Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

sgimb.c

00001 /*****************************************************************************
00002  * sgimb.c: a meta demux to parse sgimb referrer files
00003  *****************************************************************************
00004  * Copyright (C) 2004 the VideoLAN team
00005  * $Id: sgimb.c 12229 2005-08-18 15:14:02Z jpsaman $
00006  *
00007  * Authors: Derk-Jan Hartman <hartman at videolan dot org>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * This is a metademux for the Kasenna MediaBase metafile format.
00026  * Kasenna MediaBase first returns this file when you are trying to access
00027  * their MPEG streams (MIME: application/x-sgimb). Very few applications
00028  * understand this format and the format is not really documented on the net.
00029  * Following a typical MediaBase file. Notice the sgi prefix of all the elements.
00030  * This stems from the fact that the MediaBase servers were first introduced by SGI?????.
00031  *
00032  * sgiNameServerHost=host.name.tld
00033  *     Obvious: the host hosting this stream
00034  * Stream="xdma://host.name.tld/demo/a_very_cool.mpg"
00035  *     Not always present. xdma can be read as RTSP.
00036  * sgiMovieName=/demo/a_very_cool.mpg
00037  *     The path to the asset
00038  * sgiAuxState=1|2
00039  *     AuxState=2 is always Video On Demand (so not Scheduled)
00040  *     Not present with Live streams
00041  * sgiLiveFeed=True|False
00042  *     Denounces if the stream is live or from assets (Canned?)
00043  *     Live appears as a little sattelite dish in the web interface of Kasenna
00044  * sgiFormatName=PARTNER_41_MPEG-4
00045  *     The type of stream. One of:
00046  *       PARTNER_41_MPEG-4 (RTSP MPEG-4 fully compliant)
00047  *       MPEG1-Audio       (MP3 Audio streams in MPEG TS)
00048  *       MPEG-1            (MPEG 1 A/V in MPEG TS)
00049  *       MPEG-2            (MPEG 2 A/V in MPEG TS)
00050  * sgiWidth=720
00051  *     The width of the to be received stream. Only present if stream is not Live.
00052  * sgiHeight=576
00053  *     The height of the to be received stream. Only present if stream is not Live.
00054  * sgiBitrate=1630208
00055  *     The bitrate of the to be received stream. Only present if stream is not Live.
00056  * sgiDuration=378345000
00057  *     The duration of the to be received stream. Only present if stream is not Live.
00058  * sgiQTFileBegin
00059  * rtsptext
00060  * rtsp://host.name.tld/demo/a_very_cool.mpg
00061  * sgiQTFileEnd
00062  *     Sometimes present. QT will recognize this as a RTSP reference file, if present.
00063  * sgiApplicationName=MediaBaseURL
00064  *     Beats me !! :)
00065  * sgiElapsedTime=0
00066  *     Time passed since the asset was started (resets for repeating non live assets?)
00067  * sgiMulticastAddress=233.81.233.15
00068  *     The multicast IP used for the Multicast feed.
00069  *     Also defines if a stream is multicast or not. (blue dot in kasenna web interface)
00070  * sgiMulticastPort=1234
00071  *     The multicast port for the same Multicast feed.
00072  * sgiPacketSize=16384
00073  *     The packetsize of the UDP frames that Kasenna sends. They should have used a default
00074  *     that is a multiple of 188 (TS frame size). Most networks don't support more than 1500 anyways.
00075  *     Also, when you loose a frame of this size, imagecorruption is more likely then with smaller
00076  *     frames.
00077  * sgiServerVersion=6.1.2
00078  *     Version of the server
00079  * sgiRtspPort=554
00080  *     TCP port used for RTSP communication
00081  * AutoStart=True
00082  *     Start playing automatically
00083  * DeliveryService=cds
00084  *     Simulcasted (scheduled unicast) content. (Green dot in Kasenna web interface) 
00085  * sgiShowingName=A nice name that everyone likes
00086  *     A human readible descriptive title for this stream.
00087  * sgiSid=2311
00088  *     Looks like this is the ID of the scheduled asset?
00089  * sgiUserAccount=pid=1724&time=1078527309&displayText=You%20are%20logged%20as%20guest&
00090  *     User Authentication. Above is a default guest entry. Not required for RTSP communication.
00091  * sgiUserPassword=
00092  *     Password :)
00093  *
00094  *****************************************************************************/
00095 
00096 
00097 /*****************************************************************************
00098  * Preamble
00099  *****************************************************************************/
00100 #include <stdlib.h>                                      /* malloc(), free() */
00101 
00102 #include <vlc/vlc.h>
00103 #include <vlc/input.h>
00104 #include <vlc_playlist.h>
00105 
00106 /*****************************************************************************
00107  * Module descriptor
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  * Local prototypes
00123  *****************************************************************************/
00124 #define MAX_LINE 1024
00125 
00126 struct demux_sys_t
00127 {
00128     char        *psz_uri;       /* Stream= or sgiQTFileBegin rtsp link */
00129     char        *psz_server;    /* sgiNameServerHost= */
00130     char        *psz_location;  /* sgiMovieName= */
00131     char        *psz_name;      /* sgiShowingName= */
00132     char        *psz_user;      /* sgiUserAccount= */
00133     char        *psz_password;  /* sgiUserPassword= */
00134     char        *psz_mcast_ip;  /* sgiMulticastAddress= */
00135     int         i_mcast_port;   /* sgiMulticastPort= */
00136     int         i_packet_size;  /* sgiPacketSize= */
00137     mtime_t     i_duration;     /* sgiDuration= */
00138     int         i_port;         /* sgiRtspPort= */
00139     int         i_sid;          /* sgiSid= */
00140     vlc_bool_t  b_concert;      /* DeliveryService=cds */
00141     vlc_bool_t  b_rtsp_kasenna; /* kasenna style RTSP */
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  * Activate: initializes m3u demux structures
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     /* Lets check the content to see if this is a sgi mediabase file */
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  * Deactivate: frees unused data
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     /* Remove unnecessary tabs or spaces at the beginning of line */
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         /* We found the link, it was inside a sgiQTFileBegin */
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         /* We cheat around xdma. for some reason xdma links work different then rtsp */
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 ) /*not mpeg4 found in string */
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         /* This line isn't really important */
00324         return 0;
00325     }
00326     return VLC_SUCCESS;
00327 }
00328 
00329 /*****************************************************************************
00330  * Demux: reads and demuxes data packets
00331  *****************************************************************************
00332  * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
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         /* Definetly schedules multicast session */
00364         /* We don't care if it's live or not */
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         /* It's definetly a simulcasted scheduled stream */
00390         /* We don't care if it's live or not */
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 

Generated on Tue Dec 20 10:14:35 2005 for vlc-0.8.4a by  doxygen 1.4.2