From 7bbf132e209bb7ece864592ec0650b759dad6094 Mon Sep 17 00:00:00 2001 From: Philip Langdale Date: Mon, 5 Aug 2024 20:24:37 -0700 Subject: [PATCH] vo: hwdec: add AVHWDeviceType property to hwdecs As the first step towards handling scenarios where the are multiple hwdecs for a given image format but backed by different AVHWDeviceTypes, let us annotate the hwdecs with their corresponding device types. From this, we can also see how all the existing hwdecs which match the same image format also match the same device type. --- osdep/mac/meson.build | 3 ++- video/out/d3d11/hwdec_d3d11va.c | 1 + video/out/d3d11/hwdec_dxva2dxgi.c | 1 + video/out/gpu/hwdec.c | 10 ++++++++++ video/out/gpu/hwdec.h | 9 +++++++++ video/out/hwdec/hwdec_aimagereader.c | 1 + video/out/hwdec/hwdec_cuda.c | 1 + video/out/hwdec/hwdec_drmprime.c | 1 + video/out/hwdec/hwdec_drmprime_overlay.c | 1 + video/out/hwdec/hwdec_vaapi.c | 1 + video/out/hwdec/hwdec_vt.c | 1 + video/out/hwdec/hwdec_vulkan.c | 1 + video/out/opengl/hwdec_d3d11egl.c | 1 + video/out/opengl/hwdec_dxva2egl.c | 1 + video/out/opengl/hwdec_dxva2gldx.c | 1 + video/out/opengl/hwdec_vdpau.c | 1 + 16 files changed, 34 insertions(+), 1 deletion(-) diff --git a/osdep/mac/meson.build b/osdep/mac/meson.build index 9116d81476..7227b55ebc 100644 --- a/osdep/mac/meson.build +++ b/osdep/mac/meson.build @@ -51,7 +51,8 @@ swift_compile = [swift_prog, swift_flags, '-module-name', 'swift', '-emit-objc-header-path', '@OUTPUT1@', '-o', '@OUTPUT2@', '@INPUT@', '-I.', '-I' + source_root, '-I' + libplacebo.get_variable('includedir', - default_value: source_root / 'subprojects' / 'libplacebo' / 'src' / 'include')] + default_value: source_root / 'subprojects' / 'libplacebo' / 'src' / 'include'), + '-I' + libavutil.get_variable('includedir')] swift_targets = custom_target('swift_targets', input: swift_sources, diff --git a/video/out/d3d11/hwdec_d3d11va.c b/video/out/d3d11/hwdec_d3d11va.c index 6aaa12bc66..abfef5ce55 100644 --- a/video/out/d3d11/hwdec_d3d11va.c +++ b/video/out/d3d11/hwdec_d3d11va.c @@ -246,6 +246,7 @@ const struct ra_hwdec_driver ra_hwdec_d3d11va = { .name = "d3d11va", .priv_size = sizeof(struct priv_owner), .imgfmts = {IMGFMT_D3D11, 0}, + .device_type = AV_HWDEVICE_TYPE_D3D11VA, .init = init, .uninit = uninit, .mapper = &(const struct ra_hwdec_mapper_driver){ diff --git a/video/out/d3d11/hwdec_dxva2dxgi.c b/video/out/d3d11/hwdec_dxva2dxgi.c index 62158d467b..e2342a1475 100644 --- a/video/out/d3d11/hwdec_dxva2dxgi.c +++ b/video/out/d3d11/hwdec_dxva2dxgi.c @@ -466,6 +466,7 @@ const struct ra_hwdec_driver ra_hwdec_dxva2dxgi = { .name = "dxva2-dxgi", .priv_size = sizeof(struct priv_owner), .imgfmts = {IMGFMT_DXVA2, 0}, + .device_type = AV_HWDEVICE_TYPE_DXVA2, .init = init, .uninit = uninit, .mapper = &(const struct ra_hwdec_mapper_driver){ diff --git a/video/out/gpu/hwdec.c b/video/out/gpu/hwdec.c index c7d817c63a..a929e678f8 100644 --- a/video/out/gpu/hwdec.c +++ b/video/out/gpu/hwdec.c @@ -352,3 +352,13 @@ int ra_hwdec_driver_get_imgfmt_for_name(const char *name) } return IMGFMT_NONE; } + +enum AVHWDeviceType ra_hwdec_driver_get_device_type_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]->device_type; + } + } + return AV_HWDEVICE_TYPE_NONE; +} diff --git a/video/out/gpu/hwdec.h b/video/out/gpu/hwdec.h index f195606417..83222ec264 100644 --- a/video/out/gpu/hwdec.h +++ b/video/out/gpu/hwdec.h @@ -1,6 +1,8 @@ #ifndef MPGL_HWDEC_H_ #define MPGL_HWDEC_H_ +#include + #include "video/mp_image.h" #include "context.h" #include "ra.h" @@ -106,6 +108,9 @@ struct ra_hwdec_driver { // Terminated with a 0 entry. (Extend the array size as needed.) const int imgfmts[3]; + // The underlying ffmpeg hw device type this hwdec corresponds to. + enum AVHWDeviceType device_type; + // Create the hwdec device. It must add it to hw->devs, if applicable. int (*init)(struct ra_hwdec *hw); void (*uninit)(struct ra_hwdec *hw); @@ -149,4 +154,8 @@ int ra_hwdec_mapper_map(struct ra_hwdec_mapper *mapper, struct mp_image *img); // Returns IMGFMT_NONE if the name doesn't get matched. int ra_hwdec_driver_get_imgfmt_for_name(const char *name); +// Get the primary hw device type for the given driver name. +// Returns AV_HWDEVICE_TYPE_NONE if the name doesn't get matched. +enum AVHWDeviceType ra_hwdec_driver_get_device_type_for_name(const char *name); + #endif diff --git a/video/out/hwdec/hwdec_aimagereader.c b/video/out/hwdec/hwdec_aimagereader.c index 1aa92eea4a..acab232a7c 100644 --- a/video/out/hwdec/hwdec_aimagereader.c +++ b/video/out/hwdec/hwdec_aimagereader.c @@ -392,6 +392,7 @@ const struct ra_hwdec_driver ra_hwdec_aimagereader = { .name = "aimagereader", .priv_size = sizeof(struct priv_owner), .imgfmts = {IMGFMT_MEDIACODEC, 0}, + .device_type = AV_HWDEVICE_TYPE_MEDIACODEC, .init = init, .uninit = uninit, .mapper = &(const struct ra_hwdec_mapper_driver){ diff --git a/video/out/hwdec/hwdec_cuda.c b/video/out/hwdec/hwdec_cuda.c index 8987cf3407..14289468ba 100644 --- a/video/out/hwdec/hwdec_cuda.c +++ b/video/out/hwdec/hwdec_cuda.c @@ -284,6 +284,7 @@ static int mapper_map(struct ra_hwdec_mapper *mapper) const struct ra_hwdec_driver ra_hwdec_cuda = { .name = "cuda", .imgfmts = {IMGFMT_CUDA, 0}, + .device_type = AV_HWDEVICE_TYPE_CUDA, .priv_size = sizeof(struct cuda_hw_priv), .init = cuda_init, .uninit = cuda_uninit, diff --git a/video/out/hwdec/hwdec_drmprime.c b/video/out/hwdec/hwdec_drmprime.c index bf604056f3..b4f9b9ff89 100644 --- a/video/out/hwdec/hwdec_drmprime.c +++ b/video/out/hwdec/hwdec_drmprime.c @@ -307,6 +307,7 @@ const struct ra_hwdec_driver ra_hwdec_drmprime = { .name = "drmprime", .priv_size = sizeof(struct priv_owner), .imgfmts = {IMGFMT_DRMPRIME, 0}, + .device_type = AV_HWDEVICE_TYPE_DRM, .init = init, .uninit = uninit, .mapper = &(const struct ra_hwdec_mapper_driver){ diff --git a/video/out/hwdec/hwdec_drmprime_overlay.c b/video/out/hwdec/hwdec_drmprime_overlay.c index f5c4b1a4cb..31cf3dd342 100644 --- a/video/out/hwdec/hwdec_drmprime_overlay.c +++ b/video/out/hwdec/hwdec_drmprime_overlay.c @@ -328,6 +328,7 @@ const struct ra_hwdec_driver ra_hwdec_drmprime_overlay = { .name = "drmprime-overlay", .priv_size = sizeof(struct priv), .imgfmts = {IMGFMT_DRMPRIME, 0}, + .device_type = AV_HWDEVICE_TYPE_DRM, .init = init, .overlay_frame = overlay_frame, .uninit = uninit, diff --git a/video/out/hwdec/hwdec_vaapi.c b/video/out/hwdec/hwdec_vaapi.c index 504880ad4e..00737a3d20 100644 --- a/video/out/hwdec/hwdec_vaapi.c +++ b/video/out/hwdec/hwdec_vaapi.c @@ -546,6 +546,7 @@ const struct ra_hwdec_driver ra_hwdec_vaapi = { .name = "vaapi", .priv_size = sizeof(struct priv_owner), .imgfmts = {IMGFMT_VAAPI, 0}, + .device_type = AV_HWDEVICE_TYPE_VAAPI, .init = init, .uninit = uninit, .mapper = &(const struct ra_hwdec_mapper_driver){ diff --git a/video/out/hwdec/hwdec_vt.c b/video/out/hwdec/hwdec_vt.c index 643ff9043f..aa995eacb4 100644 --- a/video/out/hwdec/hwdec_vt.c +++ b/video/out/hwdec/hwdec_vt.c @@ -129,6 +129,7 @@ const struct ra_hwdec_driver ra_hwdec_videotoolbox = { .name = "videotoolbox", .priv_size = sizeof(struct priv_owner), .imgfmts = {IMGFMT_VIDEOTOOLBOX, 0}, + .device_type = AV_HWDEVICE_TYPE_VIDEOTOOLBOX, .init = init, .uninit = uninit, .mapper = &(const struct ra_hwdec_mapper_driver){ diff --git a/video/out/hwdec/hwdec_vulkan.c b/video/out/hwdec/hwdec_vulkan.c index 5f7354dd8e..5073a0bc3a 100644 --- a/video/out/hwdec/hwdec_vulkan.c +++ b/video/out/hwdec/hwdec_vulkan.c @@ -320,6 +320,7 @@ static int mapper_map(struct ra_hwdec_mapper *mapper) const struct ra_hwdec_driver ra_hwdec_vulkan = { .name = "vulkan", .imgfmts = {IMGFMT_VULKAN, 0}, + .device_type = AV_HWDEVICE_TYPE_VULKAN, .priv_size = sizeof(struct vulkan_hw_priv), .init = vulkan_init, .uninit = vulkan_uninit, diff --git a/video/out/opengl/hwdec_d3d11egl.c b/video/out/opengl/hwdec_d3d11egl.c index c3120914ea..50fcf5a664 100644 --- a/video/out/opengl/hwdec_d3d11egl.c +++ b/video/out/opengl/hwdec_d3d11egl.c @@ -351,6 +351,7 @@ const struct ra_hwdec_driver ra_hwdec_d3d11egl = { .name = "d3d11-egl", .priv_size = sizeof(struct priv_owner), .imgfmts = {IMGFMT_D3D11, 0}, + .device_type = AV_HWDEVICE_TYPE_D3D11VA, .init = init, .uninit = uninit, .mapper = &(const struct ra_hwdec_mapper_driver){ diff --git a/video/out/opengl/hwdec_dxva2egl.c b/video/out/opengl/hwdec_dxva2egl.c index 979ef59745..741aa9b4b6 100644 --- a/video/out/opengl/hwdec_dxva2egl.c +++ b/video/out/opengl/hwdec_dxva2egl.c @@ -373,6 +373,7 @@ const struct ra_hwdec_driver ra_hwdec_dxva2egl = { .name = "dxva2-egl", .priv_size = sizeof(struct priv_owner), .imgfmts = {IMGFMT_DXVA2, 0}, + .device_type = AV_HWDEVICE_TYPE_DXVA2, .init = init, .uninit = uninit, .mapper = &(const struct ra_hwdec_mapper_driver){ diff --git a/video/out/opengl/hwdec_dxva2gldx.c b/video/out/opengl/hwdec_dxva2gldx.c index 01728130d7..1150b3ddd3 100644 --- a/video/out/opengl/hwdec_dxva2gldx.c +++ b/video/out/opengl/hwdec_dxva2gldx.c @@ -236,6 +236,7 @@ const struct ra_hwdec_driver ra_hwdec_dxva2gldx = { .name = "dxva2-dxinterop", .priv_size = sizeof(struct priv_owner), .imgfmts = {IMGFMT_DXVA2, 0}, + .device_type = AV_HWDEVICE_TYPE_DXVA2, .init = init, .uninit = uninit, .mapper = &(const struct ra_hwdec_mapper_driver){ diff --git a/video/out/opengl/hwdec_vdpau.c b/video/out/opengl/hwdec_vdpau.c index acdc703cad..7d40527b39 100644 --- a/video/out/opengl/hwdec_vdpau.c +++ b/video/out/opengl/hwdec_vdpau.c @@ -239,6 +239,7 @@ const struct ra_hwdec_driver ra_hwdec_vdpau = { .name = "vdpau-gl", .priv_size = sizeof(struct priv_owner), .imgfmts = {IMGFMT_VDPAU, 0}, + .device_type = AV_HWDEVICE_TYPE_VDPAU, .init = init, .uninit = uninit, .mapper = &(const struct ra_hwdec_mapper_driver){