From patchwork Fri Dec 8 04:23:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodger Combs X-Patchwork-Id: 6596 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp74613jah; Thu, 7 Dec 2017 20:23:47 -0800 (PST) X-Google-Smtp-Source: AGs4zMb8AMKm1LI510PBj5XhEeAJMo+J7TrWpenqUWN4FHXthJB5BroUi/iBiKQvgkGVrRFQJj6O X-Received: by 10.223.189.11 with SMTP id j11mr12722027wrh.265.1512707027657; Thu, 07 Dec 2017 20:23:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512707027; cv=none; d=google.com; s=arc-20160816; b=jWmegylNmYGyO+aV3+kCLoHKfdwuxVwdFU0eVqviTgnKHigIPVV4GICWmewGSVErRU lv9fkuF/fZroclIswZazBvW8HbOCoIl2fCX3k8+GWrol5oR5WtcWwyJpBtZKEe8o2fh4 xGWehGyxtGuvvUJtXcOtUVBp5FUTzNgZgX9VTWV8PnnIgNo5ALVLjIvMkjcQNpUGxUvl OjxXDIly+/AzYi3p3CBnXoDSai03+5kH92HyB7vrtl5saSHEvS42EzHcdUff7vamgNr9 16mb/bVFJD5s+fk6upJ2+VTnb93p/AJyPP02HobYEzTU10NEtlPK6aZE4bj5cEhKVzNl r8Ow== 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=FttdImzpSY+eJ9EBOpckp4ci+YRM8VfI93pYM1yrzPs=; b=gEdQhn/HVRE+sRUb9dnKjMRJ4OmFgmj92JvZglXWDGnZX/WBU9WEShgf5D1TKTaFB9 sETxoM4lofDMAwoAi+jBf61t511eHFKsbohc4QqROhyD9wmV6MOOqcMCU28z8sfjkwb1 qggOj4sdQh8oLZXL36SUPGYyGm8e7sQO4Txzb5DJipWrvDQDOigOFR20aiULp0zmIEcr g0uUv3HIkFD6l65tB1gTuHOvjmURWRJIqYivgEYriN7WLOnRPitpXHUh3TPmZ09NjoPe pr+bsTtvz/7TZmr5+ahILLb5LiyVif2RTiOyM+dq3CzDOjV6uZR/qr/M0WOd+ow6GpKS JY2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=hbc5Dg/O; 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 u42si4053222wrf.243.2017.12.07.20.23.47; Thu, 07 Dec 2017 20:23:47 -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=hbc5Dg/O; 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 D828668A426; Fri, 8 Dec 2017 06:23:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f65.google.com (mail-it0-f65.google.com [209.85.214.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4CD7868A3C5 for ; Fri, 8 Dec 2017 06:23:18 +0200 (EET) Received: by mail-it0-f65.google.com with SMTP id p139so2286008itb.1 for ; Thu, 07 Dec 2017 20:23:24 -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=VUzbJ2h/Ke/t1sda6IbmjAK03Wmzj7w23o78IJSiyaY=; b=hbc5Dg/O4UTcJOyH6RTsr+SjbLpwhCh/9oVdctJRx7qVAzkkpUXQrRaaXnzV6a/3wI RdveLTjy/3UyYhmq6uQO8F1OYfpz7cl27ybUermQyqc21sZuEFmfG82R+TNTVXmRreHN VtZU2SW3zjjZJdXx7Tygca/2yZFUQODY8Oy354aCXP/CMNu+Fv31e3eLq+Je6fZEa1ga oL4JqWnustzGTN4TabdqzwQSIqTsVEO5XO92cyRs79tzy+W6wwBelsmD00rCln5DUrih bgjPUz/GPDAai8A9D5EDlrrhdWAzEvNwSMhcTRrUtrhaft3p8bgNYQchaMbCsspaJnJH Fu4w== 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=VUzbJ2h/Ke/t1sda6IbmjAK03Wmzj7w23o78IJSiyaY=; b=TYQ7s1mbVN6/B97YH/7e9fXQAXssbGjAxwYwEgTZr+c6mUWHrk5EyKNcU232FhOlCV SQbYRtiyyPdNQyl3QovRDnJ79rm/LQ3ubzA8so2dw7RnhiuqvGwbQzsX1O96dyAVSe0N 9tx3GVetvHe1U6aQfo4H83YuIl2geKc2tjPyyMNEJ/iUxlN2YTbYWLNjK7bDtvb/GXae tmMLPJ4afx1F9XYRIZV8MAUFB3AveJKPt/Zz8EDlxWJWREE+cyAHyD+ODKKI5g5nQoK0 eIY3n9bQFdkTxDRtwR7HIodei9CSOKmJNNNltvJramdj78CWA+PYpkY7wP6rplyEPuR3 Ck4Q== X-Gm-Message-State: AKGB3mKqv3/7DVi3hPPChPmFHrWFrXBa9OTC9c64NWo3Dr0nemIepyqW xP+oo4wxGIo8Pnf5ntRd4jJdM8UV X-Received: by 10.36.208.23 with SMTP id m23mr4184006itg.137.1512707003242; Thu, 07 Dec 2017 20:23:23 -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 n7sm3154355ioi.57.2017.12.07.20.23.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Dec 2017 20:23:22 -0800 (PST) From: Rodger Combs To: ffmpeg-devel@ffmpeg.org Date: Thu, 7 Dec 2017 22:23:16 -0600 Message-Id: <20171208042316.94655-3-rodger.combs@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171208042316.94655-1-rodger.combs@gmail.com> References: <20171208042316.94655-1-rodger.combs@gmail.com> Subject: [FFmpeg-devel] [PATCH 3/3] 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 98af941e9f..22cefb2975 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);