kernel32: GlobalMemoryStatusEx: return the size of physical memory + swapsize in...
[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->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": DSoundRenderImpl.csFilter");
320     pDSoundRender->state = State_Stopped;
321
322     pDSoundRender->ppPins = CoTaskMemAlloc(1 * sizeof(IPin *));
323     if (!pDSoundRender->ppPins)
324     {
325         pDSoundRender->csFilter.DebugInfo->Spare[0] = 0;
326         DeleteCriticalSection(&pDSoundRender->csFilter);
327         CoTaskMemFree(pDSoundRender);
328         return E_OUTOFMEMORY;
329     }
330
331     /* construct input pin */
332     piInput.dir = PINDIR_INPUT;
333     piInput.pFilter = (IBaseFilter *)pDSoundRender;
334     lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
335     hr = DSoundRender_InputPin_Construct(&piInput, DSoundRender_Sample, (LPVOID)pDSoundRender, DSoundRender_QueryAccept, &pDSoundRender->csFilter, (IPin **)&pDSoundRender->pInputPin);
336
337     if (SUCCEEDED(hr))
338     {
339         pDSoundRender->ppPins[0] = (IPin *)pDSoundRender->pInputPin;
340         *ppv = (LPVOID)pDSoundRender;
341     }
342     else
343     {
344         CoTaskMemFree(pDSoundRender->ppPins);
345         pDSoundRender->csFilter.DebugInfo->Spare[0] = 0;
346         DeleteCriticalSection(&pDSoundRender->csFilter);
347         CoTaskMemFree(pDSoundRender);
348     }
349
350     return hr;
351 }
352
353 static HRESULT WINAPI DSoundRender_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
354 {
355     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
356     TRACE("(%p, %p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
357
358     *ppv = NULL;
359
360     if (IsEqualIID(riid, &IID_IUnknown))
361         *ppv = (LPVOID)This;
362     else if (IsEqualIID(riid, &IID_IPersist))
363         *ppv = (LPVOID)This;
364     else if (IsEqualIID(riid, &IID_IMediaFilter))
365         *ppv = (LPVOID)This;
366     else if (IsEqualIID(riid, &IID_IBaseFilter))
367         *ppv = (LPVOID)This;
368     else if (IsEqualIID(riid, &IID_IBasicAudio))
369         *ppv = (LPVOID)&(This->IBasicAudio_vtbl);
370
371     if (*ppv)
372     {
373         IUnknown_AddRef((IUnknown *)(*ppv));
374         return S_OK;
375     }
376
377     FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
378
379     return E_NOINTERFACE;
380 }
381
382 static ULONG WINAPI DSoundRender_AddRef(IBaseFilter * iface)
383 {
384     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
385     ULONG refCount = InterlockedIncrement(&This->refCount);
386
387     TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
388
389     return refCount;
390 }
391
392 static ULONG WINAPI DSoundRender_Release(IBaseFilter * iface)
393 {
394     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
395     ULONG refCount = InterlockedDecrement(&This->refCount);
396
397     TRACE("(%p)->() Release from %d\n", This, refCount + 1);
398
399     if (!refCount)
400     {
401         IPin *pConnectedTo;
402
403         This->csFilter.DebugInfo->Spare[0] = 0;
404         DeleteCriticalSection(&This->csFilter);
405         if (This->pClock)
406             IReferenceClock_Release(This->pClock);
407
408         if (This->dsbuffer)
409             IDirectSoundBuffer_Release(This->dsbuffer);
410         This->dsbuffer = NULL;
411         if (This->dsound)
412             IDirectSound_Release(This->dsound);
413         This->dsound = NULL;
414        
415         if (SUCCEEDED(IPin_ConnectedTo(This->ppPins[0], &pConnectedTo)))
416         {
417             IPin_Disconnect(pConnectedTo);
418             IPin_Release(pConnectedTo);
419         }
420         IPin_Disconnect(This->ppPins[0]);
421
422         IPin_Release(This->ppPins[0]);
423         
424         CoTaskMemFree(This->ppPins);
425         This->lpVtbl = NULL;
426         This->IBasicAudio_vtbl = NULL;
427         
428         TRACE("Destroying Audio Renderer\n");
429         CoTaskMemFree(This);
430         
431         return 0;
432     }
433     else
434         return refCount;
435 }
436
437 /** IPersist methods **/
438
439 static HRESULT WINAPI DSoundRender_GetClassID(IBaseFilter * iface, CLSID * pClsid)
440 {
441     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
442     TRACE("(%p/%p)->(%p)\n", This, iface, pClsid);
443
444     *pClsid = CLSID_DSoundRender;
445
446     return S_OK;
447 }
448
449 /** IMediaFilter methods **/
450
451 static HRESULT WINAPI DSoundRender_Stop(IBaseFilter * iface)
452 {
453     HRESULT hr = S_OK;
454     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
455
456     TRACE("(%p/%p)->()\n", This, iface);
457
458     EnterCriticalSection(&This->csFilter);
459     {
460         DWORD state = 0;
461         if (This->dsbuffer)
462         {
463             hr = IDirectSoundBuffer_GetStatus(This->dsbuffer, &state);
464             if (SUCCEEDED(hr))
465             {
466                 if (state & DSBSTATUS_PLAYING)
467                     hr = IDirectSoundBuffer_Stop(This->dsbuffer);
468             }
469         }
470         if (SUCCEEDED(hr))
471         {
472             This->started = FALSE;
473             This->state = State_Stopped;
474         }
475     }
476     LeaveCriticalSection(&This->csFilter);
477     
478     return hr;
479 }
480
481 static HRESULT WINAPI DSoundRender_Pause(IBaseFilter * iface)
482 {
483     HRESULT hr = S_OK;
484     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
485     
486     TRACE("(%p/%p)->()\n", This, iface);
487
488     EnterCriticalSection(&This->csFilter);
489     {
490         DWORD state = 0;
491         if (This->dsbuffer)
492         {
493             hr = IDirectSoundBuffer_GetStatus(This->dsbuffer, &state);
494             if (SUCCEEDED(hr))
495             {
496                 if (state & DSBSTATUS_PLAYING)
497                     hr = IDirectSoundBuffer_Stop(This->dsbuffer);
498             }
499         }
500         if (SUCCEEDED(hr))
501         {
502             This->started = FALSE;
503             This->state = State_Paused;
504         }
505     }
506     LeaveCriticalSection(&This->csFilter);
507
508     return hr;
509 }
510
511 static HRESULT WINAPI DSoundRender_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
512 {
513     HRESULT hr = S_OK;
514     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
515
516     TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
517
518     EnterCriticalSection(&This->csFilter);
519     {
520         This->rtStreamStart = tStart;
521         This->state = State_Running;
522     }
523     LeaveCriticalSection(&This->csFilter);
524
525     return hr;
526 }
527
528 static HRESULT WINAPI DSoundRender_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
529 {
530     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
531
532     TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
533
534     EnterCriticalSection(&This->csFilter);
535     {
536         *pState = This->state;
537     }
538     LeaveCriticalSection(&This->csFilter);
539
540     return S_OK;
541 }
542
543 static HRESULT WINAPI DSoundRender_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
544 {
545     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
546
547     TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
548
549     EnterCriticalSection(&This->csFilter);
550     {
551         if (This->pClock)
552             IReferenceClock_Release(This->pClock);
553         This->pClock = pClock;
554         if (This->pClock)
555             IReferenceClock_AddRef(This->pClock);
556     }
557     LeaveCriticalSection(&This->csFilter);
558
559     return S_OK;
560 }
561
562 static HRESULT WINAPI DSoundRender_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
563 {
564     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
565
566     TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
567
568     EnterCriticalSection(&This->csFilter);
569     {
570         *ppClock = This->pClock;
571         IReferenceClock_AddRef(This->pClock);
572     }
573     LeaveCriticalSection(&This->csFilter);
574     
575     return S_OK;
576 }
577
578 /** IBaseFilter implementation **/
579
580 static HRESULT WINAPI DSoundRender_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
581 {
582     ENUMPINDETAILS epd;
583     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
584
585     TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
586
587     epd.cPins = 1; /* input pin */
588     epd.ppPins = This->ppPins;
589     return IEnumPinsImpl_Construct(&epd, ppEnum);
590 }
591
592 static HRESULT WINAPI DSoundRender_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
593 {
594     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
595
596     TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_w(Id), ppPin);
597     
598     FIXME("DSoundRender::FindPin(...)\n");
599
600     /* FIXME: critical section */
601
602     return E_NOTIMPL;
603 }
604
605 static HRESULT WINAPI DSoundRender_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
606 {
607     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
608
609     TRACE("(%p/%p)->(%p)\n", This, iface, pInfo);
610
611     strcpyW(pInfo->achName, This->filterInfo.achName);
612     pInfo->pGraph = This->filterInfo.pGraph;
613
614     if (pInfo->pGraph)
615         IFilterGraph_AddRef(pInfo->pGraph);
616     
617     return S_OK;
618 }
619
620 static HRESULT WINAPI DSoundRender_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
621 {
622     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
623
624     TRACE("(%p/%p)->(%p, %s)\n", This, iface, pGraph, debugstr_w(pName));
625
626     EnterCriticalSection(&This->csFilter);
627     {
628         if (pName)
629             strcpyW(This->filterInfo.achName, pName);
630         else
631             *This->filterInfo.achName = '\0';
632         This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
633     }
634     LeaveCriticalSection(&This->csFilter);
635
636     return S_OK;
637 }
638
639 static HRESULT WINAPI DSoundRender_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
640 {
641     DSoundRenderImpl *This = (DSoundRenderImpl *)iface;
642     TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
643     return E_NOTIMPL;
644 }
645
646 static const IBaseFilterVtbl DSoundRender_Vtbl =
647 {
648     DSoundRender_QueryInterface,
649     DSoundRender_AddRef,
650     DSoundRender_Release,
651     DSoundRender_GetClassID,
652     DSoundRender_Stop,
653     DSoundRender_Pause,
654     DSoundRender_Run,
655     DSoundRender_GetState,
656     DSoundRender_SetSyncSource,
657     DSoundRender_GetSyncSource,
658     DSoundRender_EnumPins,
659     DSoundRender_FindPin,
660     DSoundRender_QueryFilterInfo,
661     DSoundRender_JoinFilterGraph,
662     DSoundRender_QueryVendorInfo
663 };
664
665 static HRESULT WINAPI DSoundRender_InputPin_EndOfStream(IPin * iface)
666 {
667     InputPin* This = (InputPin*)iface;
668     IMediaEventSink* pEventSink;
669     HRESULT hr;
670
671     TRACE("(%p/%p)->()\n", This, iface);
672
673     hr = IFilterGraph_QueryInterface(((DSoundRenderImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
674     if (SUCCEEDED(hr))
675     {
676         /* FIXME: We should wait that all audio data has been played */
677         hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
678         IMediaEventSink_Release(pEventSink);
679     }
680
681     return hr;
682 }
683
684 static const IPinVtbl DSoundRender_InputPin_Vtbl = 
685 {
686     InputPin_QueryInterface,
687     IPinImpl_AddRef,
688     InputPin_Release,
689     InputPin_Connect,
690     InputPin_ReceiveConnection,
691     IPinImpl_Disconnect,
692     IPinImpl_ConnectedTo,
693     IPinImpl_ConnectionMediaType,
694     IPinImpl_QueryPinInfo,
695     IPinImpl_QueryDirection,
696     IPinImpl_QueryId,
697     IPinImpl_QueryAccept,
698     IPinImpl_EnumMediaTypes,
699     IPinImpl_QueryInternalConnections,
700     DSoundRender_InputPin_EndOfStream,
701     InputPin_BeginFlush,
702     InputPin_EndFlush,
703     InputPin_NewSegment
704 };
705
706 static const IMemInputPinVtbl MemInputPin_Vtbl = 
707 {
708     MemInputPin_QueryInterface,
709     MemInputPin_AddRef,
710     MemInputPin_Release,
711     MemInputPin_GetAllocator,
712     MemInputPin_NotifyAllocator,
713     MemInputPin_GetAllocatorRequirements,
714     MemInputPin_Receive,
715     MemInputPin_ReceiveMultiple,
716     MemInputPin_ReceiveCanBlock
717 };
718
719 /*** IUnknown methods ***/
720 static HRESULT WINAPI Basicaudio_QueryInterface(IBasicAudio *iface,
721                                                 REFIID riid,
722                                                 LPVOID*ppvObj) {
723     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
724
725     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
726
727     return DSoundRender_QueryInterface((IBaseFilter*)This, riid, ppvObj);
728 }
729
730 static ULONG WINAPI Basicaudio_AddRef(IBasicAudio *iface) {
731     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
732
733     TRACE("(%p/%p)->()\n", This, iface);
734
735     return DSoundRender_AddRef((IBaseFilter*)This);
736 }
737
738 static ULONG WINAPI Basicaudio_Release(IBasicAudio *iface) {
739     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
740
741     TRACE("(%p/%p)->()\n", This, iface);
742
743     return DSoundRender_Release((IBaseFilter*)This);
744 }
745
746 /*** IDispatch methods ***/
747 static HRESULT WINAPI Basicaudio_GetTypeInfoCount(IBasicAudio *iface,
748                                                   UINT*pctinfo) {
749     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
750
751     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
752
753     return S_OK;
754 }
755
756 static HRESULT WINAPI Basicaudio_GetTypeInfo(IBasicAudio *iface,
757                                              UINT iTInfo,
758                                              LCID lcid,
759                                              ITypeInfo**ppTInfo) {
760     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
761
762     TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
763
764     return S_OK;
765 }
766
767 static HRESULT WINAPI Basicaudio_GetIDsOfNames(IBasicAudio *iface,
768                                                REFIID riid,
769                                                LPOLESTR*rgszNames,
770                                                UINT cNames,
771                                                LCID lcid,
772                                                DISPID*rgDispId) {
773     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
774
775     TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
776
777     return S_OK;
778 }
779
780 static HRESULT WINAPI Basicaudio_Invoke(IBasicAudio *iface,
781                                         DISPID dispIdMember,
782                                         REFIID riid,
783                                         LCID lcid,
784                                         WORD wFlags,
785                                         DISPPARAMS*pDispParams,
786                                         VARIANT*pVarResult,
787                                         EXCEPINFO*pExepInfo,
788                                         UINT*puArgErr) {
789     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
790
791     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);
792
793     return S_OK;
794 }
795
796 /*** IBasicAudio methods ***/
797 static HRESULT WINAPI Basicaudio_put_Volume(IBasicAudio *iface,
798                                             long lVolume) {
799     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
800
801     TRACE("(%p/%p)->(%ld): stub !!!\n", This, iface, lVolume);
802
803     return S_OK;
804 }
805
806 static HRESULT WINAPI Basicaudio_get_Volume(IBasicAudio *iface,
807                                             long *plVolume) {
808     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
809
810     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, plVolume);
811
812     return S_OK;
813 }
814
815 static HRESULT WINAPI Basicaudio_put_Balance(IBasicAudio *iface,
816                                              long lBalance) {
817     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
818
819     TRACE("(%p/%p)->(%ld): stub !!!\n", This, iface, lBalance);
820
821     return S_OK;
822 }
823
824 static HRESULT WINAPI Basicaudio_get_Balance(IBasicAudio *iface,
825                                              long *plBalance) {
826     ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface);
827
828     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, plBalance);
829
830     return S_OK;
831 }
832
833 static const IBasicAudioVtbl IBasicAudio_Vtbl =
834 {
835     Basicaudio_QueryInterface,
836     Basicaudio_AddRef,
837     Basicaudio_Release,
838     Basicaudio_GetTypeInfoCount,
839     Basicaudio_GetTypeInfo,
840     Basicaudio_GetIDsOfNames,
841     Basicaudio_Invoke,
842     Basicaudio_put_Volume,
843     Basicaudio_get_Volume,
844     Basicaudio_put_Balance,
845     Basicaudio_get_Balance
846 };