From patchwork Fri Sep 28 07:25:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jeyapal, Karthick" X-Patchwork-Id: 10510 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:1286:0:0:0:0:0 with SMTP id 6-v6csp414311jap; Fri, 28 Sep 2018 00:26:21 -0700 (PDT) X-Google-Smtp-Source: ACcGV61dILQzj/6qxt9UCGgNze+DlL+1ABh4+Wcf8d18q9dLGBvxaeavOYRAZnb7nam8B1eWW3Xo X-Received: by 2002:a1c:357:: with SMTP id 84-v6mr728350wmd.8.1538119581256; Fri, 28 Sep 2018 00:26:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538119581; cv=none; d=google.com; s=arc-20160816; b=Ad6chkxnUsbMeL714lUb6v7dPbhFM7dr7TldxHP1jDARruovssDgl2DUnaqFA3vrF2 TV74+jcqECcFqjQuBZkK7bKgqqs+MVRRpWNQmfEwanPuUl41+U7cRyun+H8e49nI7cK8 aGcDMZSePwrCt7rJKkpY/lo5mbKziqYkg/0S+hjoohWVz03cxTXE7ZHRmO/7CucHdhES sxe8mP5t//UKDHk+ioddWTiae0BnU+b6vG/Q6/okqnt6gRLe9qJ6RxHq5HXYDwSNsUrX cEDMJkvqIrx8jRhks25QhY8E1OjzVf81t3VfLXf0yLe/fs/oqLaPcwvhhBJLoPq3pNi+ WNNQ== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=XKKmuP6GI+zLU8pILuNxBGRcd/HA8MHewl40R5/38p0=; b=OzSbwbxwMKLA5rfZFefGT1ySo/M4h9avmiS180i+Mz7Nq5P4MuIC93KuVw3YQqY0uU z5Xcpn/1m4aTIQqO9bQA7Dmk00+EaoloswJ2C/ehoW4DlwSIlSGWUMBwTLrPt8cqew3c BpM3KInGzj88zo5L/OwKi3rEFQc1IFoIgl6oXZ7akQft8HKdjO2qk+4aVywIAWvXJ/aO pM6HJMG7cL99/cd6Ii0n3UjBNmHPiMEIpF5FGJNxHhOUUm/qXqBigXCACUjVNc6rJXOx zyPn2xTiQWXRog0dDHRZnLE3bb7yL7ijza9Y87zC5WnDPxhp4V5NwmBAeBFNuOjD+Ppk 97Uw== 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=B0UWu+da; 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 b1-v6si1082153wrm.262.2018.09.28.00.26.20; Fri, 28 Sep 2018 00:26:21 -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=B0UWu+da; 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 71A8668A3D1; Fri, 28 Sep 2018 10:26: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 8BE80689E9B for ; Fri, 28 Sep 2018 10:25:54 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=m78bu0.a1-4.dyn; x=1538120477; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe; bh=cVNMwg+j6BQMfxRBsHIVskfrJ+TQWdrB6QofxiSRnC0=; b=B0UWu+da 27FX04Ck8KZnO4zsQO7Qc3CXinZ/b1pxteEiSBvMzQdiSnks49zLkdbWwRv1cU9yRnz/Bnf1xRYpw KVcP5A4WMsHxPoxqFgD2OdEtA6ABr4W3em5vyrwNGwRjiIckr2V++ENPqXIX0iUlW6KSUmupb6X5Z QfXMfZ/0K6yEwVd8E1RctgyDjRJ2nhC2gcSA8kgbSUPBv3tmTZNbC9+DGDe0Yk+qXUyfmvJWaj4Ty HSWedfLKvQXXJbXzEMsDVl9+N+/Hhq4/cM5W4wdiHooEaBbq0OJEwCP9cRucYWq5W50YsbWjGzLgA H3c3Nbencd2vDF94HedBew3shA==; Received: from [10.139.162.187] (helo=SmtpCorp) by smtpcorp.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.91) (envelope-from ) id 1g5nA8-ItkGEY-GW; Fri, 28 Sep 2018 07:26:08 +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 1g5nA6-4XaBFr-10; Fri, 28 Sep 2018 07:26:06 +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 w8S7Q3H5007389; Fri, 28 Sep 2018 12:56:03 +0530 Received: (from akamai@localhost) by gmail.com (8.14.4/8.14.4/Submit) id w8S7Q2ln007388; Fri, 28 Sep 2018 12:56:02 +0530 From: Karthick J To: ffmpeg-devel@ffmpeg.org Date: Fri, 28 Sep 2018 12:55:54 +0530 Message-Id: <1538119554-7348-1-git-send-email-kjeyapal@akamai.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-Smtpcorp-Track: 1g5nj64baUFr10.rZ-e2dL4b Feedback-ID: 337386m:337386asVRLGB:337386sqUp5Fh1LR X-Report-Abuse: Please forward a copy of this message, including all headers, to Subject: [FFmpeg-devel] [PATCH v2] 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 | 13 +++++++++++++ libavdevice/decklink_common_c.h | 1 + libavdevice/decklink_dec.cpp | 11 +++++++++++ libavdevice/decklink_dec_c.c | 1 + 4 files changed, 26 insertions(+) diff --git a/doc/indevs.texi b/doc/indevs.texi index ed2784b..694bac9 100644 --- a/doc/indevs.texi +++ b/doc/indevs.texi @@ -371,6 +371,19 @@ 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. +Note that this method not foolproof. In some border cases input synchronization +may not happen due to thread scheduling jitters in the OS. Either sync could go +wrong by 1 frame or in a rarer case by even @option{timestamp_align} seconds. +Defaults to @samp{0}. + @end table @subsection Examples diff --git a/libavdevice/decklink_common_c.h b/libavdevice/decklink_common_c.h index 32a5d70..8e3bbeb 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; + int64_t timestamp_align; }; #endif /* AVDEVICE_DECKLINK_COMMON_C_H */ diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index 7fabef2..1f4d68b 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -703,6 +703,17 @@ 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_make_q(ctx->video_st->r_frame_rate.den, + ctx->video_st->r_frame_rate.num); + 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(); diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c index 6ab3819..2e6fcb6 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_DURATION, { .i64 = 0 }, 0, INT_MAX, DEC }, { NULL }, };