hwdec: do not add hwdec device if it failed to create

This commit is contained in:
Kacper Michajłow 2023-06-19 20:32:44 +02:00 committed by sfan5
parent a5b9290261
commit 4dfc2c50c1
10 changed files with 64 additions and 8 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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:

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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;
}