Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmain.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/main.c 00005 * PURPOSE: System Audio graph builder 00006 * PROGRAMMER: Andrew Greenwood 00007 * Johannes Anderwald 00008 * HISTORY: 00009 * 8 Jul 07 Started basic implementation 00010 */ 00011 00012 #include "sysaudio.h" 00013 00014 00015 const GUID KSCATEGORY_SYSAUDIO = {0xA7C7A5B1L, 0x5AF3, 0x11D1, {0x9C, 0xED, 0x00, 0xA0, 0x24, 0xBF, 0x04, 0x07}}; 00016 const GUID KSCATEGORY_AUDIO_DEVICE = {0xFBF6F530L, 0x07B9, 0x11D2, {0xA7, 0x1E, 0x00, 0x00, 0xF8, 0x00, 0x47, 0x88}}; 00017 const GUID KSCATEGORY_PREFERRED_WAVEOUT_DEVICE = {0xD6C5066EL, 0x72C1, 0x11D2, {0x97, 0x55, 0x00, 0x00, 0xF8, 0x00, 0x47, 0x88}}; 00018 const GUID KSCATEGORY_PREFERRED_WAVEIN_DEVICE = {0xD6C50671L, 0x72C1, 0x11D2, {0x97, 0x55, 0x00, 0x00, 0xF8, 0x00, 0x47, 0x88}}; 00019 const GUID KSCATEGORY_PREFERRED_MIDIOUT_DEVICE = {0xD6C50674L, 0x72C1, 0x11D2, {0x97, 0x55, 0x00, 0x00, 0xF8, 0x00, 0x47, 0x88}}; 00020 00021 PVOID 00022 AllocateItem( 00023 IN POOL_TYPE PoolType, 00024 IN SIZE_T NumberOfBytes) 00025 { 00026 PVOID Item = ExAllocatePool(PoolType, NumberOfBytes); 00027 if (!Item) 00028 return Item; 00029 00030 RtlZeroMemory(Item, NumberOfBytes); 00031 return Item; 00032 } 00033 00034 VOID 00035 FreeItem( 00036 IN PVOID Item) 00037 { 00038 ExFreePool(Item); 00039 } 00040 00041 00042 VOID 00043 NTAPI 00044 SysAudio_Unload(IN PDRIVER_OBJECT DriverObject) 00045 { 00046 DPRINT("SysAudio_Unload called\n"); 00047 } 00048 00049 NTSTATUS 00050 NTAPI 00051 SysAudio_Shutdown( 00052 IN PDEVICE_OBJECT DeviceObject, 00053 IN PIRP Irp) 00054 { 00055 PKSAUDIO_DEVICE_ENTRY DeviceEntry; 00056 PSYSAUDIODEVEXT DeviceExtension; 00057 PLIST_ENTRY Entry; 00058 00059 DPRINT("SysAudio_Shutdown called\n"); 00060 00061 DeviceExtension = (PSYSAUDIODEVEXT)DeviceObject->DeviceExtension; 00062 00063 while(!IsListEmpty(&DeviceExtension->KsAudioDeviceList)) 00064 { 00065 Entry = RemoveHeadList(&DeviceExtension->KsAudioDeviceList); 00066 DeviceEntry = (PKSAUDIO_DEVICE_ENTRY)CONTAINING_RECORD(Entry, KSAUDIO_DEVICE_ENTRY, Entry); 00067 00068 DPRINT("Freeing item %wZ\n", &DeviceEntry->DeviceName); 00069 00070 /* dereference audio device file object */ 00071 ObDereferenceObject(DeviceEntry->FileObject); 00072 00073 /* close audio device handle */ 00074 ZwClose(DeviceEntry->Handle); 00075 00076 /* free device string */ 00077 RtlFreeUnicodeString(&DeviceEntry->DeviceName); 00078 00079 /* free audio device entry */ 00080 FreeItem(DeviceEntry); 00081 } 00082 00083 Irp->IoStatus.Information = 0; 00084 Irp->IoStatus.Status = STATUS_SUCCESS; 00085 IoCompleteRequest(Irp, IO_NO_INCREMENT); 00086 return STATUS_SUCCESS; 00087 } 00088 00089 00090 NTSTATUS 00091 NTAPI 00092 SysAudio_Pnp( 00093 IN PDEVICE_OBJECT DeviceObject, 00094 IN PIRP Irp) 00095 { 00096 PIO_STACK_LOCATION IrpStack; 00097 UNICODE_STRING SymlinkName = RTL_CONSTANT_STRING(L"\\DosDevices\\sysaudio"); 00098 SYSAUDIODEVEXT *DeviceExtension; 00099 00100 /* Get current irp stack */ 00101 IrpStack = IoGetCurrentIrpStackLocation(Irp); 00102 00103 /* Fetch the device extension */ 00104 DeviceExtension = (SYSAUDIODEVEXT*)DeviceObject->DeviceExtension; 00105 ASSERT(DeviceExtension); 00106 00107 if (IrpStack->MinorFunction == IRP_MN_REMOVE_DEVICE) 00108 { 00109 /* Unregister the echo cancel hook */ 00110 if (DeviceExtension->EchoCancelNotificationEntry) 00111 IoUnregisterPlugPlayNotification(DeviceExtension->EchoCancelNotificationEntry); 00112 00113 /* Unregister the ks audio hook */ 00114 if (DeviceExtension->KsAudioNotificationEntry) 00115 IoUnregisterPlugPlayNotification(DeviceExtension->KsAudioNotificationEntry); 00116 00117 /* Destroy our symbolic link */ 00118 IoDeleteSymbolicLink(&SymlinkName); 00119 } 00120 else if (IrpStack->MinorFunction == IRP_MN_QUERY_PNP_DEVICE_STATE) 00121 { 00122 /* Sysaudio can not be disabled */ 00123 Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE; 00124 } 00125 00126 /* Perform default pnp actions */ 00127 return KsDefaultDispatchPnp(DeviceObject, Irp); 00128 } 00129 00130 NTSTATUS 00131 NTAPI 00132 SysAudio_InstallDevice( 00133 IN PDRIVER_OBJECT DriverObject) 00134 { 00135 NTSTATUS Status; 00136 UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\sysaudio"); 00137 UNICODE_STRING SymlinkName = RTL_CONSTANT_STRING(L"\\DosDevices\\sysaudio"); 00138 PDEVICE_OBJECT DeviceObject; 00139 SYSAUDIODEVEXT *DeviceExtension; 00140 00141 00142 DPRINT("SysAudio_InstallDevice called\n"); 00143 00144 /* Create the device */ 00145 Status = IoCreateDevice(DriverObject, 00146 sizeof(SYSAUDIODEVEXT), 00147 &DeviceName, 00148 FILE_DEVICE_KS, 00149 0, 00150 FALSE, 00151 &DeviceObject); 00152 00153 /* Check for success */ 00154 if (!NT_SUCCESS(Status)) 00155 { 00156 DPRINT("Failed to create \\Device\\sysaudio !\n"); 00157 return Status; 00158 } 00159 00160 /* Register device interfaces */ 00161 Status = SysAudioRegisterDeviceInterfaces(DeviceObject); 00162 if (!NT_SUCCESS(Status)) 00163 { 00164 /* Failed to register 00165 * Create a hack interface 00166 */ 00167 Status = IoCreateSymbolicLink(&SymlinkName, &DeviceName); 00168 if (!NT_SUCCESS(Status)) 00169 { 00170 IoDeleteDevice(DeviceObject); 00171 DPRINT1("Failed to create sysaudio symlink!\n"); 00172 return Status; 00173 } 00174 } 00175 /* Acquire device extension */ 00176 DeviceExtension = (SYSAUDIODEVEXT*)DeviceObject->DeviceExtension; 00177 /* Initialize device extension */ 00178 RtlZeroMemory(DeviceExtension, sizeof(SYSAUDIODEVEXT)); 00179 00180 /* Initialize the mutex */ 00181 KeInitializeSpinLock(&DeviceExtension->Lock); 00182 00183 /* Initialize the ks audio device list */ 00184 InitializeListHead(&DeviceExtension->KsAudioDeviceList); 00185 00186 /* Allocate kernel streaming device header */ 00187 Status = SysAudioAllocateDeviceHeader(DeviceExtension); 00188 if (!NT_SUCCESS(Status)) 00189 { 00190 DPRINT1("KsAllocateDeviceHeader failed with %x\n", Status); 00191 goto cleanup; 00192 } 00193 00194 /* Register device notification hooks */ 00195 Status = SysAudioRegisterNotifications(DriverObject, 00196 DeviceObject); 00197 if (!NT_SUCCESS(Status)) 00198 { 00199 DPRINT1("Failed to register device notifications\n"); 00200 goto cleanup; 00201 } 00202 00203 /* Load kmixer */ 00204 Status = SysAudioOpenKMixer(DeviceExtension); 00205 if (!NT_SUCCESS(Status)) 00206 { 00207 DPRINT1("SysAudioOpenKMixer failed with %x\n", Status); 00208 goto cleanup; 00209 } 00210 00211 /* set io flags */ 00212 DeviceObject->Flags |= DO_DIRECT_IO | DO_POWER_PAGABLE; 00213 /* clear initializing flag */ 00214 DeviceObject->Flags &= ~ DO_DEVICE_INITIALIZING; 00215 00216 /* register shutdown notfication */ 00217 IoRegisterShutdownNotification(DeviceObject); 00218 00219 00220 /* Done */ 00221 return STATUS_SUCCESS; 00222 00223 cleanup: 00224 00225 if (DeviceExtension->KsAudioNotificationEntry) 00226 IoUnregisterPlugPlayNotification(DeviceExtension->KsAudioNotificationEntry); 00227 00228 if (DeviceExtension->EchoCancelNotificationEntry) 00229 IoUnregisterPlugPlayNotification(DeviceExtension->EchoCancelNotificationEntry); 00230 00231 IoDeleteSymbolicLink(&SymlinkName); 00232 IoDeleteDevice(DeviceObject); 00233 return Status; 00234 } 00235 00236 NTSTATUS 00237 NTAPI 00238 DriverEntry( 00239 IN PDRIVER_OBJECT DriverObject, 00240 IN PUNICODE_STRING RegistryPath) 00241 { 00242 DPRINT("System audio graph builder (sysaudio) started\n"); 00243 00244 /* Let ks handle these */ 00245 KsSetMajorFunctionHandler(DriverObject, IRP_MJ_CREATE); 00246 KsSetMajorFunctionHandler(DriverObject, IRP_MJ_CLOSE); 00247 KsSetMajorFunctionHandler(DriverObject, IRP_MJ_WRITE); 00248 KsSetMajorFunctionHandler(DriverObject, IRP_MJ_DEVICE_CONTROL); 00249 00250 /* Let ks handle these */ 00251 DriverObject->MajorFunction[IRP_MJ_POWER] = KsDefaultDispatchPower; 00252 DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = KsDefaultForwardIrp; 00253 00254 /* Use provided ks unload function */ 00255 DriverObject->DriverUnload = KsNullDriverUnload; 00256 00257 /* Sysaudio needs to do work on pnp, so handle it */ 00258 DriverObject->MajorFunction[IRP_MJ_PNP] = SysAudio_Pnp; 00259 DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = SysAudio_Shutdown; 00260 00261 /* Call our initialization function */ 00262 return SysAudio_InstallDevice(DriverObject); 00263 } Generated on Sun May 27 2012 04:16:44 for ReactOS by
1.7.6.1
|