[vlc-commits] [Git][videolan/vlc][master] 8 commits: demux: ogg: dont use negative values in date_t

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Aug 31 13:50:56 UTC 2022



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
69cada6a by Francois Cartegnie at 2022-08-31T13:07:45+00:00
demux: ogg: dont use negative values in date_t

- - - - -
d06a185b by Francois Cartegnie at 2022-08-31T13:07:45+00:00
demux: ogg: fix bogus blocksize on vorbis headers

returning negative error on these

- - - - -
fd62f66b by Francois Cartegnie at 2022-08-31T13:07:45+00:00
demux: ogg: fix first page position when not directly audio data

- - - - -
19e5ec79 by Francois Cartegnie at 2022-08-31T13:07:45+00:00
demux: ogg: fix error code check

- - - - -
a8871e32 by Francois Cartegnie at 2022-08-31T13:07:45+00:00
demux: ogg: remove bogus optimization

We can't assume page are small.
and seeks to wrong/outside of stream pos if
stream does not start time 0

- - - - -
2ecf0170 by Francois Cartegnie at 2022-08-31T13:07:45+00:00
demux: ogg: remove leftoff debug

- - - - -
6ee6370f by Francois Cartegnie at 2022-08-31T13:07:45+00:00
demux: ogg: add missing continuity offset

bogus seek after chained content
regression by 7b091b2124c00951576f2e4b30772211d8f08963

- - - - -
82e84dab by Francois Cartegnie at 2022-08-31T13:07:45+00:00
demux: ogg: fix dequeing first continued page

- - - - -


2 changed files:

- modules/demux/ogg.c
- modules/demux/oggseek.c


Changes:

=====================================
modules/demux/ogg.c
=====================================
@@ -178,6 +178,7 @@ static void Ogg_ApplySkeleton( logical_stream_t * );
 /* Special decoding */
 static void Ogg_CleanSpecificData( logical_stream_t * );
 #ifdef HAVE_LIBVORBIS
+static bool Ogg_VorbisValidBlocksize( long );
 static void Ogg_DecodeVorbisHeader( logical_stream_t *, ogg_packet *, int );
 #endif
 
@@ -724,7 +725,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
                 return VLC_EGENERIC;
             }
             vlc_stream_Control( p_demux->s, STREAM_CAN_FASTSEEK, &b );
-            if ( Oggseek_BlindSeektoAbsoluteTime( p_demux, p_stream, VLC_TICK_0 + i64, b ) )
+            if ( Oggseek_BlindSeektoAbsoluteTime( p_demux, p_stream, VLC_TICK_0 + i64, b ) != -1 )
             {
                 Ogg_PreparePostSeek( p_sys );
                 if( acc )
@@ -872,7 +873,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
             }
 
             vlc_stream_Control( p_demux->s, STREAM_CAN_FASTSEEK, &b );
-            if ( Oggseek_BlindSeektoAbsoluteTime( p_demux, p_stream, VLC_TICK_0 + i64, b ) )
+            if ( Oggseek_BlindSeektoAbsoluteTime( p_demux, p_stream, VLC_TICK_0 + i64, b ) != -1 )
             {
                 Ogg_PreparePostSeek( p_sys );
                 es_out_Control( p_demux->out, ES_OUT_SET_NEXT_DISPLAY_TIME,
@@ -967,20 +968,23 @@ static void Ogg_SetNextFrame( demux_t *p_demux, logical_stream_t *p_stream,
                                 p_stream->special.speex.i_framesperpacket;
                     break;
 #ifdef HAVE_LIBVORBIS
+# define Vbs p_stream->special.vorbis
                 case VLC_CODEC_VORBIS:
-                    if( p_stream->special.vorbis.p_info &&
-                        VORBIS_HEADERS_VALID(p_stream) )
+                    if( Vbs.p_info && VORBIS_HEADERS_VALID(p_stream) )
                     {
-                        long i_blocksize = vorbis_packet_blocksize(
-                                    p_stream->special.vorbis.p_info, p_oggpacket );
+                        long i_blocksize = vorbis_packet_blocksize( Vbs.p_info, p_oggpacket );
                         /* duration in samples per channel */
-                        if ( p_stream->special.vorbis.i_prev_blocksize )
-                            i_samples = ( i_blocksize + p_stream->special.vorbis.i_prev_blocksize ) / 4;
-                        else
-                            i_samples = i_blocksize / 2;
-                        p_stream->special.vorbis.i_prev_blocksize = i_blocksize;
+                        if( Ogg_VorbisValidBlocksize( i_blocksize ) )
+                        {
+                            if ( Ogg_VorbisValidBlocksize( Vbs.i_prev_blocksize ) )
+                                i_samples = ( i_blocksize + Vbs.i_prev_blocksize ) / 4;
+                            else
+                                i_samples = i_blocksize / 2;
+                        }
+                        Vbs.i_prev_blocksize = i_blocksize;
                     }
                     break;
+# undef Vbs
 #endif
                 default:
                     if( p_stream->fmt.i_bitrate )
@@ -1056,7 +1060,8 @@ static vlc_tick_t Ogg_FixupOutputQueue( demux_t *p_demux, logical_stream_t *p_st
                                                                 &dumb_packet );
                 /* The spec has 3 specific cases depending on long/short prev/next blocksizes
                    ranging weights from 1/4 to 3/4... but everyone does A/4 + B/4 */
-                p_block->i_nb_samples = (i_blocksize + i_nextblocksize) / 4;
+                if( Ogg_VorbisValidBlocksize( i_blocksize ) && Ogg_VorbisValidBlocksize( i_nextblocksize ) )
+                    p_block->i_nb_samples = (i_blocksize + i_nextblocksize) / 4;
                 break;
             }
 #endif
@@ -1073,7 +1078,17 @@ static vlc_tick_t Ogg_FixupOutputQueue( demux_t *p_demux, logical_stream_t *p_st
     {
         date_t d = p_stream->dts;
         date_Set( &d, i_enddts );
-        date_Decrement( &d, i_total_samples );
+        i_enddts = date_Decrement( &d, i_total_samples );
+        if( i_enddts < VLC_TICK_0 )
+            i_enddts = VLC_TICK_0;
+        vlc_tick_t difftopos = ( date_Get( &d ) < VLC_TICK_0 )
+                             ? VLC_TICK_0 - date_Get( &d )
+                             : 0;
+        /* enforce positive values in date_t so we don't run
+         * into impossible increment on INVALID */
+        date_Set( &d, date_Get( &d ) + difftopos );
+
+        assert(date_Get( &d ) != VLC_TICK_INVALID);
 
         /* truncate end */
         if( b_eos && date_Get( &d ) < VLC_TICK_0 )
@@ -1083,7 +1098,7 @@ static vlc_tick_t Ogg_FixupOutputQueue( demux_t *p_demux, logical_stream_t *p_st
         {
             if( p_block->i_flags & BLOCK_FLAG_HEADER )
                 continue;
-            p_block->i_dts = date_Get( &d );
+            p_block->i_dts = date_Get( &d ) - difftopos;
 
             /* truncate start */
             if( !b_eos && p_block->i_dts < VLC_TICK_0 )
@@ -1103,7 +1118,7 @@ static vlc_tick_t Ogg_FixupOutputQueue( demux_t *p_demux, logical_stream_t *p_st
 
     } /* else can't do anything, no timestamped blocks in stream */
 
-    return i_enddts;
+    return ( i_enddts != VLC_TICK_INVALID )? p_sys->i_nzpcr_offset + i_enddts : i_enddts;
 }
 
 static void Ogg_QueueBlocks( demux_t *p_demux, logical_stream_t *p_stream,
@@ -1122,7 +1137,7 @@ static void Ogg_QueueBlocks( demux_t *p_demux, logical_stream_t *p_stream,
 
     /* If we can have or compute block start from granule, it is set.
      * Otherwise the end dts will be used for reverse calculation */
-    if( p_stream->i_pcr == VLC_TICK_INVALID && i_enddts != VLC_TICK_INVALID )
+    if( p_stream->i_pcr == VLC_TICK_INVALID && i_enddts != VLC_TICK_INVALID && p_block->i_dts != VLC_TICK_INVALID )
     {
         /* fixup queue */
         p_stream->i_pcr = Ogg_FixupOutputQueue( p_demux, p_stream, i_enddts, b_eos );
@@ -1384,8 +1399,7 @@ static void Ogg_DecodePacket( demux_t *p_demux,
     }
 
     vlc_tick_t i_dts = Ogg_GranuleToTime( p_stream, p_oggpacket->granulepos, true, false );
-    vlc_tick_t i_enddts = (i_dts == VLC_TICK_INVALID) ? Ogg_GranuleToTime( p_stream, p_oggpacket->granulepos, false, false )
-                                                      : VLC_TICK_INVALID;
+    vlc_tick_t i_enddts = Ogg_GranuleToTime( p_stream, p_oggpacket->granulepos, false, false );
     vlc_tick_t i_expected_dts = p_stream->b_interpolation_failed ? VLC_TICK_INVALID :
                                 date_Get( &p_stream->dts ); /* Interpolated or previous end time */
     if( i_dts == VLC_TICK_INVALID )
@@ -2785,6 +2799,12 @@ static bool Ogg_ReadVorbisHeader( logical_stream_t *p_stream,
     return true;
 }
 #ifdef HAVE_LIBVORBIS
+static bool Ogg_VorbisValidBlocksize( long i_blocksize )
+{
+    /* non audio or broken return negative errors */
+    return i_blocksize > 0 && i_blocksize <= 8192;
+}
+
 static void Ogg_DecodeVorbisHeader( logical_stream_t *p_stream,
                                     ogg_packet *p_oggpacket, int i_number )
 {


=====================================
modules/demux/oggseek.c
=====================================
@@ -407,12 +407,11 @@ static int64_t find_first_page_granule( demux_t *p_demux,
         if ( i_packets_checked )
         {
             *i_granulepos = ogg_page_granulepos( &p_sys->current_page );
-            return i_pos1;
+            return p_sys->i_input_position;
         }
 
         /*  -> start of next page */
         p_sys->i_input_position += i_result;
-        i_pos1 = p_sys->i_input_position;
     }
 }
 
@@ -454,7 +453,6 @@ static bool OggSeekToPacket( demux_t *p_demux, logical_stream_t *p_stream,
                 msg_Dbg(p_demux, "** KEYFRAME PACKET START pageno %"PRId64" OFFSET %"PRId64" skip %"PRId64" **", p_lastpacketcoords->i_pageno, p_lastpacketcoords->i_pos, p_lastpacketcoords->i_skip );
                 msg_Dbg(p_demux, "KEYFRAME PACKET IS at pageno %"PRId64" OFFSET %"PRId64" with skip %d packet (%d / %d) ",
                     ogg_page_pageno( &p_sys->current_page ), p_sys->i_input_position, i, i+1, ogg_page_packets( &p_sys->current_page ) );
-                DemuxDebug( p_sys->b_seeked = true; )
             );
 
             if ( i != 0 ) /* Not continued packet */
@@ -791,15 +789,7 @@ int Oggseek_BlindSeektoAbsoluteTime( demux_t *p_demux, logical_stream_t *p_strea
         b_found = true;
     }
 
-    /* Or try to be smart with audio fixed bitrate streams */
-    if ( !b_found && p_stream->fmt.i_cat == AUDIO_ES && p_sys->i_streams == 1
-         && p_sys->i_bitrate && Ogg_GetKeyframeGranule( p_stream, 0xFF00FF00 ) == 0xFF00FF00 )
-    {
-        /* But only if there's no keyframe/preload requirements */
-        /* FIXME: add function to get preload time by codec, ex: opus */
-        i_lowerpos = VLC_TICK_0 + (i_time - VLC_TICK_0) * p_sys->i_bitrate / (CLOCK_FREQ * 8);
-        b_found = true;
-    }
+    /* FIXME: add function to get preload time by codec, ex: opus */
 
     /* or search */
     if ( !b_found && b_fastseek )



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/33db6000e3d10956244a3f4d44f81ffc577e2640...82e84dabee98b6032e5b19e3942eb5153c218d07

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/33db6000e3d10956244a3f4d44f81ffc577e2640...82e84dabee98b6032e5b19e3942eb5153c218d07
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list