hid: Stub HidP_TranslateUsagesToI8042ScanCodes.
[wine.git] / dlls / quartz / filtergraph.c
blob5488afbf8fb5ce4d506212284fe593b7d2a7a91a
1 /* DirectShow FilterGraph object (QUARTZ.DLL)
3 * Copyright 2002 Lionel Ulmer
4 * Copyright 2004 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include <stdarg.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "shlwapi.h"
31 #include "dshow.h"
32 #include "wine/debug.h"
33 #include "quartz_private.h"
34 #include "ole2.h"
35 #include "olectl.h"
36 #include "strmif.h"
37 #include "vfwmsgs.h"
38 #include "evcode.h"
39 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
44 typedef struct {
45 HWND hWnd; /* Target window */
46 UINT msg; /* User window message */
47 LONG_PTR instance; /* User data */
48 int disabled; /* Disabled messages posting */
49 } WndNotify;
51 typedef struct {
52 LONG lEventCode; /* Event code */
53 LONG_PTR lParam1; /* Param1 */
54 LONG_PTR lParam2; /* Param2 */
55 } Event;
57 /* messages ring implementation for queuing events (taken from winmm) */
58 #define EVENTS_RING_BUFFER_INCREMENT 64
59 typedef struct {
60 Event* messages;
61 int ring_buffer_size;
62 int msg_tosave;
63 int msg_toget;
64 CRITICAL_SECTION msg_crst;
65 HANDLE msg_event; /* Signaled for no empty queue */
66 } EventsQueue;
68 static int EventsQueue_Init(EventsQueue* omr)
70 omr->msg_toget = 0;
71 omr->msg_tosave = 0;
72 omr->msg_event = CreateEventW(NULL, TRUE, FALSE, NULL);
73 omr->ring_buffer_size = EVENTS_RING_BUFFER_INCREMENT;
74 omr->messages = CoTaskMemAlloc(omr->ring_buffer_size * sizeof(Event));
75 ZeroMemory(omr->messages, omr->ring_buffer_size * sizeof(Event));
77 InitializeCriticalSection(&omr->msg_crst);
78 omr->msg_crst.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": EventsQueue.msg_crst");
79 return TRUE;
82 static int EventsQueue_Destroy(EventsQueue* omr)
84 CloseHandle(omr->msg_event);
85 CoTaskMemFree(omr->messages);
86 omr->msg_crst.DebugInfo->Spare[0] = 0;
87 DeleteCriticalSection(&omr->msg_crst);
88 return TRUE;
91 static BOOL EventsQueue_PutEvent(EventsQueue* omr, const Event* evt)
93 EnterCriticalSection(&omr->msg_crst);
94 if (omr->msg_toget == ((omr->msg_tosave + 1) % omr->ring_buffer_size))
96 int old_ring_buffer_size = omr->ring_buffer_size;
97 omr->ring_buffer_size += EVENTS_RING_BUFFER_INCREMENT;
98 TRACE("omr->ring_buffer_size=%d\n",omr->ring_buffer_size);
99 omr->messages = CoTaskMemRealloc(omr->messages, omr->ring_buffer_size * sizeof(Event));
100 /* Now we need to rearrange the ring buffer so that the new
101 buffers just allocated are in between omr->msg_tosave and
102 omr->msg_toget.
104 if (omr->msg_tosave < omr->msg_toget)
106 memmove(&(omr->messages[omr->msg_toget + EVENTS_RING_BUFFER_INCREMENT]),
107 &(omr->messages[omr->msg_toget]),
108 sizeof(Event)*(old_ring_buffer_size - omr->msg_toget)
110 omr->msg_toget += EVENTS_RING_BUFFER_INCREMENT;
113 omr->messages[omr->msg_tosave] = *evt;
114 SetEvent(omr->msg_event);
115 omr->msg_tosave = (omr->msg_tosave + 1) % omr->ring_buffer_size;
116 LeaveCriticalSection(&omr->msg_crst);
117 return TRUE;
120 static BOOL EventsQueue_GetEvent(EventsQueue* omr, Event* evt, LONG msTimeOut)
122 if (WaitForSingleObject(omr->msg_event, msTimeOut) != WAIT_OBJECT_0)
123 return FALSE;
125 EnterCriticalSection(&omr->msg_crst);
127 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
129 LeaveCriticalSection(&omr->msg_crst);
130 return FALSE;
133 *evt = omr->messages[omr->msg_toget];
134 omr->msg_toget = (omr->msg_toget + 1) % omr->ring_buffer_size;
136 /* Mark the buffer as empty if needed */
137 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
138 ResetEvent(omr->msg_event);
140 LeaveCriticalSection(&omr->msg_crst);
141 return TRUE;
144 #define MAX_ITF_CACHE_ENTRIES 3
145 typedef struct _ITF_CACHE_ENTRY {
146 const IID* riid;
147 IBaseFilter* filter;
148 IUnknown* iface;
149 } ITF_CACHE_ENTRY;
151 typedef struct _IFilterGraphImpl {
152 IUnknown IUnknown_inner;
153 IFilterGraph2 IFilterGraph2_iface;
154 IMediaControl IMediaControl_iface;
155 IMediaSeeking IMediaSeeking_iface;
156 IBasicAudio IBasicAudio_iface;
157 IBasicVideo2 IBasicVideo2_iface;
158 IVideoWindow IVideoWindow_iface;
159 IMediaEventEx IMediaEventEx_iface;
160 IMediaFilter IMediaFilter_iface;
161 IMediaEventSink IMediaEventSink_iface;
162 IGraphConfig IGraphConfig_iface;
163 IMediaPosition IMediaPosition_iface;
164 IObjectWithSite IObjectWithSite_iface;
165 IGraphVersion IGraphVersion_iface;
166 /* IAMGraphStreams */
167 /* IAMStats */
168 /* IFilterChain */
169 /* IFilterMapper2 */
170 /* IQueueCommand */
171 /* IRegisterServiceProvider */
172 /* IResourceMananger */
173 /* IServiceProvider */
174 /* IVideoFrameStep */
176 IUnknown *outer_unk;
177 LONG ref;
178 IUnknown *punkFilterMapper2;
179 IBaseFilter ** ppFiltersInGraph;
180 LPWSTR * pFilterNames;
181 ULONG nFilters;
182 int filterCapacity;
183 LONG nameIndex;
184 IReferenceClock *refClock;
185 IBaseFilter *refClockProvider;
186 EventsQueue evqueue;
187 HANDLE hEventCompletion;
188 int CompletionStatus;
189 WndNotify notif;
190 int nRenderers;
191 int EcCompleteCount;
192 int HandleEcComplete;
193 int HandleEcRepaint;
194 int HandleEcClockChanged;
195 OAFilterState state;
196 CRITICAL_SECTION cs;
197 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
198 int nItfCacheEntries;
199 BOOL defaultclock;
200 GUID timeformatseek;
201 REFERENCE_TIME start_time;
202 REFERENCE_TIME pause_time;
203 LONGLONG stop_position;
204 LONG recursioncount;
205 IUnknown *pSite;
206 LONG version;
207 } IFilterGraphImpl;
209 static inline IFilterGraphImpl *impl_from_IUnknown(IUnknown *iface)
211 return CONTAINING_RECORD(iface, IFilterGraphImpl, IUnknown_inner);
214 static HRESULT WINAPI FilterGraphInner_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObj)
216 IFilterGraphImpl *This = impl_from_IUnknown(iface);
217 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObj);
219 if (IsEqualGUID(&IID_IUnknown, riid)) {
220 *ppvObj = &This->IUnknown_inner;
221 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
222 } else if (IsEqualGUID(&IID_IFilterGraph, riid) ||
223 IsEqualGUID(&IID_IFilterGraph2, riid) ||
224 IsEqualGUID(&IID_IGraphBuilder, riid)) {
225 *ppvObj = &This->IFilterGraph2_iface;
226 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj);
227 } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
228 *ppvObj = &This->IMediaControl_iface;
229 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj);
230 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
231 *ppvObj = &This->IMediaSeeking_iface;
232 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
233 } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
234 *ppvObj = &This->IBasicAudio_iface;
235 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj);
236 } else if (IsEqualGUID(&IID_IBasicVideo, riid) ||
237 IsEqualGUID(&IID_IBasicVideo2, riid)) {
238 *ppvObj = &This->IBasicVideo2_iface;
239 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj);
240 } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
241 *ppvObj = &This->IVideoWindow_iface;
242 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj);
243 } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
244 IsEqualGUID(&IID_IMediaEventEx, riid)) {
245 *ppvObj = &This->IMediaEventEx_iface;
246 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
247 } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
248 IsEqualGUID(&IID_IPersist, riid)) {
249 *ppvObj = &This->IMediaFilter_iface;
250 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj);
251 } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
252 *ppvObj = &This->IMediaEventSink_iface;
253 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj);
254 } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
255 *ppvObj = &This->IGraphConfig_iface;
256 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
257 } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
258 *ppvObj = &This->IMediaPosition_iface;
259 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj);
260 } else if (IsEqualGUID(&IID_IObjectWithSite, riid)) {
261 *ppvObj = &This->IObjectWithSite_iface;
262 TRACE(" returning IObjectWithSite interface (%p)\n", *ppvObj);
263 } else if (IsEqualGUID(&IID_IFilterMapper, riid)) {
264 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj);
265 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
266 } else if (IsEqualGUID(&IID_IFilterMapper2, riid)) {
267 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
268 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
269 } else if (IsEqualGUID(&IID_IFilterMapper3, riid)) {
270 TRACE(" returning IFilterMapper3 interface from aggregated filtermapper (%p)\n", *ppvObj);
271 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
272 } else if (IsEqualGUID(&IID_IGraphVersion, riid)) {
273 *ppvObj = &This->IGraphConfig_iface;
274 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
275 } else {
276 *ppvObj = NULL;
277 FIXME("unknown interface %s\n", debugstr_guid(riid));
278 return E_NOINTERFACE;
281 IUnknown_AddRef((IUnknown *)*ppvObj);
282 return S_OK;
285 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown *iface)
287 IFilterGraphImpl *This = impl_from_IUnknown(iface);
288 ULONG ref = InterlockedIncrement(&This->ref);
290 TRACE("(%p)->(): new ref = %d\n", This, ref);
292 return ref;
295 static ULONG WINAPI FilterGraphInner_Release(IUnknown *iface)
297 IFilterGraphImpl *This = impl_from_IUnknown(iface);
298 ULONG ref = InterlockedDecrement(&This->ref);
300 TRACE("(%p)->(): new ref = %d\n", This, ref);
302 if (ref == 0) {
303 int i;
305 This->ref = 1; /* guard against reentrancy (aggregation). */
307 IMediaControl_Stop(&This->IMediaControl_iface);
309 while (This->nFilters)
310 IFilterGraph2_RemoveFilter(&This->IFilterGraph2_iface, This->ppFiltersInGraph[0]);
312 if (This->refClock)
313 IReferenceClock_Release(This->refClock);
315 for (i = 0; i < This->nItfCacheEntries; i++)
317 if (This->ItfCacheEntries[i].iface)
318 IUnknown_Release(This->ItfCacheEntries[i].iface);
321 IUnknown_Release(This->punkFilterMapper2);
323 if (This->pSite) IUnknown_Release(This->pSite);
325 CloseHandle(This->hEventCompletion);
326 EventsQueue_Destroy(&This->evqueue);
327 This->cs.DebugInfo->Spare[0] = 0;
328 DeleteCriticalSection(&This->cs);
329 CoTaskMemFree(This->ppFiltersInGraph);
330 CoTaskMemFree(This->pFilterNames);
331 CoTaskMemFree(This);
333 return ref;
336 static inline IFilterGraphImpl *impl_from_IFilterGraph2(IFilterGraph2 *iface)
338 return CONTAINING_RECORD(iface, IFilterGraphImpl, IFilterGraph2_iface);
341 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface, REFIID riid, void **ppvObj)
343 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
345 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
347 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
350 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface)
352 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
354 TRACE("(%p/%p)->()\n", This, iface);
356 return IUnknown_AddRef(This->outer_unk);
359 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface)
361 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
363 TRACE("(%p/%p)->()\n", This, iface);
365 return IUnknown_Release(This->outer_unk);
368 /*** IFilterGraph methods ***/
369 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface, IBaseFilter *pFilter,
370 LPCWSTR pName)
372 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
373 HRESULT hr;
374 int i,j;
375 WCHAR* wszFilterName = NULL;
376 BOOL duplicate_name = FALSE;
378 TRACE("(%p/%p)->(%p, %s (%p))\n", This, iface, pFilter, debugstr_w(pName), pName);
380 if (!pFilter)
381 return E_POINTER;
383 wszFilterName = CoTaskMemAlloc( (pName ? strlenW(pName) + 6 : 5) * sizeof(WCHAR) );
385 if (pName)
387 /* Check if name already exists */
388 for(i = 0; i < This->nFilters; i++)
389 if (!strcmpW(This->pFilterNames[i], pName))
391 duplicate_name = TRUE;
392 break;
396 /* If no name given or name already existing, generate one */
397 if (!pName || duplicate_name)
399 static const WCHAR wszFmt1[] = {'%','s',' ','%','0','4','d',0};
400 static const WCHAR wszFmt2[] = {'%','0','4','d',0};
402 for (j = 0; j < 10000 ; j++)
404 /* Create name */
405 if (pName)
406 sprintfW(wszFilterName, wszFmt1, pName, This->nameIndex);
407 else
408 sprintfW(wszFilterName, wszFmt2, This->nameIndex);
409 TRACE("Generated name %s\n", debugstr_w(wszFilterName));
411 /* Check if the generated name already exists */
412 for(i = 0; i < This->nFilters; i++)
413 if (!strcmpW(This->pFilterNames[i], wszFilterName))
414 break;
416 /* Compute next index and exit if generated name is suitable */
417 if (This->nameIndex++ == 10000)
418 This->nameIndex = 1;
419 if (i == This->nFilters)
420 break;
422 /* Unable to find a suitable name */
423 if (j == 10000)
425 CoTaskMemFree(wszFilterName);
426 return VFW_E_DUPLICATE_NAME;
429 else
430 memcpy(wszFilterName, pName, (strlenW(pName) + 1) * sizeof(WCHAR));
432 if (This->nFilters + 1 > This->filterCapacity)
434 int newCapacity = This->filterCapacity ? 2 * This->filterCapacity : 1;
435 IBaseFilter ** ppNewFilters = CoTaskMemAlloc(newCapacity * sizeof(IBaseFilter*));
436 LPWSTR * pNewNames = CoTaskMemAlloc(newCapacity * sizeof(LPWSTR));
437 memcpy(ppNewFilters, This->ppFiltersInGraph, This->nFilters * sizeof(IBaseFilter*));
438 memcpy(pNewNames, This->pFilterNames, This->nFilters * sizeof(LPWSTR));
439 if (This->filterCapacity)
441 CoTaskMemFree(This->ppFiltersInGraph);
442 CoTaskMemFree(This->pFilterNames);
444 This->ppFiltersInGraph = ppNewFilters;
445 This->pFilterNames = pNewNames;
446 This->filterCapacity = newCapacity;
449 hr = IBaseFilter_JoinFilterGraph(pFilter, (IFilterGraph *)&This->IFilterGraph2_iface, wszFilterName);
451 if (SUCCEEDED(hr))
453 IBaseFilter_AddRef(pFilter);
454 This->ppFiltersInGraph[This->nFilters] = pFilter;
455 This->pFilterNames[This->nFilters] = wszFilterName;
456 This->nFilters++;
457 This->version++;
458 IBaseFilter_SetSyncSource(pFilter, This->refClock);
460 else
461 CoTaskMemFree(wszFilterName);
463 if (SUCCEEDED(hr) && duplicate_name)
464 return VFW_S_DUPLICATE_NAME;
466 return hr;
469 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
471 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
472 int i;
473 HRESULT hr = E_FAIL;
475 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
477 /* FIXME: check graph is stopped */
479 for (i = 0; i < This->nFilters; i++)
481 if (This->ppFiltersInGraph[i] == pFilter)
483 IEnumPins *penumpins = NULL;
484 FILTER_STATE state;
486 if (This->defaultclock && This->refClockProvider == pFilter)
488 IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, NULL);
489 This->defaultclock = TRUE;
492 TRACE("Removing filter %s\n", debugstr_w(This->pFilterNames[i]));
493 IBaseFilter_GetState(pFilter, 0, &state);
494 if (state == State_Running)
495 IBaseFilter_Pause(pFilter);
496 if (state != State_Stopped)
497 IBaseFilter_Stop(pFilter);
499 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
500 if (SUCCEEDED(hr)) {
501 IPin *ppin;
502 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
504 IPin *victim = NULL;
505 HRESULT h;
506 IPin_ConnectedTo(ppin, &victim);
507 if (victim)
509 h = IPin_Disconnect(victim);
510 TRACE("Disconnect other side: %08x\n", h);
511 if (h == VFW_E_NOT_STOPPED)
513 PIN_INFO pinfo;
514 IPin_QueryPinInfo(victim, &pinfo);
516 IBaseFilter_GetState(pinfo.pFilter, 0, &state);
517 if (state == State_Running)
518 IBaseFilter_Pause(pinfo.pFilter);
519 IBaseFilter_Stop(pinfo.pFilter);
520 IBaseFilter_Release(pinfo.pFilter);
521 h = IPin_Disconnect(victim);
522 TRACE("Disconnect retry: %08x\n", h);
524 IPin_Release(victim);
526 h = IPin_Disconnect(ppin);
527 TRACE("Disconnect 2: %08x\n", h);
529 IPin_Release(ppin);
531 IEnumPins_Release(penumpins);
534 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, This->pFilterNames[i]);
535 if (SUCCEEDED(hr))
537 IBaseFilter_SetSyncSource(pFilter, NULL);
538 IBaseFilter_Release(pFilter);
539 CoTaskMemFree(This->pFilterNames[i]);
540 memmove(This->ppFiltersInGraph+i, This->ppFiltersInGraph+i+1, sizeof(IBaseFilter*)*(This->nFilters - 1 - i));
541 memmove(This->pFilterNames+i, This->pFilterNames+i+1, sizeof(LPWSTR)*(This->nFilters - 1 - i));
542 This->nFilters--;
543 This->version++;
544 /* Invalidate interfaces in the cache */
545 for (i = 0; i < This->nItfCacheEntries; i++)
546 if (pFilter == This->ItfCacheEntries[i].filter)
548 IUnknown_Release(This->ItfCacheEntries[i].iface);
549 This->ItfCacheEntries[i].iface = NULL;
550 This->ItfCacheEntries[i].filter = NULL;
552 return S_OK;
554 break;
558 return hr; /* FIXME: check this error code */
561 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface, IEnumFilters **ppEnum)
563 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
565 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
567 return IEnumFiltersImpl_Construct(&This->IGraphVersion_iface, &This->ppFiltersInGraph, &This->nFilters, ppEnum);
570 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface, LPCWSTR pName,
571 IBaseFilter **ppFilter)
573 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
574 int i;
576 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_w(pName), pName, ppFilter);
578 if (!ppFilter)
579 return E_POINTER;
581 for (i = 0; i < This->nFilters; i++)
583 if (!strcmpW(pName, This->pFilterNames[i]))
585 *ppFilter = This->ppFiltersInGraph[i];
586 IBaseFilter_AddRef(*ppFilter);
587 return S_OK;
591 *ppFilter = NULL;
592 return VFW_E_NOT_FOUND;
595 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
596 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
598 static HRESULT CheckCircularConnection(IFilterGraphImpl *This, IPin *out, IPin *in)
600 #if 1
601 HRESULT hr;
602 PIN_INFO info_out, info_in;
604 hr = IPin_QueryPinInfo(out, &info_out);
605 if (FAILED(hr))
606 return hr;
607 if (info_out.dir != PINDIR_OUTPUT)
609 IBaseFilter_Release(info_out.pFilter);
610 return VFW_E_CANNOT_CONNECT;
613 hr = IPin_QueryPinInfo(in, &info_in);
614 if (SUCCEEDED(hr))
615 IBaseFilter_Release(info_in.pFilter);
616 if (FAILED(hr))
617 goto out;
618 if (info_in.dir != PINDIR_INPUT)
620 hr = VFW_E_CANNOT_CONNECT;
621 goto out;
624 if (info_out.pFilter == info_in.pFilter)
625 hr = VFW_E_CIRCULAR_GRAPH;
626 else
628 IEnumPins *enumpins;
629 IPin *test;
631 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
632 if (FAILED(hr))
633 goto out;
635 IEnumPins_Reset(enumpins);
636 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
638 PIN_DIRECTION dir = PINDIR_OUTPUT;
639 IPin_QueryDirection(test, &dir);
640 if (dir == PINDIR_INPUT)
642 IPin *victim = NULL;
643 IPin_ConnectedTo(test, &victim);
644 if (victim)
646 hr = CheckCircularConnection(This, victim, in);
647 IPin_Release(victim);
648 if (FAILED(hr))
650 IPin_Release(test);
651 break;
655 IPin_Release(test);
657 IEnumPins_Release(enumpins);
660 out:
661 IBaseFilter_Release(info_out.pFilter);
662 if (FAILED(hr))
663 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
664 return hr;
665 #else
666 /* Debugging filtergraphs not enabled */
667 return S_OK;
668 #endif
672 /* NOTE: despite the implication, it doesn't matter which
673 * way round you put in the input and output pins */
674 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppinIn, IPin *ppinOut,
675 const AM_MEDIA_TYPE *pmt)
677 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
678 PIN_DIRECTION dir;
679 HRESULT hr;
681 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
683 /* FIXME: check pins are in graph */
685 if (TRACE_ON(quartz))
687 PIN_INFO PinInfo;
689 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
690 if (FAILED(hr))
691 return hr;
693 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
694 IBaseFilter_Release(PinInfo.pFilter);
696 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
697 if (FAILED(hr))
698 return hr;
700 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
701 IBaseFilter_Release(PinInfo.pFilter);
704 hr = IPin_QueryDirection(ppinIn, &dir);
705 if (SUCCEEDED(hr))
707 if (dir == PINDIR_INPUT)
709 hr = CheckCircularConnection(This, ppinOut, ppinIn);
710 if (SUCCEEDED(hr))
711 hr = IPin_Connect(ppinOut, ppinIn, pmt);
713 else
715 hr = CheckCircularConnection(This, ppinIn, ppinOut);
716 if (SUCCEEDED(hr))
717 hr = IPin_Connect(ppinIn, ppinOut, pmt);
721 return hr;
724 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface, IPin *ppin)
726 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
727 IPin *pConnectedTo = NULL;
728 HRESULT hr;
729 PIN_DIRECTION pindir;
731 IPin_QueryDirection(ppin, &pindir);
732 hr = IPin_ConnectedTo(ppin, &pConnectedTo);
733 if (FAILED(hr)) {
734 TRACE("Querying connected to failed: %x\n", hr);
735 return hr;
737 IPin_Disconnect(ppin);
738 IPin_Disconnect(pConnectedTo);
739 if (pindir == PINDIR_INPUT)
740 hr = IPin_Connect(pConnectedTo, ppin, NULL);
741 else
742 hr = IPin_Connect(ppin, pConnectedTo, NULL);
743 IPin_Release(pConnectedTo);
744 if (FAILED(hr))
745 WARN("Reconnecting pins failed, pins are not connected now..\n");
746 TRACE("(%p->%p) -- %p %p -> %x\n", iface, This, ppin, pConnectedTo, hr);
747 return hr;
750 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
752 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
754 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
756 if (!ppin)
757 return E_POINTER;
759 return IPin_Disconnect(ppin);
762 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
764 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
765 IReferenceClock *pClock = NULL;
766 HRESULT hr = S_OK;
767 int i;
769 TRACE("(%p/%p)->() live sources not handled properly!\n", iface, This);
771 EnterCriticalSection(&This->cs);
773 for (i = 0; i < This->nFilters; ++i)
775 DWORD miscflags;
776 IAMFilterMiscFlags *flags = NULL;
777 IBaseFilter_QueryInterface(This->ppFiltersInGraph[i], &IID_IAMFilterMiscFlags, (void**)&flags);
778 if (!flags)
779 continue;
780 miscflags = IAMFilterMiscFlags_GetMiscFlags(flags);
781 IAMFilterMiscFlags_Release(flags);
782 if (miscflags == AM_FILTER_MISC_FLAGS_IS_RENDERER)
783 IBaseFilter_QueryInterface(This->ppFiltersInGraph[i], &IID_IReferenceClock, (void**)&pClock);
784 if (pClock)
785 break;
788 if (!pClock)
790 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
791 This->refClockProvider = NULL;
793 else
794 This->refClockProvider = This->ppFiltersInGraph[i];
796 if (SUCCEEDED(hr))
798 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
799 This->defaultclock = TRUE;
800 IReferenceClock_Release(pClock);
802 LeaveCriticalSection(&This->cs);
804 return hr;
807 static HRESULT GetFilterInfo(IMoniker* pMoniker, VARIANT* pvar)
809 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
810 IPropertyBag * pPropBagCat = NULL;
811 HRESULT hr;
813 VariantInit(pvar);
815 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
817 if (SUCCEEDED(hr))
818 hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL);
820 if (SUCCEEDED(hr))
821 TRACE("Moniker = %s\n", debugstr_w(V_BSTR(pvar)));
823 if (pPropBagCat)
824 IPropertyBag_Release(pPropBagCat);
826 return hr;
829 static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPin*** pppins, ULONG* pnb)
831 HRESULT hr;
832 ULONG nb = 0;
834 TRACE("(%p, %p, %p, %p)\n", pfilter, pinputpin, pppins, pnb);
835 hr = IPin_QueryInternalConnections(pinputpin, NULL, &nb);
836 if (hr == S_OK) {
837 /* Rendered input */
838 } else if (hr == S_FALSE) {
839 *pppins = CoTaskMemAlloc(sizeof(IPin*)*nb);
840 hr = IPin_QueryInternalConnections(pinputpin, *pppins, &nb);
841 if (hr != S_OK) {
842 WARN("Error (%x)\n", hr);
844 } else if (hr == E_NOTIMPL) {
845 /* Input connected to all outputs */
846 IEnumPins* penumpins;
847 IPin* ppin;
848 int i = 0;
849 TRACE("E_NOTIMPL\n");
850 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
851 if (FAILED(hr)) {
852 WARN("filter Enumpins failed (%x)\n", hr);
853 return hr;
855 i = 0;
856 /* Count output pins */
857 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
858 PIN_DIRECTION pindir;
859 IPin_QueryDirection(ppin, &pindir);
860 if (pindir == PINDIR_OUTPUT)
861 i++;
862 IPin_Release(ppin);
864 *pppins = CoTaskMemAlloc(sizeof(IPin*)*i);
865 /* Retrieve output pins */
866 IEnumPins_Reset(penumpins);
867 i = 0;
868 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
869 PIN_DIRECTION pindir;
870 IPin_QueryDirection(ppin, &pindir);
871 if (pindir == PINDIR_OUTPUT)
872 (*pppins)[i++] = ppin;
873 else
874 IPin_Release(ppin);
876 IEnumPins_Release(penumpins);
877 nb = i;
878 if (FAILED(hr)) {
879 WARN("Next failed (%x)\n", hr);
880 return hr;
882 } else if (FAILED(hr)) {
883 WARN("Cannot get internal connection (%x)\n", hr);
884 return hr;
887 *pnb = nb;
888 return S_OK;
891 /*** IGraphBuilder methods ***/
892 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IPin *ppinIn)
894 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
895 HRESULT hr;
896 AM_MEDIA_TYPE* mt = NULL;
897 IEnumMediaTypes* penummt = NULL;
898 ULONG nbmt;
899 IEnumPins* penumpins;
900 IEnumMoniker* pEnumMoniker;
901 GUID tab[2];
902 ULONG nb = 0;
903 IMoniker* pMoniker;
904 ULONG pin;
905 PIN_INFO PinInfo;
906 CLSID FilterCLSID;
907 PIN_DIRECTION dir;
908 unsigned int i = 0;
909 IFilterMapper2 *pFilterMapper2 = NULL;
911 TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
913 if(!ppinOut || !ppinIn)
914 return E_POINTER;
916 if (TRACE_ON(quartz))
918 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
919 if (FAILED(hr))
920 return hr;
922 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
923 IBaseFilter_Release(PinInfo.pFilter);
925 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
926 if (FAILED(hr))
927 return hr;
929 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
930 IBaseFilter_Release(PinInfo.pFilter);
933 EnterCriticalSection(&This->cs);
934 ++This->recursioncount;
935 if (This->recursioncount >= 5)
937 WARN("Recursion count has reached %d\n", This->recursioncount);
938 hr = VFW_E_CANNOT_CONNECT;
939 goto out;
942 hr = IPin_QueryDirection(ppinOut, &dir);
943 if (FAILED(hr))
944 goto out;
946 if (dir == PINDIR_INPUT)
948 IPin *temp;
950 temp = ppinIn;
951 ppinIn = ppinOut;
952 ppinOut = temp;
955 hr = CheckCircularConnection(This, ppinOut, ppinIn);
956 if (FAILED(hr))
957 goto out;
959 /* Try direct connection first */
960 hr = IPin_Connect(ppinOut, ppinIn, NULL);
961 if (SUCCEEDED(hr))
962 goto out;
964 TRACE("Direct connection failed, trying to render using extra filters\n");
966 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
967 if (FAILED(hr))
968 goto out;
970 hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
971 IBaseFilter_Release(PinInfo.pFilter);
972 if (FAILED(hr))
973 goto out;
975 /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream
976 * filter to the minor mediatype of input pin of the renderer */
977 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
978 if (FAILED(hr))
980 WARN("EnumMediaTypes (%x)\n", hr);
981 goto out;
984 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
985 if (FAILED(hr)) {
986 WARN("IEnumMediaTypes_Next (%x)\n", hr);
987 goto out;
990 if (!nbmt)
992 WARN("No media type found!\n");
993 hr = VFW_E_INVALIDMEDIATYPE;
994 goto out;
996 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
997 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
999 hr = IUnknown_QueryInterface(This->punkFilterMapper2, &IID_IFilterMapper2, (void**)&pFilterMapper2);
1000 if (FAILED(hr)) {
1001 WARN("Unable to get IFilterMapper2 (%x)\n", hr);
1002 goto out;
1005 /* Try to find a suitable filter that can connect to the pin to render */
1006 tab[0] = mt->majortype;
1007 tab[1] = mt->subtype;
1008 hr = IFilterMapper2_EnumMatchingFilters(pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1009 if (FAILED(hr)) {
1010 WARN("Unable to enum filters (%x)\n", hr);
1011 goto out;
1014 hr = VFW_E_CANNOT_RENDER;
1015 while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1017 VARIANT var;
1018 GUID clsid;
1019 IPin** ppins = NULL;
1020 IPin* ppinfilter = NULL;
1021 IBaseFilter* pfilter = NULL;
1022 IAMGraphBuilderCallback *callback = NULL;
1024 hr = GetFilterInfo(pMoniker, &var);
1025 if (FAILED(hr)) {
1026 WARN("Unable to retrieve filter info (%x)\n", hr);
1027 goto error;
1030 hr = IMoniker_BindToObject(pMoniker, NULL, NULL, &IID_IBaseFilter, (LPVOID*)&pfilter);
1031 IMoniker_Release(pMoniker);
1032 if (FAILED(hr)) {
1033 WARN("Unable to create filter (%x), trying next one\n", hr);
1034 goto error;
1037 hr = IBaseFilter_GetClassID(pfilter, &clsid);
1038 if (FAILED(hr))
1040 IBaseFilter_Release(pfilter);
1041 goto error;
1044 if (IsEqualGUID(&clsid, &FilterCLSID)) {
1045 /* Skip filter (same as the one the output pin belongs to) */
1046 IBaseFilter_Release(pfilter);
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 if (SUCCEEDED(hr))
1541 hr = IBaseFilter_EnumPins(preader, &penumpins);
1542 if (SUCCEEDED(hr))
1544 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1546 PIN_DIRECTION dir;
1548 IPin_QueryDirection(ppinreader, &dir);
1549 if (dir == PINDIR_OUTPUT)
1551 INT i;
1553 hr = IFilterGraph2_Render(iface, ppinreader);
1554 TRACE("Render %08x\n", hr);
1556 for (i = 0; i < This->nFilters; ++i)
1557 TRACE("Filters in chain: %s\n", debugstr_w(This->pFilterNames[i]));
1559 if (SUCCEEDED(hr))
1560 any = TRUE;
1561 if (hr != S_OK)
1562 partial = TRUE;
1564 IPin_Release(ppinreader);
1566 IEnumPins_Release(penumpins);
1568 if (!any)
1569 hr = VFW_E_CANNOT_RENDER;
1570 else if (partial)
1571 hr = VFW_S_PARTIAL_RENDER;
1572 else
1573 hr = S_OK;
1575 IBaseFilter_Release(preader);
1577 TRACE("--> %08x\n", hr);
1578 return hr;
1581 static HRESULT CreateFilterInstanceAndLoadFile(GUID* clsid, LPCOLESTR pszFileName, IBaseFilter **filter)
1583 IFileSourceFilter *source = NULL;
1584 HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1585 TRACE("CLSID: %s\n", debugstr_guid(clsid));
1586 if (FAILED(hr))
1587 return hr;
1589 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID*)&source);
1590 if (FAILED(hr))
1592 IBaseFilter_Release(*filter);
1593 return hr;
1596 /* Load the file in the file source filter */
1597 hr = IFileSourceFilter_Load(source, pszFileName, NULL);
1598 IFileSourceFilter_Release(source);
1599 if (FAILED(hr)) {
1600 WARN("Load (%x)\n", hr);
1601 IBaseFilter_Release(*filter);
1602 return hr;
1605 return hr;
1608 /* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
1609 static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
1611 HRESULT hr;
1612 GUID clsid;
1613 IAsyncReader * pReader = NULL;
1614 IFileSourceFilter* pSource = NULL;
1615 IPin * pOutputPin = NULL;
1616 static const WCHAR wszOutputPinName[] = { 'O','u','t','p','u','t',0 };
1618 /* Try to find a match without reading the file first */
1619 hr = GetClassMediaFile(NULL, pszFileName, NULL, NULL, &clsid);
1621 if (hr == S_OK)
1622 return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
1624 /* Now create a AyncReader instance, to check for signature bytes in the file */
1625 hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1626 if (FAILED(hr))
1627 return hr;
1629 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID *)&pSource);
1630 if (FAILED(hr))
1632 IBaseFilter_Release(*filter);
1633 return hr;
1636 hr = IFileSourceFilter_Load(pSource, pszFileName, NULL);
1637 IFileSourceFilter_Release(pSource);
1638 if (FAILED(hr))
1640 IBaseFilter_Release(*filter);
1641 return hr;
1644 hr = IBaseFilter_FindPin(*filter, wszOutputPinName, &pOutputPin);
1645 if (FAILED(hr))
1647 IBaseFilter_Release(*filter);
1648 return hr;
1651 hr = IPin_QueryInterface(pOutputPin, &IID_IAsyncReader, (LPVOID *)&pReader);
1652 IPin_Release(pOutputPin);
1653 if (FAILED(hr))
1655 IBaseFilter_Release(*filter);
1656 return hr;
1659 /* Try again find a match */
1660 hr = GetClassMediaFile(pReader, pszFileName, NULL, NULL, &clsid);
1661 IAsyncReader_Release(pReader);
1663 if (hr == S_OK)
1665 /* Release the AsyncReader filter and create the matching one */
1666 IBaseFilter_Release(*filter);
1667 return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
1670 /* Return the AsyncReader filter */
1671 return S_OK;
1674 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface, LPCWSTR lpcwstrFileName,
1675 LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1677 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1678 HRESULT hr;
1679 IBaseFilter* preader;
1680 IFileSourceFilter* pfile = NULL;
1681 AM_MEDIA_TYPE mt;
1682 WCHAR* filename;
1684 TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1686 /* Try from file name first, then fall back to default asynchronous reader */
1687 hr = GetFileSourceFilter(lpcwstrFileName, &preader);
1688 if (FAILED(hr)) {
1689 WARN("Unable to create file source filter (%x)\n", hr);
1690 return hr;
1693 hr = IFilterGraph2_AddFilter(iface, preader, lpcwstrFilterName);
1694 if (FAILED(hr)) {
1695 WARN("Unable add filter (%x)\n", hr);
1696 IBaseFilter_Release(preader);
1697 return hr;
1700 hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1701 if (FAILED(hr)) {
1702 WARN("Unable to get IFileSourceInterface (%x)\n", hr);
1703 goto error;
1706 /* The file has been already loaded */
1707 hr = IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1708 if (FAILED(hr)) {
1709 WARN("GetCurFile (%x)\n", hr);
1710 goto error;
1713 TRACE("File %s\n", debugstr_w(filename));
1714 TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
1715 TRACE("SubType %s\n", debugstr_guid(&mt.subtype));
1717 if (ppFilter)
1718 *ppFilter = preader;
1719 IFileSourceFilter_Release(pfile);
1721 return S_OK;
1723 error:
1724 if (pfile)
1725 IFileSourceFilter_Release(pfile);
1726 IFilterGraph2_RemoveFilter(iface, preader);
1727 IBaseFilter_Release(preader);
1729 return hr;
1732 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR hFile)
1734 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1736 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1738 return S_OK;
1741 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1743 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1745 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1747 return S_OK;
1750 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1752 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1754 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1756 return S_OK;
1759 /*** IFilterGraph2 methods ***/
1760 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1761 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1763 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1764 HRESULT hr;
1765 IBaseFilter* pfilter;
1767 TRACE("(%p/%p)->(%p %p %s %p)\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1769 hr = IMoniker_BindToObject(pMoniker, pCtx, NULL, &IID_IBaseFilter, (void**)&pfilter);
1770 if(FAILED(hr)) {
1771 WARN("Unable to bind moniker to filter object (%x)\n", hr);
1772 return hr;
1775 hr = IFilterGraph2_AddFilter(iface, pfilter, lpcwstrFilterName);
1776 if (FAILED(hr)) {
1777 WARN("Unable to add filter (%x)\n", hr);
1778 IBaseFilter_Release(pfilter);
1779 return hr;
1782 if(ppFilter)
1783 *ppFilter = pfilter;
1784 else IBaseFilter_Release(pfilter);
1786 return S_OK;
1789 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *ppin,
1790 const AM_MEDIA_TYPE *pmt)
1792 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1794 TRACE("(%p/%p)->(%p %p): stub !!!\n", This, iface, ppin, pmt);
1796 return S_OK;
1799 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *pPinOut, DWORD dwFlags,
1800 DWORD *pvContext)
1802 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1804 TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This, iface, pPinOut, dwFlags, pvContext);
1806 return S_OK;
1810 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1812 FilterGraph2_QueryInterface,
1813 FilterGraph2_AddRef,
1814 FilterGraph2_Release,
1815 FilterGraph2_AddFilter,
1816 FilterGraph2_RemoveFilter,
1817 FilterGraph2_EnumFilters,
1818 FilterGraph2_FindFilterByName,
1819 FilterGraph2_ConnectDirect,
1820 FilterGraph2_Reconnect,
1821 FilterGraph2_Disconnect,
1822 FilterGraph2_SetDefaultSyncSource,
1823 FilterGraph2_Connect,
1824 FilterGraph2_Render,
1825 FilterGraph2_RenderFile,
1826 FilterGraph2_AddSourceFilter,
1827 FilterGraph2_SetLogFile,
1828 FilterGraph2_Abort,
1829 FilterGraph2_ShouldOperationContinue,
1830 FilterGraph2_AddSourceFilterForMoniker,
1831 FilterGraph2_ReconnectEx,
1832 FilterGraph2_RenderEx
1835 static inline IFilterGraphImpl *impl_from_IMediaControl(IMediaControl *iface)
1837 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaControl_iface);
1840 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID riid, void **ppvObj)
1842 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1844 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
1846 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
1849 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1851 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1853 TRACE("(%p/%p)->()\n", This, iface);
1855 return IUnknown_AddRef(This->outer_unk);
1858 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1860 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1862 TRACE("(%p/%p)->()\n", This, iface);
1864 return IUnknown_Release(This->outer_unk);
1868 /*** IDispatch methods ***/
1869 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *pctinfo)
1871 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1873 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1875 return S_OK;
1878 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT iTInfo, LCID lcid,
1879 ITypeInfo **ppTInfo)
1881 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1883 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1885 return S_OK;
1888 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID riid,
1889 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1891 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1893 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
1894 cNames, lcid, rgDispId);
1896 return S_OK;
1899 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID dispIdMember, REFIID riid,
1900 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
1901 UINT *puArgErr)
1903 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1905 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
1906 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
1908 return S_OK;
1911 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *, DWORD_PTR data);
1913 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter, DWORD_PTR data)
1915 HRESULT hr;
1916 IPin* pInputPin;
1917 IPin** ppPins;
1918 ULONG nb;
1919 ULONG i;
1920 PIN_INFO PinInfo;
1922 TRACE("%p %p\n", pGraph, pOutputPin);
1923 PinInfo.pFilter = NULL;
1925 hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1927 if (SUCCEEDED(hr))
1929 hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1930 if (SUCCEEDED(hr))
1931 hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1932 IPin_Release(pInputPin);
1935 if (SUCCEEDED(hr))
1937 if (nb == 0)
1939 TRACE("Reached a renderer\n");
1940 /* Count renderers for end of stream notification */
1941 pGraph->nRenderers++;
1943 else
1945 for(i = 0; i < nb; i++)
1947 /* Explore the graph downstream from this pin
1948 * FIXME: We should prevent exploring from a pin more than once. This can happens when
1949 * several input pins are connected to the same output (a MUX for instance). */
1950 ExploreGraph(pGraph, ppPins[i], FoundFilter, data);
1951 IPin_Release(ppPins[i]);
1954 CoTaskMemFree(ppPins);
1956 TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1958 FoundFilter(PinInfo.pFilter, data);
1961 if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1962 return hr;
1965 static HRESULT WINAPI SendRun(IBaseFilter *pFilter, DWORD_PTR data)
1967 REFERENCE_TIME time = *(REFERENCE_TIME*)data;
1968 return IBaseFilter_Run(pFilter, time);
1971 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1973 return IBaseFilter_Pause(pFilter);
1976 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1978 return IBaseFilter_Stop(pFilter);
1981 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1983 FILTER_STATE state;
1984 DWORD time_end = data;
1985 DWORD time_now = GetTickCount();
1986 LONG wait;
1988 if (time_end == INFINITE)
1990 wait = INFINITE;
1992 else if (time_end > time_now)
1994 wait = time_end - time_now;
1996 else
1997 wait = 0;
1999 return IBaseFilter_GetState(pFilter, wait, &state);
2003 static HRESULT SendFilterMessage(IFilterGraphImpl *This, fnFoundFilter FoundFilter, DWORD_PTR data)
2005 int i;
2006 IBaseFilter* pfilter;
2007 IEnumPins* pEnum;
2008 HRESULT hr;
2009 IPin* pPin;
2010 DWORD dummy;
2011 PIN_DIRECTION dir;
2013 TRACE("(%p)->()\n", This);
2015 /* Explorer the graph from source filters to renderers, determine renderers
2016 * number and run filters from renderers to source filters */
2017 This->nRenderers = 0;
2018 ResetEvent(This->hEventCompletion);
2020 for(i = 0; i < This->nFilters; i++)
2022 BOOL source = TRUE;
2023 pfilter = This->ppFiltersInGraph[i];
2024 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
2025 if (hr != S_OK)
2027 WARN("Enum pins failed %x\n", hr);
2028 continue;
2030 /* Check if it is a source filter */
2031 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2033 IPin_QueryDirection(pPin, &dir);
2034 IPin_Release(pPin);
2035 if (dir == PINDIR_INPUT)
2037 source = FALSE;
2038 break;
2041 if (source)
2043 TRACE("Found a source filter %p\n", pfilter);
2044 IEnumPins_Reset(pEnum);
2045 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2047 /* Explore the graph downstream from this pin */
2048 ExploreGraph(This, pPin, FoundFilter, data);
2049 IPin_Release(pPin);
2051 FoundFilter(pfilter, data);
2053 IEnumPins_Release(pEnum);
2056 return S_FALSE;
2059 /*** IMediaControl methods ***/
2060 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
2062 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2064 TRACE("(%p/%p)->()\n", This, iface);
2066 EnterCriticalSection(&This->cs);
2067 if (This->state == State_Running)
2068 goto out;
2069 This->EcCompleteCount = 0;
2071 if (This->defaultclock && !This->refClock)
2072 IFilterGraph2_SetDefaultSyncSource(&This->IFilterGraph2_iface);
2074 if (This->refClock)
2076 REFERENCE_TIME now;
2077 IReferenceClock_GetTime(This->refClock, &now);
2078 if (This->state == State_Stopped)
2079 This->start_time = now + 500000;
2080 else if (This->pause_time >= 0)
2081 This->start_time += now - This->pause_time;
2082 else
2083 This->start_time = now;
2085 else This->start_time = 0;
2087 SendFilterMessage(This, SendRun, (DWORD_PTR)&This->start_time);
2088 This->state = State_Running;
2089 out:
2090 LeaveCriticalSection(&This->cs);
2091 return S_FALSE;
2094 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
2096 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2098 TRACE("(%p/%p)->()\n", This, iface);
2100 EnterCriticalSection(&This->cs);
2101 if (This->state == State_Paused)
2102 goto out;
2104 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2105 IReferenceClock_GetTime(This->refClock, &This->pause_time);
2106 else
2107 This->pause_time = -1;
2109 SendFilterMessage(This, SendPause, 0);
2110 This->state = State_Paused;
2111 out:
2112 LeaveCriticalSection(&This->cs);
2113 return S_FALSE;
2116 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
2118 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2120 TRACE("(%p/%p)->()\n", This, iface);
2122 if (This->state == State_Stopped) return S_OK;
2124 EnterCriticalSection(&This->cs);
2125 if (This->state == State_Running) SendFilterMessage(This, SendPause, 0);
2126 SendFilterMessage(This, SendStop, 0);
2127 This->state = State_Stopped;
2128 LeaveCriticalSection(&This->cs);
2129 return S_OK;
2132 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG msTimeout,
2133 OAFilterState *pfs)
2135 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2136 DWORD end;
2138 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
2140 if (!pfs)
2141 return E_POINTER;
2143 EnterCriticalSection(&This->cs);
2145 *pfs = This->state;
2146 if (msTimeout > 0)
2148 end = GetTickCount() + msTimeout;
2150 else if (msTimeout < 0)
2152 end = INFINITE;
2154 else
2156 end = 0;
2158 if (end)
2159 SendFilterMessage(This, SendGetState, end);
2161 LeaveCriticalSection(&This->cs);
2163 return S_OK;
2166 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
2168 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2170 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strFilename), strFilename);
2172 return IFilterGraph2_RenderFile(&This->IFilterGraph2_iface, strFilename, NULL);
2175 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
2176 IDispatch **ppUnk)
2178 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2180 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2182 return S_OK;
2185 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2187 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2189 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2191 return S_OK;
2194 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2196 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2198 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2200 return S_OK;
2203 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
2205 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2207 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2209 return S_OK;
2213 static const IMediaControlVtbl IMediaControl_VTable =
2215 MediaControl_QueryInterface,
2216 MediaControl_AddRef,
2217 MediaControl_Release,
2218 MediaControl_GetTypeInfoCount,
2219 MediaControl_GetTypeInfo,
2220 MediaControl_GetIDsOfNames,
2221 MediaControl_Invoke,
2222 MediaControl_Run,
2223 MediaControl_Pause,
2224 MediaControl_Stop,
2225 MediaControl_GetState,
2226 MediaControl_RenderFile,
2227 MediaControl_AddSourceFilter,
2228 MediaControl_get_FilterCollection,
2229 MediaControl_get_RegFilterCollection,
2230 MediaControl_StopWhenReady
2233 static inline IFilterGraphImpl *impl_from_IMediaSeeking(IMediaSeeking *iface)
2235 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaSeeking_iface);
2238 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID riid, void **ppvObj)
2240 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2242 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
2244 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2247 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2249 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2251 TRACE("(%p/%p)->()\n", This, iface);
2253 return IUnknown_AddRef(This->outer_unk);
2256 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2258 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2260 TRACE("(%p/%p)->()\n", This, iface);
2262 return IUnknown_Release(This->outer_unk);
2265 typedef HRESULT (WINAPI *fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
2267 static HRESULT all_renderers_seek(IFilterGraphImpl *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2268 BOOL allnotimpl = TRUE;
2269 int i;
2270 HRESULT hr, hr_return = S_OK;
2272 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2273 /* Send a message to all renderers, they are responsible for broadcasting it further */
2275 for(i = 0; i < This->nFilters; i++)
2277 IMediaSeeking *seek = NULL;
2278 IBaseFilter* pfilter = This->ppFiltersInGraph[i];
2279 IAMFilterMiscFlags *flags = NULL;
2280 ULONG filterflags;
2281 IBaseFilter_QueryInterface(pfilter, &IID_IAMFilterMiscFlags, (void**)&flags);
2282 if (!flags)
2283 continue;
2284 filterflags = IAMFilterMiscFlags_GetMiscFlags(flags);
2285 IAMFilterMiscFlags_Release(flags);
2286 if (filterflags != AM_FILTER_MISC_FLAGS_IS_RENDERER)
2287 continue;
2289 IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2290 if (!seek)
2291 continue;
2292 hr = FoundSeek(This, seek, arg);
2293 IMediaSeeking_Release(seek);
2294 if (hr_return != E_NOTIMPL)
2295 allnotimpl = FALSE;
2296 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2297 hr_return = hr;
2300 if (allnotimpl)
2301 return E_NOTIMPL;
2302 return hr_return;
2305 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2307 HRESULT hr;
2308 DWORD caps = 0;
2310 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2311 if (FAILED(hr))
2312 return hr;
2314 /* Only add common capabilities everything supports */
2315 *(DWORD*)pcaps &= caps;
2317 return hr;
2320 /*** IMediaSeeking methods ***/
2321 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2323 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2324 HRESULT hr;
2326 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2328 if (!pCapabilities)
2329 return E_POINTER;
2331 EnterCriticalSection(&This->cs);
2332 *pCapabilities = 0xffffffff;
2334 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2335 LeaveCriticalSection(&This->cs);
2337 return hr;
2340 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2342 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2343 DWORD originalcaps;
2344 HRESULT hr;
2346 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2348 if (!pCapabilities)
2349 return E_POINTER;
2351 EnterCriticalSection(&This->cs);
2352 originalcaps = *pCapabilities;
2353 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2354 LeaveCriticalSection(&This->cs);
2356 if (FAILED(hr))
2357 return hr;
2359 if (!*pCapabilities)
2360 return E_FAIL;
2361 if (*pCapabilities != originalcaps)
2362 return S_FALSE;
2363 return S_OK;
2366 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2368 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2370 if (!pFormat)
2371 return E_POINTER;
2373 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2375 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2377 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2378 return S_FALSE;
2381 return S_OK;
2384 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2386 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2388 if (!pFormat)
2389 return E_POINTER;
2391 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2392 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2394 return S_OK;
2397 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2399 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2401 if (!pFormat)
2402 return E_POINTER;
2404 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2405 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2407 return S_OK;
2410 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2412 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2414 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2415 if (!pFormat)
2416 return E_POINTER;
2418 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2419 return S_FALSE;
2421 return S_OK;
2424 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2426 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2428 if (!pFormat)
2429 return E_POINTER;
2431 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2433 if (This->state != State_Stopped)
2434 return VFW_E_WRONG_STATE;
2436 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2438 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2439 return E_INVALIDARG;
2442 return S_OK;
2445 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2447 HRESULT hr;
2448 LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2450 hr = IMediaSeeking_GetDuration(seek, &duration);
2451 if (FAILED(hr))
2452 return hr;
2454 if (*pdur < duration)
2455 *pdur = duration;
2456 return hr;
2459 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *pDuration)
2461 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2462 HRESULT hr;
2464 TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2466 if (!pDuration)
2467 return E_POINTER;
2469 EnterCriticalSection(&This->cs);
2470 *pDuration = 0;
2471 hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2472 LeaveCriticalSection(&This->cs);
2474 TRACE("--->%08x\n", hr);
2475 return hr;
2478 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *pStop)
2480 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2481 HRESULT hr = S_OK;
2483 TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2485 if (!pStop)
2486 return E_POINTER;
2488 EnterCriticalSection(&This->cs);
2489 if (This->stop_position < 0)
2490 /* Stop position not set, use duration instead */
2491 hr = IMediaSeeking_GetDuration(iface, pStop);
2492 else
2493 *pStop = This->stop_position;
2494 LeaveCriticalSection(&This->cs);
2496 return hr;
2499 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *pCurrent)
2501 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2502 LONGLONG time = 0;
2504 if (!pCurrent)
2505 return E_POINTER;
2507 EnterCriticalSection(&This->cs);
2508 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2510 IReferenceClock_GetTime(This->refClock, &time);
2511 if (time)
2512 time -= This->start_time;
2514 if (This->pause_time > 0)
2515 time += This->pause_time;
2516 *pCurrent = time;
2517 LeaveCriticalSection(&This->cs);
2519 TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2521 return S_OK;
2524 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2525 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2527 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2529 TRACE("(%p/%p)->(%p, %s, 0x%s, %s)\n", This, iface, pTarget,
2530 debugstr_guid(pTargetFormat), wine_dbgstr_longlong(Source), debugstr_guid(pSourceFormat));
2532 if (!pSourceFormat)
2533 pSourceFormat = &This->timeformatseek;
2535 if (!pTargetFormat)
2536 pTargetFormat = &This->timeformatseek;
2538 if (IsEqualGUID(pTargetFormat, pSourceFormat))
2539 *pTarget = Source;
2540 else
2541 FIXME("conversion %s->%s not supported\n", debugstr_guid(pSourceFormat), debugstr_guid(pTargetFormat));
2543 return S_OK;
2546 struct pos_args {
2547 LONGLONG* current, *stop;
2548 DWORD curflags, stopflags;
2551 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2553 struct pos_args *args = (void*)pargs;
2555 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
2558 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2559 DWORD dwCurrentFlags, LONGLONG *pStop, DWORD dwStopFlags)
2561 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2562 HRESULT hr = S_OK;
2563 FILTER_STATE state;
2564 struct pos_args args;
2566 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
2568 EnterCriticalSection(&This->cs);
2569 state = This->state;
2570 TRACE("State: %s\n", state == State_Running ? "Running" : (state == State_Paused ? "Paused" : (state == State_Stopped ? "Stopped" : "UNKNOWN")));
2572 if ((dwCurrentFlags & 0x7) != AM_SEEKING_AbsolutePositioning &&
2573 (dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2574 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
2576 if ((dwStopFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2577 This->stop_position = *pStop;
2578 else if ((dwStopFlags & 0x7) != AM_SEEKING_NoPositioning)
2579 FIXME("Stop position not handled yet!\n");
2581 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2582 IMediaControl_Pause(&This->IMediaControl_iface);
2583 args.current = pCurrent;
2584 args.stop = pStop;
2585 args.curflags = dwCurrentFlags;
2586 args.stopflags = dwStopFlags;
2587 hr = all_renderers_seek(This, found_setposition, (DWORD_PTR)&args);
2589 if ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2590 This->pause_time = This->start_time = -1;
2591 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2592 IMediaControl_Run(&This->IMediaControl_iface);
2593 LeaveCriticalSection(&This->cs);
2595 return hr;
2598 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2599 LONGLONG *pStop)
2601 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2602 HRESULT hr;
2604 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pCurrent, pStop);
2605 hr = IMediaSeeking_GetCurrentPosition(iface, pCurrent);
2606 if (SUCCEEDED(hr))
2607 hr = IMediaSeeking_GetStopPosition(iface, pStop);
2609 return hr;
2612 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2613 LONGLONG *pLatest)
2615 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2617 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2619 return S_OK;
2622 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2624 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2626 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2628 return S_OK;
2631 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2633 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2635 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2637 if (!pdRate)
2638 return E_POINTER;
2640 *pdRate = 1.0;
2642 return S_OK;
2645 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2647 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2649 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2651 return S_OK;
2655 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2657 MediaSeeking_QueryInterface,
2658 MediaSeeking_AddRef,
2659 MediaSeeking_Release,
2660 MediaSeeking_GetCapabilities,
2661 MediaSeeking_CheckCapabilities,
2662 MediaSeeking_IsFormatSupported,
2663 MediaSeeking_QueryPreferredFormat,
2664 MediaSeeking_GetTimeFormat,
2665 MediaSeeking_IsUsingTimeFormat,
2666 MediaSeeking_SetTimeFormat,
2667 MediaSeeking_GetDuration,
2668 MediaSeeking_GetStopPosition,
2669 MediaSeeking_GetCurrentPosition,
2670 MediaSeeking_ConvertTimeFormat,
2671 MediaSeeking_SetPositions,
2672 MediaSeeking_GetPositions,
2673 MediaSeeking_GetAvailable,
2674 MediaSeeking_SetRate,
2675 MediaSeeking_GetRate,
2676 MediaSeeking_GetPreroll
2679 static inline IFilterGraphImpl *impl_from_IMediaPosition(IMediaPosition *iface)
2681 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaPosition_iface);
2684 /*** IUnknown methods ***/
2685 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj)
2687 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2689 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
2691 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2694 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2696 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2698 TRACE("(%p/%p)->()\n", This, iface);
2700 return IUnknown_AddRef(This->outer_unk);
2703 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2705 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2707 TRACE("(%p/%p)->()\n", This, iface);
2709 return IUnknown_Release(This->outer_unk);
2712 /*** IDispatch methods ***/
2713 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo)
2715 FIXME("(%p) stub!\n", iface);
2716 return E_NOTIMPL;
2719 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
2721 FIXME("(%p) stub!\n", iface);
2722 return E_NOTIMPL;
2725 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
2727 FIXME("(%p) stub!\n", iface);
2728 return E_NOTIMPL;
2731 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2733 FIXME("(%p) stub!\n", iface);
2734 return E_NOTIMPL;
2737 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2739 GUID time_format;
2740 HRESULT hr;
2742 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2743 if (FAILED(hr))
2744 return hr;
2745 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2747 FIXME("Unsupported time format.\n");
2748 return E_NOTIMPL;
2751 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2752 return S_OK;
2755 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2757 GUID time_format;
2758 HRESULT hr;
2760 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2761 if (FAILED(hr))
2762 return hr;
2763 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2765 FIXME("Unsupported time format.\n");
2766 return E_NOTIMPL;
2769 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2770 return S_OK;
2773 /*** IMediaPosition methods ***/
2774 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2776 LONGLONG duration;
2777 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2778 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2779 if (FAILED(hr))
2780 return hr;
2781 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2784 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2786 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2787 LONGLONG reftime;
2788 HRESULT hr;
2790 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2791 if (FAILED(hr))
2792 return hr;
2793 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2794 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2797 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2799 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2800 LONGLONG pos;
2801 HRESULT hr;
2803 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2804 if (FAILED(hr))
2805 return hr;
2806 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2809 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2811 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2812 LONGLONG pos;
2813 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2814 if (FAILED(hr))
2815 return hr;
2816 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2819 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2821 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2822 LONGLONG reftime;
2823 HRESULT hr;
2825 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2826 if (FAILED(hr))
2827 return hr;
2828 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2829 &reftime, AM_SEEKING_AbsolutePositioning);
2832 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime)
2834 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2835 return E_NOTIMPL;
2838 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime)
2840 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2841 return E_NOTIMPL;
2844 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2846 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2847 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2850 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2852 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2853 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2856 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward)
2858 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2859 return E_NOTIMPL;
2862 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward)
2864 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2865 return E_NOTIMPL;
2869 static const IMediaPositionVtbl IMediaPosition_VTable =
2871 MediaPosition_QueryInterface,
2872 MediaPosition_AddRef,
2873 MediaPosition_Release,
2874 MediaPosition_GetTypeInfoCount,
2875 MediaPosition_GetTypeInfo,
2876 MediaPosition_GetIDsOfNames,
2877 MediaPosition_Invoke,
2878 MediaPosition_get_Duration,
2879 MediaPosition_put_CurrentPosition,
2880 MediaPosition_get_CurrentPosition,
2881 MediaPosition_get_StopTime,
2882 MediaPosition_put_StopTime,
2883 MediaPosition_get_PrerollTime,
2884 MediaPosition_put_PrerollTime,
2885 MediaPosition_put_Rate,
2886 MediaPosition_get_Rate,
2887 MediaPosition_CanSeekForward,
2888 MediaPosition_CanSeekBackward
2891 static inline IFilterGraphImpl *impl_from_IObjectWithSite(IObjectWithSite *iface)
2893 return CONTAINING_RECORD(iface, IFilterGraphImpl, IObjectWithSite_iface);
2896 /*** IUnknown methods ***/
2897 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite* iface, REFIID riid, void** ppvObj)
2899 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2901 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
2903 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2906 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
2908 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2910 TRACE("(%p/%p)->()\n", This, iface);
2912 return IUnknown_AddRef(This->outer_unk);
2915 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
2917 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2919 TRACE("(%p/%p)->()\n", This, iface);
2921 return IUnknown_Release(This->outer_unk);
2924 /*** IObjectWithSite methods ***/
2926 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
2928 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2930 TRACE("(%p/%p)->()\n", This, iface);
2931 if (This->pSite) IUnknown_Release(This->pSite);
2932 This->pSite = pUnkSite;
2933 IUnknown_AddRef(This->pSite);
2934 return S_OK;
2937 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, PVOID *ppvSite)
2939 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2941 TRACE("(%p/%p)->(%s)\n", This, iface,debugstr_guid(riid));
2943 *ppvSite = NULL;
2944 if (!This->pSite)
2945 return E_FAIL;
2946 else
2947 return IUnknown_QueryInterface(This->pSite, riid, ppvSite);
2950 static const IObjectWithSiteVtbl IObjectWithSite_VTable =
2952 ObjectWithSite_QueryInterface,
2953 ObjectWithSite_AddRef,
2954 ObjectWithSite_Release,
2955 ObjectWithSite_SetSite,
2956 ObjectWithSite_GetSite,
2959 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2961 HRESULT hr = E_NOINTERFACE;
2962 int i;
2963 int entry;
2965 /* Check if the interface type is already registered */
2966 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2967 if (riid == pGraph->ItfCacheEntries[entry].riid)
2969 if (pGraph->ItfCacheEntries[entry].iface)
2971 /* Return the interface if available */
2972 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2973 return S_OK;
2975 break;
2978 if (entry >= MAX_ITF_CACHE_ENTRIES)
2980 FIXME("Not enough space to store interface in the cache\n");
2981 return E_OUTOFMEMORY;
2984 /* Find a filter supporting the requested interface */
2985 for (i = 0; i < pGraph->nFilters; i++)
2987 hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2988 if (hr == S_OK)
2990 pGraph->ItfCacheEntries[entry].riid = riid;
2991 pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2992 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2993 if (entry >= pGraph->nItfCacheEntries)
2994 pGraph->nItfCacheEntries++;
2995 return S_OK;
2997 if (hr != E_NOINTERFACE)
2998 return hr;
3001 return hr;
3004 static inline IFilterGraphImpl *impl_from_IBasicAudio(IBasicAudio *iface)
3006 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicAudio_iface);
3009 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID riid, void **ppvObj)
3011 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3013 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
3015 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
3018 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
3020 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3022 TRACE("(%p/%p)->()\n", This, iface);
3024 return IUnknown_AddRef(This->outer_unk);
3027 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
3029 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3031 TRACE("(%p/%p)->()\n", This, iface);
3033 return IUnknown_Release(This->outer_unk);
3036 /*** IDispatch methods ***/
3037 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *pctinfo)
3039 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3040 IBasicAudio* pBasicAudio;
3041 HRESULT hr;
3043 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3045 EnterCriticalSection(&This->cs);
3047 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3049 if (hr == S_OK)
3050 hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
3052 LeaveCriticalSection(&This->cs);
3054 return hr;
3057 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT iTInfo, LCID lcid,
3058 ITypeInfo **ppTInfo)
3060 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3061 IBasicAudio* pBasicAudio;
3062 HRESULT hr;
3064 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3066 EnterCriticalSection(&This->cs);
3068 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3070 if (hr == S_OK)
3071 hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
3073 LeaveCriticalSection(&This->cs);
3075 return hr;
3078 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID riid, LPOLESTR *rgszNames,
3079 UINT cNames, LCID lcid, DISPID *rgDispId)
3081 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3082 IBasicAudio* pBasicAudio;
3083 HRESULT hr;
3085 TRACE("(%p/%p)->(%s, %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), rgszNames, cNames,
3086 lcid, rgDispId);
3088 EnterCriticalSection(&This->cs);
3090 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3092 if (hr == S_OK)
3093 hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
3095 LeaveCriticalSection(&This->cs);
3097 return hr;
3100 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID dispIdMember, REFIID riid,
3101 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3102 UINT *puArgErr)
3104 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3105 IBasicAudio* pBasicAudio;
3106 HRESULT hr;
3108 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember,
3109 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3111 EnterCriticalSection(&This->cs);
3113 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3115 if (hr == S_OK)
3116 hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3118 LeaveCriticalSection(&This->cs);
3120 return hr;
3123 /*** IBasicAudio methods ***/
3124 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
3126 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3127 IBasicAudio* pBasicAudio;
3128 HRESULT hr;
3130 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
3132 EnterCriticalSection(&This->cs);
3134 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3136 if (hr == S_OK)
3137 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
3139 LeaveCriticalSection(&This->cs);
3141 return hr;
3144 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
3146 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3147 IBasicAudio* pBasicAudio;
3148 HRESULT hr;
3150 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
3152 EnterCriticalSection(&This->cs);
3154 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3156 if (hr == S_OK)
3157 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
3159 LeaveCriticalSection(&This->cs);
3161 return hr;
3164 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
3166 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3167 IBasicAudio* pBasicAudio;
3168 HRESULT hr;
3170 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
3172 EnterCriticalSection(&This->cs);
3174 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3176 if (hr == S_OK)
3177 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
3179 LeaveCriticalSection(&This->cs);
3181 return hr;
3184 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
3186 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3187 IBasicAudio* pBasicAudio;
3188 HRESULT hr;
3190 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
3192 EnterCriticalSection(&This->cs);
3194 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3196 if (hr == S_OK)
3197 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
3199 LeaveCriticalSection(&This->cs);
3201 return hr;
3204 static const IBasicAudioVtbl IBasicAudio_VTable =
3206 BasicAudio_QueryInterface,
3207 BasicAudio_AddRef,
3208 BasicAudio_Release,
3209 BasicAudio_GetTypeInfoCount,
3210 BasicAudio_GetTypeInfo,
3211 BasicAudio_GetIDsOfNames,
3212 BasicAudio_Invoke,
3213 BasicAudio_put_Volume,
3214 BasicAudio_get_Volume,
3215 BasicAudio_put_Balance,
3216 BasicAudio_get_Balance
3219 static inline IFilterGraphImpl *impl_from_IBasicVideo2(IBasicVideo2 *iface)
3221 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicVideo2_iface);
3224 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID riid, void **ppvObj)
3226 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3228 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
3230 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
3233 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
3235 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3237 TRACE("(%p/%p)->()\n", This, iface);
3239 return IUnknown_AddRef(This->outer_unk);
3242 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
3244 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3246 TRACE("(%p/%p)->()\n", This, iface);
3248 return IUnknown_Release(This->outer_unk);
3251 /*** IDispatch methods ***/
3252 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *pctinfo)
3254 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3255 IBasicVideo *pBasicVideo;
3256 HRESULT hr;
3258 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3260 EnterCriticalSection(&This->cs);
3262 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3264 if (hr == S_OK)
3265 hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
3267 LeaveCriticalSection(&This->cs);
3269 return hr;
3272 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT iTInfo, LCID lcid,
3273 ITypeInfo **ppTInfo)
3275 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3276 IBasicVideo *pBasicVideo;
3277 HRESULT hr;
3279 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3281 EnterCriticalSection(&This->cs);
3283 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3285 if (hr == S_OK)
3286 hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
3288 LeaveCriticalSection(&This->cs);
3290 return hr;
3293 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID riid,
3294 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
3296 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3297 IBasicVideo *pBasicVideo;
3298 HRESULT hr;
3300 TRACE("(%p/%p)->(%s, %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), rgszNames, cNames,
3301 lcid, rgDispId);
3303 EnterCriticalSection(&This->cs);
3305 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3307 if (hr == S_OK)
3308 hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
3310 LeaveCriticalSection(&This->cs);
3312 return hr;
3315 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID dispIdMember, REFIID riid,
3316 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3317 UINT *puArgErr)
3319 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3320 IBasicVideo *pBasicVideo;
3321 HRESULT hr;
3323 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember,
3324 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3326 EnterCriticalSection(&This->cs);
3328 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3330 if (hr == S_OK)
3331 hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3333 LeaveCriticalSection(&This->cs);
3335 return hr;
3338 /*** IBasicVideo methods ***/
3339 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3341 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3342 IBasicVideo *pBasicVideo;
3343 HRESULT hr;
3345 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3347 EnterCriticalSection(&This->cs);
3349 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3351 if (hr == S_OK)
3352 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3354 LeaveCriticalSection(&This->cs);
3356 return hr;
3359 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3361 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3362 IBasicVideo *pBasicVideo;
3363 HRESULT hr;
3365 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3367 EnterCriticalSection(&This->cs);
3369 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3371 if (hr == S_OK)
3372 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3374 LeaveCriticalSection(&This->cs);
3376 return hr;
3379 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3381 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3382 IBasicVideo *pBasicVideo;
3383 HRESULT hr;
3385 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3387 EnterCriticalSection(&This->cs);
3389 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3391 if (hr == S_OK)
3392 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3394 LeaveCriticalSection(&This->cs);
3396 return hr;
3399 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3401 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3402 IBasicVideo *pBasicVideo;
3403 HRESULT hr;
3405 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3407 EnterCriticalSection(&This->cs);
3409 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3411 if (hr == S_OK)
3412 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3414 LeaveCriticalSection(&This->cs);
3416 return hr;
3419 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3421 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3422 IBasicVideo *pBasicVideo;
3423 HRESULT hr;
3425 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3427 EnterCriticalSection(&This->cs);
3429 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3431 if (hr == S_OK)
3432 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3434 LeaveCriticalSection(&This->cs);
3436 return hr;
3439 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3441 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3442 IBasicVideo *pBasicVideo;
3443 HRESULT hr;
3445 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3447 EnterCriticalSection(&This->cs);
3449 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3451 if (hr == S_OK)
3452 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3454 LeaveCriticalSection(&This->cs);
3456 return hr;
3459 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3461 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3462 IBasicVideo *pBasicVideo;
3463 HRESULT hr;
3465 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3467 EnterCriticalSection(&This->cs);
3469 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3471 if (hr == S_OK)
3472 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3474 LeaveCriticalSection(&This->cs);
3476 return hr;
3479 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3481 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3482 IBasicVideo *pBasicVideo;
3483 HRESULT hr;
3485 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3487 EnterCriticalSection(&This->cs);
3489 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3491 if (hr == S_OK)
3492 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3494 LeaveCriticalSection(&This->cs);
3496 return hr;
3499 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3501 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3502 IBasicVideo *pBasicVideo;
3503 HRESULT hr;
3505 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3507 EnterCriticalSection(&This->cs);
3509 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3511 if (hr == S_OK)
3512 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3514 LeaveCriticalSection(&This->cs);
3516 return hr;
3519 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3521 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3522 IBasicVideo *pBasicVideo;
3523 HRESULT hr;
3525 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3527 EnterCriticalSection(&This->cs);
3529 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3531 if (hr == S_OK)
3532 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3534 LeaveCriticalSection(&This->cs);
3536 return hr;
3539 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3541 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3542 IBasicVideo *pBasicVideo;
3543 HRESULT hr;
3545 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3547 EnterCriticalSection(&This->cs);
3549 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3551 if (hr == S_OK)
3552 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3554 LeaveCriticalSection(&This->cs);
3556 return hr;
3559 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3561 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3562 IBasicVideo *pBasicVideo;
3563 HRESULT hr;
3565 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3567 EnterCriticalSection(&This->cs);
3569 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3571 if (hr == S_OK)
3572 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3574 LeaveCriticalSection(&This->cs);
3576 return hr;
3579 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3581 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3582 IBasicVideo *pBasicVideo;
3583 HRESULT hr;
3585 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3587 EnterCriticalSection(&This->cs);
3589 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3591 if (hr == S_OK)
3592 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3594 LeaveCriticalSection(&This->cs);
3596 return hr;
3599 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3601 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3602 IBasicVideo *pBasicVideo;
3603 HRESULT hr;
3605 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3607 EnterCriticalSection(&This->cs);
3609 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3611 if (hr == S_OK)
3612 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3614 LeaveCriticalSection(&This->cs);
3616 return hr;
3619 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3621 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3622 IBasicVideo *pBasicVideo;
3623 HRESULT hr;
3625 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3627 EnterCriticalSection(&This->cs);
3629 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3631 if (hr == S_OK)
3632 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3634 LeaveCriticalSection(&This->cs);
3636 return hr;
3639 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3641 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3642 IBasicVideo *pBasicVideo;
3643 HRESULT hr;
3645 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3647 EnterCriticalSection(&This->cs);
3649 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3651 if (hr == S_OK)
3652 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3654 LeaveCriticalSection(&This->cs);
3656 return hr;
3659 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3661 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3662 IBasicVideo *pBasicVideo;
3663 HRESULT hr;
3665 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3667 EnterCriticalSection(&This->cs);
3669 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3671 if (hr == S_OK)
3672 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3674 LeaveCriticalSection(&This->cs);
3676 return hr;
3679 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3681 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3682 IBasicVideo *pBasicVideo;
3683 HRESULT hr;
3685 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3687 EnterCriticalSection(&This->cs);
3689 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3691 if (hr == S_OK)
3692 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3694 LeaveCriticalSection(&This->cs);
3696 return hr;
3699 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3701 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3702 IBasicVideo *pBasicVideo;
3703 HRESULT hr;
3705 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3707 EnterCriticalSection(&This->cs);
3709 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3711 if (hr == S_OK)
3712 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3714 LeaveCriticalSection(&This->cs);
3716 return hr;
3719 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3721 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3722 IBasicVideo *pBasicVideo;
3723 HRESULT hr;
3725 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3727 EnterCriticalSection(&This->cs);
3729 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3731 if (hr == S_OK)
3732 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3734 LeaveCriticalSection(&This->cs);
3736 return hr;
3739 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3740 LONG *pDestinationHeight)
3742 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3743 IBasicVideo *pBasicVideo;
3744 HRESULT hr;
3746 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3748 EnterCriticalSection(&This->cs);
3750 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3752 if (hr == S_OK)
3753 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3755 LeaveCriticalSection(&This->cs);
3757 return hr;
3760 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3761 LONG Width, LONG Height)
3763 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3764 IBasicVideo *pBasicVideo;
3765 HRESULT hr;
3767 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3769 EnterCriticalSection(&This->cs);
3771 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3773 if (hr == S_OK)
3774 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3776 LeaveCriticalSection(&This->cs);
3778 return hr;
3781 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3782 LONG *pWidth, LONG *pHeight)
3784 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3785 IBasicVideo *pBasicVideo;
3786 HRESULT hr;
3788 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3790 EnterCriticalSection(&This->cs);
3792 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3794 if (hr == S_OK)
3795 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3797 LeaveCriticalSection(&This->cs);
3799 return hr;
3802 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3804 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3805 IBasicVideo *pBasicVideo;
3806 HRESULT hr;
3808 TRACE("(%p/%p)->()\n", This, iface);
3810 EnterCriticalSection(&This->cs);
3812 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3814 if (hr == S_OK)
3815 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3817 LeaveCriticalSection(&This->cs);
3819 return hr;
3822 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3823 LONG Width, LONG Height)
3825 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3826 IBasicVideo *pBasicVideo;
3827 HRESULT hr;
3829 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3831 EnterCriticalSection(&This->cs);
3833 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3835 if (hr == S_OK)
3836 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3838 LeaveCriticalSection(&This->cs);
3840 return hr;
3843 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3844 LONG *pTop, LONG *pWidth, LONG *pHeight)
3846 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3847 IBasicVideo *pBasicVideo;
3848 HRESULT hr;
3850 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3852 EnterCriticalSection(&This->cs);
3854 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3856 if (hr == S_OK)
3857 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3859 LeaveCriticalSection(&This->cs);
3861 return hr;
3864 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3866 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3867 IBasicVideo *pBasicVideo;
3868 HRESULT hr;
3870 TRACE("(%p/%p)->()\n", This, iface);
3872 EnterCriticalSection(&This->cs);
3874 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3876 if (hr == S_OK)
3877 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3879 LeaveCriticalSection(&This->cs);
3881 return hr;
3884 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3886 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3887 IBasicVideo *pBasicVideo;
3888 HRESULT hr;
3890 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3892 EnterCriticalSection(&This->cs);
3894 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3896 if (hr == S_OK)
3897 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3899 LeaveCriticalSection(&This->cs);
3901 return hr;
3904 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3905 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3907 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3908 IBasicVideo *pBasicVideo;
3909 HRESULT hr;
3911 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3913 EnterCriticalSection(&This->cs);
3915 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3917 if (hr == S_OK)
3918 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3920 LeaveCriticalSection(&This->cs);
3922 return hr;
3925 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3926 LONG *pDIBImage)
3928 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3929 IBasicVideo *pBasicVideo;
3930 HRESULT hr;
3932 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3934 EnterCriticalSection(&This->cs);
3936 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3938 if (hr == S_OK)
3939 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3941 LeaveCriticalSection(&This->cs);
3943 return hr;
3946 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3948 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3949 IBasicVideo *pBasicVideo;
3950 HRESULT hr;
3952 TRACE("(%p/%p)->()\n", This, iface);
3954 EnterCriticalSection(&This->cs);
3956 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3958 if (hr == S_OK)
3959 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3961 LeaveCriticalSection(&This->cs);
3963 return hr;
3966 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3968 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3969 IBasicVideo *pBasicVideo;
3970 HRESULT hr;
3972 TRACE("(%p/%p)->()\n", This, iface);
3974 EnterCriticalSection(&This->cs);
3976 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3978 if (hr == S_OK)
3979 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3981 LeaveCriticalSection(&This->cs);
3983 return hr;
3986 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3987 LONG *plAspectY)
3989 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3990 IBasicVideo2 *pBasicVideo2;
3991 HRESULT hr;
3993 TRACE("(%p/%p)->()\n", This, iface);
3995 EnterCriticalSection(&This->cs);
3997 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3999 if (hr == S_OK)
4000 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
4002 LeaveCriticalSection(&This->cs);
4004 return hr;
4007 static const IBasicVideo2Vtbl IBasicVideo_VTable =
4009 BasicVideo_QueryInterface,
4010 BasicVideo_AddRef,
4011 BasicVideo_Release,
4012 BasicVideo_GetTypeInfoCount,
4013 BasicVideo_GetTypeInfo,
4014 BasicVideo_GetIDsOfNames,
4015 BasicVideo_Invoke,
4016 BasicVideo_get_AvgTimePerFrame,
4017 BasicVideo_get_BitRate,
4018 BasicVideo_get_BitErrorRate,
4019 BasicVideo_get_VideoWidth,
4020 BasicVideo_get_VideoHeight,
4021 BasicVideo_put_SourceLeft,
4022 BasicVideo_get_SourceLeft,
4023 BasicVideo_put_SourceWidth,
4024 BasicVideo_get_SourceWidth,
4025 BasicVideo_put_SourceTop,
4026 BasicVideo_get_SourceTop,
4027 BasicVideo_put_SourceHeight,
4028 BasicVideo_get_SourceHeight,
4029 BasicVideo_put_DestinationLeft,
4030 BasicVideo_get_DestinationLeft,
4031 BasicVideo_put_DestinationWidth,
4032 BasicVideo_get_DestinationWidth,
4033 BasicVideo_put_DestinationTop,
4034 BasicVideo_get_DestinationTop,
4035 BasicVideo_put_DestinationHeight,
4036 BasicVideo_get_DestinationHeight,
4037 BasicVideo_SetSourcePosition,
4038 BasicVideo_GetSourcePosition,
4039 BasicVideo_SetDefaultSourcePosition,
4040 BasicVideo_SetDestinationPosition,
4041 BasicVideo_GetDestinationPosition,
4042 BasicVideo_SetDefaultDestinationPosition,
4043 BasicVideo_GetVideoSize,
4044 BasicVideo_GetVideoPaletteEntries,
4045 BasicVideo_GetCurrentImage,
4046 BasicVideo_IsUsingDefaultSource,
4047 BasicVideo_IsUsingDefaultDestination,
4048 BasicVideo2_GetPreferredAspectRatio
4051 static inline IFilterGraphImpl *impl_from_IVideoWindow(IVideoWindow *iface)
4053 return CONTAINING_RECORD(iface, IFilterGraphImpl, IVideoWindow_iface);
4056 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID riid, void **ppvObj)
4058 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4060 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
4062 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
4065 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
4067 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4069 TRACE("(%p/%p)->()\n", This, iface);
4071 return IUnknown_AddRef(This->outer_unk);
4074 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
4076 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4078 TRACE("(%p/%p)->()\n", This, iface);
4080 return IUnknown_Release(This->outer_unk);
4083 /*** IDispatch methods ***/
4084 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *pctinfo)
4086 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4087 IVideoWindow *pVideoWindow;
4088 HRESULT hr;
4090 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
4092 EnterCriticalSection(&This->cs);
4094 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4096 if (hr == S_OK)
4097 hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
4099 LeaveCriticalSection(&This->cs);
4101 return hr;
4104 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT iTInfo, LCID lcid,
4105 ITypeInfo **ppTInfo)
4107 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4108 IVideoWindow *pVideoWindow;
4109 HRESULT hr;
4111 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
4113 EnterCriticalSection(&This->cs);
4115 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4117 if (hr == S_OK)
4118 hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
4120 LeaveCriticalSection(&This->cs);
4122 return hr;
4125 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID riid,
4126 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4128 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4129 IVideoWindow *pVideoWindow;
4130 HRESULT hr;
4132 TRACE("(%p/%p)->(%s, %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), rgszNames, cNames,
4133 lcid, rgDispId);
4135 EnterCriticalSection(&This->cs);
4137 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4139 if (hr == S_OK)
4140 hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
4142 LeaveCriticalSection(&This->cs);
4144 return hr;
4147 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID dispIdMember, REFIID riid,
4148 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4149 UINT*puArgErr)
4151 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4152 IVideoWindow *pVideoWindow;
4153 HRESULT hr;
4155 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember,
4156 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4158 EnterCriticalSection(&This->cs);
4160 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4162 if (hr == S_OK)
4163 hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4165 LeaveCriticalSection(&This->cs);
4167 return hr;
4171 /*** IVideoWindow methods ***/
4172 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
4174 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4175 IVideoWindow *pVideoWindow;
4176 HRESULT hr;
4178 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
4180 EnterCriticalSection(&This->cs);
4182 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4184 if (hr == S_OK)
4185 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
4187 LeaveCriticalSection(&This->cs);
4189 return hr;
4192 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
4194 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4195 IVideoWindow *pVideoWindow;
4196 HRESULT hr;
4198 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
4200 EnterCriticalSection(&This->cs);
4202 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4204 if (hr == S_OK)
4205 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
4207 LeaveCriticalSection(&This->cs);
4209 return hr;
4212 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
4214 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4215 IVideoWindow *pVideoWindow;
4216 HRESULT hr;
4218 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
4220 EnterCriticalSection(&This->cs);
4222 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4224 if (hr == S_OK)
4225 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
4227 LeaveCriticalSection(&This->cs);
4229 return hr;
4232 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
4234 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4235 IVideoWindow *pVideoWindow;
4236 HRESULT hr;
4238 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
4240 EnterCriticalSection(&This->cs);
4242 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4244 if (hr == S_OK)
4245 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
4247 LeaveCriticalSection(&This->cs);
4249 return hr;
4252 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
4254 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4255 IVideoWindow *pVideoWindow;
4256 HRESULT hr;
4258 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
4260 EnterCriticalSection(&This->cs);
4262 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4264 if (hr == S_OK)
4265 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
4267 LeaveCriticalSection(&This->cs);
4269 return hr;
4272 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
4274 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4275 IVideoWindow *pVideoWindow;
4276 HRESULT hr;
4278 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
4280 EnterCriticalSection(&This->cs);
4282 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4284 if (hr == S_OK)
4285 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
4287 LeaveCriticalSection(&This->cs);
4289 return hr;
4292 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
4294 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4295 IVideoWindow *pVideoWindow;
4296 HRESULT hr;
4298 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
4300 EnterCriticalSection(&This->cs);
4302 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4304 if (hr == S_OK)
4305 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4307 LeaveCriticalSection(&This->cs);
4309 return hr;
4312 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
4314 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4315 IVideoWindow *pVideoWindow;
4316 HRESULT hr;
4318 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4320 EnterCriticalSection(&This->cs);
4322 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4324 if (hr == S_OK)
4325 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4327 LeaveCriticalSection(&This->cs);
4329 return hr;
4332 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
4334 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4335 IVideoWindow *pVideoWindow;
4336 HRESULT hr;
4338 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4340 EnterCriticalSection(&This->cs);
4342 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4344 if (hr == S_OK)
4345 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4347 LeaveCriticalSection(&This->cs);
4349 return hr;
4352 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4354 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4355 IVideoWindow *pVideoWindow;
4356 HRESULT hr;
4358 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4360 EnterCriticalSection(&This->cs);
4362 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4364 if (hr == S_OK)
4365 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4367 LeaveCriticalSection(&This->cs);
4369 return hr;
4372 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4374 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4375 IVideoWindow *pVideoWindow;
4376 HRESULT hr;
4378 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4380 EnterCriticalSection(&This->cs);
4382 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4384 if (hr == S_OK)
4385 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4387 LeaveCriticalSection(&This->cs);
4389 return hr;
4392 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4393 LONG *pBackgroundPalette)
4395 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4396 IVideoWindow *pVideoWindow;
4397 HRESULT hr;
4399 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4401 EnterCriticalSection(&This->cs);
4403 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4405 if (hr == S_OK)
4406 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4408 LeaveCriticalSection(&This->cs);
4410 return hr;
4413 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4415 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4416 IVideoWindow *pVideoWindow;
4417 HRESULT hr;
4419 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4421 EnterCriticalSection(&This->cs);
4423 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4425 if (hr == S_OK)
4426 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4428 LeaveCriticalSection(&This->cs);
4430 return hr;
4433 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4435 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4436 IVideoWindow *pVideoWindow;
4437 HRESULT hr;
4439 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4441 EnterCriticalSection(&This->cs);
4443 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4445 if (hr == S_OK)
4446 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4448 LeaveCriticalSection(&This->cs);
4450 return hr;
4453 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4455 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4456 IVideoWindow *pVideoWindow;
4457 HRESULT hr;
4459 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4461 EnterCriticalSection(&This->cs);
4463 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4465 if (hr == S_OK)
4466 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4468 LeaveCriticalSection(&This->cs);
4470 return hr;
4473 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4475 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4476 IVideoWindow *pVideoWindow;
4477 HRESULT hr;
4479 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4481 EnterCriticalSection(&This->cs);
4483 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4485 if (hr == S_OK)
4486 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4488 LeaveCriticalSection(&This->cs);
4490 return hr;
4493 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4495 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4496 IVideoWindow *pVideoWindow;
4497 HRESULT hr;
4499 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4501 EnterCriticalSection(&This->cs);
4503 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4505 if (hr == S_OK)
4506 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4508 LeaveCriticalSection(&This->cs);
4510 return hr;
4513 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4515 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4516 IVideoWindow *pVideoWindow;
4517 HRESULT hr;
4519 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4521 EnterCriticalSection(&This->cs);
4523 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4525 if (hr == S_OK)
4526 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4528 LeaveCriticalSection(&This->cs);
4530 return hr;
4533 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4535 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4536 IVideoWindow *pVideoWindow;
4537 HRESULT hr;
4539 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4541 EnterCriticalSection(&This->cs);
4543 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4545 if (hr == S_OK)
4546 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4548 LeaveCriticalSection(&This->cs);
4550 return hr;
4553 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4555 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4556 IVideoWindow *pVideoWindow;
4557 HRESULT hr;
4559 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4561 EnterCriticalSection(&This->cs);
4563 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4565 if (hr == S_OK)
4566 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4568 LeaveCriticalSection(&This->cs);
4570 return hr;
4573 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4575 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4576 IVideoWindow *pVideoWindow;
4577 HRESULT hr;
4579 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4581 EnterCriticalSection(&This->cs);
4583 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4585 if (hr == S_OK)
4586 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4588 LeaveCriticalSection(&This->cs);
4590 return hr;
4593 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4595 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4596 IVideoWindow *pVideoWindow;
4597 HRESULT hr;
4599 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4601 EnterCriticalSection(&This->cs);
4603 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4605 if (hr == S_OK)
4606 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4608 LeaveCriticalSection(&This->cs);
4610 return hr;
4613 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4615 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4616 IVideoWindow *pVideoWindow;
4617 HRESULT hr;
4619 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4621 EnterCriticalSection(&This->cs);
4623 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4625 if (hr == S_OK)
4626 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4628 LeaveCriticalSection(&This->cs);
4630 return hr;
4633 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4635 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4636 IVideoWindow *pVideoWindow;
4637 HRESULT hr;
4639 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4641 EnterCriticalSection(&This->cs);
4643 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4645 if (hr == S_OK)
4646 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4648 LeaveCriticalSection(&This->cs);
4650 return hr;
4653 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4655 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4656 IVideoWindow *pVideoWindow;
4657 HRESULT hr;
4659 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4661 EnterCriticalSection(&This->cs);
4663 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4665 if (hr == S_OK)
4666 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4668 LeaveCriticalSection(&This->cs);
4670 return hr;
4673 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4675 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4676 IVideoWindow *pVideoWindow;
4677 HRESULT hr;
4679 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4681 EnterCriticalSection(&This->cs);
4683 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4685 if (hr == S_OK)
4686 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4688 LeaveCriticalSection(&This->cs);
4690 return hr;
4693 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4695 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4696 IVideoWindow *pVideoWindow;
4697 HRESULT hr;
4699 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4701 EnterCriticalSection(&This->cs);
4703 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4705 if (hr == S_OK)
4706 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4708 LeaveCriticalSection(&This->cs);
4710 return hr;
4713 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4715 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4716 IVideoWindow *pVideoWindow;
4717 HRESULT hr;
4719 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4721 EnterCriticalSection(&This->cs);
4723 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4725 if (hr == S_OK)
4726 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4728 LeaveCriticalSection(&This->cs);
4730 return hr;
4733 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4735 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4736 IVideoWindow *pVideoWindow;
4737 HRESULT hr;
4739 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4741 EnterCriticalSection(&This->cs);
4743 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4745 if (hr == S_OK)
4746 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4748 LeaveCriticalSection(&This->cs);
4750 return hr;
4753 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4755 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4756 IVideoWindow *pVideoWindow;
4757 HRESULT hr;
4759 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4761 EnterCriticalSection(&This->cs);
4763 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4765 if (hr == S_OK)
4766 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4768 LeaveCriticalSection(&This->cs);
4770 return hr;
4773 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4775 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4776 IVideoWindow *pVideoWindow;
4777 HRESULT hr;
4779 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4781 EnterCriticalSection(&This->cs);
4783 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4785 if (hr == S_OK)
4786 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4788 LeaveCriticalSection(&This->cs);
4790 return hr;
4793 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4794 LONG_PTR wParam, LONG_PTR lParam)
4796 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4797 IVideoWindow *pVideoWindow;
4798 HRESULT hr;
4800 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4802 EnterCriticalSection(&This->cs);
4804 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4806 if (hr == S_OK)
4807 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4809 LeaveCriticalSection(&This->cs);
4811 return hr;
4814 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4815 LONG Width, LONG Height)
4817 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4818 IVideoWindow *pVideoWindow;
4819 HRESULT hr;
4821 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4823 EnterCriticalSection(&This->cs);
4825 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4827 if (hr == S_OK)
4828 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4830 LeaveCriticalSection(&This->cs);
4832 return hr;
4835 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4836 LONG *pWidth, LONG *pHeight)
4838 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4839 IVideoWindow *pVideoWindow;
4840 HRESULT hr;
4842 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4844 EnterCriticalSection(&This->cs);
4846 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4848 if (hr == S_OK)
4849 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4851 LeaveCriticalSection(&This->cs);
4853 return hr;
4856 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4857 LONG *pHeight)
4859 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4860 IVideoWindow *pVideoWindow;
4861 HRESULT hr;
4863 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4865 EnterCriticalSection(&This->cs);
4867 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4869 if (hr == S_OK)
4870 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4872 LeaveCriticalSection(&This->cs);
4874 return hr;
4877 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4878 LONG *pHeight)
4880 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4881 IVideoWindow *pVideoWindow;
4882 HRESULT hr;
4884 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4886 EnterCriticalSection(&This->cs);
4888 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4890 if (hr == S_OK)
4891 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4893 LeaveCriticalSection(&This->cs);
4895 return hr;
4898 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4899 LONG *pWidth, LONG *pHeight)
4901 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4902 IVideoWindow *pVideoWindow;
4903 HRESULT hr;
4905 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4907 EnterCriticalSection(&This->cs);
4909 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4911 if (hr == S_OK)
4912 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4914 LeaveCriticalSection(&This->cs);
4916 return hr;
4919 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4921 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4922 IVideoWindow *pVideoWindow;
4923 HRESULT hr;
4925 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4927 EnterCriticalSection(&This->cs);
4929 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4931 if (hr == S_OK)
4932 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4934 LeaveCriticalSection(&This->cs);
4936 return hr;
4939 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4941 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4942 IVideoWindow *pVideoWindow;
4943 HRESULT hr;
4945 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4947 EnterCriticalSection(&This->cs);
4949 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4951 if (hr == S_OK)
4952 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4954 LeaveCriticalSection(&This->cs);
4956 return hr;
4960 static const IVideoWindowVtbl IVideoWindow_VTable =
4962 VideoWindow_QueryInterface,
4963 VideoWindow_AddRef,
4964 VideoWindow_Release,
4965 VideoWindow_GetTypeInfoCount,
4966 VideoWindow_GetTypeInfo,
4967 VideoWindow_GetIDsOfNames,
4968 VideoWindow_Invoke,
4969 VideoWindow_put_Caption,
4970 VideoWindow_get_Caption,
4971 VideoWindow_put_WindowStyle,
4972 VideoWindow_get_WindowStyle,
4973 VideoWindow_put_WindowStyleEx,
4974 VideoWindow_get_WindowStyleEx,
4975 VideoWindow_put_AutoShow,
4976 VideoWindow_get_AutoShow,
4977 VideoWindow_put_WindowState,
4978 VideoWindow_get_WindowState,
4979 VideoWindow_put_BackgroundPalette,
4980 VideoWindow_get_BackgroundPalette,
4981 VideoWindow_put_Visible,
4982 VideoWindow_get_Visible,
4983 VideoWindow_put_Left,
4984 VideoWindow_get_Left,
4985 VideoWindow_put_Width,
4986 VideoWindow_get_Width,
4987 VideoWindow_put_Top,
4988 VideoWindow_get_Top,
4989 VideoWindow_put_Height,
4990 VideoWindow_get_Height,
4991 VideoWindow_put_Owner,
4992 VideoWindow_get_Owner,
4993 VideoWindow_put_MessageDrain,
4994 VideoWindow_get_MessageDrain,
4995 VideoWindow_get_BorderColor,
4996 VideoWindow_put_BorderColor,
4997 VideoWindow_get_FullScreenMode,
4998 VideoWindow_put_FullScreenMode,
4999 VideoWindow_SetWindowForeground,
5000 VideoWindow_NotifyOwnerMessage,
5001 VideoWindow_SetWindowPosition,
5002 VideoWindow_GetWindowPosition,
5003 VideoWindow_GetMinIdealImageSize,
5004 VideoWindow_GetMaxIdealImageSize,
5005 VideoWindow_GetRestorePosition,
5006 VideoWindow_HideCursor,
5007 VideoWindow_IsCursorHidden
5010 static inline IFilterGraphImpl *impl_from_IMediaEventEx(IMediaEventEx *iface)
5012 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventEx_iface);
5015 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID riid, void **ppvObj)
5017 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5019 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
5021 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
5024 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
5026 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5028 TRACE("(%p/%p)->()\n", This, iface);
5030 return IUnknown_AddRef(This->outer_unk);
5033 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
5035 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5037 TRACE("(%p/%p)->()\n", This, iface);
5039 return IUnknown_Release(This->outer_unk);
5042 /*** IDispatch methods ***/
5043 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *pctinfo)
5045 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5047 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
5049 return S_OK;
5052 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT iTInfo, LCID lcid,
5053 ITypeInfo **ppTInfo)
5055 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5057 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
5059 return S_OK;
5062 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID riid,
5063 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
5065 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5067 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
5068 cNames, lcid, rgDispId);
5070 return S_OK;
5073 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID dispIdMember, REFIID riid,
5074 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
5075 UINT *puArgErr)
5077 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5079 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
5080 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
5082 return S_OK;
5085 /*** IMediaEvent methods ***/
5086 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *hEvent)
5088 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5090 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
5092 *hEvent = (OAEVENT)This->evqueue.msg_event;
5094 return S_OK;
5097 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *lEventCode, LONG_PTR *lParam1,
5098 LONG_PTR *lParam2, LONG msTimeout)
5100 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5101 Event evt;
5103 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
5105 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
5107 *lEventCode = evt.lEventCode;
5108 *lParam1 = evt.lParam1;
5109 *lParam2 = evt.lParam2;
5110 return S_OK;
5113 *lEventCode = 0;
5114 return E_ABORT;
5117 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
5118 LONG *pEvCode)
5120 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5122 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
5124 if (This->state != State_Running)
5125 return VFW_E_WRONG_STATE;
5127 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
5129 *pEvCode = This->CompletionStatus;
5130 return S_OK;
5133 *pEvCode = 0;
5134 return E_ABORT;
5137 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5139 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5141 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5143 if (lEvCode == EC_COMPLETE)
5144 This->HandleEcComplete = FALSE;
5145 else if (lEvCode == EC_REPAINT)
5146 This->HandleEcRepaint = FALSE;
5147 else if (lEvCode == EC_CLOCK_CHANGED)
5148 This->HandleEcClockChanged = FALSE;
5149 else
5150 return S_FALSE;
5152 return S_OK;
5155 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5157 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5159 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5161 if (lEvCode == EC_COMPLETE)
5162 This->HandleEcComplete = TRUE;
5163 else if (lEvCode == EC_REPAINT)
5164 This->HandleEcRepaint = TRUE;
5165 else if (lEvCode == EC_CLOCK_CHANGED)
5166 This->HandleEcClockChanged = TRUE;
5167 else
5168 return S_FALSE;
5170 return S_OK;
5173 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG lEvCode,
5174 LONG_PTR lParam1, LONG_PTR lParam2)
5176 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5178 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
5180 return S_OK;
5183 /*** IMediaEventEx methods ***/
5184 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface, OAHWND hwnd, LONG lMsg,
5185 LONG_PTR lInstanceData)
5187 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5189 TRACE("(%p/%p)->(%08lx, %d, %08lx)\n", This, iface, hwnd, lMsg, lInstanceData);
5191 This->notif.hWnd = (HWND)hwnd;
5192 This->notif.msg = lMsg;
5193 This->notif.instance = lInstanceData;
5195 return S_OK;
5198 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG lNoNotifyFlags)
5200 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5202 TRACE("(%p/%p)->(%d)\n", This, iface, lNoNotifyFlags);
5204 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
5205 return E_INVALIDARG;
5207 This->notif.disabled = lNoNotifyFlags;
5209 return S_OK;
5212 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *lplNoNotifyFlags)
5214 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5216 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
5218 if (!lplNoNotifyFlags)
5219 return E_POINTER;
5221 *lplNoNotifyFlags = This->notif.disabled;
5223 return S_OK;
5227 static const IMediaEventExVtbl IMediaEventEx_VTable =
5229 MediaEvent_QueryInterface,
5230 MediaEvent_AddRef,
5231 MediaEvent_Release,
5232 MediaEvent_GetTypeInfoCount,
5233 MediaEvent_GetTypeInfo,
5234 MediaEvent_GetIDsOfNames,
5235 MediaEvent_Invoke,
5236 MediaEvent_GetEventHandle,
5237 MediaEvent_GetEvent,
5238 MediaEvent_WaitForCompletion,
5239 MediaEvent_CancelDefaultHandling,
5240 MediaEvent_RestoreDefaultHandling,
5241 MediaEvent_FreeEventParams,
5242 MediaEvent_SetNotifyWindow,
5243 MediaEvent_SetNotifyFlags,
5244 MediaEvent_GetNotifyFlags
5248 static inline IFilterGraphImpl *impl_from_IMediaFilter(IMediaFilter *iface)
5250 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaFilter_iface);
5253 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, void **ppv)
5255 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5257 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5260 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
5262 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5264 return IUnknown_AddRef(This->outer_unk);
5267 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
5269 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5271 return IUnknown_Release(This->outer_unk);
5274 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
5276 FIXME("(%p): stub\n", pClassID);
5278 return E_NOTIMPL;
5281 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
5283 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5285 return MediaControl_Stop(&This->IMediaControl_iface);
5288 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5290 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5292 return MediaControl_Pause(&This->IMediaControl_iface);
5295 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
5297 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5299 if (tStart)
5300 FIXME("Run called with non-null tStart: %x%08x\n",
5301 (int)(tStart>>32), (int)tStart);
5303 return MediaControl_Run(&This->IMediaControl_iface);
5306 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout,
5307 FILTER_STATE *pState)
5309 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5311 return MediaControl_GetState(&This->IMediaControl_iface, dwMsTimeout, (OAFilterState*)pState);
5314 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5316 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5317 HRESULT hr = S_OK;
5318 int i;
5320 TRACE("(%p/%p)->(%p)\n", iface, This, pClock);
5322 EnterCriticalSection(&This->cs);
5324 for (i = 0;i < This->nFilters;i++)
5326 hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5327 if (FAILED(hr))
5328 break;
5331 if (FAILED(hr))
5333 for(;i >= 0;i--)
5334 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5336 else
5338 if (This->refClock)
5339 IReferenceClock_Release(This->refClock);
5340 This->refClock = pClock;
5341 if (This->refClock)
5342 IReferenceClock_AddRef(This->refClock);
5343 This->defaultclock = FALSE;
5345 if (This->HandleEcClockChanged)
5347 IMediaEventSink *pEventSink;
5348 HRESULT eshr;
5350 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (void **)&pEventSink);
5351 if (SUCCEEDED(eshr))
5353 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5354 IMediaEventSink_Release(pEventSink);
5359 LeaveCriticalSection(&This->cs);
5361 return hr;
5364 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5366 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5368 TRACE("(%p/%p)->(%p)\n", iface, This, ppClock);
5370 if (!ppClock)
5371 return E_POINTER;
5373 EnterCriticalSection(&This->cs);
5375 *ppClock = This->refClock;
5376 if (*ppClock)
5377 IReferenceClock_AddRef(*ppClock);
5379 LeaveCriticalSection(&This->cs);
5381 return S_OK;
5384 static const IMediaFilterVtbl IMediaFilter_VTable =
5386 MediaFilter_QueryInterface,
5387 MediaFilter_AddRef,
5388 MediaFilter_Release,
5389 MediaFilter_GetClassID,
5390 MediaFilter_Stop,
5391 MediaFilter_Pause,
5392 MediaFilter_Run,
5393 MediaFilter_GetState,
5394 MediaFilter_SetSyncSource,
5395 MediaFilter_GetSyncSource
5398 static inline IFilterGraphImpl *impl_from_IMediaEventSink(IMediaEventSink *iface)
5400 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventSink_iface);
5403 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, void **ppv)
5405 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5407 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5410 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5412 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5414 return IUnknown_AddRef(This->outer_unk);
5417 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5419 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5421 return IUnknown_Release(This->outer_unk);
5424 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG EventCode,
5425 LONG_PTR EventParam1, LONG_PTR EventParam2)
5427 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5428 Event evt;
5430 TRACE("(%p/%p)->(%d, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5432 /* We need thread safety here, let's use the events queue's one */
5433 EnterCriticalSection(&This->evqueue.msg_crst);
5435 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5437 TRACE("Process EC_COMPLETE notification\n");
5438 if (++This->EcCompleteCount == This->nRenderers)
5440 evt.lEventCode = EC_COMPLETE;
5441 evt.lParam1 = S_OK;
5442 evt.lParam2 = 0;
5443 TRACE("Send EC_COMPLETE to app\n");
5444 EventsQueue_PutEvent(&This->evqueue, &evt);
5445 if (!This->notif.disabled && This->notif.hWnd)
5447 TRACE("Send Window message\n");
5448 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5450 This->CompletionStatus = EC_COMPLETE;
5451 SetEvent(This->hEventCompletion);
5454 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5456 /* FIXME: Not handled yet */
5458 else
5460 evt.lEventCode = EventCode;
5461 evt.lParam1 = EventParam1;
5462 evt.lParam2 = EventParam2;
5463 EventsQueue_PutEvent(&This->evqueue, &evt);
5464 if (!This->notif.disabled && This->notif.hWnd)
5465 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5468 LeaveCriticalSection(&This->evqueue.msg_crst);
5469 return S_OK;
5472 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5474 MediaEventSink_QueryInterface,
5475 MediaEventSink_AddRef,
5476 MediaEventSink_Release,
5477 MediaEventSink_Notify
5480 static inline IFilterGraphImpl *impl_from_IGraphConfig(IGraphConfig *iface)
5482 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphConfig_iface);
5485 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, void **ppv)
5487 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5489 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5492 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5494 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5496 return IUnknown_AddRef(This->outer_unk);
5499 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5501 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5503 return IUnknown_Release(This->outer_unk);
5506 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *pOutputPin, IPin *pInputPin,
5507 const AM_MEDIA_TYPE *pmtFirstConnection, IBaseFilter *pUsingFilter, HANDLE hAbortEvent,
5508 DWORD dwFlags)
5510 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5512 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5514 return E_NOTIMPL;
5517 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface, IGraphConfigCallback *pCallback,
5518 void *pvContext, DWORD dwFlags, HANDLE hAbortEvent)
5520 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5521 HRESULT hr;
5523 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5525 if (hAbortEvent)
5526 FIXME("The parameter hAbortEvent is not handled!\n");
5528 EnterCriticalSection(&This->cs);
5530 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5532 LeaveCriticalSection(&This->cs);
5534 return hr;
5537 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5539 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5541 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5543 return E_NOTIMPL;
5546 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5548 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5550 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5552 return E_NOTIMPL;
5555 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5557 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5559 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5561 return E_NOTIMPL;
5564 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5566 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5568 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5570 return E_NOTIMPL;
5573 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5574 IPinConnection *pConnection, HANDLE hEventAbort)
5576 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5578 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5580 return E_NOTIMPL;
5583 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5584 DWORD dwFlags)
5586 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5588 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5590 return E_NOTIMPL;
5593 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5594 DWORD *dwFlags)
5596 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5598 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5600 return E_NOTIMPL;
5603 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *pFilter,
5604 DWORD dwFlags)
5606 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5608 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5610 return E_NOTIMPL;
5613 static const IGraphConfigVtbl IGraphConfig_VTable =
5615 GraphConfig_QueryInterface,
5616 GraphConfig_AddRef,
5617 GraphConfig_Release,
5618 GraphConfig_Reconnect,
5619 GraphConfig_Reconfigure,
5620 GraphConfig_AddFilterToCache,
5621 GraphConfig_EnumCacheFilter,
5622 GraphConfig_RemoveFilterFromCache,
5623 GraphConfig_GetStartTime,
5624 GraphConfig_PushThroughData,
5625 GraphConfig_SetFilterFlags,
5626 GraphConfig_GetFilterFlags,
5627 GraphConfig_RemoveFilterEx
5630 static inline IFilterGraphImpl *impl_from_IGraphVersion(IGraphVersion *iface)
5632 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphVersion_iface);
5635 static HRESULT WINAPI GraphVersion_QueryInterface(IGraphVersion *iface, REFIID riid, void **ppv)
5637 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5639 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5642 static ULONG WINAPI GraphVersion_AddRef(IGraphVersion *iface)
5644 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5646 return IUnknown_AddRef(This->outer_unk);
5649 static ULONG WINAPI GraphVersion_Release(IGraphVersion *iface)
5651 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5653 return IUnknown_Release(This->outer_unk);
5656 static HRESULT WINAPI GraphVersion_QueryVersion(IGraphVersion *iface, LONG *pVersion)
5658 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5660 if(!pVersion)
5661 return E_POINTER;
5663 TRACE("(%p)->(%p): current version %i\n", This, pVersion, This->version);
5665 *pVersion = This->version;
5666 return S_OK;
5669 static const IGraphVersionVtbl IGraphVersion_VTable =
5671 GraphVersion_QueryInterface,
5672 GraphVersion_AddRef,
5673 GraphVersion_Release,
5674 GraphVersion_QueryVersion,
5677 static const IUnknownVtbl IInner_VTable =
5679 FilterGraphInner_QueryInterface,
5680 FilterGraphInner_AddRef,
5681 FilterGraphInner_Release
5684 /* This is the only function that actually creates a FilterGraph class... */
5685 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5687 IFilterGraphImpl *fimpl;
5688 HRESULT hr;
5690 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5692 *ppObj = NULL;
5694 fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5695 fimpl->defaultclock = TRUE;
5696 fimpl->IUnknown_inner.lpVtbl = &IInner_VTable;
5697 fimpl->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5698 fimpl->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5699 fimpl->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5700 fimpl->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5701 fimpl->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5702 fimpl->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5703 fimpl->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5704 fimpl->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5705 fimpl->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5706 fimpl->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5707 fimpl->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5708 fimpl->IObjectWithSite_iface.lpVtbl = &IObjectWithSite_VTable;
5709 fimpl->IGraphVersion_iface.lpVtbl = &IGraphVersion_VTable;
5710 fimpl->ref = 1;
5711 fimpl->ppFiltersInGraph = NULL;
5712 fimpl->pFilterNames = NULL;
5713 fimpl->nFilters = 0;
5714 fimpl->filterCapacity = 0;
5715 fimpl->nameIndex = 1;
5716 fimpl->refClock = NULL;
5717 fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5718 fimpl->HandleEcComplete = TRUE;
5719 fimpl->HandleEcRepaint = TRUE;
5720 fimpl->HandleEcClockChanged = TRUE;
5721 fimpl->notif.hWnd = 0;
5722 fimpl->notif.disabled = FALSE;
5723 fimpl->nRenderers = 0;
5724 fimpl->EcCompleteCount = 0;
5725 fimpl->refClockProvider = NULL;
5726 fimpl->state = State_Stopped;
5727 fimpl->pSite = NULL;
5728 EventsQueue_Init(&fimpl->evqueue);
5729 InitializeCriticalSection(&fimpl->cs);
5730 fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5731 fimpl->nItfCacheEntries = 0;
5732 memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5733 fimpl->start_time = fimpl->pause_time = 0;
5734 fimpl->stop_position = -1;
5735 fimpl->punkFilterMapper2 = NULL;
5736 fimpl->recursioncount = 0;
5737 fimpl->version = 0;
5739 if (pUnkOuter)
5740 fimpl->outer_unk = pUnkOuter;
5741 else
5742 fimpl->outer_unk = &fimpl->IUnknown_inner;
5744 /* create Filtermapper aggregated. */
5745 hr = CoCreateInstance(&CLSID_FilterMapper2, fimpl->outer_unk, CLSCTX_INPROC_SERVER,
5746 &IID_IUnknown, (void**)&fimpl->punkFilterMapper2);
5748 if (FAILED(hr)) {
5749 ERR("Unable to create filter mapper (%x)\n", hr);
5750 if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5751 CloseHandle(fimpl->hEventCompletion);
5752 EventsQueue_Destroy(&fimpl->evqueue);
5753 fimpl->cs.DebugInfo->Spare[0] = 0;
5754 DeleteCriticalSection(&fimpl->cs);
5755 CoTaskMemFree(fimpl);
5756 return hr;
5759 *ppObj = &fimpl->IUnknown_inner;
5760 return S_OK;
5763 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5765 FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5766 return FilterGraph_create(pUnkOuter, ppObj);