ReactOS  0.4.14-dev-52-g6116262
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)
 
void logmsg (char *string,...)
 

Variables

SERVICE_STATUS_HANDLE service_status_handle
 

Macro Definition Documentation

◆ AUDIOSRV_PRIVATE_H

#define AUDIOSRV_PRIVATE_H

Definition at line 21 of file audiosrv.h.

◆ DestroyDeviceDescriptor

#define DestroyDeviceDescriptor (   descriptor)    free(descriptor)

Definition at line 31 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 /*
68  printf("list size is %d\n", audio_device_list->size);
69  printf("device info size is %d bytes\n", device_info_size);
70 */
71 
72  /* We DON'T want to overshoot the end of the buffer! */
73  if (audio_device_list->size + device_info_size > audio_device_list->max_size)
74  {
75  /*printf("max_size would be exceeded! Failing...\n");*/
76 
78 
79  return FALSE;
80  }
81 
82  /* Commit the device descriptor to the list */
84  device,
85  device_info_size);
86 
87  /* Update the header */
89  audio_device_list->size += device_info_size;
90 
92 
93  logmsg("Device added to list\n");
94 
95  return TRUE;
96 }
VOID UnlockAudioDeviceList(VOID)
Definition: pnp_list_lock.c:53
#define TRUE
Definition: types.h:120
Definition: devices.h:37
DWORD device_count
Definition: audiosrv.h:37
void logmsg(char *string,...)
Definition: debug.c:7
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
DWORD max_size
Definition: audiosrv.h:36
static PnP_AudioHeader * audio_device_list
#define WideStringSize(str)
Definition: audiosrv.h:45
VOID LockAudioDeviceList(VOID)
Definition: pnp_list_lock.c:46

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

◆ CreateAudioDeviceList()

BOOL CreateAudioDeviceList ( DWORD  max_size)

Definition at line 99 of file pnp_list_manager.c.

100 {
101 /* printf("Initializing memory device list lock\n");*/
102 
104  {
105  /*printf("Failed!\n");*/
106  return FALSE;
107  }
108 
109  /* Preliminary locking - the list memory will likely be a big
110  buffer of gibberish at this point so we don't want anyone
111  turning up before we're ready... */
113 
114  logmsg("Creating file mapping\n");
115  /* Expose our device list to the world */
117  NULL,
119  0,
120  max_size,
122  if (!device_list_file)
123  {
124  logmsg("Creation of audio device list failed (err %d)\n", GetLastError());
125 
128 
129  return FALSE;
130  }
131 
132  logmsg("Mapping view of file\n");
133  /* Of course, we'll need to access the list ourselves */
136  0,
137  0,
138  max_size);
139  if (!audio_device_list)
140  {
141  logmsg("MapViewOfFile FAILED (err %d)\n", GetLastError());
142 
145 
148 
149  return FALSE;
150  }
151 
152  /* Clear the mem to avoid any random stray data */
154 
155  /* Don't want devices to overwrite the list! */
159 
161 
162  logmsg("Device list created\n");
163 
164  return TRUE;
165 }
VOID UnlockAudioDeviceList(VOID)
Definition: pnp_list_lock.c:53
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define MapViewOfFile
Definition: compat.h:402
#define AUDIO_LIST_NAME
Definition: audiosrv.h:22
BOOL InitializeAudioDeviceListLock(VOID)
Definition: pnp_list_lock.c:16
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static HANDLE device_list_file
static INT max_size
Definition: history.c:51
smooth NULL
Definition: ftsmooth.c:416
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:401
#define FILE_MAP_WRITE
Definition: winbase.h:154
DWORD device_count
Definition: audiosrv.h:37
void logmsg(char *string,...)
Definition: debug.c:7
VOID KillAudioDeviceListLock(VOID)
Definition: pnp_list_lock.c:39
DWORD max_size
Definition: audiosrv.h:36
static PnP_AudioHeader * audio_device_list
#define memset(x, y, z)
Definition: compat.h:39
VOID LockAudioDeviceList(VOID)
Definition: pnp_list_lock.c:46
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by ServiceMain().

◆ CreateDeviceDescriptor()

VOID* CreateDeviceDescriptor ( WCHAR path,
BOOL  is_enabled 
)

Definition at line 16 of file pnp_list_manager.c.

17 {
19 
21  int size = sizeof(PnP_AudioDevice) + path_length;
22 
23 /* printf("path_length %d, total %d\n", path_length, size);*/
24 
25  device = malloc(size);
26  if (! device)
27  {
28  logmsg("Failed to create a device descriptor (malloc fail)\n");
29  return NULL;
30  }
31 
32  device->enabled = is_enabled;
33  memcpy(device->path, path, path_length);
34 
35  return device;
36 }
Definition: devices.h:37
smooth NULL
Definition: ftsmooth.c:416
GLsizeiptr size
Definition: glext.h:5919
static long path_length
Definition: maze.c:116
void logmsg(char *string,...)
Definition: debug.c:7
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: services.c:325
#define malloc
Definition: debug_ros.c:4
#define WideStringSize(str)
Definition: audiosrv.h:45

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

◆ DestroyAudioDeviceList()

VOID DestroyAudioDeviceList ( VOID  )

Definition at line 168 of file pnp_list_manager.c.

169 {
170  logmsg("Destroying device list\n");
171 
173 
174  /*printf("Unmapping view\n");*/
177 
178  /*printf("Closing memory mapped file\n");*/
181 
183 
184  /*printf("Killing devlist lock\n");*/
186 }
VOID UnlockAudioDeviceList(VOID)
Definition: pnp_list_lock.c:53
#define CloseHandle
Definition: compat.h:398
static HANDLE device_list_file
smooth NULL
Definition: ftsmooth.c:416
void logmsg(char *string,...)
Definition: debug.c:7
VOID KillAudioDeviceListLock(VOID)
Definition: pnp_list_lock.c:39
static PnP_AudioHeader * audio_device_list
#define UnmapViewOfFile
Definition: compat.h:403
VOID LockAudioDeviceList(VOID)
Definition: pnp_list_lock.c:46

Referenced by ServiceControlHandler(), and ServiceMain().

◆ HandleDeviceEvent()

DWORD HandleDeviceEvent ( DWORD  dwEventType,
LPVOID  lpEventData 
)

Definition at line 176 of file pnp.c.

179 {
180  switch (dwEventType)
181  {
182  case DBT_DEVICEARRIVAL:
183  {
184  DEV_BROADCAST_DEVICEINTERFACE* incoming_device =
185  (DEV_BROADCAST_DEVICEINTERFACE*)lpEventData;
186 
187  return ProcessDeviceArrival(incoming_device);
188  }
189 
190  default :
191  {
192  break;
193  }
194  }
195 
196  return NO_ERROR;
197 }
#define NO_ERROR
Definition: dderror.h:5
DWORD ProcessDeviceArrival(DEV_BROADCAST_DEVICEINTERFACE *device)
Definition: pnp.c:111
#define DBT_DEVICEARRIVAL
Definition: dbt.h:12

Referenced by ServiceControlHandler().

◆ logmsg()

void logmsg ( char string,
  ... 
)

Definition at line 7 of file debug.c.

8 {
10 
11  FILE* debug_file = fopen("c:\\audiosrv-debug.txt", "a");
12 
13  if (debug_file)
14  {
15  va_start(args, string);
16  vfprintf(debug_file, string, args);
17  va_end(args);
18  fclose(debug_file);
19  }
20  else
21  {
22  char buf[256];
23  va_start(args, string);
24  vsprintf(buf, string, args);
26  va_end(args);
27  }
28 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
Definition: match.c:390
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
#define va_start(ap, A)
Definition: acmsvcex.h:91
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
#define args
Definition: format.c:66
void WINAPI SHIM_OBJ_NAME() OutputDebugStringA(LPCSTR lpOutputString)
Definition: ignoredbgout.c:18

Referenced by AppendAudioDeviceToList(), CreateAudioDeviceList(), CreateDeviceDescriptor(), DestroyAudioDeviceList(), ProcessExistingDevices(), RegisterForDeviceNotifications(), ServiceControlHandler(), ServiceMain(), StartAudioService(), StartSystemAudioServices(), WaitForService(), and wmain().

◆ ProcessDeviceArrival()

DWORD ProcessDeviceArrival ( DEV_BROADCAST_DEVICEINTERFACE device)

Definition at line 111 of file pnp.c.

112 {
113  PnP_AudioDevice* list_node;
114  list_node = CreateDeviceDescriptor(device->dbcc_name, TRUE);
115  AppendAudioDeviceToList(list_node);
116  DestroyDeviceDescriptor(list_node);
117 
118  return NO_ERROR;
119 }
#define TRUE
Definition: types.h:120
BOOL AppendAudioDeviceToList(PnP_AudioDevice *device)
#define NO_ERROR
Definition: dderror.h:5
Definition: devices.h:37
#define DestroyDeviceDescriptor(descriptor)
Definition: audiosrv.h:31
VOID * CreateDeviceDescriptor(WCHAR *path, BOOL is_enabled)

Referenced by HandleDeviceEvent().

◆ ProcessExistingDevices()

BOOL ProcessExistingDevices ( VOID  )

Definition at line 26 of file pnp.c.

27 {
28  SP_DEVICE_INTERFACE_DATA interface_data;
29  SP_DEVINFO_DATA device_data;
31  HDEVINFO dev_info;
32  DWORD length;
33  int index = 0;
34 
35  const GUID category_guid = {STATIC_KSCATEGORY_AUDIO};
36 
37  dev_info = SetupDiGetClassDevsExW(&category_guid,
38  NULL,
39  NULL,
41  NULL,
42  NULL,
43  NULL);
44 
45 /* printf("%s:\n", ClassString); */
46 
47  interface_data.cbSize = sizeof(interface_data);
48  interface_data.Reserved = 0;
49 
50  /* Enumerate the devices within the category */
51  index = 0;
52 
54  + (MAX_PATH * sizeof(WCHAR));
55 
56  detail_data =
58  0,
59  length);
60 
61  if ( ! detail_data )
62  {
63  logmsg("ProcessExistingDevices() failed to allocate detail_data\n");
64  return TRUE;
65  }
66 
67  while (
69  NULL,
70  &category_guid,
71  index,
72  &interface_data) )
73  {
74  PnP_AudioDevice* list_node;
75 
77 
78  /* NOTE: We don't actually use device_data... */
80  device_data.cbSize = sizeof(device_data);
81  device_data.Reserved = 0;
83  &interface_data,
85  length,
86  NULL,
87  &device_data);
88 
89  list_node = CreateDeviceDescriptor(detail_data->DevicePath, TRUE);
90  AppendAudioDeviceToList(list_node);
91  DestroyDeviceDescriptor(list_node);
92 
93  /* TODO: Cleanup the device we enumerated? */
94 
95  index ++;
96  };
97 
99 
101 
102  return TRUE;
103 }
#define TRUE
Definition: types.h:120
BOOL AppendAudioDeviceToList(PnP_AudioDevice *device)
#define STATIC_KSCATEGORY_AUDIO
Definition: ksmedia.h:169
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:3016
#define ZeroMemory
Definition: winbase.h:1635
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W SP_DEVICE_INTERFACE_DETAIL_DATA_W
smooth NULL
Definition: ftsmooth.c:416
#define DestroyDeviceDescriptor(descriptor)
Definition: audiosrv.h:31
GLuint index
Definition: glext.h:6031
ULONG_PTR Reserved
Definition: setupapi.h:833
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2898
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W * PSP_DEVICE_INTERFACE_DETAIL_DATA_W
void logmsg(char *string,...)
Definition: debug.c:7
BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, CONST GUID *InterfaceClassGuid, DWORD MemberIndex, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
Definition: devinst.c:2785
SP_DEVICE_INTERFACE_DETAIL_DATA_A SP_DEVICE_INTERFACE_DETAIL_DATA
Definition: setupapi.h:1144
#define DIGCF_DEVICEINTERFACE
Definition: setupapi.h:174
HDEVINFO WINAPI SetupDiGetClassDevsExW(CONST GUID *class, PCWSTR enumstr, HWND parent, DWORD flags, HDEVINFO deviceset, PCWSTR machine, PVOID reserved)
Definition: devinst.c:2310
VOID * CreateDeviceDescriptor(WCHAR *path, BOOL is_enabled)
#define HeapFree(x, y, z)
Definition: compat.h:394
#define DIGCF_PRESENT
Definition: setupapi.h:171

Referenced by ServiceMain().

◆ RegisterForDeviceNotifications()

BOOL RegisterForDeviceNotifications ( VOID  )

Definition at line 127 of file pnp.c.

128 {
129  DEV_BROADCAST_DEVICEINTERFACE notification_filter;
130 
131  const GUID wdmaud_guid = {STATIC_KSCATEGORY_AUDIO};
132 
133  ZeroMemory(&notification_filter, sizeof(notification_filter));
134  notification_filter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
135  notification_filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
136  notification_filter.dbcc_classguid = wdmaud_guid;
137 
140  &notification_filter,
141  DEVICE_NOTIFY_SERVICE_HANDLE
142 /* |
143  DEVICE_NOTIFY_ALL_INTERFACE_CLASSES*/);
145  {
146  logmsg("RegisterDeviceNotification() failed with error %d\n", GetLastError());
147  }
148 
149  return ( device_notification_handle != NULL );
150 }
#define STATIC_KSCATEGORY_AUDIO
Definition: ksmedia.h:169
#define DBT_DEVTYP_DEVICEINTERFACE
Definition: dbt.h:24
SERVICE_STATUS_HANDLE service_status_handle
Definition: main.c:11
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
smooth NULL
Definition: ftsmooth.c:416
DEV_BROADCAST_DEVICEINTERFACE_A DEV_BROADCAST_DEVICEINTERFACE
Definition: dbt.h:137
void logmsg(char *string,...)
Definition: debug.c:7
HDEVNOTIFY WINAPI RegisterDeviceNotificationW(HANDLE hRecipient, LPVOID NotificationFilter, DWORD Flags)
Definition: resources.c:111
static HDEVNOTIFY device_notification_handle
Definition: pnp.c:18

Referenced by ServiceMain().

◆ StartSystemAudioServices()

BOOL StartSystemAudioServices ( VOID  )

Definition at line 70 of file services.c.

71 {
72  SC_HANDLE hSCManager;
73 
74  logmsg("Starting system audio services\n");
75 
77  if (!hSCManager)
78  {
79  logmsg("Failed to open service manager %x\n", GetLastError());
80  return FALSE;
81  }
82 
83  logmsg("Starting sysaudio service\n");
84  StartAudioService(hSCManager, L"sysaudio", 20);
85  logmsg("Starting wdmaud service\n");
86  StartAudioService(hSCManager, L"wdmaud", 20);
87 
89  return TRUE;
90 }
#define TRUE
Definition: types.h:120
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL StartAudioService(SC_HANDLE hSCManager, LPWSTR ServiceName, ULONG RetryCount)
Definition: services.c:41
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
smooth NULL
Definition: ftsmooth.c:416
#define OpenSCManager
Definition: winsvc.h:575
void logmsg(char *string,...)
Definition: debug.c:7
static const WCHAR L[]
Definition: oid.c:1250
SC_HANDLE hSCManager
Definition: sc.c:12

Referenced by ServiceMain().

◆ UnregisterDeviceNotifications()

VOID UnregisterDeviceNotifications ( VOID  )

Definition at line 159 of file pnp.c.

160 {
161  /* TODO -- NOT IMPLEMENTED! */
162 
164  {
165  /* TODO */
167  }
168 }
smooth NULL
Definition: ftsmooth.c:416
static HDEVNOTIFY device_notification_handle
Definition: pnp.c:18

Referenced by ServiceControlHandler(), and ServiceMain().

Variable Documentation

◆ service_status_handle

SERVICE_STATUS_HANDLE service_status_handle

Definition at line 11 of file main.c.

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