[vlc-commits] stream_filter: smooth: some streamindex have no fragments (fix #11377)

Francois Cartegnie git at videolan.org
Thu May 1 16:40:43 CEST 2014


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu May  1 14:41:39 2014 +0200| [839d173030838a61351331438dbbfc6bb7fa7487] | committer: Francois Cartegnie

stream_filter: smooth: some streamindex have no fragments (fix #11377)

SteamIndex for Chapters have no stream, then no qlevels

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=839d173030838a61351331438dbbfc6bb7fa7487
---

 modules/stream_filter/smooth/downloader.c |   50 ++++++++++---------
 modules/stream_filter/smooth/smooth.c     |   76 ++++++++++++++++++++++-------
 modules/stream_filter/smooth/utils.c      |    3 +-
 3 files changed, 88 insertions(+), 41 deletions(-)

diff --git a/modules/stream_filter/smooth/downloader.c b/modules/stream_filter/smooth/downloader.c
index a1291ef..4e43b5b 100644
--- a/modules/stream_filter/smooth/downloader.c
+++ b/modules/stream_filter/smooth/downloader.c
@@ -328,25 +328,28 @@ static int build_smoo_box( stream_t *s, uint8_t *smoo_box )
 
         quality_level_t * qlvl = get_qlevel( sms, sms->download_qlvl );
 
-        FourCC = qlvl->FourCC ? qlvl->FourCC : sms->default_FourCC;
-        ((uint32_t *)stra_box)[16] = bswap32( FourCC );
-        ((uint32_t *)stra_box)[17] = bswap32( qlvl->Bitrate );
-        ((uint32_t *)stra_box)[18] = bswap32( qlvl->MaxWidth );
-        ((uint32_t *)stra_box)[19] = bswap32( qlvl->MaxHeight );
-        ((uint32_t *)stra_box)[20] = bswap32( qlvl->SamplingRate );
-        ((uint32_t *)stra_box)[21] = bswap32( qlvl->Channels );
-        ((uint32_t *)stra_box)[22] = bswap32( qlvl->BitsPerSample );
-        ((uint32_t *)stra_box)[23] = bswap32( qlvl->AudioTag );
-        ((uint16_t *)stra_box)[48] = bswap16( qlvl->nBlockAlign );
-
-        if( !qlvl->CodecPrivateData )
-            continue;
-        stra_box[98] = stra_box[99] = stra_box[100] = 0; /* reserved */
-        assert( strlen( qlvl->CodecPrivateData ) < 512 );
-        stra_box[101] = strlen( qlvl->CodecPrivateData ) / 2;
-        uint8_t *binary_cpd = decode_string_hex_to_binary( qlvl->CodecPrivateData );
-        memcpy( stra_box + 102, binary_cpd, stra_box[101] );
-        free( binary_cpd );
+        if ( qlvl )
+        {
+            FourCC = qlvl->FourCC ? qlvl->FourCC : sms->default_FourCC;
+            ((uint32_t *)stra_box)[16] = bswap32( FourCC );
+            ((uint32_t *)stra_box)[17] = bswap32( qlvl->Bitrate );
+            ((uint32_t *)stra_box)[18] = bswap32( qlvl->MaxWidth );
+            ((uint32_t *)stra_box)[19] = bswap32( qlvl->MaxHeight );
+            ((uint32_t *)stra_box)[20] = bswap32( qlvl->SamplingRate );
+            ((uint32_t *)stra_box)[21] = bswap32( qlvl->Channels );
+            ((uint32_t *)stra_box)[22] = bswap32( qlvl->BitsPerSample );
+            ((uint32_t *)stra_box)[23] = bswap32( qlvl->AudioTag );
+            ((uint16_t *)stra_box)[48] = bswap16( qlvl->nBlockAlign );
+
+            if( !qlvl->CodecPrivateData )
+                continue;
+            stra_box[98] = stra_box[99] = stra_box[100] = 0; /* reserved */
+            assert( strlen( qlvl->CodecPrivateData ) < 512 );
+            stra_box[101] = strlen( qlvl->CodecPrivateData ) / 2;
+            uint8_t *binary_cpd = decode_string_hex_to_binary( qlvl->CodecPrivateData );
+            memcpy( stra_box + 102, binary_cpd, stra_box[101] );
+            free( binary_cpd );
+        }
     }
 
     return VLC_SUCCESS;
@@ -598,7 +601,7 @@ void* sms_Thread( void *p_this )
     for( int i = 0; i < 3; i++ )
     {
         sms = SMS_GET_SELECTED_ST( index_to_es_cat( i ) );
-        if( sms )
+        if( sms && vlc_array_count( sms->chunks ) )
         {
             chunk = vlc_array_item_at_index( sms->chunks, 0 );
             p_sys->download.lead[i] = chunk->start_time + p_sys->timescale / 1000;
@@ -676,8 +679,11 @@ void* sms_Thread( void *p_this )
         vlc_mutex_unlock( &p_sys->download.lock_wait );
 
         sms = SMS_GET_SELECTED_ST( next_track( s ) );
-        if( Download( s, sms ) != VLC_SUCCESS )
-            goto cancel;
+        if ( vlc_array_count( sms->chunks ) )
+        {
+            if( Download( s, sms ) != VLC_SUCCESS )
+                goto cancel;
+        }
     }
 
 cancel:
diff --git a/modules/stream_filter/smooth/smooth.c b/modules/stream_filter/smooth/smooth.c
index 0199035..cf268fe 100644
--- a/modules/stream_filter/smooth/smooth.c
+++ b/modules/stream_filter/smooth/smooth.c
@@ -172,12 +172,15 @@ static int parse_Manifest( stream_t *s )
                         p_sys->timescale = TIMESCALE;
                 }
 
-
                 if( !strcmp( node, "StreamIndex" ) )
                 {
                     sms = sms_New();
                     if( unlikely( !sms ) )
+                    {
+                        xml_ReaderDelete( vlc_reader );
+                        xml_Delete( vlc_xml );
                         return VLC_ENOMEM;
+                    }
                     sms->id = next_track_id;
                     next_track_id++;
 
@@ -225,15 +228,21 @@ static int parse_Manifest( stream_t *s )
                         else if( sms->type == SPU_ES )
                             sms->name = strdup( "text" );
                     }
-
-                    vlc_array_append( p_sys->sms_streams, sms );
                 }
 
                 if( !strcmp( node, "QualityLevel" ) )
                 {
+                    if ( !sms )
+                        break;
+
                     ql = ql_New();
                     if( !ql )
+                    {
+                        sms_Free( sms );
+                        xml_ReaderDelete( vlc_reader );
+                        xml_Delete( vlc_xml );
                         return VLC_ENOMEM;
+                    }
                     ql->id = next_qid;
                     next_qid++;
                     while( (name = xml_ReaderNextAttr( vlc_reader, &value )) )
@@ -275,11 +284,21 @@ static int parse_Manifest( stream_t *s )
                         if( !strcmp( name, "BitsPerSample" ) )
                             ql->BitsPerSample = strtoul( value, NULL, 10 );
                     }
+
                     vlc_array_append( sms->qlevels, ql );
                 }
 
+                if ( !strcmp( node, "Content" ) && sms && !sms->url_template )
+                {
+                    /* empty(@Url) && ./Content == manifest embedded content */
+                    sms_Free( sms );
+                    sms = NULL;
+                }
+
                 if( !strcmp( node, "c" ) )
                 {
+                    if ( !sms )
+                        break;
                     loop_count++;
                     start_time = duration = -1;
                     while( (name = xml_ReaderNextAttr( vlc_reader, &value )) )
@@ -327,6 +346,9 @@ static int parse_Manifest( stream_t *s )
                     if( unlikely( chunk_New( sms, computed_duration,
                                         computed_start_time ) == NULL ) )
                     {
+                        sms_Free( sms );
+                        xml_ReaderDelete( vlc_reader );
+                        xml_Delete( vlc_xml );
                         return VLC_ENOMEM;
                     }
                     if( b_weird && start_time != -1 )
@@ -338,17 +360,29 @@ static int parse_Manifest( stream_t *s )
                 if( strcmp( node, "StreamIndex" ) )
                     break;
 
-                computed_start_time = 0;
-                computed_duration = 0;
-                loop_count = 0;
-                if( b_weird && !chunk_New( sms, computed_duration, computed_start_time ) )
-                    return VLC_ENOMEM;
+                if ( sms )
+                {
+                    vlc_array_append( p_sys->sms_streams, sms );
 
-                b_weird = false;
-                next_qid = 1;
+                    computed_start_time = 0;
+                    computed_duration = 0;
+                    loop_count = 0;
+                    if( b_weird && !chunk_New( sms, computed_duration, computed_start_time ) )
+                    {
+                        sms_Free( sms );
+                        xml_ReaderDelete( vlc_reader );
+                        xml_Delete( vlc_xml );
+                        return VLC_ENOMEM;
+                    }
 
-                if( sms->qlevel_nb == 0 )
-                    sms->qlevel_nb = vlc_array_count( sms->qlevels );
+                    b_weird = false;
+                    next_qid = 1;
+
+                    if( sms->qlevel_nb == 0 )
+                        sms->qlevel_nb = vlc_array_count( sms->qlevels );
+
+                    sms = NULL;
+                }
                 break;
 
             case XML_READER_NONE:
@@ -356,6 +390,9 @@ static int parse_Manifest( stream_t *s )
             case XML_READER_TEXT:
                 break;
             default:
+                sms_Free( sms );
+                xml_ReaderDelete( vlc_reader );
+                xml_Delete( vlc_xml );
                 return VLC_EGENERIC;
         }
     }
@@ -437,14 +474,17 @@ static int Open( vlc_object_t *p_this )
     {
         wanted = qlvl = NULL;
         sms = vlc_array_item_at_index( p_sys->sms_streams, i );
-        wanted = vlc_array_item_at_index( sms->qlevels, 0 );
-        for( unsigned i=1; i < sms->qlevel_nb; i++ )
+        if ( vlc_array_count( sms->qlevels ) )
         {
-            qlvl = vlc_array_item_at_index( sms->qlevels, i );
-            if( qlvl->Bitrate < wanted->Bitrate )
-                wanted = qlvl;
+            wanted = vlc_array_item_at_index( sms->qlevels, 0 );
+            for( unsigned i=1; i < sms->qlevel_nb; i++ )
+            {
+                qlvl = vlc_array_item_at_index( sms->qlevels, i );
+                if( qlvl->Bitrate < wanted->Bitrate )
+                    wanted = qlvl;
+            }
+            sms->download_qlvl = wanted->id;
         }
-        sms->download_qlvl = wanted->id;
     }
 
     vlc_mutex_init( &p_sys->download.lock_wait );
diff --git a/modules/stream_filter/smooth/utils.c b/modules/stream_filter/smooth/utils.c
index 5c180dc..9329102 100644
--- a/modules/stream_filter/smooth/utils.c
+++ b/modules/stream_filter/smooth/utils.c
@@ -115,6 +115,8 @@ sms_stream_t * sms_New( void )
 
 void sms_Free( sms_stream_t *sms )
 {
+    if ( !sms )
+        return;
     if( sms->qlevels )
     {
         for( int n = 0; n < vlc_array_count( sms->qlevels ); n++ )
@@ -138,7 +140,6 @@ void sms_Free( sms_stream_t *sms )
     free( sms->name );
     free( sms->url_template );
     free( sms );
-    sms = NULL;
 }
 
 quality_level_t *get_qlevel( sms_stream_t *sms, const unsigned qid )



More information about the vlc-commits mailing list