Commit Graph

1495 Commits

Author SHA1 Message Date
wm4 11383696db demux_lavf: different hack for DVD sub autoselection hack
For now, we want to get rid of the demux->sub access, because this
field will become private to demux.c in a later commit. So replace the
current hack with another hack.

The need for the hack will be removed sooner or later. (Instead of
autoselecting a specific stream, all new streams will be enabled by
default, so that no packets can get lost. The frontend will then be
responsible to deselect unwanted streams.)
2013-07-11 19:16:37 +02:00
wm4 23e303859a mplayer: fix incorrect audio sync after format changes
This is not directly related to the handling of format changes itself,
but playing audio normally after the change. This was broken: the output
byte rate was not recalculated, so audio-video sync was simply broken.
Fix this by calculating the byte rate on the fly, instead of storing it
in sh_audio.

Format changes are relatively common (switches between stereo and 5.1
in TV recordings), so this fixes a somewhat critical bug.
2013-07-11 19:15:09 +02:00
wm4 a522483629 demux: remove facility for partial packet reads
Partial packet reads were needed because the video/audio parsers were
working on top of them. So it could happen that a parser read a part of
a packet, and returned that to the decoder. With libavformat/libavcodec,
packets are already parsed, and everything is much simpler.

Most of the simplifications in ad_spdif could have been done earlier.
Remove some other stuff as well, like the questionable slave mode start
time reporting (could be replaced by proper code, but we don't bother).
Remove the unused skip_audio_frame() functionality as well (it was used
by old demuxers). Some functions become private to demux.c, like
demux_fill_buffer(). Introduce new packet read functions, which have
simpler semantics. Packets returned from them are owned by the caller,
and all packets in the demux.c packet queue are considered unread.
Remove special code that dropped subtitle packets with size 0. This
used to be needed because it caused special cases in the old code.
2013-07-11 19:10:33 +02:00
wm4 186f6021b1 core: move code from demux/video.c to mplayer.c
Although I don't like putting even more crap into mplayer.c, this is a
bit better, especially with coming cleanups in mind.
2013-07-10 02:07:26 +02:00
wm4 89252631bd ms_hdr: remove unused definitions 2013-07-10 02:00:47 +02:00
wm4 b096269af5 demux: remove ds_read_packet() 2013-07-10 02:00:46 +02:00
wm4 9200538b39 audio: remove decoder input buffer
This was unused.
2013-07-10 02:00:46 +02:00
wm4 32ad313844 demux: remove some more minor unused things 2013-07-10 02:00:46 +02:00
wm4 9bb7935ce1 options: remove --ignore-start
This was used only with demux_avi.
2013-07-08 21:59:44 +02:00
wm4 31f685040b Merge branch 'master' into remove_old_demuxers
Conflicts:
	DOCS/man/en/changes.rst
	DOCS/man/en/options.rst
2013-07-08 21:55:44 +02:00
wm4 f630ee1597 Fix building with --disable-libass
Obscure corner case, but in theory we support this.
2013-07-08 01:40:13 +02:00
wm4 73c76de91e demux: simplify demux_open() calls
The demux_open as well as demux_open_withparams calls don't use the
stream selection parameters anymore, so remove them everywhere.
Completes the previous commit.
2013-07-08 01:37:30 +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 50808bab8d demux: merge functions 2013-07-08 01:02:45 +02:00
wm4 8a46d4c49f demux: remove unused function 2013-07-08 00:50:59 +02:00
wm4 90813f3402 demux: remove video_read_properties 2013-07-08 00:39:29 +02:00
wm4 c4f33d784a demux: remove some old stream header functions 2013-07-08 00:35:04 +02:00
wm4 aac5d758c5 demux: remove audio parser
The audio parser was needed only by the "old" demuxers, and
demux_rawaudio. All other demuxers output already parsed packets.

demux_rawaudio is usually for raw audio, so using a parser with it
doesn't usually make sense. But you can also force it to read
compressed formats with fixed packet sizes, in which case the parser
would have been used. This use case is probably broken now, but you
will be able to do the same thing with libavformat demuxers.
2013-07-08 00:13:53 +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 3f3ffd0de4 core: update metadata during playback, allow streams to export metadata
STREAM_CTRL_GET_METADATA will be used to poll for streamcast metadata.
Also add DEMUXER_CTRL_UPDATE_INFO, which could in theory be used by
demux_lavf.c. (Unfortunately, libavformat is too crappy to read metadata
mid-stream for mp3 or ogg, so we don't implement it.)
2013-07-02 12:19:16 +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
wm4 3382a6f6e4 video: add a new method to configure filters and VOs
The filter chain and the video ouputs have config() functions. They are
strictly limited to transfering the video size and format. Other
parameters (like color levels) have to be transferred separately.

Improve upon this by introducing a separate set of reconfig() functions,
which use mp_image_params to carry format parameters. This struct
contains all image format related parameters from config(), plus
additional parameters such as colorspace.

Change vf_rotate to use it, as well as vo_opengl. vf_rotate is just
an example/test case, but vo_opengl will need it later.

The intention is also to get rid of VOCTRL_SET_YUV_COLORSPACE. This
information is now handed to the VOs via reconfig(). The getter,
VOCTRL_GET_YUV_COLORSPACE, will still be needed though.
2013-06-28 20:34:46 +02:00
wm4 88916143a7 demux_lavf: add one more AAC mimetype 2013-06-25 00:55:20 +02:00
wm4 5da89f8d2c demux_libass: do charset conversion by -subcp
Old code used to use libass' recoding feature, which is a copy of the
old MPlayer code. We dropped that a few commits ago. Unfortunately,
this made it impossible to load some subtitle files, like UTF-16 files.

Make .ass loading respect -subcp again. We do this by recoding the
probe buffer to UTF-8, and then trying to load it normally. (Yep.)

Since UTF-16 in particular will effectively half the probe buffer size,
double the probe size.
2013-06-25 00:11:56 +02:00
wm4 29cec6f98b sub: prevent subtitle conversion if subs are known UTF-8
Currently this happens only in an obscure case (reading UTF-16 files
with the old subreader).
2013-06-25 00:11:56 +02:00
wm4 9ee7364172 demux_subreader: remove iconv/enca code
Not needed anymore, done by dec_sub.c instead.
2013-06-25 00:11:56 +02:00
wm4 feb64c2717 sub: attempt to use video FPS for frame based subtitle formats
This only affects demux_subreader.c for now. Maybe there is some hope
this can be used for libavformat demuxers too, but I'm not sure yet.
2013-06-25 00:11:56 +02:00
wm4 cfa45c40dc sub: add demux_libass wrapper, drop old hacks
demux_libass.c allows us to make subtitle format detection part of the
normal file loading process. libass has no probe function, but trying to
load the start of a file (the first 4 KB) is good enough. Hope that
libass can even handle random binary input gracefully without printing
stupid log messages, and that the libass parser doesn't accept too many
non-ASS files as input.

This doesn't handle the -subcp option correctly yet. This will be fixed
later.
2013-06-25 00:11:56 +02:00
wm4 1bfae45a88 core: don't set correct-pts mode randomly
The default correct-pts mode depended on which demuxer was opened last.
Often this is the subtitle demuxer. The correct-pts mode should be
decided on the demuxer for video instead.
2013-06-25 00:11:56 +02:00
wm4 98388c0c07 subreader: turn into actual demuxer
subreader.c (before this commit renamed to demux_subreader.c) was
special cased to the -sub option. The plan is using the normal demuxer
codepath for all subtitle formats (so we can prefer libavformat demuxers
for most formats).

There are some subtle changes. The probe size is restricted to 32 KB
(instead of unlimitted + giving up after 100 lines of input). For
formats like MicroDVD, the video FPS isn't used anymore, because it's
not available on the subtitle demuxer level. Instead, hardcode it to
23.976 FPS (libavformat seems to do the same). The user can probably
still use -sub-fps to fix the timing. Checking the file extension for
".utf"/".utf8"/".utf-8" is simply removed (seems worthless, was in the
way, and I've never seen this anywhere).
2013-06-25 00:11:56 +02:00
wm4 b37147744e demux: add utility functions for preloading demuxers
These will be needed by subtitle demuxers, which read all data on
initialization.
2013-06-25 00:11:55 +02:00
wm4 e3c0fb1aee demux_lavf: use stream_peek() instead of read/unread
Simpler, reduces the amount of copying.

We still have to malloc+memcpy the probe buffer though, because padding
with FF_INPUT_BUFFER_PADDING_SIZE is required by libavformat.
2013-06-25 00:11:55 +02:00
wm4 db2e1ef4d2 Move/rename subreader.c 2013-06-25 00:11:54 +02:00
wm4 a70d575291 sub: preload external text subtitles
If a subtitle is external, read it completely and add all subtitle
events in advance when the subtitle track is selected. This is done
for text subtitles only. (Note that subreader.c and subtitles loaded
with libass are different and don't have anything to do with this
commit.)
2013-06-23 22:33:59 +02:00
wm4 4f5e12136d stream: remove padding parameter from stream_read_complete()
Seems like a completely unnecessary complication. Instead, always add a
1 byte padding (could be extended if a caller needs it), and clear it.

Also add some documentation. There was some, but it was outdated and
incomplete.
2013-06-23 22:33:59 +02:00
wm4 d064c69e1c demux: don't require fill_buffer callback 2013-06-23 22:33:58 +02:00
wm4 d81b71c7f7 Merge branch 'cache_new' 2013-06-16 22:07:48 +02:00
wm4 5999efb964 stream: fix some aspects of EOF handling
The stream EOF flag should only be set when trying to read past the end
of the file (relatively similar to unix files). Always clear the EOF
flag on seeking. Trying to set it "properly" (depending whether data is
available at seek destination or not) might be an ok idea, but would
require attention to too many special cases. I suspect before this
commit (and in MPlayer etc. too), the EOF flag wasn't handled
consistently when the stream position was at the end of the file.

Fix one special case in ebml.c and stream_skip(): this function couldn't
distinguish between at-EOF and past-EOF either.
2013-06-16 22:05:10 +02:00
wm4 1c35794efd stream: remove stream_reset()
This function was called in various places. Most time, it was used
before a seek. In other cases, the purpose was apparently resetting
the EOF flag. As far as I can see, this makes no sense anymore. At
least the stream_reset() calls paired with stream_seek() are completely
pointless. A seek will either seek inside the buffer (and reset the
EOF flag), or do an actual seek and reset all state.
2013-06-16 22:05:09 +02:00
wm4 34a383664a demux_lavf: change probing, use stream_unread_buffer()
This fixes a longstanding issue with demux_lavf probing.
See previous commit.
2013-06-16 22:05:09 +02:00
wm4 98e50d5477 demux_lavf: show metadata for OGG audio files
Whether this is a hack or not, I don't even know anymore.
2013-06-15 18:36:17 +02:00
wm4 92ae48db0f Merge branch 'sub_mess'
This branch heavily refactors the subtitle code (both loading and
rendering), and adds support for a few new formats through FFmpeg.

We don't remove any of the old code yet. There are still some subtleties
related to subreader.c to be resolved: code page detection & conversion,
timing post-processing, UTF-16 subtitle support, support for the -subfps
option. Also, SRT reading and loading ASS via libass should be turned
into proper demuxers. (SRT is needed because Libav's is gravely broken,
and we want ASS loading via libass to cover full libass format support.
Both should be demuxers which are probed _before_ libavformat, so that
all subtitles can be loaded through the demuxer infrastructure, and
libavformat subtitles don't need to be treated in a special way.)
2013-06-04 00:29:44 +02:00
wm4 13a1ce16f9 sub: pass subtitle packets directly
Before this, subtitle packets were returned as data ptr/len pairs, and
mplayer.c got the rest (pts and duration) directly from the demuxer
data structures. Then mplayer.c reassembled the packet data structure
again.

Pass packets directly instead. The mplayer.c side stays a bit awkward,
because the (now by default unused) DVD path keeps getting in the way.
In demux.c there's lots of weird stuff (3 functions that read packets,
really?), but we want to keep the code equivalent for now to avoid
hitting weird issues and corner cases.
2013-06-03 22:40:07 +02:00
wm4 6dbedd27d5 demux_lavf: always set packet duration
Makes WebVTT actually work.

Also simplify the logic for setting duration. Only the subtitle path
uses the packet duration, so the checks for STREAM_SUB as well as the
keyframe flag are redundant.

Apparently duration and convergence_duration are the same thing, but
convergence_duration was added as Matroska-specific hack to get a higher
value range (int vs. int64_t) with high resolution Matroska timebases.
For us it doesn't matter, because double floats are used for timestamps
and durations.
2013-06-03 22:40:06 +02:00
wm4 e19ffa02aa sub: turn subassconvert_ functions into sub converters
This means subassconvert.c is split in sd_srt.c and sd_microdvd.c. Now
this code is involved in the sub conversion chain like sd_movtext is.
The invocation of the converter in sd_ass.c is removed.

This requires some other changes to make the new sub converter code work
with loading external subtitles. Until now, subtitles loaded via
subreader.c was assumed to be in plaintext, or for some formats, in ASS
(except in -no-ass mode). Then these were added to an ASS_Track. Change
this so that subtitles are always in their original format (as far as
decoders/converters for them are available), and turn every sub event
read by subreader.c as packet to the dec_sub.c subtitle chain.

This removes differences between external/demuxed and -ass/-no-ass code
paths further.
2013-06-03 22:40:02 +02:00
wm4 e9af899237 demux: fix "-demuxer mpegps", don't force demuxer in stream_dvd
Internally, stream_dvd.c returned DEMUXER_TYPE_MPEG_PS, and the same
value was hardcoded to enforced usage of demux_lavf in demux.c. But
"-demuxer mpegps" basically did the same, so that switch was broken
for this format. Undo this and don't request a demuxer in stream_dvd.c.
demux_lavf.c is (probably) good enough to probe correctly with DVD.
Otherwise, we'd actually have to do something completely different to
force the libavformat demuxer.
2013-06-02 23:57:41 +02:00
wm4 02ce316ade sub: refactor
Make the sub decoder stuff independent from sh_sub (except for
initialization of course). Sub decoders now access a struct sd only,
instead of getting access to sh_sub. The glue code in dec_sub.c is
similarily independent from osd.

Some simplifications are made. For example, the switch_id stuff is
unneeded: the frontend code just has to make sure to call osd_changed()
any time subtitles are switched.

This is also preparation for introducing subtitle converters. It's much
cleaner to completely separate demuxer header/renderer glue/decoders
for this purpose, especially since sub converters might completely
change how demuxer headers have to be interpreted.

Also pass data as demux_packets. Currently, this doesn't help much, but
libavcodec converters might need scary stuff like packet side data, so
it's perhaps better to go with passing packets.
2013-06-01 19:44:16 +02:00
wm4 27d383918a core: add demux_sub pseudo demuxer
Subtitle files are opened in mplayer.c, not using the demuxer
infrastructure in general. Pretend that this is not the case (outside of
the loading code) by opening a pseudo demuxer that does nothing. One
advantage is that the initialization code is now the same, and there's
no confusion about what the difference between track->stream,
track->sh_sub and mpctx->sh_sub is supposed to be.

This is a bit stupid, and it would be much better if there were proper
subtitle demuxers (there are many in recent FFmpeg, but not Libav). So
for now this is just a transition to a more proper architecture. Look
at demux_sub like an artifical limb: it's ugly, but don't hate it - it
helps you to get on with your life.
2013-06-01 19:43:11 +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 2684280643 sub: add sd_spu.c to wrap spudec, cleanup mplayer.c
This unifies the subtitle rendering path. Now all subtitle rendering
goes through sd_ass.c/sd_lavc.c/sd_spu.c.

Before that commit, the spudec.h functions were used directly in
mplayer.c, which introduced many special cases. Add sd_spu.c, which is
just a small wrapper connecting the new subtitle render API with the
dusty old vobsub decoder in spudec.c.

One detail that changes is that we always pass the palette as extra
data, instead of passing the libdvdread palette as pointer to spudec
directly. This is a bit roundabout, but actually makes the code simpler
and more elegant: the difference between DVD and non-DVD dvdsubs is
reduced.

Ideally, we would just delete spudec.c and use libavcodec's DVD sub
decoder. However, DVD playback with demux_mpg produces packets
incompatible to lavc. There are incompatibilities the other way around
as well: packets from libavformat's vobsub demuxer are incompatible to
spudec.c. So we define a new subtitle codec name for demux_mpg subs,
"dvd_subtitle_mpg", which only sd_spu can decode.

There is actually code in spudec.c to "assemble" fragments into complete
packets, but using the whole spudec.c is easier than trying to move this
code into demux_mpg to fix subtitle packets.

As additional complication, Libav 9.x can't decode DVD subs correctly,
so use sd_spu in that case as well.
2013-05-30 22:40:32 +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 6bfbca9912 core: avoid deselecting and reselecting stream needlessly
The core deselected all streams on initialization, and then selected the
streams it actually wanted. This was no problem for
demux_mkv/demux_lavf, but old demuxers (like demux_asf) could lose some
packets. The problem is that these demuxers can buffer some data on
initialization, which then is flushed on track switching. Fix this by
explicitly avoiding deselecting a wanted stream.
2013-05-29 14:57:05 +02:00
wm4 fa75ae96e1 demux_asf: fix after commit 5165e19
This demuxer reallocated packets on its own, instead of using the
demux.c functions, which clashed with a recent change.
2013-05-29 14:57:05 +02:00
wm4 cc1b1f773f demuxer_lavf: use audio/mpeg mime type for mp3
Basically, add exactly the same hacks for mp3 as we did for AAC. Should
make starting mp3 streams much faster.
2013-05-27 23:27:59 +02:00
wm4 8cfb87d200 demux_lavf: minimal probing and reduced analyzeduration for AAC over HTTP
When AAC is streamed over HTTP, using libavformat defaults is
pathetically slow. One solution for that is skipping probing and using
the mimetype to identify that it's AAC instead. This is what we did
before this commit (and ffmpeg does it too, but their logic is too
"inaccessible" for mpv).

This is still pretty fragile though. Make it a bit more robust by
requiring minimal probing. A probescore of 25 is reached after feeding
2 KB to libavformat (instead of > 500 KB for the normal probescore), so
use that. This is done only when streaming AAC from HTTP to reduce the
possibility of weird breakages for other formats.

Also reduce analyzeduration. The default analyzeduration will make
libavformat read lots of data, which makes playback start slow. So we
set analyzeduration to a low value. On the other hand, doing that for
other formats is risky, because there are unspecified effects with
certain "strange" formats (like transport streams). So we do this only
if we're streaming AAC from HTTP as well.

tl;dr libavformat is shit for media players
2013-05-27 23:26:22 +02:00
wm4 f05ec1c738 options: add allow-mimetype suboption for demux_lavf
This can control whether demux_lavf should use the HTTP mime type to
determine the format, instead of probing the data with the libavformat
API. Do this to allow easier debugging in case the mimetype is
incorrect. (This is done only for AAC streams right now.)
2013-05-27 22:48:04 +02:00
wm4 3face4300e demux_lavf: print how many bytes are read by avformat_find_stream_info()
Can be helpful for debugging slow stream startup.

Also add a comment about BIO_BUFFER_SIZE.
2013-05-26 17:01:54 +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 64a78cf314 demux_lavf: workaround minor ffmpeg memory leak
The sequence of avcodec_alloc_context3() / avcodec_copy_context() /
avcodec_close() / av_free() leaks some memory. So don't copy the context
and use it directly.

Originally avcodec_copy_context() was used to guarantee that libavformat
can't update the fields of the context during demuxing in order to make
things a little more robust, but it's not strictly needed, and
ffmpeg/ffplay don't do this anyway. Still might make the situation worse
should we move demuxing into a separate thread, though.
2013-05-21 22:07:13 +02:00
wm4 b477c68aa0 demux: workaround for -demuxer mpegts -correct-pts
Using -demuxer mpegts -correct-pts triggered the assertion in
ds_get_packet2(). This is not surprising, because the correct-pts code
was changed to accept _complete_ packets, while all the old demuxers
(including the mpegts demuxer) require you to use "partial" packet
reads, together with the video_read_frame(). (That function actually
parses video frames, so fragments of the original "packets" can be fed
to the decoder.)

However, it returns out demux_ts packet's are mostly useable. demux_ts
still adds an offset (i.e. ds->buffer_pos != 0) to the packets when
calling internal parser functions, such as in parse_es.c. While this is
unclean design due to mplayer's old video demuxing/decoding path, it can
be easily be made work by modifying the packet as returned by
ds_get_packet2(). We also have to change the packet freeing code, as
demux_packet->buffer doesn't have to point to the start of the memory
allocation anymore.

MPlayer handles this "correctly" because it doesn't have a function that
reads a complete packet.
2013-05-21 22:07:13 +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 4ee0d08820 demux: fix big endian PCM in mkv with demux_mkv 2013-05-11 20:19:08 +02:00
wm4 c2657d5c98 demux: restructure chapter seeking code
Arrange the code such that commenting the first if will allow doing
stream chapter seeks instead of time chapter seeks again, if both are
possible.
2013-05-09 01:16:04 +02:00
wm4 c653697610 demux: don't name unknown chapters "unknown"
The frontend's fallback for missing chapter names is better.
2013-05-06 23:42:05 +02:00
wm4 b01e8d6210 stream: report chapter times, use time seeks for DVD chapters
Allow the stream layer to report chapter times. Extend stream_dvd to do
this. I'm not 100% sure whether the re-used code is bug-free (because it
was used for slave-mode and/or debugging only).

MAke the frontend do time-based seeks when switching DVD chapters. I'm
not sure if there's a real reason STREAM_CTRL_SEEK_TO_CHAPTER exists
(maybe/hopefully not), but we will see.

Note that querying chapter times in demuxer_chapter_time() with the new
STREAM_CTRL_GET_CHAPTER_TIME could be excessively slow, especially with
the cache enabled. The frontend likes to query chapter times very often.
Additionally, stream_dvd uses some sort of quadratic algorithm to list
times for all chapters. For this reason, we try to query all chapters on
start (after the demuxer is opened), and add the chapters to the demuxer
chapter list. demuxer_chapter_time() will get the time from that list,
instead of asking the stream layer over and over again.

This assumes stream_dvd knows the list of chapters at the start, and
also  that the list of chapters never changes during playback. This
seems to be true, and the only exception, switching DVD titles, is not
supported at runtime (and doesn't need to be supported).
2013-05-06 23:39:48 +02:00
wm4 5148f9f5cc demux: remove retrieval of chapter end time
The frontend doesn't use this.

Also use double for returning the chapter times. Everything uses double
for times, and there's no reason to use float here.
2013-05-06 23:11:11 +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
wm4 5165e19a23 demux: use talloc for packets
No functional change.
2013-05-05 18:44:24 +02:00
wm4 e4837b2d42 core: ignore backstep command if demuxer is not capable
Also, mark demuxer as not capable if DVD playback is done. The problem
with DVD is that playback time (stream_pts) is not reported frame-exact,
and the time is a "guess" at best.
2013-05-05 18:44:24 +02:00
wm4 6a0421295e demux_lavf: use demuxer ID for transport streams
Might help mapping tracks correctly to stream_bluray, fixing the
issue with the track language not being reported.
2013-05-05 18:44:24 +02:00
wm4 b8fce1217c demux: use demux_lavf instead of demux_mpg for DVD playback
With the commit "demux_lavf: fix DEMUXER_CTRL_RESYNC", DVD playback
seems to work nicely with demux_lavf, and maybe works even better than
with demux_mpg.

The old demuxer can be forced with: --demuxer=mpegps

If no regressions surface, demux_mpg.c will be deleted later.
2013-05-05 18:44:24 +02:00
wm4 18c383f51b demux_lavf: fix DEMUXER_CTRL_RESYNC
This used the libavformat current position, instead of the mp stream
(which reflects current DVD/Bluray read position). This was broken,
because libavformat won't update its position by calling the user's
stream callbacks, negating the whole point of DEMUXER_CTRL_RESYNC.

Now DVD playback with libavformat seems to work relatively well.
2013-05-05 18:44:24 +02:00
wm4 4ed22795bb demux_lavf: set stream_pts
demux_mpg did the same, and doing this in demux_lavf fixes DVD playback
when using this demuxer.

Additionally this might make bluray work better in the future (but for
now, bluray playback doesn't change as it doesn't report stream PTS yet).
2013-05-05 18:44:24 +02:00
wm4 4ba4d6ef3f demux: report stream time info instead of demuxer info if possible
Needed for bluray and dvd. demux_mpg (used for dvd playback) did this
manually for the time length.
2013-05-05 18:44:24 +02:00
wm4 3644433224 core: move demuxer time reporting to demuxer 2013-05-05 18:44:24 +02:00
wm4 acad31c2d3 core: don't report byte-based playback position with dvd
DVD playback uses a demuxer that signals to the frontend that timestamp
resets are possible. This made the frontend calculate the OSD playback
position based on the byte position and the total size of the stream.
This actually broke DVD playback position display. Since DVD reports a
a linear playback position, we don't have to rely on the demuxer
reported position, so disable this functionality in case of DVD
playback. This reverts the OSD behavior with DVD to the old behavior.
2013-05-05 18:44:23 +02:00
wm4 1c96f51e36 demux: simplify stream ID business, fix issue with cover art
The stream ID handling as it was changed in commit 654c34f was still
a little bit insane, and caused a regression with the cover art hack
(the stream set in demux->video->sh was incorrect for demux_lavf).

Simplify by always using stream_index for demux_stream->id, and getting
rid of that tid thing. It turns out that the id for subtitles isn't
special either (maybe demux_ts.c was the only thing left that required
this).
2013-04-29 22:59:15 +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 1bae5641ab demux_lavf: fix subtitle seeking before start of the file
When trying to seek before the start of the file, which usually happens
when using the arrow keys to seek to the start of the file, external
libavformat demuxed subtitles will be invisible. This is because seeking
in the external subtitle file fails, so the subtitle demuxer is left in
a random state.

This is actually similar to the normal seeking path, which has some
fallback code to handle this situation. Add such code to the subtitle
seeking path too.

(Normally, all demuxer support av_seek_frame(), except subtitles, which
support avformat_seek_file() only. The latter was meant to be the "new"
seeking API, but this never really took off, and using it normally seems
to cause worse seeking behavior. Or maybe we just use it incorrectly,
nobody really knows.)
2013-04-21 00:21:23 +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 15ff7a5719 demux: remove some unused sh_video_t fields
Completely mysterious, and its values were never actually used.
2013-04-20 23:28:27 +02:00
wm4 c12b5ffc33 demux: get rid of sh_common_t
The only reason this existed was the parsing code. Even though it
could have been used for video, it's audio-only, so just move this
to sh_audio_t.
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 2adb1aaa5d demux: remove useless vid/aid/sid fields
Only demux_ts.c used sid in one case, replace that by reading the same
value from another location.
2013-04-20 23:28:25 +02:00
wm4 afd8d7f2db demux: fix clearing of input padding
MP_INPUT_BUFFER_PADDING_SIZE and FF_INPUT_BUFFER_PADDING_SIZE are both
16. The doxygen for FF_INPUT_BUFFER_PADDING_SIZE says only the first 23
bits must to be 0, but this is probably a lie.
2013-04-20 23:28:25 +02:00
wm4 23da9e68e8 demux_mkv: introduce new_demux_packet_from() and use it 2013-04-20 23:28:25 +02:00
wm4 eb27e14622 demux: remove some unused things 2013-04-20 23:28:25 +02:00
wm4 1e53b78b32 demux_lavf: simplify
This removes the stream handling mess by using a single list for all
stream types.

One consequence is that new streams are always set to AVDISCARD_ALL,
which could be an issue if packets are read before initializing other
streams. However, this doesn't seem to an issue for various reasons,
so we don't do anything about it.

The new code strictly assumes that libavformat never removes or
reorders streams once added to AVFormatContext->streams. Undefined
behavior will result if it does.
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
wm4 654c34f771 demux: add functions to simplify demuxers
Some preparations to simplify demux_mkv and demux_lavf.

struct demux_stream manages state for each stream type that is being
demuxed (audio/video/sub). demux_stream is rather annoying, especially
the id and sh members, which are often used by the demuxers to determine
current stream and so on. Demuxers don't really have to access this,
except for testing whether a stream is selected and to add packets.

Add a new_sh_stream(), which allows creating streams without having the
caller specify any kind of stream ID. Demuxers should just use sh_stream
pointers, instead of multiple kinds of IDs and indexes.
2013-04-20 23:28:24 +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 69258b2c71 demux: simpler way to notify demuxers about track switches
This interfaces assumes track switching is always successful.
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 1d7b289e48 matroska: update dead link 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 203b57d863 demux: simplify chapter appending code
This pre-allocation looked tricky and awkward. Use MP_TARRAY_APPEND(),
which makes the code simpler. This even keeps the pre-allocation.
2013-04-12 14:38:22 +02:00
wm4 6f28c061b4 demux: always sort chapters
The condition that checked whether the chapters are out of order and
should be sorted was inverted. This likely wasn't noticed in testing,
because even if the chapters are unsorted, if the last two chapters
were sorted, the rest got sorted too.

Instead of doing this silly check, always sort the chapters after
demuxer initialization. Also make sure the sort order is stable in case
chapter start times are the same (original_index check).
2013-04-12 14:38:04 +02:00
Rudolf Polzer 23bbbed06d demux: fix a specific gcc 4.8 warning that may hint to mis-optimized code
CC      demux/demux.o
demux/demux.c: In function 'demuxer_switch_track':
demux/demux.c:1241:29: warning: array subscript is above array bounds [-Warray-bounds]
     int new_id = demuxer->ds[type]->id;
                                  ^
2013-04-09 10:08:28 +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 9a731a9b0d demux: fix regressions by restricting cover art hack further
The code modified by this commit is supposed to prevent demuxing the
whole file when cover art is present. (The problem with cover art is
that the ffmpeg libavformat API doesn't signal video EOF correctly - so
we try to read more packets to find the next video frame, which results
in demuxing and queuing the whole audio stream.)

This caused regressions for files with extremely high audio offset (see
github issue #46). MY conclusion is that this cover art crap doesn't
work, and this is just another case of completely insane ffmpeg/libav
API.

Disable the hack in all cases, unless a cover art video track is
selected. Maybe I'll handle cover art directly in the frontend later, so
that we don't have to rely on whatever libavformat does.

Unfortunately, this also makes behavior with equally insane mp4 files
with sparse video tracks worse, but this issue takes priority.
2013-03-19 02:27:47 +01:00
wm4 be7e04f719 demux_mf: fix crashes when '*' matches directories
Doing 'mpv mf://*' in a file with directories would crash, because even
though directories are skipped, the corresponding file entry is just
left at NULL, leading to a segfault on access. So explicitly skip NULL
entries.
2013-03-19 01:54:45 +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 dfe7b3898d demux_lavf: use avg_frame_rate instead of r_frame_rate
r_frame_rate was deprecated and was finally removed from Libav and
FFmpeg git.

Not sure what's the correct replacement. avg_frame_rate may or may not
be worse than the fallback of using the time_base as guess. The
framerate is mostly unused, but needed for frame-based subtitles and for
encoding. (It appears encoding guesses a timebase based on the FPS, and
I'm not sure why we don't just use the source timebase.)
2013-03-13 23:51:30 +01:00
wm4 d8bde114fd Prefix CODEC_ID_ with AV_
The old names have been deprecated a while ago, but were needed for
supporting older ffmpeg/libav versions. The deprecated identifiers
have been removed from recent Libav and FFmpeg git.

This change breaks compatibility with Libav 0.8.x and equivalent
FFmpeg releases.
2013-03-13 23:51:30 +01:00
Stefano Pigozzi 428a4243e9 fix clang compiler warnings 2013-03-03 11:14:44 +01:00
wm4 8ddfabc535 core: fix SEEK_FACTOR
Emulate percentage-seeks (SEEK_FACTOR) as normal time-seeks if possible.
This fixes some issues with (let's call it) low quality implementations
of SEEK_FACTOR (e.g. demux_mkv basically interprets this as byte-seek,
and also seeking to 99.9% makes it seek back to the start).

For weird MPEG formats the demuxer level SEEK_FACTOR is still used.
These formats, which can have timestamp resets, are identified by
setting demuxer->ts_resets_possible to true.

Also, have get_current_pos_ratio() follow the same rules, and calculate
the percentage position with the file position if timestamp resets are
possible.

This actually fixes percentage-seeks in .ts files with demux_lavf.c.
This kind of seek is not really used now, but it will be more important
when we add a progress bar.

Note: seeking in chained ogg files is still completely broken. The main
issue is that ffmpeg doesn't provide a sane API for dealing with
timestamp resets, and trying to do byte seeks with ogg confuses demuxer
and decoder (or something like this) and just does random things.
(Tested with two concatenated flac-in-ogg files).
2013-03-01 14:44:53 +01:00
wm4 c82a83d8af demux_lavf: fix percentage display with some file formats
AVFormatContext.start_time is sometimes AV_NOPTS_VALUE, such as when
playing FLAC files. (For most other file formats it's set to 0, even if
the format doesn't support arbitrary start times.)
2013-03-01 13:03:30 +01:00
wm4 c9088fff86 m_option: don't define OPT_BASE_STRUCT by default
OPT_BASE_STRUCT defines which struct the OPT_ macros (like OPT_INT etc.)
reference implicitly, since these macros take struct member names but no
struct type. Normally, only cfg-mplayer.h should need this, and other
places shouldn't be bothered with having to #undef it.

(Some files, like demux_lavf.c, still store their options in MPOpts. In
the long term, this should be removed, and handled like e.g. with VO
suboptions instead.)
2013-03-01 11:27:59 +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 4801c3c62c demux_mf: add some more image formats
And fix the comment about fourccs.
2013-02-24 17:23:38 +01:00
wm4 90efe7cf48 demux_mf: support .xbm
And support the PIX_FMT_MONOWHITE pixel format. (This is really weird:
unlike PIX_FMT_MONOBLACK, it uses white pixels. I have no idea why
libavcodec doesn't just convert the pixel format on the fly, instead of
bothering everyone with really special pixel formats.)
2013-02-24 16:51:29 +01:00
wm4 edddf81232 demux_rawvideo: allow setting video codec
Can be used to decode some obscure image formats and similar stuff.
2013-02-24 16:46:35 +01:00
wm4 10ed11eefa demux_mf: map to codecs directly
Instead of going through FourCCs and codec_tags.c.
2013-02-24 16:31:43 +01:00
wm4 67df52ae73 demux_rawvideo: remove ancient video dimension presets
I can't see much value in them. Just specify the size manually.
2013-02-23 00:07:11 +01:00
wm4 a090c07453 demux_lavf: add workaround for broken libavformat seek behavior
Seeking before the start of a .flac file (such as seeking backwards when
the file just started) generates a bunch of decoding errors and audible
artifacts. Also, the audio output doesn't match the reported playback
position. The errors printed to the terminal are:

[flac @ 0x8aca1c0]invalid sync code
[flac @ 0x8aca1c0]invalid frame header
[flac @ 0x8aca1c0]decode_frame() failed

This is most likely a problem with the libavformat API. When seeking
with av_seek_frame() fails, the demuxer can be left in an inconsistent
state. ffplay has the same issue [1].

Older versions of mpv somehow handled this fine. Bisection shows that
commit b3fb7c2 caused this regression by removing code that retried
failed seeks with an inverted AVSEEK_FLAG_BACKWARD flag. This code was
removed because it made it harder to stop playback of a file by seeking
past the end of the file (expecting this is rather natural when skipping
through multiple files by seeking, and the internal mplayer demuxers
also did this).

As a workaround, re-add the original code, but only for the backwards
seeking case.

Also note that the original intention of the code removed in b3fb7c2 was
not dealing with this case, but something else. It also had to do with
working around weird libavformat situations, though. It's not perfectly
clear what exactly. See commit 1ad332f.

[1] https://ffmpeg.org/trac/ffmpeg/ticket/2282
2013-02-19 01:49:01 +01:00
wm4 32500b5e11 demux_mf: fix breakage after commit 4d016a9 2013-02-17 21:06:26 +01:00
wm4 ac82c73224 demux: apply sparse video hack only to demux_lavf and demux_mkv
Apparently this cuases trouble for legacy demuxers. demux_mpg stopped
doing PCM audio. (The problem was probably that it read a bunch of
video packets on detection, and then the sparse video hack prevented
audio packets from being read, because it looked like there were no
more audio packets. With sparse video, this normally helps not reading
too many audio packets.)

Since the legacy demuxers do not need this hack, enable it for
demux_lavf and demux_mkv only.

Some additional hacks that were needed to handle legacy demuxers can be
removed, making the code simpler.

Also see commit 4a40eed.
2013-02-14 19:53:15 +01:00
wm4 e6307997d2 demux: restructure code that warns about packet buffer overflows
There should be no functional changes, except that way how avoiding
spamming the terminal with the overflow warning is handled changes a
bit.

The removed check for ds->eof looks suspicious, but it should be
redundant now.
2013-02-14 19:53:06 +01:00
wm4 55e4f76ce8 demux_mpg: fix setting codec
This made one case of DVD PCM audio not work. It still doesn't work,
but that will be fixed with the following two commits.
2013-02-14 19:52:34 +01:00
wm4 517d6dbfca demux: fix video with demux_mpg (DVD playback)
Commit 4d016a9 changed how demuxers report the codec of each stream.
Some of that was missed in video.c, which is important for legacy
demuxers (demux_mpg was broken by this, which is needed for DVD
playback).

Not sure about the ASF/AVI related change, but this is also a legacy
demuxers only codepath.
2013-02-12 10:16:38 +01:00
wm4 01869d1391 demux_lavf, ad_lavc, vd_lavc: pass codec header data directly
Instead of putting codec header data into WAVEFORMATEX and
BITMAPINFOHEADER, pass it directly via AVCodecContext. To do this, we
add mp_copy_lav_codec_headers(), which copies the codec header data
from one AVCodecContext to another (originally, the plan was to use
avcodec_copy_context() for this, but it looks like this would turn
decoder initialization into an even worse mess).

Get rid of the silly CodecID <-> codec_tag mapping. This was originally
needed for codecs.conf: codec tags were used to identify codecs, but
libavformat didn't always return useful codec tags (different file
formats can have different, overlapping tag numbers). Since we don't
go through WAVEFORMATEX etc. and pass all header data directly via
AVCodecContext, we can be absolutely sure that the codec tag mapping is
not needed anymore.

Note that this also destroys the "standard" MPlayer method of exporting
codec header data. WAVEFORMATEX and BITMAPINFOHEADER made sure that
other non-libavcodec decoders could be initialized. However, all these
decoders have been removed, so this is just cruft full of old hacks that
are not needed anymore. There's still ad_spdif and ad_mpg123, bu neither
of these need codec header data. Should we ever add non-libavcodec
decoders, better data structures without the past hacks could be added
to export the headers.
2013-02-10 17:25:57 +01:00
wm4 dd61fac943 demux_lavf, ad_lavc, vd_lavc: refactor, cleanup
Rearrange some code to make it easier readable. Remove some dead code,
and stop printing AVI headers in demux_lavf. (These are not actual AVI
headers, just for internal use.)

There should be no functional changes, other than reducing output in
verbose mode.
2013-02-10 17:25:57 +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 0d3258fc1e demux_lavf: default PTS to 0 for attached pictures
The ffmpeg/libav attached picture hack usually set the PTS of video
packets to AV_NOPTS_VALUE. Set it to 0 to avoid printing a warning by
the filter code.
2013-02-03 16:53:49 +01:00
wm4 3b37fadc5d demux_lavf: remove weird stream auto-selection
Should be dead code. Stream selection is handled either during
demuxer initialization, or via DEMUXER_CTRL_SWITCH_*.
(If there were actually situations where this code did something, it
was probably broken anyway.)
2013-02-03 16:51:13 +01:00
wm4 d61408f0da demux_lavf: remove "internet radio hack"
It appears this is not needed anymore. ffmpeg can handle "chained" ogg
files fine. These can be created with "cat file1.ogg file2.ogg > chained.ogg",
and are similar (or equal) to some internet radio streams. Apparently
ffmpeg used to add new tracks when crossing boundaries in chained files,
and the hack in demux_lavf.c handled this. At some later point, ffmpeg's
ogg demuxer was improved, and stopped adding new tracks as long as the
codec doesn't change.

Since the hack in demux_lavf.c was hardcoded to Vorbis (i.e. only active
if the new and old track were both Vorbis), it's dead code, and we can
remove it. I couldn't find any stream that triggered this hack, or fails
without it.

Firefox had a similar issue, and its bug tracker makes a good reference:

    https://bugzilla.mozilla.org/show_bug.cgi?id=455165

NOTE: this doesn't update metadata on track changes anymore.
2013-02-03 16:44:41 +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 237b7491e2 demux: don't use codec_tag for raw PCM formats
In commit 2dd2d9b, raw PCM was switched to always go through ad_lavc,
and mapping codec IDs to mplayer internal codec tags was removed, as it
was not needed anymore. However, some uncompressed audio lavf demuxers
export  their own codec tags, which collide with the existing internal
mplayer codec tags, leading to incorrect raw PCM codec selection based
on the misinterpreted audio tag. Re-add the mapped codec IDs from
2dd2d9b. Map them to an invalid codec tag, so that the generic lavc
decoder is selected (assumes ad_lavc is the decoder for raw PCM).
2013-01-30 00:54:18 +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
wm4 8751a0e261 video: decouple internal pixel formats from FourCCs
mplayer's video chain traditionally used FourCCs for pixel formats. For
example, it used IMGFMT_YV12 for 4:2:0 YUV, which was defined to the
string 'YV12' interpreted as unsigned int. Additionally, it used to
encode information into the numeric values of some formats. The RGB
formats had their bit depth and endian encoded into the least
significant byte. Extended planar formats (420P10 etc.) had chroma
shift, endian, and component bit depth encoded. (This has been removed
in recent commits.)

Replace the FourCC mess with a simple enum. Remove all the redundant
formats like YV12/I420/IYUV. Replace some image format names by
something more intuitive, most importantly IMGFMT_YV12 -> IMGFMT_420P.

Add img_fourcc.h, which contains the old IDs for code that actually uses
FourCCs. Change the way demuxers, that output raw video, identify the
video format: they set either MP_FOURCC_RAWVIDEO or MP_FOURCC_IMGFMT to
request the rawvideo decoder, and sh_video->imgfmt specifies the pixel
format. Like the previous hack, this is supposed to avoid the need for
a complete codecs.cfg entry per format, or other lookup tables. (Note
that the RGB raw video FourCCs mostly rely on ffmpeg's mappings for NUT
raw video, but this is still considered better than adding a raw video
decoder - even if trivial, it would be full of annoying lookup tables.)

The TV code has not been tested.

Some corrective changes regarding endian and other image format flags
creep in.
2013-01-13 20:04:11 +01:00
wm4 06ccd9f671 video: simplify decoder pixel format handling
Simplify the decoder pixel format handling by making it handle only
the case vd_lavc needs: a video stream always decodes to a single
pixel format.

Remove the handling for multiple pixel formats, and remove the
codecs.conf pixel format declarations that are left.

Remove the handling of "ambiguous" pixel formats like YV12 vs. I420 (via
VDCTRL_QUERY_FORMAT etc.). This is only a problem if the video chain
supports I420, but not YV12, which doesn't seem to be the case anywhere,
and in fact would not have any advantage.

Make the "flip" flag a global per-codec flag, rather than a pixel format
specific flag. (Some ffmpeg decoders still return a flipped image, so
this has to be done manually.) Also fix handling of the flip operation:
do not overwrite the global flip option, and make the --flip option
invert the codec flip option rather than overriding it.
2013-01-13 17:39:31 +01:00
wm4 20c9dfa616 Replace strsep() uses
This function sucks and apparently is not very portable (at least on
mingw, the configure check fails). Also remove the emulation of that
function from osdep/strsep*, and remove the configure check.
2013-01-13 17:32:39 +01:00
wm4 ec57c94ba2 configure: remove __builtin_expect check
Change the only usage of HAVE_BUILTIN_EXPECT, demux.h, to use an #ifdef
instead. In theory, a configure check is better, but nobody does it this
way anyway, and we seek to reduce the configure script.
2013-01-13 13:55:22 +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
Rudolf Polzer 7c40d8a36e demux_lavf: avio_flush in DEMUXER_CTRL_RESYNC
This rules out possible avio buffering issues.
2013-01-10 12:36:13 +01:00
Rudolf Polzer 5a412bfa09 demux_lavf: implement DEMUXER_CTRL_RESYNC
This makes -chapter work with stream_dvd by telling ffmpeg to flush its
internal buffers after a stream_dvd seek.
2013-01-07 17:39:55 +01:00
Rudolf Polzer 671ca2a570 demux_mpg, ass_mp: fix warnings
The warnings in demux_mpg were silenced by additional no-operation
casts.

A variable in ass_mp was used only for some versions of libass; now the
declaration is in that version #ifdef too to avoid a compiler warning.
2012-12-28 08:40:40 +01:00
wm4 61aef3fff9 Fix compilation with ffmpeg 1.0
AVPROBE_SCORE_RETRY was too new, and doesn't even exist in Libav. Go
back to using the value explicitly.
2012-12-13 12:49:27 +01:00
reimar 4a40eeda94 demux: fix behavior with files that have sparse video packets
Improve EOF handling in ds_fill_buffer for the case where one stream ends
much earlier than the others, in particular make sure the "too many ..."
message is not printed over and over.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32823 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	libmpdemux/demuxer.c

Try to improve seeking in files with only few video packets,
in particular files with cover art.

This might cause issues with badly interleaved files, particularly
together with -audio-delay, even though I did not see issues
in my very limited testing.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35486 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	libmpdemux/demuxer.c
	libmpdemux/demuxer.h

Fix code that detects streams temporarily lacking data to work
properly with e.g. DVDs.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35499 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	libmpdemux/demuxer.c

Make stream eof detection less sensitive.

Fixes bug #2111.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35543 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	libmpdemux/demuxer.c
2012-12-11 00:37:55 +01:00
wm4 fdbf437055 core: allow disabling display of "album art" in audio files
ffmpeg pretends that image attachments (such as contained in ID3v2
metadata) are video streams. It injects the attached pictures as packets
into the packet stream received with av_read_frame().

Add the --audio-display option to allow configuring whether attached
pictures should be displayed. The default behavior doesn't change
(images are displayed).

Identify video streams, that are actually image attachments, with "[P]"
in the terminal output.

Modify the default stream selection such that real video streams are
preferred over attached pictures. (This is just for robustness; I do not
know of any samples where images are added before actual video streams
and could lead to bad default stream selection with the old code.)
2012-12-11 00:37:55 +01:00
wm4 071d24e19d audio/decode: remove ad_dvdpcm and use ad_lavc for DVD PCM
ad_dvdpcm reads MPEG specific headers directly (passed through codecdata
by demux_mpg), so you couldn't use ffmpeg's "pcm_dvd" with demux_mpg.
Change demux_mpg to set the correct audio parameters directly. The code
for this is taken from ad_dvdpcm.

ad_dvdpcm is evil because it still does partial packet reads (with
demux_read_data()), and it's redundant to libavcodec anyway.
2012-12-11 00:37:54 +01:00
wm4 2dd2d9bcfc audio/decode: remove ad_pcm and use ad_lavc for PCM
Since libavcodec doesn't have a "generic" PCM decoder, we have to go out
of out way to make it look like ad_lavc provides one: make it provide a
pseudo "pcm" decoder, which maps some format tags manually to the
individual libavcodec PCM decoders.

Format tags which uniquely map to one libavcodec could be mapped via
codecs.conf. Since defining these in tag_map[] is much shorter (one line
vs. a full codec entry in codecs.conf), and since we need tag_map[]
anyway, we don't use codecs.conf for these.

ad_pcm is evil because it still does partial packet reads (with
demux_read_data()), and it's redundant to libavcodec anyway.
2012-12-11 00:37:54 +01:00
wm4 180944fe28 stream_lavf/demux_lavf: export/use HTTP MIME type
This is a fix for web radio streams that send raw AAC [1]. libavformat's
AAC demuxer probe is picky enough to request hundreds of KBs data, which
makes for a slow startup. To speed up stream startup, try use the HTTP
MIME type to identify the format. The webstream in question sends an AAC
specific MIME type, for which demux_lavf will force the AAC demuxer,
without probing anything.

ffmpeg/ffplay do the same thing. Note that as of ffmpeg commit 76d851b,
av_probe_input_buffer() does the mapping from MIME type to demuxer. The
actual mapping is not publicly accessible, and can only be used by
calling that function. This will hopefully be rectified, and ideally
ffmpeg would provide a function like find_demuxer_from_mime_type().

[1] http://lr2mp0.latvijasradio.lv:8000
2012-12-11 00:37:54 +01:00
wm4 222a5cf7c0 demux_lavf: make minimum probe score customizable, remove lavf_preferred
libavformat wants to read a full ~400KB of data to determine whether
it's really AAC. This causes slow startup with AAC web radio streams [1]
(possible due to a broken initial packet). There are similar issues
with other file formats.

Make the probe "score" (libavformat's mechanism for testing file
formats) configurable with the -lavfdtops:probescore option. This allows
lowering the amount of data read on probing. If the probe score is below
the probescore option value, demux_lavf will try to get a higher score
by feeding more data to libavformat, until the required score or the
max. probe size is reached.

Remove the lavf_preferred demuxer entry. This had a purpose in
mplayer-svn, but now there doesn't seem to be any good reason for it
to exist. Make sure that our native "good" demuxers are above
demux_lavf in demuxer_list[] instead (so that they are preferred).

[1] http://lr2mp0.latvijasradio.lv:8000
2012-12-11 00:37:54 +01:00
wm4 5bf8706d1f sub: remove vobsub reader in favor of ffmpeg vobsub demuxer
ffmpeg recently added a demuxer that can read vobsubs (pairs of .sub and
.idx files). Get rid of the internal vobsub reader, and use the ffmpeg
demuxer instead.

Sneak in an unrelated manpage change (autosub default).
2012-12-11 00:37:54 +01:00
wm4 b3fb7c2cad core: improve seeking in external files
This affects streams loaded with -subfile and -audiofile. They could get
out of sync when they were deselected, and the main file was seeked. Add
code to seek external files when they are selected (see
init_demux_stream()).

Use avformat_seek_file() under certain circumstances. Both av_seek_frame()
("old" API) and avformat_seek_file() ("new" API) seem to be broken with
some formats. At least the vobsub demuxer doesn't implement the old API
(and the old API doesn't fallback to the new API), while the fallback
from new API to old API gives bad results. For example, seeking forward
with small step sizes seems to fail with the new API (tested with
Matroska by trying to seek 1 second forward relative to priv->last_pts).
Since only subtitle demuxers implement the new API anyway, checking
whether iformat->read_seek2 is set to test whether the old API is not
supported gives best results. This is a hack at best, but makes things
work.

Remove backwards seeking on seek failure. This was annoying, and only
was there to compensate for obscure corner cases (see 1ad332). In
particular, files with completely broken seeking that used to skip back
to the start on every seek request may now terminate playback.
2012-12-11 00:36:42 +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 7146a57cfe demux_gif: remove this demuxer in favor of libavformat
The gif support in libavformat/libavcodec as of ffmpeg commit 5603b2
can handle animated gif. The internal demuxer is not needed anymore.
2012-12-03 21:08:51 +01:00
wm4 dd3260185a demux_lavf: add support for libavdevice
libavdevice supports various "special" video and audio inputs, such
as screen-capture or libavfilter filter graphs.

libavdevice inputs are implemented as demuxers. They don't use the
custom stream callbacks (in AVFormatContext.pb). Instead, input
parameters are passed as filename. This means the mpv stream layer has
to be disabled. Do this by adding the pseudo stream handler avdevice://,
whose only purpose is passing the filename to demux_lavf, without
actually doing anything.

Change the logic how the filename is passed to libavformat. Remove
handling of the filename from demux_open_lavf() and move it to
lavf_check_file(). (This also fixes a possible bug when skipping the
"lavf://" prefix.)

libavdevice now can be invoked by specifying demuxer and args as in:

    mpv avdevice://demuxer:args

The args are passed as filename to libavformat. When using libavdevice
demuxers, their actual meaning is highly implementation specific. They
don't refer to actual filenames.

Note:

libavdevice is disabled by default. There is one problem: libavdevice
pulls in libavfilter, which in turn causes symbol clashes with mpv
internals. The problem is that libavfilter includes a mplayer filter
bridge, which is used to interface with a set of nearly unmodified
mplayer filters copied into libavfilter. This filter bridge uses the
same symbol names as mplayer/mpv's filter chain, which results in symbol
clashes at link-time.

This can be prevented by building ffmpeg with --disable-filter=mp, but
unfortunately this is not the default.

This means linking to libavdevice (which in turn forces linking with
libavfilter by default) must be disabled. We try doing this by compiling
a test file that defines one of the clashing symbols (vf_mpi_clear).

To enable libavdevice input, ffmpeg should be built with the options:

    --disable-filter=mp

and mpv with:

    --enable-libavdevice

Originally, I tried to auto-detect it. But the resulting complications
in configure did't seem worth the trouble.
2012-12-03 21:08:51 +01:00
wm4 aa2c07542f demux_lavf: do not prefix filename passed to libavformat with "mp:"
Opening files with the libavformat AVISynth demuxer ("avs"/avisynth.c)
fails, because the filename we pass to avformat_open_input() is prefixed
with "mp:". Normally, this doesn't matter, because data is read with the
stream interface. The AVISynth demuxer can't use this, because the
Avisynth API (apparently) can't read scripts from memory, and requires
a filename.

The "mp:" prefix used to be required when mplayer's stream layer was
made available as protocol to ffmpeg. This was replaced by setting
custom stream callbacks in de4908 (svn commit 25499), but the prefix
wasn't removed. Since this prefix doesn't have any purpose anymore and
prevents AVS playback from functioning, remove it. Fixes #5.
2012-12-03 21:08:51 +01:00
wm4 efaa73cc73 stream, demux_lavf: minor cleanup for stream size code 2012-11-20 18:00:15 +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
reimar 51dac4e070 stream: change STREAM_CTRL_GET_SIZE argument type to uint64_t
Update endpos each time libavformat asks for it.

Fixes playback of still downloading files to not stop before we
really reached the end.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35107 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	libmpdemux/demux_lavf.c

Change STREAM_CTRL_GET_SIZE argument type from off_t to
uint64_t.
Also fix the incorrect type of the uint64_res variable.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35360 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	libmpdemux/demux_lavf.c
	libmpdemux/muxer_lavf.c

Note: also merges the "forgotten" cache support from r35107.
2012-11-20 18:00:14 +01:00
reimar 3f85094d4e Fix potential bugs and issues, general cleanups
Most of these are reimar fixing issues found by Coverity static
analyzer, and possibly some more cleanup commits independent from
this.

Since these commits are rather noisy, squash them all together.

Try to make code a bit clearer.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35294 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	audio/out/ao_alsa.c

Check the correct variable for NULL.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35323 b3059339-0415-0410-9bf9-f77b7e298cf2

Remove pointless unreachable code (the loop condition already checks
the 0xff case).

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35325 b3059339-0415-0410-9bf9-f77b7e298cf2

Fix typo that might have caused reading beyond the string end.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35326 b3059339-0415-0410-9bf9-f77b7e298cf2

Do not needlessly use "long" types.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35331 b3059339-0415-0410-9bf9-f77b7e298cf2

Use AV_RB32 to avoid sign extension issues and validate offset before using it.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35332 b3059339-0415-0410-9bf9-f77b7e298cf2

Remove nonsense casts.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35343 b3059339-0415-0410-9bf9-f77b7e298cf2

Fix crash in case sh_audio allocation failed.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35348 b3059339-0415-0410-9bf9-f77b7e298cf2

Fix potential NULL dereference.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35351 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	libmpcodecs/ad_ffmpeg.c

Note: Slightly modified.

Fix malloc failure check to check the correct variable.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35353 b3059339-0415-0410-9bf9-f77b7e298cf2

Avoid code duplication and pointless casts.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35363 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	stream/tv.c

Error out if an invalid channel list name was specified
instead of continuing and reading outside array bounds
all over the place.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35364 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	stream/tv.c

Make array "static const".

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35365 b3059339-0415-0410-9bf9-f77b7e298cf2

Properly free resources even when encountering many
parse errors.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35367 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	parser-cfg.c

Avoid leaks in error handling.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35380 b3059339-0415-0410-9bf9-f77b7e298cf2

Do not do sign comparisons on "char" type which can be both signed or unsigned.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35381 b3059339-0415-0410-9bf9-f77b7e298cf2

Free cookies file data after parsing it.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35382 b3059339-0415-0410-9bf9-f77b7e298cf2

http_set_field only makes a copy of the string, so we still need to
free it.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35383 b3059339-0415-0410-9bf9-f77b7e298cf2

check4proxies does not modify input URL, so mark it const.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35390 b3059339-0415-0410-9bf9-f77b7e298cf2

Remove proxy "support" from stream_rtp and stream_upd, trying
to use a http proxy for UDP connections makes no sense.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35394 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	stream/stream_rtp.c
	stream/stream_udp.c

Add url_new_with_proxy function to reduce code duplication and memleaks.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35395 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	stream/pnm.c
	stream/stream_live555.c
	stream/stream_nemesi.c
	stream/stream_rtsp.c

Fix off-by-one errors in file descriptor validity checks.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35402 b3059339-0415-0410-9bf9-f77b7e298cf2

Remove pointless cast.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35403 b3059339-0415-0410-9bf9-f77b7e298cf2

Abort when opening the file failed instead of calling
"write" with an invalid descriptor.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35404 b3059339-0415-0410-9bf9-f77b7e298cf2

Remove pointless local variable.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35411 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	stream/http.c
2012-11-20 18:00:14 +01:00
wm4 7a1396b6ca demux_mf: allow displaying single image files, various cleanups
Enable autoprobing for demux_mf, so that image files can be directly
displayed with e.g. "mpv file.jpg --pause". (The --pause switch is
needed to prevent the window from closing immediately.)

Since demux_mf doesn't have any real file format probing and goes by
file extension only, move the demuxer down the demuxer list to ensure
it's checked last. (ffmpeg's demux_mf equivalent, "image2", probes by
file extensions too, and there doesn't seem to be anything that can
probe typical image file formats from binary data.)

Remove the --mf "w" and "h" suboptions. Don't pass the width/height to
the video stream header. Both of these are useless, because the decoder
reads the real image size at a later point from the file headers.
Remove setting the BITMAPINFOHEADER as well, as vd_lavc doesn't need
this.

Enable --correct-pts by default. This fixes displaying a single image
with vo_vdpau (as mentioned by uau).

Keep around a pointer to the sh_video stream header instead of
accessing demuxer->video->sh_video. Fixes a crash when deselecting the
video track.

Note that the format probing is incorrect when opening images from HTTP
locations. File extensions don't have to match the actual file format.
A correct implementation would require to check the MIME type, or to
probe the binary data correctly.
2012-11-16 21:21:16 +01:00
wm4 f7163c8065 subtitles: improve support for libavformat demuxed subtitles
Make demux_lavf not error out if no video or audio track is present.
This allows opening subtitle files with the demuxer.

Improve the test whether subtitles read from demuxers must do explicit
packet reads. (I'm not sure whether always doing these reads could have
bad effects, such as reading too many audio and video packets at once,
so be conservative.)
2012-11-16 21:21:16 +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