[vlc-commits] demux: avformat: fix regression with tracks

Francois Cartegnie git at videolan.org
Wed Mar 7 17:39:27 CET 2018


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Mar  7 17:32:51 2018 +0100| [416531c3b0aa176ecd0bb8029d2825ba62bb977f] | committer: Francois Cartegnie

demux: avformat: fix regression with tracks

We can't trust nb_streams while demuxing, new
tracks can be created. (and even if the documentation
says it does only when it has no header)

(cherry picked from commit 33dcfcf41340c27b6f8183fdb35b129282a79bd8)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=416531c3b0aa176ecd0bb8029d2825ba62bb977f
---

 modules/demux/avformat/demux.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/demux.c
index 14033c71f1..60a3a940b8 100644
--- a/modules/demux/avformat/demux.c
+++ b/modules/demux/avformat/demux.c
@@ -67,6 +67,7 @@ struct demux_sys_t
     AVFormatContext *ic;
 
     struct avformat_track_s *tracks;
+    unsigned i_tracks;
 
     int64_t         i_pcr;
 
@@ -366,6 +367,7 @@ int avformat_OpenDemux( vlc_object_t *p_this )
         avformat_CloseDemux( p_this );
         return VLC_ENOMEM;
     }
+    p_sys->i_tracks = nb_streams;
 
     if( error < 0 )
     {
@@ -743,7 +745,7 @@ static int Demux( demux_t *p_demux )
 
         return 0;
     }
-    if( pkt.stream_index < 0 || (unsigned) pkt.stream_index >= p_sys->ic->nb_streams )
+    if( pkt.stream_index < 0 || (unsigned) pkt.stream_index >= p_sys->i_tracks )
     {
         av_packet_unref( &pkt );
         return 1;
@@ -854,14 +856,14 @@ static int Demux( demux_t *p_demux )
         p_track->i_pcr = p_frame->i_dts;
 
     int64_t i_ts_max = INT64_MIN;
-    for( unsigned i = 0; i < p_sys->ic->nb_streams; i++ )
+    for( unsigned i = 0; i < p_sys->i_tracks; i++ )
     {
         if( p_sys->tracks[i].p_es != NULL )
             i_ts_max = __MAX( i_ts_max, p_sys->tracks[i].i_pcr );
     }
 
     int64_t i_ts_min = INT64_MAX;
-    for( unsigned i = 0; i < p_sys->ic->nb_streams; i++ )
+    for( unsigned i = 0; i < p_sys->i_tracks; i++ )
     {
         if( p_sys->tracks[i].p_es != NULL &&
                 p_sys->tracks[i].i_pcr > VLC_TS_INVALID &&
@@ -916,7 +918,7 @@ static void ResetTime( demux_t *p_demux, int64_t i_time )
         i_time = 1;
 
     p_sys->i_pcr = i_time;
-    for( unsigned i = 0; i < p_sys->ic->nb_streams; i++ )
+    for( unsigned i = 0; i < p_sys->i_tracks; i++ )
         p_sys->tracks[i].i_pcr = VLC_TS_INVALID;
 
     if( i_time > VLC_TS_INVALID )



More information about the vlc-commits mailing list