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