Commit Graph

813 Commits

Author SHA1 Message Date
Kevin Mitchell 67c4117476 ao/wasapi: make set_ao_format EX/EXTENSIBLE agnostic
There is no guarantee that closestMatch returned by IsFormatSupported
is actually a WAVEFORMATEXTENSIBLE.

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

We should therefore not blindly treat it as such.
2014-12-01 03:40:24 -08:00
Kevin Mitchell 146561cc91 ao/wasapi: fix set_ao_format
Before it used whatever was in ao->format and changed the bits even
though this might have nothing to do with the actual WAVEFORMAT
negotiated with WASAPI.

For example, if the initial ao->format was a float and we had set the
WAVEFORMAT to s24, this would create a non-existent float24 format.
Worse, it might put an u16 into ao->format when WAVEFORMAT described s16.
WASAPI doesn't support unsigned at all as far as I can tell.
2014-12-01 03:40:24 -08:00
Kevin Mitchell 524cdfc3f1 ao/wasapi: show actual waveformat tried
also remove bogus ao_format
2014-12-01 03:40:23 -08:00
Kevin Mitchell bd33fa7052 ao/wasapi: don't assume 32-bits == float
This was based on old WAVEFORMATEX restrictions
http://msdn.microsoft.com/en-us/library/windows/hardware/ff538799%28v=vs.85%29.aspx

With the new WAVEFORMATEXTENSIBLE, this is no longer a problem. and we
can have s32 or float32 so we need to actually check / set these correctly.

fixes #1287
2014-12-01 03:40:23 -08:00
Kevin Mitchell 2006069ca2 ao/format: add af_fmt_is_float 2014-12-01 03:40:23 -08:00
Kevin Mitchell 96fa3ebd1a ao/wasapi: make sure that < 16-bit pcm never happens
it just sucks. noone should have to listen to that.
2014-12-01 03:40:23 -08:00
Kevin Mitchell 9a0b97d214 ao/wasapi: get rid of WAVEFMT union
It only confused the issue. Replace it's functionality with
waveformat_copy function where needed.
2014-12-01 03:40:23 -08:00
Kevin Mitchell 77f675a151 ao/wasapi: handle VistaBlob failure more gracefully 2014-11-28 10:52:48 -08:00
Kevin Mitchell b83e447e2b ao/wasapi: remove unnecessary check of audio thread input
it would have caused a deadlock if it fired anyway.
2014-11-28 10:52:48 -08:00
Kevin Mitchell b0854bc42c ao/wasapi: more consistent/reliable method of computing extra WAVEFORMATEXTENSIBLE size 2014-11-28 10:52:48 -08:00
Kevin Mitchell 8908b80b77 ao/wasapi: more missed cleanup on failure 2014-11-28 10:52:43 -08:00
Kevin Mitchell 7b5baf3b53 ao/wasapi: check return values
Only issue a warning for failure of wasapi_enumerate_devices and
wasapi_fill_VistaBlob.
2014-11-28 10:52:12 -08:00
Kevin Mitchell 14f9719a65 ao/wasapi: make functions return bool that were acting like it
this involved inverting the logic of find_formats, enumerate_devies
and wasapi_fill_VistaBlob. The latter two were trivial as their return
values were not actually checked (to be fixed in a later
commit).
2014-11-28 10:48:36 -08:00
Kevin Mitchell 4f208e6f68 ao/wasapi: check full GUID of KSDATAFORMAT to determine float 2014-11-28 10:48:36 -08:00
Kevin Mitchell 239c880fe2 ao/wasapi: expose GUID and PKEY convenience functions
Give them the prefix mp_ and make them nonstatic.
2014-11-28 10:48:36 -08:00
Kevin Mitchell e2bc1c5f17 ao/wasapi: remove unused variable 2014-11-28 10:48:36 -08:00
Kevin Mitchell fb5d88a287 ao/wasapi: safely define PKEY constants
Before these definitions were incorrectly guarded by and #ifdef
but since they aren't macros, this would never be true so that
if they were ever added to mingw headers we would have problems.

rename KSDATAFORMAT constants with the same mp prefix for consistency.
also use DEFINE_GUID rather than defining the bare structure
2014-11-28 10:48:36 -08:00
Kevin Mitchell 81464780e9 ao/wasapi: avoid redundant passing of ao and wasapi_state as arguments
also drop some useless const declaraitons
2014-11-28 10:48:36 -08:00
Kevin Mitchell 3b0b89c0af ao/wasapi: just return 0 unconditionally from the thread
We weren't actually checking this value anyway. We only really
cared about init failure, which was checked another way.
2014-11-28 10:48:36 -08:00
Kevin Mitchell d40c0d4f90 ao/wasapi: fix unmatched CoUninitialize() on init failure 2014-11-28 10:48:36 -08:00
Kevin Mitchell d0c37f0731 ao/wasapi: more debugging messages 2014-11-28 10:48:07 -08:00
Kevin Mitchell ecb491fd95 ao/wasapi: simplify the init retry 2014-11-28 08:02:16 -08:00
Kevin Mitchell e4aaaf69df ao/wasapi: make get_device_delay return an error code 2014-11-28 08:02:16 -08:00
wm4 4a83f3df11 ao_wasapi: don't treat SetDisplayName() failure as fatal
Same for SetIconPath().
2014-11-27 20:05:29 +01:00
wm4 a98f88a12f mixer: don't show softvol neutral marker on OSD if not using softvol
Also fix the comment on the softvol field.
2014-11-27 10:11:55 +01:00
wm4 cc54377463 Do not call strerror()
...because everything is terrible.

strerror() is not documented as having to be thread-safe by POSIX and
C11. (Which is pretty much bullshit, because both mandate threads and
some form of thread-local storage - so there's no excuse why
implementation couldn't implement this in a thread-safe way. Especially
with C11 this is ridiculous, because there is no way to use threads and
convert error numbers to strings at the same time!)

Since we heavily use threads now, we should avoid unsafe functions like
strerror().

strerror_r() is in POSIX, but GNU/glibc deliberately fucks it up and
gives the function different semantics than the POSIX one. It's a bit of
work to convince this piece of shit to expose the POSIX standard
function, and not the messed up GNU one.

strerror_l() is also in POSIX, but only since the 2008 standard, and
thus is not widespread.

The solution is using avlibc (libavutil, by its official name), which
handles the unportable details for us, mostly. We avoid some pain.
2014-11-26 21:21:56 +01:00
wm4 5b69b76609 ao_alsa: fix channel map in pre-channel map API case
Forgotten in commit 5d5f5b09.
2014-11-25 18:34:24 +01:00
wm4 e1ae936e6b ao_alsa: always enable "plug" plugin for non-default device
This seems safer: otherwise, opening the AO could randomly fail if the
audio formats happens to be not float.

Unfortunately, this only works if the user does not select a device.
Since ALSA devices are arbitrary strings, including plugins with complex
parameters, it's not trivial or maybe even impossible to edit the string
in a way the "plug" plugin is added.

With --audio-device, it would be safe for users to select either
"default" or one of the "plughw" devices. Everything else seems
questionable.
2014-11-25 18:15:45 +01:00
wm4 5d5f5b094b ao_alsa: select and set channel maps via channel map API
Use the ALSA channel map API for querying and selecting supported
channel maps.

Since we (probably?) want to be compatible with ALSA versions before the
change, we still try to select the device name by channel map, and open
that device. There's no way to negotiate a channel map before opening,
so we're stuck with this approach. Fortunately, it seems these devices
allow selecting and setting any other supported channel layout, so maybe
this is not an issue at all. In particular, this avoids selecting the
default (dmix) device, which can only do stereo.

Most code is based on Martin Herkt <lachs0r@srsfckn.biz>'s alsa_ng
branch, with heavy modifications.
2014-11-25 18:09:36 +01:00
wm4 5fb54fa756 ao_alsa: minor fixes
Don't crash if no fallback channel layout could be found (caller can't
handle NULL return from select_chmap()). Apparently this could never
actually happen, though.

Don't treat snd_pcm_hw_params_set_periods_near() failure as fatal error.
Same deal as with snd_pcm_hw_params_set_buffer_time_near().

Actually free channel maps returned by snd_pcm_get_chmap().

Adjust some messages.
2014-11-25 17:27:19 +01:00
wm4 7d6e58471f audio: make mp_audio_config_to_str return a stack-allocated string
Simpler overall.
2014-11-25 11:11:31 +01:00
wm4 8a7b686597 ao_alsa: cleanups
No functional changes.

ALSA_PCM_NEW_HW_PARAMS_API was a pre-ALSA 1.0.0 thing and does nothing
with modern ALSA. It stopped being necessary about 10 years ago.

3 functions are moved to avoid forward references.
2014-11-25 11:10:44 +01:00
wm4 28b6ce39d3 audio: make mp_chmap_to_str() return a stack-allocated string
Simplifies memory management.
2014-11-24 19:56:01 +01:00
wm4 2228d47373 ao_alsa: try to use the channel map reported by ALSA
If ALSA reports a channel map, and it looks like it makes sense (i.e.
could be converted to mpv channel map, and the channel count matches),
then use that instead of the channel map we are assuming.

This is based on code written by lachs0r (alsa_ng branch).
2014-11-24 19:44:26 +01:00
wm4 df43e2d22a ao_pcm: simplify
Also shuts up Coverity.
2014-11-21 10:09:38 +01:00
wm4 9d2aef048d ao_oss: check whether setting samplerate succeeds
Independent from whether the samplerate was accepted or adjusted, errors
returned by the ioctl are fatal errors.

Found by Coverity.
2014-11-21 10:09:26 +01:00
wm4 c6c46f5aa7 ao_lavc: fix setting up AVFrame pointers
The caller set up the "start" pointer array using the number of planes,
the encode() function used the number of channels. This copied
uninitialized values for packed formats, which makes Coverity warn.
2014-11-21 10:09:25 +01:00
wm4 c01a62efbc af_scaletempo: use float division for rate
From what I understand the division is to align the dimension of the
value from seconds to milliseconds. Hard to tell whether the "rounding"
was intentional or not; I'm tipping on "not".

Found by Coverity.
2014-11-21 10:09:15 +01:00
wm4 e082c2c3df Remove some unneeded NULL checks
Found by Coverity; also see commit 85fb2af3.
2014-11-21 09:58:09 +01:00
wm4 524aa99401 audio/out/push: fix off-by-one error
Needs 1 additional free entry.

Found by Coverity.
2014-11-21 03:50:57 +01:00
wm4 459f3aa4f9 ao_lavc: fix dangling pointers
Found by Coverity.
2014-11-21 03:50:52 +01:00
Kevin Mitchell f2dda72dbc ao/wasapi: only retry resizing the buffer once
like the MSDN example:

http://msdn.microsoft.com/en-us/library/windows/desktop/dd370875%28v=vs.85%29.aspx
2014-11-18 07:50:51 -08:00
Kevin Mitchell da03334a73 ao/wasapi: keep bufferPeriod in sync on retry
Without this, the retry will fail if they are not equal or
bufferPeriod is zero.
2014-11-18 06:59:26 -08:00
Kevin Mitchell 94ea4435a9 ao/wasapi: refix printf warning for both cygwin and msys
a cast to (unsigned) should do "the right thing".
2014-11-18 05:03:33 -08:00
Kevin Mitchell 19e9c9d1be ao/wasapi: periodicity in shared mode must be zero
IAudioClient::Initialize hnsPeriodicity argument is nonzero only for exclusive mode

http://msdn.microsoft.com/en-us/library/windows/desktop/dd370805%28v=vs.85%29.aspx
2014-11-18 05:03:33 -08:00
Kevin Mitchell c545c406fa ao/wasapi: increase buffer size to 50 ms
Before it was the default device period, which was too small
causing glitches on on entering/exiting fullscreen.
2014-11-18 05:03:33 -08:00
wm4 d96bd0eaa8 audio/out: always log retrieved audio device size 2014-11-18 12:51:43 +01:00
Jonathan Yong 7697d300d2 ao/wasapi: fix leaked marshaled interface streams
Signed-off-by: Kevin Mitchell <kevmitch@gmail.com>
2014-11-18 02:12:28 -08:00
Kevin Mitchell 22bf0a78df ao/wasapi: Don't free stuff the thread may still be using on timeout
In the unlikely event of a timeout waiting for the audio thread to return,
don't free stuff that it may still be using.
2014-11-17 23:46:38 -08:00
Kevin Mitchell 20d42b3475 ao/wasapi: also free the threadLoop handle on uninit
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682453%28v=vs.85%29.aspx
2014-11-17 23:43:51 -08:00