Commit Graph

156 Commits

Author SHA1 Message Date
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
wm4 7c991706c5 player: free queued audio frame on uninit 2016-01-23 11:41:19 +01:00
wm4 04ec417d41 audio: refactor: move MPContext.ao_buffer field
It doesn't need to be part of the big context, but is strictly part of
shuffling data from the audio filters to audio output, and thus belongs
into ao_chain.

It also turns out that clearing it in clear_audio_output_buffers() is
completely redundant.

(Of course ao_buffer is an abomination in the first place and shouldn't
exist at all.)
2016-01-22 00:25:44 +01:00
wm4 7bb9203f7f player: refactor: eliminate MPContext.d_audio 2016-01-22 00:25:44 +01:00
wm4 fef8b7984b audio: refactor: work towards unentangling audio decoding and filtering
Similar to the video path. dec_audio.c now handles decoding only. It
also looks very similar to dec_video.c, and actually contains some of
the rewritten code from it. (A further goal might be unifying the
decoders, I guess.)

High potential for regressions.
2016-01-22 00:25:44 +01:00
wm4 aaafbfcc06 audio: remove initial decoding retry limitation
Seems useless.

This only helped in one case: one audio stream in the sample
av_find_best_stream_fails.ts had a AC3 packets which couldn't be
decoded, and for which avcodec_decode_audio4() returned 0 forever. In
this specific case, playback will now not start, and you have to
deselect audio manually.

(If someone complains, the old behavior might be restored, but
differently.)

Also remove the stale "bitrate" field.
2016-01-19 22:49:05 +01:00
wm4 c365b44e19 audio: move dec_audio.pool to ad_spdif
That's where its only use is.
2016-01-19 21:33:05 +01:00
wm4 4195a345a5 player: refactor: eliminate MPContext.d_video
Eventually we want the VO be driven by a A->V filter, so a decoder
doesn't even have to exist. Some features definitely require a decoder
though (like reporting the decoder in use, hardware decoding, etc.), so
for each thing which accessed d_video, it has to be redecided if and how
it can access decoder state.

At least the "framedrop" property slightly changes semantics: you can
now always set this property, even if no video is active.

Some untested changes in this commit, but our bio-based distributed
test suite has to take care of this.
2016-01-17 18:38:07 +01:00
wm4 671df54e4d demux: merge sh_video/sh_audio/sh_sub
This is mainly a refactor. I'm hoping it will make some things easier
in the future due to cleanly separating codec metadata and stream
metadata.

Also, declare that the "codec" field can not be NULL anymore. demux.c
will set it to "" if it's NULL when added. This gets rid of a corner
case everything had to handle, but which rarely happened.
2016-01-12 23:48:19 +01:00
Dmitrij D. Czarkoff ea442fa047 mpv_talloc.h: rename from talloc.h
This change helps avoiding conflict with talloc.h from libtalloc.
2016-01-11 21:05:55 +01:00
wm4 bd5a02d080 player: detect audio PTS jumps, make video PTS heuristic less aggressive
This is another attempt at making files with sparse video frames work
better.

The problem is that you generally can't know whether a jump in video
timestamps is just a (very) long video frame, or a timestamp reset. Due
to the existence of files with sparse video frames (new frame only every
few seconds or longer), every heuristic will be arbitrary (in general,
at least).

But we can use the fact that if video is continuous, audio should also
be continuous. Audio discontinuities can be easily detected, and if that
happens, reset some of the playback state.

The way the playback state is reset is rather radical (resets decoders
as well), but it's just better not to cause too much obscure stuff to
happen here. If the A/V sync code were to be rewritten, it should
probably strictly use PTS values (not this strange time_frame/delay
stuff), which would make it much easier to detect such situations and
to react to them.
2016-01-09 20:39:28 +01:00
wm4 3d03298e86 audio: update outdated comment 2016-01-05 22:08:51 +01:00
wm4 85450d06a1 player: use demuxer ts offset to simplify timeline ts handling
Use the demux_set_ts_offset() added in the previous commit to base each
timeline segment to use timestamps according to its relative position
within the overall timeline. As a consequence we don't need to care
about these timestamps anymore, and everything becomes simpler.

(Another minor but delicious nugget of sanity.)
2015-11-16 23:17:33 +01:00
wm4 fee45c0170 player: silence sporadic error messages on audio init
When the audio format is not known yet and the audio chain is still
initializing, filter reinit will fail. Normally, attempts to
reinitialize filters at this stage should be rare (e.g. user commands
editing the filter chain). But it sometimes happened with track
switching in combination with the video code calling
update_playback_speed() at arbitrary times.

Get rid of the message by not trying to change the filters for the sake
of playback speed update while decoding is still being initialized.
2015-11-10 17:53:05 +01:00
wm4 3108a3a001 audio: do not require full audio chain reinit for speed changes
Actually, it didn't really require that before (most work was avoided),
but some bits had to be run anyway. Separate the speed change into a
light-weight function, which merely updates already created filters, and
a heavy-weight one which messes with filter insertion.

This also happens to fix the case where the filters would "forget" the
current speed (force resampling, change speed, hit a volume control to
force af_volume insertion - it will reset speed and desync).

Since we now always run the light-weight function, remove the
af_scaletempo verbose message that is printed on speed setting. Other
than that, all setters are cheap.
2015-11-04 21:49:54 +01:00
wm4 db1fc3628f audio: strictly align audio on spdif frames
We still have a sample-based buffer between filters and audio outputs.
In order to avoid cutting frames into half (which can upset receivers),
we strictly need to align the boundaries on which we cut the audio.
2015-11-04 21:49:54 +01:00
wm4 350d902799 player: fix display-sync adrop speed limiting
Commit 49d94853 worked only at the start of playback.
2015-11-04 10:57:29 +01:00
wm4 49d94853b5 player: limit speed change in display-sync adrop mode
Discontinuities (like toggling fullscreen) can cause multiple frames to
be dropped in succession, which sounds very weird. It's better to drop
some video frames instead to compensate for larger desyncs.

We roughly base it on the maximum allowed speed changes (audio change is
"additional" to the video change to account for deviations when playing
at max. video speed change).
2015-11-03 20:29:25 +01:00
wm4 ce82d88215 player: reset AO stats on pause and other discontinuities
It's annoying.
2015-10-28 23:57:24 +01:00
wm4 d1ad0815fe player: simplify display-adrop mode safeguard
It's not needed, because the additional data is not appended, but is the
total size of the audio buffer. The maximum size is the static audio
drop size (or twice, if the audio is duplicated).
2015-10-28 23:57:24 +01:00
wm4 aaec2aba38 player: add audio drop/duplicate mode
Not very robust in the moment.
2015-10-27 20:56:46 +01:00
wm4 3b95dd47d5 player: simplify audio sync pts calculation
This was done for symmetry with adjust_sync(). But mpctx->delay is
always 0 at this point, so prefer slightly simpler code.
2015-10-27 20:56:39 +01:00
wm4 f7124be091 audio: add AO deviation logging
Pretty dumb (and doesn't handle pausing or other discontinuities), but
at least somewhat idiot-proof.
2015-10-08 23:20:33 +02:00
wm4 0a41c6f0ec audio: make spdif re-probe from normal decoding work
The previous commit handled not falling back to normal decoding if the
AO was reloaded (I think...), and this tries to re-engage spdif pass-
through if it was previously falling back to normal decoding (e.g.
because it temporarily switched to an audio device incapable of
passthrough).
2015-10-06 20:21:29 +02:00
wm4 66aa54d319 audio: re-probe spdif if AO is reloaded
Makes the spdif automagic work better on audio hotplugging.
2015-10-06 19:59:02 +02:00