From patchwork Wed Dec 13 11:44:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodger Combs X-Patchwork-Id: 6760 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp5314225jah; Wed, 13 Dec 2017 03:50:56 -0800 (PST) X-Google-Smtp-Source: ACJfBotyyp5+xFVNRNg5xe+4X2exg8LaAiuOLjfI23BiBmptJg/pbfh7Wj4unNnNbyrk0Xs8zm5s X-Received: by 10.223.144.41 with SMTP id h38mr2211047wrh.228.1513165856335; Wed, 13 Dec 2017 03:50:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513165856; cv=none; d=google.com; s=arc-20160816; b=il+bbt3YS0Je1dJ+e1gfrNUawUqQDHtUEZ3XhqHxyIGQw1GqHrgnX2FB53G7g7B1dg B43z96eRM/LTm3UhXuAzZe0R8hv/VsZrUdhH03hA4NokBt1fcpHP/4+e5iHVsSK4avS2 xNVUo2nP5O/HNFDtMKiXiJshvUVOPbp8lg6siDksSdmkztdyzxLY+eqnbSaqCOmajaCi j+vXFGfSHbak4niFS0x8Wneumk8lHX8ykVAZQ3yu6Eq5hMNIDUcBge4+c6qntd9X0cLA Fg2623uGPfTQY0aSojenDsrt6+OKY5gvsjFtmlRUXQRYsWZ+/IWwFkwXMk6bAkJbMcCD +xhw== 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:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=/CGFBp45Hza757C53X75tSAx0dv+33RzAvMz97zHC+M=; b=YZhznTCN5RQy/3GG2+Vbv5mALdrRGJVtuNyq8Q4CrKmLUVoH0zUpF7pykmRW/4eFq1 jHJ+nzg5koEY3zMT+4fEcREgoGArzDZiMsxVa6Jt9JWX/xq5m2ywBykfvZEv76uAMPgc nEpe79grT24SaXgihZqXStyUw6N6bi6Dof5Ty7ErEJ4k4b5hFVBiHatVRd3WwUI7pMON 6tMiFwkC7zt5MoaXjQva0E3nlACVByUCYFfcm7c2nHd32ukzuluV4HVRTVrcJTVwrhVL e2VuaQvjEjaO1e7Gz3S28nq/grkFQz2ejU/JaQKp5ralL/Jg3TNdYzerPHW9j4OOMT4T co1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=FBJUu1L8; 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=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v65si1308445wma.263.2017.12.13.03.50.55; Wed, 13 Dec 2017 03:50:56 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=FBJUu1L8; 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=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 11DF368A1F2; Wed, 13 Dec 2017 13:50:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io0-f177.google.com (mail-io0-f177.google.com [209.85.223.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F02468A1F2 for ; Wed, 13 Dec 2017 13:50:37 +0200 (EET) Received: by mail-io0-f177.google.com with SMTP id w127so2528789iow.11 for ; Wed, 13 Dec 2017 03:50:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=GB4cotNp4wdMDPDGcxEndoyfSKrjfKLup965pmT8TDo=; b=FBJUu1L8BBW/a8Zlt9DBJciyHGmKcBfFyp1us9mN4HTUjbuQCoD0To4mzllUSiTD2I Va5BEd5seBTcCKvbirzM/+C0qs8WFJR67geiOpWX0wgiLoNm88ciyohFFWMQ7lOC/nmq 6eeVPCfQdGaOATwEq9jjM9BKbNb3RWwAJfucMasV35eKlOG0taZeCJ8CvoZUNUziowSD /Ix6YPReCWjrDHgvOuKM9zyfiWSusY5RWZ9gM4yTe72x//fi+zYQGxAKpGCDPOXOKuzN NG5XDKJeuTgbmH8w2+qwJ6x9Xf/CeuecNO2JnXc1DXjSPSvqhNcwXXL754UlEfjAsEY5 QyXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=GB4cotNp4wdMDPDGcxEndoyfSKrjfKLup965pmT8TDo=; b=We8Eh69WzAiLsdBCMqKXryrpiCX4gM2IvvWwOYCFvO1xvAKWcqA+x1g7UFQ4xT/HBx ElxFQ69vChFqhntVYfHDYjjwmTNS+ecUAK1V8Qip0qUqdXjh+NMeGDdnvyJxUi3hDEkb /1MreuwQQsu5RvVMd9A6m3MnbduShx6Zc7F0xKDX6eWnesf390VPP9mmO27MHvdKMZyA Z+Ns0qgWXmxYOcjLzJPfZUOn5/QE01XVNWVBwIM2cVjnV7P8E7oRLqqGgJSL0afvToQx f5XKw4/U4MSfBfq0Kd3FDLKxjIPoBJdVO7lX0OzUPKj8NIIKVvkG1q3Tg6gGk7LPAeT4 n06A== X-Gm-Message-State: AKGB3mJ3pmxMNLFrc+bEFqlgn3z4cYhjZ09cbh/7pHafeCkRqMfJvrmt Fbsr+O1aMBppyINPRyfSs2MtLsgl X-Received: by 10.107.8.140 with SMTP id h12mr2396607ioi.270.1513165504210; Wed, 13 Dec 2017 03:45:04 -0800 (PST) Received: from Rodgers-MacBook-Pro.local.net (c-73-75-100-12.hsd1.il.comcast.net. [73.75.100.12]) by smtp.gmail.com with ESMTPSA id q6sm1106447ita.38.2017.12.13.03.45.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Dec 2017 03:45:03 -0800 (PST) From: Rodger Combs To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2017 05:44:53 -0600 Message-Id: <20171213114453.22089-4-rodger.combs@gmail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171213114453.22089-1-rodger.combs@gmail.com> References: <20171213114453.22089-1-rodger.combs@gmail.com> Subject: [FFmpeg-devel] [PATCH 4/4] lavf/utils: add flag to fill unset timestamps from wallclock offset 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavformat/avformat.h | 1 + libavformat/internal.h | 5 +++++ libavformat/options_table.h | 1 + libavformat/utils.c | 12 ++++++++++++ 4 files changed, 19 insertions(+) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index d10d583dff..a039a2764d 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1451,6 +1451,7 @@ typedef struct AVFormatContext { #define AVFMT_FLAG_SHORTEST 0x100000 ///< Stop muxing when the shortest stream stops. #define AVFMT_FLAG_AUTO_BSF 0x200000 ///< Add bitstream filters as requested by the muxer #define AVFMT_FLAG_DISCARD_CORRUPT_TS 0x400000 ///< Discard timestamps of frames marked corrupt +#define AVFMT_FLAG_FILL_WALLCLOCK_DTS 0x800000 ///< Fill missing or discarded DTS values from wallclock (for live streams) /** * Maximum size of the data read from input for determining diff --git a/libavformat/internal.h b/libavformat/internal.h index 36a57214ce..3abf1dc720 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -192,6 +192,11 @@ struct AVStreamInternal { int need_context_update; FFFrac *priv_pts; + + /** + * The wallclock timestamp of the most recent read packet (if AVFMT_FLAG_FILL_WALLCLOCK_DTS is set) + */ + int64_t cur_wallclock_time; }; #ifdef __GNUC__ diff --git a/libavformat/options_table.h b/libavformat/options_table.h index 515574d3e0..64febc7a21 100644 --- a/libavformat/options_table.h +++ b/libavformat/options_table.h @@ -59,6 +59,7 @@ static const AVOption avformat_options[] = { {"shortest", "stop muxing with the shortest stream", 0, AV_OPT_TYPE_CONST, { .i64 = AVFMT_FLAG_SHORTEST }, 0, 0, E, "fflags" }, {"autobsf", "add needed bsfs automatically", 0, AV_OPT_TYPE_CONST, { .i64 = AVFMT_FLAG_AUTO_BSF }, 0, 0, E, "fflags" }, {"discardcorruptts", "discard timestamps on corrupted frames", 0, AV_OPT_TYPE_CONST, { .i64 = AVFMT_FLAG_DISCARD_CORRUPT_TS }, 0, 0, E, "fflags" }, +{"fillwallclockdts", "fill missing or discarded DTS values from wallclock (for live streams)", 0, AV_OPT_TYPE_CONST, { .i64 = AVFMT_FLAG_FILL_WALLCLOCK_DTS }, 0, 0, E, "fflags" }, {"analyzeduration", "specify how many microseconds are analyzed to probe the input", OFFSET(max_analyze_duration), AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, INT64_MAX, D}, {"cryptokey", "decryption key", OFFSET(key), AV_OPT_TYPE_BINARY, {.dbl = 0}, 0, 0, D}, {"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), AV_OPT_TYPE_INT, {.i64 = 1<<20 }, 0, INT_MAX, D}, diff --git a/libavformat/utils.c b/libavformat/utils.c index 2e15f34469..9704f2ae29 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -881,6 +881,18 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->stream_index); } + if (s->flags & AVFMT_FLAG_FILL_WALLCLOCK_DTS) { + int64_t cur_wallclock_time = av_gettime_relative(); + if (pkt->dts == AV_NOPTS_VALUE && st->cur_dts != AV_NOPTS_VALUE && st->internal->cur_wallclock_time) { + int64_t wallclock_offset = av_rescale_q(st->internal->cur_wallclock_time - cur_wallclock_time, AV_TIME_BASE_Q, st->time_base); + pkt->dts = st->cur_dts + FFMAX(wallclock_offset, 1); + av_log(s, AV_LOG_VERBOSE, + "Filled timestamp from wallclock (stream = %d; last = %"PRId64"; val = %"PRId64")\n", + pkt->stream_index, st->cur_dts, pkt->dts); + } + st->internal->cur_wallclock_time = cur_wallclock_time; + } + pkt->dts = wrap_timestamp(st, pkt->dts); pkt->pts = wrap_timestamp(st, pkt->pts);