usp10: Merge GSUB_initialize_script_cache() and GPOS_expand_script_cache().
[wine.git] / dlls / quartz / filtergraph.c
blob0113674f34ec672396dd0ba7570230ae5dd4dd31
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 IBaseFilter ** ppFiltersInGraph;
180 LPWSTR * pFilterNames;
181 ULONG nFilters;
182 int filterCapacity;
183 LONG nameIndex;
184 IReferenceClock *refClock;
185 IBaseFilter *refClockProvider;
186 EventsQueue evqueue;
187 HANDLE hEventCompletion;
188 int CompletionStatus;
189 WndNotify notif;
190 int nRenderers;
191 int EcCompleteCount;
192 int HandleEcComplete;
193 int HandleEcRepaint;
194 int HandleEcClockChanged;
195 OAFilterState state;
196 CRITICAL_SECTION cs;
197 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
198 int nItfCacheEntries;
199 BOOL defaultclock;
200 GUID timeformatseek;
201 REFERENCE_TIME start_time;
202 REFERENCE_TIME pause_time;
203 LONGLONG stop_position;
204 LONG recursioncount;
205 IUnknown *pSite;
206 LONG version;
207 } IFilterGraphImpl;
209 static inline IFilterGraphImpl *impl_from_IUnknown(IUnknown *iface)
211 return CONTAINING_RECORD(iface, IFilterGraphImpl, IUnknown_inner);
214 static HRESULT WINAPI FilterGraphInner_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObj)
216 IFilterGraphImpl *This = impl_from_IUnknown(iface);
217 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObj);
219 if (IsEqualGUID(&IID_IUnknown, riid)) {
220 *ppvObj = &This->IUnknown_inner;
221 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
222 } else if (IsEqualGUID(&IID_IFilterGraph, riid) ||
223 IsEqualGUID(&IID_IFilterGraph2, riid) ||
224 IsEqualGUID(&IID_IGraphBuilder, riid)) {
225 *ppvObj = &This->IFilterGraph2_iface;
226 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj);
227 } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
228 *ppvObj = &This->IMediaControl_iface;
229 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj);
230 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
231 *ppvObj = &This->IMediaSeeking_iface;
232 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
233 } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
234 *ppvObj = &This->IBasicAudio_iface;
235 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj);
236 } else if (IsEqualGUID(&IID_IBasicVideo, riid) ||
237 IsEqualGUID(&IID_IBasicVideo2, riid)) {
238 *ppvObj = &This->IBasicVideo2_iface;
239 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj);
240 } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
241 *ppvObj = &This->IVideoWindow_iface;
242 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj);
243 } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
244 IsEqualGUID(&IID_IMediaEventEx, riid)) {
245 *ppvObj = &This->IMediaEventEx_iface;
246 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
247 } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
248 IsEqualGUID(&IID_IPersist, riid)) {
249 *ppvObj = &This->IMediaFilter_iface;
250 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj);
251 } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
252 *ppvObj = &This->IMediaEventSink_iface;
253 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj);
254 } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
255 *ppvObj = &This->IGraphConfig_iface;
256 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
257 } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
258 *ppvObj = &This->IMediaPosition_iface;
259 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj);
260 } else if (IsEqualGUID(&IID_IObjectWithSite, riid)) {
261 *ppvObj = &This->IObjectWithSite_iface;
262 TRACE(" returning IObjectWithSite interface (%p)\n", *ppvObj);
263 } else if (IsEqualGUID(&IID_IFilterMapper, riid)) {
264 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj);
265 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
266 } else if (IsEqualGUID(&IID_IFilterMapper2, riid)) {
267 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
268 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
269 } else if (IsEqualGUID(&IID_IFilterMapper3, riid)) {
270 TRACE(" returning IFilterMapper3 interface from aggregated filtermapper (%p)\n", *ppvObj);
271 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
272 } else if (IsEqualGUID(&IID_IGraphVersion, riid)) {
273 *ppvObj = &This->IGraphConfig_iface;
274 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
275 } else {
276 *ppvObj = NULL;
277 FIXME("unknown interface %s\n", debugstr_guid(riid));
278 return E_NOINTERFACE;
281 IUnknown_AddRef((IUnknown *)*ppvObj);
282 return S_OK;
285 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown *iface)
287 IFilterGraphImpl *This = impl_from_IUnknown(iface);
288 ULONG ref = InterlockedIncrement(&This->ref);
290 TRACE("(%p)->(): new ref = %d\n", This, ref);
292 return ref;
295 static ULONG WINAPI FilterGraphInner_Release(IUnknown *iface)
297 IFilterGraphImpl *This = impl_from_IUnknown(iface);
298 ULONG ref = InterlockedDecrement(&This->ref);
300 TRACE("(%p)->(): new ref = %d\n", This, ref);
302 if (ref == 0) {
303 int i;
305 This->ref = 1; /* guard against reentrancy (aggregation). */
307 IMediaControl_Stop(&This->IMediaControl_iface);
309 while (This->nFilters)
310 IFilterGraph2_RemoveFilter(&This->IFilterGraph2_iface, This->ppFiltersInGraph[0]);
312 if (This->refClock)
313 IReferenceClock_Release(This->refClock);
315 for (i = 0; i < This->nItfCacheEntries; i++)
317 if (This->ItfCacheEntries[i].iface)
318 IUnknown_Release(This->ItfCacheEntries[i].iface);
321 IUnknown_Release(This->punkFilterMapper2);
323 if (This->pSite) IUnknown_Release(This->pSite);
325 CloseHandle(This->hEventCompletion);
326 EventsQueue_Destroy(&This->evqueue);
327 This->cs.DebugInfo->Spare[0] = 0;
328 DeleteCriticalSection(&This->cs);
329 CoTaskMemFree(This->ppFiltersInGraph);
330 CoTaskMemFree(This->pFilterNames);
331 CoTaskMemFree(This);
333 return ref;
336 static inline IFilterGraphImpl *impl_from_IFilterGraph2(IFilterGraph2 *iface)
338 return CONTAINING_RECORD(iface, IFilterGraphImpl, IFilterGraph2_iface);
341 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface, REFIID riid, void **ppvObj)
343 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
345 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
347 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
350 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface)
352 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
354 TRACE("(%p/%p)->()\n", This, iface);
356 return IUnknown_AddRef(This->outer_unk);
359 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface)
361 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
363 TRACE("(%p/%p)->()\n", This, iface);
365 return IUnknown_Release(This->outer_unk);
368 /*** IFilterGraph methods ***/
369 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface, IBaseFilter *pFilter,
370 LPCWSTR pName)
372 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
373 HRESULT hr;
374 int i,j;
375 WCHAR* wszFilterName = NULL;
376 BOOL duplicate_name = FALSE;
378 TRACE("(%p/%p)->(%p, %s (%p))\n", This, iface, pFilter, debugstr_w(pName), pName);
380 if (!pFilter)
381 return E_POINTER;
383 wszFilterName = CoTaskMemAlloc( (pName ? strlenW(pName) + 6 : 5) * sizeof(WCHAR) );
385 if (pName)
387 /* Check if name already exists */
388 for(i = 0; i < This->nFilters; i++)
389 if (!strcmpW(This->pFilterNames[i], pName))
391 duplicate_name = TRUE;
392 break;
396 /* If no name given or name already existing, generate one */
397 if (!pName || duplicate_name)
399 static const WCHAR wszFmt1[] = {'%','s',' ','%','0','4','d',0};
400 static const WCHAR wszFmt2[] = {'%','0','4','d',0};
402 for (j = 0; j < 10000 ; j++)
404 /* Create name */
405 if (pName)
406 sprintfW(wszFilterName, wszFmt1, pName, This->nameIndex);
407 else
408 sprintfW(wszFilterName, wszFmt2, This->nameIndex);
409 TRACE("Generated name %s\n", debugstr_w(wszFilterName));
411 /* Check if the generated name already exists */
412 for(i = 0; i < This->nFilters; i++)
413 if (!strcmpW(This->pFilterNames[i], wszFilterName))
414 break;
416 /* Compute next index and exit if generated name is suitable */
417 if (This->nameIndex++ == 10000)
418 This->nameIndex = 1;
419 if (i == This->nFilters)
420 break;
422 /* Unable to find a suitable name */
423 if (j == 10000)
425 CoTaskMemFree(wszFilterName);
426 return VFW_E_DUPLICATE_NAME;
429 else
430 memcpy(wszFilterName, pName, (strlenW(pName) + 1) * sizeof(WCHAR));
432 if (This->nFilters + 1 > This->filterCapacity)
434 int newCapacity = This->filterCapacity ? 2 * This->filterCapacity : 1;
435 IBaseFilter ** ppNewFilters = CoTaskMemAlloc(newCapacity * sizeof(IBaseFilter*));
436 LPWSTR * pNewNames = CoTaskMemAlloc(newCapacity * sizeof(LPWSTR));
437 memcpy(ppNewFilters, This->ppFiltersInGraph, This->nFilters * sizeof(IBaseFilter*));
438 memcpy(pNewNames, This->pFilterNames, This->nFilters * sizeof(LPWSTR));
439 if (This->filterCapacity)
441 CoTaskMemFree(This->ppFiltersInGraph);
442 CoTaskMemFree(This->pFilterNames);
444 This->ppFiltersInGraph = ppNewFilters;
445 This->pFilterNames = pNewNames;
446 This->filterCapacity = newCapacity;
449 hr = IBaseFilter_JoinFilterGraph(pFilter, (IFilterGraph *)&This->IFilterGraph2_iface, wszFilterName);
451 if (SUCCEEDED(hr))
453 IBaseFilter_AddRef(pFilter);
454 This->ppFiltersInGraph[This->nFilters] = pFilter;
455 This->pFilterNames[This->nFilters] = wszFilterName;
456 This->nFilters++;
457 This->version++;
458 IBaseFilter_SetSyncSource(pFilter, This->refClock);
460 else
461 CoTaskMemFree(wszFilterName);
463 if (SUCCEEDED(hr) && duplicate_name)
464 return VFW_S_DUPLICATE_NAME;
466 return hr;
469 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
471 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
472 int i;
473 HRESULT hr = E_FAIL;
475 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
477 /* FIXME: check graph is stopped */
479 for (i = 0; i < This->nFilters; i++)
481 if (This->ppFiltersInGraph[i] == pFilter)
483 IEnumPins *penumpins = NULL;
484 FILTER_STATE state;
486 if (This->defaultclock && This->refClockProvider == pFilter)
488 IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, NULL);
489 This->defaultclock = TRUE;
492 TRACE("Removing filter %s\n", debugstr_w(This->pFilterNames[i]));
493 IBaseFilter_GetState(pFilter, 0, &state);
494 if (state == State_Running)
495 IBaseFilter_Pause(pFilter);
496 if (state != State_Stopped)
497 IBaseFilter_Stop(pFilter);
499 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
500 if (SUCCEEDED(hr)) {
501 IPin *ppin;
502 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
504 IPin *victim = NULL;
505 HRESULT h;
506 IPin_ConnectedTo(ppin, &victim);
507 if (victim)
509 h = IPin_Disconnect(victim);
510 TRACE("Disconnect other side: %08x\n", h);
511 if (h == VFW_E_NOT_STOPPED)
513 PIN_INFO pinfo;
514 IPin_QueryPinInfo(victim, &pinfo);
516 IBaseFilter_GetState(pinfo.pFilter, 0, &state);
517 if (state == State_Running)
518 IBaseFilter_Pause(pinfo.pFilter);
519 IBaseFilter_Stop(pinfo.pFilter);
520 IBaseFilter_Release(pinfo.pFilter);
521 h = IPin_Disconnect(victim);
522 TRACE("Disconnect retry: %08x\n", h);
524 IPin_Release(victim);
526 h = IPin_Disconnect(ppin);
527 TRACE("Disconnect 2: %08x\n", h);
529 IPin_Release(ppin);
531 IEnumPins_Release(penumpins);
534 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, This->pFilterNames[i]);
535 if (SUCCEEDED(hr))
537 IBaseFilter_SetSyncSource(pFilter, NULL);
538 IBaseFilter_Release(pFilter);
539 CoTaskMemFree(This->pFilterNames[i]);
540 memmove(This->ppFiltersInGraph+i, This->ppFiltersInGraph+i+1, sizeof(IBaseFilter*)*(This->nFilters - 1 - i));
541 memmove(This->pFilterNames+i, This->pFilterNames+i+1, sizeof(LPWSTR)*(This->nFilters - 1 - i));
542 This->nFilters--;
543 This->version++;
544 /* Invalidate interfaces in the cache */
545 for (i = 0; i < This->nItfCacheEntries; i++)
546 if (pFilter == This->ItfCacheEntries[i].filter)
548 IUnknown_Release(This->ItfCacheEntries[i].iface);
549 This->ItfCacheEntries[i].iface = NULL;
550 This->ItfCacheEntries[i].filter = NULL;
552 return S_OK;
554 break;
558 return hr; /* FIXME: check this error code */
561 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface, IEnumFilters **ppEnum)
563 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
565 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
567 return IEnumFiltersImpl_Construct(&This->IGraphVersion_iface, &This->ppFiltersInGraph, &This->nFilters, ppEnum);
570 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface, LPCWSTR pName,
571 IBaseFilter **ppFilter)
573 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
574 int i;
576 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_w(pName), pName, ppFilter);
578 if (!ppFilter)
579 return E_POINTER;
581 for (i = 0; i < This->nFilters; i++)
583 if (!strcmpW(pName, This->pFilterNames[i]))
585 *ppFilter = This->ppFiltersInGraph[i];
586 IBaseFilter_AddRef(*ppFilter);
587 return S_OK;
591 *ppFilter = NULL;
592 return VFW_E_NOT_FOUND;
595 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
596 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
598 static HRESULT CheckCircularConnection(IFilterGraphImpl *This, IPin *out, IPin *in)
600 #if 1
601 HRESULT hr;
602 PIN_INFO info_out, info_in;
604 hr = IPin_QueryPinInfo(out, &info_out);
605 if (FAILED(hr))
606 return hr;
607 if (info_out.dir != PINDIR_OUTPUT)
609 IBaseFilter_Release(info_out.pFilter);
610 return VFW_E_CANNOT_CONNECT;
613 hr = IPin_QueryPinInfo(in, &info_in);
614 if (SUCCEEDED(hr))
615 IBaseFilter_Release(info_in.pFilter);
616 if (FAILED(hr))
617 goto out;
618 if (info_in.dir != PINDIR_INPUT)
620 hr = VFW_E_CANNOT_CONNECT;
621 goto out;
624 if (info_out.pFilter == info_in.pFilter)
625 hr = VFW_E_CIRCULAR_GRAPH;
626 else
628 IEnumPins *enumpins;
629 IPin *test;
631 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
632 if (FAILED(hr))
633 goto out;
635 IEnumPins_Reset(enumpins);
636 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
638 PIN_DIRECTION dir = PINDIR_OUTPUT;
639 IPin_QueryDirection(test, &dir);
640 if (dir == PINDIR_INPUT)
642 IPin *victim = NULL;
643 IPin_ConnectedTo(test, &victim);
644 if (victim)
646 hr = CheckCircularConnection(This, victim, in);
647 IPin_Release(victim);
648 if (FAILED(hr))
650 IPin_Release(test);
651 break;
655 IPin_Release(test);
657 IEnumPins_Release(enumpins);
660 out:
661 IBaseFilter_Release(info_out.pFilter);
662 if (FAILED(hr))
663 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
664 return hr;
665 #else
666 /* Debugging filtergraphs not enabled */
667 return S_OK;
668 #endif
672 /* NOTE: despite the implication, it doesn't matter which
673 * way round you put in the input and output pins */
674 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppinIn, IPin *ppinOut,
675 const AM_MEDIA_TYPE *pmt)
677 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
678 PIN_DIRECTION dir;
679 HRESULT hr;
681 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
683 /* FIXME: check pins are in graph */
685 if (TRACE_ON(quartz))
687 PIN_INFO PinInfo;
689 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
690 if (FAILED(hr))
691 return hr;
693 TRACE("Filter owning ppinIn(%p) => %p\n", ppinIn, PinInfo.pFilter);
694 IBaseFilter_Release(PinInfo.pFilter);
696 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
697 if (FAILED(hr))
698 return hr;
700 TRACE("Filter owning ppinOut(%p) => %p\n", ppinOut, PinInfo.pFilter);
701 IBaseFilter_Release(PinInfo.pFilter);
704 hr = IPin_QueryDirection(ppinIn, &dir);
705 if (SUCCEEDED(hr))
707 if (dir == PINDIR_INPUT)
709 hr = CheckCircularConnection(This, ppinOut, ppinIn);
710 if (SUCCEEDED(hr))
711 hr = IPin_Connect(ppinOut, ppinIn, pmt);
713 else
715 hr = CheckCircularConnection(This, ppinIn, ppinOut);
716 if (SUCCEEDED(hr))
717 hr = IPin_Connect(ppinIn, ppinOut, pmt);
721 return hr;
724 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface, IPin *ppin)
726 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
727 IPin *pConnectedTo = NULL;
728 HRESULT hr;
729 PIN_DIRECTION pindir;
731 IPin_QueryDirection(ppin, &pindir);
732 hr = IPin_ConnectedTo(ppin, &pConnectedTo);
734 TRACE("(%p/%p)->(%p) -- %p\n", This, iface, ppin, pConnectedTo);
736 if (FAILED(hr)) {
737 TRACE("Querying connected to failed: %x\n", hr);
738 return hr;
740 IPin_Disconnect(ppin);
741 IPin_Disconnect(pConnectedTo);
742 if (pindir == PINDIR_INPUT)
743 hr = IPin_Connect(pConnectedTo, ppin, NULL);
744 else
745 hr = IPin_Connect(ppin, pConnectedTo, NULL);
746 IPin_Release(pConnectedTo);
747 if (FAILED(hr))
748 WARN("Reconnecting pins failed, pins are not connected now..\n");
749 TRACE("-> %08x\n", hr);
750 return hr;
753 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
755 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
757 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
759 if (!ppin)
760 return E_POINTER;
762 return IPin_Disconnect(ppin);
765 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
767 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
768 IReferenceClock *pClock = NULL;
769 HRESULT hr = S_OK;
770 int i;
772 TRACE("(%p/%p)->() live sources not handled properly!\n", This, iface);
774 EnterCriticalSection(&This->cs);
776 for (i = 0; i < This->nFilters; ++i)
778 DWORD miscflags;
779 IAMFilterMiscFlags *flags = NULL;
780 IBaseFilter_QueryInterface(This->ppFiltersInGraph[i], &IID_IAMFilterMiscFlags, (void**)&flags);
781 if (!flags)
782 continue;
783 miscflags = IAMFilterMiscFlags_GetMiscFlags(flags);
784 IAMFilterMiscFlags_Release(flags);
785 if (miscflags == AM_FILTER_MISC_FLAGS_IS_RENDERER)
786 IBaseFilter_QueryInterface(This->ppFiltersInGraph[i], &IID_IReferenceClock, (void**)&pClock);
787 if (pClock)
788 break;
791 if (!pClock)
793 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
794 This->refClockProvider = NULL;
796 else
797 This->refClockProvider = This->ppFiltersInGraph[i];
799 if (SUCCEEDED(hr))
801 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
802 This->defaultclock = TRUE;
803 IReferenceClock_Release(pClock);
805 LeaveCriticalSection(&This->cs);
807 return hr;
810 static HRESULT GetFilterInfo(IMoniker* pMoniker, VARIANT* pvar)
812 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
813 IPropertyBag * pPropBagCat = NULL;
814 HRESULT hr;
816 VariantInit(pvar);
818 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
820 if (SUCCEEDED(hr))
821 hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL);
823 if (SUCCEEDED(hr))
824 TRACE("Moniker = %s\n", debugstr_w(V_BSTR(pvar)));
826 if (pPropBagCat)
827 IPropertyBag_Release(pPropBagCat);
829 return hr;
832 static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPin*** pppins, ULONG* pnb)
834 HRESULT hr;
835 ULONG nb = 0;
837 TRACE("(%p, %p, %p, %p)\n", pfilter, pinputpin, pppins, pnb);
838 hr = IPin_QueryInternalConnections(pinputpin, NULL, &nb);
839 if (hr == S_OK) {
840 /* Rendered input */
841 } else if (hr == S_FALSE) {
842 *pppins = CoTaskMemAlloc(sizeof(IPin*)*nb);
843 hr = IPin_QueryInternalConnections(pinputpin, *pppins, &nb);
844 if (hr != S_OK) {
845 WARN("Error (%x)\n", hr);
847 } else if (hr == E_NOTIMPL) {
848 /* Input connected to all outputs */
849 IEnumPins* penumpins;
850 IPin* ppin;
851 int i = 0;
852 TRACE("E_NOTIMPL\n");
853 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
854 if (FAILED(hr)) {
855 WARN("filter Enumpins failed (%x)\n", hr);
856 return hr;
858 i = 0;
859 /* Count output pins */
860 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
861 PIN_DIRECTION pindir;
862 IPin_QueryDirection(ppin, &pindir);
863 if (pindir == PINDIR_OUTPUT)
864 i++;
865 IPin_Release(ppin);
867 *pppins = CoTaskMemAlloc(sizeof(IPin*)*i);
868 /* Retrieve output pins */
869 IEnumPins_Reset(penumpins);
870 i = 0;
871 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
872 PIN_DIRECTION pindir;
873 IPin_QueryDirection(ppin, &pindir);
874 if (pindir == PINDIR_OUTPUT)
875 (*pppins)[i++] = ppin;
876 else
877 IPin_Release(ppin);
879 IEnumPins_Release(penumpins);
880 nb = i;
881 if (FAILED(hr)) {
882 WARN("Next failed (%x)\n", hr);
883 return hr;
885 } else if (FAILED(hr)) {
886 WARN("Cannot get internal connection (%x)\n", hr);
887 return hr;
890 *pnb = nb;
891 return S_OK;
894 /*** IGraphBuilder methods ***/
895 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IPin *ppinIn)
897 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
898 HRESULT hr;
899 AM_MEDIA_TYPE* mt = NULL;
900 IEnumMediaTypes* penummt = NULL;
901 ULONG nbmt;
902 IEnumPins* penumpins;
903 IEnumMoniker* pEnumMoniker;
904 GUID tab[2];
905 ULONG nb = 0;
906 IMoniker* pMoniker;
907 ULONG pin;
908 PIN_INFO PinInfo;
909 CLSID FilterCLSID;
910 PIN_DIRECTION dir;
911 unsigned int i = 0;
912 IFilterMapper2 *pFilterMapper2 = NULL;
914 TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
916 if(!ppinOut || !ppinIn)
917 return E_POINTER;
919 if (TRACE_ON(quartz))
921 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
922 if (FAILED(hr))
923 return hr;
925 TRACE("Filter owning ppinIn(%p) => %p\n", ppinIn, PinInfo.pFilter);
926 IBaseFilter_Release(PinInfo.pFilter);
928 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
929 if (FAILED(hr))
930 return hr;
932 TRACE("Filter owning ppinOut(%p) => %p\n", ppinOut, PinInfo.pFilter);
933 IBaseFilter_Release(PinInfo.pFilter);
936 EnterCriticalSection(&This->cs);
937 ++This->recursioncount;
938 if (This->recursioncount >= 5)
940 WARN("Recursion count has reached %d\n", This->recursioncount);
941 hr = VFW_E_CANNOT_CONNECT;
942 goto out;
945 hr = IPin_QueryDirection(ppinOut, &dir);
946 if (FAILED(hr))
947 goto out;
949 if (dir == PINDIR_INPUT)
951 IPin *temp;
953 TRACE("Directions seem backwards, swapping pins\n");
955 temp = ppinIn;
956 ppinIn = ppinOut;
957 ppinOut = temp;
960 hr = CheckCircularConnection(This, ppinOut, ppinIn);
961 if (FAILED(hr))
962 goto out;
964 /* Try direct connection first */
965 hr = IPin_Connect(ppinOut, ppinIn, NULL);
966 if (SUCCEEDED(hr))
967 goto out;
969 TRACE("Direct connection failed, trying to render using extra filters\n");
971 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
972 if (FAILED(hr))
973 goto out;
975 hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
976 IBaseFilter_Release(PinInfo.pFilter);
977 if (FAILED(hr))
978 goto out;
980 /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream
981 * filter to the minor mediatype of input pin of the renderer */
982 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
983 if (FAILED(hr))
985 WARN("EnumMediaTypes (%x)\n", hr);
986 goto out;
989 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
990 if (FAILED(hr)) {
991 WARN("IEnumMediaTypes_Next (%x)\n", hr);
992 goto out;
995 if (!nbmt)
997 WARN("No media type found!\n");
998 hr = VFW_E_INVALIDMEDIATYPE;
999 goto out;
1001 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1002 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1004 hr = IUnknown_QueryInterface(This->punkFilterMapper2, &IID_IFilterMapper2, (void**)&pFilterMapper2);
1005 if (FAILED(hr)) {
1006 WARN("Unable to get IFilterMapper2 (%x)\n", hr);
1007 goto out;
1010 /* Try to find a suitable filter that can connect to the pin to render */
1011 tab[0] = mt->majortype;
1012 tab[1] = mt->subtype;
1013 hr = IFilterMapper2_EnumMatchingFilters(pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1014 if (FAILED(hr)) {
1015 WARN("Unable to enum filters (%x)\n", hr);
1016 goto out;
1019 hr = VFW_E_CANNOT_RENDER;
1020 while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1022 VARIANT var;
1023 GUID clsid;
1024 IPin** ppins = NULL;
1025 IPin* ppinfilter = NULL;
1026 IBaseFilter* pfilter = NULL;
1027 IAMGraphBuilderCallback *callback = NULL;
1029 hr = GetFilterInfo(pMoniker, &var);
1030 if (FAILED(hr)) {
1031 WARN("Unable to retrieve filter info (%x)\n", hr);
1032 goto error;
1035 hr = IMoniker_BindToObject(pMoniker, NULL, NULL, &IID_IBaseFilter, (LPVOID*)&pfilter);
1036 IMoniker_Release(pMoniker);
1037 if (FAILED(hr)) {
1038 WARN("Unable to create filter (%x), trying next one\n", hr);
1039 goto error;
1042 hr = IBaseFilter_GetClassID(pfilter, &clsid);
1043 if (FAILED(hr))
1045 IBaseFilter_Release(pfilter);
1046 goto error;
1049 if (IsEqualGUID(&clsid, &FilterCLSID)) {
1050 /* Skip filter (same as the one the output pin belongs to) */
1051 IBaseFilter_Release(pfilter);
1052 pfilter = NULL;
1053 goto error;
1056 if (This->pSite)
1058 IUnknown_QueryInterface(This->pSite, &IID_IAMGraphBuilderCallback, (LPVOID*)&callback);
1059 if (callback)
1061 HRESULT rc;
1062 rc = IAMGraphBuilderCallback_SelectedFilter(callback, pMoniker);
1063 if (FAILED(rc))
1065 TRACE("Filter rejected by IAMGraphBuilderCallback_SelectedFilter\n");
1066 IAMGraphBuilderCallback_Release(callback);
1067 goto error;
1072 if (callback)
1074 HRESULT rc;
1075 rc = IAMGraphBuilderCallback_CreatedFilter(callback, pfilter);
1076 IAMGraphBuilderCallback_Release(callback);
1077 if (FAILED(rc))
1079 IBaseFilter_Release(pfilter);
1080 pfilter = NULL;
1081 TRACE("Filter rejected by IAMGraphBuilderCallback_CreatedFilter\n");
1082 goto error;
1086 hr = IFilterGraph2_AddFilter(iface, pfilter, V_BSTR(&var));
1087 if (FAILED(hr)) {
1088 WARN("Unable to add filter (%x)\n", hr);
1089 IBaseFilter_Release(pfilter);
1090 pfilter = NULL;
1091 goto error;
1094 VariantClear(&var);
1096 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1097 if (FAILED(hr)) {
1098 WARN("Enumpins (%x)\n", hr);
1099 goto error;
1102 hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin);
1103 IEnumPins_Release(penumpins);
1105 if (FAILED(hr)) {
1106 WARN("Obtaining next pin: (%x)\n", hr);
1107 goto error;
1109 if (pin == 0) {
1110 WARN("Cannot use this filter: no pins\n");
1111 goto error;
1114 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1115 if (FAILED(hr)) {
1116 TRACE("Cannot connect to filter (%x), trying next one\n", hr);
1117 goto error;
1119 TRACE("Successfully connected to filter, follow chain...\n");
1121 /* Render all output pins of the filter by calling IFilterGraph2_Connect on each of them */
1122 hr = GetInternalConnections(pfilter, ppinfilter, &ppins, &nb);
1124 if (SUCCEEDED(hr)) {
1125 if (nb == 0) {
1126 IPin_Disconnect(ppinfilter);
1127 IPin_Disconnect(ppinOut);
1128 goto error;
1130 TRACE("pins to consider: %d\n", nb);
1131 for(i = 0; i < nb; i++)
1133 LPWSTR pinname = NULL;
1135 TRACE("Processing pin %u\n", i);
1137 hr = IPin_QueryId(ppins[i], &pinname);
1138 if (SUCCEEDED(hr))
1140 if (pinname[0] == '~')
1142 TRACE("Pinname=%s, skipping\n", debugstr_w(pinname));
1143 hr = E_FAIL;
1145 else
1146 hr = IFilterGraph2_Connect(iface, ppins[i], ppinIn);
1147 CoTaskMemFree(pinname);
1150 if (FAILED(hr)) {
1151 TRACE("Cannot connect pin %p (%x)\n", ppinfilter, hr);
1153 IPin_Release(ppins[i]);
1154 if (SUCCEEDED(hr)) break;
1156 while (++i < nb) IPin_Release(ppins[i]);
1157 CoTaskMemFree(ppins);
1158 IPin_Release(ppinfilter);
1159 IBaseFilter_Release(pfilter);
1160 if (FAILED(hr))
1162 IPin_Disconnect(ppinfilter);
1163 IPin_Disconnect(ppinOut);
1164 IFilterGraph2_RemoveFilter(iface, pfilter);
1165 continue;
1167 break;
1170 error:
1171 VariantClear(&var);
1172 if (ppinfilter) IPin_Release(ppinfilter);
1173 if (pfilter) {
1174 IFilterGraph2_RemoveFilter(iface, pfilter);
1175 IBaseFilter_Release(pfilter);
1177 while (++i < nb) IPin_Release(ppins[i]);
1178 CoTaskMemFree(ppins);
1181 IEnumMoniker_Release(pEnumMoniker);
1183 out:
1184 if (pFilterMapper2)
1185 IFilterMapper2_Release(pFilterMapper2);
1186 if (penummt)
1187 IEnumMediaTypes_Release(penummt);
1188 if (mt)
1189 DeleteMediaType(mt);
1190 --This->recursioncount;
1191 LeaveCriticalSection(&This->cs);
1192 TRACE("--> %08x\n", hr);
1193 return SUCCEEDED(hr) ? S_OK : hr;
1196 static HRESULT FilterGraph2_RenderRecurse(IFilterGraphImpl *This, IPin *ppinOut)
1198 /* This pin has been connected now, try to call render on all pins that aren't connected */
1199 IPin *to = NULL;
1200 PIN_INFO info;
1201 IEnumPins *enumpins = NULL;
1202 BOOL renderany = FALSE;
1203 BOOL renderall = TRUE;
1205 IPin_QueryPinInfo(ppinOut, &info);
1207 IBaseFilter_EnumPins(info.pFilter, &enumpins);
1208 /* Don't need to hold a reference, IEnumPins does */
1209 IBaseFilter_Release(info.pFilter);
1211 IEnumPins_Reset(enumpins);
1212 while (IEnumPins_Next(enumpins, 1, &to, NULL) == S_OK)
1214 PIN_DIRECTION dir = PINDIR_INPUT;
1216 IPin_QueryDirection(to, &dir);
1218 if (dir == PINDIR_OUTPUT)
1220 IPin *out = NULL;
1222 IPin_ConnectedTo(to, &out);
1223 if (!out)
1225 HRESULT hr;
1226 hr = IFilterGraph2_Render(&This->IFilterGraph2_iface, to);
1227 if (SUCCEEDED(hr))
1228 renderany = TRUE;
1229 else
1230 renderall = FALSE;
1232 else
1233 IPin_Release(out);
1236 IPin_Release(to);
1239 IEnumPins_Release(enumpins);
1241 if (renderall)
1242 return S_OK;
1244 if (renderany)
1245 return VFW_S_PARTIAL_RENDER;
1247 return VFW_E_CANNOT_RENDER;
1250 /* Ogg hates me if I create a direct rendering method
1252 * It can only connect to a pin properly once, so use a recursive method that does
1254 * +----+ --- (PIN 1) (Render is called on this pin)
1255 * | |
1256 * +----+ --- (PIN 2)
1258 * Enumerate possible renderers that EXACTLY match the requested type
1260 * If none is available, try to add intermediate filters that can connect to the input pin
1261 * then call Render on that intermediate pin's output pins
1262 * if it succeeds: Render returns success, if it doesn't, the intermediate filter is removed,
1263 * and another filter that can connect to the input pin is tried
1264 * if we run out of filters that can, give up and return VFW_E_CANNOT_RENDER
1265 * It's recursive, but fun!
1268 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *ppinOut)
1270 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1271 IEnumMediaTypes* penummt;
1272 AM_MEDIA_TYPE* mt;
1273 ULONG nbmt;
1274 HRESULT hr;
1276 IEnumMoniker* pEnumMoniker;
1277 GUID tab[4];
1278 ULONG nb;
1279 IMoniker* pMoniker;
1280 INT x;
1281 IFilterMapper2 *pFilterMapper2 = NULL;
1283 TRACE("(%p/%p)->(%p)\n", This, iface, ppinOut);
1285 if (TRACE_ON(quartz))
1287 PIN_INFO PinInfo;
1289 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
1290 if (FAILED(hr))
1291 return hr;
1293 TRACE("Filter owning pin => %p\n", PinInfo.pFilter);
1294 IBaseFilter_Release(PinInfo.pFilter);
1297 /* Try to find out if there is a renderer for the specified subtype already, and use that
1299 EnterCriticalSection(&This->cs);
1300 for (x = 0; x < This->nFilters; ++x)
1302 IEnumPins *enumpins = NULL;
1303 IPin *pin = NULL;
1305 hr = IBaseFilter_EnumPins(This->ppFiltersInGraph[x], &enumpins);
1307 if (FAILED(hr) || !enumpins)
1308 continue;
1310 IEnumPins_Reset(enumpins);
1311 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
1313 IPin *to = NULL;
1314 PIN_DIRECTION dir = PINDIR_OUTPUT;
1316 IPin_QueryDirection(pin, &dir);
1317 if (dir != PINDIR_INPUT)
1319 IPin_Release(pin);
1320 continue;
1322 IPin_ConnectedTo(pin, &to);
1324 if (to == NULL)
1326 hr = FilterGraph2_ConnectDirect(iface, ppinOut, pin, NULL);
1327 if (SUCCEEDED(hr))
1329 TRACE("Connected successfully %p/%p, %08x look if we should render more!\n", ppinOut, pin, hr);
1330 IPin_Release(pin);
1332 hr = FilterGraph2_RenderRecurse(This, pin);
1333 if (FAILED(hr))
1335 IPin_Disconnect(ppinOut);
1336 IPin_Disconnect(pin);
1337 continue;
1339 IEnumPins_Release(enumpins);
1340 LeaveCriticalSection(&This->cs);
1341 return hr;
1343 WARN("Could not connect!\n");
1345 else
1346 IPin_Release(to);
1348 IPin_Release(pin);
1350 IEnumPins_Release(enumpins);
1353 LeaveCriticalSection(&This->cs);
1355 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
1356 if (FAILED(hr)) {
1357 WARN("EnumMediaTypes (%x)\n", hr);
1358 return hr;
1361 IEnumMediaTypes_Reset(penummt);
1363 /* Looks like no existing renderer of the kind exists
1364 * Try adding new ones
1366 tab[0] = tab[1] = GUID_NULL;
1367 while (SUCCEEDED(hr))
1369 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
1370 if (FAILED(hr)) {
1371 WARN("IEnumMediaTypes_Next (%x)\n", hr);
1372 break;
1374 if (!nbmt)
1376 hr = VFW_E_CANNOT_RENDER;
1377 break;
1379 else
1381 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1382 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1384 /* Only enumerate once, this doesn't account for all previous ones, but this should be enough nonetheless */
1385 if (IsEqualIID(&tab[0], &mt->majortype) && IsEqualIID(&tab[1], &mt->subtype))
1387 DeleteMediaType(mt);
1388 continue;
1391 if (pFilterMapper2 == NULL)
1393 hr = IUnknown_QueryInterface(This->punkFilterMapper2, &IID_IFilterMapper2, (void**)&pFilterMapper2);
1394 if (FAILED(hr))
1396 WARN("Unable to query IFilterMapper2 (%x)\n", hr);
1397 break;
1401 /* Try to find a suitable renderer with the same media type */
1402 tab[0] = mt->majortype;
1403 tab[1] = mt->subtype;
1404 hr = IFilterMapper2_EnumMatchingFilters(pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1405 if (FAILED(hr))
1407 WARN("Unable to enum filters (%x)\n", hr);
1408 break;
1411 hr = E_FAIL;
1413 while (IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1415 VARIANT var;
1416 IPin* ppinfilter;
1417 IBaseFilter* pfilter = NULL;
1418 IEnumPins* penumpins = NULL;
1419 ULONG pin;
1421 hr = GetFilterInfo(pMoniker, &var);
1422 if (FAILED(hr)) {
1423 WARN("Unable to retrieve filter info (%x)\n", hr);
1424 goto error;
1427 hr = IMoniker_BindToObject(pMoniker, NULL, NULL, &IID_IBaseFilter, (LPVOID*)&pfilter);
1428 IMoniker_Release(pMoniker);
1429 if (FAILED(hr))
1431 WARN("Unable to create filter (%x), trying next one\n", hr);
1432 goto error;
1435 hr = IFilterGraph2_AddFilter(iface, pfilter, V_BSTR(&var));
1436 if (FAILED(hr)) {
1437 WARN("Unable to add filter (%x)\n", hr);
1438 IBaseFilter_Release(pfilter);
1439 pfilter = NULL;
1440 goto error;
1443 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1444 if (FAILED(hr)) {
1445 WARN("Splitter Enumpins (%x)\n", hr);
1446 goto error;
1449 while ((hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin)) == S_OK)
1451 PIN_DIRECTION dir;
1453 if (pin == 0) {
1454 WARN("No Pin\n");
1455 hr = E_FAIL;
1456 goto error;
1459 hr = IPin_QueryDirection(ppinfilter, &dir);
1460 if (FAILED(hr)) {
1461 IPin_Release(ppinfilter);
1462 WARN("QueryDirection failed (%x)\n", hr);
1463 goto error;
1465 if (dir != PINDIR_INPUT) {
1466 IPin_Release(ppinfilter);
1467 continue; /* Wrong direction */
1470 /* Connect the pin to the "Renderer" */
1471 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1472 IPin_Release(ppinfilter);
1474 if (FAILED(hr)) {
1475 WARN("Unable to connect %s to renderer (%x)\n", debugstr_w(V_BSTR(&var)), hr);
1476 goto error;
1478 TRACE("Connected, recursing %s\n", debugstr_w(V_BSTR(&var)));
1480 VariantClear(&var);
1482 hr = FilterGraph2_RenderRecurse(This, ppinfilter);
1483 if (FAILED(hr)) {
1484 WARN("Unable to connect recursively (%x)\n", hr);
1485 goto error;
1487 IBaseFilter_Release(pfilter);
1488 break;
1490 if (SUCCEEDED(hr)) {
1491 IEnumPins_Release(penumpins);
1492 break; /* out of IEnumMoniker_Next loop */
1495 /* IEnumPins_Next failed, all other failure case caught by goto error */
1496 WARN("IEnumPins_Next (%x)\n", hr);
1497 /* goto error */
1499 error:
1500 VariantClear(&var);
1501 if (penumpins)
1502 IEnumPins_Release(penumpins);
1503 if (pfilter) {
1504 IFilterGraph2_RemoveFilter(iface, pfilter);
1505 IBaseFilter_Release(pfilter);
1507 if (SUCCEEDED(hr)) DebugBreak();
1510 IEnumMoniker_Release(pEnumMoniker);
1511 if (nbmt)
1512 DeleteMediaType(mt);
1513 if (SUCCEEDED(hr))
1514 break;
1515 hr = S_OK;
1518 if (pFilterMapper2)
1519 IFilterMapper2_Release(pFilterMapper2);
1521 IEnumMediaTypes_Release(penummt);
1522 return hr;
1525 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface, LPCWSTR lpcwstrFile,
1526 LPCWSTR lpcwstrPlayList)
1528 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1529 static const WCHAR string[] = {'R','e','a','d','e','r',0};
1530 IBaseFilter* preader = NULL;
1531 IPin* ppinreader = NULL;
1532 IEnumPins* penumpins = NULL;
1533 HRESULT hr;
1534 BOOL partial = FALSE;
1535 BOOL any = FALSE;
1537 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1539 if (lpcwstrPlayList != NULL)
1540 return E_INVALIDARG;
1542 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, string, &preader);
1543 if (FAILED(hr))
1544 return hr;
1546 hr = IBaseFilter_EnumPins(preader, &penumpins);
1547 if (SUCCEEDED(hr))
1549 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1551 PIN_DIRECTION dir;
1553 IPin_QueryDirection(ppinreader, &dir);
1554 if (dir == PINDIR_OUTPUT)
1556 INT i;
1558 hr = IFilterGraph2_Render(iface, ppinreader);
1559 TRACE("Render %08x\n", hr);
1561 for (i = 0; i < This->nFilters; ++i)
1562 TRACE("Filters in chain: %s\n", debugstr_w(This->pFilterNames[i]));
1564 if (SUCCEEDED(hr))
1565 any = TRUE;
1566 if (hr != S_OK)
1567 partial = TRUE;
1569 IPin_Release(ppinreader);
1571 IEnumPins_Release(penumpins);
1573 if (!any)
1574 hr = VFW_E_CANNOT_RENDER;
1575 else if (partial)
1576 hr = VFW_S_PARTIAL_RENDER;
1577 else
1578 hr = S_OK;
1580 IBaseFilter_Release(preader);
1582 TRACE("--> %08x\n", hr);
1583 return hr;
1586 static HRESULT CreateFilterInstanceAndLoadFile(GUID* clsid, LPCOLESTR pszFileName, IBaseFilter **filter)
1588 IFileSourceFilter *source = NULL;
1589 HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1590 TRACE("CLSID: %s\n", debugstr_guid(clsid));
1591 if (FAILED(hr))
1592 return hr;
1594 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID*)&source);
1595 if (FAILED(hr))
1597 IBaseFilter_Release(*filter);
1598 return hr;
1601 /* Load the file in the file source filter */
1602 hr = IFileSourceFilter_Load(source, pszFileName, NULL);
1603 IFileSourceFilter_Release(source);
1604 if (FAILED(hr)) {
1605 WARN("Load (%x)\n", hr);
1606 IBaseFilter_Release(*filter);
1607 return hr;
1610 return hr;
1613 /* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
1614 static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
1616 HRESULT hr;
1617 GUID clsid;
1618 IAsyncReader * pReader = NULL;
1619 IFileSourceFilter* pSource = NULL;
1620 IPin * pOutputPin = NULL;
1621 static const WCHAR wszOutputPinName[] = { 'O','u','t','p','u','t',0 };
1623 /* Try to find a match without reading the file first */
1624 hr = GetClassMediaFile(NULL, pszFileName, NULL, NULL, &clsid);
1626 if (hr == S_OK)
1627 return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
1629 /* Now create a AyncReader instance, to check for signature bytes in the file */
1630 hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1631 if (FAILED(hr))
1632 return hr;
1634 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID *)&pSource);
1635 if (FAILED(hr))
1637 IBaseFilter_Release(*filter);
1638 return hr;
1641 hr = IFileSourceFilter_Load(pSource, pszFileName, NULL);
1642 IFileSourceFilter_Release(pSource);
1643 if (FAILED(hr))
1645 IBaseFilter_Release(*filter);
1646 return hr;
1649 hr = IBaseFilter_FindPin(*filter, wszOutputPinName, &pOutputPin);
1650 if (FAILED(hr))
1652 IBaseFilter_Release(*filter);
1653 return hr;
1656 hr = IPin_QueryInterface(pOutputPin, &IID_IAsyncReader, (LPVOID *)&pReader);
1657 IPin_Release(pOutputPin);
1658 if (FAILED(hr))
1660 IBaseFilter_Release(*filter);
1661 return hr;
1664 /* Try again find a match */
1665 hr = GetClassMediaFile(pReader, pszFileName, NULL, NULL, &clsid);
1666 IAsyncReader_Release(pReader);
1668 if (hr == S_OK)
1670 /* Release the AsyncReader filter and create the matching one */
1671 IBaseFilter_Release(*filter);
1672 return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
1675 /* Return the AsyncReader filter */
1676 return S_OK;
1679 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface, LPCWSTR lpcwstrFileName,
1680 LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1682 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1683 HRESULT hr;
1684 IBaseFilter* preader;
1685 IFileSourceFilter* pfile = NULL;
1686 AM_MEDIA_TYPE mt;
1687 WCHAR* filename;
1689 TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1691 /* Try from file name first, then fall back to default asynchronous reader */
1692 hr = GetFileSourceFilter(lpcwstrFileName, &preader);
1693 if (FAILED(hr)) {
1694 WARN("Unable to create file source filter (%x)\n", hr);
1695 return hr;
1698 hr = IFilterGraph2_AddFilter(iface, preader, lpcwstrFilterName);
1699 if (FAILED(hr)) {
1700 WARN("Unable add filter (%x)\n", hr);
1701 IBaseFilter_Release(preader);
1702 return hr;
1705 hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1706 if (FAILED(hr)) {
1707 WARN("Unable to get IFileSourceInterface (%x)\n", hr);
1708 goto error;
1711 /* The file has been already loaded */
1712 hr = IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1713 if (FAILED(hr)) {
1714 WARN("GetCurFile (%x)\n", hr);
1715 goto error;
1718 TRACE("File %s\n", debugstr_w(filename));
1719 TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
1720 TRACE("SubType %s\n", debugstr_guid(&mt.subtype));
1722 if (ppFilter)
1723 *ppFilter = preader;
1724 IFileSourceFilter_Release(pfile);
1726 return S_OK;
1728 error:
1729 if (pfile)
1730 IFileSourceFilter_Release(pfile);
1731 IFilterGraph2_RemoveFilter(iface, preader);
1732 IBaseFilter_Release(preader);
1734 return hr;
1737 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR hFile)
1739 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1741 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1743 return S_OK;
1746 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1748 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1750 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1752 return S_OK;
1755 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1757 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1759 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1761 return S_OK;
1764 /*** IFilterGraph2 methods ***/
1765 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1766 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1768 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1769 HRESULT hr;
1770 IBaseFilter* pfilter;
1772 TRACE("(%p/%p)->(%p %p %s %p)\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1774 hr = IMoniker_BindToObject(pMoniker, pCtx, NULL, &IID_IBaseFilter, (void**)&pfilter);
1775 if(FAILED(hr)) {
1776 WARN("Unable to bind moniker to filter object (%x)\n", hr);
1777 return hr;
1780 hr = IFilterGraph2_AddFilter(iface, pfilter, lpcwstrFilterName);
1781 if (FAILED(hr)) {
1782 WARN("Unable to add filter (%x)\n", hr);
1783 IBaseFilter_Release(pfilter);
1784 return hr;
1787 if(ppFilter)
1788 *ppFilter = pfilter;
1789 else IBaseFilter_Release(pfilter);
1791 return S_OK;
1794 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *ppin,
1795 const AM_MEDIA_TYPE *pmt)
1797 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1799 TRACE("(%p/%p)->(%p %p): stub !!!\n", This, iface, ppin, pmt);
1801 return S_OK;
1804 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *pPinOut, DWORD dwFlags,
1805 DWORD *pvContext)
1807 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1809 TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This, iface, pPinOut, dwFlags, pvContext);
1811 return S_OK;
1815 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1817 FilterGraph2_QueryInterface,
1818 FilterGraph2_AddRef,
1819 FilterGraph2_Release,
1820 FilterGraph2_AddFilter,
1821 FilterGraph2_RemoveFilter,
1822 FilterGraph2_EnumFilters,
1823 FilterGraph2_FindFilterByName,
1824 FilterGraph2_ConnectDirect,
1825 FilterGraph2_Reconnect,
1826 FilterGraph2_Disconnect,
1827 FilterGraph2_SetDefaultSyncSource,
1828 FilterGraph2_Connect,
1829 FilterGraph2_Render,
1830 FilterGraph2_RenderFile,
1831 FilterGraph2_AddSourceFilter,
1832 FilterGraph2_SetLogFile,
1833 FilterGraph2_Abort,
1834 FilterGraph2_ShouldOperationContinue,
1835 FilterGraph2_AddSourceFilterForMoniker,
1836 FilterGraph2_ReconnectEx,
1837 FilterGraph2_RenderEx
1840 static inline IFilterGraphImpl *impl_from_IMediaControl(IMediaControl *iface)
1842 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaControl_iface);
1845 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID riid, void **ppvObj)
1847 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1849 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
1851 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
1854 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1856 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1858 TRACE("(%p/%p)->()\n", This, iface);
1860 return IUnknown_AddRef(This->outer_unk);
1863 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1865 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1867 TRACE("(%p/%p)->()\n", This, iface);
1869 return IUnknown_Release(This->outer_unk);
1873 /*** IDispatch methods ***/
1874 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *pctinfo)
1876 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1878 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1880 return S_OK;
1883 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT iTInfo, LCID lcid,
1884 ITypeInfo **ppTInfo)
1886 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1888 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1890 return S_OK;
1893 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID riid,
1894 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1896 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1898 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
1899 cNames, lcid, rgDispId);
1901 return S_OK;
1904 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID dispIdMember, REFIID riid,
1905 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
1906 UINT *puArgErr)
1908 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1910 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
1911 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
1913 return S_OK;
1916 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *, DWORD_PTR data);
1918 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter, DWORD_PTR data)
1920 HRESULT hr;
1921 IPin* pInputPin;
1922 IPin** ppPins;
1923 ULONG nb;
1924 ULONG i;
1925 PIN_INFO PinInfo;
1927 TRACE("%p %p\n", pGraph, pOutputPin);
1928 PinInfo.pFilter = NULL;
1930 hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1932 if (SUCCEEDED(hr))
1934 hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1935 if (SUCCEEDED(hr))
1936 hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1937 IPin_Release(pInputPin);
1940 if (SUCCEEDED(hr))
1942 if (nb == 0)
1944 TRACE("Reached a renderer\n");
1945 /* Count renderers for end of stream notification */
1946 pGraph->nRenderers++;
1948 else
1950 for(i = 0; i < nb; i++)
1952 /* Explore the graph downstream from this pin
1953 * FIXME: We should prevent exploring from a pin more than once. This can happens when
1954 * several input pins are connected to the same output (a MUX for instance). */
1955 ExploreGraph(pGraph, ppPins[i], FoundFilter, data);
1956 IPin_Release(ppPins[i]);
1959 CoTaskMemFree(ppPins);
1961 TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1963 FoundFilter(PinInfo.pFilter, data);
1966 if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1967 return hr;
1970 static HRESULT WINAPI SendRun(IBaseFilter *pFilter, DWORD_PTR data)
1972 REFERENCE_TIME time = *(REFERENCE_TIME*)data;
1973 return IBaseFilter_Run(pFilter, time);
1976 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1978 return IBaseFilter_Pause(pFilter);
1981 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1983 return IBaseFilter_Stop(pFilter);
1986 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1988 FILTER_STATE state;
1989 DWORD time_end = data;
1990 DWORD time_now = GetTickCount();
1991 LONG wait;
1993 if (time_end == INFINITE)
1995 wait = INFINITE;
1997 else if (time_end > time_now)
1999 wait = time_end - time_now;
2001 else
2002 wait = 0;
2004 return IBaseFilter_GetState(pFilter, wait, &state);
2008 static HRESULT SendFilterMessage(IFilterGraphImpl *This, fnFoundFilter FoundFilter, DWORD_PTR data)
2010 int i;
2011 IBaseFilter* pfilter;
2012 IEnumPins* pEnum;
2013 HRESULT hr;
2014 IPin* pPin;
2015 DWORD dummy;
2016 PIN_DIRECTION dir;
2018 TRACE("(%p)->()\n", This);
2020 /* Explorer the graph from source filters to renderers, determine renderers
2021 * number and run filters from renderers to source filters */
2022 This->nRenderers = 0;
2023 ResetEvent(This->hEventCompletion);
2025 for(i = 0; i < This->nFilters; i++)
2027 BOOL source = TRUE;
2028 pfilter = This->ppFiltersInGraph[i];
2029 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
2030 if (hr != S_OK)
2032 WARN("Enum pins failed %x\n", hr);
2033 continue;
2035 /* Check if it is a source filter */
2036 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2038 IPin_QueryDirection(pPin, &dir);
2039 IPin_Release(pPin);
2040 if (dir == PINDIR_INPUT)
2042 source = FALSE;
2043 break;
2046 if (source)
2048 TRACE("Found a source filter %p\n", pfilter);
2049 IEnumPins_Reset(pEnum);
2050 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2052 /* Explore the graph downstream from this pin */
2053 ExploreGraph(This, pPin, FoundFilter, data);
2054 IPin_Release(pPin);
2056 FoundFilter(pfilter, data);
2058 IEnumPins_Release(pEnum);
2061 return S_FALSE;
2064 /*** IMediaControl methods ***/
2065 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
2067 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2069 TRACE("(%p/%p)->()\n", This, iface);
2071 EnterCriticalSection(&This->cs);
2072 if (This->state == State_Running)
2073 goto out;
2074 This->EcCompleteCount = 0;
2076 if (This->defaultclock && !This->refClock)
2077 IFilterGraph2_SetDefaultSyncSource(&This->IFilterGraph2_iface);
2079 if (This->refClock)
2081 REFERENCE_TIME now;
2082 IReferenceClock_GetTime(This->refClock, &now);
2083 if (This->state == State_Stopped)
2084 This->start_time = now + 500000;
2085 else if (This->pause_time >= 0)
2086 This->start_time += now - This->pause_time;
2087 else
2088 This->start_time = now;
2090 else This->start_time = 0;
2092 SendFilterMessage(This, SendRun, (DWORD_PTR)&This->start_time);
2093 This->state = State_Running;
2094 out:
2095 LeaveCriticalSection(&This->cs);
2096 return S_FALSE;
2099 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
2101 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2103 TRACE("(%p/%p)->()\n", This, iface);
2105 EnterCriticalSection(&This->cs);
2106 if (This->state == State_Paused)
2107 goto out;
2109 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2110 IReferenceClock_GetTime(This->refClock, &This->pause_time);
2111 else
2112 This->pause_time = -1;
2114 SendFilterMessage(This, SendPause, 0);
2115 This->state = State_Paused;
2116 out:
2117 LeaveCriticalSection(&This->cs);
2118 return S_FALSE;
2121 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
2123 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2125 TRACE("(%p/%p)->()\n", This, iface);
2127 if (This->state == State_Stopped) return S_OK;
2129 EnterCriticalSection(&This->cs);
2130 if (This->state == State_Running) SendFilterMessage(This, SendPause, 0);
2131 SendFilterMessage(This, SendStop, 0);
2132 This->state = State_Stopped;
2133 LeaveCriticalSection(&This->cs);
2134 return S_OK;
2137 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG msTimeout,
2138 OAFilterState *pfs)
2140 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2141 DWORD end;
2143 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
2145 if (!pfs)
2146 return E_POINTER;
2148 EnterCriticalSection(&This->cs);
2150 *pfs = This->state;
2151 if (msTimeout > 0)
2153 end = GetTickCount() + msTimeout;
2155 else if (msTimeout < 0)
2157 end = INFINITE;
2159 else
2161 end = 0;
2163 if (end)
2164 SendFilterMessage(This, SendGetState, end);
2166 LeaveCriticalSection(&This->cs);
2168 return S_OK;
2171 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
2173 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2175 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strFilename), strFilename);
2177 return IFilterGraph2_RenderFile(&This->IFilterGraph2_iface, strFilename, NULL);
2180 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
2181 IDispatch **ppUnk)
2183 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2185 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2187 return S_OK;
2190 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2192 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2194 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2196 return S_OK;
2199 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2201 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2203 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2205 return S_OK;
2208 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
2210 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2212 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2214 return S_OK;
2218 static const IMediaControlVtbl IMediaControl_VTable =
2220 MediaControl_QueryInterface,
2221 MediaControl_AddRef,
2222 MediaControl_Release,
2223 MediaControl_GetTypeInfoCount,
2224 MediaControl_GetTypeInfo,
2225 MediaControl_GetIDsOfNames,
2226 MediaControl_Invoke,
2227 MediaControl_Run,
2228 MediaControl_Pause,
2229 MediaControl_Stop,
2230 MediaControl_GetState,
2231 MediaControl_RenderFile,
2232 MediaControl_AddSourceFilter,
2233 MediaControl_get_FilterCollection,
2234 MediaControl_get_RegFilterCollection,
2235 MediaControl_StopWhenReady
2238 static inline IFilterGraphImpl *impl_from_IMediaSeeking(IMediaSeeking *iface)
2240 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaSeeking_iface);
2243 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID riid, void **ppvObj)
2245 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2247 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
2249 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2252 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2254 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2256 TRACE("(%p/%p)->()\n", This, iface);
2258 return IUnknown_AddRef(This->outer_unk);
2261 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2263 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2265 TRACE("(%p/%p)->()\n", This, iface);
2267 return IUnknown_Release(This->outer_unk);
2270 typedef HRESULT (WINAPI *fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
2272 static HRESULT all_renderers_seek(IFilterGraphImpl *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2273 BOOL allnotimpl = TRUE;
2274 int i;
2275 HRESULT hr, hr_return = S_OK;
2277 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2278 /* Send a message to all renderers, they are responsible for broadcasting it further */
2280 for(i = 0; i < This->nFilters; i++)
2282 IMediaSeeking *seek = NULL;
2283 IBaseFilter* pfilter = This->ppFiltersInGraph[i];
2284 IAMFilterMiscFlags *flags = NULL;
2285 ULONG filterflags;
2286 IBaseFilter_QueryInterface(pfilter, &IID_IAMFilterMiscFlags, (void**)&flags);
2287 if (!flags)
2288 continue;
2289 filterflags = IAMFilterMiscFlags_GetMiscFlags(flags);
2290 IAMFilterMiscFlags_Release(flags);
2291 if (filterflags != AM_FILTER_MISC_FLAGS_IS_RENDERER)
2292 continue;
2294 IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2295 if (!seek)
2296 continue;
2297 hr = FoundSeek(This, seek, arg);
2298 IMediaSeeking_Release(seek);
2299 if (hr_return != E_NOTIMPL)
2300 allnotimpl = FALSE;
2301 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2302 hr_return = hr;
2305 if (allnotimpl)
2306 return E_NOTIMPL;
2307 return hr_return;
2310 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2312 HRESULT hr;
2313 DWORD caps = 0;
2315 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2316 if (FAILED(hr))
2317 return hr;
2319 /* Only add common capabilities everything supports */
2320 *(DWORD*)pcaps &= caps;
2322 return hr;
2325 /*** IMediaSeeking methods ***/
2326 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2328 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2329 HRESULT hr;
2331 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2333 if (!pCapabilities)
2334 return E_POINTER;
2336 EnterCriticalSection(&This->cs);
2337 *pCapabilities = 0xffffffff;
2339 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2340 LeaveCriticalSection(&This->cs);
2342 return hr;
2345 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2347 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2348 DWORD originalcaps;
2349 HRESULT hr;
2351 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2353 if (!pCapabilities)
2354 return E_POINTER;
2356 EnterCriticalSection(&This->cs);
2357 originalcaps = *pCapabilities;
2358 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2359 LeaveCriticalSection(&This->cs);
2361 if (FAILED(hr))
2362 return hr;
2364 if (!*pCapabilities)
2365 return E_FAIL;
2366 if (*pCapabilities != originalcaps)
2367 return S_FALSE;
2368 return S_OK;
2371 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2373 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2375 if (!pFormat)
2376 return E_POINTER;
2378 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2380 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2382 WARN("Unhandled time format %s\n", debugstr_guid(pFormat));
2383 return S_FALSE;
2386 return S_OK;
2389 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2391 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2393 if (!pFormat)
2394 return E_POINTER;
2396 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2397 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2399 return S_OK;
2402 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2404 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2406 if (!pFormat)
2407 return E_POINTER;
2409 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2410 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2412 return S_OK;
2415 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2417 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2419 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2420 if (!pFormat)
2421 return E_POINTER;
2423 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2424 return S_FALSE;
2426 return S_OK;
2429 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2431 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2433 if (!pFormat)
2434 return E_POINTER;
2436 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2438 if (This->state != State_Stopped)
2439 return VFW_E_WRONG_STATE;
2441 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2443 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2444 return E_INVALIDARG;
2447 return S_OK;
2450 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2452 HRESULT hr;
2453 LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2455 hr = IMediaSeeking_GetDuration(seek, &duration);
2456 if (FAILED(hr))
2457 return hr;
2459 if (*pdur < duration)
2460 *pdur = duration;
2461 return hr;
2464 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *pDuration)
2466 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2467 HRESULT hr;
2469 TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2471 if (!pDuration)
2472 return E_POINTER;
2474 EnterCriticalSection(&This->cs);
2475 *pDuration = 0;
2476 hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2477 LeaveCriticalSection(&This->cs);
2479 TRACE("--->%08x\n", hr);
2480 return hr;
2483 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *pStop)
2485 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2486 HRESULT hr = S_OK;
2488 TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2490 if (!pStop)
2491 return E_POINTER;
2493 EnterCriticalSection(&This->cs);
2494 if (This->stop_position < 0)
2495 /* Stop position not set, use duration instead */
2496 hr = IMediaSeeking_GetDuration(iface, pStop);
2497 else
2498 *pStop = This->stop_position;
2499 LeaveCriticalSection(&This->cs);
2501 return hr;
2504 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *pCurrent)
2506 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2507 LONGLONG time = 0;
2509 if (!pCurrent)
2510 return E_POINTER;
2512 EnterCriticalSection(&This->cs);
2513 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2515 IReferenceClock_GetTime(This->refClock, &time);
2516 if (time)
2517 time -= This->start_time;
2519 if (This->pause_time > 0)
2520 time += This->pause_time;
2521 *pCurrent = time;
2522 LeaveCriticalSection(&This->cs);
2524 TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2526 return S_OK;
2529 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2530 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2532 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2534 TRACE("(%p/%p)->(%p, %s, 0x%s, %s)\n", This, iface, pTarget,
2535 debugstr_guid(pTargetFormat), wine_dbgstr_longlong(Source), debugstr_guid(pSourceFormat));
2537 if (!pSourceFormat)
2538 pSourceFormat = &This->timeformatseek;
2540 if (!pTargetFormat)
2541 pTargetFormat = &This->timeformatseek;
2543 if (IsEqualGUID(pTargetFormat, pSourceFormat))
2544 *pTarget = Source;
2545 else
2546 FIXME("conversion %s->%s not supported\n", debugstr_guid(pSourceFormat), debugstr_guid(pTargetFormat));
2548 return S_OK;
2551 struct pos_args {
2552 LONGLONG* current, *stop;
2553 DWORD curflags, stopflags;
2556 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2558 struct pos_args *args = (void*)pargs;
2560 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
2563 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2564 DWORD dwCurrentFlags, LONGLONG *pStop, DWORD dwStopFlags)
2566 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2567 HRESULT hr = S_OK;
2568 FILTER_STATE state;
2569 struct pos_args args;
2571 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
2573 EnterCriticalSection(&This->cs);
2574 state = This->state;
2575 TRACE("State: %s\n", state == State_Running ? "Running" : (state == State_Paused ? "Paused" : (state == State_Stopped ? "Stopped" : "UNKNOWN")));
2577 if ((dwCurrentFlags & 0x7) != AM_SEEKING_AbsolutePositioning &&
2578 (dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2579 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
2581 if ((dwStopFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2582 This->stop_position = *pStop;
2583 else if ((dwStopFlags & 0x7) != AM_SEEKING_NoPositioning)
2584 FIXME("Stop position not handled yet!\n");
2586 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2587 IMediaControl_Pause(&This->IMediaControl_iface);
2588 args.current = pCurrent;
2589 args.stop = pStop;
2590 args.curflags = dwCurrentFlags;
2591 args.stopflags = dwStopFlags;
2592 hr = all_renderers_seek(This, found_setposition, (DWORD_PTR)&args);
2594 if ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2595 This->pause_time = This->start_time = -1;
2596 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2597 IMediaControl_Run(&This->IMediaControl_iface);
2598 LeaveCriticalSection(&This->cs);
2600 return hr;
2603 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2604 LONGLONG *pStop)
2606 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2607 HRESULT hr;
2609 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pCurrent, pStop);
2610 hr = IMediaSeeking_GetCurrentPosition(iface, pCurrent);
2611 if (SUCCEEDED(hr))
2612 hr = IMediaSeeking_GetStopPosition(iface, pStop);
2614 return hr;
2617 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2618 LONGLONG *pLatest)
2620 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2622 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2624 return S_OK;
2627 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2629 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2631 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2633 return S_OK;
2636 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2638 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2640 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2642 if (!pdRate)
2643 return E_POINTER;
2645 *pdRate = 1.0;
2647 return S_OK;
2650 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2652 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2654 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2656 return S_OK;
2660 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2662 MediaSeeking_QueryInterface,
2663 MediaSeeking_AddRef,
2664 MediaSeeking_Release,
2665 MediaSeeking_GetCapabilities,
2666 MediaSeeking_CheckCapabilities,
2667 MediaSeeking_IsFormatSupported,
2668 MediaSeeking_QueryPreferredFormat,
2669 MediaSeeking_GetTimeFormat,
2670 MediaSeeking_IsUsingTimeFormat,
2671 MediaSeeking_SetTimeFormat,
2672 MediaSeeking_GetDuration,
2673 MediaSeeking_GetStopPosition,
2674 MediaSeeking_GetCurrentPosition,
2675 MediaSeeking_ConvertTimeFormat,
2676 MediaSeeking_SetPositions,
2677 MediaSeeking_GetPositions,
2678 MediaSeeking_GetAvailable,
2679 MediaSeeking_SetRate,
2680 MediaSeeking_GetRate,
2681 MediaSeeking_GetPreroll
2684 static inline IFilterGraphImpl *impl_from_IMediaPosition(IMediaPosition *iface)
2686 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaPosition_iface);
2689 /*** IUnknown methods ***/
2690 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj)
2692 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2694 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
2696 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2699 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2701 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2703 TRACE("(%p/%p)->()\n", This, iface);
2705 return IUnknown_AddRef(This->outer_unk);
2708 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2710 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2712 TRACE("(%p/%p)->()\n", This, iface);
2714 return IUnknown_Release(This->outer_unk);
2717 /*** IDispatch methods ***/
2718 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo)
2720 FIXME("(%p) stub!\n", iface);
2721 return E_NOTIMPL;
2724 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
2726 FIXME("(%p) stub!\n", iface);
2727 return E_NOTIMPL;
2730 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
2732 FIXME("(%p) stub!\n", iface);
2733 return E_NOTIMPL;
2736 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2738 FIXME("(%p) stub!\n", iface);
2739 return E_NOTIMPL;
2742 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2744 GUID time_format;
2745 HRESULT hr;
2747 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2748 if (FAILED(hr))
2749 return hr;
2750 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2752 FIXME("Unsupported time format.\n");
2753 return E_NOTIMPL;
2756 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2757 return S_OK;
2760 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2762 GUID time_format;
2763 HRESULT hr;
2765 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2766 if (FAILED(hr))
2767 return hr;
2768 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2770 FIXME("Unsupported time format.\n");
2771 return E_NOTIMPL;
2774 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2775 return S_OK;
2778 /*** IMediaPosition methods ***/
2779 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2781 LONGLONG duration;
2782 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2783 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2784 if (FAILED(hr))
2785 return hr;
2786 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2789 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2791 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2792 LONGLONG reftime;
2793 HRESULT hr;
2795 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2796 if (FAILED(hr))
2797 return hr;
2798 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2799 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2802 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2804 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2805 LONGLONG pos;
2806 HRESULT hr;
2808 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2809 if (FAILED(hr))
2810 return hr;
2811 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2814 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2816 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2817 LONGLONG pos;
2818 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2819 if (FAILED(hr))
2820 return hr;
2821 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2824 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2826 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2827 LONGLONG reftime;
2828 HRESULT hr;
2830 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2831 if (FAILED(hr))
2832 return hr;
2833 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2834 &reftime, AM_SEEKING_AbsolutePositioning);
2837 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime)
2839 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2840 return E_NOTIMPL;
2843 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime)
2845 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2846 return E_NOTIMPL;
2849 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2851 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2852 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2855 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2857 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2858 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2861 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward)
2863 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2864 return E_NOTIMPL;
2867 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward)
2869 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2870 return E_NOTIMPL;
2874 static const IMediaPositionVtbl IMediaPosition_VTable =
2876 MediaPosition_QueryInterface,
2877 MediaPosition_AddRef,
2878 MediaPosition_Release,
2879 MediaPosition_GetTypeInfoCount,
2880 MediaPosition_GetTypeInfo,
2881 MediaPosition_GetIDsOfNames,
2882 MediaPosition_Invoke,
2883 MediaPosition_get_Duration,
2884 MediaPosition_put_CurrentPosition,
2885 MediaPosition_get_CurrentPosition,
2886 MediaPosition_get_StopTime,
2887 MediaPosition_put_StopTime,
2888 MediaPosition_get_PrerollTime,
2889 MediaPosition_put_PrerollTime,
2890 MediaPosition_put_Rate,
2891 MediaPosition_get_Rate,
2892 MediaPosition_CanSeekForward,
2893 MediaPosition_CanSeekBackward
2896 static inline IFilterGraphImpl *impl_from_IObjectWithSite(IObjectWithSite *iface)
2898 return CONTAINING_RECORD(iface, IFilterGraphImpl, IObjectWithSite_iface);
2901 /*** IUnknown methods ***/
2902 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite* iface, REFIID riid, void** ppvObj)
2904 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2906 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
2908 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2911 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
2913 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2915 TRACE("(%p/%p)->()\n", This, iface);
2917 return IUnknown_AddRef(This->outer_unk);
2920 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
2922 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2924 TRACE("(%p/%p)->()\n", This, iface);
2926 return IUnknown_Release(This->outer_unk);
2929 /*** IObjectWithSite methods ***/
2931 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
2933 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2935 TRACE("(%p/%p)->()\n", This, iface);
2936 if (This->pSite) IUnknown_Release(This->pSite);
2937 This->pSite = pUnkSite;
2938 IUnknown_AddRef(This->pSite);
2939 return S_OK;
2942 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, PVOID *ppvSite)
2944 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2946 TRACE("(%p/%p)->(%s)\n", This, iface,debugstr_guid(riid));
2948 *ppvSite = NULL;
2949 if (!This->pSite)
2950 return E_FAIL;
2951 else
2952 return IUnknown_QueryInterface(This->pSite, riid, ppvSite);
2955 static const IObjectWithSiteVtbl IObjectWithSite_VTable =
2957 ObjectWithSite_QueryInterface,
2958 ObjectWithSite_AddRef,
2959 ObjectWithSite_Release,
2960 ObjectWithSite_SetSite,
2961 ObjectWithSite_GetSite,
2964 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2966 HRESULT hr = E_NOINTERFACE;
2967 int i;
2968 int entry;
2970 /* Check if the interface type is already registered */
2971 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2972 if (riid == pGraph->ItfCacheEntries[entry].riid)
2974 if (pGraph->ItfCacheEntries[entry].iface)
2976 /* Return the interface if available */
2977 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2978 return S_OK;
2980 break;
2983 if (entry >= MAX_ITF_CACHE_ENTRIES)
2985 FIXME("Not enough space to store interface in the cache\n");
2986 return E_OUTOFMEMORY;
2989 /* Find a filter supporting the requested interface */
2990 for (i = 0; i < pGraph->nFilters; i++)
2992 hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2993 if (hr == S_OK)
2995 pGraph->ItfCacheEntries[entry].riid = riid;
2996 pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2997 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2998 if (entry >= pGraph->nItfCacheEntries)
2999 pGraph->nItfCacheEntries++;
3000 return S_OK;
3002 if (hr != E_NOINTERFACE)
3003 return hr;
3006 return hr;
3009 static inline IFilterGraphImpl *impl_from_IBasicAudio(IBasicAudio *iface)
3011 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicAudio_iface);
3014 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID riid, void **ppvObj)
3016 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3018 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
3020 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
3023 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
3025 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3027 TRACE("(%p/%p)->()\n", This, iface);
3029 return IUnknown_AddRef(This->outer_unk);
3032 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
3034 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3036 TRACE("(%p/%p)->()\n", This, iface);
3038 return IUnknown_Release(This->outer_unk);
3041 /*** IDispatch methods ***/
3042 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *pctinfo)
3044 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3045 IBasicAudio* pBasicAudio;
3046 HRESULT hr;
3048 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3050 EnterCriticalSection(&This->cs);
3052 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3054 if (hr == S_OK)
3055 hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
3057 LeaveCriticalSection(&This->cs);
3059 return hr;
3062 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT iTInfo, LCID lcid,
3063 ITypeInfo **ppTInfo)
3065 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3066 IBasicAudio* pBasicAudio;
3067 HRESULT hr;
3069 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3071 EnterCriticalSection(&This->cs);
3073 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3075 if (hr == S_OK)
3076 hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
3078 LeaveCriticalSection(&This->cs);
3080 return hr;
3083 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID riid, LPOLESTR *rgszNames,
3084 UINT cNames, LCID lcid, DISPID *rgDispId)
3086 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3087 IBasicAudio* pBasicAudio;
3088 HRESULT hr;
3090 TRACE("(%p/%p)->(%s, %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), rgszNames, cNames,
3091 lcid, rgDispId);
3093 EnterCriticalSection(&This->cs);
3095 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3097 if (hr == S_OK)
3098 hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
3100 LeaveCriticalSection(&This->cs);
3102 return hr;
3105 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID dispIdMember, REFIID riid,
3106 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3107 UINT *puArgErr)
3109 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3110 IBasicAudio* pBasicAudio;
3111 HRESULT hr;
3113 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember,
3114 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3116 EnterCriticalSection(&This->cs);
3118 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3120 if (hr == S_OK)
3121 hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3123 LeaveCriticalSection(&This->cs);
3125 return hr;
3128 /*** IBasicAudio methods ***/
3129 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
3131 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3132 IBasicAudio* pBasicAudio;
3133 HRESULT hr;
3135 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
3137 EnterCriticalSection(&This->cs);
3139 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3141 if (hr == S_OK)
3142 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
3144 LeaveCriticalSection(&This->cs);
3146 return hr;
3149 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
3151 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3152 IBasicAudio* pBasicAudio;
3153 HRESULT hr;
3155 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
3157 EnterCriticalSection(&This->cs);
3159 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3161 if (hr == S_OK)
3162 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
3164 LeaveCriticalSection(&This->cs);
3166 return hr;
3169 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
3171 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3172 IBasicAudio* pBasicAudio;
3173 HRESULT hr;
3175 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
3177 EnterCriticalSection(&This->cs);
3179 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3181 if (hr == S_OK)
3182 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
3184 LeaveCriticalSection(&This->cs);
3186 return hr;
3189 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
3191 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3192 IBasicAudio* pBasicAudio;
3193 HRESULT hr;
3195 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
3197 EnterCriticalSection(&This->cs);
3199 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3201 if (hr == S_OK)
3202 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
3204 LeaveCriticalSection(&This->cs);
3206 return hr;
3209 static const IBasicAudioVtbl IBasicAudio_VTable =
3211 BasicAudio_QueryInterface,
3212 BasicAudio_AddRef,
3213 BasicAudio_Release,
3214 BasicAudio_GetTypeInfoCount,
3215 BasicAudio_GetTypeInfo,
3216 BasicAudio_GetIDsOfNames,
3217 BasicAudio_Invoke,
3218 BasicAudio_put_Volume,
3219 BasicAudio_get_Volume,
3220 BasicAudio_put_Balance,
3221 BasicAudio_get_Balance
3224 static inline IFilterGraphImpl *impl_from_IBasicVideo2(IBasicVideo2 *iface)
3226 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicVideo2_iface);
3229 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID riid, void **ppvObj)
3231 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3233 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
3235 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
3238 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
3240 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3242 TRACE("(%p/%p)->()\n", This, iface);
3244 return IUnknown_AddRef(This->outer_unk);
3247 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
3249 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3251 TRACE("(%p/%p)->()\n", This, iface);
3253 return IUnknown_Release(This->outer_unk);
3256 /*** IDispatch methods ***/
3257 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *pctinfo)
3259 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3260 IBasicVideo *pBasicVideo;
3261 HRESULT hr;
3263 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3265 EnterCriticalSection(&This->cs);
3267 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3269 if (hr == S_OK)
3270 hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
3272 LeaveCriticalSection(&This->cs);
3274 return hr;
3277 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT iTInfo, LCID lcid,
3278 ITypeInfo **ppTInfo)
3280 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3281 IBasicVideo *pBasicVideo;
3282 HRESULT hr;
3284 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3286 EnterCriticalSection(&This->cs);
3288 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3290 if (hr == S_OK)
3291 hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
3293 LeaveCriticalSection(&This->cs);
3295 return hr;
3298 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID riid,
3299 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
3301 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3302 IBasicVideo *pBasicVideo;
3303 HRESULT hr;
3305 TRACE("(%p/%p)->(%s, %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), rgszNames, cNames,
3306 lcid, rgDispId);
3308 EnterCriticalSection(&This->cs);
3310 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3312 if (hr == S_OK)
3313 hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
3315 LeaveCriticalSection(&This->cs);
3317 return hr;
3320 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID dispIdMember, REFIID riid,
3321 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3322 UINT *puArgErr)
3324 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3325 IBasicVideo *pBasicVideo;
3326 HRESULT hr;
3328 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember,
3329 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3331 EnterCriticalSection(&This->cs);
3333 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3335 if (hr == S_OK)
3336 hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3338 LeaveCriticalSection(&This->cs);
3340 return hr;
3343 /*** IBasicVideo methods ***/
3344 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3346 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3347 IBasicVideo *pBasicVideo;
3348 HRESULT hr;
3350 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3352 EnterCriticalSection(&This->cs);
3354 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3356 if (hr == S_OK)
3357 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3359 LeaveCriticalSection(&This->cs);
3361 return hr;
3364 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3366 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3367 IBasicVideo *pBasicVideo;
3368 HRESULT hr;
3370 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3372 EnterCriticalSection(&This->cs);
3374 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3376 if (hr == S_OK)
3377 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3379 LeaveCriticalSection(&This->cs);
3381 return hr;
3384 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3386 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3387 IBasicVideo *pBasicVideo;
3388 HRESULT hr;
3390 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3392 EnterCriticalSection(&This->cs);
3394 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3396 if (hr == S_OK)
3397 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3399 LeaveCriticalSection(&This->cs);
3401 return hr;
3404 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3406 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3407 IBasicVideo *pBasicVideo;
3408 HRESULT hr;
3410 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3412 EnterCriticalSection(&This->cs);
3414 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3416 if (hr == S_OK)
3417 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3419 LeaveCriticalSection(&This->cs);
3421 return hr;
3424 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3426 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3427 IBasicVideo *pBasicVideo;
3428 HRESULT hr;
3430 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3432 EnterCriticalSection(&This->cs);
3434 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3436 if (hr == S_OK)
3437 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3439 LeaveCriticalSection(&This->cs);
3441 return hr;
3444 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3446 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3447 IBasicVideo *pBasicVideo;
3448 HRESULT hr;
3450 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3452 EnterCriticalSection(&This->cs);
3454 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3456 if (hr == S_OK)
3457 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3459 LeaveCriticalSection(&This->cs);
3461 return hr;
3464 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3466 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3467 IBasicVideo *pBasicVideo;
3468 HRESULT hr;
3470 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3472 EnterCriticalSection(&This->cs);
3474 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3476 if (hr == S_OK)
3477 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3479 LeaveCriticalSection(&This->cs);
3481 return hr;
3484 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3486 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3487 IBasicVideo *pBasicVideo;
3488 HRESULT hr;
3490 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3492 EnterCriticalSection(&This->cs);
3494 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3496 if (hr == S_OK)
3497 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3499 LeaveCriticalSection(&This->cs);
3501 return hr;
3504 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3506 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3507 IBasicVideo *pBasicVideo;
3508 HRESULT hr;
3510 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3512 EnterCriticalSection(&This->cs);
3514 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3516 if (hr == S_OK)
3517 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3519 LeaveCriticalSection(&This->cs);
3521 return hr;
3524 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3526 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3527 IBasicVideo *pBasicVideo;
3528 HRESULT hr;
3530 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3532 EnterCriticalSection(&This->cs);
3534 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3536 if (hr == S_OK)
3537 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3539 LeaveCriticalSection(&This->cs);
3541 return hr;
3544 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3546 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3547 IBasicVideo *pBasicVideo;
3548 HRESULT hr;
3550 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3552 EnterCriticalSection(&This->cs);
3554 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3556 if (hr == S_OK)
3557 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3559 LeaveCriticalSection(&This->cs);
3561 return hr;
3564 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3566 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3567 IBasicVideo *pBasicVideo;
3568 HRESULT hr;
3570 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3572 EnterCriticalSection(&This->cs);
3574 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3576 if (hr == S_OK)
3577 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3579 LeaveCriticalSection(&This->cs);
3581 return hr;
3584 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3586 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3587 IBasicVideo *pBasicVideo;
3588 HRESULT hr;
3590 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3592 EnterCriticalSection(&This->cs);
3594 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3596 if (hr == S_OK)
3597 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3599 LeaveCriticalSection(&This->cs);
3601 return hr;
3604 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3606 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3607 IBasicVideo *pBasicVideo;
3608 HRESULT hr;
3610 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3612 EnterCriticalSection(&This->cs);
3614 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3616 if (hr == S_OK)
3617 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3619 LeaveCriticalSection(&This->cs);
3621 return hr;
3624 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3626 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3627 IBasicVideo *pBasicVideo;
3628 HRESULT hr;
3630 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3632 EnterCriticalSection(&This->cs);
3634 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3636 if (hr == S_OK)
3637 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3639 LeaveCriticalSection(&This->cs);
3641 return hr;
3644 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3646 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3647 IBasicVideo *pBasicVideo;
3648 HRESULT hr;
3650 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3652 EnterCriticalSection(&This->cs);
3654 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3656 if (hr == S_OK)
3657 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3659 LeaveCriticalSection(&This->cs);
3661 return hr;
3664 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3666 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3667 IBasicVideo *pBasicVideo;
3668 HRESULT hr;
3670 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3672 EnterCriticalSection(&This->cs);
3674 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3676 if (hr == S_OK)
3677 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3679 LeaveCriticalSection(&This->cs);
3681 return hr;
3684 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3686 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3687 IBasicVideo *pBasicVideo;
3688 HRESULT hr;
3690 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3692 EnterCriticalSection(&This->cs);
3694 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3696 if (hr == S_OK)
3697 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3699 LeaveCriticalSection(&This->cs);
3701 return hr;
3704 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3706 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3707 IBasicVideo *pBasicVideo;
3708 HRESULT hr;
3710 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3712 EnterCriticalSection(&This->cs);
3714 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3716 if (hr == S_OK)
3717 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3719 LeaveCriticalSection(&This->cs);
3721 return hr;
3724 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3726 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3727 IBasicVideo *pBasicVideo;
3728 HRESULT hr;
3730 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3732 EnterCriticalSection(&This->cs);
3734 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3736 if (hr == S_OK)
3737 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3739 LeaveCriticalSection(&This->cs);
3741 return hr;
3744 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3745 LONG *pDestinationHeight)
3747 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3748 IBasicVideo *pBasicVideo;
3749 HRESULT hr;
3751 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3753 EnterCriticalSection(&This->cs);
3755 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3757 if (hr == S_OK)
3758 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3760 LeaveCriticalSection(&This->cs);
3762 return hr;
3765 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3766 LONG Width, LONG Height)
3768 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3769 IBasicVideo *pBasicVideo;
3770 HRESULT hr;
3772 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3774 EnterCriticalSection(&This->cs);
3776 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3778 if (hr == S_OK)
3779 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3781 LeaveCriticalSection(&This->cs);
3783 return hr;
3786 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3787 LONG *pWidth, LONG *pHeight)
3789 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3790 IBasicVideo *pBasicVideo;
3791 HRESULT hr;
3793 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3795 EnterCriticalSection(&This->cs);
3797 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3799 if (hr == S_OK)
3800 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3802 LeaveCriticalSection(&This->cs);
3804 return hr;
3807 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3809 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3810 IBasicVideo *pBasicVideo;
3811 HRESULT hr;
3813 TRACE("(%p/%p)->()\n", This, iface);
3815 EnterCriticalSection(&This->cs);
3817 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3819 if (hr == S_OK)
3820 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3822 LeaveCriticalSection(&This->cs);
3824 return hr;
3827 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3828 LONG Width, LONG Height)
3830 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3831 IBasicVideo *pBasicVideo;
3832 HRESULT hr;
3834 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3836 EnterCriticalSection(&This->cs);
3838 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3840 if (hr == S_OK)
3841 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3843 LeaveCriticalSection(&This->cs);
3845 return hr;
3848 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3849 LONG *pTop, LONG *pWidth, LONG *pHeight)
3851 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3852 IBasicVideo *pBasicVideo;
3853 HRESULT hr;
3855 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3857 EnterCriticalSection(&This->cs);
3859 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3861 if (hr == S_OK)
3862 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3864 LeaveCriticalSection(&This->cs);
3866 return hr;
3869 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3871 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3872 IBasicVideo *pBasicVideo;
3873 HRESULT hr;
3875 TRACE("(%p/%p)->()\n", This, iface);
3877 EnterCriticalSection(&This->cs);
3879 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3881 if (hr == S_OK)
3882 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3884 LeaveCriticalSection(&This->cs);
3886 return hr;
3889 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3891 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3892 IBasicVideo *pBasicVideo;
3893 HRESULT hr;
3895 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3897 EnterCriticalSection(&This->cs);
3899 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3901 if (hr == S_OK)
3902 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3904 LeaveCriticalSection(&This->cs);
3906 return hr;
3909 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3910 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3912 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3913 IBasicVideo *pBasicVideo;
3914 HRESULT hr;
3916 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3918 EnterCriticalSection(&This->cs);
3920 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3922 if (hr == S_OK)
3923 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3925 LeaveCriticalSection(&This->cs);
3927 return hr;
3930 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3931 LONG *pDIBImage)
3933 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3934 IBasicVideo *pBasicVideo;
3935 HRESULT hr;
3937 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3939 EnterCriticalSection(&This->cs);
3941 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3943 if (hr == S_OK)
3944 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3946 LeaveCriticalSection(&This->cs);
3948 return hr;
3951 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3953 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3954 IBasicVideo *pBasicVideo;
3955 HRESULT hr;
3957 TRACE("(%p/%p)->()\n", This, iface);
3959 EnterCriticalSection(&This->cs);
3961 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3963 if (hr == S_OK)
3964 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3966 LeaveCriticalSection(&This->cs);
3968 return hr;
3971 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3973 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3974 IBasicVideo *pBasicVideo;
3975 HRESULT hr;
3977 TRACE("(%p/%p)->()\n", This, iface);
3979 EnterCriticalSection(&This->cs);
3981 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3983 if (hr == S_OK)
3984 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3986 LeaveCriticalSection(&This->cs);
3988 return hr;
3991 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3992 LONG *plAspectY)
3994 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3995 IBasicVideo2 *pBasicVideo2;
3996 HRESULT hr;
3998 TRACE("(%p/%p)->()\n", This, iface);
4000 EnterCriticalSection(&This->cs);
4002 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
4004 if (hr == S_OK)
4005 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
4007 LeaveCriticalSection(&This->cs);
4009 return hr;
4012 static const IBasicVideo2Vtbl IBasicVideo_VTable =
4014 BasicVideo_QueryInterface,
4015 BasicVideo_AddRef,
4016 BasicVideo_Release,
4017 BasicVideo_GetTypeInfoCount,
4018 BasicVideo_GetTypeInfo,
4019 BasicVideo_GetIDsOfNames,
4020 BasicVideo_Invoke,
4021 BasicVideo_get_AvgTimePerFrame,
4022 BasicVideo_get_BitRate,
4023 BasicVideo_get_BitErrorRate,
4024 BasicVideo_get_VideoWidth,
4025 BasicVideo_get_VideoHeight,
4026 BasicVideo_put_SourceLeft,
4027 BasicVideo_get_SourceLeft,
4028 BasicVideo_put_SourceWidth,
4029 BasicVideo_get_SourceWidth,
4030 BasicVideo_put_SourceTop,
4031 BasicVideo_get_SourceTop,
4032 BasicVideo_put_SourceHeight,
4033 BasicVideo_get_SourceHeight,
4034 BasicVideo_put_DestinationLeft,
4035 BasicVideo_get_DestinationLeft,
4036 BasicVideo_put_DestinationWidth,
4037 BasicVideo_get_DestinationWidth,
4038 BasicVideo_put_DestinationTop,
4039 BasicVideo_get_DestinationTop,
4040 BasicVideo_put_DestinationHeight,
4041 BasicVideo_get_DestinationHeight,
4042 BasicVideo_SetSourcePosition,
4043 BasicVideo_GetSourcePosition,
4044 BasicVideo_SetDefaultSourcePosition,
4045 BasicVideo_SetDestinationPosition,
4046 BasicVideo_GetDestinationPosition,
4047 BasicVideo_SetDefaultDestinationPosition,
4048 BasicVideo_GetVideoSize,
4049 BasicVideo_GetVideoPaletteEntries,
4050 BasicVideo_GetCurrentImage,
4051 BasicVideo_IsUsingDefaultSource,
4052 BasicVideo_IsUsingDefaultDestination,
4053 BasicVideo2_GetPreferredAspectRatio
4056 static inline IFilterGraphImpl *impl_from_IVideoWindow(IVideoWindow *iface)
4058 return CONTAINING_RECORD(iface, IFilterGraphImpl, IVideoWindow_iface);
4061 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID riid, void **ppvObj)
4063 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4065 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
4067 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
4070 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
4072 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4074 TRACE("(%p/%p)->()\n", This, iface);
4076 return IUnknown_AddRef(This->outer_unk);
4079 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
4081 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4083 TRACE("(%p/%p)->()\n", This, iface);
4085 return IUnknown_Release(This->outer_unk);
4088 /*** IDispatch methods ***/
4089 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *pctinfo)
4091 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4092 IVideoWindow *pVideoWindow;
4093 HRESULT hr;
4095 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
4097 EnterCriticalSection(&This->cs);
4099 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4101 if (hr == S_OK)
4102 hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
4104 LeaveCriticalSection(&This->cs);
4106 return hr;
4109 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT iTInfo, LCID lcid,
4110 ITypeInfo **ppTInfo)
4112 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4113 IVideoWindow *pVideoWindow;
4114 HRESULT hr;
4116 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
4118 EnterCriticalSection(&This->cs);
4120 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4122 if (hr == S_OK)
4123 hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
4125 LeaveCriticalSection(&This->cs);
4127 return hr;
4130 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID riid,
4131 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4133 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4134 IVideoWindow *pVideoWindow;
4135 HRESULT hr;
4137 TRACE("(%p/%p)->(%s, %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), rgszNames, cNames,
4138 lcid, rgDispId);
4140 EnterCriticalSection(&This->cs);
4142 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4144 if (hr == S_OK)
4145 hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
4147 LeaveCriticalSection(&This->cs);
4149 return hr;
4152 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID dispIdMember, REFIID riid,
4153 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4154 UINT*puArgErr)
4156 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4157 IVideoWindow *pVideoWindow;
4158 HRESULT hr;
4160 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember,
4161 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4163 EnterCriticalSection(&This->cs);
4165 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4167 if (hr == S_OK)
4168 hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4170 LeaveCriticalSection(&This->cs);
4172 return hr;
4176 /*** IVideoWindow methods ***/
4177 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
4179 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4180 IVideoWindow *pVideoWindow;
4181 HRESULT hr;
4183 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
4185 EnterCriticalSection(&This->cs);
4187 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4189 if (hr == S_OK)
4190 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
4192 LeaveCriticalSection(&This->cs);
4194 return hr;
4197 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
4199 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4200 IVideoWindow *pVideoWindow;
4201 HRESULT hr;
4203 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
4205 EnterCriticalSection(&This->cs);
4207 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4209 if (hr == S_OK)
4210 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
4212 LeaveCriticalSection(&This->cs);
4214 return hr;
4217 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
4219 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4220 IVideoWindow *pVideoWindow;
4221 HRESULT hr;
4223 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
4225 EnterCriticalSection(&This->cs);
4227 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4229 if (hr == S_OK)
4230 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
4232 LeaveCriticalSection(&This->cs);
4234 return hr;
4237 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
4239 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4240 IVideoWindow *pVideoWindow;
4241 HRESULT hr;
4243 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
4245 EnterCriticalSection(&This->cs);
4247 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4249 if (hr == S_OK)
4250 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
4252 LeaveCriticalSection(&This->cs);
4254 return hr;
4257 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
4259 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4260 IVideoWindow *pVideoWindow;
4261 HRESULT hr;
4263 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
4265 EnterCriticalSection(&This->cs);
4267 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4269 if (hr == S_OK)
4270 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
4272 LeaveCriticalSection(&This->cs);
4274 return hr;
4277 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
4279 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4280 IVideoWindow *pVideoWindow;
4281 HRESULT hr;
4283 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
4285 EnterCriticalSection(&This->cs);
4287 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4289 if (hr == S_OK)
4290 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
4292 LeaveCriticalSection(&This->cs);
4294 return hr;
4297 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
4299 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4300 IVideoWindow *pVideoWindow;
4301 HRESULT hr;
4303 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
4305 EnterCriticalSection(&This->cs);
4307 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4309 if (hr == S_OK)
4310 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4312 LeaveCriticalSection(&This->cs);
4314 return hr;
4317 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
4319 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4320 IVideoWindow *pVideoWindow;
4321 HRESULT hr;
4323 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4325 EnterCriticalSection(&This->cs);
4327 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4329 if (hr == S_OK)
4330 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4332 LeaveCriticalSection(&This->cs);
4334 return hr;
4337 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
4339 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4340 IVideoWindow *pVideoWindow;
4341 HRESULT hr;
4343 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4345 EnterCriticalSection(&This->cs);
4347 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4349 if (hr == S_OK)
4350 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4352 LeaveCriticalSection(&This->cs);
4354 return hr;
4357 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4359 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4360 IVideoWindow *pVideoWindow;
4361 HRESULT hr;
4363 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4365 EnterCriticalSection(&This->cs);
4367 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4369 if (hr == S_OK)
4370 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4372 LeaveCriticalSection(&This->cs);
4374 return hr;
4377 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4379 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4380 IVideoWindow *pVideoWindow;
4381 HRESULT hr;
4383 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4385 EnterCriticalSection(&This->cs);
4387 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4389 if (hr == S_OK)
4390 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4392 LeaveCriticalSection(&This->cs);
4394 return hr;
4397 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4398 LONG *pBackgroundPalette)
4400 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4401 IVideoWindow *pVideoWindow;
4402 HRESULT hr;
4404 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4406 EnterCriticalSection(&This->cs);
4408 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4410 if (hr == S_OK)
4411 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4413 LeaveCriticalSection(&This->cs);
4415 return hr;
4418 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4420 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4421 IVideoWindow *pVideoWindow;
4422 HRESULT hr;
4424 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4426 EnterCriticalSection(&This->cs);
4428 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4430 if (hr == S_OK)
4431 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4433 LeaveCriticalSection(&This->cs);
4435 return hr;
4438 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4440 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4441 IVideoWindow *pVideoWindow;
4442 HRESULT hr;
4444 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4446 EnterCriticalSection(&This->cs);
4448 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4450 if (hr == S_OK)
4451 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4453 LeaveCriticalSection(&This->cs);
4455 return hr;
4458 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4460 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4461 IVideoWindow *pVideoWindow;
4462 HRESULT hr;
4464 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4466 EnterCriticalSection(&This->cs);
4468 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4470 if (hr == S_OK)
4471 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4473 LeaveCriticalSection(&This->cs);
4475 return hr;
4478 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4480 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4481 IVideoWindow *pVideoWindow;
4482 HRESULT hr;
4484 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4486 EnterCriticalSection(&This->cs);
4488 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4490 if (hr == S_OK)
4491 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4493 LeaveCriticalSection(&This->cs);
4495 return hr;
4498 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4500 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4501 IVideoWindow *pVideoWindow;
4502 HRESULT hr;
4504 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4506 EnterCriticalSection(&This->cs);
4508 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4510 if (hr == S_OK)
4511 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4513 LeaveCriticalSection(&This->cs);
4515 return hr;
4518 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4520 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4521 IVideoWindow *pVideoWindow;
4522 HRESULT hr;
4524 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4526 EnterCriticalSection(&This->cs);
4528 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4530 if (hr == S_OK)
4531 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4533 LeaveCriticalSection(&This->cs);
4535 return hr;
4538 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4540 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4541 IVideoWindow *pVideoWindow;
4542 HRESULT hr;
4544 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4546 EnterCriticalSection(&This->cs);
4548 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4550 if (hr == S_OK)
4551 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4553 LeaveCriticalSection(&This->cs);
4555 return hr;
4558 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4560 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4561 IVideoWindow *pVideoWindow;
4562 HRESULT hr;
4564 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4566 EnterCriticalSection(&This->cs);
4568 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4570 if (hr == S_OK)
4571 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4573 LeaveCriticalSection(&This->cs);
4575 return hr;
4578 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4580 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4581 IVideoWindow *pVideoWindow;
4582 HRESULT hr;
4584 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4586 EnterCriticalSection(&This->cs);
4588 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4590 if (hr == S_OK)
4591 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4593 LeaveCriticalSection(&This->cs);
4595 return hr;
4598 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4600 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4601 IVideoWindow *pVideoWindow;
4602 HRESULT hr;
4604 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4606 EnterCriticalSection(&This->cs);
4608 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4610 if (hr == S_OK)
4611 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4613 LeaveCriticalSection(&This->cs);
4615 return hr;
4618 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4620 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4621 IVideoWindow *pVideoWindow;
4622 HRESULT hr;
4624 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4626 EnterCriticalSection(&This->cs);
4628 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4630 if (hr == S_OK)
4631 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4633 LeaveCriticalSection(&This->cs);
4635 return hr;
4638 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4640 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4641 IVideoWindow *pVideoWindow;
4642 HRESULT hr;
4644 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4646 EnterCriticalSection(&This->cs);
4648 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4650 if (hr == S_OK)
4651 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4653 LeaveCriticalSection(&This->cs);
4655 return hr;
4658 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4660 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4661 IVideoWindow *pVideoWindow;
4662 HRESULT hr;
4664 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4666 EnterCriticalSection(&This->cs);
4668 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4670 if (hr == S_OK)
4671 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4673 LeaveCriticalSection(&This->cs);
4675 return hr;
4678 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4680 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4681 IVideoWindow *pVideoWindow;
4682 HRESULT hr;
4684 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4686 EnterCriticalSection(&This->cs);
4688 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4690 if (hr == S_OK)
4691 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4693 LeaveCriticalSection(&This->cs);
4695 return hr;
4698 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4700 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4701 IVideoWindow *pVideoWindow;
4702 HRESULT hr;
4704 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4706 EnterCriticalSection(&This->cs);
4708 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4710 if (hr == S_OK)
4711 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4713 LeaveCriticalSection(&This->cs);
4715 return hr;
4718 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4720 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4721 IVideoWindow *pVideoWindow;
4722 HRESULT hr;
4724 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4726 EnterCriticalSection(&This->cs);
4728 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4730 if (hr == S_OK)
4731 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4733 LeaveCriticalSection(&This->cs);
4735 return hr;
4738 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4740 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4741 IVideoWindow *pVideoWindow;
4742 HRESULT hr;
4744 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4746 EnterCriticalSection(&This->cs);
4748 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4750 if (hr == S_OK)
4751 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4753 LeaveCriticalSection(&This->cs);
4755 return hr;
4758 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4760 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4761 IVideoWindow *pVideoWindow;
4762 HRESULT hr;
4764 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4766 EnterCriticalSection(&This->cs);
4768 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4770 if (hr == S_OK)
4771 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4773 LeaveCriticalSection(&This->cs);
4775 return hr;
4778 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4780 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4781 IVideoWindow *pVideoWindow;
4782 HRESULT hr;
4784 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4786 EnterCriticalSection(&This->cs);
4788 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4790 if (hr == S_OK)
4791 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4793 LeaveCriticalSection(&This->cs);
4795 return hr;
4798 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4799 LONG_PTR wParam, LONG_PTR lParam)
4801 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4802 IVideoWindow *pVideoWindow;
4803 HRESULT hr;
4805 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4807 EnterCriticalSection(&This->cs);
4809 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4811 if (hr == S_OK)
4812 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4814 LeaveCriticalSection(&This->cs);
4816 return hr;
4819 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4820 LONG Width, LONG Height)
4822 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4823 IVideoWindow *pVideoWindow;
4824 HRESULT hr;
4826 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4828 EnterCriticalSection(&This->cs);
4830 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4832 if (hr == S_OK)
4833 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4835 LeaveCriticalSection(&This->cs);
4837 return hr;
4840 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4841 LONG *pWidth, LONG *pHeight)
4843 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4844 IVideoWindow *pVideoWindow;
4845 HRESULT hr;
4847 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4849 EnterCriticalSection(&This->cs);
4851 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4853 if (hr == S_OK)
4854 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4856 LeaveCriticalSection(&This->cs);
4858 return hr;
4861 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4862 LONG *pHeight)
4864 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4865 IVideoWindow *pVideoWindow;
4866 HRESULT hr;
4868 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4870 EnterCriticalSection(&This->cs);
4872 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4874 if (hr == S_OK)
4875 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4877 LeaveCriticalSection(&This->cs);
4879 return hr;
4882 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4883 LONG *pHeight)
4885 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4886 IVideoWindow *pVideoWindow;
4887 HRESULT hr;
4889 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4891 EnterCriticalSection(&This->cs);
4893 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4895 if (hr == S_OK)
4896 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4898 LeaveCriticalSection(&This->cs);
4900 return hr;
4903 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4904 LONG *pWidth, LONG *pHeight)
4906 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4907 IVideoWindow *pVideoWindow;
4908 HRESULT hr;
4910 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4912 EnterCriticalSection(&This->cs);
4914 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4916 if (hr == S_OK)
4917 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4919 LeaveCriticalSection(&This->cs);
4921 return hr;
4924 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4926 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4927 IVideoWindow *pVideoWindow;
4928 HRESULT hr;
4930 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4932 EnterCriticalSection(&This->cs);
4934 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4936 if (hr == S_OK)
4937 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4939 LeaveCriticalSection(&This->cs);
4941 return hr;
4944 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4946 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4947 IVideoWindow *pVideoWindow;
4948 HRESULT hr;
4950 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4952 EnterCriticalSection(&This->cs);
4954 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4956 if (hr == S_OK)
4957 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4959 LeaveCriticalSection(&This->cs);
4961 return hr;
4965 static const IVideoWindowVtbl IVideoWindow_VTable =
4967 VideoWindow_QueryInterface,
4968 VideoWindow_AddRef,
4969 VideoWindow_Release,
4970 VideoWindow_GetTypeInfoCount,
4971 VideoWindow_GetTypeInfo,
4972 VideoWindow_GetIDsOfNames,
4973 VideoWindow_Invoke,
4974 VideoWindow_put_Caption,
4975 VideoWindow_get_Caption,
4976 VideoWindow_put_WindowStyle,
4977 VideoWindow_get_WindowStyle,
4978 VideoWindow_put_WindowStyleEx,
4979 VideoWindow_get_WindowStyleEx,
4980 VideoWindow_put_AutoShow,
4981 VideoWindow_get_AutoShow,
4982 VideoWindow_put_WindowState,
4983 VideoWindow_get_WindowState,
4984 VideoWindow_put_BackgroundPalette,
4985 VideoWindow_get_BackgroundPalette,
4986 VideoWindow_put_Visible,
4987 VideoWindow_get_Visible,
4988 VideoWindow_put_Left,
4989 VideoWindow_get_Left,
4990 VideoWindow_put_Width,
4991 VideoWindow_get_Width,
4992 VideoWindow_put_Top,
4993 VideoWindow_get_Top,
4994 VideoWindow_put_Height,
4995 VideoWindow_get_Height,
4996 VideoWindow_put_Owner,
4997 VideoWindow_get_Owner,
4998 VideoWindow_put_MessageDrain,
4999 VideoWindow_get_MessageDrain,
5000 VideoWindow_get_BorderColor,
5001 VideoWindow_put_BorderColor,
5002 VideoWindow_get_FullScreenMode,
5003 VideoWindow_put_FullScreenMode,
5004 VideoWindow_SetWindowForeground,
5005 VideoWindow_NotifyOwnerMessage,
5006 VideoWindow_SetWindowPosition,
5007 VideoWindow_GetWindowPosition,
5008 VideoWindow_GetMinIdealImageSize,
5009 VideoWindow_GetMaxIdealImageSize,
5010 VideoWindow_GetRestorePosition,
5011 VideoWindow_HideCursor,
5012 VideoWindow_IsCursorHidden
5015 static inline IFilterGraphImpl *impl_from_IMediaEventEx(IMediaEventEx *iface)
5017 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventEx_iface);
5020 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID riid, void **ppvObj)
5022 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5024 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
5026 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
5029 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
5031 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5033 TRACE("(%p/%p)->()\n", This, iface);
5035 return IUnknown_AddRef(This->outer_unk);
5038 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
5040 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5042 TRACE("(%p/%p)->()\n", This, iface);
5044 return IUnknown_Release(This->outer_unk);
5047 /*** IDispatch methods ***/
5048 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *pctinfo)
5050 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5052 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
5054 return S_OK;
5057 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT iTInfo, LCID lcid,
5058 ITypeInfo **ppTInfo)
5060 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5062 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
5064 return S_OK;
5067 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID riid,
5068 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
5070 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5072 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
5073 cNames, lcid, rgDispId);
5075 return S_OK;
5078 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID dispIdMember, REFIID riid,
5079 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
5080 UINT *puArgErr)
5082 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5084 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
5085 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
5087 return S_OK;
5090 /*** IMediaEvent methods ***/
5091 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *hEvent)
5093 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5095 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
5097 *hEvent = (OAEVENT)This->evqueue.msg_event;
5099 return S_OK;
5102 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *lEventCode, LONG_PTR *lParam1,
5103 LONG_PTR *lParam2, LONG msTimeout)
5105 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5106 Event evt;
5108 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
5110 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
5112 *lEventCode = evt.lEventCode;
5113 *lParam1 = evt.lParam1;
5114 *lParam2 = evt.lParam2;
5115 return S_OK;
5118 *lEventCode = 0;
5119 return E_ABORT;
5122 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
5123 LONG *pEvCode)
5125 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5127 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
5129 if (This->state != State_Running)
5130 return VFW_E_WRONG_STATE;
5132 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
5134 *pEvCode = This->CompletionStatus;
5135 return S_OK;
5138 *pEvCode = 0;
5139 return E_ABORT;
5142 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5144 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5146 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5148 if (lEvCode == EC_COMPLETE)
5149 This->HandleEcComplete = FALSE;
5150 else if (lEvCode == EC_REPAINT)
5151 This->HandleEcRepaint = FALSE;
5152 else if (lEvCode == EC_CLOCK_CHANGED)
5153 This->HandleEcClockChanged = FALSE;
5154 else
5155 return S_FALSE;
5157 return S_OK;
5160 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5162 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5164 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5166 if (lEvCode == EC_COMPLETE)
5167 This->HandleEcComplete = TRUE;
5168 else if (lEvCode == EC_REPAINT)
5169 This->HandleEcRepaint = TRUE;
5170 else if (lEvCode == EC_CLOCK_CHANGED)
5171 This->HandleEcClockChanged = TRUE;
5172 else
5173 return S_FALSE;
5175 return S_OK;
5178 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG lEvCode,
5179 LONG_PTR lParam1, LONG_PTR lParam2)
5181 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5183 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
5185 return S_OK;
5188 /*** IMediaEventEx methods ***/
5189 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface, OAHWND hwnd, LONG lMsg,
5190 LONG_PTR lInstanceData)
5192 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5194 TRACE("(%p/%p)->(%08lx, %d, %08lx)\n", This, iface, hwnd, lMsg, lInstanceData);
5196 This->notif.hWnd = (HWND)hwnd;
5197 This->notif.msg = lMsg;
5198 This->notif.instance = lInstanceData;
5200 return S_OK;
5203 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG lNoNotifyFlags)
5205 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5207 TRACE("(%p/%p)->(%d)\n", This, iface, lNoNotifyFlags);
5209 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
5210 return E_INVALIDARG;
5212 This->notif.disabled = lNoNotifyFlags;
5214 return S_OK;
5217 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *lplNoNotifyFlags)
5219 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5221 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
5223 if (!lplNoNotifyFlags)
5224 return E_POINTER;
5226 *lplNoNotifyFlags = This->notif.disabled;
5228 return S_OK;
5232 static const IMediaEventExVtbl IMediaEventEx_VTable =
5234 MediaEvent_QueryInterface,
5235 MediaEvent_AddRef,
5236 MediaEvent_Release,
5237 MediaEvent_GetTypeInfoCount,
5238 MediaEvent_GetTypeInfo,
5239 MediaEvent_GetIDsOfNames,
5240 MediaEvent_Invoke,
5241 MediaEvent_GetEventHandle,
5242 MediaEvent_GetEvent,
5243 MediaEvent_WaitForCompletion,
5244 MediaEvent_CancelDefaultHandling,
5245 MediaEvent_RestoreDefaultHandling,
5246 MediaEvent_FreeEventParams,
5247 MediaEvent_SetNotifyWindow,
5248 MediaEvent_SetNotifyFlags,
5249 MediaEvent_GetNotifyFlags
5253 static inline IFilterGraphImpl *impl_from_IMediaFilter(IMediaFilter *iface)
5255 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaFilter_iface);
5258 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, void **ppv)
5260 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5262 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5265 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
5267 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5269 return IUnknown_AddRef(This->outer_unk);
5272 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
5274 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5276 return IUnknown_Release(This->outer_unk);
5279 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
5281 FIXME("(%p): stub\n", pClassID);
5283 return E_NOTIMPL;
5286 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
5288 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5290 return MediaControl_Stop(&This->IMediaControl_iface);
5293 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5295 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5297 return MediaControl_Pause(&This->IMediaControl_iface);
5300 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
5302 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5304 if (tStart)
5305 FIXME("Run called with non-null tStart: %s\n", wine_dbgstr_longlong(tStart));
5307 return MediaControl_Run(&This->IMediaControl_iface);
5310 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout,
5311 FILTER_STATE *pState)
5313 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5315 return MediaControl_GetState(&This->IMediaControl_iface, dwMsTimeout, (OAFilterState*)pState);
5318 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5320 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5321 HRESULT hr = S_OK;
5322 int i;
5324 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
5326 EnterCriticalSection(&This->cs);
5328 for (i = 0;i < This->nFilters;i++)
5330 hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5331 if (FAILED(hr))
5332 break;
5335 if (FAILED(hr))
5337 for(;i >= 0;i--)
5338 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5340 else
5342 if (This->refClock)
5343 IReferenceClock_Release(This->refClock);
5344 This->refClock = pClock;
5345 if (This->refClock)
5346 IReferenceClock_AddRef(This->refClock);
5347 This->defaultclock = FALSE;
5349 if (This->HandleEcClockChanged)
5351 IMediaEventSink *pEventSink;
5352 HRESULT eshr;
5354 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (void **)&pEventSink);
5355 if (SUCCEEDED(eshr))
5357 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5358 IMediaEventSink_Release(pEventSink);
5363 LeaveCriticalSection(&This->cs);
5365 return hr;
5368 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5370 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5372 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
5374 if (!ppClock)
5375 return E_POINTER;
5377 EnterCriticalSection(&This->cs);
5379 *ppClock = This->refClock;
5380 if (*ppClock)
5381 IReferenceClock_AddRef(*ppClock);
5383 LeaveCriticalSection(&This->cs);
5385 return S_OK;
5388 static const IMediaFilterVtbl IMediaFilter_VTable =
5390 MediaFilter_QueryInterface,
5391 MediaFilter_AddRef,
5392 MediaFilter_Release,
5393 MediaFilter_GetClassID,
5394 MediaFilter_Stop,
5395 MediaFilter_Pause,
5396 MediaFilter_Run,
5397 MediaFilter_GetState,
5398 MediaFilter_SetSyncSource,
5399 MediaFilter_GetSyncSource
5402 static inline IFilterGraphImpl *impl_from_IMediaEventSink(IMediaEventSink *iface)
5404 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventSink_iface);
5407 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, void **ppv)
5409 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5411 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5414 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5416 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5418 return IUnknown_AddRef(This->outer_unk);
5421 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5423 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5425 return IUnknown_Release(This->outer_unk);
5428 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG EventCode,
5429 LONG_PTR EventParam1, LONG_PTR EventParam2)
5431 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5432 Event evt;
5434 TRACE("(%p/%p)->(%d, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5436 /* We need thread safety here, let's use the events queue's one */
5437 EnterCriticalSection(&This->evqueue.msg_crst);
5439 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5441 TRACE("Process EC_COMPLETE notification\n");
5442 if (++This->EcCompleteCount == This->nRenderers)
5444 evt.lEventCode = EC_COMPLETE;
5445 evt.lParam1 = S_OK;
5446 evt.lParam2 = 0;
5447 TRACE("Send EC_COMPLETE to app\n");
5448 EventsQueue_PutEvent(&This->evqueue, &evt);
5449 if (!This->notif.disabled && This->notif.hWnd)
5451 TRACE("Send Window message\n");
5452 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5454 This->CompletionStatus = EC_COMPLETE;
5455 SetEvent(This->hEventCompletion);
5458 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5460 /* FIXME: Not handled yet */
5462 else
5464 evt.lEventCode = EventCode;
5465 evt.lParam1 = EventParam1;
5466 evt.lParam2 = EventParam2;
5467 EventsQueue_PutEvent(&This->evqueue, &evt);
5468 if (!This->notif.disabled && This->notif.hWnd)
5469 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5472 LeaveCriticalSection(&This->evqueue.msg_crst);
5473 return S_OK;
5476 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5478 MediaEventSink_QueryInterface,
5479 MediaEventSink_AddRef,
5480 MediaEventSink_Release,
5481 MediaEventSink_Notify
5484 static inline IFilterGraphImpl *impl_from_IGraphConfig(IGraphConfig *iface)
5486 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphConfig_iface);
5489 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, void **ppv)
5491 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5493 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5496 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5498 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5500 return IUnknown_AddRef(This->outer_unk);
5503 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5505 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5507 return IUnknown_Release(This->outer_unk);
5510 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *pOutputPin, IPin *pInputPin,
5511 const AM_MEDIA_TYPE *pmtFirstConnection, IBaseFilter *pUsingFilter, HANDLE hAbortEvent,
5512 DWORD dwFlags)
5514 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5516 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5518 return E_NOTIMPL;
5521 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface, IGraphConfigCallback *pCallback,
5522 void *pvContext, DWORD dwFlags, HANDLE hAbortEvent)
5524 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5525 HRESULT hr;
5527 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5529 if (hAbortEvent)
5530 FIXME("The parameter hAbortEvent is not handled!\n");
5532 EnterCriticalSection(&This->cs);
5534 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5536 LeaveCriticalSection(&This->cs);
5538 return hr;
5541 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5543 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5545 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5547 return E_NOTIMPL;
5550 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5552 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5554 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5556 return E_NOTIMPL;
5559 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5561 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5563 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5565 return E_NOTIMPL;
5568 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5570 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5572 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5574 return E_NOTIMPL;
5577 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5578 IPinConnection *pConnection, HANDLE hEventAbort)
5580 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5582 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5584 return E_NOTIMPL;
5587 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5588 DWORD dwFlags)
5590 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5592 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5594 return E_NOTIMPL;
5597 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5598 DWORD *dwFlags)
5600 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5602 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5604 return E_NOTIMPL;
5607 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *pFilter,
5608 DWORD dwFlags)
5610 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5612 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5614 return E_NOTIMPL;
5617 static const IGraphConfigVtbl IGraphConfig_VTable =
5619 GraphConfig_QueryInterface,
5620 GraphConfig_AddRef,
5621 GraphConfig_Release,
5622 GraphConfig_Reconnect,
5623 GraphConfig_Reconfigure,
5624 GraphConfig_AddFilterToCache,
5625 GraphConfig_EnumCacheFilter,
5626 GraphConfig_RemoveFilterFromCache,
5627 GraphConfig_GetStartTime,
5628 GraphConfig_PushThroughData,
5629 GraphConfig_SetFilterFlags,
5630 GraphConfig_GetFilterFlags,
5631 GraphConfig_RemoveFilterEx
5634 static inline IFilterGraphImpl *impl_from_IGraphVersion(IGraphVersion *iface)
5636 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphVersion_iface);
5639 static HRESULT WINAPI GraphVersion_QueryInterface(IGraphVersion *iface, REFIID riid, void **ppv)
5641 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5643 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5646 static ULONG WINAPI GraphVersion_AddRef(IGraphVersion *iface)
5648 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5650 return IUnknown_AddRef(This->outer_unk);
5653 static ULONG WINAPI GraphVersion_Release(IGraphVersion *iface)
5655 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5657 return IUnknown_Release(This->outer_unk);
5660 static HRESULT WINAPI GraphVersion_QueryVersion(IGraphVersion *iface, LONG *pVersion)
5662 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5664 if(!pVersion)
5665 return E_POINTER;
5667 TRACE("(%p)->(%p): current version %i\n", This, pVersion, This->version);
5669 *pVersion = This->version;
5670 return S_OK;
5673 static const IGraphVersionVtbl IGraphVersion_VTable =
5675 GraphVersion_QueryInterface,
5676 GraphVersion_AddRef,
5677 GraphVersion_Release,
5678 GraphVersion_QueryVersion,
5681 static const IUnknownVtbl IInner_VTable =
5683 FilterGraphInner_QueryInterface,
5684 FilterGraphInner_AddRef,
5685 FilterGraphInner_Release
5688 /* This is the only function that actually creates a FilterGraph class... */
5689 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5691 IFilterGraphImpl *fimpl;
5692 HRESULT hr;
5694 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5696 *ppObj = NULL;
5698 fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5699 fimpl->defaultclock = TRUE;
5700 fimpl->IUnknown_inner.lpVtbl = &IInner_VTable;
5701 fimpl->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5702 fimpl->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5703 fimpl->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5704 fimpl->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5705 fimpl->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5706 fimpl->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5707 fimpl->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5708 fimpl->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5709 fimpl->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5710 fimpl->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5711 fimpl->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5712 fimpl->IObjectWithSite_iface.lpVtbl = &IObjectWithSite_VTable;
5713 fimpl->IGraphVersion_iface.lpVtbl = &IGraphVersion_VTable;
5714 fimpl->ref = 1;
5715 fimpl->ppFiltersInGraph = NULL;
5716 fimpl->pFilterNames = NULL;
5717 fimpl->nFilters = 0;
5718 fimpl->filterCapacity = 0;
5719 fimpl->nameIndex = 1;
5720 fimpl->refClock = NULL;
5721 fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5722 fimpl->HandleEcComplete = TRUE;
5723 fimpl->HandleEcRepaint = TRUE;
5724 fimpl->HandleEcClockChanged = TRUE;
5725 fimpl->notif.hWnd = 0;
5726 fimpl->notif.disabled = FALSE;
5727 fimpl->nRenderers = 0;
5728 fimpl->EcCompleteCount = 0;
5729 fimpl->refClockProvider = NULL;
5730 fimpl->state = State_Stopped;
5731 fimpl->pSite = NULL;
5732 EventsQueue_Init(&fimpl->evqueue);
5733 InitializeCriticalSection(&fimpl->cs);
5734 fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5735 fimpl->nItfCacheEntries = 0;
5736 memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5737 fimpl->start_time = fimpl->pause_time = 0;
5738 fimpl->stop_position = -1;
5739 fimpl->punkFilterMapper2 = NULL;
5740 fimpl->recursioncount = 0;
5741 fimpl->version = 0;
5743 if (pUnkOuter)
5744 fimpl->outer_unk = pUnkOuter;
5745 else
5746 fimpl->outer_unk = &fimpl->IUnknown_inner;
5748 /* create Filtermapper aggregated. */
5749 hr = CoCreateInstance(&CLSID_FilterMapper2, fimpl->outer_unk, CLSCTX_INPROC_SERVER,
5750 &IID_IUnknown, (void**)&fimpl->punkFilterMapper2);
5752 if (FAILED(hr)) {
5753 ERR("Unable to create filter mapper (%x)\n", hr);
5754 if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5755 CloseHandle(fimpl->hEventCompletion);
5756 EventsQueue_Destroy(&fimpl->evqueue);
5757 fimpl->cs.DebugInfo->Spare[0] = 0;
5758 DeleteCriticalSection(&fimpl->cs);
5759 CoTaskMemFree(fimpl);
5760 return hr;
5763 *ppObj = &fimpl->IUnknown_inner;
5764 return S_OK;
5767 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5769 FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5770 return FilterGraph_create(pUnkOuter, ppObj);