ReactOS 0.4.17-dev-806-gffa4164
audiosrv.h File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <malloc.h>
#include <dbt.h>
#include <audiosrv/audiosrv.h>
Include dependency graph for audiosrv.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define AUDIOSRV_PRIVATE_H
 
#define DestroyDeviceDescriptor(descriptor)   free(descriptor)
 

Functions

VOIDCreateDeviceDescriptor (WCHAR *path, BOOL is_enabled)
 
BOOL AppendAudioDeviceToList (PnP_AudioDevice *device)
 
BOOL CreateAudioDeviceList (DWORD max_size)
 
VOID DestroyAudioDeviceList (VOID)
 
BOOL ProcessExistingDevices (VOID)
 
DWORD ProcessDeviceArrival (DEV_BROADCAST_DEVICEINTERFACE *device)
 
BOOL RegisterForDeviceNotifications (VOID)
 
VOID UnregisterDeviceNotifications (VOID)
 
DWORD HandleDeviceEvent (DWORD dwEventType, LPVOID lpEventData)
 
BOOL StartSystemAudioServices (VOID)
 

Variables

SERVICE_STATUS_HANDLE service_status_handle
 

Macro Definition Documentation

◆ AUDIOSRV_PRIVATE_H

#define AUDIOSRV_PRIVATE_H

Definition at line 20 of file audiosrv.h.

◆ DestroyDeviceDescriptor

#define DestroyDeviceDescriptor (   descriptor)    free(descriptor)

Definition at line 30 of file audiosrv.h.

Function Documentation

◆ AppendAudioDeviceToList()

BOOL AppendAudioDeviceToList ( PnP_AudioDevice device)

Definition at line 57 of file pnp_list_manager.c.

58{
59 int device_info_size;
60
61 /* Figure out the actual structure size */
62 device_info_size = sizeof(PnP_AudioDevice);
63 device_info_size += WideStringSize(device->path);
64
66
67 /* We DON'T want to overshoot the end of the buffer! */
68 if (audio_device_list->size + device_info_size > audio_device_list->max_size)
69 {
70 /*DPRINT("failed, max_size would be exceeded\n");*/
71
73
74 return FALSE;
75 }
76
77 /* Commit the device descriptor to the list */
79 device,
80 device_info_size);
81
82 /* Update the header */
84 audio_device_list->size += device_info_size;
85
87
88 DPRINT("Device added to list\n");
89
90 return TRUE;
91}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
VOID LockAudioDeviceList(VOID)
Definition: pnp_list_lock.c:45
VOID UnlockAudioDeviceList(VOID)
Definition: pnp_list_lock.c:52
static PnP_AudioHeader * audio_device_list
#define WideStringSize(str)
Definition: audiosrv.h:45
#define DPRINT
Definition: sndvol32.h:73
DWORD max_size
Definition: audiosrv.h:36
DWORD device_count
Definition: audiosrv.h:37
Definition: devices.h:37

Referenced by InitializeFakeDevice(), ProcessDeviceArrival(), and ProcessExistingDevices().

◆ CreateAudioDeviceList()

BOOL CreateAudioDeviceList ( DWORD  max_size)

Definition at line 94 of file pnp_list_manager.c.

95{
97 {
98 /*DPRINT("Failed\n");*/
99 return FALSE;
100 }
101
102 /* Preliminary locking - the list memory will likely be a big
103 buffer of gibberish at this point so we don't want anyone
104 turning up before we're ready... */
106
107 DPRINT("Creating file mapping\n");
108 /* Expose our device list to the world */
110 NULL,
112 0,
113 max_size,
115 if (!device_list_file)
116 {
117 DPRINT("Creation of audio device list failed (err %d)\n", GetLastError());
118
121
122 return FALSE;
123 }
124
125 DPRINT("Mapping view of file\n");
126 /* Of course, we'll need to access the list ourselves */
129 0,
130 0,
131 max_size);
133 {
134 DPRINT("MapViewOfFile FAILED (err %d)\n", GetLastError());
135
138
141
142 return FALSE;
143 }
144
145 /* Clear the mem to avoid any random stray data */
147
148 /* Don't want devices to overwrite the list! */
152
154
155 DPRINT("Device list created\n");
156
157 return TRUE;
158}
static INT max_size
Definition: history.c:51
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:744
#define MapViewOfFile
Definition: compat.h:745
#define PAGE_READWRITE
Definition: nt_native.h:1307
BOOL InitializeAudioDeviceListLock(VOID)
Definition: pnp_list_lock.c:15
VOID KillAudioDeviceListLock(VOID)
Definition: pnp_list_lock.c:38
static HANDLE device_list_file
#define AUDIO_LIST_NAME
Definition: audiosrv.h:22
#define memset(x, y, z)
Definition: compat.h:39
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FILE_MAP_WRITE
Definition: winbase.h:157

Referenced by ServiceMain().

◆ CreateDeviceDescriptor()

VOID * CreateDeviceDescriptor ( WCHAR path,
BOOL  is_enabled 
)

Definition at line 18 of file pnp_list_manager.c.

19{
21
23 int size = sizeof(PnP_AudioDevice) + path_length;
24
26 if (! device)
27 {
28 DPRINT("Failed to malloc device descriptor\n");
29 return NULL;
30 }
31
32 device->enabled = is_enabled;
34
35 return device;
36}
static long path_length
Definition: maze.c:116
#define malloc
Definition: debug_ros.c:4
GLsizeiptr size
Definition: glext.h:5919

Referenced by InitializeFakeDevice(), ProcessDeviceArrival(), and ProcessExistingDevices().

◆ DestroyAudioDeviceList()

VOID DestroyAudioDeviceList ( VOID  )

Definition at line 161 of file pnp_list_manager.c.

162{
163 DPRINT("Destroying device list\n");
164
166
167 /*DPRINT("Unmapping view\n");*/
170
171 /*DPRINT("Closing memory mapped file\n");*/
174
176
177 /*DPRINT("Killing devlist lock\n");*/
179}
#define UnmapViewOfFile
Definition: compat.h:746

Referenced by ServiceControlHandler(), and ServiceMain().

◆ HandleDeviceEvent()

DWORD HandleDeviceEvent ( DWORD  dwEventType,
LPVOID  lpEventData 
)

Definition at line 192 of file pnp.c.

195{
196 switch (dwEventType)
197 {
199 {
200 DEV_BROADCAST_DEVICEINTERFACE* incoming_device =
201 (DEV_BROADCAST_DEVICEINTERFACE*)lpEventData;
202
203 return ProcessDeviceArrival(incoming_device);
204 }
205
207 {
208 DEV_BROADCAST_DEVICEINTERFACE* removed_device =
209 (DEV_BROADCAST_DEVICEINTERFACE*)lpEventData;
210
211 return ProcessDeviceRemovalComplete(removed_device);
212 }
213
214 default:
215 {
216 break;
217 }
218 }
219
220 return NO_ERROR;
221}
DWORD ProcessDeviceRemovalComplete(DEV_BROADCAST_DEVICEINTERFACE *device)
Definition: pnp.c:132
DWORD ProcessDeviceArrival(DEV_BROADCAST_DEVICEINTERFACE *device)
Definition: pnp.c:118
#define DBT_DEVICEARRIVAL
Definition: dbt.h:12
#define DBT_DEVICEREMOVECOMPLETE
Definition: dbt.h:16
#define NO_ERROR
Definition: dderror.h:5

Referenced by ServiceControlHandler().

◆ ProcessDeviceArrival()

DWORD ProcessDeviceArrival ( DEV_BROADCAST_DEVICEINTERFACE device)

Definition at line 118 of file pnp.c.

119{
120 PnP_AudioDevice* list_node;
121 list_node = CreateDeviceDescriptor(device->dbcc_name, TRUE);
122 AppendAudioDeviceToList(list_node);
123 DestroyDeviceDescriptor(list_node);
124
127
128 return NO_ERROR;
129}
BOOL AppendAudioDeviceToList(PnP_AudioDevice *device)
#define DestroyDeviceDescriptor(descriptor)
Definition: audiosrv.h:30
VOID * CreateDeviceDescriptor(WCHAR *path, BOOL is_enabled)
static UINT uWinMMDeviceChange
Definition: pnp.c:22
#define BSF_POSTMESSAGE
Definition: dbt.h:58
#define BSM_APPLICATIONS
Definition: dbt.h:48
#define BSM_ALLDESKTOPS
Definition: dbt.h:49
unsigned long DWORD
Definition: ntddk_ex.h:95
LONG WINAPI BroadcastSystemMessageW(DWORD dwFlags, LPDWORD lpdwRecipients, UINT uiMessage, WPARAM wParam, LPARAM lParam)
Definition: message.c:3408

Referenced by HandleDeviceEvent().

◆ ProcessExistingDevices()

BOOL ProcessExistingDevices ( VOID  )

Definition at line 30 of file pnp.c.

31{
32 SP_DEVICE_INTERFACE_DATA interface_data;
33 SP_DEVINFO_DATA device_data;
35 HDEVINFO dev_info;
37 int index = 0;
38
39 const GUID category_guid = {STATIC_KSCATEGORY_AUDIO};
40
41 dev_info = SetupDiGetClassDevsExW(&category_guid,
42 NULL,
43 NULL,
45 NULL,
46 NULL,
47 NULL);
48
49 interface_data.cbSize = sizeof(interface_data);
50 interface_data.Reserved = 0;
51
52 /* Enumerate the devices within the category */
53 index = 0;
54
56 + (MAX_PATH * sizeof(WCHAR));
57
60 0,
61 length);
62
63 if ( ! detail_data )
64 {
65 DPRINT("failed to allocate detail_data\n");
66 return TRUE;
67 }
68
69 while (
71 NULL,
72 &category_guid,
73 index,
74 &interface_data) )
75 {
76 PnP_AudioDevice* list_node;
77
79
80 /* NOTE: We don't actually use device_data... */
82 device_data.cbSize = sizeof(device_data);
83 device_data.Reserved = 0;
85 &interface_data,
87 length,
88 NULL,
89 &device_data);
90
91 list_node = CreateDeviceDescriptor(detail_data->DevicePath, TRUE);
92 AppendAudioDeviceToList(list_node);
93 DestroyDeviceDescriptor(list_node);
94
95 /* TODO: Cleanup the device we enumerated? */
96
97 index ++;
98 };
99
101
103
104 uWinMMDeviceChange = RegisterWindowMessageW(L"winmm_devicechange");
105
106 if (uWinMMDeviceChange == 0)
107 DPRINT1("Failed to register winmm_devicechange window message: GetLastError %u\n", GetLastError());
108
109 return TRUE;
110}
#define DPRINT1
Definition: precomp.h:8
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, CONST GUID *InterfaceClassGuid, DWORD MemberIndex, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
Definition: devinst.c:3069
HDEVINFO WINAPI SetupDiGetClassDevsExW(CONST GUID *class, PCWSTR enumstr, HWND parent, DWORD flags, HDEVINFO deviceset, PCWSTR machine, PVOID reserved)
Definition: devinst.c:2548
BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(HDEVINFO DeviceInfoSet, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData, DWORD DeviceInterfaceDetailDataSize, PDWORD RequiredSize, PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:3300
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:3182
#define L(x)
Definition: resources.c:13
GLuint index
Definition: glext.h:6031
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define STATIC_KSCATEGORY_AUDIO
Definition: ksmedia.h:169
#define ZeroMemory
Definition: minwinbase.h:31
short WCHAR
Definition: pedump.c:58
SP_DEVICE_INTERFACE_DETAIL_DATA_A SP_DEVICE_INTERFACE_DETAIL_DATA
Definition: setupapi.h:1152
#define DIGCF_DEVICEINTERFACE
Definition: setupapi.h:177
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W SP_DEVICE_INTERFACE_DETAIL_DATA_W
#define DIGCF_PRESENT
Definition: setupapi.h:174
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W * PSP_DEVICE_INTERFACE_DETAIL_DATA_W
ULONG_PTR Reserved
Definition: setupapi.h:841
UINT WINAPI RegisterWindowMessageW(_In_ LPCWSTR)

Referenced by ServiceMain().

◆ RegisterForDeviceNotifications()

BOOL RegisterForDeviceNotifications ( VOID  )

Definition at line 147 of file pnp.c.

148{
149 DEV_BROADCAST_DEVICEINTERFACE notification_filter;
150
151 const GUID wdmaud_guid = {STATIC_KSCATEGORY_AUDIO};
152
153 ZeroMemory(&notification_filter, sizeof(notification_filter));
154 notification_filter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
155 notification_filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
156 notification_filter.dbcc_classguid = wdmaud_guid;
157
160 &notification_filter,
161 DEVICE_NOTIFY_SERVICE_HANDLE);
163 {
164 DPRINT("failed with error %d\n", GetLastError());
165 }
166
167 return ( device_notification_handle != NULL );
168}
SERVICE_STATUS_HANDLE service_status_handle
Definition: main.c:13
static HDEVNOTIFY device_notification_handle
Definition: pnp.c:21
#define DBT_DEVTYP_DEVICEINTERFACE
Definition: dbt.h:24
DEV_BROADCAST_DEVICEINTERFACE_A DEV_BROADCAST_DEVICEINTERFACE
Definition: dbt.h:137
HDEVNOTIFY WINAPI RegisterDeviceNotificationW(HANDLE hRecipient, LPVOID NotificationFilter, DWORD Flags)
Definition: resources.c:111

Referenced by ServiceMain().

◆ StartSystemAudioServices()

BOOL StartSystemAudioServices ( VOID  )

Definition at line 72 of file services.c.

73{
74 SC_HANDLE hSCManager;
75
76 DPRINT("Starting system audio services\n");
77
79 if (!hSCManager)
80 {
81 DPRINT("Failed to open service manager %x\n", GetLastError());
82 return FALSE;
83 }
84
85 DPRINT("Starting sysaudio service\n");
86 StartAudioService(hSCManager, L"sysaudio", 20);
87 DPRINT("Starting wdmaud service\n");
88 StartAudioService(hSCManager, L"wdmaud", 20);
89
91 return TRUE;
92}
BOOL StartAudioService(SC_HANDLE hSCManager, LPWSTR ServiceName, ULONG RetryCount)
Definition: services.c:43
#define OpenSCManager
Definition: winsvc.h:581
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
SC_HANDLE hSCManager
Definition: sc.c:12
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580

Referenced by ServiceMain().

◆ UnregisterDeviceNotifications()

VOID UnregisterDeviceNotifications ( VOID  )

Definition at line 177 of file pnp.c.

178{
180 {
183 }
184}
BOOL WINAPI UnregisterDeviceNotification(HDEVNOTIFY Handle)
Definition: resources.c:162

Referenced by ServiceControlHandler(), and ServiceMain().

Variable Documentation

◆ service_status_handle

SERVICE_STATUS_HANDLE service_status_handle
extern

Definition at line 13 of file main.c.

Referenced by RegisterForDeviceNotifications(), ServiceControlHandler(), and ServiceMain().