From patchwork Wed Sep 25 13:29:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51844 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:9548:0:b0:48e:c0f8:d0de with SMTP id t8csp466614vqk; Wed, 25 Sep 2024 06:30:32 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVpz/EAbz6msKn+hGzdCOXSgrclv9Y8GJOmulHiLdlPsBhlIULteM5EIcyyxYpXNwgMV2ycGoV+OIU74KYqFOyU@gmail.com X-Google-Smtp-Source: AGHT+IEYIJYWbRPWmQD3OO+n/r3a7MY3mlL7YF1bHTUgKoR7cntS0r3o6pE9qrkQACdCDKzAokrh X-Received: by 2002:a05:6512:31c7:b0:536:a4f1:d20e with SMTP id 2adb3069b0e04-53877533057mr1799843e87.29.1727271032283; Wed, 25 Sep 2024 06:30:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727271032; cv=none; d=google.com; s=arc-20240605; b=OOQC9Alc1rDxSwADYZ+7Lps1U144Gvgic5QhM7fp+b6AeXgReufbg4lqKZBu+pDjK5 fzD4L8I/SUyMBvDNj0Xq30gMCbTeThX2Y4TSbmP2KHDbwTfC7o2/8a3ZyxwAZtEn4ijA n6ltlXfbVHbrmHWEselA6XDWbc88hVffJGYSm0nbpXPG9r7wzGgMALfnD7/UsjrDHvkD sjUMPU2LUkQ/WRSDutXEE5OHaFlQIL5S4RcLhiHkTrGVjkm3917g0ACUvpghJDX8b1L7 bTFAO/A2OkdzJi7hqSAAT5oWO/ZMIA+IEcE1Pf5xAj/36Cw5dYO0wAPFQ0jfvEv1uECm bS0A== 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=XmU61T4UAKreaW6HG+v7lq+YGlf8w9rLDIdFIjVnvr8=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=PXpHvnk/6E4cDiTMiTKi9L+XOQFxuvt+63o3733X6GX0GRHBk9hYCCy25N7S9YS7LY A5djZnDugk0fV2CA37WAduTjvr3eKwPX8Md/3Lve0KGQDgiMyTpZoUuY0nSFcF2pOj7c h38X4olPT4afljDI5emki175tR/mvn4XT7luTKkF8BQZbz+nGc+k1+KN+h+9OHtlGVBs yD+JkRivY2rMT+fj5YpftgzVGrrBS9e6l/qkA1bAzBJ65UwkQrV4/7JD2rd84eIgmm75 CsAA4Srb7NfPf9MngXQ9iMXDT7ZCa49iYb8Tlf0C9sFL1XubVqR8QApiasvK2S1rrOfe HL0g==; 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="GZtoq/pt"; 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 2adb3069b0e04-537a8650d32si1215693e87.618.2024.09.25.06.30.31; Wed, 25 Sep 2024 06:30:32 -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="GZtoq/pt"; 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 1514B68DBEC; Wed, 25 Sep 2024 16:29:40 +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 48C1A68DA56 for ; Wed, 25 Sep 2024 16:29:32 +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=GZtoq/pt; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id DF6AC4E11 for ; Wed, 25 Sep 2024 15:29:26 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id QiE-70M7GASD for ; Wed, 25 Sep 2024 15:29:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727270965; bh=snKOZsYHDxWE7twVNWbXpGGLB+ZuykI3HvxPYPJNq9I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GZtoq/ptiqCQ7CHEwH9o3DpeelIVXNvNJum5yazGmeAiNfNhfOiK7XZv1GgXdT1un k6m3WzBQ2Yv1iqxRvWSkwKTe6d5h54NeOdSAukAo3U9HvQcUjsCa5/uVRIfw+6tG9t zNLUh/vICcR6TDuiDbHKi8SGwmsyLU89LcIjNvahjIWB6Iq2CziHCU7rLe9WS3OKrd TPtkcuObviFr37B+A5nKLAl63Rn0DrdkN1SXsei+nzGN2/PQMrR0JAAvb77FA5XQzU IMMeGbl5sJcJPsdJ6+WuixtMgLkbqntQSlr3PrCNXjnc6MH1dXGzLdM0hZW51sFS0M mbrWXGWzvIRuA== 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 F07394E13 for ; Wed, 25 Sep 2024 15:29:24 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D63C23A086F for ; Wed, 25 Sep 2024 15:29:24 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 25 Sep 2024 15:29:19 +0200 Message-ID: <20240925132921.11203-8-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240925132921.11203-1-anton@khirnov.net> References: <20240925132921.11203-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/10] fftools/ffplay: stop using avfilter_graph_alloc_filter() incorrectly 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: os/c+UqaItLg This function creates AND initializes a filter, so setting any filter options after it is wrong. It happens to work when the filter's init function does not touch the options in question, but is forbidden by the API and is not guaranteed to remain functional. Instead, use avfilter_graph_alloc_filter(), followed by setting the options, and avfilter_init_dict(). --- fftools/ffplay.c | 56 +++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 60d8874eab..349c6075da 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -1861,7 +1861,6 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c { enum AVPixelFormat pix_fmts[FF_ARRAY_ELEMS(sdl_texture_format_map)]; char sws_flags_str[512] = ""; - char buffersrc_args[256]; int ret; AVFilterContext *filt_src = NULL, *filt_out = NULL, *last_filter = NULL; AVCodecParameters *codecpar = is->video_st->codecpar; @@ -1895,38 +1894,48 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c graph->scale_sws_opts = av_strdup(sws_flags_str); - snprintf(buffersrc_args, sizeof(buffersrc_args), - "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d:" - "colorspace=%d:range=%d", - frame->width, frame->height, frame->format, - is->video_st->time_base.num, is->video_st->time_base.den, - codecpar->sample_aspect_ratio.num, FFMAX(codecpar->sample_aspect_ratio.den, 1), - frame->colorspace, frame->color_range); - if (fr.num && fr.den) - av_strlcatf(buffersrc_args, sizeof(buffersrc_args), ":frame_rate=%d/%d", fr.num, fr.den); - if ((ret = avfilter_graph_create_filter(&filt_src, - avfilter_get_by_name("buffer"), - "ffplay_buffer", buffersrc_args, NULL, - graph)) < 0) + filt_src = avfilter_graph_alloc_filter(graph, avfilter_get_by_name("buffer"), + "ffplay_buffer"); + if (!filt_src) { + ret = AVERROR(ENOMEM); goto fail; + } + + par->format = frame->format; + par->time_base = is->video_st->time_base; + par->width = frame->width; + par->height = frame->height; + par->sample_aspect_ratio = codecpar->sample_aspect_ratio; + par->color_space = frame->colorspace; + par->color_range = frame->color_range; + par->frame_rate = fr; par->hw_frames_ctx = frame->hw_frames_ctx; ret = av_buffersrc_parameters_set(filt_src, par); if (ret < 0) goto fail; - ret = avfilter_graph_create_filter(&filt_out, - avfilter_get_by_name("buffersink"), - "ffplay_buffersink", NULL, NULL, graph); + ret = avfilter_init_dict(filt_src, NULL); if (ret < 0) goto fail; + filt_out = avfilter_graph_alloc_filter(graph, avfilter_get_by_name("buffersink"), + "ffplay_buffersink"); + if (!filt_out) { + ret = AVERROR(ENOMEM); + goto fail; + } + if ((ret = av_opt_set_int_list(filt_out, "pix_fmts", pix_fmts, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN)) < 0) goto fail; if (!vk_renderer && (ret = av_opt_set_int_list(filt_out, "color_spaces", sdl_supported_color_spaces, AVCOL_SPC_UNSPECIFIED, AV_OPT_SEARCH_CHILDREN)) < 0) goto fail; + ret = avfilter_init_dict(filt_out, NULL); + if (ret < 0) + goto fail; + last_filter = filt_out; /* Note: this macro adds a filter before the lastly added filter, so the @@ -2029,12 +2038,12 @@ static int configure_audio_filters(VideoState *is, const char *afilters, int for if (ret < 0) goto end; - - ret = avfilter_graph_create_filter(&filt_asink, - avfilter_get_by_name("abuffersink"), "ffplay_abuffersink", - NULL, NULL, is->agraph); - if (ret < 0) + filt_asink = avfilter_graph_alloc_filter(is->agraph, avfilter_get_by_name("abuffersink"), + "ffplay_abuffersink"); + if (!filt_asink) { + ret = AVERROR(ENOMEM); goto end; + } if ((ret = av_opt_set_int_list(filt_asink, "sample_fmts", sample_fmts, AV_SAMPLE_FMT_NONE, AV_OPT_SEARCH_CHILDREN)) < 0) goto end; @@ -2053,6 +2062,9 @@ static int configure_audio_filters(VideoState *is, const char *afilters, int for goto end; } + ret = avfilter_init_dict(filt_asink, NULL); + if (ret < 0) + goto end; if ((ret = configure_filtergraph(is->agraph, afilters, filt_asrc, filt_asink)) < 0) goto end;