summaryrefslogtreecommitdiffstats
path: root/demux/packet.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-05-17 23:41:03 +0200
committerwm4 <wm4@nowhere>2019-09-19 20:37:04 +0200
commit62e9a0c5f6be63c4cbe6387cbd3419fe19e98b74 (patch)
tree7696768e7aa86a77d5bb9ed3f7ebb603237c29d0 /demux/packet.h
parent8a58355a23ec85ff5b33196ccc6d31d660d2805f (diff)
downloadmpv-62e9a0c5f6be63c4cbe6387cbd3419fe19e98b74.tar.bz2
mpv-62e9a0c5f6be63c4cbe6387cbd3419fe19e98b74.tar.xz
demux: add shitty start of stream detection
The demuxer cache benefits slightly from knowing where the current file or stream begins. For example, seeking "left most" when the start is cached would not trigger a low level seek (which would be followed by messy range joining when it notices that the newly demuxed packets overlap with an existing range). Unfortunately, since multimedia is so crazy (or actually FFmpeg in its quite imperfect attempt to be able to demux anything), it's hard to tell where a file starts. There is no feedback whether a specific seek went to the start of the file. Packets are not tagged with a flag indicating they were demuxed from the start position. There is no index available that could be used to cross-check this (even if the file contains a full and "perfect" index, like mp4). You could go by the timestamps, but who says streams start at 0? Streams can start somewhere at an extremely high timestamps (transport streams like to do that), or they could start at negative times (e.g. files with audio pre-padding will do that), and maybe some file formats simply allow negative timestamps and could start at any negative time. Even if the affected file formats don't allow it in theory, they may in practice. In addition, FFmpeg exports a start_time field, which may or may not be useful. (mpv's internal mkv demuxer also exports such a field, but doesn't bother to set it for efficiency and robustness reasons.) Anyway, this is all a huge load of crap, so I decided that if the user performs a seek command to time 0 or earlier, we consider the first packet demuxed from each stream to be at the start of the file. In addition, just trust the start_time field. This is the "shitty" part of this commit. One common case of negative timestamps is audio pre-padding. Demuxers normally behave sanely, and will treat 0 as the start of the file, and the first packets demuxed will have negative timestamps (since they contain data to discard), which doesn't break our assumptions in this commit. (Although, unfortunately, do break some other demuxer cache assumptions, and the first cached range will be shown as starting at a negative time.) Implementation-wise, this is quite simple. Just split the existing initial_state flag into two, since we want to deal with two separate aspects. In addition, this avoids the refresh seek on track switching when it happens right after a seek, instead of only after opening the demuxer.
Diffstat (limited to 'demux/packet.h')
0 files changed, 0 insertions, 0 deletions