1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-17 21:27:08 +00:00
Commit Graph

860 Commits

Author SHA1 Message Date
James Ross-Gowan
6f9eb960c7 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-25 17:00:21 +09:00
wm4
2a2dc4d73c ao_alsa: reinitialize if device got broken
Apparently, physically disconnecting the audio device (consider USB
audio) breaks the ALSA device handle forever. It will signal ENODEV.
Fortunately, it's easy for us to handle this, and we can just use
existing mechanisms that will make the playback core close and reopen
the AO. Whether the immediate reopening will actually succeeds really is
ALSA's problem, though.
2015-01-25 17:00:21 +09:00
wm4
7d523cd47a ao_coreaudio: reset possibly random errno value
In general, you need to check errno when using strtol(), but as far as I
know, strtol() won't reset errno on success. This has to be done
manually. The code could have failed sporadically if strtol() succeeded,
and errno was already set to one of the checked values.

(This strtol() still isn't fully error checked, but I don't know if it's
intentional, e.g. for parsing a numeric prefix only.)
2015-01-25 17:00:20 +09:00
wm4
4ebed102f0 ao_alsa: fix a small memory leak 2015-01-25 17:00:19 +09:00
wm4
c56b237b3c ao_alsa: fix dtshd passthrough
We must not try to remap channels with this. Whethever ALSA gives us,
and whatever we do with it, the result will probably be nonsense.

Untested, as I don't have the required hardware.
2015-01-25 17:00:19 +09:00
wm4
35cc1830a3 ao_pulse: disable latency calculation hacks by default
This used to be required to workaround PulseAudio bugs. Even later, when
the bugs were (partially?) fixed in PulseAudio, I had the feeling the
hacks gave better behavior. On the other hand, I couldn't actually
reproduce any bad behavior without the hacks lately. On top of this, it
seems our hacks sometimes perform much worse than PulseAudio's native
implementation (see #1430).

So disable the hacks by default, but still leave the code and the option
in case it still helps somewhere. Also, being able to blame PulseAudio's
code by using its native API is much easier than trying to debug our own
(mplayer2-derived) hacks.
2015-01-25 17:00:18 +09:00
wm4
f4a9c9424f 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.

Conflicts:
	video/out/w32_common.c
	waftools/checks/custom.py
2015-01-25 17:00:18 +09:00
wm4
cf997ff691 player: print used number of threads in verbose mode
Also, don't use av_log() for mpv output.
2015-01-25 17:00:18 +09:00
Kevin Mitchell
a5191c1479 ao/wasapi: style/code formatting tweaks 2015-01-25 17:00:17 +09:00
Kevin Mitchell
cfc5a65494 ao/wasapi: use IsEqualGUID and IsEqualPropertyKey
before we were reinventing this wheel
2015-01-25 17:00:17 +09:00
Kevin Mitchell
307b8925ee ao/wasapi: set the ao with the waveformat channelmap
hopefully this fixes #1350
2015-01-25 17:00:17 +09:00
Kevin Mitchell
2090a35c57 ao/wasapi: improve exclusive mode format search
fixes #1376
2015-01-25 17:00:17 +09:00
Kevin Mitchell
2746910515 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-25 17:00:17 +09:00
Kevin Mitchell
40dce4048f ao/wasapi: add CO_E_NOTINITIALIZED to explain_err
someone on irc reported seeing this error
2015-01-25 17:00:17 +09:00
wm4
ccf8c42a42 ao_alsa: print channel map if setting it fails
This message is printed when the audio device advertised a channel map,
but couldn't set it - which is probably a dmix bug (we'll never know,
ALSA doesn't take bug reports).

Print the requested map, so that the user (maybe) can make a connection
when seeing the message and the actually used channel map, which might
be less confusing. Or at least less useless.
2015-01-25 17:00:16 +09:00
Stefano Pigozzi
1a346ce11b ao: add debug log with the detected channel maps
This could be helpful with bug reports.
2015-01-25 17:00:16 +09:00
Stefano Pigozzi
891a9727c6 chmap_sel: add multichannel fallback heuristic
Instead of just failing during channel map selection, try to select a close
layout that makes most sense and upmix/downmix to that instead of failing AO
initialization. The heuristic is rather simple, and uses the following steps:

1) If mono is required always prefer stereo to a multichannel upmix.
2) Search for an upmix that is an exact superset of the required channel map.
3) Search for a downmix that is the exact subset of the required channel map.
4) Search for either an upmix or downmix that is the closest (minimum difference
   of channels) to the required channel map.
2015-01-25 17:00:15 +09:00
Stefano Pigozzi
2e133e9dde chmap: add a 7.1(rear) layout name
This is common on Apple systems so it's handy to have a label for it.
2015-01-25 17:00:15 +09:00
Stefano Pigozzi
d627c579ea ao_coreaudio: remove useless guard
useless after 069016fd6c
2015-01-25 17:00:15 +09:00
Stefano Pigozzi
752dd2ef76 ao_coreaudio: fix some naming conventions 2015-01-25 17:00:15 +09:00
Stefano Pigozzi
562e42f826 ao_coreaudio: fix channel mapping
There where 3 major errors in the previous code:

1) The kAudioDevicePropertyPreferredChannelLayout selector returns a single
   layout not an array.
2) The check for AudioChannelLayout allocation size was wrong (didn't account
   for variable sized struct).
3) Didn't query the kAudioDevicePropertyPreferredChannelsForStereo selector
   since I didn't know about it's existence.

All of these are fixed.

Might help with #1367
2015-01-25 17:00:15 +09:00
Stefano Pigozzi
ad3d8ce5c6 ao_coreaudio: fix typo 2015-01-25 17:00:15 +09:00
Stefano Pigozzi
777bffd307 ao_coreaudio: move some code to make output readable 2015-01-25 17:00:15 +09:00
Stefano Pigozzi
7f839323cb ao_coreaudio: add more layout debug outputs
Should help remote debugging #1367 with --msg-level=ao=debug
2015-01-25 17:00:15 +09:00
Stefano Pigozzi
cb4b28e336 ao_coreaudio: fix AudioChannelLayout allocations
AudioChannelLayout uses a trailing variable sized array so we need to
query CoreAudio for the size of the struct it is going to need (or the
conversion of that particular layout would fail).

Fixes #1366
2015-01-25 17:00:14 +09:00
Stefano Pigozzi
35be53108e ao_coreaudio: fix mono/stereo channel mapping
Needed after af3bbb800d since now we use channel mapping all the time.

Fixes #1357
2015-01-25 17:00:14 +09:00
wm4
f24b8cbd47 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.
2015-01-25 17:00:14 +09:00
Kevin Mitchell
c6ce2c6b43 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.
2015-01-25 17:00:12 +09:00
Kevin Mitchell
7f92344138 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.
2015-01-25 17:00:12 +09:00
Kevin Mitchell
d56a1112d2 ao/wasapi: show actual waveformat tried
also remove bogus ao_format
2015-01-25 17:00:12 +09:00
Kevin Mitchell
b1292c044a 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
2015-01-25 17:00:12 +09:00
Kevin Mitchell
18fb4bff6f ao/format: add af_fmt_is_float 2015-01-25 17:00:12 +09:00
Kevin Mitchell
7e60fb2c97 ao/wasapi: make sure that < 16-bit pcm never happens
it just sucks. noone should have to listen to that.
2015-01-25 17:00:12 +09:00
Kevin Mitchell
8c8af64820 ao/wasapi: get rid of WAVEFMT union
It only confused the issue. Replace it's functionality with
waveformat_copy function where needed.
2015-01-25 17:00:12 +09:00
Kevin Mitchell
01401b5f5b ao/wasapi: handle VistaBlob failure more gracefully 2015-01-25 17:00:11 +09:00
Kevin Mitchell
f794eca255 ao/wasapi: remove unnecessary check of audio thread input
it would have caused a deadlock if it fired anyway.
2015-01-25 17:00:11 +09:00
Kevin Mitchell
ad2a461a09 ao/wasapi: more consistent/reliable method of computing extra WAVEFORMATEXTENSIBLE size 2015-01-25 17:00:11 +09:00
Kevin Mitchell
2e931b34f4 ao/wasapi: more missed cleanup on failure 2015-01-25 17:00:11 +09:00
Kevin Mitchell
ade8b6214d ao/wasapi: check return values
Only issue a warning for failure of wasapi_enumerate_devices and
wasapi_fill_VistaBlob.
2015-01-25 17:00:11 +09:00
Kevin Mitchell
78e957a2bd 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).
2015-01-25 17:00:11 +09:00
Kevin Mitchell
9eb75631c7 ao/wasapi: check full GUID of KSDATAFORMAT to determine float 2015-01-25 17:00:11 +09:00
Kevin Mitchell
0c8a419775 ao/wasapi: expose GUID and PKEY convenience functions
Give them the prefix mp_ and make them nonstatic.
2015-01-25 17:00:10 +09:00
Kevin Mitchell
885c6e5b07 ao/wasapi: remove unused variable 2015-01-25 17:00:10 +09:00
Kevin Mitchell
44a7649e79 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
2015-01-25 17:00:10 +09:00
Kevin Mitchell
fded4de8a7 ao/wasapi: avoid redundant passing of ao and wasapi_state as arguments
also drop some useless const declaraitons
2015-01-25 17:00:10 +09:00
Kevin Mitchell
f20575f3dd 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.
2015-01-25 17:00:10 +09:00
Kevin Mitchell
1936cfdb09 ao/wasapi: fix unmatched CoUninitialize() on init failure 2015-01-25 17:00:10 +09:00
Kevin Mitchell
84c2dc882d ao/wasapi: more debugging messages 2015-01-25 17:00:10 +09:00
Kevin Mitchell
d72718ca65 ao/wasapi: simplify the init retry 2015-01-25 17:00:10 +09:00
Kevin Mitchell
8a73b02952 ao/wasapi: make get_device_delay return an error code 2015-01-25 17:00:10 +09:00