0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 20:03:10 +02:00
Commit Graph

760 Commits

Author SHA1 Message Date
wm4
fb86750a67 ao_alsa: check for EAGAIN too
Simply retry on EAGAIN.

I've seen this in several other projects; it might be just cargo-culting
though.
2014-11-17 20:07:59 +01:00
wm4
8b2798cb3e audio/out: switch back to wasapi as default on win32
dsound was set as default, because there were some hard to fix problems
with wasapi. These problems were probably fixed now, so let's try with
wasapi as default again.
2014-11-17 14:07:11 +01:00
Kevin Mitchell
4c8b841fc4 ao/wasapi: request ao reload on thread_feed failures
Even with change notifications, there are still (rare) cases when the
feed thread gets AUDCLIENT_DEVICE_INVALIDATED. So handle failures in
thread_feed by requesting ao_reload.
2014-11-17 04:31:22 -08:00
Kevin Mitchell
9371990bd1 ao/wasapi: add retry loop on AUDCLNT_E_DEVICE_IN_USE
this works around reinitializing too fast on device property changes
2014-11-17 04:31:22 -08:00
Kevin Mitchell
6c512892d4 ao/wasapi: request reset on appropriate events
on changes to PKEY_AudioEngine_DeviceFormat, device status, and default device.
call ao_reload directly in the change_notify "methods".

this requires keeping a device enumerator around for the duration of
execution, rather than just for initially querying devices
2014-11-17 04:31:20 -08:00
Kevin Mitchell
e647f202ed ao/wasapi: add convenience functions for change notifiy 2014-11-17 04:30:53 -08:00
Jonathan Yong
f29f16663a ao/wasapi: new wasapi device monitoring interface
Implement skeleton IMMNotificationClient to watch for changes in the
sound device.  This will make recovery possible from changes shared
mode sample rate, bit depth, "enhancements"/effects and even graceful
device removal.

http://msdn.microsoft.com/en-us/library/windows/desktop/dd371417%28v=vs.85%29.aspx

Signed-off-by: Kevin Mitchell <kevmitch@gmail.com>
2014-11-17 04:30:53 -08:00
Kevin Mitchell
497df443c0 ao/wasapi: look for "multimedia" default device instead of "console"
console is more for system notifications / voice command, mpv is most certainly multimedia

http://msdn.microsoft.com/en-us/library/windows/desktop/dd370842%28v=vs.85%29.aspx
2014-11-17 04:30:53 -08:00
Kevin Mitchell
e8dbdf1eb9 ao/wasapi: put loading of default device in it's own function 2014-11-17 04:30:47 -08:00
Kevin Mitchell
f7c26230eb ao/wasapi: fix possible null dereference of pDevice
IMMDeviceEnumerator::GetDefaultAudioEndpoint may set pDevice to null on failure.

http://msdn.microsoft.com/en-us/library/windows/desktop/dd371401%28v=vs.85%29.aspx
2014-11-17 04:13:52 -08:00
Kevin Mitchell
3da6f723c6 ao/wasapi: tidy up better on failure
Before, failures, particularly in the thread loop init, could lead to a
bad state for the duration of mpvs execution. Make sure that
everything that was initialized gets properly and safely
uninitialized.
2014-11-17 04:13:52 -08:00
Kevin Mitchell
e28102f1a8 ao/wasapi: improve error messages and add more debug statements
also enforce more consistency in the exit codes and error handling

thanks to Jonathan Yong <10walls@gmail.com>
2014-11-17 04:13:49 -08:00
Kevin Mitchell
d4393be0f9 ao/wasapi: make calling of thread_init consistent with thread_uninit 2014-11-17 03:37:07 -08:00
Kevin Mitchell
6eb5c6d186 ao/wasapi: reenable the reset function
the race condition that necessitated disabling
this was fixed in
e440352313
2014-11-17 03:37:07 -08:00
Jonathan Yong
227f0e3f39 ao/wasapi: fix leaked deviceID 2014-11-17 03:36:54 -08:00
wm4
be9eb08389 af: remove redundant function 2014-11-12 20:19:21 +01:00
wm4
a669a1d0dd af: check audio params for validity
Normally, these should be valid anyway, so this is just being cautious.
2014-11-12 20:03:04 +01:00
Rudolf Polzer
4f63a812de ao_lavc, vo_lavc: Fix crashes in case of multiple init attempts.
When initialization failed, vo_lavc may cause an irrecoverable state in
the ffmpeg-related structs. Therefore, we reject additional
initialization attempts at least until we know a better way to clean up
the mess.

ao_lavc currently cannot be initialized more than once, yet it's good to
do consistent changes there as well.

Also, clean up uninit-after-failure handling to be less spammy.
2014-11-12 12:16:07 +01:00
wm4
d4cc41bbcd audio: make sure AVFrame is actually refcounted
The mp_audio_from_avframe() function requires the AVFrame to be
refcounted, and merely increases its refcount while referencing the same
data. For non-refcounted frames, it simply did nothing and potentially
would make the caller pass around a frame with dangling pointers.

(libavcodec should always return refcounted frames, but it's not clear
what other code does; and also the function should simply work, instead
of having weird requirements on its arguments.)
2014-11-11 21:20:21 +01:00
wm4
475226c783 audio: refuse to allocate frames in invalid format 2014-11-11 21:10:53 +01:00
wm4
5fd8a1e04c audio: make decoders output refcounted frames
This rewrites the audio decode loop to some degree. Audio filters don't
do refcounted frames yet, so af.c contains a hacky "emulation".

Remove some of the weird heuristic-heavy code in dec_audio.c. Instead of
estimating how much audio we need to filter, we always filter full
frames. Maybe this should be adjusted later: in case filtering increases
the volume of the audio data, we should try not to buffer too much
filter output by reducing the input that is fed at once.

For ad_spdif.c and ad_mpg123.c, we don't avoid extra copying yet - it
doesn't seem worth the trouble.
2014-11-10 22:02:05 +01:00
wm4
46d6fb9dc1 audio: add mp_audio_make_writeable() 2014-11-10 22:02:05 +01:00
wm4
c1b034f2aa audio: clear buffer array too with mp_audio_set_null_data() 2014-11-10 22:02:05 +01:00
wm4
e094e9cb75 audio: change how filters are inserted on playback speed changes
Use a pseudo-filter when changing speed with resampling, instead of
somehow changing a samplerate somewhere. This uses the same underlying
mechanism, but is a bit more structured and cleaner. It also makes some
of the following changes easier.

Since we now always use filters to change audio speed, move most of the
work set_playback_speed() does to recreate_audio_filters().
2014-11-10 22:02:05 +01:00
wm4
995a6af787 af_format: remove redundant message prefixes 2014-11-10 22:02:04 +01:00
wm4
0b26d8c666 audio: add function to convert AVFrame to mp_audio references
This is somewhat duplicated from ad_lavc.c and af_lavfi.c, but will
eventually be used by both.
2014-11-10 22:02:04 +01:00
wm4
5d46e44160 audio: add mp_audio_pool
A helper to allocate refcounted audio frames from a pool. This will
replace the static buffer many audio filters use (af->data), because
such static buffers are incompatible with refcounting.
2014-11-10 18:15:22 +01:00
wm4
9388f69f67 audio: use AVBufferRef to allocate audio frames
A first step towards refcounted audio frames.

Amazingly, the API just does what we want, and the code becomes
simpler. We will need to NIH allocation from a pool, though.
2014-11-10 10:43:15 +01:00
wm4
e440352313 audio/out/pull: avoid deadlock if audio callback stops
If the audio callback suddenly stops, and the AO provides no "reset"
callback, then reset() could deadlock by waiting on the audio callback
forever.

The waiting was needed to enter a consistent state, where the audio
callback guarantees it won't access the ringbuffer. This in turn is
needed because mp_ring_reset() is not concurrency-safe.

This active waiting is unavoidable. But the way it was implemented, the
audio callback had to call ao_read_data() at least once when reset() is
called. Fix this by making ao_read_data() set a flag upon entering and
leaving, which basically turns p->state into some sort of spinlock.

The audio callback actually never needs to spin, because there are only
2 states: playing audio, or playing silence. This might be a bit
surprising, because usually atomic_compare_exchange_strong() requires a
retry-loop idiom for correct operation.

This commit is needed because ao_wasapi can (or will in the future)
randomly stop the audio callback in certain corner cases. Then the
player would hang forever in reset().
2014-11-09 15:23:40 +01:00
wm4
5db0fbd95e audio/out: consistently use double return type for get_delay
ao_get_delay() returns double, but the get_delay callback still
returned float.
2014-11-09 11:45:04 +01:00
wm4
b021d038c2 audio/out: make ao_request_reload() idempotent
This is what you would expect. Before this commit, each
ao_request_reload() call would just queue a reload command, and then
recreate the AO for the number of times the function was called.

Instead of sending a command, introduce some sort of event retrieval
mechanism. At least for the reload case, use atomics, because we're too
lazy to setup an extra mutex.
2014-11-09 09:58:44 +01:00
wm4
b814b7ca84 audio: add --audio-client-name option
The main need I see for this is with libmpv - it would be confusing if
some application showed up as "mpv" on whateverthehell PulseAudio uses
it for (generally it does show up on various PA GUI tools).
2014-11-07 15:54:35 +01:00
wm4
a54b99d1e5 ao_oss: wait for events with poll()
The intention is to avoid using the timeout-based fallback.

There's some minor hope that this will help with OpenBSD (see #1239),
although it probably won't.

Some chance that this will cause trouble with obscure OSS
implementations or emulations.
2014-11-06 01:17:36 +01:00
wm4
3d2e278029 audio/out/push: when using audio wait fallback, recheck condition
If calling ao->driver->wait() fails, we need to fallback to timeout-
based waiting. But it could be that at this point, the mutex was already
released (and then re-acquired). So we need to recheck the condition in
order to avoid missed wakeups.

This probably wasn't an actually occurring problem, but still could
cause a small race-condition window if the dynamic fallback is actually
used.
2014-11-06 01:15:44 +01:00
wm4
93e1db0bff ad_lavc: allow skip samples amount to be larger than 1 packet
Apparently we actually need this. At least the following commit would
break without this.
2014-11-03 19:56:38 +01:00
wm4
8607b0c44b ao_alsa: don't make snd_pcm_hw_params_set_buffer_time_near() error fatal
Apparently this can "sometimes" return an error. In my opinion, this
should never return an error: neither the semantics of the function,
nor the ALSA documentation or ALSA sample code seem to indicate that
a failure is to be expected. I'm not perfectly sure about this though
(I blame ALSA being a weird, big, underdocumented API).

Since it causes problems for some users, and since there is really no
reason why we should abort on such an error, turn it into a warning.

Fixes #1231.
2014-10-31 01:09:53 +01:00
wm4
733936f376 options: accept --audio-channels=auto
This sounds much more intuitive, while "empty" was a bit of a WTF.
2014-10-30 22:58:17 +01:00
Stefano Pigozzi
0c0ff638a3 coreaudio: only list output devices 2014-10-28 14:11:50 +01:00
wm4
d5b081152a audio: add command/function to reload audio output
Anticipated use: simple solution for dealing with audio APIs which
request configuration changes via events.
2014-10-27 11:52:42 +01:00
wm4
809fbc6fc1 ao_alsa: move parameter append code to a function
Why not. (I thought I needed this, but my other experiments failed. So
this is merely a minor cleanup.)
2014-10-23 18:06:17 +02:00
Stefano Pigozzi
474461244e rename ao_coreaudio_device.c -> ao_coreaudio_exclusive.c
This is so that the source file name matches the AO name
2014-10-23 09:55:17 +02:00
Stefano Pigozzi
f8d0a75b50 coreaudio: redirect IEC61937 to coreaudio_exclusive 2014-10-23 09:16:39 +02:00
wm4
32720cdc17 audio/out: add redirection-on-init mechanism
Looks like this will help us with making --audio-device and spdif work
as expected on OSX. To be used ina  following commit.
2014-10-22 17:12:08 +02:00
wm4
42158b819a audio/out: missing error check
Oops.
2014-10-22 16:57:28 +02:00
wm4
67d63bc948 audio/out: don't add special devices to --audio-device list
Since the list associated with --audio-device is supposed to enable
simple user-selection, it doesn't make much sense to include overly
special things like ao_pcm or ao_null in the list. Specifically,
ao_pcm is harmful, because it will just dump all audio to a file
named audiodump.wav in the current working directory. The user can't
choose the filename (it can be customized, but not through this
option), and the working directory might be essentially random,
especially if this is used from a GUI.

Exclude "strange" entries. We reuse the fact that there's already a
simple list ordered by auto-probe priority in order to avoid having to
add an additional flag. This is also why coreaudio_exclusive was moved
above ao_null: ao_null ends auto-probing and marks the start of
"special" outputs, which don't show up on the device, but we want
coreaudio_exclusive to be selectable (I think).
2014-10-22 16:16:35 +02:00
wm4
2a74704d76 audio/out: include coreaudio_exclusive in auto-probing
Move it above ao_null, so that it can be selected during auto-probing
(even if it's only last). I see no reason why it should not be included,
and it makes the following commit slightly more elegant. (See
explanations there.)
2014-10-22 16:15:49 +02:00
wm4
9ba6641879 Set thread name for debugging
Especially with other components (libavcodec, OSX stuff), the thread
list can get quite populated. Setting the thread name helps when
debugging.

Since this is not portable, we check the OS variants in waf configure.
old-configure just gets a special-case for glibc, since doing a full
check here would probably be a waste of effort.
2014-10-19 23:48:40 +02:00
wm4
c854ce934e audio: quote devices in --audio-device=help
The output is a bit confusing. Quoting the device name probably helps a
little bit; also add minimal explanations to the manpage.
2014-10-19 16:36:38 +02:00
wm4
312531c08c audio/out/push: reset projected EOF time on new data
Seems like this could theoretically happen in low buffer situations, but
I haven't spotted this behavior in the wild.
2014-10-14 22:07:04 +02:00
wm4
e9b0a61444 ao_wasapi: implement device listing 2014-10-13 18:21:45 +02:00