# HG changeset patch # User reimar # Date 1353958258 0 # Node ID 092c40fbd33d14f97b7f81e86a95007c18da7420 # Parent d076af01765d8ae2906c6b98e5f548d969318f0c Try to improve seeking in files with only few video packets, in particular files with cover art. This might cause issues with badly interleaved files, particularly together with -audio-delay, even though I did not see issues in my very limited testing. diff -r d076af01765d -r 092c40fbd33d libmpdemux/demuxer.c --- a/libmpdemux/demuxer.c Mon Nov 26 11:32:50 2012 +0000 +++ b/libmpdemux/demuxer.c Mon Nov 26 19:30:58 2012 +0000 @@ -663,6 +663,7 @@ demux_packet_t *p = ds->first; // obviously not yet EOF after all ds->eof = 0; + ds->fill_count = 0; #if 0 if (demux->reference_clock != MP_NOPTS_VALUE) { if ( p->pts != MP_NOPTS_VALUE @@ -697,6 +698,11 @@ --ds->packs; return 1; } + // avoid buffering too far ahead in e.g. badly interleaved files + // or when one stream is shorter, without breaking large audio + // delay with well interleaved files. + if (ds->fill_count++ > 20) + break; // avoid printing the "too many ..." message over and over if (ds->eof) break; diff -r d076af01765d -r 092c40fbd33d libmpdemux/demuxer.h --- a/libmpdemux/demuxer.h Mon Nov 26 11:32:50 2012 +0000 +++ b/libmpdemux/demuxer.h Mon Nov 26 19:30:58 2012 +0000 @@ -144,6 +144,7 @@ int non_interleaved; // 1 if this stream is not properly interleaved, // so e.g. subtitle handling must do explicit reads. //--------------- + int fill_count; // number of unsuccessful tries to get a packet int packs; // number of packets in buffer int bytes; // total bytes of packets in buffer demux_packet_t *first; // read to first buffer after the current buffer from here