d3dcompiler: Don't allow semantics on void functions.
[wine/multimedia.git] / dlls / quartz / filtergraph.c
blob6b0085d4a7d53e7283e83a9671146fe4882f0532
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 IUnknown IUnknown_inner;
153 IFilterGraph2 IFilterGraph2_iface;
154 IMediaControl IMediaControl_iface;
155 IMediaSeeking IMediaSeeking_iface;
156 IBasicAudio IBasicAudio_iface;
157 IBasicVideo2 IBasicVideo2_iface;
158 IVideoWindow IVideoWindow_iface;
159 IMediaEventEx IMediaEventEx_iface;
160 IMediaFilter IMediaFilter_iface;
161 IMediaEventSink IMediaEventSink_iface;
162 IGraphConfig IGraphConfig_iface;
163 IMediaPosition IMediaPosition_iface;
164 IObjectWithSite IObjectWithSite_iface;
165 /* IAMGraphStreams */
166 /* IAMStats */
167 /* IFilterChain */
168 /* IFilterMapper2 */
169 /* IGraphVersion */
170 /* IQueueCommand */
171 /* IRegisterServiceProvider */
172 /* IResourceMananger */
173 /* IServiceProvider */
174 /* IVideoFrameStep */
176 IUnknown *outer_unk;
177 LONG ref;
178 IUnknown *punkFilterMapper2;
179 IFilterMapper2 * pFilterMapper2;
180 IBaseFilter ** ppFiltersInGraph;
181 LPWSTR * pFilterNames;
182 int nFilters;
183 int filterCapacity;
184 LONG nameIndex;
185 IReferenceClock *refClock;
186 IBaseFilter *refClockProvider;
187 EventsQueue evqueue;
188 HANDLE hEventCompletion;
189 int CompletionStatus;
190 WndNotify notif;
191 int nRenderers;
192 int EcCompleteCount;
193 int HandleEcComplete;
194 int HandleEcRepaint;
195 int HandleEcClockChanged;
196 OAFilterState state;
197 CRITICAL_SECTION cs;
198 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
199 int nItfCacheEntries;
200 BOOL defaultclock;
201 GUID timeformatseek;
202 REFERENCE_TIME start_time;
203 REFERENCE_TIME pause_time;
204 LONGLONG stop_position;
205 LONG recursioncount;
206 IUnknown *pSite;
207 } IFilterGraphImpl;
209 static inline IFilterGraphImpl *impl_from_IUnknown(IUnknown *iface)
211 return CONTAINING_RECORD(iface, IFilterGraphImpl, IUnknown_inner);
214 static HRESULT WINAPI FilterGraphInner_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObj)
216 IFilterGraphImpl *This = impl_from_IUnknown(iface);
217 TRACE("(%p)->(%s (%p), %p)\n", This, debugstr_guid(riid), riid, ppvObj);
219 if (IsEqualGUID(&IID_IUnknown, riid)) {
220 *ppvObj = &This->IUnknown_inner;
221 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
222 } else if (IsEqualGUID(&IID_IFilterGraph, riid) ||
223 IsEqualGUID(&IID_IFilterGraph2, riid) ||
224 IsEqualGUID(&IID_IGraphBuilder, riid)) {
225 *ppvObj = &This->IFilterGraph2_iface;
226 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj);
227 } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
228 *ppvObj = &This->IMediaControl_iface;
229 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj);
230 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
231 *ppvObj = &This->IMediaSeeking_iface;
232 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
233 } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
234 *ppvObj = &This->IBasicAudio_iface;
235 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj);
236 } else if (IsEqualGUID(&IID_IBasicVideo, riid) ||
237 IsEqualGUID(&IID_IBasicVideo2, riid)) {
238 *ppvObj = &This->IBasicVideo2_iface;
239 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj);
240 } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
241 *ppvObj = &This->IVideoWindow_iface;
242 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj);
243 } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
244 IsEqualGUID(&IID_IMediaEventEx, riid)) {
245 *ppvObj = &This->IMediaEventEx_iface;
246 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
247 } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
248 IsEqualGUID(&IID_IPersist, riid)) {
249 *ppvObj = &This->IMediaFilter_iface;
250 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj);
251 } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
252 *ppvObj = &This->IMediaEventSink_iface;
253 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj);
254 } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
255 *ppvObj = &This->IGraphConfig_iface;
256 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
257 } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
258 *ppvObj = &This->IMediaPosition_iface;
259 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj);
260 } else if (IsEqualGUID(&IID_IObjectWithSite, riid)) {
261 *ppvObj = &This->IObjectWithSite_iface;
262 TRACE(" returning IObjectWithSite interface (%p)\n", *ppvObj);
263 } else if (IsEqualGUID(&IID_IFilterMapper, riid)) {
264 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj);
265 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
266 } else if (IsEqualGUID(&IID_IFilterMapper2, riid)) {
267 *ppvObj = This->pFilterMapper2;
268 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
269 } else if (IsEqualGUID(&IID_IFilterMapper3, riid)) {
270 *ppvObj = This->pFilterMapper2;
271 TRACE(" returning IFilterMapper3 interface from aggregated filtermapper (%p)\n", *ppvObj);
272 } else {
273 *ppvObj = NULL;
274 FIXME("unknown interface %s\n", debugstr_guid(riid));
275 return E_NOINTERFACE;
278 IUnknown_AddRef((IUnknown *)*ppvObj);
279 return S_OK;
282 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown *iface)
284 IFilterGraphImpl *This = impl_from_IUnknown(iface);
285 ULONG ref = InterlockedIncrement(&This->ref);
287 TRACE("(%p)->(): new ref = %d\n", This, ref);
289 return ref;
292 static ULONG WINAPI FilterGraphInner_Release(IUnknown *iface)
294 IFilterGraphImpl *This = impl_from_IUnknown(iface);
295 ULONG ref = InterlockedDecrement(&This->ref);
297 TRACE("(%p)->(): new ref = %d\n", This, ref);
299 if (ref == 0) {
300 int i;
302 This->ref = 1; /* guard against reentrancy (aggregation). */
304 IMediaControl_Stop(&This->IMediaControl_iface);
306 while (This->nFilters)
307 IFilterGraph2_RemoveFilter(&This->IFilterGraph2_iface, This->ppFiltersInGraph[0]);
309 if (This->refClock)
310 IReferenceClock_Release(This->refClock);
312 for (i = 0; i < This->nItfCacheEntries; i++)
314 if (This->ItfCacheEntries[i].iface)
315 IUnknown_Release(This->ItfCacheEntries[i].iface);
318 /* AddRef on controlling IUnknown, to compensate for Release of cached IFilterMapper2 */
319 IUnknown_AddRef(This->outer_unk);
320 IFilterMapper2_Release(This->pFilterMapper2);
321 IUnknown_Release(This->punkFilterMapper2);
323 if (This->pSite) IUnknown_Release(This->pSite);
325 CloseHandle(This->hEventCompletion);
326 EventsQueue_Destroy(&This->evqueue);
327 This->cs.DebugInfo->Spare[0] = 0;
328 DeleteCriticalSection(&This->cs);
329 CoTaskMemFree(This->ppFiltersInGraph);
330 CoTaskMemFree(This->pFilterNames);
331 CoTaskMemFree(This);
333 return ref;
336 static inline IFilterGraphImpl *impl_from_IFilterGraph2(IFilterGraph2 *iface)
338 return CONTAINING_RECORD(iface, IFilterGraphImpl, IFilterGraph2_iface);
341 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface, REFIID riid, void **ppvObj)
343 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
345 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
347 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
350 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface)
352 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
354 TRACE("(%p/%p)->() calling FilterGraph AddRef\n", This, iface);
356 return IUnknown_AddRef(This->outer_unk);
359 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface)
361 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
363 TRACE("(%p/%p)->() calling FilterGraph Release\n", This, iface);
365 return IUnknown_Release(This->outer_unk);
368 /*** IFilterGraph methods ***/
369 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface, IBaseFilter *pFilter,
370 LPCWSTR pName)
372 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
373 HRESULT hr;
374 int i,j;
375 WCHAR* wszFilterName = NULL;
376 int duplicate_name = FALSE;
378 TRACE("(%p/%p)->(%p, %s (%p))\n", This, iface, pFilter, debugstr_w(pName), pName);
380 if (!pFilter)
381 return E_POINTER;
383 wszFilterName = CoTaskMemAlloc( (pName ? strlenW(pName) + 6 : 5) * sizeof(WCHAR) );
385 if (pName)
387 /* Check if name already exists */
388 for(i = 0; i < This->nFilters; i++)
389 if (!strcmpW(This->pFilterNames[i], pName))
391 duplicate_name = TRUE;
392 break;
396 /* If no name given or name already existing, generate one */
397 if (!pName || duplicate_name)
399 static const WCHAR wszFmt1[] = {'%','s',' ','%','0','4','d',0};
400 static const WCHAR wszFmt2[] = {'%','0','4','d',0};
402 for (j = 0; j < 10000 ; j++)
404 /* Create name */
405 if (pName)
406 sprintfW(wszFilterName, wszFmt1, pName, This->nameIndex);
407 else
408 sprintfW(wszFilterName, wszFmt2, This->nameIndex);
409 TRACE("Generated name %s\n", debugstr_w(wszFilterName));
411 /* Check if the generated name already exists */
412 for(i = 0; i < This->nFilters; i++)
413 if (!strcmpW(This->pFilterNames[i], wszFilterName))
414 break;
416 /* Compute next index and exit if generated name is suitable */
417 if (This->nameIndex++ == 10000)
418 This->nameIndex = 1;
419 if (i == This->nFilters)
420 break;
422 /* Unable to find a suitable name */
423 if (j == 10000)
425 CoTaskMemFree(wszFilterName);
426 return VFW_E_DUPLICATE_NAME;
429 else
430 memcpy(wszFilterName, pName, (strlenW(pName) + 1) * sizeof(WCHAR));
432 if (This->nFilters + 1 > This->filterCapacity)
434 int newCapacity = This->filterCapacity ? 2 * This->filterCapacity : 1;
435 IBaseFilter ** ppNewFilters = CoTaskMemAlloc(newCapacity * sizeof(IBaseFilter*));
436 LPWSTR * pNewNames = CoTaskMemAlloc(newCapacity * sizeof(LPWSTR));
437 memcpy(ppNewFilters, This->ppFiltersInGraph, This->nFilters * sizeof(IBaseFilter*));
438 memcpy(pNewNames, This->pFilterNames, This->nFilters * sizeof(LPWSTR));
439 if (This->filterCapacity)
441 CoTaskMemFree(This->ppFiltersInGraph);
442 CoTaskMemFree(This->pFilterNames);
444 This->ppFiltersInGraph = ppNewFilters;
445 This->pFilterNames = pNewNames;
446 This->filterCapacity = newCapacity;
449 hr = IBaseFilter_JoinFilterGraph(pFilter, (IFilterGraph *)This, wszFilterName);
451 if (SUCCEEDED(hr))
453 IBaseFilter_AddRef(pFilter);
454 This->ppFiltersInGraph[This->nFilters] = pFilter;
455 This->pFilterNames[This->nFilters] = wszFilterName;
456 This->nFilters++;
457 IBaseFilter_SetSyncSource(pFilter, This->refClock);
459 else
460 CoTaskMemFree(wszFilterName);
462 if (SUCCEEDED(hr) && duplicate_name)
463 return VFW_S_DUPLICATE_NAME;
465 return hr;
468 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
470 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
471 int i;
472 HRESULT hr = E_FAIL;
474 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
476 /* FIXME: check graph is stopped */
478 for (i = 0; i < This->nFilters; i++)
480 if (This->ppFiltersInGraph[i] == pFilter)
482 IEnumPins *penumpins = NULL;
483 FILTER_STATE state;
485 if (This->defaultclock && This->refClockProvider == pFilter)
487 IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, NULL);
488 This->defaultclock = 1;
491 TRACE("Removing filter %s\n", debugstr_w(This->pFilterNames[i]));
492 IBaseFilter_GetState(pFilter, 0, &state);
493 if (state == State_Running)
494 IBaseFilter_Pause(pFilter);
495 if (state != State_Stopped)
496 IBaseFilter_Stop(pFilter);
498 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
499 if (SUCCEEDED(hr)) {
500 IPin *ppin;
501 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
503 IPin *victim = NULL;
504 HRESULT h;
505 IPin_ConnectedTo(ppin, &victim);
506 if (victim)
508 h = IPin_Disconnect(victim);
509 TRACE("Disconnect other side: %08x\n", h);
510 if (h == VFW_E_NOT_STOPPED)
512 PIN_INFO pinfo;
513 IPin_QueryPinInfo(victim, &pinfo);
515 IBaseFilter_GetState(pinfo.pFilter, 0, &state);
516 if (state == State_Running)
517 IBaseFilter_Pause(pinfo.pFilter);
518 IBaseFilter_Stop(pinfo.pFilter);
519 IBaseFilter_Release(pinfo.pFilter);
520 h = IPin_Disconnect(victim);
521 TRACE("Disconnect retry: %08x\n", h);
523 IPin_Release(victim);
525 h = IPin_Disconnect(ppin);
526 TRACE("Disconnect 2: %08x\n", h);
528 IPin_Release(ppin);
530 IEnumPins_Release(penumpins);
533 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, This->pFilterNames[i]);
534 if (SUCCEEDED(hr))
536 IBaseFilter_SetSyncSource(pFilter, NULL);
537 IBaseFilter_Release(pFilter);
538 CoTaskMemFree(This->pFilterNames[i]);
539 memmove(This->ppFiltersInGraph+i, This->ppFiltersInGraph+i+1, sizeof(IBaseFilter*)*(This->nFilters - 1 - i));
540 memmove(This->pFilterNames+i, This->pFilterNames+i+1, sizeof(LPWSTR)*(This->nFilters - 1 - i));
541 This->nFilters--;
542 /* Invalidate interfaces in the cache */
543 for (i = 0; i < This->nItfCacheEntries; i++)
544 if (pFilter == This->ItfCacheEntries[i].filter)
546 IUnknown_Release(This->ItfCacheEntries[i].iface);
547 This->ItfCacheEntries[i].iface = NULL;
548 This->ItfCacheEntries[i].filter = NULL;
550 return S_OK;
552 break;
556 return hr; /* FIXME: check this error code */
559 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface, IEnumFilters **ppEnum)
561 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
563 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
565 return IEnumFiltersImpl_Construct(This->ppFiltersInGraph, This->nFilters, ppEnum);
568 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface, LPCWSTR pName,
569 IBaseFilter **ppFilter)
571 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
572 int i;
574 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_w(pName), pName, ppFilter);
576 if (!ppFilter)
577 return E_POINTER;
579 for (i = 0; i < This->nFilters; i++)
581 if (!strcmpW(pName, This->pFilterNames[i]))
583 *ppFilter = This->ppFiltersInGraph[i];
584 IBaseFilter_AddRef(*ppFilter);
585 return S_OK;
589 *ppFilter = NULL;
590 return VFW_E_NOT_FOUND;
593 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
594 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
596 static HRESULT CheckCircularConnection(IFilterGraphImpl *This, IPin *out, IPin *in)
598 #if 1
599 HRESULT hr;
600 PIN_INFO info_out, info_in;
602 hr = IPin_QueryPinInfo(out, &info_out);
603 if (FAILED(hr))
604 return hr;
605 if (info_out.dir != PINDIR_OUTPUT)
607 IBaseFilter_Release(info_out.pFilter);
608 return E_UNEXPECTED;
611 hr = IPin_QueryPinInfo(in, &info_in);
612 if (SUCCEEDED(hr))
613 IBaseFilter_Release(info_in.pFilter);
614 if (FAILED(hr))
615 goto out;
616 if (info_in.dir != PINDIR_INPUT)
618 hr = E_UNEXPECTED;
619 goto out;
622 if (info_out.pFilter == info_in.pFilter)
623 hr = VFW_E_CIRCULAR_GRAPH;
624 else
626 IEnumPins *enumpins;
627 IPin *test;
629 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
630 if (FAILED(hr))
631 goto out;
633 IEnumPins_Reset(enumpins);
634 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
636 PIN_DIRECTION dir = PINDIR_OUTPUT;
637 IPin_QueryDirection(test, &dir);
638 if (dir == PINDIR_INPUT)
640 IPin *victim = NULL;
641 IPin_ConnectedTo(test, &victim);
642 if (victim)
644 hr = CheckCircularConnection(This, victim, in);
645 IPin_Release(victim);
646 if (FAILED(hr))
648 IPin_Release(test);
649 break;
653 IPin_Release(test);
655 IEnumPins_Release(enumpins);
658 out:
659 IBaseFilter_Release(info_out.pFilter);
660 if (FAILED(hr))
661 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
662 return hr;
663 #else
664 /* Debugging filtergraphs not enabled */
665 return S_OK;
666 #endif
670 /* NOTE: despite the implication, it doesn't matter which
671 * way round you put in the input and output pins */
672 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppinIn, IPin *ppinOut,
673 const AM_MEDIA_TYPE *pmt)
675 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
676 PIN_DIRECTION dir;
677 HRESULT hr;
679 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
681 /* FIXME: check pins are in graph */
683 if (TRACE_ON(quartz))
685 PIN_INFO PinInfo;
687 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
688 if (FAILED(hr))
689 return hr;
691 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
692 IBaseFilter_Release(PinInfo.pFilter);
694 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
695 if (FAILED(hr))
696 return hr;
698 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
699 IBaseFilter_Release(PinInfo.pFilter);
702 hr = IPin_QueryDirection(ppinIn, &dir);
703 if (SUCCEEDED(hr))
705 if (dir == PINDIR_INPUT)
707 hr = CheckCircularConnection(This, ppinOut, ppinIn);
708 if (SUCCEEDED(hr))
709 hr = IPin_Connect(ppinOut, ppinIn, pmt);
711 else
713 hr = CheckCircularConnection(This, ppinIn, ppinOut);
714 if (SUCCEEDED(hr))
715 hr = IPin_Connect(ppinIn, ppinOut, pmt);
719 return hr;
722 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface, IPin *ppin)
724 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
725 IPin *pConnectedTo = NULL;
726 HRESULT hr;
727 PIN_DIRECTION pindir;
729 IPin_QueryDirection(ppin, &pindir);
730 hr = IPin_ConnectedTo(ppin, &pConnectedTo);
731 if (FAILED(hr)) {
732 TRACE("Querying connected to failed: %x\n", hr);
733 return hr;
735 IPin_Disconnect(ppin);
736 IPin_Disconnect(pConnectedTo);
737 if (pindir == PINDIR_INPUT)
738 hr = IPin_Connect(pConnectedTo, ppin, NULL);
739 else
740 hr = IPin_Connect(ppin, pConnectedTo, NULL);
741 IPin_Release(pConnectedTo);
742 if (FAILED(hr))
743 WARN("Reconnecting pins failed, pins are not connected now..\n");
744 TRACE("(%p->%p) -- %p %p -> %x\n", iface, This, ppin, pConnectedTo, hr);
745 return hr;
748 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
750 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
752 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
754 if (!ppin)
755 return E_POINTER;
757 return IPin_Disconnect(ppin);
760 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
762 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
763 IReferenceClock *pClock = NULL;
764 HRESULT hr = S_OK;
765 int i;
767 TRACE("(%p/%p)->() live sources not handled properly!\n", iface, This);
769 EnterCriticalSection(&This->cs);
771 for (i = 0; i < This->nFilters; ++i)
773 DWORD miscflags;
774 IAMFilterMiscFlags *flags = NULL;
775 IUnknown_QueryInterface(This->ppFiltersInGraph[i], &IID_IAMFilterMiscFlags, (void**)&flags);
776 if (!flags)
777 continue;
778 miscflags = IAMFilterMiscFlags_GetMiscFlags(flags);
779 IUnknown_Release(flags);
780 if (miscflags == AM_FILTER_MISC_FLAGS_IS_RENDERER)
781 IUnknown_QueryInterface(This->ppFiltersInGraph[i], &IID_IReferenceClock, (void**)&pClock);
782 if (pClock)
783 break;
786 if (!pClock)
788 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
789 This->refClockProvider = NULL;
791 else
792 This->refClockProvider = This->ppFiltersInGraph[i];
794 if (SUCCEEDED(hr))
796 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
797 This->defaultclock = TRUE;
798 IReferenceClock_Release(pClock);
800 LeaveCriticalSection(&This->cs);
802 return hr;
805 static HRESULT GetFilterInfo(IMoniker* pMoniker, GUID* pclsid, VARIANT* pvar)
807 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
808 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
809 IPropertyBag * pPropBagCat = NULL;
810 HRESULT hr;
812 VariantInit(pvar);
814 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
816 if (SUCCEEDED(hr))
817 hr = IPropertyBag_Read(pPropBagCat, wszClsidName, pvar, NULL);
819 if (SUCCEEDED(hr))
820 hr = CLSIDFromString(V_UNION(pvar, bstrVal), pclsid);
822 VariantClear(pvar);
824 if (SUCCEEDED(hr))
825 hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL);
827 if (SUCCEEDED(hr))
828 TRACE("Moniker = %s - %s\n", debugstr_guid(pclsid), debugstr_w(V_UNION(pvar, bstrVal)));
830 if (pPropBagCat)
831 IPropertyBag_Release(pPropBagCat);
833 return hr;
836 static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPin*** pppins, ULONG* pnb)
838 HRESULT hr;
839 ULONG nb = 0;
841 TRACE("(%p, %p, %p, %p)\n", pfilter, pinputpin, pppins, pnb);
842 hr = IPin_QueryInternalConnections(pinputpin, NULL, &nb);
843 if (hr == S_OK) {
844 /* Rendered input */
845 } else if (hr == S_FALSE) {
846 *pppins = CoTaskMemAlloc(sizeof(IPin*)*nb);
847 hr = IPin_QueryInternalConnections(pinputpin, *pppins, &nb);
848 if (hr != S_OK) {
849 WARN("Error (%x)\n", hr);
851 } else if (hr == E_NOTIMPL) {
852 /* Input connected to all outputs */
853 IEnumPins* penumpins;
854 IPin* ppin;
855 int i = 0;
856 TRACE("E_NOTIMPL\n");
857 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
858 if (FAILED(hr)) {
859 WARN("filter Enumpins failed (%x)\n", hr);
860 return hr;
862 i = 0;
863 /* Count output pins */
864 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
865 PIN_DIRECTION pindir;
866 IPin_QueryDirection(ppin, &pindir);
867 if (pindir == PINDIR_OUTPUT)
868 i++;
869 IPin_Release(ppin);
871 *pppins = CoTaskMemAlloc(sizeof(IPin*)*i);
872 /* Retrieve output pins */
873 IEnumPins_Reset(penumpins);
874 i = 0;
875 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
876 PIN_DIRECTION pindir;
877 IPin_QueryDirection(ppin, &pindir);
878 if (pindir == PINDIR_OUTPUT)
879 (*pppins)[i++] = ppin;
880 else
881 IPin_Release(ppin);
883 IEnumPins_Release(penumpins);
884 nb = i;
885 if (FAILED(hr)) {
886 WARN("Next failed (%x)\n", hr);
887 return hr;
889 } else if (FAILED(hr)) {
890 WARN("Cannot get internal connection (%x)\n", hr);
891 return hr;
894 *pnb = nb;
895 return S_OK;
898 /*** IGraphBuilder methods ***/
899 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IPin *ppinIn)
901 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
902 HRESULT hr;
903 AM_MEDIA_TYPE* mt = NULL;
904 IEnumMediaTypes* penummt = NULL;
905 ULONG nbmt;
906 IEnumPins* penumpins;
907 IEnumMoniker* pEnumMoniker;
908 GUID tab[2];
909 ULONG nb;
910 IMoniker* pMoniker;
911 ULONG pin;
912 PIN_INFO PinInfo;
913 CLSID FilterCLSID;
914 PIN_DIRECTION dir;
916 TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
918 if (TRACE_ON(quartz))
920 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
921 if (FAILED(hr))
922 return hr;
924 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
925 IBaseFilter_Release(PinInfo.pFilter);
927 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
928 if (FAILED(hr))
929 return hr;
931 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
932 IBaseFilter_Release(PinInfo.pFilter);
935 EnterCriticalSection(&This->cs);
936 ++This->recursioncount;
937 if (This->recursioncount >= 5)
939 WARN("Recursion count has reached %d\n", This->recursioncount);
940 hr = VFW_E_CANNOT_CONNECT;
941 goto out;
944 hr = IPin_QueryDirection(ppinOut, &dir);
945 if (FAILED(hr))
946 goto out;
948 if (dir == PINDIR_INPUT)
950 IPin *temp;
952 temp = ppinIn;
953 ppinIn = ppinOut;
954 ppinOut = temp;
957 hr = CheckCircularConnection(This, ppinOut, ppinIn);
958 if (FAILED(hr))
959 goto out;
961 /* Try direct connection first */
962 hr = IPin_Connect(ppinOut, ppinIn, NULL);
963 if (SUCCEEDED(hr))
964 goto out;
966 TRACE("Direct connection failed, trying to render using extra filters\n");
968 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
969 if (FAILED(hr))
970 goto out;
972 hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
973 IBaseFilter_Release(PinInfo.pFilter);
974 if (FAILED(hr))
975 goto out;
977 /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream
978 * filter to the minor mediatype of input pin of the renderer */
979 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
980 if (FAILED(hr))
982 WARN("EnumMediaTypes (%x)\n", hr);
983 goto out;
986 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
987 if (FAILED(hr)) {
988 WARN("IEnumMediaTypes_Next (%x)\n", hr);
989 goto out;
992 if (!nbmt)
994 WARN("No media type found!\n");
995 hr = VFW_E_INVALIDMEDIATYPE;
996 goto out;
998 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
999 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1001 /* Try to find a suitable filter that can connect to the pin to render */
1002 tab[0] = mt->majortype;
1003 tab[1] = mt->subtype;
1004 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1005 if (FAILED(hr)) {
1006 WARN("Unable to enum filters (%x)\n", hr);
1007 goto out;
1010 hr = VFW_E_CANNOT_RENDER;
1011 while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1013 VARIANT var;
1014 GUID clsid;
1015 IPin** ppins;
1016 IPin* ppinfilter = NULL;
1017 IBaseFilter* pfilter = NULL;
1018 IAMGraphBuilderCallback *callback = NULL;
1020 hr = GetFilterInfo(pMoniker, &clsid, &var);
1021 IMoniker_Release(pMoniker);
1022 if (FAILED(hr)) {
1023 WARN("Unable to retrieve filter info (%x)\n", hr);
1024 goto error;
1027 if (IsEqualGUID(&clsid, &FilterCLSID)) {
1028 /* Skip filter (same as the one the output pin belongs to) */
1029 goto error;
1032 if (This->pSite)
1034 IUnknown_QueryInterface(This->pSite, &IID_IAMGraphBuilderCallback, (LPVOID*)&callback);
1035 if (callback)
1037 HRESULT rc;
1038 rc = IAMGraphBuilderCallback_SelectedFilter(callback, pMoniker);
1039 if (FAILED(rc))
1041 TRACE("Filter rejected by IAMGraphBuilderCallback_SelectedFilter\n");
1042 IUnknown_Release(callback);
1043 goto error;
1048 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
1049 if (FAILED(hr)) {
1050 WARN("Unable to create filter (%x), trying next one\n", hr);
1051 goto error;
1054 if (callback)
1056 HRESULT rc;
1057 rc = IAMGraphBuilderCallback_CreatedFilter(callback, pfilter);
1058 IUnknown_Release(callback);
1059 if (FAILED(rc))
1061 IBaseFilter_Release(pfilter);
1062 pfilter = NULL;
1063 TRACE("Filter rejected by IAMGraphBuilderCallback_CreatedFilter\n");
1064 goto error;
1068 hr = IFilterGraph2_AddFilter(iface, pfilter, V_UNION(&var, bstrVal));
1069 if (FAILED(hr)) {
1070 WARN("Unable to add filter (%x)\n", hr);
1071 IBaseFilter_Release(pfilter);
1072 pfilter = NULL;
1073 goto error;
1076 VariantClear(&var);
1078 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1079 if (FAILED(hr)) {
1080 WARN("Enumpins (%x)\n", hr);
1081 goto error;
1084 hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin);
1085 IEnumPins_Release(penumpins);
1087 if (FAILED(hr)) {
1088 WARN("Obtaining next pin: (%x)\n", hr);
1089 goto error;
1091 if (pin == 0) {
1092 WARN("Cannot use this filter: no pins\n");
1093 goto error;
1096 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1097 if (FAILED(hr)) {
1098 TRACE("Cannot connect to filter (%x), trying next one\n", hr);
1099 goto error;
1101 TRACE("Successfully connected to filter, follow chain...\n");
1103 /* Render all output pins of the filter by calling IFilterGraph2_Connect on each of them */
1104 hr = GetInternalConnections(pfilter, ppinfilter, &ppins, &nb);
1106 if (SUCCEEDED(hr)) {
1107 unsigned int i;
1108 if (nb == 0) {
1109 IPin_Disconnect(ppinfilter);
1110 IPin_Disconnect(ppinOut);
1111 goto error;
1113 TRACE("pins to consider: %d\n", nb);
1114 for(i = 0; i < nb; i++)
1116 LPWSTR pinname = NULL;
1118 TRACE("Processing pin %u\n", i);
1120 hr = IPin_QueryId(ppins[i], &pinname);
1121 if (SUCCEEDED(hr))
1123 if (pinname[0] == '~')
1125 TRACE("Pinname=%s, skipping\n", debugstr_w(pinname));
1126 hr = E_FAIL;
1128 else
1129 hr = IFilterGraph2_Connect(iface, ppins[i], ppinIn);
1130 CoTaskMemFree(pinname);
1133 if (FAILED(hr)) {
1134 TRACE("Cannot connect pin %p (%x)\n", ppinfilter, hr);
1136 IPin_Release(ppins[i]);
1137 if (SUCCEEDED(hr)) break;
1139 while (++i < nb) IPin_Release(ppins[i]);
1140 CoTaskMemFree(ppins);
1141 IPin_Release(ppinfilter);
1142 IBaseFilter_Release(pfilter);
1143 if (FAILED(hr))
1145 IPin_Disconnect(ppinfilter);
1146 IPin_Disconnect(ppinOut);
1147 IFilterGraph2_RemoveFilter(iface, pfilter);
1148 continue;
1150 break;
1153 error:
1154 VariantClear(&var);
1155 if (ppinfilter) IPin_Release(ppinfilter);
1156 if (pfilter) {
1157 IFilterGraph2_RemoveFilter(iface, pfilter);
1158 IBaseFilter_Release(pfilter);
1162 out:
1163 if (penummt)
1164 IEnumMediaTypes_Release(penummt);
1165 if (mt)
1166 DeleteMediaType(mt);
1167 --This->recursioncount;
1168 LeaveCriticalSection(&This->cs);
1169 TRACE("--> %08x\n", hr);
1170 return SUCCEEDED(hr) ? S_OK : hr;
1173 static HRESULT FilterGraph2_RenderRecurse(IFilterGraphImpl *This, IPin *ppinOut)
1175 /* This pin has been connected now, try to call render on all pins that aren't connected */
1176 IPin *to = NULL;
1177 PIN_INFO info;
1178 IEnumPins *enumpins = NULL;
1179 BOOL renderany = FALSE;
1180 BOOL renderall = TRUE;
1182 IPin_QueryPinInfo(ppinOut, &info);
1184 IBaseFilter_EnumPins(info.pFilter, &enumpins);
1185 /* Don't need to hold a reference, IEnumPins does */
1186 IBaseFilter_Release(info.pFilter);
1188 IEnumPins_Reset(enumpins);
1189 while (IEnumPins_Next(enumpins, 1, &to, NULL) == S_OK)
1191 PIN_DIRECTION dir = PINDIR_INPUT;
1193 IPin_QueryDirection(to, &dir);
1195 if (dir == PINDIR_OUTPUT)
1197 IPin *out = NULL;
1199 IPin_ConnectedTo(to, &out);
1200 if (!out)
1202 HRESULT hr;
1203 hr = IFilterGraph2_Render(&This->IFilterGraph2_iface, to);
1204 if (SUCCEEDED(hr))
1205 renderany = TRUE;
1206 else
1207 renderall = FALSE;
1209 else
1210 IPin_Release(out);
1213 IPin_Release(to);
1216 IEnumPins_Release(enumpins);
1218 if (renderall)
1219 return S_OK;
1221 if (renderany)
1222 return VFW_S_PARTIAL_RENDER;
1224 return VFW_E_CANNOT_RENDER;
1227 /* Ogg hates me if I create a direct rendering method
1229 * It can only connect to a pin properly once, so use a recursive method that does
1231 * +----+ --- (PIN 1) (Render is called on this pin)
1232 * | |
1233 * +----+ --- (PIN 2)
1235 * Enumerate possible renderers that EXACTLY match the requested type
1237 * If none is available, try to add intermediate filters that can connect to the input pin
1238 * then call Render on that intermediate pin's output pins
1239 * if it succeeds: Render returns success, if it doesn't, the intermediate filter is removed,
1240 * and another filter that can connect to the input pin is tried
1241 * if we run out of filters that can, give up and return VFW_E_CANNOT_RENDER
1242 * It's recursive, but fun!
1245 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *ppinOut)
1247 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1248 IEnumMediaTypes* penummt;
1249 AM_MEDIA_TYPE* mt;
1250 ULONG nbmt;
1251 HRESULT hr;
1253 IEnumMoniker* pEnumMoniker;
1254 GUID tab[4];
1255 ULONG nb;
1256 IMoniker* pMoniker;
1257 INT x;
1259 TRACE("(%p/%p)->(%p)\n", This, iface, ppinOut);
1261 if (TRACE_ON(quartz))
1263 PIN_INFO PinInfo;
1265 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
1266 if (FAILED(hr))
1267 return hr;
1269 TRACE("Filter owning pin => %p\n", PinInfo.pFilter);
1270 IBaseFilter_Release(PinInfo.pFilter);
1273 /* Try to find out if there is a renderer for the specified subtype already, and use that
1275 EnterCriticalSection(&This->cs);
1276 for (x = 0; x < This->nFilters; ++x)
1278 IEnumPins *enumpins = NULL;
1279 IPin *pin = NULL;
1281 hr = IBaseFilter_EnumPins(This->ppFiltersInGraph[x], &enumpins);
1283 if (FAILED(hr) || !enumpins)
1284 continue;
1286 IEnumPins_Reset(enumpins);
1287 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
1289 IPin *to = NULL;
1290 PIN_DIRECTION dir = PINDIR_OUTPUT;
1292 IPin_QueryDirection(pin, &dir);
1293 if (dir != PINDIR_INPUT)
1295 IPin_Release(pin);
1296 continue;
1298 IPin_ConnectedTo(pin, &to);
1300 if (to == NULL)
1302 hr = FilterGraph2_ConnectDirect(iface, ppinOut, pin, NULL);
1303 if (SUCCEEDED(hr))
1305 TRACE("Connected successfully %p/%p, %08x look if we should render more!\n", ppinOut, pin, hr);
1306 IPin_Release(pin);
1308 hr = FilterGraph2_RenderRecurse(This, pin);
1309 if (FAILED(hr))
1311 IPin_Disconnect(ppinOut);
1312 IPin_Disconnect(pin);
1313 continue;
1315 IEnumPins_Release(enumpins);
1316 LeaveCriticalSection(&This->cs);
1317 return hr;
1319 WARN("Could not connect!\n");
1321 else
1322 IPin_Release(to);
1324 IPin_Release(pin);
1326 IEnumPins_Release(enumpins);
1329 LeaveCriticalSection(&This->cs);
1331 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
1332 if (FAILED(hr)) {
1333 WARN("EnumMediaTypes (%x)\n", hr);
1334 return hr;
1337 IEnumMediaTypes_Reset(penummt);
1339 /* Looks like no existing renderer of the kind exists
1340 * Try adding new ones
1342 tab[0] = tab[1] = GUID_NULL;
1343 while (SUCCEEDED(hr))
1345 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
1346 if (FAILED(hr)) {
1347 WARN("IEnumMediaTypes_Next (%x)\n", hr);
1348 break;
1350 if (!nbmt)
1352 hr = VFW_E_CANNOT_RENDER;
1353 break;
1355 else
1357 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1358 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1360 /* Only enumerate once, this doesn't account for all previous ones, but this should be enough nonetheless */
1361 if (IsEqualIID(&tab[0], &mt->majortype) && IsEqualIID(&tab[1], &mt->subtype))
1363 DeleteMediaType(mt);
1364 continue;
1367 /* Try to find a suitable renderer with the same media type */
1368 tab[0] = mt->majortype;
1369 tab[1] = mt->subtype;
1370 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1371 if (FAILED(hr))
1373 WARN("Unable to enum filters (%x)\n", hr);
1374 break;
1377 hr = E_FAIL;
1379 while (IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1381 VARIANT var;
1382 GUID clsid;
1383 IPin* ppinfilter;
1384 IBaseFilter* pfilter = NULL;
1385 IEnumPins* penumpins = NULL;
1386 ULONG pin;
1388 hr = GetFilterInfo(pMoniker, &clsid, &var);
1389 IMoniker_Release(pMoniker);
1390 if (FAILED(hr)) {
1391 WARN("Unable to retrieve filter info (%x)\n", hr);
1392 goto error;
1395 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
1396 if (FAILED(hr))
1398 WARN("Unable to create filter (%x), trying next one\n", hr);
1399 goto error;
1402 hr = IFilterGraph2_AddFilter(iface, pfilter, V_UNION(&var, bstrVal));
1403 if (FAILED(hr)) {
1404 WARN("Unable to add filter (%x)\n", hr);
1405 IBaseFilter_Release(pfilter);
1406 pfilter = NULL;
1407 goto error;
1410 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1411 if (FAILED(hr)) {
1412 WARN("Splitter Enumpins (%x)\n", hr);
1413 goto error;
1416 while ((hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin)) == S_OK)
1418 PIN_DIRECTION dir;
1420 if (pin == 0) {
1421 WARN("No Pin\n");
1422 hr = E_FAIL;
1423 goto error;
1426 hr = IPin_QueryDirection(ppinfilter, &dir);
1427 if (FAILED(hr)) {
1428 IPin_Release(ppinfilter);
1429 WARN("QueryDirection failed (%x)\n", hr);
1430 goto error;
1432 if (dir != PINDIR_INPUT) {
1433 IPin_Release(ppinfilter);
1434 continue; /* Wrong direction */
1437 /* Connect the pin to the "Renderer" */
1438 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1439 IPin_Release(ppinfilter);
1441 if (FAILED(hr)) {
1442 WARN("Unable to connect %s to renderer (%x)\n", debugstr_w(V_UNION(&var, bstrVal)), hr);
1443 goto error;
1445 TRACE("Connected, recursing %s\n", debugstr_w(V_UNION(&var, bstrVal)));
1447 VariantClear(&var);
1449 hr = FilterGraph2_RenderRecurse(This, ppinfilter);
1450 if (FAILED(hr)) {
1451 WARN("Unable to connect recursively (%x)\n", hr);
1452 goto error;
1454 IBaseFilter_Release(pfilter);
1455 break;
1457 if (SUCCEEDED(hr)) {
1458 IEnumPins_Release(penumpins);
1459 break; /* out of IEnumMoniker_Next loop */
1462 /* IEnumPins_Next failed, all other failure case caught by goto error */
1463 WARN("IEnumPins_Next (%x)\n", hr);
1464 /* goto error */
1466 error:
1467 VariantClear(&var);
1468 if (penumpins)
1469 IEnumPins_Release(penumpins);
1470 if (pfilter) {
1471 IFilterGraph2_RemoveFilter(iface, pfilter);
1472 IBaseFilter_Release(pfilter);
1474 if (SUCCEEDED(hr)) DebugBreak();
1477 IEnumMoniker_Release(pEnumMoniker);
1478 if (nbmt)
1479 DeleteMediaType(mt);
1480 if (SUCCEEDED(hr))
1481 break;
1482 hr = S_OK;
1485 IEnumMediaTypes_Release(penummt);
1486 return hr;
1489 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface, LPCWSTR lpcwstrFile,
1490 LPCWSTR lpcwstrPlayList)
1492 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1493 static const WCHAR string[] = {'R','e','a','d','e','r',0};
1494 IBaseFilter* preader = NULL;
1495 IPin* ppinreader = NULL;
1496 IEnumPins* penumpins = NULL;
1497 HRESULT hr;
1498 BOOL partial = FALSE;
1499 HRESULT any = FALSE;
1501 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1503 if (lpcwstrPlayList != NULL)
1504 return E_INVALIDARG;
1506 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, string, &preader);
1507 if (FAILED(hr))
1508 return hr;
1510 if (SUCCEEDED(hr))
1511 hr = IBaseFilter_EnumPins(preader, &penumpins);
1512 if (SUCCEEDED(hr))
1514 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1516 PIN_DIRECTION dir;
1518 IPin_QueryDirection(ppinreader, &dir);
1519 if (dir == PINDIR_OUTPUT)
1521 INT i;
1523 hr = IFilterGraph2_Render(iface, ppinreader);
1524 TRACE("Render %08x\n", hr);
1526 for (i = 0; i < This->nFilters; ++i)
1527 TRACE("Filters in chain: %s\n", debugstr_w(This->pFilterNames[i]));
1529 if (SUCCEEDED(hr))
1530 any = TRUE;
1531 if (hr != S_OK)
1532 partial = TRUE;
1534 IPin_Release(ppinreader);
1536 IEnumPins_Release(penumpins);
1538 if (!any)
1539 hr = VFW_E_CANNOT_RENDER;
1540 else if (partial)
1541 hr = VFW_S_PARTIAL_RENDER;
1542 else
1543 hr = S_OK;
1545 IBaseFilter_Release(preader);
1547 TRACE("--> %08x\n", hr);
1548 return hr;
1551 /* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
1552 static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
1554 static const WCHAR wszReg[] = {'M','e','d','i','a',' ','T','y','p','e','\\','E','x','t','e','n','s','i','o','n','s',0};
1555 HRESULT hr = S_OK;
1556 HKEY extkey;
1557 LONG lRet;
1559 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszReg, 0, KEY_READ, &extkey);
1560 hr = HRESULT_FROM_WIN32(lRet);
1562 if (SUCCEEDED(hr))
1564 static const WCHAR filtersource[] = {'S','o','u','r','c','e',' ','F','i','l','t','e','r',0};
1565 WCHAR *ext = PathFindExtensionW(pszFileName);
1566 WCHAR clsid_key[39];
1567 GUID clsid;
1568 DWORD size = sizeof(clsid_key);
1569 HKEY pathkey;
1571 if (!ext)
1573 CloseHandle(extkey);
1574 return E_FAIL;
1577 lRet = RegOpenKeyExW(extkey, ext, 0, KEY_READ, &pathkey);
1578 hr = HRESULT_FROM_WIN32(lRet);
1579 CloseHandle(extkey);
1580 if (FAILED(hr))
1581 return hr;
1583 lRet = RegQueryValueExW(pathkey, filtersource, NULL, NULL, (LPBYTE)clsid_key, &size);
1584 hr = HRESULT_FROM_WIN32(lRet);
1585 CloseHandle(pathkey);
1586 if (FAILED(hr))
1587 return hr;
1589 CLSIDFromString(clsid_key, &clsid);
1591 TRACE("CLSID: %s\n", debugstr_guid(&clsid));
1592 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1593 if (SUCCEEDED(hr))
1595 IFileSourceFilter *source = NULL;
1596 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID*)&source);
1597 if (SUCCEEDED(hr))
1598 IFileSourceFilter_Release(source);
1599 else
1600 IBaseFilter_Release(*filter);
1603 if (FAILED(hr))
1604 *filter = NULL;
1605 return hr;
1608 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface, LPCWSTR lpcwstrFileName,
1609 LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1611 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1612 HRESULT hr;
1613 IBaseFilter* preader;
1614 IFileSourceFilter* pfile = NULL;
1615 AM_MEDIA_TYPE mt;
1616 WCHAR* filename;
1618 TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1620 /* Try from file name first, then fall back to default asynchronous reader */
1621 hr = GetFileSourceFilter(lpcwstrFileName, &preader);
1623 if (FAILED(hr))
1624 hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&preader);
1625 if (FAILED(hr)) {
1626 WARN("Unable to create file source filter (%x)\n", hr);
1627 return hr;
1630 hr = IFilterGraph2_AddFilter(iface, preader, lpcwstrFilterName);
1631 if (FAILED(hr)) {
1632 WARN("Unable add filter (%x)\n", hr);
1633 IBaseFilter_Release(preader);
1634 return hr;
1637 hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1638 if (FAILED(hr)) {
1639 WARN("Unable to get IFileSourceInterface (%x)\n", hr);
1640 goto error;
1643 /* Load the file in the file source filter */
1644 hr = IFileSourceFilter_Load(pfile, lpcwstrFileName, NULL);
1645 if (FAILED(hr)) {
1646 WARN("Load (%x)\n", hr);
1647 goto error;
1650 IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1651 if (FAILED(hr)) {
1652 WARN("GetCurFile (%x)\n", hr);
1653 goto error;
1656 TRACE("File %s\n", debugstr_w(filename));
1657 TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
1658 TRACE("SubType %s\n", debugstr_guid(&mt.subtype));
1660 if (ppFilter)
1661 *ppFilter = preader;
1662 IFileSourceFilter_Release(pfile);
1664 return S_OK;
1666 error:
1667 if (pfile)
1668 IFileSourceFilter_Release(pfile);
1669 IFilterGraph2_RemoveFilter(iface, preader);
1670 IBaseFilter_Release(preader);
1672 return hr;
1675 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR hFile)
1677 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1679 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1681 return S_OK;
1684 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1686 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1688 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1690 return S_OK;
1693 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1695 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1697 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1699 return S_OK;
1702 /*** IFilterGraph2 methods ***/
1703 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1704 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1706 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1708 TRACE("(%p/%p)->(%p %p %s %p): stub !!!\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1710 return S_OK;
1713 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *ppin,
1714 const AM_MEDIA_TYPE *pmt)
1716 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1718 TRACE("(%p/%p)->(%p %p): stub !!!\n", This, iface, ppin, pmt);
1720 return S_OK;
1723 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *pPinOut, DWORD dwFlags,
1724 DWORD *pvContext)
1726 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1728 TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This, iface, pPinOut, dwFlags, pvContext);
1730 return S_OK;
1734 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1736 FilterGraph2_QueryInterface,
1737 FilterGraph2_AddRef,
1738 FilterGraph2_Release,
1739 FilterGraph2_AddFilter,
1740 FilterGraph2_RemoveFilter,
1741 FilterGraph2_EnumFilters,
1742 FilterGraph2_FindFilterByName,
1743 FilterGraph2_ConnectDirect,
1744 FilterGraph2_Reconnect,
1745 FilterGraph2_Disconnect,
1746 FilterGraph2_SetDefaultSyncSource,
1747 FilterGraph2_Connect,
1748 FilterGraph2_Render,
1749 FilterGraph2_RenderFile,
1750 FilterGraph2_AddSourceFilter,
1751 FilterGraph2_SetLogFile,
1752 FilterGraph2_Abort,
1753 FilterGraph2_ShouldOperationContinue,
1754 FilterGraph2_AddSourceFilterForMoniker,
1755 FilterGraph2_ReconnectEx,
1756 FilterGraph2_RenderEx
1759 static inline IFilterGraphImpl *impl_from_IMediaControl(IMediaControl *iface)
1761 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaControl_iface);
1764 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID riid, void **ppvObj)
1766 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1768 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1770 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
1773 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1775 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1777 TRACE("(%p/%p)->()\n", This, iface);
1779 return IUnknown_AddRef(This->outer_unk);
1782 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1784 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1786 TRACE("(%p/%p)->()\n", This, iface);
1788 return IUnknown_Release(This->outer_unk);
1792 /*** IDispatch methods ***/
1793 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *pctinfo)
1795 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1797 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1799 return S_OK;
1802 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT iTInfo, LCID lcid,
1803 ITypeInfo **ppTInfo)
1805 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1807 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1809 return S_OK;
1812 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID riid,
1813 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1815 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1817 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1819 return S_OK;
1822 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID dispIdMember, REFIID riid,
1823 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
1824 UINT *puArgErr)
1826 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1828 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);
1830 return S_OK;
1833 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *, DWORD_PTR data);
1835 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter, DWORD_PTR data)
1837 HRESULT hr;
1838 IPin* pInputPin;
1839 IPin** ppPins;
1840 ULONG nb;
1841 ULONG i;
1842 PIN_INFO PinInfo;
1844 TRACE("%p %p\n", pGraph, pOutputPin);
1845 PinInfo.pFilter = NULL;
1847 hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1849 if (SUCCEEDED(hr))
1851 hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1852 if (SUCCEEDED(hr))
1853 hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1854 IPin_Release(pInputPin);
1857 if (SUCCEEDED(hr))
1859 if (nb == 0)
1861 TRACE("Reached a renderer\n");
1862 /* Count renderers for end of stream notification */
1863 pGraph->nRenderers++;
1865 else
1867 for(i = 0; i < nb; i++)
1869 /* Explore the graph downstream from this pin
1870 * FIXME: We should prevent exploring from a pin more than once. This can happens when
1871 * several input pins are connected to the same output (a MUX for instance). */
1872 ExploreGraph(pGraph, ppPins[i], FoundFilter, data);
1873 IPin_Release(ppPins[i]);
1876 CoTaskMemFree(ppPins);
1878 TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1880 FoundFilter(PinInfo.pFilter, data);
1883 if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1884 return hr;
1887 static HRESULT WINAPI SendRun(IBaseFilter *pFilter, DWORD_PTR data)
1889 REFERENCE_TIME time = *(REFERENCE_TIME*)data;
1890 return IBaseFilter_Run(pFilter, time);
1893 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1895 return IBaseFilter_Pause(pFilter);
1898 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1900 return IBaseFilter_Stop(pFilter);
1903 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1905 FILTER_STATE state;
1906 DWORD time_end = data;
1907 DWORD time_now = GetTickCount();
1908 LONG wait;
1910 if (time_end == INFINITE)
1912 wait = INFINITE;
1914 else if (time_end > time_now)
1916 wait = time_end - time_now;
1918 else
1919 wait = 0;
1921 return IBaseFilter_GetState(pFilter, wait, &state);
1925 static HRESULT SendFilterMessage(IFilterGraphImpl *This, fnFoundFilter FoundFilter, DWORD_PTR data)
1927 int i;
1928 IBaseFilter* pfilter;
1929 IEnumPins* pEnum;
1930 HRESULT hr;
1931 IPin* pPin;
1932 DWORD dummy;
1933 PIN_DIRECTION dir;
1935 TRACE("(%p)->()\n", This);
1937 /* Explorer the graph from source filters to renderers, determine renderers
1938 * number and run filters from renderers to source filters */
1939 This->nRenderers = 0;
1940 ResetEvent(This->hEventCompletion);
1942 for(i = 0; i < This->nFilters; i++)
1944 BOOL source = TRUE;
1945 pfilter = This->ppFiltersInGraph[i];
1946 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
1947 if (hr != S_OK)
1949 WARN("Enum pins failed %x\n", hr);
1950 continue;
1952 /* Check if it is a source filter */
1953 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1955 IPin_QueryDirection(pPin, &dir);
1956 IPin_Release(pPin);
1957 if (dir == PINDIR_INPUT)
1959 source = FALSE;
1960 break;
1963 if (source)
1965 TRACE("Found a source filter %p\n", pfilter);
1966 IEnumPins_Reset(pEnum);
1967 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1969 /* Explore the graph downstream from this pin */
1970 ExploreGraph(This, pPin, FoundFilter, data);
1971 IPin_Release(pPin);
1973 FoundFilter(pfilter, data);
1975 IEnumPins_Release(pEnum);
1978 return S_FALSE;
1981 /*** IMediaControl methods ***/
1982 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
1984 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1986 TRACE("(%p/%p)->()\n", This, iface);
1988 EnterCriticalSection(&This->cs);
1989 if (This->state == State_Running)
1990 goto out;
1991 This->EcCompleteCount = 0;
1993 if (This->defaultclock && !This->refClock)
1994 IFilterGraph2_SetDefaultSyncSource(&This->IFilterGraph2_iface);
1996 if (This->refClock)
1998 REFERENCE_TIME now;
1999 IReferenceClock_GetTime(This->refClock, &now);
2000 if (This->state == State_Stopped)
2001 This->start_time = now + 500000;
2002 else if (This->pause_time >= 0)
2003 This->start_time += now - This->pause_time;
2004 else
2005 This->start_time = now;
2007 else This->start_time = 0;
2009 SendFilterMessage(This, SendRun, (DWORD_PTR)&This->start_time);
2010 This->state = State_Running;
2011 out:
2012 LeaveCriticalSection(&This->cs);
2013 return S_FALSE;
2016 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
2018 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2020 TRACE("(%p/%p)->()\n", This, iface);
2022 EnterCriticalSection(&This->cs);
2023 if (This->state == State_Paused)
2024 goto out;
2026 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2027 IReferenceClock_GetTime(This->refClock, &This->pause_time);
2028 else
2029 This->pause_time = -1;
2031 SendFilterMessage(This, SendPause, 0);
2032 This->state = State_Paused;
2033 out:
2034 LeaveCriticalSection(&This->cs);
2035 return S_FALSE;
2038 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
2040 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2042 TRACE("(%p/%p)->()\n", This, iface);
2044 if (This->state == State_Stopped) return S_OK;
2046 EnterCriticalSection(&This->cs);
2047 if (This->state == State_Running) SendFilterMessage(This, SendPause, 0);
2048 SendFilterMessage(This, SendStop, 0);
2049 This->state = State_Stopped;
2050 LeaveCriticalSection(&This->cs);
2051 return S_OK;
2054 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG msTimeout,
2055 OAFilterState *pfs)
2057 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2058 DWORD end;
2060 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
2062 if (!pfs)
2063 return E_POINTER;
2065 EnterCriticalSection(&This->cs);
2067 *pfs = This->state;
2068 if (msTimeout > 0)
2070 end = GetTickCount() + msTimeout;
2072 else if (msTimeout < 0)
2074 end = INFINITE;
2076 else
2078 end = 0;
2080 if (end)
2081 SendFilterMessage(This, SendGetState, end);
2083 LeaveCriticalSection(&This->cs);
2085 return S_OK;
2088 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
2090 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2092 FIXME("(%p/%p)->(%s (%p)): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename);
2094 return S_OK;
2097 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
2098 IDispatch **ppUnk)
2100 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2102 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2104 return S_OK;
2107 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2109 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2111 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2113 return S_OK;
2116 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2118 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2120 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2122 return S_OK;
2125 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
2127 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2129 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2131 return S_OK;
2135 static const IMediaControlVtbl IMediaControl_VTable =
2137 MediaControl_QueryInterface,
2138 MediaControl_AddRef,
2139 MediaControl_Release,
2140 MediaControl_GetTypeInfoCount,
2141 MediaControl_GetTypeInfo,
2142 MediaControl_GetIDsOfNames,
2143 MediaControl_Invoke,
2144 MediaControl_Run,
2145 MediaControl_Pause,
2146 MediaControl_Stop,
2147 MediaControl_GetState,
2148 MediaControl_RenderFile,
2149 MediaControl_AddSourceFilter,
2150 MediaControl_get_FilterCollection,
2151 MediaControl_get_RegFilterCollection,
2152 MediaControl_StopWhenReady
2155 static inline IFilterGraphImpl *impl_from_IMediaSeeking(IMediaSeeking *iface)
2157 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaSeeking_iface);
2160 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID riid, void **ppvObj)
2162 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2164 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2166 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2169 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2171 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2173 TRACE("(%p/%p)->()\n", This, iface);
2175 return IUnknown_AddRef(This->outer_unk);
2178 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2180 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2182 TRACE("(%p/%p)->()\n", This, iface);
2184 return IUnknown_Release(This->outer_unk);
2187 typedef HRESULT (WINAPI *fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
2189 static HRESULT all_renderers_seek(IFilterGraphImpl *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2190 BOOL allnotimpl = TRUE;
2191 int i;
2192 HRESULT hr, hr_return = S_OK;
2194 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2195 /* Send a message to all renderers, they are responsible for broadcasting it further */
2197 for(i = 0; i < This->nFilters; i++)
2199 IMediaSeeking *seek = NULL;
2200 IBaseFilter* pfilter = This->ppFiltersInGraph[i];
2201 IAMFilterMiscFlags *flags = NULL;
2202 ULONG filterflags;
2203 IUnknown_QueryInterface(pfilter, &IID_IAMFilterMiscFlags, (void**)&flags);
2204 if (!flags)
2205 continue;
2206 filterflags = IAMFilterMiscFlags_GetMiscFlags(flags);
2207 IUnknown_Release(flags);
2208 if (filterflags != AM_FILTER_MISC_FLAGS_IS_RENDERER)
2209 continue;
2211 IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2212 if (!seek)
2213 continue;
2214 hr = FoundSeek(This, seek, arg);
2215 IMediaSeeking_Release(seek);
2216 if (hr_return != E_NOTIMPL)
2217 allnotimpl = FALSE;
2218 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2219 hr_return = hr;
2222 if (allnotimpl)
2223 return E_NOTIMPL;
2224 return hr_return;
2227 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2229 HRESULT hr;
2230 DWORD caps = 0;
2232 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2233 if (FAILED(hr))
2234 return hr;
2236 /* Only add common capabilities everything supports */
2237 *(DWORD*)pcaps &= caps;
2239 return hr;
2242 /*** IMediaSeeking methods ***/
2243 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2245 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2246 HRESULT hr;
2248 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2250 if (!pCapabilities)
2251 return E_POINTER;
2253 EnterCriticalSection(&This->cs);
2254 *pCapabilities = 0xffffffff;
2256 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2257 LeaveCriticalSection(&This->cs);
2259 return hr;
2262 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2264 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2265 DWORD originalcaps;
2266 HRESULT hr;
2268 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2270 if (!pCapabilities)
2271 return E_POINTER;
2273 EnterCriticalSection(&This->cs);
2274 originalcaps = *pCapabilities;
2275 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2276 LeaveCriticalSection(&This->cs);
2278 if (FAILED(hr))
2279 return hr;
2281 if (!*pCapabilities)
2282 return E_FAIL;
2283 if (*pCapabilities != originalcaps)
2284 return S_FALSE;
2285 return S_OK;
2288 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2290 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2292 if (!pFormat)
2293 return E_POINTER;
2295 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2297 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2299 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2300 return S_FALSE;
2303 return S_OK;
2306 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2308 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2310 if (!pFormat)
2311 return E_POINTER;
2313 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2314 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2316 return S_OK;
2319 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2321 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2323 if (!pFormat)
2324 return E_POINTER;
2326 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2327 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2329 return S_OK;
2332 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2334 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2336 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2337 if (!pFormat)
2338 return E_POINTER;
2340 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2341 return S_FALSE;
2343 return S_OK;
2346 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2348 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2350 if (!pFormat)
2351 return E_POINTER;
2353 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2355 if (This->state != State_Stopped)
2356 return VFW_E_WRONG_STATE;
2358 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2360 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2361 return E_INVALIDARG;
2364 return S_OK;
2367 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2369 HRESULT hr;
2370 LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2372 hr = IMediaSeeking_GetDuration(seek, &duration);
2373 if (FAILED(hr))
2374 return hr;
2376 if (*pdur < duration)
2377 *pdur = duration;
2378 return hr;
2381 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *pDuration)
2383 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2384 HRESULT hr;
2386 TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2388 if (!pDuration)
2389 return E_POINTER;
2391 EnterCriticalSection(&This->cs);
2392 *pDuration = 0;
2393 hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2394 LeaveCriticalSection(&This->cs);
2396 TRACE("--->%08x\n", hr);
2397 return hr;
2400 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *pStop)
2402 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2403 HRESULT hr = S_OK;
2405 TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2407 if (!pStop)
2408 return E_POINTER;
2410 EnterCriticalSection(&This->cs);
2411 if (This->stop_position < 0)
2412 /* Stop position not set, use duration instead */
2413 hr = IMediaSeeking_GetDuration(iface, pStop);
2414 else
2415 *pStop = This->stop_position;
2416 LeaveCriticalSection(&This->cs);
2418 return hr;
2421 static HRESULT WINAPI FoundCurrentPosition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pposition)
2423 HRESULT hr;
2424 LONGLONG pos = 0, *ppos = (LONGLONG*)pposition;
2426 hr = IMediaSeeking_GetCurrentPosition(seek, &pos);
2427 if (FAILED(hr))
2428 return hr;
2430 if (*ppos < 0 || pos < *ppos)
2431 *ppos = pos;
2432 return hr;
2435 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *pCurrent)
2437 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2438 HRESULT hr;
2440 if (!pCurrent)
2441 return E_POINTER;
2443 EnterCriticalSection(&This->cs);
2444 *pCurrent = -1;
2445 hr = all_renderers_seek(This, FoundCurrentPosition, (DWORD_PTR)pCurrent);
2446 if (hr == E_NOTIMPL) {
2447 LONGLONG time = 0;
2448 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2450 IReferenceClock_GetTime(This->refClock, &time);
2451 if (time)
2452 time -= This->start_time;
2454 if (This->pause_time > 0)
2455 time += This->pause_time;
2456 *pCurrent = time;
2457 hr = S_OK;
2459 LeaveCriticalSection(&This->cs);
2461 TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2463 return hr;
2466 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2467 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2469 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2471 FIXME("(%p/%p)->(%p, %p, 0x%s, %p): stub !!!\n", This, iface, pTarget,
2472 pTargetFormat, wine_dbgstr_longlong(Source), pSourceFormat);
2474 return S_OK;
2477 struct pos_args {
2478 LONGLONG* current, *stop;
2479 DWORD curflags, stopflags;
2482 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2484 struct pos_args *args = (void*)pargs;
2486 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
2489 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2490 DWORD dwCurrentFlags, LONGLONG *pStop, DWORD dwStopFlags)
2492 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2493 HRESULT hr = S_OK;
2494 FILTER_STATE state;
2495 struct pos_args args;
2497 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
2499 EnterCriticalSection(&This->cs);
2500 state = This->state;
2501 TRACE("State: %s\n", state == State_Running ? "Running" : (state == State_Paused ? "Paused" : (state == State_Stopped ? "Stopped" : "UNKNOWN")));
2503 if ((dwCurrentFlags & 0x7) != AM_SEEKING_AbsolutePositioning &&
2504 (dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2505 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
2507 if ((dwStopFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2508 This->stop_position = *pStop;
2509 else if ((dwStopFlags & 0x7) != AM_SEEKING_NoPositioning)
2510 FIXME("Stop position not handled yet!\n");
2512 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2513 IMediaControl_Pause(&This->IMediaControl_iface);
2514 args.current = pCurrent;
2515 args.stop = pStop;
2516 args.curflags = dwCurrentFlags;
2517 args.stopflags = dwStopFlags;
2518 hr = all_renderers_seek(This, found_setposition, (DWORD_PTR)&args);
2520 if ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2521 This->pause_time = This->start_time = -1;
2522 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2523 IMediaControl_Run(&This->IMediaControl_iface);
2524 LeaveCriticalSection(&This->cs);
2526 return hr;
2529 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2530 LONGLONG *pStop)
2532 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2533 HRESULT hr;
2535 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pCurrent, pStop);
2536 hr = IMediaSeeking_GetCurrentPosition(iface, pCurrent);
2537 if (SUCCEEDED(hr))
2538 hr = IMediaSeeking_GetStopPosition(iface, pStop);
2540 return hr;
2543 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2544 LONGLONG *pLatest)
2546 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2548 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2550 return S_OK;
2553 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2555 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2557 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2559 return S_OK;
2562 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2564 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2566 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2568 return S_OK;
2571 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2573 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2575 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2577 return S_OK;
2581 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2583 MediaSeeking_QueryInterface,
2584 MediaSeeking_AddRef,
2585 MediaSeeking_Release,
2586 MediaSeeking_GetCapabilities,
2587 MediaSeeking_CheckCapabilities,
2588 MediaSeeking_IsFormatSupported,
2589 MediaSeeking_QueryPreferredFormat,
2590 MediaSeeking_GetTimeFormat,
2591 MediaSeeking_IsUsingTimeFormat,
2592 MediaSeeking_SetTimeFormat,
2593 MediaSeeking_GetDuration,
2594 MediaSeeking_GetStopPosition,
2595 MediaSeeking_GetCurrentPosition,
2596 MediaSeeking_ConvertTimeFormat,
2597 MediaSeeking_SetPositions,
2598 MediaSeeking_GetPositions,
2599 MediaSeeking_GetAvailable,
2600 MediaSeeking_SetRate,
2601 MediaSeeking_GetRate,
2602 MediaSeeking_GetPreroll
2605 static inline IFilterGraphImpl *impl_from_IMediaPosition(IMediaPosition *iface)
2607 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaPosition_iface);
2610 /*** IUnknown methods ***/
2611 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj)
2613 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2615 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2617 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2620 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2622 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2624 TRACE("(%p/%p)->()\n", This, iface);
2626 return IUnknown_AddRef(This->outer_unk);
2629 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2631 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2633 TRACE("(%p/%p)->()\n", This, iface);
2635 return IUnknown_Release(This->outer_unk);
2638 /*** IDispatch methods ***/
2639 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo){
2640 FIXME("(%p) stub!\n", iface);
2641 return E_NOTIMPL;
2644 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo){
2645 FIXME("(%p) stub!\n", iface);
2646 return E_NOTIMPL;
2649 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId){
2650 FIXME("(%p) stub!\n", iface);
2651 return E_NOTIMPL;
2654 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr){
2655 FIXME("(%p) stub!\n", iface);
2656 return E_NOTIMPL;
2659 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2661 GUID time_format;
2662 HRESULT hr;
2664 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2665 if (FAILED(hr))
2666 return hr;
2667 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2669 FIXME("Unsupported time format.\n");
2670 return E_NOTIMPL;
2673 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2674 return S_OK;
2677 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2679 GUID time_format;
2680 HRESULT hr;
2682 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2683 if (FAILED(hr))
2684 return hr;
2685 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2687 FIXME("Unsupported time format.\n");
2688 return E_NOTIMPL;
2691 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2692 return S_OK;
2695 /*** IMediaPosition methods ***/
2696 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2698 LONGLONG duration;
2699 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2700 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2701 if (FAILED(hr))
2702 return hr;
2703 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2706 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2708 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2709 LONGLONG reftime;
2710 HRESULT hr;
2712 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2713 if (FAILED(hr))
2714 return hr;
2715 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2716 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2719 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2721 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2722 LONGLONG pos;
2723 HRESULT hr;
2725 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2726 if (FAILED(hr))
2727 return hr;
2728 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2731 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2733 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2734 LONGLONG pos;
2735 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2736 if (FAILED(hr))
2737 return hr;
2738 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2741 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2743 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2744 LONGLONG reftime;
2745 HRESULT hr;
2747 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2748 if (FAILED(hr))
2749 return hr;
2750 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2751 &reftime, AM_SEEKING_AbsolutePositioning);
2754 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime){
2755 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2756 return E_NOTIMPL;
2759 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime){
2760 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2761 return E_NOTIMPL;
2764 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2766 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2767 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2770 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2772 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2773 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2776 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward){
2777 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2778 return E_NOTIMPL;
2781 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward){
2782 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2783 return E_NOTIMPL;
2787 static const IMediaPositionVtbl IMediaPosition_VTable =
2789 MediaPosition_QueryInterface,
2790 MediaPosition_AddRef,
2791 MediaPosition_Release,
2792 MediaPosition_GetTypeInfoCount,
2793 MediaPosition_GetTypeInfo,
2794 MediaPosition_GetIDsOfNames,
2795 MediaPosition_Invoke,
2796 MediaPosition_get_Duration,
2797 MediaPosition_put_CurrentPosition,
2798 MediaPosition_get_CurrentPosition,
2799 MediaPosition_get_StopTime,
2800 MediaPosition_put_StopTime,
2801 MediaPosition_get_PrerollTime,
2802 MediaPosition_put_PrerollTime,
2803 MediaPosition_put_Rate,
2804 MediaPosition_get_Rate,
2805 MediaPosition_CanSeekForward,
2806 MediaPosition_CanSeekBackward
2809 static inline IFilterGraphImpl *impl_from_IObjectWithSite(IObjectWithSite *iface)
2811 return CONTAINING_RECORD(iface, IFilterGraphImpl, IObjectWithSite_iface);
2814 /*** IUnknown methods ***/
2815 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite* iface, REFIID riid, void** ppvObj)
2817 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2819 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2821 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2824 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
2826 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2828 TRACE("(%p/%p)->()\n", This, iface);
2830 return IUnknown_AddRef(This->outer_unk);
2833 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
2835 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2837 TRACE("(%p/%p)->()\n", This, iface);
2839 return IUnknown_Release(This->outer_unk);
2842 /*** IObjectWithSite methods ***/
2844 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
2846 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2848 TRACE("(%p/%p)->()\n", This, iface);
2849 if (This->pSite) IUnknown_Release(This->pSite);
2850 This->pSite = pUnkSite;
2851 IUnknown_AddRef(This->pSite);
2852 return S_OK;
2855 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, PVOID *ppvSite)
2857 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2859 TRACE("(%p/%p)->(%s)\n", This, iface,debugstr_guid(riid));
2861 *ppvSite = NULL;
2862 if (!This->pSite)
2863 return E_FAIL;
2864 else
2865 return IUnknown_QueryInterface(This->pSite, riid, ppvSite);
2868 static const IObjectWithSiteVtbl IObjectWithSite_VTable =
2870 ObjectWithSite_QueryInterface,
2871 ObjectWithSite_AddRef,
2872 ObjectWithSite_Release,
2873 ObjectWithSite_SetSite,
2874 ObjectWithSite_GetSite,
2877 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2879 HRESULT hr = E_NOINTERFACE;
2880 int i;
2881 int entry;
2883 /* Check if the interface type is already registered */
2884 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2885 if (riid == pGraph->ItfCacheEntries[entry].riid)
2887 if (pGraph->ItfCacheEntries[entry].iface)
2889 /* Return the interface if available */
2890 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2891 return S_OK;
2893 break;
2896 if (entry >= MAX_ITF_CACHE_ENTRIES)
2898 FIXME("Not enough space to store interface in the cache\n");
2899 return E_OUTOFMEMORY;
2902 /* Find a filter supporting the requested interface */
2903 for (i = 0; i < pGraph->nFilters; i++)
2905 hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2906 if (hr == S_OK)
2908 pGraph->ItfCacheEntries[entry].riid = riid;
2909 pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2910 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2911 if (entry >= pGraph->nItfCacheEntries)
2912 pGraph->nItfCacheEntries++;
2913 return S_OK;
2915 if (hr != E_NOINTERFACE)
2916 return hr;
2919 return hr;
2922 static inline IFilterGraphImpl *impl_from_IBasicAudio(IBasicAudio *iface)
2924 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicAudio_iface);
2927 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID riid, void **ppvObj)
2929 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2931 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2933 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2936 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
2938 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2940 TRACE("(%p/%p)->()\n", This, iface);
2942 return IUnknown_AddRef(This->outer_unk);
2945 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
2947 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2949 TRACE("(%p/%p)->()\n", This, iface);
2951 return IUnknown_Release(This->outer_unk);
2954 /*** IDispatch methods ***/
2955 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *pctinfo)
2957 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2958 IBasicAudio* pBasicAudio;
2959 HRESULT hr;
2961 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
2963 EnterCriticalSection(&This->cs);
2965 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2967 if (hr == S_OK)
2968 hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
2970 LeaveCriticalSection(&This->cs);
2972 return hr;
2975 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT iTInfo, LCID lcid,
2976 ITypeInfo **ppTInfo)
2978 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2979 IBasicAudio* pBasicAudio;
2980 HRESULT hr;
2982 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
2984 EnterCriticalSection(&This->cs);
2986 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2988 if (hr == S_OK)
2989 hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
2991 LeaveCriticalSection(&This->cs);
2993 return hr;
2996 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID riid, LPOLESTR *rgszNames,
2997 UINT cNames, LCID lcid, DISPID *rgDispId)
2999 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3000 IBasicAudio* pBasicAudio;
3001 HRESULT hr;
3003 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3005 EnterCriticalSection(&This->cs);
3007 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3009 if (hr == S_OK)
3010 hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
3012 LeaveCriticalSection(&This->cs);
3014 return hr;
3017 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID dispIdMember, REFIID riid,
3018 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3019 UINT *puArgErr)
3021 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3022 IBasicAudio* pBasicAudio;
3023 HRESULT hr;
3025 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);
3027 EnterCriticalSection(&This->cs);
3029 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3031 if (hr == S_OK)
3032 hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3034 LeaveCriticalSection(&This->cs);
3036 return hr;
3039 /*** IBasicAudio methods ***/
3040 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
3042 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3043 IBasicAudio* pBasicAudio;
3044 HRESULT hr;
3046 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
3048 EnterCriticalSection(&This->cs);
3050 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3052 if (hr == S_OK)
3053 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
3055 LeaveCriticalSection(&This->cs);
3057 return hr;
3060 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
3062 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3063 IBasicAudio* pBasicAudio;
3064 HRESULT hr;
3066 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
3068 EnterCriticalSection(&This->cs);
3070 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3072 if (hr == S_OK)
3073 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
3075 LeaveCriticalSection(&This->cs);
3077 return hr;
3080 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
3082 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3083 IBasicAudio* pBasicAudio;
3084 HRESULT hr;
3086 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
3088 EnterCriticalSection(&This->cs);
3090 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3092 if (hr == S_OK)
3093 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
3095 LeaveCriticalSection(&This->cs);
3097 return hr;
3100 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
3102 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3103 IBasicAudio* pBasicAudio;
3104 HRESULT hr;
3106 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
3108 EnterCriticalSection(&This->cs);
3110 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3112 if (hr == S_OK)
3113 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
3115 LeaveCriticalSection(&This->cs);
3117 return hr;
3120 static const IBasicAudioVtbl IBasicAudio_VTable =
3122 BasicAudio_QueryInterface,
3123 BasicAudio_AddRef,
3124 BasicAudio_Release,
3125 BasicAudio_GetTypeInfoCount,
3126 BasicAudio_GetTypeInfo,
3127 BasicAudio_GetIDsOfNames,
3128 BasicAudio_Invoke,
3129 BasicAudio_put_Volume,
3130 BasicAudio_get_Volume,
3131 BasicAudio_put_Balance,
3132 BasicAudio_get_Balance
3135 static inline IFilterGraphImpl *impl_from_IBasicVideo2(IBasicVideo2 *iface)
3137 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicVideo2_iface);
3140 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID riid, void **ppvObj)
3142 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3144 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3146 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
3149 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
3151 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3153 TRACE("(%p/%p)->()\n", This, iface);
3155 return IUnknown_AddRef(This->outer_unk);
3158 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
3160 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3162 TRACE("(%p/%p)->()\n", This, iface);
3164 return IUnknown_Release(This->outer_unk);
3167 /*** IDispatch methods ***/
3168 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *pctinfo)
3170 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3171 IBasicVideo *pBasicVideo;
3172 HRESULT hr;
3174 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3176 EnterCriticalSection(&This->cs);
3178 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3180 if (hr == S_OK)
3181 hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
3183 LeaveCriticalSection(&This->cs);
3185 return hr;
3188 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT iTInfo, LCID lcid,
3189 ITypeInfo **ppTInfo)
3191 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3192 IBasicVideo *pBasicVideo;
3193 HRESULT hr;
3195 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3197 EnterCriticalSection(&This->cs);
3199 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3201 if (hr == S_OK)
3202 hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
3204 LeaveCriticalSection(&This->cs);
3206 return hr;
3209 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID riid,
3210 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
3212 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3213 IBasicVideo *pBasicVideo;
3214 HRESULT hr;
3216 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3218 EnterCriticalSection(&This->cs);
3220 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3222 if (hr == S_OK)
3223 hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
3225 LeaveCriticalSection(&This->cs);
3227 return hr;
3230 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID dispIdMember, REFIID riid,
3231 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3232 UINT *puArgErr)
3234 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3235 IBasicVideo *pBasicVideo;
3236 HRESULT hr;
3238 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);
3240 EnterCriticalSection(&This->cs);
3242 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3244 if (hr == S_OK)
3245 hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3247 LeaveCriticalSection(&This->cs);
3249 return hr;
3252 /*** IBasicVideo methods ***/
3253 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3255 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3256 IBasicVideo *pBasicVideo;
3257 HRESULT hr;
3259 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3261 EnterCriticalSection(&This->cs);
3263 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3265 if (hr == S_OK)
3266 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3268 LeaveCriticalSection(&This->cs);
3270 return hr;
3273 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3275 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3276 IBasicVideo *pBasicVideo;
3277 HRESULT hr;
3279 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3281 EnterCriticalSection(&This->cs);
3283 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3285 if (hr == S_OK)
3286 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3288 LeaveCriticalSection(&This->cs);
3290 return hr;
3293 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3295 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3296 IBasicVideo *pBasicVideo;
3297 HRESULT hr;
3299 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3301 EnterCriticalSection(&This->cs);
3303 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3305 if (hr == S_OK)
3306 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3308 LeaveCriticalSection(&This->cs);
3310 return hr;
3313 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3315 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3316 IBasicVideo *pBasicVideo;
3317 HRESULT hr;
3319 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3321 EnterCriticalSection(&This->cs);
3323 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3325 if (hr == S_OK)
3326 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3328 LeaveCriticalSection(&This->cs);
3330 return hr;
3333 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3335 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3336 IBasicVideo *pBasicVideo;
3337 HRESULT hr;
3339 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3341 EnterCriticalSection(&This->cs);
3343 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3345 if (hr == S_OK)
3346 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3348 LeaveCriticalSection(&This->cs);
3350 return hr;
3353 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3355 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3356 IBasicVideo *pBasicVideo;
3357 HRESULT hr;
3359 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3361 EnterCriticalSection(&This->cs);
3363 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3365 if (hr == S_OK)
3366 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3368 LeaveCriticalSection(&This->cs);
3370 return hr;
3373 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3375 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3376 IBasicVideo *pBasicVideo;
3377 HRESULT hr;
3379 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3381 EnterCriticalSection(&This->cs);
3383 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3385 if (hr == S_OK)
3386 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3388 LeaveCriticalSection(&This->cs);
3390 return hr;
3393 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3395 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3396 IBasicVideo *pBasicVideo;
3397 HRESULT hr;
3399 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3401 EnterCriticalSection(&This->cs);
3403 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3405 if (hr == S_OK)
3406 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3408 LeaveCriticalSection(&This->cs);
3410 return hr;
3413 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3415 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3416 IBasicVideo *pBasicVideo;
3417 HRESULT hr;
3419 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3421 EnterCriticalSection(&This->cs);
3423 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3425 if (hr == S_OK)
3426 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3428 LeaveCriticalSection(&This->cs);
3430 return hr;
3433 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3435 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3436 IBasicVideo *pBasicVideo;
3437 HRESULT hr;
3439 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3441 EnterCriticalSection(&This->cs);
3443 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3445 if (hr == S_OK)
3446 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3448 LeaveCriticalSection(&This->cs);
3450 return hr;
3453 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3455 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3456 IBasicVideo *pBasicVideo;
3457 HRESULT hr;
3459 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3461 EnterCriticalSection(&This->cs);
3463 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3465 if (hr == S_OK)
3466 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3468 LeaveCriticalSection(&This->cs);
3470 return hr;
3473 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3475 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3476 IBasicVideo *pBasicVideo;
3477 HRESULT hr;
3479 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3481 EnterCriticalSection(&This->cs);
3483 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3485 if (hr == S_OK)
3486 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3488 LeaveCriticalSection(&This->cs);
3490 return hr;
3493 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3495 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3496 IBasicVideo *pBasicVideo;
3497 HRESULT hr;
3499 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3501 EnterCriticalSection(&This->cs);
3503 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3505 if (hr == S_OK)
3506 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3508 LeaveCriticalSection(&This->cs);
3510 return hr;
3513 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3515 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3516 IBasicVideo *pBasicVideo;
3517 HRESULT hr;
3519 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3521 EnterCriticalSection(&This->cs);
3523 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3525 if (hr == S_OK)
3526 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3528 LeaveCriticalSection(&This->cs);
3530 return hr;
3533 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3535 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3536 IBasicVideo *pBasicVideo;
3537 HRESULT hr;
3539 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3541 EnterCriticalSection(&This->cs);
3543 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3545 if (hr == S_OK)
3546 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3548 LeaveCriticalSection(&This->cs);
3550 return hr;
3553 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3555 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3556 IBasicVideo *pBasicVideo;
3557 HRESULT hr;
3559 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3561 EnterCriticalSection(&This->cs);
3563 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3565 if (hr == S_OK)
3566 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3568 LeaveCriticalSection(&This->cs);
3570 return hr;
3573 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3575 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3576 IBasicVideo *pBasicVideo;
3577 HRESULT hr;
3579 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3581 EnterCriticalSection(&This->cs);
3583 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3585 if (hr == S_OK)
3586 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3588 LeaveCriticalSection(&This->cs);
3590 return hr;
3593 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3595 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3596 IBasicVideo *pBasicVideo;
3597 HRESULT hr;
3599 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3601 EnterCriticalSection(&This->cs);
3603 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3605 if (hr == S_OK)
3606 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3608 LeaveCriticalSection(&This->cs);
3610 return hr;
3613 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3615 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3616 IBasicVideo *pBasicVideo;
3617 HRESULT hr;
3619 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3621 EnterCriticalSection(&This->cs);
3623 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3625 if (hr == S_OK)
3626 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3628 LeaveCriticalSection(&This->cs);
3630 return hr;
3633 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3635 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3636 IBasicVideo *pBasicVideo;
3637 HRESULT hr;
3639 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3641 EnterCriticalSection(&This->cs);
3643 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3645 if (hr == S_OK)
3646 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3648 LeaveCriticalSection(&This->cs);
3650 return hr;
3653 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3654 LONG *pDestinationHeight)
3656 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3657 IBasicVideo *pBasicVideo;
3658 HRESULT hr;
3660 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3662 EnterCriticalSection(&This->cs);
3664 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3666 if (hr == S_OK)
3667 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3669 LeaveCriticalSection(&This->cs);
3671 return hr;
3674 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3675 LONG Width, LONG Height)
3677 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3678 IBasicVideo *pBasicVideo;
3679 HRESULT hr;
3681 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3683 EnterCriticalSection(&This->cs);
3685 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3687 if (hr == S_OK)
3688 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3690 LeaveCriticalSection(&This->cs);
3692 return hr;
3695 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3696 LONG *pWidth, LONG *pHeight)
3698 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3699 IBasicVideo *pBasicVideo;
3700 HRESULT hr;
3702 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3704 EnterCriticalSection(&This->cs);
3706 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3708 if (hr == S_OK)
3709 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3711 LeaveCriticalSection(&This->cs);
3713 return hr;
3716 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3718 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3719 IBasicVideo *pBasicVideo;
3720 HRESULT hr;
3722 TRACE("(%p/%p)->()\n", This, iface);
3724 EnterCriticalSection(&This->cs);
3726 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3728 if (hr == S_OK)
3729 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3731 LeaveCriticalSection(&This->cs);
3733 return hr;
3736 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3737 LONG Width, LONG Height)
3739 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3740 IBasicVideo *pBasicVideo;
3741 HRESULT hr;
3743 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3745 EnterCriticalSection(&This->cs);
3747 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3749 if (hr == S_OK)
3750 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3752 LeaveCriticalSection(&This->cs);
3754 return hr;
3757 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3758 LONG *pTop, LONG *pWidth, LONG *pHeight)
3760 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3761 IBasicVideo *pBasicVideo;
3762 HRESULT hr;
3764 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3766 EnterCriticalSection(&This->cs);
3768 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3770 if (hr == S_OK)
3771 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3773 LeaveCriticalSection(&This->cs);
3775 return hr;
3778 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3780 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3781 IBasicVideo *pBasicVideo;
3782 HRESULT hr;
3784 TRACE("(%p/%p)->()\n", This, iface);
3786 EnterCriticalSection(&This->cs);
3788 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3790 if (hr == S_OK)
3791 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3793 LeaveCriticalSection(&This->cs);
3795 return hr;
3798 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3800 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3801 IBasicVideo *pBasicVideo;
3802 HRESULT hr;
3804 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3806 EnterCriticalSection(&This->cs);
3808 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3810 if (hr == S_OK)
3811 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3813 LeaveCriticalSection(&This->cs);
3815 return hr;
3818 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3819 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3821 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3822 IBasicVideo *pBasicVideo;
3823 HRESULT hr;
3825 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3827 EnterCriticalSection(&This->cs);
3829 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3831 if (hr == S_OK)
3832 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3834 LeaveCriticalSection(&This->cs);
3836 return hr;
3839 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3840 LONG *pDIBImage)
3842 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3843 IBasicVideo *pBasicVideo;
3844 HRESULT hr;
3846 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3848 EnterCriticalSection(&This->cs);
3850 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3852 if (hr == S_OK)
3853 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3855 LeaveCriticalSection(&This->cs);
3857 return hr;
3860 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3862 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3863 IBasicVideo *pBasicVideo;
3864 HRESULT hr;
3866 TRACE("(%p/%p)->()\n", This, iface);
3868 EnterCriticalSection(&This->cs);
3870 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3872 if (hr == S_OK)
3873 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3875 LeaveCriticalSection(&This->cs);
3877 return hr;
3880 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3882 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3883 IBasicVideo *pBasicVideo;
3884 HRESULT hr;
3886 TRACE("(%p/%p)->()\n", This, iface);
3888 EnterCriticalSection(&This->cs);
3890 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3892 if (hr == S_OK)
3893 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3895 LeaveCriticalSection(&This->cs);
3897 return hr;
3900 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3901 LONG *plAspectY)
3903 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3904 IBasicVideo2 *pBasicVideo2;
3905 HRESULT hr;
3907 TRACE("(%p/%p)->()\n", This, iface);
3909 EnterCriticalSection(&This->cs);
3911 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3913 if (hr == S_OK)
3914 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3916 LeaveCriticalSection(&This->cs);
3918 return hr;
3921 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3923 BasicVideo_QueryInterface,
3924 BasicVideo_AddRef,
3925 BasicVideo_Release,
3926 BasicVideo_GetTypeInfoCount,
3927 BasicVideo_GetTypeInfo,
3928 BasicVideo_GetIDsOfNames,
3929 BasicVideo_Invoke,
3930 BasicVideo_get_AvgTimePerFrame,
3931 BasicVideo_get_BitRate,
3932 BasicVideo_get_BitErrorRate,
3933 BasicVideo_get_VideoWidth,
3934 BasicVideo_get_VideoHeight,
3935 BasicVideo_put_SourceLeft,
3936 BasicVideo_get_SourceLeft,
3937 BasicVideo_put_SourceWidth,
3938 BasicVideo_get_SourceWidth,
3939 BasicVideo_put_SourceTop,
3940 BasicVideo_get_SourceTop,
3941 BasicVideo_put_SourceHeight,
3942 BasicVideo_get_SourceHeight,
3943 BasicVideo_put_DestinationLeft,
3944 BasicVideo_get_DestinationLeft,
3945 BasicVideo_put_DestinationWidth,
3946 BasicVideo_get_DestinationWidth,
3947 BasicVideo_put_DestinationTop,
3948 BasicVideo_get_DestinationTop,
3949 BasicVideo_put_DestinationHeight,
3950 BasicVideo_get_DestinationHeight,
3951 BasicVideo_SetSourcePosition,
3952 BasicVideo_GetSourcePosition,
3953 BasicVideo_SetDefaultSourcePosition,
3954 BasicVideo_SetDestinationPosition,
3955 BasicVideo_GetDestinationPosition,
3956 BasicVideo_SetDefaultDestinationPosition,
3957 BasicVideo_GetVideoSize,
3958 BasicVideo_GetVideoPaletteEntries,
3959 BasicVideo_GetCurrentImage,
3960 BasicVideo_IsUsingDefaultSource,
3961 BasicVideo_IsUsingDefaultDestination,
3962 BasicVideo2_GetPreferredAspectRatio
3965 static inline IFilterGraphImpl *impl_from_IVideoWindow(IVideoWindow *iface)
3967 return CONTAINING_RECORD(iface, IFilterGraphImpl, IVideoWindow_iface);
3970 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID riid, void **ppvObj)
3972 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
3974 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3976 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
3979 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
3981 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
3983 TRACE("(%p/%p)->()\n", This, iface);
3985 return IUnknown_AddRef(This->outer_unk);
3988 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
3990 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
3992 TRACE("(%p/%p)->()\n", This, iface);
3994 return IUnknown_Release(This->outer_unk);
3997 /*** IDispatch methods ***/
3998 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *pctinfo)
4000 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4001 IVideoWindow *pVideoWindow;
4002 HRESULT hr;
4004 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
4006 EnterCriticalSection(&This->cs);
4008 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4010 if (hr == S_OK)
4011 hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
4013 LeaveCriticalSection(&This->cs);
4015 return hr;
4018 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT iTInfo, LCID lcid,
4019 ITypeInfo **ppTInfo)
4021 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4022 IVideoWindow *pVideoWindow;
4023 HRESULT hr;
4025 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
4027 EnterCriticalSection(&This->cs);
4029 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4031 if (hr == S_OK)
4032 hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
4034 LeaveCriticalSection(&This->cs);
4036 return hr;
4039 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID riid,
4040 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4042 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4043 IVideoWindow *pVideoWindow;
4044 HRESULT hr;
4046 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
4048 EnterCriticalSection(&This->cs);
4050 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4052 if (hr == S_OK)
4053 hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
4055 LeaveCriticalSection(&This->cs);
4057 return hr;
4060 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID dispIdMember, REFIID riid,
4061 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4062 UINT*puArgErr)
4064 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4065 IVideoWindow *pVideoWindow;
4066 HRESULT hr;
4068 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);
4070 EnterCriticalSection(&This->cs);
4072 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4074 if (hr == S_OK)
4075 hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4077 LeaveCriticalSection(&This->cs);
4079 return hr;
4083 /*** IVideoWindow methods ***/
4084 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
4086 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4087 IVideoWindow *pVideoWindow;
4088 HRESULT hr;
4090 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
4092 EnterCriticalSection(&This->cs);
4094 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4096 if (hr == S_OK)
4097 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
4099 LeaveCriticalSection(&This->cs);
4101 return hr;
4104 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
4106 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4107 IVideoWindow *pVideoWindow;
4108 HRESULT hr;
4110 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
4112 EnterCriticalSection(&This->cs);
4114 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4116 if (hr == S_OK)
4117 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
4119 LeaveCriticalSection(&This->cs);
4121 return hr;
4124 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
4126 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4127 IVideoWindow *pVideoWindow;
4128 HRESULT hr;
4130 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
4132 EnterCriticalSection(&This->cs);
4134 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4136 if (hr == S_OK)
4137 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
4139 LeaveCriticalSection(&This->cs);
4141 return hr;
4144 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
4146 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4147 IVideoWindow *pVideoWindow;
4148 HRESULT hr;
4150 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
4152 EnterCriticalSection(&This->cs);
4154 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4156 if (hr == S_OK)
4157 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
4159 LeaveCriticalSection(&This->cs);
4161 return hr;
4164 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
4166 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4167 IVideoWindow *pVideoWindow;
4168 HRESULT hr;
4170 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
4172 EnterCriticalSection(&This->cs);
4174 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4176 if (hr == S_OK)
4177 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
4179 LeaveCriticalSection(&This->cs);
4181 return hr;
4184 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
4186 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4187 IVideoWindow *pVideoWindow;
4188 HRESULT hr;
4190 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
4192 EnterCriticalSection(&This->cs);
4194 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4196 if (hr == S_OK)
4197 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
4199 LeaveCriticalSection(&This->cs);
4201 return hr;
4204 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
4206 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4207 IVideoWindow *pVideoWindow;
4208 HRESULT hr;
4210 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
4212 EnterCriticalSection(&This->cs);
4214 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4216 if (hr == S_OK)
4217 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4219 LeaveCriticalSection(&This->cs);
4221 return hr;
4224 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
4226 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4227 IVideoWindow *pVideoWindow;
4228 HRESULT hr;
4230 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4232 EnterCriticalSection(&This->cs);
4234 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4236 if (hr == S_OK)
4237 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4239 LeaveCriticalSection(&This->cs);
4241 return hr;
4244 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
4246 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4247 IVideoWindow *pVideoWindow;
4248 HRESULT hr;
4250 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4252 EnterCriticalSection(&This->cs);
4254 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4256 if (hr == S_OK)
4257 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4259 LeaveCriticalSection(&This->cs);
4261 return hr;
4264 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4266 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4267 IVideoWindow *pVideoWindow;
4268 HRESULT hr;
4270 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4272 EnterCriticalSection(&This->cs);
4274 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4276 if (hr == S_OK)
4277 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4279 LeaveCriticalSection(&This->cs);
4281 return hr;
4284 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4286 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4287 IVideoWindow *pVideoWindow;
4288 HRESULT hr;
4290 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4292 EnterCriticalSection(&This->cs);
4294 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4296 if (hr == S_OK)
4297 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4299 LeaveCriticalSection(&This->cs);
4301 return hr;
4304 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4305 LONG *pBackgroundPalette)
4307 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4308 IVideoWindow *pVideoWindow;
4309 HRESULT hr;
4311 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4313 EnterCriticalSection(&This->cs);
4315 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4317 if (hr == S_OK)
4318 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4320 LeaveCriticalSection(&This->cs);
4322 return hr;
4325 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4327 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4328 IVideoWindow *pVideoWindow;
4329 HRESULT hr;
4331 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4333 EnterCriticalSection(&This->cs);
4335 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4337 if (hr == S_OK)
4338 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4340 LeaveCriticalSection(&This->cs);
4342 return hr;
4345 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4347 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4348 IVideoWindow *pVideoWindow;
4349 HRESULT hr;
4351 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4353 EnterCriticalSection(&This->cs);
4355 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4357 if (hr == S_OK)
4358 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4360 LeaveCriticalSection(&This->cs);
4362 return hr;
4365 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4367 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4368 IVideoWindow *pVideoWindow;
4369 HRESULT hr;
4371 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4373 EnterCriticalSection(&This->cs);
4375 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4377 if (hr == S_OK)
4378 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4380 LeaveCriticalSection(&This->cs);
4382 return hr;
4385 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4387 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4388 IVideoWindow *pVideoWindow;
4389 HRESULT hr;
4391 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4393 EnterCriticalSection(&This->cs);
4395 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4397 if (hr == S_OK)
4398 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4400 LeaveCriticalSection(&This->cs);
4402 return hr;
4405 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4407 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4408 IVideoWindow *pVideoWindow;
4409 HRESULT hr;
4411 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4413 EnterCriticalSection(&This->cs);
4415 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4417 if (hr == S_OK)
4418 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4420 LeaveCriticalSection(&This->cs);
4422 return hr;
4425 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4427 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4428 IVideoWindow *pVideoWindow;
4429 HRESULT hr;
4431 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4433 EnterCriticalSection(&This->cs);
4435 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4437 if (hr == S_OK)
4438 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4440 LeaveCriticalSection(&This->cs);
4442 return hr;
4445 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4447 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4448 IVideoWindow *pVideoWindow;
4449 HRESULT hr;
4451 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4453 EnterCriticalSection(&This->cs);
4455 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4457 if (hr == S_OK)
4458 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4460 LeaveCriticalSection(&This->cs);
4462 return hr;
4465 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4467 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4468 IVideoWindow *pVideoWindow;
4469 HRESULT hr;
4471 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4473 EnterCriticalSection(&This->cs);
4475 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4477 if (hr == S_OK)
4478 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4480 LeaveCriticalSection(&This->cs);
4482 return hr;
4485 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4487 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4488 IVideoWindow *pVideoWindow;
4489 HRESULT hr;
4491 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4493 EnterCriticalSection(&This->cs);
4495 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4497 if (hr == S_OK)
4498 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4500 LeaveCriticalSection(&This->cs);
4502 return hr;
4505 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4507 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4508 IVideoWindow *pVideoWindow;
4509 HRESULT hr;
4511 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4513 EnterCriticalSection(&This->cs);
4515 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4517 if (hr == S_OK)
4518 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4520 LeaveCriticalSection(&This->cs);
4522 return hr;
4525 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4527 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4528 IVideoWindow *pVideoWindow;
4529 HRESULT hr;
4531 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4533 EnterCriticalSection(&This->cs);
4535 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4537 if (hr == S_OK)
4538 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4540 LeaveCriticalSection(&This->cs);
4542 return hr;
4545 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4547 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4548 IVideoWindow *pVideoWindow;
4549 HRESULT hr;
4551 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4553 EnterCriticalSection(&This->cs);
4555 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4557 if (hr == S_OK)
4558 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4560 LeaveCriticalSection(&This->cs);
4562 return hr;
4565 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4567 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4568 IVideoWindow *pVideoWindow;
4569 HRESULT hr;
4571 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4573 EnterCriticalSection(&This->cs);
4575 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4577 if (hr == S_OK)
4578 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4580 LeaveCriticalSection(&This->cs);
4582 return hr;
4585 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4587 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4588 IVideoWindow *pVideoWindow;
4589 HRESULT hr;
4591 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4593 EnterCriticalSection(&This->cs);
4595 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4597 if (hr == S_OK)
4598 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4600 LeaveCriticalSection(&This->cs);
4602 return hr;
4605 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4607 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4608 IVideoWindow *pVideoWindow;
4609 HRESULT hr;
4611 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4613 EnterCriticalSection(&This->cs);
4615 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4617 if (hr == S_OK)
4618 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4620 LeaveCriticalSection(&This->cs);
4622 return hr;
4625 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4627 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4628 IVideoWindow *pVideoWindow;
4629 HRESULT hr;
4631 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4633 EnterCriticalSection(&This->cs);
4635 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4637 if (hr == S_OK)
4638 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4640 LeaveCriticalSection(&This->cs);
4642 return hr;
4645 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4647 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4648 IVideoWindow *pVideoWindow;
4649 HRESULT hr;
4651 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4653 EnterCriticalSection(&This->cs);
4655 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4657 if (hr == S_OK)
4658 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4660 LeaveCriticalSection(&This->cs);
4662 return hr;
4665 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4667 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4668 IVideoWindow *pVideoWindow;
4669 HRESULT hr;
4671 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4673 EnterCriticalSection(&This->cs);
4675 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4677 if (hr == S_OK)
4678 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4680 LeaveCriticalSection(&This->cs);
4682 return hr;
4685 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4687 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4688 IVideoWindow *pVideoWindow;
4689 HRESULT hr;
4691 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4693 EnterCriticalSection(&This->cs);
4695 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4697 if (hr == S_OK)
4698 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4700 LeaveCriticalSection(&This->cs);
4702 return hr;
4705 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4706 LONG_PTR wParam, LONG_PTR lParam)
4708 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4709 IVideoWindow *pVideoWindow;
4710 HRESULT hr;
4712 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4714 EnterCriticalSection(&This->cs);
4716 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4718 if (hr == S_OK)
4719 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4721 LeaveCriticalSection(&This->cs);
4723 return hr;
4726 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4727 LONG Width, LONG Height)
4729 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4730 IVideoWindow *pVideoWindow;
4731 HRESULT hr;
4733 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4735 EnterCriticalSection(&This->cs);
4737 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4739 if (hr == S_OK)
4740 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4742 LeaveCriticalSection(&This->cs);
4744 return hr;
4747 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4748 LONG *pWidth, LONG *pHeight)
4750 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4751 IVideoWindow *pVideoWindow;
4752 HRESULT hr;
4754 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4756 EnterCriticalSection(&This->cs);
4758 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4760 if (hr == S_OK)
4761 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4763 LeaveCriticalSection(&This->cs);
4765 return hr;
4768 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4769 LONG *pHeight)
4771 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4772 IVideoWindow *pVideoWindow;
4773 HRESULT hr;
4775 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4777 EnterCriticalSection(&This->cs);
4779 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4781 if (hr == S_OK)
4782 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4784 LeaveCriticalSection(&This->cs);
4786 return hr;
4789 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4790 LONG *pHeight)
4792 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4793 IVideoWindow *pVideoWindow;
4794 HRESULT hr;
4796 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4798 EnterCriticalSection(&This->cs);
4800 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4802 if (hr == S_OK)
4803 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4805 LeaveCriticalSection(&This->cs);
4807 return hr;
4810 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4811 LONG *pWidth, LONG *pHeight)
4813 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4814 IVideoWindow *pVideoWindow;
4815 HRESULT hr;
4817 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4819 EnterCriticalSection(&This->cs);
4821 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4823 if (hr == S_OK)
4824 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4826 LeaveCriticalSection(&This->cs);
4828 return hr;
4831 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4833 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4834 IVideoWindow *pVideoWindow;
4835 HRESULT hr;
4837 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4839 EnterCriticalSection(&This->cs);
4841 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4843 if (hr == S_OK)
4844 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4846 LeaveCriticalSection(&This->cs);
4848 return hr;
4851 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4853 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4854 IVideoWindow *pVideoWindow;
4855 HRESULT hr;
4857 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4859 EnterCriticalSection(&This->cs);
4861 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4863 if (hr == S_OK)
4864 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4866 LeaveCriticalSection(&This->cs);
4868 return hr;
4872 static const IVideoWindowVtbl IVideoWindow_VTable =
4874 VideoWindow_QueryInterface,
4875 VideoWindow_AddRef,
4876 VideoWindow_Release,
4877 VideoWindow_GetTypeInfoCount,
4878 VideoWindow_GetTypeInfo,
4879 VideoWindow_GetIDsOfNames,
4880 VideoWindow_Invoke,
4881 VideoWindow_put_Caption,
4882 VideoWindow_get_Caption,
4883 VideoWindow_put_WindowStyle,
4884 VideoWindow_get_WindowStyle,
4885 VideoWindow_put_WindowStyleEx,
4886 VideoWindow_get_WindowStyleEx,
4887 VideoWindow_put_AutoShow,
4888 VideoWindow_get_AutoShow,
4889 VideoWindow_put_WindowState,
4890 VideoWindow_get_WindowState,
4891 VideoWindow_put_BackgroundPalette,
4892 VideoWindow_get_BackgroundPalette,
4893 VideoWindow_put_Visible,
4894 VideoWindow_get_Visible,
4895 VideoWindow_put_Left,
4896 VideoWindow_get_Left,
4897 VideoWindow_put_Width,
4898 VideoWindow_get_Width,
4899 VideoWindow_put_Top,
4900 VideoWindow_get_Top,
4901 VideoWindow_put_Height,
4902 VideoWindow_get_Height,
4903 VideoWindow_put_Owner,
4904 VideoWindow_get_Owner,
4905 VideoWindow_put_MessageDrain,
4906 VideoWindow_get_MessageDrain,
4907 VideoWindow_get_BorderColor,
4908 VideoWindow_put_BorderColor,
4909 VideoWindow_get_FullScreenMode,
4910 VideoWindow_put_FullScreenMode,
4911 VideoWindow_SetWindowForeground,
4912 VideoWindow_NotifyOwnerMessage,
4913 VideoWindow_SetWindowPosition,
4914 VideoWindow_GetWindowPosition,
4915 VideoWindow_GetMinIdealImageSize,
4916 VideoWindow_GetMaxIdealImageSize,
4917 VideoWindow_GetRestorePosition,
4918 VideoWindow_HideCursor,
4919 VideoWindow_IsCursorHidden
4922 static inline IFilterGraphImpl *impl_from_IMediaEventEx(IMediaEventEx *iface)
4924 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventEx_iface);
4927 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID riid, void **ppvObj)
4929 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4931 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
4933 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
4936 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
4938 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4940 TRACE("(%p/%p)->()\n", This, iface);
4942 return IUnknown_AddRef(This->outer_unk);
4945 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
4947 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4949 TRACE("(%p/%p)->()\n", This, iface);
4951 return IUnknown_Release(This->outer_unk);
4954 /*** IDispatch methods ***/
4955 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *pctinfo)
4957 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4959 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
4961 return S_OK;
4964 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT iTInfo, LCID lcid,
4965 ITypeInfo **ppTInfo)
4967 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4969 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
4971 return S_OK;
4974 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID riid,
4975 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4977 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4979 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
4981 return S_OK;
4984 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID dispIdMember, REFIID riid,
4985 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4986 UINT *puArgErr)
4988 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4990 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);
4992 return S_OK;
4995 /*** IMediaEvent methods ***/
4996 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *hEvent)
4998 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5000 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
5002 *hEvent = (OAEVENT)This->evqueue.msg_event;
5004 return S_OK;
5007 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *lEventCode, LONG_PTR *lParam1,
5008 LONG_PTR *lParam2, LONG msTimeout)
5010 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5011 Event evt;
5013 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
5015 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
5017 *lEventCode = evt.lEventCode;
5018 *lParam1 = evt.lParam1;
5019 *lParam2 = evt.lParam2;
5020 return S_OK;
5023 *lEventCode = 0;
5024 return E_ABORT;
5027 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
5028 LONG *pEvCode)
5030 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5032 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
5034 if (This->state != State_Running)
5035 return VFW_E_WRONG_STATE;
5037 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
5039 *pEvCode = This->CompletionStatus;
5040 return S_OK;
5043 *pEvCode = 0;
5044 return E_ABORT;
5047 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5049 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5051 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5053 if (lEvCode == EC_COMPLETE)
5054 This->HandleEcComplete = FALSE;
5055 else if (lEvCode == EC_REPAINT)
5056 This->HandleEcRepaint = FALSE;
5057 else if (lEvCode == EC_CLOCK_CHANGED)
5058 This->HandleEcClockChanged = FALSE;
5059 else
5060 return S_FALSE;
5062 return S_OK;
5065 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5067 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5069 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5071 if (lEvCode == EC_COMPLETE)
5072 This->HandleEcComplete = TRUE;
5073 else if (lEvCode == EC_REPAINT)
5074 This->HandleEcRepaint = TRUE;
5075 else if (lEvCode == EC_CLOCK_CHANGED)
5076 This->HandleEcClockChanged = TRUE;
5077 else
5078 return S_FALSE;
5080 return S_OK;
5083 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG lEvCode,
5084 LONG_PTR lParam1, LONG_PTR lParam2)
5086 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5088 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
5090 return S_OK;
5093 /*** IMediaEventEx methods ***/
5094 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface, OAHWND hwnd, LONG lMsg,
5095 LONG_PTR lInstanceData)
5097 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5099 TRACE("(%p/%p)->(%08lx, %d, %08lx)\n", This, iface, hwnd, lMsg, lInstanceData);
5101 This->notif.hWnd = (HWND)hwnd;
5102 This->notif.msg = lMsg;
5103 This->notif.instance = lInstanceData;
5105 return S_OK;
5108 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG lNoNotifyFlags)
5110 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5112 TRACE("(%p/%p)->(%d)\n", This, iface, lNoNotifyFlags);
5114 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
5115 return E_INVALIDARG;
5117 This->notif.disabled = lNoNotifyFlags;
5119 return S_OK;
5122 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *lplNoNotifyFlags)
5124 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5126 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
5128 if (!lplNoNotifyFlags)
5129 return E_POINTER;
5131 *lplNoNotifyFlags = This->notif.disabled;
5133 return S_OK;
5137 static const IMediaEventExVtbl IMediaEventEx_VTable =
5139 MediaEvent_QueryInterface,
5140 MediaEvent_AddRef,
5141 MediaEvent_Release,
5142 MediaEvent_GetTypeInfoCount,
5143 MediaEvent_GetTypeInfo,
5144 MediaEvent_GetIDsOfNames,
5145 MediaEvent_Invoke,
5146 MediaEvent_GetEventHandle,
5147 MediaEvent_GetEvent,
5148 MediaEvent_WaitForCompletion,
5149 MediaEvent_CancelDefaultHandling,
5150 MediaEvent_RestoreDefaultHandling,
5151 MediaEvent_FreeEventParams,
5152 MediaEvent_SetNotifyWindow,
5153 MediaEvent_SetNotifyFlags,
5154 MediaEvent_GetNotifyFlags
5158 static inline IFilterGraphImpl *impl_from_IMediaFilter(IMediaFilter *iface)
5160 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaFilter_iface);
5163 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, void **ppv)
5165 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5167 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5170 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
5172 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5174 return IUnknown_AddRef(This->outer_unk);
5177 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
5179 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5181 return IUnknown_Release(This->outer_unk);
5184 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
5186 FIXME("(%p): stub\n", pClassID);
5188 return E_NOTIMPL;
5191 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
5193 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5195 return MediaControl_Stop(&This->IMediaControl_iface);
5198 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5200 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5202 return MediaControl_Pause(&This->IMediaControl_iface);
5205 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
5207 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5209 if (tStart)
5210 FIXME("Run called with non-null tStart: %x%08x\n",
5211 (int)(tStart>>32), (int)tStart);
5213 return MediaControl_Run(&This->IMediaControl_iface);
5216 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout,
5217 FILTER_STATE *pState)
5219 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5221 return MediaControl_GetState(&This->IMediaControl_iface, dwMsTimeout, (OAFilterState*)pState);
5224 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5226 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5227 HRESULT hr = S_OK;
5228 int i;
5230 TRACE("(%p/%p)->(%p)\n", iface, This, pClock);
5232 EnterCriticalSection(&This->cs);
5234 for (i = 0;i < This->nFilters;i++)
5236 hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5237 if (FAILED(hr))
5238 break;
5241 if (FAILED(hr))
5243 for(;i >= 0;i--)
5244 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5246 else
5248 if (This->refClock)
5249 IReferenceClock_Release(This->refClock);
5250 This->refClock = pClock;
5251 if (This->refClock)
5252 IReferenceClock_AddRef(This->refClock);
5253 This->defaultclock = FALSE;
5255 if (This->HandleEcClockChanged)
5257 IMediaEventSink *pEventSink;
5258 HRESULT eshr;
5260 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (LPVOID)&pEventSink);
5261 if (SUCCEEDED(eshr))
5263 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5264 IMediaEventSink_Release(pEventSink);
5269 LeaveCriticalSection(&This->cs);
5271 return hr;
5274 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5276 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5278 TRACE("(%p/%p)->(%p)\n", iface, This, ppClock);
5280 if (!ppClock)
5281 return E_POINTER;
5283 EnterCriticalSection(&This->cs);
5285 *ppClock = This->refClock;
5286 if (*ppClock)
5287 IReferenceClock_AddRef(*ppClock);
5289 LeaveCriticalSection(&This->cs);
5291 return S_OK;
5294 static const IMediaFilterVtbl IMediaFilter_VTable =
5296 MediaFilter_QueryInterface,
5297 MediaFilter_AddRef,
5298 MediaFilter_Release,
5299 MediaFilter_GetClassID,
5300 MediaFilter_Stop,
5301 MediaFilter_Pause,
5302 MediaFilter_Run,
5303 MediaFilter_GetState,
5304 MediaFilter_SetSyncSource,
5305 MediaFilter_GetSyncSource
5308 static inline IFilterGraphImpl *impl_from_IMediaEventSink(IMediaEventSink *iface)
5310 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventSink_iface);
5313 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, void **ppv)
5315 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5317 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5320 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5322 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5324 return IUnknown_AddRef(This->outer_unk);
5327 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5329 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5331 return IUnknown_Release(This->outer_unk);
5334 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG EventCode,
5335 LONG_PTR EventParam1, LONG_PTR EventParam2)
5337 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5338 Event evt;
5340 TRACE("(%p/%p)->(%d, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5342 /* We need thread safety here, let's use the events queue's one */
5343 EnterCriticalSection(&This->evqueue.msg_crst);
5345 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5347 TRACE("Process EC_COMPLETE notification\n");
5348 if (++This->EcCompleteCount == This->nRenderers)
5350 evt.lEventCode = EC_COMPLETE;
5351 evt.lParam1 = S_OK;
5352 evt.lParam2 = 0;
5353 TRACE("Send EC_COMPLETE to app\n");
5354 EventsQueue_PutEvent(&This->evqueue, &evt);
5355 if (!This->notif.disabled && This->notif.hWnd)
5357 TRACE("Send Window message\n");
5358 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5360 This->CompletionStatus = EC_COMPLETE;
5361 SetEvent(This->hEventCompletion);
5364 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5366 /* FIXME: Not handled yet */
5368 else
5370 evt.lEventCode = EventCode;
5371 evt.lParam1 = EventParam1;
5372 evt.lParam2 = EventParam2;
5373 EventsQueue_PutEvent(&This->evqueue, &evt);
5374 if (!This->notif.disabled && This->notif.hWnd)
5375 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5378 LeaveCriticalSection(&This->evqueue.msg_crst);
5379 return S_OK;
5382 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5384 MediaEventSink_QueryInterface,
5385 MediaEventSink_AddRef,
5386 MediaEventSink_Release,
5387 MediaEventSink_Notify
5390 static inline IFilterGraphImpl *impl_from_IGraphConfig(IGraphConfig *iface)
5392 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphConfig_iface);
5395 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, void **ppv)
5397 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5399 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5402 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5404 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5406 return IUnknown_AddRef(This->outer_unk);
5409 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5411 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5413 return IUnknown_Release(This->outer_unk);
5416 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *pOutputPin, IPin *pInputPin,
5417 const AM_MEDIA_TYPE *pmtFirstConnection, IBaseFilter *pUsingFilter, HANDLE hAbortEvent,
5418 DWORD dwFlags)
5420 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5422 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5424 return E_NOTIMPL;
5427 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface, IGraphConfigCallback *pCallback,
5428 void *pvContext, DWORD dwFlags, HANDLE hAbortEvent)
5430 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5431 HRESULT hr;
5433 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5435 if (hAbortEvent)
5436 FIXME("The parameter hAbortEvent is not handled!\n");
5438 EnterCriticalSection(&This->cs);
5440 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5442 LeaveCriticalSection(&This->cs);
5444 return hr;
5447 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5449 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5451 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5453 return E_NOTIMPL;
5456 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5458 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5460 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5462 return E_NOTIMPL;
5465 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5467 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5469 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5471 return E_NOTIMPL;
5474 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5476 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5478 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5480 return E_NOTIMPL;
5483 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5484 IPinConnection *pConnection, HANDLE hEventAbort)
5486 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5488 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5490 return E_NOTIMPL;
5493 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5494 DWORD dwFlags)
5496 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5498 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5500 return E_NOTIMPL;
5503 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5504 DWORD *dwFlags)
5506 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5508 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5510 return E_NOTIMPL;
5513 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *pFilter,
5514 DWORD dwFlags)
5516 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5518 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5520 return E_NOTIMPL;
5523 static const IGraphConfigVtbl IGraphConfig_VTable =
5525 GraphConfig_QueryInterface,
5526 GraphConfig_AddRef,
5527 GraphConfig_Release,
5528 GraphConfig_Reconnect,
5529 GraphConfig_Reconfigure,
5530 GraphConfig_AddFilterToCache,
5531 GraphConfig_EnumCacheFilter,
5532 GraphConfig_RemoveFilterFromCache,
5533 GraphConfig_GetStartTime,
5534 GraphConfig_PushThroughData,
5535 GraphConfig_SetFilterFlags,
5536 GraphConfig_GetFilterFlags,
5537 GraphConfig_RemoveFilterEx
5540 static const IUnknownVtbl IInner_VTable =
5542 FilterGraphInner_QueryInterface,
5543 FilterGraphInner_AddRef,
5544 FilterGraphInner_Release
5547 /* This is the only function that actually creates a FilterGraph class... */
5548 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5550 IFilterGraphImpl *fimpl;
5551 HRESULT hr;
5553 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5555 *ppObj = NULL;
5557 fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5558 fimpl->defaultclock = TRUE;
5559 fimpl->IUnknown_inner.lpVtbl = &IInner_VTable;
5560 fimpl->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5561 fimpl->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5562 fimpl->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5563 fimpl->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5564 fimpl->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5565 fimpl->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5566 fimpl->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5567 fimpl->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5568 fimpl->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5569 fimpl->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5570 fimpl->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5571 fimpl->IObjectWithSite_iface.lpVtbl = &IObjectWithSite_VTable;
5572 fimpl->ref = 1;
5573 fimpl->ppFiltersInGraph = NULL;
5574 fimpl->pFilterNames = NULL;
5575 fimpl->nFilters = 0;
5576 fimpl->filterCapacity = 0;
5577 fimpl->nameIndex = 1;
5578 fimpl->refClock = NULL;
5579 fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5580 fimpl->HandleEcComplete = TRUE;
5581 fimpl->HandleEcRepaint = TRUE;
5582 fimpl->HandleEcClockChanged = TRUE;
5583 fimpl->notif.hWnd = 0;
5584 fimpl->notif.disabled = FALSE;
5585 fimpl->nRenderers = 0;
5586 fimpl->EcCompleteCount = 0;
5587 fimpl->refClockProvider = NULL;
5588 fimpl->state = State_Stopped;
5589 fimpl->pSite = NULL;
5590 EventsQueue_Init(&fimpl->evqueue);
5591 InitializeCriticalSection(&fimpl->cs);
5592 fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5593 fimpl->nItfCacheEntries = 0;
5594 memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5595 fimpl->start_time = fimpl->pause_time = 0;
5596 fimpl->stop_position = -1;
5597 fimpl->punkFilterMapper2 = NULL;
5598 fimpl->recursioncount = 0;
5600 if (pUnkOuter)
5601 fimpl->outer_unk = pUnkOuter;
5602 else
5603 fimpl->outer_unk = &fimpl->IUnknown_inner;
5605 /* create Filtermapper aggregated. */
5606 hr = CoCreateInstance(&CLSID_FilterMapper2, fimpl->outer_unk, CLSCTX_INPROC_SERVER,
5607 &IID_IUnknown, (void**)&fimpl->punkFilterMapper2);
5609 if (SUCCEEDED(hr))
5610 hr = IUnknown_QueryInterface(fimpl->punkFilterMapper2, &IID_IFilterMapper2,
5611 (void**)&fimpl->pFilterMapper2);
5613 if (SUCCEEDED(hr))
5614 /* Release controlling IUnknown - compensate refcount increase from caching IFilterMapper2 interface. */
5615 IUnknown_Release(fimpl->outer_unk);
5617 if (FAILED(hr)) {
5618 ERR("Unable to create filter mapper (%x)\n", hr);
5619 if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5620 CloseHandle(fimpl->hEventCompletion);
5621 EventsQueue_Destroy(&fimpl->evqueue);
5622 fimpl->cs.DebugInfo->Spare[0] = 0;
5623 DeleteCriticalSection(&fimpl->cs);
5624 CoTaskMemFree(fimpl);
5625 return hr;
5628 *ppObj = &fimpl->IUnknown_inner;
5629 return S_OK;
5632 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5634 FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5635 return FilterGraph_create(pUnkOuter, ppObj);