@@ -527,31 +527,14 @@ static int archive_entry_fill_buffer(stream_t *s, void *buffer, int max_len)
527527static int archive_entry_seek (stream_t * s , int64_t newpos )
528528{
529529 struct priv * p = s -> priv ;
530- if (p -> mpa && !p -> broken_seek ) {
531- locale_t oldlocale = uselocale (p -> mpa -> locale );
532- int r = archive_seek_data (p -> mpa -> arch , newpos , SEEK_SET );
533- uselocale (oldlocale );
534- if (r >= 0 )
535- return 1 ;
536- MP_WARN (s , "possibly unsupported seeking - switching to reopening\n" );
537- p -> broken_seek = true;
538- if (reopen_archive (s ) < STREAM_OK )
539- return -1 ;
540- }
541- // libarchive can't seek in most formats.
542- if (newpos < s -> pos ) {
543- // Hack seeking backwards into working by reopening the archive and
544- // starting over.
545- MP_VERBOSE (s , "trying to reopen archive for performing seek\n" );
546- if (reopen_archive (s ) < STREAM_OK )
547- return -1 ;
548- }
549- if (newpos > s -> pos ) {
530+
531+ // For forward seeks, prefer skipping by reading data to avoid reopening
532+ // which disrupts hwdec initialization
533+ if (newpos >= s -> pos ) {
550534 if (!p -> mpa && reopen_archive (s ) < STREAM_OK )
551535 return -1 ;
552- // For seeking forwards, just keep reading data (there's no libarchive
553- // skip function either).
554- char buffer [4096 ];
536+ // Skip forward by reading and discarding data
537+ char buffer [65536 ];
555538 while (newpos > s -> pos ) {
556539 if (mp_cancel_test (s -> cancel ))
557540 return -1 ;
@@ -578,7 +561,20 @@ static int archive_entry_seek(stream_t *s, int64_t newpos)
578561 uselocale (oldlocale );
579562 s -> pos += r ;
580563 }
564+ return 1 ;
565+ }
566+
567+ // libarchive can't seek backwards in most formats.
568+ if (newpos < s -> pos ) {
569+ // Hack seeking backwards into working by reopening the archive and
570+ // starting over.
571+ MP_VERBOSE (s , "trying to reopen archive for performing seek\n" );
572+ if (reopen_archive (s ) < STREAM_OK )
573+ return -1 ;
574+ // Now recursively call to seek forward to the target position
575+ return archive_entry_seek (s , newpos );
581576 }
577+
582578 return 1 ;
583579}
584580
0 commit comments