From 3ecbbfac7d35b52599d295ac7f71c001e03f57b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Filip=20Ros=C3=A9en?= Date: Wed, 25 Jul 2018 04:33:24 +0200 Subject: [PATCH] stream_extractor: archive: simplify seeking As a seek should be successful even if the requested position is outside the bounds of the input, there is no need for us to reset the state of the libarchive reader immediately after seeking fails, instead we rely on the fact that future reads will return EOF, and that the reader will have to seek to a proper position in order to continue reading (causing a libarchive reset). Signed-off-by: Jean-Baptiste Kempf --- modules/stream_extractor/archive.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/modules/stream_extractor/archive.c b/modules/stream_extractor/archive.c index 27f5a76f63..15262d2a72 100644 --- a/modules/stream_extractor/archive.c +++ b/modules/stream_extractor/archive.c @@ -627,26 +627,27 @@ static int archive_skip_decompressed( stream_extractor_t* p_extractor, uint64_t static int Seek( stream_extractor_t* p_extractor, uint64_t i_req ) { private_sys_t* p_sys = p_extractor->p_sys; - uint64_t i_orig_offset = p_sys->i_offset; if( p_sys->b_dead ) return VLC_EGENERIC; - if( !p_sys->p_entry ) - return VLC_EGENERIC; - - if( !p_sys->b_seekable_source ) + if( !p_sys->p_entry || !p_sys->b_seekable_source ) return VLC_EGENERIC; if( archive_entry_size_is_set( p_sys->p_entry ) && - (uint64_t)archive_entry_size( p_sys->p_entry ) < i_req ) - return VLC_EGENERIC; + (uint64_t)archive_entry_size( p_sys->p_entry ) <= i_req ) + { + p_sys->b_eof = true; + return VLC_SUCCESS; + } - if( !p_sys->b_seekable_archive + p_sys->b_eof = false; + + if( !p_sys->b_seekable_archive || p_sys->b_dead || archive_seek_data( p_sys->p_archive, i_req, SEEK_SET ) < 0 ) { - msg_Dbg( p_extractor, "libarchive intrinsic seek failed:" - " '%s' (falling back to dumb seek)", + msg_Dbg( p_extractor, + "intrinsic seek failed: '%s' (falling back to dumb seek)", archive_error_string( p_sys->p_archive ) ); uint64_t i_skip = i_req - p_sys->i_offset; @@ -665,12 +666,7 @@ static int Seek( stream_extractor_t* p_extractor, uint64_t i_req ) } if( archive_skip_decompressed( p_extractor, i_skip ) ) - { - if( archive_extractor_reset( p_extractor ) || - archive_skip_decompressed( p_extractor, i_orig_offset ) ) - msg_Err( p_extractor, "unable to reset original offset" ); - return VLC_EGENERIC; - } + msg_Dbg( p_extractor, "failed to skip to seek position" ); } p_sys->i_offset = i_req; -- 2.11.4.GIT