gdi32: Replace inline static with static inline.
[wine] / dlls / quartz / filtergraph.c
1 /*              DirectShow FilterGraph object (QUARTZ.DLL)
2  *
3  * Copyright 2002 Lionel Ulmer
4  * Copyright 2004 Christian Costa
5  *
6  * This file contains the (internal) driver registration functions,
7  * driver enumeration APIs and DirectDraw creation functions.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #include "config.h"
25 #include <stdarg.h>
26
27 #define COBJMACROS
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "dshow.h"
33 #include "wine/debug.h"
34 #include "quartz_private.h"
35 #include "ole2.h"
36 #include "olectl.h"
37 #include "strmif.h"
38 #include "vfwmsgs.h"
39 #include "evcode.h"
40 #include "wine/unicode.h"
41
42
43 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
44
45 typedef struct {
46     HWND hWnd;      /* Target window */
47     long msg;       /* User window message */
48     long instance;  /* User data */
49     int  disabled;  /* Disabled messages posting */
50 } WndNotify;
51
52 typedef struct {
53     long lEventCode;   /* Event code */
54     LONG_PTR lParam1;  /* Param1 */
55     LONG_PTR lParam2;  /* Param2 */
56 } Event;
57
58 /* messages ring implementation for queuing events (taken from winmm) */
59 #define EVENTS_RING_BUFFER_INCREMENT      64
60 typedef struct {
61     Event* messages;
62     int ring_buffer_size;
63     int msg_tosave;
64     int msg_toget;
65     CRITICAL_SECTION msg_crst;
66     HANDLE msg_event; /* Signaled for no empty queue */
67 } EventsQueue;
68
69 static int EventsQueue_Init(EventsQueue* omr)
70 {
71     omr->msg_toget = 0;
72     omr->msg_tosave = 0;
73     omr->msg_event = CreateEventW(NULL, TRUE, FALSE, NULL);
74     omr->ring_buffer_size = EVENTS_RING_BUFFER_INCREMENT;
75     omr->messages = CoTaskMemAlloc(omr->ring_buffer_size * sizeof(Event));
76     ZeroMemory(omr->messages, omr->ring_buffer_size * sizeof(Event));
77
78     InitializeCriticalSection(&omr->msg_crst);
79     omr->msg_crst.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": EventsQueue.msg_crst");
80     return TRUE;
81 }
82
83 static int EventsQueue_Destroy(EventsQueue* omr)
84 {
85     CloseHandle(omr->msg_event);
86     CoTaskMemFree(omr->messages);
87     omr->msg_crst.DebugInfo->Spare[0] = 0;
88     DeleteCriticalSection(&omr->msg_crst);
89     return TRUE;
90 }
91
92 static int EventsQueue_PutEvent(EventsQueue* omr, Event* evt)
93 {
94     EnterCriticalSection(&omr->msg_crst);
95     if ((omr->msg_toget == ((omr->msg_tosave + 1) % omr->ring_buffer_size)))
96     {
97         int old_ring_buffer_size = omr->ring_buffer_size;
98         omr->ring_buffer_size += EVENTS_RING_BUFFER_INCREMENT;
99         TRACE("omr->ring_buffer_size=%d\n",omr->ring_buffer_size);
100         omr->messages = HeapReAlloc(GetProcessHeap(),0,omr->messages, omr->ring_buffer_size * sizeof(Event));
101         /* Now we need to rearrange the ring buffer so that the new
102            buffers just allocated are in between omr->msg_tosave and
103            omr->msg_toget.
104         */
105         if (omr->msg_tosave < omr->msg_toget)
106         {
107             memmove(&(omr->messages[omr->msg_toget + EVENTS_RING_BUFFER_INCREMENT]),
108                     &(omr->messages[omr->msg_toget]),
109                     sizeof(Event)*(old_ring_buffer_size - omr->msg_toget)
110                     );
111             omr->msg_toget += EVENTS_RING_BUFFER_INCREMENT;
112         }
113     }
114     omr->messages[omr->msg_tosave] = *evt;
115     SetEvent(omr->msg_event);
116     omr->msg_tosave = (omr->msg_tosave + 1) % omr->ring_buffer_size;
117     LeaveCriticalSection(&omr->msg_crst);
118     return TRUE;
119 }
120
121 static int EventsQueue_GetEvent(EventsQueue* omr, Event* evt, long msTimeOut)
122 {
123     if (WaitForSingleObject(omr->msg_event, msTimeOut) != WAIT_OBJECT_0)
124         return FALSE;
125         
126     EnterCriticalSection(&omr->msg_crst);
127
128     if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
129     {
130         LeaveCriticalSection(&omr->msg_crst);
131         return FALSE;
132     }
133
134     *evt = omr->messages[omr->msg_toget];
135     omr->msg_toget = (omr->msg_toget + 1) % omr->ring_buffer_size;
136
137     /* Mark the buffer as empty if needed */
138     if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
139         ResetEvent(omr->msg_event);
140
141     LeaveCriticalSection(&omr->msg_crst);
142     return TRUE;
143 }
144
145 #define MAX_ITF_CACHE_ENTRIES 3
146 typedef struct _ITF_CACHE_ENTRY {
147    const IID* riid;
148    IBaseFilter* filter;
149    IUnknown* iface;
150 } ITF_CACHE_ENTRY;
151
152 typedef struct _IFilterGraphImpl {
153     const IGraphBuilderVtbl *IGraphBuilder_vtbl;
154     const IMediaControlVtbl *IMediaControl_vtbl;
155     const IMediaSeekingVtbl *IMediaSeeking_vtbl;
156     const IBasicAudioVtbl *IBasicAudio_vtbl;
157     const IBasicVideoVtbl *IBasicVideo_vtbl;
158     const IVideoWindowVtbl *IVideoWindow_vtbl;
159     const IMediaEventExVtbl *IMediaEventEx_vtbl;
160     const IMediaFilterVtbl *IMediaFilter_vtbl;
161     const IMediaEventSinkVtbl *IMediaEventSink_vtbl;
162     const IGraphConfigVtbl *IGraphConfig_vtbl;
163     const IMediaPositionVtbl *IMediaPosition_vtbl;
164     /* IAMGraphStreams */
165     /* IAMStats */
166     /* IBasicVideo2 */
167     /* IFilterChain */
168     /* IFilterGraph2 */
169     /* IFilterMapper2 */
170     /* IGraphVersion */
171     /* IQueueCommand */
172     /* IRegisterServiceProvider */
173     /* IResourceMananger */
174     /* IServiceProvider */
175     /* IVideoFrameStep */
176
177     LONG ref;
178     IFilterMapper2 * pFilterMapper2;
179     IBaseFilter ** ppFiltersInGraph;
180     LPWSTR * pFilterNames;
181     int nFilters;
182     int filterCapacity;
183     long nameIndex;
184     EventsQueue evqueue;
185     HANDLE hEventCompletion;
186     int CompletionStatus;
187     WndNotify notif;
188     int nRenderers;
189     int EcCompleteCount;
190     int HandleEcComplete;
191     int HandleEcRepaint;
192     OAFilterState state;
193     CRITICAL_SECTION cs;
194     ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
195     int nItfCacheEntries;
196 } IFilterGraphImpl;
197
198
199 static HRESULT Filtergraph_QueryInterface(IFilterGraphImpl *This,
200                                           REFIID riid,
201                                           LPVOID *ppvObj) {
202     TRACE("(%p)->(%s (%p), %p)\n", This, debugstr_guid(riid), riid, ppvObj);
203     
204     if (IsEqualGUID(&IID_IUnknown, riid) ||
205         IsEqualGUID(&IID_IFilterGraph, riid) ||
206         IsEqualGUID(&IID_IGraphBuilder, riid)) {
207         *ppvObj = &(This->IGraphBuilder_vtbl);
208         TRACE("   returning IGraphBuilder interface (%p)\n", *ppvObj);
209     } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
210         *ppvObj = &(This->IMediaControl_vtbl);
211         TRACE("   returning IMediaControl interface (%p)\n", *ppvObj);
212     } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
213         *ppvObj = &(This->IMediaSeeking_vtbl);
214         TRACE("   returning IMediaSeeking interface (%p)\n", *ppvObj);
215     } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
216         *ppvObj = &(This->IBasicAudio_vtbl);
217         TRACE("   returning IBasicAudio interface (%p)\n", *ppvObj);
218     } else if (IsEqualGUID(&IID_IBasicVideo, riid)) {
219         *ppvObj = &(This->IBasicVideo_vtbl);
220         TRACE("   returning IBasicVideo interface (%p)\n", *ppvObj);
221     } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
222         *ppvObj = &(This->IVideoWindow_vtbl);
223         TRACE("   returning IVideoWindow interface (%p)\n", *ppvObj);
224     } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
225            IsEqualGUID(&IID_IMediaEventEx, riid)) {
226         *ppvObj = &(This->IMediaEventEx_vtbl);
227         TRACE("   returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
228     } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
229           IsEqualGUID(&IID_IPersist, riid)) {
230         *ppvObj = &(This->IMediaFilter_vtbl);
231         TRACE("   returning IMediaFilter interface (%p)\n", *ppvObj);
232     } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
233         *ppvObj = &(This->IMediaEventSink_vtbl);
234         TRACE("   returning IMediaEventSink interface (%p)\n", *ppvObj);
235     } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
236         *ppvObj = &(This->IGraphConfig_vtbl);
237         TRACE("   returning IGraphConfig interface (%p)\n", *ppvObj);
238     } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
239         *ppvObj = &(This->IMediaPosition_vtbl);
240         TRACE("   returning IMediaPosition interface (%p)\n", *ppvObj);
241     } else {
242         *ppvObj = NULL;
243         FIXME("unknown interface %s\n", debugstr_guid(riid));
244         return E_NOINTERFACE;
245     }
246
247     InterlockedIncrement(&This->ref);
248     return S_OK;
249 }
250
251 static ULONG Filtergraph_AddRef(IFilterGraphImpl *This) {
252     ULONG ref = InterlockedIncrement(&This->ref);
253
254     TRACE("(%p)->(): new ref = %d\n", This, ref);
255     
256     return ref;
257 }
258
259 static ULONG Filtergraph_Release(IFilterGraphImpl *This) {
260     ULONG ref = InterlockedDecrement(&This->ref);
261     
262     TRACE("(%p)->(): new ref = %d\n", This, ref);
263     
264     if (ref == 0) {
265         int i;
266         for (i = 0; i < This->nFilters; i++)
267             IBaseFilter_Release(This->ppFiltersInGraph[i]);
268         for (i = 0; i < This->nItfCacheEntries; i++)
269             IUnknown_Release(This->ItfCacheEntries[i].iface);
270         IFilterMapper2_Release(This->pFilterMapper2);
271         CloseHandle(This->hEventCompletion);
272         EventsQueue_Destroy(&This->evqueue);
273         This->cs.DebugInfo->Spare[0] = 0;
274         DeleteCriticalSection(&This->cs);
275         CoTaskMemFree(This->ppFiltersInGraph);
276         CoTaskMemFree(This->pFilterNames);
277         CoTaskMemFree(This);
278     }
279     return ref;
280 }
281
282
283 /*** IUnknown methods ***/
284 static HRESULT WINAPI GraphBuilder_QueryInterface(IGraphBuilder *iface,
285                                                   REFIID riid,
286                                                   LPVOID*ppvObj) {
287     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
288     
289     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
290     return Filtergraph_QueryInterface(This, riid, ppvObj);
291 }
292
293 static ULONG WINAPI GraphBuilder_AddRef(IGraphBuilder *iface) {
294     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
295     
296     TRACE("(%p/%p)->() calling FilterGraph AddRef\n", This, iface);
297     
298     return Filtergraph_AddRef(This);
299 }
300
301 static ULONG WINAPI GraphBuilder_Release(IGraphBuilder *iface) {
302     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
303     
304     TRACE("(%p/%p)->() calling FilterGraph Release\n", This, iface);
305
306     return Filtergraph_Release(This);
307 }
308
309 /*** IFilterGraph methods ***/
310 static HRESULT WINAPI GraphBuilder_AddFilter(IGraphBuilder *iface,
311                                              IBaseFilter *pFilter,
312                                              LPCWSTR pName) {
313     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
314     HRESULT hr;
315     int i,j;
316     WCHAR* wszFilterName = NULL;
317     int duplicate_name = FALSE;
318     
319     TRACE("(%p/%p)->(%p, %s (%p))\n", This, iface, pFilter, debugstr_w(pName), pName);
320
321     wszFilterName = (WCHAR*) CoTaskMemAlloc( (pName ? strlenW(pName) + 6 : 5) * sizeof(WCHAR) );
322     
323     if (pName)
324     {
325         /* Check if name already exists */
326         for(i = 0; i < This->nFilters; i++)
327             if (!strcmpW(This->pFilterNames[i], pName))
328             {
329                 duplicate_name = TRUE;
330                 break;
331             }
332     }
333
334     /* If no name given or name already existing, generate one */
335     if (!pName || duplicate_name)
336     {
337         static const WCHAR wszFmt1[] = {'%','s',' ','%','0','4','d',0};
338         static const WCHAR wszFmt2[] = {'%','0','4','d',0};
339
340         for (j = 0; j < 10000 ; j++)
341         {
342             /* Create name */
343             if (pName)
344                 sprintfW(wszFilterName, wszFmt1, pName, This->nameIndex);
345             else
346                 sprintfW(wszFilterName, wszFmt2, This->nameIndex);
347             TRACE("Generated name %s\n", debugstr_w(wszFilterName));
348
349             /* Check if the generated name already exists */
350             for(i = 0; i < This->nFilters; i++)
351                 if (!strcmpW(This->pFilterNames[i], wszFilterName))
352                     break;
353
354             /* Compute next index and exit if generated name is suitable */
355             if (This->nameIndex++ == 10000)
356                 This->nameIndex = 1;
357             if (i == This->nFilters)
358                 break;
359         }
360         /* Unable to find a suitable name */
361         if (j == 10000)
362         {
363             CoTaskMemFree(wszFilterName);
364             return VFW_E_DUPLICATE_NAME;
365         }
366     }
367     else
368         memcpy(wszFilterName, pName, (strlenW(pName) + 1) * sizeof(WCHAR));
369
370     if (This->nFilters + 1 > This->filterCapacity)
371     {
372         int newCapacity = This->filterCapacity ? 2 * This->filterCapacity : 1;
373         IBaseFilter ** ppNewFilters = CoTaskMemAlloc(newCapacity * sizeof(IBaseFilter*));
374         LPWSTR * pNewNames = CoTaskMemAlloc(newCapacity * sizeof(LPWSTR));
375         memcpy(ppNewFilters, This->ppFiltersInGraph, This->nFilters * sizeof(IBaseFilter*));
376         memcpy(pNewNames, This->pFilterNames, This->nFilters * sizeof(LPWSTR));
377         if (!This->filterCapacity)
378         {
379             CoTaskMemFree(This->ppFiltersInGraph);
380             CoTaskMemFree(This->pFilterNames);
381         }
382         This->ppFiltersInGraph = ppNewFilters;
383         This->pFilterNames = pNewNames;
384         This->filterCapacity = newCapacity;
385     }
386
387     hr = IBaseFilter_JoinFilterGraph(pFilter, (IFilterGraph *)This, wszFilterName);
388
389     if (SUCCEEDED(hr))
390     {
391         IBaseFilter_AddRef(pFilter);
392         This->ppFiltersInGraph[This->nFilters] = pFilter;
393         This->pFilterNames[This->nFilters] = wszFilterName;
394         This->nFilters++;
395     }
396     else
397         CoTaskMemFree(wszFilterName);
398
399     if (SUCCEEDED(hr) && duplicate_name)
400         return VFW_S_DUPLICATE_NAME;
401         
402     return hr;
403 }
404
405 static HRESULT WINAPI GraphBuilder_RemoveFilter(IGraphBuilder *iface,
406                                                 IBaseFilter *pFilter) {
407     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
408     int i;
409     HRESULT hr = E_FAIL;
410
411     TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
412
413     /* FIXME: check graph is stopped */
414
415     for (i = 0; i < This->nFilters; i++)
416     {
417         if (This->ppFiltersInGraph[i] == pFilter)
418         {
419             IEnumPins *penumpins;
420             hr = IBaseFilter_EnumPins(pFilter, &penumpins);
421             if (SUCCEEDED(hr)) {
422                 IPin *ppin;
423                 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK) {
424                     IPin_Disconnect(ppin);
425                     IPin_Release(ppin);
426                 }
427                 IEnumPins_Release(penumpins);
428             }
429
430             hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, This->pFilterNames[i]);
431             if (SUCCEEDED(hr))
432             {
433                 IBaseFilter_Release(pFilter);
434                 CoTaskMemFree(This->pFilterNames[i]);
435                 memmove(This->ppFiltersInGraph+i, This->ppFiltersInGraph+i+1, sizeof(IBaseFilter*)*(This->nFilters - 1 - i));
436                 memmove(This->pFilterNames+i, This->pFilterNames+i+1, sizeof(LPWSTR)*(This->nFilters - 1 - i));
437                 This->nFilters--;
438                 /* Invalidate interfaces in the cache */
439                 for (i = 0; i < This->nItfCacheEntries; i++)
440                     if (pFilter == This->ItfCacheEntries[i].filter)
441                     {
442                         IUnknown_Release(This->ItfCacheEntries[i].iface);
443                         This->ItfCacheEntries[i].iface = NULL;
444                         This->ItfCacheEntries[i].filter = NULL;
445                     }
446                 return S_OK;
447             }
448             break;
449         }
450     }
451
452     return hr; /* FIXME: check this error code */
453 }
454
455 static HRESULT WINAPI GraphBuilder_EnumFilters(IGraphBuilder *iface,
456                                               IEnumFilters **ppEnum) {
457     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
458
459     TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
460
461     return IEnumFiltersImpl_Construct(This->ppFiltersInGraph, This->nFilters, ppEnum);
462 }
463
464 static HRESULT WINAPI GraphBuilder_FindFilterByName(IGraphBuilder *iface,
465                                                     LPCWSTR pName,
466                                                     IBaseFilter **ppFilter) {
467     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
468     int i;
469
470     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_w(pName), pName, ppFilter);
471
472     *ppFilter = NULL;
473
474     for (i = 0; i < This->nFilters; i++)
475     {
476         if (!strcmpW(pName, This->pFilterNames[i]))
477         {
478             *ppFilter = This->ppFiltersInGraph[i];
479             IBaseFilter_AddRef(*ppFilter);
480             return S_OK;
481         }
482     }
483
484     return E_FAIL; /* FIXME: check this error code */
485 }
486
487 /* NOTE: despite the implication, it doesn't matter which
488  * way round you put in the input and output pins */
489 static HRESULT WINAPI GraphBuilder_ConnectDirect(IGraphBuilder *iface,
490                                                  IPin *ppinIn,
491                                                  IPin *ppinOut,
492                                                  const AM_MEDIA_TYPE *pmt) {
493     PIN_DIRECTION dir;
494     HRESULT hr;
495
496     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
497
498     TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
499
500     /* FIXME: check pins are in graph */
501
502     if (TRACE_ON(quartz))
503     {
504         PIN_INFO PinInfo;
505
506         hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
507         if (FAILED(hr))
508             return hr;
509
510         TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
511         IBaseFilter_Release(PinInfo.pFilter);
512
513         hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
514         if (FAILED(hr))
515             return hr;
516
517         TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
518         IBaseFilter_Release(PinInfo.pFilter);
519     }
520
521     hr = IPin_QueryDirection(ppinIn, &dir);
522     if (SUCCEEDED(hr))
523     {
524         if (dir == PINDIR_INPUT)
525             hr = IPin_Connect(ppinOut, ppinIn, pmt);
526         else
527             hr = IPin_Connect(ppinIn, ppinOut, pmt);
528     }
529
530     return hr;
531 }
532
533 static HRESULT WINAPI GraphBuilder_Reconnect(IGraphBuilder *iface,
534                                              IPin *ppin) {
535     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
536     IPin *pConnectedTo = NULL;
537     HRESULT hr;
538     PIN_DIRECTION pindir;
539
540     IPin_QueryDirection(ppin, &pindir);
541     hr = IPin_ConnectedTo(ppin, &pConnectedTo);
542     if (FAILED(hr)) {
543         TRACE("Querying connected to failed: %x\n", hr);
544         return hr; 
545     }
546     IPin_Disconnect(ppin);
547     IPin_Disconnect(pConnectedTo);
548     if (pindir == PINDIR_INPUT)
549         hr = IPin_Connect(pConnectedTo, ppin, NULL);
550     else
551         hr = IPin_Connect(ppin, pConnectedTo, NULL);
552     IPin_Release(pConnectedTo);
553     if (FAILED(hr))
554         ERR("Reconnecting pins failed, pins are not connected now..\n");
555     TRACE("(%p->%p) -- %p %p -> %x\n", iface, This, ppin, pConnectedTo, hr);
556     return hr;
557 }
558
559 static HRESULT WINAPI GraphBuilder_Disconnect(IGraphBuilder *iface,
560                                               IPin *ppin) {
561     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
562
563     TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
564
565     return IPin_Disconnect(ppin);
566 }
567
568 static HRESULT WINAPI GraphBuilder_SetDefaultSyncSource(IGraphBuilder *iface) {
569     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
570
571     TRACE("(%p/%p)->(): stub !!!\n", iface, This);
572
573     return S_OK;
574 }
575
576 static HRESULT GetFilterInfo(IMoniker* pMoniker, GUID* pclsid, VARIANT* pvar)
577 {
578     static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
579     static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
580     IPropertyBag * pPropBagCat = NULL;
581     HRESULT hr;
582
583     VariantInit(pvar);
584     V_VT(pvar) = VT_BSTR;
585
586     hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
587
588     if (SUCCEEDED(hr))
589         hr = IPropertyBag_Read(pPropBagCat, wszClsidName, pvar, NULL);
590
591     if (SUCCEEDED(hr))
592         hr = CLSIDFromString(V_UNION(pvar, bstrVal), pclsid);
593
594     if (SUCCEEDED(hr))
595         hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL);
596
597     if (SUCCEEDED(hr))
598         TRACE("Moniker = %s - %s\n", debugstr_guid(pclsid), debugstr_w(V_UNION(pvar, bstrVal)));
599
600     if (pPropBagCat)
601         IPropertyBag_Release(pPropBagCat);
602
603     return hr;
604 }
605
606 static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPin*** pppins, ULONG* pnb)
607 {
608     HRESULT hr;
609     ULONG nb = 0;
610
611     TRACE("(%p, %p, %p, %p)\n", pfilter, pinputpin, pppins, pnb);
612     hr = IPin_QueryInternalConnections(pinputpin, NULL, &nb);
613     if (hr == S_OK) {
614         /* Rendered input */
615     } else if (hr == S_FALSE) {
616         *pppins = CoTaskMemAlloc(sizeof(IPin*)*nb);
617         hr = IPin_QueryInternalConnections(pinputpin, *pppins, &nb);
618         if (hr != S_OK) {
619             ERR("Error (%x)\n", hr);
620         }
621     } else if (hr == E_NOTIMPL) {
622         /* Input connected to all outputs */
623         IEnumPins* penumpins;
624         IPin* ppin;
625         int i = 0;
626         TRACE("E_NOTIMPL\n");
627         hr = IBaseFilter_EnumPins(pfilter, &penumpins);
628         if (FAILED(hr)) {
629             ERR("filter Enumpins failed (%x)\n", hr);
630             return hr;
631         }
632         i = 0;
633         /* Count output pins */
634         while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
635             PIN_DIRECTION pindir;
636             IPin_QueryDirection(ppin, &pindir);
637             if (pindir == PINDIR_OUTPUT)
638                 i++;
639             IPin_Release(ppin);
640         }
641         *pppins = CoTaskMemAlloc(sizeof(IPin*)*i);
642         /* Retrieve output pins */
643         IEnumPins_Reset(penumpins);
644         i = 0;
645         while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
646             PIN_DIRECTION pindir;
647             IPin_QueryDirection(ppin, &pindir);
648             if (pindir == PINDIR_OUTPUT)
649                 (*pppins)[i++] = ppin;
650             else
651                 IPin_Release(ppin);
652         }
653         IEnumPins_Release(penumpins);
654         nb = i;
655         if (FAILED(hr)) {
656             ERR("Next failed (%x)\n", hr);
657             return hr;
658         }
659     } else if (FAILED(hr)) {
660         ERR("Cannot get internal connection (%x)\n", hr);
661         return hr;
662     }
663
664     *pnb = nb;
665     return S_OK;
666 }
667
668 /*** IGraphBuilder methods ***/
669 static HRESULT WINAPI GraphBuilder_Connect(IGraphBuilder *iface,
670                                            IPin *ppinOut,
671                                            IPin *ppinIn) {
672     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
673     HRESULT hr;
674     AM_MEDIA_TYPE* mt;
675     IEnumMediaTypes* penummt;
676     ULONG nbmt;
677     IEnumPins* penumpins;
678     IEnumMoniker* pEnumMoniker;
679     GUID tab[2];
680     ULONG nb;
681     IMoniker* pMoniker;
682     ULONG pin;
683     PIN_INFO PinInfo;
684     CLSID FilterCLSID;
685
686     TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
687
688     if (TRACE_ON(quartz))
689     {
690         hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
691         if (FAILED(hr))
692             return hr;
693
694         TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
695         IBaseFilter_Release(PinInfo.pFilter);
696
697         hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
698         if (FAILED(hr))
699             return hr;
700
701         TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
702         IBaseFilter_Release(PinInfo.pFilter);
703     }
704
705     /* Try direct connection first */
706     hr = IPin_Connect(ppinOut, ppinIn, NULL);
707     if (SUCCEEDED(hr)) {
708         return S_OK;
709     }
710     TRACE("Direct connection failed, trying to insert other filters\n");
711
712     hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
713     if (FAILED(hr))
714        return hr;
715
716     hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
717     IBaseFilter_Release(PinInfo.pFilter);
718     if (FAILED(hr))
719        return hr;
720
721     /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream 
722      * filter to the minor mediatype of input pin of the renderer */
723     hr = IPin_EnumMediaTypes(ppinOut, &penummt);
724     if (FAILED(hr)) {
725         ERR("EnumMediaTypes (%x)\n", hr);
726         return hr;
727     }
728
729     hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
730     if (FAILED(hr)) {
731         ERR("IEnumMediaTypes_Next (%x)\n", hr);
732         return hr;
733     }
734
735     if (!nbmt) {
736         ERR("No media type found!\n");
737         return S_OK;
738     }
739     TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
740     TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
741
742     /* Try to find a suitable filter that can connect to the pin to render */
743     tab[0] = mt->majortype;
744     tab[1] = mt->subtype;
745     hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, 0, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
746     if (FAILED(hr)) {
747         ERR("Unable to enum filters (%x)\n", hr);
748         return hr;
749     }
750     
751     while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
752     {
753         VARIANT var;
754         GUID clsid;
755         IPin** ppins;
756         IPin* ppinfilter = NULL;
757         IBaseFilter* pfilter = NULL;
758
759         hr = GetFilterInfo(pMoniker, &clsid, &var);
760         IMoniker_Release(pMoniker);
761         if (FAILED(hr)) {
762             ERR("Unable to retrieve filter info (%x)\n", hr);
763             goto error;
764         }
765
766         if (IsEqualGUID(&clsid, &FilterCLSID)) {
767             /* Skip filter (same as the one the output pin belongs to) */
768             goto error;
769         }
770
771         hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
772         if (FAILED(hr)) {
773             ERR("Unable to create filter (%x), trying next one\n", hr);
774             goto error;
775         }
776
777         hr = IGraphBuilder_AddFilter(iface, pfilter, NULL);
778         if (FAILED(hr)) {
779             ERR("Unable to add filter (%x)\n", hr);
780             IBaseFilter_Release(pfilter);
781             pfilter = NULL;
782             goto error;
783         }
784
785         hr = IBaseFilter_EnumPins(pfilter, &penumpins);
786         if (FAILED(hr)) {
787             ERR("Enumpins (%x)\n", hr);
788             goto error;
789         }
790
791         hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin);
792         IEnumPins_Release(penumpins);
793
794         if (FAILED(hr)) {
795             ERR("Next (%x)\n", hr);
796             goto error;
797         }
798         if (pin == 0) {
799             ERR("No Pin\n");
800             goto error;
801         }
802
803         hr = IPin_Connect(ppinOut, ppinfilter, NULL);
804         if (FAILED(hr)) {
805             TRACE("Cannot connect to filter (%x), trying next one\n", hr);
806             goto error;
807         }
808         TRACE("Successfully connected to filter, follow chain...\n");
809
810         /* Render all output pins of the filter by calling IGraphBuilder_Render on each of them */
811         hr = GetInternalConnections(pfilter, ppinfilter, &ppins, &nb);
812
813         if (SUCCEEDED(hr)) {
814             int i;
815             if (nb == 0) {
816                 IPin_Disconnect(ppinOut);
817                 goto error;
818             }
819             TRACE("pins to consider: %d\n", nb);
820             for(i = 0; i < nb; i++) {
821                 TRACE("Processing pin %d\n", i);
822                 hr = IGraphBuilder_Connect(iface, ppins[i], ppinIn);
823                 if (FAILED(hr)) {
824                    TRACE("Cannot render pin %p (%x)\n", ppinfilter, hr);
825                 }
826                 IPin_Release(ppins[i]);
827                 if (SUCCEEDED(hr)) break;
828             }
829             while (++i < nb) IPin_Release(ppins[i]);
830             CoTaskMemFree(ppins);
831             IPin_Release(ppinfilter);
832             IBaseFilter_Release(pfilter);
833             break;
834         }
835
836 error:
837         if (ppinfilter) IPin_Release(ppinfilter);
838         if (pfilter) {
839             IGraphBuilder_RemoveFilter(iface, pfilter);
840             IBaseFilter_Release(pfilter);
841         }
842     }
843
844     IEnumMediaTypes_Release(penummt);
845     DeleteMediaType(mt);
846     
847     return S_OK;
848 }
849
850 static HRESULT WINAPI GraphBuilder_Render(IGraphBuilder *iface,
851                                           IPin *ppinOut) {
852     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
853     IEnumMediaTypes* penummt;
854     AM_MEDIA_TYPE* mt;
855     ULONG nbmt;
856     HRESULT hr;
857
858     IEnumMoniker* pEnumMoniker;
859     GUID tab[2];
860     ULONG nb;
861     IMoniker* pMoniker;
862
863     TRACE("(%p/%p)->(%p)\n", This, iface, ppinOut);
864
865     if (TRACE_ON(quartz))
866     {
867         PIN_INFO PinInfo;
868
869         hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
870         if (FAILED(hr))
871             return hr;
872
873         TRACE("Filter owning pin => %p\n", PinInfo.pFilter);
874         IBaseFilter_Release(PinInfo.pFilter);
875     }
876
877     hr = IPin_EnumMediaTypes(ppinOut, &penummt);
878     if (FAILED(hr)) {
879         ERR("EnumMediaTypes (%x)\n", hr);
880         return hr;
881     }
882
883     while(1)
884     {
885         hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
886         if (FAILED(hr)) {
887             ERR("IEnumMediaTypes_Next (%x)\n", hr);
888             return hr;
889         }
890         if (!nbmt)
891             break;
892         TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
893         TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
894
895         /* Try to find a suitable renderer with the same media type */
896         tab[0] = mt->majortype;
897         tab[1] = GUID_NULL;
898         hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, 0, TRUE, 1, tab, NULL, NULL, TRUE, FALSE, 0, NULL, NULL, NULL);
899         if (FAILED(hr)) {
900             ERR("Unable to enum filters (%x)\n", hr);
901             return hr;
902         }
903
904         while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
905         {
906             VARIANT var;
907             GUID clsid;
908             IPin* ppinfilter;
909             IBaseFilter* pfilter = NULL;
910             IEnumPins* penumpins;
911             ULONG pin;
912
913             hr = GetFilterInfo(pMoniker, &clsid, &var);
914             IMoniker_Release(pMoniker);
915             if (FAILED(hr)) {
916                 ERR("Unable to retrieve filter info (%x)\n", hr);
917                 goto error;
918             }
919
920             hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
921             if (FAILED(hr)) {
922                ERR("Unable to create filter (%x), trying next one\n", hr);
923                goto error;
924             }
925
926             hr = IGraphBuilder_AddFilter(iface, pfilter, NULL);
927             if (FAILED(hr)) {
928                 ERR("Unable to add filter (%x)\n", hr);
929                 IBaseFilter_Release(pfilter);
930                 pfilter = NULL;
931                 goto error;
932             }
933
934             hr = IBaseFilter_EnumPins(pfilter, &penumpins);
935             if (FAILED(hr)) {
936                 ERR("Splitter Enumpins (%x)\n", hr);
937                 goto error;
938             }
939             hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin);
940             IEnumPins_Release(penumpins);
941             if (FAILED(hr)) {
942                ERR("Next (%x)\n", hr);
943                goto error;
944             }
945             if (pin == 0) {
946                ERR("No Pin\n");
947                goto error;
948             }
949
950             /* Connect the pin to render to the renderer */
951             hr = IGraphBuilder_Connect(iface, ppinOut, ppinfilter);
952             if (FAILED(hr)) {
953                 TRACE("Unable to connect to renderer (%x)\n", hr);
954                 IPin_Release(ppinfilter);
955                 goto error;
956             }
957             IPin_Release(ppinfilter);
958             IBaseFilter_Release(pfilter);
959             pfilter = NULL;
960             break;
961
962 error:
963             if (pfilter) {
964                 IGraphBuilder_RemoveFilter(iface, pfilter);
965                 IBaseFilter_Release(pfilter);
966             }
967         }
968        
969         DeleteMediaType(mt);
970         break;  
971     }
972
973     IEnumMediaTypes_Release(penummt);
974     
975     return S_OK;
976 }
977
978 static HRESULT WINAPI GraphBuilder_RenderFile(IGraphBuilder *iface,
979                                               LPCWSTR lpcwstrFile,
980                                               LPCWSTR lpcwstrPlayList) {
981     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
982     static const WCHAR string[] = {'R','e','a','d','e','r',0};
983     IBaseFilter* preader = NULL;
984     IBaseFilter* psplitter = NULL;
985     IPin* ppinreader = NULL;
986     IPin* ppinsplitter;
987     IEnumPins* penumpins;
988     ULONG pin;
989     HRESULT hr;
990     IEnumMoniker* pEnumMoniker = NULL;
991     GUID tab[2];
992     IPin** ppins = NULL;
993     ULONG nb;
994     IMoniker* pMoniker;
995     IFileSourceFilter* pfile = NULL;
996     AM_MEDIA_TYPE mt;
997     WCHAR* filename;
998
999     TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1000
1001     if (lpcwstrPlayList != NULL)
1002         return E_INVALIDARG;
1003
1004     hr = IGraphBuilder_AddSourceFilter(iface, lpcwstrFile, string, &preader);
1005
1006     /* Retrieve file media type */
1007     if (SUCCEEDED(hr))
1008         hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1009     if (SUCCEEDED(hr)) {
1010         hr = IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1011         IFileSourceFilter_Release(pfile);
1012     }
1013
1014     if (SUCCEEDED(hr))
1015         hr = IBaseFilter_EnumPins(preader, &penumpins);
1016     if (SUCCEEDED(hr)) {
1017         hr = IEnumPins_Next(penumpins, 1, &ppinreader, &pin);
1018         IEnumPins_Release(penumpins);
1019     }
1020
1021     if (SUCCEEDED(hr)) {
1022         tab[0] = mt.majortype;
1023         tab[1] = mt.subtype;
1024         hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, 0, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1025     }
1026
1027     if (FAILED(hr))
1028     {
1029         if (ppinreader)
1030             IPin_Release(ppinreader);
1031         if (pEnumMoniker)
1032             IEnumMoniker_Release(pEnumMoniker);
1033         if (preader) {
1034              IGraphBuilder_RemoveFilter(iface, preader);
1035              IBaseFilter_Release(preader);
1036         }
1037         return hr;
1038     }
1039
1040     hr = VFW_E_CANNOT_RENDER;
1041     while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1042     {
1043         VARIANT var;
1044         GUID clsid;
1045
1046         hr = GetFilterInfo(pMoniker, &clsid, &var);
1047         IMoniker_Release(pMoniker);
1048         if (FAILED(hr)) {
1049             ERR("Unable to retrieve filter info (%x)\n", hr);
1050             continue;
1051         }
1052
1053         hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&psplitter);
1054         if (FAILED(hr)) {
1055            ERR("Unable to create filter (%x), trying next one\n", hr);
1056            continue;
1057         }
1058
1059         hr = IGraphBuilder_AddFilter(iface, psplitter, NULL);
1060         if (FAILED(hr)) {
1061             ERR("Unable add filter (%x)\n", hr);
1062             IBaseFilter_Release(psplitter);
1063             continue;
1064         }
1065
1066         /* Connect file source and splitter filters together */
1067         /* Make the splitter analyze incoming data */
1068
1069         hr = IBaseFilter_EnumPins(psplitter, &penumpins);
1070         if (SUCCEEDED(hr)) {
1071             hr = IEnumPins_Next(penumpins, 1, &ppinsplitter, &pin);
1072             IEnumPins_Release(penumpins);
1073         }
1074
1075         if (SUCCEEDED(hr))
1076             hr = IPin_Connect(ppinreader, ppinsplitter, NULL);
1077
1078         /* Make sure there's some output pins in the filter */
1079         if (SUCCEEDED(hr))
1080             hr = GetInternalConnections(psplitter, ppinsplitter, &ppins, &nb);
1081         if (SUCCEEDED(hr)) {
1082             if(nb == 0) {
1083                 IPin_Disconnect(ppinreader);
1084                 TRACE("No output pins found in filter\n");
1085                 hr = VFW_E_CANNOT_RENDER;
1086             }
1087         }
1088
1089         if (ppinsplitter)
1090             IPin_Release(ppinsplitter);
1091         ppinsplitter = NULL;
1092
1093         if (SUCCEEDED(hr)) {
1094             TRACE("Successfully connected to filter\n");
1095             break;
1096         }
1097
1098         TRACE("Cannot connect to filter (%x), trying next one\n", hr);
1099
1100         if (ppins) {
1101             CoTaskMemFree(ppins);
1102             ppins = NULL;
1103         }
1104         IGraphBuilder_RemoveFilter(iface, psplitter);
1105         IBaseFilter_Release(psplitter);
1106         psplitter = NULL;
1107     }
1108
1109     /* Render all output pin of the splitter by calling IGraphBuilder_Render on each of them */
1110     if (SUCCEEDED(hr)) {
1111         int partial = 0;
1112         int i;
1113         TRACE("pins to consider: %d\n", nb);
1114         for(i = 0; i < nb; i++) {
1115             TRACE("Processing pin %d\n", i);
1116             hr = IGraphBuilder_Render(iface, ppins[i]);
1117             if (FAILED(hr)) {
1118                 ERR("Cannot render pin %p (%x)\n", ppins[i], hr);
1119                 partial = 1;
1120             }
1121             IPin_Release(ppins[i]);
1122         }
1123         CoTaskMemFree(ppins);
1124
1125         hr = (partial ? VFW_S_PARTIAL_RENDER : S_OK);
1126     }
1127
1128     IPin_Release(ppinreader);
1129     IBaseFilter_Release(preader);
1130     if (psplitter)
1131         IBaseFilter_Release(psplitter);
1132
1133     return hr;
1134 }
1135
1136 static HRESULT WINAPI GraphBuilder_AddSourceFilter(IGraphBuilder *iface,
1137                                                    LPCWSTR lpcwstrFileName,
1138                                                    LPCWSTR lpcwstrFilterName,
1139                                                    IBaseFilter **ppFilter) {
1140     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
1141     HRESULT hr;
1142     IBaseFilter* preader;
1143     IFileSourceFilter* pfile = NULL;
1144     AM_MEDIA_TYPE mt;
1145     WCHAR* filename;
1146
1147     TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1148
1149     /* Instantiate a file source filter */ 
1150     hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&preader);
1151     if (FAILED(hr)) {
1152         ERR("Unable to create file source filter (%x)\n", hr);
1153         return hr;
1154     }
1155
1156     hr = IGraphBuilder_AddFilter(iface, preader, lpcwstrFilterName);
1157     if (FAILED(hr)) {
1158         ERR("Unable add filter (%x)\n", hr);
1159         IBaseFilter_Release(preader);
1160         return hr;
1161     }
1162
1163     hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1164     if (FAILED(hr)) {
1165         ERR("Unable to get IFileSourceInterface (%x)\n", hr);
1166         goto error;
1167     }
1168
1169     /* Load the file in the file source filter */
1170     hr = IFileSourceFilter_Load(pfile, lpcwstrFileName, NULL);
1171     if (FAILED(hr)) {
1172         ERR("Load (%x)\n", hr);
1173         goto error;
1174     }
1175     
1176     IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1177     if (FAILED(hr)) {
1178         ERR("GetCurFile (%x)\n", hr);
1179         goto error;
1180     }
1181     TRACE("File %s\n", debugstr_w(filename));
1182     TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
1183     TRACE("SubType %s\n", debugstr_guid(&mt.subtype));
1184
1185     if (ppFilter)
1186         *ppFilter = preader;
1187     IFileSourceFilter_Release(pfile);
1188
1189     return S_OK;
1190     
1191 error:
1192     if (pfile)
1193         IFileSourceFilter_Release(pfile);
1194     IGraphBuilder_RemoveFilter(iface, preader);
1195     IBaseFilter_Release(preader);
1196        
1197     return hr;
1198 }
1199
1200 static HRESULT WINAPI GraphBuilder_SetLogFile(IGraphBuilder *iface,
1201                                               DWORD_PTR hFile) {
1202     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
1203
1204     TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1205
1206     return S_OK;
1207 }
1208
1209 static HRESULT WINAPI GraphBuilder_Abort(IGraphBuilder *iface) {
1210     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
1211
1212     TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1213
1214     return S_OK;
1215 }
1216
1217 static HRESULT WINAPI GraphBuilder_ShouldOperationContinue(IGraphBuilder *iface) {
1218     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphBuilder_vtbl, iface);
1219
1220     TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1221
1222     return S_OK;
1223 }
1224
1225
1226 static const IGraphBuilderVtbl IGraphBuilder_VTable =
1227 {
1228     GraphBuilder_QueryInterface,
1229     GraphBuilder_AddRef,
1230     GraphBuilder_Release,
1231     GraphBuilder_AddFilter,
1232     GraphBuilder_RemoveFilter,
1233     GraphBuilder_EnumFilters,
1234     GraphBuilder_FindFilterByName,
1235     GraphBuilder_ConnectDirect,
1236     GraphBuilder_Reconnect,
1237     GraphBuilder_Disconnect,
1238     GraphBuilder_SetDefaultSyncSource,
1239     GraphBuilder_Connect,
1240     GraphBuilder_Render,
1241     GraphBuilder_RenderFile,
1242     GraphBuilder_AddSourceFilter,
1243     GraphBuilder_SetLogFile,
1244     GraphBuilder_Abort,
1245     GraphBuilder_ShouldOperationContinue
1246 };
1247
1248 /*** IUnknown methods ***/
1249 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface,
1250                                                   REFIID riid,
1251                                                   LPVOID*ppvObj) {
1252     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1253
1254     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1255
1256     return Filtergraph_QueryInterface(This, riid, ppvObj);
1257 }
1258
1259 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface) {
1260     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1261
1262     TRACE("(%p/%p)->()\n", This, iface);
1263
1264     return Filtergraph_AddRef(This);
1265 }
1266
1267 static ULONG WINAPI MediaControl_Release(IMediaControl *iface) {
1268     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1269
1270     TRACE("(%p/%p)->()\n", This, iface);
1271
1272     return Filtergraph_Release(This);
1273
1274 }
1275
1276 /*** IDispatch methods ***/
1277 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface,
1278                                                     UINT*pctinfo) {
1279     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1280
1281     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1282
1283     return S_OK;
1284 }
1285
1286 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface,
1287                                                UINT iTInfo,
1288                                                LCID lcid,
1289                                                ITypeInfo**ppTInfo) {
1290     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1291
1292     TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1293
1294     return S_OK;
1295 }
1296
1297 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface,
1298                                                  REFIID riid,
1299                                                  LPOLESTR*rgszNames,
1300                                                  UINT cNames,
1301                                                  LCID lcid,
1302                                                  DISPID*rgDispId) {
1303     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1304
1305     TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1306
1307     return S_OK;
1308 }
1309
1310 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface,
1311                                           DISPID dispIdMember,
1312                                           REFIID riid,
1313                                           LCID lcid,
1314                                           WORD wFlags,
1315                                           DISPPARAMS*pDispParams,
1316                                           VARIANT*pVarResult,
1317                                           EXCEPINFO*pExepInfo,
1318                                           UINT*puArgErr) {
1319     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1320
1321     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);
1322
1323     return S_OK;
1324 }
1325
1326 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *);
1327
1328 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter)
1329 {
1330     HRESULT hr;
1331     IPin* pInputPin;
1332     IPin** ppPins;
1333     ULONG nb;
1334     ULONG i;
1335     PIN_INFO PinInfo;
1336
1337     TRACE("%p %p\n", pGraph, pOutputPin);
1338     PinInfo.pFilter = NULL;
1339
1340     hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1341
1342     if (SUCCEEDED(hr))
1343     {
1344         hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1345         if (SUCCEEDED(hr))
1346             hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1347         IPin_Release(pInputPin);
1348     }
1349
1350     if (SUCCEEDED(hr))
1351     {
1352         if (nb == 0)
1353         {
1354             TRACE("Reached a renderer\n");
1355             /* Count renderers for end of stream notification */
1356             pGraph->nRenderers++;
1357         }
1358         else
1359         {
1360             for(i = 0; i < nb; i++)
1361             {
1362                 /* Explore the graph downstream from this pin
1363                  * FIXME: We should prevent exploring from a pin more than once. This can happens when
1364                  * several input pins are connected to the same output (a MUX for instance). */
1365                 ExploreGraph(pGraph, ppPins[i], FoundFilter);
1366                 IPin_Release(ppPins[i]);
1367             }
1368
1369             CoTaskMemFree(ppPins);
1370         }
1371         TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1372         FoundFilter(PinInfo.pFilter);
1373     }
1374
1375     if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1376     return hr;
1377 }
1378
1379 static HRESULT WINAPI SendRun(IBaseFilter *pFilter) {
1380    return IBaseFilter_Run(pFilter, 0);
1381 }
1382
1383 static HRESULT WINAPI SendPause(IBaseFilter *pFilter) {
1384    return IBaseFilter_Pause(pFilter);
1385 }
1386
1387 static HRESULT WINAPI SendStop(IBaseFilter *pFilter) {
1388    return IBaseFilter_Stop(pFilter);
1389 }
1390
1391 static HRESULT SendFilterMessage(IMediaControl *iface, fnFoundFilter FoundFilter) {
1392     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1393     int i;
1394     IBaseFilter* pfilter;
1395     IEnumPins* pEnum;
1396     HRESULT hr;
1397     IPin* pPin;
1398     DWORD dummy;
1399     PIN_DIRECTION dir;
1400     TRACE("(%p/%p)->()\n", This, iface);
1401
1402     /* Explorer the graph from source filters to renderers, determine renderers
1403      * number and run filters from renderers to source filters */
1404     This->nRenderers = 0;  
1405     ResetEvent(This->hEventCompletion);
1406
1407     for(i = 0; i < This->nFilters; i++)
1408     {
1409         BOOL source = TRUE;
1410         pfilter = This->ppFiltersInGraph[i];
1411         hr = IBaseFilter_EnumPins(pfilter, &pEnum);
1412         if (hr != S_OK)
1413         {
1414             ERR("Enum pins failed %x\n", hr);
1415             continue;
1416         }
1417         /* Check if it is a source filter */
1418         while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1419         {
1420             IPin_QueryDirection(pPin, &dir);
1421             IPin_Release(pPin);
1422             if (dir == PINDIR_INPUT)
1423             {
1424                 source = FALSE;
1425                 break;
1426             }
1427         }
1428         if (source)
1429         {
1430             TRACE("Found a source filter %p\n", pfilter);
1431             IEnumPins_Reset(pEnum);
1432             while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1433             {
1434                 /* Explore the graph downstream from this pin */
1435                 ExploreGraph(This, pPin, FoundFilter);
1436                 IPin_Release(pPin);
1437             }
1438             FoundFilter(pfilter);
1439         }
1440         IEnumPins_Release(pEnum);
1441     }
1442
1443     return S_FALSE;
1444 }
1445
1446 /*** IMediaControl methods ***/
1447 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface) {
1448     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1449     TRACE("(%p/%p)->()\n", This, iface);
1450
1451     if (This->state == State_Running) return S_OK;
1452
1453     EnterCriticalSection(&This->cs);
1454     SendFilterMessage(iface, SendRun);
1455     This->state = State_Running;
1456     LeaveCriticalSection(&This->cs);
1457     return S_FALSE;
1458 }
1459
1460 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface) {
1461     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1462     TRACE("(%p/%p)->()\n", This, iface);
1463
1464     if (This->state == State_Paused) return S_OK;
1465
1466     EnterCriticalSection(&This->cs);
1467     SendFilterMessage(iface, SendPause);
1468     This->state = State_Paused;
1469     LeaveCriticalSection(&This->cs);
1470     return S_FALSE;
1471 }
1472
1473 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface) {
1474     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1475     TRACE("(%p/%p)->()\n", This, iface);
1476
1477     if (This->state == State_Stopped) return S_OK;
1478
1479     EnterCriticalSection(&This->cs);
1480     if (This->state == State_Running) SendFilterMessage(iface, SendPause);
1481     SendFilterMessage(iface, SendStop);
1482     This->state = State_Stopped;
1483     LeaveCriticalSection(&This->cs);
1484     return S_FALSE;
1485 }
1486
1487 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface,
1488                                             LONG msTimeout,
1489                                             OAFilterState *pfs) {
1490     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1491
1492     TRACE("(%p/%p)->(%d, %p): semi-stub !!!\n", This, iface, msTimeout, pfs);
1493
1494     EnterCriticalSection(&This->cs);
1495
1496     *pfs = This->state;
1497
1498     LeaveCriticalSection(&This->cs);
1499
1500     return S_OK;
1501 }
1502
1503 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface,
1504                                               BSTR strFilename) {
1505     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1506
1507     TRACE("(%p/%p)->(%s (%p)): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename);
1508
1509     return S_OK;
1510 }
1511
1512 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface,
1513                                                    BSTR strFilename,
1514                                                    IDispatch **ppUnk) {
1515     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1516
1517     TRACE("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
1518
1519     return S_OK;
1520 }
1521
1522 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface,
1523                                                         IDispatch **ppUnk) {
1524     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1525
1526     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
1527
1528     return S_OK;
1529 }
1530
1531 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface,
1532                                                            IDispatch **ppUnk) {
1533     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1534
1535     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
1536
1537     return S_OK;
1538 }
1539
1540 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface) {
1541     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1542
1543     TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1544
1545     return S_OK;
1546 }
1547
1548
1549 static const IMediaControlVtbl IMediaControl_VTable =
1550 {
1551     MediaControl_QueryInterface,
1552     MediaControl_AddRef,
1553     MediaControl_Release,
1554     MediaControl_GetTypeInfoCount,
1555     MediaControl_GetTypeInfo,
1556     MediaControl_GetIDsOfNames,
1557     MediaControl_Invoke,
1558     MediaControl_Run,
1559     MediaControl_Pause,
1560     MediaControl_Stop,
1561     MediaControl_GetState,
1562     MediaControl_RenderFile,
1563     MediaControl_AddSourceFilter,
1564     MediaControl_get_FilterCollection,
1565     MediaControl_get_RegFilterCollection,
1566     MediaControl_StopWhenReady
1567 };
1568
1569
1570 /*** IUnknown methods ***/
1571 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface,
1572                                                   REFIID riid,
1573                                                   LPVOID*ppvObj) {
1574     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1575
1576     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1577
1578     return Filtergraph_QueryInterface(This, riid, ppvObj);
1579 }
1580
1581 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface) {
1582     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1583
1584     TRACE("(%p/%p)->()\n", This, iface);
1585
1586     return Filtergraph_AddRef(This);
1587 }
1588
1589 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface) {
1590     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1591
1592     TRACE("(%p/%p)->()\n", This, iface);
1593
1594     return Filtergraph_Release(This);
1595 }
1596
1597 /*** IMediaSeeking methods ***/
1598 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface,
1599                                                    DWORD *pCapabilities) {
1600     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1601
1602     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pCapabilities);
1603
1604     return S_OK;
1605 }
1606
1607 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface,
1608                                                      DWORD *pCapabilities) {
1609     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1610
1611     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pCapabilities);
1612
1613     return S_OK;
1614 }
1615
1616 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface,
1617                                                      const GUID *pFormat) {
1618     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1619
1620     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pFormat);
1621
1622     return S_OK;
1623 }
1624
1625 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface,
1626                                                         GUID *pFormat) {
1627     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1628
1629     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pFormat);
1630
1631     return S_OK;
1632 }
1633
1634 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface,
1635                                                  GUID *pFormat) {
1636     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1637
1638     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pFormat);
1639
1640     return S_OK;
1641 }
1642
1643 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface,
1644                                                      const GUID *pFormat) {
1645     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1646
1647     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pFormat);
1648
1649     return S_OK;
1650 }
1651
1652 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface,
1653                                                  const GUID *pFormat) {
1654     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1655
1656     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pFormat);
1657
1658     return S_OK;
1659 }
1660
1661 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface,
1662                                                LONGLONG *pDuration) {
1663     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1664
1665     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pDuration);
1666
1667     return S_OK;
1668 }
1669
1670 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface,
1671                                                    LONGLONG *pStop) {
1672     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1673
1674     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pStop);
1675
1676     return S_OK;
1677 }
1678
1679 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface,
1680                                                       LONGLONG *pCurrent) {
1681     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1682
1683     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pCurrent);
1684
1685     return S_OK;
1686 }
1687
1688 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface,
1689                                                      LONGLONG *pTarget,
1690                                                      const GUID *pTargetFormat,
1691                                                      LONGLONG Source,
1692                                                      const GUID *pSourceFormat) {
1693     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1694
1695     TRACE("(%p/%p)->(%p, %p, 0x%s, %p): stub !!!\n", This, iface, pTarget,
1696         pTargetFormat, wine_dbgstr_longlong(Source), pSourceFormat);
1697
1698     return S_OK;
1699 }
1700
1701 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface,
1702                                                 LONGLONG *pCurrent,
1703                                                 DWORD dwCurrentFlags,
1704                                                 LONGLONG *pStop,
1705                                                 DWORD dwStopFlags) {
1706     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1707
1708     TRACE("(%p/%p)->(%p, %08x, %p, %08x): stub !!!\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
1709
1710     return S_OK;
1711 }
1712
1713 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface,
1714                                                 LONGLONG *pCurrent,
1715                                                 LONGLONG *pStop) {
1716     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1717
1718     TRACE("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pCurrent, pStop);
1719
1720     return S_OK;
1721 }
1722
1723 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface,
1724                                                 LONGLONG *pEarliest,
1725                                                 LONGLONG *pLatest) {
1726     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1727
1728     TRACE("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
1729
1730     return S_OK;
1731 }
1732
1733 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface,
1734                                            double dRate) {
1735     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1736
1737     TRACE("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
1738
1739     return S_OK;
1740 }
1741
1742 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface,
1743                                            double *pdRate) {
1744     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1745
1746     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
1747
1748     return S_OK;
1749 }
1750
1751 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface,
1752                                               LONGLONG *pllPreroll) {
1753     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
1754
1755     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
1756
1757     return S_OK;
1758 }
1759
1760
1761 static const IMediaSeekingVtbl IMediaSeeking_VTable =
1762 {
1763     MediaSeeking_QueryInterface,
1764     MediaSeeking_AddRef,
1765     MediaSeeking_Release,
1766     MediaSeeking_GetCapabilities,
1767     MediaSeeking_CheckCapabilities,
1768     MediaSeeking_IsFormatSupported,
1769     MediaSeeking_QueryPreferredFormat,
1770     MediaSeeking_GetTimeFormat,
1771     MediaSeeking_IsUsingTimeFormat,
1772     MediaSeeking_SetTimeFormat,
1773     MediaSeeking_GetDuration,
1774     MediaSeeking_GetStopPosition,
1775     MediaSeeking_GetCurrentPosition,
1776     MediaSeeking_ConvertTimeFormat,
1777     MediaSeeking_SetPositions,
1778     MediaSeeking_GetPositions,
1779     MediaSeeking_GetAvailable,
1780     MediaSeeking_SetRate,
1781     MediaSeeking_GetRate,
1782     MediaSeeking_GetPreroll
1783 };
1784
1785 /*** IUnknown methods ***/
1786 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj){
1787     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaPosition_vtbl, iface);
1788
1789     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1790
1791     return Filtergraph_QueryInterface(This, riid, ppvObj);
1792 }
1793
1794 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface){
1795     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaPosition_vtbl, iface);
1796
1797     TRACE("(%p/%p)->()\n", This, iface);
1798
1799     return Filtergraph_AddRef(This);
1800 }
1801
1802 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface){
1803     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaPosition_vtbl, iface);
1804
1805     TRACE("(%p/%p)->()\n", This, iface);
1806
1807     return Filtergraph_Release(This);
1808 }
1809
1810 /*** IDispatch methods ***/
1811 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo){
1812     FIXME("(%p) stub!\n", iface);
1813     return E_NOTIMPL;
1814 }
1815
1816 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo){
1817     FIXME("(%p) stub!\n", iface);
1818     return E_NOTIMPL;
1819 }
1820
1821 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId){
1822     FIXME("(%p) stub!\n", iface);
1823     return E_NOTIMPL;
1824 }
1825
1826 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr){
1827     FIXME("(%p) stub!\n", iface);
1828     return E_NOTIMPL;
1829 }
1830
1831 /*** IMediaPosition methods ***/
1832 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength){
1833     FIXME("(%p)->(%p) stub!\n", iface, plength);
1834     return E_NOTIMPL;
1835 }
1836
1837 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime){
1838     FIXME("(%p)->(%f) stub!\n", iface, llTime);
1839     return E_NOTIMPL;
1840 }
1841
1842 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime){
1843     FIXME("(%p)->(%p) stub!\n", iface, pllTime);
1844     return E_NOTIMPL;
1845 }
1846
1847 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime){
1848     FIXME("(%p)->(%p) stub!\n", iface, pllTime);
1849     return E_NOTIMPL;
1850 }
1851
1852 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime){
1853     FIXME("(%p)->(%f) stub!\n", iface, llTime);
1854     return E_NOTIMPL;
1855 }
1856
1857 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime){
1858     FIXME("(%p)->(%p) stub!\n", iface, pllTime);
1859     return E_NOTIMPL;
1860 }
1861
1862 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime){
1863     FIXME("(%p)->(%f) stub!\n", iface, llTime);
1864     return E_NOTIMPL;
1865 }
1866
1867 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate){
1868     FIXME("(%p)->(%f) stub!\n", iface, dRate);
1869     return E_NOTIMPL;
1870 }
1871
1872 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate){
1873     FIXME("(%p)->(%p) stub!\n", iface, pdRate);
1874     return E_NOTIMPL;
1875 }
1876
1877 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward){
1878     FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
1879     return E_NOTIMPL;
1880 }
1881
1882 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward){
1883     FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
1884     return E_NOTIMPL;
1885 }
1886
1887
1888 static const IMediaPositionVtbl IMediaPosition_VTable =
1889 {
1890     MediaPosition_QueryInterface,
1891     MediaPosition_AddRef,
1892     MediaPosition_Release,
1893     MediaPosition_GetTypeInfoCount,
1894     MediaPosition_GetTypeInfo,
1895     MediaPosition_GetIDsOfNames,
1896     MediaPosition_Invoke,
1897     MediaPosition_get_Duration,
1898     MediaPosition_put_CurrentPosition,
1899     MediaPosition_get_CurrentPosition,
1900     MediaPosition_get_StopTime,
1901     MediaPosition_put_StopTime,
1902     MediaPosition_get_PrerollTime,
1903     MediaPosition_put_PrerollTime,
1904     MediaPosition_put_Rate,
1905     MediaPosition_get_Rate,
1906     MediaPosition_CanSeekForward,
1907     MediaPosition_CanSeekBackward
1908 };
1909
1910 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
1911 {
1912     HRESULT hr = E_NOINTERFACE;
1913     int i;
1914     int entry;
1915
1916     /* Check if the interface type is already registered */
1917     for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
1918         if (riid == pGraph->ItfCacheEntries[entry].riid)
1919         {
1920             if (pGraph->ItfCacheEntries[entry].iface)
1921             {
1922                 /* Return the interface if available */
1923                 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
1924                 return S_OK;
1925             }
1926             break;
1927         }
1928
1929     if (entry >= MAX_ITF_CACHE_ENTRIES)
1930     {
1931         FIXME("Not enough space to store interface in the cache\n");
1932         return E_OUTOFMEMORY;
1933     }
1934
1935     /* Find a filter supporting the requested interface */
1936     for (i = 0; i < pGraph->nFilters; i++)
1937     {
1938         hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
1939         if (hr == S_OK)
1940         {
1941             pGraph->ItfCacheEntries[entry].riid = riid;
1942             pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
1943             pGraph->ItfCacheEntries[entry].iface = (IUnknown*)*ppvObj;
1944             if (entry >= pGraph->nItfCacheEntries)
1945                 pGraph->nItfCacheEntries++;
1946             return S_OK;
1947         }
1948         if (hr != E_NOINTERFACE)
1949             return hr;
1950     }
1951
1952     return hr;
1953 }
1954
1955 /*** IUnknown methods ***/
1956 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface,
1957                                                 REFIID riid,
1958                                                 LPVOID*ppvObj) {
1959     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
1960
1961     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1962
1963     return Filtergraph_QueryInterface(This, riid, ppvObj);
1964 }
1965
1966 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface) {
1967     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
1968
1969     TRACE("(%p/%p)->()\n", This, iface);
1970
1971     return Filtergraph_AddRef(This);
1972 }
1973
1974 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface) {
1975     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
1976
1977     TRACE("(%p/%p)->()\n", This, iface);
1978
1979     return Filtergraph_Release(This);
1980 }
1981
1982 /*** IDispatch methods ***/
1983 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface,
1984                                                   UINT*pctinfo) {
1985     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
1986     IBasicAudio* pBasicAudio;
1987     HRESULT hr;
1988
1989     TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
1990
1991     EnterCriticalSection(&This->cs);
1992
1993     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
1994
1995     if (hr == S_OK)
1996         hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
1997
1998     LeaveCriticalSection(&This->cs);
1999
2000     return hr;
2001 }
2002
2003 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface,
2004                                              UINT iTInfo,
2005                                              LCID lcid,
2006                                              ITypeInfo**ppTInfo) {
2007     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2008     IBasicAudio* pBasicAudio;
2009     HRESULT hr;
2010
2011     TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
2012
2013     EnterCriticalSection(&This->cs);
2014
2015     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2016
2017     if (hr == S_OK)
2018         hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
2019
2020     LeaveCriticalSection(&This->cs);
2021
2022     return hr;
2023 }
2024
2025 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface,
2026                                                REFIID riid,
2027                                                LPOLESTR*rgszNames,
2028                                                UINT cNames,
2029                                                LCID lcid,
2030                                                DISPID*rgDispId) {
2031     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2032     IBasicAudio* pBasicAudio;
2033     HRESULT hr;
2034
2035     TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
2036
2037     EnterCriticalSection(&This->cs);
2038
2039     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2040
2041     if (hr == S_OK)
2042         hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
2043
2044     LeaveCriticalSection(&This->cs);
2045
2046     return hr;
2047 }
2048
2049 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface,
2050                                         DISPID dispIdMember,
2051                                         REFIID riid,
2052                                         LCID lcid,
2053                                         WORD wFlags,
2054                                         DISPPARAMS*pDispParams,
2055                                         VARIANT*pVarResult,
2056                                         EXCEPINFO*pExepInfo,
2057                                         UINT*puArgErr) {
2058     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2059     IBasicAudio* pBasicAudio;
2060     HRESULT hr;
2061
2062     TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
2063
2064     EnterCriticalSection(&This->cs);
2065
2066     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2067
2068     if (hr == S_OK)
2069         hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
2070
2071     LeaveCriticalSection(&This->cs);
2072
2073     return hr;
2074 }
2075
2076 /*** IBasicAudio methods ***/
2077 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface,
2078                                             long lVolume) {
2079     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2080     IBasicAudio* pBasicAudio;
2081     HRESULT hr;
2082
2083     TRACE("(%p/%p)->(%ld)\n", This, iface, lVolume);
2084
2085     EnterCriticalSection(&This->cs);
2086
2087     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2088
2089     if (hr == S_OK)
2090         hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
2091
2092     LeaveCriticalSection(&This->cs);
2093
2094     return hr;
2095 }
2096
2097 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface,
2098                                             long *plVolume) {
2099     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2100     IBasicAudio* pBasicAudio;
2101     HRESULT hr;
2102
2103     TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
2104
2105     EnterCriticalSection(&This->cs);
2106
2107     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2108
2109     if (hr == S_OK)
2110         hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
2111
2112     LeaveCriticalSection(&This->cs);
2113
2114     return hr;
2115 }
2116
2117 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface,
2118                                              long lBalance) {
2119     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2120     IBasicAudio* pBasicAudio;
2121     HRESULT hr;
2122
2123     TRACE("(%p/%p)->(%ld)\n", This, iface, lBalance);
2124
2125     EnterCriticalSection(&This->cs);
2126
2127     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2128
2129     if (hr == S_OK)
2130         hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
2131
2132     LeaveCriticalSection(&This->cs);
2133
2134     return hr;
2135 }
2136
2137 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface,
2138                                              long *plBalance) {
2139     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2140     IBasicAudio* pBasicAudio;
2141     HRESULT hr;
2142
2143     TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
2144
2145     EnterCriticalSection(&This->cs);
2146
2147     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2148
2149     if (hr == S_OK)
2150         hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
2151
2152     LeaveCriticalSection(&This->cs);
2153
2154     return hr;
2155 }
2156
2157 static const IBasicAudioVtbl IBasicAudio_VTable =
2158 {
2159     BasicAudio_QueryInterface,
2160     BasicAudio_AddRef,
2161     BasicAudio_Release,
2162     BasicAudio_GetTypeInfoCount,
2163     BasicAudio_GetTypeInfo,
2164     BasicAudio_GetIDsOfNames,
2165     BasicAudio_Invoke,
2166     BasicAudio_put_Volume,
2167     BasicAudio_get_Volume,
2168     BasicAudio_put_Balance,
2169     BasicAudio_get_Balance
2170 };
2171
2172 /*** IUnknown methods ***/
2173 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo *iface,
2174                                                 REFIID riid,
2175                                                 LPVOID*ppvObj) {
2176     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2177
2178     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2179
2180     return Filtergraph_QueryInterface(This, riid, ppvObj);
2181 }
2182
2183 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo *iface) {
2184     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2185
2186     TRACE("(%p/%p)->()\n", This, iface);
2187
2188     return Filtergraph_AddRef(This);
2189 }
2190
2191 static ULONG WINAPI BasicVideo_Release(IBasicVideo *iface) {
2192     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2193
2194     TRACE("(%p/%p)->()\n", This, iface);
2195
2196     return Filtergraph_Release(This);
2197 }
2198
2199 /*** IDispatch methods ***/
2200 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo *iface,
2201                                                   UINT*pctinfo) {
2202     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2203     IBasicVideo* pBasicVideo;
2204     HRESULT hr;
2205
2206     TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
2207
2208     EnterCriticalSection(&This->cs);
2209
2210     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2211
2212     if (hr == S_OK)
2213         hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
2214
2215     LeaveCriticalSection(&This->cs);
2216
2217     return hr;
2218 }
2219
2220 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo *iface,
2221                                              UINT iTInfo,
2222                                              LCID lcid,
2223                                              ITypeInfo**ppTInfo) {
2224     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2225     IBasicVideo* pBasicVideo;
2226     HRESULT hr;
2227
2228     TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
2229
2230     EnterCriticalSection(&This->cs);
2231
2232     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2233
2234     if (hr == S_OK)
2235         hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
2236
2237     LeaveCriticalSection(&This->cs);
2238
2239     return hr;
2240 }
2241
2242 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo *iface,
2243                                                REFIID riid,
2244                                                LPOLESTR*rgszNames,
2245                                                UINT cNames,
2246                                                LCID lcid,
2247                                                DISPID*rgDispId) {
2248     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2249     IBasicVideo* pBasicVideo;
2250     HRESULT hr;
2251
2252     TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
2253
2254     EnterCriticalSection(&This->cs);
2255
2256     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2257
2258     if (hr == S_OK)
2259         hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
2260
2261     LeaveCriticalSection(&This->cs);
2262
2263     return hr;
2264 }
2265
2266 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo *iface,
2267                                         DISPID dispIdMember,
2268                                         REFIID riid,
2269                                         LCID lcid,
2270                                         WORD wFlags,
2271                                         DISPPARAMS*pDispParams,
2272                                         VARIANT*pVarResult,
2273                                         EXCEPINFO*pExepInfo,
2274                                         UINT*puArgErr) {
2275     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2276     IBasicVideo* pBasicVideo;
2277     HRESULT hr;
2278
2279     TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
2280
2281     EnterCriticalSection(&This->cs);
2282
2283     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2284
2285     if (hr == S_OK)
2286         hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
2287
2288     LeaveCriticalSection(&This->cs);
2289
2290     return hr;
2291 }
2292
2293 /*** IBasicVideo methods ***/
2294 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo *iface,
2295                                                      REFTIME *pAvgTimePerFrame) {
2296     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2297     IBasicVideo* pBasicVideo;
2298     HRESULT hr;
2299
2300     TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
2301
2302     EnterCriticalSection(&This->cs);
2303
2304     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2305
2306     if (hr == S_OK)
2307         hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
2308
2309     LeaveCriticalSection(&This->cs);
2310
2311     return hr;
2312 }
2313
2314 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo *iface,
2315                                              long *pBitRate) {
2316     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2317     IBasicVideo* pBasicVideo;
2318     HRESULT hr;
2319
2320     TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
2321
2322     EnterCriticalSection(&This->cs);
2323
2324     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2325
2326     if (hr == S_OK)
2327         hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
2328
2329     LeaveCriticalSection(&This->cs);
2330
2331     return hr;
2332 }
2333
2334 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo *iface,
2335                                                   long *pBitErrorRate) {
2336     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2337     IBasicVideo* pBasicVideo;
2338     HRESULT hr;
2339
2340     TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
2341
2342     EnterCriticalSection(&This->cs);
2343
2344     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2345
2346     if (hr == S_OK)
2347         hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
2348
2349     LeaveCriticalSection(&This->cs);
2350
2351     return hr;
2352 }
2353
2354 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo *iface,
2355                                                 long *pVideoWidth) {
2356     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2357     IBasicVideo* pBasicVideo;
2358     HRESULT hr;
2359
2360     TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
2361
2362     EnterCriticalSection(&This->cs);
2363
2364     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2365
2366     if (hr == S_OK)
2367         hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
2368
2369     LeaveCriticalSection(&This->cs);
2370
2371     return hr;
2372 }
2373
2374 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo *iface,
2375                                                  long *pVideoHeight) {
2376     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2377     IBasicVideo* pBasicVideo;
2378     HRESULT hr;
2379
2380     TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
2381
2382     EnterCriticalSection(&This->cs);
2383
2384     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2385
2386     if (hr == S_OK)
2387         hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
2388
2389     LeaveCriticalSection(&This->cs);
2390
2391     return hr;
2392 }
2393
2394 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo *iface,
2395                                                 long SourceLeft) {
2396     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2397     IBasicVideo* pBasicVideo;
2398     HRESULT hr;
2399
2400     TRACE("(%p/%p)->(%ld)\n", This, iface, SourceLeft);
2401
2402     EnterCriticalSection(&This->cs);
2403
2404     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2405
2406     if (hr == S_OK)
2407         hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
2408
2409     LeaveCriticalSection(&This->cs);
2410
2411     return hr;
2412 }
2413
2414 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo *iface,
2415                                                 long *pSourceLeft) {
2416     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2417     IBasicVideo* pBasicVideo;
2418     HRESULT hr;
2419
2420     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
2421
2422     EnterCriticalSection(&This->cs);
2423
2424     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2425
2426     if (hr == S_OK)
2427         hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
2428
2429     LeaveCriticalSection(&This->cs);
2430
2431     return hr;
2432 }
2433
2434 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo *iface,
2435                                                  long SourceWidth) {
2436     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2437     IBasicVideo* pBasicVideo;
2438     HRESULT hr;
2439
2440     TRACE("(%p/%p)->(%ld)\n", This, iface, SourceWidth);
2441
2442     EnterCriticalSection(&This->cs);
2443
2444     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2445
2446     if (hr == S_OK)
2447         hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
2448
2449     LeaveCriticalSection(&This->cs);
2450
2451     return hr;
2452 }
2453
2454 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo *iface,
2455                                                  long *pSourceWidth) {
2456     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2457     IBasicVideo* pBasicVideo;
2458     HRESULT hr;
2459
2460     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
2461
2462     EnterCriticalSection(&This->cs);
2463
2464     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2465
2466     if (hr == S_OK)
2467         hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
2468
2469     LeaveCriticalSection(&This->cs);
2470
2471     return hr;
2472 }
2473
2474 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo *iface,
2475                                                long SourceTop) {
2476     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2477     IBasicVideo* pBasicVideo;
2478     HRESULT hr;
2479
2480     TRACE("(%p/%p)->(%ld)\n", This, iface, SourceTop);
2481
2482     EnterCriticalSection(&This->cs);
2483
2484     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2485
2486     if (hr == S_OK)
2487         hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
2488
2489     LeaveCriticalSection(&This->cs);
2490
2491     return hr;
2492 }
2493
2494 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo *iface,
2495                                                long *pSourceTop) {
2496     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2497     IBasicVideo* pBasicVideo;
2498     HRESULT hr;
2499
2500     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
2501
2502     EnterCriticalSection(&This->cs);
2503
2504     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2505
2506     if (hr == S_OK)
2507         hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
2508
2509     LeaveCriticalSection(&This->cs);
2510
2511     return hr;
2512 }
2513
2514 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo *iface,
2515                                                   long SourceHeight) {
2516     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2517     IBasicVideo* pBasicVideo;
2518     HRESULT hr;
2519
2520     TRACE("(%p/%p)->(%ld)\n", This, iface, SourceHeight);
2521
2522     EnterCriticalSection(&This->cs);
2523
2524     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2525
2526     if (hr == S_OK)
2527         hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
2528
2529     LeaveCriticalSection(&This->cs);
2530
2531     return hr;
2532 }
2533
2534 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo *iface,
2535                                                   long *pSourceHeight) {
2536     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2537     IBasicVideo* pBasicVideo;
2538     HRESULT hr;
2539
2540     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
2541
2542     EnterCriticalSection(&This->cs);
2543
2544     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2545
2546     if (hr == S_OK)
2547         hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
2548
2549     LeaveCriticalSection(&This->cs);
2550
2551     return hr;
2552 }
2553
2554 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo *iface,
2555                                                      long DestinationLeft) {
2556     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2557     IBasicVideo* pBasicVideo;
2558     HRESULT hr;
2559
2560     TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationLeft);
2561
2562     EnterCriticalSection(&This->cs);
2563
2564     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2565
2566     if (hr == S_OK)
2567         hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
2568
2569     LeaveCriticalSection(&This->cs);
2570
2571     return hr;
2572 }
2573
2574 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo *iface,
2575                                                      long *pDestinationLeft) {
2576     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2577     IBasicVideo* pBasicVideo;
2578     HRESULT hr;
2579
2580     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
2581
2582     EnterCriticalSection(&This->cs);
2583
2584     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2585
2586     if (hr == S_OK)
2587         hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
2588
2589     LeaveCriticalSection(&This->cs);
2590
2591     return hr;
2592 }
2593
2594 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo *iface,
2595                                                       long DestinationWidth) {
2596     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2597     IBasicVideo* pBasicVideo;
2598     HRESULT hr;
2599
2600     TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationWidth);
2601
2602     EnterCriticalSection(&This->cs);
2603
2604     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2605
2606     if (hr == S_OK)
2607         hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
2608
2609     LeaveCriticalSection(&This->cs);
2610
2611     return hr;
2612 }
2613
2614 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo *iface,
2615                                                       long *pDestinationWidth) {
2616     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2617     IBasicVideo* pBasicVideo;
2618     HRESULT hr;
2619
2620     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
2621
2622     EnterCriticalSection(&This->cs);
2623
2624     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2625
2626     if (hr == S_OK)
2627         hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
2628
2629     LeaveCriticalSection(&This->cs);
2630
2631     return hr;
2632 }
2633
2634 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo *iface,
2635                                                     long DestinationTop) {
2636     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2637     IBasicVideo* pBasicVideo;
2638     HRESULT hr;
2639
2640     TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationTop);
2641
2642     EnterCriticalSection(&This->cs);
2643
2644     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2645
2646     if (hr == S_OK)
2647         hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
2648
2649     LeaveCriticalSection(&This->cs);
2650
2651     return hr;
2652 }
2653
2654 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo *iface,
2655                                                     long *pDestinationTop) {
2656     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2657     IBasicVideo* pBasicVideo;
2658     HRESULT hr;
2659
2660     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
2661
2662     EnterCriticalSection(&This->cs);
2663
2664     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2665
2666     if (hr == S_OK)
2667         hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
2668
2669     LeaveCriticalSection(&This->cs);
2670
2671     return hr;
2672 }
2673
2674 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo *iface,
2675                                                        long DestinationHeight) {
2676     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2677     IBasicVideo* pBasicVideo;
2678     HRESULT hr;
2679
2680     TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationHeight);
2681
2682     EnterCriticalSection(&This->cs);
2683
2684     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2685
2686     if (hr == S_OK)
2687         hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
2688
2689     LeaveCriticalSection(&This->cs);
2690
2691     return hr;
2692 }
2693
2694 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo *iface,
2695                                                        long *pDestinationHeight) {
2696     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2697     IBasicVideo* pBasicVideo;
2698     HRESULT hr;
2699
2700     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
2701
2702     EnterCriticalSection(&This->cs);
2703
2704     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2705
2706     if (hr == S_OK)
2707         hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
2708
2709     LeaveCriticalSection(&This->cs);
2710
2711     return hr;
2712 }
2713
2714 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo *iface,
2715                                                    long Left,
2716                                                    long Top,
2717                                                    long Width,
2718                                                    long Height) {
2719     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2720     IBasicVideo* pBasicVideo;
2721     HRESULT hr;
2722
2723     TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
2724
2725     EnterCriticalSection(&This->cs);
2726
2727     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2728
2729     if (hr == S_OK)
2730         hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
2731
2732     LeaveCriticalSection(&This->cs);
2733
2734     return hr;
2735 }
2736
2737 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo *iface,
2738                                                    long *pLeft,
2739                                                    long *pTop,
2740                                                    long *pWidth,
2741                                                    long *pHeight) {
2742     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2743     IBasicVideo* pBasicVideo;
2744     HRESULT hr;
2745
2746     TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
2747
2748     EnterCriticalSection(&This->cs);
2749
2750     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2751
2752     if (hr == S_OK)
2753         hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
2754
2755     LeaveCriticalSection(&This->cs);
2756
2757     return hr;
2758 }
2759
2760 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo *iface) {
2761     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2762     IBasicVideo* pBasicVideo;
2763     HRESULT hr;
2764
2765     TRACE("(%p/%p)->()\n", This, iface);
2766
2767     EnterCriticalSection(&This->cs);
2768
2769     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2770
2771     if (hr == S_OK)
2772         hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
2773
2774     LeaveCriticalSection(&This->cs);
2775
2776     return hr;
2777 }
2778
2779 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo *iface,
2780                                                         long Left,
2781                                                         long Top,
2782                                                         long Width,
2783                                                         long Height) {
2784     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2785     IBasicVideo* pBasicVideo;
2786     HRESULT hr;
2787
2788     TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
2789
2790     EnterCriticalSection(&This->cs);
2791
2792     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2793
2794     if (hr == S_OK)
2795         hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
2796
2797     LeaveCriticalSection(&This->cs);
2798
2799     return hr;
2800 }
2801
2802 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo *iface,
2803                                                         long *pLeft,
2804                                                         long *pTop,
2805                                                         long *pWidth,
2806                                                         long *pHeight) {
2807     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2808     IBasicVideo* pBasicVideo;
2809     HRESULT hr;
2810
2811     TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
2812
2813     EnterCriticalSection(&This->cs);
2814
2815     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2816
2817     if (hr == S_OK)
2818         hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
2819
2820     LeaveCriticalSection(&This->cs);
2821
2822     return hr;
2823 }
2824
2825 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo *iface) {
2826     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2827     IBasicVideo* pBasicVideo;
2828     HRESULT hr;
2829
2830     TRACE("(%p/%p)->()\n", This, iface);
2831
2832     EnterCriticalSection(&This->cs);
2833
2834     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2835
2836     if (hr == S_OK)
2837         hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
2838
2839     LeaveCriticalSection(&This->cs);
2840
2841     return hr;
2842 }
2843
2844 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo *iface,
2845                                               long *pWidth,
2846                                               long *pHeight) {
2847     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2848     IBasicVideo* pBasicVideo;
2849     HRESULT hr;
2850
2851     TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
2852
2853     EnterCriticalSection(&This->cs);
2854
2855     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2856
2857     if (hr == S_OK)
2858         hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
2859
2860     LeaveCriticalSection(&This->cs);
2861
2862     return hr;
2863 }
2864
2865 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo *iface,
2866                                                         long StartIndex,
2867                                                         long Entries,
2868                                                         long *pRetrieved,
2869                                                         long *pPalette) {
2870     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2871     IBasicVideo* pBasicVideo;
2872     HRESULT hr;
2873
2874     TRACE("(%p/%p)->(%ld, %ld, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
2875
2876     EnterCriticalSection(&This->cs);
2877
2878     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2879
2880     if (hr == S_OK)
2881         hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
2882
2883     LeaveCriticalSection(&This->cs);
2884
2885     return hr;
2886 }
2887
2888 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo *iface,
2889                                                  long *pBufferSize,
2890                                                  long *pDIBImage) {
2891     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2892     IBasicVideo* pBasicVideo;
2893     HRESULT hr;
2894
2895     TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
2896
2897     EnterCriticalSection(&This->cs);
2898
2899     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2900
2901     if (hr == S_OK)
2902         hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
2903
2904     LeaveCriticalSection(&This->cs);
2905
2906     return hr;
2907 }
2908
2909 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo *iface) {
2910     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2911     IBasicVideo* pBasicVideo;
2912     HRESULT hr;
2913
2914     TRACE("(%p/%p)->()\n", This, iface);
2915
2916     EnterCriticalSection(&This->cs);
2917
2918     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2919
2920     if (hr == S_OK)
2921         hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
2922
2923     LeaveCriticalSection(&This->cs);
2924
2925     return hr;
2926 }
2927
2928 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo *iface) {
2929     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2930     IBasicVideo* pBasicVideo;
2931     HRESULT hr;
2932
2933     TRACE("(%p/%p)->()\n", This, iface);
2934
2935     EnterCriticalSection(&This->cs);
2936
2937     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2938
2939     if (hr == S_OK)
2940         hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
2941
2942     LeaveCriticalSection(&This->cs);
2943
2944     return hr;
2945 }
2946
2947
2948 static const IBasicVideoVtbl IBasicVideo_VTable =
2949 {
2950     BasicVideo_QueryInterface,
2951     BasicVideo_AddRef,
2952     BasicVideo_Release,
2953     BasicVideo_GetTypeInfoCount,
2954     BasicVideo_GetTypeInfo,
2955     BasicVideo_GetIDsOfNames,
2956     BasicVideo_Invoke,
2957     BasicVideo_get_AvgTimePerFrame,
2958     BasicVideo_get_BitRate,
2959     BasicVideo_get_BitErrorRate,
2960     BasicVideo_get_VideoWidth,
2961     BasicVideo_get_VideoHeight,
2962     BasicVideo_put_SourceLeft,
2963     BasicVideo_get_SourceLeft,
2964     BasicVideo_put_SourceWidth,
2965     BasicVideo_get_SourceWidth,
2966     BasicVideo_put_SourceTop,
2967     BasicVideo_get_SourceTop,
2968     BasicVideo_put_SourceHeight,
2969     BasicVideo_get_SourceHeight,
2970     BasicVideo_put_DestinationLeft,
2971     BasicVideo_get_DestinationLeft,
2972     BasicVideo_put_DestinationWidth,
2973     BasicVideo_get_DestinationWidth,
2974     BasicVideo_put_DestinationTop,
2975     BasicVideo_get_DestinationTop,
2976     BasicVideo_put_DestinationHeight,
2977     BasicVideo_get_DestinationHeight,
2978     BasicVideo_SetSourcePosition,
2979     BasicVideo_GetSourcePosition,
2980     BasicVideo_SetDefaultSourcePosition,
2981     BasicVideo_SetDestinationPosition,
2982     BasicVideo_GetDestinationPosition,
2983     BasicVideo_SetDefaultDestinationPosition,
2984     BasicVideo_GetVideoSize,
2985     BasicVideo_GetVideoPaletteEntries,
2986     BasicVideo_GetCurrentImage,
2987     BasicVideo_IsUsingDefaultSource,
2988     BasicVideo_IsUsingDefaultDestination
2989 };
2990
2991
2992 /*** IUnknown methods ***/
2993 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface,
2994                                                  REFIID riid,
2995                                                  LPVOID*ppvObj) {
2996     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
2997
2998     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2999
3000     return Filtergraph_QueryInterface(This, riid, ppvObj);
3001 }
3002
3003 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface) {
3004     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3005
3006     TRACE("(%p/%p)->()\n", This, iface);
3007
3008     return Filtergraph_AddRef(This);
3009 }
3010
3011 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface) {
3012     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3013
3014     TRACE("(%p/%p)->()\n", This, iface);
3015
3016     return Filtergraph_Release(This);
3017 }
3018
3019 /*** IDispatch methods ***/
3020 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface,
3021                                                    UINT*pctinfo) {
3022     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3023     IVideoWindow* pVideoWindow;
3024     HRESULT hr;
3025
3026     TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3027
3028     EnterCriticalSection(&This->cs);
3029
3030     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3031
3032     if (hr == S_OK)
3033         hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
3034
3035     LeaveCriticalSection(&This->cs);
3036
3037     return hr;
3038 }
3039
3040 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface,
3041                                               UINT iTInfo,
3042                                               LCID lcid,
3043                                               ITypeInfo**ppTInfo) {
3044     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3045     IVideoWindow* pVideoWindow;
3046     HRESULT hr;
3047
3048     TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3049
3050     EnterCriticalSection(&This->cs);
3051
3052     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3053
3054     if (hr == S_OK)
3055         hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
3056
3057     LeaveCriticalSection(&This->cs);
3058
3059     return hr;
3060 }
3061
3062 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface,
3063                                                 REFIID riid,
3064                                                 LPOLESTR*rgszNames,
3065                                                 UINT cNames,
3066                                                 LCID lcid,
3067                                                 DISPID*rgDispId) {
3068     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3069     IVideoWindow* pVideoWindow;
3070     HRESULT hr;
3071
3072     TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3073
3074     EnterCriticalSection(&This->cs);
3075
3076     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3077
3078     if (hr == S_OK)
3079         hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
3080
3081     LeaveCriticalSection(&This->cs);
3082
3083     return hr;
3084 }
3085
3086 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface,
3087                                          DISPID dispIdMember,
3088                                          REFIID riid,
3089                                          LCID lcid,
3090                                          WORD wFlags,
3091                                          DISPPARAMS*pDispParams,
3092                                          VARIANT*pVarResult,
3093                                          EXCEPINFO*pExepInfo,
3094                                          UINT*puArgErr) {
3095     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3096     IVideoWindow* pVideoWindow;
3097     HRESULT hr;
3098
3099     TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3100
3101     EnterCriticalSection(&This->cs);
3102
3103     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3104
3105     if (hr == S_OK)
3106         hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3107
3108     LeaveCriticalSection(&This->cs);
3109
3110     return hr;
3111 }
3112
3113
3114 /*** IVideoWindow methods ***/
3115 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface,
3116                                               BSTR strCaption) {
3117     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3118     IVideoWindow* pVideoWindow;
3119     HRESULT hr;
3120     
3121     TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
3122
3123     EnterCriticalSection(&This->cs);
3124
3125     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3126
3127     if (hr == S_OK)
3128         hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
3129
3130     LeaveCriticalSection(&This->cs);
3131
3132     return hr;
3133 }
3134
3135 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface,
3136                                               BSTR *strCaption) {
3137     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3138     IVideoWindow* pVideoWindow;
3139     HRESULT hr;
3140
3141     TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
3142
3143     EnterCriticalSection(&This->cs);
3144
3145     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3146
3147     if (hr == S_OK)
3148         hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
3149
3150     LeaveCriticalSection(&This->cs);
3151
3152     return hr;
3153 }
3154
3155 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface,
3156                                                   long WindowStyle) {
3157     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3158     IVideoWindow* pVideoWindow;
3159     HRESULT hr;
3160
3161     TRACE("(%p/%p)->(%ld)\n", This, iface, WindowStyle);
3162
3163     EnterCriticalSection(&This->cs);
3164
3165     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3166
3167     if (hr == S_OK)
3168         hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
3169
3170     LeaveCriticalSection(&This->cs);
3171
3172     return hr;
3173 }
3174
3175 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface,
3176                                                   long *WindowStyle) {
3177     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3178     IVideoWindow* pVideoWindow;
3179     HRESULT hr;
3180
3181     TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
3182
3183     EnterCriticalSection(&This->cs);
3184
3185     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3186
3187     if (hr == S_OK)
3188         hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
3189
3190     LeaveCriticalSection(&This->cs);
3191
3192     return hr;
3193 }
3194
3195 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface,
3196                                                     long WindowStyleEx) {
3197     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3198     IVideoWindow* pVideoWindow;
3199     HRESULT hr;
3200
3201     TRACE("(%p/%p)->(%ld)\n", This, iface, WindowStyleEx);
3202
3203     EnterCriticalSection(&This->cs);
3204
3205     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3206
3207     if (hr == S_OK)
3208         hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
3209
3210     LeaveCriticalSection(&This->cs);
3211
3212     return hr;
3213 }
3214
3215 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface,
3216                                                     long *WindowStyleEx) {
3217     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3218     IVideoWindow* pVideoWindow;
3219     HRESULT hr;
3220
3221     TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
3222
3223     EnterCriticalSection(&This->cs);
3224
3225     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3226
3227     if (hr == S_OK)
3228         hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
3229
3230     LeaveCriticalSection(&This->cs);
3231
3232     return hr;
3233 }
3234
3235 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface,
3236                                                long AutoShow) {
3237     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3238     IVideoWindow* pVideoWindow;
3239     HRESULT hr;
3240
3241     TRACE("(%p/%p)->(%ld)\n", This, iface, AutoShow);
3242
3243     EnterCriticalSection(&This->cs);
3244
3245     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3246
3247     if (hr == S_OK)
3248         hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
3249
3250     LeaveCriticalSection(&This->cs);
3251
3252     return hr;
3253 }
3254
3255 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface,
3256                                                long *AutoShow) {
3257     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3258     IVideoWindow* pVideoWindow;
3259     HRESULT hr;
3260
3261     TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
3262
3263     EnterCriticalSection(&This->cs);
3264
3265     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3266
3267     if (hr == S_OK)
3268         hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
3269
3270     LeaveCriticalSection(&This->cs);
3271
3272     return hr;
3273 }
3274
3275 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface,
3276                                                   long WindowState) {
3277     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3278     IVideoWindow* pVideoWindow;
3279     HRESULT hr;
3280
3281     TRACE("(%p/%p)->(%ld)\n", This, iface, WindowState);
3282
3283     EnterCriticalSection(&This->cs);
3284
3285     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3286
3287     if (hr == S_OK)
3288         hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
3289
3290     LeaveCriticalSection(&This->cs);
3291
3292     return hr;
3293 }
3294
3295 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface,
3296                                                   long *WindowState) {
3297     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3298     IVideoWindow* pVideoWindow;
3299     HRESULT hr;
3300
3301     TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
3302
3303     EnterCriticalSection(&This->cs);
3304
3305     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3306
3307     if (hr == S_OK)
3308         hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
3309
3310     LeaveCriticalSection(&This->cs);
3311
3312     return hr;
3313 }
3314
3315 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface,
3316                                                         long BackgroundPalette) {
3317     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3318     IVideoWindow* pVideoWindow;
3319     HRESULT hr;
3320
3321     TRACE("(%p/%p)->(%ld)\n", This, iface, BackgroundPalette);
3322
3323     EnterCriticalSection(&This->cs);
3324
3325     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3326
3327     if (hr == S_OK)
3328         hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
3329
3330     LeaveCriticalSection(&This->cs);
3331
3332     return hr;
3333 }
3334
3335 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
3336                                                         long *pBackgroundPalette) {
3337     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3338     IVideoWindow* pVideoWindow;
3339     HRESULT hr;
3340
3341     TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
3342
3343     EnterCriticalSection(&This->cs);
3344
3345     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3346
3347     if (hr == S_OK)
3348         hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
3349
3350     LeaveCriticalSection(&This->cs);
3351
3352     return hr;
3353 }
3354
3355 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface,
3356                                               long Visible) {
3357     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3358     IVideoWindow* pVideoWindow;
3359     HRESULT hr;
3360
3361     TRACE("(%p/%p)->(%ld)\n", This, iface, Visible);
3362
3363     EnterCriticalSection(&This->cs);
3364
3365     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3366
3367     if (hr == S_OK)
3368         hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
3369
3370     LeaveCriticalSection(&This->cs);
3371
3372     return hr;
3373 }
3374
3375 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface,
3376                                               long *pVisible) {
3377     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3378     IVideoWindow* pVideoWindow;
3379     HRESULT hr;
3380
3381     TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
3382
3383     EnterCriticalSection(&This->cs);
3384
3385     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3386
3387     if (hr == S_OK)
3388         hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
3389
3390     LeaveCriticalSection(&This->cs);
3391
3392     return hr;
3393 }
3394
3395 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface,
3396                                            long Left) {
3397     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3398     IVideoWindow* pVideoWindow;
3399     HRESULT hr;
3400
3401     TRACE("(%p/%p)->(%ld)\n", This, iface, Left);
3402
3403     EnterCriticalSection(&This->cs);
3404
3405     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3406
3407     if (hr == S_OK)
3408         hr = IVideoWindow_put_Left(pVideoWindow, Left);
3409
3410     LeaveCriticalSection(&This->cs);
3411
3412     return hr;
3413 }
3414
3415 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface,
3416                                            long *pLeft) {
3417     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3418     IVideoWindow* pVideoWindow;
3419     HRESULT hr;
3420
3421     TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
3422
3423     EnterCriticalSection(&This->cs);
3424
3425     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3426
3427     if (hr == S_OK)
3428         hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
3429
3430     LeaveCriticalSection(&This->cs);
3431
3432     return hr;
3433 }
3434
3435 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface,
3436                                             long Width) {
3437     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3438     IVideoWindow* pVideoWindow;
3439     HRESULT hr;
3440
3441     TRACE("(%p/%p)->(%ld)\n", This, iface, Width);
3442
3443     EnterCriticalSection(&This->cs);
3444
3445     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3446
3447     if (hr == S_OK)
3448         hr = IVideoWindow_put_Width(pVideoWindow, Width);
3449
3450     LeaveCriticalSection(&This->cs);
3451
3452     return hr;
3453 }
3454
3455 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface,
3456                                             long *pWidth) {
3457     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3458     IVideoWindow* pVideoWindow;
3459     HRESULT hr;
3460
3461     TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
3462
3463     EnterCriticalSection(&This->cs);
3464
3465     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3466
3467     if (hr == S_OK)
3468         hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
3469
3470     LeaveCriticalSection(&This->cs);
3471
3472     return hr;
3473 }
3474
3475 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface,
3476                                           long Top) {
3477     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3478     IVideoWindow* pVideoWindow;
3479     HRESULT hr;
3480
3481     TRACE("(%p/%p)->(%ld)\n", This, iface, Top);
3482
3483     EnterCriticalSection(&This->cs);
3484
3485     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3486
3487     if (hr == S_OK)
3488         hr = IVideoWindow_put_Top(pVideoWindow, Top);
3489
3490     LeaveCriticalSection(&This->cs);
3491
3492     return hr;
3493 }
3494
3495 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface,
3496                                           long *pTop) {
3497     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3498     IVideoWindow* pVideoWindow;
3499     HRESULT hr;
3500
3501     TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
3502
3503     EnterCriticalSection(&This->cs);
3504
3505     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3506
3507     if (hr == S_OK)
3508         hr = IVideoWindow_get_Top(pVideoWindow, pTop);
3509
3510     LeaveCriticalSection(&This->cs);
3511
3512     return hr;
3513 }
3514
3515 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface,
3516                                              long Height) {
3517     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3518     IVideoWindow* pVideoWindow;
3519     HRESULT hr;
3520
3521     TRACE("(%p/%p)->(%ld)\n", This, iface, Height);
3522
3523     EnterCriticalSection(&This->cs);
3524
3525     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3526
3527     if (hr == S_OK)
3528         hr = IVideoWindow_put_Height(pVideoWindow, Height);
3529
3530     LeaveCriticalSection(&This->cs);
3531
3532     return hr;
3533 }
3534
3535 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface,
3536                                              long *pHeight) {
3537     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3538     IVideoWindow* pVideoWindow;
3539     HRESULT hr;
3540
3541     TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
3542
3543     EnterCriticalSection(&This->cs);
3544
3545     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3546
3547     if (hr == S_OK)
3548         hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
3549
3550     LeaveCriticalSection(&This->cs);
3551
3552     return hr;
3553 }
3554
3555 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface,
3556                                             OAHWND Owner) {
3557     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3558     IVideoWindow* pVideoWindow;
3559     HRESULT hr;
3560
3561     TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
3562
3563     EnterCriticalSection(&This->cs);
3564
3565     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3566
3567     if (hr == S_OK)
3568         hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
3569
3570     LeaveCriticalSection(&This->cs);
3571
3572     return hr;
3573 }
3574
3575 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface,
3576                                             OAHWND *Owner) {
3577     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3578     IVideoWindow* pVideoWindow;
3579     HRESULT hr;
3580
3581     TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
3582
3583     EnterCriticalSection(&This->cs);
3584
3585     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3586
3587     if (hr == S_OK)
3588         hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
3589
3590     LeaveCriticalSection(&This->cs);
3591
3592     return hr;
3593 }
3594
3595 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface,
3596                                                    OAHWND Drain) {
3597     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3598     IVideoWindow* pVideoWindow;
3599     HRESULT hr;
3600
3601     TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
3602
3603     EnterCriticalSection(&This->cs);
3604
3605     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3606
3607     if (hr == S_OK)
3608         hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
3609
3610     LeaveCriticalSection(&This->cs);
3611
3612     return hr;
3613 }
3614
3615 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface,
3616                                                    OAHWND *Drain) {
3617     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3618     IVideoWindow* pVideoWindow;
3619     HRESULT hr;
3620
3621     TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
3622
3623     EnterCriticalSection(&This->cs);
3624
3625     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3626
3627     if (hr == S_OK)
3628         hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
3629
3630     LeaveCriticalSection(&This->cs);
3631
3632     return hr;
3633 }
3634
3635 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface,
3636                                                   long *Color) {
3637     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3638     IVideoWindow* pVideoWindow;
3639     HRESULT hr;
3640
3641     TRACE("(%p/%p)->(%p)\n", This, iface, Color);
3642
3643     EnterCriticalSection(&This->cs);
3644
3645     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3646
3647     if (hr == S_OK)
3648         hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
3649
3650     LeaveCriticalSection(&This->cs);
3651
3652     return hr;
3653 }
3654
3655 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface,
3656                                                   long Color) {
3657     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3658     IVideoWindow* pVideoWindow;
3659     HRESULT hr;
3660
3661     TRACE("(%p/%p)->(%ld)\n", This, iface, Color);
3662
3663     EnterCriticalSection(&This->cs);
3664
3665     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3666
3667     if (hr == S_OK)
3668         hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
3669
3670     LeaveCriticalSection(&This->cs);
3671
3672     return hr;
3673 }
3674
3675 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface,
3676                                                      long *FullScreenMode) {
3677     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3678     IVideoWindow* pVideoWindow;
3679     HRESULT hr;
3680
3681     TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
3682
3683     EnterCriticalSection(&This->cs);
3684
3685     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3686
3687     if (hr == S_OK)
3688         hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
3689
3690     LeaveCriticalSection(&This->cs);
3691
3692     return hr;
3693 }
3694
3695 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface,
3696                                                      long FullScreenMode) {
3697     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3698     IVideoWindow* pVideoWindow;
3699     HRESULT hr;
3700
3701     TRACE("(%p/%p)->(%ld)\n", This, iface, FullScreenMode);
3702
3703     EnterCriticalSection(&This->cs);
3704
3705     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3706
3707     if (hr == S_OK)
3708         hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
3709
3710     LeaveCriticalSection(&This->cs);
3711
3712     return hr;
3713 }
3714
3715 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface,
3716                                                       long Focus) {
3717     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3718     IVideoWindow* pVideoWindow;
3719     HRESULT hr;
3720
3721     TRACE("(%p/%p)->(%ld)\n", This, iface, Focus);
3722
3723     EnterCriticalSection(&This->cs);
3724
3725     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3726
3727     if (hr == S_OK)
3728         hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
3729
3730     LeaveCriticalSection(&This->cs);
3731
3732     return hr;
3733 }
3734
3735 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface,
3736                                                      OAHWND hwnd,
3737                                                      long uMsg,
3738                                                      LONG_PTR wParam,
3739                                                      LONG_PTR lParam) {
3740     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3741     IVideoWindow* pVideoWindow;
3742     HRESULT hr;
3743
3744     TRACE("(%p/%p)->(%08x, %ld, %08lx, %08lx)\n", This, iface, (DWORD) hwnd, uMsg, wParam, lParam);
3745
3746     EnterCriticalSection(&This->cs);
3747
3748     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3749
3750     if (hr == S_OK)
3751         hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
3752
3753     LeaveCriticalSection(&This->cs);
3754
3755     return hr;
3756 }
3757
3758 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface,
3759                                                     long Left,
3760                                                     long Top,
3761                                                     long Width,
3762                                                     long Height) {
3763     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3764     IVideoWindow* pVideoWindow;
3765     HRESULT hr;
3766     
3767     TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
3768
3769     EnterCriticalSection(&This->cs);
3770
3771     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3772
3773     if (hr == S_OK)
3774         hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
3775
3776     LeaveCriticalSection(&This->cs);
3777
3778     return hr;
3779 }
3780
3781 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface,
3782                                                     long *pLeft,
3783                                                     long *pTop,
3784                                                     long *pWidth,
3785                                                     long *pHeight) {
3786     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3787     IVideoWindow* pVideoWindow;
3788     HRESULT hr;
3789
3790     TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3791
3792     EnterCriticalSection(&This->cs);
3793
3794     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3795
3796     if (hr == S_OK)
3797         hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
3798
3799     LeaveCriticalSection(&This->cs);
3800
3801     return hr;
3802 }
3803
3804 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface,
3805                                                        long *pWidth,
3806                                                        long *pHeight) {
3807     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3808     IVideoWindow* pVideoWindow;
3809     HRESULT hr;
3810
3811     TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3812
3813     EnterCriticalSection(&This->cs);
3814
3815     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3816
3817     if (hr == S_OK)
3818         hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
3819
3820     LeaveCriticalSection(&This->cs);
3821
3822     return hr;
3823 }
3824
3825 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface,
3826                                                        long *pWidth,
3827                                                        long *pHeight) {
3828     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3829     IVideoWindow* pVideoWindow;
3830     HRESULT hr;
3831
3832     TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3833
3834     EnterCriticalSection(&This->cs);
3835
3836     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3837
3838     if (hr == S_OK)
3839         hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
3840
3841     LeaveCriticalSection(&This->cs);
3842
3843     return hr;
3844 }
3845
3846 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface,
3847                                                      long *pLeft,
3848                                                      long *pTop,
3849                                                      long *pWidth,
3850                                                      long *pHeight) {
3851     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3852     IVideoWindow* pVideoWindow;
3853     HRESULT hr;
3854
3855     TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3856
3857     EnterCriticalSection(&This->cs);
3858
3859     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3860
3861     if (hr == S_OK)
3862         hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
3863
3864     LeaveCriticalSection(&This->cs);
3865
3866     return hr;
3867 }
3868
3869 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface,
3870                                              long HideCursor) {
3871     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3872     IVideoWindow* pVideoWindow;
3873     HRESULT hr;
3874
3875     TRACE("(%p/%p)->(%ld)\n", This, iface, HideCursor);
3876
3877     EnterCriticalSection(&This->cs);
3878
3879     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3880
3881     if (hr == S_OK)
3882         hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
3883
3884     LeaveCriticalSection(&This->cs);
3885
3886     return hr;
3887 }
3888
3889 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface,
3890                                                  long *CursorHidden) {
3891     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3892     IVideoWindow* pVideoWindow;
3893     HRESULT hr;
3894
3895     TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
3896
3897     EnterCriticalSection(&This->cs);
3898
3899     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3900
3901     if (hr == S_OK)
3902         hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
3903
3904     LeaveCriticalSection(&This->cs);
3905
3906     return hr;
3907 }
3908
3909
3910 static const IVideoWindowVtbl IVideoWindow_VTable =
3911 {
3912     VideoWindow_QueryInterface,
3913     VideoWindow_AddRef,
3914     VideoWindow_Release,
3915     VideoWindow_GetTypeInfoCount,
3916     VideoWindow_GetTypeInfo,
3917     VideoWindow_GetIDsOfNames,
3918     VideoWindow_Invoke,
3919     VideoWindow_put_Caption,
3920     VideoWindow_get_Caption,
3921     VideoWindow_put_WindowStyle,
3922     VideoWindow_get_WindowStyle,
3923     VideoWindow_put_WindowStyleEx,
3924     VideoWindow_get_WindowStyleEx,
3925     VideoWindow_put_AutoShow,
3926     VideoWindow_get_AutoShow,
3927     VideoWindow_put_WindowState,
3928     VideoWindow_get_WindowState,
3929     VideoWindow_put_BackgroundPalette,
3930     VideoWindow_get_BackgroundPalette,
3931     VideoWindow_put_Visible,
3932     VideoWindow_get_Visible,
3933     VideoWindow_put_Left,
3934     VideoWindow_get_Left,
3935     VideoWindow_put_Width,
3936     VideoWindow_get_Width,
3937     VideoWindow_put_Top,
3938     VideoWindow_get_Top,
3939     VideoWindow_put_Height,
3940     VideoWindow_get_Height,
3941     VideoWindow_put_Owner,
3942     VideoWindow_get_Owner,
3943     VideoWindow_put_MessageDrain,
3944     VideoWindow_get_MessageDrain,
3945     VideoWindow_get_BorderColor,
3946     VideoWindow_put_BorderColor,
3947     VideoWindow_get_FullScreenMode,
3948     VideoWindow_put_FullScreenMode,
3949     VideoWindow_SetWindowForeground,
3950     VideoWindow_NotifyOwnerMessage,
3951     VideoWindow_SetWindowPosition,
3952     VideoWindow_GetWindowPosition,
3953     VideoWindow_GetMinIdealImageSize,
3954     VideoWindow_GetMaxIdealImageSize,
3955     VideoWindow_GetRestorePosition,
3956     VideoWindow_HideCursor,
3957     VideoWindow_IsCursorHidden
3958 };
3959
3960
3961 /*** IUnknown methods ***/
3962 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface,
3963                                                 REFIID riid,
3964                                                 LPVOID*ppvObj) {
3965     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
3966
3967     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3968
3969     return Filtergraph_QueryInterface(This, riid, ppvObj);
3970 }
3971
3972 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface) {
3973     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
3974
3975     TRACE("(%p/%p)->()\n", This, iface);
3976
3977     return Filtergraph_AddRef(This);
3978 }
3979
3980 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface) {
3981     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
3982
3983     TRACE("(%p/%p)->()\n", This, iface);
3984
3985     return Filtergraph_Release(This);
3986 }
3987
3988 /*** IDispatch methods ***/
3989 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface,
3990                                                   UINT*pctinfo) {
3991     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
3992
3993     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
3994
3995     return S_OK;
3996 }
3997
3998 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface,
3999                                              UINT iTInfo,
4000                                              LCID lcid,
4001                                              ITypeInfo**ppTInfo) {
4002     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4003
4004     TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
4005
4006     return S_OK;
4007 }
4008
4009 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface,
4010                                                REFIID riid,
4011                                                LPOLESTR*rgszNames,
4012                                                UINT cNames,
4013                                                LCID lcid,
4014                                                DISPID*rgDispId) {
4015     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4016
4017     TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
4018
4019     return S_OK;
4020 }
4021
4022 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface,
4023                                         DISPID dispIdMember,
4024                                         REFIID riid,
4025                                         LCID lcid,
4026                                         WORD wFlags,
4027                                         DISPPARAMS*pDispParams,
4028                                         VARIANT*pVarResult,
4029                                         EXCEPINFO*pExepInfo,
4030                                         UINT*puArgErr) {
4031     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4032
4033     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);
4034
4035     return S_OK;
4036 }
4037
4038 /*** IMediaEvent methods ***/
4039 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface,
4040                                                 OAEVENT *hEvent) {
4041     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4042
4043     TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
4044
4045     *hEvent = (OAEVENT)This->evqueue.msg_event;
4046
4047     return S_OK;
4048 }
4049
4050 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface,
4051                                           long *lEventCode,
4052                                           LONG_PTR *lParam1,
4053                                           LONG_PTR *lParam2,
4054                                           long msTimeout) {
4055     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4056     Event evt;
4057
4058     TRACE("(%p/%p)->(%p, %p, %p, %ld)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
4059
4060     if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
4061     {
4062         *lEventCode = evt.lEventCode;
4063         *lParam1 = evt.lParam1;
4064         *lParam2 = evt.lParam2;
4065         return S_OK;
4066     }
4067
4068     *lEventCode = 0;
4069     return E_ABORT;
4070 }
4071
4072 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface,
4073                                                    long msTimeout,
4074                                                    long *pEvCode) {
4075     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4076
4077     TRACE("(%p/%p)->(%ld, %p)\n", This, iface, msTimeout, pEvCode);
4078
4079     if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
4080     {
4081         *pEvCode = This->CompletionStatus;
4082         return S_OK;
4083     }
4084
4085     *pEvCode = 0;
4086     return E_ABORT;
4087 }
4088
4089 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface,
4090                                                        long lEvCode) {
4091     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4092
4093     TRACE("(%p/%p)->(%ld)\n", This, iface, lEvCode);
4094
4095     if (lEvCode == EC_COMPLETE)
4096         This->HandleEcComplete = FALSE;
4097     else if (lEvCode == EC_REPAINT)
4098         This->HandleEcRepaint = FALSE;
4099     else
4100         return S_FALSE;
4101
4102     return S_OK;
4103 }
4104
4105 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface,
4106                                                         long lEvCode) {
4107     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4108
4109     TRACE("(%p/%p)->(%ld)\n", This, iface, lEvCode);
4110
4111     if (lEvCode == EC_COMPLETE)
4112         This->HandleEcComplete = TRUE;
4113     else if (lEvCode == EC_REPAINT)
4114         This->HandleEcRepaint = TRUE;
4115     else
4116         return S_FALSE;
4117
4118     return S_OK;
4119 }
4120
4121 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface,
4122                                                  long lEvCode,
4123                                                  LONG_PTR lParam1,
4124                                                  LONG_PTR lParam2) {
4125     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4126
4127     TRACE("(%p/%p)->(%ld, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
4128
4129     return S_OK;
4130 }
4131
4132 /*** IMediaEventEx methods ***/
4133 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface,
4134                                                  OAHWND hwnd,
4135                                                  long lMsg,
4136                                                  LONG_PTR lInstanceData) {
4137     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4138
4139     TRACE("(%p/%p)->(%08x, %ld, %08lx)\n", This, iface, (DWORD) hwnd, lMsg, lInstanceData);
4140
4141     This->notif.hWnd = (HWND)hwnd;
4142     This->notif.msg = lMsg;
4143     This->notif.instance = (long) lInstanceData;
4144
4145     return S_OK;
4146 }
4147
4148 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface,
4149                                                 long lNoNotifyFlags) {
4150     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4151
4152     TRACE("(%p/%p)->(%ld)\n", This, iface, lNoNotifyFlags);
4153
4154     if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
4155         return E_INVALIDARG;
4156
4157     This->notif.disabled = lNoNotifyFlags;
4158
4159     return S_OK;
4160 }
4161
4162 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface,
4163                                                 long *lplNoNotifyFlags) {
4164     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4165
4166     TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
4167
4168     if (!lplNoNotifyFlags)
4169         return E_POINTER;
4170
4171     *lplNoNotifyFlags = This->notif.disabled;
4172
4173     return S_OK;
4174 }
4175
4176
4177 static const IMediaEventExVtbl IMediaEventEx_VTable =
4178 {
4179     MediaEvent_QueryInterface,
4180     MediaEvent_AddRef,
4181     MediaEvent_Release,
4182     MediaEvent_GetTypeInfoCount,
4183     MediaEvent_GetTypeInfo,
4184     MediaEvent_GetIDsOfNames,
4185     MediaEvent_Invoke,
4186     MediaEvent_GetEventHandle,
4187     MediaEvent_GetEvent,
4188     MediaEvent_WaitForCompletion,
4189     MediaEvent_CancelDefaultHandling,
4190     MediaEvent_RestoreDefaultHandling,
4191     MediaEvent_FreeEventParams,
4192     MediaEvent_SetNotifyWindow,
4193     MediaEvent_SetNotifyFlags,
4194     MediaEvent_GetNotifyFlags
4195 };
4196
4197
4198 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, LPVOID *ppv)
4199 {
4200     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
4201
4202     return Filtergraph_QueryInterface(This, riid, ppv);
4203 }
4204
4205 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
4206 {
4207     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
4208
4209     return Filtergraph_AddRef(This);
4210 }
4211
4212 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
4213 {
4214     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
4215
4216     return Filtergraph_Release(This);
4217 }
4218
4219 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
4220 {
4221     FIXME("(%p): stub\n", pClassID);
4222
4223     return E_NOTIMPL;
4224 }
4225
4226 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
4227 {
4228     FIXME("(): stub\n");
4229
4230     return E_NOTIMPL;
4231 }
4232
4233 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
4234 {
4235     FIXME("(): stub\n");
4236
4237     return E_NOTIMPL;
4238 }
4239
4240 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
4241 {
4242     FIXME("(0x%s): stub\n", wine_dbgstr_longlong(tStart));
4243
4244     return E_NOTIMPL;
4245 }
4246
4247 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout, FILTER_STATE * pState)
4248 {
4249     FIXME("(%d, %p): stub\n", dwMsTimeout, pState);
4250
4251     return E_NOTIMPL;
4252 }
4253
4254 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
4255 {
4256     FIXME("(%p): stub\n", pClock);
4257
4258     return E_NOTIMPL;
4259 }
4260
4261 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
4262 {
4263     FIXME("(%p): stub\n", ppClock);
4264
4265     return E_NOTIMPL;
4266 }
4267
4268 static const IMediaFilterVtbl IMediaFilter_VTable =
4269 {
4270     MediaFilter_QueryInterface,
4271     MediaFilter_AddRef,
4272     MediaFilter_Release,
4273     MediaFilter_GetClassID,
4274     MediaFilter_Stop,
4275     MediaFilter_Pause,
4276     MediaFilter_Run,
4277     MediaFilter_GetState,
4278     MediaFilter_SetSyncSource,
4279     MediaFilter_GetSyncSource
4280 };
4281
4282 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, LPVOID *ppv)
4283 {
4284     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
4285
4286     return Filtergraph_QueryInterface(This, riid, ppv);
4287 }
4288
4289 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
4290 {
4291     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
4292
4293     return Filtergraph_AddRef(This);
4294 }
4295
4296 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
4297 {
4298     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
4299
4300     return Filtergraph_Release(This);
4301 }
4302
4303 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, long EventCode, LONG_PTR EventParam1, LONG_PTR EventParam2)
4304 {
4305     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
4306     Event evt;
4307
4308     TRACE("(%p/%p)->(%ld, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
4309
4310     /* We need thread safety here, let's use the events queue's one */
4311     EnterCriticalSection(&This->evqueue.msg_crst);
4312
4313     if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
4314     {
4315         TRACE("Process EC_COMPLETE notification\n");
4316         if (++This->EcCompleteCount == This->nRenderers)
4317         {
4318             evt.lEventCode = EC_COMPLETE;
4319             evt.lParam1 = S_OK;
4320             evt.lParam2 = 0;
4321             TRACE("Send EC_COMPLETE to app\n");
4322             EventsQueue_PutEvent(&This->evqueue, &evt);
4323             if (!This->notif.disabled && This->notif.hWnd)
4324             {
4325                 TRACE("Send Window message\n");
4326                 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
4327             }
4328             This->CompletionStatus = EC_COMPLETE;
4329             SetEvent(This->hEventCompletion);
4330         }
4331     }
4332     else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
4333     {
4334         /* FIXME: Not handled yet */
4335     }
4336     else
4337     {
4338         evt.lEventCode = EventCode;
4339         evt.lParam1 = EventParam1;
4340         evt.lParam2 = EventParam2;
4341         EventsQueue_PutEvent(&This->evqueue, &evt);
4342         if (!This->notif.disabled && This->notif.hWnd)
4343             PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
4344     }
4345
4346     LeaveCriticalSection(&This->evqueue.msg_crst);
4347     return S_OK;
4348 }
4349
4350 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
4351 {
4352     MediaEventSink_QueryInterface,
4353     MediaEventSink_AddRef,
4354     MediaEventSink_Release,
4355     MediaEventSink_Notify
4356 };
4357
4358 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, LPVOID *ppv)
4359 {
4360     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
4361
4362     return Filtergraph_QueryInterface(This, riid, ppv);
4363 }
4364
4365 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
4366 {
4367     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
4368
4369     return Filtergraph_AddRef(This);
4370 }
4371
4372 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
4373 {
4374     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
4375
4376     return Filtergraph_Release(This);
4377 }
4378
4379 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface,
4380                                             IPin* pOutputPin,
4381                                             IPin* pInputPin,
4382                                             const AM_MEDIA_TYPE* pmtFirstConnection,
4383                                             IBaseFilter* pUsingFilter,
4384                                             HANDLE hAbortEvent,
4385                                             DWORD dwFlags)
4386 {
4387     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
4388
4389     FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
4390     
4391     return E_NOTIMPL;
4392 }
4393
4394 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface,
4395                                               IGraphConfigCallback* pCallback,
4396                                               PVOID pvContext,
4397                                               DWORD dwFlags,
4398                                               HANDLE hAbortEvent)
4399 {
4400     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
4401
4402     FIXME("(%p)->(%p, %p, %x, %p): stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
4403     
4404     return E_NOTIMPL;
4405 }
4406
4407 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface,
4408                                                    IBaseFilter* pFilter)
4409 {
4410     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
4411
4412     FIXME("(%p)->(%p): stub!\n", This, pFilter);
4413     
4414     return E_NOTIMPL;
4415 }
4416
4417 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface,
4418                                                   IEnumFilters** pEnum)
4419 {
4420     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
4421
4422     FIXME("(%p)->(%p): stub!\n", This, pEnum);
4423     
4424     return E_NOTIMPL;
4425 }
4426
4427 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface,
4428                                                         IBaseFilter* pFilter)
4429 {
4430     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
4431
4432     FIXME("(%p)->(%p): stub!\n", This, pFilter);
4433     
4434     return E_NOTIMPL;
4435 }
4436
4437 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface,
4438                                                REFERENCE_TIME* prtStart)
4439 {
4440     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
4441
4442     FIXME("(%p)->(%p): stub!\n", This, prtStart);
4443     
4444     return E_NOTIMPL;
4445 }
4446
4447 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface,
4448                                                   IPin* pOutputPin,
4449                                                   IPinConnection* pConnection,
4450                                                   HANDLE hEventAbort)
4451 {
4452     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
4453
4454     FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
4455     
4456     return E_NOTIMPL;
4457 }
4458
4459 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface,
4460                                                  IBaseFilter* pFilter,
4461                                                  DWORD dwFlags)
4462 {
4463     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
4464
4465     FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
4466     
4467     return E_NOTIMPL;
4468 }
4469
4470 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface,
4471                                                  IBaseFilter* pFilter,
4472                                                  DWORD* dwFlags)
4473 {
4474     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
4475
4476     FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
4477     
4478     return E_NOTIMPL;
4479 }
4480
4481 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface,
4482                                                  IBaseFilter* pFilter,
4483                                                  DWORD dwFlags)
4484 {
4485     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
4486
4487     FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
4488     
4489     return E_NOTIMPL;
4490 }
4491
4492 static const IGraphConfigVtbl IGraphConfig_VTable =
4493 {
4494     GraphConfig_QueryInterface,
4495     GraphConfig_AddRef,
4496     GraphConfig_Release,
4497     GraphConfig_Reconnect,
4498     GraphConfig_Reconfigure,
4499     GraphConfig_AddFilterToCache,
4500     GraphConfig_EnumCacheFilter,
4501     GraphConfig_RemoveFilterFromCache,
4502     GraphConfig_GetStartTime,
4503     GraphConfig_PushThroughData,
4504     GraphConfig_SetFilterFlags,
4505     GraphConfig_GetFilterFlags,
4506     GraphConfig_RemoveFilterEx
4507 };
4508
4509 /* This is the only function that actually creates a FilterGraph class... */
4510 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
4511 {
4512     IFilterGraphImpl *fimpl;
4513     HRESULT hr;
4514
4515     TRACE("(%p,%p)\n", pUnkOuter, ppObj);
4516
4517     if( pUnkOuter )
4518         return CLASS_E_NOAGGREGATION;
4519
4520     fimpl = CoTaskMemAlloc(sizeof(*fimpl));
4521     fimpl->IGraphBuilder_vtbl = &IGraphBuilder_VTable;
4522     fimpl->IMediaControl_vtbl = &IMediaControl_VTable;
4523     fimpl->IMediaSeeking_vtbl = &IMediaSeeking_VTable;
4524     fimpl->IBasicAudio_vtbl = &IBasicAudio_VTable;
4525     fimpl->IBasicVideo_vtbl = &IBasicVideo_VTable;
4526     fimpl->IVideoWindow_vtbl = &IVideoWindow_VTable;
4527     fimpl->IMediaEventEx_vtbl = &IMediaEventEx_VTable;
4528     fimpl->IMediaFilter_vtbl = &IMediaFilter_VTable;
4529     fimpl->IMediaEventSink_vtbl = &IMediaEventSink_VTable;
4530     fimpl->IGraphConfig_vtbl = &IGraphConfig_VTable;
4531     fimpl->IMediaPosition_vtbl = &IMediaPosition_VTable;
4532     fimpl->ref = 1;
4533     fimpl->ppFiltersInGraph = NULL;
4534     fimpl->pFilterNames = NULL;
4535     fimpl->nFilters = 0;
4536     fimpl->filterCapacity = 0;
4537     fimpl->nameIndex = 1;
4538     fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
4539     fimpl->HandleEcComplete = TRUE;
4540     fimpl->HandleEcRepaint = TRUE;
4541     fimpl->notif.hWnd = 0;
4542     fimpl->notif.disabled = FALSE;
4543     fimpl->nRenderers = 0;
4544     fimpl->EcCompleteCount = 0;
4545     fimpl->state = State_Stopped;
4546     EventsQueue_Init(&fimpl->evqueue);
4547     InitializeCriticalSection(&fimpl->cs);
4548     fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
4549     fimpl->nItfCacheEntries = 0;
4550
4551     hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&fimpl->pFilterMapper2);
4552     if (FAILED(hr)) {
4553         ERR("Unable to create filter mapper (%x)\n", hr);
4554         return hr;
4555     }
4556
4557     *ppObj = fimpl;
4558     return S_OK;
4559 }
4560
4561 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
4562 {
4563     FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
4564     return FilterGraph_create(pUnkOuter, ppObj);
4565 }