From patchwork Mon Sep 24 11:49:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jeyapal, Karthick" X-Patchwork-Id: 10470 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:1286:0:0:0:0:0 with SMTP id 6-v6csp2394645jap; Mon, 24 Sep 2018 04:50:18 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbQYEvdDk4N0CLEn9nnhebIsHFtCP+/zlYyogpDlr/pEoJYDTXRpQpErF4FzYA4+AB6eznT X-Received: by 2002:a1c:2787:: with SMTP id n129-v6mr6529569wmn.101.1537789818792; Mon, 24 Sep 2018 04:50:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537789818; cv=none; d=google.com; s=arc-20160816; b=qi4FoIV0dNXyCJOqGQhVm5iZxYfABsyMQXAKuQoDGKL6jxQuqvc/oPAK5VmIeYOqVX bknPb0Y6qfTrHCy2UZ/sjPkmn7mXjrF/lvJyG94IBBHZ8offGAB/8ZtJqt5NUnMRD2Bk T9aHP7cooWCNpayy+P6ZFazoXCSQGOhQ7mEk8Hd+jCmRO7BoT52SoRB70P4LycQ0t2M5 pfUBnDyWkWNQNJV8uzdhU/LKwjy0RXzWjhzgAc9bSStHvEm5gzvl1HeA7e4NZepTn94n QFrSP8FseHB7kb5EMvOlTtiW0p82uqkDGcrvlwwnPICuzriKsAn2bqERM4vcpnQU/AIj sZyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:feedback-id:message-id:date:to:from :dkim-signature:delivered-to; bh=wW80i3FP7h3iN5uI9M1iFYHKoPLq4l/3fc+9N4GP/Uc=; b=BVWx2HbZdEBxqJ9oFdxBQtSKBCPz9ffdj/kERwD74rrXBuKvwL5Huq9mi1AB4rdCGr MiHQlnJbwuYLBk42rUtCupnZN5M6QBR+BpNW0voWzFlwHPKoeNCnd2HnNTTC7SJ5sXaJ Db0p+wGBQwqgSK/lgsXtgslWaURY8Zsnt8fDrckKXo/isn5sB7saJPFzlQCOcaUjG4Wv IVaoKt7Wn08xCQTBVkxKrQ1i/4lNf0PTWGBZTNA85rk+Nmrtzcz8QoynDYz0rKxePBQd lAYt/FLVQajmMlUp086IisNfUTbwHUsSxtO5kK4fsSCg5WI5DgIWuuEpymIQovvkfJTe 4mUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@smtpservice.net header.s=m78bu0.a1-4.dyn header.b=JZvcRj34; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q17-v6si1142089wme.136.2018.09.24.04.50.18; Mon, 24 Sep 2018 04:50:18 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@smtpservice.net header.s=m78bu0.a1-4.dyn header.b=JZvcRj34; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3608368A122; Mon, 24 Sep 2018 14:50:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from a1i390.smtp2go.com (a1i390.smtp2go.com [43.228.185.134]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0A89D6800C9 for ; Mon, 24 Sep 2018 14:49:55 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=m78bu0.a1-4.dyn; x=1537790716; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe; bh=aXuj2uTSGYVFGIUQo1OSVG7NIX8GE/umCY00+1QiQZM=; b=JZvcRj34 n0AEduHiDquhcWqvW4DUCLYCqlZnWUR3xdGVDi+qHNm1FBertQriMifBigz+jjrojDOMyvwfWppNW /0FrJJdQPbf7UFN818IXxkCoM19VoUj1fCwPjLZwS+6TeC2MJkkhAkhME/yjmRnpg7HTkkJ+5cUmn uKWFm3fNgk9EXbnWQSVpJ5/dPWsfoLAyGXddaBt7uf1HEvpatggAK9DR+YDikoxaId7us31oKIIJP VSe1eaXZGy1RZyWV2rM9S/IVO+4LEuKQ4abZu1vSk32Y/nXVvcOSlPMyu0ioFs2UedAkvpBdYphUU LEQbrJZE4noZuIIoFNMtRzdpHg==; Received: from [10.45.63.29] (helo=SmtpCorp) by smtpcorp.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.91) (envelope-from ) id 1g4PNP-Itk94W-Qf; Mon, 24 Sep 2018 11:50:07 +0000 Received: from [10.125.17.166] (helo=gmail.com) by smtpcorp.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.91) (envelope-from ) id 1g4PNM-RyuKL2-V4; Mon, 24 Sep 2018 11:50:05 +0000 Received: from gmail.com (localhost [127.0.0.1]) by gmail.com (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id w8OBnvOQ006240; Mon, 24 Sep 2018 17:19:57 +0530 Received: (from akamai@localhost) by gmail.com (8.14.4/8.14.4/Submit) id w8OBnvr9006239; Mon, 24 Sep 2018 17:19:57 +0530 From: Karthick J To: ffmpeg-devel@ffmpeg.org Date: Mon, 24 Sep 2018 17:19:52 +0530 Message-Id: <1537789792-6200-1-git-send-email-kjeyapal@akamai.com> X-Mailer: git-send-email 1.9.1 X-Smtpcorp-Track: 1g4eNuRyIKL2V4.qm9tLntdn Feedback-ID: 337386m:337386asVRLGB:337386s68v0QeGAX X-Report-Abuse: Please forward a copy of this message, including all headers, to Subject: [FFmpeg-devel] [PATCH] avdevice/decklink: Add option to align Capture start time X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Karthick Jeyapal MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Karthick Jeyapal 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. --- doc/indevs.texi | 10 ++++++++++ libavdevice/decklink_common_c.h | 1 + libavdevice/decklink_dec.cpp | 20 ++++++++++++++++++++ libavdevice/decklink_dec_c.c | 1 + 4 files changed, 32 insertions(+) diff --git a/doc/indevs.texi b/doc/indevs.texi index ed2784b..dfd530a 100644 --- a/doc/indevs.texi +++ b/doc/indevs.texi @@ -371,6 +371,16 @@ If set to @option{true}, timestamps are forwarded as they are without removing the initial offset. Defaults to @option{false}. +@item timestamp_align +Capture start time alignment in seconds. If set to nonzero, input frames are +dropped till the system timestamp aligns with configured value. +Alignment difference of upto one frame duration is tolerated. +This 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. +Defaults to @samp{0}. + @end table @subsection Examples diff --git a/libavdevice/decklink_common_c.h b/libavdevice/decklink_common_c.h index 32a5d70..c4a8985 100644 --- a/libavdevice/decklink_common_c.h +++ b/libavdevice/decklink_common_c.h @@ -56,6 +56,7 @@ struct decklink_cctx { int raw_format; int64_t queue_size; int copyts; + int timestamp_align; }; #endif /* AVDEVICE_DECKLINK_COMMON_C_H */ diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index 7fabef2..24f5ca9 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -703,6 +703,26 @@ 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) { + int64_t current_time_us = av_gettime(); + int64_t align_factor_us = (cctx->timestamp_align * 1000000); + int remainder = current_time_us % align_factor_us; + if (videoFrame) { + videoFrame->GetStreamTime(&frameTime, &frameDuration, 1000000); + } else if (audioFrame) { + long sample_count = audioFrame->GetSampleFrameCount(); + frameDuration = (long)(sample_count * 1000000) / bmdAudioSampleRate48kHz; + } else { + frameDuration = 0; + } + // threshold of one frameDuration + if(remainder > frameDuration) { + ++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(); diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c index 6ab3819..bef9c14 100644 --- a/libavdevice/decklink_dec_c.c +++ b/libavdevice/decklink_dec_c.c @@ -84,6 +84,7 @@ static const AVOption options[] = { { "queue_size", "input queue buffer size", OFFSET(queue_size), AV_OPT_TYPE_INT64, { .i64 = (1024 * 1024 * 1024)}, 0, INT64_MAX, DEC }, { "audio_depth", "audio bitdepth (16 or 32)", OFFSET(audio_depth), AV_OPT_TYPE_INT, { .i64 = 16}, 16, 32, DEC }, { "decklink_copyts", "copy timestamps, do not remove the initial offset", OFFSET(copyts), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, DEC }, + { "timestamp_align", "Capture start time alignment (in seconds)", OFFSET(timestamp_align), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, DEC }, { NULL }, };