dbghelp: Don't parse the DWARF info from Mach-O files if we were requested to only...
[wine.git] / dlls / quartz / filtergraph.c
blob26a40807e24861fd07d722a5f794ab7de3ddb9d6
1 /* DirectShow FilterGraph object (QUARTZ.DLL)
3 * Copyright 2002 Lionel Ulmer
4 * Copyright 2004 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include <stdarg.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "shlwapi.h"
31 #include "dshow.h"
32 #include "wine/debug.h"
33 #include "quartz_private.h"
34 #include "ole2.h"
35 #include "olectl.h"
36 #include "strmif.h"
37 #include "vfwmsgs.h"
38 #include "evcode.h"
39 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
44 typedef struct {
45 HWND hWnd; /* Target window */
46 UINT msg; /* User window message */
47 LONG_PTR instance; /* User data */
48 int disabled; /* Disabled messages posting */
49 } WndNotify;
51 typedef struct {
52 LONG lEventCode; /* Event code */
53 LONG_PTR lParam1; /* Param1 */
54 LONG_PTR lParam2; /* Param2 */
55 } Event;
57 /* messages ring implementation for queuing events (taken from winmm) */
58 #define EVENTS_RING_BUFFER_INCREMENT 64
59 typedef struct {
60 Event* messages;
61 int ring_buffer_size;
62 int msg_tosave;
63 int msg_toget;
64 CRITICAL_SECTION msg_crst;
65 HANDLE msg_event; /* Signaled for no empty queue */
66 } EventsQueue;
68 static int EventsQueue_Init(EventsQueue* omr)
70 omr->msg_toget = 0;
71 omr->msg_tosave = 0;
72 omr->msg_event = CreateEventW(NULL, TRUE, FALSE, NULL);
73 omr->ring_buffer_size = EVENTS_RING_BUFFER_INCREMENT;
74 omr->messages = CoTaskMemAlloc(omr->ring_buffer_size * sizeof(Event));
75 ZeroMemory(omr->messages, omr->ring_buffer_size * sizeof(Event));
77 InitializeCriticalSection(&omr->msg_crst);
78 omr->msg_crst.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": EventsQueue.msg_crst");
79 return TRUE;
82 static int EventsQueue_Destroy(EventsQueue* omr)
84 CloseHandle(omr->msg_event);
85 CoTaskMemFree(omr->messages);
86 omr->msg_crst.DebugInfo->Spare[0] = 0;
87 DeleteCriticalSection(&omr->msg_crst);
88 return TRUE;
91 static BOOL EventsQueue_PutEvent(EventsQueue* omr, const Event* evt)
93 EnterCriticalSection(&omr->msg_crst);
94 if (omr->msg_toget == ((omr->msg_tosave + 1) % omr->ring_buffer_size))
96 int old_ring_buffer_size = omr->ring_buffer_size;
97 omr->ring_buffer_size += EVENTS_RING_BUFFER_INCREMENT;
98 TRACE("omr->ring_buffer_size=%d\n",omr->ring_buffer_size);
99 omr->messages = CoTaskMemRealloc(omr->messages, omr->ring_buffer_size * sizeof(Event));
100 /* Now we need to rearrange the ring buffer so that the new
101 buffers just allocated are in between omr->msg_tosave and
102 omr->msg_toget.
104 if (omr->msg_tosave < omr->msg_toget)
106 memmove(&(omr->messages[omr->msg_toget + EVENTS_RING_BUFFER_INCREMENT]),
107 &(omr->messages[omr->msg_toget]),
108 sizeof(Event)*(old_ring_buffer_size - omr->msg_toget)
110 omr->msg_toget += EVENTS_RING_BUFFER_INCREMENT;
113 omr->messages[omr->msg_tosave] = *evt;
114 SetEvent(omr->msg_event);
115 omr->msg_tosave = (omr->msg_tosave + 1) % omr->ring_buffer_size;
116 LeaveCriticalSection(&omr->msg_crst);
117 return TRUE;
120 static BOOL EventsQueue_GetEvent(EventsQueue* omr, Event* evt, LONG msTimeOut)
122 if (WaitForSingleObject(omr->msg_event, msTimeOut) != WAIT_OBJECT_0)
123 return FALSE;
125 EnterCriticalSection(&omr->msg_crst);
127 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
129 LeaveCriticalSection(&omr->msg_crst);
130 return FALSE;
133 *evt = omr->messages[omr->msg_toget];
134 omr->msg_toget = (omr->msg_toget + 1) % omr->ring_buffer_size;
136 /* Mark the buffer as empty if needed */
137 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
138 ResetEvent(omr->msg_event);
140 LeaveCriticalSection(&omr->msg_crst);
141 return TRUE;
144 #define MAX_ITF_CACHE_ENTRIES 3
145 typedef struct _ITF_CACHE_ENTRY {
146 const IID* riid;
147 IBaseFilter* filter;
148 IUnknown* iface;
149 } ITF_CACHE_ENTRY;
151 typedef struct _IFilterGraphImpl {
152 IUnknown IUnknown_inner;
153 IFilterGraph2 IFilterGraph2_iface;
154 IMediaControl IMediaControl_iface;
155 IMediaSeeking IMediaSeeking_iface;
156 IBasicAudio IBasicAudio_iface;
157 IBasicVideo2 IBasicVideo2_iface;
158 IVideoWindow IVideoWindow_iface;
159 IMediaEventEx IMediaEventEx_iface;
160 IMediaFilter IMediaFilter_iface;
161 IMediaEventSink IMediaEventSink_iface;
162 IGraphConfig IGraphConfig_iface;
163 IMediaPosition IMediaPosition_iface;
164 IObjectWithSite IObjectWithSite_iface;
165 IGraphVersion IGraphVersion_iface;
166 /* IAMGraphStreams */
167 /* IAMStats */
168 /* IFilterChain */
169 /* IFilterMapper2 */
170 /* IQueueCommand */
171 /* IRegisterServiceProvider */
172 /* IResourceMananger */
173 /* IServiceProvider */
174 /* IVideoFrameStep */
176 IUnknown *outer_unk;
177 LONG ref;
178 IUnknown *punkFilterMapper2;
179 IFilterMapper2 * pFilterMapper2;
180 IBaseFilter ** ppFiltersInGraph;
181 LPWSTR * pFilterNames;
182 ULONG nFilters;
183 int filterCapacity;
184 LONG nameIndex;
185 IReferenceClock *refClock;
186 IBaseFilter *refClockProvider;
187 EventsQueue evqueue;
188 HANDLE hEventCompletion;
189 int CompletionStatus;
190 WndNotify notif;
191 int nRenderers;
192 int EcCompleteCount;
193 int HandleEcComplete;
194 int HandleEcRepaint;
195 int HandleEcClockChanged;
196 OAFilterState state;
197 CRITICAL_SECTION cs;
198 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
199 int nItfCacheEntries;
200 BOOL defaultclock;
201 GUID timeformatseek;
202 REFERENCE_TIME start_time;
203 REFERENCE_TIME pause_time;
204 LONGLONG stop_position;
205 LONG recursioncount;
206 IUnknown *pSite;
207 LONG version;
208 } IFilterGraphImpl;
210 static inline IFilterGraphImpl *impl_from_IUnknown(IUnknown *iface)
212 return CONTAINING_RECORD(iface, IFilterGraphImpl, IUnknown_inner);
215 static HRESULT WINAPI FilterGraphInner_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObj)
217 IFilterGraphImpl *This = impl_from_IUnknown(iface);
218 TRACE("(%p)->(%s (%p), %p)\n", This, debugstr_guid(riid), riid, ppvObj);
220 if (IsEqualGUID(&IID_IUnknown, riid)) {
221 *ppvObj = &This->IUnknown_inner;
222 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
223 } else if (IsEqualGUID(&IID_IFilterGraph, riid) ||
224 IsEqualGUID(&IID_IFilterGraph2, riid) ||
225 IsEqualGUID(&IID_IGraphBuilder, riid)) {
226 *ppvObj = &This->IFilterGraph2_iface;
227 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj);
228 } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
229 *ppvObj = &This->IMediaControl_iface;
230 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj);
231 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
232 *ppvObj = &This->IMediaSeeking_iface;
233 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
234 } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
235 *ppvObj = &This->IBasicAudio_iface;
236 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj);
237 } else if (IsEqualGUID(&IID_IBasicVideo, riid) ||
238 IsEqualGUID(&IID_IBasicVideo2, riid)) {
239 *ppvObj = &This->IBasicVideo2_iface;
240 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj);
241 } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
242 *ppvObj = &This->IVideoWindow_iface;
243 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj);
244 } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
245 IsEqualGUID(&IID_IMediaEventEx, riid)) {
246 *ppvObj = &This->IMediaEventEx_iface;
247 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
248 } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
249 IsEqualGUID(&IID_IPersist, riid)) {
250 *ppvObj = &This->IMediaFilter_iface;
251 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj);
252 } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
253 *ppvObj = &This->IMediaEventSink_iface;
254 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj);
255 } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
256 *ppvObj = &This->IGraphConfig_iface;
257 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
258 } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
259 *ppvObj = &This->IMediaPosition_iface;
260 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj);
261 } else if (IsEqualGUID(&IID_IObjectWithSite, riid)) {
262 *ppvObj = &This->IObjectWithSite_iface;
263 TRACE(" returning IObjectWithSite interface (%p)\n", *ppvObj);
264 } else if (IsEqualGUID(&IID_IFilterMapper, riid)) {
265 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj);
266 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
267 } else if (IsEqualGUID(&IID_IFilterMapper2, riid)) {
268 *ppvObj = This->pFilterMapper2;
269 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
270 } else if (IsEqualGUID(&IID_IFilterMapper3, riid)) {
271 *ppvObj = This->pFilterMapper2;
272 TRACE(" returning IFilterMapper3 interface from aggregated filtermapper (%p)\n", *ppvObj);
273 } else if (IsEqualGUID(&IID_IGraphVersion, riid)) {
274 *ppvObj = &This->IGraphConfig_iface;
275 TRACE(" returning IGraphConfig interface (%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)
288 IFilterGraphImpl *This = impl_from_IUnknown(iface);
289 ULONG ref = InterlockedIncrement(&This->ref);
291 TRACE("(%p)->(): new ref = %d\n", This, ref);
293 return ref;
296 static ULONG WINAPI FilterGraphInner_Release(IUnknown *iface)
298 IFilterGraphImpl *This = impl_from_IUnknown(iface);
299 ULONG ref = InterlockedDecrement(&This->ref);
301 TRACE("(%p)->(): new ref = %d\n", This, ref);
303 if (ref == 0) {
304 int i;
306 This->ref = 1; /* guard against reentrancy (aggregation). */
308 IMediaControl_Stop(&This->IMediaControl_iface);
310 while (This->nFilters)
311 IFilterGraph2_RemoveFilter(&This->IFilterGraph2_iface, This->ppFiltersInGraph[0]);
313 if (This->refClock)
314 IReferenceClock_Release(This->refClock);
316 for (i = 0; i < This->nItfCacheEntries; i++)
318 if (This->ItfCacheEntries[i].iface)
319 IUnknown_Release(This->ItfCacheEntries[i].iface);
322 /* AddRef on controlling IUnknown, to compensate for Release of cached IFilterMapper2 */
323 IUnknown_AddRef(This->outer_unk);
324 IFilterMapper2_Release(This->pFilterMapper2);
325 IUnknown_Release(This->punkFilterMapper2);
327 if (This->pSite) IUnknown_Release(This->pSite);
329 CloseHandle(This->hEventCompletion);
330 EventsQueue_Destroy(&This->evqueue);
331 This->cs.DebugInfo->Spare[0] = 0;
332 DeleteCriticalSection(&This->cs);
333 CoTaskMemFree(This->ppFiltersInGraph);
334 CoTaskMemFree(This->pFilterNames);
335 CoTaskMemFree(This);
337 return ref;
340 static inline IFilterGraphImpl *impl_from_IFilterGraph2(IFilterGraph2 *iface)
342 return CONTAINING_RECORD(iface, IFilterGraphImpl, IFilterGraph2_iface);
345 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface, REFIID riid, void **ppvObj)
347 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
349 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
351 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
354 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface)
356 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
358 TRACE("(%p/%p)->()\n", This, iface);
360 return IUnknown_AddRef(This->outer_unk);
363 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface)
365 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
367 TRACE("(%p/%p)->()\n", This, iface);
369 return IUnknown_Release(This->outer_unk);
372 /*** IFilterGraph methods ***/
373 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface, IBaseFilter *pFilter,
374 LPCWSTR pName)
376 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
377 HRESULT hr;
378 int i,j;
379 WCHAR* wszFilterName = NULL;
380 BOOL duplicate_name = FALSE;
382 TRACE("(%p/%p)->(%p, %s (%p))\n", This, iface, pFilter, debugstr_w(pName), pName);
384 if (!pFilter)
385 return E_POINTER;
387 wszFilterName = CoTaskMemAlloc( (pName ? strlenW(pName) + 6 : 5) * sizeof(WCHAR) );
389 if (pName)
391 /* Check if name already exists */
392 for(i = 0; i < This->nFilters; i++)
393 if (!strcmpW(This->pFilterNames[i], pName))
395 duplicate_name = TRUE;
396 break;
400 /* If no name given or name already existing, generate one */
401 if (!pName || duplicate_name)
403 static const WCHAR wszFmt1[] = {'%','s',' ','%','0','4','d',0};
404 static const WCHAR wszFmt2[] = {'%','0','4','d',0};
406 for (j = 0; j < 10000 ; j++)
408 /* Create name */
409 if (pName)
410 sprintfW(wszFilterName, wszFmt1, pName, This->nameIndex);
411 else
412 sprintfW(wszFilterName, wszFmt2, This->nameIndex);
413 TRACE("Generated name %s\n", debugstr_w(wszFilterName));
415 /* Check if the generated name already exists */
416 for(i = 0; i < This->nFilters; i++)
417 if (!strcmpW(This->pFilterNames[i], wszFilterName))
418 break;
420 /* Compute next index and exit if generated name is suitable */
421 if (This->nameIndex++ == 10000)
422 This->nameIndex = 1;
423 if (i == This->nFilters)
424 break;
426 /* Unable to find a suitable name */
427 if (j == 10000)
429 CoTaskMemFree(wszFilterName);
430 return VFW_E_DUPLICATE_NAME;
433 else
434 memcpy(wszFilterName, pName, (strlenW(pName) + 1) * sizeof(WCHAR));
436 if (This->nFilters + 1 > This->filterCapacity)
438 int newCapacity = This->filterCapacity ? 2 * This->filterCapacity : 1;
439 IBaseFilter ** ppNewFilters = CoTaskMemAlloc(newCapacity * sizeof(IBaseFilter*));
440 LPWSTR * pNewNames = CoTaskMemAlloc(newCapacity * sizeof(LPWSTR));
441 memcpy(ppNewFilters, This->ppFiltersInGraph, This->nFilters * sizeof(IBaseFilter*));
442 memcpy(pNewNames, This->pFilterNames, This->nFilters * sizeof(LPWSTR));
443 if (This->filterCapacity)
445 CoTaskMemFree(This->ppFiltersInGraph);
446 CoTaskMemFree(This->pFilterNames);
448 This->ppFiltersInGraph = ppNewFilters;
449 This->pFilterNames = pNewNames;
450 This->filterCapacity = newCapacity;
453 hr = IBaseFilter_JoinFilterGraph(pFilter, (IFilterGraph *)&This->IFilterGraph2_iface, wszFilterName);
455 if (SUCCEEDED(hr))
457 IBaseFilter_AddRef(pFilter);
458 This->ppFiltersInGraph[This->nFilters] = pFilter;
459 This->pFilterNames[This->nFilters] = wszFilterName;
460 This->nFilters++;
461 This->version++;
462 IBaseFilter_SetSyncSource(pFilter, This->refClock);
464 else
465 CoTaskMemFree(wszFilterName);
467 if (SUCCEEDED(hr) && duplicate_name)
468 return VFW_S_DUPLICATE_NAME;
470 return hr;
473 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
475 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
476 int i;
477 HRESULT hr = E_FAIL;
479 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
481 /* FIXME: check graph is stopped */
483 for (i = 0; i < This->nFilters; i++)
485 if (This->ppFiltersInGraph[i] == pFilter)
487 IEnumPins *penumpins = NULL;
488 FILTER_STATE state;
490 if (This->defaultclock && This->refClockProvider == pFilter)
492 IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, NULL);
493 This->defaultclock = TRUE;
496 TRACE("Removing filter %s\n", debugstr_w(This->pFilterNames[i]));
497 IBaseFilter_GetState(pFilter, 0, &state);
498 if (state == State_Running)
499 IBaseFilter_Pause(pFilter);
500 if (state != State_Stopped)
501 IBaseFilter_Stop(pFilter);
503 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
504 if (SUCCEEDED(hr)) {
505 IPin *ppin;
506 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
508 IPin *victim = NULL;
509 HRESULT h;
510 IPin_ConnectedTo(ppin, &victim);
511 if (victim)
513 h = IPin_Disconnect(victim);
514 TRACE("Disconnect other side: %08x\n", h);
515 if (h == VFW_E_NOT_STOPPED)
517 PIN_INFO pinfo;
518 IPin_QueryPinInfo(victim, &pinfo);
520 IBaseFilter_GetState(pinfo.pFilter, 0, &state);
521 if (state == State_Running)
522 IBaseFilter_Pause(pinfo.pFilter);
523 IBaseFilter_Stop(pinfo.pFilter);
524 IBaseFilter_Release(pinfo.pFilter);
525 h = IPin_Disconnect(victim);
526 TRACE("Disconnect retry: %08x\n", h);
528 IPin_Release(victim);
530 h = IPin_Disconnect(ppin);
531 TRACE("Disconnect 2: %08x\n", h);
533 IPin_Release(ppin);
535 IEnumPins_Release(penumpins);
538 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, This->pFilterNames[i]);
539 if (SUCCEEDED(hr))
541 IBaseFilter_SetSyncSource(pFilter, NULL);
542 IBaseFilter_Release(pFilter);
543 CoTaskMemFree(This->pFilterNames[i]);
544 memmove(This->ppFiltersInGraph+i, This->ppFiltersInGraph+i+1, sizeof(IBaseFilter*)*(This->nFilters - 1 - i));
545 memmove(This->pFilterNames+i, This->pFilterNames+i+1, sizeof(LPWSTR)*(This->nFilters - 1 - i));
546 This->nFilters--;
547 This->version++;
548 /* Invalidate interfaces in the cache */
549 for (i = 0; i < This->nItfCacheEntries; i++)
550 if (pFilter == This->ItfCacheEntries[i].filter)
552 IUnknown_Release(This->ItfCacheEntries[i].iface);
553 This->ItfCacheEntries[i].iface = NULL;
554 This->ItfCacheEntries[i].filter = NULL;
556 return S_OK;
558 break;
562 return hr; /* FIXME: check this error code */
565 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface, IEnumFilters **ppEnum)
567 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
569 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
571 return IEnumFiltersImpl_Construct(&This->IGraphVersion_iface, &This->ppFiltersInGraph, &This->nFilters, ppEnum);
574 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface, LPCWSTR pName,
575 IBaseFilter **ppFilter)
577 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
578 int i;
580 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_w(pName), pName, ppFilter);
582 if (!ppFilter)
583 return E_POINTER;
585 for (i = 0; i < This->nFilters; i++)
587 if (!strcmpW(pName, This->pFilterNames[i]))
589 *ppFilter = This->ppFiltersInGraph[i];
590 IBaseFilter_AddRef(*ppFilter);
591 return S_OK;
595 *ppFilter = NULL;
596 return VFW_E_NOT_FOUND;
599 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
600 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
602 static HRESULT CheckCircularConnection(IFilterGraphImpl *This, IPin *out, IPin *in)
604 #if 1
605 HRESULT hr;
606 PIN_INFO info_out, info_in;
608 hr = IPin_QueryPinInfo(out, &info_out);
609 if (FAILED(hr))
610 return hr;
611 if (info_out.dir != PINDIR_OUTPUT)
613 IBaseFilter_Release(info_out.pFilter);
614 return E_UNEXPECTED;
617 hr = IPin_QueryPinInfo(in, &info_in);
618 if (SUCCEEDED(hr))
619 IBaseFilter_Release(info_in.pFilter);
620 if (FAILED(hr))
621 goto out;
622 if (info_in.dir != PINDIR_INPUT)
624 hr = E_UNEXPECTED;
625 goto out;
628 if (info_out.pFilter == info_in.pFilter)
629 hr = VFW_E_CIRCULAR_GRAPH;
630 else
632 IEnumPins *enumpins;
633 IPin *test;
635 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
636 if (FAILED(hr))
637 goto out;
639 IEnumPins_Reset(enumpins);
640 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
642 PIN_DIRECTION dir = PINDIR_OUTPUT;
643 IPin_QueryDirection(test, &dir);
644 if (dir == PINDIR_INPUT)
646 IPin *victim = NULL;
647 IPin_ConnectedTo(test, &victim);
648 if (victim)
650 hr = CheckCircularConnection(This, victim, in);
651 IPin_Release(victim);
652 if (FAILED(hr))
654 IPin_Release(test);
655 break;
659 IPin_Release(test);
661 IEnumPins_Release(enumpins);
664 out:
665 IBaseFilter_Release(info_out.pFilter);
666 if (FAILED(hr))
667 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
668 return hr;
669 #else
670 /* Debugging filtergraphs not enabled */
671 return S_OK;
672 #endif
676 /* NOTE: despite the implication, it doesn't matter which
677 * way round you put in the input and output pins */
678 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppinIn, IPin *ppinOut,
679 const AM_MEDIA_TYPE *pmt)
681 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
682 PIN_DIRECTION dir;
683 HRESULT hr;
685 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
687 /* FIXME: check pins are in graph */
689 if (TRACE_ON(quartz))
691 PIN_INFO PinInfo;
693 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
694 if (FAILED(hr))
695 return hr;
697 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
698 IBaseFilter_Release(PinInfo.pFilter);
700 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
701 if (FAILED(hr))
702 return hr;
704 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
705 IBaseFilter_Release(PinInfo.pFilter);
708 hr = IPin_QueryDirection(ppinIn, &dir);
709 if (SUCCEEDED(hr))
711 if (dir == PINDIR_INPUT)
713 hr = CheckCircularConnection(This, ppinOut, ppinIn);
714 if (SUCCEEDED(hr))
715 hr = IPin_Connect(ppinOut, ppinIn, pmt);
717 else
719 hr = CheckCircularConnection(This, ppinIn, ppinOut);
720 if (SUCCEEDED(hr))
721 hr = IPin_Connect(ppinIn, ppinOut, pmt);
725 return hr;
728 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface, IPin *ppin)
730 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
731 IPin *pConnectedTo = NULL;
732 HRESULT hr;
733 PIN_DIRECTION pindir;
735 IPin_QueryDirection(ppin, &pindir);
736 hr = IPin_ConnectedTo(ppin, &pConnectedTo);
737 if (FAILED(hr)) {
738 TRACE("Querying connected to failed: %x\n", hr);
739 return hr;
741 IPin_Disconnect(ppin);
742 IPin_Disconnect(pConnectedTo);
743 if (pindir == PINDIR_INPUT)
744 hr = IPin_Connect(pConnectedTo, ppin, NULL);
745 else
746 hr = IPin_Connect(ppin, pConnectedTo, NULL);
747 IPin_Release(pConnectedTo);
748 if (FAILED(hr))
749 WARN("Reconnecting pins failed, pins are not connected now..\n");
750 TRACE("(%p->%p) -- %p %p -> %x\n", iface, This, ppin, pConnectedTo, hr);
751 return hr;
754 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
756 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
758 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
760 if (!ppin)
761 return E_POINTER;
763 return IPin_Disconnect(ppin);
766 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
768 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
769 IReferenceClock *pClock = NULL;
770 HRESULT hr = S_OK;
771 int i;
773 TRACE("(%p/%p)->() live sources not handled properly!\n", iface, This);
775 EnterCriticalSection(&This->cs);
777 for (i = 0; i < This->nFilters; ++i)
779 DWORD miscflags;
780 IAMFilterMiscFlags *flags = NULL;
781 IBaseFilter_QueryInterface(This->ppFiltersInGraph[i], &IID_IAMFilterMiscFlags, (void**)&flags);
782 if (!flags)
783 continue;
784 miscflags = IAMFilterMiscFlags_GetMiscFlags(flags);
785 IAMFilterMiscFlags_Release(flags);
786 if (miscflags == AM_FILTER_MISC_FLAGS_IS_RENDERER)
787 IBaseFilter_QueryInterface(This->ppFiltersInGraph[i], &IID_IReferenceClock, (void**)&pClock);
788 if (pClock)
789 break;
792 if (!pClock)
794 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
795 This->refClockProvider = NULL;
797 else
798 This->refClockProvider = This->ppFiltersInGraph[i];
800 if (SUCCEEDED(hr))
802 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
803 This->defaultclock = TRUE;
804 IReferenceClock_Release(pClock);
806 LeaveCriticalSection(&This->cs);
808 return hr;
811 static HRESULT GetFilterInfo(IMoniker* pMoniker, VARIANT* pvar)
813 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
814 IPropertyBag * pPropBagCat = NULL;
815 HRESULT hr;
817 VariantInit(pvar);
819 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
821 if (SUCCEEDED(hr))
822 hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL);
824 if (SUCCEEDED(hr))
825 TRACE("Moniker = %s\n", debugstr_w(V_BSTR(pvar)));
827 if (pPropBagCat)
828 IPropertyBag_Release(pPropBagCat);
830 return hr;
833 static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPin*** pppins, ULONG* pnb)
835 HRESULT hr;
836 ULONG nb = 0;
838 TRACE("(%p, %p, %p, %p)\n", pfilter, pinputpin, pppins, pnb);
839 hr = IPin_QueryInternalConnections(pinputpin, NULL, &nb);
840 if (hr == S_OK) {
841 /* Rendered input */
842 } else if (hr == S_FALSE) {
843 *pppins = CoTaskMemAlloc(sizeof(IPin*)*nb);
844 hr = IPin_QueryInternalConnections(pinputpin, *pppins, &nb);
845 if (hr != S_OK) {
846 WARN("Error (%x)\n", hr);
848 } else if (hr == E_NOTIMPL) {
849 /* Input connected to all outputs */
850 IEnumPins* penumpins;
851 IPin* ppin;
852 int i = 0;
853 TRACE("E_NOTIMPL\n");
854 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
855 if (FAILED(hr)) {
856 WARN("filter Enumpins failed (%x)\n", hr);
857 return hr;
859 i = 0;
860 /* Count output pins */
861 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
862 PIN_DIRECTION pindir;
863 IPin_QueryDirection(ppin, &pindir);
864 if (pindir == PINDIR_OUTPUT)
865 i++;
866 IPin_Release(ppin);
868 *pppins = CoTaskMemAlloc(sizeof(IPin*)*i);
869 /* Retrieve output pins */
870 IEnumPins_Reset(penumpins);
871 i = 0;
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 (*pppins)[i++] = ppin;
877 else
878 IPin_Release(ppin);
880 IEnumPins_Release(penumpins);
881 nb = i;
882 if (FAILED(hr)) {
883 WARN("Next failed (%x)\n", hr);
884 return hr;
886 } else if (FAILED(hr)) {
887 WARN("Cannot get internal connection (%x)\n", hr);
888 return hr;
891 *pnb = nb;
892 return S_OK;
895 /*** IGraphBuilder methods ***/
896 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IPin *ppinIn)
898 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
899 HRESULT hr;
900 AM_MEDIA_TYPE* mt = NULL;
901 IEnumMediaTypes* penummt = NULL;
902 ULONG nbmt;
903 IEnumPins* penumpins;
904 IEnumMoniker* pEnumMoniker;
905 GUID tab[2];
906 ULONG nb = 0;
907 IMoniker* pMoniker;
908 ULONG pin;
909 PIN_INFO PinInfo;
910 CLSID FilterCLSID;
911 PIN_DIRECTION dir;
912 unsigned int i = 0;
914 TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
916 if (TRACE_ON(quartz))
918 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
919 if (FAILED(hr))
920 return hr;
922 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
923 IBaseFilter_Release(PinInfo.pFilter);
925 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
926 if (FAILED(hr))
927 return hr;
929 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
930 IBaseFilter_Release(PinInfo.pFilter);
933 EnterCriticalSection(&This->cs);
934 ++This->recursioncount;
935 if (This->recursioncount >= 5)
937 WARN("Recursion count has reached %d\n", This->recursioncount);
938 hr = VFW_E_CANNOT_CONNECT;
939 goto out;
942 hr = IPin_QueryDirection(ppinOut, &dir);
943 if (FAILED(hr))
944 goto out;
946 if (dir == PINDIR_INPUT)
948 IPin *temp;
950 temp = ppinIn;
951 ppinIn = ppinOut;
952 ppinOut = temp;
955 hr = CheckCircularConnection(This, ppinOut, ppinIn);
956 if (FAILED(hr))
957 goto out;
959 /* Try direct connection first */
960 hr = IPin_Connect(ppinOut, ppinIn, NULL);
961 if (SUCCEEDED(hr))
962 goto out;
964 TRACE("Direct connection failed, trying to render using extra filters\n");
966 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
967 if (FAILED(hr))
968 goto out;
970 hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
971 IBaseFilter_Release(PinInfo.pFilter);
972 if (FAILED(hr))
973 goto out;
975 /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream
976 * filter to the minor mediatype of input pin of the renderer */
977 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
978 if (FAILED(hr))
980 WARN("EnumMediaTypes (%x)\n", hr);
981 goto out;
984 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
985 if (FAILED(hr)) {
986 WARN("IEnumMediaTypes_Next (%x)\n", hr);
987 goto out;
990 if (!nbmt)
992 WARN("No media type found!\n");
993 hr = VFW_E_INVALIDMEDIATYPE;
994 goto out;
996 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
997 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
999 /* Try to find a suitable filter that can connect to the pin to render */
1000 tab[0] = mt->majortype;
1001 tab[1] = mt->subtype;
1002 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1003 if (FAILED(hr)) {
1004 WARN("Unable to enum filters (%x)\n", hr);
1005 goto out;
1008 hr = VFW_E_CANNOT_RENDER;
1009 while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1011 VARIANT var;
1012 GUID clsid;
1013 IPin** ppins = NULL;
1014 IPin* ppinfilter = NULL;
1015 IBaseFilter* pfilter = NULL;
1016 IAMGraphBuilderCallback *callback = NULL;
1018 hr = GetFilterInfo(pMoniker, &var);
1019 if (FAILED(hr)) {
1020 WARN("Unable to retrieve filter info (%x)\n", hr);
1021 goto error;
1024 hr = IMoniker_BindToObject(pMoniker, NULL, NULL, &IID_IBaseFilter, (LPVOID*)&pfilter);
1025 IMoniker_Release(pMoniker);
1026 if (FAILED(hr)) {
1027 WARN("Unable to create filter (%x), trying next one\n", hr);
1028 goto error;
1031 hr = IBaseFilter_GetClassID(pfilter, &clsid);
1032 if (FAILED(hr))
1034 IBaseFilter_Release(pfilter);
1035 goto error;
1038 if (IsEqualGUID(&clsid, &FilterCLSID)) {
1039 /* Skip filter (same as the one the output pin belongs to) */
1040 IBaseFilter_Release(pfilter);
1041 goto error;
1044 if (This->pSite)
1046 IUnknown_QueryInterface(This->pSite, &IID_IAMGraphBuilderCallback, (LPVOID*)&callback);
1047 if (callback)
1049 HRESULT rc;
1050 rc = IAMGraphBuilderCallback_SelectedFilter(callback, pMoniker);
1051 if (FAILED(rc))
1053 TRACE("Filter rejected by IAMGraphBuilderCallback_SelectedFilter\n");
1054 IAMGraphBuilderCallback_Release(callback);
1055 goto error;
1060 if (callback)
1062 HRESULT rc;
1063 rc = IAMGraphBuilderCallback_CreatedFilter(callback, pfilter);
1064 IAMGraphBuilderCallback_Release(callback);
1065 if (FAILED(rc))
1067 IBaseFilter_Release(pfilter);
1068 pfilter = NULL;
1069 TRACE("Filter rejected by IAMGraphBuilderCallback_CreatedFilter\n");
1070 goto error;
1074 hr = IFilterGraph2_AddFilter(iface, pfilter, V_BSTR(&var));
1075 if (FAILED(hr)) {
1076 WARN("Unable to add filter (%x)\n", hr);
1077 IBaseFilter_Release(pfilter);
1078 pfilter = NULL;
1079 goto error;
1082 VariantClear(&var);
1084 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1085 if (FAILED(hr)) {
1086 WARN("Enumpins (%x)\n", hr);
1087 goto error;
1090 hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin);
1091 IEnumPins_Release(penumpins);
1093 if (FAILED(hr)) {
1094 WARN("Obtaining next pin: (%x)\n", hr);
1095 goto error;
1097 if (pin == 0) {
1098 WARN("Cannot use this filter: no pins\n");
1099 goto error;
1102 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1103 if (FAILED(hr)) {
1104 TRACE("Cannot connect to filter (%x), trying next one\n", hr);
1105 goto error;
1107 TRACE("Successfully connected to filter, follow chain...\n");
1109 /* Render all output pins of the filter by calling IFilterGraph2_Connect on each of them */
1110 hr = GetInternalConnections(pfilter, ppinfilter, &ppins, &nb);
1112 if (SUCCEEDED(hr)) {
1113 if (nb == 0) {
1114 IPin_Disconnect(ppinfilter);
1115 IPin_Disconnect(ppinOut);
1116 goto error;
1118 TRACE("pins to consider: %d\n", nb);
1119 for(i = 0; i < nb; i++)
1121 LPWSTR pinname = NULL;
1123 TRACE("Processing pin %u\n", i);
1125 hr = IPin_QueryId(ppins[i], &pinname);
1126 if (SUCCEEDED(hr))
1128 if (pinname[0] == '~')
1130 TRACE("Pinname=%s, skipping\n", debugstr_w(pinname));
1131 hr = E_FAIL;
1133 else
1134 hr = IFilterGraph2_Connect(iface, ppins[i], ppinIn);
1135 CoTaskMemFree(pinname);
1138 if (FAILED(hr)) {
1139 TRACE("Cannot connect pin %p (%x)\n", ppinfilter, hr);
1141 IPin_Release(ppins[i]);
1142 if (SUCCEEDED(hr)) break;
1144 while (++i < nb) IPin_Release(ppins[i]);
1145 CoTaskMemFree(ppins);
1146 IPin_Release(ppinfilter);
1147 IBaseFilter_Release(pfilter);
1148 if (FAILED(hr))
1150 IPin_Disconnect(ppinfilter);
1151 IPin_Disconnect(ppinOut);
1152 IFilterGraph2_RemoveFilter(iface, pfilter);
1153 continue;
1155 break;
1158 error:
1159 VariantClear(&var);
1160 if (ppinfilter) IPin_Release(ppinfilter);
1161 if (pfilter) {
1162 IFilterGraph2_RemoveFilter(iface, pfilter);
1163 IBaseFilter_Release(pfilter);
1165 while (++i < nb) IPin_Release(ppins[i]);
1166 CoTaskMemFree(ppins);
1169 out:
1170 if (penummt)
1171 IEnumMediaTypes_Release(penummt);
1172 if (mt)
1173 DeleteMediaType(mt);
1174 --This->recursioncount;
1175 LeaveCriticalSection(&This->cs);
1176 TRACE("--> %08x\n", hr);
1177 return SUCCEEDED(hr) ? S_OK : hr;
1180 static HRESULT FilterGraph2_RenderRecurse(IFilterGraphImpl *This, IPin *ppinOut)
1182 /* This pin has been connected now, try to call render on all pins that aren't connected */
1183 IPin *to = NULL;
1184 PIN_INFO info;
1185 IEnumPins *enumpins = NULL;
1186 BOOL renderany = FALSE;
1187 BOOL renderall = TRUE;
1189 IPin_QueryPinInfo(ppinOut, &info);
1191 IBaseFilter_EnumPins(info.pFilter, &enumpins);
1192 /* Don't need to hold a reference, IEnumPins does */
1193 IBaseFilter_Release(info.pFilter);
1195 IEnumPins_Reset(enumpins);
1196 while (IEnumPins_Next(enumpins, 1, &to, NULL) == S_OK)
1198 PIN_DIRECTION dir = PINDIR_INPUT;
1200 IPin_QueryDirection(to, &dir);
1202 if (dir == PINDIR_OUTPUT)
1204 IPin *out = NULL;
1206 IPin_ConnectedTo(to, &out);
1207 if (!out)
1209 HRESULT hr;
1210 hr = IFilterGraph2_Render(&This->IFilterGraph2_iface, to);
1211 if (SUCCEEDED(hr))
1212 renderany = TRUE;
1213 else
1214 renderall = FALSE;
1216 else
1217 IPin_Release(out);
1220 IPin_Release(to);
1223 IEnumPins_Release(enumpins);
1225 if (renderall)
1226 return S_OK;
1228 if (renderany)
1229 return VFW_S_PARTIAL_RENDER;
1231 return VFW_E_CANNOT_RENDER;
1234 /* Ogg hates me if I create a direct rendering method
1236 * It can only connect to a pin properly once, so use a recursive method that does
1238 * +----+ --- (PIN 1) (Render is called on this pin)
1239 * | |
1240 * +----+ --- (PIN 2)
1242 * Enumerate possible renderers that EXACTLY match the requested type
1244 * If none is available, try to add intermediate filters that can connect to the input pin
1245 * then call Render on that intermediate pin's output pins
1246 * if it succeeds: Render returns success, if it doesn't, the intermediate filter is removed,
1247 * and another filter that can connect to the input pin is tried
1248 * if we run out of filters that can, give up and return VFW_E_CANNOT_RENDER
1249 * It's recursive, but fun!
1252 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *ppinOut)
1254 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1255 IEnumMediaTypes* penummt;
1256 AM_MEDIA_TYPE* mt;
1257 ULONG nbmt;
1258 HRESULT hr;
1260 IEnumMoniker* pEnumMoniker;
1261 GUID tab[4];
1262 ULONG nb;
1263 IMoniker* pMoniker;
1264 INT x;
1266 TRACE("(%p/%p)->(%p)\n", This, iface, ppinOut);
1268 if (TRACE_ON(quartz))
1270 PIN_INFO PinInfo;
1272 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
1273 if (FAILED(hr))
1274 return hr;
1276 TRACE("Filter owning pin => %p\n", PinInfo.pFilter);
1277 IBaseFilter_Release(PinInfo.pFilter);
1280 /* Try to find out if there is a renderer for the specified subtype already, and use that
1282 EnterCriticalSection(&This->cs);
1283 for (x = 0; x < This->nFilters; ++x)
1285 IEnumPins *enumpins = NULL;
1286 IPin *pin = NULL;
1288 hr = IBaseFilter_EnumPins(This->ppFiltersInGraph[x], &enumpins);
1290 if (FAILED(hr) || !enumpins)
1291 continue;
1293 IEnumPins_Reset(enumpins);
1294 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
1296 IPin *to = NULL;
1297 PIN_DIRECTION dir = PINDIR_OUTPUT;
1299 IPin_QueryDirection(pin, &dir);
1300 if (dir != PINDIR_INPUT)
1302 IPin_Release(pin);
1303 continue;
1305 IPin_ConnectedTo(pin, &to);
1307 if (to == NULL)
1309 hr = FilterGraph2_ConnectDirect(iface, ppinOut, pin, NULL);
1310 if (SUCCEEDED(hr))
1312 TRACE("Connected successfully %p/%p, %08x look if we should render more!\n", ppinOut, pin, hr);
1313 IPin_Release(pin);
1315 hr = FilterGraph2_RenderRecurse(This, pin);
1316 if (FAILED(hr))
1318 IPin_Disconnect(ppinOut);
1319 IPin_Disconnect(pin);
1320 continue;
1322 IEnumPins_Release(enumpins);
1323 LeaveCriticalSection(&This->cs);
1324 return hr;
1326 WARN("Could not connect!\n");
1328 else
1329 IPin_Release(to);
1331 IPin_Release(pin);
1333 IEnumPins_Release(enumpins);
1336 LeaveCriticalSection(&This->cs);
1338 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
1339 if (FAILED(hr)) {
1340 WARN("EnumMediaTypes (%x)\n", hr);
1341 return hr;
1344 IEnumMediaTypes_Reset(penummt);
1346 /* Looks like no existing renderer of the kind exists
1347 * Try adding new ones
1349 tab[0] = tab[1] = GUID_NULL;
1350 while (SUCCEEDED(hr))
1352 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
1353 if (FAILED(hr)) {
1354 WARN("IEnumMediaTypes_Next (%x)\n", hr);
1355 break;
1357 if (!nbmt)
1359 hr = VFW_E_CANNOT_RENDER;
1360 break;
1362 else
1364 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1365 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1367 /* Only enumerate once, this doesn't account for all previous ones, but this should be enough nonetheless */
1368 if (IsEqualIID(&tab[0], &mt->majortype) && IsEqualIID(&tab[1], &mt->subtype))
1370 DeleteMediaType(mt);
1371 continue;
1374 /* Try to find a suitable renderer with the same media type */
1375 tab[0] = mt->majortype;
1376 tab[1] = mt->subtype;
1377 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1378 if (FAILED(hr))
1380 WARN("Unable to enum filters (%x)\n", hr);
1381 break;
1384 hr = E_FAIL;
1386 while (IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1388 VARIANT var;
1389 IPin* ppinfilter;
1390 IBaseFilter* pfilter = NULL;
1391 IEnumPins* penumpins = NULL;
1392 ULONG pin;
1394 hr = GetFilterInfo(pMoniker, &var);
1395 if (FAILED(hr)) {
1396 WARN("Unable to retrieve filter info (%x)\n", hr);
1397 goto error;
1400 hr = IMoniker_BindToObject(pMoniker, NULL, NULL, &IID_IBaseFilter, (LPVOID*)&pfilter);
1401 IMoniker_Release(pMoniker);
1402 if (FAILED(hr))
1404 WARN("Unable to create filter (%x), trying next one\n", hr);
1405 goto error;
1408 hr = IFilterGraph2_AddFilter(iface, pfilter, V_BSTR(&var));
1409 if (FAILED(hr)) {
1410 WARN("Unable to add filter (%x)\n", hr);
1411 IBaseFilter_Release(pfilter);
1412 pfilter = NULL;
1413 goto error;
1416 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1417 if (FAILED(hr)) {
1418 WARN("Splitter Enumpins (%x)\n", hr);
1419 goto error;
1422 while ((hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin)) == S_OK)
1424 PIN_DIRECTION dir;
1426 if (pin == 0) {
1427 WARN("No Pin\n");
1428 hr = E_FAIL;
1429 goto error;
1432 hr = IPin_QueryDirection(ppinfilter, &dir);
1433 if (FAILED(hr)) {
1434 IPin_Release(ppinfilter);
1435 WARN("QueryDirection failed (%x)\n", hr);
1436 goto error;
1438 if (dir != PINDIR_INPUT) {
1439 IPin_Release(ppinfilter);
1440 continue; /* Wrong direction */
1443 /* Connect the pin to the "Renderer" */
1444 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1445 IPin_Release(ppinfilter);
1447 if (FAILED(hr)) {
1448 WARN("Unable to connect %s to renderer (%x)\n", debugstr_w(V_BSTR(&var)), hr);
1449 goto error;
1451 TRACE("Connected, recursing %s\n", debugstr_w(V_BSTR(&var)));
1453 VariantClear(&var);
1455 hr = FilterGraph2_RenderRecurse(This, ppinfilter);
1456 if (FAILED(hr)) {
1457 WARN("Unable to connect recursively (%x)\n", hr);
1458 goto error;
1460 IBaseFilter_Release(pfilter);
1461 break;
1463 if (SUCCEEDED(hr)) {
1464 IEnumPins_Release(penumpins);
1465 break; /* out of IEnumMoniker_Next loop */
1468 /* IEnumPins_Next failed, all other failure case caught by goto error */
1469 WARN("IEnumPins_Next (%x)\n", hr);
1470 /* goto error */
1472 error:
1473 VariantClear(&var);
1474 if (penumpins)
1475 IEnumPins_Release(penumpins);
1476 if (pfilter) {
1477 IFilterGraph2_RemoveFilter(iface, pfilter);
1478 IBaseFilter_Release(pfilter);
1480 if (SUCCEEDED(hr)) DebugBreak();
1483 IEnumMoniker_Release(pEnumMoniker);
1484 if (nbmt)
1485 DeleteMediaType(mt);
1486 if (SUCCEEDED(hr))
1487 break;
1488 hr = S_OK;
1491 IEnumMediaTypes_Release(penummt);
1492 return hr;
1495 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface, LPCWSTR lpcwstrFile,
1496 LPCWSTR lpcwstrPlayList)
1498 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1499 static const WCHAR string[] = {'R','e','a','d','e','r',0};
1500 IBaseFilter* preader = NULL;
1501 IPin* ppinreader = NULL;
1502 IEnumPins* penumpins = NULL;
1503 HRESULT hr;
1504 BOOL partial = FALSE;
1505 BOOL any = FALSE;
1507 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1509 if (lpcwstrPlayList != NULL)
1510 return E_INVALIDARG;
1512 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, string, &preader);
1513 if (FAILED(hr))
1514 return hr;
1516 if (SUCCEEDED(hr))
1517 hr = IBaseFilter_EnumPins(preader, &penumpins);
1518 if (SUCCEEDED(hr))
1520 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1522 PIN_DIRECTION dir;
1524 IPin_QueryDirection(ppinreader, &dir);
1525 if (dir == PINDIR_OUTPUT)
1527 INT i;
1529 hr = IFilterGraph2_Render(iface, ppinreader);
1530 TRACE("Render %08x\n", hr);
1532 for (i = 0; i < This->nFilters; ++i)
1533 TRACE("Filters in chain: %s\n", debugstr_w(This->pFilterNames[i]));
1535 if (SUCCEEDED(hr))
1536 any = TRUE;
1537 if (hr != S_OK)
1538 partial = TRUE;
1540 IPin_Release(ppinreader);
1542 IEnumPins_Release(penumpins);
1544 if (!any)
1545 hr = VFW_E_CANNOT_RENDER;
1546 else if (partial)
1547 hr = VFW_S_PARTIAL_RENDER;
1548 else
1549 hr = S_OK;
1551 IBaseFilter_Release(preader);
1553 TRACE("--> %08x\n", hr);
1554 return hr;
1557 static HRESULT CreateFilterInstanceAndLoadFile(GUID* clsid, LPCOLESTR pszFileName, IBaseFilter **filter)
1559 IFileSourceFilter *source = NULL;
1560 HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1561 TRACE("CLSID: %s\n", debugstr_guid(clsid));
1562 if (FAILED(hr))
1563 return hr;
1565 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID*)&source);
1566 if (FAILED(hr))
1568 IBaseFilter_Release(*filter);
1569 return hr;
1572 /* Load the file in the file source filter */
1573 hr = IFileSourceFilter_Load(source, pszFileName, NULL);
1574 IFileSourceFilter_Release(source);
1575 if (FAILED(hr)) {
1576 WARN("Load (%x)\n", hr);
1577 IBaseFilter_Release(*filter);
1578 return hr;
1581 return hr;
1584 /* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
1585 static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
1587 HRESULT hr;
1588 GUID clsid;
1589 IAsyncReader * pReader = NULL;
1590 IFileSourceFilter* pSource = NULL;
1591 IPin * pOutputPin = NULL;
1592 static const WCHAR wszOutputPinName[] = { 'O','u','t','p','u','t',0 };
1594 /* Try to find a match without reading the file first */
1595 hr = GetClassMediaFile(NULL, pszFileName, NULL, NULL, &clsid);
1597 if (!hr)
1598 return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
1600 /* Now create a AyncReader instance, to check for signature bytes in the file */
1601 hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1602 if (FAILED(hr))
1603 return hr;
1605 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID *)&pSource);
1606 if (FAILED(hr))
1608 IBaseFilter_Release(*filter);
1609 return hr;
1612 hr = IFileSourceFilter_Load(pSource, pszFileName, NULL);
1613 IFileSourceFilter_Release(pSource);
1614 if (FAILED(hr))
1616 IBaseFilter_Release(*filter);
1617 return hr;
1620 hr = IBaseFilter_FindPin(*filter, wszOutputPinName, &pOutputPin);
1621 if (FAILED(hr))
1623 IBaseFilter_Release(*filter);
1624 return hr;
1627 hr = IPin_QueryInterface(pOutputPin, &IID_IAsyncReader, (LPVOID *)&pReader);
1628 IPin_Release(pOutputPin);
1629 if (FAILED(hr))
1631 IBaseFilter_Release(*filter);
1632 return hr;
1635 /* Try again find a match */
1636 hr = GetClassMediaFile(pReader, pszFileName, NULL, NULL, &clsid);
1637 IAsyncReader_Release(pReader);
1639 if (!hr)
1641 /* Release the AsyncReader filter and create the matching one */
1642 IBaseFilter_Release(*filter);
1643 return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
1646 /* Return the AsyncReader filter */
1647 return S_OK;
1650 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface, LPCWSTR lpcwstrFileName,
1651 LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1653 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1654 HRESULT hr;
1655 IBaseFilter* preader;
1656 IFileSourceFilter* pfile = NULL;
1657 AM_MEDIA_TYPE mt;
1658 WCHAR* filename;
1660 TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1662 /* Try from file name first, then fall back to default asynchronous reader */
1663 hr = GetFileSourceFilter(lpcwstrFileName, &preader);
1664 if (FAILED(hr)) {
1665 WARN("Unable to create file source filter (%x)\n", hr);
1666 return hr;
1669 hr = IFilterGraph2_AddFilter(iface, preader, lpcwstrFilterName);
1670 if (FAILED(hr)) {
1671 WARN("Unable add filter (%x)\n", hr);
1672 IBaseFilter_Release(preader);
1673 return hr;
1676 hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1677 if (FAILED(hr)) {
1678 WARN("Unable to get IFileSourceInterface (%x)\n", hr);
1679 goto error;
1682 /* The file has been already loaded */
1683 hr = IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1684 if (FAILED(hr)) {
1685 WARN("GetCurFile (%x)\n", hr);
1686 goto error;
1689 TRACE("File %s\n", debugstr_w(filename));
1690 TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
1691 TRACE("SubType %s\n", debugstr_guid(&mt.subtype));
1693 if (ppFilter)
1694 *ppFilter = preader;
1695 IFileSourceFilter_Release(pfile);
1697 return S_OK;
1699 error:
1700 if (pfile)
1701 IFileSourceFilter_Release(pfile);
1702 IFilterGraph2_RemoveFilter(iface, preader);
1703 IBaseFilter_Release(preader);
1705 return hr;
1708 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR hFile)
1710 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1712 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1714 return S_OK;
1717 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1719 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1721 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1723 return S_OK;
1726 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1728 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1730 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1732 return S_OK;
1735 /*** IFilterGraph2 methods ***/
1736 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1737 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1739 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1740 HRESULT hr;
1741 IBaseFilter* pfilter;
1743 TRACE("(%p/%p)->(%p %p %s %p)\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1745 hr = IMoniker_BindToObject(pMoniker, pCtx, NULL, &IID_IBaseFilter, (void**)&pfilter);
1746 if(FAILED(hr)) {
1747 WARN("Unable to bind moniker to filter object (%x)\n", hr);
1748 return hr;
1751 hr = IFilterGraph2_AddFilter(iface, pfilter, lpcwstrFilterName);
1752 if (FAILED(hr)) {
1753 WARN("Unable to add filter (%x)\n", hr);
1754 IBaseFilter_Release(pfilter);
1755 return hr;
1758 if(ppFilter)
1759 *ppFilter = pfilter;
1760 else IBaseFilter_Release(pfilter);
1762 return S_OK;
1765 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *ppin,
1766 const AM_MEDIA_TYPE *pmt)
1768 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1770 TRACE("(%p/%p)->(%p %p): stub !!!\n", This, iface, ppin, pmt);
1772 return S_OK;
1775 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *pPinOut, DWORD dwFlags,
1776 DWORD *pvContext)
1778 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1780 TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This, iface, pPinOut, dwFlags, pvContext);
1782 return S_OK;
1786 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1788 FilterGraph2_QueryInterface,
1789 FilterGraph2_AddRef,
1790 FilterGraph2_Release,
1791 FilterGraph2_AddFilter,
1792 FilterGraph2_RemoveFilter,
1793 FilterGraph2_EnumFilters,
1794 FilterGraph2_FindFilterByName,
1795 FilterGraph2_ConnectDirect,
1796 FilterGraph2_Reconnect,
1797 FilterGraph2_Disconnect,
1798 FilterGraph2_SetDefaultSyncSource,
1799 FilterGraph2_Connect,
1800 FilterGraph2_Render,
1801 FilterGraph2_RenderFile,
1802 FilterGraph2_AddSourceFilter,
1803 FilterGraph2_SetLogFile,
1804 FilterGraph2_Abort,
1805 FilterGraph2_ShouldOperationContinue,
1806 FilterGraph2_AddSourceFilterForMoniker,
1807 FilterGraph2_ReconnectEx,
1808 FilterGraph2_RenderEx
1811 static inline IFilterGraphImpl *impl_from_IMediaControl(IMediaControl *iface)
1813 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaControl_iface);
1816 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID riid, void **ppvObj)
1818 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1820 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1822 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
1825 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1827 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1829 TRACE("(%p/%p)->()\n", This, iface);
1831 return IUnknown_AddRef(This->outer_unk);
1834 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1836 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1838 TRACE("(%p/%p)->()\n", This, iface);
1840 return IUnknown_Release(This->outer_unk);
1844 /*** IDispatch methods ***/
1845 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *pctinfo)
1847 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1849 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1851 return S_OK;
1854 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT iTInfo, LCID lcid,
1855 ITypeInfo **ppTInfo)
1857 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1859 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1861 return S_OK;
1864 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID riid,
1865 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1867 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1869 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1871 return S_OK;
1874 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID dispIdMember, REFIID riid,
1875 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
1876 UINT *puArgErr)
1878 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1880 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);
1882 return S_OK;
1885 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *, DWORD_PTR data);
1887 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter, DWORD_PTR data)
1889 HRESULT hr;
1890 IPin* pInputPin;
1891 IPin** ppPins;
1892 ULONG nb;
1893 ULONG i;
1894 PIN_INFO PinInfo;
1896 TRACE("%p %p\n", pGraph, pOutputPin);
1897 PinInfo.pFilter = NULL;
1899 hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1901 if (SUCCEEDED(hr))
1903 hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1904 if (SUCCEEDED(hr))
1905 hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1906 IPin_Release(pInputPin);
1909 if (SUCCEEDED(hr))
1911 if (nb == 0)
1913 TRACE("Reached a renderer\n");
1914 /* Count renderers for end of stream notification */
1915 pGraph->nRenderers++;
1917 else
1919 for(i = 0; i < nb; i++)
1921 /* Explore the graph downstream from this pin
1922 * FIXME: We should prevent exploring from a pin more than once. This can happens when
1923 * several input pins are connected to the same output (a MUX for instance). */
1924 ExploreGraph(pGraph, ppPins[i], FoundFilter, data);
1925 IPin_Release(ppPins[i]);
1928 CoTaskMemFree(ppPins);
1930 TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1932 FoundFilter(PinInfo.pFilter, data);
1935 if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1936 return hr;
1939 static HRESULT WINAPI SendRun(IBaseFilter *pFilter, DWORD_PTR data)
1941 REFERENCE_TIME time = *(REFERENCE_TIME*)data;
1942 return IBaseFilter_Run(pFilter, time);
1945 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1947 return IBaseFilter_Pause(pFilter);
1950 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1952 return IBaseFilter_Stop(pFilter);
1955 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1957 FILTER_STATE state;
1958 DWORD time_end = data;
1959 DWORD time_now = GetTickCount();
1960 LONG wait;
1962 if (time_end == INFINITE)
1964 wait = INFINITE;
1966 else if (time_end > time_now)
1968 wait = time_end - time_now;
1970 else
1971 wait = 0;
1973 return IBaseFilter_GetState(pFilter, wait, &state);
1977 static HRESULT SendFilterMessage(IFilterGraphImpl *This, fnFoundFilter FoundFilter, DWORD_PTR data)
1979 int i;
1980 IBaseFilter* pfilter;
1981 IEnumPins* pEnum;
1982 HRESULT hr;
1983 IPin* pPin;
1984 DWORD dummy;
1985 PIN_DIRECTION dir;
1987 TRACE("(%p)->()\n", This);
1989 /* Explorer the graph from source filters to renderers, determine renderers
1990 * number and run filters from renderers to source filters */
1991 This->nRenderers = 0;
1992 ResetEvent(This->hEventCompletion);
1994 for(i = 0; i < This->nFilters; i++)
1996 BOOL source = TRUE;
1997 pfilter = This->ppFiltersInGraph[i];
1998 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
1999 if (hr != S_OK)
2001 WARN("Enum pins failed %x\n", hr);
2002 continue;
2004 /* Check if it is a source filter */
2005 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2007 IPin_QueryDirection(pPin, &dir);
2008 IPin_Release(pPin);
2009 if (dir == PINDIR_INPUT)
2011 source = FALSE;
2012 break;
2015 if (source)
2017 TRACE("Found a source filter %p\n", pfilter);
2018 IEnumPins_Reset(pEnum);
2019 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2021 /* Explore the graph downstream from this pin */
2022 ExploreGraph(This, pPin, FoundFilter, data);
2023 IPin_Release(pPin);
2025 FoundFilter(pfilter, data);
2027 IEnumPins_Release(pEnum);
2030 return S_FALSE;
2033 /*** IMediaControl methods ***/
2034 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
2036 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2038 TRACE("(%p/%p)->()\n", This, iface);
2040 EnterCriticalSection(&This->cs);
2041 if (This->state == State_Running)
2042 goto out;
2043 This->EcCompleteCount = 0;
2045 if (This->defaultclock && !This->refClock)
2046 IFilterGraph2_SetDefaultSyncSource(&This->IFilterGraph2_iface);
2048 if (This->refClock)
2050 REFERENCE_TIME now;
2051 IReferenceClock_GetTime(This->refClock, &now);
2052 if (This->state == State_Stopped)
2053 This->start_time = now + 500000;
2054 else if (This->pause_time >= 0)
2055 This->start_time += now - This->pause_time;
2056 else
2057 This->start_time = now;
2059 else This->start_time = 0;
2061 SendFilterMessage(This, SendRun, (DWORD_PTR)&This->start_time);
2062 This->state = State_Running;
2063 out:
2064 LeaveCriticalSection(&This->cs);
2065 return S_FALSE;
2068 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
2070 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2072 TRACE("(%p/%p)->()\n", This, iface);
2074 EnterCriticalSection(&This->cs);
2075 if (This->state == State_Paused)
2076 goto out;
2078 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2079 IReferenceClock_GetTime(This->refClock, &This->pause_time);
2080 else
2081 This->pause_time = -1;
2083 SendFilterMessage(This, SendPause, 0);
2084 This->state = State_Paused;
2085 out:
2086 LeaveCriticalSection(&This->cs);
2087 return S_FALSE;
2090 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
2092 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2094 TRACE("(%p/%p)->()\n", This, iface);
2096 if (This->state == State_Stopped) return S_OK;
2098 EnterCriticalSection(&This->cs);
2099 if (This->state == State_Running) SendFilterMessage(This, SendPause, 0);
2100 SendFilterMessage(This, SendStop, 0);
2101 This->state = State_Stopped;
2102 LeaveCriticalSection(&This->cs);
2103 return S_OK;
2106 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG msTimeout,
2107 OAFilterState *pfs)
2109 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2110 DWORD end;
2112 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
2114 if (!pfs)
2115 return E_POINTER;
2117 EnterCriticalSection(&This->cs);
2119 *pfs = This->state;
2120 if (msTimeout > 0)
2122 end = GetTickCount() + msTimeout;
2124 else if (msTimeout < 0)
2126 end = INFINITE;
2128 else
2130 end = 0;
2132 if (end)
2133 SendFilterMessage(This, SendGetState, end);
2135 LeaveCriticalSection(&This->cs);
2137 return S_OK;
2140 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
2142 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2144 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strFilename), strFilename);
2146 return IFilterGraph2_RenderFile(&This->IFilterGraph2_iface, strFilename, NULL);
2149 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
2150 IDispatch **ppUnk)
2152 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2154 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2156 return S_OK;
2159 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2161 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2163 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2165 return S_OK;
2168 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2170 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2172 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2174 return S_OK;
2177 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
2179 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2181 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2183 return S_OK;
2187 static const IMediaControlVtbl IMediaControl_VTable =
2189 MediaControl_QueryInterface,
2190 MediaControl_AddRef,
2191 MediaControl_Release,
2192 MediaControl_GetTypeInfoCount,
2193 MediaControl_GetTypeInfo,
2194 MediaControl_GetIDsOfNames,
2195 MediaControl_Invoke,
2196 MediaControl_Run,
2197 MediaControl_Pause,
2198 MediaControl_Stop,
2199 MediaControl_GetState,
2200 MediaControl_RenderFile,
2201 MediaControl_AddSourceFilter,
2202 MediaControl_get_FilterCollection,
2203 MediaControl_get_RegFilterCollection,
2204 MediaControl_StopWhenReady
2207 static inline IFilterGraphImpl *impl_from_IMediaSeeking(IMediaSeeking *iface)
2209 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaSeeking_iface);
2212 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID riid, void **ppvObj)
2214 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2216 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2218 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2221 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2223 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2225 TRACE("(%p/%p)->()\n", This, iface);
2227 return IUnknown_AddRef(This->outer_unk);
2230 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2232 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2234 TRACE("(%p/%p)->()\n", This, iface);
2236 return IUnknown_Release(This->outer_unk);
2239 typedef HRESULT (WINAPI *fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
2241 static HRESULT all_renderers_seek(IFilterGraphImpl *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2242 BOOL allnotimpl = TRUE;
2243 int i;
2244 HRESULT hr, hr_return = S_OK;
2246 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2247 /* Send a message to all renderers, they are responsible for broadcasting it further */
2249 for(i = 0; i < This->nFilters; i++)
2251 IMediaSeeking *seek = NULL;
2252 IBaseFilter* pfilter = This->ppFiltersInGraph[i];
2253 IAMFilterMiscFlags *flags = NULL;
2254 ULONG filterflags;
2255 IBaseFilter_QueryInterface(pfilter, &IID_IAMFilterMiscFlags, (void**)&flags);
2256 if (!flags)
2257 continue;
2258 filterflags = IAMFilterMiscFlags_GetMiscFlags(flags);
2259 IAMFilterMiscFlags_Release(flags);
2260 if (filterflags != AM_FILTER_MISC_FLAGS_IS_RENDERER)
2261 continue;
2263 IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2264 if (!seek)
2265 continue;
2266 hr = FoundSeek(This, seek, arg);
2267 IMediaSeeking_Release(seek);
2268 if (hr_return != E_NOTIMPL)
2269 allnotimpl = FALSE;
2270 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2271 hr_return = hr;
2274 if (allnotimpl)
2275 return E_NOTIMPL;
2276 return hr_return;
2279 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2281 HRESULT hr;
2282 DWORD caps = 0;
2284 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2285 if (FAILED(hr))
2286 return hr;
2288 /* Only add common capabilities everything supports */
2289 *(DWORD*)pcaps &= caps;
2291 return hr;
2294 /*** IMediaSeeking methods ***/
2295 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2297 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2298 HRESULT hr;
2300 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2302 if (!pCapabilities)
2303 return E_POINTER;
2305 EnterCriticalSection(&This->cs);
2306 *pCapabilities = 0xffffffff;
2308 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2309 LeaveCriticalSection(&This->cs);
2311 return hr;
2314 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2316 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2317 DWORD originalcaps;
2318 HRESULT hr;
2320 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2322 if (!pCapabilities)
2323 return E_POINTER;
2325 EnterCriticalSection(&This->cs);
2326 originalcaps = *pCapabilities;
2327 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2328 LeaveCriticalSection(&This->cs);
2330 if (FAILED(hr))
2331 return hr;
2333 if (!*pCapabilities)
2334 return E_FAIL;
2335 if (*pCapabilities != originalcaps)
2336 return S_FALSE;
2337 return S_OK;
2340 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2342 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2344 if (!pFormat)
2345 return E_POINTER;
2347 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2349 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2351 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2352 return S_FALSE;
2355 return S_OK;
2358 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2360 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2362 if (!pFormat)
2363 return E_POINTER;
2365 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2366 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2368 return S_OK;
2371 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2373 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2375 if (!pFormat)
2376 return E_POINTER;
2378 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2379 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2381 return S_OK;
2384 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2386 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2388 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2389 if (!pFormat)
2390 return E_POINTER;
2392 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2393 return S_FALSE;
2395 return S_OK;
2398 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2400 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2402 if (!pFormat)
2403 return E_POINTER;
2405 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2407 if (This->state != State_Stopped)
2408 return VFW_E_WRONG_STATE;
2410 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2412 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2413 return E_INVALIDARG;
2416 return S_OK;
2419 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2421 HRESULT hr;
2422 LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2424 hr = IMediaSeeking_GetDuration(seek, &duration);
2425 if (FAILED(hr))
2426 return hr;
2428 if (*pdur < duration)
2429 *pdur = duration;
2430 return hr;
2433 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *pDuration)
2435 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2436 HRESULT hr;
2438 TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2440 if (!pDuration)
2441 return E_POINTER;
2443 EnterCriticalSection(&This->cs);
2444 *pDuration = 0;
2445 hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2446 LeaveCriticalSection(&This->cs);
2448 TRACE("--->%08x\n", hr);
2449 return hr;
2452 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *pStop)
2454 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2455 HRESULT hr = S_OK;
2457 TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2459 if (!pStop)
2460 return E_POINTER;
2462 EnterCriticalSection(&This->cs);
2463 if (This->stop_position < 0)
2464 /* Stop position not set, use duration instead */
2465 hr = IMediaSeeking_GetDuration(iface, pStop);
2466 else
2467 *pStop = This->stop_position;
2468 LeaveCriticalSection(&This->cs);
2470 return hr;
2473 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *pCurrent)
2475 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2476 LONGLONG time = 0;
2478 if (!pCurrent)
2479 return E_POINTER;
2481 EnterCriticalSection(&This->cs);
2482 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2484 IReferenceClock_GetTime(This->refClock, &time);
2485 if (time)
2486 time -= This->start_time;
2488 if (This->pause_time > 0)
2489 time += This->pause_time;
2490 *pCurrent = time;
2491 LeaveCriticalSection(&This->cs);
2493 TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2495 return S_OK;
2498 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2499 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2501 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2503 TRACE("(%p/%p)->(%p, %s, 0x%s, %s)\n", This, iface, pTarget,
2504 debugstr_guid(pTargetFormat), wine_dbgstr_longlong(Source), debugstr_guid(pSourceFormat));
2506 if (!pSourceFormat)
2507 pSourceFormat = &This->timeformatseek;
2509 if (IsEqualGUID(pTargetFormat, pSourceFormat))
2510 *pTarget = Source;
2511 else
2512 FIXME("conversion %s->%s not supported\n", debugstr_guid(pSourceFormat), debugstr_guid(pTargetFormat));
2514 return S_OK;
2517 struct pos_args {
2518 LONGLONG* current, *stop;
2519 DWORD curflags, stopflags;
2522 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2524 struct pos_args *args = (void*)pargs;
2526 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
2529 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2530 DWORD dwCurrentFlags, LONGLONG *pStop, DWORD dwStopFlags)
2532 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2533 HRESULT hr = S_OK;
2534 FILTER_STATE state;
2535 struct pos_args args;
2537 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
2539 EnterCriticalSection(&This->cs);
2540 state = This->state;
2541 TRACE("State: %s\n", state == State_Running ? "Running" : (state == State_Paused ? "Paused" : (state == State_Stopped ? "Stopped" : "UNKNOWN")));
2543 if ((dwCurrentFlags & 0x7) != AM_SEEKING_AbsolutePositioning &&
2544 (dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2545 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
2547 if ((dwStopFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2548 This->stop_position = *pStop;
2549 else if ((dwStopFlags & 0x7) != AM_SEEKING_NoPositioning)
2550 FIXME("Stop position not handled yet!\n");
2552 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2553 IMediaControl_Pause(&This->IMediaControl_iface);
2554 args.current = pCurrent;
2555 args.stop = pStop;
2556 args.curflags = dwCurrentFlags;
2557 args.stopflags = dwStopFlags;
2558 hr = all_renderers_seek(This, found_setposition, (DWORD_PTR)&args);
2560 if ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2561 This->pause_time = This->start_time = -1;
2562 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2563 IMediaControl_Run(&This->IMediaControl_iface);
2564 LeaveCriticalSection(&This->cs);
2566 return hr;
2569 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2570 LONGLONG *pStop)
2572 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2573 HRESULT hr;
2575 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pCurrent, pStop);
2576 hr = IMediaSeeking_GetCurrentPosition(iface, pCurrent);
2577 if (SUCCEEDED(hr))
2578 hr = IMediaSeeking_GetStopPosition(iface, pStop);
2580 return hr;
2583 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2584 LONGLONG *pLatest)
2586 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2588 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2590 return S_OK;
2593 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2595 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2597 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2599 return S_OK;
2602 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2604 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2606 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2608 return S_OK;
2611 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2613 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2615 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2617 return S_OK;
2621 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2623 MediaSeeking_QueryInterface,
2624 MediaSeeking_AddRef,
2625 MediaSeeking_Release,
2626 MediaSeeking_GetCapabilities,
2627 MediaSeeking_CheckCapabilities,
2628 MediaSeeking_IsFormatSupported,
2629 MediaSeeking_QueryPreferredFormat,
2630 MediaSeeking_GetTimeFormat,
2631 MediaSeeking_IsUsingTimeFormat,
2632 MediaSeeking_SetTimeFormat,
2633 MediaSeeking_GetDuration,
2634 MediaSeeking_GetStopPosition,
2635 MediaSeeking_GetCurrentPosition,
2636 MediaSeeking_ConvertTimeFormat,
2637 MediaSeeking_SetPositions,
2638 MediaSeeking_GetPositions,
2639 MediaSeeking_GetAvailable,
2640 MediaSeeking_SetRate,
2641 MediaSeeking_GetRate,
2642 MediaSeeking_GetPreroll
2645 static inline IFilterGraphImpl *impl_from_IMediaPosition(IMediaPosition *iface)
2647 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaPosition_iface);
2650 /*** IUnknown methods ***/
2651 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj)
2653 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2655 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2657 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2660 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2662 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2664 TRACE("(%p/%p)->()\n", This, iface);
2666 return IUnknown_AddRef(This->outer_unk);
2669 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2671 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2673 TRACE("(%p/%p)->()\n", This, iface);
2675 return IUnknown_Release(This->outer_unk);
2678 /*** IDispatch methods ***/
2679 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo)
2681 FIXME("(%p) stub!\n", iface);
2682 return E_NOTIMPL;
2685 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
2687 FIXME("(%p) stub!\n", iface);
2688 return E_NOTIMPL;
2691 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
2693 FIXME("(%p) stub!\n", iface);
2694 return E_NOTIMPL;
2697 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2699 FIXME("(%p) stub!\n", iface);
2700 return E_NOTIMPL;
2703 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2705 GUID time_format;
2706 HRESULT hr;
2708 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2709 if (FAILED(hr))
2710 return hr;
2711 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2713 FIXME("Unsupported time format.\n");
2714 return E_NOTIMPL;
2717 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2718 return S_OK;
2721 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2723 GUID time_format;
2724 HRESULT hr;
2726 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2727 if (FAILED(hr))
2728 return hr;
2729 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2731 FIXME("Unsupported time format.\n");
2732 return E_NOTIMPL;
2735 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2736 return S_OK;
2739 /*** IMediaPosition methods ***/
2740 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2742 LONGLONG duration;
2743 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2744 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2745 if (FAILED(hr))
2746 return hr;
2747 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2750 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2752 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2753 LONGLONG reftime;
2754 HRESULT hr;
2756 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2757 if (FAILED(hr))
2758 return hr;
2759 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2760 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2763 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2765 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2766 LONGLONG pos;
2767 HRESULT hr;
2769 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2770 if (FAILED(hr))
2771 return hr;
2772 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2775 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2777 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2778 LONGLONG pos;
2779 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2780 if (FAILED(hr))
2781 return hr;
2782 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2785 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2787 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2788 LONGLONG reftime;
2789 HRESULT hr;
2791 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2792 if (FAILED(hr))
2793 return hr;
2794 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2795 &reftime, AM_SEEKING_AbsolutePositioning);
2798 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime)
2800 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2801 return E_NOTIMPL;
2804 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime)
2806 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2807 return E_NOTIMPL;
2810 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2812 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2813 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2816 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2818 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2819 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2822 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward)
2824 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2825 return E_NOTIMPL;
2828 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward)
2830 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2831 return E_NOTIMPL;
2835 static const IMediaPositionVtbl IMediaPosition_VTable =
2837 MediaPosition_QueryInterface,
2838 MediaPosition_AddRef,
2839 MediaPosition_Release,
2840 MediaPosition_GetTypeInfoCount,
2841 MediaPosition_GetTypeInfo,
2842 MediaPosition_GetIDsOfNames,
2843 MediaPosition_Invoke,
2844 MediaPosition_get_Duration,
2845 MediaPosition_put_CurrentPosition,
2846 MediaPosition_get_CurrentPosition,
2847 MediaPosition_get_StopTime,
2848 MediaPosition_put_StopTime,
2849 MediaPosition_get_PrerollTime,
2850 MediaPosition_put_PrerollTime,
2851 MediaPosition_put_Rate,
2852 MediaPosition_get_Rate,
2853 MediaPosition_CanSeekForward,
2854 MediaPosition_CanSeekBackward
2857 static inline IFilterGraphImpl *impl_from_IObjectWithSite(IObjectWithSite *iface)
2859 return CONTAINING_RECORD(iface, IFilterGraphImpl, IObjectWithSite_iface);
2862 /*** IUnknown methods ***/
2863 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite* iface, REFIID riid, void** ppvObj)
2865 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2867 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2869 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2872 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
2874 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2876 TRACE("(%p/%p)->()\n", This, iface);
2878 return IUnknown_AddRef(This->outer_unk);
2881 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
2883 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2885 TRACE("(%p/%p)->()\n", This, iface);
2887 return IUnknown_Release(This->outer_unk);
2890 /*** IObjectWithSite methods ***/
2892 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
2894 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2896 TRACE("(%p/%p)->()\n", This, iface);
2897 if (This->pSite) IUnknown_Release(This->pSite);
2898 This->pSite = pUnkSite;
2899 IUnknown_AddRef(This->pSite);
2900 return S_OK;
2903 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, PVOID *ppvSite)
2905 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2907 TRACE("(%p/%p)->(%s)\n", This, iface,debugstr_guid(riid));
2909 *ppvSite = NULL;
2910 if (!This->pSite)
2911 return E_FAIL;
2912 else
2913 return IUnknown_QueryInterface(This->pSite, riid, ppvSite);
2916 static const IObjectWithSiteVtbl IObjectWithSite_VTable =
2918 ObjectWithSite_QueryInterface,
2919 ObjectWithSite_AddRef,
2920 ObjectWithSite_Release,
2921 ObjectWithSite_SetSite,
2922 ObjectWithSite_GetSite,
2925 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2927 HRESULT hr = E_NOINTERFACE;
2928 int i;
2929 int entry;
2931 /* Check if the interface type is already registered */
2932 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2933 if (riid == pGraph->ItfCacheEntries[entry].riid)
2935 if (pGraph->ItfCacheEntries[entry].iface)
2937 /* Return the interface if available */
2938 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2939 return S_OK;
2941 break;
2944 if (entry >= MAX_ITF_CACHE_ENTRIES)
2946 FIXME("Not enough space to store interface in the cache\n");
2947 return E_OUTOFMEMORY;
2950 /* Find a filter supporting the requested interface */
2951 for (i = 0; i < pGraph->nFilters; i++)
2953 hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2954 if (hr == S_OK)
2956 pGraph->ItfCacheEntries[entry].riid = riid;
2957 pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2958 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2959 if (entry >= pGraph->nItfCacheEntries)
2960 pGraph->nItfCacheEntries++;
2961 return S_OK;
2963 if (hr != E_NOINTERFACE)
2964 return hr;
2967 return hr;
2970 static inline IFilterGraphImpl *impl_from_IBasicAudio(IBasicAudio *iface)
2972 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicAudio_iface);
2975 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID riid, void **ppvObj)
2977 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2979 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2981 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2984 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
2986 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2988 TRACE("(%p/%p)->()\n", This, iface);
2990 return IUnknown_AddRef(This->outer_unk);
2993 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
2995 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2997 TRACE("(%p/%p)->()\n", This, iface);
2999 return IUnknown_Release(This->outer_unk);
3002 /*** IDispatch methods ***/
3003 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *pctinfo)
3005 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3006 IBasicAudio* pBasicAudio;
3007 HRESULT hr;
3009 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3011 EnterCriticalSection(&This->cs);
3013 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3015 if (hr == S_OK)
3016 hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
3018 LeaveCriticalSection(&This->cs);
3020 return hr;
3023 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT iTInfo, LCID lcid,
3024 ITypeInfo **ppTInfo)
3026 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3027 IBasicAudio* pBasicAudio;
3028 HRESULT hr;
3030 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3032 EnterCriticalSection(&This->cs);
3034 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3036 if (hr == S_OK)
3037 hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
3039 LeaveCriticalSection(&This->cs);
3041 return hr;
3044 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID riid, LPOLESTR *rgszNames,
3045 UINT cNames, LCID lcid, DISPID *rgDispId)
3047 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3048 IBasicAudio* pBasicAudio;
3049 HRESULT hr;
3051 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3053 EnterCriticalSection(&This->cs);
3055 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3057 if (hr == S_OK)
3058 hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
3060 LeaveCriticalSection(&This->cs);
3062 return hr;
3065 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID dispIdMember, REFIID riid,
3066 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3067 UINT *puArgErr)
3069 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3070 IBasicAudio* pBasicAudio;
3071 HRESULT hr;
3073 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);
3075 EnterCriticalSection(&This->cs);
3077 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3079 if (hr == S_OK)
3080 hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3082 LeaveCriticalSection(&This->cs);
3084 return hr;
3087 /*** IBasicAudio methods ***/
3088 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
3090 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3091 IBasicAudio* pBasicAudio;
3092 HRESULT hr;
3094 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
3096 EnterCriticalSection(&This->cs);
3098 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3100 if (hr == S_OK)
3101 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
3103 LeaveCriticalSection(&This->cs);
3105 return hr;
3108 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
3110 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3111 IBasicAudio* pBasicAudio;
3112 HRESULT hr;
3114 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
3116 EnterCriticalSection(&This->cs);
3118 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3120 if (hr == S_OK)
3121 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
3123 LeaveCriticalSection(&This->cs);
3125 return hr;
3128 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
3130 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3131 IBasicAudio* pBasicAudio;
3132 HRESULT hr;
3134 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
3136 EnterCriticalSection(&This->cs);
3138 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3140 if (hr == S_OK)
3141 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
3143 LeaveCriticalSection(&This->cs);
3145 return hr;
3148 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
3150 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3151 IBasicAudio* pBasicAudio;
3152 HRESULT hr;
3154 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
3156 EnterCriticalSection(&This->cs);
3158 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3160 if (hr == S_OK)
3161 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
3163 LeaveCriticalSection(&This->cs);
3165 return hr;
3168 static const IBasicAudioVtbl IBasicAudio_VTable =
3170 BasicAudio_QueryInterface,
3171 BasicAudio_AddRef,
3172 BasicAudio_Release,
3173 BasicAudio_GetTypeInfoCount,
3174 BasicAudio_GetTypeInfo,
3175 BasicAudio_GetIDsOfNames,
3176 BasicAudio_Invoke,
3177 BasicAudio_put_Volume,
3178 BasicAudio_get_Volume,
3179 BasicAudio_put_Balance,
3180 BasicAudio_get_Balance
3183 static inline IFilterGraphImpl *impl_from_IBasicVideo2(IBasicVideo2 *iface)
3185 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicVideo2_iface);
3188 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID riid, void **ppvObj)
3190 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3192 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3194 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
3197 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
3199 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3201 TRACE("(%p/%p)->()\n", This, iface);
3203 return IUnknown_AddRef(This->outer_unk);
3206 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
3208 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3210 TRACE("(%p/%p)->()\n", This, iface);
3212 return IUnknown_Release(This->outer_unk);
3215 /*** IDispatch methods ***/
3216 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *pctinfo)
3218 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3219 IBasicVideo *pBasicVideo;
3220 HRESULT hr;
3222 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3224 EnterCriticalSection(&This->cs);
3226 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3228 if (hr == S_OK)
3229 hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
3231 LeaveCriticalSection(&This->cs);
3233 return hr;
3236 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT iTInfo, LCID lcid,
3237 ITypeInfo **ppTInfo)
3239 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3240 IBasicVideo *pBasicVideo;
3241 HRESULT hr;
3243 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3245 EnterCriticalSection(&This->cs);
3247 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3249 if (hr == S_OK)
3250 hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
3252 LeaveCriticalSection(&This->cs);
3254 return hr;
3257 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID riid,
3258 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
3260 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3261 IBasicVideo *pBasicVideo;
3262 HRESULT hr;
3264 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3266 EnterCriticalSection(&This->cs);
3268 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3270 if (hr == S_OK)
3271 hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
3273 LeaveCriticalSection(&This->cs);
3275 return hr;
3278 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID dispIdMember, REFIID riid,
3279 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3280 UINT *puArgErr)
3282 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3283 IBasicVideo *pBasicVideo;
3284 HRESULT hr;
3286 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);
3288 EnterCriticalSection(&This->cs);
3290 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3292 if (hr == S_OK)
3293 hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3295 LeaveCriticalSection(&This->cs);
3297 return hr;
3300 /*** IBasicVideo methods ***/
3301 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3303 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3304 IBasicVideo *pBasicVideo;
3305 HRESULT hr;
3307 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3309 EnterCriticalSection(&This->cs);
3311 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3313 if (hr == S_OK)
3314 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3316 LeaveCriticalSection(&This->cs);
3318 return hr;
3321 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3323 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3324 IBasicVideo *pBasicVideo;
3325 HRESULT hr;
3327 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3329 EnterCriticalSection(&This->cs);
3331 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3333 if (hr == S_OK)
3334 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3336 LeaveCriticalSection(&This->cs);
3338 return hr;
3341 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3343 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3344 IBasicVideo *pBasicVideo;
3345 HRESULT hr;
3347 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3349 EnterCriticalSection(&This->cs);
3351 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3353 if (hr == S_OK)
3354 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3356 LeaveCriticalSection(&This->cs);
3358 return hr;
3361 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3363 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3364 IBasicVideo *pBasicVideo;
3365 HRESULT hr;
3367 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3369 EnterCriticalSection(&This->cs);
3371 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3373 if (hr == S_OK)
3374 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3376 LeaveCriticalSection(&This->cs);
3378 return hr;
3381 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3383 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3384 IBasicVideo *pBasicVideo;
3385 HRESULT hr;
3387 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3389 EnterCriticalSection(&This->cs);
3391 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3393 if (hr == S_OK)
3394 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3396 LeaveCriticalSection(&This->cs);
3398 return hr;
3401 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3403 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3404 IBasicVideo *pBasicVideo;
3405 HRESULT hr;
3407 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3409 EnterCriticalSection(&This->cs);
3411 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3413 if (hr == S_OK)
3414 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3416 LeaveCriticalSection(&This->cs);
3418 return hr;
3421 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3423 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3424 IBasicVideo *pBasicVideo;
3425 HRESULT hr;
3427 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3429 EnterCriticalSection(&This->cs);
3431 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3433 if (hr == S_OK)
3434 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3436 LeaveCriticalSection(&This->cs);
3438 return hr;
3441 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3443 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3444 IBasicVideo *pBasicVideo;
3445 HRESULT hr;
3447 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3449 EnterCriticalSection(&This->cs);
3451 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3453 if (hr == S_OK)
3454 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3456 LeaveCriticalSection(&This->cs);
3458 return hr;
3461 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3463 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3464 IBasicVideo *pBasicVideo;
3465 HRESULT hr;
3467 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3469 EnterCriticalSection(&This->cs);
3471 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3473 if (hr == S_OK)
3474 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3476 LeaveCriticalSection(&This->cs);
3478 return hr;
3481 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3483 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3484 IBasicVideo *pBasicVideo;
3485 HRESULT hr;
3487 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3489 EnterCriticalSection(&This->cs);
3491 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3493 if (hr == S_OK)
3494 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3496 LeaveCriticalSection(&This->cs);
3498 return hr;
3501 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3503 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3504 IBasicVideo *pBasicVideo;
3505 HRESULT hr;
3507 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3509 EnterCriticalSection(&This->cs);
3511 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3513 if (hr == S_OK)
3514 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3516 LeaveCriticalSection(&This->cs);
3518 return hr;
3521 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3523 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3524 IBasicVideo *pBasicVideo;
3525 HRESULT hr;
3527 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3529 EnterCriticalSection(&This->cs);
3531 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3533 if (hr == S_OK)
3534 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3536 LeaveCriticalSection(&This->cs);
3538 return hr;
3541 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3543 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3544 IBasicVideo *pBasicVideo;
3545 HRESULT hr;
3547 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3549 EnterCriticalSection(&This->cs);
3551 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3553 if (hr == S_OK)
3554 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3556 LeaveCriticalSection(&This->cs);
3558 return hr;
3561 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3563 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3564 IBasicVideo *pBasicVideo;
3565 HRESULT hr;
3567 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3569 EnterCriticalSection(&This->cs);
3571 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3573 if (hr == S_OK)
3574 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3576 LeaveCriticalSection(&This->cs);
3578 return hr;
3581 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3583 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3584 IBasicVideo *pBasicVideo;
3585 HRESULT hr;
3587 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3589 EnterCriticalSection(&This->cs);
3591 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3593 if (hr == S_OK)
3594 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3596 LeaveCriticalSection(&This->cs);
3598 return hr;
3601 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3603 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3604 IBasicVideo *pBasicVideo;
3605 HRESULT hr;
3607 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3609 EnterCriticalSection(&This->cs);
3611 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3613 if (hr == S_OK)
3614 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3616 LeaveCriticalSection(&This->cs);
3618 return hr;
3621 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3623 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3624 IBasicVideo *pBasicVideo;
3625 HRESULT hr;
3627 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3629 EnterCriticalSection(&This->cs);
3631 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3633 if (hr == S_OK)
3634 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3636 LeaveCriticalSection(&This->cs);
3638 return hr;
3641 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3643 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3644 IBasicVideo *pBasicVideo;
3645 HRESULT hr;
3647 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3649 EnterCriticalSection(&This->cs);
3651 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3653 if (hr == S_OK)
3654 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3656 LeaveCriticalSection(&This->cs);
3658 return hr;
3661 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3663 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3664 IBasicVideo *pBasicVideo;
3665 HRESULT hr;
3667 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3669 EnterCriticalSection(&This->cs);
3671 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3673 if (hr == S_OK)
3674 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3676 LeaveCriticalSection(&This->cs);
3678 return hr;
3681 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3683 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3684 IBasicVideo *pBasicVideo;
3685 HRESULT hr;
3687 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3689 EnterCriticalSection(&This->cs);
3691 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3693 if (hr == S_OK)
3694 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3696 LeaveCriticalSection(&This->cs);
3698 return hr;
3701 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3702 LONG *pDestinationHeight)
3704 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3705 IBasicVideo *pBasicVideo;
3706 HRESULT hr;
3708 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3710 EnterCriticalSection(&This->cs);
3712 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3714 if (hr == S_OK)
3715 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3717 LeaveCriticalSection(&This->cs);
3719 return hr;
3722 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3723 LONG Width, LONG Height)
3725 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3726 IBasicVideo *pBasicVideo;
3727 HRESULT hr;
3729 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3731 EnterCriticalSection(&This->cs);
3733 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3735 if (hr == S_OK)
3736 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3738 LeaveCriticalSection(&This->cs);
3740 return hr;
3743 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3744 LONG *pWidth, LONG *pHeight)
3746 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3747 IBasicVideo *pBasicVideo;
3748 HRESULT hr;
3750 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3752 EnterCriticalSection(&This->cs);
3754 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3756 if (hr == S_OK)
3757 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3759 LeaveCriticalSection(&This->cs);
3761 return hr;
3764 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3766 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3767 IBasicVideo *pBasicVideo;
3768 HRESULT hr;
3770 TRACE("(%p/%p)->()\n", This, iface);
3772 EnterCriticalSection(&This->cs);
3774 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3776 if (hr == S_OK)
3777 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3779 LeaveCriticalSection(&This->cs);
3781 return hr;
3784 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3785 LONG Width, LONG Height)
3787 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3788 IBasicVideo *pBasicVideo;
3789 HRESULT hr;
3791 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3793 EnterCriticalSection(&This->cs);
3795 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3797 if (hr == S_OK)
3798 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3800 LeaveCriticalSection(&This->cs);
3802 return hr;
3805 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3806 LONG *pTop, LONG *pWidth, LONG *pHeight)
3808 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3809 IBasicVideo *pBasicVideo;
3810 HRESULT hr;
3812 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3814 EnterCriticalSection(&This->cs);
3816 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3818 if (hr == S_OK)
3819 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3821 LeaveCriticalSection(&This->cs);
3823 return hr;
3826 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3828 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3829 IBasicVideo *pBasicVideo;
3830 HRESULT hr;
3832 TRACE("(%p/%p)->()\n", This, iface);
3834 EnterCriticalSection(&This->cs);
3836 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3838 if (hr == S_OK)
3839 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3841 LeaveCriticalSection(&This->cs);
3843 return hr;
3846 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3848 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3849 IBasicVideo *pBasicVideo;
3850 HRESULT hr;
3852 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3854 EnterCriticalSection(&This->cs);
3856 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3858 if (hr == S_OK)
3859 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3861 LeaveCriticalSection(&This->cs);
3863 return hr;
3866 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3867 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3869 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3870 IBasicVideo *pBasicVideo;
3871 HRESULT hr;
3873 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3875 EnterCriticalSection(&This->cs);
3877 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3879 if (hr == S_OK)
3880 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3882 LeaveCriticalSection(&This->cs);
3884 return hr;
3887 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3888 LONG *pDIBImage)
3890 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3891 IBasicVideo *pBasicVideo;
3892 HRESULT hr;
3894 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3896 EnterCriticalSection(&This->cs);
3898 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3900 if (hr == S_OK)
3901 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3903 LeaveCriticalSection(&This->cs);
3905 return hr;
3908 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3910 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3911 IBasicVideo *pBasicVideo;
3912 HRESULT hr;
3914 TRACE("(%p/%p)->()\n", This, iface);
3916 EnterCriticalSection(&This->cs);
3918 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3920 if (hr == S_OK)
3921 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3923 LeaveCriticalSection(&This->cs);
3925 return hr;
3928 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3930 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3931 IBasicVideo *pBasicVideo;
3932 HRESULT hr;
3934 TRACE("(%p/%p)->()\n", This, iface);
3936 EnterCriticalSection(&This->cs);
3938 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3940 if (hr == S_OK)
3941 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3943 LeaveCriticalSection(&This->cs);
3945 return hr;
3948 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3949 LONG *plAspectY)
3951 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3952 IBasicVideo2 *pBasicVideo2;
3953 HRESULT hr;
3955 TRACE("(%p/%p)->()\n", This, iface);
3957 EnterCriticalSection(&This->cs);
3959 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3961 if (hr == S_OK)
3962 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3964 LeaveCriticalSection(&This->cs);
3966 return hr;
3969 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3971 BasicVideo_QueryInterface,
3972 BasicVideo_AddRef,
3973 BasicVideo_Release,
3974 BasicVideo_GetTypeInfoCount,
3975 BasicVideo_GetTypeInfo,
3976 BasicVideo_GetIDsOfNames,
3977 BasicVideo_Invoke,
3978 BasicVideo_get_AvgTimePerFrame,
3979 BasicVideo_get_BitRate,
3980 BasicVideo_get_BitErrorRate,
3981 BasicVideo_get_VideoWidth,
3982 BasicVideo_get_VideoHeight,
3983 BasicVideo_put_SourceLeft,
3984 BasicVideo_get_SourceLeft,
3985 BasicVideo_put_SourceWidth,
3986 BasicVideo_get_SourceWidth,
3987 BasicVideo_put_SourceTop,
3988 BasicVideo_get_SourceTop,
3989 BasicVideo_put_SourceHeight,
3990 BasicVideo_get_SourceHeight,
3991 BasicVideo_put_DestinationLeft,
3992 BasicVideo_get_DestinationLeft,
3993 BasicVideo_put_DestinationWidth,
3994 BasicVideo_get_DestinationWidth,
3995 BasicVideo_put_DestinationTop,
3996 BasicVideo_get_DestinationTop,
3997 BasicVideo_put_DestinationHeight,
3998 BasicVideo_get_DestinationHeight,
3999 BasicVideo_SetSourcePosition,
4000 BasicVideo_GetSourcePosition,
4001 BasicVideo_SetDefaultSourcePosition,
4002 BasicVideo_SetDestinationPosition,
4003 BasicVideo_GetDestinationPosition,
4004 BasicVideo_SetDefaultDestinationPosition,
4005 BasicVideo_GetVideoSize,
4006 BasicVideo_GetVideoPaletteEntries,
4007 BasicVideo_GetCurrentImage,
4008 BasicVideo_IsUsingDefaultSource,
4009 BasicVideo_IsUsingDefaultDestination,
4010 BasicVideo2_GetPreferredAspectRatio
4013 static inline IFilterGraphImpl *impl_from_IVideoWindow(IVideoWindow *iface)
4015 return CONTAINING_RECORD(iface, IFilterGraphImpl, IVideoWindow_iface);
4018 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID riid, void **ppvObj)
4020 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4022 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
4024 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
4027 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
4029 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4031 TRACE("(%p/%p)->()\n", This, iface);
4033 return IUnknown_AddRef(This->outer_unk);
4036 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
4038 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4040 TRACE("(%p/%p)->()\n", This, iface);
4042 return IUnknown_Release(This->outer_unk);
4045 /*** IDispatch methods ***/
4046 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *pctinfo)
4048 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4049 IVideoWindow *pVideoWindow;
4050 HRESULT hr;
4052 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
4054 EnterCriticalSection(&This->cs);
4056 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4058 if (hr == S_OK)
4059 hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
4061 LeaveCriticalSection(&This->cs);
4063 return hr;
4066 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT iTInfo, LCID lcid,
4067 ITypeInfo **ppTInfo)
4069 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4070 IVideoWindow *pVideoWindow;
4071 HRESULT hr;
4073 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
4075 EnterCriticalSection(&This->cs);
4077 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4079 if (hr == S_OK)
4080 hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
4082 LeaveCriticalSection(&This->cs);
4084 return hr;
4087 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID riid,
4088 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4090 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4091 IVideoWindow *pVideoWindow;
4092 HRESULT hr;
4094 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
4096 EnterCriticalSection(&This->cs);
4098 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4100 if (hr == S_OK)
4101 hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
4103 LeaveCriticalSection(&This->cs);
4105 return hr;
4108 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID dispIdMember, REFIID riid,
4109 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4110 UINT*puArgErr)
4112 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4113 IVideoWindow *pVideoWindow;
4114 HRESULT hr;
4116 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);
4118 EnterCriticalSection(&This->cs);
4120 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4122 if (hr == S_OK)
4123 hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4125 LeaveCriticalSection(&This->cs);
4127 return hr;
4131 /*** IVideoWindow methods ***/
4132 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
4134 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4135 IVideoWindow *pVideoWindow;
4136 HRESULT hr;
4138 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
4140 EnterCriticalSection(&This->cs);
4142 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4144 if (hr == S_OK)
4145 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
4147 LeaveCriticalSection(&This->cs);
4149 return hr;
4152 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
4154 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4155 IVideoWindow *pVideoWindow;
4156 HRESULT hr;
4158 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
4160 EnterCriticalSection(&This->cs);
4162 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4164 if (hr == S_OK)
4165 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
4167 LeaveCriticalSection(&This->cs);
4169 return hr;
4172 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
4174 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4175 IVideoWindow *pVideoWindow;
4176 HRESULT hr;
4178 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
4180 EnterCriticalSection(&This->cs);
4182 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4184 if (hr == S_OK)
4185 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
4187 LeaveCriticalSection(&This->cs);
4189 return hr;
4192 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
4194 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4195 IVideoWindow *pVideoWindow;
4196 HRESULT hr;
4198 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
4200 EnterCriticalSection(&This->cs);
4202 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4204 if (hr == S_OK)
4205 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
4207 LeaveCriticalSection(&This->cs);
4209 return hr;
4212 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
4214 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4215 IVideoWindow *pVideoWindow;
4216 HRESULT hr;
4218 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
4220 EnterCriticalSection(&This->cs);
4222 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4224 if (hr == S_OK)
4225 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
4227 LeaveCriticalSection(&This->cs);
4229 return hr;
4232 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
4234 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4235 IVideoWindow *pVideoWindow;
4236 HRESULT hr;
4238 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
4240 EnterCriticalSection(&This->cs);
4242 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4244 if (hr == S_OK)
4245 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
4247 LeaveCriticalSection(&This->cs);
4249 return hr;
4252 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
4254 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4255 IVideoWindow *pVideoWindow;
4256 HRESULT hr;
4258 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
4260 EnterCriticalSection(&This->cs);
4262 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4264 if (hr == S_OK)
4265 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4267 LeaveCriticalSection(&This->cs);
4269 return hr;
4272 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
4274 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4275 IVideoWindow *pVideoWindow;
4276 HRESULT hr;
4278 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4280 EnterCriticalSection(&This->cs);
4282 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4284 if (hr == S_OK)
4285 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4287 LeaveCriticalSection(&This->cs);
4289 return hr;
4292 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
4294 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4295 IVideoWindow *pVideoWindow;
4296 HRESULT hr;
4298 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4300 EnterCriticalSection(&This->cs);
4302 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4304 if (hr == S_OK)
4305 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4307 LeaveCriticalSection(&This->cs);
4309 return hr;
4312 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4314 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4315 IVideoWindow *pVideoWindow;
4316 HRESULT hr;
4318 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4320 EnterCriticalSection(&This->cs);
4322 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4324 if (hr == S_OK)
4325 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4327 LeaveCriticalSection(&This->cs);
4329 return hr;
4332 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4334 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4335 IVideoWindow *pVideoWindow;
4336 HRESULT hr;
4338 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4340 EnterCriticalSection(&This->cs);
4342 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4344 if (hr == S_OK)
4345 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4347 LeaveCriticalSection(&This->cs);
4349 return hr;
4352 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4353 LONG *pBackgroundPalette)
4355 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4356 IVideoWindow *pVideoWindow;
4357 HRESULT hr;
4359 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4361 EnterCriticalSection(&This->cs);
4363 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4365 if (hr == S_OK)
4366 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4368 LeaveCriticalSection(&This->cs);
4370 return hr;
4373 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4375 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4376 IVideoWindow *pVideoWindow;
4377 HRESULT hr;
4379 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4381 EnterCriticalSection(&This->cs);
4383 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4385 if (hr == S_OK)
4386 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4388 LeaveCriticalSection(&This->cs);
4390 return hr;
4393 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4395 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4396 IVideoWindow *pVideoWindow;
4397 HRESULT hr;
4399 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4401 EnterCriticalSection(&This->cs);
4403 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4405 if (hr == S_OK)
4406 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4408 LeaveCriticalSection(&This->cs);
4410 return hr;
4413 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4415 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4416 IVideoWindow *pVideoWindow;
4417 HRESULT hr;
4419 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4421 EnterCriticalSection(&This->cs);
4423 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4425 if (hr == S_OK)
4426 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4428 LeaveCriticalSection(&This->cs);
4430 return hr;
4433 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4435 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4436 IVideoWindow *pVideoWindow;
4437 HRESULT hr;
4439 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4441 EnterCriticalSection(&This->cs);
4443 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4445 if (hr == S_OK)
4446 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4448 LeaveCriticalSection(&This->cs);
4450 return hr;
4453 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4455 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4456 IVideoWindow *pVideoWindow;
4457 HRESULT hr;
4459 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4461 EnterCriticalSection(&This->cs);
4463 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4465 if (hr == S_OK)
4466 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4468 LeaveCriticalSection(&This->cs);
4470 return hr;
4473 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4475 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4476 IVideoWindow *pVideoWindow;
4477 HRESULT hr;
4479 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4481 EnterCriticalSection(&This->cs);
4483 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4485 if (hr == S_OK)
4486 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4488 LeaveCriticalSection(&This->cs);
4490 return hr;
4493 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4495 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4496 IVideoWindow *pVideoWindow;
4497 HRESULT hr;
4499 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4501 EnterCriticalSection(&This->cs);
4503 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4505 if (hr == S_OK)
4506 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4508 LeaveCriticalSection(&This->cs);
4510 return hr;
4513 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4515 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4516 IVideoWindow *pVideoWindow;
4517 HRESULT hr;
4519 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4521 EnterCriticalSection(&This->cs);
4523 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4525 if (hr == S_OK)
4526 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4528 LeaveCriticalSection(&This->cs);
4530 return hr;
4533 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4535 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4536 IVideoWindow *pVideoWindow;
4537 HRESULT hr;
4539 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4541 EnterCriticalSection(&This->cs);
4543 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4545 if (hr == S_OK)
4546 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4548 LeaveCriticalSection(&This->cs);
4550 return hr;
4553 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4555 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4556 IVideoWindow *pVideoWindow;
4557 HRESULT hr;
4559 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4561 EnterCriticalSection(&This->cs);
4563 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4565 if (hr == S_OK)
4566 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4568 LeaveCriticalSection(&This->cs);
4570 return hr;
4573 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4575 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4576 IVideoWindow *pVideoWindow;
4577 HRESULT hr;
4579 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4581 EnterCriticalSection(&This->cs);
4583 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4585 if (hr == S_OK)
4586 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4588 LeaveCriticalSection(&This->cs);
4590 return hr;
4593 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4595 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4596 IVideoWindow *pVideoWindow;
4597 HRESULT hr;
4599 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4601 EnterCriticalSection(&This->cs);
4603 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4605 if (hr == S_OK)
4606 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4608 LeaveCriticalSection(&This->cs);
4610 return hr;
4613 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4615 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4616 IVideoWindow *pVideoWindow;
4617 HRESULT hr;
4619 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4621 EnterCriticalSection(&This->cs);
4623 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4625 if (hr == S_OK)
4626 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4628 LeaveCriticalSection(&This->cs);
4630 return hr;
4633 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4635 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4636 IVideoWindow *pVideoWindow;
4637 HRESULT hr;
4639 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4641 EnterCriticalSection(&This->cs);
4643 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4645 if (hr == S_OK)
4646 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4648 LeaveCriticalSection(&This->cs);
4650 return hr;
4653 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4655 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4656 IVideoWindow *pVideoWindow;
4657 HRESULT hr;
4659 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4661 EnterCriticalSection(&This->cs);
4663 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4665 if (hr == S_OK)
4666 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4668 LeaveCriticalSection(&This->cs);
4670 return hr;
4673 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4675 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4676 IVideoWindow *pVideoWindow;
4677 HRESULT hr;
4679 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4681 EnterCriticalSection(&This->cs);
4683 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4685 if (hr == S_OK)
4686 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4688 LeaveCriticalSection(&This->cs);
4690 return hr;
4693 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4695 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4696 IVideoWindow *pVideoWindow;
4697 HRESULT hr;
4699 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4701 EnterCriticalSection(&This->cs);
4703 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4705 if (hr == S_OK)
4706 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4708 LeaveCriticalSection(&This->cs);
4710 return hr;
4713 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4715 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4716 IVideoWindow *pVideoWindow;
4717 HRESULT hr;
4719 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4721 EnterCriticalSection(&This->cs);
4723 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4725 if (hr == S_OK)
4726 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4728 LeaveCriticalSection(&This->cs);
4730 return hr;
4733 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4735 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4736 IVideoWindow *pVideoWindow;
4737 HRESULT hr;
4739 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4741 EnterCriticalSection(&This->cs);
4743 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4745 if (hr == S_OK)
4746 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4748 LeaveCriticalSection(&This->cs);
4750 return hr;
4753 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4754 LONG_PTR wParam, LONG_PTR lParam)
4756 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4757 IVideoWindow *pVideoWindow;
4758 HRESULT hr;
4760 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4762 EnterCriticalSection(&This->cs);
4764 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4766 if (hr == S_OK)
4767 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4769 LeaveCriticalSection(&This->cs);
4771 return hr;
4774 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4775 LONG Width, LONG Height)
4777 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4778 IVideoWindow *pVideoWindow;
4779 HRESULT hr;
4781 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4783 EnterCriticalSection(&This->cs);
4785 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4787 if (hr == S_OK)
4788 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4790 LeaveCriticalSection(&This->cs);
4792 return hr;
4795 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4796 LONG *pWidth, LONG *pHeight)
4798 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4799 IVideoWindow *pVideoWindow;
4800 HRESULT hr;
4802 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4804 EnterCriticalSection(&This->cs);
4806 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4808 if (hr == S_OK)
4809 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4811 LeaveCriticalSection(&This->cs);
4813 return hr;
4816 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4817 LONG *pHeight)
4819 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4820 IVideoWindow *pVideoWindow;
4821 HRESULT hr;
4823 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4825 EnterCriticalSection(&This->cs);
4827 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4829 if (hr == S_OK)
4830 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4832 LeaveCriticalSection(&This->cs);
4834 return hr;
4837 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4838 LONG *pHeight)
4840 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4841 IVideoWindow *pVideoWindow;
4842 HRESULT hr;
4844 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4846 EnterCriticalSection(&This->cs);
4848 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4850 if (hr == S_OK)
4851 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4853 LeaveCriticalSection(&This->cs);
4855 return hr;
4858 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4859 LONG *pWidth, LONG *pHeight)
4861 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4862 IVideoWindow *pVideoWindow;
4863 HRESULT hr;
4865 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4867 EnterCriticalSection(&This->cs);
4869 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4871 if (hr == S_OK)
4872 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4874 LeaveCriticalSection(&This->cs);
4876 return hr;
4879 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4881 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4882 IVideoWindow *pVideoWindow;
4883 HRESULT hr;
4885 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4887 EnterCriticalSection(&This->cs);
4889 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4891 if (hr == S_OK)
4892 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4894 LeaveCriticalSection(&This->cs);
4896 return hr;
4899 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4901 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4902 IVideoWindow *pVideoWindow;
4903 HRESULT hr;
4905 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4907 EnterCriticalSection(&This->cs);
4909 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4911 if (hr == S_OK)
4912 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4914 LeaveCriticalSection(&This->cs);
4916 return hr;
4920 static const IVideoWindowVtbl IVideoWindow_VTable =
4922 VideoWindow_QueryInterface,
4923 VideoWindow_AddRef,
4924 VideoWindow_Release,
4925 VideoWindow_GetTypeInfoCount,
4926 VideoWindow_GetTypeInfo,
4927 VideoWindow_GetIDsOfNames,
4928 VideoWindow_Invoke,
4929 VideoWindow_put_Caption,
4930 VideoWindow_get_Caption,
4931 VideoWindow_put_WindowStyle,
4932 VideoWindow_get_WindowStyle,
4933 VideoWindow_put_WindowStyleEx,
4934 VideoWindow_get_WindowStyleEx,
4935 VideoWindow_put_AutoShow,
4936 VideoWindow_get_AutoShow,
4937 VideoWindow_put_WindowState,
4938 VideoWindow_get_WindowState,
4939 VideoWindow_put_BackgroundPalette,
4940 VideoWindow_get_BackgroundPalette,
4941 VideoWindow_put_Visible,
4942 VideoWindow_get_Visible,
4943 VideoWindow_put_Left,
4944 VideoWindow_get_Left,
4945 VideoWindow_put_Width,
4946 VideoWindow_get_Width,
4947 VideoWindow_put_Top,
4948 VideoWindow_get_Top,
4949 VideoWindow_put_Height,
4950 VideoWindow_get_Height,
4951 VideoWindow_put_Owner,
4952 VideoWindow_get_Owner,
4953 VideoWindow_put_MessageDrain,
4954 VideoWindow_get_MessageDrain,
4955 VideoWindow_get_BorderColor,
4956 VideoWindow_put_BorderColor,
4957 VideoWindow_get_FullScreenMode,
4958 VideoWindow_put_FullScreenMode,
4959 VideoWindow_SetWindowForeground,
4960 VideoWindow_NotifyOwnerMessage,
4961 VideoWindow_SetWindowPosition,
4962 VideoWindow_GetWindowPosition,
4963 VideoWindow_GetMinIdealImageSize,
4964 VideoWindow_GetMaxIdealImageSize,
4965 VideoWindow_GetRestorePosition,
4966 VideoWindow_HideCursor,
4967 VideoWindow_IsCursorHidden
4970 static inline IFilterGraphImpl *impl_from_IMediaEventEx(IMediaEventEx *iface)
4972 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventEx_iface);
4975 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID riid, void **ppvObj)
4977 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4979 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
4981 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
4984 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
4986 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4988 TRACE("(%p/%p)->()\n", This, iface);
4990 return IUnknown_AddRef(This->outer_unk);
4993 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
4995 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4997 TRACE("(%p/%p)->()\n", This, iface);
4999 return IUnknown_Release(This->outer_unk);
5002 /*** IDispatch methods ***/
5003 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *pctinfo)
5005 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5007 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
5009 return S_OK;
5012 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT iTInfo, LCID lcid,
5013 ITypeInfo **ppTInfo)
5015 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5017 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
5019 return S_OK;
5022 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID riid,
5023 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
5025 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5027 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
5029 return S_OK;
5032 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID dispIdMember, REFIID riid,
5033 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
5034 UINT *puArgErr)
5036 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5038 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);
5040 return S_OK;
5043 /*** IMediaEvent methods ***/
5044 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *hEvent)
5046 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5048 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
5050 *hEvent = (OAEVENT)This->evqueue.msg_event;
5052 return S_OK;
5055 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *lEventCode, LONG_PTR *lParam1,
5056 LONG_PTR *lParam2, LONG msTimeout)
5058 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5059 Event evt;
5061 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
5063 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
5065 *lEventCode = evt.lEventCode;
5066 *lParam1 = evt.lParam1;
5067 *lParam2 = evt.lParam2;
5068 return S_OK;
5071 *lEventCode = 0;
5072 return E_ABORT;
5075 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
5076 LONG *pEvCode)
5078 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5080 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
5082 if (This->state != State_Running)
5083 return VFW_E_WRONG_STATE;
5085 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
5087 *pEvCode = This->CompletionStatus;
5088 return S_OK;
5091 *pEvCode = 0;
5092 return E_ABORT;
5095 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5097 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5099 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5101 if (lEvCode == EC_COMPLETE)
5102 This->HandleEcComplete = FALSE;
5103 else if (lEvCode == EC_REPAINT)
5104 This->HandleEcRepaint = FALSE;
5105 else if (lEvCode == EC_CLOCK_CHANGED)
5106 This->HandleEcClockChanged = FALSE;
5107 else
5108 return S_FALSE;
5110 return S_OK;
5113 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5115 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5117 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5119 if (lEvCode == EC_COMPLETE)
5120 This->HandleEcComplete = TRUE;
5121 else if (lEvCode == EC_REPAINT)
5122 This->HandleEcRepaint = TRUE;
5123 else if (lEvCode == EC_CLOCK_CHANGED)
5124 This->HandleEcClockChanged = TRUE;
5125 else
5126 return S_FALSE;
5128 return S_OK;
5131 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG lEvCode,
5132 LONG_PTR lParam1, LONG_PTR lParam2)
5134 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5136 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
5138 return S_OK;
5141 /*** IMediaEventEx methods ***/
5142 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface, OAHWND hwnd, LONG lMsg,
5143 LONG_PTR lInstanceData)
5145 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5147 TRACE("(%p/%p)->(%08lx, %d, %08lx)\n", This, iface, hwnd, lMsg, lInstanceData);
5149 This->notif.hWnd = (HWND)hwnd;
5150 This->notif.msg = lMsg;
5151 This->notif.instance = lInstanceData;
5153 return S_OK;
5156 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG lNoNotifyFlags)
5158 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5160 TRACE("(%p/%p)->(%d)\n", This, iface, lNoNotifyFlags);
5162 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
5163 return E_INVALIDARG;
5165 This->notif.disabled = lNoNotifyFlags;
5167 return S_OK;
5170 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *lplNoNotifyFlags)
5172 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5174 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
5176 if (!lplNoNotifyFlags)
5177 return E_POINTER;
5179 *lplNoNotifyFlags = This->notif.disabled;
5181 return S_OK;
5185 static const IMediaEventExVtbl IMediaEventEx_VTable =
5187 MediaEvent_QueryInterface,
5188 MediaEvent_AddRef,
5189 MediaEvent_Release,
5190 MediaEvent_GetTypeInfoCount,
5191 MediaEvent_GetTypeInfo,
5192 MediaEvent_GetIDsOfNames,
5193 MediaEvent_Invoke,
5194 MediaEvent_GetEventHandle,
5195 MediaEvent_GetEvent,
5196 MediaEvent_WaitForCompletion,
5197 MediaEvent_CancelDefaultHandling,
5198 MediaEvent_RestoreDefaultHandling,
5199 MediaEvent_FreeEventParams,
5200 MediaEvent_SetNotifyWindow,
5201 MediaEvent_SetNotifyFlags,
5202 MediaEvent_GetNotifyFlags
5206 static inline IFilterGraphImpl *impl_from_IMediaFilter(IMediaFilter *iface)
5208 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaFilter_iface);
5211 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, void **ppv)
5213 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5215 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5218 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
5220 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5222 return IUnknown_AddRef(This->outer_unk);
5225 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
5227 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5229 return IUnknown_Release(This->outer_unk);
5232 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
5234 FIXME("(%p): stub\n", pClassID);
5236 return E_NOTIMPL;
5239 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
5241 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5243 return MediaControl_Stop(&This->IMediaControl_iface);
5246 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5248 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5250 return MediaControl_Pause(&This->IMediaControl_iface);
5253 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
5255 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5257 if (tStart)
5258 FIXME("Run called with non-null tStart: %x%08x\n",
5259 (int)(tStart>>32), (int)tStart);
5261 return MediaControl_Run(&This->IMediaControl_iface);
5264 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout,
5265 FILTER_STATE *pState)
5267 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5269 return MediaControl_GetState(&This->IMediaControl_iface, dwMsTimeout, (OAFilterState*)pState);
5272 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5274 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5275 HRESULT hr = S_OK;
5276 int i;
5278 TRACE("(%p/%p)->(%p)\n", iface, This, pClock);
5280 EnterCriticalSection(&This->cs);
5282 for (i = 0;i < This->nFilters;i++)
5284 hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5285 if (FAILED(hr))
5286 break;
5289 if (FAILED(hr))
5291 for(;i >= 0;i--)
5292 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5294 else
5296 if (This->refClock)
5297 IReferenceClock_Release(This->refClock);
5298 This->refClock = pClock;
5299 if (This->refClock)
5300 IReferenceClock_AddRef(This->refClock);
5301 This->defaultclock = FALSE;
5303 if (This->HandleEcClockChanged)
5305 IMediaEventSink *pEventSink;
5306 HRESULT eshr;
5308 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (void **)&pEventSink);
5309 if (SUCCEEDED(eshr))
5311 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5312 IMediaEventSink_Release(pEventSink);
5317 LeaveCriticalSection(&This->cs);
5319 return hr;
5322 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5324 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5326 TRACE("(%p/%p)->(%p)\n", iface, This, ppClock);
5328 if (!ppClock)
5329 return E_POINTER;
5331 EnterCriticalSection(&This->cs);
5333 *ppClock = This->refClock;
5334 if (*ppClock)
5335 IReferenceClock_AddRef(*ppClock);
5337 LeaveCriticalSection(&This->cs);
5339 return S_OK;
5342 static const IMediaFilterVtbl IMediaFilter_VTable =
5344 MediaFilter_QueryInterface,
5345 MediaFilter_AddRef,
5346 MediaFilter_Release,
5347 MediaFilter_GetClassID,
5348 MediaFilter_Stop,
5349 MediaFilter_Pause,
5350 MediaFilter_Run,
5351 MediaFilter_GetState,
5352 MediaFilter_SetSyncSource,
5353 MediaFilter_GetSyncSource
5356 static inline IFilterGraphImpl *impl_from_IMediaEventSink(IMediaEventSink *iface)
5358 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventSink_iface);
5361 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, void **ppv)
5363 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5365 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5368 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5370 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5372 return IUnknown_AddRef(This->outer_unk);
5375 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5377 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5379 return IUnknown_Release(This->outer_unk);
5382 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG EventCode,
5383 LONG_PTR EventParam1, LONG_PTR EventParam2)
5385 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5386 Event evt;
5388 TRACE("(%p/%p)->(%d, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5390 /* We need thread safety here, let's use the events queue's one */
5391 EnterCriticalSection(&This->evqueue.msg_crst);
5393 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5395 TRACE("Process EC_COMPLETE notification\n");
5396 if (++This->EcCompleteCount == This->nRenderers)
5398 evt.lEventCode = EC_COMPLETE;
5399 evt.lParam1 = S_OK;
5400 evt.lParam2 = 0;
5401 TRACE("Send EC_COMPLETE to app\n");
5402 EventsQueue_PutEvent(&This->evqueue, &evt);
5403 if (!This->notif.disabled && This->notif.hWnd)
5405 TRACE("Send Window message\n");
5406 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5408 This->CompletionStatus = EC_COMPLETE;
5409 SetEvent(This->hEventCompletion);
5412 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5414 /* FIXME: Not handled yet */
5416 else
5418 evt.lEventCode = EventCode;
5419 evt.lParam1 = EventParam1;
5420 evt.lParam2 = EventParam2;
5421 EventsQueue_PutEvent(&This->evqueue, &evt);
5422 if (!This->notif.disabled && This->notif.hWnd)
5423 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5426 LeaveCriticalSection(&This->evqueue.msg_crst);
5427 return S_OK;
5430 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5432 MediaEventSink_QueryInterface,
5433 MediaEventSink_AddRef,
5434 MediaEventSink_Release,
5435 MediaEventSink_Notify
5438 static inline IFilterGraphImpl *impl_from_IGraphConfig(IGraphConfig *iface)
5440 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphConfig_iface);
5443 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, void **ppv)
5445 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5447 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5450 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5452 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5454 return IUnknown_AddRef(This->outer_unk);
5457 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5459 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5461 return IUnknown_Release(This->outer_unk);
5464 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *pOutputPin, IPin *pInputPin,
5465 const AM_MEDIA_TYPE *pmtFirstConnection, IBaseFilter *pUsingFilter, HANDLE hAbortEvent,
5466 DWORD dwFlags)
5468 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5470 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5472 return E_NOTIMPL;
5475 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface, IGraphConfigCallback *pCallback,
5476 void *pvContext, DWORD dwFlags, HANDLE hAbortEvent)
5478 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5479 HRESULT hr;
5481 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5483 if (hAbortEvent)
5484 FIXME("The parameter hAbortEvent is not handled!\n");
5486 EnterCriticalSection(&This->cs);
5488 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5490 LeaveCriticalSection(&This->cs);
5492 return hr;
5495 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5497 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5499 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5501 return E_NOTIMPL;
5504 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5506 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5508 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5510 return E_NOTIMPL;
5513 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5515 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5517 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5519 return E_NOTIMPL;
5522 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5524 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5526 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5528 return E_NOTIMPL;
5531 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5532 IPinConnection *pConnection, HANDLE hEventAbort)
5534 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5536 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5538 return E_NOTIMPL;
5541 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5542 DWORD dwFlags)
5544 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5546 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5548 return E_NOTIMPL;
5551 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5552 DWORD *dwFlags)
5554 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5556 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5558 return E_NOTIMPL;
5561 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *pFilter,
5562 DWORD dwFlags)
5564 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5566 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5568 return E_NOTIMPL;
5571 static const IGraphConfigVtbl IGraphConfig_VTable =
5573 GraphConfig_QueryInterface,
5574 GraphConfig_AddRef,
5575 GraphConfig_Release,
5576 GraphConfig_Reconnect,
5577 GraphConfig_Reconfigure,
5578 GraphConfig_AddFilterToCache,
5579 GraphConfig_EnumCacheFilter,
5580 GraphConfig_RemoveFilterFromCache,
5581 GraphConfig_GetStartTime,
5582 GraphConfig_PushThroughData,
5583 GraphConfig_SetFilterFlags,
5584 GraphConfig_GetFilterFlags,
5585 GraphConfig_RemoveFilterEx
5588 static inline IFilterGraphImpl *impl_from_IGraphVersion(IGraphVersion *iface)
5590 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphVersion_iface);
5593 static HRESULT WINAPI GraphVersion_QueryInterface(IGraphVersion *iface, REFIID riid, void **ppv)
5595 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5597 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5600 static ULONG WINAPI GraphVersion_AddRef(IGraphVersion *iface)
5602 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5604 return IUnknown_AddRef(This->outer_unk);
5607 static ULONG WINAPI GraphVersion_Release(IGraphVersion *iface)
5609 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5611 return IUnknown_Release(This->outer_unk);
5614 static HRESULT WINAPI GraphVersion_QueryVersion(IGraphVersion *iface, LONG *pVersion)
5616 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5618 if(!pVersion)
5619 return E_POINTER;
5621 TRACE("(%p)->(%p): current version %i\n", This, pVersion, This->version);
5623 *pVersion = This->version;
5624 return S_OK;
5627 static const IGraphVersionVtbl IGraphVersion_VTable =
5629 GraphVersion_QueryInterface,
5630 GraphVersion_AddRef,
5631 GraphVersion_Release,
5632 GraphVersion_QueryVersion,
5635 static const IUnknownVtbl IInner_VTable =
5637 FilterGraphInner_QueryInterface,
5638 FilterGraphInner_AddRef,
5639 FilterGraphInner_Release
5642 /* This is the only function that actually creates a FilterGraph class... */
5643 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5645 IFilterGraphImpl *fimpl;
5646 HRESULT hr;
5648 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5650 *ppObj = NULL;
5652 fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5653 fimpl->defaultclock = TRUE;
5654 fimpl->IUnknown_inner.lpVtbl = &IInner_VTable;
5655 fimpl->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5656 fimpl->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5657 fimpl->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5658 fimpl->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5659 fimpl->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5660 fimpl->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5661 fimpl->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5662 fimpl->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5663 fimpl->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5664 fimpl->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5665 fimpl->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5666 fimpl->IObjectWithSite_iface.lpVtbl = &IObjectWithSite_VTable;
5667 fimpl->IGraphVersion_iface.lpVtbl = &IGraphVersion_VTable;
5668 fimpl->ref = 1;
5669 fimpl->ppFiltersInGraph = NULL;
5670 fimpl->pFilterNames = NULL;
5671 fimpl->nFilters = 0;
5672 fimpl->filterCapacity = 0;
5673 fimpl->nameIndex = 1;
5674 fimpl->refClock = NULL;
5675 fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5676 fimpl->HandleEcComplete = TRUE;
5677 fimpl->HandleEcRepaint = TRUE;
5678 fimpl->HandleEcClockChanged = TRUE;
5679 fimpl->notif.hWnd = 0;
5680 fimpl->notif.disabled = FALSE;
5681 fimpl->nRenderers = 0;
5682 fimpl->EcCompleteCount = 0;
5683 fimpl->refClockProvider = NULL;
5684 fimpl->state = State_Stopped;
5685 fimpl->pSite = NULL;
5686 EventsQueue_Init(&fimpl->evqueue);
5687 InitializeCriticalSection(&fimpl->cs);
5688 fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5689 fimpl->nItfCacheEntries = 0;
5690 memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5691 fimpl->start_time = fimpl->pause_time = 0;
5692 fimpl->stop_position = -1;
5693 fimpl->punkFilterMapper2 = NULL;
5694 fimpl->recursioncount = 0;
5695 fimpl->version = 0;
5697 if (pUnkOuter)
5698 fimpl->outer_unk = pUnkOuter;
5699 else
5700 fimpl->outer_unk = &fimpl->IUnknown_inner;
5702 /* create Filtermapper aggregated. */
5703 hr = CoCreateInstance(&CLSID_FilterMapper2, fimpl->outer_unk, CLSCTX_INPROC_SERVER,
5704 &IID_IUnknown, (void**)&fimpl->punkFilterMapper2);
5706 if (SUCCEEDED(hr))
5707 hr = IUnknown_QueryInterface(fimpl->punkFilterMapper2, &IID_IFilterMapper2,
5708 (void**)&fimpl->pFilterMapper2);
5710 if (SUCCEEDED(hr))
5711 /* Release controlling IUnknown - compensate refcount increase from caching IFilterMapper2 interface. */
5712 IUnknown_Release(fimpl->outer_unk);
5714 if (FAILED(hr)) {
5715 ERR("Unable to create filter mapper (%x)\n", hr);
5716 if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5717 CloseHandle(fimpl->hEventCompletion);
5718 EventsQueue_Destroy(&fimpl->evqueue);
5719 fimpl->cs.DebugInfo->Spare[0] = 0;
5720 DeleteCriticalSection(&fimpl->cs);
5721 CoTaskMemFree(fimpl);
5722 return hr;
5725 *ppObj = &fimpl->IUnknown_inner;
5726 return S_OK;
5729 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5731 FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5732 return FilterGraph_create(pUnkOuter, ppObj);