From 292724538cfbe2a6c713420f8b5be0abf75ad46c Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 2 Dec 2017 04:33:43 +0100 Subject: 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. --- video/filter/vf_d3d11vpp.c | 22 ++++++++++++++++++---- video/filter/vf_vavpp.c | 21 ++++++++++++++++----- video/filter/vf_vdpaupp.c | 15 +++++++++++++-- video/hwdec.c | 24 ------------------------ video/hwdec.h | 34 ---------------------------------- video/out/d3d11/hwdec_d3d11va.c | 5 +---- video/out/opengl/hwdec_d3d11egl.c | 5 +---- video/out/opengl/hwdec_d3d11eglrgb.c | 5 +---- video/vaapi.c | 2 -- video/vdpau.c | 10 ---------- 10 files changed, 50 insertions(+), 93 deletions(-) (limited to 'video') diff --git a/video/filter/vf_d3d11vpp.c b/video/filter/vf_d3d11vpp.c index cafa5df122..f49af06424 100644 --- a/video/filter/vf_d3d11vpp.c +++ b/video/filter/vf_d3d11vpp.c @@ -19,6 +19,9 @@ #include #include +#include +#include + #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, diff --git a/video/filter/vf_vavpp.c b/video/filter/vf_vavpp.c index 4d2cc0981f..edee556232 100644 --- a/video/filter/vf_vavpp.c +++ b/video/filter/vf_vavpp.c @@ -21,6 +21,7 @@ #include #include +#include #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; diff --git a/video/filter/vf_vdpaupp.c b/video/filter/vf_vdpaupp.c index a583e386f2..de1979cf05 100644 --- a/video/filter/vf_vdpaupp.c +++ b/video/filter/vf_vdpaupp.c @@ -21,6 +21,8 @@ #include #include +#include + #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) diff --git a/video/hwdec.c b/video/hwdec.c index 79714f60e0..b52b082a38 100644 --- a/video/hwdec.c +++ b/video/hwdec.c @@ -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; diff --git a/video/hwdec.h b/video/hwdec.h index 2c0f19b606..80d5cfcecc 100644 --- a/video/hwdec.h +++ b/video/hwdec.h @@ -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); diff --git a/video/out/d3d11/hwdec_d3d11va.c b/video/out/d3d11/hwdec_d3d11va.c index 1be79a3748..d83fdc57af 100644 --- a/video/out/d3d11/hwdec_d3d11va.c +++ b/video/out/d3d11/hwdec_d3d11va.c @@ -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); diff --git a/video/out/opengl/hwdec_d3d11egl.c b/video/out/opengl/hwdec_d3d11egl.c index e2b188f4b5..e7416330d7 100644 --- a/video/out/opengl/hwdec_d3d11egl.c +++ b/video/out/opengl/hwdec_d3d11egl.c @@ -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); diff --git a/video/out/opengl/hwdec_d3d11eglrgb.c b/video/out/opengl/hwdec_d3d11eglrgb.c index 78bc38e93e..c8f6580320 100644 --- a/video/out/opengl/hwdec_d3d11eglrgb.c +++ b/video/out/opengl/hwdec_d3d11eglrgb.c @@ -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); diff --git a/video/vaapi.c b/video/vaapi.c index 00052cec39..c3327ce305 100644 --- a/video/vaapi.c +++ b/video/vaapi.c @@ -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, }, }; diff --git a/video/vdpau.c b/video/vdpau.c index d751849ec3..7d0ff145b0 100644 --- a/video/vdpau.c +++ b/video/vdpau.c @@ -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, }, }; -- cgit v1.2.3