vlc | branch: master | Thomas Guillem <[email protected]> | Sun Feb 24 09:59:27 2019 +0100| [e7eae9555ed25ddaa8c159dd78d98ef6e072c3f4] | committer: Thomas Guillem
hw: vaapi: use the "decoder device" module vlc_vaapi_instance is not refcounted anymore, but vlc_decoder_device is. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e7eae9555ed25ddaa8c159dd78d98ef6e072c3f4 --- modules/codec/avcodec/vaapi.c | 10 +- modules/hw/vaapi/Makefile.am | 26 +++++ modules/hw/vaapi/chroma.c | 20 ++-- modules/hw/vaapi/decoder_device.c | 154 ++++++++++++++++++++++++++ modules/hw/vaapi/filters.c | 37 ++++--- modules/hw/vaapi/filters.h | 4 +- modules/hw/vaapi/vlc_vaapi.c | 39 +++---- modules/hw/vaapi/vlc_vaapi.h | 14 +-- modules/video_output/Makefile.am | 31 +----- modules/video_output/opengl/converter_vaapi.c | 123 ++------------------ 10 files changed, 248 insertions(+), 210 deletions(-) diff --git a/modules/codec/avcodec/vaapi.c b/modules/codec/avcodec/vaapi.c index 8bc9609439..a9eddd5bfb 100644 --- a/modules/codec/avcodec/vaapi.c +++ b/modules/codec/avcodec/vaapi.c @@ -50,7 +50,7 @@ struct vlc_va_sys_t { - struct vlc_vaapi_instance *va_inst; + vlc_decoder_device *dec_device; struct vaapi_context hw_ctx; }; @@ -141,7 +141,7 @@ static void Delete(vlc_va_t *va, void *hwctx) vlc_vaapi_DestroyContext(o, sys->hw_ctx.display, sys->hw_ctx.context_id); vlc_vaapi_DestroyConfig(o, sys->hw_ctx.display, sys->hw_ctx.config_id); - vlc_vaapi_ReleaseInstance(sys->va_inst); + vlc_decoder_device_Release(sys->dec_device); free(sys); } @@ -159,7 +159,7 @@ static int Create(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt, /* The picture must be allocated by the vout */ VADisplay va_dpy; - struct vlc_vaapi_instance *va_inst = + vlc_decoder_device *dec_device = vlc_vaapi_PicSysHoldInstance(p_sys, &va_dpy); VASurfaceID *render_targets; @@ -183,7 +183,7 @@ static int Create(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt, memset(sys, 0, sizeof (*sys)); /* */ - sys->va_inst = va_inst; + sys->dec_device = dec_device; sys->hw_ctx.display = va_dpy; sys->hw_ctx.config_id = VA_INVALID_ID; sys->hw_ctx.context_id = VA_INVALID_ID; @@ -218,7 +218,7 @@ error: vlc_vaapi_DestroyConfig(o, sys->hw_ctx.display, sys->hw_ctx.config_id); free(sys); } - vlc_vaapi_ReleaseInstance(va_inst); + vlc_decoder_device_Release(dec_device); return ret; } diff --git a/modules/hw/vaapi/Makefile.am b/modules/hw/vaapi/Makefile.am index 194bff14f8..dc47f9badf 100644 --- a/modules/hw/vaapi/Makefile.am +++ b/modules/hw/vaapi/Makefile.am @@ -1,5 +1,18 @@ vaapidir = $(pluginsdir)/vaapi +libdecdev_vaapi_wl_plugin_la_SOURCES = hw/vaapi/decoder_device.c \ + hw/vaapi/vlc_vaapi.c hw/vaapi/vlc_vaapi.h +libdecdev_vaapi_wl_plugin_la_CFLAGS = $(AM_CFLAGS) $(GL_CFLAGS) -DHAVE_VA_WL $(LIBVA_WL_CFLAGS) +libdecdev_vaapi_wl_plugin_la_LIBADD = $(LIBVA_LIBS) $(LIBVA_WL_LIBS) + +libdecdev_vaapi_x11_plugin_la_SOURCES = $(libdecdev_vaapi_wl_plugin_la_SOURCES) +libdecdev_vaapi_x11_plugin_la_CFLAGS = $(AM_CFLAGS) -DHAVE_VA_X11 +libdecdev_vaapi_x11_plugin_la_LIBADD = $(LIBVA_LIBS) $(LIBVA_X11_LIBS) $(X_LIBS) $(X_PRE_LIBS) -lX11 + +libdecdev_vaapi_drm_plugin_la_SOURCES = $(libdecdev_vaapi_wl_plugin_la_SOURCES) +libdecdev_vaapi_drm_plugin_la_CFLAGS = $(AM_CFLAGS) -DHAVE_VA_DRM +libdecdev_vaapi_drm_plugin_la_LIBADD = $(LIBVA_LIBS) $(LIBVA_DRM_LIBS) + libvaapi_filters_plugin_la_SOURCES = hw/vaapi/filters.c hw/vaapi/filters.h \ hw/vaapi/vlc_vaapi.c hw/vaapi/vlc_vaapi.h \ hw/vaapi/chroma.c @@ -10,4 +23,17 @@ libvaapi_filters_plugin_la_LIBADD = libchroma_copy.la $(AM_LIBADD) $(LIBVA_LIBS) if HAVE_VAAPI vaapi_LTLIBRARIES = libvaapi_filters_plugin.la +if HAVE_WAYLAND +if HAVE_VAAPI_WL +vaapi_LTLIBRARIES += libdecdev_vaapi_wl_plugin.la +endif +endif +if HAVE_XCB +if HAVE_VAAPI_X11 +vaapi_LTLIBRARIES += libdecdev_vaapi_x11_plugin.la +endif +endif +if HAVE_VAAPI_DRM +vaapi_LTLIBRARIES += libdecdev_vaapi_drm_plugin.la +endif endif diff --git a/modules/hw/vaapi/chroma.c b/modules/hw/vaapi/chroma.c index d8bb7d7ae2..9634654630 100644 --- a/modules/hw/vaapi/chroma.c +++ b/modules/hw/vaapi/chroma.c @@ -39,7 +39,7 @@ typedef struct { - struct vlc_vaapi_instance *va_inst; + vlc_decoder_device *dec_device; VADisplay dpy; picture_pool_t * dest_pics; VASurfaceID * va_surface_ids; @@ -345,22 +345,22 @@ vlc_vaapi_OpenChroma(vlc_object_t *obj) filter_sys->image_fallback_failed = false; if (is_upload) { - filter_sys->va_inst = vlc_vaapi_FilterHoldInstance(filter, - &filter_sys->dpy); + filter_sys->dec_device = vlc_vaapi_FilterHoldInstance(filter, + &filter_sys->dpy); - if (filter_sys->va_inst == NULL) + if (filter_sys->dec_device == NULL) { free(filter_sys); return VLC_EGENERIC; } filter_sys->dest_pics = - vlc_vaapi_PoolNew(obj, filter_sys->va_inst, filter_sys->dpy, + vlc_vaapi_PoolNew(obj, filter_sys->dec_device, filter_sys->dpy, DEST_PICS_POOL_SZ, &filter_sys->va_surface_ids, &filter->fmt_out.video, true); if (!filter_sys->dest_pics) { - vlc_vaapi_FilterReleaseInstance(filter, filter_sys->va_inst); + vlc_vaapi_FilterReleaseInstance(filter, filter_sys->dec_device); free(filter_sys); return VLC_EGENERIC; } @@ -369,7 +369,7 @@ vlc_vaapi_OpenChroma(vlc_object_t *obj) { /* Don't fetch the vaapi instance since it may be not created yet at * this point (in case of cpu rendering) */ - filter_sys->va_inst = NULL; + filter_sys->dec_device = NULL; filter_sys->dpy = NULL; filter_sys->dest_pics = NULL; } @@ -380,7 +380,7 @@ vlc_vaapi_OpenChroma(vlc_object_t *obj) if (is_upload) { picture_pool_Release(filter_sys->dest_pics); - vlc_vaapi_FilterReleaseInstance(filter, filter_sys->va_inst); + vlc_vaapi_FilterReleaseInstance(filter, filter_sys->dec_device); } free(filter_sys); return VLC_EGENERIC; @@ -404,8 +404,8 @@ vlc_vaapi_CloseChroma(vlc_object_t *obj) if (filter_sys->dest_pics) picture_pool_Release(filter_sys->dest_pics); - if (filter_sys->va_inst != NULL) - vlc_vaapi_FilterReleaseInstance(filter, filter_sys->va_inst); + if (filter_sys->dec_device != NULL) + vlc_vaapi_FilterReleaseInstance(filter, filter_sys->dec_device); CopyCleanCache(&filter_sys->cache); free(filter_sys); diff --git a/modules/hw/vaapi/decoder_device.c b/modules/hw/vaapi/decoder_device.c new file mode 100644 index 0000000000..1dbb69ec16 --- /dev/null +++ b/modules/hw/vaapi/decoder_device.c @@ -0,0 +1,154 @@ +/***************************************************************************** + * decoder_device.c: VAAPI decoder_device + ***************************************************************************** + * Copyright (C) 2017-2019 VLC authors and VideoLAN + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <vlc_common.h> +#include <vlc_plugin.h> +#include <vlc_vout_window.h> +#include <vlc_codec.h> + +#include "hw/vaapi/vlc_vaapi.h" +#include <va/va_drmcommon.h> + +#ifdef HAVE_VA_WL +# include <va/va_wayland.h> +#endif + +#ifdef HAVE_VA_X11 +# include <va/va_x11.h> +# include <vlc_xlib.h> +#endif + +#ifdef HAVE_VA_DRM +# include <va/va_drm.h> +# include <vlc_fs.h> +# include <fcntl.h> +#endif + +#ifdef HAVE_VA_X11 +static void +x11_native_destroy_cb(VANativeDisplay native) +{ + XCloseDisplay(native); +} + +static struct vlc_vaapi_instance * +x11_init_vaapi_instance(vlc_decoder_device *device, vout_window_t *window, + VADisplay *vadpyp) +{ + if (!vlc_xlib_init(VLC_OBJECT(window))) + return NULL; + + Display *x11dpy = XOpenDisplay(window->display.x11); + if (x11dpy == NULL) + return NULL; + + VADisplay vadpy = *vadpyp = vaGetDisplay(x11dpy); + if (vadpy == NULL) + { + x11_native_destroy_cb(x11dpy); + return NULL; + } + + return vlc_vaapi_InitializeInstance(VLC_OBJECT(device), vadpy, + x11dpy, x11_native_destroy_cb); +} +#endif + +#ifdef HAVE_VA_DRM +static struct vlc_vaapi_instance * +drm_init_vaapi_instance(vlc_decoder_device *device, VADisplay *vadpyp) +{ + return vlc_vaapi_InitializeInstanceDRM(VLC_OBJECT(device), vaGetDisplayDRM, + vadpyp, NULL); +} +#endif + +#ifdef HAVE_VA_WL +static struct vlc_vaapi_instance * +wl_init_vaapi_instance(vlc_decoder_device *device, vout_window_t *window, + VADisplay *vadpyp) +{ + VADisplay vadpy = *vadpyp = vaGetDisplayWl(window->display.wl); + if (vadpy == NULL) + return NULL; + + return vlc_vaapi_InitializeInstance(VLC_OBJECT(device), vadpy, NULL, NULL); +} +#endif + +static void +Close(vlc_decoder_device *device) +{ + vlc_vaapi_DestroyInstance(device->sys); +} + +static int +Open(vlc_decoder_device *device, vout_window_t *window) +{ + VADisplay vadpy = NULL; + struct vlc_vaapi_instance *vainst = NULL; +#if defined (HAVE_VA_X11) + if (window && window->type == VOUT_WINDOW_TYPE_XID) + vainst = x11_init_vaapi_instance(device, window, &vadpy); +#elif defined(HAVE_VA_WL) + if (window && window->type == VOUT_WINDOW_TYPE_WAYLAND) + vainst = wl_init_vaapi_instance(device, window, &vadpy); +#elif defined (HAVE_VA_DRM) + (void) window; + vainst = drm_init_vaapi_instance(device, &vadpy); +#else +# error need X11/WL/DRM support +#endif + if (!vainst) + return VLC_EGENERIC; + assert(vadpy != NULL); + + device->sys = vainst; + device->type = VLC_DECODER_DEVICE_VAAPI; + device->opaque = vadpy; + return VLC_SUCCESS; +} + +#if defined (HAVE_VA_X11) +# define PRIORITY 2 +# define SHORTCUT "vaapi_x11" +# define DESCRIPTION_SUFFIX "X11" +#elif defined(HAVE_VA_WL) +# define PRIORITY 2 +# define SHORTCUT "vaapi_wl" +# define DESCRIPTION_SUFFIX "Wayland" +#elif defined (HAVE_VA_DRM) +# define PRIORITY 1 +# define SHORTCUT "vaapi_drm" +# define DESCRIPTION_SUFFIX "DRM" +#endif + +vlc_module_begin () + set_description("VA-API decoder device for " DESCRIPTION_SUFFIX) + set_capability("decoder device", PRIORITY) + set_callbacks(Open, Close) + set_category(CAT_VIDEO) + set_subcategory(SUBCAT_VIDEO_VOUT) + add_shortcut("vaapi", SHORTCUT) +vlc_module_end () diff --git a/modules/hw/vaapi/filters.c b/modules/hw/vaapi/filters.c index 482321d969..97f025f3f2 100644 --- a/modules/hw/vaapi/filters.c +++ b/modules/hw/vaapi/filters.c @@ -44,11 +44,11 @@ * filter is destroyed before the other ones. */ static struct { vlc_mutex_t lock; - struct vlc_vaapi_instance *inst; + vlc_decoder_device *dec_device; filter_t *owner; } holder = { VLC_STATIC_MUTEX, NULL, NULL }; -struct vlc_vaapi_instance * +vlc_decoder_device * vlc_vaapi_FilterHoldInstance(filter_t *filter, VADisplay *dpy) { @@ -62,35 +62,36 @@ vlc_vaapi_FilterHoldInstance(filter_t *filter, VADisplay *dpy) return NULL; } - struct vlc_vaapi_instance *va_inst = NULL; + vlc_decoder_device *dec_device = NULL; vlc_mutex_lock(&holder.lock); - if (holder.inst != NULL) + if (holder.dec_device != NULL) { - va_inst = holder.inst; - *dpy = vlc_vaapi_HoldInstance(holder.inst); + dec_device = vlc_decoder_device_Hold(holder.dec_device); + *dpy = dec_device->opaque; } else { holder.owner = filter; - holder.inst = va_inst = pic->p_sys ? + holder.dec_device = dec_device = pic->p_sys ? vlc_vaapi_PicSysHoldInstance(pic->p_sys, dpy) : NULL; + assert(holder.dec_device->type == VLC_DECODER_DEVICE_VAAPI); } vlc_mutex_unlock(&holder.lock); picture_Release(pic); - return va_inst; + return dec_device; } void vlc_vaapi_FilterReleaseInstance(filter_t *filter, - struct vlc_vaapi_instance *va_inst) + vlc_decoder_device *dec_device) { - vlc_vaapi_ReleaseInstance(va_inst); + vlc_decoder_device_Release(dec_device); vlc_mutex_lock(&holder.lock); if (filter == holder.owner) { - holder.inst = NULL; + holder.dec_device = NULL; holder.owner = NULL; } vlc_mutex_unlock(&holder.lock); @@ -101,7 +102,7 @@ vlc_vaapi_FilterReleaseInstance(filter_t *filter, struct va_filter_desc { - struct vlc_vaapi_instance *inst; + vlc_decoder_device *dec_device; VADisplay dpy; VAConfigID conf; VAContextID ctx; @@ -374,13 +375,13 @@ Open(filter_t * filter, filter_sys->va.conf = VA_INVALID_ID; filter_sys->va.ctx = VA_INVALID_ID; filter_sys->va.buf = VA_INVALID_ID; - filter_sys->va.inst = + filter_sys->va.dec_device = vlc_vaapi_FilterHoldInstance(filter, &filter_sys->va.dpy); - if (!filter_sys->va.inst) + if (!filter_sys->va.dec_device) goto error; filter_sys->dest_pics = - vlc_vaapi_PoolNew(VLC_OBJECT(filter), filter_sys->va.inst, + vlc_vaapi_PoolNew(VLC_OBJECT(filter), filter_sys->va.dec_device, filter_sys->va.dpy, DEST_PICS_POOL_SZ, &filter_sys->va.surface_ids, &filter->fmt_out.video, true); @@ -455,8 +456,8 @@ error: filter_sys->va.dpy, filter_sys->va.conf); if (filter_sys->dest_pics) picture_pool_Release(filter_sys->dest_pics); - if (filter_sys->va.inst) - vlc_vaapi_FilterReleaseInstance(filter, filter_sys->va.inst); + if (filter_sys->va.dec_device) + vlc_vaapi_FilterReleaseInstance(filter, filter_sys->va.dec_device); free(filter_sys); return VLC_EGENERIC; } @@ -469,7 +470,7 @@ Close(filter_t *filter, filter_sys_t * filter_sys) vlc_vaapi_DestroyBuffer(obj, filter_sys->va.dpy, filter_sys->va.buf); vlc_vaapi_DestroyContext(obj, filter_sys->va.dpy, filter_sys->va.ctx); vlc_vaapi_DestroyConfig(obj, filter_sys->va.dpy, filter_sys->va.conf); - vlc_vaapi_FilterReleaseInstance(filter, filter_sys->va.inst); + vlc_vaapi_FilterReleaseInstance(filter, filter_sys->va.dec_device); free(filter_sys); } diff --git a/modules/hw/vaapi/filters.h b/modules/hw/vaapi/filters.h index 2e739feb37..28133309b2 100644 --- a/modules/hw/vaapi/filters.h +++ b/modules/hw/vaapi/filters.h @@ -32,11 +32,11 @@ int vlc_vaapi_OpenChroma(vlc_object_t *obj); void vlc_vaapi_CloseChroma(vlc_object_t *obj); /* Get and hold the VADisplay instance from a filter */ -struct vlc_vaapi_instance * +vlc_decoder_device * vlc_vaapi_FilterHoldInstance(filter_t *filter, VADisplay *dpy); void vlc_vaapi_FilterReleaseInstance(filter_t *filter, - struct vlc_vaapi_instance *va_inst); + vlc_decoder_device *dec_device); #endif /* VLC_VAAPI_FILTERS_H */ diff --git a/modules/hw/vaapi/vlc_vaapi.c b/modules/hw/vaapi/vlc_vaapi.c index b6d6d4bd14..6fa00d0731 100644 --- a/modules/hw/vaapi/vlc_vaapi.c +++ b/modules/hw/vaapi/vlc_vaapi.c @@ -83,7 +83,6 @@ struct vlc_vaapi_instance { VADisplay dpy; VANativeDisplay native; vlc_vaapi_native_destroy_cb native_destroy_cb; - atomic_uint pic_refcount; }; struct vlc_vaapi_instance * @@ -100,7 +99,6 @@ vlc_vaapi_InitializeInstance(vlc_object_t *o, VADisplay dpy, inst->dpy = dpy; inst->native = native; inst->native_destroy_cb = native_destroy_cb; - atomic_init(&inst->pic_refcount, 1); return inst; error: @@ -167,24 +165,13 @@ vlc_vaapi_InitializeInstanceDRM(vlc_object_t *o, return NULL; } - -VADisplay -vlc_vaapi_HoldInstance(struct vlc_vaapi_instance *inst) -{ - atomic_fetch_add(&inst->pic_refcount, 1); - return inst->dpy; -} - void -vlc_vaapi_ReleaseInstance(struct vlc_vaapi_instance *inst) +vlc_vaapi_DestroyInstance(struct vlc_vaapi_instance *inst) { - if (atomic_fetch_sub(&inst->pic_refcount, 1) == 1) - { - vaTerminate(inst->dpy); - if (inst->native != NULL && inst->native_destroy_cb != NULL) - inst->native_destroy_cb(inst->native); - free(inst); - } + vaTerminate(inst->dpy); + if (inst->native != NULL && inst->native_destroy_cb != NULL) + inst->native_destroy_cb(inst->native); + free(inst); } /************************** @@ -539,7 +526,7 @@ struct pic_sys_vaapi_instance { atomic_int pic_refcount; VADisplay va_dpy; - struct vlc_vaapi_instance *va_inst; + vlc_decoder_device *dec_device; unsigned num_render_targets; VASurfaceID render_targets[]; }; @@ -560,7 +547,7 @@ pool_pic_destroy_cb(picture_t *pic) { vaDestroySurfaces(instance->va_dpy, instance->render_targets, instance->num_render_targets); - vlc_vaapi_ReleaseInstance(instance->va_inst); + vlc_decoder_device_Release(instance->dec_device); free(instance); } free(pic->p_sys); @@ -596,7 +583,7 @@ pic_sys_ctx_destroy_cb(struct picture_context_t *opaque) } picture_pool_t * -vlc_vaapi_PoolNew(vlc_object_t *o, struct vlc_vaapi_instance *va_inst, +vlc_vaapi_PoolNew(vlc_object_t *o, vlc_decoder_device *dec_device, VADisplay dpy, unsigned count, VASurfaceID **render_targets, const video_format_t *restrict fmt, bool b_force_fourcc) { @@ -665,8 +652,8 @@ vlc_vaapi_PoolNew(vlc_object_t *o, struct vlc_vaapi_instance *va_inst, goto error_pic; atomic_store(&instance->pic_refcount, count); - instance->va_dpy = vlc_vaapi_HoldInstance(va_inst); - instance->va_inst = va_inst; + instance->va_dpy = dpy; + instance->dec_device = vlc_decoder_device_Hold(dec_device); *render_targets = instance->render_targets; return pool; @@ -692,13 +679,13 @@ vlc_vaapi_PicSysGetRenderTargets(void *_sys, VASurfaceID **render_targets) return sys->instance->num_render_targets; } -struct vlc_vaapi_instance * +vlc_decoder_device * vlc_vaapi_PicSysHoldInstance(void *_sys, VADisplay *dpy) { picture_sys_t *sys = (picture_sys_t *)_sys; assert(sys->instance != NULL); - *dpy = vlc_vaapi_HoldInstance(sys->instance->va_inst); - return sys->instance->va_inst; + *dpy = sys->instance->va_dpy; + return vlc_decoder_device_Hold(sys->instance->dec_device); } #define ASSERT_VAAPI_CHROMA(pic) do { \ diff --git a/modules/hw/vaapi/vlc_vaapi.h b/modules/hw/vaapi/vlc_vaapi.h index 8f7ca3455e..a3f0169d9f 100644 --- a/modules/hw/vaapi/vlc_vaapi.h +++ b/modules/hw/vaapi/vlc_vaapi.h @@ -36,6 +36,7 @@ #endif #include <vlc_common.h> +#include <vlc_codec.h> #include <vlc_fourcc.h> #include <vlc_picture_pool.h> @@ -63,14 +64,9 @@ vlc_vaapi_InitializeInstanceDRM(vlc_object_t *o, VADisplay *pdpy, const char *device); -/* Increments the VAAPI instance refcount */ -VADisplay -vlc_vaapi_HoldInstance(struct vlc_vaapi_instance *inst); - -/* Decrements the VAAPI instance refcount, and call vaTerminate if that counter - * reaches 0 */ +/* Destroy the VAAPI instance refcount, and call vaTerminate */ void -vlc_vaapi_ReleaseInstance(struct vlc_vaapi_instance *inst); +vlc_vaapi_DestroyInstance(struct vlc_vaapi_instance *inst); /************************** * VAAPI create & destroy * @@ -194,7 +190,7 @@ vlc_vaapi_CreateConfigChecked(vlc_object_t *o, VADisplay dpy, /* Create a pool backed by VASurfaceID. render_targets will destroyed once * the pool and every pictures are released. */ picture_pool_t * -vlc_vaapi_PoolNew(vlc_object_t *o, struct vlc_vaapi_instance *vainst, +vlc_vaapi_PoolNew(vlc_object_t *o, vlc_decoder_device *dec_device, VADisplay dpy, unsigned count, VASurfaceID **render_targets, const video_format_t *restrict fmt, bool b_force_fourcc); @@ -204,7 +200,7 @@ unsigned vlc_vaapi_PicSysGetRenderTargets(void *sys, VASurfaceID **render_targets); /* Get and hold the VADisplay instance attached to the picture sys */ -struct vlc_vaapi_instance * +vlc_decoder_device * vlc_vaapi_PicSysHoldInstance(void *sys, VADisplay *dpy); /* Attachs the VASurface to the picture context, the picture must be allocated diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am index 84183f3f84..7d12466b32 100644 --- a/modules/video_output/Makefile.am +++ b/modules/video_output/Makefile.am @@ -77,22 +77,11 @@ libgl_plugin_la_CFLAGS += -DHAVE_GL_CORE_SYMBOLS libgl_plugin_la_LIBADD += $(GL_LIBS) endif -libglconv_vaapi_wl_plugin_la_SOURCES = video_output/opengl/converter_vaapi.c \ +libglconv_vaapi_plugin_la_SOURCES = video_output/opengl/converter_vaapi.c \ video_output/opengl/converter.h \ hw/vaapi/vlc_vaapi.c hw/vaapi/vlc_vaapi.h -libglconv_vaapi_wl_plugin_la_CFLAGS = $(AM_CFLAGS) $(GL_CFLAGS) -DHAVE_VA_WL $(LIBVA_WL_CFLAGS) -libglconv_vaapi_wl_plugin_la_LIBADD = $(LIBVA_LIBS) $(LIBVA_EGL_LIBS) \ - $(LIBVA_WL_LIBS) - -libglconv_vaapi_x11_plugin_la_SOURCES = $(libglconv_vaapi_wl_plugin_la_SOURCES) -libglconv_vaapi_x11_plugin_la_CFLAGS = $(AM_CFLAGS) -DHAVE_VA_X11 -libglconv_vaapi_x11_plugin_la_LIBADD = $(LIBVA_LIBS) $(LIBVA_EGL_LIBS) \ - $(LIBVA_X11_LIBS) $(X_LIBS) $(X_PRE_LIBS) -lX11 - -libglconv_vaapi_drm_plugin_la_SOURCES = $(libglconv_vaapi_wl_plugin_la_SOURCES) -libglconv_vaapi_drm_plugin_la_CFLAGS = $(AM_CFLAGS) -DHAVE_VA_DRM -libglconv_vaapi_drm_plugin_la_LIBADD = $(LIBVA_LIBS) $(LIBVA_EGL_LIBS) \ - $(LIBVA_DRM_LIBS) +libglconv_vaapi_plugin_la_CFLAGS = $(AM_CFLAGS) $(GL_CFLAGS) +libglconv_vaapi_plugin_la_LIBADD = $(LIBVA_LIBS) $(LIBVA_EGL_LIBS) libglconv_vdpau_plugin_la_SOURCES = video_output/opengl/converter_vdpau.c \ video_output/opengl/converter.h hw/vdpau/picture.c hw/vdpau/vlc_vdpau.h @@ -103,19 +92,7 @@ if HAVE_GL vout_LTLIBRARIES += libgl_plugin.la if HAVE_EGL if HAVE_VAAPI -if HAVE_WAYLAND -if HAVE_VAAPI_WL -vout_LTLIBRARIES += libglconv_vaapi_wl_plugin.la -endif -endif -if HAVE_XCB -if HAVE_VAAPI_X11 -vout_LTLIBRARIES += libglconv_vaapi_x11_plugin.la -endif -endif -if HAVE_VAAPI_DRM -vout_LTLIBRARIES += libglconv_vaapi_drm_plugin.la -endif +vout_LTLIBRARIES += libglconv_vaapi_plugin.la endif endif # HAVE_EGL diff --git a/modules/video_output/opengl/converter_vaapi.c b/modules/video_output/opengl/converter_vaapi.c index a2f8f34dd8..ba98298a4e 100644 --- a/modules/video_output/opengl/converter_vaapi.c +++ b/modules/video_output/opengl/converter_vaapi.c @@ -25,6 +25,7 @@ #include "converter.h" #include "../../hw/vaapi/vlc_vaapi.h" #include <vlc_vout_window.h> +#include <vlc_codec.h> #include <assert.h> @@ -32,24 +33,8 @@ #include <EGL/eglext.h> #include <va/va_drmcommon.h> -#ifdef HAVE_VA_WL -# include <va/va_wayland.h> -#endif - -#ifdef HAVE_VA_X11 -# include <va/va_x11.h> -# include <vlc_xlib.h> -#endif - -#ifdef HAVE_VA_DRM -# include <va/va_drm.h> -# include <vlc_fs.h> -# include <fcntl.h> -#endif - struct priv { - struct vlc_vaapi_instance *vainst; VADisplay vadpy; VASurfaceID *va_surface_ids; PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES; @@ -238,7 +223,7 @@ tc_vaegl_get_pool(const opengl_tex_converter_t *tc, unsigned requested_count) struct priv *priv = tc->priv; picture_pool_t *pool = - vlc_vaapi_PoolNew(VLC_OBJECT(tc->gl), priv->vainst, priv->vadpy, + vlc_vaapi_PoolNew(VLC_OBJECT(tc->gl), tc->dec_device, priv->vadpy, requested_count, &priv->va_surface_ids, &tc->fmt, true); if (!pool) @@ -301,8 +286,6 @@ Close(vlc_object_t *obj) if (priv->last.pic != NULL) vaegl_release_last_pic(tc, priv); - vlc_vaapi_ReleaseInstance(priv->vainst); - free(tc->priv); } @@ -340,68 +323,14 @@ tc_va_check_interop_blacklist(opengl_tex_converter_t *tc, VADisplay *vadpy) return VLC_SUCCESS; } -#ifdef HAVE_VA_X11 -static void -x11_native_destroy_cb(VANativeDisplay native) -{ - XCloseDisplay(native); -} - -static int -x11_init_vaapi_instance(opengl_tex_converter_t *tc, struct priv *priv) -{ - if (!vlc_xlib_init(VLC_OBJECT(tc->gl))) - return VLC_EGENERIC; - - Display *x11dpy = XOpenDisplay(tc->gl->surface->display.x11); - if (x11dpy == NULL) - return VLC_EGENERIC; - - priv->vadpy = vaGetDisplay(x11dpy); - if (priv->vadpy == NULL) - { - x11_native_destroy_cb(x11dpy); - return VLC_EGENERIC; - } - - priv->vainst = vlc_vaapi_InitializeInstance(VLC_OBJECT(tc->gl), priv->vadpy, - x11dpy, x11_native_destroy_cb); - return priv->vainst != NULL ? VLC_SUCCESS : VLC_EGENERIC; -} -#endif - -#ifdef HAVE_VA_DRM -static int -drm_init_vaapi_instance(opengl_tex_converter_t *tc, struct priv *priv) -{ - priv->vainst = - vlc_vaapi_InitializeInstanceDRM(VLC_OBJECT(tc->gl), vaGetDisplayDRM, - &priv->vadpy, NULL); - return priv->vainst != NULL ? VLC_SUCCESS : VLC_EGENERIC; -} -#endif - -#ifdef HAVE_VA_WL -static int -wl_init_vaapi_instance(opengl_tex_converter_t *tc, struct priv *priv) -{ - priv->vadpy = vaGetDisplayWl(tc->gl->surface->display.wl); - if (priv->vadpy == NULL) - return VLC_EGENERIC; - - priv->vainst = vlc_vaapi_InitializeInstance(VLC_OBJECT(tc->gl), priv->vadpy, - NULL, NULL); - return priv->vainst != NULL ? VLC_SUCCESS : VLC_EGENERIC; -} -#endif - - static int Open(vlc_object_t *obj) { opengl_tex_converter_t *tc = (void *) obj; - if (!vlc_vaapi_IsChromaOpaque(tc->fmt.i_chroma) + if (tc->dec_device == NULL + || tc->dec_device->type != VLC_DECODER_DEVICE_VAAPI + || !vlc_vaapi_IsChromaOpaque(tc->fmt.i_chroma) || tc->gl->ext != VLC_GL_EXT_EGL || tc->gl->egl.createImageKHR == NULL || tc->gl->egl.destroyImageKHR == NULL) @@ -418,7 +347,6 @@ Open(vlc_object_t *obj) if (unlikely(tc->priv == NULL)) goto error; priv->fourcc = 0; - priv->vainst = NULL; int va_fourcc; int vlc_sw_chroma; @@ -444,23 +372,8 @@ Open(vlc_object_t *obj) if (priv->glEGLImageTargetTexture2DOES == NULL) goto error; - int ret = VLC_EGENERIC; -#if defined (HAVE_VA_X11) - if (tc->gl->surface->type == VOUT_WINDOW_TYPE_XID) - ret = x11_init_vaapi_instance(tc, priv); -#elif defined(HAVE_VA_WL) - if (tc->gl->surface->type == VOUT_WINDOW_TYPE_WAYLAND) - ret = wl_init_vaapi_instance(tc, priv); -#elif defined (HAVE_VA_DRM) - ret = drm_init_vaapi_instance(tc, priv); -#else -# error need X11/WL/DRM support -#endif - - if (ret != VLC_SUCCESS) - goto error; - - assert(priv->vadpy != NULL && priv->vainst != NULL); + priv->vadpy = tc->dec_device->opaque; + assert(priv->vadpy != NULL); if (tc_va_check_interop_blacklist(tc, priv->vadpy)) goto error; @@ -475,31 +388,15 @@ Open(vlc_object_t *obj) return VLC_SUCCESS; error: - if (priv && priv->vainst) - vlc_vaapi_ReleaseInstance(priv->vainst); free(priv); return VLC_EGENERIC; } -#if defined (HAVE_VA_X11) -# define PRIORITY 2 -# define SHORTCUT "vaapi_x11" -# define DESCRIPTION_SUFFIX "X11" -#elif defined(HAVE_VA_WL) -# define PRIORITY 2 -# define SHORTCUT "vaapi_wl" -# define DESCRIPTION_SUFFIX "Wayland" -#elif defined (HAVE_VA_DRM) -# define PRIORITY 1 -# define SHORTCUT "vaapi_drm" -# define DESCRIPTION_SUFFIX "DRM" -#endif - vlc_module_begin () - set_description("VA-API OpenGL surface converter for " DESCRIPTION_SUFFIX) - set_capability("glconv", PRIORITY) + set_description("VA-API OpenGL surface converte") + set_capability("glconv", 1) set_callbacks(Open, Close) set_category(CAT_VIDEO) set_subcategory(SUBCAT_VIDEO_VOUT) - add_shortcut("vaapi", SHORTCUT) + add_shortcut("vaapi") vlc_module_end () _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
