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, rtLastStop;
60 IReferenceClock * pClock;
61 FILTER_INFO filterInfo;
65 IDirectSound8 *dsound;
66 LPDIRECTSOUNDBUFFER dsbuffer;
74 REFERENCE_TIME play_time;
75 MediaSeekingImpl mediaSeeking;
81 /* Seeking is not needed for a renderer, rely on newsegment for the appropriate changes */
82 static HRESULT sound_mod_stop(IBaseFilter *iface)
84 TRACE("(%p)\n", iface);
88 static HRESULT sound_mod_start(IBaseFilter *iface)
90 TRACE("(%p)\n", iface);
95 static HRESULT sound_mod_rate(IBaseFilter *iface)
97 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
99 WAVEFORMATEX *format = (WAVEFORMATEX*)This->pInputPin->pin.mtCurrent.pbFormat;
100 DWORD freq = format->nSamplesPerSec;
101 double rate = This->mediaSeeking.dRate;
103 freq = (DWORD)((double)freq * rate);
105 TRACE("(%p)\n", iface);
107 if (freq > DSBFREQUENCY_MAX)
108 return VFW_E_UNSUPPORTED_AUDIO;
110 if (freq < DSBFREQUENCY_MIN)
111 return VFW_E_UNSUPPORTED_AUDIO;
116 static inline HRESULT DSoundRender_GetPos(DSoundRenderImpl *This, DWORD *pPlayPos, REFERENCE_TIME *pRefTime)
120 EnterCriticalSection(&This->csFilter);
125 hr = IDirectSoundBuffer_GetStatus(This->dsbuffer, &state);
126 if (SUCCEEDED(hr) && !(state & DSBSTATUS_PLAYING) && This->state == State_Running)
128 TRACE("Not playing, kickstarting the engine\n");
130 hr = IDirectSoundBuffer_Play(This->dsbuffer, 0, 0, DSBPLAY_LOOPING);
132 ERR("Can't play sound buffer (%x)\n", hr);
136 hr = IDirectSoundBuffer_GetCurrentPosition(This->dsbuffer, pPlayPos, &write_pos);
139 DWORD play_pos = *pPlayPos;
141 if (play_pos < This->last_play_pos)
143 This->last_play_pos = play_pos;
145 /* If we really fell behind, start at the next possible position
146 * Also happens when just starting playback for the first time,
149 if ((This->play_loops*This->buf_size)+play_pos >=
150 (This->write_loops*This->buf_size)+This->write_pos)
151 This->write_pos = write_pos;
155 REFERENCE_TIME play_time;
156 play_time = ((REFERENCE_TIME)This->play_loops*10000000) +
157 ((REFERENCE_TIME)play_pos*10000000/This->buf_size);
159 /* Don't let time run backwards */
160 if(play_time-This->play_time > 0)
161 This->play_time = play_time;
165 *pRefTime = This->play_time;
169 LeaveCriticalSection(&This->csFilter);
174 static HRESULT DSoundRender_SendSampleData(DSoundRenderImpl* This, const BYTE *data, DWORD size)
177 LPBYTE lpbuf1 = NULL;
178 LPBYTE lpbuf2 = NULL;
182 DWORD play_pos,buf_free;
186 hr = DSoundRender_GetPos(This, &play_pos, NULL);
189 ERR("GetPos returned error: %x\n", hr);
192 if (This->write_pos <= play_pos)
193 buf_free = play_pos-This->write_pos;
195 buf_free = This->buf_size - This->write_pos + play_pos;
197 /* Wait for enough of the buffer to empty before filling it */
198 if(buf_free < This->buf_size/4)
204 size2 = min(buf_free, size);
205 hr = IDirectSoundBuffer_Lock(This->dsbuffer, This->write_pos, size2, (LPVOID *)&lpbuf1, &dwsize1, (LPVOID *)&lpbuf2, &dwsize2, 0);
207 ERR("Unable to lock sound buffer! (%x)\n", hr);
210 /* TRACE("write_pos=%d, size=%d, sz1=%d, sz2=%d\n", This->write_pos, size2, dwsize1, dwsize2); */
212 memcpy(lpbuf1, data, dwsize1);
214 memcpy(lpbuf2, data + dwsize1, dwsize2);
216 hr = IDirectSoundBuffer_Unlock(This->dsbuffer, lpbuf1, dwsize1, lpbuf2, dwsize2);
218 ERR("Unable to unlock sound buffer! (%x)\n", hr);
220 size -= dwsize1 + dwsize2;
221 data += dwsize1 + dwsize2;
222 This->write_pos += dwsize1 + dwsize2;
223 if (This->write_pos >= This->buf_size)
225 This->write_pos -= This->buf_size;
228 } while (size && This->state == State_Running);
233 static HRESULT DSoundRender_Sample(LPVOID iface, IMediaSample * pSample)
235 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
236 LPBYTE pbSrcStream = NULL;
237 long cbSrcStream = 0;
238 REFERENCE_TIME tStart, tStop;
241 TRACE("%p %p\n", iface, pSample);
243 /* Slightly incorrect, Pause completes when a frame is received so we should signal
244 * pause completion here, but for sound playing a single frame doesn't make sense
247 if (This->state == State_Paused)
250 if (This->state == State_Stopped)
253 hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
256 ERR("Cannot get pointer to sample data (%x)\n", hr);
260 hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
262 ERR("Cannot get sample time (%x)\n", hr);
264 if (This->rtLastStop != tStart && (IMediaSample_IsDiscontinuity(pSample) == S_FALSE))
265 FIXME("Unexpected discontinuity: Last: %u.%03u, tStart: %u.%03u\n",
266 (DWORD)(This->rtLastStop / 10000000), (DWORD)((This->rtLastStop / 10000)%1000),
267 (DWORD)(tStart / 10000000), (DWORD)((tStart / 10000)%1000));
268 This->rtLastStop = tStop;
270 if (IMediaSample_IsPreroll(pSample) == S_OK)
276 cbSrcStream = IMediaSample_GetActualDataLength(pSample);
277 TRACE("Sample data ptr = %p, size = %ld\n", pbSrcStream, cbSrcStream);
279 #if 0 /* For debugging purpose */
282 for(i = 0; i < cbSrcStream; i++)
284 if ((i!=0) && !(i%16))
286 TRACE("%02x ", pbSrcStream[i]);
292 return DSoundRender_SendSampleData(This, pbSrcStream, cbSrcStream);
295 static HRESULT DSoundRender_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
297 WAVEFORMATEX* format;
299 if (!IsEqualIID(&pmt->majortype, &MEDIATYPE_Audio))
302 format = (WAVEFORMATEX*)pmt->pbFormat;
303 TRACE("Format = %p\n", format);
304 TRACE("wFormatTag = %x %x\n", format->wFormatTag, WAVE_FORMAT_PCM);
305 TRACE("nChannels = %d\n", format->nChannels);
306 TRACE("nSamplesPerSec = %d\n", format->nAvgBytesPerSec);
307 TRACE("nAvgBytesPerSec = %d\n", format->nAvgBytesPerSec);
308 TRACE("nBlockAlign = %d\n", format->nBlockAlign);
309 TRACE("wBitsPerSample = %d\n", format->wBitsPerSample);
311 if (!IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_PCM))
317 HRESULT DSoundRender_create(IUnknown * pUnkOuter, LPVOID * ppv)
321 DSoundRenderImpl * pDSoundRender;
323 TRACE("(%p, %p)\n", pUnkOuter, ppv);
328 return CLASS_E_NOAGGREGATION;
330 pDSoundRender = CoTaskMemAlloc(sizeof(DSoundRenderImpl));
332 return E_OUTOFMEMORY;
333 ZeroMemory(pDSoundRender, sizeof(DSoundRenderImpl));
335 pDSoundRender->lpVtbl = &DSoundRender_Vtbl;
336 pDSoundRender->IBasicAudio_vtbl = &IBasicAudio_Vtbl;
337 pDSoundRender->IReferenceClock_vtbl = &IReferenceClock_Vtbl;
338 pDSoundRender->refCount = 1;
339 InitializeCriticalSection(&pDSoundRender->csFilter);
340 pDSoundRender->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": DSoundRenderImpl.csFilter");
341 pDSoundRender->state = State_Stopped;
343 /* construct input pin */
344 piInput.dir = PINDIR_INPUT;
345 piInput.pFilter = (IBaseFilter *)pDSoundRender;
346 lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
347 hr = InputPin_Construct(&DSoundRender_InputPin_Vtbl, &piInput, DSoundRender_Sample, pDSoundRender, DSoundRender_QueryAccept, NULL, &pDSoundRender->csFilter, NULL, (IPin **)&pDSoundRender->pInputPin);
351 hr = DirectSoundCreate8(NULL, &pDSoundRender->dsound, NULL);
353 ERR("Cannot create Direct Sound object (%x)\n", hr);
355 IDirectSound_SetCooperativeLevel(pDSoundRender->dsound, GetDesktopWindow(), DSSCL_PRIORITY);
360 MediaSeekingImpl_Init((IBaseFilter*)pDSoundRender, sound_mod_stop, sound_mod_start, sound_mod_rate, &pDSoundRender->mediaSeeking, &pDSoundRender->csFilter);
361 pDSoundRender->mediaSeeking.lpVtbl = &IMediaSeeking_Vtbl;
363 *ppv = (LPVOID)pDSoundRender;
367 if (pDSoundRender->pInputPin)
368 IPin_Release((IPin*)pDSoundRender->pInputPin);
369 pDSoundRender->csFilter.DebugInfo->Spare[0] = 0;
370 DeleteCriticalSection(&pDSoundRender->csFilter);
371 CoTaskMemFree(pDSoundRender);
377 static HRESULT WINAPI DSoundRender_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
379 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
380 TRACE("(%p, %p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
384 if (IsEqualIID(riid, &IID_IUnknown))
386 else if (IsEqualIID(riid, &IID_IPersist))
388 else if (IsEqualIID(riid, &IID_IMediaFilter))
390 else if (IsEqualIID(riid, &IID_IBaseFilter))
392 else if (IsEqualIID(riid, &IID_IBasicAudio))
393 *ppv = (LPVOID)&(This->IBasicAudio_vtbl);
394 else if (IsEqualIID(riid, &IID_IReferenceClock))
395 *ppv = (LPVOID)&(This->IReferenceClock_vtbl);
396 else if (IsEqualIID(riid, &IID_IMediaSeeking))
397 *ppv = &This->mediaSeeking.lpVtbl;
401 IUnknown_AddRef((IUnknown *)(*ppv));
405 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IVideoWindow))
406 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
408 return E_NOINTERFACE;
411 static ULONG WINAPI DSoundRender_AddRef(IBaseFilter * iface)
413 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
414 ULONG refCount = InterlockedIncrement(&This->refCount);
416 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
421 static ULONG WINAPI DSoundRender_Release(IBaseFilter * iface)
423 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
424 ULONG refCount = InterlockedDecrement(&This->refCount);
426 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
433 IReferenceClock_Release(This->pClock);
436 IDirectSoundBuffer_Release(This->dsbuffer);
437 This->dsbuffer = NULL;
439 IDirectSound_Release(This->dsound);
442 if (SUCCEEDED(IPin_ConnectedTo((IPin *)This->pInputPin, &pConnectedTo)))
444 IPin_Disconnect(pConnectedTo);
445 IPin_Release(pConnectedTo);
447 IPin_Disconnect((IPin *)This->pInputPin);
449 IPin_Release((IPin *)This->pInputPin);
452 This->IBasicAudio_vtbl = NULL;
454 This->csFilter.DebugInfo->Spare[0] = 0;
455 DeleteCriticalSection(&This->csFilter);
457 TRACE("Destroying Audio Renderer\n");
466 /** IPersist methods **/
468 static HRESULT WINAPI DSoundRender_GetClassID(IBaseFilter * iface, CLSID * pClsid)
470 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
471 TRACE("(%p/%p)->(%p)\n", This, iface, pClsid);
473 *pClsid = CLSID_DSoundRender;
478 /** IMediaFilter methods **/
480 static HRESULT WINAPI DSoundRender_Stop(IBaseFilter * iface)
483 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
485 TRACE("(%p/%p)->()\n", This, iface);
487 EnterCriticalSection(&This->csFilter);
492 hr = IDirectSoundBuffer_GetStatus(This->dsbuffer, &state);
495 if (state & DSBSTATUS_PLAYING)
496 hr = IDirectSoundBuffer_Stop(This->dsbuffer);
500 This->state = State_Stopped;
502 LeaveCriticalSection(&This->csFilter);
507 static HRESULT WINAPI DSoundRender_Pause(IBaseFilter * iface)
510 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
512 TRACE("(%p/%p)->()\n", This, iface);
514 EnterCriticalSection(&This->csFilter);
517 if (This->state == State_Stopped)
518 This->pInputPin->end_of_stream = 0;
522 hr = IDirectSoundBuffer_GetStatus(This->dsbuffer, &state);
525 if (state & DSBSTATUS_PLAYING)
526 hr = IDirectSoundBuffer_Stop(This->dsbuffer);
530 This->state = State_Paused;
532 LeaveCriticalSection(&This->csFilter);
537 static HRESULT WINAPI DSoundRender_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
540 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
542 TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
544 EnterCriticalSection(&This->csFilter);
546 This->rtStreamStart = tStart;
547 This->state = State_Running;
548 This->pInputPin->end_of_stream = 0;
550 LeaveCriticalSection(&This->csFilter);
555 static HRESULT WINAPI DSoundRender_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
557 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
559 TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
561 EnterCriticalSection(&This->csFilter);
563 *pState = This->state;
565 LeaveCriticalSection(&This->csFilter);
570 static HRESULT WINAPI DSoundRender_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
572 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
574 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
576 EnterCriticalSection(&This->csFilter);
579 IReferenceClock_Release(This->pClock);
580 This->pClock = pClock;
582 IReferenceClock_AddRef(This->pClock);
584 LeaveCriticalSection(&This->csFilter);
589 static HRESULT WINAPI DSoundRender_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
591 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
593 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
595 EnterCriticalSection(&This->csFilter);
597 *ppClock = This->pClock;
599 IReferenceClock_AddRef(This->pClock);
601 LeaveCriticalSection(&This->csFilter);
606 /** IBaseFilter implementation **/
608 static HRESULT DSoundRender_GetPin(IBaseFilter *iface, ULONG pos, IPin **pin, DWORD *lastsynctick)
610 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
612 /* Our pins are static, not changing so setting static tick count is ok */
618 *pin = (IPin *)This->pInputPin;
623 static HRESULT WINAPI DSoundRender_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
625 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
627 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
629 return IEnumPinsImpl_Construct(ppEnum, DSoundRender_GetPin, iface);
632 static HRESULT WINAPI DSoundRender_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
634 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
636 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_w(Id), ppPin);
638 FIXME("DSoundRender::FindPin(...)\n");
640 /* FIXME: critical section */
645 static HRESULT WINAPI DSoundRender_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
647 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
649 TRACE("(%p/%p)->(%p)\n", This, iface, pInfo);
651 strcpyW(pInfo->achName, This->filterInfo.achName);
652 pInfo->pGraph = This->filterInfo.pGraph;
655 IFilterGraph_AddRef(pInfo->pGraph);
660 static HRESULT WINAPI DSoundRender_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
662 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
664 TRACE("(%p/%p)->(%p, %s)\n", This, iface, pGraph, debugstr_w(pName));
666 EnterCriticalSection(&This->csFilter);
669 strcpyW(This->filterInfo.achName, pName);
671 *This->filterInfo.achName = '\0';
672 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
674 LeaveCriticalSection(&This->csFilter);
679 static HRESULT WINAPI DSoundRender_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
681 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
682 TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
686 static const IBaseFilterVtbl DSoundRender_Vtbl =
688 DSoundRender_QueryInterface,
690 DSoundRender_Release,
691 DSoundRender_GetClassID,
695 DSoundRender_GetState,
696 DSoundRender_SetSyncSource,
697 DSoundRender_GetSyncSource,
698 DSoundRender_EnumPins,
699 DSoundRender_FindPin,
700 DSoundRender_QueryFilterInfo,
701 DSoundRender_JoinFilterGraph,
702 DSoundRender_QueryVendorInfo
705 static HRESULT WINAPI DSoundRender_InputPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
707 InputPin *This = (InputPin *)iface;
708 PIN_DIRECTION pindirReceive;
709 DSoundRenderImpl *DSImpl;
712 TRACE("(%p)->(%p, %p)\n", This, pReceivePin, pmt);
713 dump_AM_MEDIA_TYPE(pmt);
715 EnterCriticalSection(This->pin.pCritSec);
717 DSImpl = (DSoundRenderImpl*)This->pin.pinInfo.pFilter;
718 DSImpl->rtLastStop = -1;
720 if (This->pin.pConnectedTo)
721 hr = VFW_E_ALREADY_CONNECTED;
723 if (SUCCEEDED(hr) && This->pin.fnQueryAccept(This->pin.pUserData, pmt) != S_OK)
724 hr = VFW_E_TYPE_NOT_ACCEPTED;
728 IPin_QueryDirection(pReceivePin, &pindirReceive);
730 if (pindirReceive != PINDIR_OUTPUT)
732 ERR("Can't connect from non-output pin\n");
733 hr = VFW_E_INVALID_DIRECTION;
739 WAVEFORMATEX *format;
740 DSBUFFERDESC buf_desc;
742 TRACE("MajorType %s\n", debugstr_guid(&pmt->majortype));
743 TRACE("SubType %s\n", debugstr_guid(&pmt->subtype));
744 TRACE("Format %s\n", debugstr_guid(&pmt->formattype));
745 TRACE("Size %d\n", pmt->cbFormat);
747 format = (WAVEFORMATEX*)pmt->pbFormat;
749 DSImpl->buf_size = format->nAvgBytesPerSec;
751 memset(&buf_desc,0,sizeof(DSBUFFERDESC));
752 buf_desc.dwSize = sizeof(DSBUFFERDESC);
753 buf_desc.dwFlags = DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN |
754 DSBCAPS_CTRLFREQUENCY |
755 DSBCAPS_GETCURRENTPOSITION2;
756 buf_desc.dwBufferBytes = DSImpl->buf_size;
757 buf_desc.lpwfxFormat = format;
758 hr = IDirectSound_CreateSoundBuffer(DSImpl->dsound, &buf_desc, &DSImpl->dsbuffer, NULL);
760 ERR("Can't create sound buffer (%x)\n", hr);
765 hr = IDirectSoundBuffer_SetVolume(DSImpl->dsbuffer, DSImpl->volume);
767 ERR("Can't set volume to %ld (%x)\n", DSImpl->volume, hr);
769 hr = IDirectSoundBuffer_SetPan(DSImpl->dsbuffer, DSImpl->pan);
771 ERR("Can't set pan to %ld (%x)\n", DSImpl->pan, hr);
773 DSImpl->write_pos = 0;
779 CopyMediaType(&This->pin.mtCurrent, pmt);
780 This->pin.pConnectedTo = pReceivePin;
781 IPin_AddRef(pReceivePin);
785 if (DSImpl->dsbuffer)
786 IDirectSoundBuffer_Release(DSImpl->dsbuffer);
787 DSImpl->dsbuffer = NULL;
790 LeaveCriticalSection(This->pin.pCritSec);
795 static HRESULT WINAPI DSoundRender_InputPin_Disconnect(IPin * iface)
797 IPinImpl *This = (IPinImpl*)iface;
798 DSoundRenderImpl *DSImpl;
800 TRACE("(%p)->()\n", iface);
802 DSImpl = (DSoundRenderImpl*)This->pinInfo.pFilter;
803 if (DSImpl->dsbuffer)
804 IDirectSoundBuffer_Release(DSImpl->dsbuffer);
805 DSImpl->dsbuffer = NULL;
807 return IPinImpl_Disconnect(iface);
810 static HRESULT WINAPI DSoundRender_InputPin_EndOfStream(IPin * iface)
812 InputPin* This = (InputPin*)iface;
813 DSoundRenderImpl *me = (DSoundRenderImpl*)This->pin.pinInfo.pFilter;
814 IMediaEventSink* pEventSink;
817 EnterCriticalSection(This->pin.pCritSec);
819 TRACE("(%p/%p)->()\n", This, iface);
820 InputPin_EndOfStream(iface);
822 hr = IFilterGraph_QueryInterface(me->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
827 silence = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, me->buf_size);
830 memset(silence, 0, me->buf_size);
831 DSoundRender_SendSampleData((DSoundRenderImpl*)This->pin.pinInfo.pFilter, silence, me->buf_size);
832 HeapFree(GetProcessHeap(), 0, silence);
835 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
836 IMediaEventSink_Release(pEventSink);
838 LeaveCriticalSection(This->pin.pCritSec);
843 static HRESULT WINAPI DSoundRender_InputPin_BeginFlush(IPin * iface)
845 InputPin *This = (InputPin *)iface;
846 DSoundRenderImpl *pFilter = (DSoundRenderImpl *)This->pin.pinInfo.pFilter;
853 EnterCriticalSection(This->pin.pCritSec);
854 hr = InputPin_BeginFlush(iface);
856 if (pFilter->dsbuffer)
858 IDirectSoundBuffer_Stop(pFilter->dsbuffer);
861 IDirectSoundBuffer_SetCurrentPosition(pFilter->dsbuffer, 0);
862 pFilter->write_pos = pFilter->last_play_pos = 0;
863 ++pFilter->play_loops;
864 pFilter->write_loops = pFilter->play_loops;
866 IDirectSoundBuffer_Lock(pFilter->dsbuffer, 0, 0, (LPVOID *)&buffer, &size, NULL, NULL, DSBLOCK_ENTIREBUFFER);
867 memset(buffer, 0, size);
868 IDirectSoundBuffer_Unlock(pFilter->dsbuffer, buffer, size, NULL, 0);
870 LeaveCriticalSection(This->pin.pCritSec);
875 static const IPinVtbl DSoundRender_InputPin_Vtbl =
877 InputPin_QueryInterface,
881 DSoundRender_InputPin_ReceiveConnection,
882 DSoundRender_InputPin_Disconnect,
883 IPinImpl_ConnectedTo,
884 IPinImpl_ConnectionMediaType,
885 IPinImpl_QueryPinInfo,
886 IPinImpl_QueryDirection,
888 IPinImpl_QueryAccept,
889 IPinImpl_EnumMediaTypes,
890 IPinImpl_QueryInternalConnections,
891 DSoundRender_InputPin_EndOfStream,
892 DSoundRender_InputPin_BeginFlush,
897 static const IMemInputPinVtbl MemInputPin_Vtbl =
899 MemInputPin_QueryInterface,
902 MemInputPin_GetAllocator,
903 MemInputPin_NotifyAllocator,
904 MemInputPin_GetAllocatorRequirements,
906 MemInputPin_ReceiveMultiple,
907 MemInputPin_ReceiveCanBlock
910 /*** IUnknown methods ***/
911 static HRESULT WINAPI Basicaudio_QueryInterface(IBasicAudio *iface,
914 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
916 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
918 return DSoundRender_QueryInterface((IBaseFilter*)This, riid, ppvObj);
921 static ULONG WINAPI Basicaudio_AddRef(IBasicAudio *iface) {
922 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
924 TRACE("(%p/%p)->()\n", This, iface);
926 return DSoundRender_AddRef((IBaseFilter*)This);
929 static ULONG WINAPI Basicaudio_Release(IBasicAudio *iface) {
930 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
932 TRACE("(%p/%p)->()\n", This, iface);
934 return DSoundRender_Release((IBaseFilter*)This);
937 /*** IDispatch methods ***/
938 static HRESULT WINAPI Basicaudio_GetTypeInfoCount(IBasicAudio *iface,
940 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
942 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
947 static HRESULT WINAPI Basicaudio_GetTypeInfo(IBasicAudio *iface,
950 ITypeInfo**ppTInfo) {
951 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
953 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
958 static HRESULT WINAPI Basicaudio_GetIDsOfNames(IBasicAudio *iface,
964 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
966 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
971 static HRESULT WINAPI Basicaudio_Invoke(IBasicAudio *iface,
976 DISPPARAMS*pDispParams,
980 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
982 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);
987 /*** IBasicAudio methods ***/
988 static HRESULT WINAPI Basicaudio_put_Volume(IBasicAudio *iface,
990 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
992 TRACE("(%p/%p)->(%ld)\n", This, iface, lVolume);
994 if (lVolume > DSBVOLUME_MAX || lVolume < DSBVOLUME_MIN)
997 if (This->dsbuffer) {
998 if (FAILED(IDirectSoundBuffer_SetVolume(This->dsbuffer, lVolume)))
1002 This->volume = lVolume;
1006 static HRESULT WINAPI Basicaudio_get_Volume(IBasicAudio *iface,
1008 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1010 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
1015 *plVolume = This->volume;
1019 static HRESULT WINAPI Basicaudio_put_Balance(IBasicAudio *iface,
1021 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1023 TRACE("(%p/%p)->(%ld)\n", This, iface, lBalance);
1025 if (lBalance < DSBPAN_LEFT || lBalance > DSBPAN_RIGHT)
1026 return E_INVALIDARG;
1028 if (This->dsbuffer) {
1029 if (FAILED(IDirectSoundBuffer_SetPan(This->dsbuffer, lBalance)))
1033 This->pan = lBalance;
1037 static HRESULT WINAPI Basicaudio_get_Balance(IBasicAudio *iface,
1039 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1041 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
1046 *plBalance = This->pan;
1050 static const IBasicAudioVtbl IBasicAudio_Vtbl =
1052 Basicaudio_QueryInterface,
1055 Basicaudio_GetTypeInfoCount,
1056 Basicaudio_GetTypeInfo,
1057 Basicaudio_GetIDsOfNames,
1059 Basicaudio_put_Volume,
1060 Basicaudio_get_Volume,
1061 Basicaudio_put_Balance,
1062 Basicaudio_get_Balance
1066 /*** IUnknown methods ***/
1067 static HRESULT WINAPI ReferenceClock_QueryInterface(IReferenceClock *iface,
1071 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1073 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1075 return DSoundRender_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1078 static ULONG WINAPI ReferenceClock_AddRef(IReferenceClock *iface)
1080 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1082 TRACE("(%p/%p)->()\n", This, iface);
1084 return DSoundRender_AddRef((IBaseFilter*)This);
1087 static ULONG WINAPI ReferenceClock_Release(IReferenceClock *iface)
1089 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1091 TRACE("(%p/%p)->()\n", This, iface);
1093 return DSoundRender_Release((IBaseFilter*)This);
1096 /*** IReferenceClock methods ***/
1097 static HRESULT WINAPI ReferenceClock_GetTime(IReferenceClock *iface,
1098 REFERENCE_TIME *pTime)
1100 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1101 HRESULT hr = E_FAIL;
1104 TRACE("(%p/%p)->(%p)\n", This, iface, pTime);
1107 hr = DSoundRender_GetPos(This, &play_pos, pTime);
1109 ERR("Could not get reference time (%x)!\n", hr);
1114 static HRESULT WINAPI ReferenceClock_AdviseTime(IReferenceClock *iface,
1115 REFERENCE_TIME rtBaseTime,
1116 REFERENCE_TIME rtStreamTime,
1118 DWORD_PTR *pdwAdviseCookie)
1120 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1122 FIXME("(%p/%p)->(%s, %s, %p, %p): stub!\n", This, iface, wine_dbgstr_longlong(rtBaseTime), wine_dbgstr_longlong(rtStreamTime), (void*)hEvent, pdwAdviseCookie);
1127 static HRESULT WINAPI ReferenceClock_AdvisePeriodic(IReferenceClock *iface,
1128 REFERENCE_TIME rtBaseTime,
1129 REFERENCE_TIME rtStreamTime,
1130 HSEMAPHORE hSemaphore,
1131 DWORD_PTR *pdwAdviseCookie)
1133 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1135 FIXME("(%p/%p)->(%s, %s, %p, %p): stub!\n", This, iface, wine_dbgstr_longlong(rtBaseTime), wine_dbgstr_longlong(rtStreamTime), (void*)hSemaphore, pdwAdviseCookie);
1140 static HRESULT WINAPI ReferenceClock_Unadvise(IReferenceClock *iface,
1141 DWORD_PTR dwAdviseCookie)
1143 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1145 FIXME("(%p/%p)->(%p): stub!\n", This, iface, (void*)dwAdviseCookie);
1150 static const IReferenceClockVtbl IReferenceClock_Vtbl =
1152 ReferenceClock_QueryInterface,
1153 ReferenceClock_AddRef,
1154 ReferenceClock_Release,
1155 ReferenceClock_GetTime,
1156 ReferenceClock_AdviseTime,
1157 ReferenceClock_AdvisePeriodic,
1158 ReferenceClock_Unadvise
1161 static inline DSoundRenderImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
1163 return (DSoundRenderImpl *)((char*)iface - FIELD_OFFSET(DSoundRenderImpl, mediaSeeking.lpVtbl));
1166 static HRESULT WINAPI sound_seek_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
1168 DSoundRenderImpl *This = impl_from_IMediaSeeking(iface);
1170 return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
1173 static ULONG WINAPI sound_seek_AddRef(IMediaSeeking * iface)
1175 DSoundRenderImpl *This = impl_from_IMediaSeeking(iface);
1177 return IUnknown_AddRef((IUnknown *)This);
1180 static ULONG WINAPI sound_seek_Release(IMediaSeeking * iface)
1182 DSoundRenderImpl *This = impl_from_IMediaSeeking(iface);
1184 return IUnknown_Release((IUnknown *)This);
1187 static const IMediaSeekingVtbl IMediaSeeking_Vtbl =
1189 sound_seek_QueryInterface,
1192 MediaSeekingImpl_GetCapabilities,
1193 MediaSeekingImpl_CheckCapabilities,
1194 MediaSeekingImpl_IsFormatSupported,
1195 MediaSeekingImpl_QueryPreferredFormat,
1196 MediaSeekingImpl_GetTimeFormat,
1197 MediaSeekingImpl_IsUsingTimeFormat,
1198 MediaSeekingImpl_SetTimeFormat,
1199 MediaSeekingImpl_GetDuration,
1200 MediaSeekingImpl_GetStopPosition,
1201 MediaSeekingImpl_GetCurrentPosition,
1202 MediaSeekingImpl_ConvertTimeFormat,
1203 MediaSeekingImpl_SetPositions,
1204 MediaSeekingImpl_GetPositions,
1205 MediaSeekingImpl_GetAvailable,
1206 MediaSeekingImpl_SetRate,
1207 MediaSeekingImpl_GetRate,
1208 MediaSeekingImpl_GetPreroll