hwdec: don't require setting legacy hwdec fields

With the recent changes, mpv's internal mechanisms got synced to
libavcodec's once more. Some things are still needed for filters (until
the mechanism gets replaced), but there's no need to require other hwdec
methods to use these fields. So remove them where they are unnecessary.

Also fix some minor leaks in the dxva2 backends, and set the driver_name
field in the Apple ones. Untested on Apple crap.
This commit is contained in:
wm4 2017-12-02 03:58:04 +01:00
parent 8b3dbab19e
commit 0780d38329
7 changed files with 18 additions and 30 deletions

View File

@ -40,7 +40,7 @@ struct mp_hwdec_ctx *hwdec_devices_get(struct mp_hwdec_devices *devs,
struct mp_hwdec_ctx *res = NULL;
pthread_mutex_lock(&devs->lock);
for (int n = 0; n < devs->num_hwctxs; n++) {
if (devs->hwctxs[n]->type == type) {
if (type && devs->hwctxs[n]->type == type) {
res = devs->hwctxs[n];
break;
}

View File

@ -1,6 +1,8 @@
#ifndef MP_HWDEC_H_
#define MP_HWDEC_H_
#include <libavutil/buffer.h>
#include "options/m_option.h"
struct mp_image_pool;
@ -9,24 +11,21 @@ struct mp_image_pool;
enum hwdec_type {
HWDEC_NONE = 0,
HWDEC_VDPAU,
HWDEC_VIDEOTOOLBOX,
HWDEC_VAAPI,
HWDEC_DXVA2,
HWDEC_D3D11VA,
HWDEC_CUDA,
};
struct mp_hwdec_ctx {
enum hwdec_type type; // (never HWDEC_NONE)
// Only needed for some filters. The main effect is that hwdec_devices_get()
// can be used. Leave unsert (i.e. HWDEC_NONE) if not needed.
enum hwdec_type type;
const char *driver_name; // NULL if unknown/not loaded
// This is never NULL. Its meaning depends on the .type field:
// The meaning depends on the .type field:
// HWDEC_VDPAU: struct mp_vdpau_ctx*
// HWDEC_VIDEOTOOLBOX: non-NULL dummy pointer
// HWDEC_VAAPI: struct mp_vaapi_ctx*
// HWDEC_D3D11VA: ID3D11Device*
// HWDEC_DXVA2: IDirect3DDevice9*
// HWDEC_CUDA: CUcontext*
void *ctx;
// libavutil-wrapped context, if available.

View File

@ -160,11 +160,9 @@ static int cuda_init(struct ra_hwdec *hw)
goto error;
p->hwctx = (struct mp_hwdec_ctx) {
.type = HWDEC_CUDA,
.ctx = p->decode_ctx,
.driver_name = hw->driver->name,
.av_device_ref = hw_device_ctx,
};
p->hwctx.driver_name = hw->driver->name;
hwdec_devices_add(hw->devs, &p->hwctx);
return 0;
@ -179,8 +177,7 @@ static void cuda_uninit(struct ra_hwdec *hw)
{
struct priv_owner *p = hw->priv;
if (p->hwctx.ctx)
hwdec_devices_remove(hw->devs, &p->hwctx);
hwdec_devices_remove(hw->devs, &p->hwctx);
av_buffer_unref(&p->hwctx.av_device_ref);
if (p->decode_ctx && p->decode_ctx != p->display_ctx)

View File

@ -58,8 +58,8 @@ static void uninit(struct ra_hwdec *hw)
{
struct priv_owner *p = hw->priv;
if (p->hwctx.ctx)
hwdec_devices_remove(hw->devs, &p->hwctx);
hwdec_devices_remove(hw->devs, &p->hwctx);
av_buffer_unref(&p->hwctx.av_device_ref);
if (p->device9ex)
IDirect3DDevice9Ex_Release(p->device9ex);
@ -180,9 +180,7 @@ static int init(struct ra_hwdec *hw)
ra_hwdec_mapper_free(&mapper);
p->hwctx = (struct mp_hwdec_ctx){
.type = HWDEC_DXVA2,
.driver_name = hw->driver->name,
.ctx = (IDirect3DDevice9 *)p->device9ex,
.av_device_ref = d3d9_wrap_device_ref((IDirect3DDevice9 *)p->device9ex),
};
hwdec_devices_add(hw->devs, &p->hwctx);

View File

@ -48,8 +48,8 @@ static void uninit(struct ra_hwdec *hw)
{
struct priv_owner *p = hw->priv;
if (p->hwctx.ctx)
hwdec_devices_remove(hw->devs, &p->hwctx);
hwdec_devices_remove(hw->devs, &p->hwctx);
av_buffer_unref(&p->hwctx.av_device_ref);
if (p->device)
IDirect3DDevice9Ex_Release(p->device);
@ -78,9 +78,7 @@ static int init(struct ra_hwdec *hw)
IDirect3DDevice9Ex_AddRef(p->device);
p->hwctx = (struct mp_hwdec_ctx){
.type = HWDEC_DXVA2,
.driver_name = hw->driver->name,
.ctx = (IDirect3DDevice9 *)p->device,
.av_device_ref = d3d9_wrap_device_ref((IDirect3DDevice9 *)p->device),
};
hwdec_devices_add(hw->devs, &p->hwctx);

View File

@ -69,8 +69,7 @@ static int init(struct ra_hwdec *hw)
return -1;
p->hwctx = (struct mp_hwdec_ctx){
.type = HWDEC_VIDEOTOOLBOX,
.ctx = &p->hwctx,
.driver_name = hw->driver->name,
};
av_hwdevice_ctx_create(&p->hwctx.av_device_ref, AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
@ -85,8 +84,7 @@ static void uninit(struct ra_hwdec *hw)
{
struct priv_owner *p = hw->priv;
if (p->hwctx.ctx)
hwdec_devices_remove(hw->devs, &p->hwctx);
hwdec_devices_remove(hw->devs, &p->hwctx);
av_buffer_unref(&p->hwctx.av_device_ref);
}

View File

@ -70,8 +70,7 @@ static int init(struct ra_hwdec *hw)
return -1;
p->hwctx = (struct mp_hwdec_ctx){
.type = HWDEC_VIDEOTOOLBOX,
.ctx = &p->hwctx,
.driver_name = hw->driver->name,
};
av_hwdevice_ctx_create(&p->hwctx.av_device_ref, AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
@ -86,8 +85,7 @@ static void uninit(struct ra_hwdec *hw)
{
struct priv_owner *p = hw->priv;
if (p->hwctx.ctx)
hwdec_devices_remove(hw->devs, &p->hwctx);
hwdec_devices_remove(hw->devs, &p->hwctx);
av_buffer_unref(&p->hwctx.av_device_ref);
}