00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 #include <stdlib.h>
00101
00102 #include <vlc/vlc.h>
00103 #include <vlc/input.h>
00104 #include <vlc_playlist.h>
00105
00106
00107
00108
00109 static int Activate ( vlc_object_t * );
00110 static void Deactivate( vlc_object_t * );
00111
00112 vlc_module_begin();
00113 set_description( _("Kasenna MediaBase metademux") );
00114 set_category( CAT_INPUT );
00115 set_subcategory( SUBCAT_INPUT_DEMUX );
00116 set_capability( "demux2", 170 );
00117 set_callbacks( Activate, Deactivate );
00118 add_shortcut( "sgimb" );
00119 vlc_module_end();
00120
00121
00122
00123
00124 #define MAX_LINE 1024
00125
00126 struct demux_sys_t
00127 {
00128 char *psz_uri;
00129 char *psz_server;
00130 char *psz_location;
00131 char *psz_name;
00132 char *psz_user;
00133 char *psz_password;
00134 char *psz_mcast_ip;
00135 int i_mcast_port;
00136 int i_packet_size;
00137 mtime_t i_duration;
00138 int i_port;
00139 int i_sid;
00140 vlc_bool_t b_concert;
00141 vlc_bool_t b_rtsp_kasenna;
00142 };
00143
00144 static int Demux ( demux_t *p_demux );
00145 static int Control( demux_t *p_demux, int i_query, va_list args );
00146
00147
00148
00149
00150 static int Activate( vlc_object_t * p_this )
00151 {
00152 demux_t *p_demux = (demux_t *)p_this;
00153 demux_sys_t *p_sys;
00154 byte_t *p_peek;
00155 int i_size;
00156
00157
00158 i_size = stream_Peek( p_demux->s, &p_peek, MAX_LINE );
00159 i_size -= sizeof("sgiNameServerHost=") - 1;
00160 if ( i_size > 0 )
00161 {
00162 while ( i_size && strncasecmp( p_peek, "sgiNameServerHost=",
00163 sizeof("sgiNameServerHost=") - 1 ) )
00164 {
00165 p_peek++;
00166 i_size--;
00167 }
00168 if ( !strncasecmp( p_peek, "sgiNameServerHost=",
00169 sizeof("sgiNameServerHost=") -1 ) )
00170 {
00171 p_demux->pf_demux = Demux;
00172 p_demux->pf_control = Control;
00173
00174 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
00175 p_sys->psz_uri = NULL;
00176 p_sys->psz_server = NULL;
00177 p_sys->psz_location = NULL;
00178 p_sys->psz_name = NULL;
00179 p_sys->psz_user = NULL;
00180 p_sys->psz_password = NULL;
00181 p_sys->psz_mcast_ip = NULL;
00182 p_sys->i_mcast_port = 0;
00183 p_sys->i_packet_size = 0;
00184 p_sys->i_duration = 0;
00185 p_sys->i_port = 0;
00186 p_sys->i_sid = 0;
00187 p_sys->b_rtsp_kasenna = VLC_FALSE;
00188 p_sys->b_concert = VLC_FALSE;
00189
00190 return VLC_SUCCESS;
00191 }
00192 }
00193 return VLC_EGENERIC;
00194 }
00195
00196
00197
00198
00199 static void Deactivate( vlc_object_t *p_this )
00200 {
00201 demux_t *p_demux = (demux_t*)p_this;
00202 demux_sys_t *p_sys = p_demux->p_sys;
00203 if( p_sys->psz_uri )
00204 free( p_sys->psz_uri );
00205 if( p_sys->psz_server )
00206 free( p_sys->psz_server );
00207 if( p_sys->psz_location )
00208 free( p_sys->psz_location );
00209 if( p_sys->psz_name )
00210 free( p_sys->psz_name );
00211 if( p_sys->psz_user )
00212 free( p_sys->psz_user );
00213 if( p_sys->psz_password )
00214 free( p_sys->psz_password );
00215 if( p_sys->psz_mcast_ip )
00216 free( p_sys->psz_mcast_ip );
00217 free( p_demux->p_sys );
00218 return;
00219 }
00220
00221 static int ParseLine ( demux_t *p_demux, char *psz_line )
00222 {
00223 char *psz_bol;
00224 demux_sys_t *p_sys = p_demux->p_sys;
00225
00226 psz_bol = psz_line;
00227
00228
00229 while( *psz_bol == ' ' || *psz_bol == '\t' ||
00230 *psz_bol == '\n' || *psz_bol == '\r' )
00231 {
00232 psz_bol++;
00233 }
00234
00235 if( !strncasecmp( psz_bol, "rtsp://", sizeof("rtsp://") - 1 ) )
00236 {
00237
00238 p_sys->psz_uri = strdup( psz_bol );
00239 }
00240 else if( !strncasecmp( psz_bol, "Stream=\"", sizeof("Stream=\"") - 1 ) )
00241 {
00242 psz_bol += sizeof("Stream=\"") - 1;
00243 if ( !psz_bol )
00244 return 0;
00245 strrchr( psz_bol, '"' )[0] = '\0';
00246
00247 if( !strncasecmp( psz_bol, "xdma://", sizeof("xdma://") - 1 ) )
00248 {
00249 psz_bol[0] = 'r';
00250 psz_bol[1] = 't';
00251 psz_bol[2] = 's';
00252 psz_bol[3] = 'p';
00253 }
00254 p_sys->psz_uri = strdup( psz_bol );
00255 }
00256 else if( !strncasecmp( psz_bol, "sgiNameServerHost=", sizeof("sgiNameServerHost=") - 1 ) )
00257 {
00258 psz_bol += sizeof("sgiNameServerHost=") - 1;
00259 p_sys->psz_server = strdup( psz_bol );
00260 }
00261 else if( !strncasecmp( psz_bol, "sgiMovieName=", sizeof("sgiMovieName=") - 1 ) )
00262 {
00263 psz_bol += sizeof("sgiMovieName=") - 1;
00264 p_sys->psz_location = strdup( psz_bol );
00265 }
00266 else if( !strncasecmp( psz_bol, "sgiUserAccount=", sizeof("sgiUserAccount=") - 1 ) )
00267 {
00268 psz_bol += sizeof("sgiUserAccount=") - 1;
00269 p_sys->psz_user = strdup( psz_bol );
00270 }
00271 else if( !strncasecmp( psz_bol, "sgiUserPassword=", sizeof("sgiUserPassword=") - 1 ) )
00272 {
00273 psz_bol += sizeof("sgiUserPassword=") - 1;
00274 p_sys->psz_password = strdup( psz_bol );
00275 }
00276 else if( !strncasecmp( psz_bol, "sgiShowingName=", sizeof("sgiShowingName=") - 1 ) )
00277 {
00278 psz_bol += sizeof("sgiShowingName=") - 1;
00279 p_sys->psz_name = strdup( psz_bol );
00280 }
00281 else if( !strncasecmp( psz_bol, "sgiFormatName=", sizeof("sgiFormatName=") - 1 ) )
00282 {
00283 psz_bol += sizeof("sgiFormatName=") - 1;
00284 if( strcasestr( psz_bol, "MPEG-4") == NULL )
00285 p_sys->b_rtsp_kasenna = VLC_TRUE;
00286 }
00287 else if( !strncasecmp( psz_bol, "sgiMulticastAddress=", sizeof("sgiMulticastAddress=") - 1 ) )
00288 {
00289 psz_bol += sizeof("sgiMulticastAddress=") - 1;
00290 p_sys->psz_mcast_ip = strdup( psz_bol );
00291 }
00292 else if( !strncasecmp( psz_bol, "sgiMulticastPort=", sizeof("sgiMulticastPort=") - 1 ) )
00293 {
00294 psz_bol += sizeof("sgiMulticastPort=") - 1;
00295 p_sys->i_mcast_port = (int) strtol( psz_bol, NULL, 0 );
00296 }
00297 else if( !strncasecmp( psz_bol, "sgiPacketSize=", sizeof("sgiPacketSize=") - 1 ) )
00298 {
00299 psz_bol += sizeof("sgiPacketSize=") - 1;
00300 p_sys->i_packet_size = (int) strtol( psz_bol, NULL, 0 );
00301 }
00302 else if( !strncasecmp( psz_bol, "sgiDuration=", sizeof("sgiDuration=") - 1 ) )
00303 {
00304 psz_bol += sizeof("sgiDuration=") - 1;
00305 p_sys->i_duration = (mtime_t) strtol( psz_bol, NULL, 0 );
00306 }
00307 else if( !strncasecmp( psz_bol, "sgiRtspPort=", sizeof("sgiRtspPort=") - 1 ) )
00308 {
00309 psz_bol += sizeof("sgiRtspPort=") - 1;
00310 p_sys->i_port = (int) strtol( psz_bol, NULL, 0 );
00311 }
00312 else if( !strncasecmp( psz_bol, "sgiSid=", sizeof("sgiSid=") - 1 ) )
00313 {
00314 psz_bol += sizeof("sgiSid=") - 1;
00315 p_sys->i_sid = (int) strtol( psz_bol, NULL, 0 );
00316 }
00317 else if( !strncasecmp( psz_bol, "DeliveryService=cds", sizeof("DeliveryService=cds") - 1 ) )
00318 {
00319 p_sys->b_concert = VLC_TRUE;
00320 }
00321 else
00322 {
00323
00324 return 0;
00325 }
00326 return VLC_SUCCESS;
00327 }
00328
00329
00330
00331
00332
00333
00334 static int Demux ( demux_t *p_demux )
00335 {
00336 demux_sys_t *p_sys = p_demux->p_sys;
00337 playlist_t *p_playlist;
00338 playlist_item_t *p_item;
00339 playlist_item_t *p_child;
00340
00341 char *psz_line;
00342
00343 p_playlist = (playlist_t *) vlc_object_find( p_demux, VLC_OBJECT_PLAYLIST,
00344 FIND_ANYWHERE );
00345 if( !p_playlist )
00346 {
00347 msg_Err( p_demux, "can't find playlist" );
00348 return -1;
00349 }
00350
00351 p_item = playlist_LockItemGetByInput( p_playlist,
00352 ((input_thread_t *)p_demux->p_parent)->input.p_item );
00353 playlist_ItemToNode( p_playlist, p_item );
00354
00355 while( ( psz_line = stream_ReadLine( p_demux->s ) ) )
00356 {
00357 ParseLine( p_demux, psz_line );
00358 if( psz_line ) free( psz_line );
00359 }
00360
00361 if( p_sys->psz_mcast_ip )
00362 {
00363
00364
00365 char *temp;
00366
00367 asprintf( &temp, "udp://@" "%s:%i", p_sys->psz_mcast_ip, p_sys->i_mcast_port );
00368 if( p_sys->psz_uri ) free( p_sys->psz_uri );
00369 p_sys->psz_uri = strdup( temp );
00370 free( temp );
00371 }
00372
00373 if( p_sys->psz_uri == NULL )
00374 {
00375 if( p_sys->psz_server && p_sys->psz_location )
00376 {
00377 char *temp;
00378
00379 asprintf( &temp, "rtsp://" "%s:%i%s",
00380 p_sys->psz_server, p_sys->i_port > 0 ? p_sys->i_port : 554, p_sys->psz_location );
00381
00382 p_sys->psz_uri = strdup( temp );
00383 free( temp );
00384 }
00385 }
00386
00387 if( p_sys->b_concert )
00388 {
00389
00390
00391 char *temp;
00392
00393 if( p_sys->psz_uri == NULL )
00394 {
00395 msg_Err( p_demux, "no URI was found" );
00396 return -1;
00397 }
00398
00399 asprintf( &temp, "%s%%3FMeDiAbAsEshowingId=%d%%26MeDiAbAsEconcert%%3FMeDiAbAsE",
00400 p_sys->psz_uri, p_sys->i_sid );
00401
00402 free( p_sys->psz_uri );
00403 p_sys->psz_uri = strdup( temp );
00404 free( temp );
00405 }
00406
00407 p_child = playlist_ItemNew( p_playlist, p_sys->psz_uri,
00408 p_sys->psz_name ? p_sys->psz_name : p_sys->psz_uri );
00409
00410 if( !p_child || !p_child->input.psz_uri )
00411 {
00412 msg_Err( p_demux, "A valid playlistitem could not be created" );
00413 return VLC_EGENERIC;
00414 }
00415
00416 if( p_sys->i_packet_size && p_sys->psz_mcast_ip )
00417 {
00418 char *psz_option;
00419 p_sys->i_packet_size += 1000;
00420 asprintf( &psz_option, "mtu=%i", p_sys->i_packet_size );
00421 playlist_ItemAddOption( p_child, psz_option );
00422 free( psz_option );
00423 }
00424 if( !p_sys->psz_mcast_ip )
00425 {
00426 char *psz_option;
00427 asprintf( &psz_option, "rtsp-caching=5000" );
00428 playlist_ItemAddOption( p_child, psz_option );
00429 free( psz_option );
00430 }
00431 if( !p_sys->psz_mcast_ip && p_sys->b_rtsp_kasenna )
00432 {
00433 char *psz_option;
00434 asprintf( &psz_option, "rtsp-kasenna" );
00435 playlist_ItemAddOption( p_child, psz_option );
00436 free( psz_option );
00437 }
00438
00439 playlist_ItemSetDuration( p_child, p_sys->i_duration );
00440 playlist_NodeAddItem( p_playlist, p_child, p_item->pp_parents[0]->i_view, p_item, PLAYLIST_APPEND, PLAYLIST_END );
00441 playlist_CopyParents( p_item, p_child );
00442 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
00443 p_playlist->status.i_view,
00444 p_playlist->status.p_item, NULL );
00445
00446 vlc_object_release( p_playlist );
00447 return VLC_SUCCESS;
00448 }
00449
00450 static int Control( demux_t *p_demux, int i_query, va_list args )
00451 {
00452 return VLC_EGENERIC;
00453 }
00454