Commit Graph

319 Commits

Author SHA1 Message Date
wm4 c827ae5f36 demux_mkv: adjust subtitle preroll again
Revert commit 24e52f66; even though the old beheavior doesn't make sense
(as the commit message assured), it turns out that this works better:
typically, it means preroll will start from the previous video key frame
(the video CUE index will contain clusters with video key frames only),
which often coincides with subtitle changes. Thus the old behavior is
actually better.

Change the code that uses CueDuration elements. Instead of merely
checking whether preroll should be done, find the first cluster that
needs to be read to get all subtitle packets. (The intention is to
compensate for the enlarged preroll cluster-range due to reverting
commit 24e52f66.)
2014-11-11 19:36:03 +01:00
wm4 b77ac78fed demux_mkv: fix indentation
Meh.
2014-11-05 23:17:55 +01:00
wm4 24e52f6643 demux_mkv: for subtitle preroll, consider all clusters
This considered only index entries that were for the same track ID as
the track used for seeking. This doesn't make much sense for preroll;
it'll just possibly skip clusters, and select an earlier cluster.

One possible negative side-effect is that the preroll might be too tight
now, and miss subtitle packets more often.
2014-11-05 21:54:28 +01:00
wm4 6ab364df4b demux_mkv: apply subtitle preroll only if needed, based on cue index
The demuxer has a hack to seek to the cluster before the target cluster
in order to "catch" subtitle lines that start before the seek target,
but overlap with the video after the seek target.

Avoid this hack if the cue index indicates that there are no overlapping
subtitle packets that can be caught by seeking to the previous cluster.
2014-11-05 21:52:20 +01:00
wm4 805e952d82 demux_mkv: read CueRelativePosition/CueDuration elements
Nothing is done with them yet. This is preparation for the following
commit.

CueRelativePosition isn't even saved anywhere, because I don't intend to
use it. (Too messy for no gain.)
2014-11-05 21:52:07 +01:00
wm4 8f992515cd demux_mkv: index all packets
Instead of indexing only 1 packet per cluster (which is enough for
working seeking), add every packet to the index.

Since on seek, we go through every single index entry, this probably
makes seeking slower. On the other hand, this code is used for files
without index only (e.g. incomplete files), so it probably doesn't
matter much.

Preparation for the following commits.
2014-11-05 21:51:43 +01:00
wm4 458a766dc9 demux_mkv: remove minor code duplication 2014-11-03 20:25:21 +01:00
wm4 4e87ac8231 demux_mkv: implement audio skipping/trimming
This mechanism was introduced for Opus, and allows correct skipping of
"preroll" data, as well as discarding trailing audio if the file's
length isn't a multiple of the audio frame size.

Not sure how to handle seeking. I don't understand the purpose of the
SeekPreRoll element.

This was tested with correctness_trimming_nobeeps.opus, remuxed to mka
with mkvmerge v7.2.0. It seems to be correct, although the reported file
duration is incorrect (maybe a mkvmerge issue).
2014-11-03 20:20:28 +01:00
wm4 969757baa0 player: always use demux_chapter
Instead of defining a separate data structure in the core.

For some odd reason, demux_chapter exported the chapter time in
nano-seconds. Change that to the usual timestamps (rename the field
to make any code relying on this to fail compilation), and also remove
the unused chapter end time.
2014-11-02 17:29:41 +01:00
wm4 71e73b6c8e demux: move some seek flag sanitation to generic code
No reason why only demux_mkv.c should do this.
2014-10-29 22:45:21 +01:00
wm4 a1083fb461 demux_mkv: implement percentage seeking with no index
It was implemented only for the case the index exists (pretty useless).
2014-10-29 22:34:40 +01:00
wm4 f2f9d23e79 demux_mkv: export packet file position
This gives us approximate fallback playback percentage position if the
duration is unknown.
2014-10-29 22:08:50 +01:00
wm4 057384baa6 demux_mkv: fix undefined behavior
With some files, the extradata variable can remain uninitialized, but
will be used for memory access.

CC: @mpv-player/stable (with high priority)
2014-10-13 16:42:00 +02:00
wm4 fdf40743bc demux_mkv: don't use default_duration for parsed packets
Makes it behave slightly better for VP9. This is also the behavior
libavformat has.

Also while we're at it, don't set duration except for the first packet.
Normally we don't use the duration except for subtitles (which are never
parsed or "laced"), so this should make no observable difference.
2014-09-26 01:25:48 +02:00
wm4 7aa933cc9e demux_mkv: get rid of MS structs
See previous commits. This finally replaces directly reading the file
data into a struct with reading them manually. In theory this is more
portable (no alignment issues and other things). For the most part,
it's nice seeing this gone.
2014-09-25 02:22:50 +02:00
wm4 9c3c199558 audio: remove WAVEFORMATEX from internal demuxer API
Same as with the previous commit. A bit more involved due to how the
code is written.
2014-09-25 01:56:51 +02:00
wm4 fd7dde404d video: remove BITMAPINFOHEADER from internal demuxer API
MPlayer traditionally did this because it made sense: the most important
formats (avi, asf/wmv) used Microsoft formats, and many important
decoders (win32 binary codecs) also did. But the world has changed, and
I've always wanted to get rid of this thing from the codebase.

demux_mkv.c internally still uses it, because, guess what, Matroska has
a VfW muxing mode, which uses these data structures natively.
2014-09-25 00:59:15 +02:00
wm4 caaeb15318 demux: gracefully handle packet allocation failures
Now the packet allocation functions can fail.
2014-09-16 18:11:00 +02:00
wm4 d9aaf78530 demux_mkv: allow up to 256 MB of extradata to make broken files work
What the flying fuck?

Unfortunately, these are already in the wild.

CC: @mpv-player/stable
2014-09-04 19:20:47 +02:00
wm4 8599c959fe video: initial Matroska 3D support
This inserts an automatic conversion filter if a Matroska file is marked
as 3D (StereoMode element). The basic idea is similar to video rotation
and colorspace handling: the 3D mode is added as a property to the video
params. Depending on this property, a video filter can be inserted.

As of this commit, extending mp_image_params is actually completely
unnecessary - but the idea is that it will make it easier to integrate
with VOs supporting stereo 3D mogrification. Although vo_opengl does
support some stereo rendering, it didn't support the mode my sample file
used, so I'll leave that part for later.

Not that most mappings from Matroska mode to vf_stereo3d mode are
probably wrong, and some are missing.

Assuming that Matroska modes, and vf_stereo3d in modes, and out modes
are all the same might be an oversimplification - we'll see.

See issue #1045.
2014-08-30 23:24:46 +02:00
shdown e2ecf3d03d demux_mkv: eliminate redundant branch
In the else branch pict_type is always 3, so pict_type != 3 is always
false. (Note that I have no idea of what it was supposed to do and it is
just an equivalent of the old behaviour.)
2014-08-30 15:15:37 +02:00
wm4 68ff8a0484 Move compat/ and bstr/ directory contents somewhere else
bstr.c doesn't really deserve its own directory, and compat had just
a few files, most of which may as well be in osdep. There isn't really
any justification for these extra directories, so get rid of them.

The compat/libav.h was empty - just delete it. We changed our approach
to API compatibility, and will likely not need it anymore.
2014-08-29 12:31:52 +02:00
wm4 d1bb1bf8af demux: fix timestamp type for seek calls
mpv/mplayer2/MPlayer use double for timestamps, but the demuxer API used
float.
2014-07-21 19:29:58 +02:00
wm4 de28876222 demux: minor simplification
Oops, should have been part of commit 37085788.
2014-07-06 19:02:21 +02:00
wm4 37085788e4 demux: minor simplification to internal API
Also some other unrelated minor changes.
2014-07-05 17:07:15 +02:00
wm4 44d7499190 demux_mkv: cosmetics 2014-07-05 17:07:14 +02:00
wm4 bb131f4c66 demux_mkv: minor improvement to overflow check
CC: @mpv-player/stable
2014-07-02 00:14:18 +02:00
wm4 9a210ca2d5 Audit and replace all ctype.h uses
Something like "char *s = ...; isdigit(s[0]);" triggers undefined
behavior, because char can be signed, and thus s[0] can be a negative
value. The is*() functions require unsigned char _or_ EOF. EOF is a
special value outside of unsigned char range, thus the argument to the
is*() functions can't be a char.

This undefined behavior can actually trigger crashes if the
implementation of these functions e.g. uses lookup tables, which are
then indexed with out-of-range values.

Replace all <ctype.h> uses with our own custom mp_is*() functions added
with misc/ctype.h. As a bonus, these functions are locale-independent.
(Although currently, we _require_ C locale for other reasons.)
2014-07-01 23:11:08 +02:00
wm4 dd9420471f demux_mkv: cosmetics 2014-06-29 23:28:47 +02:00
wm4 37251cef69 demux_mkv: add some overflow checks etc.
Some of these might be security relevant.

The RealAudio code was especially bad. I'm not sure if all RealAudio
stuff still plays correctly; I didn't have that many samples for
testing. Some checks might be unnecessary or overcomplicated compared
to the (obfuscated) nature of the code.

CC: @mpv-player/stable
2014-06-29 23:27:28 +02:00
wm4 8ffef4be92 demux_mkv: add S_DVBSUB
Probably works; untested.
2014-06-17 22:44:27 +02:00
wm4 98a31d5937 options: turn --idx, --forceidx into --index
Also clarify the semantics.

It seems --idx didn't do anything. Possibly it used to change how the
now removed legacy demuxers like demux_avi used to behave. Or maybe
it was accidental.

--forceidx basically becomes --index=force. It's possible that new
index modes will be added in the future, so I'm keeping it
extensible, instead of e.g. creating --force-index.
2014-06-13 02:05:37 +02:00
wm4 99f5fef0ea Add more const
While I'm not very fond of "const", it's important for declarations
(it decides whether a symbol is emitted in a read-only or read/write
section). Fix all these cases, so we have writeable global data only
when we really need.
2014-06-11 00:39:14 +02:00
wm4 a4d487f5b2 stream: don't use end_pos
Stop using it in most places, and prefer STREAM_CTRL_GET_SIZE. The
advantage is that always the correct size will be used. There can be no
doubt anymore whether the end_pos value is outdated (as it happens often
with files that are being downloaded).

Some streams still use end_pos. They don't change size, and it's easier
to emulate STREAM_CTRL_GET_SIZE using end_pos, instead of adding a
STREAM_CTRL_GET_SIZE implementation to these streams.

Make sure int64_t is always used for STREAM_CTRL_GET_SIZE (it was
uint64_t before).

Remove the seek flags mess, and replace them with a seekable flag. Every
stream must set it consistently now, and an assertion in stream.c checks
this. Don't distinguish between streams that can only be forward or
backwards seeked, since we have no such stream types.
2014-05-24 16:17:51 +02:00
wm4 eb3cc32f9b demux_mkv: enable parsing for VP9
VP9 packets can contain 2 frames in some video packets (from which 1
frame is invisible). Due to a design mismatch between libvpx and the
libavcodec vp9 decoder, libvpx can take the "full" packets, but lavc vp9
can not. The consequence is that we have to split the packets if we want
to feed them to the lavc codec.

This is not entirely correct yet: timestamp handling is missing.
--demuxer=lavf and ffmpeg native utilities have the same problem. We can
fix this only once the ffmpeg VP9 parser is fixed.
2014-04-26 22:24:15 +02:00
wm4 ca320f6e69 demux_mkv: enable parsing for mp3
For some reason, some files appear to have broken mp3 packets, or at
least in a form that libavcodec can't deal with. The audio in the sample
file in question could not be decoded using libavcodec.

The problematic file had variable packet sizes, and the libavcodec
decoder kept printing "mp3: Header missing" for each packet it was fed.
Remuxing with mkvmerge fixes the problem. The mp3 data is probably not
VBR, and remuxing resulted in fixed-size mp3 frames. So I don't know why
the sample file was muxed this way - it might just be incorrect.

The sample file had "libmkv 0.6.4" as MuxingApp (although I could not
get mkvinfo to print this element, maybe the file uses an incorrect
element ID), and "HandBrake 0.9.4" as WritingApp.

Note that the libmpg123 decoder does not have any issues with it. It's
probably more robust, because libmpg123 was made to decode whole mp3
files, not just single frames.

Fixes issue #742.
2014-04-25 08:36:58 +02:00
wm4 64c01a814c Remove some more unneeded version checks
All of these check against things that happened before the latest
supported FFmpeg/Libav release.
2014-03-16 13:19:28 +01:00
wm4 7aa3726c9a demux_mkv: remove weird seeking semantics for audio
This skipped all audio packets before the first video key frame was
found. I'm not really sure why this would be needed; most likely it
isn't. So get rid of it. Even if audio packets are returned to the
player too soon, the player will sync the audio start to the video
start by decoding and discarding audio data.

Note that although the removed code was just added in the previous
commit, it merely kept the old keeping semantics which demux_mkv
always followed. This commit removes these special semantics.
2014-02-09 21:13:03 +01:00
wm4 4dbd5df174 demux_mkv: improve audio-only seeking
v_skip_to_keyframe is set to true while non-keyframe video packets are
skipped. Until now, audio packets were also skipped when doing this. I
can't see any good reason why this would be done, but for now I want to
keep the old logic when audio+video seeks are done.

However, for audio-only mode, do proper seeking, which also fixes
behavior when trying to seek past the end of the file: playback is
terminated properly, instead of starting playback on the start of the
last cluster.

Note that a_no_timecode_check is used only for audio+video seek. I'm
not sure what this is needed for, but it might influence A/V sync after
seeking.
2014-02-09 20:50:24 +01:00
wm4 bc35d4fcb4 demux: fill metadata directly, instead of using wrapper functions
Get rid of demux_info_add[_bstr] and demuxer_add_chapter_info.

Make demuxer_add_chapter_info return the chapter index for convenience.
2014-02-06 13:43:01 +01:00
wm4 2305ffcaba demux_mkv: remove unused field 2014-01-31 19:49:48 +01:00
wm4 af5c393d2c demux_mkv: nicer edition output
If there's more than one edition, print the list of editions, including
the edition name, whether the edition is selected, whether the edition
is default, and the command line option to select the edition. (Similar
to stream list.)

Move reading the tags to a separate function process_tags(), which is
called when all other state is parsed. Otherwise, that tags will be lost
if chapters are read after the tags.
2014-01-23 00:54:08 +01:00
wm4 16534bbd81 demux_mkv: don't attempt to seek back when indexing
Pretty worthless. This is called from the seek code, which will
reinitialize these anyway. Even if seeking somehow decides to fail, the
new values are still valid.

One could say a failed seek (if that happens) should jump back to the
original position, and thus it would be better to make sure the state
is restored. But then demux_mkv_seek needs to do this correctly,
including not setting up skipping to the target timestamp. But not
bothering with this.
2014-01-22 23:48:57 +01:00
wm4 63fdeb79be demux_mkv: fix EOF with concatenated segments
Extremely obscure corner case with concatenated segments, in which EOF
wasn't recognized correctly, and it tried to demux clusters from the
next segment.

See [MKV]_Editions,_Linked_Segments,_&_Tracksets.mkv from the CCCP test
file collection.
2014-01-22 23:37:03 +01:00
wm4 f3db4b0b93 demux_mkv: remove old track printing code
This basically used to be part of the user interface, before mpv moved
printing the track list to the frontend, and this code was raised to
verbose output level.
2014-01-22 22:37:26 +01:00
wm4 774eb1d98d demux_mkv: always fail on header reading error
For some reason, if an error happened when reading headers, it merely
stopped reading the headers, and then continued normally. (It looks like
the case to exit hard (-2) was mainly used for skipping unwanted ordered
chapter segments.)

I can't comprehend this. Always exit on error when reading headers.
(Maybe some more error tolerance would be good, but I have no test case,
and there's some danger of entering endless loops.)
2014-01-22 22:33:55 +01:00
wm4 85bd178dbe demux_mkv: avoid seeking when reading headers
This makes everything more robust, and also somewhat simpler (even if
the diffstat isn't very impressive).

Instead of recursively following SeekHeads while reading headers, just
read the headers until the first cluster, and then possibly use
SeekHeads to read the remaining missing headers.
2014-01-22 22:17:01 +01:00
wm4 e32adef9c4 ebml: remove length parameters from read functions
Many ebml_read_* functions have a length int pointer parameter, which
returns the number of bytes skipped. Nothing actually needed this
(anymore), and code using it was rather hard to understand, so get rid
of them.
2014-01-14 17:38:51 +01:00
wm4 72d5273bc1 demux_mkv: remove unused macros 2014-01-14 17:38:32 +01:00
wm4 3c2f93aec8 demux_mkv: improve robustness by explicitly checking for level 1 elements
Matroska makes it pretty hard to resync correctly on broken files:
random data returns "valid" EBML IDs with a high probability, and when
trying to skip them it's likely that you skip a random amount of data
(instead of considering the element length invalid).

Improve upon this by skipping known level 1 elements only. Consider
everything else invalid and call the resync code. This might result in
annoying behavior when Matroska adds new level 1 elements, although it
won't be particularly harmful. Matroska doesn't really allow us to do
better (even mkvtoolnix explicitly checks for known level 1 elements).

Since we now don't always want to combine EBML element skipping and
resyncing, remove ebml_read_skip_or_resync_cluster(), and make
ebml_read_skip() more tolerant against skipping broken elements.

Also, don't resync when reading sub-elements, and instead do resyncing
when reading them results in an error.
2014-01-14 17:38:21 +01:00
wm4 ae27e13a0a demux_mkv: avoid skipping too much data in corrupted files
Until now, corrupted files were detected if the size of an element (that
should be skipped) was larger than the remaining file. This still could
skip larger regions of the file itself if the broken size happened to be
within the file.

Change it so that it's never allowed to skip outside the parent's
element.
2014-01-14 17:38:08 +01:00
wm4 3e562583e5 demux_mkv: handle TrueHD properly
Apparently, Matroska packs TrueHD packets in a way lavc doesn't expect.
This broke decoding of some files [1] completely. A short look at the
libavcodec parser shows that parsing this ourselves would probably be
too much work, so make use of the libavcodec parser API.

[1] http://www.cccp-project.net/beta/test_files/mzero_truehd_sample.mkv
2013-12-27 20:00:24 +01:00
wm4 3dbc9007b0 demux: mp_msg conversions
The TV code pretends to be part of stream/, but it's actually demuxer
code too. The audio_in code is shared between the TV code and
stream_radio.c, so stream_radio.c needs a small hack until stream.c is
converted.
2013-12-21 21:43:16 +01:00
wm4 0112143fda Split mpvcore/ into common/, misc/, bstr/ 2013-12-17 02:39:45 +01:00
wm4 eb15151705 Move options/config related files from mpvcore/ to options/
Since m_option.h and options.h are extremely often included, a lot of
files have to be changed.

Moving path.c/h to options/ is a bit questionable, but since this is
mainly about access to config files (which are also handled in
options/), it's probably ok.
2013-12-17 02:07:57 +01:00
wm4 7dc7b900c6 Replace mp_tmsg, mp_dbg -> mp_msg, remove mp_gtext(), remove set_osd_tmsg
The tmsg stuff was for the internal gettext() based translation system,
which nobody ever attempted to use and thus was removed. mp_gtext() and
set_osd_tmsg() were also for this.

mp_dbg was once enabled in debug mode only, but since we have log level
for enabling debug messages, it seems utterly useless.
2013-12-16 20:41:08 +01:00
wm4 50b3cfa221 demux_mkv: don't seek outside of the file when finding segments
The end of the current segment will be the end of the file if there is
no next segment. Normally, this didn't matter much, since UNIX files
allow seeking past the end of the file. But when opening files from
HTTP, this would print confusing error messages. So explicitly check for
EOF before trying to read a segment.
2013-12-14 21:55:03 +01:00
wm4 dc0b2046cd video: add insane hack to work around FFmpeg/Libav insanity
So, FFmpeg/Libav requires us to figure out video timestamps ourselves
(see last 10 commits or so), but the methods it provides for this aren't
even sufficient. In particular, everything that uses AVI-style DTS (avi,
vfw-muxed mkv, possibly mpeg4-in-ogm) with a codec that has an internal
frame delay is broken. In this case, libavcodec will shift the packet-
to-image correspondence by the codec delay, meaning that with a delay=1,
the first AVFrame.pkt_dts is not 0, but that of the second packet. All
timestamps will appear shifted. The start time (e.g. the time displayed
when doing "mpv file.avi --pause") will not be exactly 0.

(According to Libav developers, this is how it's supposed to work; just
that the first DTS values are normally negative with formats that use
DTS "properly". Who cares if it doesn't work at all with very common
video formats? There's no indication that they'll fix this soon,
either. An elegant workaround is missing too.)

Add a hack to re-enable the old PTS code for AVI and vfw-muxed MKV.
Since these timestamps are not reorderd, we wouldn't need to sort them,
but it's less code this way (and possibly more robust, should a demuxer
unexpectedly output PTS).

The original intention of all the timestamp changes recently was
actually to get rid of demuxer-specific hacks and the old timestamp
sorting code, but it looks like this didn't work out. Yet another case
where trying to replace native MPlayer functionality with FFmpeg/Libav
led to disadvantages and bugs. (Note that the old PTS sorting code
doesn't and can't handle frame dropping correctly, though.)

Bug reports:

 https://trac.ffmpeg.org/ticket/3178

 https://bugzilla.libav.org/show_bug.cgi?id=600
2013-11-28 15:20:33 +01:00
wm4 f1eb30a476 demux_mkv: fix realvideo timestamp handling
This was broken by the recent commits. Apparently realvideo timestamps
are severely mangled, and Matroska _of course_ doesn't have the sane,
umangled timestamps, but something unusable. The existing unmangling
code in demux_mkv.c didn't output proper timestamps either. Instead,
it was something weird that triggered sorting. Without sorting (it was
disabled by default recently), you'd get decreasing PTS warnings

In order to fix this, steal some code from libavcodec. Basically copy
the contents of rv34_parser.c (with some changes), which makes
everything magically work. (Maybe it would be better to use the
libavcodec parser API, but I don't want to do that just for this. An
alternative idea would be refusing to read files that have realvideo
tracks, and delegate this to demux_lavf.c, but maybe that's too redical
too.)

I wish I hadn't notice this...
2013-11-26 23:43:56 +01:00
wm4 b5b1692593 video: disable PTS sorting fallback by default
It appears PTS sorting was useful only for avi files (and VfW-muxed
mkv). Maybe it was historically also important for decoders with broken
or non-existent PTS reordering (win32 codecs?). But now that we handle
demuxers which outputs DTS only correctly, it just seems dead weight.

Disable it by default. The --pts-association-mode option is now forced
to always use the decoder's PTS value. You can still enable the old
default (auto) or force sorting. But we will probably remove this option
entirely at some point.

Make demux_mkv export timestamps at DTS when it's in VfW mode. This is
needed to get correct timestamps with the new default mode. demux_lavf
already does that.
2013-11-25 23:14:54 +01:00
wm4 904c73d2d2 demux: remove gsh field from sh_audio/sh_video/sh_sub
This used to be needed to access the generic stream header from the
specific headers, which in turn was needed because the decoders had
access only to the specific headers. This is not the case anymore, so
this can finally be removed again.

Also move the "format" field from the specific headers to sh_stream.
2013-11-23 21:37:56 +01:00
wm4 a2a24b957e demux: simplify handling of filepos field
demuxer->filepos contains the byte offset of the last read packet. This
is so that the player can estimate the current playback position, if no
proper timestamps are available. Simplify it to use demux_packet->pos in
the generic demuxer code, instead of bothering every demuxer
implementation about it.

(Note that this is still a bit incorrect: it relfects the position of
the last packet read by the demuxer, not that returned to the user. But
that was already broken, and is not that trivial to fix.)
2013-11-16 21:46:17 +01:00
wm4 e91edf9aed demux: use talloc for certain stream headers
Slightly simplifies memory management. This might make adding a demuxer
cache wrapper easier at a later point, because you can just copy the
complete stream header, without worrying that the wrapper will free the
individual stream header fields.
2013-11-14 19:52:18 +01:00
wm4 d8882bbfb7 demux_mkv: support some raw PCM variants
This affects 64 bit floats and big endian integer PCM variants
(basically crap nobody uses). Possibly not all MS-muxed files work, but
I couldn't get or produce any samples.

Remove a bunch of format tags that are not needed anymore. Most of these
were used by demux_mov, which is long gone. Repurpose/abuse 'twos' as
mpv-internal tag for dealing with the PCM variants mentioned above.
2013-11-11 18:40:59 +01:00
wm4 b74edd4069 demux_mkv: fix compiler warnings
Make TOOLS/matroska.pl output structs with fields sorted by name in
ebml_types.h to make the order of fields deterministic. Fix warnings in
demux_mkv.c caused by the first struct fields switching between scalar
and struct types due to non-deterministic ebml_types.h field order.
Since it's deterministic now, this shouldn't change anymore.

The warnings produced by the compilers are bogus, but we want to silence
them anyway, since this could make developers overlook legitimate
warnings.

What commits 7b52ba8, 6dd97cc, 4aae1ff were supposed to fix. An earlier
attempt sorted fields in the generated C source file, not the header
file. Hopefully this is the last commit concerning this issue...
2013-11-04 23:49:22 +01:00
wm4 f7b2d644ef Merge branch 'master' into have_configure
Conflicts:
	configure
2013-11-04 00:43:06 +01:00
Stefano Pigozzi 37388ebb0e configure: uniform the defines to #define HAVE_xxx (0|1)
The configure followed 5 different convetions of defines because the next guy
always wanted to introduce a new better way to uniform it[1]. For an
hypothetic feature 'hurr' you could have had:

  * #define HAVE_HURR 1   / #undef HAVE_DURR
  * #define HAVE_HURR     / #undef HAVE_DURR
  * #define CONFIG_HURR 1 / #undef CONFIG_DURR
  * #define HAVE_HURR 1   / #define HAVE_DURR 0
  * #define CONFIG_HURR 1 / #define CONFIG_DURR 0

All is now uniform and uses:
  * #define HAVE_HURR 1
  * #define HAVE_DURR 0

We like definining to 0 as opposed to `undef` bcause it can help spot typos
and is very helpful when doing big reorganizations in the code.

[1]: http://xkcd.com/927/ related
2013-11-03 21:59:54 +01:00
wm4 a49ab7cc2f demux: make determining seek capability generic
Instead of having each demuxer do it (only demux_mkv actually did...),
let generic code determine whether the file is seekable. This requires
adding exceptions to demuxers where the stream is not seekable, but the
demuxer is.

Sort-of try to improve handling of unseekable files in the player. Exit
early if the file is determined to be unseekable, instead of resetting
all decoders and then performing a pointless seek.

Add an exception to allow seeking if the file is not seekable, but the
stream cache is enabled. Print a warning in this case, because seeking
outside the cache (which we can't prevent since the demuxer is not aware
of this problem) still messes everything up.
2013-11-03 19:21:47 +01:00
wm4 847cbe9d5d demux: remove movi_start/movi_end fields
Pointless, using stream->start_pos/end_pos instead.

demux_mf was the only place where this was used specially, but we can
rely on timestamps instead for this case.
2013-11-03 18:50:00 +01:00
wm4 4d903127ad demux: rename Windows symbols
There are some Microsoft Windows symbols which are traditionally used by
the mplayer core, because it used to be convenient (avi was the big
format, using binary windows decoders made sense...). So these symbols
have the exact same definition as the Windows one, and if mplayer is
compiled on Windows, the symbols from windows.h are used.

This broke recently just because some files were shuffled around, and
the symbols defined in ms_hdr.h collided with windows.h ones. Since we
don't have windows binary decoders anymore, there's not the slightest
reason our symbols should have the same names. Rename them to reduce the
risk for collision, and to fix the recent regression.

Drop WAVEFORMATEXTENSIBLE, because it's mostly unused. ao_dsound defines
its own version if the windows headers don't define it, and ao_wasapi is
not available on systems where this symbol is missing.

Also reindent ms_hdr.h.
2013-11-02 15:14:12 +01:00
wm4 7b52ba87a3 demux_mkv: fix warning
Now that matroska.pl generates struct fields in deterministic order,
this should be the last time I change this.

(gcc and clang shouldn't warn about this line of code, but since they
do, we want to workaround and silence the warning anyway.)
2013-11-02 02:51:23 +01:00
wm4 4aae1ff6de demux_mkv: use a more universal zero initializer
Unfortunately, we can't avoid this warning 100%, because ebml_info is
written by a Perl script. I think the script writes the struct fields in
random order (thanks Perl), so there's no way to know whether the first
struct field is a scalar or a struct.

At least {0} is always valid here, even if it shows a warning. (The
compilers are wrong, see e.g. [1].)

[1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
2013-11-01 13:01:54 +01:00
wm4 280c8351ac demux_mkv: use standard C default initialization syntax
gcc and clang happen to allow {} to default-initialize a struct, but
strictly speaking, C99 requires at least {0}. In one case, we use {{0}},
but that's only because gcc as well as clang are too damn stupid not
to warn about {0}, which is a perfectly valid construct in this case.

(Sure is funny, don't warn about the non-standard case, but warn about
another standard conform case.)
2013-10-19 23:15:06 +02:00
wm4 47bd0a6614 demux_mkv: cosmetics: add redundant braces for consistent style
Leaving these braces away just because the syntax allows them is really
obnoxious. It removes the visual cues which help understanding the code
at the first look.

For the record,

  if (cond)
      something();

is ok, as long as there's no else branch, and the if body is one
physical line. But everything else should have braces.
2013-10-19 23:10:03 +02:00
wm4 6d5e887a20 demux_mkv: fill ordered chapters info only if it's present
This was probably not a real problem. But it's not entirely clear
whether this could actually happen or not, so it's better to be
defensive. The code is now also somewhat easier to understand.
2013-10-19 23:02:53 +02:00
wm4 af0306d48d Merge Matroska ordered chapter changes
This adds support for ChapterSegmentEditionUID (pull request #258),
and also fixes issue #278 (pull request #292).

In fact, this is a straight merge of pr/292, which also contains pr/258.
2013-10-17 00:32:14 +02:00
wm4 d3c140bbf2 demux_mkv: add support for HEVC
Note that you still need --vd-lavc-o='strict=-2' to enable the decoder.

Also, there's no guarantee that all required features for HEVC demuxing
are actually implemented, nor that the current muxing schema is the
final one.
2013-10-16 00:47:52 +02:00
Ben Boeckel 2fe2be4df3 matroska: select the edition using the requested edition uid 2013-10-07 22:42:40 -04:00
Ben Boeckel 069a2d047d matroska: set the edition uid when reading a chapter reference 2013-10-07 22:40:40 -04:00
Ben Boeckel 4f287f1792 matroska: parse the requested edition for the segment reference 2013-10-07 22:40:40 -04:00
Ben Boeckel 07fbba3935 matroska: store segment/edition uids in a single structure
To support edition references in matroska chapters, editions need to be
remembered for each chapter and source. To facilitate easier management
of these now-paired uids, a single structure is used.
2013-10-07 22:40:39 -04:00
Ben Boeckel 9f149717a6 matroska: prevent uids from being dereferenced when NULL
The old code prevented it since uids being NULL makes a 0 talloc length.
Now that we're iterating over a specific length, NULL can be
dereferenced.
2013-09-27 08:45:02 +02:00
Ben Boeckel 828a952c9a matroska: fix uninitialized memory accesses with ordered chapters
There is uninitialized memory access if the actual size isn't passed
along. In the worst case, this can cause a source to be loaded against
the uninitialized memory, causing a false count of found versus required
sources, preventing the "Failed to find ordered chapter part" message.
2013-09-26 18:20:32 +02:00
wm4 4a3ceac2b5 demux_mkv: don't add too many subtitle packets during seeking
In insane files with a very huge number of subtitle events, and if the
--demuxer-mkv-subtitle-preroll option is given, seeking can still
overflow the packet queue. Normally, the subtitle_preroll variable
specifies the maximum number of packets that can be added. But once this
number is reached, the normal seeking behavior is enabled, which will
add all subtitle packets with the right timestamps to the packet queue.
At this point the next video keyframe can still be quite far away, with
enough subtitle packets on the way to overflow the packet queue.

Fix this by always setting an upper limit of subtitle packets read
during seeking. This should provide additional robustness even if the
preroll option is not used.

This means that even with normal seeking, at most 500 subtitle packets
are demuxed. Packets after that are discarded.

One slightly questionable aspect of this commit is that subtitle_preroll
is never reset in audio-only mode, but that is probably ok.
2013-09-16 00:46:14 +02:00
wm4 1b4d9b26cb demux: keep title chapter tag in uppercase
This is generally more uniform.

Do the same for the file global title in demux_mkv.c, although that is
not strictly related to chapters.
2013-09-08 23:07:02 +02:00
wm4 f5195cc4e7 demux_mkv: support V_PRORES
Why not...

Code for demangling Matroska-style prores video packets inspired by
libavformat's Matroska demuxer.
2013-09-08 23:05:18 +02:00
wm4 35fd083828 demux: retrieve per-chapter metadata
Retrieve per-chapter metadata, but don't do much with it. We just make
the metadata of the _current_ chapter available as chapter-metadata
property. Returning the full chapter list with metadata would be no
problem, except that the property interface isn't really good with
structured data, so it's not available for now.

Not sure if it's worth it, but it was requested via github issue #201.
2013-09-08 07:43:23 +02:00
wm4 222b8c6e02 demux_mkv: don't overflow packet queue when doing sub-preroll
Consider the cluster used for prerolling contains an insane amount of
subtitle packets. Then the demuxer packet queue would be full of
subtitle packets, and demux.c would refuse to read any further packets -
including video and audio packets, resulting in EOF. Since everything
involving Matroska and subtitles is 100% insane, this can actually
happen.

Fix this by putting a limit on the number of subtitle packets read by
preroll, and throw away any further packets if the limit is exceeded. If
this happens, the preroll mechanism will stop working, but the player's
operation is unaffected otherwise.
2013-09-08 05:09:16 +02:00
wm4 402f85f7f2 sub: add webvtt-in-webm support
The way this was added to FFmpeg is less than ideal, because it requires
text parsing in the Matroska demuxer. But in order to use the FFmpeg
webvtt-to-ass converter, we still have to mimic this in some way. We do
this by putting the parsing into sd_lavc_conv.c, before the subtitle
packet is passed to libavcodec. At least this keeps the ugliness out of
unrelated code.

There is some change that FFmpeg will fix their design eventually.

Instead of rewriting the parsing code, we simply borrow it from FFmpeg's
Matroska demuxer.
2013-08-24 15:17:37 +02:00
wm4 1e649f353b demux: remove unused audio_delay parameter from demux_seek()
Used to be needed by demux_avi.
2013-08-22 19:14:26 +02:00
wm4 74e3a29606 options: replace --edition=-1 with --edition=auto
Originally, the objective of this commit was changing --edition to be
1-based, but this was cancelled. I'm still leaving the change to
demux_mkv.c though, which is now only of cosmetic nature.
2013-08-21 18:41:59 +02:00
Stefano Pigozzi 406241005e core: move contents to mpvcore (2/2)
Followup commit. Fixes all the files references.
2013-08-06 22:52:31 +02:00
wm4 e83cbde1a4 Fix some -Wshadow warnings
In general, this warning can hint to actual bugs. We don't enable it
yet, because it would conflict with some unmerged code, and we should
check with clang too (this commit was done by testing with gcc).
2013-07-23 00:45:23 +02:00
wm4 67bad55414 demux_mkv: fix realaudio timestamps
This fixes the sample RA_missing_timestamps.mkv. Pretty funny how this
code got it almost right, but not quite, so it was broken all these
years. And then, after everyone stopped caring, someone comes and fixes
it. (By the way, I know absolutely nothing about realaudio.)
2013-07-20 02:16:46 +02:00
wm4 77a00e444f demux_mkv: ignore DefaultDuration in some cases
This fixes playback of the sample linked by FFmpeg ticket 2508. The fix
follows ffmpeg commit 6158a3b (although it's not exactly the same).

The problem here is that the file contains an apparently non-sense
DefaultDuration value. DefaultDuration for audio tracks is used to
derive PTS values for packets with no timestamps, like they can happen
with frames inside a laced block. So the first packet of a SimpleBlock
will have a correct PTS, while the PTS values of the following packets
are calculated using DefaultDuration, and thus are broken.

This leads to seemingly ok playback, but broken A/V sync. Not using the
DefaultDuration value will leave the PTS values of these packets unset,
and the audio decoder can derive them from the output instead.

The fix more or less uses a heuristic to detect the broken case: if the
sample rate is 8 KHz (Matroska default, can assume unset), and the codec
is AC3 (as the broken file did), don't use it. I'm not sure why this
should be done only for AC3, maybe the muxing application (mkvmerge
v4.9.1) has known issues with AC3. AC3 also doesn't support 8 KHz as
sample rate natively.

(By the way, I'm not sure why we should honor the DefaultDuration at all
for audio. It doesn't seem to be needed. You can't seek to these frames,
and decoders should always be able to produce perfect PTS values by
adding the duration of the decoded audio to the first PTS.)
2013-07-16 22:59:55 +02:00
wm4 66a9eb570d demux_mkv: never force output sample rate
Matroska has an output sample rate (OutputSamplingFrequency), which in
theory should be forced instead of whatever the decoder outputs. But it
appears no software (other than mplayer2 and mpv until now) actually
respects this. Even worse, there were broken files around, which played
correctly with (in theory) broken software, but not mplayer2/mpv. Hacks
were added to our code to play these files correctly, but they didn't
catch all cases.

Simplify this by doing what everyone else does, and always use the
decoder's sample rate instead. In particular, we try to handle all
sample rate issues like libavformat's Matroska demuxer does.
2013-07-16 22:44:15 +02:00
wm4 84b69dcda5 demux_mkv: remove weird i_bps calculation code
Useless, as i_bps isn't really used for anything anymore.
2013-07-12 23:35:26 +02:00
wm4 6c1e9e4a45 demux: make claiming accurate seek the default
Enables hr-seek for raw audio/video demuxers.
2013-07-12 22:29:34 +02:00
wm4 879c7a101b demux: assume correct-pts mode by default
All demuxers make a reasonable effort to set packet timestamps, and thus
support correct-pts mode. This commit also implicitly switches
demux_rawvideo to correct-pts mode.

We still allow demuxers to disable correct-pts mode in theory.
2013-07-12 22:16:27 +02:00
wm4 6c414f8c7a demux: remove useless author/comment fields
Same deal as with previous commit.
2013-07-12 22:16:27 +02:00
wm4 3269bd1780 demux: rewrite probing and demuxer initialization
Get rid of the strange and messy reliance on DEMUXER_TYPE_ constants.
Instead of having two open functions for the demuxer callbacks (which
somehow are both optional, but you can also decide to implement both...),
just have one function. This function takes a parameter that tells the
demuxer how strictly it should check for the file headers. This is a
nice simplification and allows more flexibility.

Remove the file extension code. This literally did nothing (anymore).

Change demux_lavf so that we check our other builtin demuxers first
before libavformat tries to guess by file extension.
2013-07-12 22:16:26 +02:00
wm4 d17d2fdc7c demux: change signature of open functions, cleanups
Preparation for redoing the open functions.
2013-07-11 21:09:39 +02:00
wm4 ac080c77fb stheader: minor cleanup
Move codec_tags.h include to demux_mkv.c, because this is the only file
which still uses it.

Move new_sh_stream() to demux.h, because this is more proper.
2013-07-11 19:35:09 +02:00
wm4 a6706c41d8 video: eliminate frametime variable 2013-07-11 19:21:45 +02:00
wm4 6ede485e4b core: don't access demux_stream outside of demux.c, make it private
Generally remove all accesses to demux_stream from all the code, except
inside of demux.c. Make it completely private to demux.c.

This simplifies the code because it removes an extra concept. In demux.c
it is reduced to a simple packet queue. There were other uses of
demux_stream, but they were removed or are removed with this commit.

Remove the extra "ds" argument to demux fill_buffer callback. It was
used by demux_avi and the TV pseudo-demuxer only.

Remove usage of d_video->last_pts from the no-correct-pts code. This
field contains the last PTS retrieved after a packet that is not NOPTS.
We can easily get this value manually because we read the packets
ourselves. Reuse sh_video->last_pts to store the packet PTS values. It
was used only by the correct-pts code before, and like d_video->last_pts,
it is reset on seek. The behavior should be exactly the same.
2013-07-11 19:17:51 +02:00
wm4 05ae5afd62 demux: remove separate arrays for audio/video/sub streams, simplify
These separate arrays were used by the old demuxers and are not needed
anymore. We can simplify track switching as well.

One interesting thing is that stream/tv.c (which is a demuxer) won't
respect --no-audio anymore. It will probably work as expected, but it
will still open an audio device etc. - this is because track selection
is now always done with the runtime track switching mechanism. Maybe
the TV code could be updated to do proper runtime switching, but I
can't test this stuff.
2013-07-08 01:36:02 +02:00
wm4 af0c41e162 Remove old demuxers
Delete demux_avi, demux_asf, demux_mpg, demux_ts. libavformat does
better than them (except in rare corner cases), and the demuxers have
a bad influence on the rest of the code. Often they don't output
proper packets, and require additional audio and video parsing. Most
work only in --no-correct-pts mode.

Remove them to facilitate further cleanups.
2013-07-07 23:54:11 +02:00
wm4 931ee2dd21 demux_mkv: pass extradata for opus
Fixes playing 5.1 opus audio tracks.
2013-07-01 00:59:52 +02:00
Stefano Pigozzi 76f6df6be0 demux_mkv: clang: fix -Wunused-function
This was introduced with c0db930d.
2013-05-30 23:15:24 +02:00
wm4 f7ad81c0f5 demux_mkv: replace awkward goto by function call
Requires reindenting a large code block to minimize random control flow.
2013-05-30 19:59:03 +02:00
wm4 c0db930de4 demux_mkv: make sure wavpacks works with older libavcodec versions
The new wavpack packet format (see previous commit) doesn't work with
older libavcodec versions, so disable the new code in this case.

The version numbers are only approximate, since the libavcodec version
wasn't bumped with the wavpack change, but it's close enough.
2013-05-30 19:55:15 +02:00
wm4 3f3531f560 demux_mkv: fix wavpack in mkv
Libav introduced a silent API breakage by changing what wavpack packets
the libavcodec decoder accepts. Originally the libavcodec codec accepted
Matroska-style wavpack packets. Libav commit 9b6f47c removed this
capability from the libavcodec code, and added code to libavformat's
Matroska demuxer to "rearrange" wavpack packets. Since demux_mkv still
sent Matroska-style packets, playback failed.

Fix this by "rearranging" packets in demux_mkv as well by copying
libavformat's code. (The best kind of fix.)

Tested with [CCCP]_Mega_Lossless_Audio_Test.mkv, as well as with a
sample generated by mkvmerge.
2013-05-30 17:45:05 +02:00
wm4 5bdf9d01ca demux_mkv: defer reading of seek index until first seek
Playing Youtube videos often requires an additional seek to the end of
the file. This flushes the stream cache. The reason for the seek is
reading the cues (seek index). This poses the question why Google is
muxing its files in such a way, since nothing in Matroska mandates that
cues are located at the end of the file, but we want to handle this
situation better anyway.

The seek index is not needed for normal playback, only for seeking.
This commit changes header parsing such that the index is not read on
initialization in order to avoid the additional stream-level seek.
Instead, read the index on the first demuxer-level seek, when the seek
index is actually needed.

If the cues are at the beginning of the file, they are read immediately
as part of the normal header reading process. This commit changes
behavior only if cues are outside of the header (i.e. not in the area
between EBML header and clusters), and linked by a SeekHead. Other
level 1 elements linked by the SeekHead might still cause seeks to the
end of the file, although that seems to be rare.
2013-05-23 01:02:24 +02:00
wm4 1139eae082 demux_mkv: use a single flag to indicate whether cues have been read
Before this commit, the demuxer would in theory accept multiple cues
elements (and append its contents to the index in the order as
encountered during reading). According to the Matroska specification,
there can be only one cues element in the segment, so this seems like
an overcomplication.

Change it so that redundant elements are ignored, like with all other
unique header elements. This makes implementing deferred reading of the
cues element easier.
2013-05-23 01:02:24 +02:00
wm4 e8be121580 demux_mkv: support dirac in mkv
Nobody uses this, and this is an absolute waste of time. Even the user
who reported this turned out to have produced a sample manually.

Sample produced with:

wget http://diracvideo.org/download/test-streams/raw/vts/vts.LD-8Mb.drc
mkvmerge -o dirac.mkv vts.LD-8Mb.drc

mkvmerge writes a sort of broken aspect ratio. libavformat interprets it
as 1:1 PAR, while demux_mkv thinks this is a 1:1 DAR. Maybe libavformat
is more correct here.
2013-05-21 22:07:12 +02:00
wm4 266230ad64 Silence some compiler warnings
None of these were actual issues.
2013-05-21 00:04:27 +02:00
wm4 c2f96b020d demux_mkv: export Matroska title element as metadata 2013-05-15 15:00:52 +02:00
wm4 e6e5a7b221 Merge branch 'audio_changes'
Conflicts:
	audio/out/ao_lavc.c
2013-05-12 21:47:55 +02:00
wm4 4b5cee4617 core: use channel map on demuxer level too
This helps passing the channel layout correctly from decoder to audio
filter chain. (Because that part "reuses" the demuxer level codec
parameters, which is very disgusting.)

Note that ffmpeg stuff already passed the channel layout via
mp_copy_lav_codec_headers(). So other than easier dealing with the
demuxer/decoder parameters mess, there's no real advantage to doing
this.

Make the --channels option accept a channel map. Since simple numbers
map to standard layouts with the given number of channels, this is
downwards compatible. Likewise for demux_rawaudio.
2013-05-12 21:24:55 +02:00
wm4 885c6a2610 Fix some cppcheck / scan-build warnings
These were found by the cppcheck and scan-build static analyzers. Most
of these aren't interesting (the 2 previous commits fix some interesting
cases found by these analyzers), and they don't nearly fix all warnings.
(Most of the unfixed warnings are spam, things MPlayer never cared
about, or false positives.)
2013-05-06 23:11:11 +02:00
Bin Jin eec9b8a012 demux_mkv: fix segfault issue playing back VC1 in a mkv
This bug was introduced in commit 06eee1b.
2013-04-27 13:42:08 +02:00
wm4 2337bc9d9b demux_mkv: cosmetics 2013-04-24 21:33:33 +02:00
wm4 36c31f47b2 demux_mkv: fix out of range comparison
This check was always false:

    if (num == EBML_UINT_INVALID)

Fix it by using the proper type for the num variable.

This case actually doesn't really matter, and this is just for hiding
the warning and for being 100% correct.
2013-04-24 16:19:18 +02:00
wm4 963c9aa3d5 demux_mkv: always set track->codec_id to a string
Otherwise audio/video/sub track handling code would dereference the NULL
pointer.
2013-04-20 23:40:41 +02:00
wm4 018530cb74 demux_mkv: always add subtitle tracks
Even if the codec is unknown.
2013-04-20 23:28:27 +02:00
wm4 331982b99c sub, demux: identify subtitle types with the codec name
Get rid of the 1-char subtitle type field. Use sh_stream->codec instead
just like audio and video do. Use codec names as defined by libavcodec
for simplicity, even if they're somewhat verbose and annoying.

Note that ffmpeg might switch to "ass" as codec name for ASS, so we
don't bother with the current silly "ssa" name.
2013-04-20 23:28:27 +02:00
wm4 23da9e68e8 demux_mkv: introduce new_demux_packet_from() and use it 2013-04-20 23:28:25 +02:00
wm4 7f304a72a9 demux_mkv: simplify use of demuxer API
mkv_track_t now references sh_stream directly, instead of using an ID.
Also remove all accesses to demux_stream (demuxer->video etc.).

Remove some slave-mode things on the way, like "ID_SID_..." messages.
2013-04-20 23:28:25 +02:00
eng 06eee1b675 demux_mkv: code cleanup
Cleanup based on results from cppcheck-1.59
Reduce the scope of several variables
Replace 2 calloc/realloc calls with a single malloc
2013-04-20 23:28:24 +02:00
wm4 5dabaaf093 demux_mkv: use new way of track switching
Since demux_mkv queries the demuxer state when reading packets, track
switching is completely passive. Cycling etc. is done by the frontend.
As result, all track switching code can be removed.
2013-04-20 23:28:24 +02:00
wm4 cb15d9c24a demux_mkv: remove pointless video track selection
Possibly once needed, now it's just redundant code.
2013-04-20 23:28:24 +02:00
wm4 80d0ab1058 demux_mkv: support vp9
Note that ffmpeg doesn't provide a decoder by default yet.
2013-04-20 23:28:24 +02:00
wm4 8b017c73c4 core: matroska: support concatenated segments
Matroska files can contain multiple segments, which are literally
further Matroska files appended to the main file. They can be referenced
by segment linking.

While this is an extraordinarily useless and dumb feature, we support it
for the hell of it.

This is implemented by adding a further demuxer parameter for skipping
segments. When scanning for linked segments, each file is opened
multiple times, until there are no further segments found. Each segment
will have a separate demuxer instance (with a separate file handle
etc.).

It appears the Matroska spec. has an even worse feature for segments:
live streaming can completely reconfigure the stream by starting a new
segment. We won't add support for it, because there are 0 people on this
earth who think Matroska life streaming is a good idea. (As opposed to
serving Matroska/WebM files via HTTP.)
2013-04-20 23:28:23 +02:00
wm4 f989b6081b demux_mkv: don't terminate if there are no clusters
Matroska segment linking allows abusing Matroska files as playlists
without any actual video/audio/sub data, making files without any
clusters still useful for the frontend.
2013-04-20 23:28:23 +02:00
wm4 8133aa4d8a demux_mkv: simplify handle_block() logic a bit 2013-04-20 23:28:23 +02:00
wm4 59eaa8ed7e demux_mkv: verify laces separately, and in all cases 2013-04-20 23:28:23 +02:00
wm4 1d6558d9c8 demux_mkv: get rid of the duplicated lace case labels
Also change the extracting of the lace type bitfield from flags to
make it more apparent that the value range is 0-3.
2013-04-20 23:28:22 +02:00
wm4 4b562bdf20 demux_mkv: there can be 256 laces
The lace number is stored with an offset of 1, so the maximum number
of laces is 255+1=256.
2013-04-20 23:28:22 +02:00
wm4 6ef855069f demux_mkv: check block malloc() result 2013-04-20 23:28:22 +02:00
wm4 9f21c81633 demux_mkv: use a bounded buffer for block data
Should help avoiding out-of-bounds reads.
2013-04-20 23:28:22 +02:00
wm4 c951010a26 demux_mkv: static allocation for lace sizes buffer
Avoid messy memory management and error handling.

remove tmp_lace_buffer non-sense

Not sure how my mind got 8k, or how this made sense at all.
2013-04-20 23:28:22 +02:00
wm4 6da399caeb demux_mkv: remove redundant check 2013-04-20 23:28:22 +02:00
wm4 b3d12c3d54 demux_mkv: fix seeking with index generation
Relative seeks backwards didn't work too well with incomplete files, or
other files that are missing the seek index. The problem was that the
on-the-fly seek index generation simply added cluster positions as seek
entries. While this is perfectly fine, the seek code had no information
about the location of video key frames. For example, a 5 second long
cluster can have only 1 video key frame, which is located 4 seconds into
the cluster. Seeking backwards by one second while still located in the
same cluster would select this cluster as seek target again. Decoding
would resume with the key frame, giving the impression that seeking is
"stuck" at this frame.

Make the generated index aware of key frame and track information, so
that video can always be seeked in an idea way. This also uses the
normal block parsing code for indexing the clusters, instead of the
suspicious looking special code. (This code didn't parse the Matroska
elements correctly, but was fine for files with normal structure. Files
with corrupted clusters or clusters formatted for streaming were not
handled properly.)

Skipping is now quite a bit slower (takes about twice as long as
before), but it removes the special cased skipping code, and it's still
much faster (at least twice as fast) than libavformat. It needs to do
more I/O (no more skipping entire clusters, all data is read), and has
more CPU usage (more data needs to be parsed).
2013-04-20 23:28:22 +02:00
wm4 9b4d15af18 demux_mkv: move Block header parsing code
Move parts of the Block element parsing to read_block(). This way
read_block() can return block time and track information in
struct block_info.
2013-04-20 23:28:22 +02:00
wm4 3fbd6d4e9c demux_mkv: split reading blocks and reading packets
Move most code from demux_mkv_fill_buffer() to read_next_block(). The
former is supposed to read raw blocks, while ..fill_buffer() reads
blocks and turns them into packets.
2013-04-20 23:28:21 +02:00
wm4 9afe9d7061 demux_mkv: move BlockGroup reading code to a separate function
Somehow this was setup such that a BlockGroup can be incrementally
read (at least in theory). This makes no sense, as BlockGroup can
contain only one Block (despite its name). There's no need to read
this incrementally, and makes the code confusing for no gain.

Read all the BlockGroup sub-elements with a single function call,
without keeping global state for BlockGroup parsing.
2013-04-20 23:28:21 +02:00
wm4 4e531d0f2a demux_mkv: factor block reading
The code for reading block data was duplicated. Move it into a function.

Instead of returning on error (possibly due to corrupt data) and
signalling EOF, continue by trying to find the next block. This makes
error handling slightly simpler too, because you don't have to care
about freeing the current block. We could still signal EOF in this case,
but trying to resync sounds better for dealing with corrupted files.
2013-04-20 23:28:21 +02:00
wm4 75178af8b4 demux_mkv: fix streaming clusters
Matroska files prepared for streaming have clusters with unknown size.
These files are pretty rare, see e.g. test4.mkv from the official
Matroska test file collection.
2013-04-20 23:28:21 +02:00
wm4 c2bf06f63e demux_mkv: simplify cluster reading code
The end positions of the current cluster and block were managed by
tracking their size and how much of them were read, instead of just
using the absolute end positions.

I'm not sure about the reasons why this code was originally written
this way. One obvious concern is reading from pipes and such, but the
stream layers hides this. stream_tell(s) works even when reading from
pipes. It's also a fast call, and doesn't involve the stream
implementation or syscalls. Keeping track of the cluster/block end is
simpler and there's no reason why this wouldn't work.
2013-04-20 23:28:21 +02:00
wm4 c4e43aaf89 demux_mkv: use normal index data structure even for incomplete files
Incomplete files don't have a valid index, because the index is usually
located near the end of a file. In this case, an index is created on the
fly during demuxing, or when seeks are done.

This used a completely different code path, which leads to unnecessary
complications and code duplication. Use the normal index data structure
instead. The seeking code at the end of seek_creating_index() (in this
commit renamed to create_index_until()) is removed. The normal seek code
does the same thing instead.
2013-04-20 23:28:21 +02:00
wm4 c49aa35380 demux_mkv: move preroll subtitle check to the right place
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.
2013-04-04 15:24:04 +02:00
wm4 75afa370b9 demux_mkv: try to show current subtitle when seeking
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.
2013-04-04 14:45:29 +02:00
wm4 061b99d7b9 demux_mkv: fix handling of 0 DisplayWidth/Height
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
2013-04-04 01:22:24 +02:00
wm4 0142985228 demux_mkv: don't print non-sense warning on normal EOF
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.)
2013-03-30 20:51:45 +01:00
wm4 ac1c5e6e18 demux_mkv: improve robustness against broken files
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.
2013-03-28 21:45:16 +01:00
wm4 3533ee3ae4 demux_mkv: fix skipping broken header elements
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.
2013-03-28 00:00:39 +01:00
wm4 546ae23a0c demux_mkv: set correct aspect ratio even if DisplayHeight is unset
Fixes the file test2.mkv from the official Matroska test file
collection.

libavformat does the same thing.
2013-03-28 00:00:04 +01:00
wm4 e837d8ddac demux_mkv: support ALAC
Test sample was produced with ffmpeg. Extradata handling closely follows
libavformat/matroskadec.c.
2013-03-15 12:17:39 +01:00
Stephen Hutchinson 1877d7933e demux_mkv: Support playing Opus streams in Matroska
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.
2013-03-14 00:07:28 +01:00
wm4 72bdc5d3af core: use playback time to determine playback percent position
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.
2013-02-26 02:01:48 +01:00
wm4 a0987186b9 demux_lavf: remove code duplication
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.)
2013-02-10 17:25:57 +01:00
wm4 4d016a92c8 core: redo how codecs are mapped, remove codecs.conf
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.
2013-02-10 17:25:56 +01:00
wm4 0421e17c2b demux_mkv: support more formats with V_UNCOMPRESSED
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.
2013-01-30 00:57:07 +01:00
wm4 42b47624f8 demux_mkv: support V_UNCOMPRESSED video tracks
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.
2013-01-24 17:45:13 +01:00
Uoti Urpala e0d9ec60ad demux_mkv: work around bad OutputSamplingFrequency values
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.
2013-01-13 13:25:57 +01:00
Uoti Urpala 77eac2ec34 audio: improve decoder open failure handling
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).
2012-12-03 21:08:52 +01:00
wm4 ddffcce678 stream, demux: replace off_t with int64_t
On reasonable systems, these types were the same anyway. Even on
unreasonable systems (seriously, which?), this may reduce potential
breakage.
2012-11-20 18:00:15 +01:00
wm4 4873b32c59 Rename directories, move files (step 2 of 2)
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.)
2012-11-12 20:08:18 +01:00
wm4 d4bdd0473d Rename directories, move files (step 1 of 2) (does not compile)
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.
2012-11-12 20:06:14 +01:00