diff mbox series

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

Message ID 20210602132230.2380-4-dcnieho@gmail.com
State Superseded, archived
Headers show
Series avdevice/dshow: use video device timestamps | 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 2, 2021, 1:22 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 | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c
index 8408af26da..160f1e1324 100644
--- a/libavdevice/dshow_pin.c
+++ b/libavdevice/dshow_pin.c
@@ -295,8 +295,8 @@  long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample)
     uint8_t *buf;
     int buf_size; /* todo should be a long? */
     int index;
-    int64_t curtime;
-    int64_t orig_curtime;
+    int64_t curtime = 0;
+    int64_t orig_curtime = 0;
     int64_t graphtime;
     const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";
     IReferenceClock *clock = pin->filter->clock;
@@ -320,13 +320,15 @@  long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample)
         /* PTS from video devices is unreliable. */
         curtime = graphtime;
     } else {
-        IMediaSample_GetTime(sample, &curtime, &dummy);
-        if(curtime > 400000000000000000LL) {
+        HRESULT hr = IMediaSample_GetTime(sample, &curtime, &dummy);
+        if (hr==VFW_E_SAMPLE_TIME_NOT_SET || curtime==0) {
+            curtime = graphtime;
+        } else if (curtime > 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) audio frame with odd PTS too high %"PRId64"\n", curtime);
+                "dshow dropping initial (or ending) audio with odd PTS too high %"PRId64"\n", curtime);
             return S_OK;
         }
         curtime += pin->filter->start_time;