Use explicit output parameter for skipped frame

The function video_buffer_offer_decoded_frame() returned a bool to
indicate whether the previous frame had been consumed.

This was confusing, because we could expect the returned bool report
whether the action succeeded.

Make the semantic explicit by using an output parameter.

Also revert the flag (report if the frame has been skipped instead of
consumed) to avoid confusion for the first frame (the previous is
neither skipped nor consumed because there is no previous frame).
master
Romain Vimont 7 years ago
parent 9ef345fdd0
commit 8595862005

@ -20,9 +20,10 @@
// set the decoded frame as ready for rendering, and notify
static void
push_frame(struct decoder *decoder) {
bool previous_frame_consumed =
video_buffer_offer_decoded_frame(decoder->video_buffer);
if (!previous_frame_consumed) {
bool previous_frame_skipped;
video_buffer_offer_decoded_frame(decoder->video_buffer,
&previous_frame_skipped);
if (previous_frame_skipped) {
// the previous EVENT_NEW_FRAME will consume this frame
return;
}

@ -63,8 +63,9 @@ video_buffer_swap_frames(struct video_buffer *vb) {
vb->rendering_frame = tmp;
}
bool
video_buffer_offer_decoded_frame(struct video_buffer *vb) {
void
video_buffer_offer_decoded_frame(struct video_buffer *vb,
bool *previous_frame_skipped) {
mutex_lock(vb->mutex);
#ifndef SKIP_FRAMES
// if SKIP_FRAMES is disabled, then the decoder must wait for the current
@ -80,11 +81,10 @@ video_buffer_offer_decoded_frame(struct video_buffer *vb) {
video_buffer_swap_frames(vb);
bool previous_frame_consumed = vb->rendering_frame_consumed;
*previous_frame_skipped = !vb->rendering_frame_consumed;
vb->rendering_frame_consumed = false;
mutex_unlock(vb->mutex);
return previous_frame_consumed;
}
const AVFrame *

@ -30,9 +30,10 @@ video_buffer_destroy(struct video_buffer *vb);
// set the decoded frame as ready for rendering
// this function locks frames->mutex during its execution
// returns true if the previous frame had been consumed
bool
video_buffer_offer_decoded_frame(struct video_buffer *vb);
// the output flag is set to report whether the previous frame has been skipped
void
video_buffer_offer_decoded_frame(struct video_buffer *vb,
bool *previous_frame_skipped);
// mark the rendering frame as consumed and return it
// MUST be called with frames->mutex locked!!!

Loading…
Cancel
Save