Commit Graph

180 Commits

Author SHA1 Message Date
wm4 afead7a356 audio: merge --replaygain-track and --replaygain-album into one option
This is probably better than separate options. For example, the user
does not have to guess which one is applied if both options are enabled.
2017-04-27 00:21:17 +02:00
wm4 90a1ca02a2 audio: fix replaygain volume scale
The new replaygain code accidentally applied the linear gain as cubic
volume level. Fix this by moving the computation of the volume scale out
of the af_volume filter.

(Still haven't verified whether the replaygain code works correctly.)
2017-04-27 00:15:32 +02:00
wm4 f1c4d20e65 audio: move replaygain control to top-level options
af_volume is deprecated, and so are its replaygain sub-options. To make
it possible to use replaygain without deprecated options (and of course
to make it available at all after af_volume is dropped), reintroduce
them as top-level options.

This also means that they are easily changeable at runtime by using them
as properties. Change the "volume" property to use the new update
mechanism as well.

We don't actually bother sharing the implementation between new and
deprecated mechanisms, as the deprecated one will simply be deleted.

For the from_dB() functions, we mention anders' copyright, although I'm
not sure if a mere formula is copyrightable. This will have to be
determined later.

This whole change is mostly untested. Our distributed human CI will take
care of it.
2017-04-26 21:45:55 +02:00
Marko Hauptvogel 3fe6b36eb0 player: close audio device on no audio track
Close the audio device if there is no audio track (or stream) in the
current file. It will be opened again if the next file should contain
audio.

Signed-off-by: Marko Hauptvogel <marko.hauptvogel@googlemail.com>
Signed-off-by: wm4 <wm4@nowhere>
2017-04-25 20:21:09 +02:00
wm4 b96a74ec2a audio: deprecate most audio filters
Well, ok, only 4 filters. The rest will survive in one or the other
form.
2017-04-04 15:04:07 +02:00
wm4 d606b6af17 player: specifically log audio EOF too 2017-03-14 15:55:42 +01:00
wm4 c4ad2732f9 audio: stop being dumb
Obvious mistake: we entered EOF drain mode if the decoder returned
AD_WAIT, which is very wrong. AD_WAIT means we should retry after
waiting for a while (or to be precise, until the demuxer/decoder
have more data). We should just pass down this status, and not
change the audio chain state.

This was exposed by a libavfilter EOF handling bug. Feeding a filter
chain with af_dynaudnorm, and sending an EOF before a frame is returned
makes it stuck and keeps returning EAGAIN, instead of returning the
buffered audio. In combination with the bug at hand, which entered
EOG drain mode, it could happen that it got stuck due to libavfilter
discarding buffered data each time the demuxer ran out of data.

Fixes #3997.
2017-01-08 14:47:53 +01:00
Aman Gupta 7cd32ec29e audio: force pts_reset only when pts jumps forward more than 5s
i've seen several mpegts samples where pts jumps backwards and repeats
itself. this usually happens on live tv streams from cable providers,
particularly when the stream switches from one advertisement to another.
2016-10-21 17:11:26 +02:00
wm4 6fb12a5fda audio: move some fallback handling to common AO reload function
Now a reload requested by an AO behaves in exactly the same way as
changing an AO-related options (like --audio-channels or
--audio-exclusive). This is good for testing and uniform behavior. (You
could go as far as saying it's a necessity, because the spotty and
obscure AO reload behavior is hard to reproduce and thus hard to test at
all.)
2016-10-05 16:42:43 +02:00
wm4 3a5cbf3907 audio: fix late audio start
Regression since commit bbcd0b6a. This code is just cursed, because it's
a fragile state machine with no proper tests, and which could be done in
a much simpler way. Without doubt this change will cause a regression in
some ridiculous corner case as well.

Fixes #3610 (the cause of it, not the behavior it resulted in).
2016-10-02 13:47:25 +02:00
Kevin Mitchell 5fca497698 audio: fix segfault when yanking USB DAC
The ao_c pointer was stale after the mpctx entry was freed / NULLed.
This prevented the correct early exit from fill_audio_out_buffers.
2016-09-20 14:46:36 +02:00
wm4 03fec24e19 player: litter code with explicit wakeup calls
This does 3 kinds of changes:
- change sleeptime=x to mp_set_timeout()
- change sleeptime=0 to mp_wakeup_core() calls (to be more explicit)
- change commands etc. to call mp_wakeup_core() if they do changes that
  require the playloop to be rerun

This is preparation for the following changes. The goal is to process
client API requests without having to rerun the playloop every time. As
of this commit, the changes should not change behavior. In particular,
the playloop is still implicitly woken up on every command.
2016-09-16 14:39:45 +02:00
wm4 b8ade7c99b player, ao, vo: don't call mp_input_wakeup() directly
Currently, calling mp_input_wakeup() will wake up the core thread (also
called the playloop). This seems odd, but currently the core indeed
calls mp_input_wait() when it has nothing more to do. It's done this way
because MPlayer used input_ctx as central "mainloop".

This is probably going to change. Remove direct calls to this function,
and replace it with mp_wakeup_core() calls. ao and vo are changed to use
opaque callbacks and not use input_ctx for this purpose. Other code
already uses opaque callbacks, or has legitimate reasons to use
input_ctx directly (such as sending actual user input).
2016-09-16 14:37:48 +02:00
wm4 8bfcae748c audio: fix missed wakeup when changing audio output device
When playing audio-only, and changing the audio output device, playback
froze until the next time the playback core happened to wakeup (like
moving the mouse, or OSD redrawing). This is probably because of the
awful statemachine in fill_audio_out_buffers() - just make it recreate
the AO directly instead.
2016-09-15 14:50:38 +02:00
wm4 1d9032f011 audio/out: deprecate "exclusive" sub-options
And introduce a global option which does this. Or more precisely, this
deprecates the global wasapi and coreaudio options, and adds a new one
that merges their functionality. (Due to the way the sub-option
deprecation mechanism works, this is simpler.)
2016-09-05 21:26:39 +02:00
wm4 c4ba600832 audio: avoid missed wakeups with ab-loops
Could get "stuck".
2016-08-24 12:14:48 +02:00
wm4 724f60bf9a audio: do not apply --audio-channels if spdif passthrough is in use
If spdif is enabled, the channel layout has no meaning other than
setting the number of channels. The number of channels must be fixed to
achieve the exact bitrate required.

Fixes #3445.
2016-08-22 12:12:10 +02:00
wm4 bbcd0b6a03 audio: improve aspects of EOF handling
The code actually kept going out of EOF mode into resync mode back into
EOF mode when the playloop had to wait after an audio EOF caused by the
endpts. This would break seamless looping (as added by the next commit).

Apply endpts earlier, to ensure the filter_audio() function always
returns AD_EOF in this case.

The idiotic ao_buffer makes this an amazing pain in the ass.
2016-08-18 20:38:09 +02:00
wm4 86fa1e6129 player: allow passing flags to queue_seek()
Change the last parameter from a bool to an int, which is supposed to
take bit-flags. The at this point only flag is MPSEEK_FLAG_DELAY, which
replaces the previous bool parameter. The old false parameter becomes 0,
the old true parameter becomes MPSEEK_FLAG_DELAY.

Since the old "immediate" parameter is now essentially inverted, two
coalesced immediate and delayed seeks end up as delayed instead of
immediate. This change doesn't matter, since there are no relative
immediate seeks anyway.
2016-08-15 21:07:32 +02:00
wm4 062349ff5b player: add --audio-wait-open options
Complements the option added in the previous commit.
2016-08-09 17:09:29 +02:00
wm4 eab92cec60 player: add --audio-stream-silence
Completely insane that this has to be done. Crap for compensating HDMI
crap.
2016-08-09 17:09:29 +02:00
wm4 259f219438 player: gross hack to improve non-hr seeking with external audio tracks
Relative seeks backwards with external audio tracks does not always work
well: it tends to happen that video seek back further than audio, so
audio will remain silent until the audio's after-seek position is
reached. This happens because we strictly seek both video and audio
demuxer to the approximate desirted target PTS, and then start decoding
from that.

Commit 81358380 removes an older method that was supposed to deal with
this. It was sort of bad, because it could lead to the playback core
freezing by waiting on network.

Ideally, the demuxer layer would probably somehow deal with such seeks,
and do them in a way the audio is seeked after video. Currently this is
infeasible, because the demuxer layer assumes a single demuxer, and
external tracks simply use separate demuxer layers. (MPlayer actually
had a pseudo-demuxer that joined external tracks into a single demuxer,
but this is not flexible enough - and also, the demuxer layer as it
currently exists can't deal with dynamically removing external tracks
either. Maybe some time in the future.)

Instead, add a gross hack, that essentially reseeks the audio if it
detects that it's too far off. The result is actually not too bad,
because we can reuse the mechanism that is used for instant track
switching. This way we can make sure of the right position, without
having to care about certain other issues.

It should be noted that if the audio demuxer is used for other tracks
too, and the demuxer does not support refresh seeking, audio will
probably be off by even a higher amount. But this should be rare.
2016-08-07 16:29:13 +02:00
wm4 c7b73edc65 player: fix mid-stream audio sync condition
This code is for resyncing audio-only streams (e.g. switching between
audio tracks if no video track is active). This must not be run if the
video PTS just isn't known yet. (Although the case in which this changes
anything is probably very obscure, if it can even happen. Still, it's a
bit more correct.)

This is a correction to commit 91a3bda6.
2016-08-07 16:00:14 +02:00
wm4 91a3bda6f5 player: sync audio as well when enabling it mid-stream
If an audio track is enabled during playback, then make it resume at the
exact "current position", instead of playing audio before that position.
This was already done for video.
2016-08-06 17:48:45 +02:00
wm4 0b144eac39 audio: use --audio-channels=auto behavior, except on ALSA
This commit adds an --audio-channel=auto-safe mode, and makes it the
default. This mode behaves like "auto" with most AOs, except with
ao_alsa. The intention is to allow multichannel output by default on
sane APIs. ALSA is not sane as in it's so low level that it will e.g.
configure any layout over HDMI, even if the connected A/V receiver does
not support it. The HDMI fuckup is of course not ALSA's fault, but other
audio APIs normally isolate applications from dealing with this and
require the user to globally configure the correct output layout.

This will help with other AOs too. ao_lavc (encoding) is changed to the
new semantics as well, because it used to force stereo (perhaps because
encoding mode is supposed to produce safe files for crap devices?).
Exclusive mode output on Windows might need to be adjusted accordingly,
as it grants the same kind of low level access as ALSA (requires more
research).

In addition to the things mentioned above, the --audio-channels option
is extended to accept a set of channel layouts. This is supposed to be
the correct way to configure mpv ALSA multichannel output. You need to
put a list of channel layouts that your A/V receiver supports.
2016-08-04 20:49:20 +02:00
wm4 c30aa23401 player: remove special-case for DL/DR speakers
Pointless anyway. With superficial checking I couldn't find any decoder
which actually outputs this, and AO chmap negotiation would properly
ignore them anyway in most cases.
2016-08-04 19:14:35 +02:00
wm4 77e1e8e38e audio: refactor mixer code and delete mixer.c
mixer.c didn't really deserve to be separate anymore, as half of its
contents were unnecessary glue code after recent changes. It also
created a weird split between audio.c and af.c due to the fact that
mixer.c could insert audio filters. With the code being in audio.c
directly, together with other code that unserts filters during runtime,
it will be possible to cleanup this code a bit and make it work like the
video filter code.

As part of this change, make the balance code work like the volume code,
and add an option to back the current balance value. Also, since the
balance semantics are unexpected for most users (panning between the
audio channels, instead of just changing the relative volume), and there
are some other volumes, formally deprecate both the old property and the
new option.
2016-07-17 19:21:28 +02:00
wm4 995c47da9a audio: drop --softvol=no and --softvol=auto
Drop the code for switching the volume options and properties between
af_volume and AO volume controls. interface-changes.rst mentions the
changes in detail.

Do this because this was exceedingly complex and had other problems as
well. It was also very hard to test. It's just not worth the trouble.

Some leftovers like AOCONTROL_HAS_PER_APP_VOLUME will be removed at a
later point.

Fixes #3322.
2016-07-09 18:31:18 +02:00
wm4 cd9ee1a853 player: really start audio only once video is ready
The check whether video is ready yet was done only in STATUS_FILLING.
But it also switched to STATUS_READY, which means the next time
fill_audio_out_buffers() was called, audio would actually be started
before video.

In most situations, this bug didn't show up, because it was only
triggered if the demuxer didn't provide video packets quickly enough,
but did for audio packets.

Also log when audio is started.

(I hate fill_audio_out_buffers(), why did I write it?)
2016-04-20 13:08:06 +02:00
wm4 c13c9945bf player: add missing audio reconfig events
This also takes care of sending the required property change
notifications.

Fixes #2929 and maybe fixes #2920.
2016-03-13 15:52:17 +01:00
wm4 49660bcc3e player: minor simplification
No need to pass endpts down in such a dumb way.

Also remove an outdated comment somewhere.
2016-02-27 20:03:15 +01:00
wm4 71fa2e6fc2 player: slightly simplify how demuxer streams are enabled/disabled
Instead of having reselect_demux_streams() look at all streams, make it
look at the current stream that is being enabled/disabled.
2016-02-25 22:44:50 +01:00
wm4 f2b039da77 audio/video: expose codec info as separate field
Preparation for the timeline rewrite. The codec will be able to change,
the stream header not.
2016-02-15 20:34:45 +01:00
wm4 0868546f9d player: remove dead code
Fixes CID 1350055 and CID 1350054.
2016-02-12 16:06:20 +01:00
wm4 0b427c54ad player: remove double assignment in declaration
Fixes CID 1350058.

(Still looks like this might be valid C, in some fucked up way.)
2016-02-12 16:00:20 +01:00
wm4 b7f6dfc19a player: force refresh seek when changing audio filters
Unfortunately I see no better solution.

The refresh seek is skipped if the amount of buffered audio is not
overly huge.

Unfortunately softvol af_volume insertion still can cause this issue,
because it's outside of the normal dynamic filter chain changing code.

Move the video refresh call to reinit_video_filters() to make it more
uniform along with the audio code.
2016-02-09 22:19:01 +01:00
wm4 a0d3ce4819 audio: fix EOF handling if nothing could be decoded at all
The code for decoding the initial frame has to handle this explicitly.
2016-02-06 18:33:31 +01:00
wm4 ffb1d7807e player: remove some further current_track dependencies
Now it's used for initialization only for audio and video.
2016-02-05 23:41:44 +01:00
wm4 c0de087ba1 player: add complex filter graph support
See --lavfi-complex option.

This is still quite rough. There's no support for dynamic configuration
of any kind. There are probably corner cases where playback might freeze
or burn 100% CPU (due to dataflow problems when interaction with
libavfilter).

Future possible plans might include:
- freely switch tracks by providing some sort of default track graph
  label
- automatically enabling audio visualization
- automatically mix audio or stack video when multiple tracks are
  selected at once (similar to how multiple sub tracks can be selected)
2016-02-05 23:19:56 +01:00
wm4 8af70561a4 player: move audio and video decoder init to separate functions
Preparation.
2016-02-05 23:17:27 +01:00
wm4 5c8378b71a player: use different variable to indicate coverart
Slightly better.
2016-02-01 22:14:32 +01:00
wm4 ab318aeea8 audio/video: merge decoder return values
Will be helpful for the coming filter support. I planned on merging
audio/video decoding, but this will have to wait a bit longer, so only
remove the duplicate status codes.
2016-02-01 22:03:04 +01:00
wm4 a9dfd8d557 audio: use brutal resync only on larger PTS discontinuities
Let's fix broken samples with questionable heuristic without real
reasoning. Until this gets fixed properly, this is a good compromise,
though. A proper fix would properly resync audio and video without
brutally resetting the decoders, but on the other hand not doing the
brutal reset would cause issues in other obscure corner cases such
resyncing might cause.
2016-01-31 22:10:11 +01:00
wm4 c440ee99a4 audio: fix a case of going to sleep before playback start
This code is tricky because it has to wakeup the mainloop to make
progressing during syncing audio, but also has to avoid waking it up
when it's not needed. Failure to do so either burns CPU by not ever
going to sleep, or causes apparent "freezes" by going to sleep (and it
will continue if the mainloop is woken up e.g. due to user input).

In this case, simply starting A/V playback with --start=5 and removing
an unrelated wakeup in osd.c can trigger such a "freeze". The unrelated
wakeup did hide this bug, nonetheless it's a bug.

(Can't wait to rewrite this shitty audio resync code. And it's all my
fault.)
2016-01-31 22:02:02 +01:00
wm4 526d578bee player: refactor: some more minor decoder/output decoupling
These changes don't make too much sense without context, but are
preparation for later. Then the audio_src/video_src fields will be
actually be NULL under circumstances.
2016-01-29 22:46:28 +01:00
wm4 c00dc5c5c6 audio: refactor: separate audio init and filter/output init
Before this commit, reinit_audio_chain() did 2 things: create all the
management data structures and initialize the decoder, and handling lazy
filter/output init (as well as dealing with format changes). For the
second purpose, it could be called multiple times (even though it wasn't
really idempotent). This was pretty weird, so make them separate
functions. The new function is actually idempotent too.

It also turns out the reinit functions don't have to call themselves
recursively for the spdif PCM fallback.
2016-01-29 22:44:35 +01:00
wm4 c5a48c6332 audio: move pts reset check
Reduces the dependency of the filter/output code on the decoder.
2016-01-29 22:44:20 +01:00
wm4 340deb4e6e player: fix initial audio sync in certain cases
Regression caused by commit 3b95dd47. Also see commit 4c25b000. We can
either use video_next_pts and add "delay", or we just use video_pts. Any
other combination breaks. The reason why the assumption that delay==0 at
this point was wrong exactly because after displaying the first video
frame (usually done before audio resync) a new frame might be "added"
immediately, resulting in a new video_next_pts and "delay", which will
still amount to video_pts.

Fixes #2770. (The reason why display-sync was blamed in this issue is
because enabling display-sync in the options forces a prefetch by 2
instead of 1 frames for seeks/playback restart, which triggers the
issue, even if display-sync is not actually enabled. In this case,
display-sync is never enabled because the frames have a unusually high
frame duration. This is also what exposed the initial desync issue.)
2016-01-29 22:43:59 +01:00
wm4 266d8368e8 audio: fix spdif PCM fallback
With the format left untouched, this would just try to reinit with a
spdif format again.

We're not clearing the format in reset_audio_state() so the audio chain
can be recreated any time without having to wait for a frame to be
decoded.
2016-01-25 13:43:43 +01:00
wm4 223588b36a audio: release pending audio frame on seeking 2016-01-25 13:41:28 +01:00