Commit Graph

66 Commits

Author SHA1 Message Date
Kevin Mitchell 642f84f922 ao/wasapi: use atomic state variable instead of different events
Unfortunately, because we have proxy objects (pAudioVolumeProxy,
pEndpointVolumeProxy, pSessionControlProxy) it looks like we still
have to use MsgWaitForMultipleObjects and watch for and dispatch
pending messages:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms680112%28v=vs.85%29.aspx
2015-04-04 16:31:14 -07:00
Kevin Mitchell bf3e0bc1da ao_wasapi: code formatting and alignment 2015-04-03 15:40:01 -07:00
Kevin Mitchell 46b9df9f9e audio: make all format query shortcuts macros
af_fmt_is_float and af_fmt_is_planar were previously inconsistent with
AF_FORAMT_IS_SPECIAL/AF_FORMAT_IS_IEC61937
2015-04-03 15:40:01 -07:00
Kevin Mitchell 07671ac57b ao_wasapi: passthrough rework
* unify passthrough and pcm exclusive mode format setting/testing
* set passthrough format parameters correctly
* support all of mpv's existing passthrough formats
* automatically test passthrough with exclusive mode and enable
  exclusive if it succeeds, even if it was not explictly requested.
  this obviates the need for --ao=wasapi,wasapi=exclusive
* if passthrough fails (such as the device doesn't support the
  format), fallback to either exclusive pcm or shared mode depending
  on what the user specified. Right now this isn't very useful as
  it still fails due to the decoder path remainin stuck on spdif.

fixes #1742
2015-04-03 15:39:51 -07:00
Kevin Mitchell 4987c1906d ao_wasapi: abstract HRESULT_to_str 2015-04-01 02:30:19 -07:00
Kevin Mitchell e408dd20c7 ao_wasapi: remove redundant casts 2015-03-31 14:13:58 -07:00
Kevin Mitchell b6c28dd26b ao_wasapi: simplify hotplug
Take advantage of the fact that list_devs is called with a
hotplug_inited ao. Also eliminate unnecessary nested function
abstraction of hotplug_(un)init and list_devs. However, keep list_devs
in ao_wasapi_utils.c since it uses the private functions get_device_id,
get_device_name and exposing these would require including headers for
IMMDevice in ao_wasapi_utils.h.
2015-03-31 13:43:32 -07:00
Kevin Mitchell ea00fe0eeb ao_wasapi: fix device listing
remove depricated and convoluted validation. refer instead to the
--audio-device option.
2015-03-31 12:28:41 -07:00
Kevin Mitchell a6bf38bcad ao/wasapi: add ao hotplug
Create a second copy of the change_notify structure for the hotplug
ao. change_notify->is_hotplug distinguishes the hotplug version from
the regular one monitoring the currently playing ao. Also make the
change notification less verbose now that there might be two of them around.
2015-03-31 02:02:54 -07:00
Kevin Mitchell 36d1b28849 ao/wasapi: use built in KSDATAFORMATs
Rather than defining them ourselves. Thanks to rossy for figuring out
the headers.
2015-03-27 16:14:31 -07:00
Kevin Mitchell 81da34549f ao/wasapi: add missing "if" braces 2015-03-26 05:52:34 -07:00
Kevin Mitchell 41c10c3ec2 ao/wasapi: rewrite format search
More clearly separate the exclusive and shared mode format discovery.
Make the exclusive mode search more systematic in particular about
channel maps (i.e., use chmap_sel). Assume that the same sample format
/ sample rates work for all channels to narrow the search space.
2015-03-26 05:33:57 -07:00
Kevin Mitchell c52833bf16 ao/wasapi: move resume to audio thread
This echanges the two events hForceFeed/hFeedDone for hResume. This
like the last commit makes things more deterministic.

Importantly, the forcefeed is only done if there is not already a full
buffer yet to be played by the device. This should fix some of the
problems with exclusive mode.

This commit also removes the necessity to have a proxy to the
AudioClient object in the main thread.

fixes #1529
2015-02-23 14:02:08 -08:00
James Ross-Gowan 3c10ed540b ao_wasapi: fix try_format logic in shared mode
The MSDN documentation for IsFormatSupported says a return code of
AUDCLNT_E_UNSUPPORTED_FORMAT means the function "succeeded but the
specified format is not supported in exclusive mode." This seems to
imply that the format is supported in shared mode, and that's what the
old code assumed, however try_format would incorrectly return success
with some drivers.

The remarks section of the documentation contradicts that assumption. It
says that in shared mode, if the audio engine does not support the
caller-specified format or any similar format, ppClosestMatch is set to
NULL and the function returns AUDCLNT_E_UNSUPPORTED_FORMAT. This is the
same as in exclusive mode, so treat AUDCLNT_E_UNSUPPORTED_FORMAT the
same regardless of opt_exclusive. In shared mode, the format selection
code will fall back to the mix format, which should always be supported.
2015-01-23 22:02:15 +11:00
wm4 f61b8b312d win32: request UTF-16 API variants, Vista+ APIs, and COM C macros
Put the Vista+ (_WIN32_WINNT) and the COM C (COBJMACROS) defines into
the build system, instead of defining them over and over in the code.
2015-01-07 21:42:44 +01:00
Kevin Mitchell 6a6620a554 ao/wasapi: style/code formatting tweaks 2015-01-02 14:50:59 -08:00
Kevin Mitchell 155c8e20ef ao/wasapi: improve exclusive mode format search
fixes #1376
2015-01-02 14:08:47 -08:00
Kevin Mitchell 81948634ca ao/wasapi: revamp set_waveformatex
* bits instead of bytes
* add valid_bits argument
* just pass in the mp_chmap and get the number and wavext channel map from that
* indicate valid bits in waveformat_to_str
* make appropriate accomodations in try_format
2015-01-02 14:08:47 -08:00
Kevin Mitchell 121352cd95 ao/wasapi: add CO_E_NOTINITIALIZED to explain_err
someone on irc reported seeing this error
2015-01-02 14:08:47 -08:00
Kevin Mitchell 1e5f9d2673 ao/wasapi: use IsEqualGUID and IsEqualPropertyKey
before we were reinventing this wheel
2014-12-16 03:29:51 -08:00
Kevin Mitchell 4966a67f71 ao/wasapi: set the ao with the waveformat channelmap
hopefully this fixes #1350
2014-12-15 05:01:38 -08:00
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 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 b0854bc42c ao/wasapi: more consistent/reliable method of computing extra WAVEFORMATEXTENSIBLE size 2014-11-28 10:52:48 -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 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
wm4 4a83f3df11 ao_wasapi: don't treat SetDisplayName() failure as fatal
Same for SetIconPath().
2014-11-27 20:05:29 +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 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
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
James Ross-Gowan d9bac96a9d ao/wasapi: silence format string warnings 2014-11-18 12:19:36 +11: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 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