<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div><br></div>
<div>On Sat, Jul 1, 2017, at 17:08, Rémi Denis-Courmont wrote:<br></div>
<blockquote type="cite"><div><div>Le 1 juillet 2017 11:22:26 GMT+02:00, "Hugo Beauzée-Luyssen" <hugo@beauzee.fr> a écrit :<br></div>
<blockquote style="margin-top:0pt;margin-right:0pt;margin-bottom:0pt;margin-left:0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204, 204, 204);padding-left:1ex;"><pre><div>---<br></div>
<div>
<br></div>
<div> modules/codec/avcodec/vaapi.c | 92 ++++++++++++++++++++------<br></div>
<div>
<br></div>
<div> modules/hw/vaapi/<a href="http://Makefile.am">Makefile.am</a> | 11 +---<br></div>
<div>
<br></div>
<div> modules/hw/vaapi/chroma.c | 13 ++--<br></div>
<div>
<br></div>
<div> modules/hw/vaapi/filters.c | 9 ++-<br></div>
<div>
<br></div>
<div> modules/hw/vaapi/instance.c | 93 ---------------------------<br></div>
<div>
<br></div>
<div> modules/hw/vaapi/vlc_vaapi.c | 8 ++-<br></div>
<div>
<br></div>
<div> modules/hw/vaapi/vlc_vaapi.h | 18 ++----<br></div>
<div>
<br></div>
<div> modules/video_output/opengl/converter_vaapi.c | 87 +++++++++++++++++--------<br></div>
<div>
<br></div>
<div> 8 files changed, 161 insertions(+), 170 deletions(-)<br></div>
<div>
<br></div>
<div> delete mode 100644 modules/hw/vaapi/instance.c<br></div>
<div>
<br></div>
<div><br></div>
<div>
<br></div>
<div>diff --git a/modules/codec/avcodec/vaapi.c b/modules/codec/avcodec/vaapi.c<br></div>
<div>
<br></div>
<div>index 4f46802400..f9ae5edff4 100644<br></div>
<div>
<br></div>
<div>--- a/modules/codec/avcodec/vaapi.c<br></div>
<div>
<br></div>
<div>+++ b/modules/codec/avcodec/vaapi.c<br></div>
<div>
<br></div>
<div>@@ -33,6 +33,7 @@<br></div>
<div>
<br></div>
<div> #include <vlc_fourcc.h><br></div>
<div>
<br></div>
<div> #include <vlc_picture.h><br></div>
<div>
<br></div>
<div> #include <vlc_picture_pool.h><br></div>
<div>
<br></div>
<div>+#include <vlc_instance_holder.h><br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> #ifdef VLC_VA_BACKEND_XLIB<br></div>
<div>
<br></div>
<div> # include <vlc_xlib.h><br></div>
<div>
<br></div>
<div>@@ -67,6 +68,12 @@ struct vlc_va_sys_t<br></div>
<div>
<br></div>
<div> #endif<br></div>
<div>
<br></div>
<div> };<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>+typedef struct vlc_va_instance_ctx<br></div>
<div>
<br></div>
<div>+{<br></div>
<div>
<br></div>
<div>+ vlc_object_t* p_obj;<br></div>
<div>
<br></div>
<div>+ vlc_va_sys_t* p_sys;<br></div>
<div>
<br></div>
<div>+} vlc_va_instance_ctx;<br></div>
<div>
<br></div>
<div>+<br></div>
<div>
<br></div>
<div> static int GetVaProfile(AVCodecContext *ctx, VAProfile *va_profile,<br></div>
<div>
<br></div>
<div> unsigned *pic_count)<br></div>
<div>
<br></div>
<div> {<br></div>
<div>
<br></div>
<div>@@ -147,7 +154,7 @@ static void DeleteDR(vlc_va_t *va, void *hwctx)<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> vlc_vaapi_DestroyContext(o, sys->hw_ctx.display, sys->hw_ctx.context_id);<br></div>
<div>
<br></div>
<div> vlc_vaapi_DestroyConfig(o, sys->hw_ctx.display, sys->hw_ctx.config_id);<br></div>
<div>
<br></div>
<div>- vlc_vaapi_ReleaseInstance(sys->hw_ctx.display);<br></div>
<div>
<br></div>
<div>+ vlc_instance_holder_release( VLC_OBJECT( va ), "vaapi-instance" );<br></div>
<div>
<br></div>
<div> free(sys);<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>@@ -164,7 +171,8 @@ static int CreateDR(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,<br></div>
<div>
<br></div>
<div> vlc_va_sys_t *sys = NULL;<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> /* The picture must be allocated by the vout */<br></div>
<div>
<br></div>
<div>- VADisplay *va_dpy = vlc_vaapi_GetInstance();<br></div>
<div>
<br></div>
<div>+ VADisplay *va_dpy = vlc_instance_holder_get( VLC_OBJECT( va ),<br></div>
<div>
<br></div>
<div>+ "vaapi-instance" );<br></div>
<div>
<br></div>
<div> if (va_dpy == NULL)<br></div>
<div>
<br></div>
<div> return VLC_EGENERIC;<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>@@ -221,7 +229,7 @@ error:<br></div>
<div>
<br></div>
<div> vlc_vaapi_DestroyConfig(o, sys->hw_ctx.display, sys->hw_ctx.config_id);<br></div>
<div>
<br></div>
<div> free(sys);<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div>- vlc_vaapi_ReleaseInstance(va_dpy);<br></div>
<div>
<br></div>
<div>+ vlc_instance_holder_release( VLC_OBJECT( va ), "vaapi-instance" );<br></div>
<div>
<br></div>
<div> return ret;<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>@@ -254,7 +262,7 @@ static void Delete(vlc_va_t *va, void **hwctx)<br></div>
<div>
<br></div>
<div> picture_pool_Release(sys->pool);<br></div>
<div>
<br></div>
<div> vlc_vaapi_DestroyContext(o, sys->hw_ctx.display, sys->hw_ctx.context_id);<br></div>
<div>
<br></div>
<div> vlc_vaapi_DestroyConfig(o, sys->hw_ctx.display, sys->hw_ctx.config_id);<br></div>
<div>
<br></div>
<div>- vlc_vaapi_ReleaseInstance(sys->hw_ctx.display);<br></div>
<div>
<br></div>
<div>+ vlc_instance_holder_release( VLC_OBJECT( va ), "vaapi-instance" );<br></div>
<div>
<br></div>
<div> #ifdef VLC_VA_BACKEND_XLIB<br></div>
<div>
<br></div>
<div> XCloseDisplay(sys->p_display_x11);<br></div>
<div>
<br></div>
<div> #endif<br></div>
<div>
<br></div>
<div>@@ -264,6 +272,49 @@ static void Delete(vlc_va_t *va, void **hwctx)<br></div>
<div>
<br></div>
<div> free(sys);<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>+static void* CreateVaDisplayInstance( VADisplay* p_display,<br></div>
<div>
<br></div>
<div>+ vlc_va_instance_ctx* p_ctx )<br></div>
<div>
<br></div>
<div>+{<br></div>
<div>
<br></div>
<div>+ if (p_display == NULL)<br></div>
<div>
<br></div>
<div>+ {<br></div>
<div>
<br></div>
<div>+ msg_Err(p_ctx->p_obj, "Could not get a VAAPI device");<br></div>
<div>
<br></div>
<div>+ return NULL;<br></div>
<div>
<br></div>
<div>+ }<br></div>
<div>
<br></div>
<div>+<br></div>
<div>
<br></div>
<div>+ if (vlc_vaapi_Initialize(p_ctx->p_obj, p_display))<br></div>
<div>
<br></div>
<div>+ {<br></div>
<div>
<br></div>
<div>+ msg_Err(p_ctx->p_obj, "Could not initialize VA display" );<br></div>
<div>
<br></div>
<div>+ vaTerminate( p_display );<br></div>
<div>
<br></div>
<div>+ return NULL;<br></div>
<div>
<br></div>
<div>+ }<br></div>
<div>
<br></div>
<div>+ return p_display;<br></div>
<div>
<br></div>
<div>+}<br></div>
<div>
<br></div>
<div>+<br></div>
<div>
<br></div>
<div>+#ifdef VLC_VA_BACKEND_XLIB<br></div>
<div>
<br></div>
<div>+static void* CreateVaDisplayInstanceX11( void* p_opaque )<br></div>
<div>
<br></div>
<div>+{<br></div>
<div>
<br></div>
<div>+ vlc_va_instance_ctx* p_ctx = (vlc_va_instance_ctx*)p_opaque;<br></div>
<div>
<br></div>
<div>+ return CreateVaDisplayInstance( vaGetDisplay( p_ctx->p_sys->p_display_x11),<br></div>
<div>
<br></div>
<div>+ p_ctx );<br></div>
<div>
<br></div>
<div>+}<br></div>
<div>
<br></div>
<div>+#endif<br></div>
<div>
<br></div>
<div>+<br></div>
<div>
<br></div>
<div>+#ifdef VLC_VA_BACKEND_DRM<br></div>
<div>
<br></div>
<div>+static void* CreateVaDisplayInstanceDRM( void* p_opaque )<br></div>
<div>
<br></div>
<div>+{<br></div>
<div>
<br></div>
<div>+ vlc_va_instance_ctx* p_ctx = (vlc_va_instance_ctx*)p_opaque;<br></div>
<div>
<br></div>
<div>+ return CreateVaDisplayInstance( vaGetDisplayDRM(p_ctx->p_sys->drm_fd ),<br></div>
<div>
<br></div>
<div>+ p_ctx );<br></div>
<div>
<br></div>
<div>+}<br></div>
<div>
<br></div>
<div>+#endif<br></div>
<div>
<br></div>
<div>+<br></div>
<div>
<br></div>
<div>+<br></div>
<div>
<br></div>
<div>+static void DestroyVaDisplayInstance( void* p_instance, void* p_ctx )<br></div>
<div>
<br></div>
<div>+{<br></div>
<div>
<br></div>
<div>+ vaTerminate( (VADisplay)p_instance );<br></div>
<div>
<br></div>
<div>+ free( p_ctx );<br></div>
<div>
<br></div>
<div>+}<br></div>
<div>
<br></div>
<div>+<br></div>
<div>
<br></div>
<div> static int Create(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,<br></div>
<div>
<br></div>
<div> const es_format_t *fmt, picture_sys_t *p_sys)<br></div>
<div>
<br></div>
<div> {<br></div>
<div>
<br></div>
<div>@@ -300,6 +351,15 @@ static int Create(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,<br></div>
<div>
<br></div>
<div> sys->hw_ctx.context_id = VA_INVALID_ID;<br></div>
<div>
<br></div>
<div> sys->pool = NULL;<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>+ vlc_va_instance_ctx* p_ctx = malloc( sizeof( *p_ctx ) );<br></div>
<div>
<br></div>
<div>+ if ( unlikely( p_ctx == NULL ) )<br></div>
<div>
<br></div>
<div>+ {<br></div>
<div>
<br></div>
<div>+ free( sys );<br></div>
<div>
<br></div>
<div>+ return VLC_ENOMEM;<br></div>
<div>
<br></div>
<div>+ }<br></div>
<div>
<br></div>
<div>+ p_ctx->p_obj = VLC_OBJECT( va );<br></div>
<div>
<br></div>
<div>+ p_ctx->p_sys = sys;<br></div>
<div>
<br></div>
<div>+<br></div>
<div>
<br></div>
<div> /* Create a VA display */<br></div>
<div>
<br></div>
<div> #ifdef VLC_VA_BACKEND_XLIB<br></div>
<div>
<br></div>
<div> sys->p_display_x11 = XOpenDisplay(NULL);<br></div>
<div>
<br></div>
<div>@@ -309,7 +369,9 @@ static int Create(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,<br></div>
<div>
<br></div>
<div> goto error;<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>- sys->hw_ctx.display = vaGetDisplay(sys->p_display_x11);<br></div>
<div>
<br></div>
<div>+ sys->hw_ctx.display = vlc_instance_holder_acquire(<br></div>
<div>
<br></div>
<div>+ VLC_OBJECT( va ), "vaapi-instance", &CreateVaDisplayInstanceX11,<br></div>
<div>
<br></div>
<div>+ &DestroyVaDisplayInstance, p_ctx );<br></div>
<div>
<br></div>
<div> #endif<br></div>
<div>
<br></div>
<div> #ifdef VLC_VA_BACKEND_DRM<br></div>
<div>
<br></div>
<div> static const char drm_device_paths[][20] = {<br></div>
<div>
<br></div>
<div>@@ -323,7 +385,9 @@ static int Create(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,<br></div>
<div>
<br></div>
<div> if (sys->drm_fd < 0)<br></div>
<div>
<br></div>
<div> continue;<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>- sys->hw_ctx.display = vaGetDisplayDRM(sys->drm_fd);<br></div>
<div>
<br></div>
<div>+ sys->hw_ctx.display = vlc_instance_holder_acquire(<br></div>
<div>
<br></div>
<div>+ VLC_OBJECT( va ),"vaapi-instance", &CreateVaDisplayInstanceDRM,<br></div>
<div>
<br></div>
<div>+ &DestroyVaDisplayInstance, p_ctx );<br></div>
<div>
<br></div>
<div> if (sys->hw_ctx.display)<br></div>
<div>
<br></div>
<div> break;<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>@@ -337,19 +401,6 @@ static int Create(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,<br></div>
<div>
<br></div>
<div> goto error;<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>- if (vlc_vaapi_Initialize(o, sys->hw_ctx.display))<br></div>
<div>
<br></div>
<div>- {<br></div>
<div>
<br></div>
<div>- sys->hw_ctx.display = NULL;<br></div>
<div>
<br></div>
<div>- goto error;<br></div>
<div>
<br></div>
<div>- }<br></div>
<div>
<br></div>
<div>-<br></div>
<div>
<br></div>
<div>- if (vlc_vaapi_SetInstance(sys->hw_ctx.display))<br></div>
<div>
<br></div>
<div>- {<br></div>
<div>
<br></div>
<div>- msg_Err(va, "VAAPI instance already in use");<br></div>
<div>
<br></div>
<div>- sys->hw_ctx.display = NULL;<br></div>
<div>
<br></div>
<div>- goto error;<br></div>
<div>
<br></div>
<div>- }<br></div>
<div>
<br></div>
<div>-<br></div>
<div>
<br></div>
<div> sys->hw_ctx.config_id =<br></div>
<div>
<br></div>
<div> vlc_vaapi_CreateConfigChecked(o, sys->hw_ctx.display, i_profile,<br></div>
<div>
<br></div>
<div> VAEntrypointVLD, 0);<br></div>
<div>
<br></div>
<div>@@ -392,7 +443,8 @@ error:<br></div>
<div>
<br></div>
<div> if (sys->hw_ctx.config_id != VA_INVALID_ID)<br></div>
<div>
<br></div>
<div> vlc_vaapi_DestroyConfig(o, sys->hw_ctx.display, sys->hw_ctx.config_id);<br></div>
<div>
<br></div>
<div> if (sys->hw_ctx.display != NULL)<br></div>
<div>
<br></div>
<div>- vlc_vaapi_ReleaseInstance(sys->hw_ctx.display);<br></div>
<div>
<br></div>
<div>+ vlc_instance_holder_release( VLC_OBJECT( va ),<br></div>
<div>
<br></div>
<div>+ "vaapi-instance" );<br></div>
<div>
<br></div>
<div> #ifdef VLC_VA_BACKEND_XLIB<br></div>
<div>
<br></div>
<div> if( sys->p_display_x11 != NULL)<br></div>
<div>
<br></div>
<div> XCloseDisplay(sys->p_display_x11);<br></div>
<div>
<br></div>
<div>diff --git a/modules/hw/vaapi/<a href="http://Makefile.am">Makefile.am</a> b/modules/hw/vaapi/<a href="http://Makefile.am">Makefile.am</a><br></div>
<div>
<br></div>
<div>index d0e595e7c6..563bad2844 100644<br></div>
<div>
<br></div>
<div>--- a/modules/hw/vaapi/<a href="http://Makefile.am">Makefile.am</a><br></div>
<div>
<br></div>
<div>+++ b/modules/hw/vaapi/<a href="http://Makefile.am">Makefile.am</a><br></div>
<div>
<br></div>
<div>@@ -1,23 +1,16 @@<br></div>
<div>
<br></div>
<div> vaapidir = $(pluginsdir)/vaapi<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>-libvlc_vaapi_instance_la_SOURCES = hw/vaapi/instance.c hw/vaapi/vlc_vaapi.h<br></div>
<div>
<br></div>
<div>-libvlc_vaapi_instance_la_CFLAGS = $(LIBVA_CFLAGS)<br></div>
<div>
<br></div>
<div>-libvlc_vaapi_instance_la_LIBADD = $(LIBVA_LIBS) $(LIBPTHREAD)<br></div>
<div>
<br></div>
<div>-libvlc_vaapi_instance_la_LDFLAGS = -no-undefined \<br></div>
<div>
<br></div>
<div>- -version-info 0:0:0<br></div>
<div>
<br></div>
<div>-<br></div>
<div>
<br></div>
<div> libvaapi_chroma_plugin_la_SOURCES = hw/vaapi/chroma.c hw/vaapi/vlc_vaapi.c hw/vaapi/vlc_vaapi.h \<br></div>
<div>
<br></div>
<div> video_chroma/copy.c video_chroma/copy.h<br></div>
<div>
<br></div>
<div> libvaapi_chroma_plugin_la_CFLAGS = $(AM_CFLAGS) $(LIBVA_CFLAGS)<br></div>
<div>
<br></div>
<div>-libvaapi_chroma_plugin_la_LIBADD = $(AM_LIBADD) $(LIBVA_LIBS) libvlc_vaapi_<a href="http://instance.la">instance.la</a><br></div>
<div>
<br></div>
<div>+libvaapi_chroma_plugin_la_LIBADD = $(AM_LIBADD) $(LIBVA_LIBS)<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> libvaapi_filters_plugin_la_SOURCES = hw/vaapi/filters.c hw/vaapi/vlc_vaapi.c hw/vaapi/vlc_vaapi.h<br></div>
<div>
<br></div>
<div> libvaapi_filters_plugin_la_CPPFLAGS = $(AM_CPPFLAGS)<br></div>
<div>
<br></div>
<div> libvaapi_filters_plugin_la_CFLAGS = $(AM_CFLAGS) $(LIBVA_CFLAGS)<br></div>
<div>
<br></div>
<div>-libvaapi_filters_plugin_la_LIBADD = $(AM_LIBADD) $(LIBVA_LIBS) libvlc_vaapi_<a href="http://instance.la">instance.la</a><br></div>
<div>
<br></div>
<div>+libvaapi_filters_plugin_la_LIBADD = $(AM_LIBADD) $(LIBVA_LIBS)<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> if HAVE_VAAPI<br></div>
<div>
<br></div>
<div>-pkglib_LTLIBRARIES += libvlc_vaapi_<a href="http://instance.la">instance.la</a><br></div>
<div>
<br></div>
<div> vaapi_LTLIBRARIES = libvaapi_chroma_<a href="http://plugin.la">plugin.la</a> \<br></div>
<div>
<br></div>
<div> libvaapi_filters_<a href="http://plugin.la">plugin.la</a><br></div>
<div>
<br></div>
<div> endif<br></div>
<div>
<br></div>
<div>diff --git a/modules/hw/vaapi/chroma.c b/modules/hw/vaapi/chroma.c<br></div>
<div>
<br></div>
<div>index 278ecf9e17..f952325c4a 100644<br></div>
<div>
<br></div>
<div>--- a/modules/hw/vaapi/chroma.c<br></div>
<div>
<br></div>
<div>+++ b/modules/hw/vaapi/chroma.c<br></div>
<div>
<br></div>
<div>@@ -31,6 +31,7 @@<br></div>
<div>
<br></div>
<div> #include <vlc_common.h><br></div>
<div>
<br></div>
<div> #include <vlc_filter.h><br></div>
<div>
<br></div>
<div> #include <vlc_plugin.h><br></div>
<div>
<br></div>
<div>+#include <vlc_instance_holder.h><br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> #include "../../video_chroma/copy.h"<br></div>
<div>
<br></div>
<div> #include "vlc_vaapi.h"<br></div>
<div>
<br></div>
<div>@@ -134,7 +135,8 @@ DownloadSurface(filter_t *filter, picture_t *src_pic)<br></div>
<div>
<br></div>
<div> {<br></div>
<div>
<br></div>
<div> /* Get the instance here since the instance may be not created by the<br></div>
<div>
<br></div>
<div> * decoder from Open() */<br></div>
<div>
<br></div>
<div>- va_dpy = filter_sys->dpy = vlc_vaapi_GetInstance();<br></div>
<div>
<br></div>
<div>+ va_dpy = filter_sys->dpy = vlc_instance_holder_get(<br></div>
<div>
<br></div>
<div>+ VLC_OBJECT( filter ), "vaapi-instance" );<br></div>
<div>
<br></div>
<div> assert(filter_sys->dpy);<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div> else<br></div>
<div>
<br></div>
<div>@@ -313,7 +315,7 @@ static int Open(vlc_object_t *obj)<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> if (is_upload)<br></div>
<div>
<br></div>
<div> {<br></div>
<div>
<br></div>
<div>- filter_sys->dpy = vlc_vaapi_GetInstance();<br></div>
<div>
<br></div>
<div>+ filter_sys->dpy = vlc_instance_holder_get( obj, "vaapi-instance" );<br></div>
<div>
<br></div>
<div> if (filter_sys->dpy == NULL)<br></div>
<div>
<br></div>
<div> {<br></div>
<div>
<br></div>
<div> free(filter_sys);<br></div>
<div>
<br></div>
<div>@@ -327,7 +329,7 @@ static int Open(vlc_object_t *obj)<br></div>
<div>
<br></div>
<div> VA_FOURCC_NV12);<br></div>
<div>
<br></div>
<div> if (!filter_sys->dest_pics)<br></div>
<div>
<br></div>
<div> {<br></div>
<div>
<br></div>
<div>- vlc_vaapi_ReleaseInstance(filter_sys->dpy);<br></div>
<div>
<br></div>
<div>+ vlc_instance_holder_release( obj, "vaapi-instance" );<br></div>
<div>
<br></div>
<div> free(filter_sys);<br></div>
<div>
<br></div>
<div> return VLC_EGENERIC;<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div>@@ -344,7 +346,8 @@ static int Open(vlc_object_t *obj)<br></div>
<div>
<br></div>
<div> if (is_upload)<br></div>
<div>
<br></div>
<div> {<br></div>
<div>
<br></div>
<div> picture_pool_Release(filter_sys->dest_pics);<br></div>
<div>
<br></div>
<div>- vlc_vaapi_ReleaseInstance(filter_sys->dpy);<br></div>
<div>
<br></div>
<div>+ vlc_instance_holder_release( VLC_OBJECT( filter ),<br></div>
<div>
<br></div>
<div>+ "vaapi-instance" );<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div> free(filter_sys);<br></div>
<div>
<br></div>
<div> return VLC_EGENERIC;<br></div>
<div>
<br></div>
<div>@@ -366,7 +369,7 @@ Close(vlc_object_t *obj)<br></div>
<div>
<br></div>
<div> if (filter_sys->dest_pics)<br></div>
<div>
<br></div>
<div> picture_pool_Release(filter_sys->dest_pics);<br></div>
<div>
<br></div>
<div> if (filter_sys->dpy != NULL)<br></div>
<div>
<br></div>
<div>- vlc_vaapi_ReleaseInstance(filter_sys->dpy);<br></div>
<div>
<br></div>
<div>+ vlc_instance_holder_release( obj, "vaapi-instance" );<br></div>
<div>
<br></div>
<div> CopyCleanCache(&filter_sys->cache);<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> free(filter_sys);<br></div>
<div>
<br></div>
<div>diff --git a/modules/hw/vaapi/filters.c b/modules/hw/vaapi/filters.c<br></div>
<div>
<br></div>
<div>index 0af9c0548b..f778d155ed 100644<br></div>
<div>
<br></div>
<div>--- a/modules/hw/vaapi/filters.c<br></div>
<div>
<br></div>
<div>+++ b/modules/hw/vaapi/filters.c<br></div>
<div>
<br></div>
<div>@@ -31,6 +31,7 @@<br></div>
<div>
<br></div>
<div> #include <vlc_filter.h><br></div>
<div>
<br></div>
<div> #include <vlc_plugin.h><br></div>
<div>
<br></div>
<div> #include "vlc_vaapi.h"<br></div>
<div>
<br></div>
<div>+#include <vlc_instance_holder.h><br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> /********************************<br></div>
<div>
<br></div>
<div> * Common structures and macros *<br></div>
<div>
<br></div>
<div>@@ -298,7 +299,8 @@ Open(filter_t * filter,<br></div>
<div>
<br></div>
<div> filter_sys->va.conf = VA_INVALID_ID;<br></div>
<div>
<br></div>
<div> filter_sys->va.ctx = VA_INVALID_ID;<br></div>
<div>
<br></div>
<div> filter_sys->va.buf = VA_INVALID_ID;<br></div>
<div>
<br></div>
<div>- filter_sys->va.dpy = vlc_vaapi_GetInstance();<br></div>
<div>
<br></div>
<div>+ filter_sys->va.dpy = vlc_instance_holder_get( VLC_OBJECT( filter ),<br></div>
<div>
<br></div>
<div>+ "vaapi-instance" );<br></div>
<div>
<br></div>
<div> if (!filter_sys->va.dpy)<br></div>
<div>
<br></div>
<div> goto error;<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>@@ -377,7 +379,8 @@ error:<br></div>
<div>
<br></div>
<div> vlc_vaapi_DestroyConfig(VLC_OBJECT(filter),<br></div>
<div>
<br></div>
<div> filter_sys->va.dpy, filter_sys->va.conf);<br></div>
<div>
<br></div>
<div> if (filter_sys->va.dpy)<br></div>
<div>
<br></div>
<div>- vlc_vaapi_ReleaseInstance(filter_sys->va.dpy);<br></div>
<div>
<br></div>
<div>+ vlc_instance_holder_release( VLC_OBJECT( filter ),<br></div>
<div>
<br></div>
<div>+ "vaapi-instance" );<br></div>
<div>
<br></div>
<div> free(filter_sys);<br></div>
<div>
<br></div>
<div> return VLC_EGENERIC;<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div>@@ -389,7 +392,7 @@ Close(vlc_object_t * obj, filter_sys_t * filter_sys)<br></div>
<div>
<br></div>
<div> vlc_vaapi_DestroyBuffer(obj, filter_sys->va.dpy, filter_sys->va.buf);<br></div>
<div>
<br></div>
<div> vlc_vaapi_DestroyContext(obj, filter_sys->va.dpy, filter_sys->va.ctx);<br></div>
<div>
<br></div>
<div> vlc_vaapi_DestroyConfig(obj, filter_sys->va.dpy, filter_sys->va.conf);<br></div>
<div>
<br></div>
<div>- vlc_vaapi_ReleaseInstance(filter_sys->va.dpy);<br></div>
<div>
<br></div>
<div>+ vlc_instance_holder_release( obj, "vaapi-instance" );<br></div>
<div>
<br></div>
<div> free(filter_sys);<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>diff --git a/modules/hw/vaapi/instance.c b/modules/hw/vaapi/instance.c<br></div>
<div>
<br></div>
<div>deleted file mode 100644<br></div>
<div>
<br></div>
<div>index 3f70fe7ebc..0000000000<br></div>
<div>
<br></div>
<div>--- a/modules/hw/vaapi/instance.c<br></div>
<div>
<br></div>
<div>+++ /dev/null<br></div>
<div>
<br></div>
<div>@@ -1,93 +0,0 @@<br></div>
<div>
<br></div>
<div>-/*****************************************************************************<br></div>
<div>
<br></div>
<div>- * instance.c: VAAPI instance management for VLC<br></div>
<div>
<br></div>
<div>- *****************************************************************************<br></div>
<div>
<br></div>
<div>- * Copyright (C) 2017 VLC authors, VideoLAN and VideoLabs<br></div>
<div>
<br></div>
<div>- *<br></div>
<div>
<br></div>
<div>- * Author: Victorien Le Couviour--Tuffet <victorien.lecouviour.tuffet@gmail.com><br></div>
<div>
<br></div>
<div>- *<br></div>
<div>
<br></div>
<div>- * This program is free software; you can redistribute it and/or modify it<br></div>
<div>
<br></div>
<div>- * under the terms of the GNU Lesser General Public License as published by<br></div>
<div>
<br></div>
<div>- * the Free Software Foundation; either version 2.1 of the License, or<br></div>
<div>
<br></div>
<div>- * (at your option) any later version.<br></div>
<div>
<br></div>
<div>- *<br></div>
<div>
<br></div>
<div>- * This program is distributed in the hope that it will be useful,<br></div>
<div>
<br></div>
<div>- * but WITHOUT ANY WARRANTY; without even the implied warranty of<br></div>
<div>
<br></div>
<div>- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br></div>
<div>
<br></div>
<div>- * GNU Lesser General Public License for more details.<br></div>
<div>
<br></div>
<div>- *<br></div>
<div>
<br></div>
<div>- * You should have received a copy of the GNU Lesser General Public License<br></div>
<div>
<br></div>
<div>- * along with this program; if not, write to the Free Software Foundation,<br></div>
<div>
<br></div>
<div>- * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.<br></div>
<div>
<br></div>
<div>- *****************************************************************************/<br></div>
<div>
<br></div>
<div>-<br></div>
<div>
<br></div>
<div>-#ifdef HAVE_CONFIG_H<br></div>
<div>
<br></div>
<div>-# include "config.h"<br></div>
<div>
<br></div>
<div>-#endif<br></div>
<div>
<br></div>
<div>-<br></div>
<div>
<br></div>
<div>-#include <assert.h><br></div>
<div>
<br></div>
<div>-#include <pthread.h><br></div>
<div>
<br></div>
<div>-#include <stdlib.h><br></div>
<div>
<br></div>
<div>-#include <vlc_common.h><br></div>
<div>
<br></div>
<div>-#include "vlc_vaapi.h"<br></div>
<div>
<br></div>
<div>-<br></div>
<div>
<br></div>
<div>-#pragma GCC visibility push(default)<br></div>
<div>
<br></div>
<div>-<br></div>
<div>
<br></div>
<div>-static struct<br></div>
<div>
<br></div>
<div>-{<br></div>
<div>
<br></div>
<div>- pthread_mutex_t lock;<br></div>
<div>
<br></div>
<div>- VADisplay dpy;<br></div>
<div>
<br></div>
<div>- unsigned refcount;<br></div>
<div>
<br></div>
<div>-} va_instance = { PTHREAD_MUTEX_INITIALIZER, NULL, 0 };<br></div>
<div>
<br></div>
<div>-<br></div>
<div>
<br></div>
<div>-/* Set the VA instance and sets the reference counter to 1. */<br></div>
<div>
<br></div>
<div>-int<br></div>
<div>
<br></div>
<div>-vlc_vaapi_SetInstance(VADisplay dpy)<br></div>
<div>
<br></div>
<div>-{<br></div>
<div>
<br></div>
<div>- pthread_mutex_lock(&va_instance.lock);<br></div>
<div>
<br></div>
<div>- if (va_instance.refcount != 0)<br></div>
<div>
<br></div>
<div>- {<br></div>
<div>
<br></div>
<div>- vaTerminate(dpy);<br></div>
<div>
<br></div>
<div>- pthread_mutex_unlock(&va_instance.lock);<br></div>
<div>
<br></div>
<div>- return VLC_EGENERIC;<br></div>
<div>
<br></div>
<div>- }<br></div>
<div>
<br></div>
<div>- va_instance.refcount = 1;<br></div>
<div>
<br></div>
<div>- va_instance.dpy = dpy;<br></div>
<div>
<br></div>
<div>- pthread_mutex_unlock(&va_instance.lock);<br></div>
<div>
<br></div>
<div>- return VLC_SUCCESS;<br></div>
<div>
<br></div>
<div>-}<br></div>
<div>
<br></div>
<div>-<br></div>
<div>
<br></div>
<div>-/* Retrieve the VA instance and increases the reference counter by 1. */<br></div>
<div>
<br></div>
<div>-VADisplay<br></div>
<div>
<br></div>
<div>-vlc_vaapi_GetInstance(void)<br></div>
<div>
<br></div>
<div>-{<br></div>
<div>
<br></div>
<div>- VADisplay dpy;<br></div>
<div>
<br></div>
<div>- pthread_mutex_lock(&va_instance.lock);<br></div>
<div>
<br></div>
<div>- if (!va_instance.dpy)<br></div>
<div>
<br></div>
<div>- dpy = NULL;<br></div>
<div>
<br></div>
<div>- else<br></div>
<div>
<br></div>
<div>- {<br></div>
<div>
<br></div>
<div>- dpy = va_instance.dpy;<br></div>
<div>
<br></div>
<div>- ++va_instance.refcount;<br></div>
<div>
<br></div>
<div>- }<br></div>
<div>
<br></div>
<div>- pthread_mutex_unlock(&va_instance.lock);<br></div>
<div>
<br></div>
<div>- return dpy;<br></div>
<div>
<br></div>
<div>-}<br></div>
<div>
<br></div>
<div>-<br></div>
<div>
<br></div>
<div>-/* Decreases the reference counter by 1 and frees the instance if that counter<br></div>
<div>
<br></div>
<div>- reaches 0. */<br></div>
<div>
<br></div>
<div>-void<br></div>
<div>
<br></div>
<div>-vlc_vaapi_ReleaseInstance(VADisplay *dpy)<br></div>
<div>
<br></div>
<div>-{<br></div>
<div>
<br></div>
<div>- assert(va_instance.dpy == dpy && va_instance.refcount > 0);<br></div>
<div>
<br></div>
<div>- (void) dpy;<br></div>
<div>
<br></div>
<div>-<br></div>
<div>
<br></div>
<div>- pthread_mutex_lock(&va_instance.lock);<br></div>
<div>
<br></div>
<div>- if (--va_instance.refcount == 0)<br></div>
<div>
<br></div>
<div>- {<br></div>
<div>
<br></div>
<div>- vaTerminate(va_instance.dpy);<br></div>
<div>
<br></div>
<div>- va_instance.dpy = NULL;<br></div>
<div>
<br></div>
<div>- }<br></div>
<div>
<br></div>
<div>- pthread_mutex_unlock(&va_instance.lock);<br></div>
<div>
<br></div>
<div>-}<br></div>
<div>
<br></div>
<div>-<br></div>
<div>
<br></div>
<div>-#pragma GCC visibility pop<br></div>
<div>
<br></div>
<div>diff --git a/modules/hw/vaapi/vlc_vaapi.c b/modules/hw/vaapi/vlc_vaapi.c<br></div>
<div>
<br></div>
<div>index 04514eb852..28f4e6a58f 100644<br></div>
<div>
<br></div>
<div>--- a/modules/hw/vaapi/vlc_vaapi.c<br></div>
<div>
<br></div>
<div>+++ b/modules/hw/vaapi/vlc_vaapi.c<br></div>
<div>
<br></div>
<div>@@ -39,6 +39,7 @@<br></div>
<div>
<br></div>
<div> #include <vlc_atomic.h><br></div>
<div>
<br></div>
<div> #include <vlc_fourcc.h><br></div>
<div>
<br></div>
<div> #include <vlc_picture_pool.h><br></div>
<div>
<br></div>
<div>+#include <vlc_instance_holder.h><br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> /* This macro is designed to wrap any VA call, and in case of failure,<br></div>
<div>
<br></div>
<div> display the VA error string then goto the 'error' label (which you must<br></div>
<div>
<br></div>
<div>@@ -422,6 +423,7 @@ struct picture_sys_t<br></div>
<div>
<br></div>
<div> {<br></div>
<div>
<br></div>
<div> struct pic_sys_vaapi_instance *instance;<br></div>
<div>
<br></div>
<div> struct vaapi_pic_ctx ctx;<br></div>
<div>
<br></div>
<div>+ vlc_object_t* p_vlc_obj;<br></div>
<div>
<br></div>
<div> };<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> static void<br></div>
<div>
<br></div>
<div>@@ -434,7 +436,7 @@ pool_pic_destroy_cb(picture_t *pic)<br></div>
<div>
<br></div>
<div> {<br></div>
<div>
<br></div>
<div> vaDestroySurfaces(instance->dpy, instance->render_targets,<br></div>
<div>
<br></div>
<div> instance->num_render_targets);<br></div>
<div>
<br></div>
<div>- vlc_vaapi_ReleaseInstance(instance->dpy);<br></div>
<div>
<br></div>
<div>+ vlc_instance_holder_release( p_sys->p_vlc_obj, "vaapi-instance" );<br></div>
<div>
<br></div>
<div> free(instance);<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div> free(pic->p_sys);<br></div>
<div>
<br></div>
<div>@@ -515,6 +517,7 @@ vlc_vaapi_PoolNew(vlc_object_t *o, VADisplay dpy, unsigned count,<br></div>
<div>
<br></div>
<div> goto error_pic;<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div> p_sys->instance = instance;<br></div>
<div>
<br></div>
<div>+ p_sys->p_vlc_obj = o->obj.libvlc;<br></div>
<div>
<br></div>
<div> p_sys->ctx.s.destroy = pic_sys_ctx_destroy_cb;<br></div>
<div>
<br></div>
<div> p_sys->ctx.s.copy = pic_ctx_copy_cb;<br></div>
<div>
<br></div>
<div> p_sys->ctx.surface = instance->render_targets[i];<br></div>
<div>
<br></div>
<div>@@ -537,7 +540,8 @@ vlc_vaapi_PoolNew(vlc_object_t *o, VADisplay dpy, unsigned count,<br></div>
<div>
<br></div>
<div> goto error_pic;<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> atomic_store(&instance->refcount, count);<br></div>
<div>
<br></div>
<div>- instance->dpy = vlc_vaapi_GetInstance(); /* Hold a reference on VADisplay */<br></div>
<div>
<br></div>
<div>+ /* Hold a reference on VADisplay */<br></div>
<div>
<br></div>
<div>+ instance->dpy = vlc_instance_holder_get( o, "vaapi-instance" );<br></div>
<div>
<br></div>
<div> assert(instance->dpy == dpy);<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> *render_targets = instance->render_targets;<br></div>
<div>
<br></div>
<div>diff --git a/modules/hw/vaapi/vlc_vaapi.h b/modules/hw/vaapi/vlc_vaapi.h<br></div>
<div>
<br></div>
<div>index 51dbc69a6c..e06bcfeca3 100644<br></div>
<div>
<br></div>
<div>--- a/modules/hw/vaapi/vlc_vaapi.h<br></div>
<div>
<br></div>
<div>+++ b/modules/hw/vaapi/vlc_vaapi.h<br></div>
<div>
<br></div>
<div>@@ -35,18 +35,12 @@<br></div>
<div>
<br></div>
<div> * VA instance management *<br></div>
<div>
<br></div>
<div> **************************/<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>-/* Allocates the VA instance and sets the reference counter to 1. */<br></div>
<div>
<br></div>
<div>-int<br></div>
<div>
<br></div>
<div>-vlc_vaapi_SetInstance(VADisplay dpy);<br></div>
<div>
<br></div>
<div>-<br></div>
<div>
<br></div>
<div>-/* Retrieve the VA instance and increases the reference counter by 1. */<br></div>
<div>
<br></div>
<div>-VADisplay<br></div>
<div>
<br></div>
<div>-vlc_vaapi_GetInstance(void);<br></div>
<div>
<br></div>
<div>-<br></div>
<div>
<br></div>
<div>-/* Decreases the reference counter by 1 and frees the instance if that counter<br></div>
<div>
<br></div>
<div>- reaches 0. */<br></div>
<div>
<br></div>
<div>-void<br></div>
<div>
<br></div>
<div>-vlc_vaapi_ReleaseInstance(VADisplay *);<br></div>
<div>
<br></div>
<div>+static inline void<br></div>
<div>
<br></div>
<div>+vlc_vaapi_DestroyInstance( void* instance, void* opaque )<br></div>
<div>
<br></div>
<div>+{<br></div>
<div>
<br></div>
<div>+ VLC_UNUSED( opaque );<br></div>
<div>
<br></div>
<div>+ vaTerminate( (VADisplay)instance );<br></div>
<div>
<br></div>
<div>+}<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> /*****************<br></div>
<div>
<br></div>
<div> * VAAPI display *<br></div>
<div>
<br></div>
<div>diff --git a/modules/video_output/opengl/converter_vaapi.c b/modules/video_output/opengl/converter_vaapi.c<br></div>
<div>
<br></div>
<div>index 03987a8e34..658432e434 100644<br></div>
<div>
<br></div>
<div>--- a/modules/video_output/opengl/converter_vaapi.c<br></div>
<div>
<br></div>
<div>+++ b/modules/video_output/opengl/converter_vaapi.c<br></div>
<div>
<br></div>
<div>@@ -25,6 +25,7 @@<br></div>
<div>
<br></div>
<div> #include "internal.h"<br></div>
<div>
<br></div>
<div> #include "../../hw/vaapi/vlc_vaapi.h"<br></div>
<div>
<br></div>
<div> #include <vlc_vout_window.h><br></div>
<div>
<br></div>
<div>+#include <vlc_instance_holder.h><br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> #include <assert.h><br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>@@ -252,7 +253,7 @@ tc_vaegl_release(const opengl_tex_converter_t *tc)<br></div>
<div>
<br></div>
<div> if (priv->last.pic != NULL)<br></div>
<div>
<br></div>
<div> vaegl_release_last_pic(tc, priv);<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>- vlc_vaapi_ReleaseInstance(priv->vadpy);<br></div>
<div>
<br></div>
<div>+ vlc_instance_holder_release( VLC_OBJECT( tc->gl ), "vaapi-instance" );<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> #ifdef HAVE_VA_X11<br></div>
<div>
<br></div>
<div> if (priv->x11dpy != NULL)<br></div>
<div>
<br></div>
<div>@@ -296,12 +297,8 @@ tc_vaegl_init(opengl_tex_converter_t *tc, VADisplay *vadpy)<br></div>
<div>
<br></div>
<div> if (vadpy == NULL)<br></div>
<div>
<br></div>
<div> return VLC_EGENERIC;<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>- int ret = VLC_ENOMEM;<br></div>
<div>
<br></div>
<div>- struct priv *priv = tc->priv = calloc(1, sizeof(struct priv));<br></div>
<div>
<br></div>
<div>- if (unlikely(tc->priv == NULL))<br></div>
<div>
<br></div>
<div>- goto error;<br></div>
<div>
<br></div>
<div>+ struct priv *priv = tc->priv;<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>- ret = VLC_EGENERIC;<br></div>
<div>
<br></div>
<div> priv->vadpy = vadpy;<br></div>
<div>
<br></div>
<div> priv->fourcc = 0;<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>@@ -330,30 +327,48 @@ tc_vaegl_init(opengl_tex_converter_t *tc, VADisplay *vadpy)<br></div>
<div>
<br></div>
<div> if (tc_va_check_interop_blacklist(tc, priv->vadpy))<br></div>
<div>
<br></div>
<div> goto error;<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>- if (vlc_vaapi_SetInstance(priv->vadpy))<br></div>
<div>
<br></div>
<div>- {<br></div>
<div>
<br></div>
<div>- msg_Err(tc->gl, "VAAPI instance already in use");<br></div>
<div>
<br></div>
<div>- vadpy = NULL;<br></div>
<div>
<br></div>
<div>- goto error;<br></div>
<div>
<br></div>
<div>- }<br></div>
<div>
<br></div>
<div>-<br></div>
<div>
<br></div>
<div> tc->fshader = opengl_fragment_shader_init(tc, GL_TEXTURE_2D, VLC_CODEC_NV12,<br></div>
<div>
<br></div>
<div> tc-><a href="http://fmt.space">fmt.space</a>);<br></div>
<div>
<br></div>
<div> if (tc->fshader == 0)<br></div>
<div>
<br></div>
<div>- {<br></div>
<div>
<br></div>
<div>- vlc_vaapi_ReleaseInstance(priv->vadpy);<br></div>
<div>
<br></div>
<div>- vadpy = NULL;<br></div>
<div>
<br></div>
<div> goto error;<br></div>
<div>
<br></div>
<div>- }<br></div>
<div>
<br></div>
<div> return VLC_SUCCESS;<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div> error:<br></div>
<div>
<br></div>
<div> if (vadpy != NULL)<br></div>
<div>
<br></div>
<div> vaTerminate(vadpy);<br></div>
<div>
<br></div>
<div>- free(tc->priv);<br></div>
<div>
<br></div>
<div>- return ret;<br></div>
<div>
<br></div>
<div>+ return VLC_EGENERIC;<br></div>
<div>
<br></div>
<div>+}<br></div>
<div>
<br></div>
<div>+<br></div>
<div>
<br></div>
<div>+<br></div>
<div>
<br></div>
<div>+static VADisplay CreateVADisplayInstance( VADisplay p_display, opengl_tex_converter_t* p_tc )<br></div>
<div>
<br></div>
<div>+{<br></div>
<div>
<br></div>
<div>+ if ( tc_vaegl_init( p_tc, p_display ) )<br></div>
<div>
<br></div>
<div>+ {<br></div>
<div>
<br></div>
<div>+ vaTerminate( p_display );<br></div>
<div>
<br></div>
<div>+ return NULL;<br></div>
<div>
<br></div>
<div>+ }<br></div>
<div>
<br></div>
<div>+ return p_display;<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>+#ifdef HAVE_VA_X11<br></div>
<div>
<br></div>
<div>+static void* CreateVADisplayInstanceX11( void* p_opaque )<br></div>
<div>
<br></div>
<div>+{<br></div>
<div>
<br></div>
<div>+ opengl_tex_converter_t* p_tc = (opengl_tex_converter_t*)p_opaque;<br></div>
<div>
<br></div>
<div>+ struct priv* p_priv = p_tc->priv;<br></div>
<div>
<br></div>
<div>+ return CreateVADisplayInstance( vaGetDisplay( p_priv->x11dpy ), p_tc );<br></div>
<div>
<br></div>
<div>+}<br></div>
<div>
<br></div>
<div>+#endif<br></div>
<div>
<br></div>
<div>+<br></div>
<div>
<br></div>
<div>+#ifdef HAVE_VA_WL<br></div>
<div>
<br></div>
<div>+static void* CreateVADisplayInstanceWL( void* p_opaque )<br></div>
<div>
<br></div>
<div>+{<br></div>
<div>
<br></div>
<div>+ opengl_tex_converter_t* p_tc = (opengl_tex_converter_t*)p_opaque;<br></div>
<div>
<br></div>
<div>+ return CreateVADisplayInstance( vaGetDisplayWl( p_tc->gl->surface->display.wl ),<br></div>
<div>
<br></div>
<div>+ p_tc );<br></div>
<div>
<br></div>
<div>+}<br></div>
<div>
<br></div>
<div>+<br></div>
<div>
<br></div>
<div>+#endif<br></div>
<div>
<br></div>
<div>+<br></div>
<div>
<br></div>
<div> int<br></div>
<div>
<br></div>
<div> opengl_tex_converter_vaapi_init(opengl_tex_converter_t *tc)<br></div>
<div>
<br></div>
<div> {<br></div>
<div>
<br></div>
<div>@@ -362,6 +377,9 @@ opengl_tex_converter_vaapi_init(opengl_tex_converter_t *tc)<br></div>
<div>
<br></div>
<div> || tc->gl->egl.destroyImageKHR == NULL)<br></div>
<div>
<br></div>
<div> return VLC_EGENERIC;<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>+ struct priv* p_priv = tc->priv = calloc(1, sizeof(struct priv));<br></div>
<div>
<br></div>
<div>+ if (unlikely(p_priv == NULL))<br></div>
<div>
<br></div>
<div>+ return VLC_ENOMEM;<br></div>
<div>
<br></div>
<div> switch (tc->gl->surface->type)<br></div>
<div>
<br></div>
<div> {<br></div>
<div>
<br></div>
<div> #ifdef HAVE_VA_X11<br></div>
<div>
<br></div>
<div>@@ -369,27 +387,44 @@ opengl_tex_converter_vaapi_init(opengl_tex_converter_t *tc)<br></div>
<div>
<br></div>
<div> {<br></div>
<div>
<br></div>
<div> if (!vlc_xlib_init(VLC_OBJECT(tc->gl)))<br></div>
<div>
<br></div>
<div> return VLC_EGENERIC;<br></div>
<div>
<br></div>
<div>- Display *x11dpy = XOpenDisplay(tc->gl->surface->display.x11);<br></div>
<div>
<br></div>
<div>- if (x11dpy == NULL)<br></div>
<div>
<br></div>
<div>+ p_priv->x11dpy = XOpenDisplay(tc->gl->surface->display.x11);<br></div>
<div>
<br></div>
<div>+ if (p_priv->x11dpy == NULL)<br></div>
<div>
<br></div>
<div>+ {<br></div>
<div>
<br></div>
<div>+ free( p_priv );<br></div>
<div>
<br></div>
<div> return VLC_EGENERIC;<br></div>
<div>
<br></div>
<div>+ }<br></div>
<div>
<br></div>
<div> <br></div>
<div>
<br></div>
<div>- if (tc_vaegl_init(tc, vaGetDisplay(x11dpy)))<br></div>
<div>
<br></div>
<div>+ VADisplay disp = vlc_instance_holder_acquire(<br></div>
<div>
<br></div>
<div>+ VLC_OBJECT( tc->gl ), "vaapi-instance",<br></div>
<div>
<br></div>
<div>+ &CreateVADisplayInstanceX11, &vlc_vaapi_DestroyInstance,<br></div>
<div>
<br></div>
<div>+ tc );<br></div>
<div>
<br></div>
<div>+ if (disp == NULL)<br></div>
<div>
<br></div>
<div> {<br></div>
<div>
<br></div>
<div>- XCloseDisplay(x11dpy);<br></div>
<div>
<br></div>
<div>+ XCloseDisplay(p_priv->x11dpy);<br></div>
<div>
<br></div>
<div>+ p_priv->x11dpy = NULL;<br></div>
<div>
<br></div>
<div>+ free( p_priv );<br></div>
<div>
<br></div>
<div> return VLC_EGENERIC;<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div>- struct priv *priv = tc->priv;<br></div>
<div>
<br></div>
<div>- priv->x11dpy = x11dpy;<br></div>
<div>
<br></div>
<div> break;<br></div>
<div>
<br></div>
<div> }<br></div>
<div>
<br></div>
<div> #endif<br></div>
<div>
<br></div>
<div> #ifdef HAVE_VA_WL<br></div>
<div>
<br></div>
<div> case VOUT_WINDOW_TYPE_WAYLAND:<br></div>
<div>
<br></div>
<div>- if (tc_vaegl_init(tc, vaGetDisplayWl(tc->gl->surface->display.wl)))<br></div>
<div>
<br></div>
<div>+ {<br></div>
<div>
<br></div>
<div>+ VADisplay disp = vlc_instance_holder_acquire(<br></div>
<div>
<br></div>
<div>+ VLC_OBJECT( tc->gl ),"vaapi-instance",<br></div>
<div>
<br></div>
<div>+ &CreateVADisplayInstanceWL, &vlc_vaapi_DestroyInstance,<br></div>
<div>
<br></div>
<div>+ tc->gl->surface->display.wl);<br></div>
<div>
<br></div>
<div>+ if (disp == NULL)<br></div>
<div>
<br></div>
<div>+ {<br></div>
<div>
<br></div>
<div>+ free( p_priv );<br></div>
<div>
<br></div>
<div> return VLC_EGENERIC;<br></div>
<div>
<br></div>
<div>+ }<br></div>
<div>
<br></div>
<div> break;<br></div>
<div>
<br></div>
<div>+ }<br></div>
<div>
<br></div>
<div> #endif<br></div>
<div>
<br></div>
<div> default:<br></div>
<div>
<br></div>
<div>+ free( p_priv );<br></div>
<div>
<br></div>
<div> return VLC_EGENERIC;<br></div>
<div>
<br></div>
<div> } <br></div>
<div>
<br></div>
</pre></blockquote></div>
<div><br></div>
<div>VA _cannot_ use a single instance. You can have more than one VA device. Also, AFAIK, VA instances are not thread-safe.<br></div>
</blockquote><div><br></div>
<div>We are already puting the VADisplay created by the vout in an instance holder. I don't like that, but I didn't find any others solutions for 3.0.<br></div>
<div><br></div>
<div>Indeed, we can have more than one VAAPI filters in a chain. The first one will be able to get a picture allocated by the vout and have access to the context/p_sys, but the following VAAPI filters won't because the filter new_picture callback will call picture_NewFromFormat(). This is linked to the video filters pool changes that steve wanted to add for 3.0, but we decided to work on for 4.0.<br></div>
<div><br></div>
<div>As far as thread safety is concerned, the intel implementation has always been thread-safe, and the mesa one is since december 2015, see <a href="https://github.com/skeggsb/Mesa/commit/8479782361ab58eeacee7f81b18d9597553859ce">https://github.com/skeggsb/Mesa/commit/8479782361ab58eeacee7f81b18d9597553859ce</a><br></div>
<div><br></div>
<div>So, in my understanding, creating a VAConfig/VAContext is thread-safe, but then you should always use it for <br></div>
<div>decoding/encoding/VPP in only one thread. That's what we currently do.<br></div>
<div><br></div>
<div><br></div>
<blockquote type="cite"><div>-- <br></div>
<div>Rémi Denis-Courmont<br></div>
<div>Typed on an inconvenient virtual keyboard <br></div>
<div><u>_______________________________________________</u><br></div>
<div>vlc-devel mailing list<br></div>
<div>To unsubscribe or modify your subscription options:<br></div>
<div><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></div>
</blockquote><div><br></div>
</body>
</html>