wined3d: Pass a wined3d_state structure to use_vs().
[wine/multimedia.git] / dlls / quartz / filtergraph.c
blob18bf97c392bd1a3d8aef2e724b0ec1ba4d496e7d
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 = HeapReAlloc(GetProcessHeap(),0,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 LONGLONG start_time;
205 LONGLONG position;
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 LONGLONG time = 0;
1833 IReferenceClock *clock = NULL;
1835 IBaseFilter_GetSyncSource(pFilter, &clock);
1836 if (clock)
1838 IReferenceClock_GetTime(clock, &time);
1839 if (time)
1840 /* Add 50 ms */
1841 time += 500000;
1842 if (time < 0)
1843 time = 0;
1844 IReferenceClock_Release(clock);
1847 return IBaseFilter_Run(pFilter, time);
1850 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1852 return IBaseFilter_Pause(pFilter);
1855 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1857 return IBaseFilter_Stop(pFilter);
1860 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1862 FILTER_STATE state;
1863 DWORD time_end = data;
1864 DWORD time_now = GetTickCount();
1865 LONG wait;
1867 if (time_end == INFINITE)
1869 wait = INFINITE;
1871 else if (time_end > time_now)
1873 wait = time_end - time_now;
1875 else
1876 wait = 0;
1878 return IBaseFilter_GetState(pFilter, wait, &state);
1882 static HRESULT SendFilterMessage(IMediaControl *iface, fnFoundFilter FoundFilter, DWORD_PTR data)
1884 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1885 int i;
1886 IBaseFilter* pfilter;
1887 IEnumPins* pEnum;
1888 HRESULT hr;
1889 IPin* pPin;
1890 DWORD dummy;
1891 PIN_DIRECTION dir;
1892 TRACE("(%p/%p)->()\n", This, iface);
1894 /* Explorer the graph from source filters to renderers, determine renderers
1895 * number and run filters from renderers to source filters */
1896 This->nRenderers = 0;
1897 ResetEvent(This->hEventCompletion);
1899 for(i = 0; i < This->nFilters; i++)
1901 BOOL source = TRUE;
1902 pfilter = This->ppFiltersInGraph[i];
1903 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
1904 if (hr != S_OK)
1906 WARN("Enum pins failed %x\n", hr);
1907 continue;
1909 /* Check if it is a source filter */
1910 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1912 IPin_QueryDirection(pPin, &dir);
1913 IPin_Release(pPin);
1914 if (dir == PINDIR_INPUT)
1916 source = FALSE;
1917 break;
1920 if (source)
1922 TRACE("Found a source filter %p\n", pfilter);
1923 IEnumPins_Reset(pEnum);
1924 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1926 /* Explore the graph downstream from this pin */
1927 ExploreGraph(This, pPin, FoundFilter, data);
1928 IPin_Release(pPin);
1930 FoundFilter(pfilter, data);
1932 IEnumPins_Release(pEnum);
1935 return S_FALSE;
1938 /*** IMediaControl methods ***/
1939 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface) {
1940 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1941 TRACE("(%p/%p)->()\n", This, iface);
1943 if (This->state == State_Running) return S_OK;
1945 EnterCriticalSection(&This->cs);
1946 if (This->state == State_Stopped)
1947 This->EcCompleteCount = 0;
1949 if (This->refClock)
1951 IReferenceClock_GetTime(This->refClock, &This->start_time);
1952 This->start_time += 500000;
1954 else This->position = This->start_time = 0;
1956 SendFilterMessage(iface, SendRun, 0);
1957 This->state = State_Running;
1958 LeaveCriticalSection(&This->cs);
1959 return S_FALSE;
1962 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface) {
1963 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1964 TRACE("(%p/%p)->()\n", This, iface);
1966 if (This->state == State_Paused) return S_OK;
1968 EnterCriticalSection(&This->cs);
1969 if (This->state == State_Stopped)
1970 This->EcCompleteCount = 0;
1972 if (This->state == State_Running && This->refClock)
1974 LONGLONG time = This->start_time;
1975 IReferenceClock_GetTime(This->refClock, &time);
1976 This->position += time - This->start_time;
1979 SendFilterMessage(iface, SendPause, 0);
1980 This->state = State_Paused;
1981 LeaveCriticalSection(&This->cs);
1982 return S_FALSE;
1985 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface) {
1986 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1987 TRACE("(%p/%p)->()\n", This, iface);
1989 if (This->state == State_Stopped) return S_OK;
1991 EnterCriticalSection(&This->cs);
1992 if (This->state == State_Running && This->refClock)
1994 LONGLONG time = This->start_time;
1995 IReferenceClock_GetTime(This->refClock, &time);
1996 This->position += time - This->start_time;
1999 if (This->state == State_Running) SendFilterMessage(iface, SendPause, 0);
2000 SendFilterMessage(iface, SendStop, 0);
2001 This->state = State_Stopped;
2002 LeaveCriticalSection(&This->cs);
2003 return S_OK;
2006 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface,
2007 LONG msTimeout,
2008 OAFilterState *pfs) {
2009 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2010 DWORD end;
2012 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
2014 if (!pfs)
2015 return E_POINTER;
2017 EnterCriticalSection(&This->cs);
2019 *pfs = This->state;
2020 if (msTimeout > 0)
2022 end = GetTickCount() + msTimeout;
2024 else if (msTimeout < 0)
2026 end = INFINITE;
2028 else
2030 end = 0;
2032 if (end)
2033 SendFilterMessage(iface, SendGetState, end);
2035 LeaveCriticalSection(&This->cs);
2037 return S_OK;
2040 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface,
2041 BSTR strFilename) {
2042 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2044 FIXME("(%p/%p)->(%s (%p)): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename);
2046 return S_OK;
2049 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface,
2050 BSTR strFilename,
2051 IDispatch **ppUnk) {
2052 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2054 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2056 return S_OK;
2059 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface,
2060 IDispatch **ppUnk) {
2061 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2063 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2065 return S_OK;
2068 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface,
2069 IDispatch **ppUnk) {
2070 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2072 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2074 return S_OK;
2077 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface) {
2078 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2080 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2082 return S_OK;
2086 static const IMediaControlVtbl IMediaControl_VTable =
2088 MediaControl_QueryInterface,
2089 MediaControl_AddRef,
2090 MediaControl_Release,
2091 MediaControl_GetTypeInfoCount,
2092 MediaControl_GetTypeInfo,
2093 MediaControl_GetIDsOfNames,
2094 MediaControl_Invoke,
2095 MediaControl_Run,
2096 MediaControl_Pause,
2097 MediaControl_Stop,
2098 MediaControl_GetState,
2099 MediaControl_RenderFile,
2100 MediaControl_AddSourceFilter,
2101 MediaControl_get_FilterCollection,
2102 MediaControl_get_RegFilterCollection,
2103 MediaControl_StopWhenReady
2107 /*** IUnknown methods ***/
2108 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface,
2109 REFIID riid,
2110 LPVOID*ppvObj) {
2111 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2113 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2115 return Filtergraph_QueryInterface(This, riid, ppvObj);
2118 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface) {
2119 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2121 TRACE("(%p/%p)->()\n", This, iface);
2123 return Filtergraph_AddRef(This);
2126 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface) {
2127 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2129 TRACE("(%p/%p)->()\n", This, iface);
2131 return Filtergraph_Release(This);
2134 typedef HRESULT (WINAPI *fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
2136 static HRESULT all_renderers_seek(IFilterGraphImpl *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2137 BOOL allnotimpl = TRUE;
2138 int i;
2139 IBaseFilter* pfilter;
2140 IEnumPins* pEnum;
2141 HRESULT hr, hr_return = S_OK;
2142 IPin* pPin;
2143 DWORD dummy;
2144 PIN_DIRECTION dir;
2146 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2147 /* Send a message to all renderers, they are responsible for broadcasting it further */
2149 for(i = 0; i < This->nFilters; i++)
2151 BOOL renderer = TRUE;
2152 pfilter = This->ppFiltersInGraph[i];
2153 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
2154 if (hr != S_OK)
2156 WARN("Enum pins failed %x\n", hr);
2157 continue;
2159 /* Check if it is a source filter */
2160 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2162 IPin_QueryDirection(pPin, &dir);
2163 IPin_Release(pPin);
2164 if (dir != PINDIR_INPUT)
2166 renderer = FALSE;
2167 break;
2170 IEnumPins_Release(pEnum);
2171 if (renderer)
2173 IMediaSeeking *seek = NULL;
2174 IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2175 if (!seek)
2176 continue;
2178 hr = FoundSeek(This, seek, arg);
2180 IMediaSeeking_Release(seek);
2181 if (hr_return != E_NOTIMPL)
2182 allnotimpl = FALSE;
2183 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2184 hr_return = hr;
2188 if (allnotimpl)
2189 return E_NOTIMPL;
2190 return hr_return;
2193 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2195 HRESULT hr;
2196 DWORD caps = 0;
2198 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2199 if (FAILED(hr))
2200 return hr;
2202 /* Only add common capabilities everything supports */
2203 *(DWORD*)pcaps &= caps;
2205 return hr;
2208 /*** IMediaSeeking methods ***/
2209 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface,
2210 DWORD *pCapabilities) {
2211 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2212 HRESULT hr;
2213 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2215 if (!pCapabilities)
2216 return E_POINTER;
2218 EnterCriticalSection(&This->cs);
2219 *pCapabilities = 0xffffffff;
2221 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2222 LeaveCriticalSection(&This->cs);
2224 return hr;
2227 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface,
2228 DWORD *pCapabilities) {
2229 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2230 DWORD originalcaps;
2231 HRESULT hr;
2232 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2234 if (!pCapabilities)
2235 return E_POINTER;
2237 EnterCriticalSection(&This->cs);
2238 originalcaps = *pCapabilities;
2239 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2240 LeaveCriticalSection(&This->cs);
2242 if (FAILED(hr))
2243 return hr;
2245 if (!*pCapabilities)
2246 return E_FAIL;
2247 if (*pCapabilities != originalcaps)
2248 return S_FALSE;
2249 return S_OK;
2252 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface,
2253 const GUID *pFormat) {
2254 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2256 if (!pFormat)
2257 return E_POINTER;
2259 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2261 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2263 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2264 return S_FALSE;
2267 return S_OK;
2270 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface,
2271 GUID *pFormat) {
2272 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2274 if (!pFormat)
2275 return E_POINTER;
2277 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2278 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2280 return S_OK;
2283 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface,
2284 GUID *pFormat) {
2285 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2287 if (!pFormat)
2288 return E_POINTER;
2290 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2291 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2293 return S_OK;
2296 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface,
2297 const GUID *pFormat) {
2298 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2300 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2301 if (!pFormat)
2302 return E_POINTER;
2304 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2305 return S_FALSE;
2307 return S_OK;
2310 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface,
2311 const GUID *pFormat) {
2312 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2314 if (!pFormat)
2315 return E_POINTER;
2317 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2319 if (This->state != State_Stopped)
2320 return VFW_E_WRONG_STATE;
2322 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2324 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2325 return E_INVALIDARG;
2328 return S_OK;
2331 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2333 HRESULT hr;
2334 LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2336 hr = IMediaSeeking_GetDuration(seek, &duration);
2337 if (FAILED(hr))
2338 return hr;
2340 /* FIXME: Minimum or maximum duration? Assuming minimum */
2341 if (duration > 0 && *pdur < duration)
2342 *pdur = duration;
2344 return hr;
2347 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface,
2348 LONGLONG *pDuration) {
2349 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2350 HRESULT hr;
2352 TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2354 if (!pDuration)
2355 return E_POINTER;
2357 EnterCriticalSection(&This->cs);
2358 *pDuration = -1;
2359 hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2360 LeaveCriticalSection(&This->cs);
2362 TRACE("--->%08x\n", hr);
2363 return hr;
2366 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface,
2367 LONGLONG *pStop) {
2368 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2369 HRESULT hr = S_OK;
2371 TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2373 if (!pStop)
2374 return E_POINTER;
2376 EnterCriticalSection(&This->cs);
2377 if (This->stop_position < 0)
2378 /* Stop position not set, use duration instead */
2379 hr = IMediaSeeking_GetDuration(iface, pStop);
2380 else
2381 *pStop = This->stop_position;
2383 LeaveCriticalSection(&This->cs);
2385 return hr;
2388 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface,
2389 LONGLONG *pCurrent) {
2390 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2391 LONGLONG time = 0;
2393 if (!pCurrent)
2394 return E_POINTER;
2396 EnterCriticalSection(&This->cs);
2397 if (This->state == State_Running && This->refClock)
2399 IReferenceClock_GetTime(This->refClock, &time);
2400 if (time)
2401 time += This->position - This->start_time;
2402 if (time < This->position)
2403 time = This->position;
2404 *pCurrent = time;
2406 else
2407 *pCurrent = This->position;
2408 LeaveCriticalSection(&This->cs);
2410 TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2412 return S_OK;
2415 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface,
2416 LONGLONG *pTarget,
2417 const GUID *pTargetFormat,
2418 LONGLONG Source,
2419 const GUID *pSourceFormat) {
2420 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2422 FIXME("(%p/%p)->(%p, %p, 0x%s, %p): stub !!!\n", This, iface, pTarget,
2423 pTargetFormat, wine_dbgstr_longlong(Source), pSourceFormat);
2425 return S_OK;
2428 struct pos_args {
2429 LONGLONG* current, *stop;
2430 DWORD curflags, stopflags;
2433 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2435 struct pos_args *args = (void*)pargs;
2437 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
2440 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface,
2441 LONGLONG *pCurrent,
2442 DWORD dwCurrentFlags,
2443 LONGLONG *pStop,
2444 DWORD dwStopFlags) {
2445 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2446 HRESULT hr = S_OK;
2447 FILTER_STATE state;
2448 struct pos_args args;
2450 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
2452 EnterCriticalSection(&This->cs);
2453 state = This->state;
2454 TRACE("State: %s\n", state == State_Running ? "Running" : (state == State_Paused ? "Paused" : (state == State_Stopped ? "Stopped" : "UNKNOWN")));
2456 if ((dwCurrentFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2458 This->position = *pCurrent;
2460 else if ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2461 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
2463 if ((dwStopFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2464 This->stop_position = *pStop;
2465 else if ((dwStopFlags & 0x7) != AM_SEEKING_NoPositioning)
2466 FIXME("Stop position not handled yet!\n");
2468 args.current = pCurrent;
2469 args.stop = pStop;
2470 args.curflags = dwCurrentFlags;
2471 args.stopflags = dwStopFlags;
2472 hr = all_renderers_seek(This, found_setposition, (DWORD_PTR)&args);
2474 if (This->refClock && ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning))
2476 /* Update start time, prevents weird jumps */
2477 IReferenceClock_GetTime(This->refClock, &This->start_time);
2479 LeaveCriticalSection(&This->cs);
2481 return hr;
2484 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface,
2485 LONGLONG *pCurrent,
2486 LONGLONG *pStop) {
2487 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2488 HRESULT hr;
2490 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pCurrent, pStop);
2491 hr = IMediaSeeking_GetCurrentPosition(iface, pCurrent);
2492 if (SUCCEEDED(hr))
2493 hr = IMediaSeeking_GetStopPosition(iface, pStop);
2495 return hr;
2498 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface,
2499 LONGLONG *pEarliest,
2500 LONGLONG *pLatest) {
2501 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2503 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2505 return S_OK;
2508 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface,
2509 double dRate) {
2510 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2512 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2514 return S_OK;
2517 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface,
2518 double *pdRate) {
2519 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2521 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2523 return S_OK;
2526 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface,
2527 LONGLONG *pllPreroll) {
2528 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2530 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2532 return S_OK;
2536 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2538 MediaSeeking_QueryInterface,
2539 MediaSeeking_AddRef,
2540 MediaSeeking_Release,
2541 MediaSeeking_GetCapabilities,
2542 MediaSeeking_CheckCapabilities,
2543 MediaSeeking_IsFormatSupported,
2544 MediaSeeking_QueryPreferredFormat,
2545 MediaSeeking_GetTimeFormat,
2546 MediaSeeking_IsUsingTimeFormat,
2547 MediaSeeking_SetTimeFormat,
2548 MediaSeeking_GetDuration,
2549 MediaSeeking_GetStopPosition,
2550 MediaSeeking_GetCurrentPosition,
2551 MediaSeeking_ConvertTimeFormat,
2552 MediaSeeking_SetPositions,
2553 MediaSeeking_GetPositions,
2554 MediaSeeking_GetAvailable,
2555 MediaSeeking_SetRate,
2556 MediaSeeking_GetRate,
2557 MediaSeeking_GetPreroll
2560 static inline IFilterGraphImpl *impl_from_IMediaPosition( IMediaPosition *iface )
2562 return (IFilterGraphImpl *)((char*)iface - FIELD_OFFSET(IFilterGraphImpl, IMediaPosition_vtbl));
2565 /*** IUnknown methods ***/
2566 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj)
2568 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2570 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2571 return Filtergraph_QueryInterface(This, riid, ppvObj);
2574 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2576 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2578 TRACE("(%p/%p)->()\n", This, iface);
2579 return Filtergraph_AddRef(This);
2582 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2584 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2586 TRACE("(%p/%p)->()\n", This, iface);
2587 return Filtergraph_Release(This);
2590 /*** IDispatch methods ***/
2591 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo){
2592 FIXME("(%p) stub!\n", iface);
2593 return E_NOTIMPL;
2596 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo){
2597 FIXME("(%p) stub!\n", iface);
2598 return E_NOTIMPL;
2601 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId){
2602 FIXME("(%p) stub!\n", iface);
2603 return E_NOTIMPL;
2606 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr){
2607 FIXME("(%p) stub!\n", iface);
2608 return E_NOTIMPL;
2611 /*** IMediaPosition methods ***/
2612 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2614 LONGLONG duration;
2615 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2616 HRESULT hr = IMediaSeeking_GetDuration( (IMediaSeeking *)&This->IMediaSeeking_vtbl, &duration );
2617 if (SUCCEEDED(hr)) *plength = duration;
2618 return hr;
2621 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2623 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2624 LONGLONG reftime = llTime;
2626 return IMediaSeeking_SetPositions((IMediaSeeking *)&This->IMediaSeeking_vtbl,
2627 &reftime, AM_SEEKING_AbsolutePositioning,
2628 NULL, AM_SEEKING_NoPositioning);
2631 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2633 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2634 LONGLONG pos;
2635 HRESULT hr = IMediaSeeking_GetCurrentPosition( (IMediaSeeking *)&This->IMediaSeeking_vtbl, &pos );
2636 if (SUCCEEDED(hr)) *pllTime = pos;
2637 return hr;
2640 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2642 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2643 LONGLONG pos;
2644 HRESULT hr = IMediaSeeking_GetStopPosition( (IMediaSeeking *)&This->IMediaSeeking_vtbl, &pos );
2645 if (SUCCEEDED(hr)) *pllTime = pos;
2646 return hr;
2649 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2651 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2652 LONGLONG reftime = llTime;
2654 return IMediaSeeking_SetPositions((IMediaSeeking *)&This->IMediaSeeking_vtbl,
2655 NULL, AM_SEEKING_NoPositioning,
2656 &reftime, AM_SEEKING_AbsolutePositioning);
2659 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime){
2660 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2661 return E_NOTIMPL;
2664 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime){
2665 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2666 return E_NOTIMPL;
2669 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2671 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2672 return IMediaSeeking_SetRate((IMediaSeeking *)&This->IMediaSeeking_vtbl, dRate);
2675 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2677 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2678 return IMediaSeeking_GetRate((IMediaSeeking *)&This->IMediaSeeking_vtbl, pdRate);
2681 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward){
2682 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2683 return E_NOTIMPL;
2686 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward){
2687 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2688 return E_NOTIMPL;
2692 static const IMediaPositionVtbl IMediaPosition_VTable =
2694 MediaPosition_QueryInterface,
2695 MediaPosition_AddRef,
2696 MediaPosition_Release,
2697 MediaPosition_GetTypeInfoCount,
2698 MediaPosition_GetTypeInfo,
2699 MediaPosition_GetIDsOfNames,
2700 MediaPosition_Invoke,
2701 MediaPosition_get_Duration,
2702 MediaPosition_put_CurrentPosition,
2703 MediaPosition_get_CurrentPosition,
2704 MediaPosition_get_StopTime,
2705 MediaPosition_put_StopTime,
2706 MediaPosition_get_PrerollTime,
2707 MediaPosition_put_PrerollTime,
2708 MediaPosition_put_Rate,
2709 MediaPosition_get_Rate,
2710 MediaPosition_CanSeekForward,
2711 MediaPosition_CanSeekBackward
2714 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2716 HRESULT hr = E_NOINTERFACE;
2717 int i;
2718 int entry;
2720 /* Check if the interface type is already registered */
2721 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2722 if (riid == pGraph->ItfCacheEntries[entry].riid)
2724 if (pGraph->ItfCacheEntries[entry].iface)
2726 /* Return the interface if available */
2727 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2728 return S_OK;
2730 break;
2733 if (entry >= MAX_ITF_CACHE_ENTRIES)
2735 FIXME("Not enough space to store interface in the cache\n");
2736 return E_OUTOFMEMORY;
2739 /* Find a filter supporting the requested interface */
2740 for (i = 0; i < pGraph->nFilters; i++)
2742 hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2743 if (hr == S_OK)
2745 pGraph->ItfCacheEntries[entry].riid = riid;
2746 pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2747 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2748 if (entry >= pGraph->nItfCacheEntries)
2749 pGraph->nItfCacheEntries++;
2750 return S_OK;
2752 if (hr != E_NOINTERFACE)
2753 return hr;
2756 return hr;
2759 /*** IUnknown methods ***/
2760 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface,
2761 REFIID riid,
2762 LPVOID*ppvObj) {
2763 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2765 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2767 return Filtergraph_QueryInterface(This, riid, ppvObj);
2770 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface) {
2771 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2773 TRACE("(%p/%p)->()\n", This, iface);
2775 return Filtergraph_AddRef(This);
2778 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface) {
2779 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2781 TRACE("(%p/%p)->()\n", This, iface);
2783 return Filtergraph_Release(This);
2786 /*** IDispatch methods ***/
2787 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface,
2788 UINT*pctinfo) {
2789 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2790 IBasicAudio* pBasicAudio;
2791 HRESULT hr;
2793 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
2795 EnterCriticalSection(&This->cs);
2797 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2799 if (hr == S_OK)
2800 hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
2802 LeaveCriticalSection(&This->cs);
2804 return hr;
2807 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface,
2808 UINT iTInfo,
2809 LCID lcid,
2810 ITypeInfo**ppTInfo) {
2811 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2812 IBasicAudio* pBasicAudio;
2813 HRESULT hr;
2815 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
2817 EnterCriticalSection(&This->cs);
2819 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2821 if (hr == S_OK)
2822 hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
2824 LeaveCriticalSection(&This->cs);
2826 return hr;
2829 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface,
2830 REFIID riid,
2831 LPOLESTR*rgszNames,
2832 UINT cNames,
2833 LCID lcid,
2834 DISPID*rgDispId) {
2835 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2836 IBasicAudio* pBasicAudio;
2837 HRESULT hr;
2839 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
2841 EnterCriticalSection(&This->cs);
2843 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2845 if (hr == S_OK)
2846 hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
2848 LeaveCriticalSection(&This->cs);
2850 return hr;
2853 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface,
2854 DISPID dispIdMember,
2855 REFIID riid,
2856 LCID lcid,
2857 WORD wFlags,
2858 DISPPARAMS*pDispParams,
2859 VARIANT*pVarResult,
2860 EXCEPINFO*pExepInfo,
2861 UINT*puArgErr) {
2862 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2863 IBasicAudio* pBasicAudio;
2864 HRESULT hr;
2866 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);
2868 EnterCriticalSection(&This->cs);
2870 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2872 if (hr == S_OK)
2873 hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
2875 LeaveCriticalSection(&This->cs);
2877 return hr;
2880 /*** IBasicAudio methods ***/
2881 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface,
2882 LONG lVolume) {
2883 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2884 IBasicAudio* pBasicAudio;
2885 HRESULT hr;
2887 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
2889 EnterCriticalSection(&This->cs);
2891 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2893 if (hr == S_OK)
2894 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
2896 LeaveCriticalSection(&This->cs);
2898 return hr;
2901 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface,
2902 LONG *plVolume) {
2903 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2904 IBasicAudio* pBasicAudio;
2905 HRESULT hr;
2907 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
2909 EnterCriticalSection(&This->cs);
2911 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2913 if (hr == S_OK)
2914 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
2916 LeaveCriticalSection(&This->cs);
2918 return hr;
2921 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface,
2922 LONG lBalance) {
2923 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2924 IBasicAudio* pBasicAudio;
2925 HRESULT hr;
2927 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
2929 EnterCriticalSection(&This->cs);
2931 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2933 if (hr == S_OK)
2934 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
2936 LeaveCriticalSection(&This->cs);
2938 return hr;
2941 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface,
2942 LONG *plBalance) {
2943 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2944 IBasicAudio* pBasicAudio;
2945 HRESULT hr;
2947 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
2949 EnterCriticalSection(&This->cs);
2951 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2953 if (hr == S_OK)
2954 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
2956 LeaveCriticalSection(&This->cs);
2958 return hr;
2961 static const IBasicAudioVtbl IBasicAudio_VTable =
2963 BasicAudio_QueryInterface,
2964 BasicAudio_AddRef,
2965 BasicAudio_Release,
2966 BasicAudio_GetTypeInfoCount,
2967 BasicAudio_GetTypeInfo,
2968 BasicAudio_GetIDsOfNames,
2969 BasicAudio_Invoke,
2970 BasicAudio_put_Volume,
2971 BasicAudio_get_Volume,
2972 BasicAudio_put_Balance,
2973 BasicAudio_get_Balance
2976 /*** IUnknown methods ***/
2977 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface,
2978 REFIID riid,
2979 LPVOID*ppvObj) {
2980 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2982 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2984 return Filtergraph_QueryInterface(This, riid, ppvObj);
2987 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface) {
2988 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2990 TRACE("(%p/%p)->()\n", This, iface);
2992 return Filtergraph_AddRef(This);
2995 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface) {
2996 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2998 TRACE("(%p/%p)->()\n", This, iface);
3000 return Filtergraph_Release(This);
3003 /*** IDispatch methods ***/
3004 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface,
3005 UINT*pctinfo) {
3006 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3007 IBasicVideo* pBasicVideo;
3008 HRESULT hr;
3010 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3012 EnterCriticalSection(&This->cs);
3014 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3016 if (hr == S_OK)
3017 hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
3019 LeaveCriticalSection(&This->cs);
3021 return hr;
3024 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface,
3025 UINT iTInfo,
3026 LCID lcid,
3027 ITypeInfo**ppTInfo) {
3028 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3029 IBasicVideo* pBasicVideo;
3030 HRESULT hr;
3032 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3034 EnterCriticalSection(&This->cs);
3036 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3038 if (hr == S_OK)
3039 hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
3041 LeaveCriticalSection(&This->cs);
3043 return hr;
3046 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface,
3047 REFIID riid,
3048 LPOLESTR*rgszNames,
3049 UINT cNames,
3050 LCID lcid,
3051 DISPID*rgDispId) {
3052 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3053 IBasicVideo* pBasicVideo;
3054 HRESULT hr;
3056 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3058 EnterCriticalSection(&This->cs);
3060 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3062 if (hr == S_OK)
3063 hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
3065 LeaveCriticalSection(&This->cs);
3067 return hr;
3070 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface,
3071 DISPID dispIdMember,
3072 REFIID riid,
3073 LCID lcid,
3074 WORD wFlags,
3075 DISPPARAMS*pDispParams,
3076 VARIANT*pVarResult,
3077 EXCEPINFO*pExepInfo,
3078 UINT*puArgErr) {
3079 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3080 IBasicVideo* pBasicVideo;
3081 HRESULT hr;
3083 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);
3085 EnterCriticalSection(&This->cs);
3087 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3089 if (hr == S_OK)
3090 hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3092 LeaveCriticalSection(&This->cs);
3094 return hr;
3097 /*** IBasicVideo methods ***/
3098 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface,
3099 REFTIME *pAvgTimePerFrame) {
3100 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3101 IBasicVideo* pBasicVideo;
3102 HRESULT hr;
3104 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3106 EnterCriticalSection(&This->cs);
3108 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3110 if (hr == S_OK)
3111 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3113 LeaveCriticalSection(&This->cs);
3115 return hr;
3118 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface,
3119 LONG *pBitRate) {
3120 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3121 IBasicVideo* pBasicVideo;
3122 HRESULT hr;
3124 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3126 EnterCriticalSection(&This->cs);
3128 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3130 if (hr == S_OK)
3131 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3133 LeaveCriticalSection(&This->cs);
3135 return hr;
3138 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface,
3139 LONG *pBitErrorRate) {
3140 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3141 IBasicVideo* pBasicVideo;
3142 HRESULT hr;
3144 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3146 EnterCriticalSection(&This->cs);
3148 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3150 if (hr == S_OK)
3151 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3153 LeaveCriticalSection(&This->cs);
3155 return hr;
3158 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface,
3159 LONG *pVideoWidth) {
3160 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3161 IBasicVideo* pBasicVideo;
3162 HRESULT hr;
3164 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3166 EnterCriticalSection(&This->cs);
3168 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3170 if (hr == S_OK)
3171 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3173 LeaveCriticalSection(&This->cs);
3175 return hr;
3178 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface,
3179 LONG *pVideoHeight) {
3180 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3181 IBasicVideo* pBasicVideo;
3182 HRESULT hr;
3184 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3186 EnterCriticalSection(&This->cs);
3188 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3190 if (hr == S_OK)
3191 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3193 LeaveCriticalSection(&This->cs);
3195 return hr;
3198 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface,
3199 LONG SourceLeft) {
3200 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3201 IBasicVideo* pBasicVideo;
3202 HRESULT hr;
3204 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3206 EnterCriticalSection(&This->cs);
3208 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3210 if (hr == S_OK)
3211 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3213 LeaveCriticalSection(&This->cs);
3215 return hr;
3218 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface,
3219 LONG *pSourceLeft) {
3220 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3221 IBasicVideo* pBasicVideo;
3222 HRESULT hr;
3224 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3226 EnterCriticalSection(&This->cs);
3228 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3230 if (hr == S_OK)
3231 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3233 LeaveCriticalSection(&This->cs);
3235 return hr;
3238 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface,
3239 LONG SourceWidth) {
3240 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3241 IBasicVideo* pBasicVideo;
3242 HRESULT hr;
3244 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3246 EnterCriticalSection(&This->cs);
3248 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3250 if (hr == S_OK)
3251 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3253 LeaveCriticalSection(&This->cs);
3255 return hr;
3258 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface,
3259 LONG *pSourceWidth) {
3260 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3261 IBasicVideo* pBasicVideo;
3262 HRESULT hr;
3264 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3266 EnterCriticalSection(&This->cs);
3268 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3270 if (hr == S_OK)
3271 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3273 LeaveCriticalSection(&This->cs);
3275 return hr;
3278 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface,
3279 LONG SourceTop) {
3280 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3281 IBasicVideo* pBasicVideo;
3282 HRESULT hr;
3284 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3286 EnterCriticalSection(&This->cs);
3288 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3290 if (hr == S_OK)
3291 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3293 LeaveCriticalSection(&This->cs);
3295 return hr;
3298 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface,
3299 LONG *pSourceTop) {
3300 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3301 IBasicVideo* pBasicVideo;
3302 HRESULT hr;
3304 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3306 EnterCriticalSection(&This->cs);
3308 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3310 if (hr == S_OK)
3311 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3313 LeaveCriticalSection(&This->cs);
3315 return hr;
3318 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface,
3319 LONG SourceHeight) {
3320 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3321 IBasicVideo* pBasicVideo;
3322 HRESULT hr;
3324 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3326 EnterCriticalSection(&This->cs);
3328 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3330 if (hr == S_OK)
3331 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3333 LeaveCriticalSection(&This->cs);
3335 return hr;
3338 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface,
3339 LONG *pSourceHeight) {
3340 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3341 IBasicVideo* pBasicVideo;
3342 HRESULT hr;
3344 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3346 EnterCriticalSection(&This->cs);
3348 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3350 if (hr == S_OK)
3351 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3353 LeaveCriticalSection(&This->cs);
3355 return hr;
3358 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface,
3359 LONG DestinationLeft) {
3360 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3361 IBasicVideo* pBasicVideo;
3362 HRESULT hr;
3364 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3366 EnterCriticalSection(&This->cs);
3368 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3370 if (hr == S_OK)
3371 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3373 LeaveCriticalSection(&This->cs);
3375 return hr;
3378 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface,
3379 LONG *pDestinationLeft) {
3380 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3381 IBasicVideo* pBasicVideo;
3382 HRESULT hr;
3384 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3386 EnterCriticalSection(&This->cs);
3388 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3390 if (hr == S_OK)
3391 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3393 LeaveCriticalSection(&This->cs);
3395 return hr;
3398 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface,
3399 LONG DestinationWidth) {
3400 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3401 IBasicVideo* pBasicVideo;
3402 HRESULT hr;
3404 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3406 EnterCriticalSection(&This->cs);
3408 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3410 if (hr == S_OK)
3411 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3413 LeaveCriticalSection(&This->cs);
3415 return hr;
3418 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface,
3419 LONG *pDestinationWidth) {
3420 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3421 IBasicVideo* pBasicVideo;
3422 HRESULT hr;
3424 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3426 EnterCriticalSection(&This->cs);
3428 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3430 if (hr == S_OK)
3431 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3433 LeaveCriticalSection(&This->cs);
3435 return hr;
3438 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface,
3439 LONG DestinationTop) {
3440 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3441 IBasicVideo* pBasicVideo;
3442 HRESULT hr;
3444 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3446 EnterCriticalSection(&This->cs);
3448 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3450 if (hr == S_OK)
3451 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3453 LeaveCriticalSection(&This->cs);
3455 return hr;
3458 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface,
3459 LONG *pDestinationTop) {
3460 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3461 IBasicVideo* pBasicVideo;
3462 HRESULT hr;
3464 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3466 EnterCriticalSection(&This->cs);
3468 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3470 if (hr == S_OK)
3471 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3473 LeaveCriticalSection(&This->cs);
3475 return hr;
3478 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface,
3479 LONG DestinationHeight) {
3480 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3481 IBasicVideo* pBasicVideo;
3482 HRESULT hr;
3484 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3486 EnterCriticalSection(&This->cs);
3488 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3490 if (hr == S_OK)
3491 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3493 LeaveCriticalSection(&This->cs);
3495 return hr;
3498 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3499 LONG *pDestinationHeight) {
3500 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3501 IBasicVideo* pBasicVideo;
3502 HRESULT hr;
3504 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3506 EnterCriticalSection(&This->cs);
3508 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3510 if (hr == S_OK)
3511 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3513 LeaveCriticalSection(&This->cs);
3515 return hr;
3518 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface,
3519 LONG Left,
3520 LONG Top,
3521 LONG Width,
3522 LONG Height) {
3523 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3524 IBasicVideo* pBasicVideo;
3525 HRESULT hr;
3527 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3529 EnterCriticalSection(&This->cs);
3531 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3533 if (hr == S_OK)
3534 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3536 LeaveCriticalSection(&This->cs);
3538 return hr;
3541 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface,
3542 LONG *pLeft,
3543 LONG *pTop,
3544 LONG *pWidth,
3545 LONG *pHeight) {
3546 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3547 IBasicVideo* pBasicVideo;
3548 HRESULT hr;
3550 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3552 EnterCriticalSection(&This->cs);
3554 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3556 if (hr == S_OK)
3557 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3559 LeaveCriticalSection(&This->cs);
3561 return hr;
3564 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface) {
3565 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3566 IBasicVideo* pBasicVideo;
3567 HRESULT hr;
3569 TRACE("(%p/%p)->()\n", This, iface);
3571 EnterCriticalSection(&This->cs);
3573 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3575 if (hr == S_OK)
3576 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3578 LeaveCriticalSection(&This->cs);
3580 return hr;
3583 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface,
3584 LONG Left,
3585 LONG Top,
3586 LONG Width,
3587 LONG Height) {
3588 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3589 IBasicVideo* pBasicVideo;
3590 HRESULT hr;
3592 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3594 EnterCriticalSection(&This->cs);
3596 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3598 if (hr == S_OK)
3599 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3601 LeaveCriticalSection(&This->cs);
3603 return hr;
3606 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface,
3607 LONG *pLeft,
3608 LONG *pTop,
3609 LONG *pWidth,
3610 LONG *pHeight) {
3611 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3612 IBasicVideo* pBasicVideo;
3613 HRESULT hr;
3615 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3617 EnterCriticalSection(&This->cs);
3619 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3621 if (hr == S_OK)
3622 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3624 LeaveCriticalSection(&This->cs);
3626 return hr;
3629 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface) {
3630 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3631 IBasicVideo* pBasicVideo;
3632 HRESULT hr;
3634 TRACE("(%p/%p)->()\n", This, iface);
3636 EnterCriticalSection(&This->cs);
3638 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3640 if (hr == S_OK)
3641 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3643 LeaveCriticalSection(&This->cs);
3645 return hr;
3648 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface,
3649 LONG *pWidth,
3650 LONG *pHeight) {
3651 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3652 IBasicVideo* pBasicVideo;
3653 HRESULT hr;
3655 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3657 EnterCriticalSection(&This->cs);
3659 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3661 if (hr == S_OK)
3662 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3664 LeaveCriticalSection(&This->cs);
3666 return hr;
3669 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface,
3670 LONG StartIndex,
3671 LONG Entries,
3672 LONG *pRetrieved,
3673 LONG *pPalette) {
3674 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3675 IBasicVideo* pBasicVideo;
3676 HRESULT hr;
3678 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3680 EnterCriticalSection(&This->cs);
3682 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3684 if (hr == S_OK)
3685 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3687 LeaveCriticalSection(&This->cs);
3689 return hr;
3692 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface,
3693 LONG *pBufferSize,
3694 LONG *pDIBImage) {
3695 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3696 IBasicVideo* pBasicVideo;
3697 HRESULT hr;
3699 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3701 EnterCriticalSection(&This->cs);
3703 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3705 if (hr == S_OK)
3706 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3708 LeaveCriticalSection(&This->cs);
3710 return hr;
3713 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface) {
3714 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3715 IBasicVideo* pBasicVideo;
3716 HRESULT hr;
3718 TRACE("(%p/%p)->()\n", This, iface);
3720 EnterCriticalSection(&This->cs);
3722 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3724 if (hr == S_OK)
3725 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3727 LeaveCriticalSection(&This->cs);
3729 return hr;
3732 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface) {
3733 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3734 IBasicVideo* pBasicVideo;
3735 HRESULT hr;
3737 TRACE("(%p/%p)->()\n", This, iface);
3739 EnterCriticalSection(&This->cs);
3741 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3743 if (hr == S_OK)
3744 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3746 LeaveCriticalSection(&This->cs);
3748 return hr;
3751 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX, LONG *plAspectY) {
3752 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3753 IBasicVideo2 *pBasicVideo2;
3754 HRESULT hr;
3756 TRACE("(%p/%p)->()\n", This, iface);
3758 EnterCriticalSection(&This->cs);
3760 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3762 if (hr == S_OK)
3763 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3765 LeaveCriticalSection(&This->cs);
3767 return hr;
3770 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3772 BasicVideo_QueryInterface,
3773 BasicVideo_AddRef,
3774 BasicVideo_Release,
3775 BasicVideo_GetTypeInfoCount,
3776 BasicVideo_GetTypeInfo,
3777 BasicVideo_GetIDsOfNames,
3778 BasicVideo_Invoke,
3779 BasicVideo_get_AvgTimePerFrame,
3780 BasicVideo_get_BitRate,
3781 BasicVideo_get_BitErrorRate,
3782 BasicVideo_get_VideoWidth,
3783 BasicVideo_get_VideoHeight,
3784 BasicVideo_put_SourceLeft,
3785 BasicVideo_get_SourceLeft,
3786 BasicVideo_put_SourceWidth,
3787 BasicVideo_get_SourceWidth,
3788 BasicVideo_put_SourceTop,
3789 BasicVideo_get_SourceTop,
3790 BasicVideo_put_SourceHeight,
3791 BasicVideo_get_SourceHeight,
3792 BasicVideo_put_DestinationLeft,
3793 BasicVideo_get_DestinationLeft,
3794 BasicVideo_put_DestinationWidth,
3795 BasicVideo_get_DestinationWidth,
3796 BasicVideo_put_DestinationTop,
3797 BasicVideo_get_DestinationTop,
3798 BasicVideo_put_DestinationHeight,
3799 BasicVideo_get_DestinationHeight,
3800 BasicVideo_SetSourcePosition,
3801 BasicVideo_GetSourcePosition,
3802 BasicVideo_SetDefaultSourcePosition,
3803 BasicVideo_SetDestinationPosition,
3804 BasicVideo_GetDestinationPosition,
3805 BasicVideo_SetDefaultDestinationPosition,
3806 BasicVideo_GetVideoSize,
3807 BasicVideo_GetVideoPaletteEntries,
3808 BasicVideo_GetCurrentImage,
3809 BasicVideo_IsUsingDefaultSource,
3810 BasicVideo_IsUsingDefaultDestination,
3811 BasicVideo2_GetPreferredAspectRatio
3815 /*** IUnknown methods ***/
3816 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface,
3817 REFIID riid,
3818 LPVOID*ppvObj) {
3819 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3821 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3823 return Filtergraph_QueryInterface(This, riid, ppvObj);
3826 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface) {
3827 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3829 TRACE("(%p/%p)->()\n", This, iface);
3831 return Filtergraph_AddRef(This);
3834 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface) {
3835 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3837 TRACE("(%p/%p)->()\n", This, iface);
3839 return Filtergraph_Release(This);
3842 /*** IDispatch methods ***/
3843 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface,
3844 UINT*pctinfo) {
3845 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3846 IVideoWindow* pVideoWindow;
3847 HRESULT hr;
3849 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3851 EnterCriticalSection(&This->cs);
3853 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3855 if (hr == S_OK)
3856 hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
3858 LeaveCriticalSection(&This->cs);
3860 return hr;
3863 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface,
3864 UINT iTInfo,
3865 LCID lcid,
3866 ITypeInfo**ppTInfo) {
3867 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3868 IVideoWindow* pVideoWindow;
3869 HRESULT hr;
3871 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3873 EnterCriticalSection(&This->cs);
3875 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3877 if (hr == S_OK)
3878 hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
3880 LeaveCriticalSection(&This->cs);
3882 return hr;
3885 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface,
3886 REFIID riid,
3887 LPOLESTR*rgszNames,
3888 UINT cNames,
3889 LCID lcid,
3890 DISPID*rgDispId) {
3891 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3892 IVideoWindow* pVideoWindow;
3893 HRESULT hr;
3895 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3897 EnterCriticalSection(&This->cs);
3899 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3901 if (hr == S_OK)
3902 hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
3904 LeaveCriticalSection(&This->cs);
3906 return hr;
3909 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface,
3910 DISPID dispIdMember,
3911 REFIID riid,
3912 LCID lcid,
3913 WORD wFlags,
3914 DISPPARAMS*pDispParams,
3915 VARIANT*pVarResult,
3916 EXCEPINFO*pExepInfo,
3917 UINT*puArgErr) {
3918 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3919 IVideoWindow* pVideoWindow;
3920 HRESULT hr;
3922 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);
3924 EnterCriticalSection(&This->cs);
3926 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3928 if (hr == S_OK)
3929 hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3931 LeaveCriticalSection(&This->cs);
3933 return hr;
3937 /*** IVideoWindow methods ***/
3938 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface,
3939 BSTR strCaption) {
3940 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3941 IVideoWindow* pVideoWindow;
3942 HRESULT hr;
3944 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
3946 EnterCriticalSection(&This->cs);
3948 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3950 if (hr == S_OK)
3951 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
3953 LeaveCriticalSection(&This->cs);
3955 return hr;
3958 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface,
3959 BSTR *strCaption) {
3960 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3961 IVideoWindow* pVideoWindow;
3962 HRESULT hr;
3964 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
3966 EnterCriticalSection(&This->cs);
3968 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3970 if (hr == S_OK)
3971 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
3973 LeaveCriticalSection(&This->cs);
3975 return hr;
3978 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface,
3979 LONG WindowStyle) {
3980 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3981 IVideoWindow* pVideoWindow;
3982 HRESULT hr;
3984 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
3986 EnterCriticalSection(&This->cs);
3988 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3990 if (hr == S_OK)
3991 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
3993 LeaveCriticalSection(&This->cs);
3995 return hr;
3998 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface,
3999 LONG *WindowStyle) {
4000 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4001 IVideoWindow* pVideoWindow;
4002 HRESULT hr;
4004 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
4006 EnterCriticalSection(&This->cs);
4008 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4010 if (hr == S_OK)
4011 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
4013 LeaveCriticalSection(&This->cs);
4015 return hr;
4018 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface,
4019 LONG WindowStyleEx) {
4020 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4021 IVideoWindow* pVideoWindow;
4022 HRESULT hr;
4024 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
4026 EnterCriticalSection(&This->cs);
4028 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4030 if (hr == S_OK)
4031 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
4033 LeaveCriticalSection(&This->cs);
4035 return hr;
4038 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface,
4039 LONG *WindowStyleEx) {
4040 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4041 IVideoWindow* pVideoWindow;
4042 HRESULT hr;
4044 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
4046 EnterCriticalSection(&This->cs);
4048 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4050 if (hr == S_OK)
4051 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
4053 LeaveCriticalSection(&This->cs);
4055 return hr;
4058 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface,
4059 LONG AutoShow) {
4060 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4061 IVideoWindow* pVideoWindow;
4062 HRESULT hr;
4064 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
4066 EnterCriticalSection(&This->cs);
4068 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4070 if (hr == S_OK)
4071 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4073 LeaveCriticalSection(&This->cs);
4075 return hr;
4078 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface,
4079 LONG *AutoShow) {
4080 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4081 IVideoWindow* pVideoWindow;
4082 HRESULT hr;
4084 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4086 EnterCriticalSection(&This->cs);
4088 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4090 if (hr == S_OK)
4091 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4093 LeaveCriticalSection(&This->cs);
4095 return hr;
4098 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface,
4099 LONG WindowState) {
4100 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4101 IVideoWindow* pVideoWindow;
4102 HRESULT hr;
4104 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4106 EnterCriticalSection(&This->cs);
4108 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4110 if (hr == S_OK)
4111 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4113 LeaveCriticalSection(&This->cs);
4115 return hr;
4118 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface,
4119 LONG *WindowState) {
4120 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4121 IVideoWindow* pVideoWindow;
4122 HRESULT hr;
4124 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4126 EnterCriticalSection(&This->cs);
4128 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4130 if (hr == S_OK)
4131 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4133 LeaveCriticalSection(&This->cs);
4135 return hr;
4138 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface,
4139 LONG BackgroundPalette) {
4140 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4141 IVideoWindow* pVideoWindow;
4142 HRESULT hr;
4144 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4146 EnterCriticalSection(&This->cs);
4148 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4150 if (hr == S_OK)
4151 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4153 LeaveCriticalSection(&This->cs);
4155 return hr;
4158 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4159 LONG *pBackgroundPalette) {
4160 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4161 IVideoWindow* pVideoWindow;
4162 HRESULT hr;
4164 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4166 EnterCriticalSection(&This->cs);
4168 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4170 if (hr == S_OK)
4171 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4173 LeaveCriticalSection(&This->cs);
4175 return hr;
4178 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface,
4179 LONG Visible) {
4180 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4181 IVideoWindow* pVideoWindow;
4182 HRESULT hr;
4184 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4186 EnterCriticalSection(&This->cs);
4188 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4190 if (hr == S_OK)
4191 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4193 LeaveCriticalSection(&This->cs);
4195 return hr;
4198 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface,
4199 LONG *pVisible) {
4200 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4201 IVideoWindow* pVideoWindow;
4202 HRESULT hr;
4204 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4206 EnterCriticalSection(&This->cs);
4208 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4210 if (hr == S_OK)
4211 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4213 LeaveCriticalSection(&This->cs);
4215 return hr;
4218 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface,
4219 LONG Left) {
4220 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4221 IVideoWindow* pVideoWindow;
4222 HRESULT hr;
4224 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4226 EnterCriticalSection(&This->cs);
4228 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4230 if (hr == S_OK)
4231 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4233 LeaveCriticalSection(&This->cs);
4235 return hr;
4238 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface,
4239 LONG *pLeft) {
4240 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4241 IVideoWindow* pVideoWindow;
4242 HRESULT hr;
4244 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4246 EnterCriticalSection(&This->cs);
4248 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4250 if (hr == S_OK)
4251 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4253 LeaveCriticalSection(&This->cs);
4255 return hr;
4258 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface,
4259 LONG Width) {
4260 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4261 IVideoWindow* pVideoWindow;
4262 HRESULT hr;
4264 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4266 EnterCriticalSection(&This->cs);
4268 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4270 if (hr == S_OK)
4271 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4273 LeaveCriticalSection(&This->cs);
4275 return hr;
4278 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface,
4279 LONG *pWidth) {
4280 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4281 IVideoWindow* pVideoWindow;
4282 HRESULT hr;
4284 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4286 EnterCriticalSection(&This->cs);
4288 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4290 if (hr == S_OK)
4291 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4293 LeaveCriticalSection(&This->cs);
4295 return hr;
4298 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface,
4299 LONG Top) {
4300 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4301 IVideoWindow* pVideoWindow;
4302 HRESULT hr;
4304 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4306 EnterCriticalSection(&This->cs);
4308 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4310 if (hr == S_OK)
4311 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4313 LeaveCriticalSection(&This->cs);
4315 return hr;
4318 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface,
4319 LONG *pTop) {
4320 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4321 IVideoWindow* pVideoWindow;
4322 HRESULT hr;
4324 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4326 EnterCriticalSection(&This->cs);
4328 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4330 if (hr == S_OK)
4331 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4333 LeaveCriticalSection(&This->cs);
4335 return hr;
4338 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface,
4339 LONG Height) {
4340 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4341 IVideoWindow* pVideoWindow;
4342 HRESULT hr;
4344 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4346 EnterCriticalSection(&This->cs);
4348 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4350 if (hr == S_OK)
4351 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4353 LeaveCriticalSection(&This->cs);
4355 return hr;
4358 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface,
4359 LONG *pHeight) {
4360 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4361 IVideoWindow* pVideoWindow;
4362 HRESULT hr;
4364 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4366 EnterCriticalSection(&This->cs);
4368 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4370 if (hr == S_OK)
4371 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4373 LeaveCriticalSection(&This->cs);
4375 return hr;
4378 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface,
4379 OAHWND Owner) {
4380 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4381 IVideoWindow* pVideoWindow;
4382 HRESULT hr;
4384 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4386 EnterCriticalSection(&This->cs);
4388 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4390 if (hr == S_OK)
4391 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4393 LeaveCriticalSection(&This->cs);
4395 return hr;
4398 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface,
4399 OAHWND *Owner) {
4400 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4401 IVideoWindow* pVideoWindow;
4402 HRESULT hr;
4404 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4406 EnterCriticalSection(&This->cs);
4408 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4410 if (hr == S_OK)
4411 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4413 LeaveCriticalSection(&This->cs);
4415 return hr;
4418 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface,
4419 OAHWND Drain) {
4420 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4421 IVideoWindow* pVideoWindow;
4422 HRESULT hr;
4424 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4426 EnterCriticalSection(&This->cs);
4428 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4430 if (hr == S_OK)
4431 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4433 LeaveCriticalSection(&This->cs);
4435 return hr;
4438 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface,
4439 OAHWND *Drain) {
4440 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4441 IVideoWindow* pVideoWindow;
4442 HRESULT hr;
4444 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4446 EnterCriticalSection(&This->cs);
4448 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4450 if (hr == S_OK)
4451 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4453 LeaveCriticalSection(&This->cs);
4455 return hr;
4458 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface,
4459 LONG *Color) {
4460 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4461 IVideoWindow* pVideoWindow;
4462 HRESULT hr;
4464 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4466 EnterCriticalSection(&This->cs);
4468 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4470 if (hr == S_OK)
4471 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4473 LeaveCriticalSection(&This->cs);
4475 return hr;
4478 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface,
4479 LONG Color) {
4480 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4481 IVideoWindow* pVideoWindow;
4482 HRESULT hr;
4484 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4486 EnterCriticalSection(&This->cs);
4488 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4490 if (hr == S_OK)
4491 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4493 LeaveCriticalSection(&This->cs);
4495 return hr;
4498 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface,
4499 LONG *FullScreenMode) {
4500 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4501 IVideoWindow* pVideoWindow;
4502 HRESULT hr;
4504 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4506 EnterCriticalSection(&This->cs);
4508 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4510 if (hr == S_OK)
4511 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4513 LeaveCriticalSection(&This->cs);
4515 return hr;
4518 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface,
4519 LONG FullScreenMode) {
4520 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4521 IVideoWindow* pVideoWindow;
4522 HRESULT hr;
4524 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4526 EnterCriticalSection(&This->cs);
4528 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4530 if (hr == S_OK)
4531 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4533 LeaveCriticalSection(&This->cs);
4535 return hr;
4538 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface,
4539 LONG Focus) {
4540 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4541 IVideoWindow* pVideoWindow;
4542 HRESULT hr;
4544 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4546 EnterCriticalSection(&This->cs);
4548 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4550 if (hr == S_OK)
4551 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4553 LeaveCriticalSection(&This->cs);
4555 return hr;
4558 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface,
4559 OAHWND hwnd,
4560 LONG uMsg,
4561 LONG_PTR wParam,
4562 LONG_PTR lParam) {
4563 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4564 IVideoWindow* pVideoWindow;
4565 HRESULT hr;
4567 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4569 EnterCriticalSection(&This->cs);
4571 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4573 if (hr == S_OK)
4574 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4576 LeaveCriticalSection(&This->cs);
4578 return hr;
4581 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface,
4582 LONG Left,
4583 LONG Top,
4584 LONG Width,
4585 LONG Height) {
4586 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4587 IVideoWindow* pVideoWindow;
4588 HRESULT hr;
4590 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4592 EnterCriticalSection(&This->cs);
4594 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4596 if (hr == S_OK)
4597 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4599 LeaveCriticalSection(&This->cs);
4601 return hr;
4604 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface,
4605 LONG *pLeft,
4606 LONG *pTop,
4607 LONG *pWidth,
4608 LONG *pHeight) {
4609 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4610 IVideoWindow* pVideoWindow;
4611 HRESULT hr;
4613 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4615 EnterCriticalSection(&This->cs);
4617 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4619 if (hr == S_OK)
4620 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4622 LeaveCriticalSection(&This->cs);
4624 return hr;
4627 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface,
4628 LONG *pWidth,
4629 LONG *pHeight) {
4630 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4631 IVideoWindow* pVideoWindow;
4632 HRESULT hr;
4634 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4636 EnterCriticalSection(&This->cs);
4638 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4640 if (hr == S_OK)
4641 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4643 LeaveCriticalSection(&This->cs);
4645 return hr;
4648 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface,
4649 LONG *pWidth,
4650 LONG *pHeight) {
4651 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4652 IVideoWindow* pVideoWindow;
4653 HRESULT hr;
4655 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4657 EnterCriticalSection(&This->cs);
4659 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4661 if (hr == S_OK)
4662 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4664 LeaveCriticalSection(&This->cs);
4666 return hr;
4669 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface,
4670 LONG *pLeft,
4671 LONG *pTop,
4672 LONG *pWidth,
4673 LONG *pHeight) {
4674 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4675 IVideoWindow* pVideoWindow;
4676 HRESULT hr;
4678 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4680 EnterCriticalSection(&This->cs);
4682 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4684 if (hr == S_OK)
4685 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4687 LeaveCriticalSection(&This->cs);
4689 return hr;
4692 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface,
4693 LONG HideCursor) {
4694 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4695 IVideoWindow* pVideoWindow;
4696 HRESULT hr;
4698 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4700 EnterCriticalSection(&This->cs);
4702 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4704 if (hr == S_OK)
4705 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4707 LeaveCriticalSection(&This->cs);
4709 return hr;
4712 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface,
4713 LONG *CursorHidden) {
4714 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4715 IVideoWindow* pVideoWindow;
4716 HRESULT hr;
4718 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4720 EnterCriticalSection(&This->cs);
4722 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4724 if (hr == S_OK)
4725 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4727 LeaveCriticalSection(&This->cs);
4729 return hr;
4733 static const IVideoWindowVtbl IVideoWindow_VTable =
4735 VideoWindow_QueryInterface,
4736 VideoWindow_AddRef,
4737 VideoWindow_Release,
4738 VideoWindow_GetTypeInfoCount,
4739 VideoWindow_GetTypeInfo,
4740 VideoWindow_GetIDsOfNames,
4741 VideoWindow_Invoke,
4742 VideoWindow_put_Caption,
4743 VideoWindow_get_Caption,
4744 VideoWindow_put_WindowStyle,
4745 VideoWindow_get_WindowStyle,
4746 VideoWindow_put_WindowStyleEx,
4747 VideoWindow_get_WindowStyleEx,
4748 VideoWindow_put_AutoShow,
4749 VideoWindow_get_AutoShow,
4750 VideoWindow_put_WindowState,
4751 VideoWindow_get_WindowState,
4752 VideoWindow_put_BackgroundPalette,
4753 VideoWindow_get_BackgroundPalette,
4754 VideoWindow_put_Visible,
4755 VideoWindow_get_Visible,
4756 VideoWindow_put_Left,
4757 VideoWindow_get_Left,
4758 VideoWindow_put_Width,
4759 VideoWindow_get_Width,
4760 VideoWindow_put_Top,
4761 VideoWindow_get_Top,
4762 VideoWindow_put_Height,
4763 VideoWindow_get_Height,
4764 VideoWindow_put_Owner,
4765 VideoWindow_get_Owner,
4766 VideoWindow_put_MessageDrain,
4767 VideoWindow_get_MessageDrain,
4768 VideoWindow_get_BorderColor,
4769 VideoWindow_put_BorderColor,
4770 VideoWindow_get_FullScreenMode,
4771 VideoWindow_put_FullScreenMode,
4772 VideoWindow_SetWindowForeground,
4773 VideoWindow_NotifyOwnerMessage,
4774 VideoWindow_SetWindowPosition,
4775 VideoWindow_GetWindowPosition,
4776 VideoWindow_GetMinIdealImageSize,
4777 VideoWindow_GetMaxIdealImageSize,
4778 VideoWindow_GetRestorePosition,
4779 VideoWindow_HideCursor,
4780 VideoWindow_IsCursorHidden
4784 /*** IUnknown methods ***/
4785 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface,
4786 REFIID riid,
4787 LPVOID*ppvObj) {
4788 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4790 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
4792 return Filtergraph_QueryInterface(This, riid, ppvObj);
4795 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface) {
4796 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4798 TRACE("(%p/%p)->()\n", This, iface);
4800 return Filtergraph_AddRef(This);
4803 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface) {
4804 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4806 TRACE("(%p/%p)->()\n", This, iface);
4808 return Filtergraph_Release(This);
4811 /*** IDispatch methods ***/
4812 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface,
4813 UINT*pctinfo) {
4814 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4816 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
4818 return S_OK;
4821 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface,
4822 UINT iTInfo,
4823 LCID lcid,
4824 ITypeInfo**ppTInfo) {
4825 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4827 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
4829 return S_OK;
4832 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface,
4833 REFIID riid,
4834 LPOLESTR*rgszNames,
4835 UINT cNames,
4836 LCID lcid,
4837 DISPID*rgDispId) {
4838 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4840 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
4842 return S_OK;
4845 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface,
4846 DISPID dispIdMember,
4847 REFIID riid,
4848 LCID lcid,
4849 WORD wFlags,
4850 DISPPARAMS*pDispParams,
4851 VARIANT*pVarResult,
4852 EXCEPINFO*pExepInfo,
4853 UINT*puArgErr) {
4854 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4856 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);
4858 return S_OK;
4861 /*** IMediaEvent methods ***/
4862 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface,
4863 OAEVENT *hEvent) {
4864 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4866 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
4868 *hEvent = (OAEVENT)This->evqueue.msg_event;
4870 return S_OK;
4873 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface,
4874 LONG *lEventCode,
4875 LONG_PTR *lParam1,
4876 LONG_PTR *lParam2,
4877 LONG msTimeout) {
4878 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4879 Event evt;
4881 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
4883 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
4885 *lEventCode = evt.lEventCode;
4886 *lParam1 = evt.lParam1;
4887 *lParam2 = evt.lParam2;
4888 return S_OK;
4891 *lEventCode = 0;
4892 return E_ABORT;
4895 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface,
4896 LONG msTimeout,
4897 LONG *pEvCode) {
4898 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4900 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
4902 if (This->state != State_Running)
4903 return VFW_E_WRONG_STATE;
4905 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
4907 *pEvCode = This->CompletionStatus;
4908 return S_OK;
4911 *pEvCode = 0;
4912 return E_ABORT;
4915 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface,
4916 LONG lEvCode) {
4917 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4919 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4921 if (lEvCode == EC_COMPLETE)
4922 This->HandleEcComplete = FALSE;
4923 else if (lEvCode == EC_REPAINT)
4924 This->HandleEcRepaint = FALSE;
4925 else if (lEvCode == EC_CLOCK_CHANGED)
4926 This->HandleEcClockChanged = FALSE;
4927 else
4928 return S_FALSE;
4930 return S_OK;
4933 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface,
4934 LONG lEvCode) {
4935 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4937 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4939 if (lEvCode == EC_COMPLETE)
4940 This->HandleEcComplete = TRUE;
4941 else if (lEvCode == EC_REPAINT)
4942 This->HandleEcRepaint = TRUE;
4943 else if (lEvCode == EC_CLOCK_CHANGED)
4944 This->HandleEcClockChanged = TRUE;
4945 else
4946 return S_FALSE;
4948 return S_OK;
4951 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface,
4952 LONG lEvCode,
4953 LONG_PTR lParam1,
4954 LONG_PTR lParam2) {
4955 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4957 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
4959 return S_OK;
4962 /*** IMediaEventEx methods ***/
4963 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface,
4964 OAHWND hwnd,
4965 LONG lMsg,
4966 LONG_PTR lInstanceData) {
4967 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4969 TRACE("(%p/%p)->(%08lx, %d, %08lx)\n", This, iface, hwnd, lMsg, lInstanceData);
4971 This->notif.hWnd = (HWND)hwnd;
4972 This->notif.msg = lMsg;
4973 This->notif.instance = lInstanceData;
4975 return S_OK;
4978 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface,
4979 LONG lNoNotifyFlags) {
4980 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4982 TRACE("(%p/%p)->(%d)\n", This, iface, lNoNotifyFlags);
4984 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
4985 return E_INVALIDARG;
4987 This->notif.disabled = lNoNotifyFlags;
4989 return S_OK;
4992 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface,
4993 LONG *lplNoNotifyFlags) {
4994 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4996 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
4998 if (!lplNoNotifyFlags)
4999 return E_POINTER;
5001 *lplNoNotifyFlags = This->notif.disabled;
5003 return S_OK;
5007 static const IMediaEventExVtbl IMediaEventEx_VTable =
5009 MediaEvent_QueryInterface,
5010 MediaEvent_AddRef,
5011 MediaEvent_Release,
5012 MediaEvent_GetTypeInfoCount,
5013 MediaEvent_GetTypeInfo,
5014 MediaEvent_GetIDsOfNames,
5015 MediaEvent_Invoke,
5016 MediaEvent_GetEventHandle,
5017 MediaEvent_GetEvent,
5018 MediaEvent_WaitForCompletion,
5019 MediaEvent_CancelDefaultHandling,
5020 MediaEvent_RestoreDefaultHandling,
5021 MediaEvent_FreeEventParams,
5022 MediaEvent_SetNotifyWindow,
5023 MediaEvent_SetNotifyFlags,
5024 MediaEvent_GetNotifyFlags
5028 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, LPVOID *ppv)
5030 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5032 return Filtergraph_QueryInterface(This, riid, ppv);
5035 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
5037 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5039 return Filtergraph_AddRef(This);
5042 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
5044 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5046 return Filtergraph_Release(This);
5049 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
5051 FIXME("(%p): stub\n", pClassID);
5053 return E_NOTIMPL;
5056 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
5058 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5059 return MediaControl_Stop((IMediaControl*)&This->IMediaControl_vtbl);
5062 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5064 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5065 return MediaControl_Pause((IMediaControl*)&This->IMediaControl_vtbl);
5068 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
5070 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5071 return MediaControl_Run((IMediaControl*)&This->IMediaControl_vtbl);
5074 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout, FILTER_STATE * pState)
5076 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5077 return MediaControl_GetState((IMediaControl*)&This->IMediaControl_vtbl, dwMsTimeout, (OAFilterState*)pState);
5080 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5082 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5083 HRESULT hr = S_OK;
5084 int i;
5086 TRACE("(%p/%p)->(%p)\n", iface, This, pClock);
5088 EnterCriticalSection(&This->cs);
5090 for (i = 0;i < This->nFilters;i++)
5092 hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5093 if (FAILED(hr))
5094 break;
5097 if (FAILED(hr))
5099 for(;i >= 0;i--)
5100 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5102 else
5104 if (This->refClock)
5105 IReferenceClock_Release(This->refClock);
5106 This->refClock = pClock;
5107 if (This->refClock)
5108 IReferenceClock_AddRef(This->refClock);
5110 if (This->HandleEcClockChanged)
5112 IMediaEventSink *pEventSink;
5113 HRESULT eshr;
5115 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (LPVOID)&pEventSink);
5116 if (SUCCEEDED(eshr))
5118 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5119 IMediaEventSink_Release(pEventSink);
5124 LeaveCriticalSection(&This->cs);
5126 return hr;
5129 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5131 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5133 TRACE("(%p/%p)->(%p)\n", iface, This, ppClock);
5135 if (!ppClock)
5136 return E_POINTER;
5138 EnterCriticalSection(&This->cs);
5140 *ppClock = This->refClock;
5141 if (*ppClock)
5142 IReferenceClock_AddRef(*ppClock);
5144 LeaveCriticalSection(&This->cs);
5146 return S_OK;
5149 static const IMediaFilterVtbl IMediaFilter_VTable =
5151 MediaFilter_QueryInterface,
5152 MediaFilter_AddRef,
5153 MediaFilter_Release,
5154 MediaFilter_GetClassID,
5155 MediaFilter_Stop,
5156 MediaFilter_Pause,
5157 MediaFilter_Run,
5158 MediaFilter_GetState,
5159 MediaFilter_SetSyncSource,
5160 MediaFilter_GetSyncSource
5163 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, LPVOID *ppv)
5165 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5167 return Filtergraph_QueryInterface(This, riid, ppv);
5170 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5172 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5174 return Filtergraph_AddRef(This);
5177 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5179 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5181 return Filtergraph_Release(This);
5184 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG EventCode, LONG_PTR EventParam1, LONG_PTR EventParam2)
5186 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5187 Event evt;
5189 TRACE("(%p/%p)->(%d, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5191 /* We need thread safety here, let's use the events queue's one */
5192 EnterCriticalSection(&This->evqueue.msg_crst);
5194 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5196 TRACE("Process EC_COMPLETE notification\n");
5197 if (++This->EcCompleteCount == This->nRenderers)
5199 evt.lEventCode = EC_COMPLETE;
5200 evt.lParam1 = S_OK;
5201 evt.lParam2 = 0;
5202 TRACE("Send EC_COMPLETE to app\n");
5203 EventsQueue_PutEvent(&This->evqueue, &evt);
5204 if (!This->notif.disabled && This->notif.hWnd)
5206 TRACE("Send Window message\n");
5207 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5209 This->CompletionStatus = EC_COMPLETE;
5210 SetEvent(This->hEventCompletion);
5213 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5215 /* FIXME: Not handled yet */
5217 else
5219 evt.lEventCode = EventCode;
5220 evt.lParam1 = EventParam1;
5221 evt.lParam2 = EventParam2;
5222 EventsQueue_PutEvent(&This->evqueue, &evt);
5223 if (!This->notif.disabled && This->notif.hWnd)
5224 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5227 LeaveCriticalSection(&This->evqueue.msg_crst);
5228 return S_OK;
5231 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5233 MediaEventSink_QueryInterface,
5234 MediaEventSink_AddRef,
5235 MediaEventSink_Release,
5236 MediaEventSink_Notify
5239 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, LPVOID *ppv)
5241 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5243 return Filtergraph_QueryInterface(This, riid, ppv);
5246 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5248 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5250 return Filtergraph_AddRef(This);
5253 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5255 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5257 return Filtergraph_Release(This);
5260 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface,
5261 IPin* pOutputPin,
5262 IPin* pInputPin,
5263 const AM_MEDIA_TYPE* pmtFirstConnection,
5264 IBaseFilter* pUsingFilter,
5265 HANDLE hAbortEvent,
5266 DWORD dwFlags)
5268 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5270 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5272 return E_NOTIMPL;
5275 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface,
5276 IGraphConfigCallback* pCallback,
5277 PVOID pvContext,
5278 DWORD dwFlags,
5279 HANDLE hAbortEvent)
5281 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5282 HRESULT hr;
5284 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5286 if (hAbortEvent)
5287 FIXME("The parameter hAbortEvent is not handled!\n");
5289 EnterCriticalSection(&This->cs);
5291 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5293 LeaveCriticalSection(&This->cs);
5295 return hr;
5298 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface,
5299 IBaseFilter* pFilter)
5301 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5303 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5305 return E_NOTIMPL;
5308 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface,
5309 IEnumFilters** pEnum)
5311 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5313 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5315 return E_NOTIMPL;
5318 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface,
5319 IBaseFilter* pFilter)
5321 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5323 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5325 return E_NOTIMPL;
5328 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface,
5329 REFERENCE_TIME* prtStart)
5331 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5333 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5335 return E_NOTIMPL;
5338 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface,
5339 IPin* pOutputPin,
5340 IPinConnection* pConnection,
5341 HANDLE hEventAbort)
5343 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5345 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5347 return E_NOTIMPL;
5350 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface,
5351 IBaseFilter* pFilter,
5352 DWORD dwFlags)
5354 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5356 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5358 return E_NOTIMPL;
5361 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface,
5362 IBaseFilter* pFilter,
5363 DWORD* dwFlags)
5365 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5367 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5369 return E_NOTIMPL;
5372 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface,
5373 IBaseFilter* pFilter,
5374 DWORD dwFlags)
5376 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5378 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5380 return E_NOTIMPL;
5383 static const IGraphConfigVtbl IGraphConfig_VTable =
5385 GraphConfig_QueryInterface,
5386 GraphConfig_AddRef,
5387 GraphConfig_Release,
5388 GraphConfig_Reconnect,
5389 GraphConfig_Reconfigure,
5390 GraphConfig_AddFilterToCache,
5391 GraphConfig_EnumCacheFilter,
5392 GraphConfig_RemoveFilterFromCache,
5393 GraphConfig_GetStartTime,
5394 GraphConfig_PushThroughData,
5395 GraphConfig_SetFilterFlags,
5396 GraphConfig_GetFilterFlags,
5397 GraphConfig_RemoveFilterEx
5400 static const IUnknownVtbl IInner_VTable =
5402 FilterGraphInner_QueryInterface,
5403 FilterGraphInner_AddRef,
5404 FilterGraphInner_Release
5407 static HRESULT Filtergraph_QueryInterface(IFilterGraphImpl *This,
5408 REFIID riid,
5409 LPVOID * ppv) {
5410 if (This->bAggregatable)
5411 This->bUnkOuterValid = TRUE;
5413 if (This->pUnkOuter)
5415 if (This->bAggregatable)
5416 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
5418 if (IsEqualIID(riid, &IID_IUnknown))
5420 HRESULT hr;
5422 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5423 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5424 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5425 This->bAggregatable = TRUE;
5426 return hr;
5429 *ppv = NULL;
5430 return E_NOINTERFACE;
5433 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5436 static ULONG Filtergraph_AddRef(IFilterGraphImpl *This) {
5437 if (This->pUnkOuter && This->bUnkOuterValid)
5438 return IUnknown_AddRef(This->pUnkOuter);
5439 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5442 static ULONG Filtergraph_Release(IFilterGraphImpl *This) {
5443 if (This->pUnkOuter && This->bUnkOuterValid)
5444 return IUnknown_Release(This->pUnkOuter);
5445 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5448 /* This is the only function that actually creates a FilterGraph class... */
5449 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5451 IFilterGraphImpl *fimpl;
5452 HRESULT hr;
5454 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5456 *ppObj = NULL;
5458 fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5459 fimpl->pUnkOuter = pUnkOuter;
5460 fimpl->bUnkOuterValid = FALSE;
5461 fimpl->bAggregatable = FALSE;
5462 fimpl->IInner_vtbl = &IInner_VTable;
5463 fimpl->IFilterGraph2_vtbl = &IFilterGraph2_VTable;
5464 fimpl->IMediaControl_vtbl = &IMediaControl_VTable;
5465 fimpl->IMediaSeeking_vtbl = &IMediaSeeking_VTable;
5466 fimpl->IBasicAudio_vtbl = &IBasicAudio_VTable;
5467 fimpl->IBasicVideo_vtbl = &IBasicVideo_VTable;
5468 fimpl->IVideoWindow_vtbl = &IVideoWindow_VTable;
5469 fimpl->IMediaEventEx_vtbl = &IMediaEventEx_VTable;
5470 fimpl->IMediaFilter_vtbl = &IMediaFilter_VTable;
5471 fimpl->IMediaEventSink_vtbl = &IMediaEventSink_VTable;
5472 fimpl->IGraphConfig_vtbl = &IGraphConfig_VTable;
5473 fimpl->IMediaPosition_vtbl = &IMediaPosition_VTable;
5474 fimpl->ref = 1;
5475 fimpl->ppFiltersInGraph = NULL;
5476 fimpl->pFilterNames = NULL;
5477 fimpl->nFilters = 0;
5478 fimpl->filterCapacity = 0;
5479 fimpl->nameIndex = 1;
5480 fimpl->refClock = NULL;
5481 fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5482 fimpl->HandleEcComplete = TRUE;
5483 fimpl->HandleEcRepaint = TRUE;
5484 fimpl->HandleEcClockChanged = TRUE;
5485 fimpl->notif.hWnd = 0;
5486 fimpl->notif.disabled = FALSE;
5487 fimpl->nRenderers = 0;
5488 fimpl->EcCompleteCount = 0;
5489 fimpl->state = State_Stopped;
5490 EventsQueue_Init(&fimpl->evqueue);
5491 InitializeCriticalSection(&fimpl->cs);
5492 fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5493 fimpl->nItfCacheEntries = 0;
5494 memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5495 fimpl->start_time = fimpl->position = 0;
5496 fimpl->stop_position = -1;
5497 fimpl->punkFilterMapper2 = NULL;
5498 fimpl->recursioncount = 0;
5500 /* create Filtermapper aggregated. */
5501 hr = CoCreateInstance(&CLSID_FilterMapper2, pUnkOuter ? pUnkOuter : (IUnknown*)&fimpl->IInner_vtbl, CLSCTX_INPROC_SERVER,
5502 &IID_IUnknown, (LPVOID*)&fimpl->punkFilterMapper2);
5504 if (SUCCEEDED(hr)) {
5505 hr = IUnknown_QueryInterface(fimpl->punkFilterMapper2, &IID_IFilterMapper2, (LPVOID*)&fimpl->pFilterMapper2);
5508 if (SUCCEEDED(hr)) {
5509 /* Release controlling IUnknown - compensate refcount increase from caching IFilterMapper2 interface. */
5510 if (pUnkOuter) IUnknown_Release(pUnkOuter);
5511 else IUnknown_Release((IUnknown*)&fimpl->IInner_vtbl);
5514 if (FAILED(hr)) {
5515 ERR("Unable to create filter mapper (%x)\n", hr);
5516 if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5517 CloseHandle(fimpl->hEventCompletion);
5518 EventsQueue_Destroy(&fimpl->evqueue);
5519 fimpl->cs.DebugInfo->Spare[0] = 0;
5520 DeleteCriticalSection(&fimpl->cs);
5521 CoTaskMemFree(fimpl);
5522 return hr;
5524 IFilterGraph2_SetDefaultSyncSource((IFilterGraph2*)fimpl);
5526 *ppObj = fimpl;
5527 return S_OK;
5530 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5532 FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5533 return FilterGraph_create(pUnkOuter, ppObj);