video: readd codec delay estimation

Approximately reverts commit 3ccac74d. This failed with some avi files,
which do pseudo-VFR by sending packets with empty frames (or repeat
frames, depending on point of view). Specifically, these packets are not
0 bytes, so they don't get skipped by libavformat, as with the usual VFR
avi hack. Instead, the packet contains a VOP with vop_coded=0, so
libavcodec will just return no frame. We could probably distinguish such
skipped frames and delayed frames by explicitly measuring the codec
delay by counting how long it takes to get the very first frame (and
then treat skips as explicit drops), but we may as well simply reinstate
the old code.

To appease to at least one semi-broken case, do not enable this logic on
the RPI, as the FFmpeg MMAL wrapper has arbitrary buffering (and MMAL
itself is asynchronous).
This commit is contained in:
wm4 2015-12-02 14:38:47 +01:00
parent 03d311823d
commit 344d44681e
3 changed files with 18 additions and 0 deletions

View File

@ -211,6 +211,10 @@ bool video_init_best_codec(struct dec_video *d_video, char* video_decoders)
static void add_avi_pts(struct dec_video *d_video, double pts)
{
if (pts != MP_NOPTS_VALUE) {
int delay = -1;
video_vd_control(d_video, VDCTRL_QUERY_UNSEEN_FRAMES, &delay);
if (delay >= 0 && delay < d_video->num_buffered_pts)
d_video->num_buffered_pts = delay;
if (d_video->num_buffered_pts == MP_ARRAY_SIZE(d_video->buffered_pts)) {
MP_ERR(d_video, "Too many buffered pts\n");
} else {

View File

@ -42,6 +42,7 @@ extern const vd_functions_t *const mpcodecs_vd_drivers[];
enum vd_ctrl {
VDCTRL_RESET = 1, // reset decode state after seeking
VDCTRL_QUERY_UNSEEN_FRAMES, // current decoder lag
VDCTRL_FORCE_HWDEC_FALLBACK, // force software decoding fallback
VDCTRL_GET_HWDEC,
};

View File

@ -722,6 +722,19 @@ static int control(struct dec_video *vd, int cmd, void *arg)
case VDCTRL_RESET:
reset_avctx(vd);
return CONTROL_TRUE;
case VDCTRL_QUERY_UNSEEN_FRAMES: {
AVCodecContext *avctx = ctx->avctx;
if (!ctx)
break;
if (ctx->hwdec && ctx->hwdec->type == HWDEC_RPI)
break; // MMAL has arbitrary buffering, thus unknown
int delay = avctx->has_b_frames;
assert(delay >= 0);
if (avctx->active_thread_type & FF_THREAD_FRAME)
delay += avctx->thread_count - 1;
*(int *)arg = delay;
return CONTROL_TRUE;
}
case VDCTRL_GET_HWDEC: {
int hwdec = ctx->hwdec ? ctx->hwdec->type : 0;
if (!ctx->software_fallback_decoder)