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).
This commit is contained in:
parent
9ef345fdd0
commit
8595862005
3 changed files with 12 additions and 10 deletions
|
@ -20,9 +20,10 @@
|
||||||
// set the decoded frame as ready for rendering, and notify
|
// set the decoded frame as ready for rendering, and notify
|
||||||
static void
|
static void
|
||||||
push_frame(struct decoder *decoder) {
|
push_frame(struct decoder *decoder) {
|
||||||
bool previous_frame_consumed =
|
bool previous_frame_skipped;
|
||||||
video_buffer_offer_decoded_frame(decoder->video_buffer);
|
video_buffer_offer_decoded_frame(decoder->video_buffer,
|
||||||
if (!previous_frame_consumed) {
|
&previous_frame_skipped);
|
||||||
|
if (previous_frame_skipped) {
|
||||||
// the previous EVENT_NEW_FRAME will consume this frame
|
// the previous EVENT_NEW_FRAME will consume this frame
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,8 +63,9 @@ video_buffer_swap_frames(struct video_buffer *vb) {
|
||||||
vb->rendering_frame = tmp;
|
vb->rendering_frame = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
void
|
||||||
video_buffer_offer_decoded_frame(struct video_buffer *vb) {
|
video_buffer_offer_decoded_frame(struct video_buffer *vb,
|
||||||
|
bool *previous_frame_skipped) {
|
||||||
mutex_lock(vb->mutex);
|
mutex_lock(vb->mutex);
|
||||||
#ifndef SKIP_FRAMES
|
#ifndef SKIP_FRAMES
|
||||||
// if SKIP_FRAMES is disabled, then the decoder must wait for the current
|
// 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);
|
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;
|
vb->rendering_frame_consumed = false;
|
||||||
|
|
||||||
mutex_unlock(vb->mutex);
|
mutex_unlock(vb->mutex);
|
||||||
return previous_frame_consumed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const AVFrame *
|
const AVFrame *
|
||||||
|
|
|
@ -30,9 +30,10 @@ video_buffer_destroy(struct video_buffer *vb);
|
||||||
|
|
||||||
// set the decoded frame as ready for rendering
|
// set the decoded frame as ready for rendering
|
||||||
// this function locks frames->mutex during its execution
|
// this function locks frames->mutex during its execution
|
||||||
// returns true if the previous frame had been consumed
|
// the output flag is set to report whether the previous frame has been skipped
|
||||||
bool
|
void
|
||||||
video_buffer_offer_decoded_frame(struct video_buffer *vb);
|
video_buffer_offer_decoded_frame(struct video_buffer *vb,
|
||||||
|
bool *previous_frame_skipped);
|
||||||
|
|
||||||
// mark the rendering frame as consumed and return it
|
// mark the rendering frame as consumed and return it
|
||||||
// MUST be called with frames->mutex locked!!!
|
// MUST be called with frames->mutex locked!!!
|
||||||
|
|
Loading…
Reference in a new issue