summaryrefslogtreecommitdiffstats
path: root/video/decode
diff options
context:
space:
mode:
Diffstat (limited to 'video/decode')
-rw-r--r--video/decode/d3d.c36
-rw-r--r--video/decode/hw_d3d11va.c47
-rw-r--r--video/decode/hw_dxva2.c36
-rw-r--r--video/decode/lavc.h4
-rw-r--r--video/decode/vd_lavc.c35
5 files changed, 71 insertions, 87 deletions
diff --git a/video/decode/d3d.c b/video/decode/d3d.c
index cab878bafe..a9b67eb0a9 100644
--- a/video/decode/d3d.c
+++ b/video/decode/d3d.c
@@ -124,8 +124,38 @@ static void d3d11_complete_image_params(struct mp_image *img)
mp_image_setfmt(img, IMGFMT_D3D11NV12);
}
+static struct AVBufferRef *d3d11_create_standalone(struct mpv_global *global,
+ struct mp_log *plog, struct hwcontext_create_dev_params *params)
+{
+ ID3D11Device *device = NULL;
+ HRESULT hr;
+
+ d3d_load_dlls();
+ if (!d3d11_D3D11CreateDevice) {
+ mp_err(plog, "Failed to load D3D11 library\n");
+ return NULL;
+ }
+
+ hr = d3d11_D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL,
+ D3D11_CREATE_DEVICE_VIDEO_SUPPORT, NULL, 0,
+ D3D11_SDK_VERSION, &device, NULL, NULL);
+ if (FAILED(hr)) {
+ mp_err(plog, "Failed to create D3D11 Device: %s\n",
+ mp_HRESULT_to_str(hr));
+ return NULL;
+ }
+
+ AVBufferRef *avref = d3d11_wrap_device_ref(device);
+ ID3D11Device_Release(device);
+ if (!avref)
+ mp_err(plog, "Failed to allocate AVHWDeviceContext.\n");
+
+ return avref;
+}
+
const struct hwcontext_fns hwcontext_fns_d3d11 = {
- .av_hwdevice_type = AV_HWDEVICE_TYPE_D3D11VA,
- .complete_image_params = d3d11_complete_image_params,
- .refine_hwframes = d3d11_refine_hwframes,
+ .av_hwdevice_type = AV_HWDEVICE_TYPE_D3D11VA,
+ .complete_image_params = d3d11_complete_image_params,
+ .refine_hwframes = d3d11_refine_hwframes,
+ .create_dev = d3d11_create_standalone,
};
diff --git a/video/decode/hw_d3d11va.c b/video/decode/hw_d3d11va.c
index cc1d122f59..76af9a52a9 100644
--- a/video/decode/hw_d3d11va.c
+++ b/video/decode/hw_d3d11va.c
@@ -33,50 +33,6 @@
#include <libavutil/hwcontext.h>
#include <libavutil/hwcontext_d3d11va.h>
-static void d3d11_destroy_dev(struct mp_hwdec_ctx *ctx)
-{
- av_buffer_unref(&ctx->av_device_ref);
- ID3D11Device_Release((ID3D11Device *)ctx->ctx);
- talloc_free(ctx);
-}
-
-static struct mp_hwdec_ctx *d3d11_create_dev(struct mpv_global *global,
- struct mp_log *plog, bool probing)
-{
- ID3D11Device *device = NULL;
- HRESULT hr;
-
- d3d_load_dlls();
- if (!d3d11_D3D11CreateDevice) {
- mp_err(plog, "Failed to load D3D11 library\n");
- return NULL;
- }
-
- hr = d3d11_D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL,
- D3D11_CREATE_DEVICE_VIDEO_SUPPORT, NULL, 0,
- D3D11_SDK_VERSION, &device, NULL, NULL);
- if (FAILED(hr)) {
- mp_err(plog, "Failed to create D3D11 Device: %s\n",
- mp_HRESULT_to_str(hr));
- return NULL;
- }
-
- struct mp_hwdec_ctx *ctx = talloc_ptrtype(NULL, ctx);
- *ctx = (struct mp_hwdec_ctx) {
- .type = HWDEC_D3D11VA_COPY,
- .ctx = device,
- .destroy = d3d11_destroy_dev,
- .av_device_ref = d3d11_wrap_device_ref(device),
- };
-
- if (!ctx->av_device_ref) {
- mp_err(plog, "Failed to allocate AVHWDeviceContext.\n");
- d3d11_destroy_dev(ctx);
- return NULL;
- }
-
- return ctx;
-}
const struct vd_lavc_hwdec mp_vd_lavc_d3d11va = {
.type = HWDEC_D3D11VA,
@@ -90,7 +46,8 @@ const struct vd_lavc_hwdec mp_vd_lavc_d3d11va_copy = {
.copying = true,
.image_format = IMGFMT_D3D11VA,
.generic_hwaccel = true,
- .create_dev = d3d11_create_dev,
+ .create_standalone_dev = true,
+ .create_standalone_dev_type = AV_HWDEVICE_TYPE_D3D11VA,
.set_hwframes = true,
.delay_queue = HWDEC_DELAY_QUEUE_COUNT,
};
diff --git a/video/decode/hw_dxva2.c b/video/decode/hw_dxva2.c
index 37b2b78003..ede494ff4f 100644
--- a/video/decode/hw_dxva2.c
+++ b/video/decode/hw_dxva2.c
@@ -88,15 +88,8 @@ fail:
return NULL;
}
-static void d3d9_destroy_dev(struct mp_hwdec_ctx *ctx)
-{
- av_buffer_unref(&ctx->av_device_ref);
- IDirect3DDevice9_Release((IDirect3DDevice9 *)ctx->ctx);
- talloc_free(ctx);
-}
-
-static struct mp_hwdec_ctx *d3d9_create_dev(struct mpv_global *global,
- struct mp_log *plog, bool probing)
+static struct AVBufferRef *d3d9_create_standalone(struct mpv_global *global,
+ struct mp_log *plog, struct hwcontext_create_dev_params *params)
{
d3d_load_dlls();
if (!d3d9_dll || !dxva2_dll) {
@@ -149,23 +142,19 @@ static struct mp_hwdec_ctx *d3d9_create_dev(struct mpv_global *global,
return NULL;
}
- struct mp_hwdec_ctx *ctx = talloc_ptrtype(NULL, ctx);
- *ctx = (struct mp_hwdec_ctx) {
- .type = HWDEC_D3D11VA_COPY,
- .ctx = exdev,
- .destroy = d3d9_destroy_dev,
- .av_device_ref = d3d9_wrap_device_ref((IDirect3DDevice9 *)exdev),
- };
-
- if (!ctx->av_device_ref) {
+ AVBufferRef *avref = d3d9_wrap_device_ref((IDirect3DDevice9 *)exdev);
+ IDirect3DDevice9Ex_Release(exdev);
+ if (!avref)
mp_err(plog, "Failed to allocate AVHWDeviceContext.\n");
- d3d9_destroy_dev(ctx);
- return NULL;
- }
- return ctx;
+ return avref;
}
+const struct hwcontext_fns hwcontext_fns_dxva2 = {
+ .av_hwdevice_type = AV_HWDEVICE_TYPE_DXVA2,
+ .create_dev = d3d9_create_standalone,
+};
+
const struct vd_lavc_hwdec mp_vd_lavc_dxva2 = {
.type = HWDEC_DXVA2,
.image_format = IMGFMT_DXVA2,
@@ -178,7 +167,8 @@ const struct vd_lavc_hwdec mp_vd_lavc_dxva2_copy = {
.copying = true,
.image_format = IMGFMT_DXVA2,
.generic_hwaccel = true,
- .create_dev = d3d9_create_dev,
+ .create_standalone_dev = true,
+ .create_standalone_dev_type = AV_HWDEVICE_TYPE_DXVA2,
.set_hwframes = true,
.delay_queue = HWDEC_DELAY_QUEUE_COUNT,
};
diff --git a/video/decode/lavc.h b/video/decode/lavc.h
index b427ae17a2..114e454c54 100644
--- a/video/decode/lavc.h
+++ b/video/decode/lavc.h
@@ -97,10 +97,6 @@ struct vd_lavc_hwdec {
int (*init)(struct lavc_ctx *ctx);
int (*init_decoder)(struct lavc_ctx *ctx);
void (*uninit)(struct lavc_ctx *ctx);
- // For copy hwdecs. If probing is true, don't log errors if unavailable.
- // The returned device will be freed with mp_hwdec_ctx->destroy.
- struct mp_hwdec_ctx *(*create_dev)(struct mpv_global *global,
- struct mp_log *log, bool probing);
// Suffix for libavcodec decoder. If non-NULL, the codec is overridden
// with hwdec_find_decoder.
// Intuitively, this will force the corresponding wrapper decoder.
diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c
index 90217f5b8d..1097577c05 100644
--- a/video/decode/vd_lavc.c
+++ b/video/decode/vd_lavc.c
@@ -200,7 +200,8 @@ static const struct vd_lavc_hwdec mp_vd_lavc_vaapi_copy = {
.image_format = IMGFMT_VAAPI,
.generic_hwaccel = true,
.set_hwframes = true,
- .create_dev = va_create_standalone,
+ .create_standalone_dev = true,
+ .create_standalone_dev_type = AV_HWDEVICE_TYPE_VAAPI,
};
#endif
@@ -220,7 +221,8 @@ static const struct vd_lavc_hwdec mp_vd_lavc_vdpau_copy = {
.image_format = IMGFMT_VDPAU,
.generic_hwaccel = true,
.set_hwframes = true,
- .create_dev = vdpau_create_standalone,
+ .create_standalone_dev = true,
+ .create_standalone_dev_type = AV_HWDEVICE_TYPE_VDPAU,
};
#endif
@@ -358,16 +360,27 @@ static struct mp_hwdec_ctx *hwdec_create_dev(struct dec_video *vd,
.ctx = NULL,
.destroy = standalone_dev_destroy,
};
- if (av_hwdevice_ctx_create(&ctx->av_device_ref,
+ const struct hwcontext_fns *fns =
+ hwdec_get_hwcontext_fns(hwdec->create_standalone_dev_type);
+ if (fns && fns->create_dev) {
+ struct hwcontext_create_dev_params params = {
+ .probing = autoprobe,
+ };
+ ctx->av_device_ref = fns->create_dev(vd->global, vd->log, &params);
+ if (!ctx->av_device_ref) {
+ standalone_dev_destroy(ctx);
+ ctx = NULL;
+ }
+ } else {
+ if (av_hwdevice_ctx_create(&ctx->av_device_ref,
hwdec->create_standalone_dev_type, NULL, NULL, 0) < 0)
- {
- standalone_dev_destroy(ctx);
- ctx = NULL;
+ {
+ standalone_dev_destroy(ctx);
+ ctx = NULL;
+ }
}
return ctx;
}
- if (hwdec->create_dev)
- return hwdec->create_dev(vd->global, vd->log, autoprobe);
if (vd->hwdec_devs) {
int type = hwdec->interop_type ? hwdec->interop_type : hwdec->type;
hwdec_devices_request_all(vd->hwdec_devs);
@@ -391,8 +404,7 @@ static int hwdec_probe(struct dec_video *vd, struct vd_lavc_hwdec *hwdec,
return hwdec->copying ? -1 : HWDEC_ERR_NO_CTX;
if (dev->emulated)
r = HWDEC_ERR_EMULATED;
- bool owns_hwdec_dev = !!hwdec->create_dev ||
- hwdec->create_standalone_dev;
+ bool owns_hwdec_dev = !!hwdec->create_standalone_dev;
if (owns_hwdec_dev && dev->destroy)
dev->destroy(dev);
}
@@ -594,8 +606,7 @@ static void init_avctx(struct dec_video *vd, const char *decoder,
ctx->hwdec_dev = hwdec_create_dev(vd, ctx->hwdec, false);
if (!ctx->hwdec_dev)
goto error;
- ctx->owns_hwdec_dev = !!ctx->hwdec->create_dev ||
- ctx->hwdec->create_standalone_dev;
+ ctx->owns_hwdec_dev = ctx->hwdec->create_standalone_dev;
if (ctx->hwdec_dev->restore_device)
ctx->hwdec_dev->restore_device(ctx->hwdec_dev);
if (!ctx->hwdec->set_hwframes)