Commit 91f15717 authored by Jean-Paul Saman's avatar Jean-Paul Saman

Implemented decoder_GetPictureCount() and vout_GetPictureCount()

The idea is to get the  number of pictures needed according to core for direct rendering.
So that the decoder knows how many surfaces it needs to allocated. However the vout is instantiated,
after the codec is. Luckily the number needed is rather static, so if there is no vout yet, then return
the static value.
parent 9f211171
......@@ -99,6 +99,7 @@ struct decoder_t
* and decoder_LinkPicture/decoder_UnlinkPicture */
picture_t *(*pf_vout_buffer_new)( decoder_t * );
void (*pf_vout_buffer_del)( decoder_t *, picture_t * );
int (*pf_vout_buffer_size) (decoder_t * );
void (*pf_picture_link) ( decoder_t *, picture_t * );
void (*pf_picture_unlink) ( decoder_t *, picture_t * );
......@@ -186,6 +187,11 @@ VLC_API picture_t * decoder_NewPicture( decoder_t * ) VLC_USED;
*/
VLC_API void decoder_DeletePicture( decoder_t *, picture_t *p_picture );
/**
* It returns the size of the given picture pool.
*/
VLC_API int decoder_GetPictureCount( decoder_t * );
/**
* This function will increase the picture reference count.
* (picture_Hold is not usable.)
......
......@@ -149,6 +149,11 @@ VLC_API int vout_GetSnapshot( vout_thread_t *p_vout,
VLC_API picture_t * vout_GetPicture( vout_thread_t * );
VLC_API void vout_PutPicture( vout_thread_t *, picture_t * );
/**
* It returns the size of the given picture pool.
*/
VLC_API int vout_GetPictureCount( vout_thread_t * );
VLC_API void vout_HoldPicture( vout_thread_t *, picture_t * );
VLC_API void vout_ReleasePicture( vout_thread_t *, picture_t * );
......
......@@ -72,7 +72,7 @@ static inline void vlc_va_Delete(vlc_va_t *va)
va->close(va);
}
vlc_va_t *vlc_va_NewVaapi(vlc_object_t *obj, int codec_id);
vlc_va_t *vlc_va_NewVaapi(vlc_object_t *obj, int codec_id, int count);
vlc_va_t *vlc_va_NewDxva2(vlc_object_t *log, int codec_id);
#endif
......@@ -84,7 +84,7 @@ static vlc_va_vaapi_t *vlc_va_vaapi_Get( void *p_va )
}
/* */
static int Open( vlc_va_vaapi_t *p_va, int i_codec_id )
static int Open( vlc_va_vaapi_t *p_va, int i_codec_id, int i_count )
{
VAProfile i_profile;
int i_surface_count;
......@@ -109,7 +109,7 @@ static int Open( vlc_va_vaapi_t *p_va, int i_codec_id )
break;
case CODEC_ID_WMV3:
i_profile = VAProfileVC1Main;
i_surface_count = +1;
i_surface_count = 2+1;
break;
case CODEC_ID_VC1:
i_profile = VAProfileVC1Advanced;
......@@ -117,12 +117,16 @@ static int Open( vlc_va_vaapi_t *p_va, int i_codec_id )
break;
case CODEC_ID_H264:
i_profile = VAProfileH264High;
i_surface_count = 30; //16+1;
i_surface_count = 16+1;
break;
default:
return VLC_EGENERIC;
}
int i_needed = __MAX(i_surface_count, i_count);
i_surface_count = i_needed + i_surface_count;
assert( i_surface_count >= 30 );
/* */
memset( p_va, 0, sizeof(*p_va) );
p_va->i_config_id = VA_INVALID_ID;
......@@ -560,7 +564,7 @@ static void Delete( vlc_va_t *p_external )
}
/* */
vlc_va_t *vlc_va_NewVaapi( vlc_object_t *obj, int i_codec_id )
vlc_va_t *vlc_va_NewVaapi( vlc_object_t *obj, int i_codec_id, int i_count )
{
if( !vlc_xlib_init( obj ) )
return NULL;
......@@ -569,7 +573,7 @@ vlc_va_t *vlc_va_NewVaapi( vlc_object_t *obj, int i_codec_id )
if( !p_va )
return NULL;
if( Open( p_va, i_codec_id ) )
if( Open( p_va, i_codec_id, i_count ) )
{
free( p_va );
return NULL;
......@@ -588,10 +592,11 @@ vlc_va_t *vlc_va_NewVaapi( vlc_object_t *obj, int i_codec_id )
}
#else
vlc_va_t *vlc_va_NewVaapi( vlc_object_t *obj, int i_codec_id )
vlc_va_t *vlc_va_NewVaapi( vlc_object_t *obj, int i_codec_id, int i_count )
{
VLC_UNUSED( obj );
VLC_UNUSED( i_codec_id );
VLC_UNUSED( i_count );
return NULL;
}
#endif
......@@ -1173,7 +1173,8 @@ static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *p_context,
}
#ifdef HAVE_AVCODEC_VAAPI
msg_Dbg( p_dec, "Trying VA API" );
p_sys->p_va = vlc_va_NewVaapi( VLC_OBJECT(p_dec), p_sys->i_codec_id );
int count = decoder_GetPictureCount( p_dec );
p_sys->p_va = vlc_va_NewVaapi( VLC_OBJECT(p_dec), p_sys->i_codec_id, count );
if( !p_sys->p_va )
msg_Warn( p_dec, "Failed to open VA API" );
#else
......
......@@ -73,6 +73,7 @@ static aout_buffer_t *aout_new_buffer( decoder_t *, int );
static picture_t *vout_new_buffer( decoder_t * );
static void vout_del_buffer( decoder_t *, picture_t * );
static int vout_get_buffer_size( decoder_t * );
static void vout_link_picture( decoder_t *, picture_t * );
static void vout_unlink_picture( decoder_t *, picture_t * );
......@@ -197,6 +198,10 @@ void decoder_DeletePicture( decoder_t *p_decoder, picture_t *p_picture )
{
p_decoder->pf_vout_buffer_del( p_decoder, p_picture );
}
int decoder_GetPictureCount( decoder_t *p_decoder )
{
return p_decoder->pf_vout_buffer_size( p_decoder );
}
void decoder_LinkPicture( decoder_t *p_decoder, picture_t *p_picture )
{
p_decoder->pf_picture_link( p_decoder, p_picture );
......@@ -797,6 +802,7 @@ static decoder_t * CreateDecoder( vlc_object_t *p_parent,
p_dec->pf_aout_buffer_new = aout_new_buffer;
p_dec->pf_vout_buffer_new = vout_new_buffer;
p_dec->pf_vout_buffer_del = vout_del_buffer;
p_dec->pf_vout_buffer_size = vout_get_buffer_size;
p_dec->pf_picture_link = vout_link_picture;
p_dec->pf_picture_unlink = vout_unlink_picture;
p_dec->pf_spu_buffer_new = spu_new_buffer;
......@@ -2473,6 +2479,11 @@ static void vout_del_buffer( decoder_t *p_dec, picture_t *p_pic )
vout_ReleasePicture( p_dec->p_owner->p_vout, p_pic );
}
static int vout_get_buffer_size( decoder_t *p_dec )
{
return vout_GetPictureCount( p_dec->p_owner->p_vout );
}
static void vout_link_picture( decoder_t *p_dec, picture_t *p_pic )
{
vout_HoldPicture( p_dec->p_owner->p_vout, p_pic );
......
......@@ -85,6 +85,7 @@ decoder_DeleteSubpicture
decoder_GetDisplayDate
decoder_GetDisplayRate
decoder_GetInputAttachments
decoder_GetPictureCount
decoder_LinkPicture
decoder_NewAudioBuffer
decoder_NewPicture
......@@ -628,6 +629,7 @@ vlm_MessageSimpleNew
vlm_New
vout_Close
vout_GetPicture
vout_GetPictureCount
vout_PutPicture
vout_HoldPicture
vout_ReleasePicture
......
......@@ -453,6 +453,21 @@ void vout_HoldPicture(vout_thread_t *vout, picture_t *picture)
vlc_mutex_unlock(&vout->p->picture_lock);
}
/**
* Return number of pictures available in the pool.
*/
int vout_GetPictureCount(vout_thread_t *vout)
{
if (vout == NULL)
return 20; /* FIXME: vout_internal.c has VOUT_MAX_PICTURES set to 20 */
vlc_mutex_lock(&vout->p->picture_lock);
int size = picture_pool_GetSize(vout->p->decoder_pool);
vlc_mutex_lock(&vout->p->picture_lock);
return size;
}
/* */
int vout_GetSnapshot(vout_thread_t *vout,
block_t **image_dst, picture_t **picture_dst,
......
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