2 * Copyright 1993 Martin Ayotte
3 * 1998-2002 Eric Pouech
4 * 2011 Andrew Eikum for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
43 #include "mmdeviceapi.h"
44 #include "audioclient.h"
45 #include "audiopolicy.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
51 /* FIXME: Should be localized */
52 static const WCHAR volumeW[] = {'V','o','l','u','m','e',0};
53 static const WCHAR mastervolumeW[] = {'M','a','s','t','e','r',' ','V','o','l',
55 static const WCHAR muteW[] = {'M','u','t','e',0};
57 /* HWAVE (and HMIXER) format:
59 * XXXX... 1FDD DDDD IIII IIII
60 * X = unused (must be 0)
61 * 1 = the bit is set to 1, to avoid all-zero HWAVEs
62 * F = flow direction (0 = IN, 1 = OUT)
63 * D = index into g_out_mmdevices, or all 1s for the MAPPER device
64 * I = index in the mmdevice's devices array
66 * Two reasons that we don't just use pointers:
67 * - HWAVEs must fit into 16 bits for compatibility with old applications.
68 * - We must be able to identify bad devices without crashing.
71 /* buffer size = 10 * 100000 (100 ns) = 0.1 seconds */
72 #define AC_BUFLEN (10 * 100000)
73 #define MAX_DEVICES 256
74 #define MAPPER_INDEX 0x3F
76 typedef struct _WINMM_CBInfo {
83 struct _WINMM_MMDevice;
84 typedef struct _WINMM_MMDevice WINMM_MMDevice;
86 typedef struct _WINMM_Device {
95 IAudioRenderClient *render;
96 IAudioCaptureClient *capture;
98 IAudioStreamVolume *volume;
100 WAVEFORMATEX *orig_fmt;
101 HACMSTREAM acm_handle;
102 ACMSTREAMHEADER acm_hdr;
105 WAVEHDR *first, *last, *playing, *loop_start;
109 UINT32 bytes_per_frame, samples_per_sec, ofs_bytes, played_frames;
110 UINT32 remainder_frames; /* header chunk frames already played when a device switch occurred */
112 /* stored in frames of sample rate, *not* AC::GetFrequency */
113 UINT64 last_clock_pos;
116 CRITICAL_SECTION lock;
118 WINMM_MMDevice *parent;
121 struct _WINMM_MMDevice {
122 WAVEOUTCAPSW out_caps; /* must not be modified outside of WINMM_InitMMDevices*/
123 WAVEINCAPSW in_caps; /* must not be modified outside of WINMM_InitMMDevices*/
126 ISimpleAudioVolume *volume;
132 /* HMIXER format is the same as the HWAVE format, but the I bits are
133 * replaced by the value of this counter, to keep each HMIXER unique */
136 CRITICAL_SECTION lock;
138 WINMM_Device *devices[MAX_DEVICES];
141 static WINMM_MMDevice *g_out_mmdevices;
142 static WINMM_MMDevice **g_out_map;
143 static UINT g_outmmdevices_count;
144 static WINMM_Device *g_out_mapper_devices[MAX_DEVICES];
146 static WINMM_MMDevice *g_in_mmdevices;
147 static WINMM_MMDevice **g_in_map;
148 static UINT g_inmmdevices_count;
149 static WINMM_Device *g_in_mapper_devices[MAX_DEVICES];
151 static IMMDeviceEnumerator *g_devenum;
153 #define WINMM_WM_QUIT WM_USER
155 static CRITICAL_SECTION g_devthread_lock;
156 static CRITICAL_SECTION_DEBUG g_devthread_lock_debug =
158 0, 0, &g_devthread_lock,
159 { &g_devthread_lock_debug.ProcessLocksList, &g_devthread_lock_debug.ProcessLocksList },
160 0, 0, { (DWORD_PTR)(__FILE__ ": g_devthread_lock") }
162 static CRITICAL_SECTION g_devthread_lock = { &g_devthread_lock_debug, -1, 0, 0, 0, 0 };
163 static HANDLE g_devices_thread;
164 static HWND g_devices_hwnd;
166 static UINT g_devhandle_count;
167 static HANDLE *g_device_handles;
168 static WINMM_Device **g_handle_devices;
170 typedef struct _WINMM_OpenInfo {
173 WAVEFORMATEX *format;
180 typedef struct _WINMM_ControlDetails {
182 MIXERCONTROLDETAILS *details;
184 } WINMM_ControlDetails;
186 typedef struct _WINMM_QueryInterfaceInfo {
191 } WINMM_QueryInterfaceInfo;
193 static LRESULT WOD_Open(WINMM_OpenInfo *info);
194 static LRESULT WOD_Close(HWAVEOUT hwave);
195 static LRESULT WID_Open(WINMM_OpenInfo *info);
196 static LRESULT WID_Close(HWAVEIN hwave);
197 static MMRESULT WINMM_BeginPlaying(WINMM_Device *device);
199 void WINMM_DeleteWaveform(void)
204 for(i = 0; i < g_outmmdevices_count; ++i){
205 WINMM_MMDevice *mmdevice = &g_out_mmdevices[i];
206 for(j = 0; j < MAX_DEVICES && mmdevice->devices[j]; ++j){
207 WINMM_Device *device = mmdevice->devices[j];
208 SendMessageW(g_devices_hwnd, WODM_CLOSE, (WPARAM)device->handle, 0);
212 for(i = 0; i < g_inmmdevices_count; ++i){
213 WINMM_MMDevice *mmdevice = &g_in_mmdevices[i];
214 for(j = 0; j < MAX_DEVICES && mmdevice->devices[j]; ++j){
215 WINMM_Device *device = mmdevice->devices[j];
216 SendMessageW(g_devices_hwnd, WIDM_CLOSE, (WPARAM)device->handle, 0);
220 SendMessageW(g_devices_hwnd, WINMM_WM_QUIT, 0, 0);
222 for(i = 0; i < g_outmmdevices_count; ++i){
223 WINMM_MMDevice *mmdevice = &g_out_mmdevices[i];
225 for(j = 0; j < MAX_DEVICES && mmdevice->devices[j]; ++j){
226 WINMM_Device *device = mmdevice->devices[j];
228 CloseHandle(device->handle);
229 DeleteCriticalSection(&device->lock);
233 ISimpleAudioVolume_Release(mmdevice->volume);
234 CoTaskMemFree(mmdevice->dev_id);
235 DeleteCriticalSection(&mmdevice->lock);
238 for(i = 0; i < g_inmmdevices_count; ++i){
239 WINMM_MMDevice *mmdevice = &g_in_mmdevices[i];
241 for(j = 0; j < MAX_DEVICES && mmdevice->devices[j]; ++j){
242 WINMM_Device *device = mmdevice->devices[j];
244 CloseHandle(device->handle);
245 DeleteCriticalSection(&device->lock);
249 ISimpleAudioVolume_Release(mmdevice->volume);
250 CoTaskMemFree(mmdevice->dev_id);
251 DeleteCriticalSection(&mmdevice->lock);
254 HeapFree(GetProcessHeap(), 0, g_out_mmdevices);
255 HeapFree(GetProcessHeap(), 0, g_in_mmdevices);
257 HeapFree(GetProcessHeap(), 0, g_device_handles);
258 HeapFree(GetProcessHeap(), 0, g_handle_devices);
261 DeleteCriticalSection(&g_devthread_lock);
264 static inline HWAVE WINMM_MakeHWAVE(UINT mmdevice, BOOL is_out, UINT device)
266 return ULongToHandle((1 << 15) | ((!!is_out) << 14) |
267 (mmdevice << 8) | device);
270 static inline void WINMM_DecomposeHWAVE(HWAVE hwave, UINT *mmdevice_index,
271 BOOL *is_out, UINT *device_index, UINT *junk)
273 ULONG32 l = HandleToULong(hwave);
274 *device_index = l & 0xFF;
275 *mmdevice_index = (l >> 8) & 0x3F;
276 *is_out = (l >> 14) & 0x1;
280 static void WINMM_InitDevice(WINMM_Device *device)
282 InitializeCriticalSection(&device->lock);
283 device->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": WINMM_Device.lock");
286 static inline WINMM_MMDevice *read_map(WINMM_MMDevice **map, UINT index)
289 EnterCriticalSection(&g_devthread_lock);
291 LeaveCriticalSection(&g_devthread_lock);
295 /* finds the first unused Device, marks it as "open", and returns
296 * a pointer to the device
298 * IMPORTANT: it is the caller's responsibility to release the device's lock
301 static WINMM_Device *WINMM_FindUnusedDevice(WINMM_Device **devices,
302 WINMM_MMDevice *parent, UINT internal_index, BOOL is_out)
306 for(i = 0; i < MAX_DEVICES; ++i){
307 WINMM_Device *device = devices[i];
310 device = devices[i] = HeapAlloc(GetProcessHeap(),
311 HEAP_ZERO_MEMORY, sizeof(WINMM_Device));
315 WINMM_InitDevice(device);
316 EnterCriticalSection(&device->lock);
318 EnterCriticalSection(&device->lock);
321 device->handle = WINMM_MakeHWAVE(internal_index, is_out, i);
322 device->parent = parent;
328 LeaveCriticalSection(&device->lock);
331 TRACE("All devices in use: mmdevice: %u\n", internal_index);
336 static inline BOOL WINMM_ValidateAndLock(WINMM_Device *device)
341 EnterCriticalSection(&device->lock);
344 LeaveCriticalSection(&device->lock);
351 static WINMM_Device *WINMM_GetDeviceFromHWAVE(HWAVE hwave)
353 WINMM_MMDevice *mmdevice;
354 WINMM_Device *device;
355 UINT mmdevice_index, device_index, junk;
358 WINMM_DecomposeHWAVE(hwave, &mmdevice_index, &is_out, &device_index, &junk);
363 if(mmdevice_index == MAPPER_INDEX){
364 EnterCriticalSection(&g_devthread_lock);
366 device = g_out_mapper_devices[device_index];
368 device = g_in_mapper_devices[device_index];
369 LeaveCriticalSection(&g_devthread_lock);
373 if(mmdevice_index >= (is_out ? g_outmmdevices_count : g_inmmdevices_count))
377 mmdevice = &g_out_mmdevices[mmdevice_index];
379 mmdevice = &g_in_mmdevices[mmdevice_index];
381 EnterCriticalSection(&mmdevice->lock);
383 device = mmdevice->devices[device_index];
385 LeaveCriticalSection(&mmdevice->lock);
390 /* Note: NotifyClient should never be called while holding the device lock
391 * since the client may call wave* functions from within the callback. */
392 static inline void WINMM_NotifyClient(WINMM_CBInfo *info, WORD msg, DWORD_PTR param1,
395 DriverCallback(info->callback, info->flags, (HDRVR)info->hwave,
396 msg, info->user, param1, param2);
399 static MMRESULT hr2mmr(HRESULT hr)
403 case AUDCLNT_E_NOT_STOPPED:
404 return MMSYSERR_NOERROR;
405 case AUDCLNT_E_UNSUPPORTED_FORMAT:
406 return WAVERR_BADFORMAT;
407 case AUDCLNT_E_DEVICE_IN_USE:
408 return MMSYSERR_ALLOCATED;
409 case AUDCLNT_E_ENDPOINT_CREATE_FAILED:
410 return MMSYSERR_NOTENABLED;
412 return MMSYSERR_NOMEM;
415 return MMSYSERR_INVALPARAM;
416 case AUDCLNT_E_DEVICE_INVALIDATED: /* DSERR_BUFFERLOST */
418 return FAILED(hr) ? MMSYSERR_ERROR : MMSYSERR_NOERROR;
422 static HRESULT WINMM_GetFriendlyName(IMMDevice *device, WCHAR *out,
429 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
433 PropVariantInit(&var);
435 hr = IPropertyStore_GetValue(ps,
436 (PROPERTYKEY*)&DEVPKEY_Device_FriendlyName, &var);
438 IPropertyStore_Release(ps);
442 lstrcpynW(out, var.u.pwszVal, outlen);
444 PropVariantClear(&var);
446 IPropertyStore_Release(ps);
451 static HRESULT WINMM_TestFormat(IAudioClient *client, DWORD rate, DWORD depth,
454 WAVEFORMATEX fmt, *junk;
457 fmt.wFormatTag = WAVE_FORMAT_PCM;
458 fmt.nChannels = channels;
459 fmt.nSamplesPerSec = rate;
460 fmt.wBitsPerSample = depth;
461 fmt.nBlockAlign = (channels * depth) / 8;
462 fmt.nAvgBytesPerSec = rate * fmt.nBlockAlign;
465 hr = IAudioClient_IsFormatSupported(client, AUDCLNT_SHAREMODE_SHARED,
473 static struct _TestFormat {
478 } formats_to_test[] = {
479 { WAVE_FORMAT_1M08, 11025, 8, 1 },
480 { WAVE_FORMAT_1M16, 11025, 16, 1 },
481 { WAVE_FORMAT_1S08, 11025, 8, 2 },
482 { WAVE_FORMAT_1S16, 11025, 16, 2 },
483 { WAVE_FORMAT_2M08, 22050, 8, 1 },
484 { WAVE_FORMAT_2M16, 22050, 16, 1 },
485 { WAVE_FORMAT_2S08, 22050, 8, 2 },
486 { WAVE_FORMAT_2S16, 22050, 16, 2 },
487 { WAVE_FORMAT_4M08, 44100, 8, 1 },
488 { WAVE_FORMAT_4M16, 44100, 16, 1 },
489 { WAVE_FORMAT_4S08, 44100, 8, 2 },
490 { WAVE_FORMAT_4S16, 44100, 16, 2 },
491 { WAVE_FORMAT_48M08, 48000, 8, 1 },
492 { WAVE_FORMAT_48M16, 48000, 16, 1 },
493 { WAVE_FORMAT_48S08, 48000, 8, 2 },
494 { WAVE_FORMAT_48S16, 48000, 16, 2 },
495 { WAVE_FORMAT_96M08, 96000, 8, 1 },
496 { WAVE_FORMAT_96M16, 96000, 16, 1 },
497 { WAVE_FORMAT_96S08, 96000, 8, 2 },
498 { WAVE_FORMAT_96S16, 96000, 16, 2 },
502 static DWORD WINMM_GetSupportedFormats(IMMDevice *device)
506 struct _TestFormat *fmt;
507 IAudioClient *client;
509 hr = IMMDevice_Activate(device, &IID_IAudioClient,
510 CLSCTX_INPROC_SERVER, NULL, (void**)&client);
514 for(fmt = formats_to_test; fmt->flag; ++fmt){
515 hr = WINMM_TestFormat(client, fmt->rate, fmt->depth, fmt->channels);
520 IAudioClient_Release(client);
525 static HRESULT WINMM_InitMMDevice(EDataFlow flow, IMMDevice *device,
526 WINMM_MMDevice *dev, UINT index)
531 dev->out_caps.wMid = 0xFF;
532 dev->out_caps.wPid = 0xFF;
533 dev->out_caps.vDriverVersion = 0x00010001;
534 dev->out_caps.dwFormats = WINMM_GetSupportedFormats(device);
535 dev->out_caps.wReserved1 = 0;
536 dev->out_caps.dwSupport = WAVECAPS_LRVOLUME | WAVECAPS_VOLUME |
537 WAVECAPS_SAMPLEACCURATE;
538 dev->out_caps.wChannels = 2;
539 dev->out_caps.szPname[0] = '\0';
541 hr = WINMM_GetFriendlyName(device, dev->out_caps.szPname,
542 sizeof(dev->out_caps.szPname) /
543 sizeof(*dev->out_caps.szPname));
547 dev->in_caps.wMid = 0xFF;
548 dev->in_caps.wPid = 0xFF;
549 dev->in_caps.vDriverVersion = 0x00010001;
550 dev->in_caps.dwFormats = WINMM_GetSupportedFormats(device);
551 dev->in_caps.wReserved1 = 0;
552 dev->in_caps.wChannels = 2;
553 dev->in_caps.szPname[0] = '\0';
555 hr = WINMM_GetFriendlyName(device, dev->in_caps.szPname,
556 sizeof(dev->in_caps.szPname) /
557 sizeof(*dev->in_caps.szPname));
562 hr = IMMDevice_GetId(device, &dev->dev_id);
566 CoCreateGuid(&dev->session);
570 InitializeCriticalSection(&dev->lock);
571 dev->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": WINMM_Device.lock");
576 static HRESULT WINMM_EnumDevices(WINMM_MMDevice **devices,
577 WINMM_MMDevice ***map, UINT *devcount, EDataFlow flow,
578 IMMDeviceEnumerator *devenum)
580 IMMDeviceCollection *devcoll;
583 hr = IMMDeviceEnumerator_EnumAudioEndpoints(devenum, flow,
584 DEVICE_STATE_ACTIVE, &devcoll);
588 hr = IMMDeviceCollection_GetCount(devcoll, devcount);
590 IMMDeviceCollection_Release(devcoll);
596 IMMDevice *def_dev = NULL;
598 *devices = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
599 sizeof(WINMM_MMDevice) * (*devcount));
601 IMMDeviceCollection_Release(devcoll);
602 return E_OUTOFMEMORY;
605 *map = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
606 sizeof(WINMM_MMDevice *) * (*devcount));
608 IMMDeviceCollection_Release(devcoll);
609 HeapFree(GetProcessHeap(), 0, *devices);
610 return E_OUTOFMEMORY;
613 /* make sure that device 0 is the default device */
614 IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum,
615 flow, eConsole, &def_dev);
617 for(n = 0; n < *devcount; ++n){
620 hr = IMMDeviceCollection_Item(devcoll, n, &device);
622 WINMM_InitMMDevice(flow, device, &(*devices)[n], n);
624 if(device == def_dev)
625 (*map)[0] = &(*devices)[n];
627 (*map)[count] = &(*devices)[n];
631 IMMDevice_Release(device);
635 IMMDevice_Release(def_dev);
640 IMMDeviceCollection_Release(devcoll);
645 static HRESULT WINAPI notif_QueryInterface(IMMNotificationClient *iface,
646 const GUID *riid, void **obj)
648 ERR("Unexpected QueryInterface call: %s\n", wine_dbgstr_guid(riid));
649 return E_NOINTERFACE;
652 static ULONG WINAPI notif_AddRef(IMMNotificationClient *iface)
657 static ULONG WINAPI notif_Release(IMMNotificationClient *iface)
662 static HRESULT WINAPI notif_OnDeviceStateChanged(IMMNotificationClient *iface,
663 const WCHAR *device_id, DWORD new_state)
665 TRACE("Ignoring OnDeviceStateChanged callback\n");
669 static HRESULT WINAPI notif_OnDeviceAdded(IMMNotificationClient *iface,
670 const WCHAR *device_id)
672 TRACE("Ignoring OnDeviceAdded callback\n");
676 static HRESULT WINAPI notif_OnDeviceRemoved(IMMNotificationClient *iface,
677 const WCHAR *device_id)
679 TRACE("Ignoring OnDeviceRemoved callback\n");
683 static HRESULT update_mapping(WINMM_MMDevice ***map, UINT count,
684 const WCHAR *default_id)
686 WINMM_MMDevice *prev;
690 for(i = 0; i < count; ++i){
693 if(!lstrcmpW((*map)[i]->dev_id, default_id)){
694 (*map)[0] = (*map)[i];
705 WARN("Couldn't find new default device! Rearranged map for no reason.\n");
711 static HRESULT reroute_mapper_device(WINMM_Device *device, BOOL is_out)
717 UINT64 clock_freq, clock_pos;
719 TRACE("rerouting device %p\n", device->handle);
721 EnterCriticalSection(&device->lock);
723 if(!device->open || device->acm_handle){
724 /* Windows 7 doesn't re-route ACM devices, so we don't either.
725 * Seems to be because of the data waveXxxPrepareHeader allocates. */
726 LeaveCriticalSection(&device->lock);
730 stopped = device->stopped;
733 info.req_device = WAVE_MAPPER;
734 info.format = device->orig_fmt;
735 info.callback = device->cb_info.callback;
736 info.cb_user = device->cb_info.user;
737 /* We have to use direct here so that we don't suddenly introduce ACM
738 * into a playing stream that hasn't been Prepared for it */
739 info.flags = (device->cb_info.flags << 16) | WAVE_FORMAT_DIRECT_QUERY;
743 mr = WOD_Open(&info);
745 mr = WID_Open(&info);
747 if(mr != MMSYSERR_NOERROR){
748 TRACE("New default device doesn't support this stream: %p\n", device->handle);
749 LeaveCriticalSection(&device->lock);
753 hr = IAudioClient_Stop(device->client);
755 WARN("Stop failed: %08x\n", hr);
757 hr = IAudioClock_GetFrequency(device->clock, &clock_freq);
759 WARN("GetFrequency failed: %08x\n", hr);
760 LeaveCriticalSection(&device->lock);
764 hr = IAudioClock_GetPosition(device->clock, &clock_pos, NULL);
766 WARN("GetPosition failed: %08x\n", hr);
767 LeaveCriticalSection(&device->lock);
771 device->remainder_frames = MulDiv(clock_pos, device->samples_per_sec, clock_freq) - device->last_clock_pos;
773 info.handle = device->handle;
774 info.flags = (device->cb_info.flags << 16) | WAVE_FORMAT_DIRECT;
777 WOD_Close((HWAVEOUT)device->handle);
778 device->parent = read_map(g_out_map, 0);
779 mr = WOD_Open(&info);
781 WID_Close((HWAVEIN)device->handle);
782 device->parent = read_map(g_in_map, 0);
783 mr = WID_Open(&info);
786 if(mr != MMSYSERR_NOERROR){
787 ERR("Opening new default device failed! %u\n", mr);
788 LeaveCriticalSection(&device->lock);
792 HeapFree(GetProcessHeap(), 0, info.format);
795 WINMM_BeginPlaying(device);
797 LeaveCriticalSection(&device->lock);
802 static HRESULT WINAPI notif_OnDefaultDeviceChanged(IMMNotificationClient *iface,
803 EDataFlow flow, ERole role, const WCHAR *device_id)
807 TRACE("%u %u %s\n", flow, role, wine_dbgstr_w(device_id));
812 EnterCriticalSection(&g_devthread_lock);
815 update_mapping(&g_out_map, g_outmmdevices_count, device_id);
817 update_mapping(&g_in_map, g_inmmdevices_count, device_id);
819 for(i = 0; i < MAX_DEVICES && g_out_mapper_devices[i]; ++i)
820 reroute_mapper_device(g_out_mapper_devices[i], TRUE);
822 for(i = 0; i < MAX_DEVICES && g_in_mapper_devices[i]; ++i)
823 reroute_mapper_device(g_in_mapper_devices[i], FALSE);
825 LeaveCriticalSection(&g_devthread_lock);
830 static HRESULT WINAPI notif_OnPropertyValueChanged(IMMNotificationClient *iface,
831 const WCHAR *device_id, const PROPERTYKEY key)
833 TRACE("Ignoring OnPropertyValueChanged callback\n");
837 static IMMNotificationClientVtbl g_notif_vtbl = {
838 notif_QueryInterface,
841 notif_OnDeviceStateChanged,
843 notif_OnDeviceRemoved,
844 notif_OnDefaultDeviceChanged,
845 notif_OnPropertyValueChanged
848 static IMMNotificationClient g_notif = { &g_notif_vtbl };
850 static HRESULT WINMM_InitMMDevices(void)
853 IMMDeviceEnumerator *devenum = NULL;
855 if(g_outmmdevices_count || g_inmmdevices_count)
858 init_hr = CoInitialize(NULL);
860 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
861 CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&devenum);
865 hr = IMMDeviceEnumerator_RegisterEndpointNotificationCallback(devenum, &g_notif);
867 WARN("RegisterEndpointNotificationCallback failed: %08x\n", hr);
869 hr = WINMM_EnumDevices(&g_out_mmdevices, &g_out_map, &g_outmmdevices_count,
872 g_outmmdevices_count = 0;
873 g_inmmdevices_count = 0;
877 hr = WINMM_EnumDevices(&g_in_mmdevices, &g_in_map, &g_inmmdevices_count,
880 g_inmmdevices_count = 0;
886 IMMDeviceEnumerator_Release(devenum);
887 if(SUCCEEDED(init_hr))
893 static inline BOOL WINMM_IsMapper(UINT device)
895 return (device == WAVE_MAPPER || device == (UINT16)WAVE_MAPPER);
898 static MMRESULT WINMM_TryDeviceMapping(WINMM_Device *device, WAVEFORMATEX *fmt,
899 WORD channels, DWORD freq, DWORD bits_per_samp, BOOL is_out)
901 WAVEFORMATEX target, *closer_fmt = NULL;
905 TRACE("format: %u, channels: %u, sample rate: %u, bit depth: %u\n",
906 WAVE_FORMAT_PCM, channels, freq, bits_per_samp);
908 target.wFormatTag = WAVE_FORMAT_PCM;
909 target.nChannels = channels;
910 target.nSamplesPerSec = freq;
911 target.wBitsPerSample = bits_per_samp;
912 target.nBlockAlign = (target.nChannels * target.wBitsPerSample) / 8;
913 target.nAvgBytesPerSec = target.nSamplesPerSec * target.nBlockAlign;
916 hr = IAudioClient_IsFormatSupported(device->client,
917 AUDCLNT_SHAREMODE_SHARED, &target, &closer_fmt);
919 CoTaskMemFree(closer_fmt);
921 return WAVERR_BADFORMAT;
923 /* device supports our target format, so see if MSACM can
924 * do the conversion */
926 mr = acmStreamOpen(&device->acm_handle, NULL, fmt, &target, NULL,
929 mr = acmStreamOpen(&device->acm_handle, NULL, &target, fmt, NULL,
931 if(mr != MMSYSERR_NOERROR)
934 /* yes it can. initialize the audioclient and return success */
935 hr = IAudioClient_Initialize(device->client, AUDCLNT_SHAREMODE_SHARED,
936 AUDCLNT_STREAMFLAGS_EVENTCALLBACK | AUDCLNT_STREAMFLAGS_NOPERSIST,
937 AC_BUFLEN, 0, &target, &device->parent->session);
939 WARN("Initialize failed: %08x\n", hr);
940 acmStreamClose(device->acm_handle, 0);
941 device->acm_handle = NULL;
942 return MMSYSERR_ERROR;
945 device->bytes_per_frame = target.nBlockAlign;
946 device->samples_per_sec = target.nSamplesPerSec;
950 return MMSYSERR_NOERROR;
953 static MMRESULT WINMM_MapDevice(WINMM_Device *device, BOOL is_out)
956 WAVEFORMATEXTENSIBLE *fmtex = (WAVEFORMATEXTENSIBLE*)device->orig_fmt;
958 TRACE("(%p, %u)\n", device, is_out);
960 /* set up the ACM stream */
961 if(device->orig_fmt->wFormatTag != WAVE_FORMAT_PCM &&
962 !(device->orig_fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
963 IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))){
964 /* convert to PCM format if it's not already */
965 mr = WINMM_TryDeviceMapping(device, device->orig_fmt,
966 device->orig_fmt->nChannels, device->orig_fmt->nSamplesPerSec,
968 if(mr == MMSYSERR_NOERROR)
971 mr = WINMM_TryDeviceMapping(device, device->orig_fmt,
972 device->orig_fmt->nChannels, device->orig_fmt->nSamplesPerSec,
974 if(mr == MMSYSERR_NOERROR)
979 /* first try just changing bit depth and channels */
980 channels = device->orig_fmt->nChannels;
981 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels,
982 device->orig_fmt->nSamplesPerSec, 16, is_out);
983 if(mr == MMSYSERR_NOERROR)
985 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels,
986 device->orig_fmt->nSamplesPerSec, 8, is_out);
987 if(mr == MMSYSERR_NOERROR)
990 channels = (channels == 2) ? 1 : 2;
991 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels,
992 device->orig_fmt->nSamplesPerSec, 16, is_out);
993 if(mr == MMSYSERR_NOERROR)
995 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels,
996 device->orig_fmt->nSamplesPerSec, 8, is_out);
997 if(mr == MMSYSERR_NOERROR)
1000 /* that didn't work, so now try different sample rates */
1001 channels = device->orig_fmt->nChannels;
1002 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 96000, 16, is_out);
1003 if(mr == MMSYSERR_NOERROR)
1005 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 48000, 16, is_out);
1006 if(mr == MMSYSERR_NOERROR)
1008 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 44100, 16, is_out);
1009 if(mr == MMSYSERR_NOERROR)
1011 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 22050, 16, is_out);
1012 if(mr == MMSYSERR_NOERROR)
1014 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 11025, 16, is_out);
1015 if(mr == MMSYSERR_NOERROR)
1018 channels = (channels == 2) ? 1 : 2;
1019 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 96000, 16, is_out);
1020 if(mr == MMSYSERR_NOERROR)
1022 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 48000, 16, is_out);
1023 if(mr == MMSYSERR_NOERROR)
1025 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 44100, 16, is_out);
1026 if(mr == MMSYSERR_NOERROR)
1028 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 22050, 16, is_out);
1029 if(mr == MMSYSERR_NOERROR)
1031 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 11025, 16, is_out);
1032 if(mr == MMSYSERR_NOERROR)
1035 channels = device->orig_fmt->nChannels;
1036 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 96000, 8, is_out);
1037 if(mr == MMSYSERR_NOERROR)
1039 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 48000, 8, is_out);
1040 if(mr == MMSYSERR_NOERROR)
1042 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 44100, 8, is_out);
1043 if(mr == MMSYSERR_NOERROR)
1045 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 22050, 8, is_out);
1046 if(mr == MMSYSERR_NOERROR)
1048 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 11025, 8, is_out);
1049 if(mr == MMSYSERR_NOERROR)
1052 channels = (channels == 2) ? 1 : 2;
1053 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 96000, 8, is_out);
1054 if(mr == MMSYSERR_NOERROR)
1056 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 48000, 8, is_out);
1057 if(mr == MMSYSERR_NOERROR)
1059 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 44100, 8, is_out);
1060 if(mr == MMSYSERR_NOERROR)
1062 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 22050, 8, is_out);
1063 if(mr == MMSYSERR_NOERROR)
1065 mr = WINMM_TryDeviceMapping(device, device->orig_fmt, channels, 11025, 8, is_out);
1066 if(mr == MMSYSERR_NOERROR)
1070 WARN("Unable to find compatible device!\n");
1071 return WAVERR_BADFORMAT;
1074 static LRESULT WINMM_OpenDevice(WINMM_Device *device, WINMM_OpenInfo *info,
1077 LRESULT ret = MMSYSERR_NOMEM;
1080 hr = IMMDeviceEnumerator_GetDevice(g_devenum, device->parent->dev_id,
1083 WARN("Device %s (%s) unavailable: %08x\n",
1084 wine_dbgstr_w(device->parent->dev_id),
1085 wine_dbgstr_w(device->parent->out_caps.szPname), hr);
1086 ret = MMSYSERR_NODRIVER;
1090 /* this is where winexyz.drv opens the audio device */
1091 hr = IMMDevice_Activate(device->device, &IID_IAudioClient,
1092 CLSCTX_INPROC_SERVER, NULL, (void**)&device->client);
1094 WARN("Activate failed: %08x\n", hr);
1096 if(ret == MMSYSERR_ERROR)
1097 ret = MMSYSERR_NOTENABLED;
1101 if(info->format->wFormatTag == WAVE_FORMAT_PCM){
1102 /* we aren't guaranteed that the struct in lpFormat is a full
1103 * WAVEFORMATEX struct, which IAC::IsFormatSupported requires */
1104 device->orig_fmt = HeapAlloc(GetProcessHeap(), 0, sizeof(WAVEFORMATEX));
1105 memcpy(device->orig_fmt, info->format, sizeof(PCMWAVEFORMAT));
1106 device->orig_fmt->cbSize = 0;
1107 if(device->orig_fmt->wBitsPerSample % 8 != 0){
1108 WARN("Fixing bad wBitsPerSample (%u)\n", device->orig_fmt->wBitsPerSample);
1109 device->orig_fmt->wBitsPerSample = (device->orig_fmt->wBitsPerSample + 7) & ~7;
1111 /* winmm ignores broken blockalign and avgbytes */
1112 if(device->orig_fmt->nBlockAlign != device->orig_fmt->nChannels * device->orig_fmt->wBitsPerSample/8){
1113 WARN("Fixing bad nBlockAlign (%u)\n", device->orig_fmt->nBlockAlign);
1114 device->orig_fmt->nBlockAlign = device->orig_fmt->nChannels * device->orig_fmt->wBitsPerSample/8;
1116 if (device->orig_fmt->nAvgBytesPerSec != device->orig_fmt->nSamplesPerSec * device->orig_fmt->nBlockAlign) {
1117 WARN("Fixing bad nAvgBytesPerSec (%u)\n", device->orig_fmt->nAvgBytesPerSec);
1118 device->orig_fmt->nAvgBytesPerSec = device->orig_fmt->nSamplesPerSec * device->orig_fmt->nBlockAlign;
1121 device->orig_fmt = HeapAlloc(GetProcessHeap(), 0,
1122 sizeof(WAVEFORMATEX) + info->format->cbSize);
1123 memcpy(device->orig_fmt, info->format,
1124 sizeof(WAVEFORMATEX) + info->format->cbSize);
1127 if(info->flags & WAVE_FORMAT_QUERY){
1128 WAVEFORMATEX *closer_fmt = NULL;
1130 hr = IAudioClient_IsFormatSupported(device->client,
1131 AUDCLNT_SHAREMODE_SHARED, device->orig_fmt, &closer_fmt);
1133 CoTaskMemFree(closer_fmt);
1134 ret = hr == S_FALSE ? WAVERR_BADFORMAT : hr2mmr(hr);
1138 hr = IAudioClient_Initialize(device->client, AUDCLNT_SHAREMODE_SHARED,
1139 AUDCLNT_STREAMFLAGS_EVENTCALLBACK | AUDCLNT_STREAMFLAGS_NOPERSIST,
1140 AC_BUFLEN, 0, device->orig_fmt, &device->parent->session);
1142 if(hr == AUDCLNT_E_UNSUPPORTED_FORMAT && !(info->flags & WAVE_FORMAT_DIRECT)){
1143 ret = WINMM_MapDevice(device, is_out);
1144 if(ret != MMSYSERR_NOERROR || info->flags & WAVE_FORMAT_QUERY)
1147 WARN("Initialize failed: %08x\n", hr);
1152 device->bytes_per_frame = device->orig_fmt->nBlockAlign;
1153 device->samples_per_sec = device->orig_fmt->nSamplesPerSec;
1156 hr = IAudioClient_GetService(device->client, &IID_IAudioClock,
1157 (void**)&device->clock);
1159 WARN("GetService failed: %08x\n", hr);
1164 device->event = CreateEventW(NULL, FALSE, FALSE, NULL);
1166 WARN("CreateEvent failed: %08x\n", hr);
1170 /* As the devices thread is waiting on g_device_handles, it can
1171 * only be modified from within this same thread. */
1172 if(g_device_handles){
1173 g_device_handles = HeapReAlloc(GetProcessHeap(), 0, g_device_handles,
1174 sizeof(HANDLE) * (g_devhandle_count + 1));
1175 g_handle_devices = HeapReAlloc(GetProcessHeap(), 0, g_handle_devices,
1176 sizeof(WINMM_Device *) * (g_devhandle_count + 1));
1178 g_device_handles = HeapAlloc(GetProcessHeap(), 0, sizeof(HANDLE));
1179 g_handle_devices = HeapAlloc(GetProcessHeap(), 0,
1180 sizeof(WINMM_Device *));
1182 g_device_handles[g_devhandle_count] = device->event;
1183 g_handle_devices[g_devhandle_count] = device;
1184 ++g_devhandle_count;
1187 hr = IAudioClient_SetEventHandle(device->client, device->event);
1189 WARN("SetEventHandle failed: %08x\n", hr);
1194 device->played_frames = 0;
1195 device->ofs_bytes = 0;
1196 device->loop_counter = 0;
1197 device->first = device->last = device->playing = device->loop_start = NULL;
1200 device->stopped = TRUE;
1201 device->last_clock_pos = 0;
1203 device->cb_info.flags = HIWORD(info->flags & CALLBACK_TYPEMASK);
1204 device->cb_info.callback = info->callback;
1205 device->cb_info.user = info->cb_user;
1206 device->cb_info.hwave = device->handle;
1208 info->handle = device->handle;
1210 return MMSYSERR_NOERROR;
1214 IAudioClient_Release(device->client);
1215 device->client = NULL;
1218 IMMDevice_Release(device->device);
1219 device->device = NULL;
1225 static LRESULT WOD_Open(WINMM_OpenInfo *info)
1227 WINMM_Device *device;
1228 LRESULT ret = MMSYSERR_ERROR;
1231 if(info->handle != 0){
1232 device = WINMM_GetDeviceFromHWAVE(info->handle);
1234 WARN("Unexpected! Invalid info->handle given: %p\n", info->handle);
1235 return MMSYSERR_ERROR;
1238 EnterCriticalSection(&device->lock);
1240 device->open = TRUE;
1242 CRITICAL_SECTION *lock;
1243 UINT internal_index;
1244 WINMM_Device **devices;
1245 WINMM_MMDevice *mmdevice;
1247 if(WINMM_IsMapper(info->req_device)){
1248 devices = g_out_mapper_devices;
1249 mmdevice = read_map(g_out_map, 0);
1250 lock = &g_devthread_lock;
1251 internal_index = MAPPER_INDEX;
1253 if(info->req_device >= g_outmmdevices_count)
1254 return MMSYSERR_BADDEVICEID;
1256 mmdevice = read_map(g_out_map, info->req_device);
1258 if(!mmdevice->out_caps.szPname[0])
1259 return MMSYSERR_NOTENABLED;
1261 devices = mmdevice->devices;
1262 lock = &mmdevice->lock;
1263 internal_index = mmdevice->index;
1266 EnterCriticalSection(lock);
1268 device = WINMM_FindUnusedDevice(devices, mmdevice,
1269 internal_index, TRUE);
1271 LeaveCriticalSection(lock);
1272 return MMSYSERR_ALLOCATED;
1275 LeaveCriticalSection(lock);
1278 ret = WINMM_OpenDevice(device, info, TRUE);
1279 if((info->flags & WAVE_FORMAT_QUERY) || ret != MMSYSERR_NOERROR)
1281 ret = MMSYSERR_ERROR;
1283 hr = IAudioClient_GetService(device->client, &IID_IAudioRenderClient,
1284 (void**)&device->render);
1286 ERR("GetService failed: %08x\n", hr);
1290 hr = IAudioClient_GetService(device->client, &IID_IAudioStreamVolume,
1291 (void**)&device->volume);
1293 ERR("GetService failed: %08x\n", hr);
1297 LeaveCriticalSection(&device->lock);
1299 return MMSYSERR_NOERROR;
1303 IMMDevice_Release(device->device);
1304 device->device = NULL;
1307 IAudioClient_Release(device->client);
1308 device->client = NULL;
1311 IAudioRenderClient_Release(device->render);
1312 device->render = NULL;
1315 IAudioStreamVolume_Release(device->volume);
1316 device->volume = NULL;
1319 IAudioClock_Release(device->clock);
1320 device->clock = NULL;
1322 device->open = FALSE;
1323 LeaveCriticalSection(&device->lock);
1327 static LRESULT WID_Open(WINMM_OpenInfo *info)
1329 WINMM_Device *device, **devices;
1330 WINMM_MMDevice *mmdevice;
1331 UINT internal_index;
1332 CRITICAL_SECTION *lock;
1333 LRESULT ret = MMSYSERR_ERROR;
1336 if(WINMM_IsMapper(info->req_device)){
1337 devices = g_in_mapper_devices;
1338 mmdevice = read_map(g_in_map, 0);
1339 lock = &g_devthread_lock;
1340 internal_index = MAPPER_INDEX;
1342 if(info->req_device >= g_inmmdevices_count)
1343 return MMSYSERR_BADDEVICEID;
1345 mmdevice = read_map(g_in_map, info->req_device);
1347 if(!mmdevice->in_caps.szPname[0])
1348 return MMSYSERR_NOTENABLED;
1350 devices = mmdevice->devices;
1351 lock = &mmdevice->lock;
1352 internal_index = mmdevice->index;
1355 EnterCriticalSection(lock);
1357 device = WINMM_FindUnusedDevice(devices, mmdevice, internal_index, FALSE);
1359 LeaveCriticalSection(lock);
1360 return MMSYSERR_ALLOCATED;
1363 LeaveCriticalSection(lock);
1365 ret = WINMM_OpenDevice(device, info, FALSE);
1366 if((info->flags & WAVE_FORMAT_QUERY) || ret != MMSYSERR_NOERROR)
1368 ret = MMSYSERR_ERROR;
1370 hr = IAudioClient_GetService(device->client, &IID_IAudioCaptureClient,
1371 (void**)&device->capture);
1373 WARN("GetService failed: %08x\n", hr);
1377 LeaveCriticalSection(&device->lock);
1379 return MMSYSERR_NOERROR;
1383 IMMDevice_Release(device->device);
1384 device->device = NULL;
1387 IAudioClient_Release(device->client);
1388 device->client = NULL;
1390 if(device->capture){
1391 IAudioCaptureClient_Release(device->capture);
1392 device->capture = NULL;
1395 IAudioClock_Release(device->clock);
1396 device->clock = NULL;
1398 device->open = FALSE;
1399 LeaveCriticalSection(&device->lock);
1403 static HRESULT WINMM_CloseDevice(WINMM_Device *device)
1405 device->open = FALSE;
1407 if(!device->stopped){
1408 IAudioClient_Stop(device->client);
1409 device->stopped = TRUE;
1412 if(device->acm_handle){
1413 acmStreamClose(device->acm_handle, 0);
1414 device->acm_handle = NULL;
1417 IMMDevice_Release(device->device);
1418 device->device = NULL;
1420 IAudioClient_Release(device->client);
1421 device->client = NULL;
1423 IAudioClock_Release(device->clock);
1424 device->clock = NULL;
1429 static LRESULT WOD_Close(HWAVEOUT hwave)
1431 WINMM_Device *device = WINMM_GetDeviceFromHWAVE((HWAVE)hwave);
1433 TRACE("(%p)\n", hwave);
1435 if(!WINMM_ValidateAndLock(device))
1436 return MMSYSERR_INVALHANDLE;
1438 WINMM_CloseDevice(device);
1440 IAudioRenderClient_Release(device->render);
1441 device->render = NULL;
1443 IAudioStreamVolume_Release(device->volume);
1444 device->volume = NULL;
1446 LeaveCriticalSection(&device->lock);
1448 return MMSYSERR_NOERROR;
1451 static LRESULT WID_Close(HWAVEIN hwave)
1453 WINMM_Device *device = WINMM_GetDeviceFromHWAVE((HWAVE)hwave);
1455 TRACE("(%p)\n", hwave);
1457 if(!WINMM_ValidateAndLock(device))
1458 return MMSYSERR_INVALHANDLE;
1460 WINMM_CloseDevice(device);
1462 IAudioCaptureClient_Release(device->capture);
1463 device->capture = NULL;
1465 LeaveCriticalSection(&device->lock);
1467 return MMSYSERR_NOERROR;
1470 static LRESULT WINMM_PrepareHeader(HWAVE hwave, WAVEHDR *header)
1472 WINMM_Device *device = WINMM_GetDeviceFromHWAVE(hwave);
1474 TRACE("(%p, %p)\n", hwave, header);
1476 if(!WINMM_ValidateAndLock(device))
1477 return MMSYSERR_INVALHANDLE;
1479 if(device->render && device->acm_handle){
1480 ACMSTREAMHEADER *ash;
1484 mr = acmStreamSize(device->acm_handle, header->dwBufferLength, &size,
1485 ACM_STREAMSIZEF_SOURCE);
1486 if(mr != MMSYSERR_NOERROR){
1487 LeaveCriticalSection(&device->lock);
1491 ash = HeapAlloc(GetProcessHeap(), 0, sizeof(ACMSTREAMHEADER) + size);
1493 LeaveCriticalSection(&device->lock);
1494 return MMSYSERR_NOMEM;
1497 ash->cbStruct = sizeof(*ash);
1499 ash->dwUser = (DWORD_PTR)header;
1500 ash->pbSrc = (BYTE*)header->lpData;
1501 ash->cbSrcLength = header->dwBufferLength;
1502 ash->dwSrcUser = header->dwUser;
1503 ash->pbDst = (BYTE*)ash + sizeof(ACMSTREAMHEADER);
1504 ash->cbDstLength = size;
1507 mr = acmStreamPrepareHeader(device->acm_handle, ash, 0);
1508 if(mr != MMSYSERR_NOERROR){
1509 HeapFree(GetProcessHeap(), 0, ash);
1510 LeaveCriticalSection(&device->lock);
1514 header->reserved = (DWORD_PTR)ash;
1517 LeaveCriticalSection(&device->lock);
1519 header->dwFlags |= WHDR_PREPARED;
1520 header->dwFlags &= ~WHDR_DONE;
1522 return MMSYSERR_NOERROR;
1525 static LRESULT WINMM_UnprepareHeader(HWAVE hwave, WAVEHDR *header)
1527 WINMM_Device *device = WINMM_GetDeviceFromHWAVE(hwave);
1529 TRACE("(%p, %p)\n", hwave, header);
1531 if(!WINMM_ValidateAndLock(device))
1532 return MMSYSERR_INVALHANDLE;
1534 if(device->render && device->acm_handle){
1535 ACMSTREAMHEADER *ash = (ACMSTREAMHEADER*)header->reserved;
1537 acmStreamUnprepareHeader(device->acm_handle, ash, 0);
1539 HeapFree(GetProcessHeap(), 0, ash);
1542 LeaveCriticalSection(&device->lock);
1544 header->dwFlags &= ~WHDR_PREPARED;
1545 header->dwFlags |= WHDR_DONE;
1547 return MMSYSERR_NOERROR;
1550 static UINT32 WINMM_HeaderLenBytes(WINMM_Device *device, WAVEHDR *header)
1552 if(device->acm_handle){
1553 ACMSTREAMHEADER *ash = (ACMSTREAMHEADER*)header->reserved;
1554 return ash->cbDstLengthUsed;
1557 return header->dwBufferLength;
1560 static UINT32 WINMM_HeaderLenFrames(WINMM_Device *device, WAVEHDR *header)
1562 return WINMM_HeaderLenBytes(device, header) / device->bytes_per_frame;
1565 static WAVEHDR *WOD_MarkDoneHeaders(WINMM_Device *device)
1568 WAVEHDR *first = device->first, *queue = first, *last = NULL;
1569 UINT64 clock_freq, clock_pos, clock_frames;
1570 UINT32 nloops, queue_frames = 0;
1572 hr = IAudioClock_GetFrequency(device->clock, &clock_freq);
1574 WARN("GetFrequency failed: %08x\n", hr);
1578 hr = IAudioClock_GetPosition(device->clock, &clock_pos, NULL);
1580 WARN("GetPosition failed: %08x\n", hr);
1584 clock_frames = (clock_pos * device->samples_per_sec) / clock_freq;
1586 nloops = device->loop_counter;
1588 (queue_frames += WINMM_HeaderLenFrames(device, queue)) <=
1589 clock_frames - device->last_clock_pos + device->remainder_frames){
1592 device->last_clock_pos += queue_frames;
1593 device->remainder_frames = 0;
1595 queue = device->first = queue->lpNext;
1597 if(queue->dwFlags & WHDR_BEGINLOOP){
1598 if(queue->dwFlags & WHDR_ENDLOOP)
1601 queue = queue->lpNext;
1602 }else if(queue->dwFlags & WHDR_ENDLOOP){
1603 queue = device->loop_start;
1610 last->lpNext = NULL;
1616 static void WOD_PushData(WINMM_Device *device)
1618 WINMM_CBInfo cb_info;
1620 UINT32 pad, bufsize, avail_frames, queue_frames, written, ofs;
1621 UINT32 queue_bytes, nloops;
1623 WAVEHDR *queue, *first = NULL;
1625 TRACE("(%p)\n", device->handle);
1627 EnterCriticalSection(&device->lock);
1633 if (device->stopped)
1635 device->stopped = TRUE;
1636 device->last_clock_pos = 0;
1637 IAudioClient_Stop(device->client);
1638 IAudioClient_Reset(device->client);
1642 hr = IAudioClient_GetBufferSize(device->client, &bufsize);
1644 WARN("GetBufferSize failed: %08x\n", hr);
1648 hr = IAudioClient_GetCurrentPadding(device->client, &pad);
1650 WARN("GetCurrentPadding failed: %08x\n", hr);
1654 first = WOD_MarkDoneHeaders(device);
1656 /* determine which is larger between the available buffer size and
1657 * the amount of data left in the queue */
1658 avail_frames = bufsize - pad;
1660 queue = device->playing;
1661 ofs = device->ofs_bytes;
1664 while(queue && queue_frames < avail_frames){
1665 queue_bytes = WINMM_HeaderLenBytes(device, queue);
1666 queue_frames += (queue_bytes - ofs) / device->bytes_per_frame;
1669 if(queue->dwFlags & WHDR_ENDLOOP && nloops < device->loop_counter){
1670 queue = device->loop_start;
1673 queue = queue->lpNext;
1676 if(queue_frames < avail_frames)
1677 avail_frames = queue_frames;
1678 if(avail_frames == 0)
1681 hr = IAudioRenderClient_GetBuffer(device->render, avail_frames, &data);
1683 WARN("GetBuffer failed: %08x\n", hr);
1688 while(device->playing && written < avail_frames){
1689 UINT32 copy_frames, copy_bytes;
1692 queue = device->playing;
1694 if(device->acm_handle){
1695 ACMSTREAMHEADER *ash = (ACMSTREAMHEADER*)queue->reserved;
1696 queue_bytes = ash->cbDstLengthUsed;
1697 queue_data = ash->pbDst;
1699 queue_bytes = queue->dwBufferLength;
1700 queue_data = (BYTE*)queue->lpData;
1703 queue_frames = (queue_bytes - device->ofs_bytes) /
1704 device->bytes_per_frame;
1706 copy_frames = queue_frames < (avail_frames - written) ?
1707 queue_frames : avail_frames - written;
1708 copy_bytes = copy_frames * device->bytes_per_frame;
1710 memcpy(data, queue_data + device->ofs_bytes, copy_bytes);
1713 written += copy_frames;
1714 device->ofs_bytes += copy_bytes;
1716 if(device->ofs_bytes >= queue_bytes){
1717 device->ofs_bytes = 0;
1719 if(!(queue->dwFlags & (WHDR_BEGINLOOP | WHDR_ENDLOOP)))
1720 device->playing = queue->lpNext;
1722 if(queue->dwFlags & WHDR_BEGINLOOP){
1723 device->loop_start = device->playing;
1724 device->playing = queue->lpNext;
1725 device->loop_counter = queue->dwLoops;
1727 if(queue->dwFlags & WHDR_ENDLOOP){
1728 --device->loop_counter;
1729 if(device->loop_counter)
1730 device->playing = device->loop_start;
1732 device->loop_start = device->playing = queue->lpNext;
1738 hr = IAudioRenderClient_ReleaseBuffer(device->render, avail_frames, 0);
1740 WARN("ReleaseBuffer failed: %08x\n", hr);
1744 if(device->orig_fmt->nSamplesPerSec != device->samples_per_sec)
1745 device->played_frames += MulDiv(avail_frames, device->orig_fmt->nSamplesPerSec, device->samples_per_sec);
1747 device->played_frames += avail_frames;
1750 cb_info = device->cb_info;
1752 LeaveCriticalSection(&device->lock);
1755 WAVEHDR *next = first->lpNext;
1756 first->dwFlags &= ~WHDR_INQUEUE;
1757 first->dwFlags |= WHDR_DONE;
1758 WINMM_NotifyClient(&cb_info, WOM_DONE, (DWORD_PTR)first, 0);
1763 static void WID_PullACMData(WINMM_Device *device)
1765 UINT32 packet, packet_bytes;
1772 if(device->acm_hdr.cbDstLength == 0){
1773 hr = IAudioCaptureClient_GetBuffer(device->capture, &data, &packet,
1774 &flags, NULL, NULL);
1777 WARN("GetBuffer failed: %08x\n", hr);
1781 acmStreamSize(device->acm_handle, packet * device->bytes_per_frame,
1782 &packet_bytes, ACM_STREAMSIZEF_SOURCE);
1784 device->acm_offs = 0;
1786 device->acm_hdr.cbStruct = sizeof(device->acm_hdr);
1787 device->acm_hdr.fdwStatus = 0;
1788 device->acm_hdr.dwUser = 0;
1789 device->acm_hdr.pbSrc = data;
1790 device->acm_hdr.cbSrcLength = packet * device->bytes_per_frame;
1791 device->acm_hdr.cbSrcLengthUsed = 0;
1792 device->acm_hdr.dwSrcUser = 0;
1793 device->acm_hdr.pbDst = HeapAlloc(GetProcessHeap(), 0, packet_bytes);
1794 device->acm_hdr.cbDstLength = packet_bytes;
1795 device->acm_hdr.cbDstLengthUsed = 0;
1796 device->acm_hdr.dwDstUser = 0;
1798 mr = acmStreamPrepareHeader(device->acm_handle, &device->acm_hdr, 0);
1799 if(mr != MMSYSERR_NOERROR){
1800 WARN("acmStreamPrepareHeader failed: %d\n", mr);
1804 mr = acmStreamConvert(device->acm_handle, &device->acm_hdr, 0);
1805 if(mr != MMSYSERR_NOERROR){
1806 WARN("acmStreamConvert failed: %d\n", mr);
1810 hr = IAudioCaptureClient_ReleaseBuffer(device->capture, packet);
1812 WARN("ReleaseBuffer failed: %08x\n", hr);
1814 device->played_frames += packet;
1817 queue = device->first;
1819 UINT32 to_copy_bytes;
1821 to_copy_bytes = min(queue->dwBufferLength - queue->dwBytesRecorded,
1822 device->acm_hdr.cbDstLengthUsed - device->acm_offs);
1824 memcpy(queue->lpData + queue->dwBytesRecorded,
1825 device->acm_hdr.pbDst + device->acm_offs, to_copy_bytes);
1827 queue->dwBytesRecorded += to_copy_bytes;
1828 device->acm_offs += to_copy_bytes;
1830 if(queue->dwBufferLength - queue->dwBytesRecorded <
1831 device->bytes_per_frame){
1832 queue->dwFlags &= ~WHDR_INQUEUE;
1833 queue->dwFlags |= WHDR_DONE;
1834 device->first = queue = queue->lpNext;
1837 if(device->acm_offs >= device->acm_hdr.cbDstLengthUsed){
1838 acmStreamUnprepareHeader(device->acm_handle, &device->acm_hdr, 0);
1839 HeapFree(GetProcessHeap(), 0, device->acm_hdr.pbDst);
1840 device->acm_hdr.cbDstLength = 0;
1841 device->acm_hdr.cbDstLengthUsed = 0;
1843 /* done with this ACM Header, so try to pull more data */
1844 WID_PullACMData(device);
1849 /* out of WAVEHDRs to write into, so toss the rest of this packet */
1850 acmStreamUnprepareHeader(device->acm_handle, &device->acm_hdr, 0);
1851 HeapFree(GetProcessHeap(), 0, device->acm_hdr.pbDst);
1852 device->acm_hdr.cbDstLength = 0;
1853 device->acm_hdr.cbDstLengthUsed = 0;
1856 static void WID_PullData(WINMM_Device *device)
1858 WINMM_CBInfo cb_info;
1859 WAVEHDR *queue, *first = NULL, *last = NULL;
1862 TRACE("(%p)\n", device->handle);
1864 EnterCriticalSection(&device->lock);
1866 if(!device->device || !device->first)
1869 first = device->first;
1871 if(device->acm_handle){
1872 WID_PullACMData(device);
1876 while(device->first){
1878 UINT32 packet_len, packet;
1881 hr = IAudioCaptureClient_GetBuffer(device->capture, &data, &packet_len,
1882 &flags, NULL, NULL);
1885 WARN("GetBuffer failed: %08x\n", hr);
1886 else /* AUDCLNT_S_BUFFER_EMPTY success code */
1887 IAudioCaptureClient_ReleaseBuffer(device->capture, 0);
1891 packet = packet_len;
1892 queue = device->first;
1893 while(queue && packet > 0){
1894 UINT32 to_copy_bytes;
1896 to_copy_bytes = min(packet * device->bytes_per_frame,
1897 queue->dwBufferLength - queue->dwBytesRecorded);
1899 memcpy(queue->lpData + queue->dwBytesRecorded,
1900 data + (packet_len - packet) * device->bytes_per_frame,
1903 queue->dwBytesRecorded += to_copy_bytes;
1905 if(queue->dwBufferLength - queue->dwBytesRecorded <
1906 device->bytes_per_frame){
1908 device->first = queue = queue->lpNext;
1911 packet -= to_copy_bytes / device->bytes_per_frame;
1914 hr = IAudioCaptureClient_ReleaseBuffer(device->capture, packet_len);
1916 WARN("ReleaseBuffer failed: %08x\n", hr);
1919 WARN("losing %u frames\n", packet);
1920 device->played_frames += packet_len;
1924 cb_info = device->cb_info;
1926 LeaveCriticalSection(&device->lock);
1929 last->lpNext = NULL;
1931 WAVEHDR *next = first->lpNext;
1932 first->dwFlags &= ~WHDR_INQUEUE;
1933 first->dwFlags |= WHDR_DONE;
1934 WINMM_NotifyClient(&cb_info, WIM_DATA, (DWORD_PTR)first, 0);
1940 static MMRESULT WINMM_BeginPlaying(WINMM_Device *device)
1944 TRACE("(%p)\n", device->handle);
1947 /* prebuffer data before starting */
1948 WOD_PushData(device);
1950 if(device->stopped){
1951 device->stopped = FALSE;
1953 hr = IAudioClient_Start(device->client);
1954 if(FAILED(hr) && hr != AUDCLNT_E_NOT_STOPPED){
1955 device->stopped = TRUE;
1956 WARN("Start failed: %08x\n", hr);
1957 return MMSYSERR_ERROR;
1961 return MMSYSERR_NOERROR;
1964 static LRESULT WINMM_Pause(HWAVE hwave)
1966 WINMM_Device *device = WINMM_GetDeviceFromHWAVE(hwave);
1969 TRACE("(%p)\n", hwave);
1971 if(!WINMM_ValidateAndLock(device))
1972 return MMSYSERR_INVALHANDLE;
1974 hr = IAudioClient_Stop(device->client);
1976 LeaveCriticalSection(&device->lock);
1977 WARN("Stop failed: %08x\n", hr);
1978 return MMSYSERR_ERROR;
1981 device->stopped = FALSE;
1983 LeaveCriticalSection(&device->lock);
1985 return MMSYSERR_NOERROR;
1988 static LRESULT WINMM_Reset(HWAVE hwave)
1990 WINMM_CBInfo cb_info;
1991 WINMM_Device *device = WINMM_GetDeviceFromHWAVE(hwave);
1996 TRACE("(%p)\n", hwave);
1998 if(!WINMM_ValidateAndLock(device))
1999 return MMSYSERR_INVALHANDLE;
2001 hr = IAudioClient_Stop(device->client);
2003 LeaveCriticalSection(&device->lock);
2004 WARN("Stop failed: %08x\n", hr);
2005 return MMSYSERR_ERROR;
2007 device->stopped = TRUE;
2009 first = device->first;
2010 device->first = device->last = device->playing = NULL;
2011 device->ofs_bytes = 0;
2012 device->played_frames = 0;
2013 device->loop_counter = 0;
2014 device->last_clock_pos = 0;
2015 IAudioClient_Reset(device->client);
2017 cb_info = device->cb_info;
2018 is_out = device->render != NULL;
2020 LeaveCriticalSection(&device->lock);
2023 WAVEHDR *next = first->lpNext;
2024 first->dwFlags &= ~WHDR_INQUEUE;
2025 first->dwFlags |= WHDR_DONE;
2027 WINMM_NotifyClient(&cb_info, WOM_DONE, (DWORD_PTR)first, 0);
2029 WINMM_NotifyClient(&cb_info, WIM_DATA, (DWORD_PTR)first, 0);
2033 return MMSYSERR_NOERROR;
2036 static MMRESULT WINMM_FramesToMMTime(MMTIME *time, UINT32 played_frames,
2037 UINT32 sample_rate, UINT32 bytes_per_frame)
2039 switch(time->wType){
2041 time->u.sample = played_frames;
2042 return MMSYSERR_NOERROR;
2044 time->u.ms = (UINT64)played_frames * 1000 / sample_rate;
2045 return MMSYSERR_NOERROR;
2047 time->u.smpte.fps = 30;
2048 played_frames += sample_rate / time->u.smpte.fps - 1; /* round up */
2049 time->u.smpte.frame = (played_frames % sample_rate) * time->u.smpte.fps / sample_rate;
2050 played_frames /= sample_rate; /* yields seconds */
2051 time->u.smpte.sec = played_frames % 60;
2052 played_frames /= 60;
2053 time->u.smpte.min = played_frames % 60;
2054 time->u.smpte.hour= played_frames / 60;
2055 return MMSYSERR_NOERROR;
2057 time->wType = TIME_BYTES;
2060 time->u.cb = played_frames * bytes_per_frame;
2061 return MMSYSERR_NOERROR;
2065 static LRESULT WINMM_GetPosition(HWAVE hwave, MMTIME *time)
2067 WINMM_Device *device = WINMM_GetDeviceFromHWAVE(hwave);
2068 UINT32 played_frames, sample_rate, bytes_per_frame;
2070 TRACE("(%p, %p)\n", hwave, time);
2072 if(!WINMM_ValidateAndLock(device))
2073 return MMSYSERR_INVALHANDLE;
2075 played_frames = device->played_frames;
2076 sample_rate = device->orig_fmt->nSamplesPerSec;
2077 bytes_per_frame = device->orig_fmt->nBlockAlign;
2079 LeaveCriticalSection(&device->lock);
2081 return WINMM_FramesToMMTime(time, played_frames, sample_rate,
2085 static WINMM_MMDevice *WINMM_GetMixerMMDevice(HMIXEROBJ hmix, DWORD flags,
2088 UINT mmdev, dev, junk, *out;
2096 switch(flags & 0xF0000000){
2097 case MIXER_OBJECTF_MIXER: /* == 0 */
2098 *out = HandleToULong(hmix);
2099 if(*out < g_outmmdevices_count)
2100 return read_map(g_out_map, *out);
2101 if(*out - g_outmmdevices_count < g_inmmdevices_count){
2102 *out -= g_outmmdevices_count;
2103 return read_map(g_in_map, *out);
2105 /* fall through -- if it's not a valid mixer device, then
2106 * it could be a valid mixer handle. windows seems to do
2108 case MIXER_OBJECTF_HMIXER:
2109 case MIXER_OBJECTF_HWAVEOUT:
2110 case MIXER_OBJECTF_HWAVEIN:
2111 WINMM_DecomposeHWAVE((HWAVE)hmix, out, &is_out, &dev, &junk);
2112 if(junk != 0x1 || (is_out && *out >= g_outmmdevices_count) ||
2113 (!is_out && *out >= g_inmmdevices_count))
2116 return read_map(g_out_map, *out);
2117 return read_map(g_in_map, *out);
2118 case MIXER_OBJECTF_WAVEOUT:
2119 *out = HandleToULong(hmix);
2120 if(*out < g_outmmdevices_count)
2121 return read_map(g_out_map, *out);
2123 case MIXER_OBJECTF_WAVEIN:
2124 *out = HandleToULong(hmix);
2125 if(*out < g_inmmdevices_count)
2126 return read_map(g_in_map, *out);
2133 static MMRESULT WINMM_SetupMMDeviceVolume(WINMM_MMDevice *mmdevice)
2135 IAudioSessionManager *sesman;
2139 hr = IMMDeviceEnumerator_GetDevice(g_devenum, mmdevice->dev_id, &device);
2141 WARN("Device %s (%s) unavailable: %08x\n",
2142 wine_dbgstr_w(mmdevice->dev_id),
2143 wine_dbgstr_w(mmdevice->out_caps.szPname), hr);
2144 return MMSYSERR_ERROR;
2147 hr = IMMDevice_Activate(device, &IID_IAudioSessionManager,
2148 CLSCTX_INPROC_SERVER, NULL, (void**)&sesman);
2150 WARN("Activate failed: %08x\n", hr);
2151 IMMDevice_Release(device);
2152 return MMSYSERR_ERROR;
2155 IMMDevice_Release(device);
2157 hr = IAudioSessionManager_GetSimpleAudioVolume(sesman, &mmdevice->session,
2158 FALSE, &mmdevice->volume);
2159 IAudioSessionManager_Release(sesman);
2161 WARN("GetSimpleAudioVolume failed: %08x\n", hr);
2162 return MMSYSERR_ERROR;
2165 return MMSYSERR_NOERROR;
2168 static LRESULT MXD_GetControlDetails(WINMM_ControlDetails *details)
2170 WINMM_MMDevice *mmdevice;
2171 MIXERCONTROLDETAILS *control = details->details;
2174 TRACE("(%p)\n", details->hmix);
2176 mmdevice = WINMM_GetMixerMMDevice(details->hmix, details->flags, NULL);
2178 return MMSYSERR_INVALHANDLE;
2180 EnterCriticalSection(&mmdevice->lock);
2182 if(!mmdevice->volume){
2185 mr = WINMM_SetupMMDeviceVolume(mmdevice);
2186 if(mr != MMSYSERR_NOERROR){
2187 LeaveCriticalSection(&mmdevice->lock);
2192 if(control->dwControlID == 0){
2194 MIXERCONTROLDETAILS_UNSIGNED *udet;
2196 if(!control->paDetails ||
2197 control->cbDetails < sizeof(MIXERCONTROLDETAILS_UNSIGNED)){
2198 LeaveCriticalSection(&mmdevice->lock);
2199 return MMSYSERR_INVALPARAM;
2202 hr = ISimpleAudioVolume_GetMasterVolume(mmdevice->volume, &vol);
2204 WARN("GetMasterVolume failed: %08x\n", hr);
2205 LeaveCriticalSection(&mmdevice->lock);
2206 return MMSYSERR_ERROR;
2209 udet = (MIXERCONTROLDETAILS_UNSIGNED*)control->paDetails;
2210 udet->dwValue = vol * ((unsigned int)0xFFFF);
2211 }else if(control->dwControlID == 1){
2213 MIXERCONTROLDETAILS_BOOLEAN *bdet;
2215 if(!control->paDetails ||
2216 control->cbDetails < sizeof(MIXERCONTROLDETAILS_BOOLEAN)){
2217 LeaveCriticalSection(&mmdevice->lock);
2218 return MMSYSERR_INVALPARAM;
2221 hr = ISimpleAudioVolume_GetMute(mmdevice->volume, &mute);
2223 WARN("GetMute failed: %08x\n", hr);
2224 LeaveCriticalSection(&mmdevice->lock);
2225 return MMSYSERR_ERROR;
2228 bdet = (MIXERCONTROLDETAILS_BOOLEAN*)control->paDetails;
2229 bdet->fValue = mute;
2230 }else if(control->dwControlID == 2 || control->dwControlID == 3){
2231 FIXME("What should the sw-side mixer controls map to?\n");
2233 LeaveCriticalSection(&mmdevice->lock);
2234 return MIXERR_INVALCONTROL;
2237 LeaveCriticalSection(&mmdevice->lock);
2239 return MMSYSERR_NOERROR;
2242 static LRESULT MXD_SetControlDetails(WINMM_ControlDetails *details)
2244 WINMM_MMDevice *mmdevice;
2245 MIXERCONTROLDETAILS *control = details->details;
2248 TRACE("(%p)\n", details->hmix);
2250 mmdevice = WINMM_GetMixerMMDevice(details->hmix, details->flags, NULL);
2252 return MMSYSERR_INVALHANDLE;
2254 EnterCriticalSection(&mmdevice->lock);
2256 if(!mmdevice->volume){
2259 mr = WINMM_SetupMMDeviceVolume(mmdevice);
2260 if(mr != MMSYSERR_NOERROR){
2261 LeaveCriticalSection(&mmdevice->lock);
2266 if(control->dwControlID == 0){
2268 MIXERCONTROLDETAILS_UNSIGNED *udet;
2270 if(!control->paDetails ||
2271 control->cbDetails < sizeof(MIXERCONTROLDETAILS_UNSIGNED)){
2272 LeaveCriticalSection(&mmdevice->lock);
2273 return MMSYSERR_INVALPARAM;
2276 udet = (MIXERCONTROLDETAILS_UNSIGNED*)control->paDetails;
2278 if(udet->dwValue > 65535){
2279 LeaveCriticalSection(&mmdevice->lock);
2280 return MMSYSERR_INVALPARAM;
2283 vol = udet->dwValue / 65535.f;
2285 hr = ISimpleAudioVolume_SetMasterVolume(mmdevice->volume, vol, NULL);
2287 WARN("SetMasterVolume failed: %08x\n", hr);
2288 LeaveCriticalSection(&mmdevice->lock);
2289 return MMSYSERR_ERROR;
2291 }else if(control->dwControlID == 1){
2293 MIXERCONTROLDETAILS_BOOLEAN *bdet;
2295 if(!control->paDetails ||
2296 control->cbDetails < sizeof(MIXERCONTROLDETAILS_BOOLEAN)){
2297 LeaveCriticalSection(&mmdevice->lock);
2298 return MMSYSERR_INVALPARAM;
2301 bdet = (MIXERCONTROLDETAILS_BOOLEAN*)control->paDetails;
2302 mute = bdet->fValue;
2304 hr = ISimpleAudioVolume_SetMute(mmdevice->volume, mute, NULL);
2306 WARN("SetMute failed: %08x\n", hr);
2307 LeaveCriticalSection(&mmdevice->lock);
2308 return MMSYSERR_ERROR;
2310 }else if(control->dwControlID == 2 || control->dwControlID == 3){
2311 FIXME("What should the sw-side mixer controls map to?\n");
2313 LeaveCriticalSection(&mmdevice->lock);
2314 return MIXERR_INVALCONTROL;
2317 LeaveCriticalSection(&mmdevice->lock);
2319 return MMSYSERR_NOERROR;
2322 static LRESULT DRV_QueryDeviceInterface(WINMM_QueryInterfaceInfo *info)
2324 WINMM_MMDevice *mmdevice;
2331 static const PROPERTYKEY deviceinterface_key = {
2332 {0x233164c8, 0x1b2c, 0x4c7d, {0xbc, 0x68, 0xb6, 0x71, 0x68, 0x7a, 0x25, 0x67}}, 1
2335 if(WINMM_IsMapper(info->index)){
2337 if(*info->len_bytes < sizeof(WCHAR))
2338 return MMSYSERR_INVALPARAM;
2341 *info->len_bytes = sizeof(WCHAR);
2342 return MMSYSERR_NOERROR;
2346 if(info->index >= g_outmmdevices_count)
2347 return MMSYSERR_INVALHANDLE;
2349 mmdevice = &g_out_mmdevices[info->index];
2351 if(info->index >= g_inmmdevices_count)
2352 return MMSYSERR_INVALHANDLE;
2354 mmdevice = &g_in_mmdevices[info->index];
2357 hr = IMMDeviceEnumerator_GetDevice(g_devenum, mmdevice->dev_id,
2360 WARN("Device %s unavailable: %08x\n", wine_dbgstr_w(mmdevice->dev_id), hr);
2361 return MMSYSERR_ERROR;
2364 hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
2366 WARN("OpenPropertyStore failed: %08x\n", hr);
2367 IMMDevice_Release(device);
2368 return MMSYSERR_ERROR;
2371 PropVariantInit(&pv);
2372 hr = IPropertyStore_GetValue(ps, &deviceinterface_key, &pv);
2374 WARN("GetValue failed: %08x\n", hr);
2375 IPropertyStore_Release(ps);
2376 IMMDevice_Release(device);
2377 return MMSYSERR_ERROR;
2379 if(pv.vt != VT_LPWSTR){
2380 WARN("Got unexpected property type: %u\n", pv.vt);
2381 PropVariantClear(&pv);
2382 IPropertyStore_Release(ps);
2383 IMMDevice_Release(device);
2384 return MMSYSERR_ERROR;
2387 len_bytes = (lstrlenW(pv.u.pwszVal) + 1) * sizeof(WCHAR);
2390 if(len_bytes > *info->len_bytes){
2391 PropVariantClear(&pv);
2392 IPropertyStore_Release(ps);
2393 IMMDevice_Release(device);
2394 return MMSYSERR_INVALPARAM;
2397 memcpy(info->str, pv.u.pwszVal, len_bytes);
2399 *info->len_bytes = len_bytes;
2401 PropVariantClear(&pv);
2402 IPropertyStore_Release(ps);
2403 IMMDevice_Release(device);
2405 return MMSYSERR_NOERROR;
2408 static LRESULT CALLBACK WINMM_DevicesMsgProc(HWND hwnd, UINT msg, WPARAM wparam,
2413 return WOD_Open((WINMM_OpenInfo*)wparam);
2415 return WOD_Close((HWAVEOUT)wparam);
2417 return WID_Open((WINMM_OpenInfo*)wparam);
2419 return WID_Close((HWAVEIN)wparam);
2420 case MXDM_GETCONTROLDETAILS:
2421 return MXD_GetControlDetails((WINMM_ControlDetails*)wparam);
2422 case MXDM_SETCONTROLDETAILS:
2423 return MXD_SetControlDetails((WINMM_ControlDetails*)wparam);
2424 case DRV_QUERYDEVICEINTERFACESIZE:
2425 case DRV_QUERYDEVICEINTERFACE:
2426 return DRV_QueryDeviceInterface((WINMM_QueryInterfaceInfo*)wparam);
2428 TRACE("QUIT message received\n");
2429 DestroyWindow(g_devices_hwnd);
2430 g_devices_hwnd = NULL;
2431 IMMDeviceEnumerator_Release(g_devenum);
2435 return DefWindowProcW(hwnd, msg, wparam, lparam);
2438 static DWORD WINAPI WINMM_DevicesThreadProc(void *arg)
2442 static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0};
2444 hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
2446 WARN("CoInitializeEx failed: %08x\n", hr);
2450 hr = WINMM_InitMMDevices();
2456 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
2457 CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&g_devenum);
2459 WARN("CoCreateInstance failed: %08x\n", hr);
2464 g_devices_hwnd = CreateWindowW(messageW, NULL, 0, 0, 0, 0, 0,
2465 HWND_MESSAGE, NULL, NULL, NULL);
2466 if(!g_devices_hwnd){
2467 WARN("CreateWindow failed: %d\n", GetLastError());
2468 IMMDeviceEnumerator_Release(g_devenum);
2473 SetWindowLongPtrW(g_devices_hwnd, GWLP_WNDPROC,
2474 (LONG_PTR)WINMM_DevicesMsgProc);
2476 /* inform caller that the thread is ready to process messages */
2478 evt = NULL; /* do not use after this point */
2482 wait = MsgWaitForMultipleObjects(g_devhandle_count, g_device_handles,
2483 FALSE, INFINITE, QS_ALLINPUT);
2484 if(wait == g_devhandle_count + WAIT_OBJECT_0){
2486 if(PeekMessageW(&msg, g_devices_hwnd, 0, 0, PM_REMOVE))
2487 WARN("Unexpected message: 0x%x\n", msg.message);
2490 }else if(wait < g_devhandle_count + WAIT_OBJECT_0){
2491 WINMM_Device *device = g_handle_devices[wait - WAIT_OBJECT_0];
2493 WOD_PushData(device);
2495 WID_PullData(device);
2497 WARN("Unexpected MsgWait result 0x%x, GLE: %d\n", wait,
2504 static BOOL WINMM_StartDevicesThread(void)
2509 EnterCriticalSection(&g_devthread_lock);
2511 if(g_devices_thread){
2514 wait = WaitForSingleObject(g_devices_thread, 0);
2515 if(wait == WAIT_TIMEOUT){
2516 LeaveCriticalSection(&g_devthread_lock);
2519 if(wait != WAIT_OBJECT_0){
2520 LeaveCriticalSection(&g_devthread_lock);
2524 g_devices_thread = NULL;
2525 g_devices_hwnd = NULL;
2528 TRACE("Starting up devices thread\n");
2530 events[0] = CreateEventW(NULL, FALSE, FALSE, NULL);
2532 g_devices_thread = CreateThread(NULL, 0, WINMM_DevicesThreadProc,
2533 events[0], 0, NULL);
2534 if(!g_devices_thread){
2535 LeaveCriticalSection(&g_devthread_lock);
2536 CloseHandle(events[0]);
2540 events[1] = g_devices_thread;
2541 wait = WaitForMultipleObjects(2, events, FALSE, INFINITE);
2542 CloseHandle(events[0]);
2543 if(wait != WAIT_OBJECT_0){
2544 if(wait == 1 + WAIT_OBJECT_0){
2545 CloseHandle(g_devices_thread);
2546 g_devices_thread = NULL;
2547 g_devices_hwnd = NULL;
2549 LeaveCriticalSection(&g_devthread_lock);
2553 LeaveCriticalSection(&g_devthread_lock);
2558 /**************************************************************************
2559 * waveOutGetNumDevs [WINMM.@]
2561 UINT WINAPI waveOutGetNumDevs(void)
2563 HRESULT hr = WINMM_InitMMDevices();
2567 TRACE("count: %u\n", g_outmmdevices_count);
2569 return g_outmmdevices_count;
2572 /**************************************************************************
2573 * waveOutGetDevCapsA [WINMM.@]
2575 UINT WINAPI waveOutGetDevCapsA(UINT_PTR uDeviceID, LPWAVEOUTCAPSA lpCaps,
2581 TRACE("(%lu, %p, %u)\n", uDeviceID, lpCaps, uSize);
2584 return MMSYSERR_INVALPARAM;
2586 ret = waveOutGetDevCapsW(uDeviceID, &wocW, sizeof(wocW));
2588 if (ret == MMSYSERR_NOERROR) {
2590 wocA.wMid = wocW.wMid;
2591 wocA.wPid = wocW.wPid;
2592 wocA.vDriverVersion = wocW.vDriverVersion;
2593 WideCharToMultiByte( CP_ACP, 0, wocW.szPname, -1, wocA.szPname,
2594 sizeof(wocA.szPname), NULL, NULL );
2595 wocA.dwFormats = wocW.dwFormats;
2596 wocA.wChannels = wocW.wChannels;
2597 wocA.dwSupport = wocW.dwSupport;
2598 memcpy(lpCaps, &wocA, min(uSize, sizeof(wocA)));
2603 /**************************************************************************
2604 * waveOutGetDevCapsW [WINMM.@]
2606 UINT WINAPI waveOutGetDevCapsW(UINT_PTR uDeviceID, LPWAVEOUTCAPSW lpCaps,
2609 WAVEOUTCAPSW mapper_caps, *caps;
2612 TRACE("(%lu, %p, %u)\n", uDeviceID, lpCaps, uSize);
2614 hr = WINMM_InitMMDevices();
2616 return MMSYSERR_NODRIVER;
2618 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2620 if(WINMM_IsMapper(uDeviceID)){
2621 /* FIXME: Should be localized */
2622 static const WCHAR mapper_pnameW[] = {'W','i','n','e',' ','S','o','u',
2623 'n','d',' ','M','a','p','p','e','r',0};
2625 mapper_caps.wMid = 0xFF;
2626 mapper_caps.wPid = 0xFF;
2627 mapper_caps.vDriverVersion = 0x00010001;
2628 mapper_caps.dwFormats = 0xFFFFFFFF;
2629 mapper_caps.wReserved1 = 0;
2630 mapper_caps.dwSupport = WAVECAPS_LRVOLUME | WAVECAPS_VOLUME |
2631 WAVECAPS_SAMPLEACCURATE;
2632 mapper_caps.wChannels = 2;
2633 lstrcpyW(mapper_caps.szPname, mapper_pnameW);
2635 caps = &mapper_caps;
2637 if(uDeviceID >= g_outmmdevices_count)
2638 return MMSYSERR_BADDEVICEID;
2640 caps = &read_map(g_out_map, uDeviceID)->out_caps;
2643 memcpy(lpCaps, caps, min(uSize, sizeof(*lpCaps)));
2645 return MMSYSERR_NOERROR;
2648 /**************************************************************************
2649 * waveOutGetErrorTextA [WINMM.@]
2650 * waveInGetErrorTextA [WINMM.@]
2652 UINT WINAPI waveOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
2656 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
2657 else if (uSize == 0) ret = MMSYSERR_NOERROR;
2660 LPWSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize * sizeof(WCHAR));
2661 if (!xstr) ret = MMSYSERR_NOMEM;
2664 ret = waveOutGetErrorTextW(uError, xstr, uSize);
2665 if (ret == MMSYSERR_NOERROR)
2666 WideCharToMultiByte(CP_ACP, 0, xstr, -1, lpText, uSize, NULL, NULL);
2667 HeapFree(GetProcessHeap(), 0, xstr);
2673 /**************************************************************************
2674 * waveOutGetErrorTextW [WINMM.@]
2675 * waveInGetErrorTextW [WINMM.@]
2677 UINT WINAPI waveOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
2679 UINT ret = MMSYSERR_BADERRNUM;
2681 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
2682 else if (uSize == 0) ret = MMSYSERR_NOERROR;
2684 /* test has been removed because MMSYSERR_BASE is 0, and gcc did emit
2685 * a warning for the test was always true */
2686 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
2687 (uError >= WAVERR_BASE && uError <= WAVERR_LASTERROR)) {
2688 if (LoadStringW(hWinMM32Instance,
2689 uError, lpText, uSize) > 0) {
2690 ret = MMSYSERR_NOERROR;
2696 /**************************************************************************
2697 * waveOutOpen [WINMM.@]
2698 * All the args/structs have the same layout as the win16 equivalents
2700 MMRESULT WINAPI waveOutOpen(LPHWAVEOUT lphWaveOut, UINT uDeviceID,
2701 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2702 DWORD_PTR dwInstance, DWORD dwFlags)
2705 WINMM_OpenInfo info;
2706 WINMM_CBInfo cb_info;
2708 TRACE("(%p, %u, %p, %lx, %lx, %08x)\n", lphWaveOut, uDeviceID, lpFormat,
2709 dwCallback, dwInstance, dwFlags);
2711 if(!WINMM_StartDevicesThread())
2712 return MMSYSERR_NODRIVER;
2714 if(!lphWaveOut && !(dwFlags & WAVE_FORMAT_QUERY))
2715 return MMSYSERR_INVALPARAM;
2717 res = WINMM_CheckCallback(dwCallback, dwFlags, FALSE);
2718 if(res != MMSYSERR_NOERROR)
2722 info.format = (WAVEFORMATEX*)lpFormat;
2723 info.callback = dwCallback;
2724 info.cb_user = dwInstance;
2725 info.req_device = uDeviceID;
2726 info.flags = dwFlags;
2729 res = SendMessageW(g_devices_hwnd, WODM_OPEN, (DWORD_PTR)&info, 0);
2730 if(res != MMSYSERR_NOERROR)
2734 *lphWaveOut = (HWAVEOUT)info.handle;
2736 cb_info.flags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
2737 cb_info.callback = dwCallback;
2738 cb_info.user = dwInstance;
2739 cb_info.hwave = info.handle;
2741 WINMM_NotifyClient(&cb_info, WOM_OPEN, 0, 0);
2746 /**************************************************************************
2747 * waveOutClose [WINMM.@]
2749 UINT WINAPI waveOutClose(HWAVEOUT hWaveOut)
2752 WINMM_Device *device;
2753 WINMM_CBInfo cb_info;
2755 TRACE("(%p)\n", hWaveOut);
2757 device = WINMM_GetDeviceFromHWAVE((HWAVE)hWaveOut);
2759 if(!WINMM_ValidateAndLock(device))
2760 return MMSYSERR_INVALHANDLE;
2762 cb_info = device->cb_info;
2764 LeaveCriticalSection(&device->lock);
2766 res = SendMessageW(g_devices_hwnd, WODM_CLOSE, (WPARAM)hWaveOut, 0);
2768 if(res == MMSYSERR_NOERROR)
2769 WINMM_NotifyClient(&cb_info, WOM_CLOSE, 0, 0);
2774 /**************************************************************************
2775 * waveOutPrepareHeader [WINMM.@]
2777 UINT WINAPI waveOutPrepareHeader(HWAVEOUT hWaveOut,
2778 WAVEHDR* lpWaveOutHdr, UINT uSize)
2780 TRACE("(%p, %p, %u)\n", hWaveOut, lpWaveOutHdr, uSize);
2782 if(!lpWaveOutHdr || uSize < sizeof(WAVEHDR))
2783 return MMSYSERR_INVALPARAM;
2785 if(lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
2786 return WAVERR_STILLPLAYING;
2788 return WINMM_PrepareHeader((HWAVE)hWaveOut, lpWaveOutHdr);
2791 /**************************************************************************
2792 * waveOutUnprepareHeader [WINMM.@]
2794 UINT WINAPI waveOutUnprepareHeader(HWAVEOUT hWaveOut,
2795 LPWAVEHDR lpWaveOutHdr, UINT uSize)
2797 TRACE("(%p, %p, %u)\n", hWaveOut, lpWaveOutHdr, uSize);
2799 if(!lpWaveOutHdr || uSize < sizeof(WAVEHDR))
2800 return MMSYSERR_INVALPARAM;
2802 if(!(lpWaveOutHdr->dwFlags & WHDR_PREPARED))
2803 return MMSYSERR_NOERROR;
2805 if(lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
2806 return WAVERR_STILLPLAYING;
2808 return WINMM_UnprepareHeader((HWAVE)hWaveOut, lpWaveOutHdr);
2811 /**************************************************************************
2812 * waveOutWrite [WINMM.@]
2814 UINT WINAPI waveOutWrite(HWAVEOUT hWaveOut, WAVEHDR *header, UINT uSize)
2816 WINMM_Device *device;
2819 TRACE("(%p, %p, %u)\n", hWaveOut, header, uSize);
2821 device = WINMM_GetDeviceFromHWAVE((HWAVE)hWaveOut);
2823 if(!WINMM_ValidateAndLock(device))
2824 return MMSYSERR_INVALHANDLE;
2826 if(!header->lpData || !(header->dwFlags & WHDR_PREPARED)){
2827 LeaveCriticalSection(&device->lock);
2828 return WAVERR_UNPREPARED;
2831 if(header->dwFlags & WHDR_INQUEUE){
2832 LeaveCriticalSection(&device->lock);
2833 return WAVERR_STILLPLAYING;
2836 if(device->acm_handle){
2837 ACMSTREAMHEADER *ash = (ACMSTREAMHEADER*)header->reserved;
2839 ash->cbSrcLength = header->dwBufferLength;
2840 mr = acmStreamConvert(device->acm_handle, ash, 0);
2841 if(mr != MMSYSERR_NOERROR){
2842 LeaveCriticalSection(&device->lock);
2848 device->last->lpNext = header;
2849 device->last = header;
2850 if(!device->playing)
2851 device->playing = header;
2853 device->playing = device->first = device->last = header;
2854 if(header->dwFlags & WHDR_BEGINLOOP){
2855 device->loop_counter = header->dwLoops;
2856 device->loop_start = header;
2860 header->lpNext = NULL;
2861 header->dwFlags &= ~WHDR_DONE;
2862 header->dwFlags |= WHDR_INQUEUE;
2864 mr = WINMM_BeginPlaying(device);
2866 LeaveCriticalSection(&device->lock);
2871 /**************************************************************************
2872 * waveOutBreakLoop [WINMM.@]
2874 UINT WINAPI waveOutBreakLoop(HWAVEOUT hWaveOut)
2876 WINMM_Device *device;
2878 TRACE("(%p)\n", hWaveOut);
2880 device = WINMM_GetDeviceFromHWAVE((HWAVE)hWaveOut);
2882 if(!WINMM_ValidateAndLock(device))
2883 return MMSYSERR_INVALHANDLE;
2885 device->loop_counter = 0;
2887 LeaveCriticalSection(&device->lock);
2889 return MMSYSERR_NOERROR;
2892 /**************************************************************************
2893 * waveOutPause [WINMM.@]
2895 UINT WINAPI waveOutPause(HWAVEOUT hWaveOut)
2897 TRACE("(%p)\n", hWaveOut);
2899 return WINMM_Pause((HWAVE)hWaveOut);
2902 /**************************************************************************
2903 * waveOutReset [WINMM.@]
2905 UINT WINAPI waveOutReset(HWAVEOUT hWaveOut)
2907 TRACE("(%p)\n", hWaveOut);
2909 return WINMM_Reset((HWAVE)hWaveOut);
2912 /**************************************************************************
2913 * waveOutRestart [WINMM.@]
2915 UINT WINAPI waveOutRestart(HWAVEOUT hWaveOut)
2917 WINMM_Device *device;
2920 TRACE("(%p)\n", hWaveOut);
2922 device = WINMM_GetDeviceFromHWAVE((HWAVE)hWaveOut);
2924 if(!WINMM_ValidateAndLock(device))
2925 return MMSYSERR_INVALHANDLE;
2927 device->stopped = TRUE;
2929 mr = WINMM_BeginPlaying(device);
2931 LeaveCriticalSection(&device->lock);
2936 /**************************************************************************
2937 * waveOutGetPosition [WINMM.@]
2939 UINT WINAPI waveOutGetPosition(HWAVEOUT hWaveOut, LPMMTIME lpTime,
2942 TRACE("(%p, %p, %u)\n", hWaveOut, lpTime, uSize);
2944 if(!uSize || !lpTime || uSize != sizeof(MMTIME))
2945 return MMSYSERR_INVALPARAM;
2947 return WINMM_GetPosition((HWAVE)hWaveOut, lpTime);
2950 /**************************************************************************
2951 * waveOutGetPitch [WINMM.@]
2953 UINT WINAPI waveOutGetPitch(HWAVEOUT hWaveOut, LPDWORD lpdw)
2955 TRACE("(%p, %p)\n", hWaveOut, lpdw);
2956 return MMSYSERR_NOTSUPPORTED;
2959 /**************************************************************************
2960 * waveOutSetPitch [WINMM.@]
2962 UINT WINAPI waveOutSetPitch(HWAVEOUT hWaveOut, DWORD dw)
2964 TRACE("(%p, %08x)\n", hWaveOut, dw);
2966 return MMSYSERR_NOTSUPPORTED;
2969 /**************************************************************************
2970 * waveOutGetPlaybackRate [WINMM.@]
2972 UINT WINAPI waveOutGetPlaybackRate(HWAVEOUT hWaveOut, LPDWORD lpdw)
2974 TRACE("(%p, %p)\n", hWaveOut, lpdw);
2976 return MMSYSERR_NOTSUPPORTED;
2979 /**************************************************************************
2980 * waveOutSetPlaybackRate [WINMM.@]
2982 UINT WINAPI waveOutSetPlaybackRate(HWAVEOUT hWaveOut, DWORD dw)
2984 TRACE("(%p, %08x)\n", hWaveOut, dw);
2986 return MMSYSERR_NOTSUPPORTED;
2989 /**************************************************************************
2990 * waveOutGetVolume [WINMM.@]
2992 UINT WINAPI waveOutGetVolume(HWAVEOUT hWaveOut, DWORD *out)
2994 WINMM_Device *device;
2999 TRACE("(%p, %p)\n", hWaveOut, out);
3002 return MMSYSERR_INVALPARAM;
3004 device = WINMM_GetDeviceFromHWAVE((HWAVE)hWaveOut);
3006 if(!WINMM_ValidateAndLock(device))
3007 return MMSYSERR_INVALHANDLE;
3009 hr = IAudioStreamVolume_GetChannelCount(device->volume, &channels);
3011 LeaveCriticalSection(&device->lock);
3012 WARN("GetChannelCount failed: %08x\n", hr);
3013 return MMSYSERR_ERROR;
3016 vols = HeapAlloc(GetProcessHeap(), 0, sizeof(float) * channels);
3018 LeaveCriticalSection(&device->lock);
3019 return MMSYSERR_NOMEM;
3022 hr = IAudioStreamVolume_GetAllVolumes(device->volume, channels, vols);
3024 LeaveCriticalSection(&device->lock);
3025 HeapFree(GetProcessHeap(), 0, vols);
3026 WARN("GetAllVolumes failed: %08x\n", hr);
3027 return MMSYSERR_ERROR;
3030 LeaveCriticalSection(&device->lock);
3032 *out = ((UINT16)(vols[0] * (DWORD)0xFFFF));
3034 *out |= ((UINT16)(vols[1] * (DWORD)0xFFFF)) << 16;
3036 HeapFree(GetProcessHeap(), 0, vols);
3038 return MMSYSERR_NOERROR;
3041 /**************************************************************************
3042 * waveOutSetVolume [WINMM.@]
3044 UINT WINAPI waveOutSetVolume(HWAVEOUT hWaveOut, DWORD in)
3046 WINMM_Device *device;
3051 TRACE("(%p, %08x)\n", hWaveOut, in);
3053 device = WINMM_GetDeviceFromHWAVE((HWAVE)hWaveOut);
3055 if(!WINMM_ValidateAndLock(device))
3056 return MMSYSERR_INVALHANDLE;
3058 hr = IAudioStreamVolume_GetChannelCount(device->volume, &channels);
3060 LeaveCriticalSection(&device->lock);
3061 WARN("GetChannelCount failed: %08x\n", hr);
3062 return MMSYSERR_ERROR;
3065 vols = HeapAlloc(GetProcessHeap(), 0, sizeof(float) * channels);
3067 LeaveCriticalSection(&device->lock);
3068 return MMSYSERR_NOMEM;
3071 hr = IAudioStreamVolume_GetAllVolumes(device->volume, channels, vols);
3073 LeaveCriticalSection(&device->lock);
3074 HeapFree(GetProcessHeap(), 0, vols);
3075 WARN("GetAllVolumes failed: %08x\n", hr);
3076 return MMSYSERR_ERROR;
3079 vols[0] = (float)((DWORD)(in & 0xFFFF) / (float)0xFFFF);
3081 vols[1] = (float)((DWORD)(in >> 16) / (float)0xFFFF);
3083 hr = IAudioStreamVolume_SetAllVolumes(device->volume, channels, vols);
3085 LeaveCriticalSection(&device->lock);
3086 HeapFree(GetProcessHeap(), 0, vols);
3087 WARN("SetAllVolumes failed: %08x\n", hr);
3088 return MMSYSERR_ERROR;
3091 LeaveCriticalSection(&device->lock);
3093 HeapFree(GetProcessHeap(), 0, vols);
3095 return MMSYSERR_NOERROR;
3098 /**************************************************************************
3099 * waveOutGetID [WINMM.@]
3101 UINT WINAPI waveOutGetID(HWAVEOUT hWaveOut, UINT* lpuDeviceID)
3103 WINMM_Device *device;
3107 TRACE("(%p, %p)\n", hWaveOut, lpuDeviceID);
3110 return MMSYSERR_INVALPARAM;
3112 device = WINMM_GetDeviceFromHWAVE((HWAVE)hWaveOut);
3113 if(!WINMM_ValidateAndLock(device))
3114 return MMSYSERR_INVALHANDLE;
3116 LeaveCriticalSection(&device->lock);
3118 WINMM_DecomposeHWAVE((HWAVE)hWaveOut, lpuDeviceID, &is_out, &dev, &junk);
3120 return MMSYSERR_NOERROR;
3123 static UINT WINMM_QueryInstanceIDSize(UINT device, DWORD_PTR *len, BOOL is_out)
3126 WINMM_MMDevice **devices;
3128 TRACE("(%u, %p, %d)\n", device, len, is_out);
3131 count = g_outmmdevices_count;
3132 devices = g_out_map;
3134 count = g_inmmdevices_count;
3139 return MMSYSERR_INVALHANDLE;
3141 EnterCriticalSection(&g_devthread_lock);
3142 *len = (lstrlenW(devices[device]->dev_id) + 1) * sizeof(WCHAR);
3143 LeaveCriticalSection(&g_devthread_lock);
3145 return MMSYSERR_NOERROR;
3148 static UINT WINMM_QueryInstanceID(UINT device, WCHAR *str, DWORD_PTR len,
3152 WINMM_MMDevice **devices;
3154 TRACE("(%u, %p, %d)\n", device, str, is_out);
3157 count = g_outmmdevices_count;
3158 devices = g_out_map;
3160 count = g_inmmdevices_count;
3165 return MMSYSERR_INVALHANDLE;
3167 EnterCriticalSection(&g_devthread_lock);
3168 id_len = (lstrlenW(devices[device]->dev_id) + 1) * sizeof(WCHAR);
3170 LeaveCriticalSection(&g_devthread_lock);
3171 return MMSYSERR_ERROR;
3174 memcpy(str, devices[device]->dev_id, id_len);
3175 LeaveCriticalSection(&g_devthread_lock);
3177 return MMSYSERR_NOERROR;
3180 static UINT get_device_interface(UINT msg, BOOL is_out, UINT index, WCHAR *out, ULONG *out_len)
3182 WINMM_QueryInterfaceInfo info;
3184 if(!WINMM_StartDevicesThread())
3185 return MMSYSERR_NODRIVER;
3187 info.is_out = is_out;
3190 info.len_bytes = out_len;
3192 return SendMessageW(g_devices_hwnd, msg, (DWORD_PTR)&info, 0);
3195 /**************************************************************************
3196 * waveOutMessage [WINMM.@]
3198 UINT WINAPI waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage,
3199 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
3201 TRACE("(%p, %u, %lx, %lx)\n", hWaveOut, uMessage, dwParam1, dwParam2);
3204 case DRV_QUERYFUNCTIONINSTANCEIDSIZE:
3205 return WINMM_QueryInstanceIDSize(HandleToULong(hWaveOut),
3206 (DWORD_PTR*)dwParam1, TRUE);
3207 case DRV_QUERYFUNCTIONINSTANCEID:
3208 return WINMM_QueryInstanceID(HandleToULong(hWaveOut), (WCHAR*)dwParam1, dwParam2, TRUE);
3209 case DRV_QUERYDEVICEINTERFACESIZE:
3210 return get_device_interface(DRV_QUERYDEVICEINTERFACESIZE, TRUE, HandleToULong(hWaveOut),
3211 NULL, (ULONG*)dwParam1);
3212 case DRV_QUERYDEVICEINTERFACE:
3214 ULONG size = dwParam2;
3215 return get_device_interface(DRV_QUERYDEVICEINTERFACE, TRUE, HandleToULong(hWaveOut),
3216 (WCHAR*)dwParam1, &size);
3218 case DRV_QUERYMAPPABLE:
3219 return MMSYSERR_NOERROR;
3220 case DRVM_MAPPER_PREFERRED_GET:
3222 if(g_outmmdevices_count > 0)
3223 /* Device 0 is always the default device */
3224 *(DWORD *)dwParam1 = 0;
3226 *(DWORD *)dwParam1 = -1;
3231 *(DWORD *)dwParam2 = 0;
3233 return MMSYSERR_NOERROR;
3236 TRACE("Message not supported: %u\n", uMessage);
3238 return MMSYSERR_NOTSUPPORTED;
3241 /**************************************************************************
3242 * waveInGetNumDevs [WINMM.@]
3244 UINT WINAPI waveInGetNumDevs(void)
3246 HRESULT hr = WINMM_InitMMDevices();
3250 TRACE("count: %u\n", g_inmmdevices_count);
3252 return g_inmmdevices_count;
3255 /**************************************************************************
3256 * waveInGetDevCapsW [WINMM.@]
3258 UINT WINAPI waveInGetDevCapsW(UINT_PTR uDeviceID, LPWAVEINCAPSW lpCaps, UINT uSize)
3260 WAVEINCAPSW mapper_caps, *caps;
3263 TRACE("(%lu, %p, %u)\n", uDeviceID, lpCaps, uSize);
3265 hr = WINMM_InitMMDevices();
3267 return MMSYSERR_NODRIVER;
3270 return MMSYSERR_INVALPARAM;
3272 if(WINMM_IsMapper(uDeviceID)){
3273 /* FIXME: Should be localized */
3274 static const WCHAR mapper_pnameW[] = {'W','i','n','e',' ','S','o','u',
3275 'n','d',' ','M','a','p','p','e','r',0};
3277 mapper_caps.wMid = 0xFF;
3278 mapper_caps.wPid = 0xFF;
3279 mapper_caps.vDriverVersion = 0x00010001;
3280 mapper_caps.dwFormats = 0xFFFFFFFF;
3281 mapper_caps.wReserved1 = 0;
3282 mapper_caps.wChannels = 2;
3283 lstrcpyW(mapper_caps.szPname, mapper_pnameW);
3285 caps = &mapper_caps;
3287 if(uDeviceID >= g_inmmdevices_count)
3288 return MMSYSERR_BADDEVICEID;
3290 caps = &read_map(g_in_map, uDeviceID)->in_caps;
3293 memcpy(lpCaps, caps, min(uSize, sizeof(*lpCaps)));
3295 return MMSYSERR_NOERROR;
3298 /**************************************************************************
3299 * waveInGetDevCapsA [WINMM.@]
3301 UINT WINAPI waveInGetDevCapsA(UINT_PTR uDeviceID, LPWAVEINCAPSA lpCaps, UINT uSize)
3306 TRACE("(%lu, %p, %u)\n", uDeviceID, lpCaps, uSize);
3309 return MMSYSERR_INVALPARAM;
3311 ret = waveInGetDevCapsW(uDeviceID, &wicW, sizeof(wicW));
3313 if (ret == MMSYSERR_NOERROR) {
3315 wicA.wMid = wicW.wMid;
3316 wicA.wPid = wicW.wPid;
3317 wicA.vDriverVersion = wicW.vDriverVersion;
3318 WideCharToMultiByte( CP_ACP, 0, wicW.szPname, -1, wicA.szPname,
3319 sizeof(wicA.szPname), NULL, NULL );
3320 wicA.dwFormats = wicW.dwFormats;
3321 wicA.wChannels = wicW.wChannels;
3322 memcpy(lpCaps, &wicA, min(uSize, sizeof(wicA)));
3327 /**************************************************************************
3328 * waveInOpen [WINMM.@]
3330 MMRESULT WINAPI waveInOpen(HWAVEIN* lphWaveIn, UINT uDeviceID,
3331 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
3332 DWORD_PTR dwInstance, DWORD dwFlags)
3335 WINMM_OpenInfo info;
3336 WINMM_CBInfo cb_info;
3338 TRACE("(%p, %x, %p, %lx, %lx, %08x)\n", lphWaveIn, uDeviceID, lpFormat,
3339 dwCallback, dwInstance, dwFlags);
3341 if(!WINMM_StartDevicesThread())
3342 return MMSYSERR_NODRIVER;
3344 if(!lphWaveIn && !(dwFlags & WAVE_FORMAT_QUERY))
3345 return MMSYSERR_INVALPARAM;
3347 res = WINMM_CheckCallback(dwCallback, dwFlags, FALSE);
3348 if(res != MMSYSERR_NOERROR)
3352 info.format = (WAVEFORMATEX*)lpFormat;
3353 info.callback = dwCallback;
3354 info.cb_user = dwInstance;
3355 info.req_device = uDeviceID;
3356 info.flags = dwFlags;
3359 res = SendMessageW(g_devices_hwnd, WIDM_OPEN, (DWORD_PTR)&info, 0);
3360 if(res != MMSYSERR_NOERROR)
3364 *lphWaveIn = (HWAVEIN)info.handle;
3366 cb_info.flags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
3367 cb_info.callback = dwCallback;
3368 cb_info.user = dwInstance;
3369 cb_info.hwave = info.handle;
3371 WINMM_NotifyClient(&cb_info, WIM_OPEN, 0, 0);
3376 /**************************************************************************
3377 * waveInClose [WINMM.@]
3379 UINT WINAPI waveInClose(HWAVEIN hWaveIn)
3381 WINMM_Device *device;
3382 WINMM_CBInfo cb_info;
3385 TRACE("(%p)\n", hWaveIn);
3387 device = WINMM_GetDeviceFromHWAVE((HWAVE)hWaveIn);
3389 if(!WINMM_ValidateAndLock(device))
3390 return MMSYSERR_INVALHANDLE;
3392 cb_info = device->cb_info;
3394 LeaveCriticalSection(&device->lock);
3396 res = SendMessageW(g_devices_hwnd, WIDM_CLOSE, (WPARAM)hWaveIn, 0);
3398 if(res == MMSYSERR_NOERROR)
3399 WINMM_NotifyClient(&cb_info, WIM_CLOSE, 0, 0);
3404 /**************************************************************************
3405 * waveInPrepareHeader [WINMM.@]
3407 UINT WINAPI waveInPrepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
3410 TRACE("(%p, %p, %u)\n", hWaveIn, lpWaveInHdr, uSize);
3412 if(!lpWaveInHdr || uSize < sizeof(WAVEHDR))
3413 return MMSYSERR_INVALPARAM;
3415 if(lpWaveInHdr->dwFlags & WHDR_INQUEUE)
3416 return WAVERR_STILLPLAYING;
3418 return WINMM_PrepareHeader((HWAVE)hWaveIn, lpWaveInHdr);
3421 /**************************************************************************
3422 * waveInUnprepareHeader [WINMM.@]
3424 UINT WINAPI waveInUnprepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
3427 TRACE("(%p, %p, %u)\n", hWaveIn, lpWaveInHdr, uSize);
3429 if(!lpWaveInHdr || uSize < sizeof(WAVEHDR))
3430 return MMSYSERR_INVALPARAM;
3432 if(!(lpWaveInHdr->dwFlags & WHDR_PREPARED))
3433 return MMSYSERR_NOERROR;
3435 if(lpWaveInHdr->dwFlags & WHDR_INQUEUE)
3436 return WAVERR_STILLPLAYING;
3438 return WINMM_UnprepareHeader((HWAVE)hWaveIn, lpWaveInHdr);
3441 /**************************************************************************
3442 * waveInAddBuffer [WINMM.@]
3444 UINT WINAPI waveInAddBuffer(HWAVEIN hWaveIn, WAVEHDR *header, UINT uSize)
3446 WINMM_Device *device;
3448 TRACE("(%p, %p, %u)\n", hWaveIn, header, uSize);
3450 if(!header || uSize < sizeof(WAVEHDR))
3451 return MMSYSERR_INVALPARAM;
3453 if(!(header->dwFlags & WHDR_PREPARED))
3454 return WAVERR_UNPREPARED;
3456 device = WINMM_GetDeviceFromHWAVE((HWAVE)hWaveIn);
3458 if(!WINMM_ValidateAndLock(device))
3459 return MMSYSERR_INVALHANDLE;
3462 device->first = device->last = header;
3464 device->last->lpNext = header;
3465 device->last = header;
3468 header->dwBytesRecorded = 0;
3469 header->lpNext = NULL;
3470 header->dwFlags &= ~WHDR_DONE;
3471 header->dwFlags |= WHDR_INQUEUE;
3473 LeaveCriticalSection(&device->lock);
3475 return MMSYSERR_NOERROR;
3478 /**************************************************************************
3479 * waveInReset [WINMM.@]
3481 UINT WINAPI waveInReset(HWAVEIN hWaveIn)
3483 TRACE("(%p)\n", hWaveIn);
3485 return WINMM_Reset((HWAVE)hWaveIn);
3488 /**************************************************************************
3489 * waveInStart [WINMM.@]
3491 UINT WINAPI waveInStart(HWAVEIN hWaveIn)
3493 WINMM_Device *device;
3496 TRACE("(%p)\n", hWaveIn);
3498 device = WINMM_GetDeviceFromHWAVE((HWAVE)hWaveIn);
3500 if(!WINMM_ValidateAndLock(device))
3501 return MMSYSERR_INVALHANDLE;
3503 mr = WINMM_BeginPlaying(device);
3505 LeaveCriticalSection(&device->lock);
3510 /**************************************************************************
3511 * waveInStop [WINMM.@]
3513 UINT WINAPI waveInStop(HWAVEIN hWaveIn)
3515 WINMM_CBInfo cb_info;
3516 WINMM_Device *device;
3520 TRACE("(%p)\n", hWaveIn);
3522 device = WINMM_GetDeviceFromHWAVE((HWAVE)hWaveIn);
3524 if(!WINMM_ValidateAndLock(device))
3525 return MMSYSERR_INVALHANDLE;
3527 hr = WINMM_Pause((HWAVE)hWaveIn);
3529 LeaveCriticalSection(&device->lock);
3530 return MMSYSERR_ERROR;
3532 device->stopped = TRUE;
3534 buf = device->first;
3535 if(buf && buf->dwBytesRecorded > 0){
3536 device->first = buf->lpNext;
3540 cb_info = device->cb_info;
3542 LeaveCriticalSection(&device->lock);
3545 buf->dwFlags &= ~WHDR_INQUEUE;
3546 buf->dwFlags |= WHDR_DONE;
3547 WINMM_NotifyClient(&cb_info, WIM_DATA, (DWORD_PTR)buf, 0);
3550 return MMSYSERR_NOERROR;
3553 /**************************************************************************
3554 * waveInGetPosition [WINMM.@]
3556 UINT WINAPI waveInGetPosition(HWAVEIN hWaveIn, LPMMTIME lpTime,
3559 TRACE("(%p, %p, %u)\n", hWaveIn, lpTime, uSize);
3561 if(!uSize || !lpTime || uSize != sizeof(MMTIME))
3562 return MMSYSERR_INVALPARAM;
3564 return WINMM_GetPosition((HWAVE)hWaveIn, lpTime);
3567 /**************************************************************************
3568 * waveInGetID [WINMM.@]
3570 UINT WINAPI waveInGetID(HWAVEIN hWaveIn, UINT* lpuDeviceID)
3574 WINMM_Device *device;
3576 TRACE("(%p, %p)\n", hWaveIn, lpuDeviceID);
3579 return MMSYSERR_INVALPARAM;
3581 device = WINMM_GetDeviceFromHWAVE((HWAVE)hWaveIn);
3582 if(!WINMM_ValidateAndLock(device))
3583 return MMSYSERR_INVALHANDLE;
3585 LeaveCriticalSection(&device->lock);
3587 WINMM_DecomposeHWAVE((HWAVE)hWaveIn, lpuDeviceID, &is_out, &dev, &junk);
3589 return MMSYSERR_NOERROR;
3592 /**************************************************************************
3593 * waveInMessage [WINMM.@]
3595 UINT WINAPI waveInMessage(HWAVEIN hWaveIn, UINT uMessage,
3596 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
3598 TRACE("(%p, %u, %ld, %ld)\n", hWaveIn, uMessage, dwParam1, dwParam2);
3601 case DRV_QUERYFUNCTIONINSTANCEIDSIZE:
3602 return WINMM_QueryInstanceIDSize(HandleToULong(hWaveIn),
3603 (DWORD_PTR*)dwParam1, FALSE);
3604 case DRV_QUERYFUNCTIONINSTANCEID:
3605 return WINMM_QueryInstanceID(HandleToULong(hWaveIn), (WCHAR*)dwParam1, dwParam2, FALSE);
3606 case DRV_QUERYDEVICEINTERFACESIZE:
3607 return get_device_interface(DRV_QUERYDEVICEINTERFACESIZE, FALSE, HandleToULong(hWaveIn),
3608 NULL, (ULONG*)dwParam1);
3609 case DRV_QUERYDEVICEINTERFACE:
3611 ULONG size = dwParam2;
3612 return get_device_interface(DRV_QUERYDEVICEINTERFACE, FALSE, HandleToULong(hWaveIn),
3613 (WCHAR*)dwParam1, &size);
3615 case DRV_QUERYMAPPABLE:
3616 return MMSYSERR_NOERROR;
3617 case DRVM_MAPPER_PREFERRED_GET:
3619 if(g_inmmdevices_count > 0)
3620 /* Device 0 is always the default device */
3621 *(DWORD *)dwParam1 = 0;
3623 *(DWORD *)dwParam1 = -1;
3628 *(DWORD *)dwParam2 = 0;
3630 return MMSYSERR_NOERROR;
3633 TRACE("Message not supported: %u\n", uMessage);
3635 return MMSYSERR_NOTSUPPORTED;
3638 UINT WINAPI mixerGetNumDevs(void)
3644 hr = WINMM_InitMMDevices();
3648 return g_outmmdevices_count + g_inmmdevices_count;
3651 /**************************************************************************
3652 * mixerGetDevCapsA [WINMM.@]
3654 UINT WINAPI mixerGetDevCapsA(UINT_PTR uDeviceID, LPMIXERCAPSA lpCaps, UINT uSize)
3659 TRACE("(%lu, %p, %u)\n", uDeviceID, lpCaps, uSize);
3662 return MMSYSERR_INVALPARAM;
3664 ret = mixerGetDevCapsW(uDeviceID, &micW, sizeof(micW));
3666 if (ret == MMSYSERR_NOERROR) {
3668 micA.wMid = micW.wMid;
3669 micA.wPid = micW.wPid;
3670 micA.vDriverVersion = micW.vDriverVersion;
3671 WideCharToMultiByte( CP_ACP, 0, micW.szPname, -1, micA.szPname,
3672 sizeof(micA.szPname), NULL, NULL );
3673 micA.fdwSupport = micW.fdwSupport;
3674 micA.cDestinations = micW.cDestinations;
3675 memcpy(lpCaps, &micA, min(uSize, sizeof(micA)));
3680 /**************************************************************************
3681 * mixerGetDevCapsW [WINMM.@]
3683 UINT WINAPI mixerGetDevCapsW(UINT_PTR uDeviceID, LPMIXERCAPSW lpCaps, UINT uSize)
3685 WINMM_MMDevice *mmdevice;
3689 TRACE("(%lu, %p, %u)\n", uDeviceID, lpCaps, uSize);
3691 hr = WINMM_InitMMDevices();
3693 return MMSYSERR_NODRIVER;
3696 return MMSYSERR_INVALPARAM;
3699 return MMSYSERR_NOERROR;
3701 if(uDeviceID >= g_outmmdevices_count + g_inmmdevices_count)
3702 return MMSYSERR_BADDEVICEID;
3704 if(uDeviceID < g_outmmdevices_count){
3705 mmdevice = read_map(g_out_map, uDeviceID);
3706 memcpy(caps.szPname, mmdevice->out_caps.szPname, sizeof(caps.szPname));
3708 mmdevice = read_map(g_in_map, uDeviceID - g_outmmdevices_count);
3709 memcpy(caps.szPname, mmdevice->in_caps.szPname, sizeof(caps.szPname));
3714 caps.vDriverVersion = 0x00010001;
3715 caps.fdwSupport = 0;
3716 caps.cDestinations = 1;
3718 memcpy(lpCaps, &caps, uSize);
3720 return MMSYSERR_NOERROR;
3723 /**************************************************************************
3724 * mixerOpen [WINMM.@]
3726 UINT WINAPI mixerOpen(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback,
3727 DWORD_PTR dwInstance, DWORD fdwOpen)
3729 WINMM_MMDevice *mmdevice;
3733 TRACE("(%p, %d, %lx, %lx, %x)\n", lphMix, uDeviceID, dwCallback,
3734 dwInstance, fdwOpen);
3736 hr = WINMM_InitMMDevices();
3738 return MMSYSERR_NODRIVER;
3741 return MMSYSERR_INVALPARAM;
3743 mr = WINMM_CheckCallback(dwCallback, fdwOpen, TRUE);
3744 if(mr != MMSYSERR_NOERROR)
3747 if(uDeviceID >= g_outmmdevices_count + g_inmmdevices_count)
3748 return MMSYSERR_BADDEVICEID;
3750 if(uDeviceID < g_outmmdevices_count){
3751 mmdevice = read_map(g_out_map, uDeviceID);
3752 *lphMix = (HMIXER)WINMM_MakeHWAVE(uDeviceID, TRUE,
3753 mmdevice->mixer_count);
3755 mmdevice = read_map(g_in_map, uDeviceID - g_outmmdevices_count);
3756 *lphMix = (HMIXER)WINMM_MakeHWAVE(uDeviceID - g_outmmdevices_count,
3757 FALSE, mmdevice->mixer_count);
3760 ++mmdevice->mixer_count;
3762 return MMSYSERR_NOERROR;
3765 /**************************************************************************
3766 * mixerClose [WINMM.@]
3768 UINT WINAPI mixerClose(HMIXER hMix)
3770 TRACE("(%p)\n", hMix);
3772 return MMSYSERR_NOERROR;
3775 /**************************************************************************
3776 * mixerGetID [WINMM.@]
3778 UINT WINAPI mixerGetID(HMIXEROBJ hmix, LPUINT lpid, DWORD fdwID)
3780 WINMM_MMDevice *mmdevice;
3783 TRACE("(%p, %p, %x)\n", hmix, lpid, fdwID);
3785 hr = WINMM_InitMMDevices();
3787 return MMSYSERR_NODRIVER;
3790 return MMSYSERR_INVALPARAM;
3792 mmdevice = WINMM_GetMixerMMDevice(hmix, fdwID, lpid);
3794 return MMSYSERR_INVALHANDLE;
3796 if(mmdevice->in_caps.szPname[0] != '\0')
3797 *lpid += g_outmmdevices_count;
3799 return MMSYSERR_NOERROR;
3802 /**************************************************************************
3803 * mixerGetControlDetailsW [WINMM.@]
3805 UINT WINAPI mixerGetControlDetailsW(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdW,
3808 WINMM_ControlDetails details;
3811 TRACE("(%p, %p, %x)\n", hmix, lpmcdW, fdwDetails);
3813 hr = WINMM_InitMMDevices();
3815 return MMSYSERR_NODRIVER;
3818 return MMSYSERR_INVALPARAM;
3820 TRACE("dwControlID: %u\n", lpmcdW->dwControlID);
3822 details.hmix = hmix;
3823 details.details = lpmcdW;
3824 details.flags = fdwDetails;
3826 return SendMessageW(g_devices_hwnd, MXDM_GETCONTROLDETAILS,
3827 (DWORD_PTR)&details, 0);
3830 /**************************************************************************
3831 * mixerGetControlDetailsA [WINMM.@]
3833 UINT WINAPI mixerGetControlDetailsA(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdA,
3836 UINT ret = MMSYSERR_NOTSUPPORTED;
3838 TRACE("(%p, %p, %08x)\n", hmix, lpmcdA, fdwDetails);
3840 if (lpmcdA == NULL || lpmcdA->cbStruct != sizeof(*lpmcdA))
3841 return MMSYSERR_INVALPARAM;
3843 switch (fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK) {
3844 case MIXER_GETCONTROLDETAILSF_VALUE:
3845 /* can safely use A structure as it is, no string inside */
3846 ret = mixerGetControlDetailsW(hmix, lpmcdA, fdwDetails);
3848 case MIXER_GETCONTROLDETAILSF_LISTTEXT:
3850 MIXERCONTROLDETAILS_LISTTEXTA *pDetailsA = lpmcdA->paDetails;
3851 MIXERCONTROLDETAILS_LISTTEXTW *pDetailsW;
3852 int size = max(1, lpmcdA->cChannels) * sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
3855 if (lpmcdA->u.cMultipleItems != 0) {
3856 size *= lpmcdA->u.cMultipleItems;
3858 pDetailsW = HeapAlloc(GetProcessHeap(), 0, size);
3859 lpmcdA->paDetails = pDetailsW;
3860 lpmcdA->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
3861 /* set up lpmcd->paDetails */
3862 ret = mixerGetControlDetailsW(hmix, lpmcdA, fdwDetails);
3863 /* copy from lpmcd->paDetails back to paDetailsW; */
3864 if (ret == MMSYSERR_NOERROR) {
3865 for (i = 0; i < lpmcdA->u.cMultipleItems * lpmcdA->cChannels; i++) {
3866 pDetailsA->dwParam1 = pDetailsW->dwParam1;
3867 pDetailsA->dwParam2 = pDetailsW->dwParam2;
3868 WideCharToMultiByte( CP_ACP, 0, pDetailsW->szName, -1,
3870 sizeof(pDetailsA->szName), NULL, NULL );
3874 pDetailsA -= lpmcdA->u.cMultipleItems * lpmcdA->cChannels;
3875 pDetailsW -= lpmcdA->u.cMultipleItems * lpmcdA->cChannels;
3877 HeapFree(GetProcessHeap(), 0, pDetailsW);
3878 lpmcdA->paDetails = pDetailsA;
3879 lpmcdA->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTA);
3883 WARN("Unsupported fdwDetails=0x%08x\n", fdwDetails);
3889 /**************************************************************************
3890 * mixerGetLineControlsA [WINMM.@]
3892 UINT WINAPI mixerGetLineControlsA(HMIXEROBJ hmix, LPMIXERLINECONTROLSA lpmlcA,
3895 MIXERLINECONTROLSW mlcW;
3899 TRACE("(%p, %p, %x)\n", hmix, lpmlcA, fdwControls);
3901 if (lpmlcA == NULL || lpmlcA->cbStruct != sizeof(*lpmlcA) ||
3902 lpmlcA->cbmxctrl != sizeof(MIXERCONTROLA))
3903 return MMSYSERR_INVALPARAM;
3905 mlcW.cbStruct = sizeof(mlcW);
3906 mlcW.dwLineID = lpmlcA->dwLineID;
3907 mlcW.u.dwControlID = lpmlcA->u.dwControlID;
3908 mlcW.u.dwControlType = lpmlcA->u.dwControlType;
3910 /* Debugging on Windows shows for MIXER_GETLINECONTROLSF_ONEBYTYPE only,
3911 the control count is assumed to be 1 - This is relied upon by a game,
3912 "Dynomite Deluze" */
3913 if (MIXER_GETLINECONTROLSF_ONEBYTYPE == (fdwControls & MIXER_GETLINECONTROLSF_QUERYMASK)) {
3916 mlcW.cControls = lpmlcA->cControls;
3918 mlcW.cbmxctrl = sizeof(MIXERCONTROLW);
3919 mlcW.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
3920 mlcW.cControls * mlcW.cbmxctrl);
3922 ret = mixerGetLineControlsW(hmix, &mlcW, fdwControls);
3924 if (ret == MMSYSERR_NOERROR) {
3925 lpmlcA->dwLineID = mlcW.dwLineID;
3926 lpmlcA->u.dwControlID = mlcW.u.dwControlID;
3927 lpmlcA->u.dwControlType = mlcW.u.dwControlType;
3929 for (i = 0; i < mlcW.cControls; i++) {
3930 lpmlcA->pamxctrl[i].cbStruct = sizeof(MIXERCONTROLA);
3931 lpmlcA->pamxctrl[i].dwControlID = mlcW.pamxctrl[i].dwControlID;
3932 lpmlcA->pamxctrl[i].dwControlType = mlcW.pamxctrl[i].dwControlType;
3933 lpmlcA->pamxctrl[i].fdwControl = mlcW.pamxctrl[i].fdwControl;
3934 lpmlcA->pamxctrl[i].cMultipleItems = mlcW.pamxctrl[i].cMultipleItems;
3935 WideCharToMultiByte( CP_ACP, 0, mlcW.pamxctrl[i].szShortName, -1,
3936 lpmlcA->pamxctrl[i].szShortName,
3937 sizeof(lpmlcA->pamxctrl[i].szShortName), NULL, NULL );
3938 WideCharToMultiByte( CP_ACP, 0, mlcW.pamxctrl[i].szName, -1,
3939 lpmlcA->pamxctrl[i].szName,
3940 sizeof(lpmlcA->pamxctrl[i].szName), NULL, NULL );
3941 /* sizeof(lpmlcA->pamxctrl[i].Bounds) ==
3942 * sizeof(mlcW.pamxctrl[i].Bounds) */
3943 memcpy(&lpmlcA->pamxctrl[i].Bounds, &mlcW.pamxctrl[i].Bounds,
3944 sizeof(mlcW.pamxctrl[i].Bounds));
3945 /* sizeof(lpmlcA->pamxctrl[i].Metrics) ==
3946 * sizeof(mlcW.pamxctrl[i].Metrics) */
3947 memcpy(&lpmlcA->pamxctrl[i].Metrics, &mlcW.pamxctrl[i].Metrics,
3948 sizeof(mlcW.pamxctrl[i].Metrics));
3952 HeapFree(GetProcessHeap(), 0, mlcW.pamxctrl);
3957 static UINT WINMM_GetVolumeLineControl(WINMM_MMDevice *mmdevice, DWORD line,
3958 MIXERCONTROLW *ctl, DWORD flags)
3960 ctl->dwControlID = (line == 0xFFFF0000) ? 0 : 2;
3961 ctl->dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
3962 ctl->fdwControl = MIXERCONTROL_CONTROLF_UNIFORM;
3963 ctl->cMultipleItems = 0;
3964 lstrcpyW(ctl->szShortName, volumeW);
3965 lstrcpyW(ctl->szName, volumeW);
3966 ctl->Bounds.s1.dwMinimum = 0;
3967 ctl->Bounds.s1.dwMaximum = 0xFFFF;
3968 ctl->Metrics.cSteps = 192;
3970 return MMSYSERR_NOERROR;
3973 static UINT WINMM_GetMuteLineControl(WINMM_MMDevice *mmdevice, DWORD line,
3974 MIXERCONTROLW *ctl, DWORD flags)
3976 ctl->dwControlID = (line == 0xFFFF0000) ? 1 : 3;
3977 ctl->dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE;
3978 ctl->fdwControl = MIXERCONTROL_CONTROLF_UNIFORM;
3979 ctl->cMultipleItems = 0;
3980 lstrcpyW(ctl->szShortName, muteW);
3981 lstrcpyW(ctl->szName, muteW);
3982 ctl->Bounds.s1.dwMinimum = 0;
3983 ctl->Bounds.s1.dwMaximum = 1;
3984 ctl->Metrics.cSteps = 0;
3986 return MMSYSERR_NOERROR;
3989 /**************************************************************************
3990 * mixerGetLineControlsW [WINMM.@]
3992 UINT WINAPI mixerGetLineControlsW(HMIXEROBJ hmix, LPMIXERLINECONTROLSW lpmlcW,
3995 WINMM_MMDevice *mmdevice;
3998 TRACE("(%p, %p, %08x)\n", hmix, lpmlcW, fdwControls);
4000 hr = WINMM_InitMMDevices();
4002 return MMSYSERR_NODRIVER;
4004 if(fdwControls & ~(MIXER_GETLINECONTROLSF_ALL |
4005 MIXER_GETLINECONTROLSF_ONEBYID |
4006 MIXER_GETLINECONTROLSF_ONEBYTYPE |
4007 MIXER_OBJECTF_HMIXER |
4008 MIXER_OBJECTF_MIXER)){
4009 WARN("Unknown GetLineControls flag: %x\n", fdwControls);
4010 return MMSYSERR_INVALFLAG;
4013 if(!lpmlcW || lpmlcW->cbStruct < sizeof(*lpmlcW) || !lpmlcW->pamxctrl)
4014 return MMSYSERR_INVALPARAM;
4016 TRACE("dwLineID: %u\n", lpmlcW->dwLineID);
4017 TRACE("dwControl: %x\n", lpmlcW->u.dwControlID);
4018 TRACE("cControls: %u\n", lpmlcW->cControls);
4020 mmdevice = WINMM_GetMixerMMDevice(hmix, fdwControls, NULL);
4022 return MMSYSERR_INVALHANDLE;
4024 switch(fdwControls & MIXER_GETLINECONTROLSF_QUERYMASK){
4025 case MIXER_GETLINECONTROLSF_ALL:
4026 if(lpmlcW->cControls != 2)
4027 return MMSYSERR_INVALPARAM;
4028 if(lpmlcW->cbmxctrl < sizeof(MIXERCONTROLW))
4029 return MMSYSERR_INVALPARAM;
4030 if(lpmlcW->dwLineID != 0 && lpmlcW->dwLineID != 0xFFFF0000)
4031 return MIXERR_INVALLINE;
4032 WINMM_GetVolumeLineControl(mmdevice, lpmlcW->dwLineID,
4033 &lpmlcW->pamxctrl[0], fdwControls);
4034 WINMM_GetMuteLineControl(mmdevice, lpmlcW->dwLineID,
4035 &lpmlcW->pamxctrl[1], fdwControls);
4036 return MMSYSERR_NOERROR;
4037 case MIXER_GETLINECONTROLSF_ONEBYID:
4038 if(lpmlcW->cControls != 1)
4039 return MMSYSERR_INVALPARAM;
4040 if(lpmlcW->cbmxctrl < sizeof(MIXERCONTROLW))
4041 return MMSYSERR_INVALPARAM;
4042 if(lpmlcW->dwLineID != 0 && lpmlcW->dwLineID != 0xFFFF0000)
4043 return MIXERR_INVALLINE;
4044 if(lpmlcW->u.dwControlID == 0)
4045 return WINMM_GetVolumeLineControl(mmdevice, lpmlcW->dwLineID,
4046 lpmlcW->pamxctrl, fdwControls);
4047 if(lpmlcW->u.dwControlID == 1)
4048 return WINMM_GetMuteLineControl(mmdevice, lpmlcW->dwLineID,
4049 lpmlcW->pamxctrl, fdwControls);
4050 return MMSYSERR_NOTSUPPORTED;
4051 case MIXER_GETLINECONTROLSF_ONEBYTYPE:
4052 if(lpmlcW->cControls != 1)
4053 return MMSYSERR_INVALPARAM;
4054 if(lpmlcW->cbmxctrl < sizeof(MIXERCONTROLW))
4055 return MMSYSERR_INVALPARAM;
4056 if(lpmlcW->dwLineID != 0 && lpmlcW->dwLineID != 0xFFFF0000)
4057 return MIXERR_INVALLINE;
4058 if(lpmlcW->u.dwControlType == MIXERCONTROL_CONTROLTYPE_VOLUME)
4059 return WINMM_GetVolumeLineControl(mmdevice, lpmlcW->dwLineID,
4060 lpmlcW->pamxctrl, fdwControls);
4061 if(lpmlcW->u.dwControlType == MIXERCONTROL_CONTROLTYPE_MUTE)
4062 return WINMM_GetMuteLineControl(mmdevice, lpmlcW->dwLineID,
4063 lpmlcW->pamxctrl, fdwControls);
4064 return MMSYSERR_NOTSUPPORTED;
4067 return MMSYSERR_NOTSUPPORTED;
4070 static UINT WINMM_GetSourceLineInfo(WINMM_MMDevice *mmdevice, UINT mmdev_index,
4071 MIXERLINEW *info, DWORD flags)
4074 if(mmdevice->in_caps.szPname[0] != '\0')
4077 if(info->dwSource != 0)
4078 return MIXERR_INVALLINE;
4080 info->dwDestination = 0;
4082 info->fdwLine = MIXERLINE_LINEF_ACTIVE | MIXERLINE_LINEF_SOURCE;
4083 info->cConnections = 0;
4084 info->cControls = 2;
4085 /* volume & mute always affect all channels, so claim 1 channel */
4086 info->cChannels = 1;
4087 info->Target.dwDeviceID = mmdev_index;
4088 info->Target.wMid = ~0;
4089 info->Target.wPid = ~0;
4090 info->Target.vDriverVersion = 0;
4092 lstrcpyW(info->szShortName, volumeW);
4093 lstrcpyW(info->szName, mastervolumeW);
4096 info->dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
4097 info->Target.dwType = MIXERLINE_TARGETTYPE_WAVEOUT;
4098 memcpy(info->Target.szPname, mmdevice->out_caps.szPname,
4099 sizeof(info->Target.szPname));
4101 info->dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
4102 info->Target.dwType = MIXERLINE_TARGETTYPE_UNDEFINED;
4103 info->Target.szPname[0] = '\0';
4106 return MMSYSERR_NOERROR;
4109 static UINT WINMM_GetDestinationLineInfo(WINMM_MMDevice *mmdevice,
4110 UINT mmdev_index, MIXERLINEW *info, DWORD flags)
4113 if(mmdevice->in_caps.szPname[0] != '\0')
4116 if(info->dwDestination != 0)
4117 return MIXERR_INVALLINE;
4119 info->dwSource = 0xFFFFFFFF;
4120 info->dwLineID = 0xFFFF0000;
4121 info->fdwLine = MIXERLINE_LINEF_ACTIVE;
4122 info->cConnections = 1;
4123 info->cControls = 2;
4125 lstrcpyW(info->szShortName, volumeW);
4126 lstrcpyW(info->szName, mastervolumeW);
4128 info->Target.dwDeviceID = mmdev_index;
4129 info->Target.wMid = ~0;
4130 info->Target.wPid = ~0;
4131 info->Target.vDriverVersion = 0;
4134 info->dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
4135 info->cChannels = mmdevice->out_caps.wChannels;
4136 info->Target.dwType = MIXERLINE_TARGETTYPE_UNDEFINED;
4137 info->Target.szPname[0] = '\0';
4139 info->dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
4140 info->cChannels = mmdevice->in_caps.wChannels;
4141 info->Target.dwType = MIXERLINE_TARGETTYPE_WAVEIN;
4142 memcpy(info->Target.szPname, mmdevice->in_caps.szPname,
4143 sizeof(info->Target.szPname));
4146 return MMSYSERR_NOERROR;
4149 static UINT WINMM_GetComponentTypeLineInfo(WINMM_MMDevice *mmdevice,
4150 UINT mmdev_index, MIXERLINEW *info, DWORD flags)
4153 if(mmdevice->in_caps.szPname[0] != '\0')
4156 if(info->dwComponentType == MIXERLINE_COMPONENTTYPE_DST_WAVEIN){
4158 return MIXERR_INVALLINE;
4159 info->dwDestination = 0;
4160 return WINMM_GetDestinationLineInfo(mmdevice, mmdev_index, info, flags);
4163 if(info->dwComponentType == MIXERLINE_COMPONENTTYPE_DST_SPEAKERS){
4165 return MIXERR_INVALLINE;
4166 info->dwDestination = 0;
4167 return WINMM_GetDestinationLineInfo(mmdevice, mmdev_index, info, flags);
4170 if(info->dwComponentType == MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE){
4172 return MIXERR_INVALLINE;
4174 return WINMM_GetSourceLineInfo(mmdevice, mmdev_index, info, flags);
4177 if(info->dwComponentType == MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT){
4179 return MIXERR_INVALLINE;
4181 return WINMM_GetSourceLineInfo(mmdevice, mmdev_index, info, flags);
4184 TRACE("Returning INVALLINE on this component type: %u\n",
4185 info->dwComponentType);
4187 return MIXERR_INVALLINE;
4190 static UINT WINMM_GetLineIDLineInfo(WINMM_MMDevice *mmdevice,
4191 UINT mmdev_index, MIXERLINEW *info, DWORD flags)
4193 if(info->dwLineID == 0xFFFF0000){
4194 info->dwDestination = 0;
4195 return WINMM_GetDestinationLineInfo(mmdevice, mmdev_index, info, flags);
4198 if(info->dwLineID == 0){
4200 return WINMM_GetSourceLineInfo(mmdevice, mmdev_index, info, flags);
4203 TRACE("Returning INVALLINE on this dwLineID: %u\n", info->dwLineID);
4204 return MIXERR_INVALLINE;
4207 /**************************************************************************
4208 * mixerGetLineInfoW [WINMM.@]
4210 UINT WINAPI mixerGetLineInfoW(HMIXEROBJ hmix, LPMIXERLINEW lpmliW, DWORD fdwInfo)
4213 WINMM_MMDevice *mmdevice;
4216 TRACE("(%p, %p, %x)\n", hmix, lpmliW, fdwInfo);
4218 hr = WINMM_InitMMDevices();
4220 return MMSYSERR_NODRIVER;
4222 if(!lpmliW || lpmliW->cbStruct < sizeof(MIXERLINEW))
4223 return MMSYSERR_INVALPARAM;
4225 TRACE("dwDestination: %u\n", lpmliW->dwDestination);
4226 TRACE("dwSource: %u\n", lpmliW->dwSource);
4227 TRACE("dwLineID: %u\n", lpmliW->dwLineID);
4228 TRACE("fdwLine: 0x%x\n", lpmliW->fdwLine);
4229 TRACE("dwComponentType: 0x%x\n", lpmliW->dwComponentType);
4231 if(fdwInfo & ~(MIXER_GETLINEINFOF_COMPONENTTYPE |
4232 MIXER_GETLINEINFOF_DESTINATION |
4233 MIXER_GETLINEINFOF_LINEID |
4234 MIXER_GETLINEINFOF_SOURCE |
4235 MIXER_GETLINEINFOF_TARGETTYPE |
4236 MIXER_OBJECTF_HMIXER |
4237 MIXER_OBJECTF_MIXER)){
4238 WARN("Unknown GetLineInfo flag: %x\n", fdwInfo);
4239 return MMSYSERR_INVALFLAG;
4242 mmdevice = WINMM_GetMixerMMDevice(hmix, fdwInfo, &mmdev_index);
4244 return MMSYSERR_INVALHANDLE;
4246 switch(fdwInfo & MIXER_GETLINEINFOF_QUERYMASK){
4247 case MIXER_GETLINEINFOF_DESTINATION:
4248 return WINMM_GetDestinationLineInfo(mmdevice, mmdev_index, lpmliW,
4250 case MIXER_GETLINEINFOF_SOURCE:
4251 return WINMM_GetSourceLineInfo(mmdevice, mmdev_index, lpmliW, fdwInfo);
4252 case MIXER_GETLINEINFOF_COMPONENTTYPE:
4253 return WINMM_GetComponentTypeLineInfo(mmdevice, mmdev_index, lpmliW,
4255 case MIXER_GETLINEINFOF_LINEID:
4256 return WINMM_GetLineIDLineInfo(mmdevice, mmdev_index, lpmliW, fdwInfo);
4257 case MIXER_GETLINEINFOF_TARGETTYPE:
4258 FIXME("TARGETTYPE flag not implemented!\n");
4259 return MIXERR_INVALLINE;
4262 TRACE("Returning INVALFLAG on these flags: %x\n", fdwInfo & MIXER_GETLINEINFOF_QUERYMASK);
4263 return MMSYSERR_INVALFLAG;
4266 /**************************************************************************
4267 * mixerGetLineInfoA [WINMM.@]
4269 UINT WINAPI mixerGetLineInfoA(HMIXEROBJ hmix, LPMIXERLINEA lpmliA,
4275 TRACE("(%p, %p, %x)\n", hmix, lpmliA, fdwInfo);
4277 if (lpmliA == NULL || lpmliA->cbStruct != sizeof(*lpmliA))
4278 return MMSYSERR_INVALPARAM;
4280 mliW.cbStruct = sizeof(mliW);
4281 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
4282 case MIXER_GETLINEINFOF_COMPONENTTYPE:
4283 mliW.dwComponentType = lpmliA->dwComponentType;
4285 case MIXER_GETLINEINFOF_DESTINATION:
4286 mliW.dwDestination = lpmliA->dwDestination;
4288 case MIXER_GETLINEINFOF_LINEID:
4289 mliW.dwLineID = lpmliA->dwLineID;
4291 case MIXER_GETLINEINFOF_SOURCE:
4292 mliW.dwDestination = lpmliA->dwDestination;
4293 mliW.dwSource = lpmliA->dwSource;
4295 case MIXER_GETLINEINFOF_TARGETTYPE:
4296 mliW.Target.dwType = lpmliA->Target.dwType;
4297 mliW.Target.wMid = lpmliA->Target.wMid;
4298 mliW.Target.wPid = lpmliA->Target.wPid;
4299 mliW.Target.vDriverVersion = lpmliA->Target.vDriverVersion;
4300 MultiByteToWideChar( CP_ACP, 0, lpmliA->Target.szPname, -1, mliW.Target.szPname, sizeof(mliW.Target.szPname)/sizeof(WCHAR));
4303 WARN("Unsupported fdwControls=0x%08x\n", fdwInfo);
4304 return MMSYSERR_INVALFLAG;
4307 ret = mixerGetLineInfoW(hmix, &mliW, fdwInfo);
4309 if(ret == MMSYSERR_NOERROR)
4311 lpmliA->dwDestination = mliW.dwDestination;
4312 lpmliA->dwSource = mliW.dwSource;
4313 lpmliA->dwLineID = mliW.dwLineID;
4314 lpmliA->fdwLine = mliW.fdwLine;
4315 lpmliA->dwUser = mliW.dwUser;
4316 lpmliA->dwComponentType = mliW.dwComponentType;
4317 lpmliA->cChannels = mliW.cChannels;
4318 lpmliA->cConnections = mliW.cConnections;
4319 lpmliA->cControls = mliW.cControls;
4320 WideCharToMultiByte( CP_ACP, 0, mliW.szShortName, -1, lpmliA->szShortName,
4321 sizeof(lpmliA->szShortName), NULL, NULL);
4322 WideCharToMultiByte( CP_ACP, 0, mliW.szName, -1, lpmliA->szName,
4323 sizeof(lpmliA->szName), NULL, NULL );
4324 lpmliA->Target.dwType = mliW.Target.dwType;
4325 lpmliA->Target.dwDeviceID = mliW.Target.dwDeviceID;
4326 lpmliA->Target.wMid = mliW.Target.wMid;
4327 lpmliA->Target.wPid = mliW.Target.wPid;
4328 lpmliA->Target.vDriverVersion = mliW.Target.vDriverVersion;
4329 WideCharToMultiByte( CP_ACP, 0, mliW.Target.szPname, -1, lpmliA->Target.szPname,
4330 sizeof(lpmliA->Target.szPname), NULL, NULL );
4335 /**************************************************************************
4336 * mixerSetControlDetails [WINMM.@]
4338 UINT WINAPI mixerSetControlDetails(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcd,
4341 WINMM_ControlDetails details;
4343 TRACE("(%p, %p, %x)\n", hmix, lpmcd, fdwDetails);
4345 if(!WINMM_StartDevicesThread())
4346 return MMSYSERR_NODRIVER;
4348 if((fdwDetails & MIXER_SETCONTROLDETAILSF_QUERYMASK) ==
4349 MIXER_SETCONTROLDETAILSF_CUSTOM)
4350 return MMSYSERR_NOTSUPPORTED;
4353 return MMSYSERR_INVALPARAM;
4355 TRACE("dwControlID: %u\n", lpmcd->dwControlID);
4357 details.hmix = hmix;
4358 details.details = lpmcd;
4359 details.flags = fdwDetails;
4361 return SendMessageW(g_devices_hwnd, MXDM_SETCONTROLDETAILS,
4362 (DWORD_PTR)&details, 0);
4365 /**************************************************************************
4366 * mixerMessage [WINMM.@]
4368 DWORD WINAPI mixerMessage(HMIXER hmix, UINT uMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
4370 TRACE("(%p, %d, %lx, %lx)\n", hmix, uMsg, dwParam1, dwParam2);
4372 return MMSYSERR_NOTSUPPORTED;