]> git.sesse.net Git - vlc/blobdiff - modules/demux/livedotcom.cpp
* modules/demux/livedotcom.cpp: fixed segfaults.
[vlc] / modules / demux / livedotcom.cpp
index 3c0230f123c508ca298e495641d8a89f1f679131..cbad733e78e2f64ee75ecb93a84660710901a970 100644 (file)
@@ -174,6 +174,11 @@ static void StreamRead( void *, unsigned int, unsigned int,
 static void StreamClose( void * );
 static void TaskInterrupt( void * );
 
+#if LIVEMEDIA_LIBRARY_VERSION_INT >= 1117756800
+static unsigned char* parseH264ConfigStr( char const* configStr,
+                                          unsigned int& configSize );
+#endif
+
 /*****************************************************************************
  * DemuxOpen:
  *****************************************************************************/
@@ -198,8 +203,8 @@ static int  Open ( vlc_object_t *p_this )
            v, o, s fields are mandatory and in this order */
         if( stream_Peek( p_demux->s, &p_peek, 7 ) < 7 ) return VLC_EGENERIC;
 
-        if( strncmp( (char*)p_peek, "v=0\r\n", 5 ) &&
-            strncmp( (char*)p_peek, "v=0\n", 4 ) &&
+        if( memcmp( (char*)p_peek, "v=0\r\n", 5 ) &&
+            memcmp( (char*)p_peek, "v=0\n", 4 ) &&
             ( p_peek[0] < 'a' || p_peek[0] > 'z' || p_peek[1] != '=' ) )
         {
             return VLC_EGENERIC;
@@ -242,12 +247,11 @@ static int  Open ( vlc_object_t *p_this )
         goto error;
     }
 
-    if( strcasecmp( p_demux->psz_access, "sdp" ) && 
-       vlc_UrlIsNotEncoded( p_sys->psz_path ) )
+    if( strcasecmp( p_demux->psz_access, "sdp" ) )
     {
-        p_sys->psz_path = vlc_UrlEncode( p_sys->psz_path );
-        if( p_sys->psz_path == NULL )
-            goto error;
+        char *p = p_sys->psz_path;
+        while( (p = strchr( p, ' ' )) != NULL )
+            *p = '+';
     }
 
     if( p_demux->s == NULL && !strcasecmp( p_demux->psz_access, "rtsp" ) )
@@ -283,7 +287,7 @@ static int  Open ( vlc_object_t *p_this )
         /* malloc-ated copy */
         p_sys->p_sdp = strdup( (char*)p_sdp );
         delete[] p_sdp;
-        fprintf( stderr, "sdp=%s\n", p_sys->p_sdp );
+        msg_Dbg( p_demux, "sdp=%s\n", p_sys->p_sdp );
     }
     else if( p_demux->s == NULL && !strcasecmp( p_demux->psz_access, "sdp" ) )
     {
@@ -421,7 +425,7 @@ static int  Open ( vlc_object_t *p_this )
         {
             es_format_Init( &tk->fmt, AUDIO_ES, VLC_FOURCC('u','n','d','f') );
             tk->fmt.audio.i_channels = sub->numChannels();
-            tk->fmt.audio.i_rate = sub->rtpSource()->timestampFrequency();
+            tk->fmt.audio.i_rate = sub->rtpTimestampFrequency();
 
             if( !strcmp( sub->codecName(), "MPA" ) ||
                 !strcmp( sub->codecName(), "MPA-ROBUST" ) ||
@@ -453,6 +457,14 @@ static int  Open ( vlc_object_t *p_this )
             {
                 tk->fmt.i_codec = VLC_FOURCC( 'a', 'l', 'a', 'w' );
             }
+            else if( !strcmp( sub->codecName(), "AMR" ) )
+            {
+                tk->fmt.i_codec = VLC_FOURCC( 's', 'a', 'm', 'r' );
+            }
+            else if( !strcmp( sub->codecName(), "AMR-WB" ) )
+            {
+                tk->fmt.i_codec = VLC_FOURCC( 's', 'a', 'w', 'b' );
+            }
             else if( !strcmp( sub->codecName(), "MP4A-LATM" ) )
             {
                 unsigned int i_extra;
@@ -510,6 +522,28 @@ static int  Open ( vlc_object_t *p_this )
             {
                 tk->fmt.i_codec = VLC_FOURCC( 'H', '2', '6', '1' );
             }
+            else if( !strcmp( sub->codecName(), "H264" ) )
+            {
+#if LIVEMEDIA_LIBRARY_VERSION_INT >= 1117756800
+                unsigned int i_extra = 0;
+                uint8_t      *p_extra = NULL;
+#endif
+                tk->fmt.i_codec = VLC_FOURCC( 'H', '2', '6', '4' );
+                tk->fmt.b_packetized = VLC_FALSE;
+
+                /* XXX not the right minimal version I fear */
+#if LIVEMEDIA_LIBRARY_VERSION_INT >= 1117756800
+                if((p_extra=parseH264ConfigStr( sub->fmtp_spropparametersets(),
+                                                i_extra ) ) )
+                {
+                    tk->fmt.i_extra = i_extra;
+                    tk->fmt.p_extra = malloc( i_extra );
+                    memcpy( tk->fmt.p_extra, p_extra, i_extra );
+
+                    delete[] p_extra;
+                }
+#endif
+            }
             else if( !strcmp( sub->codecName(), "JPEG" ) )
             {
                 tk->fmt.i_codec = VLC_FOURCC( 'M', 'J', 'P', 'G' );
@@ -752,7 +786,7 @@ static int Demux( demux_t *p_demux )
         live_track_t *tk = p_sys->track[i];
 
         if( !tk->b_muxed && !tk->b_rtcp_sync &&
-            tk->rtpSource->hasBeenSynchronizedUsingRTCP() )
+            tk->rtpSource && tk->rtpSource->hasBeenSynchronizedUsingRTCP() )
         {
             msg_Dbg( p_demux, "tk->rtpSource->hasBeenSynchronizedUsingRTCP()" );
 
@@ -1140,7 +1174,7 @@ static void StreamRead( void *p_private, unsigned int i_size,
         msg_Warn( p_demux, "buffer overflow" );
     }
     /* FIXME could i_size be > buffer size ? */
-    if( tk->fmt.i_codec == VLC_FOURCC('h','2','6','1') )
+    if( tk->fmt.i_codec == VLC_FOURCC('H','2','6','1') )
     {
 #if LIVEMEDIA_LIBRARY_VERSION_INT >= 1081468800
         H261VideoRTPSource *h261Source = (H261VideoRTPSource*)tk->rtpSource;
@@ -1152,6 +1186,22 @@ static void StreamRead( void *p_private, unsigned int i_size,
         p_block = block_New( p_demux, i_size + 4 );
         memcpy( p_block->p_buffer, &header, 4 );
         memcpy( p_block->p_buffer + 4, tk->p_buffer, i_size );
+
+        if( tk->rtpSource->curPacketMarkerBit() )
+            p_block->i_flags |= BLOCK_FLAG_END_OF_FRAME;
+    }
+    else if( tk->fmt.i_codec == VLC_FOURCC('H','2','6','4') )
+    {
+        if( (tk->p_buffer[0] & 0x1f) >= 24 )
+            msg_Warn( p_demux, "unsupported NAL type for H264" );
+
+        /* Normal NAL type */
+        p_block = block_New( p_demux, i_size + 4 );
+        p_block->p_buffer[0] = 0x00;
+        p_block->p_buffer[1] = 0x00;
+        p_block->p_buffer[2] = 0x00;
+        p_block->p_buffer[3] = 0x01;
+        memcpy( &p_block->p_buffer[4], tk->p_buffer, i_size );
     }
     else if( tk->b_asf )
     {
@@ -1165,11 +1215,7 @@ static void StreamRead( void *p_private, unsigned int i_size,
         p_block = block_New( p_demux, i_size );
         memcpy( p_block->p_buffer, tk->p_buffer, i_size );
     }
-    if( tk->fmt.i_codec == VLC_FOURCC('h','2','6','1') &&
-        tk->rtpSource->curPacketMarkerBit() )
-    {
-        p_block->i_flags |= BLOCK_FLAG_END_OF_FRAME;
-    }
+
     //p_block->i_rate = p_input->stream.control.i_rate;
 
     if( i_pts != tk->i_pts && !tk->b_muxed )
@@ -1229,8 +1275,6 @@ static void TaskInterrupt( void *p_private )
 {
     demux_t *p_demux = (demux_t*)p_private;
 
-    fprintf( stderr, "TaskInterrupt\n" );
-
     p_demux->p_sys->i_no_data_ti++;
 
     /* Avoid lock */
@@ -1287,6 +1331,44 @@ static int ParseASF( demux_t *p_demux )
     free( psz_asf );
     return VLC_SUCCESS;
 }
+
+#if LIVEMEDIA_LIBRARY_VERSION_INT >= 1117756800
+static unsigned char* parseH264ConfigStr( char const* configStr,
+                                          unsigned int& configSize )
+{
+    char *dup, *psz;
+
+    if( configSize )
+    configSize = 0;
+
+    if( configStr == NULL || *configStr == '\0' )
+        return NULL;
+
+    psz = dup = strdup( configStr );
+
+    unsigned char *cfg = new unsigned char[5 * strlen(psz)];
+    for( ;; )
+    {
+        char *p = strchr( psz, ',' );
+        if( p )
+            *p++ = '\0';
+
+        cfg[configSize++] = 0x00;
+        cfg[configSize++] = 0x00;
+        cfg[configSize++] = 0x00;
+        cfg[configSize++] = 0x01;
+        configSize += b64_decode( (char*)&cfg[configSize], psz );
+
+        if( p == NULL )
+            break;
+        psz = p;
+    }
+
+    if( dup ) free( dup );
+    return cfg;
+}
+#endif
+
 /*char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";*/
 static int b64_decode( char *dest, char *src )
 {