dmusic/tests: Use void* instead of void** type value for outer argument.
[wine.git] / dlls / quartz / filtergraph.c
blobf9bc47b43c65416362d18a650822995fcfad3221
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 BOOL 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 BOOL 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 IGraphVersion IGraphVersion_iface;
166 /* IAMGraphStreams */
167 /* IAMStats */
168 /* IFilterChain */
169 /* IFilterMapper2 */
170 /* IQueueCommand */
171 /* IRegisterServiceProvider */
172 /* IResourceMananger */
173 /* IServiceProvider */
174 /* IVideoFrameStep */
176 IUnknown *outer_unk;
177 LONG ref;
178 IUnknown *punkFilterMapper2;
179 IBaseFilter ** ppFiltersInGraph;
180 LPWSTR * pFilterNames;
181 ULONG nFilters;
182 int filterCapacity;
183 LONG nameIndex;
184 IReferenceClock *refClock;
185 IBaseFilter *refClockProvider;
186 EventsQueue evqueue;
187 HANDLE hEventCompletion;
188 int CompletionStatus;
189 WndNotify notif;
190 int nRenderers;
191 int EcCompleteCount;
192 int HandleEcComplete;
193 int HandleEcRepaint;
194 int HandleEcClockChanged;
195 OAFilterState state;
196 CRITICAL_SECTION cs;
197 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
198 int nItfCacheEntries;
199 BOOL defaultclock;
200 GUID timeformatseek;
201 REFERENCE_TIME start_time;
202 REFERENCE_TIME pause_time;
203 LONGLONG stop_position;
204 LONG recursioncount;
205 IUnknown *pSite;
206 LONG version;
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)\n", This, debugstr_guid(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 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
268 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
269 } else if (IsEqualGUID(&IID_IFilterMapper3, riid)) {
270 TRACE(" returning IFilterMapper3 interface from aggregated filtermapper (%p)\n", *ppvObj);
271 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
272 } else if (IsEqualGUID(&IID_IGraphVersion, riid)) {
273 *ppvObj = &This->IGraphConfig_iface;
274 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
275 } else {
276 *ppvObj = NULL;
277 FIXME("unknown interface %s\n", debugstr_guid(riid));
278 return E_NOINTERFACE;
281 IUnknown_AddRef((IUnknown *)*ppvObj);
282 return S_OK;
285 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown *iface)
287 IFilterGraphImpl *This = impl_from_IUnknown(iface);
288 ULONG ref = InterlockedIncrement(&This->ref);
290 TRACE("(%p)->(): new ref = %d\n", This, ref);
292 return ref;
295 static ULONG WINAPI FilterGraphInner_Release(IUnknown *iface)
297 IFilterGraphImpl *This = impl_from_IUnknown(iface);
298 ULONG ref = InterlockedDecrement(&This->ref);
300 TRACE("(%p)->(): new ref = %d\n", This, ref);
302 if (ref == 0) {
303 int i;
305 This->ref = 1; /* guard against reentrancy (aggregation). */
307 IMediaControl_Stop(&This->IMediaControl_iface);
309 while (This->nFilters)
310 IFilterGraph2_RemoveFilter(&This->IFilterGraph2_iface, This->ppFiltersInGraph[0]);
312 if (This->refClock)
313 IReferenceClock_Release(This->refClock);
315 for (i = 0; i < This->nItfCacheEntries; i++)
317 if (This->ItfCacheEntries[i].iface)
318 IUnknown_Release(This->ItfCacheEntries[i].iface);
321 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)\n", This, iface, debugstr_guid(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)->()\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)->()\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 BOOL 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->IFilterGraph2_iface, 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 This->version++;
458 IBaseFilter_SetSyncSource(pFilter, This->refClock);
460 else
461 CoTaskMemFree(wszFilterName);
463 if (SUCCEEDED(hr) && duplicate_name)
464 return VFW_S_DUPLICATE_NAME;
466 return hr;
469 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
471 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
472 int i;
473 HRESULT hr = E_FAIL;
475 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
477 /* FIXME: check graph is stopped */
479 for (i = 0; i < This->nFilters; i++)
481 if (This->ppFiltersInGraph[i] == pFilter)
483 IEnumPins *penumpins = NULL;
484 FILTER_STATE state;
486 if (This->defaultclock && This->refClockProvider == pFilter)
488 IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, NULL);
489 This->defaultclock = TRUE;
492 TRACE("Removing filter %s\n", debugstr_w(This->pFilterNames[i]));
493 IBaseFilter_GetState(pFilter, 0, &state);
494 if (state == State_Running)
495 IBaseFilter_Pause(pFilter);
496 if (state != State_Stopped)
497 IBaseFilter_Stop(pFilter);
499 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
500 if (SUCCEEDED(hr)) {
501 IPin *ppin;
502 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
504 IPin *victim = NULL;
505 HRESULT h;
506 IPin_ConnectedTo(ppin, &victim);
507 if (victim)
509 h = IPin_Disconnect(victim);
510 TRACE("Disconnect other side: %08x\n", h);
511 if (h == VFW_E_NOT_STOPPED)
513 PIN_INFO pinfo;
514 IPin_QueryPinInfo(victim, &pinfo);
516 IBaseFilter_GetState(pinfo.pFilter, 0, &state);
517 if (state == State_Running)
518 IBaseFilter_Pause(pinfo.pFilter);
519 IBaseFilter_Stop(pinfo.pFilter);
520 IBaseFilter_Release(pinfo.pFilter);
521 h = IPin_Disconnect(victim);
522 TRACE("Disconnect retry: %08x\n", h);
524 IPin_Release(victim);
526 h = IPin_Disconnect(ppin);
527 TRACE("Disconnect 2: %08x\n", h);
529 IPin_Release(ppin);
531 IEnumPins_Release(penumpins);
534 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, This->pFilterNames[i]);
535 if (SUCCEEDED(hr))
537 IBaseFilter_SetSyncSource(pFilter, NULL);
538 IBaseFilter_Release(pFilter);
539 CoTaskMemFree(This->pFilterNames[i]);
540 memmove(This->ppFiltersInGraph+i, This->ppFiltersInGraph+i+1, sizeof(IBaseFilter*)*(This->nFilters - 1 - i));
541 memmove(This->pFilterNames+i, This->pFilterNames+i+1, sizeof(LPWSTR)*(This->nFilters - 1 - i));
542 This->nFilters--;
543 This->version++;
544 /* Invalidate interfaces in the cache */
545 for (i = 0; i < This->nItfCacheEntries; i++)
546 if (pFilter == This->ItfCacheEntries[i].filter)
548 IUnknown_Release(This->ItfCacheEntries[i].iface);
549 This->ItfCacheEntries[i].iface = NULL;
550 This->ItfCacheEntries[i].filter = NULL;
552 return S_OK;
554 break;
558 return hr; /* FIXME: check this error code */
561 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface, IEnumFilters **ppEnum)
563 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
565 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
567 return IEnumFiltersImpl_Construct(&This->IGraphVersion_iface, &This->ppFiltersInGraph, &This->nFilters, ppEnum);
570 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface, LPCWSTR pName,
571 IBaseFilter **ppFilter)
573 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
574 int i;
576 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_w(pName), pName, ppFilter);
578 if (!ppFilter)
579 return E_POINTER;
581 for (i = 0; i < This->nFilters; i++)
583 if (!strcmpW(pName, This->pFilterNames[i]))
585 *ppFilter = This->ppFiltersInGraph[i];
586 IBaseFilter_AddRef(*ppFilter);
587 return S_OK;
591 *ppFilter = NULL;
592 return VFW_E_NOT_FOUND;
595 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
596 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
598 static HRESULT CheckCircularConnection(IFilterGraphImpl *This, IPin *out, IPin *in)
600 #if 1
601 HRESULT hr;
602 PIN_INFO info_out, info_in;
604 hr = IPin_QueryPinInfo(out, &info_out);
605 if (FAILED(hr))
606 return hr;
607 if (info_out.dir != PINDIR_OUTPUT)
609 IBaseFilter_Release(info_out.pFilter);
610 return VFW_E_CANNOT_CONNECT;
613 hr = IPin_QueryPinInfo(in, &info_in);
614 if (SUCCEEDED(hr))
615 IBaseFilter_Release(info_in.pFilter);
616 if (FAILED(hr))
617 goto out;
618 if (info_in.dir != PINDIR_INPUT)
620 hr = VFW_E_CANNOT_CONNECT;
621 goto out;
624 if (info_out.pFilter == info_in.pFilter)
625 hr = VFW_E_CIRCULAR_GRAPH;
626 else
628 IEnumPins *enumpins;
629 IPin *test;
631 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
632 if (FAILED(hr))
633 goto out;
635 IEnumPins_Reset(enumpins);
636 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
638 PIN_DIRECTION dir = PINDIR_OUTPUT;
639 IPin_QueryDirection(test, &dir);
640 if (dir == PINDIR_INPUT)
642 IPin *victim = NULL;
643 IPin_ConnectedTo(test, &victim);
644 if (victim)
646 hr = CheckCircularConnection(This, victim, in);
647 IPin_Release(victim);
648 if (FAILED(hr))
650 IPin_Release(test);
651 break;
655 IPin_Release(test);
657 IEnumPins_Release(enumpins);
660 out:
661 IBaseFilter_Release(info_out.pFilter);
662 if (FAILED(hr))
663 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
664 return hr;
665 #else
666 /* Debugging filtergraphs not enabled */
667 return S_OK;
668 #endif
672 /* NOTE: despite the implication, it doesn't matter which
673 * way round you put in the input and output pins */
674 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppinIn, IPin *ppinOut,
675 const AM_MEDIA_TYPE *pmt)
677 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
678 PIN_DIRECTION dir;
679 HRESULT hr;
681 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
683 /* FIXME: check pins are in graph */
685 if (TRACE_ON(quartz))
687 PIN_INFO PinInfo;
689 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
690 if (FAILED(hr))
691 return hr;
693 TRACE("Filter owning ppinIn(%p) => %p\n", ppinIn, PinInfo.pFilter);
694 IBaseFilter_Release(PinInfo.pFilter);
696 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
697 if (FAILED(hr))
698 return hr;
700 TRACE("Filter owning ppinOut(%p) => %p\n", ppinOut, PinInfo.pFilter);
701 IBaseFilter_Release(PinInfo.pFilter);
704 hr = IPin_QueryDirection(ppinIn, &dir);
705 if (SUCCEEDED(hr))
707 if (dir == PINDIR_INPUT)
709 hr = CheckCircularConnection(This, ppinOut, ppinIn);
710 if (SUCCEEDED(hr))
711 hr = IPin_Connect(ppinOut, ppinIn, pmt);
713 else
715 hr = CheckCircularConnection(This, ppinIn, ppinOut);
716 if (SUCCEEDED(hr))
717 hr = IPin_Connect(ppinIn, ppinOut, pmt);
721 return hr;
724 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface, IPin *ppin)
726 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
727 IPin *pConnectedTo = NULL;
728 HRESULT hr;
729 PIN_DIRECTION pindir;
731 IPin_QueryDirection(ppin, &pindir);
732 hr = IPin_ConnectedTo(ppin, &pConnectedTo);
734 TRACE("(%p/%p)->(%p) -- %p\n", This, iface, ppin, pConnectedTo);
736 if (FAILED(hr)) {
737 TRACE("Querying connected to failed: %x\n", hr);
738 return hr;
740 IPin_Disconnect(ppin);
741 IPin_Disconnect(pConnectedTo);
742 if (pindir == PINDIR_INPUT)
743 hr = IPin_Connect(pConnectedTo, ppin, NULL);
744 else
745 hr = IPin_Connect(ppin, pConnectedTo, NULL);
746 IPin_Release(pConnectedTo);
747 if (FAILED(hr))
748 WARN("Reconnecting pins failed, pins are not connected now..\n");
749 TRACE("-> %08x\n", hr);
750 return hr;
753 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
755 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
757 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
759 if (!ppin)
760 return E_POINTER;
762 return IPin_Disconnect(ppin);
765 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
767 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
768 IReferenceClock *pClock = NULL;
769 HRESULT hr = S_OK;
770 int i;
772 TRACE("(%p/%p)->() live sources not handled properly!\n", This, iface);
774 EnterCriticalSection(&This->cs);
776 for (i = 0; i < This->nFilters; ++i)
778 DWORD miscflags;
779 IAMFilterMiscFlags *flags = NULL;
780 IBaseFilter_QueryInterface(This->ppFiltersInGraph[i], &IID_IAMFilterMiscFlags, (void**)&flags);
781 if (!flags)
782 continue;
783 miscflags = IAMFilterMiscFlags_GetMiscFlags(flags);
784 IAMFilterMiscFlags_Release(flags);
785 if (miscflags == AM_FILTER_MISC_FLAGS_IS_RENDERER)
786 IBaseFilter_QueryInterface(This->ppFiltersInGraph[i], &IID_IReferenceClock, (void**)&pClock);
787 if (pClock)
788 break;
791 if (!pClock)
793 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
794 This->refClockProvider = NULL;
796 else
797 This->refClockProvider = This->ppFiltersInGraph[i];
799 if (SUCCEEDED(hr))
801 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
802 This->defaultclock = TRUE;
803 IReferenceClock_Release(pClock);
805 LeaveCriticalSection(&This->cs);
807 return hr;
810 static HRESULT GetFilterInfo(IMoniker* pMoniker, VARIANT* pvar)
812 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
813 IPropertyBag * pPropBagCat = NULL;
814 HRESULT hr;
816 VariantInit(pvar);
818 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
820 if (SUCCEEDED(hr))
821 hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL);
823 if (SUCCEEDED(hr))
824 TRACE("Moniker = %s\n", debugstr_w(V_BSTR(pvar)));
826 if (pPropBagCat)
827 IPropertyBag_Release(pPropBagCat);
829 return hr;
832 static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPin*** pppins, ULONG* pnb)
834 HRESULT hr;
835 ULONG nb = 0;
837 TRACE("(%p, %p, %p, %p)\n", pfilter, pinputpin, pppins, pnb);
838 hr = IPin_QueryInternalConnections(pinputpin, NULL, &nb);
839 if (hr == S_OK) {
840 /* Rendered input */
841 } else if (hr == S_FALSE) {
842 *pppins = CoTaskMemAlloc(sizeof(IPin*)*nb);
843 hr = IPin_QueryInternalConnections(pinputpin, *pppins, &nb);
844 if (hr != S_OK) {
845 WARN("Error (%x)\n", hr);
847 } else if (hr == E_NOTIMPL) {
848 /* Input connected to all outputs */
849 IEnumPins* penumpins;
850 IPin* ppin;
851 int i = 0;
852 TRACE("E_NOTIMPL\n");
853 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
854 if (FAILED(hr)) {
855 WARN("filter Enumpins failed (%x)\n", hr);
856 return hr;
858 i = 0;
859 /* Count output pins */
860 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
861 PIN_DIRECTION pindir;
862 IPin_QueryDirection(ppin, &pindir);
863 if (pindir == PINDIR_OUTPUT)
864 i++;
865 IPin_Release(ppin);
867 *pppins = CoTaskMemAlloc(sizeof(IPin*)*i);
868 /* Retrieve output pins */
869 IEnumPins_Reset(penumpins);
870 i = 0;
871 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
872 PIN_DIRECTION pindir;
873 IPin_QueryDirection(ppin, &pindir);
874 if (pindir == PINDIR_OUTPUT)
875 (*pppins)[i++] = ppin;
876 else
877 IPin_Release(ppin);
879 IEnumPins_Release(penumpins);
880 nb = i;
881 if (FAILED(hr)) {
882 WARN("Next failed (%x)\n", hr);
883 return hr;
885 } else if (FAILED(hr)) {
886 WARN("Cannot get internal connection (%x)\n", hr);
887 return hr;
890 *pnb = nb;
891 return S_OK;
894 /*** IGraphBuilder methods ***/
895 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IPin *ppinIn)
897 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
898 HRESULT hr;
899 AM_MEDIA_TYPE* mt = NULL;
900 IEnumMediaTypes* penummt = NULL;
901 ULONG nbmt;
902 IEnumPins* penumpins;
903 IEnumMoniker* pEnumMoniker;
904 GUID tab[2];
905 ULONG nb = 0;
906 IMoniker* pMoniker;
907 ULONG pin;
908 PIN_INFO PinInfo;
909 CLSID FilterCLSID;
910 PIN_DIRECTION dir;
911 unsigned int i = 0;
912 IFilterMapper2 *pFilterMapper2 = NULL;
914 TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
916 if(!ppinOut || !ppinIn)
917 return E_POINTER;
919 if (TRACE_ON(quartz))
921 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
922 if (FAILED(hr))
923 return hr;
925 TRACE("Filter owning ppinIn(%p) => %p\n", ppinIn, PinInfo.pFilter);
926 IBaseFilter_Release(PinInfo.pFilter);
928 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
929 if (FAILED(hr))
930 return hr;
932 TRACE("Filter owning ppinOut(%p) => %p\n", ppinOut, PinInfo.pFilter);
933 IBaseFilter_Release(PinInfo.pFilter);
936 EnterCriticalSection(&This->cs);
937 ++This->recursioncount;
938 if (This->recursioncount >= 5)
940 WARN("Recursion count has reached %d\n", This->recursioncount);
941 hr = VFW_E_CANNOT_CONNECT;
942 goto out;
945 hr = IPin_QueryDirection(ppinOut, &dir);
946 if (FAILED(hr))
947 goto out;
949 if (dir == PINDIR_INPUT)
951 IPin *temp;
953 TRACE("Directions seem backwards, swapping pins\n");
955 temp = ppinIn;
956 ppinIn = ppinOut;
957 ppinOut = temp;
960 hr = CheckCircularConnection(This, ppinOut, ppinIn);
961 if (FAILED(hr))
962 goto out;
964 /* Try direct connection first */
965 hr = IPin_Connect(ppinOut, ppinIn, NULL);
966 if (SUCCEEDED(hr))
967 goto out;
969 TRACE("Direct connection failed, trying to render using extra filters\n");
971 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
972 if (FAILED(hr))
973 goto out;
975 hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
976 IBaseFilter_Release(PinInfo.pFilter);
977 if (FAILED(hr))
978 goto out;
980 /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream
981 * filter to the minor mediatype of input pin of the renderer */
982 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
983 if (FAILED(hr))
985 WARN("EnumMediaTypes (%x)\n", hr);
986 goto out;
989 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
990 if (FAILED(hr)) {
991 WARN("IEnumMediaTypes_Next (%x)\n", hr);
992 goto out;
995 if (!nbmt)
997 WARN("No media type found!\n");
998 hr = VFW_E_INVALIDMEDIATYPE;
999 goto out;
1001 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1002 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1004 hr = IUnknown_QueryInterface(This->punkFilterMapper2, &IID_IFilterMapper2, (void**)&pFilterMapper2);
1005 if (FAILED(hr)) {
1006 WARN("Unable to get IFilterMapper2 (%x)\n", hr);
1007 goto out;
1010 /* Try to find a suitable filter that can connect to the pin to render */
1011 tab[0] = mt->majortype;
1012 tab[1] = mt->subtype;
1013 hr = IFilterMapper2_EnumMatchingFilters(pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1014 if (FAILED(hr)) {
1015 WARN("Unable to enum filters (%x)\n", hr);
1016 goto out;
1019 hr = VFW_E_CANNOT_RENDER;
1020 while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1022 VARIANT var;
1023 GUID clsid;
1024 IPin** ppins = NULL;
1025 IPin* ppinfilter = NULL;
1026 IBaseFilter* pfilter = NULL;
1027 IAMGraphBuilderCallback *callback = NULL;
1029 hr = GetFilterInfo(pMoniker, &var);
1030 if (FAILED(hr)) {
1031 WARN("Unable to retrieve filter info (%x)\n", hr);
1032 goto error;
1035 hr = IMoniker_BindToObject(pMoniker, NULL, NULL, &IID_IBaseFilter, (LPVOID*)&pfilter);
1036 IMoniker_Release(pMoniker);
1037 if (FAILED(hr)) {
1038 WARN("Unable to create filter (%x), trying next one\n", hr);
1039 goto error;
1042 hr = IBaseFilter_GetClassID(pfilter, &clsid);
1043 if (FAILED(hr))
1045 IBaseFilter_Release(pfilter);
1046 goto error;
1049 if (IsEqualGUID(&clsid, &FilterCLSID)) {
1050 /* Skip filter (same as the one the output pin belongs to) */
1051 IBaseFilter_Release(pfilter);
1052 goto error;
1055 if (This->pSite)
1057 IUnknown_QueryInterface(This->pSite, &IID_IAMGraphBuilderCallback, (LPVOID*)&callback);
1058 if (callback)
1060 HRESULT rc;
1061 rc = IAMGraphBuilderCallback_SelectedFilter(callback, pMoniker);
1062 if (FAILED(rc))
1064 TRACE("Filter rejected by IAMGraphBuilderCallback_SelectedFilter\n");
1065 IAMGraphBuilderCallback_Release(callback);
1066 goto error;
1071 if (callback)
1073 HRESULT rc;
1074 rc = IAMGraphBuilderCallback_CreatedFilter(callback, pfilter);
1075 IAMGraphBuilderCallback_Release(callback);
1076 if (FAILED(rc))
1078 IBaseFilter_Release(pfilter);
1079 pfilter = NULL;
1080 TRACE("Filter rejected by IAMGraphBuilderCallback_CreatedFilter\n");
1081 goto error;
1085 hr = IFilterGraph2_AddFilter(iface, pfilter, V_BSTR(&var));
1086 if (FAILED(hr)) {
1087 WARN("Unable to add filter (%x)\n", hr);
1088 IBaseFilter_Release(pfilter);
1089 pfilter = NULL;
1090 goto error;
1093 VariantClear(&var);
1095 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1096 if (FAILED(hr)) {
1097 WARN("Enumpins (%x)\n", hr);
1098 goto error;
1101 hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin);
1102 IEnumPins_Release(penumpins);
1104 if (FAILED(hr)) {
1105 WARN("Obtaining next pin: (%x)\n", hr);
1106 goto error;
1108 if (pin == 0) {
1109 WARN("Cannot use this filter: no pins\n");
1110 goto error;
1113 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1114 if (FAILED(hr)) {
1115 TRACE("Cannot connect to filter (%x), trying next one\n", hr);
1116 goto error;
1118 TRACE("Successfully connected to filter, follow chain...\n");
1120 /* Render all output pins of the filter by calling IFilterGraph2_Connect on each of them */
1121 hr = GetInternalConnections(pfilter, ppinfilter, &ppins, &nb);
1123 if (SUCCEEDED(hr)) {
1124 if (nb == 0) {
1125 IPin_Disconnect(ppinfilter);
1126 IPin_Disconnect(ppinOut);
1127 goto error;
1129 TRACE("pins to consider: %d\n", nb);
1130 for(i = 0; i < nb; i++)
1132 LPWSTR pinname = NULL;
1134 TRACE("Processing pin %u\n", i);
1136 hr = IPin_QueryId(ppins[i], &pinname);
1137 if (SUCCEEDED(hr))
1139 if (pinname[0] == '~')
1141 TRACE("Pinname=%s, skipping\n", debugstr_w(pinname));
1142 hr = E_FAIL;
1144 else
1145 hr = IFilterGraph2_Connect(iface, ppins[i], ppinIn);
1146 CoTaskMemFree(pinname);
1149 if (FAILED(hr)) {
1150 TRACE("Cannot connect pin %p (%x)\n", ppinfilter, hr);
1152 IPin_Release(ppins[i]);
1153 if (SUCCEEDED(hr)) break;
1155 while (++i < nb) IPin_Release(ppins[i]);
1156 CoTaskMemFree(ppins);
1157 IPin_Release(ppinfilter);
1158 IBaseFilter_Release(pfilter);
1159 if (FAILED(hr))
1161 IPin_Disconnect(ppinfilter);
1162 IPin_Disconnect(ppinOut);
1163 IFilterGraph2_RemoveFilter(iface, pfilter);
1164 continue;
1166 break;
1169 error:
1170 VariantClear(&var);
1171 if (ppinfilter) IPin_Release(ppinfilter);
1172 if (pfilter) {
1173 IFilterGraph2_RemoveFilter(iface, pfilter);
1174 IBaseFilter_Release(pfilter);
1176 while (++i < nb) IPin_Release(ppins[i]);
1177 CoTaskMemFree(ppins);
1180 IEnumMoniker_Release(pEnumMoniker);
1182 out:
1183 if (pFilterMapper2)
1184 IFilterMapper2_Release(pFilterMapper2);
1185 if (penummt)
1186 IEnumMediaTypes_Release(penummt);
1187 if (mt)
1188 DeleteMediaType(mt);
1189 --This->recursioncount;
1190 LeaveCriticalSection(&This->cs);
1191 TRACE("--> %08x\n", hr);
1192 return SUCCEEDED(hr) ? S_OK : hr;
1195 static HRESULT FilterGraph2_RenderRecurse(IFilterGraphImpl *This, IPin *ppinOut)
1197 /* This pin has been connected now, try to call render on all pins that aren't connected */
1198 IPin *to = NULL;
1199 PIN_INFO info;
1200 IEnumPins *enumpins = NULL;
1201 BOOL renderany = FALSE;
1202 BOOL renderall = TRUE;
1204 IPin_QueryPinInfo(ppinOut, &info);
1206 IBaseFilter_EnumPins(info.pFilter, &enumpins);
1207 /* Don't need to hold a reference, IEnumPins does */
1208 IBaseFilter_Release(info.pFilter);
1210 IEnumPins_Reset(enumpins);
1211 while (IEnumPins_Next(enumpins, 1, &to, NULL) == S_OK)
1213 PIN_DIRECTION dir = PINDIR_INPUT;
1215 IPin_QueryDirection(to, &dir);
1217 if (dir == PINDIR_OUTPUT)
1219 IPin *out = NULL;
1221 IPin_ConnectedTo(to, &out);
1222 if (!out)
1224 HRESULT hr;
1225 hr = IFilterGraph2_Render(&This->IFilterGraph2_iface, to);
1226 if (SUCCEEDED(hr))
1227 renderany = TRUE;
1228 else
1229 renderall = FALSE;
1231 else
1232 IPin_Release(out);
1235 IPin_Release(to);
1238 IEnumPins_Release(enumpins);
1240 if (renderall)
1241 return S_OK;
1243 if (renderany)
1244 return VFW_S_PARTIAL_RENDER;
1246 return VFW_E_CANNOT_RENDER;
1249 /* Ogg hates me if I create a direct rendering method
1251 * It can only connect to a pin properly once, so use a recursive method that does
1253 * +----+ --- (PIN 1) (Render is called on this pin)
1254 * | |
1255 * +----+ --- (PIN 2)
1257 * Enumerate possible renderers that EXACTLY match the requested type
1259 * If none is available, try to add intermediate filters that can connect to the input pin
1260 * then call Render on that intermediate pin's output pins
1261 * if it succeeds: Render returns success, if it doesn't, the intermediate filter is removed,
1262 * and another filter that can connect to the input pin is tried
1263 * if we run out of filters that can, give up and return VFW_E_CANNOT_RENDER
1264 * It's recursive, but fun!
1267 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *ppinOut)
1269 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1270 IEnumMediaTypes* penummt;
1271 AM_MEDIA_TYPE* mt;
1272 ULONG nbmt;
1273 HRESULT hr;
1275 IEnumMoniker* pEnumMoniker;
1276 GUID tab[4];
1277 ULONG nb;
1278 IMoniker* pMoniker;
1279 INT x;
1280 IFilterMapper2 *pFilterMapper2 = NULL;
1282 TRACE("(%p/%p)->(%p)\n", This, iface, ppinOut);
1284 if (TRACE_ON(quartz))
1286 PIN_INFO PinInfo;
1288 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
1289 if (FAILED(hr))
1290 return hr;
1292 TRACE("Filter owning pin => %p\n", PinInfo.pFilter);
1293 IBaseFilter_Release(PinInfo.pFilter);
1296 /* Try to find out if there is a renderer for the specified subtype already, and use that
1298 EnterCriticalSection(&This->cs);
1299 for (x = 0; x < This->nFilters; ++x)
1301 IEnumPins *enumpins = NULL;
1302 IPin *pin = NULL;
1304 hr = IBaseFilter_EnumPins(This->ppFiltersInGraph[x], &enumpins);
1306 if (FAILED(hr) || !enumpins)
1307 continue;
1309 IEnumPins_Reset(enumpins);
1310 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
1312 IPin *to = NULL;
1313 PIN_DIRECTION dir = PINDIR_OUTPUT;
1315 IPin_QueryDirection(pin, &dir);
1316 if (dir != PINDIR_INPUT)
1318 IPin_Release(pin);
1319 continue;
1321 IPin_ConnectedTo(pin, &to);
1323 if (to == NULL)
1325 hr = FilterGraph2_ConnectDirect(iface, ppinOut, pin, NULL);
1326 if (SUCCEEDED(hr))
1328 TRACE("Connected successfully %p/%p, %08x look if we should render more!\n", ppinOut, pin, hr);
1329 IPin_Release(pin);
1331 hr = FilterGraph2_RenderRecurse(This, pin);
1332 if (FAILED(hr))
1334 IPin_Disconnect(ppinOut);
1335 IPin_Disconnect(pin);
1336 continue;
1338 IEnumPins_Release(enumpins);
1339 LeaveCriticalSection(&This->cs);
1340 return hr;
1342 WARN("Could not connect!\n");
1344 else
1345 IPin_Release(to);
1347 IPin_Release(pin);
1349 IEnumPins_Release(enumpins);
1352 LeaveCriticalSection(&This->cs);
1354 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
1355 if (FAILED(hr)) {
1356 WARN("EnumMediaTypes (%x)\n", hr);
1357 return hr;
1360 IEnumMediaTypes_Reset(penummt);
1362 /* Looks like no existing renderer of the kind exists
1363 * Try adding new ones
1365 tab[0] = tab[1] = GUID_NULL;
1366 while (SUCCEEDED(hr))
1368 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
1369 if (FAILED(hr)) {
1370 WARN("IEnumMediaTypes_Next (%x)\n", hr);
1371 break;
1373 if (!nbmt)
1375 hr = VFW_E_CANNOT_RENDER;
1376 break;
1378 else
1380 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1381 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1383 /* Only enumerate once, this doesn't account for all previous ones, but this should be enough nonetheless */
1384 if (IsEqualIID(&tab[0], &mt->majortype) && IsEqualIID(&tab[1], &mt->subtype))
1386 DeleteMediaType(mt);
1387 continue;
1390 if (pFilterMapper2 == NULL)
1392 hr = IUnknown_QueryInterface(This->punkFilterMapper2, &IID_IFilterMapper2, (void**)&pFilterMapper2);
1393 if (FAILED(hr))
1395 WARN("Unable to query IFilterMapper2 (%x)\n", hr);
1396 break;
1400 /* Try to find a suitable renderer with the same media type */
1401 tab[0] = mt->majortype;
1402 tab[1] = mt->subtype;
1403 hr = IFilterMapper2_EnumMatchingFilters(pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1404 if (FAILED(hr))
1406 WARN("Unable to enum filters (%x)\n", hr);
1407 break;
1410 hr = E_FAIL;
1412 while (IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1414 VARIANT var;
1415 IPin* ppinfilter;
1416 IBaseFilter* pfilter = NULL;
1417 IEnumPins* penumpins = NULL;
1418 ULONG pin;
1420 hr = GetFilterInfo(pMoniker, &var);
1421 if (FAILED(hr)) {
1422 WARN("Unable to retrieve filter info (%x)\n", hr);
1423 goto error;
1426 hr = IMoniker_BindToObject(pMoniker, NULL, NULL, &IID_IBaseFilter, (LPVOID*)&pfilter);
1427 IMoniker_Release(pMoniker);
1428 if (FAILED(hr))
1430 WARN("Unable to create filter (%x), trying next one\n", hr);
1431 goto error;
1434 hr = IFilterGraph2_AddFilter(iface, pfilter, V_BSTR(&var));
1435 if (FAILED(hr)) {
1436 WARN("Unable to add filter (%x)\n", hr);
1437 IBaseFilter_Release(pfilter);
1438 pfilter = NULL;
1439 goto error;
1442 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1443 if (FAILED(hr)) {
1444 WARN("Splitter Enumpins (%x)\n", hr);
1445 goto error;
1448 while ((hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin)) == S_OK)
1450 PIN_DIRECTION dir;
1452 if (pin == 0) {
1453 WARN("No Pin\n");
1454 hr = E_FAIL;
1455 goto error;
1458 hr = IPin_QueryDirection(ppinfilter, &dir);
1459 if (FAILED(hr)) {
1460 IPin_Release(ppinfilter);
1461 WARN("QueryDirection failed (%x)\n", hr);
1462 goto error;
1464 if (dir != PINDIR_INPUT) {
1465 IPin_Release(ppinfilter);
1466 continue; /* Wrong direction */
1469 /* Connect the pin to the "Renderer" */
1470 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1471 IPin_Release(ppinfilter);
1473 if (FAILED(hr)) {
1474 WARN("Unable to connect %s to renderer (%x)\n", debugstr_w(V_BSTR(&var)), hr);
1475 goto error;
1477 TRACE("Connected, recursing %s\n", debugstr_w(V_BSTR(&var)));
1479 VariantClear(&var);
1481 hr = FilterGraph2_RenderRecurse(This, ppinfilter);
1482 if (FAILED(hr)) {
1483 WARN("Unable to connect recursively (%x)\n", hr);
1484 goto error;
1486 IBaseFilter_Release(pfilter);
1487 break;
1489 if (SUCCEEDED(hr)) {
1490 IEnumPins_Release(penumpins);
1491 break; /* out of IEnumMoniker_Next loop */
1494 /* IEnumPins_Next failed, all other failure case caught by goto error */
1495 WARN("IEnumPins_Next (%x)\n", hr);
1496 /* goto error */
1498 error:
1499 VariantClear(&var);
1500 if (penumpins)
1501 IEnumPins_Release(penumpins);
1502 if (pfilter) {
1503 IFilterGraph2_RemoveFilter(iface, pfilter);
1504 IBaseFilter_Release(pfilter);
1506 if (SUCCEEDED(hr)) DebugBreak();
1509 IEnumMoniker_Release(pEnumMoniker);
1510 if (nbmt)
1511 DeleteMediaType(mt);
1512 if (SUCCEEDED(hr))
1513 break;
1514 hr = S_OK;
1517 if (pFilterMapper2)
1518 IFilterMapper2_Release(pFilterMapper2);
1520 IEnumMediaTypes_Release(penummt);
1521 return hr;
1524 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface, LPCWSTR lpcwstrFile,
1525 LPCWSTR lpcwstrPlayList)
1527 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1528 static const WCHAR string[] = {'R','e','a','d','e','r',0};
1529 IBaseFilter* preader = NULL;
1530 IPin* ppinreader = NULL;
1531 IEnumPins* penumpins = NULL;
1532 HRESULT hr;
1533 BOOL partial = FALSE;
1534 BOOL any = FALSE;
1536 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1538 if (lpcwstrPlayList != NULL)
1539 return E_INVALIDARG;
1541 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, string, &preader);
1542 if (FAILED(hr))
1543 return hr;
1545 hr = IBaseFilter_EnumPins(preader, &penumpins);
1546 if (SUCCEEDED(hr))
1548 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1550 PIN_DIRECTION dir;
1552 IPin_QueryDirection(ppinreader, &dir);
1553 if (dir == PINDIR_OUTPUT)
1555 INT i;
1557 hr = IFilterGraph2_Render(iface, ppinreader);
1558 TRACE("Render %08x\n", hr);
1560 for (i = 0; i < This->nFilters; ++i)
1561 TRACE("Filters in chain: %s\n", debugstr_w(This->pFilterNames[i]));
1563 if (SUCCEEDED(hr))
1564 any = TRUE;
1565 if (hr != S_OK)
1566 partial = TRUE;
1568 IPin_Release(ppinreader);
1570 IEnumPins_Release(penumpins);
1572 if (!any)
1573 hr = VFW_E_CANNOT_RENDER;
1574 else if (partial)
1575 hr = VFW_S_PARTIAL_RENDER;
1576 else
1577 hr = S_OK;
1579 IBaseFilter_Release(preader);
1581 TRACE("--> %08x\n", hr);
1582 return hr;
1585 static HRESULT CreateFilterInstanceAndLoadFile(GUID* clsid, LPCOLESTR pszFileName, IBaseFilter **filter)
1587 IFileSourceFilter *source = NULL;
1588 HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1589 TRACE("CLSID: %s\n", debugstr_guid(clsid));
1590 if (FAILED(hr))
1591 return hr;
1593 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID*)&source);
1594 if (FAILED(hr))
1596 IBaseFilter_Release(*filter);
1597 return hr;
1600 /* Load the file in the file source filter */
1601 hr = IFileSourceFilter_Load(source, pszFileName, NULL);
1602 IFileSourceFilter_Release(source);
1603 if (FAILED(hr)) {
1604 WARN("Load (%x)\n", hr);
1605 IBaseFilter_Release(*filter);
1606 return hr;
1609 return hr;
1612 /* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
1613 static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
1615 HRESULT hr;
1616 GUID clsid;
1617 IAsyncReader * pReader = NULL;
1618 IFileSourceFilter* pSource = NULL;
1619 IPin * pOutputPin = NULL;
1620 static const WCHAR wszOutputPinName[] = { 'O','u','t','p','u','t',0 };
1622 /* Try to find a match without reading the file first */
1623 hr = GetClassMediaFile(NULL, pszFileName, NULL, NULL, &clsid);
1625 if (hr == S_OK)
1626 return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
1628 /* Now create a AyncReader instance, to check for signature bytes in the file */
1629 hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1630 if (FAILED(hr))
1631 return hr;
1633 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID *)&pSource);
1634 if (FAILED(hr))
1636 IBaseFilter_Release(*filter);
1637 return hr;
1640 hr = IFileSourceFilter_Load(pSource, pszFileName, NULL);
1641 IFileSourceFilter_Release(pSource);
1642 if (FAILED(hr))
1644 IBaseFilter_Release(*filter);
1645 return hr;
1648 hr = IBaseFilter_FindPin(*filter, wszOutputPinName, &pOutputPin);
1649 if (FAILED(hr))
1651 IBaseFilter_Release(*filter);
1652 return hr;
1655 hr = IPin_QueryInterface(pOutputPin, &IID_IAsyncReader, (LPVOID *)&pReader);
1656 IPin_Release(pOutputPin);
1657 if (FAILED(hr))
1659 IBaseFilter_Release(*filter);
1660 return hr;
1663 /* Try again find a match */
1664 hr = GetClassMediaFile(pReader, pszFileName, NULL, NULL, &clsid);
1665 IAsyncReader_Release(pReader);
1667 if (hr == S_OK)
1669 /* Release the AsyncReader filter and create the matching one */
1670 IBaseFilter_Release(*filter);
1671 return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
1674 /* Return the AsyncReader filter */
1675 return S_OK;
1678 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface, LPCWSTR lpcwstrFileName,
1679 LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1681 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1682 HRESULT hr;
1683 IBaseFilter* preader;
1684 IFileSourceFilter* pfile = NULL;
1685 AM_MEDIA_TYPE mt;
1686 WCHAR* filename;
1688 TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1690 /* Try from file name first, then fall back to default asynchronous reader */
1691 hr = GetFileSourceFilter(lpcwstrFileName, &preader);
1692 if (FAILED(hr)) {
1693 WARN("Unable to create file source filter (%x)\n", hr);
1694 return hr;
1697 hr = IFilterGraph2_AddFilter(iface, preader, lpcwstrFilterName);
1698 if (FAILED(hr)) {
1699 WARN("Unable add filter (%x)\n", hr);
1700 IBaseFilter_Release(preader);
1701 return hr;
1704 hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1705 if (FAILED(hr)) {
1706 WARN("Unable to get IFileSourceInterface (%x)\n", hr);
1707 goto error;
1710 /* The file has been already loaded */
1711 hr = IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1712 if (FAILED(hr)) {
1713 WARN("GetCurFile (%x)\n", hr);
1714 goto error;
1717 TRACE("File %s\n", debugstr_w(filename));
1718 TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
1719 TRACE("SubType %s\n", debugstr_guid(&mt.subtype));
1721 if (ppFilter)
1722 *ppFilter = preader;
1723 IFileSourceFilter_Release(pfile);
1725 return S_OK;
1727 error:
1728 if (pfile)
1729 IFileSourceFilter_Release(pfile);
1730 IFilterGraph2_RemoveFilter(iface, preader);
1731 IBaseFilter_Release(preader);
1733 return hr;
1736 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR hFile)
1738 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1740 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1742 return S_OK;
1745 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1747 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1749 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1751 return S_OK;
1754 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1756 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1758 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1760 return S_OK;
1763 /*** IFilterGraph2 methods ***/
1764 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1765 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1767 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1768 HRESULT hr;
1769 IBaseFilter* pfilter;
1771 TRACE("(%p/%p)->(%p %p %s %p)\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1773 hr = IMoniker_BindToObject(pMoniker, pCtx, NULL, &IID_IBaseFilter, (void**)&pfilter);
1774 if(FAILED(hr)) {
1775 WARN("Unable to bind moniker to filter object (%x)\n", hr);
1776 return hr;
1779 hr = IFilterGraph2_AddFilter(iface, pfilter, lpcwstrFilterName);
1780 if (FAILED(hr)) {
1781 WARN("Unable to add filter (%x)\n", hr);
1782 IBaseFilter_Release(pfilter);
1783 return hr;
1786 if(ppFilter)
1787 *ppFilter = pfilter;
1788 else IBaseFilter_Release(pfilter);
1790 return S_OK;
1793 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *ppin,
1794 const AM_MEDIA_TYPE *pmt)
1796 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1798 TRACE("(%p/%p)->(%p %p): stub !!!\n", This, iface, ppin, pmt);
1800 return S_OK;
1803 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *pPinOut, DWORD dwFlags,
1804 DWORD *pvContext)
1806 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1808 TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This, iface, pPinOut, dwFlags, pvContext);
1810 return S_OK;
1814 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1816 FilterGraph2_QueryInterface,
1817 FilterGraph2_AddRef,
1818 FilterGraph2_Release,
1819 FilterGraph2_AddFilter,
1820 FilterGraph2_RemoveFilter,
1821 FilterGraph2_EnumFilters,
1822 FilterGraph2_FindFilterByName,
1823 FilterGraph2_ConnectDirect,
1824 FilterGraph2_Reconnect,
1825 FilterGraph2_Disconnect,
1826 FilterGraph2_SetDefaultSyncSource,
1827 FilterGraph2_Connect,
1828 FilterGraph2_Render,
1829 FilterGraph2_RenderFile,
1830 FilterGraph2_AddSourceFilter,
1831 FilterGraph2_SetLogFile,
1832 FilterGraph2_Abort,
1833 FilterGraph2_ShouldOperationContinue,
1834 FilterGraph2_AddSourceFilterForMoniker,
1835 FilterGraph2_ReconnectEx,
1836 FilterGraph2_RenderEx
1839 static inline IFilterGraphImpl *impl_from_IMediaControl(IMediaControl *iface)
1841 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaControl_iface);
1844 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID riid, void **ppvObj)
1846 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1848 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
1850 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
1853 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1855 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1857 TRACE("(%p/%p)->()\n", This, iface);
1859 return IUnknown_AddRef(This->outer_unk);
1862 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1864 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1866 TRACE("(%p/%p)->()\n", This, iface);
1868 return IUnknown_Release(This->outer_unk);
1872 /*** IDispatch methods ***/
1873 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *pctinfo)
1875 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1877 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1879 return S_OK;
1882 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT iTInfo, LCID lcid,
1883 ITypeInfo **ppTInfo)
1885 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1887 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1889 return S_OK;
1892 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID riid,
1893 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1895 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1897 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
1898 cNames, lcid, rgDispId);
1900 return S_OK;
1903 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID dispIdMember, REFIID riid,
1904 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
1905 UINT *puArgErr)
1907 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1909 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
1910 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
1912 return S_OK;
1915 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *, DWORD_PTR data);
1917 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter, DWORD_PTR data)
1919 HRESULT hr;
1920 IPin* pInputPin;
1921 IPin** ppPins;
1922 ULONG nb;
1923 ULONG i;
1924 PIN_INFO PinInfo;
1926 TRACE("%p %p\n", pGraph, pOutputPin);
1927 PinInfo.pFilter = NULL;
1929 hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1931 if (SUCCEEDED(hr))
1933 hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1934 if (SUCCEEDED(hr))
1935 hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1936 IPin_Release(pInputPin);
1939 if (SUCCEEDED(hr))
1941 if (nb == 0)
1943 TRACE("Reached a renderer\n");
1944 /* Count renderers for end of stream notification */
1945 pGraph->nRenderers++;
1947 else
1949 for(i = 0; i < nb; i++)
1951 /* Explore the graph downstream from this pin
1952 * FIXME: We should prevent exploring from a pin more than once. This can happens when
1953 * several input pins are connected to the same output (a MUX for instance). */
1954 ExploreGraph(pGraph, ppPins[i], FoundFilter, data);
1955 IPin_Release(ppPins[i]);
1958 CoTaskMemFree(ppPins);
1960 TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1962 FoundFilter(PinInfo.pFilter, data);
1965 if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1966 return hr;
1969 static HRESULT WINAPI SendRun(IBaseFilter *pFilter, DWORD_PTR data)
1971 REFERENCE_TIME time = *(REFERENCE_TIME*)data;
1972 return IBaseFilter_Run(pFilter, time);
1975 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1977 return IBaseFilter_Pause(pFilter);
1980 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1982 return IBaseFilter_Stop(pFilter);
1985 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1987 FILTER_STATE state;
1988 DWORD time_end = data;
1989 DWORD time_now = GetTickCount();
1990 LONG wait;
1992 if (time_end == INFINITE)
1994 wait = INFINITE;
1996 else if (time_end > time_now)
1998 wait = time_end - time_now;
2000 else
2001 wait = 0;
2003 return IBaseFilter_GetState(pFilter, wait, &state);
2007 static HRESULT SendFilterMessage(IFilterGraphImpl *This, fnFoundFilter FoundFilter, DWORD_PTR data)
2009 int i;
2010 IBaseFilter* pfilter;
2011 IEnumPins* pEnum;
2012 HRESULT hr;
2013 IPin* pPin;
2014 DWORD dummy;
2015 PIN_DIRECTION dir;
2017 TRACE("(%p)->()\n", This);
2019 /* Explorer the graph from source filters to renderers, determine renderers
2020 * number and run filters from renderers to source filters */
2021 This->nRenderers = 0;
2022 ResetEvent(This->hEventCompletion);
2024 for(i = 0; i < This->nFilters; i++)
2026 BOOL source = TRUE;
2027 pfilter = This->ppFiltersInGraph[i];
2028 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
2029 if (hr != S_OK)
2031 WARN("Enum pins failed %x\n", hr);
2032 continue;
2034 /* Check if it is a source filter */
2035 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2037 IPin_QueryDirection(pPin, &dir);
2038 IPin_Release(pPin);
2039 if (dir == PINDIR_INPUT)
2041 source = FALSE;
2042 break;
2045 if (source)
2047 TRACE("Found a source filter %p\n", pfilter);
2048 IEnumPins_Reset(pEnum);
2049 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2051 /* Explore the graph downstream from this pin */
2052 ExploreGraph(This, pPin, FoundFilter, data);
2053 IPin_Release(pPin);
2055 FoundFilter(pfilter, data);
2057 IEnumPins_Release(pEnum);
2060 return S_FALSE;
2063 /*** IMediaControl methods ***/
2064 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
2066 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2068 TRACE("(%p/%p)->()\n", This, iface);
2070 EnterCriticalSection(&This->cs);
2071 if (This->state == State_Running)
2072 goto out;
2073 This->EcCompleteCount = 0;
2075 if (This->defaultclock && !This->refClock)
2076 IFilterGraph2_SetDefaultSyncSource(&This->IFilterGraph2_iface);
2078 if (This->refClock)
2080 REFERENCE_TIME now;
2081 IReferenceClock_GetTime(This->refClock, &now);
2082 if (This->state == State_Stopped)
2083 This->start_time = now + 500000;
2084 else if (This->pause_time >= 0)
2085 This->start_time += now - This->pause_time;
2086 else
2087 This->start_time = now;
2089 else This->start_time = 0;
2091 SendFilterMessage(This, SendRun, (DWORD_PTR)&This->start_time);
2092 This->state = State_Running;
2093 out:
2094 LeaveCriticalSection(&This->cs);
2095 return S_FALSE;
2098 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
2100 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2102 TRACE("(%p/%p)->()\n", This, iface);
2104 EnterCriticalSection(&This->cs);
2105 if (This->state == State_Paused)
2106 goto out;
2108 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2109 IReferenceClock_GetTime(This->refClock, &This->pause_time);
2110 else
2111 This->pause_time = -1;
2113 SendFilterMessage(This, SendPause, 0);
2114 This->state = State_Paused;
2115 out:
2116 LeaveCriticalSection(&This->cs);
2117 return S_FALSE;
2120 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
2122 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2124 TRACE("(%p/%p)->()\n", This, iface);
2126 if (This->state == State_Stopped) return S_OK;
2128 EnterCriticalSection(&This->cs);
2129 if (This->state == State_Running) SendFilterMessage(This, SendPause, 0);
2130 SendFilterMessage(This, SendStop, 0);
2131 This->state = State_Stopped;
2132 LeaveCriticalSection(&This->cs);
2133 return S_OK;
2136 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG msTimeout,
2137 OAFilterState *pfs)
2139 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2140 DWORD end;
2142 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
2144 if (!pfs)
2145 return E_POINTER;
2147 EnterCriticalSection(&This->cs);
2149 *pfs = This->state;
2150 if (msTimeout > 0)
2152 end = GetTickCount() + msTimeout;
2154 else if (msTimeout < 0)
2156 end = INFINITE;
2158 else
2160 end = 0;
2162 if (end)
2163 SendFilterMessage(This, SendGetState, end);
2165 LeaveCriticalSection(&This->cs);
2167 return S_OK;
2170 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
2172 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2174 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strFilename), strFilename);
2176 return IFilterGraph2_RenderFile(&This->IFilterGraph2_iface, strFilename, NULL);
2179 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
2180 IDispatch **ppUnk)
2182 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2184 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2186 return S_OK;
2189 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2191 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2193 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2195 return S_OK;
2198 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2200 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2202 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2204 return S_OK;
2207 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
2209 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2211 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2213 return S_OK;
2217 static const IMediaControlVtbl IMediaControl_VTable =
2219 MediaControl_QueryInterface,
2220 MediaControl_AddRef,
2221 MediaControl_Release,
2222 MediaControl_GetTypeInfoCount,
2223 MediaControl_GetTypeInfo,
2224 MediaControl_GetIDsOfNames,
2225 MediaControl_Invoke,
2226 MediaControl_Run,
2227 MediaControl_Pause,
2228 MediaControl_Stop,
2229 MediaControl_GetState,
2230 MediaControl_RenderFile,
2231 MediaControl_AddSourceFilter,
2232 MediaControl_get_FilterCollection,
2233 MediaControl_get_RegFilterCollection,
2234 MediaControl_StopWhenReady
2237 static inline IFilterGraphImpl *impl_from_IMediaSeeking(IMediaSeeking *iface)
2239 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaSeeking_iface);
2242 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID riid, void **ppvObj)
2244 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2246 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
2248 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2251 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2253 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2255 TRACE("(%p/%p)->()\n", This, iface);
2257 return IUnknown_AddRef(This->outer_unk);
2260 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2262 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2264 TRACE("(%p/%p)->()\n", This, iface);
2266 return IUnknown_Release(This->outer_unk);
2269 typedef HRESULT (WINAPI *fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
2271 static HRESULT all_renderers_seek(IFilterGraphImpl *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2272 BOOL allnotimpl = TRUE;
2273 int i;
2274 HRESULT hr, hr_return = S_OK;
2276 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2277 /* Send a message to all renderers, they are responsible for broadcasting it further */
2279 for(i = 0; i < This->nFilters; i++)
2281 IMediaSeeking *seek = NULL;
2282 IBaseFilter* pfilter = This->ppFiltersInGraph[i];
2283 IAMFilterMiscFlags *flags = NULL;
2284 ULONG filterflags;
2285 IBaseFilter_QueryInterface(pfilter, &IID_IAMFilterMiscFlags, (void**)&flags);
2286 if (!flags)
2287 continue;
2288 filterflags = IAMFilterMiscFlags_GetMiscFlags(flags);
2289 IAMFilterMiscFlags_Release(flags);
2290 if (filterflags != AM_FILTER_MISC_FLAGS_IS_RENDERER)
2291 continue;
2293 IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2294 if (!seek)
2295 continue;
2296 hr = FoundSeek(This, seek, arg);
2297 IMediaSeeking_Release(seek);
2298 if (hr_return != E_NOTIMPL)
2299 allnotimpl = FALSE;
2300 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2301 hr_return = hr;
2304 if (allnotimpl)
2305 return E_NOTIMPL;
2306 return hr_return;
2309 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2311 HRESULT hr;
2312 DWORD caps = 0;
2314 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2315 if (FAILED(hr))
2316 return hr;
2318 /* Only add common capabilities everything supports */
2319 *(DWORD*)pcaps &= caps;
2321 return hr;
2324 /*** IMediaSeeking methods ***/
2325 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2327 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2328 HRESULT hr;
2330 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2332 if (!pCapabilities)
2333 return E_POINTER;
2335 EnterCriticalSection(&This->cs);
2336 *pCapabilities = 0xffffffff;
2338 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2339 LeaveCriticalSection(&This->cs);
2341 return hr;
2344 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2346 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2347 DWORD originalcaps;
2348 HRESULT hr;
2350 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2352 if (!pCapabilities)
2353 return E_POINTER;
2355 EnterCriticalSection(&This->cs);
2356 originalcaps = *pCapabilities;
2357 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2358 LeaveCriticalSection(&This->cs);
2360 if (FAILED(hr))
2361 return hr;
2363 if (!*pCapabilities)
2364 return E_FAIL;
2365 if (*pCapabilities != originalcaps)
2366 return S_FALSE;
2367 return S_OK;
2370 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2372 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2374 if (!pFormat)
2375 return E_POINTER;
2377 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2379 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2381 WARN("Unhandled time format %s\n", debugstr_guid(pFormat));
2382 return S_FALSE;
2385 return S_OK;
2388 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2390 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2392 if (!pFormat)
2393 return E_POINTER;
2395 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2396 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2398 return S_OK;
2401 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2403 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2405 if (!pFormat)
2406 return E_POINTER;
2408 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2409 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2411 return S_OK;
2414 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2416 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2418 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2419 if (!pFormat)
2420 return E_POINTER;
2422 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2423 return S_FALSE;
2425 return S_OK;
2428 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2430 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2432 if (!pFormat)
2433 return E_POINTER;
2435 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2437 if (This->state != State_Stopped)
2438 return VFW_E_WRONG_STATE;
2440 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2442 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2443 return E_INVALIDARG;
2446 return S_OK;
2449 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2451 HRESULT hr;
2452 LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2454 hr = IMediaSeeking_GetDuration(seek, &duration);
2455 if (FAILED(hr))
2456 return hr;
2458 if (*pdur < duration)
2459 *pdur = duration;
2460 return hr;
2463 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *pDuration)
2465 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2466 HRESULT hr;
2468 TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2470 if (!pDuration)
2471 return E_POINTER;
2473 EnterCriticalSection(&This->cs);
2474 *pDuration = 0;
2475 hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2476 LeaveCriticalSection(&This->cs);
2478 TRACE("--->%08x\n", hr);
2479 return hr;
2482 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *pStop)
2484 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2485 HRESULT hr = S_OK;
2487 TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2489 if (!pStop)
2490 return E_POINTER;
2492 EnterCriticalSection(&This->cs);
2493 if (This->stop_position < 0)
2494 /* Stop position not set, use duration instead */
2495 hr = IMediaSeeking_GetDuration(iface, pStop);
2496 else
2497 *pStop = This->stop_position;
2498 LeaveCriticalSection(&This->cs);
2500 return hr;
2503 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *pCurrent)
2505 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2506 LONGLONG time = 0;
2508 if (!pCurrent)
2509 return E_POINTER;
2511 EnterCriticalSection(&This->cs);
2512 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2514 IReferenceClock_GetTime(This->refClock, &time);
2515 if (time)
2516 time -= This->start_time;
2518 if (This->pause_time > 0)
2519 time += This->pause_time;
2520 *pCurrent = time;
2521 LeaveCriticalSection(&This->cs);
2523 TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2525 return S_OK;
2528 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2529 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2531 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2533 TRACE("(%p/%p)->(%p, %s, 0x%s, %s)\n", This, iface, pTarget,
2534 debugstr_guid(pTargetFormat), wine_dbgstr_longlong(Source), debugstr_guid(pSourceFormat));
2536 if (!pSourceFormat)
2537 pSourceFormat = &This->timeformatseek;
2539 if (!pTargetFormat)
2540 pTargetFormat = &This->timeformatseek;
2542 if (IsEqualGUID(pTargetFormat, pSourceFormat))
2543 *pTarget = Source;
2544 else
2545 FIXME("conversion %s->%s not supported\n", debugstr_guid(pSourceFormat), debugstr_guid(pTargetFormat));
2547 return S_OK;
2550 struct pos_args {
2551 LONGLONG* current, *stop;
2552 DWORD curflags, stopflags;
2555 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2557 struct pos_args *args = (void*)pargs;
2559 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
2562 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2563 DWORD dwCurrentFlags, LONGLONG *pStop, DWORD dwStopFlags)
2565 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2566 HRESULT hr = S_OK;
2567 FILTER_STATE state;
2568 struct pos_args args;
2570 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
2572 EnterCriticalSection(&This->cs);
2573 state = This->state;
2574 TRACE("State: %s\n", state == State_Running ? "Running" : (state == State_Paused ? "Paused" : (state == State_Stopped ? "Stopped" : "UNKNOWN")));
2576 if ((dwCurrentFlags & 0x7) != AM_SEEKING_AbsolutePositioning &&
2577 (dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2578 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
2580 if ((dwStopFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2581 This->stop_position = *pStop;
2582 else if ((dwStopFlags & 0x7) != AM_SEEKING_NoPositioning)
2583 FIXME("Stop position not handled yet!\n");
2585 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2586 IMediaControl_Pause(&This->IMediaControl_iface);
2587 args.current = pCurrent;
2588 args.stop = pStop;
2589 args.curflags = dwCurrentFlags;
2590 args.stopflags = dwStopFlags;
2591 hr = all_renderers_seek(This, found_setposition, (DWORD_PTR)&args);
2593 if ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2594 This->pause_time = This->start_time = -1;
2595 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2596 IMediaControl_Run(&This->IMediaControl_iface);
2597 LeaveCriticalSection(&This->cs);
2599 return hr;
2602 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2603 LONGLONG *pStop)
2605 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2606 HRESULT hr;
2608 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pCurrent, pStop);
2609 hr = IMediaSeeking_GetCurrentPosition(iface, pCurrent);
2610 if (SUCCEEDED(hr))
2611 hr = IMediaSeeking_GetStopPosition(iface, pStop);
2613 return hr;
2616 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2617 LONGLONG *pLatest)
2619 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2621 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2623 return S_OK;
2626 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2628 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2630 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2632 return S_OK;
2635 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2637 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2639 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2641 if (!pdRate)
2642 return E_POINTER;
2644 *pdRate = 1.0;
2646 return S_OK;
2649 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2651 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2653 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2655 return S_OK;
2659 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2661 MediaSeeking_QueryInterface,
2662 MediaSeeking_AddRef,
2663 MediaSeeking_Release,
2664 MediaSeeking_GetCapabilities,
2665 MediaSeeking_CheckCapabilities,
2666 MediaSeeking_IsFormatSupported,
2667 MediaSeeking_QueryPreferredFormat,
2668 MediaSeeking_GetTimeFormat,
2669 MediaSeeking_IsUsingTimeFormat,
2670 MediaSeeking_SetTimeFormat,
2671 MediaSeeking_GetDuration,
2672 MediaSeeking_GetStopPosition,
2673 MediaSeeking_GetCurrentPosition,
2674 MediaSeeking_ConvertTimeFormat,
2675 MediaSeeking_SetPositions,
2676 MediaSeeking_GetPositions,
2677 MediaSeeking_GetAvailable,
2678 MediaSeeking_SetRate,
2679 MediaSeeking_GetRate,
2680 MediaSeeking_GetPreroll
2683 static inline IFilterGraphImpl *impl_from_IMediaPosition(IMediaPosition *iface)
2685 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaPosition_iface);
2688 /*** IUnknown methods ***/
2689 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj)
2691 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2693 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
2695 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2698 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2700 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2702 TRACE("(%p/%p)->()\n", This, iface);
2704 return IUnknown_AddRef(This->outer_unk);
2707 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2709 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2711 TRACE("(%p/%p)->()\n", This, iface);
2713 return IUnknown_Release(This->outer_unk);
2716 /*** IDispatch methods ***/
2717 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo)
2719 FIXME("(%p) stub!\n", iface);
2720 return E_NOTIMPL;
2723 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
2725 FIXME("(%p) stub!\n", iface);
2726 return E_NOTIMPL;
2729 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
2731 FIXME("(%p) stub!\n", iface);
2732 return E_NOTIMPL;
2735 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2737 FIXME("(%p) stub!\n", iface);
2738 return E_NOTIMPL;
2741 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2743 GUID time_format;
2744 HRESULT hr;
2746 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2747 if (FAILED(hr))
2748 return hr;
2749 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2751 FIXME("Unsupported time format.\n");
2752 return E_NOTIMPL;
2755 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2756 return S_OK;
2759 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2761 GUID time_format;
2762 HRESULT hr;
2764 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2765 if (FAILED(hr))
2766 return hr;
2767 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2769 FIXME("Unsupported time format.\n");
2770 return E_NOTIMPL;
2773 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2774 return S_OK;
2777 /*** IMediaPosition methods ***/
2778 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2780 LONGLONG duration;
2781 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2782 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2783 if (FAILED(hr))
2784 return hr;
2785 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2788 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2790 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2791 LONGLONG reftime;
2792 HRESULT hr;
2794 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2795 if (FAILED(hr))
2796 return hr;
2797 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2798 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2801 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2803 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2804 LONGLONG pos;
2805 HRESULT hr;
2807 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2808 if (FAILED(hr))
2809 return hr;
2810 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2813 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2815 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2816 LONGLONG pos;
2817 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2818 if (FAILED(hr))
2819 return hr;
2820 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2823 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2825 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2826 LONGLONG reftime;
2827 HRESULT hr;
2829 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2830 if (FAILED(hr))
2831 return hr;
2832 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2833 &reftime, AM_SEEKING_AbsolutePositioning);
2836 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime)
2838 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2839 return E_NOTIMPL;
2842 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime)
2844 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2845 return E_NOTIMPL;
2848 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2850 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2851 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2854 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2856 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2857 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2860 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward)
2862 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2863 return E_NOTIMPL;
2866 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward)
2868 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2869 return E_NOTIMPL;
2873 static const IMediaPositionVtbl IMediaPosition_VTable =
2875 MediaPosition_QueryInterface,
2876 MediaPosition_AddRef,
2877 MediaPosition_Release,
2878 MediaPosition_GetTypeInfoCount,
2879 MediaPosition_GetTypeInfo,
2880 MediaPosition_GetIDsOfNames,
2881 MediaPosition_Invoke,
2882 MediaPosition_get_Duration,
2883 MediaPosition_put_CurrentPosition,
2884 MediaPosition_get_CurrentPosition,
2885 MediaPosition_get_StopTime,
2886 MediaPosition_put_StopTime,
2887 MediaPosition_get_PrerollTime,
2888 MediaPosition_put_PrerollTime,
2889 MediaPosition_put_Rate,
2890 MediaPosition_get_Rate,
2891 MediaPosition_CanSeekForward,
2892 MediaPosition_CanSeekBackward
2895 static inline IFilterGraphImpl *impl_from_IObjectWithSite(IObjectWithSite *iface)
2897 return CONTAINING_RECORD(iface, IFilterGraphImpl, IObjectWithSite_iface);
2900 /*** IUnknown methods ***/
2901 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite* iface, REFIID riid, void** ppvObj)
2903 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2905 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
2907 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2910 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
2912 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2914 TRACE("(%p/%p)->()\n", This, iface);
2916 return IUnknown_AddRef(This->outer_unk);
2919 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
2921 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2923 TRACE("(%p/%p)->()\n", This, iface);
2925 return IUnknown_Release(This->outer_unk);
2928 /*** IObjectWithSite methods ***/
2930 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
2932 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2934 TRACE("(%p/%p)->()\n", This, iface);
2935 if (This->pSite) IUnknown_Release(This->pSite);
2936 This->pSite = pUnkSite;
2937 IUnknown_AddRef(This->pSite);
2938 return S_OK;
2941 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, PVOID *ppvSite)
2943 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2945 TRACE("(%p/%p)->(%s)\n", This, iface,debugstr_guid(riid));
2947 *ppvSite = NULL;
2948 if (!This->pSite)
2949 return E_FAIL;
2950 else
2951 return IUnknown_QueryInterface(This->pSite, riid, ppvSite);
2954 static const IObjectWithSiteVtbl IObjectWithSite_VTable =
2956 ObjectWithSite_QueryInterface,
2957 ObjectWithSite_AddRef,
2958 ObjectWithSite_Release,
2959 ObjectWithSite_SetSite,
2960 ObjectWithSite_GetSite,
2963 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2965 HRESULT hr = E_NOINTERFACE;
2966 int i;
2967 int entry;
2969 /* Check if the interface type is already registered */
2970 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2971 if (riid == pGraph->ItfCacheEntries[entry].riid)
2973 if (pGraph->ItfCacheEntries[entry].iface)
2975 /* Return the interface if available */
2976 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2977 return S_OK;
2979 break;
2982 if (entry >= MAX_ITF_CACHE_ENTRIES)
2984 FIXME("Not enough space to store interface in the cache\n");
2985 return E_OUTOFMEMORY;
2988 /* Find a filter supporting the requested interface */
2989 for (i = 0; i < pGraph->nFilters; i++)
2991 hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2992 if (hr == S_OK)
2994 pGraph->ItfCacheEntries[entry].riid = riid;
2995 pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2996 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2997 if (entry >= pGraph->nItfCacheEntries)
2998 pGraph->nItfCacheEntries++;
2999 return S_OK;
3001 if (hr != E_NOINTERFACE)
3002 return hr;
3005 return hr;
3008 static inline IFilterGraphImpl *impl_from_IBasicAudio(IBasicAudio *iface)
3010 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicAudio_iface);
3013 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID riid, void **ppvObj)
3015 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3017 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
3019 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
3022 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
3024 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3026 TRACE("(%p/%p)->()\n", This, iface);
3028 return IUnknown_AddRef(This->outer_unk);
3031 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
3033 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3035 TRACE("(%p/%p)->()\n", This, iface);
3037 return IUnknown_Release(This->outer_unk);
3040 /*** IDispatch methods ***/
3041 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *pctinfo)
3043 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3044 IBasicAudio* pBasicAudio;
3045 HRESULT hr;
3047 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3049 EnterCriticalSection(&This->cs);
3051 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3053 if (hr == S_OK)
3054 hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
3056 LeaveCriticalSection(&This->cs);
3058 return hr;
3061 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT iTInfo, LCID lcid,
3062 ITypeInfo **ppTInfo)
3064 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3065 IBasicAudio* pBasicAudio;
3066 HRESULT hr;
3068 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3070 EnterCriticalSection(&This->cs);
3072 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3074 if (hr == S_OK)
3075 hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
3077 LeaveCriticalSection(&This->cs);
3079 return hr;
3082 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID riid, LPOLESTR *rgszNames,
3083 UINT cNames, LCID lcid, DISPID *rgDispId)
3085 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3086 IBasicAudio* pBasicAudio;
3087 HRESULT hr;
3089 TRACE("(%p/%p)->(%s, %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), rgszNames, cNames,
3090 lcid, rgDispId);
3092 EnterCriticalSection(&This->cs);
3094 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3096 if (hr == S_OK)
3097 hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
3099 LeaveCriticalSection(&This->cs);
3101 return hr;
3104 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID dispIdMember, REFIID riid,
3105 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3106 UINT *puArgErr)
3108 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3109 IBasicAudio* pBasicAudio;
3110 HRESULT hr;
3112 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember,
3113 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3115 EnterCriticalSection(&This->cs);
3117 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3119 if (hr == S_OK)
3120 hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3122 LeaveCriticalSection(&This->cs);
3124 return hr;
3127 /*** IBasicAudio methods ***/
3128 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
3130 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3131 IBasicAudio* pBasicAudio;
3132 HRESULT hr;
3134 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
3136 EnterCriticalSection(&This->cs);
3138 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3140 if (hr == S_OK)
3141 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
3143 LeaveCriticalSection(&This->cs);
3145 return hr;
3148 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
3150 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3151 IBasicAudio* pBasicAudio;
3152 HRESULT hr;
3154 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
3156 EnterCriticalSection(&This->cs);
3158 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3160 if (hr == S_OK)
3161 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
3163 LeaveCriticalSection(&This->cs);
3165 return hr;
3168 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
3170 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3171 IBasicAudio* pBasicAudio;
3172 HRESULT hr;
3174 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
3176 EnterCriticalSection(&This->cs);
3178 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3180 if (hr == S_OK)
3181 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
3183 LeaveCriticalSection(&This->cs);
3185 return hr;
3188 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
3190 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3191 IBasicAudio* pBasicAudio;
3192 HRESULT hr;
3194 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
3196 EnterCriticalSection(&This->cs);
3198 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3200 if (hr == S_OK)
3201 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
3203 LeaveCriticalSection(&This->cs);
3205 return hr;
3208 static const IBasicAudioVtbl IBasicAudio_VTable =
3210 BasicAudio_QueryInterface,
3211 BasicAudio_AddRef,
3212 BasicAudio_Release,
3213 BasicAudio_GetTypeInfoCount,
3214 BasicAudio_GetTypeInfo,
3215 BasicAudio_GetIDsOfNames,
3216 BasicAudio_Invoke,
3217 BasicAudio_put_Volume,
3218 BasicAudio_get_Volume,
3219 BasicAudio_put_Balance,
3220 BasicAudio_get_Balance
3223 static inline IFilterGraphImpl *impl_from_IBasicVideo2(IBasicVideo2 *iface)
3225 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicVideo2_iface);
3228 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID riid, void **ppvObj)
3230 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3232 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
3234 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
3237 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
3239 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3241 TRACE("(%p/%p)->()\n", This, iface);
3243 return IUnknown_AddRef(This->outer_unk);
3246 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
3248 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3250 TRACE("(%p/%p)->()\n", This, iface);
3252 return IUnknown_Release(This->outer_unk);
3255 /*** IDispatch methods ***/
3256 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *pctinfo)
3258 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3259 IBasicVideo *pBasicVideo;
3260 HRESULT hr;
3262 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3264 EnterCriticalSection(&This->cs);
3266 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3268 if (hr == S_OK)
3269 hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
3271 LeaveCriticalSection(&This->cs);
3273 return hr;
3276 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT iTInfo, LCID lcid,
3277 ITypeInfo **ppTInfo)
3279 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3280 IBasicVideo *pBasicVideo;
3281 HRESULT hr;
3283 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3285 EnterCriticalSection(&This->cs);
3287 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3289 if (hr == S_OK)
3290 hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
3292 LeaveCriticalSection(&This->cs);
3294 return hr;
3297 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID riid,
3298 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
3300 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3301 IBasicVideo *pBasicVideo;
3302 HRESULT hr;
3304 TRACE("(%p/%p)->(%s, %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), rgszNames, cNames,
3305 lcid, rgDispId);
3307 EnterCriticalSection(&This->cs);
3309 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3311 if (hr == S_OK)
3312 hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
3314 LeaveCriticalSection(&This->cs);
3316 return hr;
3319 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID dispIdMember, REFIID riid,
3320 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3321 UINT *puArgErr)
3323 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3324 IBasicVideo *pBasicVideo;
3325 HRESULT hr;
3327 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember,
3328 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3330 EnterCriticalSection(&This->cs);
3332 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3334 if (hr == S_OK)
3335 hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3337 LeaveCriticalSection(&This->cs);
3339 return hr;
3342 /*** IBasicVideo methods ***/
3343 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3345 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3346 IBasicVideo *pBasicVideo;
3347 HRESULT hr;
3349 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3351 EnterCriticalSection(&This->cs);
3353 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3355 if (hr == S_OK)
3356 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3358 LeaveCriticalSection(&This->cs);
3360 return hr;
3363 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3365 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3366 IBasicVideo *pBasicVideo;
3367 HRESULT hr;
3369 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3371 EnterCriticalSection(&This->cs);
3373 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3375 if (hr == S_OK)
3376 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3378 LeaveCriticalSection(&This->cs);
3380 return hr;
3383 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3385 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3386 IBasicVideo *pBasicVideo;
3387 HRESULT hr;
3389 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3391 EnterCriticalSection(&This->cs);
3393 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3395 if (hr == S_OK)
3396 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3398 LeaveCriticalSection(&This->cs);
3400 return hr;
3403 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3405 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3406 IBasicVideo *pBasicVideo;
3407 HRESULT hr;
3409 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3411 EnterCriticalSection(&This->cs);
3413 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3415 if (hr == S_OK)
3416 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3418 LeaveCriticalSection(&This->cs);
3420 return hr;
3423 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3425 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3426 IBasicVideo *pBasicVideo;
3427 HRESULT hr;
3429 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3431 EnterCriticalSection(&This->cs);
3433 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3435 if (hr == S_OK)
3436 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3438 LeaveCriticalSection(&This->cs);
3440 return hr;
3443 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3445 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3446 IBasicVideo *pBasicVideo;
3447 HRESULT hr;
3449 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3451 EnterCriticalSection(&This->cs);
3453 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3455 if (hr == S_OK)
3456 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3458 LeaveCriticalSection(&This->cs);
3460 return hr;
3463 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3465 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3466 IBasicVideo *pBasicVideo;
3467 HRESULT hr;
3469 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3471 EnterCriticalSection(&This->cs);
3473 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3475 if (hr == S_OK)
3476 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3478 LeaveCriticalSection(&This->cs);
3480 return hr;
3483 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3485 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3486 IBasicVideo *pBasicVideo;
3487 HRESULT hr;
3489 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3491 EnterCriticalSection(&This->cs);
3493 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3495 if (hr == S_OK)
3496 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3498 LeaveCriticalSection(&This->cs);
3500 return hr;
3503 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3505 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3506 IBasicVideo *pBasicVideo;
3507 HRESULT hr;
3509 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3511 EnterCriticalSection(&This->cs);
3513 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3515 if (hr == S_OK)
3516 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3518 LeaveCriticalSection(&This->cs);
3520 return hr;
3523 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3525 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3526 IBasicVideo *pBasicVideo;
3527 HRESULT hr;
3529 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3531 EnterCriticalSection(&This->cs);
3533 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3535 if (hr == S_OK)
3536 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3538 LeaveCriticalSection(&This->cs);
3540 return hr;
3543 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3545 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3546 IBasicVideo *pBasicVideo;
3547 HRESULT hr;
3549 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3551 EnterCriticalSection(&This->cs);
3553 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3555 if (hr == S_OK)
3556 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3558 LeaveCriticalSection(&This->cs);
3560 return hr;
3563 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3565 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3566 IBasicVideo *pBasicVideo;
3567 HRESULT hr;
3569 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3571 EnterCriticalSection(&This->cs);
3573 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3575 if (hr == S_OK)
3576 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3578 LeaveCriticalSection(&This->cs);
3580 return hr;
3583 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3585 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3586 IBasicVideo *pBasicVideo;
3587 HRESULT hr;
3589 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3591 EnterCriticalSection(&This->cs);
3593 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3595 if (hr == S_OK)
3596 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3598 LeaveCriticalSection(&This->cs);
3600 return hr;
3603 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3605 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3606 IBasicVideo *pBasicVideo;
3607 HRESULT hr;
3609 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3611 EnterCriticalSection(&This->cs);
3613 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3615 if (hr == S_OK)
3616 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3618 LeaveCriticalSection(&This->cs);
3620 return hr;
3623 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3625 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3626 IBasicVideo *pBasicVideo;
3627 HRESULT hr;
3629 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3631 EnterCriticalSection(&This->cs);
3633 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3635 if (hr == S_OK)
3636 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3638 LeaveCriticalSection(&This->cs);
3640 return hr;
3643 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3645 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3646 IBasicVideo *pBasicVideo;
3647 HRESULT hr;
3649 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3651 EnterCriticalSection(&This->cs);
3653 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3655 if (hr == S_OK)
3656 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3658 LeaveCriticalSection(&This->cs);
3660 return hr;
3663 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3665 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3666 IBasicVideo *pBasicVideo;
3667 HRESULT hr;
3669 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3671 EnterCriticalSection(&This->cs);
3673 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3675 if (hr == S_OK)
3676 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3678 LeaveCriticalSection(&This->cs);
3680 return hr;
3683 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3685 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3686 IBasicVideo *pBasicVideo;
3687 HRESULT hr;
3689 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3691 EnterCriticalSection(&This->cs);
3693 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3695 if (hr == S_OK)
3696 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3698 LeaveCriticalSection(&This->cs);
3700 return hr;
3703 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3705 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3706 IBasicVideo *pBasicVideo;
3707 HRESULT hr;
3709 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3711 EnterCriticalSection(&This->cs);
3713 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3715 if (hr == S_OK)
3716 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3718 LeaveCriticalSection(&This->cs);
3720 return hr;
3723 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3725 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3726 IBasicVideo *pBasicVideo;
3727 HRESULT hr;
3729 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3731 EnterCriticalSection(&This->cs);
3733 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3735 if (hr == S_OK)
3736 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3738 LeaveCriticalSection(&This->cs);
3740 return hr;
3743 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3744 LONG *pDestinationHeight)
3746 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3747 IBasicVideo *pBasicVideo;
3748 HRESULT hr;
3750 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3752 EnterCriticalSection(&This->cs);
3754 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3756 if (hr == S_OK)
3757 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3759 LeaveCriticalSection(&This->cs);
3761 return hr;
3764 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3765 LONG Width, LONG Height)
3767 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3768 IBasicVideo *pBasicVideo;
3769 HRESULT hr;
3771 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3773 EnterCriticalSection(&This->cs);
3775 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3777 if (hr == S_OK)
3778 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3780 LeaveCriticalSection(&This->cs);
3782 return hr;
3785 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3786 LONG *pWidth, LONG *pHeight)
3788 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3789 IBasicVideo *pBasicVideo;
3790 HRESULT hr;
3792 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3794 EnterCriticalSection(&This->cs);
3796 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3798 if (hr == S_OK)
3799 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3801 LeaveCriticalSection(&This->cs);
3803 return hr;
3806 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3808 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3809 IBasicVideo *pBasicVideo;
3810 HRESULT hr;
3812 TRACE("(%p/%p)->()\n", This, iface);
3814 EnterCriticalSection(&This->cs);
3816 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3818 if (hr == S_OK)
3819 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3821 LeaveCriticalSection(&This->cs);
3823 return hr;
3826 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3827 LONG Width, LONG Height)
3829 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3830 IBasicVideo *pBasicVideo;
3831 HRESULT hr;
3833 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3835 EnterCriticalSection(&This->cs);
3837 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3839 if (hr == S_OK)
3840 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3842 LeaveCriticalSection(&This->cs);
3844 return hr;
3847 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3848 LONG *pTop, LONG *pWidth, LONG *pHeight)
3850 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3851 IBasicVideo *pBasicVideo;
3852 HRESULT hr;
3854 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3856 EnterCriticalSection(&This->cs);
3858 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3860 if (hr == S_OK)
3861 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3863 LeaveCriticalSection(&This->cs);
3865 return hr;
3868 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3870 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3871 IBasicVideo *pBasicVideo;
3872 HRESULT hr;
3874 TRACE("(%p/%p)->()\n", This, iface);
3876 EnterCriticalSection(&This->cs);
3878 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3880 if (hr == S_OK)
3881 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3883 LeaveCriticalSection(&This->cs);
3885 return hr;
3888 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3890 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3891 IBasicVideo *pBasicVideo;
3892 HRESULT hr;
3894 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3896 EnterCriticalSection(&This->cs);
3898 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3900 if (hr == S_OK)
3901 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3903 LeaveCriticalSection(&This->cs);
3905 return hr;
3908 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3909 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3911 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3912 IBasicVideo *pBasicVideo;
3913 HRESULT hr;
3915 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3917 EnterCriticalSection(&This->cs);
3919 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3921 if (hr == S_OK)
3922 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3924 LeaveCriticalSection(&This->cs);
3926 return hr;
3929 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3930 LONG *pDIBImage)
3932 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3933 IBasicVideo *pBasicVideo;
3934 HRESULT hr;
3936 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3938 EnterCriticalSection(&This->cs);
3940 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3942 if (hr == S_OK)
3943 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3945 LeaveCriticalSection(&This->cs);
3947 return hr;
3950 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3952 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3953 IBasicVideo *pBasicVideo;
3954 HRESULT hr;
3956 TRACE("(%p/%p)->()\n", This, iface);
3958 EnterCriticalSection(&This->cs);
3960 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3962 if (hr == S_OK)
3963 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3965 LeaveCriticalSection(&This->cs);
3967 return hr;
3970 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3972 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3973 IBasicVideo *pBasicVideo;
3974 HRESULT hr;
3976 TRACE("(%p/%p)->()\n", This, iface);
3978 EnterCriticalSection(&This->cs);
3980 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3982 if (hr == S_OK)
3983 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3985 LeaveCriticalSection(&This->cs);
3987 return hr;
3990 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3991 LONG *plAspectY)
3993 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3994 IBasicVideo2 *pBasicVideo2;
3995 HRESULT hr;
3997 TRACE("(%p/%p)->()\n", This, iface);
3999 EnterCriticalSection(&This->cs);
4001 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
4003 if (hr == S_OK)
4004 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
4006 LeaveCriticalSection(&This->cs);
4008 return hr;
4011 static const IBasicVideo2Vtbl IBasicVideo_VTable =
4013 BasicVideo_QueryInterface,
4014 BasicVideo_AddRef,
4015 BasicVideo_Release,
4016 BasicVideo_GetTypeInfoCount,
4017 BasicVideo_GetTypeInfo,
4018 BasicVideo_GetIDsOfNames,
4019 BasicVideo_Invoke,
4020 BasicVideo_get_AvgTimePerFrame,
4021 BasicVideo_get_BitRate,
4022 BasicVideo_get_BitErrorRate,
4023 BasicVideo_get_VideoWidth,
4024 BasicVideo_get_VideoHeight,
4025 BasicVideo_put_SourceLeft,
4026 BasicVideo_get_SourceLeft,
4027 BasicVideo_put_SourceWidth,
4028 BasicVideo_get_SourceWidth,
4029 BasicVideo_put_SourceTop,
4030 BasicVideo_get_SourceTop,
4031 BasicVideo_put_SourceHeight,
4032 BasicVideo_get_SourceHeight,
4033 BasicVideo_put_DestinationLeft,
4034 BasicVideo_get_DestinationLeft,
4035 BasicVideo_put_DestinationWidth,
4036 BasicVideo_get_DestinationWidth,
4037 BasicVideo_put_DestinationTop,
4038 BasicVideo_get_DestinationTop,
4039 BasicVideo_put_DestinationHeight,
4040 BasicVideo_get_DestinationHeight,
4041 BasicVideo_SetSourcePosition,
4042 BasicVideo_GetSourcePosition,
4043 BasicVideo_SetDefaultSourcePosition,
4044 BasicVideo_SetDestinationPosition,
4045 BasicVideo_GetDestinationPosition,
4046 BasicVideo_SetDefaultDestinationPosition,
4047 BasicVideo_GetVideoSize,
4048 BasicVideo_GetVideoPaletteEntries,
4049 BasicVideo_GetCurrentImage,
4050 BasicVideo_IsUsingDefaultSource,
4051 BasicVideo_IsUsingDefaultDestination,
4052 BasicVideo2_GetPreferredAspectRatio
4055 static inline IFilterGraphImpl *impl_from_IVideoWindow(IVideoWindow *iface)
4057 return CONTAINING_RECORD(iface, IFilterGraphImpl, IVideoWindow_iface);
4060 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID riid, void **ppvObj)
4062 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4064 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
4066 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
4069 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
4071 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4073 TRACE("(%p/%p)->()\n", This, iface);
4075 return IUnknown_AddRef(This->outer_unk);
4078 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
4080 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4082 TRACE("(%p/%p)->()\n", This, iface);
4084 return IUnknown_Release(This->outer_unk);
4087 /*** IDispatch methods ***/
4088 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *pctinfo)
4090 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4091 IVideoWindow *pVideoWindow;
4092 HRESULT hr;
4094 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
4096 EnterCriticalSection(&This->cs);
4098 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4100 if (hr == S_OK)
4101 hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
4103 LeaveCriticalSection(&This->cs);
4105 return hr;
4108 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT iTInfo, LCID lcid,
4109 ITypeInfo **ppTInfo)
4111 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4112 IVideoWindow *pVideoWindow;
4113 HRESULT hr;
4115 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
4117 EnterCriticalSection(&This->cs);
4119 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4121 if (hr == S_OK)
4122 hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
4124 LeaveCriticalSection(&This->cs);
4126 return hr;
4129 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID riid,
4130 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4132 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4133 IVideoWindow *pVideoWindow;
4134 HRESULT hr;
4136 TRACE("(%p/%p)->(%s, %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), rgszNames, cNames,
4137 lcid, rgDispId);
4139 EnterCriticalSection(&This->cs);
4141 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4143 if (hr == S_OK)
4144 hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
4146 LeaveCriticalSection(&This->cs);
4148 return hr;
4151 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID dispIdMember, REFIID riid,
4152 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4153 UINT*puArgErr)
4155 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4156 IVideoWindow *pVideoWindow;
4157 HRESULT hr;
4159 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember,
4160 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4162 EnterCriticalSection(&This->cs);
4164 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4166 if (hr == S_OK)
4167 hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4169 LeaveCriticalSection(&This->cs);
4171 return hr;
4175 /*** IVideoWindow methods ***/
4176 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
4178 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4179 IVideoWindow *pVideoWindow;
4180 HRESULT hr;
4182 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
4184 EnterCriticalSection(&This->cs);
4186 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4188 if (hr == S_OK)
4189 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
4191 LeaveCriticalSection(&This->cs);
4193 return hr;
4196 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
4198 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4199 IVideoWindow *pVideoWindow;
4200 HRESULT hr;
4202 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
4204 EnterCriticalSection(&This->cs);
4206 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4208 if (hr == S_OK)
4209 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
4211 LeaveCriticalSection(&This->cs);
4213 return hr;
4216 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
4218 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4219 IVideoWindow *pVideoWindow;
4220 HRESULT hr;
4222 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
4224 EnterCriticalSection(&This->cs);
4226 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4228 if (hr == S_OK)
4229 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
4231 LeaveCriticalSection(&This->cs);
4233 return hr;
4236 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
4238 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4239 IVideoWindow *pVideoWindow;
4240 HRESULT hr;
4242 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
4244 EnterCriticalSection(&This->cs);
4246 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4248 if (hr == S_OK)
4249 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
4251 LeaveCriticalSection(&This->cs);
4253 return hr;
4256 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
4258 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4259 IVideoWindow *pVideoWindow;
4260 HRESULT hr;
4262 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
4264 EnterCriticalSection(&This->cs);
4266 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4268 if (hr == S_OK)
4269 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
4271 LeaveCriticalSection(&This->cs);
4273 return hr;
4276 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
4278 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4279 IVideoWindow *pVideoWindow;
4280 HRESULT hr;
4282 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
4284 EnterCriticalSection(&This->cs);
4286 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4288 if (hr == S_OK)
4289 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
4291 LeaveCriticalSection(&This->cs);
4293 return hr;
4296 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
4298 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4299 IVideoWindow *pVideoWindow;
4300 HRESULT hr;
4302 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
4304 EnterCriticalSection(&This->cs);
4306 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4308 if (hr == S_OK)
4309 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4311 LeaveCriticalSection(&This->cs);
4313 return hr;
4316 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
4318 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4319 IVideoWindow *pVideoWindow;
4320 HRESULT hr;
4322 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4324 EnterCriticalSection(&This->cs);
4326 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4328 if (hr == S_OK)
4329 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4331 LeaveCriticalSection(&This->cs);
4333 return hr;
4336 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
4338 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4339 IVideoWindow *pVideoWindow;
4340 HRESULT hr;
4342 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4344 EnterCriticalSection(&This->cs);
4346 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4348 if (hr == S_OK)
4349 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4351 LeaveCriticalSection(&This->cs);
4353 return hr;
4356 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4358 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4359 IVideoWindow *pVideoWindow;
4360 HRESULT hr;
4362 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4364 EnterCriticalSection(&This->cs);
4366 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4368 if (hr == S_OK)
4369 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4371 LeaveCriticalSection(&This->cs);
4373 return hr;
4376 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4378 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4379 IVideoWindow *pVideoWindow;
4380 HRESULT hr;
4382 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4384 EnterCriticalSection(&This->cs);
4386 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4388 if (hr == S_OK)
4389 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4391 LeaveCriticalSection(&This->cs);
4393 return hr;
4396 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4397 LONG *pBackgroundPalette)
4399 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4400 IVideoWindow *pVideoWindow;
4401 HRESULT hr;
4403 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4405 EnterCriticalSection(&This->cs);
4407 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4409 if (hr == S_OK)
4410 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4412 LeaveCriticalSection(&This->cs);
4414 return hr;
4417 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4419 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4420 IVideoWindow *pVideoWindow;
4421 HRESULT hr;
4423 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4425 EnterCriticalSection(&This->cs);
4427 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4429 if (hr == S_OK)
4430 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4432 LeaveCriticalSection(&This->cs);
4434 return hr;
4437 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4439 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4440 IVideoWindow *pVideoWindow;
4441 HRESULT hr;
4443 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4445 EnterCriticalSection(&This->cs);
4447 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4449 if (hr == S_OK)
4450 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4452 LeaveCriticalSection(&This->cs);
4454 return hr;
4457 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4459 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4460 IVideoWindow *pVideoWindow;
4461 HRESULT hr;
4463 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4465 EnterCriticalSection(&This->cs);
4467 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4469 if (hr == S_OK)
4470 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4472 LeaveCriticalSection(&This->cs);
4474 return hr;
4477 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4479 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4480 IVideoWindow *pVideoWindow;
4481 HRESULT hr;
4483 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4485 EnterCriticalSection(&This->cs);
4487 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4489 if (hr == S_OK)
4490 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4492 LeaveCriticalSection(&This->cs);
4494 return hr;
4497 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4499 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4500 IVideoWindow *pVideoWindow;
4501 HRESULT hr;
4503 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4505 EnterCriticalSection(&This->cs);
4507 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4509 if (hr == S_OK)
4510 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4512 LeaveCriticalSection(&This->cs);
4514 return hr;
4517 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4519 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4520 IVideoWindow *pVideoWindow;
4521 HRESULT hr;
4523 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4525 EnterCriticalSection(&This->cs);
4527 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4529 if (hr == S_OK)
4530 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4532 LeaveCriticalSection(&This->cs);
4534 return hr;
4537 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4539 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4540 IVideoWindow *pVideoWindow;
4541 HRESULT hr;
4543 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4545 EnterCriticalSection(&This->cs);
4547 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4549 if (hr == S_OK)
4550 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4552 LeaveCriticalSection(&This->cs);
4554 return hr;
4557 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4559 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4560 IVideoWindow *pVideoWindow;
4561 HRESULT hr;
4563 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4565 EnterCriticalSection(&This->cs);
4567 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4569 if (hr == S_OK)
4570 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4572 LeaveCriticalSection(&This->cs);
4574 return hr;
4577 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4579 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4580 IVideoWindow *pVideoWindow;
4581 HRESULT hr;
4583 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4585 EnterCriticalSection(&This->cs);
4587 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4589 if (hr == S_OK)
4590 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4592 LeaveCriticalSection(&This->cs);
4594 return hr;
4597 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4599 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4600 IVideoWindow *pVideoWindow;
4601 HRESULT hr;
4603 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4605 EnterCriticalSection(&This->cs);
4607 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4609 if (hr == S_OK)
4610 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4612 LeaveCriticalSection(&This->cs);
4614 return hr;
4617 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4619 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4620 IVideoWindow *pVideoWindow;
4621 HRESULT hr;
4623 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4625 EnterCriticalSection(&This->cs);
4627 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4629 if (hr == S_OK)
4630 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4632 LeaveCriticalSection(&This->cs);
4634 return hr;
4637 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4639 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4640 IVideoWindow *pVideoWindow;
4641 HRESULT hr;
4643 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4645 EnterCriticalSection(&This->cs);
4647 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4649 if (hr == S_OK)
4650 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4652 LeaveCriticalSection(&This->cs);
4654 return hr;
4657 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4659 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4660 IVideoWindow *pVideoWindow;
4661 HRESULT hr;
4663 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4665 EnterCriticalSection(&This->cs);
4667 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4669 if (hr == S_OK)
4670 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4672 LeaveCriticalSection(&This->cs);
4674 return hr;
4677 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4679 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4680 IVideoWindow *pVideoWindow;
4681 HRESULT hr;
4683 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4685 EnterCriticalSection(&This->cs);
4687 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4689 if (hr == S_OK)
4690 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4692 LeaveCriticalSection(&This->cs);
4694 return hr;
4697 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4699 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4700 IVideoWindow *pVideoWindow;
4701 HRESULT hr;
4703 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4705 EnterCriticalSection(&This->cs);
4707 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4709 if (hr == S_OK)
4710 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4712 LeaveCriticalSection(&This->cs);
4714 return hr;
4717 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4719 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4720 IVideoWindow *pVideoWindow;
4721 HRESULT hr;
4723 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4725 EnterCriticalSection(&This->cs);
4727 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4729 if (hr == S_OK)
4730 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4732 LeaveCriticalSection(&This->cs);
4734 return hr;
4737 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4739 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4740 IVideoWindow *pVideoWindow;
4741 HRESULT hr;
4743 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4745 EnterCriticalSection(&This->cs);
4747 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4749 if (hr == S_OK)
4750 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4752 LeaveCriticalSection(&This->cs);
4754 return hr;
4757 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4759 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4760 IVideoWindow *pVideoWindow;
4761 HRESULT hr;
4763 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4765 EnterCriticalSection(&This->cs);
4767 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4769 if (hr == S_OK)
4770 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4772 LeaveCriticalSection(&This->cs);
4774 return hr;
4777 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4779 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4780 IVideoWindow *pVideoWindow;
4781 HRESULT hr;
4783 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4785 EnterCriticalSection(&This->cs);
4787 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4789 if (hr == S_OK)
4790 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4792 LeaveCriticalSection(&This->cs);
4794 return hr;
4797 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4798 LONG_PTR wParam, LONG_PTR lParam)
4800 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4801 IVideoWindow *pVideoWindow;
4802 HRESULT hr;
4804 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4806 EnterCriticalSection(&This->cs);
4808 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4810 if (hr == S_OK)
4811 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4813 LeaveCriticalSection(&This->cs);
4815 return hr;
4818 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4819 LONG Width, LONG Height)
4821 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4822 IVideoWindow *pVideoWindow;
4823 HRESULT hr;
4825 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4827 EnterCriticalSection(&This->cs);
4829 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4831 if (hr == S_OK)
4832 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4834 LeaveCriticalSection(&This->cs);
4836 return hr;
4839 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4840 LONG *pWidth, LONG *pHeight)
4842 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4843 IVideoWindow *pVideoWindow;
4844 HRESULT hr;
4846 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4848 EnterCriticalSection(&This->cs);
4850 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4852 if (hr == S_OK)
4853 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4855 LeaveCriticalSection(&This->cs);
4857 return hr;
4860 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4861 LONG *pHeight)
4863 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4864 IVideoWindow *pVideoWindow;
4865 HRESULT hr;
4867 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4869 EnterCriticalSection(&This->cs);
4871 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4873 if (hr == S_OK)
4874 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4876 LeaveCriticalSection(&This->cs);
4878 return hr;
4881 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4882 LONG *pHeight)
4884 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4885 IVideoWindow *pVideoWindow;
4886 HRESULT hr;
4888 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4890 EnterCriticalSection(&This->cs);
4892 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4894 if (hr == S_OK)
4895 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4897 LeaveCriticalSection(&This->cs);
4899 return hr;
4902 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4903 LONG *pWidth, LONG *pHeight)
4905 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4906 IVideoWindow *pVideoWindow;
4907 HRESULT hr;
4909 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4911 EnterCriticalSection(&This->cs);
4913 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4915 if (hr == S_OK)
4916 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4918 LeaveCriticalSection(&This->cs);
4920 return hr;
4923 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4925 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4926 IVideoWindow *pVideoWindow;
4927 HRESULT hr;
4929 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4931 EnterCriticalSection(&This->cs);
4933 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4935 if (hr == S_OK)
4936 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4938 LeaveCriticalSection(&This->cs);
4940 return hr;
4943 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4945 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4946 IVideoWindow *pVideoWindow;
4947 HRESULT hr;
4949 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4951 EnterCriticalSection(&This->cs);
4953 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4955 if (hr == S_OK)
4956 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4958 LeaveCriticalSection(&This->cs);
4960 return hr;
4964 static const IVideoWindowVtbl IVideoWindow_VTable =
4966 VideoWindow_QueryInterface,
4967 VideoWindow_AddRef,
4968 VideoWindow_Release,
4969 VideoWindow_GetTypeInfoCount,
4970 VideoWindow_GetTypeInfo,
4971 VideoWindow_GetIDsOfNames,
4972 VideoWindow_Invoke,
4973 VideoWindow_put_Caption,
4974 VideoWindow_get_Caption,
4975 VideoWindow_put_WindowStyle,
4976 VideoWindow_get_WindowStyle,
4977 VideoWindow_put_WindowStyleEx,
4978 VideoWindow_get_WindowStyleEx,
4979 VideoWindow_put_AutoShow,
4980 VideoWindow_get_AutoShow,
4981 VideoWindow_put_WindowState,
4982 VideoWindow_get_WindowState,
4983 VideoWindow_put_BackgroundPalette,
4984 VideoWindow_get_BackgroundPalette,
4985 VideoWindow_put_Visible,
4986 VideoWindow_get_Visible,
4987 VideoWindow_put_Left,
4988 VideoWindow_get_Left,
4989 VideoWindow_put_Width,
4990 VideoWindow_get_Width,
4991 VideoWindow_put_Top,
4992 VideoWindow_get_Top,
4993 VideoWindow_put_Height,
4994 VideoWindow_get_Height,
4995 VideoWindow_put_Owner,
4996 VideoWindow_get_Owner,
4997 VideoWindow_put_MessageDrain,
4998 VideoWindow_get_MessageDrain,
4999 VideoWindow_get_BorderColor,
5000 VideoWindow_put_BorderColor,
5001 VideoWindow_get_FullScreenMode,
5002 VideoWindow_put_FullScreenMode,
5003 VideoWindow_SetWindowForeground,
5004 VideoWindow_NotifyOwnerMessage,
5005 VideoWindow_SetWindowPosition,
5006 VideoWindow_GetWindowPosition,
5007 VideoWindow_GetMinIdealImageSize,
5008 VideoWindow_GetMaxIdealImageSize,
5009 VideoWindow_GetRestorePosition,
5010 VideoWindow_HideCursor,
5011 VideoWindow_IsCursorHidden
5014 static inline IFilterGraphImpl *impl_from_IMediaEventEx(IMediaEventEx *iface)
5016 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventEx_iface);
5019 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID riid, void **ppvObj)
5021 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5023 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
5025 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
5028 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
5030 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5032 TRACE("(%p/%p)->()\n", This, iface);
5034 return IUnknown_AddRef(This->outer_unk);
5037 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
5039 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5041 TRACE("(%p/%p)->()\n", This, iface);
5043 return IUnknown_Release(This->outer_unk);
5046 /*** IDispatch methods ***/
5047 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *pctinfo)
5049 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5051 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
5053 return S_OK;
5056 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT iTInfo, LCID lcid,
5057 ITypeInfo **ppTInfo)
5059 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5061 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
5063 return S_OK;
5066 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID riid,
5067 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
5069 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5071 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
5072 cNames, lcid, rgDispId);
5074 return S_OK;
5077 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID dispIdMember, REFIID riid,
5078 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
5079 UINT *puArgErr)
5081 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5083 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
5084 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
5086 return S_OK;
5089 /*** IMediaEvent methods ***/
5090 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *hEvent)
5092 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5094 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
5096 *hEvent = (OAEVENT)This->evqueue.msg_event;
5098 return S_OK;
5101 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *lEventCode, LONG_PTR *lParam1,
5102 LONG_PTR *lParam2, LONG msTimeout)
5104 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5105 Event evt;
5107 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
5109 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
5111 *lEventCode = evt.lEventCode;
5112 *lParam1 = evt.lParam1;
5113 *lParam2 = evt.lParam2;
5114 return S_OK;
5117 *lEventCode = 0;
5118 return E_ABORT;
5121 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
5122 LONG *pEvCode)
5124 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5126 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
5128 if (This->state != State_Running)
5129 return VFW_E_WRONG_STATE;
5131 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
5133 *pEvCode = This->CompletionStatus;
5134 return S_OK;
5137 *pEvCode = 0;
5138 return E_ABORT;
5141 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5143 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5145 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5147 if (lEvCode == EC_COMPLETE)
5148 This->HandleEcComplete = FALSE;
5149 else if (lEvCode == EC_REPAINT)
5150 This->HandleEcRepaint = FALSE;
5151 else if (lEvCode == EC_CLOCK_CHANGED)
5152 This->HandleEcClockChanged = FALSE;
5153 else
5154 return S_FALSE;
5156 return S_OK;
5159 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5161 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5163 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5165 if (lEvCode == EC_COMPLETE)
5166 This->HandleEcComplete = TRUE;
5167 else if (lEvCode == EC_REPAINT)
5168 This->HandleEcRepaint = TRUE;
5169 else if (lEvCode == EC_CLOCK_CHANGED)
5170 This->HandleEcClockChanged = TRUE;
5171 else
5172 return S_FALSE;
5174 return S_OK;
5177 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG lEvCode,
5178 LONG_PTR lParam1, LONG_PTR lParam2)
5180 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5182 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
5184 return S_OK;
5187 /*** IMediaEventEx methods ***/
5188 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface, OAHWND hwnd, LONG lMsg,
5189 LONG_PTR lInstanceData)
5191 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5193 TRACE("(%p/%p)->(%08lx, %d, %08lx)\n", This, iface, hwnd, lMsg, lInstanceData);
5195 This->notif.hWnd = (HWND)hwnd;
5196 This->notif.msg = lMsg;
5197 This->notif.instance = lInstanceData;
5199 return S_OK;
5202 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG lNoNotifyFlags)
5204 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5206 TRACE("(%p/%p)->(%d)\n", This, iface, lNoNotifyFlags);
5208 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
5209 return E_INVALIDARG;
5211 This->notif.disabled = lNoNotifyFlags;
5213 return S_OK;
5216 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *lplNoNotifyFlags)
5218 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5220 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
5222 if (!lplNoNotifyFlags)
5223 return E_POINTER;
5225 *lplNoNotifyFlags = This->notif.disabled;
5227 return S_OK;
5231 static const IMediaEventExVtbl IMediaEventEx_VTable =
5233 MediaEvent_QueryInterface,
5234 MediaEvent_AddRef,
5235 MediaEvent_Release,
5236 MediaEvent_GetTypeInfoCount,
5237 MediaEvent_GetTypeInfo,
5238 MediaEvent_GetIDsOfNames,
5239 MediaEvent_Invoke,
5240 MediaEvent_GetEventHandle,
5241 MediaEvent_GetEvent,
5242 MediaEvent_WaitForCompletion,
5243 MediaEvent_CancelDefaultHandling,
5244 MediaEvent_RestoreDefaultHandling,
5245 MediaEvent_FreeEventParams,
5246 MediaEvent_SetNotifyWindow,
5247 MediaEvent_SetNotifyFlags,
5248 MediaEvent_GetNotifyFlags
5252 static inline IFilterGraphImpl *impl_from_IMediaFilter(IMediaFilter *iface)
5254 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaFilter_iface);
5257 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, void **ppv)
5259 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5261 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5264 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
5266 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5268 return IUnknown_AddRef(This->outer_unk);
5271 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
5273 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5275 return IUnknown_Release(This->outer_unk);
5278 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
5280 FIXME("(%p): stub\n", pClassID);
5282 return E_NOTIMPL;
5285 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
5287 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5289 return MediaControl_Stop(&This->IMediaControl_iface);
5292 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5294 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5296 return MediaControl_Pause(&This->IMediaControl_iface);
5299 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
5301 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5303 if (tStart)
5304 FIXME("Run called with non-null tStart: %s\n", wine_dbgstr_longlong(tStart));
5306 return MediaControl_Run(&This->IMediaControl_iface);
5309 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout,
5310 FILTER_STATE *pState)
5312 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5314 return MediaControl_GetState(&This->IMediaControl_iface, dwMsTimeout, (OAFilterState*)pState);
5317 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5319 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5320 HRESULT hr = S_OK;
5321 int i;
5323 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
5325 EnterCriticalSection(&This->cs);
5327 for (i = 0;i < This->nFilters;i++)
5329 hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5330 if (FAILED(hr))
5331 break;
5334 if (FAILED(hr))
5336 for(;i >= 0;i--)
5337 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5339 else
5341 if (This->refClock)
5342 IReferenceClock_Release(This->refClock);
5343 This->refClock = pClock;
5344 if (This->refClock)
5345 IReferenceClock_AddRef(This->refClock);
5346 This->defaultclock = FALSE;
5348 if (This->HandleEcClockChanged)
5350 IMediaEventSink *pEventSink;
5351 HRESULT eshr;
5353 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (void **)&pEventSink);
5354 if (SUCCEEDED(eshr))
5356 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5357 IMediaEventSink_Release(pEventSink);
5362 LeaveCriticalSection(&This->cs);
5364 return hr;
5367 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5369 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5371 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
5373 if (!ppClock)
5374 return E_POINTER;
5376 EnterCriticalSection(&This->cs);
5378 *ppClock = This->refClock;
5379 if (*ppClock)
5380 IReferenceClock_AddRef(*ppClock);
5382 LeaveCriticalSection(&This->cs);
5384 return S_OK;
5387 static const IMediaFilterVtbl IMediaFilter_VTable =
5389 MediaFilter_QueryInterface,
5390 MediaFilter_AddRef,
5391 MediaFilter_Release,
5392 MediaFilter_GetClassID,
5393 MediaFilter_Stop,
5394 MediaFilter_Pause,
5395 MediaFilter_Run,
5396 MediaFilter_GetState,
5397 MediaFilter_SetSyncSource,
5398 MediaFilter_GetSyncSource
5401 static inline IFilterGraphImpl *impl_from_IMediaEventSink(IMediaEventSink *iface)
5403 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventSink_iface);
5406 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, void **ppv)
5408 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5410 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5413 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5415 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5417 return IUnknown_AddRef(This->outer_unk);
5420 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5422 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5424 return IUnknown_Release(This->outer_unk);
5427 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG EventCode,
5428 LONG_PTR EventParam1, LONG_PTR EventParam2)
5430 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5431 Event evt;
5433 TRACE("(%p/%p)->(%d, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5435 /* We need thread safety here, let's use the events queue's one */
5436 EnterCriticalSection(&This->evqueue.msg_crst);
5438 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5440 TRACE("Process EC_COMPLETE notification\n");
5441 if (++This->EcCompleteCount == This->nRenderers)
5443 evt.lEventCode = EC_COMPLETE;
5444 evt.lParam1 = S_OK;
5445 evt.lParam2 = 0;
5446 TRACE("Send EC_COMPLETE to app\n");
5447 EventsQueue_PutEvent(&This->evqueue, &evt);
5448 if (!This->notif.disabled && This->notif.hWnd)
5450 TRACE("Send Window message\n");
5451 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5453 This->CompletionStatus = EC_COMPLETE;
5454 SetEvent(This->hEventCompletion);
5457 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5459 /* FIXME: Not handled yet */
5461 else
5463 evt.lEventCode = EventCode;
5464 evt.lParam1 = EventParam1;
5465 evt.lParam2 = EventParam2;
5466 EventsQueue_PutEvent(&This->evqueue, &evt);
5467 if (!This->notif.disabled && This->notif.hWnd)
5468 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5471 LeaveCriticalSection(&This->evqueue.msg_crst);
5472 return S_OK;
5475 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5477 MediaEventSink_QueryInterface,
5478 MediaEventSink_AddRef,
5479 MediaEventSink_Release,
5480 MediaEventSink_Notify
5483 static inline IFilterGraphImpl *impl_from_IGraphConfig(IGraphConfig *iface)
5485 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphConfig_iface);
5488 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, void **ppv)
5490 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5492 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5495 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5497 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5499 return IUnknown_AddRef(This->outer_unk);
5502 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5504 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5506 return IUnknown_Release(This->outer_unk);
5509 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *pOutputPin, IPin *pInputPin,
5510 const AM_MEDIA_TYPE *pmtFirstConnection, IBaseFilter *pUsingFilter, HANDLE hAbortEvent,
5511 DWORD dwFlags)
5513 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5515 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5517 return E_NOTIMPL;
5520 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface, IGraphConfigCallback *pCallback,
5521 void *pvContext, DWORD dwFlags, HANDLE hAbortEvent)
5523 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5524 HRESULT hr;
5526 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5528 if (hAbortEvent)
5529 FIXME("The parameter hAbortEvent is not handled!\n");
5531 EnterCriticalSection(&This->cs);
5533 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5535 LeaveCriticalSection(&This->cs);
5537 return hr;
5540 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5542 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5544 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5546 return E_NOTIMPL;
5549 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5551 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5553 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5555 return E_NOTIMPL;
5558 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5560 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5562 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5564 return E_NOTIMPL;
5567 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5569 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5571 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5573 return E_NOTIMPL;
5576 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5577 IPinConnection *pConnection, HANDLE hEventAbort)
5579 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5581 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5583 return E_NOTIMPL;
5586 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5587 DWORD dwFlags)
5589 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5591 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5593 return E_NOTIMPL;
5596 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5597 DWORD *dwFlags)
5599 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5601 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5603 return E_NOTIMPL;
5606 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *pFilter,
5607 DWORD dwFlags)
5609 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5611 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5613 return E_NOTIMPL;
5616 static const IGraphConfigVtbl IGraphConfig_VTable =
5618 GraphConfig_QueryInterface,
5619 GraphConfig_AddRef,
5620 GraphConfig_Release,
5621 GraphConfig_Reconnect,
5622 GraphConfig_Reconfigure,
5623 GraphConfig_AddFilterToCache,
5624 GraphConfig_EnumCacheFilter,
5625 GraphConfig_RemoveFilterFromCache,
5626 GraphConfig_GetStartTime,
5627 GraphConfig_PushThroughData,
5628 GraphConfig_SetFilterFlags,
5629 GraphConfig_GetFilterFlags,
5630 GraphConfig_RemoveFilterEx
5633 static inline IFilterGraphImpl *impl_from_IGraphVersion(IGraphVersion *iface)
5635 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphVersion_iface);
5638 static HRESULT WINAPI GraphVersion_QueryInterface(IGraphVersion *iface, REFIID riid, void **ppv)
5640 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5642 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5645 static ULONG WINAPI GraphVersion_AddRef(IGraphVersion *iface)
5647 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5649 return IUnknown_AddRef(This->outer_unk);
5652 static ULONG WINAPI GraphVersion_Release(IGraphVersion *iface)
5654 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5656 return IUnknown_Release(This->outer_unk);
5659 static HRESULT WINAPI GraphVersion_QueryVersion(IGraphVersion *iface, LONG *pVersion)
5661 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5663 if(!pVersion)
5664 return E_POINTER;
5666 TRACE("(%p)->(%p): current version %i\n", This, pVersion, This->version);
5668 *pVersion = This->version;
5669 return S_OK;
5672 static const IGraphVersionVtbl IGraphVersion_VTable =
5674 GraphVersion_QueryInterface,
5675 GraphVersion_AddRef,
5676 GraphVersion_Release,
5677 GraphVersion_QueryVersion,
5680 static const IUnknownVtbl IInner_VTable =
5682 FilterGraphInner_QueryInterface,
5683 FilterGraphInner_AddRef,
5684 FilterGraphInner_Release
5687 /* This is the only function that actually creates a FilterGraph class... */
5688 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5690 IFilterGraphImpl *fimpl;
5691 HRESULT hr;
5693 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5695 *ppObj = NULL;
5697 fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5698 fimpl->defaultclock = TRUE;
5699 fimpl->IUnknown_inner.lpVtbl = &IInner_VTable;
5700 fimpl->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5701 fimpl->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5702 fimpl->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5703 fimpl->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5704 fimpl->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5705 fimpl->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5706 fimpl->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5707 fimpl->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5708 fimpl->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5709 fimpl->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5710 fimpl->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5711 fimpl->IObjectWithSite_iface.lpVtbl = &IObjectWithSite_VTable;
5712 fimpl->IGraphVersion_iface.lpVtbl = &IGraphVersion_VTable;
5713 fimpl->ref = 1;
5714 fimpl->ppFiltersInGraph = NULL;
5715 fimpl->pFilterNames = NULL;
5716 fimpl->nFilters = 0;
5717 fimpl->filterCapacity = 0;
5718 fimpl->nameIndex = 1;
5719 fimpl->refClock = NULL;
5720 fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5721 fimpl->HandleEcComplete = TRUE;
5722 fimpl->HandleEcRepaint = TRUE;
5723 fimpl->HandleEcClockChanged = TRUE;
5724 fimpl->notif.hWnd = 0;
5725 fimpl->notif.disabled = FALSE;
5726 fimpl->nRenderers = 0;
5727 fimpl->EcCompleteCount = 0;
5728 fimpl->refClockProvider = NULL;
5729 fimpl->state = State_Stopped;
5730 fimpl->pSite = NULL;
5731 EventsQueue_Init(&fimpl->evqueue);
5732 InitializeCriticalSection(&fimpl->cs);
5733 fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5734 fimpl->nItfCacheEntries = 0;
5735 memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5736 fimpl->start_time = fimpl->pause_time = 0;
5737 fimpl->stop_position = -1;
5738 fimpl->punkFilterMapper2 = NULL;
5739 fimpl->recursioncount = 0;
5740 fimpl->version = 0;
5742 if (pUnkOuter)
5743 fimpl->outer_unk = pUnkOuter;
5744 else
5745 fimpl->outer_unk = &fimpl->IUnknown_inner;
5747 /* create Filtermapper aggregated. */
5748 hr = CoCreateInstance(&CLSID_FilterMapper2, fimpl->outer_unk, CLSCTX_INPROC_SERVER,
5749 &IID_IUnknown, (void**)&fimpl->punkFilterMapper2);
5751 if (FAILED(hr)) {
5752 ERR("Unable to create filter mapper (%x)\n", hr);
5753 if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5754 CloseHandle(fimpl->hEventCompletion);
5755 EventsQueue_Destroy(&fimpl->evqueue);
5756 fimpl->cs.DebugInfo->Spare[0] = 0;
5757 DeleteCriticalSection(&fimpl->cs);
5758 CoTaskMemFree(fimpl);
5759 return hr;
5762 *ppObj = &fimpl->IUnknown_inner;
5763 return S_OK;
5766 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5768 FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5769 return FilterGraph_create(pUnkOuter, ppObj);