qcap: Add DebugInfo to critical sections.
[wine] / dlls / quartz / dsoundrender.c
1 /*
2  * Direct Sound Audio Renderer
3  *
4  * Copyright 2004 Christian Costa
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include "quartz_private.h"
24 #include "control_private.h"
25 #include "pin.h"
26
27 #include "uuids.h"
28 #include "mmreg.h"
29 #include "vfwmsgs.h"
30 #include "fourcc.h"
31 #include "windef.h"
32 #include "winbase.h"
33 #include "dshow.h"
34 #include "evcode.h"
35 #include "strmif.h"
36 #include "dsound.h"
37
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
42
43 static const WCHAR wcsInputPinName[] = {'i','n','p','u','t',' ','p','i','n',0};
44
45 static const IBaseFilterVtbl DSoundRender_Vtbl;
46 static const IPinVtbl DSoundRender_InputPin_Vtbl;
47 static const IMemInputPinVtbl MemInputPin_Vtbl; 
48 static const IBasicAudioVtbl IBasicAudio_Vtbl;
49
50 typedef struct DSoundRenderImpl
51 {
52     const IBaseFilterVtbl * lpVtbl;
53     const IBasicAudioVtbl *IBasicAudio_vtbl;
54
55     LONG refCount;
56     CRITICAL_SECTION csFilter;
57     FILTER_STATE state;
58     REFERENCE_TIME rtStreamStart;
59     IReferenceClock * pClock;
60     FILTER_INFO filterInfo;
61
62     InputPin * pInputPin;
63     IPin ** ppPins;
64
65     LPDIRECTSOUND dsound;
66     LPDIRECTSOUNDBUFFER dsbuffer;
67     DWORD write_pos;
68     BOOL init;
69     BOOL started;
70 } DSoundRenderImpl;
71
72 static HRESULT DSoundRender_InputPin_Construct(const PIN_INFO * pPinInfo, SAMPLEPROC pSampleProc, LPVOID pUserData, QUERYACCEPTPROC pQueryAccept, LPCRITICAL_SECTION pCritSec, IPin ** ppPin)
73 {
74     InputPin * pPinImpl;
75
76     *ppPin = NULL;
77
78     if (pPinInfo->dir != PINDIR_INPUT)
79     {
80         ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo->dir);
81         return E_INVALIDARG;
82     }
83
84     pPinImpl = CoTaskMemAlloc(sizeof(*pPinImpl));
85
86     if (!pPinImpl)
87         return E_OUTOFMEMORY;
88
89     if (SUCCEEDED(InputPin_Init(pPinInfo, pSampleProc, pUserData, pQueryAccept, pCritSec, pPinImpl)))
90     {
91         pPinImpl->pin.lpVtbl = &DSoundRender_InputPin_Vtbl;
92         pPinImpl->lpVtblMemInput = &MemInputPin_Vtbl;
93         
94         *ppPin = (IPin *)(&pPinImpl->pin.lpVtbl);
95         return S_OK;
96     }
97     return E_FAIL;
98 }
99
100
101 #define DSBUFFERSIZE 8192
102
103 static HRESULT DSoundRender_CreateSoundBuffer(IBaseFilter * iface)
104 {
105     HRESULT hr;
106     WAVEFORMATEX wav_fmt;
107     AM_MEDIA_TYPE amt;
108     WAVEFORMATEX* format;
109     DSBUFFERDESC buf_desc;
110     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
111
112     hr = IPin_ConnectionMediaType(This->ppPins[0], &amt);
113     if (FAILED(hr)) {
114         ERR("Unable to retrieve media type\n");
115         return hr;
116     }
117
118     TRACE("MajorType %s\n", debugstr_guid(&amt.majortype));
119     TRACE("SubType %s\n", debugstr_guid(&amt.subtype));
120     TRACE("Format %s\n", debugstr_guid(&amt.formattype));
121     TRACE("Size %d\n", amt.cbFormat);
122
123     dump_AM_MEDIA_TYPE(&amt);
124     
125     format = (WAVEFORMATEX*)amt.pbFormat;
126     TRACE("wFormatTag = %x %x\n", format->wFormatTag, WAVE_FORMAT_PCM);
127     TRACE("nChannels = %d\n", format->nChannels);
128     TRACE("nSamplesPerSec = %u\n", format->nSamplesPerSec);
129     TRACE("nAvgBytesPerSec = %u\n", format->nAvgBytesPerSec);
130     TRACE("nBlockAlign = %d\n", format->nBlockAlign);
131     TRACE("wBitsPerSample = %d\n", format->wBitsPerSample);
132     TRACE("cbSize = %d\n", format->cbSize);
133     
134     hr = DirectSoundCreate(NULL, &This->dsound, NULL);
135     if (FAILED(hr)) {
136         ERR("Cannot create Direct Sound object\n");
137         return hr;
138     }
139
140     wav_fmt = *format;
141     wav_fmt.cbSize = 0;
142
143     memset(&buf_desc,0,sizeof(DSBUFFERDESC));
144     buf_desc.dwSize = sizeof(DSBUFFERDESC);
145     buf_desc.dwBufferBytes = DSBUFFERSIZE;
146     buf_desc.lpwfxFormat = &wav_fmt;
147     hr = IDirectSound_CreateSoundBuffer(This->dsound, &buf_desc, &This->dsbuffer, NULL);
148     if (FAILED(hr)) {
149         ERR("Can't create sound buffer !\n");
150         IDirectSound_Release(This->dsound);
151         return hr;
152     }
153
154     This->write_pos = 0;
155     
156     return hr;
157 }
158
159 static HRESULT DSoundRender_SendSampleData(DSoundRenderImpl* This, LPBYTE data, DWORD size)
160 {
161     HRESULT hr;
162     LPBYTE lpbuf1 = NULL;
163     LPBYTE lpbuf2 = NULL;
164     DWORD dwsize1 = 0;
165     DWORD dwsize2 = 0;
166     DWORD size2;
167     DWORD play_pos,buf_free;
168
169     while (1)
170     {
171         hr = IDirectSoundBuffer_GetCurrentPosition(This->dsbuffer, &play_pos, NULL);
172         if (hr != DS_OK)
173         {
174             ERR("Error GetCurrentPosition: %x\n", hr);
175             break;
176         }
177         if (This->write_pos < play_pos)
178              buf_free = play_pos-This->write_pos;
179         else
180              buf_free = DSBUFFERSIZE - This->write_pos + play_pos;
181
182         /* This situation is ambiguous; Assume full when playing */
183         if(buf_free == DSBUFFERSIZE && This->started)
184         {
185             Sleep(10);
186             continue;
187         }
188
189         size2 = min(buf_free, size);
190         hr = IDirectSoundBuffer_Lock(This->dsbuffer, This->write_pos, size2, (LPVOID *)&lpbuf1, &dwsize1, (LPVOID *)&lpbuf2, &dwsize2, 0);
191         if (hr != DS_OK) {
192             ERR("Unable to lock sound buffer! (%x)\n", hr);
193             break;
194         }
195         /* TRACE("write_pos=%d, size=%d, sz1=%d, sz2=%d\n", This->write_pos, size2, dwsize1, dwsize2); */
196
197         memcpy(lpbuf1, data, dwsize1);
198         if (dwsize2)
199             memcpy(lpbuf2, data + dwsize1, dwsize2);
200
201         hr = IDirectSoundBuffer_Unlock(This->dsbuffer, lpbuf1, dwsize1, lpbuf2, dwsize2);
202         if (hr != DS_OK)
203             ERR("Unable to unlock sound buffer! (%x)\n", hr);
204         if (!This->started)
205         {
206             hr = IDirectSoundBuffer_Play(This->dsbuffer, 0, 0, DSBPLAY_LOOPING);
207             if (hr == DS_OK)
208                 This->started = TRUE;
209             else
210                 ERR("Can't start playing! (%x)\n", hr);
211         }
212         size -= dwsize1 + dwsize2;
213         data += dwsize1 + dwsize2;
214         This->write_pos = (This->write_pos + dwsize1 + dwsize2) % DSBUFFERSIZE;
215
216         if (!size)
217             break;
218         Sleep(10);
219     }
220
221     return hr;
222 }
223
224 static HRESULT DSoundRender_Sample(LPVOID iface, IMediaSample * pSample)
225 {
226     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
227     LPBYTE pbSrcStream = NULL;
228     long cbSrcStream = 0;
229     REFERENCE_TIME tStart, tStop;
230     HRESULT hr;
231
232     TRACE("%p %p\n", iface, pSample);
233
234     if (This->state != State_Running)
235         return VFW_E_WRONG_STATE;
236     
237     hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
238     if (FAILED(hr))
239     {
240         ERR("Cannot get pointer to sample data (%x)\n", hr);
241         return hr;
242     }
243
244     hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
245     if (FAILED(hr))
246         ERR("Cannot get sample time (%x)\n", hr);
247
248     cbSrcStream = IMediaSample_GetActualDataLength(pSample);
249
250     TRACE("Sample data ptr = %p, size = %ld\n", pbSrcStream, cbSrcStream);
251
252 #if 0 /* For debugging purpose */
253     {
254         int i;
255         for(i = 0; i < cbSrcStream; i++)
256         {
257             if ((i!=0) && !(i%16))
258                 TRACE("\n");
259             TRACE("%02x ", pbSrcStream[i]);
260         }
261         TRACE("\n");
262     }
263 #endif
264   
265     if (!This->init)
266     {
267         hr = DSoundRender_CreateSoundBuffer(iface);
268         if (SUCCEEDED(hr))
269             This->init = TRUE;
270         else
271         {
272             ERR("Unable to create DSound buffer\n");
273             return hr;
274         }
275     }
276     
277     hr = DSoundRender_SendSampleData(This, pbSrcStream, cbSrcStream);
278
279     return hr;
280 }
281
282 static HRESULT DSoundRender_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
283 {
284     WAVEFORMATEX* format = (WAVEFORMATEX*)pmt->pbFormat;
285     TRACE("wFormatTag = %x %x\n", format->wFormatTag, WAVE_FORMAT_PCM);
286     TRACE("nChannels = %d\n", format->nChannels);
287     TRACE("nSamplesPerSec = %d\n", format->nAvgBytesPerSec);
288     TRACE("nAvgBytesPerSec = %d\n", format->nAvgBytesPerSec);
289     TRACE("nBlockAlign = %d\n", format->nBlockAlign);
290     TRACE("wBitsPerSample = %d\n", format->wBitsPerSample);
291
292     if (IsEqualIID(&pmt->majortype, &MEDIATYPE_Audio) && IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_PCM))
293         return S_OK;
294     return S_FALSE;
295 }
296
297 HRESULT DSoundRender_create(IUnknown * pUnkOuter, LPVOID * ppv)
298 {
299     HRESULT hr;
300     PIN_INFO piInput;
301     DSoundRenderImpl * pDSoundRender;
302
303     TRACE("(%p, %p)\n", pUnkOuter, ppv);
304
305     *ppv = NULL;
306
307     if (pUnkOuter)
308         return CLASS_E_NOAGGREGATION;
309     
310     pDSoundRender = CoTaskMemAlloc(sizeof(DSoundRenderImpl));
311     if (!pDSoundRender)
312         return E_OUTOFMEMORY;
313     ZeroMemory(pDSoundRender, sizeof(DSoundRenderImpl));
314
315     pDSoundRender->lpVtbl = &DSoundRender_Vtbl;
316     pDSoundRender->IBasicAudio_vtbl = &IBasicAudio_Vtbl;
317     pDSoundRender->refCount = 1;
318     InitializeCriticalSection(&pDSoundRender->csFilter);
319     pDSoundRender->state = State_Stopped;
320
321     pDSoundRender->ppPins = CoTaskMemAlloc(1 * sizeof(IPin *));
322     if (!pDSoundRender->ppPins)
323     {
324         DeleteCriticalSection(&pDSoundRender->csFilter);
325         CoTaskMemFree(pDSoundRender);
326         return E_OUTOFMEMORY;
327     }
328
329     /* construct input pin */
330     piInput.dir = PINDIR_INPUT;
331     piInput.pFilter = (IBaseFilter *)pDSoundRender;
332     lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
333     hr = DSoundRender_InputPin_Construct(&piInput, DSoundRender_Sample, (LPVOID)pDSoundRender, DSoundRender_QueryAccept, &pDSoundRender->csFilter, (IPin **)&pDSoundRender->pInputPin);
334
335     if (SUCCEEDED(hr))
336     {
337         pDSoundRender->ppPins[0] = (IPin *)pDSoundRender->pInputPin;
338         *ppv = (LPVOID)pDSoundRender;
339     }
340     else
341     {
342         CoTaskMemFree(pDSoundRender->ppPins);
343         DeleteCriticalSection(&pDSoundRender->csFilter);
344         CoTaskMemFree(pDSoundRender);
345     }
346
347     return hr;
348 }
349
350 static HRESULT WINAPI DSoundRender_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
351 {
352     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
353     TRACE("(%p, %p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
354
355     *ppv = NULL;
356
357     if (IsEqualIID(riid, &IID_IUnknown))
358         *ppv = (LPVOID)This;
359     else if (IsEqualIID(riid, &IID_IPersist))
360         *ppv = (LPVOID)This;
361     else if (IsEqualIID(riid, &IID_IMediaFilter))
362         *ppv = (LPVOID)This;
363     else if (IsEqualIID(riid, &IID_IBaseFilter))
364         *ppv = (LPVOID)This;
365     else if (IsEqualIID(riid, &IID_IBasicAudio))
366         *ppv = (LPVOID)&(This->IBasicAudio_vtbl);
367
368     if (*ppv)
369     {
370         IUnknown_AddRef((IUnknown *)(*ppv));
371         return S_OK;
372     }
373
374     FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
375
376     return E_NOINTERFACE;
377 }
378
379 static ULONG WINAPI DSoundRender_AddRef(IBaseFilter * iface)
380 {
381     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
382     ULONG refCount = InterlockedIncrement(&This->refCount);
383
384     TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
385
386     return refCount;
387 }
388
389 static ULONG WINAPI DSoundRender_Release(IBaseFilter * iface)
390 {
391     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
392     ULONG refCount = InterlockedDecrement(&This->refCount);
393
394     TRACE("(%p)->() Release from %d\n", This, refCount + 1);
395
396     if (!refCount)
397     {
398         DeleteCriticalSection(&This->csFilter);
399         if (This->pClock)
400             IReferenceClock_Release(This->pClock);
401
402         if (This->dsbuffer)
403             IDirectSoundBuffer_Release(This->dsbuffer);
404         This->dsbuffer = NULL;
405         if (This->dsound)
406             IDirectSound_Release(This->dsound);
407         This->dsound = NULL;
408        
409         IPin_Release(This->ppPins[0]);
410         
411         CoTaskMemFree(This->ppPins);
412         This->lpVtbl = NULL;
413         This->IBasicAudio_vtbl = NULL;
414         
415         TRACE("Destroying Audio Renderer\n");
416         CoTaskMemFree(This);
417         
418         return 0;
419     }
420     else
421         return refCount;
422 }
423
424 /** IPersist methods **/
425
426 static HRESULT WINAPI DSoundRender_GetClassID(IBaseFilter * iface, CLSID * pClsid)
427 {
428     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
429     TRACE("(%p/%p)->(%p)\n", This, iface, pClsid);
430
431     *pClsid = CLSID_DSoundRender;
432
433     return S_OK;
434 }
435
436 /** IMediaFilter methods **/
437
438 static HRESULT WINAPI DSoundRender_Stop(IBaseFilter * iface)
439 {
440     HRESULT hr = S_OK;
441     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
442
443     TRACE("(%p/%p)->()\n", This, iface);
444
445     EnterCriticalSection(&This->csFilter);
446     {
447         DWORD state = 0;
448         if (This->dsbuffer)
449         {
450             hr = IDirectSoundBuffer_GetStatus(This->dsbuffer, &state);
451             if (SUCCEEDED(hr))
452             {
453                 if (state & DSBSTATUS_PLAYING)
454                     hr = IDirectSoundBuffer_Stop(This->dsbuffer);
455             }
456         }
457         if (SUCCEEDED(hr))
458         {
459             This->started = FALSE;
460             This->state = State_Stopped;
461         }
462     }
463     LeaveCriticalSection(&This->csFilter);
464     
465     return hr;
466 }
467
468 static HRESULT WINAPI DSoundRender_Pause(IBaseFilter * iface)
469 {
470     HRESULT hr = S_OK;
471     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
472     
473     TRACE("(%p/%p)->()\n", This, iface);
474
475     EnterCriticalSection(&This->csFilter);
476     {
477         DWORD state = 0;
478         if (This->dsbuffer)
479         {
480             hr = IDirectSoundBuffer_GetStatus(This->dsbuffer, &state);
481             if (SUCCEEDED(hr))
482             {
483                 if (state & DSBSTATUS_PLAYING)
484                     hr = IDirectSoundBuffer_Stop(This->dsbuffer);
485             }
486         }
487         if (SUCCEEDED(hr))
488         {
489             This->started = FALSE;
490             This->state = State_Paused;
491         }
492     }
493     LeaveCriticalSection(&This->csFilter);
494
495     return hr;
496 }
497
498 static HRESULT WINAPI DSoundRender_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
499 {
500     HRESULT hr = S_OK;
501     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
502
503     TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
504
505     EnterCriticalSection(&This->csFilter);
506     {
507         This->rtStreamStart = tStart;
508         This->state = State_Running;
509     }
510     LeaveCriticalSection(&This->csFilter);
511
512     return hr;
513 }
514
515 static HRESULT WINAPI DSoundRender_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
516 {
517     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
518
519     TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
520
521     EnterCriticalSection(&This->csFilter);
522     {
523         *pState = This->state;
524     }
525     LeaveCriticalSection(&This->csFilter);
526
527     return S_OK;
528 }
529
530 static HRESULT WINAPI DSoundRender_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
531 {
532     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
533
534     TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
535
536     EnterCriticalSection(&This->csFilter);
537     {
538         if (This->pClock)
539             IReferenceClock_Release(This->pClock);
540         This->pClock = pClock;
541         if (This->pClock)
542             IReferenceClock_AddRef(This->pClock);
543     }
544     LeaveCriticalSection(&This->csFilter);
545
546     return S_OK;
547 }
548
549 static HRESULT WINAPI DSoundRender_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
550 {
551     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
552
553     TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
554
555     EnterCriticalSection(&This->csFilter);
556     {
557         *ppClock = This->pClock;
558         IReferenceClock_AddRef(This->pClock);
559     }
560     LeaveCriticalSection(&This->csFilter);
561     
562     return S_OK;
563 }
564
565 /** IBaseFilter implementation **/
566
567 static HRESULT WINAPI DSoundRender_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
568 {
569     ENUMPINDETAILS epd;
570     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
571
572     TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
573
574     epd.cPins = 1; /* input pin */
575     epd.ppPins = This->ppPins;
576     return IEnumPinsImpl_Construct(&epd, ppEnum);
577 }
578
579 static HRESULT WINAPI DSoundRender_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
580 {
581     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
582
583     TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_w(Id), ppPin);
584     
585     FIXME("DSoundRender::FindPin(...)\n");
586
587     /* FIXME: critical section */
588
589     return E_NOTIMPL;
590 }
591
592 static HRESULT WINAPI DSoundRender_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
593 {
594     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
595
596     TRACE("(%p/%p)->(%p)\n", This, iface, pInfo);
597
598     strcpyW(pInfo->achName, This->filterInfo.achName);
599     pInfo->pGraph = This->filterInfo.pGraph;
600
601     if (pInfo->pGraph)
602         IFilterGraph_AddRef(pInfo->pGraph);
603     
604     return S_OK;
605 }
606
607 static HRESULT WINAPI DSoundRender_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
608 {
609     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
610
611     TRACE("(%p/%p)->(%p, %s)\n", This, iface, pGraph, debugstr_w(pName));
612
613     EnterCriticalSection(&This->csFilter);
614     {
615         if (pName)
616             strcpyW(This->filterInfo.achName, pName);
617         else
618             *This->filterInfo.achName = '\0';
619         This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
620     }
621     LeaveCriticalSection(&This->csFilter);
622
623     return S_OK;
624 }
625
626 static HRESULT WINAPI DSoundRender_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
627 {
628     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
629     TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
630     return E_NOTIMPL;
631 }
632
633 static const IBaseFilterVtbl DSoundRender_Vtbl =
634 {
635     DSoundRender_QueryInterface,
636     DSoundRender_AddRef,
637     DSoundRender_Release,
638     DSoundRender_GetClassID,
639     DSoundRender_Stop,
640     DSoundRender_Pause,
641     DSoundRender_Run,
642     DSoundRender_GetState,
643     DSoundRender_SetSyncSource,
644     DSoundRender_GetSyncSource,
645     DSoundRender_EnumPins,
646     DSoundRender_FindPin,
647     DSoundRender_QueryFilterInfo,
648     DSoundRender_JoinFilterGraph,
649     DSoundRender_QueryVendorInfo
650 };
651
652 static HRESULT WINAPI DSoundRender_InputPin_EndOfStream(IPin * iface)
653 {
654     InputPin* This = (InputPin*)iface;
655     IMediaEventSink* pEventSink;
656     HRESULT hr;
657
658     TRACE("(%p/%p)->()\n", This, iface);
659
660     hr = IFilterGraph_QueryInterface(((DSoundRenderImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
661     if (SUCCEEDED(hr))
662     {
663         /* FIXME: We should wait that all audio data has been played */
664         hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
665         IMediaEventSink_Release(pEventSink);
666     }
667
668     return hr;
669 }
670
671 static const IPinVtbl DSoundRender_InputPin_Vtbl = 
672 {
673     InputPin_QueryInterface,
674     IPinImpl_AddRef,
675     InputPin_Release,
676     InputPin_Connect,
677     InputPin_ReceiveConnection,
678     IPinImpl_Disconnect,
679     IPinImpl_ConnectedTo,
680     IPinImpl_ConnectionMediaType,
681     IPinImpl_QueryPinInfo,
682     IPinImpl_QueryDirection,
683     IPinImpl_QueryId,
684     IPinImpl_QueryAccept,
685     IPinImpl_EnumMediaTypes,
686     IPinImpl_QueryInternalConnections,
687     DSoundRender_InputPin_EndOfStream,
688     InputPin_BeginFlush,
689     InputPin_EndFlush,
690     InputPin_NewSegment
691 };
692
693 static const IMemInputPinVtbl MemInputPin_Vtbl = 
694 {
695     MemInputPin_QueryInterface,
696     MemInputPin_AddRef,
697     MemInputPin_Release,
698     MemInputPin_GetAllocator,
699     MemInputPin_NotifyAllocator,
700     MemInputPin_GetAllocatorRequirements,
701     MemInputPin_Receive,
702     MemInputPin_ReceiveMultiple,
703     MemInputPin_ReceiveCanBlock
704 };
705
706 /*** IUnknown methods ***/
707 static HRESULT WINAPI Basicaudio_QueryInterface(IBasicAudio *iface,
708                                                 REFIID riid,
709                                                 LPVOID*ppvObj) {
710     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
711
712     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
713
714     return DSoundRender_QueryInterface((IBaseFilter*)This, riid, ppvObj);
715 }
716
717 static ULONG WINAPI Basicaudio_AddRef(IBasicAudio *iface) {
718     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
719
720     TRACE("(%p/%p)->()\n", This, iface);
721
722     return DSoundRender_AddRef((IBaseFilter*)This);
723 }
724
725 static ULONG WINAPI Basicaudio_Release(IBasicAudio *iface) {
726     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
727
728     TRACE("(%p/%p)->()\n", This, iface);
729
730     return DSoundRender_Release((IBaseFilter*)This);
731 }
732
733 /*** IDispatch methods ***/
734 static HRESULT WINAPI Basicaudio_GetTypeInfoCount(IBasicAudio *iface,
735                                                   UINT*pctinfo) {
736     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
737
738     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
739
740     return S_OK;
741 }
742
743 static HRESULT WINAPI Basicaudio_GetTypeInfo(IBasicAudio *iface,
744                                              UINT iTInfo,
745                                              LCID lcid,
746                                              ITypeInfo**ppTInfo) {
747     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
748
749     TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
750
751     return S_OK;
752 }
753
754 static HRESULT WINAPI Basicaudio_GetIDsOfNames(IBasicAudio *iface,
755                                                REFIID riid,
756                                                LPOLESTR*rgszNames,
757                                                UINT cNames,
758                                                LCID lcid,
759                                                DISPID*rgDispId) {
760     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
761
762     TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
763
764     return S_OK;
765 }
766
767 static HRESULT WINAPI Basicaudio_Invoke(IBasicAudio *iface,
768                                         DISPID dispIdMember,
769                                         REFIID riid,
770                                         LCID lcid,
771                                         WORD wFlags,
772                                         DISPPARAMS*pDispParams,
773                                         VARIANT*pVarResult,
774                                         EXCEPINFO*pExepInfo,
775                                         UINT*puArgErr) {
776     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
777
778     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);
779
780     return S_OK;
781 }
782
783 /*** IBasicAudio methods ***/
784 static HRESULT WINAPI Basicaudio_put_Volume(IBasicAudio *iface,
785                                             long lVolume) {
786     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
787
788     TRACE("(%p/%p)->(%ld): stub !!!\n", This, iface, lVolume);
789
790     return S_OK;
791 }
792
793 static HRESULT WINAPI Basicaudio_get_Volume(IBasicAudio *iface,
794                                             long *plVolume) {
795     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
796
797     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, plVolume);
798
799     return S_OK;
800 }
801
802 static HRESULT WINAPI Basicaudio_put_Balance(IBasicAudio *iface,
803                                              long lBalance) {
804     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
805
806     TRACE("(%p/%p)->(%ld): stub !!!\n", This, iface, lBalance);
807
808     return S_OK;
809 }
810
811 static HRESULT WINAPI Basicaudio_get_Balance(IBasicAudio *iface,
812                                              long *plBalance) {
813     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
814
815     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, plBalance);
816
817     return S_OK;
818 }
819
820 static const IBasicAudioVtbl IBasicAudio_Vtbl =
821 {
822     Basicaudio_QueryInterface,
823     Basicaudio_AddRef,
824     Basicaudio_Release,
825     Basicaudio_GetTypeInfoCount,
826     Basicaudio_GetTypeInfo,
827     Basicaudio_GetIDsOfNames,
828     Basicaudio_Invoke,
829     Basicaudio_put_Volume,
830     Basicaudio_get_Volume,
831     Basicaudio_put_Balance,
832     Basicaudio_get_Balance
833 };