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
;
49 typedef struct DSoundRenderImpl
51 const IBaseFilterVtbl
* lpVtbl
;
52 const IBasicAudioVtbl
*IBasicAudio_vtbl
;
53 const IReferenceClockVtbl
*IReferenceClock_vtbl
;
56 CRITICAL_SECTION csFilter
;
58 REFERENCE_TIME rtStreamStart
;
59 IReferenceClock
* pClock
;
60 FILTER_INFO filterInfo
;
66 LPDIRECTSOUNDBUFFER dsbuffer
;
73 REFERENCE_TIME play_time
;
79 static HRESULT
DSoundRender_InputPin_Construct(const PIN_INFO
* pPinInfo
, SAMPLEPROC pSampleProc
, LPVOID pUserData
, QUERYACCEPTPROC pQueryAccept
, LPCRITICAL_SECTION pCritSec
, IPin
** ppPin
)
85 if (pPinInfo
->dir
!= PINDIR_INPUT
)
87 ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo
->dir
);
91 pPinImpl
= CoTaskMemAlloc(sizeof(*pPinImpl
));
96 if (SUCCEEDED(InputPin_Init(pPinInfo
, pSampleProc
, pUserData
, pQueryAccept
, pCritSec
, pPinImpl
)))
98 pPinImpl
->pin
.lpVtbl
= &DSoundRender_InputPin_Vtbl
;
99 pPinImpl
->lpVtblMemInput
= &MemInputPin_Vtbl
;
101 *ppPin
= (IPin
*)(&pPinImpl
->pin
.lpVtbl
);
105 CoTaskMemFree(pPinImpl
);
110 static inline HRESULT
DSoundRender_GetPos(DSoundRenderImpl
*This
, DWORD
*pPlayPos
, DWORD
*pWritePos
, REFERENCE_TIME
*pRefTime
)
114 EnterCriticalSection(&This
->csFilter
);
116 hr
= IDirectSoundBuffer_GetCurrentPosition(This
->dsbuffer
, pPlayPos
, pWritePos
);
119 DWORD play_pos
= *pPlayPos
;
121 if (play_pos
< This
->last_play_pos
)
123 This
->last_play_pos
= play_pos
;
125 /* If we're really falling behind, kick the play time back */
126 if ((This
->play_loops
*This
->buf_size
)+play_pos
>=
127 (This
->write_loops
*This
->buf_size
)+This
->write_pos
)
132 REFERENCE_TIME play_time
;
133 play_time
= ((REFERENCE_TIME
)This
->play_loops
*10000000) +
134 ((REFERENCE_TIME
)play_pos
*10000000/This
->buf_size
);
136 /* Don't let time run backwards */
137 if(play_time
-This
->play_time
> 0)
138 This
->play_time
= play_time
;
142 *pRefTime
= This
->play_time
;
146 LeaveCriticalSection(&This
->csFilter
);
151 static HRESULT
DSoundRender_SendSampleData(DSoundRenderImpl
* This
, const BYTE
*data
, DWORD size
)
154 LPBYTE lpbuf1
= NULL
;
155 LPBYTE lpbuf2
= NULL
;
159 DWORD play_pos
,buf_free
;
162 hr
= DSoundRender_GetPos(This
, &play_pos
, NULL
, NULL
);
165 ERR("GetPos returned error: %x\n", hr
);
168 if (This
->write_pos
<= play_pos
)
169 buf_free
= play_pos
-This
->write_pos
;
171 buf_free
= This
->buf_size
- This
->write_pos
+ play_pos
;
173 /* Wait for enough of the buffer to empty before filling it */
174 if(buf_free
< This
->buf_size
/4)
180 size2
= min(buf_free
, size
);
181 hr
= IDirectSoundBuffer_Lock(This
->dsbuffer
, This
->write_pos
, size2
, (LPVOID
*)&lpbuf1
, &dwsize1
, (LPVOID
*)&lpbuf2
, &dwsize2
, 0);
183 ERR("Unable to lock sound buffer! (%x)\n", hr
);
186 /* TRACE("write_pos=%d, size=%d, sz1=%d, sz2=%d\n", This->write_pos, size2, dwsize1, dwsize2); */
188 memcpy(lpbuf1
, data
, dwsize1
);
190 memcpy(lpbuf2
, data
+ dwsize1
, dwsize2
);
192 hr
= IDirectSoundBuffer_Unlock(This
->dsbuffer
, lpbuf1
, dwsize1
, lpbuf2
, dwsize2
);
194 ERR("Unable to unlock sound buffer! (%x)\n", hr
);
196 size
-= dwsize1
+ dwsize2
;
197 data
+= dwsize1
+ dwsize2
;
198 This
->write_pos
+= dwsize1
+ dwsize2
;
199 if (This
->write_pos
>= This
->buf_size
)
201 This
->write_pos
-= This
->buf_size
;
204 } while (size
&& This
->state
== State_Running
);
209 static HRESULT
DSoundRender_Sample(LPVOID iface
, IMediaSample
* pSample
)
211 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
212 LPBYTE pbSrcStream
= NULL
;
213 long cbSrcStream
= 0;
214 REFERENCE_TIME tStart
, tStop
;
217 TRACE("%p %p\n", iface
, pSample
);
219 if (This
->state
!= State_Running
)
220 return VFW_E_WRONG_STATE
;
222 hr
= IMediaSample_GetPointer(pSample
, &pbSrcStream
);
225 ERR("Cannot get pointer to sample data (%x)\n", hr
);
229 hr
= IMediaSample_GetTime(pSample
, &tStart
, &tStop
);
231 ERR("Cannot get sample time (%x)\n", hr
);
233 cbSrcStream
= IMediaSample_GetActualDataLength(pSample
);
235 TRACE("Sample data ptr = %p, size = %ld\n", pbSrcStream
, cbSrcStream
);
237 #if 0 /* For debugging purpose */
240 for(i
= 0; i
< cbSrcStream
; i
++)
242 if ((i
!=0) && !(i
%16))
244 TRACE("%02x ", pbSrcStream
[i
]);
250 return DSoundRender_SendSampleData(This
, pbSrcStream
, cbSrcStream
);
253 static HRESULT
DSoundRender_QueryAccept(LPVOID iface
, const AM_MEDIA_TYPE
* pmt
)
255 WAVEFORMATEX
* format
= (WAVEFORMATEX
*)pmt
->pbFormat
;
256 TRACE("wFormatTag = %x %x\n", format
->wFormatTag
, WAVE_FORMAT_PCM
);
257 TRACE("nChannels = %d\n", format
->nChannels
);
258 TRACE("nSamplesPerSec = %d\n", format
->nAvgBytesPerSec
);
259 TRACE("nAvgBytesPerSec = %d\n", format
->nAvgBytesPerSec
);
260 TRACE("nBlockAlign = %d\n", format
->nBlockAlign
);
261 TRACE("wBitsPerSample = %d\n", format
->wBitsPerSample
);
263 if (IsEqualIID(&pmt
->majortype
, &MEDIATYPE_Audio
) && IsEqualIID(&pmt
->subtype
, &MEDIASUBTYPE_PCM
))
268 HRESULT
DSoundRender_create(IUnknown
* pUnkOuter
, LPVOID
* ppv
)
272 DSoundRenderImpl
* pDSoundRender
;
274 TRACE("(%p, %p)\n", pUnkOuter
, ppv
);
279 return CLASS_E_NOAGGREGATION
;
281 pDSoundRender
= CoTaskMemAlloc(sizeof(DSoundRenderImpl
));
283 return E_OUTOFMEMORY
;
284 ZeroMemory(pDSoundRender
, sizeof(DSoundRenderImpl
));
286 pDSoundRender
->lpVtbl
= &DSoundRender_Vtbl
;
287 pDSoundRender
->IBasicAudio_vtbl
= &IBasicAudio_Vtbl
;
288 pDSoundRender
->IReferenceClock_vtbl
= &IReferenceClock_Vtbl
;
289 pDSoundRender
->refCount
= 1;
290 InitializeCriticalSection(&pDSoundRender
->csFilter
);
291 pDSoundRender
->csFilter
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": DSoundRenderImpl.csFilter");
292 pDSoundRender
->state
= State_Stopped
;
294 pDSoundRender
->ppPins
= CoTaskMemAlloc(1 * sizeof(IPin
*));
295 if (!pDSoundRender
->ppPins
)
297 pDSoundRender
->csFilter
.DebugInfo
->Spare
[0] = 0;
298 DeleteCriticalSection(&pDSoundRender
->csFilter
);
299 CoTaskMemFree(pDSoundRender
);
300 return E_OUTOFMEMORY
;
303 /* construct input pin */
304 piInput
.dir
= PINDIR_INPUT
;
305 piInput
.pFilter
= (IBaseFilter
*)pDSoundRender
;
306 lstrcpynW(piInput
.achName
, wcsInputPinName
, sizeof(piInput
.achName
) / sizeof(piInput
.achName
[0]));
307 hr
= DSoundRender_InputPin_Construct(&piInput
, DSoundRender_Sample
, (LPVOID
)pDSoundRender
, DSoundRender_QueryAccept
, &pDSoundRender
->csFilter
, (IPin
**)&pDSoundRender
->pInputPin
);
311 hr
= DirectSoundCreate(NULL
, &pDSoundRender
->dsound
, NULL
);
313 ERR("Cannot create Direct Sound object (%x)\n", hr
);
318 pDSoundRender
->ppPins
[0] = (IPin
*)pDSoundRender
->pInputPin
;
319 *ppv
= (LPVOID
)pDSoundRender
;
323 if (pDSoundRender
->pInputPin
)
324 IPin_Release((IPin
*)pDSoundRender
->pInputPin
);
325 CoTaskMemFree(pDSoundRender
->ppPins
);
326 pDSoundRender
->csFilter
.DebugInfo
->Spare
[0] = 0;
327 DeleteCriticalSection(&pDSoundRender
->csFilter
);
328 CoTaskMemFree(pDSoundRender
);
334 static HRESULT WINAPI
DSoundRender_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
336 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
337 TRACE("(%p, %p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
341 if (IsEqualIID(riid
, &IID_IUnknown
))
343 else if (IsEqualIID(riid
, &IID_IPersist
))
345 else if (IsEqualIID(riid
, &IID_IMediaFilter
))
347 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
349 else if (IsEqualIID(riid
, &IID_IBasicAudio
))
350 *ppv
= (LPVOID
)&(This
->IBasicAudio_vtbl
);
351 else if (IsEqualIID(riid
, &IID_IReferenceClock
))
352 *ppv
= (LPVOID
)&(This
->IReferenceClock_vtbl
);
356 IUnknown_AddRef((IUnknown
*)(*ppv
));
360 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
362 return E_NOINTERFACE
;
365 static ULONG WINAPI
DSoundRender_AddRef(IBaseFilter
* iface
)
367 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
368 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
370 TRACE("(%p/%p)->() AddRef from %d\n", This
, iface
, refCount
- 1);
375 static ULONG WINAPI
DSoundRender_Release(IBaseFilter
* iface
)
377 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
378 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
380 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
387 IReferenceClock_Release(This
->pClock
);
390 IDirectSoundBuffer_Release(This
->dsbuffer
);
391 This
->dsbuffer
= NULL
;
393 IDirectSound_Release(This
->dsound
);
396 if (SUCCEEDED(IPin_ConnectedTo(This
->ppPins
[0], &pConnectedTo
)))
398 IPin_Disconnect(pConnectedTo
);
399 IPin_Release(pConnectedTo
);
401 IPin_Disconnect(This
->ppPins
[0]);
403 IPin_Release(This
->ppPins
[0]);
405 CoTaskMemFree(This
->ppPins
);
407 This
->IBasicAudio_vtbl
= NULL
;
409 This
->csFilter
.DebugInfo
->Spare
[0] = 0;
410 DeleteCriticalSection(&This
->csFilter
);
412 TRACE("Destroying Audio Renderer\n");
421 /** IPersist methods **/
423 static HRESULT WINAPI
DSoundRender_GetClassID(IBaseFilter
* iface
, CLSID
* pClsid
)
425 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
426 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClsid
);
428 *pClsid
= CLSID_DSoundRender
;
433 /** IMediaFilter methods **/
435 static HRESULT WINAPI
DSoundRender_Stop(IBaseFilter
* iface
)
438 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
440 TRACE("(%p/%p)->()\n", This
, iface
);
442 EnterCriticalSection(&This
->csFilter
);
447 hr
= IDirectSoundBuffer_GetStatus(This
->dsbuffer
, &state
);
450 if (state
& DSBSTATUS_PLAYING
)
451 hr
= IDirectSoundBuffer_Stop(This
->dsbuffer
);
455 This
->state
= State_Stopped
;
457 LeaveCriticalSection(&This
->csFilter
);
462 static HRESULT WINAPI
DSoundRender_Pause(IBaseFilter
* iface
)
465 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
467 TRACE("(%p/%p)->()\n", This
, iface
);
469 EnterCriticalSection(&This
->csFilter
);
474 hr
= IDirectSoundBuffer_GetStatus(This
->dsbuffer
, &state
);
477 if (state
& DSBSTATUS_PLAYING
)
478 hr
= IDirectSoundBuffer_Stop(This
->dsbuffer
);
482 This
->state
= State_Paused
;
484 LeaveCriticalSection(&This
->csFilter
);
489 static HRESULT WINAPI
DSoundRender_Run(IBaseFilter
* iface
, REFERENCE_TIME tStart
)
492 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
494 TRACE("(%p/%p)->(%s)\n", This
, iface
, wine_dbgstr_longlong(tStart
));
496 EnterCriticalSection(&This
->csFilter
);
498 /* It's okay if there's no buffer yet. It'll start when it's created */
501 if (This
->state
== State_Stopped
)
506 IDirectSoundBuffer_Lock(This
->dsbuffer
, 0, 0, (void**)&buf1
, &size1
, NULL
, NULL
, DSBLOCK_ENTIREBUFFER
);
507 memset(buf1
, 0, size1
);
508 IDirectSoundBuffer_Unlock(This
->dsbuffer
, buf1
, size1
, NULL
, 0);
510 hr
= IDirectSoundBuffer_Play(This
->dsbuffer
, 0, 0, DSBPLAY_LOOPING
);
512 ERR("Can't start playing! (%x)\n", hr
);
516 This
->rtStreamStart
= tStart
;
517 This
->state
= State_Running
;
520 LeaveCriticalSection(&This
->csFilter
);
525 static HRESULT WINAPI
DSoundRender_GetState(IBaseFilter
* iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
527 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
529 TRACE("(%p/%p)->(%d, %p)\n", This
, iface
, dwMilliSecsTimeout
, pState
);
531 EnterCriticalSection(&This
->csFilter
);
533 *pState
= This
->state
;
535 LeaveCriticalSection(&This
->csFilter
);
540 static HRESULT WINAPI
DSoundRender_SetSyncSource(IBaseFilter
* iface
, IReferenceClock
*pClock
)
542 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
544 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClock
);
546 EnterCriticalSection(&This
->csFilter
);
549 IReferenceClock_Release(This
->pClock
);
550 This
->pClock
= pClock
;
552 IReferenceClock_AddRef(This
->pClock
);
554 LeaveCriticalSection(&This
->csFilter
);
559 static HRESULT WINAPI
DSoundRender_GetSyncSource(IBaseFilter
* iface
, IReferenceClock
**ppClock
)
561 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
563 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppClock
);
565 EnterCriticalSection(&This
->csFilter
);
567 *ppClock
= This
->pClock
;
568 IReferenceClock_AddRef(This
->pClock
);
570 LeaveCriticalSection(&This
->csFilter
);
575 /** IBaseFilter implementation **/
577 static HRESULT WINAPI
DSoundRender_EnumPins(IBaseFilter
* iface
, IEnumPins
**ppEnum
)
580 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
582 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
584 epd
.cPins
= 1; /* input pin */
585 epd
.ppPins
= This
->ppPins
;
586 return IEnumPinsImpl_Construct(&epd
, ppEnum
);
589 static HRESULT WINAPI
DSoundRender_FindPin(IBaseFilter
* iface
, LPCWSTR Id
, IPin
**ppPin
)
591 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
593 TRACE("(%p/%p)->(%s,%p)\n", This
, iface
, debugstr_w(Id
), ppPin
);
595 FIXME("DSoundRender::FindPin(...)\n");
597 /* FIXME: critical section */
602 static HRESULT WINAPI
DSoundRender_QueryFilterInfo(IBaseFilter
* iface
, FILTER_INFO
*pInfo
)
604 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
606 TRACE("(%p/%p)->(%p)\n", This
, iface
, pInfo
);
608 strcpyW(pInfo
->achName
, This
->filterInfo
.achName
);
609 pInfo
->pGraph
= This
->filterInfo
.pGraph
;
612 IFilterGraph_AddRef(pInfo
->pGraph
);
617 static HRESULT WINAPI
DSoundRender_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
619 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
621 TRACE("(%p/%p)->(%p, %s)\n", This
, iface
, pGraph
, debugstr_w(pName
));
623 EnterCriticalSection(&This
->csFilter
);
626 strcpyW(This
->filterInfo
.achName
, pName
);
628 *This
->filterInfo
.achName
= '\0';
629 This
->filterInfo
.pGraph
= pGraph
; /* NOTE: do NOT increase ref. count */
631 LeaveCriticalSection(&This
->csFilter
);
636 static HRESULT WINAPI
DSoundRender_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
638 DSoundRenderImpl
*This
= (DSoundRenderImpl
*)iface
;
639 TRACE("(%p/%p)->(%p)\n", This
, iface
, pVendorInfo
);
643 static const IBaseFilterVtbl DSoundRender_Vtbl
=
645 DSoundRender_QueryInterface
,
647 DSoundRender_Release
,
648 DSoundRender_GetClassID
,
652 DSoundRender_GetState
,
653 DSoundRender_SetSyncSource
,
654 DSoundRender_GetSyncSource
,
655 DSoundRender_EnumPins
,
656 DSoundRender_FindPin
,
657 DSoundRender_QueryFilterInfo
,
658 DSoundRender_JoinFilterGraph
,
659 DSoundRender_QueryVendorInfo
662 static HRESULT WINAPI
DSoundRender_InputPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
664 InputPin
*This
= (InputPin
*)iface
;
665 PIN_DIRECTION pindirReceive
;
666 DSoundRenderImpl
*DSImpl
;
669 TRACE("(%p)->(%p, %p)\n", This
, pReceivePin
, pmt
);
670 dump_AM_MEDIA_TYPE(pmt
);
672 EnterCriticalSection(This
->pin
.pCritSec
);
674 DSImpl
= (DSoundRenderImpl
*)This
->pin
.pinInfo
.pFilter
;
676 if (This
->pin
.pConnectedTo
)
677 hr
= VFW_E_ALREADY_CONNECTED
;
679 if (SUCCEEDED(hr
) && This
->pin
.fnQueryAccept(This
->pin
.pUserData
, pmt
) != S_OK
)
680 hr
= VFW_E_TYPE_NOT_ACCEPTED
;
684 IPin_QueryDirection(pReceivePin
, &pindirReceive
);
686 if (pindirReceive
!= PINDIR_OUTPUT
)
688 ERR("Can't connect from non-output pin\n");
689 hr
= VFW_E_INVALID_DIRECTION
;
695 WAVEFORMATEX
*format
;
696 DSBUFFERDESC buf_desc
;
698 TRACE("MajorType %s\n", debugstr_guid(&pmt
->majortype
));
699 TRACE("SubType %s\n", debugstr_guid(&pmt
->subtype
));
700 TRACE("Format %s\n", debugstr_guid(&pmt
->formattype
));
701 TRACE("Size %d\n", pmt
->cbFormat
);
703 format
= (WAVEFORMATEX
*)pmt
->pbFormat
;
705 DSImpl
->buf_size
= format
->nAvgBytesPerSec
;
707 memset(&buf_desc
,0,sizeof(DSBUFFERDESC
));
708 buf_desc
.dwSize
= sizeof(DSBUFFERDESC
);
709 buf_desc
.dwFlags
= DSBCAPS_CTRLVOLUME
| DSBCAPS_CTRLPAN
|
710 DSBCAPS_CTRLFREQUENCY
|
711 DSBCAPS_GETCURRENTPOSITION2
;
712 buf_desc
.dwBufferBytes
= DSImpl
->buf_size
;
713 buf_desc
.lpwfxFormat
= format
;
714 hr
= IDirectSound_CreateSoundBuffer(DSImpl
->dsound
, &buf_desc
, &DSImpl
->dsbuffer
, NULL
);
716 ERR("Can't create sound buffer (%x)\n", hr
);
721 hr
= IDirectSoundBuffer_SetVolume(DSImpl
->dsbuffer
, DSImpl
->volume
);
723 ERR("Can't set volume to %ld (%x)\n", DSImpl
->volume
, hr
);
725 hr
= IDirectSoundBuffer_SetPan(DSImpl
->dsbuffer
, DSImpl
->pan
);
727 ERR("Can't set pan to %ld (%x)\n", DSImpl
->pan
, hr
);
729 DSImpl
->write_pos
= 0;
731 if (DSImpl
->state
== State_Running
)
732 hr
= IDirectSoundBuffer_Play(DSImpl
->dsbuffer
, 0, 0, DSBPLAY_LOOPING
);
734 ERR("Can't play sound buffer (%x)\n", hr
);
739 CopyMediaType(&This
->pin
.mtCurrent
, pmt
);
740 This
->pin
.pConnectedTo
= pReceivePin
;
741 IPin_AddRef(pReceivePin
);
745 if (DSImpl
->dsbuffer
)
746 IDirectSoundBuffer_Release(DSImpl
->dsbuffer
);
747 DSImpl
->dsbuffer
= NULL
;
750 LeaveCriticalSection(This
->pin
.pCritSec
);
755 static HRESULT WINAPI
DSoundRender_InputPin_Disconnect(IPin
* iface
)
757 IPinImpl
*This
= (IPinImpl
*)iface
;
758 DSoundRenderImpl
*DSImpl
;
760 TRACE("(%p)->()\n", iface
);
762 DSImpl
= (DSoundRenderImpl
*)This
->pinInfo
.pFilter
;
763 if (DSImpl
->dsbuffer
)
764 IDirectSoundBuffer_Release(DSImpl
->dsbuffer
);
765 DSImpl
->dsbuffer
= NULL
;
767 return IPinImpl_Disconnect(iface
);
770 static HRESULT WINAPI
DSoundRender_InputPin_EndOfStream(IPin
* iface
)
772 InputPin
* This
= (InputPin
*)iface
;
773 IMediaEventSink
* pEventSink
;
776 TRACE("(%p/%p)->()\n", This
, iface
);
778 hr
= IFilterGraph_QueryInterface(((DSoundRenderImpl
*)This
->pin
.pinInfo
.pFilter
)->filterInfo
.pGraph
, &IID_IMediaEventSink
, (LPVOID
*)&pEventSink
);
781 /* FIXME: We should wait that all audio data has been played */
782 hr
= IMediaEventSink_Notify(pEventSink
, EC_COMPLETE
, S_OK
, 0);
783 IMediaEventSink_Release(pEventSink
);
789 static const IPinVtbl DSoundRender_InputPin_Vtbl
=
791 InputPin_QueryInterface
,
795 DSoundRender_InputPin_ReceiveConnection
,
796 DSoundRender_InputPin_Disconnect
,
797 IPinImpl_ConnectedTo
,
798 IPinImpl_ConnectionMediaType
,
799 IPinImpl_QueryPinInfo
,
800 IPinImpl_QueryDirection
,
802 IPinImpl_QueryAccept
,
803 IPinImpl_EnumMediaTypes
,
804 IPinImpl_QueryInternalConnections
,
805 DSoundRender_InputPin_EndOfStream
,
811 static const IMemInputPinVtbl MemInputPin_Vtbl
=
813 MemInputPin_QueryInterface
,
816 MemInputPin_GetAllocator
,
817 MemInputPin_NotifyAllocator
,
818 MemInputPin_GetAllocatorRequirements
,
820 MemInputPin_ReceiveMultiple
,
821 MemInputPin_ReceiveCanBlock
824 /*** IUnknown methods ***/
825 static HRESULT WINAPI
Basicaudio_QueryInterface(IBasicAudio
*iface
,
828 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
830 TRACE("(%p/%p)->(%s (%p), %p)\n", This
, iface
, debugstr_guid(riid
), riid
, ppvObj
);
832 return DSoundRender_QueryInterface((IBaseFilter
*)This
, riid
, ppvObj
);
835 static ULONG WINAPI
Basicaudio_AddRef(IBasicAudio
*iface
) {
836 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
838 TRACE("(%p/%p)->()\n", This
, iface
);
840 return DSoundRender_AddRef((IBaseFilter
*)This
);
843 static ULONG WINAPI
Basicaudio_Release(IBasicAudio
*iface
) {
844 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
846 TRACE("(%p/%p)->()\n", This
, iface
);
848 return DSoundRender_Release((IBaseFilter
*)This
);
851 /*** IDispatch methods ***/
852 static HRESULT WINAPI
Basicaudio_GetTypeInfoCount(IBasicAudio
*iface
,
854 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
856 TRACE("(%p/%p)->(%p): stub !!!\n", This
, iface
, pctinfo
);
861 static HRESULT WINAPI
Basicaudio_GetTypeInfo(IBasicAudio
*iface
,
864 ITypeInfo
**ppTInfo
) {
865 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
867 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This
, iface
, iTInfo
, lcid
, ppTInfo
);
872 static HRESULT WINAPI
Basicaudio_GetIDsOfNames(IBasicAudio
*iface
,
878 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
880 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This
, iface
, debugstr_guid(riid
), riid
, rgszNames
, cNames
, lcid
, rgDispId
);
885 static HRESULT WINAPI
Basicaudio_Invoke(IBasicAudio
*iface
,
890 DISPPARAMS
*pDispParams
,
894 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
896 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
);
901 /*** IBasicAudio methods ***/
902 static HRESULT WINAPI
Basicaudio_put_Volume(IBasicAudio
*iface
,
904 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
906 TRACE("(%p/%p)->(%ld)\n", This
, iface
, lVolume
);
908 if (lVolume
> DSBVOLUME_MAX
|| lVolume
< DSBVOLUME_MIN
)
911 if (This
->dsbuffer
) {
912 if (FAILED(IDirectSoundBuffer_SetVolume(This
->dsbuffer
, lVolume
)))
916 This
->volume
= lVolume
;
920 static HRESULT WINAPI
Basicaudio_get_Volume(IBasicAudio
*iface
,
922 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
924 TRACE("(%p/%p)->(%p)\n", This
, iface
, plVolume
);
929 *plVolume
= This
->volume
;
933 static HRESULT WINAPI
Basicaudio_put_Balance(IBasicAudio
*iface
,
935 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
937 TRACE("(%p/%p)->(%ld)\n", This
, iface
, lBalance
);
939 if (lBalance
< DSBPAN_LEFT
|| lBalance
> DSBPAN_RIGHT
)
942 if (This
->dsbuffer
) {
943 if (FAILED(IDirectSoundBuffer_SetPan(This
->dsbuffer
, lBalance
)))
947 This
->pan
= lBalance
;
951 static HRESULT WINAPI
Basicaudio_get_Balance(IBasicAudio
*iface
,
953 ICOM_THIS_MULTI(DSoundRenderImpl
, IBasicAudio_vtbl
, iface
);
955 TRACE("(%p/%p)->(%p)\n", This
, iface
, plBalance
);
960 *plBalance
= This
->pan
;
964 static const IBasicAudioVtbl IBasicAudio_Vtbl
=
966 Basicaudio_QueryInterface
,
969 Basicaudio_GetTypeInfoCount
,
970 Basicaudio_GetTypeInfo
,
971 Basicaudio_GetIDsOfNames
,
973 Basicaudio_put_Volume
,
974 Basicaudio_get_Volume
,
975 Basicaudio_put_Balance
,
976 Basicaudio_get_Balance
980 /*** IUnknown methods ***/
981 static HRESULT WINAPI
ReferenceClock_QueryInterface(IReferenceClock
*iface
,
985 ICOM_THIS_MULTI(DSoundRenderImpl
, IReferenceClock_vtbl
, iface
);
987 TRACE("(%p/%p)->(%s (%p), %p)\n", This
, iface
, debugstr_guid(riid
), riid
, ppvObj
);
989 return DSoundRender_QueryInterface((IBaseFilter
*)This
, riid
, ppvObj
);
992 static ULONG WINAPI
ReferenceClock_AddRef(IReferenceClock
*iface
)
994 ICOM_THIS_MULTI(DSoundRenderImpl
, IReferenceClock_vtbl
, iface
);
996 TRACE("(%p/%p)->()\n", This
, iface
);
998 return DSoundRender_AddRef((IBaseFilter
*)This
);
1001 static ULONG WINAPI
ReferenceClock_Release(IReferenceClock
*iface
)
1003 ICOM_THIS_MULTI(DSoundRenderImpl
, IReferenceClock_vtbl
, iface
);
1005 TRACE("(%p/%p)->()\n", This
, iface
);
1007 return DSoundRender_Release((IBaseFilter
*)This
);
1010 /*** IReferenceClock methods ***/
1011 static HRESULT WINAPI
ReferenceClock_GetTime(IReferenceClock
*iface
,
1012 REFERENCE_TIME
*pTime
)
1014 ICOM_THIS_MULTI(DSoundRenderImpl
, IReferenceClock_vtbl
, iface
);
1015 HRESULT hr
= E_FAIL
;
1018 TRACE("(%p/%p)->(%p)\n", This
, iface
, pTime
);
1021 hr
= DSoundRender_GetPos(This
, &play_pos
, NULL
, pTime
);
1023 ERR("Could not get reference time (%x)!\n", hr
);
1028 static HRESULT WINAPI
ReferenceClock_AdviseTime(IReferenceClock
*iface
,
1029 REFERENCE_TIME rtBaseTime
,
1030 REFERENCE_TIME rtStreamTime
,
1032 DWORD_PTR
*pdwAdviseCookie
)
1034 ICOM_THIS_MULTI(DSoundRenderImpl
, IReferenceClock_vtbl
, iface
);
1036 FIXME("(%p/%p)->(%s, %s, %p, %p): stub!\n", This
, iface
, wine_dbgstr_longlong(rtBaseTime
), wine_dbgstr_longlong(rtStreamTime
), (void*)hEvent
, pdwAdviseCookie
);
1041 static HRESULT WINAPI
ReferenceClock_AdvisePeriodic(IReferenceClock
*iface
,
1042 REFERENCE_TIME rtBaseTime
,
1043 REFERENCE_TIME rtStreamTime
,
1044 HSEMAPHORE hSemaphore
,
1045 DWORD_PTR
*pdwAdviseCookie
)
1047 ICOM_THIS_MULTI(DSoundRenderImpl
, IReferenceClock_vtbl
, iface
);
1049 FIXME("(%p/%p)->(%s, %s, %p, %p): stub!\n", This
, iface
, wine_dbgstr_longlong(rtBaseTime
), wine_dbgstr_longlong(rtStreamTime
), (void*)hSemaphore
, pdwAdviseCookie
);
1054 static HRESULT WINAPI
ReferenceClock_Unadvise(IReferenceClock
*iface
,
1055 DWORD_PTR dwAdviseCookie
)
1057 ICOM_THIS_MULTI(DSoundRenderImpl
, IReferenceClock_vtbl
, iface
);
1059 FIXME("(%p/%p)->(%p): stub!\n", This
, iface
, (void*)dwAdviseCookie
);
1064 static const IReferenceClockVtbl IReferenceClock_Vtbl
=
1066 ReferenceClock_QueryInterface
,
1067 ReferenceClock_AddRef
,
1068 ReferenceClock_Release
,
1069 ReferenceClock_GetTime
,
1070 ReferenceClock_AdviseTime
,
1071 ReferenceClock_AdvisePeriodic
,
1072 ReferenceClock_Unadvise