Commit 52a6dc02 authored by Michael Tänzer's avatar Michael Tänzer Committed by 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: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 7141b8c4
......@@ -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;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment