d3dx9: Allow setting texture to NULL.
[wine.git] / dlls / quartz / filtergraph.c
blobc154f92a8a92574de1ddcbaf5bf519aad89ce147
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 UINT msg; /* User window message */
50 LONG_PTR 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 = CoTaskMemRealloc(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 IFilterGraph2 IFilterGraph2_iface;
156 IMediaControl IMediaControl_iface;
157 IMediaSeeking IMediaSeeking_iface;
158 IBasicAudio IBasicAudio_iface;
159 IBasicVideo2 IBasicVideo2_iface;
160 IVideoWindow IVideoWindow_iface;
161 IMediaEventEx IMediaEventEx_iface;
162 IMediaFilter IMediaFilter_iface;
163 IMediaEventSink IMediaEventSink_iface;
164 IGraphConfig IGraphConfig_iface;
165 IMediaPosition IMediaPosition_iface;
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 IBaseFilter *refClockProvider;
188 EventsQueue evqueue;
189 HANDLE hEventCompletion;
190 int CompletionStatus;
191 WndNotify notif;
192 int nRenderers;
193 int EcCompleteCount;
194 int HandleEcComplete;
195 int HandleEcRepaint;
196 int HandleEcClockChanged;
197 OAFilterState state;
198 CRITICAL_SECTION cs;
199 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
200 int nItfCacheEntries;
201 IUnknown * pUnkOuter;
202 BOOL bUnkOuterValid;
203 BOOL bAggregatable;
204 BOOL defaultclock;
205 GUID timeformatseek;
206 REFERENCE_TIME start_time;
207 REFERENCE_TIME pause_time;
208 LONGLONG stop_position;
209 LONG recursioncount;
210 } IFilterGraphImpl;
212 static HRESULT Filtergraph_QueryInterface(IFilterGraphImpl *This,
213 REFIID riid, LPVOID * ppv);
214 static ULONG Filtergraph_AddRef(IFilterGraphImpl *This);
215 static ULONG Filtergraph_Release(IFilterGraphImpl *This);
217 static HRESULT WINAPI FilterGraphInner_QueryInterface(IUnknown * iface,
218 REFIID riid,
219 LPVOID *ppvObj) {
220 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
221 TRACE("(%p)->(%s (%p), %p)\n", This, debugstr_guid(riid), riid, ppvObj);
223 if (This->bAggregatable)
224 This->bUnkOuterValid = TRUE;
226 if (IsEqualGUID(&IID_IUnknown, riid)) {
227 *ppvObj = &(This->IInner_vtbl);
228 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
229 } else if (IsEqualGUID(&IID_IFilterGraph, riid) ||
230 IsEqualGUID(&IID_IFilterGraph2, riid) ||
231 IsEqualGUID(&IID_IGraphBuilder, riid)) {
232 *ppvObj = &This->IFilterGraph2_iface;
233 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj);
234 } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
235 *ppvObj = &This->IMediaControl_iface;
236 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj);
237 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
238 *ppvObj = &This->IMediaSeeking_iface;
239 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
240 } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
241 *ppvObj = &This->IBasicAudio_iface;
242 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj);
243 } else if (IsEqualGUID(&IID_IBasicVideo, riid) ||
244 IsEqualGUID(&IID_IBasicVideo2, riid)) {
245 *ppvObj = &This->IBasicVideo2_iface;
246 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj);
247 } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
248 *ppvObj = &This->IVideoWindow_iface;
249 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj);
250 } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
251 IsEqualGUID(&IID_IMediaEventEx, riid)) {
252 *ppvObj = &This->IMediaEventEx_iface;
253 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
254 } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
255 IsEqualGUID(&IID_IPersist, riid)) {
256 *ppvObj = &This->IMediaFilter_iface;
257 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj);
258 } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
259 *ppvObj = &This->IMediaEventSink_iface;
260 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj);
261 } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
262 *ppvObj = &This->IGraphConfig_iface;
263 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
264 } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
265 *ppvObj = &This->IMediaPosition_iface;
266 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj);
267 } else if (IsEqualGUID(&IID_IFilterMapper, riid)) {
268 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj);
269 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
270 } else if (IsEqualGUID(&IID_IFilterMapper2, riid)) {
271 *ppvObj = This->pFilterMapper2;
272 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
273 } else if (IsEqualGUID(&IID_IFilterMapper3, riid)) {
274 *ppvObj = This->pFilterMapper2;
275 TRACE(" returning IFilterMapper3 interface from aggregated filtermapper (%p)\n", *ppvObj);
276 } else {
277 *ppvObj = NULL;
278 FIXME("unknown interface %s\n", debugstr_guid(riid));
279 return E_NOINTERFACE;
282 IUnknown_AddRef((IUnknown *)(*ppvObj));
283 return S_OK;
286 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown * iface) {
287 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
288 ULONG ref = InterlockedIncrement(&This->ref);
290 TRACE("(%p)->(): new ref = %d\n", This, ref);
292 return ref;
295 static ULONG WINAPI FilterGraphInner_Release(IUnknown * iface)
297 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
298 ULONG ref = InterlockedDecrement(&This->ref);
300 TRACE("(%p)->(): new ref = %d\n", This, ref);
302 if (ref == 0) {
303 int i;
305 This->ref = 1; /* guard against reentrancy (aggregation). */
307 IMediaControl_Stop(&This->IMediaControl_iface);
309 while (This->nFilters)
310 IFilterGraph2_RemoveFilter((IFilterGraph2*)This, This->ppFiltersInGraph[0]);
312 if (This->refClock)
313 IReferenceClock_Release(This->refClock);
315 for (i = 0; i < This->nItfCacheEntries; i++)
317 if (This->ItfCacheEntries[i].iface)
318 IUnknown_Release(This->ItfCacheEntries[i].iface);
321 /* AddRef on controlling IUnknown, to compensate for Release of cached IFilterMapper2 interface below.
323 * NOTE: Filtergraph_AddRef isn't suitable, because bUnkOuterValid may be FALSE but punkOuter non-NULL
324 * and already passed as punkOuter to filtermapper in FilterGraph_create - this will happen in case of
325 * CoCreateInstance of filtergraph with non-null pUnkOuter and REFIID other than IID_Unknown that is
326 * cleaning up after error. */
327 if (This->pUnkOuter) IUnknown_AddRef(This->pUnkOuter);
328 else IUnknown_AddRef((IUnknown*)&This->IInner_vtbl);
330 IFilterMapper2_Release(This->pFilterMapper2);
331 IUnknown_Release(This->punkFilterMapper2);
333 CloseHandle(This->hEventCompletion);
334 EventsQueue_Destroy(&This->evqueue);
335 This->cs.DebugInfo->Spare[0] = 0;
336 DeleteCriticalSection(&This->cs);
337 CoTaskMemFree(This->ppFiltersInGraph);
338 CoTaskMemFree(This->pFilterNames);
339 CoTaskMemFree(This);
341 return ref;
344 static inline IFilterGraphImpl *impl_from_IFilterGraph2(IFilterGraph2 *iface)
346 return CONTAINING_RECORD(iface, IFilterGraphImpl, IFilterGraph2_iface);
349 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface, REFIID riid, void **ppvObj)
351 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
353 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
355 return Filtergraph_QueryInterface(This, riid, ppvObj);
358 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface)
360 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
362 TRACE("(%p/%p)->() calling FilterGraph AddRef\n", This, iface);
364 return Filtergraph_AddRef(This);
367 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface)
369 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
371 TRACE("(%p/%p)->() calling FilterGraph Release\n", This, iface);
373 return Filtergraph_Release(This);
376 /*** IFilterGraph methods ***/
377 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface, IBaseFilter *pFilter,
378 LPCWSTR pName)
380 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
381 HRESULT hr;
382 int i,j;
383 WCHAR* wszFilterName = NULL;
384 int duplicate_name = FALSE;
386 TRACE("(%p/%p)->(%p, %s (%p))\n", This, iface, pFilter, debugstr_w(pName), pName);
388 if (!pFilter)
389 return E_POINTER;
391 wszFilterName = CoTaskMemAlloc( (pName ? strlenW(pName) + 6 : 5) * sizeof(WCHAR) );
393 if (pName)
395 /* Check if name already exists */
396 for(i = 0; i < This->nFilters; i++)
397 if (!strcmpW(This->pFilterNames[i], pName))
399 duplicate_name = TRUE;
400 break;
404 /* If no name given or name already existing, generate one */
405 if (!pName || duplicate_name)
407 static const WCHAR wszFmt1[] = {'%','s',' ','%','0','4','d',0};
408 static const WCHAR wszFmt2[] = {'%','0','4','d',0};
410 for (j = 0; j < 10000 ; j++)
412 /* Create name */
413 if (pName)
414 sprintfW(wszFilterName, wszFmt1, pName, This->nameIndex);
415 else
416 sprintfW(wszFilterName, wszFmt2, This->nameIndex);
417 TRACE("Generated name %s\n", debugstr_w(wszFilterName));
419 /* Check if the generated name already exists */
420 for(i = 0; i < This->nFilters; i++)
421 if (!strcmpW(This->pFilterNames[i], wszFilterName))
422 break;
424 /* Compute next index and exit if generated name is suitable */
425 if (This->nameIndex++ == 10000)
426 This->nameIndex = 1;
427 if (i == This->nFilters)
428 break;
430 /* Unable to find a suitable name */
431 if (j == 10000)
433 CoTaskMemFree(wszFilterName);
434 return VFW_E_DUPLICATE_NAME;
437 else
438 memcpy(wszFilterName, pName, (strlenW(pName) + 1) * sizeof(WCHAR));
440 if (This->nFilters + 1 > This->filterCapacity)
442 int newCapacity = This->filterCapacity ? 2 * This->filterCapacity : 1;
443 IBaseFilter ** ppNewFilters = CoTaskMemAlloc(newCapacity * sizeof(IBaseFilter*));
444 LPWSTR * pNewNames = CoTaskMemAlloc(newCapacity * sizeof(LPWSTR));
445 memcpy(ppNewFilters, This->ppFiltersInGraph, This->nFilters * sizeof(IBaseFilter*));
446 memcpy(pNewNames, This->pFilterNames, This->nFilters * sizeof(LPWSTR));
447 if (This->filterCapacity)
449 CoTaskMemFree(This->ppFiltersInGraph);
450 CoTaskMemFree(This->pFilterNames);
452 This->ppFiltersInGraph = ppNewFilters;
453 This->pFilterNames = pNewNames;
454 This->filterCapacity = newCapacity;
457 hr = IBaseFilter_JoinFilterGraph(pFilter, (IFilterGraph *)This, wszFilterName);
459 if (SUCCEEDED(hr))
461 IBaseFilter_AddRef(pFilter);
462 This->ppFiltersInGraph[This->nFilters] = pFilter;
463 This->pFilterNames[This->nFilters] = wszFilterName;
464 This->nFilters++;
465 IBaseFilter_SetSyncSource(pFilter, This->refClock);
467 else
468 CoTaskMemFree(wszFilterName);
470 if (SUCCEEDED(hr) && duplicate_name)
471 return VFW_S_DUPLICATE_NAME;
473 return hr;
476 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
478 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
479 int i;
480 HRESULT hr = E_FAIL;
482 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
484 /* FIXME: check graph is stopped */
486 for (i = 0; i < This->nFilters; i++)
488 if (This->ppFiltersInGraph[i] == pFilter)
490 IEnumPins *penumpins = NULL;
491 FILTER_STATE state;
493 if (This->defaultclock && This->refClockProvider == pFilter)
495 IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, NULL);
496 This->defaultclock = 1;
499 TRACE("Removing filter %s\n", debugstr_w(This->pFilterNames[i]));
500 IBaseFilter_GetState(pFilter, 0, &state);
501 if (state == State_Running)
502 IBaseFilter_Pause(pFilter);
503 if (state != State_Stopped)
504 IBaseFilter_Stop(pFilter);
506 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
507 if (SUCCEEDED(hr)) {
508 IPin *ppin;
509 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
511 IPin *victim = NULL;
512 HRESULT h;
513 IPin_ConnectedTo(ppin, &victim);
514 if (victim)
516 h = IPin_Disconnect(victim);
517 TRACE("Disconnect other side: %08x\n", h);
518 if (h == VFW_E_NOT_STOPPED)
520 PIN_INFO pinfo;
521 IPin_QueryPinInfo(victim, &pinfo);
523 IBaseFilter_GetState(pinfo.pFilter, 0, &state);
524 if (state == State_Running)
525 IBaseFilter_Pause(pinfo.pFilter);
526 IBaseFilter_Stop(pinfo.pFilter);
527 IBaseFilter_Release(pinfo.pFilter);
528 h = IPin_Disconnect(victim);
529 TRACE("Disconnect retry: %08x\n", h);
531 IPin_Release(victim);
533 h = IPin_Disconnect(ppin);
534 TRACE("Disconnect 2: %08x\n", h);
536 IPin_Release(ppin);
538 IEnumPins_Release(penumpins);
541 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, This->pFilterNames[i]);
542 if (SUCCEEDED(hr))
544 IBaseFilter_SetSyncSource(pFilter, NULL);
545 IBaseFilter_Release(pFilter);
546 CoTaskMemFree(This->pFilterNames[i]);
547 memmove(This->ppFiltersInGraph+i, This->ppFiltersInGraph+i+1, sizeof(IBaseFilter*)*(This->nFilters - 1 - i));
548 memmove(This->pFilterNames+i, This->pFilterNames+i+1, sizeof(LPWSTR)*(This->nFilters - 1 - i));
549 This->nFilters--;
550 /* Invalidate interfaces in the cache */
551 for (i = 0; i < This->nItfCacheEntries; i++)
552 if (pFilter == This->ItfCacheEntries[i].filter)
554 IUnknown_Release(This->ItfCacheEntries[i].iface);
555 This->ItfCacheEntries[i].iface = NULL;
556 This->ItfCacheEntries[i].filter = NULL;
558 return S_OK;
560 break;
564 return hr; /* FIXME: check this error code */
567 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface, IEnumFilters **ppEnum)
569 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
571 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
573 return IEnumFiltersImpl_Construct(This->ppFiltersInGraph, This->nFilters, ppEnum);
576 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface, LPCWSTR pName,
577 IBaseFilter **ppFilter)
579 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
580 int i;
582 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_w(pName), pName, ppFilter);
584 if (!ppFilter)
585 return E_POINTER;
587 for (i = 0; i < This->nFilters; i++)
589 if (!strcmpW(pName, This->pFilterNames[i]))
591 *ppFilter = This->ppFiltersInGraph[i];
592 IBaseFilter_AddRef(*ppFilter);
593 return S_OK;
597 *ppFilter = NULL;
598 return VFW_E_NOT_FOUND;
601 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
602 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
604 static HRESULT CheckCircularConnection(IFilterGraphImpl *This, IPin *out, IPin *in)
606 #if 1
607 HRESULT hr;
608 PIN_INFO info_out, info_in;
610 hr = IPin_QueryPinInfo(out, &info_out);
611 if (FAILED(hr))
612 return hr;
613 if (info_out.dir != PINDIR_OUTPUT)
615 IBaseFilter_Release(info_out.pFilter);
616 return E_UNEXPECTED;
619 hr = IPin_QueryPinInfo(in, &info_in);
620 if (SUCCEEDED(hr))
621 IBaseFilter_Release(info_in.pFilter);
622 if (FAILED(hr))
623 goto out;
624 if (info_in.dir != PINDIR_INPUT)
626 hr = E_UNEXPECTED;
627 goto out;
630 if (info_out.pFilter == info_in.pFilter)
631 hr = VFW_E_CIRCULAR_GRAPH;
632 else
634 IEnumPins *enumpins;
635 IPin *test;
637 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
638 if (FAILED(hr))
639 goto out;
641 IEnumPins_Reset(enumpins);
642 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
644 PIN_DIRECTION dir = PINDIR_OUTPUT;
645 IPin_QueryDirection(test, &dir);
646 if (dir == PINDIR_INPUT)
648 IPin *victim = NULL;
649 IPin_ConnectedTo(test, &victim);
650 if (victim)
652 hr = CheckCircularConnection(This, victim, in);
653 IPin_Release(victim);
654 if (FAILED(hr))
656 IPin_Release(test);
657 break;
661 IPin_Release(test);
663 IEnumPins_Release(enumpins);
666 out:
667 IBaseFilter_Release(info_out.pFilter);
668 if (FAILED(hr))
669 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
670 return hr;
671 #else
672 /* Debugging filtergraphs not enabled */
673 return S_OK;
674 #endif
678 /* NOTE: despite the implication, it doesn't matter which
679 * way round you put in the input and output pins */
680 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppinIn, IPin *ppinOut,
681 const AM_MEDIA_TYPE *pmt)
683 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
684 PIN_DIRECTION dir;
685 HRESULT hr;
687 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
689 /* FIXME: check pins are in graph */
691 if (TRACE_ON(quartz))
693 PIN_INFO PinInfo;
695 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
696 if (FAILED(hr))
697 return hr;
699 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
700 IBaseFilter_Release(PinInfo.pFilter);
702 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
703 if (FAILED(hr))
704 return hr;
706 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
707 IBaseFilter_Release(PinInfo.pFilter);
710 hr = IPin_QueryDirection(ppinIn, &dir);
711 if (SUCCEEDED(hr))
713 if (dir == PINDIR_INPUT)
715 hr = CheckCircularConnection(This, ppinOut, ppinIn);
716 if (SUCCEEDED(hr))
717 hr = IPin_Connect(ppinOut, ppinIn, pmt);
719 else
721 hr = CheckCircularConnection(This, ppinIn, ppinOut);
722 if (SUCCEEDED(hr))
723 hr = IPin_Connect(ppinIn, ppinOut, pmt);
727 return hr;
730 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface, IPin *ppin)
732 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
733 IPin *pConnectedTo = NULL;
734 HRESULT hr;
735 PIN_DIRECTION pindir;
737 IPin_QueryDirection(ppin, &pindir);
738 hr = IPin_ConnectedTo(ppin, &pConnectedTo);
739 if (FAILED(hr)) {
740 TRACE("Querying connected to failed: %x\n", hr);
741 return hr;
743 IPin_Disconnect(ppin);
744 IPin_Disconnect(pConnectedTo);
745 if (pindir == PINDIR_INPUT)
746 hr = IPin_Connect(pConnectedTo, ppin, NULL);
747 else
748 hr = IPin_Connect(ppin, pConnectedTo, NULL);
749 IPin_Release(pConnectedTo);
750 if (FAILED(hr))
751 WARN("Reconnecting pins failed, pins are not connected now..\n");
752 TRACE("(%p->%p) -- %p %p -> %x\n", iface, This, ppin, pConnectedTo, hr);
753 return hr;
756 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
758 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
760 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
762 if (!ppin)
763 return E_POINTER;
765 return IPin_Disconnect(ppin);
768 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
770 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
771 IReferenceClock *pClock = NULL;
772 HRESULT hr = S_OK;
773 int i;
775 TRACE("(%p/%p)->() live sources not handled properly!\n", iface, This);
777 EnterCriticalSection(&This->cs);
779 for (i = 0; i < This->nFilters; ++i)
781 DWORD miscflags;
782 IAMFilterMiscFlags *flags = NULL;
783 IUnknown_QueryInterface(This->ppFiltersInGraph[i], &IID_IAMFilterMiscFlags, (void**)&flags);
784 if (!flags)
785 continue;
786 miscflags = IAMFilterMiscFlags_GetMiscFlags(flags);
787 IUnknown_Release(flags);
788 if (miscflags == AM_FILTER_MISC_FLAGS_IS_RENDERER)
789 IUnknown_QueryInterface(This->ppFiltersInGraph[i], &IID_IReferenceClock, (void**)&pClock);
790 if (pClock)
791 break;
794 if (!pClock)
796 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
797 This->refClockProvider = NULL;
799 else
800 This->refClockProvider = This->ppFiltersInGraph[i];
802 if (SUCCEEDED(hr))
804 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
805 This->defaultclock = TRUE;
806 IReferenceClock_Release(pClock);
808 LeaveCriticalSection(&This->cs);
810 return hr;
813 static HRESULT GetFilterInfo(IMoniker* pMoniker, GUID* pclsid, VARIANT* pvar)
815 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
816 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
817 IPropertyBag * pPropBagCat = NULL;
818 HRESULT hr;
820 VariantInit(pvar);
822 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
824 if (SUCCEEDED(hr))
825 hr = IPropertyBag_Read(pPropBagCat, wszClsidName, pvar, NULL);
827 if (SUCCEEDED(hr))
828 hr = CLSIDFromString(V_UNION(pvar, bstrVal), pclsid);
830 VariantClear(pvar);
832 if (SUCCEEDED(hr))
833 hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL);
835 if (SUCCEEDED(hr))
836 TRACE("Moniker = %s - %s\n", debugstr_guid(pclsid), debugstr_w(V_UNION(pvar, bstrVal)));
838 if (pPropBagCat)
839 IPropertyBag_Release(pPropBagCat);
841 return hr;
844 static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPin*** pppins, ULONG* pnb)
846 HRESULT hr;
847 ULONG nb = 0;
849 TRACE("(%p, %p, %p, %p)\n", pfilter, pinputpin, pppins, pnb);
850 hr = IPin_QueryInternalConnections(pinputpin, NULL, &nb);
851 if (hr == S_OK) {
852 /* Rendered input */
853 } else if (hr == S_FALSE) {
854 *pppins = CoTaskMemAlloc(sizeof(IPin*)*nb);
855 hr = IPin_QueryInternalConnections(pinputpin, *pppins, &nb);
856 if (hr != S_OK) {
857 WARN("Error (%x)\n", hr);
859 } else if (hr == E_NOTIMPL) {
860 /* Input connected to all outputs */
861 IEnumPins* penumpins;
862 IPin* ppin;
863 int i = 0;
864 TRACE("E_NOTIMPL\n");
865 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
866 if (FAILED(hr)) {
867 WARN("filter Enumpins failed (%x)\n", hr);
868 return hr;
870 i = 0;
871 /* Count output pins */
872 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
873 PIN_DIRECTION pindir;
874 IPin_QueryDirection(ppin, &pindir);
875 if (pindir == PINDIR_OUTPUT)
876 i++;
877 IPin_Release(ppin);
879 *pppins = CoTaskMemAlloc(sizeof(IPin*)*i);
880 /* Retrieve output pins */
881 IEnumPins_Reset(penumpins);
882 i = 0;
883 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
884 PIN_DIRECTION pindir;
885 IPin_QueryDirection(ppin, &pindir);
886 if (pindir == PINDIR_OUTPUT)
887 (*pppins)[i++] = ppin;
888 else
889 IPin_Release(ppin);
891 IEnumPins_Release(penumpins);
892 nb = i;
893 if (FAILED(hr)) {
894 WARN("Next failed (%x)\n", hr);
895 return hr;
897 } else if (FAILED(hr)) {
898 WARN("Cannot get internal connection (%x)\n", hr);
899 return hr;
902 *pnb = nb;
903 return S_OK;
906 /*** IGraphBuilder methods ***/
907 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IPin *ppinIn)
909 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
910 HRESULT hr;
911 AM_MEDIA_TYPE* mt = NULL;
912 IEnumMediaTypes* penummt = NULL;
913 ULONG nbmt;
914 IEnumPins* penumpins;
915 IEnumMoniker* pEnumMoniker;
916 GUID tab[2];
917 ULONG nb;
918 IMoniker* pMoniker;
919 ULONG pin;
920 PIN_INFO PinInfo;
921 CLSID FilterCLSID;
922 PIN_DIRECTION dir;
924 TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
926 if (TRACE_ON(quartz))
928 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
929 if (FAILED(hr))
930 return hr;
932 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
933 IBaseFilter_Release(PinInfo.pFilter);
935 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
936 if (FAILED(hr))
937 return hr;
939 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
940 IBaseFilter_Release(PinInfo.pFilter);
943 EnterCriticalSection(&This->cs);
944 ++This->recursioncount;
945 if (This->recursioncount >= 5)
947 WARN("Recursion count has reached %d\n", This->recursioncount);
948 hr = VFW_E_CANNOT_CONNECT;
949 goto out;
952 hr = IPin_QueryDirection(ppinOut, &dir);
953 if (FAILED(hr))
954 goto out;
956 if (dir == PINDIR_INPUT)
958 IPin *temp;
960 temp = ppinIn;
961 ppinIn = ppinOut;
962 ppinOut = temp;
965 hr = CheckCircularConnection(This, ppinOut, ppinIn);
966 if (FAILED(hr))
967 goto out;
969 /* Try direct connection first */
970 hr = IPin_Connect(ppinOut, ppinIn, NULL);
971 if (SUCCEEDED(hr))
972 goto out;
974 TRACE("Direct connection failed, trying to render using extra filters\n");
976 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
977 if (FAILED(hr))
978 goto out;
980 hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
981 IBaseFilter_Release(PinInfo.pFilter);
982 if (FAILED(hr))
983 goto out;
985 /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream
986 * filter to the minor mediatype of input pin of the renderer */
987 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
988 if (FAILED(hr))
990 WARN("EnumMediaTypes (%x)\n", hr);
991 goto out;
994 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
995 if (FAILED(hr)) {
996 WARN("IEnumMediaTypes_Next (%x)\n", hr);
997 goto out;
1000 if (!nbmt)
1002 WARN("No media type found!\n");
1003 hr = VFW_E_INVALIDMEDIATYPE;
1004 goto out;
1006 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1007 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1009 /* Try to find a suitable filter that can connect to the pin to render */
1010 tab[0] = mt->majortype;
1011 tab[1] = mt->subtype;
1012 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1013 if (FAILED(hr)) {
1014 WARN("Unable to enum filters (%x)\n", hr);
1015 goto out;
1018 hr = VFW_E_CANNOT_RENDER;
1019 while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1021 VARIANT var;
1022 GUID clsid;
1023 IPin** ppins;
1024 IPin* ppinfilter = NULL;
1025 IBaseFilter* pfilter = NULL;
1027 hr = GetFilterInfo(pMoniker, &clsid, &var);
1028 IMoniker_Release(pMoniker);
1029 if (FAILED(hr)) {
1030 WARN("Unable to retrieve filter info (%x)\n", hr);
1031 goto error;
1034 if (IsEqualGUID(&clsid, &FilterCLSID)) {
1035 /* Skip filter (same as the one the output pin belongs to) */
1036 goto error;
1039 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
1040 if (FAILED(hr)) {
1041 WARN("Unable to create filter (%x), trying next one\n", hr);
1042 goto error;
1045 hr = IFilterGraph2_AddFilter(iface, pfilter, V_UNION(&var, bstrVal));
1046 if (FAILED(hr)) {
1047 WARN("Unable to add filter (%x)\n", hr);
1048 IBaseFilter_Release(pfilter);
1049 pfilter = NULL;
1050 goto error;
1053 VariantClear(&var);
1055 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1056 if (FAILED(hr)) {
1057 WARN("Enumpins (%x)\n", hr);
1058 goto error;
1061 hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin);
1062 IEnumPins_Release(penumpins);
1064 if (FAILED(hr)) {
1065 WARN("Obtaining next pin: (%x)\n", hr);
1066 goto error;
1068 if (pin == 0) {
1069 WARN("Cannot use this filter: no pins\n");
1070 goto error;
1073 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1074 if (FAILED(hr)) {
1075 TRACE("Cannot connect to filter (%x), trying next one\n", hr);
1076 goto error;
1078 TRACE("Successfully connected to filter, follow chain...\n");
1080 /* Render all output pins of the filter by calling IFilterGraph2_Connect on each of them */
1081 hr = GetInternalConnections(pfilter, ppinfilter, &ppins, &nb);
1083 if (SUCCEEDED(hr)) {
1084 unsigned int i;
1085 if (nb == 0) {
1086 IPin_Disconnect(ppinfilter);
1087 IPin_Disconnect(ppinOut);
1088 goto error;
1090 TRACE("pins to consider: %d\n", nb);
1091 for(i = 0; i < nb; i++)
1093 LPWSTR pinname = NULL;
1095 TRACE("Processing pin %u\n", i);
1097 hr = IPin_QueryId(ppins[i], &pinname);
1098 if (SUCCEEDED(hr))
1100 if (pinname[0] == '~')
1102 TRACE("Pinname=%s, skipping\n", debugstr_w(pinname));
1103 hr = E_FAIL;
1105 else
1106 hr = IFilterGraph2_Connect(iface, ppins[i], ppinIn);
1107 CoTaskMemFree(pinname);
1110 if (FAILED(hr)) {
1111 TRACE("Cannot connect pin %p (%x)\n", ppinfilter, hr);
1113 IPin_Release(ppins[i]);
1114 if (SUCCEEDED(hr)) break;
1116 while (++i < nb) IPin_Release(ppins[i]);
1117 CoTaskMemFree(ppins);
1118 IPin_Release(ppinfilter);
1119 IBaseFilter_Release(pfilter);
1120 if (FAILED(hr))
1122 IPin_Disconnect(ppinfilter);
1123 IPin_Disconnect(ppinOut);
1124 IFilterGraph2_RemoveFilter(iface, pfilter);
1125 continue;
1127 break;
1130 error:
1131 VariantClear(&var);
1132 if (ppinfilter) IPin_Release(ppinfilter);
1133 if (pfilter) {
1134 IFilterGraph2_RemoveFilter(iface, pfilter);
1135 IBaseFilter_Release(pfilter);
1139 out:
1140 if (penummt)
1141 IEnumMediaTypes_Release(penummt);
1142 if (mt)
1143 DeleteMediaType(mt);
1144 --This->recursioncount;
1145 LeaveCriticalSection(&This->cs);
1146 TRACE("--> %08x\n", hr);
1147 return SUCCEEDED(hr) ? S_OK : hr;
1150 static HRESULT FilterGraph2_RenderRecurse(IFilterGraphImpl *This, IPin *ppinOut)
1152 /* This pin has been connected now, try to call render on all pins that aren't connected */
1153 IPin *to = NULL;
1154 PIN_INFO info;
1155 IEnumPins *enumpins = NULL;
1156 BOOL renderany = FALSE;
1157 BOOL renderall = TRUE;
1159 IPin_QueryPinInfo(ppinOut, &info);
1161 IBaseFilter_EnumPins(info.pFilter, &enumpins);
1162 /* Don't need to hold a reference, IEnumPins does */
1163 IBaseFilter_Release(info.pFilter);
1165 IEnumPins_Reset(enumpins);
1166 while (IEnumPins_Next(enumpins, 1, &to, NULL) == S_OK)
1168 PIN_DIRECTION dir = PINDIR_INPUT;
1170 IPin_QueryDirection(to, &dir);
1172 if (dir == PINDIR_OUTPUT)
1174 IPin *out = NULL;
1176 IPin_ConnectedTo(to, &out);
1177 if (!out)
1179 HRESULT hr;
1180 hr = IFilterGraph2_Render(&This->IFilterGraph2_iface, to);
1181 if (SUCCEEDED(hr))
1182 renderany = TRUE;
1183 else
1184 renderall = FALSE;
1186 else
1187 IPin_Release(out);
1190 IPin_Release(to);
1193 IEnumPins_Release(enumpins);
1195 if (renderall)
1196 return S_OK;
1198 if (renderany)
1199 return VFW_S_PARTIAL_RENDER;
1201 return VFW_E_CANNOT_RENDER;
1204 /* Ogg hates me if I create a direct rendering method
1206 * It can only connect to a pin properly once, so use a recursive method that does
1208 * +----+ --- (PIN 1) (Render is called on this pin)
1209 * | |
1210 * +----+ --- (PIN 2)
1212 * Enumerate possible renderers that EXACTLY match the requested type
1214 * If none is available, try to add intermediate filters that can connect to the input pin
1215 * then call Render on that intermediate pin's output pins
1216 * if it succeeds: Render returns success, if it doesn't, the intermediate filter is removed,
1217 * and another filter that can connect to the input pin is tried
1218 * if we run out of filters that can, give up and return VFW_E_CANNOT_RENDER
1219 * It's recursive, but fun!
1222 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *ppinOut)
1224 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1225 IEnumMediaTypes* penummt;
1226 AM_MEDIA_TYPE* mt;
1227 ULONG nbmt;
1228 HRESULT hr;
1230 IEnumMoniker* pEnumMoniker;
1231 GUID tab[4];
1232 ULONG nb;
1233 IMoniker* pMoniker;
1234 INT x;
1236 TRACE("(%p/%p)->(%p)\n", This, iface, ppinOut);
1238 if (TRACE_ON(quartz))
1240 PIN_INFO PinInfo;
1242 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
1243 if (FAILED(hr))
1244 return hr;
1246 TRACE("Filter owning pin => %p\n", PinInfo.pFilter);
1247 IBaseFilter_Release(PinInfo.pFilter);
1250 /* Try to find out if there is a renderer for the specified subtype already, and use that
1252 EnterCriticalSection(&This->cs);
1253 for (x = 0; x < This->nFilters; ++x)
1255 IEnumPins *enumpins = NULL;
1256 IPin *pin = NULL;
1258 hr = IBaseFilter_EnumPins(This->ppFiltersInGraph[x], &enumpins);
1260 if (FAILED(hr) || !enumpins)
1261 continue;
1263 IEnumPins_Reset(enumpins);
1264 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
1266 IPin *to = NULL;
1267 PIN_DIRECTION dir = PINDIR_OUTPUT;
1269 IPin_QueryDirection(pin, &dir);
1270 if (dir != PINDIR_INPUT)
1272 IPin_Release(pin);
1273 continue;
1275 IPin_ConnectedTo(pin, &to);
1277 if (to == NULL)
1279 hr = FilterGraph2_ConnectDirect(iface, ppinOut, pin, NULL);
1280 if (SUCCEEDED(hr))
1282 TRACE("Connected successfully %p/%p, %08x look if we should render more!\n", ppinOut, pin, hr);
1283 IPin_Release(pin);
1285 hr = FilterGraph2_RenderRecurse(This, pin);
1286 if (FAILED(hr))
1288 IPin_Disconnect(ppinOut);
1289 IPin_Disconnect(pin);
1290 continue;
1292 IEnumPins_Release(enumpins);
1293 LeaveCriticalSection(&This->cs);
1294 return hr;
1296 WARN("Could not connect!\n");
1298 else
1299 IPin_Release(to);
1301 IPin_Release(pin);
1303 IEnumPins_Release(enumpins);
1306 LeaveCriticalSection(&This->cs);
1308 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
1309 if (FAILED(hr)) {
1310 WARN("EnumMediaTypes (%x)\n", hr);
1311 return hr;
1314 IEnumMediaTypes_Reset(penummt);
1316 /* Looks like no existing renderer of the kind exists
1317 * Try adding new ones
1319 tab[0] = tab[1] = GUID_NULL;
1320 while (SUCCEEDED(hr))
1322 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
1323 if (FAILED(hr)) {
1324 WARN("IEnumMediaTypes_Next (%x)\n", hr);
1325 break;
1327 if (!nbmt)
1329 hr = VFW_E_CANNOT_RENDER;
1330 break;
1332 else
1334 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1335 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1337 /* Only enumerate once, this doesn't account for all previous ones, but this should be enough nonetheless */
1338 if (IsEqualIID(&tab[0], &mt->majortype) && IsEqualIID(&tab[1], &mt->subtype))
1340 DeleteMediaType(mt);
1341 continue;
1344 /* Try to find a suitable renderer with the same media type */
1345 tab[0] = mt->majortype;
1346 tab[1] = mt->subtype;
1347 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1348 if (FAILED(hr))
1350 WARN("Unable to enum filters (%x)\n", hr);
1351 break;
1354 hr = E_FAIL;
1356 while (IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1358 VARIANT var;
1359 GUID clsid;
1360 IPin* ppinfilter;
1361 IBaseFilter* pfilter = NULL;
1362 IEnumPins* penumpins = NULL;
1363 ULONG pin;
1365 hr = GetFilterInfo(pMoniker, &clsid, &var);
1366 IMoniker_Release(pMoniker);
1367 if (FAILED(hr)) {
1368 WARN("Unable to retrieve filter info (%x)\n", hr);
1369 goto error;
1372 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
1373 if (FAILED(hr))
1375 WARN("Unable to create filter (%x), trying next one\n", hr);
1376 goto error;
1379 hr = IFilterGraph2_AddFilter(iface, pfilter, V_UNION(&var, bstrVal));
1380 if (FAILED(hr)) {
1381 WARN("Unable to add filter (%x)\n", hr);
1382 IBaseFilter_Release(pfilter);
1383 pfilter = NULL;
1384 goto error;
1387 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1388 if (FAILED(hr)) {
1389 WARN("Splitter Enumpins (%x)\n", hr);
1390 goto error;
1393 while ((hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin)) == S_OK)
1395 PIN_DIRECTION dir;
1397 if (pin == 0) {
1398 WARN("No Pin\n");
1399 hr = E_FAIL;
1400 goto error;
1403 hr = IPin_QueryDirection(ppinfilter, &dir);
1404 if (FAILED(hr)) {
1405 IPin_Release(ppinfilter);
1406 WARN("QueryDirection failed (%x)\n", hr);
1407 goto error;
1409 if (dir != PINDIR_INPUT) {
1410 IPin_Release(ppinfilter);
1411 continue; /* Wrong direction */
1414 /* Connect the pin to the "Renderer" */
1415 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1416 IPin_Release(ppinfilter);
1418 if (FAILED(hr)) {
1419 WARN("Unable to connect %s to renderer (%x)\n", debugstr_w(V_UNION(&var, bstrVal)), hr);
1420 goto error;
1422 TRACE("Connected, recursing %s\n", debugstr_w(V_UNION(&var, bstrVal)));
1424 VariantClear(&var);
1426 hr = FilterGraph2_RenderRecurse(This, ppinfilter);
1427 if (FAILED(hr)) {
1428 WARN("Unable to connect recursively (%x)\n", hr);
1429 goto error;
1431 IBaseFilter_Release(pfilter);
1432 break;
1434 if (SUCCEEDED(hr)) {
1435 IEnumPins_Release(penumpins);
1436 break; /* out of IEnumMoniker_Next loop */
1439 /* IEnumPins_Next failed, all other failure case caught by goto error */
1440 WARN("IEnumPins_Next (%x)\n", hr);
1441 /* goto error */
1443 error:
1444 VariantClear(&var);
1445 if (penumpins)
1446 IEnumPins_Release(penumpins);
1447 if (pfilter) {
1448 IFilterGraph2_RemoveFilter(iface, pfilter);
1449 IBaseFilter_Release(pfilter);
1451 if (SUCCEEDED(hr)) DebugBreak();
1454 IEnumMoniker_Release(pEnumMoniker);
1455 if (nbmt)
1456 DeleteMediaType(mt);
1457 if (SUCCEEDED(hr))
1458 break;
1459 hr = S_OK;
1462 IEnumMediaTypes_Release(penummt);
1463 return hr;
1466 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface, LPCWSTR lpcwstrFile,
1467 LPCWSTR lpcwstrPlayList)
1469 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1470 static const WCHAR string[] = {'R','e','a','d','e','r',0};
1471 IBaseFilter* preader = NULL;
1472 IPin* ppinreader = NULL;
1473 IEnumPins* penumpins = NULL;
1474 HRESULT hr;
1475 BOOL partial = FALSE;
1476 HRESULT any = FALSE;
1478 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1480 if (lpcwstrPlayList != NULL)
1481 return E_INVALIDARG;
1483 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, string, &preader);
1484 if (FAILED(hr))
1485 return hr;
1487 if (SUCCEEDED(hr))
1488 hr = IBaseFilter_EnumPins(preader, &penumpins);
1489 if (SUCCEEDED(hr))
1491 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1493 PIN_DIRECTION dir;
1495 IPin_QueryDirection(ppinreader, &dir);
1496 if (dir == PINDIR_OUTPUT)
1498 INT i;
1500 hr = IFilterGraph2_Render(iface, ppinreader);
1501 TRACE("Render %08x\n", hr);
1503 for (i = 0; i < This->nFilters; ++i)
1504 TRACE("Filters in chain: %s\n", debugstr_w(This->pFilterNames[i]));
1506 if (SUCCEEDED(hr))
1507 any = TRUE;
1508 if (hr != S_OK)
1509 partial = TRUE;
1511 IPin_Release(ppinreader);
1513 IEnumPins_Release(penumpins);
1515 if (!any)
1516 hr = VFW_E_CANNOT_RENDER;
1517 else if (partial)
1518 hr = VFW_S_PARTIAL_RENDER;
1519 else
1520 hr = S_OK;
1522 IBaseFilter_Release(preader);
1524 TRACE("--> %08x\n", hr);
1525 return hr;
1528 /* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
1529 static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
1531 static const WCHAR wszReg[] = {'M','e','d','i','a',' ','T','y','p','e','\\','E','x','t','e','n','s','i','o','n','s',0};
1532 HRESULT hr = S_OK;
1533 HKEY extkey;
1534 LONG lRet;
1536 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszReg, 0, KEY_READ, &extkey);
1537 hr = HRESULT_FROM_WIN32(lRet);
1539 if (SUCCEEDED(hr))
1541 static const WCHAR filtersource[] = {'S','o','u','r','c','e',' ','F','i','l','t','e','r',0};
1542 WCHAR *ext = PathFindExtensionW(pszFileName);
1543 WCHAR clsid_key[39];
1544 GUID clsid;
1545 DWORD size = sizeof(clsid_key);
1546 HKEY pathkey;
1548 if (!ext)
1550 CloseHandle(extkey);
1551 return E_FAIL;
1554 lRet = RegOpenKeyExW(extkey, ext, 0, KEY_READ, &pathkey);
1555 hr = HRESULT_FROM_WIN32(lRet);
1556 CloseHandle(extkey);
1557 if (FAILED(hr))
1558 return hr;
1560 lRet = RegQueryValueExW(pathkey, filtersource, NULL, NULL, (LPBYTE)clsid_key, &size);
1561 hr = HRESULT_FROM_WIN32(lRet);
1562 CloseHandle(pathkey);
1563 if (FAILED(hr))
1564 return hr;
1566 CLSIDFromString(clsid_key, &clsid);
1568 TRACE("CLSID: %s\n", debugstr_guid(&clsid));
1569 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1570 if (SUCCEEDED(hr))
1572 IFileSourceFilter *source = NULL;
1573 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID*)&source);
1574 if (SUCCEEDED(hr))
1575 IFileSourceFilter_Release(source);
1576 else
1577 IBaseFilter_Release(*filter);
1580 if (FAILED(hr))
1581 *filter = NULL;
1582 return hr;
1585 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface, LPCWSTR lpcwstrFileName,
1586 LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1588 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1589 HRESULT hr;
1590 IBaseFilter* preader;
1591 IFileSourceFilter* pfile = NULL;
1592 AM_MEDIA_TYPE mt;
1593 WCHAR* filename;
1595 TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1597 /* Try from file name first, then fall back to default asynchronous reader */
1598 hr = GetFileSourceFilter(lpcwstrFileName, &preader);
1600 if (FAILED(hr))
1601 hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&preader);
1602 if (FAILED(hr)) {
1603 WARN("Unable to create file source filter (%x)\n", hr);
1604 return hr;
1607 hr = IFilterGraph2_AddFilter(iface, preader, lpcwstrFilterName);
1608 if (FAILED(hr)) {
1609 WARN("Unable add filter (%x)\n", hr);
1610 IBaseFilter_Release(preader);
1611 return hr;
1614 hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1615 if (FAILED(hr)) {
1616 WARN("Unable to get IFileSourceInterface (%x)\n", hr);
1617 goto error;
1620 /* Load the file in the file source filter */
1621 hr = IFileSourceFilter_Load(pfile, lpcwstrFileName, NULL);
1622 if (FAILED(hr)) {
1623 WARN("Load (%x)\n", hr);
1624 goto error;
1627 IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1628 if (FAILED(hr)) {
1629 WARN("GetCurFile (%x)\n", hr);
1630 goto error;
1633 TRACE("File %s\n", debugstr_w(filename));
1634 TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
1635 TRACE("SubType %s\n", debugstr_guid(&mt.subtype));
1637 if (ppFilter)
1638 *ppFilter = preader;
1639 IFileSourceFilter_Release(pfile);
1641 return S_OK;
1643 error:
1644 if (pfile)
1645 IFileSourceFilter_Release(pfile);
1646 IFilterGraph2_RemoveFilter(iface, preader);
1647 IBaseFilter_Release(preader);
1649 return hr;
1652 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR hFile)
1654 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1656 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1658 return S_OK;
1661 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1663 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1665 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1667 return S_OK;
1670 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1672 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1674 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1676 return S_OK;
1679 /*** IFilterGraph2 methods ***/
1680 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1681 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1683 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1685 TRACE("(%p/%p)->(%p %p %s %p): stub !!!\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1687 return S_OK;
1690 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *ppin,
1691 const AM_MEDIA_TYPE *pmt)
1693 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1695 TRACE("(%p/%p)->(%p %p): stub !!!\n", This, iface, ppin, pmt);
1697 return S_OK;
1700 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *pPinOut, DWORD dwFlags,
1701 DWORD *pvContext)
1703 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1705 TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This, iface, pPinOut, dwFlags, pvContext);
1707 return S_OK;
1711 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1713 FilterGraph2_QueryInterface,
1714 FilterGraph2_AddRef,
1715 FilterGraph2_Release,
1716 FilterGraph2_AddFilter,
1717 FilterGraph2_RemoveFilter,
1718 FilterGraph2_EnumFilters,
1719 FilterGraph2_FindFilterByName,
1720 FilterGraph2_ConnectDirect,
1721 FilterGraph2_Reconnect,
1722 FilterGraph2_Disconnect,
1723 FilterGraph2_SetDefaultSyncSource,
1724 FilterGraph2_Connect,
1725 FilterGraph2_Render,
1726 FilterGraph2_RenderFile,
1727 FilterGraph2_AddSourceFilter,
1728 FilterGraph2_SetLogFile,
1729 FilterGraph2_Abort,
1730 FilterGraph2_ShouldOperationContinue,
1731 FilterGraph2_AddSourceFilterForMoniker,
1732 FilterGraph2_ReconnectEx,
1733 FilterGraph2_RenderEx
1736 static inline IFilterGraphImpl *impl_from_IMediaControl(IMediaControl *iface)
1738 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaControl_iface);
1741 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID riid, void **ppvObj)
1743 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1745 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1747 return Filtergraph_QueryInterface(This, riid, ppvObj);
1750 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1752 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1754 TRACE("(%p/%p)->()\n", This, iface);
1756 return Filtergraph_AddRef(This);
1759 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1761 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1763 TRACE("(%p/%p)->()\n", This, iface);
1765 return Filtergraph_Release(This);
1769 /*** IDispatch methods ***/
1770 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *pctinfo)
1772 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1774 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1776 return S_OK;
1779 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT iTInfo, LCID lcid,
1780 ITypeInfo **ppTInfo)
1782 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1784 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1786 return S_OK;
1789 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID riid,
1790 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1792 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1794 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1796 return S_OK;
1799 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID dispIdMember, REFIID riid,
1800 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
1801 UINT *puArgErr)
1803 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1805 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);
1807 return S_OK;
1810 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *, DWORD_PTR data);
1812 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter, DWORD_PTR data)
1814 HRESULT hr;
1815 IPin* pInputPin;
1816 IPin** ppPins;
1817 ULONG nb;
1818 ULONG i;
1819 PIN_INFO PinInfo;
1821 TRACE("%p %p\n", pGraph, pOutputPin);
1822 PinInfo.pFilter = NULL;
1824 hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1826 if (SUCCEEDED(hr))
1828 hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1829 if (SUCCEEDED(hr))
1830 hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1831 IPin_Release(pInputPin);
1834 if (SUCCEEDED(hr))
1836 if (nb == 0)
1838 TRACE("Reached a renderer\n");
1839 /* Count renderers for end of stream notification */
1840 pGraph->nRenderers++;
1842 else
1844 for(i = 0; i < nb; i++)
1846 /* Explore the graph downstream from this pin
1847 * FIXME: We should prevent exploring from a pin more than once. This can happens when
1848 * several input pins are connected to the same output (a MUX for instance). */
1849 ExploreGraph(pGraph, ppPins[i], FoundFilter, data);
1850 IPin_Release(ppPins[i]);
1853 CoTaskMemFree(ppPins);
1855 TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1857 FoundFilter(PinInfo.pFilter, data);
1860 if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1861 return hr;
1864 static HRESULT WINAPI SendRun(IBaseFilter *pFilter, DWORD_PTR data)
1866 REFERENCE_TIME time = *(REFERENCE_TIME*)data;
1867 return IBaseFilter_Run(pFilter, time);
1870 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1872 return IBaseFilter_Pause(pFilter);
1875 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1877 return IBaseFilter_Stop(pFilter);
1880 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1882 FILTER_STATE state;
1883 DWORD time_end = data;
1884 DWORD time_now = GetTickCount();
1885 LONG wait;
1887 if (time_end == INFINITE)
1889 wait = INFINITE;
1891 else if (time_end > time_now)
1893 wait = time_end - time_now;
1895 else
1896 wait = 0;
1898 return IBaseFilter_GetState(pFilter, wait, &state);
1902 static HRESULT SendFilterMessage(IFilterGraphImpl *This, fnFoundFilter FoundFilter, DWORD_PTR data)
1904 int i;
1905 IBaseFilter* pfilter;
1906 IEnumPins* pEnum;
1907 HRESULT hr;
1908 IPin* pPin;
1909 DWORD dummy;
1910 PIN_DIRECTION dir;
1912 TRACE("(%p)->()\n", This);
1914 /* Explorer the graph from source filters to renderers, determine renderers
1915 * number and run filters from renderers to source filters */
1916 This->nRenderers = 0;
1917 ResetEvent(This->hEventCompletion);
1919 for(i = 0; i < This->nFilters; i++)
1921 BOOL source = TRUE;
1922 pfilter = This->ppFiltersInGraph[i];
1923 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
1924 if (hr != S_OK)
1926 WARN("Enum pins failed %x\n", hr);
1927 continue;
1929 /* Check if it is a source filter */
1930 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1932 IPin_QueryDirection(pPin, &dir);
1933 IPin_Release(pPin);
1934 if (dir == PINDIR_INPUT)
1936 source = FALSE;
1937 break;
1940 if (source)
1942 TRACE("Found a source filter %p\n", pfilter);
1943 IEnumPins_Reset(pEnum);
1944 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1946 /* Explore the graph downstream from this pin */
1947 ExploreGraph(This, pPin, FoundFilter, data);
1948 IPin_Release(pPin);
1950 FoundFilter(pfilter, data);
1952 IEnumPins_Release(pEnum);
1955 return S_FALSE;
1958 /*** IMediaControl methods ***/
1959 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
1961 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1963 TRACE("(%p/%p)->()\n", This, iface);
1965 EnterCriticalSection(&This->cs);
1966 if (This->state == State_Running)
1967 goto out;
1968 This->EcCompleteCount = 0;
1970 if (This->defaultclock && !This->refClock)
1971 IFilterGraph2_SetDefaultSyncSource((IFilterGraph2*)This);
1973 if (This->refClock)
1975 REFERENCE_TIME now;
1976 IReferenceClock_GetTime(This->refClock, &now);
1977 if (This->state == State_Stopped)
1978 This->start_time = now + 500000;
1979 else if (This->pause_time >= 0)
1980 This->start_time += now - This->pause_time;
1981 else
1982 This->start_time = now;
1984 else This->start_time = 0;
1986 SendFilterMessage(This, SendRun, (DWORD_PTR)&This->start_time);
1987 This->state = State_Running;
1988 out:
1989 LeaveCriticalSection(&This->cs);
1990 return S_FALSE;
1993 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
1995 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1997 TRACE("(%p/%p)->()\n", This, iface);
1999 EnterCriticalSection(&This->cs);
2000 if (This->state == State_Paused)
2001 goto out;
2003 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2004 IReferenceClock_GetTime(This->refClock, &This->pause_time);
2005 else
2006 This->pause_time = -1;
2008 SendFilterMessage(This, SendPause, 0);
2009 This->state = State_Paused;
2010 out:
2011 LeaveCriticalSection(&This->cs);
2012 return S_FALSE;
2015 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
2017 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2019 TRACE("(%p/%p)->()\n", This, iface);
2021 if (This->state == State_Stopped) return S_OK;
2023 EnterCriticalSection(&This->cs);
2024 if (This->state == State_Running) SendFilterMessage(This, SendPause, 0);
2025 SendFilterMessage(This, SendStop, 0);
2026 This->state = State_Stopped;
2027 LeaveCriticalSection(&This->cs);
2028 return S_OK;
2031 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG msTimeout,
2032 OAFilterState *pfs)
2034 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2035 DWORD end;
2037 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
2039 if (!pfs)
2040 return E_POINTER;
2042 EnterCriticalSection(&This->cs);
2044 *pfs = This->state;
2045 if (msTimeout > 0)
2047 end = GetTickCount() + msTimeout;
2049 else if (msTimeout < 0)
2051 end = INFINITE;
2053 else
2055 end = 0;
2057 if (end)
2058 SendFilterMessage(This, SendGetState, end);
2060 LeaveCriticalSection(&This->cs);
2062 return S_OK;
2065 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
2067 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2069 FIXME("(%p/%p)->(%s (%p)): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename);
2071 return S_OK;
2074 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
2075 IDispatch **ppUnk)
2077 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2079 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2081 return S_OK;
2084 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2086 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2088 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2090 return S_OK;
2093 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2095 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2097 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2099 return S_OK;
2102 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
2104 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2106 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2108 return S_OK;
2112 static const IMediaControlVtbl IMediaControl_VTable =
2114 MediaControl_QueryInterface,
2115 MediaControl_AddRef,
2116 MediaControl_Release,
2117 MediaControl_GetTypeInfoCount,
2118 MediaControl_GetTypeInfo,
2119 MediaControl_GetIDsOfNames,
2120 MediaControl_Invoke,
2121 MediaControl_Run,
2122 MediaControl_Pause,
2123 MediaControl_Stop,
2124 MediaControl_GetState,
2125 MediaControl_RenderFile,
2126 MediaControl_AddSourceFilter,
2127 MediaControl_get_FilterCollection,
2128 MediaControl_get_RegFilterCollection,
2129 MediaControl_StopWhenReady
2132 static inline IFilterGraphImpl *impl_from_IMediaSeeking(IMediaSeeking *iface)
2134 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaSeeking_iface);
2137 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID riid, void **ppvObj)
2139 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2141 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2143 return Filtergraph_QueryInterface(This, riid, ppvObj);
2146 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2148 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2150 TRACE("(%p/%p)->()\n", This, iface);
2152 return Filtergraph_AddRef(This);
2155 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2157 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2159 TRACE("(%p/%p)->()\n", This, iface);
2161 return Filtergraph_Release(This);
2164 typedef HRESULT (WINAPI *fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
2166 static HRESULT all_renderers_seek(IFilterGraphImpl *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2167 BOOL allnotimpl = TRUE;
2168 int i;
2169 HRESULT hr, hr_return = S_OK;
2171 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2172 /* Send a message to all renderers, they are responsible for broadcasting it further */
2174 for(i = 0; i < This->nFilters; i++)
2176 IMediaSeeking *seek = NULL;
2177 IBaseFilter* pfilter = This->ppFiltersInGraph[i];
2178 IAMFilterMiscFlags *flags = NULL;
2179 ULONG filterflags;
2180 IUnknown_QueryInterface(pfilter, &IID_IAMFilterMiscFlags, (void**)&flags);
2181 if (!flags)
2182 continue;
2183 filterflags = IAMFilterMiscFlags_GetMiscFlags(flags);
2184 IUnknown_Release(flags);
2185 if (filterflags != AM_FILTER_MISC_FLAGS_IS_RENDERER)
2186 continue;
2188 IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2189 if (!seek)
2190 continue;
2191 hr = FoundSeek(This, seek, arg);
2192 IMediaSeeking_Release(seek);
2193 if (hr_return != E_NOTIMPL)
2194 allnotimpl = FALSE;
2195 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2196 hr_return = hr;
2199 if (allnotimpl)
2200 return E_NOTIMPL;
2201 return hr_return;
2204 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2206 HRESULT hr;
2207 DWORD caps = 0;
2209 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2210 if (FAILED(hr))
2211 return hr;
2213 /* Only add common capabilities everything supports */
2214 *(DWORD*)pcaps &= caps;
2216 return hr;
2219 /*** IMediaSeeking methods ***/
2220 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2222 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2223 HRESULT hr;
2225 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2227 if (!pCapabilities)
2228 return E_POINTER;
2230 EnterCriticalSection(&This->cs);
2231 *pCapabilities = 0xffffffff;
2233 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2234 LeaveCriticalSection(&This->cs);
2236 return hr;
2239 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2241 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2242 DWORD originalcaps;
2243 HRESULT hr;
2245 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2247 if (!pCapabilities)
2248 return E_POINTER;
2250 EnterCriticalSection(&This->cs);
2251 originalcaps = *pCapabilities;
2252 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2253 LeaveCriticalSection(&This->cs);
2255 if (FAILED(hr))
2256 return hr;
2258 if (!*pCapabilities)
2259 return E_FAIL;
2260 if (*pCapabilities != originalcaps)
2261 return S_FALSE;
2262 return S_OK;
2265 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2267 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2269 if (!pFormat)
2270 return E_POINTER;
2272 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2274 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2276 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2277 return S_FALSE;
2280 return S_OK;
2283 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2285 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2287 if (!pFormat)
2288 return E_POINTER;
2290 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2291 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2293 return S_OK;
2296 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2298 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2300 if (!pFormat)
2301 return E_POINTER;
2303 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2304 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2306 return S_OK;
2309 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2311 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2313 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2314 if (!pFormat)
2315 return E_POINTER;
2317 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2318 return S_FALSE;
2320 return S_OK;
2323 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2325 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2327 if (!pFormat)
2328 return E_POINTER;
2330 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2332 if (This->state != State_Stopped)
2333 return VFW_E_WRONG_STATE;
2335 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2337 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2338 return E_INVALIDARG;
2341 return S_OK;
2344 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2346 HRESULT hr;
2347 LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2349 hr = IMediaSeeking_GetDuration(seek, &duration);
2350 if (FAILED(hr))
2351 return hr;
2353 if (*pdur < duration)
2354 *pdur = duration;
2355 return hr;
2358 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *pDuration)
2360 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2361 HRESULT hr;
2363 TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2365 if (!pDuration)
2366 return E_POINTER;
2368 EnterCriticalSection(&This->cs);
2369 *pDuration = 0;
2370 hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2371 LeaveCriticalSection(&This->cs);
2373 TRACE("--->%08x\n", hr);
2374 return hr;
2377 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *pStop)
2379 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2380 HRESULT hr = S_OK;
2382 TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2384 if (!pStop)
2385 return E_POINTER;
2387 EnterCriticalSection(&This->cs);
2388 if (This->stop_position < 0)
2389 /* Stop position not set, use duration instead */
2390 hr = IMediaSeeking_GetDuration(iface, pStop);
2391 else
2392 *pStop = This->stop_position;
2393 LeaveCriticalSection(&This->cs);
2395 return hr;
2398 static HRESULT WINAPI FoundCurrentPosition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pposition)
2400 HRESULT hr;
2401 LONGLONG pos = 0, *ppos = (LONGLONG*)pposition;
2403 hr = IMediaSeeking_GetCurrentPosition(seek, &pos);
2404 if (FAILED(hr))
2405 return hr;
2407 if (*ppos < 0 || pos < *ppos)
2408 *ppos = pos;
2409 return hr;
2412 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *pCurrent)
2414 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2415 HRESULT hr;
2417 if (!pCurrent)
2418 return E_POINTER;
2420 EnterCriticalSection(&This->cs);
2421 *pCurrent = -1;
2422 hr = all_renderers_seek(This, FoundCurrentPosition, (DWORD_PTR)pCurrent);
2423 if (hr == E_NOTIMPL) {
2424 *pCurrent = 0;
2425 hr = S_OK;
2427 LeaveCriticalSection(&This->cs);
2429 TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2431 return hr;
2434 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2435 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2437 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2439 FIXME("(%p/%p)->(%p, %p, 0x%s, %p): stub !!!\n", This, iface, pTarget,
2440 pTargetFormat, wine_dbgstr_longlong(Source), pSourceFormat);
2442 return S_OK;
2445 struct pos_args {
2446 LONGLONG* current, *stop;
2447 DWORD curflags, stopflags;
2450 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2452 struct pos_args *args = (void*)pargs;
2454 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
2457 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2458 DWORD dwCurrentFlags, LONGLONG *pStop, DWORD dwStopFlags)
2460 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2461 HRESULT hr = S_OK;
2462 FILTER_STATE state;
2463 struct pos_args args;
2465 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
2467 EnterCriticalSection(&This->cs);
2468 state = This->state;
2469 TRACE("State: %s\n", state == State_Running ? "Running" : (state == State_Paused ? "Paused" : (state == State_Stopped ? "Stopped" : "UNKNOWN")));
2471 if ((dwCurrentFlags & 0x7) != AM_SEEKING_AbsolutePositioning &&
2472 (dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2473 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
2475 if ((dwStopFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2476 This->stop_position = *pStop;
2477 else if ((dwStopFlags & 0x7) != AM_SEEKING_NoPositioning)
2478 FIXME("Stop position not handled yet!\n");
2480 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2481 IMediaControl_Pause(&This->IMediaControl_iface);
2482 args.current = pCurrent;
2483 args.stop = pStop;
2484 args.curflags = dwCurrentFlags;
2485 args.stopflags = dwStopFlags;
2486 hr = all_renderers_seek(This, found_setposition, (DWORD_PTR)&args);
2488 if ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2489 This->pause_time = This->start_time = -1;
2490 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2491 IMediaControl_Run(&This->IMediaControl_iface);
2492 LeaveCriticalSection(&This->cs);
2494 return hr;
2497 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2498 LONGLONG *pStop)
2500 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2501 HRESULT hr;
2503 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pCurrent, pStop);
2504 hr = IMediaSeeking_GetCurrentPosition(iface, pCurrent);
2505 if (SUCCEEDED(hr))
2506 hr = IMediaSeeking_GetStopPosition(iface, pStop);
2508 return hr;
2511 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2512 LONGLONG *pLatest)
2514 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2516 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2518 return S_OK;
2521 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2523 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2525 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2527 return S_OK;
2530 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2532 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2534 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2536 return S_OK;
2539 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2541 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2543 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2545 return S_OK;
2549 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2551 MediaSeeking_QueryInterface,
2552 MediaSeeking_AddRef,
2553 MediaSeeking_Release,
2554 MediaSeeking_GetCapabilities,
2555 MediaSeeking_CheckCapabilities,
2556 MediaSeeking_IsFormatSupported,
2557 MediaSeeking_QueryPreferredFormat,
2558 MediaSeeking_GetTimeFormat,
2559 MediaSeeking_IsUsingTimeFormat,
2560 MediaSeeking_SetTimeFormat,
2561 MediaSeeking_GetDuration,
2562 MediaSeeking_GetStopPosition,
2563 MediaSeeking_GetCurrentPosition,
2564 MediaSeeking_ConvertTimeFormat,
2565 MediaSeeking_SetPositions,
2566 MediaSeeking_GetPositions,
2567 MediaSeeking_GetAvailable,
2568 MediaSeeking_SetRate,
2569 MediaSeeking_GetRate,
2570 MediaSeeking_GetPreroll
2573 static inline IFilterGraphImpl *impl_from_IMediaPosition(IMediaPosition *iface)
2575 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaPosition_iface);
2578 /*** IUnknown methods ***/
2579 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj)
2581 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2583 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2584 return Filtergraph_QueryInterface(This, riid, ppvObj);
2587 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2589 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2591 TRACE("(%p/%p)->()\n", This, iface);
2592 return Filtergraph_AddRef(This);
2595 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2597 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2599 TRACE("(%p/%p)->()\n", This, iface);
2600 return Filtergraph_Release(This);
2603 /*** IDispatch methods ***/
2604 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo){
2605 FIXME("(%p) stub!\n", iface);
2606 return E_NOTIMPL;
2609 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo){
2610 FIXME("(%p) stub!\n", iface);
2611 return E_NOTIMPL;
2614 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId){
2615 FIXME("(%p) stub!\n", iface);
2616 return E_NOTIMPL;
2619 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr){
2620 FIXME("(%p) stub!\n", iface);
2621 return E_NOTIMPL;
2624 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2626 GUID time_format;
2627 HRESULT hr;
2629 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2630 if (FAILED(hr))
2631 return hr;
2632 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2634 FIXME("Unsupported time format.\n");
2635 return E_NOTIMPL;
2638 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2639 return S_OK;
2642 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2644 GUID time_format;
2645 HRESULT hr;
2647 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2648 if (FAILED(hr))
2649 return hr;
2650 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2652 FIXME("Unsupported time format.\n");
2653 return E_NOTIMPL;
2656 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2657 return S_OK;
2660 /*** IMediaPosition methods ***/
2661 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2663 LONGLONG duration;
2664 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2665 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2666 if (FAILED(hr))
2667 return hr;
2668 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2671 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2673 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2674 LONGLONG reftime;
2675 HRESULT hr;
2677 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2678 if (FAILED(hr))
2679 return hr;
2680 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2681 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2684 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2686 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2687 LONGLONG pos;
2688 HRESULT hr;
2690 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2691 if (FAILED(hr))
2692 return hr;
2693 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2696 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2698 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2699 LONGLONG pos;
2700 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2701 if (FAILED(hr))
2702 return hr;
2703 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2706 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2708 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2709 LONGLONG reftime;
2710 HRESULT hr;
2712 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2713 if (FAILED(hr))
2714 return hr;
2715 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2716 &reftime, AM_SEEKING_AbsolutePositioning);
2719 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime){
2720 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2721 return E_NOTIMPL;
2724 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime){
2725 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2726 return E_NOTIMPL;
2729 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2731 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2732 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2735 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2737 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2738 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2741 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward){
2742 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2743 return E_NOTIMPL;
2746 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward){
2747 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2748 return E_NOTIMPL;
2752 static const IMediaPositionVtbl IMediaPosition_VTable =
2754 MediaPosition_QueryInterface,
2755 MediaPosition_AddRef,
2756 MediaPosition_Release,
2757 MediaPosition_GetTypeInfoCount,
2758 MediaPosition_GetTypeInfo,
2759 MediaPosition_GetIDsOfNames,
2760 MediaPosition_Invoke,
2761 MediaPosition_get_Duration,
2762 MediaPosition_put_CurrentPosition,
2763 MediaPosition_get_CurrentPosition,
2764 MediaPosition_get_StopTime,
2765 MediaPosition_put_StopTime,
2766 MediaPosition_get_PrerollTime,
2767 MediaPosition_put_PrerollTime,
2768 MediaPosition_put_Rate,
2769 MediaPosition_get_Rate,
2770 MediaPosition_CanSeekForward,
2771 MediaPosition_CanSeekBackward
2774 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2776 HRESULT hr = E_NOINTERFACE;
2777 int i;
2778 int entry;
2780 /* Check if the interface type is already registered */
2781 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2782 if (riid == pGraph->ItfCacheEntries[entry].riid)
2784 if (pGraph->ItfCacheEntries[entry].iface)
2786 /* Return the interface if available */
2787 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2788 return S_OK;
2790 break;
2793 if (entry >= MAX_ITF_CACHE_ENTRIES)
2795 FIXME("Not enough space to store interface in the cache\n");
2796 return E_OUTOFMEMORY;
2799 /* Find a filter supporting the requested interface */
2800 for (i = 0; i < pGraph->nFilters; i++)
2802 hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2803 if (hr == S_OK)
2805 pGraph->ItfCacheEntries[entry].riid = riid;
2806 pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2807 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2808 if (entry >= pGraph->nItfCacheEntries)
2809 pGraph->nItfCacheEntries++;
2810 return S_OK;
2812 if (hr != E_NOINTERFACE)
2813 return hr;
2816 return hr;
2819 static inline IFilterGraphImpl *impl_from_IBasicAudio(IBasicAudio *iface)
2821 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicAudio_iface);
2824 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID riid, void **ppvObj)
2826 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2828 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2830 return Filtergraph_QueryInterface(This, riid, ppvObj);
2833 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
2835 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2837 TRACE("(%p/%p)->()\n", This, iface);
2839 return Filtergraph_AddRef(This);
2842 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
2844 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2846 TRACE("(%p/%p)->()\n", This, iface);
2848 return Filtergraph_Release(This);
2851 /*** IDispatch methods ***/
2852 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *pctinfo)
2854 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2855 IBasicAudio* pBasicAudio;
2856 HRESULT hr;
2858 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
2860 EnterCriticalSection(&This->cs);
2862 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2864 if (hr == S_OK)
2865 hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
2867 LeaveCriticalSection(&This->cs);
2869 return hr;
2872 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT iTInfo, LCID lcid,
2873 ITypeInfo **ppTInfo)
2875 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2876 IBasicAudio* pBasicAudio;
2877 HRESULT hr;
2879 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
2881 EnterCriticalSection(&This->cs);
2883 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2885 if (hr == S_OK)
2886 hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
2888 LeaveCriticalSection(&This->cs);
2890 return hr;
2893 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID riid, LPOLESTR *rgszNames,
2894 UINT cNames, LCID lcid, DISPID *rgDispId)
2896 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2897 IBasicAudio* pBasicAudio;
2898 HRESULT hr;
2900 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
2902 EnterCriticalSection(&This->cs);
2904 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2906 if (hr == S_OK)
2907 hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
2909 LeaveCriticalSection(&This->cs);
2911 return hr;
2914 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID dispIdMember, REFIID riid,
2915 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
2916 UINT *puArgErr)
2918 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2919 IBasicAudio* pBasicAudio;
2920 HRESULT hr;
2922 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);
2924 EnterCriticalSection(&This->cs);
2926 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2928 if (hr == S_OK)
2929 hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
2931 LeaveCriticalSection(&This->cs);
2933 return hr;
2936 /*** IBasicAudio methods ***/
2937 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
2939 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2940 IBasicAudio* pBasicAudio;
2941 HRESULT hr;
2943 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
2945 EnterCriticalSection(&This->cs);
2947 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2949 if (hr == S_OK)
2950 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
2952 LeaveCriticalSection(&This->cs);
2954 return hr;
2957 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
2959 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2960 IBasicAudio* pBasicAudio;
2961 HRESULT hr;
2963 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
2965 EnterCriticalSection(&This->cs);
2967 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2969 if (hr == S_OK)
2970 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
2972 LeaveCriticalSection(&This->cs);
2974 return hr;
2977 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
2979 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2980 IBasicAudio* pBasicAudio;
2981 HRESULT hr;
2983 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
2985 EnterCriticalSection(&This->cs);
2987 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2989 if (hr == S_OK)
2990 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
2992 LeaveCriticalSection(&This->cs);
2994 return hr;
2997 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
2999 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3000 IBasicAudio* pBasicAudio;
3001 HRESULT hr;
3003 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
3005 EnterCriticalSection(&This->cs);
3007 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3009 if (hr == S_OK)
3010 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
3012 LeaveCriticalSection(&This->cs);
3014 return hr;
3017 static const IBasicAudioVtbl IBasicAudio_VTable =
3019 BasicAudio_QueryInterface,
3020 BasicAudio_AddRef,
3021 BasicAudio_Release,
3022 BasicAudio_GetTypeInfoCount,
3023 BasicAudio_GetTypeInfo,
3024 BasicAudio_GetIDsOfNames,
3025 BasicAudio_Invoke,
3026 BasicAudio_put_Volume,
3027 BasicAudio_get_Volume,
3028 BasicAudio_put_Balance,
3029 BasicAudio_get_Balance
3032 static inline IFilterGraphImpl *impl_from_IBasicVideo2(IBasicVideo2 *iface)
3034 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicVideo2_iface);
3037 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID riid, void **ppvObj)
3039 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3041 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3043 return Filtergraph_QueryInterface(This, riid, ppvObj);
3046 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
3048 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3050 TRACE("(%p/%p)->()\n", This, iface);
3052 return Filtergraph_AddRef(This);
3055 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
3057 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3059 TRACE("(%p/%p)->()\n", This, iface);
3061 return Filtergraph_Release(This);
3064 /*** IDispatch methods ***/
3065 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *pctinfo)
3067 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3068 IBasicVideo *pBasicVideo;
3069 HRESULT hr;
3071 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3073 EnterCriticalSection(&This->cs);
3075 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3077 if (hr == S_OK)
3078 hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
3080 LeaveCriticalSection(&This->cs);
3082 return hr;
3085 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT iTInfo, LCID lcid,
3086 ITypeInfo **ppTInfo)
3088 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3089 IBasicVideo *pBasicVideo;
3090 HRESULT hr;
3092 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3094 EnterCriticalSection(&This->cs);
3096 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3098 if (hr == S_OK)
3099 hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
3101 LeaveCriticalSection(&This->cs);
3103 return hr;
3106 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID riid,
3107 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
3109 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3110 IBasicVideo *pBasicVideo;
3111 HRESULT hr;
3113 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3115 EnterCriticalSection(&This->cs);
3117 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3119 if (hr == S_OK)
3120 hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
3122 LeaveCriticalSection(&This->cs);
3124 return hr;
3127 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID dispIdMember, REFIID riid,
3128 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3129 UINT *puArgErr)
3131 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3132 IBasicVideo *pBasicVideo;
3133 HRESULT hr;
3135 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);
3137 EnterCriticalSection(&This->cs);
3139 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3141 if (hr == S_OK)
3142 hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3144 LeaveCriticalSection(&This->cs);
3146 return hr;
3149 /*** IBasicVideo methods ***/
3150 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3152 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3153 IBasicVideo *pBasicVideo;
3154 HRESULT hr;
3156 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3158 EnterCriticalSection(&This->cs);
3160 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3162 if (hr == S_OK)
3163 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3165 LeaveCriticalSection(&This->cs);
3167 return hr;
3170 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3172 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3173 IBasicVideo *pBasicVideo;
3174 HRESULT hr;
3176 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3178 EnterCriticalSection(&This->cs);
3180 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3182 if (hr == S_OK)
3183 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3185 LeaveCriticalSection(&This->cs);
3187 return hr;
3190 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3192 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3193 IBasicVideo *pBasicVideo;
3194 HRESULT hr;
3196 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3198 EnterCriticalSection(&This->cs);
3200 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3202 if (hr == S_OK)
3203 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3205 LeaveCriticalSection(&This->cs);
3207 return hr;
3210 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3212 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3213 IBasicVideo *pBasicVideo;
3214 HRESULT hr;
3216 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3218 EnterCriticalSection(&This->cs);
3220 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3222 if (hr == S_OK)
3223 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3225 LeaveCriticalSection(&This->cs);
3227 return hr;
3230 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3232 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3233 IBasicVideo *pBasicVideo;
3234 HRESULT hr;
3236 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3238 EnterCriticalSection(&This->cs);
3240 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3242 if (hr == S_OK)
3243 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3245 LeaveCriticalSection(&This->cs);
3247 return hr;
3250 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3252 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3253 IBasicVideo *pBasicVideo;
3254 HRESULT hr;
3256 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3258 EnterCriticalSection(&This->cs);
3260 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3262 if (hr == S_OK)
3263 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3265 LeaveCriticalSection(&This->cs);
3267 return hr;
3270 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3272 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3273 IBasicVideo *pBasicVideo;
3274 HRESULT hr;
3276 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3278 EnterCriticalSection(&This->cs);
3280 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3282 if (hr == S_OK)
3283 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3285 LeaveCriticalSection(&This->cs);
3287 return hr;
3290 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3292 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3293 IBasicVideo *pBasicVideo;
3294 HRESULT hr;
3296 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3298 EnterCriticalSection(&This->cs);
3300 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3302 if (hr == S_OK)
3303 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3305 LeaveCriticalSection(&This->cs);
3307 return hr;
3310 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3312 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3313 IBasicVideo *pBasicVideo;
3314 HRESULT hr;
3316 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3318 EnterCriticalSection(&This->cs);
3320 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3322 if (hr == S_OK)
3323 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3325 LeaveCriticalSection(&This->cs);
3327 return hr;
3330 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3332 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3333 IBasicVideo *pBasicVideo;
3334 HRESULT hr;
3336 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3338 EnterCriticalSection(&This->cs);
3340 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3342 if (hr == S_OK)
3343 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3345 LeaveCriticalSection(&This->cs);
3347 return hr;
3350 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3352 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3353 IBasicVideo *pBasicVideo;
3354 HRESULT hr;
3356 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3358 EnterCriticalSection(&This->cs);
3360 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3362 if (hr == S_OK)
3363 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3365 LeaveCriticalSection(&This->cs);
3367 return hr;
3370 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3372 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3373 IBasicVideo *pBasicVideo;
3374 HRESULT hr;
3376 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3378 EnterCriticalSection(&This->cs);
3380 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3382 if (hr == S_OK)
3383 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3385 LeaveCriticalSection(&This->cs);
3387 return hr;
3390 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3392 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3393 IBasicVideo *pBasicVideo;
3394 HRESULT hr;
3396 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3398 EnterCriticalSection(&This->cs);
3400 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3402 if (hr == S_OK)
3403 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3405 LeaveCriticalSection(&This->cs);
3407 return hr;
3410 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3412 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3413 IBasicVideo *pBasicVideo;
3414 HRESULT hr;
3416 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3418 EnterCriticalSection(&This->cs);
3420 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3422 if (hr == S_OK)
3423 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3425 LeaveCriticalSection(&This->cs);
3427 return hr;
3430 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3432 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3433 IBasicVideo *pBasicVideo;
3434 HRESULT hr;
3436 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3438 EnterCriticalSection(&This->cs);
3440 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3442 if (hr == S_OK)
3443 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3445 LeaveCriticalSection(&This->cs);
3447 return hr;
3450 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3452 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3453 IBasicVideo *pBasicVideo;
3454 HRESULT hr;
3456 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3458 EnterCriticalSection(&This->cs);
3460 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3462 if (hr == S_OK)
3463 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3465 LeaveCriticalSection(&This->cs);
3467 return hr;
3470 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3472 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3473 IBasicVideo *pBasicVideo;
3474 HRESULT hr;
3476 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3478 EnterCriticalSection(&This->cs);
3480 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3482 if (hr == S_OK)
3483 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3485 LeaveCriticalSection(&This->cs);
3487 return hr;
3490 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3492 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3493 IBasicVideo *pBasicVideo;
3494 HRESULT hr;
3496 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3498 EnterCriticalSection(&This->cs);
3500 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3502 if (hr == S_OK)
3503 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3505 LeaveCriticalSection(&This->cs);
3507 return hr;
3510 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3512 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3513 IBasicVideo *pBasicVideo;
3514 HRESULT hr;
3516 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3518 EnterCriticalSection(&This->cs);
3520 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3522 if (hr == S_OK)
3523 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3525 LeaveCriticalSection(&This->cs);
3527 return hr;
3530 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3532 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3533 IBasicVideo *pBasicVideo;
3534 HRESULT hr;
3536 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3538 EnterCriticalSection(&This->cs);
3540 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3542 if (hr == S_OK)
3543 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3545 LeaveCriticalSection(&This->cs);
3547 return hr;
3550 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3551 LONG *pDestinationHeight)
3553 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3554 IBasicVideo *pBasicVideo;
3555 HRESULT hr;
3557 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3559 EnterCriticalSection(&This->cs);
3561 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3563 if (hr == S_OK)
3564 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3566 LeaveCriticalSection(&This->cs);
3568 return hr;
3571 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3572 LONG Width, LONG Height)
3574 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3575 IBasicVideo *pBasicVideo;
3576 HRESULT hr;
3578 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3580 EnterCriticalSection(&This->cs);
3582 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3584 if (hr == S_OK)
3585 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3587 LeaveCriticalSection(&This->cs);
3589 return hr;
3592 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3593 LONG *pWidth, LONG *pHeight)
3595 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3596 IBasicVideo *pBasicVideo;
3597 HRESULT hr;
3599 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3601 EnterCriticalSection(&This->cs);
3603 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3605 if (hr == S_OK)
3606 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3608 LeaveCriticalSection(&This->cs);
3610 return hr;
3613 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3615 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3616 IBasicVideo *pBasicVideo;
3617 HRESULT hr;
3619 TRACE("(%p/%p)->()\n", This, iface);
3621 EnterCriticalSection(&This->cs);
3623 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3625 if (hr == S_OK)
3626 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3628 LeaveCriticalSection(&This->cs);
3630 return hr;
3633 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3634 LONG Width, LONG Height)
3636 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3637 IBasicVideo *pBasicVideo;
3638 HRESULT hr;
3640 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3642 EnterCriticalSection(&This->cs);
3644 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3646 if (hr == S_OK)
3647 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3649 LeaveCriticalSection(&This->cs);
3651 return hr;
3654 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3655 LONG *pTop, LONG *pWidth, LONG *pHeight)
3657 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3658 IBasicVideo *pBasicVideo;
3659 HRESULT hr;
3661 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3663 EnterCriticalSection(&This->cs);
3665 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3667 if (hr == S_OK)
3668 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3670 LeaveCriticalSection(&This->cs);
3672 return hr;
3675 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3677 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3678 IBasicVideo *pBasicVideo;
3679 HRESULT hr;
3681 TRACE("(%p/%p)->()\n", This, iface);
3683 EnterCriticalSection(&This->cs);
3685 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3687 if (hr == S_OK)
3688 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3690 LeaveCriticalSection(&This->cs);
3692 return hr;
3695 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3697 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3698 IBasicVideo *pBasicVideo;
3699 HRESULT hr;
3701 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3703 EnterCriticalSection(&This->cs);
3705 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3707 if (hr == S_OK)
3708 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3710 LeaveCriticalSection(&This->cs);
3712 return hr;
3715 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3716 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3718 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3719 IBasicVideo *pBasicVideo;
3720 HRESULT hr;
3722 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3724 EnterCriticalSection(&This->cs);
3726 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3728 if (hr == S_OK)
3729 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3731 LeaveCriticalSection(&This->cs);
3733 return hr;
3736 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3737 LONG *pDIBImage)
3739 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3740 IBasicVideo *pBasicVideo;
3741 HRESULT hr;
3743 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3745 EnterCriticalSection(&This->cs);
3747 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3749 if (hr == S_OK)
3750 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3752 LeaveCriticalSection(&This->cs);
3754 return hr;
3757 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3759 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3760 IBasicVideo *pBasicVideo;
3761 HRESULT hr;
3763 TRACE("(%p/%p)->()\n", This, iface);
3765 EnterCriticalSection(&This->cs);
3767 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3769 if (hr == S_OK)
3770 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3772 LeaveCriticalSection(&This->cs);
3774 return hr;
3777 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3779 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3780 IBasicVideo *pBasicVideo;
3781 HRESULT hr;
3783 TRACE("(%p/%p)->()\n", This, iface);
3785 EnterCriticalSection(&This->cs);
3787 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3789 if (hr == S_OK)
3790 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3792 LeaveCriticalSection(&This->cs);
3794 return hr;
3797 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3798 LONG *plAspectY)
3800 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3801 IBasicVideo2 *pBasicVideo2;
3802 HRESULT hr;
3804 TRACE("(%p/%p)->()\n", This, iface);
3806 EnterCriticalSection(&This->cs);
3808 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3810 if (hr == S_OK)
3811 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3813 LeaveCriticalSection(&This->cs);
3815 return hr;
3818 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3820 BasicVideo_QueryInterface,
3821 BasicVideo_AddRef,
3822 BasicVideo_Release,
3823 BasicVideo_GetTypeInfoCount,
3824 BasicVideo_GetTypeInfo,
3825 BasicVideo_GetIDsOfNames,
3826 BasicVideo_Invoke,
3827 BasicVideo_get_AvgTimePerFrame,
3828 BasicVideo_get_BitRate,
3829 BasicVideo_get_BitErrorRate,
3830 BasicVideo_get_VideoWidth,
3831 BasicVideo_get_VideoHeight,
3832 BasicVideo_put_SourceLeft,
3833 BasicVideo_get_SourceLeft,
3834 BasicVideo_put_SourceWidth,
3835 BasicVideo_get_SourceWidth,
3836 BasicVideo_put_SourceTop,
3837 BasicVideo_get_SourceTop,
3838 BasicVideo_put_SourceHeight,
3839 BasicVideo_get_SourceHeight,
3840 BasicVideo_put_DestinationLeft,
3841 BasicVideo_get_DestinationLeft,
3842 BasicVideo_put_DestinationWidth,
3843 BasicVideo_get_DestinationWidth,
3844 BasicVideo_put_DestinationTop,
3845 BasicVideo_get_DestinationTop,
3846 BasicVideo_put_DestinationHeight,
3847 BasicVideo_get_DestinationHeight,
3848 BasicVideo_SetSourcePosition,
3849 BasicVideo_GetSourcePosition,
3850 BasicVideo_SetDefaultSourcePosition,
3851 BasicVideo_SetDestinationPosition,
3852 BasicVideo_GetDestinationPosition,
3853 BasicVideo_SetDefaultDestinationPosition,
3854 BasicVideo_GetVideoSize,
3855 BasicVideo_GetVideoPaletteEntries,
3856 BasicVideo_GetCurrentImage,
3857 BasicVideo_IsUsingDefaultSource,
3858 BasicVideo_IsUsingDefaultDestination,
3859 BasicVideo2_GetPreferredAspectRatio
3862 static inline IFilterGraphImpl *impl_from_IVideoWindow(IVideoWindow *iface)
3864 return CONTAINING_RECORD(iface, IFilterGraphImpl, IVideoWindow_iface);
3867 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID riid, void **ppvObj)
3869 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
3871 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3873 return Filtergraph_QueryInterface(This, riid, ppvObj);
3876 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
3878 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
3880 TRACE("(%p/%p)->()\n", This, iface);
3882 return Filtergraph_AddRef(This);
3885 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
3887 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
3889 TRACE("(%p/%p)->()\n", This, iface);
3891 return Filtergraph_Release(This);
3894 /*** IDispatch methods ***/
3895 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *pctinfo)
3897 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
3898 IVideoWindow *pVideoWindow;
3899 HRESULT hr;
3901 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3903 EnterCriticalSection(&This->cs);
3905 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3907 if (hr == S_OK)
3908 hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
3910 LeaveCriticalSection(&This->cs);
3912 return hr;
3915 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT iTInfo, LCID lcid,
3916 ITypeInfo **ppTInfo)
3918 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
3919 IVideoWindow *pVideoWindow;
3920 HRESULT hr;
3922 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3924 EnterCriticalSection(&This->cs);
3926 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3928 if (hr == S_OK)
3929 hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
3931 LeaveCriticalSection(&This->cs);
3933 return hr;
3936 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID riid,
3937 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
3939 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
3940 IVideoWindow *pVideoWindow;
3941 HRESULT hr;
3943 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3945 EnterCriticalSection(&This->cs);
3947 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3949 if (hr == S_OK)
3950 hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
3952 LeaveCriticalSection(&This->cs);
3954 return hr;
3957 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID dispIdMember, REFIID riid,
3958 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3959 UINT*puArgErr)
3961 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
3962 IVideoWindow *pVideoWindow;
3963 HRESULT hr;
3965 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);
3967 EnterCriticalSection(&This->cs);
3969 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3971 if (hr == S_OK)
3972 hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3974 LeaveCriticalSection(&This->cs);
3976 return hr;
3980 /*** IVideoWindow methods ***/
3981 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
3983 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
3984 IVideoWindow *pVideoWindow;
3985 HRESULT hr;
3987 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
3989 EnterCriticalSection(&This->cs);
3991 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3993 if (hr == S_OK)
3994 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
3996 LeaveCriticalSection(&This->cs);
3998 return hr;
4001 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
4003 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4004 IVideoWindow *pVideoWindow;
4005 HRESULT hr;
4007 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
4009 EnterCriticalSection(&This->cs);
4011 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4013 if (hr == S_OK)
4014 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
4016 LeaveCriticalSection(&This->cs);
4018 return hr;
4021 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
4023 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4024 IVideoWindow *pVideoWindow;
4025 HRESULT hr;
4027 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
4029 EnterCriticalSection(&This->cs);
4031 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4033 if (hr == S_OK)
4034 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
4036 LeaveCriticalSection(&This->cs);
4038 return hr;
4041 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
4043 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4044 IVideoWindow *pVideoWindow;
4045 HRESULT hr;
4047 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
4049 EnterCriticalSection(&This->cs);
4051 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4053 if (hr == S_OK)
4054 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
4056 LeaveCriticalSection(&This->cs);
4058 return hr;
4061 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
4063 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4064 IVideoWindow *pVideoWindow;
4065 HRESULT hr;
4067 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
4069 EnterCriticalSection(&This->cs);
4071 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4073 if (hr == S_OK)
4074 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
4076 LeaveCriticalSection(&This->cs);
4078 return hr;
4081 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
4083 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4084 IVideoWindow *pVideoWindow;
4085 HRESULT hr;
4087 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
4089 EnterCriticalSection(&This->cs);
4091 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4093 if (hr == S_OK)
4094 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
4096 LeaveCriticalSection(&This->cs);
4098 return hr;
4101 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
4103 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4104 IVideoWindow *pVideoWindow;
4105 HRESULT hr;
4107 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
4109 EnterCriticalSection(&This->cs);
4111 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4113 if (hr == S_OK)
4114 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4116 LeaveCriticalSection(&This->cs);
4118 return hr;
4121 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
4123 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4124 IVideoWindow *pVideoWindow;
4125 HRESULT hr;
4127 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4129 EnterCriticalSection(&This->cs);
4131 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4133 if (hr == S_OK)
4134 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4136 LeaveCriticalSection(&This->cs);
4138 return hr;
4141 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
4143 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4144 IVideoWindow *pVideoWindow;
4145 HRESULT hr;
4147 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4149 EnterCriticalSection(&This->cs);
4151 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4153 if (hr == S_OK)
4154 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4156 LeaveCriticalSection(&This->cs);
4158 return hr;
4161 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4163 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4164 IVideoWindow *pVideoWindow;
4165 HRESULT hr;
4167 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4169 EnterCriticalSection(&This->cs);
4171 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4173 if (hr == S_OK)
4174 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4176 LeaveCriticalSection(&This->cs);
4178 return hr;
4181 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4183 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4184 IVideoWindow *pVideoWindow;
4185 HRESULT hr;
4187 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4189 EnterCriticalSection(&This->cs);
4191 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4193 if (hr == S_OK)
4194 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4196 LeaveCriticalSection(&This->cs);
4198 return hr;
4201 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4202 LONG *pBackgroundPalette)
4204 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4205 IVideoWindow *pVideoWindow;
4206 HRESULT hr;
4208 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4210 EnterCriticalSection(&This->cs);
4212 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4214 if (hr == S_OK)
4215 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4217 LeaveCriticalSection(&This->cs);
4219 return hr;
4222 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4224 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4225 IVideoWindow *pVideoWindow;
4226 HRESULT hr;
4228 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4230 EnterCriticalSection(&This->cs);
4232 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4234 if (hr == S_OK)
4235 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4237 LeaveCriticalSection(&This->cs);
4239 return hr;
4242 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4244 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4245 IVideoWindow *pVideoWindow;
4246 HRESULT hr;
4248 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4250 EnterCriticalSection(&This->cs);
4252 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4254 if (hr == S_OK)
4255 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4257 LeaveCriticalSection(&This->cs);
4259 return hr;
4262 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4264 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4265 IVideoWindow *pVideoWindow;
4266 HRESULT hr;
4268 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4270 EnterCriticalSection(&This->cs);
4272 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4274 if (hr == S_OK)
4275 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4277 LeaveCriticalSection(&This->cs);
4279 return hr;
4282 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4284 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4285 IVideoWindow *pVideoWindow;
4286 HRESULT hr;
4288 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4290 EnterCriticalSection(&This->cs);
4292 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4294 if (hr == S_OK)
4295 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4297 LeaveCriticalSection(&This->cs);
4299 return hr;
4302 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4304 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4305 IVideoWindow *pVideoWindow;
4306 HRESULT hr;
4308 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4310 EnterCriticalSection(&This->cs);
4312 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4314 if (hr == S_OK)
4315 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4317 LeaveCriticalSection(&This->cs);
4319 return hr;
4322 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4324 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4325 IVideoWindow *pVideoWindow;
4326 HRESULT hr;
4328 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4330 EnterCriticalSection(&This->cs);
4332 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4334 if (hr == S_OK)
4335 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4337 LeaveCriticalSection(&This->cs);
4339 return hr;
4342 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4344 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4345 IVideoWindow *pVideoWindow;
4346 HRESULT hr;
4348 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4350 EnterCriticalSection(&This->cs);
4352 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4354 if (hr == S_OK)
4355 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4357 LeaveCriticalSection(&This->cs);
4359 return hr;
4362 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4364 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4365 IVideoWindow *pVideoWindow;
4366 HRESULT hr;
4368 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4370 EnterCriticalSection(&This->cs);
4372 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4374 if (hr == S_OK)
4375 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4377 LeaveCriticalSection(&This->cs);
4379 return hr;
4382 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4384 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4385 IVideoWindow *pVideoWindow;
4386 HRESULT hr;
4388 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4390 EnterCriticalSection(&This->cs);
4392 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4394 if (hr == S_OK)
4395 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4397 LeaveCriticalSection(&This->cs);
4399 return hr;
4402 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4404 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4405 IVideoWindow *pVideoWindow;
4406 HRESULT hr;
4408 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4410 EnterCriticalSection(&This->cs);
4412 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4414 if (hr == S_OK)
4415 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4417 LeaveCriticalSection(&This->cs);
4419 return hr;
4422 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4424 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4425 IVideoWindow *pVideoWindow;
4426 HRESULT hr;
4428 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4430 EnterCriticalSection(&This->cs);
4432 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4434 if (hr == S_OK)
4435 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4437 LeaveCriticalSection(&This->cs);
4439 return hr;
4442 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4444 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4445 IVideoWindow *pVideoWindow;
4446 HRESULT hr;
4448 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4450 EnterCriticalSection(&This->cs);
4452 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4454 if (hr == S_OK)
4455 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4457 LeaveCriticalSection(&This->cs);
4459 return hr;
4462 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4464 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4465 IVideoWindow *pVideoWindow;
4466 HRESULT hr;
4468 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4470 EnterCriticalSection(&This->cs);
4472 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4474 if (hr == S_OK)
4475 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4477 LeaveCriticalSection(&This->cs);
4479 return hr;
4482 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4484 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4485 IVideoWindow *pVideoWindow;
4486 HRESULT hr;
4488 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4490 EnterCriticalSection(&This->cs);
4492 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4494 if (hr == S_OK)
4495 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4497 LeaveCriticalSection(&This->cs);
4499 return hr;
4502 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4504 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4505 IVideoWindow *pVideoWindow;
4506 HRESULT hr;
4508 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4510 EnterCriticalSection(&This->cs);
4512 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4514 if (hr == S_OK)
4515 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4517 LeaveCriticalSection(&This->cs);
4519 return hr;
4522 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4524 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4525 IVideoWindow *pVideoWindow;
4526 HRESULT hr;
4528 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4530 EnterCriticalSection(&This->cs);
4532 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4534 if (hr == S_OK)
4535 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4537 LeaveCriticalSection(&This->cs);
4539 return hr;
4542 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4544 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4545 IVideoWindow *pVideoWindow;
4546 HRESULT hr;
4548 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4550 EnterCriticalSection(&This->cs);
4552 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4554 if (hr == S_OK)
4555 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4557 LeaveCriticalSection(&This->cs);
4559 return hr;
4562 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4564 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4565 IVideoWindow *pVideoWindow;
4566 HRESULT hr;
4568 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4570 EnterCriticalSection(&This->cs);
4572 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4574 if (hr == S_OK)
4575 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4577 LeaveCriticalSection(&This->cs);
4579 return hr;
4582 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4584 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4585 IVideoWindow *pVideoWindow;
4586 HRESULT hr;
4588 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4590 EnterCriticalSection(&This->cs);
4592 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4594 if (hr == S_OK)
4595 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4597 LeaveCriticalSection(&This->cs);
4599 return hr;
4602 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4603 LONG_PTR wParam, LONG_PTR lParam)
4605 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4606 IVideoWindow *pVideoWindow;
4607 HRESULT hr;
4609 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4611 EnterCriticalSection(&This->cs);
4613 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4615 if (hr == S_OK)
4616 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4618 LeaveCriticalSection(&This->cs);
4620 return hr;
4623 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4624 LONG Width, LONG Height)
4626 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4627 IVideoWindow *pVideoWindow;
4628 HRESULT hr;
4630 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4632 EnterCriticalSection(&This->cs);
4634 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4636 if (hr == S_OK)
4637 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4639 LeaveCriticalSection(&This->cs);
4641 return hr;
4644 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4645 LONG *pWidth, LONG *pHeight)
4647 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4648 IVideoWindow *pVideoWindow;
4649 HRESULT hr;
4651 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4653 EnterCriticalSection(&This->cs);
4655 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4657 if (hr == S_OK)
4658 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4660 LeaveCriticalSection(&This->cs);
4662 return hr;
4665 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4666 LONG *pHeight)
4668 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4669 IVideoWindow *pVideoWindow;
4670 HRESULT hr;
4672 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4674 EnterCriticalSection(&This->cs);
4676 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4678 if (hr == S_OK)
4679 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4681 LeaveCriticalSection(&This->cs);
4683 return hr;
4686 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4687 LONG *pHeight)
4689 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4690 IVideoWindow *pVideoWindow;
4691 HRESULT hr;
4693 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4695 EnterCriticalSection(&This->cs);
4697 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4699 if (hr == S_OK)
4700 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4702 LeaveCriticalSection(&This->cs);
4704 return hr;
4707 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4708 LONG *pWidth, LONG *pHeight)
4710 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4711 IVideoWindow *pVideoWindow;
4712 HRESULT hr;
4714 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4716 EnterCriticalSection(&This->cs);
4718 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4720 if (hr == S_OK)
4721 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4723 LeaveCriticalSection(&This->cs);
4725 return hr;
4728 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4730 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4731 IVideoWindow *pVideoWindow;
4732 HRESULT hr;
4734 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4736 EnterCriticalSection(&This->cs);
4738 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4740 if (hr == S_OK)
4741 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4743 LeaveCriticalSection(&This->cs);
4745 return hr;
4748 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4750 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4751 IVideoWindow *pVideoWindow;
4752 HRESULT hr;
4754 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4756 EnterCriticalSection(&This->cs);
4758 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4760 if (hr == S_OK)
4761 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4763 LeaveCriticalSection(&This->cs);
4765 return hr;
4769 static const IVideoWindowVtbl IVideoWindow_VTable =
4771 VideoWindow_QueryInterface,
4772 VideoWindow_AddRef,
4773 VideoWindow_Release,
4774 VideoWindow_GetTypeInfoCount,
4775 VideoWindow_GetTypeInfo,
4776 VideoWindow_GetIDsOfNames,
4777 VideoWindow_Invoke,
4778 VideoWindow_put_Caption,
4779 VideoWindow_get_Caption,
4780 VideoWindow_put_WindowStyle,
4781 VideoWindow_get_WindowStyle,
4782 VideoWindow_put_WindowStyleEx,
4783 VideoWindow_get_WindowStyleEx,
4784 VideoWindow_put_AutoShow,
4785 VideoWindow_get_AutoShow,
4786 VideoWindow_put_WindowState,
4787 VideoWindow_get_WindowState,
4788 VideoWindow_put_BackgroundPalette,
4789 VideoWindow_get_BackgroundPalette,
4790 VideoWindow_put_Visible,
4791 VideoWindow_get_Visible,
4792 VideoWindow_put_Left,
4793 VideoWindow_get_Left,
4794 VideoWindow_put_Width,
4795 VideoWindow_get_Width,
4796 VideoWindow_put_Top,
4797 VideoWindow_get_Top,
4798 VideoWindow_put_Height,
4799 VideoWindow_get_Height,
4800 VideoWindow_put_Owner,
4801 VideoWindow_get_Owner,
4802 VideoWindow_put_MessageDrain,
4803 VideoWindow_get_MessageDrain,
4804 VideoWindow_get_BorderColor,
4805 VideoWindow_put_BorderColor,
4806 VideoWindow_get_FullScreenMode,
4807 VideoWindow_put_FullScreenMode,
4808 VideoWindow_SetWindowForeground,
4809 VideoWindow_NotifyOwnerMessage,
4810 VideoWindow_SetWindowPosition,
4811 VideoWindow_GetWindowPosition,
4812 VideoWindow_GetMinIdealImageSize,
4813 VideoWindow_GetMaxIdealImageSize,
4814 VideoWindow_GetRestorePosition,
4815 VideoWindow_HideCursor,
4816 VideoWindow_IsCursorHidden
4819 static inline IFilterGraphImpl *impl_from_IMediaEventEx(IMediaEventEx *iface)
4821 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventEx_iface);
4824 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID riid, void **ppvObj)
4826 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4828 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
4830 return Filtergraph_QueryInterface(This, riid, ppvObj);
4833 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
4835 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4837 TRACE("(%p/%p)->()\n", This, iface);
4839 return Filtergraph_AddRef(This);
4842 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
4844 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4846 TRACE("(%p/%p)->()\n", This, iface);
4848 return Filtergraph_Release(This);
4851 /*** IDispatch methods ***/
4852 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *pctinfo)
4854 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4856 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
4858 return S_OK;
4861 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT iTInfo, LCID lcid,
4862 ITypeInfo **ppTInfo)
4864 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4866 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
4868 return S_OK;
4871 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID riid,
4872 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4874 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4876 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
4878 return S_OK;
4881 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID dispIdMember, REFIID riid,
4882 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4883 UINT *puArgErr)
4885 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4887 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);
4889 return S_OK;
4892 /*** IMediaEvent methods ***/
4893 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *hEvent)
4895 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4897 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
4899 *hEvent = (OAEVENT)This->evqueue.msg_event;
4901 return S_OK;
4904 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *lEventCode, LONG_PTR *lParam1,
4905 LONG_PTR *lParam2, LONG msTimeout)
4907 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4908 Event evt;
4910 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
4912 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
4914 *lEventCode = evt.lEventCode;
4915 *lParam1 = evt.lParam1;
4916 *lParam2 = evt.lParam2;
4917 return S_OK;
4920 *lEventCode = 0;
4921 return E_ABORT;
4924 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
4925 LONG *pEvCode)
4927 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4929 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
4931 if (This->state != State_Running)
4932 return VFW_E_WRONG_STATE;
4934 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
4936 *pEvCode = This->CompletionStatus;
4937 return S_OK;
4940 *pEvCode = 0;
4941 return E_ABORT;
4944 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
4946 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4948 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4950 if (lEvCode == EC_COMPLETE)
4951 This->HandleEcComplete = FALSE;
4952 else if (lEvCode == EC_REPAINT)
4953 This->HandleEcRepaint = FALSE;
4954 else if (lEvCode == EC_CLOCK_CHANGED)
4955 This->HandleEcClockChanged = FALSE;
4956 else
4957 return S_FALSE;
4959 return S_OK;
4962 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
4964 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4966 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4968 if (lEvCode == EC_COMPLETE)
4969 This->HandleEcComplete = TRUE;
4970 else if (lEvCode == EC_REPAINT)
4971 This->HandleEcRepaint = TRUE;
4972 else if (lEvCode == EC_CLOCK_CHANGED)
4973 This->HandleEcClockChanged = TRUE;
4974 else
4975 return S_FALSE;
4977 return S_OK;
4980 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG lEvCode,
4981 LONG_PTR lParam1, LONG_PTR lParam2)
4983 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4985 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
4987 return S_OK;
4990 /*** IMediaEventEx methods ***/
4991 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface, OAHWND hwnd, LONG lMsg,
4992 LONG_PTR lInstanceData)
4994 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4996 TRACE("(%p/%p)->(%08lx, %d, %08lx)\n", This, iface, hwnd, lMsg, lInstanceData);
4998 This->notif.hWnd = (HWND)hwnd;
4999 This->notif.msg = lMsg;
5000 This->notif.instance = lInstanceData;
5002 return S_OK;
5005 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG lNoNotifyFlags)
5007 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5009 TRACE("(%p/%p)->(%d)\n", This, iface, lNoNotifyFlags);
5011 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
5012 return E_INVALIDARG;
5014 This->notif.disabled = lNoNotifyFlags;
5016 return S_OK;
5019 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *lplNoNotifyFlags)
5021 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5023 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
5025 if (!lplNoNotifyFlags)
5026 return E_POINTER;
5028 *lplNoNotifyFlags = This->notif.disabled;
5030 return S_OK;
5034 static const IMediaEventExVtbl IMediaEventEx_VTable =
5036 MediaEvent_QueryInterface,
5037 MediaEvent_AddRef,
5038 MediaEvent_Release,
5039 MediaEvent_GetTypeInfoCount,
5040 MediaEvent_GetTypeInfo,
5041 MediaEvent_GetIDsOfNames,
5042 MediaEvent_Invoke,
5043 MediaEvent_GetEventHandle,
5044 MediaEvent_GetEvent,
5045 MediaEvent_WaitForCompletion,
5046 MediaEvent_CancelDefaultHandling,
5047 MediaEvent_RestoreDefaultHandling,
5048 MediaEvent_FreeEventParams,
5049 MediaEvent_SetNotifyWindow,
5050 MediaEvent_SetNotifyFlags,
5051 MediaEvent_GetNotifyFlags
5055 static inline IFilterGraphImpl *impl_from_IMediaFilter(IMediaFilter *iface)
5057 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaFilter_iface);
5060 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, void **ppv)
5062 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5064 return Filtergraph_QueryInterface(This, riid, ppv);
5067 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
5069 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5071 return Filtergraph_AddRef(This);
5074 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
5076 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5078 return Filtergraph_Release(This);
5081 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
5083 FIXME("(%p): stub\n", pClassID);
5085 return E_NOTIMPL;
5088 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
5090 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5092 return MediaControl_Stop(&This->IMediaControl_iface);
5095 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5097 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5099 return MediaControl_Pause(&This->IMediaControl_iface);
5102 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
5104 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5106 if (tStart)
5107 FIXME("Run called with non-null tStart: %x%08x\n",
5108 (int)(tStart>>32), (int)tStart);
5110 return MediaControl_Run(&This->IMediaControl_iface);
5113 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout,
5114 FILTER_STATE *pState)
5116 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5118 return MediaControl_GetState(&This->IMediaControl_iface, dwMsTimeout, (OAFilterState*)pState);
5121 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5123 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5124 HRESULT hr = S_OK;
5125 int i;
5127 TRACE("(%p/%p)->(%p)\n", iface, This, pClock);
5129 EnterCriticalSection(&This->cs);
5131 for (i = 0;i < This->nFilters;i++)
5133 hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5134 if (FAILED(hr))
5135 break;
5138 if (FAILED(hr))
5140 for(;i >= 0;i--)
5141 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5143 else
5145 if (This->refClock)
5146 IReferenceClock_Release(This->refClock);
5147 This->refClock = pClock;
5148 if (This->refClock)
5149 IReferenceClock_AddRef(This->refClock);
5150 This->defaultclock = FALSE;
5152 if (This->HandleEcClockChanged)
5154 IMediaEventSink *pEventSink;
5155 HRESULT eshr;
5157 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (LPVOID)&pEventSink);
5158 if (SUCCEEDED(eshr))
5160 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5161 IMediaEventSink_Release(pEventSink);
5166 LeaveCriticalSection(&This->cs);
5168 return hr;
5171 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5173 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5175 TRACE("(%p/%p)->(%p)\n", iface, This, ppClock);
5177 if (!ppClock)
5178 return E_POINTER;
5180 EnterCriticalSection(&This->cs);
5182 *ppClock = This->refClock;
5183 if (*ppClock)
5184 IReferenceClock_AddRef(*ppClock);
5186 LeaveCriticalSection(&This->cs);
5188 return S_OK;
5191 static const IMediaFilterVtbl IMediaFilter_VTable =
5193 MediaFilter_QueryInterface,
5194 MediaFilter_AddRef,
5195 MediaFilter_Release,
5196 MediaFilter_GetClassID,
5197 MediaFilter_Stop,
5198 MediaFilter_Pause,
5199 MediaFilter_Run,
5200 MediaFilter_GetState,
5201 MediaFilter_SetSyncSource,
5202 MediaFilter_GetSyncSource
5205 static inline IFilterGraphImpl *impl_from_IMediaEventSink(IMediaEventSink *iface)
5207 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventSink_iface);
5210 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, void **ppv)
5212 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5214 return Filtergraph_QueryInterface(This, riid, ppv);
5217 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5219 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5221 return Filtergraph_AddRef(This);
5224 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5226 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5228 return Filtergraph_Release(This);
5231 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG EventCode,
5232 LONG_PTR EventParam1, LONG_PTR EventParam2)
5234 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5235 Event evt;
5237 TRACE("(%p/%p)->(%d, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5239 /* We need thread safety here, let's use the events queue's one */
5240 EnterCriticalSection(&This->evqueue.msg_crst);
5242 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5244 TRACE("Process EC_COMPLETE notification\n");
5245 if (++This->EcCompleteCount == This->nRenderers)
5247 evt.lEventCode = EC_COMPLETE;
5248 evt.lParam1 = S_OK;
5249 evt.lParam2 = 0;
5250 TRACE("Send EC_COMPLETE to app\n");
5251 EventsQueue_PutEvent(&This->evqueue, &evt);
5252 if (!This->notif.disabled && This->notif.hWnd)
5254 TRACE("Send Window message\n");
5255 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5257 This->CompletionStatus = EC_COMPLETE;
5258 SetEvent(This->hEventCompletion);
5261 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5263 /* FIXME: Not handled yet */
5265 else
5267 evt.lEventCode = EventCode;
5268 evt.lParam1 = EventParam1;
5269 evt.lParam2 = EventParam2;
5270 EventsQueue_PutEvent(&This->evqueue, &evt);
5271 if (!This->notif.disabled && This->notif.hWnd)
5272 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5275 LeaveCriticalSection(&This->evqueue.msg_crst);
5276 return S_OK;
5279 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5281 MediaEventSink_QueryInterface,
5282 MediaEventSink_AddRef,
5283 MediaEventSink_Release,
5284 MediaEventSink_Notify
5287 static inline IFilterGraphImpl *impl_from_IGraphConfig(IGraphConfig *iface)
5289 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphConfig_iface);
5292 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, void **ppv)
5294 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5296 return Filtergraph_QueryInterface(This, riid, ppv);
5299 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5301 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5303 return Filtergraph_AddRef(This);
5306 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5308 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5310 return Filtergraph_Release(This);
5313 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *pOutputPin, IPin *pInputPin,
5314 const AM_MEDIA_TYPE *pmtFirstConnection, IBaseFilter *pUsingFilter, HANDLE hAbortEvent,
5315 DWORD dwFlags)
5317 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5319 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5321 return E_NOTIMPL;
5324 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface, IGraphConfigCallback *pCallback,
5325 void *pvContext, DWORD dwFlags, HANDLE hAbortEvent)
5327 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5328 HRESULT hr;
5330 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5332 if (hAbortEvent)
5333 FIXME("The parameter hAbortEvent is not handled!\n");
5335 EnterCriticalSection(&This->cs);
5337 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5339 LeaveCriticalSection(&This->cs);
5341 return hr;
5344 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5346 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5348 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5350 return E_NOTIMPL;
5353 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5355 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5357 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5359 return E_NOTIMPL;
5362 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5364 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5366 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5368 return E_NOTIMPL;
5371 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5373 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5375 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5377 return E_NOTIMPL;
5380 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5381 IPinConnection *pConnection, HANDLE hEventAbort)
5383 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5385 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5387 return E_NOTIMPL;
5390 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5391 DWORD dwFlags)
5393 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5395 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5397 return E_NOTIMPL;
5400 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5401 DWORD *dwFlags)
5403 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5405 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5407 return E_NOTIMPL;
5410 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *pFilter,
5411 DWORD dwFlags)
5413 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5415 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5417 return E_NOTIMPL;
5420 static const IGraphConfigVtbl IGraphConfig_VTable =
5422 GraphConfig_QueryInterface,
5423 GraphConfig_AddRef,
5424 GraphConfig_Release,
5425 GraphConfig_Reconnect,
5426 GraphConfig_Reconfigure,
5427 GraphConfig_AddFilterToCache,
5428 GraphConfig_EnumCacheFilter,
5429 GraphConfig_RemoveFilterFromCache,
5430 GraphConfig_GetStartTime,
5431 GraphConfig_PushThroughData,
5432 GraphConfig_SetFilterFlags,
5433 GraphConfig_GetFilterFlags,
5434 GraphConfig_RemoveFilterEx
5437 static const IUnknownVtbl IInner_VTable =
5439 FilterGraphInner_QueryInterface,
5440 FilterGraphInner_AddRef,
5441 FilterGraphInner_Release
5444 static HRESULT Filtergraph_QueryInterface(IFilterGraphImpl *This,
5445 REFIID riid,
5446 LPVOID * ppv) {
5447 if (This->bAggregatable)
5448 This->bUnkOuterValid = TRUE;
5450 if (This->pUnkOuter)
5452 if (This->bAggregatable)
5453 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
5455 if (IsEqualIID(riid, &IID_IUnknown))
5457 HRESULT hr;
5459 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5460 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5461 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5462 This->bAggregatable = TRUE;
5463 return hr;
5466 *ppv = NULL;
5467 return E_NOINTERFACE;
5470 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5473 static ULONG Filtergraph_AddRef(IFilterGraphImpl *This) {
5474 if (This->pUnkOuter && This->bUnkOuterValid)
5475 return IUnknown_AddRef(This->pUnkOuter);
5476 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5479 static ULONG Filtergraph_Release(IFilterGraphImpl *This) {
5480 if (This->pUnkOuter && This->bUnkOuterValid)
5481 return IUnknown_Release(This->pUnkOuter);
5482 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5485 /* This is the only function that actually creates a FilterGraph class... */
5486 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5488 IFilterGraphImpl *fimpl;
5489 HRESULT hr;
5491 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5493 *ppObj = NULL;
5495 fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5496 fimpl->pUnkOuter = pUnkOuter;
5497 fimpl->bUnkOuterValid = FALSE;
5498 fimpl->bAggregatable = FALSE;
5499 fimpl->defaultclock = TRUE;
5500 fimpl->IInner_vtbl = &IInner_VTable;
5501 fimpl->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5502 fimpl->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5503 fimpl->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5504 fimpl->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5505 fimpl->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5506 fimpl->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5507 fimpl->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5508 fimpl->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5509 fimpl->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5510 fimpl->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5511 fimpl->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5512 fimpl->ref = 1;
5513 fimpl->ppFiltersInGraph = NULL;
5514 fimpl->pFilterNames = NULL;
5515 fimpl->nFilters = 0;
5516 fimpl->filterCapacity = 0;
5517 fimpl->nameIndex = 1;
5518 fimpl->refClock = NULL;
5519 fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5520 fimpl->HandleEcComplete = TRUE;
5521 fimpl->HandleEcRepaint = TRUE;
5522 fimpl->HandleEcClockChanged = TRUE;
5523 fimpl->notif.hWnd = 0;
5524 fimpl->notif.disabled = FALSE;
5525 fimpl->nRenderers = 0;
5526 fimpl->EcCompleteCount = 0;
5527 fimpl->refClockProvider = NULL;
5528 fimpl->state = State_Stopped;
5529 EventsQueue_Init(&fimpl->evqueue);
5530 InitializeCriticalSection(&fimpl->cs);
5531 fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5532 fimpl->nItfCacheEntries = 0;
5533 memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5534 fimpl->start_time = fimpl->pause_time = 0;
5535 fimpl->stop_position = -1;
5536 fimpl->punkFilterMapper2 = NULL;
5537 fimpl->recursioncount = 0;
5539 /* create Filtermapper aggregated. */
5540 hr = CoCreateInstance(&CLSID_FilterMapper2, pUnkOuter ? pUnkOuter : (IUnknown*)&fimpl->IInner_vtbl, CLSCTX_INPROC_SERVER,
5541 &IID_IUnknown, (LPVOID*)&fimpl->punkFilterMapper2);
5543 if (SUCCEEDED(hr)) {
5544 hr = IUnknown_QueryInterface(fimpl->punkFilterMapper2, &IID_IFilterMapper2, (LPVOID*)&fimpl->pFilterMapper2);
5547 if (SUCCEEDED(hr)) {
5548 /* Release controlling IUnknown - compensate refcount increase from caching IFilterMapper2 interface. */
5549 if (pUnkOuter) IUnknown_Release(pUnkOuter);
5550 else IUnknown_Release((IUnknown*)&fimpl->IInner_vtbl);
5553 if (FAILED(hr)) {
5554 ERR("Unable to create filter mapper (%x)\n", hr);
5555 if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5556 CloseHandle(fimpl->hEventCompletion);
5557 EventsQueue_Destroy(&fimpl->evqueue);
5558 fimpl->cs.DebugInfo->Spare[0] = 0;
5559 DeleteCriticalSection(&fimpl->cs);
5560 CoTaskMemFree(fimpl);
5561 return hr;
5564 *ppObj = fimpl;
5565 return S_OK;
5568 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5570 FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5571 return FilterGraph_create(pUnkOuter, ppObj);