summaryrefslogtreecommitdiffstats
path: root/demux/demux_mkv.c
Commit message (Collapse)AuthorAgeFilesLines
* 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
| | | | | Change the demuxer_add_attachment() and demuxer_add_chapter() signatures to take char* instead of bstr, and everything which depends on it.
* demux_mkv: don't use byte stringswm42015-06-241-29/+28
| | | | | | Use char* for strings instead of bstr (data ptr + length pair). Matroska actually (probably) allows "padding" strings with \0 bytes, so using normal C strings instead of byte strings is more appropriate.
* demux_mkv: share some duplicated codewm42015-06-211-16/+17
| | | | | As a side effect, video tracks now actually export some fields (language, default flag) to the player.
* demux: merge extradata fieldswm42015-06-211-7/+6
| | | | | | | MPlayer traditionally had completely separate sh_ structs for audio/video/subs, without a good way to share fields. This meant that fields shared across all these headers had to be duplicated. This commit deduplicates essentially the last remaining duplicated fields.
* demux_mkv: minor audio extradata cleanupwm42015-06-211-27/+24
| | | | | | Always use the already existing extradata[_len] variable, instead of the awkward switch between manually changed extradata and falling back to passing through extradata at the end.
* demux: rename sh_stream.format to sh_stream.codec_tagwm42015-06-211-4/+4
| | | | | Why not. "format" sounds too misleading for the actual importance and meaning of this field.
* demux_mkv: do not reset bits_per_coded_sample if not neededwm42015-06-191-7/+0
|
* demux_mkv: do not set block_align for codecs which do not need itwm42015-06-191-7/+0
| | | | | These decoders do not reference it. I suspect this was originally done for the sake for MPlayer's vfw/dshow wrappers.
* demux_mkv: do not set bitrate fields for codecs which do not need itwm42015-06-191-7/+0
| | | | | | The only decoders I could find and which (possibly) require this field are codecs which can be used via VfW only, and realaudio sipr. For VfW we still passthrough this field.
* demux_mkv: stricter realaudio extradata handlingwm42015-06-191-11/+13
| | | | | | Verify memory accesses and such. The behavior should be equivalent. (RealAudio causes pain for everyone even in its grave.)
* demux_mkv: separate generic and non-VfW audio codec handling partswm42015-06-191-89/+84
| | | | | | | | | | | | | | | | | | | Native Matroska codec support has to map the Matroska codec IDs to libavcodec ones, and also has to undo codec-specific Matroska strangeness, such as restoring AAC extradata and realaudio handling. The VfW codec support doesn't need it, because AVI maps well enough to libavcodec conventions (possibly because AVI was a dominant codec when libavcodec was created). But there's still some need for generic codec handling, such as enabling parsers and messing with various codec parameters. Separate these two, and move the parts which are guaranteed not to be needed by VfW to the if-else tree that handles the VfW case ("A_MS/ACM"), making the cases exclusive. (This should probably be done more radically, since it's very unlikely that we should or have to mess with the VfW parameters at all - they should just be passed through to the decoder.)
* demux_mkv: remove indirection through defineswm42015-06-191-58/+58
| | | | | This is actually more readable. Most of the defines are used only once, so using a symbol instead of the direct string only obfuscated it.
* demux_mkv: remove FourCCs from audio codec handlingwm42015-06-191-92/+73
| | | | | | | | | | | | | | | | | | | | | | This removes the last traces of the old MPlayer FourCC-based codec mapping code. Forcing all codec IDs through a FourCC table and then back to codec names was confusing at best, so this is a nice cleanup. Handling of PCM (non-VfW case) is redone to some degree. Handling of AC3 is moved below realaudio handling, since "A_REAL/DNET" is apparently AC3, and we must not skip realaudio-specific handling. (It seems unlikely that anything would actually break, but on the other hand I don't have any A_REAL/DNET samples for testing.) Instead of explicitly matching all the specific AAC codec names, just match them all as prefix. Some codecs don't need special handling other than their mapping entries, so they fall away (like Vorbis and Opus). The prores check in mkv_parse_and_add_packet() is not strictly related to this, but is done for consistency with the wavpack check above.
* demux_mkv: always copy video extradatawm42015-06-131-16/+14
| | | | | | The existing code avoided doing this for some codecs. I see no point in this, and it seems the original reason this exists was due to some cleanup in 2007. libavformat doesn't do this. So just drop it.
* demux_mkv: fix mpeg2 mappingwm42015-06-131-1/+1
| | | | | | | | It's well possible that we've always ended up invoking the AV_CODEC_ID_MPEG1VIDEO codec, but it's hard to tell. Mangling everything through FourCCs (and then back) makes it hard to analyze. Also, libavformat's Matroska demuxer uses AV_CODEC_ID_MPEG2VIDEO here, so it should be quite safe to do anyway.
* demux_mkv: remove FourCCs from video codec handlingwm42015-06-131-26/+27
| | | | | | | | | | | | | | | | | | | Inherited from MPlayer times, we used FourCCs to identify video codecs. This was later changed to libavcodec codec names (which made life a whole lot simpler). But demux_mkv still uses FourCCs a lot. Change this for video. It's pretty simple, because some preparation was done in the past. We just have to replace some "internal" FourCCs with different handling. One potentially complicated issue is that there is no natural way to set the sh->format (AVCodecContext.codec_tag) field anymore. Most decoders do not need it, though mjpeg is an exception. Note that the AVI compatibility code still requires codec mappings, but these are provided by FFmpeg. Also, the audio code is not changed. For the MKV_V_MPEG2 -> mpeg1video thing see next commit.
* demux_mkv: remove a level of indentationwm42015-06-131-53/+52
| | | | | Replace an else block with a nested if with just "else if". No functional or other changes.
* demux_mkv: remove ms_compat codewm42015-06-131-11/+5
| | | | Reduces the mess slightly.
* demux_mkv: limit timestamp fixing to 1ms maxwm42015-04-231-1/+1
| | | | | And also fix the description. It didn't actually reflect what the code did.
* demux_mkv: attempt to fix rounded timestampswm42015-04-231-1/+18
| | | | | There is some potential for breakage. If it happens, this might have to be disabled by default.
* demux_mkv: move global options to the demuxerwm42015-04-231-8/+38
| | | | | | | The options don't change, but they're now declared and used privately by demux_mkv.c. This also brings with it a minor refactor of the subpreroll seek handling - merge the code from playloop.c into demux_mkv.c. The change in demux.c is pretty much equivalent as well.
* demux_mkv: better seeking after video endwm42015-04-231-15/+7
| | | | | | | | | | | | | | | | | This change allows forward seeking even if there are no more video keyframes in forward direction. This helps with files that e.g. encode cover art as a single video frame (within a _real_ video stream - ffmpeg seems to like to produce such files). Seeking backwards will still jump to the nearest video frame, so this improvement has limited use. The old code didn't do this because of the logic the min_diff variable followed. Instead of somehow using the timestamp of the last packet read for min_diff, use the first index entry for it. This actually makes it fall back to the first/last index entry as the (removed) comment claims. Note that last_pts is basically random at this point (because the demuxer can be far ahead of playback position), so this didn't make sense in the first place.
* Update license headersMarcin Kurczewski2015-04-131-5/+4
| | | | Signed-off-by: wm4 <wm4@nowhere>
* demux_mkv: check for playback abortswm42015-03-091-0/+2
| | | | | | | | | Check async abort notification. libavformat already do something equivalent. Before this commit, the demuxer could enter resync mode (and print silly warning messages) when the stream stopped returning data because of an abort.
* demux_mkv: actually skip elements out of reachwm42015-03-061-1/+2
| | | | | This is missing from the previous commit. Not that harmful, but also slightly un-nice since even a failed seek will reset the cache.
* demux_mkv: fix issues with unseekable streamswm42015-03-061-14/+16
| | | | | | | | | | | | | | | A user reported a webm stream that couldn't be played. The issue was that this stream 1. was on an unseekable HTTP connection, and 2. had a SeekHead element (wtf?). The code reading the SeekHead marked the element as unreadable too early: although you can't seek in the stream, reading the header elements after the SeekHead read them anyway. Marking them as unreadable only after the normal header reading fixes this. (The way the failing stream was setup was pretty retarded: inserting these SeekHead elements makes absolutely no sense for a stream that cannot be seeked.) Fixes #1656.
* buid: readd -Wparentheseswm42015-03-021-2/+2
| | | | | | | | | This warning wasn't overly helpful in the past, and warned against perfectly fine code. But at least with recent gcc versions, this is the warning that complains about assignments in if expressions (why???), so we want to enable it. Also change all the code this warning complains about for no reason.
* demux_mkv: minor refactor for deferred cue readingwm42015-02-251-45/+41
| | | | | | Should behave about the same, but reduces code some duplication with seeking and reading a header element pointed to by a SeekHead. It also makes behavior with incomplete files slightly better.
* demux_mkv: don't spam too many warnings with partial fileswm42015-02-251-14/+15
| | | | | Limit it to a single message. It often printed more than that, and in some cases (old files with "cluster" index), spammed a lot.
* video: remove redundant codec parameterswm42015-02-241-2/+0
| | | | | | | Remove coded_width and coded_height. This was originally added in commit fd7dde40, when BITMAPINFOHEADER was killed. The separate fields became redundant in commit e68f4be1. Remove them (nothing passed to the decoders actually changes with _this_ commit).
* demux, matroska: remove demuxer type fieldwm42015-02-171-1/+0
| | | | | | | | | | | | | The Matroska timeline code was the only thing which still used the demuxer.type field. This field explicitly identifies a demuxer implementation. The purpose of the Matroska timeline code was to reject files that are not Matroska. But it already forces the Matroska format, meaning loading will explicitly only use the Matroska demuxer. If the demuxer can't open the file, no other demuxer will be tried, and thus checking the field is redundant. The change in demux_mkv_timeline.c removes the if condition, and unindents the if body.
* matroska: make timeline code independent of MPContextwm42015-02-171-1/+2
|
* demux: hack for instant stream switchingwm42015-02-131-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This removes the delay when switching audio tracks in mkv or mp4 files. Other formats are not enabled, because it's not clear whether the demuxers fulfill the requirements listed in demux.h. (Many formats definitely do not with libavformat.) Background: The demuxer packet cache buffers a certain amount of packets. This includes only packets from selected streams. We discard packets from other streams for various reasons. This introduces a problem: switching to a different audio track introduces a delay. The delay is as big as the demuxer packet cache buffer, because while the file was read ahead to fill the packet buffer, the process of reading packets also discarded all packets from the previously not selected audio stream. Once the remaining packet buffer has been played, new audio packets are available and you hear audio again. We could probably just not discard packets from unselected streams. But this would require additional memory and CPU resources, and also it's hard to tell when packets from unused streams should be discarded (we don't want to keep them forever; it'd be a memory leak). We could also issue a player hr-seek to the current playback position, which would solve the problem in 1 line of code or so. But this can be rather slow. So what we do in this commit instead is: we just seek back to the position where our current packet buffer starts, and start demuxing from this position again. This way we can get the "past" packets for the newly selected stream. For streams which were already selected the packets are simply discarded until the previous position is reached again. That latter part is the hard part. We really want to skip packets exactly until the position where we left off previously, or we will skip packets or feed packets to the decoder twice. If we assume that the demuxer is deterministic (returns exactly the same packets after a seek to a previous position), then we can try to check whether it's the same packet as the one at the end of the packet buffer. If it is, we know that the packet after it is where we left off last time. Unfortunately, this is not very robust, and maybe it can't be made robust. Currently we use the demux_packet.pos field as unique packet ID - which works fine in some scenarios, but will break in arbitrary ways if the basic requirement to the demuxer (as listed in the demux.h additions) are broken. Thus, this is enabled only for the internal mkv demuxer and the libavformat mp4 demuxer. (libavformat mkv does not work, because the packet positions are not unique. Probably could be fixed upstream, but it's not clear whether it's a bug or a feature.)
* demux_mkv: return unique file positions for all packetswm42015-02-131-4/+5
| | | | | | | | | | | | | Until now, some packets could return the same file position if they were split off from a Matroska-level packet. This was perfectly fine, because the file position isn't used for anything overly important (it uses it to estimate playback position if no other information is available). The following commit will use the demux_packet.pos field as unique ID (as a simplification), so make the demuxer export more finegrained information. Also, the last_filepos field didn't have to be global, at least not anymore.
* demux_mkv: remove the realmedia fieldwm42015-02-051-25/+21
| | | | | | Granted, this doesn't help much with anything, other than the hate- driven desire to remove or at least reduce anything that has to do with RealMedia.
* demux_mkv: reindent, cosmeticswm42015-02-051-97/+79
| | | | | | | | | | Reindent the whole handle_realaudio() function, and make the surrouding if block return early instead. Also contains some cosmetics to the sipr swapping, which hopefully does not change the semantics, but is untested (the kind of cosmetic changes everyone loves so much). May the person responsible for sipr rot in hell. (It was probably done to obfuscate the codec?)
* demux_mkv: simplify realaudio handlingwm42015-02-051-30/+17
| | | | | | | Staring at the code, it doesn't look like the extra code for "normal" audio is needed. Most of it looks like artifacts from the previous code structure (much of it was added in the initial commit). I couldn't find a sample that uses this code path to fully confirm this, though.
* demux_mkv: remove realvideo-specific aspect ratio handlingwm42015-02-051-17/+5
| | | | | | | | I suppose it could lead to subtle changes in behavior in presence of realvideo files that change aspect radio. With the only sample I had available, the behavior actually improved (azumi.mkv from the MPlayer samples FTP; when starting playback in the middle it used the wrong aspect ratio).
* demux_mkv: use libavcodec parser for realvideowm42015-02-051-68/+4
| | | | | | Appears to work, so we can drop some code. For some really odd reason, the descrambling done on the timestamp requires millisecond units (due to the "algorithm", not the libavcodec API).
* demux_mkv: retrieve timestamps from libavcodec parserwm42015-02-051-3/+16
| | | | | | | | | Fixes vp9 missing timestamps. This requires a brand new libavcodec (the patch for this was just applied to FFmpeg git master). The timestamp mangling is applied to VP9 only. It'd probably work with other codecs, but it's not needed. It could break in various ways, so it has to be explicitly checked for every enabled codec.
* demux_mkv: refactor packet parsingwm42015-02-051-83/+102
| | | | | | | | Makes it somewhat more uniform, and breaks up the awfully deep nesting. This implicitly changes multiple small details, rather than only moving code around. In particular, this computes the packet fields first and parses them afterwards, which is needed for the next commit.
* demux_mkv: use unique IDs for cover art pseudo-trackswm42015-02-011-0/+1
| | | | | | | Might fix behavior with mkv files that use ordered chapters and have cover art tags. In my opinion, this should actually have worked (because cover art pseudo-tracks are strictly appended), but I don't have a sample file to test at hand.
* player: demote matroska ordered chapter scanning messages to VerboseDiogo Franco (Kovensky)2015-01-281