From patchwork Mon Sep 23 15:01:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51756 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d154:0:b0:48e:c0f8:d0de with SMTP id bt20csp2517198vqb; Mon, 23 Sep 2024 08:02:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWS5K2FnVGKwXrenhySj2x8hs+tNR/bjiM1ZFaPGLDXxmcP7Z1Gr8RDj+yhOEKs18QnCX++JsqisA3BsdT7W5pN@gmail.com X-Google-Smtp-Source: AGHT+IFbwGTHAjDYbvNHsU3PGh8d7bQ/+GY7qxh2FQI9eDHitiSU33UJMkGRPLNKPp8iu6S0y46d X-Received: by 2002:a2e:bea6:0:b0:2f7:5777:cf14 with SMTP id 38308e7fff4ca-2f7cb367b08mr77707771fa.35.1727103763733; Mon, 23 Sep 2024 08:02:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727103763; cv=none; d=google.com; s=arc-20240605; b=UwEKcCcrOA/wMBPwgNJzXe9lbnDJjZrMNu+Z/QQBkOOcCwgZQSePCWbhFnL58AMidz d8bBGWbWUwmyTMb5TdVdG3XA1RjTWcK4IpcXS+zLw54rvf0BhXxxLD+BOAkQjA/e3L4T qxphKv+hauL9r11nW98a3YrIIWqCh/llRU2484jyy5A4c0pofZ3ewCtkkfND8LSbHRyf 6hyzJ+GcV+1E9NNZvQTVTUtpqlV9DCCDZHOfF8WrhY5Mcyi4333+0VnC5gHnJkIpjtA7 Cg0NKqDWsb7KWIQECVQo8g1t5QHMuNQf0Ck+UO/dm1Hdi+2jOzI9zDcrzyL41RviPXjw jUQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=SQb8xdCPA3NczY9yUBiIsNRVyQdN2qYLE/2QFcTiteo=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Rrt5sr9R7aFuE8JMBVirzgURE0loTi/r2XI/ySOjX8/Sp6qjJlz97HkYnZ/tVeHW9A ZyrFP6IQX6QgyUMLB5rijMZjh4dJAdiwd7PqvfGo9W5d+japaskstalPicUGF5aqqXBi +/3iUAbrG4+YmS//Qlpq3ZS5BF4irkzzzvEpoBdVo/MK2qbSKdUTlodbsppol3cKcWsp R0gi5CeEaKOk3L4ZwfbkCTHHZjA1Sw4vSjdisRtz1Au6wEvpj4BioE8Kc8I8ifecAOjq HfK8yphEXG0bDYMbXj7mxNpell+DFLMgvU5aWm0RvO8kd99UDHQI34DLeYhm34VOrPiA 5t/w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=kfkMkmWV; 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 a640c23a62f3a-a9061373381si1380386466b.1022.2024.09.23.08.02.43; Mon, 23 Sep 2024 08:02:43 -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; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=kfkMkmWV; 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 332AB68DC4B; Mon, 23 Sep 2024 18:02:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8864768DB97 for ; Mon, 23 Sep 2024 18:02:06 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=kfkMkmWV; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id A62514E0F for ; Mon, 23 Sep 2024 17:02:05 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id vXoINKwIuCXA for ; Mon, 23 Sep 2024 17:02:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727103724; bh=hA8pMmLi2MTOpbtAfV6nonWixI2Bc7i/T0yPVVRe+3g=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kfkMkmWVwszkGhdn179wpgN4ejV0zjO4mPrlxnyTsQaXUmZtfRKGGUvGWGbSXIkk6 fYBOt+uWd8lCgX9eOVfiMRdcRnFwn/8ZRKWWeA51keyL38H7eM80r6YMS9dMHyOhv9 wDCC+QP00l26Gm3BbRRXiK1+59Rr+qTPlA1BmvU9VZznbVtwsQqkwcT7p4k50WYPua FuxcKZRir9LIG1uixh8XIIIDhv1rC2Ow+ipse7mgWGWNBlWhLI5pAsbO2Lp5tjJ93p u/W+D/u0TvHzEhVTQxQ1kAV+hxmoJLjOGYspgzrZYleeRwqv21b9m2bLeHly2fT7xW YlucJPxgQitlQ== 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 mail1.khirnov.net (Postfix) with ESMTPS id 5F78B4DEE for ; Mon, 23 Sep 2024 17:02:04 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 48A3E3A0998 for ; Mon, 23 Sep 2024 17:02:04 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 23 Sep 2024 17:01:41 +0200 Message-ID: <20240923150146.31693-3-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240923150146.31693-1-anton@khirnov.net> References: <20240923150146.31693-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/7] fftools/ffmpeg_filter: use AV_BUFFERSINK_FLAG_PARAMS 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: RrfAsGUhWAd4 --- fftools/ffmpeg_filter.c | 96 ++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 54 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 81c4911b03..b4c0876fa6 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -197,13 +197,8 @@ typedef struct OutputFilterPriv { AVFilterContext *filter; - /* desired output stream properties */ - int format; - int width, height; - int sample_rate; - AVChannelLayout ch_layout; - enum AVColorSpace color_space; - enum AVColorRange color_range; + /* frame holding desired output stream parameters */ + AVFrame *params; // time base in which the output is sent to our downstream // does not need to match the filtersink's timebase @@ -212,8 +207,6 @@ typedef struct OutputFilterPriv { // to our downstream, so it cannot change anymore int tb_out_locked; - AVRational sample_aspect_ratio; - AVDictionary *sws_opts; AVDictionary *swr_opts; @@ -373,11 +366,11 @@ static void sub2video_update(InputFilterPriv *ifp, int64_t heartbeat_pts, #define DEF_CHOOSE_FORMAT(name, type, var, supported_list, none, printf_format, get_name) \ static void choose_ ## name (OutputFilterPriv *ofp, AVBPrint *bprint) \ { \ - if (ofp->var == none && !ofp->supported_list) \ + if (ofp->params->var == none && !ofp->supported_list) \ return; \ av_bprintf(bprint, #name "="); \ - if (ofp->var != none) { \ - av_bprintf(bprint, printf_format, get_name(ofp->var)); \ + if (ofp->params->var != none) { \ + av_bprintf(bprint, printf_format, get_name(ofp->params->var)); \ } else { \ const type *p; \ \ @@ -399,7 +392,7 @@ DEF_CHOOSE_FORMAT(sample_fmts, enum AVSampleFormat, format, formats, DEF_CHOOSE_FORMAT(sample_rates, int, sample_rate, sample_rates, 0, "%d", ) -DEF_CHOOSE_FORMAT(color_spaces, enum AVColorSpace, color_space, color_spaces, +DEF_CHOOSE_FORMAT(color_spaces, enum AVColorSpace, colorspace, color_spaces, AVCOL_SPC_UNSPECIFIED, "%s", av_color_space_name); DEF_CHOOSE_FORMAT(color_ranges, enum AVColorRange, color_range, color_ranges, @@ -407,9 +400,9 @@ DEF_CHOOSE_FORMAT(color_ranges, enum AVColorRange, color_range, color_ranges, static void choose_channel_layouts(OutputFilterPriv *ofp, AVBPrint *bprint) { - if (av_channel_layout_check(&ofp->ch_layout)) { + if (av_channel_layout_check(&ofp->params->ch_layout)) { av_bprintf(bprint, "channel_layouts="); - av_channel_layout_describe_bprint(&ofp->ch_layout, bprint); + av_channel_layout_describe_bprint(&ofp->params->ch_layout, bprint); } else if (ofp->ch_layouts) { const AVChannelLayout *p; @@ -643,14 +636,15 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg, enum AVMediaType type) if (!ofp) return NULL; + ofp->params = av_frame_alloc(); + if (!ofp->params) + return NULL; + ofilter = &ofp->ofilter; ofilter->class = &ofilter_class; ofp->log_parent = fg; ofilter->graph = fg; ofilter->type = type; - ofp->format = -1; - ofp->color_space = AVCOL_SPC_UNSPECIFIED; - ofp->color_range = AVCOL_RANGE_UNSPECIFIED; ofp->index = fg->nb_outputs - 1; snprintf(ofp->log_name, sizeof(ofp->log_name), "%co%d", @@ -747,7 +741,7 @@ static int set_channel_layout(OutputFilterPriv *f, const AVChannelLayout *layout if (layout_requested->order != AV_CHANNEL_ORDER_UNSPEC) { /* Pass the layout through for all orders but UNSPEC */ - err = av_channel_layout_copy(&f->ch_layout, layout_requested); + err = av_channel_layout_copy(&f->params->ch_layout, layout_requested); if (err < 0) return err; return 0; @@ -757,7 +751,7 @@ static int set_channel_layout(OutputFilterPriv *f, const AVChannelLayout *layout if (!layouts_allowed) { /* Use the default native layout for the requested amount of channels when the encoder doesn't have a list of supported layouts */ - av_channel_layout_default(&f->ch_layout, layout_requested->nb_channels); + av_channel_layout_default(&f->params->ch_layout, layout_requested->nb_channels); return 0; } /* Encoder has a list of supported layouts. Pick the first layout in it with the @@ -768,14 +762,14 @@ static int set_channel_layout(OutputFilterPriv *f, const AVChannelLayout *layout } if (layouts_allowed[i].nb_channels) { /* Use it if one is found */ - err = av_channel_layout_copy(&f->ch_layout, &layouts_allowed[i]); + err = av_channel_layout_copy(&f->params->ch_layout, &layouts_allowed[i]); if (err < 0) return err; return 0; } /* If no layout for the amount of channels requested was found, use the default native layout for it. */ - av_channel_layout_default(&f->ch_layout, layout_requested->nb_channels); + av_channel_layout_default(&f->params->ch_layout, layout_requested->nb_channels); return 0; } @@ -827,20 +821,20 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, switch (ofilter->type) { case AVMEDIA_TYPE_VIDEO: - ofp->width = opts->width; - ofp->height = opts->height; + ofp->params->width = opts->width; + ofp->params->height = opts->height; if (opts->format != AV_PIX_FMT_NONE) { - ofp->format = opts->format; + ofp->params->format = opts->format; } else ofp->formats = opts->formats; if (opts->color_space != AVCOL_SPC_UNSPECIFIED) - ofp->color_space = opts->color_space; + ofp->params->colorspace = opts->color_space; else ofp->color_spaces = opts->color_spaces; if (opts->color_range != AVCOL_RANGE_UNSPECIFIED) - ofp->color_range = opts->color_range; + ofp->params->color_range = opts->color_range; else ofp->color_ranges = opts->color_ranges; @@ -865,12 +859,12 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, break; case AVMEDIA_TYPE_AUDIO: if (opts->format != AV_SAMPLE_FMT_NONE) { - ofp->format = opts->format; + ofp->params->format = opts->format; } else { ofp->formats = opts->formats; } if (opts->sample_rate) { - ofp->sample_rate = opts->sample_rate; + ofp->params->sample_rate = opts->sample_rate; } else ofp->sample_rates = opts->sample_rates; if (opts->ch_layout.nb_channels) { @@ -1012,6 +1006,7 @@ void fg_free(FilterGraph **pfg) OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); av_frame_free(&ofp->fps.last_frame); + av_frame_free(&ofp->params); av_dict_free(&ofp->sws_opts); av_dict_free(&ofp->swr_opts); @@ -1019,7 +1014,6 @@ void fg_free(FilterGraph **pfg) av_freep(&ofilter->name); av_freep(&ofilter->apad); av_freep(&ofp->name); - av_channel_layout_uninit(&ofp->ch_layout); av_freep(&fg->outputs[j]); } av_freep(&fg->outputs); @@ -1484,13 +1478,14 @@ static int configure_output_video_filter(FilterGraph *fg, AVFilterGraph *graph, if (ret < 0) return ret; - if ((ofp->width || ofp->height) && (ofp->flags & OFILTER_FLAG_AUTOSCALE)) { + if ((ofp->params->width || ofp->params->height) && + (ofp->flags & OFILTER_FLAG_AUTOSCALE)) { char args[255]; AVFilterContext *filter; const AVDictionaryEntry *e = NULL; snprintf(args, sizeof(args), "%d:%d", - ofp->width, ofp->height); + ofp->params->width, ofp->params->height); while ((e = av_dict_iterate(ofp->sws_opts, e))) { av_strlcatf(args, sizeof(args), ":%s=%s", e->key, e->value); @@ -1508,7 +1503,7 @@ static int configure_output_video_filter(FilterGraph *fg, AVFilterGraph *graph, } av_assert0(!(ofp->flags & OFILTER_FLAG_DISABLE_CONVERT) || - ofp->format != AV_PIX_FMT_NONE || !ofp->formats); + ofp->params->format != AV_PIX_FMT_NONE || !ofp->formats); av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED); choose_pix_fmts(ofp, &bprint); choose_color_spaces(ofp, &bprint); @@ -1931,12 +1926,11 @@ static int configure_filtergraph(FilterGraph *fg, FilterGraphThread *fgt) OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); AVFilterContext *sink = ofp->filter; - ofp->format = av_buffersink_get_format(sink); - - ofp->width = av_buffersink_get_w(sink); - ofp->height = av_buffersink_get_h(sink); - ofp->color_space = av_buffersink_get_colorspace(sink); - ofp->color_range = av_buffersink_get_color_range(sink); + av_frame_unref(ofp->params); + ret = av_buffersink_get_frame_flags(sink, ofp->params, + AV_BUFFERSINK_FLAG_PARAMS); + if (ret < 0) + return ret; // If the timing parameters are not locked yet, get the tentative values // here but don't lock them. They will only be used if no output frames @@ -1946,15 +1940,8 @@ static int configure_filtergraph(FilterGraph *fg, FilterGraphThread *fgt) if (ofp->fps.framerate.num <= 0 && ofp->fps.framerate.den <= 0 && fr.num > 0 && fr.den > 0) ofp->fps.framerate = fr; - ofp->tb_out = av_buffersink_get_time_base(sink); + ofp->tb_out = ofp->params->time_base; } - ofp->sample_aspect_ratio = av_buffersink_get_sample_aspect_ratio(sink); - - ofp->sample_rate = av_buffersink_get_sample_rate(sink); - av_channel_layout_uninit(&ofp->ch_layout); - ret = av_buffersink_get_ch_layout(sink, &ofp->ch_layout); - if (ret < 0) - goto fail; } for (int i = 0; i < fg->nb_inputs; i++) { @@ -2339,15 +2326,16 @@ static int close_output(OutputFilterPriv *ofp, FilterGraphThread *fgt) FrameData *fd; frame->time_base = ofp->tb_out; - frame->format = ofp->format; - frame->width = ofp->width; - frame->height = ofp->height; - frame->sample_aspect_ratio = ofp->sample_aspect_ratio; + frame->format = ofp->params->format; - frame->sample_rate = ofp->sample_rate; - if (ofp->ch_layout.nb_channels) { - ret = av_channel_layout_copy(&frame->ch_layout, &ofp->ch_layout); + frame->width = ofp->params->width; + frame->height = ofp->params->height; + frame->sample_aspect_ratio = ofp->params->sample_aspect_ratio; + + frame->sample_rate = ofp->params->sample_rate; + if (ofp->params->ch_layout.nb_channels) { + ret = av_channel_layout_copy(&frame->ch_layout, &ofp->params->ch_layout); if (ret < 0) return ret; }