Release 1.3.7.
[wine/gsoc-2012-control.git] / dlls / quartz / filtergraph.c
blobeeafe32d59ea1204ff69cbc4ebd4594de07e488c
1 /* DirectShow FilterGraph object (QUARTZ.DLL)
3 * Copyright 2002 Lionel Ulmer
4 * Copyright 2004 Christian Costa
6 * This file contains the (internal) driver registration functions,
7 * driver enumeration APIs and DirectDraw creation functions.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
25 #include <stdarg.h>
27 #define COBJMACROS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "winreg.h"
33 #include "shlwapi.h"
34 #include "dshow.h"
35 #include "wine/debug.h"
36 #include "quartz_private.h"
37 #include "ole2.h"
38 #include "olectl.h"
39 #include "strmif.h"
40 #include "vfwmsgs.h"
41 #include "evcode.h"
42 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
47 typedef struct {
48 HWND hWnd; /* Target window */
49 UINT msg; /* User window message */
50 LONG_PTR instance; /* User data */
51 int disabled; /* Disabled messages posting */
52 } WndNotify;
54 typedef struct {
55 LONG lEventCode; /* Event code */
56 LONG_PTR lParam1; /* Param1 */
57 LONG_PTR lParam2; /* Param2 */
58 } Event;
60 /* messages ring implementation for queuing events (taken from winmm) */
61 #define EVENTS_RING_BUFFER_INCREMENT 64
62 typedef struct {
63 Event* messages;
64 int ring_buffer_size;
65 int msg_tosave;
66 int msg_toget;
67 CRITICAL_SECTION msg_crst;
68 HANDLE msg_event; /* Signaled for no empty queue */
69 } EventsQueue;
71 static int EventsQueue_Init(EventsQueue* omr)
73 omr->msg_toget = 0;
74 omr->msg_tosave = 0;
75 omr->msg_event = CreateEventW(NULL, TRUE, FALSE, NULL);
76 omr->ring_buffer_size = EVENTS_RING_BUFFER_INCREMENT;
77 omr->messages = CoTaskMemAlloc(omr->ring_buffer_size * sizeof(Event));
78 ZeroMemory(omr->messages, omr->ring_buffer_size * sizeof(Event));
80 InitializeCriticalSection(&omr->msg_crst);
81 omr->msg_crst.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": EventsQueue.msg_crst");
82 return TRUE;
85 static int EventsQueue_Destroy(EventsQueue* omr)
87 CloseHandle(omr->msg_event);
88 CoTaskMemFree(omr->messages);
89 omr->msg_crst.DebugInfo->Spare[0] = 0;
90 DeleteCriticalSection(&omr->msg_crst);
91 return TRUE;
94 static int EventsQueue_PutEvent(EventsQueue* omr, const Event* evt)
96 EnterCriticalSection(&omr->msg_crst);
97 if ((omr->msg_toget == ((omr->msg_tosave + 1) % omr->ring_buffer_size)))
99 int old_ring_buffer_size = omr->ring_buffer_size;
100 omr->ring_buffer_size += EVENTS_RING_BUFFER_INCREMENT;
101 TRACE("omr->ring_buffer_size=%d\n",omr->ring_buffer_size);
102 omr->messages = CoTaskMemRealloc(omr->messages, omr->ring_buffer_size * sizeof(Event));
103 /* Now we need to rearrange the ring buffer so that the new
104 buffers just allocated are in between omr->msg_tosave and
105 omr->msg_toget.
107 if (omr->msg_tosave < omr->msg_toget)
109 memmove(&(omr->messages[omr->msg_toget + EVENTS_RING_BUFFER_INCREMENT]),
110 &(omr->messages[omr->msg_toget]),
111 sizeof(Event)*(old_ring_buffer_size - omr->msg_toget)
113 omr->msg_toget += EVENTS_RING_BUFFER_INCREMENT;
116 omr->messages[omr->msg_tosave] = *evt;
117 SetEvent(omr->msg_event);
118 omr->msg_tosave = (omr->msg_tosave + 1) % omr->ring_buffer_size;
119 LeaveCriticalSection(&omr->msg_crst);
120 return TRUE;
123 static int EventsQueue_GetEvent(EventsQueue* omr, Event* evt, LONG msTimeOut)
125 if (WaitForSingleObject(omr->msg_event, msTimeOut) != WAIT_OBJECT_0)
126 return FALSE;
128 EnterCriticalSection(&omr->msg_crst);
130 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
132 LeaveCriticalSection(&omr->msg_crst);
133 return FALSE;
136 *evt = omr->messages[omr->msg_toget];
137 omr->msg_toget = (omr->msg_toget + 1) % omr->ring_buffer_size;
139 /* Mark the buffer as empty if needed */
140 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
141 ResetEvent(omr->msg_event);
143 LeaveCriticalSection(&omr->msg_crst);
144 return TRUE;
147 #define MAX_ITF_CACHE_ENTRIES 3
148 typedef struct _ITF_CACHE_ENTRY {
149 const IID* riid;
150 IBaseFilter* filter;
151 IUnknown* iface;
152 } ITF_CACHE_ENTRY;
154 typedef struct _IFilterGraphImpl {
155 const IFilterGraph2Vtbl *IFilterGraph2_vtbl;
156 const IMediaControlVtbl *IMediaControl_vtbl;
157 const IMediaSeekingVtbl *IMediaSeeking_vtbl;
158 const IBasicAudioVtbl *IBasicAudio_vtbl;
159 const IBasicVideo2Vtbl *IBasicVideo_vtbl;
160 const IVideoWindowVtbl *IVideoWindow_vtbl;
161 const IMediaEventExVtbl *IMediaEventEx_vtbl;
162 const IMediaFilterVtbl *IMediaFilter_vtbl;
163 const IMediaEventSinkVtbl *IMediaEventSink_vtbl;
164 const IGraphConfigVtbl *IGraphConfig_vtbl;
165 const IMediaPositionVtbl *IMediaPosition_vtbl;
166 const IUnknownVtbl * IInner_vtbl;
167 /* IAMGraphStreams */
168 /* IAMStats */
169 /* IFilterChain */
170 /* IFilterMapper2 */
171 /* IGraphVersion */
172 /* IQueueCommand */
173 /* IRegisterServiceProvider */
174 /* IResourceMananger */
175 /* IServiceProvider */
176 /* IVideoFrameStep */
178 LONG ref;
179 IUnknown *punkFilterMapper2;
180 IFilterMapper2 * pFilterMapper2;
181 IBaseFilter ** ppFiltersInGraph;
182 LPWSTR * pFilterNames;
183 int nFilters;
184 int filterCapacity;
185 LONG nameIndex;
186 IReferenceClock *refClock;
187 EventsQueue evqueue;
188 HANDLE hEventCompletion;
189 int CompletionStatus;
190 WndNotify notif;
191 int nRenderers;
192 int EcCompleteCount;
193 int HandleEcComplete;
194 int HandleEcRepaint;
195 int HandleEcClockChanged;
196 OAFilterState state;
197 CRITICAL_SECTION cs;
198 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
199 int nItfCacheEntries;
200 IUnknown * pUnkOuter;
201 BOOL bUnkOuterValid;
202 BOOL bAggregatable;
203 GUID timeformatseek;
204 REFERENCE_TIME start_time;
205 REFERENCE_TIME pause_time;
206 LONGLONG stop_position;
207 LONG recursioncount;
208 } IFilterGraphImpl;
210 static HRESULT Filtergraph_QueryInterface(IFilterGraphImpl *This,
211 REFIID riid, LPVOID * ppv);
212 static ULONG Filtergraph_AddRef(IFilterGraphImpl *This);
213 static ULONG Filtergraph_Release(IFilterGraphImpl *This);
215 static HRESULT WINAPI FilterGraphInner_QueryInterface(IUnknown * iface,
216 REFIID riid,
217 LPVOID *ppvObj) {
218 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
219 TRACE("(%p)->(%s (%p), %p)\n", This, debugstr_guid(riid), riid, ppvObj);
221 if (This->bAggregatable)
222 This->bUnkOuterValid = TRUE;
224 if (IsEqualGUID(&IID_IUnknown, riid)) {
225 *ppvObj = &(This->IInner_vtbl);
226 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
227 } else if (IsEqualGUID(&IID_IFilterGraph, riid) ||
228 IsEqualGUID(&IID_IFilterGraph2, riid) ||
229 IsEqualGUID(&IID_IGraphBuilder, riid)) {
230 *ppvObj = &(This->IFilterGraph2_vtbl);
231 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj);
232 } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
233 *ppvObj = &(This->IMediaControl_vtbl);
234 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj);
235 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
236 *ppvObj = &(This->IMediaSeeking_vtbl);
237 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
238 } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
239 *ppvObj = &(This->IBasicAudio_vtbl);
240 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj);
241 } else if (IsEqualGUID(&IID_IBasicVideo, riid) ||
242 IsEqualGUID(&IID_IBasicVideo2, riid)) {
243 *ppvObj = &(This->IBasicVideo_vtbl);
244 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj);
245 } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
246 *ppvObj = &(This->IVideoWindow_vtbl);
247 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj);
248 } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
249 IsEqualGUID(&IID_IMediaEventEx, riid)) {
250 *ppvObj = &(This->IMediaEventEx_vtbl);
251 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
252 } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
253 IsEqualGUID(&IID_IPersist, riid)) {
254 *ppvObj = &(This->IMediaFilter_vtbl);
255 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj);
256 } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
257 *ppvObj = &(This->IMediaEventSink_vtbl);
258 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj);
259 } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
260 *ppvObj = &(This->IGraphConfig_vtbl);
261 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
262 } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
263 *ppvObj = &(This->IMediaPosition_vtbl);
264 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj);
265 } else if (IsEqualGUID(&IID_IFilterMapper, riid)) {
266 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj);
267 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
268 } else if (IsEqualGUID(&IID_IFilterMapper2, riid)) {
269 *ppvObj = This->pFilterMapper2;
270 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
271 } else {
272 *ppvObj = NULL;
273 FIXME("unknown interface %s\n", debugstr_guid(riid));
274 return E_NOINTERFACE;
277 IUnknown_AddRef((IUnknown *)(*ppvObj));
278 return S_OK;
281 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown * iface) {
282 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
283 ULONG ref = InterlockedIncrement(&This->ref);
285 TRACE("(%p)->(): new ref = %d\n", This, ref);
287 return ref;
290 static ULONG WINAPI FilterGraphInner_Release(IUnknown * iface)
292 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
293 ULONG ref = InterlockedDecrement(&This->ref);
295 TRACE("(%p)->(): new ref = %d\n", This, ref);
297 if (ref == 0) {
298 int i;
300 This->ref = 1; /* guard against reentrancy (aggregation). */
302 IMediaControl_Stop((IMediaControl*)&(This->IMediaControl_vtbl));
304 while (This->nFilters)
305 IFilterGraph2_RemoveFilter((IFilterGraph2*)This, This->ppFiltersInGraph[0]);
307 if (This->refClock)
308 IReferenceClock_Release(This->refClock);
310 for (i = 0; i < This->nItfCacheEntries; i++)
312 if (This->ItfCacheEntries[i].iface)
313 IUnknown_Release(This->ItfCacheEntries[i].iface);
316 /* AddRef on controlling IUnknown, to compensate for Release of cached IFilterMapper2 interface below.
318 * NOTE: Filtergraph_AddRef isn't suitable, because bUnkOuterValid may be FALSE but punkOuter non-NULL
319 * and already passed as punkOuter to filtermapper in FilterGraph_create - this will happen in case of
320 * CoCreateInstance of filtergraph with non-null pUnkOuter and REFIID other than IID_Unknown that is
321 * cleaning up after error. */
322 if (This->pUnkOuter) IUnknown_AddRef(This->pUnkOuter);
323 else IUnknown_AddRef((IUnknown*)&This->IInner_vtbl);
325 IFilterMapper2_Release(This->pFilterMapper2);
326 IUnknown_Release(This->punkFilterMapper2);
328 CloseHandle(This->hEventCompletion);
329 EventsQueue_Destroy(&This->evqueue);
330 This->cs.DebugInfo->Spare[0] = 0;
331 DeleteCriticalSection(&This->cs);
332 CoTaskMemFree(This->ppFiltersInGraph);
333 CoTaskMemFree(This->pFilterNames);
334 CoTaskMemFree(This);
336 return ref;
340 /*** IUnknown methods ***/
341 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface,
342 REFIID riid,
343 LPVOID*ppvObj) {
344 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
346 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
347 return Filtergraph_QueryInterface(This, riid, ppvObj);
350 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface) {
351 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
353 TRACE("(%p/%p)->() calling FilterGraph AddRef\n", This, iface);
355 return Filtergraph_AddRef(This);
358 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface) {
359 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
361 TRACE("(%p/%p)->() calling FilterGraph Release\n", This, iface);
363 return Filtergraph_Release(This);
366 /*** IFilterGraph methods ***/
367 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface,
368 IBaseFilter *pFilter,
369 LPCWSTR pName) {
370 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
371 HRESULT hr;
372 int i,j;
373 WCHAR* wszFilterName = NULL;
374 int duplicate_name = FALSE;
376 TRACE("(%p/%p)->(%p, %s (%p))\n", This, iface, pFilter, debugstr_w(pName), pName);
378 if (!pFilter)
379 return E_POINTER;
381 wszFilterName = CoTaskMemAlloc( (pName ? strlenW(pName) + 6 : 5) * sizeof(WCHAR) );
383 if (pName)
385 /* Check if name already exists */
386 for(i = 0; i < This->nFilters; i++)
387 if (!strcmpW(This->pFilterNames[i], pName))
389 duplicate_name = TRUE;
390 break;
394 /* If no name given or name already existing, generate one */
395 if (!pName || duplicate_name)
397 static const WCHAR wszFmt1[] = {'%','s',' ','%','0','4','d',0};
398 static const WCHAR wszFmt2[] = {'%','0','4','d',0};
400 for (j = 0; j < 10000 ; j++)
402 /* Create name */
403 if (pName)
404 sprintfW(wszFilterName, wszFmt1, pName, This->nameIndex);
405 else
406 sprintfW(wszFilterName, wszFmt2, This->nameIndex);
407 TRACE("Generated name %s\n", debugstr_w(wszFilterName));
409 /* Check if the generated name already exists */
410 for(i = 0; i < This->nFilters; i++)
411 if (!strcmpW(This->pFilterNames[i], wszFilterName))
412 break;
414 /* Compute next index and exit if generated name is suitable */
415 if (This->nameIndex++ == 10000)
416 This->nameIndex = 1;
417 if (i == This->nFilters)
418 break;
420 /* Unable to find a suitable name */
421 if (j == 10000)
423 CoTaskMemFree(wszFilterName);
424 return VFW_E_DUPLICATE_NAME;
427 else
428 memcpy(wszFilterName, pName, (strlenW(pName) + 1) * sizeof(WCHAR));
430 if (This->nFilters + 1 > This->filterCapacity)
432 int newCapacity = This->filterCapacity ? 2 * This->filterCapacity : 1;
433 IBaseFilter ** ppNewFilters = CoTaskMemAlloc(newCapacity * sizeof(IBaseFilter*));
434 LPWSTR * pNewNames = CoTaskMemAlloc(newCapacity * sizeof(LPWSTR));
435 memcpy(ppNewFilters, This->ppFiltersInGraph, This->nFilters * sizeof(IBaseFilter*));
436 memcpy(pNewNames, This->pFilterNames, This->nFilters * sizeof(LPWSTR));
437 if (This->filterCapacity)
439 CoTaskMemFree(This->ppFiltersInGraph);
440 CoTaskMemFree(This->pFilterNames);
442 This->ppFiltersInGraph = ppNewFilters;
443 This->pFilterNames = pNewNames;
444 This->filterCapacity = newCapacity;
447 hr = IBaseFilter_JoinFilterGraph(pFilter, (IFilterGraph *)This, wszFilterName);
449 if (SUCCEEDED(hr))
451 IBaseFilter_AddRef(pFilter);
452 This->ppFiltersInGraph[This->nFilters] = pFilter;
453 This->pFilterNames[This->nFilters] = wszFilterName;
454 This->nFilters++;
455 IBaseFilter_SetSyncSource(pFilter, This->refClock);
457 else
458 CoTaskMemFree(wszFilterName);
460 if (SUCCEEDED(hr) && duplicate_name)
461 return VFW_S_DUPLICATE_NAME;
463 return hr;
466 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
468 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
469 int i;
470 HRESULT hr = E_FAIL;
472 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
474 /* FIXME: check graph is stopped */
476 for (i = 0; i < This->nFilters; i++)
478 if (This->ppFiltersInGraph[i] == pFilter)
480 IEnumPins *penumpins = NULL;
481 FILTER_STATE state;
483 TRACE("Removing filter %s\n", debugstr_w(This->pFilterNames[i]));
484 IBaseFilter_GetState(pFilter, 0, &state);
485 if (state == State_Running)
486 IBaseFilter_Pause(pFilter);
487 if (state != State_Stopped)
488 IBaseFilter_Stop(pFilter);
490 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
491 if (SUCCEEDED(hr)) {
492 IPin *ppin;
493 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
495 IPin *victim = NULL;
496 HRESULT h;
497 IPin_ConnectedTo(ppin, &victim);
498 if (victim)
500 h = IPin_Disconnect(victim);
501 TRACE("Disconnect other side: %08x\n", h);
502 if (h == VFW_E_NOT_STOPPED)
504 PIN_INFO pinfo;
505 IPin_QueryPinInfo(victim, &pinfo);
507 IBaseFilter_GetState(pinfo.pFilter, 0, &state);
508 if (state == State_Running)
509 IBaseFilter_Pause(pinfo.pFilter);
510 IBaseFilter_Stop(pinfo.pFilter);
511 IBaseFilter_Release(pinfo.pFilter);
512 h = IPin_Disconnect(victim);
513 TRACE("Disconnect retry: %08x\n", h);
515 IPin_Release(victim);
517 h = IPin_Disconnect(ppin);
518 TRACE("Disconnect 2: %08x\n", h);
520 IPin_Release(ppin);
522 IEnumPins_Release(penumpins);
525 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, This->pFilterNames[i]);
526 if (SUCCEEDED(hr))
528 IBaseFilter_SetSyncSource(pFilter, NULL);
529 IBaseFilter_Release(pFilter);
530 CoTaskMemFree(This->pFilterNames[i]);
531 memmove(This->ppFiltersInGraph+i, This->ppFiltersInGraph+i+1, sizeof(IBaseFilter*)*(This->nFilters - 1 - i));
532 memmove(This->pFilterNames+i, This->pFilterNames+i+1, sizeof(LPWSTR)*(This->nFilters - 1 - i));
533 This->nFilters--;
534 /* Invalidate interfaces in the cache */
535 for (i = 0; i < This->nItfCacheEntries; i++)
536 if (pFilter == This->ItfCacheEntries[i].filter)
538 IUnknown_Release(This->ItfCacheEntries[i].iface);
539 This->ItfCacheEntries[i].iface = NULL;
540 This->ItfCacheEntries[i].filter = NULL;
542 return S_OK;
544 break;
548 return hr; /* FIXME: check this error code */
551 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface,
552 IEnumFilters **ppEnum) {
553 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
555 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
557 return IEnumFiltersImpl_Construct(This->ppFiltersInGraph, This->nFilters, ppEnum);
560 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface,
561 LPCWSTR pName,
562 IBaseFilter **ppFilter) {
563 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
564 int i;
566 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_w(pName), pName, ppFilter);
568 if (!ppFilter)
569 return E_POINTER;
571 for (i = 0; i < This->nFilters; i++)
573 if (!strcmpW(pName, This->pFilterNames[i]))
575 *ppFilter = This->ppFiltersInGraph[i];
576 IBaseFilter_AddRef(*ppFilter);
577 return S_OK;
581 *ppFilter = NULL;
582 return VFW_E_NOT_FOUND;
585 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
586 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
588 static HRESULT CheckCircularConnection(IFilterGraphImpl *This, IPin *out, IPin *in)
590 #if 1
591 HRESULT hr;
592 PIN_INFO info_out, info_in;
594 hr = IPin_QueryPinInfo(out, &info_out);
595 if (FAILED(hr))
596 return hr;
597 if (info_out.dir != PINDIR_OUTPUT)
599 IBaseFilter_Release(info_out.pFilter);
600 return E_UNEXPECTED;
603 hr = IPin_QueryPinInfo(in, &info_in);
604 if (SUCCEEDED(hr))
605 IBaseFilter_Release(info_in.pFilter);
606 if (FAILED(hr))
607 goto out;
608 if (info_in.dir != PINDIR_INPUT)
610 hr = E_UNEXPECTED;
611 goto out;
614 if (info_out.pFilter == info_in.pFilter)
615 hr = VFW_E_CIRCULAR_GRAPH;
616 else
618 IEnumPins *enumpins;
619 IPin *test;
621 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
622 if (FAILED(hr))
623 goto out;
625 IEnumPins_Reset(enumpins);
626 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
628 PIN_DIRECTION dir = PINDIR_OUTPUT;
629 IPin_QueryDirection(test, &dir);
630 if (dir == PINDIR_INPUT)
632 IPin *victim = NULL;
633 IPin_ConnectedTo(test, &victim);
634 if (victim)
636 hr = CheckCircularConnection(This, victim, in);
637 IPin_Release(victim);
638 if (FAILED(hr))
640 IPin_Release(test);
641 break;
645 IPin_Release(test);
647 IEnumPins_Release(enumpins);
650 out:
651 IBaseFilter_Release(info_out.pFilter);
652 if (FAILED(hr))
653 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
654 return hr;
655 #else
656 /* Debugging filtergraphs not enabled */
657 return S_OK;
658 #endif
662 /* NOTE: despite the implication, it doesn't matter which
663 * way round you put in the input and output pins */
664 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface,
665 IPin *ppinIn,
666 IPin *ppinOut,
667 const AM_MEDIA_TYPE *pmt) {
668 PIN_DIRECTION dir;
669 HRESULT hr;
671 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
673 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
675 /* FIXME: check pins are in graph */
677 if (TRACE_ON(quartz))
679 PIN_INFO PinInfo;
681 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
682 if (FAILED(hr))
683 return hr;
685 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
686 IBaseFilter_Release(PinInfo.pFilter);
688 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
689 if (FAILED(hr))
690 return hr;
692 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
693 IBaseFilter_Release(PinInfo.pFilter);
696 hr = IPin_QueryDirection(ppinIn, &dir);
697 if (SUCCEEDED(hr))
699 if (dir == PINDIR_INPUT)
701 hr = CheckCircularConnection(This, ppinOut, ppinIn);
702 if (SUCCEEDED(hr))
703 hr = IPin_Connect(ppinOut, ppinIn, pmt);
705 else
707 hr = CheckCircularConnection(This, ppinIn, ppinOut);
708 if (SUCCEEDED(hr))
709 hr = IPin_Connect(ppinIn, ppinOut, pmt);
713 return hr;
716 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface,
717 IPin *ppin) {
718 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
719 IPin *pConnectedTo = NULL;
720 HRESULT hr;
721 PIN_DIRECTION pindir;
723 IPin_QueryDirection(ppin, &pindir);
724 hr = IPin_ConnectedTo(ppin, &pConnectedTo);
725 if (FAILED(hr)) {
726 TRACE("Querying connected to failed: %x\n", hr);
727 return hr;
729 IPin_Disconnect(ppin);
730 IPin_Disconnect(pConnectedTo);
731 if (pindir == PINDIR_INPUT)
732 hr = IPin_Connect(pConnectedTo, ppin, NULL);
733 else
734 hr = IPin_Connect(ppin, pConnectedTo, NULL);
735 IPin_Release(pConnectedTo);
736 if (FAILED(hr))
737 WARN("Reconnecting pins failed, pins are not connected now..\n");
738 TRACE("(%p->%p) -- %p %p -> %x\n", iface, This, ppin, pConnectedTo, hr);
739 return hr;
742 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
744 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
746 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
748 if (!ppin)
749 return E_POINTER;
751 return IPin_Disconnect(ppin);
754 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface) {
755 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
756 IReferenceClock *pClock = NULL;
757 HRESULT hr;
759 TRACE("(%p/%p)->() semi-stub\n", iface, This);
761 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
763 if (SUCCEEDED(hr))
765 hr = IMediaFilter_SetSyncSource((IMediaFilter*)&(This->IMediaFilter_vtbl), pClock);
766 IReferenceClock_Release(pClock);
769 return hr;
772 static HRESULT GetFilterInfo(IMoniker* pMoniker, GUID* pclsid, VARIANT* pvar)
774 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
775 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
776 IPropertyBag * pPropBagCat = NULL;
777 HRESULT hr;
779 VariantInit(pvar);
781 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
783 if (SUCCEEDED(hr))
784 hr = IPropertyBag_Read(pPropBagCat, wszClsidName, pvar, NULL);
786 if (SUCCEEDED(hr))
787 hr = CLSIDFromString(V_UNION(pvar, bstrVal), pclsid);
789 VariantClear(pvar);
791 if (SUCCEEDED(hr))
792 hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL);
794 if (SUCCEEDED(hr))
795 TRACE("Moniker = %s - %s\n", debugstr_guid(pclsid), debugstr_w(V_UNION(pvar, bstrVal)));
797 if (pPropBagCat)
798 IPropertyBag_Release(pPropBagCat);
800 return hr;
803 static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPin*** pppins, ULONG* pnb)
805 HRESULT hr;
806 ULONG nb = 0;
808 TRACE("(%p, %p, %p, %p)\n", pfilter, pinputpin, pppins, pnb);
809 hr = IPin_QueryInternalConnections(pinputpin, NULL, &nb);
810 if (hr == S_OK) {
811 /* Rendered input */
812 } else if (hr == S_FALSE) {
813 *pppins = CoTaskMemAlloc(sizeof(IPin*)*nb);
814 hr = IPin_QueryInternalConnections(pinputpin, *pppins, &nb);
815 if (hr != S_OK) {
816 WARN("Error (%x)\n", hr);
818 } else if (hr == E_NOTIMPL) {
819 /* Input connected to all outputs */
820 IEnumPins* penumpins;
821 IPin* ppin;
822 int i = 0;
823 TRACE("E_NOTIMPL\n");
824 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
825 if (FAILED(hr)) {
826 WARN("filter Enumpins failed (%x)\n", hr);
827 return hr;
829 i = 0;
830 /* Count output pins */
831 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
832 PIN_DIRECTION pindir;
833 IPin_QueryDirection(ppin, &pindir);
834 if (pindir == PINDIR_OUTPUT)
835 i++;
836 IPin_Release(ppin);
838 *pppins = CoTaskMemAlloc(sizeof(IPin*)*i);
839 /* Retrieve output pins */
840 IEnumPins_Reset(penumpins);
841 i = 0;
842 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
843 PIN_DIRECTION pindir;
844 IPin_QueryDirection(ppin, &pindir);
845 if (pindir == PINDIR_OUTPUT)
846 (*pppins)[i++] = ppin;
847 else
848 IPin_Release(ppin);
850 IEnumPins_Release(penumpins);
851 nb = i;
852 if (FAILED(hr)) {
853 WARN("Next failed (%x)\n", hr);
854 return hr;
856 } else if (FAILED(hr)) {
857 WARN("Cannot get internal connection (%x)\n", hr);
858 return hr;
861 *pnb = nb;
862 return S_OK;
865 /*** IGraphBuilder methods ***/
866 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IPin *ppinIn)
868 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
869 HRESULT hr;
870 AM_MEDIA_TYPE* mt = NULL;
871 IEnumMediaTypes* penummt = NULL;
872 ULONG nbmt;
873 IEnumPins* penumpins;
874 IEnumMoniker* pEnumMoniker;
875 GUID tab[2];
876 ULONG nb;
877 IMoniker* pMoniker;
878 ULONG pin;
879 PIN_INFO PinInfo;
880 CLSID FilterCLSID;
881 PIN_DIRECTION dir;
883 TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
885 if (TRACE_ON(quartz))
887 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
888 if (FAILED(hr))
889 return hr;
891 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
892 IBaseFilter_Release(PinInfo.pFilter);
894 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
895 if (FAILED(hr))
896 return hr;
898 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
899 IBaseFilter_Release(PinInfo.pFilter);
902 EnterCriticalSection(&This->cs);
903 ++This->recursioncount;
904 if (This->recursioncount >= 5)
906 WARN("Recursion count has reached %d\n", This->recursioncount);
907 hr = VFW_E_CANNOT_CONNECT;
908 goto out;
911 hr = IPin_QueryDirection(ppinOut, &dir);
912 if (FAILED(hr))
913 goto out;
915 if (dir == PINDIR_INPUT)
917 IPin *temp;
919 temp = ppinIn;
920 ppinIn = ppinOut;
921 ppinOut = temp;
924 hr = CheckCircularConnection(This, ppinOut, ppinIn);
925 if (FAILED(hr))
926 goto out;
928 /* Try direct connection first */
929 hr = IPin_Connect(ppinOut, ppinIn, NULL);
930 if (SUCCEEDED(hr))
931 goto out;
933 TRACE("Direct connection failed, trying to render using extra filters\n");
935 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
936 if (FAILED(hr))
937 goto out;
939 hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
940 IBaseFilter_Release(PinInfo.pFilter);
941 if (FAILED(hr))
942 goto out;
944 /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream
945 * filter to the minor mediatype of input pin of the renderer */
946 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
947 if (FAILED(hr))
949 WARN("EnumMediaTypes (%x)\n", hr);
950 goto out;
953 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
954 if (FAILED(hr)) {
955 WARN("IEnumMediaTypes_Next (%x)\n", hr);
956 goto out;
959 if (!nbmt)
961 WARN("No media type found!\n");
962 hr = VFW_E_INVALIDMEDIATYPE;
963 goto out;
965 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
966 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
968 /* Try to find a suitable filter that can connect to the pin to render */
969 tab[0] = mt->majortype;
970 tab[1] = mt->subtype;
971 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
972 if (FAILED(hr)) {
973 WARN("Unable to enum filters (%x)\n", hr);
974 goto out;
977 hr = VFW_E_CANNOT_RENDER;
978 while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
980 VARIANT var;
981 GUID clsid;
982 IPin** ppins;
983 IPin* ppinfilter = NULL;
984 IBaseFilter* pfilter = NULL;
986 hr = GetFilterInfo(pMoniker, &clsid, &var);
987 IMoniker_Release(pMoniker);
988 if (FAILED(hr)) {
989 WARN("Unable to retrieve filter info (%x)\n", hr);
990 goto error;
993 if (IsEqualGUID(&clsid, &FilterCLSID)) {
994 /* Skip filter (same as the one the output pin belongs to) */
995 goto error;
998 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
999 if (FAILED(hr)) {
1000 WARN("Unable to create filter (%x), trying next one\n", hr);
1001 goto error;
1004 hr = IFilterGraph2_AddFilter(iface, pfilter, V_UNION(&var, bstrVal));
1005 if (FAILED(hr)) {
1006 WARN("Unable to add filter (%x)\n", hr);
1007 IBaseFilter_Release(pfilter);
1008 pfilter = NULL;
1009 goto error;
1012 VariantClear(&var);
1014 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1015 if (FAILED(hr)) {
1016 WARN("Enumpins (%x)\n", hr);
1017 goto error;
1020 hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin);
1021 IEnumPins_Release(penumpins);
1023 if (FAILED(hr)) {
1024 WARN("Obtaining next pin: (%x)\n", hr);
1025 goto error;
1027 if (pin == 0) {
1028 WARN("Cannot use this filter: no pins\n");
1029 goto error;
1032 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1033 if (FAILED(hr)) {
1034 TRACE("Cannot connect to filter (%x), trying next one\n", hr);
1035 goto error;
1037 TRACE("Successfully connected to filter, follow chain...\n");
1039 /* Render all output pins of the filter by calling IFilterGraph2_Connect on each of them */
1040 hr = GetInternalConnections(pfilter, ppinfilter, &ppins, &nb);
1042 if (SUCCEEDED(hr)) {
1043 unsigned int i;
1044 if (nb == 0) {
1045 IPin_Disconnect(ppinfilter);
1046 IPin_Disconnect(ppinOut);
1047 goto error;
1049 TRACE("pins to consider: %d\n", nb);
1050 for(i = 0; i < nb; i++)
1052 LPWSTR pinname = NULL;
1054 TRACE("Processing pin %u\n", i);
1056 hr = IPin_QueryId(ppins[i], &pinname);
1057 if (SUCCEEDED(hr))
1059 if (pinname[0] == '~')
1061 TRACE("Pinname=%s, skipping\n", debugstr_w(pinname));
1062 hr = E_FAIL;
1064 else
1065 hr = IFilterGraph2_Connect(iface, ppins[i], ppinIn);
1066 CoTaskMemFree(pinname);
1069 if (FAILED(hr)) {
1070 TRACE("Cannot connect pin %p (%x)\n", ppinfilter, hr);
1072 IPin_Release(ppins[i]);
1073 if (SUCCEEDED(hr)) break;
1075 while (++i < nb) IPin_Release(ppins[i]);
1076 CoTaskMemFree(ppins);
1077 IPin_Release(ppinfilter);
1078 IBaseFilter_Release(pfilter);
1079 if (FAILED(hr))
1081 IPin_Disconnect(ppinfilter);
1082 IPin_Disconnect(ppinOut);
1083 IFilterGraph2_RemoveFilter(iface, pfilter);
1084 continue;
1086 break;
1089 error:
1090 VariantClear(&var);
1091 if (ppinfilter) IPin_Release(ppinfilter);
1092 if (pfilter) {
1093 IFilterGraph2_RemoveFilter(iface, pfilter);
1094 IBaseFilter_Release(pfilter);
1098 out:
1099 if (penummt)
1100 IEnumMediaTypes_Release(penummt);
1101 if (mt)
1102 DeleteMediaType(mt);
1103 --This->recursioncount;
1104 LeaveCriticalSection(&This->cs);
1105 TRACE("--> %08x\n", hr);
1106 return SUCCEEDED(hr) ? S_OK : hr;
1109 static HRESULT FilterGraph2_RenderRecurse(IFilterGraphImpl *This, IPin *ppinOut)
1111 /* This pin has been connected now, try to call render on all pins that aren't connected */
1112 IPin *to = NULL;
1113 PIN_INFO info;
1114 IEnumPins *enumpins = NULL;
1115 BOOL renderany = FALSE;
1116 BOOL renderall = TRUE;
1118 IPin_QueryPinInfo(ppinOut, &info);
1120 IBaseFilter_EnumPins(info.pFilter, &enumpins);
1121 /* Don't need to hold a reference, IEnumPins does */
1122 IBaseFilter_Release(info.pFilter);
1124 IEnumPins_Reset(enumpins);
1125 while (IEnumPins_Next(enumpins, 1, &to, NULL) == S_OK)
1127 PIN_DIRECTION dir = PINDIR_INPUT;
1129 IPin_QueryDirection(to, &dir);
1131 if (dir == PINDIR_OUTPUT)
1133 IPin *out = NULL;
1135 IPin_ConnectedTo(to, &out);
1136 if (!out)
1138 HRESULT hr;
1139 hr = IFilterGraph2_Render((IFilterGraph2 *)&This->IFilterGraph2_vtbl, to);
1140 if (SUCCEEDED(hr))
1141 renderany = TRUE;
1142 else
1143 renderall = FALSE;
1145 else
1146 IPin_Release(out);
1149 IPin_Release(to);
1152 IEnumPins_Release(enumpins);
1154 if (renderall)
1155 return S_OK;
1157 if (renderany)
1158 return VFW_S_PARTIAL_RENDER;
1160 return VFW_E_CANNOT_RENDER;
1163 /* Ogg hates me if I create a direct rendering method
1165 * It can only connect to a pin properly once, so use a recursive method that does
1167 * +----+ --- (PIN 1) (Render is called on this pin)
1168 * | |
1169 * +----+ --- (PIN 2)
1171 * Enumerate possible renderers that EXACTLY match the requested type
1173 * If none is available, try to add intermediate filters that can connect to the input pin
1174 * then call Render on that intermediate pin's output pins
1175 * if it succeeds: Render returns success, if it doesn't, the intermediate filter is removed,
1176 * and another filter that can connect to the input pin is tried
1177 * if we run out of filters that can, give up and return VFW_E_CANNOT_RENDER
1178 * It's recursive, but fun!
1181 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *ppinOut)
1183 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1184 IEnumMediaTypes* penummt;
1185 AM_MEDIA_TYPE* mt;
1186 ULONG nbmt;
1187 HRESULT hr;
1189 IEnumMoniker* pEnumMoniker;
1190 GUID tab[4];
1191 ULONG nb;
1192 IMoniker* pMoniker;
1193 INT x;
1195 TRACE("(%p/%p)->(%p)\n", This, iface, ppinOut);
1197 if (TRACE_ON(quartz))
1199 PIN_INFO PinInfo;
1201 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
1202 if (FAILED(hr))
1203 return hr;
1205 TRACE("Filter owning pin => %p\n", PinInfo.pFilter);
1206 IBaseFilter_Release(PinInfo.pFilter);
1209 /* Try to find out if there is a renderer for the specified subtype already, and use that
1211 EnterCriticalSection(&This->cs);
1212 for (x = 0; x < This->nFilters; ++x)
1214 IEnumPins *enumpins = NULL;
1215 IPin *pin = NULL;
1217 hr = IBaseFilter_EnumPins(This->ppFiltersInGraph[x], &enumpins);
1219 if (FAILED(hr) || !enumpins)
1220 continue;
1222 IEnumPins_Reset(enumpins);
1223 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
1225 IPin *to = NULL;
1226 PIN_DIRECTION dir = PINDIR_OUTPUT;
1228 IPin_QueryDirection(pin, &dir);
1229 if (dir != PINDIR_INPUT)
1231 IPin_Release(pin);
1232 continue;
1234 IPin_ConnectedTo(pin, &to);
1236 if (to == NULL)
1238 hr = IPin_Connect(ppinOut, pin, NULL);
1239 if (SUCCEEDED(hr))
1241 TRACE("Connected successfully %p/%p, %08x look if we should render more!\n", ppinOut, pin, hr);
1242 IPin_Release(pin);
1244 hr = FilterGraph2_RenderRecurse(This, pin);
1245 if (FAILED(hr))
1247 IPin_Disconnect(ppinOut);
1248 IPin_Disconnect(pin);
1249 continue;
1251 IEnumPins_Release(enumpins);
1252 LeaveCriticalSection(&This->cs);
1253 return hr;
1255 WARN("Could not connect!\n");
1257 else
1258 IPin_Release(to);
1260 IPin_Release(pin);
1262 IEnumPins_Release(enumpins);
1265 LeaveCriticalSection(&This->cs);
1267 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
1268 if (FAILED(hr)) {
1269 WARN("EnumMediaTypes (%x)\n", hr);
1270 return hr;
1273 IEnumMediaTypes_Reset(penummt);
1275 /* Looks like no existing renderer of the kind exists
1276 * Try adding new ones
1278 tab[0] = tab[1] = GUID_NULL;
1279 while (SUCCEEDED(hr))
1281 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
1282 if (FAILED(hr)) {
1283 WARN("IEnumMediaTypes_Next (%x)\n", hr);
1284 break;
1286 if (!nbmt)
1288 hr = VFW_E_CANNOT_RENDER;
1289 break;
1291 else
1293 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1294 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1296 /* Only enumerate once, this doesn't account for all previous ones, but this should be enough nonetheless */
1297 if (IsEqualIID(&tab[0], &mt->majortype) && IsEqualIID(&tab[1], &mt->subtype))
1299 DeleteMediaType(mt);
1300 continue;
1303 /* Try to find a suitable renderer with the same media type */
1304 tab[0] = mt->majortype;
1305 tab[1] = mt->subtype;
1306 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1307 if (FAILED(hr))
1309 WARN("Unable to enum filters (%x)\n", hr);
1310 break;
1313 hr = E_FAIL;
1315 while (IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1317 VARIANT var;
1318 GUID clsid;
1319 IPin* ppinfilter;
1320 IBaseFilter* pfilter = NULL;
1321 IEnumPins* penumpins = NULL;
1322 ULONG pin;
1324 hr = GetFilterInfo(pMoniker, &clsid, &var);
1325 IMoniker_Release(pMoniker);
1326 if (FAILED(hr)) {
1327 WARN("Unable to retrieve filter info (%x)\n", hr);
1328 goto error;
1331 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
1332 if (FAILED(hr))
1334 WARN("Unable to create filter (%x), trying next one\n", hr);
1335 goto error;
1338 hr = IFilterGraph2_AddFilter(iface, pfilter, V_UNION(&var, bstrVal));
1339 if (FAILED(hr)) {
1340 WARN("Unable to add filter (%x)\n", hr);
1341 IBaseFilter_Release(pfilter);
1342 pfilter = NULL;
1343 goto error;
1346 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1347 if (FAILED(hr)) {
1348 WARN("Splitter Enumpins (%x)\n", hr);
1349 goto error;
1352 while ((hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin)) == S_OK)
1354 PIN_DIRECTION dir;
1356 if (pin == 0) {
1357 WARN("No Pin\n");
1358 hr = E_FAIL;
1359 goto error;
1362 hr = IPin_QueryDirection(ppinfilter, &dir);
1363 if (FAILED(hr)) {
1364 IPin_Release(ppinfilter);
1365 WARN("QueryDirection failed (%x)\n", hr);
1366 goto error;
1368 if (dir != PINDIR_INPUT) {
1369 IPin_Release(ppinfilter);
1370 continue; /* Wrong direction */
1373 /* Connect the pin to the "Renderer" */
1374 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1375 IPin_Release(ppinfilter);
1377 if (FAILED(hr)) {
1378 WARN("Unable to connect %s to renderer (%x)\n", debugstr_w(V_UNION(&var, bstrVal)), hr);
1379 goto error;
1381 TRACE("Connected, recursing %s\n", debugstr_w(V_UNION(&var, bstrVal)));
1383 VariantClear(&var);
1385 hr = FilterGraph2_RenderRecurse(This, ppinfilter);
1386 if (FAILED(hr)) {
1387 WARN("Unable to connect recursively (%x)\n", hr);
1388 goto error;
1390 IBaseFilter_Release(pfilter);
1391 break;
1393 if (SUCCEEDED(hr)) {
1394 IEnumPins_Release(penumpins);
1395 break; /* out of IEnumMoniker_Next loop */
1398 /* IEnumPins_Next failed, all other failure case caught by goto error */
1399 WARN("IEnumPins_Next (%x)\n", hr);
1400 /* goto error */
1402 error:
1403 VariantClear(&var);
1404 if (penumpins)
1405 IEnumPins_Release(penumpins);
1406 if (pfilter) {
1407 IFilterGraph2_RemoveFilter(iface, pfilter);
1408 IBaseFilter_Release(pfilter);
1410 if (SUCCEEDED(hr)) DebugBreak();
1413 IEnumMoniker_Release(pEnumMoniker);
1414 if (nbmt)
1415 DeleteMediaType(mt);
1416 if (SUCCEEDED(hr))
1417 break;
1418 hr = S_OK;
1421 IEnumMediaTypes_Release(penummt);
1422 return hr;
1425 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface,
1426 LPCWSTR lpcwstrFile,
1427 LPCWSTR lpcwstrPlayList)
1429 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1430 static const WCHAR string[] = {'R','e','a','d','e','r',0};
1431 IBaseFilter* preader = NULL;
1432 IPin* ppinreader = NULL;
1433 IEnumPins* penumpins = NULL;
1434 HRESULT hr;
1435 BOOL partial = FALSE;
1436 HRESULT any = FALSE;
1438 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1440 if (lpcwstrPlayList != NULL)
1441 return E_INVALIDARG;
1443 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, string, &preader);
1444 if (FAILED(hr))
1445 return hr;
1447 if (SUCCEEDED(hr))
1448 hr = IBaseFilter_EnumPins(preader, &penumpins);
1449 if (SUCCEEDED(hr))
1451 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1453 PIN_DIRECTION dir;
1455 IPin_QueryDirection(ppinreader, &dir);
1456 if (dir == PINDIR_OUTPUT)
1458 INT i;
1460 hr = IFilterGraph2_Render(iface, ppinreader);
1461 TRACE("Render %08x\n", hr);
1463 for (i = 0; i < This->nFilters; ++i)
1464 TRACE("Filters in chain: %s\n", debugstr_w(This->pFilterNames[i]));
1466 if (SUCCEEDED(hr))
1467 any = TRUE;
1468 if (hr != S_OK)
1469 partial = TRUE;
1471 IPin_Release(ppinreader);
1473 IEnumPins_Release(penumpins);
1475 if (!any)
1476 hr = VFW_E_CANNOT_RENDER;
1477 else if (partial)
1478 hr = VFW_S_PARTIAL_RENDER;
1479 else
1480 hr = S_OK;
1482 IBaseFilter_Release(preader);
1484 TRACE("--> %08x\n", hr);
1485 return hr;
1488 /* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
1489 static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
1491 static const WCHAR wszReg[] = {'M','e','d','i','a',' ','T','y','p','e','\\','E','x','t','e','n','s','i','o','n','s',0};
1492 HRESULT hr = S_OK;
1493 HKEY extkey;
1494 LONG lRet;
1496 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszReg, 0, KEY_READ, &extkey);
1497 hr = HRESULT_FROM_WIN32(lRet);
1499 if (SUCCEEDED(hr))
1501 static const WCHAR filtersource[] = {'S','o','u','r','c','e',' ','F','i','l','t','e','r',0};
1502 WCHAR *ext = PathFindExtensionW(pszFileName);
1503 WCHAR clsid_key[39];
1504 GUID clsid;
1505 DWORD size = sizeof(clsid_key);
1506 HKEY pathkey;
1508 if (!ext)
1510 CloseHandle(extkey);
1511 return E_FAIL;
1514 lRet = RegOpenKeyExW(extkey, ext, 0, KEY_READ, &pathkey);
1515 hr = HRESULT_FROM_WIN32(lRet);
1516 CloseHandle(extkey);
1517 if (FAILED(hr))
1518 return hr;
1520 lRet = RegQueryValueExW(pathkey, filtersource, NULL, NULL, (LPBYTE)clsid_key, &size);
1521 hr = HRESULT_FROM_WIN32(lRet);
1522 CloseHandle(pathkey);
1523 if (FAILED(hr))
1524 return hr;
1526 CLSIDFromString(clsid_key, &clsid);
1528 TRACE("CLSID: %s\n", debugstr_guid(&clsid));
1529 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1530 if (SUCCEEDED(hr))
1532 IFileSourceFilter *source = NULL;
1533 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID*)&source);
1534 if (SUCCEEDED(hr))
1535 IFileSourceFilter_Release(source);
1536 else
1537 IBaseFilter_Release(*filter);
1540 if (FAILED(hr))
1541 *filter = NULL;
1542 return hr;
1545 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface,
1546 LPCWSTR lpcwstrFileName,
1547 LPCWSTR lpcwstrFilterName,
1548 IBaseFilter **ppFilter) {
1549 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1550 HRESULT hr;
1551 IBaseFilter* preader;
1552 IFileSourceFilter* pfile = NULL;
1553 AM_MEDIA_TYPE mt;
1554 WCHAR* filename;
1556 TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1558 /* Try from file name first, then fall back to default asynchronous reader */
1559 hr = GetFileSourceFilter(lpcwstrFileName, &preader);
1561 if (FAILED(hr))
1562 hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&preader);
1563 if (FAILED(hr)) {
1564 WARN("Unable to create file source filter (%x)\n", hr);
1565 return hr;
1568 hr = IFilterGraph2_AddFilter(iface, preader, lpcwstrFilterName);
1569 if (FAILED(hr)) {
1570 WARN("Unable add filter (%x)\n", hr);
1571 IBaseFilter_Release(preader);
1572 return hr;
1575 hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1576 if (FAILED(hr)) {
1577 WARN("Unable to get IFileSourceInterface (%x)\n", hr);
1578 goto error;
1581 /* Load the file in the file source filter */
1582 hr = IFileSourceFilter_Load(pfile, lpcwstrFileName, NULL);
1583 if (FAILED(hr)) {
1584 WARN("Load (%x)\n", hr);
1585 goto error;
1588 IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1589 if (FAILED(hr)) {
1590 WARN("GetCurFile (%x)\n", hr);
1591 goto error;
1594 TRACE("File %s\n", debugstr_w(filename));
1595 TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
1596 TRACE("SubType %s\n", debugstr_guid(&mt.subtype));
1598 if (ppFilter)
1599 *ppFilter = preader;
1600 IFileSourceFilter_Release(pfile);
1602 return S_OK;
1604 error:
1605 if (pfile)
1606 IFileSourceFilter_Release(pfile);
1607 IFilterGraph2_RemoveFilter(iface, preader);
1608 IBaseFilter_Release(preader);
1610 return hr;
1613 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface,
1614 DWORD_PTR hFile) {
1615 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1617 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1619 return S_OK;
1622 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface) {
1623 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1625 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1627 return S_OK;
1630 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface) {
1631 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1633 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1635 return S_OK;
1638 /*** IFilterGraph2 methods ***/
1639 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1640 IMoniker *pMoniker,
1641 IBindCtx *pCtx,
1642 LPCWSTR lpcwstrFilterName,
1643 IBaseFilter **ppFilter) {
1644 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1646 TRACE("(%p/%p)->(%p %p %s %p): stub !!!\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1648 return S_OK;
1651 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface,
1652 IPin *ppin,
1653 const AM_MEDIA_TYPE *pmt) {
1654 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1656 TRACE("(%p/%p)->(%p %p): stub !!!\n", This, iface, ppin, pmt);
1658 return S_OK;
1661 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface,
1662 IPin *pPinOut,
1663 DWORD dwFlags,
1664 DWORD *pvContext) {
1665 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1667 TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This, iface, pPinOut, dwFlags, pvContext);
1669 return S_OK;
1673 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1675 FilterGraph2_QueryInterface,
1676 FilterGraph2_AddRef,
1677 FilterGraph2_Release,
1678 FilterGraph2_AddFilter,
1679 FilterGraph2_RemoveFilter,
1680 FilterGraph2_EnumFilters,
1681 FilterGraph2_FindFilterByName,
1682 FilterGraph2_ConnectDirect,
1683 FilterGraph2_Reconnect,
1684 FilterGraph2_Disconnect,
1685 FilterGraph2_SetDefaultSyncSource,
1686 FilterGraph2_Connect,
1687 FilterGraph2_Render,
1688 FilterGraph2_RenderFile,
1689 FilterGraph2_AddSourceFilter,
1690 FilterGraph2_SetLogFile,
1691 FilterGraph2_Abort,
1692 FilterGraph2_ShouldOperationContinue,
1693 FilterGraph2_AddSourceFilterForMoniker,
1694 FilterGraph2_ReconnectEx,
1695 FilterGraph2_RenderEx
1698 /*** IUnknown methods ***/
1699 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface,
1700 REFIID riid,
1701 LPVOID*ppvObj) {
1702 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1704 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1706 return Filtergraph_QueryInterface(This, riid, ppvObj);
1709 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface) {
1710 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1712 TRACE("(%p/%p)->()\n", This, iface);
1714 return Filtergraph_AddRef(This);
1717 static ULONG WINAPI MediaControl_Release(IMediaControl *iface) {
1718 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1720 TRACE("(%p/%p)->()\n", This, iface);
1722 return Filtergraph_Release(This);
1726 /*** IDispatch methods ***/
1727 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface,
1728 UINT*pctinfo) {
1729 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1731 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1733 return S_OK;
1736 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface,
1737 UINT iTInfo,
1738 LCID lcid,
1739 ITypeInfo**ppTInfo) {
1740 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1742 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1744 return S_OK;
1747 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface,
1748 REFIID riid,
1749 LPOLESTR*rgszNames,
1750 UINT cNames,
1751 LCID lcid,
1752 DISPID*rgDispId) {
1753 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1755 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1757 return S_OK;
1760 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface,
1761 DISPID dispIdMember,
1762 REFIID riid,
1763 LCID lcid,
1764 WORD wFlags,
1765 DISPPARAMS*pDispParams,
1766 VARIANT*pVarResult,
1767 EXCEPINFO*pExepInfo,
1768 UINT*puArgErr) {
1769 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1771 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
1773 return S_OK;
1776 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *, DWORD_PTR data);
1778 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter, DWORD_PTR data)
1780 HRESULT hr;
1781 IPin* pInputPin;
1782 IPin** ppPins;
1783 ULONG nb;
1784 ULONG i;
1785 PIN_INFO PinInfo;
1787 TRACE("%p %p\n", pGraph, pOutputPin);
1788 PinInfo.pFilter = NULL;
1790 hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1792 if (SUCCEEDED(hr))
1794 hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1795 if (SUCCEEDED(hr))
1796 hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1797 IPin_Release(pInputPin);
1800 if (SUCCEEDED(hr))
1802 if (nb == 0)
1804 TRACE("Reached a renderer\n");
1805 /* Count renderers for end of stream notification */
1806 pGraph->nRenderers++;
1808 else
1810 for(i = 0; i < nb; i++)
1812 /* Explore the graph downstream from this pin
1813 * FIXME: We should prevent exploring from a pin more than once. This can happens when
1814 * several input pins are connected to the same output (a MUX for instance). */
1815 ExploreGraph(pGraph, ppPins[i], FoundFilter, data);
1816 IPin_Release(ppPins[i]);
1819 CoTaskMemFree(ppPins);
1821 TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1823 FoundFilter(PinInfo.pFilter, data);
1826 if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1827 return hr;
1830 static HRESULT WINAPI SendRun(IBaseFilter *pFilter, DWORD_PTR data)
1832 REFERENCE_TIME time = *(REFERENCE_TIME*)data;
1833 return IBaseFilter_Run(pFilter, time);
1836 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1838 return IBaseFilter_Pause(pFilter);
1841 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1843 return IBaseFilter_Stop(pFilter);
1846 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1848 FILTER_STATE state;
1849 DWORD time_end = data;
1850 DWORD time_now = GetTickCount();
1851 LONG wait;
1853 if (time_end == INFINITE)
1855 wait = INFINITE;
1857 else if (time_end > time_now)
1859 wait = time_end - time_now;
1861 else
1862 wait = 0;
1864 return IBaseFilter_GetState(pFilter, wait, &state);
1868 static HRESULT SendFilterMessage(IMediaControl *iface, fnFoundFilter FoundFilter, DWORD_PTR data)
1870 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1871 int i;
1872 IBaseFilter* pfilter;
1873 IEnumPins* pEnum;
1874 HRESULT hr;
1875 IPin* pPin;
1876 DWORD dummy;
1877 PIN_DIRECTION dir;
1878 TRACE("(%p/%p)->()\n", This, iface);
1880 /* Explorer the graph from source filters to renderers, determine renderers
1881 * number and run filters from renderers to source filters */
1882 This->nRenderers = 0;
1883 ResetEvent(This->hEventCompletion);
1885 for(i = 0; i < This->nFilters; i++)
1887 BOOL source = TRUE;
1888 pfilter = This->ppFiltersInGraph[i];
1889 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
1890 if (hr != S_OK)
1892 WARN("Enum pins failed %x\n", hr);
1893 continue;
1895 /* Check if it is a source filter */
1896 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1898 IPin_QueryDirection(pPin, &dir);
1899 IPin_Release(pPin);
1900 if (dir == PINDIR_INPUT)
1902 source = FALSE;
1903 break;
1906 if (source)
1908 TRACE("Found a source filter %p\n", pfilter);
1909 IEnumPins_Reset(pEnum);
1910 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1912 /* Explore the graph downstream from this pin */
1913 ExploreGraph(This, pPin, FoundFilter, data);
1914 IPin_Release(pPin);
1916 FoundFilter(pfilter, data);
1918 IEnumPins_Release(pEnum);
1921 return S_FALSE;
1924 /*** IMediaControl methods ***/
1925 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface) {
1926 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1927 TRACE("(%p/%p)->()\n", This, iface);
1929 EnterCriticalSection(&This->cs);
1930 if (This->state == State_Running)
1931 goto out;
1932 This->EcCompleteCount = 0;
1934 if (This->refClock)
1936 REFERENCE_TIME now;
1937 IReferenceClock_GetTime(This->refClock, &now);
1938 if (This->state == State_Stopped)
1939 This->start_time = now + 500000;
1940 else if (This->pause_time >= 0)
1941 This->start_time += now - This->pause_time;
1942 else
1943 This->start_time = now;
1945 else This->start_time = 0;
1947 SendFilterMessage(iface, SendRun, (DWORD_PTR)&This->start_time);
1948 This->state = State_Running;
1949 out:
1950 LeaveCriticalSection(&This->cs);
1951 return S_FALSE;
1954 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface) {
1955 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1956 TRACE("(%p/%p)->()\n", This, iface);
1958 EnterCriticalSection(&This->cs);
1959 if (This->state == State_Paused)
1960 goto out;
1962 if (This->state == State_Running && This->refClock && This->start_time >= 0)
1963 IReferenceClock_GetTime(This->refClock, &This->pause_time);
1964 else
1965 This->pause_time = -1;
1967 SendFilterMessage(iface, SendPause, 0);
1968 This->state = State_Paused;
1969 out:
1970 LeaveCriticalSection(&This->cs);
1971 return S_FALSE;
1974 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface) {
1975 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1976 TRACE("(%p/%p)->()\n", This, iface);
1978 if (This->state == State_Stopped) return S_OK;
1980 EnterCriticalSection(&This->cs);
1981 if (This->state == State_Running) SendFilterMessage(iface, SendPause, 0);
1982 SendFilterMessage(iface, SendStop, 0);
1983 This->state = State_Stopped;
1984 LeaveCriticalSection(&This->cs);
1985 return S_OK;
1988 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface,
1989 LONG msTimeout,
1990 OAFilterState *pfs) {
1991 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1992 DWORD end;
1994 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
1996 if (!pfs)
1997 return E_POINTER;
1999 EnterCriticalSection(&This->cs);
2001 *pfs = This->state;
2002 if (msTimeout > 0)
2004 end = GetTickCount() + msTimeout;
2006 else if (msTimeout < 0)
2008 end = INFINITE;
2010 else
2012 end = 0;
2014 if (end)
2015 SendFilterMessage(iface, SendGetState, end);
2017 LeaveCriticalSection(&This->cs);
2019 return S_OK;
2022 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface,
2023 BSTR strFilename) {
2024 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2026 FIXME("(%p/%p)->(%s (%p)): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename);
2028 return S_OK;
2031 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface,
2032 BSTR strFilename,
2033 IDispatch **ppUnk) {
2034 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2036 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2038 return S_OK;
2041 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface,
2042 IDispatch **ppUnk) {
2043 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2045 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2047 return S_OK;
2050 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface,
2051 IDispatch **ppUnk) {
2052 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2054 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2056 return S_OK;
2059 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface) {
2060 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2062 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2064 return S_OK;
2068 static const IMediaControlVtbl IMediaControl_VTable =
2070 MediaControl_QueryInterface,
2071 MediaControl_AddRef,
2072 MediaControl_Release,
2073 MediaControl_GetTypeInfoCount,
2074 MediaControl_GetTypeInfo,
2075 MediaControl_GetIDsOfNames,
2076 MediaControl_Invoke,
2077 MediaControl_Run,
2078 MediaControl_Pause,
2079 MediaControl_Stop,
2080 MediaControl_GetState,
2081 MediaControl_RenderFile,
2082 MediaControl_AddSourceFilter,
2083 MediaControl_get_FilterCollection,
2084 MediaControl_get_RegFilterCollection,
2085 MediaControl_StopWhenReady
2089 /*** IUnknown methods ***/
2090 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface,
2091 REFIID riid,
2092 LPVOID*ppvObj) {
2093 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2095 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2097 return Filtergraph_QueryInterface(This, riid, ppvObj);
2100 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface) {
2101 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2103 TRACE("(%p/%p)->()\n", This, iface);
2105 return Filtergraph_AddRef(This);
2108 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface) {
2109 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2111 TRACE("(%p/%p)->()\n", This, iface);
2113 return Filtergraph_Release(This);
2116 typedef HRESULT (WINAPI *fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
2118 static HRESULT all_renderers_seek(IFilterGraphImpl *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2119 BOOL allnotimpl = TRUE;
2120 int i;
2121 HRESULT hr, hr_return = S_OK;
2123 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2124 /* Send a message to all renderers, they are responsible for broadcasting it further */
2126 for(i = 0; i < This->nFilters; i++)
2128 IMediaSeeking *seek = NULL;
2129 IBaseFilter* pfilter = This->ppFiltersInGraph[i];
2130 IAMFilterMiscFlags *flags = NULL;
2131 ULONG filterflags;
2132 IUnknown_QueryInterface(pfilter, &IID_IAMFilterMiscFlags, (void**)&flags);
2133 if (!flags)
2134 continue;
2135 filterflags = IAMFilterMiscFlags_GetMiscFlags(flags);
2136 IUnknown_Release(flags);
2137 if (filterflags != AM_FILTER_MISC_FLAGS_IS_RENDERER)
2138 continue;
2140 IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2141 if (!seek)
2142 continue;
2143 hr = FoundSeek(This, seek, arg);
2144 IMediaSeeking_Release(seek);
2145 if (hr_return != E_NOTIMPL)
2146 allnotimpl = FALSE;
2147 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2148 hr_return = hr;
2151 if (allnotimpl)
2152 return E_NOTIMPL;
2153 return hr_return;
2156 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2158 HRESULT hr;
2159 DWORD caps = 0;
2161 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2162 if (FAILED(hr))
2163 return hr;
2165 /* Only add common capabilities everything supports */
2166 *(DWORD*)pcaps &= caps;
2168 return hr;
2171 /*** IMediaSeeking methods ***/
2172 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface,
2173 DWORD *pCapabilities) {
2174 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2175 HRESULT hr;
2176 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2178 if (!pCapabilities)
2179 return E_POINTER;
2181 EnterCriticalSection(&This->cs);
2182 *pCapabilities = 0xffffffff;
2184 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2185 LeaveCriticalSection(&This->cs);
2187 return hr;
2190 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface,
2191 DWORD *pCapabilities) {
2192 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2193 DWORD originalcaps;
2194 HRESULT hr;
2195 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2197 if (!pCapabilities)
2198 return E_POINTER;
2200 EnterCriticalSection(&This->cs);
2201 originalcaps = *pCapabilities;
2202 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2203 LeaveCriticalSection(&This->cs);
2205 if (FAILED(hr))
2206 return hr;
2208 if (!*pCapabilities)
2209 return E_FAIL;
2210 if (*pCapabilities != originalcaps)
2211 return S_FALSE;
2212 return S_OK;
2215 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface,
2216 const GUID *pFormat) {
2217 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2219 if (!pFormat)
2220 return E_POINTER;
2222 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2224 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2226 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2227 return S_FALSE;
2230 return S_OK;
2233 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface,
2234 GUID *pFormat) {
2235 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2237 if (!pFormat)
2238 return E_POINTER;
2240 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2241 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2243 return S_OK;
2246 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface,
2247 GUID *pFormat) {
2248 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2250 if (!pFormat)
2251 return E_POINTER;
2253 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2254 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2256 return S_OK;
2259 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface,
2260 const GUID *pFormat) {
2261 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2263 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2264 if (!pFormat)
2265 return E_POINTER;
2267 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2268 return S_FALSE;
2270 return S_OK;
2273 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface,
2274 const GUID *pFormat) {
2275 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2277 if (!pFormat)
2278 return E_POINTER;
2280 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2282 if (This->state != State_Stopped)
2283 return VFW_E_WRONG_STATE;
2285 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2287 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2288 return E_INVALIDARG;
2291 return S_OK;
2294 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2296 HRESULT hr;
2297 LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2299 hr = IMediaSeeking_GetDuration(seek, &duration);
2300 if (FAILED(hr))
2301 return hr;
2303 if (*pdur < duration)
2304 *pdur = duration;
2305 return hr;
2308 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface,
2309 LONGLONG *pDuration) {
2310 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2311 HRESULT hr;
2313 TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2315 if (!pDuration)
2316 return E_POINTER;
2318 EnterCriticalSection(&This->cs);
2319 *pDuration = 0;
2320 hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2321 LeaveCriticalSection(&This->cs);
2323 TRACE("--->%08x\n", hr);
2324 return hr;
2327 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface,
2328 LONGLONG *pStop) {
2329 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2330 HRESULT hr = S_OK;
2332 TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2334 if (!pStop)
2335 return E_POINTER;
2337 EnterCriticalSection(&This->cs);
2338 if (This->stop_position < 0)
2339 /* Stop position not set, use duration instead */
2340 hr = IMediaSeeking_GetDuration(iface, pStop);
2341 else
2342 *pStop = This->stop_position;
2343 LeaveCriticalSection(&This->cs);
2345 return hr;
2348 static HRESULT WINAPI FoundCurrentPosition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pposition)
2350 HRESULT hr;
2351 LONGLONG pos = 0, *ppos = (LONGLONG*)pposition;
2353 hr = IMediaSeeking_GetCurrentPosition(seek, &pos);
2354 if (FAILED(hr))
2355 return hr;
2357 if (*ppos < 0 || pos < *ppos)
2358 *ppos = pos;
2359 return hr;
2362 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface,
2363 LONGLONG *pCurrent) {
2364 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2365 HRESULT hr;
2367 if (!pCurrent)
2368 return E_POINTER;
2370 EnterCriticalSection(&This->cs);
2371 *pCurrent = -1;
2372 hr = all_renderers_seek(This, FoundCurrentPosition, (DWORD_PTR)pCurrent);
2373 if (hr == E_NOTIMPL) {
2374 *pCurrent = 0;
2375 hr = S_OK;
2377 LeaveCriticalSection(&This->cs);
2379 TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2381 return hr;
2384 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface,
2385 LONGLONG *pTarget,
2386 const GUID *pTargetFormat,
2387 LONGLONG Source,
2388 const GUID *pSourceFormat) {
2389 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2391 FIXME("(%p/%p)->(%p, %p, 0x%s, %p): stub !!!\n", This, iface, pTarget,
2392 pTargetFormat, wine_dbgstr_longlong(Source), pSourceFormat);
2394 return S_OK;
2397 struct pos_args {
2398 LONGLONG* current, *stop;
2399 DWORD curflags, stopflags;
2402 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2404 struct pos_args *args = (void*)pargs;
2406 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
2409 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface,
2410 LONGLONG *pCurrent,
2411 DWORD dwCurrentFlags,
2412 LONGLONG *pStop,
2413 DWORD dwStopFlags) {
2414 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2415 HRESULT hr = S_OK;
2416 FILTER_STATE state;
2417 struct pos_args args;
2419 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
2421 EnterCriticalSection(&This->cs);
2422 state = This->state;
2423 TRACE("State: %s\n", state == State_Running ? "Running" : (state == State_Paused ? "Paused" : (state == State_Stopped ? "Stopped" : "UNKNOWN")));
2425 if ((dwCurrentFlags & 0x7) != AM_SEEKING_AbsolutePositioning &&
2426 (dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2427 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
2429 if ((dwStopFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2430 This->stop_position = *pStop;
2431 else if ((dwStopFlags & 0x7) != AM_SEEKING_NoPositioning)
2432 FIXME("Stop position not handled yet!\n");
2434 args.current = pCurrent;
2435 args.stop = pStop;
2436 args.curflags = dwCurrentFlags;
2437 args.stopflags = dwStopFlags;
2438 hr = all_renderers_seek(This, found_setposition, (DWORD_PTR)&args);
2440 if ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning) {
2441 if (This->state == State_Running)
2442 FIXME("Seeking while graph is running is not properly supported!\n");
2443 This->pause_time = This->start_time = -1;
2445 LeaveCriticalSection(&This->cs);
2447 return hr;
2450 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface,
2451 LONGLONG *pCurrent,
2452 LONGLONG *pStop) {
2453 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2454 HRESULT hr;
2456 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pCurrent, pStop);
2457 hr = IMediaSeeking_GetCurrentPosition(iface, pCurrent);
2458 if (SUCCEEDED(hr))
2459 hr = IMediaSeeking_GetStopPosition(iface, pStop);
2461 return hr;
2464 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface,
2465 LONGLONG *pEarliest,
2466 LONGLONG *pLatest) {
2467 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2469 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2471 return S_OK;
2474 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface,
2475 double dRate) {
2476 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2478 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2480 return S_OK;
2483 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface,
2484 double *pdRate) {
2485 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2487 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2489 return S_OK;
2492 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface,
2493 LONGLONG *pllPreroll) {
2494 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2496 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2498 return S_OK;
2502 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2504 MediaSeeking_QueryInterface,
2505 MediaSeeking_AddRef,
2506 MediaSeeking_Release,
2507 MediaSeeking_GetCapabilities,
2508 MediaSeeking_CheckCapabilities,
2509 MediaSeeking_IsFormatSupported,
2510 MediaSeeking_QueryPreferredFormat,
2511 MediaSeeking_GetTimeFormat,
2512 MediaSeeking_IsUsingTimeFormat,
2513 MediaSeeking_SetTimeFormat,
2514 MediaSeeking_GetDuration,
2515 MediaSeeking_GetStopPosition,
2516 MediaSeeking_GetCurrentPosition,
2517 MediaSeeking_ConvertTimeFormat,
2518 MediaSeeking_SetPositions,
2519 MediaSeeking_GetPositions,
2520 MediaSeeking_GetAvailable,
2521 MediaSeeking_SetRate,
2522 MediaSeeking_GetRate,
2523 MediaSeeking_GetPreroll
2526 static inline IFilterGraphImpl *impl_from_IMediaPosition( IMediaPosition *iface )
2528 return (IFilterGraphImpl *)((char*)iface - FIELD_OFFSET(IFilterGraphImpl, IMediaPosition_vtbl));
2531 /*** IUnknown methods ***/
2532 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj)
2534 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2536 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2537 return Filtergraph_QueryInterface(This, riid, ppvObj);
2540 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2542 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2544 TRACE("(%p/%p)->()\n", This, iface);
2545 return Filtergraph_AddRef(This);
2548 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2550 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2552 TRACE("(%p/%p)->()\n", This, iface);
2553 return Filtergraph_Release(This);
2556 /*** IDispatch methods ***/
2557 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo){
2558 FIXME("(%p) stub!\n", iface);
2559 return E_NOTIMPL;
2562 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo){
2563 FIXME("(%p) stub!\n", iface);
2564 return E_NOTIMPL;
2567 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId){
2568 FIXME("(%p) stub!\n", iface);
2569 return E_NOTIMPL;
2572 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr){
2573 FIXME("(%p) stub!\n", iface);
2574 return E_NOTIMPL;
2577 /*** IMediaPosition methods ***/
2578 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2580 LONGLONG duration;
2581 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2582 HRESULT hr = IMediaSeeking_GetDuration( (IMediaSeeking *)&This->IMediaSeeking_vtbl, &duration );
2583 if (SUCCEEDED(hr)) *plength = duration;
2584 return hr;
2587 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2589 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2590 LONGLONG reftime = llTime;
2592 return IMediaSeeking_SetPositions((IMediaSeeking *)&This->IMediaSeeking_vtbl,
2593 &reftime, AM_SEEKING_AbsolutePositioning,
2594 NULL, AM_SEEKING_NoPositioning);
2597 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2599 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2600 LONGLONG pos;
2601 HRESULT hr = IMediaSeeking_GetCurrentPosition( (IMediaSeeking *)&This->IMediaSeeking_vtbl, &pos );
2602 if (SUCCEEDED(hr)) *pllTime = pos;
2603 return hr;
2606 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2608 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2609 LONGLONG pos;
2610 HRESULT hr = IMediaSeeking_GetStopPosition( (IMediaSeeking *)&This->IMediaSeeking_vtbl, &pos );
2611 if (SUCCEEDED(hr)) *pllTime = pos;
2612 return hr;
2615 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2617 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2618 LONGLONG reftime = llTime;
2620 return IMediaSeeking_SetPositions((IMediaSeeking *)&This->IMediaSeeking_vtbl,
2621 NULL, AM_SEEKING_NoPositioning,
2622 &reftime, AM_SEEKING_AbsolutePositioning);
2625 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime){
2626 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2627 return E_NOTIMPL;
2630 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime){
2631 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2632 return E_NOTIMPL;
2635 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2637 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2638 return IMediaSeeking_SetRate((IMediaSeeking *)&This->IMediaSeeking_vtbl, dRate);
2641 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2643 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2644 return IMediaSeeking_GetRate((IMediaSeeking *)&This->IMediaSeeking_vtbl, pdRate);
2647 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward){
2648 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2649 return E_NOTIMPL;
2652 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward){
2653 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2654 return E_NOTIMPL;
2658 static const IMediaPositionVtbl IMediaPosition_VTable =
2660 MediaPosition_QueryInterface,
2661 MediaPosition_AddRef,
2662 MediaPosition_Release,
2663 MediaPosition_GetTypeInfoCount,
2664 MediaPosition_GetTypeInfo,
2665 MediaPosition_GetIDsOfNames,
2666 MediaPosition_Invoke,
2667 MediaPosition_get_Duration,
2668 MediaPosition_put_CurrentPosition,
2669 MediaPosition_get_CurrentPosition,
2670 MediaPosition_get_StopTime,
2671 MediaPosition_put_StopTime,
2672 MediaPosition_get_PrerollTime,
2673 MediaPosition_put_PrerollTime,
2674 MediaPosition_put_Rate,
2675 MediaPosition_get_Rate,
2676 MediaPosition_CanSeekForward,
2677 MediaPosition_CanSeekBackward
2680 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2682 HRESULT hr = E_NOINTERFACE;
2683 int i;
2684 int entry;
2686 /* Check if the interface type is already registered */
2687 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2688 if (riid == pGraph->ItfCacheEntries[entry].riid)
2690 if (pGraph->ItfCacheEntries[entry].iface)
2692 /* Return the interface if available */
2693 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2694 return S_OK;
2696 break;
2699 if (entry >= MAX_ITF_CACHE_ENTRIES)
2701 FIXME("Not enough space to store interface in the cache\n");
2702 return E_OUTOFMEMORY;
2705 /* Find a filter supporting the requested interface */
2706 for (i = 0; i < pGraph->nFilters; i++)
2708 hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2709 if (hr == S_OK)
2711 pGraph->ItfCacheEntries[entry].riid = riid;
2712 pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2713 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2714 if (entry >= pGraph->nItfCacheEntries)
2715 pGraph->nItfCacheEntries++;
2716 return S_OK;
2718 if (hr != E_NOINTERFACE)
2719 return hr;
2722 return hr;
2725 /*** IUnknown methods ***/
2726 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface,
2727 REFIID riid,
2728 LPVOID*ppvObj) {
2729 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2731 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2733 return Filtergraph_QueryInterface(This, riid, ppvObj);
2736 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface) {
2737 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2739 TRACE("(%p/%p)->()\n", This, iface);
2741 return Filtergraph_AddRef(This);
2744 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface) {
2745 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2747 TRACE("(%p/%p)->()\n", This, iface);
2749 return Filtergraph_Release(This);
2752 /*** IDispatch methods ***/
2753 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface,
2754 UINT*pctinfo) {
2755 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2756 IBasicAudio* pBasicAudio;
2757 HRESULT hr;
2759 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
2761 EnterCriticalSection(&This->cs);
2763 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2765 if (hr == S_OK)
2766 hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
2768 LeaveCriticalSection(&This->cs);
2770 return hr;
2773 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface,
2774 UINT iTInfo,
2775 LCID lcid,
2776 ITypeInfo**ppTInfo) {
2777 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2778 IBasicAudio* pBasicAudio;
2779 HRESULT hr;
2781 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
2783 EnterCriticalSection(&This->cs);
2785 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2787 if (hr == S_OK)
2788 hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
2790 LeaveCriticalSection(&This->cs);
2792 return hr;
2795 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface,
2796 REFIID riid,
2797 LPOLESTR*rgszNames,
2798 UINT cNames,
2799 LCID lcid,
2800 DISPID*rgDispId) {
2801 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2802 IBasicAudio* pBasicAudio;
2803 HRESULT hr;
2805 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
2807 EnterCriticalSection(&This->cs);
2809 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2811 if (hr == S_OK)
2812 hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
2814 LeaveCriticalSection(&This->cs);
2816 return hr;
2819 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface,
2820 DISPID dispIdMember,
2821 REFIID riid,
2822 LCID lcid,
2823 WORD wFlags,
2824 DISPPARAMS*pDispParams,
2825 VARIANT*pVarResult,
2826 EXCEPINFO*pExepInfo,
2827 UINT*puArgErr) {
2828 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2829 IBasicAudio* pBasicAudio;
2830 HRESULT hr;
2832 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
2834 EnterCriticalSection(&This->cs);
2836 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2838 if (hr == S_OK)
2839 hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
2841 LeaveCriticalSection(&This->cs);
2843 return hr;
2846 /*** IBasicAudio methods ***/
2847 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface,
2848 LONG lVolume) {
2849 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2850 IBasicAudio* pBasicAudio;
2851 HRESULT hr;
2853 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
2855 EnterCriticalSection(&This->cs);
2857 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2859 if (hr == S_OK)
2860 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
2862 LeaveCriticalSection(&This->cs);
2864 return hr;
2867 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface,
2868 LONG *plVolume) {
2869 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2870 IBasicAudio* pBasicAudio;
2871 HRESULT hr;
2873 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
2875 EnterCriticalSection(&This->cs);
2877 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2879 if (hr == S_OK)
2880 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
2882 LeaveCriticalSection(&This->cs);
2884 return hr;
2887 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface,
2888 LONG lBalance) {
2889 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2890 IBasicAudio* pBasicAudio;
2891 HRESULT hr;
2893 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
2895 EnterCriticalSection(&This->cs);
2897 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2899 if (hr == S_OK)
2900 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
2902 LeaveCriticalSection(&This->cs);
2904 return hr;
2907 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface,
2908 LONG *plBalance) {
2909 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2910 IBasicAudio* pBasicAudio;
2911 HRESULT hr;
2913 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
2915 EnterCriticalSection(&This->cs);
2917 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2919 if (hr == S_OK)
2920 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
2922 LeaveCriticalSection(&This->cs);
2924 return hr;
2927 static const IBasicAudioVtbl IBasicAudio_VTable =
2929 BasicAudio_QueryInterface,
2930 BasicAudio_AddRef,
2931 BasicAudio_Release,
2932 BasicAudio_GetTypeInfoCount,
2933 BasicAudio_GetTypeInfo,
2934 BasicAudio_GetIDsOfNames,
2935 BasicAudio_Invoke,
2936 BasicAudio_put_Volume,
2937 BasicAudio_get_Volume,
2938 BasicAudio_put_Balance,
2939 BasicAudio_get_Balance
2942 /*** IUnknown methods ***/
2943 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface,
2944 REFIID riid,
2945 LPVOID*ppvObj) {
2946 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2948 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2950 return Filtergraph_QueryInterface(This, riid, ppvObj);
2953 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface) {
2954 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2956 TRACE("(%p/%p)->()\n", This, iface);
2958 return Filtergraph_AddRef(This);
2961 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface) {
2962 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2964 TRACE("(%p/%p)->()\n", This, iface);
2966 return Filtergraph_Release(This);
2969 /*** IDispatch methods ***/
2970 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface,
2971 UINT*pctinfo) {
2972 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2973 IBasicVideo* pBasicVideo;
2974 HRESULT hr;
2976 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
2978 EnterCriticalSection(&This->cs);
2980 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2982 if (hr == S_OK)
2983 hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
2985 LeaveCriticalSection(&This->cs);
2987 return hr;
2990 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface,
2991 UINT iTInfo,
2992 LCID lcid,
2993 ITypeInfo**ppTInfo) {
2994 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2995 IBasicVideo* pBasicVideo;
2996 HRESULT hr;
2998 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3000 EnterCriticalSection(&This->cs);
3002 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3004 if (hr == S_OK)
3005 hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
3007 LeaveCriticalSection(&This->cs);
3009 return hr;
3012 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface,
3013 REFIID riid,
3014 LPOLESTR*rgszNames,
3015 UINT cNames,
3016 LCID lcid,
3017 DISPID*rgDispId) {
3018 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3019 IBasicVideo* pBasicVideo;
3020 HRESULT hr;
3022 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3024 EnterCriticalSection(&This->cs);
3026 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3028 if (hr == S_OK)
3029 hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
3031 LeaveCriticalSection(&This->cs);
3033 return hr;
3036 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface,
3037 DISPID dispIdMember,
3038 REFIID riid,
3039 LCID lcid,
3040 WORD wFlags,
3041 DISPPARAMS*pDispParams,
3042 VARIANT*pVarResult,
3043 EXCEPINFO*pExepInfo,
3044 UINT*puArgErr) {
3045 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3046 IBasicVideo* pBasicVideo;
3047 HRESULT hr;
3049 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3051 EnterCriticalSection(&This->cs);
3053 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3055 if (hr == S_OK)
3056 hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3058 LeaveCriticalSection(&This->cs);
3060 return hr;
3063 /*** IBasicVideo methods ***/
3064 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface,
3065 REFTIME *pAvgTimePerFrame) {
3066 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3067 IBasicVideo* pBasicVideo;
3068 HRESULT hr;
3070 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3072 EnterCriticalSection(&This->cs);
3074 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3076 if (hr == S_OK)
3077 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3079 LeaveCriticalSection(&This->cs);
3081 return hr;
3084 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface,
3085 LONG *pBitRate) {
3086 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3087 IBasicVideo* pBasicVideo;
3088 HRESULT hr;
3090 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3092 EnterCriticalSection(&This->cs);
3094 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3096 if (hr == S_OK)
3097 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3099 LeaveCriticalSection(&This->cs);
3101 return hr;
3104 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface,
3105 LONG *pBitErrorRate) {
3106 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3107 IBasicVideo* pBasicVideo;
3108 HRESULT hr;
3110 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3112 EnterCriticalSection(&This->cs);
3114 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3116 if (hr == S_OK)
3117 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3119 LeaveCriticalSection(&This->cs);
3121 return hr;
3124 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface,
3125 LONG *pVideoWidth) {
3126 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3127 IBasicVideo* pBasicVideo;
3128 HRESULT hr;
3130 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3132 EnterCriticalSection(&This->cs);
3134 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3136 if (hr == S_OK)
3137 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3139 LeaveCriticalSection(&This->cs);
3141 return hr;
3144 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface,
3145 LONG *pVideoHeight) {
3146 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3147 IBasicVideo* pBasicVideo;
3148 HRESULT hr;
3150 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3152 EnterCriticalSection(&This->cs);
3154 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3156 if (hr == S_OK)
3157 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3159 LeaveCriticalSection(&This->cs);
3161 return hr;
3164 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface,
3165 LONG SourceLeft) {
3166 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3167 IBasicVideo* pBasicVideo;
3168 HRESULT hr;
3170 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3172 EnterCriticalSection(&This->cs);
3174 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3176 if (hr == S_OK)
3177 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3179 LeaveCriticalSection(&This->cs);
3181 return hr;
3184 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface,
3185 LONG *pSourceLeft) {
3186 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3187 IBasicVideo* pBasicVideo;
3188 HRESULT hr;
3190 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3192 EnterCriticalSection(&This->cs);
3194 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3196 if (hr == S_OK)
3197 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3199 LeaveCriticalSection(&This->cs);
3201 return hr;
3204 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface,
3205 LONG SourceWidth) {
3206 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3207 IBasicVideo* pBasicVideo;
3208 HRESULT hr;
3210 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3212 EnterCriticalSection(&This->cs);
3214 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3216 if (hr == S_OK)
3217 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3219 LeaveCriticalSection(&This->cs);
3221 return hr;
3224 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface,
3225 LONG *pSourceWidth) {
3226 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3227 IBasicVideo* pBasicVideo;
3228 HRESULT hr;
3230 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3232 EnterCriticalSection(&This->cs);
3234 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3236 if (hr == S_OK)
3237 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3239 LeaveCriticalSection(&This->cs);
3241 return hr;
3244 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface,
3245 LONG SourceTop) {
3246 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3247 IBasicVideo* pBasicVideo;
3248 HRESULT hr;
3250 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3252 EnterCriticalSection(&This->cs);
3254 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3256 if (hr == S_OK)
3257 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3259 LeaveCriticalSection(&This->cs);
3261 return hr;
3264 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface,
3265 LONG *pSourceTop) {
3266 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3267 IBasicVideo* pBasicVideo;
3268 HRESULT hr;
3270 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3272 EnterCriticalSection(&This->cs);
3274 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3276 if (hr == S_OK)
3277 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3279 LeaveCriticalSection(&This->cs);
3281 return hr;
3284 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface,
3285 LONG SourceHeight) {
3286 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3287 IBasicVideo* pBasicVideo;
3288 HRESULT hr;
3290 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3292 EnterCriticalSection(&This->cs);
3294 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3296 if (hr == S_OK)
3297 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3299 LeaveCriticalSection(&This->cs);
3301 return hr;
3304 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface,
3305 LONG *pSourceHeight) {
3306 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3307 IBasicVideo* pBasicVideo;
3308 HRESULT hr;
3310 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3312 EnterCriticalSection(&This->cs);
3314 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3316 if (hr == S_OK)
3317 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3319 LeaveCriticalSection(&This->cs);
3321 return hr;
3324 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface,
3325 LONG DestinationLeft) {
3326 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3327 IBasicVideo* pBasicVideo;
3328 HRESULT hr;
3330 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3332 EnterCriticalSection(&This->cs);
3334 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3336 if (hr == S_OK)
3337 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3339 LeaveCriticalSection(&This->cs);
3341 return hr;
3344 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface,
3345 LONG *pDestinationLeft) {
3346 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3347 IBasicVideo* pBasicVideo;
3348 HRESULT hr;
3350 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3352 EnterCriticalSection(&This->cs);
3354 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3356 if (hr == S_OK)
3357 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3359 LeaveCriticalSection(&This->cs);
3361 return hr;
3364 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface,
3365 LONG DestinationWidth) {
3366 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3367 IBasicVideo* pBasicVideo;
3368 HRESULT hr;
3370 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3372 EnterCriticalSection(&This->cs);
3374 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3376 if (hr == S_OK)
3377 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3379 LeaveCriticalSection(&This->cs);
3381 return hr;
3384 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface,
3385 LONG *pDestinationWidth) {
3386 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3387 IBasicVideo* pBasicVideo;
3388 HRESULT hr;
3390 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3392 EnterCriticalSection(&This->cs);
3394 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3396 if (hr == S_OK)
3397 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3399 LeaveCriticalSection(&This->cs);
3401 return hr;
3404 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface,
3405 LONG DestinationTop) {
3406 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3407 IBasicVideo* pBasicVideo;
3408 HRESULT hr;
3410 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3412 EnterCriticalSection(&This->cs);
3414 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3416 if (hr == S_OK)
3417 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3419 LeaveCriticalSection(&This->cs);
3421 return hr;
3424 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface,
3425 LONG *pDestinationTop) {
3426 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3427 IBasicVideo* pBasicVideo;
3428 HRESULT hr;
3430 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3432 EnterCriticalSection(&This->cs);
3434 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3436 if (hr == S_OK)
3437 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3439 LeaveCriticalSection(&This->cs);
3441 return hr;
3444 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface,
3445 LONG DestinationHeight) {
3446 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3447 IBasicVideo* pBasicVideo;
3448 HRESULT hr;
3450 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3452 EnterCriticalSection(&This->cs);
3454 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3456 if (hr == S_OK)
3457 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3459 LeaveCriticalSection(&This->cs);
3461 return hr;
3464 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3465 LONG *pDestinationHeight) {
3466 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3467 IBasicVideo* pBasicVideo;
3468 HRESULT hr;
3470 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3472 EnterCriticalSection(&This->cs);
3474 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3476 if (hr == S_OK)
3477 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3479 LeaveCriticalSection(&This->cs);
3481 return hr;
3484 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface,
3485 LONG Left,
3486 LONG Top,
3487 LONG Width,
3488 LONG Height) {
3489 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3490 IBasicVideo* pBasicVideo;
3491 HRESULT hr;
3493 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3495 EnterCriticalSection(&This->cs);
3497 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3499 if (hr == S_OK)
3500 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3502 LeaveCriticalSection(&This->cs);
3504 return hr;
3507 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface,
3508 LONG *pLeft,
3509 LONG *pTop,
3510 LONG *pWidth,
3511 LONG *pHeight) {
3512 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3513 IBasicVideo* pBasicVideo;
3514 HRESULT hr;
3516 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3518 EnterCriticalSection(&This->cs);
3520 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3522 if (hr == S_OK)
3523 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3525 LeaveCriticalSection(&This->cs);
3527 return hr;
3530 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface) {
3531 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3532 IBasicVideo* pBasicVideo;
3533 HRESULT hr;
3535 TRACE("(%p/%p)->()\n", This, iface);
3537 EnterCriticalSection(&This->cs);
3539 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3541 if (hr == S_OK)
3542 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3544 LeaveCriticalSection(&This->cs);
3546 return hr;
3549 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface,
3550 LONG Left,
3551 LONG Top,
3552 LONG Width,
3553 LONG Height) {
3554 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3555 IBasicVideo* pBasicVideo;
3556 HRESULT hr;
3558 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3560 EnterCriticalSection(&This->cs);
3562 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3564 if (hr == S_OK)
3565 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3567 LeaveCriticalSection(&This->cs);
3569 return hr;
3572 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface,
3573 LONG *pLeft,
3574 LONG *pTop,
3575 LONG *pWidth,
3576 LONG *pHeight) {
3577 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3578 IBasicVideo* pBasicVideo;
3579 HRESULT hr;
3581 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3583 EnterCriticalSection(&This->cs);
3585 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3587 if (hr == S_OK)
3588 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3590 LeaveCriticalSection(&This->cs);
3592 return hr;
3595 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface) {
3596 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3597 IBasicVideo* pBasicVideo;
3598 HRESULT hr;
3600 TRACE("(%p/%p)->()\n", This, iface);
3602 EnterCriticalSection(&This->cs);
3604 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3606 if (hr == S_OK)
3607 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3609 LeaveCriticalSection(&This->cs);
3611 return hr;
3614 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface,
3615 LONG *pWidth,
3616 LONG *pHeight) {
3617 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3618 IBasicVideo* pBasicVideo;
3619 HRESULT hr;
3621 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3623 EnterCriticalSection(&This->cs);
3625 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3627 if (hr == S_OK)
3628 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3630 LeaveCriticalSection(&This->cs);
3632 return hr;
3635 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface,
3636 LONG StartIndex,
3637 LONG Entries,
3638 LONG *pRetrieved,
3639 LONG *pPalette) {
3640 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3641 IBasicVideo* pBasicVideo;
3642 HRESULT hr;
3644 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3646 EnterCriticalSection(&This->cs);
3648 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3650 if (hr == S_OK)
3651 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3653 LeaveCriticalSection(&This->cs);
3655 return hr;
3658 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface,
3659 LONG *pBufferSize,
3660 LONG *pDIBImage) {
3661 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3662 IBasicVideo* pBasicVideo;
3663 HRESULT hr;
3665 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3667 EnterCriticalSection(&This->cs);
3669 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3671 if (hr == S_OK)
3672 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3674 LeaveCriticalSection(&This->cs);
3676 return hr;
3679 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface) {
3680 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3681 IBasicVideo* pBasicVideo;
3682 HRESULT hr;
3684 TRACE("(%p/%p)->()\n", This, iface);
3686 EnterCriticalSection(&This->cs);
3688 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3690 if (hr == S_OK)
3691 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3693 LeaveCriticalSection(&This->cs);
3695 return hr;
3698 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface) {
3699 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3700 IBasicVideo* pBasicVideo;
3701 HRESULT hr;
3703 TRACE("(%p/%p)->()\n", This, iface);
3705 EnterCriticalSection(&This->cs);
3707 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3709 if (hr == S_OK)
3710 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3712 LeaveCriticalSection(&This->cs);
3714 return hr;
3717 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX, LONG *plAspectY) {
3718 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3719 IBasicVideo2 *pBasicVideo2;
3720 HRESULT hr;
3722 TRACE("(%p/%p)->()\n", This, iface);
3724 EnterCriticalSection(&This->cs);
3726 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3728 if (hr == S_OK)
3729 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3731 LeaveCriticalSection(&This->cs);
3733 return hr;
3736 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3738 BasicVideo_QueryInterface,
3739 BasicVideo_AddRef,
3740 BasicVideo_Release,
3741 BasicVideo_GetTypeInfoCount,
3742 BasicVideo_GetTypeInfo,
3743 BasicVideo_GetIDsOfNames,
3744 BasicVideo_Invoke,
3745 BasicVideo_get_AvgTimePerFrame,
3746 BasicVideo_get_BitRate,
3747 BasicVideo_get_BitErrorRate,
3748 BasicVideo_get_VideoWidth,
3749 BasicVideo_get_VideoHeight,
3750 BasicVideo_put_SourceLeft,
3751 BasicVideo_get_SourceLeft,
3752 BasicVideo_put_SourceWidth,
3753 BasicVideo_get_SourceWidth,
3754 BasicVideo_put_SourceTop,
3755 BasicVideo_get_SourceTop,
3756 BasicVideo_put_SourceHeight,
3757 BasicVideo_get_SourceHeight,
3758 BasicVideo_put_DestinationLeft,
3759 BasicVideo_get_DestinationLeft,
3760 BasicVideo_put_DestinationWidth,
3761 BasicVideo_get_DestinationWidth,
3762 BasicVideo_put_DestinationTop,
3763 BasicVideo_get_DestinationTop,
3764 BasicVideo_put_DestinationHeight,
3765 BasicVideo_get_DestinationHeight,
3766 BasicVideo_SetSourcePosition,
3767 BasicVideo_GetSourcePosition,
3768 BasicVideo_SetDefaultSourcePosition,
3769 BasicVideo_SetDestinationPosition,
3770 BasicVideo_GetDestinationPosition,
3771 BasicVideo_SetDefaultDestinationPosition,
3772 BasicVideo_GetVideoSize,
3773 BasicVideo_GetVideoPaletteEntries,
3774 BasicVideo_GetCurrentImage,
3775 BasicVideo_IsUsingDefaultSource,
3776 BasicVideo_IsUsingDefaultDestination,
3777 BasicVideo2_GetPreferredAspectRatio
3781 /*** IUnknown methods ***/
3782 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface,
3783 REFIID riid,
3784 LPVOID*ppvObj) {
3785 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3787 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3789 return Filtergraph_QueryInterface(This, riid, ppvObj);
3792 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface) {
3793 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3795 TRACE("(%p/%p)->()\n", This, iface);
3797 return Filtergraph_AddRef(This);
3800 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface) {
3801 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3803 TRACE("(%p/%p)->()\n", This, iface);
3805 return Filtergraph_Release(This);
3808 /*** IDispatch methods ***/
3809 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface,
3810 UINT*pctinfo) {
3811 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3812 IVideoWindow* pVideoWindow;
3813 HRESULT hr;
3815 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3817 EnterCriticalSection(&This->cs);
3819 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3821 if (hr == S_OK)
3822 hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
3824 LeaveCriticalSection(&This->cs);
3826 return hr;
3829 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface,
3830 UINT iTInfo,
3831 LCID lcid,
3832 ITypeInfo**ppTInfo) {
3833 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3834 IVideoWindow* pVideoWindow;
3835 HRESULT hr;
3837 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3839 EnterCriticalSection(&This->cs);
3841 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3843 if (hr == S_OK)
3844 hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
3846 LeaveCriticalSection(&This->cs);
3848 return hr;
3851 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface,
3852 REFIID riid,
3853 LPOLESTR*rgszNames,
3854 UINT cNames,
3855 LCID lcid,
3856 DISPID*rgDispId) {
3857 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3858 IVideoWindow* pVideoWindow;
3859 HRESULT hr;
3861 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3863 EnterCriticalSection(&This->cs);
3865 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3867 if (hr == S_OK)
3868 hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
3870 LeaveCriticalSection(&This->cs);
3872 return hr;
3875 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface,
3876 DISPID dispIdMember,
3877 REFIID riid,
3878 LCID lcid,
3879 WORD wFlags,
3880 DISPPARAMS*pDispParams,
3881 VARIANT*pVarResult,
3882 EXCEPINFO*pExepInfo,
3883 UINT*puArgErr) {
3884 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3885 IVideoWindow* pVideoWindow;
3886 HRESULT hr;
3888 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3890 EnterCriticalSection(&This->cs);
3892 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3894 if (hr == S_OK)
3895 hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3897 LeaveCriticalSection(&This->cs);
3899 return hr;
3903 /*** IVideoWindow methods ***/
3904 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface,
3905 BSTR strCaption) {
3906 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3907 IVideoWindow* pVideoWindow;
3908 HRESULT hr;
3910 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
3912 EnterCriticalSection(&This->cs);
3914 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3916 if (hr == S_OK)
3917 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
3919 LeaveCriticalSection(&This->cs);
3921 return hr;
3924 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface,
3925 BSTR *strCaption) {
3926 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3927 IVideoWindow* pVideoWindow;
3928 HRESULT hr;
3930 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
3932 EnterCriticalSection(&This->cs);
3934 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3936 if (hr == S_OK)
3937 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
3939 LeaveCriticalSection(&This->cs);
3941 return hr;
3944 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface,
3945 LONG WindowStyle) {
3946 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3947 IVideoWindow* pVideoWindow;
3948 HRESULT hr;
3950 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
3952 EnterCriticalSection(&This->cs);
3954 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3956 if (hr == S_OK)
3957 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
3959 LeaveCriticalSection(&This->cs);
3961 return hr;
3964 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface,
3965 LONG *WindowStyle) {
3966 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3967 IVideoWindow* pVideoWindow;
3968 HRESULT hr;
3970 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
3972 EnterCriticalSection(&This->cs);
3974 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3976 if (hr == S_OK)
3977 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
3979 LeaveCriticalSection(&This->cs);
3981 return hr;
3984 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface,
3985 LONG WindowStyleEx) {
3986 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3987 IVideoWindow* pVideoWindow;
3988 HRESULT hr;
3990 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
3992 EnterCriticalSection(&This->cs);
3994 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3996 if (hr == S_OK)
3997 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
3999 LeaveCriticalSection(&This->cs);
4001 return hr;
4004 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface,
4005 LONG *WindowStyleEx) {
4006 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4007 IVideoWindow* pVideoWindow;
4008 HRESULT hr;
4010 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
4012 EnterCriticalSection(&This->cs);
4014 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4016 if (hr == S_OK)
4017 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
4019 LeaveCriticalSection(&This->cs);
4021 return hr;
4024 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface,
4025 LONG AutoShow) {
4026 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4027 IVideoWindow* pVideoWindow;
4028 HRESULT hr;
4030 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
4032 EnterCriticalSection(&This->cs);
4034 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4036 if (hr == S_OK)
4037 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4039 LeaveCriticalSection(&This->cs);
4041 return hr;
4044 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface,
4045 LONG *AutoShow) {
4046 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4047 IVideoWindow* pVideoWindow;
4048 HRESULT hr;
4050 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4052 EnterCriticalSection(&This->cs);
4054 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4056 if (hr == S_OK)
4057 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4059 LeaveCriticalSection(&This->cs);
4061 return hr;
4064 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface,
4065 LONG WindowState) {
4066 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4067 IVideoWindow* pVideoWindow;
4068 HRESULT hr;
4070 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4072 EnterCriticalSection(&This->cs);
4074 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4076 if (hr == S_OK)
4077 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4079 LeaveCriticalSection(&This->cs);
4081 return hr;
4084 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface,
4085 LONG *WindowState) {
4086 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4087 IVideoWindow* pVideoWindow;
4088 HRESULT hr;
4090 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4092 EnterCriticalSection(&This->cs);
4094 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4096 if (hr == S_OK)
4097 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4099 LeaveCriticalSection(&This->cs);
4101 return hr;
4104 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface,
4105 LONG BackgroundPalette) {
4106 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4107 IVideoWindow* pVideoWindow;
4108 HRESULT hr;
4110 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4112 EnterCriticalSection(&This->cs);
4114 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4116 if (hr == S_OK)
4117 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4119 LeaveCriticalSection(&This->cs);
4121 return hr;
4124 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4125 LONG *pBackgroundPalette) {
4126 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4127 IVideoWindow* pVideoWindow;
4128 HRESULT hr;
4130 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4132 EnterCriticalSection(&This->cs);
4134 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4136 if (hr == S_OK)
4137 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4139 LeaveCriticalSection(&This->cs);
4141 return hr;
4144 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface,
4145 LONG Visible) {
4146 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4147 IVideoWindow* pVideoWindow;
4148 HRESULT hr;
4150 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4152 EnterCriticalSection(&This->cs);
4154 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4156 if (hr == S_OK)
4157 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4159 LeaveCriticalSection(&This->cs);
4161 return hr;
4164 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface,
4165 LONG *pVisible) {
4166 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4167 IVideoWindow* pVideoWindow;
4168 HRESULT hr;
4170 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4172 EnterCriticalSection(&This->cs);
4174 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4176 if (hr == S_OK)
4177 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4179 LeaveCriticalSection(&This->cs);
4181 return hr;
4184 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface,
4185 LONG Left) {
4186 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4187 IVideoWindow* pVideoWindow;
4188 HRESULT hr;
4190 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4192 EnterCriticalSection(&This->cs);
4194 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4196 if (hr == S_OK)
4197 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4199 LeaveCriticalSection(&This->cs);
4201 return hr;
4204 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface,
4205 LONG *pLeft) {
4206 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4207 IVideoWindow* pVideoWindow;
4208 HRESULT hr;
4210 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4212 EnterCriticalSection(&This->cs);
4214 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4216 if (hr == S_OK)
4217 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4219 LeaveCriticalSection(&This->cs);
4221 return hr;
4224 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface,
4225 LONG Width) {
4226 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4227 IVideoWindow* pVideoWindow;
4228 HRESULT hr;
4230 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4232 EnterCriticalSection(&This->cs);
4234 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4236 if (hr == S_OK)
4237 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4239 LeaveCriticalSection(&This->cs);
4241 return hr;
4244 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface,
4245 LONG *pWidth) {
4246 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4247 IVideoWindow* pVideoWindow;
4248 HRESULT hr;
4250 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4252 EnterCriticalSection(&This->cs);
4254 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4256 if (hr == S_OK)
4257 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4259 LeaveCriticalSection(&This->cs);
4261 return hr;
4264 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface,
4265 LONG Top) {
4266 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4267 IVideoWindow* pVideoWindow;
4268 HRESULT hr;
4270 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4272 EnterCriticalSection(&This->cs);
4274 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4276 if (hr == S_OK)
4277 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4279 LeaveCriticalSection(&This->cs);
4281 return hr;
4284 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface,
4285 LONG *pTop) {
4286 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4287 IVideoWindow* pVideoWindow;
4288 HRESULT hr;
4290 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4292 EnterCriticalSection(&This->cs);
4294 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4296 if (hr == S_OK)
4297 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4299 LeaveCriticalSection(&This->cs);
4301 return hr;
4304 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface,
4305 LONG Height) {
4306 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4307 IVideoWindow* pVideoWindow;
4308 HRESULT hr;
4310 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4312 EnterCriticalSection(&This->cs);
4314 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4316 if (hr == S_OK)
4317 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4319 LeaveCriticalSection(&This->cs);
4321 return hr;
4324 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface,
4325 LONG *pHeight) {
4326 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4327 IVideoWindow* pVideoWindow;
4328 HRESULT hr;
4330 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4332 EnterCriticalSection(&This->cs);
4334 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4336 if (hr == S_OK)
4337 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4339 LeaveCriticalSection(&This->cs);
4341 return hr;
4344 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface,
4345 OAHWND Owner) {
4346 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4347 IVideoWindow* pVideoWindow;
4348 HRESULT hr;
4350 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4352 EnterCriticalSection(&This->cs);
4354 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4356 if (hr == S_OK)
4357 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4359 LeaveCriticalSection(&This->cs);
4361 return hr;
4364 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface,
4365 OAHWND *Owner) {
4366 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4367 IVideoWindow* pVideoWindow;
4368 HRESULT hr;
4370 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4372 EnterCriticalSection(&This->cs);
4374 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4376 if (hr == S_OK)
4377 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4379 LeaveCriticalSection(&This->cs);
4381 return hr;
4384 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface,
4385 OAHWND Drain) {
4386 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4387 IVideoWindow* pVideoWindow;
4388 HRESULT hr;
4390 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4392 EnterCriticalSection(&This->cs);
4394 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4396 if (hr == S_OK)
4397 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4399 LeaveCriticalSection(&This->cs);
4401 return hr;
4404 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface,
4405 OAHWND *Drain) {
4406 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4407 IVideoWindow* pVideoWindow;
4408 HRESULT hr;
4410 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4412 EnterCriticalSection(&This->cs);
4414 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4416 if (hr == S_OK)
4417 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4419 LeaveCriticalSection(&This->cs);
4421 return hr;
4424 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface,
4425 LONG *Color) {
4426 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4427 IVideoWindow* pVideoWindow;
4428 HRESULT hr;
4430 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4432 EnterCriticalSection(&This->cs);
4434 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4436 if (hr == S_OK)
4437 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4439 LeaveCriticalSection(&This->cs);
4441 return hr;
4444 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface,
4445 LONG Color) {
4446 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4447 IVideoWindow* pVideoWindow;
4448 HRESULT hr;
4450 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4452 EnterCriticalSection(&This->cs);
4454 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4456 if (hr == S_OK)
4457 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4459 LeaveCriticalSection(&This->cs);
4461 return hr;
4464 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface,
4465 LONG *FullScreenMode) {
4466 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4467 IVideoWindow* pVideoWindow;
4468 HRESULT hr;
4470 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4472 EnterCriticalSection(&This->cs);
4474 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4476 if (hr == S_OK)
4477 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4479 LeaveCriticalSection(&This->cs);
4481 return hr;
4484 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface,
4485 LONG FullScreenMode) {
4486 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4487 IVideoWindow* pVideoWindow;
4488 HRESULT hr;
4490 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4492 EnterCriticalSection(&This->cs);
4494 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4496 if (hr == S_OK)
4497 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4499 LeaveCriticalSection(&This->cs);
4501 return hr;
4504 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface,
4505 LONG Focus) {
4506 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4507 IVideoWindow* pVideoWindow;
4508 HRESULT hr;
4510 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4512 EnterCriticalSection(&This->cs);
4514 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4516 if (hr == S_OK)
4517 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4519 LeaveCriticalSection(&This->cs);
4521 return hr;
4524 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface,
4525 OAHWND hwnd,
4526 LONG uMsg,
4527 LONG_PTR wParam,
4528 LONG_PTR lParam) {
4529 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4530 IVideoWindow* pVideoWindow;
4531 HRESULT hr;
4533 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4535 EnterCriticalSection(&This->cs);
4537 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4539 if (hr == S_OK)
4540 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4542 LeaveCriticalSection(&This->cs);
4544 return hr;
4547 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface,
4548 LONG Left,
4549 LONG Top,
4550 LONG Width,
4551 LONG Height) {
4552 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4553 IVideoWindow* pVideoWindow;
4554 HRESULT hr;
4556 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4558 EnterCriticalSection(&This->cs);
4560 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4562 if (hr == S_OK)
4563 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4565 LeaveCriticalSection(&This->cs);
4567 return hr;
4570 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface,
4571 LONG *pLeft,
4572 LONG *pTop,
4573 LONG *pWidth,
4574 LONG *pHeight) {
4575 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4576 IVideoWindow* pVideoWindow;
4577 HRESULT hr;
4579 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4581 EnterCriticalSection(&This->cs);
4583 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4585 if (hr == S_OK)
4586 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4588 LeaveCriticalSection(&This->cs);
4590 return hr;
4593 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface,
4594 LONG *pWidth,
4595 LONG *pHeight) {
4596 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4597 IVideoWindow* pVideoWindow;
4598 HRESULT hr;
4600 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4602 EnterCriticalSection(&This->cs);
4604 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4606 if (hr == S_OK)
4607 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4609 LeaveCriticalSection(&This->cs);
4611 return hr;
4614 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface,
4615 LONG *pWidth,
4616 LONG *pHeight) {
4617 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4618 IVideoWindow* pVideoWindow;
4619 HRESULT hr;
4621 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4623 EnterCriticalSection(&This->cs);
4625 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4627 if (hr == S_OK)
4628 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4630 LeaveCriticalSection(&This->cs);
4632 return hr;
4635 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface,
4636 LONG *pLeft,
4637 LONG *pTop,
4638 LONG *pWidth,
4639 LONG *pHeight) {
4640 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4641 IVideoWindow* pVideoWindow;
4642 HRESULT hr;
4644 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4646 EnterCriticalSection(&This->cs);
4648 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4650 if (hr == S_OK)
4651 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4653 LeaveCriticalSection(&This->cs);
4655 return hr;
4658 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface,
4659 LONG HideCursor) {
4660 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4661 IVideoWindow* pVideoWindow;
4662 HRESULT hr;
4664 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4666 EnterCriticalSection(&This->cs);
4668 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4670 if (hr == S_OK)
4671 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4673 LeaveCriticalSection(&This->cs);
4675 return hr;
4678 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface,
4679 LONG *CursorHidden) {
4680 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4681 IVideoWindow* pVideoWindow;
4682 HRESULT hr;
4684 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4686 EnterCriticalSection(&This->cs);
4688 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4690 if (hr == S_OK)
4691 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4693 LeaveCriticalSection(&This->cs);
4695 return hr;
4699 static const IVideoWindowVtbl IVideoWindow_VTable =
4701 VideoWindow_QueryInterface,
4702 VideoWindow_AddRef,
4703 VideoWindow_Release,
4704 VideoWindow_GetTypeInfoCount,
4705 VideoWindow_GetTypeInfo,
4706 VideoWindow_GetIDsOfNames,
4707 VideoWindow_Invoke,
4708 VideoWindow_put_Caption,
4709 VideoWindow_get_Caption,
4710 VideoWindow_put_WindowStyle,
4711 VideoWindow_get_WindowStyle,
4712 VideoWindow_put_WindowStyleEx,
4713 VideoWindow_get_WindowStyleEx,
4714 VideoWindow_put_AutoShow,
4715 VideoWindow_get_AutoShow,
4716 VideoWindow_put_WindowState,
4717 VideoWindow_get_WindowState,
4718 VideoWindow_put_BackgroundPalette,
4719 VideoWindow_get_BackgroundPalette,
4720 VideoWindow_put_Visible,
4721 VideoWindow_get_Visible,
4722 VideoWindow_put_Left,
4723 VideoWindow_get_Left,
4724 VideoWindow_put_Width,
4725 VideoWindow_get_Width,
4726 VideoWindow_put_Top,
4727 VideoWindow_get_Top,
4728 VideoWindow_put_Height,
4729 VideoWindow_get_Height,
4730 VideoWindow_put_Owner,
4731 VideoWindow_get_Owner,
4732 VideoWindow_put_MessageDrain,
4733 VideoWindow_get_MessageDrain,
4734 VideoWindow_get_BorderColor,
4735 VideoWindow_put_BorderColor,
4736 VideoWindow_get_FullScreenMode,
4737 VideoWindow_put_FullScreenMode,
4738 VideoWindow_SetWindowForeground,
4739 VideoWindow_NotifyOwnerMessage,
4740 VideoWindow_SetWindowPosition,
4741 VideoWindow_GetWindowPosition,
4742 VideoWindow_GetMinIdealImageSize,
4743 VideoWindow_GetMaxIdealImageSize,
4744 VideoWindow_GetRestorePosition,
4745 VideoWindow_HideCursor,
4746 VideoWindow_IsCursorHidden
4750 /*** IUnknown methods ***/
4751 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface,
4752 REFIID riid,
4753 LPVOID*ppvObj) {
4754 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4756 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
4758 return Filtergraph_QueryInterface(This, riid, ppvObj);
4761 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface) {
4762 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4764 TRACE("(%p/%p)->()\n", This, iface);
4766 return Filtergraph_AddRef(This);
4769 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface) {
4770 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4772 TRACE("(%p/%p)->()\n", This, iface);
4774 return Filtergraph_Release(This);
4777 /*** IDispatch methods ***/
4778 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface,
4779 UINT*pctinfo) {
4780 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4782 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
4784 return S_OK;
4787 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface,
4788 UINT iTInfo,
4789 LCID lcid,
4790 ITypeInfo**ppTInfo) {
4791 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4793 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
4795 return S_OK;
4798 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface,
4799 REFIID riid,
4800 LPOLESTR*rgszNames,
4801 UINT cNames,
4802 LCID lcid,
4803 DISPID*rgDispId) {
4804 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4806 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
4808 return S_OK;
4811 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface,
4812 DISPID dispIdMember,
4813 REFIID riid,
4814 LCID lcid,
4815 WORD wFlags,
4816 DISPPARAMS*pDispParams,
4817 VARIANT*pVarResult,
4818 EXCEPINFO*pExepInfo,
4819 UINT*puArgErr) {
4820 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4822 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4824 return S_OK;
4827 /*** IMediaEvent methods ***/
4828 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface,
4829 OAEVENT *hEvent) {
4830 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4832 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
4834 *hEvent = (OAEVENT)This->evqueue.msg_event;
4836 return S_OK;
4839 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface,
4840 LONG *lEventCode,
4841 LONG_PTR *lParam1,
4842 LONG_PTR *lParam2,
4843 LONG msTimeout) {
4844 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4845 Event evt;
4847 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
4849 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
4851 *lEventCode = evt.lEventCode;
4852 *lParam1 = evt.lParam1;
4853 *lParam2 = evt.lParam2;
4854 return S_OK;
4857 *lEventCode = 0;
4858 return E_ABORT;
4861 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface,
4862 LONG msTimeout,
4863 LONG *pEvCode) {
4864 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4866 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
4868 if (This->state != State_Running)
4869 return VFW_E_WRONG_STATE;
4871 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
4873 *pEvCode = This->CompletionStatus;
4874 return S_OK;
4877 *pEvCode = 0;
4878 return E_ABORT;
4881 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface,
4882 LONG lEvCode) {
4883 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4885 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4887 if (lEvCode == EC_COMPLETE)
4888 This->HandleEcComplete = FALSE;
4889 else if (lEvCode == EC_REPAINT)
4890 This->HandleEcRepaint = FALSE;
4891 else if (lEvCode == EC_CLOCK_CHANGED)
4892 This->HandleEcClockChanged = FALSE;
4893 else
4894 return S_FALSE;
4896 return S_OK;
4899 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface,
4900 LONG lEvCode) {
4901 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4903 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4905 if (lEvCode == EC_COMPLETE)
4906 This->HandleEcComplete = TRUE;
4907 else if (lEvCode == EC_REPAINT)
4908 This->HandleEcRepaint = TRUE;
4909 else if (lEvCode == EC_CLOCK_CHANGED)
4910 This->HandleEcClockChanged = TRUE;
4911 else
4912 return S_FALSE;
4914 return S_OK;
4917 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface,
4918 LONG lEvCode,
4919 LONG_PTR lParam1,
4920 LONG_PTR lParam2) {
4921 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4923 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
4925 return S_OK;
4928 /*** IMediaEventEx methods ***/
4929 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface,
4930 OAHWND hwnd,
4931 LONG lMsg,
4932 LONG_PTR lInstanceData) {
4933 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4935 TRACE("(%p/%p)->(%08lx, %d, %08lx)\n", This, iface, hwnd, lMsg, lInstanceData);
4937 This->notif.hWnd = (HWND)hwnd;
4938 This->notif.msg = lMsg;
4939 This->notif.instance = lInstanceData;
4941 return S_OK;
4944 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface,
4945 LONG lNoNotifyFlags) {
4946 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4948 TRACE("(%p/%p)->(%d)\n", This, iface, lNoNotifyFlags);
4950 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
4951 return E_INVALIDARG;
4953 This->notif.disabled = lNoNotifyFlags;
4955 return S_OK;
4958 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface,
4959 LONG *lplNoNotifyFlags) {
4960 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4962 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
4964 if (!lplNoNotifyFlags)
4965 return E_POINTER;
4967 *lplNoNotifyFlags = This->notif.disabled;
4969 return S_OK;
4973 static const IMediaEventExVtbl IMediaEventEx_VTable =
4975 MediaEvent_QueryInterface,
4976 MediaEvent_AddRef,
4977 MediaEvent_Release,
4978 MediaEvent_GetTypeInfoCount,
4979 MediaEvent_GetTypeInfo,
4980 MediaEvent_GetIDsOfNames,
4981 MediaEvent_Invoke,
4982 MediaEvent_GetEventHandle,
4983 MediaEvent_GetEvent,
4984 MediaEvent_WaitForCompletion,
4985 MediaEvent_CancelDefaultHandling,
4986 MediaEvent_RestoreDefaultHandling,
4987 MediaEvent_FreeEventParams,
4988 MediaEvent_SetNotifyWindow,
4989 MediaEvent_SetNotifyFlags,
4990 MediaEvent_GetNotifyFlags
4994 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, LPVOID *ppv)
4996 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
4998 return Filtergraph_QueryInterface(This, riid, ppv);
5001 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
5003 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5005 return Filtergraph_AddRef(This);
5008 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
5010 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5012 return Filtergraph_Release(This);
5015 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
5017 FIXME("(%p): stub\n", pClassID);
5019 return E_NOTIMPL;
5022 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
5024 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5025 return MediaControl_Stop((IMediaControl*)&This->IMediaControl_vtbl);
5028 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5030 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5031 return MediaControl_Pause((IMediaControl*)&This->IMediaControl_vtbl);
5034 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
5036 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5037 if (tStart)
5038 FIXME("Run called with non-null tStart: %x%08x\n",
5039 (int)(tStart>>32), (int)tStart);
5040 return MediaControl_Run((IMediaControl*)&This->IMediaControl_vtbl);
5043 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout, FILTER_STATE * pState)
5045 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5046 return MediaControl_GetState((IMediaControl*)&This->IMediaControl_vtbl, dwMsTimeout, (OAFilterState*)pState);
5049 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5051 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5052 HRESULT hr = S_OK;
5053 int i;
5055 TRACE("(%p/%p)->(%p)\n", iface, This, pClock);
5057 EnterCriticalSection(&This->cs);
5059 for (i = 0;i < This->nFilters;i++)
5061 hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5062 if (FAILED(hr))
5063 break;
5066 if (FAILED(hr))
5068 for(;i >= 0;i--)
5069 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5071 else
5073 if (This->refClock)
5074 IReferenceClock_Release(This->refClock);
5075 This->refClock = pClock;
5076 if (This->refClock)
5077 IReferenceClock_AddRef(This->refClock);
5079 if (This->HandleEcClockChanged)
5081 IMediaEventSink *pEventSink;
5082 HRESULT eshr;
5084 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (LPVOID)&pEventSink);
5085 if (SUCCEEDED(eshr))
5087 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5088 IMediaEventSink_Release(pEventSink);
5093 LeaveCriticalSection(&This->cs);
5095 return hr;
5098 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5100 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5102 TRACE("(%p/%p)->(%p)\n", iface, This, ppClock);
5104 if (!ppClock)
5105 return E_POINTER;
5107 EnterCriticalSection(&This->cs);
5109 *ppClock = This->refClock;
5110 if (*ppClock)
5111 IReferenceClock_AddRef(*ppClock);
5113 LeaveCriticalSection(&This->cs);
5115 return S_OK;
5118 static const IMediaFilterVtbl IMediaFilter_VTable =
5120 MediaFilter_QueryInterface,
5121 MediaFilter_AddRef,
5122 MediaFilter_Release,
5123 MediaFilter_GetClassID,
5124 MediaFilter_Stop,
5125 MediaFilter_Pause,
5126 MediaFilter_Run,
5127 MediaFilter_GetState,
5128 MediaFilter_SetSyncSource,
5129 MediaFilter_GetSyncSource
5132 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, LPVOID *ppv)
5134 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5136 return Filtergraph_QueryInterface(This, riid, ppv);
5139 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5141 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5143 return Filtergraph_AddRef(This);
5146 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5148 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5150 return Filtergraph_Release(This);
5153 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG EventCode, LONG_PTR EventParam1, LONG_PTR EventParam2)
5155 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5156 Event evt;
5158 TRACE("(%p/%p)->(%d, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5160 /* We need thread safety here, let's use the events queue's one */
5161 EnterCriticalSection(&This->evqueue.msg_crst);
5163 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5165 TRACE("Process EC_COMPLETE notification\n");
5166 if (++This->EcCompleteCount == This->nRenderers)
5168 evt.lEventCode = EC_COMPLETE;
5169 evt.lParam1 = S_OK;
5170 evt.lParam2 = 0;
5171 TRACE("Send EC_COMPLETE to app\n");
5172 EventsQueue_PutEvent(&This->evqueue, &evt);
5173 if (!This->notif.disabled && This->notif.hWnd)
5175 TRACE("Send Window message\n");
5176 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5178 This->CompletionStatus = EC_COMPLETE;
5179 SetEvent(This->hEventCompletion);
5182 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5184 /* FIXME: Not handled yet */
5186 else
5188 evt.lEventCode = EventCode;
5189 evt.lParam1 = EventParam1;
5190 evt.lParam2 = EventParam2;
5191 EventsQueue_PutEvent(&This->evqueue, &evt);
5192 if (!This->notif.disabled && This->notif.hWnd)
5193 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5196 LeaveCriticalSection(&This->evqueue.msg_crst);
5197 return S_OK;
5200 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5202 MediaEventSink_QueryInterface,
5203 MediaEventSink_AddRef,
5204 MediaEventSink_Release,
5205 MediaEventSink_Notify
5208 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, LPVOID *ppv)
5210 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5212 return Filtergraph_QueryInterface(This, riid, ppv);
5215 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5217 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5219 return Filtergraph_AddRef(This);
5222 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5224 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5226 return Filtergraph_Release(This);
5229 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface,
5230 IPin* pOutputPin,
5231 IPin* pInputPin,
5232 const AM_MEDIA_TYPE* pmtFirstConnection,
5233 IBaseFilter* pUsingFilter,
5234 HANDLE hAbortEvent,
5235 DWORD dwFlags)
5237 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5239 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5241 return E_NOTIMPL;
5244 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface,
5245 IGraphConfigCallback* pCallback,
5246 PVOID pvContext,
5247 DWORD dwFlags,
5248 HANDLE hAbortEvent)
5250 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5251 HRESULT hr;
5253 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5255 if (hAbortEvent)
5256 FIXME("The parameter hAbortEvent is not handled!\n");
5258 EnterCriticalSection(&This->cs);
5260 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5262 LeaveCriticalSection(&This->cs);
5264 return hr;
5267 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface,
5268 IBaseFilter* pFilter)
5270 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5272 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5274 return E_NOTIMPL;
5277 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface,
5278 IEnumFilters** pEnum)
5280 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5282 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5284 return E_NOTIMPL;
5287 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface,
5288 IBaseFilter* pFilter)
5290 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5292 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5294 return E_NOTIMPL;
5297 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface,
5298 REFERENCE_TIME* prtStart)
5300 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5302 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5304 return E_NOTIMPL;
5307 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface,
5308 IPin* pOutputPin,
5309 IPinConnection* pConnection,
5310 HANDLE hEventAbort)
5312 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5314 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5316 return E_NOTIMPL;
5319 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface,
5320 IBaseFilter* pFilter,
5321 DWORD dwFlags)
5323 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5325 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5327 return E_NOTIMPL;
5330 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface,
5331 IBaseFilter* pFilter,
5332 DWORD* dwFlags)
5334 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5336 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5338 return E_NOTIMPL;
5341 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface,
5342 IBaseFilter* pFilter,
5343 DWORD dwFlags)
5345 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5347 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5349 return E_NOTIMPL;
5352 static const IGraphConfigVtbl IGraphConfig_VTable =
5354 GraphConfig_QueryInterface,
5355 GraphConfig_AddRef,
5356 GraphConfig_Release,
5357 GraphConfig_Reconnect,
5358 GraphConfig_Reconfigure,
5359 GraphConfig_AddFilterToCache,
5360 GraphConfig_EnumCacheFilter,
5361 GraphConfig_RemoveFilterFromCache,
5362 GraphConfig_GetStartTime,
5363 GraphConfig_PushThroughData,
5364 GraphConfig_SetFilterFlags,
5365 GraphConfig_GetFilterFlags,
5366 GraphConfig_RemoveFilterEx
5369 static const IUnknownVtbl IInner_VTable =
5371 FilterGraphInner_QueryInterface,
5372 FilterGraphInner_AddRef,
5373 FilterGraphInner_Release
5376 static HRESULT Filtergraph_QueryInterface(IFilterGraphImpl *This,
5377 REFIID riid,
5378 LPVOID * ppv) {
5379 if (This->bAggregatable)
5380 This->bUnkOuterValid = TRUE;
5382 if (This->pUnkOuter)
5384 if (This->bAggregatable)
5385 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
5387 if (IsEqualIID(riid, &IID_IUnknown))
5389 HRESULT hr;
5391 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5392 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5393 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5394 This->bAggregatable = TRUE;
5395 return hr;
5398 *ppv = NULL;
5399 return E_NOINTERFACE;
5402 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5405 static ULONG Filtergraph_AddRef(IFilterGraphImpl *This) {
5406 if (This->pUnkOuter && This->bUnkOuterValid)
5407 return IUnknown_AddRef(This->pUnkOuter);
5408 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5411 static ULONG Filtergraph_Release(IFilterGraphImpl *This) {
5412 if (This->pUnkOuter && This->bUnkOuterValid)
5413 return IUnknown_Release(This->pUnkOuter);
5414 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5417 /* This is the only function that actually creates a FilterGraph class... */
5418 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5420 IFilterGraphImpl *fimpl;
5421 HRESULT hr;
5423 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5425 *ppObj = NULL;
5427 fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5428 fimpl->pUnkOuter = pUnkOuter;
5429 fimpl->bUnkOuterValid = FALSE;
5430 fimpl->bAggregatable = FALSE;
5431 fimpl->IInner_vtbl = &IInner_VTable;
5432 fimpl->IFilterGraph2_vtbl = &IFilterGraph2_VTable;
5433 fimpl->IMediaControl_vtbl = &IMediaControl_VTable;
5434 fimpl->IMediaSeeking_vtbl = &IMediaSeeking_VTable;
5435 fimpl->IBasicAudio_vtbl = &IBasicAudio_VTable;
5436 fimpl->IBasicVideo_vtbl = &IBasicVideo_VTable;
5437 fimpl->IVideoWindow_vtbl = &IVideoWindow_VTable;
5438 fimpl->IMediaEventEx_vtbl = &IMediaEventEx_VTable;
5439 fimpl->IMediaFilter_vtbl = &IMediaFilter_VTable;
5440 fimpl->IMediaEventSink_vtbl = &IMediaEventSink_VTable;
5441 fimpl->IGraphConfig_vtbl = &IGraphConfig_VTable;
5442 fimpl->IMediaPosition_vtbl = &IMediaPosition_VTable;
5443 fimpl->ref = 1;
5444 fimpl->ppFiltersInGraph = NULL;
5445 fimpl->pFilterNames = NULL;
5446 fimpl->nFilters = 0;
5447 fimpl->filterCapacity = 0;
5448 fimpl->nameIndex = 1;
5449 fimpl->refClock = NULL;
5450 fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5451 fimpl->HandleEcComplete = TRUE;
5452 fimpl->HandleEcRepaint = TRUE;
5453 fimpl->HandleEcClockChanged = TRUE;
5454 fimpl->notif.hWnd = 0;
5455 fimpl->notif.disabled = FALSE;
5456 fimpl->nRenderers = 0;
5457 fimpl->EcCompleteCount = 0;
5458 fimpl->state = State_Stopped;
5459 EventsQueue_Init(&fimpl->evqueue);
5460 InitializeCriticalSection(&fimpl->cs);
5461 fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5462 fimpl->nItfCacheEntries = 0;
5463 memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5464 fimpl->start_time = fimpl->pause_time = 0;
5465 fimpl->stop_position = -1;
5466 fimpl->punkFilterMapper2 = NULL;
5467 fimpl->recursioncount = 0;
5469 /* create Filtermapper aggregated. */
5470 hr = CoCreateInstance(&CLSID_FilterMapper2, pUnkOuter ? pUnkOuter : (IUnknown*)&fimpl->IInner_vtbl, CLSCTX_INPROC_SERVER,
5471 &IID_IUnknown, (LPVOID*)&fimpl->punkFilterMapper2);
5473 if (SUCCEEDED(hr)) {
5474 hr = IUnknown_QueryInterface(fimpl->punkFilterMapper2, &IID_IFilterMapper2, (LPVOID*)&fimpl->pFilterMapper2);
5477 if (SUCCEEDED(hr)) {
5478 /* Release controlling IUnknown - compensate refcount increase from caching IFilterMapper2 interface. */
5479 if (pUnkOuter) IUnknown_Release(pUnkOuter);
5480 else IUnknown_Release((IUnknown*)&fimpl->IInner_vtbl);
5483 if (FAILED(hr)) {
5484 ERR("Unable to create filter mapper (%x)\n", hr);
5485 if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5486 CloseHandle(fimpl->hEventCompletion);
5487 EventsQueue_Destroy(&fimpl->evqueue);
5488 fimpl->cs.DebugInfo->Spare[0] = 0;
5489 DeleteCriticalSection(&fimpl->cs);
5490 CoTaskMemFree(fimpl);
5491 return hr;
5493 IFilterGraph2_SetDefaultSyncSource((IFilterGraph2*)fimpl);
5495 *ppObj = fimpl;
5496 return S_OK;
5499 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5501 FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5502 return FilterGraph_create(pUnkOuter, ppObj);