From patchwork Fri Aug 18 16:50:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 43263 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4c9d:b0:130:ccc6:6c4b with SMTP id fq29csp2802826pzb; Fri, 18 Aug 2023 09:50:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG6lx/MvMJ9GpT8xPkRu3pVWEL36hbYv6YAyTkvYKlk/9nKiypIUSSxeS7mSnRYZVMTK+HG X-Received: by 2002:a05:6512:20c5:b0:4fb:79b5:5512 with SMTP id u5-20020a05651220c500b004fb79b55512mr1985564lfr.66.1692377420927; Fri, 18 Aug 2023 09:50:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692377420; cv=none; d=google.com; s=arc-20160816; b=g24N7cNCAXkCBLFM1aISEOrdy+JZq+C2NjshD75iGwCwpvE8JNPl/9064L4rPwFTNf nkyrU4xdHYCYMqNKTy3MfhQTxyYeJKlP59u5K35ZLbMq3Fp+Mn0NCiWA6HevTAzaKaXB l2kI5PPXUCYP1nOHg6QWk6RQ9TGccr9fm5yxJ/pCFYRmV+LJRdasklecwtBq8e38G5Cp Tf4xLOLr8uqqqr9dbMigr+ruw4lomZT0uUAvrab+VSu+lSsLm0upB/C4vjEVJaNAKIlz eTbaSR7VAPFUiFmsikLS+m8DXAKrBAnAKqnjdgIWpgTtqlHeGRi8WI+IXs7F6oNsJXzj H2Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=G8Tx2HsQcahl+CiLInnFqnnBePkBLA5VLlu88pbai48=; fh=gT0qIutk2UUjXR+TfNyL+SuB7mt8pajgYxSYYxhvGBk=; b=olpG69jVK0EPc+MXTSA6M9j58xVZkJ1p0d1A8tNWi4OnC0yK5xCkf0Oz/Gg5PzHhRO UyfzwZm5LVy2y9SF3XUnNXN3CmKf52jgvHgbASkaNphAV60h4XsvlXwl84cUutM7XKom yA+f9VcJThI7+N33/mYXJ2P7JCRgPnnB6uUPqUKfFZsoxkwSTK0TqA35seHpQNmWMRWY UHaYp0yHXZ/DJeOEybVFmO+Kj2Kz4fOmIr6keHwzshWcqZ+hPG5IGN1pa271XPKnbjLT //zVEbm3jbfNb6jRJpq+vb/hDAAZDxnsysP05rYmwBYQ+cAdxbhpU9F9ZSLJt5RcXvqQ Nz4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=sV6Dmf9k; 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 v8-20020a056402184800b005232be9ef20si1626980edy.186.2023.08.18.09.50.19; Fri, 18 Aug 2023 09:50:20 -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=@haasn.xyz header.s=mail header.b=sV6Dmf9k; 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 6584068C65F; Fri, 18 Aug 2023 19:50:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4333168C501 for ; Fri, 18 Aug 2023 19:50:09 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 6121343518; Fri, 18 Aug 2023 18:50:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1692377408; bh=Fut/i6YM4I1KUVog10qiXF5Y+dlfp2snd0QrY1dYF8s=; h=From:To:Cc:Subject:Date:From; b=sV6Dmf9kQ6TjRPhqMD+EnkeOyabJ9knN0NzbdByD5aWug+sNMiWgfpLWRpzdeT7Li 3ZYFemC9pJKlmjI0AQNKw0XUh58mCaARqsMiNdx8f0U1RSANOq9UIOutlQrr4wKZgu p9YoRSMr1wGCv9STO/O1zTpk83J6QlfkJ4rCzkxU= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 18 Aug 2023 18:50:04 +0200 Message-ID: <20230818165005.4995-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] lavfi/vf_libplacebo: switch to new pl_options struct 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: x+8GqTERkm1f From: Niklas Haas This new upstream struct simplifies params struct management by allowing them to all be contained in a single dynamically allocated struct. This commit switches to the new API in a backwards-compatible way. The only nontrivial change that was required was to handle `sigmoid_params` in a way consistent with the rest of the params structs, instead of setting it directly to the upstream default. --- libavfilter/vf_libplacebo.c | 89 ++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 32 deletions(-) diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 34879910538..b9effdbad95 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -42,6 +42,25 @@ static inline AVFrame *pl_get_mapped_avframe(const struct pl_frame *frame) } #endif +#if PL_API_VER >= 309 +#include +#else +typedef struct pl_options_t { + // Backwards compatibility shim of this struct + struct pl_render_params params; + struct pl_deband_params deband_params; + struct pl_sigmoid_params sigmoid_params; + struct pl_color_adjustment color_adjustment; + struct pl_peak_detect_params peak_detect_params; + struct pl_color_map_params color_map_params; + struct pl_dither_params dither_params; + struct pl_cone_params cone_params; +} *pl_options; + +#define pl_options_alloc(log) av_mallocz(sizeof(struct pl_options_t)) +#define pl_options_free(ptr) av_freep(ptr) +#endif + enum { TONE_MAP_AUTO, TONE_MAP_CLIP, @@ -175,7 +194,7 @@ typedef struct LibplaceboContext { int color_trc; /* pl_render_params */ - struct pl_render_params params; + pl_options opts; char *upscaler; char *downscaler; char *frame_mixer; @@ -190,7 +209,6 @@ typedef struct LibplaceboContext { int disable_fbos; /* pl_deband_params */ - struct pl_deband_params deband_params; int deband; int deband_iterations; float deband_threshold; @@ -198,7 +216,6 @@ typedef struct LibplaceboContext { float deband_grain; /* pl_color_adjustment */ - struct pl_color_adjustment color_adjustment; float brightness; float contrast; float saturation; @@ -206,7 +223,6 @@ typedef struct LibplaceboContext { float gamma; /* pl_peak_detect_params */ - struct pl_peak_detect_params peak_detect_params; int peakdetect; float smoothing; float min_peak; @@ -215,7 +231,6 @@ typedef struct LibplaceboContext { float percentile; /* pl_color_map_params */ - struct pl_color_map_params color_map_params; int gamut_mode; int tonemapping; float tonemapping_param; @@ -239,13 +254,11 @@ typedef struct LibplaceboContext { #endif /* pl_dither_params */ - struct pl_dither_params dither_params; int dithering; int dither_lut_size; int dither_temporal; /* pl_cone_params */ - struct pl_cone_params cone_params; int cones; float cone_str; @@ -363,6 +376,7 @@ static int update_settings(AVFilterContext *ctx) { int err = 0; LibplaceboContext *s = ctx->priv; + pl_options opts = s->opts; int gamut_mode = s->gamut_mode; uint8_t color_rgba[4]; @@ -394,14 +408,16 @@ static int update_settings(AVFilterContext *ctx) RET(av_parse_color(color_rgba, s->fillcolor, -1, s)); - s->deband_params = *pl_deband_params( + opts->deband_params = *pl_deband_params( .iterations = s->deband_iterations, .threshold = s->deband_threshold, .radius = s->deband_radius, .grain = s->deband_grain, ); - s->color_adjustment = (struct pl_color_adjustment) { + opts->sigmoid_params = pl_sigmoid_default_params; + + opts->color_adjustment = (struct pl_color_adjustment) { .brightness = s->brightness, .contrast = s->contrast, .saturation = s->saturation, @@ -409,7 +425,7 @@ static int update_settings(AVFilterContext *ctx) .gamma = s->gamma, }; - s->peak_detect_params = *pl_peak_detect_params( + opts->peak_detect_params = *pl_peak_detect_params( .smoothing_period = s->smoothing, .minimum_peak = s->min_peak, .scene_threshold_low = s->scene_low, @@ -422,7 +438,7 @@ static int update_settings(AVFilterContext *ctx) #endif ); - s->color_map_params = *pl_color_map_params( + opts->color_map_params = *pl_color_map_params( #if FF_API_LIBPLACEBO_OPTS # if PL_API_VER >= 269 .hybrid_mix = hybrid_mix, @@ -441,20 +457,20 @@ static int update_settings(AVFilterContext *ctx) #endif ); - set_gamut_mode(&s->color_map_params, gamut_mode); + set_gamut_mode(&opts->color_map_params, gamut_mode); - s->dither_params = *pl_dither_params( + opts->dither_params = *pl_dither_params( .method = s->dithering, .lut_size = s->dither_lut_size, .temporal = s->dither_temporal, ); - s->cone_params = *pl_cone_params( + opts->cone_params = *pl_cone_params( .cones = s->cones, .strength = s->cone_str, ); - s->params = *pl_render_params( + opts->params = *pl_render_params( .lut_entries = s->lut_entries, .antiringing_strength = s->antiringing, .background_transparency = 1.0f - (float) color_rgba[3] / UINT8_MAX, @@ -467,13 +483,13 @@ static int update_settings(AVFilterContext *ctx) .corner_rounding = s->corner_rounding, #endif - .deband_params = s->deband ? &s->deband_params : NULL, - .sigmoid_params = s->sigmoid ? &pl_sigmoid_default_params : NULL, - .color_adjustment = &s->color_adjustment, - .peak_detect_params = s->peakdetect ? &s->peak_detect_params : NULL, - .color_map_params = &s->color_map_params, - .dither_params = s->dithering >= 0 ? &s->dither_params : NULL, - .cone_params = s->cones ? &s->cone_params : NULL, + .deband_params = s->deband ? &opts->deband_params : NULL, + .sigmoid_params = s->sigmoid ? &opts->sigmoid_params : NULL, + .color_adjustment = &opts->color_adjustment, + .peak_detect_params = s->peakdetect ? &opts->peak_detect_params : NULL, + .color_map_params = &opts->color_map_params, + .dither_params = s->dithering >= 0 ? &opts->dither_params : NULL, + .cone_params = s->cones ? &opts->cone_params : NULL, .hooks = s->hooks, .num_hooks = s->num_hooks, @@ -486,9 +502,9 @@ static int update_settings(AVFilterContext *ctx) .disable_fbos = s->disable_fbos, ); - RET(find_scaler(ctx, &s->params.upscaler, s->upscaler, 0)); - RET(find_scaler(ctx, &s->params.downscaler, s->downscaler, 0)); - RET(find_scaler(ctx, &s->params.frame_mixer, s->frame_mixer, 1)); + RET(find_scaler(ctx, &opts->params.upscaler, s->upscaler, 0)); + RET(find_scaler(ctx, &opts->params.downscaler, s->downscaler, 0)); + RET(find_scaler(ctx, &opts->params.frame_mixer, s->frame_mixer, 1)); return 0; fail: @@ -528,6 +544,12 @@ static int libplacebo_init(AVFilterContext *avctx) if (!s->log) return AVERROR(ENOMEM); + s->opts = pl_options_alloc(s->log); + if (!s->opts) { + libplacebo_uninit(avctx); + return AVERROR(ENOMEM); + } + if (s->out_format_string) { s->out_format = av_get_pix_fmt(s->out_format_string); if (s->out_format == AV_PIX_FMT_NONE) { @@ -712,6 +734,8 @@ static void libplacebo_uninit(AVFilterContext *avctx) input_uninit(&s->inputs[i]); av_freep(&s->inputs); } + + pl_options_free(&s->opts); pl_vulkan_destroy(&s->vulkan); pl_log_destroy(&s->log); ff_vk_uninit(&s->vkctx); @@ -818,6 +842,7 @@ static int output_frame(AVFilterContext *ctx, int64_t pts) { int err = 0, ok, changed_csp; LibplaceboContext *s = ctx->priv; + pl_options opts = s->opts; AVFilterLink *outlink = ctx->outputs[0]; const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(outlink->format); struct pl_frame target; @@ -901,18 +926,18 @@ static int output_frame(AVFilterContext *ctx, int64_t pts) } /* Draw first frame opaque, others with blending */ - s->params.skip_target_clearing = false; - s->params.blend_params = NULL; + opts->params.skip_target_clearing = false; + opts->params.blend_params = NULL; for (int i = 0; i < s->nb_inputs; i++) { LibplaceboInput *in = &s->inputs[i]; int high_fps = av_cmp_q(in->link->frame_rate, outlink->frame_rate) >= 0; if (in->qstatus != PL_QUEUE_OK) continue; - s->params.skip_caching_single_frame = high_fps; + opts->params.skip_caching_single_frame = high_fps; update_crops(ctx, in, &target, out->pts * av_q2d(outlink->time_base)); - pl_render_image_mix(in->renderer, &in->mix, &target, &s->params); - s->params.skip_target_clearing = true; - s->params.blend_params = &pl_alpha_overlay; + pl_render_image_mix(in->renderer, &in->mix, &target, &opts->params); + opts->params.skip_target_clearing = true; + opts->params.blend_params = &pl_alpha_overlay; } if (outdesc->flags & AV_PIX_FMT_FLAG_HWACCEL) { @@ -1057,7 +1082,7 @@ static int libplacebo_activate(AVFilterContext *ctx) in->qstatus = pl_queue_update(in->queue, &in->mix, pl_queue_params( .pts = out_pts * av_q2d(outlink->time_base), - .radius = pl_frame_mix_radius(&s->params), + .radius = pl_frame_mix_radius(&s->opts->params), .vsync_duration = av_q2d(av_inv_q(outlink->frame_rate)), ));