mshtml: Add tests for get_scrollLeft.
[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         IEnumMoniker_Release(pEnumMoniker);
1374         if (nbmt)
1375             DeleteMediaType(mt);
1376         if (SUCCEEDED(hr))
1377             break;
1378         hr = S_OK;
1379     }
1380
1381     IEnumMediaTypes_Release(penummt);
1382     return hr;
1383 }
1384
1385 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface,
1386                                               LPCWSTR lpcwstrFile,
1387                                               LPCWSTR lpcwstrPlayList)
1388 {
1389     ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1390     static const WCHAR string[] = {'R','e','a','d','e','r',0};
1391     IBaseFilter* preader = NULL;
1392     IPin* ppinreader = NULL;
1393     IEnumPins* penumpins = NULL;
1394     HRESULT hr;
1395     BOOL partial = FALSE;
1396     HRESULT any = FALSE;
1397
1398     TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1399
1400     if (lpcwstrPlayList != NULL)
1401         return E_INVALIDARG;
1402
1403     hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, string, &preader);
1404     if (FAILED(hr))
1405         return hr;
1406
1407     if (SUCCEEDED(hr))
1408         hr = IBaseFilter_EnumPins(preader, &penumpins);
1409     if (SUCCEEDED(hr))
1410     {
1411         while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1412         {
1413             PIN_DIRECTION dir;
1414
1415             IPin_QueryDirection(ppinreader, &dir);
1416             if (dir == PINDIR_OUTPUT)
1417             {
1418                 INT i;
1419
1420                 hr = IFilterGraph2_Render(iface, ppinreader);
1421                 TRACE("Render %08x\n", hr);
1422
1423                 for (i = 0; i < This->nFilters; ++i)
1424                     TRACE("Filters in chain: %s\n", debugstr_w(This->pFilterNames[i]));
1425
1426                 if (SUCCEEDED(hr))
1427                     any = TRUE;
1428                 if (hr != S_OK)
1429                     partial = TRUE;
1430             }
1431             IPin_Release(ppinreader);
1432         }
1433         IEnumPins_Release(penumpins);
1434
1435         if (!any)
1436             hr = VFW_E_CANNOT_RENDER;
1437         else if (partial)
1438             hr = VFW_S_PARTIAL_RENDER;
1439         else
1440             hr = S_OK;
1441     }
1442     IBaseFilter_Release(preader);
1443
1444     TRACE("--> %08x\n", hr);
1445     return hr;
1446 }
1447
1448 /* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
1449 static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
1450 {
1451     static const WCHAR wszReg[] = {'M','e','d','i','a',' ','T','y','p','e','\\','E','x','t','e','n','s','i','o','n','s',0};
1452     HRESULT hr = S_OK;
1453     HKEY extkey;
1454     LONG lRet;
1455
1456     lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszReg, 0, KEY_READ, &extkey);
1457     hr = HRESULT_FROM_WIN32(lRet);
1458
1459     if (SUCCEEDED(hr))
1460     {
1461         static const WCHAR filtersource[] = {'S','o','u','r','c','e',' ','F','i','l','t','e','r',0};
1462         WCHAR *ext = PathFindExtensionW(pszFileName);
1463         WCHAR clsid_key[39];
1464         GUID clsid;
1465         DWORD size = sizeof(clsid_key);
1466         HKEY pathkey;
1467
1468         if (!ext)
1469         {
1470             CloseHandle(extkey);
1471             return E_FAIL;
1472         }
1473
1474         lRet = RegOpenKeyExW(extkey, ext, 0, KEY_READ, &pathkey);
1475         hr = HRESULT_FROM_WIN32(lRet);
1476         CloseHandle(extkey);
1477         if (FAILED(hr))
1478             return hr;
1479
1480         lRet = RegQueryValueExW(pathkey, filtersource, NULL, NULL, (LPBYTE)clsid_key, &size);
1481         hr = HRESULT_FROM_WIN32(lRet);
1482         CloseHandle(pathkey);
1483         if (FAILED(hr))
1484             return hr;
1485
1486         CLSIDFromString(clsid_key, &clsid);
1487
1488         TRACE("CLSID: %s\n", debugstr_guid(&clsid));
1489         hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1490         if (SUCCEEDED(hr))
1491         {
1492             IFileSourceFilter *source = NULL;
1493             hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID*)&source);
1494             if (SUCCEEDED(hr))
1495                 IFileSourceFilter_Release(source);
1496             else
1497                 IBaseFilter_Release(*filter);
1498         }
1499     }
1500     if (FAILED(hr))
1501         *filter = NULL;
1502     return hr;
1503 }
1504
1505 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface,
1506                                                    LPCWSTR lpcwstrFileName,
1507                                                    LPCWSTR lpcwstrFilterName,
1508                                                    IBaseFilter **ppFilter) {
1509     ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1510     HRESULT hr;
1511     IBaseFilter* preader;
1512     IFileSourceFilter* pfile = NULL;
1513     AM_MEDIA_TYPE mt;
1514     WCHAR* filename;
1515
1516     TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1517
1518     /* Try from file name first, then fall back to default asynchronous reader */
1519     hr = GetFileSourceFilter(lpcwstrFileName, &preader);
1520
1521     if (FAILED(hr))
1522         hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&preader);
1523     if (FAILED(hr)) {
1524         WARN("Unable to create file source filter (%x)\n", hr);
1525         return hr;
1526     }
1527
1528     hr = IFilterGraph2_AddFilter(iface, preader, lpcwstrFilterName);
1529     if (FAILED(hr)) {
1530         WARN("Unable add filter (%x)\n", hr);
1531         IBaseFilter_Release(preader);
1532         return hr;
1533     }
1534
1535     hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1536     if (FAILED(hr)) {
1537         WARN("Unable to get IFileSourceInterface (%x)\n", hr);
1538         goto error;
1539     }
1540
1541     /* Load the file in the file source filter */
1542     hr = IFileSourceFilter_Load(pfile, lpcwstrFileName, NULL);
1543     if (FAILED(hr)) {
1544         WARN("Load (%x)\n", hr);
1545         goto error;
1546     }
1547
1548     IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1549     if (FAILED(hr)) {
1550         WARN("GetCurFile (%x)\n", hr);
1551         goto error;
1552     }
1553
1554     TRACE("File %s\n", debugstr_w(filename));
1555     TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
1556     TRACE("SubType %s\n", debugstr_guid(&mt.subtype));
1557
1558     if (ppFilter)
1559         *ppFilter = preader;
1560     IFileSourceFilter_Release(pfile);
1561
1562     return S_OK;
1563     
1564 error:
1565     if (pfile)
1566         IFileSourceFilter_Release(pfile);
1567     IFilterGraph2_RemoveFilter(iface, preader);
1568     IBaseFilter_Release(preader);
1569        
1570     return hr;
1571 }
1572
1573 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface,
1574                                               DWORD_PTR hFile) {
1575     ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1576
1577     TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1578
1579     return S_OK;
1580 }
1581
1582 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface) {
1583     ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1584
1585     TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1586
1587     return S_OK;
1588 }
1589
1590 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface) {
1591     ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1592
1593     TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1594
1595     return S_OK;
1596 }
1597
1598 /*** IFilterGraph2 methods ***/
1599 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1600                                                              IMoniker *pMoniker,
1601                                                              IBindCtx *pCtx,
1602                                                              LPCWSTR lpcwstrFilterName,
1603                                                              IBaseFilter **ppFilter) {
1604     ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1605
1606     TRACE("(%p/%p)->(%p %p %s %p): stub !!!\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1607
1608     return S_OK;
1609 }
1610
1611 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface,
1612                                                IPin *ppin,
1613                                                const AM_MEDIA_TYPE *pmt) {
1614     ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1615
1616     TRACE("(%p/%p)->(%p %p): stub !!!\n", This, iface, ppin, pmt);
1617
1618     return S_OK;
1619 }
1620
1621 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface,
1622                                             IPin *pPinOut,
1623                                             DWORD dwFlags,
1624                                             DWORD *pvContext) {
1625     ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1626
1627     TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This, iface, pPinOut, dwFlags, pvContext);
1628
1629     return S_OK;
1630 }
1631
1632
1633 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1634 {
1635     FilterGraph2_QueryInterface,
1636     FilterGraph2_AddRef,
1637     FilterGraph2_Release,
1638     FilterGraph2_AddFilter,
1639     FilterGraph2_RemoveFilter,
1640     FilterGraph2_EnumFilters,
1641     FilterGraph2_FindFilterByName,
1642     FilterGraph2_ConnectDirect,
1643     FilterGraph2_Reconnect,
1644     FilterGraph2_Disconnect,
1645     FilterGraph2_SetDefaultSyncSource,
1646     FilterGraph2_Connect,
1647     FilterGraph2_Render,
1648     FilterGraph2_RenderFile,
1649     FilterGraph2_AddSourceFilter,
1650     FilterGraph2_SetLogFile,
1651     FilterGraph2_Abort,
1652     FilterGraph2_ShouldOperationContinue,
1653     FilterGraph2_AddSourceFilterForMoniker,
1654     FilterGraph2_ReconnectEx,
1655     FilterGraph2_RenderEx
1656 };
1657
1658 /*** IUnknown methods ***/
1659 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface,
1660                                                   REFIID riid,
1661                                                   LPVOID*ppvObj) {
1662     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1663
1664     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1665
1666     return Filtergraph_QueryInterface(This, riid, ppvObj);
1667 }
1668
1669 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface) {
1670     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1671
1672     TRACE("(%p/%p)->()\n", This, iface);
1673
1674     return Filtergraph_AddRef(This);
1675 }
1676
1677 static ULONG WINAPI MediaControl_Release(IMediaControl *iface) {
1678     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1679
1680     TRACE("(%p/%p)->()\n", This, iface);
1681
1682     return Filtergraph_Release(This);
1683
1684 }
1685
1686 /*** IDispatch methods ***/
1687 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface,
1688                                                     UINT*pctinfo) {
1689     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1690
1691     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1692
1693     return S_OK;
1694 }
1695
1696 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface,
1697                                                UINT iTInfo,
1698                                                LCID lcid,
1699                                                ITypeInfo**ppTInfo) {
1700     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1701
1702     TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1703
1704     return S_OK;
1705 }
1706
1707 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface,
1708                                                  REFIID riid,
1709                                                  LPOLESTR*rgszNames,
1710                                                  UINT cNames,
1711                                                  LCID lcid,
1712                                                  DISPID*rgDispId) {
1713     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1714
1715     TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1716
1717     return S_OK;
1718 }
1719
1720 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface,
1721                                           DISPID dispIdMember,
1722                                           REFIID riid,
1723                                           LCID lcid,
1724                                           WORD wFlags,
1725                                           DISPPARAMS*pDispParams,
1726                                           VARIANT*pVarResult,
1727                                           EXCEPINFO*pExepInfo,
1728                                           UINT*puArgErr) {
1729     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1730
1731     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);
1732
1733     return S_OK;
1734 }
1735
1736 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *, DWORD_PTR data);
1737
1738 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter, DWORD_PTR data)
1739 {
1740     HRESULT hr;
1741     IPin* pInputPin;
1742     IPin** ppPins;
1743     ULONG nb;
1744     ULONG i;
1745     PIN_INFO PinInfo;
1746
1747     TRACE("%p %p\n", pGraph, pOutputPin);
1748     PinInfo.pFilter = NULL;
1749
1750     hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1751
1752     if (SUCCEEDED(hr))
1753     {
1754         hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1755         if (SUCCEEDED(hr))
1756             hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1757         IPin_Release(pInputPin);
1758     }
1759
1760     if (SUCCEEDED(hr))
1761     {
1762         if (nb == 0)
1763         {
1764             TRACE("Reached a renderer\n");
1765             /* Count renderers for end of stream notification */
1766             pGraph->nRenderers++;
1767         }
1768         else
1769         {
1770             for(i = 0; i < nb; i++)
1771             {
1772                 /* Explore the graph downstream from this pin
1773                  * FIXME: We should prevent exploring from a pin more than once. This can happens when
1774                  * several input pins are connected to the same output (a MUX for instance). */
1775                 ExploreGraph(pGraph, ppPins[i], FoundFilter, data);
1776                 IPin_Release(ppPins[i]);
1777             }
1778
1779             CoTaskMemFree(ppPins);
1780         }
1781         TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1782
1783         FoundFilter(PinInfo.pFilter, data);
1784     }
1785
1786     if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1787     return hr;
1788 }
1789
1790 static HRESULT WINAPI SendRun(IBaseFilter *pFilter, DWORD_PTR data)
1791 {
1792     LONGLONG time = 0;
1793     IReferenceClock *clock = NULL;
1794
1795     IBaseFilter_GetSyncSource(pFilter, &clock);
1796     if (clock)
1797     {
1798         IReferenceClock_GetTime(clock, &time);
1799         if (time)
1800             /* Add 50 ms */
1801             time += 500000;
1802         if (time < 0)
1803             time = 0;
1804         IReferenceClock_Release(clock);
1805     }
1806
1807     return IBaseFilter_Run(pFilter, time);
1808 }
1809
1810 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1811 {
1812     return IBaseFilter_Pause(pFilter);
1813 }
1814
1815 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1816 {
1817     return IBaseFilter_Stop(pFilter);
1818 }
1819
1820 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1821 {
1822     FILTER_STATE state;
1823     DWORD time_end = data;
1824     DWORD time_now = GetTickCount();
1825     LONG wait;
1826
1827     if (time_end == INFINITE)
1828     {
1829         wait = INFINITE;
1830     }
1831     else if (time_end > time_now)
1832     {
1833         wait = time_end - time_now;
1834     }
1835     else
1836         wait = 0;
1837
1838     return IBaseFilter_GetState(pFilter, wait, &state);
1839 }
1840
1841
1842 static HRESULT SendFilterMessage(IMediaControl *iface, fnFoundFilter FoundFilter, DWORD_PTR data)
1843 {
1844     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1845     int i;
1846     IBaseFilter* pfilter;
1847     IEnumPins* pEnum;
1848     HRESULT hr;
1849     IPin* pPin;
1850     DWORD dummy;
1851     PIN_DIRECTION dir;
1852     TRACE("(%p/%p)->()\n", This, iface);
1853
1854     /* Explorer the graph from source filters to renderers, determine renderers
1855      * number and run filters from renderers to source filters */
1856     This->nRenderers = 0;
1857     ResetEvent(This->hEventCompletion);
1858
1859     for(i = 0; i < This->nFilters; i++)
1860     {
1861         BOOL source = TRUE;
1862         pfilter = This->ppFiltersInGraph[i];
1863         hr = IBaseFilter_EnumPins(pfilter, &pEnum);
1864         if (hr != S_OK)
1865         {
1866             WARN("Enum pins failed %x\n", hr);
1867             continue;
1868         }
1869         /* Check if it is a source filter */
1870         while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1871         {
1872             IPin_QueryDirection(pPin, &dir);
1873             IPin_Release(pPin);
1874             if (dir == PINDIR_INPUT)
1875             {
1876                 source = FALSE;
1877                 break;
1878             }
1879         }
1880         if (source)
1881         {
1882             TRACE("Found a source filter %p\n", pfilter);
1883             IEnumPins_Reset(pEnum);
1884             while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1885             {
1886                 /* Explore the graph downstream from this pin */
1887                 ExploreGraph(This, pPin, FoundFilter, data);
1888                 IPin_Release(pPin);
1889             }
1890             FoundFilter(pfilter, data);
1891         }
1892         IEnumPins_Release(pEnum);
1893     }
1894
1895     return S_FALSE;
1896 }
1897
1898 /*** IMediaControl methods ***/
1899 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface) {
1900     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1901     TRACE("(%p/%p)->()\n", This, iface);
1902
1903     if (This->state == State_Running) return S_OK;
1904
1905     EnterCriticalSection(&This->cs);
1906     if (This->state == State_Stopped)
1907         This->EcCompleteCount = 0;
1908
1909     if (This->refClock)
1910     {
1911         IReferenceClock_GetTime(This->refClock, &This->start_time);
1912         This->start_time += 500000;
1913     }
1914     else This->position = This->start_time = 0;
1915
1916     SendFilterMessage(iface, SendRun, 0);
1917     This->state = State_Running;
1918     LeaveCriticalSection(&This->cs);
1919     return S_FALSE;
1920 }
1921
1922 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface) {
1923     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1924     TRACE("(%p/%p)->()\n", This, iface);
1925
1926     if (This->state == State_Paused) return S_OK;
1927
1928     EnterCriticalSection(&This->cs);
1929     if (This->state == State_Stopped)
1930         This->EcCompleteCount = 0;
1931
1932     if (This->state == State_Running && This->refClock)
1933     {
1934         LONGLONG time = This->start_time;
1935         IReferenceClock_GetTime(This->refClock, &time);
1936         This->position += time - This->start_time;
1937     }
1938
1939     SendFilterMessage(iface, SendPause, 0);
1940     This->state = State_Paused;
1941     LeaveCriticalSection(&This->cs);
1942     return S_FALSE;
1943 }
1944
1945 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface) {
1946     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1947     TRACE("(%p/%p)->()\n", This, iface);
1948
1949     if (This->state == State_Stopped) return S_OK;
1950
1951     EnterCriticalSection(&This->cs);
1952     if (This->state == State_Running && This->refClock)
1953     {
1954         LONGLONG time = This->start_time;
1955         IReferenceClock_GetTime(This->refClock, &time);
1956         This->position += time - This->start_time;
1957     }
1958
1959     if (This->state == State_Running) SendFilterMessage(iface, SendPause, 0);
1960     SendFilterMessage(iface, SendStop, 0);
1961     This->state = State_Stopped;
1962     LeaveCriticalSection(&This->cs);
1963     return S_OK;
1964 }
1965
1966 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface,
1967                                             LONG msTimeout,
1968                                             OAFilterState *pfs) {
1969     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1970     DWORD end;
1971
1972     TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
1973
1974     if (!pfs)
1975         return E_POINTER;
1976
1977     EnterCriticalSection(&This->cs);
1978
1979     *pfs = This->state;
1980     if (msTimeout > 0)
1981     {
1982         end = GetTickCount() + msTimeout;
1983     }
1984     else if (msTimeout < 0)
1985     {
1986         end = INFINITE;
1987     }
1988     else
1989     {
1990         end = 0;
1991     }
1992     if (end)
1993         SendFilterMessage(iface, SendGetState, end);
1994
1995     LeaveCriticalSection(&This->cs);
1996
1997     return S_OK;
1998 }
1999
2000 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface,
2001                                               BSTR strFilename) {
2002     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2003
2004     FIXME("(%p/%p)->(%s (%p)): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename);
2005
2006     return S_OK;
2007 }
2008
2009 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface,
2010                                                    BSTR strFilename,
2011                                                    IDispatch **ppUnk) {
2012     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2013
2014     FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2015
2016     return S_OK;
2017 }
2018
2019 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface,
2020                                                         IDispatch **ppUnk) {
2021     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2022
2023     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2024
2025     return S_OK;
2026 }
2027
2028 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface,
2029                                                            IDispatch **ppUnk) {
2030     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2031
2032     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2033
2034     return S_OK;
2035 }
2036
2037 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface) {
2038     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2039
2040     FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2041
2042     return S_OK;
2043 }
2044
2045
2046 static const IMediaControlVtbl IMediaControl_VTable =
2047 {
2048     MediaControl_QueryInterface,
2049     MediaControl_AddRef,
2050     MediaControl_Release,
2051     MediaControl_GetTypeInfoCount,
2052     MediaControl_GetTypeInfo,
2053     MediaControl_GetIDsOfNames,
2054     MediaControl_Invoke,
2055     MediaControl_Run,
2056     MediaControl_Pause,
2057     MediaControl_Stop,
2058     MediaControl_GetState,
2059     MediaControl_RenderFile,
2060     MediaControl_AddSourceFilter,
2061     MediaControl_get_FilterCollection,
2062     MediaControl_get_RegFilterCollection,
2063     MediaControl_StopWhenReady
2064 };
2065
2066
2067 /*** IUnknown methods ***/
2068 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface,
2069                                                   REFIID riid,
2070                                                   LPVOID*ppvObj) {
2071     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2072
2073     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2074
2075     return Filtergraph_QueryInterface(This, riid, ppvObj);
2076 }
2077
2078 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface) {
2079     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2080
2081     TRACE("(%p/%p)->()\n", This, iface);
2082
2083     return Filtergraph_AddRef(This);
2084 }
2085
2086 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface) {
2087     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2088
2089     TRACE("(%p/%p)->()\n", This, iface);
2090
2091     return Filtergraph_Release(This);
2092 }
2093
2094 typedef HRESULT WINAPI (*fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
2095
2096 static HRESULT all_renderers_seek(IFilterGraphImpl *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2097     BOOL allnotimpl = TRUE;
2098     int i;
2099     IBaseFilter* pfilter;
2100     IEnumPins* pEnum;
2101     HRESULT hr, hr_return = S_OK;
2102     IPin* pPin;
2103     DWORD dummy;
2104     PIN_DIRECTION dir;
2105
2106     TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2107     /* Send a message to all renderers, they are responsible for broadcasting it further */
2108
2109     for(i = 0; i < This->nFilters; i++)
2110     {
2111         BOOL renderer = TRUE;
2112         pfilter = This->ppFiltersInGraph[i];
2113         hr = IBaseFilter_EnumPins(pfilter, &pEnum);
2114         if (hr != S_OK)
2115         {
2116             WARN("Enum pins failed %x\n", hr);
2117             continue;
2118         }
2119         /* Check if it is a source filter */
2120         while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2121         {
2122             IPin_QueryDirection(pPin, &dir);
2123             IPin_Release(pPin);
2124             if (dir != PINDIR_INPUT)
2125             {
2126                 renderer = FALSE;
2127                 break;
2128             }
2129         }
2130         IEnumPins_Release(pEnum);
2131         if (renderer)
2132         {
2133             IMediaSeeking *seek = NULL;
2134             IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2135             if (!seek)
2136                 continue;
2137
2138             hr = FoundSeek(This, seek, arg);
2139
2140             IMediaSeeking_Release(seek);
2141             if (hr_return != E_NOTIMPL)
2142                 allnotimpl = FALSE;
2143             if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && !FAILED(hr_return)))
2144                 hr_return = hr;
2145         }
2146     }
2147
2148     if (allnotimpl)
2149         return E_NOTIMPL;
2150     return hr_return;
2151 }
2152
2153 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2154 {
2155     HRESULT hr;
2156     DWORD caps = 0;
2157
2158     hr = IMediaSeeking_GetCapabilities(seek, &caps);
2159     if (FAILED(hr))
2160         return hr;
2161
2162     /* Only add common capabilities everything supports */
2163     *(DWORD*)pcaps &= caps;
2164
2165     return hr;
2166 }
2167
2168 /*** IMediaSeeking methods ***/
2169 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface,
2170                                                    DWORD *pCapabilities) {
2171     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2172     HRESULT hr;
2173     TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2174
2175     if (!pCapabilities)
2176         return E_POINTER;
2177
2178     EnterCriticalSection(&This->cs);
2179     *pCapabilities = 0xffffffff;
2180
2181     hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2182     LeaveCriticalSection(&This->cs);
2183
2184     return hr;
2185 }
2186
2187 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface,
2188                                                      DWORD *pCapabilities) {
2189     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2190     DWORD originalcaps;
2191     HRESULT hr;
2192     TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2193
2194     if (!pCapabilities)
2195         return E_POINTER;
2196
2197     EnterCriticalSection(&This->cs);
2198     originalcaps = *pCapabilities;
2199     hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2200     LeaveCriticalSection(&This->cs);
2201
2202     if (FAILED(hr))
2203         return hr;
2204
2205     if (!*pCapabilities)
2206         return E_FAIL;
2207     if (*pCapabilities != originalcaps)
2208         return S_FALSE;
2209     return S_OK;
2210 }
2211
2212 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface,
2213                                                      const GUID *pFormat) {
2214     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2215
2216     if (!pFormat)
2217         return E_POINTER;
2218
2219     TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2220
2221     if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2222     {
2223         FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2224         return S_FALSE;
2225     }
2226
2227     return S_OK;
2228 }
2229
2230 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface,
2231                                                         GUID *pFormat) {
2232     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2233
2234     if (!pFormat)
2235         return E_POINTER;
2236
2237     FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2238     memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2239
2240     return S_OK;
2241 }
2242
2243 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface,
2244                                                  GUID *pFormat) {
2245     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2246
2247     if (!pFormat)
2248         return E_POINTER;
2249
2250     TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2251     memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2252
2253     return S_OK;
2254 }
2255
2256 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface,
2257                                                      const GUID *pFormat) {
2258     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2259
2260     TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2261     if (!pFormat)
2262         return E_POINTER;
2263
2264     if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2265         return S_FALSE;
2266
2267     return S_OK;
2268 }
2269
2270 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface,
2271                                                  const GUID *pFormat) {
2272     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2273
2274     if (!pFormat)
2275         return E_POINTER;
2276
2277     TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2278
2279     if (This->state != State_Stopped)
2280         return VFW_E_WRONG_STATE;
2281
2282     if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2283     {
2284         FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2285         return E_INVALIDARG;
2286     }
2287
2288     return S_OK;
2289 }
2290
2291 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2292 {
2293     HRESULT hr;
2294     LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2295
2296     hr = IMediaSeeking_GetDuration(seek, &duration);
2297     if (FAILED(hr))
2298         return hr;
2299
2300     /* FIXME: Minimum or maximum duration? Assuming minimum */
2301     if (duration > 0 && *pdur < duration)
2302         *pdur = duration;
2303
2304     return hr;
2305 }
2306
2307 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface,
2308                                                LONGLONG *pDuration) {
2309     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2310     HRESULT hr;
2311
2312     TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2313
2314     if (!pDuration)
2315         return E_POINTER;
2316
2317     EnterCriticalSection(&This->cs);
2318     *pDuration = -1;
2319     hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2320     LeaveCriticalSection(&This->cs);
2321
2322     TRACE("--->%08x\n", hr);
2323     return hr;
2324 }
2325
2326 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface,
2327                                                    LONGLONG *pStop) {
2328     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2329     HRESULT hr = S_OK;
2330
2331     TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2332
2333     if (!pStop)
2334         return E_POINTER;
2335
2336     EnterCriticalSection(&This->cs);
2337     if (This->stop_position < 0)
2338         /* Stop position not set, use duration instead */
2339         hr = IMediaSeeking_GetDuration(iface, pStop);
2340     else
2341         *pStop = This->stop_position;
2342
2343     LeaveCriticalSection(&This->cs);
2344
2345     return hr;
2346 }
2347
2348 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface,
2349                                                       LONGLONG *pCurrent) {
2350     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2351     LONGLONG time = 0;
2352
2353     if (!pCurrent)
2354         return E_POINTER;
2355
2356     EnterCriticalSection(&This->cs);
2357     if (This->state == State_Running && This->refClock)
2358     {
2359         IReferenceClock_GetTime(This->refClock, &time);
2360         if (time)
2361             time += This->position - This->start_time;
2362         if (time < This->position)
2363             time = This->position;
2364         *pCurrent = time;
2365     }
2366     else
2367         *pCurrent = This->position;
2368     LeaveCriticalSection(&This->cs);
2369
2370     TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2371
2372     return S_OK;
2373 }
2374
2375 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface,
2376                                                      LONGLONG *pTarget,
2377                                                      const GUID *pTargetFormat,
2378                                                      LONGLONG Source,
2379                                                      const GUID *pSourceFormat) {
2380     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2381
2382     FIXME("(%p/%p)->(%p, %p, 0x%s, %p): stub !!!\n", This, iface, pTarget,
2383         pTargetFormat, wine_dbgstr_longlong(Source), pSourceFormat);
2384
2385     return S_OK;
2386 }
2387
2388 struct pos_args {
2389     LONGLONG* current, *stop;
2390     DWORD curflags, stopflags;
2391 };
2392
2393 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2394 {
2395     struct pos_args *args = (void*)pargs;
2396
2397     return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
2398 }
2399
2400 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface,
2401                                                 LONGLONG *pCurrent,
2402                                                 DWORD dwCurrentFlags,
2403                                                 LONGLONG *pStop,
2404                                                 DWORD dwStopFlags) {
2405     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2406     HRESULT hr = S_OK;
2407     FILTER_STATE state;
2408     struct pos_args args;
2409
2410     TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
2411
2412     EnterCriticalSection(&This->cs);
2413     state = This->state;
2414     TRACE("State: %s\n", state == State_Running ? "Running" : (state == State_Paused ? "Paused" : (state == State_Stopped ? "Stopped" : "UNKNOWN")));
2415
2416     if ((dwCurrentFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2417     {
2418         This->position = *pCurrent;
2419     }
2420     else if ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2421         FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
2422
2423     if ((dwStopFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2424         This->stop_position = *pStop;
2425     else if ((dwStopFlags & 0x7) != AM_SEEKING_NoPositioning)
2426         FIXME("Stop position not handled yet!\n");
2427
2428     args.current = pCurrent;
2429     args.stop = pStop;
2430     args.curflags = dwCurrentFlags;
2431     args.stopflags = dwStopFlags;
2432     hr = all_renderers_seek(This, found_setposition, (DWORD_PTR)&args);
2433
2434     if (This->refClock && ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning))
2435     {
2436         /* Update start time, prevents weird jumps */
2437         IReferenceClock_GetTime(This->refClock, &This->start_time);
2438     }
2439     LeaveCriticalSection(&This->cs);
2440
2441     return hr;
2442 }
2443
2444 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface,
2445                                                 LONGLONG *pCurrent,
2446                                                 LONGLONG *pStop) {
2447     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2448     HRESULT hr;
2449
2450     TRACE("(%p/%p)->(%p, %p)\n", This, iface, pCurrent, pStop);
2451     hr = IMediaSeeking_GetCurrentPosition(iface, pCurrent);
2452     if (SUCCEEDED(hr))
2453         hr = IMediaSeeking_GetStopPosition(iface, pStop);
2454
2455     return hr;
2456 }
2457
2458 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface,
2459                                                 LONGLONG *pEarliest,
2460                                                 LONGLONG *pLatest) {
2461     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2462
2463     FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2464
2465     return S_OK;
2466 }
2467
2468 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface,
2469                                            double dRate) {
2470     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2471
2472     FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2473
2474     return S_OK;
2475 }
2476
2477 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface,
2478                                            double *pdRate) {
2479     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2480
2481     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2482
2483     return S_OK;
2484 }
2485
2486 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface,
2487                                               LONGLONG *pllPreroll) {
2488     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2489
2490     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2491
2492     return S_OK;
2493 }
2494
2495
2496 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2497 {
2498     MediaSeeking_QueryInterface,
2499     MediaSeeking_AddRef,
2500     MediaSeeking_Release,
2501     MediaSeeking_GetCapabilities,
2502     MediaSeeking_CheckCapabilities,
2503     MediaSeeking_IsFormatSupported,
2504     MediaSeeking_QueryPreferredFormat,
2505     MediaSeeking_GetTimeFormat,
2506     MediaSeeking_IsUsingTimeFormat,
2507     MediaSeeking_SetTimeFormat,
2508     MediaSeeking_GetDuration,
2509     MediaSeeking_GetStopPosition,
2510     MediaSeeking_GetCurrentPosition,
2511     MediaSeeking_ConvertTimeFormat,
2512     MediaSeeking_SetPositions,
2513     MediaSeeking_GetPositions,
2514     MediaSeeking_GetAvailable,
2515     MediaSeeking_SetRate,
2516     MediaSeeking_GetRate,
2517     MediaSeeking_GetPreroll
2518 };
2519
2520 /*** IUnknown methods ***/
2521 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj){
2522     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaPosition_vtbl, iface);
2523
2524     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2525
2526     return Filtergraph_QueryInterface(This, riid, ppvObj);
2527 }
2528
2529 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface){
2530     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaPosition_vtbl, iface);
2531
2532     TRACE("(%p/%p)->()\n", This, iface);
2533
2534     return Filtergraph_AddRef(This);
2535 }
2536
2537 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface){
2538     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaPosition_vtbl, iface);
2539
2540     TRACE("(%p/%p)->()\n", This, iface);
2541
2542     return Filtergraph_Release(This);
2543 }
2544
2545 /*** IDispatch methods ***/
2546 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo){
2547     FIXME("(%p) stub!\n", iface);
2548     return E_NOTIMPL;
2549 }
2550
2551 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo){
2552     FIXME("(%p) stub!\n", iface);
2553     return E_NOTIMPL;
2554 }
2555
2556 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId){
2557     FIXME("(%p) stub!\n", iface);
2558     return E_NOTIMPL;
2559 }
2560
2561 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr){
2562     FIXME("(%p) stub!\n", iface);
2563     return E_NOTIMPL;
2564 }
2565
2566 /*** IMediaPosition methods ***/
2567 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength){
2568     FIXME("(%p)->(%p) stub!\n", iface, plength);
2569     return E_NOTIMPL;
2570 }
2571
2572 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime){
2573     FIXME("(%p)->(%f) stub!\n", iface, llTime);
2574     return E_NOTIMPL;
2575 }
2576
2577 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime){
2578     FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2579     return E_NOTIMPL;
2580 }
2581
2582 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime){
2583     FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2584     return E_NOTIMPL;
2585 }
2586
2587 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime){
2588     FIXME("(%p)->(%f) stub!\n", iface, llTime);
2589     return E_NOTIMPL;
2590 }
2591
2592 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime){
2593     FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2594     return E_NOTIMPL;
2595 }
2596
2597 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime){
2598     FIXME("(%p)->(%f) stub!\n", iface, llTime);
2599     return E_NOTIMPL;
2600 }
2601
2602 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate){
2603     FIXME("(%p)->(%f) stub!\n", iface, dRate);
2604     return E_NOTIMPL;
2605 }
2606
2607 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate){
2608     FIXME("(%p)->(%p) stub!\n", iface, pdRate);
2609     return E_NOTIMPL;
2610 }
2611
2612 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward){
2613     FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2614     return E_NOTIMPL;
2615 }
2616
2617 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward){
2618     FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2619     return E_NOTIMPL;
2620 }
2621
2622
2623 static const IMediaPositionVtbl IMediaPosition_VTable =
2624 {
2625     MediaPosition_QueryInterface,
2626     MediaPosition_AddRef,
2627     MediaPosition_Release,
2628     MediaPosition_GetTypeInfoCount,
2629     MediaPosition_GetTypeInfo,
2630     MediaPosition_GetIDsOfNames,
2631     MediaPosition_Invoke,
2632     MediaPosition_get_Duration,
2633     MediaPosition_put_CurrentPosition,
2634     MediaPosition_get_CurrentPosition,
2635     MediaPosition_get_StopTime,
2636     MediaPosition_put_StopTime,
2637     MediaPosition_get_PrerollTime,
2638     MediaPosition_put_PrerollTime,
2639     MediaPosition_put_Rate,
2640     MediaPosition_get_Rate,
2641     MediaPosition_CanSeekForward,
2642     MediaPosition_CanSeekBackward
2643 };
2644
2645 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2646 {
2647     HRESULT hr = E_NOINTERFACE;
2648     int i;
2649     int entry;
2650
2651     /* Check if the interface type is already registered */
2652     for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2653         if (riid == pGraph->ItfCacheEntries[entry].riid)
2654         {
2655             if (pGraph->ItfCacheEntries[entry].iface)
2656             {
2657                 /* Return the interface if available */
2658                 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2659                 return S_OK;
2660             }
2661             break;
2662         }
2663
2664     if (entry >= MAX_ITF_CACHE_ENTRIES)
2665     {
2666         FIXME("Not enough space to store interface in the cache\n");
2667         return E_OUTOFMEMORY;
2668     }
2669
2670     /* Find a filter supporting the requested interface */
2671     for (i = 0; i < pGraph->nFilters; i++)
2672     {
2673         hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2674         if (hr == S_OK)
2675         {
2676             pGraph->ItfCacheEntries[entry].riid = riid;
2677             pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2678             pGraph->ItfCacheEntries[entry].iface = (IUnknown*)*ppvObj;
2679             if (entry >= pGraph->nItfCacheEntries)
2680                 pGraph->nItfCacheEntries++;
2681             return S_OK;
2682         }
2683         if (hr != E_NOINTERFACE)
2684             return hr;
2685     }
2686
2687     return hr;
2688 }
2689
2690 /*** IUnknown methods ***/
2691 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface,
2692                                                 REFIID riid,
2693                                                 LPVOID*ppvObj) {
2694     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2695
2696     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2697
2698     return Filtergraph_QueryInterface(This, riid, ppvObj);
2699 }
2700
2701 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface) {
2702     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2703
2704     TRACE("(%p/%p)->()\n", This, iface);
2705
2706     return Filtergraph_AddRef(This);
2707 }
2708
2709 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface) {
2710     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2711
2712     TRACE("(%p/%p)->()\n", This, iface);
2713
2714     return Filtergraph_Release(This);
2715 }
2716
2717 /*** IDispatch methods ***/
2718 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface,
2719                                                   UINT*pctinfo) {
2720     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2721     IBasicAudio* pBasicAudio;
2722     HRESULT hr;
2723
2724     TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
2725
2726     EnterCriticalSection(&This->cs);
2727
2728     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2729
2730     if (hr == S_OK)
2731         hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
2732
2733     LeaveCriticalSection(&This->cs);
2734
2735     return hr;
2736 }
2737
2738 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface,
2739                                              UINT iTInfo,
2740                                              LCID lcid,
2741                                              ITypeInfo**ppTInfo) {
2742     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2743     IBasicAudio* pBasicAudio;
2744     HRESULT hr;
2745
2746     TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
2747
2748     EnterCriticalSection(&This->cs);
2749
2750     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2751
2752     if (hr == S_OK)
2753         hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
2754
2755     LeaveCriticalSection(&This->cs);
2756
2757     return hr;
2758 }
2759
2760 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface,
2761                                                REFIID riid,
2762                                                LPOLESTR*rgszNames,
2763                                                UINT cNames,
2764                                                LCID lcid,
2765                                                DISPID*rgDispId) {
2766     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2767     IBasicAudio* pBasicAudio;
2768     HRESULT hr;
2769
2770     TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
2771
2772     EnterCriticalSection(&This->cs);
2773
2774     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2775
2776     if (hr == S_OK)
2777         hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
2778
2779     LeaveCriticalSection(&This->cs);
2780
2781     return hr;
2782 }
2783
2784 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface,
2785                                         DISPID dispIdMember,
2786                                         REFIID riid,
2787                                         LCID lcid,
2788                                         WORD wFlags,
2789                                         DISPPARAMS*pDispParams,
2790                                         VARIANT*pVarResult,
2791                                         EXCEPINFO*pExepInfo,
2792                                         UINT*puArgErr) {
2793     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2794     IBasicAudio* pBasicAudio;
2795     HRESULT hr;
2796
2797     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);
2798
2799     EnterCriticalSection(&This->cs);
2800
2801     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2802
2803     if (hr == S_OK)
2804         hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
2805
2806     LeaveCriticalSection(&This->cs);
2807
2808     return hr;
2809 }
2810
2811 /*** IBasicAudio methods ***/
2812 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface,
2813                                             long lVolume) {
2814     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2815     IBasicAudio* pBasicAudio;
2816     HRESULT hr;
2817
2818     TRACE("(%p/%p)->(%ld)\n", This, iface, lVolume);
2819
2820     EnterCriticalSection(&This->cs);
2821
2822     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2823
2824     if (hr == S_OK)
2825         hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
2826
2827     LeaveCriticalSection(&This->cs);
2828
2829     return hr;
2830 }
2831
2832 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface,
2833                                             long *plVolume) {
2834     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2835     IBasicAudio* pBasicAudio;
2836     HRESULT hr;
2837
2838     TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
2839
2840     EnterCriticalSection(&This->cs);
2841
2842     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2843
2844     if (hr == S_OK)
2845         hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
2846
2847     LeaveCriticalSection(&This->cs);
2848
2849     return hr;
2850 }
2851
2852 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface,
2853                                              long lBalance) {
2854     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2855     IBasicAudio* pBasicAudio;
2856     HRESULT hr;
2857
2858     TRACE("(%p/%p)->(%ld)\n", This, iface, lBalance);
2859
2860     EnterCriticalSection(&This->cs);
2861
2862     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2863
2864     if (hr == S_OK)
2865         hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
2866
2867     LeaveCriticalSection(&This->cs);
2868
2869     return hr;
2870 }
2871
2872 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface,
2873                                              long *plBalance) {
2874     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2875     IBasicAudio* pBasicAudio;
2876     HRESULT hr;
2877
2878     TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
2879
2880     EnterCriticalSection(&This->cs);
2881
2882     hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2883
2884     if (hr == S_OK)
2885         hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
2886
2887     LeaveCriticalSection(&This->cs);
2888
2889     return hr;
2890 }
2891
2892 static const IBasicAudioVtbl IBasicAudio_VTable =
2893 {
2894     BasicAudio_QueryInterface,
2895     BasicAudio_AddRef,
2896     BasicAudio_Release,
2897     BasicAudio_GetTypeInfoCount,
2898     BasicAudio_GetTypeInfo,
2899     BasicAudio_GetIDsOfNames,
2900     BasicAudio_Invoke,
2901     BasicAudio_put_Volume,
2902     BasicAudio_get_Volume,
2903     BasicAudio_put_Balance,
2904     BasicAudio_get_Balance
2905 };
2906
2907 /*** IUnknown methods ***/
2908 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface,
2909                                                 REFIID riid,
2910                                                 LPVOID*ppvObj) {
2911     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2912
2913     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2914
2915     return Filtergraph_QueryInterface(This, riid, ppvObj);
2916 }
2917
2918 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface) {
2919     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2920
2921     TRACE("(%p/%p)->()\n", This, iface);
2922
2923     return Filtergraph_AddRef(This);
2924 }
2925
2926 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface) {
2927     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2928
2929     TRACE("(%p/%p)->()\n", This, iface);
2930
2931     return Filtergraph_Release(This);
2932 }
2933
2934 /*** IDispatch methods ***/
2935 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface,
2936                                                   UINT*pctinfo) {
2937     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2938     IBasicVideo* pBasicVideo;
2939     HRESULT hr;
2940
2941     TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
2942
2943     EnterCriticalSection(&This->cs);
2944
2945     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2946
2947     if (hr == S_OK)
2948         hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
2949
2950     LeaveCriticalSection(&This->cs);
2951
2952     return hr;
2953 }
2954
2955 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface,
2956                                              UINT iTInfo,
2957                                              LCID lcid,
2958                                              ITypeInfo**ppTInfo) {
2959     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2960     IBasicVideo* pBasicVideo;
2961     HRESULT hr;
2962
2963     TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
2964
2965     EnterCriticalSection(&This->cs);
2966
2967     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2968
2969     if (hr == S_OK)
2970         hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
2971
2972     LeaveCriticalSection(&This->cs);
2973
2974     return hr;
2975 }
2976
2977 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface,
2978                                                REFIID riid,
2979                                                LPOLESTR*rgszNames,
2980                                                UINT cNames,
2981                                                LCID lcid,
2982                                                DISPID*rgDispId) {
2983     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2984     IBasicVideo* pBasicVideo;
2985     HRESULT hr;
2986
2987     TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
2988
2989     EnterCriticalSection(&This->cs);
2990
2991     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2992
2993     if (hr == S_OK)
2994         hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
2995
2996     LeaveCriticalSection(&This->cs);
2997
2998     return hr;
2999 }
3000
3001 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface,
3002                                         DISPID dispIdMember,
3003                                         REFIID riid,
3004                                         LCID lcid,
3005                                         WORD wFlags,
3006                                         DISPPARAMS*pDispParams,
3007                                         VARIANT*pVarResult,
3008                                         EXCEPINFO*pExepInfo,
3009                                         UINT*puArgErr) {
3010     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3011     IBasicVideo* pBasicVideo;
3012     HRESULT hr;
3013
3014     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);
3015
3016     EnterCriticalSection(&This->cs);
3017
3018     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3019
3020     if (hr == S_OK)
3021         hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3022
3023     LeaveCriticalSection(&This->cs);
3024
3025     return hr;
3026 }
3027
3028 /*** IBasicVideo methods ***/
3029 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface,
3030                                                      REFTIME *pAvgTimePerFrame) {
3031     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3032     IBasicVideo* pBasicVideo;
3033     HRESULT hr;
3034
3035     TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3036
3037     EnterCriticalSection(&This->cs);
3038
3039     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3040
3041     if (hr == S_OK)
3042         hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3043
3044     LeaveCriticalSection(&This->cs);
3045
3046     return hr;
3047 }
3048
3049 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface,
3050                                              long *pBitRate) {
3051     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3052     IBasicVideo* pBasicVideo;
3053     HRESULT hr;
3054
3055     TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3056
3057     EnterCriticalSection(&This->cs);
3058
3059     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3060
3061     if (hr == S_OK)
3062         hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3063
3064     LeaveCriticalSection(&This->cs);
3065
3066     return hr;
3067 }
3068
3069 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface,
3070                                                   long *pBitErrorRate) {
3071     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3072     IBasicVideo* pBasicVideo;
3073     HRESULT hr;
3074
3075     TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3076
3077     EnterCriticalSection(&This->cs);
3078
3079     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3080
3081     if (hr == S_OK)
3082         hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3083
3084     LeaveCriticalSection(&This->cs);
3085
3086     return hr;
3087 }
3088
3089 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface,
3090                                                 long *pVideoWidth) {
3091     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3092     IBasicVideo* pBasicVideo;
3093     HRESULT hr;
3094
3095     TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3096
3097     EnterCriticalSection(&This->cs);
3098
3099     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3100
3101     if (hr == S_OK)
3102         hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3103
3104     LeaveCriticalSection(&This->cs);
3105
3106     return hr;
3107 }
3108
3109 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface,
3110                                                  long *pVideoHeight) {
3111     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3112     IBasicVideo* pBasicVideo;
3113     HRESULT hr;
3114
3115     TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3116
3117     EnterCriticalSection(&This->cs);
3118
3119     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3120
3121     if (hr == S_OK)
3122         hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3123
3124     LeaveCriticalSection(&This->cs);
3125
3126     return hr;
3127 }
3128
3129 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface,
3130                                                 long SourceLeft) {
3131     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3132     IBasicVideo* pBasicVideo;
3133     HRESULT hr;
3134
3135     TRACE("(%p/%p)->(%ld)\n", This, iface, SourceLeft);
3136
3137     EnterCriticalSection(&This->cs);
3138
3139     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3140
3141     if (hr == S_OK)
3142         hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3143
3144     LeaveCriticalSection(&This->cs);
3145
3146     return hr;
3147 }
3148
3149 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface,
3150                                                 long *pSourceLeft) {
3151     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3152     IBasicVideo* pBasicVideo;
3153     HRESULT hr;
3154
3155     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3156
3157     EnterCriticalSection(&This->cs);
3158
3159     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3160
3161     if (hr == S_OK)
3162         hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3163
3164     LeaveCriticalSection(&This->cs);
3165
3166     return hr;
3167 }
3168
3169 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface,
3170                                                  long SourceWidth) {
3171     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3172     IBasicVideo* pBasicVideo;
3173     HRESULT hr;
3174
3175     TRACE("(%p/%p)->(%ld)\n", This, iface, SourceWidth);
3176
3177     EnterCriticalSection(&This->cs);
3178
3179     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3180
3181     if (hr == S_OK)
3182         hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3183
3184     LeaveCriticalSection(&This->cs);
3185
3186     return hr;
3187 }
3188
3189 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface,
3190                                                  long *pSourceWidth) {
3191     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3192     IBasicVideo* pBasicVideo;
3193     HRESULT hr;
3194
3195     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3196
3197     EnterCriticalSection(&This->cs);
3198
3199     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3200
3201     if (hr == S_OK)
3202         hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3203
3204     LeaveCriticalSection(&This->cs);
3205
3206     return hr;
3207 }
3208
3209 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface,
3210                                                long SourceTop) {
3211     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3212     IBasicVideo* pBasicVideo;
3213     HRESULT hr;
3214
3215     TRACE("(%p/%p)->(%ld)\n", This, iface, SourceTop);
3216
3217     EnterCriticalSection(&This->cs);
3218
3219     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3220
3221     if (hr == S_OK)
3222         hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3223
3224     LeaveCriticalSection(&This->cs);
3225
3226     return hr;
3227 }
3228
3229 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface,
3230                                                long *pSourceTop) {
3231     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3232     IBasicVideo* pBasicVideo;
3233     HRESULT hr;
3234
3235     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3236
3237     EnterCriticalSection(&This->cs);
3238
3239     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3240
3241     if (hr == S_OK)
3242         hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3243
3244     LeaveCriticalSection(&This->cs);
3245
3246     return hr;
3247 }
3248
3249 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface,
3250                                                   long SourceHeight) {
3251     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3252     IBasicVideo* pBasicVideo;
3253     HRESULT hr;
3254
3255     TRACE("(%p/%p)->(%ld)\n", This, iface, SourceHeight);
3256
3257     EnterCriticalSection(&This->cs);
3258
3259     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3260
3261     if (hr == S_OK)
3262         hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3263
3264     LeaveCriticalSection(&This->cs);
3265
3266     return hr;
3267 }
3268
3269 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface,
3270                                                   long *pSourceHeight) {
3271     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3272     IBasicVideo* pBasicVideo;
3273     HRESULT hr;
3274
3275     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3276
3277     EnterCriticalSection(&This->cs);
3278
3279     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3280
3281     if (hr == S_OK)
3282         hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3283
3284     LeaveCriticalSection(&This->cs);
3285
3286     return hr;
3287 }
3288
3289 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface,
3290                                                      long DestinationLeft) {
3291     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3292     IBasicVideo* pBasicVideo;
3293     HRESULT hr;
3294
3295     TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationLeft);
3296
3297     EnterCriticalSection(&This->cs);
3298
3299     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3300
3301     if (hr == S_OK)
3302         hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3303
3304     LeaveCriticalSection(&This->cs);
3305
3306     return hr;
3307 }
3308
3309 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface,
3310                                                      long *pDestinationLeft) {
3311     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3312     IBasicVideo* pBasicVideo;
3313     HRESULT hr;
3314
3315     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3316
3317     EnterCriticalSection(&This->cs);
3318
3319     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3320
3321     if (hr == S_OK)
3322         hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3323
3324     LeaveCriticalSection(&This->cs);
3325
3326     return hr;
3327 }
3328
3329 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface,
3330                                                       long DestinationWidth) {
3331     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3332     IBasicVideo* pBasicVideo;
3333     HRESULT hr;
3334
3335     TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationWidth);
3336
3337     EnterCriticalSection(&This->cs);
3338
3339     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3340
3341     if (hr == S_OK)
3342         hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3343
3344     LeaveCriticalSection(&This->cs);
3345
3346     return hr;
3347 }
3348
3349 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface,
3350                                                       long *pDestinationWidth) {
3351     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3352     IBasicVideo* pBasicVideo;
3353     HRESULT hr;
3354
3355     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3356
3357     EnterCriticalSection(&This->cs);
3358
3359     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3360
3361     if (hr == S_OK)
3362         hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3363
3364     LeaveCriticalSection(&This->cs);
3365
3366     return hr;
3367 }
3368
3369 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface,
3370                                                     long DestinationTop) {
3371     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3372     IBasicVideo* pBasicVideo;
3373     HRESULT hr;
3374
3375     TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationTop);
3376
3377     EnterCriticalSection(&This->cs);
3378
3379     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3380
3381     if (hr == S_OK)
3382         hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3383
3384     LeaveCriticalSection(&This->cs);
3385
3386     return hr;
3387 }
3388
3389 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface,
3390                                                     long *pDestinationTop) {
3391     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3392     IBasicVideo* pBasicVideo;
3393     HRESULT hr;
3394
3395     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3396
3397     EnterCriticalSection(&This->cs);
3398
3399     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3400
3401     if (hr == S_OK)
3402         hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3403
3404     LeaveCriticalSection(&This->cs);
3405
3406     return hr;
3407 }
3408
3409 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface,
3410                                                        long DestinationHeight) {
3411     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3412     IBasicVideo* pBasicVideo;
3413     HRESULT hr;
3414
3415     TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationHeight);
3416
3417     EnterCriticalSection(&This->cs);
3418
3419     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3420
3421     if (hr == S_OK)
3422         hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3423
3424     LeaveCriticalSection(&This->cs);
3425
3426     return hr;
3427 }
3428
3429 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3430                                                        long *pDestinationHeight) {
3431     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3432     IBasicVideo* pBasicVideo;
3433     HRESULT hr;
3434
3435     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3436
3437     EnterCriticalSection(&This->cs);
3438
3439     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3440
3441     if (hr == S_OK)
3442         hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3443
3444     LeaveCriticalSection(&This->cs);
3445
3446     return hr;
3447 }
3448
3449 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface,
3450                                                    long Left,
3451                                                    long Top,
3452                                                    long Width,
3453                                                    long Height) {
3454     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3455     IBasicVideo* pBasicVideo;
3456     HRESULT hr;
3457
3458     TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
3459
3460     EnterCriticalSection(&This->cs);
3461
3462     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3463
3464     if (hr == S_OK)
3465         hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3466
3467     LeaveCriticalSection(&This->cs);
3468
3469     return hr;
3470 }
3471
3472 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface,
3473                                                    long *pLeft,
3474                                                    long *pTop,
3475                                                    long *pWidth,
3476                                                    long *pHeight) {
3477     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3478     IBasicVideo* pBasicVideo;
3479     HRESULT hr;
3480
3481     TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3482
3483     EnterCriticalSection(&This->cs);
3484
3485     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3486
3487     if (hr == S_OK)
3488         hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3489
3490     LeaveCriticalSection(&This->cs);
3491
3492     return hr;
3493 }
3494
3495 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface) {
3496     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3497     IBasicVideo* pBasicVideo;
3498     HRESULT hr;
3499
3500     TRACE("(%p/%p)->()\n", This, iface);
3501
3502     EnterCriticalSection(&This->cs);
3503
3504     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3505
3506     if (hr == S_OK)
3507         hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3508
3509     LeaveCriticalSection(&This->cs);
3510
3511     return hr;
3512 }
3513
3514 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface,
3515                                                         long Left,
3516                                                         long Top,
3517                                                         long Width,
3518                                                         long Height) {
3519     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3520     IBasicVideo* pBasicVideo;
3521     HRESULT hr;
3522
3523     TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
3524
3525     EnterCriticalSection(&This->cs);
3526
3527     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3528
3529     if (hr == S_OK)
3530         hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3531
3532     LeaveCriticalSection(&This->cs);
3533
3534     return hr;
3535 }
3536
3537 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface,
3538                                                         long *pLeft,
3539                                                         long *pTop,
3540                                                         long *pWidth,
3541                                                         long *pHeight) {
3542     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3543     IBasicVideo* pBasicVideo;
3544     HRESULT hr;
3545
3546     TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3547
3548     EnterCriticalSection(&This->cs);
3549
3550     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3551
3552     if (hr == S_OK)
3553         hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3554
3555     LeaveCriticalSection(&This->cs);
3556
3557     return hr;
3558 }
3559
3560 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface) {
3561     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3562     IBasicVideo* pBasicVideo;
3563     HRESULT hr;
3564
3565     TRACE("(%p/%p)->()\n", This, iface);
3566
3567     EnterCriticalSection(&This->cs);
3568
3569     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3570
3571     if (hr == S_OK)
3572         hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3573
3574     LeaveCriticalSection(&This->cs);
3575
3576     return hr;
3577 }
3578
3579 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface,
3580                                               long *pWidth,
3581                                               long *pHeight) {
3582     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3583     IBasicVideo* pBasicVideo;
3584     HRESULT hr;
3585
3586     TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3587
3588     EnterCriticalSection(&This->cs);
3589
3590     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3591
3592     if (hr == S_OK)
3593         hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3594
3595     LeaveCriticalSection(&This->cs);
3596
3597     return hr;
3598 }
3599
3600 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface,
3601                                                         long StartIndex,
3602                                                         long Entries,
3603                                                         long *pRetrieved,
3604                                                         long *pPalette) {
3605     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3606     IBasicVideo* pBasicVideo;
3607     HRESULT hr;
3608
3609     TRACE("(%p/%p)->(%ld, %ld, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3610
3611     EnterCriticalSection(&This->cs);
3612
3613     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3614
3615     if (hr == S_OK)
3616         hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3617
3618     LeaveCriticalSection(&This->cs);
3619
3620     return hr;
3621 }
3622
3623 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface,
3624                                                  long *pBufferSize,
3625                                                  long *pDIBImage) {
3626     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3627     IBasicVideo* pBasicVideo;
3628     HRESULT hr;
3629
3630     TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3631
3632     EnterCriticalSection(&This->cs);
3633
3634     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3635
3636     if (hr == S_OK)
3637         hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3638
3639     LeaveCriticalSection(&This->cs);
3640
3641     return hr;
3642 }
3643
3644 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface) {
3645     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3646     IBasicVideo* pBasicVideo;
3647     HRESULT hr;
3648
3649     TRACE("(%p/%p)->()\n", This, iface);
3650
3651     EnterCriticalSection(&This->cs);
3652
3653     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3654
3655     if (hr == S_OK)
3656         hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3657
3658     LeaveCriticalSection(&This->cs);
3659
3660     return hr;
3661 }
3662
3663 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface) {
3664     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3665     IBasicVideo* pBasicVideo;
3666     HRESULT hr;
3667
3668     TRACE("(%p/%p)->()\n", This, iface);
3669
3670     EnterCriticalSection(&This->cs);
3671
3672     hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3673
3674     if (hr == S_OK)
3675         hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3676
3677     LeaveCriticalSection(&This->cs);
3678
3679     return hr;
3680 }
3681
3682 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX, LONG *plAspectY) {
3683     ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3684     IBasicVideo2 *pBasicVideo2;
3685     HRESULT hr;
3686
3687     TRACE("(%p/%p)->()\n", This, iface);
3688
3689     EnterCriticalSection(&This->cs);
3690
3691     hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3692
3693     if (hr == S_OK)
3694         hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3695
3696     LeaveCriticalSection(&This->cs);
3697
3698     return hr;
3699 }
3700
3701 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3702 {
3703     BasicVideo_QueryInterface,
3704     BasicVideo_AddRef,
3705     BasicVideo_Release,
3706     BasicVideo_GetTypeInfoCount,
3707     BasicVideo_GetTypeInfo,
3708     BasicVideo_GetIDsOfNames,
3709     BasicVideo_Invoke,
3710     BasicVideo_get_AvgTimePerFrame,
3711     BasicVideo_get_BitRate,
3712     BasicVideo_get_BitErrorRate,
3713     BasicVideo_get_VideoWidth,
3714     BasicVideo_get_VideoHeight,
3715     BasicVideo_put_SourceLeft,
3716     BasicVideo_get_SourceLeft,
3717     BasicVideo_put_SourceWidth,
3718     BasicVideo_get_SourceWidth,
3719     BasicVideo_put_SourceTop,
3720     BasicVideo_get_SourceTop,
3721     BasicVideo_put_SourceHeight,
3722     BasicVideo_get_SourceHeight,
3723     BasicVideo_put_DestinationLeft,
3724     BasicVideo_get_DestinationLeft,
3725     BasicVideo_put_DestinationWidth,
3726     BasicVideo_get_DestinationWidth,
3727     BasicVideo_put_DestinationTop,
3728     BasicVideo_get_DestinationTop,
3729     BasicVideo_put_DestinationHeight,
3730     BasicVideo_get_DestinationHeight,
3731     BasicVideo_SetSourcePosition,
3732     BasicVideo_GetSourcePosition,
3733     BasicVideo_SetDefaultSourcePosition,
3734     BasicVideo_SetDestinationPosition,
3735     BasicVideo_GetDestinationPosition,
3736     BasicVideo_SetDefaultDestinationPosition,
3737     BasicVideo_GetVideoSize,
3738     BasicVideo_GetVideoPaletteEntries,
3739     BasicVideo_GetCurrentImage,
3740     BasicVideo_IsUsingDefaultSource,
3741     BasicVideo_IsUsingDefaultDestination,
3742     BasicVideo2_GetPreferredAspectRatio
3743 };
3744
3745
3746 /*** IUnknown methods ***/
3747 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface,
3748                                                  REFIID riid,
3749                                                  LPVOID*ppvObj) {
3750     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3751
3752     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3753
3754     return Filtergraph_QueryInterface(This, riid, ppvObj);
3755 }
3756
3757 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface) {
3758     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3759
3760     TRACE("(%p/%p)->()\n", This, iface);
3761
3762     return Filtergraph_AddRef(This);
3763 }
3764
3765 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface) {
3766     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3767
3768     TRACE("(%p/%p)->()\n", This, iface);
3769
3770     return Filtergraph_Release(This);
3771 }
3772
3773 /*** IDispatch methods ***/
3774 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface,
3775                                                    UINT*pctinfo) {
3776     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3777     IVideoWindow* pVideoWindow;
3778     HRESULT hr;
3779
3780     TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3781
3782     EnterCriticalSection(&This->cs);
3783
3784     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3785
3786     if (hr == S_OK)
3787         hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
3788
3789     LeaveCriticalSection(&This->cs);
3790
3791     return hr;
3792 }
3793
3794 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface,
3795                                               UINT iTInfo,
3796                                               LCID lcid,
3797                                               ITypeInfo**ppTInfo) {
3798     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3799     IVideoWindow* pVideoWindow;
3800     HRESULT hr;
3801
3802     TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3803
3804     EnterCriticalSection(&This->cs);
3805
3806     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3807
3808     if (hr == S_OK)
3809         hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
3810
3811     LeaveCriticalSection(&This->cs);
3812
3813     return hr;
3814 }
3815
3816 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface,
3817                                                 REFIID riid,
3818                                                 LPOLESTR*rgszNames,
3819                                                 UINT cNames,
3820                                                 LCID lcid,
3821                                                 DISPID*rgDispId) {
3822     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3823     IVideoWindow* pVideoWindow;
3824     HRESULT hr;
3825
3826     TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3827
3828     EnterCriticalSection(&This->cs);
3829
3830     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3831
3832     if (hr == S_OK)
3833         hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
3834
3835     LeaveCriticalSection(&This->cs);
3836
3837     return hr;
3838 }
3839
3840 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface,
3841                                          DISPID dispIdMember,
3842                                          REFIID riid,
3843                                          LCID lcid,
3844                                          WORD wFlags,
3845                                          DISPPARAMS*pDispParams,
3846                                          VARIANT*pVarResult,
3847                                          EXCEPINFO*pExepInfo,
3848                                          UINT*puArgErr) {
3849     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3850     IVideoWindow* pVideoWindow;
3851     HRESULT hr;
3852
3853     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);
3854
3855     EnterCriticalSection(&This->cs);
3856
3857     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3858
3859     if (hr == S_OK)
3860         hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3861
3862     LeaveCriticalSection(&This->cs);
3863
3864     return hr;
3865 }
3866
3867
3868 /*** IVideoWindow methods ***/
3869 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface,
3870                                               BSTR strCaption) {
3871     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3872     IVideoWindow* pVideoWindow;
3873     HRESULT hr;
3874     
3875     TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
3876
3877     EnterCriticalSection(&This->cs);
3878
3879     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3880
3881     if (hr == S_OK)
3882         hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
3883
3884     LeaveCriticalSection(&This->cs);
3885
3886     return hr;
3887 }
3888
3889 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface,
3890                                               BSTR *strCaption) {
3891     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3892     IVideoWindow* pVideoWindow;
3893     HRESULT hr;
3894
3895     TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
3896
3897     EnterCriticalSection(&This->cs);
3898
3899     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3900
3901     if (hr == S_OK)
3902         hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
3903
3904     LeaveCriticalSection(&This->cs);
3905
3906     return hr;
3907 }
3908
3909 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface,
3910                                                   long WindowStyle) {
3911     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3912     IVideoWindow* pVideoWindow;
3913     HRESULT hr;
3914
3915     TRACE("(%p/%p)->(%ld)\n", This, iface, WindowStyle);
3916
3917     EnterCriticalSection(&This->cs);
3918
3919     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3920
3921     if (hr == S_OK)
3922         hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
3923
3924     LeaveCriticalSection(&This->cs);
3925
3926     return hr;
3927 }
3928
3929 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface,
3930                                                   long *WindowStyle) {
3931     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3932     IVideoWindow* pVideoWindow;
3933     HRESULT hr;
3934
3935     TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
3936
3937     EnterCriticalSection(&This->cs);
3938
3939     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3940
3941     if (hr == S_OK)
3942         hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
3943
3944     LeaveCriticalSection(&This->cs);
3945
3946     return hr;
3947 }
3948
3949 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface,
3950                                                     long WindowStyleEx) {
3951     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3952     IVideoWindow* pVideoWindow;
3953     HRESULT hr;
3954
3955     TRACE("(%p/%p)->(%ld)\n", This, iface, WindowStyleEx);
3956
3957     EnterCriticalSection(&This->cs);
3958
3959     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3960
3961     if (hr == S_OK)
3962         hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
3963
3964     LeaveCriticalSection(&This->cs);
3965
3966     return hr;
3967 }
3968
3969 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface,
3970                                                     long *WindowStyleEx) {
3971     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3972     IVideoWindow* pVideoWindow;
3973     HRESULT hr;
3974
3975     TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
3976
3977     EnterCriticalSection(&This->cs);
3978
3979     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3980
3981     if (hr == S_OK)
3982         hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
3983
3984     LeaveCriticalSection(&This->cs);
3985
3986     return hr;
3987 }
3988
3989 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface,
3990                                                long AutoShow) {
3991     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3992     IVideoWindow* pVideoWindow;
3993     HRESULT hr;
3994
3995     TRACE("(%p/%p)->(%ld)\n", This, iface, AutoShow);
3996
3997     EnterCriticalSection(&This->cs);
3998
3999     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4000
4001     if (hr == S_OK)
4002         hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4003
4004     LeaveCriticalSection(&This->cs);
4005
4006     return hr;
4007 }
4008
4009 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface,
4010                                                long *AutoShow) {
4011     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4012     IVideoWindow* pVideoWindow;
4013     HRESULT hr;
4014
4015     TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4016
4017     EnterCriticalSection(&This->cs);
4018
4019     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4020
4021     if (hr == S_OK)
4022         hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4023
4024     LeaveCriticalSection(&This->cs);
4025
4026     return hr;
4027 }
4028
4029 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface,
4030                                                   long WindowState) {
4031     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4032     IVideoWindow* pVideoWindow;
4033     HRESULT hr;
4034
4035     TRACE("(%p/%p)->(%ld)\n", This, iface, WindowState);
4036
4037     EnterCriticalSection(&This->cs);
4038
4039     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4040
4041     if (hr == S_OK)
4042         hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4043
4044     LeaveCriticalSection(&This->cs);
4045
4046     return hr;
4047 }
4048
4049 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface,
4050                                                   long *WindowState) {
4051     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4052     IVideoWindow* pVideoWindow;
4053     HRESULT hr;
4054
4055     TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4056
4057     EnterCriticalSection(&This->cs);
4058
4059     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4060
4061     if (hr == S_OK)
4062         hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4063
4064     LeaveCriticalSection(&This->cs);
4065
4066     return hr;
4067 }
4068
4069 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface,
4070                                                         long BackgroundPalette) {
4071     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4072     IVideoWindow* pVideoWindow;
4073     HRESULT hr;
4074
4075     TRACE("(%p/%p)->(%ld)\n", This, iface, BackgroundPalette);
4076
4077     EnterCriticalSection(&This->cs);
4078
4079     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4080
4081     if (hr == S_OK)
4082         hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4083
4084     LeaveCriticalSection(&This->cs);
4085
4086     return hr;
4087 }
4088
4089 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4090                                                         long *pBackgroundPalette) {
4091     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4092     IVideoWindow* pVideoWindow;
4093     HRESULT hr;
4094
4095     TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4096
4097     EnterCriticalSection(&This->cs);
4098
4099     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4100
4101     if (hr == S_OK)
4102         hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4103
4104     LeaveCriticalSection(&This->cs);
4105
4106     return hr;
4107 }
4108
4109 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface,
4110                                               long Visible) {
4111     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4112     IVideoWindow* pVideoWindow;
4113     HRESULT hr;
4114
4115     TRACE("(%p/%p)->(%ld)\n", This, iface, Visible);
4116
4117     EnterCriticalSection(&This->cs);
4118
4119     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4120
4121     if (hr == S_OK)
4122         hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4123
4124     LeaveCriticalSection(&This->cs);
4125
4126     return hr;
4127 }
4128
4129 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface,
4130                                               long *pVisible) {
4131     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4132     IVideoWindow* pVideoWindow;
4133     HRESULT hr;
4134
4135     TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4136
4137     EnterCriticalSection(&This->cs);
4138
4139     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4140
4141     if (hr == S_OK)
4142         hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4143
4144     LeaveCriticalSection(&This->cs);
4145
4146     return hr;
4147 }
4148
4149 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface,
4150                                            long Left) {
4151     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4152     IVideoWindow* pVideoWindow;
4153     HRESULT hr;
4154
4155     TRACE("(%p/%p)->(%ld)\n", This, iface, Left);
4156
4157     EnterCriticalSection(&This->cs);
4158
4159     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4160
4161     if (hr == S_OK)
4162         hr = IVideoWindow_put_Left(pVideoWindow, Left);
4163
4164     LeaveCriticalSection(&This->cs);
4165
4166     return hr;
4167 }
4168
4169 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface,
4170                                            long *pLeft) {
4171     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4172     IVideoWindow* pVideoWindow;
4173     HRESULT hr;
4174
4175     TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4176
4177     EnterCriticalSection(&This->cs);
4178
4179     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4180
4181     if (hr == S_OK)
4182         hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4183
4184     LeaveCriticalSection(&This->cs);
4185
4186     return hr;
4187 }
4188
4189 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface,
4190                                             long Width) {
4191     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4192     IVideoWindow* pVideoWindow;
4193     HRESULT hr;
4194
4195     TRACE("(%p/%p)->(%ld)\n", This, iface, Width);
4196
4197     EnterCriticalSection(&This->cs);
4198
4199     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4200
4201     if (hr == S_OK)
4202         hr = IVideoWindow_put_Width(pVideoWindow, Width);
4203
4204     LeaveCriticalSection(&This->cs);
4205
4206     return hr;
4207 }
4208
4209 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface,
4210                                             long *pWidth) {
4211     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4212     IVideoWindow* pVideoWindow;
4213     HRESULT hr;
4214
4215     TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4216
4217     EnterCriticalSection(&This->cs);
4218
4219     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4220
4221     if (hr == S_OK)
4222         hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4223
4224     LeaveCriticalSection(&This->cs);
4225
4226     return hr;
4227 }
4228
4229 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface,
4230                                           long Top) {
4231     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4232     IVideoWindow* pVideoWindow;
4233     HRESULT hr;
4234
4235     TRACE("(%p/%p)->(%ld)\n", This, iface, Top);
4236
4237     EnterCriticalSection(&This->cs);
4238
4239     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4240
4241     if (hr == S_OK)
4242         hr = IVideoWindow_put_Top(pVideoWindow, Top);
4243
4244     LeaveCriticalSection(&This->cs);
4245
4246     return hr;
4247 }
4248
4249 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface,
4250                                           long *pTop) {
4251     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4252     IVideoWindow* pVideoWindow;
4253     HRESULT hr;
4254
4255     TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4256
4257     EnterCriticalSection(&This->cs);
4258
4259     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4260
4261     if (hr == S_OK)
4262         hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4263
4264     LeaveCriticalSection(&This->cs);
4265
4266     return hr;
4267 }
4268
4269 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface,
4270                                              long Height) {
4271     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4272     IVideoWindow* pVideoWindow;
4273     HRESULT hr;
4274
4275     TRACE("(%p/%p)->(%ld)\n", This, iface, Height);
4276
4277     EnterCriticalSection(&This->cs);
4278
4279     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4280
4281     if (hr == S_OK)
4282         hr = IVideoWindow_put_Height(pVideoWindow, Height);
4283
4284     LeaveCriticalSection(&This->cs);
4285
4286     return hr;
4287 }
4288
4289 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface,
4290                                              long *pHeight) {
4291     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4292     IVideoWindow* pVideoWindow;
4293     HRESULT hr;
4294
4295     TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4296
4297     EnterCriticalSection(&This->cs);
4298
4299     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4300
4301     if (hr == S_OK)
4302         hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4303
4304     LeaveCriticalSection(&This->cs);
4305
4306     return hr;
4307 }
4308
4309 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface,
4310                                             OAHWND Owner) {
4311     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4312     IVideoWindow* pVideoWindow;
4313     HRESULT hr;
4314
4315     TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4316
4317     EnterCriticalSection(&This->cs);
4318
4319     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4320
4321     if (hr == S_OK)
4322         hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4323
4324     LeaveCriticalSection(&This->cs);
4325
4326     return hr;
4327 }
4328
4329 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface,
4330                                             OAHWND *Owner) {
4331     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4332     IVideoWindow* pVideoWindow;
4333     HRESULT hr;
4334
4335     TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4336
4337     EnterCriticalSection(&This->cs);
4338
4339     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4340
4341     if (hr == S_OK)
4342         hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4343
4344     LeaveCriticalSection(&This->cs);
4345
4346     return hr;
4347 }
4348
4349 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface,
4350                                                    OAHWND Drain) {
4351     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4352     IVideoWindow* pVideoWindow;
4353     HRESULT hr;
4354
4355     TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4356
4357     EnterCriticalSection(&This->cs);
4358
4359     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4360
4361     if (hr == S_OK)
4362         hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4363
4364     LeaveCriticalSection(&This->cs);
4365
4366     return hr;
4367 }
4368
4369 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface,
4370                                                    OAHWND *Drain) {
4371     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4372     IVideoWindow* pVideoWindow;
4373     HRESULT hr;
4374
4375     TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4376
4377     EnterCriticalSection(&This->cs);
4378
4379     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4380
4381     if (hr == S_OK)
4382         hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4383
4384     LeaveCriticalSection(&This->cs);
4385
4386     return hr;
4387 }
4388
4389 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface,
4390                                                   long *Color) {
4391     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4392     IVideoWindow* pVideoWindow;
4393     HRESULT hr;
4394
4395     TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4396
4397     EnterCriticalSection(&This->cs);
4398
4399     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4400
4401     if (hr == S_OK)
4402         hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4403
4404     LeaveCriticalSection(&This->cs);
4405
4406     return hr;
4407 }
4408
4409 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface,
4410                                                   long Color) {
4411     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4412     IVideoWindow* pVideoWindow;
4413     HRESULT hr;
4414
4415     TRACE("(%p/%p)->(%ld)\n", This, iface, Color);
4416
4417     EnterCriticalSection(&This->cs);
4418
4419     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4420
4421     if (hr == S_OK)
4422         hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4423
4424     LeaveCriticalSection(&This->cs);
4425
4426     return hr;
4427 }
4428
4429 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface,
4430                                                      long *FullScreenMode) {
4431     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4432     IVideoWindow* pVideoWindow;
4433     HRESULT hr;
4434
4435     TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4436
4437     EnterCriticalSection(&This->cs);
4438
4439     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4440
4441     if (hr == S_OK)
4442         hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4443
4444     LeaveCriticalSection(&This->cs);
4445
4446     return hr;
4447 }
4448
4449 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface,
4450                                                      long FullScreenMode) {
4451     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4452     IVideoWindow* pVideoWindow;
4453     HRESULT hr;
4454
4455     TRACE("(%p/%p)->(%ld)\n", This, iface, FullScreenMode);
4456
4457     EnterCriticalSection(&This->cs);
4458
4459     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4460
4461     if (hr == S_OK)
4462         hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4463
4464     LeaveCriticalSection(&This->cs);
4465
4466     return hr;
4467 }
4468
4469 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface,
4470                                                       long Focus) {
4471     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4472     IVideoWindow* pVideoWindow;
4473     HRESULT hr;
4474
4475     TRACE("(%p/%p)->(%ld)\n", This, iface, Focus);
4476
4477     EnterCriticalSection(&This->cs);
4478
4479     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4480
4481     if (hr == S_OK)
4482         hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4483
4484     LeaveCriticalSection(&This->cs);
4485
4486     return hr;
4487 }
4488
4489 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface,
4490                                                      OAHWND hwnd,
4491                                                      long uMsg,
4492                                                      LONG_PTR wParam,
4493                                                      LONG_PTR lParam) {
4494     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4495     IVideoWindow* pVideoWindow;
4496     HRESULT hr;
4497
4498     TRACE("(%p/%p)->(%08x, %ld, %08lx, %08lx)\n", This, iface, (DWORD) hwnd, uMsg, wParam, lParam);
4499
4500     EnterCriticalSection(&This->cs);
4501
4502     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4503
4504     if (hr == S_OK)
4505         hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4506
4507     LeaveCriticalSection(&This->cs);
4508
4509     return hr;
4510 }
4511
4512 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface,
4513                                                     long Left,
4514                                                     long Top,
4515                                                     long Width,
4516                                                     long Height) {
4517     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4518     IVideoWindow* pVideoWindow;
4519     HRESULT hr;
4520     
4521     TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
4522
4523     EnterCriticalSection(&This->cs);
4524
4525     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4526
4527     if (hr == S_OK)
4528         hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4529
4530     LeaveCriticalSection(&This->cs);
4531
4532     return hr;
4533 }
4534
4535 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface,
4536                                                     long *pLeft,
4537                                                     long *pTop,
4538                                                     long *pWidth,
4539                                                     long *pHeight) {
4540     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4541     IVideoWindow* pVideoWindow;
4542     HRESULT hr;
4543
4544     TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4545
4546     EnterCriticalSection(&This->cs);
4547
4548     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4549
4550     if (hr == S_OK)
4551         hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4552
4553     LeaveCriticalSection(&This->cs);
4554
4555     return hr;
4556 }
4557
4558 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface,
4559                                                        long *pWidth,
4560                                                        long *pHeight) {
4561     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4562     IVideoWindow* pVideoWindow;
4563     HRESULT hr;
4564
4565     TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4566
4567     EnterCriticalSection(&This->cs);
4568
4569     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4570
4571     if (hr == S_OK)
4572         hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4573
4574     LeaveCriticalSection(&This->cs);
4575
4576     return hr;
4577 }
4578
4579 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface,
4580                                                        long *pWidth,
4581                                                        long *pHeight) {
4582     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4583     IVideoWindow* pVideoWindow;
4584     HRESULT hr;
4585
4586     TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4587
4588     EnterCriticalSection(&This->cs);
4589
4590     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4591
4592     if (hr == S_OK)
4593         hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4594
4595     LeaveCriticalSection(&This->cs);
4596
4597     return hr;
4598 }
4599
4600 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface,
4601                                                      long *pLeft,
4602                                                      long *pTop,
4603                                                      long *pWidth,
4604                                                      long *pHeight) {
4605     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4606     IVideoWindow* pVideoWindow;
4607     HRESULT hr;
4608
4609     TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4610
4611     EnterCriticalSection(&This->cs);
4612
4613     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4614
4615     if (hr == S_OK)
4616         hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4617
4618     LeaveCriticalSection(&This->cs);
4619
4620     return hr;
4621 }
4622
4623 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface,
4624                                              long HideCursor) {
4625     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4626     IVideoWindow* pVideoWindow;
4627     HRESULT hr;
4628
4629     TRACE("(%p/%p)->(%ld)\n", This, iface, HideCursor);
4630
4631     EnterCriticalSection(&This->cs);
4632
4633     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4634
4635     if (hr == S_OK)
4636         hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4637
4638     LeaveCriticalSection(&This->cs);
4639
4640     return hr;
4641 }
4642
4643 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface,
4644                                                  long *CursorHidden) {
4645     ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4646     IVideoWindow* pVideoWindow;
4647     HRESULT hr;
4648
4649     TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4650
4651     EnterCriticalSection(&This->cs);
4652
4653     hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4654
4655     if (hr == S_OK)
4656         hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4657
4658     LeaveCriticalSection(&This->cs);
4659
4660     return hr;
4661 }
4662
4663
4664 static const IVideoWindowVtbl IVideoWindow_VTable =
4665 {
4666     VideoWindow_QueryInterface,
4667     VideoWindow_AddRef,
4668     VideoWindow_Release,
4669     VideoWindow_GetTypeInfoCount,
4670     VideoWindow_GetTypeInfo,
4671     VideoWindow_GetIDsOfNames,
4672     VideoWindow_Invoke,
4673     VideoWindow_put_Caption,
4674     VideoWindow_get_Caption,
4675     VideoWindow_put_WindowStyle,
4676     VideoWindow_get_WindowStyle,
4677     VideoWindow_put_WindowStyleEx,
4678     VideoWindow_get_WindowStyleEx,
4679     VideoWindow_put_AutoShow,
4680     VideoWindow_get_AutoShow,
4681     VideoWindow_put_WindowState,
4682     VideoWindow_get_WindowState,
4683     VideoWindow_put_BackgroundPalette,
4684     VideoWindow_get_BackgroundPalette,
4685     VideoWindow_put_Visible,
4686     VideoWindow_get_Visible,
4687     VideoWindow_put_Left,
4688     VideoWindow_get_Left,
4689     VideoWindow_put_Width,
4690     VideoWindow_get_Width,
4691     VideoWindow_put_Top,
4692     VideoWindow_get_Top,
4693     VideoWindow_put_Height,
4694     VideoWindow_get_Height,
4695     VideoWindow_put_Owner,
4696     VideoWindow_get_Owner,
4697     VideoWindow_put_MessageDrain,
4698     VideoWindow_get_MessageDrain,
4699     VideoWindow_get_BorderColor,
4700     VideoWindow_put_BorderColor,
4701     VideoWindow_get_FullScreenMode,
4702     VideoWindow_put_FullScreenMode,
4703     VideoWindow_SetWindowForeground,
4704     VideoWindow_NotifyOwnerMessage,
4705     VideoWindow_SetWindowPosition,
4706     VideoWindow_GetWindowPosition,
4707     VideoWindow_GetMinIdealImageSize,
4708     VideoWindow_GetMaxIdealImageSize,
4709     VideoWindow_GetRestorePosition,
4710     VideoWindow_HideCursor,
4711     VideoWindow_IsCursorHidden
4712 };
4713
4714
4715 /*** IUnknown methods ***/
4716 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface,
4717                                                 REFIID riid,
4718                                                 LPVOID*ppvObj) {
4719     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4720
4721     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
4722
4723     return Filtergraph_QueryInterface(This, riid, ppvObj);
4724 }
4725
4726 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface) {
4727     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4728
4729     TRACE("(%p/%p)->()\n", This, iface);
4730
4731     return Filtergraph_AddRef(This);
4732 }
4733
4734 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface) {
4735     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4736
4737     TRACE("(%p/%p)->()\n", This, iface);
4738
4739     return Filtergraph_Release(This);
4740 }
4741
4742 /*** IDispatch methods ***/
4743 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface,
4744                                                   UINT*pctinfo) {
4745     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4746
4747     TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
4748
4749     return S_OK;
4750 }
4751
4752 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface,
4753                                              UINT iTInfo,
4754                                              LCID lcid,
4755                                              ITypeInfo**ppTInfo) {
4756     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4757
4758     TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
4759
4760     return S_OK;
4761 }
4762
4763 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface,
4764                                                REFIID riid,
4765                                                LPOLESTR*rgszNames,
4766                                                UINT cNames,
4767                                                LCID lcid,
4768                                                DISPID*rgDispId) {
4769     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4770
4771     TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
4772
4773     return S_OK;
4774 }
4775
4776 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface,
4777                                         DISPID dispIdMember,
4778                                         REFIID riid,
4779                                         LCID lcid,
4780                                         WORD wFlags,
4781                                         DISPPARAMS*pDispParams,
4782                                         VARIANT*pVarResult,
4783                                         EXCEPINFO*pExepInfo,
4784                                         UINT*puArgErr) {
4785     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4786
4787     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);
4788
4789     return S_OK;
4790 }
4791
4792 /*** IMediaEvent methods ***/
4793 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface,
4794                                                 OAEVENT *hEvent) {
4795     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4796
4797     TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
4798
4799     *hEvent = (OAEVENT)This->evqueue.msg_event;
4800
4801     return S_OK;
4802 }
4803
4804 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface,
4805                                           long *lEventCode,
4806                                           LONG_PTR *lParam1,
4807                                           LONG_PTR *lParam2,
4808                                           long msTimeout) {
4809     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4810     Event evt;
4811
4812     TRACE("(%p/%p)->(%p, %p, %p, %ld)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
4813
4814     if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
4815     {
4816         *lEventCode = evt.lEventCode;
4817         *lParam1 = evt.lParam1;
4818         *lParam2 = evt.lParam2;
4819         return S_OK;
4820     }
4821
4822     *lEventCode = 0;
4823     return E_ABORT;
4824 }
4825
4826 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface,
4827                                                    long msTimeout,
4828                                                    long *pEvCode) {
4829     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4830
4831     TRACE("(%p/%p)->(%ld, %p)\n", This, iface, msTimeout, pEvCode);
4832
4833     if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
4834     {
4835         *pEvCode = This->CompletionStatus;
4836         return S_OK;
4837     }
4838
4839     *pEvCode = 0;
4840     return E_ABORT;
4841 }
4842
4843 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface,
4844                                                        long lEvCode) {
4845     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4846
4847     TRACE("(%p/%p)->(%ld)\n", This, iface, lEvCode);
4848
4849     if (lEvCode == EC_COMPLETE)
4850         This->HandleEcComplete = FALSE;
4851     else if (lEvCode == EC_REPAINT)
4852         This->HandleEcRepaint = FALSE;
4853     else if (lEvCode == EC_CLOCK_CHANGED)
4854         This->HandleEcClockChanged = FALSE;
4855     else
4856         return S_FALSE;
4857
4858     return S_OK;
4859 }
4860
4861 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface,
4862                                                         long lEvCode) {
4863     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4864
4865     TRACE("(%p/%p)->(%ld)\n", This, iface, lEvCode);
4866
4867     if (lEvCode == EC_COMPLETE)
4868         This->HandleEcComplete = TRUE;
4869     else if (lEvCode == EC_REPAINT)
4870         This->HandleEcRepaint = TRUE;
4871     else if (lEvCode == EC_CLOCK_CHANGED)
4872         This->HandleEcClockChanged = TRUE;
4873     else
4874         return S_FALSE;
4875
4876     return S_OK;
4877 }
4878
4879 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface,
4880                                                  long lEvCode,
4881                                                  LONG_PTR lParam1,
4882                                                  LONG_PTR lParam2) {
4883     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4884
4885     TRACE("(%p/%p)->(%ld, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
4886
4887     return S_OK;
4888 }
4889
4890 /*** IMediaEventEx methods ***/
4891 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface,
4892                                                  OAHWND hwnd,
4893                                                  long lMsg,
4894                                                  LONG_PTR lInstanceData) {
4895     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4896
4897     TRACE("(%p/%p)->(%08x, %ld, %08lx)\n", This, iface, (DWORD) hwnd, lMsg, lInstanceData);
4898
4899     This->notif.hWnd = (HWND)hwnd;
4900     This->notif.msg = lMsg;
4901     This->notif.instance = (long) lInstanceData;
4902
4903     return S_OK;
4904 }
4905
4906 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface,
4907                                                 long lNoNotifyFlags) {
4908     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4909
4910     TRACE("(%p/%p)->(%ld)\n", This, iface, lNoNotifyFlags);
4911
4912     if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
4913         return E_INVALIDARG;
4914
4915     This->notif.disabled = lNoNotifyFlags;
4916
4917     return S_OK;
4918 }
4919
4920 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface,
4921                                                 long *lplNoNotifyFlags) {
4922     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4923
4924     TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
4925
4926     if (!lplNoNotifyFlags)
4927         return E_POINTER;
4928
4929     *lplNoNotifyFlags = This->notif.disabled;
4930
4931     return S_OK;
4932 }
4933
4934
4935 static const IMediaEventExVtbl IMediaEventEx_VTable =
4936 {
4937     MediaEvent_QueryInterface,
4938     MediaEvent_AddRef,
4939     MediaEvent_Release,
4940     MediaEvent_GetTypeInfoCount,
4941     MediaEvent_GetTypeInfo,
4942     MediaEvent_GetIDsOfNames,
4943     MediaEvent_Invoke,
4944     MediaEvent_GetEventHandle,
4945     MediaEvent_GetEvent,
4946     MediaEvent_WaitForCompletion,
4947     MediaEvent_CancelDefaultHandling,
4948     MediaEvent_RestoreDefaultHandling,
4949     MediaEvent_FreeEventParams,
4950     MediaEvent_SetNotifyWindow,
4951     MediaEvent_SetNotifyFlags,
4952     MediaEvent_GetNotifyFlags
4953 };
4954
4955
4956 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, LPVOID *ppv)
4957 {
4958     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
4959
4960     return Filtergraph_QueryInterface(This, riid, ppv);
4961 }
4962
4963 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
4964 {
4965     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
4966
4967     return Filtergraph_AddRef(This);
4968 }
4969
4970 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
4971 {
4972     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
4973
4974     return Filtergraph_Release(This);
4975 }
4976
4977 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
4978 {
4979     FIXME("(%p): stub\n", pClassID);
4980
4981     return E_NOTIMPL;
4982 }
4983
4984 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
4985 {
4986     FIXME("(): stub\n");
4987
4988     return E_NOTIMPL;
4989 }
4990
4991 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
4992 {
4993     FIXME("(): stub\n");
4994
4995     return E_NOTIMPL;
4996 }
4997
4998 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
4999 {
5000     FIXME("(0x%s): stub\n", wine_dbgstr_longlong(tStart));
5001
5002     return E_NOTIMPL;
5003 }
5004
5005 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout, FILTER_STATE * pState)
5006 {
5007     FIXME("(%d, %p): stub\n", dwMsTimeout, pState);
5008
5009     return E_NOTIMPL;
5010 }
5011
5012 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5013 {
5014     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5015     HRESULT hr = S_OK;
5016     int i;
5017
5018     TRACE("(%p/%p)->(%p)\n", iface, This, pClock);
5019
5020     EnterCriticalSection(&This->cs);
5021     {
5022         for (i = 0;i < This->nFilters;i++)
5023         {
5024             hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5025             if (FAILED(hr))
5026                 break;
5027         }
5028
5029         if (FAILED(hr))
5030         {
5031             for(;i >= 0;i--)
5032                 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5033         }
5034         else
5035         {
5036             if (This->refClock)
5037                 IReferenceClock_Release(This->refClock);
5038             This->refClock = pClock;
5039             if (This->refClock)
5040                 IReferenceClock_AddRef(This->refClock);
5041
5042             if (This->HandleEcClockChanged)
5043             {
5044                 IMediaEventSink *pEventSink;
5045                 HRESULT eshr;
5046
5047                 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (LPVOID)&pEventSink);
5048                 if (SUCCEEDED(eshr))
5049                 {
5050                     IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5051                     IMediaEventSink_Release(pEventSink);
5052                 }
5053             }
5054         }
5055     }
5056     LeaveCriticalSection(&This->cs);
5057
5058     return hr;
5059 }
5060
5061 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5062 {
5063     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5064
5065     TRACE("(%p/%p)->(%p)\n", iface, This, ppClock);
5066
5067     if (!ppClock)
5068         return E_POINTER;
5069
5070     EnterCriticalSection(&This->cs);
5071     {
5072         *ppClock = This->refClock;
5073         if (*ppClock)
5074             IReferenceClock_AddRef(*ppClock);
5075     }
5076     LeaveCriticalSection(&This->cs);
5077
5078     return S_OK;
5079 }
5080
5081 static const IMediaFilterVtbl IMediaFilter_VTable =
5082 {
5083     MediaFilter_QueryInterface,
5084     MediaFilter_AddRef,
5085     MediaFilter_Release,
5086     MediaFilter_GetClassID,
5087     MediaFilter_Stop,
5088     MediaFilter_Pause,
5089     MediaFilter_Run,
5090     MediaFilter_GetState,
5091     MediaFilter_SetSyncSource,
5092     MediaFilter_GetSyncSource
5093 };
5094
5095 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, LPVOID *ppv)
5096 {
5097     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5098
5099     return Filtergraph_QueryInterface(This, riid, ppv);
5100 }
5101
5102 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5103 {
5104     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5105
5106     return Filtergraph_AddRef(This);
5107 }
5108
5109 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5110 {
5111     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5112
5113     return Filtergraph_Release(This);
5114 }
5115
5116 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, long EventCode, LONG_PTR EventParam1, LONG_PTR EventParam2)
5117 {
5118     ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5119     Event evt;
5120
5121     TRACE("(%p/%p)->(%ld, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5122
5123     /* We need thread safety here, let's use the events queue's one */
5124     EnterCriticalSection(&This->evqueue.msg_crst);
5125
5126     if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5127     {
5128         TRACE("Process EC_COMPLETE notification\n");
5129         if (++This->EcCompleteCount == This->nRenderers)
5130         {
5131             evt.lEventCode = EC_COMPLETE;
5132             evt.lParam1 = S_OK;
5133             evt.lParam2 = 0;
5134             TRACE("Send EC_COMPLETE to app\n");
5135             EventsQueue_PutEvent(&This->evqueue, &evt);
5136             if (!This->notif.disabled && This->notif.hWnd)
5137             {
5138                 TRACE("Send Window message\n");
5139                 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5140             }
5141             This->CompletionStatus = EC_COMPLETE;
5142             SetEvent(This->hEventCompletion);
5143         }
5144     }
5145     else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5146     {
5147         /* FIXME: Not handled yet */
5148     }
5149     else
5150     {
5151         evt.lEventCode = EventCode;
5152         evt.lParam1 = EventParam1;
5153         evt.lParam2 = EventParam2;
5154         EventsQueue_PutEvent(&This->evqueue, &evt);
5155         if (!This->notif.disabled && This->notif.hWnd)
5156             PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5157     }
5158
5159     LeaveCriticalSection(&This->evqueue.msg_crst);
5160     return S_OK;
5161 }
5162
5163 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5164 {
5165     MediaEventSink_QueryInterface,
5166     MediaEventSink_AddRef,
5167     MediaEventSink_Release,
5168     MediaEventSink_Notify
5169 };
5170
5171 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, LPVOID *ppv)
5172 {
5173     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5174
5175     return Filtergraph_QueryInterface(This, riid, ppv);
5176 }
5177
5178 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5179 {
5180     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5181
5182     return Filtergraph_AddRef(This);
5183 }
5184
5185 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5186 {
5187     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5188
5189     return Filtergraph_Release(This);
5190 }
5191
5192 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface,
5193                                             IPin* pOutputPin,
5194                                             IPin* pInputPin,
5195                                             const AM_MEDIA_TYPE* pmtFirstConnection,
5196                                             IBaseFilter* pUsingFilter,
5197                                             HANDLE hAbortEvent,
5198                                             DWORD dwFlags)
5199 {
5200     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5201
5202     FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5203     
5204     return E_NOTIMPL;
5205 }
5206
5207 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface,
5208                                               IGraphConfigCallback* pCallback,
5209                                               PVOID pvContext,
5210                                               DWORD dwFlags,
5211                                               HANDLE hAbortEvent)
5212 {
5213     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5214     HRESULT hr;
5215
5216     WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5217
5218     if (hAbortEvent)
5219         FIXME("The parameter hAbortEvent is not handled!\n");
5220
5221     EnterCriticalSection(&This->cs);
5222
5223     hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5224
5225     LeaveCriticalSection(&This->cs);
5226
5227     return hr;
5228 }
5229
5230 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface,
5231                                                    IBaseFilter* pFilter)
5232 {
5233     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5234
5235     FIXME("(%p)->(%p): stub!\n", This, pFilter);
5236     
5237     return E_NOTIMPL;
5238 }
5239
5240 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface,
5241                                                   IEnumFilters** pEnum)
5242 {
5243     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5244
5245     FIXME("(%p)->(%p): stub!\n", This, pEnum);
5246     
5247     return E_NOTIMPL;
5248 }
5249
5250 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface,
5251                                                         IBaseFilter* pFilter)
5252 {
5253     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5254
5255     FIXME("(%p)->(%p): stub!\n", This, pFilter);
5256     
5257     return E_NOTIMPL;
5258 }
5259
5260 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface,
5261                                                REFERENCE_TIME* prtStart)
5262 {
5263     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5264
5265     FIXME("(%p)->(%p): stub!\n", This, prtStart);
5266     
5267     return E_NOTIMPL;
5268 }
5269
5270 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface,
5271                                                   IPin* pOutputPin,
5272                                                   IPinConnection* pConnection,
5273                                                   HANDLE hEventAbort)
5274 {
5275     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5276
5277     FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5278     
5279     return E_NOTIMPL;
5280 }
5281
5282 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface,
5283                                                  IBaseFilter* pFilter,
5284                                                  DWORD dwFlags)
5285 {
5286     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5287
5288     FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5289     
5290     return E_NOTIMPL;
5291 }
5292
5293 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface,
5294                                                  IBaseFilter* pFilter,
5295                                                  DWORD* dwFlags)
5296 {
5297     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5298
5299     FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5300     
5301     return E_NOTIMPL;
5302 }
5303
5304 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface,
5305                                                  IBaseFilter* pFilter,
5306                                                  DWORD dwFlags)
5307 {
5308     ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5309
5310     FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5311     
5312     return E_NOTIMPL;
5313 }
5314
5315 static const IGraphConfigVtbl IGraphConfig_VTable =
5316 {
5317     GraphConfig_QueryInterface,
5318     GraphConfig_AddRef,
5319     GraphConfig_Release,
5320     GraphConfig_Reconnect,
5321     GraphConfig_Reconfigure,
5322     GraphConfig_AddFilterToCache,
5323     GraphConfig_EnumCacheFilter,
5324     GraphConfig_RemoveFilterFromCache,
5325     GraphConfig_GetStartTime,
5326     GraphConfig_PushThroughData,
5327     GraphConfig_SetFilterFlags,
5328     GraphConfig_GetFilterFlags,
5329     GraphConfig_RemoveFilterEx
5330 };
5331
5332 static const IUnknownVtbl IInner_VTable =
5333 {
5334     FilterGraphInner_QueryInterface,
5335     FilterGraphInner_AddRef,
5336     FilterGraphInner_Release
5337 };
5338
5339 static HRESULT WINAPI Filtergraph_QueryInterface(IFilterGraphImpl *This,
5340                                                  REFIID riid,
5341                                                  LPVOID * ppv) {
5342     if (This->bAggregatable)
5343         This->bUnkOuterValid = TRUE;
5344
5345     if (This->pUnkOuter)
5346     {
5347         if (This->bAggregatable)
5348             return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
5349
5350         if (IsEqualIID(riid, &IID_IUnknown))
5351         {
5352             HRESULT hr;
5353
5354             IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5355             hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5356             IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5357             This->bAggregatable = TRUE;
5358             return hr;
5359         }
5360
5361         *ppv = NULL;
5362         return E_NOINTERFACE;
5363     }
5364
5365     return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5366 }
5367
5368 static ULONG WINAPI Filtergraph_AddRef(IFilterGraphImpl *This) {
5369     if (This->pUnkOuter && This->bUnkOuterValid)
5370         return IUnknown_AddRef(This->pUnkOuter);
5371     return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5372 }
5373
5374 static ULONG WINAPI Filtergraph_Release(IFilterGraphImpl *This) {
5375     if (This->pUnkOuter && This->bUnkOuterValid)
5376         return IUnknown_Release(This->pUnkOuter);
5377     return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5378 }
5379
5380 /* This is the only function that actually creates a FilterGraph class... */
5381 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5382 {
5383     IFilterGraphImpl *fimpl;
5384     HRESULT hr;
5385
5386     TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5387
5388     *ppObj = NULL;
5389
5390     fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5391     fimpl->pUnkOuter = pUnkOuter;
5392     fimpl->bUnkOuterValid = FALSE;
5393     fimpl->bAggregatable = FALSE;
5394     fimpl->IInner_vtbl = &IInner_VTable;
5395     fimpl->IFilterGraph2_vtbl = &IFilterGraph2_VTable;
5396     fimpl->IMediaControl_vtbl = &IMediaControl_VTable;
5397     fimpl->IMediaSeeking_vtbl = &IMediaSeeking_VTable;
5398     fimpl->IBasicAudio_vtbl = &IBasicAudio_VTable;
5399     fimpl->IBasicVideo_vtbl = &IBasicVideo_VTable;
5400     fimpl->IVideoWindow_vtbl = &IVideoWindow_VTable;
5401     fimpl->IMediaEventEx_vtbl = &IMediaEventEx_VTable;
5402     fimpl->IMediaFilter_vtbl = &IMediaFilter_VTable;
5403     fimpl->IMediaEventSink_vtbl = &IMediaEventSink_VTable;
5404     fimpl->IGraphConfig_vtbl = &IGraphConfig_VTable;
5405     fimpl->IMediaPosition_vtbl = &IMediaPosition_VTable;
5406     fimpl->ref = 1;
5407     fimpl->ppFiltersInGraph = NULL;
5408     fimpl->pFilterNames = NULL;
5409     fimpl->nFilters = 0;
5410     fimpl->filterCapacity = 0;
5411     fimpl->nameIndex = 1;
5412     fimpl->refClock = NULL;
5413     fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5414     fimpl->HandleEcComplete = TRUE;
5415     fimpl->HandleEcRepaint = TRUE;
5416     fimpl->HandleEcClockChanged = TRUE;
5417     fimpl->notif.hWnd = 0;
5418     fimpl->notif.disabled = FALSE;
5419     fimpl->nRenderers = 0;
5420     fimpl->EcCompleteCount = 0;
5421     fimpl->state = State_Stopped;
5422     EventsQueue_Init(&fimpl->evqueue);
5423     InitializeCriticalSection(&fimpl->cs);
5424     fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5425     fimpl->nItfCacheEntries = 0;
5426     memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5427     fimpl->start_time = fimpl->position = 0;
5428     fimpl->stop_position = -1;
5429     fimpl->punkFilterMapper2 = NULL;
5430
5431     /* create Filtermapper aggregated. */
5432     hr = CoCreateInstance(&CLSID_FilterMapper2, pUnkOuter ? pUnkOuter : (IUnknown*)&fimpl->IInner_vtbl, CLSCTX_INPROC_SERVER,
5433         &IID_IUnknown, (LPVOID*)&fimpl->punkFilterMapper2);
5434
5435     if (SUCCEEDED(hr)) {
5436         hr = IUnknown_QueryInterface(fimpl->punkFilterMapper2, &IID_IFilterMapper2,  (LPVOID*)&fimpl->pFilterMapper2);
5437     }
5438
5439     if (SUCCEEDED(hr)) {
5440         /* Release controlling IUnknown - compensate refcount increase from caching IFilterMapper2 interface. */
5441         if (pUnkOuter) IUnknown_Release(pUnkOuter);
5442         else IUnknown_Release((IUnknown*)&fimpl->IInner_vtbl);
5443     }
5444
5445     if (FAILED(hr)) {
5446         ERR("Unable to create filter mapper (%x)\n", hr);
5447         if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5448         CloseHandle(fimpl->hEventCompletion);
5449         EventsQueue_Destroy(&fimpl->evqueue);
5450         fimpl->cs.DebugInfo->Spare[0] = 0;
5451         DeleteCriticalSection(&fimpl->cs);
5452         CoTaskMemFree(fimpl);
5453         return hr;
5454     }
5455     IFilterGraph2_SetDefaultSyncSource((IFilterGraph2*)fimpl);
5456
5457     *ppObj = fimpl;
5458     return S_OK;
5459 }
5460
5461 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5462 {
5463     FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5464     return FilterGraph_create(pUnkOuter, ppObj);
5465 }