[vlc-commits] demux: ogg: fix find_first_granule for packets that span multiple pages

Michael Tänzer git at videolan.org
Fri Feb 5 16:46:04 CET 2016


vlc | branch: master | Michael Tänzer <neo at nhng.de> | Sun Jan 31 00:29:23 2016 +0100| [52a6dc0211e71f781c254d6d4ca4169a601b054a] | committer: Jean-Baptiste Kempf

demux: ogg: fix find_first_granule for packets that span multiple pages

If the granulepos is negative we need to pagein the page nevertheless
because it might contain a packet that is continued on the next page. Also
we want to return the position of the first page containing the packet.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/demux/oggseek.c |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/modules/demux/oggseek.c b/modules/demux/oggseek.c
index d5b6f49..104954d 100644
--- a/modules/demux/oggseek.c
+++ b/modules/demux/oggseek.c
@@ -334,7 +334,6 @@ static int64_t find_first_page_granule( demux_t *p_demux,
     *i_granulepos = -1;
     int64_t i_bytes_to_read = i_pos2 - i_pos1 + 1;
     int64_t i_bytes_read;
-    int64_t i_pages_checked = 0;
     int64_t i_packets_checked;
 
     demux_sys_t *p_sys  = p_demux->p_sys;
@@ -407,23 +406,22 @@ static int64_t find_first_page_granule( demux_t *p_demux,
             return p_sys->i_input_position;
         }
 
-        if ( ogg_page_granulepos( &p_sys->current_page ) <= 0 )
+        // found a page
+        if ( ogg_stream_pagein( &p_stream->os, &p_sys->current_page ) != 0 )
         {
+            /* page is not for this stream or incomplete */
             p_sys->i_input_position += i_result;
-            i_bytes_to_read += OGGSEEK_BYTES_TO_READ;
             continue;
         }
 
-        // found a page
-        if ( ogg_stream_pagein( &p_stream->os, &p_sys->current_page ) != 0 )
+        if ( ogg_page_granulepos( &p_sys->current_page ) <= 0 )
         {
-            /* page is not for this stream or incomplete */
+            /* A negative granulepos means that the packet continues on the
+             * next page => read the next page */
             p_sys->i_input_position += i_result;
-            if ( ! i_pages_checked ) i_pos1 = p_sys->i_input_position;
             continue;
         }
 
-        i_pages_checked++;
         i_packets_checked = 0;
 
         while ( ogg_stream_packetout( &p_stream->os, &op ) > 0 )
@@ -439,6 +437,7 @@ static int64_t find_first_page_granule( demux_t *p_demux,
 
         /*  -> start of next page */
         p_sys->i_input_position += i_result;
+        i_pos1 = p_sys->i_input_position;
     }
 }
 



More information about the vlc-commits mailing list