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;
67 LPDIRECTSOUNDBUFFER dsbuffer;
75 REFERENCE_TIME play_time;
76 MediaSeekingImpl mediaSeeking;
82 /* Seeking is not needed for a renderer, rely on newsegment for the appropiate changes */
83 static HRESULT sound_mod_stop(IBaseFilter *iface)
85 TRACE("(%p)\n", iface);
89 static HRESULT sound_mod_start(IBaseFilter *iface)
91 TRACE("(%p)\n", iface);
96 static HRESULT sound_mod_rate(IBaseFilter *iface)
98 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
100 WAVEFORMATEX *format = (WAVEFORMATEX*)This->pInputPin->pin.mtCurrent.pbFormat;
101 DWORD freq = format->nSamplesPerSec;
102 double rate = This->mediaSeeking.dRate;
104 freq = (DWORD)((double)freq * rate);
106 TRACE("(%p)\n", iface);
108 if (freq > DSBFREQUENCY_MAX)
109 return VFW_E_UNSUPPORTED_AUDIO;
111 if (freq < DSBFREQUENCY_MIN)
112 return VFW_E_UNSUPPORTED_AUDIO;
117 static inline HRESULT DSoundRender_GetPos(DSoundRenderImpl *This, DWORD *pPlayPos, REFERENCE_TIME *pRefTime)
121 EnterCriticalSection(&This->csFilter);
126 hr = IDirectSoundBuffer_GetStatus(This->dsbuffer, &state);
127 if (SUCCEEDED(hr) && !(state & DSBSTATUS_PLAYING) && This->state == State_Running)
129 TRACE("Not playing, kickstarting the engine\n");
131 hr = IDirectSoundBuffer_Play(This->dsbuffer, 0, 0, DSBPLAY_LOOPING);
133 ERR("Can't play sound buffer (%x)\n", hr);
137 hr = IDirectSoundBuffer_GetCurrentPosition(This->dsbuffer, pPlayPos, &write_pos);
140 DWORD play_pos = *pPlayPos;
142 if (play_pos < This->last_play_pos)
144 This->last_play_pos = play_pos;
146 /* If we really fell behind, start at the next possible position
147 * Also happens when just starting playback for the first time,
150 if ((This->play_loops*This->buf_size)+play_pos >=
151 (This->write_loops*This->buf_size)+This->write_pos)
152 This->write_pos = write_pos;
156 REFERENCE_TIME play_time;
157 play_time = ((REFERENCE_TIME)This->play_loops*10000000) +
158 ((REFERENCE_TIME)play_pos*10000000/This->buf_size);
160 /* Don't let time run backwards */
161 if(play_time-This->play_time > 0)
162 This->play_time = play_time;
166 *pRefTime = This->play_time;
170 LeaveCriticalSection(&This->csFilter);
175 static HRESULT DSoundRender_SendSampleData(DSoundRenderImpl* This, const BYTE *data, DWORD size)
178 LPBYTE lpbuf1 = NULL;
179 LPBYTE lpbuf2 = NULL;
183 DWORD play_pos,buf_free;
187 hr = DSoundRender_GetPos(This, &play_pos, NULL);
190 ERR("GetPos returned error: %x\n", hr);
193 if (This->write_pos <= play_pos)
194 buf_free = play_pos-This->write_pos;
196 buf_free = This->buf_size - This->write_pos + play_pos;
198 /* Wait for enough of the buffer to empty before filling it */
199 if(buf_free < This->buf_size/4)
205 size2 = min(buf_free, size);
206 hr = IDirectSoundBuffer_Lock(This->dsbuffer, This->write_pos, size2, (LPVOID *)&lpbuf1, &dwsize1, (LPVOID *)&lpbuf2, &dwsize2, 0);
208 ERR("Unable to lock sound buffer! (%x)\n", hr);
211 /* TRACE("write_pos=%d, size=%d, sz1=%d, sz2=%d\n", This->write_pos, size2, dwsize1, dwsize2); */
213 memcpy(lpbuf1, data, dwsize1);
215 memcpy(lpbuf2, data + dwsize1, dwsize2);
217 hr = IDirectSoundBuffer_Unlock(This->dsbuffer, lpbuf1, dwsize1, lpbuf2, dwsize2);
219 ERR("Unable to unlock sound buffer! (%x)\n", hr);
221 size -= dwsize1 + dwsize2;
222 data += dwsize1 + dwsize2;
223 This->write_pos += dwsize1 + dwsize2;
224 if (This->write_pos >= This->buf_size)
226 This->write_pos -= This->buf_size;
229 } while (size && This->state == State_Running);
234 static HRESULT DSoundRender_Sample(LPVOID iface, IMediaSample * pSample)
236 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
237 LPBYTE pbSrcStream = NULL;
238 long cbSrcStream = 0;
239 REFERENCE_TIME tStart, tStop;
242 TRACE("%p %p\n", iface, pSample);
244 /* Slightly incorrect, Pause completes when a frame is received so we should signal
245 * pause completion here, but for sound playing a single frame doesn't make sense
248 if (This->state == State_Paused)
251 if (This->state == State_Stopped)
254 hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
257 ERR("Cannot get pointer to sample data (%x)\n", hr);
261 hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
263 ERR("Cannot get sample time (%x)\n", hr);
265 if (This->rtLastStop != tStart && (IMediaSample_IsDiscontinuity(pSample) == S_FALSE))
266 FIXME("Unexpected discontinuity: Last: %u.%03u, tStart: %u.%03u\n",
267 (DWORD)(This->rtLastStop / 10000000), (DWORD)((This->rtLastStop / 10000)%1000),
268 (DWORD)(tStart / 10000000), (DWORD)((tStart / 10000)%1000));
269 This->rtLastStop = tStop;
271 if (IMediaSample_IsPreroll(pSample) == S_OK)
277 cbSrcStream = IMediaSample_GetActualDataLength(pSample);
278 TRACE("Sample data ptr = %p, size = %ld\n", pbSrcStream, cbSrcStream);
280 #if 0 /* For debugging purpose */
283 for(i = 0; i < cbSrcStream; i++)
285 if ((i!=0) && !(i%16))
287 TRACE("%02x ", pbSrcStream[i]);
293 return DSoundRender_SendSampleData(This, pbSrcStream, cbSrcStream);
296 static HRESULT DSoundRender_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
298 WAVEFORMATEX* format = (WAVEFORMATEX*)pmt->pbFormat;
299 TRACE("wFormatTag = %x %x\n", format->wFormatTag, WAVE_FORMAT_PCM);
300 TRACE("nChannels = %d\n", format->nChannels);
301 TRACE("nSamplesPerSec = %d\n", format->nAvgBytesPerSec);
302 TRACE("nAvgBytesPerSec = %d\n", format->nAvgBytesPerSec);
303 TRACE("nBlockAlign = %d\n", format->nBlockAlign);
304 TRACE("wBitsPerSample = %d\n", format->wBitsPerSample);
306 if (IsEqualIID(&pmt->majortype, &MEDIATYPE_Audio) && IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_PCM))
311 HRESULT DSoundRender_create(IUnknown * pUnkOuter, LPVOID * ppv)
315 DSoundRenderImpl * pDSoundRender;
317 TRACE("(%p, %p)\n", pUnkOuter, ppv);
322 return CLASS_E_NOAGGREGATION;
324 pDSoundRender = CoTaskMemAlloc(sizeof(DSoundRenderImpl));
326 return E_OUTOFMEMORY;
327 ZeroMemory(pDSoundRender, sizeof(DSoundRenderImpl));
329 pDSoundRender->lpVtbl = &DSoundRender_Vtbl;
330 pDSoundRender->IBasicAudio_vtbl = &IBasicAudio_Vtbl;
331 pDSoundRender->IReferenceClock_vtbl = &IReferenceClock_Vtbl;
332 pDSoundRender->refCount = 1;
333 InitializeCriticalSection(&pDSoundRender->csFilter);
334 pDSoundRender->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": DSoundRenderImpl.csFilter");
335 pDSoundRender->state = State_Stopped;
337 pDSoundRender->ppPins = CoTaskMemAlloc(1 * sizeof(IPin *));
338 if (!pDSoundRender->ppPins)
340 pDSoundRender->csFilter.DebugInfo->Spare[0] = 0;
341 DeleteCriticalSection(&pDSoundRender->csFilter);
342 CoTaskMemFree(pDSoundRender);
343 return E_OUTOFMEMORY;
346 /* construct input pin */
347 piInput.dir = PINDIR_INPUT;
348 piInput.pFilter = (IBaseFilter *)pDSoundRender;
349 lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
350 hr = InputPin_Construct(&DSoundRender_InputPin_Vtbl, &piInput, DSoundRender_Sample, pDSoundRender, DSoundRender_QueryAccept, NULL, &pDSoundRender->csFilter, (IPin **)&pDSoundRender->pInputPin);
354 hr = DirectSoundCreate(NULL, &pDSoundRender->dsound, NULL);
356 ERR("Cannot create Direct Sound object (%x)\n", hr);
361 MediaSeekingImpl_Init((IBaseFilter*)pDSoundRender, sound_mod_stop, sound_mod_start, sound_mod_rate, &pDSoundRender->mediaSeeking, &pDSoundRender->csFilter);
362 pDSoundRender->mediaSeeking.lpVtbl = &IMediaSeeking_Vtbl;
364 pDSoundRender->ppPins[0] = (IPin *)pDSoundRender->pInputPin;
365 *ppv = (LPVOID)pDSoundRender;
369 if (pDSoundRender->pInputPin)
370 IPin_Release((IPin*)pDSoundRender->pInputPin);
371 CoTaskMemFree(pDSoundRender->ppPins);
372 pDSoundRender->csFilter.DebugInfo->Spare[0] = 0;
373 DeleteCriticalSection(&pDSoundRender->csFilter);
374 CoTaskMemFree(pDSoundRender);
380 static HRESULT WINAPI DSoundRender_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
382 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
383 TRACE("(%p, %p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
387 if (IsEqualIID(riid, &IID_IUnknown))
389 else if (IsEqualIID(riid, &IID_IPersist))
391 else if (IsEqualIID(riid, &IID_IMediaFilter))
393 else if (IsEqualIID(riid, &IID_IBaseFilter))
395 else if (IsEqualIID(riid, &IID_IBasicAudio))
396 *ppv = (LPVOID)&(This->IBasicAudio_vtbl);
397 else if (IsEqualIID(riid, &IID_IReferenceClock))
398 *ppv = (LPVOID)&(This->IReferenceClock_vtbl);
399 else if (IsEqualIID(riid, &IID_IMediaSeeking))
400 *ppv = &This->mediaSeeking.lpVtbl;
404 IUnknown_AddRef((IUnknown *)(*ppv));
408 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IVideoWindow))
409 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
411 return E_NOINTERFACE;
414 static ULONG WINAPI DSoundRender_AddRef(IBaseFilter * iface)
416 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
417 ULONG refCount = InterlockedIncrement(&This->refCount);
419 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
424 static ULONG WINAPI DSoundRender_Release(IBaseFilter * iface)
426 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
427 ULONG refCount = InterlockedDecrement(&This->refCount);
429 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
436 IReferenceClock_Release(This->pClock);
439 IDirectSoundBuffer_Release(This->dsbuffer);
440 This->dsbuffer = NULL;
442 IDirectSound_Release(This->dsound);
445 if (SUCCEEDED(IPin_ConnectedTo(This->ppPins[0], &pConnectedTo)))
447 IPin_Disconnect(pConnectedTo);
448 IPin_Release(pConnectedTo);
450 IPin_Disconnect(This->ppPins[0]);
452 IPin_Release(This->ppPins[0]);
454 CoTaskMemFree(This->ppPins);
456 This->IBasicAudio_vtbl = NULL;
458 This->csFilter.DebugInfo->Spare[0] = 0;
459 DeleteCriticalSection(&This->csFilter);
461 TRACE("Destroying Audio Renderer\n");
470 /** IPersist methods **/
472 static HRESULT WINAPI DSoundRender_GetClassID(IBaseFilter * iface, CLSID * pClsid)
474 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
475 TRACE("(%p/%p)->(%p)\n", This, iface, pClsid);
477 *pClsid = CLSID_DSoundRender;
482 /** IMediaFilter methods **/
484 static HRESULT WINAPI DSoundRender_Stop(IBaseFilter * iface)
487 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
489 TRACE("(%p/%p)->()\n", This, iface);
491 EnterCriticalSection(&This->csFilter);
496 hr = IDirectSoundBuffer_GetStatus(This->dsbuffer, &state);
499 if (state & DSBSTATUS_PLAYING)
500 hr = IDirectSoundBuffer_Stop(This->dsbuffer);
504 This->state = State_Stopped;
506 LeaveCriticalSection(&This->csFilter);
511 static HRESULT WINAPI DSoundRender_Pause(IBaseFilter * iface)
514 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
516 TRACE("(%p/%p)->()\n", This, iface);
518 EnterCriticalSection(&This->csFilter);
521 if (This->state == State_Stopped)
522 This->pInputPin->end_of_stream = 0;
526 hr = IDirectSoundBuffer_GetStatus(This->dsbuffer, &state);
529 if (state & DSBSTATUS_PLAYING)
530 hr = IDirectSoundBuffer_Stop(This->dsbuffer);
534 This->state = State_Paused;
536 LeaveCriticalSection(&This->csFilter);
541 static HRESULT WINAPI DSoundRender_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
544 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
546 TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
548 EnterCriticalSection(&This->csFilter);
550 This->rtStreamStart = tStart;
551 This->state = State_Running;
552 This->pInputPin->end_of_stream = 0;
554 LeaveCriticalSection(&This->csFilter);
559 static HRESULT WINAPI DSoundRender_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
561 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
563 TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
565 EnterCriticalSection(&This->csFilter);
567 *pState = This->state;
569 LeaveCriticalSection(&This->csFilter);
574 static HRESULT WINAPI DSoundRender_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
576 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
578 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
580 EnterCriticalSection(&This->csFilter);
583 IReferenceClock_Release(This->pClock);
584 This->pClock = pClock;
586 IReferenceClock_AddRef(This->pClock);
588 LeaveCriticalSection(&This->csFilter);
593 static HRESULT WINAPI DSoundRender_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
595 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
597 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
599 EnterCriticalSection(&This->csFilter);
601 *ppClock = This->pClock;
603 IReferenceClock_AddRef(This->pClock);
605 LeaveCriticalSection(&This->csFilter);
610 /** IBaseFilter implementation **/
612 static HRESULT WINAPI DSoundRender_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
615 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
617 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
619 epd.cPins = 1; /* input pin */
620 epd.ppPins = This->ppPins;
621 return IEnumPinsImpl_Construct(&epd, ppEnum);
624 static HRESULT WINAPI DSoundRender_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
626 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
628 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_w(Id), ppPin);
630 FIXME("DSoundRender::FindPin(...)\n");
632 /* FIXME: critical section */
637 static HRESULT WINAPI DSoundRender_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
639 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
641 TRACE("(%p/%p)->(%p)\n", This, iface, pInfo);
643 strcpyW(pInfo->achName, This->filterInfo.achName);
644 pInfo->pGraph = This->filterInfo.pGraph;
647 IFilterGraph_AddRef(pInfo->pGraph);
652 static HRESULT WINAPI DSoundRender_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
654 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
656 TRACE("(%p/%p)->(%p, %s)\n", This, iface, pGraph, debugstr_w(pName));
658 EnterCriticalSection(&This->csFilter);
661 strcpyW(This->filterInfo.achName, pName);
663 *This->filterInfo.achName = '\0';
664 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
666 LeaveCriticalSection(&This->csFilter);
671 static HRESULT WINAPI DSoundRender_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
673 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
674 TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
678 static const IBaseFilterVtbl DSoundRender_Vtbl =
680 DSoundRender_QueryInterface,
682 DSoundRender_Release,
683 DSoundRender_GetClassID,
687 DSoundRender_GetState,
688 DSoundRender_SetSyncSource,
689 DSoundRender_GetSyncSource,
690 DSoundRender_EnumPins,
691 DSoundRender_FindPin,
692 DSoundRender_QueryFilterInfo,
693 DSoundRender_JoinFilterGraph,
694 DSoundRender_QueryVendorInfo
697 static HRESULT WINAPI DSoundRender_InputPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
699 InputPin *This = (InputPin *)iface;
700 PIN_DIRECTION pindirReceive;
701 DSoundRenderImpl *DSImpl;
704 TRACE("(%p)->(%p, %p)\n", This, pReceivePin, pmt);
705 dump_AM_MEDIA_TYPE(pmt);
707 EnterCriticalSection(This->pin.pCritSec);
709 DSImpl = (DSoundRenderImpl*)This->pin.pinInfo.pFilter;
710 DSImpl->rtLastStop = -1;
712 if (This->pin.pConnectedTo)
713 hr = VFW_E_ALREADY_CONNECTED;
715 if (SUCCEEDED(hr) && This->pin.fnQueryAccept(This->pin.pUserData, pmt) != S_OK)
716 hr = VFW_E_TYPE_NOT_ACCEPTED;
720 IPin_QueryDirection(pReceivePin, &pindirReceive);
722 if (pindirReceive != PINDIR_OUTPUT)
724 ERR("Can't connect from non-output pin\n");
725 hr = VFW_E_INVALID_DIRECTION;
731 WAVEFORMATEX *format;
732 DSBUFFERDESC buf_desc;
734 TRACE("MajorType %s\n", debugstr_guid(&pmt->majortype));
735 TRACE("SubType %s\n", debugstr_guid(&pmt->subtype));
736 TRACE("Format %s\n", debugstr_guid(&pmt->formattype));
737 TRACE("Size %d\n", pmt->cbFormat);
739 format = (WAVEFORMATEX*)pmt->pbFormat;
741 DSImpl->buf_size = format->nAvgBytesPerSec;
743 memset(&buf_desc,0,sizeof(DSBUFFERDESC));
744 buf_desc.dwSize = sizeof(DSBUFFERDESC);
745 buf_desc.dwFlags = DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN |
746 DSBCAPS_CTRLFREQUENCY |
747 DSBCAPS_GETCURRENTPOSITION2;
748 buf_desc.dwBufferBytes = DSImpl->buf_size;
749 buf_desc.lpwfxFormat = format;
750 hr = IDirectSound_CreateSoundBuffer(DSImpl->dsound, &buf_desc, &DSImpl->dsbuffer, NULL);
752 ERR("Can't create sound buffer (%x)\n", hr);
757 hr = IDirectSoundBuffer_SetVolume(DSImpl->dsbuffer, DSImpl->volume);
759 ERR("Can't set volume to %ld (%x)\n", DSImpl->volume, hr);
761 hr = IDirectSoundBuffer_SetPan(DSImpl->dsbuffer, DSImpl->pan);
763 ERR("Can't set pan to %ld (%x)\n", DSImpl->pan, hr);
765 DSImpl->write_pos = 0;
771 CopyMediaType(&This->pin.mtCurrent, pmt);
772 This->pin.pConnectedTo = pReceivePin;
773 IPin_AddRef(pReceivePin);
777 if (DSImpl->dsbuffer)
778 IDirectSoundBuffer_Release(DSImpl->dsbuffer);
779 DSImpl->dsbuffer = NULL;
782 LeaveCriticalSection(This->pin.pCritSec);
787 static HRESULT WINAPI DSoundRender_InputPin_Disconnect(IPin * iface)
789 IPinImpl *This = (IPinImpl*)iface;
790 DSoundRenderImpl *DSImpl;
792 TRACE("(%p)->()\n", iface);
794 DSImpl = (DSoundRenderImpl*)This->pinInfo.pFilter;
795 if (DSImpl->dsbuffer)
796 IDirectSoundBuffer_Release(DSImpl->dsbuffer);
797 DSImpl->dsbuffer = NULL;
799 return IPinImpl_Disconnect(iface);
802 static HRESULT WINAPI DSoundRender_InputPin_EndOfStream(IPin * iface)
804 InputPin* This = (InputPin*)iface;
805 DSoundRenderImpl *me = (DSoundRenderImpl*)This->pin.pinInfo.pFilter;
806 IMediaEventSink* pEventSink;
809 EnterCriticalSection(This->pin.pCritSec);
811 TRACE("(%p/%p)->()\n", This, iface);
812 InputPin_EndOfStream(iface);
814 hr = IFilterGraph_QueryInterface(me->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
819 silence = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, me->buf_size);
822 memset(silence, 0, me->buf_size);
823 DSoundRender_SendSampleData((DSoundRenderImpl*)This->pin.pinInfo.pFilter, silence, me->buf_size);
824 HeapFree(GetProcessHeap(), 0, silence);
827 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
828 IMediaEventSink_Release(pEventSink);
830 LeaveCriticalSection(This->pin.pCritSec);
835 static HRESULT WINAPI DSoundRender_InputPin_BeginFlush(IPin * iface)
837 InputPin *This = (InputPin *)iface;
838 DSoundRenderImpl *pFilter = (DSoundRenderImpl *)This->pin.pinInfo.pFilter;
845 EnterCriticalSection(This->pin.pCritSec);
846 hr = InputPin_BeginFlush(iface);
848 if (pFilter->dsbuffer)
850 IDirectSoundBuffer_Stop(pFilter->dsbuffer);
853 IDirectSoundBuffer_SetCurrentPosition(pFilter->dsbuffer, 0);
854 pFilter->write_pos = pFilter->last_play_pos = 0;
855 ++pFilter->play_loops;
856 pFilter->write_loops = pFilter->play_loops;
858 IDirectSoundBuffer_Lock(pFilter->dsbuffer, 0, 0, (LPVOID *)&buffer, &size, NULL, NULL, DSBLOCK_ENTIREBUFFER);
859 memset(buffer, 0, size);
860 IDirectSoundBuffer_Unlock(pFilter->dsbuffer, buffer, size, NULL, 0);
862 LeaveCriticalSection(This->pin.pCritSec);
867 static const IPinVtbl DSoundRender_InputPin_Vtbl =
869 InputPin_QueryInterface,
873 DSoundRender_InputPin_ReceiveConnection,
874 DSoundRender_InputPin_Disconnect,
875 IPinImpl_ConnectedTo,
876 IPinImpl_ConnectionMediaType,
877 IPinImpl_QueryPinInfo,
878 IPinImpl_QueryDirection,
880 IPinImpl_QueryAccept,
881 IPinImpl_EnumMediaTypes,
882 IPinImpl_QueryInternalConnections,
883 DSoundRender_InputPin_EndOfStream,
884 DSoundRender_InputPin_BeginFlush,
889 static const IMemInputPinVtbl MemInputPin_Vtbl =
891 MemInputPin_QueryInterface,
894 MemInputPin_GetAllocator,
895 MemInputPin_NotifyAllocator,
896 MemInputPin_GetAllocatorRequirements,
898 MemInputPin_ReceiveMultiple,
899 MemInputPin_ReceiveCanBlock
902 /*** IUnknown methods ***/
903 static HRESULT WINAPI Basicaudio_QueryInterface(IBasicAudio *iface,
906 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
908 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
910 return DSoundRender_QueryInterface((IBaseFilter*)This, riid, ppvObj);
913 static ULONG WINAPI Basicaudio_AddRef(IBasicAudio *iface) {
914 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
916 TRACE("(%p/%p)->()\n", This, iface);
918 return DSoundRender_AddRef((IBaseFilter*)This);
921 static ULONG WINAPI Basicaudio_Release(IBasicAudio *iface) {
922 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
924 TRACE("(%p/%p)->()\n", This, iface);
926 return DSoundRender_Release((IBaseFilter*)This);
929 /*** IDispatch methods ***/
930 static HRESULT WINAPI Basicaudio_GetTypeInfoCount(IBasicAudio *iface,
932 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
934 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
939 static HRESULT WINAPI Basicaudio_GetTypeInfo(IBasicAudio *iface,
942 ITypeInfo**ppTInfo) {
943 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
945 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
950 static HRESULT WINAPI Basicaudio_GetIDsOfNames(IBasicAudio *iface,
956 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
958 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
963 static HRESULT WINAPI Basicaudio_Invoke(IBasicAudio *iface,
968 DISPPARAMS*pDispParams,
972 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
974 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);
979 /*** IBasicAudio methods ***/
980 static HRESULT WINAPI Basicaudio_put_Volume(IBasicAudio *iface,
982 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
984 TRACE("(%p/%p)->(%ld)\n", This, iface, lVolume);
986 if (lVolume > DSBVOLUME_MAX || lVolume < DSBVOLUME_MIN)
989 if (This->dsbuffer) {
990 if (FAILED(IDirectSoundBuffer_SetVolume(This->dsbuffer, lVolume)))
994 This->volume = lVolume;
998 static HRESULT WINAPI Basicaudio_get_Volume(IBasicAudio *iface,
1000 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1002 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
1007 *plVolume = This->volume;
1011 static HRESULT WINAPI Basicaudio_put_Balance(IBasicAudio *iface,
1013 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1015 TRACE("(%p/%p)->(%ld)\n", This, iface, lBalance);
1017 if (lBalance < DSBPAN_LEFT || lBalance > DSBPAN_RIGHT)
1018 return E_INVALIDARG;
1020 if (This->dsbuffer) {
1021 if (FAILED(IDirectSoundBuffer_SetPan(This->dsbuffer, lBalance)))
1025 This->pan = lBalance;
1029 static HRESULT WINAPI Basicaudio_get_Balance(IBasicAudio *iface,
1031 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1033 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
1038 *plBalance = This->pan;
1042 static const IBasicAudioVtbl IBasicAudio_Vtbl =
1044 Basicaudio_QueryInterface,
1047 Basicaudio_GetTypeInfoCount,
1048 Basicaudio_GetTypeInfo,
1049 Basicaudio_GetIDsOfNames,
1051 Basicaudio_put_Volume,
1052 Basicaudio_get_Volume,
1053 Basicaudio_put_Balance,
1054 Basicaudio_get_Balance
1058 /*** IUnknown methods ***/
1059 static HRESULT WINAPI ReferenceClock_QueryInterface(IReferenceClock *iface,
1063 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1065 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1067 return DSoundRender_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1070 static ULONG WINAPI ReferenceClock_AddRef(IReferenceClock *iface)
1072 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1074 TRACE("(%p/%p)->()\n", This, iface);
1076 return DSoundRender_AddRef((IBaseFilter*)This);
1079 static ULONG WINAPI ReferenceClock_Release(IReferenceClock *iface)
1081 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1083 TRACE("(%p/%p)->()\n", This, iface);
1085 return DSoundRender_Release((IBaseFilter*)This);
1088 /*** IReferenceClock methods ***/
1089 static HRESULT WINAPI ReferenceClock_GetTime(IReferenceClock *iface,
1090 REFERENCE_TIME *pTime)
1092 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1093 HRESULT hr = E_FAIL;
1096 TRACE("(%p/%p)->(%p)\n", This, iface, pTime);
1099 hr = DSoundRender_GetPos(This, &play_pos, pTime);
1101 ERR("Could not get reference time (%x)!\n", hr);
1106 static HRESULT WINAPI ReferenceClock_AdviseTime(IReferenceClock *iface,
1107 REFERENCE_TIME rtBaseTime,
1108 REFERENCE_TIME rtStreamTime,
1110 DWORD_PTR *pdwAdviseCookie)
1112 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1114 FIXME("(%p/%p)->(%s, %s, %p, %p): stub!\n", This, iface, wine_dbgstr_longlong(rtBaseTime), wine_dbgstr_longlong(rtStreamTime), (void*)hEvent, pdwAdviseCookie);
1119 static HRESULT WINAPI ReferenceClock_AdvisePeriodic(IReferenceClock *iface,
1120 REFERENCE_TIME rtBaseTime,
1121 REFERENCE_TIME rtStreamTime,
1122 HSEMAPHORE hSemaphore,
1123 DWORD_PTR *pdwAdviseCookie)
1125 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1127 FIXME("(%p/%p)->(%s, %s, %p, %p): stub!\n", This, iface, wine_dbgstr_longlong(rtBaseTime), wine_dbgstr_longlong(rtStreamTime), (void*)hSemaphore, pdwAdviseCookie);
1132 static HRESULT WINAPI ReferenceClock_Unadvise(IReferenceClock *iface,
1133 DWORD_PTR dwAdviseCookie)
1135 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1137 FIXME("(%p/%p)->(%p): stub!\n", This, iface, (void*)dwAdviseCookie);
1142 static const IReferenceClockVtbl IReferenceClock_Vtbl =
1144 ReferenceClock_QueryInterface,
1145 ReferenceClock_AddRef,
1146 ReferenceClock_Release,
1147 ReferenceClock_GetTime,
1148 ReferenceClock_AdviseTime,
1149 ReferenceClock_AdvisePeriodic,
1150 ReferenceClock_Unadvise
1153 static inline DSoundRenderImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
1155 return (DSoundRenderImpl *)((char*)iface - FIELD_OFFSET(DSoundRenderImpl, mediaSeeking.lpVtbl));
1158 static HRESULT WINAPI sound_seek_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
1160 DSoundRenderImpl *This = impl_from_IMediaSeeking(iface);
1162 return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
1165 static ULONG WINAPI sound_seek_AddRef(IMediaSeeking * iface)
1167 DSoundRenderImpl *This = impl_from_IMediaSeeking(iface);
1169 return IUnknown_AddRef((IUnknown *)This);
1172 static ULONG WINAPI sound_seek_Release(IMediaSeeking * iface)
1174 DSoundRenderImpl *This = impl_from_IMediaSeeking(iface);
1176 return IUnknown_Release((IUnknown *)This);
1179 static const IMediaSeekingVtbl IMediaSeeking_Vtbl =
1181 sound_seek_QueryInterface,
1184 MediaSeekingImpl_GetCapabilities,
1185 MediaSeekingImpl_CheckCapabilities,
1186 MediaSeekingImpl_IsFormatSupported,
1187 MediaSeekingImpl_QueryPreferredFormat,
1188 MediaSeekingImpl_GetTimeFormat,
1189 MediaSeekingImpl_IsUsingTimeFormat,
1190 MediaSeekingImpl_SetTimeFormat,
1191 MediaSeekingImpl_GetDuration,
1192 MediaSeekingImpl_GetStopPosition,
1193 MediaSeekingImpl_GetCurrentPosition,
1194 MediaSeekingImpl_ConvertTimeFormat,
1195 MediaSeekingImpl_SetPositions,
1196 MediaSeekingImpl_GetPositions,
1197 MediaSeekingImpl_GetAvailable,
1198 MediaSeekingImpl_SetRate,
1199 MediaSeekingImpl_GetRate,
1200 MediaSeekingImpl_GetPreroll