00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdlib.h>
00024 #include <stdio.h>
00025 #include <string.h>
00026
00027 #include <vlc/vlc.h>
00028 #include <vlc/vout.h>
00029 #include <vlc/sout.h>
00030 #include <vlc/input.h>
00031
00032 #include "vlc_playlist.h"
00033
00034
00035
00036
00037
00038 static void RunSD( services_discovery_t *p_sd );
00039
00040
00041
00042
00043
00044 int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,
00045 const char *psz_module )
00046 {
00047 services_discovery_t *p_sd;
00048
00049 p_sd = vlc_object_create( p_playlist, VLC_OBJECT_SD );
00050 p_sd->pf_run = NULL;
00051
00052 p_sd->p_module = module_Need( p_sd, "services_discovery", psz_module, 0 );
00053
00054 if( p_sd->p_module == NULL )
00055 {
00056 msg_Err( p_playlist, "no suitable services discovery module" );
00057 vlc_object_destroy( p_sd );
00058 return VLC_EGENERIC;
00059 }
00060
00061 p_sd->psz_module = strdup( psz_module );
00062 p_sd->b_die = VLC_FALSE;
00063
00064 vlc_mutex_lock( &p_playlist->object_lock );
00065
00066 INSERT_ELEM( p_playlist->pp_sds, p_playlist->i_sds, p_playlist->i_sds,
00067 p_sd );
00068
00069 vlc_mutex_unlock( &p_playlist->object_lock );
00070
00071 if( vlc_thread_create( p_sd, "services_discovery", RunSD,
00072 VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
00073 {
00074 msg_Err( p_sd, "cannot create services discovery thread" );
00075 vlc_object_destroy( p_sd );
00076 return VLC_EGENERIC;
00077 }
00078
00079
00080 return VLC_SUCCESS;
00081 }
00082
00083 int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,
00084 const char *psz_module )
00085 {
00086 int i;
00087 services_discovery_t *p_sd = NULL;
00088 vlc_mutex_lock( &p_playlist->object_lock );
00089
00090 for( i = 0 ; i< p_playlist->i_sds ; i ++ )
00091 {
00092 if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
00093 {
00094 p_sd = p_playlist->pp_sds[i];
00095 REMOVE_ELEM( p_playlist->pp_sds, p_playlist->i_sds, i );
00096 break;
00097 }
00098 }
00099
00100 if( p_sd )
00101 {
00102 vlc_mutex_unlock( &p_playlist->object_lock );
00103 p_sd->b_die = VLC_TRUE;
00104 vlc_thread_join( p_sd );
00105 free( p_sd->psz_module );
00106 module_Unneed( p_sd, p_sd->p_module );
00107 vlc_mutex_lock( &p_playlist->object_lock );
00108 vlc_object_destroy( p_sd );
00109 }
00110 else
00111 {
00112 msg_Warn( p_playlist, "module %s is not loaded", psz_module );
00113 vlc_mutex_unlock( &p_playlist->object_lock );
00114 return VLC_EGENERIC;
00115 }
00116
00117 vlc_mutex_unlock( &p_playlist->object_lock );
00118 return VLC_SUCCESS;
00119 }
00120
00121 vlc_bool_t playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist,
00122 const char *psz_module )
00123 {
00124 int i;
00125 vlc_mutex_lock( &p_playlist->object_lock );
00126
00127 for( i = 0 ; i< p_playlist->i_sds ; i ++ )
00128 {
00129 if( !strcmp( psz_module, p_playlist->pp_sds[i]->psz_module ) )
00130 {
00131 vlc_mutex_unlock( &p_playlist->object_lock );
00132 return VLC_TRUE;
00133 }
00134 }
00135 vlc_mutex_unlock( &p_playlist->object_lock );
00136 return VLC_FALSE;
00137 }
00138
00139
00147 int playlist_AddSDModules( playlist_t *p_playlist, char *psz_modules )
00148 {
00149 if( psz_modules && *psz_modules )
00150 {
00151 char *psz_parser = psz_modules;
00152 char *psz_next;
00153
00154 while( psz_parser && *psz_parser )
00155 {
00156 while( *psz_parser == ' ' || *psz_parser == ':' )
00157 {
00158 psz_parser++;
00159 }
00160
00161 if( (psz_next = strchr( psz_parser, ':' ) ) )
00162 {
00163 *psz_next++ = '\0';
00164 }
00165 if( *psz_parser == '\0' )
00166 {
00167 break;
00168 }
00169
00170 playlist_ServicesDiscoveryAdd( p_playlist, psz_parser );
00171
00172 psz_parser = psz_next;
00173 }
00174 }
00175 return VLC_SUCCESS;
00176 }
00177
00178 static void RunSD( services_discovery_t *p_sd )
00179 {
00180 p_sd->pf_run( p_sd );
00181 return;
00182 }