ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

utils.c
Go to the documentation of this file.
00001 /*
00002  *
00003  * COPYRIGHT:            See COPYING in the top level directory
00004  * PROJECT:              ReactOS Multimedia
00005  * FILE:                 lib/mmdrv/utils.c
00006  * PURPOSE:              Multimedia User Mode Driver (utility functions)
00007  * PROGRAMMER:           Andrew Greenwood
00008  * UPDATE HISTORY:
00009  *                       Jan 30, 2004: Imported into ReactOS tree
00010  */
00011 
00012 #include "mmdrv.h"
00013 
00014 #define NDEBUG
00015 #include <debug.h>
00016 
00017 typedef struct _DEVICE_LIST
00018 {
00019     struct _DEVICE_LIST *Next;
00020     DWORD   DeviceType;
00021     ULONG   CardIndex;
00022     PVOID   DeviceInstanceData;
00023     ULONG   DeviceInstanceDataSize;
00024     WCHAR   Name[1];
00025 } DEVICE_LIST, *PDEVICE_LIST;
00026 
00027 PDEVICE_LIST DeviceList;
00028 
00029 
00030 DWORD TranslateStatus(void)
00031 {
00032     switch(GetLastError())
00033     {
00034         case NO_ERROR :
00035         case ERROR_IO_PENDING :
00036             return MMSYSERR_NOERROR;
00037             
00038         case ERROR_BUSY :
00039             return MMSYSERR_ALLOCATED;
00040             
00041         case ERROR_NOT_SUPPORTED :
00042         case ERROR_INVALID_FUNCTION :
00043             return MMSYSERR_NOTSUPPORTED;
00044             
00045         case ERROR_NOT_ENOUGH_MEMORY :
00046             return MMSYSERR_NOMEM;
00047             
00048         case ERROR_ACCESS_DENIED :
00049             return MMSYSERR_BADDEVICEID;
00050             
00051         case ERROR_INSUFFICIENT_BUFFER :
00052             return MMSYSERR_INVALPARAM;
00053             
00054         default :
00055             return MMSYSERR_ERROR;
00056     };
00057 }
00058 
00059 
00060 
00061 MMRESULT OpenDevice(UINT DeviceType, DWORD ID, PHANDLE pDeviceHandle,
00062                     DWORD Access)
00063 {
00064     DPRINT("OpenDevice()\n");
00065     WCHAR DeviceName[SOUND_MAX_DEVICE_NAME];
00066     *pDeviceHandle = INVALID_HANDLE_VALUE;
00067 
00068     if (ID > SOUND_MAX_DEVICES)
00069         return MMSYSERR_BADDEVICEID;
00070 
00071     switch(DeviceType)
00072     {
00073         case WaveOutDevice :
00074             wsprintf(DeviceName, L"\\\\.%ls%d", WAVE_OUT_DEVICE_NAME_U + strlen("\\Device"), ID);
00075             break;
00076         case WaveInDevice :
00077             wsprintf(DeviceName, L"\\\\.%ls%d", WAVE_IN_DEVICE_NAME_U + strlen("\\Device"), ID);
00078             break;
00079         case MidiOutDevice :
00080             wsprintf(DeviceName, L"\\\\.%ls%d", MIDI_OUT_DEVICE_NAME_U + strlen("\\Device"), ID);
00081             break;
00082         case MidiInDevice :
00083             wsprintf(DeviceName, L"\\\\.%ls%d", MIDI_IN_DEVICE_NAME_U + strlen("\\Device"), ID);
00084             break;
00085         case AuxDevice :
00086              wsprintf(DeviceName, L"\\\\.%ls%d", AUX_DEVICE_NAME_U + strlen("\\Device"), ID);
00087              break;
00088         default : 
00089             DPRINT("No Auido Device Found");
00090             return MMSYSERR_BADDEVICEID; /* Maybe we should change error code */
00091     };
00092 
00093     DPRINT("Attempting to open %S\n", DeviceName);
00094 
00095     *pDeviceHandle = CreateFile(DeviceName, Access, FILE_SHARE_WRITE, NULL,
00096                                 OPEN_EXISTING, Access != GENERIC_READ ? FILE_FLAG_OVERLAPPED : 0,
00097                                 NULL);
00098 
00099     DPRINT("DeviceHandle == 0x%x\n", (int)*pDeviceHandle);
00100 
00101     if (pDeviceHandle == INVALID_HANDLE_VALUE)
00102         return TranslateStatus();
00103 
00104     return MMSYSERR_NOERROR;
00105 }
00106 
00107 
00108 // DEVICE LIST MANAGEMENT
00109 
00110 
00111 BOOL AddDeviceToList(PDEVICE_LIST* pList, DWORD DeviceType, DWORD CardIndex,
00112                      LPWSTR Name)
00113 {
00114     PDEVICE_LIST pNewDevice;
00115 
00116     DPRINT("AddDeviceToList()\n");
00117 
00118     pNewDevice = (PDEVICE_LIST) HeapAlloc(Heap, 0,
00119         sizeof(DEVICE_LIST) + lstrlen(Name) * sizeof(WCHAR));
00120 
00121     if ( !pNewDevice )
00122     {
00123         SetLastError(ERROR_NOT_ENOUGH_MEMORY);
00124         return FALSE;
00125     }
00126     
00127     pNewDevice->DeviceType = DeviceType;
00128     pNewDevice->CardIndex = CardIndex;
00129     lstrcpy(pNewDevice->Name, Name);
00130     pNewDevice->DeviceInstanceData = NULL;
00131     pNewDevice->Next = *pList;
00132     *pList = pNewDevice;
00133     
00134     DPRINT("Success!\n");
00135 
00136     return TRUE;
00137 }
00138 
00139 
00140 VOID FreeDeviceList()
00141 {
00142     PDEVICE_LIST pDevice;
00143 
00144     DPRINT("FreeDeviceList()\n");
00145     
00146     while (DeviceList)
00147     {
00148         pDevice = DeviceList;
00149         DeviceList = pDevice->Next;
00150 
00151         if (pDevice->DeviceInstanceData)
00152             HeapFree(Heap, 0, (LPVOID)pDevice->DeviceInstanceData);
00153 
00154         HeapFree(Heap, 0, (LPSTR)pDevice);
00155     }
00156 }
00157 
00158 
00159 MMRESULT FindDevices()
00160 {
00161 //    DWORD Index;
00162 //    HKEY DriverKey;
00163 
00164     DPRINT("Finding devices\n");
00165     
00166 //    DriverKey = OpenParametersKey();
00167 //  see drvutil.c of MS DDK for how this SHOULD be done...
00168 
00169   
00170     SHORT i;
00171     HANDLE h;
00172     WCHAR DeviceName[SOUND_MAX_DEVICE_NAME]; 
00173 
00174     for (i=0; OpenDevice(WaveOutDevice, i, &h, GENERIC_READ) == MMSYSERR_NOERROR; i++) 
00175     { 
00176         wsprintf(DeviceName, L"WaveOut%d\0", i);
00177         CloseHandle(h);
00178         AddDeviceToList(&DeviceList, WaveOutDevice, 0, DeviceName);
00179     }
00180 
00181     for (i=0; OpenDevice(WaveInDevice, i, &h, GENERIC_READ) == MMSYSERR_NOERROR; i++) 
00182     { 
00183         wsprintf(DeviceName, L"WaveIn%d\0", i);
00184         CloseHandle(h);
00185         AddDeviceToList(&DeviceList, WaveInDevice, 0, DeviceName);
00186     }
00187 
00188     for (i=0; OpenDevice(MidiOutDevice, i, &h, GENERIC_READ) == MMSYSERR_NOERROR; i++) 
00189     { 
00190         wsprintf(DeviceName, L"MidiOut%d\0", i);
00191         CloseHandle(h);
00192         AddDeviceToList(&DeviceList, MidiOutDevice, 0, DeviceName);
00193     }
00194 
00195     for (i=0; OpenDevice(MidiInDevice, i, &h, GENERIC_READ) == MMSYSERR_NOERROR; i++) 
00196     { 
00197         wsprintf(DeviceName, L"MidiIn%d\0", i);
00198         CloseHandle(h);
00199         AddDeviceToList(&DeviceList, MidiInDevice, 0, DeviceName);
00200     }
00201 
00202     for (i=0; OpenDevice(AuxDevice, i, &h, GENERIC_READ) == MMSYSERR_NOERROR; i++) 
00203     { 
00204         wsprintf(DeviceName, L"Aux%d\0", i);
00205         CloseHandle(h);
00206         AddDeviceToList(&DeviceList, AuxDevice, 0, DeviceName);
00207     }
00208 
00209 
00210     // MIDI Out 0: MPU-401 UART
00211     // AddDeviceToList(&DeviceList, MidiOutDevice, 0, L"MidiOut0");
00212     // Wave Out 0: Sound Blaster 16 (ok?)
00213     // AddDeviceToList(&DeviceList, WaveOutDevice, 0, L"WaveOut0");
00214 
00215     return MMSYSERR_NOERROR; // ok?
00216 }
00217 
00218 
00219 
00220 DWORD GetDeviceCount(UINT DeviceType)
00221 {
00222     int i;
00223     PDEVICE_LIST List;
00224 
00225     for (List = DeviceList, i = 0; List != NULL; List = List->Next)
00226         if (List->DeviceType == DeviceType)
00227             i ++;
00228 
00229     return i;
00230 }

Generated on Sun May 27 2012 04:22:16 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.