Commit 92ba7483 authored by Jean-Paul Saman's avatar Jean-Paul Saman

codec/avcodec/vaapi: Use shared connection to libva

vlc_va_Initialize() and vlc_va_Terminate() protects vaInitialize/vaTerminate
from being called more then once. Undefining VLC_VA_SHARED_CONN forces a
private connection per each instance that calls vlc_va_Initiailize/vlc_va_Terminate.
parent 4476b41a
...@@ -46,24 +46,32 @@ ...@@ -46,24 +46,32 @@
#ifdef HAVE_AVCODEC_VAAPI #ifdef HAVE_AVCODEC_VAAPI
#define VA_SHARED_CONN
/* Global VAAPI connection state */ /* Global VAAPI connection state */
#ifdef VA_SHARED_CONN
static vlc_va_conn_t vlc_va_conn = { NULL, 0, 0, 0, 0 }; static vlc_va_conn_t vlc_va_conn = { NULL, 0, 0, 0, 0 };
static bool b_va_inited = false;
#endif
/* */
static vlc_va_conn_t *vlc_va_get_conn( void ) static vlc_va_conn_t *vlc_va_get_conn( void )
{ {
#ifndef VA_SHARED_CONN
return (vlc_va_conn_t *) calloc(1, sizeof(vlc_va_conn_t));
#else
return (vlc_va_conn_t *) &vlc_va_conn; return (vlc_va_conn_t *) &vlc_va_conn;
#endif
} }
vlc_va_conn_t *vlc_va_Initialize( const char *display_name ) vlc_va_conn_t *vlc_va_Initialize( const char *display_name )
{ {
static bool b_va_inited = false;
/* connect global to caller */ /* connect global to caller */
vlc_va_conn_t *conn = vlc_va_get_conn(); vlc_va_conn_t *conn = vlc_va_get_conn();
assert(conn); assert(conn);
#ifdef VA_SHARED_CONN
if (b_va_inited) if (b_va_inited)
return conn; return conn;
#endif
/* Create a VA display */ /* Create a VA display */
conn->p_display_x11 = XOpenDisplay(display_name); conn->p_display_x11 = XOpenDisplay(display_name);
if( !conn->p_display_x11 ) if( !conn->p_display_x11 )
...@@ -75,9 +83,10 @@ vlc_va_conn_t *vlc_va_Initialize( const char *display_name ) ...@@ -75,9 +83,10 @@ vlc_va_conn_t *vlc_va_Initialize( const char *display_name )
if( vaInitialize(conn->p_display, &conn->i_version_major, &conn->i_version_minor) ) if( vaInitialize(conn->p_display, &conn->i_version_major, &conn->i_version_minor) )
goto error; goto error;
#ifdef VA_SHARED_CONN
conn->i_ref_count++; conn->i_ref_count++;
b_va_inited = true; b_va_inited = true;
#endif
return conn; return conn;
error: error:
...@@ -87,20 +96,27 @@ error: ...@@ -87,20 +96,27 @@ error:
void vlc_va_Terminate( vlc_va_conn_t *conn ) void vlc_va_Terminate( vlc_va_conn_t *conn )
{ {
assert(conn); assert(conn);
#ifdef VA_SHARED_CONN
conn->i_ref_count--; conn->i_ref_count--;
if (conn->i_ref_count > 0) if (conn->i_ref_count > 0)
return; return;
#endif
if( conn->p_display ) if( conn->p_display )
vaTerminate( conn->p_display ); vaTerminate( conn->p_display );
if( conn->p_display_x11 ) if( conn->p_display_x11 )
XCloseDisplay( conn->p_display_x11 ); XCloseDisplay( conn->p_display_x11 );
#ifndef VA_SHARED_CONN
free(conn);
#else
/* Reset values */ /* Reset values */
conn->p_display = 0; conn->p_display = 0;
conn->p_display_x11 = NULL; conn->p_display_x11 = NULL;
conn->i_version_major = conn->i_version_minor = 0; conn->i_version_major = conn->i_version_minor = 0;
conn->i_ref_count = 0; conn->i_ref_count = 0;
conn = NULL; conn = NULL;
/* */
b_va_inited = false;
#endif
} }
#endif #endif
...@@ -80,9 +80,18 @@ struct vlc_va_conn_t ...@@ -80,9 +80,18 @@ struct vlc_va_conn_t
vlc_va_conn_t *vlc_va_Initialize(const char *display_name); vlc_va_conn_t *vlc_va_Initialize(const char *display_name);
void vlc_va_Terminate(vlc_va_conn_t *conn); void vlc_va_Terminate(vlc_va_conn_t *conn);
typedef struct
{
VASurfaceID i_id;
int i_refcount;
unsigned int i_order;
vlc_mutex_t lock;
} vlc_va_surface_t;
struct picture_sys_t struct picture_sys_t
{ {
VASurfaceID i_surface_id; vlc_va_surface_t *surface;
}; };
#endif #endif
......
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