From patchwork Sun Nov 21 17:06:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryoji Gyoda X-Patchwork-Id: 31518 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp5701472iob; Sun, 21 Nov 2021 09:12:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJx8PMI7HpkWN+2zTHOJqnFgqRT78EkmquRN9+SKdcN0hxACfTAi4xVoyg9HMBynwQfb3Hht X-Received: by 2002:a17:907:97cd:: with SMTP id js13mr30947711ejc.357.1637514749721; Sun, 21 Nov 2021 09:12:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637514749; cv=none; d=google.com; s=arc-20160816; b=vzxLzpdUzP3kGVgXQ51ZYYi5VqFT6Y/2p50j+IStsFDizQTi3aWq4ha2qUNr7oGN8E HoNBXoBj2Y8AhpJz+HzQp3eZq85JM7p0JMMazjJ76/9VFfpgxWyNKzQcgVB9o8UHlZzw YIG76ROSkfcr2hOtrbSHN4Nk4wx2f5noiOiBp0qxUzkQVBj7z6nDheVxDzO5V5pYVA9E 3ywjxRrHFqARm/he33X9ndwbADS5wliAc+6ETirWihcLe1uS6sTss7bqeY1TQiRonUp4 r5OJom3Sx78jwCwSmk/Vv42XTAavAxu9uDViG7EzsqR2c1mnE09+dLDET+xSFqUsaFgS o7iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=uAPFQXvzPP4sPRGHiYlM/OH3lJa+7rDO2SQBnFd6t+Y=; b=GqXKaqI/x9GFPPz3Sx6a8mXk45bbOPpZiI7J3E4boX6rNsb7yRNF/S21pKh2eC6vbR Q6EiUKY1erOUZzdkIA6A/JVx5bWK8AX49qJkx51WNDkGrwPZghijCRbx8xehNi3BAGbf k6V6syysU9cXLSTf+pMW9uSGWNpEUf1zWb9F5fVodsYLXe+Xhr+iVJhmuGrsyfrzOVah vBN4Qm+n/14vSey1ZQsUy6++ug9zm6C25bk7/paprnb0RokuGRznMZ9aLQK1AIFQN+pC b15NCsARsT/DPCz7574GLtLSfHQYvpkhBA4hPAEs6VNjNTxfOEPAo8GJK6sY4QBbifHo IfBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=IGd8fwvl; 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=QUARANTINE 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 n28si13374984edb.92.2021.11.21.09.12.27; Sun, 21 Nov 2021 09:12:29 -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=20210112 header.b=IGd8fwvl; 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=QUARANTINE 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 06AC768A958; Sun, 21 Nov 2021 19:12:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DF73068A54D for ; Sun, 21 Nov 2021 19:12:15 +0200 (EET) Received: by mail-pf1-f175.google.com with SMTP id n26so13970949pff.3 for ; Sun, 21 Nov 2021 09:12:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=EEvzmJ1TrAmxlp2QzuhHP0mlELfwafCx3Aw0oJ8cuQw=; b=IGd8fwvlS0Mm/v7nGT0Nr5jnuhUsyYzW7JK5wsY/i9cUZPLg7dZ3kKkE7gpOmHOm1k n2I4ErZnAcciQFQKQmgKZyj4iot2T2puwzsDZeoaJSkejK9sHRo1IaipIT8Y9KlDFTPr aIIkAGlptABPlWiI4jmaU36wHAJjTfNSzyHpHAKBqMq3TeoCSXCxyAJbPIpIubRAgER+ 6dgfTrzoV13pytLjGFCcAbOd1znQLTMxbUBeyL17ngB1fdhFAzj/F9kDEyeXZo6EY2qH xWyGmv8JcoQFHNGJqDUbPqARPlCthg1DGc2t8nleyCmrGnhhgCy3ppCXt3V2ITAjqJaI kcLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=EEvzmJ1TrAmxlp2QzuhHP0mlELfwafCx3Aw0oJ8cuQw=; b=0LnN/i+J/APku+HqO2ZPHB42SsoXLlP7Le19QJI12LSJ3BeXjP52/xeT2LOYEDjNbd UcNErfUpEv+MMIMYBFjZLXsgfPwSWH4Lg8jlV84Vlpjs3fsW2a7ZaieiavI+O5fJrixN iM1cya3QRmCqRE9iuvc3YknycgAwUB6VF8XSYdp1wH10Zuc7uxnI6j6HlyvXXWawwx8Z PqEqo48uDyUlaRPSj+maHkTlLuI6U/NcVLMLRqdCiOrFEKCgcTzbNbVgU01ecT5mjGhU ys1V53aaGQ9ZtubcvDtzecnqu7uIpTTGmXcmZEZFlafZVvGNs/tB7vMIIACFZhB1JVvx NB9Q== X-Gm-Message-State: AOAM532QmgeetywW4Pj3ADgmOsP3mQ4vcGQlE8d1zE6k+DO4JNgOj/aU nZLBnH4JkYAmscgljfb46FjNwl3ANfMBLRFw X-Received: by 2002:aa7:88cb:0:b0:49f:ad17:c08 with SMTP id k11-20020aa788cb000000b0049fad170c08mr78559901pff.19.1637514733201; Sun, 21 Nov 2021 09:12:13 -0800 (PST) Received: from localhost.localdomain (softbank126126237029.bbtec.net. [126.126.237.29]) by smtp.gmail.com with ESMTPSA id o2sm6313813pfu.206.2021.11.21.09.12.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Nov 2021 09:12:12 -0800 (PST) From: Ryoji Gyoda To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Nov 2021 02:06:20 +0900 Message-Id: <20211121170620.1756-1-gy.cft4@gmail.com> X-Mailer: git-send-email 2.24.1.windows.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] libavformat/fifo: avoid repeated failure and recovery X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Ryoji Gyoda Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: NSWoZZ1StWZa If fifo_thread_recover() succeeds immediately after fifo_thread_dispatch_message() fails, the dts of the packet is scaled twice, causing cur_dts to be abnormally large and "Application provided invalid, non monotonically increasing dts to muxer in stream" to occur repeatedly. Steps to reproduce: 1. ffmpeg -f lavfi -i testsrc -c:v libx264 -map 0:v -flags +global_header -f fifo -fifo_format flv -attempt_recovery 1 -recover_any_error 1 rtmp://example.com/livekey 2. set a breakpoint on fifo_thread_recover 3. force disconnect from the rtmp server 4. wait for break 5. reconnect to the rtmp server 6. resume execution of ffmpeg Signed-off-by: Ryoji Gyoda --- libavformat/fifo.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libavformat/fifo.c b/libavformat/fifo.c index 51d7fa5b94..e8caa6ec65 100644 --- a/libavformat/fifo.c +++ b/libavformat/fifo.c @@ -183,6 +183,7 @@ static int fifo_thread_write_packet(FifoThreadContext *ctx, AVPacket *pkt) AVFormatContext *avf2 = fifo->avf; AVRational src_tb, dst_tb; int ret, s_idx; + int64_t orig_pts, orig_dts, orig_duration; if (fifo->timeshift && pkt->dts != AV_NOPTS_VALUE) atomic_fetch_sub_explicit(&fifo->queue_duration, next_duration(avf, pkt, &ctx->last_received_dts), memory_order_relaxed); @@ -198,14 +199,24 @@ static int fifo_thread_write_packet(FifoThreadContext *ctx, AVPacket *pkt) } } + orig_pts = pkt->pts; + orig_dts = pkt->dts; + orig_duration = pkt->duration; s_idx = pkt->stream_index; src_tb = avf->streams[s_idx]->time_base; dst_tb = avf2->streams[s_idx]->time_base; av_packet_rescale_ts(pkt, src_tb, dst_tb); ret = av_write_frame(avf2, pkt); - if (ret >= 0) + if (ret >= 0) { av_packet_unref(pkt); + } + else { + // avoid scaling twice + pkt->pts = orig_pts; + pkt->dts = orig_dts; + pkt->duration = orig_duration; + } return ret; }