-/*****************************************************************************
- * VLC_AddIntf: add an interface
- *****************************************************************************
- * This function opens an interface plugin and runs it. If b_block is set
- * to 0, VLC_AddIntf will return immediately and let the interface run in a
- * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
- * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
- * the playlist when it is completely initialised.
- *****************************************************************************/
-int VLC_AddIntf( int i_object, char const *psz_module,
- vlc_bool_t b_block, vlc_bool_t b_play )
-{
- int i_err;
- intf_thread_t *p_intf;
- vlc_t *p_vlc = vlc_current_object( i_object );
-
- if( !p_vlc )
- {
- return VLC_ENOOBJ;
- }
-
-#ifndef WIN32
- if( p_vlc->p_libvlc->b_daemon && b_block && !psz_module )
- {
- /* Daemon mode hack.
- * We prefer the dummy interface if none is specified. */
- char *psz_interface = config_GetPsz( p_vlc, "intf" );
- if( !psz_interface || !*psz_interface ) psz_module = "dummy";
- if( psz_interface ) free( psz_interface );
- }
-#endif
-
- /* Try to create the interface */
- p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf" );
-
- if( p_intf == NULL )
- {
- msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_EGENERIC;
- }
-
- /* Interface doesn't handle play on start so do it ourselves */
- if( !p_intf->b_play && b_play ) VLC_Play( i_object );
-
- /* Try to run the interface */
- p_intf->b_play = b_play;
- p_intf->b_block = b_block;
- i_err = intf_RunThread( p_intf );
- if( i_err )
- {
- vlc_object_detach( p_intf );
- intf_Destroy( p_intf );
- if( i_object ) vlc_object_release( p_vlc );
- return i_err;
- }
-
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * VLC_Die: ask vlc to die.
- *****************************************************************************
- * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
- * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
- *****************************************************************************/
-int VLC_Die( int i_object )
-{
- vlc_t *p_vlc = vlc_current_object( i_object );
-
- if( !p_vlc )
- {
- return VLC_ENOOBJ;
- }
-
- p_vlc->b_die = VLC_TRUE;
-
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
- *****************************************************************************/
-int VLC_CleanUp( int i_object )
-{
- intf_thread_t * p_intf;
- playlist_t * p_playlist;
- vout_thread_t * p_vout;
- aout_instance_t * p_aout;
- announce_handler_t * p_announce;
- vlc_t *p_vlc = vlc_current_object( i_object );
-
- /* Check that the handle is valid */
- if( !p_vlc )
- {
- return VLC_ENOOBJ;
- }
-
- /*
- * Ask the interfaces to stop and destroy them
- */
- msg_Dbg( p_vlc, "removing all interfaces" );
- while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
- {
- intf_StopThread( p_intf );
- vlc_object_detach( p_intf );
- vlc_object_release( p_intf );
- intf_Destroy( p_intf );
- }
-
- /*
- * Free playlists
- */
- msg_Dbg( p_vlc, "removing all playlists" );
- while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
- FIND_CHILD )) )
- {
- vlc_object_detach( p_playlist );
- vlc_object_release( p_playlist );
- playlist_Destroy( p_playlist );
- }
-
- /*
- * Free video outputs
- */
- msg_Dbg( p_vlc, "removing all video outputs" );
- while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
- {
- vlc_object_detach( p_vout );
- vlc_object_release( p_vout );
- vout_Destroy( p_vout );
- }
-
- /*
- * Free audio outputs
- */
- msg_Dbg( p_vlc, "removing all audio outputs" );
- while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
- {
- vlc_object_detach( (vlc_object_t *)p_aout );
- vlc_object_release( (vlc_object_t *)p_aout );
- aout_Delete( p_aout );
- }
-
- /*
- * Free announce handler(s?)
- */
- msg_Dbg( p_vlc, "removing announce handler" );
- while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE,
- FIND_CHILD ) ) )
- {
- vlc_object_detach( p_announce );
- vlc_object_release( p_announce );
- announce_HandlerDestroy( p_announce );
- }
-
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * VLC_Destroy: Destroy everything.
- *****************************************************************************
- * This function requests the running threads to finish, waits for their
- * termination, and destroys their structure.
- *****************************************************************************/
-int VLC_Destroy( int i_object )
-{
- vlc_t *p_vlc = vlc_current_object( i_object );
-
- if( !p_vlc )
- {
- return VLC_ENOOBJ;
- }
-
- /*
- * Free allocated memory
- */
- if( p_vlc->p_memcpy_module )
- {
- module_Unneed( p_vlc, p_vlc->p_memcpy_module );
- p_vlc->p_memcpy_module = NULL;
- }
-
- /*
- * Free module bank !
- */
- module_EndBank( p_vlc );
-
- if( p_vlc->psz_homedir )
- {
- free( p_vlc->psz_homedir );
- p_vlc->psz_homedir = NULL;
- }
-
- if( p_vlc->psz_userdir )
- {
- free( p_vlc->psz_userdir );
- p_vlc->psz_userdir = NULL;
- }
-
- if( p_vlc->psz_configfile )
- {
- free( p_vlc->psz_configfile );
- p_vlc->psz_configfile = NULL;
- }
-
- if( p_vlc->p_hotkeys )
- {
- free( p_vlc->p_hotkeys );
- p_vlc->p_hotkeys = NULL;
- }
-
- /*
- * System specific cleaning code
- */
- system_End( p_vlc );
-
- /*
- * Free message queue.
- * Nobody shall use msg_* afterward.
- */
- msg_Flush( p_vlc );
- msg_Destroy( p_libvlc );
-
- /* Destroy global iconv */
- LocaleDeinit();
-
- /* Destroy mutexes */
- vlc_mutex_destroy( &p_vlc->config_lock );
-
- vlc_object_detach( p_vlc );
-
- /* Release object before destroying it */
- if( i_object ) vlc_object_release( p_vlc );
-
- vlc_object_destroy( p_vlc );
-
- /* Stop thread system: last one out please shut the door! */
- vlc_threads_end( p_libvlc );
-
- return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * VLC_VariableSet: set a vlc variable
- *****************************************************************************/
-int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
-{
- vlc_t *p_vlc = vlc_current_object( i_object );
- int i_ret;
-
- if( !p_vlc )
- {
- return VLC_ENOOBJ;
- }
-
- /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
- * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
- if( !strncmp( psz_var, "conf::", 6 ) )
- {
- module_config_t *p_item;
- char const *psz_newvar = psz_var + 6;
-
- p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
-
- if( p_item )
- {
- switch( p_item->i_type )
- {
- case CONFIG_ITEM_BOOL:
- config_PutInt( p_vlc, psz_newvar, value.b_bool );
- break;
- case CONFIG_ITEM_INTEGER:
- config_PutInt( p_vlc, psz_newvar, value.i_int );
- break;
- case CONFIG_ITEM_FLOAT:
- config_PutFloat( p_vlc, psz_newvar, value.f_float );
- break;
- default:
- config_PutPsz( p_vlc, psz_newvar, value.psz_string );
- break;
- }
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_SUCCESS;
- }
- }
-
- i_ret = var_Set( p_vlc, psz_var, value );
-
- if( i_object ) vlc_object_release( p_vlc );
- return i_ret;
-}
-
-/*****************************************************************************
- * VLC_VariableGet: get a vlc variable
- *****************************************************************************/
-int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
-{
- vlc_t *p_vlc = vlc_current_object( i_object );
- int i_ret;
-
- if( !p_vlc )
- {
- return VLC_ENOOBJ;
- }
-
- i_ret = var_Get( p_vlc , psz_var, p_value );
-
- if( i_object ) vlc_object_release( p_vlc );
- return i_ret;
-}
-
-/*****************************************************************************
- * VLC_VariableType: get a vlc variable type
- *****************************************************************************/
-int VLC_VariableType( int i_object, char const *psz_var, int *pi_type )
-{
- int i_type;
- vlc_t *p_vlc = vlc_current_object( i_object );
-
- if( !p_vlc )
- {
- return VLC_ENOOBJ;
- }
-
- /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
- * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
- if( !strncmp( psz_var, "conf::", 6 ) )
- {
- module_config_t *p_item;
- char const *psz_newvar = psz_var + 6;
-
- p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
-
- if( p_item )
- {
- switch( p_item->i_type )
- {
- case CONFIG_ITEM_BOOL:
- i_type = VLC_VAR_BOOL;
- break;
- case CONFIG_ITEM_INTEGER:
- i_type = VLC_VAR_INTEGER;
- break;
- case CONFIG_ITEM_FLOAT:
- i_type = VLC_VAR_FLOAT;
- break;
- default:
- i_type = VLC_VAR_STRING;
- break;
- }
- }
- else
- i_type = 0;
- }
- else
- i_type = VLC_VAR_TYPE & var_Type( p_vlc , psz_var );
-
- if( i_object ) vlc_object_release( p_vlc );
-
- if( i_type > 0 )
- {
- *pi_type = i_type;
- return VLC_SUCCESS;
- }
- return VLC_ENOVAR;
-}
-
-/*****************************************************************************
- * VLC_AddTarget: adds a target for playing.
- *****************************************************************************
- * This function adds psz_target to the current playlist. If a playlist does
- * not exist, it will create one.
- *****************************************************************************/
-int VLC_AddTarget( int i_object, char const *psz_target,
- char const **ppsz_options, int i_options,
- int i_mode, int i_pos )
-{
- int i_err;
- playlist_t *p_playlist;
- vlc_t *p_vlc = vlc_current_object( i_object );
-
- if( !p_vlc )
- {
- return VLC_ENOOBJ;
- }
-
- p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-
- if( p_playlist == NULL )
- {
- msg_Dbg( p_vlc, "no playlist present, creating one" );
- p_playlist = playlist_Create( p_vlc );
-
- if( p_playlist == NULL )
- {
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_EGENERIC;
- }
-
- vlc_object_yield( p_playlist );
- }
-
- i_err = playlist_AddExt( p_playlist, psz_target, psz_target,
- i_mode, i_pos, -1, ppsz_options, i_options);
-
- vlc_object_release( p_playlist );
-
- if( i_object ) vlc_object_release( p_vlc );
- return i_err;
-}
-
-/*****************************************************************************
- * VLC_Play: play the playlist
- *****************************************************************************/
-int VLC_Play( int i_object )
-{
- playlist_t * p_playlist;
- vlc_t *p_vlc = vlc_current_object( i_object );
-
- /* Check that the handle is valid */
- if( !p_vlc )
- {
- return VLC_ENOOBJ;
- }
-
- p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
-
- if( !p_playlist )
- {
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_ENOOBJ;
- }
-
- playlist_Play( p_playlist );
- vlc_object_release( p_playlist );
-
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * VLC_Pause: toggle pause
- *****************************************************************************/
-int VLC_Pause( int i_object )
-{
- playlist_t * p_playlist;
- vlc_t *p_vlc = vlc_current_object( i_object );
-
- /* Check that the handle is valid */
- if( !p_vlc )
- {
- return VLC_ENOOBJ;
- }
-
- p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
-
- if( !p_playlist )
- {
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_ENOOBJ;
- }
-
- playlist_Pause( p_playlist );
- vlc_object_release( p_playlist );
-
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * VLC_Pause: toggle pause
- *****************************************************************************/
-int VLC_Stop( int i_object )
-{
- playlist_t * p_playlist;
- vlc_t *p_vlc = vlc_current_object( i_object );
-
- /* Check that the handle is valid */
- if( !p_vlc )
- {
- return VLC_ENOOBJ;
- }
-
- p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
-
- if( !p_playlist )
- {
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_ENOOBJ;
- }
-
- playlist_Stop( p_playlist );
- vlc_object_release( p_playlist );
-
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * VLC_IsPlaying: Query for Playlist Status
- *****************************************************************************/
-vlc_bool_t VLC_IsPlaying( int i_object )
-{
- playlist_t * p_playlist;
- vlc_bool_t b_playing;
-
- vlc_t *p_vlc = vlc_current_object( i_object );
-
- /* Check that the handle is valid */
- if( !p_vlc )
- {
- return VLC_ENOOBJ;
- }
-
- p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
-
- if( !p_playlist )
- {
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_ENOOBJ;
- }
-
- if( p_playlist->p_input )
- {
- vlc_value_t val;
- var_Get( p_playlist->p_input, "state", &val );
- b_playing = ( val.i_int == PLAYING_S );
- }
- else
- {
- msg_Dbg(p_vlc, "polling playlist_IsPlaying");
- b_playing = playlist_IsPlaying( p_playlist );
- }
- vlc_object_release( p_playlist );
-
- if( i_object ) vlc_object_release( p_vlc );
- return b_playing;
-}
-
-/**
- * Get the current position in a input
- *
- * Return the current position as a float
- * \note For some inputs, this will be unknown.
- *
- * \param i_object a vlc object id
- * \return a float in the range of 0.0 - 1.0
- */
-float VLC_PositionGet( int i_object )
-{
- input_thread_t *p_input;
- vlc_value_t val;
- vlc_t *p_vlc = vlc_current_object( i_object );
-
- /* Check that the handle is valid */
- if( !p_vlc )
- {
- return VLC_ENOOBJ;
- }
-
- p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
-
- if( !p_input )
- {
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_ENOOBJ;
- }
-
- var_Get( p_input, "position", &val );
- vlc_object_release( p_input );
-
- if( i_object ) vlc_object_release( p_vlc );
- return val.f_float;
-}
-