From patchwork Thu Dec 7 09:37:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodger Combs X-Patchwork-Id: 6582 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp8053467jah; Thu, 7 Dec 2017 01:37:59 -0800 (PST) X-Google-Smtp-Source: AGs4zMaEG4bsns62MjKDwQ+k5lsNf1nWwHZcZv2sHAUjffi87kWwXo094JqhZuY6Y6J2Vv6IGJd5 X-Received: by 10.223.153.20 with SMTP id x20mr20308436wrb.219.1512639479913; Thu, 07 Dec 2017 01:37:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512639479; cv=none; d=google.com; s=arc-20160816; b=DE3iEp8v998EySRbTRcx3jqCHrCRYwQUi5eUOLaMK3iYrcDuIFF6u30IdYilyVjS7f prAo03uwwnQFpUiP8Z7bLtt3xX1r6STMnfNBb/WKGuiFJy/ih/AVLw2qVITovtw5FDoF MEKHOdWblVa0KbUmOztnjPElJ3UhqT8azMeBuDlFk1dCDRZMNAtIItyHPsqODECCzaYp O7tucVgOrZ1sDGMlwsoU8JBThh0FS7X5e8JHAeZVaAmP/zd6dj03FBDOmFDq+6T+arp1 fpN88bE/zTaYx4L+M5DSN5keDi11GnC9sAc/6L8UDHvEKytw+2JSgq0xV9BzJyS/WjzA n0qA== 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=HvyPSszDrt70TVRBGbBP1UwmRsHAwXo1v76Hw5W7RDQ=; b=EwnRq3YU6+7FNI8VSiI0zua5BtSuqW9dMxP7JlnDMf3rGc8oV/RSwUU6at0RGEQQfe Mx0vijgcT/+04JFnnHpMZKiluFX9lIHRe1V9oekzQVVxqemmjBs1crLT7tD2DIFCMY2I N4kKTeaz4dvr75CRhgWRzXaddDnsOzGCpsRZOss/Q30UNMznYME4NRql3FGPdB7PimES 75/WeZMAu28GXij/tVR38IDgoE5SeGWkQlqSQpxlt03zzZrnpinvhejBM0HhCplDuubz 10BhfIpdy/6aS5KDgBbrR20PXgcYzwDrzz3JW1+2FLFzRr2qmeDWZU5oJRr6snAXNNFk Ly4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=m27TXU90; 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 g34si2625751wra.332.2017.12.07.01.37.59; Thu, 07 Dec 2017 01:37:59 -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=m27TXU90; 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 0F12368A345; Thu, 7 Dec 2017 11:37:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f51.google.com (mail-it0-f51.google.com [209.85.214.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CFD4768A0D1 for ; Thu, 7 Dec 2017 11:37:39 +0200 (EET) Received: by mail-it0-f51.google.com with SMTP id x28so13345444ita.0 for ; Thu, 07 Dec 2017 01:37: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=YqEp99ORVQsdT0UQo+A2K3gK6TCZ79XViskxA7g0HMM=; b=m27TXU90aQe1sq/vv9X3ebQWjsrt0H39p5/SdkhQir5Y7XR0UX/lGQ0UnfKKzC4QsE IfU7ruxjJ7uR/3PGbDbXUmqY5NT8/n+s1briFwmTvna/YSYR4rXqm2Q6whnMspWEcWrh GON/Ey9pWgorT2OtEWxBBabv4rhRUMaP1CV+N3ebfeGr2R2ec8FHHioD+EmVl/HBnMAo LM0zCPr6VzsnRp/ZiWMKknL6iNggP75hClv/1oHbrQYpoNNuatKWE/RiGk5BhOZqKz/a ZsN0SB9wK6m4bQsYCF1yej3Z+idIKbE8r5dHSn+1j00pehBT1L0Ch+EbFM1XCNjlxgDd vL2A== 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=YqEp99ORVQsdT0UQo+A2K3gK6TCZ79XViskxA7g0HMM=; b=KRloFITx9MPp0IgSPOXhCuZxh0YmFBufwhxdE4O/715QXGkCYUV5uGV+speicqMH46 LjNH+kr8CrIgb11BcY7NQvv/epX45mUAefsPeMzWZej+Im7LLfriDE5S5V2hEVJfKIDz fW4Gen1c9sYkw9CtLaR0jpx2yji6Oo0zoUkBPc7ORBveNTLA1cGXfhJo0vCCDanXWkPV CwiTBdXtwEcxLicPKeiGxM76v0n9t1Bk5m0q1j/p2504bzZbrP4DZUuWu17cDDo5LGC7 WsHmkwzFg/3UfDpx4/20R76y06+OZHl+VYUeSPSn22i7OkmN4q1YCpn/djm6rugdNdF9 iZ8Q== X-Gm-Message-State: AKGB3mLlRQXs7TQxvd5gmM3xgJ0F7t50y4PUZg19yJffr/EH8H6xvLOy i0HWGWwRf5gYS5ICoHls3nr2GUHt X-Received: by 10.36.84.69 with SMTP id t66mr684685ita.102.1512639464385; Thu, 07 Dec 2017 01:37:44 -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 d3sm2610445itf.1.2017.12.07.01.37.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Dec 2017 01:37:43 -0800 (PST) From: Rodger Combs To: ffmpeg-devel@ffmpeg.org Date: Thu, 7 Dec 2017 03:37:38 -0600 Message-Id: <20171207093738.52358-2-rodger.combs@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171207093738.52358-1-rodger.combs@gmail.com> References: <20171207093738.52358-1-rodger.combs@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/2] lavf/utils: add flag to discard timestamps on corrupted frames 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 4f2798a871..e2d88280a8 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1450,6 +1450,7 @@ typedef struct AVFormatContext { #define AVFMT_FLAG_FAST_SEEK 0x80000 ///< Enable fast, but inaccurate seeks for some formats #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 (replacing with wallclock offset from last non-corrupt frame) /** * Maximum size of the data read from input for determining diff --git a/libavformat/internal.h b/libavformat/internal.h index 36a57214ce..39a69cf630 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_DISCARD_CORRUPT_TS is set) + */ + int64_t cur_wallclock_time; }; #ifdef __GNUC__ diff --git a/libavformat/options_table.h b/libavformat/options_table.h index b8fa47c6fd..515574d3e0 100644 --- a/libavformat/options_table.h +++ b/libavformat/options_table.h @@ -58,6 +58,7 @@ static const AVOption avformat_options[] = { {"bitexact", "do not write random/volatile data", 0, AV_OPT_TYPE_CONST, { .i64 = AVFMT_FLAG_BITEXACT }, 0, 0, E, "fflags" }, {"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" }, {"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 84e49208b8..1adb007244 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -873,6 +873,18 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) st->cur_dts = wrap_timestamp(st, st->cur_dts); } + if ((s->flags & AVFMT_FLAG_DISCARD_CORRUPT_TS)) { + int64_t cur_wallclock_time = av_gettime_relative(); + if (pkt->flags & AV_PKT_FLAG_CORRUPT) { + int64_t wallclock_offset = av_rescale_q(st->internal->cur_wallclock_time - cur_wallclock_time, AV_TIME_BASE_Q, st->time_base); + pkt->pts = pkt->dts = st->cur_dts + FFMAX(wallclock_offset, 1); + av_log(s, AV_LOG_WARNING, + "Discarded timestamp on corrupted packet (stream = %d)\n", + pkt->stream_index); + } + st->internal->cur_wallclock_time = cur_wallclock_time; + } + pkt->dts = wrap_timestamp(st, pkt->dts); pkt->pts = wrap_timestamp(st, pkt->pts);