]> git.sesse.net Git - vlc/blobdiff - modules/demux/playlist/sgimb.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / modules / demux / playlist / sgimb.c
index f244f9727e783990f60c1800934c22ce6c97bad9..07065db66422adb511421c0774cadb912b7463ea 100644 (file)
@@ -81,7 +81,7 @@
  * AutoStart=True
  *     Start playing automatically
  * DeliveryService=cds
- *     Simulcasted (scheduled unicast) content. (Green dot in Kasenna web interface) 
+ *     Simulcasted (scheduled unicast) content. (Green dot in Kasenna web interface)
  * sgiShowingName=A nice name that everyone likes
  *     A human readible descriptive title for this stream.
  * sgiSid=2311
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#define _GNU_SOURCE
-#include <stdlib.h>                                      /* malloc(), free() */
 
-#include <vlc/vlc.h>
-#include <vlc/input.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_demux.h>
 #include "playlist.h"
 
 /*****************************************************************************
@@ -123,8 +125,8 @@ struct demux_sys_t
     mtime_t     i_duration;     /* sgiDuration= */
     int         i_port;         /* sgiRtspPort= */
     int         i_sid;          /* sgiSid= */
-    vlc_bool_t  b_concert;      /* DeliveryService=cds */
-    vlc_bool_t  b_rtsp_kasenna; /* kasenna style RTSP */
+    bool  b_concert;      /* DeliveryService=cds */
+    bool  b_rtsp_kasenna; /* kasenna style RTSP */
 };
 
 static int Demux ( demux_t *p_demux );
@@ -133,10 +135,10 @@ static int Control( demux_t *p_demux, int i_query, va_list args );
 /*****************************************************************************
  * Activate: initializes m3u demux structures
  *****************************************************************************/
-int E_(Import_SGIMB)( vlc_object_t * p_this )
+int Import_SGIMB( vlc_object_t * p_this )
 {
     demux_t *p_demux = (demux_t *)p_this;
-    byte_t *p_peek;
+    const uint8_t *p_peek;
     int i_size;
 
     /* Lets check the content to see if this is a sgi mediabase file */
@@ -165,9 +167,9 @@ int E_(Import_SGIMB)( vlc_object_t * p_this )
             p_demux->p_sys->i_duration = 0;
             p_demux->p_sys->i_port = 0;
             p_demux->p_sys->i_sid = 0;
-            p_demux->p_sys->b_rtsp_kasenna = VLC_FALSE;
-            p_demux->p_sys->b_concert = VLC_FALSE;
-            
+            p_demux->p_sys->b_rtsp_kasenna = false;
+            p_demux->p_sys->b_concert = false;
+
             return VLC_SUCCESS;
         }
     }
@@ -177,24 +179,17 @@ int E_(Import_SGIMB)( vlc_object_t * p_this )
 /*****************************************************************************
  * Deactivate: frees unused data
  *****************************************************************************/
-void E_(Close_SGIMB)( vlc_object_t *p_this )
+void Close_SGIMB( vlc_object_t *p_this )
 {
     demux_t *p_demux = (demux_t*)p_this;
     demux_sys_t *p_sys = p_demux->p_sys;
-    if( p_sys->psz_uri )
-        free( p_sys->psz_uri );
-    if( p_sys->psz_server )
-        free( p_sys->psz_server );
-    if( p_sys->psz_location )
-        free( p_sys->psz_location );
-    if( p_sys->psz_name )
-        free( p_sys->psz_name );
-    if( p_sys->psz_user )
-        free( p_sys->psz_user );
-    if( p_sys->psz_password )
-        free( p_sys->psz_password );
-    if( p_sys->psz_mcast_ip )
-        free( p_sys->psz_mcast_ip );
+    free( p_sys->psz_uri );
+    free( p_sys->psz_server );
+    free( p_sys->psz_location );
+    free( p_sys->psz_name );
+    free( p_sys->psz_user );
+    free( p_sys->psz_password );
+    free( p_sys->psz_mcast_ip );
     free( p_demux->p_sys );
     return;
 }
@@ -216,6 +211,7 @@ static int ParseLine ( demux_t *p_demux, char *psz_line )
     if( !strncasecmp( psz_bol, "rtsp://", sizeof("rtsp://") - 1 ) )
     {
         /* We found the link, it was inside a sgiQTFileBegin */
+        free( p_sys->psz_uri );
         p_sys->psz_uri = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "Stream=\"", sizeof("Stream=\"") - 1 ) )
@@ -223,7 +219,10 @@ static int ParseLine ( demux_t *p_demux, char *psz_line )
         psz_bol += sizeof("Stream=\"") - 1;
         if ( !psz_bol )
             return 0;
-        strrchr( psz_bol, '"' )[0] = '\0';
+        char* psz_tmp = strrchr( psz_bol, '"' );
+        if( !psz_tmp )
+            return 0;
+        psz_tmp[0] = '\0';
         /* We cheat around xdma. for some reason xdma links work different then rtsp */
         if( !strncasecmp( psz_bol, "xdma://", sizeof("xdma://") - 1 ) )
         {
@@ -232,42 +231,49 @@ static int ParseLine ( demux_t *p_demux, char *psz_line )
             psz_bol[2] = 's';
             psz_bol[3] = 'p';
         }
+        free( p_sys->psz_uri );
         p_sys->psz_uri = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "sgiNameServerHost=", sizeof("sgiNameServerHost=") - 1 ) )
     {
         psz_bol += sizeof("sgiNameServerHost=") - 1;
+        free( p_sys->psz_server );
         p_sys->psz_server = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "sgiMovieName=", sizeof("sgiMovieName=") - 1 ) )
     {
         psz_bol += sizeof("sgiMovieName=") - 1;
+        free( p_sys->psz_location );
         p_sys->psz_location = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "sgiUserAccount=", sizeof("sgiUserAccount=") - 1 ) )
     {
         psz_bol += sizeof("sgiUserAccount=") - 1;
+        free( p_sys->psz_user );
         p_sys->psz_user = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "sgiUserPassword=", sizeof("sgiUserPassword=") - 1 ) )
     {
         psz_bol += sizeof("sgiUserPassword=") - 1;
+        free( p_sys->psz_password );
         p_sys->psz_password = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "sgiShowingName=", sizeof("sgiShowingName=") - 1 ) )
     {
         psz_bol += sizeof("sgiShowingName=") - 1;
+        free( p_sys->psz_name );
         p_sys->psz_name = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "sgiFormatName=", sizeof("sgiFormatName=") - 1 ) )
     {
         psz_bol += sizeof("sgiFormatName=") - 1;
         if( strcasestr( psz_bol, "MPEG-4") == NULL ) /*not mpeg4 found in string */
-            p_sys->b_rtsp_kasenna = VLC_TRUE;
+            p_sys->b_rtsp_kasenna = true;
     }
     else if( !strncasecmp( psz_bol, "sgiMulticastAddress=", sizeof("sgiMulticastAddress=") - 1 ) )
     {
         psz_bol += sizeof("sgiMulticastAddress=") - 1;
+        free( p_sys->psz_mcast_ip );
         p_sys->psz_mcast_ip = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "sgiMulticastPort=", sizeof("sgiMulticastPort=") - 1 ) )
@@ -297,7 +303,7 @@ static int ParseLine ( demux_t *p_demux, char *psz_line )
     }
     else if( !strncasecmp( psz_bol, "DeliveryService=cds", sizeof("DeliveryService=cds") - 1 ) )
     {
-        p_sys->b_concert = VLC_TRUE;
+        p_sys->b_concert = true;
     }
     else
     {
@@ -318,37 +324,36 @@ static int Demux ( demux_t *p_demux )
     input_item_t    *p_child = NULL;
     char            *psz_line;
 
-    INIT_PLAYLIST_STUFF;
+    input_item_t *p_current_input = GetCurrentItem(p_demux);
 
     while( ( psz_line = stream_ReadLine( p_demux->s ) ) )
     {
         ParseLine( p_demux, psz_line );
-        if( psz_line ) free( psz_line );
+        free( psz_line );
     }
 
     if( p_sys->psz_mcast_ip )
     {
         /* Definetly schedules multicast session */
         /* We don't care if it's live or not */
-        char *temp;
-
-        asprintf( &temp, "udp://@" "%s:%i", p_sys->psz_mcast_ip, p_sys->i_mcast_port );
-        if( p_sys->psz_uri ) free( p_sys->psz_uri );
-        p_sys->psz_uri = strdup( temp );
-        free( temp );
+        free( p_sys->psz_uri );
+        if( asprintf( &p_sys->psz_uri, "udp://@" "%s:%i", p_sys->psz_mcast_ip, p_sys->i_mcast_port ) == -1 )
+        {
+            p_sys->psz_uri = NULL;
+            return -1;
+        }
     }
 
     if( p_sys->psz_uri == NULL )
     {
         if( p_sys->psz_server && p_sys->psz_location )
         {
-            char *temp;
-
-            asprintf( &temp, "rtsp://" "%s:%i%s",
-                     p_sys->psz_server, p_sys->i_port > 0 ? p_sys->i_port : 554, p_sys->psz_location );
-
-            p_sys->psz_uri = strdup( temp );
-            free( temp );
+            if( asprintf( &p_sys->psz_uri, "rtsp://" "%s:%i%s",
+                     p_sys->psz_server, p_sys->i_port > 0 ? p_sys->i_port : 554, p_sys->psz_location ) == -1 )
+            {
+                p_sys->psz_uri = NULL;
+                return -1;
+            }
         }
     }
 
@@ -356,65 +361,56 @@ static int Demux ( demux_t *p_demux )
     {
         /* It's definetly a simulcasted scheduled stream */
         /* We don't care if it's live or not */
-        char *temp;
-
         if( p_sys->psz_uri == NULL )
         {
             msg_Err( p_demux, "no URI was found" );
             return -1;
         }
 
-        asprintf( &temp, "%s%%3FMeDiAbAsEshowingId=%d%%26MeDiAbAsEconcert%%3FMeDiAbAsE",
-                p_sys->psz_uri, p_sys->i_sid );
-
         free( p_sys->psz_uri );
-        p_sys->psz_uri = strdup( temp );
-        free( temp );
+        if( asprintf( &p_sys->psz_uri, "%s%%3FMeDiAbAsEshowingId=%d%%26MeDiAbAsEconcert%%3FMeDiAbAsE",
+                p_sys->psz_uri, p_sys->i_sid ) == -1 )
+        {
+            p_sys->psz_uri = NULL;
+            return -1;
+        }
     }
 
-    p_child = input_ItemNewWithType( (vlc_object_t *)p_playlist, p_sys->psz_uri,
+    p_child = input_item_NewWithType( VLC_OBJECT(p_demux), p_sys->psz_uri,
                       p_sys->psz_name ? p_sys->psz_name : p_sys->psz_uri,
-                      0, NULL, p_sys->i_duration, ITEM_TYPE_NET );
-    
+                      0, NULL, 0, p_sys->i_duration, ITEM_TYPE_NET );
+
     if( !p_child )
     {
         msg_Err( p_demux, "A valid playlistitem could not be created" );
-        return VLC_EGENERIC;
+        return -1;
     }
 
-    input_ItemCopyOptions( p_current->p_input, p_child );
+    input_item_CopyOptions( p_current_input, p_child );
     if( p_sys->i_packet_size && p_sys->psz_mcast_ip )
     {
         char *psz_option;
         p_sys->i_packet_size += 1000;
-        asprintf( &psz_option, "mtu=%i", p_sys->i_packet_size );
-        input_ItemAddOption( p_child, psz_option );
-        free( psz_option );
+        if( asprintf( &psz_option, "mtu=%i", p_sys->i_packet_size ) != -1 )
+        {
+            input_item_AddOption( p_child, psz_option, VLC_INPUT_OPTION_TRUSTED );
+            free( psz_option );
+        }
     }
     if( !p_sys->psz_mcast_ip )
-    {
-        char *psz_option;
-        asprintf( &psz_option, "rtsp-caching=5000" );
-        input_ItemAddOption( p_child, psz_option );
-        free( psz_option );
-    }
+        input_item_AddOption( p_child, "rtsp-caching=5000", VLC_INPUT_OPTION_TRUSTED );
     if( !p_sys->psz_mcast_ip && p_sys->b_rtsp_kasenna )
-    {
-        char *psz_option;
-        asprintf( &psz_option, "rtsp-kasenna" );
-        input_ItemAddOption( p_child, psz_option );
-        free( psz_option );
-    }
+        input_item_AddOption( p_child, "rtsp-kasenna", VLC_INPUT_OPTION_TRUSTED );
 
-    playlist_BothAddInput( p_playlist, p_child, p_item_in_category,
-                           PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_END,
-                           NULL, NULL);
-    HANDLE_PLAY_AND_RELEASE
-    return -1; /* Needed for correct operation of go back */
+    input_item_PostSubItem( p_current_input, p_child );
+    vlc_gc_decref( p_child );
+    vlc_gc_decref(p_current_input);
+    return 0; /* Needed for correct operation of go back */
 }
 
 static int Control( demux_t *p_demux, int i_query, va_list args )
 {
+    VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
     return VLC_EGENERIC;
 }