From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 1F5834503A for ; Sun, 27 Aug 2023 11:47:27 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6EA4F68C5CE; Sun, 27 Aug 2023 14:47:24 +0300 (EEST) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 78C2568041B for ; Sun, 27 Aug 2023 14:47:17 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id C08FE401C9; Sun, 27 Aug 2023 13:47:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1693136836; bh=823p0tZ0isxuJ6M+v635Vj+A3/+48CpE0kvfxPDSbIk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=kd4LjRbqQbk8aemsU+u0Rp9aMCEePRS53Ydf6F0Gt+FAXY4izCSiE6QnqkN1M5Wdy Ti4tMF0RY73+6pT/iQHR13LOHMIJGs1XPEJK1MYBdCFE8n5X7GTSjnL/HQ0YuqzT9V xDWomtC03sXlZHE9k1VA1vSTtwbMwF/YT/MyFuMA= Date: Sun, 27 Aug 2023 13:47:16 +0200 Message-ID: <20230827134716.GB17951@haasn.xyz> From: Niklas Haas To: ffmpeg-devel@ffmpeg.org In-Reply-To: <20230818165044.5512-1-ffmpeg@haasn.xyz> References: <20230818165044.5512-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Content-Disposition: inline Subject: Re: [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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Fri, 18 Aug 2023 18:50:43 +0200 Niklas Haas wrote: > 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)), > )); > > -- > 2.41.0 > Merged as 816983d951c77..3c9dc009b6e5 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".