quartz: If the MediaSeeking is not implemented all the way up the passthru chain...
[wine.git] / dlls / quartz / filtergraph.c
blob911e68c1f6c4179459321ece3ee446f52edda4fc
1 /* DirectShow FilterGraph object (QUARTZ.DLL)
3 * Copyright 2002 Lionel Ulmer
4 * Copyright 2004 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include <stdarg.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "shlwapi.h"
31 #include "dshow.h"
32 #include "wine/debug.h"
33 #include "quartz_private.h"
34 #include "ole2.h"
35 #include "olectl.h"
36 #include "strmif.h"
37 #include "vfwmsgs.h"
38 #include "evcode.h"
39 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
44 typedef struct {
45 HWND hWnd; /* Target window */
46 UINT msg; /* User window message */
47 LONG_PTR instance; /* User data */
48 int disabled; /* Disabled messages posting */
49 } WndNotify;
51 typedef struct {
52 LONG lEventCode; /* Event code */
53 LONG_PTR lParam1; /* Param1 */
54 LONG_PTR lParam2; /* Param2 */
55 } Event;
57 /* messages ring implementation for queuing events (taken from winmm) */
58 #define EVENTS_RING_BUFFER_INCREMENT 64
59 typedef struct {
60 Event* messages;
61 int ring_buffer_size;
62 int msg_tosave;
63 int msg_toget;
64 CRITICAL_SECTION msg_crst;
65 HANDLE msg_event; /* Signaled for no empty queue */
66 } EventsQueue;
68 static int EventsQueue_Init(EventsQueue* omr)
70 omr->msg_toget = 0;
71 omr->msg_tosave = 0;
72 omr->msg_event = CreateEventW(NULL, TRUE, FALSE, NULL);
73 omr->ring_buffer_size = EVENTS_RING_BUFFER_INCREMENT;
74 omr->messages = CoTaskMemAlloc(omr->ring_buffer_size * sizeof(Event));
75 ZeroMemory(omr->messages, omr->ring_buffer_size * sizeof(Event));
77 InitializeCriticalSection(&omr->msg_crst);
78 omr->msg_crst.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": EventsQueue.msg_crst");
79 return TRUE;
82 static int EventsQueue_Destroy(EventsQueue* omr)
84 CloseHandle(omr->msg_event);
85 CoTaskMemFree(omr->messages);
86 omr->msg_crst.DebugInfo->Spare[0] = 0;
87 DeleteCriticalSection(&omr->msg_crst);
88 return TRUE;
91 static int EventsQueue_PutEvent(EventsQueue* omr, const Event* evt)
93 EnterCriticalSection(&omr->msg_crst);
94 if (omr->msg_toget == ((omr->msg_tosave + 1) % omr->ring_buffer_size))
96 int old_ring_buffer_size = omr->ring_buffer_size;
97 omr->ring_buffer_size += EVENTS_RING_BUFFER_INCREMENT;
98 TRACE("omr->ring_buffer_size=%d\n",omr->ring_buffer_size);
99 omr->messages = CoTaskMemRealloc(omr->messages, omr->ring_buffer_size * sizeof(Event));
100 /* Now we need to rearrange the ring buffer so that the new
101 buffers just allocated are in between omr->msg_tosave and
102 omr->msg_toget.
104 if (omr->msg_tosave < omr->msg_toget)
106 memmove(&(omr->messages[omr->msg_toget + EVENTS_RING_BUFFER_INCREMENT]),
107 &(omr->messages[omr->msg_toget]),
108 sizeof(Event)*(old_ring_buffer_size - omr->msg_toget)
110 omr->msg_toget += EVENTS_RING_BUFFER_INCREMENT;
113 omr->messages[omr->msg_tosave] = *evt;
114 SetEvent(omr->msg_event);
115 omr->msg_tosave = (omr->msg_tosave + 1) % omr->ring_buffer_size;
116 LeaveCriticalSection(&omr->msg_crst);
117 return TRUE;
120 static int EventsQueue_GetEvent(EventsQueue* omr, Event* evt, LONG msTimeOut)
122 if (WaitForSingleObject(omr->msg_event, msTimeOut) != WAIT_OBJECT_0)
123 return FALSE;
125 EnterCriticalSection(&omr->msg_crst);
127 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
129 LeaveCriticalSection(&omr->msg_crst);
130 return FALSE;
133 *evt = omr->messages[omr->msg_toget];
134 omr->msg_toget = (omr->msg_toget + 1) % omr->ring_buffer_size;
136 /* Mark the buffer as empty if needed */
137 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
138 ResetEvent(omr->msg_event);
140 LeaveCriticalSection(&omr->msg_crst);
141 return TRUE;
144 #define MAX_ITF_CACHE_ENTRIES 3
145 typedef struct _ITF_CACHE_ENTRY {
146 const IID* riid;
147 IBaseFilter* filter;
148 IUnknown* iface;
149 } ITF_CACHE_ENTRY;
151 typedef struct _IFilterGraphImpl {
152 IFilterGraph2 IFilterGraph2_iface;
153 IMediaControl IMediaControl_iface;
154 IMediaSeeking IMediaSeeking_iface;
155 IBasicAudio IBasicAudio_iface;
156 IBasicVideo2 IBasicVideo2_iface;
157 IVideoWindow IVideoWindow_iface;
158 IMediaEventEx IMediaEventEx_iface;
159 IMediaFilter IMediaFilter_iface;
160 IMediaEventSink IMediaEventSink_iface;
161 IGraphConfig IGraphConfig_iface;
162 IMediaPosition IMediaPosition_iface;
163 IObjectWithSite IObjectWithSite_iface;
164 const IUnknownVtbl * IInner_vtbl;
165 /* IAMGraphStreams */
166 /* IAMStats */
167 /* IFilterChain */
168 /* IFilterMapper2 */
169 /* IGraphVersion */
170 /* IQueueCommand */
171 /* IRegisterServiceProvider */
172 /* IResourceMananger */
173 /* IServiceProvider */
174 /* IVideoFrameStep */
176 LONG ref;
177 IUnknown *punkFilterMapper2;
178 IFilterMapper2 * pFilterMapper2;
179 IBaseFilter ** ppFiltersInGraph;
180 LPWSTR * pFilterNames;
181 int nFilters;
182 int filterCapacity;
183 LONG nameIndex;
184 IReferenceClock *refClock;
185 IBaseFilter *refClockProvider;
186 EventsQueue evqueue;
187 HANDLE hEventCompletion;
188 int CompletionStatus;
189 WndNotify notif;
190 int nRenderers;
191 int EcCompleteCount;
192 int HandleEcComplete;
193 int HandleEcRepaint;
194 int HandleEcClockChanged;
195 OAFilterState state;
196 CRITICAL_SECTION cs;
197 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
198 int nItfCacheEntries;
199 IUnknown * pUnkOuter;
200 BOOL bUnkOuterValid;
201 BOOL bAggregatable;
202 BOOL defaultclock;
203 GUID timeformatseek;
204 REFERENCE_TIME start_time;
205 REFERENCE_TIME pause_time;
206 LONGLONG stop_position;
207 LONG recursioncount;
208 IUnknown *pSite;
209 } IFilterGraphImpl;
211 static HRESULT Filtergraph_QueryInterface(IFilterGraphImpl *This,
212 REFIID riid, LPVOID * ppv);
213 static ULONG Filtergraph_AddRef(IFilterGraphImpl *This);
214 static ULONG Filtergraph_Release(IFilterGraphImpl *This);
216 static HRESULT WINAPI FilterGraphInner_QueryInterface(IUnknown * iface,
217 REFIID riid,
218 LPVOID *ppvObj) {
219 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
220 TRACE("(%p)->(%s (%p), %p)\n", This, debugstr_guid(riid), riid, ppvObj);
222 if (This->bAggregatable)
223 This->bUnkOuterValid = TRUE;
225 if (IsEqualGUID(&IID_IUnknown, riid)) {
226 *ppvObj = &(This->IInner_vtbl);
227 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
228 } else if (IsEqualGUID(&IID_IFilterGraph, riid) ||
229 IsEqualGUID(&IID_IFilterGraph2, riid) ||
230 IsEqualGUID(&IID_IGraphBuilder, riid)) {
231 *ppvObj = &This->IFilterGraph2_iface;
232 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj);
233 } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
234 *ppvObj = &This->IMediaControl_iface;
235 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj);
236 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
237 *ppvObj = &This->IMediaSeeking_iface;
238 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
239 } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
240 *ppvObj = &This->IBasicAudio_iface;
241 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj);
242 } else if (IsEqualGUID(&IID_IBasicVideo, riid) ||
243 IsEqualGUID(&IID_IBasicVideo2, riid)) {
244 *ppvObj = &This->IBasicVideo2_iface;
245 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj);
246 } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
247 *ppvObj = &This->IVideoWindow_iface;
248 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj);
249 } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
250 IsEqualGUID(&IID_IMediaEventEx, riid)) {
251 *ppvObj = &This->IMediaEventEx_iface;
252 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
253 } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
254 IsEqualGUID(&IID_IPersist, riid)) {
255 *ppvObj = &This->IMediaFilter_iface;
256 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj);
257 } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
258 *ppvObj = &This->IMediaEventSink_iface;
259 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj);
260 } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
261 *ppvObj = &This->IGraphConfig_iface;
262 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
263 } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
264 *ppvObj = &This->IMediaPosition_iface;
265 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj);
266 } else if (IsEqualGUID(&IID_IObjectWithSite, riid)) {
267 *ppvObj = &This->IObjectWithSite_iface;
268 TRACE(" returning IObjectWithSite interface (%p)\n", *ppvObj);
269 } else if (IsEqualGUID(&IID_IFilterMapper, riid)) {
270 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj);
271 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
272 } else if (IsEqualGUID(&IID_IFilterMapper2, riid)) {
273 *ppvObj = This->pFilterMapper2;
274 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
275 } else if (IsEqualGUID(&IID_IFilterMapper3, riid)) {
276 *ppvObj = This->pFilterMapper2;
277 TRACE(" returning IFilterMapper3 interface from aggregated filtermapper (%p)\n", *ppvObj);
278 } else {
279 *ppvObj = NULL;
280 FIXME("unknown interface %s\n", debugstr_guid(riid));
281 return E_NOINTERFACE;
284 IUnknown_AddRef((IUnknown *)(*ppvObj));
285 return S_OK;
288 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown * iface) {
289 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
290 ULONG ref = InterlockedIncrement(&This->ref);
292 TRACE("(%p)->(): new ref = %d\n", This, ref);
294 return ref;
297 static ULONG WINAPI FilterGraphInner_Release(IUnknown * iface)
299 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
300 ULONG ref = InterlockedDecrement(&This->ref);
302 TRACE("(%p)->(): new ref = %d\n", This, ref);
304 if (ref == 0) {
305 int i;
307 This->ref = 1; /* guard against reentrancy (aggregation). */
309 IMediaControl_Stop(&This->IMediaControl_iface);
311 while (This->nFilters)
312 IFilterGraph2_RemoveFilter((IFilterGraph2*)This, This->ppFiltersInGraph[0]);
314 if (This->refClock)
315 IReferenceClock_Release(This->refClock);
317 for (i = 0; i < This->nItfCacheEntries; i++)
319 if (This->ItfCacheEntries[i].iface)
320 IUnknown_Release(This->ItfCacheEntries[i].iface);
323 /* AddRef on controlling IUnknown, to compensate for Release of cached IFilterMapper2 interface below.
325 * NOTE: Filtergraph_AddRef isn't suitable, because bUnkOuterValid may be FALSE but punkOuter non-NULL
326 * and already passed as punkOuter to filtermapper in FilterGraph_create - this will happen in case of
327 * CoCreateInstance of filtergraph with non-null pUnkOuter and REFIID other than IID_Unknown that is
328 * cleaning up after error. */
329 if (This->pUnkOuter) IUnknown_AddRef(This->pUnkOuter);
330 else IUnknown_AddRef((IUnknown*)&This->IInner_vtbl);
332 IFilterMapper2_Release(This->pFilterMapper2);
333 IUnknown_Release(This->punkFilterMapper2);
335 if (This->pSite) IUnknown_Release(This->pSite);
337 CloseHandle(This->hEventCompletion);
338 EventsQueue_Destroy(&This->evqueue);
339 This->cs.DebugInfo->Spare[0] = 0;
340 DeleteCriticalSection(&This->cs);
341 CoTaskMemFree(This->ppFiltersInGraph);
342 CoTaskMemFree(This->pFilterNames);
343 CoTaskMemFree(This);
345 return ref;
348 static inline IFilterGraphImpl *impl_from_IFilterGraph2(IFilterGraph2 *iface)
350 return CONTAINING_RECORD(iface, IFilterGraphImpl, IFilterGraph2_iface);
353 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface, REFIID riid, void **ppvObj)
355 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
357 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
359 return Filtergraph_QueryInterface(This, riid, ppvObj);
362 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface)
364 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
366 TRACE("(%p/%p)->() calling FilterGraph AddRef\n", This, iface);
368 return Filtergraph_AddRef(This);
371 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface)
373 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
375 TRACE("(%p/%p)->() calling FilterGraph Release\n", This, iface);
377 return Filtergraph_Release(This);
380 /*** IFilterGraph methods ***/
381 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface, IBaseFilter *pFilter,
382 LPCWSTR pName)
384 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
385 HRESULT hr;
386 int i,j;
387 WCHAR* wszFilterName = NULL;
388 int duplicate_name = FALSE;
390 TRACE("(%p/%p)->(%p, %s (%p))\n", This, iface, pFilter, debugstr_w(pName), pName);
392 if (!pFilter)
393 return E_POINTER;
395 wszFilterName = CoTaskMemAlloc( (pName ? strlenW(pName) + 6 : 5) * sizeof(WCHAR) );
397 if (pName)
399 /* Check if name already exists */
400 for(i = 0; i < This->nFilters; i++)
401 if (!strcmpW(This->pFilterNames[i], pName))
403 duplicate_name = TRUE;
404 break;
408 /* If no name given or name already existing, generate one */
409 if (!pName || duplicate_name)
411 static const WCHAR wszFmt1[] = {'%','s',' ','%','0','4','d',0};
412 static const WCHAR wszFmt2[] = {'%','0','4','d',0};
414 for (j = 0; j < 10000 ; j++)
416 /* Create name */
417 if (pName)
418 sprintfW(wszFilterName, wszFmt1, pName, This->nameIndex);
419 else
420 sprintfW(wszFilterName, wszFmt2, This->nameIndex);
421 TRACE("Generated name %s\n", debugstr_w(wszFilterName));
423 /* Check if the generated name already exists */
424 for(i = 0; i < This->nFilters; i++)
425 if (!strcmpW(This->pFilterNames[i], wszFilterName))
426 break;
428 /* Compute next index and exit if generated name is suitable */
429 if (This->nameIndex++ == 10000)
430 This->nameIndex = 1;
431 if (i == This->nFilters)
432 break;
434 /* Unable to find a suitable name */
435 if (j == 10000)
437 CoTaskMemFree(wszFilterName);
438 return VFW_E_DUPLICATE_NAME;
441 else
442 memcpy(wszFilterName, pName, (strlenW(pName) + 1) * sizeof(WCHAR));
444 if (This->nFilters + 1 > This->filterCapacity)
446 int newCapacity = This->filterCapacity ? 2 * This->filterCapacity : 1;
447 IBaseFilter ** ppNewFilters = CoTaskMemAlloc(newCapacity * sizeof(IBaseFilter*));
448 LPWSTR * pNewNames = CoTaskMemAlloc(newCapacity * sizeof(LPWSTR));
449 memcpy(ppNewFilters, This->ppFiltersInGraph, This->nFilters * sizeof(IBaseFilter*));
450 memcpy(pNewNames, This->pFilterNames, This->nFilters * sizeof(LPWSTR));
451 if (This->filterCapacity)
453 CoTaskMemFree(This->ppFiltersInGraph);
454 CoTaskMemFree(This->pFilterNames);
456 This->ppFiltersInGraph = ppNewFilters;
457 This->pFilterNames = pNewNames;
458 This->filterCapacity = newCapacity;
461 hr = IBaseFilter_JoinFilterGraph(pFilter, (IFilterGraph *)This, wszFilterName);
463 if (SUCCEEDED(hr))
465 IBaseFilter_AddRef(pFilter);
466 This->ppFiltersInGraph[This->nFilters] = pFilter;
467 This->pFilterNames[This->nFilters] = wszFilterName;
468 This->nFilters++;
469 IBaseFilter_SetSyncSource(pFilter, This->refClock);
471 else
472 CoTaskMemFree(wszFilterName);
474 if (SUCCEEDED(hr) && duplicate_name)
475 return VFW_S_DUPLICATE_NAME;
477 return hr;
480 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
482 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
483 int i;
484 HRESULT hr = E_FAIL;
486 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
488 /* FIXME: check graph is stopped */
490 for (i = 0; i < This->nFilters; i++)
492 if (This->ppFiltersInGraph[i] == pFilter)
494 IEnumPins *penumpins = NULL;
495 FILTER_STATE state;
497 if (This->defaultclock && This->refClockProvider == pFilter)
499 IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, NULL);
500 This->defaultclock = 1;
503 TRACE("Removing filter %s\n", debugstr_w(This->pFilterNames[i]));
504 IBaseFilter_GetState(pFilter, 0, &state);
505 if (state == State_Running)
506 IBaseFilter_Pause(pFilter);
507 if (state != State_Stopped)
508 IBaseFilter_Stop(pFilter);
510 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
511 if (SUCCEEDED(hr)) {
512 IPin *ppin;
513 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
515 IPin *victim = NULL;
516 HRESULT h;
517 IPin_ConnectedTo(ppin, &victim);
518 if (victim)
520 h = IPin_Disconnect(victim);
521 TRACE("Disconnect other side: %08x\n", h);
522 if (h == VFW_E_NOT_STOPPED)
524 PIN_INFO pinfo;
525 IPin_QueryPinInfo(victim, &pinfo);
527 IBaseFilter_GetState(pinfo.pFilter, 0, &state);
528 if (state == State_Running)
529 IBaseFilter_Pause(pinfo.pFilter);
530 IBaseFilter_Stop(pinfo.pFilter);
531 IBaseFilter_Release(pinfo.pFilter);
532 h = IPin_Disconnect(victim);
533 TRACE("Disconnect retry: %08x\n", h);
535 IPin_Release(victim);
537 h = IPin_Disconnect(ppin);
538 TRACE("Disconnect 2: %08x\n", h);
540 IPin_Release(ppin);
542 IEnumPins_Release(penumpins);
545 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, This->pFilterNames[i]);
546 if (SUCCEEDED(hr))
548 IBaseFilter_SetSyncSource(pFilter, NULL);
549 IBaseFilter_Release(pFilter);
550 CoTaskMemFree(This->pFilterNames[i]);
551 memmove(This->ppFiltersInGraph+i, This->ppFiltersInGraph+i+1, sizeof(IBaseFilter*)*(This->nFilters - 1 - i));
552 memmove(This->pFilterNames+i, This->pFilterNames+i+1, sizeof(LPWSTR)*(This->nFilters - 1 - i));
553 This->nFilters--;
554 /* Invalidate interfaces in the cache */
555 for (i = 0; i < This->nItfCacheEntries; i++)
556 if (pFilter == This->ItfCacheEntries[i].filter)
558 IUnknown_Release(This->ItfCacheEntries[i].iface);
559 This->ItfCacheEntries[i].iface = NULL;
560 This->ItfCacheEntries[i].filter = NULL;
562 return S_OK;
564 break;
568 return hr; /* FIXME: check this error code */
571 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface, IEnumFilters **ppEnum)
573 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
575 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
577 return IEnumFiltersImpl_Construct(This->ppFiltersInGraph, This->nFilters, ppEnum);
580 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface, LPCWSTR pName,
581 IBaseFilter **ppFilter)
583 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
584 int i;
586 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_w(pName), pName, ppFilter);
588 if (!ppFilter)
589 return E_POINTER;
591 for (i = 0; i < This->nFilters; i++)
593 if (!strcmpW(pName, This->pFilterNames[i]))
595 *ppFilter = This->ppFiltersInGraph[i];
596 IBaseFilter_AddRef(*ppFilter);
597 return S_OK;
601 *ppFilter = NULL;
602 return VFW_E_NOT_FOUND;
605 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
606 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
608 static HRESULT CheckCircularConnection(IFilterGraphImpl *This, IPin *out, IPin *in)
610 #if 1
611 HRESULT hr;
612 PIN_INFO info_out, info_in;
614 hr = IPin_QueryPinInfo(out, &info_out);
615 if (FAILED(hr))
616 return hr;
617 if (info_out.dir != PINDIR_OUTPUT)
619 IBaseFilter_Release(info_out.pFilter);
620 return E_UNEXPECTED;
623 hr = IPin_QueryPinInfo(in, &info_in);
624 if (SUCCEEDED(hr))
625 IBaseFilter_Release(info_in.pFilter);
626 if (FAILED(hr))
627 goto out;
628 if (info_in.dir != PINDIR_INPUT)
630 hr = E_UNEXPECTED;
631 goto out;
634 if (info_out.pFilter == info_in.pFilter)
635 hr = VFW_E_CIRCULAR_GRAPH;
636 else
638 IEnumPins *enumpins;
639 IPin *test;
641 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
642 if (FAILED(hr))
643 goto out;
645 IEnumPins_Reset(enumpins);
646 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
648 PIN_DIRECTION dir = PINDIR_OUTPUT;
649 IPin_QueryDirection(test, &dir);
650 if (dir == PINDIR_INPUT)
652 IPin *victim = NULL;
653 IPin_ConnectedTo(test, &victim);
654 if (victim)
656 hr = CheckCircularConnection(This, victim, in);
657 IPin_Release(victim);
658 if (FAILED(hr))
660 IPin_Release(test);
661 break;
665 IPin_Release(test);
667 IEnumPins_Release(enumpins);
670 out:
671 IBaseFilter_Release(info_out.pFilter);
672 if (FAILED(hr))
673 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
674 return hr;
675 #else
676 /* Debugging filtergraphs not enabled */
677 return S_OK;
678 #endif
682 /* NOTE: despite the implication, it doesn't matter which
683 * way round you put in the input and output pins */
684 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppinIn, IPin *ppinOut,
685 const AM_MEDIA_TYPE *pmt)
687 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
688 PIN_DIRECTION dir;
689 HRESULT hr;
691 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
693 /* FIXME: check pins are in graph */
695 if (TRACE_ON(quartz))
697 PIN_INFO PinInfo;
699 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
700 if (FAILED(hr))
701 return hr;
703 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
704 IBaseFilter_Release(PinInfo.pFilter);
706 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
707 if (FAILED(hr))
708 return hr;
710 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
711 IBaseFilter_Release(PinInfo.pFilter);
714 hr = IPin_QueryDirection(ppinIn, &dir);
715 if (SUCCEEDED(hr))
717 if (dir == PINDIR_INPUT)
719 hr = CheckCircularConnection(This, ppinOut, ppinIn);
720 if (SUCCEEDED(hr))
721 hr = IPin_Connect(ppinOut, ppinIn, pmt);
723 else
725 hr = CheckCircularConnection(This, ppinIn, ppinOut);
726 if (SUCCEEDED(hr))
727 hr = IPin_Connect(ppinIn, ppinOut, pmt);
731 return hr;
734 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface, IPin *ppin)
736 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
737 IPin *pConnectedTo = NULL;
738 HRESULT hr;
739 PIN_DIRECTION pindir;
741 IPin_QueryDirection(ppin, &pindir);
742 hr = IPin_ConnectedTo(ppin, &pConnectedTo);
743 if (FAILED(hr)) {
744 TRACE("Querying connected to failed: %x\n", hr);
745 return hr;
747 IPin_Disconnect(ppin);
748 IPin_Disconnect(pConnectedTo);
749 if (pindir == PINDIR_INPUT)
750 hr = IPin_Connect(pConnectedTo, ppin, NULL);
751 else
752 hr = IPin_Connect(ppin, pConnectedTo, NULL);
753 IPin_Release(pConnectedTo);
754 if (FAILED(hr))
755 WARN("Reconnecting pins failed, pins are not connected now..\n");
756 TRACE("(%p->%p) -- %p %p -> %x\n", iface, This, ppin, pConnectedTo, hr);
757 return hr;
760 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
762 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
764 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
766 if (!ppin)
767 return E_POINTER;
769 return IPin_Disconnect(ppin);
772 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
774 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
775 IReferenceClock *pClock = NULL;
776 HRESULT hr = S_OK;
777 int i;
779 TRACE("(%p/%p)->() live sources not handled properly!\n", iface, This);
781 EnterCriticalSection(&This->cs);
783 for (i = 0; i < This->nFilters; ++i)
785 DWORD miscflags;
786 IAMFilterMiscFlags *flags = NULL;
787 IUnknown_QueryInterface(This->ppFiltersInGraph[i], &IID_IAMFilterMiscFlags, (void**)&flags);
788 if (!flags)
789 continue;
790 miscflags = IAMFilterMiscFlags_GetMiscFlags(flags);
791 IUnknown_Release(flags);
792 if (miscflags == AM_FILTER_MISC_FLAGS_IS_RENDERER)
793 IUnknown_QueryInterface(This->ppFiltersInGraph[i], &IID_IReferenceClock, (void**)&pClock);
794 if (pClock)
795 break;
798 if (!pClock)
800 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
801 This->refClockProvider = NULL;
803 else
804 This->refClockProvider = This->ppFiltersInGraph[i];
806 if (SUCCEEDED(hr))
808 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
809 This->defaultclock = TRUE;
810 IReferenceClock_Release(pClock);
812 LeaveCriticalSection(&This->cs);
814 return hr;
817 static HRESULT GetFilterInfo(IMoniker* pMoniker, GUID* pclsid, VARIANT* pvar)
819 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
820 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
821 IPropertyBag * pPropBagCat = NULL;
822 HRESULT hr;
824 VariantInit(pvar);
826 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
828 if (SUCCEEDED(hr))
829 hr = IPropertyBag_Read(pPropBagCat, wszClsidName, pvar, NULL);
831 if (SUCCEEDED(hr))
832 hr = CLSIDFromString(V_UNION(pvar, bstrVal), pclsid);
834 VariantClear(pvar);
836 if (SUCCEEDED(hr))
837 hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL);
839 if (SUCCEEDED(hr))
840 TRACE("Moniker = %s - %s\n", debugstr_guid(pclsid), debugstr_w(V_UNION(pvar, bstrVal)));
842 if (pPropBagCat)
843 IPropertyBag_Release(pPropBagCat);
845 return hr;
848 static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPin*** pppins, ULONG* pnb)
850 HRESULT hr;
851 ULONG nb = 0;
853 TRACE("(%p, %p, %p, %p)\n", pfilter, pinputpin, pppins, pnb);
854 hr = IPin_QueryInternalConnections(pinputpin, NULL, &nb);
855 if (hr == S_OK) {
856 /* Rendered input */
857 } else if (hr == S_FALSE) {
858 *pppins = CoTaskMemAlloc(sizeof(IPin*)*nb);
859 hr = IPin_QueryInternalConnections(pinputpin, *pppins, &nb);
860 if (hr != S_OK) {
861 WARN("Error (%x)\n", hr);
863 } else if (hr == E_NOTIMPL) {
864 /* Input connected to all outputs */
865 IEnumPins* penumpins;
866 IPin* ppin;
867 int i = 0;
868 TRACE("E_NOTIMPL\n");
869 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
870 if (FAILED(hr)) {
871 WARN("filter Enumpins failed (%x)\n", hr);
872 return hr;
874 i = 0;
875 /* Count output pins */
876 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
877 PIN_DIRECTION pindir;
878 IPin_QueryDirection(ppin, &pindir);
879 if (pindir == PINDIR_OUTPUT)
880 i++;
881 IPin_Release(ppin);
883 *pppins = CoTaskMemAlloc(sizeof(IPin*)*i);
884 /* Retrieve output pins */
885 IEnumPins_Reset(penumpins);
886 i = 0;
887 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
888 PIN_DIRECTION pindir;
889 IPin_QueryDirection(ppin, &pindir);
890 if (pindir == PINDIR_OUTPUT)
891 (*pppins)[i++] = ppin;
892 else
893 IPin_Release(ppin);
895 IEnumPins_Release(penumpins);
896 nb = i;
897 if (FAILED(hr)) {
898 WARN("Next failed (%x)\n", hr);
899 return hr;
901 } else if (FAILED(hr)) {
902 WARN("Cannot get internal connection (%x)\n", hr);
903 return hr;
906 *pnb = nb;
907 return S_OK;
910 /*** IGraphBuilder methods ***/
911 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IPin *ppinIn)
913 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
914 HRESULT hr;
915 AM_MEDIA_TYPE* mt = NULL;
916 IEnumMediaTypes* penummt = NULL;
917 ULONG nbmt;
918 IEnumPins* penumpins;
919 IEnumMoniker* pEnumMoniker;
920 GUID tab[2];
921 ULONG nb;
922 IMoniker* pMoniker;
923 ULONG pin;
924 PIN_INFO PinInfo;
925 CLSID FilterCLSID;
926 PIN_DIRECTION dir;
928 TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
930 if (TRACE_ON(quartz))
932 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
933 if (FAILED(hr))
934 return hr;
936 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
937 IBaseFilter_Release(PinInfo.pFilter);
939 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
940 if (FAILED(hr))
941 return hr;
943 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
944 IBaseFilter_Release(PinInfo.pFilter);
947 EnterCriticalSection(&This->cs);
948 ++This->recursioncount;
949 if (This->recursioncount >= 5)
951 WARN("Recursion count has reached %d\n", This->recursioncount);
952 hr = VFW_E_CANNOT_CONNECT;
953 goto out;
956 hr = IPin_QueryDirection(ppinOut, &dir);
957 if (FAILED(hr))
958 goto out;
960 if (dir == PINDIR_INPUT)
962 IPin *temp;
964 temp = ppinIn;
965 ppinIn = ppinOut;
966 ppinOut = temp;
969 hr = CheckCircularConnection(This, ppinOut, ppinIn);
970 if (FAILED(hr))
971 goto out;
973 /* Try direct connection first */
974 hr = IPin_Connect(ppinOut, ppinIn, NULL);
975 if (SUCCEEDED(hr))
976 goto out;
978 TRACE("Direct connection failed, trying to render using extra filters\n");
980 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
981 if (FAILED(hr))
982 goto out;
984 hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
985 IBaseFilter_Release(PinInfo.pFilter);
986 if (FAILED(hr))
987 goto out;
989 /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream
990 * filter to the minor mediatype of input pin of the renderer */
991 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
992 if (FAILED(hr))
994 WARN("EnumMediaTypes (%x)\n", hr);
995 goto out;
998 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
999 if (FAILED(hr)) {
1000 WARN("IEnumMediaTypes_Next (%x)\n", hr);
1001 goto out;
1004 if (!nbmt)
1006 WARN("No media type found!\n");
1007 hr = VFW_E_INVALIDMEDIATYPE;
1008 goto out;
1010 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1011 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1013 /* Try to find a suitable filter that can connect to the pin to render */
1014 tab[0] = mt->majortype;
1015 tab[1] = mt->subtype;
1016 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1017 if (FAILED(hr)) {
1018 WARN("Unable to enum filters (%x)\n", hr);
1019 goto out;
1022 hr = VFW_E_CANNOT_RENDER;
1023 while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1025 VARIANT var;
1026 GUID clsid;
1027 IPin** ppins;
1028 IPin* ppinfilter = NULL;
1029 IBaseFilter* pfilter = NULL;
1030 IAMGraphBuilderCallback *callback = NULL;
1032 hr = GetFilterInfo(pMoniker, &clsid, &var);
1033 IMoniker_Release(pMoniker);
1034 if (FAILED(hr)) {
1035 WARN("Unable to retrieve filter info (%x)\n", hr);
1036 goto error;
1039 if (IsEqualGUID(&clsid, &FilterCLSID)) {
1040 /* Skip filter (same as the one the output pin belongs to) */
1041 goto error;
1044 if (This->pSite)
1046 IUnknown_QueryInterface(This->pSite, &IID_IAMGraphBuilderCallback, (LPVOID*)&callback);
1047 if (callback)
1049 HRESULT rc;
1050 rc = IAMGraphBuilderCallback_SelectedFilter(callback, pMoniker);
1051 if (FAILED(rc))
1053 TRACE("Filter rejected by IAMGraphBuilderCallback_SelectedFilter\n");
1054 IUnknown_Release(callback);
1055 goto error;
1060 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
1061 if (FAILED(hr)) {
1062 WARN("Unable to create filter (%x), trying next one\n", hr);
1063 goto error;
1066 if (callback)
1068 HRESULT rc;
1069 rc = IAMGraphBuilderCallback_CreatedFilter(callback, pfilter);
1070 IUnknown_Release(callback);
1071 if (FAILED(rc))
1073 IBaseFilter_Release(pfilter);
1074 pfilter = NULL;
1075 TRACE("Filter rejected by IAMGraphBuilderCallback_CreatedFilter\n");
1076 goto error;
1080 hr = IFilterGraph2_AddFilter(iface, pfilter, V_UNION(&var, bstrVal));
1081 if (FAILED(hr)) {
1082 WARN("Unable to add filter (%x)\n", hr);
1083 IBaseFilter_Release(pfilter);
1084 pfilter = NULL;
1085 goto error;
1088 VariantClear(&var);
1090 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1091 if (FAILED(hr)) {
1092 WARN("Enumpins (%x)\n", hr);
1093 goto error;
1096 hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin);
1097 IEnumPins_Release(penumpins);
1099 if (FAILED(hr)) {
1100 WARN("Obtaining next pin: (%x)\n", hr);
1101 goto error;
1103 if (pin == 0) {
1104 WARN("Cannot use this filter: no pins\n");
1105 goto error;
1108 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1109 if (FAILED(hr)) {
1110 TRACE("Cannot connect to filter (%x), trying next one\n", hr);
1111 goto error;
1113 TRACE("Successfully connected to filter, follow chain...\n");
1115 /* Render all output pins of the filter by calling IFilterGraph2_Connect on each of them */
1116 hr = GetInternalConnections(pfilter, ppinfilter, &ppins, &nb);
1118 if (SUCCEEDED(hr)) {
1119 unsigned int i;
1120 if (nb == 0) {
1121 IPin_Disconnect(ppinfilter);
1122 IPin_Disconnect(ppinOut);
1123 goto error;
1125 TRACE("pins to consider: %d\n", nb);
1126 for(i = 0; i < nb; i++)
1128 LPWSTR pinname = NULL;
1130 TRACE("Processing pin %u\n", i);
1132 hr = IPin_QueryId(ppins[i], &pinname);
1133 if (SUCCEEDED(hr))
1135 if (pinname[0] == '~')
1137 TRACE("Pinname=%s, skipping\n", debugstr_w(pinname));
1138 hr = E_FAIL;
1140 else
1141 hr = IFilterGraph2_Connect(iface, ppins[i], ppinIn);
1142 CoTaskMemFree(pinname);
1145 if (FAILED(hr)) {
1146 TRACE("Cannot connect pin %p (%x)\n", ppinfilter, hr);
1148 IPin_Release(ppins[i]);
1149 if (SUCCEEDED(hr)) break;
1151 while (++i < nb) IPin_Release(ppins[i]);
1152 CoTaskMemFree(ppins);
1153 IPin_Release(ppinfilter);
1154 IBaseFilter_Release(pfilter);
1155 if (FAILED(hr))
1157 IPin_Disconnect(ppinfilter);
1158 IPin_Disconnect(ppinOut);
1159 IFilterGraph2_RemoveFilter(iface, pfilter);
1160 continue;
1162 break;
1165 error:
1166 VariantClear(&var);
1167 if (ppinfilter) IPin_Release(ppinfilter);
1168 if (pfilter) {
1169 IFilterGraph2_RemoveFilter(iface, pfilter);
1170 IBaseFilter_Release(pfilter);
1174 out:
1175 if (penummt)
1176 IEnumMediaTypes_Release(penummt);
1177 if (mt)
1178 DeleteMediaType(mt);
1179 --This->recursioncount;
1180 LeaveCriticalSection(&This->cs);
1181 TRACE("--> %08x\n", hr);
1182 return SUCCEEDED(hr) ? S_OK : hr;
1185 static HRESULT FilterGraph2_RenderRecurse(IFilterGraphImpl *This, IPin *ppinOut)
1187 /* This pin has been connected now, try to call render on all pins that aren't connected */
1188 IPin *to = NULL;
1189 PIN_INFO info;
1190 IEnumPins *enumpins = NULL;
1191 BOOL renderany = FALSE;
1192 BOOL renderall = TRUE;
1194 IPin_QueryPinInfo(ppinOut, &info);
1196 IBaseFilter_EnumPins(info.pFilter, &enumpins);
1197 /* Don't need to hold a reference, IEnumPins does */
1198 IBaseFilter_Release(info.pFilter);
1200 IEnumPins_Reset(enumpins);
1201 while (IEnumPins_Next(enumpins, 1, &to, NULL) == S_OK)
1203 PIN_DIRECTION dir = PINDIR_INPUT;
1205 IPin_QueryDirection(to, &dir);
1207 if (dir == PINDIR_OUTPUT)
1209 IPin *out = NULL;
1211 IPin_ConnectedTo(to, &out);
1212 if (!out)
1214 HRESULT hr;
1215 hr = IFilterGraph2_Render(&This->IFilterGraph2_iface, to);
1216 if (SUCCEEDED(hr))
1217 renderany = TRUE;
1218 else
1219 renderall = FALSE;
1221 else
1222 IPin_Release(out);
1225 IPin_Release(to);
1228 IEnumPins_Release(enumpins);
1230 if (renderall)
1231 return S_OK;
1233 if (renderany)
1234 return VFW_S_PARTIAL_RENDER;
1236 return VFW_E_CANNOT_RENDER;
1239 /* Ogg hates me if I create a direct rendering method
1241 * It can only connect to a pin properly once, so use a recursive method that does
1243 * +----+ --- (PIN 1) (Render is called on this pin)
1244 * | |
1245 * +----+ --- (PIN 2)
1247 * Enumerate possible renderers that EXACTLY match the requested type
1249 * If none is available, try to add intermediate filters that can connect to the input pin
1250 * then call Render on that intermediate pin's output pins
1251 * if it succeeds: Render returns success, if it doesn't, the intermediate filter is removed,
1252 * and another filter that can connect to the input pin is tried
1253 * if we run out of filters that can, give up and return VFW_E_CANNOT_RENDER
1254 * It's recursive, but fun!
1257 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *ppinOut)
1259 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1260 IEnumMediaTypes* penummt;
1261 AM_MEDIA_TYPE* mt;
1262 ULONG nbmt;
1263 HRESULT hr;
1265 IEnumMoniker* pEnumMoniker;
1266 GUID tab[4];
1267 ULONG nb;
1268 IMoniker* pMoniker;
1269 INT x;
1271 TRACE("(%p/%p)->(%p)\n", This, iface, ppinOut);
1273 if (TRACE_ON(quartz))
1275 PIN_INFO PinInfo;
1277 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
1278 if (FAILED(hr))
1279 return hr;
1281 TRACE("Filter owning pin => %p\n", PinInfo.pFilter);
1282 IBaseFilter_Release(PinInfo.pFilter);
1285 /* Try to find out if there is a renderer for the specified subtype already, and use that
1287 EnterCriticalSection(&This->cs);
1288 for (x = 0; x < This->nFilters; ++x)
1290 IEnumPins *enumpins = NULL;
1291 IPin *pin = NULL;
1293 hr = IBaseFilter_EnumPins(This->ppFiltersInGraph[x], &enumpins);
1295 if (FAILED(hr) || !enumpins)
1296 continue;
1298 IEnumPins_Reset(enumpins);
1299 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
1301 IPin *to = NULL;
1302 PIN_DIRECTION dir = PINDIR_OUTPUT;
1304 IPin_QueryDirection(pin, &dir);
1305 if (dir != PINDIR_INPUT)
1307 IPin_Release(pin);
1308 continue;
1310 IPin_ConnectedTo(pin, &to);
1312 if (to == NULL)
1314 hr = FilterGraph2_ConnectDirect(iface, ppinOut, pin, NULL);
1315 if (SUCCEEDED(hr))
1317 TRACE("Connected successfully %p/%p, %08x look if we should render more!\n", ppinOut, pin, hr);
1318 IPin_Release(pin);
1320 hr = FilterGraph2_RenderRecurse(This, pin);
1321 if (FAILED(hr))
1323 IPin_Disconnect(ppinOut);
1324 IPin_Disconnect(pin);
1325 continue;
1327 IEnumPins_Release(enumpins);
1328 LeaveCriticalSection(&This->cs);
1329 return hr;
1331 WARN("Could not connect!\n");
1333 else
1334 IPin_Release(to);
1336 IPin_Release(pin);
1338 IEnumPins_Release(enumpins);
1341 LeaveCriticalSection(&This->cs);
1343 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
1344 if (FAILED(hr)) {
1345 WARN("EnumMediaTypes (%x)\n", hr);
1346 return hr;
1349 IEnumMediaTypes_Reset(penummt);
1351 /* Looks like no existing renderer of the kind exists
1352 * Try adding new ones
1354 tab[0] = tab[1] = GUID_NULL;
1355 while (SUCCEEDED(hr))
1357 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
1358 if (FAILED(hr)) {
1359 WARN("IEnumMediaTypes_Next (%x)\n", hr);
1360 break;
1362 if (!nbmt)
1364 hr = VFW_E_CANNOT_RENDER;
1365 break;
1367 else
1369 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1370 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1372 /* Only enumerate once, this doesn't account for all previous ones, but this should be enough nonetheless */
1373 if (IsEqualIID(&tab[0], &mt->majortype) && IsEqualIID(&tab[1], &mt->subtype))
1375 DeleteMediaType(mt);
1376 continue;
1379 /* Try to find a suitable renderer with the same media type */
1380 tab[0] = mt->majortype;
1381 tab[1] = mt->subtype;
1382 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1383 if (FAILED(hr))
1385 WARN("Unable to enum filters (%x)\n", hr);
1386 break;
1389 hr = E_FAIL;
1391 while (IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1393 VARIANT var;
1394 GUID clsid;
1395 IPin* ppinfilter;
1396 IBaseFilter* pfilter = NULL;
1397 IEnumPins* penumpins = NULL;
1398 ULONG pin;
1400 hr = GetFilterInfo(pMoniker, &clsid, &var);
1401 IMoniker_Release(pMoniker);
1402 if (FAILED(hr)) {
1403 WARN("Unable to retrieve filter info (%x)\n", hr);
1404 goto error;
1407 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
1408 if (FAILED(hr))
1410 WARN("Unable to create filter (%x), trying next one\n", hr);
1411 goto error;
1414 hr = IFilterGraph2_AddFilter(iface, pfilter, V_UNION(&var, bstrVal));
1415 if (FAILED(hr)) {
1416 WARN("Unable to add filter (%x)\n", hr);
1417 IBaseFilter_Release(pfilter);
1418 pfilter = NULL;
1419 goto error;
1422 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1423 if (FAILED(hr)) {
1424 WARN("Splitter Enumpins (%x)\n", hr);
1425 goto error;
1428 while ((hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin)) == S_OK)
1430 PIN_DIRECTION dir;
1432 if (pin == 0) {
1433 WARN("No Pin\n");
1434 hr = E_FAIL;
1435 goto error;
1438 hr = IPin_QueryDirection(ppinfilter, &dir);
1439 if (FAILED(hr)) {
1440 IPin_Release(ppinfilter);
1441 WARN("QueryDirection failed (%x)\n", hr);
1442 goto error;
1444 if (dir != PINDIR_INPUT) {
1445 IPin_Release(ppinfilter);
1446 continue; /* Wrong direction */
1449 /* Connect the pin to the "Renderer" */
1450 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1451 IPin_Release(ppinfilter);
1453 if (FAILED(hr)) {
1454 WARN("Unable to connect %s to renderer (%x)\n", debugstr_w(V_UNION(&var, bstrVal)), hr);
1455 goto error;
1457 TRACE("Connected, recursing %s\n", debugstr_w(V_UNION(&var, bstrVal)));
1459 VariantClear(&var);
1461 hr = FilterGraph2_RenderRecurse(This, ppinfilter);
1462 if (FAILED(hr)) {
1463 WARN("Unable to connect recursively (%x)\n", hr);
1464 goto error;
1466 IBaseFilter_Release(pfilter);
1467 break;
1469 if (SUCCEEDED(hr)) {
1470 IEnumPins_Release(penumpins);
1471 break; /* out of IEnumMoniker_Next loop */
1474 /* IEnumPins_Next failed, all other failure case caught by goto error */
1475 WARN("IEnumPins_Next (%x)\n", hr);
1476 /* goto error */
1478 error:
1479 VariantClear(&var);
1480 if (penumpins)
1481 IEnumPins_Release(penumpins);
1482 if (pfilter) {
1483 IFilterGraph2_RemoveFilter(iface, pfilter);
1484 IBaseFilter_Release(pfilter);
1486 if (SUCCEEDED(hr)) DebugBreak();
1489 IEnumMoniker_Release(pEnumMoniker);
1490 if (nbmt)
1491 DeleteMediaType(mt);
1492 if (SUCCEEDED(hr))
1493 break;
1494 hr = S_OK;
1497 IEnumMediaTypes_Release(penummt);
1498 return hr;
1501 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface, LPCWSTR lpcwstrFile,
1502 LPCWSTR lpcwstrPlayList)
1504 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1505 static const WCHAR string[] = {'R','e','a','d','e','r',0};
1506 IBaseFilter* preader = NULL;
1507 IPin* ppinreader = NULL;
1508 IEnumPins* penumpins = NULL;
1509 HRESULT hr;
1510 BOOL partial = FALSE;
1511 HRESULT any = FALSE;
1513 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1515 if (lpcwstrPlayList != NULL)
1516 return E_INVALIDARG;
1518 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, string, &preader);
1519 if (FAILED(hr))
1520 return hr;
1522 if (SUCCEEDED(hr))
1523 hr = IBaseFilter_EnumPins(preader, &penumpins);
1524 if (SUCCEEDED(hr))
1526 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1528 PIN_DIRECTION dir;
1530 IPin_QueryDirection(ppinreader, &dir);
1531 if (dir == PINDIR_OUTPUT)
1533 INT i;
1535 hr = IFilterGraph2_Render(iface, ppinreader);
1536 TRACE("Render %08x\n", hr);
1538 for (i = 0; i < This->nFilters; ++i)
1539 TRACE("Filters in chain: %s\n", debugstr_w(This->pFilterNames[i]));
1541 if (SUCCEEDED(hr))
1542 any = TRUE;
1543 if (hr != S_OK)
1544 partial = TRUE;
1546 IPin_Release(ppinreader);
1548 IEnumPins_Release(penumpins);
1550 if (!any)
1551 hr = VFW_E_CANNOT_RENDER;
1552 else if (partial)
1553 hr = VFW_S_PARTIAL_RENDER;
1554 else
1555 hr = S_OK;
1557 IBaseFilter_Release(preader);
1559 TRACE("--> %08x\n", hr);
1560 return hr;
1563 /* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
1564 static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
1566 static const WCHAR wszReg[] = {'M','e','d','i','a',' ','T','y','p','e','\\','E','x','t','e','n','s','i','o','n','s',0};
1567 HRESULT hr = S_OK;
1568 HKEY extkey;
1569 LONG lRet;
1571 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszReg, 0, KEY_READ, &extkey);
1572 hr = HRESULT_FROM_WIN32(lRet);
1574 if (SUCCEEDED(hr))
1576 static const WCHAR filtersource[] = {'S','o','u','r','c','e',' ','F','i','l','t','e','r',0};
1577 WCHAR *ext = PathFindExtensionW(pszFileName);
1578 WCHAR clsid_key[39];
1579 GUID clsid;
1580 DWORD size = sizeof(clsid_key);
1581 HKEY pathkey;
1583 if (!ext)
1585 CloseHandle(extkey);
1586 return E_FAIL;
1589 lRet = RegOpenKeyExW(extkey, ext, 0, KEY_READ, &pathkey);
1590 hr = HRESULT_FROM_WIN32(lRet);
1591 CloseHandle(extkey);
1592 if (FAILED(hr))
1593 return hr;
1595 lRet = RegQueryValueExW(pathkey, filtersource, NULL, NULL, (LPBYTE)clsid_key, &size);
1596 hr = HRESULT_FROM_WIN32(lRet);
1597 CloseHandle(pathkey);
1598 if (FAILED(hr))
1599 return hr;
1601 CLSIDFromString(clsid_key, &clsid);
1603 TRACE("CLSID: %s\n", debugstr_guid(&clsid));
1604 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1605 if (SUCCEEDED(hr))
1607 IFileSourceFilter *source = NULL;
1608 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID*)&source);
1609 if (SUCCEEDED(hr))
1610 IFileSourceFilter_Release(source);
1611 else
1612 IBaseFilter_Release(*filter);
1615 if (FAILED(hr))
1616 *filter = NULL;
1617 return hr;
1620 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface, LPCWSTR lpcwstrFileName,
1621 LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1623 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1624 HRESULT hr;
1625 IBaseFilter* preader;
1626 IFileSourceFilter* pfile = NULL;
1627 AM_MEDIA_TYPE mt;
1628 WCHAR* filename;
1630 TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1632 /* Try from file name first, then fall back to default asynchronous reader */
1633 hr = GetFileSourceFilter(lpcwstrFileName, &preader);
1635 if (FAILED(hr))
1636 hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&preader);
1637 if (FAILED(hr)) {
1638 WARN("Unable to create file source filter (%x)\n", hr);
1639 return hr;
1642 hr = IFilterGraph2_AddFilter(iface, preader, lpcwstrFilterName);
1643 if (FAILED(hr)) {
1644 WARN("Unable add filter (%x)\n", hr);
1645 IBaseFilter_Release(preader);
1646 return hr;
1649 hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1650 if (FAILED(hr)) {
1651 WARN("Unable to get IFileSourceInterface (%x)\n", hr);
1652 goto error;
1655 /* Load the file in the file source filter */
1656 hr = IFileSourceFilter_Load(pfile, lpcwstrFileName, NULL);
1657 if (FAILED(hr)) {
1658 WARN("Load (%x)\n", hr);
1659 goto error;
1662 IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1663 if (FAILED(hr)) {
1664 WARN("GetCurFile (%x)\n", hr);
1665 goto error;
1668 TRACE("File %s\n", debugstr_w(filename));
1669 TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
1670 TRACE("SubType %s\n", debugstr_guid(&mt.subtype));
1672 if (ppFilter)
1673 *ppFilter = preader;
1674 IFileSourceFilter_Release(pfile);
1676 return S_OK;
1678 error:
1679 if (pfile)
1680 IFileSourceFilter_Release(pfile);
1681 IFilterGraph2_RemoveFilter(iface, preader);
1682 IBaseFilter_Release(preader);
1684 return hr;
1687 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR hFile)
1689 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1691 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1693 return S_OK;
1696 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1698 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1700 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1702 return S_OK;
1705 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1707 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1709 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1711 return S_OK;
1714 /*** IFilterGraph2 methods ***/
1715 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1716 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1718 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1720 TRACE("(%p/%p)->(%p %p %s %p): stub !!!\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1722 return S_OK;
1725 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *ppin,
1726 const AM_MEDIA_TYPE *pmt)
1728 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1730 TRACE("(%p/%p)->(%p %p): stub !!!\n", This, iface, ppin, pmt);
1732 return S_OK;
1735 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *pPinOut, DWORD dwFlags,
1736 DWORD *pvContext)
1738 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1740 TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This, iface, pPinOut, dwFlags, pvContext);
1742 return S_OK;
1746 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1748 FilterGraph2_QueryInterface,
1749 FilterGraph2_AddRef,
1750 FilterGraph2_Release,
1751 FilterGraph2_AddFilter,
1752 FilterGraph2_RemoveFilter,
1753 FilterGraph2_EnumFilters,
1754 FilterGraph2_FindFilterByName,
1755 FilterGraph2_ConnectDirect,
1756 FilterGraph2_Reconnect,
1757 FilterGraph2_Disconnect,
1758 FilterGraph2_SetDefaultSyncSource,
1759 FilterGraph2_Connect,
1760 FilterGraph2_Render,
1761 FilterGraph2_RenderFile,
1762 FilterGraph2_AddSourceFilter,
1763 FilterGraph2_SetLogFile,
1764 FilterGraph2_Abort,
1765 FilterGraph2_ShouldOperationContinue,
1766 FilterGraph2_AddSourceFilterForMoniker,
1767 FilterGraph2_ReconnectEx,
1768 FilterGraph2_RenderEx
1771 static inline IFilterGraphImpl *impl_from_IMediaControl(IMediaControl *iface)
1773 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaControl_iface);
1776 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID riid, void **ppvObj)
1778 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1780 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1782 return Filtergraph_QueryInterface(This, riid, ppvObj);
1785 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1787 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1789 TRACE("(%p/%p)->()\n", This, iface);
1791 return Filtergraph_AddRef(This);
1794 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1796 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1798 TRACE("(%p/%p)->()\n", This, iface);
1800 return Filtergraph_Release(This);
1804 /*** IDispatch methods ***/
1805 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *pctinfo)
1807 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1809 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1811 return S_OK;
1814 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT iTInfo, LCID lcid,
1815 ITypeInfo **ppTInfo)
1817 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1819 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1821 return S_OK;
1824 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID riid,
1825 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1827 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1829 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1831 return S_OK;
1834 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID dispIdMember, REFIID riid,
1835 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
1836 UINT *puArgErr)
1838 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1840 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);
1842 return S_OK;
1845 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *, DWORD_PTR data);
1847 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter, DWORD_PTR data)
1849 HRESULT hr;
1850 IPin* pInputPin;
1851 IPin** ppPins;
1852 ULONG nb;
1853 ULONG i;
1854 PIN_INFO PinInfo;
1856 TRACE("%p %p\n", pGraph, pOutputPin);
1857 PinInfo.pFilter = NULL;
1859 hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1861 if (SUCCEEDED(hr))
1863 hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1864 if (SUCCEEDED(hr))
1865 hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1866 IPin_Release(pInputPin);
1869 if (SUCCEEDED(hr))
1871 if (nb == 0)
1873 TRACE("Reached a renderer\n");
1874 /* Count renderers for end of stream notification */
1875 pGraph->nRenderers++;
1877 else
1879 for(i = 0; i < nb; i++)
1881 /* Explore the graph downstream from this pin
1882 * FIXME: We should prevent exploring from a pin more than once. This can happens when
1883 * several input pins are connected to the same output (a MUX for instance). */
1884 ExploreGraph(pGraph, ppPins[i], FoundFilter, data);
1885 IPin_Release(ppPins[i]);
1888 CoTaskMemFree(ppPins);
1890 TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1892 FoundFilter(PinInfo.pFilter, data);
1895 if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1896 return hr;
1899 static HRESULT WINAPI SendRun(IBaseFilter *pFilter, DWORD_PTR data)
1901 REFERENCE_TIME time = *(REFERENCE_TIME*)data;
1902 return IBaseFilter_Run(pFilter, time);
1905 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1907 return IBaseFilter_Pause(pFilter);
1910 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1912 return IBaseFilter_Stop(pFilter);
1915 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1917 FILTER_STATE state;
1918 DWORD time_end = data;
1919 DWORD time_now = GetTickCount();
1920 LONG wait;
1922 if (time_end == INFINITE)
1924 wait = INFINITE;
1926 else if (time_end > time_now)
1928 wait = time_end - time_now;
1930 else
1931 wait = 0;
1933 return IBaseFilter_GetState(pFilter, wait, &state);
1937 static HRESULT SendFilterMessage(IFilterGraphImpl *This, fnFoundFilter FoundFilter, DWORD_PTR data)
1939 int i;
1940 IBaseFilter* pfilter;
1941 IEnumPins* pEnum;
1942 HRESULT hr;
1943 IPin* pPin;
1944 DWORD dummy;
1945 PIN_DIRECTION dir;
1947 TRACE("(%p)->()\n", This);
1949 /* Explorer the graph from source filters to renderers, determine renderers
1950 * number and run filters from renderers to source filters */
1951 This->nRenderers = 0;
1952 ResetEvent(This->hEventCompletion);
1954 for(i = 0; i < This->nFilters; i++)
1956 BOOL source = TRUE;
1957 pfilter = This->ppFiltersInGraph[i];
1958 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
1959 if (hr != S_OK)
1961 WARN("Enum pins failed %x\n", hr);
1962 continue;
1964 /* Check if it is a source filter */
1965 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1967 IPin_QueryDirection(pPin, &dir);
1968 IPin_Release(pPin);
1969 if (dir == PINDIR_INPUT)
1971 source = FALSE;
1972 break;
1975 if (source)
1977 TRACE("Found a source filter %p\n", pfilter);
1978 IEnumPins_Reset(pEnum);
1979 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1981 /* Explore the graph downstream from this pin */
1982 ExploreGraph(This, pPin, FoundFilter, data);
1983 IPin_Release(pPin);
1985 FoundFilter(pfilter, data);
1987 IEnumPins_Release(pEnum);
1990 return S_FALSE;
1993 /*** IMediaControl methods ***/
1994 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
1996 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1998 TRACE("(%p/%p)->()\n", This, iface);
2000 EnterCriticalSection(&This->cs);
2001 if (This->state == State_Running)
2002 goto out;
2003 This->EcCompleteCount = 0;
2005 if (This->defaultclock && !This->refClock)
2006 IFilterGraph2_SetDefaultSyncSource((IFilterGraph2*)This);
2008 if (This->refClock)
2010 REFERENCE_TIME now;
2011 IReferenceClock_GetTime(This->refClock, &now);
2012 if (This->state == State_Stopped)
2013 This->start_time = now + 500000;
2014 else if (This->pause_time >= 0)
2015 This->start_time += now - This->pause_time;
2016 else
2017 This->start_time = now;
2019 else This->start_time = 0;
2021 SendFilterMessage(This, SendRun, (DWORD_PTR)&This->start_time);
2022 This->state = State_Running;
2023 out:
2024 LeaveCriticalSection(&This->cs);
2025 return S_FALSE;
2028 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
2030 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2032 TRACE("(%p/%p)->()\n", This, iface);
2034 EnterCriticalSection(&This->cs);
2035 if (This->state == State_Paused)
2036 goto out;
2038 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2039 IReferenceClock_GetTime(This->refClock, &This->pause_time);
2040 else
2041 This->pause_time = -1;
2043 SendFilterMessage(This, SendPause, 0);
2044 This->state = State_Paused;
2045 out:
2046 LeaveCriticalSection(&This->cs);
2047 return S_FALSE;
2050 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
2052 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2054 TRACE("(%p/%p)->()\n", This, iface);
2056 if (This->state == State_Stopped) return S_OK;
2058 EnterCriticalSection(&This->cs);
2059 if (This->state == State_Running) SendFilterMessage(This, SendPause, 0);
2060 SendFilterMessage(This, SendStop, 0);
2061 This->state = State_Stopped;
2062 LeaveCriticalSection(&This->cs);
2063 return S_OK;
2066 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG msTimeout,
2067 OAFilterState *pfs)
2069 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2070 DWORD end;
2072 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
2074 if (!pfs)
2075 return E_POINTER;
2077 EnterCriticalSection(&This->cs);
2079 *pfs = This->state;
2080 if (msTimeout > 0)
2082 end = GetTickCount() + msTimeout;
2084 else if (msTimeout < 0)
2086 end = INFINITE;
2088 else
2090 end = 0;
2092 if (end)
2093 SendFilterMessage(This, SendGetState, end);
2095 LeaveCriticalSection(&This->cs);
2097 return S_OK;
2100 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
2102 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2104 FIXME("(%p/%p)->(%s (%p)): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename);
2106 return S_OK;
2109 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
2110 IDispatch **ppUnk)
2112 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2114 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2116 return S_OK;
2119 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2121 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2123 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2125 return S_OK;
2128 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2130 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2132 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2134 return S_OK;
2137 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
2139 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2141 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2143 return S_OK;
2147 static const IMediaControlVtbl IMediaControl_VTable =
2149 MediaControl_QueryInterface,
2150 MediaControl_AddRef,
2151 MediaControl_Release,
2152 MediaControl_GetTypeInfoCount,
2153 MediaControl_GetTypeInfo,
2154 MediaControl_GetIDsOfNames,
2155 MediaControl_Invoke,
2156 MediaControl_Run,
2157 MediaControl_Pause,
2158 MediaControl_Stop,
2159 MediaControl_GetState,
2160 MediaControl_RenderFile,
2161 MediaControl_AddSourceFilter,
2162 MediaControl_get_FilterCollection,
2163 MediaControl_get_RegFilterCollection,
2164 MediaControl_StopWhenReady
2167 static inline IFilterGraphImpl *impl_from_IMediaSeeking(IMediaSeeking *iface)
2169 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaSeeking_iface);
2172 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID riid, void **ppvObj)
2174 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2176 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2178 return Filtergraph_QueryInterface(This, riid, ppvObj);
2181 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2183 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2185 TRACE("(%p/%p)->()\n", This, iface);
2187 return Filtergraph_AddRef(This);
2190 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2192 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2194 TRACE("(%p/%p)->()\n", This, iface);
2196 return Filtergraph_Release(This);
2199 typedef HRESULT (WINAPI *fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
2201 static HRESULT all_renderers_seek(IFilterGraphImpl *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2202 BOOL allnotimpl = TRUE;
2203 int i;
2204 HRESULT hr, hr_return = S_OK;
2206 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2207 /* Send a message to all renderers, they are responsible for broadcasting it further */
2209 for(i = 0; i < This->nFilters; i++)
2211 IMediaSeeking *seek = NULL;
2212 IBaseFilter* pfilter = This->ppFiltersInGraph[i];
2213 IAMFilterMiscFlags *flags = NULL;
2214 ULONG filterflags;
2215 IUnknown_QueryInterface(pfilter, &IID_IAMFilterMiscFlags, (void**)&flags);
2216 if (!flags)
2217 continue;
2218 filterflags = IAMFilterMiscFlags_GetMiscFlags(flags);
2219 IUnknown_Release(flags);
2220 if (filterflags != AM_FILTER_MISC_FLAGS_IS_RENDERER)
2221 continue;
2223 IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2224 if (!seek)
2225 continue;
2226 hr = FoundSeek(This, seek, arg);
2227 IMediaSeeking_Release(seek);
2228 if (hr_return != E_NOTIMPL)
2229 allnotimpl = FALSE;
2230 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2231 hr_return = hr;
2234 if (allnotimpl)
2235 return E_NOTIMPL;
2236 return hr_return;
2239 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2241 HRESULT hr;
2242 DWORD caps = 0;
2244 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2245 if (FAILED(hr))
2246 return hr;
2248 /* Only add common capabilities everything supports */
2249 *(DWORD*)pcaps &= caps;
2251 return hr;
2254 /*** IMediaSeeking methods ***/
2255 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2257 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2258 HRESULT hr;
2260 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2262 if (!pCapabilities)
2263 return E_POINTER;
2265 EnterCriticalSection(&This->cs);
2266 *pCapabilities = 0xffffffff;
2268 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2269 LeaveCriticalSection(&This->cs);
2271 return hr;
2274 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2276 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2277 DWORD originalcaps;
2278 HRESULT hr;
2280 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2282 if (!pCapabilities)
2283 return E_POINTER;
2285 EnterCriticalSection(&This->cs);
2286 originalcaps = *pCapabilities;
2287 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2288 LeaveCriticalSection(&This->cs);
2290 if (FAILED(hr))
2291 return hr;
2293 if (!*pCapabilities)
2294 return E_FAIL;
2295 if (*pCapabilities != originalcaps)
2296 return S_FALSE;
2297 return S_OK;
2300 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2302 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2304 if (!pFormat)
2305 return E_POINTER;
2307 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2309 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2311 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2312 return S_FALSE;
2315 return S_OK;
2318 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2320 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2322 if (!pFormat)
2323 return E_POINTER;
2325 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2326 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2328 return S_OK;
2331 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2333 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2335 if (!pFormat)
2336 return E_POINTER;
2338 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2339 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2341 return S_OK;
2344 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2346 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2348 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2349 if (!pFormat)
2350 return E_POINTER;
2352 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2353 return S_FALSE;
2355 return S_OK;
2358 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2360 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2362 if (!pFormat)
2363 return E_POINTER;
2365 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2367 if (This->state != State_Stopped)
2368 return VFW_E_WRONG_STATE;
2370 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2372 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2373 return E_INVALIDARG;
2376 return S_OK;
2379 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2381 HRESULT hr;
2382 LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2384 hr = IMediaSeeking_GetDuration(seek, &duration);
2385 if (FAILED(hr))
2386 return hr;
2388 if (*pdur < duration)
2389 *pdur = duration;
2390 return hr;
2393 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *pDuration)
2395 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2396 HRESULT hr;
2398 TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2400 if (!pDuration)
2401 return E_POINTER;
2403 EnterCriticalSection(&This->cs);
2404 *pDuration = 0;
2405 hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2406 LeaveCriticalSection(&This->cs);
2408 TRACE("--->%08x\n", hr);
2409 return hr;
2412 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *pStop)
2414 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2415 HRESULT hr = S_OK;
2417 TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2419 if (!pStop)
2420 return E_POINTER;
2422 EnterCriticalSection(&This->cs);
2423 if (This->stop_position < 0)
2424 /* Stop position not set, use duration instead */
2425 hr = IMediaSeeking_GetDuration(iface, pStop);
2426 else
2427 *pStop = This->stop_position;
2428 LeaveCriticalSection(&This->cs);
2430 return hr;
2433 static HRESULT WINAPI FoundCurrentPosition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pposition)
2435 HRESULT hr;
2436 LONGLONG pos = 0, *ppos = (LONGLONG*)pposition;
2438 hr = IMediaSeeking_GetCurrentPosition(seek, &pos);
2439 if (FAILED(hr))
2440 return hr;
2442 if (*ppos < 0 || pos < *ppos)
2443 *ppos = pos;
2444 return hr;
2447 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *pCurrent)
2449 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2450 HRESULT hr;
2452 if (!pCurrent)
2453 return E_POINTER;
2455 EnterCriticalSection(&This->cs);
2456 *pCurrent = -1;
2457 hr = all_renderers_seek(This, FoundCurrentPosition, (DWORD_PTR)pCurrent);
2458 if (hr == E_NOTIMPL) {
2459 LONGLONG time = 0;
2460 if (This->refClock)
2462 IReferenceClock_GetTime(This->refClock, &time);
2463 if (time)
2464 time -= This->start_time;
2466 *pCurrent = time;
2467 hr = S_OK;
2469 LeaveCriticalSection(&This->cs);
2471 TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2473 return hr;
2476 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2477 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2479 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2481 FIXME("(%p/%p)->(%p, %p, 0x%s, %p): stub !!!\n", This, iface, pTarget,
2482 pTargetFormat, wine_dbgstr_longlong(Source), pSourceFormat);
2484 return S_OK;
2487 struct pos_args {
2488 LONGLONG* current, *stop;
2489 DWORD curflags, stopflags;
2492 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2494 struct pos_args *args = (void*)pargs;
2496 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
2499 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2500 DWORD dwCurrentFlags, LONGLONG *pStop, DWORD dwStopFlags)
2502 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2503 HRESULT hr = S_OK;
2504 FILTER_STATE state;
2505 struct pos_args args;
2507 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
2509 EnterCriticalSection(&This->cs);
2510 state = This->state;
2511 TRACE("State: %s\n", state == State_Running ? "Running" : (state == State_Paused ? "Paused" : (state == State_Stopped ? "Stopped" : "UNKNOWN")));
2513 if ((dwCurrentFlags & 0x7) != AM_SEEKING_AbsolutePositioning &&
2514 (dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2515 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
2517 if ((dwStopFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2518 This->stop_position = *pStop;
2519 else if ((dwStopFlags & 0x7) != AM_SEEKING_NoPositioning)
2520 FIXME("Stop position not handled yet!\n");
2522 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2523 IMediaControl_Pause(&This->IMediaControl_iface);
2524 args.current = pCurrent;
2525 args.stop = pStop;
2526 args.curflags = dwCurrentFlags;
2527 args.stopflags = dwStopFlags;
2528 hr = all_renderers_seek(This, found_setposition, (DWORD_PTR)&args);
2530 if ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2531 This->pause_time = This->start_time = -1;
2532 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2533 IMediaControl_Run(&This->IMediaControl_iface);
2534 LeaveCriticalSection(&This->cs);
2536 return hr;
2539 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2540 LONGLONG *pStop)
2542 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2543 HRESULT hr;
2545 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pCurrent, pStop);
2546 hr = IMediaSeeking_GetCurrentPosition(iface, pCurrent);
2547 if (SUCCEEDED(hr))
2548 hr = IMediaSeeking_GetStopPosition(iface, pStop);
2550 return hr;
2553 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2554 LONGLONG *pLatest)
2556 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2558 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2560 return S_OK;
2563 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2565 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2567 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2569 return S_OK;
2572 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2574 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2576 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2578 return S_OK;
2581 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2583 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2585 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2587 return S_OK;
2591 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2593 MediaSeeking_QueryInterface,
2594 MediaSeeking_AddRef,
2595 MediaSeeking_Release,
2596 MediaSeeking_GetCapabilities,
2597 MediaSeeking_CheckCapabilities,
2598 MediaSeeking_IsFormatSupported,
2599 MediaSeeking_QueryPreferredFormat,
2600 MediaSeeking_GetTimeFormat,
2601 MediaSeeking_IsUsingTimeFormat,
2602 MediaSeeking_SetTimeFormat,
2603 MediaSeeking_GetDuration,
2604 MediaSeeking_GetStopPosition,
2605 MediaSeeking_GetCurrentPosition,
2606 MediaSeeking_ConvertTimeFormat,
2607 MediaSeeking_SetPositions,
2608 MediaSeeking_GetPositions,
2609 MediaSeeking_GetAvailable,
2610 MediaSeeking_SetRate,
2611 MediaSeeking_GetRate,
2612 MediaSeeking_GetPreroll
2615 static inline IFilterGraphImpl *impl_from_IMediaPosition(IMediaPosition *iface)
2617 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaPosition_iface);
2620 /*** IUnknown methods ***/
2621 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj)
2623 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2625 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2626 return Filtergraph_QueryInterface(This, riid, ppvObj);
2629 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2631 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2633 TRACE("(%p/%p)->()\n", This, iface);
2634 return Filtergraph_AddRef(This);
2637 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2639 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2641 TRACE("(%p/%p)->()\n", This, iface);
2642 return Filtergraph_Release(This);
2645 /*** IDispatch methods ***/
2646 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo){
2647 FIXME("(%p) stub!\n", iface);
2648 return E_NOTIMPL;
2651 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo){
2652 FIXME("(%p) stub!\n", iface);
2653 return E_NOTIMPL;
2656 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId){
2657 FIXME("(%p) stub!\n", iface);
2658 return E_NOTIMPL;
2661 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr){
2662 FIXME("(%p) stub!\n", iface);
2663 return E_NOTIMPL;
2666 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2668 GUID time_format;
2669 HRESULT hr;
2671 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2672 if (FAILED(hr))
2673 return hr;
2674 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2676 FIXME("Unsupported time format.\n");
2677 return E_NOTIMPL;
2680 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2681 return S_OK;
2684 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2686 GUID time_format;
2687 HRESULT hr;
2689 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2690 if (FAILED(hr))
2691 return hr;
2692 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2694 FIXME("Unsupported time format.\n");
2695 return E_NOTIMPL;
2698 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2699 return S_OK;
2702 /*** IMediaPosition methods ***/
2703 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2705 LONGLONG duration;
2706 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2707 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2708 if (FAILED(hr))
2709 return hr;
2710 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2713 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2715 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2716 LONGLONG reftime;
2717 HRESULT hr;
2719 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2720 if (FAILED(hr))
2721 return hr;
2722 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2723 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2726 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2728 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2729 LONGLONG pos;
2730 HRESULT hr;
2732 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2733 if (FAILED(hr))
2734 return hr;
2735 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2738 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2740 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2741 LONGLONG pos;
2742 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2743 if (FAILED(hr))
2744 return hr;
2745 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2748 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2750 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2751 LONGLONG reftime;
2752 HRESULT hr;
2754 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2755 if (FAILED(hr))
2756 return hr;
2757 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2758 &reftime, AM_SEEKING_AbsolutePositioning);
2761 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime){
2762 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2763 return E_NOTIMPL;
2766 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime){
2767 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2768 return E_NOTIMPL;
2771 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2773 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2774 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2777 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2779 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2780 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2783 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward){
2784 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2785 return E_NOTIMPL;
2788 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward){
2789 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2790 return E_NOTIMPL;
2794 static const IMediaPositionVtbl IMediaPosition_VTable =
2796 MediaPosition_QueryInterface,
2797 MediaPosition_AddRef,
2798 MediaPosition_Release,
2799 MediaPosition_GetTypeInfoCount,
2800 MediaPosition_GetTypeInfo,
2801 MediaPosition_GetIDsOfNames,
2802 MediaPosition_Invoke,
2803 MediaPosition_get_Duration,
2804 MediaPosition_put_CurrentPosition,
2805 MediaPosition_get_CurrentPosition,
2806 MediaPosition_get_StopTime,
2807 MediaPosition_put_StopTime,
2808 MediaPosition_get_PrerollTime,
2809 MediaPosition_put_PrerollTime,
2810 MediaPosition_put_Rate,
2811 MediaPosition_get_Rate,
2812 MediaPosition_CanSeekForward,
2813 MediaPosition_CanSeekBackward
2816 static inline IFilterGraphImpl *impl_from_IObjectWithSite(IObjectWithSite *iface)
2818 return CONTAINING_RECORD(iface, IFilterGraphImpl, IObjectWithSite_iface);
2821 /*** IUnknown methods ***/
2822 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite* iface, REFIID riid, void** ppvObj)
2824 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2826 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2827 return Filtergraph_QueryInterface(This, riid, ppvObj);
2830 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
2832 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2834 TRACE("(%p/%p)->()\n", This, iface);
2835 return Filtergraph_AddRef(This);
2838 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
2840 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2842 TRACE("(%p/%p)->()\n", This, iface);
2843 return Filtergraph_Release(This);
2846 /*** IObjectWithSite methods ***/
2848 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
2850 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2852 TRACE("(%p/%p)->()\n", This, iface);
2853 if (This->pSite) IUnknown_Release(This->pSite);
2854 This->pSite = pUnkSite;
2855 IUnknown_AddRef(This->pSite);
2856 return S_OK;
2859 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, PVOID *ppvSite)
2861 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2863 TRACE("(%p/%p)->(%s)\n", This, iface,debugstr_guid(riid));
2865 *ppvSite = NULL;
2866 if (!This->pSite)
2867 return E_FAIL;
2868 else
2869 return IUnknown_QueryInterface(This->pSite, riid, ppvSite);
2872 static const IObjectWithSiteVtbl IObjectWithSite_VTable =
2874 ObjectWithSite_QueryInterface,
2875 ObjectWithSite_AddRef,
2876 ObjectWithSite_Release,
2877 ObjectWithSite_SetSite,
2878 ObjectWithSite_GetSite,
2881 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2883 HRESULT hr = E_NOINTERFACE;
2884 int i;
2885 int entry;
2887 /* Check if the interface type is already registered */
2888 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2889 if (riid == pGraph->ItfCacheEntries[entry].riid)
2891 if (pGraph->ItfCacheEntries[entry].iface)
2893 /* Return the interface if available */
2894 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2895 return S_OK;
2897 break;
2900 if (entry >= MAX_ITF_CACHE_ENTRIES)
2902 FIXME("Not enough space to store interface in the cache\n");
2903 return E_OUTOFMEMORY;
2906 /* Find a filter supporting the requested interface */
2907 for (i = 0; i < pGraph->nFilters; i++)
2909 hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2910 if (hr == S_OK)
2912 pGraph->ItfCacheEntries[entry].riid = riid;
2913 pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2914 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2915 if (entry >= pGraph->nItfCacheEntries)
2916 pGraph->nItfCacheEntries++;
2917 return S_OK;
2919 if (hr != E_NOINTERFACE)
2920 return hr;
2923 return hr;
2926 static inline IFilterGraphImpl *impl_from_IBasicAudio(IBasicAudio *iface)
2928 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicAudio_iface);
2931 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID riid, void **ppvObj)
2933 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2935 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2937 return Filtergraph_QueryInterface(This, riid, ppvObj);
2940 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
2942 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2944 TRACE("(%p/%p)->()\n", This, iface);
2946 return Filtergraph_AddRef(This);
2949 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
2951 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2953 TRACE("(%p/%p)->()\n", This, iface);
2955 return Filtergraph_Release(This);
2958 /*** IDispatch methods ***/
2959 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *pctinfo)
2961 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2962 IBasicAudio* pBasicAudio;
2963 HRESULT hr;
2965 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
2967 EnterCriticalSection(&This->cs);
2969 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2971 if (hr == S_OK)
2972 hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
2974 LeaveCriticalSection(&This->cs);
2976 return hr;
2979 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT iTInfo, LCID lcid,
2980 ITypeInfo **ppTInfo)
2982 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2983 IBasicAudio* pBasicAudio;
2984 HRESULT hr;
2986 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
2988 EnterCriticalSection(&This->cs);
2990 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2992 if (hr == S_OK)
2993 hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
2995 LeaveCriticalSection(&This->cs);
2997 return hr;
3000 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID riid, LPOLESTR *rgszNames,
3001 UINT cNames, LCID lcid, DISPID *rgDispId)
3003 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3004 IBasicAudio* pBasicAudio;
3005 HRESULT hr;
3007 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3009 EnterCriticalSection(&This->cs);
3011 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3013 if (hr == S_OK)
3014 hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
3016 LeaveCriticalSection(&This->cs);
3018 return hr;
3021 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID dispIdMember, REFIID riid,
3022 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3023 UINT *puArgErr)
3025 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3026 IBasicAudio* pBasicAudio;
3027 HRESULT hr;
3029 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);
3031 EnterCriticalSection(&This->cs);
3033 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3035 if (hr == S_OK)
3036 hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3038 LeaveCriticalSection(&This->cs);
3040 return hr;
3043 /*** IBasicAudio methods ***/
3044 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
3046 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3047 IBasicAudio* pBasicAudio;
3048 HRESULT hr;
3050 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
3052 EnterCriticalSection(&This->cs);
3054 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3056 if (hr == S_OK)
3057 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
3059 LeaveCriticalSection(&This->cs);
3061 return hr;
3064 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
3066 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3067 IBasicAudio* pBasicAudio;
3068 HRESULT hr;
3070 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
3072 EnterCriticalSection(&This->cs);
3074 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3076 if (hr == S_OK)
3077 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
3079 LeaveCriticalSection(&This->cs);
3081 return hr;
3084 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
3086 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3087 IBasicAudio* pBasicAudio;
3088 HRESULT hr;
3090 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
3092 EnterCriticalSection(&This->cs);
3094 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3096 if (hr == S_OK)
3097 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
3099 LeaveCriticalSection(&This->cs);
3101 return hr;
3104 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
3106 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3107 IBasicAudio* pBasicAudio;
3108 HRESULT hr;
3110 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
3112 EnterCriticalSection(&This->cs);
3114 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3116 if (hr == S_OK)
3117 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
3119 LeaveCriticalSection(&This->cs);
3121 return hr;
3124 static const IBasicAudioVtbl IBasicAudio_VTable =
3126 BasicAudio_QueryInterface,
3127 BasicAudio_AddRef,
3128 BasicAudio_Release,
3129 BasicAudio_GetTypeInfoCount,
3130 BasicAudio_GetTypeInfo,
3131 BasicAudio_GetIDsOfNames,
3132 BasicAudio_Invoke,
3133 BasicAudio_put_Volume,
3134 BasicAudio_get_Volume,
3135 BasicAudio_put_Balance,
3136 BasicAudio_get_Balance
3139 static inline IFilterGraphImpl *impl_from_IBasicVideo2(IBasicVideo2 *iface)
3141 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicVideo2_iface);
3144 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID riid, void **ppvObj)
3146 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3148 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3150 return Filtergraph_QueryInterface(This, riid, ppvObj);
3153 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
3155 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3157 TRACE("(%p/%p)->()\n", This, iface);
3159 return Filtergraph_AddRef(This);
3162 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
3164 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3166 TRACE("(%p/%p)->()\n", This, iface);
3168 return Filtergraph_Release(This);
3171 /*** IDispatch methods ***/
3172 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *pctinfo)
3174 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3175 IBasicVideo *pBasicVideo;
3176 HRESULT hr;
3178 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3180 EnterCriticalSection(&This->cs);
3182 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3184 if (hr == S_OK)
3185 hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
3187 LeaveCriticalSection(&This->cs);
3189 return hr;
3192 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT iTInfo, LCID lcid,
3193 ITypeInfo **ppTInfo)
3195 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3196 IBasicVideo *pBasicVideo;
3197 HRESULT hr;
3199 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3201 EnterCriticalSection(&This->cs);
3203 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3205 if (hr == S_OK)
3206 hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
3208 LeaveCriticalSection(&This->cs);
3210 return hr;
3213 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID riid,
3214 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
3216 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3217 IBasicVideo *pBasicVideo;
3218 HRESULT hr;
3220 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3222 EnterCriticalSection(&This->cs);
3224 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3226 if (hr == S_OK)
3227 hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
3229 LeaveCriticalSection(&This->cs);
3231 return hr;
3234 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID dispIdMember, REFIID riid,
3235 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3236 UINT *puArgErr)
3238 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3239 IBasicVideo *pBasicVideo;
3240 HRESULT hr;
3242 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);
3244 EnterCriticalSection(&This->cs);
3246 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3248 if (hr == S_OK)
3249 hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3251 LeaveCriticalSection(&This->cs);
3253 return hr;
3256 /*** IBasicVideo methods ***/
3257 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3259 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3260 IBasicVideo *pBasicVideo;
3261 HRESULT hr;
3263 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3265 EnterCriticalSection(&This->cs);
3267 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3269 if (hr == S_OK)
3270 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3272 LeaveCriticalSection(&This->cs);
3274 return hr;
3277 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3279 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3280 IBasicVideo *pBasicVideo;
3281 HRESULT hr;
3283 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3285 EnterCriticalSection(&This->cs);
3287 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3289 if (hr == S_OK)
3290 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3292 LeaveCriticalSection(&This->cs);
3294 return hr;
3297 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3299 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3300 IBasicVideo *pBasicVideo;
3301 HRESULT hr;
3303 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3305 EnterCriticalSection(&This->cs);
3307 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3309 if (hr == S_OK)
3310 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3312 LeaveCriticalSection(&This->cs);
3314 return hr;
3317 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3319 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3320 IBasicVideo *pBasicVideo;
3321 HRESULT hr;
3323 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3325 EnterCriticalSection(&This->cs);
3327 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3329 if (hr == S_OK)
3330 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3332 LeaveCriticalSection(&This->cs);
3334 return hr;
3337 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3339 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3340 IBasicVideo *pBasicVideo;
3341 HRESULT hr;
3343 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3345 EnterCriticalSection(&This->cs);
3347 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3349 if (hr == S_OK)
3350 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3352 LeaveCriticalSection(&This->cs);
3354 return hr;
3357 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3359 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3360 IBasicVideo *pBasicVideo;
3361 HRESULT hr;
3363 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3365 EnterCriticalSection(&This->cs);
3367 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3369 if (hr == S_OK)
3370 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3372 LeaveCriticalSection(&This->cs);
3374 return hr;
3377 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3379 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3380 IBasicVideo *pBasicVideo;
3381 HRESULT hr;
3383 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3385 EnterCriticalSection(&This->cs);
3387 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3389 if (hr == S_OK)
3390 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3392 LeaveCriticalSection(&This->cs);
3394 return hr;
3397 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3399 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3400 IBasicVideo *pBasicVideo;
3401 HRESULT hr;
3403 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3405 EnterCriticalSection(&This->cs);
3407 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3409 if (hr == S_OK)
3410 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3412 LeaveCriticalSection(&This->cs);
3414 return hr;
3417 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3419 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3420 IBasicVideo *pBasicVideo;
3421 HRESULT hr;
3423 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3425 EnterCriticalSection(&This->cs);
3427 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3429 if (hr == S_OK)
3430 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3432 LeaveCriticalSection(&This->cs);
3434 return hr;
3437 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3439 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3440 IBasicVideo *pBasicVideo;
3441 HRESULT hr;
3443 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3445 EnterCriticalSection(&This->cs);
3447 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3449 if (hr == S_OK)
3450 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3452 LeaveCriticalSection(&This->cs);
3454 return hr;
3457 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3459 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3460 IBasicVideo *pBasicVideo;
3461 HRESULT hr;
3463 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3465 EnterCriticalSection(&This->cs);
3467 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3469 if (hr == S_OK)
3470 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3472 LeaveCriticalSection(&This->cs);
3474 return hr;
3477 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3479 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3480 IBasicVideo *pBasicVideo;
3481 HRESULT hr;
3483 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3485 EnterCriticalSection(&This->cs);
3487 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3489 if (hr == S_OK)
3490 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3492 LeaveCriticalSection(&This->cs);
3494 return hr;
3497 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3499 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3500 IBasicVideo *pBasicVideo;
3501 HRESULT hr;
3503 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3505 EnterCriticalSection(&This->cs);
3507 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3509 if (hr == S_OK)
3510 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3512 LeaveCriticalSection(&This->cs);
3514 return hr;
3517 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3519 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3520 IBasicVideo *pBasicVideo;
3521 HRESULT hr;
3523 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3525 EnterCriticalSection(&This->cs);
3527 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3529 if (hr == S_OK)
3530 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3532 LeaveCriticalSection(&This->cs);
3534 return hr;
3537 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3539 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3540 IBasicVideo *pBasicVideo;
3541 HRESULT hr;
3543 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3545 EnterCriticalSection(&This->cs);
3547 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3549 if (hr == S_OK)
3550 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3552 LeaveCriticalSection(&This->cs);
3554 return hr;
3557 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3559 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3560 IBasicVideo *pBasicVideo;
3561 HRESULT hr;
3563 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3565 EnterCriticalSection(&This->cs);
3567 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3569 if (hr == S_OK)
3570 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3572 LeaveCriticalSection(&This->cs);
3574 return hr;
3577 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3579 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3580 IBasicVideo *pBasicVideo;
3581 HRESULT hr;
3583 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3585 EnterCriticalSection(&This->cs);
3587 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3589 if (hr == S_OK)
3590 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3592 LeaveCriticalSection(&This->cs);
3594 return hr;
3597 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3599 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3600 IBasicVideo *pBasicVideo;
3601 HRESULT hr;
3603 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3605 EnterCriticalSection(&This->cs);
3607 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3609 if (hr == S_OK)
3610 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3612 LeaveCriticalSection(&This->cs);
3614 return hr;
3617 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3619 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3620 IBasicVideo *pBasicVideo;
3621 HRESULT hr;
3623 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3625 EnterCriticalSection(&This->cs);
3627 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3629 if (hr == S_OK)
3630 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3632 LeaveCriticalSection(&This->cs);
3634 return hr;
3637 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3639 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3640 IBasicVideo *pBasicVideo;
3641 HRESULT hr;
3643 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3645 EnterCriticalSection(&This->cs);
3647 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3649 if (hr == S_OK)
3650 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3652 LeaveCriticalSection(&This->cs);
3654 return hr;
3657 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3658 LONG *pDestinationHeight)
3660 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3661 IBasicVideo *pBasicVideo;
3662 HRESULT hr;
3664 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3666 EnterCriticalSection(&This->cs);
3668 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3670 if (hr == S_OK)
3671 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3673 LeaveCriticalSection(&This->cs);
3675 return hr;
3678 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3679 LONG Width, LONG Height)
3681 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3682 IBasicVideo *pBasicVideo;
3683 HRESULT hr;
3685 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3687 EnterCriticalSection(&This->cs);
3689 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3691 if (hr == S_OK)
3692 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3694 LeaveCriticalSection(&This->cs);
3696 return hr;
3699 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3700 LONG *pWidth, LONG *pHeight)
3702 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3703 IBasicVideo *pBasicVideo;
3704 HRESULT hr;
3706 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3708 EnterCriticalSection(&This->cs);
3710 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3712 if (hr == S_OK)
3713 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3715 LeaveCriticalSection(&This->cs);
3717 return hr;
3720 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3722 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3723 IBasicVideo *pBasicVideo;
3724 HRESULT hr;
3726 TRACE("(%p/%p)->()\n", This, iface);
3728 EnterCriticalSection(&This->cs);
3730 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3732 if (hr == S_OK)
3733 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3735 LeaveCriticalSection(&This->cs);
3737 return hr;
3740 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3741 LONG Width, LONG Height)
3743 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3744 IBasicVideo *pBasicVideo;
3745 HRESULT hr;
3747 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3749 EnterCriticalSection(&This->cs);
3751 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3753 if (hr == S_OK)
3754 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3756 LeaveCriticalSection(&This->cs);
3758 return hr;
3761 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3762 LONG *pTop, LONG *pWidth, LONG *pHeight)
3764 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3765 IBasicVideo *pBasicVideo;
3766 HRESULT hr;
3768 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3770 EnterCriticalSection(&This->cs);
3772 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3774 if (hr == S_OK)
3775 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3777 LeaveCriticalSection(&This->cs);
3779 return hr;
3782 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3784 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3785 IBasicVideo *pBasicVideo;
3786 HRESULT hr;
3788 TRACE("(%p/%p)->()\n", This, iface);
3790 EnterCriticalSection(&This->cs);
3792 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3794 if (hr == S_OK)
3795 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3797 LeaveCriticalSection(&This->cs);
3799 return hr;
3802 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3804 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3805 IBasicVideo *pBasicVideo;
3806 HRESULT hr;
3808 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3810 EnterCriticalSection(&This->cs);
3812 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3814 if (hr == S_OK)
3815 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3817 LeaveCriticalSection(&This->cs);
3819 return hr;
3822 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3823 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3825 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3826 IBasicVideo *pBasicVideo;
3827 HRESULT hr;
3829 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3831 EnterCriticalSection(&This->cs);
3833 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3835 if (hr == S_OK)
3836 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3838 LeaveCriticalSection(&This->cs);
3840 return hr;
3843 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3844 LONG *pDIBImage)
3846 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3847 IBasicVideo *pBasicVideo;
3848 HRESULT hr;
3850 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3852 EnterCriticalSection(&This->cs);
3854 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3856 if (hr == S_OK)
3857 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3859 LeaveCriticalSection(&This->cs);
3861 return hr;
3864 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3866 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3867 IBasicVideo *pBasicVideo;
3868 HRESULT hr;
3870 TRACE("(%p/%p)->()\n", This, iface);
3872 EnterCriticalSection(&This->cs);
3874 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3876 if (hr == S_OK)
3877 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3879 LeaveCriticalSection(&This->cs);
3881 return hr;
3884 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3886 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3887 IBasicVideo *pBasicVideo;
3888 HRESULT hr;
3890 TRACE("(%p/%p)->()\n", This, iface);
3892 EnterCriticalSection(&This->cs);
3894 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3896 if (hr == S_OK)
3897 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3899 LeaveCriticalSection(&This->cs);
3901 return hr;
3904 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3905 LONG *plAspectY)
3907 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3908 IBasicVideo2 *pBasicVideo2;
3909 HRESULT hr;
3911 TRACE("(%p/%p)->()\n", This, iface);
3913 EnterCriticalSection(&This->cs);
3915 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3917 if (hr == S_OK)
3918 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3920 LeaveCriticalSection(&This->cs);
3922 return hr;
3925 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3927 BasicVideo_QueryInterface,
3928 BasicVideo_AddRef,
3929 BasicVideo_Release,
3930 BasicVideo_GetTypeInfoCount,
3931 BasicVideo_GetTypeInfo,
3932 BasicVideo_GetIDsOfNames,
3933 BasicVideo_Invoke,
3934 BasicVideo_get_AvgTimePerFrame,
3935 BasicVideo_get_BitRate,
3936 BasicVideo_get_BitErrorRate,
3937 BasicVideo_get_VideoWidth,
3938 BasicVideo_get_VideoHeight,
3939 BasicVideo_put_SourceLeft,
3940 BasicVideo_get_SourceLeft,
3941 BasicVideo_put_SourceWidth,
3942 BasicVideo_get_SourceWidth,
3943 BasicVideo_put_SourceTop,
3944 BasicVideo_get_SourceTop,
3945 BasicVideo_put_SourceHeight,
3946 BasicVideo_get_SourceHeight,
3947 BasicVideo_put_DestinationLeft,
3948 BasicVideo_get_DestinationLeft,
3949 BasicVideo_put_DestinationWidth,
3950 BasicVideo_get_DestinationWidth,
3951 BasicVideo_put_DestinationTop,
3952 BasicVideo_get_DestinationTop,
3953 BasicVideo_put_DestinationHeight,
3954 BasicVideo_get_DestinationHeight,
3955 BasicVideo_SetSourcePosition,
3956 BasicVideo_GetSourcePosition,
3957 BasicVideo_SetDefaultSourcePosition,
3958 BasicVideo_SetDestinationPosition,
3959 BasicVideo_GetDestinationPosition,
3960 BasicVideo_SetDefaultDestinationPosition,
3961 BasicVideo_GetVideoSize,
3962 BasicVideo_GetVideoPaletteEntries,
3963 BasicVideo_GetCurrentImage,
3964 BasicVideo_IsUsingDefaultSource,
3965 BasicVideo_IsUsingDefaultDestination,
3966 BasicVideo2_GetPreferredAspectRatio
3969 static inline IFilterGraphImpl *impl_from_IVideoWindow(IVideoWindow *iface)
3971 return CONTAINING_RECORD(iface, IFilterGraphImpl, IVideoWindow_iface);
3974 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID riid, void **ppvObj)
3976 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
3978 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3980 return Filtergraph_QueryInterface(This, riid, ppvObj);
3983 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
3985 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
3987 TRACE("(%p/%p)->()\n", This, iface);
3989 return Filtergraph_AddRef(This);
3992 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
3994 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
3996 TRACE("(%p/%p)->()\n", This, iface);
3998 return Filtergraph_Release(This);
4001 /*** IDispatch methods ***/
4002 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *pctinfo)
4004 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4005 IVideoWindow *pVideoWindow;
4006 HRESULT hr;
4008 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
4010 EnterCriticalSection(&This->cs);
4012 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4014 if (hr == S_OK)
4015 hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
4017 LeaveCriticalSection(&This->cs);
4019 return hr;
4022 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT iTInfo, LCID lcid,
4023 ITypeInfo **ppTInfo)
4025 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4026 IVideoWindow *pVideoWindow;
4027 HRESULT hr;
4029 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
4031 EnterCriticalSection(&This->cs);
4033 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4035 if (hr == S_OK)
4036 hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
4038 LeaveCriticalSection(&This->cs);
4040 return hr;
4043 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID riid,
4044 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4046 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4047 IVideoWindow *pVideoWindow;
4048 HRESULT hr;
4050 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
4052 EnterCriticalSection(&This->cs);
4054 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4056 if (hr == S_OK)
4057 hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
4059 LeaveCriticalSection(&This->cs);
4061 return hr;
4064 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID dispIdMember, REFIID riid,
4065 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4066 UINT*puArgErr)
4068 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4069 IVideoWindow *pVideoWindow;
4070 HRESULT hr;
4072 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);
4074 EnterCriticalSection(&This->cs);
4076 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4078 if (hr == S_OK)
4079 hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4081 LeaveCriticalSection(&This->cs);
4083 return hr;
4087 /*** IVideoWindow methods ***/
4088 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
4090 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4091 IVideoWindow *pVideoWindow;
4092 HRESULT hr;
4094 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
4096 EnterCriticalSection(&This->cs);
4098 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4100 if (hr == S_OK)
4101 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
4103 LeaveCriticalSection(&This->cs);
4105 return hr;
4108 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
4110 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4111 IVideoWindow *pVideoWindow;
4112 HRESULT hr;
4114 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
4116 EnterCriticalSection(&This->cs);
4118 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4120 if (hr == S_OK)
4121 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
4123 LeaveCriticalSection(&This->cs);
4125 return hr;
4128 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
4130 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4131 IVideoWindow *pVideoWindow;
4132 HRESULT hr;
4134 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
4136 EnterCriticalSection(&This->cs);
4138 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4140 if (hr == S_OK)
4141 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
4143 LeaveCriticalSection(&This->cs);
4145 return hr;
4148 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
4150 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4151 IVideoWindow *pVideoWindow;
4152 HRESULT hr;
4154 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
4156 EnterCriticalSection(&This->cs);
4158 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4160 if (hr == S_OK)
4161 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
4163 LeaveCriticalSection(&This->cs);
4165 return hr;
4168 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
4170 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4171 IVideoWindow *pVideoWindow;
4172 HRESULT hr;
4174 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
4176 EnterCriticalSection(&This->cs);
4178 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4180 if (hr == S_OK)
4181 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
4183 LeaveCriticalSection(&This->cs);
4185 return hr;
4188 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
4190 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4191 IVideoWindow *pVideoWindow;
4192 HRESULT hr;
4194 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
4196 EnterCriticalSection(&This->cs);
4198 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4200 if (hr == S_OK)
4201 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
4203 LeaveCriticalSection(&This->cs);
4205 return hr;
4208 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
4210 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4211 IVideoWindow *pVideoWindow;
4212 HRESULT hr;
4214 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
4216 EnterCriticalSection(&This->cs);
4218 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4220 if (hr == S_OK)
4221 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4223 LeaveCriticalSection(&This->cs);
4225 return hr;
4228 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
4230 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4231 IVideoWindow *pVideoWindow;
4232 HRESULT hr;
4234 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4236 EnterCriticalSection(&This->cs);
4238 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4240 if (hr == S_OK)
4241 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4243 LeaveCriticalSection(&This->cs);
4245 return hr;
4248 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
4250 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4251 IVideoWindow *pVideoWindow;
4252 HRESULT hr;
4254 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4256 EnterCriticalSection(&This->cs);
4258 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4260 if (hr == S_OK)
4261 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4263 LeaveCriticalSection(&This->cs);
4265 return hr;
4268 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4270 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4271 IVideoWindow *pVideoWindow;
4272 HRESULT hr;
4274 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4276 EnterCriticalSection(&This->cs);
4278 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4280 if (hr == S_OK)
4281 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4283 LeaveCriticalSection(&This->cs);
4285 return hr;
4288 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4290 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4291 IVideoWindow *pVideoWindow;
4292 HRESULT hr;
4294 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4296 EnterCriticalSection(&This->cs);
4298 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4300 if (hr == S_OK)
4301 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4303 LeaveCriticalSection(&This->cs);
4305 return hr;
4308 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4309 LONG *pBackgroundPalette)
4311 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4312 IVideoWindow *pVideoWindow;
4313 HRESULT hr;
4315 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4317 EnterCriticalSection(&This->cs);
4319 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4321 if (hr == S_OK)
4322 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4324 LeaveCriticalSection(&This->cs);
4326 return hr;
4329 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4331 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4332 IVideoWindow *pVideoWindow;
4333 HRESULT hr;
4335 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4337 EnterCriticalSection(&This->cs);
4339 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4341 if (hr == S_OK)
4342 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4344 LeaveCriticalSection(&This->cs);
4346 return hr;
4349 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4351 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4352 IVideoWindow *pVideoWindow;
4353 HRESULT hr;
4355 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4357 EnterCriticalSection(&This->cs);
4359 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4361 if (hr == S_OK)
4362 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4364 LeaveCriticalSection(&This->cs);
4366 return hr;
4369 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4371 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4372 IVideoWindow *pVideoWindow;
4373 HRESULT hr;
4375 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4377 EnterCriticalSection(&This->cs);
4379 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4381 if (hr == S_OK)
4382 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4384 LeaveCriticalSection(&This->cs);
4386 return hr;
4389 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4391 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4392 IVideoWindow *pVideoWindow;
4393 HRESULT hr;
4395 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4397 EnterCriticalSection(&This->cs);
4399 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4401 if (hr == S_OK)
4402 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4404 LeaveCriticalSection(&This->cs);
4406 return hr;
4409 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4411 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4412 IVideoWindow *pVideoWindow;
4413 HRESULT hr;
4415 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4417 EnterCriticalSection(&This->cs);
4419 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4421 if (hr == S_OK)
4422 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4424 LeaveCriticalSection(&This->cs);
4426 return hr;
4429 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4431 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4432 IVideoWindow *pVideoWindow;
4433 HRESULT hr;
4435 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4437 EnterCriticalSection(&This->cs);
4439 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4441 if (hr == S_OK)
4442 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4444 LeaveCriticalSection(&This->cs);
4446 return hr;
4449 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4451 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4452 IVideoWindow *pVideoWindow;
4453 HRESULT hr;
4455 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4457 EnterCriticalSection(&This->cs);
4459 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4461 if (hr == S_OK)
4462 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4464 LeaveCriticalSection(&This->cs);
4466 return hr;
4469 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4471 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4472 IVideoWindow *pVideoWindow;
4473 HRESULT hr;
4475 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4477 EnterCriticalSection(&This->cs);
4479 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4481 if (hr == S_OK)
4482 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4484 LeaveCriticalSection(&This->cs);
4486 return hr;
4489 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4491 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4492 IVideoWindow *pVideoWindow;
4493 HRESULT hr;
4495 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4497 EnterCriticalSection(&This->cs);
4499 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4501 if (hr == S_OK)
4502 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4504 LeaveCriticalSection(&This->cs);
4506 return hr;
4509 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4511 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4512 IVideoWindow *pVideoWindow;
4513 HRESULT hr;
4515 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4517 EnterCriticalSection(&This->cs);
4519 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4521 if (hr == S_OK)
4522 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4524 LeaveCriticalSection(&This->cs);
4526 return hr;
4529 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4531 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4532 IVideoWindow *pVideoWindow;
4533 HRESULT hr;
4535 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4537 EnterCriticalSection(&This->cs);
4539 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4541 if (hr == S_OK)
4542 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4544 LeaveCriticalSection(&This->cs);
4546 return hr;
4549 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4551 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4552 IVideoWindow *pVideoWindow;
4553 HRESULT hr;
4555 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4557 EnterCriticalSection(&This->cs);
4559 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4561 if (hr == S_OK)
4562 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4564 LeaveCriticalSection(&This->cs);
4566 return hr;
4569 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4571 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4572 IVideoWindow *pVideoWindow;
4573 HRESULT hr;
4575 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4577 EnterCriticalSection(&This->cs);
4579 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4581 if (hr == S_OK)
4582 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4584 LeaveCriticalSection(&This->cs);
4586 return hr;
4589 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4591 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4592 IVideoWindow *pVideoWindow;
4593 HRESULT hr;
4595 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4597 EnterCriticalSection(&This->cs);
4599 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4601 if (hr == S_OK)
4602 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4604 LeaveCriticalSection(&This->cs);
4606 return hr;
4609 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4611 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4612 IVideoWindow *pVideoWindow;
4613 HRESULT hr;
4615 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4617 EnterCriticalSection(&This->cs);
4619 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4621 if (hr == S_OK)
4622 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4624 LeaveCriticalSection(&This->cs);
4626 return hr;
4629 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4631 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4632 IVideoWindow *pVideoWindow;
4633 HRESULT hr;
4635 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4637 EnterCriticalSection(&This->cs);
4639 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4641 if (hr == S_OK)
4642 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4644 LeaveCriticalSection(&This->cs);
4646 return hr;
4649 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4651 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4652 IVideoWindow *pVideoWindow;
4653 HRESULT hr;
4655 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4657 EnterCriticalSection(&This->cs);
4659 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4661 if (hr == S_OK)
4662 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4664 LeaveCriticalSection(&This->cs);
4666 return hr;
4669 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4671 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4672 IVideoWindow *pVideoWindow;
4673 HRESULT hr;
4675 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4677 EnterCriticalSection(&This->cs);
4679 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4681 if (hr == S_OK)
4682 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4684 LeaveCriticalSection(&This->cs);
4686 return hr;
4689 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4691 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4692 IVideoWindow *pVideoWindow;
4693 HRESULT hr;
4695 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4697 EnterCriticalSection(&This->cs);
4699 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4701 if (hr == S_OK)
4702 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4704 LeaveCriticalSection(&This->cs);
4706 return hr;
4709 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4710 LONG_PTR wParam, LONG_PTR lParam)
4712 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4713 IVideoWindow *pVideoWindow;
4714 HRESULT hr;
4716 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4718 EnterCriticalSection(&This->cs);
4720 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4722 if (hr == S_OK)
4723 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4725 LeaveCriticalSection(&This->cs);
4727 return hr;
4730 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4731 LONG Width, LONG Height)
4733 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4734 IVideoWindow *pVideoWindow;
4735 HRESULT hr;
4737 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4739 EnterCriticalSection(&This->cs);
4741 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4743 if (hr == S_OK)
4744 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4746 LeaveCriticalSection(&This->cs);
4748 return hr;
4751 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4752 LONG *pWidth, LONG *pHeight)
4754 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4755 IVideoWindow *pVideoWindow;
4756 HRESULT hr;
4758 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4760 EnterCriticalSection(&This->cs);
4762 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4764 if (hr == S_OK)
4765 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4767 LeaveCriticalSection(&This->cs);
4769 return hr;
4772 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4773 LONG *pHeight)
4775 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4776 IVideoWindow *pVideoWindow;
4777 HRESULT hr;
4779 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4781 EnterCriticalSection(&This->cs);
4783 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4785 if (hr == S_OK)
4786 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4788 LeaveCriticalSection(&This->cs);
4790 return hr;
4793 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4794 LONG *pHeight)
4796 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4797 IVideoWindow *pVideoWindow;
4798 HRESULT hr;
4800 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4802 EnterCriticalSection(&This->cs);
4804 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4806 if (hr == S_OK)
4807 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4809 LeaveCriticalSection(&This->cs);
4811 return hr;
4814 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4815 LONG *pWidth, LONG *pHeight)
4817 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4818 IVideoWindow *pVideoWindow;
4819 HRESULT hr;
4821 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4823 EnterCriticalSection(&This->cs);
4825 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4827 if (hr == S_OK)
4828 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4830 LeaveCriticalSection(&This->cs);
4832 return hr;
4835 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4837 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4838 IVideoWindow *pVideoWindow;
4839 HRESULT hr;
4841 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4843 EnterCriticalSection(&This->cs);
4845 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4847 if (hr == S_OK)
4848 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4850 LeaveCriticalSection(&This->cs);
4852 return hr;
4855 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4857 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4858 IVideoWindow *pVideoWindow;
4859 HRESULT hr;
4861 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4863 EnterCriticalSection(&This->cs);
4865 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4867 if (hr == S_OK)
4868 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4870 LeaveCriticalSection(&This->cs);
4872 return hr;
4876 static const IVideoWindowVtbl IVideoWindow_VTable =
4878 VideoWindow_QueryInterface,
4879 VideoWindow_AddRef,
4880 VideoWindow_Release,
4881 VideoWindow_GetTypeInfoCount,
4882 VideoWindow_GetTypeInfo,
4883 VideoWindow_GetIDsOfNames,
4884 VideoWindow_Invoke,
4885 VideoWindow_put_Caption,
4886 VideoWindow_get_Caption,
4887 VideoWindow_put_WindowStyle,
4888 VideoWindow_get_WindowStyle,
4889 VideoWindow_put_WindowStyleEx,
4890 VideoWindow_get_WindowStyleEx,
4891 VideoWindow_put_AutoShow,
4892 VideoWindow_get_AutoShow,
4893 VideoWindow_put_WindowState,
4894 VideoWindow_get_WindowState,
4895 VideoWindow_put_BackgroundPalette,
4896 VideoWindow_get_BackgroundPalette,
4897 VideoWindow_put_Visible,
4898 VideoWindow_get_Visible,
4899 VideoWindow_put_Left,
4900 VideoWindow_get_Left,
4901 VideoWindow_put_Width,
4902 VideoWindow_get_Width,
4903 VideoWindow_put_Top,
4904 VideoWindow_get_Top,
4905 VideoWindow_put_Height,
4906 VideoWindow_get_Height,
4907 VideoWindow_put_Owner,
4908 VideoWindow_get_Owner,
4909 VideoWindow_put_MessageDrain,
4910 VideoWindow_get_MessageDrain,
4911 VideoWindow_get_BorderColor,
4912 VideoWindow_put_BorderColor,
4913 VideoWindow_get_FullScreenMode,
4914 VideoWindow_put_FullScreenMode,
4915 VideoWindow_SetWindowForeground,
4916 VideoWindow_NotifyOwnerMessage,
4917 VideoWindow_SetWindowPosition,
4918 VideoWindow_GetWindowPosition,
4919 VideoWindow_GetMinIdealImageSize,
4920 VideoWindow_GetMaxIdealImageSize,
4921 VideoWindow_GetRestorePosition,
4922 VideoWindow_HideCursor,
4923 VideoWindow_IsCursorHidden
4926 static inline IFilterGraphImpl *impl_from_IMediaEventEx(IMediaEventEx *iface)
4928 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventEx_iface);
4931 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID riid, void **ppvObj)
4933 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4935 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
4937 return Filtergraph_QueryInterface(This, riid, ppvObj);
4940 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
4942 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4944 TRACE("(%p/%p)->()\n", This, iface);
4946 return Filtergraph_AddRef(This);
4949 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
4951 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4953 TRACE("(%p/%p)->()\n", This, iface);
4955 return Filtergraph_Release(This);
4958 /*** IDispatch methods ***/
4959 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *pctinfo)
4961 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4963 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
4965 return S_OK;
4968 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT iTInfo, LCID lcid,
4969 ITypeInfo **ppTInfo)
4971 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4973 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
4975 return S_OK;
4978 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID riid,
4979 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4981 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4983 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
4985 return S_OK;
4988 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID dispIdMember, REFIID riid,
4989 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4990 UINT *puArgErr)
4992 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4994 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);
4996 return S_OK;
4999 /*** IMediaEvent methods ***/
5000 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *hEvent)
5002 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5004 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
5006 *hEvent = (OAEVENT)This->evqueue.msg_event;
5008 return S_OK;
5011 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *lEventCode, LONG_PTR *lParam1,
5012 LONG_PTR *lParam2, LONG msTimeout)
5014 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5015 Event evt;
5017 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
5019 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
5021 *lEventCode = evt.lEventCode;
5022 *lParam1 = evt.lParam1;
5023 *lParam2 = evt.lParam2;
5024 return S_OK;
5027 *lEventCode = 0;
5028 return E_ABORT;
5031 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
5032 LONG *pEvCode)
5034 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5036 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
5038 if (This->state != State_Running)
5039 return VFW_E_WRONG_STATE;
5041 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
5043 *pEvCode = This->CompletionStatus;
5044 return S_OK;
5047 *pEvCode = 0;
5048 return E_ABORT;
5051 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5053 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5055 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5057 if (lEvCode == EC_COMPLETE)
5058 This->HandleEcComplete = FALSE;
5059 else if (lEvCode == EC_REPAINT)
5060 This->HandleEcRepaint = FALSE;
5061 else if (lEvCode == EC_CLOCK_CHANGED)
5062 This->HandleEcClockChanged = FALSE;
5063 else
5064 return S_FALSE;
5066 return S_OK;
5069 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5071 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5073 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5075 if (lEvCode == EC_COMPLETE)
5076 This->HandleEcComplete = TRUE;
5077 else if (lEvCode == EC_REPAINT)
5078 This->HandleEcRepaint = TRUE;
5079 else if (lEvCode == EC_CLOCK_CHANGED)
5080 This->HandleEcClockChanged = TRUE;
5081 else
5082 return S_FALSE;
5084 return S_OK;
5087 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG lEvCode,
5088 LONG_PTR lParam1, LONG_PTR lParam2)
5090 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5092 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
5094 return S_OK;
5097 /*** IMediaEventEx methods ***/
5098 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface, OAHWND hwnd, LONG lMsg,
5099 LONG_PTR lInstanceData)
5101 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5103 TRACE("(%p/%p)->(%08lx, %d, %08lx)\n", This, iface, hwnd, lMsg, lInstanceData);
5105 This->notif.hWnd = (HWND)hwnd;
5106 This->notif.msg = lMsg;
5107 This->notif.instance = lInstanceData;
5109 return S_OK;
5112 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG lNoNotifyFlags)
5114 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5116 TRACE("(%p/%p)->(%d)\n", This, iface, lNoNotifyFlags);
5118 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
5119 return E_INVALIDARG;
5121 This->notif.disabled = lNoNotifyFlags;
5123 return S_OK;
5126 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *lplNoNotifyFlags)
5128 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5130 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
5132 if (!lplNoNotifyFlags)
5133 return E_POINTER;
5135 *lplNoNotifyFlags = This->notif.disabled;
5137 return S_OK;
5141 static const IMediaEventExVtbl IMediaEventEx_VTable =
5143 MediaEvent_QueryInterface,
5144 MediaEvent_AddRef,
5145 MediaEvent_Release,
5146 MediaEvent_GetTypeInfoCount,
5147 MediaEvent_GetTypeInfo,
5148 MediaEvent_GetIDsOfNames,
5149 MediaEvent_Invoke,
5150 MediaEvent_GetEventHandle,
5151 MediaEvent_GetEvent,
5152 MediaEvent_WaitForCompletion,
5153 MediaEvent_CancelDefaultHandling,
5154 MediaEvent_RestoreDefaultHandling,
5155 MediaEvent_FreeEventParams,
5156 MediaEvent_SetNotifyWindow,
5157 MediaEvent_SetNotifyFlags,
5158 MediaEvent_GetNotifyFlags
5162 static inline IFilterGraphImpl *impl_from_IMediaFilter(IMediaFilter *iface)
5164 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaFilter_iface);
5167 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, void **ppv)
5169 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5171 return Filtergraph_QueryInterface(This, riid, ppv);
5174 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
5176 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5178 return Filtergraph_AddRef(This);
5181 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
5183 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5185 return Filtergraph_Release(This);
5188 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
5190 FIXME("(%p): stub\n", pClassID);
5192 return E_NOTIMPL;
5195 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
5197 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5199 return MediaControl_Stop(&This->IMediaControl_iface);
5202 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5204 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5206 return MediaControl_Pause(&This->IMediaControl_iface);
5209 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
5211 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5213 if (tStart)
5214 FIXME("Run called with non-null tStart: %x%08x\n",
5215 (int)(tStart>>32), (int)tStart);
5217 return MediaControl_Run(&This->IMediaControl_iface);
5220 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout,
5221 FILTER_STATE *pState)
5223 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5225 return MediaControl_GetState(&This->IMediaControl_iface, dwMsTimeout, (OAFilterState*)pState);
5228 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5230 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5231 HRESULT hr = S_OK;
5232 int i;
5234 TRACE("(%p/%p)->(%p)\n", iface, This, pClock);
5236 EnterCriticalSection(&This->cs);
5238 for (i = 0;i < This->nFilters;i++)
5240 hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5241 if (FAILED(hr))
5242 break;
5245 if (FAILED(hr))
5247 for(;i >= 0;i--)
5248 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5250 else
5252 if (This->refClock)
5253 IReferenceClock_Release(This->refClock);
5254 This->refClock = pClock;
5255 if (This->refClock)
5256 IReferenceClock_AddRef(This->refClock);
5257 This->defaultclock = FALSE;
5259 if (This->HandleEcClockChanged)
5261 IMediaEventSink *pEventSink;
5262 HRESULT eshr;
5264 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (LPVOID)&pEventSink);
5265 if (SUCCEEDED(eshr))
5267 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5268 IMediaEventSink_Release(pEventSink);
5273 LeaveCriticalSection(&This->cs);
5275 return hr;
5278 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5280 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5282 TRACE("(%p/%p)->(%p)\n", iface, This, ppClock);
5284 if (!ppClock)
5285 return E_POINTER;
5287 EnterCriticalSection(&This->cs);
5289 *ppClock = This->refClock;
5290 if (*ppClock)
5291 IReferenceClock_AddRef(*ppClock);
5293 LeaveCriticalSection(&This->cs);
5295 return S_OK;
5298 static const IMediaFilterVtbl IMediaFilter_VTable =
5300 MediaFilter_QueryInterface,
5301 MediaFilter_AddRef,
5302 MediaFilter_Release,
5303 MediaFilter_GetClassID,
5304 MediaFilter_Stop,
5305 MediaFilter_Pause,
5306 MediaFilter_Run,
5307 MediaFilter_GetState,
5308 MediaFilter_SetSyncSource,
5309 MediaFilter_GetSyncSource
5312 static inline IFilterGraphImpl *impl_from_IMediaEventSink(IMediaEventSink *iface)
5314 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventSink_iface);
5317 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, void **ppv)
5319 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5321 return Filtergraph_QueryInterface(This, riid, ppv);
5324 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5326 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5328 return Filtergraph_AddRef(This);
5331 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5333 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5335 return Filtergraph_Release(This);
5338 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG EventCode,
5339 LONG_PTR EventParam1, LONG_PTR EventParam2)
5341 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5342 Event evt;
5344 TRACE("(%p/%p)->(%d, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5346 /* We need thread safety here, let's use the events queue's one */
5347 EnterCriticalSection(&This->evqueue.msg_crst);
5349 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5351 TRACE("Process EC_COMPLETE notification\n");
5352 if (++This->EcCompleteCount == This->nRenderers)
5354 evt.lEventCode = EC_COMPLETE;
5355 evt.lParam1 = S_OK;
5356 evt.lParam2 = 0;
5357 TRACE("Send EC_COMPLETE to app\n");
5358 EventsQueue_PutEvent(&This->evqueue, &evt);
5359 if (!This->notif.disabled && This->notif.hWnd)
5361 TRACE("Send Window message\n");
5362 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5364 This->CompletionStatus = EC_COMPLETE;
5365 SetEvent(This->hEventCompletion);
5368 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5370 /* FIXME: Not handled yet */
5372 else
5374 evt.lEventCode = EventCode;
5375 evt.lParam1 = EventParam1;
5376 evt.lParam2 = EventParam2;
5377 EventsQueue_PutEvent(&This->evqueue, &evt);
5378 if (!This->notif.disabled && This->notif.hWnd)
5379 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5382 LeaveCriticalSection(&This->evqueue.msg_crst);
5383 return S_OK;
5386 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5388 MediaEventSink_QueryInterface,
5389 MediaEventSink_AddRef,
5390 MediaEventSink_Release,
5391 MediaEventSink_Notify
5394 static inline IFilterGraphImpl *impl_from_IGraphConfig(IGraphConfig *iface)
5396 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphConfig_iface);
5399 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, void **ppv)
5401 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5403 return Filtergraph_QueryInterface(This, riid, ppv);
5406 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5408 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5410 return Filtergraph_AddRef(This);
5413 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5415 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5417 return Filtergraph_Release(This);
5420 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *pOutputPin, IPin *pInputPin,
5421 const AM_MEDIA_TYPE *pmtFirstConnection, IBaseFilter *pUsingFilter, HANDLE hAbortEvent,
5422 DWORD dwFlags)
5424 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5426 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5428 return E_NOTIMPL;
5431 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface, IGraphConfigCallback *pCallback,
5432 void *pvContext, DWORD dwFlags, HANDLE hAbortEvent)
5434 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5435 HRESULT hr;
5437 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5439 if (hAbortEvent)
5440 FIXME("The parameter hAbortEvent is not handled!\n");
5442 EnterCriticalSection(&This->cs);
5444 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5446 LeaveCriticalSection(&This->cs);
5448 return hr;
5451 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5453 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5455 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5457 return E_NOTIMPL;
5460 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5462 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5464 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5466 return E_NOTIMPL;
5469 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5471 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5473 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5475 return E_NOTIMPL;
5478 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5480 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5482 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5484 return E_NOTIMPL;
5487 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5488 IPinConnection *pConnection, HANDLE hEventAbort)
5490 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5492 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5494 return E_NOTIMPL;
5497 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5498 DWORD dwFlags)
5500 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5502 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5504 return E_NOTIMPL;
5507 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5508 DWORD *dwFlags)
5510 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5512 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5514 return E_NOTIMPL;
5517 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *pFilter,
5518 DWORD dwFlags)
5520 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5522 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5524 return E_NOTIMPL;
5527 static const IGraphConfigVtbl IGraphConfig_VTable =
5529 GraphConfig_QueryInterface,
5530 GraphConfig_AddRef,
5531 GraphConfig_Release,
5532 GraphConfig_Reconnect,
5533 GraphConfig_Reconfigure,
5534 GraphConfig_AddFilterToCache,
5535 GraphConfig_EnumCacheFilter,
5536 GraphConfig_RemoveFilterFromCache,
5537 GraphConfig_GetStartTime,
5538 GraphConfig_PushThroughData,
5539 GraphConfig_SetFilterFlags,
5540 GraphConfig_GetFilterFlags,
5541 GraphConfig_RemoveFilterEx
5544 static const IUnknownVtbl IInner_VTable =
5546 FilterGraphInner_QueryInterface,
5547 FilterGraphInner_AddRef,
5548 FilterGraphInner_Release
5551 static HRESULT Filtergraph_QueryInterface(IFilterGraphImpl *This,
5552 REFIID riid,
5553 LPVOID * ppv) {
5554 if (This->bAggregatable)
5555 This->bUnkOuterValid = TRUE;
5557 if (This->pUnkOuter)
5559 if (This->bAggregatable)
5560 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
5562 if (IsEqualIID(riid, &IID_IUnknown))
5564 HRESULT hr;
5566 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5567 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5568 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5569 This->bAggregatable = TRUE;
5570 return hr;
5573 *ppv = NULL;
5574 return E_NOINTERFACE;
5577 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5580 static ULONG Filtergraph_AddRef(IFilterGraphImpl *This) {
5581 if (This->pUnkOuter && This->bUnkOuterValid)
5582 return IUnknown_AddRef(This->pUnkOuter);
5583 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5586 static ULONG Filtergraph_Release(IFilterGraphImpl *This) {
5587 if (This->pUnkOuter && This->bUnkOuterValid)
5588 return IUnknown_Release(This->pUnkOuter);
5589 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5592 /* This is the only function that actually creates a FilterGraph class... */
5593 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5595 IFilterGraphImpl *fimpl;
5596 HRESULT hr;
5598 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5600 *ppObj = NULL;
5602 fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5603 fimpl->pUnkOuter = pUnkOuter;
5604 fimpl->bUnkOuterValid = FALSE;
5605 fimpl->bAggregatable = FALSE;
5606 fimpl->defaultclock = TRUE;
5607 fimpl->IInner_vtbl = &IInner_VTable;
5608 fimpl->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5609 fimpl->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5610 fimpl->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5611 fimpl->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5612 fimpl->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5613 fimpl->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5614 fimpl->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5615 fimpl->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5616 fimpl->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5617 fimpl->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5618 fimpl->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5619 fimpl->IObjectWithSite_iface.lpVtbl = &IObjectWithSite_VTable;
5620 fimpl->ref = 1;
5621 fimpl->ppFiltersInGraph = NULL;
5622 fimpl->pFilterNames = NULL;
5623 fimpl->nFilters = 0;
5624 fimpl->filterCapacity = 0;
5625 fimpl->nameIndex = 1;
5626 fimpl->refClock = NULL;
5627 fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5628 fimpl->HandleEcComplete = TRUE;
5629 fimpl->HandleEcRepaint = TRUE;
5630 fimpl->HandleEcClockChanged = TRUE;
5631 fimpl->notif.hWnd = 0;
5632 fimpl->notif.disabled = FALSE;
5633 fimpl->nRenderers = 0;
5634 fimpl->EcCompleteCount = 0;
5635 fimpl->refClockProvider = NULL;
5636 fimpl->state = State_Stopped;
5637 fimpl->pSite = NULL;
5638 EventsQueue_Init(&fimpl->evqueue);
5639 InitializeCriticalSection(&fimpl->cs);
5640 fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5641 fimpl->nItfCacheEntries = 0;
5642 memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5643 fimpl->start_time = fimpl->pause_time = 0;
5644 fimpl->stop_position = -1;
5645 fimpl->punkFilterMapper2 = NULL;
5646 fimpl->recursioncount = 0;
5648 /* create Filtermapper aggregated. */
5649 hr = CoCreateInstance(&CLSID_FilterMapper2, pUnkOuter ? pUnkOuter : (IUnknown*)&fimpl->IInner_vtbl, CLSCTX_INPROC_SERVER,
5650 &IID_IUnknown, (LPVOID*)&fimpl->punkFilterMapper2);
5652 if (SUCCEEDED(hr)) {
5653 hr = IUnknown_QueryInterface(fimpl->punkFilterMapper2, &IID_IFilterMapper2, (LPVOID*)&fimpl->pFilterMapper2);
5656 if (SUCCEEDED(hr)) {
5657 /* Release controlling IUnknown - compensate refcount increase from caching IFilterMapper2 interface. */
5658 if (pUnkOuter) IUnknown_Release(pUnkOuter);
5659 else IUnknown_Release((IUnknown*)&fimpl->IInner_vtbl);
5662 if (FAILED(hr)) {
5663 ERR("Unable to create filter mapper (%x)\n", hr);
5664 if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5665 CloseHandle(fimpl->hEventCompletion);
5666 EventsQueue_Destroy(&fimpl->evqueue);
5667 fimpl->cs.DebugInfo->Spare[0] = 0;
5668 DeleteCriticalSection(&fimpl->cs);
5669 CoTaskMemFree(fimpl);
5670 return hr;
5673 *ppObj = fimpl;
5674 return S_OK;
5677 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5679 FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5680 return FilterGraph_create(pUnkOuter, ppObj);