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 ERR("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 ERR("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
);
881 TRACE("(%p)->(%x, %x, %s, %s, %p, %s)\n", This
, mode
, flags
,
882 wine_dbgstr_longlong(duration
), wine_dbgstr_longlong(period
), fmt
, debugstr_guid(sessionguid
));
889 if(mode
!= AUDCLNT_SHAREMODE_SHARED
&& mode
!= AUDCLNT_SHAREMODE_EXCLUSIVE
)
890 return AUDCLNT_E_NOT_INITIALIZED
;
892 if(flags
& ~(AUDCLNT_STREAMFLAGS_CROSSPROCESS
|
893 AUDCLNT_STREAMFLAGS_LOOPBACK
|
894 AUDCLNT_STREAMFLAGS_EVENTCALLBACK
|
895 AUDCLNT_STREAMFLAGS_NOPERSIST
|
896 AUDCLNT_STREAMFLAGS_RATEADJUST
|
897 AUDCLNT_SESSIONFLAGS_EXPIREWHENUNOWNED
|
898 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDE
|
899 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDEWHENEXPIRED
)){
900 TRACE("Unknown flags: %08x\n", flags
);
904 if(mode
== AUDCLNT_SHAREMODE_SHARED
){
905 period
= DefaultPeriod
;
906 if( duration
< 3 * period
)
907 duration
= 3 * period
;
910 period
= DefaultPeriod
; /* not minimum */
911 if(period
< MinimumPeriod
|| period
> 5000000)
912 return AUDCLNT_E_INVALID_DEVICE_PERIOD
;
913 if(duration
> 20000000) /* the smaller the period, the lower this limit */
914 return AUDCLNT_E_BUFFER_SIZE_ERROR
;
915 if(flags
& AUDCLNT_STREAMFLAGS_EVENTCALLBACK
){
916 if(duration
!= period
)
917 return AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL
;
918 FIXME("EXCLUSIVE mode with EVENTCALLBACK\n");
919 return AUDCLNT_E_DEVICE_IN_USE
;
921 if( duration
< 8 * period
)
922 duration
= 8 * period
; /* may grow above 2s */
926 EnterCriticalSection(&This
->lock
);
929 LeaveCriticalSection(&This
->lock
);
930 return AUDCLNT_E_ALREADY_INITIALIZED
;
933 hr
= setup_oss_device(This
->fd
, fmt
, NULL
, FALSE
);
935 LeaveCriticalSection(&This
->lock
);
939 This
->fmt
= clone_format(fmt
);
941 LeaveCriticalSection(&This
->lock
);
942 return E_OUTOFMEMORY
;
945 This
->period_us
= period
/ 10;
946 This
->period_frames
= MulDiv(fmt
->nSamplesPerSec
, period
, 10000000);
948 This
->bufsize_frames
= MulDiv(duration
, fmt
->nSamplesPerSec
, 10000000);
949 This
->local_buffer
= HeapAlloc(GetProcessHeap(), 0,
950 This
->bufsize_frames
* fmt
->nBlockAlign
);
951 if(!This
->local_buffer
){
952 CoTaskMemFree(This
->fmt
);
954 LeaveCriticalSection(&This
->lock
);
955 return E_OUTOFMEMORY
;
958 if(This
->dataflow
== eRender
){
959 if(ioctl(This
->fd
, SNDCTL_DSP_GETOSPACE
, &bi
) < 0){
960 WARN("GETOSPACE failed: %d (%s)\n", errno
, strerror(errno
));
961 CoTaskMemFree(This
->fmt
);
963 LeaveCriticalSection(&This
->lock
);
967 This
->oss_bufsize_bytes
= bi
.bytes
;
970 This
->vols
= HeapAlloc(GetProcessHeap(), 0, fmt
->nChannels
* sizeof(float));
972 CoTaskMemFree(This
->fmt
);
974 LeaveCriticalSection(&This
->lock
);
975 return E_OUTOFMEMORY
;
978 for(i
= 0; i
< fmt
->nChannels
; ++i
)
984 EnterCriticalSection(&g_sessions_lock
);
986 hr
= get_audio_session(sessionguid
, This
->parent
, fmt
->nChannels
,
989 LeaveCriticalSection(&g_sessions_lock
);
990 HeapFree(GetProcessHeap(), 0, This
->vols
);
992 CoTaskMemFree(This
->fmt
);
994 LeaveCriticalSection(&This
->lock
);
998 list_add_tail(&This
->session
->clients
, &This
->entry
);
1000 LeaveCriticalSection(&g_sessions_lock
);
1002 This
->initted
= TRUE
;
1004 LeaveCriticalSection(&This
->lock
);
1009 static HRESULT WINAPI
AudioClient_GetBufferSize(IAudioClient
*iface
,
1012 ACImpl
*This
= impl_from_IAudioClient(iface
);
1014 TRACE("(%p)->(%p)\n", This
, frames
);
1019 EnterCriticalSection(&This
->lock
);
1022 LeaveCriticalSection(&This
->lock
);
1023 return AUDCLNT_E_NOT_INITIALIZED
;
1026 *frames
= This
->bufsize_frames
;
1028 TRACE("buffer size: %u\n", *frames
);
1030 LeaveCriticalSection(&This
->lock
);
1035 static HRESULT WINAPI
AudioClient_GetStreamLatency(IAudioClient
*iface
,
1036 REFERENCE_TIME
*latency
)
1038 ACImpl
*This
= impl_from_IAudioClient(iface
);
1040 TRACE("(%p)->(%p)\n", This
, latency
);
1045 EnterCriticalSection(&This
->lock
);
1048 LeaveCriticalSection(&This
->lock
);
1049 return AUDCLNT_E_NOT_INITIALIZED
;
1052 /* pretend we process audio in Period chunks, so max latency includes
1053 * the period time. Some native machines add .6666ms in shared mode. */
1054 *latency
= This
->period_us
* 10 + 6666;
1056 LeaveCriticalSection(&This
->lock
);
1061 static HRESULT WINAPI
AudioClient_GetCurrentPadding(IAudioClient
*iface
,
1064 ACImpl
*This
= impl_from_IAudioClient(iface
);
1066 TRACE("(%p)->(%p)\n", This
, numpad
);
1071 EnterCriticalSection(&This
->lock
);
1074 LeaveCriticalSection(&This
->lock
);
1075 return AUDCLNT_E_NOT_INITIALIZED
;
1078 *numpad
= This
->held_frames
;
1080 TRACE("padding: %u\n", *numpad
);
1082 LeaveCriticalSection(&This
->lock
);
1087 static HRESULT WINAPI
AudioClient_IsFormatSupported(IAudioClient
*iface
,
1088 AUDCLNT_SHAREMODE mode
, const WAVEFORMATEX
*pwfx
,
1089 WAVEFORMATEX
**outpwfx
)
1091 ACImpl
*This
= impl_from_IAudioClient(iface
);
1095 TRACE("(%p)->(%x, %p, %p)\n", This
, mode
, pwfx
, outpwfx
);
1097 if(!pwfx
|| (mode
== AUDCLNT_SHAREMODE_SHARED
&& !outpwfx
))
1100 if(mode
!= AUDCLNT_SHAREMODE_SHARED
&& mode
!= AUDCLNT_SHAREMODE_EXCLUSIVE
)
1101 return E_INVALIDARG
;
1103 if(pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
1104 pwfx
->cbSize
< sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
))
1105 return E_INVALIDARG
;
1111 if(mode
!= AUDCLNT_SHAREMODE_SHARED
)
1115 if(This
->dataflow
== eRender
)
1116 fd
= open(This
->devnode
, O_WRONLY
| O_NONBLOCK
, 0);
1117 else if(This
->dataflow
== eCapture
)
1118 fd
= open(This
->devnode
, O_RDONLY
| O_NONBLOCK
, 0);
1121 ERR("Unable to open device %s: %d (%s)\n", This
->devnode
, errno
,
1123 return AUDCLNT_E_DEVICE_INVALIDATED
;
1126 ret
= setup_oss_device(fd
, pwfx
, outpwfx
, TRUE
);
1133 static HRESULT WINAPI
AudioClient_GetMixFormat(IAudioClient
*iface
,
1134 WAVEFORMATEX
**pwfx
)
1136 ACImpl
*This
= impl_from_IAudioClient(iface
);
1137 WAVEFORMATEXTENSIBLE
*fmt
;
1140 TRACE("(%p)->(%p)\n", This
, pwfx
);
1146 if(This
->dataflow
== eRender
)
1147 formats
= This
->ai
.oformats
;
1148 else if(This
->dataflow
== eCapture
)
1149 formats
= This
->ai
.iformats
;
1151 return E_UNEXPECTED
;
1153 fmt
= CoTaskMemAlloc(sizeof(WAVEFORMATEXTENSIBLE
));
1155 return E_OUTOFMEMORY
;
1157 fmt
->Format
.wFormatTag
= WAVE_FORMAT_EXTENSIBLE
;
1158 if(formats
& AFMT_S16_LE
){
1159 fmt
->Format
.wBitsPerSample
= 16;
1160 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1162 }else if(formats
& AFMT_FLOAT
){
1163 fmt
->Format
.wBitsPerSample
= 32;
1164 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
1166 }else if(formats
& AFMT_U8
){
1167 fmt
->Format
.wBitsPerSample
= 8;
1168 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1169 }else if(formats
& AFMT_S32_LE
){
1170 fmt
->Format
.wBitsPerSample
= 32;
1171 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1172 }else if(formats
& AFMT_S24_LE
){
1173 fmt
->Format
.wBitsPerSample
= 24;
1174 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1176 ERR("Didn't recognize any available OSS formats: %x\n", formats
);
1181 fmt
->Format
.nChannels
= This
->ai
.max_channels
;
1182 fmt
->Format
.nSamplesPerSec
= This
->ai
.max_rate
;
1183 fmt
->dwChannelMask
= get_channel_mask(fmt
->Format
.nChannels
);
1185 fmt
->Format
.nBlockAlign
= (fmt
->Format
.wBitsPerSample
*
1186 fmt
->Format
.nChannels
) / 8;
1187 fmt
->Format
.nAvgBytesPerSec
= fmt
->Format
.nSamplesPerSec
*
1188 fmt
->Format
.nBlockAlign
;
1190 fmt
->Samples
.wValidBitsPerSample
= fmt
->Format
.wBitsPerSample
;
1191 fmt
->Format
.cbSize
= sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
);
1193 *pwfx
= (WAVEFORMATEX
*)fmt
;
1199 static HRESULT WINAPI
AudioClient_GetDevicePeriod(IAudioClient
*iface
,
1200 REFERENCE_TIME
*defperiod
, REFERENCE_TIME
*minperiod
)
1202 ACImpl
*This
= impl_from_IAudioClient(iface
);
1204 TRACE("(%p)->(%p, %p)\n", This
, defperiod
, minperiod
);
1206 if(!defperiod
&& !minperiod
)
1210 *defperiod
= DefaultPeriod
;
1212 *minperiod
= MinimumPeriod
;
1217 static void oss_silence_buffer(ACImpl
*This
, BYTE
*buf
, UINT32 frames
)
1219 if(This
->fmt
->wBitsPerSample
== 8)
1220 memset(buf
, 128, frames
* This
->fmt
->nBlockAlign
);
1222 memset(buf
, 0, frames
* This
->fmt
->nBlockAlign
);
1225 static void oss_write_data(ACImpl
*This
)
1227 ssize_t written_bytes
;
1228 UINT32 written_frames
, in_oss_frames
, write_limit
, max_period
;
1229 size_t to_write_frames
, to_write_bytes
;
1232 This
->local_buffer
+ (This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
);
1234 if(This
->held_frames
== 0)
1237 if(This
->lcl_offs_frames
+ This
->held_frames
> This
->bufsize_frames
)
1238 to_write_frames
= This
->bufsize_frames
- This
->lcl_offs_frames
;
1240 to_write_frames
= This
->held_frames
;
1242 if(ioctl(This
->fd
, SNDCTL_DSP_GETOSPACE
, &bi
) < 0){
1243 WARN("GETOSPACE failed: %d (%s)\n", errno
, strerror(errno
));
1247 max_period
= max(bi
.fragsize
/ This
->fmt
->nBlockAlign
, This
->period_frames
);
1249 if(bi
.bytes
> This
->oss_bufsize_bytes
){
1250 TRACE("New buffer size (%u) is larger than old buffer size (%u)\n",
1251 bi
.bytes
, This
->oss_bufsize_bytes
);
1252 This
->oss_bufsize_bytes
= bi
.bytes
;
1254 }else if(This
->oss_bufsize_bytes
- bi
.bytes
<= bi
.fragsize
)
1257 in_oss_frames
= (This
->oss_bufsize_bytes
- bi
.bytes
) / This
->fmt
->nBlockAlign
;
1260 while(write_limit
+ in_oss_frames
< max_period
* 3)
1261 write_limit
+= max_period
;
1262 if(write_limit
== 0)
1265 to_write_frames
= min(to_write_frames
, write_limit
);
1266 to_write_bytes
= to_write_frames
* This
->fmt
->nBlockAlign
;
1268 if(This
->session
->mute
)
1269 oss_silence_buffer(This
, buf
, to_write_frames
);
1271 written_bytes
= write(This
->fd
, buf
, to_write_bytes
);
1272 if(written_bytes
< 0){
1273 /* EAGAIN is OSS buffer full, log that too */
1274 WARN("write failed: %d (%s)\n", errno
, strerror(errno
));
1277 written_frames
= written_bytes
/ This
->fmt
->nBlockAlign
;
1279 This
->lcl_offs_frames
+= written_frames
;
1280 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1281 This
->held_frames
-= written_frames
;
1283 if(written_frames
< to_write_frames
){
1284 /* OSS buffer probably full */
1288 if(This
->held_frames
&& written_frames
< write_limit
){
1289 /* wrapped and have some data back at the start to write */
1291 to_write_frames
= min(write_limit
- written_frames
, This
->held_frames
);
1292 to_write_bytes
= to_write_frames
* This
->fmt
->nBlockAlign
;
1294 if(This
->session
->mute
)
1295 oss_silence_buffer(This
, This
->local_buffer
, to_write_frames
);
1297 written_bytes
= write(This
->fd
, This
->local_buffer
, to_write_bytes
);
1298 if(written_bytes
< 0){
1299 WARN("write failed: %d (%s)\n", errno
, strerror(errno
));
1302 written_frames
= written_bytes
/ This
->fmt
->nBlockAlign
;
1304 This
->lcl_offs_frames
+= written_frames
;
1305 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1306 This
->held_frames
-= written_frames
;
1310 static void oss_read_data(ACImpl
*This
)
1312 UINT64 pos
, readable
;
1316 if(ioctl(This
->fd
, SNDCTL_DSP_GETISPACE
, &bi
) < 0){
1317 WARN("GETISPACE failed: %d (%s)\n", errno
, strerror(errno
));
1321 pos
= (This
->held_frames
+ This
->lcl_offs_frames
) % This
->bufsize_frames
;
1322 readable
= (This
->bufsize_frames
- pos
) * This
->fmt
->nBlockAlign
;
1324 if(bi
.bytes
< readable
)
1325 readable
= bi
.bytes
;
1327 nread
= read(This
->fd
, This
->local_buffer
+ pos
* This
->fmt
->nBlockAlign
,
1330 WARN("read failed: %d (%s)\n", errno
, strerror(errno
));
1334 This
->held_frames
+= nread
/ This
->fmt
->nBlockAlign
;
1336 if(This
->held_frames
> This
->bufsize_frames
){
1337 WARN("Overflow of unread data\n");
1338 This
->lcl_offs_frames
+= This
->held_frames
;
1339 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1340 This
->held_frames
= This
->bufsize_frames
;
1344 static void CALLBACK
oss_period_callback(void *user
, BOOLEAN timer
)
1346 ACImpl
*This
= user
;
1348 EnterCriticalSection(&This
->lock
);
1350 if(This
->dataflow
== eRender
&& This
->held_frames
)
1351 oss_write_data(This
);
1352 else if(This
->dataflow
== eCapture
)
1353 oss_read_data(This
);
1356 SetEvent(This
->event
);
1358 LeaveCriticalSection(&This
->lock
);
1361 static HRESULT WINAPI
AudioClient_Start(IAudioClient
*iface
)
1363 ACImpl
*This
= impl_from_IAudioClient(iface
);
1365 TRACE("(%p)\n", This
);
1367 EnterCriticalSection(&This
->lock
);
1370 LeaveCriticalSection(&This
->lock
);
1371 return AUDCLNT_E_NOT_INITIALIZED
;
1374 if((This
->flags
& AUDCLNT_STREAMFLAGS_EVENTCALLBACK
) && !This
->event
){
1375 LeaveCriticalSection(&This
->lock
);
1376 return AUDCLNT_E_EVENTHANDLE_NOT_SET
;
1380 LeaveCriticalSection(&This
->lock
);
1381 return AUDCLNT_E_NOT_STOPPED
;
1384 if(!CreateTimerQueueTimer(&This
->timer
, g_timer_q
,
1385 oss_period_callback
, This
, 0, This
->period_us
/ 1000,
1386 WT_EXECUTEINTIMERTHREAD
))
1387 ERR("Unable to create period timer: %u\n", GetLastError());
1389 This
->playing
= TRUE
;
1391 LeaveCriticalSection(&This
->lock
);
1396 static HRESULT WINAPI
AudioClient_Stop(IAudioClient
*iface
)
1398 ACImpl
*This
= impl_from_IAudioClient(iface
);
1400 TRACE("(%p)\n", This
);
1402 EnterCriticalSection(&This
->lock
);
1405 LeaveCriticalSection(&This
->lock
);
1406 return AUDCLNT_E_NOT_INITIALIZED
;
1410 LeaveCriticalSection(&This
->lock
);
1414 if(This
->timer
&& This
->timer
!= INVALID_HANDLE_VALUE
){
1415 DeleteTimerQueueTimer(g_timer_q
, This
->timer
,
1416 INVALID_HANDLE_VALUE
);
1420 This
->playing
= FALSE
;
1422 LeaveCriticalSection(&This
->lock
);
1427 static HRESULT WINAPI
AudioClient_Reset(IAudioClient
*iface
)
1429 ACImpl
*This
= impl_from_IAudioClient(iface
);
1431 TRACE("(%p)\n", This
);
1433 EnterCriticalSection(&This
->lock
);
1436 LeaveCriticalSection(&This
->lock
);
1437 return AUDCLNT_E_NOT_INITIALIZED
;
1441 LeaveCriticalSection(&This
->lock
);
1442 return AUDCLNT_E_NOT_STOPPED
;
1445 if(This
->buf_state
!= NOT_LOCKED
|| This
->getbuf_last
){
1446 LeaveCriticalSection(&This
->lock
);
1447 return AUDCLNT_E_BUFFER_OPERATION_PENDING
;
1450 if(This
->dataflow
== eRender
){
1451 This
->written_frames
= 0;
1453 This
->written_frames
+= This
->held_frames
;
1455 This
->lcl_offs_frames
= 0;
1456 This
->held_frames
= 0;
1457 This
->last_pos_frames
= 0;
1459 LeaveCriticalSection(&This
->lock
);
1464 static HRESULT WINAPI
AudioClient_SetEventHandle(IAudioClient
*iface
,
1467 ACImpl
*This
= impl_from_IAudioClient(iface
);
1469 TRACE("(%p)->(%p)\n", This
, event
);
1472 return E_INVALIDARG
;
1474 EnterCriticalSection(&This
->lock
);
1477 LeaveCriticalSection(&This
->lock
);
1478 return AUDCLNT_E_NOT_INITIALIZED
;
1481 if(!(This
->flags
& AUDCLNT_STREAMFLAGS_EVENTCALLBACK
)){
1482 LeaveCriticalSection(&This
->lock
);
1483 return AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED
;
1486 This
->event
= event
;
1488 LeaveCriticalSection(&This
->lock
);
1493 static HRESULT WINAPI
AudioClient_GetService(IAudioClient
*iface
, REFIID riid
,
1496 ACImpl
*This
= impl_from_IAudioClient(iface
);
1498 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1504 EnterCriticalSection(&This
->lock
);
1507 LeaveCriticalSection(&This
->lock
);
1508 return AUDCLNT_E_NOT_INITIALIZED
;
1511 if(IsEqualIID(riid
, &IID_IAudioRenderClient
)){
1512 if(This
->dataflow
!= eRender
){
1513 LeaveCriticalSection(&This
->lock
);
1514 return AUDCLNT_E_WRONG_ENDPOINT_TYPE
;
1516 IAudioRenderClient_AddRef(&This
->IAudioRenderClient_iface
);
1517 *ppv
= &This
->IAudioRenderClient_iface
;
1518 }else if(IsEqualIID(riid
, &IID_IAudioCaptureClient
)){
1519 if(This
->dataflow
!= eCapture
){
1520 LeaveCriticalSection(&This
->lock
);
1521 return AUDCLNT_E_WRONG_ENDPOINT_TYPE
;
1523 IAudioCaptureClient_AddRef(&This
->IAudioCaptureClient_iface
);
1524 *ppv
= &This
->IAudioCaptureClient_iface
;
1525 }else if(IsEqualIID(riid
, &IID_IAudioClock
)){
1526 IAudioClock_AddRef(&This
->IAudioClock_iface
);
1527 *ppv
= &This
->IAudioClock_iface
;
1528 }else if(IsEqualIID(riid
, &IID_IAudioStreamVolume
)){
1529 IAudioStreamVolume_AddRef(&This
->IAudioStreamVolume_iface
);
1530 *ppv
= &This
->IAudioStreamVolume_iface
;
1531 }else if(IsEqualIID(riid
, &IID_IAudioSessionControl
)){
1532 if(!This
->session_wrapper
){
1533 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1534 if(!This
->session_wrapper
){
1535 LeaveCriticalSection(&This
->lock
);
1536 return E_OUTOFMEMORY
;
1539 IAudioSessionControl2_AddRef(&This
->session_wrapper
->IAudioSessionControl2_iface
);
1541 *ppv
= &This
->session_wrapper
->IAudioSessionControl2_iface
;
1542 }else if(IsEqualIID(riid
, &IID_IChannelAudioVolume
)){
1543 if(!This
->session_wrapper
){
1544 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1545 if(!This
->session_wrapper
){
1546 LeaveCriticalSection(&This
->lock
);
1547 return E_OUTOFMEMORY
;
1550 IChannelAudioVolume_AddRef(&This
->session_wrapper
->IChannelAudioVolume_iface
);
1552 *ppv
= &This
->session_wrapper
->IChannelAudioVolume_iface
;
1553 }else if(IsEqualIID(riid
, &IID_ISimpleAudioVolume
)){
1554 if(!This
->session_wrapper
){
1555 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1556 if(!This
->session_wrapper
){
1557 LeaveCriticalSection(&This
->lock
);
1558 return E_OUTOFMEMORY
;
1561 ISimpleAudioVolume_AddRef(&This
->session_wrapper
->ISimpleAudioVolume_iface
);
1563 *ppv
= &This
->session_wrapper
->ISimpleAudioVolume_iface
;
1567 LeaveCriticalSection(&This
->lock
);
1571 LeaveCriticalSection(&This
->lock
);
1573 FIXME("stub %s\n", debugstr_guid(riid
));
1574 return E_NOINTERFACE
;
1577 static const IAudioClientVtbl AudioClient_Vtbl
=
1579 AudioClient_QueryInterface
,
1581 AudioClient_Release
,
1582 AudioClient_Initialize
,
1583 AudioClient_GetBufferSize
,
1584 AudioClient_GetStreamLatency
,
1585 AudioClient_GetCurrentPadding
,
1586 AudioClient_IsFormatSupported
,
1587 AudioClient_GetMixFormat
,
1588 AudioClient_GetDevicePeriod
,
1592 AudioClient_SetEventHandle
,
1593 AudioClient_GetService
1596 static HRESULT WINAPI
AudioRenderClient_QueryInterface(
1597 IAudioRenderClient
*iface
, REFIID riid
, void **ppv
)
1599 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1605 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1606 IsEqualIID(riid
, &IID_IAudioRenderClient
))
1609 IUnknown_AddRef((IUnknown
*)*ppv
);
1613 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1614 return E_NOINTERFACE
;
1617 static ULONG WINAPI
AudioRenderClient_AddRef(IAudioRenderClient
*iface
)
1619 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1620 return AudioClient_AddRef(&This
->IAudioClient_iface
);
1623 static ULONG WINAPI
AudioRenderClient_Release(IAudioRenderClient
*iface
)
1625 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1626 return AudioClient_Release(&This
->IAudioClient_iface
);
1629 static HRESULT WINAPI
AudioRenderClient_GetBuffer(IAudioRenderClient
*iface
,
1630 UINT32 frames
, BYTE
**data
)
1632 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1633 UINT32 pad
, write_pos
;
1636 TRACE("(%p)->(%u, %p)\n", This
, frames
, data
);
1643 EnterCriticalSection(&This
->lock
);
1645 if(This
->getbuf_last
){
1646 LeaveCriticalSection(&This
->lock
);
1647 return AUDCLNT_E_OUT_OF_ORDER
;
1651 LeaveCriticalSection(&This
->lock
);
1655 hr
= IAudioClient_GetCurrentPadding(&This
->IAudioClient_iface
, &pad
);
1657 LeaveCriticalSection(&This
->lock
);
1661 if(pad
+ frames
> This
->bufsize_frames
){
1662 LeaveCriticalSection(&This
->lock
);
1663 return AUDCLNT_E_BUFFER_TOO_LARGE
;
1667 (This
->lcl_offs_frames
+ This
->held_frames
) % This
->bufsize_frames
;
1668 if(write_pos
+ frames
> This
->bufsize_frames
){
1669 if(This
->tmp_buffer_frames
< frames
){
1670 HeapFree(GetProcessHeap(), 0, This
->tmp_buffer
);
1671 This
->tmp_buffer
= HeapAlloc(GetProcessHeap(), 0,
1672 frames
* This
->fmt
->nBlockAlign
);
1673 if(!This
->tmp_buffer
){
1674 LeaveCriticalSection(&This
->lock
);
1675 return E_OUTOFMEMORY
;
1677 This
->tmp_buffer_frames
= frames
;
1679 *data
= This
->tmp_buffer
;
1680 This
->getbuf_last
= -frames
;
1682 *data
= This
->local_buffer
+ write_pos
* This
->fmt
->nBlockAlign
;
1683 This
->getbuf_last
= frames
;
1686 LeaveCriticalSection(&This
->lock
);
1691 static void oss_wrap_buffer(ACImpl
*This
, BYTE
*buffer
, UINT32 written_frames
)
1693 UINT32 write_offs_frames
=
1694 (This
->lcl_offs_frames
+ This
->held_frames
) % This
->bufsize_frames
;
1695 UINT32 write_offs_bytes
= write_offs_frames
* This
->fmt
->nBlockAlign
;
1696 UINT32 chunk_frames
= This
->bufsize_frames
- write_offs_frames
;
1697 UINT32 chunk_bytes
= chunk_frames
* This
->fmt
->nBlockAlign
;
1698 UINT32 written_bytes
= written_frames
* This
->fmt
->nBlockAlign
;
1700 if(written_bytes
<= chunk_bytes
){
1701 memcpy(This
->local_buffer
+ write_offs_bytes
, buffer
, written_bytes
);
1703 memcpy(This
->local_buffer
+ write_offs_bytes
, buffer
, chunk_bytes
);
1704 memcpy(This
->local_buffer
, buffer
+ chunk_bytes
,
1705 written_bytes
- chunk_bytes
);
1709 static HRESULT WINAPI
AudioRenderClient_ReleaseBuffer(
1710 IAudioRenderClient
*iface
, UINT32 written_frames
, DWORD flags
)
1712 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1715 TRACE("(%p)->(%u, %x)\n", This
, written_frames
, flags
);
1717 EnterCriticalSection(&This
->lock
);
1719 if(!written_frames
){
1720 This
->getbuf_last
= 0;
1721 LeaveCriticalSection(&This
->lock
);
1725 if(!This
->getbuf_last
){
1726 LeaveCriticalSection(&This
->lock
);
1727 return AUDCLNT_E_OUT_OF_ORDER
;
1730 if(written_frames
> (This
->getbuf_last
>= 0 ? This
->getbuf_last
: -This
->getbuf_last
)){
1731 LeaveCriticalSection(&This
->lock
);
1732 return AUDCLNT_E_INVALID_SIZE
;
1735 if(This
->getbuf_last
>= 0)
1736 buffer
= This
->local_buffer
+ This
->fmt
->nBlockAlign
*
1737 ((This
->lcl_offs_frames
+ This
->held_frames
) % This
->bufsize_frames
);
1739 buffer
= This
->tmp_buffer
;
1741 if(flags
& AUDCLNT_BUFFERFLAGS_SILENT
)
1742 oss_silence_buffer(This
, buffer
, written_frames
);
1744 if(This
->getbuf_last
< 0)
1745 oss_wrap_buffer(This
, buffer
, written_frames
);
1747 This
->held_frames
+= written_frames
;
1748 This
->written_frames
+= written_frames
;
1749 This
->getbuf_last
= 0;
1751 LeaveCriticalSection(&This
->lock
);
1756 static const IAudioRenderClientVtbl AudioRenderClient_Vtbl
= {
1757 AudioRenderClient_QueryInterface
,
1758 AudioRenderClient_AddRef
,
1759 AudioRenderClient_Release
,
1760 AudioRenderClient_GetBuffer
,
1761 AudioRenderClient_ReleaseBuffer
1764 static HRESULT WINAPI
AudioCaptureClient_QueryInterface(
1765 IAudioCaptureClient
*iface
, REFIID riid
, void **ppv
)
1767 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1773 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1774 IsEqualIID(riid
, &IID_IAudioCaptureClient
))
1777 IUnknown_AddRef((IUnknown
*)*ppv
);
1781 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1782 return E_NOINTERFACE
;
1785 static ULONG WINAPI
AudioCaptureClient_AddRef(IAudioCaptureClient
*iface
)
1787 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1788 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
1791 static ULONG WINAPI
AudioCaptureClient_Release(IAudioCaptureClient
*iface
)
1793 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1794 return IAudioClient_Release(&This
->IAudioClient_iface
);
1797 static HRESULT WINAPI
AudioCaptureClient_GetBuffer(IAudioCaptureClient
*iface
,
1798 BYTE
**data
, UINT32
*frames
, DWORD
*flags
, UINT64
*devpos
,
1801 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1804 TRACE("(%p)->(%p, %p, %p, %p, %p)\n", This
, data
, frames
, flags
,
1807 if(!data
|| !frames
|| !flags
)
1810 EnterCriticalSection(&This
->lock
);
1812 if(This
->buf_state
!= NOT_LOCKED
){
1813 LeaveCriticalSection(&This
->lock
);
1814 return AUDCLNT_E_OUT_OF_ORDER
;
1817 hr
= IAudioCaptureClient_GetNextPacketSize(iface
, frames
);
1819 LeaveCriticalSection(&This
->lock
);
1825 if(This
->lcl_offs_frames
+ *frames
> This
->bufsize_frames
){
1826 UINT32 chunk_bytes
, offs_bytes
, frames_bytes
;
1827 if(This
->tmp_buffer_frames
< *frames
){
1828 HeapFree(GetProcessHeap(), 0, This
->tmp_buffer
);
1829 This
->tmp_buffer
= HeapAlloc(GetProcessHeap(), 0,
1830 *frames
* This
->fmt
->nBlockAlign
);
1831 if(!This
->tmp_buffer
){
1832 LeaveCriticalSection(&This
->lock
);
1833 return E_OUTOFMEMORY
;
1835 This
->tmp_buffer_frames
= *frames
;
1838 *data
= This
->tmp_buffer
;
1839 chunk_bytes
= (This
->bufsize_frames
- This
->lcl_offs_frames
) *
1840 This
->fmt
->nBlockAlign
;
1841 offs_bytes
= This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
;
1842 frames_bytes
= *frames
* This
->fmt
->nBlockAlign
;
1843 memcpy(This
->tmp_buffer
, This
->local_buffer
+ offs_bytes
, chunk_bytes
);
1844 memcpy(This
->tmp_buffer
+ chunk_bytes
, This
->local_buffer
,
1845 frames_bytes
- chunk_bytes
);
1847 *data
= This
->local_buffer
+
1848 This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
;
1850 This
->buf_state
= LOCKED_NORMAL
;
1852 if(devpos
|| qpcpos
)
1853 IAudioClock_GetPosition(&This
->IAudioClock_iface
, devpos
, qpcpos
);
1855 LeaveCriticalSection(&This
->lock
);
1857 return *frames
? S_OK
: AUDCLNT_S_BUFFER_EMPTY
;
1860 static HRESULT WINAPI
AudioCaptureClient_ReleaseBuffer(
1861 IAudioCaptureClient
*iface
, UINT32 done
)
1863 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1865 TRACE("(%p)->(%u)\n", This
, done
);
1867 EnterCriticalSection(&This
->lock
);
1869 if(This
->buf_state
== NOT_LOCKED
){
1870 LeaveCriticalSection(&This
->lock
);
1871 return AUDCLNT_E_OUT_OF_ORDER
;
1874 This
->held_frames
-= done
;
1875 This
->lcl_offs_frames
+= done
;
1876 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1878 This
->buf_state
= NOT_LOCKED
;
1880 LeaveCriticalSection(&This
->lock
);
1885 static HRESULT WINAPI
AudioCaptureClient_GetNextPacketSize(
1886 IAudioCaptureClient
*iface
, UINT32
*frames
)
1888 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1890 TRACE("(%p)->(%p)\n", This
, frames
);
1892 return AudioClient_GetCurrentPadding(&This
->IAudioClient_iface
, frames
);
1895 static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl
=
1897 AudioCaptureClient_QueryInterface
,
1898 AudioCaptureClient_AddRef
,
1899 AudioCaptureClient_Release
,
1900 AudioCaptureClient_GetBuffer
,
1901 AudioCaptureClient_ReleaseBuffer
,
1902 AudioCaptureClient_GetNextPacketSize
1905 static HRESULT WINAPI
AudioClock_QueryInterface(IAudioClock
*iface
,
1906 REFIID riid
, void **ppv
)
1908 ACImpl
*This
= impl_from_IAudioClock(iface
);
1910 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1916 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IAudioClock
))
1918 else if(IsEqualIID(riid
, &IID_IAudioClock2
))
1919 *ppv
= &This
->IAudioClock2_iface
;
1921 IUnknown_AddRef((IUnknown
*)*ppv
);
1925 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1926 return E_NOINTERFACE
;
1929 static ULONG WINAPI
AudioClock_AddRef(IAudioClock
*iface
)
1931 ACImpl
*This
= impl_from_IAudioClock(iface
);
1932 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
1935 static ULONG WINAPI
AudioClock_Release(IAudioClock
*iface
)
1937 ACImpl
*This
= impl_from_IAudioClock(iface
);
1938 return IAudioClient_Release(&This
->IAudioClient_iface
);
1941 static HRESULT WINAPI
AudioClock_GetFrequency(IAudioClock
*iface
, UINT64
*freq
)
1943 ACImpl
*This
= impl_from_IAudioClock(iface
);
1945 TRACE("(%p)->(%p)\n", This
, freq
);
1947 *freq
= This
->fmt
->nSamplesPerSec
;
1952 static HRESULT WINAPI
AudioClock_GetPosition(IAudioClock
*iface
, UINT64
*pos
,
1955 ACImpl
*This
= impl_from_IAudioClock(iface
);
1958 TRACE("(%p)->(%p, %p)\n", This
, pos
, qpctime
);
1963 EnterCriticalSection(&This
->lock
);
1965 if(This
->dataflow
== eRender
){
1966 if(!This
->playing
|| !This
->held_frames
||
1967 ioctl(This
->fd
, SNDCTL_DSP_GETODELAY
, &delay
) < 0)
1970 delay
/= This
->fmt
->nBlockAlign
;
1971 if(This
->held_frames
+ delay
>= This
->written_frames
)
1972 *pos
= This
->last_pos_frames
;
1974 *pos
= This
->written_frames
- This
->held_frames
- delay
;
1975 if(*pos
< This
->last_pos_frames
)
1976 *pos
= This
->last_pos_frames
;
1978 }else if(This
->dataflow
== eCapture
){
1982 if(ioctl(This
->fd
, SNDCTL_DSP_GETISPACE
, &bi
) < 0){
1983 TRACE("GETISPACE failed: %d (%s)\n", errno
, strerror(errno
));
1986 if(bi
.bytes
<= bi
.fragsize
)
1989 held
= bi
.bytes
/ This
->fmt
->nBlockAlign
;
1992 *pos
= This
->written_frames
+ held
;
1995 This
->last_pos_frames
= *pos
;
1997 LeaveCriticalSection(&This
->lock
);
2000 LARGE_INTEGER stamp
, freq
;
2001 QueryPerformanceCounter(&stamp
);
2002 QueryPerformanceFrequency(&freq
);
2003 *qpctime
= (stamp
.QuadPart
* (INT64
)10000000) / freq
.QuadPart
;
2009 static HRESULT WINAPI
AudioClock_GetCharacteristics(IAudioClock
*iface
,
2012 ACImpl
*This
= impl_from_IAudioClock(iface
);
2014 TRACE("(%p)->(%p)\n", This
, chars
);
2019 *chars
= AUDIOCLOCK_CHARACTERISTIC_FIXED_FREQ
;
2024 static const IAudioClockVtbl AudioClock_Vtbl
=
2026 AudioClock_QueryInterface
,
2029 AudioClock_GetFrequency
,
2030 AudioClock_GetPosition
,
2031 AudioClock_GetCharacteristics
2034 static HRESULT WINAPI
AudioClock2_QueryInterface(IAudioClock2
*iface
,
2035 REFIID riid
, void **ppv
)
2037 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2038 return IAudioClock_QueryInterface(&This
->IAudioClock_iface
, riid
, ppv
);
2041 static ULONG WINAPI
AudioClock2_AddRef(IAudioClock2
*iface
)
2043 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2044 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
2047 static ULONG WINAPI
AudioClock2_Release(IAudioClock2
*iface
)
2049 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2050 return IAudioClient_Release(&This
->IAudioClient_iface
);
2053 static HRESULT WINAPI
AudioClock2_GetDevicePosition(IAudioClock2
*iface
,
2054 UINT64
*pos
, UINT64
*qpctime
)
2056 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2058 FIXME("(%p)->(%p, %p)\n", This
, pos
, qpctime
);
2063 static const IAudioClock2Vtbl AudioClock2_Vtbl
=
2065 AudioClock2_QueryInterface
,
2067 AudioClock2_Release
,
2068 AudioClock2_GetDevicePosition
2071 static AudioSessionWrapper
*AudioSessionWrapper_Create(ACImpl
*client
)
2073 AudioSessionWrapper
*ret
;
2075 ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2076 sizeof(AudioSessionWrapper
));
2080 ret
->IAudioSessionControl2_iface
.lpVtbl
= &AudioSessionControl2_Vtbl
;
2081 ret
->ISimpleAudioVolume_iface
.lpVtbl
= &SimpleAudioVolume_Vtbl
;
2082 ret
->IChannelAudioVolume_iface
.lpVtbl
= &ChannelAudioVolume_Vtbl
;
2086 ret
->client
= client
;
2088 ret
->session
= client
->session
;
2089 AudioClient_AddRef(&client
->IAudioClient_iface
);
2095 static HRESULT WINAPI
AudioSessionControl_QueryInterface(
2096 IAudioSessionControl2
*iface
, REFIID riid
, void **ppv
)
2098 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2104 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2105 IsEqualIID(riid
, &IID_IAudioSessionControl
) ||
2106 IsEqualIID(riid
, &IID_IAudioSessionControl2
))
2109 IUnknown_AddRef((IUnknown
*)*ppv
);
2113 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2114 return E_NOINTERFACE
;
2117 static ULONG WINAPI
AudioSessionControl_AddRef(IAudioSessionControl2
*iface
)
2119 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2121 ref
= InterlockedIncrement(&This
->ref
);
2122 TRACE("(%p) Refcount now %u\n", This
, ref
);
2126 static ULONG WINAPI
AudioSessionControl_Release(IAudioSessionControl2
*iface
)
2128 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2130 ref
= InterlockedDecrement(&This
->ref
);
2131 TRACE("(%p) Refcount now %u\n", This
, ref
);
2134 EnterCriticalSection(&This
->client
->lock
);
2135 This
->client
->session_wrapper
= NULL
;
2136 LeaveCriticalSection(&This
->client
->lock
);
2137 AudioClient_Release(&This
->client
->IAudioClient_iface
);
2139 HeapFree(GetProcessHeap(), 0, This
);
2144 static HRESULT WINAPI
AudioSessionControl_GetState(IAudioSessionControl2
*iface
,
2145 AudioSessionState
*state
)
2147 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2150 TRACE("(%p)->(%p)\n", This
, state
);
2153 return NULL_PTR_ERR
;
2155 EnterCriticalSection(&g_sessions_lock
);
2157 if(list_empty(&This
->session
->clients
)){
2158 *state
= AudioSessionStateExpired
;
2159 LeaveCriticalSection(&g_sessions_lock
);
2163 LIST_FOR_EACH_ENTRY(client
, &This
->session
->clients
, ACImpl
, entry
){
2164 EnterCriticalSection(&client
->lock
);
2165 if(client
->playing
){
2166 *state
= AudioSessionStateActive
;
2167 LeaveCriticalSection(&client
->lock
);
2168 LeaveCriticalSection(&g_sessions_lock
);
2171 LeaveCriticalSection(&client
->lock
);
2174 LeaveCriticalSection(&g_sessions_lock
);
2176 *state
= AudioSessionStateInactive
;
2181 static HRESULT WINAPI
AudioSessionControl_GetDisplayName(
2182 IAudioSessionControl2
*iface
, WCHAR
**name
)
2184 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2186 FIXME("(%p)->(%p) - stub\n", This
, name
);
2191 static HRESULT WINAPI
AudioSessionControl_SetDisplayName(
2192 IAudioSessionControl2
*iface
, const WCHAR
*name
, const GUID
*session
)
2194 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2196 FIXME("(%p)->(%p, %s) - stub\n", This
, name
, debugstr_guid(session
));
2201 static HRESULT WINAPI
AudioSessionControl_GetIconPath(
2202 IAudioSessionControl2
*iface
, WCHAR
**path
)
2204 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2206 FIXME("(%p)->(%p) - stub\n", This
, path
);
2211 static HRESULT WINAPI
AudioSessionControl_SetIconPath(
2212 IAudioSessionControl2
*iface
, const WCHAR
*path
, const GUID
*session
)
2214 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2216 FIXME("(%p)->(%p, %s) - stub\n", This
, path
, debugstr_guid(session
));
2221 static HRESULT WINAPI
AudioSessionControl_GetGroupingParam(
2222 IAudioSessionControl2
*iface
, GUID
*group
)
2224 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2226 FIXME("(%p)->(%p) - stub\n", This
, group
);
2231 static HRESULT WINAPI
AudioSessionControl_SetGroupingParam(
2232 IAudioSessionControl2
*iface
, const GUID
*group
, const GUID
*session
)
2234 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2236 FIXME("(%p)->(%s, %s) - stub\n", This
, debugstr_guid(group
),
2237 debugstr_guid(session
));
2242 static HRESULT WINAPI
AudioSessionControl_RegisterAudioSessionNotification(
2243 IAudioSessionControl2
*iface
, IAudioSessionEvents
*events
)
2245 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2247 FIXME("(%p)->(%p) - stub\n", This
, events
);
2252 static HRESULT WINAPI
AudioSessionControl_UnregisterAudioSessionNotification(
2253 IAudioSessionControl2
*iface
, IAudioSessionEvents
*events
)
2255 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2257 FIXME("(%p)->(%p) - stub\n", This
, events
);
2262 static HRESULT WINAPI
AudioSessionControl_GetSessionIdentifier(
2263 IAudioSessionControl2
*iface
, WCHAR
**id
)
2265 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2267 FIXME("(%p)->(%p) - stub\n", This
, id
);
2272 static HRESULT WINAPI
AudioSessionControl_GetSessionInstanceIdentifier(
2273 IAudioSessionControl2
*iface
, WCHAR
**id
)
2275 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2277 FIXME("(%p)->(%p) - stub\n", This
, id
);
2282 static HRESULT WINAPI
AudioSessionControl_GetProcessId(
2283 IAudioSessionControl2
*iface
, DWORD
*pid
)
2285 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2287 TRACE("(%p)->(%p)\n", This
, pid
);
2292 *pid
= GetCurrentProcessId();
2297 static HRESULT WINAPI
AudioSessionControl_IsSystemSoundsSession(
2298 IAudioSessionControl2
*iface
)
2300 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2302 TRACE("(%p)\n", This
);
2307 static HRESULT WINAPI
AudioSessionControl_SetDuckingPreference(
2308 IAudioSessionControl2
*iface
, BOOL optout
)
2310 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2312 TRACE("(%p)->(%d)\n", This
, optout
);
2317 static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl
=
2319 AudioSessionControl_QueryInterface
,
2320 AudioSessionControl_AddRef
,
2321 AudioSessionControl_Release
,
2322 AudioSessionControl_GetState
,
2323 AudioSessionControl_GetDisplayName
,
2324 AudioSessionControl_SetDisplayName
,
2325 AudioSessionControl_GetIconPath
,
2326 AudioSessionControl_SetIconPath
,
2327 AudioSessionControl_GetGroupingParam
,
2328 AudioSessionControl_SetGroupingParam
,
2329 AudioSessionControl_RegisterAudioSessionNotification
,
2330 AudioSessionControl_UnregisterAudioSessionNotification
,
2331 AudioSessionControl_GetSessionIdentifier
,
2332 AudioSessionControl_GetSessionInstanceIdentifier
,
2333 AudioSessionControl_GetProcessId
,
2334 AudioSessionControl_IsSystemSoundsSession
,
2335 AudioSessionControl_SetDuckingPreference
2338 static HRESULT WINAPI
SimpleAudioVolume_QueryInterface(
2339 ISimpleAudioVolume
*iface
, REFIID riid
, void **ppv
)
2341 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2347 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2348 IsEqualIID(riid
, &IID_ISimpleAudioVolume
))
2351 IUnknown_AddRef((IUnknown
*)*ppv
);
2355 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2356 return E_NOINTERFACE
;
2359 static ULONG WINAPI
SimpleAudioVolume_AddRef(ISimpleAudioVolume
*iface
)
2361 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2362 return AudioSessionControl_AddRef(&This
->IAudioSessionControl2_iface
);
2365 static ULONG WINAPI
SimpleAudioVolume_Release(ISimpleAudioVolume
*iface
)
2367 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2368 return AudioSessionControl_Release(&This
->IAudioSessionControl2_iface
);
2371 static HRESULT WINAPI
SimpleAudioVolume_SetMasterVolume(
2372 ISimpleAudioVolume
*iface
, float level
, const GUID
*context
)
2374 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2375 AudioSession
*session
= This
->session
;
2377 TRACE("(%p)->(%f, %s)\n", session
, level
, wine_dbgstr_guid(context
));
2379 if(level
< 0.f
|| level
> 1.f
)
2380 return E_INVALIDARG
;
2383 FIXME("Notifications not supported yet\n");
2385 EnterCriticalSection(&session
->lock
);
2387 session
->master_vol
= level
;
2389 TRACE("OSS doesn't support setting volume\n");
2391 LeaveCriticalSection(&session
->lock
);
2396 static HRESULT WINAPI
SimpleAudioVolume_GetMasterVolume(
2397 ISimpleAudioVolume
*iface
, float *level
)
2399 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2400 AudioSession
*session
= This
->session
;
2402 TRACE("(%p)->(%p)\n", session
, level
);
2405 return NULL_PTR_ERR
;
2407 *level
= session
->master_vol
;
2412 static HRESULT WINAPI
SimpleAudioVolume_SetMute(ISimpleAudioVolume
*iface
,
2413 BOOL mute
, const GUID
*context
)
2415 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2416 AudioSession
*session
= This
->session
;
2418 TRACE("(%p)->(%u, %p)\n", session
, mute
, context
);
2420 EnterCriticalSection(&session
->lock
);
2422 session
->mute
= mute
;
2424 LeaveCriticalSection(&session
->lock
);
2429 static HRESULT WINAPI
SimpleAudioVolume_GetMute(ISimpleAudioVolume
*iface
,
2432 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2433 AudioSession
*session
= This
->session
;
2435 TRACE("(%p)->(%p)\n", session
, mute
);
2438 return NULL_PTR_ERR
;
2440 *mute
= This
->session
->mute
;
2445 static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl
=
2447 SimpleAudioVolume_QueryInterface
,
2448 SimpleAudioVolume_AddRef
,
2449 SimpleAudioVolume_Release
,
2450 SimpleAudioVolume_SetMasterVolume
,
2451 SimpleAudioVolume_GetMasterVolume
,
2452 SimpleAudioVolume_SetMute
,
2453 SimpleAudioVolume_GetMute
2456 static HRESULT WINAPI
AudioStreamVolume_QueryInterface(
2457 IAudioStreamVolume
*iface
, REFIID riid
, void **ppv
)
2459 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2465 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2466 IsEqualIID(riid
, &IID_IAudioStreamVolume
))
2469 IUnknown_AddRef((IUnknown
*)*ppv
);
2473 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2474 return E_NOINTERFACE
;
2477 static ULONG WINAPI
AudioStreamVolume_AddRef(IAudioStreamVolume
*iface
)
2479 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2480 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
2483 static ULONG WINAPI
AudioStreamVolume_Release(IAudioStreamVolume
*iface
)
2485 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2486 return IAudioClient_Release(&This
->IAudioClient_iface
);
2489 static HRESULT WINAPI
AudioStreamVolume_GetChannelCount(
2490 IAudioStreamVolume
*iface
, UINT32
*out
)
2492 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2494 TRACE("(%p)->(%p)\n", This
, out
);
2499 *out
= This
->fmt
->nChannels
;
2504 static HRESULT WINAPI
AudioStreamVolume_SetChannelVolume(
2505 IAudioStreamVolume
*iface
, UINT32 index
, float level
)
2507 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2509 TRACE("(%p)->(%d, %f)\n", This
, index
, level
);
2511 if(level
< 0.f
|| level
> 1.f
)
2512 return E_INVALIDARG
;
2514 if(index
>= This
->fmt
->nChannels
)
2515 return E_INVALIDARG
;
2517 EnterCriticalSection(&This
->lock
);
2519 This
->vols
[index
] = level
;
2521 TRACE("OSS doesn't support setting volume\n");
2523 LeaveCriticalSection(&This
->lock
);
2528 static HRESULT WINAPI
AudioStreamVolume_GetChannelVolume(
2529 IAudioStreamVolume
*iface
, UINT32 index
, float *level
)
2531 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2533 TRACE("(%p)->(%d, %p)\n", This
, index
, level
);
2538 if(index
>= This
->fmt
->nChannels
)
2539 return E_INVALIDARG
;
2541 *level
= This
->vols
[index
];
2546 static HRESULT WINAPI
AudioStreamVolume_SetAllVolumes(
2547 IAudioStreamVolume
*iface
, UINT32 count
, const float *levels
)
2549 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2552 TRACE("(%p)->(%d, %p)\n", This
, count
, levels
);
2557 if(count
!= This
->fmt
->nChannels
)
2558 return E_INVALIDARG
;
2560 EnterCriticalSection(&This
->lock
);
2562 for(i
= 0; i
< count
; ++i
)
2563 This
->vols
[i
] = levels
[i
];
2565 TRACE("OSS doesn't support setting volume\n");
2567 LeaveCriticalSection(&This
->lock
);
2572 static HRESULT WINAPI
AudioStreamVolume_GetAllVolumes(
2573 IAudioStreamVolume
*iface
, UINT32 count
, float *levels
)
2575 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2578 TRACE("(%p)->(%d, %p)\n", This
, count
, levels
);
2583 if(count
!= This
->fmt
->nChannels
)
2584 return E_INVALIDARG
;
2586 EnterCriticalSection(&This
->lock
);
2588 for(i
= 0; i
< count
; ++i
)
2589 levels
[i
] = This
->vols
[i
];
2591 LeaveCriticalSection(&This
->lock
);
2596 static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl
=
2598 AudioStreamVolume_QueryInterface
,
2599 AudioStreamVolume_AddRef
,
2600 AudioStreamVolume_Release
,
2601 AudioStreamVolume_GetChannelCount
,
2602 AudioStreamVolume_SetChannelVolume
,
2603 AudioStreamVolume_GetChannelVolume
,
2604 AudioStreamVolume_SetAllVolumes
,
2605 AudioStreamVolume_GetAllVolumes
2608 static HRESULT WINAPI
ChannelAudioVolume_QueryInterface(
2609 IChannelAudioVolume
*iface
, REFIID riid
, void **ppv
)
2611 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2617 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2618 IsEqualIID(riid
, &IID_IChannelAudioVolume
))
2621 IUnknown_AddRef((IUnknown
*)*ppv
);
2625 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2626 return E_NOINTERFACE
;
2629 static ULONG WINAPI
ChannelAudioVolume_AddRef(IChannelAudioVolume
*iface
)
2631 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2632 return AudioSessionControl_AddRef(&This
->IAudioSessionControl2_iface
);
2635 static ULONG WINAPI
ChannelAudioVolume_Release(IChannelAudioVolume
*iface
)
2637 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2638 return AudioSessionControl_Release(&This
->IAudioSessionControl2_iface
);
2641 static HRESULT WINAPI
ChannelAudioVolume_GetChannelCount(
2642 IChannelAudioVolume
*iface
, UINT32
*out
)
2644 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2645 AudioSession
*session
= This
->session
;
2647 TRACE("(%p)->(%p)\n", session
, out
);
2650 return NULL_PTR_ERR
;
2652 *out
= session
->channel_count
;
2657 static HRESULT WINAPI
ChannelAudioVolume_SetChannelVolume(
2658 IChannelAudioVolume
*iface
, UINT32 index
, float level
,
2659 const GUID
*context
)
2661 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2662 AudioSession
*session
= This
->session
;
2664 TRACE("(%p)->(%d, %f, %s)\n", session
, index
, level
,
2665 wine_dbgstr_guid(context
));
2667 if(level
< 0.f
|| level
> 1.f
)
2668 return E_INVALIDARG
;
2670 if(index
>= session
->channel_count
)
2671 return E_INVALIDARG
;
2674 FIXME("Notifications not supported yet\n");
2676 EnterCriticalSection(&session
->lock
);
2678 session
->channel_vols
[index
] = level
;
2680 TRACE("OSS doesn't support setting volume\n");
2682 LeaveCriticalSection(&session
->lock
);
2687 static HRESULT WINAPI
ChannelAudioVolume_GetChannelVolume(
2688 IChannelAudioVolume
*iface
, UINT32 index
, float *level
)
2690 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2691 AudioSession
*session
= This
->session
;
2693 TRACE("(%p)->(%d, %p)\n", session
, index
, level
);
2696 return NULL_PTR_ERR
;
2698 if(index
>= session
->channel_count
)
2699 return E_INVALIDARG
;
2701 *level
= session
->channel_vols
[index
];
2706 static HRESULT WINAPI
ChannelAudioVolume_SetAllVolumes(
2707 IChannelAudioVolume
*iface
, UINT32 count
, const float *levels
,
2708 const GUID
*context
)
2710 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2711 AudioSession
*session
= This
->session
;
2714 TRACE("(%p)->(%d, %p, %s)\n", session
, count
, levels
,
2715 wine_dbgstr_guid(context
));
2718 return NULL_PTR_ERR
;
2720 if(count
!= session
->channel_count
)
2721 return E_INVALIDARG
;
2724 FIXME("Notifications not supported yet\n");
2726 EnterCriticalSection(&session
->lock
);
2728 for(i
= 0; i
< count
; ++i
)
2729 session
->channel_vols
[i
] = levels
[i
];
2731 TRACE("OSS doesn't support setting volume\n");
2733 LeaveCriticalSection(&session
->lock
);
2738 static HRESULT WINAPI
ChannelAudioVolume_GetAllVolumes(
2739 IChannelAudioVolume
*iface
, UINT32 count
, float *levels
)
2741 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2742 AudioSession
*session
= This
->session
;
2745 TRACE("(%p)->(%d, %p)\n", session
, count
, levels
);
2748 return NULL_PTR_ERR
;
2750 if(count
!= session
->channel_count
)
2751 return E_INVALIDARG
;
2753 for(i
= 0; i
< count
; ++i
)
2754 levels
[i
] = session
->channel_vols
[i
];
2759 static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl
=
2761 ChannelAudioVolume_QueryInterface
,
2762 ChannelAudioVolume_AddRef
,
2763 ChannelAudioVolume_Release
,
2764 ChannelAudioVolume_GetChannelCount
,
2765 ChannelAudioVolume_SetChannelVolume
,
2766 ChannelAudioVolume_GetChannelVolume
,
2767 ChannelAudioVolume_SetAllVolumes
,
2768 ChannelAudioVolume_GetAllVolumes
2771 static HRESULT WINAPI
AudioSessionManager_QueryInterface(IAudioSessionManager2
*iface
,
2772 REFIID riid
, void **ppv
)
2774 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2780 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2781 IsEqualIID(riid
, &IID_IAudioSessionManager
) ||
2782 IsEqualIID(riid
, &IID_IAudioSessionManager2
))
2785 IUnknown_AddRef((IUnknown
*)*ppv
);
2789 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2790 return E_NOINTERFACE
;
2793 static ULONG WINAPI
AudioSessionManager_AddRef(IAudioSessionManager2
*iface
)
2795 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2797 ref
= InterlockedIncrement(&This
->ref
);
2798 TRACE("(%p) Refcount now %u\n", This
, ref
);
2802 static ULONG WINAPI
AudioSessionManager_Release(IAudioSessionManager2
*iface
)
2804 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2806 ref
= InterlockedDecrement(&This
->ref
);
2807 TRACE("(%p) Refcount now %u\n", This
, ref
);
2809 HeapFree(GetProcessHeap(), 0, This
);
2813 static HRESULT WINAPI
AudioSessionManager_GetAudioSessionControl(
2814 IAudioSessionManager2
*iface
, const GUID
*session_guid
, DWORD flags
,
2815 IAudioSessionControl
**out
)
2817 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2818 AudioSession
*session
;
2819 AudioSessionWrapper
*wrapper
;
2822 TRACE("(%p)->(%s, %x, %p)\n", This
, debugstr_guid(session_guid
),
2825 hr
= get_audio_session(session_guid
, This
->device
, 0, &session
);
2829 wrapper
= AudioSessionWrapper_Create(NULL
);
2831 return E_OUTOFMEMORY
;
2833 wrapper
->session
= session
;
2835 *out
= (IAudioSessionControl
*)&wrapper
->IAudioSessionControl2_iface
;
2840 static HRESULT WINAPI
AudioSessionManager_GetSimpleAudioVolume(
2841 IAudioSessionManager2
*iface
, const GUID
*session_guid
, DWORD flags
,
2842 ISimpleAudioVolume
**out
)
2844 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2845 AudioSession
*session
;
2846 AudioSessionWrapper
*wrapper
;
2849 TRACE("(%p)->(%s, %x, %p)\n", This
, debugstr_guid(session_guid
),
2852 hr
= get_audio_session(session_guid
, This
->device
, 0, &session
);
2856 wrapper
= AudioSessionWrapper_Create(NULL
);
2858 return E_OUTOFMEMORY
;
2860 wrapper
->session
= session
;
2862 *out
= &wrapper
->ISimpleAudioVolume_iface
;
2867 static HRESULT WINAPI
AudioSessionManager_GetSessionEnumerator(
2868 IAudioSessionManager2
*iface
, IAudioSessionEnumerator
**out
)
2870 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2871 FIXME("(%p)->(%p) - stub\n", This
, out
);
2875 static HRESULT WINAPI
AudioSessionManager_RegisterSessionNotification(
2876 IAudioSessionManager2
*iface
, IAudioSessionNotification
*notification
)
2878 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2879 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2883 static HRESULT WINAPI
AudioSessionManager_UnregisterSessionNotification(
2884 IAudioSessionManager2
*iface
, IAudioSessionNotification
*notification
)
2886 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2887 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2891 static HRESULT WINAPI
AudioSessionManager_RegisterDuckNotification(
2892 IAudioSessionManager2
*iface
, const WCHAR
*session_id
,
2893 IAudioVolumeDuckNotification
*notification
)
2895 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2896 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2900 static HRESULT WINAPI
AudioSessionManager_UnregisterDuckNotification(
2901 IAudioSessionManager2
*iface
,
2902 IAudioVolumeDuckNotification
*notification
)
2904 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2905 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2909 static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl
=
2911 AudioSessionManager_QueryInterface
,
2912 AudioSessionManager_AddRef
,
2913 AudioSessionManager_Release
,
2914 AudioSessionManager_GetAudioSessionControl
,
2915 AudioSessionManager_GetSimpleAudioVolume
,
2916 AudioSessionManager_GetSessionEnumerator
,
2917 AudioSessionManager_RegisterSessionNotification
,
2918 AudioSessionManager_UnregisterSessionNotification
,
2919 AudioSessionManager_RegisterDuckNotification
,
2920 AudioSessionManager_UnregisterDuckNotification
2923 HRESULT WINAPI
AUDDRV_GetAudioSessionManager(IMMDevice
*device
,
2924 IAudioSessionManager2
**out
)
2928 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SessionMgr
));
2930 return E_OUTOFMEMORY
;
2932 This
->IAudioSessionManager2_iface
.lpVtbl
= &AudioSessionManager2_Vtbl
;
2933 This
->device
= device
;
2936 *out
= &This
->IAudioSessionManager2_iface
;