2 * Copyright 2011 Andrew Eikum for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define NONAMELESSUNION
29 #include <sys/types.h>
31 #include <sys/ioctl.h>
35 #include <sys/soundcard.h>
41 #include "wine/debug.h"
42 #include "wine/unicode.h"
43 #include "wine/list.h"
46 #include "mmdeviceapi.h"
52 #include "endpointvolume.h"
53 #include "audiopolicy.h"
54 #include "audioclient.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(oss
);
58 #define NULL_PTR_ERR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, RPC_X_NULL_REF_POINTER)
60 static const REFERENCE_TIME DefaultPeriod
= 200000;
61 static const REFERENCE_TIME MinimumPeriod
= 100000;
64 typedef struct ACImpl ACImpl
;
66 typedef struct _AudioSession
{
77 CRITICAL_SECTION lock
;
82 typedef struct _AudioSessionWrapper
{
83 IAudioSessionControl2 IAudioSessionControl2_iface
;
84 IChannelAudioVolume IChannelAudioVolume_iface
;
85 ISimpleAudioVolume ISimpleAudioVolume_iface
;
90 AudioSession
*session
;
91 } AudioSessionWrapper
;
94 IAudioClient IAudioClient_iface
;
95 IAudioRenderClient IAudioRenderClient_iface
;
96 IAudioCaptureClient IAudioCaptureClient_iface
;
97 IAudioClock IAudioClock_iface
;
98 IAudioClock2 IAudioClock2_iface
;
99 IAudioStreamVolume IAudioStreamVolume_iface
;
109 AUDCLNT_SHAREMODE share
;
115 char devnode
[OSS_DEVNODE_SIZE
];
117 BOOL initted
, playing
;
118 UINT64 written_frames
, last_pos_frames
;
119 UINT32 period_us
, period_frames
, bufsize_frames
, held_frames
, tmp_buffer_frames
;
120 UINT32 oss_bufsize_bytes
, lcl_offs_frames
; /* offs into local_buffer where valid data starts */
122 BYTE
*local_buffer
, *tmp_buffer
;
124 LONG32 getbuf_last
; /* <0 when using tmp_buffer */
127 CRITICAL_SECTION lock
;
129 AudioSession
*session
;
130 AudioSessionWrapper
*session_wrapper
;
137 LOCKED_NORMAL
, /* public buffer piece is from local_buffer */
138 LOCKED_WRAPPED
/* public buffer piece is in tmp_buffer */
141 typedef struct _SessionMgr
{
142 IAudioSessionManager2 IAudioSessionManager2_iface
;
149 static HANDLE g_timer_q
;
151 static CRITICAL_SECTION g_sessions_lock
;
152 static CRITICAL_SECTION_DEBUG g_sessions_lock_debug
=
154 0, 0, &g_sessions_lock
,
155 { &g_sessions_lock_debug
.ProcessLocksList
, &g_sessions_lock_debug
.ProcessLocksList
},
156 0, 0, { (DWORD_PTR
)(__FILE__
": g_sessions_lock") }
158 static CRITICAL_SECTION g_sessions_lock
= { &g_sessions_lock_debug
, -1, 0, 0, 0, 0 };
159 static struct list g_sessions
= LIST_INIT(g_sessions
);
161 static AudioSessionWrapper
*AudioSessionWrapper_Create(ACImpl
*client
);
163 static const IAudioClientVtbl AudioClient_Vtbl
;
164 static const IAudioRenderClientVtbl AudioRenderClient_Vtbl
;
165 static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl
;
166 static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl
;
167 static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl
;
168 static const IAudioClockVtbl AudioClock_Vtbl
;
169 static const IAudioClock2Vtbl AudioClock2_Vtbl
;
170 static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl
;
171 static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl
;
172 static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl
;
174 static inline ACImpl
*impl_from_IAudioClient(IAudioClient
*iface
)
176 return CONTAINING_RECORD(iface
, ACImpl
, IAudioClient_iface
);
179 static inline ACImpl
*impl_from_IAudioRenderClient(IAudioRenderClient
*iface
)
181 return CONTAINING_RECORD(iface
, ACImpl
, IAudioRenderClient_iface
);
184 static inline ACImpl
*impl_from_IAudioCaptureClient(IAudioCaptureClient
*iface
)
186 return CONTAINING_RECORD(iface
, ACImpl
, IAudioCaptureClient_iface
);
189 static inline AudioSessionWrapper
*impl_from_IAudioSessionControl2(IAudioSessionControl2
*iface
)
191 return CONTAINING_RECORD(iface
, AudioSessionWrapper
, IAudioSessionControl2_iface
);
194 static inline AudioSessionWrapper
*impl_from_ISimpleAudioVolume(ISimpleAudioVolume
*iface
)
196 return CONTAINING_RECORD(iface
, AudioSessionWrapper
, ISimpleAudioVolume_iface
);
199 static inline AudioSessionWrapper
*impl_from_IChannelAudioVolume(IChannelAudioVolume
*iface
)
201 return CONTAINING_RECORD(iface
, AudioSessionWrapper
, IChannelAudioVolume_iface
);
204 static inline ACImpl
*impl_from_IAudioClock(IAudioClock
*iface
)
206 return CONTAINING_RECORD(iface
, ACImpl
, IAudioClock_iface
);
209 static inline ACImpl
*impl_from_IAudioClock2(IAudioClock2
*iface
)
211 return CONTAINING_RECORD(iface
, ACImpl
, IAudioClock2_iface
);
214 static inline ACImpl
*impl_from_IAudioStreamVolume(IAudioStreamVolume
*iface
)
216 return CONTAINING_RECORD(iface
, ACImpl
, IAudioStreamVolume_iface
);
219 static inline SessionMgr
*impl_from_IAudioSessionManager2(IAudioSessionManager2
*iface
)
221 return CONTAINING_RECORD(iface
, SessionMgr
, IAudioSessionManager2_iface
);
224 BOOL WINAPI
DllMain(HINSTANCE dll
, DWORD reason
, void *reserved
)
228 case DLL_PROCESS_ATTACH
:
229 g_timer_q
= CreateTimerQueue();
234 case DLL_PROCESS_DETACH
:
235 DeleteCriticalSection(&g_sessions_lock
);
241 /* From <dlls/mmdevapi/mmdevapi.h> */
242 enum DriverPriority
{
243 Priority_Unavailable
= 0,
249 int WINAPI
AUDDRV_GetPriority(void)
254 /* Attempt to determine if we are running on OSS or ALSA's OSS
255 * compatibility layer. There is no official way to do that, so just check
256 * for validity as best as possible, without rejecting valid OSS
257 * implementations. */
259 mixer_fd
= open("/dev/mixer", O_RDONLY
, 0);
261 TRACE("Priority_Unavailable: open failed\n");
262 return Priority_Unavailable
;
265 sysinfo
.version
[0] = 0xFF;
266 sysinfo
.versionnum
= ~0;
267 if(ioctl(mixer_fd
, SNDCTL_SYSINFO
, &sysinfo
) < 0){
268 TRACE("Priority_Unavailable: ioctl failed\n");
270 return Priority_Unavailable
;
275 if(sysinfo
.version
[0] < '4' || sysinfo
.version
[0] > '9'){
276 TRACE("Priority_Low: sysinfo.version[0]: %x\n", sysinfo
.version
[0]);
279 if(sysinfo
.versionnum
& 0x80000000){
280 TRACE("Priority_Low: sysinfo.versionnum: %x\n", sysinfo
.versionnum
);
284 TRACE("Priority_Preferred: Seems like valid OSS!\n");
286 return Priority_Preferred
;
289 static const char *oss_clean_devnode(const char *devnode
)
291 static char ret
[OSS_DEVNODE_SIZE
];
293 const char *dot
, *slash
;
296 dot
= strrchr(devnode
, '.');
300 slash
= strrchr(devnode
, '/');
301 if(slash
&& dot
< slash
)
306 memcpy(ret
, devnode
, len
);
312 static UINT
get_default_index(EDataFlow flow
, char **keys
, UINT num
)
319 fd
= open("/dev/dsp", O_WRONLY
| O_NONBLOCK
);
321 fd
= open("/dev/dsp", O_RDONLY
| O_NONBLOCK
);
324 WARN("Couldn't open default device!\n");
329 if((err
= ioctl(fd
, SNDCTL_ENGINEINFO
, &ai
)) < 0){
330 WARN("SNDCTL_ENGINEINFO failed: %d (%s)\n", err
, strerror(errno
));
337 TRACE("Default devnode: %s\n", ai
.devnode
);
338 devnode
= oss_clean_devnode(ai
.devnode
);
339 for(i
= 0; i
< num
; ++i
)
340 if(!strcmp(devnode
, keys
[i
]))
343 WARN("Couldn't find default device! Choosing first.\n");
347 HRESULT WINAPI
AUDDRV_GetEndpointIDs(EDataFlow flow
, WCHAR
***ids
, char ***keys
,
348 UINT
*num
, UINT
*def_index
)
352 static int print_once
= 0;
354 TRACE("%d %p %p %p\n", flow
, ids
, num
, def_index
);
356 mixer_fd
= open("/dev/mixer", O_RDONLY
, 0);
358 ERR("OSS /dev/mixer doesn't seem to exist\n");
359 return AUDCLNT_E_SERVICE_NOT_RUNNING
;
362 if(ioctl(mixer_fd
, SNDCTL_SYSINFO
, &sysinfo
) < 0){
366 ERR("OSS version too old, need at least OSSv4\n");
367 return AUDCLNT_E_SERVICE_NOT_RUNNING
;
370 ERR("Error getting SNDCTL_SYSINFO: %d (%s)\n", errno
, strerror(errno
));
375 TRACE("OSS sysinfo:\n");
376 TRACE("product: %s\n", sysinfo
.product
);
377 TRACE("version: %s\n", sysinfo
.version
);
378 TRACE("versionnum: %x\n", sysinfo
.versionnum
);
379 TRACE("numaudios: %d\n", sysinfo
.numaudios
);
380 TRACE("nummixers: %d\n", sysinfo
.nummixers
);
381 TRACE("numcards: %d\n", sysinfo
.numcards
);
382 TRACE("numaudioengines: %d\n", sysinfo
.numaudioengines
);
386 if(sysinfo
.numaudios
<= 0){
387 WARN("No audio devices!\n");
389 return AUDCLNT_E_SERVICE_NOT_RUNNING
;
392 *ids
= HeapAlloc(GetProcessHeap(), 0, sysinfo
.numaudios
* sizeof(WCHAR
*));
393 *keys
= HeapAlloc(GetProcessHeap(), 0, sysinfo
.numaudios
* sizeof(char *));
396 for(i
= 0; i
< sysinfo
.numaudios
; ++i
){
397 oss_audioinfo ai
= {0};
402 if(ioctl(mixer_fd
, SNDCTL_AUDIOINFO
, &ai
) < 0){
403 WARN("Error getting AUDIOINFO for dev %d: %d (%s)\n", i
, errno
,
408 devnode
= oss_clean_devnode(ai
.devnode
);
410 /* check for duplicates */
411 for(j
= 0; j
< *num
; ++j
)
412 if(!strcmp(devnode
, (*keys
)[j
]))
418 fd
= open(devnode
, O_WRONLY
| O_NONBLOCK
, 0);
420 fd
= open(devnode
, O_RDONLY
| O_NONBLOCK
, 0);
422 WARN("Opening device \"%s\" failed, pretending it doesn't exist: %d (%s)\n",
423 devnode
, errno
, strerror(errno
));
428 if((flow
== eCapture
&& (ai
.caps
& PCM_CAP_INPUT
)) ||
429 (flow
== eRender
&& (ai
.caps
& PCM_CAP_OUTPUT
))){
432 (*keys
)[*num
] = HeapAlloc(GetProcessHeap(), 0,
433 strlen(devnode
) + 1);
435 for(i
= 0; i
< *num
; ++i
){
436 HeapFree(GetProcessHeap(), 0, (*ids
)[i
]);
437 HeapFree(GetProcessHeap(), 0, (*keys
)[i
]);
439 HeapFree(GetProcessHeap(), 0, *ids
);
440 HeapFree(GetProcessHeap(), 0, *keys
);
442 return E_OUTOFMEMORY
;
444 strcpy((*keys
)[*num
], devnode
);
446 len
= MultiByteToWideChar(CP_UNIXCP
, 0, ai
.name
, -1, NULL
, 0);
447 (*ids
)[*num
] = HeapAlloc(GetProcessHeap(), 0,
448 len
* sizeof(WCHAR
));
450 HeapFree(GetProcessHeap(), 0, (*keys
)[*num
]);
451 for(i
= 0; i
< *num
; ++i
){
452 HeapFree(GetProcessHeap(), 0, (*ids
)[i
]);
453 HeapFree(GetProcessHeap(), 0, (*keys
)[i
]);
455 HeapFree(GetProcessHeap(), 0, *ids
);
456 HeapFree(GetProcessHeap(), 0, *keys
);
458 return E_OUTOFMEMORY
;
460 MultiByteToWideChar(CP_UNIXCP
, 0, ai
.name
, -1,
469 *def_index
= get_default_index(flow
, *keys
, *num
);
474 HRESULT WINAPI
AUDDRV_GetAudioEndpoint(char *devnode
, IMMDevice
*dev
,
475 EDataFlow dataflow
, IAudioClient
**out
)
479 TRACE("%s %p %d %p\n", devnode
, dev
, dataflow
, out
);
481 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(ACImpl
));
483 return E_OUTOFMEMORY
;
485 if(dataflow
== eRender
)
486 This
->fd
= open(devnode
, O_WRONLY
| O_NONBLOCK
, 0);
487 else if(dataflow
== eCapture
)
488 This
->fd
= open(devnode
, O_RDONLY
| O_NONBLOCK
, 0);
490 HeapFree(GetProcessHeap(), 0, This
);
494 WARN("Unable to open device %s: %d (%s)\n", devnode
, errno
,
496 HeapFree(GetProcessHeap(), 0, This
);
497 return AUDCLNT_E_DEVICE_INVALIDATED
;
500 This
->dataflow
= dataflow
;
503 if(ioctl(This
->fd
, SNDCTL_ENGINEINFO
, &This
->ai
) < 0){
504 WARN("Unable to get audio info for device %s: %d (%s)\n", devnode
,
505 errno
, strerror(errno
));
507 HeapFree(GetProcessHeap(), 0, This
);
511 strcpy(This
->devnode
, devnode
);
513 TRACE("OSS audioinfo:\n");
514 TRACE("devnode: %s\n", This
->ai
.devnode
);
515 TRACE("name: %s\n", This
->ai
.name
);
516 TRACE("busy: %x\n", This
->ai
.busy
);
517 TRACE("caps: %x\n", This
->ai
.caps
);
518 TRACE("iformats: %x\n", This
->ai
.iformats
);
519 TRACE("oformats: %x\n", This
->ai
.oformats
);
520 TRACE("enabled: %d\n", This
->ai
.enabled
);
521 TRACE("min_rate: %d\n", This
->ai
.min_rate
);
522 TRACE("max_rate: %d\n", This
->ai
.max_rate
);
523 TRACE("min_channels: %d\n", This
->ai
.min_channels
);
524 TRACE("max_channels: %d\n", This
->ai
.max_channels
);
526 This
->IAudioClient_iface
.lpVtbl
= &AudioClient_Vtbl
;
527 This
->IAudioRenderClient_iface
.lpVtbl
= &AudioRenderClient_Vtbl
;
528 This
->IAudioCaptureClient_iface
.lpVtbl
= &AudioCaptureClient_Vtbl
;
529 This
->IAudioClock_iface
.lpVtbl
= &AudioClock_Vtbl
;
530 This
->IAudioClock2_iface
.lpVtbl
= &AudioClock2_Vtbl
;
531 This
->IAudioStreamVolume_iface
.lpVtbl
= &AudioStreamVolume_Vtbl
;
533 InitializeCriticalSection(&This
->lock
);
534 This
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": ACImpl.lock");
537 IMMDevice_AddRef(This
->parent
);
539 IAudioClient_AddRef(&This
->IAudioClient_iface
);
541 *out
= &This
->IAudioClient_iface
;
546 static HRESULT WINAPI
AudioClient_QueryInterface(IAudioClient
*iface
,
547 REFIID riid
, void **ppv
)
549 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
554 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IAudioClient
))
557 IUnknown_AddRef((IUnknown
*)*ppv
);
560 WARN("Unknown interface %s\n", debugstr_guid(riid
));
561 return E_NOINTERFACE
;
564 static ULONG WINAPI
AudioClient_AddRef(IAudioClient
*iface
)
566 ACImpl
*This
= impl_from_IAudioClient(iface
);
568 ref
= InterlockedIncrement(&This
->ref
);
569 TRACE("(%p) Refcount now %u\n", This
, ref
);
573 static ULONG WINAPI
AudioClient_Release(IAudioClient
*iface
)
575 ACImpl
*This
= impl_from_IAudioClient(iface
);
577 ref
= InterlockedDecrement(&This
->ref
);
578 TRACE("(%p) Refcount now %u\n", This
, ref
);
580 IAudioClient_Stop(iface
);
581 IMMDevice_Release(This
->parent
);
582 This
->lock
.DebugInfo
->Spare
[0] = 0;
583 DeleteCriticalSection(&This
->lock
);
586 EnterCriticalSection(&g_sessions_lock
);
587 list_remove(&This
->entry
);
588 LeaveCriticalSection(&g_sessions_lock
);
590 HeapFree(GetProcessHeap(), 0, This
->vols
);
591 HeapFree(GetProcessHeap(), 0, This
->local_buffer
);
592 HeapFree(GetProcessHeap(), 0, This
->tmp_buffer
);
593 CoTaskMemFree(This
->fmt
);
594 HeapFree(GetProcessHeap(), 0, This
);
599 static void dump_fmt(const WAVEFORMATEX
*fmt
)
601 TRACE("wFormatTag: 0x%x (", fmt
->wFormatTag
);
602 switch(fmt
->wFormatTag
){
603 case WAVE_FORMAT_PCM
:
604 TRACE("WAVE_FORMAT_PCM");
606 case WAVE_FORMAT_IEEE_FLOAT
:
607 TRACE("WAVE_FORMAT_IEEE_FLOAT");
609 case WAVE_FORMAT_EXTENSIBLE
:
610 TRACE("WAVE_FORMAT_EXTENSIBLE");
618 TRACE("nChannels: %u\n", fmt
->nChannels
);
619 TRACE("nSamplesPerSec: %u\n", fmt
->nSamplesPerSec
);
620 TRACE("nAvgBytesPerSec: %u\n", fmt
->nAvgBytesPerSec
);
621 TRACE("nBlockAlign: %u\n", fmt
->nBlockAlign
);
622 TRACE("wBitsPerSample: %u\n", fmt
->wBitsPerSample
);
623 TRACE("cbSize: %u\n", fmt
->cbSize
);
625 if(fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
){
626 WAVEFORMATEXTENSIBLE
*fmtex
= (void*)fmt
;
627 TRACE("dwChannelMask: %08x\n", fmtex
->dwChannelMask
);
628 TRACE("Samples: %04x\n", fmtex
->Samples
.wReserved
);
629 TRACE("SubFormat: %s\n", wine_dbgstr_guid(&fmtex
->SubFormat
));
633 static DWORD
get_channel_mask(unsigned int channels
)
639 return KSAUDIO_SPEAKER_MONO
;
641 return KSAUDIO_SPEAKER_STEREO
;
643 return KSAUDIO_SPEAKER_STEREO
| SPEAKER_LOW_FREQUENCY
;
645 return KSAUDIO_SPEAKER_QUAD
; /* not _SURROUND */
647 return KSAUDIO_SPEAKER_QUAD
| SPEAKER_LOW_FREQUENCY
;
649 return KSAUDIO_SPEAKER_5POINT1
; /* not 5POINT1_SURROUND */
651 return KSAUDIO_SPEAKER_5POINT1
| SPEAKER_BACK_CENTER
;
653 return KSAUDIO_SPEAKER_7POINT1_SURROUND
; /* Vista deprecates 7POINT1 */
655 FIXME("Unknown speaker configuration: %u\n", channels
);
659 static int get_oss_format(const WAVEFORMATEX
*fmt
)
661 WAVEFORMATEXTENSIBLE
*fmtex
= (WAVEFORMATEXTENSIBLE
*)fmt
;
663 if(fmt
->wFormatTag
== WAVE_FORMAT_PCM
||
664 (fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
665 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
))){
666 switch(fmt
->wBitsPerSample
){
680 if(fmt
->wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
||
681 (fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
682 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
))){
683 if(fmt
->wBitsPerSample
!= 32)
693 static WAVEFORMATEX
*clone_format(const WAVEFORMATEX
*fmt
)
698 if(fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
699 size
= sizeof(WAVEFORMATEXTENSIBLE
);
701 size
= sizeof(WAVEFORMATEX
);
703 ret
= CoTaskMemAlloc(size
);
707 memcpy(ret
, fmt
, size
);
709 ret
->cbSize
= size
- sizeof(WAVEFORMATEX
);
714 static HRESULT
setup_oss_device(int fd
, const WAVEFORMATEX
*fmt
,
715 WAVEFORMATEX
**out
, BOOL query
)
720 WAVEFORMATEXTENSIBLE
*fmtex
= (void*)fmt
;
721 WAVEFORMATEX
*closest
= NULL
;
723 tmp
= oss_format
= get_oss_format(fmt
);
725 return AUDCLNT_E_UNSUPPORTED_FORMAT
;
726 if(ioctl(fd
, SNDCTL_DSP_SETFMT
, &tmp
) < 0){
727 WARN("SETFMT failed: %d (%s)\n", errno
, strerror(errno
));
730 if(tmp
!= oss_format
){
731 TRACE("Format unsupported by this OSS version: %x\n", oss_format
);
732 return AUDCLNT_E_UNSUPPORTED_FORMAT
;
735 closest
= clone_format(fmt
);
737 return E_OUTOFMEMORY
;
739 tmp
= fmt
->nSamplesPerSec
;
740 if(ioctl(fd
, SNDCTL_DSP_SPEED
, &tmp
) < 0){
741 WARN("SPEED failed: %d (%s)\n", errno
, strerror(errno
));
742 CoTaskMemFree(closest
);
745 tenth
= fmt
->nSamplesPerSec
* 0.1;
746 if(tmp
> fmt
->nSamplesPerSec
+ tenth
|| tmp
< fmt
->nSamplesPerSec
- tenth
){
748 closest
->nSamplesPerSec
= tmp
;
751 tmp
= fmt
->nChannels
;
752 if(ioctl(fd
, SNDCTL_DSP_CHANNELS
, &tmp
) < 0){
753 WARN("CHANNELS failed: %d (%s)\n", errno
, strerror(errno
));
754 CoTaskMemFree(closest
);
757 if(tmp
!= fmt
->nChannels
){
759 closest
->nChannels
= tmp
;
762 if(closest
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
){
763 DWORD mask
= get_channel_mask(closest
->nChannels
);
765 ((WAVEFORMATEXTENSIBLE
*)closest
)->dwChannelMask
= mask
;
767 if(query
&& fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
768 fmtex
->dwChannelMask
!= 0 &&
769 fmtex
->dwChannelMask
!= mask
)
773 if(ret
== S_FALSE
&& !out
)
774 ret
= AUDCLNT_E_UNSUPPORTED_FORMAT
;
776 if(ret
== S_FALSE
&& out
){
777 closest
->nBlockAlign
=
778 closest
->nChannels
* closest
->wBitsPerSample
/ 8;
779 closest
->nAvgBytesPerSec
=
780 closest
->nBlockAlign
* closest
->nSamplesPerSec
;
783 CoTaskMemFree(closest
);
785 TRACE("returning: %08x\n", ret
);
789 static void session_init_vols(AudioSession
*session
, UINT channels
)
791 if(session
->channel_count
< channels
){
794 if(session
->channel_vols
)
795 session
->channel_vols
= HeapReAlloc(GetProcessHeap(), 0,
796 session
->channel_vols
, sizeof(float) * channels
);
798 session
->channel_vols
= HeapAlloc(GetProcessHeap(), 0,
799 sizeof(float) * channels
);
800 if(!session
->channel_vols
)
803 for(i
= session
->channel_count
; i
< channels
; ++i
)
804 session
->channel_vols
[i
] = 1.f
;
806 session
->channel_count
= channels
;
810 static AudioSession
*create_session(const GUID
*guid
, IMMDevice
*device
,
815 ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(AudioSession
));
819 memcpy(&ret
->guid
, guid
, sizeof(GUID
));
821 ret
->device
= device
;
823 list_init(&ret
->clients
);
825 list_add_head(&g_sessions
, &ret
->entry
);
827 InitializeCriticalSection(&ret
->lock
);
828 ret
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": AudioSession.lock");
830 session_init_vols(ret
, num_channels
);
832 ret
->master_vol
= 1.f
;
837 /* if channels == 0, then this will return or create a session with
838 * matching dataflow and GUID. otherwise, channels must also match */
839 static HRESULT
get_audio_session(const GUID
*sessionguid
,
840 IMMDevice
*device
, UINT channels
, AudioSession
**out
)
842 AudioSession
*session
;
844 if(!sessionguid
|| IsEqualGUID(sessionguid
, &GUID_NULL
)){
845 *out
= create_session(&GUID_NULL
, device
, channels
);
847 return E_OUTOFMEMORY
;
853 LIST_FOR_EACH_ENTRY(session
, &g_sessions
, AudioSession
, entry
){
854 if(session
->device
== device
&&
855 IsEqualGUID(sessionguid
, &session
->guid
)){
856 session_init_vols(session
, channels
);
863 *out
= create_session(sessionguid
, device
, channels
);
865 return E_OUTOFMEMORY
;
871 static HRESULT WINAPI
AudioClient_Initialize(IAudioClient
*iface
,
872 AUDCLNT_SHAREMODE mode
, DWORD flags
, REFERENCE_TIME duration
,
873 REFERENCE_TIME period
, const WAVEFORMATEX
*fmt
,
874 const GUID
*sessionguid
)
876 ACImpl
*This
= impl_from_IAudioClient(iface
);
880 TRACE("(%p)->(%x, %x, %s, %s, %p, %s)\n", This
, mode
, flags
,
881 wine_dbgstr_longlong(duration
), wine_dbgstr_longlong(period
), fmt
, debugstr_guid(sessionguid
));
888 if(mode
!= AUDCLNT_SHAREMODE_SHARED
&& mode
!= AUDCLNT_SHAREMODE_EXCLUSIVE
)
889 return AUDCLNT_E_NOT_INITIALIZED
;
891 if(flags
& ~(AUDCLNT_STREAMFLAGS_CROSSPROCESS
|
892 AUDCLNT_STREAMFLAGS_LOOPBACK
|
893 AUDCLNT_STREAMFLAGS_EVENTCALLBACK
|
894 AUDCLNT_STREAMFLAGS_NOPERSIST
|
895 AUDCLNT_STREAMFLAGS_RATEADJUST
|
896 AUDCLNT_SESSIONFLAGS_EXPIREWHENUNOWNED
|
897 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDE
|
898 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDEWHENEXPIRED
)){
899 TRACE("Unknown flags: %08x\n", flags
);
903 if(mode
== AUDCLNT_SHAREMODE_SHARED
){
904 period
= DefaultPeriod
;
905 if( duration
< 3 * period
)
906 duration
= 3 * period
;
909 period
= DefaultPeriod
; /* not minimum */
910 if(period
< MinimumPeriod
|| period
> 5000000)
911 return AUDCLNT_E_INVALID_DEVICE_PERIOD
;
912 if(duration
> 20000000) /* the smaller the period, the lower this limit */
913 return AUDCLNT_E_BUFFER_SIZE_ERROR
;
914 if(flags
& AUDCLNT_STREAMFLAGS_EVENTCALLBACK
){
915 if(duration
!= period
)
916 return AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL
;
917 FIXME("EXCLUSIVE mode with EVENTCALLBACK\n");
918 return AUDCLNT_E_DEVICE_IN_USE
;
920 if( duration
< 8 * period
)
921 duration
= 8 * period
; /* may grow above 2s */
925 EnterCriticalSection(&This
->lock
);
928 LeaveCriticalSection(&This
->lock
);
929 return AUDCLNT_E_ALREADY_INITIALIZED
;
932 hr
= setup_oss_device(This
->fd
, fmt
, NULL
, FALSE
);
934 LeaveCriticalSection(&This
->lock
);
938 This
->fmt
= clone_format(fmt
);
940 LeaveCriticalSection(&This
->lock
);
941 return E_OUTOFMEMORY
;
944 This
->period_us
= period
/ 10;
945 This
->period_frames
= MulDiv(fmt
->nSamplesPerSec
, period
, 10000000);
947 This
->bufsize_frames
= MulDiv(duration
, fmt
->nSamplesPerSec
, 10000000);
948 This
->local_buffer
= HeapAlloc(GetProcessHeap(), 0,
949 This
->bufsize_frames
* fmt
->nBlockAlign
);
950 if(!This
->local_buffer
){
951 CoTaskMemFree(This
->fmt
);
953 LeaveCriticalSection(&This
->lock
);
954 return E_OUTOFMEMORY
;
957 This
->vols
= HeapAlloc(GetProcessHeap(), 0, fmt
->nChannels
* sizeof(float));
959 CoTaskMemFree(This
->fmt
);
961 LeaveCriticalSection(&This
->lock
);
962 return E_OUTOFMEMORY
;
965 for(i
= 0; i
< fmt
->nChannels
; ++i
)
970 This
->oss_bufsize_bytes
= 0;
972 EnterCriticalSection(&g_sessions_lock
);
974 hr
= get_audio_session(sessionguid
, This
->parent
, fmt
->nChannels
,
977 LeaveCriticalSection(&g_sessions_lock
);
978 HeapFree(GetProcessHeap(), 0, This
->vols
);
980 CoTaskMemFree(This
->fmt
);
982 LeaveCriticalSection(&This
->lock
);
986 list_add_tail(&This
->session
->clients
, &This
->entry
);
988 LeaveCriticalSection(&g_sessions_lock
);
990 This
->initted
= TRUE
;
992 LeaveCriticalSection(&This
->lock
);
997 static HRESULT WINAPI
AudioClient_GetBufferSize(IAudioClient
*iface
,
1000 ACImpl
*This
= impl_from_IAudioClient(iface
);
1002 TRACE("(%p)->(%p)\n", This
, frames
);
1007 EnterCriticalSection(&This
->lock
);
1010 LeaveCriticalSection(&This
->lock
);
1011 return AUDCLNT_E_NOT_INITIALIZED
;
1014 *frames
= This
->bufsize_frames
;
1016 TRACE("buffer size: %u\n", *frames
);
1018 LeaveCriticalSection(&This
->lock
);
1023 static HRESULT WINAPI
AudioClient_GetStreamLatency(IAudioClient
*iface
,
1024 REFERENCE_TIME
*latency
)
1026 ACImpl
*This
= impl_from_IAudioClient(iface
);
1028 TRACE("(%p)->(%p)\n", This
, latency
);
1033 EnterCriticalSection(&This
->lock
);
1036 LeaveCriticalSection(&This
->lock
);
1037 return AUDCLNT_E_NOT_INITIALIZED
;
1040 /* pretend we process audio in Period chunks, so max latency includes
1041 * the period time. Some native machines add .6666ms in shared mode. */
1042 *latency
= This
->period_us
* 10 + 6666;
1044 LeaveCriticalSection(&This
->lock
);
1049 static HRESULT WINAPI
AudioClient_GetCurrentPadding(IAudioClient
*iface
,
1052 ACImpl
*This
= impl_from_IAudioClient(iface
);
1054 TRACE("(%p)->(%p)\n", This
, numpad
);
1059 EnterCriticalSection(&This
->lock
);
1062 LeaveCriticalSection(&This
->lock
);
1063 return AUDCLNT_E_NOT_INITIALIZED
;
1066 *numpad
= This
->held_frames
;
1068 TRACE("padding: %u\n", *numpad
);
1070 LeaveCriticalSection(&This
->lock
);
1075 static HRESULT WINAPI
AudioClient_IsFormatSupported(IAudioClient
*iface
,
1076 AUDCLNT_SHAREMODE mode
, const WAVEFORMATEX
*pwfx
,
1077 WAVEFORMATEX
**outpwfx
)
1079 ACImpl
*This
= impl_from_IAudioClient(iface
);
1083 TRACE("(%p)->(%x, %p, %p)\n", This
, mode
, pwfx
, outpwfx
);
1085 if(!pwfx
|| (mode
== AUDCLNT_SHAREMODE_SHARED
&& !outpwfx
))
1088 if(mode
!= AUDCLNT_SHAREMODE_SHARED
&& mode
!= AUDCLNT_SHAREMODE_EXCLUSIVE
)
1089 return E_INVALIDARG
;
1091 if(pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
1092 pwfx
->cbSize
< sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
))
1093 return E_INVALIDARG
;
1099 if(mode
!= AUDCLNT_SHAREMODE_SHARED
)
1103 if(This
->dataflow
== eRender
)
1104 fd
= open(This
->devnode
, O_WRONLY
| O_NONBLOCK
, 0);
1105 else if(This
->dataflow
== eCapture
)
1106 fd
= open(This
->devnode
, O_RDONLY
| O_NONBLOCK
, 0);
1109 WARN("Unable to open device %s: %d (%s)\n", This
->devnode
, errno
,
1111 return AUDCLNT_E_DEVICE_INVALIDATED
;
1114 ret
= setup_oss_device(fd
, pwfx
, outpwfx
, TRUE
);
1121 static HRESULT WINAPI
AudioClient_GetMixFormat(IAudioClient
*iface
,
1122 WAVEFORMATEX
**pwfx
)
1124 ACImpl
*This
= impl_from_IAudioClient(iface
);
1125 WAVEFORMATEXTENSIBLE
*fmt
;
1128 TRACE("(%p)->(%p)\n", This
, pwfx
);
1134 if(This
->dataflow
== eRender
)
1135 formats
= This
->ai
.oformats
;
1136 else if(This
->dataflow
== eCapture
)
1137 formats
= This
->ai
.iformats
;
1139 return E_UNEXPECTED
;
1141 fmt
= CoTaskMemAlloc(sizeof(WAVEFORMATEXTENSIBLE
));
1143 return E_OUTOFMEMORY
;
1145 fmt
->Format
.wFormatTag
= WAVE_FORMAT_EXTENSIBLE
;
1146 if(formats
& AFMT_S16_LE
){
1147 fmt
->Format
.wBitsPerSample
= 16;
1148 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1150 }else if(formats
& AFMT_FLOAT
){
1151 fmt
->Format
.wBitsPerSample
= 32;
1152 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
1154 }else if(formats
& AFMT_U8
){
1155 fmt
->Format
.wBitsPerSample
= 8;
1156 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1157 }else if(formats
& AFMT_S32_LE
){
1158 fmt
->Format
.wBitsPerSample
= 32;
1159 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1160 }else if(formats
& AFMT_S24_LE
){
1161 fmt
->Format
.wBitsPerSample
= 24;
1162 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1164 WARN("Didn't recognize any available OSS formats: %x\n", formats
);
1169 fmt
->Format
.nChannels
= This
->ai
.max_channels
;
1170 fmt
->Format
.nSamplesPerSec
= This
->ai
.max_rate
;
1171 fmt
->dwChannelMask
= get_channel_mask(fmt
->Format
.nChannels
);
1173 fmt
->Format
.nBlockAlign
= (fmt
->Format
.wBitsPerSample
*
1174 fmt
->Format
.nChannels
) / 8;
1175 fmt
->Format
.nAvgBytesPerSec
= fmt
->Format
.nSamplesPerSec
*
1176 fmt
->Format
.nBlockAlign
;
1178 fmt
->Samples
.wValidBitsPerSample
= fmt
->Format
.wBitsPerSample
;
1179 fmt
->Format
.cbSize
= sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
);
1181 *pwfx
= (WAVEFORMATEX
*)fmt
;
1187 static HRESULT WINAPI
AudioClient_GetDevicePeriod(IAudioClient
*iface
,
1188 REFERENCE_TIME
*defperiod
, REFERENCE_TIME
*minperiod
)
1190 ACImpl
*This
= impl_from_IAudioClient(iface
);
1192 TRACE("(%p)->(%p, %p)\n", This
, defperiod
, minperiod
);
1194 if(!defperiod
&& !minperiod
)
1198 *defperiod
= DefaultPeriod
;
1200 *minperiod
= MinimumPeriod
;
1205 static void oss_silence_buffer(ACImpl
*This
, BYTE
*buf
, UINT32 frames
)
1207 if(This
->fmt
->wBitsPerSample
== 8)
1208 memset(buf
, 128, frames
* This
->fmt
->nBlockAlign
);
1210 memset(buf
, 0, frames
* This
->fmt
->nBlockAlign
);
1213 static void oss_write_data(ACImpl
*This
)
1215 ssize_t written_bytes
;
1216 UINT32 written_frames
, in_oss_frames
, write_limit
, max_period
;
1217 size_t to_write_frames
, to_write_bytes
;
1220 This
->local_buffer
+ (This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
);
1222 if(This
->held_frames
== 0)
1225 if(This
->lcl_offs_frames
+ This
->held_frames
> This
->bufsize_frames
)
1226 to_write_frames
= This
->bufsize_frames
- This
->lcl_offs_frames
;
1228 to_write_frames
= This
->held_frames
;
1230 if(ioctl(This
->fd
, SNDCTL_DSP_GETOSPACE
, &bi
) < 0){
1231 WARN("GETOSPACE failed: %d (%s)\n", errno
, strerror(errno
));
1235 max_period
= max(bi
.fragsize
/ This
->fmt
->nBlockAlign
, This
->period_frames
);
1237 if(bi
.bytes
> This
->oss_bufsize_bytes
){
1238 TRACE("New buffer size (%u) is larger than old buffer size (%u)\n",
1239 bi
.bytes
, This
->oss_bufsize_bytes
);
1240 This
->oss_bufsize_bytes
= bi
.bytes
;
1242 }else if(This
->oss_bufsize_bytes
- bi
.bytes
<= bi
.fragsize
)
1245 in_oss_frames
= (This
->oss_bufsize_bytes
- bi
.bytes
) / This
->fmt
->nBlockAlign
;
1248 while(write_limit
+ in_oss_frames
< max_period
* 3)
1249 write_limit
+= max_period
;
1250 if(write_limit
== 0)
1253 to_write_frames
= min(to_write_frames
, write_limit
);
1254 to_write_bytes
= to_write_frames
* This
->fmt
->nBlockAlign
;
1256 if(This
->session
->mute
)
1257 oss_silence_buffer(This
, buf
, to_write_frames
);
1259 written_bytes
= write(This
->fd
, buf
, to_write_bytes
);
1260 if(written_bytes
< 0){
1261 /* EAGAIN is OSS buffer full, log that too */
1262 WARN("write failed: %d (%s)\n", errno
, strerror(errno
));
1265 written_frames
= written_bytes
/ This
->fmt
->nBlockAlign
;
1267 This
->lcl_offs_frames
+= written_frames
;
1268 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1269 This
->held_frames
-= written_frames
;
1271 if(written_frames
< to_write_frames
){
1272 /* OSS buffer probably full */
1276 if(This
->held_frames
&& written_frames
< write_limit
){
1277 /* wrapped and have some data back at the start to write */
1279 to_write_frames
= min(write_limit
- written_frames
, This
->held_frames
);
1280 to_write_bytes
= to_write_frames
* This
->fmt
->nBlockAlign
;
1282 if(This
->session
->mute
)
1283 oss_silence_buffer(This
, This
->local_buffer
, to_write_frames
);
1285 written_bytes
= write(This
->fd
, This
->local_buffer
, to_write_bytes
);
1286 if(written_bytes
< 0){
1287 WARN("write failed: %d (%s)\n", errno
, strerror(errno
));
1290 written_frames
= written_bytes
/ This
->fmt
->nBlockAlign
;
1292 This
->lcl_offs_frames
+= written_frames
;
1293 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1294 This
->held_frames
-= written_frames
;
1298 static void oss_read_data(ACImpl
*This
)
1300 UINT64 pos
, readable
;
1304 if(ioctl(This
->fd
, SNDCTL_DSP_GETISPACE
, &bi
) < 0){
1305 WARN("GETISPACE failed: %d (%s)\n", errno
, strerror(errno
));
1309 pos
= (This
->held_frames
+ This
->lcl_offs_frames
) % This
->bufsize_frames
;
1310 readable
= (This
->bufsize_frames
- pos
) * This
->fmt
->nBlockAlign
;
1312 if(bi
.bytes
< readable
)
1313 readable
= bi
.bytes
;
1315 nread
= read(This
->fd
, This
->local_buffer
+ pos
* This
->fmt
->nBlockAlign
,
1318 WARN("read failed: %d (%s)\n", errno
, strerror(errno
));
1322 This
->held_frames
+= nread
/ This
->fmt
->nBlockAlign
;
1324 if(This
->held_frames
> This
->bufsize_frames
){
1325 WARN("Overflow of unread data\n");
1326 This
->lcl_offs_frames
+= This
->held_frames
;
1327 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1328 This
->held_frames
= This
->bufsize_frames
;
1332 static void CALLBACK
oss_period_callback(void *user
, BOOLEAN timer
)
1334 ACImpl
*This
= user
;
1336 EnterCriticalSection(&This
->lock
);
1339 if(This
->dataflow
== eRender
&& This
->held_frames
)
1340 oss_write_data(This
);
1341 else if(This
->dataflow
== eCapture
)
1342 oss_read_data(This
);
1345 SetEvent(This
->event
);
1348 LeaveCriticalSection(&This
->lock
);
1351 static HRESULT WINAPI
AudioClient_Start(IAudioClient
*iface
)
1353 ACImpl
*This
= impl_from_IAudioClient(iface
);
1355 TRACE("(%p)\n", This
);
1357 EnterCriticalSection(&This
->lock
);
1360 LeaveCriticalSection(&This
->lock
);
1361 return AUDCLNT_E_NOT_INITIALIZED
;
1364 if((This
->flags
& AUDCLNT_STREAMFLAGS_EVENTCALLBACK
) && !This
->event
){
1365 LeaveCriticalSection(&This
->lock
);
1366 return AUDCLNT_E_EVENTHANDLE_NOT_SET
;
1370 LeaveCriticalSection(&This
->lock
);
1371 return AUDCLNT_E_NOT_STOPPED
;
1374 if(!CreateTimerQueueTimer(&This
->timer
, g_timer_q
,
1375 oss_period_callback
, This
, 0, This
->period_us
/ 1000,
1376 WT_EXECUTEINTIMERTHREAD
))
1377 ERR("Unable to create period timer: %u\n", GetLastError());
1379 This
->playing
= TRUE
;
1381 LeaveCriticalSection(&This
->lock
);
1386 static HRESULT WINAPI
AudioClient_Stop(IAudioClient
*iface
)
1388 ACImpl
*This
= impl_from_IAudioClient(iface
);
1392 TRACE("(%p)\n", This
);
1394 EnterCriticalSection(&This
->lock
);
1397 LeaveCriticalSection(&This
->lock
);
1398 return AUDCLNT_E_NOT_INITIALIZED
;
1402 LeaveCriticalSection(&This
->lock
);
1406 event
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
1407 wait
= !DeleteTimerQueueTimer(g_timer_q
, This
->timer
, event
);
1409 WARN("DeleteTimerQueueTimer error %u\n", GetLastError());
1410 wait
= wait
&& GetLastError() == ERROR_IO_PENDING
;
1412 This
->playing
= FALSE
;
1414 LeaveCriticalSection(&This
->lock
);
1417 WaitForSingleObject(event
, INFINITE
);
1423 static HRESULT WINAPI
AudioClient_Reset(IAudioClient
*iface
)
1425 ACImpl
*This
= impl_from_IAudioClient(iface
);
1427 TRACE("(%p)\n", This
);
1429 EnterCriticalSection(&This
->lock
);
1432 LeaveCriticalSection(&This
->lock
);
1433 return AUDCLNT_E_NOT_INITIALIZED
;
1437 LeaveCriticalSection(&This
->lock
);
1438 return AUDCLNT_E_NOT_STOPPED
;
1441 if(This
->buf_state
!= NOT_LOCKED
|| This
->getbuf_last
){
1442 LeaveCriticalSection(&This
->lock
);
1443 return AUDCLNT_E_BUFFER_OPERATION_PENDING
;
1446 if(This
->dataflow
== eRender
){
1447 This
->written_frames
= 0;
1449 This
->written_frames
+= This
->held_frames
;
1451 This
->lcl_offs_frames
= 0;
1452 This
->held_frames
= 0;
1453 This
->last_pos_frames
= 0;
1455 LeaveCriticalSection(&This
->lock
);
1460 static HRESULT WINAPI
AudioClient_SetEventHandle(IAudioClient
*iface
,
1463 ACImpl
*This
= impl_from_IAudioClient(iface
);
1465 TRACE("(%p)->(%p)\n", This
, event
);
1468 return E_INVALIDARG
;
1470 EnterCriticalSection(&This
->lock
);
1473 LeaveCriticalSection(&This
->lock
);
1474 return AUDCLNT_E_NOT_INITIALIZED
;
1477 if(!(This
->flags
& AUDCLNT_STREAMFLAGS_EVENTCALLBACK
)){
1478 LeaveCriticalSection(&This
->lock
);
1479 return AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED
;
1482 This
->event
= event
;
1484 LeaveCriticalSection(&This
->lock
);
1489 static HRESULT WINAPI
AudioClient_GetService(IAudioClient
*iface
, REFIID riid
,
1492 ACImpl
*This
= impl_from_IAudioClient(iface
);
1494 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1500 EnterCriticalSection(&This
->lock
);
1503 LeaveCriticalSection(&This
->lock
);
1504 return AUDCLNT_E_NOT_INITIALIZED
;
1507 if(IsEqualIID(riid
, &IID_IAudioRenderClient
)){
1508 if(This
->dataflow
!= eRender
){
1509 LeaveCriticalSection(&This
->lock
);
1510 return AUDCLNT_E_WRONG_ENDPOINT_TYPE
;
1512 IAudioRenderClient_AddRef(&This
->IAudioRenderClient_iface
);
1513 *ppv
= &This
->IAudioRenderClient_iface
;
1514 }else if(IsEqualIID(riid
, &IID_IAudioCaptureClient
)){
1515 if(This
->dataflow
!= eCapture
){
1516 LeaveCriticalSection(&This
->lock
);
1517 return AUDCLNT_E_WRONG_ENDPOINT_TYPE
;
1519 IAudioCaptureClient_AddRef(&This
->IAudioCaptureClient_iface
);
1520 *ppv
= &This
->IAudioCaptureClient_iface
;
1521 }else if(IsEqualIID(riid
, &IID_IAudioClock
)){
1522 IAudioClock_AddRef(&This
->IAudioClock_iface
);
1523 *ppv
= &This
->IAudioClock_iface
;
1524 }else if(IsEqualIID(riid
, &IID_IAudioStreamVolume
)){
1525 IAudioStreamVolume_AddRef(&This
->IAudioStreamVolume_iface
);
1526 *ppv
= &This
->IAudioStreamVolume_iface
;
1527 }else if(IsEqualIID(riid
, &IID_IAudioSessionControl
)){
1528 if(!This
->session_wrapper
){
1529 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1530 if(!This
->session_wrapper
){
1531 LeaveCriticalSection(&This
->lock
);
1532 return E_OUTOFMEMORY
;
1535 IAudioSessionControl2_AddRef(&This
->session_wrapper
->IAudioSessionControl2_iface
);
1537 *ppv
= &This
->session_wrapper
->IAudioSessionControl2_iface
;
1538 }else if(IsEqualIID(riid
, &IID_IChannelAudioVolume
)){
1539 if(!This
->session_wrapper
){
1540 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1541 if(!This
->session_wrapper
){
1542 LeaveCriticalSection(&This
->lock
);
1543 return E_OUTOFMEMORY
;
1546 IChannelAudioVolume_AddRef(&This
->session_wrapper
->IChannelAudioVolume_iface
);
1548 *ppv
= &This
->session_wrapper
->IChannelAudioVolume_iface
;
1549 }else if(IsEqualIID(riid
, &IID_ISimpleAudioVolume
)){
1550 if(!This
->session_wrapper
){
1551 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1552 if(!This
->session_wrapper
){
1553 LeaveCriticalSection(&This
->lock
);
1554 return E_OUTOFMEMORY
;
1557 ISimpleAudioVolume_AddRef(&This
->session_wrapper
->ISimpleAudioVolume_iface
);
1559 *ppv
= &This
->session_wrapper
->ISimpleAudioVolume_iface
;
1563 LeaveCriticalSection(&This
->lock
);
1567 LeaveCriticalSection(&This
->lock
);
1569 FIXME("stub %s\n", debugstr_guid(riid
));
1570 return E_NOINTERFACE
;
1573 static const IAudioClientVtbl AudioClient_Vtbl
=
1575 AudioClient_QueryInterface
,
1577 AudioClient_Release
,
1578 AudioClient_Initialize
,
1579 AudioClient_GetBufferSize
,
1580 AudioClient_GetStreamLatency
,
1581 AudioClient_GetCurrentPadding
,
1582 AudioClient_IsFormatSupported
,
1583 AudioClient_GetMixFormat
,
1584 AudioClient_GetDevicePeriod
,
1588 AudioClient_SetEventHandle
,
1589 AudioClient_GetService
1592 static HRESULT WINAPI
AudioRenderClient_QueryInterface(
1593 IAudioRenderClient
*iface
, REFIID riid
, void **ppv
)
1595 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1601 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1602 IsEqualIID(riid
, &IID_IAudioRenderClient
))
1605 IUnknown_AddRef((IUnknown
*)*ppv
);
1609 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1610 return E_NOINTERFACE
;
1613 static ULONG WINAPI
AudioRenderClient_AddRef(IAudioRenderClient
*iface
)
1615 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1616 return AudioClient_AddRef(&This
->IAudioClient_iface
);
1619 static ULONG WINAPI
AudioRenderClient_Release(IAudioRenderClient
*iface
)
1621 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1622 return AudioClient_Release(&This
->IAudioClient_iface
);
1625 static HRESULT WINAPI
AudioRenderClient_GetBuffer(IAudioRenderClient
*iface
,
1626 UINT32 frames
, BYTE
**data
)
1628 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1629 UINT32 pad
, write_pos
;
1632 TRACE("(%p)->(%u, %p)\n", This
, frames
, data
);
1639 EnterCriticalSection(&This
->lock
);
1641 if(This
->getbuf_last
){
1642 LeaveCriticalSection(&This
->lock
);
1643 return AUDCLNT_E_OUT_OF_ORDER
;
1647 LeaveCriticalSection(&This
->lock
);
1651 hr
= IAudioClient_GetCurrentPadding(&This
->IAudioClient_iface
, &pad
);
1653 LeaveCriticalSection(&This
->lock
);
1657 if(pad
+ frames
> This
->bufsize_frames
){
1658 LeaveCriticalSection(&This
->lock
);
1659 return AUDCLNT_E_BUFFER_TOO_LARGE
;
1663 (This
->lcl_offs_frames
+ This
->held_frames
) % This
->bufsize_frames
;
1664 if(write_pos
+ frames
> This
->bufsize_frames
){
1665 if(This
->tmp_buffer_frames
< frames
){
1666 HeapFree(GetProcessHeap(), 0, This
->tmp_buffer
);
1667 This
->tmp_buffer
= HeapAlloc(GetProcessHeap(), 0,
1668 frames
* This
->fmt
->nBlockAlign
);
1669 if(!This
->tmp_buffer
){
1670 LeaveCriticalSection(&This
->lock
);
1671 return E_OUTOFMEMORY
;
1673 This
->tmp_buffer_frames
= frames
;
1675 *data
= This
->tmp_buffer
;
1676 This
->getbuf_last
= -frames
;
1678 *data
= This
->local_buffer
+ write_pos
* This
->fmt
->nBlockAlign
;
1679 This
->getbuf_last
= frames
;
1682 LeaveCriticalSection(&This
->lock
);
1687 static void oss_wrap_buffer(ACImpl
*This
, BYTE
*buffer
, UINT32 written_frames
)
1689 UINT32 write_offs_frames
=
1690 (This
->lcl_offs_frames
+ This
->held_frames
) % This
->bufsize_frames
;
1691 UINT32 write_offs_bytes
= write_offs_frames
* This
->fmt
->nBlockAlign
;
1692 UINT32 chunk_frames
= This
->bufsize_frames
- write_offs_frames
;
1693 UINT32 chunk_bytes
= chunk_frames
* This
->fmt
->nBlockAlign
;
1694 UINT32 written_bytes
= written_frames
* This
->fmt
->nBlockAlign
;
1696 if(written_bytes
<= chunk_bytes
){
1697 memcpy(This
->local_buffer
+ write_offs_bytes
, buffer
, written_bytes
);
1699 memcpy(This
->local_buffer
+ write_offs_bytes
, buffer
, chunk_bytes
);
1700 memcpy(This
->local_buffer
, buffer
+ chunk_bytes
,
1701 written_bytes
- chunk_bytes
);
1705 static HRESULT WINAPI
AudioRenderClient_ReleaseBuffer(
1706 IAudioRenderClient
*iface
, UINT32 written_frames
, DWORD flags
)
1708 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1711 TRACE("(%p)->(%u, %x)\n", This
, written_frames
, flags
);
1713 EnterCriticalSection(&This
->lock
);
1715 if(!written_frames
){
1716 This
->getbuf_last
= 0;
1717 LeaveCriticalSection(&This
->lock
);
1721 if(!This
->getbuf_last
){
1722 LeaveCriticalSection(&This
->lock
);
1723 return AUDCLNT_E_OUT_OF_ORDER
;
1726 if(written_frames
> (This
->getbuf_last
>= 0 ? This
->getbuf_last
: -This
->getbuf_last
)){
1727 LeaveCriticalSection(&This
->lock
);
1728 return AUDCLNT_E_INVALID_SIZE
;
1731 if(This
->getbuf_last
>= 0)
1732 buffer
= This
->local_buffer
+ This
->fmt
->nBlockAlign
*
1733 ((This
->lcl_offs_frames
+ This
->held_frames
) % This
->bufsize_frames
);
1735 buffer
= This
->tmp_buffer
;
1737 if(flags
& AUDCLNT_BUFFERFLAGS_SILENT
)
1738 oss_silence_buffer(This
, buffer
, written_frames
);
1740 if(This
->getbuf_last
< 0)
1741 oss_wrap_buffer(This
, buffer
, written_frames
);
1743 This
->held_frames
+= written_frames
;
1744 This
->written_frames
+= written_frames
;
1745 This
->getbuf_last
= 0;
1747 LeaveCriticalSection(&This
->lock
);
1752 static const IAudioRenderClientVtbl AudioRenderClient_Vtbl
= {
1753 AudioRenderClient_QueryInterface
,
1754 AudioRenderClient_AddRef
,
1755 AudioRenderClient_Release
,
1756 AudioRenderClient_GetBuffer
,
1757 AudioRenderClient_ReleaseBuffer
1760 static HRESULT WINAPI
AudioCaptureClient_QueryInterface(
1761 IAudioCaptureClient
*iface
, REFIID riid
, void **ppv
)
1763 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1769 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1770 IsEqualIID(riid
, &IID_IAudioCaptureClient
))
1773 IUnknown_AddRef((IUnknown
*)*ppv
);
1777 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1778 return E_NOINTERFACE
;
1781 static ULONG WINAPI
AudioCaptureClient_AddRef(IAudioCaptureClient
*iface
)
1783 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1784 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
1787 static ULONG WINAPI
AudioCaptureClient_Release(IAudioCaptureClient
*iface
)
1789 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1790 return IAudioClient_Release(&This
->IAudioClient_iface
);
1793 static HRESULT WINAPI
AudioCaptureClient_GetBuffer(IAudioCaptureClient
*iface
,
1794 BYTE
**data
, UINT32
*frames
, DWORD
*flags
, UINT64
*devpos
,
1797 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1800 TRACE("(%p)->(%p, %p, %p, %p, %p)\n", This
, data
, frames
, flags
,
1803 if(!data
|| !frames
|| !flags
)
1806 EnterCriticalSection(&This
->lock
);
1808 if(This
->buf_state
!= NOT_LOCKED
){
1809 LeaveCriticalSection(&This
->lock
);
1810 return AUDCLNT_E_OUT_OF_ORDER
;
1813 hr
= IAudioCaptureClient_GetNextPacketSize(iface
, frames
);
1815 LeaveCriticalSection(&This
->lock
);
1821 if(This
->lcl_offs_frames
+ *frames
> This
->bufsize_frames
){
1822 UINT32 chunk_bytes
, offs_bytes
, frames_bytes
;
1823 if(This
->tmp_buffer_frames
< *frames
){
1824 HeapFree(GetProcessHeap(), 0, This
->tmp_buffer
);
1825 This
->tmp_buffer
= HeapAlloc(GetProcessHeap(), 0,
1826 *frames
* This
->fmt
->nBlockAlign
);
1827 if(!This
->tmp_buffer
){
1828 LeaveCriticalSection(&This
->lock
);
1829 return E_OUTOFMEMORY
;
1831 This
->tmp_buffer_frames
= *frames
;
1834 *data
= This
->tmp_buffer
;
1835 chunk_bytes
= (This
->bufsize_frames
- This
->lcl_offs_frames
) *
1836 This
->fmt
->nBlockAlign
;
1837 offs_bytes
= This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
;
1838 frames_bytes
= *frames
* This
->fmt
->nBlockAlign
;
1839 memcpy(This
->tmp_buffer
, This
->local_buffer
+ offs_bytes
, chunk_bytes
);
1840 memcpy(This
->tmp_buffer
+ chunk_bytes
, This
->local_buffer
,
1841 frames_bytes
- chunk_bytes
);
1843 *data
= This
->local_buffer
+
1844 This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
;
1846 This
->buf_state
= LOCKED_NORMAL
;
1848 if(devpos
|| qpcpos
)
1849 IAudioClock_GetPosition(&This
->IAudioClock_iface
, devpos
, qpcpos
);
1851 LeaveCriticalSection(&This
->lock
);
1853 return *frames
? S_OK
: AUDCLNT_S_BUFFER_EMPTY
;
1856 static HRESULT WINAPI
AudioCaptureClient_ReleaseBuffer(
1857 IAudioCaptureClient
*iface
, UINT32 done
)
1859 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1861 TRACE("(%p)->(%u)\n", This
, done
);
1863 EnterCriticalSection(&This
->lock
);
1865 if(This
->buf_state
== NOT_LOCKED
){
1866 LeaveCriticalSection(&This
->lock
);
1867 return AUDCLNT_E_OUT_OF_ORDER
;
1870 This
->held_frames
-= done
;
1871 This
->lcl_offs_frames
+= done
;
1872 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1874 This
->buf_state
= NOT_LOCKED
;
1876 LeaveCriticalSection(&This
->lock
);
1881 static HRESULT WINAPI
AudioCaptureClient_GetNextPacketSize(
1882 IAudioCaptureClient
*iface
, UINT32
*frames
)
1884 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1886 TRACE("(%p)->(%p)\n", This
, frames
);
1888 return AudioClient_GetCurrentPadding(&This
->IAudioClient_iface
, frames
);
1891 static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl
=
1893 AudioCaptureClient_QueryInterface
,
1894 AudioCaptureClient_AddRef
,
1895 AudioCaptureClient_Release
,
1896 AudioCaptureClient_GetBuffer
,
1897 AudioCaptureClient_ReleaseBuffer
,
1898 AudioCaptureClient_GetNextPacketSize
1901 static HRESULT WINAPI
AudioClock_QueryInterface(IAudioClock
*iface
,
1902 REFIID riid
, void **ppv
)
1904 ACImpl
*This
= impl_from_IAudioClock(iface
);
1906 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1912 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IAudioClock
))
1914 else if(IsEqualIID(riid
, &IID_IAudioClock2
))
1915 *ppv
= &This
->IAudioClock2_iface
;
1917 IUnknown_AddRef((IUnknown
*)*ppv
);
1921 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1922 return E_NOINTERFACE
;
1925 static ULONG WINAPI
AudioClock_AddRef(IAudioClock
*iface
)
1927 ACImpl
*This
= impl_from_IAudioClock(iface
);
1928 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
1931 static ULONG WINAPI
AudioClock_Release(IAudioClock
*iface
)
1933 ACImpl
*This
= impl_from_IAudioClock(iface
);
1934 return IAudioClient_Release(&This
->IAudioClient_iface
);
1937 static HRESULT WINAPI
AudioClock_GetFrequency(IAudioClock
*iface
, UINT64
*freq
)
1939 ACImpl
*This
= impl_from_IAudioClock(iface
);
1941 TRACE("(%p)->(%p)\n", This
, freq
);
1943 *freq
= This
->fmt
->nSamplesPerSec
;
1948 static HRESULT WINAPI
AudioClock_GetPosition(IAudioClock
*iface
, UINT64
*pos
,
1951 ACImpl
*This
= impl_from_IAudioClock(iface
);
1954 TRACE("(%p)->(%p, %p)\n", This
, pos
, qpctime
);
1959 EnterCriticalSection(&This
->lock
);
1961 if(This
->dataflow
== eRender
){
1962 if(!This
->playing
|| !This
->held_frames
||
1963 ioctl(This
->fd
, SNDCTL_DSP_GETODELAY
, &delay
) < 0)
1966 delay
/= This
->fmt
->nBlockAlign
;
1967 if(This
->held_frames
+ delay
>= This
->written_frames
)
1968 *pos
= This
->last_pos_frames
;
1970 *pos
= This
->written_frames
- This
->held_frames
- delay
;
1971 if(*pos
< This
->last_pos_frames
)
1972 *pos
= This
->last_pos_frames
;
1974 }else if(This
->dataflow
== eCapture
){
1978 if(ioctl(This
->fd
, SNDCTL_DSP_GETISPACE
, &bi
) < 0){
1979 TRACE("GETISPACE failed: %d (%s)\n", errno
, strerror(errno
));
1982 if(bi
.bytes
<= bi
.fragsize
)
1985 held
= bi
.bytes
/ This
->fmt
->nBlockAlign
;
1988 *pos
= This
->written_frames
+ held
;
1991 This
->last_pos_frames
= *pos
;
1993 LeaveCriticalSection(&This
->lock
);
1996 LARGE_INTEGER stamp
, freq
;
1997 QueryPerformanceCounter(&stamp
);
1998 QueryPerformanceFrequency(&freq
);
1999 *qpctime
= (stamp
.QuadPart
* (INT64
)10000000) / freq
.QuadPart
;
2005 static HRESULT WINAPI
AudioClock_GetCharacteristics(IAudioClock
*iface
,
2008 ACImpl
*This
= impl_from_IAudioClock(iface
);
2010 TRACE("(%p)->(%p)\n", This
, chars
);
2015 *chars
= AUDIOCLOCK_CHARACTERISTIC_FIXED_FREQ
;
2020 static const IAudioClockVtbl AudioClock_Vtbl
=
2022 AudioClock_QueryInterface
,
2025 AudioClock_GetFrequency
,
2026 AudioClock_GetPosition
,
2027 AudioClock_GetCharacteristics
2030 static HRESULT WINAPI
AudioClock2_QueryInterface(IAudioClock2
*iface
,
2031 REFIID riid
, void **ppv
)
2033 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2034 return IAudioClock_QueryInterface(&This
->IAudioClock_iface
, riid
, ppv
);
2037 static ULONG WINAPI
AudioClock2_AddRef(IAudioClock2
*iface
)
2039 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2040 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
2043 static ULONG WINAPI
AudioClock2_Release(IAudioClock2
*iface
)
2045 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2046 return IAudioClient_Release(&This
->IAudioClient_iface
);
2049 static HRESULT WINAPI
AudioClock2_GetDevicePosition(IAudioClock2
*iface
,
2050 UINT64
*pos
, UINT64
*qpctime
)
2052 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2054 FIXME("(%p)->(%p, %p)\n", This
, pos
, qpctime
);
2059 static const IAudioClock2Vtbl AudioClock2_Vtbl
=
2061 AudioClock2_QueryInterface
,
2063 AudioClock2_Release
,
2064 AudioClock2_GetDevicePosition
2067 static AudioSessionWrapper
*AudioSessionWrapper_Create(ACImpl
*client
)
2069 AudioSessionWrapper
*ret
;
2071 ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2072 sizeof(AudioSessionWrapper
));
2076 ret
->IAudioSessionControl2_iface
.lpVtbl
= &AudioSessionControl2_Vtbl
;
2077 ret
->ISimpleAudioVolume_iface
.lpVtbl
= &SimpleAudioVolume_Vtbl
;
2078 ret
->IChannelAudioVolume_iface
.lpVtbl
= &ChannelAudioVolume_Vtbl
;
2082 ret
->client
= client
;
2084 ret
->session
= client
->session
;
2085 AudioClient_AddRef(&client
->IAudioClient_iface
);
2091 static HRESULT WINAPI
AudioSessionControl_QueryInterface(
2092 IAudioSessionControl2
*iface
, REFIID riid
, void **ppv
)
2094 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2100 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2101 IsEqualIID(riid
, &IID_IAudioSessionControl
) ||
2102 IsEqualIID(riid
, &IID_IAudioSessionControl2
))
2105 IUnknown_AddRef((IUnknown
*)*ppv
);
2109 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2110 return E_NOINTERFACE
;
2113 static ULONG WINAPI
AudioSessionControl_AddRef(IAudioSessionControl2
*iface
)
2115 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2117 ref
= InterlockedIncrement(&This
->ref
);
2118 TRACE("(%p) Refcount now %u\n", This
, ref
);
2122 static ULONG WINAPI
AudioSessionControl_Release(IAudioSessionControl2
*iface
)
2124 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2126 ref
= InterlockedDecrement(&This
->ref
);
2127 TRACE("(%p) Refcount now %u\n", This
, ref
);
2130 EnterCriticalSection(&This
->client
->lock
);
2131 This
->client
->session_wrapper
= NULL
;
2132 LeaveCriticalSection(&This
->client
->lock
);
2133 AudioClient_Release(&This
->client
->IAudioClient_iface
);
2135 HeapFree(GetProcessHeap(), 0, This
);
2140 static HRESULT WINAPI
AudioSessionControl_GetState(IAudioSessionControl2
*iface
,
2141 AudioSessionState
*state
)
2143 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2146 TRACE("(%p)->(%p)\n", This
, state
);
2149 return NULL_PTR_ERR
;
2151 EnterCriticalSection(&g_sessions_lock
);
2153 if(list_empty(&This
->session
->clients
)){
2154 *state
= AudioSessionStateExpired
;
2155 LeaveCriticalSection(&g_sessions_lock
);
2159 LIST_FOR_EACH_ENTRY(client
, &This
->session
->clients
, ACImpl
, entry
){
2160 EnterCriticalSection(&client
->lock
);
2161 if(client
->playing
){
2162 *state
= AudioSessionStateActive
;
2163 LeaveCriticalSection(&client
->lock
);
2164 LeaveCriticalSection(&g_sessions_lock
);
2167 LeaveCriticalSection(&client
->lock
);
2170 LeaveCriticalSection(&g_sessions_lock
);
2172 *state
= AudioSessionStateInactive
;
2177 static HRESULT WINAPI
AudioSessionControl_GetDisplayName(
2178 IAudioSessionControl2
*iface
, WCHAR
**name
)
2180 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2182 FIXME("(%p)->(%p) - stub\n", This
, name
);
2187 static HRESULT WINAPI
AudioSessionControl_SetDisplayName(
2188 IAudioSessionControl2
*iface
, const WCHAR
*name
, const GUID
*session
)
2190 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2192 FIXME("(%p)->(%p, %s) - stub\n", This
, name
, debugstr_guid(session
));
2197 static HRESULT WINAPI
AudioSessionControl_GetIconPath(
2198 IAudioSessionControl2
*iface
, WCHAR
**path
)
2200 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2202 FIXME("(%p)->(%p) - stub\n", This
, path
);
2207 static HRESULT WINAPI
AudioSessionControl_SetIconPath(
2208 IAudioSessionControl2
*iface
, const WCHAR
*path
, const GUID
*session
)
2210 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2212 FIXME("(%p)->(%p, %s) - stub\n", This
, path
, debugstr_guid(session
));
2217 static HRESULT WINAPI
AudioSessionControl_GetGroupingParam(
2218 IAudioSessionControl2
*iface
, GUID
*group
)
2220 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2222 FIXME("(%p)->(%p) - stub\n", This
, group
);
2227 static HRESULT WINAPI
AudioSessionControl_SetGroupingParam(
2228 IAudioSessionControl2
*iface
, const GUID
*group
, const GUID
*session
)
2230 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2232 FIXME("(%p)->(%s, %s) - stub\n", This
, debugstr_guid(group
),
2233 debugstr_guid(session
));
2238 static HRESULT WINAPI
AudioSessionControl_RegisterAudioSessionNotification(
2239 IAudioSessionControl2
*iface
, IAudioSessionEvents
*events
)
2241 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2243 FIXME("(%p)->(%p) - stub\n", This
, events
);
2248 static HRESULT WINAPI
AudioSessionControl_UnregisterAudioSessionNotification(
2249 IAudioSessionControl2
*iface
, IAudioSessionEvents
*events
)
2251 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2253 FIXME("(%p)->(%p) - stub\n", This
, events
);
2258 static HRESULT WINAPI
AudioSessionControl_GetSessionIdentifier(
2259 IAudioSessionControl2
*iface
, WCHAR
**id
)
2261 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2263 FIXME("(%p)->(%p) - stub\n", This
, id
);
2268 static HRESULT WINAPI
AudioSessionControl_GetSessionInstanceIdentifier(
2269 IAudioSessionControl2
*iface
, WCHAR
**id
)
2271 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2273 FIXME("(%p)->(%p) - stub\n", This
, id
);
2278 static HRESULT WINAPI
AudioSessionControl_GetProcessId(
2279 IAudioSessionControl2
*iface
, DWORD
*pid
)
2281 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2283 TRACE("(%p)->(%p)\n", This
, pid
);
2288 *pid
= GetCurrentProcessId();
2293 static HRESULT WINAPI
AudioSessionControl_IsSystemSoundsSession(
2294 IAudioSessionControl2
*iface
)
2296 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2298 TRACE("(%p)\n", This
);
2303 static HRESULT WINAPI
AudioSessionControl_SetDuckingPreference(
2304 IAudioSessionControl2
*iface
, BOOL optout
)
2306 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2308 TRACE("(%p)->(%d)\n", This
, optout
);
2313 static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl
=
2315 AudioSessionControl_QueryInterface
,
2316 AudioSessionControl_AddRef
,
2317 AudioSessionControl_Release
,
2318 AudioSessionControl_GetState
,
2319 AudioSessionControl_GetDisplayName
,
2320 AudioSessionControl_SetDisplayName
,
2321 AudioSessionControl_GetIconPath
,
2322 AudioSessionControl_SetIconPath
,
2323 AudioSessionControl_GetGroupingParam
,
2324 AudioSessionControl_SetGroupingParam
,
2325 AudioSessionControl_RegisterAudioSessionNotification
,
2326 AudioSessionControl_UnregisterAudioSessionNotification
,
2327 AudioSessionControl_GetSessionIdentifier
,
2328 AudioSessionControl_GetSessionInstanceIdentifier
,
2329 AudioSessionControl_GetProcessId
,
2330 AudioSessionControl_IsSystemSoundsSession
,
2331 AudioSessionControl_SetDuckingPreference
2334 static HRESULT WINAPI
SimpleAudioVolume_QueryInterface(
2335 ISimpleAudioVolume
*iface
, REFIID riid
, void **ppv
)
2337 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2343 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2344 IsEqualIID(riid
, &IID_ISimpleAudioVolume
))
2347 IUnknown_AddRef((IUnknown
*)*ppv
);
2351 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2352 return E_NOINTERFACE
;
2355 static ULONG WINAPI
SimpleAudioVolume_AddRef(ISimpleAudioVolume
*iface
)
2357 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2358 return AudioSessionControl_AddRef(&This
->IAudioSessionControl2_iface
);
2361 static ULONG WINAPI
SimpleAudioVolume_Release(ISimpleAudioVolume
*iface
)
2363 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2364 return AudioSessionControl_Release(&This
->IAudioSessionControl2_iface
);
2367 static HRESULT WINAPI
SimpleAudioVolume_SetMasterVolume(
2368 ISimpleAudioVolume
*iface
, float level
, const GUID
*context
)
2370 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2371 AudioSession
*session
= This
->session
;
2373 TRACE("(%p)->(%f, %s)\n", session
, level
, wine_dbgstr_guid(context
));
2375 if(level
< 0.f
|| level
> 1.f
)
2376 return E_INVALIDARG
;
2379 FIXME("Notifications not supported yet\n");
2381 EnterCriticalSection(&session
->lock
);
2383 session
->master_vol
= level
;
2385 TRACE("OSS doesn't support setting volume\n");
2387 LeaveCriticalSection(&session
->lock
);
2392 static HRESULT WINAPI
SimpleAudioVolume_GetMasterVolume(
2393 ISimpleAudioVolume
*iface
, float *level
)
2395 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2396 AudioSession
*session
= This
->session
;
2398 TRACE("(%p)->(%p)\n", session
, level
);
2401 return NULL_PTR_ERR
;
2403 *level
= session
->master_vol
;
2408 static HRESULT WINAPI
SimpleAudioVolume_SetMute(ISimpleAudioVolume
*iface
,
2409 BOOL mute
, const GUID
*context
)
2411 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2412 AudioSession
*session
= This
->session
;
2414 TRACE("(%p)->(%u, %p)\n", session
, mute
, context
);
2416 EnterCriticalSection(&session
->lock
);
2418 session
->mute
= mute
;
2420 LeaveCriticalSection(&session
->lock
);
2425 static HRESULT WINAPI
SimpleAudioVolume_GetMute(ISimpleAudioVolume
*iface
,
2428 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2429 AudioSession
*session
= This
->session
;
2431 TRACE("(%p)->(%p)\n", session
, mute
);
2434 return NULL_PTR_ERR
;
2436 *mute
= This
->session
->mute
;
2441 static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl
=
2443 SimpleAudioVolume_QueryInterface
,
2444 SimpleAudioVolume_AddRef
,
2445 SimpleAudioVolume_Release
,
2446 SimpleAudioVolume_SetMasterVolume
,
2447 SimpleAudioVolume_GetMasterVolume
,
2448 SimpleAudioVolume_SetMute
,
2449 SimpleAudioVolume_GetMute
2452 static HRESULT WINAPI
AudioStreamVolume_QueryInterface(
2453 IAudioStreamVolume
*iface
, REFIID riid
, void **ppv
)
2455 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2461 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2462 IsEqualIID(riid
, &IID_IAudioStreamVolume
))
2465 IUnknown_AddRef((IUnknown
*)*ppv
);
2469 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2470 return E_NOINTERFACE
;
2473 static ULONG WINAPI
AudioStreamVolume_AddRef(IAudioStreamVolume
*iface
)
2475 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2476 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
2479 static ULONG WINAPI
AudioStreamVolume_Release(IAudioStreamVolume
*iface
)
2481 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2482 return IAudioClient_Release(&This
->IAudioClient_iface
);
2485 static HRESULT WINAPI
AudioStreamVolume_GetChannelCount(
2486 IAudioStreamVolume
*iface
, UINT32
*out
)
2488 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2490 TRACE("(%p)->(%p)\n", This
, out
);
2495 *out
= This
->fmt
->nChannels
;
2500 static HRESULT WINAPI
AudioStreamVolume_SetChannelVolume(
2501 IAudioStreamVolume
*iface
, UINT32 index
, float level
)
2503 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2505 TRACE("(%p)->(%d, %f)\n", This
, index
, level
);
2507 if(level
< 0.f
|| level
> 1.f
)
2508 return E_INVALIDARG
;
2510 if(index
>= This
->fmt
->nChannels
)
2511 return E_INVALIDARG
;
2513 EnterCriticalSection(&This
->lock
);
2515 This
->vols
[index
] = level
;
2517 TRACE("OSS doesn't support setting volume\n");
2519 LeaveCriticalSection(&This
->lock
);
2524 static HRESULT WINAPI
AudioStreamVolume_GetChannelVolume(
2525 IAudioStreamVolume
*iface
, UINT32 index
, float *level
)
2527 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2529 TRACE("(%p)->(%d, %p)\n", This
, index
, level
);
2534 if(index
>= This
->fmt
->nChannels
)
2535 return E_INVALIDARG
;
2537 *level
= This
->vols
[index
];
2542 static HRESULT WINAPI
AudioStreamVolume_SetAllVolumes(
2543 IAudioStreamVolume
*iface
, UINT32 count
, const float *levels
)
2545 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2548 TRACE("(%p)->(%d, %p)\n", This
, count
, levels
);
2553 if(count
!= This
->fmt
->nChannels
)
2554 return E_INVALIDARG
;
2556 EnterCriticalSection(&This
->lock
);
2558 for(i
= 0; i
< count
; ++i
)
2559 This
->vols
[i
] = levels
[i
];
2561 TRACE("OSS doesn't support setting volume\n");
2563 LeaveCriticalSection(&This
->lock
);
2568 static HRESULT WINAPI
AudioStreamVolume_GetAllVolumes(
2569 IAudioStreamVolume
*iface
, UINT32 count
, float *levels
)
2571 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2574 TRACE("(%p)->(%d, %p)\n", This
, count
, levels
);
2579 if(count
!= This
->fmt
->nChannels
)
2580 return E_INVALIDARG
;
2582 EnterCriticalSection(&This
->lock
);
2584 for(i
= 0; i
< count
; ++i
)
2585 levels
[i
] = This
->vols
[i
];
2587 LeaveCriticalSection(&This
->lock
);
2592 static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl
=
2594 AudioStreamVolume_QueryInterface
,
2595 AudioStreamVolume_AddRef
,
2596 AudioStreamVolume_Release
,
2597 AudioStreamVolume_GetChannelCount
,
2598 AudioStreamVolume_SetChannelVolume
,
2599 AudioStreamVolume_GetChannelVolume
,
2600 AudioStreamVolume_SetAllVolumes
,
2601 AudioStreamVolume_GetAllVolumes
2604 static HRESULT WINAPI
ChannelAudioVolume_QueryInterface(
2605 IChannelAudioVolume
*iface
, REFIID riid
, void **ppv
)
2607 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2613 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2614 IsEqualIID(riid
, &IID_IChannelAudioVolume
))
2617 IUnknown_AddRef((IUnknown
*)*ppv
);
2621 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2622 return E_NOINTERFACE
;
2625 static ULONG WINAPI
ChannelAudioVolume_AddRef(IChannelAudioVolume
*iface
)
2627 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2628 return AudioSessionControl_AddRef(&This
->IAudioSessionControl2_iface
);
2631 static ULONG WINAPI
ChannelAudioVolume_Release(IChannelAudioVolume
*iface
)
2633 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2634 return AudioSessionControl_Release(&This
->IAudioSessionControl2_iface
);
2637 static HRESULT WINAPI
ChannelAudioVolume_GetChannelCount(
2638 IChannelAudioVolume
*iface
, UINT32
*out
)
2640 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2641 AudioSession
*session
= This
->session
;
2643 TRACE("(%p)->(%p)\n", session
, out
);
2646 return NULL_PTR_ERR
;
2648 *out
= session
->channel_count
;
2653 static HRESULT WINAPI
ChannelAudioVolume_SetChannelVolume(
2654 IChannelAudioVolume
*iface
, UINT32 index
, float level
,
2655 const GUID
*context
)
2657 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2658 AudioSession
*session
= This
->session
;
2660 TRACE("(%p)->(%d, %f, %s)\n", session
, index
, level
,
2661 wine_dbgstr_guid(context
));
2663 if(level
< 0.f
|| level
> 1.f
)
2664 return E_INVALIDARG
;
2666 if(index
>= session
->channel_count
)
2667 return E_INVALIDARG
;
2670 FIXME("Notifications not supported yet\n");
2672 EnterCriticalSection(&session
->lock
);
2674 session
->channel_vols
[index
] = level
;
2676 TRACE("OSS doesn't support setting volume\n");
2678 LeaveCriticalSection(&session
->lock
);
2683 static HRESULT WINAPI
ChannelAudioVolume_GetChannelVolume(
2684 IChannelAudioVolume
*iface
, UINT32 index
, float *level
)
2686 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2687 AudioSession
*session
= This
->session
;
2689 TRACE("(%p)->(%d, %p)\n", session
, index
, level
);
2692 return NULL_PTR_ERR
;
2694 if(index
>= session
->channel_count
)
2695 return E_INVALIDARG
;
2697 *level
= session
->channel_vols
[index
];
2702 static HRESULT WINAPI
ChannelAudioVolume_SetAllVolumes(
2703 IChannelAudioVolume
*iface
, UINT32 count
, const float *levels
,
2704 const GUID
*context
)
2706 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2707 AudioSession
*session
= This
->session
;
2710 TRACE("(%p)->(%d, %p, %s)\n", session
, count
, levels
,
2711 wine_dbgstr_guid(context
));
2714 return NULL_PTR_ERR
;
2716 if(count
!= session
->channel_count
)
2717 return E_INVALIDARG
;
2720 FIXME("Notifications not supported yet\n");
2722 EnterCriticalSection(&session
->lock
);
2724 for(i
= 0; i
< count
; ++i
)
2725 session
->channel_vols
[i
] = levels
[i
];
2727 TRACE("OSS doesn't support setting volume\n");
2729 LeaveCriticalSection(&session
->lock
);
2734 static HRESULT WINAPI
ChannelAudioVolume_GetAllVolumes(
2735 IChannelAudioVolume
*iface
, UINT32 count
, float *levels
)
2737 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2738 AudioSession
*session
= This
->session
;
2741 TRACE("(%p)->(%d, %p)\n", session
, count
, levels
);
2744 return NULL_PTR_ERR
;
2746 if(count
!= session
->channel_count
)
2747 return E_INVALIDARG
;
2749 for(i
= 0; i
< count
; ++i
)
2750 levels
[i
] = session
->channel_vols
[i
];
2755 static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl
=
2757 ChannelAudioVolume_QueryInterface
,
2758 ChannelAudioVolume_AddRef
,
2759 ChannelAudioVolume_Release
,
2760 ChannelAudioVolume_GetChannelCount
,
2761 ChannelAudioVolume_SetChannelVolume
,
2762 ChannelAudioVolume_GetChannelVolume
,
2763 ChannelAudioVolume_SetAllVolumes
,
2764 ChannelAudioVolume_GetAllVolumes
2767 static HRESULT WINAPI
AudioSessionManager_QueryInterface(IAudioSessionManager2
*iface
,
2768 REFIID riid
, void **ppv
)
2770 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2776 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2777 IsEqualIID(riid
, &IID_IAudioSessionManager
) ||
2778 IsEqualIID(riid
, &IID_IAudioSessionManager2
))
2781 IUnknown_AddRef((IUnknown
*)*ppv
);
2785 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2786 return E_NOINTERFACE
;
2789 static ULONG WINAPI
AudioSessionManager_AddRef(IAudioSessionManager2
*iface
)
2791 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2793 ref
= InterlockedIncrement(&This
->ref
);
2794 TRACE("(%p) Refcount now %u\n", This
, ref
);
2798 static ULONG WINAPI
AudioSessionManager_Release(IAudioSessionManager2
*iface
)
2800 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2802 ref
= InterlockedDecrement(&This
->ref
);
2803 TRACE("(%p) Refcount now %u\n", This
, ref
);
2805 HeapFree(GetProcessHeap(), 0, This
);
2809 static HRESULT WINAPI
AudioSessionManager_GetAudioSessionControl(
2810 IAudioSessionManager2
*iface
, const GUID
*session_guid
, DWORD flags
,
2811 IAudioSessionControl
**out
)
2813 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2814 AudioSession
*session
;
2815 AudioSessionWrapper
*wrapper
;
2818 TRACE("(%p)->(%s, %x, %p)\n", This
, debugstr_guid(session_guid
),
2821 hr
= get_audio_session(session_guid
, This
->device
, 0, &session
);
2825 wrapper
= AudioSessionWrapper_Create(NULL
);
2827 return E_OUTOFMEMORY
;
2829 wrapper
->session
= session
;
2831 *out
= (IAudioSessionControl
*)&wrapper
->IAudioSessionControl2_iface
;
2836 static HRESULT WINAPI
AudioSessionManager_GetSimpleAudioVolume(
2837 IAudioSessionManager2
*iface
, const GUID
*session_guid
, DWORD flags
,
2838 ISimpleAudioVolume
**out
)
2840 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2841 AudioSession
*session
;
2842 AudioSessionWrapper
*wrapper
;
2845 TRACE("(%p)->(%s, %x, %p)\n", This
, debugstr_guid(session_guid
),
2848 hr
= get_audio_session(session_guid
, This
->device
, 0, &session
);
2852 wrapper
= AudioSessionWrapper_Create(NULL
);
2854 return E_OUTOFMEMORY
;
2856 wrapper
->session
= session
;
2858 *out
= &wrapper
->ISimpleAudioVolume_iface
;
2863 static HRESULT WINAPI
AudioSessionManager_GetSessionEnumerator(
2864 IAudioSessionManager2
*iface
, IAudioSessionEnumerator
**out
)
2866 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2867 FIXME("(%p)->(%p) - stub\n", This
, out
);
2871 static HRESULT WINAPI
AudioSessionManager_RegisterSessionNotification(
2872 IAudioSessionManager2
*iface
, IAudioSessionNotification
*notification
)
2874 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2875 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2879 static HRESULT WINAPI
AudioSessionManager_UnregisterSessionNotification(
2880 IAudioSessionManager2
*iface
, IAudioSessionNotification
*notification
)
2882 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2883 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2887 static HRESULT WINAPI
AudioSessionManager_RegisterDuckNotification(
2888 IAudioSessionManager2
*iface
, const WCHAR
*session_id
,
2889 IAudioVolumeDuckNotification
*notification
)
2891 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2892 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2896 static HRESULT WINAPI
AudioSessionManager_UnregisterDuckNotification(
2897 IAudioSessionManager2
*iface
,
2898 IAudioVolumeDuckNotification
*notification
)
2900 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2901 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2905 static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl
=
2907 AudioSessionManager_QueryInterface
,
2908 AudioSessionManager_AddRef
,
2909 AudioSessionManager_Release
,
2910 AudioSessionManager_GetAudioSessionControl
,
2911 AudioSessionManager_GetSimpleAudioVolume
,
2912 AudioSessionManager_GetSessionEnumerator
,
2913 AudioSessionManager_RegisterSessionNotification
,
2914 AudioSessionManager_UnregisterSessionNotification
,
2915 AudioSessionManager_RegisterDuckNotification
,
2916 AudioSessionManager_UnregisterDuckNotification
2919 HRESULT WINAPI
AUDDRV_GetAudioSessionManager(IMMDevice
*device
,
2920 IAudioSessionManager2
**out
)
2924 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SessionMgr
));
2926 return E_OUTOFMEMORY
;
2928 This
->IAudioSessionManager2_iface
.lpVtbl
= &AudioSessionManager2_Vtbl
;
2929 This
->device
= device
;
2932 *out
= &This
->IAudioSessionManager2_iface
;