Commit Graph

332 Commits

Author SHA1 Message Date
wm4 8743d3fbfa demux_lavf: disable genpts by default, remove the builtin genpts hack
This was needed to determine PTS from DTS, but the previous commits
make it unnecessary.

The builtin genpts hack was used for DVD, because libavformat's genpts
essentially went amok on DVD timestamp resets. See commit 65d87091 for
details.
2013-11-25 23:13:46 +01:00
wm4 9f72a9753e demux: export dts from demux_lavf, use it for avi
Having the DTS directly can be useful for restoring PTS values.

The avi file format doesn't actually store PTS values, just DTS. An
older hack explicitly exported the DTS as PTS (ignoring the [I assume]
genpts generated non-sense PTS), which is not necessary anymore due to
this change.
2013-11-25 23:13:01 +01:00
wm4 904c73d2d2 demux: remove gsh field from sh_audio/sh_video/sh_sub
This used to be needed to access the generic stream header from the
specific headers, which in turn was needed because the decoders had
access only to the specific headers. This is not the case anymore, so
this can finally be removed again.

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

(Note that this is still a bit incorrect: it relfects the position of
the last packet read by the demuxer, not that returned to the user. But
that was already broken, and is not that trivial to fix.)
2013-11-16 21:46:17 +01:00
wm4 0cdbc6db6e demux_lavf: remove broken and commented byte based seeks
This was originally added for better seeking where libavformat's seek
function won't work well: files with timestamp resets. In these cases,
the code tried to calculate an average bitrate, and then do byte based
seeks by multiplying the seek target time with the bitrate.

Apparently this was unreliable enough that the code was just commented
(and other parts became inactive). Get rid of it.

Note that the player still does byte based seeks in these cases when
doing percent-seeks.
2013-11-16 21:46:17 +01:00
wm4 a49ab7cc2f demux: make determining seek capability generic
Instead of having each demuxer do it (only demux_mkv actually did...),
let generic code determine whether the file is seekable. This requires
adding exceptions to demuxers where the stream is not seekable, but the
demuxer is.

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

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

demux_mf was the only place where this was used specially, but we can
rely on timestamps instead for this case.
2013-11-03 18:50:00 +01:00
wm4 dd344b43e8 Enable -Wshadow
This one really did bite me hard (see previous commit), so enable it by
default.

Fix some cases of shadowing throughout the codebase. None of these
change behavior, and all of these were correct code, and just tripped up
the warning.
2013-11-01 13:00:15 +01:00
wm4 c613d802bc talloc: change talloc destructor signature
Change talloc destructor so that they can never signal failure, and
don't return a status code. This makes our talloc copy even more
incompatible to upstream talloc, but on the other hand this is
preparation for getting rid of talloc entirely.

(The talloc replacement in the next commit won't allow the talloc_free
equivalent to fail, and the destructor return value would be useless.
But I don't want to change any mpv code either; the idea is that the
talloc replacement commit can be reverted for some time in order to
test whether the talloc replacement introduced a regression.)
2013-10-13 01:16:30 +02:00
wm4 b0f7a26f1a network: fix rtsp playback
By default, libavformat uses UDP for rtsp playback. This doesn't work
very well. Apparently the reason is that the buffer sizes libavformat
chooses for UDP are way too small, and switching to TCP gets rid of this
issue entirely (thanks go to Reimar Döffinger for figuring this out).

In theory, you can set buffer sizes as libavformat options, but that
doesn't seem to help.

Add an option to select the rtsp transport, and make TCP the default.

Also remove an outdated comment from stream.c.
2013-09-22 02:40:29 +02:00
wm4 35fd083828 demux: retrieve per-chapter metadata
Retrieve per-chapter metadata, but don't do much with it. We just make
the metadata of the _current_ chapter available as chapter-metadata
property. Returning the full chapter list with metadata would be no
problem, except that the property interface isn't really good with
structured data, so it's not available for now.

Not sure if it's worth it, but it was requested via github issue #201.
2013-09-08 07:43:23 +02:00
wm4 c8f49be919 demux_lavf: workaround for broken libavformat subtitle seeking
The really funny thing about this commit is that this code is added on
top of another work around. Basically, subtitle seeking in libavformat
is completely broken. To make it useful, we have to add yet another
workaround.

The basic problem is that libavformat's subtitle seeking code always
uses the stream time base, instead of AV_TIME_BASE if stream index -1 is
passed to the avformat_seek_file() function.

Fixes github issue #216. Hopefully this will be fixed in ffmpeg too at
some point.
2013-09-07 02:56:28 +02:00
wm4 1e649f353b demux: remove unused audio_delay parameter from demux_seek()
Used to be needed by demux_avi.
2013-08-22 19:14:26 +02:00
wm4 d8922361d1 demux_lavf: blacklist "tty" libavformat demuxer
This is completely useless, and in this particular case, it broke the
fallback for MLP2 subtitles (stored as .txt files) to demux_subreader.
(Yes, libavformat should be fixed to handle this, but for now this will
_always_ break playback of subtitle files stored in .txt.)

You can still force this demuxer, but by default we will just pretend
that the "tty" demuxer does not exist.
2013-08-07 23:15:43 +02:00
Stefano Pigozzi 406241005e core: move contents to mpvcore (2/2)
Followup commit. Fixes all the files references.
2013-08-06 22:52:31 +02:00
wm4 cccfac47a4 demux_lavf: make avio buffer configurable
Perhaps not very useful, but reserved for situations when a user reports
awful latency and experimentation/debugging might be required to find
out why or to fix it (happens often).
2013-08-04 23:25:54 +02:00
wm4 b53497a403 demux_lavf: fix API usage
avio_alloc_context() is documented to require an av_malloc'ed buffer. It
appears libavformat can even reallocate the buffer while it is probing,
so passing a static buffer can in theory lead to crashes.

I couldn't reproduce such a crash, but apparently it happened to
mplayer-svn. This commit follows the mplayer fix in svn commit r36397.
2013-08-04 23:21:50 +02:00
wm4 3bddc16431 options: simplify --correct-pts handling
Remove the (now unused) code for determining correct-pts mode based on
the demuxer in use. Change its description in the manpage to reflect
what this option does now.
2013-07-26 02:11:34 +02:00
wm4 4e7ab517c1 demux_lavf: set keyframe flag on attached pictures
Gives really funky results with PNG attachments otherwise. The main
problem is that avcodec_flush_buffers() does not fully reset the
decoder, so passing multiple PNG packets without keyframe flags will
attempt to combine the new picture with the previously decoded
contents. (Makes no sense with proper PNG - maybe this codepath is
intended for MNG or APNG.)
2013-07-24 19:42:02 +02:00
wm4 65d8709152 demux_lavf: add terrible hack to make DVD playback just work
DVD playback had some trouble with PTS resets: libavformat's genpts
feature would try reading until EOF (worst case) to find a new usable
PTS in case a packet's PTS is not set correctly. Especially with slow
DVD access, this would make the player to appear frozen.

Reimplement it partially in demux_lavf.c, and use that code in the DVD
case. This is heavily "inspired" by the code in av_read_frame from
libavformat/utils.c. The difference is that we stop reading if no PTS
has been found after 50 packets (consider this a heuristic). Also, we
don't bother with the PTS wrapping and last-frame-before-EOF handling.
Even with normal PTS wraps, the player frontend will go to hell for the
duration of a frame anyway, and should recover quickly after that.

The terribleness of this commit is mostly that we duplicate libavformat
functionality, and that we suddenly need a packet queue.
2013-07-14 23:44:50 +02:00
wm4 879c7a101b demux: assume correct-pts mode by default
All demuxers make a reasonable effort to set packet timestamps, and thus
support correct-pts mode. This commit also implicitly switches
demux_rawvideo to correct-pts mode.

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

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

Change demux_lavf so that we check our other builtin demuxers first
before libavformat tries to guess by file extension.
2013-07-12 22:16:26 +02:00
wm4 d17d2fdc7c demux: change signature of open functions, cleanups
Preparation for redoing the open functions.
2013-07-11 21:09:39 +02:00
wm4 4cda1d113e core: completely change handling of attached picture pseudo video
Before this commit, we tried to play along with libavformat and tried
to pretend that attached pictures are video streams with a single
frame, and that the frame magically appeared at the seek position when
seeking. The playback core would then switch to a mode where the video
has ended, and the "remaining" audio is played.

This didn't work very well:
- we needed a hack in demux.c, because we tried to read more packets in
  order to find the "next" video frame (libavformat doesn't tell us if
  a stream has ended)
- switching the video stream didn't work, because we can't tell
  libavformat to send the packet again
- seeking and resuming after was hacky (for some reason libavformat sets
  the returned packet's PTS to that of the previously returned audio
  packet in generic code not related to attached pictures, and this
  happened to work)
- if the user did something stupid and e.g. inserted a deinterlacer by
  default, a picture was never displayed, only an inactive VO window)
- same when using a command that reconfigured the VO (like switching
  aspect or video filters)
- hr-seek didn't work

For this reason, handle attached pictures as separate case with a
separate video decoding function, which doesn't read packets. Also,
do not synchronize audio to video start in this case.
2013-07-11 19:23:56 +02:00
wm4 86cc3bd9be demux_lavf: do stream selection centrally
Removes very minor code duplication for setting the st->discard flag.
2013-07-11 19:23:31 +02:00
wm4 e5544e2da3 demux: improve DVD sub auto-selection hack
The code touched by this commit makes sure that DVD subtitle tracks
known by libdvdread but not known by demux_lavf can be selected and
displayed properly. These subtitle tracks have the first packet
some time late in the packet stream, so that libavformat won't
immediately recognize them, and will add the track as soon as the
first packet is seen during normal demuxing.

demux_mpg used to handle this elegantly: you just set the MPEG ID of
the stream you wanted. demux_lavf couldn't do this, so it was emulated
with a DEMUXER_CTRL. This commit changes it so that new streams are
selected by default (if autoselect is enabled), and the playloop
simply can take appropriate action before the lower layer throws away
the first packet.

This also changes the demux_lavf behavior that subtitle packets are
always demuxed, even if not needed. (They were immediately thrown away,
so there was no advantage to this.)

Further, this adds the ability to demux.c to deal with demuxing more
than one stream of a kind at once. (Though currently it's not useful.)
2013-07-11 19:22:24 +02:00
wm4 83eb28fff7 demux_lavf: use AVDISCARD_DEFAULT instead of AVDISCARD_NONE
AVDISCARD_DEFAULT is probably a bit better for normal decoding.
AVDISCARD_NONE would (as by documentation) include "useless" packets
too, while DEFAULT filters these.
2013-07-11 19:22:02 +02:00
wm4 a6706c41d8 video: eliminate frametime variable 2013-07-11 19:21:45 +02:00
wm4 6ede485e4b core: don't access demux_stream outside of demux.c, make it private
Generally remove all accesses to demux_stream from all the code, except
inside of demux.c. Make it completely private to demux.c.

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

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

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

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

Remove them to facilitate further cleanups.
2013-07-07 23:54:11 +02:00
wm4 88916143a7 demux_lavf: add one more AAC mimetype 2013-06-25 00:55:20 +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 d81b71c7f7 Merge branch 'cache_new' 2013-06-16 22:07:48 +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 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 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 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 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 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 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 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 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 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 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
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 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 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
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
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
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 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 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 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
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
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