Commit 8fa0dc7b authored by Jean-Paul Saman's avatar Jean-Paul Saman

VAAPI-XCB: vaapi codec and vaapi-xcb get their own X11 display server handle.

The VAAPI codec thread and the video output thread shared an X11 display handle.
However this is not necessary and not required. Let the two modules (and threads)
handle their own private connection.
parent 9ea6c422
......@@ -48,7 +48,7 @@
#ifdef HAVE_AVCODEC_VAAPI
/* Global VAAPI connection state */
static vlc_va_conn_t vlc_va_conn = { NULL, 0, 0, 0, 0, NULL, NULL };
static vlc_va_conn_t vlc_va_conn = { 0, 0, 0, 0, NULL, NULL };
static vlc_mutex_t vlc_va_conn_lock = VLC_STATIC_MUTEX;
static void vlc_va_lock(void)
......@@ -67,9 +67,10 @@ vlc_va_conn_t *vlc_va_get_conn( void )
return (vlc_va_conn_t *) &vlc_va_conn;
}
vlc_va_conn_t *vlc_va_Initialize( const char *display_name )
vlc_va_conn_t *vlc_va_Initialize( Display *display )
{
vlc_mutex_lock(&vlc_va_conn_lock);
/* connect global to caller */
vlc_va_conn_t *conn = vlc_va_get_conn();
assert(conn);
......@@ -84,11 +85,7 @@ vlc_va_conn_t *vlc_va_Initialize( const char *display_name )
conn->unlock = vlc_va_unlock;
/* Create a VA display */
conn->p_x11 = XOpenDisplay(display_name);
if( !conn->p_x11 )
goto error;
conn->p_display = vaGetDisplay(conn->p_x11);
conn->p_display = vaGetDisplay(display);
if( !conn->p_display )
goto error;
......@@ -114,12 +111,9 @@ void vlc_va_Terminate( vlc_va_conn_t *conn )
if( conn->p_display )
vaTerminate( conn->p_display );
if( conn->p_x11 )
XCloseDisplay( conn->p_x11 );
/* Reset values */
conn->p_display = 0;
conn->p_x11 = NULL;
conn->i_version_major = conn->i_version_minor = 0;
conn->i_ref_count = 0;
conn = NULL;
......
......@@ -76,8 +76,5 @@ vlc_va_t *vlc_va_NewDxva2(vlc_object_t *log, int codec_id);
typedef struct vlc_va_conn_t vlc_va_conn_t;
vlc_va_conn_t *vlc_va_get_conn( void );
vlc_va_conn_t *vlc_va_Initialize(const char *display_name);
void vlc_va_Terminate(vlc_va_conn_t *conn);
#endif
......@@ -55,6 +55,7 @@ typedef struct
/* */
vlc_va_conn_t *conn;
Display *display;
VAConfigID i_config_id;
VAContextID i_context_id;
......@@ -75,6 +76,8 @@ typedef struct
} vlc_va_vaapi_t;
static void Close( vlc_va_vaapi_t *p_va );
static vlc_va_vaapi_t *vlc_va_vaapi_Get( void *p_va )
{
return p_va;
......@@ -127,9 +130,14 @@ static int Open( vlc_va_vaapi_t *p_va, int i_codec_id )
p_va->image.image_id = VA_INVALID_ID;
/* Create a VA display */
p_va->conn = vlc_va_Initialize(NULL);
p_va->display = XOpenDisplay(NULL);
if (!p_va->display)
goto error;
p_va->conn = vlc_va_Initialize(p_va->display);
if (!p_va->conn)
goto error;
p_va->conn->lock();
/* Create a VA configuration */
......@@ -161,6 +169,7 @@ static int Open( vlc_va_vaapi_t *p_va, int i_codec_id )
error:
p_va->conn->unlock();
Close(p_va);
return VLC_EGENERIC;
}
......@@ -520,11 +529,17 @@ static void Close( vlc_va_vaapi_t *p_va )
if( p_va->i_surface_width || p_va->i_surface_height )
DestroySurfaces( p_va );
p_va->conn->lock();
if( p_va->i_config_id != VA_INVALID_ID )
vaDestroyConfig( p_va->conn->p_display, p_va->i_config_id );
p_va->conn->unlock();
vlc_va_Terminate( p_va->conn );
if (p_va->conn)
{
p_va->conn->lock();
if( p_va->i_config_id != VA_INVALID_ID )
vaDestroyConfig( p_va->conn->p_display, p_va->i_config_id );
p_va->conn->unlock();
vlc_va_Terminate( p_va->conn );
}
if( p_va->display )
XCloseDisplay( p_va->display );
}
static void Delete( vlc_va_t *p_external )
......
......@@ -20,7 +20,6 @@
#ifdef HAVE_AVCODEC_VAAPI
struct vlc_va_conn_t
{
Display *p_x11;
VADisplay p_display;
int i_version_major;
int i_version_minor;
......@@ -30,6 +29,9 @@ struct vlc_va_conn_t
void (*unlock)(void);
};
vlc_va_conn_t *vlc_va_Initialize(Display *display);
void vlc_va_Terminate(vlc_va_conn_t *conn);
typedef struct
{
VASurfaceID i_id;
......
......@@ -94,6 +94,7 @@ struct vout_display_sys_t
vlc_mutex_t cache_lock;
vlc_array_t cache; /* array of subpicture_subpicture_cache_t */
Display *x11display; /* x11 display connection */
xcb_cursor_t cursor; /* blank cursor */
xcb_window_t window; /* drawable X window */
......@@ -433,22 +434,25 @@ int OpenVaapiX11(vlc_object_t *obj)
if (unlikely(sys->embed == NULL))
goto error;
/* X11 display */
sys->x11display = XOpenDisplay(sys->embed->display.x11);
if (!sys->x11display)
goto error;
/* Create a VA display */
sys->conn = vlc_va_Initialize(sys->embed->display.x11);
sys->conn = vlc_va_Initialize(sys->x11display);
if (!sys->conn)
goto error;
if (FindVAFourCC(vd) != VLC_SUCCESS)
goto error;
sys->conn->lock();
XSetEventQueueOwner(sys->conn->p_x11, XCBOwnsEventQueue);
XSetEventQueueOwner(sys->x11display, XCBOwnsEventQueue);
xcb_connection_t *conn = XGetXCBConnection(sys->conn->p_x11);
xcb_connection_t *conn = XGetXCBConnection(sys->x11display);
assert(conn);
RegisterMouseEvents(obj, conn, sys->embed->handle.xid);
sys->conn->unlock();
/* Find window parameters */
unsigned snum;
......@@ -530,15 +534,13 @@ void CloseVaapiX11(vlc_object_t *obj)
vout_display_t *vd = (vout_display_t *) obj;
vout_display_sys_t *sys = (vout_display_sys_t *) vd->sys;
if (sys->conn && sys->conn->p_x11)
if (sys->x11display)
{
sys->conn->lock();
/* show the default cursor */
xcb_change_window_attributes(XGetXCBConnection(sys->conn->p_x11),
xcb_change_window_attributes(XGetXCBConnection(sys->x11display),
sys->embed->handle.xid, XCB_CW_CURSOR,
&(uint32_t) { XCB_CURSOR_NONE });
xcb_flush(XGetXCBConnection(sys->conn->p_x11));
sys->conn->unlock();
xcb_flush(XGetXCBConnection(sys->x11display));
}
if (sys->embed)
......@@ -572,17 +574,16 @@ void CloseVaapiX11(vlc_object_t *obj)
if (sys->conn)
vlc_va_Terminate(sys->conn);
if (sys->x11display)
XCloseDisplay(sys->x11display);
free(vd->sys);
}
static void Manage(vout_display_t *vd)
{
vout_display_sys_t *sys = vd->sys;
sys->conn->lock();
xcb_connection_t *conn = XGetXCBConnection(sys->conn->p_x11);
sys->conn->unlock();
xcb_connection_t *conn = XGetXCBConnection(sys->x11display);
ManageEvent(vd, conn, &sys->visible);
}
......@@ -610,9 +611,7 @@ static int Control (vout_display_t *vd, int query, va_list ap)
case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
case VOUT_DISPLAY_CHANGE_SOURCE_CROP:
{
sys->conn->lock();
xcb_connection_t *conn = XGetXCBConnection(sys->conn->p_x11);
sys->conn->unlock();
xcb_connection_t *conn = XGetXCBConnection(sys->x11display);
const vout_display_cfg_t *cfg;
const video_format_t *source;
......@@ -667,10 +666,7 @@ static int Control (vout_display_t *vd, int query, va_list ap)
* vout_display_t::info.b_hide_mouse is false */
case VOUT_DISPLAY_HIDE_MOUSE:
{
sys->conn->lock();
xcb_connection_t *conn = XGetXCBConnection(sys->conn->p_x11);
sys->conn->unlock();
xcb_connection_t *conn = XGetXCBConnection(sys->x11display);
xcb_change_window_attributes(conn, sys->embed->handle.xid,
XCB_CW_CURSOR, &(uint32_t){ sys->cursor });
xcb_flush(conn);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment