mshtml: Fixed event target leak in dispatch_event.
[wine.git] / dlls / quartz / dsoundrender.c
blob79029554819729f66c464612e3ab054661a9d576
1 /*
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
21 #include "config.h"
23 #include "quartz_private.h"
24 #include "pin.h"
26 #include "uuids.h"
27 #include "vfwmsgs.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "dshow.h"
31 #include "evcode.h"
32 #include "strmif.h"
33 #include "dsound.h"
34 #include "amaudio.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
41 /* NOTE: buffer can still be filled completely,
42 * but we start waiting until only this amount is buffered
44 static const REFERENCE_TIME DSoundRenderer_Max_Fill = 150 * 10000;
46 static const IBaseFilterVtbl DSoundRender_Vtbl;
47 static const IBasicAudioVtbl IBasicAudio_Vtbl;
48 static const IReferenceClockVtbl IReferenceClock_Vtbl;
49 static const IAMDirectSoundVtbl IAMDirectSound_Vtbl;
50 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl;
52 typedef struct DSoundRenderImpl
54 BaseRenderer renderer;
55 BasicAudio basicAudio;
57 IReferenceClock IReferenceClock_iface;
58 IAMDirectSound IAMDirectSound_iface;
59 IAMFilterMiscFlags IAMFilterMiscFlags_iface;
61 IDirectSound8 *dsound;
62 LPDIRECTSOUNDBUFFER dsbuffer;
63 DWORD buf_size;
64 DWORD in_loop;
65 DWORD last_playpos, writepos;
67 REFERENCE_TIME play_time;
69 HANDLE blocked;
71 LONG volume;
72 LONG pan;
74 DWORD threadid;
75 HANDLE advisethread, thread_wait;
76 } DSoundRenderImpl;
78 static inline DSoundRenderImpl *impl_from_BaseRenderer(BaseRenderer *iface)
80 return CONTAINING_RECORD(iface, DSoundRenderImpl, renderer);
83 static inline DSoundRenderImpl *impl_from_IBaseFilter(IBaseFilter *iface)
85 return CONTAINING_RECORD(iface, DSoundRenderImpl, renderer.filter.IBaseFilter_iface);
88 static inline DSoundRenderImpl *impl_from_IBasicAudio(IBasicAudio *iface)
90 return CONTAINING_RECORD(iface, DSoundRenderImpl, basicAudio.IBasicAudio_iface);
93 static inline DSoundRenderImpl *impl_from_IReferenceClock(IReferenceClock *iface)
95 return CONTAINING_RECORD(iface, DSoundRenderImpl, IReferenceClock_iface);
98 static inline DSoundRenderImpl *impl_from_IAMDirectSound(IAMDirectSound *iface)
100 return CONTAINING_RECORD(iface, DSoundRenderImpl, IAMDirectSound_iface);
103 static inline DSoundRenderImpl *impl_from_IAMFilterMiscFlags(IAMFilterMiscFlags *iface)
105 return CONTAINING_RECORD(iface, DSoundRenderImpl, IAMFilterMiscFlags_iface);
108 static REFERENCE_TIME time_from_pos(DSoundRenderImpl *This, DWORD pos) {
109 WAVEFORMATEX *wfx = (WAVEFORMATEX*)This->renderer.pInputPin->pin.mtCurrent.pbFormat;
110 REFERENCE_TIME ret = 10000000;
111 ret = ret * pos / wfx->nAvgBytesPerSec;
112 return ret;
115 static DWORD pos_from_time(DSoundRenderImpl *This, REFERENCE_TIME time) {
116 WAVEFORMATEX *wfx = (WAVEFORMATEX*)This->renderer.pInputPin->pin.mtCurrent.pbFormat;
117 REFERENCE_TIME ret = time;
118 ret *= wfx->nAvgBytesPerSec;
119 ret /= 10000000;
120 ret -= ret % wfx->nBlockAlign;
121 return ret;
124 static void DSoundRender_UpdatePositions(DSoundRenderImpl *This, DWORD *seqwritepos, DWORD *minwritepos) {
125 WAVEFORMATEX *wfx = (WAVEFORMATEX*)This->renderer.pInputPin->pin.mtCurrent.pbFormat;
126 BYTE *buf1, *buf2;
127 DWORD size1, size2, playpos, writepos, old_writepos, old_playpos, adv;
128 BOOL writepos_set = This->writepos < This->buf_size;
130 /* Update position and zero */
131 old_writepos = This->writepos;
132 old_playpos = This->last_playpos;
133 if (old_writepos <= old_playpos)
134 old_writepos += This->buf_size;
136 IDirectSoundBuffer_GetCurrentPosition(This->dsbuffer, &playpos, &writepos);
137 if (old_playpos > playpos) {
138 adv = This->buf_size + playpos - old_playpos;
139 This->play_time += time_from_pos(This, This->buf_size);
140 } else
141 adv = playpos - old_playpos;
142 This->last_playpos = playpos;
143 if (adv) {
144 TRACE("Moving from %u to %u: clearing %u bytes\n", old_playpos, playpos, adv);
145 IDirectSoundBuffer_Lock(This->dsbuffer, old_playpos, adv, (void**)&buf1, &size1, (void**)&buf2, &size2, 0);
146 memset(buf1, wfx->wBitsPerSample == 8 ? 128 : 0, size1);
147 memset(buf2, wfx->wBitsPerSample == 8 ? 128 : 0, size2);
148 IDirectSoundBuffer_Unlock(This->dsbuffer, buf1, size1, buf2, size2);
150 *minwritepos = writepos;
151 if (!writepos_set || old_writepos < writepos) {
152 if (writepos_set) {
153 This->writepos = This->buf_size;
154 FIXME("Underrun of data occurred!\n");
156 *seqwritepos = writepos;
157 } else
158 *seqwritepos = This->writepos;
161 static HRESULT DSoundRender_GetWritePos(DSoundRenderImpl *This, DWORD *ret_writepos, REFERENCE_TIME write_at, DWORD *pfree, DWORD *skip)
163 WAVEFORMATEX *wfx = (WAVEFORMATEX*)This->renderer.pInputPin->pin.mtCurrent.pbFormat;
164 DWORD writepos, min_writepos, playpos;
165 REFERENCE_TIME max_lag = 50 * 10000;
166 REFERENCE_TIME min_lag = 25 * 10000;
167 REFERENCE_TIME cur, writepos_t, delta_t;
169 DSoundRender_UpdatePositions(This, &writepos, &min_writepos);
170 playpos = This->last_playpos;
171 if (This->renderer.filter.pClock == &This->IReferenceClock_iface) {
172 max_lag = min_lag;
173 cur = This->play_time + time_from_pos(This, playpos);
174 cur -= This->renderer.filter.rtStreamStart;
175 } else if (This->renderer.filter.pClock) {
176 IReferenceClock_GetTime(This->renderer.filter.pClock, &cur);
177 cur -= This->renderer.filter.rtStreamStart;
178 } else
179 write_at = -1;
181 if (writepos == min_writepos)
182 max_lag = 0;
184 *skip = 0;
185 if (write_at < 0) {
186 *ret_writepos = writepos;
187 goto end;
190 if (writepos >= playpos)
191 writepos_t = cur + time_from_pos(This, writepos - playpos);
192 else
193 writepos_t = cur + time_from_pos(This, This->buf_size + writepos - playpos);
195 /* write_at: Starting time of sample */
196 /* cur: current time of play position */
197 /* writepos_t: current time of our pointer play position */
198 delta_t = write_at - writepos_t;
199 if (delta_t >= -max_lag && delta_t <= max_lag) {
200 TRACE("Continuing from old position\n");
201 *ret_writepos = writepos;
202 } else if (delta_t < 0) {
203 REFERENCE_TIME past, min_writepos_t;
204 WARN("Delta too big %i/%i, overwriting old data or even skipping\n", (int)delta_t / 10000, (int)max_lag / 10000);
205 if (min_writepos >= playpos)
206 min_writepos_t = cur + time_from_pos(This, min_writepos - playpos);
207 else
208 min_writepos_t = cur + time_from_pos(This, This->buf_size - playpos + min_writepos);
209 past = min_writepos_t - write_at;
210 if (past >= 0) {
211 DWORD skipbytes = pos_from_time(This, past);
212 WARN("Skipping %u bytes\n", skipbytes);
213 *skip = skipbytes;
214 *ret_writepos = min_writepos;
215 } else {
216 DWORD aheadbytes = pos_from_time(This, -past);
217 WARN("Advancing %u bytes\n", aheadbytes);
218 *ret_writepos = (min_writepos + aheadbytes) % This->buf_size;
220 } else /* delta_t > 0 */ {
221 DWORD aheadbytes;
222 WARN("Delta too big %i/%i, too far ahead\n", (int)delta_t / 10000, (int)max_lag / 10000);
223 aheadbytes = pos_from_time(This, delta_t);
224 WARN("Advancing %u bytes\n", aheadbytes);
225 if (delta_t >= DSoundRenderer_Max_Fill)
226 return S_FALSE;
227 *ret_writepos = (min_writepos + aheadbytes) % This->buf_size;
229 end:
230 if (playpos > *ret_writepos)
231 *pfree = playpos - *ret_writepos;
232 else if (playpos == *ret_writepos)
233 *pfree = This->buf_size - wfx->nBlockAlign;
234 else
235 *pfree = This->buf_size + playpos - *ret_writepos;
236 if (time_from_pos(This, This->buf_size - *pfree) >= DSoundRenderer_Max_Fill) {
237 TRACE("Blocked: too full %i / %i\n", (int)(time_from_pos(This, This->buf_size - *pfree)/10000), (int)(DSoundRenderer_Max_Fill / 10000));
238 return S_FALSE;
240 return S_OK;
243 static HRESULT DSoundRender_HandleEndOfStream(DSoundRenderImpl *This)
245 while (This->renderer.filter.state == State_Running)
247 DWORD pos1, pos2;
248 DSoundRender_UpdatePositions(This, &pos1, &pos2);
249 if (pos1 == pos2)
250 break;
252 This->in_loop = 1;
253 LeaveCriticalSection(&This->renderer.filter.csFilter);
254 LeaveCriticalSection(&This->renderer.csRenderLock);
255 WaitForSingleObject(This->blocked, 10);
256 EnterCriticalSection(&This->renderer.csRenderLock);
257 EnterCriticalSection(&This->renderer.filter.csFilter);
258 This->in_loop = 0;
261 return S_OK;
264 static HRESULT DSoundRender_SendSampleData(DSoundRenderImpl* This, REFERENCE_TIME tStart, REFERENCE_TIME tStop, const BYTE *data, DWORD size)
266 HRESULT hr;
268 while (size && This->renderer.filter.state != State_Stopped) {
269 DWORD writepos, skip = 0, free, size1, size2, ret;
270 BYTE *buf1, *buf2;
272 if (This->renderer.filter.state == State_Running)
273 hr = DSoundRender_GetWritePos(This, &writepos, tStart, &free, &skip);
274 else
275 hr = S_FALSE;
277 if (hr != S_OK) {
278 This->in_loop = 1;
279 LeaveCriticalSection(&This->renderer.csRenderLock);
280 ret = WaitForSingleObject(This->blocked, 10);
281 EnterCriticalSection(&This->renderer.csRenderLock);
282 This->in_loop = 0;
283 if (This->renderer.pInputPin->flushing ||
284 This->renderer.filter.state == State_Stopped) {
285 return This->renderer.filter.state == State_Paused ? S_OK : VFW_E_WRONG_STATE;
287 if (ret != WAIT_TIMEOUT)
288 ERR("%x\n", ret);
289 continue;
291 tStart = -1;
293 if (skip)
294 FIXME("Sample dropped %u of %u bytes\n", skip, size);
295 if (skip >= size)
296 return S_OK;
297 data += skip;
298 size -= skip;
300 hr = IDirectSoundBuffer_Lock(This->dsbuffer, writepos, min(free, size), (void**)&buf1, &size1, (void**)&buf2, &size2, 0);
301 if (hr != DS_OK) {
302 ERR("Unable to lock sound buffer! (%x)\n", hr);
303 break;
305 memcpy(buf1, data, size1);
306 if (size2)
307 memcpy(buf2, data+size1, size2);
308 IDirectSoundBuffer_Unlock(This->dsbuffer, buf1, size1, buf2, size2);
309 This->writepos = (writepos + size1 + size2) % This->buf_size;
310 TRACE("Wrote %u bytes at %u, next at %u - (%u/%u)\n", size1+size2, writepos, This->writepos, free, size);
311 data += size1 + size2;
312 size -= size1 + size2;
314 return S_OK;
317 static HRESULT WINAPI DSoundRender_ShouldDrawSampleNow(BaseRenderer *This, IMediaSample *pMediaSample, REFERENCE_TIME *pStartTime, REFERENCE_TIME *pEndTime)
319 /* We time ourselves do not use the base renderers timing */
320 return S_OK;
324 static HRESULT WINAPI DSoundRender_PrepareReceive(BaseRenderer *iface, IMediaSample *pSample)
326 DSoundRenderImpl *This = impl_from_BaseRenderer(iface);
327 HRESULT hr;
328 AM_MEDIA_TYPE *amt;
330 if (IMediaSample_GetMediaType(pSample, &amt) == S_OK)
332 AM_MEDIA_TYPE *orig = &This->renderer.pInputPin->pin.mtCurrent;
333 WAVEFORMATEX *origfmt = (WAVEFORMATEX *)orig->pbFormat;
334 WAVEFORMATEX *newfmt = (WAVEFORMATEX *)amt->pbFormat;
336 if (origfmt->wFormatTag == newfmt->wFormatTag &&
337 origfmt->nChannels == newfmt->nChannels &&
338 origfmt->nBlockAlign == newfmt->nBlockAlign &&
339 origfmt->wBitsPerSample == newfmt->wBitsPerSample &&
340 origfmt->cbSize == newfmt->cbSize)
342 if (origfmt->nSamplesPerSec != newfmt->nSamplesPerSec)
344 hr = IDirectSoundBuffer_SetFrequency(This->dsbuffer,
345 newfmt->nSamplesPerSec);
346 if (FAILED(hr))
347 return VFW_E_TYPE_NOT_ACCEPTED;
348 FreeMediaType(orig);
349 CopyMediaType(orig, amt);
350 IMediaSample_SetMediaType(pSample, NULL);
353 else
354 return VFW_E_TYPE_NOT_ACCEPTED;
356 return S_OK;
359 static HRESULT WINAPI DSoundRender_DoRenderSample(BaseRenderer *iface, IMediaSample * pSample)
361 DSoundRenderImpl *This = impl_from_BaseRenderer(iface);
362 LPBYTE pbSrcStream = NULL;
363 LONG cbSrcStream = 0;
364 REFERENCE_TIME tStart, tStop;
365 HRESULT hr;
367 TRACE("%p %p\n", iface, pSample);
369 /* Slightly incorrect, Pause completes when a frame is received so we should signal
370 * pause completion here, but for sound playing a single frame doesn't make sense
373 hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
374 if (FAILED(hr))
376 ERR("Cannot get pointer to sample data (%x)\n", hr);
377 return hr;
380 hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
381 if (FAILED(hr)) {
382 ERR("Cannot get sample time (%x)\n", hr);
383 tStart = tStop = -1;
386 IMediaSample_IsDiscontinuity(pSample);
388 if (IMediaSample_IsPreroll(pSample) == S_OK)
390 TRACE("Preroll!\n");
391 return S_OK;
394 cbSrcStream = IMediaSample_GetActualDataLength(pSample);
395 TRACE("Sample data ptr = %p, size = %d\n", pbSrcStream, cbSrcStream);
397 hr = DSoundRender_SendSampleData(This, tStart, tStop, pbSrcStream, cbSrcStream);
398 if (This->renderer.filter.state == State_Running && This->renderer.filter.pClock && tStart >= 0) {
399 REFERENCE_TIME jitter, now = 0;
400 Quality q;
401 IReferenceClock_GetTime(This->renderer.filter.pClock, &now);
402 jitter = now - This->renderer.filter.rtStreamStart - tStart;
403 if (jitter <= -DSoundRenderer_Max_Fill)
404 jitter += DSoundRenderer_Max_Fill;
405 else if (jitter < 0)
406 jitter = 0;
407 q.Type = (jitter > 0 ? Famine : Flood);
408 q.Proportion = 1000;
409 q.Late = jitter;
410 q.TimeStamp = tStart;
411 IQualityControl_Notify((IQualityControl *)This->renderer.qcimpl, (IBaseFilter*)This, q);
413 return hr;
416 static HRESULT WINAPI DSoundRender_CheckMediaType(BaseRenderer *iface, const AM_MEDIA_TYPE * pmt)
418 WAVEFORMATEX* format;
420 if (!IsEqualIID(&pmt->majortype, &MEDIATYPE_Audio))
421 return S_FALSE;
423 format = (WAVEFORMATEX*)pmt->pbFormat;
424 TRACE("Format = %p\n", format);
425 TRACE("wFormatTag = %x %x\n", format->wFormatTag, WAVE_FORMAT_PCM);
426 TRACE("nChannels = %d\n", format->nChannels);
427 TRACE("nSamplesPerSec = %d\n", format->nSamplesPerSec);
428 TRACE("nAvgBytesPerSec = %d\n", format->nAvgBytesPerSec);
429 TRACE("nBlockAlign = %d\n", format->nBlockAlign);
430 TRACE("wBitsPerSample = %d\n", format->wBitsPerSample);
432 if (!IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_PCM))
433 return S_FALSE;
435 return S_OK;
438 static VOID WINAPI DSoundRender_OnStopStreaming(BaseRenderer * iface)
440 DSoundRenderImpl *This = impl_from_BaseRenderer(iface);
442 TRACE("(%p/%p)->()\n", This, iface);
444 IDirectSoundBuffer_Stop(This->dsbuffer);
445 This->writepos = This->buf_size;
446 SetEvent(This->blocked);
449 static VOID WINAPI DSoundRender_OnStartStreaming(BaseRenderer * iface)
451 DSoundRenderImpl *This = impl_from_BaseRenderer(iface);
453 TRACE("(%p)\n", This);
455 if (This->renderer.pInputPin->pin.pConnectedTo)
457 if (This->renderer.filter.state == State_Paused)
459 /* Unblock our thread, state changing from paused to running doesn't need a reset for state change */
460 SetEvent(This->blocked);
462 IDirectSoundBuffer_Play(This->dsbuffer, 0, 0, DSBPLAY_LOOPING);
463 ResetEvent(This->blocked);
467 static HRESULT WINAPI DSoundRender_CompleteConnect(BaseRenderer * iface, IPin * pReceivePin)
469 DSoundRenderImpl *This = impl_from_BaseRenderer(iface);
470 const AM_MEDIA_TYPE * pmt = &This->renderer.pInputPin->pin.mtCurrent;
471 HRESULT hr = S_OK;
472 WAVEFORMATEX *format;
473 DSBUFFERDESC buf_desc;
475 TRACE("(%p)->(%p)\n", This, pReceivePin);
476 dump_AM_MEDIA_TYPE(pmt);
478 TRACE("MajorType %s\n", debugstr_guid(&pmt->majortype));
479 TRACE("SubType %s\n", debugstr_guid(&pmt->subtype));
480 TRACE("Format %s\n", debugstr_guid(&pmt->formattype));
481 TRACE("Size %d\n", pmt->cbFormat);
483 format = (WAVEFORMATEX*)pmt->pbFormat;
485 This->buf_size = format->nAvgBytesPerSec;
487 memset(&buf_desc,0,sizeof(DSBUFFERDESC));
488 buf_desc.dwSize = sizeof(DSBUFFERDESC);
489 buf_desc.dwFlags = DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN |
490 DSBCAPS_CTRLFREQUENCY | DSBCAPS_GLOBALFOCUS |
491 DSBCAPS_GETCURRENTPOSITION2;
492 buf_desc.dwBufferBytes = This->buf_size;
493 buf_desc.lpwfxFormat = format;
494 hr = IDirectSound_CreateSoundBuffer(This->dsound, &buf_desc, &This->dsbuffer, NULL);
495 This->writepos = This->buf_size;
496 if (FAILED(hr))
497 ERR("Can't create sound buffer (%x)\n", hr);
499 if (SUCCEEDED(hr))
501 hr = IDirectSoundBuffer_SetVolume(This->dsbuffer, This->volume);
502 if (FAILED(hr))
503 ERR("Can't set volume to %d (%x)\n", This->volume, hr);
505 hr = IDirectSoundBuffer_SetPan(This->dsbuffer, This->pan);
506 if (FAILED(hr))
507 ERR("Can't set pan to %d (%x)\n", This->pan, hr);
508 hr = S_OK;
511 if (FAILED(hr) && hr != VFW_E_ALREADY_CONNECTED)
513 if (This->dsbuffer)
514 IDirectSoundBuffer_Release(This->dsbuffer);
515 This->dsbuffer = NULL;
518 return hr;
521 static HRESULT WINAPI DSoundRender_BreakConnect(BaseRenderer* iface)
523 DSoundRenderImpl *This = impl_from_BaseRenderer(iface);
525 TRACE("(%p)->()\n", iface);
527 if (This->threadid) {
528 PostThreadMessageW(This->threadid, WM_APP, 0, 0);
529 LeaveCriticalSection(This->renderer.pInputPin->pin.pCritSec);
530 WaitForSingleObject(This->advisethread, INFINITE);
531 EnterCriticalSection(This->renderer.pInputPin->pin.pCritSec);
532 CloseHandle(This->advisethread);
534 if (This->dsbuffer)
535 IDirectSoundBuffer_Release(This->dsbuffer);
536 This->dsbuffer = NULL;
538 return S_OK;
541 static HRESULT WINAPI DSoundRender_EndOfStream(BaseRenderer* iface)
543 DSoundRenderImpl *This = impl_from_BaseRenderer(iface);
544 HRESULT hr;
546 TRACE("(%p)->()\n",iface);
548 hr = BaseRendererImpl_EndOfStream(iface);
549 if (hr != S_OK)
551 ERR("%08x\n", hr);
552 return hr;
555 hr = DSoundRender_HandleEndOfStream(This);
557 return hr;
560 static HRESULT WINAPI DSoundRender_BeginFlush(BaseRenderer* iface)
562 DSoundRenderImpl *This = impl_from_BaseRenderer(iface);
564 TRACE("\n");
565 BaseRendererImpl_BeginFlush(iface);
566 SetEvent(This->blocked);
568 return S_OK;
571 static HRESULT WINAPI DSoundRender_EndFlush(BaseRenderer* iface)
573 DSoundRenderImpl *This = impl_from_BaseRenderer(iface);
575 TRACE("\n");
577 BaseRendererImpl_EndFlush(iface);
578 if (This->renderer.filter.state != State_Stopped)
579 ResetEvent(This->blocked);
581 if (This->dsbuffer)
583 LPBYTE buffer;
584 DWORD size;
586 /* Force a reset */
587 IDirectSoundBuffer_Lock(This->dsbuffer, 0, 0, (LPVOID *)&buffer, &size, NULL, NULL, DSBLOCK_ENTIREBUFFER);
588 memset(buffer, 0, size);
589 IDirectSoundBuffer_Unlock(This->dsbuffer, buffer, size, NULL, 0);
590 This->writepos = This->buf_size;
593 return S_OK;
596 static const BaseRendererFuncTable BaseFuncTable = {
597 DSoundRender_CheckMediaType,
598 DSoundRender_DoRenderSample,
599 /**/
600 NULL,
601 NULL,
602 NULL,
603 DSoundRender_OnStartStreaming,
604 DSoundRender_OnStopStreaming,
605 NULL,
606 NULL,
607 NULL,
608 DSoundRender_ShouldDrawSampleNow,
609 DSoundRender_PrepareReceive,
610 /**/
611 DSoundRender_CompleteConnect,
612 DSoundRender_BreakConnect,
613 DSoundRender_EndOfStream,
614 DSoundRender_BeginFlush,
615 DSoundRender_EndFlush,
618 HRESULT DSoundRender_create(IUnknown * pUnkOuter, LPVOID * ppv)
620 HRESULT hr;
621 DSoundRenderImpl * pDSoundRender;
623 TRACE("(%p, %p)\n", pUnkOuter, ppv);
625 *ppv = NULL;
627 if (pUnkOuter)
628 return CLASS_E_NOAGGREGATION;
630 pDSoundRender = CoTaskMemAlloc(sizeof(DSoundRenderImpl));
631 if (!pDSoundRender)
632 return E_OUTOFMEMORY;
633 ZeroMemory(pDSoundRender, sizeof(DSoundRenderImpl));
635 hr = BaseRenderer_Init(&pDSoundRender->renderer, &DSoundRender_Vtbl, (IUnknown*)pDSoundRender, &CLSID_DSoundRender, (DWORD_PTR)(__FILE__ ": DSoundRenderImpl.csFilter"), &BaseFuncTable);
637 BasicAudio_Init(&pDSoundRender->basicAudio,&IBasicAudio_Vtbl);
638 pDSoundRender->IReferenceClock_iface.lpVtbl = &IReferenceClock_Vtbl;
639 pDSoundRender->IAMDirectSound_iface.lpVtbl = &IAMDirectSound_Vtbl;
640 pDSoundRender->IAMFilterMiscFlags_iface.lpVtbl = &IAMFilterMiscFlags_Vtbl;
642 if (SUCCEEDED(hr))
644 hr = DirectSoundCreate8(NULL, &pDSoundRender->dsound, NULL);
645 if (FAILED(hr))
646 ERR("Cannot create Direct Sound object (%x)\n", hr);
647 else
648 hr = IDirectSound_SetCooperativeLevel(pDSoundRender->dsound, GetDesktopWindow(), DSSCL_PRIORITY);
649 if (SUCCEEDED(hr)) {
650 IDirectSoundBuffer *buf;
651 DSBUFFERDESC buf_desc;
652 memset(&buf_desc,0,sizeof(DSBUFFERDESC));
653 buf_desc.dwSize = sizeof(DSBUFFERDESC);
654 buf_desc.dwFlags = DSBCAPS_PRIMARYBUFFER;
655 hr = IDirectSound_CreateSoundBuffer(pDSoundRender->dsound, &buf_desc, &buf, NULL);
656 if (SUCCEEDED(hr)) {
657 IDirectSoundBuffer_Play(buf, 0, 0, DSBPLAY_LOOPING);
658 IDirectSoundBuffer_Release(buf);
660 hr = S_OK;
664 if (SUCCEEDED(hr))
666 pDSoundRender->blocked = CreateEventW(NULL, TRUE, TRUE, NULL);
668 if (!pDSoundRender->blocked || FAILED(hr))
670 IBaseFilter_Release(&pDSoundRender->renderer.filter.IBaseFilter_iface);
671 return HRESULT_FROM_WIN32(GetLastError());
674 *ppv = pDSoundRender;
676 else
678 BaseRendererImpl_Release(&pDSoundRender->renderer.filter.IBaseFilter_iface);
679 CoTaskMemFree(pDSoundRender);
682 return hr;
685 static HRESULT WINAPI DSoundRender_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
687 DSoundRenderImpl *This = impl_from_IBaseFilter(iface);
688 TRACE("(%p, %p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
690 *ppv = NULL;
692 if (IsEqualIID(riid, &IID_IBasicAudio))
693 *ppv = &This->basicAudio.IBasicAudio_iface;
694 else if (IsEqualIID(riid, &IID_IReferenceClock))
695 *ppv = &This->IReferenceClock_iface;
696 else if (IsEqualIID(riid, &IID_IAMDirectSound))
697 *ppv = &This->IAMDirectSound_iface;
698 else if (IsEqualIID(riid, &IID_IAMFilterMiscFlags))
699 *ppv = &This->IAMFilterMiscFlags_iface;
700 else
702 HRESULT hr;
703 hr = BaseRendererImpl_QueryInterface(iface, riid, ppv);
704 if (SUCCEEDED(hr))
705 return hr;
708 if (*ppv)
710 IUnknown_AddRef((IUnknown *)(*ppv));
711 return S_OK;
714 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IVideoWindow))
715 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
717 return E_NOINTERFACE;
720 static ULONG WINAPI DSoundRender_Release(IBaseFilter * iface)
722 DSoundRenderImpl *This = impl_from_IBaseFilter(iface);
723 ULONG refCount = BaseRendererImpl_Release(iface);
725 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
727 if (!refCount)
729 if (This->threadid) {
730 PostThreadMessageW(This->threadid, WM_APP, 0, 0);
731 WaitForSingleObject(This->advisethread, INFINITE);
732 CloseHandle(This->advisethread);
735 if (This->dsbuffer)
736 IDirectSoundBuffer_Release(This->dsbuffer);
737 This->dsbuffer = NULL;
738 if (This->dsound)
739 IDirectSound_Release(This->dsound);
740 This->dsound = NULL;
742 BasicAudio_Destroy(&This->basicAudio);
743 CloseHandle(This->blocked);
745 TRACE("Destroying Audio Renderer\n");
746 CoTaskMemFree(This);
748 return 0;
750 else
751 return refCount;
754 static HRESULT WINAPI DSoundRender_Pause(IBaseFilter * iface)
756 HRESULT hr = S_OK;
757 DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
759 TRACE("(%p/%p)->()\n", This, iface);
761 EnterCriticalSection(&This->renderer.csRenderLock);
762 if (This->renderer.filter.state != State_Paused)
764 if (This->renderer.filter.state == State_Stopped)
766 if (This->renderer.pInputPin->pin.pConnectedTo)
767 ResetEvent(This->renderer.evComplete);
768 This->renderer.pInputPin->end_of_stream = 0;
771 hr = IDirectSoundBuffer_Stop(This->dsbuffer);
772 if (SUCCEEDED(hr))
773 This->renderer.filter.state = State_Paused;
775 ResetEvent(This->blocked);
776 ResetEvent(This->renderer.RenderEvent);
778 ResetEvent(This->renderer.ThreadSignal);
779 LeaveCriticalSection(&This->renderer.csRenderLock);
781 return hr;
784 static const IBaseFilterVtbl DSoundRender_Vtbl =
786 DSoundRender_QueryInterface,
787 BaseFilterImpl_AddRef,
788 DSoundRender_Release,
789 BaseFilterImpl_GetClassID,
790 BaseRendererImpl_Stop,
791 DSoundRender_Pause,
792 BaseRendererImpl_Run,
793 BaseRendererImpl_GetState,
794 BaseRendererImpl_SetSyncSource,
795 BaseFilterImpl_GetSyncSource,
796 BaseFilterImpl_EnumPins,
797 BaseRendererImpl_FindPin,
798 BaseFilterImpl_QueryFilterInfo,
799 BaseFilterImpl_JoinFilterGraph,
800 BaseFilterImpl_QueryVendorInfo
803 /*** IUnknown methods ***/
804 static HRESULT WINAPI Basicaudio_QueryInterface(IBasicAudio *iface,
805 REFIID riid,
806 LPVOID*ppvObj) {
807 DSoundRenderImpl *This = impl_from_IBasicAudio(iface);
809 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
811 return DSoundRender_QueryInterface(&This->renderer.filter.IBaseFilter_iface, riid, ppvObj);
814 static ULONG WINAPI Basicaudio_AddRef(IBasicAudio *iface) {
815 DSoundRenderImpl *This = impl_from_IBasicAudio(iface);
817 TRACE("(%p/%p)->()\n", This, iface);
819 return BaseFilterImpl_AddRef(&This->renderer.filter.IBaseFilter_iface);
822 static ULONG WINAPI Basicaudio_Release(IBasicAudio *iface) {
823 DSoundRenderImpl *This = impl_from_IBasicAudio(iface);
825 TRACE("(%p/%p)->()\n", This, iface);
827 return DSoundRender_Release(&This->renderer.filter.IBaseFilter_iface);
830 /*** IBasicAudio methods ***/
831 static HRESULT WINAPI Basicaudio_put_Volume(IBasicAudio *iface,
832 LONG lVolume) {
833 DSoundRenderImpl *This = impl_from_IBasicAudio(iface);
835 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
837 if (lVolume > DSBVOLUME_MAX || lVolume < DSBVOLUME_MIN)
838 return E_INVALIDARG;
840 if (This->dsbuffer) {
841 if (FAILED(IDirectSoundBuffer_SetVolume(This->dsbuffer, lVolume)))
842 return E_FAIL;
845 This->volume = lVolume;
846 return S_OK;
849 static HRESULT WINAPI Basicaudio_get_Volume(IBasicAudio *iface,
850 LONG *plVolume) {
851 DSoundRenderImpl *This = impl_from_IBasicAudio(iface);
853 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
855 if (!plVolume)
856 return E_POINTER;
858 *plVolume = This->volume;
859 return S_OK;
862 static HRESULT WINAPI Basicaudio_put_Balance(IBasicAudio *iface,
863 LONG lBalance) {
864 DSoundRenderImpl *This = impl_from_IBasicAudio(iface);
866 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
868 if (lBalance < DSBPAN_LEFT || lBalance > DSBPAN_RIGHT)
869 return E_INVALIDARG;
871 if (This->dsbuffer) {
872 if (FAILED(IDirectSoundBuffer_SetPan(This->dsbuffer, lBalance)))
873 return E_FAIL;
876 This->pan = lBalance;
877 return S_OK;
880 static HRESULT WINAPI Basicaudio_get_Balance(IBasicAudio *iface,
881 LONG *plBalance) {
882 DSoundRenderImpl *This = impl_from_IBasicAudio(iface);
884 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
886 if (!plBalance)
887 return E_POINTER;
889 *plBalance = This->pan;
890 return S_OK;
893 static const IBasicAudioVtbl IBasicAudio_Vtbl =
895 Basicaudio_QueryInterface,
896 Basicaudio_AddRef,
897 Basicaudio_Release,
898 BasicAudioImpl_GetTypeInfoCount,
899 BasicAudioImpl_GetTypeInfo,
900 BasicAudioImpl_GetIDsOfNames,
901 BasicAudioImpl_Invoke,
902 Basicaudio_put_Volume,
903 Basicaudio_get_Volume,
904 Basicaudio_put_Balance,
905 Basicaudio_get_Balance
908 struct dsoundrender_timer {
909 struct dsoundrender_timer *next;
910 REFERENCE_TIME start;
911 REFERENCE_TIME periodicity;
912 HANDLE handle;
913 DWORD cookie;
915 static LONG cookie_counter = 1;
917 static DWORD WINAPI DSoundAdviseThread(LPVOID lpParam) {
918 DSoundRenderImpl *This = lpParam;
919 struct dsoundrender_timer head = {NULL};
920 MSG msg;
922 TRACE("(%p): Main Loop\n", This);
924 PeekMessageW(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
925 SetEvent(This->thread_wait);
927 while (1)
929 HRESULT hr;
930 REFERENCE_TIME curtime = 0;
931 BOOL ret;
932 struct dsoundrender_timer *prev = &head, *cur;
934 hr = IReferenceClock_GetTime(&This->IReferenceClock_iface, &curtime);
935 if (SUCCEEDED(hr)) {
936 TRACE("Time: %s\n", wine_dbgstr_longlong(curtime));
937 while (prev->next) {
938 cur = prev->next;
939 if (cur->start > curtime) {
940 TRACE("Skipping %p\n", cur);
941 prev = cur;
942 } else if (cur->periodicity) {
943 while (cur->start <= curtime) {
944 cur->start += cur->periodicity;
945 ReleaseSemaphore(cur->handle, 1, NULL);
947 prev = cur;
948 } else {
949 struct dsoundrender_timer *next = cur->next;
950 TRACE("Firing %p %s < %s\n", cur, wine_dbgstr_longlong(cur->start), wine_dbgstr_longlong(curtime));
951 SetEvent(cur->handle);
952 HeapFree(GetProcessHeap(), 0, cur);
953 prev->next = next;
957 if (!head.next)
958 ret = GetMessageW(&msg, INVALID_HANDLE_VALUE, WM_APP, WM_APP + 4);
959 else
960 ret = PeekMessageW(&msg, INVALID_HANDLE_VALUE, WM_APP, WM_APP + 4, PM_REMOVE);
961 while (ret) {
962 switch (LOWORD(msg.message) - WM_APP) {
963 case 0: TRACE("Exiting\n"); return 0;
964 case 1:
965 case 2: {
966 struct dsoundrender_timer *t = (struct dsoundrender_timer *)msg.wParam;
967 if (LOWORD(msg.message) - WM_APP == 1)
968 TRACE("Adding one-shot timer %p\n", t);
969 else
970 TRACE("Adding periodic timer %p\n", t);
971 t->next = head.next;
972 head.next = t;
973 break;
975 case 3:
976 prev = &head;
977 while (prev->next) {
978 cur = prev->next;
979 if (cur->cookie == msg.wParam) {
980 struct dsoundrender_timer *next = cur->next;
981 HeapFree(GetProcessHeap(), 0, cur);
982 prev->next = next;
983 break;
985 prev = cur;
987 break;
989 ret = PeekMessageW(&msg, INVALID_HANDLE_VALUE, WM_APP, WM_APP + 4, PM_REMOVE);
991 MsgWaitForMultipleObjects(0, NULL, 5, QS_POSTMESSAGE, 0);
993 return 0;
996 /*** IUnknown methods ***/
997 static HRESULT WINAPI ReferenceClock_QueryInterface(IReferenceClock *iface,
998 REFIID riid,
999 LPVOID*ppvObj)
1001 DSoundRenderImpl *This = impl_from_IReferenceClock(iface);
1003 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
1005 return DSoundRender_QueryInterface(&This->renderer.filter.IBaseFilter_iface, riid, ppvObj);
1008 static ULONG WINAPI ReferenceClock_AddRef(IReferenceClock *iface)
1010 DSoundRenderImpl *This = impl_from_IReferenceClock(iface);
1012 TRACE("(%p/%p)->()\n", This, iface);
1014 return BaseFilterImpl_AddRef(&This->renderer.filter.IBaseFilter_iface);
1017 static ULONG WINAPI ReferenceClock_Release(IReferenceClock *iface)
1019 DSoundRenderImpl *This = impl_from_IReferenceClock(iface);
1021 TRACE("(%p/%p)->()\n", This, iface);
1023 return DSoundRender_Release(&This->renderer.filter.IBaseFilter_iface);
1026 /*** IReferenceClock methods ***/
1027 static HRESULT WINAPI ReferenceClock_GetTime(IReferenceClock *iface,
1028 REFERENCE_TIME *pTime)
1030 DSoundRenderImpl *This = impl_from_IReferenceClock(iface);
1031 HRESULT hr = E_FAIL;
1033 TRACE("(%p/%p)->(%p)\n", This, iface, pTime);
1034 if (!pTime)
1035 return E_POINTER;
1037 if (This->dsbuffer) {
1038 DWORD writepos1, writepos2;
1039 EnterCriticalSection(&This->renderer.filter.csFilter);
1040 DSoundRender_UpdatePositions(This, &writepos1, &writepos2);
1041 if (This->renderer.pInputPin && This->renderer.pInputPin->pin.mtCurrent.pbFormat)
1043 *pTime = This->play_time + time_from_pos(This, This->last_playpos);
1044 hr = S_OK;
1046 else
1048 ERR("pInputPin Disconnected\n");
1049 hr = E_FAIL;
1051 LeaveCriticalSection(&This->renderer.filter.csFilter);
1053 if (FAILED(hr))
1054 WARN("Could not get reference time (%x)!\n", hr);
1056 return hr;
1059 static HRESULT WINAPI ReferenceClock_AdviseTime(IReferenceClock *iface,
1060 REFERENCE_TIME rtBaseTime,
1061 REFERENCE_TIME rtStreamTime,
1062 HEVENT hEvent,
1063 DWORD_PTR *pdwAdviseCookie)
1065 DSoundRenderImpl *This = impl_from_IReferenceClock(iface);
1066 REFERENCE_TIME when = rtBaseTime + rtStreamTime;
1067 REFERENCE_TIME future;
1068 TRACE("(%p/%p)->(%s, %s, %p, %p)\n", This, iface, wine_dbgstr_longlong(rtBaseTime), wine_dbgstr_longlong(rtStreamTime), (void*)hEvent, pdwAdviseCookie);
1070 if (when <= 0)
1071 return E_INVALIDARG;
1073 if (!pdwAdviseCookie)
1074 return E_POINTER;
1076 EnterCriticalSection(&This->renderer.filter.csFilter);
1077 future = when - This->play_time;
1078 if (!This->threadid && This->dsbuffer) {
1079 This->thread_wait = CreateEventW(0, 0, 0, 0);
1080 This->advisethread = CreateThread(NULL, 0, DSoundAdviseThread, This, 0, &This->threadid);
1081 WaitForSingleObject(This->thread_wait, INFINITE);
1082 CloseHandle(This->thread_wait);
1084 LeaveCriticalSection(&This->renderer.filter.csFilter);
1085 /* If it's in the past or the next millisecond, trigger immediately */
1086 if (future <= 10000) {
1087 SetEvent((HANDLE)hEvent);
1088 *pdwAdviseCookie = 0;
1089 } else {
1090 struct dsoundrender_timer *t = HeapAlloc(GetProcessHeap(), 0, sizeof(*t));
1091 t->next = NULL;
1092 t->start = when;
1093 t->periodicity = 0;
1094 t->handle = (HANDLE)hEvent;
1095 t->cookie = InterlockedIncrement(&cookie_counter);
1096 PostThreadMessageW(This->threadid, WM_APP+1, (WPARAM)t, 0);
1097 *pdwAdviseCookie = t->cookie;
1100 return S_OK;
1103 static HRESULT WINAPI ReferenceClock_AdvisePeriodic(IReferenceClock *iface,
1104 REFERENCE_TIME rtStartTime,
1105 REFERENCE_TIME rtPeriodTime,
1106 HSEMAPHORE hSemaphore,
1107 DWORD_PTR *pdwAdviseCookie)
1109 DSoundRenderImpl *This = impl_from_IReferenceClock(iface);
1110 struct dsoundrender_timer *t;
1112 TRACE("(%p/%p)->(%s, %s, %p, %p)\n", This, iface, wine_dbgstr_longlong(rtStartTime), wine_dbgstr_longlong(rtPeriodTime), (void*)hSemaphore, pdwAdviseCookie);
1114 if (rtStartTime <= 0 || rtPeriodTime <= 0)
1115 return E_INVALIDARG;
1117 if (!pdwAdviseCookie)
1118 return E_POINTER;
1120 EnterCriticalSection(&This->renderer.filter.csFilter);
1121 if (!This->threadid && This->dsbuffer) {
1122 This->thread_wait = CreateEventW(0, 0, 0, 0);
1123 This->advisethread = CreateThread(NULL, 0, DSoundAdviseThread, This, 0, &This->threadid);
1124 WaitForSingleObject(This->thread_wait, INFINITE);
1125 CloseHandle(This->thread_wait);
1127 LeaveCriticalSection(&This->renderer.filter.csFilter);
1129 t = HeapAlloc(GetProcessHeap(), 0, sizeof(*t));
1130 t->next = NULL;
1131 t->start = rtStartTime;
1132 t->periodicity = rtPeriodTime;
1133 t->handle = (HANDLE)hSemaphore;
1134 t->cookie = InterlockedIncrement(&cookie_counter);
1135 PostThreadMessageW(This->threadid, WM_APP+1, (WPARAM)t, 0);
1136 *pdwAdviseCookie = t->cookie;
1138 return S_OK;
1141 static HRESULT WINAPI ReferenceClock_Unadvise(IReferenceClock *iface,
1142 DWORD_PTR dwAdviseCookie)
1144 DSoundRenderImpl *This = impl_from_IReferenceClock(iface);
1146 TRACE("(%p/%p)->(%p)\n", This, iface, (void*)dwAdviseCookie);
1147 if (!This->advisethread || !dwAdviseCookie)
1148 return S_FALSE;
1149 PostThreadMessageW(This->threadid, WM_APP+3, dwAdviseCookie, 0);
1150 return S_OK;
1153 static const IReferenceClockVtbl IReferenceClock_Vtbl =
1155 ReferenceClock_QueryInterface,
1156 ReferenceClock_AddRef,
1157 ReferenceClock_Release,
1158 ReferenceClock_GetTime,
1159 ReferenceClock_AdviseTime,
1160 ReferenceClock_AdvisePeriodic,
1161 ReferenceClock_Unadvise
1164 /*** IUnknown methods ***/
1165 static HRESULT WINAPI AMDirectSound_QueryInterface(IAMDirectSound *iface,
1166 REFIID riid,
1167 LPVOID*ppvObj)
1169 DSoundRenderImpl *This = impl_from_IAMDirectSound(iface);
1171 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
1173 return DSoundRender_QueryInterface(&This->renderer.filter.IBaseFilter_iface, riid, ppvObj);
1176 static ULONG WINAPI AMDirectSound_AddRef(IAMDirectSound *iface)
1178 DSoundRenderImpl *This = impl_from_IAMDirectSound(iface);
1180 TRACE("(%p/%p)->()\n", This, iface);
1182 return BaseFilterImpl_AddRef(&This->renderer.filter.IBaseFilter_iface);
1185 static ULONG WINAPI AMDirectSound_Release(IAMDirectSound *iface)
1187 DSoundRenderImpl *This = impl_from_IAMDirectSound(iface);
1189 TRACE("(%p/%p)->()\n", This, iface);
1191 return DSoundRender_Release(&This->renderer.filter.IBaseFilter_iface);
1194 /*** IAMDirectSound methods ***/
1195 static HRESULT WINAPI AMDirectSound_GetDirectSoundInterface(IAMDirectSound *iface, IDirectSound **ds)
1197 DSoundRenderImpl *This = impl_from_IAMDirectSound(iface);
1199 FIXME("(%p/%p)->(%p): stub\n", This, iface, ds);
1201 return E_NOTIMPL;
1204 static HRESULT WINAPI AMDirectSound_GetPrimaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer **buf)
1206 DSoundRenderImpl *This = impl_from_IAMDirectSound(iface);
1208 FIXME("(%p/%p)->(%p): stub\n", This, iface, buf);
1210 return E_NOTIMPL;
1213 static HRESULT WINAPI AMDirectSound_GetSecondaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer **buf)
1215 DSoundRenderImpl *This = impl_from_IAMDirectSound(iface);
1217 FIXME("(%p/%p)->(%p): stub\n", This, iface, buf);
1219 return E_NOTIMPL;
1222 static HRESULT WINAPI AMDirectSound_ReleaseDirectSoundInterface(IAMDirectSound *iface, IDirectSound *ds)
1224 DSoundRenderImpl *This = impl_from_IAMDirectSound(iface);
1226 FIXME("(%p/%p)->(%p): stub\n", This, iface, ds);
1228 return E_NOTIMPL;
1231 static HRESULT WINAPI AMDirectSound_ReleasePrimaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer *buf)
1233 DSoundRenderImpl *This = impl_from_IAMDirectSound(iface);
1235 FIXME("(%p/%p)->(%p): stub\n", This, iface, buf);
1237 return E_NOTIMPL;
1240 static HRESULT WINAPI AMDirectSound_ReleaseSecondaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer *buf)
1242 DSoundRenderImpl *This = impl_from_IAMDirectSound(iface);
1244 FIXME("(%p/%p)->(%p): stub\n", This, iface, buf);
1246 return E_NOTIMPL;
1249 static HRESULT WINAPI AMDirectSound_SetFocusWindow(IAMDirectSound *iface, HWND hwnd, BOOL bgaudible)
1251 DSoundRenderImpl *This = impl_from_IAMDirectSound(iface);
1253 FIXME("(%p/%p)->(%p,%d): stub\n", This, iface, hwnd, bgaudible);
1255 return E_NOTIMPL;
1258 static HRESULT WINAPI AMDirectSound_GetFocusWindow(IAMDirectSound *iface, HWND *hwnd, BOOL *bgaudible)
1260 DSoundRenderImpl *This = impl_from_IAMDirectSound(iface);
1262 FIXME("(%p/%p)->(%p,%p): stub\n", This, iface, hwnd, bgaudible);
1264 return E_NOTIMPL;
1267 static const IAMDirectSoundVtbl IAMDirectSound_Vtbl =
1269 AMDirectSound_QueryInterface,
1270 AMDirectSound_AddRef,
1271 AMDirectSound_Release,
1272 AMDirectSound_GetDirectSoundInterface,
1273 AMDirectSound_GetPrimaryBufferInterface,
1274 AMDirectSound_GetSecondaryBufferInterface,
1275 AMDirectSound_ReleaseDirectSoundInterface,
1276 AMDirectSound_ReleasePrimaryBufferInterface,
1277 AMDirectSound_ReleaseSecondaryBufferInterface,
1278 AMDirectSound_SetFocusWindow,
1279 AMDirectSound_GetFocusWindow
1282 static HRESULT WINAPI AMFilterMiscFlags_QueryInterface(IAMFilterMiscFlags *iface, REFIID riid, void **ppv) {
1283 DSoundRenderImpl *This = impl_from_IAMFilterMiscFlags(iface);
1284 return IBaseFilter_QueryInterface(&This->renderer.filter.IBaseFilter_iface, riid, ppv);
1287 static ULONG WINAPI AMFilterMiscFlags_AddRef(IAMFilterMiscFlags *iface) {
1288 DSoundRenderImpl *This = impl_from_IAMFilterMiscFlags(iface);
1289 return IBaseFilter_AddRef(&This->renderer.filter.IBaseFilter_iface);
1292 static ULONG WINAPI AMFilterMiscFlags_Release(IAMFilterMiscFlags *iface) {
1293 DSoundRenderImpl *This = impl_from_IAMFilterMiscFlags(iface);
1294 return IBaseFilter_Release(&This->renderer.filter.IBaseFilter_iface);
1297 static ULONG WINAPI AMFilterMiscFlags_GetMiscFlags(IAMFilterMiscFlags *iface) {
1298 return AM_FILTER_MISC_FLAGS_IS_RENDERER;
1301 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl = {
1302 AMFilterMiscFlags_QueryInterface,
1303 AMFilterMiscFlags_AddRef,
1304 AMFilterMiscFlags_Release,
1305 AMFilterMiscFlags_GetMiscFlags