Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencapture.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS Configuration of network devices 00004 * FILE: dll/directx/dsound_new/capture.c 00005 * PURPOSE: Implement IDirectSoundCapture 00006 * 00007 * PROGRAMMERS: Johannes Anderwald (janderwald@reactos.org) 00008 */ 00009 00010 #include "precomp.h" 00011 00012 typedef struct 00013 { 00014 IDirectSoundCaptureVtbl *lpVtbl; 00015 LONG ref; 00016 GUID DeviceGUID; 00017 BOOL bInitialized; 00018 LPFILTERINFO Filter; 00019 }CDirectSoundCaptureImpl, *LPCDirectSoundCaptureImpl; 00020 00021 HRESULT 00022 WINAPI 00023 CDirectSoundCapture_fnQueryInterface( 00024 LPDIRECTSOUNDCAPTURE8 iface, 00025 REFIID riid, 00026 LPVOID * ppobj) 00027 { 00028 LPOLESTR pStr; 00029 LPCDirectSoundCaptureImpl This = (LPCDirectSoundCaptureImpl)CONTAINING_RECORD(iface, CDirectSoundCaptureImpl, lpVtbl); 00030 00031 /* check if the interface is supported */ 00032 if (IsEqualIID(riid, &IID_IUnknown) || 00033 IsEqualIID(riid, &IID_IDirectSoundCapture)) 00034 { 00035 *ppobj = (LPVOID)&This->lpVtbl; 00036 InterlockedIncrement(&This->ref); 00037 return S_OK; 00038 } 00039 00040 /* unsupported interface */ 00041 if (SUCCEEDED(StringFromIID(riid, &pStr))) 00042 { 00043 DPRINT("No Interface for class %s\n", pStr); 00044 CoTaskMemFree(pStr); 00045 } 00046 return E_NOINTERFACE; 00047 } 00048 00049 ULONG 00050 WINAPI 00051 CDirectSoundCapture_fnAddRef( 00052 LPDIRECTSOUNDCAPTURE8 iface) 00053 { 00054 ULONG ref; 00055 LPCDirectSoundCaptureImpl This = (LPCDirectSoundCaptureImpl)CONTAINING_RECORD(iface, CDirectSoundCaptureImpl, lpVtbl); 00056 00057 /* increment reference count */ 00058 ref = InterlockedIncrement(&This->ref); 00059 00060 return ref; 00061 } 00062 00063 ULONG 00064 WINAPI 00065 CDirectSoundCapture_fnRelease( 00066 LPDIRECTSOUNDCAPTURE8 iface) 00067 { 00068 ULONG ref; 00069 LPCDirectSoundCaptureImpl This = (LPCDirectSoundCaptureImpl)CONTAINING_RECORD(iface, CDirectSoundCaptureImpl, lpVtbl); 00070 00071 /* release reference count */ 00072 ref = InterlockedDecrement(&(This->ref)); 00073 00074 if (!ref) 00075 { 00076 HeapFree(GetProcessHeap(), 0, This); 00077 } 00078 00079 return ref; 00080 } 00081 00082 00083 HRESULT 00084 WINAPI 00085 CDirectSoundCapture_fnCreateCaptureBuffer( 00086 LPDIRECTSOUNDCAPTURE8 iface, 00087 LPCDSCBUFFERDESC lpcDSBufferDesc, 00088 LPDIRECTSOUNDCAPTUREBUFFER *ppDSCBuffer, 00089 LPUNKNOWN pUnkOuter) 00090 { 00091 HRESULT hResult; 00092 LPCDirectSoundCaptureImpl This = (LPCDirectSoundCaptureImpl)CONTAINING_RECORD(iface, CDirectSoundCaptureImpl, lpVtbl); 00093 00094 if (!This->bInitialized) 00095 { 00096 /* object not yet initialized */ 00097 return DSERR_UNINITIALIZED; 00098 } 00099 00100 if (!lpcDSBufferDesc || !ppDSCBuffer || pUnkOuter != NULL) 00101 { 00102 /* invalid param */ 00103 return DSERR_INVALIDPARAM; 00104 } 00105 00106 /* check buffer description */ 00107 if ((lpcDSBufferDesc->dwSize != sizeof(DSCBUFFERDESC) && lpcDSBufferDesc->dwSize != sizeof(DSCBUFFERDESC1)) || 00108 lpcDSBufferDesc->dwReserved != 0 || lpcDSBufferDesc->dwBufferBytes == 0 || lpcDSBufferDesc->lpwfxFormat == NULL) 00109 { 00110 /* invalid buffer description */ 00111 return DSERR_INVALIDPARAM; 00112 } 00113 00114 DPRINT("This %p wFormatTag %x nChannels %u nSamplesPerSec %u nAvgBytesPerSec %u NBlockAlign %u wBitsPerSample %u cbSize %u\n", 00115 This, lpcDSBufferDesc->lpwfxFormat->wFormatTag, lpcDSBufferDesc->lpwfxFormat->nChannels, lpcDSBufferDesc->lpwfxFormat->nSamplesPerSec, lpcDSBufferDesc->lpwfxFormat->nAvgBytesPerSec, lpcDSBufferDesc->lpwfxFormat->nBlockAlign, lpcDSBufferDesc->lpwfxFormat->wBitsPerSample, lpcDSBufferDesc->lpwfxFormat->cbSize); 00116 00117 hResult = NewDirectSoundCaptureBuffer((LPDIRECTSOUNDCAPTUREBUFFER8*)ppDSCBuffer, This->Filter, lpcDSBufferDesc); 00118 return hResult; 00119 } 00120 00121 00122 HRESULT 00123 WINAPI 00124 CDirectSoundCapture_fnGetCaps( 00125 LPDIRECTSOUNDCAPTURE8 iface, 00126 LPDSCCAPS pDSCCaps) 00127 { 00128 WAVEINCAPSW Caps; 00129 MMRESULT Result; 00130 LPCDirectSoundCaptureImpl This = (LPCDirectSoundCaptureImpl)CONTAINING_RECORD(iface, CDirectSoundCaptureImpl, lpVtbl); 00131 00132 if (!This->bInitialized) 00133 { 00134 /* object not yet initialized */ 00135 return DSERR_UNINITIALIZED; 00136 } 00137 00138 if (!pDSCCaps) 00139 { 00140 /* invalid param */ 00141 return DSERR_INVALIDPARAM; 00142 } 00143 00144 if (pDSCCaps->dwSize != sizeof(DSCCAPS)) 00145 { 00146 /* invalid param */ 00147 return DSERR_INVALIDPARAM; 00148 } 00149 00150 00151 /* We are certified ;) */ 00152 pDSCCaps->dwFlags = DSCCAPS_CERTIFIED; 00153 00154 ASSERT(This->Filter); 00155 00156 Result = waveInGetDevCapsW(This->Filter->MappedId[0], &Caps, sizeof(WAVEINCAPSW)); 00157 if (Result != MMSYSERR_NOERROR) 00158 { 00159 /* failed */ 00160 DPRINT("waveInGetDevCapsW for device %u failed with %x\n", This->Filter->MappedId[0], Result); 00161 return DSERR_UNSUPPORTED; 00162 } 00163 00164 pDSCCaps->dwFormats = Caps.dwFormats; 00165 pDSCCaps->dwChannels = Caps.wChannels; 00166 00167 return DS_OK; 00168 } 00169 00170 00171 HRESULT 00172 WINAPI 00173 CDirectSoundCapture_fnInitialize( 00174 LPDIRECTSOUNDCAPTURE8 iface, 00175 LPCGUID pcGuidDevice) 00176 { 00177 GUID DeviceGuid; 00178 LPOLESTR pGuidStr; 00179 LPCDirectSoundCaptureImpl This = (LPCDirectSoundCaptureImpl)CONTAINING_RECORD(iface, CDirectSoundCaptureImpl, lpVtbl); 00180 00181 /* sanity check */ 00182 ASSERT(RootInfo); 00183 00184 if (This->bInitialized) 00185 { 00186 /* object has already been initialized */ 00187 return DSERR_ALREADYINITIALIZED; 00188 } 00189 00190 /* fixme mutual exlucsion */ 00191 00192 if (pcGuidDevice == NULL || IsEqualGUID(pcGuidDevice, &GUID_NULL)) 00193 { 00194 /* use default playback device id */ 00195 pcGuidDevice = &DSDEVID_DefaultCapture; 00196 } 00197 00198 if (IsEqualIID(pcGuidDevice, &DSDEVID_DefaultVoicePlayback) || IsEqualIID(pcGuidDevice, &DSDEVID_DefaultPlayback)) 00199 { 00200 /* this has to be a winetest */ 00201 return DSERR_NODRIVER; 00202 } 00203 00204 /* now verify the guid */ 00205 if (GetDeviceID(pcGuidDevice, &DeviceGuid) != DS_OK) 00206 { 00207 if (SUCCEEDED(StringFromIID(pcGuidDevice, &pGuidStr))) 00208 { 00209 DPRINT("IDirectSound8_fnInitialize: Unknown GUID %ws\n", pGuidStr); 00210 CoTaskMemFree(pGuidStr); 00211 } 00212 return DSERR_INVALIDPARAM; 00213 } 00214 00215 if (FindDeviceByGuid(&DeviceGuid, &This->Filter)) 00216 { 00217 This->bInitialized = TRUE; 00218 return DS_OK; 00219 } 00220 00221 DPRINT("Failed to find device\n"); 00222 return DSERR_INVALIDPARAM; 00223 } 00224 00225 static IDirectSoundCaptureVtbl vt_DirectSoundCapture = 00226 { 00227 /* IUnknown methods */ 00228 CDirectSoundCapture_fnQueryInterface, 00229 CDirectSoundCapture_fnAddRef, 00230 CDirectSoundCapture_fnRelease, 00231 CDirectSoundCapture_fnCreateCaptureBuffer, 00232 CDirectSoundCapture_fnGetCaps, 00233 CDirectSoundCapture_fnInitialize 00234 }; 00235 00236 HRESULT 00237 InternalDirectSoundCaptureCreate( 00238 LPCGUID lpcGUID, 00239 LPDIRECTSOUNDCAPTURE8 *ppDS, 00240 IUnknown *pUnkOuter) 00241 { 00242 LPCDirectSoundCaptureImpl This; 00243 HRESULT hr; 00244 00245 if (!ppDS || pUnkOuter != NULL) 00246 { 00247 /* invalid parameter passed */ 00248 return DSERR_INVALIDPARAM; 00249 } 00250 00251 /* allocate CDirectSoundCaptureImpl struct */ 00252 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CDirectSoundCaptureImpl)); 00253 if (!This) 00254 { 00255 /* not enough memory */ 00256 return DSERR_OUTOFMEMORY; 00257 } 00258 00259 /* initialize IDirectSoundCapture object */ 00260 This->ref = 1; 00261 This->lpVtbl = &vt_DirectSoundCapture; 00262 00263 00264 /* initialize direct sound interface */ 00265 hr = IDirectSoundCapture_Initialize((LPDIRECTSOUNDCAPTURE8)&This->lpVtbl, lpcGUID); 00266 00267 /* check for success */ 00268 if (!SUCCEEDED(hr)) 00269 { 00270 /* failed */ 00271 DPRINT("Failed to initialize DirectSoundCapture object with %x\n", hr); 00272 IDirectSoundCapture_Release((LPDIRECTSOUND8)&This->lpVtbl); 00273 return hr; 00274 } 00275 00276 /* store result */ 00277 *ppDS = (LPDIRECTSOUNDCAPTURE8)&This->lpVtbl; 00278 DPRINT("DirectSoundCapture object %p\n", *ppDS); 00279 return DS_OK; 00280 } 00281 00282 HRESULT 00283 CALLBACK 00284 NewDirectSoundCapture( 00285 IUnknown* pUnkOuter, 00286 REFIID riid, 00287 LPVOID* ppvObject) 00288 { 00289 LPOLESTR pStr; 00290 LPCDirectSoundCaptureImpl This; 00291 00292 /* check requested interface */ 00293 if (!IsEqualIID(riid, &IID_IUnknown) && !IsEqualIID(riid, &IID_IDirectSoundCapture) && !IsEqualIID(riid, &IID_IDirectSoundCapture8)) 00294 { 00295 *ppvObject = 0; 00296 StringFromIID(riid, &pStr); 00297 DPRINT("NewDirectSoundCapture does not support Interface %ws\n", pStr); 00298 CoTaskMemFree(pStr); 00299 return E_NOINTERFACE; 00300 } 00301 00302 /* allocate CDirectSoundCaptureImpl struct */ 00303 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CDirectSoundCaptureImpl)); 00304 if (!This) 00305 { 00306 /* not enough memory */ 00307 return DSERR_OUTOFMEMORY; 00308 } 00309 00310 /* initialize object */ 00311 This->ref = 1; 00312 This->lpVtbl = &vt_DirectSoundCapture; 00313 This->bInitialized = FALSE; 00314 *ppvObject = (LPVOID)&This->lpVtbl; 00315 00316 return S_OK; 00317 } 00318 00319 00320 HRESULT 00321 WINAPI 00322 DirectSoundCaptureCreate( 00323 LPCGUID lpcGUID, 00324 LPDIRECTSOUNDCAPTURE *ppDSC, 00325 LPUNKNOWN pUnkOuter) 00326 { 00327 return InternalDirectSoundCaptureCreate(lpcGUID, (LPDIRECTSOUNDCAPTURE8*)ppDSC, pUnkOuter); 00328 } 00329 00330 HRESULT 00331 WINAPI 00332 DirectSoundCaptureCreate8( 00333 LPCGUID lpcGUID, 00334 LPDIRECTSOUNDCAPTURE8 *ppDSC8, 00335 LPUNKNOWN pUnkOuter) 00336 { 00337 return InternalDirectSoundCaptureCreate(lpcGUID, ppDSC8, pUnkOuter); 00338 } Generated on Mon May 28 2012 04:21:08 for ReactOS by
1.7.6.1
|