Commit Graph

300 Commits

Author SHA1 Message Date
Stefano Pigozzi e777a86b69 ao_coreaudio: use default output unit when no device is specified
Using the default output audio unit should provide a much better user
exeperience since it changes automatically the output device based on which
becomes the default one.
2013-07-29 08:22:33 +02:00
Stefano Pigozzi ca678dce4d ao_coreaudio: prevent buffer underruns to output garbage
This was removed in d427b4fd. I now found a sample that causes underruns when
moving to a chapter and apparently this is also a problem when taking
screenshots.
2013-07-28 11:21:03 +02:00
Dmitry Kalinkin 721071a5ec ao_coreaudio: fix compilation on OS X 10.7
Reverts one of the changes from 18777ecf. `kAudioObjectPropertyScopeOutput`
was introduced in the 10.8 SDK while `kAudioDevicePropertyScopeOutput` was
moved to `AudioHardwareDeprecated.h`. Since the deprecation is silent for now
(no warnings), just use the old constant.

Either way, they both evaluate to 'outp', and in the 10.8 SDK the deprecated
constant is defined in terms of the non-deprecated one.

Fixes #155
2013-07-28 09:48:49 +02:00
James Ross-Gowan 8e1461b9f8 ao_wasapi: don't check the audio feed while paused 2013-07-27 14:28:42 +10:00
wm4 e83cbde1a4 Fix some -Wshadow warnings
In general, this warning can hint to actual bugs. We don't enable it
yet, because it would conflict with some unmerged code, and we should
check with clang too (this commit was done by testing with gcc).
2013-07-23 00:45:23 +02:00
wm4 78ebb3c6fa options: make legacy hacks for AFs/VFs more explicit
This means that AOs/VOs with no options set do not take the legacy
option parsing path, but instead report that they have no options.
2013-07-22 23:07:23 +02:00
wm4 f32a90a839 audio/out: remove options argument from init()
Same as with VOs in the previous commit.
2013-07-22 22:58:09 +02:00
wm4 1df2ad7e03 Remove subopt-helper
Finally not used by anything anymore. Farewell.
2013-07-22 22:42:55 +02:00
Stefano Pigozzi 14f1a25a8e ao_coreaudio: fix ifdef'd conditional
The big endian case was not covered. Doesn't make much difference since mpv
runs on Macs with x86 only, but for the sake of correctness.
2013-07-22 22:35:44 +02:00
Stefano Pigozzi cd10936357 ao_coreaudio: use new option API 2013-07-22 22:27:08 +02:00
Stefano Pigozzi 7d58c51fd6 ao_coreaudio: switch properties getters to talloc 2013-07-22 21:53:18 +02:00
Stefano Pigozzi af6ad6717f ao_coreaudio: reduce verbosity of the chmapping code 2013-07-22 21:53:18 +02:00
Stefano Pigozzi df39121206 ao_coreaudio: revert to original device format on digital uninit
This is not done automatically by CoreAudio. I am told that it would a PITA
to have to switch back the format manually on the device (especially if the
same device is used for lpcm output).
2013-07-22 21:53:18 +02:00
Stefano Pigozzi c11c744998 ao_coreaudio: refactor chmap detection
b2f9e0610 introduced this functionality with code that was quite 'monolithic'.
Split the functionality over several functions and ose the new macros to get
array properties.
2013-07-22 21:53:18 +02:00
Stefano Pigozzi 18777ecfe8 ao_coreaudio: refactor properties code
Introduce some macros to deal with properties. These allow to work around the
limitation of CoreAudio's API being `void **` based. The macros allow to keep
their client's code DRY, by not asking size and other details which can be
derived by the macro itself. I have no idea why Apple didn't design their API
like this in the first place.
2013-07-22 21:53:18 +02:00
Stefano Pigozzi 1ed1175636 ao_coreaudio: move utils functions to snake_case 2013-07-22 21:53:18 +02:00
Stefano Pigozzi 1e37965597 ao_coreaudio: split ao_coreaudio_common in two files
* ao_coreaudio_utils: contains several utility function
 * ao_coreaudio_properties: contains functions to set and get  audio object
   properties.

Conflicts:
	audio/out/ao_coreaudio.c
2013-07-22 21:53:18 +02:00
Stefano Pigozzi 5a195845e3 ao_coreaudio: store asbd only when selected
Previous code needlessly stored the input asbd before actually testing it's
support against the hardware.
2013-07-22 21:53:18 +02:00
Stefano Pigozzi 4e0618dab9 ao_coreaudio: fallback to waveext on non surround inputs 2013-07-22 21:53:18 +02:00
Stefano Pigozzi c2de6fdf34 ao_coreaudio: set channel layout based on hardware query
this is a wip
2013-07-22 21:53:18 +02:00
Stefano Pigozzi 9652245ef0 ao_coreaudio: fix regression in digital stream selection
The condition was checked wrongly on asbd which is the input format
description. This lead to the condition always being true, thus selecting lpcm
streams for digital input.
2013-07-22 21:53:18 +02:00
Stefano Pigozzi e61102e637 ao_coreaudio: return errors instead false in init functions 2013-07-22 21:53:18 +02:00
Stefano Pigozzi b41fcc1e2c ao_coreaudio: remove useless function declaration 2013-07-22 21:53:18 +02:00
Stefano Pigozzi b174d647e5 ao_coreaudio: only set chmap_sel info for lpcm 2013-07-22 21:53:18 +02:00
Stefano Pigozzi 4d15f1bb60 ao_coreaudio: set channel layout bitmap 2013-07-22 21:53:18 +02:00
Stefano Pigozzi 24cad42363 ao_coreaudio: move digital detection before asbd creation 2013-07-22 21:53:18 +02:00
Stefano Pigozzi 6473cc59b1 ao_coreaudio: remove chmap selection if format is digital 2013-07-22 21:53:18 +02:00
Stefano Pigozzi 6d2f9a2804 ao_coreaudio: remove volume multiplication by 4
kHALOutputParam_Volume is the linear gain so it should be at maximum 1 to
keep the audio quality good. No idea why it was more than that.
2013-07-22 21:53:18 +02:00
Stefano Pigozzi a2d106cb31 ao_coreaudio: remove device property listener on uninit
Also extract this functionality inside a function in coreaudio_common
2013-07-22 21:53:18 +02:00
Stefano Pigozzi 7b2b292343 ao_coreaudio: print help string in one go 2013-07-22 21:53:18 +02:00
Stefano Pigozzi 5a4ae42892 ao_coreaudio: change all ++var to var++
Luckily they all were inside for loops so the functionality does not actually
change.
2013-07-22 21:53:18 +02:00
Stefano Pigozzi d3fb585b58 ao_coreaudio: change private vars names to match mpv conventions 2013-07-22 21:53:17 +02:00
Stefano Pigozzi d9c0dc7733 ao_coreaudio: remove packetSize private variable 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 7d7381f9cf ao_coreaudio: refactor play/pause 2013-07-22 21:53:17 +02:00
Stefano Pigozzi d4b161f37d ao_coreaudio: refactor uninit 2013-07-22 21:53:17 +02:00
Stefano Pigozzi f392ffe95c ao_coreaudio: remove a fixme since that seems fixed 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 6e44b12240 ao_coreaudio: ca_msg: add trailing \n where missing 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 88425625cf ao_coreaudio: refactor play 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 065e446e04 ao_coreaudio: extract mixmode set/unset in utility functions 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 838fa07376 ao_coreaudio: move AudioStreamChangeFormat to common file and refactor 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 40f6e2e041 ao_coreaudio: extract methods to lock/unlock device for digital output 2013-07-22 21:53:17 +02:00
Stefano Pigozzi e3ce0f0f8e ao_coreaudio: lpcm: remove buffer size calculation depending on audio unit 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 1640ce3262 ao_coreaudio: refactor initialization
The initialization is split more clearly between compressed and lpcm case.
For the compressed case, format selection is simplified a lot and negotiation
removed. The way it was written it just passed back to the core the original
requested format, not what was found available on hardware.

Since this is most likely useless for the compressed case, I didn't bother
with this. In the future I'd like to split this AO in two one that only uses
the AUHAL and the other with direct access to the hardware so that even
passthrough of lcpm can be possible. This would decrease the latency,
audiophiles would like that.
2013-07-22 21:53:17 +02:00
Stefano Pigozzi f9a31bc3d9 ao_coreaudio: refactor print_help 2013-07-22 21:53:17 +02:00
Stefano Pigozzi f35f6a34b5 ao_coreaudio: split out some utility functions and refactor them
Split out some utility functions that use the CoreAudio API but are not related
the main task of the AOs (which is to move data correctly to the ringbuffer).
These are mainly need for the verbosity of the CoreAudio API and are just
obscuring the 'real' code.
2013-07-22 21:53:17 +02:00
Stefano Pigozzi dc8eb9d77a ao_coreaudio: make variable names shorter
property_address -> p_addr
2013-07-22 21:53:17 +02:00
Stefano Pigozzi 45479825ba ao_coreaudio: add error check function and macro
WIP
2013-07-22 21:53:17 +02:00
Stefano Pigozzi 3edb605172 ao_coreaudio: dry up ca_msg and use it everywhere
Change the ca_msg macro to pass along MSGT_AO automatically. Also use it for
every output for consistency.
2013-07-22 21:53:17 +02:00
Stefano Pigozzi c4bed92280 ao_coreaudio: simplify digital render callback
It was reported that it also works by not setting the read size in the
AudioBuffer (now idea how, but I will discover it later).
2013-07-22 21:53:17 +02:00
Stefano Pigozzi 8cf36cf950 ao_coreaudio: rewrite spdif render callback 2013-07-22 21:53:17 +02:00
Stefano Pigozzi d427b4fd1c ao_coreaudio: simplify render callback
Read only the requested amount by the AUHAL (instead of all the buffered data).
No idea what the deal is with pausing the audio units if there is no audio to
play, maybe to avoid underruns of some sort. Anyway from my tests this
condition never occurred so I'm removing it all.
2013-07-22 21:53:16 +02:00
wm4 c729df3d10 af_bs2b: use new option API 2013-07-22 15:11:04 +02:00
wm4 74146a855c af_lavfi: switch to new option API
This makes it actually possible to use the filter with more complicated
filter graphs (such as graphs containing the "," character).
2013-07-22 15:11:04 +02:00
wm4 465b162d13 af_scaletempo: use new option API 2013-07-22 15:11:04 +02:00
wm4 7c2bf06615 af_lavrresample: switch to new option API
Also add a "o" suboption, which should allow fine control over
libavresample.
2013-07-22 15:11:04 +02:00
wm4 1189f64dd1 af_force: use new option API 2013-07-22 15:11:04 +02:00
wm4 3b8dfddb4c audio/filter: use new option API
Make the VF/VO/AO option parser available to audio filters. No audio
filter uses this yet, but it's still a quite intrusive change.

In particular, the commands for manipulating filters at runtime
completely change. We delete the old code, and use the same
infrastructure as for video filters. (This forces complete
reinitialization of the filter chain, which hopefully isn't a problem
for any use cases. The old code forced reinitialization too, but it
could potentially allow a filter to cache things; e.g. consider loaded
ladspa plugins and such.)
2013-07-22 15:11:03 +02:00
wm4 221ef23d0d af_force: add option that causes filter to fail at initialization
This is useful for debugging.
2013-07-22 15:06:43 +02:00
wm4 0c9b0ba40d af: fix recovery code for filter insertion (changing volume with spdif crash)
This code is supposed to run if dynamic filter insertion (such as when
inserting a volume filter in mixer.c) fails. Then it removes all filters
and recreates the default list of filters. But the code just blew up and
entered an endless loop, because it removed even the sentinel in/out
filters. This could happen when trying to use softvol controls while
using spdif, but also other situations. Fix it by calling the correct
code.

Also remove these obnoxious yoda-conditions.
2013-07-22 15:06:07 +02:00
wm4 f86b94f9b4 audio/decode: remove macro crap
Declare decoders directly, instead of using the LIBAD_EXTERN macro. This
is simpler (no weird magic) and more extensible.
2013-07-22 14:41:56 +02:00
Diogo Franco (Kovensky) 58338f9240 ao_wasapi: Make default on Windows.
Ahead of OSS because cygwin provides OSS.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 1b2dc3613f ao_wasapi: Fix S/PDIF passthrough init
MSDN tells me to multiply the samplerates by 4 (for setting up the S/PDIF
signal frequency), but doesn't mention that I'm only supposed to do it
on the new, NT6.1+ IEC 61937 structs. Works on my Realtek Digital Output,
but as I can't connect any hardware to it I can't hear the result.

Also, always ask for little-endian AC3. I'm not sure if this is supposed
to be LE or NE, but Windows is LE on all platforms, so we go with LE.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 9fe2772780 ao_wasapi: Log the passthrough format in MSGL_V 2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) a8b4be274c ao_wasapi: Also do passthrough for AF_FORMAT_MPEG2
That's the sample format ad_spdif uses when the source is MP3.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) dcf38e0190 ao_wasapi: Support S/PDIF passthrough
Entirely untested as this troper has no S/PDIF hardware.

Refuses trying any other format if we can't use passthrough, or we would
end up sending white noise at the user.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 58e3d3f207 ao_wasapi: Fix double free on uninit
Caused by incorrect conversion to the m_option API: since we don't allocate
the state ourselves, we also don't free it ourselves.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) c62395dc09 ao_wasapi: Support loading devices by name
Do an strstr match against the device description and, if we have only
a single match, take it. This works as long as the devices in the system
don't change, but it's not supposed to be reliable; if one wants
reliability, one uses the device ID string.

Formatting.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) ad6acddbcf ao_wasapi: Don't search for devices as part of validation
This could turn valid parameters into syntax errors by the mere presence
or abscence of a device (e.g. USB audio devices), so don't do that.

We do validate that, if the parameter is an integer, it is not negative.
We also respond to the "help" parameter, which does the same as the "list"
suboption but exits after listing.

Demote the validation logging to MSGL_DBG2.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) d68fa0531f ao_wasapi: Change function macros to require semicolon after invocation
Add semicolons where they were missing.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 964341b02d ao_wasapi: Use OPT_STRING_VALIDATE for device suboption
Validates by trying to pick the device using the device enumerator and
aborting with out of range on failure.

Refactors find_and_load_device to not use the wasapi_state; it might be
called during validation. Adds missing CoInitialize/CoUninitialize calls.
Remove unused variables (the SAFE_RELEASE macros keep them referenced so
compiler warnings don't help finding them...).

Remove the IMMDeviceEnumerator from the wasapi_state, it's only needed
during initialization and initialization is now well factored enough to
get rid of it.

Try and connect to unplugged devices as well when using the device ID
string.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) d42c3e51b4 ao_wasapi: Fully convert to m_option API 2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 56274c6664 ao_wasapi: Don't leak the default device's ID when listing devices
Also remove unused variable.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 32cb190855 ao_wasapi: Annotate the default device when listing devices 2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) efc3668fbe ao_wasapi: Refactor device listing/loading
Omit "{0.0.0.00000000}." on devices that start with that substring,
re-add when searching for devices by ID.

Log the device ID of the default device.

Log the friendly name of the used device.

Consistently refer to endpoints/devices as devices, as this is more
consistent with mpv terminology.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) d5adaed9d8 ao_wasapi0: Rename to ao_wasapi
Nobody knows what the 0 was for. There's no "WASAPI version 0". Just take
it out.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 553ed6b32f ao_wasapi0: Use the mix format directly in try_mix_format 2013-07-22 02:42:37 +02:00
Diogo Franco (Kovensky) d9a1358505 ao_wasapi0: Don't complain about failed init during AO probing
Only if the user specifically asked for ao_wasapi0.
2013-07-22 02:42:37 +02:00
Diogo Franco (Kovensky) 4cf1fc678f ao_wasapi0: Don't fail init when listing devices 2013-07-22 02:42:37 +02:00
Diogo Franco (Kovensky) 0081f1facd ao_wasapi0: Demote "negotiation failed" message to MSGL_V
Could spam the console with what may be harmless in some cases. We already
complain loudly if we're stuck checking this too many times.
2013-07-22 02:42:37 +02:00
Diogo Franco (Kovensky) df1922babe ao_wasapi0: Support shared mode, better format guessing method
Uses WASAPI in shared mode by default, add :exclusive flag to choose
exclusive mode (duh). WASAPI works somewhat different in shared mode:
the OS suggests the sample format to use, and the GetBuffer call is
done slightly differently.

The shared mode driver does not consume audio as fast as it notifies
the thread; we need to check how much we're allowed to write. Not doing
this correctly results in spamming the console with
AUDCLNT_E_BUFFER_TOO_LARGE errors.

When guessing formats for exclusive mode, try several sample size and
sample rate combinations instead of just falling back to s16le@44100hz.
If none of the rates are accepted, tries remixing >6 channels to 5.1
channels. Failing that, tries remixing to stereo. Failing everything,
including the CD Red Book format, what else is left to test?

Calculate buffer_block_size based on the configured channels and bytes
per sample; MSDN docs say nBlockAlign is not guaranteed to be set for
anything but integer PCM formats.
2013-07-22 02:42:37 +02:00
Diogo Franco (Kovensky) f12e14849d ao_wasapi0: Support device enumeration and selection
Adds the :list suboption to ao_wasapi0, which enumerates the audio endpoints
in the system.

Adds the :device=<n> suboption, which either takes an ID string (as output by
list) or a device number and uses the requested device instead of the system
default.
2013-07-22 02:42:37 +02:00
wm4 15ab75c7a0 ao_dsound: use new option API 2013-07-22 00:11:06 +02:00
wm4 0c28dc6adc ao_jack: use new option API 2013-07-22 00:03:57 +02:00
wm4 ecc5cb67f8 ao_oss: switch to new option API 2013-07-21 23:52:40 +02:00
wm4 5b91ba0a8d options: remove --mixer and --mixer-channel, turn them into alsa/oss subopts
These two options were supported by ALSA and OSS only. Further, their
values were specific to the respective audio systems, so it doesn't make
sense to keep them as top-level options.
2013-07-21 23:35:14 +02:00
wm4 5c610836cd ao_rsound: use new option API
Untested. I don't even know if this compiles. I have no clue what rsound
even is.
2013-07-21 23:27:32 +02:00
wm4 12e645fc24 ao_sdl: use new option API 2013-07-21 23:27:32 +02:00
wm4 73dc678c25 ao_openal: use new option API 2013-07-21 23:27:32 +02:00
wm4 ce89ba6d75 ao_pulse: use new option API
Untested, but should be fine.
2013-07-21 23:27:31 +02:00
wm4 3cdf4cf14d options: hide encoding AO/VO in help output
These can't be used manually. Encoding is enabled with -o instead, and
the encoding AO/VO is selected using internal mechanisms.
2013-07-21 23:27:31 +02:00
wm4 2111d7bc05 ao_alsa: use new option API (changes syntax)
This changes how device names are handled. Before this commit, device
names were mangled in strange ways to avoid clashing with the option
parser syntax. "." was replaced with ",", and "=" with ":" (the user had
to do the inverse to get the correct device name).

The "new" option parser has multiple ways to escape option strings, so
we don't need this confusing hack anymore.

Add an explicit note to the manpage as well.
2013-07-21 23:27:31 +02:00
wm4 38f81c618e ao_pcm: use new option API 2013-07-21 23:27:31 +02:00
wm4 38f712d96d ao_portaudio: use new option API
This basically serves as example. All other AOs should be ported as
well.
2013-07-21 23:27:31 +02:00
wm4 7eba27c125 options: use new option code for --ao
This requires completely refactoring the AO creation code too.
2013-07-21 23:27:31 +02:00
Diogo Franco (Kovensky) d0b129971a ao_wasapi0: Don't starve the WASAPI thread on seeks
Seeking calls thread_reset, but doesn't call thread_play. thread_reset
would disable WASAPI events, but they would never get re-enabled unless
the user paused and then unpaused.

Keep track of whether the stream is paused or not (there already was a
field for that, but it was apparently unused), and if it's not paused,
call thread_play after thread_reset. Fixes mpv freezing after seeks.
2013-07-20 02:21:04 +02:00
Diogo Franco (Kovensky) 20c2947cbb ao_wasapi0: Don't release WASAPI buffer twice
Would cause bogus AUDCLNT_E_OUT_OF_ORDER errors.
2013-07-20 02:21:00 +02:00
Diogo Franco (Kovensky) 9ab73b6373 ao_wasapi0: Make it compile on cygwin64
Fixes format specifies that assume windows TYPEDEFS are as long as they look
like they are.

Remove calls to _beginthreadex and _endthreadex, these are only present on
microsoft's C runtimes. Replace by the otherwise identical CreateThread and
ExitThread calls.

This actually requires fixes to devicetopology.h, but the problem has been
(kinda) reported to mingw-w64:

<Kovensky> I see that those KSJACK* structs are supposedly declared in
  devicetopology.h itself, but for some reason (some of?) the decls that use
  them aren't seeing them?
<Kovensky> ok, it seems that it expects ks.h and ksmedia.h to declare those
  structs, but it doesn't
<Kovensky> the included files declare KDATAFORMAT, KSIDENTIFIER and LUID (and
  the associated pointer typedefs)
<Kovensky> but everything else is essentially inside #if 0
<Kovensky> changing the #ifndef _KS_ to only include KDATAFORMAT, KSIDENTIFIER
  and LUID (and putting the KSJACK stuff outside that #ifndef) makes the
  header compile
<Kovensky> it solves my immediate problem, but if that happened to begin with
  there's probably something more wrong with the ks headers :S
2013-07-20 02:20:46 +02:00
wm4 66a9eb570d demux_mkv: never force output sample rate
Matroska has an output sample rate (OutputSamplingFrequency), which in
theory should be forced instead of whatever the decoder outputs. But it
appears no software (other than mplayer2 and mpv until now) actually
respects this. Even worse, there were broken files around, which played
correctly with (in theory) broken software, but not mplayer2/mpv. Hacks
were added to our code to play these files correctly, but they didn't
catch all cases.

Simplify this by doing what everyone else does, and always use the
decoder's sample rate instead. In particular, we try to handle all
sample rate issues like libavformat's Matroska demuxer does.
2013-07-16 22:44:15 +02:00
wm4 e18ffd6b99 Merge branch 'remove_old_demuxers'
The merged branch doesn't actually just remove old demuxers, but also
includes a branch of cleanups and some refactoring.

Conflicts:
	stream/stream.c
2013-07-14 17:59:26 +02:00
Jonathan Yong 27d352afbd ao_wasapi0: use new mp_ring buffer 2013-07-12 20:01:23 +02:00