From 4dfc2c50c18de74e73e3283773c1792b8a4b5a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Mon, 19 Jun 2023 20:32:44 +0200 Subject: hwdec: do not add hwdec device if it failed to create --- video/out/d3d11/hwdec_d3d11va.c | 6 ++++++ video/out/d3d11/hwdec_dxva2dxgi.c | 6 ++++++ video/out/hwdec/hwdec_aimagereader.c | 6 ++++++ video/out/hwdec/hwdec_drmprime_overlay.c | 14 ++++++++++---- video/out/opengl/hwdec_d3d11egl.c | 6 ++++++ video/out/opengl/hwdec_dxva2egl.c | 6 ++++++ video/out/opengl/hwdec_dxva2gldx.c | 6 ++++++ video/out/opengl/hwdec_ios.m | 8 ++++++-- video/out/opengl/hwdec_osx.c | 8 ++++++-- video/out/vo_mediacodec_embed.c | 6 ++++++ 10 files changed, 64 insertions(+), 8 deletions(-) (limited to 'video') diff --git a/video/out/d3d11/hwdec_d3d11va.c b/video/out/d3d11/hwdec_d3d11va.c index 0242c8fedf..6aaa12bc66 100644 --- a/video/out/d3d11/hwdec_d3d11va.c +++ b/video/out/d3d11/hwdec_d3d11va.c @@ -108,6 +108,12 @@ static int init(struct ra_hwdec *hw) .supported_formats = subfmts, .hw_imgfmt = IMGFMT_D3D11, }; + + if (!p->hwctx.av_device_ref) { + MP_VERBOSE(hw, "Failed to create hwdevice_ctx\n"); + return -1; + } + hwdec_devices_add(hw->devs, &p->hwctx); return 0; } diff --git a/video/out/d3d11/hwdec_dxva2dxgi.c b/video/out/d3d11/hwdec_dxva2dxgi.c index f68e0e3065..62158d467b 100644 --- a/video/out/d3d11/hwdec_dxva2dxgi.c +++ b/video/out/d3d11/hwdec_dxva2dxgi.c @@ -136,6 +136,12 @@ static int init(struct ra_hwdec *hw) .av_device_ref = d3d9_wrap_device_ref((IDirect3DDevice9 *)p->dev9), .hw_imgfmt = IMGFMT_DXVA2, }; + + if (!p->hwctx.av_device_ref) { + MP_VERBOSE(hw, "Failed to create hwdevice_ctx\n"); + goto done; + } + hwdec_devices_add(hw->devs, &p->hwctx); ret = 0; diff --git a/video/out/hwdec/hwdec_aimagereader.c b/video/out/hwdec/hwdec_aimagereader.c index 173fe0a2b3..93ced50548 100644 --- a/video/out/hwdec/hwdec_aimagereader.c +++ b/video/out/hwdec/hwdec_aimagereader.c @@ -178,6 +178,12 @@ static int init(struct ra_hwdec *hw) .av_device_ref = create_mediacodec_device_ref(p->surface), .hw_imgfmt = IMGFMT_MEDIACODEC, }; + + if (!p->hwctx.av_device_ref) { + MP_VERBOSE(hw, "Failed to create hwdevice_ctx\n"); + return -1; + } + hwdec_devices_add(hw->devs, &p->hwctx); return 0; diff --git a/video/out/hwdec/hwdec_drmprime_overlay.c b/video/out/hwdec/hwdec_drmprime_overlay.c index 75d2a0740c..6b6aae60f0 100644 --- a/video/out/hwdec/hwdec_drmprime_overlay.c +++ b/video/out/hwdec/hwdec_drmprime_overlay.c @@ -304,13 +304,19 @@ static int init(struct ra_hwdec *hw) }; char *device = drmGetDeviceNameFromFd2(p->ctx->fd); - if (!av_hwdevice_ctx_create(&p->hwctx.av_device_ref, AV_HWDEVICE_TYPE_DRM, - device, NULL, 0)) { - hwdec_devices_add(hw->devs, &p->hwctx); - } + int ret = av_hwdevice_ctx_create(&p->hwctx.av_device_ref, + AV_HWDEVICE_TYPE_DRM, device, NULL, 0); + if (device) free(device); + if (ret != 0) { + MP_VERBOSE(hw, "Failed to create hwdevice_ctx: %s\n", av_err2str(ret)); + goto err; + } + + hwdec_devices_add(hw->devs, &p->hwctx); + return 0; err: diff --git a/video/out/opengl/hwdec_d3d11egl.c b/video/out/opengl/hwdec_d3d11egl.c index 84b985906c..c3120914ea 100644 --- a/video/out/opengl/hwdec_d3d11egl.c +++ b/video/out/opengl/hwdec_d3d11egl.c @@ -185,6 +185,12 @@ static int init(struct ra_hwdec *hw) .supported_formats = subfmts, .hw_imgfmt = IMGFMT_D3D11, }; + + if (!p->hwctx.av_device_ref) { + MP_VERBOSE(hw, "Failed to create hwdevice_ctx\n"); + return -1; + } + hwdec_devices_add(hw->devs, &p->hwctx); return 0; diff --git a/video/out/opengl/hwdec_dxva2egl.c b/video/out/opengl/hwdec_dxva2egl.c index 197d25b9b0..d870d982cd 100644 --- a/video/out/opengl/hwdec_dxva2egl.c +++ b/video/out/opengl/hwdec_dxva2egl.c @@ -183,6 +183,12 @@ static int init(struct ra_hwdec *hw) .av_device_ref = d3d9_wrap_device_ref((IDirect3DDevice9 *)p->device9ex), .hw_imgfmt = IMGFMT_DXVA2, }; + + if (!p->hwctx.av_device_ref) { + MP_VERBOSE(hw, "Failed to create hwdevice_ctx\n"); + goto fail; + } + hwdec_devices_add(hw->devs, &p->hwctx); return 0; diff --git a/video/out/opengl/hwdec_dxva2gldx.c b/video/out/opengl/hwdec_dxva2gldx.c index 0a0784af4c..01728130d7 100644 --- a/video/out/opengl/hwdec_dxva2gldx.c +++ b/video/out/opengl/hwdec_dxva2gldx.c @@ -83,6 +83,12 @@ static int init(struct ra_hwdec *hw) .av_device_ref = d3d9_wrap_device_ref((IDirect3DDevice9 *)p->device), .hw_imgfmt = IMGFMT_DXVA2, }; + + if (!p->hwctx.av_device_ref) { + MP_VERBOSE(hw, "Failed to create hwdevice_ctx\n"); + return -1; + } + hwdec_devices_add(hw->devs, &p->hwctx); return 0; } diff --git a/video/out/opengl/hwdec_ios.m b/video/out/opengl/hwdec_ios.m index 480c9d9fe6..380c107ec1 100644 --- a/video/out/opengl/hwdec_ios.m +++ b/video/out/opengl/hwdec_ios.m @@ -71,8 +71,12 @@ static int init(struct ra_hwdec *hw) .hw_imgfmt = IMGFMT_VIDEOTOOLBOX, }; - av_hwdevice_ctx_create(&p->hwctx.av_device_ref, AV_HWDEVICE_TYPE_VIDEOTOOLBOX, - NULL, NULL, 0); + int ret = av_hwdevice_ctx_create(&p->hwctx.av_device_ref, + AV_HWDEVICE_TYPE_VIDEOTOOLBOX, NULL, NULL, 0); + if (ret != 0) { + MP_VERBOSE(hw, "Failed to create hwdevice_ctx: %s\n", av_err2str(ret)); + return -1; + } hwdec_devices_add(hw->devs, &p->hwctx); diff --git a/video/out/opengl/hwdec_osx.c b/video/out/opengl/hwdec_osx.c index 69e8ca9d09..8bbe54bd4c 100644 --- a/video/out/opengl/hwdec_osx.c +++ b/video/out/opengl/hwdec_osx.c @@ -72,8 +72,12 @@ static int init(struct ra_hwdec *hw) .hw_imgfmt = IMGFMT_VIDEOTOOLBOX, }; - av_hwdevice_ctx_create(&p->hwctx.av_device_ref, AV_HWDEVICE_TYPE_VIDEOTOOLBOX, - NULL, NULL, 0); + int ret = av_hwdevice_ctx_create(&p->hwctx.av_device_ref, + AV_HWDEVICE_TYPE_VIDEOTOOLBOX, NULL, NULL, 0); + if (ret != 0) { + MP_VERBOSE(hw, "Failed to create hwdevice_ctx: %s\n", av_err2str(ret)); + return -1; + } hwdec_devices_add(hw->devs, &p->hwctx); diff --git a/video/out/vo_mediacodec_embed.c b/video/out/vo_mediacodec_embed.c index 3a1df2fd2c..bf12c49ceb 100644 --- a/video/out/vo_mediacodec_embed.c +++ b/video/out/vo_mediacodec_embed.c @@ -55,6 +55,12 @@ static int preinit(struct vo *vo) .av_device_ref = create_mediacodec_device_ref(vo), .hw_imgfmt = IMGFMT_MEDIACODEC, }; + + if (!p->hwctx.av_device_ref) { + MP_VERBOSE(hw, "Failed to create hwdevice_ctx\n"); + return -1; + } + hwdec_devices_add(vo->hwdec_devs, &p->hwctx); return 0; } -- cgit v1.2.3