1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-16 12:17:12 +00:00

video: remove some more hwdec legacy stuff

Finally get rid of all the HWDEC_* things, and instead rely on the
libavutil equivalents. vdpau still uses a shitty hack, but fuck the
vdpau code.

Remove all the now unneeded remains. The vdpau preemption thing was not
unused anymore; if someone cares this could probably be restored.
This commit is contained in:
wm4 2017-12-02 04:33:43 +01:00
parent 23a9efd124
commit 292724538c
10 changed files with 50 additions and 93 deletions

View File

@ -19,6 +19,9 @@
#include <windows.h>
#include <d3d11.h>
#include <libavutil/hwcontext.h>
#include <libavutil/hwcontext_d3d11va.h>
#include "common/common.h"
#include "osdep/timer.h"
#include "osdep/windows_utils.h"
@ -477,6 +480,9 @@ static int vf_open(vf_instance_t *vf)
{
struct vf_priv_s *p = vf->priv;
if (!vf->hwdec_devs)
return 0;
vf->reconfig = reconfig;
vf->filter_ext = filter_ext;
vf->filter_out = filter_out;
@ -484,14 +490,22 @@ static int vf_open(vf_instance_t *vf)
vf->uninit = uninit;
vf->control = control;
p->queue = mp_refqueue_alloc();
p->vo_dev = hwdec_devices_load(vf->hwdec_devs, HWDEC_D3D11VA);
if (!p->vo_dev)
hwdec_devices_request_all(vf->hwdec_devs);
AVBufferRef *ref =
hwdec_devices_get_lavc(vf->hwdec_devs, AV_HWDEVICE_TYPE_D3D11VA);
if (!ref)
return 0;
AVHWDeviceContext *hwctx = (void *)ref->data;
AVD3D11VADeviceContext *d3dctx = hwctx->hwctx;
p->vo_dev = d3dctx->device;
ID3D11Device_AddRef(p->vo_dev);
av_buffer_unref(&ref);
p->queue = mp_refqueue_alloc();
HRESULT hr;
hr = ID3D11Device_QueryInterface(p->vo_dev, &IID_ID3D11VideoDevice,

View File

@ -21,6 +21,7 @@
#include <va/va_vpp.h>
#include <libavutil/hwcontext.h>
#include <libavutil/hwcontext_vaapi.h>
#include "config.h"
#include "options/options.h"
@ -57,7 +58,7 @@ struct vf_priv_s {
VAContextID context;
struct mp_image_params params;
VADisplay display;
struct mp_vaapi_ctx *va;
AVBufferRef *av_device_ref;
struct pipeline pipe;
AVBufferRef *hw_pool;
@ -358,7 +359,7 @@ static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
out->hw_subfmt = IMGFMT_NV12;
}
p->hw_pool = av_hwframe_ctx_alloc(p->va->av_device_ref);
p->hw_pool = av_hwframe_ctx_alloc(p->av_device_ref);
if (!p->hw_pool)
return -1;
AVHWFramesContext *hw_frames = (void *)p->hw_pool->data;
@ -387,6 +388,7 @@ static void uninit(struct vf_instance *vf)
av_buffer_unref(&p->hw_pool);
flush_frames(vf);
mp_refqueue_free(p->queue);
av_buffer_unref(&p->av_device_ref);
}
static int query_format(struct vf_instance *vf, unsigned int imgfmt)
@ -489,6 +491,9 @@ static int vf_open(vf_instance_t *vf)
{
struct vf_priv_s *p = vf->priv;
if (!vf->hwdec_devs)
return 0;
vf->reconfig = reconfig;
vf->filter_ext = filter_ext;
vf->filter_out = filter_out;
@ -498,12 +503,18 @@ static int vf_open(vf_instance_t *vf)
p->queue = mp_refqueue_alloc();
p->va = hwdec_devices_load(vf->hwdec_devs, HWDEC_VAAPI);
if (!p->va || !p->va->av_device_ref) {
hwdec_devices_request_all(vf->hwdec_devs);
p->av_device_ref =
hwdec_devices_get_lavc(vf->hwdec_devs, AV_HWDEVICE_TYPE_VAAPI);
if (!p->av_device_ref) {
uninit(vf);
return 0;
}
p->display = p->va->display;
AVHWDeviceContext *hwctx = (void *)p->av_device_ref->data;
AVVAAPIDeviceContext *vactx = hwctx->hwctx;
p->display = vactx->display;
if (initialize(vf))
return true;

View File

@ -21,6 +21,8 @@
#include <inttypes.h>
#include <assert.h>
#include <libavutil/hwcontext.h>
#include "common/common.h"
#include "common/msg.h"
#include "options/m_option.h"
@ -166,6 +168,9 @@ static int vf_open(vf_instance_t *vf)
{
struct vf_priv_s *p = vf->priv;
if (!vf->hwdec_devs)
return 0;
vf->reconfig = reconfig;
vf->filter_ext = filter_ext;
vf->filter_out = filter_out;
@ -175,9 +180,15 @@ static int vf_open(vf_instance_t *vf)
p->queue = mp_refqueue_alloc();
p->ctx = hwdec_devices_load(vf->hwdec_devs, HWDEC_VDPAU);
if (!p->ctx)
hwdec_devices_request_all(vf->hwdec_devs);
AVBufferRef *ref =
hwdec_devices_get_lavc(vf->hwdec_devs, AV_HWDEVICE_TYPE_VDPAU);
struct mp_vdpau_ctx *ctx = mp_vdpau_get_ctx_from_av(ref);
av_buffer_unref(&ref);
if (!ctx) {
uninit(vf);
return 0;
}
p->def_deintmode = p->opts.deint;
if (!p->deint_enabled)

View File

@ -34,21 +34,6 @@ void hwdec_devices_destroy(struct mp_hwdec_devices *devs)
talloc_free(devs);
}
struct mp_hwdec_ctx *hwdec_devices_get(struct mp_hwdec_devices *devs,
enum hwdec_type type)
{
struct mp_hwdec_ctx *res = NULL;
pthread_mutex_lock(&devs->lock);
for (int n = 0; n < devs->num_hwctxs; n++) {
if (type && devs->hwctxs[n]->type == type) {
res = devs->hwctxs[n];
break;
}
}
pthread_mutex_unlock(&devs->lock);
return res;
}
struct AVBufferRef *hwdec_devices_get_lavc(struct mp_hwdec_devices *devs,
int av_hwdevice_type)
{
@ -109,15 +94,6 @@ void hwdec_devices_request_all(struct mp_hwdec_devices *devs)
devs->load_api(devs->load_api_ctx);
}
void *hwdec_devices_load(struct mp_hwdec_devices *devs, enum hwdec_type type)
{
if (!devs)
return NULL;
hwdec_devices_request_all(devs);
struct mp_hwdec_ctx *hwctx = hwdec_devices_get(devs, type);
return hwctx ? hwctx->ctx : NULL;
}
char *hwdec_devices_get_names(struct mp_hwdec_devices *devs)
{
char *res = NULL;

View File

@ -7,27 +7,9 @@
struct mp_image_pool;
// (for some legacy stuff)
enum hwdec_type {
HWDEC_NONE = 0,
HWDEC_VDPAU,
HWDEC_VAAPI,
HWDEC_D3D11VA,
};
struct mp_hwdec_ctx {
// 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
// The meaning depends on the .type field:
// HWDEC_VDPAU: struct mp_vdpau_ctx*
// HWDEC_VAAPI: struct mp_vaapi_ctx*
// HWDEC_D3D11VA: ID3D11Device*
void *ctx;
// libavutil-wrapped context, if available.
struct AVBufferRef *av_device_ref; // AVHWDeviceContext*
@ -37,9 +19,6 @@ struct mp_hwdec_ctx {
// Hint to generic code: it's using a wrapper API
bool emulated;
// Optional. Crap for vdpau. Makes sure preemption recovery is run if needed.
void (*restore_device)(struct mp_hwdec_ctx *ctx);
// Optional. Do not set for VO-bound devices.
void (*destroy)(struct mp_hwdec_ctx *ctx);
};
@ -54,12 +33,6 @@ void hwdec_devices_destroy(struct mp_hwdec_devices *devs);
// available. Logically, the returned pointer remains valid until VO
// uninitialization is started (all users of it must be uninitialized before).
// hwdec_devices_request() may be used before this to lazily load devices.
struct mp_hwdec_ctx *hwdec_devices_get(struct mp_hwdec_devices *devs,
enum hwdec_type type);
struct AVBufferRef;
// Like hwdec_devices_get(), but search by AV_HWDEVICE_TYPE_* type.
// Contains a wrapped AVHWDeviceContext.
// Beware that this creates a _new_ reference.
struct AVBufferRef *hwdec_devices_get_lavc(struct mp_hwdec_devices *devs,
@ -86,13 +59,6 @@ void hwdec_devices_set_loader(struct mp_hwdec_devices *devs,
// if not available).
void hwdec_devices_request_all(struct mp_hwdec_devices *devs);
// Convenience function:
// - return NULL if devs==NULL
// - call hwdec_devices_request(devs, type)
// - call hwdec_devices_get(devs, type)
// - then return the mp_hwdec_ctx.ctx field
void *hwdec_devices_load(struct mp_hwdec_devices *devs, enum hwdec_type type);
// Return "," concatenated list (for introspection/debugging). Use talloc_free().
char *hwdec_devices_get_names(struct mp_hwdec_devices *devs);

View File

@ -66,8 +66,7 @@ struct priv {
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);
SAFE_RELEASE(p->device);
SAFE_RELEASE(p->device1);
}
@ -106,9 +105,7 @@ static int init(struct ra_hwdec *hw)
ID3D10Multithread_Release(multithread);
p->hwctx = (struct mp_hwdec_ctx){
.type = HWDEC_D3D11VA,
.driver_name = hw->driver->name,
.ctx = p->device,
.av_device_ref = d3d11_wrap_device_ref(p->device),
};
hwdec_devices_add(hw->devs, &p->hwctx);

View File

@ -75,8 +75,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);
if (p->d3d11_device)
ID3D11Device_Release(p->d3d11_device);
@ -180,9 +179,7 @@ static int init(struct ra_hwdec *hw)
ID3D10Multithread_Release(multithread);
p->hwctx = (struct mp_hwdec_ctx){
.type = HWDEC_D3D11VA,
.driver_name = hw->driver->name,
.ctx = p->d3d11_device,
.av_device_ref = d3d11_wrap_device_ref(p->d3d11_device),
};
hwdec_devices_add(hw->devs, &p->hwctx);

View File

@ -54,8 +54,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);
if (p->d3d11_device)
ID3D11Device_Release(p->d3d11_device);
@ -137,9 +136,7 @@ static int init(struct ra_hwdec *hw)
}
p->hwctx = (struct mp_hwdec_ctx){
.type = HWDEC_D3D11VA,
.driver_name = hw->driver->name,
.ctx = p->d3d11_device,
.av_device_ref = d3d11_wrap_device_ref(p->d3d11_device),
};
hwdec_devices_add(hw->devs, &p->hwctx);

View File

@ -139,8 +139,6 @@ struct mp_vaapi_ctx *va_initialize(VADisplay *display, struct mp_log *plog,
.display = display,
.av_device_ref = avref,
.hwctx = {
.type = HWDEC_VAAPI,
.ctx = res,
.av_device_ref = avref,
},
};

View File

@ -330,13 +330,6 @@ struct mp_image *mp_vdpau_get_video_surface(struct mp_vdpau_ctx *ctx,
return mp_vdpau_get_surface(ctx, chroma, 0, false, w, h);
}
static void recheck_preemption(struct mp_hwdec_ctx *hwctx)
{
struct mp_vdpau_ctx *ctx = hwctx->ctx;
mp_vdpau_handle_preemption(ctx, NULL);
}
static void free_device_ref(struct AVHWDeviceContext *hwctx)
{
struct mp_vdpau_ctx *ctx = hwctx->user_opaque;
@ -392,9 +385,6 @@ struct mp_vdpau_ctx *mp_vdpau_create_device_x11(struct mp_log *log, Display *x11
.preemption_counter = 1,
.av_device_ref = avref,
.hwctx = {
.type = HWDEC_VDPAU,
.ctx = ctx,
.restore_device = recheck_preemption,
.av_device_ref = avref,
},
};