diff mbox series

[FFmpeg-devel,04/35] avdevice/dshow: handle unknown sample time

Message ID 20210607230414.612-5-dcnieho@gmail.com
State Superseded, archived
Headers show
Series avdevice (mostly dshow) enhancements | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Diederick C. Niehorster June 7, 2021, 11:03 p.m. UTC
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@gmail.com>
---
 libavdevice/dshow_pin.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
diff mbox series

Patch

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;