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"
57 /* Some implementations of OSS, such as FreeBSD older than 9.0, lack
58 SNDCTL_DSP_HALT which is just a synonym for the older SNDCTL_DSP_RESET. */
59 #ifndef SNDCTL_DSP_HALT
60 #define SNDCTL_DSP_HALT SNDCTL_DSP_RESET
63 WINE_DEFAULT_DEBUG_CHANNEL(oss
);
65 #define NULL_PTR_ERR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, RPC_X_NULL_REF_POINTER)
67 static const REFERENCE_TIME DefaultPeriod
= 200000;
68 static const REFERENCE_TIME MinimumPeriod
= 100000;
71 typedef struct ACImpl ACImpl
;
73 typedef struct _AudioSession
{
84 CRITICAL_SECTION lock
;
89 typedef struct _AudioSessionWrapper
{
90 IAudioSessionControl2 IAudioSessionControl2_iface
;
91 IChannelAudioVolume IChannelAudioVolume_iface
;
92 ISimpleAudioVolume ISimpleAudioVolume_iface
;
97 AudioSession
*session
;
98 } AudioSessionWrapper
;
101 IAudioClient IAudioClient_iface
;
102 IAudioRenderClient IAudioRenderClient_iface
;
103 IAudioCaptureClient IAudioCaptureClient_iface
;
104 IAudioClock IAudioClock_iface
;
105 IAudioClock2 IAudioClock2_iface
;
106 IAudioStreamVolume IAudioStreamVolume_iface
;
116 AUDCLNT_SHAREMODE share
;
123 BOOL initted
, playing
;
124 UINT64 written_frames
;
125 UINT32 period_us
, bufsize_frames
, held_frames
, tmp_buffer_frames
, inbuf_frames
;
126 UINT32 lcl_offs_frames
; /* offs into local_buffer where valid data starts */
128 BYTE
*local_buffer
, *tmp_buffer
;
132 CRITICAL_SECTION lock
;
134 AudioSession
*session
;
135 AudioSessionWrapper
*session_wrapper
;
142 LOCKED_NORMAL
, /* public buffer piece is from local_buffer */
143 LOCKED_WRAPPED
/* public buffer piece is in tmp_buffer */
146 typedef struct _SessionMgr
{
147 IAudioSessionManager2 IAudioSessionManager2_iface
;
154 static HANDLE g_timer_q
;
156 static CRITICAL_SECTION g_sessions_lock
;
157 static struct list g_sessions
= LIST_INIT(g_sessions
);
159 static AudioSessionWrapper
*AudioSessionWrapper_Create(ACImpl
*client
);
160 static HRESULT
oss_setvol(ACImpl
*This
, UINT32 index
);
162 static const IAudioClientVtbl AudioClient_Vtbl
;
163 static const IAudioRenderClientVtbl AudioRenderClient_Vtbl
;
164 static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl
;
165 static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl
;
166 static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl
;
167 static const IAudioClockVtbl AudioClock_Vtbl
;
168 static const IAudioClock2Vtbl AudioClock2_Vtbl
;
169 static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl
;
170 static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl
;
171 static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl
;
173 static inline ACImpl
*impl_from_IAudioClient(IAudioClient
*iface
)
175 return CONTAINING_RECORD(iface
, ACImpl
, IAudioClient_iface
);
178 static inline ACImpl
*impl_from_IAudioRenderClient(IAudioRenderClient
*iface
)
180 return CONTAINING_RECORD(iface
, ACImpl
, IAudioRenderClient_iface
);
183 static inline ACImpl
*impl_from_IAudioCaptureClient(IAudioCaptureClient
*iface
)
185 return CONTAINING_RECORD(iface
, ACImpl
, IAudioCaptureClient_iface
);
188 static inline AudioSessionWrapper
*impl_from_IAudioSessionControl2(IAudioSessionControl2
*iface
)
190 return CONTAINING_RECORD(iface
, AudioSessionWrapper
, IAudioSessionControl2_iface
);
193 static inline AudioSessionWrapper
*impl_from_ISimpleAudioVolume(ISimpleAudioVolume
*iface
)
195 return CONTAINING_RECORD(iface
, AudioSessionWrapper
, ISimpleAudioVolume_iface
);
198 static inline AudioSessionWrapper
*impl_from_IChannelAudioVolume(IChannelAudioVolume
*iface
)
200 return CONTAINING_RECORD(iface
, AudioSessionWrapper
, IChannelAudioVolume_iface
);
203 static inline ACImpl
*impl_from_IAudioClock(IAudioClock
*iface
)
205 return CONTAINING_RECORD(iface
, ACImpl
, IAudioClock_iface
);
208 static inline ACImpl
*impl_from_IAudioClock2(IAudioClock2
*iface
)
210 return CONTAINING_RECORD(iface
, ACImpl
, IAudioClock2_iface
);
213 static inline ACImpl
*impl_from_IAudioStreamVolume(IAudioStreamVolume
*iface
)
215 return CONTAINING_RECORD(iface
, ACImpl
, IAudioStreamVolume_iface
);
218 static inline SessionMgr
*impl_from_IAudioSessionManager2(IAudioSessionManager2
*iface
)
220 return CONTAINING_RECORD(iface
, SessionMgr
, IAudioSessionManager2_iface
);
223 BOOL WINAPI
DllMain(HINSTANCE dll
, DWORD reason
, void *reserved
)
225 if(reason
== DLL_PROCESS_ATTACH
){
226 g_timer_q
= CreateTimerQueue();
230 InitializeCriticalSection(&g_sessions_lock
);
236 /* From <dlls/mmdevapi/mmdevapi.h> */
237 enum DriverPriority
{
238 Priority_Unavailable
= 0,
244 int WINAPI
AUDDRV_GetPriority(void)
249 /* Attempt to determine if we are running on OSS or ALSA's OSS
250 * compatibility layer. There is no official way to do that, so just check
251 * for validity as best as possible, without rejecting valid OSS
252 * implementations. */
254 mixer_fd
= open("/dev/mixer", O_RDONLY
, 0);
256 TRACE("Priority_Unavailable: open failed\n");
257 return Priority_Unavailable
;
260 sysinfo
.version
[0] = 0xFF;
261 sysinfo
.versionnum
= ~0;
262 if(ioctl(mixer_fd
, SNDCTL_SYSINFO
, &sysinfo
) < 0){
263 TRACE("Priority_Unavailable: ioctl failed\n");
265 return Priority_Unavailable
;
270 if(sysinfo
.version
[0] < '4' || sysinfo
.version
[0] > '9'){
271 TRACE("Priority_Low: sysinfo.version[0]: %x\n", sysinfo
.version
[0]);
274 if(sysinfo
.versionnum
& 0x80000000){
275 TRACE("Priority_Low: sysinfo.versionnum: %x\n", sysinfo
.versionnum
);
279 TRACE("Priority_Preferred: Seems like valid OSS!\n");
281 return Priority_Preferred
;
284 static UINT
get_default_index(EDataFlow flow
, char **keys
, UINT num
)
290 fd
= open("/dev/dsp", O_WRONLY
);
292 fd
= open("/dev/dsp", O_RDONLY
);
295 WARN("Couldn't open default device!\n");
300 if((err
= ioctl(fd
, SNDCTL_ENGINEINFO
, &ai
)) < 0){
301 WARN("SNDCTL_ENGINEINFO failed: %d (%s)\n", err
, strerror(errno
));
308 TRACE("Default devnode: %s\n", ai
.devnode
);
309 for(i
= 0; i
< num
; ++i
)
310 if(!strcmp(ai
.devnode
, keys
[i
]))
313 WARN("Couldn't find default device! Choosing first.\n");
317 HRESULT WINAPI
AUDDRV_GetEndpointIDs(EDataFlow flow
, WCHAR
***ids
, char ***keys
,
318 UINT
*num
, UINT
*def_index
)
322 static int print_once
= 0;
324 TRACE("%d %p %p %p\n", flow
, ids
, num
, def_index
);
326 mixer_fd
= open("/dev/mixer", O_RDONLY
, 0);
328 ERR("OSS /dev/mixer doesn't seem to exist\n");
329 return AUDCLNT_E_SERVICE_NOT_RUNNING
;
332 if(ioctl(mixer_fd
, SNDCTL_SYSINFO
, &sysinfo
) < 0){
336 ERR("OSS version too old, need at least OSSv4\n");
337 return AUDCLNT_E_SERVICE_NOT_RUNNING
;
340 ERR("Error getting SNDCTL_SYSINFO: %d (%s)\n", errno
, strerror(errno
));
345 TRACE("OSS sysinfo:\n");
346 TRACE("product: %s\n", sysinfo
.product
);
347 TRACE("version: %s\n", sysinfo
.version
);
348 TRACE("versionnum: %x\n", sysinfo
.versionnum
);
349 TRACE("numaudios: %d\n", sysinfo
.numaudios
);
350 TRACE("nummixers: %d\n", sysinfo
.nummixers
);
351 TRACE("numcards: %d\n", sysinfo
.numcards
);
352 TRACE("numaudioengines: %d\n", sysinfo
.numaudioengines
);
356 if(sysinfo
.numaudios
<= 0){
357 WARN("No audio devices!\n");
359 return AUDCLNT_E_SERVICE_NOT_RUNNING
;
362 *ids
= HeapAlloc(GetProcessHeap(), 0, sysinfo
.numaudios
* sizeof(WCHAR
*));
363 *keys
= HeapAlloc(GetProcessHeap(), 0, sysinfo
.numaudios
* sizeof(char *));
366 for(i
= 0; i
< sysinfo
.numaudios
; ++i
){
367 oss_audioinfo ai
= {0};
371 if(ioctl(mixer_fd
, SNDCTL_AUDIOINFO
, &ai
) < 0){
372 WARN("Error getting AUDIOINFO for dev %d: %d (%s)\n", i
, errno
,
378 fd
= open(ai
.devnode
, O_WRONLY
, 0);
380 fd
= open(ai
.devnode
, O_RDONLY
, 0);
382 WARN("Opening device \"%s\" failed, pretending it doesn't exist: %d (%s)\n",
383 ai
.devnode
, errno
, strerror(errno
));
388 if((flow
== eCapture
&& (ai
.caps
& PCM_CAP_INPUT
)) ||
389 (flow
== eRender
&& (ai
.caps
& PCM_CAP_OUTPUT
))){
392 (*keys
)[*num
] = HeapAlloc(GetProcessHeap(), 0,
393 strlen(ai
.devnode
) + 1);
395 for(i
= 0; i
< *num
; ++i
){
396 HeapFree(GetProcessHeap(), 0, (*ids
)[i
]);
397 HeapFree(GetProcessHeap(), 0, (*keys
)[i
]);
399 HeapFree(GetProcessHeap(), 0, *ids
);
400 HeapFree(GetProcessHeap(), 0, *keys
);
402 return E_OUTOFMEMORY
;
404 strcpy((*keys
)[*num
], ai
.devnode
);
406 len
= MultiByteToWideChar(CP_UNIXCP
, 0, ai
.name
, -1, NULL
, 0);
407 (*ids
)[*num
] = HeapAlloc(GetProcessHeap(), 0,
408 len
* sizeof(WCHAR
));
410 HeapFree(GetProcessHeap(), 0, (*keys
)[*num
]);
411 for(i
= 0; i
< *num
; ++i
){
412 HeapFree(GetProcessHeap(), 0, (*ids
)[i
]);
413 HeapFree(GetProcessHeap(), 0, (*keys
)[i
]);
415 HeapFree(GetProcessHeap(), 0, *ids
);
416 HeapFree(GetProcessHeap(), 0, *keys
);
418 return E_OUTOFMEMORY
;
420 MultiByteToWideChar(CP_UNIXCP
, 0, ai
.name
, -1,
429 *def_index
= get_default_index(flow
, *keys
, *num
);
434 HRESULT WINAPI
AUDDRV_GetAudioEndpoint(char *devnode
, IMMDevice
*dev
,
435 EDataFlow dataflow
, IAudioClient
**out
)
439 TRACE("%s %p %d %p\n", devnode
, dev
, dataflow
, out
);
441 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(ACImpl
));
443 return E_OUTOFMEMORY
;
445 if(dataflow
== eRender
)
446 This
->fd
= open(devnode
, O_WRONLY
, 0);
447 else if(dataflow
== eCapture
)
448 This
->fd
= open(devnode
, O_RDONLY
, 0);
450 HeapFree(GetProcessHeap(), 0, This
);
454 ERR("Unable to open device %s: %d (%s)\n", devnode
, errno
,
456 HeapFree(GetProcessHeap(), 0, This
);
457 return AUDCLNT_E_DEVICE_INVALIDATED
;
460 This
->dataflow
= dataflow
;
463 if(ioctl(This
->fd
, SNDCTL_ENGINEINFO
, &This
->ai
) < 0){
464 ERR("Unable to get audio info for device %s: %d (%s)\n", devnode
,
465 errno
, strerror(errno
));
467 HeapFree(GetProcessHeap(), 0, This
);
471 TRACE("OSS audioinfo:\n");
472 TRACE("devnode: %s\n", This
->ai
.devnode
);
473 TRACE("name: %s\n", This
->ai
.name
);
474 TRACE("busy: %x\n", This
->ai
.busy
);
475 TRACE("caps: %x\n", This
->ai
.caps
);
476 TRACE("iformats: %x\n", This
->ai
.iformats
);
477 TRACE("oformats: %x\n", This
->ai
.oformats
);
478 TRACE("enabled: %d\n", This
->ai
.enabled
);
479 TRACE("min_rate: %d\n", This
->ai
.min_rate
);
480 TRACE("max_rate: %d\n", This
->ai
.max_rate
);
481 TRACE("min_channels: %d\n", This
->ai
.min_channels
);
482 TRACE("max_channels: %d\n", This
->ai
.max_channels
);
484 This
->IAudioClient_iface
.lpVtbl
= &AudioClient_Vtbl
;
485 This
->IAudioRenderClient_iface
.lpVtbl
= &AudioRenderClient_Vtbl
;
486 This
->IAudioCaptureClient_iface
.lpVtbl
= &AudioCaptureClient_Vtbl
;
487 This
->IAudioClock_iface
.lpVtbl
= &AudioClock_Vtbl
;
488 This
->IAudioClock2_iface
.lpVtbl
= &AudioClock2_Vtbl
;
489 This
->IAudioStreamVolume_iface
.lpVtbl
= &AudioStreamVolume_Vtbl
;
491 InitializeCriticalSection(&This
->lock
);
494 IMMDevice_AddRef(This
->parent
);
496 IAudioClient_AddRef(&This
->IAudioClient_iface
);
498 *out
= &This
->IAudioClient_iface
;
503 static HRESULT WINAPI
AudioClient_QueryInterface(IAudioClient
*iface
,
504 REFIID riid
, void **ppv
)
506 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
511 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IAudioClient
))
514 IUnknown_AddRef((IUnknown
*)*ppv
);
517 WARN("Unknown interface %s\n", debugstr_guid(riid
));
518 return E_NOINTERFACE
;
521 static ULONG WINAPI
AudioClient_AddRef(IAudioClient
*iface
)
523 ACImpl
*This
= impl_from_IAudioClient(iface
);
525 ref
= InterlockedIncrement(&This
->ref
);
526 TRACE("(%p) Refcount now %u\n", This
, ref
);
530 static ULONG WINAPI
AudioClient_Release(IAudioClient
*iface
)
532 ACImpl
*This
= impl_from_IAudioClient(iface
);
534 ref
= InterlockedDecrement(&This
->ref
);
535 TRACE("(%p) Refcount now %u\n", This
, ref
);
537 IAudioClient_Stop(iface
);
538 IMMDevice_Release(This
->parent
);
539 DeleteCriticalSection(&This
->lock
);
542 EnterCriticalSection(&g_sessions_lock
);
543 list_remove(&This
->entry
);
544 LeaveCriticalSection(&g_sessions_lock
);
546 HeapFree(GetProcessHeap(), 0, This
->vols
);
547 HeapFree(GetProcessHeap(), 0, This
->local_buffer
);
548 HeapFree(GetProcessHeap(), 0, This
->tmp_buffer
);
549 CoTaskMemFree(This
->fmt
);
550 HeapFree(GetProcessHeap(), 0, This
);
555 static void dump_fmt(const WAVEFORMATEX
*fmt
)
557 TRACE("wFormatTag: 0x%x (", fmt
->wFormatTag
);
558 switch(fmt
->wFormatTag
){
559 case WAVE_FORMAT_PCM
:
560 TRACE("WAVE_FORMAT_PCM");
562 case WAVE_FORMAT_IEEE_FLOAT
:
563 TRACE("WAVE_FORMAT_IEEE_FLOAT");
565 case WAVE_FORMAT_EXTENSIBLE
:
566 TRACE("WAVE_FORMAT_EXTENSIBLE");
574 TRACE("nChannels: %u\n", fmt
->nChannels
);
575 TRACE("nSamplesPerSec: %u\n", fmt
->nSamplesPerSec
);
576 TRACE("nAvgBytesPerSec: %u\n", fmt
->nAvgBytesPerSec
);
577 TRACE("nBlockAlign: %u\n", fmt
->nBlockAlign
);
578 TRACE("wBitsPerSample: %u\n", fmt
->wBitsPerSample
);
579 TRACE("cbSize: %u\n", fmt
->cbSize
);
581 if(fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
){
582 WAVEFORMATEXTENSIBLE
*fmtex
= (void*)fmt
;
583 TRACE("dwChannelMask: %08x\n", fmtex
->dwChannelMask
);
584 TRACE("Samples: %04x\n", fmtex
->Samples
.wReserved
);
585 TRACE("SubFormat: %s\n", wine_dbgstr_guid(&fmtex
->SubFormat
));
589 static DWORD
get_channel_mask(unsigned int channels
)
595 return KSAUDIO_SPEAKER_MONO
;
597 return KSAUDIO_SPEAKER_STEREO
;
599 return KSAUDIO_SPEAKER_STEREO
| SPEAKER_LOW_FREQUENCY
;
601 return KSAUDIO_SPEAKER_QUAD
; /* not _SURROUND */
603 return KSAUDIO_SPEAKER_QUAD
| SPEAKER_LOW_FREQUENCY
;
605 return KSAUDIO_SPEAKER_5POINT1
; /* not 5POINT1_SURROUND */
607 return KSAUDIO_SPEAKER_5POINT1
| SPEAKER_BACK_CENTER
;
609 return KSAUDIO_SPEAKER_7POINT1
; /* not 7POINT1_SURROUND */
611 FIXME("Unknown speaker configuration: %u\n", channels
);
615 static int get_oss_format(const WAVEFORMATEX
*fmt
)
617 WAVEFORMATEXTENSIBLE
*fmtex
= (WAVEFORMATEXTENSIBLE
*)fmt
;
619 if(fmt
->wFormatTag
== WAVE_FORMAT_PCM
||
620 (fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
621 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
))){
622 switch(fmt
->wBitsPerSample
){
636 if(fmt
->wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
||
637 (fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
638 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
))){
639 if(fmt
->wBitsPerSample
!= 32)
649 static WAVEFORMATEX
*clone_format(const WAVEFORMATEX
*fmt
)
654 if(fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
655 size
= sizeof(WAVEFORMATEXTENSIBLE
);
657 size
= sizeof(WAVEFORMATEX
);
659 ret
= CoTaskMemAlloc(size
);
663 memcpy(ret
, fmt
, size
);
665 ret
->cbSize
= size
- sizeof(WAVEFORMATEX
);
670 static HRESULT
setup_oss_device(ACImpl
*This
, const WAVEFORMATEX
*fmt
,
671 WAVEFORMATEX
**out
, BOOL query
)
676 WAVEFORMATEXTENSIBLE
*fmtex
= (void*)fmt
;
677 WAVEFORMATEX
*closest
= NULL
;
682 tmp
= oss_format
= get_oss_format(fmt
);
684 return AUDCLNT_E_UNSUPPORTED_FORMAT
;
685 if(ioctl(This
->fd
, SNDCTL_DSP_SETFMT
, &tmp
) < 0){
686 WARN("SETFMT failed: %d (%s)\n", errno
, strerror(errno
));
689 if(tmp
!= oss_format
){
690 TRACE("Format unsupported by this OSS version: %x\n", oss_format
);
691 return AUDCLNT_E_UNSUPPORTED_FORMAT
;
694 closest
= clone_format(fmt
);
696 return E_OUTOFMEMORY
;
698 tmp
= fmt
->nSamplesPerSec
;
699 if(ioctl(This
->fd
, SNDCTL_DSP_SPEED
, &tmp
) < 0){
700 WARN("SPEED failed: %d (%s)\n", errno
, strerror(errno
));
701 CoTaskMemFree(closest
);
704 tenth
= fmt
->nSamplesPerSec
* 0.1;
705 if(tmp
> fmt
->nSamplesPerSec
+ tenth
|| tmp
< fmt
->nSamplesPerSec
- tenth
){
707 closest
->nSamplesPerSec
= tmp
;
710 tmp
= fmt
->nChannels
;
711 if(ioctl(This
->fd
, SNDCTL_DSP_CHANNELS
, &tmp
) < 0){
712 WARN("CHANNELS failed: %d (%s)\n", errno
, strerror(errno
));
713 CoTaskMemFree(closest
);
716 if(tmp
!= fmt
->nChannels
){
718 closest
->nChannels
= tmp
;
721 if(closest
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
){
722 DWORD mask
= get_channel_mask(closest
->nChannels
);
724 ((WAVEFORMATEXTENSIBLE
*)closest
)->dwChannelMask
= mask
;
726 if(query
&& fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
727 fmtex
->dwChannelMask
!= 0 &&
728 fmtex
->dwChannelMask
!= mask
)
732 if(ret
== S_FALSE
&& out
){
733 closest
->nBlockAlign
=
734 closest
->nChannels
* closest
->wBitsPerSample
/ 8;
735 closest
->nAvgBytesPerSec
=
736 closest
->nBlockAlign
* closest
->nSamplesPerSec
;
739 CoTaskMemFree(closest
);
741 TRACE("returning: %08x\n", ret
);
745 static void session_init_vols(AudioSession
*session
, UINT channels
)
747 if(session
->channel_count
< channels
){
750 if(session
->channel_vols
)
751 session
->channel_vols
= HeapReAlloc(GetProcessHeap(), 0,
752 session
->channel_vols
, sizeof(float) * channels
);
754 session
->channel_vols
= HeapAlloc(GetProcessHeap(), 0,
755 sizeof(float) * channels
);
756 if(!session
->channel_vols
)
759 for(i
= session
->channel_count
; i
< channels
; ++i
)
760 session
->channel_vols
[i
] = 1.f
;
762 session
->channel_count
= channels
;
766 static AudioSession
*create_session(const GUID
*guid
, IMMDevice
*device
,
771 ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(AudioSession
));
775 memcpy(&ret
->guid
, guid
, sizeof(GUID
));
777 ret
->device
= device
;
779 list_init(&ret
->clients
);
781 list_add_head(&g_sessions
, &ret
->entry
);
783 InitializeCriticalSection(&ret
->lock
);
785 session_init_vols(ret
, num_channels
);
787 ret
->master_vol
= 1.f
;
792 /* if channels == 0, then this will return or create a session with
793 * matching dataflow and GUID. otherwise, channels must also match */
794 static HRESULT
get_audio_session(const GUID
*sessionguid
,
795 IMMDevice
*device
, UINT channels
, AudioSession
**out
)
797 AudioSession
*session
;
799 if(!sessionguid
|| IsEqualGUID(sessionguid
, &GUID_NULL
)){
800 *out
= create_session(&GUID_NULL
, device
, channels
);
802 return E_OUTOFMEMORY
;
808 LIST_FOR_EACH_ENTRY(session
, &g_sessions
, AudioSession
, entry
){
809 if(session
->device
== device
&&
810 IsEqualGUID(sessionguid
, &session
->guid
)){
811 session_init_vols(session
, channels
);
818 *out
= create_session(sessionguid
, device
, channels
);
820 return E_OUTOFMEMORY
;
826 static HRESULT WINAPI
AudioClient_Initialize(IAudioClient
*iface
,
827 AUDCLNT_SHAREMODE mode
, DWORD flags
, REFERENCE_TIME duration
,
828 REFERENCE_TIME period
, const WAVEFORMATEX
*fmt
,
829 const GUID
*sessionguid
)
831 ACImpl
*This
= impl_from_IAudioClient(iface
);
835 TRACE("(%p)->(%x, %x, %s, %s, %p, %s)\n", This
, mode
, flags
,
836 wine_dbgstr_longlong(duration
), wine_dbgstr_longlong(period
), fmt
, debugstr_guid(sessionguid
));
843 if(mode
!= AUDCLNT_SHAREMODE_SHARED
&& mode
!= AUDCLNT_SHAREMODE_EXCLUSIVE
)
844 return AUDCLNT_E_NOT_INITIALIZED
;
846 if(flags
& ~(AUDCLNT_STREAMFLAGS_CROSSPROCESS
|
847 AUDCLNT_STREAMFLAGS_LOOPBACK
|
848 AUDCLNT_STREAMFLAGS_EVENTCALLBACK
|
849 AUDCLNT_STREAMFLAGS_NOPERSIST
|
850 AUDCLNT_STREAMFLAGS_RATEADJUST
|
851 AUDCLNT_SESSIONFLAGS_EXPIREWHENUNOWNED
|
852 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDE
|
853 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDEWHENEXPIRED
)){
854 TRACE("Unknown flags: %08x\n", flags
);
858 EnterCriticalSection(&This
->lock
);
861 LeaveCriticalSection(&This
->lock
);
862 return AUDCLNT_E_ALREADY_INITIALIZED
;
865 hr
= setup_oss_device(This
, fmt
, NULL
, FALSE
);
867 LeaveCriticalSection(&This
->lock
);
868 return AUDCLNT_E_UNSUPPORTED_FORMAT
;
871 LeaveCriticalSection(&This
->lock
);
876 if(ioctl(This
->fd
, SNDCTL_DSP_SETTRIGGER
, &mask
) < 0){
877 LeaveCriticalSection(&This
->lock
);
878 WARN("SETTRIGGER failed: %d (%s)\n", errno
, strerror(errno
));
882 mask
= (100 << 8) | 100;
883 if(ioctl(This
->fd
, SNDCTL_DSP_SETPLAYVOL
, &mask
) < 0)
884 WARN("SETPLAYVOL failed: %d (%s)\n", errno
, strerror(errno
));
886 This
->fmt
= clone_format(fmt
);
888 LeaveCriticalSection(&This
->lock
);
889 return E_OUTOFMEMORY
;
893 This
->period_us
= period
/ 10;
895 This
->period_us
= DefaultPeriod
/ 10;
898 duration
= 300000; /* 0.03s */
899 This
->bufsize_frames
= ceil(fmt
->nSamplesPerSec
* (duration
/ 10000000.));
900 This
->local_buffer
= HeapAlloc(GetProcessHeap(), 0,
901 This
->bufsize_frames
* fmt
->nBlockAlign
);
902 if(!This
->local_buffer
){
903 CoTaskMemFree(This
->fmt
);
905 LeaveCriticalSection(&This
->lock
);
906 return E_OUTOFMEMORY
;
909 This
->vols
= HeapAlloc(GetProcessHeap(), 0, fmt
->nChannels
* sizeof(float));
911 CoTaskMemFree(This
->fmt
);
913 LeaveCriticalSection(&This
->lock
);
914 return E_OUTOFMEMORY
;
917 for(i
= 0; i
< fmt
->nChannels
; ++i
)
923 EnterCriticalSection(&g_sessions_lock
);
925 hr
= get_audio_session(sessionguid
, This
->parent
, fmt
->nChannels
,
928 LeaveCriticalSection(&g_sessions_lock
);
929 HeapFree(GetProcessHeap(), 0, This
->vols
);
931 CoTaskMemFree(This
->fmt
);
933 LeaveCriticalSection(&This
->lock
);
937 list_add_tail(&This
->session
->clients
, &This
->entry
);
939 LeaveCriticalSection(&g_sessions_lock
);
941 This
->initted
= TRUE
;
943 oss_setvol(This
, -1);
945 LeaveCriticalSection(&This
->lock
);
950 static HRESULT WINAPI
AudioClient_GetBufferSize(IAudioClient
*iface
,
953 ACImpl
*This
= impl_from_IAudioClient(iface
);
955 TRACE("(%p)->(%p)\n", This
, frames
);
960 EnterCriticalSection(&This
->lock
);
963 LeaveCriticalSection(&This
->lock
);
964 return AUDCLNT_E_NOT_INITIALIZED
;
967 *frames
= This
->bufsize_frames
;
969 LeaveCriticalSection(&This
->lock
);
974 static HRESULT WINAPI
AudioClient_GetStreamLatency(IAudioClient
*iface
,
975 REFERENCE_TIME
*latency
)
977 ACImpl
*This
= impl_from_IAudioClient(iface
);
979 TRACE("(%p)->(%p)\n", This
, latency
);
984 EnterCriticalSection(&This
->lock
);
987 LeaveCriticalSection(&This
->lock
);
988 return AUDCLNT_E_NOT_INITIALIZED
;
991 if(This
->dataflow
== eRender
){
995 if(ioctl(This
->fd
, SNDCTL_DSP_GETODELAY
, &delay_bytes
) < 0){
996 LeaveCriticalSection(&This
->lock
);
997 WARN("GETODELAY failed: %d (%s)\n", errno
, strerror(errno
));
1001 delay_s
= delay_bytes
/ (double)(This
->fmt
->nSamplesPerSec
*
1002 This
->fmt
->nBlockAlign
);
1004 *latency
= delay_s
* 10000000;
1006 *latency
= 10000; /* OSS doesn't provide input latency */
1008 LeaveCriticalSection(&This
->lock
);
1013 static HRESULT WINAPI
AudioClient_GetCurrentPadding(IAudioClient
*iface
,
1016 ACImpl
*This
= impl_from_IAudioClient(iface
);
1019 TRACE("(%p)->(%p)\n", This
, numpad
);
1024 EnterCriticalSection(&This
->lock
);
1027 LeaveCriticalSection(&This
->lock
);
1028 return AUDCLNT_E_NOT_INITIALIZED
;
1031 if(This
->dataflow
== eRender
){
1032 if(ioctl(This
->fd
, SNDCTL_DSP_GETOSPACE
, &bi
) < 0){
1033 LeaveCriticalSection(&This
->lock
);
1034 WARN("GETOSPACE failed: %d (%s)\n", errno
, strerror(errno
));
1038 *numpad
= (bi
.fragstotal
* bi
.fragsize
- bi
.bytes
) /
1039 This
->fmt
->nBlockAlign
;
1041 /* when the OSS buffer has less than one fragment of data, including
1042 * no data, it often reports it as some non-zero portion of a
1043 * fragment. when it has more than one fragment of data, it reports
1044 * it as some multiple of that portion of the fragment size.
1046 * so, we have to do some ugly workarounds to report the timing
1047 * as accurately as possible */
1048 if(*numpad
< bi
.fragsize
/ This
->fmt
->nBlockAlign
){
1049 *numpad
= This
->inbuf_frames
;
1050 This
->inbuf_frames
= 0;
1052 if(*numpad
< This
->inbuf_frames
)
1053 This
->inbuf_frames
= *numpad
;
1055 *numpad
= This
->inbuf_frames
;
1057 }else if(This
->dataflow
== eCapture
){
1058 if(ioctl(This
->fd
, SNDCTL_DSP_GETISPACE
, &bi
) < 0){
1059 LeaveCriticalSection(&This
->lock
);
1060 WARN("GETISPACE failed: %d (%s)\n", errno
, strerror(errno
));
1064 if(bi
.bytes
<= bi
.fragsize
)
1067 *numpad
= bi
.bytes
/ This
->fmt
->nBlockAlign
;
1069 LeaveCriticalSection(&This
->lock
);
1070 return E_UNEXPECTED
;
1073 *numpad
+= This
->held_frames
;
1075 LeaveCriticalSection(&This
->lock
);
1080 static HRESULT WINAPI
AudioClient_IsFormatSupported(IAudioClient
*iface
,
1081 AUDCLNT_SHAREMODE mode
, const WAVEFORMATEX
*pwfx
,
1082 WAVEFORMATEX
**outpwfx
)
1084 ACImpl
*This
= impl_from_IAudioClient(iface
);
1087 TRACE("(%p)->(%x, %p, %p)\n", This
, mode
, pwfx
, outpwfx
);
1089 if(!pwfx
|| (mode
== AUDCLNT_SHAREMODE_SHARED
&& !outpwfx
))
1092 if(mode
!= AUDCLNT_SHAREMODE_SHARED
&& mode
!= AUDCLNT_SHAREMODE_EXCLUSIVE
)
1093 return E_INVALIDARG
;
1095 if(pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
1096 pwfx
->cbSize
< sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
))
1097 return E_INVALIDARG
;
1101 EnterCriticalSection(&This
->lock
);
1103 ret
= setup_oss_device(This
, pwfx
, outpwfx
, TRUE
);
1105 LeaveCriticalSection(&This
->lock
);
1110 static HRESULT WINAPI
AudioClient_GetMixFormat(IAudioClient
*iface
,
1111 WAVEFORMATEX
**pwfx
)
1113 ACImpl
*This
= impl_from_IAudioClient(iface
);
1114 WAVEFORMATEXTENSIBLE
*fmt
;
1117 TRACE("(%p)->(%p)\n", This
, pwfx
);
1123 if(This
->dataflow
== eRender
)
1124 formats
= This
->ai
.oformats
;
1125 else if(This
->dataflow
== eCapture
)
1126 formats
= This
->ai
.iformats
;
1128 return E_UNEXPECTED
;
1130 fmt
= CoTaskMemAlloc(sizeof(WAVEFORMATEXTENSIBLE
));
1132 return E_OUTOFMEMORY
;
1134 fmt
->Format
.wFormatTag
= WAVE_FORMAT_EXTENSIBLE
;
1135 if(formats
& AFMT_S16_LE
){
1136 fmt
->Format
.wBitsPerSample
= 16;
1137 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1139 }else if(formats
& AFMT_FLOAT
){
1140 fmt
->Format
.wBitsPerSample
= 32;
1141 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
1143 }else if(formats
& AFMT_U8
){
1144 fmt
->Format
.wBitsPerSample
= 8;
1145 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1146 }else if(formats
& AFMT_S32_LE
){
1147 fmt
->Format
.wBitsPerSample
= 32;
1148 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1149 }else if(formats
& AFMT_S24_LE
){
1150 fmt
->Format
.wBitsPerSample
= 24;
1151 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1153 ERR("Didn't recognize any available OSS formats: %x\n", formats
);
1158 fmt
->Format
.nChannels
= This
->ai
.max_channels
;
1159 fmt
->Format
.nSamplesPerSec
= This
->ai
.max_rate
;
1160 fmt
->dwChannelMask
= get_channel_mask(fmt
->Format
.nChannels
);
1162 fmt
->Format
.nBlockAlign
= (fmt
->Format
.wBitsPerSample
*
1163 fmt
->Format
.nChannels
) / 8;
1164 fmt
->Format
.nAvgBytesPerSec
= fmt
->Format
.nSamplesPerSec
*
1165 fmt
->Format
.nBlockAlign
;
1167 fmt
->Samples
.wValidBitsPerSample
= fmt
->Format
.wBitsPerSample
;
1168 fmt
->Format
.cbSize
= sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
);
1170 *pwfx
= (WAVEFORMATEX
*)fmt
;
1176 static HRESULT WINAPI
AudioClient_GetDevicePeriod(IAudioClient
*iface
,
1177 REFERENCE_TIME
*defperiod
, REFERENCE_TIME
*minperiod
)
1179 ACImpl
*This
= impl_from_IAudioClient(iface
);
1181 TRACE("(%p)->(%p, %p)\n", This
, defperiod
, minperiod
);
1183 if(!defperiod
&& !minperiod
)
1186 EnterCriticalSection(&This
->lock
);
1189 *defperiod
= DefaultPeriod
;
1191 *minperiod
= MinimumPeriod
;
1193 LeaveCriticalSection(&This
->lock
);
1198 static void oss_silence_buffer(ACImpl
*This
, BYTE
*buf
, UINT32 frames
)
1200 if(This
->fmt
->wBitsPerSample
== 8)
1201 memset(buf
, 128, frames
* This
->fmt
->nBlockAlign
);
1203 memset(buf
, 0, frames
* This
->fmt
->nBlockAlign
);
1206 static void oss_write_data(ACImpl
*This
)
1209 UINT32 written_frames
;
1212 This
->local_buffer
+ (This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
);
1214 if(This
->lcl_offs_frames
+ This
->held_frames
> This
->bufsize_frames
)
1215 to_write
= This
->bufsize_frames
- This
->lcl_offs_frames
;
1217 to_write
= This
->held_frames
;
1219 if(This
->session
->mute
)
1220 oss_silence_buffer(This
, buf
, to_write
);
1222 written
= write(This
->fd
, buf
, to_write
* This
->fmt
->nBlockAlign
);
1224 /* EAGAIN is OSS buffer full, log that too */
1225 WARN("write failed: %d (%s)\n", errno
, strerror(errno
));
1228 written_frames
= written
/ This
->fmt
->nBlockAlign
;
1230 This
->lcl_offs_frames
+= written_frames
;
1231 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1232 This
->held_frames
-= written_frames
;
1233 This
->inbuf_frames
+= written_frames
;
1235 if(written_frames
< to_write
){
1236 /* OSS buffer probably full */
1240 if(This
->held_frames
){
1241 /* wrapped and have some data back at the start to write */
1243 if(This
->session
->mute
)
1244 oss_silence_buffer(This
, This
->local_buffer
, This
->held_frames
);
1246 written
= write(This
->fd
, This
->local_buffer
,
1247 This
->held_frames
* This
->fmt
->nBlockAlign
);
1249 WARN("write failed: %d (%s)\n", errno
, strerror(errno
));
1252 written_frames
= written
/ This
->fmt
->nBlockAlign
;
1254 This
->lcl_offs_frames
+= written_frames
;
1255 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1256 This
->held_frames
-= written_frames
;
1257 This
->inbuf_frames
+= written_frames
;
1261 static void oss_read_data(ACImpl
*This
)
1263 UINT64 pos
, readable
;
1267 if(ioctl(This
->fd
, SNDCTL_DSP_GETISPACE
, &bi
) < 0){
1268 WARN("GETISPACE failed: %d (%s)\n", errno
, strerror(errno
));
1272 pos
= (This
->held_frames
+ This
->lcl_offs_frames
) % This
->bufsize_frames
;
1273 readable
= (This
->bufsize_frames
- pos
) * This
->fmt
->nBlockAlign
;
1275 if(bi
.bytes
< readable
)
1276 readable
= bi
.bytes
;
1278 nread
= read(This
->fd
, This
->local_buffer
+ pos
* This
->fmt
->nBlockAlign
,
1281 WARN("read failed: %d (%s)\n", errno
, strerror(errno
));
1285 This
->held_frames
+= nread
/ This
->fmt
->nBlockAlign
;
1287 if(This
->held_frames
> This
->bufsize_frames
){
1288 WARN("Overflow of unread data\n");
1289 This
->lcl_offs_frames
+= This
->held_frames
;
1290 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1291 This
->held_frames
= This
->bufsize_frames
;
1295 static void CALLBACK
oss_period_callback(void *user
, BOOLEAN timer
)
1297 ACImpl
*This
= user
;
1299 EnterCriticalSection(&This
->lock
);
1301 if(This
->dataflow
== eRender
&& This
->held_frames
)
1302 oss_write_data(This
);
1303 else if(This
->dataflow
== eCapture
)
1304 oss_read_data(This
);
1307 SetEvent(This
->event
);
1309 LeaveCriticalSection(&This
->lock
);
1312 static HRESULT WINAPI
AudioClient_Start(IAudioClient
*iface
)
1314 ACImpl
*This
= impl_from_IAudioClient(iface
);
1317 TRACE("(%p)\n", This
);
1319 EnterCriticalSection(&This
->lock
);
1322 LeaveCriticalSection(&This
->lock
);
1323 return AUDCLNT_E_NOT_INITIALIZED
;
1326 if((This
->flags
& AUDCLNT_STREAMFLAGS_EVENTCALLBACK
) && !This
->event
){
1327 LeaveCriticalSection(&This
->lock
);
1328 return AUDCLNT_E_EVENTHANDLE_NOT_SET
;
1332 LeaveCriticalSection(&This
->lock
);
1333 return AUDCLNT_E_NOT_STOPPED
;
1336 if(This
->dataflow
== eRender
)
1337 mask
= PCM_ENABLE_OUTPUT
;
1338 else if(This
->dataflow
== eCapture
)
1339 mask
= PCM_ENABLE_INPUT
;
1341 LeaveCriticalSection(&This
->lock
);
1342 return E_UNEXPECTED
;
1345 if(ioctl(This
->fd
, SNDCTL_DSP_SETTRIGGER
, &mask
) < 0){
1346 LeaveCriticalSection(&This
->lock
);
1347 WARN("SETTRIGGER failed: %d (%s)\n", errno
, strerror(errno
));
1351 if(!CreateTimerQueueTimer(&This
->timer
, g_timer_q
,
1352 oss_period_callback
, This
, 0, This
->period_us
/ 1000,
1353 WT_EXECUTEINTIMERTHREAD
))
1354 ERR("Unable to create period timer: %u\n", GetLastError());
1356 This
->playing
= TRUE
;
1358 LeaveCriticalSection(&This
->lock
);
1363 static HRESULT WINAPI
AudioClient_Stop(IAudioClient
*iface
)
1365 ACImpl
*This
= impl_from_IAudioClient(iface
);
1368 TRACE("(%p)\n", This
);
1370 EnterCriticalSection(&This
->lock
);
1373 LeaveCriticalSection(&This
->lock
);
1374 return AUDCLNT_E_NOT_INITIALIZED
;
1378 LeaveCriticalSection(&This
->lock
);
1382 if(This
->timer
&& This
->timer
!= INVALID_HANDLE_VALUE
){
1383 DeleteTimerQueueTimer(g_timer_q
, This
->timer
,
1384 INVALID_HANDLE_VALUE
);
1388 if(ioctl(This
->fd
, SNDCTL_DSP_HALT
, NULL
) < 0){
1389 LeaveCriticalSection(&This
->lock
);
1390 WARN("HALT failed: %d (%s)\n", errno
, strerror(errno
));
1395 if(ioctl(This
->fd
, SNDCTL_DSP_SETTRIGGER
, &mask
) < 0){
1396 LeaveCriticalSection(&This
->lock
);
1397 WARN("SETTRIGGER failed: %d (%s)\n", errno
, strerror(errno
));
1401 This
->playing
= FALSE
;
1403 LeaveCriticalSection(&This
->lock
);
1408 static HRESULT WINAPI
AudioClient_Reset(IAudioClient
*iface
)
1410 ACImpl
*This
= impl_from_IAudioClient(iface
);
1412 TRACE("(%p)\n", This
);
1414 EnterCriticalSection(&This
->lock
);
1417 LeaveCriticalSection(&This
->lock
);
1418 return AUDCLNT_E_NOT_INITIALIZED
;
1422 LeaveCriticalSection(&This
->lock
);
1423 return AUDCLNT_E_NOT_STOPPED
;
1426 if(This
->buf_state
!= NOT_LOCKED
){
1427 LeaveCriticalSection(&This
->lock
);
1428 return AUDCLNT_E_BUFFER_OPERATION_PENDING
;
1431 This
->written_frames
= 0;
1432 This
->inbuf_frames
= 0;
1433 This
->held_frames
= 0;
1435 if(ioctl(This
->fd
, SNDCTL_DSP_SKIP
, NULL
) < 0)
1436 WARN("SKIP failed: %d (%s)\n", errno
, strerror(errno
));
1438 LeaveCriticalSection(&This
->lock
);
1443 static HRESULT WINAPI
AudioClient_SetEventHandle(IAudioClient
*iface
,
1446 ACImpl
*This
= impl_from_IAudioClient(iface
);
1448 TRACE("(%p)->(%p)\n", This
, event
);
1451 return E_INVALIDARG
;
1453 EnterCriticalSection(&This
->lock
);
1456 LeaveCriticalSection(&This
->lock
);
1457 return AUDCLNT_E_NOT_INITIALIZED
;
1460 if(!(This
->flags
& AUDCLNT_STREAMFLAGS_EVENTCALLBACK
)){
1461 LeaveCriticalSection(&This
->lock
);
1462 return AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED
;
1465 This
->event
= event
;
1467 LeaveCriticalSection(&This
->lock
);
1472 static HRESULT WINAPI
AudioClient_GetService(IAudioClient
*iface
, REFIID riid
,
1475 ACImpl
*This
= impl_from_IAudioClient(iface
);
1477 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1483 EnterCriticalSection(&This
->lock
);
1486 LeaveCriticalSection(&This
->lock
);
1487 return AUDCLNT_E_NOT_INITIALIZED
;
1490 if(IsEqualIID(riid
, &IID_IAudioRenderClient
)){
1491 if(This
->dataflow
!= eRender
){
1492 LeaveCriticalSection(&This
->lock
);
1493 return AUDCLNT_E_WRONG_ENDPOINT_TYPE
;
1495 IAudioRenderClient_AddRef(&This
->IAudioRenderClient_iface
);
1496 *ppv
= &This
->IAudioRenderClient_iface
;
1497 }else if(IsEqualIID(riid
, &IID_IAudioCaptureClient
)){
1498 if(This
->dataflow
!= eCapture
){
1499 LeaveCriticalSection(&This
->lock
);
1500 return AUDCLNT_E_WRONG_ENDPOINT_TYPE
;
1502 IAudioCaptureClient_AddRef(&This
->IAudioCaptureClient_iface
);
1503 *ppv
= &This
->IAudioCaptureClient_iface
;
1504 }else if(IsEqualIID(riid
, &IID_IAudioClock
)){
1505 IAudioClock_AddRef(&This
->IAudioClock_iface
);
1506 *ppv
= &This
->IAudioClock_iface
;
1507 }else if(IsEqualIID(riid
, &IID_IAudioStreamVolume
)){
1508 IAudioStreamVolume_AddRef(&This
->IAudioStreamVolume_iface
);
1509 *ppv
= &This
->IAudioStreamVolume_iface
;
1510 }else if(IsEqualIID(riid
, &IID_IAudioSessionControl
)){
1511 if(!This
->session_wrapper
){
1512 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1513 if(!This
->session_wrapper
){
1514 LeaveCriticalSection(&This
->lock
);
1515 return E_OUTOFMEMORY
;
1518 IAudioSessionControl2_AddRef(&This
->session_wrapper
->IAudioSessionControl2_iface
);
1520 *ppv
= &This
->session_wrapper
->IAudioSessionControl2_iface
;
1521 }else if(IsEqualIID(riid
, &IID_IChannelAudioVolume
)){
1522 if(!This
->session_wrapper
){
1523 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1524 if(!This
->session_wrapper
){
1525 LeaveCriticalSection(&This
->lock
);
1526 return E_OUTOFMEMORY
;
1529 IChannelAudioVolume_AddRef(&This
->session_wrapper
->IChannelAudioVolume_iface
);
1531 *ppv
= &This
->session_wrapper
->IChannelAudioVolume_iface
;
1532 }else if(IsEqualIID(riid
, &IID_ISimpleAudioVolume
)){
1533 if(!This
->session_wrapper
){
1534 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1535 if(!This
->session_wrapper
){
1536 LeaveCriticalSection(&This
->lock
);
1537 return E_OUTOFMEMORY
;
1540 ISimpleAudioVolume_AddRef(&This
->session_wrapper
->ISimpleAudioVolume_iface
);
1542 *ppv
= &This
->session_wrapper
->ISimpleAudioVolume_iface
;
1546 LeaveCriticalSection(&This
->lock
);
1550 LeaveCriticalSection(&This
->lock
);
1552 FIXME("stub %s\n", debugstr_guid(riid
));
1553 return E_NOINTERFACE
;
1556 static const IAudioClientVtbl AudioClient_Vtbl
=
1558 AudioClient_QueryInterface
,
1560 AudioClient_Release
,
1561 AudioClient_Initialize
,
1562 AudioClient_GetBufferSize
,
1563 AudioClient_GetStreamLatency
,
1564 AudioClient_GetCurrentPadding
,
1565 AudioClient_IsFormatSupported
,
1566 AudioClient_GetMixFormat
,
1567 AudioClient_GetDevicePeriod
,
1571 AudioClient_SetEventHandle
,
1572 AudioClient_GetService
1575 static HRESULT WINAPI
AudioRenderClient_QueryInterface(
1576 IAudioRenderClient
*iface
, REFIID riid
, void **ppv
)
1578 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1584 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1585 IsEqualIID(riid
, &IID_IAudioRenderClient
))
1588 IUnknown_AddRef((IUnknown
*)*ppv
);
1592 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1593 return E_NOINTERFACE
;
1596 static ULONG WINAPI
AudioRenderClient_AddRef(IAudioRenderClient
*iface
)
1598 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1599 return AudioClient_AddRef(&This
->IAudioClient_iface
);
1602 static ULONG WINAPI
AudioRenderClient_Release(IAudioRenderClient
*iface
)
1604 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1605 return AudioClient_Release(&This
->IAudioClient_iface
);
1608 static HRESULT WINAPI
AudioRenderClient_GetBuffer(IAudioRenderClient
*iface
,
1609 UINT32 frames
, BYTE
**data
)
1611 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1612 UINT32 pad
, write_pos
;
1615 TRACE("(%p)->(%u, %p)\n", This
, frames
, data
);
1620 EnterCriticalSection(&This
->lock
);
1622 if(This
->buf_state
!= NOT_LOCKED
){
1623 LeaveCriticalSection(&This
->lock
);
1624 return AUDCLNT_E_OUT_OF_ORDER
;
1628 This
->buf_state
= LOCKED_NORMAL
;
1629 LeaveCriticalSection(&This
->lock
);
1633 hr
= IAudioClient_GetCurrentPadding(&This
->IAudioClient_iface
, &pad
);
1635 LeaveCriticalSection(&This
->lock
);
1639 if(pad
+ frames
> This
->bufsize_frames
){
1640 LeaveCriticalSection(&This
->lock
);
1641 return AUDCLNT_E_BUFFER_TOO_LARGE
;
1645 (This
->lcl_offs_frames
+ This
->held_frames
) % This
->bufsize_frames
;
1646 if(write_pos
+ frames
> This
->bufsize_frames
){
1647 if(This
->tmp_buffer_frames
< frames
){
1648 if(This
->tmp_buffer
)
1649 This
->tmp_buffer
= HeapReAlloc(GetProcessHeap(), 0,
1650 This
->tmp_buffer
, frames
* This
->fmt
->nBlockAlign
);
1652 This
->tmp_buffer
= HeapAlloc(GetProcessHeap(), 0,
1653 frames
* This
->fmt
->nBlockAlign
);
1654 if(!This
->tmp_buffer
){
1655 LeaveCriticalSection(&This
->lock
);
1656 return E_OUTOFMEMORY
;
1658 This
->tmp_buffer_frames
= frames
;
1660 *data
= This
->tmp_buffer
;
1661 This
->buf_state
= LOCKED_WRAPPED
;
1663 *data
= This
->local_buffer
+ write_pos
* This
->fmt
->nBlockAlign
;
1664 This
->buf_state
= LOCKED_NORMAL
;
1667 LeaveCriticalSection(&This
->lock
);
1672 static void oss_wrap_buffer(ACImpl
*This
, BYTE
*buffer
, UINT32 written_frames
)
1674 UINT32 write_offs_frames
=
1675 (This
->lcl_offs_frames
+ This
->held_frames
) % This
->bufsize_frames
;
1676 UINT32 write_offs_bytes
= write_offs_frames
* This
->fmt
->nBlockAlign
;
1677 UINT32 chunk_frames
= This
->bufsize_frames
- write_offs_frames
;
1678 UINT32 chunk_bytes
= chunk_frames
* This
->fmt
->nBlockAlign
;
1679 UINT32 written_bytes
= written_frames
* This
->fmt
->nBlockAlign
;
1681 if(written_bytes
<= chunk_bytes
){
1682 memcpy(This
->local_buffer
+ write_offs_bytes
, buffer
, written_bytes
);
1684 memcpy(This
->local_buffer
+ write_offs_bytes
, buffer
, chunk_bytes
);
1685 memcpy(This
->local_buffer
, buffer
+ chunk_bytes
,
1686 written_bytes
- chunk_bytes
);
1690 static HRESULT WINAPI
AudioRenderClient_ReleaseBuffer(
1691 IAudioRenderClient
*iface
, UINT32 written_frames
, DWORD flags
)
1693 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1696 TRACE("(%p)->(%u, %x)\n", This
, written_frames
, flags
);
1698 EnterCriticalSection(&This
->lock
);
1700 if(This
->buf_state
== NOT_LOCKED
|| !written_frames
){
1701 This
->buf_state
= NOT_LOCKED
;
1702 LeaveCriticalSection(&This
->lock
);
1703 return written_frames
? AUDCLNT_E_OUT_OF_ORDER
: S_OK
;
1706 if(This
->buf_state
== LOCKED_NORMAL
)
1707 buffer
= This
->local_buffer
+ This
->fmt
->nBlockAlign
*
1708 ((This
->lcl_offs_frames
+ This
->held_frames
) % This
->bufsize_frames
);
1710 buffer
= This
->tmp_buffer
;
1712 if(flags
& AUDCLNT_BUFFERFLAGS_SILENT
)
1713 oss_silence_buffer(This
, buffer
, written_frames
);
1715 if(This
->held_frames
){
1716 if(This
->buf_state
== LOCKED_WRAPPED
)
1717 oss_wrap_buffer(This
, buffer
, written_frames
);
1719 This
->held_frames
+= written_frames
;
1724 if(This
->session
->mute
)
1725 oss_silence_buffer(This
, buffer
, written_frames
);
1727 w_bytes
= write(This
->fd
, buffer
,
1728 written_frames
* This
->fmt
->nBlockAlign
);
1730 if(errno
!= EAGAIN
){
1731 This
->buf_state
= NOT_LOCKED
;
1732 LeaveCriticalSection(&This
->lock
);
1733 ERR("write failed: %d (%s)\n", errno
, strerror(errno
));
1735 }else /* OSS buffer full */
1738 w_frames
= w_bytes
/ This
->fmt
->nBlockAlign
;
1739 This
->inbuf_frames
+= w_frames
;
1741 if(w_frames
< written_frames
){
1742 if(This
->buf_state
== LOCKED_WRAPPED
)
1743 oss_wrap_buffer(This
, This
->tmp_buffer
+ w_bytes
,
1744 written_frames
- w_frames
);
1746 This
->lcl_offs_frames
+= w_frames
;
1747 This
->held_frames
= written_frames
- w_frames
;
1751 This
->written_frames
+= written_frames
;
1752 This
->buf_state
= NOT_LOCKED
;
1754 LeaveCriticalSection(&This
->lock
);
1759 static const IAudioRenderClientVtbl AudioRenderClient_Vtbl
= {
1760 AudioRenderClient_QueryInterface
,
1761 AudioRenderClient_AddRef
,
1762 AudioRenderClient_Release
,
1763 AudioRenderClient_GetBuffer
,
1764 AudioRenderClient_ReleaseBuffer
1767 static HRESULT WINAPI
AudioCaptureClient_QueryInterface(
1768 IAudioCaptureClient
*iface
, REFIID riid
, void **ppv
)
1770 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1776 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1777 IsEqualIID(riid
, &IID_IAudioCaptureClient
))
1780 IUnknown_AddRef((IUnknown
*)*ppv
);
1784 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1785 return E_NOINTERFACE
;
1788 static ULONG WINAPI
AudioCaptureClient_AddRef(IAudioCaptureClient
*iface
)
1790 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1791 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
1794 static ULONG WINAPI
AudioCaptureClient_Release(IAudioCaptureClient
*iface
)
1796 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1797 return IAudioClient_Release(&This
->IAudioClient_iface
);
1800 static HRESULT WINAPI
AudioCaptureClient_GetBuffer(IAudioCaptureClient
*iface
,
1801 BYTE
**data
, UINT32
*frames
, DWORD
*flags
, UINT64
*devpos
,
1804 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1807 TRACE("(%p)->(%p, %p, %p, %p, %p)\n", This
, data
, frames
, flags
,
1810 if(!data
|| !frames
|| !flags
)
1813 EnterCriticalSection(&This
->lock
);
1815 if(This
->buf_state
!= NOT_LOCKED
){
1816 LeaveCriticalSection(&This
->lock
);
1817 return AUDCLNT_E_OUT_OF_ORDER
;
1820 hr
= IAudioCaptureClient_GetNextPacketSize(iface
, frames
);
1822 LeaveCriticalSection(&This
->lock
);
1828 if(This
->lcl_offs_frames
+ *frames
> This
->bufsize_frames
){
1829 UINT32 chunk_bytes
, offs_bytes
, frames_bytes
;
1830 if(This
->tmp_buffer_frames
< *frames
){
1831 if(This
->tmp_buffer
)
1832 This
->tmp_buffer
= HeapReAlloc(GetProcessHeap(), 0,
1833 This
->tmp_buffer
, *frames
* This
->fmt
->nBlockAlign
);
1835 This
->tmp_buffer
= HeapAlloc(GetProcessHeap(), 0,
1836 *frames
* This
->fmt
->nBlockAlign
);
1837 if(!This
->tmp_buffer
){
1838 LeaveCriticalSection(&This
->lock
);
1839 return E_OUTOFMEMORY
;
1841 This
->tmp_buffer_frames
= *frames
;
1844 *data
= This
->tmp_buffer
;
1845 chunk_bytes
= (This
->bufsize_frames
- This
->lcl_offs_frames
) *
1846 This
->fmt
->nBlockAlign
;
1847 offs_bytes
= This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
;
1848 frames_bytes
= *frames
* This
->fmt
->nBlockAlign
;
1849 memcpy(This
->tmp_buffer
, This
->local_buffer
+ offs_bytes
, chunk_bytes
);
1850 memcpy(This
->tmp_buffer
, This
->local_buffer
,
1851 frames_bytes
- chunk_bytes
);
1853 *data
= This
->local_buffer
+
1854 This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
;
1856 This
->buf_state
= LOCKED_NORMAL
;
1858 if(devpos
|| qpcpos
)
1859 IAudioClock_GetPosition(&This
->IAudioClock_iface
, devpos
, qpcpos
);
1861 LeaveCriticalSection(&This
->lock
);
1863 return *frames
? S_OK
: AUDCLNT_S_BUFFER_EMPTY
;
1866 static HRESULT WINAPI
AudioCaptureClient_ReleaseBuffer(
1867 IAudioCaptureClient
*iface
, UINT32 done
)
1869 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1871 TRACE("(%p)->(%u)\n", This
, done
);
1873 EnterCriticalSection(&This
->lock
);
1875 if(This
->buf_state
== NOT_LOCKED
){
1876 LeaveCriticalSection(&This
->lock
);
1877 return AUDCLNT_E_OUT_OF_ORDER
;
1880 This
->held_frames
-= done
;
1881 This
->lcl_offs_frames
+= done
;
1882 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1884 This
->buf_state
= NOT_LOCKED
;
1886 LeaveCriticalSection(&This
->lock
);
1891 static HRESULT WINAPI
AudioCaptureClient_GetNextPacketSize(
1892 IAudioCaptureClient
*iface
, UINT32
*frames
)
1894 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1896 TRACE("(%p)->(%p)\n", This
, frames
);
1898 return AudioClient_GetCurrentPadding(&This
->IAudioClient_iface
, frames
);
1901 static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl
=
1903 AudioCaptureClient_QueryInterface
,
1904 AudioCaptureClient_AddRef
,
1905 AudioCaptureClient_Release
,
1906 AudioCaptureClient_GetBuffer
,
1907 AudioCaptureClient_ReleaseBuffer
,
1908 AudioCaptureClient_GetNextPacketSize
1911 static HRESULT WINAPI
AudioClock_QueryInterface(IAudioClock
*iface
,
1912 REFIID riid
, void **ppv
)
1914 ACImpl
*This
= impl_from_IAudioClock(iface
);
1916 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1922 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IAudioClock
))
1924 else if(IsEqualIID(riid
, &IID_IAudioClock2
))
1925 *ppv
= &This
->IAudioClock2_iface
;
1927 IUnknown_AddRef((IUnknown
*)*ppv
);
1931 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1932 return E_NOINTERFACE
;
1935 static ULONG WINAPI
AudioClock_AddRef(IAudioClock
*iface
)
1937 ACImpl
*This
= impl_from_IAudioClock(iface
);
1938 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
1941 static ULONG WINAPI
AudioClock_Release(IAudioClock
*iface
)
1943 ACImpl
*This
= impl_from_IAudioClock(iface
);
1944 return IAudioClient_Release(&This
->IAudioClient_iface
);
1947 static HRESULT WINAPI
AudioClock_GetFrequency(IAudioClock
*iface
, UINT64
*freq
)
1949 ACImpl
*This
= impl_from_IAudioClock(iface
);
1951 TRACE("(%p)->(%p)\n", This
, freq
);
1953 *freq
= This
->fmt
->nSamplesPerSec
;
1958 static HRESULT WINAPI
AudioClock_GetPosition(IAudioClock
*iface
, UINT64
*pos
,
1961 ACImpl
*This
= impl_from_IAudioClock(iface
);
1965 TRACE("(%p)->(%p, %p)\n", This
, pos
, qpctime
);
1970 EnterCriticalSection(&This
->lock
);
1972 hr
= IAudioClient_GetCurrentPadding(&This
->IAudioClient_iface
, &pad
);
1974 LeaveCriticalSection(&This
->lock
);
1978 if(This
->dataflow
== eRender
)
1979 *pos
= This
->written_frames
- pad
;
1980 else if(This
->dataflow
== eCapture
)
1981 *pos
= This
->written_frames
+ pad
;
1983 LeaveCriticalSection(&This
->lock
);
1986 LARGE_INTEGER stamp
, freq
;
1987 QueryPerformanceCounter(&stamp
);
1988 QueryPerformanceFrequency(&freq
);
1989 *qpctime
= (stamp
.QuadPart
* (INT64
)10000000) / freq
.QuadPart
;
1995 static HRESULT WINAPI
AudioClock_GetCharacteristics(IAudioClock
*iface
,
1998 ACImpl
*This
= impl_from_IAudioClock(iface
);
2000 TRACE("(%p)->(%p)\n", This
, chars
);
2005 *chars
= AUDIOCLOCK_CHARACTERISTIC_FIXED_FREQ
;
2010 static const IAudioClockVtbl AudioClock_Vtbl
=
2012 AudioClock_QueryInterface
,
2015 AudioClock_GetFrequency
,
2016 AudioClock_GetPosition
,
2017 AudioClock_GetCharacteristics
2020 static HRESULT WINAPI
AudioClock2_QueryInterface(IAudioClock2
*iface
,
2021 REFIID riid
, void **ppv
)
2023 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2024 return IAudioClock_QueryInterface(&This
->IAudioClock_iface
, riid
, ppv
);
2027 static ULONG WINAPI
AudioClock2_AddRef(IAudioClock2
*iface
)
2029 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2030 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
2033 static ULONG WINAPI
AudioClock2_Release(IAudioClock2
*iface
)
2035 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2036 return IAudioClient_Release(&This
->IAudioClient_iface
);
2039 static HRESULT WINAPI
AudioClock2_GetDevicePosition(IAudioClock2
*iface
,
2040 UINT64
*pos
, UINT64
*qpctime
)
2042 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2044 FIXME("(%p)->(%p, %p)\n", This
, pos
, qpctime
);
2049 static const IAudioClock2Vtbl AudioClock2_Vtbl
=
2051 AudioClock2_QueryInterface
,
2053 AudioClock2_Release
,
2054 AudioClock2_GetDevicePosition
2057 static AudioSessionWrapper
*AudioSessionWrapper_Create(ACImpl
*client
)
2059 AudioSessionWrapper
*ret
;
2061 ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2062 sizeof(AudioSessionWrapper
));
2066 ret
->IAudioSessionControl2_iface
.lpVtbl
= &AudioSessionControl2_Vtbl
;
2067 ret
->ISimpleAudioVolume_iface
.lpVtbl
= &SimpleAudioVolume_Vtbl
;
2068 ret
->IChannelAudioVolume_iface
.lpVtbl
= &ChannelAudioVolume_Vtbl
;
2072 ret
->client
= client
;
2074 ret
->session
= client
->session
;
2075 AudioClient_AddRef(&client
->IAudioClient_iface
);
2081 static HRESULT WINAPI
AudioSessionControl_QueryInterface(
2082 IAudioSessionControl2
*iface
, REFIID riid
, void **ppv
)
2084 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2090 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2091 IsEqualIID(riid
, &IID_IAudioSessionControl
) ||
2092 IsEqualIID(riid
, &IID_IAudioSessionControl2
))
2095 IUnknown_AddRef((IUnknown
*)*ppv
);
2099 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2100 return E_NOINTERFACE
;
2103 static ULONG WINAPI
AudioSessionControl_AddRef(IAudioSessionControl2
*iface
)
2105 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2107 ref
= InterlockedIncrement(&This
->ref
);
2108 TRACE("(%p) Refcount now %u\n", This
, ref
);
2112 static ULONG WINAPI
AudioSessionControl_Release(IAudioSessionControl2
*iface
)
2114 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2116 ref
= InterlockedDecrement(&This
->ref
);
2117 TRACE("(%p) Refcount now %u\n", This
, ref
);
2120 EnterCriticalSection(&This
->client
->lock
);
2121 This
->client
->session_wrapper
= NULL
;
2122 LeaveCriticalSection(&This
->client
->lock
);
2123 AudioClient_Release(&This
->client
->IAudioClient_iface
);
2125 HeapFree(GetProcessHeap(), 0, This
);
2130 static HRESULT WINAPI
AudioSessionControl_GetState(IAudioSessionControl2
*iface
,
2131 AudioSessionState
*state
)
2133 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2136 TRACE("(%p)->(%p)\n", This
, state
);
2139 return NULL_PTR_ERR
;
2141 EnterCriticalSection(&g_sessions_lock
);
2143 if(list_empty(&This
->session
->clients
)){
2144 *state
= AudioSessionStateExpired
;
2145 LeaveCriticalSection(&g_sessions_lock
);
2149 LIST_FOR_EACH_ENTRY(client
, &This
->session
->clients
, ACImpl
, entry
){
2150 EnterCriticalSection(&client
->lock
);
2151 if(client
->playing
){
2152 *state
= AudioSessionStateActive
;
2153 LeaveCriticalSection(&client
->lock
);
2154 LeaveCriticalSection(&g_sessions_lock
);
2157 LeaveCriticalSection(&client
->lock
);
2160 LeaveCriticalSection(&g_sessions_lock
);
2162 *state
= AudioSessionStateInactive
;
2167 static HRESULT WINAPI
AudioSessionControl_GetDisplayName(
2168 IAudioSessionControl2
*iface
, WCHAR
**name
)
2170 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2172 FIXME("(%p)->(%p) - stub\n", This
, name
);
2177 static HRESULT WINAPI
AudioSessionControl_SetDisplayName(
2178 IAudioSessionControl2
*iface
, const WCHAR
*name
, const GUID
*session
)
2180 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2182 FIXME("(%p)->(%p, %s) - stub\n", This
, name
, debugstr_guid(session
));
2187 static HRESULT WINAPI
AudioSessionControl_GetIconPath(
2188 IAudioSessionControl2
*iface
, WCHAR
**path
)
2190 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2192 FIXME("(%p)->(%p) - stub\n", This
, path
);
2197 static HRESULT WINAPI
AudioSessionControl_SetIconPath(
2198 IAudioSessionControl2
*iface
, const WCHAR
*path
, const GUID
*session
)
2200 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2202 FIXME("(%p)->(%p, %s) - stub\n", This
, path
, debugstr_guid(session
));
2207 static HRESULT WINAPI
AudioSessionControl_GetGroupingParam(
2208 IAudioSessionControl2
*iface
, GUID
*group
)
2210 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2212 FIXME("(%p)->(%p) - stub\n", This
, group
);
2217 static HRESULT WINAPI
AudioSessionControl_SetGroupingParam(
2218 IAudioSessionControl2
*iface
, const GUID
*group
, const GUID
*session
)
2220 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2222 FIXME("(%p)->(%s, %s) - stub\n", This
, debugstr_guid(group
),
2223 debugstr_guid(session
));
2228 static HRESULT WINAPI
AudioSessionControl_RegisterAudioSessionNotification(
2229 IAudioSessionControl2
*iface
, IAudioSessionEvents
*events
)
2231 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2233 FIXME("(%p)->(%p) - stub\n", This
, events
);
2238 static HRESULT WINAPI
AudioSessionControl_UnregisterAudioSessionNotification(
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_GetSessionIdentifier(
2249 IAudioSessionControl2
*iface
, WCHAR
**id
)
2251 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2253 FIXME("(%p)->(%p) - stub\n", This
, id
);
2258 static HRESULT WINAPI
AudioSessionControl_GetSessionInstanceIdentifier(
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_GetProcessId(
2269 IAudioSessionControl2
*iface
, DWORD
*pid
)
2271 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2273 TRACE("(%p)->(%p)\n", This
, pid
);
2278 *pid
= GetCurrentProcessId();
2283 static HRESULT WINAPI
AudioSessionControl_IsSystemSoundsSession(
2284 IAudioSessionControl2
*iface
)
2286 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2288 TRACE("(%p)\n", This
);
2293 static HRESULT WINAPI
AudioSessionControl_SetDuckingPreference(
2294 IAudioSessionControl2
*iface
, BOOL optout
)
2296 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2298 TRACE("(%p)->(%d)\n", This
, optout
);
2303 static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl
=
2305 AudioSessionControl_QueryInterface
,
2306 AudioSessionControl_AddRef
,
2307 AudioSessionControl_Release
,
2308 AudioSessionControl_GetState
,
2309 AudioSessionControl_GetDisplayName
,
2310 AudioSessionControl_SetDisplayName
,
2311 AudioSessionControl_GetIconPath
,
2312 AudioSessionControl_SetIconPath
,
2313 AudioSessionControl_GetGroupingParam
,
2314 AudioSessionControl_SetGroupingParam
,
2315 AudioSessionControl_RegisterAudioSessionNotification
,
2316 AudioSessionControl_UnregisterAudioSessionNotification
,
2317 AudioSessionControl_GetSessionIdentifier
,
2318 AudioSessionControl_GetSessionInstanceIdentifier
,
2319 AudioSessionControl_GetProcessId
,
2320 AudioSessionControl_IsSystemSoundsSession
,
2321 AudioSessionControl_SetDuckingPreference
2324 /* index == -1 means set all channels, otherwise sets only the given channel */
2325 static HRESULT
oss_setvol(ACImpl
*This
, UINT32 index
)
2332 if(index
== (UINT32
)-1){
2335 for(i
= 0; i
< This
->fmt
->nChannels
; ++i
){
2337 hr
= oss_setvol(This
, i
);
2345 /* OSS doesn't support volume control past the first two channels */
2348 if(This
->dataflow
== eRender
){
2349 setreq
= SNDCTL_DSP_SETPLAYVOL
;
2350 getreq
= SNDCTL_DSP_GETPLAYVOL
;
2351 }else if(This
->dataflow
== eCapture
){
2352 setreq
= SNDCTL_DSP_SETRECVOL
;
2353 getreq
= SNDCTL_DSP_GETRECVOL
;
2355 return E_UNEXPECTED
;
2357 if(ioctl(This
->fd
, getreq
, &vol
) < 0){
2359 /* device doesn't support this call */
2362 WARN("GET[REC|PLAY]VOL failed: %d (%s)\n", errno
, strerror(errno
));
2366 level
= This
->session
->master_vol
* This
->session
->channel_vols
[index
] *
2370 vol
= l
| (vol
& 0xFF00);
2372 vol
= (vol
& 0xFF) | (l
<< 8);
2374 if(ioctl(This
->fd
, setreq
, &vol
) < 0){
2376 /* device doesn't support this call */
2379 WARN("SET[REC|PLAY]VOL failed: %d (%s)\n", errno
, strerror(errno
));
2386 static HRESULT
oss_session_setvol(AudioSession
*session
, UINT32 index
)
2391 LIST_FOR_EACH_ENTRY(client
, &session
->clients
, ACImpl
, entry
){
2393 hr
= oss_setvol(client
, index
);
2401 static HRESULT WINAPI
SimpleAudioVolume_QueryInterface(
2402 ISimpleAudioVolume
*iface
, REFIID riid
, void **ppv
)
2404 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2410 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2411 IsEqualIID(riid
, &IID_ISimpleAudioVolume
))
2414 IUnknown_AddRef((IUnknown
*)*ppv
);
2418 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2419 return E_NOINTERFACE
;
2422 static ULONG WINAPI
SimpleAudioVolume_AddRef(ISimpleAudioVolume
*iface
)
2424 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2425 return AudioSessionControl_AddRef(&This
->IAudioSessionControl2_iface
);
2428 static ULONG WINAPI
SimpleAudioVolume_Release(ISimpleAudioVolume
*iface
)
2430 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2431 return AudioSessionControl_Release(&This
->IAudioSessionControl2_iface
);
2434 static HRESULT WINAPI
SimpleAudioVolume_SetMasterVolume(
2435 ISimpleAudioVolume
*iface
, float level
, const GUID
*context
)
2437 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2438 AudioSession
*session
= This
->session
;
2441 TRACE("(%p)->(%f, %s)\n", session
, level
, wine_dbgstr_guid(context
));
2443 if(level
< 0.f
|| level
> 1.f
)
2444 return E_INVALIDARG
;
2447 FIXME("Notifications not supported yet\n");
2449 EnterCriticalSection(&session
->lock
);
2451 session
->master_vol
= level
;
2453 ret
= oss_session_setvol(session
, -1);
2455 LeaveCriticalSection(&session
->lock
);
2460 static HRESULT WINAPI
SimpleAudioVolume_GetMasterVolume(
2461 ISimpleAudioVolume
*iface
, float *level
)
2463 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2464 AudioSession
*session
= This
->session
;
2466 TRACE("(%p)->(%p)\n", session
, level
);
2469 return NULL_PTR_ERR
;
2471 *level
= session
->master_vol
;
2476 static HRESULT WINAPI
SimpleAudioVolume_SetMute(ISimpleAudioVolume
*iface
,
2477 BOOL mute
, const GUID
*context
)
2479 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2480 AudioSession
*session
= This
->session
;
2482 TRACE("(%p)->(%u, %p)\n", session
, mute
, context
);
2484 EnterCriticalSection(&session
->lock
);
2486 if(!mute
&& session
->mute
){
2489 session
->mute
= mute
;
2491 LIST_FOR_EACH_ENTRY(client
, &session
->clients
, ACImpl
, entry
){
2492 EnterCriticalSection(&client
->lock
);
2493 if(ioctl(client
->fd
, SNDCTL_DSP_SKIP
) < 0)
2494 WARN("Error calling DSP_SKIP: %d (%s)\n", errno
,
2496 oss_write_data(client
);
2497 LeaveCriticalSection(&client
->lock
);
2500 session
->mute
= mute
;
2502 LeaveCriticalSection(&session
->lock
);
2507 static HRESULT WINAPI
SimpleAudioVolume_GetMute(ISimpleAudioVolume
*iface
,
2510 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2511 AudioSession
*session
= This
->session
;
2513 TRACE("(%p)->(%p)\n", session
, mute
);
2516 return NULL_PTR_ERR
;
2518 *mute
= This
->session
->mute
;
2523 static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl
=
2525 SimpleAudioVolume_QueryInterface
,
2526 SimpleAudioVolume_AddRef
,
2527 SimpleAudioVolume_Release
,
2528 SimpleAudioVolume_SetMasterVolume
,
2529 SimpleAudioVolume_GetMasterVolume
,
2530 SimpleAudioVolume_SetMute
,
2531 SimpleAudioVolume_GetMute
2534 static HRESULT WINAPI
AudioStreamVolume_QueryInterface(
2535 IAudioStreamVolume
*iface
, REFIID riid
, void **ppv
)
2537 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2543 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2544 IsEqualIID(riid
, &IID_IAudioStreamVolume
))
2547 IUnknown_AddRef((IUnknown
*)*ppv
);
2551 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2552 return E_NOINTERFACE
;
2555 static ULONG WINAPI
AudioStreamVolume_AddRef(IAudioStreamVolume
*iface
)
2557 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2558 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
2561 static ULONG WINAPI
AudioStreamVolume_Release(IAudioStreamVolume
*iface
)
2563 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2564 return IAudioClient_Release(&This
->IAudioClient_iface
);
2567 static HRESULT WINAPI
AudioStreamVolume_GetChannelCount(
2568 IAudioStreamVolume
*iface
, UINT32
*out
)
2570 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2572 TRACE("(%p)->(%p)\n", This
, out
);
2577 *out
= This
->fmt
->nChannels
;
2582 static HRESULT WINAPI
AudioStreamVolume_SetChannelVolume(
2583 IAudioStreamVolume
*iface
, UINT32 index
, float level
)
2585 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2588 TRACE("(%p)->(%d, %f)\n", This
, index
, level
);
2590 if(level
< 0.f
|| level
> 1.f
)
2591 return E_INVALIDARG
;
2593 if(index
>= This
->fmt
->nChannels
)
2594 return E_INVALIDARG
;
2596 EnterCriticalSection(&This
->lock
);
2598 This
->vols
[index
] = level
;
2600 ret
= oss_setvol(This
, index
);
2602 LeaveCriticalSection(&This
->lock
);
2607 static HRESULT WINAPI
AudioStreamVolume_GetChannelVolume(
2608 IAudioStreamVolume
*iface
, UINT32 index
, float *level
)
2610 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2612 TRACE("(%p)->(%d, %p)\n", This
, index
, level
);
2617 if(index
>= This
->fmt
->nChannels
)
2618 return E_INVALIDARG
;
2620 *level
= This
->vols
[index
];
2625 static HRESULT WINAPI
AudioStreamVolume_SetAllVolumes(
2626 IAudioStreamVolume
*iface
, UINT32 count
, const float *levels
)
2628 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2632 TRACE("(%p)->(%d, %p)\n", This
, count
, levels
);
2637 if(count
!= This
->fmt
->nChannels
)
2638 return E_INVALIDARG
;
2640 EnterCriticalSection(&This
->lock
);
2642 for(i
= 0; i
< count
; ++i
)
2643 This
->vols
[i
] = levels
[i
];
2645 ret
= oss_setvol(This
, -1);
2647 LeaveCriticalSection(&This
->lock
);
2652 static HRESULT WINAPI
AudioStreamVolume_GetAllVolumes(
2653 IAudioStreamVolume
*iface
, UINT32 count
, float *levels
)
2655 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2658 TRACE("(%p)->(%d, %p)\n", This
, count
, levels
);
2663 if(count
!= This
->fmt
->nChannels
)
2664 return E_INVALIDARG
;
2666 EnterCriticalSection(&This
->lock
);
2668 for(i
= 0; i
< count
; ++i
)
2669 levels
[i
] = This
->vols
[i
];
2671 LeaveCriticalSection(&This
->lock
);
2676 static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl
=
2678 AudioStreamVolume_QueryInterface
,
2679 AudioStreamVolume_AddRef
,
2680 AudioStreamVolume_Release
,
2681 AudioStreamVolume_GetChannelCount
,
2682 AudioStreamVolume_SetChannelVolume
,
2683 AudioStreamVolume_GetChannelVolume
,
2684 AudioStreamVolume_SetAllVolumes
,
2685 AudioStreamVolume_GetAllVolumes
2688 static HRESULT WINAPI
ChannelAudioVolume_QueryInterface(
2689 IChannelAudioVolume
*iface
, REFIID riid
, void **ppv
)
2691 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2697 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2698 IsEqualIID(riid
, &IID_IChannelAudioVolume
))
2701 IUnknown_AddRef((IUnknown
*)*ppv
);
2705 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2706 return E_NOINTERFACE
;
2709 static ULONG WINAPI
ChannelAudioVolume_AddRef(IChannelAudioVolume
*iface
)
2711 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2712 return AudioSessionControl_AddRef(&This
->IAudioSessionControl2_iface
);
2715 static ULONG WINAPI
ChannelAudioVolume_Release(IChannelAudioVolume
*iface
)
2717 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2718 return AudioSessionControl_Release(&This
->IAudioSessionControl2_iface
);
2721 static HRESULT WINAPI
ChannelAudioVolume_GetChannelCount(
2722 IChannelAudioVolume
*iface
, UINT32
*out
)
2724 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2725 AudioSession
*session
= This
->session
;
2727 TRACE("(%p)->(%p)\n", session
, out
);
2730 return NULL_PTR_ERR
;
2732 *out
= session
->channel_count
;
2737 static HRESULT WINAPI
ChannelAudioVolume_SetChannelVolume(
2738 IChannelAudioVolume
*iface
, UINT32 index
, float level
,
2739 const GUID
*context
)
2741 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2742 AudioSession
*session
= This
->session
;
2745 TRACE("(%p)->(%d, %f, %s)\n", session
, index
, level
,
2746 wine_dbgstr_guid(context
));
2748 if(level
< 0.f
|| level
> 1.f
)
2749 return E_INVALIDARG
;
2751 if(index
>= session
->channel_count
)
2752 return E_INVALIDARG
;
2755 FIXME("Notifications not supported yet\n");
2757 EnterCriticalSection(&session
->lock
);
2759 session
->channel_vols
[index
] = level
;
2761 ret
= oss_session_setvol(session
, index
);
2763 LeaveCriticalSection(&session
->lock
);
2768 static HRESULT WINAPI
ChannelAudioVolume_GetChannelVolume(
2769 IChannelAudioVolume
*iface
, UINT32 index
, float *level
)
2771 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2772 AudioSession
*session
= This
->session
;
2774 TRACE("(%p)->(%d, %p)\n", session
, index
, level
);
2777 return NULL_PTR_ERR
;
2779 if(index
>= session
->channel_count
)
2780 return E_INVALIDARG
;
2782 *level
= session
->channel_vols
[index
];
2787 static HRESULT WINAPI
ChannelAudioVolume_SetAllVolumes(
2788 IChannelAudioVolume
*iface
, UINT32 count
, const float *levels
,
2789 const GUID
*context
)
2791 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2792 AudioSession
*session
= This
->session
;
2796 TRACE("(%p)->(%d, %p, %s)\n", session
, count
, levels
,
2797 wine_dbgstr_guid(context
));
2800 return NULL_PTR_ERR
;
2802 if(count
!= session
->channel_count
)
2803 return E_INVALIDARG
;
2806 FIXME("Notifications not supported yet\n");
2808 EnterCriticalSection(&session
->lock
);
2810 for(i
= 0; i
< count
; ++i
)
2811 session
->channel_vols
[i
] = levels
[i
];
2813 ret
= oss_session_setvol(session
, -1);
2815 LeaveCriticalSection(&session
->lock
);
2820 static HRESULT WINAPI
ChannelAudioVolume_GetAllVolumes(
2821 IChannelAudioVolume
*iface
, UINT32 count
, float *levels
)
2823 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2824 AudioSession
*session
= This
->session
;
2827 TRACE("(%p)->(%d, %p)\n", session
, count
, levels
);
2830 return NULL_PTR_ERR
;
2832 if(count
!= session
->channel_count
)
2833 return E_INVALIDARG
;
2835 for(i
= 0; i
< count
; ++i
)
2836 levels
[i
] = session
->channel_vols
[i
];
2841 static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl
=
2843 ChannelAudioVolume_QueryInterface
,
2844 ChannelAudioVolume_AddRef
,
2845 ChannelAudioVolume_Release
,
2846 ChannelAudioVolume_GetChannelCount
,
2847 ChannelAudioVolume_SetChannelVolume
,
2848 ChannelAudioVolume_GetChannelVolume
,
2849 ChannelAudioVolume_SetAllVolumes
,
2850 ChannelAudioVolume_GetAllVolumes
2853 static HRESULT WINAPI
AudioSessionManager_QueryInterface(IAudioSessionManager2
*iface
,
2854 REFIID riid
, void **ppv
)
2856 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2862 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2863 IsEqualIID(riid
, &IID_IAudioSessionManager
) ||
2864 IsEqualIID(riid
, &IID_IAudioSessionManager2
))
2867 IUnknown_AddRef((IUnknown
*)*ppv
);
2871 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2872 return E_NOINTERFACE
;
2875 static ULONG WINAPI
AudioSessionManager_AddRef(IAudioSessionManager2
*iface
)
2877 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2879 ref
= InterlockedIncrement(&This
->ref
);
2880 TRACE("(%p) Refcount now %u\n", This
, ref
);
2884 static ULONG WINAPI
AudioSessionManager_Release(IAudioSessionManager2
*iface
)
2886 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2888 ref
= InterlockedDecrement(&This
->ref
);
2889 TRACE("(%p) Refcount now %u\n", This
, ref
);
2891 HeapFree(GetProcessHeap(), 0, This
);
2895 static HRESULT WINAPI
AudioSessionManager_GetAudioSessionControl(
2896 IAudioSessionManager2
*iface
, const GUID
*session_guid
, DWORD flags
,
2897 IAudioSessionControl
**out
)
2899 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2900 AudioSession
*session
;
2901 AudioSessionWrapper
*wrapper
;
2904 TRACE("(%p)->(%s, %x, %p)\n", This
, debugstr_guid(session_guid
),
2907 hr
= get_audio_session(session_guid
, This
->device
, 0, &session
);
2911 wrapper
= AudioSessionWrapper_Create(NULL
);
2913 return E_OUTOFMEMORY
;
2915 wrapper
->session
= session
;
2917 *out
= (IAudioSessionControl
*)&wrapper
->IAudioSessionControl2_iface
;
2922 static HRESULT WINAPI
AudioSessionManager_GetSimpleAudioVolume(
2923 IAudioSessionManager2
*iface
, const GUID
*session_guid
, DWORD flags
,
2924 ISimpleAudioVolume
**out
)
2926 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2927 AudioSession
*session
;
2928 AudioSessionWrapper
*wrapper
;
2931 TRACE("(%p)->(%s, %x, %p)\n", This
, debugstr_guid(session_guid
),
2934 hr
= get_audio_session(session_guid
, This
->device
, 0, &session
);
2938 wrapper
= AudioSessionWrapper_Create(NULL
);
2940 return E_OUTOFMEMORY
;
2942 wrapper
->session
= session
;
2944 *out
= &wrapper
->ISimpleAudioVolume_iface
;
2949 static HRESULT WINAPI
AudioSessionManager_GetSessionEnumerator(
2950 IAudioSessionManager2
*iface
, IAudioSessionEnumerator
**out
)
2952 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2953 FIXME("(%p)->(%p) - stub\n", This
, out
);
2957 static HRESULT WINAPI
AudioSessionManager_RegisterSessionNotification(
2958 IAudioSessionManager2
*iface
, IAudioSessionNotification
*notification
)
2960 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2961 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2965 static HRESULT WINAPI
AudioSessionManager_UnregisterSessionNotification(
2966 IAudioSessionManager2
*iface
, IAudioSessionNotification
*notification
)
2968 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2969 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2973 static HRESULT WINAPI
AudioSessionManager_RegisterDuckNotification(
2974 IAudioSessionManager2
*iface
, const WCHAR
*session_id
,
2975 IAudioVolumeDuckNotification
*notification
)
2977 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2978 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2982 static HRESULT WINAPI
AudioSessionManager_UnregisterDuckNotification(
2983 IAudioSessionManager2
*iface
,
2984 IAudioVolumeDuckNotification
*notification
)
2986 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
2987 FIXME("(%p)->(%p) - stub\n", This
, notification
);
2991 static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl
=
2993 AudioSessionManager_QueryInterface
,
2994 AudioSessionManager_AddRef
,
2995 AudioSessionManager_Release
,
2996 AudioSessionManager_GetAudioSessionControl
,
2997 AudioSessionManager_GetSimpleAudioVolume
,
2998 AudioSessionManager_GetSessionEnumerator
,
2999 AudioSessionManager_RegisterSessionNotification
,
3000 AudioSessionManager_UnregisterSessionNotification
,
3001 AudioSessionManager_RegisterDuckNotification
,
3002 AudioSessionManager_UnregisterDuckNotification
3005 HRESULT WINAPI
AUDDRV_GetAudioSessionManager(IMMDevice
*device
,
3006 IAudioSessionManager2
**out
)
3010 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SessionMgr
));
3012 return E_OUTOFMEMORY
;
3014 This
->IAudioSessionManager2_iface
.lpVtbl
= &AudioSessionManager2_Vtbl
;
3015 This
->device
= device
;
3018 *out
= &This
->IAudioSessionManager2_iface
;