oleaut32: Convert CustData to use standard linked lists.
[wine.git] / dlls / quartz / filtergraph.c
blob05b6e47b4db5c191bb9358a753f83c6361508fc6
1 /* DirectShow FilterGraph object (QUARTZ.DLL)
3 * Copyright 2002 Lionel Ulmer
4 * Copyright 2004 Christian Costa
6 * This file contains the (internal) driver registration functions,
7 * driver enumeration APIs and DirectDraw creation functions.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
25 #include <stdarg.h>
27 #define COBJMACROS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "winreg.h"
33 #include "shlwapi.h"
34 #include "dshow.h"
35 #include "wine/debug.h"
36 #include "quartz_private.h"
37 #include "ole2.h"
38 #include "olectl.h"
39 #include "strmif.h"
40 #include "vfwmsgs.h"
41 #include "evcode.h"
42 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
47 typedef struct {
48 HWND hWnd; /* Target window */
49 UINT msg; /* User window message */
50 LONG_PTR instance; /* User data */
51 int disabled; /* Disabled messages posting */
52 } WndNotify;
54 typedef struct {
55 LONG lEventCode; /* Event code */
56 LONG_PTR lParam1; /* Param1 */
57 LONG_PTR lParam2; /* Param2 */
58 } Event;
60 /* messages ring implementation for queuing events (taken from winmm) */
61 #define EVENTS_RING_BUFFER_INCREMENT 64
62 typedef struct {
63 Event* messages;
64 int ring_buffer_size;
65 int msg_tosave;
66 int msg_toget;
67 CRITICAL_SECTION msg_crst;
68 HANDLE msg_event; /* Signaled for no empty queue */
69 } EventsQueue;
71 static int EventsQueue_Init(EventsQueue* omr)
73 omr->msg_toget = 0;
74 omr->msg_tosave = 0;
75 omr->msg_event = CreateEventW(NULL, TRUE, FALSE, NULL);
76 omr->ring_buffer_size = EVENTS_RING_BUFFER_INCREMENT;
77 omr->messages = CoTaskMemAlloc(omr->ring_buffer_size * sizeof(Event));
78 ZeroMemory(omr->messages, omr->ring_buffer_size * sizeof(Event));
80 InitializeCriticalSection(&omr->msg_crst);
81 omr->msg_crst.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": EventsQueue.msg_crst");
82 return TRUE;
85 static int EventsQueue_Destroy(EventsQueue* omr)
87 CloseHandle(omr->msg_event);
88 CoTaskMemFree(omr->messages);
89 omr->msg_crst.DebugInfo->Spare[0] = 0;
90 DeleteCriticalSection(&omr->msg_crst);
91 return TRUE;
94 static int EventsQueue_PutEvent(EventsQueue* omr, const Event* evt)
96 EnterCriticalSection(&omr->msg_crst);
97 if ((omr->msg_toget == ((omr->msg_tosave + 1) % omr->ring_buffer_size)))
99 int old_ring_buffer_size = omr->ring_buffer_size;
100 omr->ring_buffer_size += EVENTS_RING_BUFFER_INCREMENT;
101 TRACE("omr->ring_buffer_size=%d\n",omr->ring_buffer_size);
102 omr->messages = CoTaskMemRealloc(omr->messages, omr->ring_buffer_size * sizeof(Event));
103 /* Now we need to rearrange the ring buffer so that the new
104 buffers just allocated are in between omr->msg_tosave and
105 omr->msg_toget.
107 if (omr->msg_tosave < omr->msg_toget)
109 memmove(&(omr->messages[omr->msg_toget + EVENTS_RING_BUFFER_INCREMENT]),
110 &(omr->messages[omr->msg_toget]),
111 sizeof(Event)*(old_ring_buffer_size - omr->msg_toget)
113 omr->msg_toget += EVENTS_RING_BUFFER_INCREMENT;
116 omr->messages[omr->msg_tosave] = *evt;
117 SetEvent(omr->msg_event);
118 omr->msg_tosave = (omr->msg_tosave + 1) % omr->ring_buffer_size;
119 LeaveCriticalSection(&omr->msg_crst);
120 return TRUE;
123 static int EventsQueue_GetEvent(EventsQueue* omr, Event* evt, LONG msTimeOut)
125 if (WaitForSingleObject(omr->msg_event, msTimeOut) != WAIT_OBJECT_0)
126 return FALSE;
128 EnterCriticalSection(&omr->msg_crst);
130 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
132 LeaveCriticalSection(&omr->msg_crst);
133 return FALSE;
136 *evt = omr->messages[omr->msg_toget];
137 omr->msg_toget = (omr->msg_toget + 1) % omr->ring_buffer_size;
139 /* Mark the buffer as empty if needed */
140 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
141 ResetEvent(omr->msg_event);
143 LeaveCriticalSection(&omr->msg_crst);
144 return TRUE;
147 #define MAX_ITF_CACHE_ENTRIES 3
148 typedef struct _ITF_CACHE_ENTRY {
149 const IID* riid;
150 IBaseFilter* filter;
151 IUnknown* iface;
152 } ITF_CACHE_ENTRY;
154 typedef struct _IFilterGraphImpl {
155 const IFilterGraph2Vtbl *IFilterGraph2_vtbl;
156 const IMediaControlVtbl *IMediaControl_vtbl;
157 const IMediaSeekingVtbl *IMediaSeeking_vtbl;
158 const IBasicAudioVtbl *IBasicAudio_vtbl;
159 const IBasicVideo2Vtbl *IBasicVideo_vtbl;
160 const IVideoWindowVtbl *IVideoWindow_vtbl;
161 const IMediaEventExVtbl *IMediaEventEx_vtbl;
162 const IMediaFilterVtbl *IMediaFilter_vtbl;
163 const IMediaEventSinkVtbl *IMediaEventSink_vtbl;
164 const IGraphConfigVtbl *IGraphConfig_vtbl;
165 const IMediaPositionVtbl *IMediaPosition_vtbl;
166 const IUnknownVtbl * IInner_vtbl;
167 /* IAMGraphStreams */
168 /* IAMStats */
169 /* IFilterChain */
170 /* IFilterMapper2 */
171 /* IGraphVersion */
172 /* IQueueCommand */
173 /* IRegisterServiceProvider */
174 /* IResourceMananger */
175 /* IServiceProvider */
176 /* IVideoFrameStep */
178 LONG ref;
179 IUnknown *punkFilterMapper2;
180 IFilterMapper2 * pFilterMapper2;
181 IBaseFilter ** ppFiltersInGraph;
182 LPWSTR * pFilterNames;
183 int nFilters;
184 int filterCapacity;
185 LONG nameIndex;
186 IReferenceClock *refClock;
187 IBaseFilter *refClockProvider;
188 EventsQueue evqueue;
189 HANDLE hEventCompletion;
190 int CompletionStatus;
191 WndNotify notif;
192 int nRenderers;
193 int EcCompleteCount;
194 int HandleEcComplete;
195 int HandleEcRepaint;
196 int HandleEcClockChanged;
197 OAFilterState state;
198 CRITICAL_SECTION cs;
199 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
200 int nItfCacheEntries;
201 IUnknown * pUnkOuter;
202 BOOL bUnkOuterValid;
203 BOOL bAggregatable;
204 BOOL defaultclock;
205 GUID timeformatseek;
206 REFERENCE_TIME start_time;
207 REFERENCE_TIME pause_time;
208 LONGLONG stop_position;
209 LONG recursioncount;
210 } IFilterGraphImpl;
212 static HRESULT Filtergraph_QueryInterface(IFilterGraphImpl *This,
213 REFIID riid, LPVOID * ppv);
214 static ULONG Filtergraph_AddRef(IFilterGraphImpl *This);
215 static ULONG Filtergraph_Release(IFilterGraphImpl *This);
217 static HRESULT WINAPI FilterGraphInner_QueryInterface(IUnknown * iface,
218 REFIID riid,
219 LPVOID *ppvObj) {
220 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
221 TRACE("(%p)->(%s (%p), %p)\n", This, debugstr_guid(riid), riid, ppvObj);
223 if (This->bAggregatable)
224 This->bUnkOuterValid = TRUE;
226 if (IsEqualGUID(&IID_IUnknown, riid)) {
227 *ppvObj = &(This->IInner_vtbl);
228 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
229 } else if (IsEqualGUID(&IID_IFilterGraph, riid) ||
230 IsEqualGUID(&IID_IFilterGraph2, riid) ||
231 IsEqualGUID(&IID_IGraphBuilder, riid)) {
232 *ppvObj = &(This->IFilterGraph2_vtbl);
233 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj);
234 } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
235 *ppvObj = &(This->IMediaControl_vtbl);
236 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj);
237 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
238 *ppvObj = &(This->IMediaSeeking_vtbl);
239 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
240 } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
241 *ppvObj = &(This->IBasicAudio_vtbl);
242 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj);
243 } else if (IsEqualGUID(&IID_IBasicVideo, riid) ||
244 IsEqualGUID(&IID_IBasicVideo2, riid)) {
245 *ppvObj = &(This->IBasicVideo_vtbl);
246 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj);
247 } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
248 *ppvObj = &(This->IVideoWindow_vtbl);
249 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj);
250 } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
251 IsEqualGUID(&IID_IMediaEventEx, riid)) {
252 *ppvObj = &(This->IMediaEventEx_vtbl);
253 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
254 } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
255 IsEqualGUID(&IID_IPersist, riid)) {
256 *ppvObj = &(This->IMediaFilter_vtbl);
257 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj);
258 } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
259 *ppvObj = &(This->IMediaEventSink_vtbl);
260 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj);
261 } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
262 *ppvObj = &(This->IGraphConfig_vtbl);
263 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
264 } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
265 *ppvObj = &(This->IMediaPosition_vtbl);
266 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj);
267 } else if (IsEqualGUID(&IID_IFilterMapper, riid)) {
268 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj);
269 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
270 } else if (IsEqualGUID(&IID_IFilterMapper2, riid)) {
271 *ppvObj = This->pFilterMapper2;
272 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
273 } else if (IsEqualGUID(&IID_IFilterMapper3, riid)) {
274 *ppvObj = This->pFilterMapper2;
275 TRACE(" returning IFilterMapper3 interface from aggregated filtermapper (%p)\n", *ppvObj);
276 } else {
277 *ppvObj = NULL;
278 FIXME("unknown interface %s\n", debugstr_guid(riid));
279 return E_NOINTERFACE;
282 IUnknown_AddRef((IUnknown *)(*ppvObj));
283 return S_OK;
286 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown * iface) {
287 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
288 ULONG ref = InterlockedIncrement(&This->ref);
290 TRACE("(%p)->(): new ref = %d\n", This, ref);
292 return ref;
295 static ULONG WINAPI FilterGraphInner_Release(IUnknown * iface)
297 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
298 ULONG ref = InterlockedDecrement(&This->ref);
300 TRACE("(%p)->(): new ref = %d\n", This, ref);
302 if (ref == 0) {
303 int i;
305 This->ref = 1; /* guard against reentrancy (aggregation). */
307 IMediaControl_Stop((IMediaControl*)&(This->IMediaControl_vtbl));
309 while (This->nFilters)
310 IFilterGraph2_RemoveFilter((IFilterGraph2*)This, This->ppFiltersInGraph[0]);
312 if (This->refClock)
313 IReferenceClock_Release(This->refClock);
315 for (i = 0; i < This->nItfCacheEntries; i++)
317 if (This->ItfCacheEntries[i].iface)
318 IUnknown_Release(This->ItfCacheEntries[i].iface);
321 /* AddRef on controlling IUnknown, to compensate for Release of cached IFilterMapper2 interface below.
323 * NOTE: Filtergraph_AddRef isn't suitable, because bUnkOuterValid may be FALSE but punkOuter non-NULL
324 * and already passed as punkOuter to filtermapper in FilterGraph_create - this will happen in case of
325 * CoCreateInstance of filtergraph with non-null pUnkOuter and REFIID other than IID_Unknown that is
326 * cleaning up after error. */
327 if (This->pUnkOuter) IUnknown_AddRef(This->pUnkOuter);
328 else IUnknown_AddRef((IUnknown*)&This->IInner_vtbl);
330 IFilterMapper2_Release(This->pFilterMapper2);
331 IUnknown_Release(This->punkFilterMapper2);
333 CloseHandle(This->hEventCompletion);
334 EventsQueue_Destroy(&This->evqueue);
335 This->cs.DebugInfo->Spare[0] = 0;
336 DeleteCriticalSection(&This->cs);
337 CoTaskMemFree(This->ppFiltersInGraph);
338 CoTaskMemFree(This->pFilterNames);
339 CoTaskMemFree(This);
341 return ref;
345 /*** IUnknown methods ***/
346 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface,
347 REFIID riid,
348 LPVOID*ppvObj) {
349 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
351 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
352 return Filtergraph_QueryInterface(This, riid, ppvObj);
355 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface) {
356 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
358 TRACE("(%p/%p)->() calling FilterGraph AddRef\n", This, iface);
360 return Filtergraph_AddRef(This);
363 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface) {
364 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
366 TRACE("(%p/%p)->() calling FilterGraph Release\n", This, iface);
368 return Filtergraph_Release(This);
371 /*** IFilterGraph methods ***/
372 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface,
373 IBaseFilter *pFilter,
374 LPCWSTR pName) {
375 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
376 HRESULT hr;
377 int i,j;
378 WCHAR* wszFilterName = NULL;
379 int duplicate_name = FALSE;
381 TRACE("(%p/%p)->(%p, %s (%p))\n", This, iface, pFilter, debugstr_w(pName), pName);
383 if (!pFilter)
384 return E_POINTER;
386 wszFilterName = CoTaskMemAlloc( (pName ? strlenW(pName) + 6 : 5) * sizeof(WCHAR) );
388 if (pName)
390 /* Check if name already exists */
391 for(i = 0; i < This->nFilters; i++)
392 if (!strcmpW(This->pFilterNames[i], pName))
394 duplicate_name = TRUE;
395 break;
399 /* If no name given or name already existing, generate one */
400 if (!pName || duplicate_name)
402 static const WCHAR wszFmt1[] = {'%','s',' ','%','0','4','d',0};
403 static const WCHAR wszFmt2[] = {'%','0','4','d',0};
405 for (j = 0; j < 10000 ; j++)
407 /* Create name */
408 if (pName)
409 sprintfW(wszFilterName, wszFmt1, pName, This->nameIndex);
410 else
411 sprintfW(wszFilterName, wszFmt2, This->nameIndex);
412 TRACE("Generated name %s\n", debugstr_w(wszFilterName));
414 /* Check if the generated name already exists */
415 for(i = 0; i < This->nFilters; i++)
416 if (!strcmpW(This->pFilterNames[i], wszFilterName))
417 break;
419 /* Compute next index and exit if generated name is suitable */
420 if (This->nameIndex++ == 10000)
421 This->nameIndex = 1;
422 if (i == This->nFilters)
423 break;
425 /* Unable to find a suitable name */
426 if (j == 10000)
428 CoTaskMemFree(wszFilterName);
429 return VFW_E_DUPLICATE_NAME;
432 else
433 memcpy(wszFilterName, pName, (strlenW(pName) + 1) * sizeof(WCHAR));
435 if (This->nFilters + 1 > This->filterCapacity)
437 int newCapacity = This->filterCapacity ? 2 * This->filterCapacity : 1;
438 IBaseFilter ** ppNewFilters = CoTaskMemAlloc(newCapacity * sizeof(IBaseFilter*));
439 LPWSTR * pNewNames = CoTaskMemAlloc(newCapacity * sizeof(LPWSTR));
440 memcpy(ppNewFilters, This->ppFiltersInGraph, This->nFilters * sizeof(IBaseFilter*));
441 memcpy(pNewNames, This->pFilterNames, This->nFilters * sizeof(LPWSTR));
442 if (This->filterCapacity)
444 CoTaskMemFree(This->ppFiltersInGraph);
445 CoTaskMemFree(This->pFilterNames);
447 This->ppFiltersInGraph = ppNewFilters;
448 This->pFilterNames = pNewNames;
449 This->filterCapacity = newCapacity;
452 hr = IBaseFilter_JoinFilterGraph(pFilter, (IFilterGraph *)This, wszFilterName);
454 if (SUCCEEDED(hr))
456 IBaseFilter_AddRef(pFilter);
457 This->ppFiltersInGraph[This->nFilters] = pFilter;
458 This->pFilterNames[This->nFilters] = wszFilterName;
459 This->nFilters++;
460 IBaseFilter_SetSyncSource(pFilter, This->refClock);
462 else
463 CoTaskMemFree(wszFilterName);
465 if (SUCCEEDED(hr) && duplicate_name)
466 return VFW_S_DUPLICATE_NAME;
468 return hr;
471 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
473 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
474 int i;
475 HRESULT hr = E_FAIL;
477 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
479 /* FIXME: check graph is stopped */
481 for (i = 0; i < This->nFilters; i++)
483 if (This->ppFiltersInGraph[i] == pFilter)
485 IEnumPins *penumpins = NULL;
486 FILTER_STATE state;
488 if (This->defaultclock && This->refClockProvider == pFilter)
490 IMediaFilter_SetSyncSource((IMediaFilter*)&This->IMediaFilter_vtbl, NULL);
491 This->defaultclock = 1;
494 TRACE("Removing filter %s\n", debugstr_w(This->pFilterNames[i]));
495 IBaseFilter_GetState(pFilter, 0, &state);
496 if (state == State_Running)
497 IBaseFilter_Pause(pFilter);
498 if (state != State_Stopped)
499 IBaseFilter_Stop(pFilter);
501 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
502 if (SUCCEEDED(hr)) {
503 IPin *ppin;
504 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
506 IPin *victim = NULL;
507 HRESULT h;
508 IPin_ConnectedTo(ppin, &victim);
509 if (victim)
511 h = IPin_Disconnect(victim);
512 TRACE("Disconnect other side: %08x\n", h);
513 if (h == VFW_E_NOT_STOPPED)
515 PIN_INFO pinfo;
516 IPin_QueryPinInfo(victim, &pinfo);
518 IBaseFilter_GetState(pinfo.pFilter, 0, &state);
519 if (state == State_Running)
520 IBaseFilter_Pause(pinfo.pFilter);
521 IBaseFilter_Stop(pinfo.pFilter);
522 IBaseFilter_Release(pinfo.pFilter);
523 h = IPin_Disconnect(victim);
524 TRACE("Disconnect retry: %08x\n", h);
526 IPin_Release(victim);
528 h = IPin_Disconnect(ppin);
529 TRACE("Disconnect 2: %08x\n", h);
531 IPin_Release(ppin);
533 IEnumPins_Release(penumpins);
536 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, This->pFilterNames[i]);
537 if (SUCCEEDED(hr))
539 IBaseFilter_SetSyncSource(pFilter, NULL);
540 IBaseFilter_Release(pFilter);
541 CoTaskMemFree(This->pFilterNames[i]);
542 memmove(This->ppFiltersInGraph+i, This->ppFiltersInGraph+i+1, sizeof(IBaseFilter*)*(This->nFilters - 1 - i));
543 memmove(This->pFilterNames+i, This->pFilterNames+i+1, sizeof(LPWSTR)*(This->nFilters - 1 - i));
544 This->nFilters--;
545 /* Invalidate interfaces in the cache */
546 for (i = 0; i < This->nItfCacheEntries; i++)
547 if (pFilter == This->ItfCacheEntries[i].filter)
549 IUnknown_Release(This->ItfCacheEntries[i].iface);
550 This->ItfCacheEntries[i].iface = NULL;
551 This->ItfCacheEntries[i].filter = NULL;
553 return S_OK;
555 break;
559 return hr; /* FIXME: check this error code */
562 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface,
563 IEnumFilters **ppEnum) {
564 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
566 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
568 return IEnumFiltersImpl_Construct(This->ppFiltersInGraph, This->nFilters, ppEnum);
571 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface,
572 LPCWSTR pName,
573 IBaseFilter **ppFilter) {
574 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
575 int i;
577 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_w(pName), pName, ppFilter);
579 if (!ppFilter)
580 return E_POINTER;
582 for (i = 0; i < This->nFilters; i++)
584 if (!strcmpW(pName, This->pFilterNames[i]))
586 *ppFilter = This->ppFiltersInGraph[i];
587 IBaseFilter_AddRef(*ppFilter);
588 return S_OK;
592 *ppFilter = NULL;
593 return VFW_E_NOT_FOUND;
596 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
597 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
599 static HRESULT CheckCircularConnection(IFilterGraphImpl *This, IPin *out, IPin *in)
601 #if 1
602 HRESULT hr;
603 PIN_INFO info_out, info_in;
605 hr = IPin_QueryPinInfo(out, &info_out);
606 if (FAILED(hr))
607 return hr;
608 if (info_out.dir != PINDIR_OUTPUT)
610 IBaseFilter_Release(info_out.pFilter);
611 return E_UNEXPECTED;
614 hr = IPin_QueryPinInfo(in, &info_in);
615 if (SUCCEEDED(hr))
616 IBaseFilter_Release(info_in.pFilter);
617 if (FAILED(hr))
618 goto out;
619 if (info_in.dir != PINDIR_INPUT)
621 hr = E_UNEXPECTED;
622 goto out;
625 if (info_out.pFilter == info_in.pFilter)
626 hr = VFW_E_CIRCULAR_GRAPH;
627 else
629 IEnumPins *enumpins;
630 IPin *test;
632 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
633 if (FAILED(hr))
634 goto out;
636 IEnumPins_Reset(enumpins);
637 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
639 PIN_DIRECTION dir = PINDIR_OUTPUT;
640 IPin_QueryDirection(test, &dir);
641 if (dir == PINDIR_INPUT)
643 IPin *victim = NULL;
644 IPin_ConnectedTo(test, &victim);
645 if (victim)
647 hr = CheckCircularConnection(This, victim, in);
648 IPin_Release(victim);
649 if (FAILED(hr))
651 IPin_Release(test);
652 break;
656 IPin_Release(test);
658 IEnumPins_Release(enumpins);
661 out:
662 IBaseFilter_Release(info_out.pFilter);
663 if (FAILED(hr))
664 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
665 return hr;
666 #else
667 /* Debugging filtergraphs not enabled */
668 return S_OK;
669 #endif
673 /* NOTE: despite the implication, it doesn't matter which
674 * way round you put in the input and output pins */
675 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface,
676 IPin *ppinIn,
677 IPin *ppinOut,
678 const AM_MEDIA_TYPE *pmt) {
679 PIN_DIRECTION dir;
680 HRESULT hr;
682 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
684 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
686 /* FIXME: check pins are in graph */
688 if (TRACE_ON(quartz))
690 PIN_INFO PinInfo;
692 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
693 if (FAILED(hr))
694 return hr;
696 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
697 IBaseFilter_Release(PinInfo.pFilter);
699 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
700 if (FAILED(hr))
701 return hr;
703 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
704 IBaseFilter_Release(PinInfo.pFilter);
707 hr = IPin_QueryDirection(ppinIn, &dir);
708 if (SUCCEEDED(hr))
710 if (dir == PINDIR_INPUT)
712 hr = CheckCircularConnection(This, ppinOut, ppinIn);
713 if (SUCCEEDED(hr))
714 hr = IPin_Connect(ppinOut, ppinIn, pmt);
716 else
718 hr = CheckCircularConnection(This, ppinIn, ppinOut);
719 if (SUCCEEDED(hr))
720 hr = IPin_Connect(ppinIn, ppinOut, pmt);
724 return hr;
727 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface,
728 IPin *ppin) {
729 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
730 IPin *pConnectedTo = NULL;
731 HRESULT hr;
732 PIN_DIRECTION pindir;
734 IPin_QueryDirection(ppin, &pindir);
735 hr = IPin_ConnectedTo(ppin, &pConnectedTo);
736 if (FAILED(hr)) {
737 TRACE("Querying connected to failed: %x\n", hr);
738 return hr;
740 IPin_Disconnect(ppin);
741 IPin_Disconnect(pConnectedTo);
742 if (pindir == PINDIR_INPUT)
743 hr = IPin_Connect(pConnectedTo, ppin, NULL);
744 else
745 hr = IPin_Connect(ppin, pConnectedTo, NULL);
746 IPin_Release(pConnectedTo);
747 if (FAILED(hr))
748 WARN("Reconnecting pins failed, pins are not connected now..\n");
749 TRACE("(%p->%p) -- %p %p -> %x\n", iface, This, ppin, pConnectedTo, hr);
750 return hr;
753 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
755 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
757 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
759 if (!ppin)
760 return E_POINTER;
762 return IPin_Disconnect(ppin);
765 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface) {
766 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
767 IReferenceClock *pClock = NULL;
768 HRESULT hr = S_OK;
769 int i;
771 TRACE("(%p/%p)->() live sources not handled properly!\n", iface, This);
773 EnterCriticalSection(&This->cs);
775 for (i = 0; i < This->nFilters; ++i)
777 DWORD miscflags;
778 IAMFilterMiscFlags *flags = NULL;
779 IUnknown_QueryInterface(This->ppFiltersInGraph[i], &IID_IAMFilterMiscFlags, (void**)&flags);
780 if (!flags)
781 continue;
782 miscflags = IAMFilterMiscFlags_GetMiscFlags(flags);
783 IUnknown_Release(flags);
784 if (miscflags == AM_FILTER_MISC_FLAGS_IS_RENDERER)
785 IUnknown_QueryInterface(This->ppFiltersInGraph[i], &IID_IReferenceClock, (void**)&pClock);
786 if (pClock)
787 break;
790 if (!pClock)
792 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
793 This->refClockProvider = NULL;
795 else
796 This->refClockProvider = This->ppFiltersInGraph[i];
798 if (SUCCEEDED(hr))
800 hr = IMediaFilter_SetSyncSource((IMediaFilter*)&(This->IMediaFilter_vtbl), pClock);
801 This->defaultclock = TRUE;
802 IReferenceClock_Release(pClock);
804 LeaveCriticalSection(&This->cs);
806 return hr;
809 static HRESULT GetFilterInfo(IMoniker* pMoniker, GUID* pclsid, VARIANT* pvar)
811 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
812 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
813 IPropertyBag * pPropBagCat = NULL;
814 HRESULT hr;
816 VariantInit(pvar);
818 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
820 if (SUCCEEDED(hr))
821 hr = IPropertyBag_Read(pPropBagCat, wszClsidName, pvar, NULL);
823 if (SUCCEEDED(hr))
824 hr = CLSIDFromString(V_UNION(pvar, bstrVal), pclsid);
826 VariantClear(pvar);
828 if (SUCCEEDED(hr))
829 hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL);
831 if (SUCCEEDED(hr))
832 TRACE("Moniker = %s - %s\n", debugstr_guid(pclsid), debugstr_w(V_UNION(pvar, bstrVal)));
834 if (pPropBagCat)
835 IPropertyBag_Release(pPropBagCat);
837 return hr;
840 static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPin*** pppins, ULONG* pnb)
842 HRESULT hr;
843 ULONG nb = 0;
845 TRACE("(%p, %p, %p, %p)\n", pfilter, pinputpin, pppins, pnb);
846 hr = IPin_QueryInternalConnections(pinputpin, NULL, &nb);
847 if (hr == S_OK) {
848 /* Rendered input */
849 } else if (hr == S_FALSE) {
850 *pppins = CoTaskMemAlloc(sizeof(IPin*)*nb);
851 hr = IPin_QueryInternalConnections(pinputpin, *pppins, &nb);
852 if (hr != S_OK) {
853 WARN("Error (%x)\n", hr);
855 } else if (hr == E_NOTIMPL) {
856 /* Input connected to all outputs */
857 IEnumPins* penumpins;
858 IPin* ppin;
859 int i = 0;
860 TRACE("E_NOTIMPL\n");
861 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
862 if (FAILED(hr)) {
863 WARN("filter Enumpins failed (%x)\n", hr);
864 return hr;
866 i = 0;
867 /* Count output pins */
868 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
869 PIN_DIRECTION pindir;
870 IPin_QueryDirection(ppin, &pindir);
871 if (pindir == PINDIR_OUTPUT)
872 i++;
873 IPin_Release(ppin);
875 *pppins = CoTaskMemAlloc(sizeof(IPin*)*i);
876 /* Retrieve output pins */
877 IEnumPins_Reset(penumpins);
878 i = 0;
879 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
880 PIN_DIRECTION pindir;
881 IPin_QueryDirection(ppin, &pindir);
882 if (pindir == PINDIR_OUTPUT)
883 (*pppins)[i++] = ppin;
884 else
885 IPin_Release(ppin);
887 IEnumPins_Release(penumpins);
888 nb = i;
889 if (FAILED(hr)) {
890 WARN("Next failed (%x)\n", hr);
891 return hr;
893 } else if (FAILED(hr)) {
894 WARN("Cannot get internal connection (%x)\n", hr);
895 return hr;
898 *pnb = nb;
899 return S_OK;
902 /*** IGraphBuilder methods ***/
903 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IPin *ppinIn)
905 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
906 HRESULT hr;
907 AM_MEDIA_TYPE* mt = NULL;
908 IEnumMediaTypes* penummt = NULL;
909 ULONG nbmt;
910 IEnumPins* penumpins;
911 IEnumMoniker* pEnumMoniker;
912 GUID tab[2];
913 ULONG nb;
914 IMoniker* pMoniker;
915 ULONG pin;
916 PIN_INFO PinInfo;
917 CLSID FilterCLSID;
918 PIN_DIRECTION dir;
920 TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
922 if (TRACE_ON(quartz))
924 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
925 if (FAILED(hr))
926 return hr;
928 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
929 IBaseFilter_Release(PinInfo.pFilter);
931 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
932 if (FAILED(hr))
933 return hr;
935 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
936 IBaseFilter_Release(PinInfo.pFilter);
939 EnterCriticalSection(&This->cs);
940 ++This->recursioncount;
941 if (This->recursioncount >= 5)
943 WARN("Recursion count has reached %d\n", This->recursioncount);
944 hr = VFW_E_CANNOT_CONNECT;
945 goto out;
948 hr = IPin_QueryDirection(ppinOut, &dir);
949 if (FAILED(hr))
950 goto out;
952 if (dir == PINDIR_INPUT)
954 IPin *temp;
956 temp = ppinIn;
957 ppinIn = ppinOut;
958 ppinOut = temp;
961 hr = CheckCircularConnection(This, ppinOut, ppinIn);
962 if (FAILED(hr))
963 goto out;
965 /* Try direct connection first */
966 hr = IPin_Connect(ppinOut, ppinIn, NULL);
967 if (SUCCEEDED(hr))
968 goto out;
970 TRACE("Direct connection failed, trying to render using extra filters\n");
972 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
973 if (FAILED(hr))
974 goto out;
976 hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
977 IBaseFilter_Release(PinInfo.pFilter);
978 if (FAILED(hr))
979 goto out;
981 /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream
982 * filter to the minor mediatype of input pin of the renderer */
983 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
984 if (FAILED(hr))
986 WARN("EnumMediaTypes (%x)\n", hr);
987 goto out;
990 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
991 if (FAILED(hr)) {
992 WARN("IEnumMediaTypes_Next (%x)\n", hr);
993 goto out;
996 if (!nbmt)
998 WARN("No media type found!\n");
999 hr = VFW_E_INVALIDMEDIATYPE;
1000 goto out;
1002 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1003 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1005 /* Try to find a suitable filter that can connect to the pin to render */
1006 tab[0] = mt->majortype;
1007 tab[1] = mt->subtype;
1008 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1009 if (FAILED(hr)) {
1010 WARN("Unable to enum filters (%x)\n", hr);
1011 goto out;
1014 hr = VFW_E_CANNOT_RENDER;
1015 while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1017 VARIANT var;
1018 GUID clsid;
1019 IPin** ppins;
1020 IPin* ppinfilter = NULL;
1021 IBaseFilter* pfilter = NULL;
1023 hr = GetFilterInfo(pMoniker, &clsid, &var);
1024 IMoniker_Release(pMoniker);
1025 if (FAILED(hr)) {
1026 WARN("Unable to retrieve filter info (%x)\n", hr);
1027 goto error;
1030 if (IsEqualGUID(&clsid, &FilterCLSID)) {
1031 /* Skip filter (same as the one the output pin belongs to) */
1032 goto error;
1035 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
1036 if (FAILED(hr)) {
1037 WARN("Unable to create filter (%x), trying next one\n", hr);
1038 goto error;
1041 hr = IFilterGraph2_AddFilter(iface, pfilter, V_UNION(&var, bstrVal));
1042 if (FAILED(hr)) {
1043 WARN("Unable to add filter (%x)\n", hr);
1044 IBaseFilter_Release(pfilter);
1045 pfilter = NULL;
1046 goto error;
1049 VariantClear(&var);
1051 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1052 if (FAILED(hr)) {
1053 WARN("Enumpins (%x)\n", hr);
1054 goto error;
1057 hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin);
1058 IEnumPins_Release(penumpins);
1060 if (FAILED(hr)) {
1061 WARN("Obtaining next pin: (%x)\n", hr);
1062 goto error;
1064 if (pin == 0) {
1065 WARN("Cannot use this filter: no pins\n");
1066 goto error;
1069 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1070 if (FAILED(hr)) {
1071 TRACE("Cannot connect to filter (%x), trying next one\n", hr);
1072 goto error;
1074 TRACE("Successfully connected to filter, follow chain...\n");
1076 /* Render all output pins of the filter by calling IFilterGraph2_Connect on each of them */
1077 hr = GetInternalConnections(pfilter, ppinfilter, &ppins, &nb);
1079 if (SUCCEEDED(hr)) {
1080 unsigned int i;
1081 if (nb == 0) {
1082 IPin_Disconnect(ppinfilter);
1083 IPin_Disconnect(ppinOut);
1084 goto error;
1086 TRACE("pins to consider: %d\n", nb);
1087 for(i = 0; i < nb; i++)
1089 LPWSTR pinname = NULL;
1091 TRACE("Processing pin %u\n", i);
1093 hr = IPin_QueryId(ppins[i], &pinname);
1094 if (SUCCEEDED(hr))
1096 if (pinname[0] == '~')
1098 TRACE("Pinname=%s, skipping\n", debugstr_w(pinname));
1099 hr = E_FAIL;
1101 else
1102 hr = IFilterGraph2_Connect(iface, ppins[i], ppinIn);
1103 CoTaskMemFree(pinname);
1106 if (FAILED(hr)) {
1107 TRACE("Cannot connect pin %p (%x)\n", ppinfilter, hr);
1109 IPin_Release(ppins[i]);
1110 if (SUCCEEDED(hr)) break;
1112 while (++i < nb) IPin_Release(ppins[i]);
1113 CoTaskMemFree(ppins);
1114 IPin_Release(ppinfilter);
1115 IBaseFilter_Release(pfilter);
1116 if (FAILED(hr))
1118 IPin_Disconnect(ppinfilter);
1119 IPin_Disconnect(ppinOut);
1120 IFilterGraph2_RemoveFilter(iface, pfilter);
1121 continue;
1123 break;
1126 error:
1127 VariantClear(&var);
1128 if (ppinfilter) IPin_Release(ppinfilter);
1129 if (pfilter) {
1130 IFilterGraph2_RemoveFilter(iface, pfilter);
1131 IBaseFilter_Release(pfilter);
1135 out:
1136 if (penummt)
1137 IEnumMediaTypes_Release(penummt);
1138 if (mt)
1139 DeleteMediaType(mt);
1140 --This->recursioncount;
1141 LeaveCriticalSection(&This->cs);
1142 TRACE("--> %08x\n", hr);
1143 return SUCCEEDED(hr) ? S_OK : hr;
1146 static HRESULT FilterGraph2_RenderRecurse(IFilterGraphImpl *This, IPin *ppinOut)
1148 /* This pin has been connected now, try to call render on all pins that aren't connected */
1149 IPin *to = NULL;
1150 PIN_INFO info;
1151 IEnumPins *enumpins = NULL;
1152 BOOL renderany = FALSE;
1153 BOOL renderall = TRUE;
1155 IPin_QueryPinInfo(ppinOut, &info);
1157 IBaseFilter_EnumPins(info.pFilter, &enumpins);
1158 /* Don't need to hold a reference, IEnumPins does */
1159 IBaseFilter_Release(info.pFilter);
1161 IEnumPins_Reset(enumpins);
1162 while (IEnumPins_Next(enumpins, 1, &to, NULL) == S_OK)
1164 PIN_DIRECTION dir = PINDIR_INPUT;
1166 IPin_QueryDirection(to, &dir);
1168 if (dir == PINDIR_OUTPUT)
1170 IPin *out = NULL;
1172 IPin_ConnectedTo(to, &out);
1173 if (!out)
1175 HRESULT hr;
1176 hr = IFilterGraph2_Render((IFilterGraph2 *)&This->IFilterGraph2_vtbl, to);
1177 if (SUCCEEDED(hr))
1178 renderany = TRUE;
1179 else
1180 renderall = FALSE;
1182 else
1183 IPin_Release(out);
1186 IPin_Release(to);
1189 IEnumPins_Release(enumpins);
1191 if (renderall)
1192 return S_OK;
1194 if (renderany)
1195 return VFW_S_PARTIAL_RENDER;
1197 return VFW_E_CANNOT_RENDER;
1200 /* Ogg hates me if I create a direct rendering method
1202 * It can only connect to a pin properly once, so use a recursive method that does
1204 * +----+ --- (PIN 1) (Render is called on this pin)
1205 * | |
1206 * +----+ --- (PIN 2)
1208 * Enumerate possible renderers that EXACTLY match the requested type
1210 * If none is available, try to add intermediate filters that can connect to the input pin
1211 * then call Render on that intermediate pin's output pins
1212 * if it succeeds: Render returns success, if it doesn't, the intermediate filter is removed,
1213 * and another filter that can connect to the input pin is tried
1214 * if we run out of filters that can, give up and return VFW_E_CANNOT_RENDER
1215 * It's recursive, but fun!
1218 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *ppinOut)
1220 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1221 IEnumMediaTypes* penummt;
1222 AM_MEDIA_TYPE* mt;
1223 ULONG nbmt;
1224 HRESULT hr;
1226 IEnumMoniker* pEnumMoniker;
1227 GUID tab[4];
1228 ULONG nb;
1229 IMoniker* pMoniker;
1230 INT x;
1232 TRACE("(%p/%p)->(%p)\n", This, iface, ppinOut);
1234 if (TRACE_ON(quartz))
1236 PIN_INFO PinInfo;
1238 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
1239 if (FAILED(hr))
1240 return hr;
1242 TRACE("Filter owning pin => %p\n", PinInfo.pFilter);
1243 IBaseFilter_Release(PinInfo.pFilter);
1246 /* Try to find out if there is a renderer for the specified subtype already, and use that
1248 EnterCriticalSection(&This->cs);
1249 for (x = 0; x < This->nFilters; ++x)
1251 IEnumPins *enumpins = NULL;
1252 IPin *pin = NULL;
1254 hr = IBaseFilter_EnumPins(This->ppFiltersInGraph[x], &enumpins);
1256 if (FAILED(hr) || !enumpins)
1257 continue;
1259 IEnumPins_Reset(enumpins);
1260 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
1262 IPin *to = NULL;
1263 PIN_DIRECTION dir = PINDIR_OUTPUT;
1265 IPin_QueryDirection(pin, &dir);
1266 if (dir != PINDIR_INPUT)
1268 IPin_Release(pin);
1269 continue;
1271 IPin_ConnectedTo(pin, &to);
1273 if (to == NULL)
1275 hr = FilterGraph2_ConnectDirect(iface, ppinOut, pin, NULL);
1276 if (SUCCEEDED(hr))
1278 TRACE("Connected successfully %p/%p, %08x look if we should render more!\n", ppinOut, pin, hr);
1279 IPin_Release(pin);
1281 hr = FilterGraph2_RenderRecurse(This, pin);
1282 if (FAILED(hr))
1284 IPin_Disconnect(ppinOut);
1285 IPin_Disconnect(pin);
1286 continue;
1288 IEnumPins_Release(enumpins);
1289 LeaveCriticalSection(&This->cs);
1290 return hr;
1292 WARN("Could not connect!\n");
1294 else
1295 IPin_Release(to);
1297 IPin_Release(pin);
1299 IEnumPins_Release(enumpins);
1302 LeaveCriticalSection(&This->cs);
1304 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
1305 if (FAILED(hr)) {
1306 WARN("EnumMediaTypes (%x)\n", hr);
1307 return hr;
1310 IEnumMediaTypes_Reset(penummt);
1312 /* Looks like no existing renderer of the kind exists
1313 * Try adding new ones
1315 tab[0] = tab[1] = GUID_NULL;
1316 while (SUCCEEDED(hr))
1318 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
1319 if (FAILED(hr)) {
1320 WARN("IEnumMediaTypes_Next (%x)\n", hr);
1321 break;
1323 if (!nbmt)
1325 hr = VFW_E_CANNOT_RENDER;
1326 break;
1328 else
1330 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1331 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1333 /* Only enumerate once, this doesn't account for all previous ones, but this should be enough nonetheless */
1334 if (IsEqualIID(&tab[0], &mt->majortype) && IsEqualIID(&tab[1], &mt->subtype))
1336 DeleteMediaType(mt);
1337 continue;
1340 /* Try to find a suitable renderer with the same media type */
1341 tab[0] = mt->majortype;
1342 tab[1] = mt->subtype;
1343 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1344 if (FAILED(hr))
1346 WARN("Unable to enum filters (%x)\n", hr);
1347 break;
1350 hr = E_FAIL;
1352 while (IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1354 VARIANT var;
1355 GUID clsid;
1356 IPin* ppinfilter;
1357 IBaseFilter* pfilter = NULL;
1358 IEnumPins* penumpins = NULL;
1359 ULONG pin;
1361 hr = GetFilterInfo(pMoniker, &clsid, &var);
1362 IMoniker_Release(pMoniker);
1363 if (FAILED(hr)) {
1364 WARN("Unable to retrieve filter info (%x)\n", hr);
1365 goto error;
1368 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
1369 if (FAILED(hr))
1371 WARN("Unable to create filter (%x), trying next one\n", hr);
1372 goto error;
1375 hr = IFilterGraph2_AddFilter(iface, pfilter, V_UNION(&var, bstrVal));
1376 if (FAILED(hr)) {
1377 WARN("Unable to add filter (%x)\n", hr);
1378 IBaseFilter_Release(pfilter);
1379 pfilter = NULL;
1380 goto error;
1383 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1384 if (FAILED(hr)) {
1385 WARN("Splitter Enumpins (%x)\n", hr);
1386 goto error;
1389 while ((hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin)) == S_OK)
1391 PIN_DIRECTION dir;
1393 if (pin == 0) {
1394 WARN("No Pin\n");
1395 hr = E_FAIL;
1396 goto error;
1399 hr = IPin_QueryDirection(ppinfilter, &dir);
1400 if (FAILED(hr)) {
1401 IPin_Release(ppinfilter);
1402 WARN("QueryDirection failed (%x)\n", hr);
1403 goto error;
1405 if (dir != PINDIR_INPUT) {
1406 IPin_Release(ppinfilter);
1407 continue; /* Wrong direction */
1410 /* Connect the pin to the "Renderer" */
1411 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1412 IPin_Release(ppinfilter);
1414 if (FAILED(hr)) {
1415 WARN("Unable to connect %s to renderer (%x)\n", debugstr_w(V_UNION(&var, bstrVal)), hr);
1416 goto error;
1418 TRACE("Connected, recursing %s\n", debugstr_w(V_UNION(&var, bstrVal)));
1420 VariantClear(&var);
1422 hr = FilterGraph2_RenderRecurse(This, ppinfilter);
1423 if (FAILED(hr)) {
1424 WARN("Unable to connect recursively (%x)\n", hr);
1425 goto error;
1427 IBaseFilter_Release(pfilter);
1428 break;
1430 if (SUCCEEDED(hr)) {
1431 IEnumPins_Release(penumpins);
1432 break; /* out of IEnumMoniker_Next loop */
1435 /* IEnumPins_Next failed, all other failure case caught by goto error */
1436 WARN("IEnumPins_Next (%x)\n", hr);
1437 /* goto error */
1439 error:
1440 VariantClear(&var);
1441 if (penumpins)
1442 IEnumPins_Release(penumpins);
1443 if (pfilter) {
1444 IFilterGraph2_RemoveFilter(iface, pfilter);
1445 IBaseFilter_Release(pfilter);
1447 if (SUCCEEDED(hr)) DebugBreak();
1450 IEnumMoniker_Release(pEnumMoniker);
1451 if (nbmt)
1452 DeleteMediaType(mt);
1453 if (SUCCEEDED(hr))
1454 break;
1455 hr = S_OK;
1458 IEnumMediaTypes_Release(penummt);
1459 return hr;
1462 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface,
1463 LPCWSTR lpcwstrFile,
1464 LPCWSTR lpcwstrPlayList)
1466 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1467 static const WCHAR string[] = {'R','e','a','d','e','r',0};
1468 IBaseFilter* preader = NULL;
1469 IPin* ppinreader = NULL;
1470 IEnumPins* penumpins = NULL;
1471 HRESULT hr;
1472 BOOL partial = FALSE;
1473 HRESULT any = FALSE;
1475 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1477 if (lpcwstrPlayList != NULL)
1478 return E_INVALIDARG;
1480 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, string, &preader);
1481 if (FAILED(hr))
1482 return hr;
1484 if (SUCCEEDED(hr))
1485 hr = IBaseFilter_EnumPins(preader, &penumpins);
1486 if (SUCCEEDED(hr))
1488 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1490 PIN_DIRECTION dir;
1492 IPin_QueryDirection(ppinreader, &dir);
1493 if (dir == PINDIR_OUTPUT)
1495 INT i;
1497 hr = IFilterGraph2_Render(iface, ppinreader);
1498 TRACE("Render %08x\n", hr);
1500 for (i = 0; i < This->nFilters; ++i)
1501 TRACE("Filters in chain: %s\n", debugstr_w(This->pFilterNames[i]));
1503 if (SUCCEEDED(hr))
1504 any = TRUE;
1505 if (hr != S_OK)
1506 partial = TRUE;
1508 IPin_Release(ppinreader);
1510 IEnumPins_Release(penumpins);
1512 if (!any)
1513 hr = VFW_E_CANNOT_RENDER;
1514 else if (partial)
1515 hr = VFW_S_PARTIAL_RENDER;
1516 else
1517 hr = S_OK;
1519 IBaseFilter_Release(preader);
1521 TRACE("--> %08x\n", hr);
1522 return hr;
1525 /* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
1526 static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
1528 static const WCHAR wszReg[] = {'M','e','d','i','a',' ','T','y','p','e','\\','E','x','t','e','n','s','i','o','n','s',0};
1529 HRESULT hr = S_OK;
1530 HKEY extkey;
1531 LONG lRet;
1533 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszReg, 0, KEY_READ, &extkey);
1534 hr = HRESULT_FROM_WIN32(lRet);
1536 if (SUCCEEDED(hr))
1538 static const WCHAR filtersource[] = {'S','o','u','r','c','e',' ','F','i','l','t','e','r',0};
1539 WCHAR *ext = PathFindExtensionW(pszFileName);
1540 WCHAR clsid_key[39];
1541 GUID clsid;
1542 DWORD size = sizeof(clsid_key);
1543 HKEY pathkey;
1545 if (!ext)
1547 CloseHandle(extkey);
1548 return E_FAIL;
1551 lRet = RegOpenKeyExW(extkey, ext, 0, KEY_READ, &pathkey);
1552 hr = HRESULT_FROM_WIN32(lRet);
1553 CloseHandle(extkey);
1554 if (FAILED(hr))
1555 return hr;
1557 lRet = RegQueryValueExW(pathkey, filtersource, NULL, NULL, (LPBYTE)clsid_key, &size);
1558 hr = HRESULT_FROM_WIN32(lRet);
1559 CloseHandle(pathkey);
1560 if (FAILED(hr))
1561 return hr;
1563 CLSIDFromString(clsid_key, &clsid);
1565 TRACE("CLSID: %s\n", debugstr_guid(&clsid));
1566 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1567 if (SUCCEEDED(hr))
1569 IFileSourceFilter *source = NULL;
1570 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID*)&source);
1571 if (SUCCEEDED(hr))
1572 IFileSourceFilter_Release(source);
1573 else
1574 IBaseFilter_Release(*filter);
1577 if (FAILED(hr))
1578 *filter = NULL;
1579 return hr;
1582 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface,
1583 LPCWSTR lpcwstrFileName,
1584 LPCWSTR lpcwstrFilterName,
1585 IBaseFilter **ppFilter) {
1586 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1587 HRESULT hr;
1588 IBaseFilter* preader;
1589 IFileSourceFilter* pfile = NULL;
1590 AM_MEDIA_TYPE mt;
1591 WCHAR* filename;
1593 TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1595 /* Try from file name first, then fall back to default asynchronous reader */
1596 hr = GetFileSourceFilter(lpcwstrFileName, &preader);
1598 if (FAILED(hr))
1599 hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&preader);
1600 if (FAILED(hr)) {
1601 WARN("Unable to create file source filter (%x)\n", hr);
1602 return hr;
1605 hr = IFilterGraph2_AddFilter(iface, preader, lpcwstrFilterName);
1606 if (FAILED(hr)) {
1607 WARN("Unable add filter (%x)\n", hr);
1608 IBaseFilter_Release(preader);
1609 return hr;
1612 hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1613 if (FAILED(hr)) {
1614 WARN("Unable to get IFileSourceInterface (%x)\n", hr);
1615 goto error;
1618 /* Load the file in the file source filter */
1619 hr = IFileSourceFilter_Load(pfile, lpcwstrFileName, NULL);
1620 if (FAILED(hr)) {
1621 WARN("Load (%x)\n", hr);
1622 goto error;
1625 IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1626 if (FAILED(hr)) {
1627 WARN("GetCurFile (%x)\n", hr);
1628 goto error;
1631 TRACE("File %s\n", debugstr_w(filename));
1632 TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
1633 TRACE("SubType %s\n", debugstr_guid(&mt.subtype));
1635 if (ppFilter)
1636 *ppFilter = preader;
1637 IFileSourceFilter_Release(pfile);
1639 return S_OK;
1641 error:
1642 if (pfile)
1643 IFileSourceFilter_Release(pfile);
1644 IFilterGraph2_RemoveFilter(iface, preader);
1645 IBaseFilter_Release(preader);
1647 return hr;
1650 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface,
1651 DWORD_PTR hFile) {
1652 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1654 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1656 return S_OK;
1659 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface) {
1660 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1662 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1664 return S_OK;
1667 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface) {
1668 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1670 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1672 return S_OK;
1675 /*** IFilterGraph2 methods ***/
1676 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1677 IMoniker *pMoniker,
1678 IBindCtx *pCtx,
1679 LPCWSTR lpcwstrFilterName,
1680 IBaseFilter **ppFilter) {
1681 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1683 TRACE("(%p/%p)->(%p %p %s %p): stub !!!\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1685 return S_OK;
1688 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface,
1689 IPin *ppin,
1690 const AM_MEDIA_TYPE *pmt) {
1691 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1693 TRACE("(%p/%p)->(%p %p): stub !!!\n", This, iface, ppin, pmt);
1695 return S_OK;
1698 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface,
1699 IPin *pPinOut,
1700 DWORD dwFlags,
1701 DWORD *pvContext) {
1702 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1704 TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This, iface, pPinOut, dwFlags, pvContext);
1706 return S_OK;
1710 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1712 FilterGraph2_QueryInterface,
1713 FilterGraph2_AddRef,
1714 FilterGraph2_Release,
1715 FilterGraph2_AddFilter,
1716 FilterGraph2_RemoveFilter,
1717 FilterGraph2_EnumFilters,
1718 FilterGraph2_FindFilterByName,
1719 FilterGraph2_ConnectDirect,
1720 FilterGraph2_Reconnect,
1721 FilterGraph2_Disconnect,
1722 FilterGraph2_SetDefaultSyncSource,
1723 FilterGraph2_Connect,
1724 FilterGraph2_Render,
1725 FilterGraph2_RenderFile,
1726 FilterGraph2_AddSourceFilter,
1727 FilterGraph2_SetLogFile,
1728 FilterGraph2_Abort,
1729 FilterGraph2_ShouldOperationContinue,
1730 FilterGraph2_AddSourceFilterForMoniker,
1731 FilterGraph2_ReconnectEx,
1732 FilterGraph2_RenderEx
1735 /*** IUnknown methods ***/
1736 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface,
1737 REFIID riid,
1738 LPVOID*ppvObj) {
1739 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1741 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1743 return Filtergraph_QueryInterface(This, riid, ppvObj);
1746 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface) {
1747 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1749 TRACE("(%p/%p)->()\n", This, iface);
1751 return Filtergraph_AddRef(This);
1754 static ULONG WINAPI MediaControl_Release(IMediaControl *iface) {
1755 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1757 TRACE("(%p/%p)->()\n", This, iface);
1759 return Filtergraph_Release(This);
1763 /*** IDispatch methods ***/
1764 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface,
1765 UINT*pctinfo) {
1766 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1768 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1770 return S_OK;
1773 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface,
1774 UINT iTInfo,
1775 LCID lcid,
1776 ITypeInfo**ppTInfo) {
1777 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1779 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1781 return S_OK;
1784 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface,
1785 REFIID riid,
1786 LPOLESTR*rgszNames,
1787 UINT cNames,
1788 LCID lcid,
1789 DISPID*rgDispId) {
1790 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1792 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1794 return S_OK;
1797 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface,
1798 DISPID dispIdMember,
1799 REFIID riid,
1800 LCID lcid,
1801 WORD wFlags,
1802 DISPPARAMS*pDispParams,
1803 VARIANT*pVarResult,
1804 EXCEPINFO*pExepInfo,
1805 UINT*puArgErr) {
1806 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1808 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);
1810 return S_OK;
1813 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *, DWORD_PTR data);
1815 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter, DWORD_PTR data)
1817 HRESULT hr;
1818 IPin* pInputPin;
1819 IPin** ppPins;
1820 ULONG nb;
1821 ULONG i;
1822 PIN_INFO PinInfo;
1824 TRACE("%p %p\n", pGraph, pOutputPin);
1825 PinInfo.pFilter = NULL;
1827 hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1829 if (SUCCEEDED(hr))
1831 hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1832 if (SUCCEEDED(hr))
1833 hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1834 IPin_Release(pInputPin);
1837 if (SUCCEEDED(hr))
1839 if (nb == 0)
1841 TRACE("Reached a renderer\n");
1842 /* Count renderers for end of stream notification */
1843 pGraph->nRenderers++;
1845 else
1847 for(i = 0; i < nb; i++)
1849 /* Explore the graph downstream from this pin
1850 * FIXME: We should prevent exploring from a pin more than once. This can happens when
1851 * several input pins are connected to the same output (a MUX for instance). */
1852 ExploreGraph(pGraph, ppPins[i], FoundFilter, data);
1853 IPin_Release(ppPins[i]);
1856 CoTaskMemFree(ppPins);
1858 TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1860 FoundFilter(PinInfo.pFilter, data);
1863 if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1864 return hr;
1867 static HRESULT WINAPI SendRun(IBaseFilter *pFilter, DWORD_PTR data)
1869 REFERENCE_TIME time = *(REFERENCE_TIME*)data;
1870 return IBaseFilter_Run(pFilter, time);
1873 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1875 return IBaseFilter_Pause(pFilter);
1878 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1880 return IBaseFilter_Stop(pFilter);
1883 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1885 FILTER_STATE state;
1886 DWORD time_end = data;
1887 DWORD time_now = GetTickCount();
1888 LONG wait;
1890 if (time_end == INFINITE)
1892 wait = INFINITE;
1894 else if (time_end > time_now)
1896 wait = time_end - time_now;
1898 else
1899 wait = 0;
1901 return IBaseFilter_GetState(pFilter, wait, &state);
1905 static HRESULT SendFilterMessage(IMediaControl *iface, fnFoundFilter FoundFilter, DWORD_PTR data)
1907 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1908 int i;
1909 IBaseFilter* pfilter;
1910 IEnumPins* pEnum;
1911 HRESULT hr;
1912 IPin* pPin;
1913 DWORD dummy;
1914 PIN_DIRECTION dir;
1915 TRACE("(%p/%p)->()\n", This, iface);
1917 /* Explorer the graph from source filters to renderers, determine renderers
1918 * number and run filters from renderers to source filters */
1919 This->nRenderers = 0;
1920 ResetEvent(This->hEventCompletion);
1922 for(i = 0; i < This->nFilters; i++)
1924 BOOL source = TRUE;
1925 pfilter = This->ppFiltersInGraph[i];
1926 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
1927 if (hr != S_OK)
1929 WARN("Enum pins failed %x\n", hr);
1930 continue;
1932 /* Check if it is a source filter */
1933 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1935 IPin_QueryDirection(pPin, &dir);
1936 IPin_Release(pPin);
1937 if (dir == PINDIR_INPUT)
1939 source = FALSE;
1940 break;
1943 if (source)
1945 TRACE("Found a source filter %p\n", pfilter);
1946 IEnumPins_Reset(pEnum);
1947 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1949 /* Explore the graph downstream from this pin */
1950 ExploreGraph(This, pPin, FoundFilter, data);
1951 IPin_Release(pPin);
1953 FoundFilter(pfilter, data);
1955 IEnumPins_Release(pEnum);
1958 return S_FALSE;
1961 /*** IMediaControl methods ***/
1962 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface) {
1963 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1964 TRACE("(%p/%p)->()\n", This, iface);
1966 EnterCriticalSection(&This->cs);
1967 if (This->state == State_Running)
1968 goto out;
1969 This->EcCompleteCount = 0;
1971 if (This->defaultclock && !This->refClock)
1972 IFilterGraph2_SetDefaultSyncSource((IFilterGraph2*)This);
1974 if (This->refClock)
1976 REFERENCE_TIME now;
1977 IReferenceClock_GetTime(This->refClock, &now);
1978 if (This->state == State_Stopped)
1979 This->start_time = now + 500000;
1980 else if (This->pause_time >= 0)
1981 This->start_time += now - This->pause_time;
1982 else
1983 This->start_time = now;
1985 else This->start_time = 0;
1987 SendFilterMessage(iface, SendRun, (DWORD_PTR)&This->start_time);
1988 This->state = State_Running;
1989 out:
1990 LeaveCriticalSection(&This->cs);
1991 return S_FALSE;
1994 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface) {
1995 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1996 TRACE("(%p/%p)->()\n", This, iface);
1998 EnterCriticalSection(&This->cs);
1999 if (This->state == State_Paused)
2000 goto out;
2002 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2003 IReferenceClock_GetTime(This->refClock, &This->pause_time);
2004 else
2005 This->pause_time = -1;
2007 SendFilterMessage(iface, SendPause, 0);
2008 This->state = State_Paused;
2009 out:
2010 LeaveCriticalSection(&This->cs);
2011 return S_FALSE;
2014 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface) {
2015 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2016 TRACE("(%p/%p)->()\n", This, iface);
2018 if (This->state == State_Stopped) return S_OK;
2020 EnterCriticalSection(&This->cs);
2021 if (This->state == State_Running) SendFilterMessage(iface, SendPause, 0);
2022 SendFilterMessage(iface, SendStop, 0);
2023 This->state = State_Stopped;
2024 LeaveCriticalSection(&This->cs);
2025 return S_OK;
2028 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface,
2029 LONG msTimeout,
2030 OAFilterState *pfs) {
2031 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2032 DWORD end;
2034 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
2036 if (!pfs)
2037 return E_POINTER;
2039 EnterCriticalSection(&This->cs);
2041 *pfs = This->state;
2042 if (msTimeout > 0)
2044 end = GetTickCount() + msTimeout;
2046 else if (msTimeout < 0)
2048 end = INFINITE;
2050 else
2052 end = 0;
2054 if (end)
2055 SendFilterMessage(iface, SendGetState, end);
2057 LeaveCriticalSection(&This->cs);
2059 return S_OK;
2062 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface,
2063 BSTR strFilename) {
2064 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2066 FIXME("(%p/%p)->(%s (%p)): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename);
2068 return S_OK;
2071 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface,
2072 BSTR strFilename,
2073 IDispatch **ppUnk) {
2074 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2076 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2078 return S_OK;
2081 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface,
2082 IDispatch **ppUnk) {
2083 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2085 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2087 return S_OK;
2090 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface,
2091 IDispatch **ppUnk) {
2092 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2094 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2096 return S_OK;
2099 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface) {
2100 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2102 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2104 return S_OK;
2108 static const IMediaControlVtbl IMediaControl_VTable =
2110 MediaControl_QueryInterface,
2111 MediaControl_AddRef,
2112 MediaControl_Release,
2113 MediaControl_GetTypeInfoCount,
2114 MediaControl_GetTypeInfo,
2115 MediaControl_GetIDsOfNames,
2116 MediaControl_Invoke,
2117 MediaControl_Run,
2118 MediaControl_Pause,
2119 MediaControl_Stop,
2120 MediaControl_GetState,
2121 MediaControl_RenderFile,
2122 MediaControl_AddSourceFilter,
2123 MediaControl_get_FilterCollection,
2124 MediaControl_get_RegFilterCollection,
2125 MediaControl_StopWhenReady
2129 /*** IUnknown methods ***/
2130 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface,
2131 REFIID riid,
2132 LPVOID*ppvObj) {
2133 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2135 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2137 return Filtergraph_QueryInterface(This, riid, ppvObj);
2140 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface) {
2141 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2143 TRACE("(%p/%p)->()\n", This, iface);
2145 return Filtergraph_AddRef(This);
2148 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface) {
2149 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2151 TRACE("(%p/%p)->()\n", This, iface);
2153 return Filtergraph_Release(This);
2156 typedef HRESULT (WINAPI *fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
2158 static HRESULT all_renderers_seek(IFilterGraphImpl *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2159 BOOL allnotimpl = TRUE;
2160 int i;
2161 HRESULT hr, hr_return = S_OK;
2163 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2164 /* Send a message to all renderers, they are responsible for broadcasting it further */
2166 for(i = 0; i < This->nFilters; i++)
2168 IMediaSeeking *seek = NULL;
2169 IBaseFilter* pfilter = This->ppFiltersInGraph[i];
2170 IAMFilterMiscFlags *flags = NULL;
2171 ULONG filterflags;
2172 IUnknown_QueryInterface(pfilter, &IID_IAMFilterMiscFlags, (void**)&flags);
2173 if (!flags)
2174 continue;
2175 filterflags = IAMFilterMiscFlags_GetMiscFlags(flags);
2176 IUnknown_Release(flags);
2177 if (filterflags != AM_FILTER_MISC_FLAGS_IS_RENDERER)
2178 continue;
2180 IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2181 if (!seek)
2182 continue;
2183 hr = FoundSeek(This, seek, arg);
2184 IMediaSeeking_Release(seek);
2185 if (hr_return != E_NOTIMPL)
2186 allnotimpl = FALSE;
2187 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2188 hr_return = hr;
2191 if (allnotimpl)
2192 return E_NOTIMPL;
2193 return hr_return;
2196 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2198 HRESULT hr;
2199 DWORD caps = 0;
2201 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2202 if (FAILED(hr))
2203 return hr;
2205 /* Only add common capabilities everything supports */
2206 *(DWORD*)pcaps &= caps;
2208 return hr;
2211 /*** IMediaSeeking methods ***/
2212 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface,
2213 DWORD *pCapabilities) {
2214 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2215 HRESULT hr;
2216 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2218 if (!pCapabilities)
2219 return E_POINTER;
2221 EnterCriticalSection(&This->cs);
2222 *pCapabilities = 0xffffffff;
2224 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2225 LeaveCriticalSection(&This->cs);
2227 return hr;
2230 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface,
2231 DWORD *pCapabilities) {
2232 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2233 DWORD originalcaps;
2234 HRESULT hr;
2235 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2237 if (!pCapabilities)
2238 return E_POINTER;
2240 EnterCriticalSection(&This->cs);
2241 originalcaps = *pCapabilities;
2242 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2243 LeaveCriticalSection(&This->cs);
2245 if (FAILED(hr))
2246 return hr;
2248 if (!*pCapabilities)
2249 return E_FAIL;
2250 if (*pCapabilities != originalcaps)
2251 return S_FALSE;
2252 return S_OK;
2255 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface,
2256 const GUID *pFormat) {
2257 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2259 if (!pFormat)
2260 return E_POINTER;
2262 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2264 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2266 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2267 return S_FALSE;
2270 return S_OK;
2273 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface,
2274 GUID *pFormat) {
2275 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2277 if (!pFormat)
2278 return E_POINTER;
2280 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2281 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2283 return S_OK;
2286 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface,
2287 GUID *pFormat) {
2288 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2290 if (!pFormat)
2291 return E_POINTER;
2293 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2294 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2296 return S_OK;
2299 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface,
2300 const GUID *pFormat) {
2301 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2303 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2304 if (!pFormat)
2305 return E_POINTER;
2307 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2308 return S_FALSE;
2310 return S_OK;
2313 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface,
2314 const GUID *pFormat) {
2315 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2317 if (!pFormat)
2318 return E_POINTER;
2320 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2322 if (This->state != State_Stopped)
2323 return VFW_E_WRONG_STATE;
2325 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2327 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2328 return E_INVALIDARG;
2331 return S_OK;
2334 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2336 HRESULT hr;
2337 LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2339 hr = IMediaSeeking_GetDuration(seek, &duration);
2340 if (FAILED(hr))
2341 return hr;
2343 if (*pdur < duration)
2344 *pdur = duration;
2345 return hr;
2348 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface,
2349 LONGLONG *pDuration) {
2350 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2351 HRESULT hr;
2353 TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2355 if (!pDuration)
2356 return E_POINTER;
2358 EnterCriticalSection(&This->cs);
2359 *pDuration = 0;
2360 hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2361 LeaveCriticalSection(&This->cs);
2363 TRACE("--->%08x\n", hr);
2364 return hr;
2367 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface,
2368 LONGLONG *pStop) {
2369 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2370 HRESULT hr = S_OK;
2372 TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2374 if (!pStop)
2375 return E_POINTER;
2377 EnterCriticalSection(&This->cs);
2378 if (This->stop_position < 0)
2379 /* Stop position not set, use duration instead */
2380 hr = IMediaSeeking_GetDuration(iface, pStop);
2381 else
2382 *pStop = This->stop_position;
2383 LeaveCriticalSection(&This->cs);
2385 return hr;
2388 static HRESULT WINAPI FoundCurrentPosition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pposition)
2390 HRESULT hr;
2391 LONGLONG pos = 0, *ppos = (LONGLONG*)pposition;
2393 hr = IMediaSeeking_GetCurrentPosition(seek, &pos);
2394 if (FAILED(hr))
2395 return hr;
2397 if (*ppos < 0 || pos < *ppos)
2398 *ppos = pos;
2399 return hr;
2402 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface,
2403 LONGLONG *pCurrent) {
2404 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2405 HRESULT hr;
2407 if (!pCurrent)
2408 return E_POINTER;
2410 EnterCriticalSection(&This->cs);
2411 *pCurrent = -1;
2412 hr = all_renderers_seek(This, FoundCurrentPosition, (DWORD_PTR)pCurrent);
2413 if (hr == E_NOTIMPL) {
2414 *pCurrent = 0;
2415 hr = S_OK;
2417 LeaveCriticalSection(&This->cs);
2419 TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2421 return hr;
2424 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface,
2425 LONGLONG *pTarget,
2426 const GUID *pTargetFormat,
2427 LONGLONG Source,
2428 const GUID *pSourceFormat) {
2429 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2431 FIXME("(%p/%p)->(%p, %p, 0x%s, %p): stub !!!\n", This, iface, pTarget,
2432 pTargetFormat, wine_dbgstr_longlong(Source), pSourceFormat);
2434 return S_OK;
2437 struct pos_args {
2438 LONGLONG* current, *stop;
2439 DWORD curflags, stopflags;
2442 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2444 struct pos_args *args = (void*)pargs;
2446 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
2449 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface,
2450 LONGLONG *pCurrent,
2451 DWORD dwCurrentFlags,
2452 LONGLONG *pStop,
2453 DWORD dwStopFlags) {
2454 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2455 HRESULT hr = S_OK;
2456 FILTER_STATE state;
2457 struct pos_args args;
2459 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
2461 EnterCriticalSection(&This->cs);
2462 state = This->state;
2463 TRACE("State: %s\n", state == State_Running ? "Running" : (state == State_Paused ? "Paused" : (state == State_Stopped ? "Stopped" : "UNKNOWN")));
2465 if ((dwCurrentFlags & 0x7) != AM_SEEKING_AbsolutePositioning &&
2466 (dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2467 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
2469 if ((dwStopFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2470 This->stop_position = *pStop;
2471 else if ((dwStopFlags & 0x7) != AM_SEEKING_NoPositioning)
2472 FIXME("Stop position not handled yet!\n");
2474 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2475 IMediaControl_Pause((IMediaControl*)&This->IMediaControl_vtbl);
2476 args.current = pCurrent;
2477 args.stop = pStop;
2478 args.curflags = dwCurrentFlags;
2479 args.stopflags = dwStopFlags;
2480 hr = all_renderers_seek(This, found_setposition, (DWORD_PTR)&args);
2482 if ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2483 This->pause_time = This->start_time = -1;
2484 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2485 IMediaControl_Run((IMediaControl*)&This->IMediaControl_vtbl);
2486 LeaveCriticalSection(&This->cs);
2488 return hr;
2491 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface,
2492 LONGLONG *pCurrent,
2493 LONGLONG *pStop) {
2494 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2495 HRESULT hr;
2497 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pCurrent, pStop);
2498 hr = IMediaSeeking_GetCurrentPosition(iface, pCurrent);
2499 if (SUCCEEDED(hr))
2500 hr = IMediaSeeking_GetStopPosition(iface, pStop);
2502 return hr;
2505 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface,
2506 LONGLONG *pEarliest,
2507 LONGLONG *pLatest) {
2508 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2510 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2512 return S_OK;
2515 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface,
2516 double dRate) {
2517 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2519 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2521 return S_OK;
2524 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface,
2525 double *pdRate) {
2526 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2528 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2530 return S_OK;
2533 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface,
2534 LONGLONG *pllPreroll) {
2535 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2537 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2539 return S_OK;
2543 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2545 MediaSeeking_QueryInterface,
2546 MediaSeeking_AddRef,
2547 MediaSeeking_Release,
2548 MediaSeeking_GetCapabilities,
2549 MediaSeeking_CheckCapabilities,
2550 MediaSeeking_IsFormatSupported,
2551 MediaSeeking_QueryPreferredFormat,
2552 MediaSeeking_GetTimeFormat,
2553 MediaSeeking_IsUsingTimeFormat,
2554 MediaSeeking_SetTimeFormat,
2555 MediaSeeking_GetDuration,
2556 MediaSeeking_GetStopPosition,
2557 MediaSeeking_GetCurrentPosition,
2558 MediaSeeking_ConvertTimeFormat,
2559 MediaSeeking_SetPositions,
2560 MediaSeeking_GetPositions,
2561 MediaSeeking_GetAvailable,
2562 MediaSeeking_SetRate,
2563 MediaSeeking_GetRate,
2564 MediaSeeking_GetPreroll
2567 static inline IFilterGraphImpl *impl_from_IMediaPosition( IMediaPosition *iface )
2569 return (IFilterGraphImpl *)((char*)iface - FIELD_OFFSET(IFilterGraphImpl, IMediaPosition_vtbl));
2572 /*** IUnknown methods ***/
2573 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj)
2575 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2577 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2578 return Filtergraph_QueryInterface(This, riid, ppvObj);
2581 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2583 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2585 TRACE("(%p/%p)->()\n", This, iface);
2586 return Filtergraph_AddRef(This);
2589 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2591 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2593 TRACE("(%p/%p)->()\n", This, iface);
2594 return Filtergraph_Release(This);
2597 /*** IDispatch methods ***/
2598 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo){
2599 FIXME("(%p) stub!\n", iface);
2600 return E_NOTIMPL;
2603 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo){
2604 FIXME("(%p) stub!\n", iface);
2605 return E_NOTIMPL;
2608 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId){
2609 FIXME("(%p) stub!\n", iface);
2610 return E_NOTIMPL;
2613 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr){
2614 FIXME("(%p) stub!\n", iface);
2615 return E_NOTIMPL;
2618 /*** IMediaPosition methods ***/
2619 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2621 LONGLONG duration;
2622 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2623 HRESULT hr = IMediaSeeking_GetDuration( (IMediaSeeking *)&This->IMediaSeeking_vtbl, &duration );
2624 if (SUCCEEDED(hr)) *plength = duration;
2625 return hr;
2628 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2630 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2631 LONGLONG reftime = llTime;
2633 return IMediaSeeking_SetPositions((IMediaSeeking *)&This->IMediaSeeking_vtbl,
2634 &reftime, AM_SEEKING_AbsolutePositioning,
2635 NULL, AM_SEEKING_NoPositioning);
2638 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2640 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2641 LONGLONG pos;
2642 HRESULT hr = IMediaSeeking_GetCurrentPosition( (IMediaSeeking *)&This->IMediaSeeking_vtbl, &pos );
2643 if (SUCCEEDED(hr)) *pllTime = pos;
2644 return hr;
2647 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2649 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2650 LONGLONG pos;
2651 HRESULT hr = IMediaSeeking_GetStopPosition( (IMediaSeeking *)&This->IMediaSeeking_vtbl, &pos );
2652 if (SUCCEEDED(hr)) *pllTime = pos;
2653 return hr;
2656 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2658 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2659 LONGLONG reftime = llTime;
2661 return IMediaSeeking_SetPositions((IMediaSeeking *)&This->IMediaSeeking_vtbl,
2662 NULL, AM_SEEKING_NoPositioning,
2663 &reftime, AM_SEEKING_AbsolutePositioning);
2666 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime){
2667 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2668 return E_NOTIMPL;
2671 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime){
2672 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2673 return E_NOTIMPL;
2676 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2678 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2679 return IMediaSeeking_SetRate((IMediaSeeking *)&This->IMediaSeeking_vtbl, dRate);
2682 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2684 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2685 return IMediaSeeking_GetRate((IMediaSeeking *)&This->IMediaSeeking_vtbl, pdRate);
2688 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward){
2689 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2690 return E_NOTIMPL;
2693 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward){
2694 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2695 return E_NOTIMPL;
2699 static const IMediaPositionVtbl IMediaPosition_VTable =
2701 MediaPosition_QueryInterface,
2702 MediaPosition_AddRef,
2703 MediaPosition_Release,
2704 MediaPosition_GetTypeInfoCount,
2705 MediaPosition_GetTypeInfo,
2706 MediaPosition_GetIDsOfNames,
2707 MediaPosition_Invoke,
2708 MediaPosition_get_Duration,
2709 MediaPosition_put_CurrentPosition,
2710 MediaPosition_get_CurrentPosition,
2711 MediaPosition_get_StopTime,
2712 MediaPosition_put_StopTime,
2713 MediaPosition_get_PrerollTime,
2714 MediaPosition_put_PrerollTime,
2715 MediaPosition_put_Rate,
2716 MediaPosition_get_Rate,
2717 MediaPosition_CanSeekForward,
2718 MediaPosition_CanSeekBackward
2721 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2723 HRESULT hr = E_NOINTERFACE;
2724 int i;
2725 int entry;
2727 /* Check if the interface type is already registered */
2728 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2729 if (riid == pGraph->ItfCacheEntries[entry].riid)
2731 if (pGraph->ItfCacheEntries[entry].iface)
2733 /* Return the interface if available */
2734 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2735 return S_OK;
2737 break;
2740 if (entry >= MAX_ITF_CACHE_ENTRIES)
2742 FIXME("Not enough space to store interface in the cache\n");
2743 return E_OUTOFMEMORY;
2746 /* Find a filter supporting the requested interface */
2747 for (i = 0; i < pGraph->nFilters; i++)
2749 hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2750 if (hr == S_OK)
2752 pGraph->ItfCacheEntries[entry].riid = riid;
2753 pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2754 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2755 if (entry >= pGraph->nItfCacheEntries)
2756 pGraph->nItfCacheEntries++;
2757 return S_OK;
2759 if (hr != E_NOINTERFACE)
2760 return hr;
2763 return hr;
2766 /*** IUnknown methods ***/
2767 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface,
2768 REFIID riid,
2769 LPVOID*ppvObj) {
2770 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2772 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2774 return Filtergraph_QueryInterface(This, riid, ppvObj);
2777 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface) {
2778 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2780 TRACE("(%p/%p)->()\n", This, iface);
2782 return Filtergraph_AddRef(This);
2785 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface) {
2786 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2788 TRACE("(%p/%p)->()\n", This, iface);
2790 return Filtergraph_Release(This);
2793 /*** IDispatch methods ***/
2794 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface,
2795 UINT*pctinfo) {
2796 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2797 IBasicAudio* pBasicAudio;
2798 HRESULT hr;
2800 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
2802 EnterCriticalSection(&This->cs);
2804 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2806 if (hr == S_OK)
2807 hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
2809 LeaveCriticalSection(&This->cs);
2811 return hr;
2814 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface,
2815 UINT iTInfo,
2816 LCID lcid,
2817 ITypeInfo**ppTInfo) {
2818 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2819 IBasicAudio* pBasicAudio;
2820 HRESULT hr;
2822 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
2824 EnterCriticalSection(&This->cs);
2826 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2828 if (hr == S_OK)
2829 hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
2831 LeaveCriticalSection(&This->cs);
2833 return hr;
2836 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface,
2837 REFIID riid,
2838 LPOLESTR*rgszNames,
2839 UINT cNames,
2840 LCID lcid,
2841 DISPID*rgDispId) {
2842 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2843 IBasicAudio* pBasicAudio;
2844 HRESULT hr;
2846 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
2848 EnterCriticalSection(&This->cs);
2850 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2852 if (hr == S_OK)
2853 hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
2855 LeaveCriticalSection(&This->cs);
2857 return hr;
2860 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface,
2861 DISPID dispIdMember,
2862 REFIID riid,
2863 LCID lcid,
2864 WORD wFlags,
2865 DISPPARAMS*pDispParams,
2866 VARIANT*pVarResult,
2867 EXCEPINFO*pExepInfo,
2868 UINT*puArgErr) {
2869 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2870 IBasicAudio* pBasicAudio;
2871 HRESULT hr;
2873 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);
2875 EnterCriticalSection(&This->cs);
2877 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2879 if (hr == S_OK)
2880 hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
2882 LeaveCriticalSection(&This->cs);
2884 return hr;
2887 /*** IBasicAudio methods ***/
2888 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface,
2889 LONG lVolume) {
2890 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2891 IBasicAudio* pBasicAudio;
2892 HRESULT hr;
2894 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
2896 EnterCriticalSection(&This->cs);
2898 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2900 if (hr == S_OK)
2901 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
2903 LeaveCriticalSection(&This->cs);
2905 return hr;
2908 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface,
2909 LONG *plVolume) {
2910 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2911 IBasicAudio* pBasicAudio;
2912 HRESULT hr;
2914 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
2916 EnterCriticalSection(&This->cs);
2918 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2920 if (hr == S_OK)
2921 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
2923 LeaveCriticalSection(&This->cs);
2925 return hr;
2928 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface,
2929 LONG lBalance) {
2930 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2931 IBasicAudio* pBasicAudio;
2932 HRESULT hr;
2934 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
2936 EnterCriticalSection(&This->cs);
2938 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2940 if (hr == S_OK)
2941 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
2943 LeaveCriticalSection(&This->cs);
2945 return hr;
2948 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface,
2949 LONG *plBalance) {
2950 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2951 IBasicAudio* pBasicAudio;
2952 HRESULT hr;
2954 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
2956 EnterCriticalSection(&This->cs);
2958 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2960 if (hr == S_OK)
2961 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
2963 LeaveCriticalSection(&This->cs);
2965 return hr;
2968 static const IBasicAudioVtbl IBasicAudio_VTable =
2970 BasicAudio_QueryInterface,
2971 BasicAudio_AddRef,
2972 BasicAudio_Release,
2973 BasicAudio_GetTypeInfoCount,
2974 BasicAudio_GetTypeInfo,
2975 BasicAudio_GetIDsOfNames,
2976 BasicAudio_Invoke,
2977 BasicAudio_put_Volume,
2978 BasicAudio_get_Volume,
2979 BasicAudio_put_Balance,
2980 BasicAudio_get_Balance
2983 /*** IUnknown methods ***/
2984 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface,
2985 REFIID riid,
2986 LPVOID*ppvObj) {
2987 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2989 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2991 return Filtergraph_QueryInterface(This, riid, ppvObj);
2994 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface) {
2995 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2997 TRACE("(%p/%p)->()\n", This, iface);
2999 return Filtergraph_AddRef(This);
3002 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface) {
3003 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3005 TRACE("(%p/%p)->()\n", This, iface);
3007 return Filtergraph_Release(This);
3010 /*** IDispatch methods ***/
3011 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface,
3012 UINT*pctinfo) {
3013 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3014 IBasicVideo* pBasicVideo;
3015 HRESULT hr;
3017 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3019 EnterCriticalSection(&This->cs);
3021 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3023 if (hr == S_OK)
3024 hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
3026 LeaveCriticalSection(&This->cs);
3028 return hr;
3031 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface,
3032 UINT iTInfo,
3033 LCID lcid,
3034 ITypeInfo**ppTInfo) {
3035 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3036 IBasicVideo* pBasicVideo;
3037 HRESULT hr;
3039 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3041 EnterCriticalSection(&This->cs);
3043 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3045 if (hr == S_OK)
3046 hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
3048 LeaveCriticalSection(&This->cs);
3050 return hr;
3053 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface,
3054 REFIID riid,
3055 LPOLESTR*rgszNames,
3056 UINT cNames,
3057 LCID lcid,
3058 DISPID*rgDispId) {
3059 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3060 IBasicVideo* pBasicVideo;
3061 HRESULT hr;
3063 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3065 EnterCriticalSection(&This->cs);
3067 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3069 if (hr == S_OK)
3070 hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
3072 LeaveCriticalSection(&This->cs);
3074 return hr;
3077 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface,
3078 DISPID dispIdMember,
3079 REFIID riid,
3080 LCID lcid,
3081 WORD wFlags,
3082 DISPPARAMS*pDispParams,
3083 VARIANT*pVarResult,
3084 EXCEPINFO*pExepInfo,
3085 UINT*puArgErr) {
3086 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3087 IBasicVideo* pBasicVideo;
3088 HRESULT hr;
3090 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);
3092 EnterCriticalSection(&This->cs);
3094 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3096 if (hr == S_OK)
3097 hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3099 LeaveCriticalSection(&This->cs);
3101 return hr;
3104 /*** IBasicVideo methods ***/
3105 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface,
3106 REFTIME *pAvgTimePerFrame) {
3107 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3108 IBasicVideo* pBasicVideo;
3109 HRESULT hr;
3111 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3113 EnterCriticalSection(&This->cs);
3115 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3117 if (hr == S_OK)
3118 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3120 LeaveCriticalSection(&This->cs);
3122 return hr;
3125 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface,
3126 LONG *pBitRate) {
3127 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3128 IBasicVideo* pBasicVideo;
3129 HRESULT hr;
3131 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3133 EnterCriticalSection(&This->cs);
3135 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3137 if (hr == S_OK)
3138 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3140 LeaveCriticalSection(&This->cs);
3142 return hr;
3145 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface,
3146 LONG *pBitErrorRate) {
3147 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3148 IBasicVideo* pBasicVideo;
3149 HRESULT hr;
3151 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3153 EnterCriticalSection(&This->cs);
3155 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3157 if (hr == S_OK)
3158 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3160 LeaveCriticalSection(&This->cs);
3162 return hr;
3165 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface,
3166 LONG *pVideoWidth) {
3167 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3168 IBasicVideo* pBasicVideo;
3169 HRESULT hr;
3171 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3173 EnterCriticalSection(&This->cs);
3175 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3177 if (hr == S_OK)
3178 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3180 LeaveCriticalSection(&This->cs);
3182 return hr;
3185 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface,
3186 LONG *pVideoHeight) {
3187 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3188 IBasicVideo* pBasicVideo;
3189 HRESULT hr;
3191 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3193 EnterCriticalSection(&This->cs);
3195 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3197 if (hr == S_OK)
3198 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3200 LeaveCriticalSection(&This->cs);
3202 return hr;
3205 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface,
3206 LONG SourceLeft) {
3207 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3208 IBasicVideo* pBasicVideo;
3209 HRESULT hr;
3211 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3213 EnterCriticalSection(&This->cs);
3215 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3217 if (hr == S_OK)
3218 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3220 LeaveCriticalSection(&This->cs);
3222 return hr;
3225 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface,
3226 LONG *pSourceLeft) {
3227 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3228 IBasicVideo* pBasicVideo;
3229 HRESULT hr;
3231 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3233 EnterCriticalSection(&This->cs);
3235 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3237 if (hr == S_OK)
3238 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3240 LeaveCriticalSection(&This->cs);
3242 return hr;
3245 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface,
3246 LONG SourceWidth) {
3247 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3248 IBasicVideo* pBasicVideo;
3249 HRESULT hr;
3251 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3253 EnterCriticalSection(&This->cs);
3255 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3257 if (hr == S_OK)
3258 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3260 LeaveCriticalSection(&This->cs);
3262 return hr;
3265 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface,
3266 LONG *pSourceWidth) {
3267 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3268 IBasicVideo* pBasicVideo;
3269 HRESULT hr;
3271 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3273 EnterCriticalSection(&This->cs);
3275 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3277 if (hr == S_OK)
3278 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3280 LeaveCriticalSection(&This->cs);
3282 return hr;
3285 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface,
3286 LONG SourceTop) {
3287 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3288 IBasicVideo* pBasicVideo;
3289 HRESULT hr;
3291 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3293 EnterCriticalSection(&This->cs);
3295 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3297 if (hr == S_OK)
3298 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3300 LeaveCriticalSection(&This->cs);
3302 return hr;
3305 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface,
3306 LONG *pSourceTop) {
3307 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3308 IBasicVideo* pBasicVideo;
3309 HRESULT hr;
3311 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3313 EnterCriticalSection(&This->cs);
3315 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3317 if (hr == S_OK)
3318 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3320 LeaveCriticalSection(&This->cs);
3322 return hr;
3325 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface,
3326 LONG SourceHeight) {
3327 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3328 IBasicVideo* pBasicVideo;
3329 HRESULT hr;
3331 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3333 EnterCriticalSection(&This->cs);
3335 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3337 if (hr == S_OK)
3338 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3340 LeaveCriticalSection(&This->cs);
3342 return hr;
3345 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface,
3346 LONG *pSourceHeight) {
3347 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3348 IBasicVideo* pBasicVideo;
3349 HRESULT hr;
3351 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3353 EnterCriticalSection(&This->cs);
3355 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3357 if (hr == S_OK)
3358 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3360 LeaveCriticalSection(&This->cs);
3362 return hr;
3365 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface,
3366 LONG DestinationLeft) {
3367 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3368 IBasicVideo* pBasicVideo;
3369 HRESULT hr;
3371 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3373 EnterCriticalSection(&This->cs);
3375 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3377 if (hr == S_OK)
3378 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3380 LeaveCriticalSection(&This->cs);
3382 return hr;
3385 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface,
3386 LONG *pDestinationLeft) {
3387 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3388 IBasicVideo* pBasicVideo;
3389 HRESULT hr;
3391 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3393 EnterCriticalSection(&This->cs);
3395 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3397 if (hr == S_OK)
3398 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3400 LeaveCriticalSection(&This->cs);
3402 return hr;
3405 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface,
3406 LONG DestinationWidth) {
3407 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3408 IBasicVideo* pBasicVideo;
3409 HRESULT hr;
3411 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3413 EnterCriticalSection(&This->cs);
3415 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3417 if (hr == S_OK)
3418 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3420 LeaveCriticalSection(&This->cs);
3422 return hr;
3425 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface,
3426 LONG *pDestinationWidth) {
3427 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3428 IBasicVideo* pBasicVideo;
3429 HRESULT hr;
3431 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3433 EnterCriticalSection(&This->cs);
3435 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3437 if (hr == S_OK)
3438 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3440 LeaveCriticalSection(&This->cs);
3442 return hr;
3445 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface,
3446 LONG DestinationTop) {
3447 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3448 IBasicVideo* pBasicVideo;
3449 HRESULT hr;
3451 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3453 EnterCriticalSection(&This->cs);
3455 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3457 if (hr == S_OK)
3458 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3460 LeaveCriticalSection(&This->cs);
3462 return hr;
3465 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface,
3466 LONG *pDestinationTop) {
3467 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3468 IBasicVideo* pBasicVideo;
3469 HRESULT hr;
3471 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3473 EnterCriticalSection(&This->cs);
3475 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3477 if (hr == S_OK)
3478 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3480 LeaveCriticalSection(&This->cs);
3482 return hr;
3485 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface,
3486 LONG DestinationHeight) {
3487 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3488 IBasicVideo* pBasicVideo;
3489 HRESULT hr;
3491 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3493 EnterCriticalSection(&This->cs);
3495 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3497 if (hr == S_OK)
3498 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3500 LeaveCriticalSection(&This->cs);
3502 return hr;
3505 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3506 LONG *pDestinationHeight) {
3507 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3508 IBasicVideo* pBasicVideo;
3509 HRESULT hr;
3511 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3513 EnterCriticalSection(&This->cs);
3515 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3517 if (hr == S_OK)
3518 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3520 LeaveCriticalSection(&This->cs);
3522 return hr;
3525 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface,
3526 LONG Left,
3527 LONG Top,
3528 LONG Width,
3529 LONG Height) {
3530 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3531 IBasicVideo* pBasicVideo;
3532 HRESULT hr;
3534 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3536 EnterCriticalSection(&This->cs);
3538 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3540 if (hr == S_OK)
3541 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3543 LeaveCriticalSection(&This->cs);
3545 return hr;
3548 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface,
3549 LONG *pLeft,
3550 LONG *pTop,
3551 LONG *pWidth,
3552 LONG *pHeight) {
3553 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3554 IBasicVideo* pBasicVideo;
3555 HRESULT hr;
3557 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3559 EnterCriticalSection(&This->cs);
3561 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3563 if (hr == S_OK)
3564 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3566 LeaveCriticalSection(&This->cs);
3568 return hr;
3571 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface) {
3572 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3573 IBasicVideo* pBasicVideo;
3574 HRESULT hr;
3576 TRACE("(%p/%p)->()\n", This, iface);
3578 EnterCriticalSection(&This->cs);
3580 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3582 if (hr == S_OK)
3583 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3585 LeaveCriticalSection(&This->cs);
3587 return hr;
3590 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface,
3591 LONG Left,
3592 LONG Top,
3593 LONG Width,
3594 LONG Height) {
3595 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3596 IBasicVideo* pBasicVideo;
3597 HRESULT hr;
3599 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3601 EnterCriticalSection(&This->cs);
3603 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3605 if (hr == S_OK)
3606 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3608 LeaveCriticalSection(&This->cs);
3610 return hr;
3613 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface,
3614 LONG *pLeft,
3615 LONG *pTop,
3616 LONG *pWidth,
3617 LONG *pHeight) {
3618 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3619 IBasicVideo* pBasicVideo;
3620 HRESULT hr;
3622 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3624 EnterCriticalSection(&This->cs);
3626 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3628 if (hr == S_OK)
3629 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3631 LeaveCriticalSection(&This->cs);
3633 return hr;
3636 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface) {
3637 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3638 IBasicVideo* pBasicVideo;
3639 HRESULT hr;
3641 TRACE("(%p/%p)->()\n", This, iface);
3643 EnterCriticalSection(&This->cs);
3645 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3647 if (hr == S_OK)
3648 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3650 LeaveCriticalSection(&This->cs);
3652 return hr;
3655 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface,
3656 LONG *pWidth,
3657 LONG *pHeight) {
3658 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3659 IBasicVideo* pBasicVideo;
3660 HRESULT hr;
3662 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3664 EnterCriticalSection(&This->cs);
3666 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3668 if (hr == S_OK)
3669 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3671 LeaveCriticalSection(&This->cs);
3673 return hr;
3676 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface,
3677 LONG StartIndex,
3678 LONG Entries,
3679 LONG *pRetrieved,
3680 LONG *pPalette) {
3681 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3682 IBasicVideo* pBasicVideo;
3683 HRESULT hr;
3685 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3687 EnterCriticalSection(&This->cs);
3689 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3691 if (hr == S_OK)
3692 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3694 LeaveCriticalSection(&This->cs);
3696 return hr;
3699 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface,
3700 LONG *pBufferSize,
3701 LONG *pDIBImage) {
3702 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3703 IBasicVideo* pBasicVideo;
3704 HRESULT hr;
3706 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3708 EnterCriticalSection(&This->cs);
3710 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3712 if (hr == S_OK)
3713 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3715 LeaveCriticalSection(&This->cs);
3717 return hr;
3720 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface) {
3721 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3722 IBasicVideo* pBasicVideo;
3723 HRESULT hr;
3725 TRACE("(%p/%p)->()\n", This, iface);
3727 EnterCriticalSection(&This->cs);
3729 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3731 if (hr == S_OK)
3732 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3734 LeaveCriticalSection(&This->cs);
3736 return hr;
3739 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface) {
3740 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3741 IBasicVideo* pBasicVideo;
3742 HRESULT hr;
3744 TRACE("(%p/%p)->()\n", This, iface);
3746 EnterCriticalSection(&This->cs);
3748 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3750 if (hr == S_OK)
3751 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3753 LeaveCriticalSection(&This->cs);
3755 return hr;
3758 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX, LONG *plAspectY) {
3759 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3760 IBasicVideo2 *pBasicVideo2;
3761 HRESULT hr;
3763 TRACE("(%p/%p)->()\n", This, iface);
3765 EnterCriticalSection(&This->cs);
3767 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3769 if (hr == S_OK)
3770 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3772 LeaveCriticalSection(&This->cs);
3774 return hr;
3777 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3779 BasicVideo_QueryInterface,
3780 BasicVideo_AddRef,
3781 BasicVideo_Release,
3782 BasicVideo_GetTypeInfoCount,
3783 BasicVideo_GetTypeInfo,
3784 BasicVideo_GetIDsOfNames,
3785 BasicVideo_Invoke,
3786 BasicVideo_get_AvgTimePerFrame,
3787 BasicVideo_get_BitRate,
3788 BasicVideo_get_BitErrorRate,
3789 BasicVideo_get_VideoWidth,
3790 BasicVideo_get_VideoHeight,
3791 BasicVideo_put_SourceLeft,
3792 BasicVideo_get_SourceLeft,
3793 BasicVideo_put_SourceWidth,
3794 BasicVideo_get_SourceWidth,
3795 BasicVideo_put_SourceTop,
3796 BasicVideo_get_SourceTop,
3797 BasicVideo_put_SourceHeight,
3798 BasicVideo_get_SourceHeight,
3799 BasicVideo_put_DestinationLeft,
3800 BasicVideo_get_DestinationLeft,
3801 BasicVideo_put_DestinationWidth,
3802 BasicVideo_get_DestinationWidth,
3803 BasicVideo_put_DestinationTop,
3804 BasicVideo_get_DestinationTop,
3805 BasicVideo_put_DestinationHeight,
3806 BasicVideo_get_DestinationHeight,
3807 BasicVideo_SetSourcePosition,
3808 BasicVideo_GetSourcePosition,
3809 BasicVideo_SetDefaultSourcePosition,
3810 BasicVideo_SetDestinationPosition,
3811 BasicVideo_GetDestinationPosition,
3812 BasicVideo_SetDefaultDestinationPosition,
3813 BasicVideo_GetVideoSize,
3814 BasicVideo_GetVideoPaletteEntries,
3815 BasicVideo_GetCurrentImage,
3816 BasicVideo_IsUsingDefaultSource,
3817 BasicVideo_IsUsingDefaultDestination,
3818 BasicVideo2_GetPreferredAspectRatio
3822 /*** IUnknown methods ***/
3823 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface,
3824 REFIID riid,
3825 LPVOID*ppvObj) {
3826 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3828 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3830 return Filtergraph_QueryInterface(This, riid, ppvObj);
3833 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface) {
3834 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3836 TRACE("(%p/%p)->()\n", This, iface);
3838 return Filtergraph_AddRef(This);
3841 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface) {
3842 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3844 TRACE("(%p/%p)->()\n", This, iface);
3846 return Filtergraph_Release(This);
3849 /*** IDispatch methods ***/
3850 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface,
3851 UINT*pctinfo) {
3852 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3853 IVideoWindow* pVideoWindow;
3854 HRESULT hr;
3856 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3858 EnterCriticalSection(&This->cs);
3860 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3862 if (hr == S_OK)
3863 hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
3865 LeaveCriticalSection(&This->cs);
3867 return hr;
3870 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface,
3871 UINT iTInfo,
3872 LCID lcid,
3873 ITypeInfo**ppTInfo) {
3874 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3875 IVideoWindow* pVideoWindow;
3876 HRESULT hr;
3878 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3880 EnterCriticalSection(&This->cs);
3882 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3884 if (hr == S_OK)
3885 hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
3887 LeaveCriticalSection(&This->cs);
3889 return hr;
3892 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface,
3893 REFIID riid,
3894 LPOLESTR*rgszNames,
3895 UINT cNames,
3896 LCID lcid,
3897 DISPID*rgDispId) {
3898 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3899 IVideoWindow* pVideoWindow;
3900 HRESULT hr;
3902 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3904 EnterCriticalSection(&This->cs);
3906 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3908 if (hr == S_OK)
3909 hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
3911 LeaveCriticalSection(&This->cs);
3913 return hr;
3916 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface,
3917 DISPID dispIdMember,
3918 REFIID riid,
3919 LCID lcid,
3920 WORD wFlags,
3921 DISPPARAMS*pDispParams,
3922 VARIANT*pVarResult,
3923 EXCEPINFO*pExepInfo,
3924 UINT*puArgErr) {
3925 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3926 IVideoWindow* pVideoWindow;
3927 HRESULT hr;
3929 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);
3931 EnterCriticalSection(&This->cs);
3933 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3935 if (hr == S_OK)
3936 hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3938 LeaveCriticalSection(&This->cs);
3940 return hr;
3944 /*** IVideoWindow methods ***/
3945 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface,
3946 BSTR strCaption) {
3947 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3948 IVideoWindow* pVideoWindow;
3949 HRESULT hr;
3951 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
3953 EnterCriticalSection(&This->cs);
3955 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3957 if (hr == S_OK)
3958 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
3960 LeaveCriticalSection(&This->cs);
3962 return hr;
3965 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface,
3966 BSTR *strCaption) {
3967 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3968 IVideoWindow* pVideoWindow;
3969 HRESULT hr;
3971 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
3973 EnterCriticalSection(&This->cs);
3975 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3977 if (hr == S_OK)
3978 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
3980 LeaveCriticalSection(&This->cs);
3982 return hr;
3985 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface,
3986 LONG WindowStyle) {
3987 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3988 IVideoWindow* pVideoWindow;
3989 HRESULT hr;
3991 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
3993 EnterCriticalSection(&This->cs);
3995 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3997 if (hr == S_OK)
3998 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
4000 LeaveCriticalSection(&This->cs);
4002 return hr;
4005 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface,
4006 LONG *WindowStyle) {
4007 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4008 IVideoWindow* pVideoWindow;
4009 HRESULT hr;
4011 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
4013 EnterCriticalSection(&This->cs);
4015 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4017 if (hr == S_OK)
4018 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
4020 LeaveCriticalSection(&This->cs);
4022 return hr;
4025 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface,
4026 LONG WindowStyleEx) {
4027 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4028 IVideoWindow* pVideoWindow;
4029 HRESULT hr;
4031 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
4033 EnterCriticalSection(&This->cs);
4035 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4037 if (hr == S_OK)
4038 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
4040 LeaveCriticalSection(&This->cs);
4042 return hr;
4045 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface,
4046 LONG *WindowStyleEx) {
4047 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4048 IVideoWindow* pVideoWindow;
4049 HRESULT hr;
4051 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
4053 EnterCriticalSection(&This->cs);
4055 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4057 if (hr == S_OK)
4058 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
4060 LeaveCriticalSection(&This->cs);
4062 return hr;
4065 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface,
4066 LONG AutoShow) {
4067 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4068 IVideoWindow* pVideoWindow;
4069 HRESULT hr;
4071 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
4073 EnterCriticalSection(&This->cs);
4075 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4077 if (hr == S_OK)
4078 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4080 LeaveCriticalSection(&This->cs);
4082 return hr;
4085 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface,
4086 LONG *AutoShow) {
4087 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4088 IVideoWindow* pVideoWindow;
4089 HRESULT hr;
4091 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4093 EnterCriticalSection(&This->cs);
4095 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4097 if (hr == S_OK)
4098 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4100 LeaveCriticalSection(&This->cs);
4102 return hr;
4105 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface,
4106 LONG WindowState) {
4107 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4108 IVideoWindow* pVideoWindow;
4109 HRESULT hr;
4111 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4113 EnterCriticalSection(&This->cs);
4115 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4117 if (hr == S_OK)
4118 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4120 LeaveCriticalSection(&This->cs);
4122 return hr;
4125 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface,
4126 LONG *WindowState) {
4127 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4128 IVideoWindow* pVideoWindow;
4129 HRESULT hr;
4131 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4133 EnterCriticalSection(&This->cs);
4135 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4137 if (hr == S_OK)
4138 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4140 LeaveCriticalSection(&This->cs);
4142 return hr;
4145 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface,
4146 LONG BackgroundPalette) {
4147 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4148 IVideoWindow* pVideoWindow;
4149 HRESULT hr;
4151 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4153 EnterCriticalSection(&This->cs);
4155 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4157 if (hr == S_OK)
4158 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4160 LeaveCriticalSection(&This->cs);
4162 return hr;
4165 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4166 LONG *pBackgroundPalette) {
4167 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4168 IVideoWindow* pVideoWindow;
4169 HRESULT hr;
4171 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4173 EnterCriticalSection(&This->cs);
4175 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4177 if (hr == S_OK)
4178 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4180 LeaveCriticalSection(&This->cs);
4182 return hr;
4185 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface,
4186 LONG Visible) {
4187 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4188 IVideoWindow* pVideoWindow;
4189 HRESULT hr;
4191 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4193 EnterCriticalSection(&This->cs);
4195 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4197 if (hr == S_OK)
4198 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4200 LeaveCriticalSection(&This->cs);
4202 return hr;
4205 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface,
4206 LONG *pVisible) {
4207 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4208 IVideoWindow* pVideoWindow;
4209 HRESULT hr;
4211 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4213 EnterCriticalSection(&This->cs);
4215 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4217 if (hr == S_OK)
4218 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4220 LeaveCriticalSection(&This->cs);
4222 return hr;
4225 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface,
4226 LONG Left) {
4227 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4228 IVideoWindow* pVideoWindow;
4229 HRESULT hr;
4231 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4233 EnterCriticalSection(&This->cs);
4235 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4237 if (hr == S_OK)
4238 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4240 LeaveCriticalSection(&This->cs);
4242 return hr;
4245 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface,
4246 LONG *pLeft) {
4247 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4248 IVideoWindow* pVideoWindow;
4249 HRESULT hr;
4251 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4253 EnterCriticalSection(&This->cs);
4255 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4257 if (hr == S_OK)
4258 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4260 LeaveCriticalSection(&This->cs);
4262 return hr;
4265 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface,
4266 LONG Width) {
4267 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4268 IVideoWindow* pVideoWindow;
4269 HRESULT hr;
4271 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4273 EnterCriticalSection(&This->cs);
4275 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4277 if (hr == S_OK)
4278 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4280 LeaveCriticalSection(&This->cs);
4282 return hr;
4285 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface,
4286 LONG *pWidth) {
4287 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4288 IVideoWindow* pVideoWindow;
4289 HRESULT hr;
4291 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4293 EnterCriticalSection(&This->cs);
4295 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4297 if (hr == S_OK)
4298 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4300 LeaveCriticalSection(&This->cs);
4302 return hr;
4305 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface,
4306 LONG Top) {
4307 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4308 IVideoWindow* pVideoWindow;
4309 HRESULT hr;
4311 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4313 EnterCriticalSection(&This->cs);
4315 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4317 if (hr == S_OK)
4318 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4320 LeaveCriticalSection(&This->cs);
4322 return hr;
4325 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface,
4326 LONG *pTop) {
4327 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4328 IVideoWindow* pVideoWindow;
4329 HRESULT hr;
4331 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4333 EnterCriticalSection(&This->cs);
4335 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4337 if (hr == S_OK)
4338 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4340 LeaveCriticalSection(&This->cs);
4342 return hr;
4345 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface,
4346 LONG Height) {
4347 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4348 IVideoWindow* pVideoWindow;
4349 HRESULT hr;
4351 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4353 EnterCriticalSection(&This->cs);
4355 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4357 if (hr == S_OK)
4358 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4360 LeaveCriticalSection(&This->cs);
4362 return hr;
4365 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface,
4366 LONG *pHeight) {
4367 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4368 IVideoWindow* pVideoWindow;
4369 HRESULT hr;
4371 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4373 EnterCriticalSection(&This->cs);
4375 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4377 if (hr == S_OK)
4378 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4380 LeaveCriticalSection(&This->cs);
4382 return hr;
4385 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface,
4386 OAHWND Owner) {
4387 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4388 IVideoWindow* pVideoWindow;
4389 HRESULT hr;
4391 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4393 EnterCriticalSection(&This->cs);
4395 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4397 if (hr == S_OK)
4398 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4400 LeaveCriticalSection(&This->cs);
4402 return hr;
4405 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface,
4406 OAHWND *Owner) {
4407 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4408 IVideoWindow* pVideoWindow;
4409 HRESULT hr;
4411 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4413 EnterCriticalSection(&This->cs);
4415 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4417 if (hr == S_OK)
4418 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4420 LeaveCriticalSection(&This->cs);
4422 return hr;
4425 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface,
4426 OAHWND Drain) {
4427 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4428 IVideoWindow* pVideoWindow;
4429 HRESULT hr;
4431 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4433 EnterCriticalSection(&This->cs);
4435 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4437 if (hr == S_OK)
4438 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4440 LeaveCriticalSection(&This->cs);
4442 return hr;
4445 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface,
4446 OAHWND *Drain) {
4447 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4448 IVideoWindow* pVideoWindow;
4449 HRESULT hr;
4451 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4453 EnterCriticalSection(&This->cs);
4455 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4457 if (hr == S_OK)
4458 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4460 LeaveCriticalSection(&This->cs);
4462 return hr;
4465 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface,
4466 LONG *Color) {
4467 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4468 IVideoWindow* pVideoWindow;
4469 HRESULT hr;
4471 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4473 EnterCriticalSection(&This->cs);
4475 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4477 if (hr == S_OK)
4478 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4480 LeaveCriticalSection(&This->cs);
4482 return hr;
4485 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface,
4486 LONG Color) {
4487 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4488 IVideoWindow* pVideoWindow;
4489 HRESULT hr;
4491 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4493 EnterCriticalSection(&This->cs);
4495 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4497 if (hr == S_OK)
4498 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4500 LeaveCriticalSection(&This->cs);
4502 return hr;
4505 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface,
4506 LONG *FullScreenMode) {
4507 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4508 IVideoWindow* pVideoWindow;
4509 HRESULT hr;
4511 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4513 EnterCriticalSection(&This->cs);
4515 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4517 if (hr == S_OK)
4518 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4520 LeaveCriticalSection(&This->cs);
4522 return hr;
4525 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface,
4526 LONG FullScreenMode) {
4527 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4528 IVideoWindow* pVideoWindow;
4529 HRESULT hr;
4531 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4533 EnterCriticalSection(&This->cs);
4535 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4537 if (hr == S_OK)
4538 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4540 LeaveCriticalSection(&This->cs);
4542 return hr;
4545 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface,
4546 LONG Focus) {
4547 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4548 IVideoWindow* pVideoWindow;
4549 HRESULT hr;
4551 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4553 EnterCriticalSection(&This->cs);
4555 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4557 if (hr == S_OK)
4558 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4560 LeaveCriticalSection(&This->cs);
4562 return hr;
4565 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface,
4566 OAHWND hwnd,
4567 LONG uMsg,
4568 LONG_PTR wParam,
4569 LONG_PTR lParam) {
4570 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4571 IVideoWindow* pVideoWindow;
4572 HRESULT hr;
4574 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4576 EnterCriticalSection(&This->cs);
4578 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4580 if (hr == S_OK)
4581 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4583 LeaveCriticalSection(&This->cs);
4585 return hr;
4588 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface,
4589 LONG Left,
4590 LONG Top,
4591 LONG Width,
4592 LONG Height) {
4593 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4594 IVideoWindow* pVideoWindow;
4595 HRESULT hr;
4597 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4599 EnterCriticalSection(&This->cs);
4601 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4603 if (hr == S_OK)
4604 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4606 LeaveCriticalSection(&This->cs);
4608 return hr;
4611 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface,
4612 LONG *pLeft,
4613 LONG *pTop,
4614 LONG *pWidth,
4615 LONG *pHeight) {
4616 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4617 IVideoWindow* pVideoWindow;
4618 HRESULT hr;
4620 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4622 EnterCriticalSection(&This->cs);
4624 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4626 if (hr == S_OK)
4627 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4629 LeaveCriticalSection(&This->cs);
4631 return hr;
4634 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface,
4635 LONG *pWidth,
4636 LONG *pHeight) {
4637 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4638 IVideoWindow* pVideoWindow;
4639 HRESULT hr;
4641 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4643 EnterCriticalSection(&This->cs);
4645 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4647 if (hr == S_OK)
4648 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4650 LeaveCriticalSection(&This->cs);
4652 return hr;
4655 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface,
4656 LONG *pWidth,
4657 LONG *pHeight) {
4658 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4659 IVideoWindow* pVideoWindow;
4660 HRESULT hr;
4662 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4664 EnterCriticalSection(&This->cs);
4666 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4668 if (hr == S_OK)
4669 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4671 LeaveCriticalSection(&This->cs);
4673 return hr;
4676 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface,
4677 LONG *pLeft,
4678 LONG *pTop,
4679 LONG *pWidth,
4680 LONG *pHeight) {
4681 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4682 IVideoWindow* pVideoWindow;
4683 HRESULT hr;
4685 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4687 EnterCriticalSection(&This->cs);
4689 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4691 if (hr == S_OK)
4692 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4694 LeaveCriticalSection(&This->cs);
4696 return hr;
4699 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface,
4700 LONG HideCursor) {
4701 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4702 IVideoWindow* pVideoWindow;
4703 HRESULT hr;
4705 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4707 EnterCriticalSection(&This->cs);
4709 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4711 if (hr == S_OK)
4712 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4714 LeaveCriticalSection(&This->cs);
4716 return hr;
4719 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface,
4720 LONG *CursorHidden) {
4721 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4722 IVideoWindow* pVideoWindow;
4723 HRESULT hr;
4725 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4727 EnterCriticalSection(&This->cs);
4729 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4731 if (hr == S_OK)
4732 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4734 LeaveCriticalSection(&This->cs);
4736 return hr;
4740 static const IVideoWindowVtbl IVideoWindow_VTable =
4742 VideoWindow_QueryInterface,
4743 VideoWindow_AddRef,
4744 VideoWindow_Release,
4745 VideoWindow_GetTypeInfoCount,
4746 VideoWindow_GetTypeInfo,
4747 VideoWindow_GetIDsOfNames,
4748 VideoWindow_Invoke,
4749 VideoWindow_put_Caption,
4750 VideoWindow_get_Caption,
4751 VideoWindow_put_WindowStyle,
4752 VideoWindow_get_WindowStyle,
4753 VideoWindow_put_WindowStyleEx,
4754 VideoWindow_get_WindowStyleEx,
4755 VideoWindow_put_AutoShow,
4756 VideoWindow_get_AutoShow,
4757 VideoWindow_put_WindowState,
4758 VideoWindow_get_WindowState,
4759 VideoWindow_put_BackgroundPalette,
4760 VideoWindow_get_BackgroundPalette,
4761 VideoWindow_put_Visible,
4762 VideoWindow_get_Visible,
4763 VideoWindow_put_Left,
4764 VideoWindow_get_Left,
4765 VideoWindow_put_Width,
4766 VideoWindow_get_Width,
4767 VideoWindow_put_Top,
4768 VideoWindow_get_Top,
4769 VideoWindow_put_Height,
4770 VideoWindow_get_Height,
4771 VideoWindow_put_Owner,
4772 VideoWindow_get_Owner,
4773 VideoWindow_put_MessageDrain,
4774 VideoWindow_get_MessageDrain,
4775 VideoWindow_get_BorderColor,
4776 VideoWindow_put_BorderColor,
4777 VideoWindow_get_FullScreenMode,
4778 VideoWindow_put_FullScreenMode,
4779 VideoWindow_SetWindowForeground,
4780 VideoWindow_NotifyOwnerMessage,
4781 VideoWindow_SetWindowPosition,
4782 VideoWindow_GetWindowPosition,
4783 VideoWindow_GetMinIdealImageSize,
4784 VideoWindow_GetMaxIdealImageSize,
4785 VideoWindow_GetRestorePosition,
4786 VideoWindow_HideCursor,
4787 VideoWindow_IsCursorHidden
4791 /*** IUnknown methods ***/
4792 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface,
4793 REFIID riid,
4794 LPVOID*ppvObj) {
4795 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4797 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
4799 return Filtergraph_QueryInterface(This, riid, ppvObj);
4802 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface) {
4803 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4805 TRACE("(%p/%p)->()\n", This, iface);
4807 return Filtergraph_AddRef(This);
4810 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface) {
4811 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4813 TRACE("(%p/%p)->()\n", This, iface);
4815 return Filtergraph_Release(This);
4818 /*** IDispatch methods ***/
4819 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface,
4820 UINT*pctinfo) {
4821 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4823 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
4825 return S_OK;
4828 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface,
4829 UINT iTInfo,
4830 LCID lcid,
4831 ITypeInfo**ppTInfo) {
4832 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4834 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
4836 return S_OK;
4839 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface,
4840 REFIID riid,
4841 LPOLESTR*rgszNames,
4842 UINT cNames,
4843 LCID lcid,
4844 DISPID*rgDispId) {
4845 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4847 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
4849 return S_OK;
4852 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface,
4853 DISPID dispIdMember,
4854 REFIID riid,
4855 LCID lcid,
4856 WORD wFlags,
4857 DISPPARAMS*pDispParams,
4858 VARIANT*pVarResult,
4859 EXCEPINFO*pExepInfo,
4860 UINT*puArgErr) {
4861 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4863 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);
4865 return S_OK;
4868 /*** IMediaEvent methods ***/
4869 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface,
4870 OAEVENT *hEvent) {
4871 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4873 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
4875 *hEvent = (OAEVENT)This->evqueue.msg_event;
4877 return S_OK;
4880 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface,
4881 LONG *lEventCode,
4882 LONG_PTR *lParam1,
4883 LONG_PTR *lParam2,
4884 LONG msTimeout) {
4885 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4886 Event evt;
4888 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
4890 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
4892 *lEventCode = evt.lEventCode;
4893 *lParam1 = evt.lParam1;
4894 *lParam2 = evt.lParam2;
4895 return S_OK;
4898 *lEventCode = 0;
4899 return E_ABORT;
4902 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface,
4903 LONG msTimeout,
4904 LONG *pEvCode) {
4905 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4907 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
4909 if (This->state != State_Running)
4910 return VFW_E_WRONG_STATE;
4912 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
4914 *pEvCode = This->CompletionStatus;
4915 return S_OK;
4918 *pEvCode = 0;
4919 return E_ABORT;
4922 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface,
4923 LONG lEvCode) {
4924 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4926 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4928 if (lEvCode == EC_COMPLETE)
4929 This->HandleEcComplete = FALSE;
4930 else if (lEvCode == EC_REPAINT)
4931 This->HandleEcRepaint = FALSE;
4932 else if (lEvCode == EC_CLOCK_CHANGED)
4933 This->HandleEcClockChanged = FALSE;
4934 else
4935 return S_FALSE;
4937 return S_OK;
4940 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface,
4941 LONG lEvCode) {
4942 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4944 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4946 if (lEvCode == EC_COMPLETE)
4947 This->HandleEcComplete = TRUE;
4948 else if (lEvCode == EC_REPAINT)
4949 This->HandleEcRepaint = TRUE;
4950 else if (lEvCode == EC_CLOCK_CHANGED)
4951 This->HandleEcClockChanged = TRUE;
4952 else
4953 return S_FALSE;
4955 return S_OK;
4958 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface,
4959 LONG lEvCode,
4960 LONG_PTR lParam1,
4961 LONG_PTR lParam2) {
4962 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4964 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
4966 return S_OK;
4969 /*** IMediaEventEx methods ***/
4970 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface,
4971 OAHWND hwnd,
4972 LONG lMsg,
4973 LONG_PTR lInstanceData) {
4974 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4976 TRACE("(%p/%p)->(%08lx, %d, %08lx)\n", This, iface, hwnd, lMsg, lInstanceData);
4978 This->notif.hWnd = (HWND)hwnd;
4979 This->notif.msg = lMsg;
4980 This->notif.instance = lInstanceData;
4982 return S_OK;
4985 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface,
4986 LONG lNoNotifyFlags) {
4987 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4989 TRACE("(%p/%p)->(%d)\n", This, iface, lNoNotifyFlags);
4991 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
4992 return E_INVALIDARG;
4994 This->notif.disabled = lNoNotifyFlags;
4996 return S_OK;
4999 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface,
5000 LONG *lplNoNotifyFlags) {
5001 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
5003 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
5005 if (!lplNoNotifyFlags)
5006 return E_POINTER;
5008 *lplNoNotifyFlags = This->notif.disabled;
5010 return S_OK;
5014 static const IMediaEventExVtbl IMediaEventEx_VTable =
5016 MediaEvent_QueryInterface,
5017 MediaEvent_AddRef,
5018 MediaEvent_Release,
5019 MediaEvent_GetTypeInfoCount,
5020 MediaEvent_GetTypeInfo,
5021 MediaEvent_GetIDsOfNames,
5022 MediaEvent_Invoke,
5023 MediaEvent_GetEventHandle,
5024 MediaEvent_GetEvent,
5025 MediaEvent_WaitForCompletion,
5026 MediaEvent_CancelDefaultHandling,
5027 MediaEvent_RestoreDefaultHandling,
5028 MediaEvent_FreeEventParams,
5029 MediaEvent_SetNotifyWindow,
5030 MediaEvent_SetNotifyFlags,
5031 MediaEvent_GetNotifyFlags
5035 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, LPVOID *ppv)
5037 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5039 return Filtergraph_QueryInterface(This, riid, ppv);
5042 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
5044 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5046 return Filtergraph_AddRef(This);
5049 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
5051 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5053 return Filtergraph_Release(This);
5056 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
5058 FIXME("(%p): stub\n", pClassID);
5060 return E_NOTIMPL;
5063 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
5065 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5066 return MediaControl_Stop((IMediaControl*)&This->IMediaControl_vtbl);
5069 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5071 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5072 return MediaControl_Pause((IMediaControl*)&This->IMediaControl_vtbl);
5075 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
5077 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5078 if (tStart)
5079 FIXME("Run called with non-null tStart: %x%08x\n",
5080 (int)(tStart>>32), (int)tStart);
5081 return MediaControl_Run((IMediaControl*)&This->IMediaControl_vtbl);
5084 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout, FILTER_STATE * pState)
5086 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5087 return MediaControl_GetState((IMediaControl*)&This->IMediaControl_vtbl, dwMsTimeout, (OAFilterState*)pState);
5090 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5092 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5093 HRESULT hr = S_OK;
5094 int i;
5096 TRACE("(%p/%p)->(%p)\n", iface, This, pClock);
5098 EnterCriticalSection(&This->cs);
5100 for (i = 0;i < This->nFilters;i++)
5102 hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5103 if (FAILED(hr))
5104 break;
5107 if (FAILED(hr))
5109 for(;i >= 0;i--)
5110 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5112 else
5114 if (This->refClock)
5115 IReferenceClock_Release(This->refClock);
5116 This->refClock = pClock;
5117 if (This->refClock)
5118 IReferenceClock_AddRef(This->refClock);
5119 This->defaultclock = FALSE;
5121 if (This->HandleEcClockChanged)
5123 IMediaEventSink *pEventSink;
5124 HRESULT eshr;
5126 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (LPVOID)&pEventSink);
5127 if (SUCCEEDED(eshr))
5129 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5130 IMediaEventSink_Release(pEventSink);
5135 LeaveCriticalSection(&This->cs);
5137 return hr;
5140 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5142 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5144 TRACE("(%p/%p)->(%p)\n", iface, This, ppClock);
5146 if (!ppClock)
5147 return E_POINTER;
5149 EnterCriticalSection(&This->cs);
5151 *ppClock = This->refClock;
5152 if (*ppClock)
5153 IReferenceClock_AddRef(*ppClock);
5155 LeaveCriticalSection(&This->cs);
5157 return S_OK;
5160 static const IMediaFilterVtbl IMediaFilter_VTable =
5162 MediaFilter_QueryInterface,
5163 MediaFilter_AddRef,
5164 MediaFilter_Release,
5165 MediaFilter_GetClassID,
5166 MediaFilter_Stop,
5167 MediaFilter_Pause,
5168 MediaFilter_Run,
5169 MediaFilter_GetState,
5170 MediaFilter_SetSyncSource,
5171 MediaFilter_GetSyncSource
5174 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, LPVOID *ppv)
5176 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5178 return Filtergraph_QueryInterface(This, riid, ppv);
5181 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5183 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5185 return Filtergraph_AddRef(This);
5188 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5190 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5192 return Filtergraph_Release(This);
5195 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG EventCode, LONG_PTR EventParam1, LONG_PTR EventParam2)
5197 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5198 Event evt;
5200 TRACE("(%p/%p)->(%d, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5202 /* We need thread safety here, let's use the events queue's one */
5203 EnterCriticalSection(&This->evqueue.msg_crst);
5205 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5207 TRACE("Process EC_COMPLETE notification\n");
5208 if (++This->EcCompleteCount == This->nRenderers)
5210 evt.lEventCode = EC_COMPLETE;
5211 evt.lParam1 = S_OK;
5212 evt.lParam2 = 0;
5213 TRACE("Send EC_COMPLETE to app\n");
5214 EventsQueue_PutEvent(&This->evqueue, &evt);
5215 if (!This->notif.disabled && This->notif.hWnd)
5217 TRACE("Send Window message\n");
5218 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5220 This->CompletionStatus = EC_COMPLETE;
5221 SetEvent(This->hEventCompletion);
5224 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5226 /* FIXME: Not handled yet */
5228 else
5230 evt.lEventCode = EventCode;
5231 evt.lParam1 = EventParam1;
5232 evt.lParam2 = EventParam2;
5233 EventsQueue_PutEvent(&This->evqueue, &evt);
5234 if (!This->notif.disabled && This->notif.hWnd)
5235 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5238 LeaveCriticalSection(&This->evqueue.msg_crst);
5239 return S_OK;
5242 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5244 MediaEventSink_QueryInterface,
5245 MediaEventSink_AddRef,
5246 MediaEventSink_Release,
5247 MediaEventSink_Notify
5250 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, LPVOID *ppv)
5252 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5254 return Filtergraph_QueryInterface(This, riid, ppv);
5257 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5259 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5261 return Filtergraph_AddRef(This);
5264 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5266 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5268 return Filtergraph_Release(This);
5271 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface,
5272 IPin* pOutputPin,
5273 IPin* pInputPin,
5274 const AM_MEDIA_TYPE* pmtFirstConnection,
5275 IBaseFilter* pUsingFilter,
5276 HANDLE hAbortEvent,
5277 DWORD dwFlags)
5279 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5281 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5283 return E_NOTIMPL;
5286 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface,
5287 IGraphConfigCallback* pCallback,
5288 PVOID pvContext,
5289 DWORD dwFlags,
5290 HANDLE hAbortEvent)
5292 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5293 HRESULT hr;
5295 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5297 if (hAbortEvent)
5298 FIXME("The parameter hAbortEvent is not handled!\n");
5300 EnterCriticalSection(&This->cs);
5302 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5304 LeaveCriticalSection(&This->cs);
5306 return hr;
5309 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface,
5310 IBaseFilter* pFilter)
5312 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5314 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5316 return E_NOTIMPL;
5319 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface,
5320 IEnumFilters** pEnum)
5322 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5324 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5326 return E_NOTIMPL;
5329 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface,
5330 IBaseFilter* pFilter)
5332 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5334 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5336 return E_NOTIMPL;
5339 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface,
5340 REFERENCE_TIME* prtStart)
5342 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5344 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5346 return E_NOTIMPL;
5349 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface,
5350 IPin* pOutputPin,
5351 IPinConnection* pConnection,
5352 HANDLE hEventAbort)
5354 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5356 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5358 return E_NOTIMPL;
5361 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface,
5362 IBaseFilter* pFilter,
5363 DWORD dwFlags)
5365 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5367 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5369 return E_NOTIMPL;
5372 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface,
5373 IBaseFilter* pFilter,
5374 DWORD* dwFlags)
5376 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5378 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5380 return E_NOTIMPL;
5383 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface,
5384 IBaseFilter* pFilter,
5385 DWORD dwFlags)
5387 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5389 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5391 return E_NOTIMPL;
5394 static const IGraphConfigVtbl IGraphConfig_VTable =
5396 GraphConfig_QueryInterface,
5397 GraphConfig_AddRef,
5398 GraphConfig_Release,
5399 GraphConfig_Reconnect,
5400 GraphConfig_Reconfigure,
5401 GraphConfig_AddFilterToCache,
5402 GraphConfig_EnumCacheFilter,
5403 GraphConfig_RemoveFilterFromCache,
5404 GraphConfig_GetStartTime,
5405 GraphConfig_PushThroughData,
5406 GraphConfig_SetFilterFlags,
5407 GraphConfig_GetFilterFlags,
5408 GraphConfig_RemoveFilterEx
5411 static const IUnknownVtbl IInner_VTable =
5413 FilterGraphInner_QueryInterface,
5414 FilterGraphInner_AddRef,
5415 FilterGraphInner_Release
5418 static HRESULT Filtergraph_QueryInterface(IFilterGraphImpl *This,
5419 REFIID riid,
5420 LPVOID * ppv) {
5421 if (This->bAggregatable)
5422 This->bUnkOuterValid = TRUE;
5424 if (This->pUnkOuter)
5426 if (This->bAggregatable)
5427 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
5429 if (IsEqualIID(riid, &IID_IUnknown))
5431 HRESULT hr;
5433 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5434 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5435 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5436 This->bAggregatable = TRUE;
5437 return hr;
5440 *ppv = NULL;
5441 return E_NOINTERFACE;
5444 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5447 static ULONG Filtergraph_AddRef(IFilterGraphImpl *This) {
5448 if (This->pUnkOuter && This->bUnkOuterValid)
5449 return IUnknown_AddRef(This->pUnkOuter);
5450 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5453 static ULONG Filtergraph_Release(IFilterGraphImpl *This) {
5454 if (This->pUnkOuter && This->bUnkOuterValid)
5455 return IUnknown_Release(This->pUnkOuter);
5456 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5459 /* This is the only function that actually creates a FilterGraph class... */
5460 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5462 IFilterGraphImpl *fimpl;
5463 HRESULT hr;
5465 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5467 *ppObj = NULL;
5469 fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5470 fimpl->pUnkOuter = pUnkOuter;
5471 fimpl->bUnkOuterValid = FALSE;
5472 fimpl->bAggregatable = FALSE;
5473 fimpl->defaultclock = TRUE;
5474 fimpl->IInner_vtbl = &IInner_VTable;
5475 fimpl->IFilterGraph2_vtbl = &IFilterGraph2_VTable;
5476 fimpl->IMediaControl_vtbl = &IMediaControl_VTable;
5477 fimpl->IMediaSeeking_vtbl = &IMediaSeeking_VTable;
5478 fimpl->IBasicAudio_vtbl = &IBasicAudio_VTable;
5479 fimpl->IBasicVideo_vtbl = &IBasicVideo_VTable;
5480 fimpl->IVideoWindow_vtbl = &IVideoWindow_VTable;
5481 fimpl->IMediaEventEx_vtbl = &IMediaEventEx_VTable;
5482 fimpl->IMediaFilter_vtbl = &IMediaFilter_VTable;
5483 fimpl->IMediaEventSink_vtbl = &IMediaEventSink_VTable;
5484 fimpl->IGraphConfig_vtbl = &IGraphConfig_VTable;
5485 fimpl->IMediaPosition_vtbl = &IMediaPosition_VTable;
5486 fimpl->ref = 1;
5487 fimpl->ppFiltersInGraph = NULL;
5488 fimpl->pFilterNames = NULL;
5489 fimpl->nFilters = 0;
5490 fimpl->filterCapacity = 0;
5491 fimpl->nameIndex = 1;
5492 fimpl->refClock = NULL;
5493 fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5494 fimpl->HandleEcComplete = TRUE;
5495 fimpl->HandleEcRepaint = TRUE;
5496 fimpl->HandleEcClockChanged = TRUE;
5497 fimpl->notif.hWnd = 0;
5498 fimpl->notif.disabled = FALSE;
5499 fimpl->nRenderers = 0;
5500 fimpl->EcCompleteCount = 0;
5501 fimpl->refClockProvider = NULL;
5502 fimpl->state = State_Stopped;
5503 EventsQueue_Init(&fimpl->evqueue);
5504 InitializeCriticalSection(&fimpl->cs);
5505 fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5506 fimpl->nItfCacheEntries = 0;
5507 memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5508 fimpl->start_time = fimpl->pause_time = 0;
5509 fimpl->stop_position = -1;
5510 fimpl->punkFilterMapper2 = NULL;
5511 fimpl->recursioncount = 0;
5513 /* create Filtermapper aggregated. */
5514 hr = CoCreateInstance(&CLSID_FilterMapper2, pUnkOuter ? pUnkOuter : (IUnknown*)&fimpl->IInner_vtbl, CLSCTX_INPROC_SERVER,
5515 &IID_IUnknown, (LPVOID*)&fimpl->punkFilterMapper2);
5517 if (SUCCEEDED(hr)) {
5518 hr = IUnknown_QueryInterface(fimpl->punkFilterMapper2, &IID_IFilterMapper2, (LPVOID*)&fimpl->pFilterMapper2);
5521 if (SUCCEEDED(hr)) {
5522 /* Release controlling IUnknown - compensate refcount increase from caching IFilterMapper2 interface. */
5523 if (pUnkOuter) IUnknown_Release(pUnkOuter);
5524 else IUnknown_Release((IUnknown*)&fimpl->IInner_vtbl);
5527 if (FAILED(hr)) {
5528 ERR("Unable to create filter mapper (%x)\n", hr);
5529 if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5530 CloseHandle(fimpl->hEventCompletion);
5531 EventsQueue_Destroy(&fimpl->evqueue);
5532 fimpl->cs.DebugInfo->Spare[0] = 0;
5533 DeleteCriticalSection(&fimpl->cs);
5534 CoTaskMemFree(fimpl);
5535 return hr;
5538 *ppObj = fimpl;
5539 return S_OK;
5542 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5544 FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5545 return FilterGraph_create(pUnkOuter, ppObj);