video: check whether there are enough frames after filtering

Move the check to a function. Run the check a second time after
decoding/filtering. This second check is strictly speaking redundant
(which is why it wasn't done until now), but it avoids a useless
playloop iteration.
This commit is contained in:
wm4 2014-09-18 19:20:22 +02:00
parent 35810cb8b4
commit e37ad620aa
1 changed files with 11 additions and 6 deletions

View File

@ -495,6 +495,15 @@ static void adjust_sync(struct MPContext *mpctx, double v_pts, double frame_time
mpctx->total_avsync_change += change;
}
// Enough video filtered already to push one frame to the VO?
static bool have_new_frame(struct MPContext *mpctx)
{
bool need_2nd = !!(mpctx->opts->frame_dropping & 1) // we need the duration
&& mpctx->video_pts != MP_NOPTS_VALUE; // ...except for the 1st frame
return mpctx->next_frame[0] && (!need_2nd || mpctx->next_frame[1]);
}
// Fill mpctx->next_frame[] with a newly filtered or decoded image.
// returns VD_* code
static int video_output_image(struct MPContext *mpctx, double endpts)
@ -511,11 +520,7 @@ static int video_output_image(struct MPContext *mpctx, double endpts)
return r <= 0 ? VD_EOF : VD_PROGRESS;
}
bool need_2nd = !!(mpctx->opts->frame_dropping & 1) // we need the duration
&& mpctx->video_pts != MP_NOPTS_VALUE; // ...except for the 1st frame
// Enough video filtered already?
if (mpctx->next_frame[0] && (!need_2nd || mpctx->next_frame[1]))
if (have_new_frame(mpctx))
return VD_NEW_FRAME;
// Filter a new frame.
@ -573,7 +578,7 @@ static int video_output_image(struct MPContext *mpctx, double endpts)
}
// On EOF, always allow the playloop to use the remaining frame.
if (r <= 0 && mpctx->next_frame[0])
if (have_new_frame(mpctx) || (r <= 0 && mpctx->next_frame[0]))
r = VD_NEW_FRAME;
return r;