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 static CRITICAL_SECTION g_devthread_lock
;
143 static CRITICAL_SECTION_DEBUG g_devthread_lock_debug
=
145 0, 0, &g_devthread_lock
,
146 { &g_devthread_lock_debug
.ProcessLocksList
, &g_devthread_lock_debug
.ProcessLocksList
},
147 0, 0, { (DWORD_PTR
)(__FILE__
": g_devthread_lock") }
149 static CRITICAL_SECTION g_devthread_lock
= { &g_devthread_lock_debug
, -1, 0, 0, 0, 0 };
150 static HANDLE g_devices_thread
;
151 static HWND g_devices_hwnd
;
153 static UINT g_devhandle_count
;
154 static HANDLE
*g_device_handles
;
155 static WINMM_Device
**g_handle_devices
;
157 typedef struct _WINMM_OpenInfo
{
160 WAVEFORMATEX
*format
;
166 typedef struct _WINMM_ControlDetails
{
168 MIXERCONTROLDETAILS
*details
;
170 } WINMM_ControlDetails
;
172 typedef struct _WINMM_QueryInterfaceInfo
{
177 } WINMM_QueryInterfaceInfo
;
179 static LRESULT
WOD_Open(WINMM_OpenInfo
*info
);
180 static LRESULT
WOD_Close(HWAVEOUT hwave
);
181 static LRESULT
WID_Open(WINMM_OpenInfo
*info
);
182 static LRESULT
WID_Close(HWAVEIN hwave
);
184 void WINMM_DeleteWaveform(void)
188 for(i
= 0; i
< g_outmmdevices_count
; ++i
){
189 WINMM_MMDevice
*mmdevice
= &g_out_mmdevices
[i
];
190 for(j
= 0; j
< MAX_DEVICES
&& mmdevice
->devices
[j
]; ++j
){
191 WINMM_Device
*device
= mmdevice
->devices
[j
];
193 SendMessageW(g_devices_hwnd
, WODM_CLOSE
, (WPARAM
)device
->handle
, 0);
197 for(i
= 0; i
< g_inmmdevices_count
; ++i
){
198 WINMM_MMDevice
*mmdevice
= &g_in_mmdevices
[i
];
199 for(j
= 0; j
< MAX_DEVICES
&& mmdevice
->devices
[j
]; ++j
){
200 WINMM_Device
*device
= mmdevice
->devices
[j
];
202 SendMessageW(g_devices_hwnd
, WIDM_CLOSE
, (WPARAM
)device
->handle
, 0);
206 /* FIXME: Free g_(in,out)_mmdevices? */
207 DeleteCriticalSection(&g_devthread_lock
);
210 static inline HWAVE
WINMM_MakeHWAVE(UINT mmdevice
, BOOL is_out
, UINT device
)
212 return ULongToHandle((1 << 15) | ((!!is_out
) << 14) |
213 (mmdevice
<< 8) | device
);
216 static inline void WINMM_DecomposeHWAVE(HWAVE hwave
, UINT
*mmdevice_index
,
217 BOOL
*is_out
, UINT
*device_index
, UINT
*junk
)
219 ULONG32 l
= HandleToULong(hwave
);
220 *device_index
= l
& 0xFF;
221 *mmdevice_index
= (l
>> 8) & 0x3F;
222 *is_out
= (l
>> 14) & 0x1;
226 static void WINMM_InitDevice(WINMM_Device
*device
,
227 WINMM_MMDevice
*parent
, HWAVE hwave
)
229 InitializeCriticalSection(&device
->lock
);
230 device
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": WINMM_Device.lock");
232 device
->handle
= hwave
;
233 device
->parent
= parent
;
236 /* finds the first unused Device, marks it as "open", and returns
237 * a pointer to the device
239 * IMPORTANT: it is the caller's responsibility to release the device's lock
242 static WINMM_Device
*WINMM_FindUnusedDevice(BOOL is_out
, UINT mmdevice_index
)
244 WINMM_MMDevice
*mmdevice
;
248 mmdevice
= &g_out_mmdevices
[mmdevice_index
];
250 mmdevice
= &g_in_mmdevices
[mmdevice_index
];
252 EnterCriticalSection(&mmdevice
->lock
);
253 for(i
= 0; i
< MAX_DEVICES
; ++i
){
254 WINMM_Device
*device
= mmdevice
->devices
[i
];
257 device
= mmdevice
->devices
[i
] = HeapAlloc(GetProcessHeap(),
258 HEAP_ZERO_MEMORY
, sizeof(WINMM_Device
));
260 LeaveCriticalSection(&mmdevice
->lock
);
264 WINMM_InitDevice(device
, mmdevice
,
265 WINMM_MakeHWAVE(mmdevice_index
, is_out
, i
));
266 EnterCriticalSection(&device
->lock
);
268 EnterCriticalSection(&device
->lock
);
271 LeaveCriticalSection(&mmdevice
->lock
);
273 TRACE("Found free device: mmdevice: %u, device id: %u\n",
278 LeaveCriticalSection(&device
->lock
);
281 LeaveCriticalSection(&mmdevice
->lock
);
283 TRACE("All devices in use: mmdevice: %u\n", mmdevice_index
);
288 static inline BOOL
WINMM_ValidateAndLock(WINMM_Device
*device
)
293 EnterCriticalSection(&device
->lock
);
296 LeaveCriticalSection(&device
->lock
);
303 static WINMM_Device
*WINMM_GetDeviceFromHWAVE(HWAVE hwave
)
305 WINMM_MMDevice
*mmdevice
;
306 WINMM_Device
*device
;
307 UINT mmdevice_index
, device_index
, junk
;
310 WINMM_DecomposeHWAVE(hwave
, &mmdevice_index
, &is_out
, &device_index
, &junk
);
315 if(mmdevice_index
>= (is_out
? g_outmmdevices_count
: g_inmmdevices_count
))
319 mmdevice
= &g_out_mmdevices
[mmdevice_index
];
321 mmdevice
= &g_in_mmdevices
[mmdevice_index
];
323 EnterCriticalSection(&mmdevice
->lock
);
325 device
= mmdevice
->devices
[device_index
];
327 LeaveCriticalSection(&mmdevice
->lock
);
332 /* Note: NotifyClient should never be called while holding the device lock
333 * since the client may call wave* functions from within the callback. */
334 static inline void WINMM_NotifyClient(WINMM_CBInfo
*info
, WORD msg
, DWORD_PTR param1
,
337 DriverCallback(info
->callback
, info
->flags
, (HDRVR
)info
->hwave
,
338 msg
, info
->user
, param1
, param2
);
341 static HRESULT
WINMM_GetFriendlyName(IMMDevice
*device
, WCHAR
*out
,
348 hr
= IMMDevice_OpenPropertyStore(device
, STGM_READ
, &ps
);
352 PropVariantInit(&var
);
354 hr
= IPropertyStore_GetValue(ps
,
355 (PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &var
);
357 IPropertyStore_Release(ps
);
361 lstrcpynW(out
, var
.u
.pwszVal
, outlen
);
363 PropVariantClear(&var
);
365 IPropertyStore_Release(ps
);
370 static HRESULT
WINMM_TestFormat(IAudioClient
*client
, DWORD rate
, DWORD depth
,
373 WAVEFORMATEX fmt
, *junk
;
376 fmt
.wFormatTag
= WAVE_FORMAT_PCM
;
377 fmt
.nChannels
= channels
;
378 fmt
.nSamplesPerSec
= rate
;
379 fmt
.wBitsPerSample
= depth
;
380 fmt
.nBlockAlign
= (channels
* depth
) / 8;
381 fmt
.nAvgBytesPerSec
= rate
* fmt
.nBlockAlign
;
384 hr
= IAudioClient_IsFormatSupported(client
, AUDCLNT_SHAREMODE_SHARED
,
392 static struct _TestFormat
{
397 } formats_to_test
[] = {
398 { WAVE_FORMAT_1M08
, 11025, 8, 1 },
399 { WAVE_FORMAT_1M16
, 11025, 16, 1 },
400 { WAVE_FORMAT_1S08
, 11025, 8, 2 },
401 { WAVE_FORMAT_1S16
, 11025, 16, 2 },
402 { WAVE_FORMAT_2M08
, 22050, 8, 1 },
403 { WAVE_FORMAT_2M16
, 22050, 16, 1 },
404 { WAVE_FORMAT_2S08
, 22050, 8, 2 },
405 { WAVE_FORMAT_2S16
, 22050, 16, 2 },
406 { WAVE_FORMAT_4M08
, 44100, 8, 1 },
407 { WAVE_FORMAT_4M16
, 44100, 16, 1 },
408 { WAVE_FORMAT_4S08
, 44100, 8, 2 },
409 { WAVE_FORMAT_4S16
, 44100, 16, 2 },
410 { WAVE_FORMAT_48M08
, 48000, 8, 1 },
411 { WAVE_FORMAT_48M16
, 48000, 16, 1 },
412 { WAVE_FORMAT_48S08
, 48000, 8, 2 },
413 { WAVE_FORMAT_48S16
, 48000, 16, 2 },
414 { WAVE_FORMAT_96M08
, 96000, 8, 1 },
415 { WAVE_FORMAT_96M16
, 96000, 16, 1 },
416 { WAVE_FORMAT_96S08
, 96000, 8, 2 },
417 { WAVE_FORMAT_96S16
, 96000, 16, 2 },
421 static DWORD
WINMM_GetSupportedFormats(IMMDevice
*device
)
425 struct _TestFormat
*fmt
;
426 IAudioClient
*client
;
428 hr
= IMMDevice_Activate(device
, &IID_IAudioClient
,
429 CLSCTX_INPROC_SERVER
, NULL
, (void**)&client
);
433 for(fmt
= formats_to_test
; fmt
->flag
; ++fmt
){
434 hr
= WINMM_TestFormat(client
, fmt
->rate
, fmt
->depth
, fmt
->channels
);
439 IAudioClient_Release(client
);
444 static HRESULT
WINMM_InitMMDevice(EDataFlow flow
, IMMDevice
*device
,
445 WINMM_MMDevice
*dev
, UINT index
)
450 dev
->out_caps
.wMid
= 0xFF;
451 dev
->out_caps
.wPid
= 0xFF;
452 dev
->out_caps
.vDriverVersion
= 0x00010001;
453 dev
->out_caps
.dwFormats
= WINMM_GetSupportedFormats(device
);
454 dev
->out_caps
.wReserved1
= 0;
455 dev
->out_caps
.dwSupport
= WAVECAPS_LRVOLUME
| WAVECAPS_VOLUME
|
456 WAVECAPS_SAMPLEACCURATE
;
457 dev
->out_caps
.wChannels
= 2;
458 dev
->out_caps
.szPname
[0] = '\0';
460 hr
= WINMM_GetFriendlyName(device
, dev
->out_caps
.szPname
,
461 sizeof(dev
->out_caps
.szPname
) /
462 sizeof(*dev
->out_caps
.szPname
));
466 dev
->in_caps
.wMid
= 0xFF;
467 dev
->in_caps
.wPid
= 0xFF;
468 dev
->in_caps
.vDriverVersion
= 0x00010001;
469 dev
->in_caps
.dwFormats
= WINMM_GetSupportedFormats(device
);
470 dev
->in_caps
.wReserved1
= 0;
471 dev
->in_caps
.wChannels
= 2;
472 dev
->in_caps
.szPname
[0] = '\0';
474 hr
= WINMM_GetFriendlyName(device
, dev
->in_caps
.szPname
,
475 sizeof(dev
->in_caps
.szPname
) /
476 sizeof(*dev
->in_caps
.szPname
));
481 hr
= IMMDevice_GetId(device
, &dev
->dev_id
);
485 CoCreateGuid(&dev
->session
);
487 InitializeCriticalSection(&dev
->lock
);
488 dev
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": WINMM_Device.lock");
493 static HRESULT
WINMM_EnumDevices(WINMM_MMDevice
**devices
, UINT
*devcount
,
494 EDataFlow flow
, IMMDeviceEnumerator
*devenum
)
496 IMMDeviceCollection
*devcoll
;
499 hr
= IMMDeviceEnumerator_EnumAudioEndpoints(devenum
, flow
,
500 DEVICE_STATE_ACTIVE
, &devcoll
);
504 hr
= IMMDeviceCollection_GetCount(devcoll
, devcount
);
506 IMMDeviceCollection_Release(devcoll
);
512 IMMDevice
*def_dev
= NULL
;
514 *devices
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
515 sizeof(WINMM_MMDevice
) * (*devcount
));
517 IMMDeviceCollection_Release(devcoll
);
518 return E_OUTOFMEMORY
;
523 /* make sure that device 0 is the default device */
524 hr
= IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum
,
525 flow
, eConsole
, &def_dev
);
527 WINMM_InitMMDevice(flow
, def_dev
, &(*devices
)[0], 0);
531 for(n
= 0; n
< *devcount
; ++n
){
534 hr
= IMMDeviceCollection_Item(devcoll
, n
, &device
);
536 if(device
!= def_dev
){
537 WINMM_InitMMDevice(flow
, device
, &(*devices
)[count
], count
);
541 IMMDevice_Release(device
);
546 IMMDevice_Release(def_dev
);
551 IMMDeviceCollection_Release(devcoll
);
556 static HRESULT
WINMM_InitMMDevices(void)
559 IMMDeviceEnumerator
*devenum
= NULL
;
561 if(g_outmmdevices_count
|| g_inmmdevices_count
)
564 init_hr
= CoInitialize(NULL
);
566 hr
= CoCreateInstance(&CLSID_MMDeviceEnumerator
, NULL
,
567 CLSCTX_INPROC_SERVER
, &IID_IMMDeviceEnumerator
, (void**)&devenum
);
571 hr
= WINMM_EnumDevices(&g_out_mmdevices
, &g_outmmdevices_count
, eRender
, devenum
);
573 g_outmmdevices_count
= 0;
574 g_inmmdevices_count
= 0;
578 hr
= WINMM_EnumDevices(&g_in_mmdevices
, &g_inmmdevices_count
, eCapture
, devenum
);
580 g_inmmdevices_count
= 0;
586 IMMDeviceEnumerator_Release(devenum
);
587 if(SUCCEEDED(init_hr
))
593 static inline BOOL
WINMM_IsMapper(UINT device
)
595 return (device
== WAVE_MAPPER
|| device
== (UINT16
)WAVE_MAPPER
);
598 static MMRESULT
WINMM_TryDeviceMapping(WINMM_OpenInfo
*info
, WORD channels
,
599 DWORD freq
, DWORD bits_per_samp
, BOOL is_out
)
601 WINMM_Device
*device
;
606 TRACE("format: %u, channels: %u, sample rate: %u, bit depth: %u\n",
607 WAVE_FORMAT_PCM
, channels
, freq
, bits_per_samp
);
609 target
.wFormatTag
= WAVE_FORMAT_PCM
;
610 target
.nChannels
= channels
;
611 target
.nSamplesPerSec
= freq
;
612 target
.wBitsPerSample
= bits_per_samp
;
613 target
.nBlockAlign
= (target
.nChannels
* target
.wBitsPerSample
) / 8;
614 target
.nAvgBytesPerSec
= target
.nSamplesPerSec
* target
.nBlockAlign
;
618 mr
= acmStreamOpen(NULL
, NULL
, info
->format
, &target
, NULL
, 0,
619 0, ACM_STREAMOPENF_QUERY
);
621 mr
= acmStreamOpen(NULL
, NULL
, &target
, info
->format
, NULL
, 0,
622 0, ACM_STREAMOPENF_QUERY
);
623 if(mr
!= MMSYSERR_NOERROR
)
626 /* ACM can convert from src->dst, so try to find a device
627 * that supports dst */
629 if(WINMM_IsMapper(info
->req_device
)){
630 for(i
= 0; i
< g_outmmdevices_count
; ++i
){
631 WINMM_OpenInfo l_info
= *info
;
632 l_info
.req_device
= i
;
633 l_info
.format
= &target
;
634 mr
= WOD_Open(&l_info
);
635 if(mr
== MMSYSERR_NOERROR
){
636 info
->handle
= l_info
.handle
;
641 WINMM_OpenInfo l_info
= *info
;
642 l_info
.flags
&= ~WAVE_MAPPED
;
643 l_info
.format
= &target
;
644 mr
= WOD_Open(&l_info
);
645 if(mr
== MMSYSERR_NOERROR
)
646 info
->handle
= l_info
.handle
;
649 if(WINMM_IsMapper(info
->req_device
)){
650 for(i
= 0; i
< g_inmmdevices_count
; ++i
){
651 WINMM_OpenInfo l_info
= *info
;
652 l_info
.req_device
= i
;
653 l_info
.format
= &target
;
654 mr
= WID_Open(&l_info
);
655 if(mr
== MMSYSERR_NOERROR
){
656 info
->handle
= l_info
.handle
;
661 WINMM_OpenInfo l_info
= *info
;
662 l_info
.flags
&= ~WAVE_MAPPED
;
663 l_info
.format
= &target
;
664 mr
= WID_Open(&l_info
);
665 if(mr
== MMSYSERR_NOERROR
)
666 info
->handle
= l_info
.handle
;
669 if(mr
!= MMSYSERR_NOERROR
)
670 return WAVERR_BADFORMAT
;
672 device
= WINMM_GetDeviceFromHWAVE(info
->handle
);
674 return MMSYSERR_INVALHANDLE
;
676 /* set up the ACM stream */
678 mr
= acmStreamOpen(&device
->acm_handle
, NULL
, info
->format
, &target
,
681 mr
= acmStreamOpen(&device
->acm_handle
, NULL
, &target
, info
->format
,
683 if(mr
!= MMSYSERR_NOERROR
){
685 WOD_Close((HWAVEOUT
)info
->handle
);
687 WID_Close((HWAVEIN
)info
->handle
);
692 return MMSYSERR_NOERROR
;
695 static MMRESULT
WINMM_MapDevice(WINMM_OpenInfo
*info
, BOOL is_out
)
699 WAVEFORMATEXTENSIBLE
*fmtex
= (WAVEFORMATEXTENSIBLE
*)info
->format
;
701 TRACE("(%p, %d)\n", info
, is_out
);
703 /* try to find a direct match */
705 WINMM_OpenInfo l_info
= *info
;
706 if(WINMM_IsMapper(info
->req_device
)){
707 for(i
= 0; i
< g_outmmdevices_count
; ++i
){
708 l_info
.req_device
= i
;
709 mr
= WOD_Open(&l_info
);
710 if(mr
== MMSYSERR_NOERROR
){
711 info
->handle
= l_info
.handle
;
716 l_info
.flags
&= ~WAVE_MAPPED
;
717 mr
= WOD_Open(&l_info
);
718 if(mr
== MMSYSERR_NOERROR
){
719 info
->handle
= l_info
.handle
;
724 WINMM_OpenInfo l_info
= *info
;
725 if(WINMM_IsMapper(info
->req_device
)){
726 for(i
= 0; i
< g_inmmdevices_count
; ++i
){
727 l_info
.req_device
= i
;
728 mr
= WID_Open(&l_info
);
729 if(mr
== MMSYSERR_NOERROR
){
730 info
->handle
= l_info
.handle
;
735 l_info
.flags
&= ~WAVE_MAPPED
;
736 mr
= WID_Open(&l_info
);
737 if(mr
== MMSYSERR_NOERROR
){
738 info
->handle
= l_info
.handle
;
744 /* no direct match, so set up the ACM stream */
745 if(info
->format
->wFormatTag
!= WAVE_FORMAT_PCM
&&
746 !(info
->format
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
747 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
))){
748 /* convert to PCM format if it's not already */
749 mr
= WINMM_TryDeviceMapping(info
, info
->format
->nChannels
,
750 info
->format
->nSamplesPerSec
, 16, is_out
);
751 if(mr
== MMSYSERR_NOERROR
)
754 mr
= WINMM_TryDeviceMapping(info
, info
->format
->nChannels
,
755 info
->format
->nSamplesPerSec
, 8, is_out
);
756 if(mr
== MMSYSERR_NOERROR
)
761 /* first try just changing bit depth and channels */
762 channels
= info
->format
->nChannels
;
763 mr
= WINMM_TryDeviceMapping(info
, channels
,
764 info
->format
->nSamplesPerSec
, 16, is_out
);
765 if(mr
== MMSYSERR_NOERROR
)
767 mr
= WINMM_TryDeviceMapping(info
, channels
,
768 info
->format
->nSamplesPerSec
, 8, is_out
);
769 if(mr
== MMSYSERR_NOERROR
)
772 channels
= (channels
== 2) ? 1 : 2;
773 mr
= WINMM_TryDeviceMapping(info
, channels
,
774 info
->format
->nSamplesPerSec
, 16, is_out
);
775 if(mr
== MMSYSERR_NOERROR
)
777 mr
= WINMM_TryDeviceMapping(info
, channels
,
778 info
->format
->nSamplesPerSec
, 8, is_out
);
779 if(mr
== MMSYSERR_NOERROR
)
782 /* that didn't work, so now try different sample rates */
783 channels
= info
->format
->nChannels
;
784 mr
= WINMM_TryDeviceMapping(info
, channels
, 96000, 16, is_out
);
785 if(mr
== MMSYSERR_NOERROR
)
787 mr
= WINMM_TryDeviceMapping(info
, channels
, 48000, 16, is_out
);
788 if(mr
== MMSYSERR_NOERROR
)
790 mr
= WINMM_TryDeviceMapping(info
, channels
, 44100, 16, is_out
);
791 if(mr
== MMSYSERR_NOERROR
)
793 mr
= WINMM_TryDeviceMapping(info
, channels
, 22050, 16, is_out
);
794 if(mr
== MMSYSERR_NOERROR
)
796 mr
= WINMM_TryDeviceMapping(info
, channels
, 11025, 16, is_out
);
797 if(mr
== MMSYSERR_NOERROR
)
800 channels
= (channels
== 2) ? 1 : 2;
801 mr
= WINMM_TryDeviceMapping(info
, channels
, 96000, 16, is_out
);
802 if(mr
== MMSYSERR_NOERROR
)
804 mr
= WINMM_TryDeviceMapping(info
, channels
, 48000, 16, is_out
);
805 if(mr
== MMSYSERR_NOERROR
)
807 mr
= WINMM_TryDeviceMapping(info
, channels
, 44100, 16, is_out
);
808 if(mr
== MMSYSERR_NOERROR
)
810 mr
= WINMM_TryDeviceMapping(info
, channels
, 22050, 16, is_out
);
811 if(mr
== MMSYSERR_NOERROR
)
813 mr
= WINMM_TryDeviceMapping(info
, channels
, 11025, 16, is_out
);
814 if(mr
== MMSYSERR_NOERROR
)
817 channels
= info
->format
->nChannels
;
818 mr
= WINMM_TryDeviceMapping(info
, channels
, 96000, 8, is_out
);
819 if(mr
== MMSYSERR_NOERROR
)
821 mr
= WINMM_TryDeviceMapping(info
, channels
, 48000, 8, is_out
);
822 if(mr
== MMSYSERR_NOERROR
)
824 mr
= WINMM_TryDeviceMapping(info
, channels
, 44100, 8, is_out
);
825 if(mr
== MMSYSERR_NOERROR
)
827 mr
= WINMM_TryDeviceMapping(info
, channels
, 22050, 8, is_out
);
828 if(mr
== MMSYSERR_NOERROR
)
830 mr
= WINMM_TryDeviceMapping(info
, channels
, 11025, 8, is_out
);
831 if(mr
== MMSYSERR_NOERROR
)
834 channels
= (channels
== 2) ? 1 : 2;
835 mr
= WINMM_TryDeviceMapping(info
, channels
, 96000, 8, is_out
);
836 if(mr
== MMSYSERR_NOERROR
)
838 mr
= WINMM_TryDeviceMapping(info
, channels
, 48000, 8, is_out
);
839 if(mr
== MMSYSERR_NOERROR
)
841 mr
= WINMM_TryDeviceMapping(info
, channels
, 44100, 8, is_out
);
842 if(mr
== MMSYSERR_NOERROR
)
844 mr
= WINMM_TryDeviceMapping(info
, channels
, 22050, 8, is_out
);
845 if(mr
== MMSYSERR_NOERROR
)
847 mr
= WINMM_TryDeviceMapping(info
, channels
, 11025, 8, is_out
);
848 if(mr
== MMSYSERR_NOERROR
)
852 WARN("Unable to find compatible device!\n");
853 return WAVERR_BADFORMAT
;
856 static LRESULT
WINMM_OpenDevice(WINMM_Device
*device
, WINMM_MMDevice
*mmdevice
,
857 WINMM_OpenInfo
*info
)
859 WAVEFORMATEX
*closer_fmt
= NULL
, fmt
, *passed_fmt
;
860 LRESULT ret
= MMSYSERR_ERROR
;
863 hr
= IMMDeviceEnumerator_GetDevice(g_devenum
, mmdevice
->dev_id
,
866 WARN("Device %s (%s) unavailable: %08x\n",
867 wine_dbgstr_w(mmdevice
->dev_id
),
868 wine_dbgstr_w(mmdevice
->out_caps
.szPname
), hr
);
872 hr
= IMMDevice_Activate(device
->device
, &IID_IAudioClient
,
873 CLSCTX_INPROC_SERVER
, NULL
, (void**)&device
->client
);
875 WARN("Activate failed: %08x\n", hr
);
879 if(info
->format
->wFormatTag
== WAVE_FORMAT_PCM
){
880 /* we aren't guaranteed that the struct in lpFormat is a full
881 * WAVEFORMATEX struct, which IAC::IsFormatSupported requires */
883 memcpy(passed_fmt
, info
->format
, sizeof(PCMWAVEFORMAT
));
884 passed_fmt
->cbSize
= 0;
885 if(fmt
.wBitsPerSample
% 8 != 0){
886 WARN("Fixing bad wBitsPerSample (%u)\n", fmt
.wBitsPerSample
);
887 fmt
.wBitsPerSample
= (fmt
.wBitsPerSample
+ 7) & ~7;
889 /* winmm ignores broken blockalign and avgbytes */
890 if(fmt
.nBlockAlign
!= fmt
.nChannels
* fmt
.wBitsPerSample
/8){
891 WARN("Fixing bad nBlockAlign (%u)\n", fmt
.nBlockAlign
);
892 fmt
.nBlockAlign
= fmt
.nChannels
* fmt
.wBitsPerSample
/8;
894 if (fmt
.nAvgBytesPerSec
!= fmt
.nSamplesPerSec
* fmt
.nBlockAlign
) {
895 WARN("Fixing bad nAvgBytesPerSec (%u)\n", fmt
.nAvgBytesPerSec
);
896 fmt
.nAvgBytesPerSec
= fmt
.nSamplesPerSec
* fmt
.nBlockAlign
;
899 passed_fmt
= info
->format
;
901 hr
= IAudioClient_IsFormatSupported(device
->client
,
902 AUDCLNT_SHAREMODE_SHARED
, passed_fmt
, &closer_fmt
);
904 CoTaskMemFree(closer_fmt
);
905 if(FAILED(hr
) && hr
!= AUDCLNT_E_UNSUPPORTED_FORMAT
){
906 WARN("IsFormatSupported failed: %08x\n", hr
);
909 if(hr
== S_FALSE
|| hr
== AUDCLNT_E_UNSUPPORTED_FORMAT
){
910 ret
= WAVERR_BADFORMAT
;
913 if(info
->flags
& WAVE_FORMAT_QUERY
){
914 ret
= MMSYSERR_NOERROR
;
918 /* buffer size = 10 * 100000 (100 ns) = 0.1 seconds */
919 hr
= IAudioClient_Initialize(device
->client
, AUDCLNT_SHAREMODE_SHARED
,
920 AUDCLNT_STREAMFLAGS_EVENTCALLBACK
| AUDCLNT_STREAMFLAGS_NOPERSIST
,
921 10 * 100000, 50000, passed_fmt
, &device
->parent
->session
);
923 WARN("Initialize failed: %08x\n", hr
);
927 hr
= IAudioClient_GetService(device
->client
, &IID_IAudioClock
,
928 (void**)&device
->clock
);
930 WARN("GetService failed: %08x\n", hr
);
935 device
->event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
937 WARN("CreateEvent failed: %08x\n", hr
);
941 /* As the devices thread is waiting on g_device_handles, it can
942 * only be modified from within this same thread. */
943 if(g_device_handles
){
944 g_device_handles
= HeapReAlloc(GetProcessHeap(), 0, g_device_handles
,
945 sizeof(HANDLE
) * (g_devhandle_count
+ 1));
946 g_handle_devices
= HeapReAlloc(GetProcessHeap(), 0, g_handle_devices
,
947 sizeof(WINMM_Device
*) * (g_devhandle_count
+ 1));
949 g_device_handles
= HeapAlloc(GetProcessHeap(), 0, sizeof(HANDLE
));
950 g_handle_devices
= HeapAlloc(GetProcessHeap(), 0,
951 sizeof(WINMM_Device
*));
953 g_device_handles
[g_devhandle_count
] = device
->event
;
954 g_handle_devices
[g_devhandle_count
] = device
;
958 hr
= IAudioClient_SetEventHandle(device
->client
, device
->event
);
960 WARN("SetEventHandle failed: %08x\n", hr
);
964 device
->bytes_per_frame
= passed_fmt
->nBlockAlign
;
965 device
->samples_per_sec
= passed_fmt
->nSamplesPerSec
;
967 device
->played_frames
= 0;
968 device
->last_clock_pos
= 0;
969 device
->ofs_bytes
= 0;
970 device
->loop_counter
= 0;
971 device
->stopped
= TRUE
;
972 device
->first
= device
->last
= device
->playing
= device
->loop_start
= NULL
;
974 device
->cb_info
.flags
= HIWORD(info
->flags
& CALLBACK_TYPEMASK
);
975 device
->cb_info
.callback
= info
->callback
;
976 device
->cb_info
.user
= info
->cb_user
;
977 device
->cb_info
.hwave
= device
->handle
;
979 info
->handle
= device
->handle
;
981 return MMSYSERR_NOERROR
;
985 IAudioClient_Release(device
->client
);
986 device
->client
= NULL
;
989 IMMDevice_Release(device
->device
);
990 device
->device
= NULL
;
996 static LRESULT
WOD_Open(WINMM_OpenInfo
*info
)
998 WINMM_MMDevice
*mmdevice
;
999 WINMM_Device
*device
= NULL
;
1000 LRESULT ret
= MMSYSERR_ERROR
;
1003 TRACE("(%u, %p, %08x)\n", info
->req_device
, info
, info
->flags
);
1005 if(WINMM_IsMapper(info
->req_device
) || (info
->flags
& WAVE_MAPPED
))
1006 return WINMM_MapDevice(info
, TRUE
);
1008 if(info
->req_device
>= g_outmmdevices_count
)
1009 return MMSYSERR_BADDEVICEID
;
1011 mmdevice
= &g_out_mmdevices
[info
->req_device
];
1013 if(!mmdevice
->out_caps
.szPname
[0])
1014 return MMSYSERR_NOTENABLED
;
1016 device
= WINMM_FindUnusedDevice(TRUE
, info
->req_device
);
1018 return MMSYSERR_ALLOCATED
;
1020 ret
= WINMM_OpenDevice(device
, mmdevice
, info
);
1021 if((info
->flags
& WAVE_FORMAT_QUERY
) || ret
!= MMSYSERR_NOERROR
)
1023 ret
= MMSYSERR_ERROR
;
1025 hr
= IAudioClient_GetService(device
->client
, &IID_IAudioRenderClient
,
1026 (void**)&device
->render
);
1028 WARN("GetService(RenderClient) failed: %08x\n", hr
);
1032 hr
= IAudioClient_GetService(device
->client
, &IID_IAudioStreamVolume
,
1033 (void**)&device
->volume
);
1035 WARN("GetService(StreamVolume) failed: %08x\n", hr
);
1039 LeaveCriticalSection(&device
->lock
);
1041 return MMSYSERR_NOERROR
;
1045 IMMDevice_Release(device
->device
);
1046 device
->device
= NULL
;
1049 IAudioClient_Release(device
->client
);
1050 device
->client
= NULL
;
1053 IAudioRenderClient_Release(device
->render
);
1054 device
->render
= NULL
;
1057 IAudioStreamVolume_Release(device
->volume
);
1058 device
->volume
= NULL
;
1061 IAudioClock_Release(device
->clock
);
1062 device
->clock
= NULL
;
1064 device
->open
= FALSE
;
1065 LeaveCriticalSection(&device
->lock
);
1069 static LRESULT
WID_Open(WINMM_OpenInfo
*info
)
1071 WINMM_MMDevice
*mmdevice
;
1072 WINMM_Device
*device
= NULL
;
1073 LRESULT ret
= MMSYSERR_ERROR
;
1076 TRACE("(%u, %p, %08x)\n", info
->req_device
, info
, info
->flags
);
1078 if(WINMM_IsMapper(info
->req_device
) || info
->flags
& WAVE_MAPPED
)
1079 return WINMM_MapDevice(info
, FALSE
);
1081 if(info
->req_device
>= g_inmmdevices_count
)
1082 return MMSYSERR_BADDEVICEID
;
1084 mmdevice
= &g_in_mmdevices
[info
->req_device
];
1086 if(!mmdevice
->in_caps
.szPname
[0])
1087 return MMSYSERR_NOTENABLED
;
1089 device
= WINMM_FindUnusedDevice(FALSE
, info
->req_device
);
1091 return MMSYSERR_ALLOCATED
;
1093 ret
= WINMM_OpenDevice(device
, mmdevice
, info
);
1094 if((info
->flags
& WAVE_FORMAT_QUERY
) || ret
!= MMSYSERR_NOERROR
)
1096 ret
= MMSYSERR_ERROR
;
1098 hr
= IAudioClient_GetService(device
->client
, &IID_IAudioCaptureClient
,
1099 (void**)&device
->capture
);
1101 WARN("GetService failed: %08x\n", hr
);
1105 LeaveCriticalSection(&device
->lock
);
1107 return MMSYSERR_NOERROR
;
1111 IMMDevice_Release(device
->device
);
1112 device
->device
= NULL
;
1115 IAudioClient_Release(device
->client
);
1116 device
->client
= NULL
;
1118 if(device
->capture
){
1119 IAudioCaptureClient_Release(device
->capture
);
1120 device
->capture
= NULL
;
1123 IAudioClock_Release(device
->clock
);
1124 device
->clock
= NULL
;
1126 device
->open
= FALSE
;
1127 LeaveCriticalSection(&device
->lock
);
1131 static HRESULT
WINMM_CloseDevice(WINMM_Device
*device
)
1133 device
->open
= FALSE
;
1135 if(!device
->stopped
){
1136 IAudioClient_Stop(device
->client
);
1137 device
->stopped
= TRUE
;
1140 if(device
->acm_handle
){
1141 acmStreamClose(device
->acm_handle
, 0);
1142 device
->acm_handle
= NULL
;
1145 IMMDevice_Release(device
->device
);
1146 device
->device
= NULL
;
1148 IAudioClient_Release(device
->client
);
1149 device
->client
= NULL
;
1151 IAudioClock_Release(device
->clock
);
1152 device
->clock
= NULL
;
1157 static LRESULT
WOD_Close(HWAVEOUT hwave
)
1159 WINMM_Device
*device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hwave
);
1161 TRACE("(%p)\n", hwave
);
1163 if(!WINMM_ValidateAndLock(device
))
1164 return MMSYSERR_INVALHANDLE
;
1166 WINMM_CloseDevice(device
);
1168 IAudioRenderClient_Release(device
->render
);
1169 device
->render
= NULL
;
1171 IAudioStreamVolume_Release(device
->volume
);
1172 device
->volume
= NULL
;
1174 LeaveCriticalSection(&device
->lock
);
1176 return MMSYSERR_NOERROR
;
1179 static LRESULT
WID_Close(HWAVEIN hwave
)
1181 WINMM_Device
*device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hwave
);
1183 TRACE("(%p)\n", hwave
);
1185 if(!WINMM_ValidateAndLock(device
))
1186 return MMSYSERR_INVALHANDLE
;
1188 WINMM_CloseDevice(device
);
1190 IAudioCaptureClient_Release(device
->capture
);
1191 device
->capture
= NULL
;
1193 LeaveCriticalSection(&device
->lock
);
1195 return MMSYSERR_NOERROR
;
1198 static LRESULT
WINMM_PrepareHeader(HWAVE hwave
, WAVEHDR
*header
)
1200 WINMM_Device
*device
= WINMM_GetDeviceFromHWAVE(hwave
);
1202 TRACE("(%p, %p)\n", hwave
, header
);
1204 if(!WINMM_ValidateAndLock(device
))
1205 return MMSYSERR_INVALHANDLE
;
1207 if(device
->render
&& device
->acm_handle
){
1208 ACMSTREAMHEADER
*ash
;
1212 mr
= acmStreamSize(device
->acm_handle
, header
->dwBufferLength
, &size
,
1213 ACM_STREAMSIZEF_SOURCE
);
1214 if(mr
!= MMSYSERR_NOERROR
){
1215 LeaveCriticalSection(&device
->lock
);
1219 ash
= HeapAlloc(GetProcessHeap(), 0, sizeof(ACMSTREAMHEADER
) + size
);
1221 LeaveCriticalSection(&device
->lock
);
1222 return MMSYSERR_NOMEM
;
1225 ash
->cbStruct
= sizeof(*ash
);
1227 ash
->dwUser
= (DWORD_PTR
)header
;
1228 ash
->pbSrc
= (BYTE
*)header
->lpData
;
1229 ash
->cbSrcLength
= header
->dwBufferLength
;
1230 ash
->dwSrcUser
= header
->dwUser
;
1231 ash
->pbDst
= (BYTE
*)ash
+ sizeof(ACMSTREAMHEADER
);
1232 ash
->cbDstLength
= size
;
1235 mr
= acmStreamPrepareHeader(device
->acm_handle
, ash
, 0);
1236 if(mr
!= MMSYSERR_NOERROR
){
1237 HeapFree(GetProcessHeap(), 0, ash
);
1238 LeaveCriticalSection(&device
->lock
);
1242 header
->reserved
= (DWORD_PTR
)ash
;
1245 LeaveCriticalSection(&device
->lock
);
1247 header
->dwFlags
|= WHDR_PREPARED
;
1248 header
->dwFlags
&= ~WHDR_DONE
;
1250 return MMSYSERR_NOERROR
;
1253 static LRESULT
WINMM_UnprepareHeader(HWAVE hwave
, WAVEHDR
*header
)
1255 WINMM_Device
*device
= WINMM_GetDeviceFromHWAVE(hwave
);
1257 TRACE("(%p, %p)\n", hwave
, header
);
1259 if(!WINMM_ValidateAndLock(device
))
1260 return MMSYSERR_INVALHANDLE
;
1262 if(device
->render
&& device
->acm_handle
){
1263 ACMSTREAMHEADER
*ash
= (ACMSTREAMHEADER
*)header
->reserved
;
1265 acmStreamUnprepareHeader(device
->acm_handle
, ash
, 0);
1267 HeapFree(GetProcessHeap(), 0, ash
);
1270 LeaveCriticalSection(&device
->lock
);
1272 header
->dwFlags
&= ~WHDR_PREPARED
;
1273 header
->dwFlags
|= WHDR_DONE
;
1275 return MMSYSERR_NOERROR
;
1278 static UINT32
WINMM_HeaderLenBytes(WINMM_Device
*device
, WAVEHDR
*header
)
1280 if(device
->acm_handle
){
1281 ACMSTREAMHEADER
*ash
= (ACMSTREAMHEADER
*)header
->reserved
;
1282 return ash
->cbDstLengthUsed
;
1285 return header
->dwBufferLength
;
1288 static UINT32
WINMM_HeaderLenFrames(WINMM_Device
*device
, WAVEHDR
*header
)
1290 return WINMM_HeaderLenBytes(device
, header
) / device
->bytes_per_frame
;
1293 static WAVEHDR
*WOD_MarkDoneHeaders(WINMM_Device
*device
)
1296 WAVEHDR
*first
= device
->first
, *queue
= first
, *last
= NULL
;
1297 UINT64 clock_freq
, clock_pos
, clock_frames
;
1298 UINT32 nloops
, queue_frames
= 0;
1300 hr
= IAudioClock_GetFrequency(device
->clock
, &clock_freq
);
1302 WARN("GetFrequency failed: %08x\n", hr
);
1306 hr
= IAudioClock_GetPosition(device
->clock
, &clock_pos
, NULL
);
1308 WARN("GetPosition failed: %08x\n", hr
);
1312 clock_frames
= (clock_pos
* device
->samples_per_sec
) / clock_freq
;
1314 nloops
= device
->loop_counter
;
1316 (queue_frames
+= WINMM_HeaderLenFrames(device
, queue
)) <=
1317 clock_frames
- device
->last_clock_pos
){
1320 device
->last_clock_pos
+= queue_frames
;
1322 queue
= device
->first
= queue
->lpNext
;
1324 if(queue
->dwFlags
& WHDR_BEGINLOOP
){
1325 if(queue
->dwFlags
& WHDR_ENDLOOP
)
1328 queue
= queue
->lpNext
;
1329 }else if(queue
->dwFlags
& WHDR_ENDLOOP
){
1330 queue
= device
->loop_start
;
1337 last
->lpNext
= NULL
;
1343 static void WOD_PushData(WINMM_Device
*device
)
1345 WINMM_CBInfo cb_info
;
1347 UINT32 pad
, bufsize
, avail_frames
, queue_frames
, written
, ofs
;
1348 UINT32 queue_bytes
, nloops
;
1350 WAVEHDR
*queue
, *first
= NULL
;
1352 TRACE("(%p)\n", device
->handle
);
1354 EnterCriticalSection(&device
->lock
);
1360 device
->stopped
= TRUE
;
1361 device
->last_clock_pos
= 0;
1362 IAudioClient_Stop(device
->client
);
1363 IAudioClient_Reset(device
->client
);
1367 hr
= IAudioClient_GetBufferSize(device
->client
, &bufsize
);
1369 WARN("GetBufferSize failed: %08x\n", hr
);
1373 hr
= IAudioClient_GetCurrentPadding(device
->client
, &pad
);
1375 WARN("GetCurrentPadding failed: %08x\n", hr
);
1379 first
= WOD_MarkDoneHeaders(device
);
1381 /* determine which is larger between the available buffer size and
1382 * the amount of data left in the queue */
1383 avail_frames
= bufsize
- pad
;
1385 queue
= device
->playing
;
1386 ofs
= device
->ofs_bytes
;
1389 while(queue
&& queue_frames
< avail_frames
){
1390 queue_bytes
= WINMM_HeaderLenBytes(device
, queue
);
1391 queue_frames
+= (queue_bytes
- ofs
) / device
->bytes_per_frame
;
1394 if(queue
->dwFlags
& WHDR_ENDLOOP
&& nloops
< device
->loop_counter
){
1395 queue
= device
->loop_start
;
1398 queue
= queue
->lpNext
;
1401 if(queue_frames
< avail_frames
)
1402 avail_frames
= queue_frames
;
1403 if(avail_frames
== 0)
1406 hr
= IAudioRenderClient_GetBuffer(device
->render
, avail_frames
, &data
);
1408 WARN("GetBuffer failed: %08x\n", hr
);
1413 while(device
->playing
&& written
< avail_frames
){
1414 UINT32 copy_frames
, copy_bytes
;
1417 queue
= device
->playing
;
1419 if(device
->acm_handle
){
1420 ACMSTREAMHEADER
*ash
= (ACMSTREAMHEADER
*)queue
->reserved
;
1421 queue_bytes
= ash
->cbDstLengthUsed
;
1422 queue_data
= ash
->pbDst
;
1424 queue_bytes
= queue
->dwBufferLength
;
1425 queue_data
= (BYTE
*)queue
->lpData
;
1428 queue_frames
= (queue_bytes
- device
->ofs_bytes
) /
1429 device
->bytes_per_frame
;
1431 copy_frames
= queue_frames
< (avail_frames
- written
) ?
1432 queue_frames
: avail_frames
- written
;
1433 copy_bytes
= copy_frames
* device
->bytes_per_frame
;
1435 memcpy(data
, queue_data
+ device
->ofs_bytes
, copy_bytes
);
1438 written
+= copy_frames
;
1439 device
->ofs_bytes
+= copy_bytes
;
1441 if(device
->ofs_bytes
>= queue_bytes
){
1442 device
->ofs_bytes
= 0;
1444 if(!(queue
->dwFlags
& (WHDR_BEGINLOOP
| WHDR_ENDLOOP
)))
1445 device
->playing
= queue
->lpNext
;
1447 if(queue
->dwFlags
& WHDR_BEGINLOOP
){
1448 device
->loop_start
= device
->playing
;
1449 device
->playing
= queue
->lpNext
;
1450 device
->loop_counter
= queue
->dwLoops
;
1452 if(queue
->dwFlags
& WHDR_ENDLOOP
){
1453 --device
->loop_counter
;
1454 if(device
->loop_counter
)
1455 device
->playing
= device
->loop_start
;
1457 device
->loop_start
= device
->playing
= queue
->lpNext
;
1463 hr
= IAudioRenderClient_ReleaseBuffer(device
->render
, avail_frames
, 0);
1465 WARN("ReleaseBuffer failed: %08x\n", hr
);
1469 device
->played_frames
+= avail_frames
;
1472 cb_info
= device
->cb_info
;
1474 LeaveCriticalSection(&device
->lock
);
1477 WAVEHDR
*next
= first
->lpNext
;
1478 first
->dwFlags
&= ~WHDR_INQUEUE
;
1479 first
->dwFlags
|= WHDR_DONE
;
1480 WINMM_NotifyClient(&cb_info
, WOM_DONE
, (DWORD_PTR
)first
, 0);
1485 static void WID_PullACMData(WINMM_Device
*device
)
1487 UINT32 packet
, packet_bytes
;
1494 if(device
->acm_hdr
.cbDstLength
== 0){
1495 hr
= IAudioCaptureClient_GetBuffer(device
->capture
, &data
, &packet
,
1496 &flags
, NULL
, NULL
);
1499 WARN("GetBuffer failed: %08x\n", hr
);
1503 acmStreamSize(device
->acm_handle
, packet
* device
->bytes_per_frame
,
1504 &packet_bytes
, ACM_STREAMSIZEF_SOURCE
);
1506 device
->acm_offs
= 0;
1508 device
->acm_hdr
.cbStruct
= sizeof(device
->acm_hdr
);
1509 device
->acm_hdr
.fdwStatus
= 0;
1510 device
->acm_hdr
.dwUser
= 0;
1511 device
->acm_hdr
.pbSrc
= data
;
1512 device
->acm_hdr
.cbSrcLength
= packet
* device
->bytes_per_frame
;
1513 device
->acm_hdr
.cbSrcLengthUsed
= 0;
1514 device
->acm_hdr
.dwSrcUser
= 0;
1515 device
->acm_hdr
.pbDst
= HeapAlloc(GetProcessHeap(), 0, packet_bytes
);
1516 device
->acm_hdr
.cbDstLength
= packet_bytes
;
1517 device
->acm_hdr
.cbDstLengthUsed
= 0;
1518 device
->acm_hdr
.dwDstUser
= 0;
1520 mr
= acmStreamPrepareHeader(device
->acm_handle
, &device
->acm_hdr
, 0);
1521 if(mr
!= MMSYSERR_NOERROR
){
1522 WARN("acmStreamPrepareHeader failed: %d\n", mr
);
1526 mr
= acmStreamConvert(device
->acm_handle
, &device
->acm_hdr
, 0);
1527 if(mr
!= MMSYSERR_NOERROR
){
1528 WARN("acmStreamConvert failed: %d\n", mr
);
1532 hr
= IAudioCaptureClient_ReleaseBuffer(device
->capture
, packet
);
1534 WARN("ReleaseBuffer failed: %08x\n", hr
);
1536 device
->played_frames
+= packet
;
1539 queue
= device
->first
;
1541 UINT32 to_copy_bytes
;
1543 to_copy_bytes
= min(queue
->dwBufferLength
- queue
->dwBytesRecorded
,
1544 device
->acm_hdr
.cbDstLengthUsed
- device
->acm_offs
);
1546 memcpy(queue
->lpData
+ queue
->dwBytesRecorded
,
1547 device
->acm_hdr
.pbDst
+ device
->acm_offs
, to_copy_bytes
);
1549 queue
->dwBytesRecorded
+= to_copy_bytes
;
1550 device
->acm_offs
+= to_copy_bytes
;
1552 if(queue
->dwBufferLength
- queue
->dwBytesRecorded
<
1553 device
->bytes_per_frame
){
1554 queue
->dwFlags
&= ~WHDR_INQUEUE
;
1555 queue
->dwFlags
|= WHDR_DONE
;
1556 device
->first
= queue
= queue
->lpNext
;
1559 if(device
->acm_offs
>= device
->acm_hdr
.cbDstLengthUsed
){
1560 acmStreamUnprepareHeader(device
->acm_handle
, &device
->acm_hdr
, 0);
1561 HeapFree(GetProcessHeap(), 0, device
->acm_hdr
.pbDst
);
1562 device
->acm_hdr
.cbDstLength
= 0;
1563 device
->acm_hdr
.cbDstLengthUsed
= 0;
1565 /* done with this ACM Header, so try to pull more data */
1566 WID_PullACMData(device
);
1571 /* out of WAVEHDRs to write into, so toss the rest of this packet */
1572 acmStreamUnprepareHeader(device
->acm_handle
, &device
->acm_hdr
, 0);
1573 HeapFree(GetProcessHeap(), 0, device
->acm_hdr
.pbDst
);
1574 device
->acm_hdr
.cbDstLength
= 0;
1575 device
->acm_hdr
.cbDstLengthUsed
= 0;
1578 static void WID_PullData(WINMM_Device
*device
)
1580 WINMM_CBInfo cb_info
;
1581 WAVEHDR
*queue
, *first
= NULL
, *last
= NULL
;
1584 TRACE("(%p)\n", device
->handle
);
1586 EnterCriticalSection(&device
->lock
);
1588 if(!device
->device
|| !device
->first
)
1591 first
= device
->first
;
1593 if(device
->acm_handle
){
1594 WID_PullACMData(device
);
1598 while(device
->first
){
1600 UINT32 packet_len
, packet
;
1603 hr
= IAudioCaptureClient_GetBuffer(device
->capture
, &data
, &packet_len
,
1604 &flags
, NULL
, NULL
);
1607 WARN("GetBuffer failed: %08x\n", hr
);
1608 else /* AUDCLNT_S_BUFFER_EMPTY success code */
1609 IAudioCaptureClient_ReleaseBuffer(device
->capture
, 0);
1613 packet
= packet_len
;
1614 queue
= device
->first
;
1615 while(queue
&& packet
> 0){
1616 UINT32 to_copy_bytes
;
1618 to_copy_bytes
= min(packet
* device
->bytes_per_frame
,
1619 queue
->dwBufferLength
- queue
->dwBytesRecorded
);
1621 memcpy(queue
->lpData
+ queue
->dwBytesRecorded
,
1622 data
+ (packet_len
- packet
) * device
->bytes_per_frame
,
1625 queue
->dwBytesRecorded
+= to_copy_bytes
;
1627 if(queue
->dwBufferLength
- queue
->dwBytesRecorded
<
1628 device
->bytes_per_frame
){
1630 device
->first
= queue
= queue
->lpNext
;
1633 packet
-= to_copy_bytes
/ device
->bytes_per_frame
;
1636 hr
= IAudioCaptureClient_ReleaseBuffer(device
->capture
, packet_len
);
1638 WARN("ReleaseBuffer failed: %08x\n", hr
);
1641 WARN("losing %u frames\n", packet
);
1642 device
->played_frames
+= packet_len
;
1646 cb_info
= device
->cb_info
;
1648 LeaveCriticalSection(&device
->lock
);
1651 last
->lpNext
= NULL
;
1653 WAVEHDR
*next
= first
->lpNext
;
1654 first
->dwFlags
&= ~WHDR_INQUEUE
;
1655 first
->dwFlags
|= WHDR_DONE
;
1656 WINMM_NotifyClient(&cb_info
, WIM_DATA
, (DWORD_PTR
)first
, 0);
1662 static HRESULT
WINMM_BeginPlaying(WINMM_Device
*device
)
1666 TRACE("(%p)\n", device
->handle
);
1669 /* prebuffer data before starting */
1670 WOD_PushData(device
);
1672 if(device
->stopped
){
1673 device
->stopped
= FALSE
;
1675 hr
= IAudioClient_Start(device
->client
);
1676 if(FAILED(hr
) && hr
!= AUDCLNT_E_NOT_STOPPED
){
1677 device
->stopped
= TRUE
;
1678 WARN("Start failed: %08x\n", hr
);
1686 static LRESULT
WINMM_Pause(HWAVE hwave
)
1688 WINMM_Device
*device
= WINMM_GetDeviceFromHWAVE(hwave
);
1691 TRACE("(%p)\n", hwave
);
1693 if(!WINMM_ValidateAndLock(device
))
1694 return MMSYSERR_INVALHANDLE
;
1696 hr
= IAudioClient_Stop(device
->client
);
1698 LeaveCriticalSection(&device
->lock
);
1699 WARN("Stop failed: %08x\n", hr
);
1700 return MMSYSERR_ERROR
;
1703 device
->stopped
= FALSE
;
1705 LeaveCriticalSection(&device
->lock
);
1707 return MMSYSERR_NOERROR
;
1710 static LRESULT
WINMM_Reset(HWAVE hwave
)
1712 WINMM_CBInfo cb_info
;
1713 WINMM_Device
*device
= WINMM_GetDeviceFromHWAVE(hwave
);
1718 TRACE("(%p)\n", hwave
);
1720 if(!WINMM_ValidateAndLock(device
))
1721 return MMSYSERR_INVALHANDLE
;
1723 hr
= IAudioClient_Stop(device
->client
);
1725 LeaveCriticalSection(&device
->lock
);
1726 WARN("Stop failed: %08x\n", hr
);
1727 return MMSYSERR_ERROR
;
1729 device
->stopped
= TRUE
;
1731 first
= device
->first
;
1732 device
->first
= device
->last
= device
->playing
= NULL
;
1733 device
->ofs_bytes
= 0;
1734 device
->played_frames
= 0;
1735 device
->loop_counter
= 0;
1736 device
->last_clock_pos
= 0;
1737 IAudioClient_Reset(device
->client
);
1739 cb_info
= device
->cb_info
;
1740 is_out
= device
->render
? TRUE
: FALSE
;
1742 LeaveCriticalSection(&device
->lock
);
1745 WAVEHDR
*next
= first
->lpNext
;
1746 first
->dwFlags
&= ~WHDR_INQUEUE
;
1747 first
->dwFlags
|= WHDR_DONE
;
1749 WINMM_NotifyClient(&cb_info
, WOM_DONE
, (DWORD_PTR
)first
, 0);
1751 WINMM_NotifyClient(&cb_info
, WIM_DATA
, (DWORD_PTR
)first
, 0);
1755 return MMSYSERR_NOERROR
;
1758 static MMRESULT
WINMM_FramesToMMTime(MMTIME
*time
, UINT32 played_frames
,
1759 UINT32 sample_rate
, UINT32 bytes_per_frame
)
1761 switch(time
->wType
){
1763 time
->u
.sample
= played_frames
;
1764 return MMSYSERR_NOERROR
;
1766 time
->u
.ms
= (UINT64
)played_frames
* 1000 / sample_rate
;
1767 return MMSYSERR_NOERROR
;
1769 time
->u
.smpte
.fps
= 30;
1770 played_frames
+= sample_rate
/ time
->u
.smpte
.fps
- 1; /* round up */
1771 time
->u
.smpte
.frame
= (played_frames
% sample_rate
) * time
->u
.smpte
.fps
/ sample_rate
;
1772 played_frames
/= sample_rate
; /* yields seconds */
1773 time
->u
.smpte
.sec
= played_frames
% 60;
1774 played_frames
/= 60;
1775 time
->u
.smpte
.min
= played_frames
% 60;
1776 time
->u
.smpte
.hour
= played_frames
/ 60;
1777 return MMSYSERR_NOERROR
;
1779 time
->wType
= TIME_BYTES
;
1782 time
->u
.cb
= played_frames
* bytes_per_frame
;
1783 return MMSYSERR_NOERROR
;
1787 static LRESULT
WINMM_GetPosition(HWAVE hwave
, MMTIME
*time
)
1789 WINMM_Device
*device
= WINMM_GetDeviceFromHWAVE(hwave
);
1790 UINT32 played_frames
, sample_rate
, bytes_per_frame
;
1792 TRACE("(%p, %p)\n", hwave
, time
);
1794 if(!WINMM_ValidateAndLock(device
))
1795 return MMSYSERR_INVALHANDLE
;
1797 played_frames
= device
->played_frames
;
1798 sample_rate
= device
->samples_per_sec
;
1799 bytes_per_frame
= device
->bytes_per_frame
;
1801 LeaveCriticalSection(&device
->lock
);
1803 return WINMM_FramesToMMTime(time
, played_frames
, sample_rate
,
1807 static WINMM_MMDevice
*WINMM_GetMixerMMDevice(HMIXEROBJ hmix
, DWORD flags
,
1810 UINT mmdev
, dev
, junk
, *out
;
1818 switch(flags
& 0xF0000000){
1819 case MIXER_OBJECTF_MIXER
: /* == 0 */
1820 *out
= HandleToULong(hmix
);
1821 if(*out
< g_outmmdevices_count
)
1822 return &g_out_mmdevices
[*out
];
1823 if(*out
- g_outmmdevices_count
< g_inmmdevices_count
){
1824 *out
-= g_outmmdevices_count
;
1825 return &g_in_mmdevices
[*out
];
1827 /* fall through -- if it's not a valid mixer device, then
1828 * it could be a valid mixer handle. windows seems to do
1830 case MIXER_OBJECTF_HMIXER
:
1831 case MIXER_OBJECTF_HWAVEOUT
:
1832 case MIXER_OBJECTF_HWAVEIN
:
1833 WINMM_DecomposeHWAVE((HWAVE
)hmix
, out
, &is_out
, &dev
, &junk
);
1834 if(junk
!= 0x1 || (is_out
&& *out
>= g_outmmdevices_count
) ||
1835 (!is_out
&& *out
>= g_inmmdevices_count
))
1838 return &g_out_mmdevices
[*out
];
1839 return &g_in_mmdevices
[*out
];
1840 case MIXER_OBJECTF_WAVEOUT
:
1841 *out
= HandleToULong(hmix
);
1842 if(*out
< g_outmmdevices_count
)
1843 return &g_out_mmdevices
[*out
];
1845 case MIXER_OBJECTF_WAVEIN
:
1846 *out
= HandleToULong(hmix
);
1847 if(*out
< g_inmmdevices_count
)
1848 return &g_in_mmdevices
[*out
];
1855 static MMRESULT
WINMM_SetupMMDeviceVolume(WINMM_MMDevice
*mmdevice
)
1857 IAudioSessionManager
*sesman
;
1861 hr
= IMMDeviceEnumerator_GetDevice(g_devenum
, mmdevice
->dev_id
, &device
);
1863 WARN("Device %s (%s) unavailable: %08x\n",
1864 wine_dbgstr_w(mmdevice
->dev_id
),
1865 wine_dbgstr_w(mmdevice
->out_caps
.szPname
), hr
);
1866 return MMSYSERR_ERROR
;
1869 hr
= IMMDevice_Activate(device
, &IID_IAudioSessionManager
,
1870 CLSCTX_INPROC_SERVER
, NULL
, (void**)&sesman
);
1872 WARN("Activate failed: %08x\n", hr
);
1873 IMMDevice_Release(device
);
1874 return MMSYSERR_ERROR
;
1877 IMMDevice_Release(device
);
1879 hr
= IAudioSessionManager_GetSimpleAudioVolume(sesman
, &mmdevice
->session
,
1880 FALSE
, &mmdevice
->volume
);
1881 IAudioSessionManager_Release(sesman
);
1883 WARN("GetSimpleAudioVolume failed: %08x\n", hr
);
1884 return MMSYSERR_ERROR
;
1887 return MMSYSERR_NOERROR
;
1890 static LRESULT
MXD_GetControlDetails(WINMM_ControlDetails
*details
)
1892 WINMM_MMDevice
*mmdevice
;
1893 MIXERCONTROLDETAILS
*control
= details
->details
;
1896 TRACE("(%p)\n", details
->hmix
);
1898 mmdevice
= WINMM_GetMixerMMDevice(details
->hmix
, details
->flags
, NULL
);
1900 return MMSYSERR_INVALHANDLE
;
1902 EnterCriticalSection(&mmdevice
->lock
);
1904 if(!mmdevice
->volume
){
1907 mr
= WINMM_SetupMMDeviceVolume(mmdevice
);
1908 if(mr
!= MMSYSERR_NOERROR
){
1909 LeaveCriticalSection(&mmdevice
->lock
);
1914 if(control
->dwControlID
== 0){
1916 MIXERCONTROLDETAILS_UNSIGNED
*udet
;
1918 if(!control
->paDetails
||
1919 control
->cbDetails
< sizeof(MIXERCONTROLDETAILS_UNSIGNED
)){
1920 LeaveCriticalSection(&mmdevice
->lock
);
1921 return MMSYSERR_INVALPARAM
;
1924 hr
= ISimpleAudioVolume_GetMasterVolume(mmdevice
->volume
, &vol
);
1926 WARN("GetMasterVolume failed: %08x\n", hr
);
1927 LeaveCriticalSection(&mmdevice
->lock
);
1928 return MMSYSERR_ERROR
;
1931 udet
= (MIXERCONTROLDETAILS_UNSIGNED
*)control
->paDetails
;
1932 udet
->dwValue
= vol
* ((unsigned int)0xFFFF);
1933 }else if(control
->dwControlID
== 1){
1935 MIXERCONTROLDETAILS_BOOLEAN
*bdet
;
1937 if(!control
->paDetails
||
1938 control
->cbDetails
< sizeof(MIXERCONTROLDETAILS_BOOLEAN
)){
1939 LeaveCriticalSection(&mmdevice
->lock
);
1940 return MMSYSERR_INVALPARAM
;
1943 hr
= ISimpleAudioVolume_GetMute(mmdevice
->volume
, &mute
);
1945 WARN("GetMute failed: %08x\n", hr
);
1946 LeaveCriticalSection(&mmdevice
->lock
);
1947 return MMSYSERR_ERROR
;
1950 bdet
= (MIXERCONTROLDETAILS_BOOLEAN
*)control
->paDetails
;
1951 bdet
->fValue
= mute
;
1952 }else if(control
->dwControlID
== 2 || control
->dwControlID
== 3){
1953 FIXME("What should the sw-side mixer controls map to?\n");
1955 LeaveCriticalSection(&mmdevice
->lock
);
1956 return MIXERR_INVALCONTROL
;
1959 LeaveCriticalSection(&mmdevice
->lock
);
1961 return MMSYSERR_NOERROR
;
1964 static LRESULT
MXD_SetControlDetails(WINMM_ControlDetails
*details
)
1966 WINMM_MMDevice
*mmdevice
;
1967 MIXERCONTROLDETAILS
*control
= details
->details
;
1970 TRACE("(%p)\n", details
->hmix
);
1972 mmdevice
= WINMM_GetMixerMMDevice(details
->hmix
, details
->flags
, NULL
);
1974 return MMSYSERR_INVALHANDLE
;
1976 EnterCriticalSection(&mmdevice
->lock
);
1978 if(!mmdevice
->volume
){
1981 mr
= WINMM_SetupMMDeviceVolume(mmdevice
);
1982 if(mr
!= MMSYSERR_NOERROR
){
1983 LeaveCriticalSection(&mmdevice
->lock
);
1988 if(control
->dwControlID
== 0){
1990 MIXERCONTROLDETAILS_UNSIGNED
*udet
;
1992 if(!control
->paDetails
||
1993 control
->cbDetails
< sizeof(MIXERCONTROLDETAILS_UNSIGNED
)){
1994 LeaveCriticalSection(&mmdevice
->lock
);
1995 return MMSYSERR_INVALPARAM
;
1998 udet
= (MIXERCONTROLDETAILS_UNSIGNED
*)control
->paDetails
;
2000 if(udet
->dwValue
> 65535){
2001 LeaveCriticalSection(&mmdevice
->lock
);
2002 return MMSYSERR_INVALPARAM
;
2005 vol
= udet
->dwValue
/ 65535.f
;
2007 hr
= ISimpleAudioVolume_SetMasterVolume(mmdevice
->volume
, vol
, NULL
);
2009 WARN("SetMasterVolume failed: %08x\n", hr
);
2010 LeaveCriticalSection(&mmdevice
->lock
);
2011 return MMSYSERR_ERROR
;
2013 }else if(control
->dwControlID
== 1){
2015 MIXERCONTROLDETAILS_BOOLEAN
*bdet
;
2017 if(!control
->paDetails
||
2018 control
->cbDetails
< sizeof(MIXERCONTROLDETAILS_BOOLEAN
)){
2019 LeaveCriticalSection(&mmdevice
->lock
);
2020 return MMSYSERR_INVALPARAM
;
2023 bdet
= (MIXERCONTROLDETAILS_BOOLEAN
*)control
->paDetails
;
2024 mute
= bdet
->fValue
;
2026 hr
= ISimpleAudioVolume_SetMute(mmdevice
->volume
, mute
, NULL
);
2028 WARN("SetMute failed: %08x\n", hr
);
2029 LeaveCriticalSection(&mmdevice
->lock
);
2030 return MMSYSERR_ERROR
;
2032 }else if(control
->dwControlID
== 2 || control
->dwControlID
== 3){
2033 FIXME("What should the sw-side mixer controls map to?\n");
2035 LeaveCriticalSection(&mmdevice
->lock
);
2036 return MIXERR_INVALCONTROL
;
2039 LeaveCriticalSection(&mmdevice
->lock
);
2041 return MMSYSERR_NOERROR
;
2044 static LRESULT
DRV_QueryDeviceInterface(WINMM_QueryInterfaceInfo
*info
)
2046 WINMM_MMDevice
*mmdevice
;
2053 static const PROPERTYKEY deviceinterface_key
= {
2054 {0x233164c8, 0x1b2c, 0x4c7d, {0xbc, 0x68, 0xb6, 0x71, 0x68, 0x7a, 0x25, 0x67}}, 1
2057 if(WINMM_IsMapper(info
->index
)){
2059 if(*info
->len_bytes
< sizeof(WCHAR
))
2060 return MMSYSERR_INVALPARAM
;
2063 *info
->len_bytes
= sizeof(WCHAR
);
2064 return MMSYSERR_NOERROR
;
2068 if(info
->index
>= g_outmmdevices_count
)
2069 return MMSYSERR_INVALHANDLE
;
2071 mmdevice
= &g_out_mmdevices
[info
->index
];
2073 if(info
->index
>= g_inmmdevices_count
)
2074 return MMSYSERR_INVALHANDLE
;
2076 mmdevice
= &g_in_mmdevices
[info
->index
];
2079 hr
= IMMDeviceEnumerator_GetDevice(g_devenum
, mmdevice
->dev_id
,
2082 WARN("Device %s unavailable: %08x\n", wine_dbgstr_w(mmdevice
->dev_id
), hr
);
2083 return MMSYSERR_ERROR
;
2086 hr
= IMMDevice_OpenPropertyStore(device
, STGM_READ
, &ps
);
2088 WARN("OpenPropertyStore failed: %08x\n", hr
);
2089 IMMDevice_Release(device
);
2090 return MMSYSERR_ERROR
;
2093 PropVariantInit(&pv
);
2094 hr
= IPropertyStore_GetValue(ps
, &deviceinterface_key
, &pv
);
2096 WARN("GetValue failed: %08x\n", hr
);
2097 IPropertyStore_Release(ps
);
2098 IMMDevice_Release(device
);
2099 return MMSYSERR_ERROR
;
2101 if(pv
.vt
!= VT_LPWSTR
){
2102 WARN("Got unexpected property type: %u\n", pv
.vt
);
2103 PropVariantClear(&pv
);
2104 IPropertyStore_Release(ps
);
2105 IMMDevice_Release(device
);
2106 return MMSYSERR_ERROR
;
2109 len_bytes
= (lstrlenW(pv
.u
.pwszVal
) + 1) * sizeof(WCHAR
);
2112 if(len_bytes
> *info
->len_bytes
){
2113 PropVariantClear(&pv
);
2114 IPropertyStore_Release(ps
);
2115 IMMDevice_Release(device
);
2116 return MMSYSERR_INVALPARAM
;
2119 memcpy(info
->str
, pv
.u
.pwszVal
, len_bytes
);
2121 *info
->len_bytes
= len_bytes
;
2123 PropVariantClear(&pv
);
2124 IPropertyStore_Release(ps
);
2125 IMMDevice_Release(device
);
2127 return MMSYSERR_NOERROR
;
2130 static LRESULT CALLBACK
WINMM_DevicesMsgProc(HWND hwnd
, UINT msg
, WPARAM wparam
,
2135 return WOD_Open((WINMM_OpenInfo
*)wparam
);
2137 return WOD_Close((HWAVEOUT
)wparam
);
2139 return WID_Open((WINMM_OpenInfo
*)wparam
);
2141 return WID_Close((HWAVEIN
)wparam
);
2142 case MXDM_GETCONTROLDETAILS
:
2143 return MXD_GetControlDetails((WINMM_ControlDetails
*)wparam
);
2144 case MXDM_SETCONTROLDETAILS
:
2145 return MXD_SetControlDetails((WINMM_ControlDetails
*)wparam
);
2146 case DRV_QUERYDEVICEINTERFACESIZE
:
2147 case DRV_QUERYDEVICEINTERFACE
:
2148 return DRV_QueryDeviceInterface((WINMM_QueryInterfaceInfo
*)wparam
);
2150 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
2153 static DWORD WINAPI
WINMM_DevicesThreadProc(void *arg
)
2157 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e',0};
2159 hr
= CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
2161 WARN("CoInitializeEx failed: %08x\n", hr
);
2165 hr
= WINMM_InitMMDevices();
2171 hr
= CoCreateInstance(&CLSID_MMDeviceEnumerator
, NULL
,
2172 CLSCTX_INPROC_SERVER
, &IID_IMMDeviceEnumerator
, (void**)&g_devenum
);
2174 WARN("CoCreateInstance failed: %08x\n", hr
);
2179 g_devices_hwnd
= CreateWindowW(messageW
, NULL
, 0, 0, 0, 0, 0,
2180 HWND_MESSAGE
, NULL
, NULL
, NULL
);
2181 if(!g_devices_hwnd
){
2182 WARN("CreateWindow failed: %d\n", GetLastError());
2183 IMMDeviceEnumerator_Release(g_devenum
);
2188 SetWindowLongPtrW(g_devices_hwnd
, GWLP_WNDPROC
,
2189 (LONG_PTR
)WINMM_DevicesMsgProc
);
2191 /* inform caller that the thread is ready to process messages */
2193 evt
= NULL
; /* do not use after this point */
2197 wait
= MsgWaitForMultipleObjects(g_devhandle_count
, g_device_handles
,
2198 FALSE
, INFINITE
, QS_ALLINPUT
);
2199 if(wait
== g_devhandle_count
+ WAIT_OBJECT_0
){
2201 if(PeekMessageW(&msg
, g_devices_hwnd
, 0, 0, PM_REMOVE
))
2202 WARN("Unexpected message: 0x%x\n", msg
.message
);
2203 }else if(wait
< g_devhandle_count
+ WAIT_OBJECT_0
){
2204 WINMM_Device
*device
= g_handle_devices
[wait
- WAIT_OBJECT_0
];
2206 WOD_PushData(device
);
2208 WID_PullData(device
);
2210 WARN("Unexpected MsgWait result 0x%x, GLE: %d\n", wait
,
2214 DestroyWindow(g_devices_hwnd
);
2216 IMMDeviceEnumerator_Release(g_devenum
);
2223 static BOOL
WINMM_StartDevicesThread(void)
2228 EnterCriticalSection(&g_devthread_lock
);
2230 if(g_devices_thread
){
2233 wait
= WaitForSingleObject(g_devices_thread
, 0);
2234 if(wait
== WAIT_TIMEOUT
){
2235 LeaveCriticalSection(&g_devthread_lock
);
2238 if(wait
!= WAIT_OBJECT_0
){
2239 LeaveCriticalSection(&g_devthread_lock
);
2243 g_devices_thread
= NULL
;
2244 g_devices_hwnd
= NULL
;
2247 TRACE("Starting up devices thread\n");
2249 events
[0] = CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2251 g_devices_thread
= CreateThread(NULL
, 0, WINMM_DevicesThreadProc
,
2252 events
[0], 0, NULL
);
2253 if(!g_devices_thread
){
2254 LeaveCriticalSection(&g_devthread_lock
);
2255 CloseHandle(events
[0]);
2259 events
[1] = g_devices_thread
;
2260 wait
= WaitForMultipleObjects(2, events
, FALSE
, INFINITE
);
2261 CloseHandle(events
[0]);
2262 if(wait
!= WAIT_OBJECT_0
){
2263 if(wait
== 1 + WAIT_OBJECT_0
){
2264 CloseHandle(g_devices_thread
);
2265 g_devices_thread
= NULL
;
2266 g_devices_hwnd
= NULL
;
2268 LeaveCriticalSection(&g_devthread_lock
);
2272 LeaveCriticalSection(&g_devthread_lock
);
2277 /**************************************************************************
2278 * waveOutGetNumDevs [WINMM.@]
2280 UINT WINAPI
waveOutGetNumDevs(void)
2282 HRESULT hr
= WINMM_InitMMDevices();
2286 TRACE("count: %u\n", g_outmmdevices_count
);
2288 return g_outmmdevices_count
;
2291 /**************************************************************************
2292 * waveOutGetDevCapsA [WINMM.@]
2294 UINT WINAPI
waveOutGetDevCapsA(UINT_PTR uDeviceID
, LPWAVEOUTCAPSA lpCaps
,
2300 TRACE("(%lu, %p, %u)\n", uDeviceID
, lpCaps
, uSize
);
2303 return MMSYSERR_INVALPARAM
;
2305 ret
= waveOutGetDevCapsW(uDeviceID
, &wocW
, sizeof(wocW
));
2307 if (ret
== MMSYSERR_NOERROR
) {
2309 wocA
.wMid
= wocW
.wMid
;
2310 wocA
.wPid
= wocW
.wPid
;
2311 wocA
.vDriverVersion
= wocW
.vDriverVersion
;
2312 WideCharToMultiByte( CP_ACP
, 0, wocW
.szPname
, -1, wocA
.szPname
,
2313 sizeof(wocA
.szPname
), NULL
, NULL
);
2314 wocA
.dwFormats
= wocW
.dwFormats
;
2315 wocA
.wChannels
= wocW
.wChannels
;
2316 wocA
.dwSupport
= wocW
.dwSupport
;
2317 memcpy(lpCaps
, &wocA
, min(uSize
, sizeof(wocA
)));
2322 /**************************************************************************
2323 * waveOutGetDevCapsW [WINMM.@]
2325 UINT WINAPI
waveOutGetDevCapsW(UINT_PTR uDeviceID
, LPWAVEOUTCAPSW lpCaps
,
2328 WAVEOUTCAPSW mapper_caps
, *caps
;
2331 TRACE("(%lu, %p, %u)\n", uDeviceID
, lpCaps
, uSize
);
2333 hr
= WINMM_InitMMDevices();
2335 return MMSYSERR_ERROR
;
2337 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
2339 if(WINMM_IsMapper(uDeviceID
)){
2340 /* FIXME: Should be localized */
2341 static const WCHAR mapper_pnameW
[] = {'W','i','n','e',' ','S','o','u',
2342 'n','d',' ','M','a','p','p','e','r',0};
2344 mapper_caps
.wMid
= 0xFF;
2345 mapper_caps
.wPid
= 0xFF;
2346 mapper_caps
.vDriverVersion
= 0x00010001;
2347 mapper_caps
.dwFormats
= 0xFFFFFFFF;
2348 mapper_caps
.wReserved1
= 0;
2349 mapper_caps
.dwSupport
= WAVECAPS_LRVOLUME
| WAVECAPS_VOLUME
|
2350 WAVECAPS_SAMPLEACCURATE
;
2351 mapper_caps
.wChannels
= 2;
2352 lstrcpyW(mapper_caps
.szPname
, mapper_pnameW
);
2354 caps
= &mapper_caps
;
2356 if(uDeviceID
>= g_outmmdevices_count
)
2357 return MMSYSERR_BADDEVICEID
;
2359 caps
= &g_out_mmdevices
[uDeviceID
].out_caps
;
2362 memcpy(lpCaps
, caps
, min(uSize
, sizeof(*lpCaps
)));
2364 return MMSYSERR_NOERROR
;
2367 /**************************************************************************
2368 * waveOutGetErrorTextA [WINMM.@]
2369 * waveInGetErrorTextA [WINMM.@]
2371 UINT WINAPI
waveOutGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
2375 if (lpText
== NULL
) ret
= MMSYSERR_INVALPARAM
;
2376 else if (uSize
== 0) ret
= MMSYSERR_NOERROR
;
2379 LPWSTR xstr
= HeapAlloc(GetProcessHeap(), 0, uSize
* sizeof(WCHAR
));
2380 if (!xstr
) ret
= MMSYSERR_NOMEM
;
2383 ret
= waveOutGetErrorTextW(uError
, xstr
, uSize
);
2384 if (ret
== MMSYSERR_NOERROR
)
2385 WideCharToMultiByte(CP_ACP
, 0, xstr
, -1, lpText
, uSize
, NULL
, NULL
);
2386 HeapFree(GetProcessHeap(), 0, xstr
);
2392 /**************************************************************************
2393 * waveOutGetErrorTextW [WINMM.@]
2394 * waveInGetErrorTextW [WINMM.@]
2396 UINT WINAPI
waveOutGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
2398 UINT ret
= MMSYSERR_BADERRNUM
;
2400 if (lpText
== NULL
) ret
= MMSYSERR_INVALPARAM
;
2401 else if (uSize
== 0) ret
= MMSYSERR_NOERROR
;
2403 /* test has been removed because MMSYSERR_BASE is 0, and gcc did emit
2404 * a warning for the test was always true */
2405 (/*uError >= MMSYSERR_BASE && */ uError
<= MMSYSERR_LASTERROR
) ||
2406 (uError
>= WAVERR_BASE
&& uError
<= WAVERR_LASTERROR
)) {
2407 if (LoadStringW(hWinMM32Instance
,
2408 uError
, lpText
, uSize
) > 0) {
2409 ret
= MMSYSERR_NOERROR
;
2415 /**************************************************************************
2416 * waveOutOpen [WINMM.@]
2417 * All the args/structs have the same layout as the win16 equivalents
2419 MMRESULT WINAPI
waveOutOpen(LPHWAVEOUT lphWaveOut
, UINT uDeviceID
,
2420 LPCWAVEFORMATEX lpFormat
, DWORD_PTR dwCallback
,
2421 DWORD_PTR dwInstance
, DWORD dwFlags
)
2424 WINMM_OpenInfo info
;
2425 WINMM_CBInfo cb_info
;
2427 TRACE("(%p, %u, %p, %lx, %lx, %08x)\n", lphWaveOut
, uDeviceID
, lpFormat
,
2428 dwCallback
, dwInstance
, dwFlags
);
2430 if(!WINMM_StartDevicesThread())
2431 return MMSYSERR_ERROR
;
2433 if(!lphWaveOut
&& !(dwFlags
& WAVE_FORMAT_QUERY
))
2434 return MMSYSERR_INVALPARAM
;
2436 res
= WINMM_CheckCallback(dwCallback
, dwFlags
, FALSE
);
2437 if(res
!= MMSYSERR_NOERROR
)
2440 info
.format
= (WAVEFORMATEX
*)lpFormat
;
2441 info
.callback
= dwCallback
;
2442 info
.cb_user
= dwInstance
;
2443 info
.req_device
= uDeviceID
;
2444 info
.flags
= dwFlags
;
2446 res
= SendMessageW(g_devices_hwnd
, WODM_OPEN
, (DWORD_PTR
)&info
, 0);
2447 if(res
!= MMSYSERR_NOERROR
)
2451 *lphWaveOut
= (HWAVEOUT
)info
.handle
;
2453 cb_info
.flags
= HIWORD(dwFlags
& CALLBACK_TYPEMASK
);
2454 cb_info
.callback
= dwCallback
;
2455 cb_info
.user
= dwInstance
;
2456 cb_info
.hwave
= info
.handle
;
2458 WINMM_NotifyClient(&cb_info
, WOM_OPEN
, 0, 0);
2463 /**************************************************************************
2464 * waveOutClose [WINMM.@]
2466 UINT WINAPI
waveOutClose(HWAVEOUT hWaveOut
)
2469 WINMM_Device
*device
;
2470 WINMM_CBInfo cb_info
;
2472 TRACE("(%p)\n", hWaveOut
);
2474 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveOut
);
2476 if(!WINMM_ValidateAndLock(device
))
2477 return MMSYSERR_INVALHANDLE
;
2479 cb_info
= device
->cb_info
;
2481 LeaveCriticalSection(&device
->lock
);
2483 res
= SendMessageW(g_devices_hwnd
, WODM_CLOSE
, (WPARAM
)hWaveOut
, 0);
2485 if(res
== MMSYSERR_NOERROR
)
2486 WINMM_NotifyClient(&cb_info
, WOM_CLOSE
, 0, 0);
2491 /**************************************************************************
2492 * waveOutPrepareHeader [WINMM.@]
2494 UINT WINAPI
waveOutPrepareHeader(HWAVEOUT hWaveOut
,
2495 WAVEHDR
* lpWaveOutHdr
, UINT uSize
)
2497 TRACE("(%p, %p, %u)\n", hWaveOut
, lpWaveOutHdr
, uSize
);
2499 if(!lpWaveOutHdr
|| uSize
< sizeof(WAVEHDR
))
2500 return MMSYSERR_INVALPARAM
;
2502 if(lpWaveOutHdr
->dwFlags
& WHDR_INQUEUE
)
2503 return WAVERR_STILLPLAYING
;
2505 return WINMM_PrepareHeader((HWAVE
)hWaveOut
, lpWaveOutHdr
);
2508 /**************************************************************************
2509 * waveOutUnprepareHeader [WINMM.@]
2511 UINT WINAPI
waveOutUnprepareHeader(HWAVEOUT hWaveOut
,
2512 LPWAVEHDR lpWaveOutHdr
, UINT uSize
)
2514 TRACE("(%p, %p, %u)\n", hWaveOut
, lpWaveOutHdr
, uSize
);
2516 if(!lpWaveOutHdr
|| uSize
< sizeof(WAVEHDR
))
2517 return MMSYSERR_INVALPARAM
;
2519 if(!(lpWaveOutHdr
->dwFlags
& WHDR_PREPARED
))
2520 return MMSYSERR_NOERROR
;
2522 if(lpWaveOutHdr
->dwFlags
& WHDR_INQUEUE
)
2523 return WAVERR_STILLPLAYING
;
2525 return WINMM_UnprepareHeader((HWAVE
)hWaveOut
, lpWaveOutHdr
);
2528 /**************************************************************************
2529 * waveOutWrite [WINMM.@]
2531 UINT WINAPI
waveOutWrite(HWAVEOUT hWaveOut
, WAVEHDR
*header
, UINT uSize
)
2533 WINMM_Device
*device
;
2536 TRACE("(%p, %p, %u)\n", hWaveOut
, header
, uSize
);
2538 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveOut
);
2540 if(!WINMM_ValidateAndLock(device
))
2541 return MMSYSERR_INVALHANDLE
;
2543 if(!header
->lpData
|| !(header
->dwFlags
& WHDR_PREPARED
)){
2544 LeaveCriticalSection(&device
->lock
);
2545 return WAVERR_UNPREPARED
;
2548 if(header
->dwFlags
& WHDR_INQUEUE
){
2549 LeaveCriticalSection(&device
->lock
);
2550 return WAVERR_STILLPLAYING
;
2553 if(device
->acm_handle
){
2554 ACMSTREAMHEADER
*ash
= (ACMSTREAMHEADER
*)header
->reserved
;
2557 ash
->cbSrcLength
= header
->dwBufferLength
;
2558 mr
= acmStreamConvert(device
->acm_handle
, ash
, 0);
2559 if(mr
!= MMSYSERR_NOERROR
){
2560 LeaveCriticalSection(&device
->lock
);
2566 device
->last
->lpNext
= header
;
2567 device
->last
= header
;
2568 if(!device
->playing
)
2569 device
->playing
= header
;
2571 device
->playing
= device
->first
= device
->last
= header
;
2572 if(header
->dwFlags
& WHDR_BEGINLOOP
){
2573 device
->loop_counter
= header
->dwLoops
;
2574 device
->loop_start
= header
;
2578 header
->lpNext
= NULL
;
2579 header
->dwFlags
&= ~WHDR_DONE
;
2580 header
->dwFlags
|= WHDR_INQUEUE
;
2582 hr
= WINMM_BeginPlaying(device
);
2584 LeaveCriticalSection(&device
->lock
);
2585 return MMSYSERR_ERROR
;
2588 LeaveCriticalSection(&device
->lock
);
2590 return MMSYSERR_NOERROR
;
2593 /**************************************************************************
2594 * waveOutBreakLoop [WINMM.@]
2596 UINT WINAPI
waveOutBreakLoop(HWAVEOUT hWaveOut
)
2598 WINMM_Device
*device
;
2600 TRACE("(%p)\n", hWaveOut
);
2602 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveOut
);
2604 if(!WINMM_ValidateAndLock(device
))
2605 return MMSYSERR_INVALHANDLE
;
2607 device
->loop_counter
= 0;
2609 LeaveCriticalSection(&device
->lock
);
2611 return MMSYSERR_NOERROR
;
2614 /**************************************************************************
2615 * waveOutPause [WINMM.@]
2617 UINT WINAPI
waveOutPause(HWAVEOUT hWaveOut
)
2619 TRACE("(%p)\n", hWaveOut
);
2621 return WINMM_Pause((HWAVE
)hWaveOut
);
2624 /**************************************************************************
2625 * waveOutReset [WINMM.@]
2627 UINT WINAPI
waveOutReset(HWAVEOUT hWaveOut
)
2629 TRACE("(%p)\n", hWaveOut
);
2631 return WINMM_Reset((HWAVE
)hWaveOut
);
2634 /**************************************************************************
2635 * waveOutRestart [WINMM.@]
2637 UINT WINAPI
waveOutRestart(HWAVEOUT hWaveOut
)
2639 WINMM_Device
*device
;
2642 TRACE("(%p)\n", hWaveOut
);
2644 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveOut
);
2646 if(!WINMM_ValidateAndLock(device
))
2647 return MMSYSERR_INVALHANDLE
;
2649 device
->stopped
= TRUE
;
2651 hr
= WINMM_BeginPlaying(device
);
2653 LeaveCriticalSection(&device
->lock
);
2654 return MMSYSERR_ERROR
;
2657 LeaveCriticalSection(&device
->lock
);
2659 return MMSYSERR_NOERROR
;
2662 /**************************************************************************
2663 * waveOutGetPosition [WINMM.@]
2665 UINT WINAPI
waveOutGetPosition(HWAVEOUT hWaveOut
, LPMMTIME lpTime
,
2668 TRACE("(%p, %p, %u)\n", hWaveOut
, lpTime
, uSize
);
2670 if(!uSize
|| !lpTime
|| uSize
!= sizeof(MMTIME
))
2671 return MMSYSERR_INVALPARAM
;
2673 return WINMM_GetPosition((HWAVE
)hWaveOut
, lpTime
);
2676 /**************************************************************************
2677 * waveOutGetPitch [WINMM.@]
2679 UINT WINAPI
waveOutGetPitch(HWAVEOUT hWaveOut
, LPDWORD lpdw
)
2681 TRACE("(%p, %p)\n", hWaveOut
, lpdw
);
2682 return MMSYSERR_NOTSUPPORTED
;
2685 /**************************************************************************
2686 * waveOutSetPitch [WINMM.@]
2688 UINT WINAPI
waveOutSetPitch(HWAVEOUT hWaveOut
, DWORD dw
)
2690 TRACE("(%p, %08x)\n", hWaveOut
, dw
);
2692 return MMSYSERR_NOTSUPPORTED
;
2695 /**************************************************************************
2696 * waveOutGetPlaybackRate [WINMM.@]
2698 UINT WINAPI
waveOutGetPlaybackRate(HWAVEOUT hWaveOut
, LPDWORD lpdw
)
2700 TRACE("(%p, %p)\n", hWaveOut
, lpdw
);
2702 return MMSYSERR_NOTSUPPORTED
;
2705 /**************************************************************************
2706 * waveOutSetPlaybackRate [WINMM.@]
2708 UINT WINAPI
waveOutSetPlaybackRate(HWAVEOUT hWaveOut
, DWORD dw
)
2710 TRACE("(%p, %08x)\n", hWaveOut
, dw
);
2712 return MMSYSERR_NOTSUPPORTED
;
2715 /**************************************************************************
2716 * waveOutGetVolume [WINMM.@]
2718 UINT WINAPI
waveOutGetVolume(HWAVEOUT hWaveOut
, DWORD
*out
)
2720 WINMM_Device
*device
;
2725 TRACE("(%p, %p)\n", hWaveOut
, out
);
2728 return MMSYSERR_INVALPARAM
;
2730 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveOut
);
2732 if(!WINMM_ValidateAndLock(device
))
2733 return MMSYSERR_INVALHANDLE
;
2735 hr
= IAudioStreamVolume_GetChannelCount(device
->volume
, &channels
);
2737 LeaveCriticalSection(&device
->lock
);
2738 WARN("GetChannelCount failed: %08x\n", hr
);
2739 return MMSYSERR_ERROR
;
2742 vols
= HeapAlloc(GetProcessHeap(), 0, sizeof(float) * channels
);
2744 LeaveCriticalSection(&device
->lock
);
2745 return MMSYSERR_NOMEM
;
2748 hr
= IAudioStreamVolume_GetAllVolumes(device
->volume
, channels
, vols
);
2750 LeaveCriticalSection(&device
->lock
);
2751 HeapFree(GetProcessHeap(), 0, vols
);
2752 WARN("GetAllVolumes failed: %08x\n", hr
);
2753 return MMSYSERR_ERROR
;
2756 LeaveCriticalSection(&device
->lock
);
2758 *out
= ((UINT16
)(vols
[0] * (DWORD
)0xFFFF));
2760 *out
|= ((UINT16
)(vols
[1] * (DWORD
)0xFFFF)) << 16;
2762 HeapFree(GetProcessHeap(), 0, vols
);
2764 return MMSYSERR_NOERROR
;
2767 /**************************************************************************
2768 * waveOutSetVolume [WINMM.@]
2770 UINT WINAPI
waveOutSetVolume(HWAVEOUT hWaveOut
, DWORD in
)
2772 WINMM_Device
*device
;
2777 TRACE("(%p, %08x)\n", hWaveOut
, in
);
2779 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveOut
);
2781 if(!WINMM_ValidateAndLock(device
))
2782 return MMSYSERR_INVALHANDLE
;
2784 hr
= IAudioStreamVolume_GetChannelCount(device
->volume
, &channels
);
2786 LeaveCriticalSection(&device
->lock
);
2787 WARN("GetChannelCount failed: %08x\n", hr
);
2788 return MMSYSERR_ERROR
;
2791 vols
= HeapAlloc(GetProcessHeap(), 0, sizeof(float) * channels
);
2793 LeaveCriticalSection(&device
->lock
);
2794 return MMSYSERR_NOMEM
;
2797 hr
= IAudioStreamVolume_GetAllVolumes(device
->volume
, channels
, vols
);
2799 LeaveCriticalSection(&device
->lock
);
2800 HeapFree(GetProcessHeap(), 0, vols
);
2801 WARN("GetAllVolumes failed: %08x\n", hr
);
2802 return MMSYSERR_ERROR
;
2805 vols
[0] = (float)((DWORD
)(in
& 0xFFFF) / (float)0xFFFF);
2807 vols
[1] = (float)((DWORD
)(in
>> 16) / (float)0xFFFF);
2809 hr
= IAudioStreamVolume_SetAllVolumes(device
->volume
, channels
, vols
);
2811 LeaveCriticalSection(&device
->lock
);
2812 HeapFree(GetProcessHeap(), 0, vols
);
2813 WARN("SetAllVolumes failed: %08x\n", hr
);
2814 return MMSYSERR_ERROR
;
2817 LeaveCriticalSection(&device
->lock
);
2819 HeapFree(GetProcessHeap(), 0, vols
);
2821 return MMSYSERR_NOERROR
;
2824 /**************************************************************************
2825 * waveOutGetID [WINMM.@]
2827 UINT WINAPI
waveOutGetID(HWAVEOUT hWaveOut
, UINT
* lpuDeviceID
)
2829 WINMM_Device
*device
;
2833 TRACE("(%p, %p)\n", hWaveOut
, lpuDeviceID
);
2836 return MMSYSERR_INVALPARAM
;
2838 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveOut
);
2839 if(!WINMM_ValidateAndLock(device
))
2840 return MMSYSERR_INVALHANDLE
;
2842 LeaveCriticalSection(&device
->lock
);
2844 WINMM_DecomposeHWAVE((HWAVE
)hWaveOut
, lpuDeviceID
, &is_out
, &dev
, &junk
);
2846 return MMSYSERR_NOERROR
;
2849 static UINT
WINMM_QueryInstanceIDSize(UINT device
, DWORD_PTR
*len
, BOOL is_out
)
2852 WINMM_MMDevice
*devices
;
2854 TRACE("(%u, %p, %d)\n", device
, len
, is_out
);
2857 count
= g_outmmdevices_count
;
2858 devices
= g_out_mmdevices
;
2860 count
= g_inmmdevices_count
;
2861 devices
= g_in_mmdevices
;
2865 return MMSYSERR_INVALHANDLE
;
2867 *len
= (lstrlenW(devices
[device
].dev_id
) + 1) * sizeof(WCHAR
);
2869 return MMSYSERR_NOERROR
;
2872 static UINT
WINMM_QueryInstanceID(UINT device
, WCHAR
*str
, DWORD_PTR len
,
2876 WINMM_MMDevice
*devices
;
2878 TRACE("(%u, %p, %d)\n", device
, str
, is_out
);
2881 count
= g_outmmdevices_count
;
2882 devices
= g_out_mmdevices
;
2884 count
= g_inmmdevices_count
;
2885 devices
= g_in_mmdevices
;
2889 return MMSYSERR_INVALHANDLE
;
2891 id_len
= (lstrlenW(devices
[device
].dev_id
) + 1) * sizeof(WCHAR
);
2893 return MMSYSERR_ERROR
;
2895 memcpy(str
, devices
[device
].dev_id
, id_len
);
2897 return MMSYSERR_NOERROR
;
2900 static UINT
get_device_interface(UINT msg
, BOOL is_out
, UINT index
, WCHAR
*out
, ULONG
*out_len
)
2902 WINMM_QueryInterfaceInfo info
;
2904 if(!WINMM_StartDevicesThread())
2905 return MMSYSERR_ERROR
;
2907 info
.is_out
= is_out
;
2910 info
.len_bytes
= out_len
;
2912 return SendMessageW(g_devices_hwnd
, msg
, (DWORD_PTR
)&info
, 0);
2915 /**************************************************************************
2916 * waveOutMessage [WINMM.@]
2918 UINT WINAPI
waveOutMessage(HWAVEOUT hWaveOut
, UINT uMessage
,
2919 DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2921 TRACE("(%p, %u, %lx, %lx)\n", hWaveOut
, uMessage
, dwParam1
, dwParam2
);
2924 case DRV_QUERYFUNCTIONINSTANCEIDSIZE
:
2925 return WINMM_QueryInstanceIDSize(HandleToULong(hWaveOut
),
2926 (DWORD_PTR
*)dwParam1
, TRUE
);
2927 case DRV_QUERYFUNCTIONINSTANCEID
:
2928 return WINMM_QueryInstanceID(HandleToULong(hWaveOut
), (WCHAR
*)dwParam1
, dwParam2
, TRUE
);
2929 case DRV_QUERYDEVICEINTERFACESIZE
:
2930 return get_device_interface(DRV_QUERYDEVICEINTERFACESIZE
, TRUE
, HandleToULong(hWaveOut
),
2931 NULL
, (ULONG
*)dwParam1
);
2932 case DRV_QUERYDEVICEINTERFACE
:
2934 ULONG size
= dwParam2
;
2935 return get_device_interface(DRV_QUERYDEVICEINTERFACE
, TRUE
, HandleToULong(hWaveOut
),
2936 (WCHAR
*)dwParam1
, &size
);
2938 case DRV_QUERYMAPPABLE
:
2939 return MMSYSERR_NOERROR
;
2940 case DRVM_MAPPER_PREFERRED_GET
:
2942 if(g_outmmdevices_count
> 0)
2943 /* Device 0 is always the default device */
2944 *(DWORD
*)dwParam1
= 0;
2946 *(DWORD
*)dwParam1
= -1;
2951 *(DWORD
*)dwParam2
= 0;
2953 return MMSYSERR_NOERROR
;
2956 TRACE("Message not supported: %u\n", uMessage
);
2958 return MMSYSERR_NOTSUPPORTED
;
2961 /**************************************************************************
2962 * waveInGetNumDevs [WINMM.@]
2964 UINT WINAPI
waveInGetNumDevs(void)
2966 HRESULT hr
= WINMM_InitMMDevices();
2970 TRACE("count: %u\n", g_inmmdevices_count
);
2972 return g_inmmdevices_count
;
2975 /**************************************************************************
2976 * waveInGetDevCapsW [WINMM.@]
2978 UINT WINAPI
waveInGetDevCapsW(UINT_PTR uDeviceID
, LPWAVEINCAPSW lpCaps
, UINT uSize
)
2980 WAVEINCAPSW mapper_caps
, *caps
;
2983 TRACE("(%lu, %p, %u)\n", uDeviceID
, lpCaps
, uSize
);
2985 hr
= WINMM_InitMMDevices();
2987 return MMSYSERR_ERROR
;
2990 return MMSYSERR_INVALPARAM
;
2992 if(WINMM_IsMapper(uDeviceID
)){
2993 /* FIXME: Should be localized */
2994 static const WCHAR mapper_pnameW
[] = {'W','i','n','e',' ','S','o','u',
2995 'n','d',' ','M','a','p','p','e','r',0};
2997 mapper_caps
.wMid
= 0xFF;
2998 mapper_caps
.wPid
= 0xFF;
2999 mapper_caps
.vDriverVersion
= 0x00010001;
3000 mapper_caps
.dwFormats
= 0xFFFFFFFF;
3001 mapper_caps
.wReserved1
= 0;
3002 mapper_caps
.wChannels
= 2;
3003 lstrcpyW(mapper_caps
.szPname
, mapper_pnameW
);
3005 caps
= &mapper_caps
;
3007 if(uDeviceID
>= g_inmmdevices_count
)
3008 return MMSYSERR_BADDEVICEID
;
3010 caps
= &g_in_mmdevices
[uDeviceID
].in_caps
;
3013 memcpy(lpCaps
, caps
, min(uSize
, sizeof(*lpCaps
)));
3015 return MMSYSERR_NOERROR
;
3018 /**************************************************************************
3019 * waveInGetDevCapsA [WINMM.@]
3021 UINT WINAPI
waveInGetDevCapsA(UINT_PTR uDeviceID
, LPWAVEINCAPSA lpCaps
, UINT uSize
)
3026 TRACE("(%lu, %p, %u)\n", uDeviceID
, lpCaps
, uSize
);
3029 return MMSYSERR_INVALPARAM
;
3031 ret
= waveInGetDevCapsW(uDeviceID
, &wicW
, sizeof(wicW
));
3033 if (ret
== MMSYSERR_NOERROR
) {
3035 wicA
.wMid
= wicW
.wMid
;
3036 wicA
.wPid
= wicW
.wPid
;
3037 wicA
.vDriverVersion
= wicW
.vDriverVersion
;
3038 WideCharToMultiByte( CP_ACP
, 0, wicW
.szPname
, -1, wicA
.szPname
,
3039 sizeof(wicA
.szPname
), NULL
, NULL
);
3040 wicA
.dwFormats
= wicW
.dwFormats
;
3041 wicA
.wChannels
= wicW
.wChannels
;
3042 memcpy(lpCaps
, &wicA
, min(uSize
, sizeof(wicA
)));
3047 /**************************************************************************
3048 * waveInOpen [WINMM.@]
3050 MMRESULT WINAPI
waveInOpen(HWAVEIN
* lphWaveIn
, UINT uDeviceID
,
3051 LPCWAVEFORMATEX lpFormat
, DWORD_PTR dwCallback
,
3052 DWORD_PTR dwInstance
, DWORD dwFlags
)
3055 WINMM_OpenInfo info
;
3056 WINMM_CBInfo cb_info
;
3058 TRACE("(%p, %x, %p, %lx, %lx, %08x)\n", lphWaveIn
, uDeviceID
, lpFormat
,
3059 dwCallback
, dwInstance
, dwFlags
);
3061 if(!WINMM_StartDevicesThread())
3062 return MMSYSERR_ERROR
;
3064 if(!lphWaveIn
&& !(dwFlags
& WAVE_FORMAT_QUERY
))
3065 return MMSYSERR_INVALPARAM
;
3067 res
= WINMM_CheckCallback(dwCallback
, dwFlags
, FALSE
);
3068 if(res
!= MMSYSERR_NOERROR
)
3071 info
.format
= (WAVEFORMATEX
*)lpFormat
;
3072 info
.callback
= dwCallback
;
3073 info
.cb_user
= dwInstance
;
3074 info
.req_device
= uDeviceID
;
3075 info
.flags
= dwFlags
;
3077 res
= SendMessageW(g_devices_hwnd
, WIDM_OPEN
, (DWORD_PTR
)&info
, 0);
3078 if(res
!= MMSYSERR_NOERROR
)
3082 *lphWaveIn
= (HWAVEIN
)info
.handle
;
3084 cb_info
.flags
= HIWORD(dwFlags
& CALLBACK_TYPEMASK
);
3085 cb_info
.callback
= dwCallback
;
3086 cb_info
.user
= dwInstance
;
3087 cb_info
.hwave
= info
.handle
;
3089 WINMM_NotifyClient(&cb_info
, WIM_OPEN
, 0, 0);
3094 /**************************************************************************
3095 * waveInClose [WINMM.@]
3097 UINT WINAPI
waveInClose(HWAVEIN hWaveIn
)
3099 WINMM_Device
*device
;
3100 WINMM_CBInfo cb_info
;
3103 TRACE("(%p)\n", hWaveIn
);
3105 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveIn
);
3107 if(!WINMM_ValidateAndLock(device
))
3108 return MMSYSERR_INVALHANDLE
;
3110 cb_info
= device
->cb_info
;
3112 LeaveCriticalSection(&device
->lock
);
3114 res
= SendMessageW(g_devices_hwnd
, WIDM_CLOSE
, (WPARAM
)hWaveIn
, 0);
3116 if(res
== MMSYSERR_NOERROR
)
3117 WINMM_NotifyClient(&cb_info
, WIM_CLOSE
, 0, 0);
3122 /**************************************************************************
3123 * waveInPrepareHeader [WINMM.@]
3125 UINT WINAPI
waveInPrepareHeader(HWAVEIN hWaveIn
, WAVEHDR
* lpWaveInHdr
,
3128 TRACE("(%p, %p, %u)\n", hWaveIn
, lpWaveInHdr
, uSize
);
3130 if(!lpWaveInHdr
|| uSize
< sizeof(WAVEHDR
))
3131 return MMSYSERR_INVALPARAM
;
3133 if(lpWaveInHdr
->dwFlags
& WHDR_INQUEUE
)
3134 return WAVERR_STILLPLAYING
;
3136 return WINMM_PrepareHeader((HWAVE
)hWaveIn
, lpWaveInHdr
);
3139 /**************************************************************************
3140 * waveInUnprepareHeader [WINMM.@]
3142 UINT WINAPI
waveInUnprepareHeader(HWAVEIN hWaveIn
, WAVEHDR
* lpWaveInHdr
,
3145 TRACE("(%p, %p, %u)\n", hWaveIn
, lpWaveInHdr
, uSize
);
3147 if(!lpWaveInHdr
|| uSize
< sizeof(WAVEHDR
))
3148 return MMSYSERR_INVALPARAM
;
3150 if(!(lpWaveInHdr
->dwFlags
& WHDR_PREPARED
))
3151 return MMSYSERR_NOERROR
;
3153 if(lpWaveInHdr
->dwFlags
& WHDR_INQUEUE
)
3154 return WAVERR_STILLPLAYING
;
3156 return WINMM_UnprepareHeader((HWAVE
)hWaveIn
, lpWaveInHdr
);
3159 /**************************************************************************
3160 * waveInAddBuffer [WINMM.@]
3162 UINT WINAPI
waveInAddBuffer(HWAVEIN hWaveIn
, WAVEHDR
*header
, UINT uSize
)
3164 WINMM_Device
*device
;
3166 TRACE("(%p, %p, %u)\n", hWaveIn
, header
, uSize
);
3168 if(!header
|| uSize
< sizeof(WAVEHDR
))
3169 return MMSYSERR_INVALPARAM
;
3171 if(!(header
->dwFlags
& WHDR_PREPARED
))
3172 return WAVERR_UNPREPARED
;
3174 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveIn
);
3176 if(!WINMM_ValidateAndLock(device
))
3177 return MMSYSERR_INVALHANDLE
;
3180 device
->first
= device
->last
= header
;
3182 device
->last
->lpNext
= header
;
3183 device
->last
= header
;
3186 header
->dwBytesRecorded
= 0;
3187 header
->lpNext
= NULL
;
3188 header
->dwFlags
&= ~WHDR_DONE
;
3189 header
->dwFlags
|= WHDR_INQUEUE
;
3191 LeaveCriticalSection(&device
->lock
);
3193 return MMSYSERR_NOERROR
;
3196 /**************************************************************************
3197 * waveInReset [WINMM.@]
3199 UINT WINAPI
waveInReset(HWAVEIN hWaveIn
)
3201 TRACE("(%p)\n", hWaveIn
);
3203 return WINMM_Reset((HWAVE
)hWaveIn
);
3206 /**************************************************************************
3207 * waveInStart [WINMM.@]
3209 UINT WINAPI
waveInStart(HWAVEIN hWaveIn
)
3211 WINMM_Device
*device
;
3214 TRACE("(%p)\n", hWaveIn
);
3216 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveIn
);
3218 if(!WINMM_ValidateAndLock(device
))
3219 return MMSYSERR_INVALHANDLE
;
3221 hr
= WINMM_BeginPlaying(device
);
3223 LeaveCriticalSection(&device
->lock
);
3224 return MMSYSERR_ERROR
;
3227 LeaveCriticalSection(&device
->lock
);
3229 return MMSYSERR_NOERROR
;
3232 /**************************************************************************
3233 * waveInStop [WINMM.@]
3235 UINT WINAPI
waveInStop(HWAVEIN hWaveIn
)
3237 WINMM_CBInfo cb_info
;
3238 WINMM_Device
*device
;
3242 TRACE("(%p)\n", hWaveIn
);
3244 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveIn
);
3246 if(!WINMM_ValidateAndLock(device
))
3247 return MMSYSERR_INVALHANDLE
;
3249 hr
= WINMM_Pause((HWAVE
)hWaveIn
);
3251 LeaveCriticalSection(&device
->lock
);
3252 return MMSYSERR_ERROR
;
3254 device
->stopped
= TRUE
;
3256 buf
= device
->first
;
3257 if(buf
&& buf
->dwBytesRecorded
> 0){
3258 device
->first
= buf
->lpNext
;
3262 cb_info
= device
->cb_info
;
3264 LeaveCriticalSection(&device
->lock
);
3267 buf
->dwFlags
&= ~WHDR_INQUEUE
;
3268 buf
->dwFlags
|= WHDR_DONE
;
3269 WINMM_NotifyClient(&cb_info
, WIM_DATA
, (DWORD_PTR
)buf
, 0);
3272 return MMSYSERR_NOERROR
;
3275 /**************************************************************************
3276 * waveInGetPosition [WINMM.@]
3278 UINT WINAPI
waveInGetPosition(HWAVEIN hWaveIn
, LPMMTIME lpTime
,
3281 TRACE("(%p, %p, %u)\n", hWaveIn
, lpTime
, uSize
);
3283 if(!uSize
|| !lpTime
|| uSize
!= sizeof(MMTIME
))
3284 return MMSYSERR_INVALPARAM
;
3286 return WINMM_GetPosition((HWAVE
)hWaveIn
, lpTime
);
3289 /**************************************************************************
3290 * waveInGetID [WINMM.@]
3292 UINT WINAPI
waveInGetID(HWAVEIN hWaveIn
, UINT
* lpuDeviceID
)
3296 WINMM_Device
*device
;
3298 TRACE("(%p, %p)\n", hWaveIn
, lpuDeviceID
);
3301 return MMSYSERR_INVALPARAM
;
3303 device
= WINMM_GetDeviceFromHWAVE((HWAVE
)hWaveIn
);
3304 if(!WINMM_ValidateAndLock(device
))
3305 return MMSYSERR_INVALHANDLE
;
3307 LeaveCriticalSection(&device
->lock
);
3309 WINMM_DecomposeHWAVE((HWAVE
)hWaveIn
, lpuDeviceID
, &is_out
, &dev
, &junk
);
3311 return MMSYSERR_NOERROR
;
3314 /**************************************************************************
3315 * waveInMessage [WINMM.@]
3317 UINT WINAPI
waveInMessage(HWAVEIN hWaveIn
, UINT uMessage
,
3318 DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
3320 TRACE("(%p, %u, %ld, %ld)\n", hWaveIn
, uMessage
, dwParam1
, dwParam2
);
3323 case DRV_QUERYFUNCTIONINSTANCEIDSIZE
:
3324 return WINMM_QueryInstanceIDSize(HandleToULong(hWaveIn
),
3325 (DWORD_PTR
*)dwParam1
, FALSE
);
3326 case DRV_QUERYFUNCTIONINSTANCEID
:
3327 return WINMM_QueryInstanceID(HandleToULong(hWaveIn
), (WCHAR
*)dwParam1
, dwParam2
, FALSE
);
3328 case DRV_QUERYDEVICEINTERFACESIZE
:
3329 return get_device_interface(DRV_QUERYDEVICEINTERFACESIZE
, FALSE
, HandleToULong(hWaveIn
),
3330 NULL
, (ULONG
*)dwParam1
);
3331 case DRV_QUERYDEVICEINTERFACE
:
3333 ULONG size
= dwParam2
;
3334 return get_device_interface(DRV_QUERYDEVICEINTERFACE
, FALSE
, HandleToULong(hWaveIn
),
3335 (WCHAR
*)dwParam1
, &size
);
3337 case DRV_QUERYMAPPABLE
:
3338 return MMSYSERR_NOERROR
;
3339 case DRVM_MAPPER_PREFERRED_GET
:
3341 if(g_inmmdevices_count
> 0)
3342 /* Device 0 is always the default device */
3343 *(DWORD
*)dwParam1
= 0;
3345 *(DWORD
*)dwParam1
= -1;
3350 *(DWORD
*)dwParam2
= 0;
3352 return MMSYSERR_NOERROR
;
3355 TRACE("Message not supported: %u\n", uMessage
);
3357 return MMSYSERR_NOTSUPPORTED
;
3360 UINT WINAPI
mixerGetNumDevs(void)
3366 hr
= WINMM_InitMMDevices();
3370 return g_outmmdevices_count
+ g_inmmdevices_count
;
3373 /**************************************************************************
3374 * mixerGetDevCapsA [WINMM.@]
3376 UINT WINAPI
mixerGetDevCapsA(UINT_PTR uDeviceID
, LPMIXERCAPSA lpCaps
, UINT uSize
)
3381 TRACE("(%lu, %p, %u)\n", uDeviceID
, lpCaps
, uSize
);
3384 return MMSYSERR_INVALPARAM
;
3386 ret
= mixerGetDevCapsW(uDeviceID
, &micW
, sizeof(micW
));
3388 if (ret
== MMSYSERR_NOERROR
) {
3390 micA
.wMid
= micW
.wMid
;
3391 micA
.wPid
= micW
.wPid
;
3392 micA
.vDriverVersion
= micW
.vDriverVersion
;
3393 WideCharToMultiByte( CP_ACP
, 0, micW
.szPname
, -1, micA
.szPname
,
3394 sizeof(micA
.szPname
), NULL
, NULL
);
3395 micA
.fdwSupport
= micW
.fdwSupport
;
3396 micA
.cDestinations
= micW
.cDestinations
;
3397 memcpy(lpCaps
, &micA
, min(uSize
, sizeof(micA
)));
3402 /**************************************************************************
3403 * mixerGetDevCapsW [WINMM.@]
3405 UINT WINAPI
mixerGetDevCapsW(UINT_PTR uDeviceID
, LPMIXERCAPSW lpCaps
, UINT uSize
)
3407 WINMM_MMDevice
*mmdevice
;
3411 TRACE("(%lu, %p, %u)\n", uDeviceID
, lpCaps
, uSize
);
3413 hr
= WINMM_InitMMDevices();
3415 return MMSYSERR_ERROR
;
3418 return MMSYSERR_INVALPARAM
;
3421 return MMSYSERR_NOERROR
;
3423 if(uDeviceID
>= g_outmmdevices_count
+ g_inmmdevices_count
)
3424 return MMSYSERR_BADDEVICEID
;
3426 if(uDeviceID
< g_outmmdevices_count
){
3427 mmdevice
= &g_out_mmdevices
[uDeviceID
];
3428 memcpy(caps
.szPname
, mmdevice
->out_caps
.szPname
, sizeof(caps
.szPname
));
3430 mmdevice
= &g_in_mmdevices
[uDeviceID
- g_outmmdevices_count
];
3431 memcpy(caps
.szPname
, mmdevice
->in_caps
.szPname
, sizeof(caps
.szPname
));
3436 caps
.vDriverVersion
= 0x00010001;
3437 caps
.fdwSupport
= 0;
3438 caps
.cDestinations
= 1;
3440 memcpy(lpCaps
, &caps
, uSize
);
3442 return MMSYSERR_NOERROR
;
3445 /**************************************************************************
3446 * mixerOpen [WINMM.@]
3448 UINT WINAPI
mixerOpen(LPHMIXER lphMix
, UINT uDeviceID
, DWORD_PTR dwCallback
,
3449 DWORD_PTR dwInstance
, DWORD fdwOpen
)
3451 WINMM_MMDevice
*mmdevice
;
3455 TRACE("(%p, %d, %lx, %lx, %x)\n", lphMix
, uDeviceID
, dwCallback
,
3456 dwInstance
, fdwOpen
);
3458 hr
= WINMM_InitMMDevices();
3460 return MMSYSERR_ERROR
;
3463 return MMSYSERR_INVALPARAM
;
3465 mr
= WINMM_CheckCallback(dwCallback
, fdwOpen
, TRUE
);
3466 if(mr
!= 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 *lphMix
= (HMIXER
)WINMM_MakeHWAVE(uDeviceID
, TRUE
,
3475 mmdevice
->mixer_count
);
3477 mmdevice
= &g_in_mmdevices
[uDeviceID
- g_outmmdevices_count
];
3478 *lphMix
= (HMIXER
)WINMM_MakeHWAVE(uDeviceID
- g_outmmdevices_count
,
3479 FALSE
, mmdevice
->mixer_count
);
3482 ++mmdevice
->mixer_count
;
3484 return MMSYSERR_NOERROR
;
3487 /**************************************************************************
3488 * mixerClose [WINMM.@]
3490 UINT WINAPI
mixerClose(HMIXER hMix
)
3492 TRACE("(%p)\n", hMix
);
3494 return MMSYSERR_NOERROR
;
3497 /**************************************************************************
3498 * mixerGetID [WINMM.@]
3500 UINT WINAPI
mixerGetID(HMIXEROBJ hmix
, LPUINT lpid
, DWORD fdwID
)
3502 WINMM_MMDevice
*mmdevice
;
3505 TRACE("(%p, %p, %x)\n", hmix
, lpid
, fdwID
);
3507 hr
= WINMM_InitMMDevices();
3509 return MMSYSERR_ERROR
;
3512 return MMSYSERR_INVALPARAM
;
3514 mmdevice
= WINMM_GetMixerMMDevice(hmix
, fdwID
, lpid
);
3516 return MMSYSERR_INVALHANDLE
;
3518 if(mmdevice
->in_caps
.szPname
[0] != '\0')
3519 *lpid
+= g_outmmdevices_count
;
3521 return MMSYSERR_NOERROR
;
3524 /**************************************************************************
3525 * mixerGetControlDetailsW [WINMM.@]
3527 UINT WINAPI
mixerGetControlDetailsW(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcdW
,
3530 WINMM_ControlDetails details
;
3533 TRACE("(%p, %p, %x)\n", hmix
, lpmcdW
, fdwDetails
);
3535 hr
= WINMM_InitMMDevices();
3537 return MMSYSERR_ERROR
;
3540 return MMSYSERR_INVALPARAM
;
3542 TRACE("dwControlID: %u\n", lpmcdW
->dwControlID
);
3544 details
.hmix
= hmix
;
3545 details
.details
= lpmcdW
;
3546 details
.flags
= fdwDetails
;
3548 return SendMessageW(g_devices_hwnd
, MXDM_GETCONTROLDETAILS
,
3549 (DWORD_PTR
)&details
, 0);
3552 /**************************************************************************
3553 * mixerGetControlDetailsA [WINMM.@]
3555 UINT WINAPI
mixerGetControlDetailsA(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcdA
,
3558 UINT ret
= MMSYSERR_NOTSUPPORTED
;
3560 TRACE("(%p, %p, %08x)\n", hmix
, lpmcdA
, fdwDetails
);
3562 if (lpmcdA
== NULL
|| lpmcdA
->cbStruct
!= sizeof(*lpmcdA
))
3563 return MMSYSERR_INVALPARAM
;
3565 switch (fdwDetails
& MIXER_GETCONTROLDETAILSF_QUERYMASK
) {
3566 case MIXER_GETCONTROLDETAILSF_VALUE
:
3567 /* can safely use A structure as it is, no string inside */
3568 ret
= mixerGetControlDetailsW(hmix
, lpmcdA
, fdwDetails
);
3570 case MIXER_GETCONTROLDETAILSF_LISTTEXT
:
3572 MIXERCONTROLDETAILS_LISTTEXTA
*pDetailsA
= lpmcdA
->paDetails
;
3573 MIXERCONTROLDETAILS_LISTTEXTW
*pDetailsW
;
3574 int size
= max(1, lpmcdA
->cChannels
) * sizeof(MIXERCONTROLDETAILS_LISTTEXTW
);
3577 if (lpmcdA
->u
.cMultipleItems
!= 0) {
3578 size
*= lpmcdA
->u
.cMultipleItems
;
3580 pDetailsW
= HeapAlloc(GetProcessHeap(), 0, size
);
3581 lpmcdA
->paDetails
= pDetailsW
;
3582 lpmcdA
->cbDetails
= sizeof(MIXERCONTROLDETAILS_LISTTEXTW
);
3583 /* set up lpmcd->paDetails */
3584 ret
= mixerGetControlDetailsW(hmix
, lpmcdA
, fdwDetails
);
3585 /* copy from lpmcd->paDetails back to paDetailsW; */
3586 if (ret
== MMSYSERR_NOERROR
) {
3587 for (i
= 0; i
< lpmcdA
->u
.cMultipleItems
* lpmcdA
->cChannels
; i
++) {
3588 pDetailsA
->dwParam1
= pDetailsW
->dwParam1
;
3589 pDetailsA
->dwParam2
= pDetailsW
->dwParam2
;
3590 WideCharToMultiByte( CP_ACP
, 0, pDetailsW
->szName
, -1,
3592 sizeof(pDetailsA
->szName
), NULL
, NULL
);
3596 pDetailsA
-= lpmcdA
->u
.cMultipleItems
* lpmcdA
->cChannels
;
3597 pDetailsW
-= lpmcdA
->u
.cMultipleItems
* lpmcdA
->cChannels
;
3599 HeapFree(GetProcessHeap(), 0, pDetailsW
);
3600 lpmcdA
->paDetails
= pDetailsA
;
3601 lpmcdA
->cbDetails
= sizeof(MIXERCONTROLDETAILS_LISTTEXTA
);
3605 WARN("Unsupported fdwDetails=0x%08x\n", fdwDetails
);
3611 /**************************************************************************
3612 * mixerGetLineControlsA [WINMM.@]
3614 UINT WINAPI
mixerGetLineControlsA(HMIXEROBJ hmix
, LPMIXERLINECONTROLSA lpmlcA
,
3617 MIXERLINECONTROLSW mlcW
;
3621 TRACE("(%p, %p, %x)\n", hmix
, lpmlcA
, fdwControls
);
3623 if (lpmlcA
== NULL
|| lpmlcA
->cbStruct
!= sizeof(*lpmlcA
) ||
3624 lpmlcA
->cbmxctrl
!= sizeof(MIXERCONTROLA
))
3625 return MMSYSERR_INVALPARAM
;
3627 mlcW
.cbStruct
= sizeof(mlcW
);
3628 mlcW
.dwLineID
= lpmlcA
->dwLineID
;
3629 mlcW
.u
.dwControlID
= lpmlcA
->u
.dwControlID
;
3630 mlcW
.u
.dwControlType
= lpmlcA
->u
.dwControlType
;
3632 /* Debugging on Windows shows for MIXER_GETLINECONTROLSF_ONEBYTYPE only,
3633 the control count is assumed to be 1 - This is relied upon by a game,
3634 "Dynomite Deluze" */
3635 if (MIXER_GETLINECONTROLSF_ONEBYTYPE
== (fdwControls
& MIXER_GETLINECONTROLSF_QUERYMASK
)) {
3638 mlcW
.cControls
= lpmlcA
->cControls
;
3640 mlcW
.cbmxctrl
= sizeof(MIXERCONTROLW
);
3641 mlcW
.pamxctrl
= HeapAlloc(GetProcessHeap(), 0,
3642 mlcW
.cControls
* mlcW
.cbmxctrl
);
3644 ret
= mixerGetLineControlsW(hmix
, &mlcW
, fdwControls
);
3646 if (ret
== MMSYSERR_NOERROR
) {
3647 lpmlcA
->dwLineID
= mlcW
.dwLineID
;
3648 lpmlcA
->u
.dwControlID
= mlcW
.u
.dwControlID
;
3649 lpmlcA
->u
.dwControlType
= mlcW
.u
.dwControlType
;
3651 for (i
= 0; i
< mlcW
.cControls
; i
++) {
3652 lpmlcA
->pamxctrl
[i
].cbStruct
= sizeof(MIXERCONTROLA
);
3653 lpmlcA
->pamxctrl
[i
].dwControlID
= mlcW
.pamxctrl
[i
].dwControlID
;
3654 lpmlcA
->pamxctrl
[i
].dwControlType
= mlcW
.pamxctrl
[i
].dwControlType
;
3655 lpmlcA
->pamxctrl
[i
].fdwControl
= mlcW
.pamxctrl
[i
].fdwControl
;
3656 lpmlcA
->pamxctrl
[i
].cMultipleItems
= mlcW
.pamxctrl
[i
].cMultipleItems
;
3657 WideCharToMultiByte( CP_ACP
, 0, mlcW
.pamxctrl
[i
].szShortName
, -1,
3658 lpmlcA
->pamxctrl
[i
].szShortName
,
3659 sizeof(lpmlcA
->pamxctrl
[i
].szShortName
), NULL
, NULL
);
3660 WideCharToMultiByte( CP_ACP
, 0, mlcW
.pamxctrl
[i
].szName
, -1,
3661 lpmlcA
->pamxctrl
[i
].szName
,
3662 sizeof(lpmlcA
->pamxctrl
[i
].szName
), NULL
, NULL
);
3663 /* sizeof(lpmlcA->pamxctrl[i].Bounds) ==
3664 * sizeof(mlcW.pamxctrl[i].Bounds) */
3665 memcpy(&lpmlcA
->pamxctrl
[i
].Bounds
, &mlcW
.pamxctrl
[i
].Bounds
,
3666 sizeof(mlcW
.pamxctrl
[i
].Bounds
));
3667 /* sizeof(lpmlcA->pamxctrl[i].Metrics) ==
3668 * sizeof(mlcW.pamxctrl[i].Metrics) */
3669 memcpy(&lpmlcA
->pamxctrl
[i
].Metrics
, &mlcW
.pamxctrl
[i
].Metrics
,
3670 sizeof(mlcW
.pamxctrl
[i
].Metrics
));
3674 HeapFree(GetProcessHeap(), 0, mlcW
.pamxctrl
);
3679 static UINT
WINMM_GetVolumeLineControl(WINMM_MMDevice
*mmdevice
, DWORD line
,
3680 MIXERCONTROLW
*ctl
, DWORD flags
)
3682 ctl
->dwControlID
= (line
== 0xFFFF0000) ? 0 : 2;
3683 ctl
->dwControlType
= MIXERCONTROL_CONTROLTYPE_VOLUME
;
3684 ctl
->fdwControl
= MIXERCONTROL_CONTROLF_UNIFORM
;
3685 ctl
->cMultipleItems
= 0;
3686 lstrcpyW(ctl
->szShortName
, volumeW
);
3687 lstrcpyW(ctl
->szName
, volumeW
);
3688 ctl
->Bounds
.s1
.dwMinimum
= 0;
3689 ctl
->Bounds
.s1
.dwMaximum
= 0xFFFF;
3690 ctl
->Metrics
.cSteps
= 192;
3692 return MMSYSERR_NOERROR
;
3695 static UINT
WINMM_GetMuteLineControl(WINMM_MMDevice
*mmdevice
, DWORD line
,
3696 MIXERCONTROLW
*ctl
, DWORD flags
)
3698 ctl
->dwControlID
= (line
== 0xFFFF0000) ? 1 : 3;
3699 ctl
->dwControlType
= MIXERCONTROL_CONTROLTYPE_MUTE
;
3700 ctl
->fdwControl
= MIXERCONTROL_CONTROLF_UNIFORM
;
3701 ctl
->cMultipleItems
= 0;
3702 lstrcpyW(ctl
->szShortName
, muteW
);
3703 lstrcpyW(ctl
->szName
, muteW
);
3704 ctl
->Bounds
.s1
.dwMinimum
= 0;
3705 ctl
->Bounds
.s1
.dwMaximum
= 1;
3706 ctl
->Metrics
.cSteps
= 0;
3708 return MMSYSERR_NOERROR
;
3711 /**************************************************************************
3712 * mixerGetLineControlsW [WINMM.@]
3714 UINT WINAPI
mixerGetLineControlsW(HMIXEROBJ hmix
, LPMIXERLINECONTROLSW lpmlcW
,
3717 WINMM_MMDevice
*mmdevice
;
3720 TRACE("(%p, %p, %08x)\n", hmix
, lpmlcW
, fdwControls
);
3722 hr
= WINMM_InitMMDevices();
3724 return MMSYSERR_ERROR
;
3726 if(fdwControls
& ~(MIXER_GETLINECONTROLSF_ALL
|
3727 MIXER_GETLINECONTROLSF_ONEBYID
|
3728 MIXER_GETLINECONTROLSF_ONEBYTYPE
|
3729 MIXER_OBJECTF_HMIXER
|
3730 MIXER_OBJECTF_MIXER
)){
3731 WARN("Unknown GetLineControls flag: %x\n", fdwControls
);
3732 return MMSYSERR_INVALFLAG
;
3735 if(!lpmlcW
|| lpmlcW
->cbStruct
< sizeof(*lpmlcW
) || !lpmlcW
->pamxctrl
)
3736 return MMSYSERR_INVALPARAM
;
3738 TRACE("dwLineID: %u\n", lpmlcW
->dwLineID
);
3739 TRACE("dwControl: %x\n", lpmlcW
->u
.dwControlID
);
3740 TRACE("cControls: %u\n", lpmlcW
->cControls
);
3742 mmdevice
= WINMM_GetMixerMMDevice(hmix
, fdwControls
, NULL
);
3744 return MMSYSERR_INVALHANDLE
;
3746 switch(fdwControls
& MIXER_GETLINECONTROLSF_QUERYMASK
){
3747 case MIXER_GETLINECONTROLSF_ALL
:
3748 if(lpmlcW
->cControls
!= 2)
3749 return MMSYSERR_INVALPARAM
;
3750 if(lpmlcW
->cbmxctrl
< sizeof(MIXERCONTROLW
))
3751 return MMSYSERR_INVALPARAM
;
3752 if(lpmlcW
->dwLineID
!= 0 && lpmlcW
->dwLineID
!= 0xFFFF0000)
3753 return MIXERR_INVALLINE
;
3754 WINMM_GetVolumeLineControl(mmdevice
, lpmlcW
->dwLineID
,
3755 &lpmlcW
->pamxctrl
[0], fdwControls
);
3756 WINMM_GetMuteLineControl(mmdevice
, lpmlcW
->dwLineID
,
3757 &lpmlcW
->pamxctrl
[1], fdwControls
);
3758 return MMSYSERR_NOERROR
;
3759 case MIXER_GETLINECONTROLSF_ONEBYID
:
3760 if(lpmlcW
->cControls
!= 1)
3761 return MMSYSERR_INVALPARAM
;
3762 if(lpmlcW
->cbmxctrl
< sizeof(MIXERCONTROLW
))
3763 return MMSYSERR_INVALPARAM
;
3764 if(lpmlcW
->dwLineID
!= 0 && lpmlcW
->dwLineID
!= 0xFFFF0000)
3765 return MIXERR_INVALLINE
;
3766 if(lpmlcW
->u
.dwControlID
== 0)
3767 return WINMM_GetVolumeLineControl(mmdevice
, lpmlcW
->dwLineID
,
3768 lpmlcW
->pamxctrl
, fdwControls
);
3769 if(lpmlcW
->u
.dwControlID
== 1)
3770 return WINMM_GetMuteLineControl(mmdevice
, lpmlcW
->dwLineID
,
3771 lpmlcW
->pamxctrl
, fdwControls
);
3772 return MMSYSERR_NOTSUPPORTED
;
3773 case MIXER_GETLINECONTROLSF_ONEBYTYPE
:
3774 if(lpmlcW
->cControls
!= 1)
3775 return MMSYSERR_INVALPARAM
;
3776 if(lpmlcW
->cbmxctrl
< sizeof(MIXERCONTROLW
))
3777 return MMSYSERR_INVALPARAM
;
3778 if(lpmlcW
->dwLineID
!= 0 && lpmlcW
->dwLineID
!= 0xFFFF0000)
3779 return MIXERR_INVALLINE
;
3780 if(lpmlcW
->u
.dwControlType
== MIXERCONTROL_CONTROLTYPE_VOLUME
)
3781 return WINMM_GetVolumeLineControl(mmdevice
, lpmlcW
->dwLineID
,
3782 lpmlcW
->pamxctrl
, fdwControls
);
3783 if(lpmlcW
->u
.dwControlType
== MIXERCONTROL_CONTROLTYPE_MUTE
)
3784 return WINMM_GetMuteLineControl(mmdevice
, lpmlcW
->dwLineID
,
3785 lpmlcW
->pamxctrl
, fdwControls
);
3786 return MMSYSERR_NOTSUPPORTED
;
3789 return MMSYSERR_NOTSUPPORTED
;
3792 static UINT
WINMM_GetSourceLineInfo(WINMM_MMDevice
*mmdevice
, UINT mmdev_index
,
3793 MIXERLINEW
*info
, DWORD flags
)
3796 if(mmdevice
->in_caps
.szPname
[0] != '\0')
3799 if(info
->dwSource
!= 0)
3800 return MIXERR_INVALLINE
;
3802 info
->dwDestination
= 0;
3804 info
->fdwLine
= MIXERLINE_LINEF_ACTIVE
| MIXERLINE_LINEF_SOURCE
;
3805 info
->cConnections
= 0;
3806 info
->cControls
= 2;
3807 /* volume & mute always affect all channels, so claim 1 channel */
3808 info
->cChannels
= 1;
3809 info
->Target
.dwDeviceID
= mmdev_index
;
3810 info
->Target
.wMid
= ~0;
3811 info
->Target
.wPid
= ~0;
3812 info
->Target
.vDriverVersion
= 0;
3814 lstrcpyW(info
->szShortName
, volumeW
);
3815 lstrcpyW(info
->szName
, mastervolumeW
);
3818 info
->dwComponentType
= MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT
;
3819 info
->Target
.dwType
= MIXERLINE_TARGETTYPE_WAVEOUT
;
3820 memcpy(info
->Target
.szPname
, mmdevice
->out_caps
.szPname
,
3821 sizeof(info
->Target
.szPname
));
3823 info
->dwComponentType
= MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE
;
3824 info
->Target
.dwType
= MIXERLINE_TARGETTYPE_UNDEFINED
;
3825 info
->Target
.szPname
[0] = '\0';
3828 return MMSYSERR_NOERROR
;
3831 static UINT
WINMM_GetDestinationLineInfo(WINMM_MMDevice
*mmdevice
,
3832 UINT mmdev_index
, MIXERLINEW
*info
, DWORD flags
)
3835 if(mmdevice
->in_caps
.szPname
[0] != '\0')
3838 if(info
->dwDestination
!= 0)
3839 return MIXERR_INVALLINE
;
3841 info
->dwSource
= 0xFFFFFFFF;
3842 info
->dwLineID
= 0xFFFF0000;
3843 info
->fdwLine
= MIXERLINE_LINEF_ACTIVE
;
3844 info
->cConnections
= 1;
3845 info
->cControls
= 2;
3847 lstrcpyW(info
->szShortName
, volumeW
);
3848 lstrcpyW(info
->szName
, mastervolumeW
);
3850 info
->Target
.dwDeviceID
= mmdev_index
;
3851 info
->Target
.wMid
= ~0;
3852 info
->Target
.wPid
= ~0;
3853 info
->Target
.vDriverVersion
= 0;
3856 info
->dwComponentType
= MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
;
3857 info
->cChannels
= mmdevice
->out_caps
.wChannels
;
3858 info
->Target
.dwType
= MIXERLINE_TARGETTYPE_UNDEFINED
;
3859 info
->Target
.szPname
[0] = '\0';
3861 info
->dwComponentType
= MIXERLINE_COMPONENTTYPE_DST_WAVEIN
;
3862 info
->cChannels
= mmdevice
->in_caps
.wChannels
;
3863 info
->Target
.dwType
= MIXERLINE_TARGETTYPE_WAVEIN
;
3864 memcpy(info
->Target
.szPname
, mmdevice
->in_caps
.szPname
,
3865 sizeof(info
->Target
.szPname
));
3868 return MMSYSERR_NOERROR
;
3871 static UINT
WINMM_GetComponentTypeLineInfo(WINMM_MMDevice
*mmdevice
,
3872 UINT mmdev_index
, MIXERLINEW
*info
, DWORD flags
)
3875 if(mmdevice
->in_caps
.szPname
[0] != '\0')
3878 if(info
->dwComponentType
== MIXERLINE_COMPONENTTYPE_DST_WAVEIN
){
3880 return MIXERR_INVALLINE
;
3881 info
->dwDestination
= 0;
3882 return WINMM_GetDestinationLineInfo(mmdevice
, mmdev_index
, info
, flags
);
3885 if(info
->dwComponentType
== MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
){
3887 return MIXERR_INVALLINE
;
3888 info
->dwDestination
= 0;
3889 return WINMM_GetDestinationLineInfo(mmdevice
, mmdev_index
, info
, flags
);
3892 if(info
->dwComponentType
== MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE
){
3894 return MIXERR_INVALLINE
;
3896 return WINMM_GetSourceLineInfo(mmdevice
, mmdev_index
, info
, flags
);
3899 if(info
->dwComponentType
== MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT
){
3901 return MIXERR_INVALLINE
;
3903 return WINMM_GetSourceLineInfo(mmdevice
, mmdev_index
, info
, flags
);
3906 TRACE("Returning INVALLINE on this component type: %u\n",
3907 info
->dwComponentType
);
3909 return MIXERR_INVALLINE
;
3912 static UINT
WINMM_GetLineIDLineInfo(WINMM_MMDevice
*mmdevice
,
3913 UINT mmdev_index
, MIXERLINEW
*info
, DWORD flags
)
3915 if(info
->dwLineID
== 0xFFFF0000){
3916 info
->dwDestination
= 0;
3917 return WINMM_GetDestinationLineInfo(mmdevice
, mmdev_index
, info
, flags
);
3920 if(info
->dwLineID
== 0){
3922 return WINMM_GetSourceLineInfo(mmdevice
, mmdev_index
, info
, flags
);
3925 TRACE("Returning INVALLINE on this dwLineID: %u\n", info
->dwLineID
);
3926 return MIXERR_INVALLINE
;
3929 /**************************************************************************
3930 * mixerGetLineInfoW [WINMM.@]
3932 UINT WINAPI
mixerGetLineInfoW(HMIXEROBJ hmix
, LPMIXERLINEW lpmliW
, DWORD fdwInfo
)
3935 WINMM_MMDevice
*mmdevice
;
3938 TRACE("(%p, %p, %x)\n", hmix
, lpmliW
, fdwInfo
);
3940 hr
= WINMM_InitMMDevices();
3942 return MMSYSERR_ERROR
;
3944 if(!lpmliW
|| lpmliW
->cbStruct
< sizeof(MIXERLINEW
))
3945 return MMSYSERR_INVALPARAM
;
3947 TRACE("dwDestination: %u\n", lpmliW
->dwDestination
);
3948 TRACE("dwSource: %u\n", lpmliW
->dwSource
);
3949 TRACE("dwLineID: %u\n", lpmliW
->dwLineID
);
3950 TRACE("fdwLine: 0x%x\n", lpmliW
->fdwLine
);
3951 TRACE("dwComponentType: 0x%x\n", lpmliW
->dwComponentType
);
3953 if(fdwInfo
& ~(MIXER_GETLINEINFOF_COMPONENTTYPE
|
3954 MIXER_GETLINEINFOF_DESTINATION
|
3955 MIXER_GETLINEINFOF_LINEID
|
3956 MIXER_GETLINEINFOF_SOURCE
|
3957 MIXER_GETLINEINFOF_TARGETTYPE
|
3958 MIXER_OBJECTF_HMIXER
|
3959 MIXER_OBJECTF_MIXER
)){
3960 WARN("Unknown GetLineInfo flag: %x\n", fdwInfo
);
3961 return MMSYSERR_INVALFLAG
;
3964 mmdevice
= WINMM_GetMixerMMDevice(hmix
, fdwInfo
, &mmdev_index
);
3966 return MMSYSERR_INVALHANDLE
;
3968 switch(fdwInfo
& MIXER_GETLINEINFOF_QUERYMASK
){
3969 case MIXER_GETLINEINFOF_DESTINATION
:
3970 return WINMM_GetDestinationLineInfo(mmdevice
, mmdev_index
, lpmliW
,
3972 case MIXER_GETLINEINFOF_SOURCE
:
3973 return WINMM_GetSourceLineInfo(mmdevice
, mmdev_index
, lpmliW
, fdwInfo
);
3974 case MIXER_GETLINEINFOF_COMPONENTTYPE
:
3975 return WINMM_GetComponentTypeLineInfo(mmdevice
, mmdev_index
, lpmliW
,
3977 case MIXER_GETLINEINFOF_LINEID
:
3978 return WINMM_GetLineIDLineInfo(mmdevice
, mmdev_index
, lpmliW
, fdwInfo
);
3979 case MIXER_GETLINEINFOF_TARGETTYPE
:
3980 FIXME("TARGETTYPE flag not implemented!\n");
3981 return MIXERR_INVALLINE
;
3984 TRACE("Returning INVALFLAG on these flags: %x\n", fdwInfo
& MIXER_GETLINEINFOF_QUERYMASK
);
3985 return MMSYSERR_INVALFLAG
;
3988 /**************************************************************************
3989 * mixerGetLineInfoA [WINMM.@]
3991 UINT WINAPI
mixerGetLineInfoA(HMIXEROBJ hmix
, LPMIXERLINEA lpmliA
,
3997 TRACE("(%p, %p, %x)\n", hmix
, lpmliA
, fdwInfo
);
3999 if (lpmliA
== NULL
|| lpmliA
->cbStruct
!= sizeof(*lpmliA
))
4000 return MMSYSERR_INVALPARAM
;
4002 mliW
.cbStruct
= sizeof(mliW
);
4003 switch (fdwInfo
& MIXER_GETLINEINFOF_QUERYMASK
) {
4004 case MIXER_GETLINEINFOF_COMPONENTTYPE
:
4005 mliW
.dwComponentType
= lpmliA
->dwComponentType
;
4007 case MIXER_GETLINEINFOF_DESTINATION
:
4008 mliW
.dwDestination
= lpmliA
->dwDestination
;
4010 case MIXER_GETLINEINFOF_LINEID
:
4011 mliW
.dwLineID
= lpmliA
->dwLineID
;
4013 case MIXER_GETLINEINFOF_SOURCE
:
4014 mliW
.dwDestination
= lpmliA
->dwDestination
;
4015 mliW
.dwSource
= lpmliA
->dwSource
;
4017 case MIXER_GETLINEINFOF_TARGETTYPE
:
4018 mliW
.Target
.dwType
= lpmliA
->Target
.dwType
;
4019 mliW
.Target
.wMid
= lpmliA
->Target
.wMid
;
4020 mliW
.Target
.wPid
= lpmliA
->Target
.wPid
;
4021 mliW
.Target
.vDriverVersion
= lpmliA
->Target
.vDriverVersion
;
4022 MultiByteToWideChar( CP_ACP
, 0, lpmliA
->Target
.szPname
, -1, mliW
.Target
.szPname
, sizeof(mliW
.Target
.szPname
)/sizeof(WCHAR
));
4025 WARN("Unsupported fdwControls=0x%08x\n", fdwInfo
);
4026 return MMSYSERR_INVALFLAG
;
4029 ret
= mixerGetLineInfoW(hmix
, &mliW
, fdwInfo
);
4031 if(ret
== MMSYSERR_NOERROR
)
4033 lpmliA
->dwDestination
= mliW
.dwDestination
;
4034 lpmliA
->dwSource
= mliW
.dwSource
;
4035 lpmliA
->dwLineID
= mliW
.dwLineID
;
4036 lpmliA
->fdwLine
= mliW
.fdwLine
;
4037 lpmliA
->dwUser
= mliW
.dwUser
;
4038 lpmliA
->dwComponentType
= mliW
.dwComponentType
;
4039 lpmliA
->cChannels
= mliW
.cChannels
;
4040 lpmliA
->cConnections
= mliW
.cConnections
;
4041 lpmliA
->cControls
= mliW
.cControls
;
4042 WideCharToMultiByte( CP_ACP
, 0, mliW
.szShortName
, -1, lpmliA
->szShortName
,
4043 sizeof(lpmliA
->szShortName
), NULL
, NULL
);
4044 WideCharToMultiByte( CP_ACP
, 0, mliW
.szName
, -1, lpmliA
->szName
,
4045 sizeof(lpmliA
->szName
), NULL
, NULL
);
4046 lpmliA
->Target
.dwType
= mliW
.Target
.dwType
;
4047 lpmliA
->Target
.dwDeviceID
= mliW
.Target
.dwDeviceID
;
4048 lpmliA
->Target
.wMid
= mliW
.Target
.wMid
;
4049 lpmliA
->Target
.wPid
= mliW
.Target
.wPid
;
4050 lpmliA
->Target
.vDriverVersion
= mliW
.Target
.vDriverVersion
;
4051 WideCharToMultiByte( CP_ACP
, 0, mliW
.Target
.szPname
, -1, lpmliA
->Target
.szPname
,
4052 sizeof(lpmliA
->Target
.szPname
), NULL
, NULL
);
4057 /**************************************************************************
4058 * mixerSetControlDetails [WINMM.@]
4060 UINT WINAPI
mixerSetControlDetails(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcd
,
4063 WINMM_ControlDetails details
;
4065 TRACE("(%p, %p, %x)\n", hmix
, lpmcd
, fdwDetails
);
4067 if(!WINMM_StartDevicesThread())
4068 return MMSYSERR_ERROR
;
4070 if((fdwDetails
& MIXER_SETCONTROLDETAILSF_QUERYMASK
) ==
4071 MIXER_SETCONTROLDETAILSF_CUSTOM
)
4072 return MMSYSERR_NOTSUPPORTED
;
4075 return MMSYSERR_INVALPARAM
;
4077 TRACE("dwControlID: %u\n", lpmcd
->dwControlID
);
4079 details
.hmix
= hmix
;
4080 details
.details
= lpmcd
;
4081 details
.flags
= fdwDetails
;
4083 return SendMessageW(g_devices_hwnd
, MXDM_SETCONTROLDETAILS
,
4084 (DWORD_PTR
)&details
, 0);
4087 /**************************************************************************
4088 * mixerMessage [WINMM.@]
4090 DWORD WINAPI
mixerMessage(HMIXER hmix
, UINT uMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
4092 TRACE("(%p, %d, %lx, %lx)\n", hmix
, uMsg
, dwParam1
, dwParam2
);
4094 return MMSYSERR_NOTSUPPORTED
;