Commit Graph

694 Commits

Author SHA1 Message Date
wm4 4b2f81a36f ao_pulse: don't use pa_format_info_to_sample_spec()
This function is available starting with PulseAudio 2.0, while we only
require 1.0. This broke compilation on Ubuntu 12.04.5 LTS.

Use our own function to calculate the buffer size, which is actually
simpler and needs slightly less code.

Hopefully fixes #1154.
CC: @mpv-player/stable
2014-10-06 21:49:26 +02:00
wm4 9e3e5ca598 audio/out/push: fix some AOs freezing on exit
Caused by a dumb deadlock.
2014-10-05 23:05:54 +02:00
wm4 aeefb8511c audio/out/push: make draining more robust
It was more complicated than it had to be: the audio thread already
determines whether audio has ended, so we can use that. Remove the
separate logic for draining.
2014-10-05 00:31:20 +02:00
wm4 6431e09fb3 audio/out/push: limit fallback sleep time to reasonable limits 2014-10-05 00:13:00 +02:00
wm4 0d4e245de7 ao_pulse: change suspend circumvention logic
Commit 957097 attempted to use PA_STREAM_FAIL_ON_SUSPEND to make
ao_pulse exit if the stream was started suspended.

Unfortunately, PA_STREAM_FAIL_ON_SUSPEND is active even during playback.
If you pause mpv, pulseaudio will close the actual audio device after a
while (or something like this), and unpausing won't work. Instead, it
will spam "Entity killed" error messages.

Undo this change and check for suspended audio manually during init.

CC: @mpv-player/stable
2014-10-04 23:30:07 +02:00
wm4 f679c5de1b ad_lavc: avoid warning messages on older FFmpeg or Libav
If the flag doesn't exist, the av_opt_set() API will print warning
messages.
2014-10-04 12:30:34 +02:00
wm4 9570976255 ao_pulse: refuse to start suspended
Sometimes, ao_pulse starts in suspended mode, which means playback is
essentially paused in pulseaudio. This gives the impression that mpv is
hanging, since it times video against the audio playback progress, and
audio never makes progress in this state.

I'm not sure if this will help - possibly it does with mixed
pulseaudio/alsa setups. However, if the alsa setup has the pulseaudio
plugin, alsa will hang too. But there's still a chance we get less
blame for pulseaudio messes.
2014-10-03 23:04:12 +02:00
wm4 cf2add4ff9 audio: skip samples and adjust timestamps ourselves
This gets rid of this warning:

  Could not update timestamps for skipped samples.

This required an API addition to FFmpeg (otherwise it would instead
doing arithmetic on the timestamps itself), so whether it works depends
on the FFmpeg version.
2014-10-03 23:03:22 +02:00
wm4 b5942f80de audio/filter: allow removing filters by label
Although the "af" command already could do this, it seems it's better
to introduce a lower level mechanism for now. This avoids some messy
issues, since that code would recursive call reinit_audio_chain().

To be used by the next commit.
2014-10-02 02:50:12 +02:00
wm4 7dd3822d09 audio: refactor some aspects of filter chain setup
There's no real reason why audio_init_filter() should exist. Just use
af_init or af_reinit directly. (We lose a useless message; the same
information is printed in a quite close place with more details.)

Requires less code, and the way the filter chain is marked as having
failed to initialize allows just switching off audio instead of
crashing if trying to insert a volume filter in mixer.c fails, and
recreating the old filter chain fails too.
2014-10-02 02:42:23 +02:00
wm4 2e16dfbf93 audio/filter: don't wipe full filter chain if adding a filter fails
There's no need for that, and in fact makes it more likely that it
recovers normally.
2014-10-02 01:20:01 +02:00
wm4 650af29471 audio/out/push: clean up properly on init error
Close the wakeup pipes, free the mutex and condition var.
2014-09-27 04:54:17 +02:00
wm4 e79de41b97 audio/out: check device buffer size for push.c only
Should fix #1125.
2014-09-27 04:52:46 +02:00
wm4 d778130dc4 audio/out: disable ao_sndio by default
Don't build it, move it down the autoprobe list even if it's enabled. It
doesn't work well enough.
2014-09-26 15:52:29 +02:00
wm4 4784ca32c9 audio/out: fail init on unknown audio buffer
A 0 audio buffer makes push.c go haywire. Shouldn't normally happen.
2014-09-26 15:50:04 +02:00
wm4 387d5f55e6 ao_sndio: print a warning when draining audio
libsndio has absolutely no mechanism to discard already written audio
(other than SIGKILLing the sound server). sio_stop() will always block
until all audio is played. This is a legitimate design bug.

In theory, we could just not stop it at all, so if the player is e.g.
paused, the remaining audio would be played. When resuming, we would
have to do something to ensure get_delay() returns the right value. But
I couldn't get it to work in all cases.
2014-09-26 15:46:39 +02:00
wm4 da1918b894 ao_sndio: update buffer status on get_delay
get_delay needs to report the current audio buffer status. It's
important for A/V sync that this information is current, but functions
which update it were called on play() or get_space() calls only.
2014-09-26 15:46:36 +02:00
wm4 3208f8c445 ao_sndio: change p->delay to samples
This was in bytes, but it's more convenient to use samples (or frames;
in any case the smallest unit of audio that includes all channels).

Remove the ao->bps line too; it will be set after init() returns.
2014-09-26 15:46:33 +02:00
wm4 12d93fdfef ao_sndio: set non-blocking flag
Otherwise the feed thread and the playloop will get randomly blocked.

This seems to fix most A/V sync issues.
2014-09-26 15:46:30 +02:00
wm4 1b1421866d ao_sndio: fix some incorrect comments
The AO API always uses sample counts.
2014-09-26 15:46:23 +02:00
wm4 9c3c199558 audio: remove WAVEFORMATEX from internal demuxer API
Same as with the previous commit. A bit more involved due to how the
code is written.
2014-09-25 01:56:51 +02:00
wm4 e977624d87 audio: confine demux_mkv audio PCM hack
Let codec_tags.c do the messy mapping.

In theory we could simplify further by makign demux_mkv.c directly use
codec names instead of the MPlayer-inherited "internal FourCC" business,
but I'd rather not touch this - it would just break things.
2014-09-24 23:33:21 +02:00
wm4 9ac86d9e99 audio: decouple demux and audio decoder/filter sample formats
For a while, we used this to transfer PCM from demuxer to the filter
chain. We had a special "codec" that mapped what MPlayer used to do
(MPlayer passes the AF sample format over an extra field to ad_pcm,
which specially interprets it).

Do this by providing a mp_set_pcm_codec() function, which describes a
sample format in a generic way, and sets the appropriate demuxer header
fields so that libavcodec interprets it correctly. We use the fact that
libavcodec has separate PCM decoders for each format. These are
systematically named, so we can easily map them.

This has the advantage that we can change the audio filter chain as we
like, without losing features from the "rawaudio" demuxer. In fact, this
commit also gets rid of the audio filter chain formats completely.
Instead have an explicit list of PCM formats. (We could even just have
the user pass libavcodec PCM decoder names directly, but that would be
annoying in other ways.)
2014-09-24 22:55:50 +02:00
wm4 8a8f65d73d ao_sndio: fix U24 bit width
This was wrong since the initial commit.
2014-09-24 21:32:15 +02:00
wm4 7954017b56 ao_oss: improve format negotiation, and hopefully fix pass-through
Digital pass-through was probably broken. Possibly fix it (no way to
test). This also should make the logic slightly saner.

Fortunately, it's unlikely that anyone who uses OSS has a spdif setup.
2014-09-24 01:12:14 +02:00
wm4 bf927531aa ao_coreaudio: fix build failure
Commit 5b5a3d0c broke this. The really funny thing is that this code was
actually always under "#if BYTE_ORDER == BIG_ENDIAN". The breaking
commit just edited this code slightly, but it must have failed to
compile on big endian long before (since over 1 year ago, commit d3fb58).
2014-09-24 00:05:18 +02:00
wm4 429260a35c ao_oss: unbreak
Oops.
2014-09-23 23:34:30 +02:00
wm4 c2fa9f6629 ao_pulse: digital pass-through
Should be able to pass-through AC3, DTS, and others.

It seems PulseAudio wants players to fallback to PCM on certain events
signaled by the server, but we don't implement that. There's not much
documentation available anyway.
2014-09-23 23:11:55 +02:00
wm4 7230d88c7e ao_pulse: correctly wait for stream state
This works similar to condition variables; for some reason this
apparently worked fine until now, but it breaks with passthrough mode.
2014-09-23 23:11:55 +02:00
wm4 601fb2f93a ao_pulse: use pa_stream_new_extended()
Needed for compressed audio pass-through later.
2014-09-23 23:11:55 +02:00
wm4 81bf9a1963 audio: cleanup spdif format definitions
Before this commit, there was AF_FORMAT_AC3 (the original spdif format,
used for AC3 and DTS core), and AF_FORMAT_IEC61937 (used for AC3, DTS
and DTS-HD), which was handled as some sort of superset for
AF_FORMAT_AC3. There also was AF_FORMAT_MPEG2, which used
IEC61937-framing, but still was handled as something "separate".

Technically, all of them are pretty similar, but may use different
bitrates. Since digital passthrough pretends to be PCM (just with
special headers that wrap digital packets), this is easily detectable by
the higher samplerate or higher number of channels, so I don't know why
you'd need a separate "class" of sample formats (AF_FORMAT_AC3 vs.
AF_FORMAT_IEC61937) to distinguish them. Actually, this whole thing is
just a mess.

Simplify this by handling all these formats the same way.
AF_FORMAT_IS_IEC61937() now returns 1 for all spdif formats (even MP3).
All AOs just accept all spdif formats now - whether that works or not is
not really clear (seems inconsistent due to earlier attempts to make
DTS-HD work). But on the other hand, enabling spdif requires manual user
interaction, so it doesn't matter much if initialization fails in
slightly less graceful ways if it can't work at all.

At a later point, we will support passthrough with ao_pulse. It seems
the PulseAudio API wants to know the codec type (or maybe not - feeding
it DTS while telling it it's AC3 works), add separate formats for each
codecs. While this reminds of the earlier chaos, it's stricter, and most
code just uses AF_FORMAT_IS_IEC61937().

Also, modify AF_FORMAT_TYPE_MASK (renamed from AF_FORMAT_POINT_MASK) to
include special formats, so that it always describes the fundamental
sample format type. This also ensures valid AF formats are never 0 (this
was probably broken in one of the earlier commits from today).
2014-09-23 23:11:54 +02:00
wm4 308d72a02e ao_wasapi: fix fragile format-mapping code
This code tried to play with the format bits, and potentially could
create invalid formats, or reinterpret obscure formats in unexpected
ways.

Also there was an abort() call if the winapi or mpv used a format with
unexpected bit-width. This could probably easily happen; for example,
mpv supports at least one 64 bit format. And what would happen on 8 bit
formats anyway?

Untested.
2014-09-23 23:09:29 +02:00
wm4 b745c2d005 audio: drop swapped-endian audio formats
Until now, the audio chain could handle both little endian and big
endian formats. This actually doesn't make much sense, since the audio
API and the HW will most likely prefer native formats. Or at the very
least, it should be trivial for audio drivers to do the byte swapping
themselves.

From now on, the audio chain contains native-endian formats only. All
AOs and some filters are adjusted. af_convertsignendian.c is now wrongly
named, but the filter name is adjusted. In some cases, the audio
infrastructure was reused on the demuxer side, but that is relatively
easy to rectify.

This is a quite intrusive and radical change. It's possible that it will
break some things (especially if they're obscure or not Linux), so watch
out for regressions. It's probably still better to do it the bulldozer
way, since slow transition and researching foreign platforms would take
a lot of time and effort.
2014-09-23 23:09:25 +02:00
wm4 5b5a3d0c46 audio: remove swapped-endian spdif formats
IEC 61937 frames should always be little endian (little endian 16 bit
words). I don't see any apparent need why the audio chain should handle
swapped-endian formats.

It could be that some audio outputs might want them (especially on big
endian architectures). On the other hand, it's not clear how that works
on these architectures, and it's not even known whether the current code
works on big endian at all. If something should break, and it should
turn out that swapped-endian spdif is needed on any platform/AO,
swapping still could be done in-place within the affected AO, and
there's no need for the additional complexity in the rest of the player.

Note that af_lavcac3enc outputs big endian spdif frames for unknown
reasons. Normally, the resulting data is just pulled through an auto-
inserted conversion filter and turned into little endian. Maybe this was
done as a trick so that the code didn't have to byte-swap the actual
audio frame. In any case, just make it output little endian frames.

All of this is untested, because I have no receiver hardware.
2014-09-23 19:34:14 +02:00
wm4 9ce4526139 audio: prefer libavcodec over libmpg123
libavcodec/libavformat now handles gapless audio better. In theory, this
could be implemented with ad_mpg123 too, but since libavformat strips
metadata from mp3 files and passes pure mp3 packets to the decoders
only, this can't work by itself. Instead, the player must pass this
metadata separately. libav* do this relatively transparently over packet
"side data" (attached to AVPacket).

It might also be possible to let libmpg123 handles all this by
implementing it as demuxer that outputs PCM, but that would have other
problems, and I think it's better to make libavformat work correctly.

libmpg123 can still be used with '--ad=mpg123:mp3'.

Also see issue #1101.
2014-09-22 22:38:06 +02:00
wm4 7329101478 mixer: always restore volume (even with pulse), don't unmute
Be less clever, and restore the volume state even with AOs like pulse,
which have per-application audio.

Before this commit we didn't do this, because the volume is global (even
if per-application), so the volume will persist between invocations. But
to me it looks like always restoring is less tricky and makes for easier
to understand semantics.

Also, don't always unmute on exit. Unmuting was done even with ao_pulse,
and interfered with user expectations (see #1107).

This might annoy some users, because mpv will change the volume all the
time. We will see.

Fixes #1107.
2014-09-20 02:02:29 +02:00
wm4 c86b4790a8 af_hrtf: initialize coefficient arrays
Sometimes, --af=hrtf produces heavy artifacts or silence. It's possible
that this commit fixes these issues. My theory is that usually, the
uninitialized coefficients quickly converge to sane values as more audio
is filtered, which would explain why there are often artifacts on init,
with normal playback after that. It's also possible that sometimes, the
uninitialized values were NaN or inf, so that the artifacts (or silence)
would never go away.

Fix this by initializing the coefficients to 0. I'm not sure if this is
correct, but certainly better than before.

See issue #1104.
2014-09-19 21:16:42 +02:00
wm4 396756e58a ao_oss: prevent hang when unpausing after device was lost
Pausing/unpausing while the audio device can't be reopened, and then
unpausing again when the device is finally reopened, can hang the
player for a while.

This happens because p->prepause_samples grows without bounds each
time the player is unpaused while the device is lost. On unpause,
ao_oss plays prepause_samples of silence to compensate for A/V timing
issues due to the partially lost buffer (we can't pause the device at
an arbitrary sample position, and the current period will be lost).
This in turn will make the player appear to be frozen if too much
audio is queued. (Normally, play() must never block, but here it
happens because more data is written than get_space() reports. A
better implementation would never let prepause_samples grow larger
than the period size.)

The unbounded growth happens because get_space() always returns that
the device can be written while the device is lost. So limit it to
200ms. (A better implementation would limit it to the period size.)

Also see #1080.
2014-09-17 00:33:40 +02:00
wm4 c158e4641a ao_oss: move code around
More logical, and preparation for the next commit. No functional
changes.
2014-09-17 00:14:21 +02:00
wm4 b2b1b848da af_lavrresample: fix crash with size 0
The filter output size can be 0. Due to how filtering works, this is
nothing unusual, but avresample_convert() will return 0. The same case
is already handling with "normal" resampling (this commit fixes the
reordering code).

Additionally, don't use an assert(). avresample_convert() failing is
unusual, but might also happen due to e.g. internal out of memory
conditions, so we shouldn't just crash on it.

Curiously observed with --ao=oss --audio-channels=5.1 when changing
speed.
2014-09-15 23:14:19 +02:00
wm4 7c2fb859ab ao_oss: don't break playback when device can't be reopened
Apparently NetBSD users want/need this (see issue #1080).

In order not to break playback, we need at least to emulate get_delay().
We do this approximately by using the system clock.

Also, always close the audio device on reset. Reopen it on play only. If
we can't reopen it, don't retry until after the next time reset or
resume is called, to avoid spam and unexpectedly "stealing" back the
audio device.

Also do something about framestepping causing audio desync.
2014-09-15 23:08:19 +02:00
wm4 d5b8b5b901 ao_oss: audio_buf_info isn't state
The context struct had an audio_buf_info field, but there's no reason
why this would be needed. It's a tiny struct, and it isn't permanent
state. It's always returned by SNDCTL_DSP_GETOSPACE. Keeping this as
field is just confusing, so get rid of it.
2014-09-15 22:02:04 +02:00
wm4 b951326a38 ao_oss: remove duplicate audio device open code
The code for reopening the audio device was separate, and duplicated
some of the "real" open code. This was very badly done, and major
required parts of initialization were skipped. Fix this by removing
the code duplication. This consists mainly of moving the code for
opening the device to a separate function, and adding some changes
to handle format changes gracefully. (We can't change the audio
format on the fly, but we can at least not explode and play noise
when that happens.)

As a minor change, actually always use SNDCTL_DSP_RESET when closing
the audio device. We don't want to wait until the rest of the buffer
is played.

Also, don't use strerror() when printing the error message that
reopening failed, simply because reopen_device() takes care of this,
and also errno might be clobbered at this point.
2014-09-15 22:02:04 +02:00
wm4 9ca1582953 ao_oss: assume audio format reinit is not needed with SNDCTL_DSP_RESET
I have no idea whether this is true, because there literally doesn't
seem to exist documentation for SNDCTL_DSP_RESET. But at least on
Linux' OSS emulation, it is true. Also, it would be quite insane if
it would be needed.
2014-09-15 21:56:46 +02:00
wm4 2308eda2b8 ao_oss: don't use SNDCTL_DSP_RESET when pausing on NetBSD
It seems on NetBSD SNDCTL_DSP_RESET exists, but using it for pausing
is not feasible. We still use it to discard the audio buffer when
closing the audio device.
2014-09-15 21:54:28 +02:00
wm4 8efc4b7e24 ao_oss: fix incorrect comments using bytes instead of samples
MPlayer uses bytes, mpv uses sample counts in the AO API.
2014-09-15 20:22:12 +02:00
wm4 d26a0ae111 ao_oss: fix audio device leak on error
Close the audio device if it was already opened, but the rest of
initialization failed.
2014-09-11 02:05:12 +02:00
wm4 5f80e3f91a ao_oss: use poll(), drop --disable-audio-select support
Replace select() usage with poll() (and reduce code duplication).

Also, while we're at it, drop --disable-audio-select, since it has the
wrong name anyway. And I have doubts that this is needed anywhere. If
it is, it should probably fallback to doing the right thing by default,
instead of requiring the user to do it manually. Since nobody has done
that yet, and since this configure option has been part of MPlayer ever
since ao_oss was added, it's probably safe to say it's not needed.

The '#ifdef SNDCTL_DSP_GETOSPACE' was pointless, since it's already used
unconditionally in another place.
2014-09-11 02:03:15 +02:00
wm4 f744aadb77 ao_pulse: dump library version etc.
Might help with debugging.

Unfortunately, there doesn't seem to be a way to get the actual
pulseaudio server version.
2014-09-10 23:14:06 +02:00
wm4 b578abe81b ao_pulse: fix typo in error message
Closes #1076.
2014-09-08 17:19:53 +02:00