quartz: Sign-compare warnings fix.
[wine/multimedia.git] / dlls / quartz / filtergraph.c
blobeec0e440b9e95a1edb3fcf1e8a7221dfe9cd0143
1 /* DirectShow FilterGraph object (QUARTZ.DLL)
3 * Copyright 2002 Lionel Ulmer
4 * Copyright 2004 Christian Costa
6 * This file contains the (internal) driver registration functions,
7 * driver enumeration APIs and DirectDraw creation functions.
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.
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.
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
24 #include "config.h"
25 #include <stdarg.h>
27 #define COBJMACROS
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"
45 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
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;
54 typedef struct {
55 long lEventCode; /* Event code */
56 LONG_PTR lParam1; /* Param1 */
57 LONG_PTR lParam2; /* Param2 */
58 } Event;
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;
71 static int EventsQueue_Init(EventsQueue* omr)
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));
80 InitializeCriticalSection(&omr->msg_crst);
81 omr->msg_crst.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": EventsQueue.msg_crst");
82 return TRUE;
85 static int EventsQueue_Destroy(EventsQueue* omr)
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;
94 static int EventsQueue_PutEvent(EventsQueue* omr, const Event* evt)
96 EnterCriticalSection(&omr->msg_crst);
97 if ((omr->msg_toget == ((omr->msg_tosave + 1) % omr->ring_buffer_size)))
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.
107 if (omr->msg_tosave < omr->msg_toget)
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)
113 omr->msg_toget += EVENTS_RING_BUFFER_INCREMENT;
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;
123 static int EventsQueue_GetEvent(EventsQueue* omr, Event* evt, long msTimeOut)
125 if (WaitForSingleObject(omr->msg_event, msTimeOut) != WAIT_OBJECT_0)
126 return FALSE;
128 EnterCriticalSection(&omr->msg_crst);
130 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
132 LeaveCriticalSection(&omr->msg_crst);
133 return FALSE;
136 *evt = omr->messages[omr->msg_toget];
137 omr->msg_toget = (omr->msg_toget + 1) % omr->ring_buffer_size;
139 /* Mark the buffer as empty if needed */
140 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
141 ResetEvent(omr->msg_event);
143 LeaveCriticalSection(&omr->msg_crst);
144 return TRUE;
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;
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 */
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;
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);
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);
220 if (This->bAggregatable)
221 This->bUnkOuterValid = TRUE;
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;
276 IUnknown_AddRef((IUnknown *)(*ppvObj));
277 return S_OK;
280 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown * iface) {
281 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
282 ULONG ref = InterlockedIncrement(&This->ref);
284 TRACE("(%p)->(): new ref = %d\n", This, ref);
286 return ref;
289 static ULONG WINAPI FilterGraphInner_Release(IUnknown * iface)
291 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
292 ULONG ref = InterlockedDecrement(&This->ref);
294 TRACE("(%p)->(): new ref = %d\n", This, ref);
296 if (ref == 0) {
297 int i;
299 This->ref = 1; /* guard against reentrancy (aggregation). */
301 IMediaControl_Stop((IMediaControl*)&(This->IMediaControl_vtbl));
303 while (This->nFilters)
304 IFilterGraph2_RemoveFilter((IFilterGraph2*)This, This->ppFiltersInGraph[0]);
306 if (This->refClock)
307 IReferenceClock_Release(This->refClock);
309 for (i = 0; i < This->nItfCacheEntries; i++)
311 if (This->ItfCacheEntries[i].iface)
312 IUnknown_Release(This->ItfCacheEntries[i].iface);
315 /* AddRef on controlling IUnknown, to compensate for Release of cached IFilterMapper2 interface below.
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);
324 IFilterMapper2_Release(This->pFilterMapper2);
325 IUnknown_Release(This->punkFilterMapper2);
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);
335 return ref;
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);
345 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
346 return Filtergraph_QueryInterface(This, riid, ppvObj);
349 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface) {
350 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
352 TRACE("(%p/%p)->() calling FilterGraph AddRef\n", This, iface);
354 return Filtergraph_AddRef(This);
357 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface) {
358 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
360 TRACE("(%p/%p)->() calling FilterGraph Release\n", This, iface);
362 return Filtergraph_Release(This);
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;
375 TRACE("(%p/%p)->(%p, %s (%p))\n", This, iface, pFilter, debugstr_w(pName), pName);
377 if (!pFilter)
378 return E_POINTER;
380 wszFilterName = CoTaskMemAlloc( (pName ? strlenW(pName) + 6 : 5) * sizeof(WCHAR) );
382 if (pName)
384 /* Check if name already exists */
385 for(i = 0; i < This->nFilters; i++)
386 if (!strcmpW(This->pFilterNames[i], pName))
388 duplicate_name = TRUE;
389 break;
393 /* If no name given or name already existing, generate one */
394 if (!pName || duplicate_name)
396 static const WCHAR wszFmt1[] = {'%','s',' ','%','0','4','d',0};
397 static const WCHAR wszFmt2[] = {'%','0','4','d',0};
399 for (j = 0; j < 10000 ; j++)
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));
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;
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;
419 /* Unable to find a suitable name */
420 if (j == 10000)
422 CoTaskMemFree(wszFilterName);
423 return VFW_E_DUPLICATE_NAME;
426 else
427 memcpy(wszFilterName, pName, (strlenW(pName) + 1) * sizeof(WCHAR));
429 if (This->nFilters + 1 > This->filterCapacity)
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)
438 CoTaskMemFree(This->ppFiltersInGraph);
439 CoTaskMemFree(This->pFilterNames);
441 This->ppFiltersInGraph = ppNewFilters;
442 This->pFilterNames = pNewNames;
443 This->filterCapacity = newCapacity;
446 hr = IBaseFilter_JoinFilterGraph(pFilter, (IFilterGraph *)This, wszFilterName);
448 if (SUCCEEDED(hr))
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);
456 else
457 CoTaskMemFree(wszFilterName);
459 if (SUCCEEDED(hr) && duplicate_name)
460 return VFW_S_DUPLICATE_NAME;
462 return hr;
465 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
467 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
468 int i;
469 HRESULT hr = E_FAIL;
471 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
473 /* FIXME: check graph is stopped */
475 for (i = 0; i < This->nFilters; i++)
477 if (This->ppFiltersInGraph[i] == pFilter)
479 IEnumPins *penumpins = NULL;
480 FILTER_STATE state;
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);
489 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
490 if (SUCCEEDED(hr)) {
491 IPin *ppin;
492 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
494 IPin *victim = NULL;
495 HRESULT h;
496 IPin_ConnectedTo(ppin, &victim);
497 if (victim)
499 h = IPin_Disconnect(victim);
500 TRACE("Disconnect other side: %08x\n", h);
501 if (h == VFW_E_NOT_STOPPED)
503 PIN_INFO pinfo;
504 IPin_QueryPinInfo(victim, &pinfo);
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);
514 IPin_Release(victim);
516 h = IPin_Disconnect(ppin);
517 TRACE("Disconnect 2: %08x\n", h);
519 IPin_Release(ppin);
521 IEnumPins_Release(penumpins);
524 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, This->pFilterNames[i]);
525 if (SUCCEEDED(hr))
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)
537 IUnknown_Release(This->ItfCacheEntries[i].iface);
538 This->ItfCacheEntries[i].iface = NULL;
539 This->ItfCacheEntries[i].filter = NULL;
541 return S_OK;
543 break;
547 return hr; /* FIXME: check this error code */
550 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface,
551 IEnumFilters **ppEnum) {
552 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
554 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
556 return IEnumFiltersImpl_Construct(This->ppFiltersInGraph, This->nFilters, ppEnum);
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;
565 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_w(pName), pName, ppFilter);
567 if (!ppFilter)
568 return E_POINTER;
570 for (i = 0; i < This->nFilters; i++)
572 if (!strcmpW(pName, This->pFilterNames[i]))
574 *ppFilter = This->ppFiltersInGraph[i];
575 IBaseFilter_AddRef(*ppFilter);
576 return S_OK;
580 *ppFilter = NULL;
581 return VFW_E_NOT_FOUND;
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
587 static HRESULT WINAPI CheckCircularConnection(IFilterGraphImpl *This, IPin *out, IPin *in)
589 #if 1
590 HRESULT hr;
591 PIN_INFO info_out, info_in;
593 hr = IPin_QueryPinInfo(out, &info_out);
594 if (FAILED(hr))
595 return hr;
596 if (info_out.dir != PINDIR_OUTPUT)
598 IBaseFilter_Release(info_out.pFilter);
599 return E_UNEXPECTED;
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)
609 hr = E_UNEXPECTED;
610 goto out;
613 if (info_out.pFilter == info_in.pFilter)
614 hr = VFW_E_CIRCULAR_GRAPH;
615 else
617 IEnumPins *enumpins;
618 IPin *test;
620 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
621 if (FAILED(hr))
622 goto out;
624 IEnumPins_Reset(enumpins);
625 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
627 PIN_DIRECTION dir = PINDIR_OUTPUT;
628 IPin_QueryDirection(test, &dir);
629 if (dir == PINDIR_INPUT)
631 IPin *victim = NULL;
632 IPin_ConnectedTo(test, &victim);
633 if (victim)
635 hr = CheckCircularConnection(This, victim, in);
636 IPin_Release(victim);
637 if (FAILED(hr))
639 IPin_Release(test);
640 break;
644 IPin_Release(test);
646 IEnumPins_Release(enumpins);
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
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;
670 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
672 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
674 /* FIXME: check pins are in graph */
676 if (TRACE_ON(quartz))
678 PIN_INFO PinInfo;
680 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
681 if (FAILED(hr))
682 return hr;
684 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
685 IBaseFilter_Release(PinInfo.pFilter);
687 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
688 if (FAILED(hr))
689 return hr;
691 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
692 IBaseFilter_Release(PinInfo.pFilter);
695 hr = IPin_QueryDirection(ppinIn, &dir);
696 if (SUCCEEDED(hr))
698 if (dir == PINDIR_INPUT)
700 hr = CheckCircularConnection(This, ppinOut, ppinIn);
701 if (SUCCEEDED(hr))
702 hr = IPin_Connect(ppinOut, ppinIn, pmt);
704 else
706 hr = CheckCircularConnection(This, ppinIn, ppinOut);
707 if (SUCCEEDED(hr))
708 hr = IPin_Connect(ppinIn, ppinOut, pmt);
712 return hr;
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;
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;
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;
741 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
743 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
745 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
747 return IPin_Disconnect(ppin);
750 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface) {
751 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
752 IReferenceClock *pClock = NULL;
753 HRESULT hr;
755 TRACE("(%p/%p)->() semi-stub\n", iface, This);
757 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
759 if (SUCCEEDED(hr))
761 hr = IMediaFilter_SetSyncSource((IMediaFilter*)&(This->IMediaFilter_vtbl), pClock);
762 IReferenceClock_Release(pClock);
765 return hr;
768 static HRESULT GetFilterInfo(IMoniker* pMoniker, GUID* pclsid, VARIANT* pvar)
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;
775 VariantInit(pvar);
777 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
779 if (SUCCEEDED(hr))
780 hr = IPropertyBag_Read(pPropBagCat, wszClsidName, pvar, NULL);
782 if (SUCCEEDED(hr))
783 hr = CLSIDFromString(V_UNION(pvar, bstrVal), pclsid);
785 VariantClear(pvar);
787 if (SUCCEEDED(hr))
788 hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL);
790 if (SUCCEEDED(hr))
791 TRACE("Moniker = %s - %s\n", debugstr_guid(pclsid), debugstr_w(V_UNION(pvar, bstrVal)));
793 if (pPropBagCat)
794 IPropertyBag_Release(pPropBagCat);
796 return hr;
799 static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPin*** pppins, ULONG* pnb)
801 HRESULT hr;
802 ULONG nb = 0;
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);
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;
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);
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);
846 IEnumPins_Release(penumpins);
847 nb = i;
848 if (FAILED(hr)) {
849 WARN("Next failed (%x)\n", hr);
850 return hr;
852 } else if (FAILED(hr)) {
853 WARN("Cannot get internal connection (%x)\n", hr);
854 return hr;
857 *pnb = nb;
858 return S_OK;
861 /*** IGraphBuilder methods ***/
862 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IPin *ppinIn)
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;
879 TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
881 if (TRACE_ON(quartz))
883 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
884 if (FAILED(hr))
885 return hr;
887 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
888 IBaseFilter_Release(PinInfo.pFilter);
890 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
891 if (FAILED(hr))
892 return hr;
894 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
895 IBaseFilter_Release(PinInfo.pFilter);
898 hr = IPin_QueryDirection(ppinOut, &dir);
899 if (FAILED(hr))
900 return hr;
902 if (dir == PINDIR_INPUT)
904 IPin *temp;
906 temp = ppinIn;
907 ppinIn = ppinOut;
908 ppinOut = temp;
911 hr = CheckCircularConnection(This, ppinOut, ppinIn);
912 if (FAILED(hr))
913 return hr;
915 /* Try direct connection first */
916 hr = IPin_Connect(ppinOut, ppinIn, NULL);
917 if (SUCCEEDED(hr)) {
918 return S_OK;
920 TRACE("Direct connection failed, trying to render using extra filters\n");
922 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
923 if (FAILED(hr))
924 return hr;
926 hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
927 IBaseFilter_Release(PinInfo.pFilter);
928 if (FAILED(hr))
929 return hr;
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;
939 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
940 if (FAILED(hr)) {
941 WARN("IEnumMediaTypes_Next (%x)\n", hr);
942 return hr;
945 if (!nbmt)
947 WARN("No media type found!\n");
948 return S_OK;
950 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
951 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
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;
962 hr = VFW_E_CANNOT_RENDER;
963 while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
965 VARIANT var;
966 GUID clsid;
967 IPin** ppins;
968 IPin* ppinfilter = NULL;
969 IBaseFilter* pfilter = NULL;
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;
978 if (IsEqualGUID(&clsid, &FilterCLSID)) {
979 /* Skip filter (same as the one the output pin belongs to) */
980 goto error;
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;
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;
997 VariantClear(&var);
999 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1000 if (FAILED(hr)) {
1001 WARN("Enumpins (%x)\n", hr);
1002 goto error;
1005 hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin);
1006 IEnumPins_Release(penumpins);
1008 if (FAILED(hr)) {
1009 WARN("Obtaining next pin: (%x)\n", hr);
1010 goto error;
1012 if (pin == 0) {
1013 WARN("Cannot use this filter: no pins\n");
1014 goto error;
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;
1022 TRACE("Successfully connected to filter, follow chain...\n");
1024 /* Render all output pins of the filter by calling IFilterGraph2_Connect on each of them */
1025 hr = GetInternalConnections(pfilter, ppinfilter, &ppins, &nb);
1027 if (SUCCEEDED(hr)) {
1028 unsigned int i;
1029 if (nb == 0) {
1030 IPin_Disconnect(ppinfilter);
1031 IPin_Disconnect(ppinOut);
1032 goto error;
1034 TRACE("pins to consider: %d\n", nb);
1035 for(i = 0; i < nb; i++)
1037 LPWSTR pinname = NULL;
1039 TRACE("Processing pin %u\n", i);
1041 hr = IPin_QueryId(ppins[i], &pinname);
1042 if (SUCCEEDED(hr))
1044 if (pinname[0] == '~')
1046 TRACE("Pinname=%s, skipping\n", debugstr_w(pinname));
1047 hr = E_FAIL;
1049 else
1050 hr = IFilterGraph2_Connect(iface, ppins[i], ppinIn);
1051 CoTaskMemFree(pinname);
1054 if (FAILED(hr)) {
1055 TRACE("Cannot connect pin %p (%x)\n", ppinfilter, hr);
1057 IPin_Release(ppins[i]);
1058 if (SUCCEEDED(hr)) break;
1060 while (++i < nb) IPin_Release(ppins[i]);
1061 CoTaskMemFree(ppins);
1062 IPin_Release(ppinfilter);
1063 IBaseFilter_Release(pfilter);
1064 if (FAILED(hr))
1066 IPin_Disconnect(ppinfilter);
1067 IPin_Disconnect(ppinOut);
1068 IFilterGraph2_RemoveFilter(iface, pfilter);
1069 continue;
1071 break;
1074 error:
1075 VariantClear(&var);
1076 if (ppinfilter) IPin_Release(ppinfilter);
1077 if (pfilter) {
1078 IFilterGraph2_RemoveFilter(iface, pfilter);
1079 IBaseFilter_Release(pfilter);
1083 IEnumMediaTypes_Release(penummt);
1084 DeleteMediaType(mt);
1086 TRACE("--> %08x\n", hr);
1087 return SUCCEEDED(hr) ? S_OK : hr;
1090 static HRESULT WINAPI FilterGraph2_RenderRecurse(IFilterGraphImpl *This, IPin *ppinOut)
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;
1099 IPin_QueryPinInfo(ppinOut, &info);
1101 IBaseFilter_EnumPins(info.pFilter, &enumpins);
1102 /* Don't need to hold a reference, IEnumPins does */
1103 IBaseFilter_Release(info.pFilter);
1105 IEnumPins_Reset(enumpins);
1106 while (IEnumPins_Next(enumpins, 1, &to, NULL) == S_OK)
1108 PIN_DIRECTION dir = PINDIR_INPUT;
1110 IPin_QueryDirection(to, &dir);
1112 if (dir == PINDIR_OUTPUT)
1114 IPin *out = NULL;
1116 IPin_ConnectedTo(to, &out);
1117 if (!out)
1119 HRESULT hr;
1120 hr = IFilterGraph2_Render((IFilterGraph2 *)&This->IFilterGraph2_vtbl, to);
1121 if (SUCCEEDED(hr))
1122 renderany = TRUE;
1123 else
1124 renderall = FALSE;
1126 else
1127 IPin_Release(out);
1130 IPin_Release(to);
1133 IEnumPins_Release(enumpins);
1135 if (renderall)
1136 return S_OK;
1138 if (renderany)
1139 return VFW_S_PARTIAL_RENDER;
1141 return VFW_E_CANNOT_RENDER;
1144 /* Ogg hates me if I create a direct rendering method
1146 * It can only connect to a pin properly once, so use a recursive method that does
1148 * +----+ --- (PIN 1) (Render is called on this pin)
1149 * | |
1150 * +----+ --- (PIN 2)
1152 * Enumerate possible renderers that EXACTLY match the requested type
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!
1162 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *ppinOut)
1164 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1165 IEnumMediaTypes* penummt;
1166 AM_MEDIA_TYPE* mt;
1167 ULONG nbmt;
1168 HRESULT hr;
1170 IEnumMoniker* pEnumMoniker;
1171 GUID tab[4];
1172 ULONG nb;
1173 IMoniker* pMoniker;
1174 INT x;
1176 TRACE("(%p/%p)->(%p)\n", This, iface, ppinOut);
1178 if (TRACE_ON(quartz))
1180 PIN_INFO PinInfo;
1182 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
1183 if (FAILED(hr))
1184 return hr;
1186 TRACE("Filter owning pin => %p\n", PinInfo.pFilter);
1187 IBaseFilter_Release(PinInfo.pFilter);
1190 /* Try to find out if there is a renderer for the specified subtype already, and use that
1192 EnterCriticalSection(&This->cs);
1193 for (x = 0; x < This->nFilters; ++x)
1195 IEnumPins *enumpins = NULL;
1196 IPin *pin = NULL;
1198 hr = IBaseFilter_EnumPins(This->ppFiltersInGraph[x], &enumpins);
1200 if (FAILED(hr) || !enumpins)
1201 continue;
1203 IEnumPins_Reset(enumpins);
1204 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
1206 IPin *to = NULL;
1207 PIN_DIRECTION dir = PINDIR_OUTPUT;
1209 IPin_QueryDirection(pin, &dir);
1210 if (dir != PINDIR_INPUT)
1212 IPin_Release(pin);
1213 continue;
1215 IPin_ConnectedTo(pin, &to);
1217 if (to == NULL)
1219 hr = IPin_Connect(ppinOut, pin, NULL);
1220 if (SUCCEEDED(hr))
1222 TRACE("Connected successfully %p/%p, %08x look if we should render more!\n", ppinOut, pin, hr);
1223 IPin_Release(pin);
1225 hr = FilterGraph2_RenderRecurse(This, pin);
1226 if (FAILED(hr))
1228 IPin_Disconnect(ppinOut);
1229 IPin_Disconnect(pin);
1230 continue;
1232 IEnumPins_Release(enumpins);
1233 LeaveCriticalSection(&This->cs);
1234 return hr;
1236 WARN("Could not connect!\n");
1238 else
1239 IPin_Release(to);
1241 IPin_Release(pin);
1243 IEnumPins_Release(enumpins);
1246 LeaveCriticalSection(&This->cs);
1248 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
1249 if (FAILED(hr)) {
1250 WARN("EnumMediaTypes (%x)\n", hr);
1251 return hr;
1254 IEnumMediaTypes_Reset(penummt);
1256 /* Looks like no existing renderer of the kind exists
1257 * Try adding new ones
1259 tab[0] = tab[1] = GUID_NULL;
1260 while (SUCCEEDED(hr))
1262 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
1263 if (FAILED(hr)) {
1264 WARN("IEnumMediaTypes_Next (%x)\n", hr);
1265 break;
1267 if (!nbmt)
1269 hr = VFW_E_CANNOT_RENDER;
1270 break;
1272 else
1274 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1275 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
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))
1280 DeleteMediaType(mt);
1281 continue;
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))
1290 WARN("Unable to enum filters (%x)\n", hr);
1291 break;
1294 hr = E_FAIL;
1296 while (IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1298 VARIANT var;
1299 GUID clsid;
1300 IPin* ppinfilter;
1301 IBaseFilter* pfilter = NULL;
1302 IEnumPins* penumpins;
1303 ULONG pin;
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;
1312 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
1313 if (FAILED(hr))
1315 WARN("Unable to create filter (%x), trying next one\n", hr);
1316 goto error;
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;
1327 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1328 if (FAILED(hr)) {
1329 WARN("Splitter Enumpins (%x)\n", hr);
1330 goto error;
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;
1338 if (pin == 0) {
1339 WARN("No Pin\n");
1340 hr = E_FAIL;
1341 goto error;
1344 /* Connect the pin to the "Renderer" */
1345 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1346 IPin_Release(ppinfilter);
1348 if (FAILED(hr)) {
1349 WARN("Unable to connect %s to renderer (%x)\n", debugstr_w(V_UNION(&var, bstrVal)), hr);
1350 goto error;
1352 TRACE("Connected, recursing %s\n", debugstr_w(V_UNION(&var, bstrVal)));
1354 VariantClear(&var);
1356 hr = FilterGraph2_RenderRecurse(This, ppinfilter);
1357 if (FAILED(hr)) {
1358 WARN("Unable to connect recursively (%x)\n", hr);
1359 goto error;
1361 IBaseFilter_Release(pfilter);
1362 break;
1364 error:
1365 VariantClear(&var);
1366 if (pfilter) {
1367 IFilterGraph2_RemoveFilter(iface, pfilter);
1368 IBaseFilter_Release(pfilter);
1370 if (SUCCEEDED(hr)) DebugBreak();
1373 IEnumMoniker_Release(pEnumMoniker);
1374 if (nbmt)
1375 DeleteMediaType(mt);
1376 if (SUCCEEDED(hr))
1377 break;
1378 hr = S_OK;
1381 IEnumMediaTypes_Release(penummt);
1382 return hr;
1385 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface,
1386 LPCWSTR lpcwstrFile,
1387 LPCWSTR lpcwstrPlayList)
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;
1398 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1400 if (lpcwstrPlayList != NULL)
1401 return E_INVALIDARG;
1403 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, string, &preader);
1404 if (FAILED(hr))
1405 return hr;
1407 if (SUCCEEDED(hr))
1408 hr = IBaseFilter_EnumPins(preader, &penumpins);
1409 if (SUCCEEDED(hr))
1411 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1413 PIN_DIRECTION dir;
1415 IPin_QueryDirection(ppinreader, &dir);
1416 if (dir == PINDIR_OUTPUT)
1418 INT i;
1420 hr = IFilterGraph2_Render(iface, ppinreader);
1421 TRACE("Render %08x\n", hr);
1423 for (i = 0; i < This->nFilters; ++i)
1424 TRACE("Filters in chain: %s\n", debugstr_w(This->pFilterNames[i]));
1426 if (SUCCEEDED(hr))
1427 any = TRUE;
1428 if (hr != S_OK)
1429 partial = TRUE;
1431 IPin_Release(ppinreader);
1433 IEnumPins_Release(penumpins);
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;
1442 IBaseFilter_Release(preader);
1444 TRACE("--> %08x\n", hr);
1445 return hr;
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)
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;
1456 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszReg, 0, KEY_READ, &extkey);
1457 hr = HRESULT_FROM_WIN32(lRet);
1459 if (SUCCEEDED(hr))
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;
1468 if (!ext)
1470 CloseHandle(extkey);
1471 return E_FAIL;
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;
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;
1486 CLSIDFromString(clsid_key, &clsid);
1488 TRACE("CLSID: %s\n", debugstr_guid(&clsid));
1489 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1490 if (SUCCEEDED(hr))
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);
1500 if (FAILED(hr))
1501 *filter = NULL;
1502 return hr;
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;
1516 TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1518 /* Try from file name first, then fall back to default asynchronous reader */
1519 hr = GetFileSourceFilter(lpcwstrFileName, &preader);
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;
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;
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;
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;
1548 IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1549 if (FAILED(hr)) {
1550 WARN("GetCurFile (%x)\n", hr);
1551 goto error;
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));
1558 if (ppFilter)
1559 *ppFilter = preader;
1560 IFileSourceFilter_Release(pfile);
1562 return S_OK;
1564 error:
1565 if (pfile)
1566 IFileSourceFilter_Release(pfile);
1567 IFilterGraph2_RemoveFilter(iface, preader);
1568 IBaseFilter_Release(preader);
1570 return hr;
1573 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface,
1574 DWORD_PTR hFile) {
1575 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1577 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1579 return S_OK;
1582 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface) {
1583 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1585 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1587 return S_OK;
1590 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface) {
1591 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1593 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1595 return S_OK;
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);
1606 TRACE("(%p/%p)->(%p %p %s %p): stub !!!\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1608 return S_OK;
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);
1616 TRACE("(%p/%p)->(%p %p): stub !!!\n", This, iface, ppin, pmt);
1618 return S_OK;
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);
1627 TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This, iface, pPinOut, dwFlags, pvContext);
1629 return S_OK;
1633 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
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
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);
1664 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1666 return Filtergraph_QueryInterface(This, riid, ppvObj);
1669 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface) {
1670 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1672 TRACE("(%p/%p)->()\n", This, iface);
1674 return Filtergraph_AddRef(This);
1677 static ULONG WINAPI MediaControl_Release(IMediaControl *iface) {
1678 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1680 TRACE("(%p/%p)->()\n", This, iface);
1682 return Filtergraph_Release(This);
1686 /*** IDispatch methods ***/
1687 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface,
1688 UINT*pctinfo) {
1689 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1691 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1693 return S_OK;
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);
1702 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1704 return S_OK;
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);
1715 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1717 return S_OK;
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);
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);
1733 return S_OK;
1736 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *, DWORD_PTR data);
1738 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter, DWORD_PTR data)
1740 HRESULT hr;
1741 IPin* pInputPin;
1742 IPin** ppPins;
1743 ULONG nb;
1744 ULONG i;
1745 PIN_INFO PinInfo;
1747 TRACE("%p %p\n", pGraph, pOutputPin);
1748 PinInfo.pFilter = NULL;
1750 hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1752 if (SUCCEEDED(hr))
1754 hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1755 if (SUCCEEDED(hr))
1756 hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1757 IPin_Release(pInputPin);
1760 if (SUCCEEDED(hr))
1762 if (nb == 0)
1764 TRACE("Reached a renderer\n");
1765 /* Count renderers for end of stream notification */
1766 pGraph->nRenderers++;
1768 else
1770 for(i = 0; i < nb; i++)
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]);
1779 CoTaskMemFree(ppPins);
1781 TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1783 FoundFilter(PinInfo.pFilter, data);
1786 if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1787 return hr;
1790 static HRESULT WINAPI SendRun(IBaseFilter *pFilter, DWORD_PTR data)
1792 LONGLONG time = 0;
1793 IReferenceClock *clock = NULL;
1795 IBaseFilter_GetSyncSource(pFilter, &clock);
1796 if (clock)
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);
1807 return IBaseFilter_Run(pFilter, time);
1810 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1812 return IBaseFilter_Pause(pFilter);
1815 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1817 return IBaseFilter_Stop(pFilter);
1820 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1822 FILTER_STATE state;
1823 DWORD time_end = data;
1824 DWORD time_now = GetTickCount();
1825 LONG wait;
1827 if (time_end == INFINITE)
1829 wait = INFINITE;
1831 else if (time_end > time_now)
1833 wait = time_end - time_now;
1835 else
1836 wait = 0;
1838 return IBaseFilter_GetState(pFilter, wait, &state);
1842 static HRESULT SendFilterMessage(IMediaControl *iface, fnFoundFilter FoundFilter, DWORD_PTR data)
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);
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);
1859 for(i = 0; i < This->nFilters; i++)
1861 BOOL source = TRUE;
1862 pfilter = This->ppFiltersInGraph[i];
1863 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
1864 if (hr != S_OK)
1866 WARN("Enum pins failed %x\n", hr);
1867 continue;
1869 /* Check if it is a source filter */
1870 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1872 IPin_QueryDirection(pPin, &dir);
1873 IPin_Release(pPin);
1874 if (dir == PINDIR_INPUT)
1876 source = FALSE;
1877 break;
1880 if (source)
1882 TRACE("Found a source filter %p\n", pfilter);
1883 IEnumPins_Reset(pEnum);
1884 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1886 /* Explore the graph downstream from this pin */
1887 ExploreGraph(This, pPin, FoundFilter, data);
1888 IPin_Release(pPin);
1890 FoundFilter(pfilter, data);
1892 IEnumPins_Release(pEnum);
1895 return S_FALSE;
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);
1903 if (This->state == State_Running) return S_OK;
1905 EnterCriticalSection(&This->cs);
1906 if (This->state == State_Stopped)
1907 This->EcCompleteCount = 0;
1909 if (This->refClock)
1911 IReferenceClock_GetTime(This->refClock, &This->start_time);
1912 This->start_time += 500000;
1914 else This->position = This->start_time = 0;
1916 SendFilterMessage(iface, SendRun, 0);
1917 This->state = State_Running;
1918 LeaveCriticalSection(&This->cs);
1919 return S_FALSE;
1922 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface) {
1923 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1924 TRACE("(%p/%p)->()\n", This, iface);
1926 if (This->state == State_Paused) return S_OK;
1928 EnterCriticalSection(&This->cs);
1929 if (This->state == State_Stopped)
1930 This->EcCompleteCount = 0;
1932 if (This->state == State_Running && This->refClock)
1934 LONGLONG time = This->start_time;
1935 IReferenceClock_GetTime(This->refClock, &time);
1936 This->position += time - This->start_time;
1939 SendFilterMessage(iface, SendPause, 0);
1940 This->state = State_Paused;
1941 LeaveCriticalSection(&This->cs);
1942 return S_FALSE;
1945 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface) {
1946 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1947 TRACE("(%p/%p)->()\n", This, iface);
1949 if (This->state == State_Stopped) return S_OK;
1951 EnterCriticalSection(&This->cs);
1952 if (This->state == State_Running && This->refClock)
1954 LONGLONG time = This->start_time;
1955 IReferenceClock_GetTime(This->refClock, &time);
1956 This->position += time - This->start_time;
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;
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;
1972 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
1974 if (!pfs)
1975 return E_POINTER;
1977 EnterCriticalSection(&This->cs);
1979 *pfs = This->state;
1980 if (msTimeout > 0)
1982 end = GetTickCount() + msTimeout;
1984 else if (msTimeout < 0)
1986 end = INFINITE;
1988 else
1990 end = 0;
1992 if (end)
1993 SendFilterMessage(iface, SendGetState, end);
1995 LeaveCriticalSection(&This->cs);
1997 return S_OK;
2000 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface,
2001 BSTR strFilename) {
2002 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2004 FIXME("(%p/%p)->(%s (%p)): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename);
2006 return S_OK;
2009 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface,
2010 BSTR strFilename,
2011 IDispatch **ppUnk) {
2012 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2014 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2016 return S_OK;
2019 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface,
2020 IDispatch **ppUnk) {
2021 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2023 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2025 return S_OK;
2028 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface,
2029 IDispatch **ppUnk) {
2030 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2032 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2034 return S_OK;
2037 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface) {
2038 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2040 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2042 return S_OK;
2046 static const IMediaControlVtbl IMediaControl_VTable =
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
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);
2073 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2075 return Filtergraph_QueryInterface(This, riid, ppvObj);
2078 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface) {
2079 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2081 TRACE("(%p/%p)->()\n", This, iface);
2083 return Filtergraph_AddRef(This);
2086 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface) {
2087 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2089 TRACE("(%p/%p)->()\n", This, iface);
2091 return Filtergraph_Release(This);
2094 typedef HRESULT (WINAPI *fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
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;
2106 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2107 /* Send a message to all renderers, they are responsible for broadcasting it further */
2109 for(i = 0; i < This->nFilters; i++)
2111 BOOL renderer = TRUE;
2112 pfilter = This->ppFiltersInGraph[i];
2113 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
2114 if (hr != S_OK)
2116 WARN("Enum pins failed %x\n", hr);
2117 continue;
2119 /* Check if it is a source filter */
2120 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2122 IPin_QueryDirection(pPin, &dir);
2123 IPin_Release(pPin);
2124 if (dir != PINDIR_INPUT)
2126 renderer = FALSE;
2127 break;
2130 IEnumPins_Release(pEnum);
2131 if (renderer)
2133 IMediaSeeking *seek = NULL;
2134 IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2135 if (!seek)
2136 continue;
2138 hr = FoundSeek(This, seek, arg);
2140 IMediaSeeking_Release(seek);
2141 if (hr_return != E_NOTIMPL)
2142 allnotimpl = FALSE;
2143 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2144 hr_return = hr;
2148 if (allnotimpl)
2149 return E_NOTIMPL;
2150 return hr_return;
2153 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2155 HRESULT hr;
2156 DWORD caps = 0;
2158 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2159 if (FAILED(hr))
2160 return hr;
2162 /* Only add common capabilities everything supports */
2163 *(DWORD*)pcaps &= caps;
2165 return hr;
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);
2175 if (!pCapabilities)
2176 return E_POINTER;
2178 EnterCriticalSection(&This->cs);
2179 *pCapabilities = 0xffffffff;
2181 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2182 LeaveCriticalSection(&This->cs);
2184 return hr;
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);
2194 if (!pCapabilities)
2195 return E_POINTER;
2197 EnterCriticalSection(&This->cs);
2198 originalcaps = *pCapabilities;
2199 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2200 LeaveCriticalSection(&This->cs);
2202 if (FAILED(hr))
2203 return hr;
2205 if (!*pCapabilities)
2206 return E_FAIL;
2207 if (*pCapabilities != originalcaps)
2208 return S_FALSE;
2209 return S_OK;
2212 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface,
2213 const GUID *pFormat) {
2214 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2216 if (!pFormat)
2217 return E_POINTER;
2219 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2221 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2223 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2224 return S_FALSE;
2227 return S_OK;
2230 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface,
2231 GUID *pFormat) {
2232 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2234 if (!pFormat)
2235 return E_POINTER;
2237 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2238 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2240 return S_OK;
2243 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface,
2244 GUID *pFormat) {
2245 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2247 if (!pFormat)
2248 return E_POINTER;
2250 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2251 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2253 return S_OK;
2256 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface,
2257 const GUID *pFormat) {
2258 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2260 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2261 if (!pFormat)
2262 return E_POINTER;
2264 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2265 return S_FALSE;
2267 return S_OK;
2270 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface,
2271 const GUID *pFormat) {
2272 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2274 if (!pFormat)
2275 return E_POINTER;
2277 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2279 if (This->state != State_Stopped)
2280 return VFW_E_WRONG_STATE;
2282 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2284 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2285 return E_INVALIDARG;
2288 return S_OK;
2291 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2293 HRESULT hr;
2294 LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2296 hr = IMediaSeeking_GetDuration(seek, &duration);
2297 if (FAILED(hr))
2298 return hr;
2300 /* FIXME: Minimum or maximum duration? Assuming minimum */
2301 if (duration > 0 && *pdur < duration)
2302 *pdur = duration;
2304 return hr;
2307 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface,
2308 LONGLONG *pDuration) {
2309 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2310 HRESULT hr;
2312 TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2314 if (!pDuration)
2315 return E_POINTER;
2317 EnterCriticalSection(&This->cs);
2318 *pDuration = -1;
2319 hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2320 LeaveCriticalSection(&This->cs);
2322 TRACE("--->%08x\n", hr);
2323 return hr;
2326 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface,
2327 LONGLONG *pStop) {
2328 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2329 HRESULT hr = S_OK;
2331 TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2333 if (!pStop)
2334 return E_POINTER;
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;
2343 LeaveCriticalSection(&This->cs);
2345 return hr;
2348 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface,
2349 LONGLONG *pCurrent) {
2350 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2351 LONGLONG time = 0;
2353 if (!pCurrent)
2354 return E_POINTER;
2356 EnterCriticalSection(&This->cs);
2357 if (This->state == State_Running && This->refClock)
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;
2366 else
2367 *pCurrent = This->position;
2368 LeaveCriticalSection(&This->cs);
2370 TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2372 return S_OK;
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);
2382 FIXME("(%p/%p)->(%p, %p, 0x%s, %p): stub !!!\n", This, iface, pTarget,
2383 pTargetFormat, wine_dbgstr_longlong(Source), pSourceFormat);
2385 return S_OK;
2388 struct pos_args {
2389 LONGLONG* current, *stop;
2390 DWORD curflags, stopflags;
2393 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2395 struct pos_args *args = (void*)pargs;
2397 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
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;
2410 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
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")));
2416 if ((dwCurrentFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2418 This->position = *pCurrent;
2420 else if ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2421 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
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");
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);
2434 if (This->refClock && ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning))
2436 /* Update start time, prevents weird jumps */
2437 IReferenceClock_GetTime(This->refClock, &This->start_time);
2439 LeaveCriticalSection(&This->cs);
2441 return hr;
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;
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);
2455 return hr;
2458 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface,
2459 LONGLONG *pEarliest,
2460 LONGLONG *pLatest) {
2461 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2463 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2465 return S_OK;
2468 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface,
2469 double dRate) {
2470 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2472 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2474 return S_OK;
2477 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface,
2478 double *pdRate) {
2479 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2481 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2483 return S_OK;
2486 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface,
2487 LONGLONG *pllPreroll) {
2488 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2490 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2492 return S_OK;
2496 static const IMediaSeekingVtbl IMediaSeeking_VTable =
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
2520 /*** IUnknown methods ***/
2521 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj){
2522 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaPosition_vtbl, iface);
2524 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2526 return Filtergraph_QueryInterface(This, riid, ppvObj);
2529 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface){
2530 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaPosition_vtbl, iface);
2532 TRACE("(%p/%p)->()\n", This, iface);
2534 return Filtergraph_AddRef(This);
2537 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface){
2538 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaPosition_vtbl, iface);
2540 TRACE("(%p/%p)->()\n", This, iface);
2542 return Filtergraph_Release(This);
2545 /*** IDispatch methods ***/
2546 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo){
2547 FIXME("(%p) stub!\n", iface);
2548 return E_NOTIMPL;
2551 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo){
2552 FIXME("(%p) stub!\n", iface);
2553 return E_NOTIMPL;
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;
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;
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;
2572 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime){
2573 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaPosition_vtbl, iface);
2574 LONGLONG reftime = llTime;
2576 return IMediaSeeking_SetPositions((IMediaSeeking *)&This->IMediaSeeking_vtbl, &reftime, AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2579 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime){
2580 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2581 return E_NOTIMPL;
2584 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime){
2585 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2586 return E_NOTIMPL;
2589 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime){
2590 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2591 return E_NOTIMPL;
2594 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime){
2595 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2596 return E_NOTIMPL;
2599 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime){
2600 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2601 return E_NOTIMPL;
2604 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate){
2605 FIXME("(%p)->(%f) stub!\n", iface, dRate);
2606 return E_NOTIMPL;
2609 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate){
2610 FIXME("(%p)->(%p) stub!\n", iface, pdRate);
2611 return E_NOTIMPL;
2614 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward){
2615 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2616 return E_NOTIMPL;
2619 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward){
2620 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2621 return E_NOTIMPL;
2625 static const IMediaPositionVtbl IMediaPosition_VTable =
2627 MediaPosition_QueryInterface,
2628 MediaPosition_AddRef,
2629 MediaPosition_Release,
2630 MediaPosition_GetTypeInfoCount,
2631 MediaPosition_GetTypeInfo,
2632 MediaPosition_GetIDsOfNames,
2633 MediaPosition_Invoke,
2634 MediaPosition_get_Duration,
2635 MediaPosition_put_CurrentPosition,
2636 MediaPosition_get_CurrentPosition,
2637 MediaPosition_get_StopTime,
2638 MediaPosition_put_StopTime,
2639 MediaPosition_get_PrerollTime,
2640 MediaPosition_put_PrerollTime,
2641 MediaPosition_put_Rate,
2642 MediaPosition_get_Rate,
2643 MediaPosition_CanSeekForward,
2644 MediaPosition_CanSeekBackward
2647 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2649 HRESULT hr = E_NOINTERFACE;
2650 int i;
2651 int entry;
2653 /* Check if the interface type is already registered */
2654 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2655 if (riid == pGraph->ItfCacheEntries[entry].riid)
2657 if (pGraph->ItfCacheEntries[entry].iface)
2659 /* Return the interface if available */
2660 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2661 return S_OK;
2663 break;
2666 if (entry >= MAX_ITF_CACHE_ENTRIES)
2668 FIXME("Not enough space to store interface in the cache\n");
2669 return E_OUTOFMEMORY;
2672 /* Find a filter supporting the requested interface */
2673 for (i = 0; i < pGraph->nFilters; i++)
2675 hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2676 if (hr == S_OK)
2678 pGraph->ItfCacheEntries[entry].riid = riid;
2679 pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2680 pGraph->ItfCacheEntries[entry].iface = (IUnknown*)*ppvObj;
2681 if (entry >= pGraph->nItfCacheEntries)
2682 pGraph->nItfCacheEntries++;
2683 return S_OK;
2685 if (hr != E_NOINTERFACE)
2686 return hr;
2689 return hr;
2692 /*** IUnknown methods ***/
2693 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface,
2694 REFIID riid,
2695 LPVOID*ppvObj) {
2696 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2698 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2700 return Filtergraph_QueryInterface(This, riid, ppvObj);
2703 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface) {
2704 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2706 TRACE("(%p/%p)->()\n", This, iface);
2708 return Filtergraph_AddRef(This);
2711 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface) {
2712 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2714 TRACE("(%p/%p)->()\n", This, iface);
2716 return Filtergraph_Release(This);
2719 /*** IDispatch methods ***/
2720 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface,
2721 UINT*pctinfo) {
2722 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2723 IBasicAudio* pBasicAudio;
2724 HRESULT hr;
2726 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
2728 EnterCriticalSection(&This->cs);
2730 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2732 if (hr == S_OK)
2733 hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
2735 LeaveCriticalSection(&This->cs);
2737 return hr;
2740 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface,
2741 UINT iTInfo,
2742 LCID lcid,
2743 ITypeInfo**ppTInfo) {
2744 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2745 IBasicAudio* pBasicAudio;
2746 HRESULT hr;
2748 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
2750 EnterCriticalSection(&This->cs);
2752 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2754 if (hr == S_OK)
2755 hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
2757 LeaveCriticalSection(&This->cs);
2759 return hr;
2762 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface,
2763 REFIID riid,
2764 LPOLESTR*rgszNames,
2765 UINT cNames,
2766 LCID lcid,
2767 DISPID*rgDispId) {
2768 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2769 IBasicAudio* pBasicAudio;
2770 HRESULT hr;
2772 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
2774 EnterCriticalSection(&This->cs);
2776 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2778 if (hr == S_OK)
2779 hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
2781 LeaveCriticalSection(&This->cs);
2783 return hr;
2786 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface,
2787 DISPID dispIdMember,
2788 REFIID riid,
2789 LCID lcid,
2790 WORD wFlags,
2791 DISPPARAMS*pDispParams,
2792 VARIANT*pVarResult,
2793 EXCEPINFO*pExepInfo,
2794 UINT*puArgErr) {
2795 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2796 IBasicAudio* pBasicAudio;
2797 HRESULT hr;
2799 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);
2801 EnterCriticalSection(&This->cs);
2803 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2805 if (hr == S_OK)
2806 hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
2808 LeaveCriticalSection(&This->cs);
2810 return hr;
2813 /*** IBasicAudio methods ***/
2814 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface,
2815 long lVolume) {
2816 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2817 IBasicAudio* pBasicAudio;
2818 HRESULT hr;
2820 TRACE("(%p/%p)->(%ld)\n", This, iface, lVolume);
2822 EnterCriticalSection(&This->cs);
2824 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2826 if (hr == S_OK)
2827 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
2829 LeaveCriticalSection(&This->cs);
2831 return hr;
2834 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface,
2835 long *plVolume) {
2836 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2837 IBasicAudio* pBasicAudio;
2838 HRESULT hr;
2840 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
2842 EnterCriticalSection(&This->cs);
2844 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2846 if (hr == S_OK)
2847 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
2849 LeaveCriticalSection(&This->cs);
2851 return hr;
2854 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface,
2855 long lBalance) {
2856 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2857 IBasicAudio* pBasicAudio;
2858 HRESULT hr;
2860 TRACE("(%p/%p)->(%ld)\n", This, iface, lBalance);
2862 EnterCriticalSection(&This->cs);
2864 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2866 if (hr == S_OK)
2867 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
2869 LeaveCriticalSection(&This->cs);
2871 return hr;
2874 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface,
2875 long *plBalance) {
2876 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2877 IBasicAudio* pBasicAudio;
2878 HRESULT hr;
2880 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
2882 EnterCriticalSection(&This->cs);
2884 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2886 if (hr == S_OK)
2887 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
2889 LeaveCriticalSection(&This->cs);
2891 return hr;
2894 static const IBasicAudioVtbl IBasicAudio_VTable =
2896 BasicAudio_QueryInterface,
2897 BasicAudio_AddRef,
2898 BasicAudio_Release,
2899 BasicAudio_GetTypeInfoCount,
2900 BasicAudio_GetTypeInfo,
2901 BasicAudio_GetIDsOfNames,
2902 BasicAudio_Invoke,
2903 BasicAudio_put_Volume,
2904 BasicAudio_get_Volume,
2905 BasicAudio_put_Balance,
2906 BasicAudio_get_Balance
2909 /*** IUnknown methods ***/
2910 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface,
2911 REFIID riid,
2912 LPVOID*ppvObj) {
2913 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2915 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2917 return Filtergraph_QueryInterface(This, riid, ppvObj);
2920 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface) {
2921 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2923 TRACE("(%p/%p)->()\n", This, iface);
2925 return Filtergraph_AddRef(This);
2928 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface) {
2929 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2931 TRACE("(%p/%p)->()\n", This, iface);
2933 return Filtergraph_Release(This);
2936 /*** IDispatch methods ***/
2937 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface,
2938 UINT*pctinfo) {
2939 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2940 IBasicVideo* pBasicVideo;
2941 HRESULT hr;
2943 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
2945 EnterCriticalSection(&This->cs);
2947 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2949 if (hr == S_OK)
2950 hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
2952 LeaveCriticalSection(&This->cs);
2954 return hr;
2957 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface,
2958 UINT iTInfo,
2959 LCID lcid,
2960 ITypeInfo**ppTInfo) {
2961 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2962 IBasicVideo* pBasicVideo;
2963 HRESULT hr;
2965 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
2967 EnterCriticalSection(&This->cs);
2969 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2971 if (hr == S_OK)
2972 hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
2974 LeaveCriticalSection(&This->cs);
2976 return hr;
2979 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface,
2980 REFIID riid,
2981 LPOLESTR*rgszNames,
2982 UINT cNames,
2983 LCID lcid,
2984 DISPID*rgDispId) {
2985 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2986 IBasicVideo* pBasicVideo;
2987 HRESULT hr;
2989 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
2991 EnterCriticalSection(&This->cs);
2993 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2995 if (hr == S_OK)
2996 hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
2998 LeaveCriticalSection(&This->cs);
3000 return hr;
3003 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface,
3004 DISPID dispIdMember,
3005 REFIID riid,
3006 LCID lcid,
3007 WORD wFlags,
3008 DISPPARAMS*pDispParams,
3009 VARIANT*pVarResult,
3010 EXCEPINFO*pExepInfo,
3011 UINT*puArgErr) {
3012 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3013 IBasicVideo* pBasicVideo;
3014 HRESULT hr;
3016 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);
3018 EnterCriticalSection(&This->cs);
3020 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3022 if (hr == S_OK)
3023 hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3025 LeaveCriticalSection(&This->cs);
3027 return hr;
3030 /*** IBasicVideo methods ***/
3031 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface,
3032 REFTIME *pAvgTimePerFrame) {
3033 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3034 IBasicVideo* pBasicVideo;
3035 HRESULT hr;
3037 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3039 EnterCriticalSection(&This->cs);
3041 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3043 if (hr == S_OK)
3044 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3046 LeaveCriticalSection(&This->cs);
3048 return hr;
3051 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface,
3052 long *pBitRate) {
3053 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3054 IBasicVideo* pBasicVideo;
3055 HRESULT hr;
3057 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3059 EnterCriticalSection(&This->cs);
3061 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3063 if (hr == S_OK)
3064 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3066 LeaveCriticalSection(&This->cs);
3068 return hr;
3071 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface,
3072 long *pBitErrorRate) {
3073 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3074 IBasicVideo* pBasicVideo;
3075 HRESULT hr;
3077 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3079 EnterCriticalSection(&This->cs);
3081 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3083 if (hr == S_OK)
3084 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3086 LeaveCriticalSection(&This->cs);
3088 return hr;
3091 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface,
3092 long *pVideoWidth) {
3093 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3094 IBasicVideo* pBasicVideo;
3095 HRESULT hr;
3097 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3099 EnterCriticalSection(&This->cs);
3101 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3103 if (hr == S_OK)
3104 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3106 LeaveCriticalSection(&This->cs);
3108 return hr;
3111 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface,
3112 long *pVideoHeight) {
3113 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3114 IBasicVideo* pBasicVideo;
3115 HRESULT hr;
3117 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3119 EnterCriticalSection(&This->cs);
3121 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3123 if (hr == S_OK)
3124 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3126 LeaveCriticalSection(&This->cs);
3128 return hr;
3131 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface,
3132 long SourceLeft) {
3133 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3134 IBasicVideo* pBasicVideo;
3135 HRESULT hr;
3137 TRACE("(%p/%p)->(%ld)\n", This, iface, SourceLeft);
3139 EnterCriticalSection(&This->cs);
3141 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3143 if (hr == S_OK)
3144 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3146 LeaveCriticalSection(&This->cs);
3148 return hr;
3151 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface,
3152 long *pSourceLeft) {
3153 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3154 IBasicVideo* pBasicVideo;
3155 HRESULT hr;
3157 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3159 EnterCriticalSection(&This->cs);
3161 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3163 if (hr == S_OK)
3164 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3166 LeaveCriticalSection(&This->cs);
3168 return hr;
3171 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface,
3172 long SourceWidth) {
3173 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3174 IBasicVideo* pBasicVideo;
3175 HRESULT hr;
3177 TRACE("(%p/%p)->(%ld)\n", This, iface, SourceWidth);
3179 EnterCriticalSection(&This->cs);
3181 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3183 if (hr == S_OK)
3184 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3186 LeaveCriticalSection(&This->cs);
3188 return hr;
3191 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface,
3192 long *pSourceWidth) {
3193 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3194 IBasicVideo* pBasicVideo;
3195 HRESULT hr;
3197 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3199 EnterCriticalSection(&This->cs);
3201 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3203 if (hr == S_OK)
3204 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3206 LeaveCriticalSection(&This->cs);
3208 return hr;
3211 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface,
3212 long SourceTop) {
3213 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3214 IBasicVideo* pBasicVideo;
3215 HRESULT hr;
3217 TRACE("(%p/%p)->(%ld)\n", This, iface, SourceTop);
3219 EnterCriticalSection(&This->cs);
3221 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3223 if (hr == S_OK)
3224 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3226 LeaveCriticalSection(&This->cs);
3228 return hr;
3231 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface,
3232 long *pSourceTop) {
3233 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3234 IBasicVideo* pBasicVideo;
3235 HRESULT hr;
3237 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3239 EnterCriticalSection(&This->cs);
3241 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3243 if (hr == S_OK)
3244 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3246 LeaveCriticalSection(&This->cs);
3248 return hr;
3251 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface,
3252 long SourceHeight) {
3253 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3254 IBasicVideo* pBasicVideo;
3255 HRESULT hr;
3257 TRACE("(%p/%p)->(%ld)\n", This, iface, SourceHeight);
3259 EnterCriticalSection(&This->cs);
3261 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3263 if (hr == S_OK)
3264 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3266 LeaveCriticalSection(&This->cs);
3268 return hr;
3271 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface,
3272 long *pSourceHeight) {
3273 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3274 IBasicVideo* pBasicVideo;
3275 HRESULT hr;
3277 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3279 EnterCriticalSection(&This->cs);
3281 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3283 if (hr == S_OK)
3284 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3286 LeaveCriticalSection(&This->cs);
3288 return hr;
3291 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface,
3292 long DestinationLeft) {
3293 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3294 IBasicVideo* pBasicVideo;
3295 HRESULT hr;
3297 TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationLeft);
3299 EnterCriticalSection(&This->cs);
3301 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3303 if (hr == S_OK)
3304 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3306 LeaveCriticalSection(&This->cs);
3308 return hr;
3311 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface,
3312 long *pDestinationLeft) {
3313 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3314 IBasicVideo* pBasicVideo;
3315 HRESULT hr;
3317 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3319 EnterCriticalSection(&This->cs);
3321 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3323 if (hr == S_OK)
3324 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3326 LeaveCriticalSection(&This->cs);
3328 return hr;
3331 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface,
3332 long DestinationWidth) {
3333 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3334 IBasicVideo* pBasicVideo;
3335 HRESULT hr;
3337 TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationWidth);
3339 EnterCriticalSection(&This->cs);
3341 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3343 if (hr == S_OK)
3344 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3346 LeaveCriticalSection(&This->cs);
3348 return hr;
3351 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface,
3352 long *pDestinationWidth) {
3353 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3354 IBasicVideo* pBasicVideo;
3355 HRESULT hr;
3357 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3359 EnterCriticalSection(&This->cs);
3361 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3363 if (hr == S_OK)
3364 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3366 LeaveCriticalSection(&This->cs);
3368 return hr;
3371 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface,
3372 long DestinationTop) {
3373 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3374 IBasicVideo* pBasicVideo;
3375 HRESULT hr;
3377 TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationTop);
3379 EnterCriticalSection(&This->cs);
3381 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3383 if (hr == S_OK)
3384 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3386 LeaveCriticalSection(&This->cs);
3388 return hr;
3391 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface,
3392 long *pDestinationTop) {
3393 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3394 IBasicVideo* pBasicVideo;
3395 HRESULT hr;
3397 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3399 EnterCriticalSection(&This->cs);
3401 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3403 if (hr == S_OK)
3404 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3406 LeaveCriticalSection(&This->cs);
3408 return hr;
3411 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface,
3412 long DestinationHeight) {
3413 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3414 IBasicVideo* pBasicVideo;
3415 HRESULT hr;
3417 TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationHeight);
3419 EnterCriticalSection(&This->cs);
3421 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3423 if (hr == S_OK)
3424 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3426 LeaveCriticalSection(&This->cs);
3428 return hr;
3431 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3432 long *pDestinationHeight) {
3433 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3434 IBasicVideo* pBasicVideo;
3435 HRESULT hr;
3437 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3439 EnterCriticalSection(&This->cs);
3441 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3443 if (hr == S_OK)
3444 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3446 LeaveCriticalSection(&This->cs);
3448 return hr;
3451 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface,
3452 long Left,
3453 long Top,
3454 long Width,
3455 long Height) {
3456 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3457 IBasicVideo* pBasicVideo;
3458 HRESULT hr;
3460 TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
3462 EnterCriticalSection(&This->cs);
3464 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3466 if (hr == S_OK)
3467 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3469 LeaveCriticalSection(&This->cs);
3471 return hr;
3474 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface,
3475 long *pLeft,
3476 long *pTop,
3477 long *pWidth,
3478 long *pHeight) {
3479 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3480 IBasicVideo* pBasicVideo;
3481 HRESULT hr;
3483 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3485 EnterCriticalSection(&This->cs);
3487 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3489 if (hr == S_OK)
3490 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3492 LeaveCriticalSection(&This->cs);
3494 return hr;
3497 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface) {
3498 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3499 IBasicVideo* pBasicVideo;
3500 HRESULT hr;
3502 TRACE("(%p/%p)->()\n", This, iface);
3504 EnterCriticalSection(&This->cs);
3506 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3508 if (hr == S_OK)
3509 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3511 LeaveCriticalSection(&This->cs);
3513 return hr;
3516 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface,
3517 long Left,
3518 long Top,
3519 long Width,
3520 long Height) {
3521 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3522 IBasicVideo* pBasicVideo;
3523 HRESULT hr;
3525 TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
3527 EnterCriticalSection(&This->cs);
3529 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3531 if (hr == S_OK)
3532 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3534 LeaveCriticalSection(&This->cs);
3536 return hr;
3539 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface,
3540 long *pLeft,
3541 long *pTop,
3542 long *pWidth,
3543 long *pHeight) {
3544 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3545 IBasicVideo* pBasicVideo;
3546 HRESULT hr;
3548 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3550 EnterCriticalSection(&This->cs);
3552 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3554 if (hr == S_OK)
3555 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3557 LeaveCriticalSection(&This->cs);
3559 return hr;
3562 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface) {
3563 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3564 IBasicVideo* pBasicVideo;
3565 HRESULT hr;
3567 TRACE("(%p/%p)->()\n", This, iface);
3569 EnterCriticalSection(&This->cs);
3571 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3573 if (hr == S_OK)
3574 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3576 LeaveCriticalSection(&This->cs);
3578 return hr;
3581 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface,
3582 long *pWidth,
3583 long *pHeight) {
3584 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3585 IBasicVideo* pBasicVideo;
3586 HRESULT hr;
3588 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3590 EnterCriticalSection(&This->cs);
3592 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3594 if (hr == S_OK)
3595 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3597 LeaveCriticalSection(&This->cs);
3599 return hr;
3602 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface,
3603 long StartIndex,
3604 long Entries,
3605 long *pRetrieved,
3606 long *pPalette) {
3607 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3608 IBasicVideo* pBasicVideo;
3609 HRESULT hr;
3611 TRACE("(%p/%p)->(%ld, %ld, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3613 EnterCriticalSection(&This->cs);
3615 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3617 if (hr == S_OK)
3618 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3620 LeaveCriticalSection(&This->cs);
3622 return hr;
3625 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface,
3626 long *pBufferSize,
3627 long *pDIBImage) {
3628 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3629 IBasicVideo* pBasicVideo;
3630 HRESULT hr;
3632 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3634 EnterCriticalSection(&This->cs);
3636 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3638 if (hr == S_OK)
3639 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3641 LeaveCriticalSection(&This->cs);
3643 return hr;
3646 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface) {
3647 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3648 IBasicVideo* pBasicVideo;
3649 HRESULT hr;
3651 TRACE("(%p/%p)->()\n", This, iface);
3653 EnterCriticalSection(&This->cs);
3655 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3657 if (hr == S_OK)
3658 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3660 LeaveCriticalSection(&This->cs);
3662 return hr;
3665 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface) {
3666 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3667 IBasicVideo* pBasicVideo;
3668 HRESULT hr;
3670 TRACE("(%p/%p)->()\n", This, iface);
3672 EnterCriticalSection(&This->cs);
3674 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3676 if (hr == S_OK)
3677 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3679 LeaveCriticalSection(&This->cs);
3681 return hr;
3684 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX, LONG *plAspectY) {
3685 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3686 IBasicVideo2 *pBasicVideo2;
3687 HRESULT hr;
3689 TRACE("(%p/%p)->()\n", This, iface);
3691 EnterCriticalSection(&This->cs);
3693 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3695 if (hr == S_OK)
3696 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3698 LeaveCriticalSection(&This->cs);
3700 return hr;
3703 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3705 BasicVideo_QueryInterface,
3706 BasicVideo_AddRef,
3707 BasicVideo_Release,
3708 BasicVideo_GetTypeInfoCount,
3709 BasicVideo_GetTypeInfo,
3710 BasicVideo_GetIDsOfNames,
3711 BasicVideo_Invoke,
3712 BasicVideo_get_AvgTimePerFrame,
3713 BasicVideo_get_BitRate,
3714 BasicVideo_get_BitErrorRate,
3715 BasicVideo_get_VideoWidth,
3716 BasicVideo_get_VideoHeight,
3717 BasicVideo_put_SourceLeft,
3718 BasicVideo_get_SourceLeft,
3719 BasicVideo_put_SourceWidth,
3720 BasicVideo_get_SourceWidth,
3721 BasicVideo_put_SourceTop,
3722 BasicVideo_get_SourceTop,
3723 BasicVideo_put_SourceHeight,
3724 BasicVideo_get_SourceHeight,
3725 BasicVideo_put_DestinationLeft,
3726 BasicVideo_get_DestinationLeft,
3727 BasicVideo_put_DestinationWidth,
3728 BasicVideo_get_DestinationWidth,
3729 BasicVideo_put_DestinationTop,
3730 BasicVideo_get_DestinationTop,
3731 BasicVideo_put_DestinationHeight,
3732 BasicVideo_get_DestinationHeight,
3733 BasicVideo_SetSourcePosition,
3734 BasicVideo_GetSourcePosition,
3735 BasicVideo_SetDefaultSourcePosition,
3736 BasicVideo_SetDestinationPosition,
3737 BasicVideo_GetDestinationPosition,
3738 BasicVideo_SetDefaultDestinationPosition,
3739 BasicVideo_GetVideoSize,
3740 BasicVideo_GetVideoPaletteEntries,
3741 BasicVideo_GetCurrentImage,
3742 BasicVideo_IsUsingDefaultSource,
3743 BasicVideo_IsUsingDefaultDestination,
3744 BasicVideo2_GetPreferredAspectRatio
3748 /*** IUnknown methods ***/
3749 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface,
3750 REFIID riid,
3751 LPVOID*ppvObj) {
3752 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3754 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3756 return Filtergraph_QueryInterface(This, riid, ppvObj);
3759 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface) {
3760 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3762 TRACE("(%p/%p)->()\n", This, iface);
3764 return Filtergraph_AddRef(This);
3767 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface) {
3768 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3770 TRACE("(%p/%p)->()\n", This, iface);
3772 return Filtergraph_Release(This);
3775 /*** IDispatch methods ***/
3776 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface,
3777 UINT*pctinfo) {
3778 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3779 IVideoWindow* pVideoWindow;
3780 HRESULT hr;
3782 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3784 EnterCriticalSection(&This->cs);
3786 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3788 if (hr == S_OK)
3789 hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
3791 LeaveCriticalSection(&This->cs);
3793 return hr;
3796 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface,
3797 UINT iTInfo,
3798 LCID lcid,
3799 ITypeInfo**ppTInfo) {
3800 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3801 IVideoWindow* pVideoWindow;
3802 HRESULT hr;
3804 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3806 EnterCriticalSection(&This->cs);
3808 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3810 if (hr == S_OK)
3811 hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
3813 LeaveCriticalSection(&This->cs);
3815 return hr;
3818 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface,
3819 REFIID riid,
3820 LPOLESTR*rgszNames,
3821 UINT cNames,
3822 LCID lcid,
3823 DISPID*rgDispId) {
3824 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3825 IVideoWindow* pVideoWindow;
3826 HRESULT hr;
3828 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3830 EnterCriticalSection(&This->cs);
3832 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3834 if (hr == S_OK)
3835 hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
3837 LeaveCriticalSection(&This->cs);
3839 return hr;
3842 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface,
3843 DISPID dispIdMember,
3844 REFIID riid,
3845 LCID lcid,
3846 WORD wFlags,
3847 DISPPARAMS*pDispParams,
3848 VARIANT*pVarResult,
3849 EXCEPINFO*pExepInfo,
3850 UINT*puArgErr) {
3851 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3852 IVideoWindow* pVideoWindow;
3853 HRESULT hr;
3855 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);
3857 EnterCriticalSection(&This->cs);
3859 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3861 if (hr == S_OK)
3862 hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3864 LeaveCriticalSection(&This->cs);
3866 return hr;
3870 /*** IVideoWindow methods ***/
3871 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface,
3872 BSTR strCaption) {
3873 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3874 IVideoWindow* pVideoWindow;
3875 HRESULT hr;
3877 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
3879 EnterCriticalSection(&This->cs);
3881 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3883 if (hr == S_OK)
3884 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
3886 LeaveCriticalSection(&This->cs);
3888 return hr;
3891 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface,
3892 BSTR *strCaption) {
3893 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3894 IVideoWindow* pVideoWindow;
3895 HRESULT hr;
3897 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
3899 EnterCriticalSection(&This->cs);
3901 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3903 if (hr == S_OK)
3904 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
3906 LeaveCriticalSection(&This->cs);
3908 return hr;
3911 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface,
3912 long WindowStyle) {
3913 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3914 IVideoWindow* pVideoWindow;
3915 HRESULT hr;
3917 TRACE("(%p/%p)->(%ld)\n", This, iface, WindowStyle);
3919 EnterCriticalSection(&This->cs);
3921 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3923 if (hr == S_OK)
3924 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
3926 LeaveCriticalSection(&This->cs);
3928 return hr;
3931 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface,
3932 long *WindowStyle) {
3933 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3934 IVideoWindow* pVideoWindow;
3935 HRESULT hr;
3937 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
3939 EnterCriticalSection(&This->cs);
3941 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3943 if (hr == S_OK)
3944 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
3946 LeaveCriticalSection(&This->cs);
3948 return hr;
3951 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface,
3952 long WindowStyleEx) {
3953 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3954 IVideoWindow* pVideoWindow;
3955 HRESULT hr;
3957 TRACE("(%p/%p)->(%ld)\n", This, iface, WindowStyleEx);
3959 EnterCriticalSection(&This->cs);
3961 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3963 if (hr == S_OK)
3964 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
3966 LeaveCriticalSection(&This->cs);
3968 return hr;
3971 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface,
3972 long *WindowStyleEx) {
3973 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3974 IVideoWindow* pVideoWindow;
3975 HRESULT hr;
3977 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
3979 EnterCriticalSection(&This->cs);
3981 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3983 if (hr == S_OK)
3984 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
3986 LeaveCriticalSection(&This->cs);
3988 return hr;
3991 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface,
3992 long AutoShow) {
3993 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3994 IVideoWindow* pVideoWindow;
3995 HRESULT hr;
3997 TRACE("(%p/%p)->(%ld)\n", This, iface, AutoShow);
3999 EnterCriticalSection(&This->cs);
4001 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4003 if (hr == S_OK)
4004 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4006 LeaveCriticalSection(&This->cs);
4008 return hr;
4011 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface,
4012 long *AutoShow) {
4013 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4014 IVideoWindow* pVideoWindow;
4015 HRESULT hr;
4017 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4019 EnterCriticalSection(&This->cs);
4021 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4023 if (hr == S_OK)
4024 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4026 LeaveCriticalSection(&This->cs);
4028 return hr;
4031 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface,
4032 long WindowState) {
4033 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4034 IVideoWindow* pVideoWindow;
4035 HRESULT hr;
4037 TRACE("(%p/%p)->(%ld)\n", This, iface, WindowState);
4039 EnterCriticalSection(&This->cs);
4041 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4043 if (hr == S_OK)
4044 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4046 LeaveCriticalSection(&This->cs);
4048 return hr;
4051 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface,
4052 long *WindowState) {
4053 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4054 IVideoWindow* pVideoWindow;
4055 HRESULT hr;
4057 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4059 EnterCriticalSection(&This->cs);
4061 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4063 if (hr == S_OK)
4064 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4066 LeaveCriticalSection(&This->cs);
4068 return hr;
4071 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface,
4072 long BackgroundPalette) {
4073 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4074 IVideoWindow* pVideoWindow;
4075 HRESULT hr;
4077 TRACE("(%p/%p)->(%ld)\n", This, iface, BackgroundPalette);
4079 EnterCriticalSection(&This->cs);
4081 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4083 if (hr == S_OK)
4084 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4086 LeaveCriticalSection(&This->cs);
4088 return hr;
4091 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4092 long *pBackgroundPalette) {
4093 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4094 IVideoWindow* pVideoWindow;
4095 HRESULT hr;
4097 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4099 EnterCriticalSection(&This->cs);
4101 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4103 if (hr == S_OK)
4104 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4106 LeaveCriticalSection(&This->cs);
4108 return hr;
4111 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface,
4112 long Visible) {
4113 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4114 IVideoWindow* pVideoWindow;
4115 HRESULT hr;
4117 TRACE("(%p/%p)->(%ld)\n", This, iface, Visible);
4119 EnterCriticalSection(&This->cs);
4121 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4123 if (hr == S_OK)
4124 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4126 LeaveCriticalSection(&This->cs);
4128 return hr;
4131 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface,
4132 long *pVisible) {
4133 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4134 IVideoWindow* pVideoWindow;
4135 HRESULT hr;
4137 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4139 EnterCriticalSection(&This->cs);
4141 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4143 if (hr == S_OK)
4144 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4146 LeaveCriticalSection(&This->cs);
4148 return hr;
4151 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface,
4152 long Left) {
4153 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4154 IVideoWindow* pVideoWindow;
4155 HRESULT hr;
4157 TRACE("(%p/%p)->(%ld)\n", This, iface, Left);
4159 EnterCriticalSection(&This->cs);
4161 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4163 if (hr == S_OK)
4164 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4166 LeaveCriticalSection(&This->cs);
4168 return hr;
4171 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface,
4172 long *pLeft) {
4173 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4174 IVideoWindow* pVideoWindow;
4175 HRESULT hr;
4177 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4179 EnterCriticalSection(&This->cs);
4181 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4183 if (hr == S_OK)
4184 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4186 LeaveCriticalSection(&This->cs);
4188 return hr;
4191 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface,
4192 long Width) {
4193 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4194 IVideoWindow* pVideoWindow;
4195 HRESULT hr;
4197 TRACE("(%p/%p)->(%ld)\n", This, iface, Width);
4199 EnterCriticalSection(&This->cs);
4201 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4203 if (hr == S_OK)
4204 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4206 LeaveCriticalSection(&This->cs);
4208 return hr;
4211 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface,
4212 long *pWidth) {
4213 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4214 IVideoWindow* pVideoWindow;
4215 HRESULT hr;
4217 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4219 EnterCriticalSection(&This->cs);
4221 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4223 if (hr == S_OK)
4224 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4226 LeaveCriticalSection(&This->cs);
4228 return hr;
4231 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface,
4232 long Top) {
4233 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4234 IVideoWindow* pVideoWindow;
4235 HRESULT hr;
4237 TRACE("(%p/%p)->(%ld)\n", This, iface, Top);
4239 EnterCriticalSection(&This->cs);
4241 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4243 if (hr == S_OK)
4244 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4246 LeaveCriticalSection(&This->cs);
4248 return hr;
4251 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface,
4252 long *pTop) {
4253 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4254 IVideoWindow* pVideoWindow;
4255 HRESULT hr;
4257 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4259 EnterCriticalSection(&This->cs);
4261 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4263 if (hr == S_OK)
4264 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4266 LeaveCriticalSection(&This->cs);
4268 return hr;
4271 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface,
4272 long Height) {
4273 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4274 IVideoWindow* pVideoWindow;
4275 HRESULT hr;
4277 TRACE("(%p/%p)->(%ld)\n", This, iface, Height);
4279 EnterCriticalSection(&This->cs);
4281 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4283 if (hr == S_OK)
4284 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4286 LeaveCriticalSection(&This->cs);
4288 return hr;
4291 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface,
4292 long *pHeight) {
4293 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4294 IVideoWindow* pVideoWindow;
4295 HRESULT hr;
4297 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4299 EnterCriticalSection(&This->cs);
4301 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4303 if (hr == S_OK)
4304 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4306 LeaveCriticalSection(&This->cs);
4308 return hr;
4311 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface,
4312 OAHWND Owner) {
4313 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4314 IVideoWindow* pVideoWindow;
4315 HRESULT hr;
4317 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4319 EnterCriticalSection(&This->cs);
4321 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4323 if (hr == S_OK)
4324 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4326 LeaveCriticalSection(&This->cs);
4328 return hr;
4331 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface,
4332 OAHWND *Owner) {
4333 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4334 IVideoWindow* pVideoWindow;
4335 HRESULT hr;
4337 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4339 EnterCriticalSection(&This->cs);
4341 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4343 if (hr == S_OK)
4344 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4346 LeaveCriticalSection(&This->cs);
4348 return hr;
4351 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface,
4352 OAHWND Drain) {
4353 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4354 IVideoWindow* pVideoWindow;
4355 HRESULT hr;
4357 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4359 EnterCriticalSection(&This->cs);
4361 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4363 if (hr == S_OK)
4364 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4366 LeaveCriticalSection(&This->cs);
4368 return hr;
4371 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface,
4372 OAHWND *Drain) {
4373 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4374 IVideoWindow* pVideoWindow;
4375 HRESULT hr;
4377 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4379 EnterCriticalSection(&This->cs);
4381 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4383 if (hr == S_OK)
4384 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4386 LeaveCriticalSection(&This->cs);
4388 return hr;
4391 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface,
4392 long *Color) {
4393 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4394 IVideoWindow* pVideoWindow;
4395 HRESULT hr;
4397 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4399 EnterCriticalSection(&This->cs);
4401 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4403 if (hr == S_OK)
4404 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4406 LeaveCriticalSection(&This->cs);
4408 return hr;
4411 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface,
4412 long Color) {
4413 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4414 IVideoWindow* pVideoWindow;
4415 HRESULT hr;
4417 TRACE("(%p/%p)->(%ld)\n", This, iface, Color);
4419 EnterCriticalSection(&This->cs);
4421 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4423 if (hr == S_OK)
4424 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4426 LeaveCriticalSection(&This->cs);
4428 return hr;
4431 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface,
4432 long *FullScreenMode) {
4433 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4434 IVideoWindow* pVideoWindow;
4435 HRESULT hr;
4437 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4439 EnterCriticalSection(&This->cs);
4441 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4443 if (hr == S_OK)
4444 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4446 LeaveCriticalSection(&This->cs);
4448 return hr;
4451 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface,
4452 long FullScreenMode) {
4453 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4454 IVideoWindow* pVideoWindow;
4455 HRESULT hr;
4457 TRACE("(%p/%p)->(%ld)\n", This, iface, FullScreenMode);
4459 EnterCriticalSection(&This->cs);
4461 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4463 if (hr == S_OK)
4464 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4466 LeaveCriticalSection(&This->cs);
4468 return hr;
4471 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface,
4472 long Focus) {
4473 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4474 IVideoWindow* pVideoWindow;
4475 HRESULT hr;
4477 TRACE("(%p/%p)->(%ld)\n", This, iface, Focus);
4479 EnterCriticalSection(&This->cs);
4481 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4483 if (hr == S_OK)
4484 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4486 LeaveCriticalSection(&This->cs);
4488 return hr;
4491 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface,
4492 OAHWND hwnd,
4493 long uMsg,
4494 LONG_PTR wParam,
4495 LONG_PTR lParam) {
4496 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4497 IVideoWindow* pVideoWindow;
4498 HRESULT hr;
4500 TRACE("(%p/%p)->(%08x, %ld, %08lx, %08lx)\n", This, iface, (DWORD) hwnd, uMsg, wParam, lParam);
4502 EnterCriticalSection(&This->cs);
4504 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4506 if (hr == S_OK)
4507 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4509 LeaveCriticalSection(&This->cs);
4511 return hr;
4514 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface,
4515 long Left,
4516 long Top,
4517 long Width,
4518 long Height) {
4519 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4520 IVideoWindow* pVideoWindow;
4521 HRESULT hr;
4523 TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
4525 EnterCriticalSection(&This->cs);
4527 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4529 if (hr == S_OK)
4530 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4532 LeaveCriticalSection(&This->cs);
4534 return hr;
4537 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface,
4538 long *pLeft,
4539 long *pTop,
4540 long *pWidth,
4541 long *pHeight) {
4542 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4543 IVideoWindow* pVideoWindow;
4544 HRESULT hr;
4546 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4548 EnterCriticalSection(&This->cs);
4550 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4552 if (hr == S_OK)
4553 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4555 LeaveCriticalSection(&This->cs);
4557 return hr;
4560 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface,
4561 long *pWidth,
4562 long *pHeight) {
4563 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4564 IVideoWindow* pVideoWindow;
4565 HRESULT hr;
4567 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4569 EnterCriticalSection(&This->cs);
4571 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4573 if (hr == S_OK)
4574 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4576 LeaveCriticalSection(&This->cs);
4578 return hr;
4581 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface,
4582 long *pWidth,
4583 long *pHeight) {
4584 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4585 IVideoWindow* pVideoWindow;
4586 HRESULT hr;
4588 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4590 EnterCriticalSection(&This->cs);
4592 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4594 if (hr == S_OK)
4595 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4597 LeaveCriticalSection(&This->cs);
4599 return hr;
4602 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface,
4603 long *pLeft,
4604 long *pTop,
4605 long *pWidth,
4606 long *pHeight) {
4607 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4608 IVideoWindow* pVideoWindow;
4609 HRESULT hr;
4611 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4613 EnterCriticalSection(&This->cs);
4615 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4617 if (hr == S_OK)
4618 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4620 LeaveCriticalSection(&This->cs);
4622 return hr;
4625 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface,
4626 long HideCursor) {
4627 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4628 IVideoWindow* pVideoWindow;
4629 HRESULT hr;
4631 TRACE("(%p/%p)->(%ld)\n", This, iface, HideCursor);
4633 EnterCriticalSection(&This->cs);
4635 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4637 if (hr == S_OK)
4638 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4640 LeaveCriticalSection(&This->cs);
4642 return hr;
4645 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface,
4646 long *CursorHidden) {
4647 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4648 IVideoWindow* pVideoWindow;
4649 HRESULT hr;
4651 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4653 EnterCriticalSection(&This->cs);
4655 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4657 if (hr == S_OK)
4658 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4660 LeaveCriticalSection(&This->cs);
4662 return hr;
4666 static const IVideoWindowVtbl IVideoWindow_VTable =
4668 VideoWindow_QueryInterface,
4669 VideoWindow_AddRef,
4670 VideoWindow_Release,
4671 VideoWindow_GetTypeInfoCount,
4672 VideoWindow_GetTypeInfo,
4673 VideoWindow_GetIDsOfNames,
4674 VideoWindow_Invoke,
4675 VideoWindow_put_Caption,
4676 VideoWindow_get_Caption,
4677 VideoWindow_put_WindowStyle,
4678 VideoWindow_get_WindowStyle,
4679 VideoWindow_put_WindowStyleEx,
4680 VideoWindow_get_WindowStyleEx,
4681 VideoWindow_put_AutoShow,
4682 VideoWindow_get_AutoShow,
4683 VideoWindow_put_WindowState,
4684 VideoWindow_get_WindowState,
4685 VideoWindow_put_BackgroundPalette,
4686 VideoWindow_get_BackgroundPalette,
4687 VideoWindow_put_Visible,
4688 VideoWindow_get_Visible,
4689 VideoWindow_put_Left,
4690 VideoWindow_get_Left,
4691 VideoWindow_put_Width,
4692 VideoWindow_get_Width,
4693 VideoWindow_put_Top,
4694 VideoWindow_get_Top,
4695 VideoWindow_put_Height,
4696 VideoWindow_get_Height,
4697 VideoWindow_put_Owner,
4698 VideoWindow_get_Owner,
4699 VideoWindow_put_MessageDrain,
4700 VideoWindow_get_MessageDrain,
4701 VideoWindow_get_BorderColor,
4702 VideoWindow_put_BorderColor,
4703 VideoWindow_get_FullScreenMode,
4704 VideoWindow_put_FullScreenMode,
4705 VideoWindow_SetWindowForeground,
4706 VideoWindow_NotifyOwnerMessage,
4707 VideoWindow_SetWindowPosition,
4708 VideoWindow_GetWindowPosition,
4709 VideoWindow_GetMinIdealImageSize,
4710 VideoWindow_GetMaxIdealImageSize,
4711 VideoWindow_GetRestorePosition,
4712 VideoWindow_HideCursor,
4713 VideoWindow_IsCursorHidden
4717 /*** IUnknown methods ***/
4718 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface,
4719 REFIID riid,
4720 LPVOID*ppvObj) {
4721 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4723 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
4725 return Filtergraph_QueryInterface(This, riid, ppvObj);
4728 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface) {
4729 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4731 TRACE("(%p/%p)->()\n", This, iface);
4733 return Filtergraph_AddRef(This);
4736 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface) {
4737 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4739 TRACE("(%p/%p)->()\n", This, iface);
4741 return Filtergraph_Release(This);
4744 /*** IDispatch methods ***/
4745 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface,
4746 UINT*pctinfo) {
4747 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4749 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
4751 return S_OK;
4754 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface,
4755 UINT iTInfo,
4756 LCID lcid,
4757 ITypeInfo**ppTInfo) {
4758 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4760 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
4762 return S_OK;
4765 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface,
4766 REFIID riid,
4767 LPOLESTR*rgszNames,
4768 UINT cNames,
4769 LCID lcid,
4770 DISPID*rgDispId) {
4771 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4773 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
4775 return S_OK;
4778 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface,
4779 DISPID dispIdMember,
4780 REFIID riid,
4781 LCID lcid,
4782 WORD wFlags,
4783 DISPPARAMS*pDispParams,
4784 VARIANT*pVarResult,
4785 EXCEPINFO*pExepInfo,
4786 UINT*puArgErr) {
4787 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4789 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);
4791 return S_OK;
4794 /*** IMediaEvent methods ***/
4795 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface,
4796 OAEVENT *hEvent) {
4797 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4799 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
4801 *hEvent = (OAEVENT)This->evqueue.msg_event;
4803 return S_OK;
4806 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface,
4807 long *lEventCode,
4808 LONG_PTR *lParam1,
4809 LONG_PTR *lParam2,
4810 long msTimeout) {
4811 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4812 Event evt;
4814 TRACE("(%p/%p)->(%p, %p, %p, %ld)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
4816 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
4818 *lEventCode = evt.lEventCode;
4819 *lParam1 = evt.lParam1;
4820 *lParam2 = evt.lParam2;
4821 return S_OK;
4824 *lEventCode = 0;
4825 return E_ABORT;
4828 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface,
4829 long msTimeout,
4830 long *pEvCode) {
4831 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4833 TRACE("(%p/%p)->(%ld, %p)\n", This, iface, msTimeout, pEvCode);
4835 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
4837 *pEvCode = This->CompletionStatus;
4838 return S_OK;
4841 *pEvCode = 0;
4842 return E_ABORT;
4845 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface,
4846 long lEvCode) {
4847 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4849 TRACE("(%p/%p)->(%ld)\n", This, iface, lEvCode);
4851 if (lEvCode == EC_COMPLETE)
4852 This->HandleEcComplete = FALSE;
4853 else if (lEvCode == EC_REPAINT)
4854 This->HandleEcRepaint = FALSE;
4855 else if (lEvCode == EC_CLOCK_CHANGED)
4856 This->HandleEcClockChanged = FALSE;
4857 else
4858 return S_FALSE;
4860 return S_OK;
4863 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface,
4864 long lEvCode) {
4865 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4867 TRACE("(%p/%p)->(%ld)\n", This, iface, lEvCode);
4869 if (lEvCode == EC_COMPLETE)
4870 This->HandleEcComplete = TRUE;
4871 else if (lEvCode == EC_REPAINT)
4872 This->HandleEcRepaint = TRUE;
4873 else if (lEvCode == EC_CLOCK_CHANGED)
4874 This->HandleEcClockChanged = TRUE;
4875 else
4876 return S_FALSE;
4878 return S_OK;
4881 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface,
4882 long lEvCode,
4883 LONG_PTR lParam1,
4884 LONG_PTR lParam2) {
4885 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4887 TRACE("(%p/%p)->(%ld, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
4889 return S_OK;
4892 /*** IMediaEventEx methods ***/
4893 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface,
4894 OAHWND hwnd,
4895 long lMsg,
4896 LONG_PTR lInstanceData) {
4897 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4899 TRACE("(%p/%p)->(%08x, %ld, %08lx)\n", This, iface, (DWORD) hwnd, lMsg, lInstanceData);
4901 This->notif.hWnd = (HWND)hwnd;
4902 This->notif.msg = lMsg;
4903 This->notif.instance = (long) lInstanceData;
4905 return S_OK;
4908 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface,
4909 long lNoNotifyFlags) {
4910 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4912 TRACE("(%p/%p)->(%ld)\n", This, iface, lNoNotifyFlags);
4914 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
4915 return E_INVALIDARG;
4917 This->notif.disabled = lNoNotifyFlags;
4919 return S_OK;
4922 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface,
4923 long *lplNoNotifyFlags) {
4924 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4926 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
4928 if (!lplNoNotifyFlags)
4929 return E_POINTER;
4931 *lplNoNotifyFlags = This->notif.disabled;
4933 return S_OK;
4937 static const IMediaEventExVtbl IMediaEventEx_VTable =
4939 MediaEvent_QueryInterface,
4940 MediaEvent_AddRef,
4941 MediaEvent_Release,
4942 MediaEvent_GetTypeInfoCount,
4943 MediaEvent_GetTypeInfo,
4944 MediaEvent_GetIDsOfNames,
4945 MediaEvent_Invoke,
4946 MediaEvent_GetEventHandle,
4947 MediaEvent_GetEvent,
4948 MediaEvent_WaitForCompletion,
4949 MediaEvent_CancelDefaultHandling,
4950 MediaEvent_RestoreDefaultHandling,
4951 MediaEvent_FreeEventParams,
4952 MediaEvent_SetNotifyWindow,
4953 MediaEvent_SetNotifyFlags,
4954 MediaEvent_GetNotifyFlags
4958 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, LPVOID *ppv)
4960 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
4962 return Filtergraph_QueryInterface(This, riid, ppv);
4965 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
4967 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
4969 return Filtergraph_AddRef(This);
4972 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
4974 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
4976 return Filtergraph_Release(This);
4979 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
4981 FIXME("(%p): stub\n", pClassID);
4983 return E_NOTIMPL;
4986 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
4988 FIXME("(): stub\n");
4990 return E_NOTIMPL;
4993 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
4995 FIXME("(): stub\n");
4997 return E_NOTIMPL;
5000 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
5002 FIXME("(0x%s): stub\n", wine_dbgstr_longlong(tStart));
5004 return E_NOTIMPL;
5007 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout, FILTER_STATE * pState)
5009 FIXME("(%d, %p): stub\n", dwMsTimeout, pState);
5011 return E_NOTIMPL;
5014 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5016 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5017 HRESULT hr = S_OK;
5018 int i;
5020 TRACE("(%p/%p)->(%p)\n", iface, This, pClock);
5022 EnterCriticalSection(&This->cs);
5024 for (i = 0;i < This->nFilters;i++)
5026 hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5027 if (FAILED(hr))
5028 break;
5031 if (FAILED(hr))
5033 for(;i >= 0;i--)
5034 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5036 else
5038 if (This->refClock)
5039 IReferenceClock_Release(This->refClock);
5040 This->refClock = pClock;
5041 if (This->refClock)
5042 IReferenceClock_AddRef(This->refClock);
5044 if (This->HandleEcClockChanged)
5046 IMediaEventSink *pEventSink;
5047 HRESULT eshr;
5049 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (LPVOID)&pEventSink);
5050 if (SUCCEEDED(eshr))
5052 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5053 IMediaEventSink_Release(pEventSink);
5058 LeaveCriticalSection(&This->cs);
5060 return hr;
5063 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5065 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5067 TRACE("(%p/%p)->(%p)\n", iface, This, ppClock);
5069 if (!ppClock)
5070 return E_POINTER;
5072 EnterCriticalSection(&This->cs);
5074 *ppClock = This->refClock;
5075 if (*ppClock)
5076 IReferenceClock_AddRef(*ppClock);
5078 LeaveCriticalSection(&This->cs);
5080 return S_OK;
5083 static const IMediaFilterVtbl IMediaFilter_VTable =
5085 MediaFilter_QueryInterface,
5086 MediaFilter_AddRef,
5087 MediaFilter_Release,
5088 MediaFilter_GetClassID,
5089 MediaFilter_Stop,
5090 MediaFilter_Pause,
5091 MediaFilter_Run,
5092 MediaFilter_GetState,
5093 MediaFilter_SetSyncSource,
5094 MediaFilter_GetSyncSource
5097 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, LPVOID *ppv)
5099 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5101 return Filtergraph_QueryInterface(This, riid, ppv);
5104 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5106 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5108 return Filtergraph_AddRef(This);
5111 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5113 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5115 return Filtergraph_Release(This);
5118 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, long EventCode, LONG_PTR EventParam1, LONG_PTR EventParam2)
5120 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5121 Event evt;
5123 TRACE("(%p/%p)->(%ld, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5125 /* We need thread safety here, let's use the events queue's one */
5126 EnterCriticalSection(&This->evqueue.msg_crst);
5128 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5130 TRACE("Process EC_COMPLETE notification\n");
5131 if (++This->EcCompleteCount == This->nRenderers)
5133 evt.lEventCode = EC_COMPLETE;
5134 evt.lParam1 = S_OK;
5135 evt.lParam2 = 0;
5136 TRACE("Send EC_COMPLETE to app\n");
5137 EventsQueue_PutEvent(&This->evqueue, &evt);
5138 if (!This->notif.disabled && This->notif.hWnd)
5140 TRACE("Send Window message\n");
5141 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5143 This->CompletionStatus = EC_COMPLETE;
5144 SetEvent(This->hEventCompletion);
5147 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5149 /* FIXME: Not handled yet */
5151 else
5153 evt.lEventCode = EventCode;
5154 evt.lParam1 = EventParam1;
5155 evt.lParam2 = EventParam2;
5156 EventsQueue_PutEvent(&This->evqueue, &evt);
5157 if (!This->notif.disabled && This->notif.hWnd)
5158 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5161 LeaveCriticalSection(&This->evqueue.msg_crst);
5162 return S_OK;
5165 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5167 MediaEventSink_QueryInterface,
5168 MediaEventSink_AddRef,
5169 MediaEventSink_Release,
5170 MediaEventSink_Notify
5173 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, LPVOID *ppv)
5175 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5177 return Filtergraph_QueryInterface(This, riid, ppv);
5180 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5182 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5184 return Filtergraph_AddRef(This);
5187 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5189 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5191 return Filtergraph_Release(This);
5194 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface,
5195 IPin* pOutputPin,
5196 IPin* pInputPin,
5197 const AM_MEDIA_TYPE* pmtFirstConnection,
5198 IBaseFilter* pUsingFilter,
5199 HANDLE hAbortEvent,
5200 DWORD dwFlags)
5202 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5204 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5206 return E_NOTIMPL;
5209 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface,
5210 IGraphConfigCallback* pCallback,
5211 PVOID pvContext,
5212 DWORD dwFlags,
5213 HANDLE hAbortEvent)
5215 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5216 HRESULT hr;
5218 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5220 if (hAbortEvent)
5221 FIXME("The parameter hAbortEvent is not handled!\n");
5223 EnterCriticalSection(&This->cs);
5225 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5227 LeaveCriticalSection(&This->cs);
5229 return hr;
5232 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface,
5233 IBaseFilter* pFilter)
5235 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5237 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5239 return E_NOTIMPL;
5242 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface,
5243 IEnumFilters** pEnum)
5245 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5247 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5249 return E_NOTIMPL;
5252 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface,
5253 IBaseFilter* pFilter)
5255 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5257 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5259 return E_NOTIMPL;
5262 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface,
5263 REFERENCE_TIME* prtStart)
5265 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5267 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5269 return E_NOTIMPL;
5272 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface,
5273 IPin* pOutputPin,
5274 IPinConnection* pConnection,
5275 HANDLE hEventAbort)
5277 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5279 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5281 return E_NOTIMPL;
5284 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface,
5285 IBaseFilter* pFilter,
5286 DWORD dwFlags)
5288 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5290 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5292 return E_NOTIMPL;
5295 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface,
5296 IBaseFilter* pFilter,
5297 DWORD* dwFlags)
5299 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5301 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5303 return E_NOTIMPL;
5306 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface,
5307 IBaseFilter* pFilter,
5308 DWORD dwFlags)
5310 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5312 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5314 return E_NOTIMPL;
5317 static const IGraphConfigVtbl IGraphConfig_VTable =
5319 GraphConfig_QueryInterface,
5320 GraphConfig_AddRef,
5321 GraphConfig_Release,
5322 GraphConfig_Reconnect,
5323 GraphConfig_Reconfigure,
5324 GraphConfig_AddFilterToCache,
5325 GraphConfig_EnumCacheFilter,
5326 GraphConfig_RemoveFilterFromCache,
5327 GraphConfig_GetStartTime,
5328 GraphConfig_PushThroughData,
5329 GraphConfig_SetFilterFlags,
5330 GraphConfig_GetFilterFlags,
5331 GraphConfig_RemoveFilterEx
5334 static const IUnknownVtbl IInner_VTable =
5336 FilterGraphInner_QueryInterface,
5337 FilterGraphInner_AddRef,
5338 FilterGraphInner_Release
5341 static HRESULT WINAPI Filtergraph_QueryInterface(IFilterGraphImpl *This,
5342 REFIID riid,
5343 LPVOID * ppv) {
5344 if (This->bAggregatable)
5345 This->bUnkOuterValid = TRUE;
5347 if (This->pUnkOuter)
5349 if (This->bAggregatable)
5350 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
5352 if (IsEqualIID(riid, &IID_IUnknown))
5354 HRESULT hr;
5356 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5357 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5358 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5359 This->bAggregatable = TRUE;
5360 return hr;
5363 *ppv = NULL;
5364 return E_NOINTERFACE;
5367 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5370 static ULONG WINAPI Filtergraph_AddRef(IFilterGraphImpl *This) {
5371 if (This->pUnkOuter && This->bUnkOuterValid)
5372 return IUnknown_AddRef(This->pUnkOuter);
5373 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5376 static ULONG WINAPI Filtergraph_Release(IFilterGraphImpl *This) {
5377 if (This->pUnkOuter && This->bUnkOuterValid)
5378 return IUnknown_Release(This->pUnkOuter);
5379 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5382 /* This is the only function that actually creates a FilterGraph class... */
5383 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5385 IFilterGraphImpl *fimpl;
5386 HRESULT hr;
5388 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5390 *ppObj = NULL;
5392 fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5393 fimpl->pUnkOuter = pUnkOuter;
5394 fimpl->bUnkOuterValid = FALSE;
5395 fimpl->bAggregatable = FALSE;
5396 fimpl->IInner_vtbl = &IInner_VTable;
5397 fimpl->IFilterGraph2_vtbl = &IFilterGraph2_VTable;
5398 fimpl->IMediaControl_vtbl = &IMediaControl_VTable;
5399 fimpl->IMediaSeeking_vtbl = &IMediaSeeking_VTable;
5400 fimpl->IBasicAudio_vtbl = &IBasicAudio_VTable;
5401 fimpl->IBasicVideo_vtbl = &IBasicVideo_VTable;
5402 fimpl->IVideoWindow_vtbl = &IVideoWindow_VTable;
5403 fimpl->IMediaEventEx_vtbl = &IMediaEventEx_VTable;
5404 fimpl->IMediaFilter_vtbl = &IMediaFilter_VTable;
5405 fimpl->IMediaEventSink_vtbl = &IMediaEventSink_VTable;
5406 fimpl->IGraphConfig_vtbl = &IGraphConfig_VTable;
5407 fimpl->IMediaPosition_vtbl = &IMediaPosition_VTable;
5408 fimpl->ref = 1;
5409 fimpl->ppFiltersInGraph = NULL;
5410 fimpl->pFilterNames = NULL;
5411 fimpl->nFilters = 0;
5412 fimpl->filterCapacity = 0;
5413 fimpl->nameIndex = 1;
5414 fimpl->refClock = NULL;
5415 fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5416 fimpl->HandleEcComplete = TRUE;
5417 fimpl->HandleEcRepaint = TRUE;
5418 fimpl->HandleEcClockChanged = TRUE;
5419 fimpl->notif.hWnd = 0;
5420 fimpl->notif.disabled = FALSE;
5421 fimpl->nRenderers = 0;
5422 fimpl->EcCompleteCount = 0;
5423 fimpl->state = State_Stopped;
5424 EventsQueue_Init(&fimpl->evqueue);
5425 InitializeCriticalSection(&fimpl->cs);
5426 fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5427 fimpl->nItfCacheEntries = 0;
5428 memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5429 fimpl->start_time = fimpl->position = 0;
5430 fimpl->stop_position = -1;
5431 fimpl->punkFilterMapper2 = NULL;
5433 /* create Filtermapper aggregated. */
5434 hr = CoCreateInstance(&CLSID_FilterMapper2, pUnkOuter ? pUnkOuter : (IUnknown*)&fimpl->IInner_vtbl, CLSCTX_INPROC_SERVER,
5435 &IID_IUnknown, (LPVOID*)&fimpl->punkFilterMapper2);
5437 if (SUCCEEDED(hr)) {
5438 hr = IUnknown_QueryInterface(fimpl->punkFilterMapper2, &IID_IFilterMapper2, (LPVOID*)&fimpl->pFilterMapper2);
5441 if (SUCCEEDED(hr)) {
5442 /* Release controlling IUnknown - compensate refcount increase from caching IFilterMapper2 interface. */
5443 if (pUnkOuter) IUnknown_Release(pUnkOuter);
5444 else IUnknown_Release((IUnknown*)&fimpl->IInner_vtbl);
5447 if (FAILED(hr)) {
5448 ERR("Unable to create filter mapper (%x)\n", hr);
5449 if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5450 CloseHandle(fimpl->hEventCompletion);
5451 EventsQueue_Destroy(&fimpl->evqueue);
5452 fimpl->cs.DebugInfo->Spare[0] = 0;
5453 DeleteCriticalSection(&fimpl->cs);
5454 CoTaskMemFree(fimpl);
5455 return hr;
5457 IFilterGraph2_SetDefaultSyncSource((IFilterGraph2*)fimpl);
5459 *ppObj = fimpl;
5460 return S_OK;
5463 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5465 FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5466 return FilterGraph_create(pUnkOuter, ppObj);