summaryrefslogtreecommitdiffstats
path: root/demux/demux_mkv.c
Commit message (Collapse)AuthorAgeFilesLines
* demux_mkv: move preroll subtitle check to the right placewm42013-04-041-2/+2
| | | | | | | | No subtitle selected was supposed to disable the preroll logic completely. However, the packet skipping logic was not properly enabled, so the demuxer would still return subtitle packets from before the seek target timecode. This shouldn't matter at all in practice, but fixing this makes the code clearer.
* demux_mkv: try to show current subtitle when seekingwm42013-04-041-9/+31
| | | | | | | | | | | | | | | | | Makes sure that seeking to a given time position shows the subtitle at that position. This can fail if the subtitle packet is not close enough to the seek target. Always enabled for hr-seeks, and can be manually enabled for normal seeks with --mkv-subtitle-preroll. This helps displaying subtitles correctly with ordered chapters. When switching ordered chapter segments, a seek is performed. If the subtitle is timed slightly before the start of the segment, it normally won't be demuxed. This is a problem with all seeks, but in this case normal playback is affected. Since switching segments always uses hr-seeks, the code added by this commit is always active in this situation. If no subtitles are selected or the subtitles come from an external file, the demuxer should behave exactly as before this commit.
* demux_mkv: fix handling of 0 DisplayWidth/Heightwm42013-04-041-2/+5
| | | | | | | | | Commit 546ae23 fixed aspect ratio if the DisplayWidth or DisplayHeight elements were missing. However, some bogus files [1] can have these elements present in the file, but set to 0. Use 1:1 pixel aspect for such files. [1] https://ffmpeg.org/trac/ffmpeg/ticket/2424
* demux_mkv: don't print non-sense warning on normal EOFwm42013-03-301-1/+1
| | | | | | | | | | | | | | | Commit ac1c5e6 (demux_mkv: improve robustness against broken files) added code to skip to the next cluster on error conditions. However, reaching normal EOF triggers this code as well, so explicitly check for EOF before this happens. Note that the EOF flag is only set _after_ reading the last byte, so EOF needs to be checked after the fact. (Or in other words, we must check for EOF after the ebml_read_id() call.) (To answer the question why reading packets actually reaches EOF, even if there's the seek index between the last packet and the end of the file: the cluster reading code skips the seeking related EBML elements as normal part of operation, so it hits EOF gracefully when trying to find the next cluster.)
* demux_mkv: improve robustness against broken fileswm42013-03-281-7/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes test7.mkv from the Matroska test file collection, as well as some real broken files I've found in the wild. (Unfortunately, true recovery requires resetting the decoders and playback state with a manual seek, but it's still better than just exiting.) If there are broken EBML elements, try harder to skip them correctly. Do this by searching for the next cluster element. The cluster element intentionally has a long ID, so it's a suitable element for resynchronizing (mkvmerge does something similar). We know that data is corrupt if the ID or length fields of an element are malformed. Additionally, if skipping an unknown element goes past the end of the file, we assume it's corrupt and undo the seek. Do this because it often happens that corrupt data is interpreted as correct EBML elements. Since these elements will have a ridiculous values in their length fields due to the large value range that is possible (0-2^56-2), they will go past the end of the file. So instead of skipping them (which would result in playback termination), try to find the next cluster instead. (We still skip unknown elements that are within the file, as this is needed for correct operation. Also, we first execute the seek, because we don't really know where the file ends. Doing it this way is better for unseekable streams too, because it will still work in the non-error case.) This is done as special case in the packet reading function only. On the other hand, that's the only part of the file that's read after initialization is done.
* demux_mkv: fix skipping broken header elementswm42013-03-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | Fixes test4.mkv from the Matroska test file collection. demux_mkv_open() contains a loop that reads header elements. It starts by reading the EBML element ID with ebml_read_id(). If there is broken data in the header, ebml_read_id() might return EBML_ID_INVALID. However, that is not handled specially, and the code for handling unknown tags is invoked. This reads the EBML element length in order to skip data, which, if the EBML ID is broken, is entirely random. This caused a seek beyond the end of the file, making the demuxer fail. So don't skip any data if the EBML ID was invalid, and simply try to read the next element. ebml_read_id() reads at least one byte, so the parsing loop won't get stuck. All in all this is rather questionable, but since this affects error situations only, makes behavior a bit more robust (no random seeks), and actually fixes at least one sample, it's ok. libavformat's demuxer handled this.
* demux_mkv: set correct aspect ratio even if DisplayHeight is unsetwm42013-03-281-2/+4
| | | | | | | Fixes the file test2.mkv from the official Matroska test file collection. libavformat does the same thing.
* demux_mkv: support ALACwm42013-03-151-0/+11
| | | | | Test sample was produced with ffmpeg. Extradata handling closely follows libavformat/matroskadec.c.
* demux_mkv: Support playing Opus streams in MatroskaStephen Hutchinson2013-03-141-0/+5
| | | | | | | | | | | | FFmpeg recently changed how it writes Opus-in-Matroska to match the A_OPUS/EXPERIMENTAL name that mkvmerge uses, with the caveat that things will change and compatibility with old files can get worked out when the spec is finalized. This adds both A_OPUS and A_OPUS/EXPERIMENTAL so that *hopefully* it can play both the newer files that use A_OPUS/EXPERIMENTAL, and older ones muxed by FFmpeg that were simply A_OPUS, since this is also what FFmpeg seems to be doing to handle the situation.
* core: use playback time to determine playback percent positionwm42013-02-261-8/+0
| | | | | | | | | | | | | The percent position is used for the OSD, the status line, and for the OSD bar (shown on seeks). By default, the PTS of the last demuxed packet was used to calculate it. This led to a "jumpy" display when the percentage value (casted to int) was changing. The reasons for this were the presence of video frame reordering (packet PTS is not monotonic), or getting PTS values from different streams (like audio/subs). Since these rely on PTS values and correct file durations anyway, simplify it by calculating it with the current playback position in mplayer.c instead.
* demux_lavf: remove code duplicationwm42013-02-101-2/+2
| | | | | | | | | | Also move the lang field into the general stream header. (SH_COMMON is an old hack to "share" code between audio/video/sub headers.) There should be no functional changes, other than not printing stream info in verbose mode or with slave mode. (The frontend already prints stream info, and this is just a leftover when individual demuxers did this, and slave mode remains broken.)
* core: redo how codecs are mapped, remove codecs.confwm42013-02-101-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use codec names instead of FourCCs to identify codecs. Rewrite how codecs are selected and initialized. Now each decoder exports a list of decoders (and the codec it supports) via add_decoders(). The order matters, and the first decoder for a given decoder is preferred over the other decoders. E.g. all ad_mpg123 decoders are preferred over ad_lavc, because it comes first in the mpcodecs_ad_drivers array. Likewise, decoders within ad_lavc that are enumerated first by libavcodec (using av_codec_next()) are preferred. (This is actually critical to select h264 software decoding by default instead of vdpau. libavcodec and ffmpeg/avconv use the same method to select decoders by default, so we hope this is sane.) The codec names follow libavcodec's codec names as defined by AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders have names different from the canonical codec name. The AVCodecDescriptor API is relatively new, so we need a compatibility layer for older libavcodec versions for codec names that are referenced internally, and which are different from the decoder name. (Add a configure check for that, because checking versions is getting way too messy.) demux/codec_tags.c is generated from the former codecs.conf (minus "special" decoders like vdpau, and excluding the mappings that are the same as the mappings libavformat's exported RIFF tables). It contains all the mappings from FourCCs to codec name. This is needed for demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the codec as determined by libavformat, while the other demuxers have to do this on their own, using the mp_set_audio/video_codec_from_tag() functions. Note that the sh_audio/video->format members don't uniquely identify the codec anymore, and sh->codec takes over this role. Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which provide cover the functionality of the removed switched. Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure container/video combinations (e.g. the sample Film_200_zygo_pro.mov) are played flipped. ffplay/avplay doesn't handle this properly either, so we don't care and blame ffmeg/libav instead.
* demux_mkv: support more formats with V_UNCOMPRESSEDwm42013-01-301-0/+6
| | | | | | | Select the generic raw video decoder in codecs.cfg ("MPrv" FourCC), which forces the generic lavc raw video decoder "rawvideo". This means all FourCCs understood by lavc rawvideo are supported, not just whatever has codecs.cfg entries.
* demux_mkv: support V_UNCOMPRESSED video trackswm42013-01-241-1/+10
| | | | | | Tested with a sample generated by: ffmpeg -i in.mkv -an -vcodec rawvideo out.mkv Also add proper dependencies for the Matroska Perl stuff in Makefile.
* demux_mkv: work around bad OutputSamplingFrequency valuesUoti Urpala2013-01-131-0/+8
| | | | | | | | | Something produces corrupt Matroska files with audio tracks that have SamplingFrequency set to 44100 and OutputSamplingFrequency to 96000, when the correct playback rate is 44100. Add a special case for this 44100/96000 combination and override it to 44100/44100; it's unlikely that anyone would ever want to use this 44100/96000 combination for real in valid files.
* audio: improve decoder open failure handlingUoti Urpala2012-12-031-5/+2
| | | | | | | | | | | | | | | | Reinitialize sh_audio->samplesize and sample_format before falling back to another audio decoder (some decoders rely on default values). Remove code setting these fields from demux_mkv and demux_lavf (no decoder should depend on demuxer-set values for these fields). Conflicts: audio/decode/ad_lavc.c Merged from mplayer2 commit 6b9567. The changes to ad_lavc.c are not merged, as they are very specific to the mplayer2 libavresample hack; we deplanarize manually, so we can't get unsupported sample formats yet (except on raw audio with "pcm_f64le", as we don't support AV_SAMPLE_FMT_DBL in the audio chain).
* stream, demux: replace off_t with int64_twm42012-11-201-10/+10
| | | | | | On reasonable systems, these types were the same anyway. Even on unreasonable systems (seriously, which?), this may reduce potential breakage.
* Rename directories, move files (step 2 of 2)wm42012-11-121-4/+4
| | | | | | | | | | | | Finish renaming directories and moving files. Adjust all include statements to make the previous commit compile. The two commits are separate, because git is bad at tracking renames and content changes at the same time. Also take this as an opportunity to remove the separation between "common" and "mplayer" sources in the Makefile. ("common" used to be shared between mplayer and mencoder.)
* Rename directories, move files (step 1 of 2) (does not compile)wm42012-11-121-0/+2558
Tis drops the silly lib prefixes, and attempts to organize the tree in a more logical way. Make the top-level directory less cluttered as well. Renames the following directories: libaf -> audio/filter libao2 -> audio/out libvo -> video/out libmpdemux -> demux Split libmpcodecs: vf* -> video/filter vd*, dec_video.* -> video/decode mp_image*, img_format*, ... -> video/ ad*, dec_audio.* -> audio/decode libaf/format.* is moved to audio/ - this is similar to how mp_image.* is located in video/. Move most top-level .c/.h files to core. (talloc.c/.h is left on top- level, because it's external.) Park some of the more annoying files in compat/. Some of these are relicts from the time mplayer used ffmpeg internals. sub/ is not split, because it's too much of a mess (subtitle code is mixed with OSD display and rendering). Maybe the organization of core is not ideal: it mixes playback core (like mplayer.c) and utility helpers (like bstr.c/h). Should the need arise, the playback core will be moved somewhere else, while core contains all helper and common code.