static void DestroySurfaces( vlc_va_vaapi_t *p_va )
{
- if( p_va->image.image_id )
+ if( p_va->image.image_id != VA_INVALID_SURFACE )
{
CopyCleanCache( &p_va->image_cache );
vaDestroyImage( p_va->p_display, p_va->image.image_id );
free( p_va->p_surface );
/* */
- p_va->image.image_id = 0;
+ p_va->image.image_id = VA_INVALID_SURFACE;
p_va->i_context_id = 0;
p_va->p_surface = NULL;
p_va->i_surface_width = 0;
p_va->p_surface = calloc( p_va->i_surface_count, sizeof(*p_va->p_surface) );
if( !p_va->p_surface )
return VLC_EGENERIC;
+ p_va->image.image_id = VA_INVALID_SURFACE;
/* Create surfaces */
VASurfaceID pi_surface_id[p_va->i_surface_count];
goto error;
}
- /* Find a supported image chroma */
+ /* Find and create a supported image chroma */
int i_fmt_count = vaMaxNumImageFormats( p_va->p_display );
VAImageFormat *p_fmt = calloc( i_fmt_count, sizeof(*p_fmt) );
if( !p_fmt )
p_fmt[i].fourcc == VA_FOURCC( 'I', '4', '2', '0' ) ||
p_fmt[i].fourcc == VA_FOURCC( 'N', 'V', '1', '2' ) )
{
+ if( vaCreateImage( p_va->p_display, &p_fmt[i], i_width, i_height, &p_va->image ) )
+ {
+ p_va->image.image_id = VA_INVALID_SURFACE;
+ continue;
+ }
+ /* Validate that vaGetImage works with this format */
+ if( vaGetImage( p_va->p_display, pi_surface_id[0],
+ 0, 0, i_width, i_height,
+ p_va->image.image_id) )
+ {
+ vaDestroyImage( p_va->p_display, p_va->image.image_id );
+ p_va->image.image_id = VA_INVALID_SURFACE;
+ continue;
+ }
+
i_chroma = VLC_CODEC_YV12;
fmt = p_fmt[i];
break;
goto error;
*pi_chroma = i_chroma;
- /* Create an image for surface extraction */
- if( vaCreateImage( p_va->p_display, &fmt, i_width, i_height, &p_va->image ) )
- {
- p_va->image.image_id = 0;
- goto error;
- }
CopyInitCache( &p_va->image_cache, i_width );
/* Setup the ffmpeg hardware context */
/* */
vlc_va_t *vlc_va_NewVaapi( int i_codec_id )
{
- if( !XInitThreads() )
+ bool fail;
+
+ vlc_global_lock( VLC_XLIB_MUTEX );
+ fail = !XInitThreads();
+ vlc_global_unlock( VLC_XLIB_MUTEX );
+ if( unlikely(fail) )
return NULL;
vlc_va_vaapi_t *p_va = calloc( 1, sizeof(*p_va) );