quartz/filtergraph: Factor out find_filter_by_name().
[wine.git] / dlls / quartz / filtergraph.c
blob983e2c0146dc4a64e54ca92e0b319a2bb3c834be
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->IGraphVersion_iface;
274 TRACE(" returning IGraphVersion 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 static IBaseFilter *find_filter_by_name(IFilterGraphImpl *graph, const WCHAR *name)
370 unsigned int i;
372 for (i = 0; i < graph->nFilters; ++i)
374 if (!strcmpW(graph->pFilterNames[i], name))
375 return graph->ppFiltersInGraph[i];
378 return NULL;
381 /*** IFilterGraph methods ***/
382 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface, IBaseFilter *pFilter,
383 LPCWSTR pName)
385 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
386 HRESULT hr;
387 int j;
388 WCHAR* wszFilterName = NULL;
389 BOOL duplicate_name = FALSE;
391 TRACE("(%p/%p)->(%p, %s (%p))\n", This, iface, pFilter, debugstr_w(pName), pName);
393 if (!pFilter)
394 return E_POINTER;
396 wszFilterName = CoTaskMemAlloc( (pName ? strlenW(pName) + 6 : 5) * sizeof(WCHAR) );
398 if (pName && find_filter_by_name(This, pName))
399 duplicate_name = TRUE;
401 /* If no name given or name already existing, generate one */
402 if (!pName || duplicate_name)
404 static const WCHAR wszFmt1[] = {'%','s',' ','%','0','4','d',0};
405 static const WCHAR wszFmt2[] = {'%','0','4','d',0};
407 for (j = 0; j < 10000 ; j++)
409 /* Create name */
410 if (pName)
411 sprintfW(wszFilterName, wszFmt1, pName, This->nameIndex);
412 else
413 sprintfW(wszFilterName, wszFmt2, This->nameIndex);
414 TRACE("Generated name %s\n", debugstr_w(wszFilterName));
416 if (This->nameIndex++ == 10000)
417 This->nameIndex = 1;
419 if (!find_filter_by_name(This, wszFilterName))
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,
571 const WCHAR *name, IBaseFilter **filter)
573 IFilterGraphImpl *graph = impl_from_IFilterGraph2(iface);
575 TRACE("graph %p, name %s, filter %p.\n", graph, debugstr_w(name), filter);
577 if (!filter)
578 return E_POINTER;
580 if ((*filter = find_filter_by_name(graph, name)))
582 IBaseFilter_AddRef(*filter);
583 return S_OK;
586 return VFW_E_NOT_FOUND;
589 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
590 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
592 static HRESULT CheckCircularConnection(IFilterGraphImpl *This, IPin *out, IPin *in)
594 #if 1
595 HRESULT hr;
596 PIN_INFO info_out, info_in;
598 hr = IPin_QueryPinInfo(out, &info_out);
599 if (FAILED(hr))
600 return hr;
601 if (info_out.dir != PINDIR_OUTPUT)
603 IBaseFilter_Release(info_out.pFilter);
604 return VFW_E_CANNOT_CONNECT;
607 hr = IPin_QueryPinInfo(in, &info_in);
608 if (SUCCEEDED(hr))
609 IBaseFilter_Release(info_in.pFilter);
610 if (FAILED(hr))
611 goto out;
612 if (info_in.dir != PINDIR_INPUT)
614 hr = VFW_E_CANNOT_CONNECT;
615 goto out;
618 if (info_out.pFilter == info_in.pFilter)
619 hr = VFW_E_CIRCULAR_GRAPH;
620 else
622 IEnumPins *enumpins;
623 IPin *test;
625 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
626 if (FAILED(hr))
627 goto out;
629 IEnumPins_Reset(enumpins);
630 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
632 PIN_DIRECTION dir = PINDIR_OUTPUT;
633 IPin_QueryDirection(test, &dir);
634 if (dir == PINDIR_INPUT)
636 IPin *victim = NULL;
637 IPin_ConnectedTo(test, &victim);
638 if (victim)
640 hr = CheckCircularConnection(This, victim, in);
641 IPin_Release(victim);
642 if (FAILED(hr))
644 IPin_Release(test);
645 break;
649 IPin_Release(test);
651 IEnumPins_Release(enumpins);
654 out:
655 IBaseFilter_Release(info_out.pFilter);
656 if (FAILED(hr))
657 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
658 return hr;
659 #else
660 /* Debugging filtergraphs not enabled */
661 return S_OK;
662 #endif
666 /* NOTE: despite the implication, it doesn't matter which
667 * way round you put in the input and output pins */
668 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppinIn, IPin *ppinOut,
669 const AM_MEDIA_TYPE *pmt)
671 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
672 PIN_DIRECTION dir;
673 HRESULT hr;
675 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
677 /* FIXME: check pins are in graph */
679 if (TRACE_ON(quartz))
681 PIN_INFO PinInfo;
683 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
684 if (FAILED(hr))
685 return hr;
687 TRACE("Filter owning ppinIn(%p) => %p\n", ppinIn, PinInfo.pFilter);
688 IBaseFilter_Release(PinInfo.pFilter);
690 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
691 if (FAILED(hr))
692 return hr;
694 TRACE("Filter owning ppinOut(%p) => %p\n", ppinOut, PinInfo.pFilter);
695 IBaseFilter_Release(PinInfo.pFilter);
698 hr = IPin_QueryDirection(ppinIn, &dir);
699 if (SUCCEEDED(hr))
701 if (dir == PINDIR_INPUT)
703 hr = CheckCircularConnection(This, ppinOut, ppinIn);
704 if (SUCCEEDED(hr))
705 hr = IPin_Connect(ppinOut, ppinIn, pmt);
707 else
709 hr = CheckCircularConnection(This, ppinIn, ppinOut);
710 if (SUCCEEDED(hr))
711 hr = IPin_Connect(ppinIn, ppinOut, pmt);
715 return hr;
718 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface, IPin *ppin)
720 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
721 IPin *pConnectedTo = NULL;
722 HRESULT hr;
723 PIN_DIRECTION pindir;
725 IPin_QueryDirection(ppin, &pindir);
726 hr = IPin_ConnectedTo(ppin, &pConnectedTo);
728 TRACE("(%p/%p)->(%p) -- %p\n", This, iface, ppin, pConnectedTo);
730 if (FAILED(hr)) {
731 TRACE("Querying connected to failed: %x\n", hr);
732 return hr;
734 IPin_Disconnect(ppin);
735 IPin_Disconnect(pConnectedTo);
736 if (pindir == PINDIR_INPUT)
737 hr = IPin_Connect(pConnectedTo, ppin, NULL);
738 else
739 hr = IPin_Connect(ppin, pConnectedTo, NULL);
740 IPin_Release(pConnectedTo);
741 if (FAILED(hr))
742 WARN("Reconnecting pins failed, pins are not connected now..\n");
743 TRACE("-> %08x\n", hr);
744 return hr;
747 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
749 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
751 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
753 if (!ppin)
754 return E_POINTER;
756 return IPin_Disconnect(ppin);
759 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
761 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
762 IReferenceClock *pClock = NULL;
763 HRESULT hr = S_OK;
764 int i;
766 TRACE("(%p/%p)->() live sources not handled properly!\n", This, iface);
768 EnterCriticalSection(&This->cs);
770 for (i = 0; i < This->nFilters; ++i)
772 DWORD miscflags;
773 IAMFilterMiscFlags *flags = NULL;
774 IBaseFilter_QueryInterface(This->ppFiltersInGraph[i], &IID_IAMFilterMiscFlags, (void**)&flags);
775 if (!flags)
776 continue;
777 miscflags = IAMFilterMiscFlags_GetMiscFlags(flags);
778 IAMFilterMiscFlags_Release(flags);
779 if (miscflags == AM_FILTER_MISC_FLAGS_IS_RENDERER)
780 IBaseFilter_QueryInterface(This->ppFiltersInGraph[i], &IID_IReferenceClock, (void**)&pClock);
781 if (pClock)
782 break;
785 if (!pClock)
787 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
788 This->refClockProvider = NULL;
790 else
791 This->refClockProvider = This->ppFiltersInGraph[i];
793 if (SUCCEEDED(hr))
795 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
796 This->defaultclock = TRUE;
797 IReferenceClock_Release(pClock);
799 LeaveCriticalSection(&This->cs);
801 return hr;
804 static HRESULT GetFilterInfo(IMoniker* pMoniker, VARIANT* pvar)
806 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
807 IPropertyBag * pPropBagCat = NULL;
808 HRESULT hr;
810 VariantInit(pvar);
812 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
814 if (SUCCEEDED(hr))
815 hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL);
817 if (SUCCEEDED(hr))
818 TRACE("Moniker = %s\n", debugstr_w(V_BSTR(pvar)));
820 if (pPropBagCat)
821 IPropertyBag_Release(pPropBagCat);
823 return hr;
826 static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPin*** pppins, ULONG* pnb)
828 HRESULT hr;
829 ULONG nb = 0;
831 TRACE("(%p, %p, %p, %p)\n", pfilter, pinputpin, pppins, pnb);
832 hr = IPin_QueryInternalConnections(pinputpin, NULL, &nb);
833 if (hr == S_OK) {
834 /* Rendered input */
835 } else if (hr == S_FALSE) {
836 *pppins = CoTaskMemAlloc(sizeof(IPin*)*nb);
837 hr = IPin_QueryInternalConnections(pinputpin, *pppins, &nb);
838 if (hr != S_OK) {
839 WARN("Error (%x)\n", hr);
841 } else if (hr == E_NOTIMPL) {
842 /* Input connected to all outputs */
843 IEnumPins* penumpins;
844 IPin* ppin;
845 int i = 0;
846 TRACE("E_NOTIMPL\n");
847 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
848 if (FAILED(hr)) {
849 WARN("filter Enumpins failed (%x)\n", hr);
850 return hr;
852 i = 0;
853 /* Count output pins */
854 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
855 PIN_DIRECTION pindir;
856 IPin_QueryDirection(ppin, &pindir);
857 if (pindir == PINDIR_OUTPUT)
858 i++;
859 IPin_Release(ppin);
861 *pppins = CoTaskMemAlloc(sizeof(IPin*)*i);
862 /* Retrieve output pins */
863 IEnumPins_Reset(penumpins);
864 i = 0;
865 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
866 PIN_DIRECTION pindir;
867 IPin_QueryDirection(ppin, &pindir);
868 if (pindir == PINDIR_OUTPUT)
869 (*pppins)[i++] = ppin;
870 else
871 IPin_Release(ppin);
873 IEnumPins_Release(penumpins);
874 nb = i;
875 if (FAILED(hr)) {
876 WARN("Next failed (%x)\n", hr);
877 return hr;
879 } else if (FAILED(hr)) {
880 WARN("Cannot get internal connection (%x)\n", hr);
881 return hr;
884 *pnb = nb;
885 return S_OK;
888 /*** IGraphBuilder methods ***/
889 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IPin *ppinIn)
891 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
892 HRESULT hr;
893 AM_MEDIA_TYPE* mt = NULL;
894 IEnumMediaTypes* penummt = NULL;
895 ULONG nbmt;
896 IEnumPins* penumpins;
897 IEnumMoniker* pEnumMoniker;
898 GUID tab[2];
899 ULONG nb = 0;
900 IMoniker* pMoniker;
901 ULONG pin;
902 PIN_INFO PinInfo;
903 CLSID FilterCLSID;
904 PIN_DIRECTION dir;
905 unsigned int i = 0;
906 IFilterMapper2 *pFilterMapper2 = NULL;
908 TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
910 if(!ppinOut || !ppinIn)
911 return E_POINTER;
913 if (TRACE_ON(quartz))
915 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
916 if (FAILED(hr))
917 return hr;
919 TRACE("Filter owning ppinIn(%p) => %p\n", ppinIn, PinInfo.pFilter);
920 IBaseFilter_Release(PinInfo.pFilter);
922 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
923 if (FAILED(hr))
924 return hr;
926 TRACE("Filter owning ppinOut(%p) => %p\n", ppinOut, PinInfo.pFilter);
927 IBaseFilter_Release(PinInfo.pFilter);
930 EnterCriticalSection(&This->cs);
931 ++This->recursioncount;
932 if (This->recursioncount >= 5)
934 WARN("Recursion count has reached %d\n", This->recursioncount);
935 hr = VFW_E_CANNOT_CONNECT;
936 goto out;
939 hr = IPin_QueryDirection(ppinOut, &dir);
940 if (FAILED(hr))
941 goto out;
943 if (dir == PINDIR_INPUT)
945 IPin *temp;
947 TRACE("Directions seem backwards, swapping pins\n");
949 temp = ppinIn;
950 ppinIn = ppinOut;
951 ppinOut = temp;
954 hr = CheckCircularConnection(This, ppinOut, ppinIn);
955 if (FAILED(hr))
956 goto out;
958 /* Try direct connection first */
959 hr = IPin_Connect(ppinOut, ppinIn, NULL);
960 if (SUCCEEDED(hr))
961 goto out;
963 TRACE("Direct connection failed, trying to render using extra filters\n");
965 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
966 if (FAILED(hr))
967 goto out;
969 hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
970 IBaseFilter_Release(PinInfo.pFilter);
971 if (FAILED(hr))
972 goto out;
974 /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream
975 * filter to the minor mediatype of input pin of the renderer */
976 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
977 if (FAILED(hr))
979 WARN("EnumMediaTypes (%x)\n", hr);
980 goto out;
983 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
984 if (FAILED(hr)) {
985 WARN("IEnumMediaTypes_Next (%x)\n", hr);
986 goto out;
989 if (!nbmt)
991 WARN("No media type found!\n");
992 hr = VFW_E_INVALIDMEDIATYPE;
993 goto out;
995 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
996 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
998 hr = IUnknown_QueryInterface(This->punkFilterMapper2, &IID_IFilterMapper2, (void**)&pFilterMapper2);
999 if (FAILED(hr)) {
1000 WARN("Unable to get IFilterMapper2 (%x)\n", hr);
1001 goto out;
1004 /* Try to find a suitable filter that can connect to the pin to render */
1005 tab[0] = mt->majortype;
1006 tab[1] = mt->subtype;
1007 hr = IFilterMapper2_EnumMatchingFilters(pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1008 if (FAILED(hr)) {
1009 WARN("Unable to enum filters (%x)\n", hr);
1010 goto out;
1013 hr = VFW_E_CANNOT_RENDER;
1014 while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1016 VARIANT var;
1017 GUID clsid;
1018 IPin** ppins = NULL;
1019 IPin* ppinfilter = NULL;
1020 IBaseFilter* pfilter = NULL;
1021 IAMGraphBuilderCallback *callback = NULL;
1023 hr = GetFilterInfo(pMoniker, &var);
1024 if (FAILED(hr)) {
1025 WARN("Unable to retrieve filter info (%x)\n", hr);
1026 goto error;
1029 hr = IMoniker_BindToObject(pMoniker, NULL, NULL, &IID_IBaseFilter, (LPVOID*)&pfilter);
1030 IMoniker_Release(pMoniker);
1031 if (FAILED(hr)) {
1032 WARN("Unable to create filter (%x), trying next one\n", hr);
1033 goto error;
1036 hr = IBaseFilter_GetClassID(pfilter, &clsid);
1037 if (FAILED(hr))
1039 IBaseFilter_Release(pfilter);
1040 goto error;
1043 if (IsEqualGUID(&clsid, &FilterCLSID)) {
1044 /* Skip filter (same as the one the output pin belongs to) */
1045 IBaseFilter_Release(pfilter);
1046 pfilter = NULL;
1047 goto error;
1050 if (This->pSite)
1052 IUnknown_QueryInterface(This->pSite, &IID_IAMGraphBuilderCallback, (LPVOID*)&callback);
1053 if (callback)
1055 HRESULT rc;
1056 rc = IAMGraphBuilderCallback_SelectedFilter(callback, pMoniker);
1057 if (FAILED(rc))
1059 TRACE("Filter rejected by IAMGraphBuilderCallback_SelectedFilter\n");
1060 IAMGraphBuilderCallback_Release(callback);
1061 goto error;
1066 if (callback)
1068 HRESULT rc;
1069 rc = IAMGraphBuilderCallback_CreatedFilter(callback, pfilter);
1070 IAMGraphBuilderCallback_Release(callback);
1071 if (FAILED(rc))
1073 IBaseFilter_Release(pfilter);
1074 pfilter = NULL;
1075 TRACE("Filter rejected by IAMGraphBuilderCallback_CreatedFilter\n");
1076 goto error;
1080 hr = IFilterGraph2_AddFilter(iface, pfilter, V_BSTR(&var));
1081 if (FAILED(hr)) {
1082 WARN("Unable to add filter (%x)\n", hr);
1083 IBaseFilter_Release(pfilter);
1084 pfilter = NULL;
1085 goto error;
1088 VariantClear(&var);
1090 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1091 if (FAILED(hr)) {
1092 WARN("Enumpins (%x)\n", hr);
1093 goto error;
1096 hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin);
1097 IEnumPins_Release(penumpins);
1099 if (FAILED(hr)) {
1100 WARN("Obtaining next pin: (%x)\n", hr);
1101 goto error;
1103 if (pin == 0) {
1104 WARN("Cannot use this filter: no pins\n");
1105 goto error;
1108 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1109 if (FAILED(hr)) {
1110 TRACE("Cannot connect to filter (%x), trying next one\n", hr);
1111 goto error;
1113 TRACE("Successfully connected to filter, follow chain...\n");
1115 /* Render all output pins of the filter by calling IFilterGraph2_Connect on each of them */
1116 hr = GetInternalConnections(pfilter, ppinfilter, &ppins, &nb);
1118 if (SUCCEEDED(hr)) {
1119 if (nb == 0) {
1120 IPin_Disconnect(ppinfilter);
1121 IPin_Disconnect(ppinOut);
1122 goto error;
1124 TRACE("pins to consider: %d\n", nb);
1125 for(i = 0; i < nb; i++)
1127 LPWSTR pinname = NULL;
1129 TRACE("Processing pin %u\n", i);
1131 hr = IPin_QueryId(ppins[i], &pinname);
1132 if (SUCCEEDED(hr))
1134 if (pinname[0] == '~')
1136 TRACE("Pinname=%s, skipping\n", debugstr_w(pinname));
1137 hr = E_FAIL;
1139 else
1140 hr = IFilterGraph2_Connect(iface, ppins[i], ppinIn);
1141 CoTaskMemFree(pinname);
1144 if (FAILED(hr)) {
1145 TRACE("Cannot connect pin %p (%x)\n", ppinfilter, hr);
1147 IPin_Release(ppins[i]);
1148 if (SUCCEEDED(hr)) break;
1150 while (++i < nb) IPin_Release(ppins[i]);
1151 CoTaskMemFree(ppins);
1152 IPin_Release(ppinfilter);
1153 IBaseFilter_Release(pfilter);
1154 if (FAILED(hr))
1156 IPin_Disconnect(ppinfilter);
1157 IPin_Disconnect(ppinOut);
1158 IFilterGraph2_RemoveFilter(iface, pfilter);
1159 continue;
1161 break;
1164 error:
1165 VariantClear(&var);
1166 if (ppinfilter) IPin_Release(ppinfilter);
1167 if (pfilter) {
1168 IFilterGraph2_RemoveFilter(iface, pfilter);
1169 IBaseFilter_Release(pfilter);
1171 while (++i < nb) IPin_Release(ppins[i]);
1172 CoTaskMemFree(ppins);
1175 IEnumMoniker_Release(pEnumMoniker);
1177 out:
1178 if (pFilterMapper2)
1179 IFilterMapper2_Release(pFilterMapper2);
1180 if (penummt)
1181 IEnumMediaTypes_Release(penummt);
1182 if (mt)
1183 DeleteMediaType(mt);
1184 --This->recursioncount;
1185 LeaveCriticalSection(&This->cs);
1186 TRACE("--> %08x\n", hr);
1187 return SUCCEEDED(hr) ? S_OK : hr;
1190 static HRESULT FilterGraph2_RenderRecurse(IFilterGraphImpl *This, IPin *ppinOut)
1192 /* This pin has been connected now, try to call render on all pins that aren't connected */
1193 IPin *to = NULL;
1194 PIN_INFO info;
1195 IEnumPins *enumpins = NULL;
1196 BOOL renderany = FALSE;
1197 BOOL renderall = TRUE;
1199 IPin_QueryPinInfo(ppinOut, &info);
1201 IBaseFilter_EnumPins(info.pFilter, &enumpins);
1202 /* Don't need to hold a reference, IEnumPins does */
1203 IBaseFilter_Release(info.pFilter);
1205 IEnumPins_Reset(enumpins);
1206 while (IEnumPins_Next(enumpins, 1, &to, NULL) == S_OK)
1208 PIN_DIRECTION dir = PINDIR_INPUT;
1210 IPin_QueryDirection(to, &dir);
1212 if (dir == PINDIR_OUTPUT)
1214 IPin *out = NULL;
1216 IPin_ConnectedTo(to, &out);
1217 if (!out)
1219 HRESULT hr;
1220 hr = IFilterGraph2_Render(&This->IFilterGraph2_iface, to);
1221 if (SUCCEEDED(hr))
1222 renderany = TRUE;
1223 else
1224 renderall = FALSE;
1226 else
1227 IPin_Release(out);
1230 IPin_Release(to);
1233 IEnumPins_Release(enumpins);
1235 if (renderall)
1236 return S_OK;
1238 if (renderany)
1239 return VFW_S_PARTIAL_RENDER;
1241 return VFW_E_CANNOT_RENDER;
1244 /* Ogg hates me if I create a direct rendering method
1246 * It can only connect to a pin properly once, so use a recursive method that does
1248 * +----+ --- (PIN 1) (Render is called on this pin)
1249 * | |
1250 * +----+ --- (PIN 2)
1252 * Enumerate possible renderers that EXACTLY match the requested type
1254 * If none is available, try to add intermediate filters that can connect to the input pin
1255 * then call Render on that intermediate pin's output pins
1256 * if it succeeds: Render returns success, if it doesn't, the intermediate filter is removed,
1257 * and another filter that can connect to the input pin is tried
1258 * if we run out of filters that can, give up and return VFW_E_CANNOT_RENDER
1259 * It's recursive, but fun!
1262 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *ppinOut)
1264 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1265 IEnumMediaTypes* penummt;
1266 AM_MEDIA_TYPE* mt;
1267 ULONG nbmt;
1268 HRESULT hr;
1270 IEnumMoniker* pEnumMoniker;
1271 GUID tab[4];
1272 ULONG nb;
1273 IMoniker* pMoniker;
1274 INT x;
1275 IFilterMapper2 *pFilterMapper2 = NULL;
1277 TRACE("(%p/%p)->(%p)\n", This, iface, ppinOut);
1279 if (TRACE_ON(quartz))
1281 PIN_INFO PinInfo;
1283 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
1284 if (FAILED(hr))
1285 return hr;
1287 TRACE("Filter owning pin => %p\n", PinInfo.pFilter);
1288 IBaseFilter_Release(PinInfo.pFilter);
1291 /* Try to find out if there is a renderer for the specified subtype already, and use that
1293 EnterCriticalSection(&This->cs);
1294 for (x = 0; x < This->nFilters; ++x)
1296 IEnumPins *enumpins = NULL;
1297 IPin *pin = NULL;
1299 hr = IBaseFilter_EnumPins(This->ppFiltersInGraph[x], &enumpins);
1301 if (FAILED(hr) || !enumpins)
1302 continue;
1304 IEnumPins_Reset(enumpins);
1305 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
1307 IPin *to = NULL;
1308 PIN_DIRECTION dir = PINDIR_OUTPUT;
1310 IPin_QueryDirection(pin, &dir);
1311 if (dir != PINDIR_INPUT)
1313 IPin_Release(pin);
1314 continue;
1316 IPin_ConnectedTo(pin, &to);
1318 if (to == NULL)
1320 hr = FilterGraph2_ConnectDirect(iface, ppinOut, pin, NULL);
1321 if (SUCCEEDED(hr))
1323 TRACE("Connected successfully %p/%p, %08x look if we should render more!\n", ppinOut, pin, hr);
1324 IPin_Release(pin);
1326 hr = FilterGraph2_RenderRecurse(This, pin);
1327 if (FAILED(hr))
1329 IPin_Disconnect(ppinOut);
1330 IPin_Disconnect(pin);
1331 continue;
1333 IEnumPins_Release(enumpins);
1334 LeaveCriticalSection(&This->cs);
1335 return hr;
1337 WARN("Could not connect!\n");
1339 else
1340 IPin_Release(to);
1342 IPin_Release(pin);
1344 IEnumPins_Release(enumpins);
1347 LeaveCriticalSection(&This->cs);
1349 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
1350 if (FAILED(hr)) {
1351 WARN("EnumMediaTypes (%x)\n", hr);
1352 return hr;
1355 IEnumMediaTypes_Reset(penummt);
1357 /* Looks like no existing renderer of the kind exists
1358 * Try adding new ones
1360 tab[0] = tab[1] = GUID_NULL;
1361 while (SUCCEEDED(hr))
1363 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
1364 if (FAILED(hr)) {
1365 WARN("IEnumMediaTypes_Next (%x)\n", hr);
1366 break;
1368 if (!nbmt)
1370 hr = VFW_E_CANNOT_RENDER;
1371 break;
1373 else
1375 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1376 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1378 /* Only enumerate once, this doesn't account for all previous ones, but this should be enough nonetheless */
1379 if (IsEqualIID(&tab[0], &mt->majortype) && IsEqualIID(&tab[1], &mt->subtype))
1381 DeleteMediaType(mt);
1382 continue;
1385 if (pFilterMapper2 == NULL)
1387 hr = IUnknown_QueryInterface(This->punkFilterMapper2, &IID_IFilterMapper2, (void**)&pFilterMapper2);
1388 if (FAILED(hr))
1390 WARN("Unable to query IFilterMapper2 (%x)\n", hr);
1391 break;
1395 /* Try to find a suitable renderer with the same media type */
1396 tab[0] = mt->majortype;
1397 tab[1] = mt->subtype;
1398 hr = IFilterMapper2_EnumMatchingFilters(pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1399 if (FAILED(hr))
1401 WARN("Unable to enum filters (%x)\n", hr);
1402 break;
1405 hr = E_FAIL;
1407 while (IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1409 VARIANT var;
1410 IPin* ppinfilter;
1411 IBaseFilter* pfilter = NULL;
1412 IEnumPins* penumpins = NULL;
1413 ULONG pin;
1415 hr = GetFilterInfo(pMoniker, &var);
1416 if (FAILED(hr)) {
1417 WARN("Unable to retrieve filter info (%x)\n", hr);
1418 goto error;
1421 hr = IMoniker_BindToObject(pMoniker, NULL, NULL, &IID_IBaseFilter, (LPVOID*)&pfilter);
1422 IMoniker_Release(pMoniker);
1423 if (FAILED(hr))
1425 WARN("Unable to create filter (%x), trying next one\n", hr);
1426 goto error;
1429 hr = IFilterGraph2_AddFilter(iface, pfilter, V_BSTR(&var));
1430 if (FAILED(hr)) {
1431 WARN("Unable to add filter (%x)\n", hr);
1432 IBaseFilter_Release(pfilter);
1433 pfilter = NULL;
1434 goto error;
1437 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1438 if (FAILED(hr)) {
1439 WARN("Splitter Enumpins (%x)\n", hr);
1440 goto error;
1443 while ((hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin)) == S_OK)
1445 PIN_DIRECTION dir;
1447 if (pin == 0) {
1448 WARN("No Pin\n");
1449 hr = E_FAIL;
1450 goto error;
1453 hr = IPin_QueryDirection(ppinfilter, &dir);
1454 if (FAILED(hr)) {
1455 IPin_Release(ppinfilter);
1456 WARN("QueryDirection failed (%x)\n", hr);
1457 goto error;
1459 if (dir != PINDIR_INPUT) {
1460 IPin_Release(ppinfilter);
1461 continue; /* Wrong direction */
1464 /* Connect the pin to the "Renderer" */
1465 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1466 IPin_Release(ppinfilter);
1468 if (FAILED(hr)) {
1469 WARN("Unable to connect %s to renderer (%x)\n", debugstr_w(V_BSTR(&var)), hr);
1470 goto error;
1472 TRACE("Connected, recursing %s\n", debugstr_w(V_BSTR(&var)));
1474 VariantClear(&var);
1476 hr = FilterGraph2_RenderRecurse(This, ppinfilter);
1477 if (FAILED(hr)) {
1478 WARN("Unable to connect recursively (%x)\n", hr);
1479 goto error;
1481 IBaseFilter_Release(pfilter);
1482 break;
1484 if (SUCCEEDED(hr)) {
1485 IEnumPins_Release(penumpins);
1486 break; /* out of IEnumMoniker_Next loop */
1489 /* IEnumPins_Next failed, all other failure case caught by goto error */
1490 WARN("IEnumPins_Next (%x)\n", hr);
1491 /* goto error */
1493 error:
1494 VariantClear(&var);
1495 if (penumpins)
1496 IEnumPins_Release(penumpins);
1497 if (pfilter) {
1498 IFilterGraph2_RemoveFilter(iface, pfilter);
1499 IBaseFilter_Release(pfilter);
1501 if (SUCCEEDED(hr)) DebugBreak();
1504 IEnumMoniker_Release(pEnumMoniker);
1505 if (nbmt)
1506 DeleteMediaType(mt);
1507 if (SUCCEEDED(hr))
1508 break;
1509 hr = S_OK;
1512 if (pFilterMapper2)
1513 IFilterMapper2_Release(pFilterMapper2);
1515 IEnumMediaTypes_Release(penummt);
1516 return hr;
1519 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface, LPCWSTR lpcwstrFile,
1520 LPCWSTR lpcwstrPlayList)
1522 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1523 static const WCHAR string[] = {'R','e','a','d','e','r',0};
1524 IBaseFilter* preader = NULL;
1525 IPin* ppinreader = NULL;
1526 IEnumPins* penumpins = NULL;
1527 HRESULT hr;
1528 BOOL partial = FALSE;
1529 BOOL any = FALSE;
1531 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1533 if (lpcwstrPlayList != NULL)
1534 return E_INVALIDARG;
1536 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, string, &preader);
1537 if (FAILED(hr))
1538 return hr;
1540 hr = IBaseFilter_EnumPins(preader, &penumpins);
1541 if (SUCCEEDED(hr))
1543 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1545 PIN_DIRECTION dir;
1547 IPin_QueryDirection(ppinreader, &dir);
1548 if (dir == PINDIR_OUTPUT)
1550 INT i;
1552 hr = IFilterGraph2_Render(iface, ppinreader);
1553 TRACE("Render %08x\n", hr);
1555 for (i = 0; i < This->nFilters; ++i)
1556 TRACE("Filters in chain: %s\n", debugstr_w(This->pFilterNames[i]));
1558 if (SUCCEEDED(hr))
1559 any = TRUE;
1560 if (hr != S_OK)
1561 partial = TRUE;
1563 IPin_Release(ppinreader);
1565 IEnumPins_Release(penumpins);
1567 if (!any)
1568 hr = VFW_E_CANNOT_RENDER;
1569 else if (partial)
1570 hr = VFW_S_PARTIAL_RENDER;
1571 else
1572 hr = S_OK;
1574 IBaseFilter_Release(preader);
1576 TRACE("--> %08x\n", hr);
1577 return hr;
1580 static HRESULT CreateFilterInstanceAndLoadFile(GUID* clsid, LPCOLESTR pszFileName, IBaseFilter **filter)
1582 IFileSourceFilter *source = NULL;
1583 HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1584 TRACE("CLSID: %s\n", debugstr_guid(clsid));
1585 if (FAILED(hr))
1586 return hr;
1588 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID*)&source);
1589 if (FAILED(hr))
1591 IBaseFilter_Release(*filter);
1592 return hr;
1595 /* Load the file in the file source filter */
1596 hr = IFileSourceFilter_Load(source, pszFileName, NULL);
1597 IFileSourceFilter_Release(source);
1598 if (FAILED(hr)) {
1599 WARN("Load (%x)\n", hr);
1600 IBaseFilter_Release(*filter);
1601 return hr;
1604 return hr;
1607 /* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
1608 static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
1610 HRESULT hr;
1611 GUID clsid;
1612 IAsyncReader * pReader = NULL;
1613 IFileSourceFilter* pSource = NULL;
1614 IPin * pOutputPin = NULL;
1615 static const WCHAR wszOutputPinName[] = { 'O','u','t','p','u','t',0 };
1617 /* Try to find a match without reading the file first */
1618 hr = GetClassMediaFile(NULL, pszFileName, NULL, NULL, &clsid);
1620 if (hr == S_OK)
1621 return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
1623 /* Now create a AyncReader instance, to check for signature bytes in the file */
1624 hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1625 if (FAILED(hr))
1626 return hr;
1628 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID *)&pSource);
1629 if (FAILED(hr))
1631 IBaseFilter_Release(*filter);
1632 return hr;
1635 hr = IFileSourceFilter_Load(pSource, pszFileName, NULL);
1636 IFileSourceFilter_Release(pSource);
1637 if (FAILED(hr))
1639 IBaseFilter_Release(*filter);
1640 return hr;
1643 hr = IBaseFilter_FindPin(*filter, wszOutputPinName, &pOutputPin);
1644 if (FAILED(hr))
1646 IBaseFilter_Release(*filter);
1647 return hr;
1650 hr = IPin_QueryInterface(pOutputPin, &IID_IAsyncReader, (LPVOID *)&pReader);
1651 IPin_Release(pOutputPin);
1652 if (FAILED(hr))
1654 IBaseFilter_Release(*filter);
1655 return hr;
1658 /* Try again find a match */
1659 hr = GetClassMediaFile(pReader, pszFileName, NULL, NULL, &clsid);
1660 IAsyncReader_Release(pReader);
1662 if (hr == S_OK)
1664 /* Release the AsyncReader filter and create the matching one */
1665 IBaseFilter_Release(*filter);
1666 return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
1669 /* Return the AsyncReader filter */
1670 return S_OK;
1673 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface, LPCWSTR lpcwstrFileName,
1674 LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1676 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1677 HRESULT hr;
1678 IBaseFilter* preader;
1679 IFileSourceFilter* pfile = NULL;
1680 AM_MEDIA_TYPE mt;
1681 WCHAR* filename;
1683 TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1685 /* Try from file name first, then fall back to default asynchronous reader */
1686 hr = GetFileSourceFilter(lpcwstrFileName, &preader);
1687 if (FAILED(hr)) {
1688 WARN("Unable to create file source filter (%x)\n", hr);
1689 return hr;
1692 hr = IFilterGraph2_AddFilter(iface, preader, lpcwstrFilterName);
1693 if (FAILED(hr)) {
1694 WARN("Unable add filter (%x)\n", hr);
1695 IBaseFilter_Release(preader);
1696 return hr;
1699 hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1700 if (FAILED(hr)) {
1701 WARN("Unable to get IFileSourceInterface (%x)\n", hr);
1702 goto error;
1705 /* The file has been already loaded */
1706 hr = IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1707 if (FAILED(hr)) {
1708 WARN("GetCurFile (%x)\n", hr);
1709 goto error;
1712 TRACE("File %s\n", debugstr_w(filename));
1713 TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
1714 TRACE("SubType %s\n", debugstr_guid(&mt.subtype));
1716 if (ppFilter)
1717 *ppFilter = preader;
1718 IFileSourceFilter_Release(pfile);
1720 return S_OK;
1722 error:
1723 if (pfile)
1724 IFileSourceFilter_Release(pfile);
1725 IFilterGraph2_RemoveFilter(iface, preader);
1726 IBaseFilter_Release(preader);
1728 return hr;
1731 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR hFile)
1733 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1735 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1737 return S_OK;
1740 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1742 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1744 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1746 return S_OK;
1749 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1751 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1753 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1755 return S_OK;
1758 /*** IFilterGraph2 methods ***/
1759 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1760 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1762 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1763 HRESULT hr;
1764 IBaseFilter* pfilter;
1766 TRACE("(%p/%p)->(%p %p %s %p)\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1768 hr = IMoniker_BindToObject(pMoniker, pCtx, NULL, &IID_IBaseFilter, (void**)&pfilter);
1769 if(FAILED(hr)) {
1770 WARN("Unable to bind moniker to filter object (%x)\n", hr);
1771 return hr;
1774 hr = IFilterGraph2_AddFilter(iface, pfilter, lpcwstrFilterName);
1775 if (FAILED(hr)) {
1776 WARN("Unable to add filter (%x)\n", hr);
1777 IBaseFilter_Release(pfilter);
1778 return hr;
1781 if(ppFilter)
1782 *ppFilter = pfilter;
1783 else IBaseFilter_Release(pfilter);
1785 return S_OK;
1788 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *ppin,
1789 const AM_MEDIA_TYPE *pmt)
1791 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1793 TRACE("(%p/%p)->(%p %p): stub !!!\n", This, iface, ppin, pmt);
1795 return S_OK;
1798 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *pPinOut, DWORD dwFlags,
1799 DWORD *pvContext)
1801 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1803 TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This, iface, pPinOut, dwFlags, pvContext);
1805 return S_OK;
1809 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1811 FilterGraph2_QueryInterface,
1812 FilterGraph2_AddRef,
1813 FilterGraph2_Release,
1814 FilterGraph2_AddFilter,
1815 FilterGraph2_RemoveFilter,
1816 FilterGraph2_EnumFilters,
1817 FilterGraph2_FindFilterByName,
1818 FilterGraph2_ConnectDirect,
1819 FilterGraph2_Reconnect,
1820 FilterGraph2_Disconnect,
1821 FilterGraph2_SetDefaultSyncSource,
1822 FilterGraph2_Connect,
1823 FilterGraph2_Render,
1824 FilterGraph2_RenderFile,
1825 FilterGraph2_AddSourceFilter,
1826 FilterGraph2_SetLogFile,
1827 FilterGraph2_Abort,
1828 FilterGraph2_ShouldOperationContinue,
1829 FilterGraph2_AddSourceFilterForMoniker,
1830 FilterGraph2_ReconnectEx,
1831 FilterGraph2_RenderEx
1834 static inline IFilterGraphImpl *impl_from_IMediaControl(IMediaControl *iface)
1836 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaControl_iface);
1839 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID riid, void **ppvObj)
1841 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1843 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
1845 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
1848 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1850 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1852 TRACE("(%p/%p)->()\n", This, iface);
1854 return IUnknown_AddRef(This->outer_unk);
1857 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1859 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1861 TRACE("(%p/%p)->()\n", This, iface);
1863 return IUnknown_Release(This->outer_unk);
1867 /*** IDispatch methods ***/
1868 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *pctinfo)
1870 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1872 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1874 return S_OK;
1877 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT iTInfo, LCID lcid,
1878 ITypeInfo **ppTInfo)
1880 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1882 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1884 return S_OK;
1887 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID riid,
1888 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1890 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1892 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
1893 cNames, lcid, rgDispId);
1895 return S_OK;
1898 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID dispIdMember, REFIID riid,
1899 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
1900 UINT *puArgErr)
1902 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1904 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
1905 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
1907 return S_OK;
1910 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *, DWORD_PTR data);
1912 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter, DWORD_PTR data)
1914 HRESULT hr;
1915 IPin* pInputPin;
1916 IPin** ppPins;
1917 ULONG nb;
1918 ULONG i;
1919 PIN_INFO PinInfo;
1921 TRACE("%p %p\n", pGraph, pOutputPin);
1922 PinInfo.pFilter = NULL;
1924 hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1926 if (SUCCEEDED(hr))
1928 hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1929 if (SUCCEEDED(hr))
1930 hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1931 IPin_Release(pInputPin);
1934 if (SUCCEEDED(hr))
1936 if (nb == 0)
1938 TRACE("Reached a renderer\n");
1939 /* Count renderers for end of stream notification */
1940 pGraph->nRenderers++;
1942 else
1944 for(i = 0; i < nb; i++)
1946 /* Explore the graph downstream from this pin
1947 * FIXME: We should prevent exploring from a pin more than once. This can happens when
1948 * several input pins are connected to the same output (a MUX for instance). */
1949 ExploreGraph(pGraph, ppPins[i], FoundFilter, data);
1950 IPin_Release(ppPins[i]);
1953 CoTaskMemFree(ppPins);
1955 TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1957 FoundFilter(PinInfo.pFilter, data);
1960 if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1961 return hr;
1964 static HRESULT WINAPI SendRun(IBaseFilter *pFilter, DWORD_PTR data)
1966 REFERENCE_TIME time = *(REFERENCE_TIME*)data;
1967 return IBaseFilter_Run(pFilter, time);
1970 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1972 return IBaseFilter_Pause(pFilter);
1975 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1977 return IBaseFilter_Stop(pFilter);
1980 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1982 FILTER_STATE state;
1983 DWORD time_end = data;
1984 DWORD time_now = GetTickCount();
1985 LONG wait;
1987 if (time_end == INFINITE)
1989 wait = INFINITE;
1991 else if (time_end > time_now)
1993 wait = time_end - time_now;
1995 else
1996 wait = 0;
1998 return IBaseFilter_GetState(pFilter, wait, &state);
2002 static HRESULT SendFilterMessage(IFilterGraphImpl *This, fnFoundFilter FoundFilter, DWORD_PTR data)
2004 int i;
2005 IBaseFilter* pfilter;
2006 IEnumPins* pEnum;
2007 HRESULT hr;
2008 IPin* pPin;
2009 DWORD dummy;
2010 PIN_DIRECTION dir;
2012 TRACE("(%p)->()\n", This);
2014 /* Explorer the graph from source filters to renderers, determine renderers
2015 * number and run filters from renderers to source filters */
2016 This->nRenderers = 0;
2017 ResetEvent(This->hEventCompletion);
2019 for(i = 0; i < This->nFilters; i++)
2021 BOOL source = TRUE;
2022 pfilter = This->ppFiltersInGraph[i];
2023 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
2024 if (hr != S_OK)
2026 WARN("Enum pins failed %x\n", hr);
2027 continue;
2029 /* Check if it is a source filter */
2030 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2032 IPin_QueryDirection(pPin, &dir);
2033 IPin_Release(pPin);
2034 if (dir == PINDIR_INPUT)
2036 source = FALSE;
2037 break;
2040 if (source)
2042 TRACE("Found a source filter %p\n", pfilter);
2043 IEnumPins_Reset(pEnum);
2044 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2046 /* Explore the graph downstream from this pin */
2047 ExploreGraph(This, pPin, FoundFilter, data);
2048 IPin_Release(pPin);
2050 FoundFilter(pfilter, data);
2052 IEnumPins_Release(pEnum);
2055 return S_FALSE;
2058 /*** IMediaControl methods ***/
2059 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
2061 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2063 TRACE("(%p/%p)->()\n", This, iface);
2065 EnterCriticalSection(&This->cs);
2066 if (This->state == State_Running)
2067 goto out;
2068 This->EcCompleteCount = 0;
2070 if (This->defaultclock && !This->refClock)
2071 IFilterGraph2_SetDefaultSyncSource(&This->IFilterGraph2_iface);
2073 if (This->refClock)
2075 REFERENCE_TIME now;
2076 IReferenceClock_GetTime(This->refClock, &now);
2077 if (This->state == State_Stopped)
2078 This->start_time = now + 500000;
2079 else if (This->pause_time >= 0)
2080 This->start_time += now - This->pause_time;
2081 else
2082 This->start_time = now;
2084 else This->start_time = 0;
2086 SendFilterMessage(This, SendRun, (DWORD_PTR)&This->start_time);
2087 This->state = State_Running;
2088 out:
2089 LeaveCriticalSection(&This->cs);
2090 return S_FALSE;
2093 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
2095 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2097 TRACE("(%p/%p)->()\n", This, iface);
2099 EnterCriticalSection(&This->cs);
2100 if (This->state == State_Paused)
2101 goto out;
2103 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2104 IReferenceClock_GetTime(This->refClock, &This->pause_time);
2105 else
2106 This->pause_time = -1;
2108 SendFilterMessage(This, SendPause, 0);
2109 This->state = State_Paused;
2110 out:
2111 LeaveCriticalSection(&This->cs);
2112 return S_FALSE;
2115 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
2117 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2119 TRACE("(%p/%p)->()\n", This, iface);
2121 if (This->state == State_Stopped) return S_OK;
2123 EnterCriticalSection(&This->cs);
2124 if (This->state == State_Running) SendFilterMessage(This, SendPause, 0);
2125 SendFilterMessage(This, SendStop, 0);
2126 This->state = State_Stopped;
2127 LeaveCriticalSection(&This->cs);
2128 return S_OK;
2131 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG msTimeout,
2132 OAFilterState *pfs)
2134 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2135 DWORD end;
2137 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
2139 if (!pfs)
2140 return E_POINTER;
2142 EnterCriticalSection(&This->cs);
2144 *pfs = This->state;
2145 if (msTimeout > 0)
2147 end = GetTickCount() + msTimeout;
2149 else if (msTimeout < 0)
2151 end = INFINITE;
2153 else
2155 end = 0;
2157 if (end)
2158 SendFilterMessage(This, SendGetState, end);
2160 LeaveCriticalSection(&This->cs);
2162 return S_OK;
2165 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
2167 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2169 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strFilename), strFilename);
2171 return IFilterGraph2_RenderFile(&This->IFilterGraph2_iface, strFilename, NULL);
2174 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
2175 IDispatch **ppUnk)
2177 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2179 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2181 return S_OK;
2184 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2186 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2188 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2190 return S_OK;
2193 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2195 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2197 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2199 return S_OK;
2202 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
2204 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2206 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2208 return S_OK;
2212 static const IMediaControlVtbl IMediaControl_VTable =
2214 MediaControl_QueryInterface,
2215 MediaControl_AddRef,
2216 MediaControl_Release,
2217 MediaControl_GetTypeInfoCount,
2218 MediaControl_GetTypeInfo,
2219 MediaControl_GetIDsOfNames,
2220 MediaControl_Invoke,
2221 MediaControl_Run,
2222 MediaControl_Pause,
2223 MediaControl_Stop,
2224 MediaControl_GetState,
2225 MediaControl_RenderFile,
2226 MediaControl_AddSourceFilter,
2227 MediaControl_get_FilterCollection,
2228 MediaControl_get_RegFilterCollection,
2229 MediaControl_StopWhenReady
2232 static inline IFilterGraphImpl *impl_from_IMediaSeeking(IMediaSeeking *iface)
2234 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaSeeking_iface);
2237 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID riid, void **ppvObj)
2239 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2241 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
2243 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2246 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2248 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2250 TRACE("(%p/%p)->()\n", This, iface);
2252 return IUnknown_AddRef(This->outer_unk);
2255 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2257 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2259 TRACE("(%p/%p)->()\n", This, iface);
2261 return IUnknown_Release(This->outer_unk);
2264 typedef HRESULT (WINAPI *fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
2266 static HRESULT all_renderers_seek(IFilterGraphImpl *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2267 BOOL allnotimpl = TRUE;
2268 int i;
2269 HRESULT hr, hr_return = S_OK;
2271 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2272 /* Send a message to all renderers, they are responsible for broadcasting it further */
2274 for(i = 0; i < This->nFilters; i++)
2276 IMediaSeeking *seek = NULL;
2277 IBaseFilter* pfilter = This->ppFiltersInGraph[i];
2278 IAMFilterMiscFlags *flags = NULL;
2279 ULONG filterflags;
2280 IBaseFilter_QueryInterface(pfilter, &IID_IAMFilterMiscFlags, (void**)&flags);
2281 if (!flags)
2282 continue;
2283 filterflags = IAMFilterMiscFlags_GetMiscFlags(flags);
2284 IAMFilterMiscFlags_Release(flags);
2285 if (filterflags != AM_FILTER_MISC_FLAGS_IS_RENDERER)
2286 continue;
2288 IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2289 if (!seek)
2290 continue;
2291 hr = FoundSeek(This, seek, arg);
2292 IMediaSeeking_Release(seek);
2293 if (hr_return != E_NOTIMPL)
2294 allnotimpl = FALSE;
2295 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2296 hr_return = hr;
2299 if (allnotimpl)
2300 return E_NOTIMPL;
2301 return hr_return;
2304 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2306 HRESULT hr;
2307 DWORD caps = 0;
2309 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2310 if (FAILED(hr))
2311 return hr;
2313 /* Only add common capabilities everything supports */
2314 *(DWORD*)pcaps &= caps;
2316 return hr;
2319 /*** IMediaSeeking methods ***/
2320 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2322 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2323 HRESULT hr;
2325 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2327 if (!pCapabilities)
2328 return E_POINTER;
2330 EnterCriticalSection(&This->cs);
2331 *pCapabilities = 0xffffffff;
2333 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2334 LeaveCriticalSection(&This->cs);
2336 return hr;
2339 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2341 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2342 DWORD originalcaps;
2343 HRESULT hr;
2345 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2347 if (!pCapabilities)
2348 return E_POINTER;
2350 EnterCriticalSection(&This->cs);
2351 originalcaps = *pCapabilities;
2352 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2353 LeaveCriticalSection(&This->cs);
2355 if (FAILED(hr))
2356 return hr;
2358 if (!*pCapabilities)
2359 return E_FAIL;
2360 if (*pCapabilities != originalcaps)
2361 return S_FALSE;
2362 return S_OK;
2365 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2367 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2369 if (!pFormat)
2370 return E_POINTER;
2372 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2374 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2376 WARN("Unhandled time format %s\n", debugstr_guid(pFormat));
2377 return S_FALSE;
2380 return S_OK;
2383 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2385 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2387 if (!pFormat)
2388 return E_POINTER;
2390 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2391 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2393 return S_OK;
2396 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2398 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2400 if (!pFormat)
2401 return E_POINTER;
2403 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2404 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2406 return S_OK;
2409 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2411 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2413 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2414 if (!pFormat)
2415 return E_POINTER;
2417 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2418 return S_FALSE;
2420 return S_OK;
2423 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2425 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2427 if (!pFormat)
2428 return E_POINTER;
2430 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2432 if (This->state != State_Stopped)
2433 return VFW_E_WRONG_STATE;
2435 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2437 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2438 return E_INVALIDARG;
2441 return S_OK;
2444 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2446 HRESULT hr;
2447 LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2449 hr = IMediaSeeking_GetDuration(seek, &duration);
2450 if (FAILED(hr))
2451 return hr;
2453 if (*pdur < duration)
2454 *pdur = duration;
2455 return hr;
2458 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *pDuration)
2460 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2461 HRESULT hr;
2463 TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2465 if (!pDuration)
2466 return E_POINTER;
2468 EnterCriticalSection(&This->cs);
2469 *pDuration = 0;
2470 hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2471 LeaveCriticalSection(&This->cs);
2473 TRACE("--->%08x\n", hr);
2474 return hr;
2477 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *pStop)
2479 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2480 HRESULT hr = S_OK;
2482 TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2484 if (!pStop)
2485 return E_POINTER;
2487 EnterCriticalSection(&This->cs);
2488 if (This->stop_position < 0)
2489 /* Stop position not set, use duration instead */
2490 hr = IMediaSeeking_GetDuration(iface, pStop);
2491 else
2492 *pStop = This->stop_position;
2493 LeaveCriticalSection(&This->cs);
2495 return hr;
2498 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *pCurrent)
2500 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2501 LONGLONG time = 0;
2503 if (!pCurrent)
2504 return E_POINTER;
2506 EnterCriticalSection(&This->cs);
2507 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2509 IReferenceClock_GetTime(This->refClock, &time);
2510 if (time)
2511 time -= This->start_time;
2513 if (This->pause_time > 0)
2514 time += This->pause_time;
2515 *pCurrent = time;
2516 LeaveCriticalSection(&This->cs);
2518 TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2520 return S_OK;
2523 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2524 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2526 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2528 TRACE("(%p/%p)->(%p, %s, 0x%s, %s)\n", This, iface, pTarget,
2529 debugstr_guid(pTargetFormat), wine_dbgstr_longlong(Source), debugstr_guid(pSourceFormat));
2531 if (!pSourceFormat)
2532 pSourceFormat = &This->timeformatseek;
2534 if (!pTargetFormat)
2535 pTargetFormat = &This->timeformatseek;
2537 if (IsEqualGUID(pTargetFormat, pSourceFormat))
2538 *pTarget = Source;
2539 else
2540 FIXME("conversion %s->%s not supported\n", debugstr_guid(pSourceFormat), debugstr_guid(pTargetFormat));
2542 return S_OK;
2545 struct pos_args {
2546 LONGLONG* current, *stop;
2547 DWORD curflags, stopflags;
2550 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2552 struct pos_args *args = (void*)pargs;
2554 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
2557 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2558 DWORD dwCurrentFlags, LONGLONG *pStop, DWORD dwStopFlags)
2560 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2561 HRESULT hr = S_OK;
2562 FILTER_STATE state;
2563 struct pos_args args;
2565 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
2567 EnterCriticalSection(&This->cs);
2568 state = This->state;
2569 TRACE("State: %s\n", state == State_Running ? "Running" : (state == State_Paused ? "Paused" : (state == State_Stopped ? "Stopped" : "UNKNOWN")));
2571 if ((dwCurrentFlags & 0x7) != AM_SEEKING_AbsolutePositioning &&
2572 (dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2573 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
2575 if ((dwStopFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2576 This->stop_position = *pStop;
2577 else if ((dwStopFlags & 0x7) != AM_SEEKING_NoPositioning)
2578 FIXME("Stop position not handled yet!\n");
2580 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2581 IMediaControl_Pause(&This->IMediaControl_iface);
2582 args.current = pCurrent;
2583 args.stop = pStop;
2584 args.curflags = dwCurrentFlags;
2585 args.stopflags = dwStopFlags;
2586 hr = all_renderers_seek(This, found_setposition, (DWORD_PTR)&args);
2588 if ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2589 This->pause_time = This->start_time = -1;
2590 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2591 IMediaControl_Run(&This->IMediaControl_iface);
2592 LeaveCriticalSection(&This->cs);
2594 return hr;
2597 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2598 LONGLONG *pStop)
2600 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2601 HRESULT hr;
2603 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pCurrent, pStop);
2604 hr = IMediaSeeking_GetCurrentPosition(iface, pCurrent);
2605 if (SUCCEEDED(hr))
2606 hr = IMediaSeeking_GetStopPosition(iface, pStop);
2608 return hr;
2611 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2612 LONGLONG *pLatest)
2614 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2616 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2618 return S_OK;
2621 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2623 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2625 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2627 return S_OK;
2630 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2632 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2634 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2636 if (!pdRate)
2637 return E_POINTER;
2639 *pdRate = 1.0;
2641 return S_OK;
2644 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2646 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2648 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2650 return S_OK;
2654 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2656 MediaSeeking_QueryInterface,
2657 MediaSeeking_AddRef,
2658 MediaSeeking_Release,
2659 MediaSeeking_GetCapabilities,
2660 MediaSeeking_CheckCapabilities,
2661 MediaSeeking_IsFormatSupported,
2662 MediaSeeking_QueryPreferredFormat,
2663 MediaSeeking_GetTimeFormat,
2664 MediaSeeking_IsUsingTimeFormat,
2665 MediaSeeking_SetTimeFormat,
2666 MediaSeeking_GetDuration,
2667 MediaSeeking_GetStopPosition,
2668 MediaSeeking_GetCurrentPosition,
2669 MediaSeeking_ConvertTimeFormat,
2670 MediaSeeking_SetPositions,
2671 MediaSeeking_GetPositions,
2672 MediaSeeking_GetAvailable,
2673 MediaSeeking_SetRate,
2674 MediaSeeking_GetRate,
2675 MediaSeeking_GetPreroll
2678 static inline IFilterGraphImpl *impl_from_IMediaPosition(IMediaPosition *iface)
2680 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaPosition_iface);
2683 /*** IUnknown methods ***/
2684 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj)
2686 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2688 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
2690 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2693 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2695 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2697 TRACE("(%p/%p)->()\n", This, iface);
2699 return IUnknown_AddRef(This->outer_unk);
2702 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2704 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2706 TRACE("(%p/%p)->()\n", This, iface);
2708 return IUnknown_Release(This->outer_unk);
2711 /*** IDispatch methods ***/
2712 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo)
2714 FIXME("(%p) stub!\n", iface);
2715 return E_NOTIMPL;
2718 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
2720 FIXME("(%p) stub!\n", iface);
2721 return E_NOTIMPL;
2724 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
2726 FIXME("(%p) stub!\n", iface);
2727 return E_NOTIMPL;
2730 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2732 FIXME("(%p) stub!\n", iface);
2733 return E_NOTIMPL;
2736 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2738 GUID time_format;
2739 HRESULT hr;
2741 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2742 if (FAILED(hr))
2743 return hr;
2744 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2746 FIXME("Unsupported time format.\n");
2747 return E_NOTIMPL;
2750 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2751 return S_OK;
2754 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2756 GUID time_format;
2757 HRESULT hr;
2759 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2760 if (FAILED(hr))
2761 return hr;
2762 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2764 FIXME("Unsupported time format.\n");
2765 return E_NOTIMPL;
2768 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2769 return S_OK;
2772 /*** IMediaPosition methods ***/
2773 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2775 LONGLONG duration;
2776 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2777 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2778 if (FAILED(hr))
2779 return hr;
2780 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2783 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2785 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2786 LONGLONG reftime;
2787 HRESULT hr;
2789 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2790 if (FAILED(hr))
2791 return hr;
2792 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2793 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2796 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2798 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2799 LONGLONG pos;
2800 HRESULT hr;
2802 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2803 if (FAILED(hr))
2804 return hr;
2805 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2808 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2810 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2811 LONGLONG pos;
2812 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2813 if (FAILED(hr))
2814 return hr;
2815 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2818 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2820 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2821 LONGLONG reftime;
2822 HRESULT hr;
2824 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2825 if (FAILED(hr))
2826 return hr;
2827 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2828 &reftime, AM_SEEKING_AbsolutePositioning);
2831 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime)
2833 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2834 return E_NOTIMPL;
2837 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime)
2839 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2840 return E_NOTIMPL;
2843 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2845 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2846 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2849 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2851 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2852 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2855 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward)
2857 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2858 return E_NOTIMPL;
2861 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward)
2863 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2864 return E_NOTIMPL;
2868 static const IMediaPositionVtbl IMediaPosition_VTable =
2870 MediaPosition_QueryInterface,
2871 MediaPosition_AddRef,
2872 MediaPosition_Release,
2873 MediaPosition_GetTypeInfoCount,
2874 MediaPosition_GetTypeInfo,
2875 MediaPosition_GetIDsOfNames,
2876 MediaPosition_Invoke,
2877 MediaPosition_get_Duration,
2878 MediaPosition_put_CurrentPosition,
2879 MediaPosition_get_CurrentPosition,
2880 MediaPosition_get_StopTime,
2881 MediaPosition_put_StopTime,
2882 MediaPosition_get_PrerollTime,
2883 MediaPosition_put_PrerollTime,
2884 MediaPosition_put_Rate,
2885 MediaPosition_get_Rate,
2886 MediaPosition_CanSeekForward,
2887 MediaPosition_CanSeekBackward
2890 static inline IFilterGraphImpl *impl_from_IObjectWithSite(IObjectWithSite *iface)
2892 return CONTAINING_RECORD(iface, IFilterGraphImpl, IObjectWithSite_iface);
2895 /*** IUnknown methods ***/
2896 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite* iface, REFIID riid, void** ppvObj)
2898 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2900 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
2902 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2905 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
2907 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2909 TRACE("(%p/%p)->()\n", This, iface);
2911 return IUnknown_AddRef(This->outer_unk);
2914 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
2916 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2918 TRACE("(%p/%p)->()\n", This, iface);
2920 return IUnknown_Release(This->outer_unk);
2923 /*** IObjectWithSite methods ***/
2925 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
2927 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2929 TRACE("(%p/%p)->()\n", This, iface);
2930 if (This->pSite) IUnknown_Release(This->pSite);
2931 This->pSite = pUnkSite;
2932 IUnknown_AddRef(This->pSite);
2933 return S_OK;
2936 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, PVOID *ppvSite)
2938 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2940 TRACE("(%p/%p)->(%s)\n", This, iface,debugstr_guid(riid));
2942 *ppvSite = NULL;
2943 if (!This->pSite)
2944 return E_FAIL;
2945 else
2946 return IUnknown_QueryInterface(This->pSite, riid, ppvSite);
2949 static const IObjectWithSiteVtbl IObjectWithSite_VTable =
2951 ObjectWithSite_QueryInterface,
2952 ObjectWithSite_AddRef,
2953 ObjectWithSite_Release,
2954 ObjectWithSite_SetSite,
2955 ObjectWithSite_GetSite,
2958 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2960 HRESULT hr;
2961 int i;
2962 int entry;
2964 /* Check if the interface type is already registered */
2965 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2966 if (riid == pGraph->ItfCacheEntries[entry].riid)
2968 if (pGraph->ItfCacheEntries[entry].iface)
2970 /* Return the interface if available */
2971 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2972 return S_OK;
2974 break;
2977 if (entry >= MAX_ITF_CACHE_ENTRIES)
2979 FIXME("Not enough space to store interface in the cache\n");
2980 return E_OUTOFMEMORY;
2983 /* Find a filter supporting the requested interface */
2984 for (i = 0; i < pGraph->nFilters; i++)
2986 hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2987 if (hr == S_OK)
2989 pGraph->ItfCacheEntries[entry].riid = riid;
2990 pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2991 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2992 if (entry >= pGraph->nItfCacheEntries)
2993 pGraph->nItfCacheEntries++;
2994 return S_OK;
2996 if (hr != E_NOINTERFACE)
2997 return hr;
3000 return IsEqualGUID(riid, &IID_IBasicAudio) ? E_NOTIMPL : E_NOINTERFACE;
3003 static inline IFilterGraphImpl *impl_from_IBasicAudio(IBasicAudio *iface)
3005 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicAudio_iface);
3008 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID riid, void **ppvObj)
3010 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3012 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
3014 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
3017 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
3019 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3021 TRACE("(%p/%p)->()\n", This, iface);
3023 return IUnknown_AddRef(This->outer_unk);
3026 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
3028 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3030 TRACE("(%p/%p)->()\n", This, iface);
3032 return IUnknown_Release(This->outer_unk);
3035 /*** IDispatch methods ***/
3036 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *pctinfo)
3038 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3039 IBasicAudio* pBasicAudio;
3040 HRESULT hr;
3042 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3044 EnterCriticalSection(&This->cs);
3046 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3048 if (hr == S_OK)
3049 hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
3051 LeaveCriticalSection(&This->cs);
3053 return hr;
3056 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT iTInfo, LCID lcid,
3057 ITypeInfo **ppTInfo)
3059 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3060 IBasicAudio* pBasicAudio;
3061 HRESULT hr;
3063 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3065 EnterCriticalSection(&This->cs);
3067 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3069 if (hr == S_OK)
3070 hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
3072 LeaveCriticalSection(&This->cs);
3074 return hr;
3077 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID riid, LPOLESTR *rgszNames,
3078 UINT cNames, LCID lcid, DISPID *rgDispId)
3080 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3081 IBasicAudio* pBasicAudio;
3082 HRESULT hr;
3084 TRACE("(%p/%p)->(%s, %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), rgszNames, cNames,
3085 lcid, rgDispId);
3087 EnterCriticalSection(&This->cs);
3089 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3091 if (hr == S_OK)
3092 hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
3094 LeaveCriticalSection(&This->cs);
3096 return hr;
3099 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID dispIdMember, REFIID riid,
3100 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3101 UINT *puArgErr)
3103 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3104 IBasicAudio* pBasicAudio;
3105 HRESULT hr;
3107 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember,
3108 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3110 EnterCriticalSection(&This->cs);
3112 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3114 if (hr == S_OK)
3115 hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3117 LeaveCriticalSection(&This->cs);
3119 return hr;
3122 /*** IBasicAudio methods ***/
3123 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
3125 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3126 IBasicAudio* pBasicAudio;
3127 HRESULT hr;
3129 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
3131 EnterCriticalSection(&This->cs);
3133 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3135 if (hr == S_OK)
3136 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
3138 LeaveCriticalSection(&This->cs);
3140 return hr;
3143 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
3145 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3146 IBasicAudio* pBasicAudio;
3147 HRESULT hr;
3149 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
3151 EnterCriticalSection(&This->cs);
3153 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3155 if (hr == S_OK)
3156 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
3158 LeaveCriticalSection(&This->cs);
3160 return hr;
3163 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
3165 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3166 IBasicAudio* pBasicAudio;
3167 HRESULT hr;
3169 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
3171 EnterCriticalSection(&This->cs);
3173 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3175 if (hr == S_OK)
3176 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
3178 LeaveCriticalSection(&This->cs);
3180 return hr;
3183 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
3185 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3186 IBasicAudio* pBasicAudio;
3187 HRESULT hr;
3189 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
3191 EnterCriticalSection(&This->cs);
3193 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3195 if (hr == S_OK)
3196 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
3198 LeaveCriticalSection(&This->cs);
3200 return hr;
3203 static const IBasicAudioVtbl IBasicAudio_VTable =
3205 BasicAudio_QueryInterface,
3206 BasicAudio_AddRef,
3207 BasicAudio_Release,
3208 BasicAudio_GetTypeInfoCount,
3209 BasicAudio_GetTypeInfo,
3210 BasicAudio_GetIDsOfNames,
3211 BasicAudio_Invoke,
3212 BasicAudio_put_Volume,
3213 BasicAudio_get_Volume,
3214 BasicAudio_put_Balance,
3215 BasicAudio_get_Balance
3218 static inline IFilterGraphImpl *impl_from_IBasicVideo2(IBasicVideo2 *iface)
3220 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicVideo2_iface);
3223 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID riid, void **ppvObj)
3225 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3227 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
3229 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
3232 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
3234 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3236 TRACE("(%p/%p)->()\n", This, iface);
3238 return IUnknown_AddRef(This->outer_unk);
3241 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
3243 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3245 TRACE("(%p/%p)->()\n", This, iface);
3247 return IUnknown_Release(This->outer_unk);
3250 /*** IDispatch methods ***/
3251 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *pctinfo)
3253 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3254 IBasicVideo *pBasicVideo;
3255 HRESULT hr;
3257 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3259 EnterCriticalSection(&This->cs);
3261 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3263 if (hr == S_OK)
3264 hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
3266 LeaveCriticalSection(&This->cs);
3268 return hr;
3271 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT iTInfo, LCID lcid,
3272 ITypeInfo **ppTInfo)
3274 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3275 IBasicVideo *pBasicVideo;
3276 HRESULT hr;
3278 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3280 EnterCriticalSection(&This->cs);
3282 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3284 if (hr == S_OK)
3285 hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
3287 LeaveCriticalSection(&This->cs);
3289 return hr;
3292 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID riid,
3293 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
3295 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3296 IBasicVideo *pBasicVideo;
3297 HRESULT hr;
3299 TRACE("(%p/%p)->(%s, %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), rgszNames, cNames,
3300 lcid, rgDispId);
3302 EnterCriticalSection(&This->cs);
3304 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3306 if (hr == S_OK)
3307 hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
3309 LeaveCriticalSection(&This->cs);
3311 return hr;
3314 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID dispIdMember, REFIID riid,
3315 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3316 UINT *puArgErr)
3318 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3319 IBasicVideo *pBasicVideo;
3320 HRESULT hr;
3322 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember,
3323 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3325 EnterCriticalSection(&This->cs);
3327 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3329 if (hr == S_OK)
3330 hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3332 LeaveCriticalSection(&This->cs);
3334 return hr;
3337 /*** IBasicVideo methods ***/
3338 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3340 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3341 IBasicVideo *pBasicVideo;
3342 HRESULT hr;
3344 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3346 EnterCriticalSection(&This->cs);
3348 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3350 if (hr == S_OK)
3351 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3353 LeaveCriticalSection(&This->cs);
3355 return hr;
3358 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3360 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3361 IBasicVideo *pBasicVideo;
3362 HRESULT hr;
3364 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3366 EnterCriticalSection(&This->cs);
3368 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3370 if (hr == S_OK)
3371 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3373 LeaveCriticalSection(&This->cs);
3375 return hr;
3378 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3380 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3381 IBasicVideo *pBasicVideo;
3382 HRESULT hr;
3384 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3386 EnterCriticalSection(&This->cs);
3388 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3390 if (hr == S_OK)
3391 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3393 LeaveCriticalSection(&This->cs);
3395 return hr;
3398 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3400 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3401 IBasicVideo *pBasicVideo;
3402 HRESULT hr;
3404 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3406 EnterCriticalSection(&This->cs);
3408 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3410 if (hr == S_OK)
3411 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3413 LeaveCriticalSection(&This->cs);
3415 return hr;
3418 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3420 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3421 IBasicVideo *pBasicVideo;
3422 HRESULT hr;
3424 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3426 EnterCriticalSection(&This->cs);
3428 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3430 if (hr == S_OK)
3431 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3433 LeaveCriticalSection(&This->cs);
3435 return hr;
3438 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3440 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3441 IBasicVideo *pBasicVideo;
3442 HRESULT hr;
3444 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3446 EnterCriticalSection(&This->cs);
3448 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3450 if (hr == S_OK)
3451 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3453 LeaveCriticalSection(&This->cs);
3455 return hr;
3458 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3460 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3461 IBasicVideo *pBasicVideo;
3462 HRESULT hr;
3464 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3466 EnterCriticalSection(&This->cs);
3468 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3470 if (hr == S_OK)
3471 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3473 LeaveCriticalSection(&This->cs);
3475 return hr;
3478 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3480 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3481 IBasicVideo *pBasicVideo;
3482 HRESULT hr;
3484 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3486 EnterCriticalSection(&This->cs);
3488 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3490 if (hr == S_OK)
3491 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3493 LeaveCriticalSection(&This->cs);
3495 return hr;
3498 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3500 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3501 IBasicVideo *pBasicVideo;
3502 HRESULT hr;
3504 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3506 EnterCriticalSection(&This->cs);
3508 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3510 if (hr == S_OK)
3511 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3513 LeaveCriticalSection(&This->cs);
3515 return hr;
3518 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3520 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3521 IBasicVideo *pBasicVideo;
3522 HRESULT hr;
3524 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3526 EnterCriticalSection(&This->cs);
3528 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3530 if (hr == S_OK)
3531 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3533 LeaveCriticalSection(&This->cs);
3535 return hr;
3538 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3540 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3541 IBasicVideo *pBasicVideo;
3542 HRESULT hr;
3544 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3546 EnterCriticalSection(&This->cs);
3548 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3550 if (hr == S_OK)
3551 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3553 LeaveCriticalSection(&This->cs);
3555 return hr;
3558 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3560 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3561 IBasicVideo *pBasicVideo;
3562 HRESULT hr;
3564 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3566 EnterCriticalSection(&This->cs);
3568 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3570 if (hr == S_OK)
3571 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3573 LeaveCriticalSection(&This->cs);
3575 return hr;
3578 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3580 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3581 IBasicVideo *pBasicVideo;
3582 HRESULT hr;
3584 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3586 EnterCriticalSection(&This->cs);
3588 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3590 if (hr == S_OK)
3591 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3593 LeaveCriticalSection(&This->cs);
3595 return hr;
3598 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3600 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3601 IBasicVideo *pBasicVideo;
3602 HRESULT hr;
3604 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3606 EnterCriticalSection(&This->cs);
3608 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3610 if (hr == S_OK)
3611 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3613 LeaveCriticalSection(&This->cs);
3615 return hr;
3618 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3620 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3621 IBasicVideo *pBasicVideo;
3622 HRESULT hr;
3624 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3626 EnterCriticalSection(&This->cs);
3628 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3630 if (hr == S_OK)
3631 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3633 LeaveCriticalSection(&This->cs);
3635 return hr;
3638 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3640 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3641 IBasicVideo *pBasicVideo;
3642 HRESULT hr;
3644 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3646 EnterCriticalSection(&This->cs);
3648 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3650 if (hr == S_OK)
3651 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3653 LeaveCriticalSection(&This->cs);
3655 return hr;
3658 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3660 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3661 IBasicVideo *pBasicVideo;
3662 HRESULT hr;
3664 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3666 EnterCriticalSection(&This->cs);
3668 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3670 if (hr == S_OK)
3671 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3673 LeaveCriticalSection(&This->cs);
3675 return hr;
3678 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3680 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3681 IBasicVideo *pBasicVideo;
3682 HRESULT hr;
3684 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3686 EnterCriticalSection(&This->cs);
3688 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3690 if (hr == S_OK)
3691 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3693 LeaveCriticalSection(&This->cs);
3695 return hr;
3698 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3700 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3701 IBasicVideo *pBasicVideo;
3702 HRESULT hr;
3704 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3706 EnterCriticalSection(&This->cs);
3708 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3710 if (hr == S_OK)
3711 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3713 LeaveCriticalSection(&This->cs);
3715 return hr;
3718 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3720 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3721 IBasicVideo *pBasicVideo;
3722 HRESULT hr;
3724 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3726 EnterCriticalSection(&This->cs);
3728 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3730 if (hr == S_OK)
3731 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3733 LeaveCriticalSection(&This->cs);
3735 return hr;
3738 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3739 LONG *pDestinationHeight)
3741 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3742 IBasicVideo *pBasicVideo;
3743 HRESULT hr;
3745 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3747 EnterCriticalSection(&This->cs);
3749 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3751 if (hr == S_OK)
3752 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3754 LeaveCriticalSection(&This->cs);
3756 return hr;
3759 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3760 LONG Width, LONG Height)
3762 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3763 IBasicVideo *pBasicVideo;
3764 HRESULT hr;
3766 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3768 EnterCriticalSection(&This->cs);
3770 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3772 if (hr == S_OK)
3773 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3775 LeaveCriticalSection(&This->cs);
3777 return hr;
3780 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3781 LONG *pWidth, LONG *pHeight)
3783 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3784 IBasicVideo *pBasicVideo;
3785 HRESULT hr;
3787 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3789 EnterCriticalSection(&This->cs);
3791 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3793 if (hr == S_OK)
3794 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3796 LeaveCriticalSection(&This->cs);
3798 return hr;
3801 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3803 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3804 IBasicVideo *pBasicVideo;
3805 HRESULT hr;
3807 TRACE("(%p/%p)->()\n", This, iface);
3809 EnterCriticalSection(&This->cs);
3811 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3813 if (hr == S_OK)
3814 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3816 LeaveCriticalSection(&This->cs);
3818 return hr;
3821 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3822 LONG Width, LONG Height)
3824 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3825 IBasicVideo *pBasicVideo;
3826 HRESULT hr;
3828 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3830 EnterCriticalSection(&This->cs);
3832 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3834 if (hr == S_OK)
3835 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3837 LeaveCriticalSection(&This->cs);
3839 return hr;
3842 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3843 LONG *pTop, LONG *pWidth, LONG *pHeight)
3845 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3846 IBasicVideo *pBasicVideo;
3847 HRESULT hr;
3849 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3851 EnterCriticalSection(&This->cs);
3853 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3855 if (hr == S_OK)
3856 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3858 LeaveCriticalSection(&This->cs);
3860 return hr;
3863 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3865 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3866 IBasicVideo *pBasicVideo;
3867 HRESULT hr;
3869 TRACE("(%p/%p)->()\n", This, iface);
3871 EnterCriticalSection(&This->cs);
3873 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3875 if (hr == S_OK)
3876 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3878 LeaveCriticalSection(&This->cs);
3880 return hr;
3883 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3885 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3886 IBasicVideo *pBasicVideo;
3887 HRESULT hr;
3889 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3891 EnterCriticalSection(&This->cs);
3893 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3895 if (hr == S_OK)
3896 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3898 LeaveCriticalSection(&This->cs);
3900 return hr;
3903 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3904 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3906 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3907 IBasicVideo *pBasicVideo;
3908 HRESULT hr;
3910 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3912 EnterCriticalSection(&This->cs);
3914 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3916 if (hr == S_OK)
3917 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3919 LeaveCriticalSection(&This->cs);
3921 return hr;
3924 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3925 LONG *pDIBImage)
3927 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3928 IBasicVideo *pBasicVideo;
3929 HRESULT hr;
3931 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3933 EnterCriticalSection(&This->cs);
3935 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3937 if (hr == S_OK)
3938 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3940 LeaveCriticalSection(&This->cs);
3942 return hr;
3945 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3947 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3948 IBasicVideo *pBasicVideo;
3949 HRESULT hr;
3951 TRACE("(%p/%p)->()\n", This, iface);
3953 EnterCriticalSection(&This->cs);
3955 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3957 if (hr == S_OK)
3958 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3960 LeaveCriticalSection(&This->cs);
3962 return hr;
3965 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3967 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3968 IBasicVideo *pBasicVideo;
3969 HRESULT hr;
3971 TRACE("(%p/%p)->()\n", This, iface);
3973 EnterCriticalSection(&This->cs);
3975 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3977 if (hr == S_OK)
3978 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3980 LeaveCriticalSection(&This->cs);
3982 return hr;
3985 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3986 LONG *plAspectY)
3988 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3989 IBasicVideo2 *pBasicVideo2;
3990 HRESULT hr;
3992 TRACE("(%p/%p)->()\n", This, iface);
3994 EnterCriticalSection(&This->cs);
3996 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3998 if (hr == S_OK)
3999 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
4001 LeaveCriticalSection(&This->cs);
4003 return hr;
4006 static const IBasicVideo2Vtbl IBasicVideo_VTable =
4008 BasicVideo_QueryInterface,
4009 BasicVideo_AddRef,
4010 BasicVideo_Release,
4011 BasicVideo_GetTypeInfoCount,
4012 BasicVideo_GetTypeInfo,
4013 BasicVideo_GetIDsOfNames,
4014 BasicVideo_Invoke,
4015 BasicVideo_get_AvgTimePerFrame,
4016 BasicVideo_get_BitRate,
4017 BasicVideo_get_BitErrorRate,
4018 BasicVideo_get_VideoWidth,
4019 BasicVideo_get_VideoHeight,
4020 BasicVideo_put_SourceLeft,
4021 BasicVideo_get_SourceLeft,
4022 BasicVideo_put_SourceWidth,
4023 BasicVideo_get_SourceWidth,
4024 BasicVideo_put_SourceTop,
4025 BasicVideo_get_SourceTop,
4026 BasicVideo_put_SourceHeight,
4027 BasicVideo_get_SourceHeight,
4028 BasicVideo_put_DestinationLeft,
4029 BasicVideo_get_DestinationLeft,
4030 BasicVideo_put_DestinationWidth,
4031 BasicVideo_get_DestinationWidth,
4032 BasicVideo_put_DestinationTop,
4033 BasicVideo_get_DestinationTop,
4034 BasicVideo_put_DestinationHeight,
4035 BasicVideo_get_DestinationHeight,
4036 BasicVideo_SetSourcePosition,
4037 BasicVideo_GetSourcePosition,
4038 BasicVideo_SetDefaultSourcePosition,
4039 BasicVideo_SetDestinationPosition,
4040 BasicVideo_GetDestinationPosition,
4041 BasicVideo_SetDefaultDestinationPosition,
4042 BasicVideo_GetVideoSize,
4043 BasicVideo_GetVideoPaletteEntries,
4044 BasicVideo_GetCurrentImage,
4045 BasicVideo_IsUsingDefaultSource,
4046 BasicVideo_IsUsingDefaultDestination,
4047 BasicVideo2_GetPreferredAspectRatio
4050 static inline IFilterGraphImpl *impl_from_IVideoWindow(IVideoWindow *iface)
4052 return CONTAINING_RECORD(iface, IFilterGraphImpl, IVideoWindow_iface);
4055 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID riid, void **ppvObj)
4057 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4059 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
4061 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
4064 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
4066 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4068 TRACE("(%p/%p)->()\n", This, iface);
4070 return IUnknown_AddRef(This->outer_unk);
4073 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
4075 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4077 TRACE("(%p/%p)->()\n", This, iface);
4079 return IUnknown_Release(This->outer_unk);
4082 /*** IDispatch methods ***/
4083 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *pctinfo)
4085 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4086 IVideoWindow *pVideoWindow;
4087 HRESULT hr;
4089 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
4091 EnterCriticalSection(&This->cs);
4093 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4095 if (hr == S_OK)
4096 hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
4098 LeaveCriticalSection(&This->cs);
4100 return hr;
4103 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT iTInfo, LCID lcid,
4104 ITypeInfo **ppTInfo)
4106 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4107 IVideoWindow *pVideoWindow;
4108 HRESULT hr;
4110 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
4112 EnterCriticalSection(&This->cs);
4114 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4116 if (hr == S_OK)
4117 hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
4119 LeaveCriticalSection(&This->cs);
4121 return hr;
4124 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID riid,
4125 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4127 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4128 IVideoWindow *pVideoWindow;
4129 HRESULT hr;
4131 TRACE("(%p/%p)->(%s, %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), rgszNames, cNames,
4132 lcid, rgDispId);
4134 EnterCriticalSection(&This->cs);
4136 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4138 if (hr == S_OK)
4139 hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
4141 LeaveCriticalSection(&This->cs);
4143 return hr;
4146 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID dispIdMember, REFIID riid,
4147 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4148 UINT*puArgErr)
4150 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4151 IVideoWindow *pVideoWindow;
4152 HRESULT hr;
4154 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember,
4155 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4157 EnterCriticalSection(&This->cs);
4159 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4161 if (hr == S_OK)
4162 hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4164 LeaveCriticalSection(&This->cs);
4166 return hr;
4170 /*** IVideoWindow methods ***/
4171 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
4173 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4174 IVideoWindow *pVideoWindow;
4175 HRESULT hr;
4177 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
4179 EnterCriticalSection(&This->cs);
4181 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4183 if (hr == S_OK)
4184 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
4186 LeaveCriticalSection(&This->cs);
4188 return hr;
4191 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
4193 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4194 IVideoWindow *pVideoWindow;
4195 HRESULT hr;
4197 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
4199 EnterCriticalSection(&This->cs);
4201 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4203 if (hr == S_OK)
4204 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
4206 LeaveCriticalSection(&This->cs);
4208 return hr;
4211 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
4213 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4214 IVideoWindow *pVideoWindow;
4215 HRESULT hr;
4217 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
4219 EnterCriticalSection(&This->cs);
4221 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4223 if (hr == S_OK)
4224 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
4226 LeaveCriticalSection(&This->cs);
4228 return hr;
4231 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
4233 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4234 IVideoWindow *pVideoWindow;
4235 HRESULT hr;
4237 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
4239 EnterCriticalSection(&This->cs);
4241 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4243 if (hr == S_OK)
4244 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
4246 LeaveCriticalSection(&This->cs);
4248 return hr;
4251 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
4253 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4254 IVideoWindow *pVideoWindow;
4255 HRESULT hr;
4257 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
4259 EnterCriticalSection(&This->cs);
4261 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4263 if (hr == S_OK)
4264 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
4266 LeaveCriticalSection(&This->cs);
4268 return hr;
4271 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
4273 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4274 IVideoWindow *pVideoWindow;
4275 HRESULT hr;
4277 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
4279 EnterCriticalSection(&This->cs);
4281 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4283 if (hr == S_OK)
4284 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
4286 LeaveCriticalSection(&This->cs);
4288 return hr;
4291 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
4293 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4294 IVideoWindow *pVideoWindow;
4295 HRESULT hr;
4297 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
4299 EnterCriticalSection(&This->cs);
4301 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4303 if (hr == S_OK)
4304 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4306 LeaveCriticalSection(&This->cs);
4308 return hr;
4311 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
4313 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4314 IVideoWindow *pVideoWindow;
4315 HRESULT hr;
4317 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4319 EnterCriticalSection(&This->cs);
4321 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4323 if (hr == S_OK)
4324 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4326 LeaveCriticalSection(&This->cs);
4328 return hr;
4331 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
4333 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4334 IVideoWindow *pVideoWindow;
4335 HRESULT hr;
4337 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4339 EnterCriticalSection(&This->cs);
4341 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4343 if (hr == S_OK)
4344 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4346 LeaveCriticalSection(&This->cs);
4348 return hr;
4351 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4353 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4354 IVideoWindow *pVideoWindow;
4355 HRESULT hr;
4357 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4359 EnterCriticalSection(&This->cs);
4361 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4363 if (hr == S_OK)
4364 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4366 LeaveCriticalSection(&This->cs);
4368 return hr;
4371 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4373 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4374 IVideoWindow *pVideoWindow;
4375 HRESULT hr;
4377 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4379 EnterCriticalSection(&This->cs);
4381 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4383 if (hr == S_OK)
4384 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4386 LeaveCriticalSection(&This->cs);
4388 return hr;
4391 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4392 LONG *pBackgroundPalette)
4394 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4395 IVideoWindow *pVideoWindow;
4396 HRESULT hr;
4398 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4400 EnterCriticalSection(&This->cs);
4402 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4404 if (hr == S_OK)
4405 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4407 LeaveCriticalSection(&This->cs);
4409 return hr;
4412 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4414 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4415 IVideoWindow *pVideoWindow;
4416 HRESULT hr;
4418 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4420 EnterCriticalSection(&This->cs);
4422 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4424 if (hr == S_OK)
4425 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4427 LeaveCriticalSection(&This->cs);
4429 return hr;
4432 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4434 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4435 IVideoWindow *pVideoWindow;
4436 HRESULT hr;
4438 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4440 EnterCriticalSection(&This->cs);
4442 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4444 if (hr == S_OK)
4445 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4447 LeaveCriticalSection(&This->cs);
4449 return hr;
4452 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4454 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4455 IVideoWindow *pVideoWindow;
4456 HRESULT hr;
4458 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4460 EnterCriticalSection(&This->cs);
4462 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4464 if (hr == S_OK)
4465 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4467 LeaveCriticalSection(&This->cs);
4469 return hr;
4472 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4474 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4475 IVideoWindow *pVideoWindow;
4476 HRESULT hr;
4478 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4480 EnterCriticalSection(&This->cs);
4482 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4484 if (hr == S_OK)
4485 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4487 LeaveCriticalSection(&This->cs);
4489 return hr;
4492 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4494 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4495 IVideoWindow *pVideoWindow;
4496 HRESULT hr;
4498 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4500 EnterCriticalSection(&This->cs);
4502 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4504 if (hr == S_OK)
4505 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4507 LeaveCriticalSection(&This->cs);
4509 return hr;
4512 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4514 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4515 IVideoWindow *pVideoWindow;
4516 HRESULT hr;
4518 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4520 EnterCriticalSection(&This->cs);
4522 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4524 if (hr == S_OK)
4525 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4527 LeaveCriticalSection(&This->cs);
4529 return hr;
4532 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4534 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4535 IVideoWindow *pVideoWindow;
4536 HRESULT hr;
4538 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4540 EnterCriticalSection(&This->cs);
4542 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4544 if (hr == S_OK)
4545 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4547 LeaveCriticalSection(&This->cs);
4549 return hr;
4552 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4554 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4555 IVideoWindow *pVideoWindow;
4556 HRESULT hr;
4558 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4560 EnterCriticalSection(&This->cs);
4562 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4564 if (hr == S_OK)
4565 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4567 LeaveCriticalSection(&This->cs);
4569 return hr;
4572 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4574 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4575 IVideoWindow *pVideoWindow;
4576 HRESULT hr;
4578 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4580 EnterCriticalSection(&This->cs);
4582 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4584 if (hr == S_OK)
4585 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4587 LeaveCriticalSection(&This->cs);
4589 return hr;
4592 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4594 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4595 IVideoWindow *pVideoWindow;
4596 HRESULT hr;
4598 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4600 EnterCriticalSection(&This->cs);
4602 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4604 if (hr == S_OK)
4605 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4607 LeaveCriticalSection(&This->cs);
4609 return hr;
4612 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4614 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4615 IVideoWindow *pVideoWindow;
4616 HRESULT hr;
4618 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4620 EnterCriticalSection(&This->cs);
4622 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4624 if (hr == S_OK)
4625 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4627 LeaveCriticalSection(&This->cs);
4629 return hr;
4632 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4634 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4635 IVideoWindow *pVideoWindow;
4636 HRESULT hr;
4638 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4640 EnterCriticalSection(&This->cs);
4642 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4644 if (hr == S_OK)
4645 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4647 LeaveCriticalSection(&This->cs);
4649 return hr;
4652 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4654 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4655 IVideoWindow *pVideoWindow;
4656 HRESULT hr;
4658 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4660 EnterCriticalSection(&This->cs);
4662 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4664 if (hr == S_OK)
4665 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4667 LeaveCriticalSection(&This->cs);
4669 return hr;
4672 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4674 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4675 IVideoWindow *pVideoWindow;
4676 HRESULT hr;
4678 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4680 EnterCriticalSection(&This->cs);
4682 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4684 if (hr == S_OK)
4685 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4687 LeaveCriticalSection(&This->cs);
4689 return hr;
4692 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4694 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4695 IVideoWindow *pVideoWindow;
4696 HRESULT hr;
4698 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4700 EnterCriticalSection(&This->cs);
4702 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4704 if (hr == S_OK)
4705 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4707 LeaveCriticalSection(&This->cs);
4709 return hr;
4712 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4714 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4715 IVideoWindow *pVideoWindow;
4716 HRESULT hr;
4718 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4720 EnterCriticalSection(&This->cs);
4722 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4724 if (hr == S_OK)
4725 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4727 LeaveCriticalSection(&This->cs);
4729 return hr;
4732 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4734 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4735 IVideoWindow *pVideoWindow;
4736 HRESULT hr;
4738 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4740 EnterCriticalSection(&This->cs);
4742 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4744 if (hr == S_OK)
4745 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4747 LeaveCriticalSection(&This->cs);
4749 return hr;
4752 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4754 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4755 IVideoWindow *pVideoWindow;
4756 HRESULT hr;
4758 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4760 EnterCriticalSection(&This->cs);
4762 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4764 if (hr == S_OK)
4765 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4767 LeaveCriticalSection(&This->cs);
4769 return hr;
4772 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4774 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4775 IVideoWindow *pVideoWindow;
4776 HRESULT hr;
4778 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4780 EnterCriticalSection(&This->cs);
4782 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4784 if (hr == S_OK)
4785 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4787 LeaveCriticalSection(&This->cs);
4789 return hr;
4792 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4793 LONG_PTR wParam, LONG_PTR lParam)
4795 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4796 IVideoWindow *pVideoWindow;
4797 HRESULT hr;
4799 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4801 EnterCriticalSection(&This->cs);
4803 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4805 if (hr == S_OK)
4806 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4808 LeaveCriticalSection(&This->cs);
4810 return hr;
4813 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4814 LONG Width, LONG Height)
4816 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4817 IVideoWindow *pVideoWindow;
4818 HRESULT hr;
4820 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4822 EnterCriticalSection(&This->cs);
4824 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4826 if (hr == S_OK)
4827 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4829 LeaveCriticalSection(&This->cs);
4831 return hr;
4834 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4835 LONG *pWidth, LONG *pHeight)
4837 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4838 IVideoWindow *pVideoWindow;
4839 HRESULT hr;
4841 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4843 EnterCriticalSection(&This->cs);
4845 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4847 if (hr == S_OK)
4848 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4850 LeaveCriticalSection(&This->cs);
4852 return hr;
4855 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4856 LONG *pHeight)
4858 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4859 IVideoWindow *pVideoWindow;
4860 HRESULT hr;
4862 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4864 EnterCriticalSection(&This->cs);
4866 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4868 if (hr == S_OK)
4869 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4871 LeaveCriticalSection(&This->cs);
4873 return hr;
4876 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4877 LONG *pHeight)
4879 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4880 IVideoWindow *pVideoWindow;
4881 HRESULT hr;
4883 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4885 EnterCriticalSection(&This->cs);
4887 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4889 if (hr == S_OK)
4890 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4892 LeaveCriticalSection(&This->cs);
4894 return hr;
4897 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4898 LONG *pWidth, LONG *pHeight)
4900 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4901 IVideoWindow *pVideoWindow;
4902 HRESULT hr;
4904 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4906 EnterCriticalSection(&This->cs);
4908 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4910 if (hr == S_OK)
4911 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4913 LeaveCriticalSection(&This->cs);
4915 return hr;
4918 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4920 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4921 IVideoWindow *pVideoWindow;
4922 HRESULT hr;
4924 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4926 EnterCriticalSection(&This->cs);
4928 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4930 if (hr == S_OK)
4931 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4933 LeaveCriticalSection(&This->cs);
4935 return hr;
4938 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4940 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4941 IVideoWindow *pVideoWindow;
4942 HRESULT hr;
4944 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4946 EnterCriticalSection(&This->cs);
4948 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4950 if (hr == S_OK)
4951 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4953 LeaveCriticalSection(&This->cs);
4955 return hr;
4959 static const IVideoWindowVtbl IVideoWindow_VTable =
4961 VideoWindow_QueryInterface,
4962 VideoWindow_AddRef,
4963 VideoWindow_Release,
4964 VideoWindow_GetTypeInfoCount,
4965 VideoWindow_GetTypeInfo,
4966 VideoWindow_GetIDsOfNames,
4967 VideoWindow_Invoke,
4968 VideoWindow_put_Caption,
4969 VideoWindow_get_Caption,
4970 VideoWindow_put_WindowStyle,
4971 VideoWindow_get_WindowStyle,
4972 VideoWindow_put_WindowStyleEx,
4973 VideoWindow_get_WindowStyleEx,
4974 VideoWindow_put_AutoShow,
4975 VideoWindow_get_AutoShow,
4976 VideoWindow_put_WindowState,
4977 VideoWindow_get_WindowState,
4978 VideoWindow_put_BackgroundPalette,
4979 VideoWindow_get_BackgroundPalette,
4980 VideoWindow_put_Visible,
4981 VideoWindow_get_Visible,
4982 VideoWindow_put_Left,
4983 VideoWindow_get_Left,
4984 VideoWindow_put_Width,
4985 VideoWindow_get_Width,
4986 VideoWindow_put_Top,
4987 VideoWindow_get_Top,
4988 VideoWindow_put_Height,
4989 VideoWindow_get_Height,
4990 VideoWindow_put_Owner,
4991 VideoWindow_get_Owner,
4992 VideoWindow_put_MessageDrain,
4993 VideoWindow_get_MessageDrain,
4994 VideoWindow_get_BorderColor,
4995 VideoWindow_put_BorderColor,
4996 VideoWindow_get_FullScreenMode,
4997 VideoWindow_put_FullScreenMode,
4998 VideoWindow_SetWindowForeground,
4999 VideoWindow_NotifyOwnerMessage,
5000 VideoWindow_SetWindowPosition,
5001 VideoWindow_GetWindowPosition,
5002 VideoWindow_GetMinIdealImageSize,
5003 VideoWindow_GetMaxIdealImageSize,
5004 VideoWindow_GetRestorePosition,
5005 VideoWindow_HideCursor,
5006 VideoWindow_IsCursorHidden
5009 static inline IFilterGraphImpl *impl_from_IMediaEventEx(IMediaEventEx *iface)
5011 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventEx_iface);
5014 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID riid, void **ppvObj)
5016 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5018 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
5020 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
5023 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
5025 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5027 TRACE("(%p/%p)->()\n", This, iface);
5029 return IUnknown_AddRef(This->outer_unk);
5032 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
5034 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5036 TRACE("(%p/%p)->()\n", This, iface);
5038 return IUnknown_Release(This->outer_unk);
5041 /*** IDispatch methods ***/
5042 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *pctinfo)
5044 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5046 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
5048 return S_OK;
5051 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT iTInfo, LCID lcid,
5052 ITypeInfo **ppTInfo)
5054 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5056 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
5058 return S_OK;
5061 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID riid,
5062 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
5064 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5066 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
5067 cNames, lcid, rgDispId);
5069 return S_OK;
5072 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID dispIdMember, REFIID riid,
5073 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
5074 UINT *puArgErr)
5076 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5078 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
5079 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
5081 return S_OK;
5084 /*** IMediaEvent methods ***/
5085 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *hEvent)
5087 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5089 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
5091 *hEvent = (OAEVENT)This->evqueue.msg_event;
5093 return S_OK;
5096 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *lEventCode, LONG_PTR *lParam1,
5097 LONG_PTR *lParam2, LONG msTimeout)
5099 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5100 Event evt;
5102 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
5104 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
5106 *lEventCode = evt.lEventCode;
5107 *lParam1 = evt.lParam1;
5108 *lParam2 = evt.lParam2;
5109 return S_OK;
5112 *lEventCode = 0;
5113 return E_ABORT;
5116 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
5117 LONG *pEvCode)
5119 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5121 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
5123 if (This->state != State_Running)
5124 return VFW_E_WRONG_STATE;
5126 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
5128 *pEvCode = This->CompletionStatus;
5129 return S_OK;
5132 *pEvCode = 0;
5133 return E_ABORT;
5136 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5138 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5140 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5142 if (lEvCode == EC_COMPLETE)
5143 This->HandleEcComplete = FALSE;
5144 else if (lEvCode == EC_REPAINT)
5145 This->HandleEcRepaint = FALSE;
5146 else if (lEvCode == EC_CLOCK_CHANGED)
5147 This->HandleEcClockChanged = FALSE;
5148 else
5149 return S_FALSE;
5151 return S_OK;
5154 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5156 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5158 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5160 if (lEvCode == EC_COMPLETE)
5161 This->HandleEcComplete = TRUE;
5162 else if (lEvCode == EC_REPAINT)
5163 This->HandleEcRepaint = TRUE;
5164 else if (lEvCode == EC_CLOCK_CHANGED)
5165 This->HandleEcClockChanged = TRUE;
5166 else
5167 return S_FALSE;
5169 return S_OK;
5172 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG lEvCode,
5173 LONG_PTR lParam1, LONG_PTR lParam2)
5175 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5177 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
5179 return S_OK;
5182 /*** IMediaEventEx methods ***/
5183 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface, OAHWND hwnd, LONG lMsg,
5184 LONG_PTR lInstanceData)
5186 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5188 TRACE("(%p/%p)->(%08lx, %d, %08lx)\n", This, iface, hwnd, lMsg, lInstanceData);
5190 This->notif.hWnd = (HWND)hwnd;
5191 This->notif.msg = lMsg;
5192 This->notif.instance = lInstanceData;
5194 return S_OK;
5197 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG lNoNotifyFlags)
5199 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5201 TRACE("(%p/%p)->(%d)\n", This, iface, lNoNotifyFlags);
5203 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
5204 return E_INVALIDARG;
5206 This->notif.disabled = lNoNotifyFlags;
5208 return S_OK;
5211 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *lplNoNotifyFlags)
5213 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5215 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
5217 if (!lplNoNotifyFlags)
5218 return E_POINTER;
5220 *lplNoNotifyFlags = This->notif.disabled;
5222 return S_OK;
5226 static const IMediaEventExVtbl IMediaEventEx_VTable =
5228 MediaEvent_QueryInterface,
5229 MediaEvent_AddRef,
5230 MediaEvent_Release,
5231 MediaEvent_GetTypeInfoCount,
5232 MediaEvent_GetTypeInfo,
5233 MediaEvent_GetIDsOfNames,
5234 MediaEvent_Invoke,
5235 MediaEvent_GetEventHandle,
5236 MediaEvent_GetEvent,
5237 MediaEvent_WaitForCompletion,
5238 MediaEvent_CancelDefaultHandling,
5239 MediaEvent_RestoreDefaultHandling,
5240 MediaEvent_FreeEventParams,
5241 MediaEvent_SetNotifyWindow,
5242 MediaEvent_SetNotifyFlags,
5243 MediaEvent_GetNotifyFlags
5247 static inline IFilterGraphImpl *impl_from_IMediaFilter(IMediaFilter *iface)
5249 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaFilter_iface);
5252 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, void **ppv)
5254 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5256 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5259 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
5261 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5263 return IUnknown_AddRef(This->outer_unk);
5266 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
5268 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5270 return IUnknown_Release(This->outer_unk);
5273 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
5275 FIXME("(%p): stub\n", pClassID);
5277 return E_NOTIMPL;
5280 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
5282 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5284 return MediaControl_Stop(&This->IMediaControl_iface);
5287 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5289 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5291 return MediaControl_Pause(&This->IMediaControl_iface);
5294 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
5296 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5298 if (tStart)
5299 FIXME("Run called with non-null tStart: %s\n", wine_dbgstr_longlong(tStart));
5301 return MediaControl_Run(&This->IMediaControl_iface);
5304 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout,
5305 FILTER_STATE *pState)
5307 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5309 return MediaControl_GetState(&This->IMediaControl_iface, dwMsTimeout, (OAFilterState*)pState);
5312 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5314 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5315 HRESULT hr = S_OK;
5316 int i;
5318 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
5320 EnterCriticalSection(&This->cs);
5322 for (i = 0;i < This->nFilters;i++)
5324 hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5325 if (FAILED(hr))
5326 break;
5329 if (FAILED(hr))
5331 for(;i >= 0;i--)
5332 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5334 else
5336 if (This->refClock)
5337 IReferenceClock_Release(This->refClock);
5338 This->refClock = pClock;
5339 if (This->refClock)
5340 IReferenceClock_AddRef(This->refClock);
5341 This->defaultclock = FALSE;
5343 if (This->HandleEcClockChanged)
5345 IMediaEventSink *pEventSink;
5346 HRESULT eshr;
5348 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (void **)&pEventSink);
5349 if (SUCCEEDED(eshr))
5351 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5352 IMediaEventSink_Release(pEventSink);
5357 LeaveCriticalSection(&This->cs);
5359 return hr;
5362 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5364 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5366 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
5368 if (!ppClock)
5369 return E_POINTER;
5371 EnterCriticalSection(&This->cs);
5373 *ppClock = This->refClock;
5374 if (*ppClock)
5375 IReferenceClock_AddRef(*ppClock);
5377 LeaveCriticalSection(&This->cs);
5379 return S_OK;
5382 static const IMediaFilterVtbl IMediaFilter_VTable =
5384 MediaFilter_QueryInterface,
5385 MediaFilter_AddRef,
5386 MediaFilter_Release,
5387 MediaFilter_GetClassID,
5388 MediaFilter_Stop,
5389 MediaFilter_Pause,
5390 MediaFilter_Run,
5391 MediaFilter_GetState,
5392 MediaFilter_SetSyncSource,
5393 MediaFilter_GetSyncSource
5396 static inline IFilterGraphImpl *impl_from_IMediaEventSink(IMediaEventSink *iface)
5398 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventSink_iface);
5401 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, void **ppv)
5403 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5405 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5408 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5410 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5412 return IUnknown_AddRef(This->outer_unk);
5415 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5417 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5419 return IUnknown_Release(This->outer_unk);
5422 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG EventCode,
5423 LONG_PTR EventParam1, LONG_PTR EventParam2)
5425 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5426 Event evt;
5428 TRACE("(%p/%p)->(%d, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5430 /* We need thread safety here, let's use the events queue's one */
5431 EnterCriticalSection(&This->evqueue.msg_crst);
5433 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5435 TRACE("Process EC_COMPLETE notification\n");
5436 if (++This->EcCompleteCount == This->nRenderers)
5438 evt.lEventCode = EC_COMPLETE;
5439 evt.lParam1 = S_OK;
5440 evt.lParam2 = 0;
5441 TRACE("Send EC_COMPLETE to app\n");
5442 EventsQueue_PutEvent(&This->evqueue, &evt);
5443 if (!This->notif.disabled && This->notif.hWnd)
5445 TRACE("Send Window message\n");
5446 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5448 This->CompletionStatus = EC_COMPLETE;
5449 SetEvent(This->hEventCompletion);
5452 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5454 /* FIXME: Not handled yet */
5456 else
5458 evt.lEventCode = EventCode;
5459 evt.lParam1 = EventParam1;
5460 evt.lParam2 = EventParam2;
5461 EventsQueue_PutEvent(&This->evqueue, &evt);
5462 if (!This->notif.disabled && This->notif.hWnd)
5463 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5466 LeaveCriticalSection(&This->evqueue.msg_crst);
5467 return S_OK;
5470 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5472 MediaEventSink_QueryInterface,
5473 MediaEventSink_AddRef,
5474 MediaEventSink_Release,
5475 MediaEventSink_Notify
5478 static inline IFilterGraphImpl *impl_from_IGraphConfig(IGraphConfig *iface)
5480 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphConfig_iface);
5483 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, void **ppv)
5485 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5487 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5490 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5492 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5494 return IUnknown_AddRef(This->outer_unk);
5497 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5499 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5501 return IUnknown_Release(This->outer_unk);
5504 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *pOutputPin, IPin *pInputPin,
5505 const AM_MEDIA_TYPE *pmtFirstConnection, IBaseFilter *pUsingFilter, HANDLE hAbortEvent,
5506 DWORD dwFlags)
5508 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5510 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5512 return E_NOTIMPL;
5515 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface, IGraphConfigCallback *pCallback,
5516 void *pvContext, DWORD dwFlags, HANDLE hAbortEvent)
5518 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5519 HRESULT hr;
5521 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5523 if (hAbortEvent)
5524 FIXME("The parameter hAbortEvent is not handled!\n");
5526 EnterCriticalSection(&This->cs);
5528 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5530 LeaveCriticalSection(&This->cs);
5532 return hr;
5535 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5537 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5539 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5541 return E_NOTIMPL;
5544 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5546 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5548 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5550 return E_NOTIMPL;
5553 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5555 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5557 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5559 return E_NOTIMPL;
5562 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5564 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5566 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5568 return E_NOTIMPL;
5571 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5572 IPinConnection *pConnection, HANDLE hEventAbort)
5574 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5576 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5578 return E_NOTIMPL;
5581 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5582 DWORD dwFlags)
5584 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5586 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5588 return E_NOTIMPL;
5591 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5592 DWORD *dwFlags)
5594 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5596 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5598 return E_NOTIMPL;
5601 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *pFilter,
5602 DWORD dwFlags)
5604 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5606 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5608 return E_NOTIMPL;
5611 static const IGraphConfigVtbl IGraphConfig_VTable =
5613 GraphConfig_QueryInterface,
5614 GraphConfig_AddRef,
5615 GraphConfig_Release,
5616 GraphConfig_Reconnect,
5617 GraphConfig_Reconfigure,
5618 GraphConfig_AddFilterToCache,
5619 GraphConfig_EnumCacheFilter,
5620 GraphConfig_RemoveFilterFromCache,
5621 GraphConfig_GetStartTime,
5622 GraphConfig_PushThroughData,
5623 GraphConfig_SetFilterFlags,
5624 GraphConfig_GetFilterFlags,
5625 GraphConfig_RemoveFilterEx
5628 static inline IFilterGraphImpl *impl_from_IGraphVersion(IGraphVersion *iface)
5630 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphVersion_iface);
5633 static HRESULT WINAPI GraphVersion_QueryInterface(IGraphVersion *iface, REFIID riid, void **ppv)
5635 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5637 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5640 static ULONG WINAPI GraphVersion_AddRef(IGraphVersion *iface)
5642 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5644 return IUnknown_AddRef(This->outer_unk);
5647 static ULONG WINAPI GraphVersion_Release(IGraphVersion *iface)
5649 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5651 return IUnknown_Release(This->outer_unk);
5654 static HRESULT WINAPI GraphVersion_QueryVersion(IGraphVersion *iface, LONG *pVersion)
5656 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5658 if(!pVersion)
5659 return E_POINTER;
5661 TRACE("(%p)->(%p): current version %i\n", This, pVersion, This->version);
5663 *pVersion = This->version;
5664 return S_OK;
5667 static const IGraphVersionVtbl IGraphVersion_VTable =
5669 GraphVersion_QueryInterface,
5670 GraphVersion_AddRef,
5671 GraphVersion_Release,
5672 GraphVersion_QueryVersion,
5675 static const IUnknownVtbl IInner_VTable =
5677 FilterGraphInner_QueryInterface,
5678 FilterGraphInner_AddRef,
5679 FilterGraphInner_Release
5682 /* This is the only function that actually creates a FilterGraph class... */
5683 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5685 IFilterGraphImpl *fimpl;
5686 HRESULT hr;
5688 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5690 *ppObj = NULL;
5692 fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5693 fimpl->defaultclock = TRUE;
5694 fimpl->IUnknown_inner.lpVtbl = &IInner_VTable;
5695 fimpl->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5696 fimpl->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5697 fimpl->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5698 fimpl->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5699 fimpl->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5700 fimpl->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5701 fimpl->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5702 fimpl->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5703 fimpl->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5704 fimpl->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5705 fimpl->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5706 fimpl->IObjectWithSite_iface.lpVtbl = &IObjectWithSite_VTable;
5707 fimpl->IGraphVersion_iface.lpVtbl = &IGraphVersion_VTable;
5708 fimpl->ref = 1;
5709 fimpl->ppFiltersInGraph = NULL;
5710 fimpl->pFilterNames = NULL;
5711 fimpl->nFilters = 0;
5712 fimpl->filterCapacity = 0;
5713 fimpl->nameIndex = 1;
5714 fimpl->refClock = NULL;
5715 fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5716 fimpl->HandleEcComplete = TRUE;
5717 fimpl->HandleEcRepaint = TRUE;
5718 fimpl->HandleEcClockChanged = TRUE;
5719 fimpl->notif.hWnd = 0;
5720 fimpl->notif.disabled = FALSE;
5721 fimpl->nRenderers = 0;
5722 fimpl->EcCompleteCount = 0;
5723 fimpl->refClockProvider = NULL;
5724 fimpl->state = State_Stopped;
5725 fimpl->pSite = NULL;
5726 EventsQueue_Init(&fimpl->evqueue);
5727 InitializeCriticalSection(&fimpl->cs);
5728 fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5729 fimpl->nItfCacheEntries = 0;
5730 memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5731 fimpl->start_time = fimpl->pause_time = 0;
5732 fimpl->stop_position = -1;
5733 fimpl->punkFilterMapper2 = NULL;
5734 fimpl->recursioncount = 0;
5735 fimpl->version = 0;
5737 if (pUnkOuter)
5738 fimpl->outer_unk = pUnkOuter;
5739 else
5740 fimpl->outer_unk = &fimpl->IUnknown_inner;
5742 /* create Filtermapper aggregated. */
5743 hr = CoCreateInstance(&CLSID_FilterMapper2, fimpl->outer_unk, CLSCTX_INPROC_SERVER,
5744 &IID_IUnknown, (void**)&fimpl->punkFilterMapper2);
5746 if (FAILED(hr)) {
5747 ERR("Unable to create filter mapper (%x)\n", hr);
5748 if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5749 CloseHandle(fimpl->hEventCompletion);
5750 EventsQueue_Destroy(&fimpl->evqueue);
5751 fimpl->cs.DebugInfo->Spare[0] = 0;
5752 DeleteCriticalSection(&fimpl->cs);
5753 CoTaskMemFree(fimpl);
5754 return hr;
5757 *ppObj = &fimpl->IUnknown_inner;
5758 return S_OK;
5761 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5763 FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5764 return FilterGraph_create(pUnkOuter, ppObj);