From 989d873d6ec57171a55f432d6f87a9e5a61a706c Mon Sep 17 00:00:00 2001 From: Philip Langdale Date: Sat, 12 Mar 2022 11:24:51 -0800 Subject: filters: lavfi: allow hwdec_interop selection for filters Today, lavfi filters are provided a hw_device from the first hwdec_interop that was loaded, regardless of whether it's the right one or not. In most situations where a hardware based filter is used, we need more control over the device. In this change, a `hwdec_interop` option is added to the lavfi wrapper filter configuration and this is used to pick the correct hw_device to inject into the filter or graph (in the case of a graph, all filters get the same device). Note that this requires the use of the explicit lavfi syntax to allow for the extra configuration. eg: ``` mpv --vf=hwupload ``` becomes ``` mpv --vf=lavfi=[hwupload]:hwdec_interop=cuda-nvdec ``` or ``` mpv --vf=lavfi-bridge=[hwupload]:hwdec_interop=cuda-nvdec ``` --- video/out/gpu/hwdec.c | 44 ++++++++++++++++++++++++++++++++++---------- video/out/gpu/hwdec.h | 8 ++++++++ 2 files changed, 42 insertions(+), 10 deletions(-) (limited to 'video/out') diff --git a/video/out/gpu/hwdec.c b/video/out/gpu/hwdec.c index 9b994bc0a1..01147be832 100644 --- a/video/out/gpu/hwdec.c +++ b/video/out/gpu/hwdec.c @@ -26,17 +26,14 @@ #include "hwdec.h" extern const struct ra_hwdec_driver ra_hwdec_vaegl; -extern const struct ra_hwdec_driver ra_hwdec_vaglx; extern const struct ra_hwdec_driver ra_hwdec_videotoolbox; extern const struct ra_hwdec_driver ra_hwdec_vdpau; extern const struct ra_hwdec_driver ra_hwdec_dxva2egl; extern const struct ra_hwdec_driver ra_hwdec_d3d11egl; extern const struct ra_hwdec_driver ra_hwdec_dxva2gldx; -extern const struct ra_hwdec_driver ra_hwdec_dxva2; extern const struct ra_hwdec_driver ra_hwdec_d3d11va; extern const struct ra_hwdec_driver ra_hwdec_dxva2dxgi; extern const struct ra_hwdec_driver ra_hwdec_cuda; -extern const struct ra_hwdec_driver ra_hwdec_cuda_nvdec; extern const struct ra_hwdec_driver ra_hwdec_rpi_overlay; extern const struct ra_hwdec_driver ra_hwdec_drmprime; extern const struct ra_hwdec_driver ra_hwdec_drmprime_drm; @@ -174,8 +171,9 @@ int ra_hwdec_mapper_map(struct ra_hwdec_mapper *mapper, struct mp_image *img) return 0; } -int ra_hwdec_validate_opt(struct mp_log *log, const m_option_t *opt, - struct bstr name, const char **value) +static int ra_hwdec_validate_opt_full(struct mp_log *log, bool include_modes, + const m_option_t *opt, + struct bstr name, const char **value) { struct bstr param = bstr0(*value); bool help = bstr_equals0(param, "help"); @@ -190,20 +188,36 @@ int ra_hwdec_validate_opt(struct mp_log *log, const m_option_t *opt, } } if (help) { - mp_info(log, " auto (behavior depends on context)\n" - " all (load all hwdecs)\n" - " no (do not load any and block loading on demand)\n"); + if (include_modes) { + mp_info(log, " auto (behavior depends on context)\n" + " all (load all hwdecs)\n" + " no (do not load any and block loading on demand)\n"); + } return M_OPT_EXIT; } if (!param.len) return 1; // "" is treated specially - if (bstr_equals0(param, "all") || bstr_equals0(param, "auto") || - bstr_equals0(param, "no")) + if (include_modes && + (bstr_equals0(param, "all") || bstr_equals0(param, "auto") || + bstr_equals0(param, "no"))) return 1; mp_fatal(log, "No hwdec backend named '%.*s' found!\n", BSTR_P(param)); return M_OPT_INVALID; } +int ra_hwdec_validate_opt(struct mp_log *log, const m_option_t *opt, + struct bstr name, const char **value) +{ + return ra_hwdec_validate_opt_full(log, true, opt, name, value); +} + +int ra_hwdec_validate_drivers_only_opt(struct mp_log *log, + const m_option_t *opt, + struct bstr name, const char **value) +{ + return ra_hwdec_validate_opt_full(log, false, opt, name, value); +} + static void load_add_hwdec(struct ra_hwdec_ctx *ctx, struct mp_hwdec_devices *devs, const struct ra_hwdec_driver *drv, bool is_auto) { @@ -323,3 +337,13 @@ struct ra_hwdec *ra_hwdec_get(struct ra_hwdec_ctx *ctx, int imgfmt) return NULL; } + +int ra_hwdec_driver_get_imgfmt_for_name(const char *name) +{ + for (int i = 0; ra_hwdec_drivers[i]; i++) { + if (!strcmp(ra_hwdec_drivers[i]->name, name)) { + return ra_hwdec_drivers[i]->imgfmts[0]; + } + } + return IMGFMT_NONE; +} diff --git a/video/out/gpu/hwdec.h b/video/out/gpu/hwdec.h index 34f8bc7856..0dd2e14588 100644 --- a/video/out/gpu/hwdec.h +++ b/video/out/gpu/hwdec.h @@ -20,6 +20,10 @@ struct ra_hwdec_ctx { int ra_hwdec_validate_opt(struct mp_log *log, const m_option_t *opt, struct bstr name, const char **value); +int ra_hwdec_validate_drivers_only_opt(struct mp_log *log, + const m_option_t *opt, + struct bstr name, const char **value); + void ra_hwdec_ctx_init(struct ra_hwdec_ctx *ctx, struct mp_hwdec_devices *devs, const char *opt, bool load_all_by_default); void ra_hwdec_ctx_uninit(struct ra_hwdec_ctx *ctx); @@ -143,4 +147,8 @@ void ra_hwdec_mapper_free(struct ra_hwdec_mapper **mapper); void ra_hwdec_mapper_unmap(struct ra_hwdec_mapper *mapper); int ra_hwdec_mapper_map(struct ra_hwdec_mapper *mapper, struct mp_image *img); +// Get the primary image format for the given driver name. +// Returns IMGFMT_NONE if the name doesn't get matched. +int ra_hwdec_driver_get_imgfmt_for_name(const char *name); + #endif -- cgit v1.2.3