[FFmpeg-devel] [PATCH v3 04/34] avdevice/dshow: handle unknown sample time

Diederick Niehorster dcnieho at gmail.com
Tue Jul 6 12:19:50 EEST 2021


GetTime may return an error indication that the sample has not
timestamps, or may return a NULL start time. In those cases, fall back
to graph time.
Better debug message in case sample dropped: could now be audio or
video frame

Signed-off-by: Diederick Niehorster <dcnieho at gmail.com>
---
 libavdevice/dshow_pin.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c
index 1d0e880480..310f48c85e 100644
--- a/libavdevice/dshow_pin.c
+++ b/libavdevice/dshow_pin.c
@@ -295,14 +295,15 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample)
     uint8_t *buf;
     int buf_size; /* todo should be a long? */
     int index;
-    int64_t chosentime;
-    int64_t sampletime;
-    int64_t graphtime;
+    int64_t chosentime = 0;
+    int64_t sampletime = 0;
+    int64_t graphtime = 0;
     int use_sample_time = 1;
     const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";
     IReferenceClock *clock = pin->filter->clock;
     int64_t dummy;
     struct dshow_ctx *ctx;
+    HRESULT hr;
 
 
     dshowdebug("ff_dshow_meminputpin_Receive(%p)\n", this);
@@ -314,22 +315,26 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample)
     s = priv_data;
     ctx = s->priv_data;
 
-    IMediaSample_GetTime(sample, &sampletime, &dummy);
+    hr = IMediaSample_GetTime(sample, &sampletime, &dummy);
     IReferenceClock_GetTime(clock, &graphtime);
     if (devtype == VideoDevice && !ctx->use_video_device_timestamps) {
         /* PTS from video devices is unreliable. */
         chosentime = graphtime;
         use_sample_time = 0;
     } else {
-        if (sampletime > 400000000000000000LL) {
+        if (hr == VFW_E_SAMPLE_TIME_NOT_SET || sampletime == 0) {
+            chosentime = graphtime;
+            use_sample_time = 0;
+        }
+        else if (sampletime > 400000000000000000LL) {
             /* initial frames sometimes start < 0 (shown as a very large number here,
                like 437650244077016960 which FFmpeg doesn't like).
                TODO figure out math. For now just drop them. */
             av_log(NULL, AV_LOG_DEBUG,
                 "dshow dropping initial (or ending) frame with odd PTS too high %"PRId64"\n", sampletime);
             return S_OK;
-        }
-        chosentime = sampletime;
+        } else
+            chosentime = sampletime;
     }
     // media sample time is relative to graph start time
     sampletime += pin->filter->start_time;
-- 
2.28.0.windows.1



More information about the ffmpeg-devel mailing list