2011-04-27 16:12:36 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Andrew Eikum for CodeWeavers
|
2022-03-31 09:21:46 +02:00
|
|
|
* 2022 Huw Davies
|
2011-04-27 16:12:36 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2011-05-02 20:06:49 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <sys/soundcard.h>
|
2022-04-12 08:59:02 +02:00
|
|
|
#include <pthread.h>
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2022-03-31 09:21:46 +02:00
|
|
|
#include "winternl.h"
|
2011-04-27 16:12:36 +02:00
|
|
|
#include "winnls.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
|
|
|
|
#include "ole2.h"
|
|
|
|
#include "mmdeviceapi.h"
|
|
|
|
#include "devpkey.h"
|
|
|
|
#include "dshow.h"
|
|
|
|
#include "dsound.h"
|
2011-05-02 15:21:49 +02:00
|
|
|
|
|
|
|
#include "initguid.h"
|
2011-09-23 22:03:59 +02:00
|
|
|
#include "endpointvolume.h"
|
2011-04-27 16:12:36 +02:00
|
|
|
#include "audiopolicy.h"
|
2011-05-02 15:21:49 +02:00
|
|
|
#include "audioclient.h"
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-03-31 09:21:46 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/list.h"
|
2022-03-31 09:21:50 +02:00
|
|
|
#include "wine/unicode.h"
|
2022-03-31 09:21:46 +02:00
|
|
|
#include "wine/unixlib.h"
|
|
|
|
|
|
|
|
#include "unixlib.h"
|
|
|
|
|
2011-04-27 16:12:36 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(oss);
|
|
|
|
|
2011-05-02 15:21:49 +02:00
|
|
|
#define NULL_PTR_ERR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, RPC_X_NULL_REF_POINTER)
|
|
|
|
|
2022-03-31 09:21:46 +02:00
|
|
|
unixlib_handle_t oss_handle = 0;
|
|
|
|
|
2014-06-27 18:04:16 +02:00
|
|
|
static const REFERENCE_TIME DefaultPeriod = 100000;
|
|
|
|
static const REFERENCE_TIME MinimumPeriod = 50000;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2011-05-02 15:21:49 +02:00
|
|
|
struct ACImpl;
|
|
|
|
typedef struct ACImpl ACImpl;
|
|
|
|
|
|
|
|
typedef struct _AudioSession {
|
|
|
|
GUID guid;
|
|
|
|
struct list clients;
|
|
|
|
|
2011-06-13 22:23:09 +02:00
|
|
|
IMMDevice *device;
|
2011-05-02 15:21:49 +02:00
|
|
|
|
2011-05-06 17:34:27 +02:00
|
|
|
float master_vol;
|
|
|
|
UINT32 channel_count;
|
|
|
|
float *channel_vols;
|
2011-06-20 16:31:51 +02:00
|
|
|
BOOL mute;
|
2011-05-06 17:34:27 +02:00
|
|
|
|
2011-05-02 15:21:49 +02:00
|
|
|
struct list entry;
|
|
|
|
} AudioSession;
|
|
|
|
|
|
|
|
typedef struct _AudioSessionWrapper {
|
|
|
|
IAudioSessionControl2 IAudioSessionControl2_iface;
|
2011-05-06 17:34:27 +02:00
|
|
|
IChannelAudioVolume IChannelAudioVolume_iface;
|
|
|
|
ISimpleAudioVolume ISimpleAudioVolume_iface;
|
2011-05-02 15:21:49 +02:00
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
ACImpl *client;
|
|
|
|
AudioSession *session;
|
|
|
|
} AudioSessionWrapper;
|
|
|
|
|
|
|
|
struct ACImpl {
|
2020-10-01 22:23:05 +02:00
|
|
|
IAudioClient3 IAudioClient3_iface;
|
2011-04-27 16:12:36 +02:00
|
|
|
IAudioRenderClient IAudioRenderClient_iface;
|
|
|
|
IAudioCaptureClient IAudioCaptureClient_iface;
|
|
|
|
IAudioClock IAudioClock_iface;
|
|
|
|
IAudioClock2 IAudioClock2_iface;
|
2011-05-06 17:34:27 +02:00
|
|
|
IAudioStreamVolume IAudioStreamVolume_iface;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
IMMDevice *parent;
|
2013-08-02 03:54:21 +02:00
|
|
|
IUnknown *pUnkFTMarshal;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
EDataFlow dataflow;
|
2011-05-06 17:34:27 +02:00
|
|
|
float *vols;
|
2022-04-06 08:55:51 +02:00
|
|
|
UINT32 channel_count;
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
HANDLE timer;
|
|
|
|
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSession *session;
|
|
|
|
AudioSessionWrapper *session_wrapper;
|
|
|
|
|
|
|
|
struct list entry;
|
2022-04-06 08:55:52 +02:00
|
|
|
|
|
|
|
/* Keep at end */
|
|
|
|
char devnode[0];
|
2011-05-02 15:21:49 +02:00
|
|
|
};
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2011-06-06 15:49:26 +02:00
|
|
|
typedef struct _SessionMgr {
|
|
|
|
IAudioSessionManager2 IAudioSessionManager2_iface;
|
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
2011-06-13 22:23:09 +02:00
|
|
|
IMMDevice *device;
|
2011-06-06 15:49:26 +02:00
|
|
|
} SessionMgr;
|
|
|
|
|
2012-04-03 21:05:20 +02:00
|
|
|
typedef struct _OSSDevice {
|
2022-03-31 09:21:50 +02:00
|
|
|
struct list entry;
|
2012-04-03 21:05:20 +02:00
|
|
|
EDataFlow flow;
|
|
|
|
GUID guid;
|
2022-03-31 09:21:50 +02:00
|
|
|
char devnode[0];
|
2012-04-03 21:05:20 +02:00
|
|
|
} OSSDevice;
|
|
|
|
|
|
|
|
static struct list g_devices = LIST_INIT(g_devices);
|
|
|
|
|
|
|
|
static const WCHAR drv_key_devicesW[] = {'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'W','i','n','e','\\','D','r','i','v','e','r','s','\\',
|
|
|
|
'w','i','n','e','o','s','s','.','d','r','v','\\','d','e','v','i','c','e','s',0};
|
|
|
|
static const WCHAR guidW[] = {'g','u','i','d',0};
|
|
|
|
|
2011-04-27 16:12:36 +02:00
|
|
|
static HANDLE g_timer_q;
|
|
|
|
|
2011-05-02 15:21:49 +02:00
|
|
|
static CRITICAL_SECTION g_sessions_lock;
|
2011-11-15 14:39:45 +01:00
|
|
|
static CRITICAL_SECTION_DEBUG g_sessions_lock_debug =
|
|
|
|
{
|
|
|
|
0, 0, &g_sessions_lock,
|
|
|
|
{ &g_sessions_lock_debug.ProcessLocksList, &g_sessions_lock_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": g_sessions_lock") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION g_sessions_lock = { &g_sessions_lock_debug, -1, 0, 0, 0, 0 };
|
2011-05-02 15:21:49 +02:00
|
|
|
static struct list g_sessions = LIST_INIT(g_sessions);
|
|
|
|
|
|
|
|
static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client);
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static const IAudioClient3Vtbl AudioClient3_Vtbl;
|
2011-04-27 16:12:36 +02:00
|
|
|
static const IAudioRenderClientVtbl AudioRenderClient_Vtbl;
|
|
|
|
static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl;
|
|
|
|
static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl;
|
|
|
|
static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl;
|
|
|
|
static const IAudioClockVtbl AudioClock_Vtbl;
|
|
|
|
static const IAudioClock2Vtbl AudioClock2_Vtbl;
|
2011-05-06 17:34:27 +02:00
|
|
|
static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl;
|
|
|
|
static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl;
|
2011-06-06 15:49:26 +02:00
|
|
|
static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static inline ACImpl *impl_from_IAudioClient3(IAudioClient3 *iface)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
return CONTAINING_RECORD(iface, ACImpl, IAudioClient3_iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline ACImpl *impl_from_IAudioRenderClient(IAudioRenderClient *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ACImpl, IAudioRenderClient_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline ACImpl *impl_from_IAudioCaptureClient(IAudioCaptureClient *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ACImpl, IAudioCaptureClient_iface);
|
|
|
|
}
|
|
|
|
|
2011-05-02 15:21:49 +02:00
|
|
|
static inline AudioSessionWrapper *impl_from_IAudioSessionControl2(IAudioSessionControl2 *iface)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
return CONTAINING_RECORD(iface, AudioSessionWrapper, IAudioSessionControl2_iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
2011-05-06 17:34:27 +02:00
|
|
|
static inline AudioSessionWrapper *impl_from_ISimpleAudioVolume(ISimpleAudioVolume *iface)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
2011-05-06 17:34:27 +02:00
|
|
|
return CONTAINING_RECORD(iface, AudioSessionWrapper, ISimpleAudioVolume_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline AudioSessionWrapper *impl_from_IChannelAudioVolume(IChannelAudioVolume *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, AudioSessionWrapper, IChannelAudioVolume_iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline ACImpl *impl_from_IAudioClock(IAudioClock *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ACImpl, IAudioClock_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline ACImpl *impl_from_IAudioClock2(IAudioClock2 *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ACImpl, IAudioClock2_iface);
|
|
|
|
}
|
|
|
|
|
2011-05-06 17:34:27 +02:00
|
|
|
static inline ACImpl *impl_from_IAudioStreamVolume(IAudioStreamVolume *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ACImpl, IAudioStreamVolume_iface);
|
|
|
|
}
|
|
|
|
|
2011-06-06 15:49:26 +02:00
|
|
|
static inline SessionMgr *impl_from_IAudioSessionManager2(IAudioSessionManager2 *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, SessionMgr, IAudioSessionManager2_iface);
|
|
|
|
}
|
|
|
|
|
2011-05-02 15:21:29 +02:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved)
|
|
|
|
{
|
2011-11-15 14:39:45 +01:00
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2022-03-31 09:21:46 +02:00
|
|
|
if(NtQueryVirtualMemory(GetCurrentProcess(), dll, MemoryWineUnixFuncs,
|
|
|
|
&oss_handle, sizeof(oss_handle), NULL))
|
|
|
|
return FALSE;
|
2011-05-02 15:21:29 +02:00
|
|
|
g_timer_q = CreateTimerQueue();
|
|
|
|
if(!g_timer_q)
|
|
|
|
return FALSE;
|
2011-11-15 14:39:45 +01:00
|
|
|
break;
|
2011-05-02 15:21:49 +02:00
|
|
|
|
2011-11-15 14:39:45 +01:00
|
|
|
case DLL_PROCESS_DETACH:
|
2013-05-15 10:30:36 +02:00
|
|
|
if (!reserved)
|
2012-04-03 21:05:20 +02:00
|
|
|
{
|
|
|
|
OSSDevice *iter, *iter2;
|
|
|
|
|
|
|
|
DeleteCriticalSection(&g_sessions_lock);
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(iter, iter2, &g_devices, OSSDevice, entry){
|
|
|
|
HeapFree(GetProcessHeap(), 0, iter);
|
|
|
|
}
|
|
|
|
}
|
2013-05-15 10:30:36 +02:00
|
|
|
break;
|
2011-05-02 15:21:29 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-08-31 22:04:37 +02:00
|
|
|
int WINAPI AUDDRV_GetPriority(void)
|
|
|
|
{
|
2022-03-31 09:21:46 +02:00
|
|
|
struct test_connect_params params;
|
2011-08-31 22:04:37 +02:00
|
|
|
|
2022-03-31 09:21:46 +02:00
|
|
|
OSS_CALL(test_connect, ¶ms);
|
2011-08-31 22:04:37 +02:00
|
|
|
|
2022-03-31 09:21:46 +02:00
|
|
|
return params.priority;
|
2011-08-31 22:04:37 +02:00
|
|
|
}
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
static void oss_lock(struct oss_stream *stream)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&stream->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void oss_unlock(struct oss_stream *stream)
|
|
|
|
{
|
|
|
|
pthread_mutex_unlock(&stream->lock);
|
|
|
|
}
|
|
|
|
|
2012-04-03 21:05:20 +02:00
|
|
|
static void set_device_guid(EDataFlow flow, HKEY drv_key, const WCHAR *key_name,
|
|
|
|
GUID *guid)
|
|
|
|
{
|
|
|
|
HKEY key;
|
|
|
|
BOOL opened = FALSE;
|
|
|
|
LONG lr;
|
|
|
|
|
|
|
|
if(!drv_key){
|
|
|
|
lr = RegCreateKeyExW(HKEY_CURRENT_USER, drv_key_devicesW, 0, NULL, 0, KEY_WRITE,
|
|
|
|
NULL, &drv_key, NULL);
|
|
|
|
if(lr != ERROR_SUCCESS){
|
|
|
|
ERR("RegCreateKeyEx(drv_key) failed: %u\n", lr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
opened = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lr = RegCreateKeyExW(drv_key, key_name, 0, NULL, 0, KEY_WRITE,
|
|
|
|
NULL, &key, NULL);
|
|
|
|
if(lr != ERROR_SUCCESS){
|
|
|
|
ERR("RegCreateKeyEx(%s) failed: %u\n", wine_dbgstr_w(key_name), lr);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
lr = RegSetValueExW(key, guidW, 0, REG_BINARY, (BYTE*)guid,
|
|
|
|
sizeof(GUID));
|
|
|
|
if(lr != ERROR_SUCCESS)
|
|
|
|
ERR("RegSetValueEx(%s\\guid) failed: %u\n", wine_dbgstr_w(key_name), lr);
|
|
|
|
|
|
|
|
RegCloseKey(key);
|
|
|
|
exit:
|
|
|
|
if(opened)
|
|
|
|
RegCloseKey(drv_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_device_guid(EDataFlow flow, const char *device, GUID *guid)
|
|
|
|
{
|
|
|
|
HKEY key = NULL, dev_key;
|
|
|
|
DWORD type, size = sizeof(*guid);
|
|
|
|
WCHAR key_name[256];
|
|
|
|
|
|
|
|
if(flow == eCapture)
|
|
|
|
key_name[0] = '1';
|
|
|
|
else
|
|
|
|
key_name[0] = '0';
|
|
|
|
key_name[1] = ',';
|
2018-08-09 20:59:33 +02:00
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, device, -1, key_name + 2, ARRAY_SIZE(key_name) - 2);
|
2012-04-03 21:05:20 +02:00
|
|
|
|
|
|
|
if(RegOpenKeyExW(HKEY_CURRENT_USER, drv_key_devicesW, 0, KEY_WRITE|KEY_READ, &key) == ERROR_SUCCESS){
|
|
|
|
if(RegOpenKeyExW(key, key_name, 0, KEY_READ, &dev_key) == ERROR_SUCCESS){
|
|
|
|
if(RegQueryValueExW(dev_key, guidW, 0, &type,
|
|
|
|
(BYTE*)guid, &size) == ERROR_SUCCESS){
|
|
|
|
if(type == REG_BINARY){
|
|
|
|
RegCloseKey(dev_key);
|
|
|
|
RegCloseKey(key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ERR("Invalid type for device %s GUID: %u; ignoring and overwriting\n",
|
|
|
|
wine_dbgstr_w(key_name), type);
|
|
|
|
}
|
|
|
|
RegCloseKey(dev_key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CoCreateGuid(guid);
|
|
|
|
|
|
|
|
set_device_guid(flow, key, key_name, guid);
|
|
|
|
|
|
|
|
if(key)
|
|
|
|
RegCloseKey(key);
|
|
|
|
}
|
|
|
|
|
2022-03-31 09:21:48 +02:00
|
|
|
static int open_device(const char *device, EDataFlow flow)
|
|
|
|
{
|
|
|
|
int flags = ((flow == eRender) ? O_WRONLY : O_RDONLY) | O_NONBLOCK;
|
|
|
|
|
|
|
|
return open(device, flags, 0);
|
|
|
|
}
|
|
|
|
|
2022-04-12 08:59:00 +02:00
|
|
|
static void set_stream_volumes(ACImpl *This)
|
|
|
|
{
|
|
|
|
struct oss_stream *stream = This->stream;
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_lock(stream);
|
2022-04-12 08:59:00 +02:00
|
|
|
stream->mute = This->session->mute;
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2022-04-12 08:59:00 +02:00
|
|
|
}
|
|
|
|
|
2022-03-31 09:21:49 +02:00
|
|
|
static const OSSDevice *get_ossdevice_from_guid(const GUID *guid)
|
|
|
|
{
|
|
|
|
OSSDevice *dev_item;
|
|
|
|
LIST_FOR_EACH_ENTRY(dev_item, &g_devices, OSSDevice, entry)
|
|
|
|
if(IsEqualGUID(guid, &dev_item->guid))
|
|
|
|
return dev_item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-03-31 09:21:50 +02:00
|
|
|
static void device_add(OSSDevice *oss_dev)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
2022-03-31 09:21:50 +02:00
|
|
|
if(get_ossdevice_from_guid(&oss_dev->guid)) /* already in list */
|
|
|
|
HeapFree(GetProcessHeap(), 0, oss_dev);
|
|
|
|
else
|
|
|
|
list_add_tail(&g_devices, &oss_dev->entry);
|
|
|
|
}
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-03-31 09:21:50 +02:00
|
|
|
HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, WCHAR ***ids_out, GUID **guids_out,
|
|
|
|
UINT *num, UINT *def_index)
|
|
|
|
{
|
|
|
|
struct get_endpoint_ids_params params;
|
|
|
|
GUID *guids = NULL;
|
|
|
|
WCHAR **ids = NULL;
|
|
|
|
unsigned int i;
|
2012-04-04 20:16:09 +02:00
|
|
|
|
2012-04-03 21:05:20 +02:00
|
|
|
TRACE("%d %p %p %p %p\n", flow, ids, guids, num, def_index);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-03-31 09:21:50 +02:00
|
|
|
params.flow = flow;
|
|
|
|
params.size = 1000;
|
|
|
|
params.endpoints = NULL;
|
|
|
|
do{
|
|
|
|
HeapFree(GetProcessHeap(), 0, params.endpoints);
|
|
|
|
params.endpoints = HeapAlloc(GetProcessHeap(), 0, params.size);
|
|
|
|
OSS_CALL(get_endpoint_ids, ¶ms);
|
|
|
|
}while(params.result == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER));
|
|
|
|
|
|
|
|
if(FAILED(params.result)) goto end;
|
|
|
|
|
|
|
|
ids = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, params.num * sizeof(*ids));
|
|
|
|
guids = HeapAlloc(GetProcessHeap(), 0, params.num * sizeof(*guids));
|
|
|
|
if(!ids || !guids){
|
|
|
|
params.result = E_OUTOFMEMORY;
|
|
|
|
goto end;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
2022-03-31 09:21:50 +02:00
|
|
|
for(i = 0; i < params.num; i++){
|
|
|
|
unsigned int name_size = (strlenW(params.endpoints[i].name) + 1) * sizeof(WCHAR);
|
|
|
|
unsigned int dev_size = strlen(params.endpoints[i].device) + 1;
|
|
|
|
OSSDevice *oss_dev;
|
|
|
|
|
|
|
|
ids[i] = HeapAlloc(GetProcessHeap(), 0, name_size);
|
|
|
|
oss_dev = HeapAlloc(GetProcessHeap(), 0, offsetof(OSSDevice, devnode[dev_size]));
|
|
|
|
if(!ids[i] || !oss_dev){
|
|
|
|
HeapFree(GetProcessHeap, 0, oss_dev);
|
|
|
|
params.result = E_OUTOFMEMORY;
|
|
|
|
goto end;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
2022-03-31 09:21:50 +02:00
|
|
|
memcpy(ids[i], params.endpoints[i].name, name_size);
|
|
|
|
get_device_guid(flow, params.endpoints[i].device, guids + i);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-03-31 09:21:50 +02:00
|
|
|
oss_dev->flow = flow;
|
|
|
|
oss_dev->guid = guids[i];
|
|
|
|
memcpy(oss_dev->devnode, params.endpoints[i].device, dev_size);
|
|
|
|
device_add(oss_dev);
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
2022-03-31 09:21:50 +02:00
|
|
|
*def_index = params.default_idx;
|
|
|
|
|
|
|
|
end:
|
|
|
|
HeapFree(GetProcessHeap(), 0, params.endpoints);
|
|
|
|
if(FAILED(params.result)){
|
|
|
|
HeapFree(GetProcessHeap(), 0, guids);
|
|
|
|
if(ids){
|
|
|
|
for(i = 0; i < params.num; i++)
|
|
|
|
HeapFree(GetProcessHeap(), 0, ids[i]);
|
|
|
|
HeapFree(GetProcessHeap(), 0, ids);
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
2022-03-31 09:21:50 +02:00
|
|
|
}else{
|
|
|
|
*ids_out = ids;
|
|
|
|
*guids_out = guids;
|
|
|
|
*num = params.num;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
2022-03-31 09:21:50 +02:00
|
|
|
return params.result;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 21:05:20 +02:00
|
|
|
HRESULT WINAPI AUDDRV_GetAudioEndpoint(GUID *guid, IMMDevice *dev,
|
2012-04-03 20:48:12 +02:00
|
|
|
IAudioClient **out)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
|
|
|
ACImpl *This;
|
2012-04-03 21:05:20 +02:00
|
|
|
const OSSDevice *oss_dev;
|
2013-08-02 03:54:21 +02:00
|
|
|
HRESULT hr;
|
2022-04-06 08:55:52 +02:00
|
|
|
int len;
|
2012-04-03 21:05:20 +02:00
|
|
|
|
|
|
|
TRACE("%s %p %p\n", debugstr_guid(guid), dev, out);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2012-04-03 21:05:20 +02:00
|
|
|
oss_dev = get_ossdevice_from_guid(guid);
|
|
|
|
if(!oss_dev){
|
|
|
|
WARN("Unknown GUID: %s\n", debugstr_guid(guid));
|
|
|
|
return AUDCLNT_E_DEVICE_INVALIDATED;
|
|
|
|
}
|
2022-04-06 08:55:52 +02:00
|
|
|
len = strlen(oss_dev->devnode);
|
|
|
|
This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, offsetof(ACImpl, devnode[len + 1]));
|
2011-04-27 16:12:36 +02:00
|
|
|
if(!This)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
hr = CoCreateFreeThreadedMarshaler((IUnknown *)&This->IAudioClient3_iface, &This->pUnkFTMarshal);
|
2013-08-02 03:54:21 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-04-03 21:05:20 +02:00
|
|
|
This->dataflow = oss_dev->flow;
|
|
|
|
strcpy(This->devnode, oss_dev->devnode);
|
2011-10-10 22:57:06 +02:00
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
This->IAudioClient3_iface.lpVtbl = &AudioClient3_Vtbl;
|
2011-04-27 16:12:36 +02:00
|
|
|
This->IAudioRenderClient_iface.lpVtbl = &AudioRenderClient_Vtbl;
|
|
|
|
This->IAudioCaptureClient_iface.lpVtbl = &AudioCaptureClient_Vtbl;
|
|
|
|
This->IAudioClock_iface.lpVtbl = &AudioClock_Vtbl;
|
|
|
|
This->IAudioClock2_iface.lpVtbl = &AudioClock2_Vtbl;
|
2011-05-06 17:34:27 +02:00
|
|
|
This->IAudioStreamVolume_iface.lpVtbl = &AudioStreamVolume_Vtbl;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
This->parent = dev;
|
|
|
|
IMMDevice_AddRef(This->parent);
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
*out = (IAudioClient *)&This->IAudioClient3_iface;
|
|
|
|
IAudioClient3_AddRef(&This->IAudioClient3_iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_QueryInterface(IAudioClient3 *iface,
|
2011-04-27 16:12:36 +02:00
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if(!ppv)
|
|
|
|
return E_POINTER;
|
|
|
|
*ppv = NULL;
|
2020-10-01 21:31:22 +02:00
|
|
|
if(IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IAudioClient) ||
|
2020-10-01 22:23:05 +02:00
|
|
|
IsEqualIID(riid, &IID_IAudioClient2) ||
|
|
|
|
IsEqualIID(riid, &IID_IAudioClient3))
|
2011-04-27 16:12:36 +02:00
|
|
|
*ppv = iface;
|
2013-08-02 03:54:21 +02:00
|
|
|
else if(IsEqualIID(riid, &IID_IMarshal))
|
|
|
|
return IUnknown_QueryInterface(This->pUnkFTMarshal, riid, ppv);
|
2011-04-27 16:12:36 +02:00
|
|
|
if(*ppv){
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
WARN("Unknown interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static ULONG WINAPI AudioClient_AddRef(IAudioClient3 *iface)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
ULONG ref;
|
|
|
|
ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p) Refcount now %u\n", This, ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static ULONG WINAPI AudioClient_Release(IAudioClient3 *iface)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2011-04-27 16:12:36 +02:00
|
|
|
ULONG ref;
|
2014-06-27 18:04:23 +02:00
|
|
|
|
2011-04-27 16:12:36 +02:00
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
TRACE("(%p) Refcount now %u\n", This, ref);
|
|
|
|
if(!ref){
|
2014-06-27 18:04:23 +02:00
|
|
|
if(This->timer){
|
|
|
|
HANDLE event;
|
|
|
|
DWORD wait;
|
|
|
|
event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
|
|
|
wait = !DeleteTimerQueueTimer(g_timer_q, This->timer, event);
|
|
|
|
wait = wait && GetLastError() == ERROR_IO_PENDING;
|
|
|
|
if(event && wait)
|
|
|
|
WaitForSingleObject(event, INFINITE);
|
|
|
|
CloseHandle(event);
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
IAudioClient3_Stop(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
IMMDevice_Release(This->parent);
|
2013-08-02 03:54:21 +02:00
|
|
|
IUnknown_Release(This->pUnkFTMarshal);
|
2022-04-12 08:58:59 +02:00
|
|
|
if(This->session){
|
2011-05-02 15:21:49 +02:00
|
|
|
EnterCriticalSection(&g_sessions_lock);
|
|
|
|
list_remove(&This->entry);
|
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
|
|
|
}
|
2011-05-06 17:34:27 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->vols);
|
2022-04-06 08:55:57 +02:00
|
|
|
if(stream){
|
2022-04-12 08:59:03 +02:00
|
|
|
SIZE_T size;
|
2022-04-06 08:55:57 +02:00
|
|
|
close(stream->fd);
|
2022-04-12 08:59:03 +02:00
|
|
|
if(stream->local_buffer){
|
|
|
|
size = 0;
|
|
|
|
NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->local_buffer, &size, MEM_RELEASE);
|
|
|
|
}
|
|
|
|
if(stream->tmp_buffer){
|
|
|
|
size = 0;
|
|
|
|
NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer, &size, MEM_RELEASE);
|
|
|
|
}
|
2022-04-06 08:55:57 +02:00
|
|
|
CoTaskMemFree(stream->fmt);
|
2022-04-12 08:59:02 +02:00
|
|
|
pthread_mutex_destroy(&stream->lock);
|
2022-04-06 08:55:57 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, stream);
|
|
|
|
}
|
2011-04-27 16:12:36 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_fmt(const WAVEFORMATEX *fmt)
|
|
|
|
{
|
|
|
|
TRACE("wFormatTag: 0x%x (", fmt->wFormatTag);
|
|
|
|
switch(fmt->wFormatTag){
|
|
|
|
case WAVE_FORMAT_PCM:
|
|
|
|
TRACE("WAVE_FORMAT_PCM");
|
|
|
|
break;
|
|
|
|
case WAVE_FORMAT_IEEE_FLOAT:
|
|
|
|
TRACE("WAVE_FORMAT_IEEE_FLOAT");
|
|
|
|
break;
|
|
|
|
case WAVE_FORMAT_EXTENSIBLE:
|
|
|
|
TRACE("WAVE_FORMAT_EXTENSIBLE");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
TRACE("Unknown");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TRACE(")\n");
|
|
|
|
|
|
|
|
TRACE("nChannels: %u\n", fmt->nChannels);
|
|
|
|
TRACE("nSamplesPerSec: %u\n", fmt->nSamplesPerSec);
|
|
|
|
TRACE("nAvgBytesPerSec: %u\n", fmt->nAvgBytesPerSec);
|
|
|
|
TRACE("nBlockAlign: %u\n", fmt->nBlockAlign);
|
|
|
|
TRACE("wBitsPerSample: %u\n", fmt->wBitsPerSample);
|
|
|
|
TRACE("cbSize: %u\n", fmt->cbSize);
|
|
|
|
|
|
|
|
if(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE){
|
|
|
|
WAVEFORMATEXTENSIBLE *fmtex = (void*)fmt;
|
|
|
|
TRACE("dwChannelMask: %08x\n", fmtex->dwChannelMask);
|
|
|
|
TRACE("Samples: %04x\n", fmtex->Samples.wReserved);
|
|
|
|
TRACE("SubFormat: %s\n", wine_dbgstr_guid(&fmtex->SubFormat));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD get_channel_mask(unsigned int channels)
|
|
|
|
{
|
|
|
|
switch(channels){
|
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
case 1:
|
2011-09-02 22:49:20 +02:00
|
|
|
return KSAUDIO_SPEAKER_MONO;
|
2011-04-27 16:12:36 +02:00
|
|
|
case 2:
|
2011-09-02 22:49:20 +02:00
|
|
|
return KSAUDIO_SPEAKER_STEREO;
|
2011-04-27 16:12:36 +02:00
|
|
|
case 3:
|
2011-09-02 22:49:20 +02:00
|
|
|
return KSAUDIO_SPEAKER_STEREO | SPEAKER_LOW_FREQUENCY;
|
2011-04-27 16:12:36 +02:00
|
|
|
case 4:
|
2011-09-02 22:49:20 +02:00
|
|
|
return KSAUDIO_SPEAKER_QUAD; /* not _SURROUND */
|
2011-04-27 16:12:36 +02:00
|
|
|
case 5:
|
2011-09-02 22:49:20 +02:00
|
|
|
return KSAUDIO_SPEAKER_QUAD | SPEAKER_LOW_FREQUENCY;
|
2011-04-27 16:12:36 +02:00
|
|
|
case 6:
|
2011-09-02 22:49:20 +02:00
|
|
|
return KSAUDIO_SPEAKER_5POINT1; /* not 5POINT1_SURROUND */
|
2011-04-27 16:12:36 +02:00
|
|
|
case 7:
|
2011-09-02 22:49:20 +02:00
|
|
|
return KSAUDIO_SPEAKER_5POINT1 | SPEAKER_BACK_CENTER;
|
|
|
|
case 8:
|
2011-09-24 21:11:45 +02:00
|
|
|
return KSAUDIO_SPEAKER_7POINT1_SURROUND; /* Vista deprecates 7POINT1 */
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
FIXME("Unknown speaker configuration: %u\n", channels);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_oss_format(const WAVEFORMATEX *fmt)
|
|
|
|
{
|
|
|
|
WAVEFORMATEXTENSIBLE *fmtex = (WAVEFORMATEXTENSIBLE*)fmt;
|
|
|
|
|
|
|
|
if(fmt->wFormatTag == WAVE_FORMAT_PCM ||
|
|
|
|
(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
|
|
|
|
IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))){
|
|
|
|
switch(fmt->wBitsPerSample){
|
|
|
|
case 8:
|
|
|
|
return AFMT_U8;
|
|
|
|
case 16:
|
|
|
|
return AFMT_S16_LE;
|
|
|
|
case 24:
|
2011-05-08 02:04:06 +02:00
|
|
|
return AFMT_S24_LE;
|
2011-04-27 16:12:36 +02:00
|
|
|
case 32:
|
|
|
|
return AFMT_S32_LE;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-08 02:46:37 +02:00
|
|
|
#ifdef AFMT_FLOAT
|
2011-04-27 16:12:36 +02:00
|
|
|
if(fmt->wFormatTag == WAVE_FORMAT_IEEE_FLOAT ||
|
|
|
|
(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
|
|
|
|
IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))){
|
|
|
|
if(fmt->wBitsPerSample != 32)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return AFMT_FLOAT;
|
|
|
|
}
|
2011-05-08 02:46:37 +02:00
|
|
|
#endif
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WAVEFORMATEX *clone_format(const WAVEFORMATEX *fmt)
|
|
|
|
{
|
|
|
|
WAVEFORMATEX *ret;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
if(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
|
|
|
|
size = sizeof(WAVEFORMATEXTENSIBLE);
|
|
|
|
else
|
|
|
|
size = sizeof(WAVEFORMATEX);
|
|
|
|
|
|
|
|
ret = CoTaskMemAlloc(size);
|
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memcpy(ret, fmt, size);
|
|
|
|
|
|
|
|
ret->cbSize = size - sizeof(WAVEFORMATEX);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-03 17:28:11 +01:00
|
|
|
static HRESULT setup_oss_device(AUDCLNT_SHAREMODE mode, int fd,
|
|
|
|
const WAVEFORMATEX *fmt, WAVEFORMATEX **out)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
|
|
|
int tmp, oss_format;
|
|
|
|
double tenth;
|
|
|
|
HRESULT ret = S_OK;
|
|
|
|
WAVEFORMATEX *closest = NULL;
|
|
|
|
|
|
|
|
tmp = oss_format = get_oss_format(fmt);
|
|
|
|
if(oss_format < 0)
|
|
|
|
return AUDCLNT_E_UNSUPPORTED_FORMAT;
|
2011-09-28 20:32:03 +02:00
|
|
|
if(ioctl(fd, SNDCTL_DSP_SETFMT, &tmp) < 0){
|
2011-04-27 16:12:36 +02:00
|
|
|
WARN("SETFMT failed: %d (%s)\n", errno, strerror(errno));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
if(tmp != oss_format){
|
|
|
|
TRACE("Format unsupported by this OSS version: %x\n", oss_format);
|
|
|
|
return AUDCLNT_E_UNSUPPORTED_FORMAT;
|
|
|
|
}
|
|
|
|
|
2012-12-03 17:28:11 +01:00
|
|
|
if(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
|
|
|
|
(fmt->nAvgBytesPerSec == 0 ||
|
|
|
|
fmt->nBlockAlign == 0 ||
|
|
|
|
((WAVEFORMATEXTENSIBLE*)fmt)->Samples.wValidBitsPerSample > fmt->wBitsPerSample))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if(fmt->nChannels == 0)
|
|
|
|
return AUDCLNT_E_UNSUPPORTED_FORMAT;
|
|
|
|
|
2011-04-27 16:12:36 +02:00
|
|
|
closest = clone_format(fmt);
|
2011-08-02 21:49:12 +02:00
|
|
|
if(!closest)
|
|
|
|
return E_OUTOFMEMORY;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
tmp = fmt->nSamplesPerSec;
|
2011-09-28 20:32:03 +02:00
|
|
|
if(ioctl(fd, SNDCTL_DSP_SPEED, &tmp) < 0){
|
2011-04-27 16:12:36 +02:00
|
|
|
WARN("SPEED failed: %d (%s)\n", errno, strerror(errno));
|
|
|
|
CoTaskMemFree(closest);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
tenth = fmt->nSamplesPerSec * 0.1;
|
|
|
|
if(tmp > fmt->nSamplesPerSec + tenth || tmp < fmt->nSamplesPerSec - tenth){
|
|
|
|
ret = S_FALSE;
|
|
|
|
closest->nSamplesPerSec = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = fmt->nChannels;
|
2011-09-28 20:32:03 +02:00
|
|
|
if(ioctl(fd, SNDCTL_DSP_CHANNELS, &tmp) < 0){
|
2011-04-27 16:12:36 +02:00
|
|
|
WARN("CHANNELS failed: %d (%s)\n", errno, strerror(errno));
|
|
|
|
CoTaskMemFree(closest);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
if(tmp != fmt->nChannels){
|
|
|
|
ret = S_FALSE;
|
|
|
|
closest->nChannels = tmp;
|
|
|
|
}
|
|
|
|
|
2012-12-03 17:28:11 +01:00
|
|
|
if(closest->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
|
|
|
|
((WAVEFORMATEXTENSIBLE*)closest)->dwChannelMask = get_channel_mask(closest->nChannels);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2012-12-03 17:28:11 +01:00
|
|
|
if(fmt->nBlockAlign != fmt->nChannels * fmt->wBitsPerSample / 8 ||
|
|
|
|
fmt->nAvgBytesPerSec != fmt->nBlockAlign * fmt->nSamplesPerSec ||
|
|
|
|
(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
|
|
|
|
((WAVEFORMATEXTENSIBLE*)fmt)->Samples.wValidBitsPerSample < fmt->wBitsPerSample))
|
|
|
|
ret = S_FALSE;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2012-12-03 17:28:11 +01:00
|
|
|
if(mode == AUDCLNT_SHAREMODE_EXCLUSIVE &&
|
|
|
|
fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE){
|
|
|
|
if(((WAVEFORMATEXTENSIBLE*)fmt)->dwChannelMask == 0 ||
|
|
|
|
((WAVEFORMATEXTENSIBLE*)fmt)->dwChannelMask & SPEAKER_RESERVED)
|
2011-04-27 16:12:36 +02:00
|
|
|
ret = S_FALSE;
|
|
|
|
}
|
|
|
|
|
2011-09-08 15:21:52 +02:00
|
|
|
if(ret == S_FALSE && !out)
|
|
|
|
ret = AUDCLNT_E_UNSUPPORTED_FORMAT;
|
|
|
|
|
2011-08-02 21:49:12 +02:00
|
|
|
if(ret == S_FALSE && out){
|
2011-04-27 16:12:36 +02:00
|
|
|
closest->nBlockAlign =
|
|
|
|
closest->nChannels * closest->wBitsPerSample / 8;
|
|
|
|
closest->nAvgBytesPerSec =
|
|
|
|
closest->nBlockAlign * closest->nSamplesPerSec;
|
2012-12-03 17:28:11 +01:00
|
|
|
if(closest->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
|
|
|
|
((WAVEFORMATEXTENSIBLE*)closest)->Samples.wValidBitsPerSample = closest->wBitsPerSample;
|
2011-04-27 16:12:36 +02:00
|
|
|
*out = closest;
|
2011-08-02 21:49:12 +02:00
|
|
|
} else
|
|
|
|
CoTaskMemFree(closest);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("returning: %08x\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-06-06 15:49:26 +02:00
|
|
|
static void session_init_vols(AudioSession *session, UINT channels)
|
|
|
|
{
|
2011-06-13 22:23:09 +02:00
|
|
|
if(session->channel_count < channels){
|
|
|
|
UINT i;
|
2011-06-06 15:49:26 +02:00
|
|
|
|
2011-06-13 22:23:09 +02:00
|
|
|
if(session->channel_vols)
|
|
|
|
session->channel_vols = HeapReAlloc(GetProcessHeap(), 0,
|
|
|
|
session->channel_vols, sizeof(float) * channels);
|
|
|
|
else
|
|
|
|
session->channel_vols = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
sizeof(float) * channels);
|
|
|
|
if(!session->channel_vols)
|
|
|
|
return;
|
2011-06-06 15:49:26 +02:00
|
|
|
|
2011-06-13 22:23:09 +02:00
|
|
|
for(i = session->channel_count; i < channels; ++i)
|
|
|
|
session->channel_vols[i] = 1.f;
|
|
|
|
|
|
|
|
session->channel_count = channels;
|
|
|
|
}
|
2011-06-06 15:49:26 +02:00
|
|
|
}
|
|
|
|
|
2011-06-13 22:23:09 +02:00
|
|
|
static AudioSession *create_session(const GUID *guid, IMMDevice *device,
|
2011-06-06 15:49:26 +02:00
|
|
|
UINT num_channels)
|
2011-05-02 15:21:49 +02:00
|
|
|
{
|
|
|
|
AudioSession *ret;
|
|
|
|
|
|
|
|
ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(AudioSession));
|
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memcpy(&ret->guid, guid, sizeof(GUID));
|
|
|
|
|
2011-06-13 22:23:09 +02:00
|
|
|
ret->device = device;
|
2011-05-02 15:21:49 +02:00
|
|
|
|
|
|
|
list_init(&ret->clients);
|
|
|
|
|
|
|
|
list_add_head(&g_sessions, &ret->entry);
|
|
|
|
|
2011-06-13 22:23:09 +02:00
|
|
|
session_init_vols(ret, num_channels);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
|
|
|
ret->master_vol = 1.f;
|
|
|
|
|
2011-05-02 15:21:49 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-06-06 15:49:26 +02:00
|
|
|
/* if channels == 0, then this will return or create a session with
|
|
|
|
* matching dataflow and GUID. otherwise, channels must also match */
|
|
|
|
static HRESULT get_audio_session(const GUID *sessionguid,
|
2011-06-13 22:23:09 +02:00
|
|
|
IMMDevice *device, UINT channels, AudioSession **out)
|
2011-06-06 15:49:26 +02:00
|
|
|
{
|
|
|
|
AudioSession *session;
|
|
|
|
|
|
|
|
if(!sessionguid || IsEqualGUID(sessionguid, &GUID_NULL)){
|
2011-06-13 22:23:09 +02:00
|
|
|
*out = create_session(&GUID_NULL, device, channels);
|
2011-06-06 15:49:26 +02:00
|
|
|
if(!*out)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out = NULL;
|
|
|
|
LIST_FOR_EACH_ENTRY(session, &g_sessions, AudioSession, entry){
|
2011-06-13 22:23:09 +02:00
|
|
|
if(session->device == device &&
|
|
|
|
IsEqualGUID(sessionguid, &session->guid)){
|
|
|
|
session_init_vols(session, channels);
|
2011-06-06 15:49:26 +02:00
|
|
|
*out = session;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!*out){
|
2011-06-13 22:23:09 +02:00
|
|
|
*out = create_session(sessionguid, device, channels);
|
2011-06-06 15:49:26 +02:00
|
|
|
if(!*out)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface,
|
2011-04-27 16:12:36 +02:00
|
|
|
AUDCLNT_SHAREMODE mode, DWORD flags, REFERENCE_TIME duration,
|
|
|
|
REFERENCE_TIME period, const WAVEFORMATEX *fmt,
|
|
|
|
const GUID *sessionguid)
|
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2022-04-06 08:55:57 +02:00
|
|
|
struct oss_stream *stream;
|
|
|
|
oss_audioinfo ai;
|
2022-04-12 08:59:03 +02:00
|
|
|
SIZE_T size;
|
2012-01-25 18:14:03 +01:00
|
|
|
int i;
|
2011-04-27 16:12:36 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2011-05-02 21:03:15 +02:00
|
|
|
TRACE("(%p)->(%x, %x, %s, %s, %p, %s)\n", This, mode, flags,
|
|
|
|
wine_dbgstr_longlong(duration), wine_dbgstr_longlong(period), fmt, debugstr_guid(sessionguid));
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
if(!fmt)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
dump_fmt(fmt);
|
|
|
|
|
|
|
|
if(mode != AUDCLNT_SHAREMODE_SHARED && mode != AUDCLNT_SHAREMODE_EXCLUSIVE)
|
2019-10-24 18:28:43 +02:00
|
|
|
return E_INVALIDARG;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
if(flags & ~(AUDCLNT_STREAMFLAGS_CROSSPROCESS |
|
|
|
|
AUDCLNT_STREAMFLAGS_LOOPBACK |
|
|
|
|
AUDCLNT_STREAMFLAGS_EVENTCALLBACK |
|
|
|
|
AUDCLNT_STREAMFLAGS_NOPERSIST |
|
|
|
|
AUDCLNT_STREAMFLAGS_RATEADJUST |
|
|
|
|
AUDCLNT_SESSIONFLAGS_EXPIREWHENUNOWNED |
|
|
|
|
AUDCLNT_SESSIONFLAGS_DISPLAY_HIDE |
|
2020-07-10 21:13:44 +02:00
|
|
|
AUDCLNT_SESSIONFLAGS_DISPLAY_HIDEWHENEXPIRED |
|
|
|
|
AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY |
|
|
|
|
AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM)){
|
|
|
|
FIXME("Unknown flags: %08x\n", flags);
|
2011-04-27 16:12:36 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2011-12-15 23:07:41 +01:00
|
|
|
if(mode == AUDCLNT_SHAREMODE_SHARED){
|
|
|
|
period = DefaultPeriod;
|
|
|
|
if( duration < 3 * period)
|
|
|
|
duration = 3 * period;
|
|
|
|
}else{
|
|
|
|
if(!period)
|
|
|
|
period = DefaultPeriod; /* not minimum */
|
|
|
|
if(period < MinimumPeriod || period > 5000000)
|
|
|
|
return AUDCLNT_E_INVALID_DEVICE_PERIOD;
|
|
|
|
if(duration > 20000000) /* the smaller the period, the lower this limit */
|
|
|
|
return AUDCLNT_E_BUFFER_SIZE_ERROR;
|
|
|
|
if(flags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK){
|
|
|
|
if(duration != period)
|
|
|
|
return AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL;
|
|
|
|
FIXME("EXCLUSIVE mode with EVENTCALLBACK\n");
|
|
|
|
return AUDCLNT_E_DEVICE_IN_USE;
|
|
|
|
}else{
|
|
|
|
if( duration < 8 * period)
|
|
|
|
duration = 8 * period; /* may grow above 2s */
|
|
|
|
}
|
2011-08-23 21:16:24 +02:00
|
|
|
}
|
|
|
|
|
2021-12-02 13:02:39 +01:00
|
|
|
EnterCriticalSection(&g_sessions_lock);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-12 08:58:59 +02:00
|
|
|
if(This->stream){
|
2021-12-02 13:02:39 +01:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_ALREADY_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:57 +02:00
|
|
|
stream = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*This->stream));
|
|
|
|
if(!stream){
|
2021-12-02 13:02:39 +01:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2022-04-06 08:55:57 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
stream->flow = This->dataflow;
|
2022-04-12 08:59:02 +02:00
|
|
|
pthread_mutex_init(&stream->lock, NULL);
|
2022-04-06 08:55:57 +02:00
|
|
|
|
|
|
|
stream->fd = open_device(This->devnode, This->dataflow);
|
|
|
|
if(stream->fd < 0){
|
|
|
|
WARN("Unable to open device %s: %d (%s)\n", This->devnode, errno, strerror(errno));
|
|
|
|
hr = AUDCLNT_E_DEVICE_INVALIDATED;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
ai.dev = -1;
|
|
|
|
if(ioctl(stream->fd, SNDCTL_ENGINEINFO, &ai) < 0){
|
|
|
|
WARN("Unable to get audio info for device %s: %d (%s)\n", This->devnode, errno, strerror(errno));
|
|
|
|
hr = E_FAIL;
|
|
|
|
goto exit;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:57 +02:00
|
|
|
TRACE("OSS audioinfo:\n");
|
|
|
|
TRACE("devnode: %s\n", ai.devnode);
|
|
|
|
TRACE("name: %s\n", ai.name);
|
|
|
|
TRACE("busy: %x\n", ai.busy);
|
|
|
|
TRACE("caps: %x\n", ai.caps);
|
|
|
|
TRACE("iformats: %x\n", ai.iformats);
|
|
|
|
TRACE("oformats: %x\n", ai.oformats);
|
|
|
|
TRACE("enabled: %d\n", ai.enabled);
|
|
|
|
TRACE("min_rate: %d\n", ai.min_rate);
|
|
|
|
TRACE("max_rate: %d\n", ai.max_rate);
|
|
|
|
TRACE("min_channels: %d\n", ai.min_channels);
|
|
|
|
TRACE("max_channels: %d\n", ai.max_channels);
|
|
|
|
|
|
|
|
hr = setup_oss_device(mode, stream->fd, fmt, NULL);
|
|
|
|
if(FAILED(hr))
|
|
|
|
goto exit;
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->fmt = clone_format(fmt);
|
|
|
|
if(!stream->fmt){
|
2022-04-06 08:55:57 +02:00
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto exit;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->period_us = period / 10;
|
|
|
|
stream->period_frames = MulDiv(fmt->nSamplesPerSec, period, 10000000);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->bufsize_frames = MulDiv(duration, fmt->nSamplesPerSec, 10000000);
|
2014-05-19 15:59:23 +02:00
|
|
|
if(mode == AUDCLNT_SHAREMODE_EXCLUSIVE)
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->bufsize_frames -= stream->bufsize_frames % stream->period_frames;
|
2022-04-12 08:59:03 +02:00
|
|
|
size = stream->bufsize_frames * fmt->nBlockAlign;
|
|
|
|
if(NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&stream->local_buffer, 0, &size,
|
|
|
|
MEM_COMMIT, PAGE_READWRITE)){
|
2022-04-06 08:55:57 +02:00
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto exit;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:51 +02:00
|
|
|
This->channel_count = fmt->nChannels;
|
|
|
|
This->vols = HeapAlloc(GetProcessHeap(), 0, This->channel_count * sizeof(float));
|
2011-05-06 17:34:27 +02:00
|
|
|
if(!This->vols){
|
2022-04-06 08:55:57 +02:00
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto exit;
|
2011-05-06 17:34:27 +02:00
|
|
|
}
|
2022-04-06 08:55:51 +02:00
|
|
|
for(i = 0; i < This->channel_count; ++i)
|
2011-05-06 17:34:27 +02:00
|
|
|
This->vols[i] = 1.f;
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->share = mode;
|
|
|
|
stream->flags = flags;
|
|
|
|
stream->oss_bufsize_bytes = 0;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:51 +02:00
|
|
|
hr = get_audio_session(sessionguid, This->parent, This->channel_count,
|
2011-06-06 15:49:26 +02:00
|
|
|
&This->session);
|
2022-04-06 08:55:57 +02:00
|
|
|
|
|
|
|
exit:
|
2011-06-06 15:49:26 +02:00
|
|
|
if(FAILED(hr)){
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->vols);
|
|
|
|
This->vols = NULL;
|
2022-04-06 08:55:54 +02:00
|
|
|
CoTaskMemFree(stream->fmt);
|
2022-04-06 08:55:57 +02:00
|
|
|
if(stream->fd >= 0) close(stream->fd);
|
2022-04-12 08:59:03 +02:00
|
|
|
if(stream->local_buffer){
|
|
|
|
size = 0;
|
|
|
|
NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->local_buffer, &size, MEM_RELEASE);
|
|
|
|
}
|
2022-04-12 08:59:02 +02:00
|
|
|
pthread_mutex_destroy(&stream->lock);
|
2022-04-06 08:55:57 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, stream);
|
|
|
|
} else {
|
|
|
|
list_add_tail(&This->session->clients, &This->entry);
|
|
|
|
This->stream = stream;
|
2022-04-12 08:59:00 +02:00
|
|
|
set_stream_volumes(This);
|
2011-05-02 15:21:49 +02:00
|
|
|
}
|
|
|
|
|
2021-12-02 13:02:39 +01:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:57 +02:00
|
|
|
return hr;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_GetBufferSize(IAudioClient3 *iface,
|
2011-04-27 16:12:36 +02:00
|
|
|
UINT32 *frames)
|
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, frames);
|
|
|
|
|
|
|
|
if(!frames)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
if(!This->stream)
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_NOT_INITIALIZED;
|
2022-04-12 08:59:02 +02:00
|
|
|
|
|
|
|
oss_lock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
*frames = stream->bufsize_frames;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2012-01-25 18:14:03 +01:00
|
|
|
TRACE("buffer size: %u\n", *frames);
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_GetStreamLatency(IAudioClient3 *iface,
|
2011-04-27 16:12:36 +02:00
|
|
|
REFERENCE_TIME *latency)
|
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, latency);
|
|
|
|
|
|
|
|
if(!latency)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
if(!This->stream)
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_NOT_INITIALIZED;
|
2022-04-12 08:59:02 +02:00
|
|
|
|
|
|
|
oss_lock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2011-12-01 17:57:18 +01:00
|
|
|
/* pretend we process audio in Period chunks, so max latency includes
|
2012-01-05 22:19:35 +01:00
|
|
|
* the period time. Some native machines add .6666ms in shared mode. */
|
2022-04-06 08:55:54 +02:00
|
|
|
*latency = (REFERENCE_TIME)stream->period_us * 10 + 6666;
|
2011-12-01 17:57:18 +01:00
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_GetCurrentPadding(IAudioClient3 *iface,
|
2011-04-27 16:12:36 +02:00
|
|
|
UINT32 *numpad)
|
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, numpad);
|
|
|
|
|
|
|
|
if(!numpad)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
if(!This->stream)
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_NOT_INITIALIZED;
|
2022-04-12 08:59:02 +02:00
|
|
|
|
|
|
|
oss_lock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
*numpad = stream->held_frames;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2012-01-25 18:14:03 +01:00
|
|
|
TRACE("padding: %u\n", *numpad);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_IsFormatSupported(IAudioClient3 *iface,
|
2022-04-06 08:55:55 +02:00
|
|
|
AUDCLNT_SHAREMODE mode, const WAVEFORMATEX *fmt,
|
|
|
|
WAVEFORMATEX **out)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2022-04-06 08:55:55 +02:00
|
|
|
struct is_format_supported_params params;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:55 +02:00
|
|
|
TRACE("(%p)->(%x, %p, %p)\n", This, mode, fmt, out);
|
|
|
|
if(fmt) dump_fmt(fmt);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:55 +02:00
|
|
|
params.device = This->devnode;
|
|
|
|
params.flow = This->dataflow;
|
|
|
|
params.share = mode;
|
|
|
|
params.fmt_in = fmt;
|
|
|
|
params.fmt_out = NULL;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:55 +02:00
|
|
|
if(out){
|
|
|
|
*out = NULL;
|
|
|
|
if(mode == AUDCLNT_SHAREMODE_SHARED)
|
|
|
|
params.fmt_out = CoTaskMemAlloc(sizeof(*params.fmt_out));
|
2011-09-08 15:21:52 +02:00
|
|
|
}
|
2022-04-06 08:55:55 +02:00
|
|
|
OSS_CALL(is_format_supported, ¶ms);
|
2011-09-08 15:21:52 +02:00
|
|
|
|
2022-04-06 08:55:55 +02:00
|
|
|
if(params.result == S_FALSE)
|
|
|
|
*out = ¶ms.fmt_out->Format;
|
|
|
|
else
|
|
|
|
CoTaskMemFree(params.fmt_out);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:55 +02:00
|
|
|
return params.result;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_GetMixFormat(IAudioClient3 *iface,
|
2011-04-27 16:12:36 +02:00
|
|
|
WAVEFORMATEX **pwfx)
|
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2022-04-06 08:55:58 +02:00
|
|
|
struct get_mix_format_params params;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pwfx);
|
|
|
|
|
|
|
|
if(!pwfx)
|
|
|
|
return E_POINTER;
|
2011-06-05 10:32:10 +02:00
|
|
|
*pwfx = NULL;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:58 +02:00
|
|
|
params.device = This->devnode;
|
|
|
|
params.flow = This->dataflow;
|
|
|
|
params.fmt = CoTaskMemAlloc(sizeof(WAVEFORMATEXTENSIBLE));
|
|
|
|
if(!params.fmt)
|
2011-06-05 10:32:10 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2022-04-06 08:55:58 +02:00
|
|
|
OSS_CALL(get_mix_format, ¶ms);
|
2019-09-10 17:55:16 +02:00
|
|
|
|
2022-04-06 08:55:58 +02:00
|
|
|
if(SUCCEEDED(params.result)){
|
|
|
|
*pwfx = ¶ms.fmt->Format;
|
|
|
|
dump_fmt(*pwfx);
|
|
|
|
} else
|
|
|
|
CoTaskMemFree(params.fmt);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:58 +02:00
|
|
|
return params.result;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_GetDevicePeriod(IAudioClient3 *iface,
|
2011-04-27 16:12:36 +02:00
|
|
|
REFERENCE_TIME *defperiod, REFERENCE_TIME *minperiod)
|
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p, %p)\n", This, defperiod, minperiod);
|
|
|
|
|
|
|
|
if(!defperiod && !minperiod)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if(defperiod)
|
|
|
|
*defperiod = DefaultPeriod;
|
|
|
|
if(minperiod)
|
|
|
|
*minperiod = MinimumPeriod;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
static void silence_buffer(struct oss_stream *stream, BYTE *buffer, UINT32 frames)
|
2011-06-20 16:31:51 +02:00
|
|
|
{
|
2022-04-06 08:55:54 +02:00
|
|
|
WAVEFORMATEXTENSIBLE *fmtex = (WAVEFORMATEXTENSIBLE*)stream->fmt;
|
|
|
|
if((stream->fmt->wFormatTag == WAVE_FORMAT_PCM ||
|
|
|
|
(stream->fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
|
2013-11-12 17:17:21 +01:00
|
|
|
IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))) &&
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->fmt->wBitsPerSample == 8)
|
|
|
|
memset(buffer, 128, frames * stream->fmt->nBlockAlign);
|
2011-06-20 16:31:51 +02:00
|
|
|
else
|
2022-04-06 08:55:54 +02:00
|
|
|
memset(buffer, 0, frames * stream->fmt->nBlockAlign);
|
2011-06-20 16:31:51 +02:00
|
|
|
}
|
|
|
|
|
2022-04-12 08:59:00 +02:00
|
|
|
static void oss_write_data(struct oss_stream *stream)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
2011-10-11 22:31:28 +02:00
|
|
|
ssize_t written_bytes;
|
2014-12-17 16:28:13 +01:00
|
|
|
UINT32 written_frames, in_oss_frames, write_limit, max_period, write_offs_frames, new_frames;
|
2015-04-01 19:20:41 +02:00
|
|
|
SIZE_T to_write_frames, to_write_bytes, advanced;
|
2011-10-11 22:31:28 +02:00
|
|
|
audio_buf_info bi;
|
2014-12-17 16:28:13 +01:00
|
|
|
BYTE *buf;
|
2011-10-11 22:31:28 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(ioctl(stream->fd, SNDCTL_DSP_GETOSPACE, &bi) < 0){
|
2011-10-11 22:31:28 +02:00
|
|
|
WARN("GETOSPACE failed: %d (%s)\n", errno, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
max_period = max(bi.fragsize / stream->fmt->nBlockAlign, stream->period_frames);
|
2012-01-25 18:14:03 +01:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(bi.bytes > stream->oss_bufsize_bytes){
|
2012-01-25 18:14:03 +01:00
|
|
|
TRACE("New buffer size (%u) is larger than old buffer size (%u)\n",
|
2022-04-06 08:55:54 +02:00
|
|
|
bi.bytes, stream->oss_bufsize_bytes);
|
|
|
|
stream->oss_bufsize_bytes = bi.bytes;
|
2012-01-25 18:14:03 +01:00
|
|
|
in_oss_frames = 0;
|
2015-04-01 19:20:41 +02:00
|
|
|
}else
|
2022-04-06 08:55:54 +02:00
|
|
|
in_oss_frames = (stream->oss_bufsize_bytes - bi.bytes) / stream->fmt->nBlockAlign;
|
2012-01-25 18:14:03 +01:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(in_oss_frames > stream->in_oss_frames){
|
2015-04-06 15:21:48 +02:00
|
|
|
TRACE("Capping reported frames from %u to %u\n",
|
2022-04-06 08:55:54 +02:00
|
|
|
in_oss_frames, stream->in_oss_frames);
|
|
|
|
in_oss_frames = stream->in_oss_frames;
|
2015-04-06 15:21:48 +02:00
|
|
|
}
|
|
|
|
|
2012-01-25 18:14:03 +01:00
|
|
|
write_limit = 0;
|
|
|
|
while(write_limit + in_oss_frames < max_period * 3)
|
|
|
|
write_limit += max_period;
|
|
|
|
if(write_limit == 0)
|
|
|
|
return;
|
|
|
|
|
2014-12-17 16:28:13 +01:00
|
|
|
/* vvvvvv - in_oss_frames
|
|
|
|
* [--xxxxxxxxxx]
|
|
|
|
* [xxxxxxxxxx--]
|
|
|
|
* ^^^^^^^^^^ - held_frames
|
|
|
|
* ^ - lcl_offs_frames
|
|
|
|
*/
|
2022-04-06 08:55:54 +02:00
|
|
|
advanced = stream->in_oss_frames - in_oss_frames;
|
|
|
|
if(advanced > stream->held_frames)
|
|
|
|
advanced = stream->held_frames;
|
|
|
|
stream->lcl_offs_frames += advanced;
|
|
|
|
stream->lcl_offs_frames %= stream->bufsize_frames;
|
|
|
|
stream->held_frames -= advanced;
|
|
|
|
stream->in_oss_frames = in_oss_frames;
|
2015-04-01 19:20:41 +02:00
|
|
|
TRACE("advanced by %lu, lcl_offs: %u, held: %u, in_oss: %u\n",
|
2022-04-06 08:55:54 +02:00
|
|
|
advanced, stream->lcl_offs_frames, stream->held_frames, stream->in_oss_frames);
|
2014-12-17 16:28:13 +01:00
|
|
|
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->held_frames == stream->in_oss_frames)
|
2014-12-17 16:28:13 +01:00
|
|
|
return;
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
write_offs_frames = (stream->lcl_offs_frames + stream->in_oss_frames) % stream->bufsize_frames;
|
|
|
|
new_frames = stream->held_frames - stream->in_oss_frames;
|
2014-12-17 16:28:13 +01:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(write_offs_frames + new_frames > stream->bufsize_frames)
|
|
|
|
to_write_frames = stream->bufsize_frames - write_offs_frames;
|
2014-12-17 16:28:13 +01:00
|
|
|
else
|
|
|
|
to_write_frames = new_frames;
|
|
|
|
|
2012-01-25 18:14:03 +01:00
|
|
|
to_write_frames = min(to_write_frames, write_limit);
|
2022-04-06 08:55:54 +02:00
|
|
|
to_write_bytes = to_write_frames * stream->fmt->nBlockAlign;
|
2015-04-01 19:20:41 +02:00
|
|
|
TRACE("going to write %lu frames from %u (%lu of %u)\n", to_write_frames,
|
|
|
|
write_offs_frames, to_write_frames + write_offs_frames,
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->bufsize_frames);
|
2014-12-17 16:28:13 +01:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
buf = stream->local_buffer + write_offs_frames * stream->fmt->nBlockAlign;
|
2014-12-17 16:28:13 +01:00
|
|
|
|
2022-04-12 08:59:00 +02:00
|
|
|
if(stream->mute)
|
2022-04-06 08:55:54 +02:00
|
|
|
silence_buffer(stream, buf, to_write_frames);
|
2011-06-20 16:31:51 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
written_bytes = write(stream->fd, buf, to_write_bytes);
|
2011-10-11 22:31:28 +02:00
|
|
|
if(written_bytes < 0){
|
2011-09-21 10:42:16 +02:00
|
|
|
/* EAGAIN is OSS buffer full, log that too */
|
2011-04-27 16:12:36 +02:00
|
|
|
WARN("write failed: %d (%s)\n", errno, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
2022-04-06 08:55:54 +02:00
|
|
|
written_frames = written_bytes / stream->fmt->nBlockAlign;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->in_oss_frames += written_frames;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2011-10-11 22:31:28 +02:00
|
|
|
if(written_frames < to_write_frames){
|
2011-04-27 16:12:36 +02:00
|
|
|
/* OSS buffer probably full */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-17 16:28:13 +01:00
|
|
|
if(new_frames > written_frames && written_frames < write_limit){
|
2011-04-27 16:12:36 +02:00
|
|
|
/* wrapped and have some data back at the start to write */
|
2011-06-20 16:31:51 +02:00
|
|
|
|
2014-12-17 16:28:13 +01:00
|
|
|
to_write_frames = min(write_limit - written_frames, new_frames - written_frames);
|
2022-04-06 08:55:54 +02:00
|
|
|
to_write_bytes = to_write_frames * stream->fmt->nBlockAlign;
|
2011-10-11 22:31:28 +02:00
|
|
|
|
2022-04-12 08:59:00 +02:00
|
|
|
if(stream->mute)
|
2022-04-06 08:55:54 +02:00
|
|
|
silence_buffer(stream, stream->local_buffer, to_write_frames);
|
2011-06-20 16:31:51 +02:00
|
|
|
|
2015-04-01 19:20:41 +02:00
|
|
|
TRACE("wrapping to write %lu frames from beginning\n", to_write_frames);
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
written_bytes = write(stream->fd, stream->local_buffer, to_write_bytes);
|
2011-10-11 22:31:28 +02:00
|
|
|
if(written_bytes < 0){
|
2011-04-27 16:12:36 +02:00
|
|
|
WARN("write failed: %d (%s)\n", errno, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
2022-04-06 08:55:54 +02:00
|
|
|
written_frames = written_bytes / stream->fmt->nBlockAlign;
|
|
|
|
stream->in_oss_frames += written_frames;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
static void oss_read_data(struct oss_stream *stream)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
|
|
|
UINT64 pos, readable;
|
|
|
|
ssize_t nread;
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
pos = (stream->held_frames + stream->lcl_offs_frames) % stream->bufsize_frames;
|
|
|
|
readable = (stream->bufsize_frames - pos) * stream->fmt->nBlockAlign;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
nread = read(stream->fd, stream->local_buffer + pos * stream->fmt->nBlockAlign,
|
2011-04-27 16:12:36 +02:00
|
|
|
readable);
|
|
|
|
if(nread < 0){
|
|
|
|
WARN("read failed: %d (%s)\n", errno, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->held_frames += nread / stream->fmt->nBlockAlign;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->held_frames > stream->bufsize_frames){
|
2011-04-27 16:12:36 +02:00
|
|
|
WARN("Overflow of unread data\n");
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->lcl_offs_frames += stream->held_frames;
|
|
|
|
stream->lcl_offs_frames %= stream->bufsize_frames;
|
|
|
|
stream->held_frames = stream->bufsize_frames;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CALLBACK oss_period_callback(void *user, BOOLEAN timer)
|
|
|
|
{
|
|
|
|
ACImpl *This = user;
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_lock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->playing){
|
|
|
|
if(stream->flow == eRender && stream->held_frames)
|
2022-04-12 08:59:00 +02:00
|
|
|
oss_write_data(stream);
|
2022-04-06 08:55:54 +02:00
|
|
|
else if(stream->flow == eCapture)
|
|
|
|
oss_read_data(stream);
|
2012-02-23 16:44:20 +01:00
|
|
|
}
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->event)
|
|
|
|
SetEvent(stream->event);
|
2022-04-12 08:59:02 +02:00
|
|
|
|
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_Start(IAudioClient3 *iface)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
2022-04-12 08:59:01 +02:00
|
|
|
EnterCriticalSection(&g_sessions_lock);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-12 08:58:59 +02:00
|
|
|
if(!This->stream){
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_lock(stream);
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if((stream->flags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK) && !stream->event){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_EVENTHANDLE_NOT_SET;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->playing){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_NOT_STOPPED;
|
|
|
|
}
|
|
|
|
|
2014-06-27 18:04:23 +02:00
|
|
|
if(!This->timer){
|
|
|
|
if(!CreateTimerQueueTimer(&This->timer, g_timer_q,
|
2022-04-06 08:55:54 +02:00
|
|
|
oss_period_callback, This, 0, stream->period_us / 1000,
|
2014-06-27 18:04:23 +02:00
|
|
|
WT_EXECUTEINTIMERTHREAD))
|
|
|
|
ERR("Unable to create period timer: %u\n", GetLastError());
|
|
|
|
}
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->playing = TRUE;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_Stop(IAudioClient3 *iface)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
if(!This->stream)
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_NOT_INITIALIZED;
|
2022-04-12 08:59:02 +02:00
|
|
|
|
|
|
|
oss_lock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(!stream->playing){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->playing = FALSE;
|
|
|
|
stream->in_oss_frames = 0;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_Reset(IAudioClient3 *iface)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
if(!This->stream)
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_NOT_INITIALIZED;
|
2022-04-12 08:59:02 +02:00
|
|
|
|
|
|
|
oss_lock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->playing){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_NOT_STOPPED;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->getbuf_last){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-08-10 18:07:51 +02:00
|
|
|
return AUDCLNT_E_BUFFER_OPERATION_PENDING;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->flow == eRender){
|
|
|
|
stream->written_frames = 0;
|
|
|
|
stream->last_pos_frames = 0;
|
2012-01-12 23:08:47 +01:00
|
|
|
}else{
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->written_frames += stream->held_frames;
|
2012-01-12 23:08:47 +01:00
|
|
|
}
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->held_frames = 0;
|
|
|
|
stream->lcl_offs_frames = 0;
|
|
|
|
stream->in_oss_frames = 0;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_SetEventHandle(IAudioClient3 *iface,
|
2011-04-27 16:12:36 +02:00
|
|
|
HANDLE event)
|
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, event);
|
|
|
|
|
|
|
|
if(!event)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
if(!This->stream)
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_NOT_INITIALIZED;
|
2022-04-12 08:59:02 +02:00
|
|
|
|
|
|
|
oss_lock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(!(stream->flags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK)){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if (stream->event){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2012-12-09 21:39:16 +01:00
|
|
|
FIXME("called twice\n");
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_INVALID_NAME);
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->event = event;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid,
|
2011-04-27 16:12:36 +02:00
|
|
|
void **ppv)
|
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if(!ppv)
|
|
|
|
return E_POINTER;
|
|
|
|
*ppv = NULL;
|
|
|
|
|
2022-04-12 08:59:01 +02:00
|
|
|
EnterCriticalSection(&g_sessions_lock);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-12 08:58:59 +02:00
|
|
|
if(!This->stream){
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(IsEqualIID(riid, &IID_IAudioRenderClient)){
|
2011-05-02 15:21:49 +02:00
|
|
|
if(This->dataflow != eRender){
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_WRONG_ENDPOINT_TYPE;
|
2011-05-02 15:21:49 +02:00
|
|
|
}
|
2011-06-20 16:31:22 +02:00
|
|
|
IAudioRenderClient_AddRef(&This->IAudioRenderClient_iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
*ppv = &This->IAudioRenderClient_iface;
|
|
|
|
}else if(IsEqualIID(riid, &IID_IAudioCaptureClient)){
|
2011-05-02 15:21:49 +02:00
|
|
|
if(This->dataflow != eCapture){
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_WRONG_ENDPOINT_TYPE;
|
2011-05-02 15:21:49 +02:00
|
|
|
}
|
2011-06-20 16:31:22 +02:00
|
|
|
IAudioCaptureClient_AddRef(&This->IAudioCaptureClient_iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
*ppv = &This->IAudioCaptureClient_iface;
|
2011-05-06 17:34:27 +02:00
|
|
|
}else if(IsEqualIID(riid, &IID_IAudioClock)){
|
2011-06-20 16:31:22 +02:00
|
|
|
IAudioClock_AddRef(&This->IAudioClock_iface);
|
2011-05-06 17:34:27 +02:00
|
|
|
*ppv = &This->IAudioClock_iface;
|
|
|
|
}else if(IsEqualIID(riid, &IID_IAudioStreamVolume)){
|
2011-06-20 16:31:22 +02:00
|
|
|
IAudioStreamVolume_AddRef(&This->IAudioStreamVolume_iface);
|
2011-05-06 17:34:27 +02:00
|
|
|
*ppv = &This->IAudioStreamVolume_iface;
|
2011-04-27 16:12:36 +02:00
|
|
|
}else if(IsEqualIID(riid, &IID_IAudioSessionControl)){
|
2011-05-02 15:21:49 +02:00
|
|
|
if(!This->session_wrapper){
|
|
|
|
This->session_wrapper = AudioSessionWrapper_Create(This);
|
|
|
|
if(!This->session_wrapper){
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-05-02 15:21:49 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2011-06-20 16:31:22 +02:00
|
|
|
}else
|
|
|
|
IAudioSessionControl2_AddRef(&This->session_wrapper->IAudioSessionControl2_iface);
|
2011-05-02 15:21:49 +02:00
|
|
|
|
|
|
|
*ppv = &This->session_wrapper->IAudioSessionControl2_iface;
|
2011-05-06 17:34:27 +02:00
|
|
|
}else if(IsEqualIID(riid, &IID_IChannelAudioVolume)){
|
|
|
|
if(!This->session_wrapper){
|
|
|
|
This->session_wrapper = AudioSessionWrapper_Create(This);
|
|
|
|
if(!This->session_wrapper){
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-05-06 17:34:27 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2011-06-20 16:31:22 +02:00
|
|
|
}else
|
|
|
|
IChannelAudioVolume_AddRef(&This->session_wrapper->IChannelAudioVolume_iface);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
|
|
|
*ppv = &This->session_wrapper->IChannelAudioVolume_iface;
|
2011-04-27 16:12:36 +02:00
|
|
|
}else if(IsEqualIID(riid, &IID_ISimpleAudioVolume)){
|
2011-05-06 17:34:27 +02:00
|
|
|
if(!This->session_wrapper){
|
|
|
|
This->session_wrapper = AudioSessionWrapper_Create(This);
|
|
|
|
if(!This->session_wrapper){
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-05-06 17:34:27 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2011-06-20 16:31:22 +02:00
|
|
|
}else
|
|
|
|
ISimpleAudioVolume_AddRef(&This->session_wrapper->ISimpleAudioVolume_iface);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
|
|
|
*ppv = &This->session_wrapper->ISimpleAudioVolume_iface;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(*ppv){
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-04-27 16:12:36 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-05-02 15:21:49 +02:00
|
|
|
|
2011-04-27 16:12:36 +02:00
|
|
|
FIXME("stub %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_IsOffloadCapable(IAudioClient3 *iface,
|
2020-10-01 21:31:22 +02:00
|
|
|
AUDIO_STREAM_CATEGORY category, BOOL *offload_capable)
|
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2020-10-01 21:31:22 +02:00
|
|
|
|
2020-10-01 21:31:27 +02:00
|
|
|
TRACE("(%p)->(0x%x, %p)\n", This, category, offload_capable);
|
2020-10-01 21:31:22 +02:00
|
|
|
|
2020-10-01 21:31:27 +02:00
|
|
|
if(!offload_capable)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*offload_capable = FALSE;
|
|
|
|
|
|
|
|
return S_OK;
|
2020-10-01 21:31:22 +02:00
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_SetClientProperties(IAudioClient3 *iface,
|
2020-10-01 21:31:22 +02:00
|
|
|
const AudioClientProperties *prop)
|
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2020-11-20 15:58:28 +01:00
|
|
|
const Win8AudioClientProperties *legacy_prop = (const Win8AudioClientProperties *)prop;
|
2020-10-01 21:31:22 +02:00
|
|
|
|
2020-10-01 21:31:32 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, prop);
|
2020-10-01 21:31:22 +02:00
|
|
|
|
2020-11-20 15:58:28 +01:00
|
|
|
if(!legacy_prop)
|
2020-10-01 21:31:32 +02:00
|
|
|
return E_POINTER;
|
|
|
|
|
2020-11-20 15:58:28 +01:00
|
|
|
if(legacy_prop->cbSize == sizeof(AudioClientProperties)){
|
|
|
|
TRACE("{ bIsOffload: %u, eCategory: 0x%x, Options: 0x%x }\n",
|
|
|
|
legacy_prop->bIsOffload,
|
|
|
|
legacy_prop->eCategory,
|
|
|
|
prop->Options);
|
|
|
|
}else if(legacy_prop->cbSize == sizeof(Win8AudioClientProperties)){
|
|
|
|
TRACE("{ bIsOffload: %u, eCategory: 0x%x }\n",
|
|
|
|
legacy_prop->bIsOffload,
|
|
|
|
legacy_prop->eCategory);
|
|
|
|
}else{
|
|
|
|
WARN("Unsupported Size = %d\n", legacy_prop->cbSize);
|
2020-10-01 21:31:32 +02:00
|
|
|
return E_INVALIDARG;
|
2020-11-20 15:58:28 +01:00
|
|
|
}
|
2020-10-01 21:31:32 +02:00
|
|
|
|
|
|
|
|
2020-11-20 15:58:28 +01:00
|
|
|
if(legacy_prop->bIsOffload)
|
2020-10-01 21:31:32 +02:00
|
|
|
return AUDCLNT_E_ENDPOINT_OFFLOAD_NOT_CAPABLE;
|
|
|
|
|
|
|
|
return S_OK;
|
2020-10-01 21:31:22 +02:00
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_GetBufferSizeLimits(IAudioClient3 *iface,
|
2020-10-01 21:31:22 +02:00
|
|
|
const WAVEFORMATEX *format, BOOL event_driven, REFERENCE_TIME *min_duration,
|
|
|
|
REFERENCE_TIME *max_duration)
|
|
|
|
{
|
2020-10-01 22:23:05 +02:00
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
2020-10-01 21:31:22 +02:00
|
|
|
|
|
|
|
FIXME("(%p)->(%p, %u, %p, %p)\n", This, format, event_driven, min_duration, max_duration);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:23:05 +02:00
|
|
|
static HRESULT WINAPI AudioClient_GetSharedModeEnginePeriod(IAudioClient3 *iface,
|
|
|
|
const WAVEFORMATEX *format, UINT32 *default_period_frames, UINT32 *unit_period_frames,
|
|
|
|
UINT32 *min_period_frames, UINT32 *max_period_frames)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
|
|
|
|
|
|
|
FIXME("(%p)->(%p, %p, %p, %p, %p)\n", This, format, default_period_frames, unit_period_frames,
|
|
|
|
min_period_frames, max_period_frames);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioClient_GetCurrentSharedModeEnginePeriod(IAudioClient3 *iface,
|
|
|
|
WAVEFORMATEX **cur_format, UINT32 *cur_period_frames)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
|
|
|
|
|
|
|
FIXME("(%p)->(%p, %p)\n", This, cur_format, cur_period_frames);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioClient_InitializeSharedAudioStream(IAudioClient3 *iface,
|
|
|
|
DWORD flags, UINT32 period_frames, const WAVEFORMATEX *format,
|
|
|
|
const GUID *session_guid)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioClient3(iface);
|
|
|
|
|
|
|
|
FIXME("(%p)->(0x%x, %u, %p, %s)\n", This, flags, period_frames, format, debugstr_guid(session_guid));
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IAudioClient3Vtbl AudioClient3_Vtbl =
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
|
|
|
AudioClient_QueryInterface,
|
|
|
|
AudioClient_AddRef,
|
|
|
|
AudioClient_Release,
|
|
|
|
AudioClient_Initialize,
|
|
|
|
AudioClient_GetBufferSize,
|
|
|
|
AudioClient_GetStreamLatency,
|
|
|
|
AudioClient_GetCurrentPadding,
|
|
|
|
AudioClient_IsFormatSupported,
|
|
|
|
AudioClient_GetMixFormat,
|
|
|
|
AudioClient_GetDevicePeriod,
|
|
|
|
AudioClient_Start,
|
|
|
|
AudioClient_Stop,
|
|
|
|
AudioClient_Reset,
|
|
|
|
AudioClient_SetEventHandle,
|
2020-10-01 21:31:22 +02:00
|
|
|
AudioClient_GetService,
|
|
|
|
AudioClient_IsOffloadCapable,
|
|
|
|
AudioClient_SetClientProperties,
|
|
|
|
AudioClient_GetBufferSizeLimits,
|
2020-10-01 22:23:05 +02:00
|
|
|
AudioClient_GetSharedModeEnginePeriod,
|
|
|
|
AudioClient_GetCurrentSharedModeEnginePeriod,
|
|
|
|
AudioClient_InitializeSharedAudioStream,
|
2011-04-27 16:12:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioRenderClient_QueryInterface(
|
|
|
|
IAudioRenderClient *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2013-08-02 03:54:21 +02:00
|
|
|
ACImpl *This = impl_from_IAudioRenderClient(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if(!ppv)
|
|
|
|
return E_POINTER;
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IAudioRenderClient))
|
|
|
|
*ppv = iface;
|
2013-08-02 03:54:21 +02:00
|
|
|
else if(IsEqualIID(riid, &IID_IMarshal))
|
|
|
|
return IUnknown_QueryInterface(This->pUnkFTMarshal, riid, ppv);
|
2011-04-27 16:12:36 +02:00
|
|
|
if(*ppv){
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unknown interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AudioRenderClient_AddRef(IAudioRenderClient *iface)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioRenderClient(iface);
|
2020-10-01 22:23:05 +02:00
|
|
|
return AudioClient_AddRef(&This->IAudioClient3_iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AudioRenderClient_Release(IAudioRenderClient *iface)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioRenderClient(iface);
|
2020-10-01 22:23:05 +02:00
|
|
|
return AudioClient_Release(&This->IAudioClient3_iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
|
|
|
|
UINT32 frames, BYTE **data)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioRenderClient(iface);
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2012-05-22 20:11:09 +02:00
|
|
|
UINT32 write_pos;
|
2022-04-12 08:59:03 +02:00
|
|
|
SIZE_T size;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%u, %p)\n", This, frames, data);
|
|
|
|
|
|
|
|
if(!data)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2012-01-09 22:25:32 +01:00
|
|
|
*data = NULL;
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_lock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->getbuf_last){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_OUT_OF_ORDER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!frames){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->held_frames + frames > stream->bufsize_frames){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_BUFFER_TOO_LARGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
write_pos =
|
2022-04-06 08:55:54 +02:00
|
|
|
(stream->lcl_offs_frames + stream->held_frames) % stream->bufsize_frames;
|
|
|
|
if(write_pos + frames > stream->bufsize_frames){
|
|
|
|
if(stream->tmp_buffer_frames < frames){
|
2022-04-12 08:59:03 +02:00
|
|
|
if(stream->tmp_buffer){
|
|
|
|
size = 0;
|
|
|
|
NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer, &size, MEM_RELEASE);
|
|
|
|
stream->tmp_buffer = NULL;
|
|
|
|
}
|
|
|
|
size = frames * stream->fmt->nBlockAlign;
|
|
|
|
if(NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer, 0, &size,
|
|
|
|
MEM_COMMIT, PAGE_READWRITE)){
|
|
|
|
stream->tmp_buffer_frames = 0;
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->tmp_buffer_frames = frames;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
2022-04-06 08:55:54 +02:00
|
|
|
*data = stream->tmp_buffer;
|
|
|
|
stream->getbuf_last = -frames;
|
2011-04-27 16:12:36 +02:00
|
|
|
}else{
|
2022-04-06 08:55:54 +02:00
|
|
|
*data = stream->local_buffer + write_pos * stream->fmt->nBlockAlign;
|
|
|
|
stream->getbuf_last = frames;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
silence_buffer(stream, *data, frames);
|
2013-11-12 17:17:21 +01:00
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
static void oss_wrap_buffer(struct oss_stream *stream, BYTE *buffer, UINT32 written_frames)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
|
|
|
UINT32 write_offs_frames =
|
2022-04-06 08:55:54 +02:00
|
|
|
(stream->lcl_offs_frames + stream->held_frames) % stream->bufsize_frames;
|
|
|
|
UINT32 write_offs_bytes = write_offs_frames * stream->fmt->nBlockAlign;
|
|
|
|
UINT32 chunk_frames = stream->bufsize_frames - write_offs_frames;
|
|
|
|
UINT32 chunk_bytes = chunk_frames * stream->fmt->nBlockAlign;
|
|
|
|
UINT32 written_bytes = written_frames * stream->fmt->nBlockAlign;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2011-08-09 21:29:00 +02:00
|
|
|
if(written_bytes <= chunk_bytes){
|
2022-04-06 08:55:54 +02:00
|
|
|
memcpy(stream->local_buffer + write_offs_bytes, buffer, written_bytes);
|
2011-04-27 16:12:36 +02:00
|
|
|
}else{
|
2022-04-06 08:55:54 +02:00
|
|
|
memcpy(stream->local_buffer + write_offs_bytes, buffer, chunk_bytes);
|
|
|
|
memcpy(stream->local_buffer, buffer + chunk_bytes,
|
2011-04-27 16:12:36 +02:00
|
|
|
written_bytes - chunk_bytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
|
|
|
|
IAudioRenderClient *iface, UINT32 written_frames, DWORD flags)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioRenderClient(iface);
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2011-04-27 16:12:36 +02:00
|
|
|
BYTE *buffer;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%u, %x)\n", This, written_frames, flags);
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_lock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2012-01-09 22:25:32 +01:00
|
|
|
if(!written_frames){
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->getbuf_last = 0;
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2012-01-09 22:25:32 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(!stream->getbuf_last){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2012-01-09 22:25:32 +01:00
|
|
|
return AUDCLNT_E_OUT_OF_ORDER;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(written_frames > (stream->getbuf_last >= 0 ? stream->getbuf_last : -stream->getbuf_last)){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2012-01-09 22:25:32 +01:00
|
|
|
return AUDCLNT_E_INVALID_SIZE;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->getbuf_last >= 0)
|
|
|
|
buffer = stream->local_buffer + stream->fmt->nBlockAlign *
|
|
|
|
((stream->lcl_offs_frames + stream->held_frames) % stream->bufsize_frames);
|
2011-04-27 16:12:36 +02:00
|
|
|
else
|
2022-04-06 08:55:54 +02:00
|
|
|
buffer = stream->tmp_buffer;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2011-06-20 16:31:51 +02:00
|
|
|
if(flags & AUDCLNT_BUFFERFLAGS_SILENT)
|
2022-04-06 08:55:54 +02:00
|
|
|
silence_buffer(stream, buffer, written_frames);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->getbuf_last < 0)
|
|
|
|
oss_wrap_buffer(stream, buffer, written_frames);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->held_frames += written_frames;
|
|
|
|
stream->written_frames += written_frames;
|
|
|
|
stream->getbuf_last = 0;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IAudioRenderClientVtbl AudioRenderClient_Vtbl = {
|
|
|
|
AudioRenderClient_QueryInterface,
|
|
|
|
AudioRenderClient_AddRef,
|
|
|
|
AudioRenderClient_Release,
|
|
|
|
AudioRenderClient_GetBuffer,
|
|
|
|
AudioRenderClient_ReleaseBuffer
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioCaptureClient_QueryInterface(
|
|
|
|
IAudioCaptureClient *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2013-08-02 03:54:21 +02:00
|
|
|
ACImpl *This = impl_from_IAudioCaptureClient(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if(!ppv)
|
|
|
|
return E_POINTER;
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IAudioCaptureClient))
|
|
|
|
*ppv = iface;
|
2013-08-02 03:54:21 +02:00
|
|
|
else if(IsEqualIID(riid, &IID_IMarshal))
|
|
|
|
return IUnknown_QueryInterface(This->pUnkFTMarshal, riid, ppv);
|
2011-04-27 16:12:36 +02:00
|
|
|
if(*ppv){
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unknown interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AudioCaptureClient_AddRef(IAudioCaptureClient *iface)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioCaptureClient(iface);
|
2020-10-01 22:23:05 +02:00
|
|
|
return IAudioClient3_AddRef(&This->IAudioClient3_iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AudioCaptureClient_Release(IAudioCaptureClient *iface)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioCaptureClient(iface);
|
2020-10-01 22:23:05 +02:00
|
|
|
return IAudioClient3_Release(&This->IAudioClient3_iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioCaptureClient_GetBuffer(IAudioCaptureClient *iface,
|
|
|
|
BYTE **data, UINT32 *frames, DWORD *flags, UINT64 *devpos,
|
|
|
|
UINT64 *qpcpos)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioCaptureClient(iface);
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2022-04-12 08:59:03 +02:00
|
|
|
SIZE_T size;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p, %p, %p, %p, %p)\n", This, data, frames, flags,
|
|
|
|
devpos, qpcpos);
|
|
|
|
|
2019-10-24 18:28:35 +02:00
|
|
|
if(!data)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*data = NULL;
|
|
|
|
|
|
|
|
if(!frames || !flags)
|
2011-04-27 16:12:36 +02:00
|
|
|
return E_POINTER;
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_lock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->getbuf_last){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_OUT_OF_ORDER;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->held_frames < stream->period_frames){
|
2012-05-22 20:11:06 +02:00
|
|
|
*frames = 0;
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2012-05-22 20:11:06 +02:00
|
|
|
return AUDCLNT_S_BUFFER_EMPTY;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*flags = 0;
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
*frames = stream->period_frames;
|
2012-05-22 20:11:06 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->lcl_offs_frames + *frames > stream->bufsize_frames){
|
2011-04-27 16:12:36 +02:00
|
|
|
UINT32 chunk_bytes, offs_bytes, frames_bytes;
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->tmp_buffer_frames < *frames){
|
2022-04-12 08:59:03 +02:00
|
|
|
if(stream->tmp_buffer){
|
|
|
|
size = 0;
|
|
|
|
NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer, &size, MEM_RELEASE);
|
|
|
|
stream->tmp_buffer = NULL;
|
|
|
|
}
|
|
|
|
size = *frames * stream->fmt->nBlockAlign;
|
|
|
|
if(NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer, 0, &size,
|
|
|
|
MEM_COMMIT, PAGE_READWRITE)){
|
|
|
|
stream->tmp_buffer_frames = 0;
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->tmp_buffer_frames = *frames;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
*data = stream->tmp_buffer;
|
|
|
|
chunk_bytes = (stream->bufsize_frames - stream->lcl_offs_frames) *
|
|
|
|
stream->fmt->nBlockAlign;
|
|
|
|
offs_bytes = stream->lcl_offs_frames * stream->fmt->nBlockAlign;
|
|
|
|
frames_bytes = *frames * stream->fmt->nBlockAlign;
|
|
|
|
memcpy(stream->tmp_buffer, stream->local_buffer + offs_bytes, chunk_bytes);
|
|
|
|
memcpy(stream->tmp_buffer + chunk_bytes, stream->local_buffer,
|
2011-04-27 16:12:36 +02:00
|
|
|
frames_bytes - chunk_bytes);
|
|
|
|
}else
|
2022-04-06 08:55:54 +02:00
|
|
|
*data = stream->local_buffer +
|
|
|
|
stream->lcl_offs_frames * stream->fmt->nBlockAlign;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->getbuf_last = *frames;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2012-05-22 20:11:06 +02:00
|
|
|
if(devpos)
|
2022-04-06 08:55:54 +02:00
|
|
|
*devpos = stream->written_frames;
|
2012-05-22 20:11:06 +02:00
|
|
|
if(qpcpos){
|
|
|
|
LARGE_INTEGER stamp, freq;
|
|
|
|
QueryPerformanceCounter(&stamp);
|
|
|
|
QueryPerformanceFrequency(&freq);
|
|
|
|
*qpcpos = (stamp.QuadPart * (INT64)10000000) / freq.QuadPart;
|
|
|
|
}
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
return *frames ? S_OK : AUDCLNT_S_BUFFER_EMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioCaptureClient_ReleaseBuffer(
|
|
|
|
IAudioCaptureClient *iface, UINT32 done)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioCaptureClient(iface);
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%u)\n", This, done);
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_lock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2012-05-22 20:11:06 +02:00
|
|
|
if(!done){
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->getbuf_last = 0;
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2012-05-22 20:11:06 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(!stream->getbuf_last){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
return AUDCLNT_E_OUT_OF_ORDER;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->getbuf_last != done){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2012-05-22 20:11:06 +02:00
|
|
|
return AUDCLNT_E_INVALID_SIZE;
|
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->written_frames += done;
|
|
|
|
stream->held_frames -= done;
|
|
|
|
stream->lcl_offs_frames += done;
|
|
|
|
stream->lcl_offs_frames %= stream->bufsize_frames;
|
|
|
|
stream->getbuf_last = 0;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioCaptureClient_GetNextPacketSize(
|
|
|
|
IAudioCaptureClient *iface, UINT32 *frames)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioCaptureClient(iface);
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, frames);
|
|
|
|
|
2012-05-22 20:11:09 +02:00
|
|
|
if(!frames)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_lock(stream);
|
2012-05-22 20:11:09 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
*frames = stream->held_frames < stream->period_frames ? 0 : stream->period_frames;
|
2012-05-22 20:11:09 +02:00
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2012-05-22 20:11:09 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl =
|
|
|
|
{
|
|
|
|
AudioCaptureClient_QueryInterface,
|
|
|
|
AudioCaptureClient_AddRef,
|
|
|
|
AudioCaptureClient_Release,
|
|
|
|
AudioCaptureClient_GetBuffer,
|
|
|
|
AudioCaptureClient_ReleaseBuffer,
|
|
|
|
AudioCaptureClient_GetNextPacketSize
|
|
|
|
};
|
|
|
|
|
2011-05-06 17:34:25 +02:00
|
|
|
static HRESULT WINAPI AudioClock_QueryInterface(IAudioClock *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioClock(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if(!ppv)
|
|
|
|
return E_POINTER;
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IAudioClock))
|
|
|
|
*ppv = iface;
|
|
|
|
else if(IsEqualIID(riid, &IID_IAudioClock2))
|
|
|
|
*ppv = &This->IAudioClock2_iface;
|
|
|
|
if(*ppv){
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unknown interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AudioClock_AddRef(IAudioClock *iface)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioClock(iface);
|
2020-10-01 22:23:05 +02:00
|
|
|
return IAudioClient3_AddRef(&This->IAudioClient3_iface);
|
2011-05-06 17:34:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AudioClock_Release(IAudioClock *iface)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioClock(iface);
|
2020-10-01 22:23:05 +02:00
|
|
|
return IAudioClient3_Release(&This->IAudioClient3_iface);
|
2011-05-06 17:34:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioClock_GetFrequency(IAudioClock *iface, UINT64 *freq)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioClock(iface);
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2011-05-06 17:34:25 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, freq);
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->share == AUDCLNT_SHAREMODE_SHARED)
|
|
|
|
*freq = (UINT64)stream->fmt->nSamplesPerSec * stream->fmt->nBlockAlign;
|
2014-05-19 15:59:26 +02:00
|
|
|
else
|
2022-04-06 08:55:54 +02:00
|
|
|
*freq = stream->fmt->nSamplesPerSec;
|
2011-05-06 17:34:25 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioClock_GetPosition(IAudioClock *iface, UINT64 *pos,
|
|
|
|
UINT64 *qpctime)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioClock(iface);
|
2022-04-06 08:55:54 +02:00
|
|
|
struct oss_stream *stream = This->stream;
|
2011-05-06 17:34:25 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p, %p)\n", This, pos, qpctime);
|
|
|
|
|
|
|
|
if(!pos)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_lock(stream);
|
2011-05-06 17:34:25 +02:00
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->flow == eRender){
|
|
|
|
*pos = stream->written_frames - stream->held_frames;
|
|
|
|
if(*pos < stream->last_pos_frames)
|
|
|
|
*pos = stream->last_pos_frames;
|
|
|
|
}else if(stream->flow == eCapture){
|
2012-01-25 18:14:13 +01:00
|
|
|
audio_buf_info bi;
|
|
|
|
UINT32 held;
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
if(ioctl(stream->fd, SNDCTL_DSP_GETISPACE, &bi) < 0){
|
2012-01-25 18:14:13 +01:00
|
|
|
TRACE("GETISPACE failed: %d (%s)\n", errno, strerror(errno));
|
|
|
|
held = 0;
|
|
|
|
}else{
|
|
|
|
if(bi.bytes <= bi.fragsize)
|
|
|
|
held = 0;
|
|
|
|
else
|
2022-04-06 08:55:54 +02:00
|
|
|
held = bi.bytes / stream->fmt->nBlockAlign;
|
2012-01-25 18:14:13 +01:00
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
*pos = stream->written_frames + held;
|
2011-05-06 17:34:25 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 08:55:54 +02:00
|
|
|
stream->last_pos_frames = *pos;
|
2011-05-06 17:34:25 +02:00
|
|
|
|
2014-12-17 16:28:13 +01:00
|
|
|
TRACE("returning: %s\n", wine_dbgstr_longlong(*pos));
|
2022-04-06 08:55:54 +02:00
|
|
|
if(stream->share == AUDCLNT_SHAREMODE_SHARED)
|
|
|
|
*pos *= stream->fmt->nBlockAlign;
|
2014-05-19 15:59:26 +02:00
|
|
|
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(stream);
|
2011-05-06 17:34:25 +02:00
|
|
|
|
|
|
|
if(qpctime){
|
|
|
|
LARGE_INTEGER stamp, freq;
|
|
|
|
QueryPerformanceCounter(&stamp);
|
|
|
|
QueryPerformanceFrequency(&freq);
|
|
|
|
*qpctime = (stamp.QuadPart * (INT64)10000000) / freq.QuadPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioClock_GetCharacteristics(IAudioClock *iface,
|
|
|
|
DWORD *chars)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioClock(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, chars);
|
|
|
|
|
|
|
|
if(!chars)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*chars = AUDIOCLOCK_CHARACTERISTIC_FIXED_FREQ;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IAudioClockVtbl AudioClock_Vtbl =
|
|
|
|
{
|
|
|
|
AudioClock_QueryInterface,
|
|
|
|
AudioClock_AddRef,
|
|
|
|
AudioClock_Release,
|
|
|
|
AudioClock_GetFrequency,
|
|
|
|
AudioClock_GetPosition,
|
|
|
|
AudioClock_GetCharacteristics
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioClock2_QueryInterface(IAudioClock2 *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioClock2(iface);
|
|
|
|
return IAudioClock_QueryInterface(&This->IAudioClock_iface, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AudioClock2_AddRef(IAudioClock2 *iface)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioClock2(iface);
|
2020-10-01 22:23:05 +02:00
|
|
|
return IAudioClient3_AddRef(&This->IAudioClient3_iface);
|
2011-05-06 17:34:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AudioClock2_Release(IAudioClock2 *iface)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioClock2(iface);
|
2020-10-01 22:23:05 +02:00
|
|
|
return IAudioClient3_Release(&This->IAudioClient3_iface);
|
2011-05-06 17:34:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioClock2_GetDevicePosition(IAudioClock2 *iface,
|
|
|
|
UINT64 *pos, UINT64 *qpctime)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioClock2(iface);
|
|
|
|
|
|
|
|
FIXME("(%p)->(%p, %p)\n", This, pos, qpctime);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IAudioClock2Vtbl AudioClock2_Vtbl =
|
|
|
|
{
|
|
|
|
AudioClock2_QueryInterface,
|
|
|
|
AudioClock2_AddRef,
|
|
|
|
AudioClock2_Release,
|
|
|
|
AudioClock2_GetDevicePosition
|
|
|
|
};
|
|
|
|
|
2011-05-02 15:21:49 +02:00
|
|
|
static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client)
|
|
|
|
{
|
|
|
|
AudioSessionWrapper *ret;
|
|
|
|
|
|
|
|
ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
sizeof(AudioSessionWrapper));
|
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret->IAudioSessionControl2_iface.lpVtbl = &AudioSessionControl2_Vtbl;
|
2011-05-06 17:34:27 +02:00
|
|
|
ret->ISimpleAudioVolume_iface.lpVtbl = &SimpleAudioVolume_Vtbl;
|
|
|
|
ret->IChannelAudioVolume_iface.lpVtbl = &ChannelAudioVolume_Vtbl;
|
2011-05-02 15:21:49 +02:00
|
|
|
|
2011-06-20 16:31:22 +02:00
|
|
|
ret->ref = 1;
|
|
|
|
|
2011-05-02 15:21:49 +02:00
|
|
|
ret->client = client;
|
2011-06-06 15:49:26 +02:00
|
|
|
if(client){
|
|
|
|
ret->session = client->session;
|
2020-10-01 22:23:05 +02:00
|
|
|
AudioClient_AddRef(&client->IAudioClient3_iface);
|
2011-06-06 15:49:26 +02:00
|
|
|
}
|
2011-05-02 15:21:49 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-27 16:12:36 +02:00
|
|
|
static HRESULT WINAPI AudioSessionControl_QueryInterface(
|
|
|
|
IAudioSessionControl2 *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if(!ppv)
|
|
|
|
return E_POINTER;
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IAudioSessionControl) ||
|
|
|
|
IsEqualIID(riid, &IID_IAudioSessionControl2))
|
|
|
|
*ppv = iface;
|
|
|
|
if(*ppv){
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unknown interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AudioSessionControl_AddRef(IAudioSessionControl2 *iface)
|
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
|
|
|
ULONG ref;
|
|
|
|
ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p) Refcount now %u\n", This, ref);
|
|
|
|
return ref;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AudioSessionControl_Release(IAudioSessionControl2 *iface)
|
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
|
|
|
ULONG ref;
|
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
TRACE("(%p) Refcount now %u\n", This, ref);
|
|
|
|
if(!ref){
|
2011-06-06 15:49:26 +02:00
|
|
|
if(This->client){
|
2022-04-12 08:59:01 +02:00
|
|
|
EnterCriticalSection(&g_sessions_lock);
|
2011-06-06 15:49:26 +02:00
|
|
|
This->client->session_wrapper = NULL;
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2020-10-01 22:23:05 +02:00
|
|
|
AudioClient_Release(&This->client->IAudioClient3_iface);
|
2011-06-06 15:49:26 +02:00
|
|
|
}
|
2011-05-02 15:21:49 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
return ref;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface,
|
|
|
|
AudioSessionState *state)
|
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
|
|
|
ACImpl *client;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2011-05-02 15:21:49 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, state);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
if(!state)
|
2011-05-02 15:21:49 +02:00
|
|
|
return NULL_PTR_ERR;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2011-05-02 15:21:49 +02:00
|
|
|
EnterCriticalSection(&g_sessions_lock);
|
|
|
|
|
|
|
|
if(list_empty(&This->session->clients)){
|
|
|
|
*state = AudioSessionStateExpired;
|
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry){
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_lock(client->stream);
|
2022-04-06 08:55:54 +02:00
|
|
|
if(client->stream->playing){
|
2011-05-02 15:21:49 +02:00
|
|
|
*state = AudioSessionStateActive;
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(client->stream);
|
2011-05-02 15:21:49 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2022-04-12 08:59:02 +02:00
|
|
|
oss_unlock(client->stream);
|
2011-05-02 15:21:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
|
|
|
|
|
|
|
*state = AudioSessionStateInactive;
|
|
|
|
|
|
|
|
return S_OK;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioSessionControl_GetDisplayName(
|
|
|
|
IAudioSessionControl2 *iface, WCHAR **name)
|
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
FIXME("(%p)->(%p) - stub\n", This, name);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioSessionControl_SetDisplayName(
|
|
|
|
IAudioSessionControl2 *iface, const WCHAR *name, const GUID *session)
|
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
FIXME("(%p)->(%p, %s) - stub\n", This, name, debugstr_guid(session));
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioSessionControl_GetIconPath(
|
|
|
|
IAudioSessionControl2 *iface, WCHAR **path)
|
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
FIXME("(%p)->(%p) - stub\n", This, path);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioSessionControl_SetIconPath(
|
|
|
|
IAudioSessionControl2 *iface, const WCHAR *path, const GUID *session)
|
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
FIXME("(%p)->(%p, %s) - stub\n", This, path, debugstr_guid(session));
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioSessionControl_GetGroupingParam(
|
|
|
|
IAudioSessionControl2 *iface, GUID *group)
|
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
FIXME("(%p)->(%p) - stub\n", This, group);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioSessionControl_SetGroupingParam(
|
2011-07-04 11:18:28 +02:00
|
|
|
IAudioSessionControl2 *iface, const GUID *group, const GUID *session)
|
2011-04-27 16:12:36 +02:00
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
FIXME("(%p)->(%s, %s) - stub\n", This, debugstr_guid(group),
|
|
|
|
debugstr_guid(session));
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioSessionControl_RegisterAudioSessionNotification(
|
|
|
|
IAudioSessionControl2 *iface, IAudioSessionEvents *events)
|
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
FIXME("(%p)->(%p) - stub\n", This, events);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioSessionControl_UnregisterAudioSessionNotification(
|
|
|
|
IAudioSessionControl2 *iface, IAudioSessionEvents *events)
|
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
FIXME("(%p)->(%p) - stub\n", This, events);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioSessionControl_GetSessionIdentifier(
|
|
|
|
IAudioSessionControl2 *iface, WCHAR **id)
|
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
FIXME("(%p)->(%p) - stub\n", This, id);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioSessionControl_GetSessionInstanceIdentifier(
|
|
|
|
IAudioSessionControl2 *iface, WCHAR **id)
|
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
FIXME("(%p)->(%p) - stub\n", This, id);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioSessionControl_GetProcessId(
|
|
|
|
IAudioSessionControl2 *iface, DWORD *pid)
|
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pid);
|
|
|
|
|
|
|
|
if(!pid)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*pid = GetCurrentProcessId();
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioSessionControl_IsSystemSoundsSession(
|
|
|
|
IAudioSessionControl2 *iface)
|
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioSessionControl_SetDuckingPreference(
|
|
|
|
IAudioSessionControl2 *iface, BOOL optout)
|
|
|
|
{
|
2011-05-02 15:21:49 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, optout);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl =
|
|
|
|
{
|
|
|
|
AudioSessionControl_QueryInterface,
|
|
|
|
AudioSessionControl_AddRef,
|
|
|
|
AudioSessionControl_Release,
|
|
|
|
AudioSessionControl_GetState,
|
|
|
|
AudioSessionControl_GetDisplayName,
|
|
|
|
AudioSessionControl_SetDisplayName,
|
|
|
|
AudioSessionControl_GetIconPath,
|
|
|
|
AudioSessionControl_SetIconPath,
|
|
|
|
AudioSessionControl_GetGroupingParam,
|
|
|
|
AudioSessionControl_SetGroupingParam,
|
|
|
|
AudioSessionControl_RegisterAudioSessionNotification,
|
|
|
|
AudioSessionControl_UnregisterAudioSessionNotification,
|
|
|
|
AudioSessionControl_GetSessionIdentifier,
|
|
|
|
AudioSessionControl_GetSessionInstanceIdentifier,
|
|
|
|
AudioSessionControl_GetProcessId,
|
|
|
|
AudioSessionControl_IsSystemSoundsSession,
|
|
|
|
AudioSessionControl_SetDuckingPreference
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI SimpleAudioVolume_QueryInterface(
|
|
|
|
ISimpleAudioVolume *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if(!ppv)
|
|
|
|
return E_POINTER;
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_ISimpleAudioVolume))
|
|
|
|
*ppv = iface;
|
|
|
|
if(*ppv){
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unknown interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI SimpleAudioVolume_AddRef(ISimpleAudioVolume *iface)
|
|
|
|
{
|
2011-05-06 17:34:27 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
|
|
|
|
return AudioSessionControl_AddRef(&This->IAudioSessionControl2_iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI SimpleAudioVolume_Release(ISimpleAudioVolume *iface)
|
|
|
|
{
|
2011-05-06 17:34:27 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
|
|
|
|
return AudioSessionControl_Release(&This->IAudioSessionControl2_iface);
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SimpleAudioVolume_SetMasterVolume(
|
|
|
|
ISimpleAudioVolume *iface, float level, const GUID *context)
|
|
|
|
{
|
2011-05-06 17:34:27 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
|
|
|
|
AudioSession *session = This->session;
|
2022-04-12 08:59:00 +02:00
|
|
|
ACImpl *client;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2011-05-06 17:34:27 +02:00
|
|
|
TRACE("(%p)->(%f, %s)\n", session, level, wine_dbgstr_guid(context));
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2011-05-06 17:34:27 +02:00
|
|
|
if(level < 0.f || level > 1.f)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if(context)
|
|
|
|
FIXME("Notifications not supported yet\n");
|
|
|
|
|
2022-04-06 08:55:53 +02:00
|
|
|
EnterCriticalSection(&g_sessions_lock);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
|
|
|
session->master_vol = level;
|
|
|
|
|
2011-12-01 17:57:11 +01:00
|
|
|
TRACE("OSS doesn't support setting volume\n");
|
2022-04-12 08:59:00 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry)
|
|
|
|
set_stream_volumes(client);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
2022-04-06 08:55:53 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
2011-12-01 17:57:11 +01:00
|
|
|
return S_OK;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SimpleAudioVolume_GetMasterVolume(
|
|
|
|
ISimpleAudioVolume *iface, float *level)
|
|
|
|
{
|
2011-05-06 17:34:27 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
|
|
|
|
AudioSession *session = This->session;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2011-05-06 17:34:27 +02:00
|
|
|
TRACE("(%p)->(%p)\n", session, level);
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2011-05-06 17:34:27 +02:00
|
|
|
if(!level)
|
|
|
|
return NULL_PTR_ERR;
|
|
|
|
|
|
|
|
*level = session->master_vol;
|
|
|
|
|
|
|
|
return S_OK;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SimpleAudioVolume_SetMute(ISimpleAudioVolume *iface,
|
|
|
|
BOOL mute, const GUID *context)
|
|
|
|
{
|
2011-05-06 17:34:27 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
|
|
|
|
AudioSession *session = This->session;
|
2022-04-12 08:59:00 +02:00
|
|
|
ACImpl *client;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2016-08-07 22:11:53 +02:00
|
|
|
TRACE("(%p)->(%u, %s)\n", session, mute, debugstr_guid(context));
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2022-04-06 08:55:53 +02:00
|
|
|
EnterCriticalSection(&g_sessions_lock);
|
2011-06-20 16:31:51 +02:00
|
|
|
|
2012-01-25 18:14:03 +01:00
|
|
|
session->mute = mute;
|
2011-06-20 16:31:51 +02:00
|
|
|
|
2022-04-12 08:59:00 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry)
|
|
|
|
set_stream_volumes(client);
|
|
|
|
|
2022-04-06 08:55:53 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-06-20 16:31:51 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI SimpleAudioVolume_GetMute(ISimpleAudioVolume *iface,
|
|
|
|
BOOL *mute)
|
|
|
|
{
|
2011-05-06 17:34:27 +02:00
|
|
|
AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
|
|
|
|
AudioSession *session = This->session;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2011-06-20 16:31:51 +02:00
|
|
|
TRACE("(%p)->(%p)\n", session, mute);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
|
|
|
if(!mute)
|
|
|
|
return NULL_PTR_ERR;
|
2011-04-27 16:12:36 +02:00
|
|
|
|
2011-06-20 16:31:51 +02:00
|
|
|
*mute = This->session->mute;
|
|
|
|
|
|
|
|
return S_OK;
|
2011-04-27 16:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl =
|
|
|
|
{
|
|
|
|
SimpleAudioVolume_QueryInterface,
|
|
|
|
SimpleAudioVolume_AddRef,
|
|
|
|
SimpleAudioVolume_Release,
|
|
|
|
SimpleAudioVolume_SetMasterVolume,
|
|
|
|
SimpleAudioVolume_GetMasterVolume,
|
|
|
|
SimpleAudioVolume_SetMute,
|
|
|
|
SimpleAudioVolume_GetMute
|
|
|
|
};
|
2011-05-06 17:34:27 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI AudioStreamVolume_QueryInterface(
|
|
|
|
IAudioStreamVolume *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if(!ppv)
|
|
|
|
return E_POINTER;
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IAudioStreamVolume))
|
|
|
|
*ppv = iface;
|
|
|
|
if(*ppv){
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unknown interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AudioStreamVolume_AddRef(IAudioStreamVolume *iface)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioStreamVolume(iface);
|
2020-10-01 22:23:05 +02:00
|
|
|
return IAudioClient3_AddRef(&This->IAudioClient3_iface);
|
2011-05-06 17:34:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AudioStreamVolume_Release(IAudioStreamVolume *iface)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioStreamVolume(iface);
|
2020-10-01 22:23:05 +02:00
|
|
|
return IAudioClient3_Release(&This->IAudioClient3_iface);
|
2011-05-06 17:34:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioStreamVolume_GetChannelCount(
|
|
|
|
IAudioStreamVolume *iface, UINT32 *out)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioStreamVolume(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, out);
|
|
|
|
|
|
|
|
if(!out)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2022-04-06 08:55:51 +02:00
|
|
|
*out = This->channel_count;
|
2011-05-06 17:34:27 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioStreamVolume_SetChannelVolume(
|
|
|
|
IAudioStreamVolume *iface, UINT32 index, float level)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioStreamVolume(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d, %f)\n", This, index, level);
|
|
|
|
|
|
|
|
if(level < 0.f || level > 1.f)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2022-04-06 08:55:51 +02:00
|
|
|
if(index >= This->channel_count)
|
2011-05-06 17:34:27 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2022-04-12 08:59:01 +02:00
|
|
|
EnterCriticalSection(&g_sessions_lock);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
|
|
|
This->vols[index] = level;
|
|
|
|
|
2011-12-01 17:57:11 +01:00
|
|
|
TRACE("OSS doesn't support setting volume\n");
|
2022-04-12 08:59:00 +02:00
|
|
|
set_stream_volumes(This);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
2011-12-01 17:57:11 +01:00
|
|
|
return S_OK;
|
2011-05-06 17:34:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioStreamVolume_GetChannelVolume(
|
|
|
|
IAudioStreamVolume *iface, UINT32 index, float *level)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioStreamVolume(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d, %p)\n", This, index, level);
|
|
|
|
|
|
|
|
if(!level)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2022-04-06 08:55:51 +02:00
|
|
|
if(index >= This->channel_count)
|
2011-05-06 17:34:27 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*level = This->vols[index];
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioStreamVolume_SetAllVolumes(
|
|
|
|
IAudioStreamVolume *iface, UINT32 count, const float *levels)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioStreamVolume(iface);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d, %p)\n", This, count, levels);
|
|
|
|
|
|
|
|
if(!levels)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2022-04-06 08:55:51 +02:00
|
|
|
if(count != This->channel_count)
|
2011-05-06 17:34:27 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2022-04-12 08:59:01 +02:00
|
|
|
EnterCriticalSection(&g_sessions_lock);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
|
|
|
for(i = 0; i < count; ++i)
|
|
|
|
This->vols[i] = levels[i];
|
|
|
|
|
2011-12-01 17:57:11 +01:00
|
|
|
TRACE("OSS doesn't support setting volume\n");
|
2022-04-12 08:59:00 +02:00
|
|
|
set_stream_volumes(This);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
2011-12-01 17:57:11 +01:00
|
|
|
return S_OK;
|
2011-05-06 17:34:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AudioStreamVolume_GetAllVolumes(
|
|
|
|
IAudioStreamVolume *iface, UINT32 count, float *levels)
|
|
|
|
{
|
|
|
|
ACImpl *This = impl_from_IAudioStreamVolume(iface);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d, %p)\n", This, count, levels);
|
|
|
|
|
|
|
|
if(!levels)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2022-04-06 08:55:51 +02:00
|
|
|
if(count != This->channel_count)
|
2011-05-06 17:34:27 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2022-04-12 08:59:01 +02:00
|
|
|
EnterCriticalSection(&g_sessions_lock);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
|
|
|
for(i = 0; i < count; ++i)
|
|
|
|
levels[i] = This->vols[i];
|
|
|
|
|
2022-04-12 08:59:01 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl =
|
|
|
|
{
|
|
|
|
AudioStreamVolume_QueryInterface,
|
|
|
|
AudioStreamVolume_AddRef,
|
|
|
|
AudioStreamVolume_Release,
|
|
|
|
AudioStreamVolume_GetChannelCount,
|
|
|
|
AudioStreamVolume_SetChannelVolume,
|
|
|
|
AudioStreamVolume_GetChannelVolume,
|
|
|
|
AudioStreamVolume_SetAllVolumes,
|
|
|
|
AudioStreamVolume_GetAllVolumes
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI ChannelAudioVolume_QueryInterface(
|
|
|
|
IChannelAudioVolume *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if(!ppv)
|
|
|
|
return E_POINTER;
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IChannelAudioVolume))
|
|
|
|
*ppv = iface;
|
|
|
|
if(*ppv){
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unknown interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ChannelAudioVolume_AddRef(IChannelAudioVolume *iface)
|
|
|
|
{
|
|
|
|
AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
|
|
|
|
return AudioSessionControl_AddRef(&This->IAudioSessionControl2_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ChannelAudioVolume_Release(IChannelAudioVolume *iface)
|
|
|
|
{
|
|
|
|
AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
|
|
|
|
return AudioSessionControl_Release(&This->IAudioSessionControl2_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ChannelAudioVolume_GetChannelCount(
|
|
|
|
IChannelAudioVolume *iface, UINT32 *out)
|
|
|
|
{
|
|
|
|
AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
|
|
|
|
AudioSession *session = This->session;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", session, out);
|
|
|
|
|
|
|
|
if(!out)
|
|
|
|
return NULL_PTR_ERR;
|
|
|
|
|
|
|
|
*out = session->channel_count;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ChannelAudioVolume_SetChannelVolume(
|
|
|
|
IChannelAudioVolume *iface, UINT32 index, float level,
|
|
|
|
const GUID *context)
|
|
|
|
{
|
|
|
|
AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
|
|
|
|
AudioSession *session = This->session;
|
2022-04-12 08:59:00 +02:00
|
|
|
ACImpl *client;
|
2011-05-06 17:34:27 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d, %f, %s)\n", session, index, level,
|
|
|
|
wine_dbgstr_guid(context));
|
|
|
|
|
|
|
|
if(level < 0.f || level > 1.f)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if(index >= session->channel_count)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if(context)
|
|
|
|
FIXME("Notifications not supported yet\n");
|
|
|
|
|
2022-04-06 08:55:53 +02:00
|
|
|
EnterCriticalSection(&g_sessions_lock);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
|
|
|
session->channel_vols[index] = level;
|
|
|
|
|
2011-12-01 17:57:11 +01:00
|
|
|
TRACE("OSS doesn't support setting volume\n");
|
2022-04-12 08:59:00 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry)
|
|
|
|
set_stream_volumes(client);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
2022-04-06 08:55:53 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
2011-12-01 17:57:11 +01:00
|
|
|
return S_OK;
|
2011-05-06 17:34:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ChannelAudioVolume_GetChannelVolume(
|
|
|
|
IChannelAudioVolume *iface, UINT32 index, float *level)
|
|
|
|
{
|
|
|
|
AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
|
|
|
|
AudioSession *session = This->session;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d, %p)\n", session, index, level);
|
|
|
|
|
|
|
|
if(!level)
|
|
|
|
return NULL_PTR_ERR;
|
|
|
|
|
|
|
|
if(index >= session->channel_count)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*level = session->channel_vols[index];
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ChannelAudioVolume_SetAllVolumes(
|
|
|
|
IChannelAudioVolume *iface, UINT32 count, const float *levels,
|
|
|
|
const GUID *context)
|
|
|
|
{
|
|
|
|
AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
|
|
|
|
AudioSession *session = This->session;
|
2022-04-12 08:59:00 +02:00
|
|
|
ACImpl *client;
|
2011-05-06 17:34:27 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d, %p, %s)\n", session, count, levels,
|
|
|
|
wine_dbgstr_guid(context));
|
|
|
|
|
|
|
|
if(!levels)
|
|
|
|
return NULL_PTR_ERR;
|
|
|
|
|
|
|
|
if(count != session->channel_count)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if(context)
|
|
|
|
FIXME("Notifications not supported yet\n");
|
|
|
|
|
2022-04-06 08:55:53 +02:00
|
|
|
EnterCriticalSection(&g_sessions_lock);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
|
|
|
for(i = 0; i < count; ++i)
|
|
|
|
session->channel_vols[i] = levels[i];
|
|
|
|
|
2011-12-01 17:57:11 +01:00
|
|
|
TRACE("OSS doesn't support setting volume\n");
|
2022-04-12 08:59:00 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry)
|
|
|
|
set_stream_volumes(client);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
2022-04-06 08:55:53 +02:00
|
|
|
LeaveCriticalSection(&g_sessions_lock);
|
2011-05-06 17:34:27 +02:00
|
|
|
|
2011-12-01 17:57:11 +01:00
|
|
|
return S_OK;
|
2011-05-06 17:34:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ChannelAudioVolume_GetAllVolumes(
|
|
|
|
IChannelAudioVolume *iface, UINT32 count, float *levels)
|
|
|
|
{
|
|
|
|
AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface);
|
|
|
|
AudioSession *session = This->session;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d, %p)\n", session, count, levels);
|
|
|
|
|
|
|
|
if(!levels)
|
|
|
|
return NULL_PTR_ERR;
|
|
|
|
|
|
|
|
if(count != session->channel_count)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
for(i = 0; i < count; ++i)
|
|
|
|
levels[i] = session->channel_vols[i];
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl =
|
|
|
|
{
|
|
|
|
ChannelAudioVolume_QueryInterface,
|
|
|
|
ChannelAudioVolume_AddRef,
|
|
|
|
ChannelAudioVolume_Release,
|
|
|
|
ChannelAudioVolume_GetChannelCount,
|
|
|
|
ChannelAudioVolume_SetChannelVolume,
|
|
|
|
ChannelAudioVolume_GetChannelVolume,
|
|
|
|
ChannelAudioVolume_SetAllVolumes,
|
|
|
|
ChannelAudioVolume_GetAllVolumes
|
|
|
|
};
|
2011-06-06 15:49:26 +02:00
|
|
|
|
2011-07-11 11:52:43 +02:00
|
|
|
static HRESULT WINAPI AudioSessionManager_QueryInterface(IAudioSessionManager2 *iface,
|
2011-06-06 15:49:26 +02:00
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if(!ppv)
|
|
|
|
return E_POINTER;
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IAudioSessionManager) ||
|
|
|
|
IsEqualIID(riid, &IID_IAudioSessionManager2))
|
|
|
|
*ppv = iface;
|
|
|
|
if(*ppv){
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unknown interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2011-07-11 11:52:43 +02:00
|
|
|
static ULONG WINAPI AudioSessionManager_AddRef(IAudioSessionManager2 *iface)
|
2011-06-06 15:49:26 +02:00
|
|
|
{
|
|
|
|
SessionMgr *This = impl_from_IAudioSessionManager2(iface);
|
|
|
|
ULONG ref;
|
|
|
|
ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p) Refcount now %u\n", This, ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2011-07-11 11:52:43 +02:00
|
|
|
static ULONG WINAPI AudioSessionManager_Release(IAudioSessionManager2 *iface)
|
2011-06-06 15:49:26 +02:00
|
|
|
{
|
|
|
|
SessionMgr *This = impl_from_IAudioSessionManager2(iface);
|
|
|
|
ULONG ref;
|
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
TRACE("(%p) Refcount now %u\n", This, ref);
|
|
|
|
if(!ref)
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2011-07-11 11:52:43 +02:00
|
|
|
static HRESULT WINAPI AudioSessionManager_GetAudioSessionControl(
|
2011-06-06 15:49:26 +02:00
|
|
|
IAudioSessionManager2 *iface, const GUID *session_guid, DWORD flags,
|
|
|
|
IAudioSessionControl **out)
|
|
|
|
{
|
|
|
|
SessionMgr *This = impl_from_IAudioSessionManager2(iface);
|
|
|
|
AudioSession *session;
|
|
|
|
AudioSessionWrapper *wrapper;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s, %x, %p)\n", This, debugstr_guid(session_guid),
|
|
|
|
flags, out);
|
|
|
|
|
2011-06-13 22:23:09 +02:00
|
|
|
hr = get_audio_session(session_guid, This->device, 0, &session);
|
2011-06-06 15:49:26 +02:00
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
wrapper = AudioSessionWrapper_Create(NULL);
|
|
|
|
if(!wrapper)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
wrapper->session = session;
|
|
|
|
|
|
|
|
*out = (IAudioSessionControl*)&wrapper->IAudioSessionControl2_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-11 11:52:43 +02:00
|
|
|
static HRESULT WINAPI AudioSessionManager_GetSimpleAudioVolume(
|
2011-06-06 15:49:26 +02:00
|
|
|
IAudioSessionManager2 *iface, const GUID *session_guid, DWORD flags,
|
|
|
|
ISimpleAudioVolume **out)
|
|
|
|
{
|
|
|
|
SessionMgr *This = impl_from_IAudioSessionManager2(iface);
|
|
|
|
AudioSession *session;
|
|
|
|
AudioSessionWrapper *wrapper;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s, %x, %p)\n", This, debugstr_guid(session_guid),
|
|
|
|
flags, out);
|
|
|
|
|
2011-06-13 22:23:09 +02:00
|
|
|
hr = get_audio_session(session_guid, This->device, 0, &session);
|
2011-06-06 15:49:26 +02:00
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
wrapper = AudioSessionWrapper_Create(NULL);
|
|
|
|
if(!wrapper)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
wrapper->session = session;
|
|
|
|
|
|
|
|
*out = &wrapper->ISimpleAudioVolume_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-11 11:52:43 +02:00
|
|
|
static HRESULT WINAPI AudioSessionManager_GetSessionEnumerator(
|
2011-06-06 15:49:26 +02:00
|
|
|
IAudioSessionManager2 *iface, IAudioSessionEnumerator **out)
|
|
|
|
{
|
|
|
|
SessionMgr *This = impl_from_IAudioSessionManager2(iface);
|
|
|
|
FIXME("(%p)->(%p) - stub\n", This, out);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2011-07-11 11:52:43 +02:00
|
|
|
static HRESULT WINAPI AudioSessionManager_RegisterSessionNotification(
|
2011-06-06 15:49:26 +02:00
|
|
|
IAudioSessionManager2 *iface, IAudioSessionNotification *notification)
|
|
|
|
{
|
|
|
|
SessionMgr *This = impl_from_IAudioSessionManager2(iface);
|
|
|
|
FIXME("(%p)->(%p) - stub\n", This, notification);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2011-07-11 11:52:43 +02:00
|
|
|
static HRESULT WINAPI AudioSessionManager_UnregisterSessionNotification(
|
2011-06-06 15:49:26 +02:00
|
|
|
IAudioSessionManager2 *iface, IAudioSessionNotification *notification)
|
|
|
|
{
|
|
|
|
SessionMgr *This = impl_from_IAudioSessionManager2(iface);
|
|
|
|
FIXME("(%p)->(%p) - stub\n", This, notification);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2011-07-11 11:52:43 +02:00
|
|
|
static HRESULT WINAPI AudioSessionManager_RegisterDuckNotification(
|
2011-06-06 15:49:26 +02:00
|
|
|
IAudioSessionManager2 *iface, const WCHAR *session_id,
|
|
|
|
IAudioVolumeDuckNotification *notification)
|
|
|
|
{
|
|
|
|
SessionMgr *This = impl_from_IAudioSessionManager2(iface);
|
|
|
|
FIXME("(%p)->(%p) - stub\n", This, notification);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2011-07-11 11:52:43 +02:00
|
|
|
static HRESULT WINAPI AudioSessionManager_UnregisterDuckNotification(
|
2011-06-06 15:49:26 +02:00
|
|
|
IAudioSessionManager2 *iface,
|
|
|
|
IAudioVolumeDuckNotification *notification)
|
|
|
|
{
|
|
|
|
SessionMgr *This = impl_from_IAudioSessionManager2(iface);
|
|
|
|
FIXME("(%p)->(%p) - stub\n", This, notification);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl =
|
|
|
|
{
|
|
|
|
AudioSessionManager_QueryInterface,
|
|
|
|
AudioSessionManager_AddRef,
|
|
|
|
AudioSessionManager_Release,
|
|
|
|
AudioSessionManager_GetAudioSessionControl,
|
|
|
|
AudioSessionManager_GetSimpleAudioVolume,
|
|
|
|
AudioSessionManager_GetSessionEnumerator,
|
|
|
|
AudioSessionManager_RegisterSessionNotification,
|
|
|
|
AudioSessionManager_UnregisterSessionNotification,
|
|
|
|
AudioSessionManager_RegisterDuckNotification,
|
|
|
|
AudioSessionManager_UnregisterDuckNotification
|
|
|
|
};
|
|
|
|
|
2011-06-13 22:23:09 +02:00
|
|
|
HRESULT WINAPI AUDDRV_GetAudioSessionManager(IMMDevice *device,
|
2011-06-06 15:49:26 +02:00
|
|
|
IAudioSessionManager2 **out)
|
|
|
|
{
|
|
|
|
SessionMgr *This;
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SessionMgr));
|
2011-06-13 22:23:09 +02:00
|
|
|
if(!This)
|
2011-06-06 15:49:26 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->IAudioSessionManager2_iface.lpVtbl = &AudioSessionManager2_Vtbl;
|
2011-06-13 22:23:09 +02:00
|
|
|
This->device = device;
|
2011-06-06 15:49:26 +02:00
|
|
|
This->ref = 1;
|
|
|
|
|
|
|
|
*out = &This->IAudioSessionManager2_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|