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;
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 = (WAVEFORMATEX*)pmt->pbFormat;
298 TRACE("wFormatTag = %x %x\n", format->wFormatTag, WAVE_FORMAT_PCM);
299 TRACE("nChannels = %d\n", format->nChannels);
300 TRACE("nSamplesPerSec = %d\n", format->nAvgBytesPerSec);
301 TRACE("nAvgBytesPerSec = %d\n", format->nAvgBytesPerSec);
302 TRACE("nBlockAlign = %d\n", format->nBlockAlign);
303 TRACE("wBitsPerSample = %d\n", format->wBitsPerSample);
305 if (IsEqualIID(&pmt->majortype, &MEDIATYPE_Audio) && IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_PCM))
310 HRESULT DSoundRender_create(IUnknown * pUnkOuter, LPVOID * ppv)
314 DSoundRenderImpl * pDSoundRender;
316 TRACE("(%p, %p)\n", pUnkOuter, ppv);
321 return CLASS_E_NOAGGREGATION;
323 pDSoundRender = CoTaskMemAlloc(sizeof(DSoundRenderImpl));
325 return E_OUTOFMEMORY;
326 ZeroMemory(pDSoundRender, sizeof(DSoundRenderImpl));
328 pDSoundRender->lpVtbl = &DSoundRender_Vtbl;
329 pDSoundRender->IBasicAudio_vtbl = &IBasicAudio_Vtbl;
330 pDSoundRender->IReferenceClock_vtbl = &IReferenceClock_Vtbl;
331 pDSoundRender->refCount = 1;
332 InitializeCriticalSection(&pDSoundRender->csFilter);
333 pDSoundRender->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": DSoundRenderImpl.csFilter");
334 pDSoundRender->state = State_Stopped;
336 /* construct input pin */
337 piInput.dir = PINDIR_INPUT;
338 piInput.pFilter = (IBaseFilter *)pDSoundRender;
339 lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
340 hr = InputPin_Construct(&DSoundRender_InputPin_Vtbl, &piInput, DSoundRender_Sample, pDSoundRender, DSoundRender_QueryAccept, NULL, &pDSoundRender->csFilter, (IPin **)&pDSoundRender->pInputPin);
344 hr = DirectSoundCreate(NULL, &pDSoundRender->dsound, NULL);
346 ERR("Cannot create Direct Sound object (%x)\n", hr);
351 MediaSeekingImpl_Init((IBaseFilter*)pDSoundRender, sound_mod_stop, sound_mod_start, sound_mod_rate, &pDSoundRender->mediaSeeking, &pDSoundRender->csFilter);
352 pDSoundRender->mediaSeeking.lpVtbl = &IMediaSeeking_Vtbl;
354 *ppv = (LPVOID)pDSoundRender;
358 if (pDSoundRender->pInputPin)
359 IPin_Release((IPin*)pDSoundRender->pInputPin);
360 pDSoundRender->csFilter.DebugInfo->Spare[0] = 0;
361 DeleteCriticalSection(&pDSoundRender->csFilter);
362 CoTaskMemFree(pDSoundRender);
368 static HRESULT WINAPI DSoundRender_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
370 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
371 TRACE("(%p, %p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
375 if (IsEqualIID(riid, &IID_IUnknown))
377 else if (IsEqualIID(riid, &IID_IPersist))
379 else if (IsEqualIID(riid, &IID_IMediaFilter))
381 else if (IsEqualIID(riid, &IID_IBaseFilter))
383 else if (IsEqualIID(riid, &IID_IBasicAudio))
384 *ppv = (LPVOID)&(This->IBasicAudio_vtbl);
385 else if (IsEqualIID(riid, &IID_IReferenceClock))
386 *ppv = (LPVOID)&(This->IReferenceClock_vtbl);
387 else if (IsEqualIID(riid, &IID_IMediaSeeking))
388 *ppv = &This->mediaSeeking.lpVtbl;
392 IUnknown_AddRef((IUnknown *)(*ppv));
396 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IVideoWindow))
397 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
399 return E_NOINTERFACE;
402 static ULONG WINAPI DSoundRender_AddRef(IBaseFilter * iface)
404 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
405 ULONG refCount = InterlockedIncrement(&This->refCount);
407 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
412 static ULONG WINAPI DSoundRender_Release(IBaseFilter * iface)
414 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
415 ULONG refCount = InterlockedDecrement(&This->refCount);
417 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
424 IReferenceClock_Release(This->pClock);
427 IDirectSoundBuffer_Release(This->dsbuffer);
428 This->dsbuffer = NULL;
430 IDirectSound_Release(This->dsound);
433 if (SUCCEEDED(IPin_ConnectedTo((IPin *)This->pInputPin, &pConnectedTo)))
435 IPin_Disconnect(pConnectedTo);
436 IPin_Release(pConnectedTo);
438 IPin_Disconnect((IPin *)This->pInputPin);
440 IPin_Release((IPin *)This->pInputPin);
443 This->IBasicAudio_vtbl = NULL;
445 This->csFilter.DebugInfo->Spare[0] = 0;
446 DeleteCriticalSection(&This->csFilter);
448 TRACE("Destroying Audio Renderer\n");
457 /** IPersist methods **/
459 static HRESULT WINAPI DSoundRender_GetClassID(IBaseFilter * iface, CLSID * pClsid)
461 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
462 TRACE("(%p/%p)->(%p)\n", This, iface, pClsid);
464 *pClsid = CLSID_DSoundRender;
469 /** IMediaFilter methods **/
471 static HRESULT WINAPI DSoundRender_Stop(IBaseFilter * iface)
474 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
476 TRACE("(%p/%p)->()\n", This, iface);
478 EnterCriticalSection(&This->csFilter);
483 hr = IDirectSoundBuffer_GetStatus(This->dsbuffer, &state);
486 if (state & DSBSTATUS_PLAYING)
487 hr = IDirectSoundBuffer_Stop(This->dsbuffer);
491 This->state = State_Stopped;
493 LeaveCriticalSection(&This->csFilter);
498 static HRESULT WINAPI DSoundRender_Pause(IBaseFilter * iface)
501 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
503 TRACE("(%p/%p)->()\n", This, iface);
505 EnterCriticalSection(&This->csFilter);
508 if (This->state == State_Stopped)
509 This->pInputPin->end_of_stream = 0;
513 hr = IDirectSoundBuffer_GetStatus(This->dsbuffer, &state);
516 if (state & DSBSTATUS_PLAYING)
517 hr = IDirectSoundBuffer_Stop(This->dsbuffer);
521 This->state = State_Paused;
523 LeaveCriticalSection(&This->csFilter);
528 static HRESULT WINAPI DSoundRender_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
531 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
533 TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
535 EnterCriticalSection(&This->csFilter);
537 This->rtStreamStart = tStart;
538 This->state = State_Running;
539 This->pInputPin->end_of_stream = 0;
541 LeaveCriticalSection(&This->csFilter);
546 static HRESULT WINAPI DSoundRender_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
548 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
550 TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
552 EnterCriticalSection(&This->csFilter);
554 *pState = This->state;
556 LeaveCriticalSection(&This->csFilter);
561 static HRESULT WINAPI DSoundRender_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
563 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
565 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
567 EnterCriticalSection(&This->csFilter);
570 IReferenceClock_Release(This->pClock);
571 This->pClock = pClock;
573 IReferenceClock_AddRef(This->pClock);
575 LeaveCriticalSection(&This->csFilter);
580 static HRESULT WINAPI DSoundRender_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
582 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
584 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
586 EnterCriticalSection(&This->csFilter);
588 *ppClock = This->pClock;
590 IReferenceClock_AddRef(This->pClock);
592 LeaveCriticalSection(&This->csFilter);
597 /** IBaseFilter implementation **/
599 static HRESULT DSoundRender_GetPin(IBaseFilter *iface, ULONG pos, IPin **pin, DWORD *lastsynctick)
601 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
603 /* Our pins are static, not changing so setting static tick count is ok */
609 *pin = (IPin *)This->pInputPin;
614 static HRESULT WINAPI DSoundRender_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
616 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
618 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
620 return IEnumPinsImpl_Construct(ppEnum, DSoundRender_GetPin, iface);
623 static HRESULT WINAPI DSoundRender_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
625 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
627 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_w(Id), ppPin);
629 FIXME("DSoundRender::FindPin(...)\n");
631 /* FIXME: critical section */
636 static HRESULT WINAPI DSoundRender_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
638 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
640 TRACE("(%p/%p)->(%p)\n", This, iface, pInfo);
642 strcpyW(pInfo->achName, This->filterInfo.achName);
643 pInfo->pGraph = This->filterInfo.pGraph;
646 IFilterGraph_AddRef(pInfo->pGraph);
651 static HRESULT WINAPI DSoundRender_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
653 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
655 TRACE("(%p/%p)->(%p, %s)\n", This, iface, pGraph, debugstr_w(pName));
657 EnterCriticalSection(&This->csFilter);
660 strcpyW(This->filterInfo.achName, pName);
662 *This->filterInfo.achName = '\0';
663 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
665 LeaveCriticalSection(&This->csFilter);
670 static HRESULT WINAPI DSoundRender_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
672 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
673 TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
677 static const IBaseFilterVtbl DSoundRender_Vtbl =
679 DSoundRender_QueryInterface,
681 DSoundRender_Release,
682 DSoundRender_GetClassID,
686 DSoundRender_GetState,
687 DSoundRender_SetSyncSource,
688 DSoundRender_GetSyncSource,
689 DSoundRender_EnumPins,
690 DSoundRender_FindPin,
691 DSoundRender_QueryFilterInfo,
692 DSoundRender_JoinFilterGraph,
693 DSoundRender_QueryVendorInfo
696 static HRESULT WINAPI DSoundRender_InputPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
698 InputPin *This = (InputPin *)iface;
699 PIN_DIRECTION pindirReceive;
700 DSoundRenderImpl *DSImpl;
703 TRACE("(%p)->(%p, %p)\n", This, pReceivePin, pmt);
704 dump_AM_MEDIA_TYPE(pmt);
706 EnterCriticalSection(This->pin.pCritSec);
708 DSImpl = (DSoundRenderImpl*)This->pin.pinInfo.pFilter;
709 DSImpl->rtLastStop = -1;
711 if (This->pin.pConnectedTo)
712 hr = VFW_E_ALREADY_CONNECTED;
714 if (SUCCEEDED(hr) && This->pin.fnQueryAccept(This->pin.pUserData, pmt) != S_OK)
715 hr = VFW_E_TYPE_NOT_ACCEPTED;
719 IPin_QueryDirection(pReceivePin, &pindirReceive);
721 if (pindirReceive != PINDIR_OUTPUT)
723 ERR("Can't connect from non-output pin\n");
724 hr = VFW_E_INVALID_DIRECTION;
730 WAVEFORMATEX *format;
731 DSBUFFERDESC buf_desc;
733 TRACE("MajorType %s\n", debugstr_guid(&pmt->majortype));
734 TRACE("SubType %s\n", debugstr_guid(&pmt->subtype));
735 TRACE("Format %s\n", debugstr_guid(&pmt->formattype));
736 TRACE("Size %d\n", pmt->cbFormat);
738 format = (WAVEFORMATEX*)pmt->pbFormat;
740 DSImpl->buf_size = format->nAvgBytesPerSec;
742 memset(&buf_desc,0,sizeof(DSBUFFERDESC));
743 buf_desc.dwSize = sizeof(DSBUFFERDESC);
744 buf_desc.dwFlags = DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN |
745 DSBCAPS_CTRLFREQUENCY |
746 DSBCAPS_GETCURRENTPOSITION2;
747 buf_desc.dwBufferBytes = DSImpl->buf_size;
748 buf_desc.lpwfxFormat = format;
749 hr = IDirectSound_CreateSoundBuffer(DSImpl->dsound, &buf_desc, &DSImpl->dsbuffer, NULL);
751 ERR("Can't create sound buffer (%x)\n", hr);
756 hr = IDirectSoundBuffer_SetVolume(DSImpl->dsbuffer, DSImpl->volume);
758 ERR("Can't set volume to %ld (%x)\n", DSImpl->volume, hr);
760 hr = IDirectSoundBuffer_SetPan(DSImpl->dsbuffer, DSImpl->pan);
762 ERR("Can't set pan to %ld (%x)\n", DSImpl->pan, hr);
764 DSImpl->write_pos = 0;
770 CopyMediaType(&This->pin.mtCurrent, pmt);
771 This->pin.pConnectedTo = pReceivePin;
772 IPin_AddRef(pReceivePin);
776 if (DSImpl->dsbuffer)
777 IDirectSoundBuffer_Release(DSImpl->dsbuffer);
778 DSImpl->dsbuffer = NULL;
781 LeaveCriticalSection(This->pin.pCritSec);
786 static HRESULT WINAPI DSoundRender_InputPin_Disconnect(IPin * iface)
788 IPinImpl *This = (IPinImpl*)iface;
789 DSoundRenderImpl *DSImpl;
791 TRACE("(%p)->()\n", iface);
793 DSImpl = (DSoundRenderImpl*)This->pinInfo.pFilter;
794 if (DSImpl->dsbuffer)
795 IDirectSoundBuffer_Release(DSImpl->dsbuffer);
796 DSImpl->dsbuffer = NULL;
798 return IPinImpl_Disconnect(iface);
801 static HRESULT WINAPI DSoundRender_InputPin_EndOfStream(IPin * iface)
803 InputPin* This = (InputPin*)iface;
804 DSoundRenderImpl *me = (DSoundRenderImpl*)This->pin.pinInfo.pFilter;
805 IMediaEventSink* pEventSink;
808 EnterCriticalSection(This->pin.pCritSec);
810 TRACE("(%p/%p)->()\n", This, iface);
811 InputPin_EndOfStream(iface);
813 hr = IFilterGraph_QueryInterface(me->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
818 silence = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, me->buf_size);
821 memset(silence, 0, me->buf_size);
822 DSoundRender_SendSampleData((DSoundRenderImpl*)This->pin.pinInfo.pFilter, silence, me->buf_size);
823 HeapFree(GetProcessHeap(), 0, silence);
826 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
827 IMediaEventSink_Release(pEventSink);
829 LeaveCriticalSection(This->pin.pCritSec);
834 static HRESULT WINAPI DSoundRender_InputPin_BeginFlush(IPin * iface)
836 InputPin *This = (InputPin *)iface;
837 DSoundRenderImpl *pFilter = (DSoundRenderImpl *)This->pin.pinInfo.pFilter;
844 EnterCriticalSection(This->pin.pCritSec);
845 hr = InputPin_BeginFlush(iface);
847 if (pFilter->dsbuffer)
849 IDirectSoundBuffer_Stop(pFilter->dsbuffer);
852 IDirectSoundBuffer_SetCurrentPosition(pFilter->dsbuffer, 0);
853 pFilter->write_pos = pFilter->last_play_pos = 0;
854 ++pFilter->play_loops;
855 pFilter->write_loops = pFilter->play_loops;
857 IDirectSoundBuffer_Lock(pFilter->dsbuffer, 0, 0, (LPVOID *)&buffer, &size, NULL, NULL, DSBLOCK_ENTIREBUFFER);
858 memset(buffer, 0, size);
859 IDirectSoundBuffer_Unlock(pFilter->dsbuffer, buffer, size, NULL, 0);
861 LeaveCriticalSection(This->pin.pCritSec);
866 static const IPinVtbl DSoundRender_InputPin_Vtbl =
868 InputPin_QueryInterface,
872 DSoundRender_InputPin_ReceiveConnection,
873 DSoundRender_InputPin_Disconnect,
874 IPinImpl_ConnectedTo,
875 IPinImpl_ConnectionMediaType,
876 IPinImpl_QueryPinInfo,
877 IPinImpl_QueryDirection,
879 IPinImpl_QueryAccept,
880 IPinImpl_EnumMediaTypes,
881 IPinImpl_QueryInternalConnections,
882 DSoundRender_InputPin_EndOfStream,
883 DSoundRender_InputPin_BeginFlush,
888 static const IMemInputPinVtbl MemInputPin_Vtbl =
890 MemInputPin_QueryInterface,
893 MemInputPin_GetAllocator,
894 MemInputPin_NotifyAllocator,
895 MemInputPin_GetAllocatorRequirements,
897 MemInputPin_ReceiveMultiple,
898 MemInputPin_ReceiveCanBlock
901 /*** IUnknown methods ***/
902 static HRESULT WINAPI Basicaudio_QueryInterface(IBasicAudio *iface,
905 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
907 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
909 return DSoundRender_QueryInterface((IBaseFilter*)This, riid, ppvObj);
912 static ULONG WINAPI Basicaudio_AddRef(IBasicAudio *iface) {
913 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
915 TRACE("(%p/%p)->()\n", This, iface);
917 return DSoundRender_AddRef((IBaseFilter*)This);
920 static ULONG WINAPI Basicaudio_Release(IBasicAudio *iface) {
921 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
923 TRACE("(%p/%p)->()\n", This, iface);
925 return DSoundRender_Release((IBaseFilter*)This);
928 /*** IDispatch methods ***/
929 static HRESULT WINAPI Basicaudio_GetTypeInfoCount(IBasicAudio *iface,
931 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
933 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
938 static HRESULT WINAPI Basicaudio_GetTypeInfo(IBasicAudio *iface,
941 ITypeInfo**ppTInfo) {
942 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
944 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
949 static HRESULT WINAPI Basicaudio_GetIDsOfNames(IBasicAudio *iface,
955 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
957 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
962 static HRESULT WINAPI Basicaudio_Invoke(IBasicAudio *iface,
967 DISPPARAMS*pDispParams,
971 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
973 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);
978 /*** IBasicAudio methods ***/
979 static HRESULT WINAPI Basicaudio_put_Volume(IBasicAudio *iface,
981 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
983 TRACE("(%p/%p)->(%ld)\n", This, iface, lVolume);
985 if (lVolume > DSBVOLUME_MAX || lVolume < DSBVOLUME_MIN)
988 if (This->dsbuffer) {
989 if (FAILED(IDirectSoundBuffer_SetVolume(This->dsbuffer, lVolume)))
993 This->volume = lVolume;
997 static HRESULT WINAPI Basicaudio_get_Volume(IBasicAudio *iface,
999 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1001 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
1006 *plVolume = This->volume;
1010 static HRESULT WINAPI Basicaudio_put_Balance(IBasicAudio *iface,
1012 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1014 TRACE("(%p/%p)->(%ld)\n", This, iface, lBalance);
1016 if (lBalance < DSBPAN_LEFT || lBalance > DSBPAN_RIGHT)
1017 return E_INVALIDARG;
1019 if (This->dsbuffer) {
1020 if (FAILED(IDirectSoundBuffer_SetPan(This->dsbuffer, lBalance)))
1024 This->pan = lBalance;
1028 static HRESULT WINAPI Basicaudio_get_Balance(IBasicAudio *iface,
1030 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1032 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
1037 *plBalance = This->pan;
1041 static const IBasicAudioVtbl IBasicAudio_Vtbl =
1043 Basicaudio_QueryInterface,
1046 Basicaudio_GetTypeInfoCount,
1047 Basicaudio_GetTypeInfo,
1048 Basicaudio_GetIDsOfNames,
1050 Basicaudio_put_Volume,
1051 Basicaudio_get_Volume,
1052 Basicaudio_put_Balance,
1053 Basicaudio_get_Balance
1057 /*** IUnknown methods ***/
1058 static HRESULT WINAPI ReferenceClock_QueryInterface(IReferenceClock *iface,
1062 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1064 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1066 return DSoundRender_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1069 static ULONG WINAPI ReferenceClock_AddRef(IReferenceClock *iface)
1071 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1073 TRACE("(%p/%p)->()\n", This, iface);
1075 return DSoundRender_AddRef((IBaseFilter*)This);
1078 static ULONG WINAPI ReferenceClock_Release(IReferenceClock *iface)
1080 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1082 TRACE("(%p/%p)->()\n", This, iface);
1084 return DSoundRender_Release((IBaseFilter*)This);
1087 /*** IReferenceClock methods ***/
1088 static HRESULT WINAPI ReferenceClock_GetTime(IReferenceClock *iface,
1089 REFERENCE_TIME *pTime)
1091 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1092 HRESULT hr = E_FAIL;
1095 TRACE("(%p/%p)->(%p)\n", This, iface, pTime);
1098 hr = DSoundRender_GetPos(This, &play_pos, pTime);
1100 ERR("Could not get reference time (%x)!\n", hr);
1105 static HRESULT WINAPI ReferenceClock_AdviseTime(IReferenceClock *iface,
1106 REFERENCE_TIME rtBaseTime,
1107 REFERENCE_TIME rtStreamTime,
1109 DWORD_PTR *pdwAdviseCookie)
1111 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1113 FIXME("(%p/%p)->(%s, %s, %p, %p): stub!\n", This, iface, wine_dbgstr_longlong(rtBaseTime), wine_dbgstr_longlong(rtStreamTime), (void*)hEvent, pdwAdviseCookie);
1118 static HRESULT WINAPI ReferenceClock_AdvisePeriodic(IReferenceClock *iface,
1119 REFERENCE_TIME rtBaseTime,
1120 REFERENCE_TIME rtStreamTime,
1121 HSEMAPHORE hSemaphore,
1122 DWORD_PTR *pdwAdviseCookie)
1124 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1126 FIXME("(%p/%p)->(%s, %s, %p, %p): stub!\n", This, iface, wine_dbgstr_longlong(rtBaseTime), wine_dbgstr_longlong(rtStreamTime), (void*)hSemaphore, pdwAdviseCookie);
1131 static HRESULT WINAPI ReferenceClock_Unadvise(IReferenceClock *iface,
1132 DWORD_PTR dwAdviseCookie)
1134 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1136 FIXME("(%p/%p)->(%p): stub!\n", This, iface, (void*)dwAdviseCookie);
1141 static const IReferenceClockVtbl IReferenceClock_Vtbl =
1143 ReferenceClock_QueryInterface,
1144 ReferenceClock_AddRef,
1145 ReferenceClock_Release,
1146 ReferenceClock_GetTime,
1147 ReferenceClock_AdviseTime,
1148 ReferenceClock_AdvisePeriodic,
1149 ReferenceClock_Unadvise
1152 static inline DSoundRenderImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
1154 return (DSoundRenderImpl *)((char*)iface - FIELD_OFFSET(DSoundRenderImpl, mediaSeeking.lpVtbl));
1157 static HRESULT WINAPI sound_seek_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
1159 DSoundRenderImpl *This = impl_from_IMediaSeeking(iface);
1161 return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
1164 static ULONG WINAPI sound_seek_AddRef(IMediaSeeking * iface)
1166 DSoundRenderImpl *This = impl_from_IMediaSeeking(iface);
1168 return IUnknown_AddRef((IUnknown *)This);
1171 static ULONG WINAPI sound_seek_Release(IMediaSeeking * iface)
1173 DSoundRenderImpl *This = impl_from_IMediaSeeking(iface);
1175 return IUnknown_Release((IUnknown *)This);
1178 static const IMediaSeekingVtbl IMediaSeeking_Vtbl =
1180 sound_seek_QueryInterface,
1183 MediaSeekingImpl_GetCapabilities,
1184 MediaSeekingImpl_CheckCapabilities,
1185 MediaSeekingImpl_IsFormatSupported,
1186 MediaSeekingImpl_QueryPreferredFormat,
1187 MediaSeekingImpl_GetTimeFormat,
1188 MediaSeekingImpl_IsUsingTimeFormat,
1189 MediaSeekingImpl_SetTimeFormat,
1190 MediaSeekingImpl_GetDuration,
1191 MediaSeekingImpl_GetStopPosition,
1192 MediaSeekingImpl_GetCurrentPosition,
1193 MediaSeekingImpl_ConvertTimeFormat,
1194 MediaSeekingImpl_SetPositions,
1195 MediaSeekingImpl_GetPositions,
1196 MediaSeekingImpl_GetAvailable,
1197 MediaSeekingImpl_SetRate,
1198 MediaSeekingImpl_GetRate,
1199 MediaSeekingImpl_GetPreroll