Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendeviface.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS Kernel Streaming 00004 * FILE: drivers/wdm/audio/sysaudio/deviface.c 00005 * PURPOSE: System Audio graph builder 00006 * PROGRAMMER: Johannes Anderwald 00007 */ 00008 00009 #include "sysaudio.h" 00010 00011 const GUID GUID_DEVICE_INTERFACE_ARRIVAL = {0xCB3A4004L, 0x46F0, 0x11D0, {0xB0, 0x8F, 0x00, 0x60, 0x97, 0x13, 0x05, 0x3F}}; 00012 const GUID GUID_DEVICE_INTERFACE_REMOVAL = {0xCB3A4005L, 0x46F0, 0x11D0, {0xB0, 0x8F, 0x00, 0x60, 0x97, 0x13, 0x05, 0x3F}}; 00013 const GUID KS_CATEGORY_AUDIO = {0x6994AD04L, 0x93EF, 0x11D0, {0xA3, 0xCC, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}}; 00014 const GUID KS_CATEGORY_TOPOLOGY = {0xDDA54A40, 0x1E4C, 0x11D1, {0xA0, 0x50, 0x40, 0x57, 0x05, 0xC1, 0x00, 0x00}}; 00015 const GUID DMOCATEGORY_ACOUSTIC_ECHO_CANCEL = {0xBF963D80L, 0xC559, 0x11D0, {0x8A, 0x2B, 0x00, 0xA0, 0xC9, 0x25, 0x5A, 0xC1}}; 00016 00017 NTSTATUS 00018 OpenDevice( 00019 IN PUNICODE_STRING DeviceName, 00020 IN PHANDLE HandleOut, 00021 IN PFILE_OBJECT * FileObjectOut) 00022 { 00023 NTSTATUS Status; 00024 HANDLE NodeHandle; 00025 PFILE_OBJECT FileObject; 00026 OBJECT_ATTRIBUTES ObjectAttributes; 00027 IO_STATUS_BLOCK IoStatusBlock; 00028 00029 InitializeObjectAttributes(&ObjectAttributes, DeviceName, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL); 00030 00031 Status = ZwCreateFile(&NodeHandle, 00032 GENERIC_READ | GENERIC_WRITE, 00033 &ObjectAttributes, 00034 &IoStatusBlock, 00035 NULL, 00036 0, 00037 0, 00038 FILE_OPEN, 00039 FILE_SYNCHRONOUS_IO_NONALERT, 00040 NULL, 00041 0); 00042 00043 00044 if (!NT_SUCCESS(Status)) 00045 { 00046 DPRINT("ZwCreateFile failed with %x %S\n", Status, DeviceName->Buffer); 00047 return Status; 00048 } 00049 00050 Status = ObReferenceObjectByHandle(NodeHandle, GENERIC_READ | GENERIC_WRITE, IoFileObjectType, KernelMode, (PVOID*)&FileObject, NULL); 00051 if (!NT_SUCCESS(Status)) 00052 { 00053 ZwClose(NodeHandle); 00054 DPRINT("ObReferenceObjectByHandle failed with %x\n", Status); 00055 return Status; 00056 } 00057 00058 *HandleOut = NodeHandle; 00059 *FileObjectOut = FileObject; 00060 return Status; 00061 } 00062 00063 NTSTATUS 00064 InsertAudioDevice( 00065 IN PDEVICE_OBJECT DeviceObject, 00066 IN PUNICODE_STRING DeviceName) 00067 { 00068 NTSTATUS Status = STATUS_SUCCESS; 00069 PSYSAUDIODEVEXT DeviceExtension; 00070 PKSAUDIO_DEVICE_ENTRY DeviceEntry = NULL; 00071 00072 /* a new device has arrived */ 00073 DeviceEntry = AllocateItem(NonPagedPool, sizeof(KSAUDIO_DEVICE_ENTRY)); 00074 if (!DeviceEntry) 00075 { 00076 /* no memory */ 00077 return STATUS_INSUFFICIENT_RESOURCES; 00078 } 00079 00080 /* initialize audio device entry */ 00081 RtlZeroMemory(DeviceEntry, sizeof(KSAUDIO_DEVICE_ENTRY)); 00082 00083 /* set device name */ 00084 DeviceEntry->DeviceName.Length = 0; 00085 DeviceEntry->DeviceName.MaximumLength = DeviceName->MaximumLength + 10 * sizeof(WCHAR); 00086 00087 DeviceEntry->DeviceName.Buffer = AllocateItem(NonPagedPool, DeviceEntry->DeviceName.MaximumLength); 00088 00089 if (!DeviceEntry->DeviceName.Buffer) 00090 { 00091 Status = STATUS_INSUFFICIENT_RESOURCES; 00092 goto cleanup; 00093 } 00094 00095 RtlAppendUnicodeToString(&DeviceEntry->DeviceName, L"\\??\\"); 00096 RtlAppendUnicodeStringToString(&DeviceEntry->DeviceName, DeviceName); 00097 00098 Status = OpenDevice(&DeviceEntry->DeviceName, &DeviceEntry->Handle, &DeviceEntry->FileObject); 00099 00100 if (!NT_SUCCESS(Status)) 00101 { 00102 goto cleanup; 00103 } 00104 00105 /* fetch device extension */ 00106 DeviceExtension = (PSYSAUDIODEVEXT)DeviceObject->DeviceExtension; 00107 /* insert new audio device */ 00108 ExInterlockedInsertTailList(&DeviceExtension->KsAudioDeviceList, &DeviceEntry->Entry, &DeviceExtension->Lock); 00109 InterlockedIncrement((PLONG)&DeviceExtension->NumberOfKsAudioDevices); 00110 00111 DPRINT("Successfully opened audio device %u Device %S\n", DeviceExtension->NumberOfKsAudioDevices, DeviceEntry->DeviceName.Buffer); 00112 return Status; 00113 00114 cleanup: 00115 if (DeviceEntry) 00116 { 00117 if (DeviceEntry->DeviceName.Buffer) 00118 FreeItem(DeviceEntry->DeviceName.Buffer); 00119 00120 FreeItem(DeviceEntry); 00121 } 00122 00123 return Status; 00124 00125 } 00126 00127 00128 NTSTATUS 00129 NTAPI 00130 DeviceInterfaceChangeCallback( 00131 IN PVOID NotificationStructure, 00132 IN PVOID Context) 00133 { 00134 DEVICE_INTERFACE_CHANGE_NOTIFICATION * Event; 00135 NTSTATUS Status = STATUS_SUCCESS; 00136 PDEVICE_OBJECT DeviceObject = (PDEVICE_OBJECT)Context; 00137 00138 Event = (DEVICE_INTERFACE_CHANGE_NOTIFICATION*)NotificationStructure; 00139 00140 if (IsEqualGUIDAligned(&Event->Event, 00141 &GUID_DEVICE_INTERFACE_ARRIVAL)) 00142 { 00143 Status = InsertAudioDevice(DeviceObject, Event->SymbolicLinkName); 00144 return Status; 00145 } 00146 else 00147 { 00148 DPRINT("Remove interface to audio device!\n"); 00149 UNIMPLEMENTED 00150 return STATUS_SUCCESS; 00151 } 00152 00153 00154 } 00155 00156 NTSTATUS 00157 SysAudioRegisterNotifications( 00158 IN PDRIVER_OBJECT DriverObject, 00159 IN PDEVICE_OBJECT DeviceObject) 00160 { 00161 NTSTATUS Status; 00162 PSYSAUDIODEVEXT DeviceExtension; 00163 00164 DeviceExtension = (PSYSAUDIODEVEXT)DeviceObject->DeviceExtension; 00165 00166 Status = IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange, 00167 PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES, 00168 (PVOID)&KS_CATEGORY_AUDIO, 00169 DriverObject, 00170 DeviceInterfaceChangeCallback, 00171 (PVOID)DeviceObject, 00172 (PVOID*)&DeviceExtension->KsAudioNotificationEntry); 00173 00174 if (!NT_SUCCESS(Status)) 00175 { 00176 DPRINT("IoRegisterPlugPlayNotification failed with %x\n", Status); 00177 } 00178 00179 Status = IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange, 00180 PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES, 00181 (PVOID)&DMOCATEGORY_ACOUSTIC_ECHO_CANCEL, 00182 DriverObject, 00183 DeviceInterfaceChangeCallback, 00184 (PVOID)DeviceObject, 00185 (PVOID*)&DeviceExtension->EchoCancelNotificationEntry); 00186 00187 if (!NT_SUCCESS(Status)) 00188 { 00189 /* ignore failure for now */ 00190 DPRINT("IoRegisterPlugPlayNotification failed for DMOCATEGORY_ACOUSTIC_ECHO_CANCEL\n", Status); 00191 } 00192 00193 return STATUS_SUCCESS; 00194 } 00195 00196 00197 00198 NTSTATUS 00199 SysAudioRegisterDeviceInterfaces( 00200 IN PDEVICE_OBJECT DeviceObject) 00201 { 00202 NTSTATUS Status; 00203 UNICODE_STRING SymbolicLink; 00204 00205 Status = IoRegisterDeviceInterface(DeviceObject, &KSCATEGORY_PREFERRED_MIDIOUT_DEVICE, NULL, &SymbolicLink); 00206 if (NT_SUCCESS(Status)) 00207 { 00208 IoSetDeviceInterfaceState(&SymbolicLink, TRUE); 00209 RtlFreeUnicodeString(&SymbolicLink); 00210 } 00211 else 00212 { 00213 DPRINT("Failed to register KSCATEGORY_PREFERRED_MIDIOUT_DEVICE interface Status %x\n", Status); 00214 return Status; 00215 } 00216 00217 Status = IoRegisterDeviceInterface(DeviceObject, &KSCATEGORY_PREFERRED_WAVEIN_DEVICE, NULL, &SymbolicLink); 00218 if (NT_SUCCESS(Status)) 00219 { 00220 IoSetDeviceInterfaceState(&SymbolicLink, TRUE); 00221 RtlFreeUnicodeString(&SymbolicLink); 00222 } 00223 else 00224 { 00225 DPRINT("Failed to register KSCATEGORY_PREFERRED_WAVEIN_DEVICE interface Status %x\n", Status); 00226 return Status; 00227 } 00228 00229 Status = IoRegisterDeviceInterface(DeviceObject, &KSCATEGORY_PREFERRED_WAVEOUT_DEVICE, NULL, &SymbolicLink); 00230 if (NT_SUCCESS(Status)) 00231 { 00232 IoSetDeviceInterfaceState(&SymbolicLink, TRUE); 00233 RtlFreeUnicodeString(&SymbolicLink); 00234 } 00235 else 00236 { 00237 DPRINT("Failed to register KSCATEGORY_PREFERRED_WAVEOUT_DEVICE interface Status %x\n", Status); 00238 } 00239 00240 Status = IoRegisterDeviceInterface(DeviceObject, &KSCATEGORY_SYSAUDIO, NULL, &SymbolicLink); 00241 if (NT_SUCCESS(Status)) 00242 { 00243 IoSetDeviceInterfaceState(&SymbolicLink, TRUE); 00244 RtlFreeUnicodeString(&SymbolicLink); 00245 } 00246 else 00247 { 00248 DPRINT("Failed to register KSCATEGORY_SYSAUDIO interface Status %x\n", Status); 00249 } 00250 00251 return Status; 00252 } 00253 Generated on Sun May 27 2012 04:28:39 for ReactOS by
1.7.6.1
|