From patchwork Tue May 23 13:58:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41808 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp602708pzb; Tue, 23 May 2023 07:02:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ49OUn9RPkFYkDJ6dMt6nIcMynfndNaESVE5LIFfKaa9vmQ9hqfyE9zXY+gOcVsd8q/iOHm X-Received: by 2002:a05:6402:357:b0:50d:682d:d431 with SMTP id r23-20020a056402035700b0050d682dd431mr12014666edw.16.1684850523956; Tue, 23 May 2023 07:02:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850523; cv=none; d=google.com; s=arc-20160816; b=Mvpu0shgljTbePZfbjxMm80DqvEfTix285m/WCxwdEfBQuTT0G6uJNaFxwp8cw6Rw4 HwrXpOA5WMkai+NFz2xSFIy2mAkA4sEG8L0NePa5sGa/6SOzk9F8iHD6dFiPEQMw9zuf 2Y426T5nYJxdMonEwFZmZd9+CByiK/8oWOHQCmCKRuxVhTm+yyqvVWIn6aJAnG9AFGJl z7gyDGQwG5/6vDOa7o5UAePH0SjKxY4MozwErNfGQxFrMhOlHM/YveZW46X/ymzpVy9C tFGY9VFxDvk4JCmNvuLVktwSzTjxugewbKxfKElGaGvMDUVaZCxMhmCL+5SmXLMPYjzy eUIA== 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=tvSE1C8njJNBg8RALwsQb/DV4wFywmYMdwhnT8q1NhI=; b=dRySUdxKdM6zcjoeLSLVPoV4ArOTPXrWOOiO/3pDHcp7MN5/YiyknxbgXlVyhhF4m+ kOqQf8r6T6NU4xo8bezm5sENU6GxTe+L/JXeJgLwdnyYKClFcUQk6a8KoW7/Za1TVJB7 dYvMfsDWNK1EK6yvt4k2HdK4VmYs4qfhzxowv6dXM+FxXBoU+iBVXe1ruBvxCoIMSOZ/ RjcXiHy7K7pT0V+IslWqp2cwfDfaFvWVjs9HqnDt4WksjVPHDu/2ayxlofEk47M9fXoj RbBMm3heUR4juBV+4p386uo45HtNc5LwVtil0gfq23sZlCgnvnj+Pnawbzl9Q6Bjhnai A/Cg== 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 t20-20020aa7d4d4000000b0050bc68690bdsi2190690edr.343.2023.05.23.07.02.03; Tue, 23 May 2023 07:02:03 -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 194A968C17E; Tue, 23 May 2023 16:59:19 +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 5430368C118 for ; Tue, 23 May 2023 16:59:05 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 0C5D32404EC for ; Tue, 23 May 2023 15:59:05 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id bWom122nXB6q for ; Tue, 23 May 2023 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 AB3E12406CC for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9D4E23A048F for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:39 +0200 Message-Id: <20230523135842.20388-12-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/15] fftools/ffmpeg: add InputStream.index 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: K+s6zVVDih8K This allows to avoid access to the underlying AVStream in many places. --- fftools/ffmpeg.c | 6 +++--- fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_dec.c | 6 +++--- fftools/ffmpeg_demux.c | 1 + fftools/ffmpeg_filter.c | 10 +++++----- fftools/ffmpeg_mux_init.c | 2 +- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 1fc13b3e29..0539a45856 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -539,7 +539,7 @@ OutputStream *ost_iter(OutputStream *prev) InputStream *ist_iter(InputStream *prev) { int if_idx = prev ? prev->file_index : 0; - int ist_idx = prev ? prev->st->index + 1 : 0; + int ist_idx = prev ? prev->index + 1 : 0; for (; if_idx < nb_input_files; if_idx++) { InputFile *f = input_files[if_idx]; @@ -937,7 +937,7 @@ static void print_stream_maps(void) for (int j = 0; j < ist->nb_filters; j++) { if (!filtergraph_is_simple(ist->filters[j]->graph)) { av_log(NULL, AV_LOG_INFO, " Stream #%d:%d (%s) -> %s", - ist->file_index, ist->st->index, ist->dec ? ist->dec->name : "?", + ist->file_index, ist->index, ist->dec ? ist->dec->name : "?", ist->filters[j]->name); if (nb_filtergraphs > 1) av_log(NULL, AV_LOG_INFO, " (graph %d)", ist->filters[j]->graph->index); @@ -967,7 +967,7 @@ static void print_stream_maps(void) av_log(NULL, AV_LOG_INFO, " Stream #%d:%d -> #%d:%d", ost->ist->file_index, - ost->ist->st->index, + ost->ist->index, ost->file_index, ost->index); if (ost->enc_ctx) { diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index d9cac95710..95334825ef 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -330,6 +330,8 @@ typedef struct InputStream { const AVClass *class; int file_index; + int index; + AVStream *st; int discard; /* true if stream data should be discarded */ int user_set_discard; diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index c952473c16..afb2612ae8 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -470,7 +470,7 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) update_benchmark(NULL); ret = avcodec_receive_frame(dec, frame); update_benchmark("decode_%s %d.%d", type_desc, - ist->file_index, ist->st->index); + ist->file_index, ist->index); if (ret == AVERROR(EAGAIN)) { av_assert0(pkt); // should never happen during flushing @@ -528,7 +528,7 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) ret = video_frame_process(ist, frame); if (ret < 0) { av_log(NULL, AV_LOG_FATAL, "Error while processing the decoded " - "data for stream #%d:%d\n", ist->file_index, ist->st->index); + "data for stream #%d:%d\n", ist->file_index, ist->index); exit_program(1); } } @@ -577,7 +577,7 @@ static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat "%s hwaccel requested for input stream #%d:%d, " "but cannot be initialized.\n", av_hwdevice_get_type_name(config->device_type), - ist->file_index, ist->st->index); + ist->file_index, ist->index); return AV_PIX_FMT_NONE; } continue; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index e02bdc3b96..828a1182f0 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -1025,6 +1025,7 @@ static DemuxStream *demux_stream_alloc(Demuxer *d, AVStream *st) ds->ist.st = st; ds->ist.file_index = f->index; + ds->ist.index = st->index; ds->ist.class = &input_stream_class; snprintf(ds->log_name, sizeof(ds->log_name), "%cist#%d:%d/%s", diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 640ecec067..f37b867b31 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1073,7 +1073,7 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, if (fr.num && fr.den) av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den); snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index, - ist->file_index, ist->st->index); + ist->file_index, ist->index); if ((ret = avfilter_graph_create_filter(&ifilter->filter, buffer_filt, name, @@ -1127,7 +1127,7 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, } snprintf(name, sizeof(name), "trim_in_%d_%d", - ist->file_index, ist->st->index); + ist->file_index, ist->index); if (copy_ts) { tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time; if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE) @@ -1180,7 +1180,7 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, } else av_bprintf(&args, ":channels=%d", ifp->ch_layout.nb_channels); snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index, - ist->file_index, ist->st->index); + ist->file_index, ist->index); if ((ret = avfilter_graph_create_filter(&ifilter->filter, abuffer_filt, name, args.str, NULL, @@ -1189,7 +1189,7 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, last_filter = ifilter->filter; snprintf(name, sizeof(name), "trim for input stream %d:%d", - ist->file_index, ist->st->index); + ist->file_index, ist->index); if (copy_ts) { tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time; if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE) @@ -1574,7 +1574,7 @@ int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb) ifp->type_src == AVMEDIA_TYPE_VIDEO)) { av_log(NULL, AV_LOG_ERROR, "Cannot determine format of input stream %d:%d after EOF\n", - ifp->ist->file_index, ifp->ist->st->index); + ifp->ist->file_index, ifp->ist->index); return AVERROR_INVALIDDATA; } } diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 56f9d1215c..dc33d225df 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -792,7 +792,7 @@ static void new_stream_audio(Muxer *mux, const OptionsContext *o, ist = ost->ist; } - if (!ist || (ist->file_index == map->file_idx && ist->st->index == map->stream_idx)) { + if (!ist || (ist->file_index == map->file_idx && ist->index == map->stream_idx)) { if (av_reallocp_array(&ost->audio_channels_map, ost->audio_channels_mapped + 1, sizeof(*ost->audio_channels_map)