Factorize frame swap

This commit is contained in:
Romain Vimont 2021-02-21 17:22:25 +01:00
parent fb464614c7
commit 86ae6955c6

View File

@ -75,20 +75,11 @@ video_buffer_destroy(struct video_buffer *vb) {
av_frame_free(&vb->producer_frame);
}
static void
video_buffer_swap_producer_frame(struct video_buffer *vb) {
sc_mutex_assert(&vb->mutex);
AVFrame *tmp = vb->producer_frame;
vb->producer_frame = vb->pending_frame;
vb->pending_frame = tmp;
}
static void
video_buffer_swap_consumer_frame(struct video_buffer *vb) {
sc_mutex_assert(&vb->mutex);
AVFrame *tmp = vb->consumer_frame;
vb->consumer_frame = vb->pending_frame;
vb->pending_frame = tmp;
static inline void
swap_frames(AVFrame **lhs, AVFrame **rhs) {
AVFrame *tmp = *lhs;
*lhs = *rhs;
*rhs = tmp;
}
void
@ -101,7 +92,7 @@ video_buffer_producer_offer_frame(struct video_buffer *vb) {
}
}
video_buffer_swap_producer_frame(vb);
swap_frames(&vb->producer_frame, &vb->pending_frame);
bool skipped = !vb->pending_frame_consumed;
if (skipped) {
@ -125,7 +116,7 @@ video_buffer_consumer_take_frame(struct video_buffer *vb, unsigned *skipped) {
assert(!vb->pending_frame_consumed);
vb->pending_frame_consumed = true;
video_buffer_swap_consumer_frame(vb);
swap_frames(&vb->consumer_frame, &vb->pending_frame);
if (vb->wait_consumer) {
// unblock video_buffer_offer_decoded_frame()