summaryrefslogtreecommitdiff
path: root/libavdevice/decklink_dec.cpp
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2016-06-19 00:35:44 +0200
committerMarton Balint <cus@passwd.hu>2016-06-26 19:18:06 +0200
commitcf0a05668b9999178deebad8221d1bfb32d81c2a (patch)
treeb12a44fcd288fc97d5a528c3956bf5359f71a1b9 /libavdevice/decklink_dec.cpp
parentda89c6e37cf2fb3645611e8196cc28b6acfb9bd6 (diff)
avdevice/decklink: add support for setting input packet timestamp source
Reviewed-by: Deti Fliegl <deti@fliegl.de> Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavdevice/decklink_dec.cpp')
-rw-r--r--libavdevice/decklink_dec.cpp62
1 files changed, 48 insertions, 14 deletions
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 7f45224308..fcb024e5b3 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -28,8 +28,11 @@ extern "C" {
#include "config.h"
#include "libavformat/avformat.h"
#include "libavformat/internal.h"
+#include "libavutil/avutil.h"
#include "libavutil/common.h"
#include "libavutil/imgutils.h"
+#include "libavutil/time.h"
+#include "libavutil/mathematics.h"
#if CONFIG_LIBZVBI
#include <libzvbi.h>
#endif
@@ -237,6 +240,44 @@ ULONG decklink_input_callback::Release(void)
return (ULONG)m_refCount;
}
+static int64_t get_pkt_pts(IDeckLinkVideoInputFrame *videoFrame,
+ IDeckLinkAudioInputPacket *audioFrame,
+ int64_t wallclock,
+ DecklinkPtsSource pts_src,
+ AVRational time_base, int64_t *initial_pts)
+{
+ int64_t pts = AV_NOPTS_VALUE;
+ BMDTimeValue bmd_pts;
+ BMDTimeValue bmd_duration;
+ HRESULT res = E_INVALIDARG;
+ switch (pts_src) {
+ case PTS_SRC_AUDIO:
+ if (audioFrame)
+ res = audioFrame->GetPacketTime(&bmd_pts, time_base.den);
+ break;
+ case PTS_SRC_VIDEO:
+ if (videoFrame)
+ res = videoFrame->GetStreamTime(&bmd_pts, &bmd_duration, time_base.den);
+ break;
+ case PTS_SRC_REFERENCE:
+ if (videoFrame)
+ res = videoFrame->GetHardwareReferenceTimestamp(time_base.den, &bmd_pts, &bmd_duration);
+ break;
+ case PTS_SRC_WALLCLOCK:
+ pts = av_rescale_q(wallclock, AV_TIME_BASE_Q, time_base);
+ break;
+ }
+ if (res == S_OK)
+ pts = bmd_pts / time_base.num;
+
+ if (pts != AV_NOPTS_VALUE && *initial_pts == AV_NOPTS_VALUE)
+ *initial_pts = pts;
+ if (*initial_pts != AV_NOPTS_VALUE)
+ pts -= *initial_pts;
+
+ return pts;
+}
+
HRESULT decklink_input_callback::VideoInputFrameArrived(
IDeckLinkVideoInputFrame *videoFrame, IDeckLinkAudioInputPacket *audioFrame)
{
@@ -244,8 +285,11 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
void *audioFrameBytes;
BMDTimeValue frameTime;
BMDTimeValue frameDuration;
+ int64_t wallclock = 0;
ctx->frameCount++;
+ if (ctx->audio_pts_source == PTS_SRC_WALLCLOCK || ctx->video_pts_source == PTS_SRC_WALLCLOCK)
+ wallclock = av_gettime_relative();
// Handle Video Frame
if (videoFrame) {
@@ -292,13 +336,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
no_video = 0;
}
- pkt.pts = frameTime / ctx->video_st->time_base.num;
-
- if (initial_video_pts == AV_NOPTS_VALUE) {
- initial_video_pts = pkt.pts;
- }
-
- pkt.pts -= initial_video_pts;
+ pkt.pts = get_pkt_pts(videoFrame, audioFrame, wallclock, ctx->video_pts_source, ctx->video_st->time_base, &initial_video_pts);
pkt.dts = pkt.pts;
pkt.duration = frameDuration;
@@ -368,13 +406,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
pkt.size = audioFrame->GetSampleFrameCount() * ctx->audio_st->codecpar->channels * (16 / 8);
audioFrame->GetBytes(&audioFrameBytes);
audioFrame->GetPacketTime(&audio_pts, ctx->audio_st->time_base.den);
- pkt.pts = audio_pts / ctx->audio_st->time_base.num;
-
- if (initial_audio_pts == AV_NOPTS_VALUE) {
- initial_audio_pts = pkt.pts;
- }
-
- pkt.pts -= initial_audio_pts;
+ pkt.pts = get_pkt_pts(videoFrame, audioFrame, wallclock, ctx->audio_pts_source, ctx->audio_st->time_base, &initial_audio_pts);
pkt.dts = pkt.pts;
//fprintf(stderr,"Audio Frame size %d ts %d\n", pkt.size, pkt.pts);
@@ -451,6 +483,8 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx)
ctx->video_input = decklink_video_connection_map[cctx->video_input];
if (cctx->audio_input > 0 && (unsigned int)cctx->audio_input < FF_ARRAY_ELEMS(decklink_audio_connection_map))
ctx->audio_input = decklink_audio_connection_map[cctx->audio_input];
+ ctx->audio_pts_source = cctx->audio_pts_source;
+ ctx->video_pts_source = cctx->video_pts_source;
cctx->ctx = ctx;
#if !CONFIG_LIBZVBI