summaryrefslogtreecommitdiffstats
path: root/audio/out/ao_wasapi.c
Commit message (Collapse)AuthorAgeFilesLines
* ao_wasapi: remove unnecessary header fileKevin Mitchell2016-01-051-11/+2
| | | | | All the wasapi files were including both ao_wasapi.h and ao_wasapi_utils.h. Just merge them into a single file.
* ao_wasapi: initialize change notify in main threadKevin Mitchell2016-01-051-0/+6
| | | | This is something else that has nothing to do with audio rendering.
* ao_wasapi: make find_deviceID read only wrt struct aoKevin Mitchell2016-01-051-1/+2
| | | | This makes it clearer that state->device is being allocated.
* ao_wasapi: move device selection to main threadKevin Mitchell2016-01-051-1/+6
| | | | In attempt to simplify the audio event thread, this can now be moved out.
* ao_wasapi: make persistent enumerator local to change_notifyKevin Mitchell2016-01-041-8/+1
| | | | This is no longer required by anything else
* ao_wasapi: fix delay calculation againKevin Mitchell2016-01-021-6/+12
| | | | | | | | Apparently it's only wine where the qpc_position returned by IAudioClock_GetPosition can be overflowed. So actually do the rescaling correctly, but throw away the result if it looks unreasonable. this fixes a regression in 5afa68835ade9f21f9c709f791319bf9d2e35265
* ao_wasapi: fix delay calculationKevin Mitchell2015-12-211-21/+36
| | | | | | | | | | | | | | | | | | | Make sure that subtraction of performance counters is done correctly. Follow the *exact* instructions for converting performance counter to something comparable to the QPCposition returned by IAudioClient::GetPosition https://msdn.microsoft.com/en-us/library/windows/desktop/dd370889%28v=vs.85%29.aspx Also make sure that subtraction of unsigned integers is stored into a signed integer to avoid nastiness. Also be more careful about overflow in the conversion of the device position into number of samples. Avoid casting mp_time_us() to a double, and use llrint to convert the double precision delay_us back to integer for ao_read_data. Finally, actually check the return value of ao_read_data and add a verbose message if it is not the expected value. Unfortunately, there is no way to tell WASAPI when this happens since the frame_count in ReleaseBuffer must match GetBuffer.
* ao_wasapi: non-fatal error handling for COM marshallingKevin Mitchell2015-12-211-1/+1
| | | | | Also make sure that CoReleaseMarshalData is called if errors occur before unmarshalling.
* ao_wasapi: wrap long lines and use only c99 comment styleKevin Mitchell2015-12-211-32/+43
| | | | | also remove a log message in AOCONTROL_UPDATE_STREAM_TITLE since none of the other controls have one.
* ao_wasapi: move exclusive and shared-specific controls to functionsKevin Mitchell2015-12-211-75/+87
|
* ao_wasapi: check for proxy availability in controlKevin Mitchell2015-12-201-22/+37
| | | | | Make sure that the proxy has been created before using it. This will be used when a future commit makes proxy setup optional.
* ao_wasapi: actually use hw volume support information for exclusive modeKevin Mitchell2015-12-201-17/+29
| | | | | | | | | 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.
* ao_wasapi: don't cast control arg to something it isn'tKevin Mitchell2015-12-201-9/+14
| | | | | the ao_control_vol_t cast was happening outside AOCONTROL_GET/SET_VOLUME which is the only place that would be valid
* ao_wasapi: remove volume "restore" on exitKevin Mitchell2015-12-201-28/+9
| | | | | | 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.
* ao_wasapi: split exclusive/shared specific ao controlsKevin Mitchell2015-12-201-37/+60
| | | | | this avoids having to check if we're exclusive or shared for every control
* ao_wasapi: get rid of Vistablob hackKevin Mitchell2015-11-241-4/+0
| | | | | This was required to work around XP linking issues and is no longer required.
* ao_wasapi: only report per-app volume in shared modeKevin Mitchell2015-11-191-1/+2
| | | | | otherwise we were incorrectly adjusting the hardware master volume in exclusive mode with softvol=auto
* win32: revert wchar_t changeswm42015-08-011-3/+2
| | | | | | | | | | | 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).
* win32: replace wchar_t with WCHARwm42015-07-291-2/+3
| | | | | | | | | | | | | 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.)
* ao_wasapi: fix crash on hotplug init errorwm42015-06-171-0/+1
| | | | | On init error, the mp_msg macros are actually called. They could cause a crash because state->log was NULL.
* ao/wasapi: use atomic state variable instead of different eventsKevin Mitchell2015-04-041-54/+61
| | | | | | | | | 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
* ao_wasapi: code formatting and alignmentKevin Mitchell2015-04-031-15/+15
|
* ao_wasapi: passthrough reworkKevin Mitchell2015-04-031-6/+0
| | | | | | | | | | | | | | | * 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
* ao_wasapi: abstract HRESULT_to_strKevin Mitchell2015-04-011-22/+11
|
* ao_wasapi: remove redundant castsKevin Mitchell2015-03-311-14/+14
|
* ao_wasapi: simplify hotplugKevin Mitchell2015-03-311-13/+16
| | | | | | | | | 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.
* ao_wasapi: fix device listingKevin Mitchell2015-03-311-9/+2
| | | | | remove depricated and convoluted validation. refer instead to the --audio-device option.
* ao/wasapi: add ao hotplugKevin Mitchell2015-03-311-0/+20
| | | | | | | 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.
* ao/wasapi: rewrite format searchKevin Mitchell2015-03-261-7/+0
| | | | | | | 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.
* ao/wasapi: move resume to audio threadKevin Mitchell2015-02-231-16/+37
| | | | | | | | | | | | | | 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
* ao_wasapi: move reset into audio threadKevin Mitchell2015-02-231-9/+36
| | | | | | | | | This makes things a bit more deterministic. It ensures that the audio thread isn't doing anything between IAudioClient_Stop(), IAudioClient_Reset() and setting the sample_count to 0. Buffer overfilling on resume is still a problem in exclusive mode (see next commit).
* win32: request UTF-16 API variants, Vista+ APIs, and COM C macroswm42015-01-071-3/+0
| | | | | 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.
* ao/wasapi: style/code formatting tweaksKevin Mitchell2015-01-021-7/+7
|
* ao/wasapi: remove unnecessary check of audio thread inputKevin Mitchell2014-11-281-2/+0
| | | | it would have caused a deadlock if it fired anyway.
* ao/wasapi: more missed cleanup on failureKevin Mitchell2014-11-281-3/+5
|
* ao/wasapi: check return valuesKevin Mitchell2014-11-281-3/+6
| | | | | Only issue a warning for failure of wasapi_enumerate_devices and wasapi_fill_VistaBlob.
* ao/wasapi: just return 0 unconditionally from the threadKevin Mitchell2014-11-281-10/+4
| | | | | We weren't actually checking this value anyway. We only really cared about init failure, which was checked another way.
* ao/wasapi: fix unmatched CoUninitialize() on init failureKevin Mitchell2014-11-281-0/+5
|
* ao/wasapi: more debugging messagesKevin Mitchell2014-11-281-2/+7
|
* ao/wasapi: make get_device_delay return an error codeKevin Mitchell2014-11-281-12/+21
|
* ao/wasapi: increase buffer size to 50 msKevin Mitchell2014-11-181-0/+1
| | | | | Before it was the default device period, which was too small causing glitches on on entering/exiting fullscreen.
* ao/wasapi: Don't free stuff the thread may still be using on timeoutKevin Mitchell2014-11-171-1/+3
| | | | | In the unlikely event of a timeout waiting for the audio thread to return, don't free stuff that it may still be using.
* ao/wasapi: also free the threadLoop handle on uninitKevin Mitchell2014-11-171-0/+1
| | | | http://msdn.microsoft.com/en-us/library/windows/desktop/ms682453%28v=vs.85%29.aspx
* ao/wasapi: fix leaked event handlesKevin Mitchell2014-11-171-6/+5
|
* ao/wasapi: fix race condition in uninit on failure.Kevin Mitchell2014-11-171-2/+1
| | | | | | | | | When the audio thread fails to properly init, it signals failure to the main thread, AND THEN starts to clean up. For this to work, ao_init callback must not return until the thread's cleanup is finished. This is correctly handled in the ao_uninit callback by waiting for the thread to exit, so just call that to clean up the main thread. I have no idea why I didn't do this in the first place.
* ao/wasapi: request ao reload on thread_feed failuresKevin Mitchell2014-11-171-0/+2
| | | | | | Even with change notifications, there are still (rare) cases when the feed thread gets AUDCLIENT_DEVICE_INVALIDATED. So handle failures in thread_feed by requesting ao_reload.
* ao/wasapi: request reset on appropriate eventsKevin Mitchell2014-11-171-5/+0
| | | | | | | | 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
* ao/wasapi: tidy up better on failureKevin Mitchell2014-11-171-12/+11
| | | | | | | Before, failures, particularly in the thread loop init, could lead to a bad state for the duration of mpvs execution. Make sure that everything that was initialized gets properly and safely uninitialized.
* ao/wasapi: improve error messages and add more debug statementsKevin Mitchell2014-11-171-21/+34
| | | | | | also enforce more consistency in the exit codes and error handling thanks to Jonathan Yong <10walls@gmail.com>
* ao/wasapi: make calling of thread_init consistent with thread_uninitKevin Mitchell2014-11-171-1/+1
|
* ao/wasapi: reenable the reset functionKevin Mitchell2014-11-171-1/+1
| | | | | | the race condition that necessitated disabling this was fixed in e4403523131a69a92a8418bb3714090a408680c7
* ao_wasapi: implement device listingwm42014-10-131-1/+7
|
* audio/out: remove old thingswm42014-09-061-1/+2
| | | | | | | | Remove the unnecessary indirection through ao fields. Also fix the inverted result of AOCONTROL_HAS_TEMP_VOLUME. Hopefully the change is equivalent. But actually, it looks like the old code did it wrong.
* audio/out/pull: remove race conditionswm42014-05-291-8/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There were subtle and minor race conditions in the pull.c code, and AOs using it (jack, portaudio, sdl, wasapi). Attempt to remove these. There was at least a race condition in the ao_reset() implementation: mp_ring_reset() was called concurrently to the audio callback. While the ringbuffer uses atomics to allow concurrent access, the reset function wasn't concurrency-safe (and can't easily be made to). Fix this by stopping the audio callback before doing a reset. After that, we can do anything without needing synchronization. The callback is resumed when resuming playback at a later point. Don't call driver->pause, and make driver->resume and driver->reset start/stop the audio callback. In the initial state, the audio callback must be disabled. JackAudio of course is different. Maybe there is no way to suspend the audio callback without "disconnecting" it (what jack_deactivate() would do), so I'm not trying my luck, and implemented a really bad hack doing active waiting until we get the audio callback into a state where it won't interfere. Once the callback goes from AO_STATE_WAIT to NONE, we can be sure that the callback doesn't access the ringbuffer or anything else anymore. Since both sched_yield() and pthread_yield() apparently are not always available, use mp_sleep_us(1) to avoid burning CPU during active waiting. The ao_jack.c change also removes a race condition: apparently we didn't initialize _all_ ao fields before starting the audio callback. In ao_wasapi.c, I'm not sure whether reset really waits for the audio callback to return. Kovensky says it's not guaranteed, so disable the reset callback - for now the behavior of ao_wasapi.c is like with ao_jack.c, and active waiting is used to deal with the audio callback.
* atomics: switch to C11 stdatomic.hwm42014-05-211-6/+3
| | | | | | | | | | | | | | | | | | | | | | | | | In my opinion, we shouldn't use atomics at all, but ok. This switches the mpv code to use C11 stdatomic.h, and for compilers that don't support stdatomic.h yet, we emulate the subset used by mpv using the builtins commonly provided by gcc and clang. This supersedes an earlier similar attempt by Kovensky. That attempt unfortunately relied on a big copypasted freebsd header (which also depended on much more highly compiler-specific functionality, defined reserved symbols, etc.), so it had to be NIH'ed. Some issues: - C11 says default initialization of atomics "produces a valid state", but it's not sure whether the stored value is really 0. But we rely on this. - I'm pretty sure our use of the __atomic... builtins is/was incorrect. We don't use atomic load/store intrinsics, and access stuff directly. - Our wrapper actually does stricter typechecking than the stdatomic.h implementation by gcc 4.9. We make the atomic types incompatible with normal types by wrapping them into structs. (The FreeBSD wrapper does the same.) - I couldn't test on MinGW.
* ao_wasapi: Use the character set conversion functions from io.hDiogo Franco (Kovensky)2014-03-111-12/+3
| | | | | ...rather than rolling out our own. The only possible advantage is that the "custom" ones didn't use talloc.
* ao_wasapi: Implement AOCONTROL_UPDATE_STREAM_TITLEDiogo Franco (Kovensky)2014-03-111-0/+30
|
* ao_wasapi: Implement per-application mixingDiogo Franco (Kovensky)2014-03-111-8/+41
| | | | | | | | | | | | | The volume controls in mpv now affect the session's volume (the application's volume in the mixer). Since we do not request a non-persistent session, the volume and mute status persist across mpv invocations and system reboots. In exclusive mode, WASAPI doesn't have access to a mixer so the endpoint (sound card)'s master volume is modified instead. Since by definition mpv is the only thing outputting audio in exclusive mode, this causes no conflict, and ao_wasapi restores the last user-set volume when it's uninitialized.
* ao_wasapi: Move non-critical code outside of the event threadDiogo Franco (Kovensky)2014-03-111-214/+54
| | | | | | | | | | | | | | | Due to the COM Single-Threaded Apartment model, the thread owning the objects will still do all the actual method calls (in the form of message dispatches), but at least this will be COM's problem rather than having to set up several handles and adding extra code to the event thread. Since the event thread still needs to own the WASAPI handles to avoid waiting on another thread to dispatch the messages, the init and uninit code still has to run in the thread. This also removes a broken drain implementation and removes unused headers from each of the files split from the original ao_wasapi.c.
* ao_wasapi: Split into 2 filesDiogo Franco (Kovensky)2014-03-111-900/+12
| | | | | | ao_wasapi.c was almost entirely init code mixed with option code and occasionally actual audio handling code. Split most things to ao_wasapi_utils.c and keep the audio handling code in ao_wasapi.c.
* ao_wasapi: Initial conversion to the new pull modelDiogo Franco (Kovensky)2014-03-111-154/+73
| | | | | | | | | Gets rid of the internal ring buffer and get_buffer. Corrects an implementation error in thread_reset. There is still a possible race condition on reset, and a few refactors left to do. If feasible, the thread that handles everything WASAPI-related will be made to only handle feed events.
* ao_wasapi: Use double math for QueryPerformanceCounter correctionDiogo Franco (Kovensky)2014-03-091-2/+2
| | | | | | The uint64_t math would cause overflow at long enough system uptimes (...such as 3 days), and any precision error given by the double math will be under one milisecond.
* audio/out: make draining a separate operationwm42014-03-091-2/+2
| | | | | | | | | | | | Until now, this was always conflated with uninit. This was ugly, and also many AOs emulated this manually (or just ignored it). Make draining an explicit operation, so AOs which support it can provide it, and for all others generic code will emulate it. For ao_wasapi, we keep it simple and basically disable the internal draining implementation (maybe it should be restored later). Tested on Linux only.
* audio/out: make ao struct opaquewm42014-03-091-0/+1
| | | | | | We want to move the AO to its own thread. There's no technical reason for making the ao struct opaque to do this. But it helps us sleep at night, because we can control access to shared state better.
* ao_wasapi: