From patchwork Mon Dec 7 10:08:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 24378 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 60E3A44B3F9 for ; Mon, 7 Dec 2020 12:08:58 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 295516898E4; Mon, 7 Dec 2020 12:08:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7C50D6880C3 for ; Mon, 7 Dec 2020 12:08:51 +0200 (EET) Received: by mail-lf1-f67.google.com with SMTP id a9so17236300lfh.2 for ; Mon, 07 Dec 2020 02:08:51 -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:mime-version :content-transfer-encoding; bh=YqVYgz28pTl9gWCaO/4pkggLsXb7WDy1iAH51Qts14E=; b=eJ0hziR4wHhXsDrfyfuzWTwXoeBVGRSZQV72eso7Gxci/Zgm2VlkfvmKSTtDslGxl5 ItMj32gDjxVoY8PSKME3uO0kC1JglT+9yxuaAxwX3JYM7RgKfjwqSJbSj6vmOrUW5s4W zwbi2ZHftG0h+sZhdnnuNzJwQ9RND6MY5Fr1EmYqOpxQ7TKo3ThL4/6NoE7HXhbD57Kr y5yYIzFxN/G3/GqCTMD+3nAfyc9e/zbPQMvlimNJCjaXnNB7P0G4Qps3XN0EM6jTYoc6 3LlBUfhdvRanq7Aw2D1CJsIdDYB97B1TH5t7ovRLDvn7y0ng7EsJms2VinC0DqbypQX5 nzKw== 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:mime-version:content-transfer-encoding; bh=YqVYgz28pTl9gWCaO/4pkggLsXb7WDy1iAH51Qts14E=; b=B8EhpWfR/ZKDxjvyPDe9UKw4WYfHrRHmkCqgHQ/Gos9qCV9a/pNl44PZhlNnwDzJNI 9sex1kcPIrNcnRTGzC24vVlMNjIMxPLrWh29uUJb+5boNlC3BjyHbg7awIE4gH42u7v2 o4L1Z29YcDIG7LYK8v5OrzbBr7QikjHnv7CmD1EcJ3cMFFsziROxjdQwjujBOc7FzxUA wrPdH2HuDU8b+hodOMBrpiyQ1dRYGtGrLmn9UzGIaQt01bw8HFByeVGMT9vVPx0RwOrN 5ArR4B6+0omOcf1LPtnDuv1QpmD+DFWR2KfCICh0jgFb/AG2qZBARHz0F5CJDIX/ZrNQ qFew== X-Gm-Message-State: AOAM530NlDgwifVZ+QhWvi0i+8yQ6WvZ+fprGBraLd0oLq0CffB65HqE /KDIOaVIZ6AIAlUNJlS3T8X4yrOXt7RZFA== X-Google-Smtp-Source: ABdhPJwezMYVVokx1jI1OToWJ755Qbo+pvBJR/GM7vnZNbteZxRrV3nTxlSRrSjYGbVN1iOjKWNHMQ== X-Received: by 2002:a05:6512:3054:: with SMTP id b20mr7702946lfb.45.1607335730215; Mon, 07 Dec 2020 02:08:50 -0800 (PST) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id v5sm45061ljj.135.2020.12.07.02.08.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 02:08:49 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Dec 2020 12:08:41 +0200 Message-Id: <20201207100845.17520-2-jeebjp@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201207100845.17520-1-jeebjp@gmail.com> References: <20201207100845.17520-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] avformat/fifo: always wait recovery_wait_time between recoveries 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Bernard Boulay With various formats/protocols - for example fragmented mp4 over HTTP - success/failure might not appear right away. The header and first packet might get successfully written into the muxer, but a response of failure might appear only N packets later. In such a case, a recovery attempt would always be the "first time", and it would thus be executed without delay, causing effectively a DoS towards the server on the other side of the connection. Thus, modify the logic of the module so that it takes into account the last time recovery was attempted - even if it seemed to be successful: 1. Refactor update of last_recovery_ts to its own helper function. 2. Call this function even if the recovery is successful, thus ensuring that the time is always set. 3. Move initialization of last_recovery_ts to be handled together with the thread initialization. 4. Do not limit sleeping in recovery based on recovery_nr being nonzero ("not the first time of attempted recovery"). Signed-off-by: Jan Ekström --- libavformat/fifo.c | 54 +++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/libavformat/fifo.c b/libavformat/fifo.c index 17748e94ce5..55cbf14ae93 100644 --- a/libavformat/fifo.c +++ b/libavformat/fifo.c @@ -279,15 +279,10 @@ static void free_message(void *msg) av_packet_unref(&fifo_msg->pkt); } -static int fifo_thread_process_recovery_failure(FifoThreadContext *ctx, AVPacket *pkt, - int err_no) +static void fifo_thread_set_last_recovery_ts(FifoThreadContext *ctx, AVPacket *pkt) { AVFormatContext *avf = ctx->avf; FifoContext *fifo = avf->priv_data; - int ret; - - av_log(avf, AV_LOG_INFO, "Recovery failed: %s\n", - av_err2str(err_no)); if (fifo->recovery_wait_streamtime) { if (pkt->pts == AV_NOPTS_VALUE) @@ -297,6 +292,19 @@ static int fifo_thread_process_recovery_failure(FifoThreadContext *ctx, AVPacket } else { ctx->last_recovery_ts = av_gettime_relative(); } +} + +static int fifo_thread_process_recovery_failure(FifoThreadContext *ctx, AVPacket *pkt, + int err_no) +{ + AVFormatContext *avf = ctx->avf; + FifoContext *fifo = avf->priv_data; + int ret; + + av_log(avf, AV_LOG_INFO, "Recovery failed: %s\n", + av_err2str(err_no)); + + fifo_thread_set_last_recovery_ts(ctx, pkt); if (fifo->max_recovery_attempts && ctx->recovery_nr >= fifo->max_recovery_attempts) { @@ -329,27 +337,22 @@ static int fifo_thread_attempt_recovery(FifoThreadContext *ctx, FifoMessage *msg ctx->header_written = 0; } - if (!ctx->recovery_nr) { - ctx->last_recovery_ts = fifo->recovery_wait_streamtime ? - AV_NOPTS_VALUE : 0; - } else { - if (fifo->recovery_wait_streamtime) { - if (ctx->last_recovery_ts == AV_NOPTS_VALUE) { - AVRational tb = avf->streams[pkt->stream_index]->time_base; - time_since_recovery = av_rescale_q(pkt->pts - ctx->last_recovery_ts, - tb, AV_TIME_BASE_Q); - } else { - /* Enforce recovery immediately */ - time_since_recovery = fifo->recovery_wait_time; - } + if (fifo->recovery_wait_streamtime) { + if (ctx->last_recovery_ts == AV_NOPTS_VALUE) { + AVRational tb = avf->streams[pkt->stream_index]->time_base; + time_since_recovery = av_rescale_q(pkt->pts - ctx->last_recovery_ts, + tb, AV_TIME_BASE_Q); } else { - time_since_recovery = av_gettime_relative() - ctx->last_recovery_ts; + /* Enforce recovery immediately */ + time_since_recovery = fifo->recovery_wait_time; } - - if (time_since_recovery < fifo->recovery_wait_time) - return AVERROR(EAGAIN); + } else { + time_since_recovery = av_gettime_relative() - ctx->last_recovery_ts; } + if (time_since_recovery < fifo->recovery_wait_time) + return AVERROR(EAGAIN); + ctx->recovery_nr++; if (fifo->max_recovery_attempts) { @@ -372,6 +375,7 @@ static int fifo_thread_attempt_recovery(FifoThreadContext *ctx, FifoMessage *msg } } else { av_log(avf, AV_LOG_INFO, "Recovery successful\n"); + fifo_thread_set_last_recovery_ts(ctx, pkt); ctx->recovery_nr = 0; } @@ -389,7 +393,7 @@ static int fifo_thread_recover(FifoThreadContext *ctx, FifoMessage *msg, int err int ret; do { - if (!fifo->recovery_wait_streamtime && ctx->recovery_nr > 0) { + if (!fifo->recovery_wait_streamtime) { int64_t time_since_recovery = av_gettime_relative() - ctx->last_recovery_ts; int64_t time_to_wait = FFMAX(0, fifo->recovery_wait_time - time_since_recovery); if (time_to_wait) @@ -420,6 +424,8 @@ static void *fifo_consumer_thread(void *data) memset(&fifo_thread_ctx, 0, sizeof(FifoThreadContext)); fifo_thread_ctx.avf = avf; fifo_thread_ctx.last_received_dts = AV_NOPTS_VALUE; + fifo_thread_ctx.last_recovery_ts = fifo->recovery_wait_streamtime ? + AV_NOPTS_VALUE : 0; while (1) { uint8_t just_flushed = 0; From patchwork Mon Dec 7 10:08:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 24385 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 365B744AA24 for ; Mon, 7 Dec 2020 12:16:08 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1CE31689997; Mon, 7 Dec 2020 12:16:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 58368688041 for ; Mon, 7 Dec 2020 12:16:01 +0200 (EET) Received: by mail-wr1-f65.google.com with SMTP id 91so8244658wrj.7 for ; Mon, 07 Dec 2020 02:16:01 -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:mime-version :content-transfer-encoding; bh=+rZf2bJsAhkUbshEycL53r8Qw24N5jAJa2fiHFcpov4=; b=S9NKSCvlVUjgpuorF4T7gd/z8gJSAIITw5mtG3QlNA6t+cGkDV1O1sOylOSzv399PC zmXDH+2PHMnjlUR1bW3r87UPAdx25/GSNM1p/J20U33QUpK9pA2UiqeUE/uSTv2OTifl gM2eYJctmWB8xBVvx4VIbuT2EXo3qFhuxG1B3dnkNvYXiBz/nAVzpV3LcDd2xjPNZo78 4KVmyA2Tjl6oKp2RURfKeGuJ0iBnLoc5AzqJMCWVejhRQRdNXeuYpdIWmOSwhQkRib7I PaFy8Hq/Veqn2WIvvzcg2roDjdDEs211dAtXGr+05DxDG+X+5Vx2naJKaX9xQSvkg1XE kg9g== 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:mime-version:content-transfer-encoding; bh=+rZf2bJsAhkUbshEycL53r8Qw24N5jAJa2fiHFcpov4=; b=cY70oMivC1l3wmqxIRRImOlzThLe2Go4ttUBElu4SL9jyA9NJjihBl29+yiUoSz0wn OCQrJefdPqaEvbWPq3khbuTv7J27/aK9gSkJtYwQExVJQpZCf3OfZTt7kXSsNbXsv8yk UYs0Bsunk5jSqbLdCyCrdB5qpwRle79lvwWuc+GZnjmdcvOgz719sGnEQVYDPu6x013Z tPOc0VSxSFEDa5C/o9BVplcb43O8bxOOq6e/7B/lRfCLvR1y5scgIkBNjyh75MiPqyI1 LbU1ORD7QLgoevRZsk38Lxsu5FbH5YTAKoOByfMppHZi4wAzDDdDlRTZR7I+kw4wB5On RmxA== X-Gm-Message-State: AOAM531HtiZ+EC7z/WszFH8NGuaRCl+cNKuBkPCKuJdXU4LVn79J+NKg +TbcXolbbJ+9JNvA1PgWvFJlKHA/78gxKg== X-Google-Smtp-Source: ABdhPJxIC51dX8YLGx6TPZ4/CxUIOZ542c2DpGPa+er9GT8zcNJ3eLaVB8QdMyogucLK4SwABh47yw== X-Received: by 2002:a05:651c:147:: with SMTP id c7mr7945899ljd.455.1607335731067; Mon, 07 Dec 2020 02:08:51 -0800 (PST) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id v5sm45061ljj.135.2020.12.07.02.08.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 02:08:50 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Dec 2020 12:08:42 +0200 Message-Id: <20201207100845.17520-3-jeebjp@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201207100845.17520-1-jeebjp@gmail.com> References: <20201207100845.17520-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] avformat/fifo: fix handling of stream-time non-NOPTS recovery 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Jan Ekström Until now the proper diff between last_recovery_ts and packet's pts was only done when last_recovery_ts was AV_NOPTS_VALUE. This is kind of an oxymoron as the result of comparing that difference to AV_NOPTS_VALUE most likely always be relatively large. Thus, move the immediate recovery to when last_recovery_ts is AV_NOPTS_VALUE, and do a proper difference between the values otherwise. Signed-off-by: Jan Ekström --- libavformat/fifo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavformat/fifo.c b/libavformat/fifo.c index 55cbf14ae93..b940d0dafe1 100644 --- a/libavformat/fifo.c +++ b/libavformat/fifo.c @@ -339,12 +339,12 @@ static int fifo_thread_attempt_recovery(FifoThreadContext *ctx, FifoMessage *msg if (fifo->recovery_wait_streamtime) { if (ctx->last_recovery_ts == AV_NOPTS_VALUE) { + /* Enforce recovery immediately */ + time_since_recovery = fifo->recovery_wait_time; + } else { AVRational tb = avf->streams[pkt->stream_index]->time_base; time_since_recovery = av_rescale_q(pkt->pts - ctx->last_recovery_ts, tb, AV_TIME_BASE_Q); - } else { - /* Enforce recovery immediately */ - time_since_recovery = fifo->recovery_wait_time; } } else { time_since_recovery = av_gettime_relative() - ctx->last_recovery_ts; From patchwork Mon Dec 7 10:08:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 24379 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9C36144B3F9 for ; Mon, 7 Dec 2020 12:08:59 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 81DB468990E; Mon, 7 Dec 2020 12:08:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f66.google.com (mail-lf1-f66.google.com [209.85.167.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0BA136803CE for ; Mon, 7 Dec 2020 12:08:53 +0200 (EET) Received: by mail-lf1-f66.google.com with SMTP id w13so4521506lfd.5 for ; Mon, 07 Dec 2020 02:08:53 -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:mime-version :content-transfer-encoding; bh=l55uMEVI/k8wvJCWYRlep/88h4EHc3G5mB2XiVlSj2g=; b=Ah80lT3D3uRFHJm/bYVBaaDYCUsMtv9bVd5LpQd9UW4Fa1CekfKFq3pawsa8KFKA6j 61NCylJdRNnMHpfgBCdbNSJqXrgXA77tA38mYP28iATJ1FZAGhh55XzLKkg4CCG610n2 Rna8joVf85luv6xZPuLrx8BPKSE2Wxc47eeDSJSieiS13N9W1wJgSk98e4XLiV01wxyp yVvfvKlGjA+5lQgmh47ZqmpJBfGRhnpxyu0su3d1x0CJnA4lE7RDNljzglkDpWodCyY9 bmYIVnrnKmpyLfeRHeFSBBcmRknZZNfzOb/WCtyU4RIaekwkSowjYtYf1qycCoIFVYlY qXgA== 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:mime-version:content-transfer-encoding; bh=l55uMEVI/k8wvJCWYRlep/88h4EHc3G5mB2XiVlSj2g=; b=IFmg+q5Zg13r/lwkkZsFTzVelU/m5FAyra7tPoOQXAWk2sor+wHaSu3t5AGW0cQgpm n5OApSra9999MApVxpXzSQ2B4qK6LqCp3/EbeBz9aX+3fwFdD3sym/u7inMBweX2DIbw g2w/o/s6A1jYmCXLE4fIavJWZHuEv1F7rHWxz4zFYdz4SAoeZaCiEcqXggeR4J4nOyX3 3H1gkD7kOY1wbxNFBpEL1f9uONlVzJxrphercaET/dr+atbS2bebFonxGjBdz4mBHWWF UCt1pYSbXxltZeN4PzEL3L08GUH9RuwQvyK5W7hn85uw7hqyd+ercGPIe9VL2fgIKv4a gT3g== X-Gm-Message-State: AOAM533CbWzbN8klbUoHNNZdhb8SxafVkl2XoWHtOg9B91QVGkM2q9gW c33pH5WvUS3z/uXGwZa/VXZ5luTwi/R5hg== X-Google-Smtp-Source: ABdhPJwNO+ruXjQ4f33rR5NQQMOnJMdkWcpXtFCQyi5QnzplbjbBi7ZRZ6UOVVRepiTyEzfqVo4oKg== X-Received: by 2002:ac2:5b1e:: with SMTP id v30mr3140432lfn.540.1607335731902; Mon, 07 Dec 2020 02:08:51 -0800 (PST) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id v5sm45061ljj.135.2020.12.07.02.08.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 02:08:51 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Dec 2020 12:08:43 +0200 Message-Id: <20201207100845.17520-4-jeebjp@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201207100845.17520-1-jeebjp@gmail.com> References: <20201207100845.17520-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] avformat/fifo: cause immediate stream-time recovery if time went backwards 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Jan Ekström This way discontinuities backwards could also get handled (albeit they generally tend to be incorrect to begin with on this layer of avformat). Signed-off-by: Jan Ekström --- libavformat/fifo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavformat/fifo.c b/libavformat/fifo.c index b940d0dafe1..9fc524adbdf 100644 --- a/libavformat/fifo.c +++ b/libavformat/fifo.c @@ -338,7 +338,8 @@ static int fifo_thread_attempt_recovery(FifoThreadContext *ctx, FifoMessage *msg } if (fifo->recovery_wait_streamtime) { - if (ctx->last_recovery_ts == AV_NOPTS_VALUE) { + if (ctx->last_recovery_ts == AV_NOPTS_VALUE || + pkt->pts < ctx->last_recovery_ts) { /* Enforce recovery immediately */ time_since_recovery = fifo->recovery_wait_time; } else { From patchwork Mon Dec 7 10:08:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 24382 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id D11D444B3F9 for ; Mon, 7 Dec 2020 12:09:01 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B5AA8689A09; Mon, 7 Dec 2020 12:09:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7B35E6897E4 for ; Mon, 7 Dec 2020 12:08:54 +0200 (EET) Received: by mail-lf1-f44.google.com with SMTP id u19so17231120lfr.7 for ; Mon, 07 Dec 2020 02:08:54 -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:mime-version :content-transfer-encoding; bh=T57zhgFa/vIKHIGmkdagj2Hh1id67cZt4nTeUAe0UYA=; b=rCxL/gGmOJ+hsDoGn1J8CQmI68jSLIBn5DCLSTVlnmw2jrJnU6a27AJD2sofJtUcj9 D/XfE8567SUxPzxjhQ6Fu8TYa6lxpO//H99poq9E4qyHBilgpGeRP2dSjjBt6+v9N1/h ibqCVIaeV2uj4NavUZlFFH7PoCySUZfA6ZGt91rPHYwsIGITucJLhGvHbu21ZW0YVNPF 4sc2hQoT6PlCzfHQo1Dn02TWcG4QEHaTs1EC0Na53Xw6ajHmNTilyQdr9tzQIkrh8dyd dHBDyxYdkhC1/LofeasGP0vsN0DbGujNcPVBMHC0RLWuBGCGjrI7hilMEL0JMJYPAL2+ wsKQ== 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:mime-version:content-transfer-encoding; bh=T57zhgFa/vIKHIGmkdagj2Hh1id67cZt4nTeUAe0UYA=; b=TsaaDkd8QKEQuxehPR4TlyQB+zee2RK0iwBk7L1mJsicBgMDGog10/K7FtXE+eqolN pbweO8V2Ld0bqB3W/hY/9jsdgM7qjyhU6IZYYwM34NVGHP3Qe1HW68SCFBeEMOL6R7yt n8VYevNMIMFr/WEJXArYqaWOMLU6Jn09LKiXIwAo4jJia4tp5Uw9aAYIT962N65FJ+AD 6lexoZyah443H9xBxqroyfMYpStqJqo0ING4xM5gBqtvddfJO+k/cF64hXklXDzIUQU8 cT3pBStCRs+xpPuT0nF+jnpcIX3+WULHQSocPTWlnj7C32PldQC1eYxoHrxdAuNdikNp tb/w== X-Gm-Message-State: AOAM532ONZrhUmod33Kb4ohgGmtqHIGopI709IqfrDDjC7d9pfDoqk2t kpQyRRasyYPJ05iA6mhNW0IEuB3aT0bbIQ== X-Google-Smtp-Source: ABdhPJwwtNd36t3z4YTKos537H0IHzSyz1p5Q2MVauLupHN+K0HCZu4NTYz9EWz5cEFHU0CrKzdP7A== X-Received: by 2002:a19:7415:: with SMTP id v21mr1453335lfe.343.1607335732856; Mon, 07 Dec 2020 02:08:52 -0800 (PST) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id v5sm45061ljj.135.2020.12.07.02.08.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 02:08:52 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Dec 2020 12:08:44 +0200 Message-Id: <20201207100845.17520-5-jeebjp@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201207100845.17520-1-jeebjp@gmail.com> References: <20201207100845.17520-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/5] avformat/fifo: close IO in case header writing fails 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Jan Ekström Otherwise each new attempt will leave its connection open. Signed-off-by: Jan Ekström --- libavformat/fifo.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libavformat/fifo.c b/libavformat/fifo.c index 9fc524adbdf..bc363e458cd 100644 --- a/libavformat/fifo.c +++ b/libavformat/fifo.c @@ -142,8 +142,14 @@ static int fifo_thread_write_header(FifoThreadContext *ctx) avf2->streams[i]->cur_dts = 0; ret = avformat_write_header(avf2, &format_options); - if (!ret) - ctx->header_written = 1; + if (ret < 0) { + av_log(avf2, AV_LOG_ERROR, + "Failed to write format header: %s\n", av_err2str(ret)); + ff_format_io_close(avf2, &avf2->pb); + goto end; + } + + ctx->header_written = 1; // Check for options unrecognized by underlying muxer if (format_options) { From patchwork Mon Dec 7 10:08:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 24421 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:c00a:0:0:0:0:0 with SMTP id c10csp2488564ybf; Mon, 7 Dec 2020 02:15:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzB1c//BjhBB9nWxXxGB64vcwUUgFP7/GhmxOUUQ2jRuQADAHjEhsEKd41Ibr60L50eUgug X-Received: by 2002:adf:81a2:: with SMTP id 31mr5905712wra.381.1607336142263; Mon, 07 Dec 2020 02:15:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607336142; cv=none; d=google.com; s=arc-20160816; b=v7SJGv/yFU2GpdITFiVtwnCpjE1NN4+FUHcdkCTa/1kBOk/5qD7WfW9VzwjW0CWuPJ BipA77rV/16bCpPdndLoUsnj8i8EaC7/d2nfI3Rd4i0Zhty031SSLDeX2gcmg86Fe5Zb dAXrwqXND//vpyr6nWMpaxKZpk3jWILKVeGlAPb8/7nx33h0ZYU4Gn7SixC3S7weAg3A Pgxm8FLC6573F6Oc2it8E2KY5tFiTm6365aJqay3Ka36bgk+FaHV5/RcA+Aolu49gFOY tgSV31udCGwf2TY5DnPkNlZWii63pQ3VG2WSVxIYeBR6FYjL+ArGzwks3B4fthOgWy3Z 3bJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=ltZ4onsWZmJeqqBXz5ZeaAqj3qTQGNCs22oECs2ukCY=; b=W8cIT7GuVYDmBv/ymXjzY0dlHuAlLztkOfNEqEe8cP7esAs7xM4JskLHQCGDo3PQoY BbI2a2+F9kFxu029LBXOAS9tHc2Ok8u0N038VEWicCaVZmA/NQaXByjMAYZO/DcPrQWD gyYNGxGNviarjLDbixU0AsHidUUxCGy80jvpXd0kYf2Ro4Y0XlqpQNi/8el99JOWhuWe l4aikhpXAPQeCg32f/J4sh4O2Xe5Vzh1jgP7vMjrBNN9X7L02Li97AtMz58Upq5pmnru o4NTy3r0jqqRwYgnL/ot9ZMcDaAVeLd1adEeLH4L9Av34BvozzrxeanrwEhNtmtXV1g3 e9Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=I2jSdT0z; 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 4si10865342wrl.90.2020.12.07.02.15.41; Mon, 07 Dec 2020 02:15:42 -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=I2jSdT0z; 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 205DC689B32; Mon, 7 Dec 2020 12:15:41 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D25A66809D2 for ; Mon, 7 Dec 2020 12:15:34 +0200 (EET) Received: by mail-lf1-f68.google.com with SMTP id u19so17258014lfr.7 for ; Mon, 07 Dec 2020 02:15:34 -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:mime-version :content-transfer-encoding; bh=MmjPQQdGze+Wmau/c/SiJ+Hq9tXkpBUAkWyTsT2fwS8=; b=I2jSdT0zHrifK9hGnfmVnDQxcVeFj39IElik1xl92ItMVeHJQwU9X/ibZHZpTNP+g/ kT/f5phPLGIavGJ3P9LY3UGBZfvC1bSJT2qVUcpix+GZPs+pRPGTMmpwg2LLvZQUZI8n kME/UPEaabhY4qDKKrxmXJWHMagwHlqpjhhBNwu1kUjMWBILP2eyaHcfjaIhRAd+bwfx MyCN38VfEaM8+SBSP3gVP/MCQvASFIFo4z+5ofpgtPLYSGHZy3Gr/kGfxiWcQb0pHoWA YE8uJzpm9vBtxjzWW0KiE2yCITgeRDVgRLgiozNz893FG1YmyC1ym9VQpdFWTcHOB/Jy u3RA== 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:mime-version:content-transfer-encoding; bh=MmjPQQdGze+Wmau/c/SiJ+Hq9tXkpBUAkWyTsT2fwS8=; b=r0XD+TQv2JT4q4OPoxhpO7ua/Atk4FCpEkmALsVyDp4iRzSv06RtyOxpOI2XedCTRo aIrfcH2eEELLNLk8Hes3ecV+K6uPhfwEqxVOv9OHPAMUPU0ukXYW0NOKyE9sAlUNeXk9 C/aJXDq9Zn2ZWONLimeAg0pYOcDJUmr7YM06cwbiog8cxXpLArb6XNh88pypgevB7Svp Vd4vPnazzqlXbpExu8/DcmXY4Tq3CPb0OP/UfzZekUt2RS3+0gXPDaxvVtVsLbJwY/KB K3qYgMavQ7v0Cs76aIsDNDUfY2ruXD9jjTjVBdpaib+EkGFSlTmEL9QpecgVVdph5eq1 WjfA== X-Gm-Message-State: AOAM530b7jpoe65XQ40ndGIphP6Ahe5bxf650m4CmXKqKWzut5ZXTDR1 4DAJPj3CHhpcO6raLSgeHZrONo85MvAIZA== X-Received: by 2002:a2e:9b4d:: with SMTP id o13mr405792ljj.163.1607335734103; Mon, 07 Dec 2020 02:08:54 -0800 (PST) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id v5sm45061ljj.135.2020.12.07.02.08.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 02:08:53 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Dec 2020 12:08:45 +0200 Message-Id: <20201207100845.17520-6-jeebjp@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201207100845.17520-1-jeebjp@gmail.com> References: <20201207100845.17520-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] avformat/fifo: unset codec tag if unsupported by underlying muxer 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: iaMEIsKIZh4F Content-Length: 2233 From: Jan Ekström The API client has no visibility into the values provided by the underlying muxer, so we either do this always, or when an option is presented. In this case, we do it unconditionally, as this is probably more useful. Signed-off-by: Jan Ekström --- libavformat/fifo.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libavformat/fifo.c b/libavformat/fifo.c index bc363e458cd..c9b782c2309 100644 --- a/libavformat/fifo.c +++ b/libavformat/fifo.c @@ -513,6 +513,18 @@ static int fifo_mux_init(AVFormatContext *avf, ff_const59 AVOutputFormat *oforma ret = ff_stream_encode_params_copy(st, avf->streams[i]); if (ret < 0) return ret; + + if ((st->codecpar->codec_tag && oformat->codec_tag) && + av_codec_get_id(oformat->codec_tag, st->codecpar->codec_tag) != st->codecpar->codec_id) { + av_log(avf, AV_LOG_ERROR, + "Codec tag '%s' is unsupported for codec %s in the %s muxer! " + "Unsetting codec tag so that auto-configuration can be " + "attempted.\n", + av_fourcc2str(st->codecpar->codec_tag), + avcodec_get_name(st->codecpar->codec_id), + avf2->oformat->name); + st->codecpar->codec_tag = 0; + } } return 0;