avdevice/decklink_dec: Used av_parity instead of duplicated function
[ffmpeg.git] / libavdevice / dshow_pin.c
index 5e14108..664246d 100644 (file)
@@ -19,7 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "dshow.h"
+#include "dshow_capture.h"
 
 #include <stddef.h>
 #define imemoffset offsetof(libAVPin, imemvtbl)
@@ -285,7 +285,7 @@ libAVMemInputPin_GetAllocator(libAVMemInputPin *this, IMemAllocator **alloc)
 }
 long WINAPI
 libAVMemInputPin_NotifyAllocator(libAVMemInputPin *this, IMemAllocator *alloc,
-                                 WINBOOL rdwr)
+                                 BOOL rdwr)
 {
     dshowdebug("libAVMemInputPin_NotifyAllocator(%p)\n", this);
     return S_OK;
@@ -303,32 +303,54 @@ libAVMemInputPin_Receive(libAVMemInputPin *this, IMediaSample *sample)
     libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
     enum dshowDeviceType devtype = pin->filter->type;
     void *priv_data;
+    AVFormatContext *s;
     uint8_t *buf;
-    int buf_size;
+    int buf_size; /* todo should be a long? */
     int index;
     int64_t curtime;
+    int64_t orig_curtime;
+    int64_t graphtime;
+    const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";
+    IReferenceClock *clock = pin->filter->clock;
+    int64_t dummy;
+    struct dshow_ctx *ctx;
+
 
     dshowdebug("libAVMemInputPin_Receive(%p)\n", this);
 
     if (!sample)
         return E_POINTER;
 
+    IMediaSample_GetTime(sample, &orig_curtime, &dummy);
+    orig_curtime += pin->filter->start_time;
+    IReferenceClock_GetTime(clock, &graphtime);
     if (devtype == VideoDevice) {
         /* PTS from video devices is unreliable. */
-        IReferenceClock *clock = pin->filter->clock;
         IReferenceClock_GetTime(clock, &curtime);
     } else {
-        int64_t dummy;
         IMediaSample_GetTime(sample, &curtime, &dummy);
+        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);
+            return S_OK;
+        }
         curtime += pin->filter->start_time;
     }
 
     buf_size = IMediaSample_GetActualDataLength(sample);
     IMediaSample_GetPointer(sample, &buf);
     priv_data = pin->filter->priv_data;
+    s = priv_data;
+    ctx = s->priv_data;
     index = pin->filter->stream_index;
 
-    pin->filter->callback(priv_data, index, buf, buf_size, curtime);
+    av_log(NULL, AV_LOG_VERBOSE, "dshow passing through packet of type %s size %8d "
+        "timestamp %"PRId64" orig timestamp %"PRId64" graph timestamp %"PRId64" diff %"PRId64" %s\n",
+        devtypename, buf_size, curtime, orig_curtime, graphtime, graphtime - orig_curtime, ctx->device_name[devtype]);
+    pin->filter->callback(priv_data, index, buf, buf_size, curtime, devtype);
 
     return S_OK;
 }
@@ -358,5 +380,5 @@ libAVMemInputPin_Destroy(libAVMemInputPin *this)
 {
     libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
     dshowdebug("libAVMemInputPin_Destroy(%p)\n", this);
-    return libAVPin_Destroy(pin);
+    libAVPin_Destroy(pin);
 }