From be4b2533a97387e9ab338659c5001e5c421aca35 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 6 Mar 2008 14:47:57 +0000 Subject: [PATCH] ext/ffmpeg/gstffmpegdec.c: Work around an ffmpeg bug where it always returns 0 timestamps. Original commit message from CVS: * ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_open), (get_output_buffer), (gst_ffmpegdec_video_frame), (gst_ffmpegdec_chain): Work around an ffmpeg bug where it always returns 0 timestamps. --- ChangeLog | 7 +++++++ ext/ffmpeg/gstffmpegdec.c | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 40173cdeec..7c5454e31f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-03-06 Wim Taymans + + * ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_open), + (get_output_buffer), (gst_ffmpegdec_video_frame), + (gst_ffmpegdec_chain): + Work around an ffmpeg bug where it always returns 0 timestamps. + 2008-03-06 Michael Smith * ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_pixfmt_to_caps): diff --git a/ext/ffmpeg/gstffmpegdec.c b/ext/ffmpeg/gstffmpegdec.c index c65b5e0d36..4783a647b9 100644 --- a/ext/ffmpeg/gstffmpegdec.c +++ b/ext/ffmpeg/gstffmpegdec.c @@ -577,6 +577,7 @@ gst_ffmpegdec_open (GstFFMpegDec * ffmpegdec) break; } + ffmpegdec->last_out = GST_CLOCK_TIME_NONE; ffmpegdec->next_ts = GST_CLOCK_TIME_NONE; /* FIXME, reset_qos holds the LOCK */ ffmpegdec->proportion = 0.0; @@ -1343,6 +1344,8 @@ get_output_buffer (GstFFMpegDec * ffmpegdec, GstBuffer ** outbuf) (AVPicture *) ffmpegdec->picture, ffmpegdec->context->pix_fmt, width, height); } + ffmpegdec->picture->pts = -1; + return ret; /* special cases */ @@ -1493,7 +1496,17 @@ gst_ffmpegdec_video_frame (GstFFMpegDec * ffmpegdec, "timestamp discont, we have DTS as timestamps"); } } - ffmpegdec->last_out = out_pts; + + if (out_pts == 0 && out_pts == ffmpegdec->last_out) { + GST_LOG_OBJECT (ffmpegdec, "ffmpeg returns 0 timestamps, ignoring"); + /* some codecs only output 0 timestamps, when that happens, make us select an + * output timestamp based on the input timestamp. We do this by making the + * ffmpeg timestamp and the interpollated next timestamp invalid. */ + out_pts = -1; + ffmpegdec->next_ts = -1; + } + else + ffmpegdec->last_out = out_pts; if (ffmpegdec->ts_is_dts) { /* we are dealing with DTS as the timestamps, only copy the DTS on the picture @@ -1538,7 +1551,7 @@ gst_ffmpegdec_video_frame (GstFFMpegDec * ffmpegdec, GST_LOG_OBJECT (ffmpegdec, "using timestamp %" GST_TIME_FORMAT " returned by ffmpeg", GST_TIME_ARGS (out_timestamp)); } - if (!GST_CLOCK_TIME_IS_VALID (out_timestamp)) { + if (!GST_CLOCK_TIME_IS_VALID (out_timestamp) && ffmpegdec->next_ts != -1) { out_timestamp = ffmpegdec->next_ts; GST_LOG_OBJECT (ffmpegdec, "using next timestamp %" GST_TIME_FORMAT, GST_TIME_ARGS (out_timestamp)); @@ -2099,6 +2112,7 @@ gst_ffmpegdec_chain (GstPad * pad, GstBuffer * inbuf) avcodec_flush_buffers (ffmpegdec->context); ffmpegdec->waiting_for_key = TRUE; ffmpegdec->discont = TRUE; + ffmpegdec->last_out = GST_CLOCK_TIME_NONE; ffmpegdec->next_ts = GST_CLOCK_TIME_NONE; }