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"
37 #include "wine/unicode.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
42 /* NOTE: buffer can still be filled completely,
43 * but we start waiting until only this amount is buffered
45 static const REFERENCE_TIME DSoundRenderer_Max_Fill = 150 * 10000;
47 static const WCHAR wcsInputPinName[] = {'i','n','p','u','t',' ','p','i','n',0};
49 static const IBaseFilterVtbl DSoundRender_Vtbl;
50 static const IPinVtbl DSoundRender_InputPin_Vtbl;
51 static const IBasicAudioVtbl IBasicAudio_Vtbl;
52 static const IReferenceClockVtbl IReferenceClock_Vtbl;
53 static const IMediaSeekingVtbl IMediaSeeking_Vtbl;
54 static const IAMDirectSoundVtbl IAMDirectSound_Vtbl;
55 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl;
56 static const IQualityControlVtbl DSoundRender_QualityControl_Vtbl = {
57 QualityControlImpl_QueryInterface,
58 QualityControlImpl_AddRef,
59 QualityControlImpl_Release,
60 QualityControlImpl_Notify,
61 QualityControlImpl_SetSink
64 typedef struct DSoundRenderImpl
68 const IBasicAudioVtbl *IBasicAudio_vtbl;
69 const IReferenceClockVtbl *IReferenceClock_vtbl;
70 const IAMDirectSoundVtbl *IAMDirectSound_vtbl;
71 const IAMFilterMiscFlagsVtbl *IAMFilterMiscFlags_vtbl;
72 IUnknown *seekthru_unk;
74 BaseInputPin * pInputPin;
75 QualityControlImpl qcimpl;
77 IDirectSound8 *dsound;
78 LPDIRECTSOUNDBUFFER dsbuffer;
81 DWORD last_playpos, writepos;
83 REFERENCE_TIME play_time;
85 HANDLE state_change, blocked;
91 HANDLE advisethread, thread_wait;
94 static REFERENCE_TIME time_from_pos(DSoundRenderImpl *This, DWORD pos) {
95 WAVEFORMATEX *wfx = (WAVEFORMATEX*)This->pInputPin->pin.mtCurrent.pbFormat;
96 REFERENCE_TIME ret = 10000000;
97 ret = ret * pos / wfx->nAvgBytesPerSec;
101 static DWORD pos_from_time(DSoundRenderImpl *This, REFERENCE_TIME time) {
102 WAVEFORMATEX *wfx = (WAVEFORMATEX*)This->pInputPin->pin.mtCurrent.pbFormat;
103 REFERENCE_TIME ret = time;
104 ret *= wfx->nSamplesPerSec;
106 ret *= wfx->nBlockAlign;
110 static void DSoundRender_UpdatePositions(DSoundRenderImpl *This, DWORD *seqwritepos, DWORD *minwritepos) {
111 WAVEFORMATEX *wfx = (WAVEFORMATEX*)This->pInputPin->pin.mtCurrent.pbFormat;
113 DWORD size1, size2, playpos, writepos, old_writepos, old_playpos, adv;
114 BOOL writepos_set = This->writepos < This->buf_size;
116 /* Update position and zero */
117 old_writepos = This->writepos;
118 old_playpos = This->last_playpos;
119 if (old_writepos <= old_playpos)
120 old_writepos += This->buf_size;
122 IDirectSoundBuffer_GetCurrentPosition(This->dsbuffer, &playpos, &writepos);
123 if (old_playpos > playpos) {
124 adv = This->buf_size + playpos - old_playpos;
125 This->play_time += time_from_pos(This, This->buf_size);
127 adv = playpos - old_playpos;
128 This->last_playpos = playpos;
130 TRACE("Moving from %u to %u: clearing %u bytes\n", old_playpos, playpos, adv);
131 IDirectSoundBuffer_Lock(This->dsbuffer, old_playpos, adv, (void**)&buf1, &size1, (void**)&buf2, &size2, 0);
132 memset(buf1, wfx->wBitsPerSample == 8 ? 128 : 0, size1);
133 memset(buf2, wfx->wBitsPerSample == 8 ? 128 : 0, size2);
134 IDirectSoundBuffer_Unlock(This->dsbuffer, buf1, size1, buf2, size2);
136 *minwritepos = writepos;
137 if (!writepos_set || old_writepos < writepos) {
139 This->writepos = This->buf_size;
140 FIXME("Underrun of data occured!\n");
142 *seqwritepos = writepos;
144 *seqwritepos = This->writepos;
147 static HRESULT DSoundRender_GetWritePos(DSoundRenderImpl *This, DWORD *ret_writepos, REFERENCE_TIME write_at, DWORD *pfree, DWORD *skip)
149 WAVEFORMATEX *wfx = (WAVEFORMATEX*)This->pInputPin->pin.mtCurrent.pbFormat;
150 DWORD writepos, min_writepos, playpos;
151 REFERENCE_TIME max_lag = 50 * 10000;
152 REFERENCE_TIME min_lag = 25 * 10000;
153 REFERENCE_TIME cur, writepos_t, delta_t;
155 DSoundRender_UpdatePositions(This, &writepos, &min_writepos);
156 playpos = This->last_playpos;
157 if (This->filter.pClock == (IReferenceClock*)&This->IReferenceClock_vtbl) {
159 cur = This->play_time + time_from_pos(This, playpos);
160 cur -= This->filter.rtStreamStart;
161 } else if (This->filter.pClock) {
162 IReferenceClock_GetTime(This->filter.pClock, &cur);
163 cur -= This->filter.rtStreamStart;
167 if (writepos == min_writepos)
172 *ret_writepos = writepos;
176 if (writepos >= playpos)
177 writepos_t = cur + time_from_pos(This, writepos - playpos);
179 writepos_t = cur + time_from_pos(This, This->buf_size + writepos - playpos);
181 /* write_at: Starting time of sample */
182 /* cur: current time of play position */
183 /* writepos_t: current time of our pointer play position */
184 delta_t = write_at - writepos_t;
185 if (delta_t >= -max_lag && delta_t <= max_lag) {
186 TRACE("Continuing from old position\n");
187 *ret_writepos = writepos;
188 } else if (delta_t < 0) {
189 REFERENCE_TIME past, min_writepos_t;
190 WARN("Delta too big %i/%i, overwriting old data or even skipping\n", (int)delta_t / 10000, (int)max_lag / 10000);
191 if (min_writepos >= playpos)
192 min_writepos_t = cur + time_from_pos(This, min_writepos - playpos);
194 min_writepos_t = cur + time_from_pos(This, This->buf_size - playpos + min_writepos);
195 past = min_writepos_t - write_at;
197 DWORD skipbytes = pos_from_time(This, past);
198 WARN("Skipping %u bytes\n", skipbytes);
200 *ret_writepos = min_writepos;
202 DWORD aheadbytes = pos_from_time(This, -past);
203 WARN("Advancing %u bytes\n", aheadbytes);
204 *ret_writepos = (min_writepos + aheadbytes) % This->buf_size;
206 } else /* delta_t > 0 */ {
208 WARN("Delta too big %i/%i, too far ahead\n", (int)delta_t / 10000, (int)max_lag / 10000);
209 aheadbytes = pos_from_time(This, delta_t);
210 WARN("Advancing %u bytes\n", aheadbytes);
211 if (delta_t >= DSoundRenderer_Max_Fill)
213 *ret_writepos = (min_writepos + aheadbytes) % This->buf_size;
216 if (playpos > *ret_writepos)
217 *pfree = playpos - *ret_writepos;
218 else if (playpos == *ret_writepos)
219 *pfree = This->buf_size - wfx->nBlockAlign;
221 *pfree = This->buf_size + playpos - *ret_writepos;
222 if (time_from_pos(This, This->buf_size - *pfree) >= DSoundRenderer_Max_Fill) {
223 TRACE("Blocked: too full %i / %i\n", (int)(time_from_pos(This, This->buf_size - *pfree)/10000), (int)(DSoundRenderer_Max_Fill / 10000));
229 static HRESULT DSoundRender_SendSampleData(DSoundRenderImpl* This, REFERENCE_TIME tStart, REFERENCE_TIME tStop, const BYTE *data, DWORD size)
233 while (size && This->filter.state != State_Stopped) {
234 DWORD writepos, skip = 0, free, size1, size2, ret;
237 if (This->filter.state == State_Running)
238 hr = DSoundRender_GetWritePos(This, &writepos, tStart, &free, &skip);
244 LeaveCriticalSection(&This->filter.csFilter);
245 ret = WaitForSingleObject(This->blocked, 10);
246 EnterCriticalSection(&This->filter.csFilter);
248 if (This->pInputPin->flushing ||
249 This->filter.state == State_Stopped) {
250 SetEvent(This->state_change);
251 return This->filter.state == State_Paused ? S_OK : VFW_E_WRONG_STATE;
253 if (ret != WAIT_TIMEOUT)
260 FIXME("Sample dropped %u of %u bytes\n", skip, size);
266 hr = IDirectSoundBuffer_Lock(This->dsbuffer, writepos, min(free, size), (void**)&buf1, &size1, (void**)&buf2, &size2, 0);
268 ERR("Unable to lock sound buffer! (%x)\n", hr);
271 memcpy(buf1, data, size1);
273 memcpy(buf2, data+size1, size2);
274 IDirectSoundBuffer_Unlock(This->dsbuffer, buf1, size1, buf2, size2);
275 This->writepos = (writepos + size1 + size2) % This->buf_size;
276 TRACE("Wrote %u bytes at %u, next at %u - (%u/%u)\n", size1+size2, writepos, This->writepos, free, size);
277 data += size1 + size2;
278 size -= size1 + size2;
283 static HRESULT WINAPI DSoundRender_Receive(BaseInputPin *pin, IMediaSample * pSample)
285 DSoundRenderImpl *This = (DSoundRenderImpl*)pin->pin.pinInfo.pFilter;
286 LPBYTE pbSrcStream = NULL;
287 LONG cbSrcStream = 0;
288 REFERENCE_TIME tStart, tStop;
292 TRACE("%p %p\n", pin, pSample);
294 /* Slightly incorrect, Pause completes when a frame is received so we should signal
295 * pause completion here, but for sound playing a single frame doesn't make sense
298 EnterCriticalSection(&This->filter.csFilter);
300 if (This->pInputPin->end_of_stream || This->pInputPin->flushing)
302 LeaveCriticalSection(&This->filter.csFilter);
306 if (This->filter.state == State_Stopped)
308 LeaveCriticalSection(&This->filter.csFilter);
309 return VFW_E_WRONG_STATE;
312 if (IMediaSample_GetMediaType(pSample, &amt) == S_OK)
314 AM_MEDIA_TYPE *orig = &This->pInputPin->pin.mtCurrent;
315 WAVEFORMATEX *origfmt = (WAVEFORMATEX *)orig->pbFormat;
316 WAVEFORMATEX *newfmt = (WAVEFORMATEX *)amt->pbFormat;
318 if (origfmt->wFormatTag == newfmt->wFormatTag &&
319 origfmt->nChannels == newfmt->nChannels &&
320 origfmt->nBlockAlign == newfmt->nBlockAlign &&
321 origfmt->wBitsPerSample == newfmt->wBitsPerSample &&
322 origfmt->cbSize == newfmt->cbSize)
324 if (origfmt->nSamplesPerSec != newfmt->nSamplesPerSec)
326 hr = IDirectSoundBuffer_SetFrequency(This->dsbuffer,
327 newfmt->nSamplesPerSec);
330 LeaveCriticalSection(&This->filter.csFilter);
331 return VFW_E_TYPE_NOT_ACCEPTED;
334 CopyMediaType(orig, amt);
335 IMediaSample_SetMediaType(pSample, NULL);
340 LeaveCriticalSection(&This->filter.csFilter);
341 return VFW_E_TYPE_NOT_ACCEPTED;
345 hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
348 ERR("Cannot get pointer to sample data (%x)\n", hr);
349 LeaveCriticalSection(&This->filter.csFilter);
353 if (IMediaSample_GetMediaTime(pSample, &tStart, &tStop) == S_OK)
354 MediaSeekingPassThru_RegisterMediaTime(This->seekthru_unk, tStart);
355 hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
357 ERR("Cannot get sample time (%x)\n", hr);
361 IMediaSample_IsDiscontinuity(pSample);
363 if (IMediaSample_IsPreroll(pSample) == S_OK)
366 LeaveCriticalSection(&This->filter.csFilter);
370 cbSrcStream = IMediaSample_GetActualDataLength(pSample);
371 TRACE("Sample data ptr = %p, size = %d\n", pbSrcStream, cbSrcStream);
373 SetEvent(This->state_change);
374 hr = DSoundRender_SendSampleData(This, tStart, tStop, pbSrcStream, cbSrcStream);
375 if (This->filter.state == State_Running && This->filter.pClock && tStart >= 0) {
376 REFERENCE_TIME jitter, now = 0;
378 IReferenceClock_GetTime(This->filter.pClock, &now);
379 jitter = now - This->filter.rtStreamStart - tStart;
380 if (jitter <= -DSoundRenderer_Max_Fill)
381 jitter += DSoundRenderer_Max_Fill;
384 q.Type = (jitter > 0 ? Famine : Flood);
387 q.TimeStamp = tStart;
388 IQualityControl_Notify((IQualityControl *)&This->qcimpl, (IBaseFilter*)This, q);
390 LeaveCriticalSection(&This->filter.csFilter);
394 static HRESULT WINAPI DSoundRender_CheckMediaType(BasePin *iface, const AM_MEDIA_TYPE * pmt)
396 WAVEFORMATEX* format;
398 if (!IsEqualIID(&pmt->majortype, &MEDIATYPE_Audio))
401 format = (WAVEFORMATEX*)pmt->pbFormat;
402 TRACE("Format = %p\n", format);
403 TRACE("wFormatTag = %x %x\n", format->wFormatTag, WAVE_FORMAT_PCM);
404 TRACE("nChannels = %d\n", format->nChannels);
405 TRACE("nSamplesPerSec = %d\n", format->nAvgBytesPerSec);
406 TRACE("nAvgBytesPerSec = %d\n", format->nAvgBytesPerSec);
407 TRACE("nBlockAlign = %d\n", format->nBlockAlign);
408 TRACE("wBitsPerSample = %d\n", format->wBitsPerSample);
410 if (!IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_PCM))
416 static IPin* WINAPI DSoundRender_GetPin(BaseFilter *iface, int pos)
418 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
420 if (pos >= 1 || pos < 0)
423 IPin_AddRef((IPin*)This->pInputPin);
424 return (IPin*)This->pInputPin;
427 static LONG WINAPI DSoundRender_GetPinCount(BaseFilter *iface)
429 /* Our pins are static */
433 static const BaseFilterFuncTable BaseFuncTable = {
435 DSoundRender_GetPinCount
438 static const BasePinFuncTable input_BaseFuncTable = {
439 DSoundRender_CheckMediaType,
441 BasePinImpl_GetMediaTypeVersion,
442 BasePinImpl_GetMediaType
445 static const BaseInputPinFuncTable input_BaseInputFuncTable = {
450 HRESULT DSoundRender_create(IUnknown * pUnkOuter, LPVOID * ppv)
454 DSoundRenderImpl * pDSoundRender;
456 TRACE("(%p, %p)\n", pUnkOuter, ppv);
461 return CLASS_E_NOAGGREGATION;
463 pDSoundRender = CoTaskMemAlloc(sizeof(DSoundRenderImpl));
465 return E_OUTOFMEMORY;
466 ZeroMemory(pDSoundRender, sizeof(DSoundRenderImpl));
468 BaseFilter_Init(&pDSoundRender->filter, &DSoundRender_Vtbl, &CLSID_DSoundRender, (DWORD_PTR)(__FILE__ ": DSoundRenderImpl.csFilter"), &BaseFuncTable);
470 pDSoundRender->IBasicAudio_vtbl = &IBasicAudio_Vtbl;
471 pDSoundRender->IReferenceClock_vtbl = &IReferenceClock_Vtbl;
472 pDSoundRender->IAMDirectSound_vtbl = &IAMDirectSound_Vtbl;
473 pDSoundRender->IAMFilterMiscFlags_vtbl = &IAMFilterMiscFlags_Vtbl;
475 /* construct input pin */
476 piInput.dir = PINDIR_INPUT;
477 piInput.pFilter = (IBaseFilter *)pDSoundRender;
478 lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
479 hr = BaseInputPin_Construct(&DSoundRender_InputPin_Vtbl, &piInput, &input_BaseFuncTable, &input_BaseInputFuncTable, &pDSoundRender->filter.csFilter, NULL, (IPin **)&pDSoundRender->pInputPin);
483 hr = DirectSoundCreate8(NULL, &pDSoundRender->dsound, NULL);
485 ERR("Cannot create Direct Sound object (%x)\n", hr);
487 hr = IDirectSound_SetCooperativeLevel(pDSoundRender->dsound, GetDesktopWindow(), DSSCL_PRIORITY);
489 IDirectSoundBuffer *buf;
490 DSBUFFERDESC buf_desc;
491 memset(&buf_desc,0,sizeof(DSBUFFERDESC));
492 buf_desc.dwSize = sizeof(DSBUFFERDESC);
493 buf_desc.dwFlags = DSBCAPS_PRIMARYBUFFER;
494 hr = IDirectSound_CreateSoundBuffer(pDSoundRender->dsound, &buf_desc, &buf, NULL);
496 IDirectSoundBuffer_Play(buf, 0, 0, DSBPLAY_LOOPING);
497 IUnknown_Release(buf);
505 ISeekingPassThru *passthru;
506 pDSoundRender->state_change = CreateEventW(NULL, TRUE, TRUE, NULL);
507 pDSoundRender->blocked = CreateEventW(NULL, TRUE, TRUE, NULL);
508 hr = CoCreateInstance(&CLSID_SeekingPassThru, (IUnknown*)pDSoundRender, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void**)&pDSoundRender->seekthru_unk);
509 if (!pDSoundRender->state_change || !pDSoundRender->blocked || FAILED(hr))
511 IUnknown_Release((IUnknown *)pDSoundRender);
512 return HRESULT_FROM_WIN32(GetLastError());
515 IUnknown_QueryInterface(pDSoundRender->seekthru_unk, &IID_ISeekingPassThru, (void**)&passthru);
516 ISeekingPassThru_Init(passthru, TRUE, (IPin*)pDSoundRender->pInputPin);
517 ISeekingPassThru_Release(passthru);
518 QualityControlImpl_init(&pDSoundRender->qcimpl, (IPin*)pDSoundRender->pInputPin, (IBaseFilter*)pDSoundRender);
519 pDSoundRender->qcimpl.lpVtbl = &DSoundRender_QualityControl_Vtbl;
520 *ppv = pDSoundRender;
524 if (pDSoundRender->pInputPin)
525 IPin_Release((IPin*)pDSoundRender->pInputPin);
526 BaseFilterImpl_Release((IBaseFilter*)pDSoundRender);
527 CoTaskMemFree(pDSoundRender);
533 static HRESULT WINAPI DSoundRender_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
535 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
536 TRACE("(%p, %p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
540 if (IsEqualIID(riid, &IID_IUnknown))
542 else if (IsEqualIID(riid, &IID_IPersist))
544 else if (IsEqualIID(riid, &IID_IMediaFilter))
546 else if (IsEqualIID(riid, &IID_IBaseFilter))
548 else if (IsEqualIID(riid, &IID_IBasicAudio))
549 *ppv = &This->IBasicAudio_vtbl;
550 else if (IsEqualIID(riid, &IID_IReferenceClock))
551 *ppv = &This->IReferenceClock_vtbl;
552 else if (IsEqualIID(riid, &IID_IMediaSeeking))
553 return IUnknown_QueryInterface(This->seekthru_unk, riid, ppv);
554 else if (IsEqualIID(riid, &IID_IAMDirectSound))
555 *ppv = &This->IAMDirectSound_vtbl;
556 else if (IsEqualIID(riid, &IID_IAMFilterMiscFlags))
557 *ppv = &This->IAMFilterMiscFlags_vtbl;
558 else if (IsEqualIID(riid, &IID_IQualityControl))
559 *ppv = &This->qcimpl;
563 IUnknown_AddRef((IUnknown *)(*ppv));
567 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IVideoWindow))
568 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
570 return E_NOINTERFACE;
573 static ULONG WINAPI DSoundRender_Release(IBaseFilter * iface)
575 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
576 ULONG refCount = BaseFilterImpl_Release(iface);
578 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
584 if (This->threadid) {
585 PostThreadMessageW(This->threadid, WM_APP, 0, 0);
586 WaitForSingleObject(This->advisethread, INFINITE);
587 CloseHandle(This->advisethread);
591 IDirectSoundBuffer_Release(This->dsbuffer);
592 This->dsbuffer = NULL;
594 IDirectSound_Release(This->dsound);
596 if (SUCCEEDED(IPin_ConnectedTo((IPin *)This->pInputPin, &pConnectedTo)))
598 IPin_Disconnect(pConnectedTo);
599 IPin_Release(pConnectedTo);
601 IPin_Disconnect((IPin *)This->pInputPin);
603 IPin_Release((IPin *)This->pInputPin);
605 This->IBasicAudio_vtbl = NULL;
606 if (This->seekthru_unk)
607 IUnknown_Release(This->seekthru_unk);
609 CloseHandle(This->state_change);
610 CloseHandle(This->blocked);
612 TRACE("Destroying Audio Renderer\n");
621 /** IMediaFilter methods **/
623 static HRESULT WINAPI DSoundRender_Stop(IBaseFilter * iface)
626 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
628 TRACE("(%p/%p)->()\n", This, iface);
630 EnterCriticalSection(&This->filter.csFilter);
632 hr = IDirectSoundBuffer_Stop(This->dsbuffer);
634 This->filter.state = State_Stopped;
636 /* Complete our transition */
637 This->writepos = This->buf_size;
638 SetEvent(This->state_change);
639 SetEvent(This->blocked);
640 MediaSeekingPassThru_ResetMediaTime(This->seekthru_unk);
642 LeaveCriticalSection(&This->filter.csFilter);
647 static HRESULT WINAPI DSoundRender_Pause(IBaseFilter * iface)
650 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
652 TRACE("(%p/%p)->()\n", This, iface);
654 EnterCriticalSection(&This->filter.csFilter);
655 if (This->filter.state != State_Paused)
657 if (This->filter.state == State_Stopped)
659 This->pInputPin->end_of_stream = 0;
660 ResetEvent(This->state_change);
663 hr = IDirectSoundBuffer_Stop(This->dsbuffer);
665 This->filter.state = State_Paused;
667 ResetEvent(This->blocked);
669 LeaveCriticalSection(&This->filter.csFilter);
674 static HRESULT WINAPI DSoundRender_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
677 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
679 TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
681 EnterCriticalSection(&This->filter.csFilter);
682 if (This->pInputPin->pin.pConnectedTo)
684 This->filter.rtStreamStart = tStart;
685 QualityControlRender_Start(&This->qcimpl, tStart);
686 if (This->filter.state == State_Paused)
688 /* Unblock our thread, state changing from paused to running doesn't need a reset for state change */
689 SetEvent(This->blocked);
691 else if (This->filter.state == State_Stopped)
693 ResetEvent(This->state_change);
694 This->pInputPin->end_of_stream = 0;
696 IDirectSoundBuffer_Play(This->dsbuffer, 0, 0, DSBPLAY_LOOPING);
697 ResetEvent(This->blocked);
698 } else if (This->filter.filterInfo.pGraph) {
699 IMediaEventSink *pEventSink;
700 hr = IFilterGraph_QueryInterface(This->filter.filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
703 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, (LONG_PTR)This);
704 IMediaEventSink_Release(pEventSink);
709 This->filter.state = State_Running;
710 LeaveCriticalSection(&This->filter.csFilter);
715 static HRESULT WINAPI DSoundRender_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
718 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
720 TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
722 if (WaitForSingleObject(This->state_change, dwMilliSecsTimeout) == WAIT_TIMEOUT)
723 hr = VFW_S_STATE_INTERMEDIATE;
727 BaseFilterImpl_GetState(iface, dwMilliSecsTimeout, pState);
732 /** IBaseFilter implementation **/
734 static HRESULT WINAPI DSoundRender_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
736 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
738 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_w(Id), ppPin);
740 FIXME("DSoundRender::FindPin(...)\n");
742 /* FIXME: critical section */
747 static const IBaseFilterVtbl DSoundRender_Vtbl =
749 DSoundRender_QueryInterface,
750 BaseFilterImpl_AddRef,
751 DSoundRender_Release,
752 BaseFilterImpl_GetClassID,
756 DSoundRender_GetState,
757 BaseFilterImpl_SetSyncSource,
758 BaseFilterImpl_GetSyncSource,
759 BaseFilterImpl_EnumPins,
760 DSoundRender_FindPin,
761 BaseFilterImpl_QueryFilterInfo,
762 BaseFilterImpl_JoinFilterGraph,
763 BaseFilterImpl_QueryVendorInfo
766 static HRESULT WINAPI DSoundRender_InputPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
768 BaseInputPin *This = (BaseInputPin *)iface;
769 PIN_DIRECTION pindirReceive;
770 DSoundRenderImpl *DSImpl;
773 TRACE("(%p)->(%p, %p)\n", This, pReceivePin, pmt);
774 dump_AM_MEDIA_TYPE(pmt);
776 EnterCriticalSection(This->pin.pCritSec);
778 DSImpl = (DSoundRenderImpl*)This->pin.pinInfo.pFilter;
780 if (This->pin.pConnectedTo)
781 hr = VFW_E_ALREADY_CONNECTED;
783 if (SUCCEEDED(hr) && This->pin.pFuncsTable->pfnCheckMediaType((BasePin*)This, pmt) != S_OK)
784 hr = VFW_E_TYPE_NOT_ACCEPTED;
788 IPin_QueryDirection(pReceivePin, &pindirReceive);
790 if (pindirReceive != PINDIR_OUTPUT)
792 ERR("Can't connect from non-output pin\n");
793 hr = VFW_E_INVALID_DIRECTION;
799 WAVEFORMATEX *format;
800 DSBUFFERDESC buf_desc;
802 TRACE("MajorType %s\n", debugstr_guid(&pmt->majortype));
803 TRACE("SubType %s\n", debugstr_guid(&pmt->subtype));
804 TRACE("Format %s\n", debugstr_guid(&pmt->formattype));
805 TRACE("Size %d\n", pmt->cbFormat);
807 format = (WAVEFORMATEX*)pmt->pbFormat;
809 DSImpl->buf_size = format->nAvgBytesPerSec;
811 memset(&buf_desc,0,sizeof(DSBUFFERDESC));
812 buf_desc.dwSize = sizeof(DSBUFFERDESC);
813 buf_desc.dwFlags = DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN |
814 DSBCAPS_CTRLFREQUENCY | DSBCAPS_GLOBALFOCUS |
815 DSBCAPS_GETCURRENTPOSITION2;
816 buf_desc.dwBufferBytes = DSImpl->buf_size;
817 buf_desc.lpwfxFormat = format;
818 hr = IDirectSound_CreateSoundBuffer(DSImpl->dsound, &buf_desc, &DSImpl->dsbuffer, NULL);
819 DSImpl->writepos = DSImpl->buf_size;
821 ERR("Can't create sound buffer (%x)\n", hr);
826 hr = IDirectSoundBuffer_SetVolume(DSImpl->dsbuffer, DSImpl->volume);
828 ERR("Can't set volume to %d (%x)\n", DSImpl->volume, hr);
830 hr = IDirectSoundBuffer_SetPan(DSImpl->dsbuffer, DSImpl->pan);
832 ERR("Can't set pan to %d (%x)\n", DSImpl->pan, hr);
838 CopyMediaType(&This->pin.mtCurrent, pmt);
839 This->pin.pConnectedTo = pReceivePin;
840 IPin_AddRef(pReceivePin);
842 else if (hr != VFW_E_ALREADY_CONNECTED)
844 if (DSImpl->dsbuffer)
845 IDirectSoundBuffer_Release(DSImpl->dsbuffer);
846 DSImpl->dsbuffer = NULL;
849 LeaveCriticalSection(This->pin.pCritSec);
854 static HRESULT WINAPI DSoundRender_InputPin_Disconnect(IPin * iface)
856 BasePin *This = (BasePin*)iface;
857 DSoundRenderImpl *DSImpl;
859 TRACE("(%p)->()\n", iface);
861 DSImpl = (DSoundRenderImpl*)This->pinInfo.pFilter;
862 if (DSImpl->threadid) {
863 PostThreadMessageW(DSImpl->threadid, WM_APP, 0, 0);
864 WaitForSingleObject(DSImpl->advisethread, INFINITE);
865 CloseHandle(DSImpl->advisethread);
867 if (DSImpl->dsbuffer)
868 IDirectSoundBuffer_Release(DSImpl->dsbuffer);
869 DSImpl->dsbuffer = NULL;
871 return BasePinImpl_Disconnect(iface);
874 static HRESULT WINAPI DSoundRender_InputPin_EndOfStream(IPin * iface)
876 BaseInputPin* This = (BaseInputPin*)iface;
877 DSoundRenderImpl *me = (DSoundRenderImpl*)This->pin.pinInfo.pFilter;
878 IMediaEventSink* pEventSink;
881 EnterCriticalSection(This->pin.pCritSec);
883 TRACE("(%p/%p)->()\n", This, iface);
884 hr = BaseInputPinImpl_EndOfStream(iface);
888 LeaveCriticalSection(This->pin.pCritSec);
892 if (me->filter.filterInfo.pGraph)
894 hr = IFilterGraph_QueryInterface(me->filter.filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
897 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, (LONG_PTR)me);
898 IMediaEventSink_Release(pEventSink);
901 MediaSeekingPassThru_EOS(me->seekthru_unk);
902 SetEvent(me->state_change);
903 LeaveCriticalSection(This->pin.pCritSec);
908 static HRESULT WINAPI DSoundRender_InputPin_BeginFlush(IPin * iface)
910 BaseInputPin *This = (BaseInputPin *)iface;
911 DSoundRenderImpl *pFilter = (DSoundRenderImpl *)This->pin.pinInfo.pFilter;
916 EnterCriticalSection(This->pin.pCritSec);
917 hr = BaseInputPinImpl_BeginFlush(iface);
918 SetEvent(pFilter->blocked);
919 LeaveCriticalSection(This->pin.pCritSec);
924 static HRESULT WINAPI DSoundRender_InputPin_EndFlush(IPin * iface)
926 BaseInputPin *This = (BaseInputPin *)iface;
927 DSoundRenderImpl *pFilter = (DSoundRenderImpl *)This->pin.pinInfo.pFilter;
932 EnterCriticalSection(This->pin.pCritSec);
933 if (pFilter->in_loop) {
934 ResetEvent(pFilter->state_change);
935 LeaveCriticalSection(This->pin.pCritSec);
936 WaitForSingleObject(pFilter->state_change, -1);
937 EnterCriticalSection(This->pin.pCritSec);
939 if (pFilter->filter.state != State_Stopped)
940 ResetEvent(pFilter->blocked);
942 if (pFilter->dsbuffer)
948 IDirectSoundBuffer_Lock(pFilter->dsbuffer, 0, 0, (LPVOID *)&buffer, &size, NULL, NULL, DSBLOCK_ENTIREBUFFER);
949 memset(buffer, 0, size);
950 IDirectSoundBuffer_Unlock(pFilter->dsbuffer, buffer, size, NULL, 0);
951 pFilter->writepos = pFilter->buf_size;
953 QualityControlRender_Start(&pFilter->qcimpl, pFilter->filter.rtStreamStart);
954 hr = BaseInputPinImpl_EndFlush(iface);
955 LeaveCriticalSection(This->pin.pCritSec);
956 MediaSeekingPassThru_ResetMediaTime(pFilter->seekthru_unk);
961 static const IPinVtbl DSoundRender_InputPin_Vtbl =
963 BaseInputPinImpl_QueryInterface,
965 BaseInputPinImpl_Release,
966 BaseInputPinImpl_Connect,
967 DSoundRender_InputPin_ReceiveConnection,
968 DSoundRender_InputPin_Disconnect,
969 BasePinImpl_ConnectedTo,
970 BasePinImpl_ConnectionMediaType,
971 BasePinImpl_QueryPinInfo,
972 BasePinImpl_QueryDirection,
974 BaseInputPinImpl_QueryAccept,
975 BasePinImpl_EnumMediaTypes,
976 BasePinImpl_QueryInternalConnections,
977 DSoundRender_InputPin_EndOfStream,
978 DSoundRender_InputPin_BeginFlush,
979 DSoundRender_InputPin_EndFlush,
980 BaseInputPinImpl_NewSegment
983 /*** IUnknown methods ***/
984 static HRESULT WINAPI Basicaudio_QueryInterface(IBasicAudio *iface,
987 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
989 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
991 return DSoundRender_QueryInterface((IBaseFilter*)This, riid, ppvObj);
994 static ULONG WINAPI Basicaudio_AddRef(IBasicAudio *iface) {
995 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
997 TRACE("(%p/%p)->()\n", This, iface);
999 return BaseFilterImpl_AddRef((IBaseFilter*)This);
1002 static ULONG WINAPI Basicaudio_Release(IBasicAudio *iface) {
1003 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1005 TRACE("(%p/%p)->()\n", This, iface);
1007 return DSoundRender_Release((IBaseFilter*)This);
1010 /*** IDispatch methods ***/
1011 static HRESULT WINAPI Basicaudio_GetTypeInfoCount(IBasicAudio *iface,
1013 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1015 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1020 static HRESULT WINAPI Basicaudio_GetTypeInfo(IBasicAudio *iface,
1023 ITypeInfo**ppTInfo) {
1024 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1026 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1031 static HRESULT WINAPI Basicaudio_GetIDsOfNames(IBasicAudio *iface,
1037 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1039 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1044 static HRESULT WINAPI Basicaudio_Invoke(IBasicAudio *iface,
1045 DISPID dispIdMember,
1049 DISPPARAMS*pDispParams,
1051 EXCEPINFO*pExepInfo,
1053 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1055 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);
1060 /*** IBasicAudio methods ***/
1061 static HRESULT WINAPI Basicaudio_put_Volume(IBasicAudio *iface,
1063 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1065 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
1067 if (lVolume > DSBVOLUME_MAX || lVolume < DSBVOLUME_MIN)
1068 return E_INVALIDARG;
1070 if (This->dsbuffer) {
1071 if (FAILED(IDirectSoundBuffer_SetVolume(This->dsbuffer, lVolume)))
1075 This->volume = lVolume;
1079 static HRESULT WINAPI Basicaudio_get_Volume(IBasicAudio *iface,
1081 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1083 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
1088 *plVolume = This->volume;
1092 static HRESULT WINAPI Basicaudio_put_Balance(IBasicAudio *iface,
1094 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1096 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
1098 if (lBalance < DSBPAN_LEFT || lBalance > DSBPAN_RIGHT)
1099 return E_INVALIDARG;
1101 if (This->dsbuffer) {
1102 if (FAILED(IDirectSoundBuffer_SetPan(This->dsbuffer, lBalance)))
1106 This->pan = lBalance;
1110 static HRESULT WINAPI Basicaudio_get_Balance(IBasicAudio *iface,
1112 ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
1114 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
1119 *plBalance = This->pan;
1123 static const IBasicAudioVtbl IBasicAudio_Vtbl =
1125 Basicaudio_QueryInterface,
1128 Basicaudio_GetTypeInfoCount,
1129 Basicaudio_GetTypeInfo,
1130 Basicaudio_GetIDsOfNames,
1132 Basicaudio_put_Volume,
1133 Basicaudio_get_Volume,
1134 Basicaudio_put_Balance,
1135 Basicaudio_get_Balance
1138 struct dsoundrender_timer {
1139 struct dsoundrender_timer *next;
1140 REFERENCE_TIME start;
1141 REFERENCE_TIME periodicity;
1145 static LONG cookie_counter = 1;
1147 static DWORD WINAPI DSoundAdviseThread(LPVOID lpParam) {
1148 DSoundRenderImpl *This = lpParam;
1149 struct dsoundrender_timer head = { };
1152 TRACE("(%p): Main Loop\n", This);
1154 PeekMessageW(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
1155 SetEvent(This->thread_wait);
1160 REFERENCE_TIME curtime = 0;
1162 struct dsoundrender_timer *prev = &head, *cur;
1164 hr = IReferenceClock_GetTime((IReferenceClock*) &This->IReferenceClock_vtbl, &curtime);
1166 FIXME("Could not get time: %08x\n", hr);
1169 TRACE("Time: %Li\n", curtime);
1170 while (prev->next) {
1172 if (cur->start > curtime) {
1173 TRACE("Skipping %p\n", cur);
1175 } else if (cur->periodicity) {
1176 while (cur->start <= curtime) {
1177 cur->start += cur->periodicity;
1178 ReleaseSemaphore(cur->handle, 1, NULL);
1182 struct dsoundrender_timer *next = cur->next;
1183 TRACE("Firing %p %Li < %Li\n", cur, cur->start, curtime);
1184 SetEvent(cur->handle);
1185 HeapFree(GetProcessHeap(), 0, cur);
1190 ret = GetMessageW(&msg, INVALID_HANDLE_VALUE, WM_APP, WM_APP + 4);
1192 ret = PeekMessageW(&msg, INVALID_HANDLE_VALUE, WM_APP, WM_APP + 4, PM_REMOVE);
1194 switch (LOWORD(msg.message) - WM_APP) {
1195 case 0: TRACE("Exiting\n"); return 0;
1198 struct dsoundrender_timer *t = (struct dsoundrender_timer *)msg.wParam;
1199 if (LOWORD(msg.message) - WM_APP == 1)
1200 TRACE("Adding one-shot timer %p\n", t);
1202 TRACE("Adding periodic timer %p\n", t);
1203 t->next = head.next;
1209 while (prev->next) {
1211 if (cur->cookie == msg.wParam) {
1212 struct dsoundrender_timer *next = cur->next;
1213 HeapFree(GetProcessHeap(), 0, cur);
1221 ret = PeekMessageW(&msg, INVALID_HANDLE_VALUE, WM_APP, WM_APP + 4, PM_REMOVE);
1223 MsgWaitForMultipleObjects(0, NULL, 5, QS_POSTMESSAGE, 0);
1228 /*** IUnknown methods ***/
1229 static HRESULT WINAPI ReferenceClock_QueryInterface(IReferenceClock *iface,
1233 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1235 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1237 return DSoundRender_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1240 static ULONG WINAPI ReferenceClock_AddRef(IReferenceClock *iface)
1242 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1244 TRACE("(%p/%p)->()\n", This, iface);
1246 return BaseFilterImpl_AddRef((IBaseFilter*)This);
1249 static ULONG WINAPI ReferenceClock_Release(IReferenceClock *iface)
1251 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1253 TRACE("(%p/%p)->()\n", This, iface);
1255 return DSoundRender_Release((IBaseFilter*)This);
1258 /*** IReferenceClock methods ***/
1259 static HRESULT WINAPI ReferenceClock_GetTime(IReferenceClock *iface,
1260 REFERENCE_TIME *pTime)
1262 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1263 HRESULT hr = E_FAIL;
1265 TRACE("(%p/%p)->(%p)\n", This, iface, pTime);
1269 if (This->dsbuffer) {
1270 DWORD writepos1, writepos2;
1271 EnterCriticalSection(&This->filter.csFilter);
1272 DSoundRender_UpdatePositions(This, &writepos1, &writepos2);
1273 *pTime = This->play_time + time_from_pos(This, This->last_playpos);
1274 LeaveCriticalSection(&This->filter.csFilter);
1278 WARN("Could not get reference time (%x)!\n", hr);
1283 static HRESULT WINAPI ReferenceClock_AdviseTime(IReferenceClock *iface,
1284 REFERENCE_TIME rtBaseTime,
1285 REFERENCE_TIME rtStreamTime,
1287 DWORD_PTR *pdwAdviseCookie)
1289 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1290 REFERENCE_TIME when = rtBaseTime + rtStreamTime;
1291 REFERENCE_TIME future;
1292 TRACE("(%p/%p)->(%s, %s, %p, %p)\n", This, iface, wine_dbgstr_longlong(rtBaseTime), wine_dbgstr_longlong(rtStreamTime), (void*)hEvent, pdwAdviseCookie);
1295 return E_INVALIDARG;
1297 if (!pdwAdviseCookie)
1300 EnterCriticalSection(&This->filter.csFilter);
1301 future = when - This->play_time;
1302 if (!This->threadid && This->dsbuffer) {
1303 This->thread_wait = CreateEventW(0, 0, 0, 0);
1304 This->advisethread = CreateThread(NULL, 0, DSoundAdviseThread, This, 0, &This->threadid);
1305 WaitForSingleObject(This->thread_wait, INFINITE);
1306 CloseHandle(This->thread_wait);
1308 LeaveCriticalSection(&This->filter.csFilter);
1309 /* If it's in the past or the next millisecond, trigger immediately */
1310 if (future <= 10000) {
1311 SetEvent((HANDLE)hEvent);
1312 *pdwAdviseCookie = 0;
1314 struct dsoundrender_timer *t = HeapAlloc(GetProcessHeap(), 0, sizeof(*t));
1318 t->handle = (HANDLE)hEvent;
1319 t->cookie = InterlockedIncrement(&cookie_counter);
1320 PostThreadMessageW(This->threadid, WM_APP+1, (WPARAM)t, 0);
1321 *pdwAdviseCookie = t->cookie;
1327 static HRESULT WINAPI ReferenceClock_AdvisePeriodic(IReferenceClock *iface,
1328 REFERENCE_TIME rtStartTime,
1329 REFERENCE_TIME rtPeriodTime,
1330 HSEMAPHORE hSemaphore,
1331 DWORD_PTR *pdwAdviseCookie)
1333 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1334 struct dsoundrender_timer *t;
1336 TRACE("(%p/%p)->(%s, %s, %p, %p)\n", This, iface, wine_dbgstr_longlong(rtStartTime), wine_dbgstr_longlong(rtPeriodTime), (void*)hSemaphore, pdwAdviseCookie);
1338 if (rtStartTime <= 0 || rtPeriodTime <= 0)
1339 return E_INVALIDARG;
1341 if (!pdwAdviseCookie)
1344 EnterCriticalSection(&This->filter.csFilter);
1345 if (!This->threadid && This->dsbuffer) {
1346 This->thread_wait = CreateEventW(0, 0, 0, 0);
1347 This->advisethread = CreateThread(NULL, 0, DSoundAdviseThread, This, 0, &This->threadid);
1348 WaitForSingleObject(This->thread_wait, INFINITE);
1349 CloseHandle(This->thread_wait);
1351 LeaveCriticalSection(&This->filter.csFilter);
1353 t = HeapAlloc(GetProcessHeap(), 0, sizeof(*t));
1355 t->start = rtStartTime;
1356 t->periodicity = rtPeriodTime;
1357 t->handle = (HANDLE)hSemaphore;
1358 t->cookie = InterlockedIncrement(&cookie_counter);
1359 PostThreadMessageW(This->threadid, WM_APP+1, (WPARAM)t, 0);
1360 *pdwAdviseCookie = t->cookie;
1365 static HRESULT WINAPI ReferenceClock_Unadvise(IReferenceClock *iface,
1366 DWORD_PTR dwAdviseCookie)
1368 ICOM_THIS_MULTI(DSoundRenderImpl, IReferenceClock_vtbl, iface);
1370 TRACE("(%p/%p)->(%p)\n", This, iface, (void*)dwAdviseCookie);
1371 if (!This->advisethread || !dwAdviseCookie)
1373 PostThreadMessageW(This->threadid, WM_APP+3, dwAdviseCookie, 0);
1377 static const IReferenceClockVtbl IReferenceClock_Vtbl =
1379 ReferenceClock_QueryInterface,
1380 ReferenceClock_AddRef,
1381 ReferenceClock_Release,
1382 ReferenceClock_GetTime,
1383 ReferenceClock_AdviseTime,
1384 ReferenceClock_AdvisePeriodic,
1385 ReferenceClock_Unadvise
1388 /*** IUnknown methods ***/
1389 static HRESULT WINAPI AMDirectSound_QueryInterface(IAMDirectSound *iface,
1393 ICOM_THIS_MULTI(DSoundRenderImpl, IAMDirectSound_vtbl, iface);
1395 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1397 return DSoundRender_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1400 static ULONG WINAPI AMDirectSound_AddRef(IAMDirectSound *iface)
1402 ICOM_THIS_MULTI(DSoundRenderImpl, IAMDirectSound_vtbl, iface);
1404 TRACE("(%p/%p)->()\n", This, iface);
1406 return BaseFilterImpl_AddRef((IBaseFilter*)This);
1409 static ULONG WINAPI AMDirectSound_Release(IAMDirectSound *iface)
1411 ICOM_THIS_MULTI(DSoundRenderImpl, IAMDirectSound_vtbl, iface);
1413 TRACE("(%p/%p)->()\n", This, iface);
1415 return DSoundRender_Release((IBaseFilter*)This);
1418 /*** IAMDirectSound methods ***/
1419 static HRESULT WINAPI AMDirectSound_GetDirectSoundInterface(IAMDirectSound *iface, IDirectSound **ds)
1421 ICOM_THIS_MULTI(DSoundRenderImpl, IAMDirectSound_vtbl, iface);
1423 FIXME("(%p/%p)->(%p): stub\n", This, iface, ds);
1428 static HRESULT WINAPI AMDirectSound_GetPrimaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer **buf)
1430 ICOM_THIS_MULTI(DSoundRenderImpl, IAMDirectSound_vtbl, iface);
1432 FIXME("(%p/%p)->(%p): stub\n", This, iface, buf);
1437 static HRESULT WINAPI AMDirectSound_GetSecondaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer **buf)
1439 ICOM_THIS_MULTI(DSoundRenderImpl, IAMDirectSound_vtbl, iface);
1441 FIXME("(%p/%p)->(%p): stub\n", This, iface, buf);
1446 static HRESULT WINAPI AMDirectSound_ReleaseDirectSoundInterface(IAMDirectSound *iface, IDirectSound *ds)
1448 ICOM_THIS_MULTI(DSoundRenderImpl, IAMDirectSound_vtbl, iface);
1450 FIXME("(%p/%p)->(%p): stub\n", This, iface, ds);
1455 static HRESULT WINAPI AMDirectSound_ReleasePrimaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer *buf)
1457 ICOM_THIS_MULTI(DSoundRenderImpl, IAMDirectSound_vtbl, iface);
1459 FIXME("(%p/%p)->(%p): stub\n", This, iface, buf);
1464 static HRESULT WINAPI AMDirectSound_ReleaseSecondaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer *buf)
1466 ICOM_THIS_MULTI(DSoundRenderImpl, IAMDirectSound_vtbl, iface);
1468 FIXME("(%p/%p)->(%p): stub\n", This, iface, buf);
1473 static HRESULT WINAPI AMDirectSound_SetFocusWindow(IAMDirectSound *iface, HWND hwnd, BOOL bgsilent)
1475 ICOM_THIS_MULTI(DSoundRenderImpl, IAMDirectSound_vtbl, iface);
1477 FIXME("(%p/%p)->(%p,%d): stub\n", This, iface, hwnd, bgsilent);
1482 static HRESULT WINAPI AMDirectSound_GetFocusWindow(IAMDirectSound *iface, HWND hwnd)
1484 ICOM_THIS_MULTI(DSoundRenderImpl, IAMDirectSound_vtbl, iface);
1486 FIXME("(%p/%p)->(%p): stub\n", This, iface, hwnd);
1491 static const IAMDirectSoundVtbl IAMDirectSound_Vtbl =
1493 AMDirectSound_QueryInterface,
1494 AMDirectSound_AddRef,
1495 AMDirectSound_Release,
1496 AMDirectSound_GetDirectSoundInterface,
1497 AMDirectSound_GetPrimaryBufferInterface,
1498 AMDirectSound_GetSecondaryBufferInterface,
1499 AMDirectSound_ReleaseDirectSoundInterface,
1500 AMDirectSound_ReleasePrimaryBufferInterface,
1501 AMDirectSound_ReleaseSecondaryBufferInterface,
1502 AMDirectSound_SetFocusWindow,
1503 AMDirectSound_GetFocusWindow
1506 static DSoundRenderImpl *from_IAMFilterMiscFlags(IAMFilterMiscFlags *iface) {
1507 return (DSoundRenderImpl*)((char*)iface - offsetof(DSoundRenderImpl, IAMFilterMiscFlags_vtbl));
1510 static HRESULT WINAPI AMFilterMiscFlags_QueryInterface(IAMFilterMiscFlags *iface, const REFIID riid, void **ppv) {
1511 DSoundRenderImpl *This = from_IAMFilterMiscFlags(iface);
1512 return IUnknown_QueryInterface((IUnknown*)This, riid, ppv);
1515 static ULONG WINAPI AMFilterMiscFlags_AddRef(IAMFilterMiscFlags *iface) {
1516 DSoundRenderImpl *This = from_IAMFilterMiscFlags(iface);
1517 return IUnknown_AddRef((IUnknown*)This);
1520 static ULONG WINAPI AMFilterMiscFlags_Release(IAMFilterMiscFlags *iface) {
1521 DSoundRenderImpl *This = from_IAMFilterMiscFlags(iface);
1522 return IUnknown_Release((IUnknown*)This);
1525 static ULONG WINAPI AMFilterMiscFlags_GetMiscFlags(IAMFilterMiscFlags *iface) {
1526 return AM_FILTER_MISC_FLAGS_IS_RENDERER;
1529 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl = {
1530 AMFilterMiscFlags_QueryInterface,
1531 AMFilterMiscFlags_AddRef,
1532 AMFilterMiscFlags_Release,
1533 AMFilterMiscFlags_GetMiscFlags