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
28 #include <sys/types.h>
30 #include <sys/ioctl.h>
34 #include <sys/soundcard.h>
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
42 #include "wine/list.h"
45 #include "mmdeviceapi.h"
51 #include "endpointvolume.h"
52 #include "audiopolicy.h"
53 #include "audioclient.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(oss
);
57 #define NULL_PTR_ERR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, RPC_X_NULL_REF_POINTER)
59 static const REFERENCE_TIME DefaultPeriod
= 100000;
60 static const REFERENCE_TIME MinimumPeriod
= 50000;
63 typedef struct ACImpl ACImpl
;
65 typedef struct _AudioSession
{
76 CRITICAL_SECTION lock
;
81 typedef struct _AudioSessionWrapper
{
82 IAudioSessionControl2 IAudioSessionControl2_iface
;
83 IChannelAudioVolume IChannelAudioVolume_iface
;
84 ISimpleAudioVolume ISimpleAudioVolume_iface
;
89 AudioSession
*session
;
90 } AudioSessionWrapper
;
93 IAudioClient IAudioClient_iface
;
94 IAudioRenderClient IAudioRenderClient_iface
;
95 IAudioCaptureClient IAudioCaptureClient_iface
;
96 IAudioClock IAudioClock_iface
;
97 IAudioClock2 IAudioClock2_iface
;
98 IAudioStreamVolume IAudioStreamVolume_iface
;
103 IUnknown
*pUnkFTMarshal
;
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
, in_oss_frames
;
120 UINT32 oss_bufsize_bytes
, lcl_offs_frames
; /* offs into local_buffer where valid data starts */
122 BYTE
*local_buffer
, *tmp_buffer
;
123 LONG32 getbuf_last
; /* <0 when using tmp_buffer */
126 CRITICAL_SECTION lock
;
128 AudioSession
*session
;
129 AudioSessionWrapper
*session_wrapper
;
134 typedef struct _SessionMgr
{
135 IAudioSessionManager2 IAudioSessionManager2_iface
;
142 typedef struct _OSSDevice
{
144 char devnode
[OSS_DEVNODE_SIZE
];
150 static struct list g_devices
= LIST_INIT(g_devices
);
152 static const WCHAR drv_key_devicesW
[] = {'S','o','f','t','w','a','r','e','\\',
153 'W','i','n','e','\\','D','r','i','v','e','r','s','\\',
154 'w','i','n','e','o','s','s','.','d','r','v','\\','d','e','v','i','c','e','s',0};
155 static const WCHAR guidW
[] = {'g','u','i','d',0};
157 static HANDLE g_timer_q
;
159 static CRITICAL_SECTION g_sessions_lock
;
160 static CRITICAL_SECTION_DEBUG g_sessions_lock_debug
=
162 0, 0, &g_sessions_lock
,
163 { &g_sessions_lock_debug
.ProcessLocksList
, &g_sessions_lock_debug
.ProcessLocksList
},
164 0, 0, { (DWORD_PTR
)(__FILE__
": g_sessions_lock") }
166 static CRITICAL_SECTION g_sessions_lock
= { &g_sessions_lock_debug
, -1, 0, 0, 0, 0 };
167 static struct list g_sessions
= LIST_INIT(g_sessions
);
169 static AudioSessionWrapper
*AudioSessionWrapper_Create(ACImpl
*client
);
171 static const IAudioClientVtbl AudioClient_Vtbl
;
172 static const IAudioRenderClientVtbl AudioRenderClient_Vtbl
;
173 static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl
;
174 static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl
;
175 static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl
;
176 static const IAudioClockVtbl AudioClock_Vtbl
;
177 static const IAudioClock2Vtbl AudioClock2_Vtbl
;
178 static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl
;
179 static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl
;
180 static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl
;
182 static inline ACImpl
*impl_from_IAudioClient(IAudioClient
*iface
)
184 return CONTAINING_RECORD(iface
, ACImpl
, IAudioClient_iface
);
187 static inline ACImpl
*impl_from_IAudioRenderClient(IAudioRenderClient
*iface
)
189 return CONTAINING_RECORD(iface
, ACImpl
, IAudioRenderClient_iface
);
192 static inline ACImpl
*impl_from_IAudioCaptureClient(IAudioCaptureClient
*iface
)
194 return CONTAINING_RECORD(iface
, ACImpl
, IAudioCaptureClient_iface
);
197 static inline AudioSessionWrapper
*impl_from_IAudioSessionControl2(IAudioSessionControl2
*iface
)
199 return CONTAINING_RECORD(iface
, AudioSessionWrapper
, IAudioSessionControl2_iface
);
202 static inline AudioSessionWrapper
*impl_from_ISimpleAudioVolume(ISimpleAudioVolume
*iface
)
204 return CONTAINING_RECORD(iface
, AudioSessionWrapper
, ISimpleAudioVolume_iface
);
207 static inline AudioSessionWrapper
*impl_from_IChannelAudioVolume(IChannelAudioVolume
*iface
)
209 return CONTAINING_RECORD(iface
, AudioSessionWrapper
, IChannelAudioVolume_iface
);
212 static inline ACImpl
*impl_from_IAudioClock(IAudioClock
*iface
)
214 return CONTAINING_RECORD(iface
, ACImpl
, IAudioClock_iface
);
217 static inline ACImpl
*impl_from_IAudioClock2(IAudioClock2
*iface
)
219 return CONTAINING_RECORD(iface
, ACImpl
, IAudioClock2_iface
);
222 static inline ACImpl
*impl_from_IAudioStreamVolume(IAudioStreamVolume
*iface
)
224 return CONTAINING_RECORD(iface
, ACImpl
, IAudioStreamVolume_iface
);
227 static inline SessionMgr
*impl_from_IAudioSessionManager2(IAudioSessionManager2
*iface
)
229 return CONTAINING_RECORD(iface
, SessionMgr
, IAudioSessionManager2_iface
);
232 BOOL WINAPI
DllMain(HINSTANCE dll
, DWORD reason
, void *reserved
)
236 case DLL_PROCESS_ATTACH
:
237 g_timer_q
= CreateTimerQueue();
242 case DLL_PROCESS_DETACH
:
245 OSSDevice
*iter
, *iter2
;
247 DeleteCriticalSection(&g_sessions_lock
);
249 LIST_FOR_EACH_ENTRY_SAFE(iter
, iter2
, &g_devices
, OSSDevice
, entry
){
250 HeapFree(GetProcessHeap(), 0, iter
);
258 /* From <dlls/mmdevapi/mmdevapi.h> */
259 enum DriverPriority
{
260 Priority_Unavailable
= 0,
266 int WINAPI
AUDDRV_GetPriority(void)
271 /* Attempt to determine if we are running on OSS or ALSA's OSS
272 * compatibility layer. There is no official way to do that, so just check
273 * for validity as best as possible, without rejecting valid OSS
274 * implementations. */
276 mixer_fd
= open("/dev/mixer", O_RDONLY
, 0);
278 TRACE("Priority_Unavailable: open failed\n");
279 return Priority_Unavailable
;
282 sysinfo
.version
[0] = 0xFF;
283 sysinfo
.versionnum
= ~0;
284 if(ioctl(mixer_fd
, SNDCTL_SYSINFO
, &sysinfo
) < 0){
285 TRACE("Priority_Unavailable: ioctl failed\n");
287 return Priority_Unavailable
;
292 if(sysinfo
.version
[0] < '4' || sysinfo
.version
[0] > '9'){
293 TRACE("Priority_Low: sysinfo.version[0]: %x\n", sysinfo
.version
[0]);
296 if(sysinfo
.versionnum
& 0x80000000){
297 TRACE("Priority_Low: sysinfo.versionnum: %x\n", sysinfo
.versionnum
);
301 TRACE("Priority_Preferred: Seems like valid OSS!\n");
303 return Priority_Preferred
;
306 static void set_device_guid(EDataFlow flow
, HKEY drv_key
, const WCHAR
*key_name
,
314 lr
= RegCreateKeyExW(HKEY_CURRENT_USER
, drv_key_devicesW
, 0, NULL
, 0, KEY_WRITE
,
315 NULL
, &drv_key
, NULL
);
316 if(lr
!= ERROR_SUCCESS
){
317 ERR("RegCreateKeyEx(drv_key) failed: %u\n", lr
);
323 lr
= RegCreateKeyExW(drv_key
, key_name
, 0, NULL
, 0, KEY_WRITE
,
325 if(lr
!= ERROR_SUCCESS
){
326 ERR("RegCreateKeyEx(%s) failed: %u\n", wine_dbgstr_w(key_name
), lr
);
330 lr
= RegSetValueExW(key
, guidW
, 0, REG_BINARY
, (BYTE
*)guid
,
332 if(lr
!= ERROR_SUCCESS
)
333 ERR("RegSetValueEx(%s\\guid) failed: %u\n", wine_dbgstr_w(key_name
), lr
);
338 RegCloseKey(drv_key
);
341 static void get_device_guid(EDataFlow flow
, const char *device
, GUID
*guid
)
343 HKEY key
= NULL
, dev_key
;
344 DWORD type
, size
= sizeof(*guid
);
352 MultiByteToWideChar(CP_UNIXCP
, 0, device
, -1, key_name
+ 2,
353 (sizeof(key_name
) / sizeof(*key_name
)) - 2);
355 if(RegOpenKeyExW(HKEY_CURRENT_USER
, drv_key_devicesW
, 0, KEY_WRITE
|KEY_READ
, &key
) == ERROR_SUCCESS
){
356 if(RegOpenKeyExW(key
, key_name
, 0, KEY_READ
, &dev_key
) == ERROR_SUCCESS
){
357 if(RegQueryValueExW(dev_key
, guidW
, 0, &type
,
358 (BYTE
*)guid
, &size
) == ERROR_SUCCESS
){
359 if(type
== REG_BINARY
){
360 RegCloseKey(dev_key
);
364 ERR("Invalid type for device %s GUID: %u; ignoring and overwriting\n",
365 wine_dbgstr_w(key_name
), type
);
367 RegCloseKey(dev_key
);
373 set_device_guid(flow
, key
, key_name
, guid
);
379 static const char *oss_clean_devnode(const char *devnode
)
381 static char ret
[OSS_DEVNODE_SIZE
];
383 const char *dot
, *slash
;
386 dot
= strrchr(devnode
, '.');
390 slash
= strrchr(devnode
, '/');
391 if(slash
&& dot
< slash
)
396 memcpy(ret
, devnode
, len
);
402 static UINT
get_default_index(EDataFlow flow
)
411 fd
= open("/dev/dsp", O_WRONLY
| O_NONBLOCK
);
413 fd
= open("/dev/dsp", O_RDONLY
| O_NONBLOCK
);
416 WARN("Couldn't open default device!\n");
421 if((err
= ioctl(fd
, SNDCTL_ENGINEINFO
, &ai
)) < 0){
422 WARN("SNDCTL_ENGINEINFO failed: %d (%s)\n", err
, strerror(errno
));
429 TRACE("Default devnode: %s\n", ai
.devnode
);
430 devnode
= oss_clean_devnode(ai
.devnode
);
432 LIST_FOR_EACH_ENTRY(dev_item
, &g_devices
, OSSDevice
, entry
){
433 if(dev_item
->flow
== flow
){
434 if(!strcmp(devnode
, dev_item
->devnode
))
440 WARN("Couldn't find default device! Choosing first.\n");
444 HRESULT WINAPI
AUDDRV_GetEndpointIDs(EDataFlow flow
, WCHAR
***ids
, GUID
**guids
,
445 UINT
*num
, UINT
*def_index
)
449 static int print_once
= 0;
451 static const WCHAR outW
[] = {'O','u','t',':',' ',0};
452 static const WCHAR inW
[] = {'I','n',':',' ',0};
454 TRACE("%d %p %p %p %p\n", flow
, ids
, guids
, num
, def_index
);
456 mixer_fd
= open("/dev/mixer", O_RDONLY
, 0);
458 ERR("OSS /dev/mixer doesn't seem to exist\n");
459 return AUDCLNT_E_SERVICE_NOT_RUNNING
;
462 if(ioctl(mixer_fd
, SNDCTL_SYSINFO
, &sysinfo
) < 0){
466 ERR("OSS version too old, need at least OSSv4\n");
467 return AUDCLNT_E_SERVICE_NOT_RUNNING
;
470 ERR("Error getting SNDCTL_SYSINFO: %d (%s)\n", errno
, strerror(errno
));
475 TRACE("OSS sysinfo:\n");
476 TRACE("product: %s\n", sysinfo
.product
);
477 TRACE("version: %s\n", sysinfo
.version
);
478 TRACE("versionnum: %x\n", sysinfo
.versionnum
);
479 TRACE("numaudios: %d\n", sysinfo
.numaudios
);
480 TRACE("nummixers: %d\n", sysinfo
.nummixers
);
481 TRACE("numcards: %d\n", sysinfo
.numcards
);
482 TRACE("numaudioengines: %d\n", sysinfo
.numaudioengines
);
486 if(sysinfo
.numaudios
<= 0){
487 WARN("No audio devices!\n");
489 return AUDCLNT_E_SERVICE_NOT_RUNNING
;
492 *ids
= HeapAlloc(GetProcessHeap(), 0, sysinfo
.numaudios
* sizeof(WCHAR
*));
493 *guids
= HeapAlloc(GetProcessHeap(), 0, sysinfo
.numaudios
* sizeof(GUID
));
496 for(i
= 0; i
< sysinfo
.numaudios
; ++i
){
497 oss_audioinfo ai
= {0};
503 if(ioctl(mixer_fd
, SNDCTL_AUDIOINFO
, &ai
) < 0){
504 WARN("Error getting AUDIOINFO for dev %d: %d (%s)\n", i
, errno
,
509 devnode
= oss_clean_devnode(ai
.devnode
);
511 /* check for duplicates */
512 LIST_FOR_EACH_ENTRY(dev_item
, &g_devices
, OSSDevice
, entry
){
513 if(dev_item
->flow
== flow
&& !strcmp(devnode
, dev_item
->devnode
))
516 if(&dev_item
->entry
!= &g_devices
)
520 fd
= open(devnode
, O_WRONLY
| O_NONBLOCK
, 0);
522 fd
= open(devnode
, O_RDONLY
| O_NONBLOCK
, 0);
524 WARN("Opening device \"%s\" failed, pretending it doesn't exist: %d (%s)\n",
525 devnode
, errno
, strerror(errno
));
530 if((flow
== eCapture
&& (ai
.caps
& PCM_CAP_INPUT
)) ||
531 (flow
== eRender
&& (ai
.caps
& PCM_CAP_OUTPUT
))){
532 size_t len
, prefix_len
;
535 dev_item
= HeapAlloc(GetProcessHeap(), 0, sizeof(*dev_item
));
537 dev_item
->flow
= flow
;
538 get_device_guid(flow
, devnode
, &dev_item
->guid
);
539 strcpy(dev_item
->devnode
, devnode
);
541 (*guids
)[*num
] = dev_item
->guid
;
543 len
= MultiByteToWideChar(CP_UNIXCP
, 0, ai
.name
, -1, NULL
, 0);
546 prefix_len
= (sizeof(outW
) / sizeof(*outW
)) - 1;
550 prefix_len
= (sizeof(inW
) / sizeof(*inW
)) - 1;
553 (*ids
)[*num
] = HeapAlloc(GetProcessHeap(), 0,
554 len
* sizeof(WCHAR
));
556 for(i
= 0; i
< *num
; ++i
)
557 HeapFree(GetProcessHeap(), 0, (*ids
)[i
]);
558 HeapFree(GetProcessHeap(), 0, *ids
);
559 HeapFree(GetProcessHeap(), 0, *guids
);
560 HeapFree(GetProcessHeap(), 0, dev_item
);
562 return E_OUTOFMEMORY
;
564 memcpy((*ids
)[*num
], prefix
, prefix_len
* sizeof(WCHAR
));
565 MultiByteToWideChar(CP_UNIXCP
, 0, ai
.name
, -1,
566 (*ids
)[*num
] + prefix_len
, len
- prefix_len
);
568 list_add_tail(&g_devices
, &dev_item
->entry
);
576 *def_index
= get_default_index(flow
);
581 static const OSSDevice
*get_ossdevice_from_guid(const GUID
*guid
)
584 LIST_FOR_EACH_ENTRY(dev_item
, &g_devices
, OSSDevice
, entry
)
585 if(IsEqualGUID(guid
, &dev_item
->guid
))
590 HRESULT WINAPI
AUDDRV_GetAudioEndpoint(GUID
*guid
, IMMDevice
*dev
,
594 const OSSDevice
*oss_dev
;
597 TRACE("%s %p %p\n", debugstr_guid(guid
), dev
, out
);
599 oss_dev
= get_ossdevice_from_guid(guid
);
601 WARN("Unknown GUID: %s\n", debugstr_guid(guid
));
602 return AUDCLNT_E_DEVICE_INVALIDATED
;
605 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(ACImpl
));
607 return E_OUTOFMEMORY
;
609 hr
= CoCreateFreeThreadedMarshaler((IUnknown
*)&This
->IAudioClient_iface
,
610 (IUnknown
**)&This
->pUnkFTMarshal
);
612 HeapFree(GetProcessHeap(), 0, This
);
616 if(oss_dev
->flow
== eRender
)
617 This
->fd
= open(oss_dev
->devnode
, O_WRONLY
| O_NONBLOCK
, 0);
618 else if(oss_dev
->flow
== eCapture
)
619 This
->fd
= open(oss_dev
->devnode
, O_RDONLY
| O_NONBLOCK
, 0);
621 HeapFree(GetProcessHeap(), 0, This
);
625 WARN("Unable to open device %s: %d (%s)\n", oss_dev
->devnode
, errno
,
627 HeapFree(GetProcessHeap(), 0, This
);
628 return AUDCLNT_E_DEVICE_INVALIDATED
;
631 This
->dataflow
= oss_dev
->flow
;
634 if(ioctl(This
->fd
, SNDCTL_ENGINEINFO
, &This
->ai
) < 0){
635 WARN("Unable to get audio info for device %s: %d (%s)\n", oss_dev
->devnode
,
636 errno
, strerror(errno
));
638 HeapFree(GetProcessHeap(), 0, This
);
642 strcpy(This
->devnode
, oss_dev
->devnode
);
644 TRACE("OSS audioinfo:\n");
645 TRACE("devnode: %s\n", This
->ai
.devnode
);
646 TRACE("name: %s\n", This
->ai
.name
);
647 TRACE("busy: %x\n", This
->ai
.busy
);
648 TRACE("caps: %x\n", This
->ai
.caps
);
649 TRACE("iformats: %x\n", This
->ai
.iformats
);
650 TRACE("oformats: %x\n", This
->ai
.oformats
);
651 TRACE("enabled: %d\n", This
->ai
.enabled
);
652 TRACE("min_rate: %d\n", This
->ai
.min_rate
);
653 TRACE("max_rate: %d\n", This
->ai
.max_rate
);
654 TRACE("min_channels: %d\n", This
->ai
.min_channels
);
655 TRACE("max_channels: %d\n", This
->ai
.max_channels
);
657 This
->IAudioClient_iface
.lpVtbl
= &AudioClient_Vtbl
;
658 This
->IAudioRenderClient_iface
.lpVtbl
= &AudioRenderClient_Vtbl
;
659 This
->IAudioCaptureClient_iface
.lpVtbl
= &AudioCaptureClient_Vtbl
;
660 This
->IAudioClock_iface
.lpVtbl
= &AudioClock_Vtbl
;
661 This
->IAudioClock2_iface
.lpVtbl
= &AudioClock2_Vtbl
;
662 This
->IAudioStreamVolume_iface
.lpVtbl
= &AudioStreamVolume_Vtbl
;
664 InitializeCriticalSection(&This
->lock
);
665 This
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": ACImpl.lock");
668 IMMDevice_AddRef(This
->parent
);
670 IAudioClient_AddRef(&This
->IAudioClient_iface
);
672 *out
= &This
->IAudioClient_iface
;
677 static HRESULT WINAPI
AudioClient_QueryInterface(IAudioClient
*iface
,
678 REFIID riid
, void **ppv
)
680 ACImpl
*This
= impl_from_IAudioClient(iface
);
681 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
686 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IAudioClient
))
688 else if(IsEqualIID(riid
, &IID_IMarshal
))
689 return IUnknown_QueryInterface(This
->pUnkFTMarshal
, riid
, ppv
);
691 IUnknown_AddRef((IUnknown
*)*ppv
);
694 WARN("Unknown interface %s\n", debugstr_guid(riid
));
695 return E_NOINTERFACE
;
698 static ULONG WINAPI
AudioClient_AddRef(IAudioClient
*iface
)
700 ACImpl
*This
= impl_from_IAudioClient(iface
);
702 ref
= InterlockedIncrement(&This
->ref
);
703 TRACE("(%p) Refcount now %u\n", This
, ref
);
707 static ULONG WINAPI
AudioClient_Release(IAudioClient
*iface
)
709 ACImpl
*This
= impl_from_IAudioClient(iface
);
712 ref
= InterlockedDecrement(&This
->ref
);
713 TRACE("(%p) Refcount now %u\n", This
, ref
);
718 event
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
719 wait
= !DeleteTimerQueueTimer(g_timer_q
, This
->timer
, event
);
720 wait
= wait
&& GetLastError() == ERROR_IO_PENDING
;
722 WaitForSingleObject(event
, INFINITE
);
726 IAudioClient_Stop(iface
);
727 IMMDevice_Release(This
->parent
);
728 IUnknown_Release(This
->pUnkFTMarshal
);
729 This
->lock
.DebugInfo
->Spare
[0] = 0;
730 DeleteCriticalSection(&This
->lock
);
733 EnterCriticalSection(&g_sessions_lock
);
734 list_remove(&This
->entry
);
735 LeaveCriticalSection(&g_sessions_lock
);
737 HeapFree(GetProcessHeap(), 0, This
->vols
);
738 HeapFree(GetProcessHeap(), 0, This
->local_buffer
);
739 HeapFree(GetProcessHeap(), 0, This
->tmp_buffer
);
740 CoTaskMemFree(This
->fmt
);
741 HeapFree(GetProcessHeap(), 0, This
);
746 static void dump_fmt(const WAVEFORMATEX
*fmt
)
748 TRACE("wFormatTag: 0x%x (", fmt
->wFormatTag
);
749 switch(fmt
->wFormatTag
){
750 case WAVE_FORMAT_PCM
:
751 TRACE("WAVE_FORMAT_PCM");
753 case WAVE_FORMAT_IEEE_FLOAT
:
754 TRACE("WAVE_FORMAT_IEEE_FLOAT");
756 case WAVE_FORMAT_EXTENSIBLE
:
757 TRACE("WAVE_FORMAT_EXTENSIBLE");
765 TRACE("nChannels: %u\n", fmt
->nChannels
);
766 TRACE("nSamplesPerSec: %u\n", fmt
->nSamplesPerSec
);
767 TRACE("nAvgBytesPerSec: %u\n", fmt
->nAvgBytesPerSec
);
768 TRACE("nBlockAlign: %u\n", fmt
->nBlockAlign
);
769 TRACE("wBitsPerSample: %u\n", fmt
->wBitsPerSample
);
770 TRACE("cbSize: %u\n", fmt
->cbSize
);
772 if(fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
){
773 WAVEFORMATEXTENSIBLE
*fmtex
= (void*)fmt
;
774 TRACE("dwChannelMask: %08x\n", fmtex
->dwChannelMask
);
775 TRACE("Samples: %04x\n", fmtex
->Samples
.wReserved
);
776 TRACE("SubFormat: %s\n", wine_dbgstr_guid(&fmtex
->SubFormat
));
780 static DWORD
get_channel_mask(unsigned int channels
)
786 return KSAUDIO_SPEAKER_MONO
;
788 return KSAUDIO_SPEAKER_STEREO
;
790 return KSAUDIO_SPEAKER_STEREO
| SPEAKER_LOW_FREQUENCY
;
792 return KSAUDIO_SPEAKER_QUAD
; /* not _SURROUND */
794 return KSAUDIO_SPEAKER_QUAD
| SPEAKER_LOW_FREQUENCY
;
796 return KSAUDIO_SPEAKER_5POINT1
; /* not 5POINT1_SURROUND */
798 return KSAUDIO_SPEAKER_5POINT1
| SPEAKER_BACK_CENTER
;
800 return KSAUDIO_SPEAKER_7POINT1_SURROUND
; /* Vista deprecates 7POINT1 */
802 FIXME("Unknown speaker configuration: %u\n", channels
);
806 static int get_oss_format(const WAVEFORMATEX
*fmt
)
808 WAVEFORMATEXTENSIBLE
*fmtex
= (WAVEFORMATEXTENSIBLE
*)fmt
;
810 if(fmt
->wFormatTag
== WAVE_FORMAT_PCM
||
811 (fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
812 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
))){
813 switch(fmt
->wBitsPerSample
){
827 if(fmt
->wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
||
828 (fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
829 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
))){
830 if(fmt
->wBitsPerSample
!= 32)
840 static WAVEFORMATEX
*clone_format(const WAVEFORMATEX
*fmt
)
845 if(fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
846 size
= sizeof(WAVEFORMATEXTENSIBLE
);
848 size
= sizeof(WAVEFORMATEX
);
850 ret
= CoTaskMemAlloc(size
);
854 memcpy(ret
, fmt
, size
);
856 ret
->cbSize
= size
- sizeof(WAVEFORMATEX
);
861 static HRESULT
setup_oss_device(AUDCLNT_SHAREMODE mode
, int fd
,
862 const WAVEFORMATEX
*fmt
, WAVEFORMATEX
**out
)
867 WAVEFORMATEX
*closest
= NULL
;
869 tmp
= oss_format
= get_oss_format(fmt
);
871 return AUDCLNT_E_UNSUPPORTED_FORMAT
;
872 if(ioctl(fd
, SNDCTL_DSP_SETFMT
, &tmp
) < 0){
873 WARN("SETFMT failed: %d (%s)\n", errno
, strerror(errno
));
876 if(tmp
!= oss_format
){
877 TRACE("Format unsupported by this OSS version: %x\n", oss_format
);
878 return AUDCLNT_E_UNSUPPORTED_FORMAT
;
881 if(fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
882 (fmt
->nAvgBytesPerSec
== 0 ||
883 fmt
->nBlockAlign
== 0 ||
884 ((WAVEFORMATEXTENSIBLE
*)fmt
)->Samples
.wValidBitsPerSample
> fmt
->wBitsPerSample
))
887 if(fmt
->nChannels
== 0)
888 return AUDCLNT_E_UNSUPPORTED_FORMAT
;
890 closest
= clone_format(fmt
);
892 return E_OUTOFMEMORY
;
894 tmp
= fmt
->nSamplesPerSec
;
895 if(ioctl(fd
, SNDCTL_DSP_SPEED
, &tmp
) < 0){
896 WARN("SPEED failed: %d (%s)\n", errno
, strerror(errno
));
897 CoTaskMemFree(closest
);
900 tenth
= fmt
->nSamplesPerSec
* 0.1;
901 if(tmp
> fmt
->nSamplesPerSec
+ tenth
|| tmp
< fmt
->nSamplesPerSec
- tenth
){
903 closest
->nSamplesPerSec
= tmp
;
906 tmp
= fmt
->nChannels
;
907 if(ioctl(fd
, SNDCTL_DSP_CHANNELS
, &tmp
) < 0){
908 WARN("CHANNELS failed: %d (%s)\n", errno
, strerror(errno
));
909 CoTaskMemFree(closest
);
912 if(tmp
!= fmt
->nChannels
){
914 closest
->nChannels
= tmp
;
917 if(closest
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
918 ((WAVEFORMATEXTENSIBLE
*)closest
)->dwChannelMask
= get_channel_mask(closest
->nChannels
);
920 if(fmt
->nBlockAlign
!= fmt
->nChannels
* fmt
->wBitsPerSample
/ 8 ||
921 fmt
->nAvgBytesPerSec
!= fmt
->nBlockAlign
* fmt
->nSamplesPerSec
||
922 (fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
923 ((WAVEFORMATEXTENSIBLE
*)fmt
)->Samples
.wValidBitsPerSample
< fmt
->wBitsPerSample
))
926 if(mode
== AUDCLNT_SHAREMODE_EXCLUSIVE
&&
927 fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
){
928 if(((WAVEFORMATEXTENSIBLE
*)fmt
)->dwChannelMask
== 0 ||
929 ((WAVEFORMATEXTENSIBLE
*)fmt
)->dwChannelMask
& SPEAKER_RESERVED
)
933 if(ret
== S_FALSE
&& !out
)
934 ret
= AUDCLNT_E_UNSUPPORTED_FORMAT
;
936 if(ret
== S_FALSE
&& out
){
937 closest
->nBlockAlign
=
938 closest
->nChannels
* closest
->wBitsPerSample
/ 8;
939 closest
->nAvgBytesPerSec
=
940 closest
->nBlockAlign
* closest
->nSamplesPerSec
;
941 if(closest
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
942 ((WAVEFORMATEXTENSIBLE
*)closest
)->Samples
.wValidBitsPerSample
= closest
->wBitsPerSample
;
945 CoTaskMemFree(closest
);
947 TRACE("returning: %08x\n", ret
);
951 static void session_init_vols(AudioSession
*session
, UINT channels
)
953 if(session
->channel_count
< channels
){
956 if(session
->channel_vols
)
957 session
->channel_vols
= HeapReAlloc(GetProcessHeap(), 0,
958 session
->channel_vols
, sizeof(float) * channels
);
960 session
->channel_vols
= HeapAlloc(GetProcessHeap(), 0,
961 sizeof(float) * channels
);
962 if(!session
->channel_vols
)
965 for(i
= session
->channel_count
; i
< channels
; ++i
)
966 session
->channel_vols
[i
] = 1.f
;
968 session
->channel_count
= channels
;
972 static AudioSession
*create_session(const GUID
*guid
, IMMDevice
*device
,
977 ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(AudioSession
));
981 memcpy(&ret
->guid
, guid
, sizeof(GUID
));
983 ret
->device
= device
;
985 list_init(&ret
->clients
);
987 list_add_head(&g_sessions
, &ret
->entry
);
989 InitializeCriticalSection(&ret
->lock
);
990 ret
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": AudioSession.lock");
992 session_init_vols(ret
, num_channels
);
994 ret
->master_vol
= 1.f
;
999 /* if channels == 0, then this will return or create a session with
1000 * matching dataflow and GUID. otherwise, channels must also match */
1001 static HRESULT
get_audio_session(const GUID
*sessionguid
,
1002 IMMDevice
*device
, UINT channels
, AudioSession
**out
)
1004 AudioSession
*session
;
1006 if(!sessionguid
|| IsEqualGUID(sessionguid
, &GUID_NULL
)){
1007 *out
= create_session(&GUID_NULL
, device
, channels
);
1009 return E_OUTOFMEMORY
;
1015 LIST_FOR_EACH_ENTRY(session
, &g_sessions
, AudioSession
, entry
){
1016 if(session
->device
== device
&&
1017 IsEqualGUID(sessionguid
, &session
->guid
)){
1018 session_init_vols(session
, channels
);
1025 *out
= create_session(sessionguid
, device
, channels
);
1027 return E_OUTOFMEMORY
;
1033 static HRESULT WINAPI
AudioClient_Initialize(IAudioClient
*iface
,
1034 AUDCLNT_SHAREMODE mode
, DWORD flags
, REFERENCE_TIME duration
,
1035 REFERENCE_TIME period
, const WAVEFORMATEX
*fmt
,
1036 const GUID
*sessionguid
)
1038 ACImpl
*This
= impl_from_IAudioClient(iface
);
1042 TRACE("(%p)->(%x, %x, %s, %s, %p, %s)\n", This
, mode
, flags
,
1043 wine_dbgstr_longlong(duration
), wine_dbgstr_longlong(period
), fmt
, debugstr_guid(sessionguid
));
1050 if(mode
!= AUDCLNT_SHAREMODE_SHARED
&& mode
!= AUDCLNT_SHAREMODE_EXCLUSIVE
)
1051 return AUDCLNT_E_NOT_INITIALIZED
;
1053 if(flags
& ~(AUDCLNT_STREAMFLAGS_CROSSPROCESS
|
1054 AUDCLNT_STREAMFLAGS_LOOPBACK
|
1055 AUDCLNT_STREAMFLAGS_EVENTCALLBACK
|
1056 AUDCLNT_STREAMFLAGS_NOPERSIST
|
1057 AUDCLNT_STREAMFLAGS_RATEADJUST
|
1058 AUDCLNT_SESSIONFLAGS_EXPIREWHENUNOWNED
|
1059 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDE
|
1060 AUDCLNT_SESSIONFLAGS_DISPLAY_HIDEWHENEXPIRED
)){
1061 TRACE("Unknown flags: %08x\n", flags
);
1062 return E_INVALIDARG
;
1065 if(mode
== AUDCLNT_SHAREMODE_SHARED
){
1066 period
= DefaultPeriod
;
1067 if( duration
< 3 * period
)
1068 duration
= 3 * period
;
1071 period
= DefaultPeriod
; /* not minimum */
1072 if(period
< MinimumPeriod
|| period
> 5000000)
1073 return AUDCLNT_E_INVALID_DEVICE_PERIOD
;
1074 if(duration
> 20000000) /* the smaller the period, the lower this limit */
1075 return AUDCLNT_E_BUFFER_SIZE_ERROR
;
1076 if(flags
& AUDCLNT_STREAMFLAGS_EVENTCALLBACK
){
1077 if(duration
!= period
)
1078 return AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL
;
1079 FIXME("EXCLUSIVE mode with EVENTCALLBACK\n");
1080 return AUDCLNT_E_DEVICE_IN_USE
;
1082 if( duration
< 8 * period
)
1083 duration
= 8 * period
; /* may grow above 2s */
1087 EnterCriticalSection(&This
->lock
);
1090 LeaveCriticalSection(&This
->lock
);
1091 return AUDCLNT_E_ALREADY_INITIALIZED
;
1094 hr
= setup_oss_device(mode
, This
->fd
, fmt
, NULL
);
1096 LeaveCriticalSection(&This
->lock
);
1100 This
->fmt
= clone_format(fmt
);
1102 LeaveCriticalSection(&This
->lock
);
1103 return E_OUTOFMEMORY
;
1106 This
->period_us
= period
/ 10;
1107 This
->period_frames
= MulDiv(fmt
->nSamplesPerSec
, period
, 10000000);
1109 This
->bufsize_frames
= MulDiv(duration
, fmt
->nSamplesPerSec
, 10000000);
1110 if(mode
== AUDCLNT_SHAREMODE_EXCLUSIVE
)
1111 This
->bufsize_frames
-= This
->bufsize_frames
% This
->period_frames
;
1112 This
->local_buffer
= HeapAlloc(GetProcessHeap(), 0,
1113 This
->bufsize_frames
* fmt
->nBlockAlign
);
1114 if(!This
->local_buffer
){
1115 CoTaskMemFree(This
->fmt
);
1117 LeaveCriticalSection(&This
->lock
);
1118 return E_OUTOFMEMORY
;
1121 This
->vols
= HeapAlloc(GetProcessHeap(), 0, fmt
->nChannels
* sizeof(float));
1123 CoTaskMemFree(This
->fmt
);
1125 LeaveCriticalSection(&This
->lock
);
1126 return E_OUTOFMEMORY
;
1129 for(i
= 0; i
< fmt
->nChannels
; ++i
)
1130 This
->vols
[i
] = 1.f
;
1133 This
->flags
= flags
;
1134 This
->oss_bufsize_bytes
= 0;
1136 EnterCriticalSection(&g_sessions_lock
);
1138 hr
= get_audio_session(sessionguid
, This
->parent
, fmt
->nChannels
,
1141 LeaveCriticalSection(&g_sessions_lock
);
1142 HeapFree(GetProcessHeap(), 0, This
->vols
);
1144 CoTaskMemFree(This
->fmt
);
1146 LeaveCriticalSection(&This
->lock
);
1150 list_add_tail(&This
->session
->clients
, &This
->entry
);
1152 LeaveCriticalSection(&g_sessions_lock
);
1154 This
->initted
= TRUE
;
1156 LeaveCriticalSection(&This
->lock
);
1161 static HRESULT WINAPI
AudioClient_GetBufferSize(IAudioClient
*iface
,
1164 ACImpl
*This
= impl_from_IAudioClient(iface
);
1166 TRACE("(%p)->(%p)\n", This
, frames
);
1171 EnterCriticalSection(&This
->lock
);
1174 LeaveCriticalSection(&This
->lock
);
1175 return AUDCLNT_E_NOT_INITIALIZED
;
1178 *frames
= This
->bufsize_frames
;
1180 TRACE("buffer size: %u\n", *frames
);
1182 LeaveCriticalSection(&This
->lock
);
1187 static HRESULT WINAPI
AudioClient_GetStreamLatency(IAudioClient
*iface
,
1188 REFERENCE_TIME
*latency
)
1190 ACImpl
*This
= impl_from_IAudioClient(iface
);
1192 TRACE("(%p)->(%p)\n", This
, latency
);
1197 EnterCriticalSection(&This
->lock
);
1200 LeaveCriticalSection(&This
->lock
);
1201 return AUDCLNT_E_NOT_INITIALIZED
;
1204 /* pretend we process audio in Period chunks, so max latency includes
1205 * the period time. Some native machines add .6666ms in shared mode. */
1206 *latency
= This
->period_us
* 10 + 6666;
1208 LeaveCriticalSection(&This
->lock
);
1213 static HRESULT WINAPI
AudioClient_GetCurrentPadding(IAudioClient
*iface
,
1216 ACImpl
*This
= impl_from_IAudioClient(iface
);
1218 TRACE("(%p)->(%p)\n", This
, numpad
);
1223 EnterCriticalSection(&This
->lock
);
1226 LeaveCriticalSection(&This
->lock
);
1227 return AUDCLNT_E_NOT_INITIALIZED
;
1230 *numpad
= This
->held_frames
;
1232 TRACE("padding: %u\n", *numpad
);
1234 LeaveCriticalSection(&This
->lock
);
1239 static HRESULT WINAPI
AudioClient_IsFormatSupported(IAudioClient
*iface
,
1240 AUDCLNT_SHAREMODE mode
, const WAVEFORMATEX
*pwfx
,
1241 WAVEFORMATEX
**outpwfx
)
1243 ACImpl
*This
= impl_from_IAudioClient(iface
);
1247 TRACE("(%p)->(%x, %p, %p)\n", This
, mode
, pwfx
, outpwfx
);
1249 if(!pwfx
|| (mode
== AUDCLNT_SHAREMODE_SHARED
&& !outpwfx
))
1252 if(mode
!= AUDCLNT_SHAREMODE_SHARED
&& mode
!= AUDCLNT_SHAREMODE_EXCLUSIVE
)
1253 return E_INVALIDARG
;
1255 if(pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
1256 pwfx
->cbSize
< sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
))
1257 return E_INVALIDARG
;
1263 if(mode
!= AUDCLNT_SHAREMODE_SHARED
)
1267 if(This
->dataflow
== eRender
)
1268 fd
= open(This
->devnode
, O_WRONLY
| O_NONBLOCK
, 0);
1269 else if(This
->dataflow
== eCapture
)
1270 fd
= open(This
->devnode
, O_RDONLY
| O_NONBLOCK
, 0);
1273 WARN("Unable to open device %s: %d (%s)\n", This
->devnode
, errno
,
1275 return AUDCLNT_E_DEVICE_INVALIDATED
;
1278 ret
= setup_oss_device(mode
, fd
, pwfx
, outpwfx
);
1285 static HRESULT WINAPI
AudioClient_GetMixFormat(IAudioClient
*iface
,
1286 WAVEFORMATEX
**pwfx
)
1288 ACImpl
*This
= impl_from_IAudioClient(iface
);
1289 WAVEFORMATEXTENSIBLE
*fmt
;
1292 TRACE("(%p)->(%p)\n", This
, pwfx
);
1298 if(This
->dataflow
== eRender
)
1299 formats
= This
->ai
.oformats
;
1300 else if(This
->dataflow
== eCapture
)
1301 formats
= This
->ai
.iformats
;
1303 return E_UNEXPECTED
;
1305 fmt
= CoTaskMemAlloc(sizeof(WAVEFORMATEXTENSIBLE
));
1307 return E_OUTOFMEMORY
;
1309 fmt
->Format
.wFormatTag
= WAVE_FORMAT_EXTENSIBLE
;
1310 if(formats
& AFMT_S16_LE
){
1311 fmt
->Format
.wBitsPerSample
= 16;
1312 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1314 }else if(formats
& AFMT_FLOAT
){
1315 fmt
->Format
.wBitsPerSample
= 32;
1316 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
1318 }else if(formats
& AFMT_U8
){
1319 fmt
->Format
.wBitsPerSample
= 8;
1320 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1321 }else if(formats
& AFMT_S32_LE
){
1322 fmt
->Format
.wBitsPerSample
= 32;
1323 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1324 }else if(formats
& AFMT_S24_LE
){
1325 fmt
->Format
.wBitsPerSample
= 24;
1326 fmt
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
1328 WARN("Didn't recognize any available OSS formats: %x\n", formats
);
1333 /* some OSS drivers are buggy, so set reasonable defaults if
1334 * the reported values seem wacky */
1335 fmt
->Format
.nChannels
= max(This
->ai
.max_channels
, This
->ai
.min_channels
);
1336 if(fmt
->Format
.nChannels
== 0 || fmt
->Format
.nChannels
> 8)
1337 fmt
->Format
.nChannels
= 2;
1339 if(This
->ai
.max_rate
== 0)
1340 fmt
->Format
.nSamplesPerSec
= 44100;
1342 fmt
->Format
.nSamplesPerSec
= min(This
->ai
.max_rate
, 44100);
1343 if(fmt
->Format
.nSamplesPerSec
< This
->ai
.min_rate
)
1344 fmt
->Format
.nSamplesPerSec
= This
->ai
.min_rate
;
1346 fmt
->dwChannelMask
= get_channel_mask(fmt
->Format
.nChannels
);
1348 fmt
->Format
.nBlockAlign
= (fmt
->Format
.wBitsPerSample
*
1349 fmt
->Format
.nChannels
) / 8;
1350 fmt
->Format
.nAvgBytesPerSec
= fmt
->Format
.nSamplesPerSec
*
1351 fmt
->Format
.nBlockAlign
;
1353 fmt
->Samples
.wValidBitsPerSample
= fmt
->Format
.wBitsPerSample
;
1354 fmt
->Format
.cbSize
= sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
);
1356 *pwfx
= (WAVEFORMATEX
*)fmt
;
1362 static HRESULT WINAPI
AudioClient_GetDevicePeriod(IAudioClient
*iface
,
1363 REFERENCE_TIME
*defperiod
, REFERENCE_TIME
*minperiod
)
1365 ACImpl
*This
= impl_from_IAudioClient(iface
);
1367 TRACE("(%p)->(%p, %p)\n", This
, defperiod
, minperiod
);
1369 if(!defperiod
&& !minperiod
)
1373 *defperiod
= DefaultPeriod
;
1375 *minperiod
= MinimumPeriod
;
1380 static void silence_buffer(ACImpl
*This
, BYTE
*buffer
, UINT32 frames
)
1382 WAVEFORMATEXTENSIBLE
*fmtex
= (WAVEFORMATEXTENSIBLE
*)This
->fmt
;
1383 if((This
->fmt
->wFormatTag
== WAVE_FORMAT_PCM
||
1384 (This
->fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
1385 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
))) &&
1386 This
->fmt
->wBitsPerSample
== 8)
1387 memset(buffer
, 128, frames
* This
->fmt
->nBlockAlign
);
1389 memset(buffer
, 0, frames
* This
->fmt
->nBlockAlign
);
1392 static void oss_write_data(ACImpl
*This
)
1394 ssize_t written_bytes
;
1395 UINT32 written_frames
, in_oss_frames
, write_limit
, max_period
, write_offs_frames
, new_frames
;
1396 SIZE_T to_write_frames
, to_write_bytes
, advanced
;
1400 if(ioctl(This
->fd
, SNDCTL_DSP_GETOSPACE
, &bi
) < 0){
1401 WARN("GETOSPACE failed: %d (%s)\n", errno
, strerror(errno
));
1405 max_period
= max(bi
.fragsize
/ This
->fmt
->nBlockAlign
, This
->period_frames
);
1407 if(bi
.bytes
> This
->oss_bufsize_bytes
){
1408 TRACE("New buffer size (%u) is larger than old buffer size (%u)\n",
1409 bi
.bytes
, This
->oss_bufsize_bytes
);
1410 This
->oss_bufsize_bytes
= bi
.bytes
;
1413 in_oss_frames
= (This
->oss_bufsize_bytes
- bi
.bytes
) / This
->fmt
->nBlockAlign
;
1415 if(in_oss_frames
> This
->in_oss_frames
){
1416 TRACE("Capping reported frames from %u to %u\n",
1417 in_oss_frames
, This
->in_oss_frames
);
1418 in_oss_frames
= This
->in_oss_frames
;
1422 while(write_limit
+ in_oss_frames
< max_period
* 3)
1423 write_limit
+= max_period
;
1424 if(write_limit
== 0)
1427 /* vvvvvv - in_oss_frames
1430 * ^^^^^^^^^^ - held_frames
1431 * ^ - lcl_offs_frames
1433 advanced
= This
->in_oss_frames
- in_oss_frames
;
1434 if(advanced
> This
->held_frames
)
1435 advanced
= This
->held_frames
;
1436 This
->lcl_offs_frames
+= advanced
;
1437 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1438 This
->held_frames
-= advanced
;
1439 This
->in_oss_frames
= in_oss_frames
;
1440 TRACE("advanced by %lu, lcl_offs: %u, held: %u, in_oss: %u\n",
1441 advanced
, This
->lcl_offs_frames
, This
->held_frames
, This
->in_oss_frames
);
1444 if(This
->held_frames
== This
->in_oss_frames
)
1447 write_offs_frames
= (This
->lcl_offs_frames
+ This
->in_oss_frames
) % This
->bufsize_frames
;
1448 new_frames
= This
->held_frames
- This
->in_oss_frames
;
1450 if(write_offs_frames
+ new_frames
> This
->bufsize_frames
)
1451 to_write_frames
= This
->bufsize_frames
- write_offs_frames
;
1453 to_write_frames
= new_frames
;
1455 to_write_frames
= min(to_write_frames
, write_limit
);
1456 to_write_bytes
= to_write_frames
* This
->fmt
->nBlockAlign
;
1457 TRACE("going to write %lu frames from %u (%lu of %u)\n", to_write_frames
,
1458 write_offs_frames
, to_write_frames
+ write_offs_frames
,
1459 This
->bufsize_frames
);
1461 buf
= This
->local_buffer
+ write_offs_frames
* This
->fmt
->nBlockAlign
;
1463 if(This
->session
->mute
)
1464 silence_buffer(This
, buf
, to_write_frames
);
1466 written_bytes
= write(This
->fd
, buf
, to_write_bytes
);
1467 if(written_bytes
< 0){
1468 /* EAGAIN is OSS buffer full, log that too */
1469 WARN("write failed: %d (%s)\n", errno
, strerror(errno
));
1472 written_frames
= written_bytes
/ This
->fmt
->nBlockAlign
;
1474 This
->in_oss_frames
+= written_frames
;
1476 if(written_frames
< to_write_frames
){
1477 /* OSS buffer probably full */
1481 if(new_frames
> written_frames
&& written_frames
< write_limit
){
1482 /* wrapped and have some data back at the start to write */
1484 to_write_frames
= min(write_limit
- written_frames
, new_frames
- written_frames
);
1485 to_write_bytes
= to_write_frames
* This
->fmt
->nBlockAlign
;
1487 if(This
->session
->mute
)
1488 silence_buffer(This
, This
->local_buffer
, to_write_frames
);
1490 TRACE("wrapping to write %lu frames from beginning\n", to_write_frames
);
1492 written_bytes
= write(This
->fd
, This
->local_buffer
, to_write_bytes
);
1493 if(written_bytes
< 0){
1494 WARN("write failed: %d (%s)\n", errno
, strerror(errno
));
1497 written_frames
= written_bytes
/ This
->fmt
->nBlockAlign
;
1498 This
->in_oss_frames
+= written_frames
;
1502 static void oss_read_data(ACImpl
*This
)
1504 UINT64 pos
, readable
;
1507 pos
= (This
->held_frames
+ This
->lcl_offs_frames
) % This
->bufsize_frames
;
1508 readable
= (This
->bufsize_frames
- pos
) * This
->fmt
->nBlockAlign
;
1510 nread
= read(This
->fd
, This
->local_buffer
+ pos
* This
->fmt
->nBlockAlign
,
1513 WARN("read failed: %d (%s)\n", errno
, strerror(errno
));
1517 This
->held_frames
+= nread
/ This
->fmt
->nBlockAlign
;
1519 if(This
->held_frames
> This
->bufsize_frames
){
1520 WARN("Overflow of unread data\n");
1521 This
->lcl_offs_frames
+= This
->held_frames
;
1522 This
->lcl_offs_frames
%= This
->bufsize_frames
;
1523 This
->held_frames
= This
->bufsize_frames
;
1527 static void CALLBACK
oss_period_callback(void *user
, BOOLEAN timer
)
1529 ACImpl
*This
= user
;
1531 EnterCriticalSection(&This
->lock
);
1534 if(This
->dataflow
== eRender
&& This
->held_frames
)
1535 oss_write_data(This
);
1536 else if(This
->dataflow
== eCapture
)
1537 oss_read_data(This
);
1540 LeaveCriticalSection(&This
->lock
);
1543 SetEvent(This
->event
);
1546 static HRESULT WINAPI
AudioClient_Start(IAudioClient
*iface
)
1548 ACImpl
*This
= impl_from_IAudioClient(iface
);
1550 TRACE("(%p)\n", This
);
1552 EnterCriticalSection(&This
->lock
);
1555 LeaveCriticalSection(&This
->lock
);
1556 return AUDCLNT_E_NOT_INITIALIZED
;
1559 if((This
->flags
& AUDCLNT_STREAMFLAGS_EVENTCALLBACK
) && !This
->event
){
1560 LeaveCriticalSection(&This
->lock
);
1561 return AUDCLNT_E_EVENTHANDLE_NOT_SET
;
1565 LeaveCriticalSection(&This
->lock
);
1566 return AUDCLNT_E_NOT_STOPPED
;
1570 if(!CreateTimerQueueTimer(&This
->timer
, g_timer_q
,
1571 oss_period_callback
, This
, 0, This
->period_us
/ 1000,
1572 WT_EXECUTEINTIMERTHREAD
))
1573 ERR("Unable to create period timer: %u\n", GetLastError());
1576 This
->playing
= TRUE
;
1578 LeaveCriticalSection(&This
->lock
);
1583 static HRESULT WINAPI
AudioClient_Stop(IAudioClient
*iface
)
1585 ACImpl
*This
= impl_from_IAudioClient(iface
);
1587 TRACE("(%p)\n", This
);
1589 EnterCriticalSection(&This
->lock
);
1592 LeaveCriticalSection(&This
->lock
);
1593 return AUDCLNT_E_NOT_INITIALIZED
;
1597 LeaveCriticalSection(&This
->lock
);
1601 This
->playing
= FALSE
;
1602 This
->in_oss_frames
= 0;
1604 LeaveCriticalSection(&This
->lock
);
1609 static HRESULT WINAPI
AudioClient_Reset(IAudioClient
*iface
)
1611 ACImpl
*This
= impl_from_IAudioClient(iface
);
1613 TRACE("(%p)\n", This
);
1615 EnterCriticalSection(&This
->lock
);
1618 LeaveCriticalSection(&This
->lock
);
1619 return AUDCLNT_E_NOT_INITIALIZED
;
1623 LeaveCriticalSection(&This
->lock
);
1624 return AUDCLNT_E_NOT_STOPPED
;
1627 if(This
->getbuf_last
){
1628 LeaveCriticalSection(&This
->lock
);
1629 return AUDCLNT_E_BUFFER_OPERATION_PENDING
;
1632 if(This
->dataflow
== eRender
){
1633 This
->written_frames
= 0;
1634 This
->last_pos_frames
= 0;
1636 This
->written_frames
+= This
->held_frames
;
1638 This
->held_frames
= 0;
1639 This
->lcl_offs_frames
= 0;
1640 This
->in_oss_frames
= 0;
1642 LeaveCriticalSection(&This
->lock
);
1647 static HRESULT WINAPI
AudioClient_SetEventHandle(IAudioClient
*iface
,
1650 ACImpl
*This
= impl_from_IAudioClient(iface
);
1652 TRACE("(%p)->(%p)\n", This
, event
);
1655 return E_INVALIDARG
;
1657 EnterCriticalSection(&This
->lock
);
1660 LeaveCriticalSection(&This
->lock
);
1661 return AUDCLNT_E_NOT_INITIALIZED
;
1664 if(!(This
->flags
& AUDCLNT_STREAMFLAGS_EVENTCALLBACK
)){
1665 LeaveCriticalSection(&This
->lock
);
1666 return AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED
;
1670 LeaveCriticalSection(&This
->lock
);
1671 FIXME("called twice\n");
1672 return HRESULT_FROM_WIN32(ERROR_INVALID_NAME
);
1675 This
->event
= event
;
1677 LeaveCriticalSection(&This
->lock
);
1682 static HRESULT WINAPI
AudioClient_GetService(IAudioClient
*iface
, REFIID riid
,
1685 ACImpl
*This
= impl_from_IAudioClient(iface
);
1687 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1693 EnterCriticalSection(&This
->lock
);
1696 LeaveCriticalSection(&This
->lock
);
1697 return AUDCLNT_E_NOT_INITIALIZED
;
1700 if(IsEqualIID(riid
, &IID_IAudioRenderClient
)){
1701 if(This
->dataflow
!= eRender
){
1702 LeaveCriticalSection(&This
->lock
);
1703 return AUDCLNT_E_WRONG_ENDPOINT_TYPE
;
1705 IAudioRenderClient_AddRef(&This
->IAudioRenderClient_iface
);
1706 *ppv
= &This
->IAudioRenderClient_iface
;
1707 }else if(IsEqualIID(riid
, &IID_IAudioCaptureClient
)){
1708 if(This
->dataflow
!= eCapture
){
1709 LeaveCriticalSection(&This
->lock
);
1710 return AUDCLNT_E_WRONG_ENDPOINT_TYPE
;
1712 IAudioCaptureClient_AddRef(&This
->IAudioCaptureClient_iface
);
1713 *ppv
= &This
->IAudioCaptureClient_iface
;
1714 }else if(IsEqualIID(riid
, &IID_IAudioClock
)){
1715 IAudioClock_AddRef(&This
->IAudioClock_iface
);
1716 *ppv
= &This
->IAudioClock_iface
;
1717 }else if(IsEqualIID(riid
, &IID_IAudioStreamVolume
)){
1718 IAudioStreamVolume_AddRef(&This
->IAudioStreamVolume_iface
);
1719 *ppv
= &This
->IAudioStreamVolume_iface
;
1720 }else if(IsEqualIID(riid
, &IID_IAudioSessionControl
)){
1721 if(!This
->session_wrapper
){
1722 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1723 if(!This
->session_wrapper
){
1724 LeaveCriticalSection(&This
->lock
);
1725 return E_OUTOFMEMORY
;
1728 IAudioSessionControl2_AddRef(&This
->session_wrapper
->IAudioSessionControl2_iface
);
1730 *ppv
= &This
->session_wrapper
->IAudioSessionControl2_iface
;
1731 }else if(IsEqualIID(riid
, &IID_IChannelAudioVolume
)){
1732 if(!This
->session_wrapper
){
1733 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1734 if(!This
->session_wrapper
){
1735 LeaveCriticalSection(&This
->lock
);
1736 return E_OUTOFMEMORY
;
1739 IChannelAudioVolume_AddRef(&This
->session_wrapper
->IChannelAudioVolume_iface
);
1741 *ppv
= &This
->session_wrapper
->IChannelAudioVolume_iface
;
1742 }else if(IsEqualIID(riid
, &IID_ISimpleAudioVolume
)){
1743 if(!This
->session_wrapper
){
1744 This
->session_wrapper
= AudioSessionWrapper_Create(This
);
1745 if(!This
->session_wrapper
){
1746 LeaveCriticalSection(&This
->lock
);
1747 return E_OUTOFMEMORY
;
1750 ISimpleAudioVolume_AddRef(&This
->session_wrapper
->ISimpleAudioVolume_iface
);
1752 *ppv
= &This
->session_wrapper
->ISimpleAudioVolume_iface
;
1756 LeaveCriticalSection(&This
->lock
);
1760 LeaveCriticalSection(&This
->lock
);
1762 FIXME("stub %s\n", debugstr_guid(riid
));
1763 return E_NOINTERFACE
;
1766 static const IAudioClientVtbl AudioClient_Vtbl
=
1768 AudioClient_QueryInterface
,
1770 AudioClient_Release
,
1771 AudioClient_Initialize
,
1772 AudioClient_GetBufferSize
,
1773 AudioClient_GetStreamLatency
,
1774 AudioClient_GetCurrentPadding
,
1775 AudioClient_IsFormatSupported
,
1776 AudioClient_GetMixFormat
,
1777 AudioClient_GetDevicePeriod
,
1781 AudioClient_SetEventHandle
,
1782 AudioClient_GetService
1785 static HRESULT WINAPI
AudioRenderClient_QueryInterface(
1786 IAudioRenderClient
*iface
, REFIID riid
, void **ppv
)
1788 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1789 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1795 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1796 IsEqualIID(riid
, &IID_IAudioRenderClient
))
1798 else if(IsEqualIID(riid
, &IID_IMarshal
))
1799 return IUnknown_QueryInterface(This
->pUnkFTMarshal
, riid
, ppv
);
1801 IUnknown_AddRef((IUnknown
*)*ppv
);
1805 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1806 return E_NOINTERFACE
;
1809 static ULONG WINAPI
AudioRenderClient_AddRef(IAudioRenderClient
*iface
)
1811 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1812 return AudioClient_AddRef(&This
->IAudioClient_iface
);
1815 static ULONG WINAPI
AudioRenderClient_Release(IAudioRenderClient
*iface
)
1817 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1818 return AudioClient_Release(&This
->IAudioClient_iface
);
1821 static HRESULT WINAPI
AudioRenderClient_GetBuffer(IAudioRenderClient
*iface
,
1822 UINT32 frames
, BYTE
**data
)
1824 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1827 TRACE("(%p)->(%u, %p)\n", This
, frames
, data
);
1834 EnterCriticalSection(&This
->lock
);
1836 if(This
->getbuf_last
){
1837 LeaveCriticalSection(&This
->lock
);
1838 return AUDCLNT_E_OUT_OF_ORDER
;
1842 LeaveCriticalSection(&This
->lock
);
1846 if(This
->held_frames
+ frames
> This
->bufsize_frames
){
1847 LeaveCriticalSection(&This
->lock
);
1848 return AUDCLNT_E_BUFFER_TOO_LARGE
;
1852 (This
->lcl_offs_frames
+ This
->held_frames
) % This
->bufsize_frames
;
1853 if(write_pos
+ frames
> This
->bufsize_frames
){
1854 if(This
->tmp_buffer_frames
< frames
){
1855 HeapFree(GetProcessHeap(), 0, This
->tmp_buffer
);
1856 This
->tmp_buffer
= HeapAlloc(GetProcessHeap(), 0,
1857 frames
* This
->fmt
->nBlockAlign
);
1858 if(!This
->tmp_buffer
){
1859 LeaveCriticalSection(&This
->lock
);
1860 return E_OUTOFMEMORY
;
1862 This
->tmp_buffer_frames
= frames
;
1864 *data
= This
->tmp_buffer
;
1865 This
->getbuf_last
= -frames
;
1867 *data
= This
->local_buffer
+ write_pos
* This
->fmt
->nBlockAlign
;
1868 This
->getbuf_last
= frames
;
1871 silence_buffer(This
, *data
, frames
);
1873 LeaveCriticalSection(&This
->lock
);
1878 static void oss_wrap_buffer(ACImpl
*This
, BYTE
*buffer
, UINT32 written_frames
)
1880 UINT32 write_offs_frames
=
1881 (This
->lcl_offs_frames
+ This
->held_frames
) % This
->bufsize_frames
;
1882 UINT32 write_offs_bytes
= write_offs_frames
* This
->fmt
->nBlockAlign
;
1883 UINT32 chunk_frames
= This
->bufsize_frames
- write_offs_frames
;
1884 UINT32 chunk_bytes
= chunk_frames
* This
->fmt
->nBlockAlign
;
1885 UINT32 written_bytes
= written_frames
* This
->fmt
->nBlockAlign
;
1887 if(written_bytes
<= chunk_bytes
){
1888 memcpy(This
->local_buffer
+ write_offs_bytes
, buffer
, written_bytes
);
1890 memcpy(This
->local_buffer
+ write_offs_bytes
, buffer
, chunk_bytes
);
1891 memcpy(This
->local_buffer
, buffer
+ chunk_bytes
,
1892 written_bytes
- chunk_bytes
);
1896 static HRESULT WINAPI
AudioRenderClient_ReleaseBuffer(
1897 IAudioRenderClient
*iface
, UINT32 written_frames
, DWORD flags
)
1899 ACImpl
*This
= impl_from_IAudioRenderClient(iface
);
1902 TRACE("(%p)->(%u, %x)\n", This
, written_frames
, flags
);
1904 EnterCriticalSection(&This
->lock
);
1906 if(!written_frames
){
1907 This
->getbuf_last
= 0;
1908 LeaveCriticalSection(&This
->lock
);
1912 if(!This
->getbuf_last
){
1913 LeaveCriticalSection(&This
->lock
);
1914 return AUDCLNT_E_OUT_OF_ORDER
;
1917 if(written_frames
> (This
->getbuf_last
>= 0 ? This
->getbuf_last
: -This
->getbuf_last
)){
1918 LeaveCriticalSection(&This
->lock
);
1919 return AUDCLNT_E_INVALID_SIZE
;
1922 if(This
->getbuf_last
>= 0)
1923 buffer
= This
->local_buffer
+ This
->fmt
->nBlockAlign
*
1924 ((This
->lcl_offs_frames
+ This
->held_frames
) % This
->bufsize_frames
);
1926 buffer
= This
->tmp_buffer
;
1928 if(flags
& AUDCLNT_BUFFERFLAGS_SILENT
)
1929 silence_buffer(This
, buffer
, written_frames
);
1931 if(This
->getbuf_last
< 0)
1932 oss_wrap_buffer(This
, buffer
, written_frames
);
1934 This
->held_frames
+= written_frames
;
1935 This
->written_frames
+= written_frames
;
1936 This
->getbuf_last
= 0;
1938 LeaveCriticalSection(&This
->lock
);
1943 static const IAudioRenderClientVtbl AudioRenderClient_Vtbl
= {
1944 AudioRenderClient_QueryInterface
,
1945 AudioRenderClient_AddRef
,
1946 AudioRenderClient_Release
,
1947 AudioRenderClient_GetBuffer
,
1948 AudioRenderClient_ReleaseBuffer
1951 static HRESULT WINAPI
AudioCaptureClient_QueryInterface(
1952 IAudioCaptureClient
*iface
, REFIID riid
, void **ppv
)
1954 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1955 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
1961 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1962 IsEqualIID(riid
, &IID_IAudioCaptureClient
))
1964 else if(IsEqualIID(riid
, &IID_IMarshal
))
1965 return IUnknown_QueryInterface(This
->pUnkFTMarshal
, riid
, ppv
);
1967 IUnknown_AddRef((IUnknown
*)*ppv
);
1971 WARN("Unknown interface %s\n", debugstr_guid(riid
));
1972 return E_NOINTERFACE
;
1975 static ULONG WINAPI
AudioCaptureClient_AddRef(IAudioCaptureClient
*iface
)
1977 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1978 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
1981 static ULONG WINAPI
AudioCaptureClient_Release(IAudioCaptureClient
*iface
)
1983 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1984 return IAudioClient_Release(&This
->IAudioClient_iface
);
1987 static HRESULT WINAPI
AudioCaptureClient_GetBuffer(IAudioCaptureClient
*iface
,
1988 BYTE
**data
, UINT32
*frames
, DWORD
*flags
, UINT64
*devpos
,
1991 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
1993 TRACE("(%p)->(%p, %p, %p, %p, %p)\n", This
, data
, frames
, flags
,
1996 if(!data
|| !frames
|| !flags
)
1999 EnterCriticalSection(&This
->lock
);
2001 if(This
->getbuf_last
){
2002 LeaveCriticalSection(&This
->lock
);
2003 return AUDCLNT_E_OUT_OF_ORDER
;
2006 if(This
->held_frames
< This
->period_frames
){
2008 LeaveCriticalSection(&This
->lock
);
2009 return AUDCLNT_S_BUFFER_EMPTY
;
2014 *frames
= This
->period_frames
;
2016 if(This
->lcl_offs_frames
+ *frames
> This
->bufsize_frames
){
2017 UINT32 chunk_bytes
, offs_bytes
, frames_bytes
;
2018 if(This
->tmp_buffer_frames
< *frames
){
2019 HeapFree(GetProcessHeap(), 0, This
->tmp_buffer
);
2020 This
->tmp_buffer
= HeapAlloc(GetProcessHeap(), 0,
2021 *frames
* This
->fmt
->nBlockAlign
);
2022 if(!This
->tmp_buffer
){
2023 LeaveCriticalSection(&This
->lock
);
2024 return E_OUTOFMEMORY
;
2026 This
->tmp_buffer_frames
= *frames
;
2029 *data
= This
->tmp_buffer
;
2030 chunk_bytes
= (This
->bufsize_frames
- This
->lcl_offs_frames
) *
2031 This
->fmt
->nBlockAlign
;
2032 offs_bytes
= This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
;
2033 frames_bytes
= *frames
* This
->fmt
->nBlockAlign
;
2034 memcpy(This
->tmp_buffer
, This
->local_buffer
+ offs_bytes
, chunk_bytes
);
2035 memcpy(This
->tmp_buffer
+ chunk_bytes
, This
->local_buffer
,
2036 frames_bytes
- chunk_bytes
);
2038 *data
= This
->local_buffer
+
2039 This
->lcl_offs_frames
* This
->fmt
->nBlockAlign
;
2041 This
->getbuf_last
= *frames
;
2044 *devpos
= This
->written_frames
;
2046 LARGE_INTEGER stamp
, freq
;
2047 QueryPerformanceCounter(&stamp
);
2048 QueryPerformanceFrequency(&freq
);
2049 *qpcpos
= (stamp
.QuadPart
* (INT64
)10000000) / freq
.QuadPart
;
2052 LeaveCriticalSection(&This
->lock
);
2054 return *frames
? S_OK
: AUDCLNT_S_BUFFER_EMPTY
;
2057 static HRESULT WINAPI
AudioCaptureClient_ReleaseBuffer(
2058 IAudioCaptureClient
*iface
, UINT32 done
)
2060 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
2062 TRACE("(%p)->(%u)\n", This
, done
);
2064 EnterCriticalSection(&This
->lock
);
2067 This
->getbuf_last
= 0;
2068 LeaveCriticalSection(&This
->lock
);
2072 if(!This
->getbuf_last
){
2073 LeaveCriticalSection(&This
->lock
);
2074 return AUDCLNT_E_OUT_OF_ORDER
;
2077 if(This
->getbuf_last
!= done
){
2078 LeaveCriticalSection(&This
->lock
);
2079 return AUDCLNT_E_INVALID_SIZE
;
2082 This
->written_frames
+= done
;
2083 This
->held_frames
-= done
;
2084 This
->lcl_offs_frames
+= done
;
2085 This
->lcl_offs_frames
%= This
->bufsize_frames
;
2086 This
->getbuf_last
= 0;
2088 LeaveCriticalSection(&This
->lock
);
2093 static HRESULT WINAPI
AudioCaptureClient_GetNextPacketSize(
2094 IAudioCaptureClient
*iface
, UINT32
*frames
)
2096 ACImpl
*This
= impl_from_IAudioCaptureClient(iface
);
2098 TRACE("(%p)->(%p)\n", This
, frames
);
2103 EnterCriticalSection(&This
->lock
);
2105 *frames
= This
->held_frames
< This
->period_frames
? 0 : This
->period_frames
;
2107 LeaveCriticalSection(&This
->lock
);
2112 static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl
=
2114 AudioCaptureClient_QueryInterface
,
2115 AudioCaptureClient_AddRef
,
2116 AudioCaptureClient_Release
,
2117 AudioCaptureClient_GetBuffer
,
2118 AudioCaptureClient_ReleaseBuffer
,
2119 AudioCaptureClient_GetNextPacketSize
2122 static HRESULT WINAPI
AudioClock_QueryInterface(IAudioClock
*iface
,
2123 REFIID riid
, void **ppv
)
2125 ACImpl
*This
= impl_from_IAudioClock(iface
);
2127 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2133 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IAudioClock
))
2135 else if(IsEqualIID(riid
, &IID_IAudioClock2
))
2136 *ppv
= &This
->IAudioClock2_iface
;
2138 IUnknown_AddRef((IUnknown
*)*ppv
);
2142 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2143 return E_NOINTERFACE
;
2146 static ULONG WINAPI
AudioClock_AddRef(IAudioClock
*iface
)
2148 ACImpl
*This
= impl_from_IAudioClock(iface
);
2149 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
2152 static ULONG WINAPI
AudioClock_Release(IAudioClock
*iface
)
2154 ACImpl
*This
= impl_from_IAudioClock(iface
);
2155 return IAudioClient_Release(&This
->IAudioClient_iface
);
2158 static HRESULT WINAPI
AudioClock_GetFrequency(IAudioClock
*iface
, UINT64
*freq
)
2160 ACImpl
*This
= impl_from_IAudioClock(iface
);
2162 TRACE("(%p)->(%p)\n", This
, freq
);
2164 if(This
->share
== AUDCLNT_SHAREMODE_SHARED
)
2165 *freq
= (UINT64
)This
->fmt
->nSamplesPerSec
* This
->fmt
->nBlockAlign
;
2167 *freq
= This
->fmt
->nSamplesPerSec
;
2172 static HRESULT WINAPI
AudioClock_GetPosition(IAudioClock
*iface
, UINT64
*pos
,
2175 ACImpl
*This
= impl_from_IAudioClock(iface
);
2177 TRACE("(%p)->(%p, %p)\n", This
, pos
, qpctime
);
2182 EnterCriticalSection(&This
->lock
);
2184 if(This
->dataflow
== eRender
){
2185 *pos
= This
->written_frames
- This
->held_frames
;
2186 if(*pos
< This
->last_pos_frames
)
2187 *pos
= This
->last_pos_frames
;
2188 }else if(This
->dataflow
== eCapture
){
2192 if(ioctl(This
->fd
, SNDCTL_DSP_GETISPACE
, &bi
) < 0){
2193 TRACE("GETISPACE failed: %d (%s)\n", errno
, strerror(errno
));
2196 if(bi
.bytes
<= bi
.fragsize
)
2199 held
= bi
.bytes
/ This
->fmt
->nBlockAlign
;
2202 *pos
= This
->written_frames
+ held
;
2205 This
->last_pos_frames
= *pos
;
2207 TRACE("returning: %s\n", wine_dbgstr_longlong(*pos
));
2208 if(This
->share
== AUDCLNT_SHAREMODE_SHARED
)
2209 *pos
*= This
->fmt
->nBlockAlign
;
2211 LeaveCriticalSection(&This
->lock
);
2214 LARGE_INTEGER stamp
, freq
;
2215 QueryPerformanceCounter(&stamp
);
2216 QueryPerformanceFrequency(&freq
);
2217 *qpctime
= (stamp
.QuadPart
* (INT64
)10000000) / freq
.QuadPart
;
2223 static HRESULT WINAPI
AudioClock_GetCharacteristics(IAudioClock
*iface
,
2226 ACImpl
*This
= impl_from_IAudioClock(iface
);
2228 TRACE("(%p)->(%p)\n", This
, chars
);
2233 *chars
= AUDIOCLOCK_CHARACTERISTIC_FIXED_FREQ
;
2238 static const IAudioClockVtbl AudioClock_Vtbl
=
2240 AudioClock_QueryInterface
,
2243 AudioClock_GetFrequency
,
2244 AudioClock_GetPosition
,
2245 AudioClock_GetCharacteristics
2248 static HRESULT WINAPI
AudioClock2_QueryInterface(IAudioClock2
*iface
,
2249 REFIID riid
, void **ppv
)
2251 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2252 return IAudioClock_QueryInterface(&This
->IAudioClock_iface
, riid
, ppv
);
2255 static ULONG WINAPI
AudioClock2_AddRef(IAudioClock2
*iface
)
2257 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2258 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
2261 static ULONG WINAPI
AudioClock2_Release(IAudioClock2
*iface
)
2263 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2264 return IAudioClient_Release(&This
->IAudioClient_iface
);
2267 static HRESULT WINAPI
AudioClock2_GetDevicePosition(IAudioClock2
*iface
,
2268 UINT64
*pos
, UINT64
*qpctime
)
2270 ACImpl
*This
= impl_from_IAudioClock2(iface
);
2272 FIXME("(%p)->(%p, %p)\n", This
, pos
, qpctime
);
2277 static const IAudioClock2Vtbl AudioClock2_Vtbl
=
2279 AudioClock2_QueryInterface
,
2281 AudioClock2_Release
,
2282 AudioClock2_GetDevicePosition
2285 static AudioSessionWrapper
*AudioSessionWrapper_Create(ACImpl
*client
)
2287 AudioSessionWrapper
*ret
;
2289 ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2290 sizeof(AudioSessionWrapper
));
2294 ret
->IAudioSessionControl2_iface
.lpVtbl
= &AudioSessionControl2_Vtbl
;
2295 ret
->ISimpleAudioVolume_iface
.lpVtbl
= &SimpleAudioVolume_Vtbl
;
2296 ret
->IChannelAudioVolume_iface
.lpVtbl
= &ChannelAudioVolume_Vtbl
;
2300 ret
->client
= client
;
2302 ret
->session
= client
->session
;
2303 AudioClient_AddRef(&client
->IAudioClient_iface
);
2309 static HRESULT WINAPI
AudioSessionControl_QueryInterface(
2310 IAudioSessionControl2
*iface
, REFIID riid
, void **ppv
)
2312 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2318 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2319 IsEqualIID(riid
, &IID_IAudioSessionControl
) ||
2320 IsEqualIID(riid
, &IID_IAudioSessionControl2
))
2323 IUnknown_AddRef((IUnknown
*)*ppv
);
2327 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2328 return E_NOINTERFACE
;
2331 static ULONG WINAPI
AudioSessionControl_AddRef(IAudioSessionControl2
*iface
)
2333 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2335 ref
= InterlockedIncrement(&This
->ref
);
2336 TRACE("(%p) Refcount now %u\n", This
, ref
);
2340 static ULONG WINAPI
AudioSessionControl_Release(IAudioSessionControl2
*iface
)
2342 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2344 ref
= InterlockedDecrement(&This
->ref
);
2345 TRACE("(%p) Refcount now %u\n", This
, ref
);
2348 EnterCriticalSection(&This
->client
->lock
);
2349 This
->client
->session_wrapper
= NULL
;
2350 LeaveCriticalSection(&This
->client
->lock
);
2351 AudioClient_Release(&This
->client
->IAudioClient_iface
);
2353 HeapFree(GetProcessHeap(), 0, This
);
2358 static HRESULT WINAPI
AudioSessionControl_GetState(IAudioSessionControl2
*iface
,
2359 AudioSessionState
*state
)
2361 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2364 TRACE("(%p)->(%p)\n", This
, state
);
2367 return NULL_PTR_ERR
;
2369 EnterCriticalSection(&g_sessions_lock
);
2371 if(list_empty(&This
->session
->clients
)){
2372 *state
= AudioSessionStateExpired
;
2373 LeaveCriticalSection(&g_sessions_lock
);
2377 LIST_FOR_EACH_ENTRY(client
, &This
->session
->clients
, ACImpl
, entry
){
2378 EnterCriticalSection(&client
->lock
);
2379 if(client
->playing
){
2380 *state
= AudioSessionStateActive
;
2381 LeaveCriticalSection(&client
->lock
);
2382 LeaveCriticalSection(&g_sessions_lock
);
2385 LeaveCriticalSection(&client
->lock
);
2388 LeaveCriticalSection(&g_sessions_lock
);
2390 *state
= AudioSessionStateInactive
;
2395 static HRESULT WINAPI
AudioSessionControl_GetDisplayName(
2396 IAudioSessionControl2
*iface
, WCHAR
**name
)
2398 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2400 FIXME("(%p)->(%p) - stub\n", This
, name
);
2405 static HRESULT WINAPI
AudioSessionControl_SetDisplayName(
2406 IAudioSessionControl2
*iface
, const WCHAR
*name
, const GUID
*session
)
2408 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2410 FIXME("(%p)->(%p, %s) - stub\n", This
, name
, debugstr_guid(session
));
2415 static HRESULT WINAPI
AudioSessionControl_GetIconPath(
2416 IAudioSessionControl2
*iface
, WCHAR
**path
)
2418 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2420 FIXME("(%p)->(%p) - stub\n", This
, path
);
2425 static HRESULT WINAPI
AudioSessionControl_SetIconPath(
2426 IAudioSessionControl2
*iface
, const WCHAR
*path
, const GUID
*session
)
2428 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2430 FIXME("(%p)->(%p, %s) - stub\n", This
, path
, debugstr_guid(session
));
2435 static HRESULT WINAPI
AudioSessionControl_GetGroupingParam(
2436 IAudioSessionControl2
*iface
, GUID
*group
)
2438 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2440 FIXME("(%p)->(%p) - stub\n", This
, group
);
2445 static HRESULT WINAPI
AudioSessionControl_SetGroupingParam(
2446 IAudioSessionControl2
*iface
, const GUID
*group
, const GUID
*session
)
2448 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2450 FIXME("(%p)->(%s, %s) - stub\n", This
, debugstr_guid(group
),
2451 debugstr_guid(session
));
2456 static HRESULT WINAPI
AudioSessionControl_RegisterAudioSessionNotification(
2457 IAudioSessionControl2
*iface
, IAudioSessionEvents
*events
)
2459 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2461 FIXME("(%p)->(%p) - stub\n", This
, events
);
2466 static HRESULT WINAPI
AudioSessionControl_UnregisterAudioSessionNotification(
2467 IAudioSessionControl2
*iface
, IAudioSessionEvents
*events
)
2469 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2471 FIXME("(%p)->(%p) - stub\n", This
, events
);
2476 static HRESULT WINAPI
AudioSessionControl_GetSessionIdentifier(
2477 IAudioSessionControl2
*iface
, WCHAR
**id
)
2479 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2481 FIXME("(%p)->(%p) - stub\n", This
, id
);
2486 static HRESULT WINAPI
AudioSessionControl_GetSessionInstanceIdentifier(
2487 IAudioSessionControl2
*iface
, WCHAR
**id
)
2489 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2491 FIXME("(%p)->(%p) - stub\n", This
, id
);
2496 static HRESULT WINAPI
AudioSessionControl_GetProcessId(
2497 IAudioSessionControl2
*iface
, DWORD
*pid
)
2499 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2501 TRACE("(%p)->(%p)\n", This
, pid
);
2506 *pid
= GetCurrentProcessId();
2511 static HRESULT WINAPI
AudioSessionControl_IsSystemSoundsSession(
2512 IAudioSessionControl2
*iface
)
2514 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2516 TRACE("(%p)\n", This
);
2521 static HRESULT WINAPI
AudioSessionControl_SetDuckingPreference(
2522 IAudioSessionControl2
*iface
, BOOL optout
)
2524 AudioSessionWrapper
*This
= impl_from_IAudioSessionControl2(iface
);
2526 TRACE("(%p)->(%d)\n", This
, optout
);
2531 static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl
=
2533 AudioSessionControl_QueryInterface
,
2534 AudioSessionControl_AddRef
,
2535 AudioSessionControl_Release
,
2536 AudioSessionControl_GetState
,
2537 AudioSessionControl_GetDisplayName
,
2538 AudioSessionControl_SetDisplayName
,
2539 AudioSessionControl_GetIconPath
,
2540 AudioSessionControl_SetIconPath
,
2541 AudioSessionControl_GetGroupingParam
,
2542 AudioSessionControl_SetGroupingParam
,
2543 AudioSessionControl_RegisterAudioSessionNotification
,
2544 AudioSessionControl_UnregisterAudioSessionNotification
,
2545 AudioSessionControl_GetSessionIdentifier
,
2546 AudioSessionControl_GetSessionInstanceIdentifier
,
2547 AudioSessionControl_GetProcessId
,
2548 AudioSessionControl_IsSystemSoundsSession
,
2549 AudioSessionControl_SetDuckingPreference
2552 static HRESULT WINAPI
SimpleAudioVolume_QueryInterface(
2553 ISimpleAudioVolume
*iface
, REFIID riid
, void **ppv
)
2555 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2561 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2562 IsEqualIID(riid
, &IID_ISimpleAudioVolume
))
2565 IUnknown_AddRef((IUnknown
*)*ppv
);
2569 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2570 return E_NOINTERFACE
;
2573 static ULONG WINAPI
SimpleAudioVolume_AddRef(ISimpleAudioVolume
*iface
)
2575 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2576 return AudioSessionControl_AddRef(&This
->IAudioSessionControl2_iface
);
2579 static ULONG WINAPI
SimpleAudioVolume_Release(ISimpleAudioVolume
*iface
)
2581 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2582 return AudioSessionControl_Release(&This
->IAudioSessionControl2_iface
);
2585 static HRESULT WINAPI
SimpleAudioVolume_SetMasterVolume(
2586 ISimpleAudioVolume
*iface
, float level
, const GUID
*context
)
2588 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2589 AudioSession
*session
= This
->session
;
2591 TRACE("(%p)->(%f, %s)\n", session
, level
, wine_dbgstr_guid(context
));
2593 if(level
< 0.f
|| level
> 1.f
)
2594 return E_INVALIDARG
;
2597 FIXME("Notifications not supported yet\n");
2599 EnterCriticalSection(&session
->lock
);
2601 session
->master_vol
= level
;
2603 TRACE("OSS doesn't support setting volume\n");
2605 LeaveCriticalSection(&session
->lock
);
2610 static HRESULT WINAPI
SimpleAudioVolume_GetMasterVolume(
2611 ISimpleAudioVolume
*iface
, float *level
)
2613 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2614 AudioSession
*session
= This
->session
;
2616 TRACE("(%p)->(%p)\n", session
, level
);
2619 return NULL_PTR_ERR
;
2621 *level
= session
->master_vol
;
2626 static HRESULT WINAPI
SimpleAudioVolume_SetMute(ISimpleAudioVolume
*iface
,
2627 BOOL mute
, const GUID
*context
)
2629 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2630 AudioSession
*session
= This
->session
;
2632 TRACE("(%p)->(%u, %p)\n", session
, mute
, context
);
2634 EnterCriticalSection(&session
->lock
);
2636 session
->mute
= mute
;
2638 LeaveCriticalSection(&session
->lock
);
2643 static HRESULT WINAPI
SimpleAudioVolume_GetMute(ISimpleAudioVolume
*iface
,
2646 AudioSessionWrapper
*This
= impl_from_ISimpleAudioVolume(iface
);
2647 AudioSession
*session
= This
->session
;
2649 TRACE("(%p)->(%p)\n", session
, mute
);
2652 return NULL_PTR_ERR
;
2654 *mute
= This
->session
->mute
;
2659 static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl
=
2661 SimpleAudioVolume_QueryInterface
,
2662 SimpleAudioVolume_AddRef
,
2663 SimpleAudioVolume_Release
,
2664 SimpleAudioVolume_SetMasterVolume
,
2665 SimpleAudioVolume_GetMasterVolume
,
2666 SimpleAudioVolume_SetMute
,
2667 SimpleAudioVolume_GetMute
2670 static HRESULT WINAPI
AudioStreamVolume_QueryInterface(
2671 IAudioStreamVolume
*iface
, REFIID riid
, void **ppv
)
2673 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2679 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2680 IsEqualIID(riid
, &IID_IAudioStreamVolume
))
2683 IUnknown_AddRef((IUnknown
*)*ppv
);
2687 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2688 return E_NOINTERFACE
;
2691 static ULONG WINAPI
AudioStreamVolume_AddRef(IAudioStreamVolume
*iface
)
2693 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2694 return IAudioClient_AddRef(&This
->IAudioClient_iface
);
2697 static ULONG WINAPI
AudioStreamVolume_Release(IAudioStreamVolume
*iface
)
2699 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2700 return IAudioClient_Release(&This
->IAudioClient_iface
);
2703 static HRESULT WINAPI
AudioStreamVolume_GetChannelCount(
2704 IAudioStreamVolume
*iface
, UINT32
*out
)
2706 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2708 TRACE("(%p)->(%p)\n", This
, out
);
2713 *out
= This
->fmt
->nChannels
;
2718 static HRESULT WINAPI
AudioStreamVolume_SetChannelVolume(
2719 IAudioStreamVolume
*iface
, UINT32 index
, float level
)
2721 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2723 TRACE("(%p)->(%d, %f)\n", This
, index
, level
);
2725 if(level
< 0.f
|| level
> 1.f
)
2726 return E_INVALIDARG
;
2728 if(index
>= This
->fmt
->nChannels
)
2729 return E_INVALIDARG
;
2731 EnterCriticalSection(&This
->lock
);
2733 This
->vols
[index
] = level
;
2735 TRACE("OSS doesn't support setting volume\n");
2737 LeaveCriticalSection(&This
->lock
);
2742 static HRESULT WINAPI
AudioStreamVolume_GetChannelVolume(
2743 IAudioStreamVolume
*iface
, UINT32 index
, float *level
)
2745 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2747 TRACE("(%p)->(%d, %p)\n", This
, index
, level
);
2752 if(index
>= This
->fmt
->nChannels
)
2753 return E_INVALIDARG
;
2755 *level
= This
->vols
[index
];
2760 static HRESULT WINAPI
AudioStreamVolume_SetAllVolumes(
2761 IAudioStreamVolume
*iface
, UINT32 count
, const float *levels
)
2763 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2766 TRACE("(%p)->(%d, %p)\n", This
, count
, levels
);
2771 if(count
!= This
->fmt
->nChannels
)
2772 return E_INVALIDARG
;
2774 EnterCriticalSection(&This
->lock
);
2776 for(i
= 0; i
< count
; ++i
)
2777 This
->vols
[i
] = levels
[i
];
2779 TRACE("OSS doesn't support setting volume\n");
2781 LeaveCriticalSection(&This
->lock
);
2786 static HRESULT WINAPI
AudioStreamVolume_GetAllVolumes(
2787 IAudioStreamVolume
*iface
, UINT32 count
, float *levels
)
2789 ACImpl
*This
= impl_from_IAudioStreamVolume(iface
);
2792 TRACE("(%p)->(%d, %p)\n", This
, count
, levels
);
2797 if(count
!= This
->fmt
->nChannels
)
2798 return E_INVALIDARG
;
2800 EnterCriticalSection(&This
->lock
);
2802 for(i
= 0; i
< count
; ++i
)
2803 levels
[i
] = This
->vols
[i
];
2805 LeaveCriticalSection(&This
->lock
);
2810 static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl
=
2812 AudioStreamVolume_QueryInterface
,
2813 AudioStreamVolume_AddRef
,
2814 AudioStreamVolume_Release
,
2815 AudioStreamVolume_GetChannelCount
,
2816 AudioStreamVolume_SetChannelVolume
,
2817 AudioStreamVolume_GetChannelVolume
,
2818 AudioStreamVolume_SetAllVolumes
,
2819 AudioStreamVolume_GetAllVolumes
2822 static HRESULT WINAPI
ChannelAudioVolume_QueryInterface(
2823 IChannelAudioVolume
*iface
, REFIID riid
, void **ppv
)
2825 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2831 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2832 IsEqualIID(riid
, &IID_IChannelAudioVolume
))
2835 IUnknown_AddRef((IUnknown
*)*ppv
);
2839 WARN("Unknown interface %s\n", debugstr_guid(riid
));
2840 return E_NOINTERFACE
;
2843 static ULONG WINAPI
ChannelAudioVolume_AddRef(IChannelAudioVolume
*iface
)
2845 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2846 return AudioSessionControl_AddRef(&This
->IAudioSessionControl2_iface
);
2849 static ULONG WINAPI
ChannelAudioVolume_Release(IChannelAudioVolume
*iface
)
2851 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2852 return AudioSessionControl_Release(&This
->IAudioSessionControl2_iface
);
2855 static HRESULT WINAPI
ChannelAudioVolume_GetChannelCount(
2856 IChannelAudioVolume
*iface
, UINT32
*out
)
2858 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2859 AudioSession
*session
= This
->session
;
2861 TRACE("(%p)->(%p)\n", session
, out
);
2864 return NULL_PTR_ERR
;
2866 *out
= session
->channel_count
;
2871 static HRESULT WINAPI
ChannelAudioVolume_SetChannelVolume(
2872 IChannelAudioVolume
*iface
, UINT32 index
, float level
,
2873 const GUID
*context
)
2875 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2876 AudioSession
*session
= This
->session
;
2878 TRACE("(%p)->(%d, %f, %s)\n", session
, index
, level
,
2879 wine_dbgstr_guid(context
));
2881 if(level
< 0.f
|| level
> 1.f
)
2882 return E_INVALIDARG
;
2884 if(index
>= session
->channel_count
)
2885 return E_INVALIDARG
;
2888 FIXME("Notifications not supported yet\n");
2890 EnterCriticalSection(&session
->lock
);
2892 session
->channel_vols
[index
] = level
;
2894 TRACE("OSS doesn't support setting volume\n");
2896 LeaveCriticalSection(&session
->lock
);
2901 static HRESULT WINAPI
ChannelAudioVolume_GetChannelVolume(
2902 IChannelAudioVolume
*iface
, UINT32 index
, float *level
)
2904 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2905 AudioSession
*session
= This
->session
;
2907 TRACE("(%p)->(%d, %p)\n", session
, index
, level
);
2910 return NULL_PTR_ERR
;
2912 if(index
>= session
->channel_count
)
2913 return E_INVALIDARG
;
2915 *level
= session
->channel_vols
[index
];
2920 static HRESULT WINAPI
ChannelAudioVolume_SetAllVolumes(
2921 IChannelAudioVolume
*iface
, UINT32 count
, const float *levels
,
2922 const GUID
*context
)
2924 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2925 AudioSession
*session
= This
->session
;
2928 TRACE("(%p)->(%d, %p, %s)\n", session
, count
, levels
,
2929 wine_dbgstr_guid(context
));
2932 return NULL_PTR_ERR
;
2934 if(count
!= session
->channel_count
)
2935 return E_INVALIDARG
;
2938 FIXME("Notifications not supported yet\n");
2940 EnterCriticalSection(&session
->lock
);
2942 for(i
= 0; i
< count
; ++i
)
2943 session
->channel_vols
[i
] = levels
[i
];
2945 TRACE("OSS doesn't support setting volume\n");
2947 LeaveCriticalSection(&session
->lock
);
2952 static HRESULT WINAPI
ChannelAudioVolume_GetAllVolumes(
2953 IChannelAudioVolume
*iface
, UINT32 count
, float *levels
)
2955 AudioSessionWrapper
*This
= impl_from_IChannelAudioVolume(iface
);
2956 AudioSession
*session
= This
->session
;
2959 TRACE("(%p)->(%d, %p)\n", session
, count
, levels
);
2962 return NULL_PTR_ERR
;
2964 if(count
!= session
->channel_count
)
2965 return E_INVALIDARG
;
2967 for(i
= 0; i
< count
; ++i
)
2968 levels
[i
] = session
->channel_vols
[i
];
2973 static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl
=
2975 ChannelAudioVolume_QueryInterface
,
2976 ChannelAudioVolume_AddRef
,
2977 ChannelAudioVolume_Release
,
2978 ChannelAudioVolume_GetChannelCount
,
2979 ChannelAudioVolume_SetChannelVolume
,
2980 ChannelAudioVolume_GetChannelVolume
,
2981 ChannelAudioVolume_SetAllVolumes
,
2982 ChannelAudioVolume_GetAllVolumes
2985 static HRESULT WINAPI
AudioSessionManager_QueryInterface(IAudioSessionManager2
*iface
,
2986 REFIID riid
, void **ppv
)
2988 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2994 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2995 IsEqualIID(riid
, &IID_IAudioSessionManager
) ||
2996 IsEqualIID(riid
, &IID_IAudioSessionManager2
))
2999 IUnknown_AddRef((IUnknown
*)*ppv
);
3003 WARN("Unknown interface %s\n", debugstr_guid(riid
));
3004 return E_NOINTERFACE
;
3007 static ULONG WINAPI
AudioSessionManager_AddRef(IAudioSessionManager2
*iface
)
3009 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
3011 ref
= InterlockedIncrement(&This
->ref
);
3012 TRACE("(%p) Refcount now %u\n", This
, ref
);
3016 static ULONG WINAPI
AudioSessionManager_Release(IAudioSessionManager2
*iface
)
3018 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
3020 ref
= InterlockedDecrement(&This
->ref
);
3021 TRACE("(%p) Refcount now %u\n", This
, ref
);
3023 HeapFree(GetProcessHeap(), 0, This
);
3027 static HRESULT WINAPI
AudioSessionManager_GetAudioSessionControl(
3028 IAudioSessionManager2
*iface
, const GUID
*session_guid
, DWORD flags
,
3029 IAudioSessionControl
**out
)
3031 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
3032 AudioSession
*session
;
3033 AudioSessionWrapper
*wrapper
;
3036 TRACE("(%p)->(%s, %x, %p)\n", This
, debugstr_guid(session_guid
),
3039 hr
= get_audio_session(session_guid
, This
->device
, 0, &session
);
3043 wrapper
= AudioSessionWrapper_Create(NULL
);
3045 return E_OUTOFMEMORY
;
3047 wrapper
->session
= session
;
3049 *out
= (IAudioSessionControl
*)&wrapper
->IAudioSessionControl2_iface
;
3054 static HRESULT WINAPI
AudioSessionManager_GetSimpleAudioVolume(
3055 IAudioSessionManager2
*iface
, const GUID
*session_guid
, DWORD flags
,
3056 ISimpleAudioVolume
**out
)
3058 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
3059 AudioSession
*session
;
3060 AudioSessionWrapper
*wrapper
;
3063 TRACE("(%p)->(%s, %x, %p)\n", This
, debugstr_guid(session_guid
),
3066 hr
= get_audio_session(session_guid
, This
->device
, 0, &session
);
3070 wrapper
= AudioSessionWrapper_Create(NULL
);
3072 return E_OUTOFMEMORY
;
3074 wrapper
->session
= session
;
3076 *out
= &wrapper
->ISimpleAudioVolume_iface
;
3081 static HRESULT WINAPI
AudioSessionManager_GetSessionEnumerator(
3082 IAudioSessionManager2
*iface
, IAudioSessionEnumerator
**out
)
3084 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
3085 FIXME("(%p)->(%p) - stub\n", This
, out
);
3089 static HRESULT WINAPI
AudioSessionManager_RegisterSessionNotification(
3090 IAudioSessionManager2
*iface
, IAudioSessionNotification
*notification
)
3092 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
3093 FIXME("(%p)->(%p) - stub\n", This
, notification
);
3097 static HRESULT WINAPI
AudioSessionManager_UnregisterSessionNotification(
3098 IAudioSessionManager2
*iface
, IAudioSessionNotification
*notification
)
3100 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
3101 FIXME("(%p)->(%p) - stub\n", This
, notification
);
3105 static HRESULT WINAPI
AudioSessionManager_RegisterDuckNotification(
3106 IAudioSessionManager2
*iface
, const WCHAR
*session_id
,
3107 IAudioVolumeDuckNotification
*notification
)
3109 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
3110 FIXME("(%p)->(%p) - stub\n", This
, notification
);
3114 static HRESULT WINAPI
AudioSessionManager_UnregisterDuckNotification(
3115 IAudioSessionManager2
*iface
,
3116 IAudioVolumeDuckNotification
*notification
)
3118 SessionMgr
*This
= impl_from_IAudioSessionManager2(iface
);
3119 FIXME("(%p)->(%p) - stub\n", This
, notification
);
3123 static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl
=
3125 AudioSessionManager_QueryInterface
,
3126 AudioSessionManager_AddRef
,
3127 AudioSessionManager_Release
,
3128 AudioSessionManager_GetAudioSessionControl
,
3129 AudioSessionManager_GetSimpleAudioVolume
,
3130 AudioSessionManager_GetSessionEnumerator
,
3131 AudioSessionManager_RegisterSessionNotification
,
3132 AudioSessionManager_UnregisterSessionNotification
,
3133 AudioSessionManager_RegisterDuckNotification
,
3134 AudioSessionManager_UnregisterDuckNotification
3137 HRESULT WINAPI
AUDDRV_GetAudioSessionManager(IMMDevice
*device
,
3138 IAudioSessionManager2
**out
)
3142 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SessionMgr
));
3144 return E_OUTOFMEMORY
;
3146 This
->IAudioSessionManager2_iface
.lpVtbl
= &AudioSessionManager2_Vtbl
;
3147 This
->device
= device
;
3150 *out
= &This
->IAudioSessionManager2_iface
;