quartz: Check allocation failure and clear memory in DSound Renderer.
[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     if (This->state != State_Running) {
170         DWORD state;
171         if (SUCCEEDED(IDirectSoundBuffer_GetStatus(This->dsbuffer, &state))) {
172             if (state & DSBSTATUS_PLAYING) {
173                 IDirectSoundBuffer_Stop(This->dsbuffer);
174                 This->started = FALSE;
175             }
176         }
177         return S_OK;
178     }
179
180     while (1)
181     {
182         hr = IDirectSoundBuffer_GetCurrentPosition(This->dsbuffer, &play_pos, NULL);
183         if (hr != DS_OK)
184         {
185             ERR("Error GetCurrentPosition: %x\n", hr);
186             break;
187         }
188         if (This->write_pos < play_pos)
189              buf_free = play_pos-This->write_pos;
190         else
191              buf_free = DSBUFFERSIZE - This->write_pos + play_pos;
192
193         /* This situation is ambiguous; Assume full when playing */
194         if(buf_free == DSBUFFERSIZE && This->started)
195         {
196             Sleep(10);
197             continue;
198         }
199
200         size2 = min(buf_free, size);
201         hr = IDirectSoundBuffer_Lock(This->dsbuffer, This->write_pos, size2, (LPVOID *)&lpbuf1, &dwsize1, (LPVOID *)&lpbuf2, &dwsize2, 0);
202         if (hr != DS_OK) {
203             ERR("Unable to lock sound buffer! (%x)\n", hr);
204             break;
205         }
206         /* TRACE("write_pos=%d, size=%d, sz1=%d, sz2=%d\n", This->write_pos, size2, dwsize1, dwsize2); */
207
208         memcpy(lpbuf1, data, dwsize1);
209         if (dwsize2)
210             memcpy(lpbuf2, data + dwsize1, dwsize2);
211
212         hr = IDirectSoundBuffer_Unlock(This->dsbuffer, lpbuf1, dwsize1, lpbuf2, dwsize2);
213         if (hr != DS_OK)
214             ERR("Unable to unlock sound buffer! (%x)\n", hr);
215         if (!This->started)
216         {
217             hr = IDirectSoundBuffer_Play(This->dsbuffer, 0, 0, DSBPLAY_LOOPING);
218             if (hr == DS_OK)
219                 This->started = TRUE;
220             else
221                 ERR("Can't start playing! (%x)\n", hr);
222         }
223         size -= dwsize1 + dwsize2;
224         data += dwsize1 + dwsize2;
225         This->write_pos = (This->write_pos + dwsize1 + dwsize2) % DSBUFFERSIZE;
226
227         if (!size)
228             break;
229         Sleep(10);
230     }
231
232     return hr;
233 }
234
235 static HRESULT DSoundRender_Sample(LPVOID iface, IMediaSample * pSample)
236 {
237     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
238     LPBYTE pbSrcStream = NULL;
239     long cbSrcStream = 0;
240     REFERENCE_TIME tStart, tStop;
241     HRESULT hr;
242
243     TRACE("%p %p\n", iface, pSample);
244     
245     hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
246     if (FAILED(hr))
247     {
248         ERR("Cannot get pointer to sample data (%x)\n", hr);
249         return hr;
250     }
251
252     hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
253     if (FAILED(hr))
254         ERR("Cannot get sample time (%x)\n", hr);
255
256     cbSrcStream = IMediaSample_GetActualDataLength(pSample);
257
258     TRACE("Sample data ptr = %p, size = %ld\n", pbSrcStream, cbSrcStream);
259
260 #if 0 /* For debugging purpose */
261     {
262         int i;
263         for(i = 0; i < cbSrcStream; i++)
264         {
265             if ((i!=0) && !(i%16))
266                 TRACE("\n");
267             TRACE("%02x ", pbSrcStream[i]);
268         }
269         TRACE("\n");
270     }
271 #endif
272   
273     if (!This->init)
274     {
275         hr = DSoundRender_CreateSoundBuffer(iface);
276         if (SUCCEEDED(hr))
277             This->init = TRUE;
278         else
279         {
280             ERR("Unable to create DSound buffer\n");
281             return hr;
282         }
283     }
284     
285     hr = DSoundRender_SendSampleData(This, pbSrcStream, cbSrcStream);
286
287     return hr;
288 }
289
290 static HRESULT DSoundRender_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
291 {
292     WAVEFORMATEX* format = (WAVEFORMATEX*)pmt->pbFormat;
293     TRACE("wFormatTag = %x %x\n", format->wFormatTag, WAVE_FORMAT_PCM);
294     TRACE("nChannels = %d\n", format->nChannels);
295     TRACE("nSamplesPerSec = %d\n", format->nAvgBytesPerSec);
296     TRACE("nAvgBytesPerSec = %d\n", format->nAvgBytesPerSec);
297     TRACE("nBlockAlign = %d\n", format->nBlockAlign);
298     TRACE("wBitsPerSample = %d\n", format->wBitsPerSample);
299
300     if (IsEqualIID(&pmt->majortype, &MEDIATYPE_Audio) && IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_PCM))
301         return S_OK;
302     return S_FALSE;
303 }
304
305 HRESULT DSoundRender_create(IUnknown * pUnkOuter, LPVOID * ppv)
306 {
307     HRESULT hr;
308     PIN_INFO piInput;
309     DSoundRenderImpl * pDSoundRender;
310
311     TRACE("(%p, %p)\n", pUnkOuter, ppv);
312
313     *ppv = NULL;
314
315     if (pUnkOuter)
316         return CLASS_E_NOAGGREGATION;
317     
318     pDSoundRender = CoTaskMemAlloc(sizeof(DSoundRenderImpl));
319     if (!pDSoundRender)
320         return E_OUTOFMEMORY;
321     ZeroMemory(pDSoundRender, sizeof(DSoundRenderImpl));
322
323     pDSoundRender->lpVtbl = &DSoundRender_Vtbl;
324     pDSoundRender->IBasicAudio_vtbl = &IBasicAudio_Vtbl;
325     pDSoundRender->refCount = 1;
326     InitializeCriticalSection(&pDSoundRender->csFilter);
327     pDSoundRender->state = State_Stopped;
328
329     pDSoundRender->ppPins = CoTaskMemAlloc(1 * sizeof(IPin *));
330     if (!pDSoundRender->ppPins)
331     {
332         DeleteCriticalSection(&pDSoundRender->csFilter);
333         CoTaskMemFree(pDSoundRender);
334         return E_OUTOFMEMORY;
335     }
336
337     /* construct input pin */
338     piInput.dir = PINDIR_INPUT;
339     piInput.pFilter = (IBaseFilter *)pDSoundRender;
340     lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
341     hr = DSoundRender_InputPin_Construct(&piInput, DSoundRender_Sample, (LPVOID)pDSoundRender, DSoundRender_QueryAccept, &pDSoundRender->csFilter, (IPin **)&pDSoundRender->pInputPin);
342
343     if (SUCCEEDED(hr))
344     {
345         pDSoundRender->ppPins[0] = (IPin *)pDSoundRender->pInputPin;
346         *ppv = (LPVOID)pDSoundRender;
347     }
348     else
349     {
350         CoTaskMemFree(pDSoundRender->ppPins);
351         DeleteCriticalSection(&pDSoundRender->csFilter);
352         CoTaskMemFree(pDSoundRender);
353     }
354
355     return hr;
356 }
357
358 static HRESULT WINAPI DSoundRender_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
359 {
360     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
361     TRACE("(%p, %p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
362
363     *ppv = NULL;
364
365     if (IsEqualIID(riid, &IID_IUnknown))
366         *ppv = (LPVOID)This;
367     else if (IsEqualIID(riid, &IID_IPersist))
368         *ppv = (LPVOID)This;
369     else if (IsEqualIID(riid, &IID_IMediaFilter))
370         *ppv = (LPVOID)This;
371     else if (IsEqualIID(riid, &IID_IBaseFilter))
372         *ppv = (LPVOID)This;
373     else if (IsEqualIID(riid, &IID_IBasicAudio))
374         *ppv = (LPVOID)&(This->IBasicAudio_vtbl);
375
376     if (*ppv)
377     {
378         IUnknown_AddRef((IUnknown *)(*ppv));
379         return S_OK;
380     }
381
382     FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
383
384     return E_NOINTERFACE;
385 }
386
387 static ULONG WINAPI DSoundRender_AddRef(IBaseFilter * iface)
388 {
389     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
390     ULONG refCount = InterlockedIncrement(&This->refCount);
391
392     TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
393
394     return refCount;
395 }
396
397 static ULONG WINAPI DSoundRender_Release(IBaseFilter * iface)
398 {
399     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
400     ULONG refCount = InterlockedDecrement(&This->refCount);
401
402     TRACE("(%p)->() Release from %d\n", This, refCount + 1);
403
404     if (!refCount)
405     {
406         DeleteCriticalSection(&This->csFilter);
407         if (This->pClock)
408             IReferenceClock_Release(This->pClock);
409
410         if (This->dsbuffer)
411             IDirectSoundBuffer_Release(This->dsbuffer);
412         This->dsbuffer = NULL;
413         if (This->dsound)
414             IDirectSound_Release(This->dsound);
415         This->dsound = NULL;
416        
417         IPin_Release(This->ppPins[0]);
418         
419         CoTaskMemFree(This->ppPins);
420         This->lpVtbl = NULL;
421         This->IBasicAudio_vtbl = NULL;
422         
423         TRACE("Destroying Audio Renderer\n");
424         CoTaskMemFree(This);
425         
426         return 0;
427     }
428     else
429         return refCount;
430 }
431
432 /** IPersist methods **/
433
434 static HRESULT WINAPI DSoundRender_GetClassID(IBaseFilter * iface, CLSID * pClsid)
435 {
436     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
437     TRACE("(%p/%p)->(%p)\n", This, iface, pClsid);
438
439     *pClsid = CLSID_DSoundRender;
440
441     return S_OK;
442 }
443
444 /** IMediaFilter methods **/
445
446 static HRESULT WINAPI DSoundRender_Stop(IBaseFilter * iface)
447 {
448     HRESULT hr = S_OK;
449     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
450
451     TRACE("(%p/%p)->()\n", This, iface);
452
453     EnterCriticalSection(&This->csFilter);
454     {
455         This->state = State_Stopped;
456     }
457     LeaveCriticalSection(&This->csFilter);
458     
459     return hr;
460 }
461
462 static HRESULT WINAPI DSoundRender_Pause(IBaseFilter * iface)
463 {
464     HRESULT hr = S_OK;
465     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
466     
467     TRACE("(%p/%p)->()\n", This, iface);
468
469     EnterCriticalSection(&This->csFilter);
470     {
471         This->state = State_Paused;
472     }
473     LeaveCriticalSection(&This->csFilter);
474
475     return hr;
476 }
477
478 static HRESULT WINAPI DSoundRender_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
479 {
480     HRESULT hr = S_OK;
481     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
482
483     TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
484
485     EnterCriticalSection(&This->csFilter);
486     {
487         This->rtStreamStart = tStart;
488         This->state = State_Running;
489     }
490     LeaveCriticalSection(&This->csFilter);
491
492     return hr;
493 }
494
495 static HRESULT WINAPI DSoundRender_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
496 {
497     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
498
499     TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
500
501     EnterCriticalSection(&This->csFilter);
502     {
503         *pState = This->state;
504     }
505     LeaveCriticalSection(&This->csFilter);
506
507     return S_OK;
508 }
509
510 static HRESULT WINAPI DSoundRender_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
511 {
512     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
513
514     TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
515
516     EnterCriticalSection(&This->csFilter);
517     {
518         if (This->pClock)
519             IReferenceClock_Release(This->pClock);
520         This->pClock = pClock;
521         if (This->pClock)
522             IReferenceClock_AddRef(This->pClock);
523     }
524     LeaveCriticalSection(&This->csFilter);
525
526     return S_OK;
527 }
528
529 static HRESULT WINAPI DSoundRender_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
530 {
531     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
532
533     TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
534
535     EnterCriticalSection(&This->csFilter);
536     {
537         *ppClock = This->pClock;
538         IReferenceClock_AddRef(This->pClock);
539     }
540     LeaveCriticalSection(&This->csFilter);
541     
542     return S_OK;
543 }
544
545 /** IBaseFilter implementation **/
546
547 static HRESULT WINAPI DSoundRender_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
548 {
549     ENUMPINDETAILS epd;
550     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
551
552     TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
553
554     epd.cPins = 1; /* input pin */
555     epd.ppPins = This->ppPins;
556     return IEnumPinsImpl_Construct(&epd, ppEnum);
557 }
558
559 static HRESULT WINAPI DSoundRender_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
560 {
561     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
562
563     TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_w(Id), ppPin);
564     
565     FIXME("DSoundRender::FindPin(...)\n");
566
567     /* FIXME: critical section */
568
569     return E_NOTIMPL;
570 }
571
572 static HRESULT WINAPI DSoundRender_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
573 {
574     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
575
576     TRACE("(%p/%p)->(%p)\n", This, iface, pInfo);
577
578     strcpyW(pInfo->achName, This->filterInfo.achName);
579     pInfo->pGraph = This->filterInfo.pGraph;
580
581     if (pInfo->pGraph)
582         IFilterGraph_AddRef(pInfo->pGraph);
583     
584     return S_OK;
585 }
586
587 static HRESULT WINAPI DSoundRender_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
588 {
589     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
590
591     TRACE("(%p/%p)->(%p, %s)\n", This, iface, pGraph, debugstr_w(pName));
592
593     EnterCriticalSection(&This->csFilter);
594     {
595         if (pName)
596             strcpyW(This->filterInfo.achName, pName);
597         else
598             *This->filterInfo.achName = '\0';
599         This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
600     }
601     LeaveCriticalSection(&This->csFilter);
602
603     return S_OK;
604 }
605
606 static HRESULT WINAPI DSoundRender_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
607 {
608     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
609     TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
610     return E_NOTIMPL;
611 }
612
613 static const IBaseFilterVtbl DSoundRender_Vtbl =
614 {
615     DSoundRender_QueryInterface,
616     DSoundRender_AddRef,
617     DSoundRender_Release,
618     DSoundRender_GetClassID,
619     DSoundRender_Stop,
620     DSoundRender_Pause,
621     DSoundRender_Run,
622     DSoundRender_GetState,
623     DSoundRender_SetSyncSource,
624     DSoundRender_GetSyncSource,
625     DSoundRender_EnumPins,
626     DSoundRender_FindPin,
627     DSoundRender_QueryFilterInfo,
628     DSoundRender_JoinFilterGraph,
629     DSoundRender_QueryVendorInfo
630 };
631
632 static HRESULT WINAPI DSoundRender_InputPin_EndOfStream(IPin * iface)
633 {
634     InputPin* This = (InputPin*)iface;
635     IMediaEventSink* pEventSink;
636     HRESULT hr;
637
638     TRACE("(%p/%p)->()\n", This, iface);
639
640     hr = IFilterGraph_QueryInterface(((DSoundRenderImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
641     if (SUCCEEDED(hr))
642     {
643         /* FIXME: We should wait that all audio data has been played */
644         hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
645         IMediaEventSink_Release(pEventSink);
646     }
647
648     return hr;
649 }
650
651 static const IPinVtbl DSoundRender_InputPin_Vtbl = 
652 {
653     InputPin_QueryInterface,
654     IPinImpl_AddRef,
655     InputPin_Release,
656     InputPin_Connect,
657     InputPin_ReceiveConnection,
658     IPinImpl_Disconnect,
659     IPinImpl_ConnectedTo,
660     IPinImpl_ConnectionMediaType,
661     IPinImpl_QueryPinInfo,
662     IPinImpl_QueryDirection,
663     IPinImpl_QueryId,
664     IPinImpl_QueryAccept,
665     IPinImpl_EnumMediaTypes,
666     IPinImpl_QueryInternalConnections,
667     DSoundRender_InputPin_EndOfStream,
668     InputPin_BeginFlush,
669     InputPin_EndFlush,
670     InputPin_NewSegment
671 };
672
673 static const IMemInputPinVtbl MemInputPin_Vtbl = 
674 {
675     MemInputPin_QueryInterface,
676     MemInputPin_AddRef,
677     MemInputPin_Release,
678     MemInputPin_GetAllocator,
679     MemInputPin_NotifyAllocator,
680     MemInputPin_GetAllocatorRequirements,
681     MemInputPin_Receive,
682     MemInputPin_ReceiveMultiple,
683     MemInputPin_ReceiveCanBlock
684 };
685
686 /*** IUnknown methods ***/
687 static HRESULT WINAPI Basicaudio_QueryInterface(IBasicAudio *iface,
688                                                 REFIID riid,
689                                                 LPVOID*ppvObj) {
690     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
691
692     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
693
694     return DSoundRender_QueryInterface((IBaseFilter*)This, riid, ppvObj);
695 }
696
697 static ULONG WINAPI Basicaudio_AddRef(IBasicAudio *iface) {
698     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
699
700     TRACE("(%p/%p)->()\n", This, iface);
701
702     return DSoundRender_AddRef((IBaseFilter*)This);
703 }
704
705 static ULONG WINAPI Basicaudio_Release(IBasicAudio *iface) {
706     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
707
708     TRACE("(%p/%p)->()\n", This, iface);
709
710     return DSoundRender_Release((IBaseFilter*)This);
711 }
712
713 /*** IDispatch methods ***/
714 static HRESULT WINAPI Basicaudio_GetTypeInfoCount(IBasicAudio *iface,
715                                                   UINT*pctinfo) {
716     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
717
718     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
719
720     return S_OK;
721 }
722
723 static HRESULT WINAPI Basicaudio_GetTypeInfo(IBasicAudio *iface,
724                                              UINT iTInfo,
725                                              LCID lcid,
726                                              ITypeInfo**ppTInfo) {
727     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
728
729     TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
730
731     return S_OK;
732 }
733
734 static HRESULT WINAPI Basicaudio_GetIDsOfNames(IBasicAudio *iface,
735                                                REFIID riid,
736                                                LPOLESTR*rgszNames,
737                                                UINT cNames,
738                                                LCID lcid,
739                                                DISPID*rgDispId) {
740     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
741
742     TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
743
744     return S_OK;
745 }
746
747 static HRESULT WINAPI Basicaudio_Invoke(IBasicAudio *iface,
748                                         DISPID dispIdMember,
749                                         REFIID riid,
750                                         LCID lcid,
751                                         WORD wFlags,
752                                         DISPPARAMS*pDispParams,
753                                         VARIANT*pVarResult,
754                                         EXCEPINFO*pExepInfo,
755                                         UINT*puArgErr) {
756     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
757
758     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);
759
760     return S_OK;
761 }
762
763 /*** IBasicAudio methods ***/
764 static HRESULT WINAPI Basicaudio_put_Volume(IBasicAudio *iface,
765                                             long lVolume) {
766     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
767
768     TRACE("(%p/%p)->(%ld): stub !!!\n", This, iface, lVolume);
769
770     return S_OK;
771 }
772
773 static HRESULT WINAPI Basicaudio_get_Volume(IBasicAudio *iface,
774                                             long *plVolume) {
775     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
776
777     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, plVolume);
778
779     return S_OK;
780 }
781
782 static HRESULT WINAPI Basicaudio_put_Balance(IBasicAudio *iface,
783                                              long lBalance) {
784     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
785
786     TRACE("(%p/%p)->(%ld): stub !!!\n", This, iface, lBalance);
787
788     return S_OK;
789 }
790
791 static HRESULT WINAPI Basicaudio_get_Balance(IBasicAudio *iface,
792                                              long *plBalance) {
793     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
794
795     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, plBalance);
796
797     return S_OK;
798 }
799
800 static const IBasicAudioVtbl IBasicAudio_Vtbl =
801 {
802     Basicaudio_QueryInterface,
803     Basicaudio_AddRef,
804     Basicaudio_Release,
805     Basicaudio_GetTypeInfoCount,
806     Basicaudio_GetTypeInfo,
807     Basicaudio_GetIDsOfNames,
808     Basicaudio_Invoke,
809     Basicaudio_put_Volume,
810     Basicaudio_get_Volume,
811     Basicaudio_put_Balance,
812     Basicaudio_get_Balance
813 };