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

davinci: Call CERuntimeInit() and CERuntimeExit() exactly only once.

parent 1cbcc4c7
......@@ -332,3 +332,69 @@ void davinci_PrintAvailableAlgorithms( vlc_object_t *p_this, const char *psz_eng
}
}
/* NOTE:
* CERuntime should be inited and exited only once per application.
*/
static void vlc_ceruntime_mutex (bool acquire)
{
static vlc_mutex_t lock = VLC_STATIC_MUTEX;
if (acquire)
vlc_mutex_lock (&lock);
else
vlc_mutex_unlock (&lock);
}
static inline void vlc_ceruntime_lock()
{
vlc_ceruntime_mutex(true);
}
static inline void vlc_ceruntime_unlock()
{
vlc_ceruntime_mutex(false);
}
static bool b_ceruntimeinit = false;
static uint32_t ref_ceruntime = 0;
void davinci_RuntimeInit( vlc_object_t *p_this )
{
vlc_ceruntime_lock();
ref_ceruntime++;
if( !b_ceruntimeinit )
{
/* Initialize the codec engine */
CERuntime_init();
b_ceruntimeinit = true;
msg_Dbg( p_this, "CERuntime initialized" );
}
else
{
msg_Dbg( p_this, "CERuntime already initialized" );
}
vlc_ceruntime_unlock();
}
void davinci_RuntimeExit( vlc_object_t *p_this )
{
vlc_ceruntime_lock();
ref_ceruntime--;
if( ref_ceruntime == 0 )
{
/* Exit the codec engine */
CERuntime_exit();
b_ceruntimeinit = false;
msg_Dbg( p_this, "CERuntime exited" );
}
else
{
msg_Dbg( p_this, "CERuntime exited (reference count %d)", ref_ceruntime );
}
vlc_ceruntime_unlock();
}
......@@ -99,7 +99,7 @@ void calculate_fps( encoder_t *p_enc );
const char *davinci_GetExtendedError( XDAS_Int32 );
void davinci_PrintAvailableAlgorithms( vlc_object_t *, const char * );
/* Davinci FourCC */
/* Davinci XDM Versions */
enum davinci_xdm_version_e
{
DAVINCI_XDM0_9 = 0x09,
......@@ -112,6 +112,10 @@ bool GetDavinciEncoder( vlc_fourcc_t, int *, int *, const char **, const char **
bool GetVlcFourcc( const char *, int *, vlc_fourcc_t *, const char ** );
XDAS_Int32 VlcChromaToXdm( vlc_fourcc_t );
/* CE Runtime */
void davinci_RuntimeInit( vlc_object_t *p_this );
void davinci_RuntimeExit( vlc_object_t *p_this );
/* XDM 0.9 */
int davinci_AllocateBuffer( XDAS_Int32, XDAS_Int32 *, XDM_BufDesc * );
void davinci_FreeBuffer( XDM_BufDesc * );
......
......@@ -88,7 +88,7 @@ int OpenEncoder( vlc_object_t *p_this )
}
/* Initialize the codec engine */
CERuntime_init();
davinci_RuntimeInit( p_this );
/* Create an engine handle */
p_sys->engine = Engine_open( p_sys->psz_ti_engine, NULL /*&Engine_ATTRS*/, &err );
......@@ -183,8 +183,7 @@ void CloseEncoder( vlc_object_t *p_this )
Engine_close( p_sys->engine );
/* Exit the codec engine */
/* FIXME: Should this be done only once (if we have encoder + decoder runing) */
CERuntime_exit();
davinci_RuntimeExit( p_this );
free( p_sys->psz_ti_engine );
free( p_sys );
......
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