summaryrefslogtreecommitdiffstats
path: root/demux/demux_mkv.c
Commit message (Collapse)AuthorAgeFilesLines
* demux_mkv: passthrough BlockAdditions for libvpx alphawm42017-01-311-0/+27
| | | | | Dumb but simple thing. Requires the FFmpeg libvpx decoder wrapper, as its native decoder doesn't support alpha.
* demux_mkv: any reference makes a frame not a keyframewm42017-01-311-2/+1
| | | | | | | | | | | | | Fixes seeking with: https://bugs.chromium.org/p/chromium/issues/detail?id=497889 Haali also ignores the element's contents, and interprets its presence as the block not being a keyframe. FFmpeg is going to have an equivalent change. I don't know yet whether the affected sample is valid - a reference timestamp of 0 doesn't make too much sense to me.
* demux_mkv: trust keyframe flags for TrueHDwm42016-12-201-1/+2
| | | | | | | | | | TrueHD is a fucked up audio codec with extremely small frame sizes. Some of these frames start with full headers, which are usually marked as keyframes, and from which decoding can be started (or at least that's what you'd expect). So for such tracks we should probably trust the keyframe flags. Doesn't really improve seek behavior, though.
* demux_mkv: fix seeking in some broken fileswm42016-12-191-1/+16
| | | | | | | | | | | | | | | | | | | | | | Some files have audio tracks with packets that do not have a keyframe flag set at all. I don't think there's any audio codec which actually needs keyframe flags, so always assume an audio packet is a keyframe (which, in Matroska terminology, means it can start decoding from that packet). The file in question had these set: | + Multiplexing application: Lavf57.56.100 at 313 | + Writing application: Lavf57.56.100 at 329 Garbage produced by garbage... There are other such files produced by mkvmerge, though. It's not perfectly sure whether these have been produced by FFmpeg as well (mkvmerge often trusts the information in the source file, even if it's wrong - so other samples could have been remuxed from FFmpeg). Fixes #3920.
* demux_mkv: distinguish mp2 and mp3wm42016-11-231-2/+4
| | | | | demux_mkv.c has returned mp3 for mp2 since the initial commit. Normally not a problem.
* demux: expose demuxer colorimetry metadata to playerNiklas Haas2016-11-081-0/+1
| | | | | | Implementation-wise, the values from the demuxer/codec header are merged with the values from the decoder such that the former are used only where the latter are unknown (0/auto).
* demux_mkv: parse colorimetry metadataNiklas Haas2016-11-081-0/+39
| | | | | | | | | Matroska actually has lots of colorimetry metadata that video tracks can use, including mastering metadata (HDR signal peak) etc. This commit adds the EBML definitions and parses the most basic fields. Note that nothing uses these fields yet, this commit is just adding the necessary parsing and infrastructure.
* demux_mkv: fix ordered chapter sources with ordered editionsUoti Urpala2016-10-221-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | Commit f72a900892 (and others) added support for ordered editions that recursively refer to other ordered editions. However, this recursion code incorrectly activated if the source files had ordered chapters even if the main file only wanted to use them as raw video, resulting in broken timeline info overall. Ordered chapters can specify a ChapterSegmentEditionUID value if they want to use a specific edition from a source file. Otherwise the source is supposed to be used as a raw video file. The code checked demuxer->matroska_data.num_ordered_chapters for an opened source file to see whether it was using a recursive ordered edition, but demux_mkv could enable a default ordered edition for the file using the normal playback rules even if the main file had not specified any ChapterSegmentEditionUID. Thus this incorrectly enabled recursion if a source file had a default edition using ordered chapters. Check demuxer->matroska_data.uid.edition instead, and ensure it's never set if a file is opened without ChapterSegmentEditionUID. Also fix what seems like a memory leak in demux_mkv.c. Signed-off-by: wm4 <wm4@nowhere>
* demux: do not access global optionswm42016-09-061-15/+22
| | | | | | | | | | | | | | | | | Don't access MPOpts directly, and always use the new m_config.h functions for accessing them in a thread-safe way. The goal is eventually removing the mpv_global.opts field, and the demuxer/stream-layer specific hack that copies MPOpts to deal with thread-safety issues. This moves around a lot of options. For one, we often change the physical storage location of options to make them more localized, but these changes are not user-visible (or should not be). For shared options on the other hand it's better to do messy direct access, which is worrying as in that somehow renaming an option or changing its type would break code reading them manually, without causing a compilation error.
* demux: add per-track metadatawm42016-08-121-4/+16
| | | | | | | | | | | | | | | | | ...and ignore it. The main purpose is for retrieving per-track replaygain tags. Other than that per-track tags are not used or accessed by the playback core yet. The demuxer infrastructure is still not really good with that whole synchronization thing (at least in part due to being inherited from mplayer's single-threaded architecture). A convoluted mechanism is needed to transport the tags from demuxer thread to user thread. Two factors contribute to the complexity: tags can change during playback, and tracks (i.e. struct sh_stream) are not duplicated per thread. In particular, we update the way replaygain tags are retrieved. We first try to use per-track tags (common in Matroska) and global tags (effectively formats like mp3). This part fixes #3405.
* demux: make refresh seek handling more genericwm42016-08-061-1/+0
| | | | | | | | | | | | | | | | | Remove the explicit whitelisting of formats for refresh seeks. Instead, check whether the packet position is somewhat reliable during demuxing. If there are packets without position, or the packet position is not monotonically increasing, then do not use them for refresh seeks. This does not make sure of some requirements, such as deterministic seeks. If that happens, mpv will mess up a bit on stream switching. Also, add another method that uses DTS to identify packets, and prefer it to the packet position method. Even if there's a demuxer which randomizes packet positions, it hardly can do that with DTS. The DTS method is not always available either, though. Some formats do not have a DTS, and others are not always strictly monotonic (possibly due to libavformat codec parsing and timestamp determination issues).
* demux_mkv: support Matroska webvttwm42016-06-141-0/+1
| | | | | | | They're different from the Google/WebM subtitle types, and use a new codec ID. Fixes #3247.
* demux_mkv: better resync behavior for broken google-created webmswm42016-05-211-0/+2
| | | | | | | | | | | | | | | | | | | | | I've got a broken webm that fails to seek correctly with "--start=0". The problem is that every index entry points to 1 byte before cluster start (!!!). demux_mkv tries to resync to the next cluster, but since it already has read 2 bytes with ebml_read_id(), it doesn't get the first cluster, but the following one. Actually, it can be any amount of bytes from 1-4, whatever happens to look valid at this essentially random byte position. Improve this by resyncing from the original position, instead of the one after the EBML element ID has been attempted to be read. The file shows the following headers: | + Muxing application: google at 177 | + Writing application: google at 186 Indeed, the file was downloaded with youtube-dl. I can only guess that Google got it completely wrong.
* demux_mkv: fix seeking with files that miss the first index entrywm42016-04-121-3/+6
| | | | | | | | | Now it will always be able to seek back to the start, even if the index is sparse or misses the first entry. This can be achieved by reusing the logic for incremental index generation (for files with no index), and start time probing (for making sure the first block is always indexed).
* Revert "demux_mkv: don't trust DefaultDuration for audio"wm42016-03-301-3/+5
| | | | | | | | | | This reverts commit 503c6f7fd6c3c542667c93c75db260671c4ba982. There are situations where some decoders (MF apparently) always require a timestamp. Also, this makes bitrate estimation more granular than necessary. It seems it's better to try to detect fiels with broken default durations explicitly instead. Or maybe something should be added to smooth audio timestamps after filters.
* demux_mkv: correctly export unknown packet durationswm42016-03-051-2/+3
| | | | Instead of just setting the duration to 0.
* Revert "demux_mkv: pretend waveext channel layouts by default"wm42016-03-021-1/+1
| | | | | | | | | | | | | | | | This reverts commit af66fa8fa5d8e46b26a08a2b241f03d46abb3c2b. The reverted commit caused AVCodecContext.channel_layout to be set, while requesting stereo downmix will make libavcodec output a stupid message: ac3: Channel layout '5.1' with 6 channels does not match specified number of channels 2: ignoring specified channel layout The same happens with --demuxer=lavf (without this change too). I'm not quite sure what acrobatics are required to shut up libavcodec, but for now revert the commit. It was a rather minor, almost cosmetic issue, which I consider less important than clean CLI terminal output.
* demux_mkv: pretend waveext channel layouts by defaultwm42016-02-291-1/+1
| | | | | Not much of an impact, just makes output of the "channels" "track-list" sub-property nicer.
* demux: remove relative seekingwm42016-02-281-10/+7
| | | | | | | | | | | | | | | | | | | Ever since a change in mplayer2 or so, relative seeks were translated to absolute seeks before sending them to the demuxer in most cases. The only exception in current mpv is DVD seeking. Remove the SEEK_ABSOLUTE flag; it's not the implied default. SEEK_FACTOR is kept, because it's sometimes slightly useful for seeking in things like transport streams. (And maybe mkv files without duration set?) DVD seeking is terrible because DVD and libdvdnav are terrible, but mostly because libdvdnav is terrible. libdvdnav does not expose seeking with seek tables. (Although I know xbmc/kodi use an undocumented API that is not declared in the headers by dladdr()ing it - I think the function is dvdnav_jump_to_sector_by_time().) With the current mpv policy if not giving a shit about DVD, just revert our half-working seek hacks and always use dvdnav_time_search(). Relative seeking might get stuck sometimes; in this case --hr-seek=always is recommended.
* demux_mkv: don't trust DefaultDuration for audiowm42016-02-241-5/+3
| | | | | It's used to interpolate timestamps for sub-packets ("block laces"). It's occasionally broken, and not really needed by us.
* demux_mkv: fix opus gapless behavior (2)wm42016-02-221-2/+2
| | | | | | | Commit 943f76e6, which already tried this, was very stupid: it didn't actually override the samplerate for Opus, but overrode it for all codecs other than Opus. And even then, it failed to use the overridden samplerate. (Sigh...)
* demux_mkv: add hack to fix opus gapless behaviorwm42016-02-211-0/+6
| | | | | | | I think the conclusion is that AV_PKT_DATA_SKIP_SAMPLES is misdesigned (at least for some formats), and an alternative mechanism using durations would be better. (Combining it with a proper timebase would keep sample-accuracy.)
* demux_mkv: support channel layout in VfW muxed PCMwm42016-02-141-1/+7
| | | | Fixes #2820.
* demux_mkv: allow negative timestampswm42016-01-271-18/+20
| | | | | | | FFmpeg can generate such files. It's unclear whether they're allowed by Matroska. mkvinfo shows packet timestamps in both forms (one of them must be a bug), and at last libavformat's demuxer treats timestamps as signed.
* demux: merge sh_video/sh_audio/sh_subwm42016-01-121-45/+45
| | | | | | | | | | This is mainly a refactor. I'm hoping it will make some things easier in the future due to cleanly separating codec metadata and stream metadata. Also, declare that the "codec" field can not be NULL anymore. demux.c will set it to "" if it's NULL when added. This gets rid of a corner case everything had to handle, but which rarely happened.
* mpv_talloc.h: rename from talloc.hDmitrij D. Czarkoff2016-01-111-1/+1
| | | | This change helps avoiding conflict with talloc.h from libtalloc.
* demux_mkv: skip EBML void elementsKagami Hiiragi2015-12-291-1/+1
| | | | | | | EBML_ID_VOID might occur at any level, see: https://github.com/Matroska-Org/ebml-specification/blob/master/specification.markdown This change prevents "Corrupt file detected" errors on completely valid files.
* demux_mkv: adjust subtitle preroll defaultswm42015-12-271-3/+13
| | | | | | | | | | | | | | | | | Always preroll by default if the cue (index) information indicates overlapping subtitles. Increase the amount of maximum data it will skip to get such subtitles to 10 seconds. Since the index information can reliably tell whether reading earlier is needed, the maximum should be rarely actually used, thus we can set it high. On the other hand, the "old" prerolling mechanism always has to skip the maximum amount of data; thus the method using the index gets its own option to control the maximum amount of data to skip. (As more and more files With newer mkvtoolnix versions are muxed, and with this new and hopefully sane default established, these options can probably be removed in the future.)
* demux: remove weird tripple-buffering for the sh_stream listwm42015-12-231-14/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The demuxer infrastructure was originally single-threaded. To make it suitable for multithreading (specifically, demuxing and decoding on separate threads), some sort of tripple-buffering was introduced. There are separate "struct demuxer" allocations. The demuxer thread sets the state on d_thread. If anything changes, the state is copied to d_buffer (the copy is protected by a lock), and the decoder thread is notified. Then the decoder thread copies the state from d_buffer to d_user (again while holding a lock). This avoids the need for locking in the demuxer/decoder code itself (only demux.c needs an internal, "invisible" lock.) Remove the streams/num_streams fields from this tripple-buffering schema. Move them to the internal struct, and protect them with the internal lock. Use accessors for read access outside of demux.c. Other than replacing all field accesses with accessors, this separates allocating and adding sh_streams. This is needed to avoid race conditions. Before this change, this was awkwardly handled by first initializing the sh_stream, and then sending a stream change event. Now the stream is allocated, then initialized, and then declared as immutable and added (at which point it becomes visible to the decoder thread immediately). This change is useful for PR #2626. And eventually, we should probably get entirely of the tripple buffering, and this makes a nice first step.
* video: switch from using display aspect to sample aspectwm42015-12-191-4/+9
| | | | | | | | | | | | | | | | MPlayer traditionally always used the display aspect ratio, e.g. 16:9, while FFmpeg uses the sample (aka pixel) aspect ratio. Both have a bunch of advantages and disadvantages. Actually, it seems using sample aspect ratio is generally nicer. The main reason for the change is making mpv closer to how FFmpeg works in order to make life easier. It's also nice that everything uses integer fractions instead of floats now (except --video-aspect option/property). Note that there is at least 1 user-visible change: vf_dsize now does not set the display size, only the display aspect ratio. This is because the image_params d_w/d_h fields did not just set the display aspect, but also the size (except in encoding mode).
* demux_mkv: fix incremental indexing with single-keyframe fileswm42015-11-171-2/+1
| | | | | | | | | | | | This is another regression of the recently added start time probing. If a seek is executed after opening the file (but before reading any packets), the first block is discarded instead of indexed. If there are no other keyframes in the file, seeking will fail completely. Fix it by seeking to the cluster start if there aren't any index entries yet. This will read the skipped packet again. Fixes #2498.
* demux_mkv: remove --demuxer-mkv-fix-timestampswm42015-11-071-17/+1
| | | | | | | | While it seemed like a pretty good idea at first, it's just a dead end and works only in the simplest cases. While it may or may not help slightly with audio sync mode, the display-sync mode already compensates this in a better way. The main issue is that timestamps at this layer are not in order, so it can look at single timestamps only.
* demux_mkv: dump mixing/writing app fields in verbose logwm42015-11-061-0/+4
|
* demux_mkv: fix cluster skip with duration probingwm42015-10-271-6/+7
| | | | The start time probing essentially broke it.
* demux_mkv: fix duration probing for files with non-0 start timewm42015-10-261-1/+1
| | | | | When using --demuxer-mkv-probe-video-duration=full and the file did not start at timestamp 0, the reported duration was still wrong.
* demux_mkv: probe start timewm42015-10-161-10/+43
| | | | | | | | | | | | | | | | | MKV files can very well start with timestamps other than 0. While mpv has support for such files in general, and demux_lavf enables this feature, demux_mkv didn't export a start time. Implement this by simply reading the first cluster timestamp. This in turn is done by reading 1 block. While we don't need the block for this prupose at all, it's the easiest way to get the cluster timestamp read correctly without code duplication. In theory this could be wrong, and a packet could start at a much later time, but in practice this won't happen. This commit also adds an option to disable this feature. It's not documented because nobody should use it. (But I happen to have a need for this.)
* demux_mkv: do not return subtitle packets that end before seek targetwm42015-10-121-2/+6
| | | | | | This affects the subtitle preroll mode during seeking. It could matter somewhat with insane files with ten-thousands of subtitle events, which now seem to pop up, and will avoid packet queue overflow.
* demux_mkv: discard broken indexwm42015-08-261-4/+17
| | | | | | | | | | | | | | | | Add a simplistic heuristic for detecting broken indexes. This includes indexes with very few elements (apparently libavformat sometimes writes such indexes, or used to), and indexes with broken timestamps. The latter was apparently produced by very old HandBrake versions: | + Muxing application: libmkv 0.6.1.2 | + Writing application: HandBrake 0.9.1 These broken files seem to be common enough that libavformat added a workaround for them in 2008 (and maybe again in 2015). Apparently all timestamps are multiplied with the file's tc_scale twice, and FFmpeg attempts to fix them. We should throw away the whole thing.
* demux_mkv: don't read index twicewm42015-08-261-1/+1
| | | | | | Actually, this never happened, because there's logic for ignoring duplicate header elements (which includes the seek index). This is mostly for robustness and readability.
* stream: provide a stream_get_size() convenience functionwm42015-08-181-11/+5
| | | | | And use it everywhere, instead of retrieving the size manually. Slight simplification.
* demux_mkv: disable timestamp fixup code againwm42015-08-101-1/+1
| | | | | | | | | | | | This doesn't work too well if sections of the file change to a different framerate. It lowers our chances to guess the correct FPS in the display sync code. For normal playback, this (probably) doesn't help that much anyway, except that the "estimated-vf-fps" property will regress in the simplest mkv case. This will be fixed with the next commit. The now disabled code will probably be removed; it's not useful anymore.
* demux_mkv: remove unnecessary codewm42015-07-201-4/+0
| | | | This did nothing. It's a leftover from ancient times.
* demux_mkv: parse FLAC channel layoutswm42015-07-201-0/+67
| | | | | | | | | | | | | | | | | | Handle a relatively recently introduced hack, that allows FLAC audio to have arbitrary channel layouts, instead of just the predefined fixed ones. This is actually supported by FFmpeg, but since the demuxer (instead of the decoder) handles this in FFmpeg, we need to add special- code to our mkv demuxer. (The way FFmpeg does this seems a bit backwards, since now every demuxer for a format that can handle FLAC needs to contain this logic as well.) The FLAC hack is relatively terrible: we need to parse the FLAC headers, look for a VorbisComment, parse the VorbisComment, and then retrieve the magic WAVEFORMATEXTENSIBLE_CHANNEL_MASK entry. But the hack is officially endorsed, as the official FLAC tools use it. (Although I couldn't find a trace of it in the format specification. Should I be surprised?)
* demux_mkv: improve video duration detection heuristicwm42015-07-091-16/+29
| | | | | | | | | | | Extend the --demuxer-mkv-probe-video-duration behavior to work with files that are partial and are missing an index. Do this by finding a cluster 10MB before the end of the file, and if that fails, just read the entire file. This is actually pretty trivial to do and requires only 5 lines of code. Also add a mode that always reads the entire file to estimate the video duration.
* demux_mkv: disable ordered chapters if ChapterTimeEnd is missingwm42015-06-281-2/+11
| | | | | | | | | | | | | If the EditionFlagOrdered is set, chapters without ChapterTimeEnd make no sense. Ordered chapters will play the chapters in the order they appear, but will play the ranges the chapters cover. So if the end time is missing, the range is incomplete and it's not clear what should be played. If you assume the start of the next chapter as end time, the ordered flag will have no observable effect, so that's not a useful assumption. This fixes playback of a file which (apparently) had the EditionFlagOrdered set accidentally, with normal chapters.
* demux: export forced flagwm42015-06-271-0/+7
| | | | | | At least Matroska files have a "forced" flag (in addition to the "default" flag). Export this flag. Treat it almost like the default flag, but with slightly higher priority.
* demux_mkv: ignore deprecated FrameRate, do not assume PALwm42015-06-271-8/+2
| | | | | | | | | | | The "FrameRate" element is probably deprecated (it's greyed out in the "spec", and described as "Informational only" in bold). Normally files use DefaultDuration. In fact, the FrameRate field was preferred over DefaultDuration for determining framerate if present. Do not do this and rely on DefaultDuration only. Also, if no framerate is set, do not assume PAL (25 FPS). Such a fallback makes little sense and will cause more problems than it solves.
* demux_mkv: remove some ASCII art log messageswm42015-06-271-8/+4
| | | | | Some of the ASCII art makes sense (like the lines starting with "|"), but these do not make any sense to me and just look annoying.
* demux_mkv: use arrays for codec lookup tableswm42015-06-261-18/+11
| | | | No need to define extra types.
* demux_mkv: minor simplificationwm42015-06-261-3/+1
|
* demux: get rid of some bstr thingswm42015-06-241-2/+3
| | | |