2 * Direct Sound Audio Renderer
4 * Copyright 2004 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "quartz_private.h"
24 #include "control_private.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
41 static const WCHAR wcsInputPinName
[] = {'i','n','p','u','t',' ','p','i','n',0};
43 static const IBaseFilterVtbl DSoundRender_Vtbl
;
44 static const IPinVtbl DSoundRender_InputPin_Vtbl
;
45 static const IMemInputPinVtbl MemInputPin_Vtbl
;
46 static const IBasicAudioVtbl IBasicAudio_Vtbl
;
47 static const IReferenceClockVtbl IReferenceClock_Vtbl
;
48 static const IMediaSeekingVtbl IMediaSeeking_Vtbl
;
50 typedef struct DSoundRenderImpl
52 const IBaseFilterVtbl
* lpVtbl
;
53 const IBasicAudioVtbl
*IBasicAudio_vtbl
;
54 const IReferenceClockVtbl
*IReferenceClock_vtbl
;
57 CRITICAL_SECTION csFilter
;
59 REFERENCE_TIME rtStreamStart
;
60 IReferenceClock
* pClock
;
61 FILTER_INFO filterInfo
;
67 LPDIRECTSOUNDBUFFER dsbuffer
;
74 REFERENCE_TIME play_time
;
75 MediaSeekingImpl mediaSeeking
;
81 static HRESULT
sound_mod_stop(IBaseFilter
*iface
)
83 FIXME("(%p) stub\n", iface
);
87 static HRESULT
sound_mod_start(IBaseFilter
*iface
)
89 FIXME("(%p) stub\n", iface
);
93 static HRESULT
sound_mod_rate(IBaseFilter
*iface
)
95 FIXME("(%p) stub\n", iface
);
100 static HRESULT
DSoundRender_InputPin_Construct(const PIN_INFO
* pPinInfo
, SAMPLEPROC pSampleProc
, LPVOID pUserData
, QUERYACCEPTPROC pQueryAccept
, LPCRITICAL_SECTION pCritSec
, IPin
** ppPin
)
106 if (pPinInfo
->dir
!= PINDIR_INPUT
)
108 ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo
->dir
);
112 pPinImpl
= CoTaskMemAlloc(sizeof(*pPinImpl
));
115 return E_OUTOFMEMORY
;
117 if (SUCCEEDED(InputPin_Init(pPinInfo
, pSampleProc
, pUserData
, pQueryAccept
, pCritSec
, pPinImpl
)))
119 pPinImpl
->pin
.lpVtbl
= &DSoundRender_InputPin_Vtbl
;
120 pPinImpl
->lpVtblMemInput
= &MemInputPin_Vtbl
;
122 *ppPin
= (IPin
*)(&pPinImpl
->pin
.lpVtbl
);
126 CoTaskMemFree(pPinImpl
);
131 static inline HRESULT
DSoundRender_GetPos(DSoundRenderImpl
*This
, DWORD
*pPlayPos
, DWORD
*pWritePos
, REFERENCE_TIME
*pRefTime
)
135 EnterCriticalSection(&This
->csFilter
);
137 hr
= IDirectSoundBuffer_GetCurrentPosition(This
->dsbuffer
, pPlayPos
, pWritePos
);
140 DWORD play_pos
= *pPlayPos
;
142 if (play_pos
< This
->last_play_pos
)
144 This
->last_play_pos
= play_pos
;
146 /* If we're really falling behind, kick the play time back */
147 if ((This
->play_loops
*This
->buf_size
)+play_pos
>=
148 (This
->write_loops
*This
->buf_size
)+This
->write_pos
)
153 REFERENCE_TIME play_time
;
154 play_time
= ((REFERENCE_TIME
)This
->play_loops
*10000000) +
155 ((REFERENCE_TIME
)play_pos
*10000000/This
->buf_size
);
157 /* Don't let time run backwards */
158 if(play_time
-This
->play_time
> 0)
159 This
->play_time
= play_time
;
163 *pRefTime
= This
->play_time
;
167 LeaveCriticalSection(&This
->csFilter
);
172 static HRESULT
DSoundRender_SendSampleData(DSoundRenderImpl
* This
, const BYTE
*data
, DWORD size
)
175 LPBYTE lpbuf1
= NULL
;
176 LPBYTE lpbuf2
= NULL
;
180 DWORD play_pos
,buf_free
;
183 hr
= DSoundRender_GetPos(This
, &play_pos
, NULL
, NULL
);
186 ERR("GetPos returned error: %x\n", hr
);
189 if (This
->write_pos
<= play_pos
)
190 buf_free
= play_pos
-This
->write_pos
;
192 buf_free
= This
->buf_size
- This
->write_pos
+ play_pos
;
194 /* Wait for enough of the buffer to empty before filling it */
195 if(buf_free
< This
->buf_size
/4)
201 size2
= min(buf_free
, size
);
202 hr
= IDirectSoundBuffer_Lock(This
->dsbuffer
, This
->write_pos
, size2
, (LPVOID
*)&lpbuf1
, &dwsize1
, (LPVOID
*)&lpbuf2
, &dwsize2
, 0);
204 ERR("Unable to lock sound buffer! (%x)\n", hr
);
207 /* TRACE("write_pos=%d, size=%d, sz1=%d, sz2=%d\n", This->write_pos, size2, dwsize1, dwsize2); */
209 memcpy(lpbuf1
, data
, dwsize1
);
211 memcpy(lpbuf2
, data
+ dwsize1
, dwsize2
);
213 hr
= IDirectSoundBuffer_Unlock(This
->dsbuffer
, lpbuf1
, dwsize1
, lpbuf2
, dwsize2
);
215 ERR("Unable to unlock sound buffer! (%x)\n", hr
);
217 size
-= dwsize1
+ dwsize2
;
218 data
+= dwsize1
+ dwsize2
;
219 This
->write_pos
+= dwsize1
+ dwsize2
;
220 if (This
->write_pos
>= This
->buf_size
)
222 This
->write_pos
-= This
->buf_size
;
225 } while (size
&& This
->state
== State_Running
);
230 static HRESULT
DSoundRender_Sample(LPVOID iface
, IMediaSample
* pSample
)
232 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
233 LPBYTE pbSrcStream
= NULL
;
234 long cbSrcStream
= 0;
235 REFERENCE_TIME tStart
, tStop
;
238 TRACE("%p %p\n", iface
, pSample
);
240 if (This
->state
!= State_Running
)
241 return VFW_E_WRONG_STATE
;
243 hr
= IMediaSample_GetPointer(pSample
, &pbSrcStream
);
246 ERR("Cannot get pointer to sample data (%x)\n", hr
);
250 hr
= IMediaSample_GetTime(pSample
, &tStart
, &tStop
);
252 ERR("Cannot get sample time (%x)\n", hr
);
254 cbSrcStream
= IMediaSample_GetActualDataLength(pSample
);
255 TRACE("Sample data ptr = %p, size = %ld\n", pbSrcStream
, cbSrcStream
);
257 #if 0 /* For debugging purpose */
260 for(i
= 0; i
< cbSrcStream
; i
++)
262 if ((i
!=0) && !(i
%16))
264 TRACE("%02x ", pbSrcStream
[i
]);
270 return DSoundRender_SendSampleData(This
, pbSrcStream
, cbSrcStream
);
273 static HRESULT
DSoundRender_QueryAccept(LPVOID iface
, const AM_MEDIA_TYPE
* pmt
)
275 WAVEFORMATEX
* format
= (WAVEFORMATEX
*)pmt
->pbFormat
;
276 TRACE("wFormatTag = %x %x\n", format
->wFormatTag
, WAVE_FORMAT_PCM
);
277 TRACE("nChannels = %d\n", format
->nChannels
);
278 TRACE("nSamplesPerSec = %d\n", format
->nAvgBytesPerSec
);
279 TRACE("nAvgBytesPerSec = %d\n", format
->nAvgBytesPerSec
);
280 TRACE("nBlockAlign = %d\n", format
->nBlockAlign
);
281 TRACE("wBitsPerSample = %d\n", format
->wBitsPerSample
);
283 if (IsEqualIID(&pmt
->majortype
, &MEDIATYPE_Audio
) && IsEqualIID(&pmt
->subtype
, &MEDIASUBTYPE_PCM
))
288 HRESULT
DSoundRender_create(IUnknown
* pUnkOuter
, LPVOID
* ppv
)
292 DSoundRenderImpl
* pDSoundRender
;
294 TRACE("(%p, %p)\n", pUnkOuter
, ppv
);
299 return CLASS_E_NOAGGREGATION
;
301 pDSoundRender
= CoTaskMemAlloc(sizeof(DSoundRenderImpl
));
303 return E_OUTOFMEMORY
;
304 ZeroMemory(pDSoundRender
, sizeof(DSoundRenderImpl
));
306 pDSoundRender
->lpVtbl
= &DSoundRender_Vtbl
;
307 pDSoundRender
->IBasicAudio_vtbl
= &IBasicAudio_Vtbl
;
308 pDSoundRender
->IReferenceClock_vtbl
= &IReferenceClock_Vtbl
;
309 pDSoundRender
->refCount
= 1;
310 InitializeCriticalSection(&pDSoundRender
->csFilter
);
311 pDSoundRender
->csFilter
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": DSoundRenderImpl.csFilter");
312 pDSoundRender
->state
= State_Stopped
;
314 pDSoundRender
->ppPins
= CoTaskMemAlloc(1 * sizeof(IPin
*));
315 if (!pDSoundRender
->ppPins
)
317 pDSoundRender
->csFilter
.DebugInfo
->Spare
[0] = 0;
318 DeleteCriticalSection(&pDSoundRender
->csFilter
);
319 CoTaskMemFree(pDSoundRender
);
320 return E_OUTOFMEMORY
;
323 /* construct input pin */
324 piInput
.dir
= PINDIR_INPUT
;
325 piInput
.pFilter
= (IBaseFilter
*)pDSoundRender
;
326 lstrcpynW(piInput
.achName
, wcsInputPinName
, sizeof(piInput
.achName
) / sizeof(piInput
.achName
[0]));
327 hr
= DSoundRender_InputPin_Construct(&piInput
, DSoundRender_Sample
, (LPVOID
)pDSoundRender
, DSoundRender_QueryAccept
, &pDSoundRender
->csFilter
, (IPin
**)&pDSoundRender
->pInputPin
);
331 hr
= DirectSoundCreate(NULL
, &pDSoundRender
->dsound
, NULL
);
333 ERR("Cannot create Direct Sound object (%x)\n", hr
);
338 MediaSeekingImpl_Init((IBaseFilter
*)pDSoundRender
, sound_mod_stop
, sound_mod_start
, sound_mod_rate
, &pDSoundRender
->mediaSeeking
, &pDSoundRender
->csFilter
);
339 pDSoundRender
->mediaSeeking
.lpVtbl
= &IMediaSeeking_Vtbl
;
341 pDSoundRender
->ppPins
[0] = (IPin
*)pDSoundRender
->pInputPin
;
342 *ppv
= (LPVOID
)pDSoundRender
;
346 if (pDSoundRender
->pInputPin
)
347 IPin_Release((IPin
*)pDSoundRender
->pInputPin
);
348 CoTaskMemFree(pDSoundRender
->ppPins
);
349 pDSoundRender
->csFilter
.DebugInfo
->Spare
[0] = 0;
350 DeleteCriticalSection(&pDSoundRender
->csFilter
);
351 CoTaskMemFree(pDSoundRender
);
357 static HRESULT WINAPI
DSoundRender_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
359 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
360 TRACE("(%p, %p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
364 if (IsEqualIID(riid
, &IID_IUnknown
))
366 else if (IsEqualIID(riid
, &IID_IPersist
))
368 else if (IsEqualIID(riid
, &IID_IMediaFilter
))
370 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
372 else if (IsEqualIID(riid
, &IID_IBasicAudio
))
373 *ppv
= (LPVOID
)&(This
->IBasicAudio_vtbl
);
374 else if (IsEqualIID(riid
, &IID_IReferenceClock
))
375 *ppv
= (LPVOID
)&(This
->IReferenceClock_vtbl
);
376 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
377 *ppv
= &This
->mediaSeeking
.lpVtbl
;
381 IUnknown_AddRef((IUnknown
*)(*ppv
));
385 if (!IsEqualIID(riid
, &IID_IPin
))
386 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
388 return E_NOINTERFACE
;
391 static ULONG WINAPI
DSoundRender_AddRef(IBaseFilter
* iface
)
393 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
394 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
396 TRACE("(%p/%p)->() AddRef from %d\n", This
, iface
, refCount
- 1);
401 static ULONG WINAPI
DSoundRender_Release(IBaseFilter
* iface
)
403 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
404 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
406 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
413 IReferenceClock_Release(This
->pClock
);
416 IDirectSoundBuffer_Release(This
->dsbuffer
);
417 This
->dsbuffer
= NULL
;
419 IDirectSound_Release(This
->dsound
);
422 if (SUCCEEDED(IPin_ConnectedTo(This
->ppPins
[0], &pConnectedTo
)))
424 IPin_Disconnect(pConnectedTo
);
425 IPin_Release(pConnectedTo
);
427 IPin_Disconnect(This
->ppPins
[0]);
429 IPin_Release(This
->ppPins
[0]);
431 CoTaskMemFree(This
->ppPins
);
433 This
->IBasicAudio_vtbl
= NULL
;
435 This
->csFilter
.DebugInfo
->Spare
[0] = 0;
436 DeleteCriticalSection(&This
->csFilter
);
438 TRACE("Destroying Audio Renderer\n");
447 /** IPersist methods **/
449 static HRESULT WINAPI
DSoundRender_GetClassID(IBaseFilter
* iface
, CLSID
* pClsid
)
451 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
452 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClsid
);
454 *pClsid
= CLSID_DSoundRender
;
459 /** IMediaFilter methods **/
461 static HRESULT WINAPI
DSoundRender_Stop(IBaseFilter
* iface
)
464 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
466 TRACE("(%p/%p)->()\n", This
, iface
);
468 EnterCriticalSection(&This
->csFilter
);
473 hr
= IDirectSoundBuffer_GetStatus(This
->dsbuffer
, &state
);
476 if (state
& DSBSTATUS_PLAYING
)
477 hr
= IDirectSoundBuffer_Stop(This
->dsbuffer
);
481 This
->state
= State_Stopped
;
483 LeaveCriticalSection(&This
->csFilter
);
488 static HRESULT WINAPI
DSoundRender_Pause(IBaseFilter
* iface
)
491 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
493 TRACE("(%p/%p)->()\n", This
, iface
);
495 EnterCriticalSection(&This
->csFilter
);
500 hr
= IDirectSoundBuffer_GetStatus(This
->dsbuffer
, &state
);
503 if (state
& DSBSTATUS_PLAYING
)
504 hr
= IDirectSoundBuffer_Stop(This
->dsbuffer
);
508 This
->state
= State_Paused
;
510 LeaveCriticalSection(&This
->csFilter
);
515 static HRESULT WINAPI
DSoundRender_Run(IBaseFilter
* iface
, REFERENCE_TIME tStart
)
518 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
520 TRACE("(%p/%p)->(%s)\n", This
, iface
, wine_dbgstr_longlong(tStart
));
522 EnterCriticalSection(&This
->csFilter
);
524 /* It's okay if there's no buffer yet. It'll start when it's created */
527 if (This
->state
== State_Stopped
)
532 IDirectSoundBuffer_Lock(This
->dsbuffer
, 0, 0, (void**)&buf1
, &size1
, NULL
, NULL
, DSBLOCK_ENTIREBUFFER
);
533 memset(buf1
, 0, size1
);
534 IDirectSoundBuffer_Unlock(This
->dsbuffer
, buf1
, size1
, NULL
, 0);
536 hr
= IDirectSoundBuffer_Play(This
->dsbuffer
, 0, 0, DSBPLAY_LOOPING
);
538 ERR("Can't start playing! (%x)\n", hr
);
542 This
->rtStreamStart
= tStart
;
543 This
->state
= State_Running
;
546 LeaveCriticalSection(&This
->csFilter
);
551 static HRESULT WINAPI
DSoundRender_GetState(IBaseFilter
* iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
553 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
555 TRACE("(%p/%p)->(%d, %p)\n", This
, iface
, dwMilliSecsTimeout
, pState
);
557 EnterCriticalSection(&This
->csFilter
);
559 *pState
= This
->state
;
561 LeaveCriticalSection(&This
->csFilter
);
566 static HRESULT WINAPI
DSoundRender_SetSyncSource(IBaseFilter
* iface
, IReferenceClock
*pClock
)
568 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
570 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClock
);
572 EnterCriticalSection(&This
->csFilter
);
575 IReferenceClock_Release(This
->pClock
);
576 This
->pClock
= pClock
;
578 IReferenceClock_AddRef(This
->pClock
);
580 LeaveCriticalSection(&This
->csFilter
);
585 static HRESULT WINAPI
DSoundRender_GetSyncSource(IBaseFilter
* iface
, IReferenceClock
**ppClock
)
587 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
589 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppClock
);
591 EnterCriticalSection(&This
->csFilter
);
593 *ppClock
= This
->pClock
;
594 IReferenceClock_AddRef(This
->pClock
);
596 LeaveCriticalSection(&This
->csFilter
);
601 /** IBaseFilter implementation **/
603 static HRESULT WINAPI
DSoundRender_EnumPins(IBaseFilter
* iface
, IEnumPins
**ppEnum
)
606 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
608 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
610 epd
.cPins
= 1; /* input pin */
611 epd
.ppPins
= This
->ppPins
;
612 return IEnumPinsImpl_Construct(&epd
, ppEnum
);
615 static HRESULT WINAPI
DSoundRender_FindPin(IBaseFilter
* iface
, LPCWSTR Id
, IPin
**ppPin
)
617 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
619 TRACE("(%p/%p)->(%s,%p)\n", This
, iface
, debugstr_w(Id
), ppPin
);
621 FIXME("DSoundRender::FindPin(...)\n");
623 /* FIXME: critical section */
628 static HRESULT WINAPI
DSoundRender_QueryFilterInfo(IBaseFilter
* iface
, FILTER_INFO
*pInfo
)
630 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
632 TRACE("(%p/%p)->(%p)\n", This
, iface
, pInfo
);
634 strcpyW(pInfo
->achName
, This
->filterInfo
.achName
);
635 pInfo
->pGraph
= This
->filterInfo
.pGraph
;
638 IFilterGraph_AddRef(pInfo
->pGraph
);
643 static HRESULT WINAPI
DSoundRender_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
645 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
647 TRACE("(%p/%p)->(%p, %s)\n", This
, iface
, pGraph
, debugstr_w(pName
));
649 EnterCriticalSection(&This
->csFilter
);
652 strcpyW(This
->filterInfo
.achName
, pName
);
654 *This
->filterInfo
.achName
= '\0';
655 This
->filterInfo
.pGraph
= pGraph
; /* NOTE: do NOT increase ref. count */
657 LeaveCriticalSection(&This
->csFilter
);
662 static HRESULT WINAPI
DSoundRender_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
664 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
665 TRACE("(%p/%p)->(%p)\n", This
, iface
, pVendorInfo
);
669 static const IBaseFilterVtbl DSoundRender_Vtbl
=
671 DSoundRender_QueryInterface
,
673 DSoundRender_Release
,
674 DSoundRender_GetClassID
,
678 DSoundRender_GetState
,
679 DSoundRender_SetSyncSource
,
680 DSoundRender_GetSyncSource
,
681 DSoundRender_EnumPins
,
682 DSoundRender_FindPin
,
683 DSoundRender_QueryFilterInfo
,
684 DSoundRender_JoinFilterGraph
,
685 DSoundRender_QueryVendorInfo
688 static HRESULT WINAPI
DSoundRender_InputPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
690 InputPin
*This
= (InputPin
*)iface
;
691 PIN_DIRECTION pindirReceive
;
692 DSoundRenderImpl
*DSImpl
;
695 TRACE("(%p)->(%p, %p)\n", This
, pReceivePin
, pmt
);
696 dump_AM_MEDIA_TYPE(pmt
);
698 EnterCriticalSection(This
->pin
.pCritSec
);
700 DSImpl
= (DSoundRenderImpl
*)This
->pin
.pinInfo
.pFilter
;
702 if (This
->pin
.pConnectedTo
)
703 hr
= VFW_E_ALREADY_CONNECTED
;
705 if (SUCCEEDED(hr
) && This
->pin
.fnQueryAccept(This
->pin
.pUserData
, pmt
) != S_OK
)
706 hr
= VFW_E_TYPE_NOT_ACCEPTED
;
710 IPin_QueryDirection(pReceivePin
, &pindirReceive
);
712 if (pindirReceive
!= PINDIR_OUTPUT
)
714 ERR("Can't connect from non-output pin\n");
715 hr
= VFW_E_INVALID_DIRECTION
;
721 WAVEFORMATEX
*format
;
722 DSBUFFERDESC buf_desc
;
724 TRACE("MajorType %s\n", debugstr_guid(&pmt
->majortype
));
725 TRACE("SubType %s\n", debugstr_guid(&pmt
->subtype
));
726 TRACE("Format %s\n", debugstr_guid(&pmt
->formattype
));
727 TRACE("Size %d\n", pmt
->cbFormat
);
729 format
= (WAVEFORMATEX
*)pmt
->pbFormat
;
731 DSImpl
->buf_size
= format
->nAvgBytesPerSec
;
733 memset(&buf_desc
,0,sizeof(DSBUFFERDESC
));
734 buf_desc
.dwSize
= sizeof(DSBUFFERDESC
);
735 buf_desc
.dwFlags
= DSBCAPS_CTRLVOLUME
| DSBCAPS_CTRLPAN
|
736 DSBCAPS_CTRLFREQUENCY
|
737 DSBCAPS_GETCURRENTPOSITION2
;
738 buf_desc
.dwBufferBytes
= DSImpl
->buf_size
;
739 buf_desc
.lpwfxFormat
= format
;
740 hr
= IDirectSound_CreateSoundBuffer(DSImpl
->dsound
, &buf_desc
, &DSImpl
->dsbuffer
, NULL
);
742 ERR("Can't create sound buffer (%x)\n", hr
);
747 hr
= IDirectSoundBuffer_SetVolume(DSImpl
->dsbuffer
, DSImpl
->volume
);
749 ERR("Can't set volume to %ld (%x)\n", DSImpl
->volume
, hr
);
751 hr
= IDirectSoundBuffer_SetPan(DSImpl
->dsbuffer
, DSImpl
->pan
);
753 ERR("Can't set pan to %ld (%x)\n", DSImpl
->pan
, hr
);
755 DSImpl
->write_pos
= 0;
757 if (DSImpl
->state
== State_Running
)
758 hr
= IDirectSoundBuffer_Play(DSImpl
->dsbuffer
, 0, 0, DSBPLAY_LOOPING
);
760 ERR("Can't play sound buffer (%x)\n", hr
);
765 CopyMediaType(&This
->pin
.mtCurrent
, pmt
);
766 This
->pin
.pConnectedTo
= pReceivePin
;
767 IPin_AddRef(pReceivePin
);
771 if (DSImpl
->dsbuffer
)
772 IDirectSoundBuffer_Release(DSImpl
->dsbuffer
);
773 DSImpl
->dsbuffer
= NULL
;
776 LeaveCriticalSection(This
->pin
.pCritSec
);
781 static HRESULT WINAPI
DSoundRender_InputPin_Disconnect(IPin
* iface
)
783 IPinImpl
*This
= (IPinImpl
*)iface
;
784 DSoundRenderImpl
*DSImpl
;
786 TRACE("(%p)->()\n", iface
);
788 DSImpl
= (DSoundRenderImpl
*)This
->pinInfo
.pFilter
;
789 if (DSImpl
->dsbuffer
)
790 IDirectSoundBuffer_Release(DSImpl
->dsbuffer
);
791 DSImpl
->dsbuffer
= NULL
;
793 return IPinImpl_Disconnect(iface
);
796 static HRESULT WINAPI
DSoundRender_InputPin_EndOfStream(IPin
* iface
)
798 InputPin
* This
= (InputPin
*)iface
;
799 DSoundRenderImpl
*me
= (DSoundRenderImpl
*)This
->pin
.pinInfo
.pFilter
;
800 IMediaEventSink
* pEventSink
;
803 TRACE("(%p/%p)->()\n", This
, iface
);
804 InputPin_EndOfStream(iface
);
806 hr
= IFilterGraph_QueryInterface(me
->filterInfo
.pGraph
, &IID_IMediaEventSink
, (LPVOID
*)&pEventSink
);
811 silence
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, me
->buf_size
);
814 memset(silence
, 0, me
->buf_size
);
815 DSoundRender_SendSampleData((DSoundRenderImpl
*)This
->pin
.pinInfo
.pFilter
, silence
, me
->buf_size
);
816 HeapFree(GetProcessHeap(), 0, silence
);
819 hr
= IMediaEventSink_Notify(pEventSink
, EC_COMPLETE
, S_OK
, 0);
820 IMediaEventSink_Release(pEventSink
);
826 static const IPinVtbl DSoundRender_InputPin_Vtbl
=
828 InputPin_QueryInterface
,
832 DSoundRender_InputPin_ReceiveConnection
,
833 DSoundRender_InputPin_Disconnect
,
834 IPinImpl_ConnectedTo
,
835 IPinImpl_ConnectionMediaType
,
836 IPinImpl_QueryPinInfo
,
837 IPinImpl_QueryDirection
,
839 IPinImpl_QueryAccept
,
840 IPinImpl_EnumMediaTypes
,
841 IPinImpl_QueryInternalConnections
,
842 DSoundRender_InputPin_EndOfStream
,
848 static const IMemInputPinVtbl MemInputPin_Vtbl
=
850 MemInputPin_QueryInterface
,
853 MemInputPin_GetAllocator
,
854 MemInputPin_NotifyAllocator
,
855 MemInputPin_GetAllocatorRequirements
,
857 MemInputPin_ReceiveMultiple
,
858 MemInputPin_ReceiveCanBlock
861 /*** IUnknown methods ***/
862 static HRESULT WINAPI
Basicaudio_QueryInterface(IBasicAudio
*iface
,
865 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
867 TRACE("(%p/%p)->(%s (%p), %p)\n", This
, iface
, debugstr_guid(riid
), riid
, ppvObj
);
869 return DSoundRender_QueryInterface((IBaseFilter
*)This
, riid
, ppvObj
);
872 static ULONG WINAPI
Basicaudio_AddRef(IBasicAudio
*iface
) {
873 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
875 TRACE("(%p/%p)->()\n", This
, iface
);
877 return DSoundRender_AddRef((IBaseFilter
*)This
);
880 static ULONG WINAPI
Basicaudio_Release(IBasicAudio
*iface
) {
881 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
883 TRACE("(%p/%p)->()\n", This
, iface
);
885 return DSoundRender_Release((IBaseFilter
*)This
);
888 /*** IDispatch methods ***/
889 static HRESULT WINAPI
Basicaudio_GetTypeInfoCount(IBasicAudio
*iface
,
891 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
893 TRACE("(%p/%p)->(%p): stub !!!\n", This
, iface
, pctinfo
);
898 static HRESULT WINAPI
Basicaudio_GetTypeInfo(IBasicAudio
*iface
,
901 ITypeInfo
**ppTInfo
) {
902 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
904 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This
, iface
, iTInfo
, lcid
, ppTInfo
);
909 static HRESULT WINAPI
Basicaudio_GetIDsOfNames(IBasicAudio
*iface
,
915 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
917 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This
, iface
, debugstr_guid(riid
), riid
, rgszNames
, cNames
, lcid
, rgDispId
);
922 static HRESULT WINAPI
Basicaudio_Invoke(IBasicAudio
*iface
,
927 DISPPARAMS
*pDispParams
,
931 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
933 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p): stub !!!\n", This
, iface
, dispIdMember
, debugstr_guid(riid
), riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExepInfo
, puArgErr
);
938 /*** IBasicAudio methods ***/
939 static HRESULT WINAPI
Basicaudio_put_Volume(IBasicAudio
*iface
,
941 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
943 TRACE("(%p/%p)->(%ld)\n", This
, iface
, lVolume
);
945 if (lVolume
> DSBVOLUME_MAX
|| lVolume
< DSBVOLUME_MIN
)
948 if (This
->dsbuffer
) {
949 if (FAILED(IDirectSoundBuffer_SetVolume(This
->dsbuffer
, lVolume
)))
953 This
->volume
= lVolume
;
957 static HRESULT WINAPI
Basicaudio_get_Volume(IBasicAudio
*iface
,
959 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
961 TRACE("(%p/%p)->(%p)\n", This
, iface
, plVolume
);
966 *plVolume
= This
->volume
;
970 static HRESULT WINAPI
Basicaudio_put_Balance(IBasicAudio
*iface
,
972 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
974 TRACE("(%p/%p)->(%ld)\n", This
, iface
, lBalance
);
976 if (lBalance
< DSBPAN_LEFT
|| lBalance
> DSBPAN_RIGHT
)
979 if (This
->dsbuffer
) {
980 if (FAILED(IDirectSoundBuffer_SetPan(This
->dsbuffer
, lBalance
)))
984 This
->pan
= lBalance
;
988 static HRESULT WINAPI
Basicaudio_get_Balance(IBasicAudio
*iface
,
990 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
992 TRACE("(%p/%p)->(%p)\n", This
, iface
, plBalance
);
997 *plBalance
= This
->pan
;
1001 static const IBasicAudioVtbl IBasicAudio_Vtbl
=
1003 Basicaudio_QueryInterface
,
1006 Basicaudio_GetTypeInfoCount
,
1007 Basicaudio_GetTypeInfo
,
1008 Basicaudio_GetIDsOfNames
,
1010 Basicaudio_put_Volume
,
1011 Basicaudio_get_Volume
,
1012 Basicaudio_put_Balance
,
1013 Basicaudio_get_Balance
1017 /*** IUnknown methods ***/
1018 static HRESULT WINAPI
ReferenceClock_QueryInterface(IReferenceClock
*iface
,
1022 ICOM_THIS_MULTI(DSoundRenderImpl
, IReferenceClock_vtbl
, iface
);
1024 TRACE("(%p/%p)->(%s (%p), %p)\n", This
, iface
, debugstr_guid(riid
), riid
, ppvObj
);
1026 return DSoundRender_QueryInterface((IBaseFilter
*)This
, riid
, ppvObj
);
1029 static ULONG WINAPI
ReferenceClock_AddRef(IReferenceClock
*iface
)
1031 ICOM_THIS_MULTI(DSoundRenderImpl
, IReferenceClock_vtbl
, iface
);
1033 TRACE("(%p/%p)->()\n", This
, iface
);
1035 return DSoundRender_AddRef((IBaseFilter
*)This
);
1038 static ULONG WINAPI
ReferenceClock_Release(IReferenceClock
*iface
)
1040 ICOM_THIS_MULTI(DSoundRenderImpl
, IReferenceClock_vtbl
, iface
);
1042 TRACE("(%p/%p)->()\n", This
, iface
);
1044 return DSoundRender_Release((IBaseFilter
*)This
);
1047 /*** IReferenceClock methods ***/
1048 static HRESULT WINAPI
ReferenceClock_GetTime(IReferenceClock
*iface
,
1049 REFERENCE_TIME
*pTime
)
1051 ICOM_THIS_MULTI(DSoundRenderImpl
, IReferenceClock_vtbl
, iface
);
1052 HRESULT hr
= E_FAIL
;
1055 TRACE("(%p/%p)->(%p)\n", This
, iface
, pTime
);
1058 hr
= DSoundRender_GetPos(This
, &play_pos
, NULL
, pTime
);
1060 ERR("Could not get reference time (%x)!\n", hr
);
1065 static HRESULT WINAPI
ReferenceClock_AdviseTime(IReferenceClock
*iface
,
1066 REFERENCE_TIME rtBaseTime
,
1067 REFERENCE_TIME rtStreamTime
,
1069 DWORD_PTR
*pdwAdviseCookie
)
1071 ICOM_THIS_MULTI(DSoundRenderImpl
, IReferenceClock_vtbl
, iface
);
1073 FIXME("(%p/%p)->(%s, %s, %p, %p): stub!\n", This
, iface
, wine_dbgstr_longlong(rtBaseTime
), wine_dbgstr_longlong(rtStreamTime
), (void*)hEvent
, pdwAdviseCookie
);
1078 static HRESULT WINAPI
ReferenceClock_AdvisePeriodic(IReferenceClock
*iface
,
1079 REFERENCE_TIME rtBaseTime
,
1080 REFERENCE_TIME rtStreamTime
,
1081 HSEMAPHORE hSemaphore
,
1082 DWORD_PTR
*pdwAdviseCookie
)
1084 ICOM_THIS_MULTI(DSoundRenderImpl
, IReferenceClock_vtbl
, iface
);
1086 FIXME("(%p/%p)->(%s, %s, %p, %p): stub!\n", This
, iface
, wine_dbgstr_longlong(rtBaseTime
), wine_dbgstr_longlong(rtStreamTime
), (void*)hSemaphore
, pdwAdviseCookie
);
1091 static HRESULT WINAPI
ReferenceClock_Unadvise(IReferenceClock
*iface
,
1092 DWORD_PTR dwAdviseCookie
)
1094 ICOM_THIS_MULTI(DSoundRenderImpl
, IReferenceClock_vtbl
, iface
);
1096 FIXME("(%p/%p)->(%p): stub!\n", This
, iface
, (void*)dwAdviseCookie
);
1101 static const IReferenceClockVtbl IReferenceClock_Vtbl
=
1103 ReferenceClock_QueryInterface
,
1104 ReferenceClock_AddRef
,
1105 ReferenceClock_Release
,
1106 ReferenceClock_GetTime
,
1107 ReferenceClock_AdviseTime
,
1108 ReferenceClock_AdvisePeriodic
,
1109 ReferenceClock_Unadvise
1112 static inline DSoundRenderImpl
*impl_from_IMediaSeeking( IMediaSeeking
*iface
)
1114 return (DSoundRenderImpl
*)((char*)iface
- FIELD_OFFSET(DSoundRenderImpl
, mediaSeeking
.lpVtbl
));
1117 static HRESULT WINAPI
sound_seek_QueryInterface(IMediaSeeking
* iface
, REFIID riid
, LPVOID
* ppv
)
1119 DSoundRenderImpl
*This
= impl_from_IMediaSeeking(iface
);
1121 return IUnknown_QueryInterface((IUnknown
*)This
, riid
, ppv
);
1124 static ULONG WINAPI
sound_seek_AddRef(IMediaSeeking
* iface
)
1126 DSoundRenderImpl
*This
= impl_from_IMediaSeeking(iface
);
1128 return IUnknown_AddRef((IUnknown
*)This
);
1131 static ULONG WINAPI
sound_seek_Release(IMediaSeeking
* iface
)
1133 DSoundRenderImpl
*This
= impl_from_IMediaSeeking(iface
);
1135 return IUnknown_Release((IUnknown
*)This
);
1138 static const IMediaSeekingVtbl IMediaSeeking_Vtbl
=
1140 sound_seek_QueryInterface
,
1143 MediaSeekingImpl_GetCapabilities
,
1144 MediaSeekingImpl_CheckCapabilities
,
1145 MediaSeekingImpl_IsFormatSupported
,
1146 MediaSeekingImpl_QueryPreferredFormat
,
1147 MediaSeekingImpl_GetTimeFormat
,
1148 MediaSeekingImpl_IsUsingTimeFormat
,
1149 MediaSeekingImpl_SetTimeFormat
,
1150 MediaSeekingImpl_GetDuration
,
1151 MediaSeekingImpl_GetStopPosition
,
1152 MediaSeekingImpl_GetCurrentPosition
,
1153 MediaSeekingImpl_ConvertTimeFormat
,
1154 MediaSeekingImpl_SetPositions
,
1155 MediaSeekingImpl_GetPositions
,
1156 MediaSeekingImpl_GetAvailable
,
1157 MediaSeekingImpl_SetRate
,
1158 MediaSeekingImpl_GetRate
,
1159 MediaSeekingImpl_GetPreroll