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
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 #define MAX_DEVICES 256
73 typedef struct _WINMM_CBInfo
{
80 struct _WINMM_MMDevice
;
81 typedef struct _WINMM_MMDevice WINMM_MMDevice
;
83 typedef struct _WINMM_Device
{
92 IAudioRenderClient
*render
;
93 IAudioCaptureClient
*capture
;
95 IAudioStreamVolume
*volume
;
97 HACMSTREAM acm_handle
;
98 ACMSTREAMHEADER acm_hdr
;
101 WAVEHDR
*first
, *last
, *playing
, *loop_start
;
105 UINT32 bytes_per_frame
, samples_per_sec
, ofs_bytes
, played_frames
;
107 /* stored in frames of sample rate, *not* AC::GetFrequency */
108 UINT64 last_clock_pos
;
111 CRITICAL_SECTION lock
;
113 WINMM_MMDevice
*parent
;
116 struct _WINMM_MMDevice
{
117 WAVEOUTCAPSW out_caps
; /* must not be modified outside of WINMM_InitMMDevices*/
118 WAVEINCAPSW in_caps
; /* must not be modified outside of WINMM_InitMMDevices*/
121 ISimpleAudioVolume
*volume
;
125 /* HMIXER format is the same as the HWAVE format, but the I bits are
126 * replaced by the value of this counter, to keep each HMIXER unique */
129 CRITICAL_SECTION lock
;
131 WINMM_Device
*devices
[MAX_DEVICES
];
134 static WINMM_MMDevice
*g_out_mmdevices
;
135 static UINT g_outmmdevices_count
;
137 static WINMM_MMDevice
*g_in_mmdevices
;
138 static UINT g_inmmdevices_count
;
140 static IMMDeviceEnumerator
*g_devenum
;
142 #define WINMM_WM_QUIT WM_USER
144 static CRITICAL_SECTION g_devthread_lock
;
145 static CRITICAL_SECTION_DEBUG g_devthread_lock_debug
=
147 0, 0, &g_devthread_lock
,
148 { &g_devthread_lock_debug
.ProcessLocksList
, &g_devthread_lock_debug
.ProcessLocksList
},
149 0, 0, { (DWORD_PTR
)(__FILE__
": g_devthread_lock") }
151 static CRITICAL_SECTION g_devthread_lock
= { &g_devthread_lock_debug
, -1, 0, 0, 0, 0 };
152 static HANDLE g_devices_thread
;
153 static HWND g_devices_hwnd
;
155 static UINT g_devhandle_count
;
156 static HANDLE
*g_device_handles
;
157 static WINMM_Device
**g_handle_devices
;
159 typedef struct _WINMM_OpenInfo
{
162 WAVEFORMATEX
*format
;
168 typedef struct _WINMM_ControlDetails
{
170 MIXERCONTROLDETAILS
*details
;
172 } WINMM_ControlDetails
;
174 typedef struct _WINMM_QueryInterfaceInfo
{
179 } WINMM_QueryInterfaceInfo
;
181 static LRESULT
WOD_Open(WINMM_OpenInfo
*info
);
182 static LRESULT
WOD_Close(HWAVEOUT hwave
);
183 static LRESULT
WID_Open(WINMM_OpenInfo
*info
);
184 static LRESULT
WID_Close(HWAVEIN hwave
);
186 void WINMM_DeleteWaveform(void)
191 for(i
= 0; i
< g_outmmdevices_count
; ++i
){
192 WINMM_MMDevice
*mmdevice
= &g_out_mmdevices
[i
];
193 for(j
= 0; j
< MAX_DEVICES
&& mmdevice
->devices
[j
]; ++j
){
194 WINMM_Device
*device
= mmdevice
->devices
[j
];
195 SendMessageW(g_devices_hwnd
, WODM_CLOSE
, (WPARAM
)device
->handle
, 0);
199 for(i
= 0; i
< g_inmmdevices_count
; ++i
){
200 WINMM_MMDevice
*mmdevice
= &g_in_mmdevices
[i
];
201 for(j
= 0; j
< MAX_DEVICES
&& mmdevice
->devices
[j
]; ++j
){
202 WINMM_Device
*device
= mmdevice
->devices
[j
];
203 SendMessageW(g_devices_hwnd
, WIDM_CLOSE
, (WPARAM
)device
->handle
, 0);
207 SendMessageW(g_devices_hwnd
, WINMM_WM_QUIT
, 0, 0);
209 for(i
= 0; i
< g_outmmdevices_count
; ++i
){
210 WINMM_MMDevice
*mmdevice
= &g_out_mmdevices
[i
];
212 for(j
= 0; j
< MAX_DEVICES
&& mmdevice
->devices
[j
]; ++j
){
213 WINMM_Device
*device
= mmdevice
->devices
[j
];
215 CloseHandle(device
->handle
);
216 DeleteCriticalSection(&device
->lock
);
220 ISimpleAudioVolume_Release(mmdevice
->volume
);
221 CoTaskMemFree(mmdevice
->dev_id
);
222 DeleteCriticalSection(&mmdevice
->lock
);
225 for(i
= 0; i
< g_inmmdevices_count
; ++i
){
226 WINMM_MMDevice
*mmdevice
= &g_in_mmdevices
[i
];
228 for(j
= 0; j
< MAX_DEVICES
&& mmdevice
->devices
[j
]; ++j
){
229 WINMM_Device
*device
= mmdevice
->devices
[j
];
231 CloseHandle(device
->handle
);
232 DeleteCriticalSection(&device
->lock
);
236 ISimpleAudioVolume_Release(mmdevice
->volume
);
237 CoTaskMemFree(mmdevice
->dev_id
);
238 DeleteCriticalSection(&mmdevice
->lock
);
241 HeapFree(GetProcessHeap(), 0, g_out_mmdevices
);
242 HeapFree(GetProcessHeap(), 0, g_in_mmdevices
);
244 HeapFree(GetProcessHeap(), 0, g_device_handles
);
245 HeapFree(GetProcessHeap(), 0, g_handle_devices
);
248 DeleteCriticalSection(&g_devthread_lock
);
251 static inline HWAVE
WINMM_MakeHWAVE(UINT mmdevice
, BOOL is_out
, UINT device
)
253 return ULongToHandle((1 << 15) | ((!!is_out
) << 14) |
254 (mmdevice
<< 8) | device
);
257 static inline void WINMM_DecomposeHWAVE(HWAVE hwave
, UINT
*mmdevice_index
,
258 BOOL
*is_out
, UINT
*device_index
, UINT
*junk
)
260 ULONG32 l
= HandleToULong(hwave
);
261 *device_index
= l
& 0xFF;
262 *mmdevice_index
= (l
>> 8) & 0x3F;
263 *is_out
= (l
>> 14) & 0x1;
267 static void WINMM_InitDevice(WINMM_Device
*device
,
268 WINMM_MMDevice
*parent
, HWAVE hwave
)
270 InitializeCriticalSection(&device
->lock
);
271 device
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": WINMM_Device.lock");
273 device
->handle
= hwave
;
274 device
->parent
= parent
;
277 /* finds the first unused Device, marks it as "open", and returns
278 * a pointer to the device
280 * IMPORTANT: it is the caller's responsibility to release the device's lock
283 static WINMM_Device
*WINMM_FindUnusedDevice(BOOL is_out
, UINT mmdevice_index
)
285 WINMM_MMDevice
*mmdevice
;
289 mmdevice
= &g_out_mmdevices
[mmdevice_index
];
291 mmdevice
= &g_in_mmdevices
[mmdevice_index
];
293 EnterCriticalSection(&mmdevice
->lock
);
294 for(i
= 0; i
< MAX_DEVICES
; ++i
){
295 WINMM_Device
*device
= mmdevice
->devices
[i
];
298 device
= mmdevice
->devices
[i
] = HeapAlloc(GetProcessHeap(),
299 HEAP_ZERO_MEMORY
, sizeof(WINMM_Device
));
301 LeaveCriticalSection(&mmdevice
->lock
);
305 WINMM_InitDevice(device
, mmdevice
,
306 WINMM_MakeHWAVE(mmdevice_index
, is_out
, i
));
307 EnterCriticalSection(&device
->lock
);
309 EnterCriticalSection(&device
->lock
);
312 LeaveCriticalSection(&mmdevice
->lock
);
314 TRACE("Found free device: mmdevice: %u, device id: %u\n",
319 LeaveCriticalSection(&device
->lock
);
322 LeaveCriticalSection(&mmdevice
->lock
);
324 TRACE("All devices in use: mmdevice: %u\n", mmdevice_index
);
329 static inline BOOL
WINMM_ValidateAndLock(WINMM_Device
*device
)
334 EnterCriticalSection(&device
->lock
);
337 LeaveCriticalSection(&device
->lock
);
344 static WINMM_Device
*WINMM_GetDeviceFromHWAVE(HWAVE hwave
)
346 WINMM_MMDevice
*mmdevice
;
347 WINMM_Device
*device
;
348 UINT mmdevice_index
, device_index
, junk
;
351 WINMM_DecomposeHWAVE(hwave
, &mmdevice_index
, &is_out
, &device_index
, &junk
);
356 if(mmdevice_index
>= (is_out
? g_outmmdevices_count
: g_inmmdevices_count
))
360 mmdevice
= &g_out_mmdevices
[mmdevice_index
];
362 mmdevice
= &g_in_mmdevices
[mmdevice_index
];
364 EnterCriticalSection(&mmdevice
->lock
);
366 device
= mmdevice
->devices
[device_index
];
368 LeaveCriticalSection(&mmdevice
->lock
);
373 /* Note: NotifyClient should never be called while holding the device lock
374 * since the client may call wave* functions from within the callback. */
375 static inline void WINMM_NotifyClient(WINMM_CBInfo
*info
, WORD msg
, DWORD_PTR param1
,
378 DriverCallback(info
->callback
, info
->flags
, (HDRVR
)info
->hwave
,
379 msg
, info
->user
, param1
, param2
);
382 static HRESULT
WINMM_GetFriendlyName(IMMDevice
*device
, WCHAR
*out
,
389 hr
= IMMDevice_OpenPropertyStore(device
, STGM_READ
, &ps
);
393 PropVariantInit(&var
);
395 hr
= IPropertyStore_GetValue(ps
,
396 (PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &var
);
398 IPropertyStore_Release(ps
);
402 lstrcpynW(out
, var
.u
.pwszVal
, outlen
);
404 PropVariantClear(&var
);
406 IPropertyStore_Release(ps
);
411 static HRESULT
WINMM_TestFormat(IAudioClient
*client
, DWORD rate
, DWORD depth
,
414 WAVEFORMATEX fmt
, *junk
;
417 fmt
.wFormatTag
= WAVE_FORMAT_PCM
;
418 fmt
.nChannels
= channels
;
419 fmt
.nSamplesPerSec
= rate
;
420 fmt
.wBitsPerSample
= depth
;
421 fmt
.nBlockAlign
= (channels
* depth
) / 8;
422 fmt
.nAvgBytesPerSec
= rate
* fmt
.nBlockAlign
;
425 hr
= IAudioClient_IsFormatSupported(client
, AUDCLNT_SHAREMODE_SHARED
,
433 static struct _TestFormat
{
438 } formats_to_test
[] = {
439 { WAVE_FORMAT_1M08
, 11025, 8, 1 },
440 { WAVE_FORMAT_1M16
, 11025, 16, 1 },
441 { WAVE_FORMAT_1S08
, 11025, 8, 2 },
442 { WAVE_FORMAT_1S16
, 11025, 16, 2 },
443 { WAVE_FORMAT_2M08
, 22050, 8, 1 },
444 { WAVE_FORMAT_2M16
, 22050, 16, 1 },
445 { WAVE_FORMAT_2S08
, 22050, 8, 2 },
446 { WAVE_FORMAT_2S16
, 22050, 16, 2 },
447 { WAVE_FORMAT_4M08
, 44100, 8, 1 },
448 { WAVE_FORMAT_4M16
, 44100, 16, 1 },
449 { WAVE_FORMAT_4S08
, 44100, 8, 2 },
450 { WAVE_FORMAT_4S16
, 44100, 16, 2 },
451 { WAVE_FORMAT_48M08
, 48000, 8, 1 },
452 { WAVE_FORMAT_48M16
, 48000, 16, 1 },
453 { WAVE_FORMAT_48S08
, 48000, 8, 2 },
454 { WAVE_FORMAT_48S16
, 48000, 16, 2 },
455 { WAVE_FORMAT_96M08
, 96000, 8, 1 },
456 { WAVE_FORMAT_96M16
, 96000, 16, 1 },
457 { WAVE_FORMAT_96S08
, 96000, 8, 2 },
458 { WAVE_FORMAT_96S16
, 96000, 16, 2 },
462 static DWORD
WINMM_GetSupportedFormats(IMMDevice
*device
)
466 struct _TestFormat
*fmt
;
467 IAudioClient
*client
;
469 hr
= IMMDevice_Activate(device
, &IID_IAudioClient
,
470 CLSCTX_INPROC_SERVER
, NULL
, (void**)&client
);
474 for(fmt
= formats_to_test
; fmt
->flag
; ++fmt
){
475 hr
= WINMM_TestFormat(client
, fmt
->rate
, fmt
->depth
, fmt
->channels
);
480 IAudioClient_Release(client
);
485 static HRESULT
WINMM_InitMMDevice(EDataFlow flow
, IMMDevice
*device
,
486 WINMM_MMDevice
*dev
, UINT index
)
491 dev
->out_caps
.wMid
= 0xFF;
492 dev
->out_caps
.wPid
= 0xFF;
493 dev
->out_caps
.vDriverVersion
= 0x00010001;
494 dev
->out_caps
.dwFormats
= WINMM_GetSupportedFormats(device
);
495 dev
->out_caps
.wReserved1
= 0;
496 dev
->out_caps
.dwSupport
= WAVECAPS_LRVOLUME
| WAVECAPS_VOLUME
|
497 WAVECAPS_SAMPLEACCURATE
;
498 dev
->out_caps
.wChannels
= 2;
499 dev
->out_caps
.szPname
[0] = '\0';
501 hr
= WINMM_GetFriendlyName(device
, dev
->out_caps
.szPname
,
502 sizeof(dev
->out_caps
.szPname
) /
503 sizeof(*dev
->out_caps
.szPname
));
507 dev
->in_caps
.wMid
= 0xFF;
508 dev
->in_caps
.wPid
= 0xFF;
509 dev
->in_caps
.vDriverVersion
= 0x00010001;
510 dev
->in_caps
.dwFormats
= WINMM_GetSupportedFormats(device
);
511 dev
->in_caps
.wReserved1
= 0;
512 dev
->in_caps
.wChannels
= 2;
513 dev
->in_caps
.szPname
[0] = '\0';
515 hr
= WINMM_GetFriendlyName(device
, dev
->in_caps
.szPname
,
516 sizeof(dev
->in_caps
.szPname
) /
517 sizeof(*dev
->in_caps
.szPname
));
522 hr
= IMMDevice_GetId(device
, &dev
->dev_id
);
526 CoCreateGuid(&dev
->session
);
528 InitializeCriticalSection(&dev
->lock
);
529 dev
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": WINMM_Device.lock");
534 static HRESULT
WINMM_EnumDevices(WINMM_MMDevice
**devices
, UINT
*devcount
,
535 EDataFlow flow
, IMMDeviceEnumerator
*devenum
)
537 IMMDeviceCollection
*devcoll
;
540 hr
= IMMDeviceEnumerator_EnumAudioEndpoints(devenum
, flow
,
541 DEVICE_STATE_ACTIVE
, &devcoll
);
545 hr
= IMMDeviceCollection_GetCount(devcoll
, devcount
);
547 IMMDeviceCollection_Release(devcoll
);
553 IMMDevice
*def_dev
= NULL
;
555 *devices
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
556 sizeof(WINMM_MMDevice
) * (*devcount
));
558 IMMDeviceCollection_Release(devcoll
);
559 return E_OUTOFMEMORY
;
564 /* make sure that device 0 is the default device */
565 hr
= IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum
,
566 flow
, eConsole
, &def_dev
);
568 WINMM_InitMMDevice(flow
, def_dev
, &(*devices
)[0], 0);
572 for(n
= 0; n
< *devcount
; ++n
){
575 hr
= IMMDeviceCollection_Item(devcoll
, n
, &device
);
577 if(device
!= def_dev
){
578 WINMM_InitMMDevice(flow
, device
, &(*devices
)[count
], count
);
582 IMMDevice_Release(device
);
587 IMMDevice_Release(def_dev
);
592 IMMDeviceCollection_Release(devcoll
);
597 static HRESULT
WINMM_InitMMDevices(void)
600 IMMDeviceEnumerator
*devenum
= NULL
;
602 if(g_outmmdevices_count
|| g_inmmdevices_count
)
605 init_hr
= CoInitialize(NULL
);
607 hr
= CoCreateInstance(&CLSID_MMDeviceEnumerator
, NULL
,
608 CLSCTX_INPROC_SERVER
, &IID_IMMDeviceEnumerator
, (void**)&devenum
);
612 hr
= WINMM_EnumDevices(&g_out_mmdevices
, &g_outmmdevices_count
, eRender
, devenum
);
614 g_outmmdevices_count
= 0;
615 g_inmmdevices_count
= 0;
619 hr
= WINMM_EnumDevices(&g_in_mmdevices
, &g_inmmdevices_count
, eCapture
, devenum
);
621 g_inmmdevices_count
= 0;
627 IMMDeviceEnumerator_Release(devenum
);
628 if(SUCCEEDED(init_hr
))
634 static inline BOOL
WINMM_IsMapper(UINT device
)
636 return (device
== WAVE_MAPPER
|| device
== (UINT16
)WAVE_MAPPER
);
639 static MMRESULT
WINMM_TryDeviceMapping(WINMM_OpenInfo
*info
, WORD channels
,
640 DWORD freq
, DWORD bits_per_samp
, BOOL is_out
)
642 WINMM_Device
*device
;
647 TRACE("format: %u, channels: %u, sample rate: %u, bit depth: %u\n",
648 WAVE_FORMAT_PCM
, channels
, freq
, bits_per_samp
);
650 target
.wFormatTag
= WAVE_FORMAT_PCM
;
651 target
.nChannels
= channels
;
652 target
.nSamplesPerSec
= freq
;
653 target
.wBitsPerSample
= bits_per_samp
;
654 target
.nBlockAlign
= (target
.nChannels
* target
.wBitsPerSample
) / 8;
655 target
.nAvgBytesPerSec
= target
.nSamplesPerSec
* target
.nBlockAlign
;
659 mr
= acmStreamOpen(NULL
, NULL
, info
->format
, &target
, NULL
, 0,
660 0, ACM_STREAMOPENF_QUERY
);
662 mr
= acmStreamOpen(NULL
, NULL
, &target
, info
->format
, NULL
, 0,
663 0, ACM_STREAMOPENF_QUERY
);
664 if(mr
!= MMSYSERR_NOERROR
)
667 /* ACM can convert from src->dst, so try to find a device
668 * that supports dst */
670 if(WINMM_IsMapper(info
->req_device
)){
671 for(i
= 0; i
< g_outmmdevices_count
; ++i
){
672 WINMM_OpenInfo l_info
= *info
;
673 l_info
.req_device
= i
;
674 l_info
.format
= &target
;
675 mr
= WOD_Open(&l_info
);
676 if(mr
== MMSYSERR_NOERROR
){
677 info
->handle
= l_info
.handle
;
682 WINMM_OpenInfo l_info
= *info
;
683 l_info
.flags
&= ~WAVE_MAPPED
;
684 l_info
.format
= &target
;
685 mr
= WOD_Open(&l_info
);
686 if(mr
== MMSYSERR_NOERROR
)
687 info
->handle
= l_info
.handle
;
690 if(WINMM_IsMapper(info
->req_device
)){
691 for(i
= 0; i
< g_inmmdevices_count
; ++i
){
692 WINMM_OpenInfo l_info
= *info
;
693 l_info
.req_device
= i
;
694 l_info
.format
= &target
;
695 mr
= WID_Open(&l_info
);
696 if(mr
== MMSYSERR_NOERROR
){
697 info
->handle
= l_info
.handle
;
702 WINMM_OpenInfo l_info
= *info
;
703 l_info
.flags
&= ~WAVE_MAPPED
;
704 l_info
.format
= &target
;
705 mr
= WID_Open(&l_info
);
706 if(mr
== MMSYSERR_NOERROR
)
707 info
->handle
= l_info
.handle
;
710 if(mr
!= MMSYSERR_NOERROR
)
711 return WAVERR_BADFORMAT
;
713 device
= WINMM_GetDeviceFromHWAVE(info
->handle
);
715 return MMSYSERR_INVALHANDLE
;
717 /* set up the ACM stream */
719 mr
= acmStreamOpen(&device
->acm_handle
, NULL
, info
->format
, &target
,
722 mr
= acmStreamOpen(&device
->acm_handle
, NULL
, &target
, info
->format
,
724 if(mr
!= MMSYSERR_NOERROR
){
726 WOD_Close((HWAVEOUT
)info
->handle
);
728 WID_Close((HWAVEIN
)info
->handle
);
733 return MMSYSERR_NOERROR
;
736 static MMRESULT
WINMM_MapDevice(WINMM_OpenInfo
*info
, BOOL is_out
)
740 WAVEFORMATEXTENSIBLE
*fmtex
= (WAVEFORMATEXTENSIBLE
*)info
->format
;
742 TRACE("(%p, %d)\n", info
, is_out
);
744 /* try to find a direct match */
746 WINMM_OpenInfo l_info
= *info
;
747 if(WINMM_IsMapper(info
->req_device
)){
748 for(i
= 0; i
< g_outmmdevices_count
; ++i
){
749 l_info
.req_device
= i
;
750 mr
= WOD_Open(&l_info
);
751 if(mr
== MMSYSERR_NOERROR
){
752 info
->handle
= l_info
.handle
;
757 l_info
.flags
&= ~WAVE_MAPPED
;
758 mr
= WOD_Open(&l_info
);
759 if(mr
== MMSYSERR_NOERROR
){
760 info
->handle
= l_info
.handle
;
765 WINMM_OpenInfo l_info
= *info
;
766 if(WINMM_IsMapper(info
->req_device
)){
767 for(i
= 0; i
< g_inmmdevices_count
; ++i
){
768 l_info
.req_device
= i
;
769 mr
= WID_Open(&l_info
);
770 if(mr
== MMSYSERR_NOERROR
){
771 info
->handle
= l_info
.handle
;
776 l_info
.flags
&= ~WAVE_MAPPED
;
777 mr
= WID_Open(&l_info
);
778 if(mr
== MMSYSERR_NOERROR
){
779 info
->handle
= l_info
.handle
;
785 /* no direct match, so set up the ACM stream */
786 if(info
->format
->wFormatTag
!= WAVE_FORMAT_PCM
&&
787 !(info
->format
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
788 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
))){
789 /* convert to PCM format if it's not already */
790 mr
= WINMM_TryDeviceMapping(info
, info
->format
->nChannels
,
791 info
->format
->nSamplesPerSec
, 16, is_out
);
792 if(mr
== MMSYSERR_NOERROR
)
795 mr
= WINMM_TryDeviceMapping(info
, info
->format
->nChannels
,
796 info
->format
->nSamplesPerSec
, 8, is_out
);
797 if(mr
== MMSYSERR_NOERROR
)
802 /* first try just changing bit depth and channels */
803 channels
= info
->format
->nChannels
;
804 mr
= WINMM_TryDeviceMapping(info
, channels
,
805 info
->format
->nSamplesPerSec
, 16, is_out
);
806 if(mr
== MMSYSERR_NOERROR
)
808 mr
= WINMM_TryDeviceMapping(info
, channels
,
809 info
->format
->nSamplesPerSec
, 8, is_out
);
810 if(mr
== MMSYSERR_NOERROR
)
813 channels
= (channels
== 2) ? 1 : 2;
814 mr
= WINMM_TryDeviceMapping(info
, channels
,
815 info
->format
->nSamplesPerSec
, 16, is_out
);
816 if(mr
== MMSYSERR_NOERROR
)
818 mr
= WINMM_TryDeviceMapping(info
, channels
,
819 info
->format
->nSamplesPerSec
, 8, is_out
);
820 if(mr
== MMSYSERR_NOERROR
)
823 /* that didn't work, so now try different sample rates */
824 channels
= info
->format
->nChannels
;
825 mr
= WINMM_TryDeviceMapping(info
, channels
, 96000, 16, is_out
);
826 if(mr
== MMSYSERR_NOERROR
)
828 mr
= WINMM_TryDeviceMapping(info
, channels
, 48000, 16, is_out
);
829 if(mr
== MMSYSERR_NOERROR
)
831 mr
= WINMM_TryDeviceMapping(info
, channels
, 44100, 16, is_out
);
832 if(mr
== MMSYSERR_NOERROR
)
834 mr
= WINMM_TryDeviceMapping(info
, channels
, 22050, 16, is_out
);
835 if(mr
== MMSYSERR_NOERROR
)
837 mr
= WINMM_TryDeviceMapping(info
, channels
, 11025, 16, is_out
);
838 if(mr
== MMSYSERR_NOERROR
)
841 channels
= (channels
== 2) ? 1 : 2;
842 mr
= WINMM_TryDeviceMapping(info
, channels
, 96000, 16, is_out
);
843 if(mr
== MMSYSERR_NOERROR
)
845 mr
= WINMM_TryDeviceMapping(info
, channels
, 48000, 16, is_out
);
846 if(mr
== MMSYSERR_NOERROR
)
848 mr
= WINMM_TryDeviceMapping(info
, channels
, 44100, 16, is_out
);
849 if(mr
== MMSYSERR_NOERROR
)
851 mr
= WINMM_TryDeviceMapping(info
, channels
, 22050, 16, is_out
);
852 if(mr
== MMSYSERR_NOERROR
)
854 mr
= WINMM_TryDeviceMapping(info
, channels
, 11025, 16, is_out
);
855 if(mr
== MMSYSERR_NOERROR
)
858 channels
= info
->format
->nChannels
;
859 mr
= WINMM_TryDeviceMapping(info
, channels
, 96000, 8, is_out
);
860 if(mr
== MMSYSERR_NOERROR
)
862 mr
= WINMM_TryDeviceMapping(info
, channels
, 48000, 8, is_out
);
863 if(mr
== MMSYSERR_NOERROR
)
865 mr
= WINMM_TryDeviceMapping(info
, channels
, 44100, 8, is_out
);
866 if(mr
== MMSYSERR_NOERROR
)
868 mr
= WINMM_TryDeviceMapping(info
, channels
, 22050, 8, is_out
);
869 if(mr
== MMSYSERR_NOERROR
)
871 mr
= WINMM_TryDeviceMapping(info
, channels
, 11025, 8, is_out
);
872 if(mr
== MMSYSERR_NOERROR
)
875 channels
= (channels
== 2) ? 1 : 2;
876 mr
= WINMM_TryDeviceMapping(info
, channels
, 96000, 8, is_out
);
877 if(mr
== MMSYSERR_NOERROR
)
879 mr
= WINMM_TryDeviceMapping(info
, channels
, 48000, 8, is_out
);
880 if(mr
== MMSYSERR_NOERROR
)
882 mr
= WINMM_TryDeviceMapping(info
, channels
, 44100, 8, is_out
);
883 if(mr
== MMSYSERR_NOERROR
)
885 mr
= WINMM_TryDeviceMapping(info
, channels
, 22050, 8, is_out
);
886 if(mr
== MMSYSERR_NOERROR
)
888 mr
= WINMM_TryDeviceMapping(info
, channels
, 11025, 8, is_out
);
889 if(mr
== MMSYSERR_NOERROR
)
893 WARN("Unable to find compatible device!\n");
894 return WAVERR_BADFORMAT
;
897 static LRESULT
WINMM_OpenDevice(WINMM_Device
*device
, WINMM_MMDevice
*mmdevice
,
898 WINMM_OpenInfo
*info
)
900 WAVEFORMATEX
*closer_fmt
= NULL
, fmt
, *passed_fmt
;
901 LRESULT ret
= MMSYSERR_ERROR
;
904 hr
= IMMDeviceEnumerator_GetDevice(g_devenum
, mmdevice
->dev_id
,
907 WARN("Device %s (%s) unavailable: %08x\n",
908 wine_dbgstr_w(mmdevice
->dev_id
),
909 wine_dbgstr_w(mmdevice
->out_caps
.szPname
), hr
);
913 hr
= IMMDevice_Activate(device
->device
, &IID_IAudioClient
,
914 CLSCTX_INPROC_SERVER
, NULL
, (void**)&device
->client
);
916 WARN("Activate failed: %08x\n", hr
);
920 if(info
->format
->wFormatTag
== WAVE_FORMAT_PCM
){
921 /* we aren't guaranteed that the struct in lpFormat is a full
922 * WAVEFORMATEX struct, which IAC::IsFormatSupported requires */
924 memcpy(passed_fmt
, info
->format
, sizeof(PCMWAVEFORMAT
));
925 passed_fmt
->cbSize
= 0;
926 if(fmt
.wBitsPerSample
% 8 != 0){
927 WARN("Fixing bad wBitsPerSample (%u)\n", fmt
.wBitsPerSample
);
928 fmt
.wBitsPerSample
= (fmt
.wBitsPerSample
+ 7) & ~7;
930 /* winmm ignores broken blockalign and avgbytes */
931 if(fmt
.nBlockAlign
!= fmt
.nChannels
* fmt
.wBitsPerSample
/8){
932 WARN("Fixing bad nBlockAlign (%u)\n", fmt
.nBlockAlign
);
933 fmt
.nBlockAlign
= fmt
.nChannels
* fmt
.wBitsPerSample
/8;
935 if (fmt
.nAvgBytesPerSec
!= fmt
.nSamplesPerSec
* fmt
.nBlockAlign
) {
936 WARN("Fixing bad nAvgBytesPerSec (%u)\n", fmt
.nAvgBytesPerSec
);
937 fmt
.nAvgBytesPerSec
= fmt
.nSamplesPerSec
* fmt
.nBlockAlign
;
940 passed_fmt
= info
->format
;
942 hr
= IAudioClient_IsFormatSupported(device
->client
,
943 AUDCLNT_SHAREMODE_SHARED
, passed_fmt
, &closer_fmt
);
945 CoTaskMemFree(closer_fmt
);
946 if(FAILED(hr
) && hr
!= AUDCLNT_E_UNSUPPORTED_FORMAT
){
947 WARN("IsFormatSupported failed: %08x\n", hr
);
950 if(hr
== S_FALSE
|| hr
== AUDCLNT_E_UNSUPPORTED_FORMAT
){
951 ret
= WAVERR_BADFORMAT
;
954 if(info
->flags
& WAVE_FORMAT_QUERY
){
955 ret
= MMSYSERR_NOERROR
;
959 /* buffer size = 10 * 100000 (100 ns) = 0.1 seconds */
960 hr
= IAudioClient_Initialize(device
->client
, AUDCLNT_SHAREMODE_SHARED
,
961 AUDCLNT_STREAMFLAGS_EVENTCALLBACK
| AUDCLNT_STREAMFLAGS_NOPERSIST
,
962 10 * 100000, 50000, passed_fmt
, &device
->parent
->session
);
964 WARN("Initialize failed: %08x\n", hr
);
968 hr
= IAudioClient_GetService(device
->client
, &IID_IAudioClock
,
969 (void**)&device
->clock
);
971 WARN("GetService failed: %08x\n", hr
);
976 device
->event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
978 WARN("CreateEvent failed: %08x\n", hr
);
982 /* As the devices thread is waiting on g_device_handles, it can
983 * only be modified from within this same thread. */
984 if(g_device_handles
){
985 g_device_handles
= HeapReAlloc(GetProcessHeap(), 0, g_device_handles
,
986 sizeof(HANDLE
) * (g_devhandle_count
+ 1));
987 g_handle_devices
= HeapReAlloc(GetProcessHeap(), 0, g_handle_devices
,
988 sizeof(WINMM_Device
*) * (g_devhandle_count
+ 1));
990 g_device_handles
= HeapAlloc(GetProcessHeap(), 0, sizeof(HANDLE
));
991 g_handle_devices
= HeapAlloc(GetProcessHeap(), 0,
992 sizeof(WINMM_Device
*));
994 g_device_handles
[g_devhandle_count
] = device
->event
;
995 g_handle_devices
[g_devhandle_count
] = device
;
999 hr
= IAudioClient_SetEventHandle(device
->client
, device
->event
);
1001 WARN("SetEventHandle failed: %08x\n", hr
);
1005 device
->bytes_per_frame
= passed_fmt
->nBlockAlign
;
1006 device
->samples_per_sec
= passed_fmt
->nSamplesPerSec
;
1008 device
->played_frames
= 0;
1009 device
->last_clock_pos
= 0;
1010 device
->ofs_bytes
= 0;
1011 device
->loop_counter
= 0;
1012 device
->stopped
= TRUE
;
1013 device
->first
= device
->last
= device
->playing
= device
->loop_start
= NULL
;
1015 device
->cb_info
.flags
= HIWORD(info
->flags
& CALLBACK_TYPEMASK
);
1016 device
->cb_info
.callback
= info
->callback
;
1017 device
->cb_info
.user
= info
->cb_user
;
1018 device
->cb_info
.hwave
= device
->handle
;
1020 info
->handle
= device
->handle
;
1022 return MMSYSERR_NOERROR
;
1026 IAudioClient_Release(device
->client
);
1027 device
->client
= NULL
;
1030 IMMDevice_Release(device
->device
);
1031 device
->device
= NULL
;
1037 static LRESULT
WOD_Open(WINMM_OpenInfo
*info
)
1039 WINMM_MMDevice
*mmdevice
;
1040 WINMM_Device
*device
= NULL
;
1041 LRESULT ret
= MMSYSERR_ERROR
;
1044 TRACE("(%u, %p, %08x)\n", info
->req_device
, info
, info
->flags
);
1046 if(WINMM_IsMapper(info
->req_device
) || (info
->flags
& WAVE_MAPPED
))
1047 return WINMM_MapDevice(info
, TRUE
);
1049 if(info
->req_device
>= g_outmmdevices_count
)
1050 return MMSYSERR_BADDEVICEID
;
1052 mmdevice
= &g_out_mmdevices
[info
->req_device
];
1054 if(!mmdevice
->out_caps
.szPname
[0])
1055 return MMSYSERR_NOTENABLED
;
1057 device
= WINMM_FindUnusedDevice(TRUE
, info
->req_device
);
1059 return MMSYSERR_ALLOCATED
;
1061 ret
= WINMM_OpenDevice(device
, mmdevice
, info
);
1062 if((info
->flags
& WAVE_FORMAT_QUERY
) || ret
!= MMSYSERR_NOERROR
)
1064 ret
= MMSYSERR_ERROR
;
1066 hr
= IAudioClient_GetService(device
->client
, &IID_IAudioRenderClient
,
1067 (void**)&device
->render
);
1069 WARN("GetService(RenderClient) failed: %08x\n", hr
);
1073 hr
= IAudioClient_GetService(device
->client
, &IID_IAudioStreamVolume
,
1074 (void**)&device
->volume
);
1076 WARN("GetService(StreamVolume) failed: %08x\n", hr
);
1080 LeaveCriticalSection(&device
->lock
);
1082 return MMSYSERR_NOERROR
;
1086 IMMDevice_Release(device
->device
);
1087 device
->device
= NULL
;
1090 IAudioClient_Release(device
->client
);
1091 device
->client
= NULL
;
1094 IAudioRenderClient_Release(device
->render
);
1095 device
->render
= NULL
;
1098 IAudioStreamVolume_Release(device
->volume
);
1099 device
->volume
= NULL
;
1102 IAudioClock_Release(device
->clock
);
1103 device
->clock
= NULL
;
1105 device
->open
= FALSE
;
1106 LeaveCriticalSection(&device
->lock
);
1110 static LRESULT
WID_Open(WINMM_OpenInfo
*info
)
1112 WINMM_MMDevice
*mmdevice
;
1113 WINMM_Device
*device
= NULL
;
1114 LRESULT ret
= MMSYSERR_ERROR
;
1117 TRACE("(%u, %p, %08x)\n", info
->req_device
, info
, info
->flags
);
1119 if(WINMM_IsMapper(info
->req_device
) || info
->flags
& WAVE_MAPPED
)
1120 return WINMM_MapDevice(info
, FALSE
);
1122 if(info
->req_device
>= g_inmmdevices_count
)
1123 return MMSYSERR_BADDEVICEID
;
1125 mmdevice
= &g_in_mmdevices
[info
->req_device
];
1127 if(!mmdevice
->in_caps
.szPname
[0])
1128 return MMSYSERR_NOTENABLED
;
1130 device
= WINMM_FindUnusedDevice(FALSE
, info
->req_device
);
1132 return MMSYSERR_ALLOCATED
;
1134 ret
= WINMM_OpenDevice(device
, mmdevice
, info
);
1135 if((info
->flags
& WAVE_FORMAT_QUERY
) || ret
!= MMSYSERR_NOERROR
)
1137 ret
= MMSYSERR_ERROR
;
1139 hr
= IAudioClient_GetService(device
->client
, &IID_IAudioCaptureClient
,
1140 (void**)&device
->capture
);
1142 WARN("GetService failed: %08x\n", hr
);
1146 LeaveCriticalSection(&device
->lock
);
1148 return MMSYSERR_NOERROR
;
1152 IMMDevice_Release(device
->device
);
1153 device
->device
= NULL
;
1156 IAudioClient_Release(device
->client
);
1157 device
->client
= NULL
;
1159 if(device
->capture
){
1160 IAudioCaptureClient_Release(device
->capture
);
1161 device
->capture
= NULL
;
1164 IAudioClock_Release(device
->clock
);
1165 device
->clock
= NULL
;
1167 device
->open
= FALSE
;
1168 LeaveCriticalSection(&device
->lock
);
1172 static HRESULT
WINMM_CloseDevice(WINMM_Device
*device
)
1174 device
->open
= FALSE
;
1176 if(!device
->stopped
){
1177 IAudioClient_Stop(device
->client
);
1178 device
->stopped
= TRUE
;
1181 if(device
->acm_handle
){
1182 acmStreamClose(device
->acm_handle
, 0);
1183 device
->acm_handle
= NULL
;
1186 IMMDevice_Release(device
->device
);
1187 device
->device
= NULL
;
1189 IAudioClient_Release(device
->client
);
1190 device
->client
= NULL
;
1192 IAudioClock_Release(device
->clock
);
1193 device
->clock
= NULL
;
1198 static LRESULT
WOD_Close(HWAVEOUT hwave
)
1200 WINMM_Device
*device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hwave
);
1202 TRACE("(%p)\n", hwave
);
1204 if(!WINMM_ValidateAndLock(device
))
1205 return MMSYSERR_INVALHANDLE
;
1207 WINMM_CloseDevice(device
);
1209 IAudioRenderClient_Release(device
->render
);
1210 device
->render
= NULL
;
1212 IAudioStreamVolume_Release(device
->volume
);
1213 device
->volume
= NULL
;
1215 LeaveCriticalSection(&device
->lock
);
1217 return MMSYSERR_NOERROR
;
1220 static LRESULT
WID_Close(HWAVEIN hwave
)
1222 WINMM_Device
*device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hwave
);
1224 TRACE("(%p)\n", hwave
);
1226 if(!WINMM_ValidateAndLock(device
))
1227 return MMSYSERR_INVALHANDLE
;
1229 WINMM_CloseDevice(device
);
1231 IAudioCaptureClient_Release(device
->capture
);
1232 device
->capture
= NULL
;
1234 LeaveCriticalSection(&device
->lock
);
1236 return MMSYSERR_NOERROR
;
1239 static LRESULT
WINMM_PrepareHeader(HWAVE hwave
, WAVEHDR
*header
)
1241 WINMM_Device
*device
= WINMM_GetDeviceFromHWAVE(hwave
);
1243 TRACE("(%p, %p)\n", hwave
, header
);
1245 if(!WINMM_ValidateAndLock(device
))
1246 return MMSYSERR_INVALHANDLE
;
1248 if(device
->render
&& device
->acm_handle
){
1249 ACMSTREAMHEADER
*ash
;
1253 mr
= acmStreamSize(device
->acm_handle
, header
->dwBufferLength
, &size
,
1254 ACM_STREAMSIZEF_SOURCE
);
1255 if(mr
!= MMSYSERR_NOERROR
){
1256 LeaveCriticalSection(&device
->lock
);
1260 ash
= HeapAlloc(GetProcessHeap(), 0, sizeof(ACMSTREAMHEADER
) + size
);
1262 LeaveCriticalSection(&device
->lock
);
1263 return MMSYSERR_NOMEM
;
1266 ash
->cbStruct
= sizeof(*ash
);
1268 ash
->dwUser
= (DWORD_PTR
)header
;
1269 ash
->pbSrc
= (BYTE
*)header
->lpData
;
1270 ash
->cbSrcLength
= header
->dwBufferLength
;
1271 ash
->dwSrcUser
= header
->dwUser
;
1272 ash
->pbDst
= (BYTE
*)ash
+ sizeof(ACMSTREAMHEADER
);
1273 ash
->cbDstLength
= size
;
1276 mr
= acmStreamPrepareHeader(device
->acm_handle
, ash
, 0);
1277 if(mr
!= MMSYSERR_NOERROR
){
1278 HeapFree(GetProcessHeap(), 0, ash
);
1279 LeaveCriticalSection(&device
->lock
);
1283 header
->reserved
= (DWORD_PTR
)ash
;
1286 LeaveCriticalSection(&device
->lock
);
1288 header
->dwFlags
|= WHDR_PREPARED
;
1289 header
->dwFlags
&= ~WHDR_DONE
;
1291 return MMSYSERR_NOERROR
;
1294 static LRESULT
WINMM_UnprepareHeader(HWAVE hwave
, WAVEHDR
*header
)
1296 WINMM_Device
*device
= WINMM_GetDeviceFromHWAVE(hwave
);
1298 TRACE("(%p, %p)\n", hwave
, header
);
1300 if(!WINMM_ValidateAndLock(device
))
1301 return MMSYSERR_INVALHANDLE
;
1303 if(device
->render
&& device
->acm_handle
){
1304 ACMSTREAMHEADER
*ash
= (ACMSTREAMHEADER
*)header
->reserved
;
1306 acmStreamUnprepareHeader(device
->acm_handle
, ash
, 0);
1308 HeapFree(GetProcessHeap(), 0, ash
);
1311 LeaveCriticalSection(&device
->lock
);
1313 header
->dwFlags
&= ~WHDR_PREPARED
;
1314 header
->dwFlags
|= WHDR_DONE
;
1316 return MMSYSERR_NOERROR
;
1319 static UINT32
WINMM_HeaderLenBytes(WINMM_Device
*device
, WAVEHDR
*header
)
1321 if(device
->acm_handle
){
1322 ACMSTREAMHEADER
*ash
= (ACMSTREAMHEADER
*)header
->reserved
;
1323 return ash
->cbDstLengthUsed
;
1326 return header
->dwBufferLength
;
1329 static UINT32
WINMM_HeaderLenFrames(WINMM_Device
*device
, WAVEHDR
*header
)
1331 return WINMM_HeaderLenBytes(device
, header
) / device
->bytes_per_frame
;
1334 static WAVEHDR
*WOD_MarkDoneHeaders(WINMM_Device
*device
)
1337 WAVEHDR
*first
= device
->first
, *queue
= first
, *last
= NULL
;
1338 UINT64 clock_freq
, clock_pos
, clock_frames
;
1339 UINT32 nloops
, queue_frames
= 0;
1341 hr
= IAudioClock_GetFrequency(device
->clock
, &clock_freq
);
1343 WARN("GetFrequency failed: %08x\n", hr
);
1347 hr
= IAudioClock_GetPosition(device
->clock
, &clock_pos
, NULL
);
1349 WARN("GetPosition failed: %08x\n", hr
);
1353 clock_frames
= (clock_pos
* device
->samples_per_sec
) / clock_freq
;
1355 nloops
= device
->loop_counter
;
1357 (queue_frames
+= WINMM_HeaderLenFrames(device
, queue
)) <=
1358 clock_frames
- device
->last_clock_pos
){
1361 device
->last_clock_pos
+= queue_frames
;
1363 queue
= device
->first
= queue
->lpNext
;
1365 if(queue
->dwFlags
& WHDR_BEGINLOOP
){
1366 if(queue
->dwFlags
& WHDR_ENDLOOP
)
1369 queue
= queue
->lpNext
;
1370 }else if(queue
->dwFlags
& WHDR_ENDLOOP
){
1371 queue
= device
->loop_start
;
1378 last
->lpNext
= NULL
;
1384 static void WOD_PushData(WINMM_Device
*device
)
1386 WINMM_CBInfo cb_info
;
1388 UINT32 pad
, bufsize
, avail_frames
, queue_frames
, written
, ofs
;
1389 UINT32 queue_bytes
, nloops
;
1391 WAVEHDR
*queue
, *first
= NULL
;
1393 TRACE("(%p)\n", device
->handle
);
1395 EnterCriticalSection(&device
->lock
);
1401 if (device
->stopped
)
1403 device
->stopped
= TRUE
;
1404 device
->last_clock_pos
= 0;
1405 IAudioClient_Stop(device
->client
);
1406 IAudioClient_Reset(device
->client
);
1410 hr
= IAudioClient_GetBufferSize(device
->client
, &bufsize
);
1412 WARN("GetBufferSize failed: %08x\n", hr
);
1416 hr
= IAudioClient_GetCurrentPadding(device
->client
, &pad
);
1418 WARN("GetCurrentPadding failed: %08x\n", hr
);
1422 first
= WOD_MarkDoneHeaders(device
);
1424 /* determine which is larger between the available buffer size and
1425 * the amount of data left in the queue */
1426 avail_frames
= bufsize
- pad
;
1428 queue
= device
->playing
;
1429 ofs
= device
->ofs_bytes
;
1432 while(queue
&& queue_frames
< avail_frames
){
1433 queue_bytes
= WINMM_HeaderLenBytes(device
, queue
);
1434 queue_frames
+= (queue_bytes
- ofs
) / device
->bytes_per_frame
;
1437 if(queue
->dwFlags
& WHDR_ENDLOOP
&& nloops
< device
->loop_counter
){
1438 queue
= device
->loop_start
;
1441 queue
= queue
->lpNext
;
1444 if(queue_frames
< avail_frames
)
1445 avail_frames
= queue_frames
;
1446 if(avail_frames
== 0)
1449 hr
= IAudioRenderClient_GetBuffer(device
->render
, avail_frames
, &data
);
1451 WARN("GetBuffer failed: %08x\n", hr
);
1456 while(device
->playing
&& written
< avail_frames
){
1457 UINT32 copy_frames
, copy_bytes
;
1460 queue
= device
->playing
;
1462 if(device
->acm_handle
){
1463 ACMSTREAMHEADER
*ash
= (ACMSTREAMHEADER
*)queue
->reserved
;
1464 queue_bytes
= ash
->cbDstLengthUsed
;
1465 queue_data
= ash
->pbDst
;
1467 queue_bytes
= queue
->dwBufferLength
;
1468 queue_data
= (BYTE
*)queue
->lpData
;
1471 queue_frames
= (queue_bytes
- device
->ofs_bytes
) /
1472 device
->bytes_per_frame
;
1474 copy_frames
= queue_frames
< (avail_frames
- written
) ?
1475 queue_frames
: avail_frames
- written
;
1476 copy_bytes
= copy_frames
* device
->bytes_per_frame
;
1478 memcpy(data
, queue_data
+ device
->ofs_bytes
, copy_bytes
);
1481 written
+= copy_frames
;
1482 device
->ofs_bytes
+= copy_bytes
;
1484 if(device
->ofs_bytes
>= queue_bytes
){
1485 device
->ofs_bytes
= 0;
1487 if(!(queue
->dwFlags
& (WHDR_BEGINLOOP
| WHDR_ENDLOOP
)))
1488 device
->playing
= queue
->lpNext
;
1490 if(queue
->dwFlags
& WHDR_BEGINLOOP
){
1491 device
->loop_start
= device
->playing
;
1492 device
->playing
= queue
->lpNext
;
1493 device
->loop_counter
= queue
->dwLoops
;
1495 if(queue
->dwFlags
& WHDR_ENDLOOP
){
1496 --device
->loop_counter
;
1497 if(device
->loop_counter
)
1498 device
->playing
= device
->loop_start
;
1500 device
->loop_start
= device
->playing
= queue
->lpNext
;
1506 hr
= IAudioRenderClient_ReleaseBuffer(device
->render
, avail_frames
, 0);
1508 WARN("ReleaseBuffer failed: %08x\n", hr
);
1512 device
->played_frames
+= avail_frames
;
1515 cb_info
= device
->cb_info
;
1517 LeaveCriticalSection(&device
->lock
);
1520 WAVEHDR
*next
= first
->lpNext
;
1521 first
->dwFlags
&= ~WHDR_INQUEUE
;
1522 first
->dwFlags
|= WHDR_DONE
;
1523 WINMM_NotifyClient(&cb_info
, WOM_DONE
, (DWORD_PTR
)first
, 0);
1528 static void WID_PullACMData(WINMM_Device
*device
)
1530 UINT32 packet
, packet_bytes
;
1537 if(device
->acm_hdr
.cbDstLength
== 0){
1538 hr
= IAudioCaptureClient_GetBuffer(device
->capture
, &data
, &packet
,
1539 &flags
, NULL
, NULL
);
1542 WARN("GetBuffer failed: %08x\n", hr
);
1546 acmStreamSize(device
->acm_handle
, packet
* device
->bytes_per_frame
,
1547 &packet_bytes
, ACM_STREAMSIZEF_SOURCE
);
1549 device
->acm_offs
= 0;
1551 device
->acm_hdr
.cbStruct
= sizeof(device
->acm_hdr
);
1552 device
->acm_hdr
.fdwStatus
= 0;
1553 device
->acm_hdr
.dwUser
= 0;
1554 device
->acm_hdr
.pbSrc
= data
;
1555 device
->acm_hdr
.cbSrcLength
= packet
* device
->bytes_per_frame
;
1556 device
->acm_hdr
.cbSrcLengthUsed
= 0;
1557 device
->acm_hdr
.dwSrcUser
= 0;
1558 device
->acm_hdr
.pbDst
= HeapAlloc(GetProcessHeap(), 0, packet_bytes
);
1559 device
->acm_hdr
.cbDstLength
= packet_bytes
;
1560 device
->acm_hdr
.cbDstLengthUsed
= 0;
1561 device
->acm_hdr
.dwDstUser
= 0;
1563 mr
= acmStreamPrepareHeader(device
->acm_handle
, &device
->acm_hdr
, 0);
1564 if(mr
!= MMSYSERR_NOERROR
){
1565 WARN("acmStreamPrepareHeader failed: %d\n", mr
);
1569 mr
= acmStreamConvert(device
->acm_handle
, &device
->acm_hdr
, 0);
1570 if(mr
!= MMSYSERR_NOERROR
){
1571 WARN("acmStreamConvert failed: %d\n", mr
);
1575 hr
= IAudioCaptureClient_ReleaseBuffer(device
->capture
, packet
);
1577 WARN("ReleaseBuffer failed: %08x\n", hr
);
1579 device
->played_frames
+= packet
;
1582 queue
= device
->first
;
1584 UINT32 to_copy_bytes
;
1586 to_copy_bytes
= min(queue
->dwBufferLength
- queue
->dwBytesRecorded
,
1587 device
->acm_hdr
.cbDstLengthUsed
- device
->acm_offs
);
1589 memcpy(queue
->lpData
+ queue
->dwBytesRecorded
,
1590 device
->acm_hdr
.pbDst
+ device
->acm_offs
, to_copy_bytes
);
1592 queue
->dwBytesRecorded
+= to_copy_bytes
;
1593 device
->acm_offs
+= to_copy_bytes
;
1595 if(queue
->dwBufferLength
- queue
->dwBytesRecorded
<
1596 device
->bytes_per_frame
){
1597 queue
->dwFlags
&= ~WHDR_INQUEUE
;
1598 queue
->dwFlags
|= WHDR_DONE
;
1599 device
->first
= queue
= queue
->lpNext
;
1602 if(device
->acm_offs
>= device
->acm_hdr
.cbDstLengthUsed
){
1603 acmStreamUnprepareHeader(device
->acm_handle
, &device
->acm_hdr
, 0);
1604 HeapFree(GetProcessHeap(), 0, device
->acm_hdr
.pbDst
);
1605 device
->acm_hdr
.cbDstLength
= 0;
1606 device
->acm_hdr
.cbDstLengthUsed
= 0;
1608 /* done with this ACM Header, so try to pull more data */
1609 WID_PullACMData(device
);
1614 /* out of WAVEHDRs to write into, so toss the rest of this packet */
1615 acmStreamUnprepareHeader(device
->acm_handle
, &device
->acm_hdr
, 0);
1616 HeapFree(GetProcessHeap(), 0, device
->acm_hdr
.pbDst
);
1617 device
->acm_hdr
.cbDstLength
= 0;
1618 device
->acm_hdr
.cbDstLengthUsed
= 0;
1621 static void WID_PullData(WINMM_Device
*device
)
1623 WINMM_CBInfo cb_info
;
1624 WAVEHDR
*queue
, *first
= NULL
, *last
= NULL
;
1627 TRACE("(%p)\n", device
->handle
);
1629 EnterCriticalSection(&device
->lock
);
1631 if(!device
->device
|| !device
->first
)
1634 first
= device
->first
;
1636 if(device
->acm_handle
){
1637 WID_PullACMData(device
);
1641 while(device
->first
){
1643 UINT32 packet_len
, packet
;
1646 hr
= IAudioCaptureClient_GetBuffer(device
->capture
, &data
, &packet_len
,
1647 &flags
, NULL
, NULL
);
1650 WARN("GetBuffer failed: %08x\n", hr
);
1651 else /* AUDCLNT_S_BUFFER_EMPTY success code */
1652 IAudioCaptureClient_ReleaseBuffer(device
->capture
, 0);
1656 packet
= packet_len
;
1657 queue
= device
->first
;
1658 while(queue
&& packet
> 0){
1659 UINT32 to_copy_bytes
;
1661 to_copy_bytes
= min(packet
* device
->bytes_per_frame
,
1662 queue
->dwBufferLength
- queue
->dwBytesRecorded
);
1664 memcpy(queue
->lpData
+ queue
->dwBytesRecorded
,
1665 data
+ (packet_len
- packet
) * device
->bytes_per_frame
,
1668 queue
->dwBytesRecorded
+= to_copy_bytes
;
1670 if(queue
->dwBufferLength
- queue
->dwBytesRecorded
<
1671 device
->bytes_per_frame
){
1673 device
->first
= queue
= queue
->lpNext
;
1676 packet
-= to_copy_bytes
/ device
->bytes_per_frame
;
1679 hr
= IAudioCaptureClient_ReleaseBuffer(device
->capture
, packet_len
);
1681 WARN("ReleaseBuffer failed: %08x\n", hr
);
1684 WARN("losing %u frames\n", packet
);
1685 device
->played_frames
+= packet_len
;
1689 cb_info
= device
->cb_info
;
1691 LeaveCriticalSection(&device
->lock
);
1694 last
->lpNext
= NULL
;
1696 WAVEHDR
*next
= first
->lpNext
;
1697 first
->dwFlags
&= ~WHDR_INQUEUE
;
1698 first
->dwFlags
|= WHDR_DONE
;
1699 WINMM_NotifyClient(&cb_info
, WIM_DATA
, (DWORD_PTR
)first
, 0);
1705 static HRESULT
WINMM_BeginPlaying(WINMM_Device
*device
)
1709 TRACE("(%p)\n", device
->handle
);
1712 /* prebuffer data before starting */
1713 WOD_PushData(device
);
1715 if(device
->stopped
){
1716 device
->stopped
= FALSE
;
1718 hr
= IAudioClient_Start(device
->client
);
1719 if(FAILED(hr
) && hr
!= AUDCLNT_E_NOT_STOPPED
){
1720 device
->stopped
= TRUE
;
1721 WARN("Start failed: %08x\n", hr
);
1729 static LRESULT
WINMM_Pause(HWAVE hwave
)
1731 WINMM_Device
*device
= WINMM_GetDeviceFromHWAVE(hwave
);
1734 TRACE("(%p)\n", hwave
);
1736 if(!WINMM_ValidateAndLock(device
))
1737 return MMSYSERR_INVALHANDLE
;
1739 hr
= IAudioClient_Stop(device
->client
);
1741 LeaveCriticalSection(&device
->lock
);
1742 WARN("Stop failed: %08x\n", hr
);
1743 return MMSYSERR_ERROR
;
1746 device
->stopped
= FALSE
;
1748 LeaveCriticalSection(&device
->lock
);
1750 return MMSYSERR_NOERROR
;
1753 static LRESULT
WINMM_Reset(HWAVE hwave
)
1755 WINMM_CBInfo cb_info
;
1756 WINMM_Device
*device
= WINMM_GetDeviceFromHWAVE(hwave
);
1761 TRACE("(%p)\n", hwave
);
1763 if(!WINMM_ValidateAndLock(device
))
1764 return MMSYSERR_INVALHANDLE
;
1766 hr
= IAudioClient_Stop(device
->client
);
1768 LeaveCriticalSection(&device
->lock
);
1769 WARN("Stop failed: %08x\n", hr
);
1770 return MMSYSERR_ERROR
;
1772 device
->stopped
= TRUE
;
1774 first
= device
->first
;
1775 device
->first
= device
->last
= device
->playing
= NULL
;
1776 device
->ofs_bytes
= 0;
1777 device
->played_frames
= 0;
1778 device
->loop_counter
= 0;
1779 device
->last_clock_pos
= 0;
1780 IAudioClient_Reset(device
->client
);
1782 cb_info
= device
->cb_info
;
1783 is_out
= device
->render
!= NULL
;
1785 LeaveCriticalSection(&device
->lock
);
1788 WAVEHDR
*next
= first
->lpNext
;
1789 first
->dwFlags
&= ~WHDR_INQUEUE
;
1790 first
->dwFlags
|= WHDR_DONE
;
1792 WINMM_NotifyClient(&cb_info
, WOM_DONE
, (DWORD_PTR
)first
, 0);
1794 WINMM_NotifyClient(&cb_info
, WIM_DATA
, (DWORD_PTR
)first
, 0);
1798 return MMSYSERR_NOERROR
;
1801 static MMRESULT
WINMM_FramesToMMTime(MMTIME
*time
, UINT32 played_frames
,
1802 UINT32 sample_rate
, UINT32 bytes_per_frame
)
1804 switch(time
->wType
){
1806 time
->u
.sample
= played_frames
;
1807 return MMSYSERR_NOERROR
;
1809 time
->u
.ms
= (UINT64
)played_frames
* 1000 / sample_rate
;
1810 return MMSYSERR_NOERROR
;
1812 time
->u
.smpte
.fps
= 30;
1813 played_frames
+= sample_rate
/ time
->u
.smpte
.fps
- 1; /* round up */
1814 time
->u
.smpte
.frame
= (played_frames
% sample_rate
) * time
->u
.smpte
.fps
/ sample_rate
;
1815 played_frames
/= sample_rate
; /* yields seconds */
1816 time
->u
.smpte
.sec
= played_frames
% 60;
1817 played_frames
/= 60;
1818 time
->u
.smpte
.min
= played_frames
% 60;
1819 time
->u
.smpte
.hour
= played_frames
/ 60;
1820 return MMSYSERR_NOERROR
;
1822 time
->wType
= TIME_BYTES
;
1825 time
->u
.cb
= played_frames
* bytes_per_frame
;
1826 return MMSYSERR_NOERROR
;
1830 static LRESULT
WINMM_GetPosition(HWAVE hwave
, MMTIME
*time
)
1832 WINMM_Device
*device
= WINMM_GetDeviceFromHWAVE(hwave
);
1833 UINT32 played_frames
, sample_rate
, bytes_per_frame
;
1835 TRACE("(%p, %p)\n", hwave
, time
);
1837 if(!WINMM_ValidateAndLock(device
))
1838 return MMSYSERR_INVALHANDLE
;
1840 played_frames
= device
->played_frames
;
1841 sample_rate
= device
->samples_per_sec
;
1842 bytes_per_frame
= device
->bytes_per_frame
;
1844 LeaveCriticalSection(&device
->lock
);
1846 return WINMM_FramesToMMTime(time
, played_frames
, sample_rate
,
1850 static WINMM_MMDevice
*WINMM_GetMixerMMDevice(HMIXEROBJ hmix
, DWORD flags
,
1853 UINT mmdev
, dev
, junk
, *out
;
1861 switch(flags
& 0xF0000000){
1862 case MIXER_OBJECTF_MIXER
: /* == 0 */
1863 *out
= HandleToULong(hmix
);
1864 if(*out
< g_outmmdevices_count
)
1865 return &g_out_mmdevices
[*out
];
1866 if(*out
- g_outmmdevices_count
< g_inmmdevices_count
){
1867 *out
-= g_outmmdevices_count
;
1868 return &g_in_mmdevices
[*out
];
1870 /* fall through -- if it's not a valid mixer device, then
1871 * it could be a valid mixer handle. windows seems to do
1873 case MIXER_OBJECTF_HMIXER
:
1874 case MIXER_OBJECTF_HWAVEOUT
:
1875 case MIXER_OBJECTF_HWAVEIN
:
1876 WINMM_DecomposeHWAVE((HWAVE
)hmix
, out
, &is_out
, &dev
, &junk
);
1877 if(junk
!= 0x1 || (is_out
&& *out
>= g_outmmdevices_count
) ||
1878 (!is_out
&& *out
>= g_inmmdevices_count
))
1881 return &g_out_mmdevices
[*out
];
1882 return &g_in_mmdevices
[*out
];
1883 case MIXER_OBJECTF_WAVEOUT
:
1884 *out
= HandleToULong(hmix
);
1885 if(*out
< g_outmmdevices_count
)
1886 return &g_out_mmdevices
[*out
];
1888 case MIXER_OBJECTF_WAVEIN
:
1889 *out
= HandleToULong(hmix
);
1890 if(*out
< g_inmmdevices_count
)
1891 return &g_in_mmdevices
[*out
];
1898 static MMRESULT
WINMM_SetupMMDeviceVolume(WINMM_MMDevice
*mmdevice
)
1900 IAudioSessionManager
*sesman
;
1904 hr
= IMMDeviceEnumerator_GetDevice(g_devenum
, mmdevice
->dev_id
, &device
);
1906 WARN("Device %s (%s) unavailable: %08x\n",
1907 wine_dbgstr_w(mmdevice
->dev_id
),
1908 wine_dbgstr_w(mmdevice
->out_caps
.szPname
), hr
);
1909 return MMSYSERR_ERROR
;
1912 hr
= IMMDevice_Activate(device
, &IID_IAudioSessionManager
,
1913 CLSCTX_INPROC_SERVER
, NULL
, (void**)&sesman
);
1915 WARN("Activate failed: %08x\n", hr
);
1916 IMMDevice_Release(device
);
1917 return MMSYSERR_ERROR
;
1920 IMMDevice_Release(device
);
1922 hr
= IAudioSessionManager_GetSimpleAudioVolume(sesman
, &mmdevice
->session
,
1923 FALSE
, &mmdevice
->volume
);
1924 IAudioSessionManager_Release(sesman
);
1926 WARN("GetSimpleAudioVolume failed: %08x\n", hr
);
1927 return MMSYSERR_ERROR
;
1930 return MMSYSERR_NOERROR
;
1933 static LRESULT
MXD_GetControlDetails(WINMM_ControlDetails
*details
)
1935 WINMM_MMDevice
*mmdevice
;
1936 MIXERCONTROLDETAILS
*control
= details
->details
;
1939 TRACE("(%p)\n", details
->hmix
);
1941 mmdevice
= WINMM_GetMixerMMDevice(details
->hmix
, details
->flags
, NULL
);
1943 return MMSYSERR_INVALHANDLE
;
1945 EnterCriticalSection(&mmdevice
->lock
);
1947 if(!mmdevice
->volume
){
1950 mr
= WINMM_SetupMMDeviceVolume(mmdevice
);
1951 if(mr
!= MMSYSERR_NOERROR
){
1952 LeaveCriticalSection(&mmdevice
->lock
);
1957 if(control
->dwControlID
== 0){
1959 MIXERCONTROLDETAILS_UNSIGNED
*udet
;
1961 if(!control
->paDetails
||
1962 control
->cbDetails
< sizeof(MIXERCONTROLDETAILS_UNSIGNED
)){
1963 LeaveCriticalSection(&mmdevice
->lock
);
1964 return MMSYSERR_INVALPARAM
;
1967 hr
= ISimpleAudioVolume_GetMasterVolume(mmdevice
->volume
, &vol
);
1969 WARN("GetMasterVolume failed: %08x\n", hr
);
1970 LeaveCriticalSection(&mmdevice
->lock
);
1971 return MMSYSERR_ERROR
;
1974 udet
= (MIXERCONTROLDETAILS_UNSIGNED
*)control
->paDetails
;
1975 udet
->dwValue
= vol
* ((unsigned int)0xFFFF);
1976 }else if(control
->dwControlID
== 1){
1978 MIXERCONTROLDETAILS_BOOLEAN
*bdet
;
1980 if(!control
->paDetails
||
1981 control
->cbDetails
< sizeof(MIXERCONTROLDETAILS_BOOLEAN
)){
1982 LeaveCriticalSection(&mmdevice
->lock
);
1983 return MMSYSERR_INVALPARAM
;
1986 hr
= ISimpleAudioVolume_GetMute(mmdevice
->volume
, &mute
);
1988 WARN("GetMute failed: %08x\n", hr
);
1989 LeaveCriticalSection(&mmdevice
->lock
);
1990 return MMSYSERR_ERROR
;
1993 bdet
= (MIXERCONTROLDETAILS_BOOLEAN
*)control
->paDetails
;
1994 bdet
->fValue
= mute
;
1995 }else if(control
->dwControlID
== 2 || control
->dwControlID
== 3){
1996 FIXME("What should the sw-side mixer controls map to?\n");
1998 LeaveCriticalSection(&mmdevice
->lock
);
1999 return MIXERR_INVALCONTROL
;
2002 LeaveCriticalSection(&mmdevice
->lock
);
2004 return MMSYSERR_NOERROR
;
2007 static LRESULT
MXD_SetControlDetails(WINMM_ControlDetails
*details
)
2009 WINMM_MMDevice
*mmdevice
;
2010 MIXERCONTROLDETAILS
*control
= details
->details
;
2013 TRACE("(%p)\n", details
->hmix
);
2015 mmdevice
= WINMM_GetMixerMMDevice(details
->hmix
, details
->flags
, NULL
);
2017 return MMSYSERR_INVALHANDLE
;
2019 EnterCriticalSection(&mmdevice
->lock
);
2021 if(!mmdevice
->volume
){
2024 mr
= WINMM_SetupMMDeviceVolume(mmdevice
);
2025 if(mr
!= MMSYSERR_NOERROR
){
2026 LeaveCriticalSection(&mmdevice
->lock
);
2031 if(control
->dwControlID
== 0){
2033 MIXERCONTROLDETAILS_UNSIGNED
*udet
;
2035 if(!control
->paDetails
||
2036 control
->cbDetails
< sizeof(MIXERCONTROLDETAILS_UNSIGNED
)){
2037 LeaveCriticalSection(&mmdevice
->lock
);
2038 return MMSYSERR_INVALPARAM
;
2041 udet
= (MIXERCONTROLDETAILS_UNSIGNED
*)control
->paDetails
;
2043 if(udet
->dwValue
> 65535){
2044 LeaveCriticalSection(&mmdevice
->lock
);
2045 return MMSYSERR_INVALPARAM
;
2048 vol
= udet
->dwValue
/ 65535.f
;
2050 hr
= ISimpleAudioVolume_SetMasterVolume(mmdevice
->volume
, vol
, NULL
);
2052 WARN("SetMasterVolume failed: %08x\n", hr
);
2053 LeaveCriticalSection(&mmdevice
->lock
);
2054 return MMSYSERR_ERROR
;
2056 }else if(control
->dwControlID
== 1){
2058 MIXERCONTROLDETAILS_BOOLEAN
*bdet
;
2060 if(!control
->paDetails
||
2061 control
->cbDetails
< sizeof(MIXERCONTROLDETAILS_BOOLEAN
)){
2062 LeaveCriticalSection(&mmdevice
->lock
);
2063 return MMSYSERR_INVALPARAM
;
2066 bdet
= (MIXERCONTROLDETAILS_BOOLEAN
*)control
->paDetails
;
2067 mute
= bdet
->fValue
;
2069 hr
= ISimpleAudioVolume_SetMute(mmdevice
->volume
, mute
, NULL
);
2071 WARN("SetMute failed: %08x\n", hr
);
2072 LeaveCriticalSection(&mmdevice
->lock
);
2073 return MMSYSERR_ERROR
;
2075 }else if(control
->dwControlID
== 2 || control
->dwControlID
== 3){
2076 FIXME("What should the sw-side mixer controls map to?\n");
2078 LeaveCriticalSection(&mmdevice
->lock
);
2079 return MIXERR_INVALCONTROL
;
2082 LeaveCriticalSection(&mmdevice
->lock
);
2084 return MMSYSERR_NOERROR
;
2087 static LRESULT
DRV_QueryDeviceInterface(WINMM_QueryInterfaceInfo
*info
)
2089 WINMM_MMDevice
*mmdevice
;
2096 static const PROPERTYKEY deviceinterface_key
= {
2097 {0x233164c8, 0x1b2c, 0x4c7d, {0xbc, 0x68, 0xb6, 0x71, 0x68, 0x7a, 0x25, 0x67}}, 1
2100 if(WINMM_IsMapper(info
->index
)){
2102 if(*info
->len_bytes
< sizeof(WCHAR
))
2103 return MMSYSERR_INVALPARAM
;
2106 *info
->len_bytes
= sizeof(WCHAR
);
2107 return MMSYSERR_NOERROR
;
2111 if(info
->index
>= g_outmmdevices_count
)
2112 return MMSYSERR_INVALHANDLE
;
2114 mmdevice
= &g_out_mmdevices
[info
->index
];
2116 if(info
->index
>= g_inmmdevices_count
)
2117 return MMSYSERR_INVALHANDLE
;
2119 mmdevice
= &g_in_mmdevices
[info
->index
];
2122 hr
= IMMDeviceEnumerator_GetDevice(g_devenum
, mmdevice
->dev_id
,
2125 WARN("Device %s unavailable: %08x\n", wine_dbgstr_w(mmdevice
->dev_id
), hr
);
2126 return MMSYSERR_ERROR
;
2129 hr
= IMMDevice_OpenPropertyStore(device
, STGM_READ
, &ps
);
2131 WARN("OpenPropertyStore failed: %08x\n", hr
);
2132 IMMDevice_Release(device
);
2133 return MMSYSERR_ERROR
;
2136 PropVariantInit(&pv
);
2137 hr
= IPropertyStore_GetValue(ps
, &deviceinterface_key
, &pv
);
2139 WARN("GetValue failed: %08x\n", hr
);
2140 IPropertyStore_Release(ps
);
2141 IMMDevice_Release(device
);
2142 return MMSYSERR_ERROR
;
2144 if(pv
.vt
!= VT_LPWSTR
){
2145 WARN("Got unexpected property type: %u\n", pv
.vt
);
2146 PropVariantClear(&pv
);
2147 IPropertyStore_Release(ps
);
2148 IMMDevice_Release(device
);
2149 return MMSYSERR_ERROR
;
2152 len_bytes
= (lstrlenW(pv
.u
.pwszVal
) + 1) * sizeof(WCHAR
);
2155 if(len_bytes
> *info
->len_bytes
){
2156 PropVariantClear(&pv
);
2157 IPropertyStore_Release(ps
);
2158 IMMDevice_Release(device
);
2159 return MMSYSERR_INVALPARAM
;
2162 memcpy(info
->str
, pv
.u
.pwszVal
, len_bytes
);
2164 *info
->len_bytes
= len_bytes
;
2166 PropVariantClear(&pv
);
2167 IPropertyStore_Release(ps
);
2168 IMMDevice_Release(device
);
2170 return MMSYSERR_NOERROR
;
2173 static LRESULT CALLBACK
WINMM_DevicesMsgProc(HWND hwnd
, UINT msg
, WPARAM wparam
,
2178 return WOD_Open((WINMM_OpenInfo
*)wparam
);
2180 return WOD_Close((HWAVEOUT
)wparam
);
2182 return WID_Open((WINMM_OpenInfo
*)wparam
);
2184 return WID_Close((HWAVEIN
)wparam
);
2185 case MXDM_GETCONTROLDETAILS
:
2186 return MXD_GetControlDetails((WINMM_ControlDetails
*)wparam
);
2187 case MXDM_SETCONTROLDETAILS
:
2188 return MXD_SetControlDetails((WINMM_ControlDetails
*)wparam
);
2189 case DRV_QUERYDEVICEINTERFACESIZE
:
2190 case DRV_QUERYDEVICEINTERFACE
:
2191 return DRV_QueryDeviceInterface((WINMM_QueryInterfaceInfo
*)wparam
);
2193 TRACE("QUIT message received\n");
2194 DestroyWindow(g_devices_hwnd
);
2195 g_devices_hwnd
= NULL
;
2196 IMMDeviceEnumerator_Release(g_devenum
);
2200 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
2203 static DWORD WINAPI
WINMM_DevicesThreadProc(void *arg
)
2207 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e',0};
2209 hr
= CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
2211 WARN("CoInitializeEx failed: %08x\n", hr
);
2215 hr
= WINMM_InitMMDevices();
2221 hr
= CoCreateInstance(&CLSID_MMDeviceEnumerator
, NULL
,
2222 CLSCTX_INPROC_SERVER
, &IID_IMMDeviceEnumerator
, (void**)&g_devenum
);
2224 WARN("CoCreateInstance failed: %08x\n", hr
);
2229 g_devices_hwnd
= CreateWindowW(messageW
, NULL
, 0, 0, 0, 0, 0,
2230 HWND_MESSAGE
, NULL
, NULL
, NULL
);
2231 if(!g_devices_hwnd
){
2232 WARN("CreateWindow failed: %d\n", GetLastError());
2233 IMMDeviceEnumerator_Release(g_devenum
);
2238 SetWindowLongPtrW(g_devices_hwnd
, GWLP_WNDPROC
,
2239 (LONG_PTR
)WINMM_DevicesMsgProc
);
2241 /* inform caller that the thread is ready to process messages */
2243 evt
= NULL
; /* do not use after this point */
2247 wait
= MsgWaitForMultipleObjects(g_devhandle_count
, g_device_handles
,
2248 FALSE
, INFINITE
, QS_ALLINPUT
);
2249 if(wait
== g_devhandle_count
+ WAIT_OBJECT_0
){
2251 if(PeekMessageW(&msg
, g_devices_hwnd
, 0, 0, PM_REMOVE
))
2252 WARN("Unexpected message: 0x%x\n", msg
.message
);
2255 }else if(wait
< g_devhandle_count
+ WAIT_OBJECT_0
){
2256 WINMM_Device
*device
= g_handle_devices
[wait
- WAIT_OBJECT_0
];
2258 WOD_PushData(device
);
2260 WID_PullData(device
);
2262 WARN("Unexpected MsgWait result 0x%x, GLE: %d\n", wait
,
2269 static BOOL
WINMM_StartDevicesThread(void)
2274 EnterCriticalSection(&g_devthread_lock
);
2276 if(g_devices_thread
){
2279 wait
= WaitForSingleObject(g_devices_thread
, 0);
2280 if(wait
== WAIT_TIMEOUT
){
2281 LeaveCriticalSection(&g_devthread_lock
);
2284 if(wait
!= WAIT_OBJECT_0
){
2285 LeaveCriticalSection(&g_devthread_lock
);
2289 g_devices_thread
= NULL
;
2290 g_devices_hwnd
= NULL
;
2293 TRACE("Starting up devices thread\n");
2295 events
[0] = CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2297 g_devices_thread
= CreateThread(NULL
, 0, WINMM_DevicesThreadProc
,
2298 events
[0], 0, NULL
);
2299 if(!g_devices_thread
){
2300 LeaveCriticalSection(&g_devthread_lock
);
2301 CloseHandle(events
[0]);
2305 events
[1] = g_devices_thread
;
2306 wait
= WaitForMultipleObjects(2, events
, FALSE
, INFINITE
);
2307 CloseHandle(events
[0]);
2308 if(wait
!= WAIT_OBJECT_0
){
2309 if(wait
== 1 + WAIT_OBJECT_0
){
2310 CloseHandle(g_devices_thread
);
2311 g_devices_thread
= NULL
;
2312 g_devices_hwnd
= NULL
;
2314 LeaveCriticalSection(&g_devthread_lock
);
2318 LeaveCriticalSection(&g_devthread_lock
);
2323 /**************************************************************************
2324 * waveOutGetNumDevs [WINMM.@]
2326 UINT WINAPI
waveOutGetNumDevs(void)
2328 HRESULT hr
= WINMM_InitMMDevices();
2332 TRACE("count: %u\n", g_outmmdevices_count
);
2334 return g_outmmdevices_count
;
2337 /**************************************************************************
2338 * waveOutGetDevCapsA [WINMM.@]
2340 UINT WINAPI
waveOutGetDevCapsA(UINT_PTR uDeviceID
, LPWAVEOUTCAPSA lpCaps
,
2346 TRACE("(%lu, %p, %u)\n", uDeviceID
, lpCaps
, uSize
);
2349 return MMSYSERR_INVALPARAM
;
2351 ret
= waveOutGetDevCapsW(uDeviceID
, &wocW
, sizeof(wocW
));
2353 if (ret
== MMSYSERR_NOERROR
) {
2355 wocA
.wMid
= wocW
.wMid
;
2356 wocA
.wPid
= wocW
.wPid
;
2357 wocA
.vDriverVersion
= wocW
.vDriverVersion
;
2358 WideCharToMultiByte( CP_ACP
, 0, wocW
.szPname
, -1, wocA
.szPname
,
2359 sizeof(wocA
.szPname
), NULL
, NULL
);
2360 wocA
.dwFormats
= wocW
.dwFormats
;
2361 wocA
.wChannels
= wocW
.wChannels
;
2362 wocA
.dwSupport
= wocW
.dwSupport
;
2363 memcpy(lpCaps
, &wocA
, min(uSize
, sizeof(wocA
)));
2368 /**************************************************************************
2369 * waveOutGetDevCapsW [WINMM.@]
2371 UINT WINAPI
waveOutGetDevCapsW(UINT_PTR uDeviceID
, LPWAVEOUTCAPSW lpCaps
,
2374 WAVEOUTCAPSW mapper_caps
, *caps
;
2377 TRACE("(%lu, %p, %u)\n", uDeviceID
, lpCaps
, uSize
);
2379 hr
= WINMM_InitMMDevices();
2381 return MMSYSERR_ERROR
;
2383 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
2385 if(WINMM_IsMapper(uDeviceID
)){
2386 /* FIXME: Should be localized */
2387 static const WCHAR mapper_pnameW
[] = {'W','i','n','e',' ','S','o','u',
2388 'n','d',' ','M','a','p','p','e','r',0};
2390 mapper_caps
.wMid
= 0xFF;
2391 mapper_caps
.wPid
= 0xFF;
2392 mapper_caps
.vDriverVersion
= 0x00010001;
2393 mapper_caps
.dwFormats
= 0xFFFFFFFF;
2394 mapper_caps
.wReserved1
= 0;
2395 mapper_caps
.dwSupport
= WAVECAPS_LRVOLUME
| WAVECAPS_VOLUME
|
2396 WAVECAPS_SAMPLEACCURATE
;
2397 mapper_caps
.wChannels
= 2;
2398 lstrcpyW(mapper_caps
.szPname
, mapper_pnameW
);
2400 caps
= &mapper_caps
;
2402 if(uDeviceID
>= g_outmmdevices_count
)
2403 return MMSYSERR_BADDEVICEID
;
2405 caps
= &g_out_mmdevices
[uDeviceID
].out_caps
;
2408 memcpy(lpCaps
, caps
, min(uSize
, sizeof(*lpCaps
)));
2410 return MMSYSERR_NOERROR
;
2413 /**************************************************************************
2414 * waveOutGetErrorTextA [WINMM.@]
2415 * waveInGetErrorTextA [WINMM.@]
2417 UINT WINAPI
waveOutGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
2421 if (lpText
== NULL
) ret
= MMSYSERR_INVALPARAM
;
2422 else if (uSize
== 0) ret
= MMSYSERR_NOERROR
;
2425 LPWSTR xstr
= HeapAlloc(GetProcessHeap(), 0, uSize
* sizeof(WCHAR
));
2426 if (!xstr
) ret
= MMSYSERR_NOMEM
;
2429 ret
= waveOutGetErrorTextW(uError
, xstr
, uSize
);
2430 if (ret
== MMSYSERR_NOERROR
)
2431 WideCharToMultiByte(CP_ACP
, 0, xstr
, -1, lpText
, uSize
, NULL
, NULL
);
2432 HeapFree(GetProcessHeap(), 0, xstr
);
2438 /**************************************************************************
2439 * waveOutGetErrorTextW [WINMM.@]
2440 * waveInGetErrorTextW [WINMM.@]
2442 UINT WINAPI
waveOutGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
2444 UINT ret
= MMSYSERR_BADERRNUM
;
2446 if (lpText
== NULL
) ret
= MMSYSERR_INVALPARAM
;
2447 else if (uSize
== 0) ret
= MMSYSERR_NOERROR
;
2449 /* test has been removed because MMSYSERR_BASE is 0, and gcc did emit
2450 * a warning for the test was always true */
2451 (/*uError >= MMSYSERR_BASE && */ uError
<= MMSYSERR_LASTERROR
) ||
2452 (uError
>= WAVERR_BASE
&& uError
<= WAVERR_LASTERROR
)) {
2453 if (LoadStringW(hWinMM32Instance
,
2454 uError
, lpText
, uSize
) > 0) {
2455 ret
= MMSYSERR_NOERROR
;
2461 /**************************************************************************
2462 * waveOutOpen [WINMM.@]
2463 * All the args/structs have the same layout as the win16 equivalents
2465 MMRESULT WINAPI
waveOutOpen(LPHWAVEOUT lphWaveOut
, UINT uDeviceID
,
2466 LPCWAVEFORMATEX lpFormat
, DWORD_PTR dwCallback
,
2467 DWORD_PTR dwInstance
, DWORD dwFlags
)
2470 WINMM_OpenInfo info
;
2471 WINMM_CBInfo cb_info
;
2473 TRACE("(%p, %u, %p, %lx, %lx, %08x)\n", lphWaveOut
, uDeviceID
, lpFormat
,
2474 dwCallback
, dwInstance
, dwFlags
);
2476 if(!WINMM_StartDevicesThread())
2477 return MMSYSERR_ERROR
;
2479 if(!lphWaveOut
&& !(dwFlags
& WAVE_FORMAT_QUERY
))
2480 return MMSYSERR_INVALPARAM
;
2482 res
= WINMM_CheckCallback(dwCallback
, dwFlags
, FALSE
);
2483 if(res
!= MMSYSERR_NOERROR
)
2486 info
.format
= (WAVEFORMATEX
*)lpFormat
;
2487 info
.callback
= dwCallback
;
2488 info
.cb_user
= dwInstance
;
2489 info
.req_device
= uDeviceID
;
2490 info
.flags
= dwFlags
;
2492 res
= SendMessageW(g_devices_hwnd
, WODM_OPEN
, (DWORD_PTR
)&info
, 0);
2493 if(res
!= MMSYSERR_NOERROR
)
2497 *lphWaveOut
= (HWAVEOUT
)info
.handle
;
2499 cb_info
.flags
= HIWORD(dwFlags
& CALLBACK_TYPEMASK
);
2500 cb_info
.callback
= dwCallback
;
2501 cb_info
.user
= dwInstance
;
2502 cb_info
.hwave
= info
.handle
;
2504 WINMM_NotifyClient(&cb_info
, WOM_OPEN
, 0, 0);
2509 /**************************************************************************
2510 * waveOutClose [WINMM.@]
2512 UINT WINAPI
waveOutClose(HWAVEOUT hWaveOut
)
2515 WINMM_Device
*device
;
2516 WINMM_CBInfo cb_info
;
2518 TRACE("(%p)\n", hWaveOut
);
2520 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveOut
);
2522 if(!WINMM_ValidateAndLock(device
))
2523 return MMSYSERR_INVALHANDLE
;
2525 cb_info
= device
->cb_info
;
2527 LeaveCriticalSection(&device
->lock
);
2529 res
= SendMessageW(g_devices_hwnd
, WODM_CLOSE
, (WPARAM
)hWaveOut
, 0);
2531 if(res
== MMSYSERR_NOERROR
)
2532 WINMM_NotifyClient(&cb_info
, WOM_CLOSE
, 0, 0);
2537 /**************************************************************************
2538 * waveOutPrepareHeader [WINMM.@]
2540 UINT WINAPI
waveOutPrepareHeader(HWAVEOUT hWaveOut
,
2541 WAVEHDR
* lpWaveOutHdr
, UINT uSize
)
2543 TRACE("(%p, %p, %u)\n", hWaveOut
, lpWaveOutHdr
, uSize
);
2545 if(!lpWaveOutHdr
|| uSize
< sizeof(WAVEHDR
))
2546 return MMSYSERR_INVALPARAM
;
2548 if(lpWaveOutHdr
->dwFlags
& WHDR_INQUEUE
)
2549 return WAVERR_STILLPLAYING
;
2551 return WINMM_PrepareHeader((HWAVE
)hWaveOut
, lpWaveOutHdr
);
2554 /**************************************************************************
2555 * waveOutUnprepareHeader [WINMM.@]
2557 UINT WINAPI
waveOutUnprepareHeader(HWAVEOUT hWaveOut
,
2558 LPWAVEHDR lpWaveOutHdr
, UINT uSize
)
2560 TRACE("(%p, %p, %u)\n", hWaveOut
, lpWaveOutHdr
, uSize
);
2562 if(!lpWaveOutHdr
|| uSize
< sizeof(WAVEHDR
))
2563 return MMSYSERR_INVALPARAM
;
2565 if(!(lpWaveOutHdr
->dwFlags
& WHDR_PREPARED
))
2566 return MMSYSERR_NOERROR
;
2568 if(lpWaveOutHdr
->dwFlags
& WHDR_INQUEUE
)
2569 return WAVERR_STILLPLAYING
;
2571 return WINMM_UnprepareHeader((HWAVE
)hWaveOut
, lpWaveOutHdr
);
2574 /**************************************************************************
2575 * waveOutWrite [WINMM.@]
2577 UINT WINAPI
waveOutWrite(HWAVEOUT hWaveOut
, WAVEHDR
*header
, UINT uSize
)
2579 WINMM_Device
*device
;
2582 TRACE("(%p, %p, %u)\n", hWaveOut
, header
, uSize
);
2584 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveOut
);
2586 if(!WINMM_ValidateAndLock(device
))
2587 return MMSYSERR_INVALHANDLE
;
2589 if(!header
->lpData
|| !(header
->dwFlags
& WHDR_PREPARED
)){
2590 LeaveCriticalSection(&device
->lock
);
2591 return WAVERR_UNPREPARED
;
2594 if(header
->dwFlags
& WHDR_INQUEUE
){
2595 LeaveCriticalSection(&device
->lock
);
2596 return WAVERR_STILLPLAYING
;
2599 if(device
->acm_handle
){
2600 ACMSTREAMHEADER
*ash
= (ACMSTREAMHEADER
*)header
->reserved
;
2603 ash
->cbSrcLength
= header
->dwBufferLength
;
2604 mr
= acmStreamConvert(device
->acm_handle
, ash
, 0);
2605 if(mr
!= MMSYSERR_NOERROR
){
2606 LeaveCriticalSection(&device
->lock
);
2612 device
->last
->lpNext
= header
;
2613 device
->last
= header
;
2614 if(!device
->playing
)
2615 device
->playing
= header
;
2617 device
->playing
= device
->first
= device
->last
= header
;
2618 if(header
->dwFlags
& WHDR_BEGINLOOP
){
2619 device
->loop_counter
= header
->dwLoops
;
2620 device
->loop_start
= header
;
2624 header
->lpNext
= NULL
;
2625 header
->dwFlags
&= ~WHDR_DONE
;
2626 header
->dwFlags
|= WHDR_INQUEUE
;
2628 hr
= WINMM_BeginPlaying(device
);
2630 LeaveCriticalSection(&device
->lock
);
2631 return MMSYSERR_ERROR
;
2634 LeaveCriticalSection(&device
->lock
);
2636 return MMSYSERR_NOERROR
;
2639 /**************************************************************************
2640 * waveOutBreakLoop [WINMM.@]
2642 UINT WINAPI
waveOutBreakLoop(HWAVEOUT hWaveOut
)
2644 WINMM_Device
*device
;
2646 TRACE("(%p)\n", hWaveOut
);
2648 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveOut
);
2650 if(!WINMM_ValidateAndLock(device
))
2651 return MMSYSERR_INVALHANDLE
;
2653 device
->loop_counter
= 0;
2655 LeaveCriticalSection(&device
->lock
);
2657 return MMSYSERR_NOERROR
;
2660 /**************************************************************************
2661 * waveOutPause [WINMM.@]
2663 UINT WINAPI
waveOutPause(HWAVEOUT hWaveOut
)
2665 TRACE("(%p)\n", hWaveOut
);
2667 return WINMM_Pause((HWAVE
)hWaveOut
);
2670 /**************************************************************************
2671 * waveOutReset [WINMM.@]
2673 UINT WINAPI
waveOutReset(HWAVEOUT hWaveOut
)
2675 TRACE("(%p)\n", hWaveOut
);
2677 return WINMM_Reset((HWAVE
)hWaveOut
);
2680 /**************************************************************************
2681 * waveOutRestart [WINMM.@]
2683 UINT WINAPI
waveOutRestart(HWAVEOUT hWaveOut
)
2685 WINMM_Device
*device
;
2688 TRACE("(%p)\n", hWaveOut
);
2690 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveOut
);
2692 if(!WINMM_ValidateAndLock(device
))
2693 return MMSYSERR_INVALHANDLE
;
2695 device
->stopped
= TRUE
;
2697 hr
= WINMM_BeginPlaying(device
);
2699 LeaveCriticalSection(&device
->lock
);
2700 return MMSYSERR_ERROR
;
2703 LeaveCriticalSection(&device
->lock
);
2705 return MMSYSERR_NOERROR
;
2708 /**************************************************************************
2709 * waveOutGetPosition [WINMM.@]
2711 UINT WINAPI
waveOutGetPosition(HWAVEOUT hWaveOut
, LPMMTIME lpTime
,
2714 TRACE("(%p, %p, %u)\n", hWaveOut
, lpTime
, uSize
);
2716 if(!uSize
|| !lpTime
|| uSize
!= sizeof(MMTIME
))
2717 return MMSYSERR_INVALPARAM
;
2719 return WINMM_GetPosition((HWAVE
)hWaveOut
, lpTime
);
2722 /**************************************************************************
2723 * waveOutGetPitch [WINMM.@]
2725 UINT WINAPI
waveOutGetPitch(HWAVEOUT hWaveOut
, LPDWORD lpdw
)
2727 TRACE("(%p, %p)\n", hWaveOut
, lpdw
);
2728 return MMSYSERR_NOTSUPPORTED
;
2731 /**************************************************************************
2732 * waveOutSetPitch [WINMM.@]
2734 UINT WINAPI
waveOutSetPitch(HWAVEOUT hWaveOut
, DWORD dw
)
2736 TRACE("(%p, %08x)\n", hWaveOut
, dw
);
2738 return MMSYSERR_NOTSUPPORTED
;
2741 /**************************************************************************
2742 * waveOutGetPlaybackRate [WINMM.@]
2744 UINT WINAPI
waveOutGetPlaybackRate(HWAVEOUT hWaveOut
, LPDWORD lpdw
)
2746 TRACE("(%p, %p)\n", hWaveOut
, lpdw
);
2748 return MMSYSERR_NOTSUPPORTED
;
2751 /**************************************************************************
2752 * waveOutSetPlaybackRate [WINMM.@]
2754 UINT WINAPI
waveOutSetPlaybackRate(HWAVEOUT hWaveOut
, DWORD dw
)
2756 TRACE("(%p, %08x)\n", hWaveOut
, dw
);
2758 return MMSYSERR_NOTSUPPORTED
;
2761 /**************************************************************************
2762 * waveOutGetVolume [WINMM.@]
2764 UINT WINAPI
waveOutGetVolume(HWAVEOUT hWaveOut
, DWORD
*out
)
2766 WINMM_Device
*device
;
2771 TRACE("(%p, %p)\n", hWaveOut
, out
);
2774 return MMSYSERR_INVALPARAM
;
2776 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveOut
);
2778 if(!WINMM_ValidateAndLock(device
))
2779 return MMSYSERR_INVALHANDLE
;
2781 hr
= IAudioStreamVolume_GetChannelCount(device
->volume
, &channels
);
2783 LeaveCriticalSection(&device
->lock
);
2784 WARN("GetChannelCount failed: %08x\n", hr
);
2785 return MMSYSERR_ERROR
;
2788 vols
= HeapAlloc(GetProcessHeap(), 0, sizeof(float) * channels
);
2790 LeaveCriticalSection(&device
->lock
);
2791 return MMSYSERR_NOMEM
;
2794 hr
= IAudioStreamVolume_GetAllVolumes(device
->volume
, channels
, vols
);
2796 LeaveCriticalSection(&device
->lock
);
2797 HeapFree(GetProcessHeap(), 0, vols
);
2798 WARN("GetAllVolumes failed: %08x\n", hr
);
2799 return MMSYSERR_ERROR
;
2802 LeaveCriticalSection(&device
->lock
);
2804 *out
= ((UINT16
)(vols
[0] * (DWORD
)0xFFFF));
2806 *out
|= ((UINT16
)(vols
[1] * (DWORD
)0xFFFF)) << 16;
2808 HeapFree(GetProcessHeap(), 0, vols
);
2810 return MMSYSERR_NOERROR
;
2813 /**************************************************************************
2814 * waveOutSetVolume [WINMM.@]
2816 UINT WINAPI
waveOutSetVolume(HWAVEOUT hWaveOut
, DWORD in
)
2818 WINMM_Device
*device
;
2823 TRACE("(%p, %08x)\n", hWaveOut
, in
);
2825 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveOut
);
2827 if(!WINMM_ValidateAndLock(device
))
2828 return MMSYSERR_INVALHANDLE
;
2830 hr
= IAudioStreamVolume_GetChannelCount(device
->volume
, &channels
);
2832 LeaveCriticalSection(&device
->lock
);
2833 WARN("GetChannelCount failed: %08x\n", hr
);
2834 return MMSYSERR_ERROR
;
2837 vols
= HeapAlloc(GetProcessHeap(), 0, sizeof(float) * channels
);
2839 LeaveCriticalSection(&device
->lock
);
2840 return MMSYSERR_NOMEM
;
2843 hr
= IAudioStreamVolume_GetAllVolumes(device
->volume
, channels
, vols
);
2845 LeaveCriticalSection(&device
->lock
);
2846 HeapFree(GetProcessHeap(), 0, vols
);
2847 WARN("GetAllVolumes failed: %08x\n", hr
);
2848 return MMSYSERR_ERROR
;
2851 vols
[0] = (float)((DWORD
)(in
& 0xFFFF) / (float)0xFFFF);
2853 vols
[1] = (float)((DWORD
)(in
>> 16) / (float)0xFFFF);
2855 hr
= IAudioStreamVolume_SetAllVolumes(device
->volume
, channels
, vols
);
2857 LeaveCriticalSection(&device
->lock
);
2858 HeapFree(GetProcessHeap(), 0, vols
);
2859 WARN("SetAllVolumes failed: %08x\n", hr
);
2860 return MMSYSERR_ERROR
;
2863 LeaveCriticalSection(&device
->lock
);
2865 HeapFree(GetProcessHeap(), 0, vols
);
2867 return MMSYSERR_NOERROR
;
2870 /**************************************************************************
2871 * waveOutGetID [WINMM.@]
2873 UINT WINAPI
waveOutGetID(HWAVEOUT hWaveOut
, UINT
* lpuDeviceID
)
2875 WINMM_Device
*device
;
2879 TRACE("(%p, %p)\n", hWaveOut
, lpuDeviceID
);
2882 return MMSYSERR_INVALPARAM
;
2884 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveOut
);
2885 if(!WINMM_ValidateAndLock(device
))
2886 return MMSYSERR_INVALHANDLE
;
2888 LeaveCriticalSection(&device
->lock
);
2890 WINMM_DecomposeHWAVE((HWAVE
)hWaveOut
, lpuDeviceID
, &is_out
, &dev
, &junk
);
2892 return MMSYSERR_NOERROR
;
2895 static UINT
WINMM_QueryInstanceIDSize(UINT device
, DWORD_PTR
*len
, BOOL is_out
)
2898 WINMM_MMDevice
*devices
;
2900 TRACE("(%u, %p, %d)\n", device
, len
, is_out
);
2903 count
= g_outmmdevices_count
;
2904 devices
= g_out_mmdevices
;
2906 count
= g_inmmdevices_count
;
2907 devices
= g_in_mmdevices
;
2911 return MMSYSERR_INVALHANDLE
;
2913 *len
= (lstrlenW(devices
[device
].dev_id
) + 1) * sizeof(WCHAR
);
2915 return MMSYSERR_NOERROR
;
2918 static UINT
WINMM_QueryInstanceID(UINT device
, WCHAR
*str
, DWORD_PTR len
,
2922 WINMM_MMDevice
*devices
;
2924 TRACE("(%u, %p, %d)\n", device
, str
, is_out
);
2927 count
= g_outmmdevices_count
;
2928 devices
= g_out_mmdevices
;
2930 count
= g_inmmdevices_count
;
2931 devices
= g_in_mmdevices
;
2935 return MMSYSERR_INVALHANDLE
;
2937 id_len
= (lstrlenW(devices
[device
].dev_id
) + 1) * sizeof(WCHAR
);
2939 return MMSYSERR_ERROR
;
2941 memcpy(str
, devices
[device
].dev_id
, id_len
);
2943 return MMSYSERR_NOERROR
;
2946 static UINT
get_device_interface(UINT msg
, BOOL is_out
, UINT index
, WCHAR
*out
, ULONG
*out_len
)
2948 WINMM_QueryInterfaceInfo info
;
2950 if(!WINMM_StartDevicesThread())
2951 return MMSYSERR_ERROR
;
2953 info
.is_out
= is_out
;
2956 info
.len_bytes
= out_len
;
2958 return SendMessageW(g_devices_hwnd
, msg
, (DWORD_PTR
)&info
, 0);
2961 /**************************************************************************
2962 * waveOutMessage [WINMM.@]
2964 UINT WINAPI
waveOutMessage(HWAVEOUT hWaveOut
, UINT uMessage
,
2965 DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2967 TRACE("(%p, %u, %lx, %lx)\n", hWaveOut
, uMessage
, dwParam1
, dwParam2
);
2970 case DRV_QUERYFUNCTIONINSTANCEIDSIZE
:
2971 return WINMM_QueryInstanceIDSize(HandleToULong(hWaveOut
),
2972 (DWORD_PTR
*)dwParam1
, TRUE
);
2973 case DRV_QUERYFUNCTIONINSTANCEID
:
2974 return WINMM_QueryInstanceID(HandleToULong(hWaveOut
), (WCHAR
*)dwParam1
, dwParam2
, TRUE
);
2975 case DRV_QUERYDEVICEINTERFACESIZE
:
2976 return get_device_interface(DRV_QUERYDEVICEINTERFACESIZE
, TRUE
, HandleToULong(hWaveOut
),
2977 NULL
, (ULONG
*)dwParam1
);
2978 case DRV_QUERYDEVICEINTERFACE
:
2980 ULONG size
= dwParam2
;
2981 return get_device_interface(DRV_QUERYDEVICEINTERFACE
, TRUE
, HandleToULong(hWaveOut
),
2982 (WCHAR
*)dwParam1
, &size
);
2984 case DRV_QUERYMAPPABLE
:
2985 return MMSYSERR_NOERROR
;
2986 case DRVM_MAPPER_PREFERRED_GET
:
2988 if(g_outmmdevices_count
> 0)
2989 /* Device 0 is always the default device */
2990 *(DWORD
*)dwParam1
= 0;
2992 *(DWORD
*)dwParam1
= -1;
2997 *(DWORD
*)dwParam2
= 0;
2999 return MMSYSERR_NOERROR
;
3002 TRACE("Message not supported: %u\n", uMessage
);
3004 return MMSYSERR_NOTSUPPORTED
;
3007 /**************************************************************************
3008 * waveInGetNumDevs [WINMM.@]
3010 UINT WINAPI
waveInGetNumDevs(void)
3012 HRESULT hr
= WINMM_InitMMDevices();
3016 TRACE("count: %u\n", g_inmmdevices_count
);
3018 return g_inmmdevices_count
;
3021 /**************************************************************************
3022 * waveInGetDevCapsW [WINMM.@]
3024 UINT WINAPI
waveInGetDevCapsW(UINT_PTR uDeviceID
, LPWAVEINCAPSW lpCaps
, UINT uSize
)
3026 WAVEINCAPSW mapper_caps
, *caps
;
3029 TRACE("(%lu, %p, %u)\n", uDeviceID
, lpCaps
, uSize
);
3031 hr
= WINMM_InitMMDevices();
3033 return MMSYSERR_ERROR
;
3036 return MMSYSERR_INVALPARAM
;
3038 if(WINMM_IsMapper(uDeviceID
)){
3039 /* FIXME: Should be localized */
3040 static const WCHAR mapper_pnameW
[] = {'W','i','n','e',' ','S','o','u',
3041 'n','d',' ','M','a','p','p','e','r',0};
3043 mapper_caps
.wMid
= 0xFF;
3044 mapper_caps
.wPid
= 0xFF;
3045 mapper_caps
.vDriverVersion
= 0x00010001;
3046 mapper_caps
.dwFormats
= 0xFFFFFFFF;
3047 mapper_caps
.wReserved1
= 0;
3048 mapper_caps
.wChannels
= 2;
3049 lstrcpyW(mapper_caps
.szPname
, mapper_pnameW
);
3051 caps
= &mapper_caps
;
3053 if(uDeviceID
>= g_inmmdevices_count
)
3054 return MMSYSERR_BADDEVICEID
;
3056 caps
= &g_in_mmdevices
[uDeviceID
].in_caps
;
3059 memcpy(lpCaps
, caps
, min(uSize
, sizeof(*lpCaps
)));
3061 return MMSYSERR_NOERROR
;
3064 /**************************************************************************
3065 * waveInGetDevCapsA [WINMM.@]
3067 UINT WINAPI
waveInGetDevCapsA(UINT_PTR uDeviceID
, LPWAVEINCAPSA lpCaps
, UINT uSize
)
3072 TRACE("(%lu, %p, %u)\n", uDeviceID
, lpCaps
, uSize
);
3075 return MMSYSERR_INVALPARAM
;
3077 ret
= waveInGetDevCapsW(uDeviceID
, &wicW
, sizeof(wicW
));
3079 if (ret
== MMSYSERR_NOERROR
) {
3081 wicA
.wMid
= wicW
.wMid
;
3082 wicA
.wPid
= wicW
.wPid
;
3083 wicA
.vDriverVersion
= wicW
.vDriverVersion
;
3084 WideCharToMultiByte( CP_ACP
, 0, wicW
.szPname
, -1, wicA
.szPname
,
3085 sizeof(wicA
.szPname
), NULL
, NULL
);
3086 wicA
.dwFormats
= wicW
.dwFormats
;
3087 wicA
.wChannels
= wicW
.wChannels
;
3088 memcpy(lpCaps
, &wicA
, min(uSize
, sizeof(wicA
)));
3093 /**************************************************************************
3094 * waveInOpen [WINMM.@]
3096 MMRESULT WINAPI
waveInOpen(HWAVEIN
* lphWaveIn
, UINT uDeviceID
,
3097 LPCWAVEFORMATEX lpFormat
, DWORD_PTR dwCallback
,
3098 DWORD_PTR dwInstance
, DWORD dwFlags
)
3101 WINMM_OpenInfo info
;
3102 WINMM_CBInfo cb_info
;
3104 TRACE("(%p, %x, %p, %lx, %lx, %08x)\n", lphWaveIn
, uDeviceID
, lpFormat
,
3105 dwCallback
, dwInstance
, dwFlags
);
3107 if(!WINMM_StartDevicesThread())
3108 return MMSYSERR_ERROR
;
3110 if(!lphWaveIn
&& !(dwFlags
& WAVE_FORMAT_QUERY
))
3111 return MMSYSERR_INVALPARAM
;
3113 res
= WINMM_CheckCallback(dwCallback
, dwFlags
, FALSE
);
3114 if(res
!= MMSYSERR_NOERROR
)
3117 info
.format
= (WAVEFORMATEX
*)lpFormat
;
3118 info
.callback
= dwCallback
;
3119 info
.cb_user
= dwInstance
;
3120 info
.req_device
= uDeviceID
;
3121 info
.flags
= dwFlags
;
3123 res
= SendMessageW(g_devices_hwnd
, WIDM_OPEN
, (DWORD_PTR
)&info
, 0);
3124 if(res
!= MMSYSERR_NOERROR
)
3128 *lphWaveIn
= (HWAVEIN
)info
.handle
;
3130 cb_info
.flags
= HIWORD(dwFlags
& CALLBACK_TYPEMASK
);
3131 cb_info
.callback
= dwCallback
;
3132 cb_info
.user
= dwInstance
;
3133 cb_info
.hwave
= info
.handle
;
3135 WINMM_NotifyClient(&cb_info
, WIM_OPEN
, 0, 0);
3140 /**************************************************************************
3141 * waveInClose [WINMM.@]
3143 UINT WINAPI
waveInClose(HWAVEIN hWaveIn
)
3145 WINMM_Device
*device
;
3146 WINMM_CBInfo cb_info
;
3149 TRACE("(%p)\n", hWaveIn
);
3151 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveIn
);
3153 if(!WINMM_ValidateAndLock(device
))
3154 return MMSYSERR_INVALHANDLE
;
3156 cb_info
= device
->cb_info
;
3158 LeaveCriticalSection(&device
->lock
);
3160 res
= SendMessageW(g_devices_hwnd
, WIDM_CLOSE
, (WPARAM
)hWaveIn
, 0);
3162 if(res
== MMSYSERR_NOERROR
)
3163 WINMM_NotifyClient(&cb_info
, WIM_CLOSE
, 0, 0);
3168 /**************************************************************************
3169 * waveInPrepareHeader [WINMM.@]
3171 UINT WINAPI
waveInPrepareHeader(HWAVEIN hWaveIn
, WAVEHDR
* lpWaveInHdr
,
3174 TRACE("(%p, %p, %u)\n", hWaveIn
, lpWaveInHdr
, uSize
);
3176 if(!lpWaveInHdr
|| uSize
< sizeof(WAVEHDR
))
3177 return MMSYSERR_INVALPARAM
;
3179 if(lpWaveInHdr
->dwFlags
& WHDR_INQUEUE
)
3180 return WAVERR_STILLPLAYING
;
3182 return WINMM_PrepareHeader((HWAVE
)hWaveIn
, lpWaveInHdr
);
3185 /**************************************************************************
3186 * waveInUnprepareHeader [WINMM.@]
3188 UINT WINAPI
waveInUnprepareHeader(HWAVEIN hWaveIn
, WAVEHDR
* lpWaveInHdr
,
3191 TRACE("(%p, %p, %u)\n", hWaveIn
, lpWaveInHdr
, uSize
);
3193 if(!lpWaveInHdr
|| uSize
< sizeof(WAVEHDR
))
3194 return MMSYSERR_INVALPARAM
;
3196 if(!(lpWaveInHdr
->dwFlags
& WHDR_PREPARED
))
3197 return MMSYSERR_NOERROR
;
3199 if(lpWaveInHdr
->dwFlags
& WHDR_INQUEUE
)
3200 return WAVERR_STILLPLAYING
;
3202 return WINMM_UnprepareHeader((HWAVE
)hWaveIn
, lpWaveInHdr
);
3205 /**************************************************************************
3206 * waveInAddBuffer [WINMM.@]
3208 UINT WINAPI
waveInAddBuffer(HWAVEIN hWaveIn
, WAVEHDR
*header
, UINT uSize
)
3210 WINMM_Device
*device
;
3212 TRACE("(%p, %p, %u)\n", hWaveIn
, header
, uSize
);
3214 if(!header
|| uSize
< sizeof(WAVEHDR
))
3215 return MMSYSERR_INVALPARAM
;
3217 if(!(header
->dwFlags
& WHDR_PREPARED
))
3218 return WAVERR_UNPREPARED
;
3220 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveIn
);
3222 if(!WINMM_ValidateAndLock(device
))
3223 return MMSYSERR_INVALHANDLE
;
3226 device
->first
= device
->last
= header
;
3228 device
->last
->lpNext
= header
;
3229 device
->last
= header
;
3232 header
->dwBytesRecorded
= 0;
3233 header
->lpNext
= NULL
;
3234 header
->dwFlags
&= ~WHDR_DONE
;
3235 header
->dwFlags
|= WHDR_INQUEUE
;
3237 LeaveCriticalSection(&device
->lock
);
3239 return MMSYSERR_NOERROR
;
3242 /**************************************************************************
3243 * waveInReset [WINMM.@]
3245 UINT WINAPI
waveInReset(HWAVEIN hWaveIn
)
3247 TRACE("(%p)\n", hWaveIn
);
3249 return WINMM_Reset((HWAVE
)hWaveIn
);
3252 /**************************************************************************
3253 * waveInStart [WINMM.@]
3255 UINT WINAPI
waveInStart(HWAVEIN hWaveIn
)
3257 WINMM_Device
*device
;
3260 TRACE("(%p)\n", hWaveIn
);
3262 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveIn
);
3264 if(!WINMM_ValidateAndLock(device
))
3265 return MMSYSERR_INVALHANDLE
;
3267 hr
= WINMM_BeginPlaying(device
);
3269 LeaveCriticalSection(&device
->lock
);
3270 return MMSYSERR_ERROR
;
3273 LeaveCriticalSection(&device
->lock
);
3275 return MMSYSERR_NOERROR
;
3278 /**************************************************************************
3279 * waveInStop [WINMM.@]
3281 UINT WINAPI
waveInStop(HWAVEIN hWaveIn
)
3283 WINMM_CBInfo cb_info
;
3284 WINMM_Device
*device
;
3288 TRACE("(%p)\n", hWaveIn
);
3290 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveIn
);
3292 if(!WINMM_ValidateAndLock(device
))
3293 return MMSYSERR_INVALHANDLE
;
3295 hr
= WINMM_Pause((HWAVE
)hWaveIn
);
3297 LeaveCriticalSection(&device
->lock
);
3298 return MMSYSERR_ERROR
;
3300 device
->stopped
= TRUE
;
3302 buf
= device
->first
;
3303 if(buf
&& buf
->dwBytesRecorded
> 0){
3304 device
->first
= buf
->lpNext
;
3308 cb_info
= device
->cb_info
;
3310 LeaveCriticalSection(&device
->lock
);
3313 buf
->dwFlags
&= ~WHDR_INQUEUE
;
3314 buf
->dwFlags
|= WHDR_DONE
;
3315 WINMM_NotifyClient(&cb_info
, WIM_DATA
, (DWORD_PTR
)buf
, 0);
3318 return MMSYSERR_NOERROR
;
3321 /**************************************************************************
3322 * waveInGetPosition [WINMM.@]
3324 UINT WINAPI
waveInGetPosition(HWAVEIN hWaveIn
, LPMMTIME lpTime
,
3327 TRACE("(%p, %p, %u)\n", hWaveIn
, lpTime
, uSize
);
3329 if(!uSize
|| !lpTime
|| uSize
!= sizeof(MMTIME
))
3330 return MMSYSERR_INVALPARAM
;
3332 return WINMM_GetPosition((HWAVE
)hWaveIn
, lpTime
);
3335 /**************************************************************************
3336 * waveInGetID [WINMM.@]
3338 UINT WINAPI
waveInGetID(HWAVEIN hWaveIn
, UINT
* lpuDeviceID
)
3342 WINMM_Device
*device
;
3344 TRACE("(%p, %p)\n", hWaveIn
, lpuDeviceID
);
3347 return MMSYSERR_INVALPARAM
;
3349 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveIn
);
3350 if(!WINMM_ValidateAndLock(device
))
3351 return MMSYSERR_INVALHANDLE
;
3353 LeaveCriticalSection(&device
->lock
);
3355 WINMM_DecomposeHWAVE((HWAVE
)hWaveIn
, lpuDeviceID
, &is_out
, &dev
, &junk
);
3357 return MMSYSERR_NOERROR
;
3360 /**************************************************************************
3361 * waveInMessage [WINMM.@]
3363 UINT WINAPI
waveInMessage(HWAVEIN hWaveIn
, UINT uMessage
,
3364 DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
3366 TRACE("(%p, %u, %ld, %ld)\n", hWaveIn
, uMessage
, dwParam1
, dwParam2
);
3369 case DRV_QUERYFUNCTIONINSTANCEIDSIZE
:
3370 return WINMM_QueryInstanceIDSize(HandleToULong(hWaveIn
),
3371 (DWORD_PTR
*)dwParam1
, FALSE
);
3372 case DRV_QUERYFUNCTIONINSTANCEID
:
3373 return WINMM_QueryInstanceID(HandleToULong(hWaveIn
), (WCHAR
*)dwParam1
, dwParam2
, FALSE
);
3374 case DRV_QUERYDEVICEINTERFACESIZE
:
3375 return get_device_interface(DRV_QUERYDEVICEINTERFACESIZE
, FALSE
, HandleToULong(hWaveIn
),
3376 NULL
, (ULONG
*)dwParam1
);
3377 case DRV_QUERYDEVICEINTERFACE
:
3379 ULONG size
= dwParam2
;
3380 return get_device_interface(DRV_QUERYDEVICEINTERFACE
, FALSE
, HandleToULong(hWaveIn
),
3381 (WCHAR
*)dwParam1
, &size
);
3383 case DRV_QUERYMAPPABLE
:
3384 return MMSYSERR_NOERROR
;
3385 case DRVM_MAPPER_PREFERRED_GET
:
3387 if(g_inmmdevices_count
> 0)
3388 /* Device 0 is always the default device */
3389 *(DWORD
*)dwParam1
= 0;
3391 *(DWORD
*)dwParam1
= -1;
3396 *(DWORD
*)dwParam2
= 0;
3398 return MMSYSERR_NOERROR
;
3401 TRACE("Message not supported: %u\n", uMessage
);
3403 return MMSYSERR_NOTSUPPORTED
;
3406 UINT WINAPI
mixerGetNumDevs(void)
3412 hr
= WINMM_InitMMDevices();
3416 return g_outmmdevices_count
+ g_inmmdevices_count
;
3419 /**************************************************************************
3420 * mixerGetDevCapsA [WINMM.@]
3422 UINT WINAPI
mixerGetDevCapsA(UINT_PTR uDeviceID
, LPMIXERCAPSA lpCaps
, UINT uSize
)
3427 TRACE("(%lu, %p, %u)\n", uDeviceID
, lpCaps
, uSize
);
3430 return MMSYSERR_INVALPARAM
;
3432 ret
= mixerGetDevCapsW(uDeviceID
, &micW
, sizeof(micW
));
3434 if (ret
== MMSYSERR_NOERROR
) {
3436 micA
.wMid
= micW
.wMid
;
3437 micA
.wPid
= micW
.wPid
;
3438 micA
.vDriverVersion
= micW
.vDriverVersion
;
3439 WideCharToMultiByte( CP_ACP
, 0, micW
.szPname
, -1, micA
.szPname
,
3440 sizeof(micA
.szPname
), NULL
, NULL
);
3441 micA
.fdwSupport
= micW
.fdwSupport
;
3442 micA
.cDestinations
= micW
.cDestinations
;
3443 memcpy(lpCaps
, &micA
, min(uSize
, sizeof(micA
)));
3448 /**************************************************************************
3449 * mixerGetDevCapsW [WINMM.@]
3451 UINT WINAPI
mixerGetDevCapsW(UINT_PTR uDeviceID
, LPMIXERCAPSW lpCaps
, UINT uSize
)
3453 WINMM_MMDevice
*mmdevice
;
3457 TRACE("(%lu, %p, %u)\n", uDeviceID
, lpCaps
, uSize
);
3459 hr
= WINMM_InitMMDevices();
3461 return MMSYSERR_ERROR
;
3464 return MMSYSERR_INVALPARAM
;
3467 return MMSYSERR_NOERROR
;
3469 if(uDeviceID
>= g_outmmdevices_count
+ g_inmmdevices_count
)
3470 return MMSYSERR_BADDEVICEID
;
3472 if(uDeviceID
< g_outmmdevices_count
){
3473 mmdevice
= &g_out_mmdevices
[uDeviceID
];
3474 memcpy(caps
.szPname
, mmdevice
->out_caps
.szPname
, sizeof(caps
.szPname
));
3476 mmdevice
= &g_in_mmdevices
[uDeviceID
- g_outmmdevices_count
];
3477 memcpy(caps
.szPname
, mmdevice
->in_caps
.szPname
, sizeof(caps
.szPname
));
3482 caps
.vDriverVersion
= 0x00010001;
3483 caps
.fdwSupport
= 0;
3484 caps
.cDestinations
= 1;
3486 memcpy(lpCaps
, &caps
, uSize
);
3488 return MMSYSERR_NOERROR
;
3491 /**************************************************************************
3492 * mixerOpen [WINMM.@]
3494 UINT WINAPI
mixerOpen(LPHMIXER lphMix
, UINT uDeviceID
, DWORD_PTR dwCallback
,
3495 DWORD_PTR dwInstance
, DWORD fdwOpen
)
3497 WINMM_MMDevice
*mmdevice
;
3501 TRACE("(%p, %d, %lx, %lx, %x)\n", lphMix
, uDeviceID
, dwCallback
,
3502 dwInstance
, fdwOpen
);
3504 hr
= WINMM_InitMMDevices();
3506 return MMSYSERR_ERROR
;
3509 return MMSYSERR_INVALPARAM
;
3511 mr
= WINMM_CheckCallback(dwCallback
, fdwOpen
, TRUE
);
3512 if(mr
!= MMSYSERR_NOERROR
)
3515 if(uDeviceID
>= g_outmmdevices_count
+ g_inmmdevices_count
)
3516 return MMSYSERR_BADDEVICEID
;
3518 if(uDeviceID
< g_outmmdevices_count
){
3519 mmdevice
= &g_out_mmdevices
[uDeviceID
];
3520 *lphMix
= (HMIXER
)WINMM_MakeHWAVE(uDeviceID
, TRUE
,
3521 mmdevice
->mixer_count
);
3523 mmdevice
= &g_in_mmdevices
[uDeviceID
- g_outmmdevices_count
];
3524 *lphMix
= (HMIXER
)WINMM_MakeHWAVE(uDeviceID
- g_outmmdevices_count
,
3525 FALSE
, mmdevice
->mixer_count
);
3528 ++mmdevice
->mixer_count
;
3530 return MMSYSERR_NOERROR
;
3533 /**************************************************************************
3534 * mixerClose [WINMM.@]
3536 UINT WINAPI
mixerClose(HMIXER hMix
)
3538 TRACE("(%p)\n", hMix
);
3540 return MMSYSERR_NOERROR
;
3543 /**************************************************************************
3544 * mixerGetID [WINMM.@]
3546 UINT WINAPI
mixerGetID(HMIXEROBJ hmix
, LPUINT lpid
, DWORD fdwID
)
3548 WINMM_MMDevice
*mmdevice
;
3551 TRACE("(%p, %p, %x)\n", hmix
, lpid
, fdwID
);
3553 hr
= WINMM_InitMMDevices();
3555 return MMSYSERR_ERROR
;
3558 return MMSYSERR_INVALPARAM
;
3560 mmdevice
= WINMM_GetMixerMMDevice(hmix
, fdwID
, lpid
);
3562 return MMSYSERR_INVALHANDLE
;
3564 if(mmdevice
->in_caps
.szPname
[0] != '\0')
3565 *lpid
+= g_outmmdevices_count
;
3567 return MMSYSERR_NOERROR
;
3570 /**************************************************************************
3571 * mixerGetControlDetailsW [WINMM.@]
3573 UINT WINAPI
mixerGetControlDetailsW(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcdW
,
3576 WINMM_ControlDetails details
;
3579 TRACE("(%p, %p, %x)\n", hmix
, lpmcdW
, fdwDetails
);
3581 hr
= WINMM_InitMMDevices();
3583 return MMSYSERR_ERROR
;
3586 return MMSYSERR_INVALPARAM
;
3588 TRACE("dwControlID: %u\n", lpmcdW
->dwControlID
);
3590 details
.hmix
= hmix
;
3591 details
.details
= lpmcdW
;
3592 details
.flags
= fdwDetails
;
3594 return SendMessageW(g_devices_hwnd
, MXDM_GETCONTROLDETAILS
,
3595 (DWORD_PTR
)&details
, 0);
3598 /**************************************************************************
3599 * mixerGetControlDetailsA [WINMM.@]
3601 UINT WINAPI
mixerGetControlDetailsA(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcdA
,
3604 UINT ret
= MMSYSERR_NOTSUPPORTED
;
3606 TRACE("(%p, %p, %08x)\n", hmix
, lpmcdA
, fdwDetails
);
3608 if (lpmcdA
== NULL
|| lpmcdA
->cbStruct
!= sizeof(*lpmcdA
))
3609 return MMSYSERR_INVALPARAM
;
3611 switch (fdwDetails
& MIXER_GETCONTROLDETAILSF_QUERYMASK
) {
3612 case MIXER_GETCONTROLDETAILSF_VALUE
:
3613 /* can safely use A structure as it is, no string inside */
3614 ret
= mixerGetControlDetailsW(hmix
, lpmcdA
, fdwDetails
);
3616 case MIXER_GETCONTROLDETAILSF_LISTTEXT
:
3618 MIXERCONTROLDETAILS_LISTTEXTA
*pDetailsA
= lpmcdA
->paDetails
;
3619 MIXERCONTROLDETAILS_LISTTEXTW
*pDetailsW
;
3620 int size
= max(1, lpmcdA
->cChannels
) * sizeof(MIXERCONTROLDETAILS_LISTTEXTW
);
3623 if (lpmcdA
->u
.cMultipleItems
!= 0) {
3624 size
*= lpmcdA
->u
.cMultipleItems
;
3626 pDetailsW
= HeapAlloc(GetProcessHeap(), 0, size
);
3627 lpmcdA
->paDetails
= pDetailsW
;
3628 lpmcdA
->cbDetails
= sizeof(MIXERCONTROLDETAILS_LISTTEXTW
);
3629 /* set up lpmcd->paDetails */
3630 ret
= mixerGetControlDetailsW(hmix
, lpmcdA
, fdwDetails
);
3631 /* copy from lpmcd->paDetails back to paDetailsW; */
3632 if (ret
== MMSYSERR_NOERROR
) {
3633 for (i
= 0; i
< lpmcdA
->u
.cMultipleItems
* lpmcdA
->cChannels
; i
++) {
3634 pDetailsA
->dwParam1
= pDetailsW
->dwParam1
;
3635 pDetailsA
->dwParam2
= pDetailsW
->dwParam2
;
3636 WideCharToMultiByte( CP_ACP
, 0, pDetailsW
->szName
, -1,
3638 sizeof(pDetailsA
->szName
), NULL
, NULL
);
3642 pDetailsA
-= lpmcdA
->u
.cMultipleItems
* lpmcdA
->cChannels
;
3643 pDetailsW
-= lpmcdA
->u
.cMultipleItems
* lpmcdA
->cChannels
;
3645 HeapFree(GetProcessHeap(), 0, pDetailsW
);
3646 lpmcdA
->paDetails
= pDetailsA
;
3647 lpmcdA
->cbDetails
= sizeof(MIXERCONTROLDETAILS_LISTTEXTA
);
3651 WARN("Unsupported fdwDetails=0x%08x\n", fdwDetails
);
3657 /**************************************************************************
3658 * mixerGetLineControlsA [WINMM.@]
3660 UINT WINAPI
mixerGetLineControlsA(HMIXEROBJ hmix
, LPMIXERLINECONTROLSA lpmlcA
,
3663 MIXERLINECONTROLSW mlcW
;
3667 TRACE("(%p, %p, %x)\n", hmix
, lpmlcA
, fdwControls
);
3669 if (lpmlcA
== NULL
|| lpmlcA
->cbStruct
!= sizeof(*lpmlcA
) ||
3670 lpmlcA
->cbmxctrl
!= sizeof(MIXERCONTROLA
))
3671 return MMSYSERR_INVALPARAM
;
3673 mlcW
.cbStruct
= sizeof(mlcW
);
3674 mlcW
.dwLineID
= lpmlcA
->dwLineID
;
3675 mlcW
.u
.dwControlID
= lpmlcA
->u
.dwControlID
;
3676 mlcW
.u
.dwControlType
= lpmlcA
->u
.dwControlType
;
3678 /* Debugging on Windows shows for MIXER_GETLINECONTROLSF_ONEBYTYPE only,
3679 the control count is assumed to be 1 - This is relied upon by a game,
3680 "Dynomite Deluze" */
3681 if (MIXER_GETLINECONTROLSF_ONEBYTYPE
== (fdwControls
& MIXER_GETLINECONTROLSF_QUERYMASK
)) {
3684 mlcW
.cControls
= lpmlcA
->cControls
;
3686 mlcW
.cbmxctrl
= sizeof(MIXERCONTROLW
);
3687 mlcW
.pamxctrl
= HeapAlloc(GetProcessHeap(), 0,
3688 mlcW
.cControls
* mlcW
.cbmxctrl
);
3690 ret
= mixerGetLineControlsW(hmix
, &mlcW
, fdwControls
);
3692 if (ret
== MMSYSERR_NOERROR
) {
3693 lpmlcA
->dwLineID
= mlcW
.dwLineID
;
3694 lpmlcA
->u
.dwControlID
= mlcW
.u
.dwControlID
;
3695 lpmlcA
->u
.dwControlType
= mlcW
.u
.dwControlType
;
3697 for (i
= 0; i
< mlcW
.cControls
; i
++) {
3698 lpmlcA
->pamxctrl
[i
].cbStruct
= sizeof(MIXERCONTROLA
);
3699 lpmlcA
->pamxctrl
[i
].dwControlID
= mlcW
.pamxctrl
[i
].dwControlID
;
3700 lpmlcA
->pamxctrl
[i
].dwControlType
= mlcW
.pamxctrl
[i
].dwControlType
;
3701 lpmlcA
->pamxctrl
[i
].fdwControl
= mlcW
.pamxctrl
[i
].fdwControl
;
3702 lpmlcA
->pamxctrl
[i
].cMultipleItems
= mlcW
.pamxctrl
[i
].cMultipleItems
;
3703 WideCharToMultiByte( CP_ACP
, 0, mlcW
.pamxctrl
[i
].szShortName
, -1,
3704 lpmlcA
->pamxctrl
[i
].szShortName
,
3705 sizeof(lpmlcA
->pamxctrl
[i
].szShortName
), NULL
, NULL
);
3706 WideCharToMultiByte( CP_ACP
, 0, mlcW
.pamxctrl
[i
].szName
, -1,
3707 lpmlcA
->pamxctrl
[i
].szName
,
3708 sizeof(lpmlcA
->pamxctrl
[i
].szName
), NULL
, NULL
);
3709 /* sizeof(lpmlcA->pamxctrl[i].Bounds) ==
3710 * sizeof(mlcW.pamxctrl[i].Bounds) */
3711 memcpy(&lpmlcA
->pamxctrl
[i
].Bounds
, &mlcW
.pamxctrl
[i
].Bounds
,
3712 sizeof(mlcW
.pamxctrl
[i
].Bounds
));
3713 /* sizeof(lpmlcA->pamxctrl[i].Metrics) ==
3714 * sizeof(mlcW.pamxctrl[i].Metrics) */
3715 memcpy(&lpmlcA
->pamxctrl
[i
].Metrics
, &mlcW
.pamxctrl
[i
].Metrics
,
3716 sizeof(mlcW
.pamxctrl
[i
].Metrics
));
3720 HeapFree(GetProcessHeap(), 0, mlcW
.pamxctrl
);
3725 static UINT
WINMM_GetVolumeLineControl(WINMM_MMDevice
*mmdevice
, DWORD line
,
3726 MIXERCONTROLW
*ctl
, DWORD flags
)
3728 ctl
->dwControlID
= (line
== 0xFFFF0000) ? 0 : 2;
3729 ctl
->dwControlType
= MIXERCONTROL_CONTROLTYPE_VOLUME
;
3730 ctl
->fdwControl
= MIXERCONTROL_CONTROLF_UNIFORM
;
3731 ctl
->cMultipleItems
= 0;
3732 lstrcpyW(ctl
->szShortName
, volumeW
);
3733 lstrcpyW(ctl
->szName
, volumeW
);
3734 ctl
->Bounds
.s1
.dwMinimum
= 0;
3735 ctl
->Bounds
.s1
.dwMaximum
= 0xFFFF;
3736 ctl
->Metrics
.cSteps
= 192;
3738 return MMSYSERR_NOERROR
;
3741 static UINT
WINMM_GetMuteLineControl(WINMM_MMDevice
*mmdevice
, DWORD line
,
3742 MIXERCONTROLW
*ctl
, DWORD flags
)
3744 ctl
->dwControlID
= (line
== 0xFFFF0000) ? 1 : 3;
3745 ctl
->dwControlType
= MIXERCONTROL_CONTROLTYPE_MUTE
;
3746 ctl
->fdwControl
= MIXERCONTROL_CONTROLF_UNIFORM
;
3747 ctl
->cMultipleItems
= 0;
3748 lstrcpyW(ctl
->szShortName
, muteW
);
3749 lstrcpyW(ctl
->szName
, muteW
);
3750 ctl
->Bounds
.s1
.dwMinimum
= 0;
3751 ctl
->Bounds
.s1
.dwMaximum
= 1;
3752 ctl
->Metrics
.cSteps
= 0;
3754 return MMSYSERR_NOERROR
;
3757 /**************************************************************************
3758 * mixerGetLineControlsW [WINMM.@]
3760 UINT WINAPI
mixerGetLineControlsW(HMIXEROBJ hmix
, LPMIXERLINECONTROLSW lpmlcW
,
3763 WINMM_MMDevice
*mmdevice
;
3766 TRACE("(%p, %p, %08x)\n", hmix
, lpmlcW
, fdwControls
);
3768 hr
= WINMM_InitMMDevices();
3770 return MMSYSERR_ERROR
;
3772 if(fdwControls
& ~(MIXER_GETLINECONTROLSF_ALL
|
3773 MIXER_GETLINECONTROLSF_ONEBYID
|
3774 MIXER_GETLINECONTROLSF_ONEBYTYPE
|
3775 MIXER_OBJECTF_HMIXER
|
3776 MIXER_OBJECTF_MIXER
)){
3777 WARN("Unknown GetLineControls flag: %x\n", fdwControls
);
3778 return MMSYSERR_INVALFLAG
;
3781 if(!lpmlcW
|| lpmlcW
->cbStruct
< sizeof(*lpmlcW
) || !lpmlcW
->pamxctrl
)
3782 return MMSYSERR_INVALPARAM
;
3784 TRACE("dwLineID: %u\n", lpmlcW
->dwLineID
);
3785 TRACE("dwControl: %x\n", lpmlcW
->u
.dwControlID
);
3786 TRACE("cControls: %u\n", lpmlcW
->cControls
);
3788 mmdevice
= WINMM_GetMixerMMDevice(hmix
, fdwControls
, NULL
);
3790 return MMSYSERR_INVALHANDLE
;
3792 switch(fdwControls
& MIXER_GETLINECONTROLSF_QUERYMASK
){
3793 case MIXER_GETLINECONTROLSF_ALL
:
3794 if(lpmlcW
->cControls
!= 2)
3795 return MMSYSERR_INVALPARAM
;
3796 if(lpmlcW
->cbmxctrl
< sizeof(MIXERCONTROLW
))
3797 return MMSYSERR_INVALPARAM
;
3798 if(lpmlcW
->dwLineID
!= 0 && lpmlcW
->dwLineID
!= 0xFFFF0000)
3799 return MIXERR_INVALLINE
;
3800 WINMM_GetVolumeLineControl(mmdevice
, lpmlcW
->dwLineID
,
3801 &lpmlcW
->pamxctrl
[0], fdwControls
);
3802 WINMM_GetMuteLineControl(mmdevice
, lpmlcW
->dwLineID
,
3803 &lpmlcW
->pamxctrl
[1], fdwControls
);
3804 return MMSYSERR_NOERROR
;
3805 case MIXER_GETLINECONTROLSF_ONEBYID
:
3806 if(lpmlcW
->cControls
!= 1)
3807 return MMSYSERR_INVALPARAM
;
3808 if(lpmlcW
->cbmxctrl
< sizeof(MIXERCONTROLW
))
3809 return MMSYSERR_INVALPARAM
;
3810 if(lpmlcW
->dwLineID
!= 0 && lpmlcW
->dwLineID
!= 0xFFFF0000)
3811 return MIXERR_INVALLINE
;
3812 if(lpmlcW
->u
.dwControlID
== 0)
3813 return WINMM_GetVolumeLineControl(mmdevice
, lpmlcW
->dwLineID
,
3814 lpmlcW
->pamxctrl
, fdwControls
);
3815 if(lpmlcW
->u
.dwControlID
== 1)
3816 return WINMM_GetMuteLineControl(mmdevice
, lpmlcW
->dwLineID
,
3817 lpmlcW
->pamxctrl
, fdwControls
);
3818 return MMSYSERR_NOTSUPPORTED
;
3819 case MIXER_GETLINECONTROLSF_ONEBYTYPE
:
3820 if(lpmlcW
->cControls
!= 1)
3821 return MMSYSERR_INVALPARAM
;
3822 if(lpmlcW
->cbmxctrl
< sizeof(MIXERCONTROLW
))
3823 return MMSYSERR_INVALPARAM
;
3824 if(lpmlcW
->dwLineID
!= 0 && lpmlcW
->dwLineID
!= 0xFFFF0000)
3825 return MIXERR_INVALLINE
;
3826 if(lpmlcW
->u
.dwControlType
== MIXERCONTROL_CONTROLTYPE_VOLUME
)
3827 return WINMM_GetVolumeLineControl(mmdevice
, lpmlcW
->dwLineID
,
3828 lpmlcW
->pamxctrl
, fdwControls
);
3829 if(lpmlcW
->u
.dwControlType
== MIXERCONTROL_CONTROLTYPE_MUTE
)
3830 return WINMM_GetMuteLineControl(mmdevice
, lpmlcW
->dwLineID
,
3831 lpmlcW
->pamxctrl
, fdwControls
);
3832 return MMSYSERR_NOTSUPPORTED
;
3835 return MMSYSERR_NOTSUPPORTED
;
3838 static UINT
WINMM_GetSourceLineInfo(WINMM_MMDevice
*mmdevice
, UINT mmdev_index
,
3839 MIXERLINEW
*info
, DWORD flags
)
3842 if(mmdevice
->in_caps
.szPname
[0] != '\0')
3845 if(info
->dwSource
!= 0)
3846 return MIXERR_INVALLINE
;
3848 info
->dwDestination
= 0;
3850 info
->fdwLine
= MIXERLINE_LINEF_ACTIVE
| MIXERLINE_LINEF_SOURCE
;
3851 info
->cConnections
= 0;
3852 info
->cControls
= 2;
3853 /* volume & mute always affect all channels, so claim 1 channel */
3854 info
->cChannels
= 1;
3855 info
->Target
.dwDeviceID
= mmdev_index
;
3856 info
->Target
.wMid
= ~0;
3857 info
->Target
.wPid
= ~0;
3858 info
->Target
.vDriverVersion
= 0;
3860 lstrcpyW(info
->szShortName
, volumeW
);
3861 lstrcpyW(info
->szName
, mastervolumeW
);
3864 info
->dwComponentType
= MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT
;
3865 info
->Target
.dwType
= MIXERLINE_TARGETTYPE_WAVEOUT
;
3866 memcpy(info
->Target
.szPname
, mmdevice
->out_caps
.szPname
,
3867 sizeof(info
->Target
.szPname
));
3869 info
->dwComponentType
= MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE
;
3870 info
->Target
.dwType
= MIXERLINE_TARGETTYPE_UNDEFINED
;
3871 info
->Target
.szPname
[0] = '\0';
3874 return MMSYSERR_NOERROR
;
3877 static UINT
WINMM_GetDestinationLineInfo(WINMM_MMDevice
*mmdevice
,
3878 UINT mmdev_index
, MIXERLINEW
*info
, DWORD flags
)
3881 if(mmdevice
->in_caps
.szPname
[0] != '\0')
3884 if(info
->dwDestination
!= 0)
3885 return MIXERR_INVALLINE
;
3887 info
->dwSource
= 0xFFFFFFFF;
3888 info
->dwLineID
= 0xFFFF0000;
3889 info
->fdwLine
= MIXERLINE_LINEF_ACTIVE
;
3890 info
->cConnections
= 1;
3891 info
->cControls
= 2;
3893 lstrcpyW(info
->szShortName
, volumeW
);
3894 lstrcpyW(info
->szName
, mastervolumeW
);
3896 info
->Target
.dwDeviceID
= mmdev_index
;
3897 info
->Target
.wMid
= ~0;
3898 info
->Target
.wPid
= ~0;
3899 info
->Target
.vDriverVersion
= 0;
3902 info
->dwComponentType
= MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
;
3903 info
->cChannels
= mmdevice
->out_caps
.wChannels
;
3904 info
->Target
.dwType
= MIXERLINE_TARGETTYPE_UNDEFINED
;
3905 info
->Target
.szPname
[0] = '\0';
3907 info
->dwComponentType
= MIXERLINE_COMPONENTTYPE_DST_WAVEIN
;
3908 info
->cChannels
= mmdevice
->in_caps
.wChannels
;
3909 info
->Target
.dwType
= MIXERLINE_TARGETTYPE_WAVEIN
;
3910 memcpy(info
->Target
.szPname
, mmdevice
->in_caps
.szPname
,
3911 sizeof(info
->Target
.szPname
));
3914 return MMSYSERR_NOERROR
;
3917 static UINT
WINMM_GetComponentTypeLineInfo(WINMM_MMDevice
*mmdevice
,
3918 UINT mmdev_index
, MIXERLINEW
*info
, DWORD flags
)
3921 if(mmdevice
->in_caps
.szPname
[0] != '\0')
3924 if(info
->dwComponentType
== MIXERLINE_COMPONENTTYPE_DST_WAVEIN
){
3926 return MIXERR_INVALLINE
;
3927 info
->dwDestination
= 0;
3928 return WINMM_GetDestinationLineInfo(mmdevice
, mmdev_index
, info
, flags
);
3931 if(info
->dwComponentType
== MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
){
3933 return MIXERR_INVALLINE
;
3934 info
->dwDestination
= 0;
3935 return WINMM_GetDestinationLineInfo(mmdevice
, mmdev_index
, info
, flags
);
3938 if(info
->dwComponentType
== MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE
){
3940 return MIXERR_INVALLINE
;
3942 return WINMM_GetSourceLineInfo(mmdevice
, mmdev_index
, info
, flags
);
3945 if(info
->dwComponentType
== MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT
){
3947 return MIXERR_INVALLINE
;
3949 return WINMM_GetSourceLineInfo(mmdevice
, mmdev_index
, info
, flags
);
3952 TRACE("Returning INVALLINE on this component type: %u\n",
3953 info
->dwComponentType
);
3955 return MIXERR_INVALLINE
;
3958 static UINT
WINMM_GetLineIDLineInfo(WINMM_MMDevice
*mmdevice
,
3959 UINT mmdev_index
, MIXERLINEW
*info
, DWORD flags
)
3961 if(info
->dwLineID
== 0xFFFF0000){
3962 info
->dwDestination
= 0;
3963 return WINMM_GetDestinationLineInfo(mmdevice
, mmdev_index
, info
, flags
);
3966 if(info
->dwLineID
== 0){
3968 return WINMM_GetSourceLineInfo(mmdevice
, mmdev_index
, info
, flags
);
3971 TRACE("Returning INVALLINE on this dwLineID: %u\n", info
->dwLineID
);
3972 return MIXERR_INVALLINE
;
3975 /**************************************************************************
3976 * mixerGetLineInfoW [WINMM.@]
3978 UINT WINAPI
mixerGetLineInfoW(HMIXEROBJ hmix
, LPMIXERLINEW lpmliW
, DWORD fdwInfo
)
3981 WINMM_MMDevice
*mmdevice
;
3984 TRACE("(%p, %p, %x)\n", hmix
, lpmliW
, fdwInfo
);
3986 hr
= WINMM_InitMMDevices();
3988 return MMSYSERR_ERROR
;
3990 if(!lpmliW
|| lpmliW
->cbStruct
< sizeof(MIXERLINEW
))
3991 return MMSYSERR_INVALPARAM
;
3993 TRACE("dwDestination: %u\n", lpmliW
->dwDestination
);
3994 TRACE("dwSource: %u\n", lpmliW
->dwSource
);
3995 TRACE("dwLineID: %u\n", lpmliW
->dwLineID
);
3996 TRACE("fdwLine: 0x%x\n", lpmliW
->fdwLine
);
3997 TRACE("dwComponentType: 0x%x\n", lpmliW
->dwComponentType
);
3999 if(fdwInfo
& ~(MIXER_GETLINEINFOF_COMPONENTTYPE
|
4000 MIXER_GETLINEINFOF_DESTINATION
|
4001 MIXER_GETLINEINFOF_LINEID
|
4002 MIXER_GETLINEINFOF_SOURCE
|
4003 MIXER_GETLINEINFOF_TARGETTYPE
|
4004 MIXER_OBJECTF_HMIXER
|
4005 MIXER_OBJECTF_MIXER
)){
4006 WARN("Unknown GetLineInfo flag: %x\n", fdwInfo
);
4007 return MMSYSERR_INVALFLAG
;
4010 mmdevice
= WINMM_GetMixerMMDevice(hmix
, fdwInfo
, &mmdev_index
);
4012 return MMSYSERR_INVALHANDLE
;
4014 switch(fdwInfo
& MIXER_GETLINEINFOF_QUERYMASK
){
4015 case MIXER_GETLINEINFOF_DESTINATION
:
4016 return WINMM_GetDestinationLineInfo(mmdevice
, mmdev_index
, lpmliW
,
4018 case MIXER_GETLINEINFOF_SOURCE
:
4019 return WINMM_GetSourceLineInfo(mmdevice
, mmdev_index
, lpmliW
, fdwInfo
);
4020 case MIXER_GETLINEINFOF_COMPONENTTYPE
:
4021 return WINMM_GetComponentTypeLineInfo(mmdevice
, mmdev_index
, lpmliW
,
4023 case MIXER_GETLINEINFOF_LINEID
:
4024 return WINMM_GetLineIDLineInfo(mmdevice
, mmdev_index
, lpmliW
, fdwInfo
);
4025 case MIXER_GETLINEINFOF_TARGETTYPE
:
4026 FIXME("TARGETTYPE flag not implemented!\n");
4027 return MIXERR_INVALLINE
;
4030 TRACE("Returning INVALFLAG on these flags: %x\n", fdwInfo
& MIXER_GETLINEINFOF_QUERYMASK
);
4031 return MMSYSERR_INVALFLAG
;
4034 /**************************************************************************
4035 * mixerGetLineInfoA [WINMM.@]
4037 UINT WINAPI
mixerGetLineInfoA(HMIXEROBJ hmix
, LPMIXERLINEA lpmliA
,
4043 TRACE("(%p, %p, %x)\n", hmix
, lpmliA
, fdwInfo
);
4045 if (lpmliA
== NULL
|| lpmliA
->cbStruct
!= sizeof(*lpmliA
))
4046 return MMSYSERR_INVALPARAM
;
4048 mliW
.cbStruct
= sizeof(mliW
);
4049 switch (fdwInfo
& MIXER_GETLINEINFOF_QUERYMASK
) {
4050 case MIXER_GETLINEINFOF_COMPONENTTYPE
:
4051 mliW
.dwComponentType
= lpmliA
->dwComponentType
;
4053 case MIXER_GETLINEINFOF_DESTINATION
:
4054 mliW
.dwDestination
= lpmliA
->dwDestination
;
4056 case MIXER_GETLINEINFOF_LINEID
:
4057 mliW
.dwLineID
= lpmliA
->dwLineID
;
4059 case MIXER_GETLINEINFOF_SOURCE
:
4060 mliW
.dwDestination
= lpmliA
->dwDestination
;
4061 mliW
.dwSource
= lpmliA
->dwSource
;
4063 case MIXER_GETLINEINFOF_TARGETTYPE
:
4064 mliW
.Target
.dwType
= lpmliA
->Target
.dwType
;
4065 mliW
.Target
.wMid
= lpmliA
->Target
.wMid
;
4066 mliW
.Target
.wPid
= lpmliA
->Target
.wPid
;
4067 mliW
.Target
.vDriverVersion
= lpmliA
->Target
.vDriverVersion
;
4068 MultiByteToWideChar( CP_ACP
, 0, lpmliA
->Target
.szPname
, -1, mliW
.Target
.szPname
, sizeof(mliW
.Target
.szPname
)/sizeof(WCHAR
));
4071 WARN("Unsupported fdwControls=0x%08x\n", fdwInfo
);
4072 return MMSYSERR_INVALFLAG
;
4075 ret
= mixerGetLineInfoW(hmix
, &mliW
, fdwInfo
);
4077 if(ret
== MMSYSERR_NOERROR
)
4079 lpmliA
->dwDestination
= mliW
.dwDestination
;
4080 lpmliA
->dwSource
= mliW
.dwSource
;
4081 lpmliA
->dwLineID
= mliW
.dwLineID
;
4082 lpmliA
->fdwLine
= mliW
.fdwLine
;
4083 lpmliA
->dwUser
= mliW
.dwUser
;
4084 lpmliA
->dwComponentType
= mliW
.dwComponentType
;
4085 lpmliA
->cChannels
= mliW
.cChannels
;
4086 lpmliA
->cConnections
= mliW
.cConnections
;
4087 lpmliA
->cControls
= mliW
.cControls
;
4088 WideCharToMultiByte( CP_ACP
, 0, mliW
.szShortName
, -1, lpmliA
->szShortName
,
4089 sizeof(lpmliA
->szShortName
), NULL
, NULL
);
4090 WideCharToMultiByte( CP_ACP
, 0, mliW
.szName
, -1, lpmliA
->szName
,
4091 sizeof(lpmliA
->szName
), NULL
, NULL
);
4092 lpmliA
->Target
.dwType
= mliW
.Target
.dwType
;
4093 lpmliA
->Target
.dwDeviceID
= mliW
.Target
.dwDeviceID
;
4094 lpmliA
->Target
.wMid
= mliW
.Target
.wMid
;
4095 lpmliA
->Target
.wPid
= mliW
.Target
.wPid
;
4096 lpmliA
->Target
.vDriverVersion
= mliW
.Target
.vDriverVersion
;
4097 WideCharToMultiByte( CP_ACP
, 0, mliW
.Target
.szPname
, -1, lpmliA
->Target
.szPname
,
4098 sizeof(lpmliA
->Target
.szPname
), NULL
, NULL
);
4103 /**************************************************************************
4104 * mixerSetControlDetails [WINMM.@]
4106 UINT WINAPI
mixerSetControlDetails(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcd
,
4109 WINMM_ControlDetails details
;
4111 TRACE("(%p, %p, %x)\n", hmix
, lpmcd
, fdwDetails
);
4113 if(!WINMM_StartDevicesThread())
4114 return MMSYSERR_ERROR
;
4116 if((fdwDetails
& MIXER_SETCONTROLDETAILSF_QUERYMASK
) ==
4117 MIXER_SETCONTROLDETAILSF_CUSTOM
)
4118 return MMSYSERR_NOTSUPPORTED
;
4121 return MMSYSERR_INVALPARAM
;
4123 TRACE("dwControlID: %u\n", lpmcd
->dwControlID
);
4125 details
.hmix
= hmix
;
4126 details
.details
= lpmcd
;
4127 details
.flags
= fdwDetails
;
4129 return SendMessageW(g_devices_hwnd
, MXDM_SETCONTROLDETAILS
,
4130 (DWORD_PTR
)&details
, 0);
4133 /**************************************************************************
4134 * mixerMessage [WINMM.@]
4136 DWORD WINAPI
mixerMessage(HMIXER hmix
, UINT uMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
4138 TRACE("(%p, %d, %lx, %lx)\n", hmix
, uMsg
, dwParam1
, dwParam2
);
4140 return MMSYSERR_NOTSUPPORTED
;