ReactOS 0.4.15-dev-7918-g2a2556c
capturebuffer.c File Reference
#include "precomp.h"
Include dependency graph for capturebuffer.c:

Go to the source code of this file.

Classes

struct  CDirectSoundCaptureBufferImpl
 

Typedefs

typedef struct CDirectSoundCaptureBufferImplLPCDirectSoundCaptureBufferImpl
 

Functions

DWORD WINAPI MixerThreadRoutine (LPVOID lpParameter)
 
HRESULT WINAPI IDirectSoundCaptureBufferImpl_QueryInterface (LPDIRECTSOUNDCAPTUREBUFFER8 iface, IN REFIID riid, LPVOID *ppobj)
 
ULONG WINAPI IDirectSoundCaptureBufferImpl_AddRef (LPDIRECTSOUNDCAPTUREBUFFER8 iface)
 
ULONG WINAPI IDirectSoundCaptureBufferImpl_Release (LPDIRECTSOUNDCAPTUREBUFFER8 iface)
 
HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetCaps (LPDIRECTSOUNDCAPTUREBUFFER8 iface, LPDSCBCAPS lpDSCBCaps)
 
HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetCurrentPosition (LPDIRECTSOUNDCAPTUREBUFFER8 iface, LPDWORD lpdwCapturePosition, LPDWORD lpdwReadPosition)
 
HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetFormat (LPDIRECTSOUNDCAPTUREBUFFER8 iface, LPWAVEFORMATEX lpwfxFormat, DWORD dwSizeAllocated, LPDWORD lpdwSizeWritten)
 
HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetStatus (LPDIRECTSOUNDCAPTUREBUFFER8 iface, LPDWORD lpdwStatus)
 
HRESULT WINAPI IDirectSoundCaptureBufferImpl_Initialize (LPDIRECTSOUNDCAPTUREBUFFER8 iface, LPDIRECTSOUNDCAPTURE lpDSC, LPCDSCBUFFERDESC lpcDSCBDesc)
 
HRESULT WINAPI IDirectSoundCaptureBufferImpl_Lock (LPDIRECTSOUNDCAPTUREBUFFER8 iface, DWORD dwOffset, DWORD dwBytes, LPVOID *ppvAudioPtr1, LPDWORD pdwAudioBytes1, LPVOID *ppvAudioPtr2, LPDWORD pdwAudioBytes2, DWORD dwFlags)
 
HRESULT WINAPI IDirectSoundCaptureBufferImpl_Start (LPDIRECTSOUNDCAPTUREBUFFER8 iface, DWORD dwFlags)
 
HRESULT WINAPI IDirectSoundCaptureBufferImpl_Stop (LPDIRECTSOUNDCAPTUREBUFFER8 iface)
 
HRESULT WINAPI IDirectSoundCaptureBufferImpl_Unlock (LPDIRECTSOUNDCAPTUREBUFFER8 iface, LPVOID lpvAudioPtr1, DWORD dwAudioBytes1, LPVOID lpvAudioPtr2, DWORD dwAudioBytes2)
 
HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetObjectInPath (LPDIRECTSOUNDCAPTUREBUFFER8 iface, REFGUID rguidObject, DWORD dwIndex, REFGUID rguidInterface, LPVOID *ppObject)
 
HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetFXStatus (LPDIRECTSOUNDCAPTUREBUFFER8 iface, DWORD dwFXCount, LPDWORD pdwFXStatus)
 
HRESULT NewDirectSoundCaptureBuffer (LPDIRECTSOUNDCAPTUREBUFFER8 *OutBuffer, LPFILTERINFO Filter, LPCDSCBUFFERDESC lpcDSBufferDesc)
 

Variables

const GUID KSINTERFACESETID_Standard = {0x1A8766A0L, 0x62CE, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}}
 
const GUID KSMEDIUMSETID_Standard = {0x4747B320L, 0x62CE, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}}
 
const GUID KSDATAFORMAT_TYPE_AUDIO = {0x73647561L, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}
 
const GUID KSDATAFORMAT_SPECIFIER_WAVEFORMATEX = {0x05589f81L, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}}
 
const GUID KSPROPSETID_Connection = {0x1D58C920L, 0xAC9B, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}}
 
const GUID KSEVENTSETID_LoopedStreaming = {0x4682B940L, 0xC6EF, 0x11D0, {0x96, 0xD8, 0x00, 0xAA, 0x00, 0x51, 0xE5, 0x1D}}
 
static IDirectSoundCaptureBuffer8Vtbl vt_DirectSoundCaptureBuffer8
 

Typedef Documentation

◆ LPCDirectSoundCaptureBufferImpl

Function Documentation

◆ IDirectSoundCaptureBufferImpl_AddRef()

ULONG WINAPI IDirectSoundCaptureBufferImpl_AddRef ( LPDIRECTSOUNDCAPTUREBUFFER8  iface)

Definition at line 191 of file capturebuffer.c.

193{
194 ULONG ref;
196
197 /* increment reference count */
199
200 return ref;
201
202}
#define InterlockedIncrement
Definition: armddk.h:53
struct CDirectSoundCaptureBufferImpl * LPCDirectSoundCaptureBufferImpl
Definition: send.c:48
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59

◆ IDirectSoundCaptureBufferImpl_GetCaps()

HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetCaps ( LPDIRECTSOUNDCAPTUREBUFFER8  iface,
LPDSCBCAPS  lpDSCBCaps 
)

Definition at line 249 of file capturebuffer.c.

252{
254
255 if (!lpDSCBCaps)
256 {
257 /* invalid parameter */
258 return DSERR_INVALIDPARAM;
259 }
260
261 if (lpDSCBCaps->dwSize != sizeof(DSCBCAPS))
262 {
263 /* invalid parameter */
264 return DSERR_INVALIDPARAM;
265 }
266
267 lpDSCBCaps->dwBufferBytes = This->BufferSize;
268 lpDSCBCaps->dwReserved = 0;
269 //lpDSCBCaps->dwFlags = DSCBCAPS_WAVEMAPPED;
270
271 return DS_OK;
272}
#define DS_OK
Definition: dsound.h:116
#define DSERR_INVALIDPARAM
Definition: dsound.h:121
DWORD dwBufferBytes
Definition: dsound.h:380
DWORD dwReserved
Definition: dsound.h:381
DWORD dwSize
Definition: dsound.h:378

◆ IDirectSoundCaptureBufferImpl_GetCurrentPosition()

HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetCurrentPosition ( LPDIRECTSOUNDCAPTUREBUFFER8  iface,
LPDWORD  lpdwCapturePosition,
LPDWORD  lpdwReadPosition 
)

Definition at line 276 of file capturebuffer.c.

280{
284 DWORD Value;
285
287
288 if (!This->hPin)
289 {
290 if (lpdwCapturePosition)
291 *lpdwCapturePosition = 0;
292
293 if (lpdwReadPosition)
294 *lpdwReadPosition = 0;
295
296 DPRINT("No Audio Pin\n");
297 return DS_OK;
298 }
299
300 if (This->bMix)
301 {
302 /* read current position */
303 Value = InterlockedCompareExchange(&This->CurrentMixPosition, 0, 0);
304
305 if (lpdwCapturePosition)
306 *lpdwCapturePosition = (DWORD)Value;
307
308 if (lpdwReadPosition)
309 *lpdwReadPosition = (DWORD)Value;
310
311 return DS_OK;
312 }
313
314 /* setup audio position property request */
318
319
321
322 if (Result != ERROR_SUCCESS)
323 {
324 DPRINT("GetPosition failed with %x\n", Result);
325 return DSERR_UNSUPPORTED;
326 }
327
328 //DPRINT("Play %I64u Write %I64u \n", Position.PlayOffset, Position.WriteOffset);
329
330 if (lpdwCapturePosition)
331 *lpdwCapturePosition = (DWORD)Position.PlayOffset;
332
333 if (lpdwReadPosition)
334 *lpdwReadPosition = (DWORD)Position.WriteOffset;
335
336 return DS_OK;
337}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
DWORD SyncOverlappedDeviceIoControl(IN HANDLE Handle, IN DWORD IoControlCode, IN LPVOID InBuffer, IN DWORD InBufferSize, OUT LPVOID OutBuffer, IN DWORD OutBufferSize, OUT LPDWORD BytesTransferred OPTIONAL)
Definition: misc.c:298
#define DSERR_UNSUPPORTED
Definition: dsound.h:127
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
unsigned long DWORD
Definition: ntddk_ex.h:95
#define InterlockedCompareExchange
Definition: interlocked.h:104
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
@ KSPROPERTY_AUDIO_POSITION
Definition: ksmedia.h:1058
#define KSPROPSETID_Audio
Definition: ksmedia.h:1051
if(dx< 0)
Definition: linetemp.h:194
#define DWORD
Definition: nt_native.h:44
#define DPRINT
Definition: sndvol32.h:71
static COORD Position
Definition: mouse.c:34
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

◆ IDirectSoundCaptureBufferImpl_GetFormat()

HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetFormat ( LPDIRECTSOUNDCAPTUREBUFFER8  iface,
LPWAVEFORMATEX  lpwfxFormat,
DWORD  dwSizeAllocated,
LPDWORD  lpdwSizeWritten 
)

Definition at line 342 of file capturebuffer.c.

347{
348 DWORD FormatSize;
350
351 FormatSize = sizeof(WAVEFORMATEX) + This->Format->cbSize;
352
353 if (!lpwfxFormat && !lpdwSizeWritten)
354 {
355 /* invalid parameter */
356 return DSERR_INVALIDPARAM;
357 }
358
359 if (!lpwfxFormat)
360 {
361 /* return required format size */
362 *lpdwSizeWritten = FormatSize;
363 return DS_OK;
364 }
365 else
366 {
367 if (dwSizeAllocated >= FormatSize)
368 {
369 /* copy format */
370 CopyMemory(lpwfxFormat, This->Format, FormatSize);
371
372 if (lpdwSizeWritten)
373 *lpdwSizeWritten = FormatSize;
374
375 return DS_OK;
376 }
377 /* buffer too small */
378 if (lpdwSizeWritten)
379 *lpdwSizeWritten = 0;
380 return DSERR_INVALIDPARAM;
381 }
382}
#define CopyMemory
Definition: winbase.h:1710

◆ IDirectSoundCaptureBufferImpl_GetFXStatus()

HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetFXStatus ( LPDIRECTSOUNDCAPTUREBUFFER8  iface,
DWORD  dwFXCount,
LPDWORD  pdwFXStatus 
)

Definition at line 650 of file capturebuffer.c.

654{
656 return DSERR_INVALIDPARAM;
657}
#define UNIMPLEMENTED
Definition: debug.h:115

◆ IDirectSoundCaptureBufferImpl_GetObjectInPath()

HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetObjectInPath ( LPDIRECTSOUNDCAPTUREBUFFER8  iface,
REFGUID  rguidObject,
DWORD  dwIndex,
REFGUID  rguidInterface,
LPVOID ppObject 
)

Definition at line 637 of file capturebuffer.c.

643{
645 return DSERR_INVALIDPARAM;
646}

◆ IDirectSoundCaptureBufferImpl_GetStatus()

HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetStatus ( LPDIRECTSOUNDCAPTUREBUFFER8  iface,
LPDWORD  lpdwStatus 
)

Definition at line 386 of file capturebuffer.c.

389{
391
392 if (!lpdwStatus)
393 {
394 /* invalid parameter */
395 return DSERR_INVALIDPARAM;
396 }
397
398 /* reset flags */
399 *lpdwStatus = 0;
400
401 /* check if pin is running */
402 if (This->State == KSSTATE_RUN)
403 *lpdwStatus |= DSCBSTATUS_CAPTURING;
404
405 /* check if a looped buffer is used */
406 if (This->bLoop)
407 *lpdwStatus |= DSCBSTATUS_LOOPING;
408
409 /* done */
410 return DS_OK;
411}
#define DSCBSTATUS_LOOPING
Definition: dsound.h:397
#define DSCBSTATUS_CAPTURING
Definition: dsound.h:396
@ KSSTATE_RUN
Definition: ks.h:1218

◆ IDirectSoundCaptureBufferImpl_Initialize()

HRESULT WINAPI IDirectSoundCaptureBufferImpl_Initialize ( LPDIRECTSOUNDCAPTUREBUFFER8  iface,
LPDIRECTSOUNDCAPTURE  lpDSC,
LPCDSCBUFFERDESC  lpcDSCBDesc 
)

Definition at line 415 of file capturebuffer.c.

419{
420 /* capture buffer is already initialized */
422}
#define DSERR_ALREADYINITIALIZED
Definition: dsound.h:129

◆ IDirectSoundCaptureBufferImpl_Lock()

HRESULT WINAPI IDirectSoundCaptureBufferImpl_Lock ( LPDIRECTSOUNDCAPTUREBUFFER8  iface,
DWORD  dwOffset,
DWORD  dwBytes,
LPVOID ppvAudioPtr1,
LPDWORD  pdwAudioBytes1,
LPVOID ppvAudioPtr2,
LPDWORD  pdwAudioBytes2,
DWORD  dwFlags 
)

Definition at line 426 of file capturebuffer.c.

435{
437
438 DPRINT("This %p dwOffset %u dwBytes %u ppvAudioPtr1 %p pdwAudioBytes1 %p ppvAudioPtr2 %p pdwAudioBytes2 %p dwFlags %x This->BufferSize %u\n",
439 This, dwOffset, dwBytes, ppvAudioPtr1, pdwAudioBytes1, ppvAudioPtr2, pdwAudioBytes2, dwFlags, This->BufferSize);
440
442 {
443 *ppvAudioPtr1 = (LPVOID)This->Buffer;
444 *pdwAudioBytes1 = This->BufferSize;
445 if (ppvAudioPtr2)
446 *ppvAudioPtr2 = NULL;
447 if (pdwAudioBytes2)
448 *pdwAudioBytes2 = 0;
449
450 return DS_OK;
451 }
452 else
453 {
454 ASSERT(dwOffset < This->BufferSize);
455 ASSERT(dwBytes < This->BufferSize);
456 ASSERT(dwBytes + dwOffset <= This->BufferSize);
457
458 *ppvAudioPtr1 = This->Buffer + dwOffset;
459 *pdwAudioBytes1 = dwBytes;
460 if (ppvAudioPtr2)
461 *ppvAudioPtr2 = NULL;
462 if (pdwAudioBytes2)
463 *pdwAudioBytes2 = 0;
464
465 return DS_OK;
466 }
467}
#define DSBLOCK_ENTIREBUFFER
Definition: dsound.h:204
#define ASSERT(a)
Definition: mode.c:44
#define LPVOID
Definition: nt_native.h:45
_In_ DWORD _In_ DWORD dwOffset
Definition: ntgdi.h:2033
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176

◆ IDirectSoundCaptureBufferImpl_QueryInterface()

HRESULT WINAPI IDirectSoundCaptureBufferImpl_QueryInterface ( LPDIRECTSOUNDCAPTUREBUFFER8  iface,
IN REFIID  riid,
LPVOID ppobj 
)

Definition at line 143 of file capturebuffer.c.

147{
148 LPOLESTR pStr;
150
151 /* check if requested interface is supported */
153 IsEqualIID(riid, &IID_IDirectSoundCaptureBuffer) ||
154 IsEqualIID(riid, &IID_IDirectSoundCaptureBuffer8))
155 {
156 *ppobj = (LPVOID)&This->lpVtbl;
158 return S_OK;
159 }
160
161 /* check if the interface is supported */
162 if (IsEqualIID(riid, &IID_IDirectSoundNotify))
163 {
164 if (!This->Notify)
165 {
166 HRESULT hr = NewDirectSoundNotify(&This->Notify, This->bLoop, This->bMix, This->hPin, This->BufferSize);
167 if (FAILED(hr))
168 return hr;
169
170 *ppobj = (LPVOID)This->Notify;
171 return S_OK;
172 }
173
174 /* increment reference count on existing notify object */
176 *ppobj = (LPVOID)This->Notify;
177 return S_OK;
178 }
179
180 /* interface not supported */
181 if (SUCCEEDED(StringFromIID(riid, &pStr)))
182 {
183 DPRINT("No Interface for class %s\n", pStr);
184 CoTaskMemFree(pStr);
185 }
186 return E_NOINTERFACE;
187}
const GUID IID_IUnknown
HRESULT NewDirectSoundNotify(LPDIRECTSOUNDNOTIFY *Notify, BOOL bLoop, BOOL bMix, HANDLE hPin, DWORD BufferSize)
Definition: notify.c:232
#define IDirectSoundNotify_AddRef(p)
Definition: dsound.h:893
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
static LPOLESTR
Definition: stg_prop.c:27
_Check_return_ HRESULT WINAPI StringFromIID(_In_ REFIID rclsid, _Outptr_ LPOLESTR *lplpsz)
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
HRESULT hr
Definition: shlfolder.c:183
#define E_NOINTERFACE
Definition: winerror.h:2364

◆ IDirectSoundCaptureBufferImpl_Release()

ULONG WINAPI IDirectSoundCaptureBufferImpl_Release ( LPDIRECTSOUNDCAPTUREBUFFER8  iface)

Definition at line 206 of file capturebuffer.c.

208{
209 ULONG ref;
211
212 /* release reference count */
213 ref = InterlockedDecrement(&(This->ref));
214
215 if (!ref)
216 {
217 if (This->hPin)
218 {
219 /* close pin handle */
220 CloseHandle(This->hPin);
221 }
222
223 if (This->hStopEvent)
224 {
225 /* close stop event handle */
226 CloseHandle(This->hStopEvent);
227 }
228
229 if (This->MixBuffer)
230 {
231 /* free mix buffer */
232 HeapFree(GetProcessHeap(), 0, This->MixBuffer);
233 }
234
235 /* free capture buffer */
236 HeapFree(GetProcessHeap(), 0, This->Buffer);
237 /* free wave format */
238 HeapFree(GetProcessHeap(), 0, This->Format);
239 /* free capture buffer */
241 }
242
243 return ref;
244}
#define InterlockedDecrement
Definition: armddk.h:52
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735

◆ IDirectSoundCaptureBufferImpl_Start()

HRESULT WINAPI IDirectSoundCaptureBufferImpl_Start ( LPDIRECTSOUNDCAPTUREBUFFER8  iface,
DWORD  dwFlags 
)

Definition at line 471 of file capturebuffer.c.

474{
478 OVERLAPPED Overlapped;
481
483
484 DPRINT("IDirectSoundCaptureBufferImpl_Start Flags %x\n", dwFlags);
486
487 /* check if pin is already running */
488 if (This->State == KSSTATE_RUN)
489 return DS_OK;
490
491
492 /* check if there is a pin instance */
493 if (!This->hPin)
494 return DSERR_GENERIC;
495
496 /* setup request */
501
502 /* set pin to run */
504
506
507 if (Result == ERROR_SUCCESS)
508 {
509 /* store result */
510 This->State = State;
511 }
512
513 /* initialize overlapped struct */
514 ZeroMemory(&Overlapped, sizeof(OVERLAPPED));
515 Overlapped.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
516
517 /* clear stream header */
519
520 /* initialize stream header */
521 Header.FrameExtent = This->BufferSize;
522 Header.DataUsed = 0;
523 Header.Data = (This->bMix ? This->MixBuffer : This->Buffer);
524 Header.Size = sizeof(KSSTREAM_HEADER);
525 Header.PresentationTime.Numerator = 1;
526 Header.PresentationTime.Denominator = 1;
527
529
530 if (Result != ERROR_SUCCESS)
531 {
532 DPRINT("Failed submit buffer with %lx\n", Result);
533 return DSERR_GENERIC;
534 }
535
536 if (This->bMix)
537 {
538 if (!This->hStopEvent)
539 {
540 /* create stop event */
541 This->hStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
542 if (!This->hStopEvent)
543 {
544 DPRINT1("Failed to create event object with %x\n", GetLastError());
545 return DSERR_GENERIC;
546 }
547 }
548
549 /* set state to stop false */
550 This->StopMixerThread = FALSE;
551
553 if (!hThread)
554 {
555 DPRINT1("Failed to create thread with %x\n", GetLastError());
556 return DSERR_GENERIC;
557 }
558
559 /* close thread handle */
561 }
562
563
564 return DS_OK;
565}
#define DPRINT1
Definition: precomp.h:8
const GUID KSPROPSETID_Connection
Definition: capturebuffer.c:17
DWORD WINAPI MixerThreadRoutine(LPVOID lpParameter)
Definition: capturebuffer.c:48
Definition: Header.h:9
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
#define DSCBSTART_LOOPING
Definition: dsound.h:393
#define DSERR_GENERIC
Definition: dsound.h:123
#define KSPROPERTY_TYPE_SET
Definition: dmksctrl.h:43
@ KSPROPERTY_CONNECTION_STATE
Definition: ks.h:349
KSSTATE
Definition: ks.h:1214
#define IOCTL_KS_WRITE_STREAM
Definition: ks.h:139
HANDLE hThread
Definition: wizard.c:28
HANDLE hEvent
Definition: winbase.h:820
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET _In_opt_ PWDF_MEMORY_DESCRIPTOR _Out_opt_ PULONG BytesTransferred
Definition: wdfusb.h:1342
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CreateEvent
Definition: winbase.h:3748

◆ IDirectSoundCaptureBufferImpl_Stop()

HRESULT WINAPI IDirectSoundCaptureBufferImpl_Stop ( LPDIRECTSOUNDCAPTUREBUFFER8  iface)

Definition at line 569 of file capturebuffer.c.

570{
574
576
577 if (This->State == KSSTATE_STOP)
578 {
579 /* stream has already been stopped */
580 return DS_OK;
581 }
582
583 if (!This->hPin)
584 return DSERR_GENERIC;
585
586 /* setup request */
591
592
593 /* set pin to stop */
595
597
598
599 if (This->bMix)
600 {
601 /* sanity check */
602 ASSERT(This->hStopEvent);
603 /* reset event */
604 ResetEvent(This->hStopEvent);
605 /* signal event to stop */
606 This->StopMixerThread = TRUE;
607 /* Wait for the event to stop */
608 WaitForSingleObject(This->hStopEvent, INFINITE);
609 }
610
611
612 if (Result == ERROR_SUCCESS)
613 {
614 /* store result */
615 This->State = State;
616 return DS_OK;
617 }
618
619 DPRINT("Failed to stop pin\n");
620 return DSERR_GENERIC;
621}
#define INFINITE
Definition: serial.h:102
@ KSSTATE_STOP
Definition: ks.h:1215
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent(IN HANDLE hEvent)
Definition: synch.c:714

◆ IDirectSoundCaptureBufferImpl_Unlock()

HRESULT WINAPI IDirectSoundCaptureBufferImpl_Unlock ( LPDIRECTSOUNDCAPTUREBUFFER8  iface,
LPVOID  lpvAudioPtr1,
DWORD  dwAudioBytes1,
LPVOID  lpvAudioPtr2,
DWORD  dwAudioBytes2 
)

Definition at line 625 of file capturebuffer.c.

631{
632 return DS_OK;
633}

◆ MixerThreadRoutine()

DWORD WINAPI MixerThreadRoutine ( LPVOID  lpParameter)

Definition at line 48 of file capturebuffer.c.

50{
53 DWORD Result, MixPosition, BufferPosition, BytesWritten, BytesRead, MixLength, BufferLength;
55
56 /* setup audio position property request */
60
61 MixPosition = 0;
62 BufferPosition = 0;
63 do
64 {
65 /* query current position */
67
68 /* sanity check */
70
71 /* FIXME implement samplerate conversion */
72 ASSERT(This->MixFormat.nSamplesPerSec == This->Format->nSamplesPerSec);
73
74 /* FIXME implement bitrate conversion */
75 ASSERT(This->MixFormat.wBitsPerSample == This->Format->wBitsPerSample);
76
77 /* sanity check */
78 ASSERT(BufferPosition <= This->BufferSize);
79 ASSERT(MixPosition <= This->MixBufferSize);
80
81 if (BufferPosition == This->BufferSize)
82 {
83 /* restart from front */
84 BufferPosition = 0;
85 }
86
87 if (MixPosition == This->MixBufferSize)
88 {
89 /* restart from front */
90 MixPosition = 0;
91 }
92
93 if (This->MixFormat.nChannels != This->Format->nChannels)
94 {
95 if ((DWORD)Position.PlayOffset >= MixPosition)
96 {
97 /* calculate buffer position difference */
98 MixLength = Position.PlayOffset - MixPosition;
99 }
100 else
101 {
102 /* buffer overlap */
103 MixLength = This->MixBufferSize - MixPosition;
104 }
105
106 BufferLength = This->BufferSize - BufferPosition;
107
108 /* convert the format */
109 PerformChannelConversion(&This->MixBuffer[MixPosition], MixLength, &BytesRead, This->MixFormat.nChannels, This->Format->nChannels, This->Format->wBitsPerSample, &This->Buffer[BufferPosition], BufferLength, &BytesWritten);
110
111 /* update buffer offsets */
112 MixPosition += BytesRead;
113 BufferPosition += BytesWritten;
114 DPRINT("MixPosition %u BufferPosition %u BytesRead %u BytesWritten %u MixLength %u BufferLength %u\n", MixPosition, BufferPosition, BytesRead, BytesWritten, MixLength, BufferLength);
115 }
116
117 /* Notify Events */
118 if (This->Notify)
119 {
120 DoNotifyPositionEvents(This->Notify, This->CurrentMixPosition, BufferPosition);
121 }
122
123 /* update offset */
124 InterlockedExchange(&This->CurrentMixPosition, (LONG)BufferPosition);
125
126 /* FIXME use timer */
127 Sleep(10);
128
129 }while(InterlockedCompareExchange(&This->StopMixerThread, 0, 0) == 0);
130
131
132 /* signal stop event */
133 SetEvent(This->hStopEvent);
134
135 /* done */
136 return 0;
137}
#define InterlockedExchange
Definition: armddk.h:54
VOID PerformChannelConversion(PUCHAR Buffer, ULONG BufferLength, PULONG BytesRead, ULONG OldChannels, ULONG NewChannels, ULONG BitsPerSample, PUCHAR Result, ULONG ResultLength, PULONG BytesWritten)
Definition: misc.c:18
VOID DoNotifyPositionEvents(LPDIRECTSOUNDNOTIFY iface, DWORD OldPosition, DWORD NewPosition)
Definition: notify.c:190
long LONG
Definition: pedump.c:60
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:960
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870

Referenced by IDirectSoundCaptureBufferImpl_Start().

◆ NewDirectSoundCaptureBuffer()

HRESULT NewDirectSoundCaptureBuffer ( LPDIRECTSOUNDCAPTUREBUFFER8 OutBuffer,
LPFILTERINFO  Filter,
LPCDSCBUFFERDESC  lpcDSBufferDesc 
)

Definition at line 687 of file capturebuffer.c.

691{
692 DWORD FormatSize, MixBufferSize;
693 ULONG DeviceId = 0, PinId;
695 WAVEFORMATEX MixFormat;
696
698
699 if (!This)
700 {
701 /* not enough memory */
702 return DSERR_OUTOFMEMORY;
703 }
704
705 /* calculate format size */
706 FormatSize = sizeof(WAVEFORMATEX) + lpcDSBufferDesc->lpwfxFormat->cbSize;
707 /* allocate format struct */
708 This->Format = HeapAlloc(GetProcessHeap(), 0, FormatSize);
709 if (!This->Format)
710 {
711 /* not enough memory */
713 return DSERR_OUTOFMEMORY;
714 }
715
716 /* sanity check */
717 ASSERT(lpcDSBufferDesc->dwBufferBytes);
718
719 /* allocate capture buffer */
720 This->Buffer = HeapAlloc(GetProcessHeap(), 0, lpcDSBufferDesc->dwBufferBytes);
721 if (!This->Buffer)
722 {
723 /* not enough memory */
724 HeapFree(GetProcessHeap(), 0, This->Format);
726 return DSERR_OUTOFMEMORY;
727 }
728
729 /* store buffer size */
730 This->BufferSize = lpcDSBufferDesc->dwBufferBytes;
731 ASSERT(lpcDSBufferDesc->lpwfxFormat->cbSize == 0);
732
733 do
734 {
735 /* try all available recording pins on that filter */
736 PinId = GetPinIdFromFilter(Filter, TRUE, DeviceId);
737
738 if (PinId == ULONG_MAX)
739 break;
740
741 Result = OpenPin(Filter->hFilter, PinId, lpcDSBufferDesc->lpwfxFormat, &This->hPin, TRUE);
742 if (Result == ERROR_SUCCESS)
743 break;
744
745 DeviceId++;
746 }while(TRUE);
747
748 if (Result != ERROR_SUCCESS)
749 {
750 /* failed to instantiate the capture pin with the native format
751 * try to compute a compatible format and use that
752 * we could use the mixer api for this purpose but... the kmixer isnt working very good atm
753 */
754
755 DeviceId = 0;
756 do
757 {
758 /* try all available recording pins on that filter */
759 PinId = GetPinIdFromFilter(Filter, TRUE, DeviceId);
760 DPRINT("PinId %u DeviceId %u\n", PinId, DeviceId);
761
762 if (PinId == ULONG_MAX)
763 break;
764
765 if (CreateCompatiblePin(Filter->hFilter, PinId, TRUE, lpcDSBufferDesc->lpwfxFormat, &MixFormat, &This->hPin))
766 {
767 This->bMix = TRUE;
768 CopyMemory(&This->MixFormat, &MixFormat, sizeof(WAVEFORMATEX));
769 break;
770 }
771
772 DeviceId++;
773 }while(TRUE);
774
775
776 if (!This->bMix)
777 {
778 /* FIXME should not happen */
779 DPRINT("failed to compute a compatible format\n");
780 HeapFree(GetProcessHeap(), 0, This->MixBuffer);
781 HeapFree(GetProcessHeap(), 0, This->Buffer);
782 HeapFree(GetProcessHeap(), 0, This->Format);
784 return DSERR_GENERIC;
785 }
786
787 MixBufferSize = lpcDSBufferDesc->dwBufferBytes;
788 MixBufferSize /= lpcDSBufferDesc->lpwfxFormat->nChannels;
789 MixBufferSize /= (lpcDSBufferDesc->lpwfxFormat->wBitsPerSample/8);
790
791 MixBufferSize *= This->MixFormat.nChannels;
792 MixBufferSize *= (This->MixFormat.wBitsPerSample/8);
793
794 /* allocate buffer for mixing */
795 This->MixBuffer = HeapAlloc(GetProcessHeap(), 0, MixBufferSize);
796 if (!This->Buffer)
797 {
798 /* not enough memory */
799 CloseHandle(This->hPin);
800 HeapFree(GetProcessHeap(), 0, This->Buffer);
801 HeapFree(GetProcessHeap(), 0, This->Format);
803 return DSERR_OUTOFMEMORY;
804 }
805 This->MixBufferSize = MixBufferSize;
806 DPRINT1("MixBufferSize %u BufferSize %u\n", MixBufferSize, This->BufferSize);
807 }
808
809 /* initialize capture buffer */
810 This->ref = 1;
812 This->Filter = Filter;
813 This->State = KSSTATE_STOP;
814 This->bLoop = TRUE;
815
816 RtlMoveMemory(This->Format, lpcDSBufferDesc->lpwfxFormat, FormatSize);
817
819 return DS_OK;
820}
static IDirectSoundCaptureBuffer8Vtbl vt_DirectSoundCaptureBuffer8
ULONG GetPinIdFromFilter(LPFILTERINFO Filter, BOOL bCapture, ULONG Offset)
Definition: devicelist.c:13
DWORD OpenPin(HANDLE hFilter, ULONG PinId, LPWAVEFORMATEX WaveFormatEx, PHANDLE hPin, BOOL bLoop)
Definition: misc.c:212
BOOL CreateCompatiblePin(IN HANDLE hFilter, IN DWORD PinId, IN BOOL bLoop, IN LPWAVEFORMATEX WaveFormatEx, OUT LPWAVEFORMATEX WaveFormatOut, OUT PHANDLE hPin)
Definition: misc.c:517
#define HeapAlloc
Definition: compat.h:733
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
struct IDirectSoundCaptureBuffer8 * LPDIRECTSOUNDCAPTUREBUFFER8
Definition: dsound.h:100
#define DSERR_OUTOFMEMORY
Definition: dsound.h:125
_Must_inspect_result_ _In_opt_ PFLT_FILTER Filter
Definition: fltkernel.h:1801
#define ULONG_MAX
Definition: limits.h:44
_In_ UCHAR _In_ ULONG _Out_ PUCHAR _Outptr_result_bytebuffer_ OutBufferLength PVOID * OutBuffer
Definition: scsi.h:4071
DWORD dwBufferBytes
Definition: dsound.h:359
LPWAVEFORMATEX lpwfxFormat
Definition: dsound.h:361
WORD cbSize
Definition: mmreg.h:84
WORD nChannels
Definition: mmreg.h:79
WORD wBitsPerSample
Definition: mmreg.h:83
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264

Referenced by CDirectSoundCapture_fnCreateCaptureBuffer().

Variable Documentation

◆ KSDATAFORMAT_SPECIFIER_WAVEFORMATEX

const GUID KSDATAFORMAT_SPECIFIER_WAVEFORMATEX = {0x05589f81L, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}}

Definition at line 16 of file capturebuffer.c.

◆ KSDATAFORMAT_TYPE_AUDIO

const GUID KSDATAFORMAT_TYPE_AUDIO = {0x73647561L, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}

Definition at line 15 of file capturebuffer.c.

◆ KSEVENTSETID_LoopedStreaming

const GUID KSEVENTSETID_LoopedStreaming = {0x4682B940L, 0xC6EF, 0x11D0, {0x96, 0xD8, 0x00, 0xAA, 0x00, 0x51, 0xE5, 0x1D}}

Definition at line 18 of file capturebuffer.c.

◆ KSINTERFACESETID_Standard

const GUID KSINTERFACESETID_Standard = {0x1A8766A0L, 0x62CE, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}}

Definition at line 13 of file capturebuffer.c.

◆ KSMEDIUMSETID_Standard

const GUID KSMEDIUMSETID_Standard = {0x4747B320L, 0x62CE, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}}

Definition at line 14 of file capturebuffer.c.

◆ KSPROPSETID_Connection

const GUID KSPROPSETID_Connection = {0x1D58C920L, 0xAC9B, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}}

◆ vt_DirectSoundCaptureBuffer8

IDirectSoundCaptureBuffer8Vtbl vt_DirectSoundCaptureBuffer8
static
Initial value:
=
{
}
HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetCaps(LPDIRECTSOUNDCAPTUREBUFFER8 iface, LPDSCBCAPS lpDSCBCaps)
ULONG WINAPI IDirectSoundCaptureBufferImpl_Release(LPDIRECTSOUNDCAPTUREBUFFER8 iface)
ULONG WINAPI IDirectSoundCaptureBufferImpl_AddRef(LPDIRECTSOUNDCAPTUREBUFFER8 iface)
HRESULT WINAPI IDirectSoundCaptureBufferImpl_Initialize(LPDIRECTSOUNDCAPTUREBUFFER8 iface, LPDIRECTSOUNDCAPTURE lpDSC, LPCDSCBUFFERDESC lpcDSCBDesc)
HRESULT WINAPI IDirectSoundCaptureBufferImpl_Stop(LPDIRECTSOUNDCAPTUREBUFFER8 iface)
HRESULT WINAPI IDirectSoundCaptureBufferImpl_Lock(LPDIRECTSOUNDCAPTUREBUFFER8 iface, DWORD dwOffset, DWORD dwBytes, LPVOID *ppvAudioPtr1, LPDWORD pdwAudioBytes1, LPVOID *ppvAudioPtr2, LPDWORD pdwAudioBytes2, DWORD dwFlags)
HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetStatus(LPDIRECTSOUNDCAPTUREBUFFER8 iface, LPDWORD lpdwStatus)
HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetCurrentPosition(LPDIRECTSOUNDCAPTUREBUFFER8 iface, LPDWORD lpdwCapturePosition, LPDWORD lpdwReadPosition)
HRESULT WINAPI IDirectSoundCaptureBufferImpl_Unlock(LPDIRECTSOUNDCAPTUREBUFFER8 iface, LPVOID lpvAudioPtr1, DWORD dwAudioBytes1, LPVOID lpvAudioPtr2, DWORD dwAudioBytes2)
HRESULT WINAPI IDirectSoundCaptureBufferImpl_QueryInterface(LPDIRECTSOUNDCAPTUREBUFFER8 iface, IN REFIID riid, LPVOID *ppobj)
HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetObjectInPath(LPDIRECTSOUNDCAPTUREBUFFER8 iface, REFGUID rguidObject, DWORD dwIndex, REFGUID rguidInterface, LPVOID *ppObject)
HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetFXStatus(LPDIRECTSOUNDCAPTUREBUFFER8 iface, DWORD dwFXCount, LPDWORD pdwFXStatus)
HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetFormat(LPDIRECTSOUNDCAPTUREBUFFER8 iface, LPWAVEFORMATEX lpwfxFormat, DWORD dwSizeAllocated, LPDWORD lpdwSizeWritten)
HRESULT WINAPI IDirectSoundCaptureBufferImpl_Start(LPDIRECTSOUNDCAPTUREBUFFER8 iface, DWORD dwFlags)

Definition at line 660 of file capturebuffer.c.

Referenced by NewDirectSoundCaptureBuffer().