From patchwork Wed Aug 3 13:58:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37117 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp459839pzb; Wed, 3 Aug 2022 07:02:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vUZymeFaDzcvgL8cY2NmDjpEp2evxb2MkssfYOz0Ue73U2NVTbh4S1nxmwxUO8clDTZDNu X-Received: by 2002:a17:906:6a21:b0:72f:2174:16e6 with SMTP id qw33-20020a1709066a2100b0072f217416e6mr20545052ejc.177.1659535353742; Wed, 03 Aug 2022 07:02:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535353; cv=none; d=google.com; s=arc-20160816; b=ZYkWQm+TC3prSOknWwCs/AOiDu+oqAEr7nVPomTXUKawHaKShWlejP621dCfsvPJ7e DwWqQo9FrSNGK5PzhOSz49JGXqOT0WyLfPs4GWt/sPoT7KJngMnQixlDu+oD64bLz1Zc Ljkn4nZsBP5GM24i5bPeEpFH7Mxzoa2JbCSKR3ycZkeVAhXezEebEmn6JGRt2lct2Cpo 4uYgTso4sR8aRx6pB6Re3TgWXht0kWHvh8E6VtM+UUaBAF3FA09uXPWfAbOBC+IFIKAo hgcxx7p6f7W53UX3k1Lo3cNoFf/mq8viznb/3fETlK+uTRhGDFE75xcxesceG0s3wzHm Asdw== 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:delivered-to; bh=K9jo3bk9SzPWr4Qd0LE6r3H2+N/cf/j5hOgLOI+H0WI=; b=DEsVLKTDCTaSO1FPCs4v8tJ5Ao6/w7mVI3D34LvLDyXdlHpHYw8S54EKnJ5BTaipNi avyODrcOiHVmQHsXJvBZPLM3z6DDG9A0Pe4ox5PS9Ap9cSBUfhp29sb8RoyL9Rx40ql+ rxAkG9Bm+2GYDSIhOUQf7LIPG1s855xh2g/tPqWhnO97xNHEuzOflKbpdCDbpO7mDZxt Fnkon5GPLlYRQHAQBnZCNew9Zh4sFfk2PXzauVAaZ82Ew3NWuz8DpBoukAWLCl41zdE7 mNzfpCXmjBU902zwzv2KlUUI6XwTDbtB0sqghxqDI5Gr8+GJrlA5za0EcjWLR1Jhz2JV jHVg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qf21-20020a1709077f1500b007262c51b07dsi9324183ejc.724.2022.08.03.07.02.27; Wed, 03 Aug 2022 07:02:33 -0700 (PDT) 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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 655E468B9C2; Wed, 3 Aug 2022 16:59:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 70E0F68B89E for ; Wed, 3 Aug 2022 16:59:02 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B496224052D for ; Wed, 3 Aug 2022 15:59:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 4JsodODxBl6l for ; Wed, 3 Aug 2022 15:59:00 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id EBB70240555 for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 3AA9E3A05F9; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:38 +0200 Message-Id: <20220803135844.16662-19-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/25] fftools/ffmpeg: report new streams from the input thread 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 3x2MkAKVKBJ3 This avoids a potential race with the demuxer adding new streams. It is also more efficient, since we no longer do inter-thread transfers of packets that will be just discarded. --- fftools/ffmpeg.c | 22 ---------------------- fftools/ffmpeg_demux.c | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 1393ca9c1e..37f52f0208 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3277,21 +3277,6 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, return ret; } -static void report_new_stream(int input_index, AVPacket *pkt) -{ - InputFile *file = input_files[input_index]; - AVStream *st = file->ctx->streams[pkt->stream_index]; - - if (pkt->stream_index < file->nb_streams_warn) - return; - av_log(file->ctx, AV_LOG_WARNING, - "New %s stream %d:%d at pos:%"PRId64" and DTS:%ss\n", - av_get_media_type_string(st->codecpar->codec_type), - input_index, pkt->stream_index, - pkt->pos, av_ts2timestr(pkt->dts, &st->time_base)); - file->nb_streams_warn = pkt->stream_index + 1; -} - static int transcode_init(void) { int ret = 0, i, j, k; @@ -3831,13 +3816,6 @@ static int process_input(int file_index) reset_eagain(); - /* the following test is needed in case new streams appear - dynamically in stream : we ignore them */ - if (pkt->stream_index >= ifile->nb_streams) { - report_new_stream(file_index, pkt); - goto discard_packet; - } - ist = input_streams[ifile->ist_index + pkt->stream_index]; ist->data_size += pkt->size; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index f9bd6d47fe..66cb6ebd5f 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -20,6 +20,7 @@ #include "libavutil/error.h" #include "libavutil/time.h" +#include "libavutil/timestamp.h" #include "libavutil/thread.h" #include "libavutil/threadmessage.h" @@ -27,6 +28,20 @@ #include "libavformat/avformat.h" +static void report_new_stream(InputFile *file, AVPacket *pkt) +{ + AVStream *st = file->ctx->streams[pkt->stream_index]; + + if (pkt->stream_index < file->nb_streams_warn) + return; + av_log(file->ctx, AV_LOG_WARNING, + "New %s stream %d:%d at pos:%"PRId64" and DTS:%ss\n", + av_get_media_type_string(st->codecpar->codec_type), + file->index, pkt->stream_index, + pkt->pos, av_ts2timestr(pkt->dts, &st->time_base)); + file->nb_streams_warn = pkt->stream_index + 1; +} + static void *input_thread(void *arg) { InputFile *f = arg; @@ -51,6 +66,14 @@ static void *input_thread(void *arg) f->ctx->streams[pkt->stream_index]); } + /* the following test is needed in case new streams appear + dynamically in stream : we ignore them */ + if (pkt->stream_index >= f->nb_streams) { + report_new_stream(f, pkt); + av_packet_unref(pkt); + continue; + } + queue_pkt = av_packet_alloc(); if (!queue_pkt) { av_packet_unref(pkt);