avdevice/decklink_dec: add option to align capture start time

This option is useful for maintaining input synchronization across N
different hardware devices deployed for 'N-way' redundancy.
The system time of different hardware devices should be synchronized
with protocols such as NTP or PTP, before using this option.

Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
Karthick Jeyapal
2018-09-28 12:55:54 +05:30
committed by Marton Balint
parent 449b1dcd7d
commit c0ee4e0ac2
5 changed files with 27 additions and 1 deletions

View File

@@ -703,6 +703,16 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
return S_OK;
}
// Drop the frames till system's timestamp aligns with the configured value.
if (0 == ctx->frameCount && cctx->timestamp_align) {
AVRational remainder = av_make_q(av_gettime() % cctx->timestamp_align, 1000000);
AVRational frame_duration = av_inv_q(ctx->video_st->r_frame_rate);
if (av_cmp_q(remainder, frame_duration) > 0) {
++ctx->dropped;
return S_OK;
}
}
ctx->frameCount++;
if (ctx->audio_pts_source == PTS_SRC_WALLCLOCK || ctx->video_pts_source == PTS_SRC_WALLCLOCK)
wallclock = av_gettime_relative();