quartz: Use wine_dbgstr_longlong() to trace REFERENCE_TIME.
[wine.git] / dlls / quartz / filtergraph.c
blobfaf6e513f4c69f72fbdc8d70b146ab2ef33fb7a3
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);
733 if (FAILED(hr)) {
734 TRACE("Querying connected to failed: %x\n", hr);
735 return hr;
737 IPin_Disconnect(ppin);
738 IPin_Disconnect(pConnectedTo);
739 if (pindir == PINDIR_INPUT)
740 hr = IPin_Connect(pConnectedTo, ppin, NULL);
741 else
742 hr = IPin_Connect(ppin, pConnectedTo, NULL);
743 IPin_Release(pConnectedTo);
744 if (FAILED(hr))
745 WARN("Reconnecting pins failed, pins are not connected now..\n");
746 TRACE("(%p->%p) -- %p %p -> %x\n", iface, This, ppin, pConnectedTo, hr);
747 return hr;
750 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
752 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
754 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
756 if (!ppin)
757 return E_POINTER;
759 return IPin_Disconnect(ppin);
762 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
764 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
765 IReferenceClock *pClock = NULL;
766 HRESULT hr = S_OK;
767 int i;
769 TRACE("(%p/%p)->() live sources not handled properly!\n", iface, This);
771 EnterCriticalSection(&This->cs);
773 for (i = 0; i < This->nFilters; ++i)
775 DWORD miscflags;
776 IAMFilterMiscFlags *flags = NULL;
777 IBaseFilter_QueryInterface(This->ppFiltersInGraph[i], &IID_IAMFilterMiscFlags, (void**)&flags);
778 if (!flags)
779 continue;
780 miscflags = IAMFilterMiscFlags_GetMiscFlags(flags);
781 IAMFilterMiscFlags_Release(flags);
782 if (miscflags == AM_FILTER_MISC_FLAGS_IS_RENDERER)
783 IBaseFilter_QueryInterface(This->ppFiltersInGraph[i], &IID_IReferenceClock, (void**)&pClock);
784 if (pClock)
785 break;
788 if (!pClock)
790 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
791 This->refClockProvider = NULL;
793 else
794 This->refClockProvider = This->ppFiltersInGraph[i];
796 if (SUCCEEDED(hr))
798 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
799 This->defaultclock = TRUE;
800 IReferenceClock_Release(pClock);
802 LeaveCriticalSection(&This->cs);
804 return hr;
807 static HRESULT GetFilterInfo(IMoniker* pMoniker, VARIANT* pvar)
809 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
810 IPropertyBag * pPropBagCat = NULL;
811 HRESULT hr;
813 VariantInit(pvar);
815 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
817 if (SUCCEEDED(hr))
818 hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL);
820 if (SUCCEEDED(hr))
821 TRACE("Moniker = %s\n", debugstr_w(V_BSTR(pvar)));
823 if (pPropBagCat)
824 IPropertyBag_Release(pPropBagCat);
826 return hr;
829 static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPin*** pppins, ULONG* pnb)
831 HRESULT hr;
832 ULONG nb = 0;
834 TRACE("(%p, %p, %p, %p)\n", pfilter, pinputpin, pppins, pnb);
835 hr = IPin_QueryInternalConnections(pinputpin, NULL, &nb);
836 if (hr == S_OK) {
837 /* Rendered input */
838 } else if (hr == S_FALSE) {
839 *pppins = CoTaskMemAlloc(sizeof(IPin*)*nb);
840 hr = IPin_QueryInternalConnections(pinputpin, *pppins, &nb);
841 if (hr != S_OK) {
842 WARN("Error (%x)\n", hr);
844 } else if (hr == E_NOTIMPL) {
845 /* Input connected to all outputs */
846 IEnumPins* penumpins;
847 IPin* ppin;
848 int i = 0;
849 TRACE("E_NOTIMPL\n");
850 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
851 if (FAILED(hr)) {
852 WARN("filter Enumpins failed (%x)\n", hr);
853 return hr;
855 i = 0;
856 /* Count output pins */
857 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
858 PIN_DIRECTION pindir;
859 IPin_QueryDirection(ppin, &pindir);
860 if (pindir == PINDIR_OUTPUT)
861 i++;
862 IPin_Release(ppin);
864 *pppins = CoTaskMemAlloc(sizeof(IPin*)*i);
865 /* Retrieve output pins */
866 IEnumPins_Reset(penumpins);
867 i = 0;
868 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
869 PIN_DIRECTION pindir;
870 IPin_QueryDirection(ppin, &pindir);
871 if (pindir == PINDIR_OUTPUT)
872 (*pppins)[i++] = ppin;
873 else
874 IPin_Release(ppin);
876 IEnumPins_Release(penumpins);
877 nb = i;
878 if (FAILED(hr)) {
879 WARN("Next failed (%x)\n", hr);
880 return hr;
882 } else if (FAILED(hr)) {
883 WARN("Cannot get internal connection (%x)\n", hr);
884 return hr;
887 *pnb = nb;
888 return S_OK;
891 /*** IGraphBuilder methods ***/
892 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IPin *ppinIn)
894 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
895 HRESULT hr;
896 AM_MEDIA_TYPE* mt = NULL;
897 IEnumMediaTypes* penummt = NULL;
898 ULONG nbmt;
899 IEnumPins* penumpins;
900 IEnumMoniker* pEnumMoniker;
901 GUID tab[2];
902 ULONG nb = 0;
903 IMoniker* pMoniker;
904 ULONG pin;
905 PIN_INFO PinInfo;
906 CLSID FilterCLSID;
907 PIN_DIRECTION dir;
908 unsigned int i = 0;
909 IFilterMapper2 *pFilterMapper2 = NULL;
911 TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
913 if(!ppinOut || !ppinIn)
914 return E_POINTER;
916 if (TRACE_ON(quartz))
918 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
919 if (FAILED(hr))
920 return hr;
922 TRACE("Filter owning ppinIn(%p) => %p\n", ppinIn, PinInfo.pFilter);
923 IBaseFilter_Release(PinInfo.pFilter);
925 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
926 if (FAILED(hr))
927 return hr;
929 TRACE("Filter owning ppinOut(%p) => %p\n", ppinOut, PinInfo.pFilter);
930 IBaseFilter_Release(PinInfo.pFilter);
933 EnterCriticalSection(&This->cs);
934 ++This->recursioncount;
935 if (This->recursioncount >= 5)
937 WARN("Recursion count has reached %d\n", This->recursioncount);
938 hr = VFW_E_CANNOT_CONNECT;
939 goto out;
942 hr = IPin_QueryDirection(ppinOut, &dir);
943 if (FAILED(hr))
944 goto out;
946 if (dir == PINDIR_INPUT)
948 IPin *temp;
950 TRACE("Directions seem backwards, swapping pins\n");
952 temp = ppinIn;
953 ppinIn = ppinOut;
954 ppinOut = temp;
957 hr = CheckCircularConnection(This, ppinOut, ppinIn);
958 if (FAILED(hr))
959 goto out;
961 /* Try direct connection first */
962 hr = IPin_Connect(ppinOut, ppinIn, NULL);
963 if (SUCCEEDED(hr))
964 goto out;
966 TRACE("Direct connection failed, trying to render using extra filters\n");
968 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
969 if (FAILED(hr))
970 goto out;
972 hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
973 IBaseFilter_Release(PinInfo.pFilter);
974 if (FAILED(hr))
975 goto out;
977 /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream
978 * filter to the minor mediatype of input pin of the renderer */
979 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
980 if (FAILED(hr))
982 WARN("EnumMediaTypes (%x)\n", hr);
983 goto out;
986 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
987 if (FAILED(hr)) {
988 WARN("IEnumMediaTypes_Next (%x)\n", hr);
989 goto out;
992 if (!nbmt)
994 WARN("No media type found!\n");
995 hr = VFW_E_INVALIDMEDIATYPE;
996 goto out;
998 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
999 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1001 hr = IUnknown_QueryInterface(This->punkFilterMapper2, &IID_IFilterMapper2, (void**)&pFilterMapper2);
1002 if (FAILED(hr)) {
1003 WARN("Unable to get IFilterMapper2 (%x)\n", hr);
1004 goto out;
1007 /* Try to find a suitable filter that can connect to the pin to render */
1008 tab[0] = mt->majortype;
1009 tab[1] = mt->subtype;
1010 hr = IFilterMapper2_EnumMatchingFilters(pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1011 if (FAILED(hr)) {
1012 WARN("Unable to enum filters (%x)\n", hr);
1013 goto out;
1016 hr = VFW_E_CANNOT_RENDER;
1017 while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1019 VARIANT var;
1020 GUID clsid;
1021 IPin** ppins = NULL;
1022 IPin* ppinfilter = NULL;
1023 IBaseFilter* pfilter = NULL;
1024 IAMGraphBuilderCallback *callback = NULL;
1026 hr = GetFilterInfo(pMoniker, &var);
1027 if (FAILED(hr)) {
1028 WARN("Unable to retrieve filter info (%x)\n", hr);
1029 goto error;
1032 hr = IMoniker_BindToObject(pMoniker, NULL, NULL, &IID_IBaseFilter, (LPVOID*)&pfilter);
1033 IMoniker_Release(pMoniker);
1034 if (FAILED(hr)) {
1035 WARN("Unable to create filter (%x), trying next one\n", hr);
1036 goto error;
1039 hr = IBaseFilter_GetClassID(pfilter, &clsid);
1040 if (FAILED(hr))
1042 IBaseFilter_Release(pfilter);
1043 goto error;
1046 if (IsEqualGUID(&clsid, &FilterCLSID)) {
1047 /* Skip filter (same as the one the output pin belongs to) */
1048 IBaseFilter_Release(pfilter);
1049 goto error;
1052 if (This->pSite)
1054 IUnknown_QueryInterface(This->pSite, &IID_IAMGraphBuilderCallback, (LPVOID*)&callback);
1055 if (callback)
1057 HRESULT rc;
1058 rc = IAMGraphBuilderCallback_SelectedFilter(callback, pMoniker);
1059 if (FAILED(rc))
1061 TRACE("Filter rejected by IAMGraphBuilderCallback_SelectedFilter\n");
1062 IAMGraphBuilderCallback_Release(callback);
1063 goto error;
1068 if (callback)
1070 HRESULT rc;
1071 rc = IAMGraphBuilderCallback_CreatedFilter(callback, pfilter);
1072 IAMGraphBuilderCallback_Release(callback);
1073 if (FAILED(rc))
1075 IBaseFilter_Release(pfilter);
1076 pfilter = NULL;
1077 TRACE("Filter rejected by IAMGraphBuilderCallback_CreatedFilter\n");
1078 goto error;
1082 hr = IFilterGraph2_AddFilter(iface, pfilter, V_BSTR(&var));
1083 if (FAILED(hr)) {
1084 WARN("Unable to add filter (%x)\n", hr);
1085 IBaseFilter_Release(pfilter);
1086 pfilter = NULL;
1087 goto error;
1090 VariantClear(&var);
1092 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1093 if (FAILED(hr)) {
1094 WARN("Enumpins (%x)\n", hr);
1095 goto error;
1098 hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin);
1099 IEnumPins_Release(penumpins);
1101 if (FAILED(hr)) {
1102 WARN("Obtaining next pin: (%x)\n", hr);
1103 goto error;
1105 if (pin == 0) {
1106 WARN("Cannot use this filter: no pins\n");
1107 goto error;
1110 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1111 if (FAILED(hr)) {
1112 TRACE("Cannot connect to filter (%x), trying next one\n", hr);
1113 goto error;
1115 TRACE("Successfully connected to filter, follow chain...\n");
1117 /* Render all output pins of the filter by calling IFilterGraph2_Connect on each of them */
1118 hr = GetInternalConnections(pfilter, ppinfilter, &ppins, &nb);
1120 if (SUCCEEDED(hr)) {
1121 if (nb == 0) {
1122 IPin_Disconnect(ppinfilter);
1123 IPin_Disconnect(ppinOut);
1124 goto error;
1126 TRACE("pins to consider: %d\n", nb);
1127 for(i = 0; i < nb; i++)
1129 LPWSTR pinname = NULL;
1131 TRACE("Processing pin %u\n", i);
1133 hr = IPin_QueryId(ppins[i], &pinname);
1134 if (SUCCEEDED(hr))
1136 if (pinname[0] == '~')
1138 TRACE("Pinname=%s, skipping\n", debugstr_w(pinname));
1139 hr = E_FAIL;
1141 else
1142 hr = IFilterGraph2_Connect(iface, ppins[i], ppinIn);
1143 CoTaskMemFree(pinname);
1146 if (FAILED(hr)) {
1147 TRACE("Cannot connect pin %p (%x)\n", ppinfilter, hr);
1149 IPin_Release(ppins[i]);
1150 if (SUCCEEDED(hr)) break;
1152 while (++i < nb) IPin_Release(ppins[i]);
1153 CoTaskMemFree(ppins);
1154 IPin_Release(ppinfilter);
1155 IBaseFilter_Release(pfilter);
1156 if (FAILED(hr))
1158 IPin_Disconnect(ppinfilter);
1159 IPin_Disconnect(ppinOut);
1160 IFilterGraph2_RemoveFilter(iface, pfilter);
1161 continue;
1163 break;
1166 error:
1167 VariantClear(&var);
1168 if (ppinfilter) IPin_Release(ppinfilter);
1169 if (pfilter) {
1170 IFilterGraph2_RemoveFilter(iface, pfilter);
1171 IBaseFilter_Release(pfilter);
1173 while (++i < nb) IPin_Release(ppins[i]);
1174 CoTaskMemFree(ppins);
1177 IEnumMoniker_Release(pEnumMoniker);
1179 out:
1180 if (pFilterMapper2)
1181 IFilterMapper2_Release(pFilterMapper2);
1182 if (penummt)
1183 IEnumMediaTypes_Release(penummt);
1184 if (mt)
1185 DeleteMediaType(mt);
1186 --This->recursioncount;
1187 LeaveCriticalSection(&This->cs);
1188 TRACE("--> %08x\n", hr);
1189 return SUCCEEDED(hr) ? S_OK : hr;
1192 static HRESULT FilterGraph2_RenderRecurse(IFilterGraphImpl *This, IPin *ppinOut)
1194 /* This pin has been connected now, try to call render on all pins that aren't connected */
1195 IPin *to = NULL;
1196 PIN_INFO info;
1197 IEnumPins *enumpins = NULL;
1198 BOOL renderany = FALSE;
1199 BOOL renderall = TRUE;
1201 IPin_QueryPinInfo(ppinOut, &info);
1203 IBaseFilter_EnumPins(info.pFilter, &enumpins);
1204 /* Don't need to hold a reference, IEnumPins does */
1205 IBaseFilter_Release(info.pFilter);
1207 IEnumPins_Reset(enumpins);
1208 while (IEnumPins_Next(enumpins, 1, &to, NULL) == S_OK)
1210 PIN_DIRECTION dir = PINDIR_INPUT;
1212 IPin_QueryDirection(to, &dir);
1214 if (dir == PINDIR_OUTPUT)
1216 IPin *out = NULL;
1218 IPin_ConnectedTo(to, &out);
1219 if (!out)
1221 HRESULT hr;
1222 hr = IFilterGraph2_Render(&This->IFilterGraph2_iface, to);
1223 if (SUCCEEDED(hr))
1224 renderany = TRUE;
1225 else
1226 renderall = FALSE;
1228 else
1229 IPin_Release(out);
1232 IPin_Release(to);
1235 IEnumPins_Release(enumpins);
1237 if (renderall)
1238 return S_OK;
1240 if (renderany)
1241 return VFW_S_PARTIAL_RENDER;
1243 return VFW_E_CANNOT_RENDER;
1246 /* Ogg hates me if I create a direct rendering method
1248 * It can only connect to a pin properly once, so use a recursive method that does
1250 * +----+ --- (PIN 1) (Render is called on this pin)
1251 * | |
1252 * +----+ --- (PIN 2)
1254 * Enumerate possible renderers that EXACTLY match the requested type
1256 * If none is available, try to add intermediate filters that can connect to the input pin
1257 * then call Render on that intermediate pin's output pins
1258 * if it succeeds: Render returns success, if it doesn't, the intermediate filter is removed,
1259 * and another filter that can connect to the input pin is tried
1260 * if we run out of filters that can, give up and return VFW_E_CANNOT_RENDER
1261 * It's recursive, but fun!
1264 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *ppinOut)
1266 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1267 IEnumMediaTypes* penummt;
1268 AM_MEDIA_TYPE* mt;
1269 ULONG nbmt;
1270 HRESULT hr;
1272 IEnumMoniker* pEnumMoniker;
1273 GUID tab[4];
1274 ULONG nb;
1275 IMoniker* pMoniker;
1276 INT x;
1277 IFilterMapper2 *pFilterMapper2 = NULL;
1279 TRACE("(%p/%p)->(%p)\n", This, iface, ppinOut);
1281 if (TRACE_ON(quartz))
1283 PIN_INFO PinInfo;
1285 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
1286 if (FAILED(hr))
1287 return hr;
1289 TRACE("Filter owning pin => %p\n", PinInfo.pFilter);
1290 IBaseFilter_Release(PinInfo.pFilter);
1293 /* Try to find out if there is a renderer for the specified subtype already, and use that
1295 EnterCriticalSection(&This->cs);
1296 for (x = 0; x < This->nFilters; ++x)
1298 IEnumPins *enumpins = NULL;
1299 IPin *pin = NULL;
1301 hr = IBaseFilter_EnumPins(This->ppFiltersInGraph[x], &enumpins);
1303 if (FAILED(hr) || !enumpins)
1304 continue;
1306 IEnumPins_Reset(enumpins);
1307 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
1309 IPin *to = NULL;
1310 PIN_DIRECTION dir = PINDIR_OUTPUT;
1312 IPin_QueryDirection(pin, &dir);
1313 if (dir != PINDIR_INPUT)
1315 IPin_Release(pin);
1316 continue;
1318 IPin_ConnectedTo(pin, &to);
1320 if (to == NULL)
1322 hr = FilterGraph2_ConnectDirect(iface, ppinOut, pin, NULL);
1323 if (SUCCEEDED(hr))
1325 TRACE("Connected successfully %p/%p, %08x look if we should render more!\n", ppinOut, pin, hr);
1326 IPin_Release(pin);
1328 hr = FilterGraph2_RenderRecurse(This, pin);
1329 if (FAILED(hr))
1331 IPin_Disconnect(ppinOut);
1332 IPin_Disconnect(pin);
1333 continue;
1335 IEnumPins_Release(enumpins);
1336 LeaveCriticalSection(&This->cs);
1337 return hr;
1339 WARN("Could not connect!\n");
1341 else
1342 IPin_Release(to);
1344 IPin_Release(pin);
1346 IEnumPins_Release(enumpins);
1349 LeaveCriticalSection(&This->cs);
1351 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
1352 if (FAILED(hr)) {
1353 WARN("EnumMediaTypes (%x)\n", hr);
1354 return hr;
1357 IEnumMediaTypes_Reset(penummt);
1359 /* Looks like no existing renderer of the kind exists
1360 * Try adding new ones
1362 tab[0] = tab[1] = GUID_NULL;
1363 while (SUCCEEDED(hr))
1365 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
1366 if (FAILED(hr)) {
1367 WARN("IEnumMediaTypes_Next (%x)\n", hr);
1368 break;
1370 if (!nbmt)
1372 hr = VFW_E_CANNOT_RENDER;
1373 break;
1375 else
1377 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1378 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1380 /* Only enumerate once, this doesn't account for all previous ones, but this should be enough nonetheless */
1381 if (IsEqualIID(&tab[0], &mt->majortype) && IsEqualIID(&tab[1], &mt->subtype))
1383 DeleteMediaType(mt);
1384 continue;
1387 if (pFilterMapper2 == NULL)
1389 hr = IUnknown_QueryInterface(This->punkFilterMapper2, &IID_IFilterMapper2, (void**)&pFilterMapper2);
1390 if (FAILED(hr))
1392 WARN("Unable to query IFilterMapper2 (%x)\n", hr);
1393 break;
1397 /* Try to find a suitable renderer with the same media type */
1398 tab[0] = mt->majortype;
1399 tab[1] = mt->subtype;
1400 hr = IFilterMapper2_EnumMatchingFilters(pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1401 if (FAILED(hr))
1403 WARN("Unable to enum filters (%x)\n", hr);
1404 break;
1407 hr = E_FAIL;
1409 while (IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1411 VARIANT var;
1412 IPin* ppinfilter;
1413 IBaseFilter* pfilter = NULL;
1414 IEnumPins* penumpins = NULL;
1415 ULONG pin;
1417 hr = GetFilterInfo(pMoniker, &var);
1418 if (FAILED(hr)) {
1419 WARN("Unable to retrieve filter info (%x)\n", hr);
1420 goto error;
1423 hr = IMoniker_BindToObject(pMoniker, NULL, NULL, &IID_IBaseFilter, (LPVOID*)&pfilter);
1424 IMoniker_Release(pMoniker);
1425 if (FAILED(hr))
1427 WARN("Unable to create filter (%x), trying next one\n", hr);
1428 goto error;
1431 hr = IFilterGraph2_AddFilter(iface, pfilter, V_BSTR(&var));
1432 if (FAILED(hr)) {
1433 WARN("Unable to add filter (%x)\n", hr);
1434 IBaseFilter_Release(pfilter);
1435 pfilter = NULL;
1436 goto error;
1439 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1440 if (FAILED(hr)) {
1441 WARN("Splitter Enumpins (%x)\n", hr);
1442 goto error;
1445 while ((hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin)) == S_OK)
1447 PIN_DIRECTION dir;
1449 if (pin == 0) {
1450 WARN("No Pin\n");
1451 hr = E_FAIL;
1452 goto error;
1455 hr = IPin_QueryDirection(ppinfilter, &dir);
1456 if (FAILED(hr)) {
1457 IPin_Release(ppinfilter);
1458 WARN("QueryDirection failed (%x)\n", hr);
1459 goto error;
1461 if (dir != PINDIR_INPUT) {
1462 IPin_Release(ppinfilter);
1463 continue; /* Wrong direction */
1466 /* Connect the pin to the "Renderer" */
1467 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1468 IPin_Release(ppinfilter);
1470 if (FAILED(hr)) {
1471 WARN("Unable to connect %s to renderer (%x)\n", debugstr_w(V_BSTR(&var)), hr);
1472 goto error;
1474 TRACE("Connected, recursing %s\n", debugstr_w(V_BSTR(&var)));
1476 VariantClear(&var);
1478 hr = FilterGraph2_RenderRecurse(This, ppinfilter);
1479 if (FAILED(hr)) {
1480 WARN("Unable to connect recursively (%x)\n", hr);
1481 goto error;
1483 IBaseFilter_Release(pfilter);
1484 break;
1486 if (SUCCEEDED(hr)) {
1487 IEnumPins_Release(penumpins);
1488 break; /* out of IEnumMoniker_Next loop */
1491 /* IEnumPins_Next failed, all other failure case caught by goto error */
1492 WARN("IEnumPins_Next (%x)\n", hr);
1493 /* goto error */
1495 error:
1496 VariantClear(&var);
1497 if (penumpins)
1498 IEnumPins_Release(penumpins);
1499 if (pfilter) {
1500 IFilterGraph2_RemoveFilter(iface, pfilter);
1501 IBaseFilter_Release(pfilter);
1503 if (SUCCEEDED(hr)) DebugBreak();
1506 IEnumMoniker_Release(pEnumMoniker);
1507 if (nbmt)
1508 DeleteMediaType(mt);
1509 if (SUCCEEDED(hr))
1510 break;
1511 hr = S_OK;
1514 if (pFilterMapper2)
1515 IFilterMapper2_Release(pFilterMapper2);
1517 IEnumMediaTypes_Release(penummt);
1518 return hr;
1521 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface, LPCWSTR lpcwstrFile,
1522 LPCWSTR lpcwstrPlayList)
1524 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1525 static const WCHAR string[] = {'R','e','a','d','e','r',0};
1526 IBaseFilter* preader = NULL;
1527 IPin* ppinreader = NULL;
1528 IEnumPins* penumpins = NULL;
1529 HRESULT hr;
1530 BOOL partial = FALSE;
1531 BOOL any = FALSE;
1533 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1535 if (lpcwstrPlayList != NULL)
1536 return E_INVALIDARG;
1538 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, string, &preader);
1539 if (FAILED(hr))
1540 return hr;
1542 if (SUCCEEDED(hr))
1543 hr = IBaseFilter_EnumPins(preader, &penumpins);
1544 if (SUCCEEDED(hr))
1546 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1548 PIN_DIRECTION dir;
1550 IPin_QueryDirection(ppinreader, &dir);
1551 if (dir == PINDIR_OUTPUT)
1553 INT i;
1555 hr = IFilterGraph2_Render(iface, ppinreader);
1556 TRACE("Render %08x\n", hr);
1558 for (i = 0; i < This->nFilters; ++i)
1559 TRACE("Filters in chain: %s\n", debugstr_w(This->pFilterNames[i]));
1561 if (SUCCEEDED(hr))
1562 any = TRUE;
1563 if (hr != S_OK)
1564 partial = TRUE;
1566 IPin_Release(ppinreader);
1568 IEnumPins_Release(penumpins);
1570 if (!any)
1571 hr = VFW_E_CANNOT_RENDER;
1572 else if (partial)
1573 hr = VFW_S_PARTIAL_RENDER;
1574 else
1575 hr = S_OK;
1577 IBaseFilter_Release(preader);
1579 TRACE("--> %08x\n", hr);
1580 return hr;
1583 static HRESULT CreateFilterInstanceAndLoadFile(GUID* clsid, LPCOLESTR pszFileName, IBaseFilter **filter)
1585 IFileSourceFilter *source = NULL;
1586 HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1587 TRACE("CLSID: %s\n", debugstr_guid(clsid));
1588 if (FAILED(hr))
1589 return hr;
1591 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID*)&source);
1592 if (FAILED(hr))
1594 IBaseFilter_Release(*filter);
1595 return hr;
1598 /* Load the file in the file source filter */
1599 hr = IFileSourceFilter_Load(source, pszFileName, NULL);
1600 IFileSourceFilter_Release(source);
1601 if (FAILED(hr)) {
1602 WARN("Load (%x)\n", hr);
1603 IBaseFilter_Release(*filter);
1604 return hr;
1607 return hr;
1610 /* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
1611 static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
1613 HRESULT hr;
1614 GUID clsid;
1615 IAsyncReader * pReader = NULL;
1616 IFileSourceFilter* pSource = NULL;
1617 IPin * pOutputPin = NULL;
1618 static const WCHAR wszOutputPinName[] = { 'O','u','t','p','u','t',0 };
1620 /* Try to find a match without reading the file first */
1621 hr = GetClassMediaFile(NULL, pszFileName, NULL, NULL, &clsid);
1623 if (hr == S_OK)
1624 return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
1626 /* Now create a AyncReader instance, to check for signature bytes in the file */
1627 hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1628 if (FAILED(hr))
1629 return hr;
1631 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID *)&pSource);
1632 if (FAILED(hr))
1634 IBaseFilter_Release(*filter);
1635 return hr;
1638 hr = IFileSourceFilter_Load(pSource, pszFileName, NULL);
1639 IFileSourceFilter_Release(pSource);
1640 if (FAILED(hr))
1642 IBaseFilter_Release(*filter);
1643 return hr;
1646 hr = IBaseFilter_FindPin(*filter, wszOutputPinName, &pOutputPin);
1647 if (FAILED(hr))
1649 IBaseFilter_Release(*filter);
1650 return hr;
1653 hr = IPin_QueryInterface(pOutputPin, &IID_IAsyncReader, (LPVOID *)&pReader);
1654 IPin_Release(pOutputPin);
1655 if (FAILED(hr))
1657 IBaseFilter_Release(*filter);
1658 return hr;
1661 /* Try again find a match */
1662 hr = GetClassMediaFile(pReader, pszFileName, NULL, NULL, &clsid);
1663 IAsyncReader_Release(pReader);
1665 if (hr == S_OK)
1667 /* Release the AsyncReader filter and create the matching one */
1668 IBaseFilter_Release(*filter);
1669 return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
1672 /* Return the AsyncReader filter */
1673 return S_OK;
1676 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface, LPCWSTR lpcwstrFileName,
1677 LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1679 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1680 HRESULT hr;
1681 IBaseFilter* preader;
1682 IFileSourceFilter* pfile = NULL;
1683 AM_MEDIA_TYPE mt;
1684 WCHAR* filename;
1686 TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1688 /* Try from file name first, then fall back to default asynchronous reader */
1689 hr = GetFileSourceFilter(lpcwstrFileName, &preader);
1690 if (FAILED(hr)) {
1691 WARN("Unable to create file source filter (%x)\n", hr);
1692 return hr;
1695 hr = IFilterGraph2_AddFilter(iface, preader, lpcwstrFilterName);
1696 if (FAILED(hr)) {
1697 WARN("Unable add filter (%x)\n", hr);
1698 IBaseFilter_Release(preader);
1699 return hr;
1702 hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1703 if (FAILED(hr)) {
1704 WARN("Unable to get IFileSourceInterface (%x)\n", hr);
1705 goto error;
1708 /* The file has been already loaded */
1709 hr = IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1710 if (FAILED(hr)) {
1711 WARN("GetCurFile (%x)\n", hr);
1712 goto error;
1715 TRACE("File %s\n", debugstr_w(filename));
1716 TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
1717 TRACE("SubType %s\n", debugstr_guid(&mt.subtype));
1719 if (ppFilter)
1720 *ppFilter = preader;
1721 IFileSourceFilter_Release(pfile);
1723 return S_OK;
1725 error:
1726 if (pfile)
1727 IFileSourceFilter_Release(pfile);
1728 IFilterGraph2_RemoveFilter(iface, preader);
1729 IBaseFilter_Release(preader);
1731 return hr;
1734 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR hFile)
1736 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1738 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1740 return S_OK;
1743 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1745 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1747 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1749 return S_OK;
1752 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1754 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1756 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1758 return S_OK;
1761 /*** IFilterGraph2 methods ***/
1762 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1763 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1765 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1766 HRESULT hr;
1767 IBaseFilter* pfilter;
1769 TRACE("(%p/%p)->(%p %p %s %p)\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1771 hr = IMoniker_BindToObject(pMoniker, pCtx, NULL, &IID_IBaseFilter, (void**)&pfilter);
1772 if(FAILED(hr)) {
1773 WARN("Unable to bind moniker to filter object (%x)\n", hr);
1774 return hr;
1777 hr = IFilterGraph2_AddFilter(iface, pfilter, lpcwstrFilterName);
1778 if (FAILED(hr)) {
1779 WARN("Unable to add filter (%x)\n", hr);
1780 IBaseFilter_Release(pfilter);
1781 return hr;
1784 if(ppFilter)
1785 *ppFilter = pfilter;
1786 else IBaseFilter_Release(pfilter);
1788 return S_OK;
1791 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *ppin,
1792 const AM_MEDIA_TYPE *pmt)
1794 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1796 TRACE("(%p/%p)->(%p %p): stub !!!\n", This, iface, ppin, pmt);
1798 return S_OK;
1801 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *pPinOut, DWORD dwFlags,
1802 DWORD *pvContext)
1804 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1806 TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This, iface, pPinOut, dwFlags, pvContext);
1808 return S_OK;
1812 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1814 FilterGraph2_QueryInterface,
1815 FilterGraph2_AddRef,
1816 FilterGraph2_Release,
1817 FilterGraph2_AddFilter,
1818 FilterGraph2_RemoveFilter,
1819 FilterGraph2_EnumFilters,
1820 FilterGraph2_FindFilterByName,
1821 FilterGraph2_ConnectDirect,
1822 FilterGraph2_Reconnect,
1823 FilterGraph2_Disconnect,
1824 FilterGraph2_SetDefaultSyncSource,
1825 FilterGraph2_Connect,
1826 FilterGraph2_Render,
1827 FilterGraph2_RenderFile,
1828 FilterGraph2_AddSourceFilter,
1829 FilterGraph2_SetLogFile,
1830 FilterGraph2_Abort,
1831 FilterGraph2_ShouldOperationContinue,
1832 FilterGraph2_AddSourceFilterForMoniker,
1833 FilterGraph2_ReconnectEx,
1834 FilterGraph2_RenderEx
1837 static inline IFilterGraphImpl *impl_from_IMediaControl(IMediaControl *iface)
1839 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaControl_iface);
1842 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID riid, void **ppvObj)
1844 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1846 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
1848 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
1851 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1853 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1855 TRACE("(%p/%p)->()\n", This, iface);
1857 return IUnknown_AddRef(This->outer_unk);
1860 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1862 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1864 TRACE("(%p/%p)->()\n", This, iface);
1866 return IUnknown_Release(This->outer_unk);
1870 /*** IDispatch methods ***/
1871 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *pctinfo)
1873 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1875 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1877 return S_OK;
1880 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT iTInfo, LCID lcid,
1881 ITypeInfo **ppTInfo)
1883 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1885 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1887 return S_OK;
1890 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID riid,
1891 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1893 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1895 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
1896 cNames, lcid, rgDispId);
1898 return S_OK;
1901 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID dispIdMember, REFIID riid,
1902 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
1903 UINT *puArgErr)
1905 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1907 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
1908 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
1910 return S_OK;
1913 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *, DWORD_PTR data);
1915 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter, DWORD_PTR data)
1917 HRESULT hr;
1918 IPin* pInputPin;
1919 IPin** ppPins;
1920 ULONG nb;
1921 ULONG i;
1922 PIN_INFO PinInfo;
1924 TRACE("%p %p\n", pGraph, pOutputPin);
1925 PinInfo.pFilter = NULL;
1927 hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1929 if (SUCCEEDED(hr))
1931 hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1932 if (SUCCEEDED(hr))
1933 hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1934 IPin_Release(pInputPin);
1937 if (SUCCEEDED(hr))
1939 if (nb == 0)
1941 TRACE("Reached a renderer\n");
1942 /* Count renderers for end of stream notification */
1943 pGraph->nRenderers++;
1945 else
1947 for(i = 0; i < nb; i++)
1949 /* Explore the graph downstream from this pin
1950 * FIXME: We should prevent exploring from a pin more than once. This can happens when
1951 * several input pins are connected to the same output (a MUX for instance). */
1952 ExploreGraph(pGraph, ppPins[i], FoundFilter, data);
1953 IPin_Release(ppPins[i]);
1956 CoTaskMemFree(ppPins);
1958 TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1960 FoundFilter(PinInfo.pFilter, data);
1963 if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1964 return hr;
1967 static HRESULT WINAPI SendRun(IBaseFilter *pFilter, DWORD_PTR data)
1969 REFERENCE_TIME time = *(REFERENCE_TIME*)data;
1970 return IBaseFilter_Run(pFilter, time);
1973 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1975 return IBaseFilter_Pause(pFilter);
1978 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1980 return IBaseFilter_Stop(pFilter);
1983 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1985 FILTER_STATE state;
1986 DWORD time_end = data;
1987 DWORD time_now = GetTickCount();
1988 LONG wait;
1990 if (time_end == INFINITE)
1992 wait = INFINITE;
1994 else if (time_end > time_now)
1996 wait = time_end - time_now;
1998 else
1999 wait = 0;
2001 return IBaseFilter_GetState(pFilter, wait, &state);
2005 static HRESULT SendFilterMessage(IFilterGraphImpl *This, fnFoundFilter FoundFilter, DWORD_PTR data)
2007 int i;
2008 IBaseFilter* pfilter;
2009 IEnumPins* pEnum;
2010 HRESULT hr;
2011 IPin* pPin;
2012 DWORD dummy;
2013 PIN_DIRECTION dir;
2015 TRACE("(%p)->()\n", This);
2017 /* Explorer the graph from source filters to renderers, determine renderers
2018 * number and run filters from renderers to source filters */
2019 This->nRenderers = 0;
2020 ResetEvent(This->hEventCompletion);
2022 for(i = 0; i < This->nFilters; i++)
2024 BOOL source = TRUE;
2025 pfilter = This->ppFiltersInGraph[i];
2026 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
2027 if (hr != S_OK)
2029 WARN("Enum pins failed %x\n", hr);
2030 continue;
2032 /* Check if it is a source filter */
2033 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2035 IPin_QueryDirection(pPin, &dir);
2036 IPin_Release(pPin);
2037 if (dir == PINDIR_INPUT)
2039 source = FALSE;
2040 break;
2043 if (source)
2045 TRACE("Found a source filter %p\n", pfilter);
2046 IEnumPins_Reset(pEnum);
2047 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2049 /* Explore the graph downstream from this pin */
2050 ExploreGraph(This, pPin, FoundFilter, data);
2051 IPin_Release(pPin);
2053 FoundFilter(pfilter, data);
2055 IEnumPins_Release(pEnum);
2058 return S_FALSE;
2061 /*** IMediaControl methods ***/
2062 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
2064 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2066 TRACE("(%p/%p)->()\n", This, iface);
2068 EnterCriticalSection(&This->cs);
2069 if (This->state == State_Running)
2070 goto out;
2071 This->EcCompleteCount = 0;
2073 if (This->defaultclock && !This->refClock)
2074 IFilterGraph2_SetDefaultSyncSource(&This->IFilterGraph2_iface);
2076 if (This->refClock)
2078 REFERENCE_TIME now;
2079 IReferenceClock_GetTime(This->refClock, &now);
2080 if (This->state == State_Stopped)
2081 This->start_time = now + 500000;
2082 else if (This->pause_time >= 0)
2083 This->start_time += now - This->pause_time;
2084 else
2085 This->start_time = now;
2087 else This->start_time = 0;
2089 SendFilterMessage(This, SendRun, (DWORD_PTR)&This->start_time);
2090 This->state = State_Running;
2091 out:
2092 LeaveCriticalSection(&This->cs);
2093 return S_FALSE;
2096 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
2098 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2100 TRACE("(%p/%p)->()\n", This, iface);
2102 EnterCriticalSection(&This->cs);
2103 if (This->state == State_Paused)
2104 goto out;
2106 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2107 IReferenceClock_GetTime(This->refClock, &This->pause_time);
2108 else
2109 This->pause_time = -1;
2111 SendFilterMessage(This, SendPause, 0);
2112 This->state = State_Paused;
2113 out:
2114 LeaveCriticalSection(&This->cs);
2115 return S_FALSE;
2118 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
2120 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2122 TRACE("(%p/%p)->()\n", This, iface);
2124 if (This->state == State_Stopped) return S_OK;
2126 EnterCriticalSection(&This->cs);
2127 if (This->state == State_Running) SendFilterMessage(This, SendPause, 0);
2128 SendFilterMessage(This, SendStop, 0);
2129 This->state = State_Stopped;
2130 LeaveCriticalSection(&This->cs);
2131 return S_OK;
2134 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG msTimeout,
2135 OAFilterState *pfs)
2137 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2138 DWORD end;
2140 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
2142 if (!pfs)
2143 return E_POINTER;
2145 EnterCriticalSection(&This->cs);
2147 *pfs = This->state;
2148 if (msTimeout > 0)
2150 end = GetTickCount() + msTimeout;
2152 else if (msTimeout < 0)
2154 end = INFINITE;
2156 else
2158 end = 0;
2160 if (end)
2161 SendFilterMessage(This, SendGetState, end);
2163 LeaveCriticalSection(&This->cs);
2165 return S_OK;
2168 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
2170 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2172 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strFilename), strFilename);
2174 return IFilterGraph2_RenderFile(&This->IFilterGraph2_iface, strFilename, NULL);
2177 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
2178 IDispatch **ppUnk)
2180 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2182 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2184 return S_OK;
2187 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2189 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2191 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2193 return S_OK;
2196 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2198 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2200 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2202 return S_OK;
2205 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
2207 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2209 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2211 return S_OK;
2215 static const IMediaControlVtbl IMediaControl_VTable =
2217 MediaControl_QueryInterface,
2218 MediaControl_AddRef,
2219 MediaControl_Release,
2220 MediaControl_GetTypeInfoCount,
2221 MediaControl_GetTypeInfo,
2222 MediaControl_GetIDsOfNames,
2223 MediaControl_Invoke,
2224 MediaControl_Run,
2225 MediaControl_Pause,
2226 MediaControl_Stop,
2227 MediaControl_GetState,
2228 MediaControl_RenderFile,
2229 MediaControl_AddSourceFilter,
2230 MediaControl_get_FilterCollection,
2231 MediaControl_get_RegFilterCollection,
2232 MediaControl_StopWhenReady
2235 static inline IFilterGraphImpl *impl_from_IMediaSeeking(IMediaSeeking *iface)
2237 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaSeeking_iface);
2240 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID riid, void **ppvObj)
2242 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2244 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
2246 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2249 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2251 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2253 TRACE("(%p/%p)->()\n", This, iface);
2255 return IUnknown_AddRef(This->outer_unk);
2258 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2260 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2262 TRACE("(%p/%p)->()\n", This, iface);
2264 return IUnknown_Release(This->outer_unk);
2267 typedef HRESULT (WINAPI *fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
2269 static HRESULT all_renderers_seek(IFilterGraphImpl *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2270 BOOL allnotimpl = TRUE;
2271 int i;
2272 HRESULT hr, hr_return = S_OK;
2274 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2275 /* Send a message to all renderers, they are responsible for broadcasting it further */
2277 for(i = 0; i < This->nFilters; i++)
2279 IMediaSeeking *seek = NULL;
2280 IBaseFilter* pfilter = This->ppFiltersInGraph[i];
2281 IAMFilterMiscFlags *flags = NULL;
2282 ULONG filterflags;
2283 IBaseFilter_QueryInterface(pfilter, &IID_IAMFilterMiscFlags, (void**)&flags);
2284 if (!flags)
2285 continue;
2286 filterflags = IAMFilterMiscFlags_GetMiscFlags(flags);
2287 IAMFilterMiscFlags_Release(flags);
2288 if (filterflags != AM_FILTER_MISC_FLAGS_IS_RENDERER)
2289 continue;
2291 IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2292 if (!seek)
2293 continue;
2294 hr = FoundSeek(This, seek, arg);
2295 IMediaSeeking_Release(seek);
2296 if (hr_return != E_NOTIMPL)
2297 allnotimpl = FALSE;
2298 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2299 hr_return = hr;
2302 if (allnotimpl)
2303 return E_NOTIMPL;
2304 return hr_return;
2307 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2309 HRESULT hr;
2310 DWORD caps = 0;
2312 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2313 if (FAILED(hr))
2314 return hr;
2316 /* Only add common capabilities everything supports */
2317 *(DWORD*)pcaps &= caps;
2319 return hr;
2322 /*** IMediaSeeking methods ***/
2323 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2325 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2326 HRESULT hr;
2328 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2330 if (!pCapabilities)
2331 return E_POINTER;
2333 EnterCriticalSection(&This->cs);
2334 *pCapabilities = 0xffffffff;
2336 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2337 LeaveCriticalSection(&This->cs);
2339 return hr;
2342 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2344 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2345 DWORD originalcaps;
2346 HRESULT hr;
2348 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2350 if (!pCapabilities)
2351 return E_POINTER;
2353 EnterCriticalSection(&This->cs);
2354 originalcaps = *pCapabilities;
2355 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2356 LeaveCriticalSection(&This->cs);
2358 if (FAILED(hr))
2359 return hr;
2361 if (!*pCapabilities)
2362 return E_FAIL;
2363 if (*pCapabilities != originalcaps)
2364 return S_FALSE;
2365 return S_OK;
2368 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2370 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2372 if (!pFormat)
2373 return E_POINTER;
2375 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2377 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2379 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2380 return S_FALSE;
2383 return S_OK;
2386 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2388 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2390 if (!pFormat)
2391 return E_POINTER;
2393 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2394 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2396 return S_OK;
2399 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2401 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2403 if (!pFormat)
2404 return E_POINTER;
2406 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2407 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2409 return S_OK;
2412 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2414 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2416 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2417 if (!pFormat)
2418 return E_POINTER;
2420 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2421 return S_FALSE;
2423 return S_OK;
2426 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2428 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2430 if (!pFormat)
2431 return E_POINTER;
2433 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2435 if (This->state != State_Stopped)
2436 return VFW_E_WRONG_STATE;
2438 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2440 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2441 return E_INVALIDARG;
2444 return S_OK;
2447 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2449 HRESULT hr;
2450 LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2452 hr = IMediaSeeking_GetDuration(seek, &duration);
2453 if (FAILED(hr))
2454 return hr;
2456 if (*pdur < duration)
2457 *pdur = duration;
2458 return hr;
2461 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *pDuration)
2463 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2464 HRESULT hr;
2466 TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2468 if (!pDuration)
2469 return E_POINTER;
2471 EnterCriticalSection(&This->cs);
2472 *pDuration = 0;
2473 hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2474 LeaveCriticalSection(&This->cs);
2476 TRACE("--->%08x\n", hr);
2477 return hr;
2480 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *pStop)
2482 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2483 HRESULT hr = S_OK;
2485 TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2487 if (!pStop)
2488 return E_POINTER;
2490 EnterCriticalSection(&This->cs);
2491 if (This->stop_position < 0)
2492 /* Stop position not set, use duration instead */
2493 hr = IMediaSeeking_GetDuration(iface, pStop);
2494 else
2495 *pStop = This->stop_position;
2496 LeaveCriticalSection(&This->cs);
2498 return hr;
2501 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *pCurrent)
2503 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2504 LONGLONG time = 0;
2506 if (!pCurrent)
2507 return E_POINTER;
2509 EnterCriticalSection(&This->cs);
2510 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2512 IReferenceClock_GetTime(This->refClock, &time);
2513 if (time)
2514 time -= This->start_time;
2516 if (This->pause_time > 0)
2517 time += This->pause_time;
2518 *pCurrent = time;
2519 LeaveCriticalSection(&This->cs);
2521 TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2523 return S_OK;
2526 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2527 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2529 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2531 TRACE("(%p/%p)->(%p, %s, 0x%s, %s)\n", This, iface, pTarget,
2532 debugstr_guid(pTargetFormat), wine_dbgstr_longlong(Source), debugstr_guid(pSourceFormat));
2534 if (!pSourceFormat)
2535 pSourceFormat = &This->timeformatseek;
2537 if (!pTargetFormat)
2538 pTargetFormat = &This->timeformatseek;
2540 if (IsEqualGUID(pTargetFormat, pSourceFormat))
2541 *pTarget = Source;
2542 else
2543 FIXME("conversion %s->%s not supported\n", debugstr_guid(pSourceFormat), debugstr_guid(pTargetFormat));
2545 return S_OK;
2548 struct pos_args {
2549 LONGLONG* current, *stop;
2550 DWORD curflags, stopflags;
2553 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2555 struct pos_args *args = (void*)pargs;
2557 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
2560 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2561 DWORD dwCurrentFlags, LONGLONG *pStop, DWORD dwStopFlags)
2563 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2564 HRESULT hr = S_OK;
2565 FILTER_STATE state;
2566 struct pos_args args;
2568 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
2570 EnterCriticalSection(&This->cs);
2571 state = This->state;
2572 TRACE("State: %s\n", state == State_Running ? "Running" : (state == State_Paused ? "Paused" : (state == State_Stopped ? "Stopped" : "UNKNOWN")));
2574 if ((dwCurrentFlags & 0x7) != AM_SEEKING_AbsolutePositioning &&
2575 (dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2576 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
2578 if ((dwStopFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2579 This->stop_position = *pStop;
2580 else if ((dwStopFlags & 0x7) != AM_SEEKING_NoPositioning)
2581 FIXME("Stop position not handled yet!\n");
2583 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2584 IMediaControl_Pause(&This->IMediaControl_iface);
2585 args.current = pCurrent;
2586 args.stop = pStop;
2587 args.curflags = dwCurrentFlags;
2588 args.stopflags = dwStopFlags;
2589 hr = all_renderers_seek(This, found_setposition, (DWORD_PTR)&args);
2591 if ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2592 This->pause_time = This->start_time = -1;
2593 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2594 IMediaControl_Run(&This->IMediaControl_iface);
2595 LeaveCriticalSection(&This->cs);
2597 return hr;
2600 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2601 LONGLONG *pStop)
2603 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2604 HRESULT hr;
2606 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pCurrent, pStop);
2607 hr = IMediaSeeking_GetCurrentPosition(iface, pCurrent);
2608 if (SUCCEEDED(hr))
2609 hr = IMediaSeeking_GetStopPosition(iface, pStop);
2611 return hr;
2614 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2615 LONGLONG *pLatest)
2617 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2619 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2621 return S_OK;
2624 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2626 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2628 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2630 return S_OK;
2633 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2635 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2637 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2639 if (!pdRate)
2640 return E_POINTER;
2642 *pdRate = 1.0;
2644 return S_OK;
2647 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2649 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2651 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2653 return S_OK;
2657 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2659 MediaSeeking_QueryInterface,
2660 MediaSeeking_AddRef,
2661 MediaSeeking_Release,
2662 MediaSeeking_GetCapabilities,
2663 MediaSeeking_CheckCapabilities,
2664 MediaSeeking_IsFormatSupported,
2665 MediaSeeking_QueryPreferredFormat,
2666 MediaSeeking_GetTimeFormat,
2667 MediaSeeking_IsUsingTimeFormat,
2668 MediaSeeking_SetTimeFormat,
2669 MediaSeeking_GetDuration,
2670 MediaSeeking_GetStopPosition,
2671 MediaSeeking_GetCurrentPosition,
2672 MediaSeeking_ConvertTimeFormat,
2673 MediaSeeking_SetPositions,
2674 MediaSeeking_GetPositions,
2675 MediaSeeking_GetAvailable,
2676 MediaSeeking_SetRate,
2677 MediaSeeking_GetRate,
2678 MediaSeeking_GetPreroll
2681 static inline IFilterGraphImpl *impl_from_IMediaPosition(IMediaPosition *iface)
2683 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaPosition_iface);
2686 /*** IUnknown methods ***/
2687 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj)
2689 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2691 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
2693 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2696 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2698 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2700 TRACE("(%p/%p)->()\n", This, iface);
2702 return IUnknown_AddRef(This->outer_unk);
2705 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2707 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2709 TRACE("(%p/%p)->()\n", This, iface);
2711 return IUnknown_Release(This->outer_unk);
2714 /*** IDispatch methods ***/
2715 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo)
2717 FIXME("(%p) stub!\n", iface);
2718 return E_NOTIMPL;
2721 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
2723 FIXME("(%p) stub!\n", iface);
2724 return E_NOTIMPL;
2727 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
2729 FIXME("(%p) stub!\n", iface);
2730 return E_NOTIMPL;
2733 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2735 FIXME("(%p) stub!\n", iface);
2736 return E_NOTIMPL;
2739 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2741 GUID time_format;
2742 HRESULT hr;
2744 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2745 if (FAILED(hr))
2746 return hr;
2747 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2749 FIXME("Unsupported time format.\n");
2750 return E_NOTIMPL;
2753 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2754 return S_OK;
2757 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2759 GUID time_format;
2760 HRESULT hr;
2762 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2763 if (FAILED(hr))
2764 return hr;
2765 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2767 FIXME("Unsupported time format.\n");
2768 return E_NOTIMPL;
2771 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2772 return S_OK;
2775 /*** IMediaPosition methods ***/
2776 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2778 LONGLONG duration;
2779 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2780 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2781 if (FAILED(hr))
2782 return hr;
2783 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2786 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2788 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2789 LONGLONG reftime;
2790 HRESULT hr;
2792 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2793 if (FAILED(hr))
2794 return hr;
2795 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2796 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2799 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2801 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2802 LONGLONG pos;
2803 HRESULT hr;
2805 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2806 if (FAILED(hr))
2807 return hr;
2808 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2811 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2813 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2814 LONGLONG pos;
2815 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2816 if (FAILED(hr))
2817 return hr;
2818 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2821 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2823 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2824 LONGLONG reftime;
2825 HRESULT hr;
2827 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2828 if (FAILED(hr))
2829 return hr;
2830 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2831 &reftime, AM_SEEKING_AbsolutePositioning);
2834 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime)
2836 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2837 return E_NOTIMPL;
2840 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime)
2842 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2843 return E_NOTIMPL;
2846 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2848 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2849 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2852 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2854 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2855 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2858 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward)
2860 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2861 return E_NOTIMPL;
2864 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward)
2866 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2867 return E_NOTIMPL;
2871 static const IMediaPositionVtbl IMediaPosition_VTable =
2873 MediaPosition_QueryInterface,
2874 MediaPosition_AddRef,
2875 MediaPosition_Release,
2876 MediaPosition_GetTypeInfoCount,
2877 MediaPosition_GetTypeInfo,
2878 MediaPosition_GetIDsOfNames,
2879 MediaPosition_Invoke,
2880 MediaPosition_get_Duration,
2881 MediaPosition_put_CurrentPosition,
2882 MediaPosition_get_CurrentPosition,
2883 MediaPosition_get_StopTime,
2884 MediaPosition_put_StopTime,
2885 MediaPosition_get_PrerollTime,
2886 MediaPosition_put_PrerollTime,
2887 MediaPosition_put_Rate,
2888 MediaPosition_get_Rate,
2889 MediaPosition_CanSeekForward,
2890 MediaPosition_CanSeekBackward
2893 static inline IFilterGraphImpl *impl_from_IObjectWithSite(IObjectWithSite *iface)
2895 return CONTAINING_RECORD(iface, IFilterGraphImpl, IObjectWithSite_iface);
2898 /*** IUnknown methods ***/
2899 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite* iface, REFIID riid, void** ppvObj)
2901 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2903 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
2905 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2908 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
2910 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2912 TRACE("(%p/%p)->()\n", This, iface);
2914 return IUnknown_AddRef(This->outer_unk);
2917 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
2919 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2921 TRACE("(%p/%p)->()\n", This, iface);
2923 return IUnknown_Release(This->outer_unk);
2926 /*** IObjectWithSite methods ***/
2928 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
2930 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2932 TRACE("(%p/%p)->()\n", This, iface);
2933 if (This->pSite) IUnknown_Release(This->pSite);
2934 This->pSite = pUnkSite;
2935 IUnknown_AddRef(This->pSite);
2936 return S_OK;
2939 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, PVOID *ppvSite)
2941 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2943 TRACE("(%p/%p)->(%s)\n", This, iface,debugstr_guid(riid));
2945 *ppvSite = NULL;
2946 if (!This->pSite)
2947 return E_FAIL;
2948 else
2949 return IUnknown_QueryInterface(This->pSite, riid, ppvSite);
2952 static const IObjectWithSiteVtbl IObjectWithSite_VTable =
2954 ObjectWithSite_QueryInterface,
2955 ObjectWithSite_AddRef,
2956 ObjectWithSite_Release,
2957 ObjectWithSite_SetSite,
2958 ObjectWithSite_GetSite,
2961 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2963 HRESULT hr = E_NOINTERFACE;
2964 int i;
2965 int entry;
2967 /* Check if the interface type is already registered */
2968 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2969 if (riid == pGraph->ItfCacheEntries[entry].riid)
2971 if (pGraph->ItfCacheEntries[entry].iface)
2973 /* Return the interface if available */
2974 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2975 return S_OK;
2977 break;
2980 if (entry >= MAX_ITF_CACHE_ENTRIES)
2982 FIXME("Not enough space to store interface in the cache\n");
2983 return E_OUTOFMEMORY;
2986 /* Find a filter supporting the requested interface */
2987 for (i = 0; i < pGraph->nFilters; i++)
2989 hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2990 if (hr == S_OK)
2992 pGraph->ItfCacheEntries[entry].riid = riid;
2993 pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2994 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2995 if (entry >= pGraph->nItfCacheEntries)
2996 pGraph->nItfCacheEntries++;
2997 return S_OK;
2999 if (hr != E_NOINTERFACE)
3000 return hr;
3003 return hr;
3006 static inline IFilterGraphImpl *impl_from_IBasicAudio(IBasicAudio *iface)
3008 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicAudio_iface);
3011 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID riid, void **ppvObj)
3013 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3015 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
3017 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
3020 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
3022 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3024 TRACE("(%p/%p)->()\n", This, iface);
3026 return IUnknown_AddRef(This->outer_unk);
3029 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
3031 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3033 TRACE("(%p/%p)->()\n", This, iface);
3035 return IUnknown_Release(This->outer_unk);
3038 /*** IDispatch methods ***/
3039 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *pctinfo)
3041 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3042 IBasicAudio* pBasicAudio;
3043 HRESULT hr;
3045 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3047 EnterCriticalSection(&This->cs);
3049 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3051 if (hr == S_OK)
3052 hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
3054 LeaveCriticalSection(&This->cs);
3056 return hr;
3059 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT iTInfo, LCID lcid,
3060 ITypeInfo **ppTInfo)
3062 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3063 IBasicAudio* pBasicAudio;
3064 HRESULT hr;
3066 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3068 EnterCriticalSection(&This->cs);
3070 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3072 if (hr == S_OK)
3073 hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
3075 LeaveCriticalSection(&This->cs);
3077 return hr;
3080 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID riid, LPOLESTR *rgszNames,
3081 UINT cNames, LCID lcid, DISPID *rgDispId)
3083 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3084 IBasicAudio* pBasicAudio;
3085 HRESULT hr;
3087 TRACE("(%p/%p)->(%s, %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), rgszNames, cNames,
3088 lcid, rgDispId);
3090 EnterCriticalSection(&This->cs);
3092 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3094 if (hr == S_OK)
3095 hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
3097 LeaveCriticalSection(&This->cs);
3099 return hr;
3102 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID dispIdMember, REFIID riid,
3103 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3104 UINT *puArgErr)
3106 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3107 IBasicAudio* pBasicAudio;
3108 HRESULT hr;
3110 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember,
3111 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3113 EnterCriticalSection(&This->cs);
3115 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3117 if (hr == S_OK)
3118 hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3120 LeaveCriticalSection(&This->cs);
3122 return hr;
3125 /*** IBasicAudio methods ***/
3126 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
3128 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3129 IBasicAudio* pBasicAudio;
3130 HRESULT hr;
3132 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
3134 EnterCriticalSection(&This->cs);
3136 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3138 if (hr == S_OK)
3139 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
3141 LeaveCriticalSection(&This->cs);
3143 return hr;
3146 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
3148 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3149 IBasicAudio* pBasicAudio;
3150 HRESULT hr;
3152 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
3154 EnterCriticalSection(&This->cs);
3156 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3158 if (hr == S_OK)
3159 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
3161 LeaveCriticalSection(&This->cs);
3163 return hr;
3166 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
3168 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3169 IBasicAudio* pBasicAudio;
3170 HRESULT hr;
3172 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
3174 EnterCriticalSection(&This->cs);
3176 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3178 if (hr == S_OK)
3179 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
3181 LeaveCriticalSection(&This->cs);
3183 return hr;
3186 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
3188 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3189 IBasicAudio* pBasicAudio;
3190 HRESULT hr;
3192 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
3194 EnterCriticalSection(&This->cs);
3196 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3198 if (hr == S_OK)
3199 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
3201 LeaveCriticalSection(&This->cs);
3203 return hr;
3206 static const IBasicAudioVtbl IBasicAudio_VTable =
3208 BasicAudio_QueryInterface,
3209 BasicAudio_AddRef,
3210 BasicAudio_Release,
3211 BasicAudio_GetTypeInfoCount,
3212 BasicAudio_GetTypeInfo,
3213 BasicAudio_GetIDsOfNames,
3214 BasicAudio_Invoke,
3215 BasicAudio_put_Volume,
3216 BasicAudio_get_Volume,
3217 BasicAudio_put_Balance,
3218 BasicAudio_get_Balance
3221 static inline IFilterGraphImpl *impl_from_IBasicVideo2(IBasicVideo2 *iface)
3223 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicVideo2_iface);
3226 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID riid, void **ppvObj)
3228 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3230 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
3232 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
3235 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
3237 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3239 TRACE("(%p/%p)->()\n", This, iface);
3241 return IUnknown_AddRef(This->outer_unk);
3244 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
3246 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3248 TRACE("(%p/%p)->()\n", This, iface);
3250 return IUnknown_Release(This->outer_unk);
3253 /*** IDispatch methods ***/
3254 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *pctinfo)
3256 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3257 IBasicVideo *pBasicVideo;
3258 HRESULT hr;
3260 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3262 EnterCriticalSection(&This->cs);
3264 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3266 if (hr == S_OK)
3267 hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
3269 LeaveCriticalSection(&This->cs);
3271 return hr;
3274 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT iTInfo, LCID lcid,
3275 ITypeInfo **ppTInfo)
3277 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3278 IBasicVideo *pBasicVideo;
3279 HRESULT hr;
3281 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3283 EnterCriticalSection(&This->cs);
3285 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3287 if (hr == S_OK)
3288 hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
3290 LeaveCriticalSection(&This->cs);
3292 return hr;
3295 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID riid,
3296 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
3298 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3299 IBasicVideo *pBasicVideo;
3300 HRESULT hr;
3302 TRACE("(%p/%p)->(%s, %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), rgszNames, cNames,
3303 lcid, rgDispId);
3305 EnterCriticalSection(&This->cs);
3307 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3309 if (hr == S_OK)
3310 hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
3312 LeaveCriticalSection(&This->cs);
3314 return hr;
3317 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID dispIdMember, REFIID riid,
3318 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3319 UINT *puArgErr)
3321 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3322 IBasicVideo *pBasicVideo;
3323 HRESULT hr;
3325 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember,
3326 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3328 EnterCriticalSection(&This->cs);
3330 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3332 if (hr == S_OK)
3333 hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3335 LeaveCriticalSection(&This->cs);
3337 return hr;
3340 /*** IBasicVideo methods ***/
3341 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3343 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3344 IBasicVideo *pBasicVideo;
3345 HRESULT hr;
3347 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3349 EnterCriticalSection(&This->cs);
3351 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3353 if (hr == S_OK)
3354 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3356 LeaveCriticalSection(&This->cs);
3358 return hr;
3361 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3363 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3364 IBasicVideo *pBasicVideo;
3365 HRESULT hr;
3367 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3369 EnterCriticalSection(&This->cs);
3371 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3373 if (hr == S_OK)
3374 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3376 LeaveCriticalSection(&This->cs);
3378 return hr;
3381 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3383 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3384 IBasicVideo *pBasicVideo;
3385 HRESULT hr;
3387 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3389 EnterCriticalSection(&This->cs);
3391 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3393 if (hr == S_OK)
3394 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3396 LeaveCriticalSection(&This->cs);
3398 return hr;
3401 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3403 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3404 IBasicVideo *pBasicVideo;
3405 HRESULT hr;
3407 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3409 EnterCriticalSection(&This->cs);
3411 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3413 if (hr == S_OK)
3414 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3416 LeaveCriticalSection(&This->cs);
3418 return hr;
3421 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3423 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3424 IBasicVideo *pBasicVideo;
3425 HRESULT hr;
3427 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3429 EnterCriticalSection(&This->cs);
3431 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3433 if (hr == S_OK)
3434 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3436 LeaveCriticalSection(&This->cs);
3438 return hr;
3441 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3443 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3444 IBasicVideo *pBasicVideo;
3445 HRESULT hr;
3447 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3449 EnterCriticalSection(&This->cs);
3451 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3453 if (hr == S_OK)
3454 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3456 LeaveCriticalSection(&This->cs);
3458 return hr;
3461 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3463 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3464 IBasicVideo *pBasicVideo;
3465 HRESULT hr;
3467 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3469 EnterCriticalSection(&This->cs);
3471 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3473 if (hr == S_OK)
3474 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3476 LeaveCriticalSection(&This->cs);
3478 return hr;
3481 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3483 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3484 IBasicVideo *pBasicVideo;
3485 HRESULT hr;
3487 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3489 EnterCriticalSection(&This->cs);
3491 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3493 if (hr == S_OK)
3494 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3496 LeaveCriticalSection(&This->cs);
3498 return hr;
3501 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3503 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3504 IBasicVideo *pBasicVideo;
3505 HRESULT hr;
3507 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3509 EnterCriticalSection(&This->cs);
3511 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3513 if (hr == S_OK)
3514 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3516 LeaveCriticalSection(&This->cs);
3518 return hr;
3521 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3523 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3524 IBasicVideo *pBasicVideo;
3525 HRESULT hr;
3527 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3529 EnterCriticalSection(&This->cs);
3531 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3533 if (hr == S_OK)
3534 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3536 LeaveCriticalSection(&This->cs);
3538 return hr;
3541 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3543 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3544 IBasicVideo *pBasicVideo;
3545 HRESULT hr;
3547 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3549 EnterCriticalSection(&This->cs);
3551 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3553 if (hr == S_OK)
3554 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3556 LeaveCriticalSection(&This->cs);
3558 return hr;
3561 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3563 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3564 IBasicVideo *pBasicVideo;
3565 HRESULT hr;
3567 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3569 EnterCriticalSection(&This->cs);
3571 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3573 if (hr == S_OK)
3574 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3576 LeaveCriticalSection(&This->cs);
3578 return hr;
3581 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3583 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3584 IBasicVideo *pBasicVideo;
3585 HRESULT hr;
3587 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3589 EnterCriticalSection(&This->cs);
3591 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3593 if (hr == S_OK)
3594 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3596 LeaveCriticalSection(&This->cs);
3598 return hr;
3601 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3603 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3604 IBasicVideo *pBasicVideo;
3605 HRESULT hr;
3607 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3609 EnterCriticalSection(&This->cs);
3611 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3613 if (hr == S_OK)
3614 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3616 LeaveCriticalSection(&This->cs);
3618 return hr;
3621 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3623 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3624 IBasicVideo *pBasicVideo;
3625 HRESULT hr;
3627 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3629 EnterCriticalSection(&This->cs);
3631 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3633 if (hr == S_OK)
3634 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3636 LeaveCriticalSection(&This->cs);
3638 return hr;
3641 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3643 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3644 IBasicVideo *pBasicVideo;
3645 HRESULT hr;
3647 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3649 EnterCriticalSection(&This->cs);
3651 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3653 if (hr == S_OK)
3654 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3656 LeaveCriticalSection(&This->cs);
3658 return hr;
3661 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3663 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3664 IBasicVideo *pBasicVideo;
3665 HRESULT hr;
3667 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3669 EnterCriticalSection(&This->cs);
3671 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3673 if (hr == S_OK)
3674 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3676 LeaveCriticalSection(&This->cs);
3678 return hr;
3681 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3683 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3684 IBasicVideo *pBasicVideo;
3685 HRESULT hr;
3687 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3689 EnterCriticalSection(&This->cs);
3691 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3693 if (hr == S_OK)
3694 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3696 LeaveCriticalSection(&This->cs);
3698 return hr;
3701 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3703 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3704 IBasicVideo *pBasicVideo;
3705 HRESULT hr;
3707 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3709 EnterCriticalSection(&This->cs);
3711 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3713 if (hr == S_OK)
3714 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3716 LeaveCriticalSection(&This->cs);
3718 return hr;
3721 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3723 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3724 IBasicVideo *pBasicVideo;
3725 HRESULT hr;
3727 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3729 EnterCriticalSection(&This->cs);
3731 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3733 if (hr == S_OK)
3734 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3736 LeaveCriticalSection(&This->cs);
3738 return hr;
3741 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3742 LONG *pDestinationHeight)
3744 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3745 IBasicVideo *pBasicVideo;
3746 HRESULT hr;
3748 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3750 EnterCriticalSection(&This->cs);
3752 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3754 if (hr == S_OK)
3755 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3757 LeaveCriticalSection(&This->cs);
3759 return hr;
3762 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3763 LONG Width, LONG Height)
3765 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3766 IBasicVideo *pBasicVideo;
3767 HRESULT hr;
3769 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3771 EnterCriticalSection(&This->cs);
3773 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3775 if (hr == S_OK)
3776 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3778 LeaveCriticalSection(&This->cs);
3780 return hr;
3783 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3784 LONG *pWidth, LONG *pHeight)
3786 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3787 IBasicVideo *pBasicVideo;
3788 HRESULT hr;
3790 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3792 EnterCriticalSection(&This->cs);
3794 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3796 if (hr == S_OK)
3797 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3799 LeaveCriticalSection(&This->cs);
3801 return hr;
3804 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3806 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3807 IBasicVideo *pBasicVideo;
3808 HRESULT hr;
3810 TRACE("(%p/%p)->()\n", This, iface);
3812 EnterCriticalSection(&This->cs);
3814 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3816 if (hr == S_OK)
3817 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3819 LeaveCriticalSection(&This->cs);
3821 return hr;
3824 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3825 LONG Width, LONG Height)
3827 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3828 IBasicVideo *pBasicVideo;
3829 HRESULT hr;
3831 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3833 EnterCriticalSection(&This->cs);
3835 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3837 if (hr == S_OK)
3838 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3840 LeaveCriticalSection(&This->cs);
3842 return hr;
3845 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3846 LONG *pTop, LONG *pWidth, LONG *pHeight)
3848 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3849 IBasicVideo *pBasicVideo;
3850 HRESULT hr;
3852 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3854 EnterCriticalSection(&This->cs);
3856 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3858 if (hr == S_OK)
3859 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3861 LeaveCriticalSection(&This->cs);
3863 return hr;
3866 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3868 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3869 IBasicVideo *pBasicVideo;
3870 HRESULT hr;
3872 TRACE("(%p/%p)->()\n", This, iface);
3874 EnterCriticalSection(&This->cs);
3876 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3878 if (hr == S_OK)
3879 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3881 LeaveCriticalSection(&This->cs);
3883 return hr;
3886 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3888 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3889 IBasicVideo *pBasicVideo;
3890 HRESULT hr;
3892 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3894 EnterCriticalSection(&This->cs);
3896 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3898 if (hr == S_OK)
3899 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3901 LeaveCriticalSection(&This->cs);
3903 return hr;
3906 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3907 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3909 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3910 IBasicVideo *pBasicVideo;
3911 HRESULT hr;
3913 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3915 EnterCriticalSection(&This->cs);
3917 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3919 if (hr == S_OK)
3920 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3922 LeaveCriticalSection(&This->cs);
3924 return hr;
3927 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3928 LONG *pDIBImage)
3930 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3931 IBasicVideo *pBasicVideo;
3932 HRESULT hr;
3934 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3936 EnterCriticalSection(&This->cs);
3938 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3940 if (hr == S_OK)
3941 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3943 LeaveCriticalSection(&This->cs);
3945 return hr;
3948 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3950 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3951 IBasicVideo *pBasicVideo;
3952 HRESULT hr;
3954 TRACE("(%p/%p)->()\n", This, iface);
3956 EnterCriticalSection(&This->cs);
3958 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3960 if (hr == S_OK)
3961 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3963 LeaveCriticalSection(&This->cs);
3965 return hr;
3968 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3970 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3971 IBasicVideo *pBasicVideo;
3972 HRESULT hr;
3974 TRACE("(%p/%p)->()\n", This, iface);
3976 EnterCriticalSection(&This->cs);
3978 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3980 if (hr == S_OK)
3981 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3983 LeaveCriticalSection(&This->cs);
3985 return hr;
3988 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3989 LONG *plAspectY)
3991 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3992 IBasicVideo2 *pBasicVideo2;
3993 HRESULT hr;
3995 TRACE("(%p/%p)->()\n", This, iface);
3997 EnterCriticalSection(&This->cs);
3999 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
4001 if (hr == S_OK)
4002 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
4004 LeaveCriticalSection(&This->cs);
4006 return hr;
4009 static const IBasicVideo2Vtbl IBasicVideo_VTable =
4011 BasicVideo_QueryInterface,
4012 BasicVideo_AddRef,
4013 BasicVideo_Release,
4014 BasicVideo_GetTypeInfoCount,
4015 BasicVideo_GetTypeInfo,
4016 BasicVideo_GetIDsOfNames,
4017 BasicVideo_Invoke,
4018 BasicVideo_get_AvgTimePerFrame,
4019 BasicVideo_get_BitRate,
4020 BasicVideo_get_BitErrorRate,
4021 BasicVideo_get_VideoWidth,
4022 BasicVideo_get_VideoHeight,
4023 BasicVideo_put_SourceLeft,
4024 BasicVideo_get_SourceLeft,
4025 BasicVideo_put_SourceWidth,
4026 BasicVideo_get_SourceWidth,
4027 BasicVideo_put_SourceTop,
4028 BasicVideo_get_SourceTop,
4029 BasicVideo_put_SourceHeight,
4030 BasicVideo_get_SourceHeight,
4031 BasicVideo_put_DestinationLeft,
4032 BasicVideo_get_DestinationLeft,
4033 BasicVideo_put_DestinationWidth,
4034 BasicVideo_get_DestinationWidth,
4035 BasicVideo_put_DestinationTop,
4036 BasicVideo_get_DestinationTop,
4037 BasicVideo_put_DestinationHeight,
4038 BasicVideo_get_DestinationHeight,
4039 BasicVideo_SetSourcePosition,
4040 BasicVideo_GetSourcePosition,
4041 BasicVideo_SetDefaultSourcePosition,
4042 BasicVideo_SetDestinationPosition,
4043 BasicVideo_GetDestinationPosition,
4044 BasicVideo_SetDefaultDestinationPosition,
4045 BasicVideo_GetVideoSize,
4046 BasicVideo_GetVideoPaletteEntries,
4047 BasicVideo_GetCurrentImage,
4048 BasicVideo_IsUsingDefaultSource,
4049 BasicVideo_IsUsingDefaultDestination,
4050 BasicVideo2_GetPreferredAspectRatio
4053 static inline IFilterGraphImpl *impl_from_IVideoWindow(IVideoWindow *iface)
4055 return CONTAINING_RECORD(iface, IFilterGraphImpl, IVideoWindow_iface);
4058 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID riid, void **ppvObj)
4060 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4062 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
4064 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
4067 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
4069 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4071 TRACE("(%p/%p)->()\n", This, iface);
4073 return IUnknown_AddRef(This->outer_unk);
4076 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
4078 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4080 TRACE("(%p/%p)->()\n", This, iface);
4082 return IUnknown_Release(This->outer_unk);
4085 /*** IDispatch methods ***/
4086 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *pctinfo)
4088 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4089 IVideoWindow *pVideoWindow;
4090 HRESULT hr;
4092 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
4094 EnterCriticalSection(&This->cs);
4096 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4098 if (hr == S_OK)
4099 hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
4101 LeaveCriticalSection(&This->cs);
4103 return hr;
4106 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT iTInfo, LCID lcid,
4107 ITypeInfo **ppTInfo)
4109 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4110 IVideoWindow *pVideoWindow;
4111 HRESULT hr;
4113 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
4115 EnterCriticalSection(&This->cs);
4117 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4119 if (hr == S_OK)
4120 hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
4122 LeaveCriticalSection(&This->cs);
4124 return hr;
4127 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID riid,
4128 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4130 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4131 IVideoWindow *pVideoWindow;
4132 HRESULT hr;
4134 TRACE("(%p/%p)->(%s, %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), rgszNames, cNames,
4135 lcid, rgDispId);
4137 EnterCriticalSection(&This->cs);
4139 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4141 if (hr == S_OK)
4142 hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
4144 LeaveCriticalSection(&This->cs);
4146 return hr;
4149 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID dispIdMember, REFIID riid,
4150 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4151 UINT*puArgErr)
4153 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4154 IVideoWindow *pVideoWindow;
4155 HRESULT hr;
4157 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember,
4158 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4160 EnterCriticalSection(&This->cs);
4162 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4164 if (hr == S_OK)
4165 hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4167 LeaveCriticalSection(&This->cs);
4169 return hr;
4173 /*** IVideoWindow methods ***/
4174 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
4176 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4177 IVideoWindow *pVideoWindow;
4178 HRESULT hr;
4180 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
4182 EnterCriticalSection(&This->cs);
4184 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4186 if (hr == S_OK)
4187 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
4189 LeaveCriticalSection(&This->cs);
4191 return hr;
4194 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
4196 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4197 IVideoWindow *pVideoWindow;
4198 HRESULT hr;
4200 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
4202 EnterCriticalSection(&This->cs);
4204 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4206 if (hr == S_OK)
4207 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
4209 LeaveCriticalSection(&This->cs);
4211 return hr;
4214 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
4216 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4217 IVideoWindow *pVideoWindow;
4218 HRESULT hr;
4220 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
4222 EnterCriticalSection(&This->cs);
4224 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4226 if (hr == S_OK)
4227 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
4229 LeaveCriticalSection(&This->cs);
4231 return hr;
4234 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
4236 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4237 IVideoWindow *pVideoWindow;
4238 HRESULT hr;
4240 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
4242 EnterCriticalSection(&This->cs);
4244 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4246 if (hr == S_OK)
4247 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
4249 LeaveCriticalSection(&This->cs);
4251 return hr;
4254 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
4256 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4257 IVideoWindow *pVideoWindow;
4258 HRESULT hr;
4260 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
4262 EnterCriticalSection(&This->cs);
4264 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4266 if (hr == S_OK)
4267 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
4269 LeaveCriticalSection(&This->cs);
4271 return hr;
4274 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
4276 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4277 IVideoWindow *pVideoWindow;
4278 HRESULT hr;
4280 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
4282 EnterCriticalSection(&This->cs);
4284 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4286 if (hr == S_OK)
4287 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
4289 LeaveCriticalSection(&This->cs);
4291 return hr;
4294 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
4296 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4297 IVideoWindow *pVideoWindow;
4298 HRESULT hr;
4300 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
4302 EnterCriticalSection(&This->cs);
4304 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4306 if (hr == S_OK)
4307 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4309 LeaveCriticalSection(&This->cs);
4311 return hr;
4314 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
4316 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4317 IVideoWindow *pVideoWindow;
4318 HRESULT hr;
4320 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4322 EnterCriticalSection(&This->cs);
4324 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4326 if (hr == S_OK)
4327 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4329 LeaveCriticalSection(&This->cs);
4331 return hr;
4334 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
4336 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4337 IVideoWindow *pVideoWindow;
4338 HRESULT hr;
4340 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4342 EnterCriticalSection(&This->cs);
4344 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4346 if (hr == S_OK)
4347 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4349 LeaveCriticalSection(&This->cs);
4351 return hr;
4354 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4356 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4357 IVideoWindow *pVideoWindow;
4358 HRESULT hr;
4360 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4362 EnterCriticalSection(&This->cs);
4364 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4366 if (hr == S_OK)
4367 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4369 LeaveCriticalSection(&This->cs);
4371 return hr;
4374 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4376 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4377 IVideoWindow *pVideoWindow;
4378 HRESULT hr;
4380 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4382 EnterCriticalSection(&This->cs);
4384 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4386 if (hr == S_OK)
4387 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4389 LeaveCriticalSection(&This->cs);
4391 return hr;
4394 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4395 LONG *pBackgroundPalette)
4397 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4398 IVideoWindow *pVideoWindow;
4399 HRESULT hr;
4401 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4403 EnterCriticalSection(&This->cs);
4405 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4407 if (hr == S_OK)
4408 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4410 LeaveCriticalSection(&This->cs);
4412 return hr;
4415 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4417 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4418 IVideoWindow *pVideoWindow;
4419 HRESULT hr;
4421 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4423 EnterCriticalSection(&This->cs);
4425 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4427 if (hr == S_OK)
4428 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4430 LeaveCriticalSection(&This->cs);
4432 return hr;
4435 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4437 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4438 IVideoWindow *pVideoWindow;
4439 HRESULT hr;
4441 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4443 EnterCriticalSection(&This->cs);
4445 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4447 if (hr == S_OK)
4448 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4450 LeaveCriticalSection(&This->cs);
4452 return hr;
4455 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4457 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4458 IVideoWindow *pVideoWindow;
4459 HRESULT hr;
4461 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4463 EnterCriticalSection(&This->cs);
4465 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4467 if (hr == S_OK)
4468 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4470 LeaveCriticalSection(&This->cs);
4472 return hr;
4475 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4477 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4478 IVideoWindow *pVideoWindow;
4479 HRESULT hr;
4481 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4483 EnterCriticalSection(&This->cs);
4485 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4487 if (hr == S_OK)
4488 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4490 LeaveCriticalSection(&This->cs);
4492 return hr;
4495 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4497 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4498 IVideoWindow *pVideoWindow;
4499 HRESULT hr;
4501 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4503 EnterCriticalSection(&This->cs);
4505 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4507 if (hr == S_OK)
4508 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4510 LeaveCriticalSection(&This->cs);
4512 return hr;
4515 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4517 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4518 IVideoWindow *pVideoWindow;
4519 HRESULT hr;
4521 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4523 EnterCriticalSection(&This->cs);
4525 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4527 if (hr == S_OK)
4528 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4530 LeaveCriticalSection(&This->cs);
4532 return hr;
4535 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4537 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4538 IVideoWindow *pVideoWindow;
4539 HRESULT hr;
4541 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4543 EnterCriticalSection(&This->cs);
4545 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4547 if (hr == S_OK)
4548 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4550 LeaveCriticalSection(&This->cs);
4552 return hr;
4555 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4557 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4558 IVideoWindow *pVideoWindow;
4559 HRESULT hr;
4561 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4563 EnterCriticalSection(&This->cs);
4565 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4567 if (hr == S_OK)
4568 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4570 LeaveCriticalSection(&This->cs);
4572 return hr;
4575 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4577 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4578 IVideoWindow *pVideoWindow;
4579 HRESULT hr;
4581 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4583 EnterCriticalSection(&This->cs);
4585 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4587 if (hr == S_OK)
4588 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4590 LeaveCriticalSection(&This->cs);
4592 return hr;
4595 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4597 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4598 IVideoWindow *pVideoWindow;
4599 HRESULT hr;
4601 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4603 EnterCriticalSection(&This->cs);
4605 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4607 if (hr == S_OK)
4608 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4610 LeaveCriticalSection(&This->cs);
4612 return hr;
4615 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4617 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4618 IVideoWindow *pVideoWindow;
4619 HRESULT hr;
4621 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4623 EnterCriticalSection(&This->cs);
4625 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4627 if (hr == S_OK)
4628 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4630 LeaveCriticalSection(&This->cs);
4632 return hr;
4635 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4637 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4638 IVideoWindow *pVideoWindow;
4639 HRESULT hr;
4641 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4643 EnterCriticalSection(&This->cs);
4645 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4647 if (hr == S_OK)
4648 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4650 LeaveCriticalSection(&This->cs);
4652 return hr;
4655 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4657 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4658 IVideoWindow *pVideoWindow;
4659 HRESULT hr;
4661 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4663 EnterCriticalSection(&This->cs);
4665 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4667 if (hr == S_OK)
4668 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4670 LeaveCriticalSection(&This->cs);
4672 return hr;
4675 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4677 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4678 IVideoWindow *pVideoWindow;
4679 HRESULT hr;
4681 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4683 EnterCriticalSection(&This->cs);
4685 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4687 if (hr == S_OK)
4688 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4690 LeaveCriticalSection(&This->cs);
4692 return hr;
4695 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4697 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4698 IVideoWindow *pVideoWindow;
4699 HRESULT hr;
4701 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4703 EnterCriticalSection(&This->cs);
4705 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4707 if (hr == S_OK)
4708 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4710 LeaveCriticalSection(&This->cs);
4712 return hr;
4715 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4717 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4718 IVideoWindow *pVideoWindow;
4719 HRESULT hr;
4721 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4723 EnterCriticalSection(&This->cs);
4725 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4727 if (hr == S_OK)
4728 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4730 LeaveCriticalSection(&This->cs);
4732 return hr;
4735 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4737 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4738 IVideoWindow *pVideoWindow;
4739 HRESULT hr;
4741 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4743 EnterCriticalSection(&This->cs);
4745 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4747 if (hr == S_OK)
4748 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4750 LeaveCriticalSection(&This->cs);
4752 return hr;
4755 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4757 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4758 IVideoWindow *pVideoWindow;
4759 HRESULT hr;
4761 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4763 EnterCriticalSection(&This->cs);
4765 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4767 if (hr == S_OK)
4768 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4770 LeaveCriticalSection(&This->cs);
4772 return hr;
4775 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4777 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4778 IVideoWindow *pVideoWindow;
4779 HRESULT hr;
4781 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4783 EnterCriticalSection(&This->cs);
4785 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4787 if (hr == S_OK)
4788 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4790 LeaveCriticalSection(&This->cs);
4792 return hr;
4795 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4796 LONG_PTR wParam, LONG_PTR lParam)
4798 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4799 IVideoWindow *pVideoWindow;
4800 HRESULT hr;
4802 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4804 EnterCriticalSection(&This->cs);
4806 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4808 if (hr == S_OK)
4809 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4811 LeaveCriticalSection(&This->cs);
4813 return hr;
4816 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4817 LONG Width, LONG Height)
4819 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4820 IVideoWindow *pVideoWindow;
4821 HRESULT hr;
4823 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4825 EnterCriticalSection(&This->cs);
4827 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4829 if (hr == S_OK)
4830 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4832 LeaveCriticalSection(&This->cs);
4834 return hr;
4837 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4838 LONG *pWidth, LONG *pHeight)
4840 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4841 IVideoWindow *pVideoWindow;
4842 HRESULT hr;
4844 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4846 EnterCriticalSection(&This->cs);
4848 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4850 if (hr == S_OK)
4851 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4853 LeaveCriticalSection(&This->cs);
4855 return hr;
4858 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4859 LONG *pHeight)
4861 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4862 IVideoWindow *pVideoWindow;
4863 HRESULT hr;
4865 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4867 EnterCriticalSection(&This->cs);
4869 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4871 if (hr == S_OK)
4872 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4874 LeaveCriticalSection(&This->cs);
4876 return hr;
4879 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4880 LONG *pHeight)
4882 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4883 IVideoWindow *pVideoWindow;
4884 HRESULT hr;
4886 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4888 EnterCriticalSection(&This->cs);
4890 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4892 if (hr == S_OK)
4893 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4895 LeaveCriticalSection(&This->cs);
4897 return hr;
4900 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4901 LONG *pWidth, LONG *pHeight)
4903 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4904 IVideoWindow *pVideoWindow;
4905 HRESULT hr;
4907 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4909 EnterCriticalSection(&This->cs);
4911 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4913 if (hr == S_OK)
4914 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4916 LeaveCriticalSection(&This->cs);
4918 return hr;
4921 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4923 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4924 IVideoWindow *pVideoWindow;
4925 HRESULT hr;
4927 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4929 EnterCriticalSection(&This->cs);
4931 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4933 if (hr == S_OK)
4934 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4936 LeaveCriticalSection(&This->cs);
4938 return hr;
4941 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4943 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4944 IVideoWindow *pVideoWindow;
4945 HRESULT hr;
4947 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4949 EnterCriticalSection(&This->cs);
4951 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4953 if (hr == S_OK)
4954 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4956 LeaveCriticalSection(&This->cs);
4958 return hr;
4962 static const IVideoWindowVtbl IVideoWindow_VTable =
4964 VideoWindow_QueryInterface,
4965 VideoWindow_AddRef,
4966 VideoWindow_Release,
4967 VideoWindow_GetTypeInfoCount,
4968 VideoWindow_GetTypeInfo,
4969 VideoWindow_GetIDsOfNames,
4970 VideoWindow_Invoke,
4971 VideoWindow_put_Caption,
4972 VideoWindow_get_Caption,
4973 VideoWindow_put_WindowStyle,
4974 VideoWindow_get_WindowStyle,
4975 VideoWindow_put_WindowStyleEx,
4976 VideoWindow_get_WindowStyleEx,
4977 VideoWindow_put_AutoShow,
4978 VideoWindow_get_AutoShow,
4979 VideoWindow_put_WindowState,
4980 VideoWindow_get_WindowState,
4981 VideoWindow_put_BackgroundPalette,
4982 VideoWindow_get_BackgroundPalette,
4983 VideoWindow_put_Visible,
4984 VideoWindow_get_Visible,
4985 VideoWindow_put_Left,
4986 VideoWindow_get_Left,
4987 VideoWindow_put_Width,
4988 VideoWindow_get_Width,
4989 VideoWindow_put_Top,
4990 VideoWindow_get_Top,
4991 VideoWindow_put_Height,
4992 VideoWindow_get_Height,
4993 VideoWindow_put_Owner,
4994 VideoWindow_get_Owner,
4995 VideoWindow_put_MessageDrain,
4996 VideoWindow_get_MessageDrain,
4997 VideoWindow_get_BorderColor,
4998 VideoWindow_put_BorderColor,
4999 VideoWindow_get_FullScreenMode,
5000 VideoWindow_put_FullScreenMode,
5001 VideoWindow_SetWindowForeground,
5002 VideoWindow_NotifyOwnerMessage,
5003 VideoWindow_SetWindowPosition,
5004 VideoWindow_GetWindowPosition,
5005 VideoWindow_GetMinIdealImageSize,
5006 VideoWindow_GetMaxIdealImageSize,
5007 VideoWindow_GetRestorePosition,
5008 VideoWindow_HideCursor,
5009 VideoWindow_IsCursorHidden
5012 static inline IFilterGraphImpl *impl_from_IMediaEventEx(IMediaEventEx *iface)
5014 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventEx_iface);
5017 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID riid, void **ppvObj)
5019 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5021 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
5023 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
5026 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
5028 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5030 TRACE("(%p/%p)->()\n", This, iface);
5032 return IUnknown_AddRef(This->outer_unk);
5035 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
5037 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5039 TRACE("(%p/%p)->()\n", This, iface);
5041 return IUnknown_Release(This->outer_unk);
5044 /*** IDispatch methods ***/
5045 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *pctinfo)
5047 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5049 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
5051 return S_OK;
5054 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT iTInfo, LCID lcid,
5055 ITypeInfo **ppTInfo)
5057 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5059 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
5061 return S_OK;
5064 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID riid,
5065 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
5067 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5069 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
5070 cNames, lcid, rgDispId);
5072 return S_OK;
5075 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID dispIdMember, REFIID riid,
5076 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
5077 UINT *puArgErr)
5079 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5081 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
5082 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
5084 return S_OK;
5087 /*** IMediaEvent methods ***/
5088 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *hEvent)
5090 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5092 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
5094 *hEvent = (OAEVENT)This->evqueue.msg_event;
5096 return S_OK;
5099 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *lEventCode, LONG_PTR *lParam1,
5100 LONG_PTR *lParam2, LONG msTimeout)
5102 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5103 Event evt;
5105 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
5107 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
5109 *lEventCode = evt.lEventCode;
5110 *lParam1 = evt.lParam1;
5111 *lParam2 = evt.lParam2;
5112 return S_OK;
5115 *lEventCode = 0;
5116 return E_ABORT;
5119 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
5120 LONG *pEvCode)
5122 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5124 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
5126 if (This->state != State_Running)
5127 return VFW_E_WRONG_STATE;
5129 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
5131 *pEvCode = This->CompletionStatus;
5132 return S_OK;
5135 *pEvCode = 0;
5136 return E_ABORT;
5139 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5141 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5143 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5145 if (lEvCode == EC_COMPLETE)
5146 This->HandleEcComplete = FALSE;
5147 else if (lEvCode == EC_REPAINT)
5148 This->HandleEcRepaint = FALSE;
5149 else if (lEvCode == EC_CLOCK_CHANGED)
5150 This->HandleEcClockChanged = FALSE;
5151 else
5152 return S_FALSE;
5154 return S_OK;
5157 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5159 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5161 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5163 if (lEvCode == EC_COMPLETE)
5164 This->HandleEcComplete = TRUE;
5165 else if (lEvCode == EC_REPAINT)
5166 This->HandleEcRepaint = TRUE;
5167 else if (lEvCode == EC_CLOCK_CHANGED)
5168 This->HandleEcClockChanged = TRUE;
5169 else
5170 return S_FALSE;
5172 return S_OK;
5175 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG lEvCode,
5176 LONG_PTR lParam1, LONG_PTR lParam2)
5178 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5180 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
5182 return S_OK;
5185 /*** IMediaEventEx methods ***/
5186 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface, OAHWND hwnd, LONG lMsg,
5187 LONG_PTR lInstanceData)
5189 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5191 TRACE("(%p/%p)->(%08lx, %d, %08lx)\n", This, iface, hwnd, lMsg, lInstanceData);
5193 This->notif.hWnd = (HWND)hwnd;
5194 This->notif.msg = lMsg;
5195 This->notif.instance = lInstanceData;
5197 return S_OK;
5200 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG lNoNotifyFlags)
5202 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5204 TRACE("(%p/%p)->(%d)\n", This, iface, lNoNotifyFlags);
5206 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
5207 return E_INVALIDARG;
5209 This->notif.disabled = lNoNotifyFlags;
5211 return S_OK;
5214 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *lplNoNotifyFlags)
5216 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5218 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
5220 if (!lplNoNotifyFlags)
5221 return E_POINTER;
5223 *lplNoNotifyFlags = This->notif.disabled;
5225 return S_OK;
5229 static const IMediaEventExVtbl IMediaEventEx_VTable =
5231 MediaEvent_QueryInterface,
5232 MediaEvent_AddRef,
5233 MediaEvent_Release,
5234 MediaEvent_GetTypeInfoCount,
5235 MediaEvent_GetTypeInfo,
5236 MediaEvent_GetIDsOfNames,
5237 MediaEvent_Invoke,
5238 MediaEvent_GetEventHandle,
5239 MediaEvent_GetEvent,
5240 MediaEvent_WaitForCompletion,
5241 MediaEvent_CancelDefaultHandling,
5242 MediaEvent_RestoreDefaultHandling,
5243 MediaEvent_FreeEventParams,
5244 MediaEvent_SetNotifyWindow,
5245 MediaEvent_SetNotifyFlags,
5246 MediaEvent_GetNotifyFlags
5250 static inline IFilterGraphImpl *impl_from_IMediaFilter(IMediaFilter *iface)
5252 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaFilter_iface);
5255 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, void **ppv)
5257 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5259 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5262 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
5264 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5266 return IUnknown_AddRef(This->outer_unk);
5269 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
5271 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5273 return IUnknown_Release(This->outer_unk);
5276 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
5278 FIXME("(%p): stub\n", pClassID);
5280 return E_NOTIMPL;
5283 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
5285 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5287 return MediaControl_Stop(&This->IMediaControl_iface);
5290 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5292 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5294 return MediaControl_Pause(&This->IMediaControl_iface);
5297 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
5299 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5301 if (tStart)
5302 FIXME("Run called with non-null tStart: %s\n", wine_dbgstr_longlong(tStart));
5304 return MediaControl_Run(&This->IMediaControl_iface);
5307 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout,
5308 FILTER_STATE *pState)
5310 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5312 return MediaControl_GetState(&This->IMediaControl_iface, dwMsTimeout, (OAFilterState*)pState);
5315 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5317 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5318 HRESULT hr = S_OK;
5319 int i;
5321 TRACE("(%p/%p)->(%p)\n", iface, This, pClock);
5323 EnterCriticalSection(&This->cs);
5325 for (i = 0;i < This->nFilters;i++)
5327 hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5328 if (FAILED(hr))
5329 break;
5332 if (FAILED(hr))
5334 for(;i >= 0;i--)
5335 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5337 else
5339 if (This->refClock)
5340 IReferenceClock_Release(This->refClock);
5341 This->refClock = pClock;
5342 if (This->refClock)
5343 IReferenceClock_AddRef(This->refClock);
5344 This->defaultclock = FALSE;
5346 if (This->HandleEcClockChanged)
5348 IMediaEventSink *pEventSink;
5349 HRESULT eshr;
5351 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (void **)&pEventSink);
5352 if (SUCCEEDED(eshr))
5354 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5355 IMediaEventSink_Release(pEventSink);
5360 LeaveCriticalSection(&This->cs);
5362 return hr;
5365 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5367 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5369 TRACE("(%p/%p)->(%p)\n", iface, This, ppClock);
5371 if (!ppClock)
5372 return E_POINTER;
5374 EnterCriticalSection(&This->cs);
5376 *ppClock = This->refClock;
5377 if (*ppClock)
5378 IReferenceClock_AddRef(*ppClock);
5380 LeaveCriticalSection(&This->cs);
5382 return S_OK;
5385 static const IMediaFilterVtbl IMediaFilter_VTable =
5387 MediaFilter_QueryInterface,
5388 MediaFilter_AddRef,
5389 MediaFilter_Release,
5390 MediaFilter_GetClassID,
5391 MediaFilter_Stop,
5392 MediaFilter_Pause,
5393 MediaFilter_Run,
5394 MediaFilter_GetState,
5395 MediaFilter_SetSyncSource,
5396 MediaFilter_GetSyncSource
5399 static inline IFilterGraphImpl *impl_from_IMediaEventSink(IMediaEventSink *iface)
5401 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventSink_iface);
5404 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, void **ppv)
5406 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5408 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5411 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5413 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5415 return IUnknown_AddRef(This->outer_unk);
5418 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5420 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5422 return IUnknown_Release(This->outer_unk);
5425 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG EventCode,
5426 LONG_PTR EventParam1, LONG_PTR EventParam2)
5428 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5429 Event evt;
5431 TRACE("(%p/%p)->(%d, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5433 /* We need thread safety here, let's use the events queue's one */
5434 EnterCriticalSection(&This->evqueue.msg_crst);
5436 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5438 TRACE("Process EC_COMPLETE notification\n");
5439 if (++This->EcCompleteCount == This->nRenderers)
5441 evt.lEventCode = EC_COMPLETE;
5442 evt.lParam1 = S_OK;
5443 evt.lParam2 = 0;
5444 TRACE("Send EC_COMPLETE to app\n");
5445 EventsQueue_PutEvent(&This->evqueue, &evt);
5446 if (!This->notif.disabled && This->notif.hWnd)
5448 TRACE("Send Window message\n");
5449 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5451 This->CompletionStatus = EC_COMPLETE;
5452 SetEvent(This->hEventCompletion);
5455 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5457 /* FIXME: Not handled yet */
5459 else
5461 evt.lEventCode = EventCode;
5462 evt.lParam1 = EventParam1;
5463 evt.lParam2 = EventParam2;
5464 EventsQueue_PutEvent(&This->evqueue, &evt);
5465 if (!This->notif.disabled && This->notif.hWnd)
5466 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5469 LeaveCriticalSection(&This->evqueue.msg_crst);
5470 return S_OK;
5473 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5475 MediaEventSink_QueryInterface,
5476 MediaEventSink_AddRef,
5477 MediaEventSink_Release,
5478 MediaEventSink_Notify
5481 static inline IFilterGraphImpl *impl_from_IGraphConfig(IGraphConfig *iface)
5483 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphConfig_iface);
5486 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, void **ppv)
5488 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5490 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5493 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5495 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5497 return IUnknown_AddRef(This->outer_unk);
5500 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5502 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5504 return IUnknown_Release(This->outer_unk);
5507 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *pOutputPin, IPin *pInputPin,
5508 const AM_MEDIA_TYPE *pmtFirstConnection, IBaseFilter *pUsingFilter, HANDLE hAbortEvent,
5509 DWORD dwFlags)
5511 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5513 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5515 return E_NOTIMPL;
5518 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface, IGraphConfigCallback *pCallback,
5519 void *pvContext, DWORD dwFlags, HANDLE hAbortEvent)
5521 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5522 HRESULT hr;
5524 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5526 if (hAbortEvent)
5527 FIXME("The parameter hAbortEvent is not handled!\n");
5529 EnterCriticalSection(&This->cs);
5531 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5533 LeaveCriticalSection(&This->cs);
5535 return hr;
5538 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5540 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5542 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5544 return E_NOTIMPL;
5547 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5549 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5551 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5553 return E_NOTIMPL;
5556 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5558 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5560 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5562 return E_NOTIMPL;
5565 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5567 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5569 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5571 return E_NOTIMPL;
5574 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5575 IPinConnection *pConnection, HANDLE hEventAbort)
5577 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5579 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5581 return E_NOTIMPL;
5584 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5585 DWORD dwFlags)
5587 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5589 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5591 return E_NOTIMPL;
5594 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5595 DWORD *dwFlags)
5597 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5599 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5601 return E_NOTIMPL;
5604 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *pFilter,
5605 DWORD dwFlags)
5607 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5609 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5611 return E_NOTIMPL;
5614 static const IGraphConfigVtbl IGraphConfig_VTable =
5616 GraphConfig_QueryInterface,
5617 GraphConfig_AddRef,
5618 GraphConfig_Release,
5619 GraphConfig_Reconnect,
5620 GraphConfig_Reconfigure,
5621 GraphConfig_AddFilterToCache,
5622 GraphConfig_EnumCacheFilter,
5623 GraphConfig_RemoveFilterFromCache,
5624 GraphConfig_GetStartTime,
5625 GraphConfig_PushThroughData,
5626 GraphConfig_SetFilterFlags,
5627 GraphConfig_GetFilterFlags,
5628 GraphConfig_RemoveFilterEx
5631 static inline IFilterGraphImpl *impl_from_IGraphVersion(IGraphVersion *iface)
5633 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphVersion_iface);
5636 static HRESULT WINAPI GraphVersion_QueryInterface(IGraphVersion *iface, REFIID riid, void **ppv)
5638 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5640 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5643 static ULONG WINAPI GraphVersion_AddRef(IGraphVersion *iface)
5645 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5647 return IUnknown_AddRef(This->outer_unk);
5650 static ULONG WINAPI GraphVersion_Release(IGraphVersion *iface)
5652 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5654 return IUnknown_Release(This->outer_unk);
5657 static HRESULT WINAPI GraphVersion_QueryVersion(IGraphVersion *iface, LONG *pVersion)
5659 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5661 if(!pVersion)
5662 return E_POINTER;
5664 TRACE("(%p)->(%p): current version %i\n", This, pVersion, This->version);
5666 *pVersion = This->version;
5667 return S_OK;
5670 static const IGraphVersionVtbl IGraphVersion_VTable =
5672 GraphVersion_QueryInterface,
5673 GraphVersion_AddRef,
5674 GraphVersion_Release,
5675 GraphVersion_QueryVersion,
5678 static const IUnknownVtbl IInner_VTable =
5680 FilterGraphInner_QueryInterface,
5681 FilterGraphInner_AddRef,
5682 FilterGraphInner_Release
5685 /* This is the only function that actually creates a FilterGraph class... */
5686 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5688 IFilterGraphImpl *fimpl;
5689 HRESULT hr;
5691 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5693 *ppObj = NULL;
5695 fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5696 fimpl->defaultclock = TRUE;
5697 fimpl->IUnknown_inner.lpVtbl = &IInner_VTable;
5698 fimpl->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5699 fimpl->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5700 fimpl->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5701 fimpl->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5702 fimpl->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5703 fimpl->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5704 fimpl->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5705 fimpl->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5706 fimpl->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5707 fimpl->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5708 fimpl->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5709 fimpl->IObjectWithSite_iface.lpVtbl = &IObjectWithSite_VTable;
5710 fimpl->IGraphVersion_iface.lpVtbl = &IGraphVersion_VTable;
5711 fimpl->ref = 1;
5712 fimpl->ppFiltersInGraph = NULL;
5713 fimpl->pFilterNames = NULL;
5714 fimpl->nFilters = 0;
5715 fimpl->filterCapacity = 0;
5716 fimpl->nameIndex = 1;
5717 fimpl->refClock = NULL;
5718 fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5719 fimpl->HandleEcComplete = TRUE;
5720 fimpl->HandleEcRepaint = TRUE;
5721 fimpl->HandleEcClockChanged = TRUE;
5722 fimpl->notif.hWnd = 0;
5723 fimpl->notif.disabled = FALSE;
5724 fimpl->nRenderers = 0;
5725 fimpl->EcCompleteCount = 0;
5726 fimpl->refClockProvider = NULL;
5727 fimpl->state = State_Stopped;
5728 fimpl->pSite = NULL;
5729 EventsQueue_Init(&fimpl->evqueue);
5730 InitializeCriticalSection(&fimpl->cs);
5731 fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5732 fimpl->nItfCacheEntries = 0;
5733 memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5734 fimpl->start_time = fimpl->pause_time = 0;
5735 fimpl->stop_position = -1;
5736 fimpl->punkFilterMapper2 = NULL;
5737 fimpl->recursioncount = 0;
5738 fimpl->version = 0;
5740 if (pUnkOuter)
5741 fimpl->outer_unk = pUnkOuter;
5742 else
5743 fimpl->outer_unk = &fimpl->IUnknown_inner;
5745 /* create Filtermapper aggregated. */
5746 hr = CoCreateInstance(&CLSID_FilterMapper2, fimpl->outer_unk, CLSCTX_INPROC_SERVER,
5747 &IID_IUnknown, (void**)&fimpl->punkFilterMapper2);
5749 if (FAILED(hr)) {
5750 ERR("Unable to create filter mapper (%x)\n", hr);
5751 if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5752 CloseHandle(fimpl->hEventCompletion);
5753 EventsQueue_Destroy(&fimpl->evqueue);
5754 fimpl->cs.DebugInfo->Spare[0] = 0;
5755 DeleteCriticalSection(&fimpl->cs);
5756 CoTaskMemFree(fimpl);
5757 return hr;
5760 *ppObj = &fimpl->IUnknown_inner;
5761 return S_OK;
5764 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5766 FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5767 return FilterGraph_create(pUnkOuter, ppObj);