Commit Graph

115 Commits

Author SHA1 Message Date
Pedro Pombeiro f22d12ac51 ao_wasapi: do not use deprecated wchar functions
These break on UWP. Based on a patch by Pedro Pombeiro.
2017-06-29 10:35:25 +02:00
wm4 3a3a0aced2 ao_wasapi: remove subtly duplicated code
Seems like this can be slightly simplified.
2017-06-28 18:43:19 +02:00
wm4 3b7e292844 ao_wasapi: remove duplicate code for creating IAudioClient
The code accounting for the terrible AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED
semantics (which MSDN claims can happen "starting with Windows 7" - so
probably on Windows 10 too) duplicated the call for creating the
IAudioClient. That's not great, so get rid of it.

Let wasapi_thread_init() handle this. It has a retry loop anyway. This
redoes device lookup and format negotiation, but potential failures due
to race conditions (what if the driver decides to change behavior)
shouldn't be worse than before.
2017-06-28 18:43:18 +02:00
wm4 c68be80a63 ao_wasapi: do not pass nonsense to drivers with double
This tried to use AF_FORMAT_DOUBLE as KSDATAFORMAT_SUBTYPE_IEEE_FLOAT,
with wBitsPerSample==64. This is probably not allowed, and drivers
appear to react inconsistently to it. (With one user, the format was
accepted during format negotiation, but then rejected on actual init.)

Remove it, which essentially forces it to fall back to some other
format. (Looks like it'll use af_select_best_samplerate(), which would
probably make it try S32 next.)

The af_fmt_from_planar() is so that we don't have to care about
AF_FORMAT_FLOATP. Wasapi always requires packed data anyway.

This should actually handle other potentially unknown sample formats
better.

This changes that set_waveformat() always set the exact format. Now it
might set a "close" format instead. But all callers seem to deal with
this well. Although in theory, callers should probably handle the
fallback. The next cleanup (if ever) can take care of this.
2017-03-29 15:19:25 +02:00
James Ross-Gowan 9692814502 win32: add COM-specific SAFE_RELEASE to windows_utils.h
See: https://msdn.microsoft.com/en-us/library/windows/desktop/dd743946.aspx

Microsoft example code often uses a SAFE_RELEASE macro like the one in
the above link. This makes it easier to avoid errors when releasing COM
interfaces. It also reduces noise in COM-heavy code.

ao_wasapi.h also had a macro called SAFE_RELEASE, though unlike the
version above, its SAFE_RELEASE macro accepted a second parameter which
allowed it to destroy arbitrary objects other than just COM interfaces.
This renames ao_wasapi's SAFE_RELEASE to SAFE_DESTROY, which should more
accurately reflect what it does and prevent confusion with the Microsoft
version.
2017-01-30 00:22:30 +11:00
wm4 ec74a79e12 ao_wasapi: log return code when probing audio formats
We log a large number of formats, but we rarely log the result of the
probing. Change this.

The logic in try_format_exclusive() changes slightly, but should be
equivalent. EXIT_ON_ERROR() checks for FAILED(), which should be
exclusive to SUCCEEDED().
2016-11-30 17:56:33 +01:00
pavelxdd 3203d6003c ao_wasapi_utils: remove unused variable
Introduced in 1a2319f3e4
Produced a warning during compilation on Windows.
2016-11-27 20:32:33 +01:00
wm4 1a2319f3e4 options: remove deprecated sub-option handling for --vo and --ao
Long planned. Leads to some sanity.

There still are some rather gross things. Especially g_groups is ugly,
and a hack that can hopefully be removed. (There is a plan for it, but
whether it's implemented depends on how much energy is left.)
2016-11-25 21:17:25 +01:00
James Ross-Gowan 3751065f97 win32: build with -DINITGUID
We always want to use __declspec(selectany) to declare GUIDs, but
manually including <initguid.h> in every file that used GUIDs was
error-prone. Since all <initguid.h> does is define INITGUID and include
<guiddef.h>, we can remove all references to <initguid.h> and just
compile with -DINITGUID to get the same effect.

Also, this partially reverts 622bcb0 by re-adding libuuid.a to the
build, since apparently some GUIDs (such as GUID_NULL) are not declared
in the source file, even when INITGUID is set.
2016-09-28 21:38:52 +10:00
wm4 b2e5eb13bc ao_wasapi: in exclusive mode do not output multichannel by default
Exactly the same situation as with ao_alsa in commit 0b144eac (except
that we can detect the situation better under wasapi).

Essentially, wasapi will allow us to output any sample format, and not
just the one configured by the user in the audio system settings.
2016-08-05 16:11:42 +02:00
Kevin Mitchell 96053d53a7 ao_wasapi: use new af_select_best_samplerate function
It duplicates the logic that was previously used here.
2016-03-17 02:31:05 -07:00
Kevin Mitchell 534571f794 ao_wasapi: use MP_FATAL for stuff that leads to init failure 2016-02-26 15:43:51 -08:00
Kevin Mitchell 82f102cfe3 ao_wasapi: set buffer size to device period in exclusive mode
This eliminates some intermittent pops heard in a HRT MicroStreamer DAC
uncorrelated with user interaction. As a bonus, this resolves #1773 which I can
o longer reproduce as of this commit. Leave the 50ms buffer for shared mode
since that seems to be working quite well.

This is also the way exclusive mode is done in the MSDN example code:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd370844%28v=vs.85%29.aspx

This was originally increased in c545c40 to mitigate glitches that subsequent
refactorings have eliminated.
2016-02-26 15:43:51 -08:00
Kevin Mitchell 84a3c21beb ao_wasapi: replace laggy COM messaging with mp_dispatch_queue
A COM message loop is apparently totally inappropriate for a low latency
thread. It leads to audio glitches because the thread doesn't wake up fast
enough when it should. It also causes mysterious correlations between the vo
and ao thread (i.e., toggling fullscreen delays audio feed events). Instead use
an mp_dispatch_queue to set/get volume/mute/session display name from the audio
thread. This has the added benefit of obviating the need to marshal the
associated interfaces from the audio thread.
2016-02-26 15:43:51 -08:00
Kevin Mitchell a842ad8f50 ao_wasapi: use SUCCEEDED/FAILED macros 2016-02-26 15:43:51 -08:00
Jan Ekström ff0112e08d Initial Android support
* Adds an 'android' feature, which is automatically detected.
* Android has a broken strnlen, so a wrapper is added from FreeBSD.
2016-02-10 21:29:36 +01:00
Kevin Mitchell 4d5d25fdbb ao_wasapi: add "wasapi" prefix to non-static find_deviceID function 2016-01-28 00:56:03 -08:00
Kevin Mitchell e927ff1666 ao_wasapi: correct check for specified device on default change
Correctly avoid a reload if the current device was specified by the user through
--audio-device. Previously, we only recognized if the user had specified
--ao=wasapi:device=.
2016-01-28 00:55:58 -08:00
Kevin Mitchell f1072be3b7 ao_wasapi: fix check for already found device
oops, forgot to change this when I made get_deviceID a more proper function.
state->deviceID is not set or read here - that's for the caller to do.
2016-01-28 00:24:58 -08:00
Kevin Mitchell ce0b26c60f ao_wasapi: use correct UINT type for device enumeration
Notably, the address of the enumerator->count member is passed to
IMMDeviceCollection::GetCount(), which expects a UINT variable, not an int. How
did this ever work?
2016-01-22 03:21:21 -08:00
Kevin Mitchell ff7884e635 ao_wasapi: exit earlier if there are zero playback devices found
Previously, if the enumerator found no devices, attempting to get the default
device with IMMDeviceEnumerator::GetDefaultAudioEndpoint would result in the
cryptic (and undocumented) E_PROP_ID_UNSUPPORTED. This way, the user is given a
better indication of what exactly is wrong and isolates any other possible
triggers for this error.
2016-01-22 03:21:21 -08:00
wm4 8a9b64329c Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.

There are probably more files to which this applies, but I'm being
conservative here.

A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).

common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.

codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.

From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).

misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.

screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 18:36:06 +01:00
wm4 31a4547187 ao_wasapi: move out some utility functions
Note that hresult_to_str() (coming from wasapi_explain_err()) is mostly
wasapi-specific, but since HRESULT error codes are unique, it can be
extended for any other use.
2016-01-11 16:24:13 +01:00
Kevin Mitchell 27ccad541a ao_wasapi: remove unnecessary header file
All the wasapi files were including both ao_wasapi.h and ao_wasapi_utils.h.
Just merge them into a single file.
2016-01-05 17:47:55 -08:00
Kevin Mitchell bf611ff0f6 ao_wasapi: initialize change notify in main thread
This is something else that has nothing to do with audio rendering.
2016-01-05 17:47:55 -08:00
Kevin Mitchell 8368ead1fa ao_wasapi: make find_deviceID read only wrt struct ao
This makes it clearer that state->device is being allocated.
2016-01-05 17:47:55 -08:00
Kevin Mitchell d22d24a6d5 ao_wasapi: move device selection to main thread
In attempt to simplify the audio event thread, this can now be moved out.
2016-01-05 17:47:55 -08:00
Kevin Mitchell fb84c6974d ao_wasapi: avoid some redundant error messages in device selection
If these error conditions are triggered, the called function will have already
output a sufficiently informantive error message.
2016-01-05 17:47:55 -08:00
Kevin Mitchell 92ded6c6fd ao_wasapi: alloc later to avoid free on error
In get_device_desc, don't alloc the return value until we know there
wasn't an error.
2016-01-05 17:47:55 -08:00
wm4 09f0f68959 ao_wasapi: remove +x flag from files 2016-01-04 19:18:02 +01:00
Kevin Mitchell efb9943637 ao_wasapi: make persistent enumerator local to change_notify
This is no longer required by anything else
2016-01-04 07:41:21 -08:00
Kevin Mitchell 243a2976a8 ao_wasapi: rewrite device listing and selection
Unify and clean up listing and selection. Use common enumerator code for both
operations to avoid duplication or inconsistencies.

Maintain, but significatnly simplify manual device selection by id, name or
number. This actually fixes loading by name which didn't really work before
since the "name" displayed by --audio-device=help differed from that used to
match the selection, which used the device "description" instead.

Save the selected deviceID in the private structure for later loading. This will
permit moving the device selection into the main thread in a future commit.
2016-01-04 07:41:21 -08:00
Kevin Mitchell 0afb1acab3 ao_wasapi: move volume control init to it's own function
also make failure non-fatal
2015-12-21 05:23:26 -08:00
Kevin Mitchell 05b6646d7a ao_wasapi: correctly handle audio session display failure
In particular, try and release/null the interface so that it won't be
marshalled.
2015-12-21 05:23:26 -08:00
Kevin Mitchell 35296c1f33 ao_wasapi: non-fatal error handling for COM marshalling
Also make sure that CoReleaseMarshalData is called if errors occur before
unmarshalling.
2015-12-21 05:23:22 -08:00
Kevin Mitchell 3ae726e8dd ao_wasapi: wrap long lines and use only c99 comment style
also remove a log message in AOCONTROL_UPDATE_STREAM_TITLE since
none of the other controls have one.
2015-12-21 05:03:09 -08:00
Kevin Mitchell 099fdde7a4 ao_wasapi: remove useless buffer_block_size
this was only ever used for a verbose message
2015-12-21 05:03:09 -08:00
Kevin Mitchell a191712169 ao_wasapi: call the class-specific release functions
IUnknown_Release() might be alright, but stay on the safe
side.
2015-12-20 03:30:28 -08:00
Kevin Mitchell 821e8fb9d0 ao_wasapi: actually use hw volume support information for exclusive mode
Do not try and set/get master volume in exclusive if there is no
hardware support. This would just uselessly change the master slider,
but have no effect on the actual volume.

Furthermore if getting hardware volume support information fails, then assume
it has none.
2015-12-20 03:30:28 -08:00
Kevin Mitchell d1cbff37be ao_wasapi: remove volume "restore" on exit
It was complicated and not even very intuitive to the user.
If you are controlling the master volume, you just have to be
prepared to deal with the consequences.
2015-12-20 03:30:28 -08:00
Kevin Mitchell e15526153e ao_wasapi: add E_NOINTERFACE to error list
this is encountered trying to set up COM proxies in wine
2015-12-20 03:30:28 -08:00
Kevin Mitchell 00b7fb3023 ao_wasapi: get rid of Vistablob hack
This was required to work around XP linking issues and is no longer
required.
2015-11-24 04:42:37 -08:00
wm4 7e285a6f71 ao_wasapi: work around DTS passthrough failure
Apparently, some audio drivers do not support the DTS subtype, but
passthrough works anyway if the AC3 subtype is set. Just retry with
AC3 if the proper format doesn't work. The audio device which
exposed this behavior reported itself as
"M601d-A3/A3R (Intel(R) Display Audio)".

xbmc/kodi even always passes DTS as AC3.
2015-11-19 00:08:07 +01:00
wm4 ec27d573f4 audio: always log channel maps before determining final map
Until now, this was done only in debug verbosity, while some AOs logged
equivalent information in verbose mode. Clean this up.
2015-10-26 15:52:08 +01:00
wm4 41101c2996 win32: revert wchar_t changes
Revert "win32: more wchar_t -> WCHAR replacements"
Revert "win32: replace wchar_t with WCHAR"

Doing a "partial" port of this makes no sense anymore from my
perspective. Revert the changes, as they're confusing without
context, maintenance, and progress. These changes were a bit
premature anyway, and might actually cause other issues
(locale neutrality etc. as it was pointed out).
2015-08-01 21:09:11 +02:00
wm4 fefac2c941 win32: more wchar_t -> WCHAR replacements
This was essentially missing from commit 0b52ac8a.

Since L"..." string literals have the type wchar_t[], we can't use them
for UTF-16 strings. Use C11 u"..." string literals instead. These have
the type char16_t[], but we simply assume char16_t is the same
underlying type as WCHAR. In practice, they're both unsigned short.

For this reason use -std=c11 on Windows. Since Windows is a "special"
environment (we require either MinGW or Cygwin), we don't need to worry
too much about compiler compatibility.
2015-07-30 21:50:11 +02:00
wm4 0b52ac8a78 win32: replace wchar_t with WCHAR
WCHAR is more portable. While at least MinGW, Cygwin, and MSVC actually
use 16 bit wchar_t, Midipix will have 32 bit wchar_t. In that context,
using WCHAR instead is more portable.

This affects only non-MinGW parts, so not all uses of wchar_t need to
be changed. For example, terminal-win.c won't be used on Midipix at
all. (Most of io.c won't either, so the search & replace here is more
than necessary, but also not harmful.)

(Midipix is not useable yet, so this is just preparation.)
2015-07-29 00:01:32 +02:00
wm4 6ffb1e2b66 ao_wasapi: fix regression
This probably fixes the regression introduced with commit 6147bcce.
2015-06-27 17:59:27 +02:00
wm4 6147bcce35 audio: fix format function consistency issues
Replace all the check macros with function calls. Give them all the
same case and naming schema.

Drop af_fmt2bits(). Only af_fmt2bps() survives as af_fmt_to_bytes().

Introduce af_fmt_is_pcm(), and use it in situations that used
!AF_FORMAT_IS_SPECIAL. Nobody really knew what a "special" format
was. It simply meant "not PCM".
2015-06-26 23:06:37 +02:00
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