quartz: Actually use the start time in SendRun.
[wine/multimedia.git] / dlls / quartz / filtergraph.c
blobf8d2ff22990684e876ae8666e4b3944533f28b40
1 /* DirectShow FilterGraph object (QUARTZ.DLL)
3 * Copyright 2002 Lionel Ulmer
4 * Copyright 2004 Christian Costa
6 * This file contains the (internal) driver registration functions,
7 * driver enumeration APIs and DirectDraw creation functions.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
25 #include <stdarg.h>
27 #define COBJMACROS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "winreg.h"
33 #include "shlwapi.h"
34 #include "dshow.h"
35 #include "wine/debug.h"
36 #include "quartz_private.h"
37 #include "ole2.h"
38 #include "olectl.h"
39 #include "strmif.h"
40 #include "vfwmsgs.h"
41 #include "evcode.h"
42 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
47 typedef struct {
48 HWND hWnd; /* Target window */
49 UINT msg; /* User window message */
50 LONG_PTR instance; /* User data */
51 int disabled; /* Disabled messages posting */
52 } WndNotify;
54 typedef struct {
55 LONG lEventCode; /* Event code */
56 LONG_PTR lParam1; /* Param1 */
57 LONG_PTR lParam2; /* Param2 */
58 } Event;
60 /* messages ring implementation for queuing events (taken from winmm) */
61 #define EVENTS_RING_BUFFER_INCREMENT 64
62 typedef struct {
63 Event* messages;
64 int ring_buffer_size;
65 int msg_tosave;
66 int msg_toget;
67 CRITICAL_SECTION msg_crst;
68 HANDLE msg_event; /* Signaled for no empty queue */
69 } EventsQueue;
71 static int EventsQueue_Init(EventsQueue* omr)
73 omr->msg_toget = 0;
74 omr->msg_tosave = 0;
75 omr->msg_event = CreateEventW(NULL, TRUE, FALSE, NULL);
76 omr->ring_buffer_size = EVENTS_RING_BUFFER_INCREMENT;
77 omr->messages = CoTaskMemAlloc(omr->ring_buffer_size * sizeof(Event));
78 ZeroMemory(omr->messages, omr->ring_buffer_size * sizeof(Event));
80 InitializeCriticalSection(&omr->msg_crst);
81 omr->msg_crst.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": EventsQueue.msg_crst");
82 return TRUE;
85 static int EventsQueue_Destroy(EventsQueue* omr)
87 CloseHandle(omr->msg_event);
88 CoTaskMemFree(omr->messages);
89 omr->msg_crst.DebugInfo->Spare[0] = 0;
90 DeleteCriticalSection(&omr->msg_crst);
91 return TRUE;
94 static int EventsQueue_PutEvent(EventsQueue* omr, const Event* evt)
96 EnterCriticalSection(&omr->msg_crst);
97 if ((omr->msg_toget == ((omr->msg_tosave + 1) % omr->ring_buffer_size)))
99 int old_ring_buffer_size = omr->ring_buffer_size;
100 omr->ring_buffer_size += EVENTS_RING_BUFFER_INCREMENT;
101 TRACE("omr->ring_buffer_size=%d\n",omr->ring_buffer_size);
102 omr->messages = CoTaskMemRealloc(omr->messages, omr->ring_buffer_size * sizeof(Event));
103 /* Now we need to rearrange the ring buffer so that the new
104 buffers just allocated are in between omr->msg_tosave and
105 omr->msg_toget.
107 if (omr->msg_tosave < omr->msg_toget)
109 memmove(&(omr->messages[omr->msg_toget + EVENTS_RING_BUFFER_INCREMENT]),
110 &(omr->messages[omr->msg_toget]),
111 sizeof(Event)*(old_ring_buffer_size - omr->msg_toget)
113 omr->msg_toget += EVENTS_RING_BUFFER_INCREMENT;
116 omr->messages[omr->msg_tosave] = *evt;
117 SetEvent(omr->msg_event);
118 omr->msg_tosave = (omr->msg_tosave + 1) % omr->ring_buffer_size;
119 LeaveCriticalSection(&omr->msg_crst);
120 return TRUE;
123 static int EventsQueue_GetEvent(EventsQueue* omr, Event* evt, LONG msTimeOut)
125 if (WaitForSingleObject(omr->msg_event, msTimeOut) != WAIT_OBJECT_0)
126 return FALSE;
128 EnterCriticalSection(&omr->msg_crst);
130 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
132 LeaveCriticalSection(&omr->msg_crst);
133 return FALSE;
136 *evt = omr->messages[omr->msg_toget];
137 omr->msg_toget = (omr->msg_toget + 1) % omr->ring_buffer_size;
139 /* Mark the buffer as empty if needed */
140 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
141 ResetEvent(omr->msg_event);
143 LeaveCriticalSection(&omr->msg_crst);
144 return TRUE;
147 #define MAX_ITF_CACHE_ENTRIES 3
148 typedef struct _ITF_CACHE_ENTRY {
149 const IID* riid;
150 IBaseFilter* filter;
151 IUnknown* iface;
152 } ITF_CACHE_ENTRY;
154 typedef struct _IFilterGraphImpl {
155 const IFilterGraph2Vtbl *IFilterGraph2_vtbl;
156 const IMediaControlVtbl *IMediaControl_vtbl;
157 const IMediaSeekingVtbl *IMediaSeeking_vtbl;
158 const IBasicAudioVtbl *IBasicAudio_vtbl;
159 const IBasicVideo2Vtbl *IBasicVideo_vtbl;
160 const IVideoWindowVtbl *IVideoWindow_vtbl;
161 const IMediaEventExVtbl *IMediaEventEx_vtbl;
162 const IMediaFilterVtbl *IMediaFilter_vtbl;
163 const IMediaEventSinkVtbl *IMediaEventSink_vtbl;
164 const IGraphConfigVtbl *IGraphConfig_vtbl;
165 const IMediaPositionVtbl *IMediaPosition_vtbl;
166 const IUnknownVtbl * IInner_vtbl;
167 /* IAMGraphStreams */
168 /* IAMStats */
169 /* IFilterChain */
170 /* IFilterMapper2 */
171 /* IGraphVersion */
172 /* IQueueCommand */
173 /* IRegisterServiceProvider */
174 /* IResourceMananger */
175 /* IServiceProvider */
176 /* IVideoFrameStep */
178 LONG ref;
179 IUnknown *punkFilterMapper2;
180 IFilterMapper2 * pFilterMapper2;
181 IBaseFilter ** ppFiltersInGraph;
182 LPWSTR * pFilterNames;
183 int nFilters;
184 int filterCapacity;
185 LONG nameIndex;
186 IReferenceClock *refClock;
187 EventsQueue evqueue;
188 HANDLE hEventCompletion;
189 int CompletionStatus;
190 WndNotify notif;
191 int nRenderers;
192 int EcCompleteCount;
193 int HandleEcComplete;
194 int HandleEcRepaint;
195 int HandleEcClockChanged;
196 OAFilterState state;
197 CRITICAL_SECTION cs;
198 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
199 int nItfCacheEntries;
200 IUnknown * pUnkOuter;
201 BOOL bUnkOuterValid;
202 BOOL bAggregatable;
203 GUID timeformatseek;
204 REFERENCE_TIME start_time;
205 REFERENCE_TIME pause_time;
206 LONGLONG stop_position;
207 LONG recursioncount;
208 } IFilterGraphImpl;
210 static HRESULT Filtergraph_QueryInterface(IFilterGraphImpl *This,
211 REFIID riid, LPVOID * ppv);
212 static ULONG Filtergraph_AddRef(IFilterGraphImpl *This);
213 static ULONG Filtergraph_Release(IFilterGraphImpl *This);
215 static HRESULT WINAPI FilterGraphInner_QueryInterface(IUnknown * iface,
216 REFIID riid,
217 LPVOID *ppvObj) {
218 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
219 TRACE("(%p)->(%s (%p), %p)\n", This, debugstr_guid(riid), riid, ppvObj);
221 if (This->bAggregatable)
222 This->bUnkOuterValid = TRUE;
224 if (IsEqualGUID(&IID_IUnknown, riid)) {
225 *ppvObj = &(This->IInner_vtbl);
226 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
227 } else if (IsEqualGUID(&IID_IFilterGraph, riid) ||
228 IsEqualGUID(&IID_IFilterGraph2, riid) ||
229 IsEqualGUID(&IID_IGraphBuilder, riid)) {
230 *ppvObj = &(This->IFilterGraph2_vtbl);
231 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj);
232 } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
233 *ppvObj = &(This->IMediaControl_vtbl);
234 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj);
235 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
236 *ppvObj = &(This->IMediaSeeking_vtbl);
237 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
238 } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
239 *ppvObj = &(This->IBasicAudio_vtbl);
240 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj);
241 } else if (IsEqualGUID(&IID_IBasicVideo, riid) ||
242 IsEqualGUID(&IID_IBasicVideo2, riid)) {
243 *ppvObj = &(This->IBasicVideo_vtbl);
244 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj);
245 } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
246 *ppvObj = &(This->IVideoWindow_vtbl);
247 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj);
248 } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
249 IsEqualGUID(&IID_IMediaEventEx, riid)) {
250 *ppvObj = &(This->IMediaEventEx_vtbl);
251 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
252 } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
253 IsEqualGUID(&IID_IPersist, riid)) {
254 *ppvObj = &(This->IMediaFilter_vtbl);
255 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj);
256 } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
257 *ppvObj = &(This->IMediaEventSink_vtbl);
258 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj);
259 } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
260 *ppvObj = &(This->IGraphConfig_vtbl);
261 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
262 } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
263 *ppvObj = &(This->IMediaPosition_vtbl);
264 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj);
265 } else if (IsEqualGUID(&IID_IFilterMapper, riid)) {
266 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj);
267 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
268 } else if (IsEqualGUID(&IID_IFilterMapper2, riid)) {
269 *ppvObj = This->pFilterMapper2;
270 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
271 } else {
272 *ppvObj = NULL;
273 FIXME("unknown interface %s\n", debugstr_guid(riid));
274 return E_NOINTERFACE;
277 IUnknown_AddRef((IUnknown *)(*ppvObj));
278 return S_OK;
281 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown * iface) {
282 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
283 ULONG ref = InterlockedIncrement(&This->ref);
285 TRACE("(%p)->(): new ref = %d\n", This, ref);
287 return ref;
290 static ULONG WINAPI FilterGraphInner_Release(IUnknown * iface)
292 ICOM_THIS_MULTI(IFilterGraphImpl, IInner_vtbl, iface);
293 ULONG ref = InterlockedDecrement(&This->ref);
295 TRACE("(%p)->(): new ref = %d\n", This, ref);
297 if (ref == 0) {
298 int i;
300 This->ref = 1; /* guard against reentrancy (aggregation). */
302 IMediaControl_Stop((IMediaControl*)&(This->IMediaControl_vtbl));
304 while (This->nFilters)
305 IFilterGraph2_RemoveFilter((IFilterGraph2*)This, This->ppFiltersInGraph[0]);
307 if (This->refClock)
308 IReferenceClock_Release(This->refClock);
310 for (i = 0; i < This->nItfCacheEntries; i++)
312 if (This->ItfCacheEntries[i].iface)
313 IUnknown_Release(This->ItfCacheEntries[i].iface);
316 /* AddRef on controlling IUnknown, to compensate for Release of cached IFilterMapper2 interface below.
318 * NOTE: Filtergraph_AddRef isn't suitable, because bUnkOuterValid may be FALSE but punkOuter non-NULL
319 * and already passed as punkOuter to filtermapper in FilterGraph_create - this will happen in case of
320 * CoCreateInstance of filtergraph with non-null pUnkOuter and REFIID other than IID_Unknown that is
321 * cleaning up after error. */
322 if (This->pUnkOuter) IUnknown_AddRef(This->pUnkOuter);
323 else IUnknown_AddRef((IUnknown*)&This->IInner_vtbl);
325 IFilterMapper2_Release(This->pFilterMapper2);
326 IUnknown_Release(This->punkFilterMapper2);
328 CloseHandle(This->hEventCompletion);
329 EventsQueue_Destroy(&This->evqueue);
330 This->cs.DebugInfo->Spare[0] = 0;
331 DeleteCriticalSection(&This->cs);
332 CoTaskMemFree(This->ppFiltersInGraph);
333 CoTaskMemFree(This->pFilterNames);
334 CoTaskMemFree(This);
336 return ref;
340 /*** IUnknown methods ***/
341 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface,
342 REFIID riid,
343 LPVOID*ppvObj) {
344 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
346 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
347 return Filtergraph_QueryInterface(This, riid, ppvObj);
350 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface) {
351 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
353 TRACE("(%p/%p)->() calling FilterGraph AddRef\n", This, iface);
355 return Filtergraph_AddRef(This);
358 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface) {
359 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
361 TRACE("(%p/%p)->() calling FilterGraph Release\n", This, iface);
363 return Filtergraph_Release(This);
366 /*** IFilterGraph methods ***/
367 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface,
368 IBaseFilter *pFilter,
369 LPCWSTR pName) {
370 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
371 HRESULT hr;
372 int i,j;
373 WCHAR* wszFilterName = NULL;
374 int duplicate_name = FALSE;
376 TRACE("(%p/%p)->(%p, %s (%p))\n", This, iface, pFilter, debugstr_w(pName), pName);
378 if (!pFilter)
379 return E_POINTER;
381 wszFilterName = CoTaskMemAlloc( (pName ? strlenW(pName) + 6 : 5) * sizeof(WCHAR) );
383 if (pName)
385 /* Check if name already exists */
386 for(i = 0; i < This->nFilters; i++)
387 if (!strcmpW(This->pFilterNames[i], pName))
389 duplicate_name = TRUE;
390 break;
394 /* If no name given or name already existing, generate one */
395 if (!pName || duplicate_name)
397 static const WCHAR wszFmt1[] = {'%','s',' ','%','0','4','d',0};
398 static const WCHAR wszFmt2[] = {'%','0','4','d',0};
400 for (j = 0; j < 10000 ; j++)
402 /* Create name */
403 if (pName)
404 sprintfW(wszFilterName, wszFmt1, pName, This->nameIndex);
405 else
406 sprintfW(wszFilterName, wszFmt2, This->nameIndex);
407 TRACE("Generated name %s\n", debugstr_w(wszFilterName));
409 /* Check if the generated name already exists */
410 for(i = 0; i < This->nFilters; i++)
411 if (!strcmpW(This->pFilterNames[i], wszFilterName))
412 break;
414 /* Compute next index and exit if generated name is suitable */
415 if (This->nameIndex++ == 10000)
416 This->nameIndex = 1;
417 if (i == This->nFilters)
418 break;
420 /* Unable to find a suitable name */
421 if (j == 10000)
423 CoTaskMemFree(wszFilterName);
424 return VFW_E_DUPLICATE_NAME;
427 else
428 memcpy(wszFilterName, pName, (strlenW(pName) + 1) * sizeof(WCHAR));
430 if (This->nFilters + 1 > This->filterCapacity)
432 int newCapacity = This->filterCapacity ? 2 * This->filterCapacity : 1;
433 IBaseFilter ** ppNewFilters = CoTaskMemAlloc(newCapacity * sizeof(IBaseFilter*));
434 LPWSTR * pNewNames = CoTaskMemAlloc(newCapacity * sizeof(LPWSTR));
435 memcpy(ppNewFilters, This->ppFiltersInGraph, This->nFilters * sizeof(IBaseFilter*));
436 memcpy(pNewNames, This->pFilterNames, This->nFilters * sizeof(LPWSTR));
437 if (This->filterCapacity)
439 CoTaskMemFree(This->ppFiltersInGraph);
440 CoTaskMemFree(This->pFilterNames);
442 This->ppFiltersInGraph = ppNewFilters;
443 This->pFilterNames = pNewNames;
444 This->filterCapacity = newCapacity;
447 hr = IBaseFilter_JoinFilterGraph(pFilter, (IFilterGraph *)This, wszFilterName);
449 if (SUCCEEDED(hr))
451 IBaseFilter_AddRef(pFilter);
452 This->ppFiltersInGraph[This->nFilters] = pFilter;
453 This->pFilterNames[This->nFilters] = wszFilterName;
454 This->nFilters++;
455 IBaseFilter_SetSyncSource(pFilter, This->refClock);
457 else
458 CoTaskMemFree(wszFilterName);
460 if (SUCCEEDED(hr) && duplicate_name)
461 return VFW_S_DUPLICATE_NAME;
463 return hr;
466 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
468 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
469 int i;
470 HRESULT hr = E_FAIL;
472 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
474 /* FIXME: check graph is stopped */
476 for (i = 0; i < This->nFilters; i++)
478 if (This->ppFiltersInGraph[i] == pFilter)
480 IEnumPins *penumpins = NULL;
481 FILTER_STATE state;
483 TRACE("Removing filter %s\n", debugstr_w(This->pFilterNames[i]));
484 IBaseFilter_GetState(pFilter, 0, &state);
485 if (state == State_Running)
486 IBaseFilter_Pause(pFilter);
487 if (state != State_Stopped)
488 IBaseFilter_Stop(pFilter);
490 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
491 if (SUCCEEDED(hr)) {
492 IPin *ppin;
493 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
495 IPin *victim = NULL;
496 HRESULT h;
497 IPin_ConnectedTo(ppin, &victim);
498 if (victim)
500 h = IPin_Disconnect(victim);
501 TRACE("Disconnect other side: %08x\n", h);
502 if (h == VFW_E_NOT_STOPPED)
504 PIN_INFO pinfo;
505 IPin_QueryPinInfo(victim, &pinfo);
507 IBaseFilter_GetState(pinfo.pFilter, 0, &state);
508 if (state == State_Running)
509 IBaseFilter_Pause(pinfo.pFilter);
510 IBaseFilter_Stop(pinfo.pFilter);
511 IBaseFilter_Release(pinfo.pFilter);
512 h = IPin_Disconnect(victim);
513 TRACE("Disconnect retry: %08x\n", h);
515 IPin_Release(victim);
517 h = IPin_Disconnect(ppin);
518 TRACE("Disconnect 2: %08x\n", h);
520 IPin_Release(ppin);
522 IEnumPins_Release(penumpins);
525 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, This->pFilterNames[i]);
526 if (SUCCEEDED(hr))
528 IBaseFilter_SetSyncSource(pFilter, NULL);
529 IBaseFilter_Release(pFilter);
530 CoTaskMemFree(This->pFilterNames[i]);
531 memmove(This->ppFiltersInGraph+i, This->ppFiltersInGraph+i+1, sizeof(IBaseFilter*)*(This->nFilters - 1 - i));
532 memmove(This->pFilterNames+i, This->pFilterNames+i+1, sizeof(LPWSTR)*(This->nFilters - 1 - i));
533 This->nFilters--;
534 /* Invalidate interfaces in the cache */
535 for (i = 0; i < This->nItfCacheEntries; i++)
536 if (pFilter == This->ItfCacheEntries[i].filter)
538 IUnknown_Release(This->ItfCacheEntries[i].iface);
539 This->ItfCacheEntries[i].iface = NULL;
540 This->ItfCacheEntries[i].filter = NULL;
542 return S_OK;
544 break;
548 return hr; /* FIXME: check this error code */
551 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface,
552 IEnumFilters **ppEnum) {
553 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
555 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
557 return IEnumFiltersImpl_Construct(This->ppFiltersInGraph, This->nFilters, ppEnum);
560 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface,
561 LPCWSTR pName,
562 IBaseFilter **ppFilter) {
563 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
564 int i;
566 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_w(pName), pName, ppFilter);
568 if (!ppFilter)
569 return E_POINTER;
571 for (i = 0; i < This->nFilters; i++)
573 if (!strcmpW(pName, This->pFilterNames[i]))
575 *ppFilter = This->ppFiltersInGraph[i];
576 IBaseFilter_AddRef(*ppFilter);
577 return S_OK;
581 *ppFilter = NULL;
582 return VFW_E_NOT_FOUND;
585 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
586 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
588 static HRESULT CheckCircularConnection(IFilterGraphImpl *This, IPin *out, IPin *in)
590 #if 1
591 HRESULT hr;
592 PIN_INFO info_out, info_in;
594 hr = IPin_QueryPinInfo(out, &info_out);
595 if (FAILED(hr))
596 return hr;
597 if (info_out.dir != PINDIR_OUTPUT)
599 IBaseFilter_Release(info_out.pFilter);
600 return E_UNEXPECTED;
603 hr = IPin_QueryPinInfo(in, &info_in);
604 if (SUCCEEDED(hr))
605 IBaseFilter_Release(info_in.pFilter);
606 if (FAILED(hr))
607 goto out;
608 if (info_in.dir != PINDIR_INPUT)
610 hr = E_UNEXPECTED;
611 goto out;
614 if (info_out.pFilter == info_in.pFilter)
615 hr = VFW_E_CIRCULAR_GRAPH;
616 else
618 IEnumPins *enumpins;
619 IPin *test;
621 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
622 if (FAILED(hr))
623 goto out;
625 IEnumPins_Reset(enumpins);
626 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
628 PIN_DIRECTION dir = PINDIR_OUTPUT;
629 IPin_QueryDirection(test, &dir);
630 if (dir == PINDIR_INPUT)
632 IPin *victim = NULL;
633 IPin_ConnectedTo(test, &victim);
634 if (victim)
636 hr = CheckCircularConnection(This, victim, in);
637 IPin_Release(victim);
638 if (FAILED(hr))
640 IPin_Release(test);
641 break;
645 IPin_Release(test);
647 IEnumPins_Release(enumpins);
650 out:
651 IBaseFilter_Release(info_out.pFilter);
652 if (FAILED(hr))
653 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
654 return hr;
655 #else
656 /* Debugging filtergraphs not enabled */
657 return S_OK;
658 #endif
662 /* NOTE: despite the implication, it doesn't matter which
663 * way round you put in the input and output pins */
664 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface,
665 IPin *ppinIn,
666 IPin *ppinOut,
667 const AM_MEDIA_TYPE *pmt) {
668 PIN_DIRECTION dir;
669 HRESULT hr;
671 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
673 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
675 /* FIXME: check pins are in graph */
677 if (TRACE_ON(quartz))
679 PIN_INFO PinInfo;
681 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
682 if (FAILED(hr))
683 return hr;
685 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
686 IBaseFilter_Release(PinInfo.pFilter);
688 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
689 if (FAILED(hr))
690 return hr;
692 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
693 IBaseFilter_Release(PinInfo.pFilter);
696 hr = IPin_QueryDirection(ppinIn, &dir);
697 if (SUCCEEDED(hr))
699 if (dir == PINDIR_INPUT)
701 hr = CheckCircularConnection(This, ppinOut, ppinIn);
702 if (SUCCEEDED(hr))
703 hr = IPin_Connect(ppinOut, ppinIn, pmt);
705 else
707 hr = CheckCircularConnection(This, ppinIn, ppinOut);
708 if (SUCCEEDED(hr))
709 hr = IPin_Connect(ppinIn, ppinOut, pmt);
713 return hr;
716 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface,
717 IPin *ppin) {
718 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
719 IPin *pConnectedTo = NULL;
720 HRESULT hr;
721 PIN_DIRECTION pindir;
723 IPin_QueryDirection(ppin, &pindir);
724 hr = IPin_ConnectedTo(ppin, &pConnectedTo);
725 if (FAILED(hr)) {
726 TRACE("Querying connected to failed: %x\n", hr);
727 return hr;
729 IPin_Disconnect(ppin);
730 IPin_Disconnect(pConnectedTo);
731 if (pindir == PINDIR_INPUT)
732 hr = IPin_Connect(pConnectedTo, ppin, NULL);
733 else
734 hr = IPin_Connect(ppin, pConnectedTo, NULL);
735 IPin_Release(pConnectedTo);
736 if (FAILED(hr))
737 WARN("Reconnecting pins failed, pins are not connected now..\n");
738 TRACE("(%p->%p) -- %p %p -> %x\n", iface, This, ppin, pConnectedTo, hr);
739 return hr;
742 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
744 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
746 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
748 if (!ppin)
749 return E_POINTER;
751 return IPin_Disconnect(ppin);
754 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface) {
755 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
756 IReferenceClock *pClock = NULL;
757 HRESULT hr;
759 TRACE("(%p/%p)->() semi-stub\n", iface, This);
761 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
763 if (SUCCEEDED(hr))
765 hr = IMediaFilter_SetSyncSource((IMediaFilter*)&(This->IMediaFilter_vtbl), pClock);
766 IReferenceClock_Release(pClock);
769 return hr;
772 static HRESULT GetFilterInfo(IMoniker* pMoniker, GUID* pclsid, VARIANT* pvar)
774 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
775 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
776 IPropertyBag * pPropBagCat = NULL;
777 HRESULT hr;
779 VariantInit(pvar);
781 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
783 if (SUCCEEDED(hr))
784 hr = IPropertyBag_Read(pPropBagCat, wszClsidName, pvar, NULL);
786 if (SUCCEEDED(hr))
787 hr = CLSIDFromString(V_UNION(pvar, bstrVal), pclsid);
789 VariantClear(pvar);
791 if (SUCCEEDED(hr))
792 hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL);
794 if (SUCCEEDED(hr))
795 TRACE("Moniker = %s - %s\n", debugstr_guid(pclsid), debugstr_w(V_UNION(pvar, bstrVal)));
797 if (pPropBagCat)
798 IPropertyBag_Release(pPropBagCat);
800 return hr;
803 static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPin*** pppins, ULONG* pnb)
805 HRESULT hr;
806 ULONG nb = 0;
808 TRACE("(%p, %p, %p, %p)\n", pfilter, pinputpin, pppins, pnb);
809 hr = IPin_QueryInternalConnections(pinputpin, NULL, &nb);
810 if (hr == S_OK) {
811 /* Rendered input */
812 } else if (hr == S_FALSE) {
813 *pppins = CoTaskMemAlloc(sizeof(IPin*)*nb);
814 hr = IPin_QueryInternalConnections(pinputpin, *pppins, &nb);
815 if (hr != S_OK) {
816 WARN("Error (%x)\n", hr);
818 } else if (hr == E_NOTIMPL) {
819 /* Input connected to all outputs */
820 IEnumPins* penumpins;
821 IPin* ppin;
822 int i = 0;
823 TRACE("E_NOTIMPL\n");
824 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
825 if (FAILED(hr)) {
826 WARN("filter Enumpins failed (%x)\n", hr);
827 return hr;
829 i = 0;
830 /* Count output pins */
831 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
832 PIN_DIRECTION pindir;
833 IPin_QueryDirection(ppin, &pindir);
834 if (pindir == PINDIR_OUTPUT)
835 i++;
836 IPin_Release(ppin);
838 *pppins = CoTaskMemAlloc(sizeof(IPin*)*i);
839 /* Retrieve output pins */
840 IEnumPins_Reset(penumpins);
841 i = 0;
842 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
843 PIN_DIRECTION pindir;
844 IPin_QueryDirection(ppin, &pindir);
845 if (pindir == PINDIR_OUTPUT)
846 (*pppins)[i++] = ppin;
847 else
848 IPin_Release(ppin);
850 IEnumPins_Release(penumpins);
851 nb = i;
852 if (FAILED(hr)) {
853 WARN("Next failed (%x)\n", hr);
854 return hr;
856 } else if (FAILED(hr)) {
857 WARN("Cannot get internal connection (%x)\n", hr);
858 return hr;
861 *pnb = nb;
862 return S_OK;
865 /*** IGraphBuilder methods ***/
866 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IPin *ppinIn)
868 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
869 HRESULT hr;
870 AM_MEDIA_TYPE* mt = NULL;
871 IEnumMediaTypes* penummt = NULL;
872 ULONG nbmt;
873 IEnumPins* penumpins;
874 IEnumMoniker* pEnumMoniker;
875 GUID tab[2];
876 ULONG nb;
877 IMoniker* pMoniker;
878 ULONG pin;
879 PIN_INFO PinInfo;
880 CLSID FilterCLSID;
881 PIN_DIRECTION dir;
883 TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
885 if (TRACE_ON(quartz))
887 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
888 if (FAILED(hr))
889 return hr;
891 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
892 IBaseFilter_Release(PinInfo.pFilter);
894 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
895 if (FAILED(hr))
896 return hr;
898 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
899 IBaseFilter_Release(PinInfo.pFilter);
902 EnterCriticalSection(&This->cs);
903 ++This->recursioncount;
904 if (This->recursioncount >= 5)
906 WARN("Recursion count has reached %d\n", This->recursioncount);
907 hr = VFW_E_CANNOT_CONNECT;
908 goto out;
911 hr = IPin_QueryDirection(ppinOut, &dir);
912 if (FAILED(hr))
913 goto out;
915 if (dir == PINDIR_INPUT)
917 IPin *temp;
919 temp = ppinIn;
920 ppinIn = ppinOut;
921 ppinOut = temp;
924 hr = CheckCircularConnection(This, ppinOut, ppinIn);
925 if (FAILED(hr))
926 goto out;
928 /* Try direct connection first */
929 hr = IPin_Connect(ppinOut, ppinIn, NULL);
930 if (SUCCEEDED(hr))
931 goto out;
933 TRACE("Direct connection failed, trying to render using extra filters\n");
935 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
936 if (FAILED(hr))
937 goto out;
939 hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
940 IBaseFilter_Release(PinInfo.pFilter);
941 if (FAILED(hr))
942 goto out;
944 /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream
945 * filter to the minor mediatype of input pin of the renderer */
946 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
947 if (FAILED(hr))
949 WARN("EnumMediaTypes (%x)\n", hr);
950 goto out;
953 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
954 if (FAILED(hr)) {
955 WARN("IEnumMediaTypes_Next (%x)\n", hr);
956 goto out;
959 if (!nbmt)
961 WARN("No media type found!\n");
962 hr = VFW_E_INVALIDMEDIATYPE;
963 goto out;
965 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
966 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
968 /* Try to find a suitable filter that can connect to the pin to render */
969 tab[0] = mt->majortype;
970 tab[1] = mt->subtype;
971 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
972 if (FAILED(hr)) {
973 WARN("Unable to enum filters (%x)\n", hr);
974 goto out;
977 hr = VFW_E_CANNOT_RENDER;
978 while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
980 VARIANT var;
981 GUID clsid;
982 IPin** ppins;
983 IPin* ppinfilter = NULL;
984 IBaseFilter* pfilter = NULL;
986 hr = GetFilterInfo(pMoniker, &clsid, &var);
987 IMoniker_Release(pMoniker);
988 if (FAILED(hr)) {
989 WARN("Unable to retrieve filter info (%x)\n", hr);
990 goto error;
993 if (IsEqualGUID(&clsid, &FilterCLSID)) {
994 /* Skip filter (same as the one the output pin belongs to) */
995 goto error;
998 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
999 if (FAILED(hr)) {
1000 WARN("Unable to create filter (%x), trying next one\n", hr);
1001 goto error;
1004 hr = IFilterGraph2_AddFilter(iface, pfilter, V_UNION(&var, bstrVal));
1005 if (FAILED(hr)) {
1006 WARN("Unable to add filter (%x)\n", hr);
1007 IBaseFilter_Release(pfilter);
1008 pfilter = NULL;
1009 goto error;
1012 VariantClear(&var);
1014 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1015 if (FAILED(hr)) {
1016 WARN("Enumpins (%x)\n", hr);
1017 goto error;
1020 hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin);
1021 IEnumPins_Release(penumpins);
1023 if (FAILED(hr)) {
1024 WARN("Obtaining next pin: (%x)\n", hr);
1025 goto error;
1027 if (pin == 0) {
1028 WARN("Cannot use this filter: no pins\n");
1029 goto error;
1032 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1033 if (FAILED(hr)) {
1034 TRACE("Cannot connect to filter (%x), trying next one\n", hr);
1035 goto error;
1037 TRACE("Successfully connected to filter, follow chain...\n");
1039 /* Render all output pins of the filter by calling IFilterGraph2_Connect on each of them */
1040 hr = GetInternalConnections(pfilter, ppinfilter, &ppins, &nb);
1042 if (SUCCEEDED(hr)) {
1043 unsigned int i;
1044 if (nb == 0) {
1045 IPin_Disconnect(ppinfilter);
1046 IPin_Disconnect(ppinOut);
1047 goto error;
1049 TRACE("pins to consider: %d\n", nb);
1050 for(i = 0; i < nb; i++)
1052 LPWSTR pinname = NULL;
1054 TRACE("Processing pin %u\n", i);
1056 hr = IPin_QueryId(ppins[i], &pinname);
1057 if (SUCCEEDED(hr))
1059 if (pinname[0] == '~')
1061 TRACE("Pinname=%s, skipping\n", debugstr_w(pinname));
1062 hr = E_FAIL;
1064 else
1065 hr = IFilterGraph2_Connect(iface, ppins[i], ppinIn);
1066 CoTaskMemFree(pinname);
1069 if (FAILED(hr)) {
1070 TRACE("Cannot connect pin %p (%x)\n", ppinfilter, hr);
1072 IPin_Release(ppins[i]);
1073 if (SUCCEEDED(hr)) break;
1075 while (++i < nb) IPin_Release(ppins[i]);
1076 CoTaskMemFree(ppins);
1077 IPin_Release(ppinfilter);
1078 IBaseFilter_Release(pfilter);
1079 if (FAILED(hr))
1081 IPin_Disconnect(ppinfilter);
1082 IPin_Disconnect(ppinOut);
1083 IFilterGraph2_RemoveFilter(iface, pfilter);
1084 continue;
1086 break;
1089 error:
1090 VariantClear(&var);
1091 if (ppinfilter) IPin_Release(ppinfilter);
1092 if (pfilter) {
1093 IFilterGraph2_RemoveFilter(iface, pfilter);
1094 IBaseFilter_Release(pfilter);
1098 out:
1099 if (penummt)
1100 IEnumMediaTypes_Release(penummt);
1101 if (mt)
1102 DeleteMediaType(mt);
1103 --This->recursioncount;
1104 LeaveCriticalSection(&This->cs);
1105 TRACE("--> %08x\n", hr);
1106 return SUCCEEDED(hr) ? S_OK : hr;
1109 static HRESULT FilterGraph2_RenderRecurse(IFilterGraphImpl *This, IPin *ppinOut)
1111 /* This pin has been connected now, try to call render on all pins that aren't connected */
1112 IPin *to = NULL;
1113 PIN_INFO info;
1114 IEnumPins *enumpins = NULL;
1115 BOOL renderany = FALSE;
1116 BOOL renderall = TRUE;
1118 IPin_QueryPinInfo(ppinOut, &info);
1120 IBaseFilter_EnumPins(info.pFilter, &enumpins);
1121 /* Don't need to hold a reference, IEnumPins does */
1122 IBaseFilter_Release(info.pFilter);
1124 IEnumPins_Reset(enumpins);
1125 while (IEnumPins_Next(enumpins, 1, &to, NULL) == S_OK)
1127 PIN_DIRECTION dir = PINDIR_INPUT;
1129 IPin_QueryDirection(to, &dir);
1131 if (dir == PINDIR_OUTPUT)
1133 IPin *out = NULL;
1135 IPin_ConnectedTo(to, &out);
1136 if (!out)
1138 HRESULT hr;
1139 hr = IFilterGraph2_Render((IFilterGraph2 *)&This->IFilterGraph2_vtbl, to);
1140 if (SUCCEEDED(hr))
1141 renderany = TRUE;
1142 else
1143 renderall = FALSE;
1145 else
1146 IPin_Release(out);
1149 IPin_Release(to);
1152 IEnumPins_Release(enumpins);
1154 if (renderall)
1155 return S_OK;
1157 if (renderany)
1158 return VFW_S_PARTIAL_RENDER;
1160 return VFW_E_CANNOT_RENDER;
1163 /* Ogg hates me if I create a direct rendering method
1165 * It can only connect to a pin properly once, so use a recursive method that does
1167 * +----+ --- (PIN 1) (Render is called on this pin)
1168 * | |
1169 * +----+ --- (PIN 2)
1171 * Enumerate possible renderers that EXACTLY match the requested type
1173 * If none is available, try to add intermediate filters that can connect to the input pin
1174 * then call Render on that intermediate pin's output pins
1175 * if it succeeds: Render returns success, if it doesn't, the intermediate filter is removed,
1176 * and another filter that can connect to the input pin is tried
1177 * if we run out of filters that can, give up and return VFW_E_CANNOT_RENDER
1178 * It's recursive, but fun!
1181 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *ppinOut)
1183 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1184 IEnumMediaTypes* penummt;
1185 AM_MEDIA_TYPE* mt;
1186 ULONG nbmt;
1187 HRESULT hr;
1189 IEnumMoniker* pEnumMoniker;
1190 GUID tab[4];
1191 ULONG nb;
1192 IMoniker* pMoniker;
1193 INT x;
1195 TRACE("(%p/%p)->(%p)\n", This, iface, ppinOut);
1197 if (TRACE_ON(quartz))
1199 PIN_INFO PinInfo;
1201 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
1202 if (FAILED(hr))
1203 return hr;
1205 TRACE("Filter owning pin => %p\n", PinInfo.pFilter);
1206 IBaseFilter_Release(PinInfo.pFilter);
1209 /* Try to find out if there is a renderer for the specified subtype already, and use that
1211 EnterCriticalSection(&This->cs);
1212 for (x = 0; x < This->nFilters; ++x)
1214 IEnumPins *enumpins = NULL;
1215 IPin *pin = NULL;
1217 hr = IBaseFilter_EnumPins(This->ppFiltersInGraph[x], &enumpins);
1219 if (FAILED(hr) || !enumpins)
1220 continue;
1222 IEnumPins_Reset(enumpins);
1223 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
1225 IPin *to = NULL;
1226 PIN_DIRECTION dir = PINDIR_OUTPUT;
1228 IPin_QueryDirection(pin, &dir);
1229 if (dir != PINDIR_INPUT)
1231 IPin_Release(pin);
1232 continue;
1234 IPin_ConnectedTo(pin, &to);
1236 if (to == NULL)
1238 hr = IPin_Connect(ppinOut, pin, NULL);
1239 if (SUCCEEDED(hr))
1241 TRACE("Connected successfully %p/%p, %08x look if we should render more!\n", ppinOut, pin, hr);
1242 IPin_Release(pin);
1244 hr = FilterGraph2_RenderRecurse(This, pin);
1245 if (FAILED(hr))
1247 IPin_Disconnect(ppinOut);
1248 IPin_Disconnect(pin);
1249 continue;
1251 IEnumPins_Release(enumpins);
1252 LeaveCriticalSection(&This->cs);
1253 return hr;
1255 WARN("Could not connect!\n");
1257 else
1258 IPin_Release(to);
1260 IPin_Release(pin);
1262 IEnumPins_Release(enumpins);
1265 LeaveCriticalSection(&This->cs);
1267 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
1268 if (FAILED(hr)) {
1269 WARN("EnumMediaTypes (%x)\n", hr);
1270 return hr;
1273 IEnumMediaTypes_Reset(penummt);
1275 /* Looks like no existing renderer of the kind exists
1276 * Try adding new ones
1278 tab[0] = tab[1] = GUID_NULL;
1279 while (SUCCEEDED(hr))
1281 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
1282 if (FAILED(hr)) {
1283 WARN("IEnumMediaTypes_Next (%x)\n", hr);
1284 break;
1286 if (!nbmt)
1288 hr = VFW_E_CANNOT_RENDER;
1289 break;
1291 else
1293 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1294 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1296 /* Only enumerate once, this doesn't account for all previous ones, but this should be enough nonetheless */
1297 if (IsEqualIID(&tab[0], &mt->majortype) && IsEqualIID(&tab[1], &mt->subtype))
1299 DeleteMediaType(mt);
1300 continue;
1303 /* Try to find a suitable renderer with the same media type */
1304 tab[0] = mt->majortype;
1305 tab[1] = mt->subtype;
1306 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1307 if (FAILED(hr))
1309 WARN("Unable to enum filters (%x)\n", hr);
1310 break;
1313 hr = E_FAIL;
1315 while (IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1317 VARIANT var;
1318 GUID clsid;
1319 IPin* ppinfilter;
1320 IBaseFilter* pfilter = NULL;
1321 IEnumPins* penumpins = NULL;
1322 ULONG pin;
1324 hr = GetFilterInfo(pMoniker, &clsid, &var);
1325 IMoniker_Release(pMoniker);
1326 if (FAILED(hr)) {
1327 WARN("Unable to retrieve filter info (%x)\n", hr);
1328 goto error;
1331 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
1332 if (FAILED(hr))
1334 WARN("Unable to create filter (%x), trying next one\n", hr);
1335 goto error;
1338 hr = IFilterGraph2_AddFilter(iface, pfilter, V_UNION(&var, bstrVal));
1339 if (FAILED(hr)) {
1340 WARN("Unable to add filter (%x)\n", hr);
1341 IBaseFilter_Release(pfilter);
1342 pfilter = NULL;
1343 goto error;
1346 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1347 if (FAILED(hr)) {
1348 WARN("Splitter Enumpins (%x)\n", hr);
1349 goto error;
1352 while ((hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin)) == S_OK)
1354 PIN_DIRECTION dir;
1356 if (pin == 0) {
1357 WARN("No Pin\n");
1358 hr = E_FAIL;
1359 goto error;
1362 hr = IPin_QueryDirection(ppinfilter, &dir);
1363 if (FAILED(hr)) {
1364 IPin_Release(ppinfilter);
1365 WARN("QueryDirection failed (%x)\n", hr);
1366 goto error;
1368 if (dir != PINDIR_INPUT) {
1369 IPin_Release(ppinfilter);
1370 continue; /* Wrong direction */
1373 /* Connect the pin to the "Renderer" */
1374 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1375 IPin_Release(ppinfilter);
1377 if (FAILED(hr)) {
1378 WARN("Unable to connect %s to renderer (%x)\n", debugstr_w(V_UNION(&var, bstrVal)), hr);
1379 goto error;
1381 TRACE("Connected, recursing %s\n", debugstr_w(V_UNION(&var, bstrVal)));
1383 VariantClear(&var);
1385 hr = FilterGraph2_RenderRecurse(This, ppinfilter);
1386 if (FAILED(hr)) {
1387 WARN("Unable to connect recursively (%x)\n", hr);
1388 goto error;
1390 IBaseFilter_Release(pfilter);
1391 break;
1393 if (SUCCEEDED(hr)) {
1394 IEnumPins_Release(penumpins);
1395 break; /* out of IEnumMoniker_Next loop */
1398 /* IEnumPins_Next failed, all other failure case caught by goto error */
1399 WARN("IEnumPins_Next (%x)\n", hr);
1400 /* goto error */
1402 error:
1403 VariantClear(&var);
1404 if (penumpins)
1405 IEnumPins_Release(penumpins);
1406 if (pfilter) {
1407 IFilterGraph2_RemoveFilter(iface, pfilter);
1408 IBaseFilter_Release(pfilter);
1410 if (SUCCEEDED(hr)) DebugBreak();
1413 IEnumMoniker_Release(pEnumMoniker);
1414 if (nbmt)
1415 DeleteMediaType(mt);
1416 if (SUCCEEDED(hr))
1417 break;
1418 hr = S_OK;
1421 IEnumMediaTypes_Release(penummt);
1422 return hr;
1425 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface,
1426 LPCWSTR lpcwstrFile,
1427 LPCWSTR lpcwstrPlayList)
1429 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1430 static const WCHAR string[] = {'R','e','a','d','e','r',0};
1431 IBaseFilter* preader = NULL;
1432 IPin* ppinreader = NULL;
1433 IEnumPins* penumpins = NULL;
1434 HRESULT hr;
1435 BOOL partial = FALSE;
1436 HRESULT any = FALSE;
1438 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1440 if (lpcwstrPlayList != NULL)
1441 return E_INVALIDARG;
1443 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, string, &preader);
1444 if (FAILED(hr))
1445 return hr;
1447 if (SUCCEEDED(hr))
1448 hr = IBaseFilter_EnumPins(preader, &penumpins);
1449 if (SUCCEEDED(hr))
1451 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1453 PIN_DIRECTION dir;
1455 IPin_QueryDirection(ppinreader, &dir);
1456 if (dir == PINDIR_OUTPUT)
1458 INT i;
1460 hr = IFilterGraph2_Render(iface, ppinreader);
1461 TRACE("Render %08x\n", hr);
1463 for (i = 0; i < This->nFilters; ++i)
1464 TRACE("Filters in chain: %s\n", debugstr_w(This->pFilterNames[i]));
1466 if (SUCCEEDED(hr))
1467 any = TRUE;
1468 if (hr != S_OK)
1469 partial = TRUE;
1471 IPin_Release(ppinreader);
1473 IEnumPins_Release(penumpins);
1475 if (!any)
1476 hr = VFW_E_CANNOT_RENDER;
1477 else if (partial)
1478 hr = VFW_S_PARTIAL_RENDER;
1479 else
1480 hr = S_OK;
1482 IBaseFilter_Release(preader);
1484 TRACE("--> %08x\n", hr);
1485 return hr;
1488 /* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
1489 static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
1491 static const WCHAR wszReg[] = {'M','e','d','i','a',' ','T','y','p','e','\\','E','x','t','e','n','s','i','o','n','s',0};
1492 HRESULT hr = S_OK;
1493 HKEY extkey;
1494 LONG lRet;
1496 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszReg, 0, KEY_READ, &extkey);
1497 hr = HRESULT_FROM_WIN32(lRet);
1499 if (SUCCEEDED(hr))
1501 static const WCHAR filtersource[] = {'S','o','u','r','c','e',' ','F','i','l','t','e','r',0};
1502 WCHAR *ext = PathFindExtensionW(pszFileName);
1503 WCHAR clsid_key[39];
1504 GUID clsid;
1505 DWORD size = sizeof(clsid_key);
1506 HKEY pathkey;
1508 if (!ext)
1510 CloseHandle(extkey);
1511 return E_FAIL;
1514 lRet = RegOpenKeyExW(extkey, ext, 0, KEY_READ, &pathkey);
1515 hr = HRESULT_FROM_WIN32(lRet);
1516 CloseHandle(extkey);
1517 if (FAILED(hr))
1518 return hr;
1520 lRet = RegQueryValueExW(pathkey, filtersource, NULL, NULL, (LPBYTE)clsid_key, &size);
1521 hr = HRESULT_FROM_WIN32(lRet);
1522 CloseHandle(pathkey);
1523 if (FAILED(hr))
1524 return hr;
1526 CLSIDFromString(clsid_key, &clsid);
1528 TRACE("CLSID: %s\n", debugstr_guid(&clsid));
1529 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1530 if (SUCCEEDED(hr))
1532 IFileSourceFilter *source = NULL;
1533 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID*)&source);
1534 if (SUCCEEDED(hr))
1535 IFileSourceFilter_Release(source);
1536 else
1537 IBaseFilter_Release(*filter);
1540 if (FAILED(hr))
1541 *filter = NULL;
1542 return hr;
1545 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface,
1546 LPCWSTR lpcwstrFileName,
1547 LPCWSTR lpcwstrFilterName,
1548 IBaseFilter **ppFilter) {
1549 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1550 HRESULT hr;
1551 IBaseFilter* preader;
1552 IFileSourceFilter* pfile = NULL;
1553 AM_MEDIA_TYPE mt;
1554 WCHAR* filename;
1556 TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1558 /* Try from file name first, then fall back to default asynchronous reader */
1559 hr = GetFileSourceFilter(lpcwstrFileName, &preader);
1561 if (FAILED(hr))
1562 hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&preader);
1563 if (FAILED(hr)) {
1564 WARN("Unable to create file source filter (%x)\n", hr);
1565 return hr;
1568 hr = IFilterGraph2_AddFilter(iface, preader, lpcwstrFilterName);
1569 if (FAILED(hr)) {
1570 WARN("Unable add filter (%x)\n", hr);
1571 IBaseFilter_Release(preader);
1572 return hr;
1575 hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1576 if (FAILED(hr)) {
1577 WARN("Unable to get IFileSourceInterface (%x)\n", hr);
1578 goto error;
1581 /* Load the file in the file source filter */
1582 hr = IFileSourceFilter_Load(pfile, lpcwstrFileName, NULL);
1583 if (FAILED(hr)) {
1584 WARN("Load (%x)\n", hr);
1585 goto error;
1588 IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1589 if (FAILED(hr)) {
1590 WARN("GetCurFile (%x)\n", hr);
1591 goto error;
1594 TRACE("File %s\n", debugstr_w(filename));
1595 TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
1596 TRACE("SubType %s\n", debugstr_guid(&mt.subtype));
1598 if (ppFilter)
1599 *ppFilter = preader;
1600 IFileSourceFilter_Release(pfile);
1602 return S_OK;
1604 error:
1605 if (pfile)
1606 IFileSourceFilter_Release(pfile);
1607 IFilterGraph2_RemoveFilter(iface, preader);
1608 IBaseFilter_Release(preader);
1610 return hr;
1613 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface,
1614 DWORD_PTR hFile) {
1615 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1617 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1619 return S_OK;
1622 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface) {
1623 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1625 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1627 return S_OK;
1630 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface) {
1631 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1633 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1635 return S_OK;
1638 /*** IFilterGraph2 methods ***/
1639 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1640 IMoniker *pMoniker,
1641 IBindCtx *pCtx,
1642 LPCWSTR lpcwstrFilterName,
1643 IBaseFilter **ppFilter) {
1644 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1646 TRACE("(%p/%p)->(%p %p %s %p): stub !!!\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1648 return S_OK;
1651 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface,
1652 IPin *ppin,
1653 const AM_MEDIA_TYPE *pmt) {
1654 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1656 TRACE("(%p/%p)->(%p %p): stub !!!\n", This, iface, ppin, pmt);
1658 return S_OK;
1661 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface,
1662 IPin *pPinOut,
1663 DWORD dwFlags,
1664 DWORD *pvContext) {
1665 ICOM_THIS_MULTI(IFilterGraphImpl, IFilterGraph2_vtbl, iface);
1667 TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This, iface, pPinOut, dwFlags, pvContext);
1669 return S_OK;
1673 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1675 FilterGraph2_QueryInterface,
1676 FilterGraph2_AddRef,
1677 FilterGraph2_Release,
1678 FilterGraph2_AddFilter,
1679 FilterGraph2_RemoveFilter,
1680 FilterGraph2_EnumFilters,
1681 FilterGraph2_FindFilterByName,
1682 FilterGraph2_ConnectDirect,
1683 FilterGraph2_Reconnect,
1684 FilterGraph2_Disconnect,
1685 FilterGraph2_SetDefaultSyncSource,
1686 FilterGraph2_Connect,
1687 FilterGraph2_Render,
1688 FilterGraph2_RenderFile,
1689 FilterGraph2_AddSourceFilter,
1690 FilterGraph2_SetLogFile,
1691 FilterGraph2_Abort,
1692 FilterGraph2_ShouldOperationContinue,
1693 FilterGraph2_AddSourceFilterForMoniker,
1694 FilterGraph2_ReconnectEx,
1695 FilterGraph2_RenderEx
1698 /*** IUnknown methods ***/
1699 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface,
1700 REFIID riid,
1701 LPVOID*ppvObj) {
1702 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1704 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1706 return Filtergraph_QueryInterface(This, riid, ppvObj);
1709 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface) {
1710 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1712 TRACE("(%p/%p)->()\n", This, iface);
1714 return Filtergraph_AddRef(This);
1717 static ULONG WINAPI MediaControl_Release(IMediaControl *iface) {
1718 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1720 TRACE("(%p/%p)->()\n", This, iface);
1722 return Filtergraph_Release(This);
1726 /*** IDispatch methods ***/
1727 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface,
1728 UINT*pctinfo) {
1729 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1731 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1733 return S_OK;
1736 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface,
1737 UINT iTInfo,
1738 LCID lcid,
1739 ITypeInfo**ppTInfo) {
1740 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1742 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1744 return S_OK;
1747 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface,
1748 REFIID riid,
1749 LPOLESTR*rgszNames,
1750 UINT cNames,
1751 LCID lcid,
1752 DISPID*rgDispId) {
1753 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1755 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1757 return S_OK;
1760 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface,
1761 DISPID dispIdMember,
1762 REFIID riid,
1763 LCID lcid,
1764 WORD wFlags,
1765 DISPPARAMS*pDispParams,
1766 VARIANT*pVarResult,
1767 EXCEPINFO*pExepInfo,
1768 UINT*puArgErr) {
1769 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1771 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
1773 return S_OK;
1776 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *, DWORD_PTR data);
1778 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter, DWORD_PTR data)
1780 HRESULT hr;
1781 IPin* pInputPin;
1782 IPin** ppPins;
1783 ULONG nb;
1784 ULONG i;
1785 PIN_INFO PinInfo;
1787 TRACE("%p %p\n", pGraph, pOutputPin);
1788 PinInfo.pFilter = NULL;
1790 hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1792 if (SUCCEEDED(hr))
1794 hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1795 if (SUCCEEDED(hr))
1796 hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1797 IPin_Release(pInputPin);
1800 if (SUCCEEDED(hr))
1802 if (nb == 0)
1804 TRACE("Reached a renderer\n");
1805 /* Count renderers for end of stream notification */
1806 pGraph->nRenderers++;
1808 else
1810 for(i = 0; i < nb; i++)
1812 /* Explore the graph downstream from this pin
1813 * FIXME: We should prevent exploring from a pin more than once. This can happens when
1814 * several input pins are connected to the same output (a MUX for instance). */
1815 ExploreGraph(pGraph, ppPins[i], FoundFilter, data);
1816 IPin_Release(ppPins[i]);
1819 CoTaskMemFree(ppPins);
1821 TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1823 FoundFilter(PinInfo.pFilter, data);
1826 if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1827 return hr;
1830 static HRESULT WINAPI SendRun(IBaseFilter *pFilter, DWORD_PTR data)
1832 REFERENCE_TIME time = *(REFERENCE_TIME*)data;
1833 return IBaseFilter_Run(pFilter, time);
1836 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1838 return IBaseFilter_Pause(pFilter);
1841 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1843 return IBaseFilter_Stop(pFilter);
1846 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1848 FILTER_STATE state;
1849 DWORD time_end = data;
1850 DWORD time_now = GetTickCount();
1851 LONG wait;
1853 if (time_end == INFINITE)
1855 wait = INFINITE;
1857 else if (time_end > time_now)
1859 wait = time_end - time_now;
1861 else
1862 wait = 0;
1864 return IBaseFilter_GetState(pFilter, wait, &state);
1868 static HRESULT SendFilterMessage(IMediaControl *iface, fnFoundFilter FoundFilter, DWORD_PTR data)
1870 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1871 int i;
1872 IBaseFilter* pfilter;
1873 IEnumPins* pEnum;
1874 HRESULT hr;
1875 IPin* pPin;
1876 DWORD dummy;
1877 PIN_DIRECTION dir;
1878 TRACE("(%p/%p)->()\n", This, iface);
1880 /* Explorer the graph from source filters to renderers, determine renderers
1881 * number and run filters from renderers to source filters */
1882 This->nRenderers = 0;
1883 ResetEvent(This->hEventCompletion);
1885 for(i = 0; i < This->nFilters; i++)
1887 BOOL source = TRUE;
1888 pfilter = This->ppFiltersInGraph[i];
1889 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
1890 if (hr != S_OK)
1892 WARN("Enum pins failed %x\n", hr);
1893 continue;
1895 /* Check if it is a source filter */
1896 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1898 IPin_QueryDirection(pPin, &dir);
1899 IPin_Release(pPin);
1900 if (dir == PINDIR_INPUT)
1902 source = FALSE;
1903 break;
1906 if (source)
1908 TRACE("Found a source filter %p\n", pfilter);
1909 IEnumPins_Reset(pEnum);
1910 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1912 /* Explore the graph downstream from this pin */
1913 ExploreGraph(This, pPin, FoundFilter, data);
1914 IPin_Release(pPin);
1916 FoundFilter(pfilter, data);
1918 IEnumPins_Release(pEnum);
1921 return S_FALSE;
1924 /*** IMediaControl methods ***/
1925 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface) {
1926 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1927 TRACE("(%p/%p)->()\n", This, iface);
1929 EnterCriticalSection(&This->cs);
1930 if (This->state == State_Running)
1931 goto out;
1932 This->EcCompleteCount = 0;
1934 if (This->refClock)
1936 REFERENCE_TIME now;
1937 IReferenceClock_GetTime(This->refClock, &now);
1938 if (This->state == State_Stopped)
1939 This->start_time = now + 500000;
1940 else
1941 This->start_time += now - This->pause_time;
1943 else This->start_time = 0;
1945 SendFilterMessage(iface, SendRun, (DWORD_PTR)&This->start_time);
1946 This->state = State_Running;
1947 out:
1948 LeaveCriticalSection(&This->cs);
1949 return S_FALSE;
1952 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface) {
1953 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1954 TRACE("(%p/%p)->()\n", This, iface);
1956 EnterCriticalSection(&This->cs);
1957 if (This->state == State_Paused)
1958 goto out;
1960 if (This->state == State_Running && This->refClock)
1961 IReferenceClock_GetTime(This->refClock, &This->pause_time);
1963 SendFilterMessage(iface, SendPause, 0);
1964 This->state = State_Paused;
1965 out:
1966 LeaveCriticalSection(&This->cs);
1967 return S_FALSE;
1970 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface) {
1971 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1972 TRACE("(%p/%p)->()\n", This, iface);
1974 if (This->state == State_Stopped) return S_OK;
1976 EnterCriticalSection(&This->cs);
1977 if (This->state == State_Running) SendFilterMessage(iface, SendPause, 0);
1978 SendFilterMessage(iface, SendStop, 0);
1979 This->state = State_Stopped;
1980 LeaveCriticalSection(&This->cs);
1981 return S_OK;
1984 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface,
1985 LONG msTimeout,
1986 OAFilterState *pfs) {
1987 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
1988 DWORD end;
1990 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
1992 if (!pfs)
1993 return E_POINTER;
1995 EnterCriticalSection(&This->cs);
1997 *pfs = This->state;
1998 if (msTimeout > 0)
2000 end = GetTickCount() + msTimeout;
2002 else if (msTimeout < 0)
2004 end = INFINITE;
2006 else
2008 end = 0;
2010 if (end)
2011 SendFilterMessage(iface, SendGetState, end);
2013 LeaveCriticalSection(&This->cs);
2015 return S_OK;
2018 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface,
2019 BSTR strFilename) {
2020 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2022 FIXME("(%p/%p)->(%s (%p)): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename);
2024 return S_OK;
2027 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface,
2028 BSTR strFilename,
2029 IDispatch **ppUnk) {
2030 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2032 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2034 return S_OK;
2037 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface,
2038 IDispatch **ppUnk) {
2039 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2041 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2043 return S_OK;
2046 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface,
2047 IDispatch **ppUnk) {
2048 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2050 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2052 return S_OK;
2055 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface) {
2056 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
2058 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2060 return S_OK;
2064 static const IMediaControlVtbl IMediaControl_VTable =
2066 MediaControl_QueryInterface,
2067 MediaControl_AddRef,
2068 MediaControl_Release,
2069 MediaControl_GetTypeInfoCount,
2070 MediaControl_GetTypeInfo,
2071 MediaControl_GetIDsOfNames,
2072 MediaControl_Invoke,
2073 MediaControl_Run,
2074 MediaControl_Pause,
2075 MediaControl_Stop,
2076 MediaControl_GetState,
2077 MediaControl_RenderFile,
2078 MediaControl_AddSourceFilter,
2079 MediaControl_get_FilterCollection,
2080 MediaControl_get_RegFilterCollection,
2081 MediaControl_StopWhenReady
2085 /*** IUnknown methods ***/
2086 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface,
2087 REFIID riid,
2088 LPVOID*ppvObj) {
2089 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2091 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2093 return Filtergraph_QueryInterface(This, riid, ppvObj);
2096 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface) {
2097 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2099 TRACE("(%p/%p)->()\n", This, iface);
2101 return Filtergraph_AddRef(This);
2104 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface) {
2105 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2107 TRACE("(%p/%p)->()\n", This, iface);
2109 return Filtergraph_Release(This);
2112 typedef HRESULT (WINAPI *fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
2114 static HRESULT all_renderers_seek(IFilterGraphImpl *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2115 BOOL allnotimpl = TRUE;
2116 int i;
2117 HRESULT hr, hr_return = S_OK;
2119 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2120 /* Send a message to all renderers, they are responsible for broadcasting it further */
2122 for(i = 0; i < This->nFilters; i++)
2124 IMediaSeeking *seek = NULL;
2125 IBaseFilter* pfilter = This->ppFiltersInGraph[i];
2126 IAMFilterMiscFlags *flags = NULL;
2127 ULONG filterflags;
2128 IUnknown_QueryInterface(pfilter, &IID_IAMFilterMiscFlags, (void**)&flags);
2129 if (!flags)
2130 continue;
2131 filterflags = IAMFilterMiscFlags_GetMiscFlags(flags);
2132 IUnknown_Release(flags);
2133 if (filterflags != AM_FILTER_MISC_FLAGS_IS_RENDERER)
2134 continue;
2136 IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2137 if (!seek)
2138 continue;
2139 hr = FoundSeek(This, seek, arg);
2140 IMediaSeeking_Release(seek);
2141 if (hr_return != E_NOTIMPL)
2142 allnotimpl = FALSE;
2143 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2144 hr_return = hr;
2147 if (allnotimpl)
2148 return E_NOTIMPL;
2149 return hr_return;
2152 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2154 HRESULT hr;
2155 DWORD caps = 0;
2157 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2158 if (FAILED(hr))
2159 return hr;
2161 /* Only add common capabilities everything supports */
2162 *(DWORD*)pcaps &= caps;
2164 return hr;
2167 /*** IMediaSeeking methods ***/
2168 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface,
2169 DWORD *pCapabilities) {
2170 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2171 HRESULT hr;
2172 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2174 if (!pCapabilities)
2175 return E_POINTER;
2177 EnterCriticalSection(&This->cs);
2178 *pCapabilities = 0xffffffff;
2180 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2181 LeaveCriticalSection(&This->cs);
2183 return hr;
2186 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface,
2187 DWORD *pCapabilities) {
2188 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2189 DWORD originalcaps;
2190 HRESULT hr;
2191 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2193 if (!pCapabilities)
2194 return E_POINTER;
2196 EnterCriticalSection(&This->cs);
2197 originalcaps = *pCapabilities;
2198 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2199 LeaveCriticalSection(&This->cs);
2201 if (FAILED(hr))
2202 return hr;
2204 if (!*pCapabilities)
2205 return E_FAIL;
2206 if (*pCapabilities != originalcaps)
2207 return S_FALSE;
2208 return S_OK;
2211 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface,
2212 const GUID *pFormat) {
2213 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2215 if (!pFormat)
2216 return E_POINTER;
2218 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2220 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2222 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2223 return S_FALSE;
2226 return S_OK;
2229 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface,
2230 GUID *pFormat) {
2231 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2233 if (!pFormat)
2234 return E_POINTER;
2236 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2237 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2239 return S_OK;
2242 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface,
2243 GUID *pFormat) {
2244 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2246 if (!pFormat)
2247 return E_POINTER;
2249 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2250 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2252 return S_OK;
2255 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface,
2256 const GUID *pFormat) {
2257 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2259 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2260 if (!pFormat)
2261 return E_POINTER;
2263 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2264 return S_FALSE;
2266 return S_OK;
2269 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface,
2270 const GUID *pFormat) {
2271 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2273 if (!pFormat)
2274 return E_POINTER;
2276 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2278 if (This->state != State_Stopped)
2279 return VFW_E_WRONG_STATE;
2281 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2283 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2284 return E_INVALIDARG;
2287 return S_OK;
2290 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2292 HRESULT hr;
2293 LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2295 hr = IMediaSeeking_GetDuration(seek, &duration);
2296 if (FAILED(hr))
2297 return hr;
2299 if (*pdur < duration)
2300 *pdur = duration;
2301 return hr;
2304 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface,
2305 LONGLONG *pDuration) {
2306 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2307 HRESULT hr;
2309 TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2311 if (!pDuration)
2312 return E_POINTER;
2314 EnterCriticalSection(&This->cs);
2315 *pDuration = 0;
2316 hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2317 LeaveCriticalSection(&This->cs);
2319 TRACE("--->%08x\n", hr);
2320 return hr;
2323 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface,
2324 LONGLONG *pStop) {
2325 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2326 HRESULT hr = S_OK;
2328 TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2330 if (!pStop)
2331 return E_POINTER;
2333 EnterCriticalSection(&This->cs);
2334 if (This->stop_position < 0)
2335 /* Stop position not set, use duration instead */
2336 hr = IMediaSeeking_GetDuration(iface, pStop);
2337 else
2338 *pStop = This->stop_position;
2339 LeaveCriticalSection(&This->cs);
2341 return hr;
2344 static HRESULT WINAPI FoundCurrentPosition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pposition)
2346 HRESULT hr;
2347 LONGLONG pos = 0, *ppos = (LONGLONG*)pposition;
2349 hr = IMediaSeeking_GetCurrentPosition(seek, &pos);
2350 if (FAILED(hr))
2351 return hr;
2353 if (*ppos < 0 || pos < *ppos)
2354 *ppos = pos;
2355 return hr;
2358 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface,
2359 LONGLONG *pCurrent) {
2360 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2361 HRESULT hr;
2363 if (!pCurrent)
2364 return E_POINTER;
2366 EnterCriticalSection(&This->cs);
2367 *pCurrent = -1;
2368 hr = all_renderers_seek(This, FoundCurrentPosition, (DWORD_PTR)pCurrent);
2369 if (hr == E_NOTIMPL) {
2370 *pCurrent = 0;
2371 hr = S_OK;
2373 LeaveCriticalSection(&This->cs);
2375 TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2377 return hr;
2380 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface,
2381 LONGLONG *pTarget,
2382 const GUID *pTargetFormat,
2383 LONGLONG Source,
2384 const GUID *pSourceFormat) {
2385 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2387 FIXME("(%p/%p)->(%p, %p, 0x%s, %p): stub !!!\n", This, iface, pTarget,
2388 pTargetFormat, wine_dbgstr_longlong(Source), pSourceFormat);
2390 return S_OK;
2393 struct pos_args {
2394 LONGLONG* current, *stop;
2395 DWORD curflags, stopflags;
2398 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2400 struct pos_args *args = (void*)pargs;
2402 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
2405 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface,
2406 LONGLONG *pCurrent,
2407 DWORD dwCurrentFlags,
2408 LONGLONG *pStop,
2409 DWORD dwStopFlags) {
2410 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2411 HRESULT hr = S_OK;
2412 FILTER_STATE state;
2413 struct pos_args args;
2415 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
2417 EnterCriticalSection(&This->cs);
2418 state = This->state;
2419 TRACE("State: %s\n", state == State_Running ? "Running" : (state == State_Paused ? "Paused" : (state == State_Stopped ? "Stopped" : "UNKNOWN")));
2421 if ((dwCurrentFlags & 0x7) != AM_SEEKING_AbsolutePositioning &&
2422 (dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2423 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
2425 if ((dwStopFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2426 This->stop_position = *pStop;
2427 else if ((dwStopFlags & 0x7) != AM_SEEKING_NoPositioning)
2428 FIXME("Stop position not handled yet!\n");
2430 args.current = pCurrent;
2431 args.stop = pStop;
2432 args.curflags = dwCurrentFlags;
2433 args.stopflags = dwStopFlags;
2434 hr = all_renderers_seek(This, found_setposition, (DWORD_PTR)&args);
2436 if (This->refClock && ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning))
2438 /* Update start time, prevents weird jumps */
2439 IReferenceClock_GetTime(This->refClock, &This->start_time);
2441 LeaveCriticalSection(&This->cs);
2443 return hr;
2446 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface,
2447 LONGLONG *pCurrent,
2448 LONGLONG *pStop) {
2449 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2450 HRESULT hr;
2452 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pCurrent, pStop);
2453 hr = IMediaSeeking_GetCurrentPosition(iface, pCurrent);
2454 if (SUCCEEDED(hr))
2455 hr = IMediaSeeking_GetStopPosition(iface, pStop);
2457 return hr;
2460 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface,
2461 LONGLONG *pEarliest,
2462 LONGLONG *pLatest) {
2463 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2465 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2467 return S_OK;
2470 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface,
2471 double dRate) {
2472 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2474 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2476 return S_OK;
2479 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface,
2480 double *pdRate) {
2481 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2483 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2485 return S_OK;
2488 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface,
2489 LONGLONG *pllPreroll) {
2490 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaSeeking_vtbl, iface);
2492 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2494 return S_OK;
2498 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2500 MediaSeeking_QueryInterface,
2501 MediaSeeking_AddRef,
2502 MediaSeeking_Release,
2503 MediaSeeking_GetCapabilities,
2504 MediaSeeking_CheckCapabilities,
2505 MediaSeeking_IsFormatSupported,
2506 MediaSeeking_QueryPreferredFormat,
2507 MediaSeeking_GetTimeFormat,
2508 MediaSeeking_IsUsingTimeFormat,
2509 MediaSeeking_SetTimeFormat,
2510 MediaSeeking_GetDuration,
2511 MediaSeeking_GetStopPosition,
2512 MediaSeeking_GetCurrentPosition,
2513 MediaSeeking_ConvertTimeFormat,
2514 MediaSeeking_SetPositions,
2515 MediaSeeking_GetPositions,
2516 MediaSeeking_GetAvailable,
2517 MediaSeeking_SetRate,
2518 MediaSeeking_GetRate,
2519 MediaSeeking_GetPreroll
2522 static inline IFilterGraphImpl *impl_from_IMediaPosition( IMediaPosition *iface )
2524 return (IFilterGraphImpl *)((char*)iface - FIELD_OFFSET(IFilterGraphImpl, IMediaPosition_vtbl));
2527 /*** IUnknown methods ***/
2528 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj)
2530 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2532 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2533 return Filtergraph_QueryInterface(This, riid, ppvObj);
2536 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2538 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2540 TRACE("(%p/%p)->()\n", This, iface);
2541 return Filtergraph_AddRef(This);
2544 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2546 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2548 TRACE("(%p/%p)->()\n", This, iface);
2549 return Filtergraph_Release(This);
2552 /*** IDispatch methods ***/
2553 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo){
2554 FIXME("(%p) stub!\n", iface);
2555 return E_NOTIMPL;
2558 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo){
2559 FIXME("(%p) stub!\n", iface);
2560 return E_NOTIMPL;
2563 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId){
2564 FIXME("(%p) stub!\n", iface);
2565 return E_NOTIMPL;
2568 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr){
2569 FIXME("(%p) stub!\n", iface);
2570 return E_NOTIMPL;
2573 /*** IMediaPosition methods ***/
2574 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2576 LONGLONG duration;
2577 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2578 HRESULT hr = IMediaSeeking_GetDuration( (IMediaSeeking *)&This->IMediaSeeking_vtbl, &duration );
2579 if (SUCCEEDED(hr)) *plength = duration;
2580 return hr;
2583 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2585 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2586 LONGLONG reftime = llTime;
2588 return IMediaSeeking_SetPositions((IMediaSeeking *)&This->IMediaSeeking_vtbl,
2589 &reftime, AM_SEEKING_AbsolutePositioning,
2590 NULL, AM_SEEKING_NoPositioning);
2593 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2595 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2596 LONGLONG pos;
2597 HRESULT hr = IMediaSeeking_GetCurrentPosition( (IMediaSeeking *)&This->IMediaSeeking_vtbl, &pos );
2598 if (SUCCEEDED(hr)) *pllTime = pos;
2599 return hr;
2602 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2604 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2605 LONGLONG pos;
2606 HRESULT hr = IMediaSeeking_GetStopPosition( (IMediaSeeking *)&This->IMediaSeeking_vtbl, &pos );
2607 if (SUCCEEDED(hr)) *pllTime = pos;
2608 return hr;
2611 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2613 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2614 LONGLONG reftime = llTime;
2616 return IMediaSeeking_SetPositions((IMediaSeeking *)&This->IMediaSeeking_vtbl,
2617 NULL, AM_SEEKING_NoPositioning,
2618 &reftime, AM_SEEKING_AbsolutePositioning);
2621 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime){
2622 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2623 return E_NOTIMPL;
2626 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime){
2627 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2628 return E_NOTIMPL;
2631 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2633 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2634 return IMediaSeeking_SetRate((IMediaSeeking *)&This->IMediaSeeking_vtbl, dRate);
2637 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2639 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2640 return IMediaSeeking_GetRate((IMediaSeeking *)&This->IMediaSeeking_vtbl, pdRate);
2643 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward){
2644 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2645 return E_NOTIMPL;
2648 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward){
2649 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2650 return E_NOTIMPL;
2654 static const IMediaPositionVtbl IMediaPosition_VTable =
2656 MediaPosition_QueryInterface,
2657 MediaPosition_AddRef,
2658 MediaPosition_Release,
2659 MediaPosition_GetTypeInfoCount,
2660 MediaPosition_GetTypeInfo,
2661 MediaPosition_GetIDsOfNames,
2662 MediaPosition_Invoke,
2663 MediaPosition_get_Duration,
2664 MediaPosition_put_CurrentPosition,
2665 MediaPosition_get_CurrentPosition,
2666 MediaPosition_get_StopTime,
2667 MediaPosition_put_StopTime,
2668 MediaPosition_get_PrerollTime,
2669 MediaPosition_put_PrerollTime,
2670 MediaPosition_put_Rate,
2671 MediaPosition_get_Rate,
2672 MediaPosition_CanSeekForward,
2673 MediaPosition_CanSeekBackward
2676 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2678 HRESULT hr = E_NOINTERFACE;
2679 int i;
2680 int entry;
2682 /* Check if the interface type is already registered */
2683 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2684 if (riid == pGraph->ItfCacheEntries[entry].riid)
2686 if (pGraph->ItfCacheEntries[entry].iface)
2688 /* Return the interface if available */
2689 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2690 return S_OK;
2692 break;
2695 if (entry >= MAX_ITF_CACHE_ENTRIES)
2697 FIXME("Not enough space to store interface in the cache\n");
2698 return E_OUTOFMEMORY;
2701 /* Find a filter supporting the requested interface */
2702 for (i = 0; i < pGraph->nFilters; i++)
2704 hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2705 if (hr == S_OK)
2707 pGraph->ItfCacheEntries[entry].riid = riid;
2708 pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2709 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2710 if (entry >= pGraph->nItfCacheEntries)
2711 pGraph->nItfCacheEntries++;
2712 return S_OK;
2714 if (hr != E_NOINTERFACE)
2715 return hr;
2718 return hr;
2721 /*** IUnknown methods ***/
2722 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface,
2723 REFIID riid,
2724 LPVOID*ppvObj) {
2725 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2727 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2729 return Filtergraph_QueryInterface(This, riid, ppvObj);
2732 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface) {
2733 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2735 TRACE("(%p/%p)->()\n", This, iface);
2737 return Filtergraph_AddRef(This);
2740 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface) {
2741 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2743 TRACE("(%p/%p)->()\n", This, iface);
2745 return Filtergraph_Release(This);
2748 /*** IDispatch methods ***/
2749 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface,
2750 UINT*pctinfo) {
2751 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2752 IBasicAudio* pBasicAudio;
2753 HRESULT hr;
2755 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
2757 EnterCriticalSection(&This->cs);
2759 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2761 if (hr == S_OK)
2762 hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
2764 LeaveCriticalSection(&This->cs);
2766 return hr;
2769 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface,
2770 UINT iTInfo,
2771 LCID lcid,
2772 ITypeInfo**ppTInfo) {
2773 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2774 IBasicAudio* pBasicAudio;
2775 HRESULT hr;
2777 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
2779 EnterCriticalSection(&This->cs);
2781 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2783 if (hr == S_OK)
2784 hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
2786 LeaveCriticalSection(&This->cs);
2788 return hr;
2791 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface,
2792 REFIID riid,
2793 LPOLESTR*rgszNames,
2794 UINT cNames,
2795 LCID lcid,
2796 DISPID*rgDispId) {
2797 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2798 IBasicAudio* pBasicAudio;
2799 HRESULT hr;
2801 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
2803 EnterCriticalSection(&This->cs);
2805 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2807 if (hr == S_OK)
2808 hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
2810 LeaveCriticalSection(&This->cs);
2812 return hr;
2815 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface,
2816 DISPID dispIdMember,
2817 REFIID riid,
2818 LCID lcid,
2819 WORD wFlags,
2820 DISPPARAMS*pDispParams,
2821 VARIANT*pVarResult,
2822 EXCEPINFO*pExepInfo,
2823 UINT*puArgErr) {
2824 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2825 IBasicAudio* pBasicAudio;
2826 HRESULT hr;
2828 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
2830 EnterCriticalSection(&This->cs);
2832 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2834 if (hr == S_OK)
2835 hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
2837 LeaveCriticalSection(&This->cs);
2839 return hr;
2842 /*** IBasicAudio methods ***/
2843 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface,
2844 LONG lVolume) {
2845 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2846 IBasicAudio* pBasicAudio;
2847 HRESULT hr;
2849 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
2851 EnterCriticalSection(&This->cs);
2853 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2855 if (hr == S_OK)
2856 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
2858 LeaveCriticalSection(&This->cs);
2860 return hr;
2863 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface,
2864 LONG *plVolume) {
2865 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2866 IBasicAudio* pBasicAudio;
2867 HRESULT hr;
2869 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
2871 EnterCriticalSection(&This->cs);
2873 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2875 if (hr == S_OK)
2876 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
2878 LeaveCriticalSection(&This->cs);
2880 return hr;
2883 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface,
2884 LONG lBalance) {
2885 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2886 IBasicAudio* pBasicAudio;
2887 HRESULT hr;
2889 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
2891 EnterCriticalSection(&This->cs);
2893 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2895 if (hr == S_OK)
2896 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
2898 LeaveCriticalSection(&This->cs);
2900 return hr;
2903 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface,
2904 LONG *plBalance) {
2905 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicAudio_vtbl, iface);
2906 IBasicAudio* pBasicAudio;
2907 HRESULT hr;
2909 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
2911 EnterCriticalSection(&This->cs);
2913 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2915 if (hr == S_OK)
2916 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
2918 LeaveCriticalSection(&This->cs);
2920 return hr;
2923 static const IBasicAudioVtbl IBasicAudio_VTable =
2925 BasicAudio_QueryInterface,
2926 BasicAudio_AddRef,
2927 BasicAudio_Release,
2928 BasicAudio_GetTypeInfoCount,
2929 BasicAudio_GetTypeInfo,
2930 BasicAudio_GetIDsOfNames,
2931 BasicAudio_Invoke,
2932 BasicAudio_put_Volume,
2933 BasicAudio_get_Volume,
2934 BasicAudio_put_Balance,
2935 BasicAudio_get_Balance
2938 /*** IUnknown methods ***/
2939 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface,
2940 REFIID riid,
2941 LPVOID*ppvObj) {
2942 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2944 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2946 return Filtergraph_QueryInterface(This, riid, ppvObj);
2949 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface) {
2950 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2952 TRACE("(%p/%p)->()\n", This, iface);
2954 return Filtergraph_AddRef(This);
2957 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface) {
2958 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2960 TRACE("(%p/%p)->()\n", This, iface);
2962 return Filtergraph_Release(This);
2965 /*** IDispatch methods ***/
2966 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface,
2967 UINT*pctinfo) {
2968 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2969 IBasicVideo* pBasicVideo;
2970 HRESULT hr;
2972 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
2974 EnterCriticalSection(&This->cs);
2976 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
2978 if (hr == S_OK)
2979 hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
2981 LeaveCriticalSection(&This->cs);
2983 return hr;
2986 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface,
2987 UINT iTInfo,
2988 LCID lcid,
2989 ITypeInfo**ppTInfo) {
2990 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
2991 IBasicVideo* pBasicVideo;
2992 HRESULT hr;
2994 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
2996 EnterCriticalSection(&This->cs);
2998 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3000 if (hr == S_OK)
3001 hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
3003 LeaveCriticalSection(&This->cs);
3005 return hr;
3008 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface,
3009 REFIID riid,
3010 LPOLESTR*rgszNames,
3011 UINT cNames,
3012 LCID lcid,
3013 DISPID*rgDispId) {
3014 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3015 IBasicVideo* pBasicVideo;
3016 HRESULT hr;
3018 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3020 EnterCriticalSection(&This->cs);
3022 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3024 if (hr == S_OK)
3025 hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
3027 LeaveCriticalSection(&This->cs);
3029 return hr;
3032 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface,
3033 DISPID dispIdMember,
3034 REFIID riid,
3035 LCID lcid,
3036 WORD wFlags,
3037 DISPPARAMS*pDispParams,
3038 VARIANT*pVarResult,
3039 EXCEPINFO*pExepInfo,
3040 UINT*puArgErr) {
3041 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3042 IBasicVideo* pBasicVideo;
3043 HRESULT hr;
3045 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3047 EnterCriticalSection(&This->cs);
3049 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3051 if (hr == S_OK)
3052 hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3054 LeaveCriticalSection(&This->cs);
3056 return hr;
3059 /*** IBasicVideo methods ***/
3060 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface,
3061 REFTIME *pAvgTimePerFrame) {
3062 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3063 IBasicVideo* pBasicVideo;
3064 HRESULT hr;
3066 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3068 EnterCriticalSection(&This->cs);
3070 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3072 if (hr == S_OK)
3073 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3075 LeaveCriticalSection(&This->cs);
3077 return hr;
3080 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface,
3081 LONG *pBitRate) {
3082 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3083 IBasicVideo* pBasicVideo;
3084 HRESULT hr;
3086 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3088 EnterCriticalSection(&This->cs);
3090 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3092 if (hr == S_OK)
3093 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3095 LeaveCriticalSection(&This->cs);
3097 return hr;
3100 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface,
3101 LONG *pBitErrorRate) {
3102 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3103 IBasicVideo* pBasicVideo;
3104 HRESULT hr;
3106 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3108 EnterCriticalSection(&This->cs);
3110 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3112 if (hr == S_OK)
3113 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3115 LeaveCriticalSection(&This->cs);
3117 return hr;
3120 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface,
3121 LONG *pVideoWidth) {
3122 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3123 IBasicVideo* pBasicVideo;
3124 HRESULT hr;
3126 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3128 EnterCriticalSection(&This->cs);
3130 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3132 if (hr == S_OK)
3133 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3135 LeaveCriticalSection(&This->cs);
3137 return hr;
3140 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface,
3141 LONG *pVideoHeight) {
3142 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3143 IBasicVideo* pBasicVideo;
3144 HRESULT hr;
3146 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3148 EnterCriticalSection(&This->cs);
3150 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3152 if (hr == S_OK)
3153 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3155 LeaveCriticalSection(&This->cs);
3157 return hr;
3160 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface,
3161 LONG SourceLeft) {
3162 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3163 IBasicVideo* pBasicVideo;
3164 HRESULT hr;
3166 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3168 EnterCriticalSection(&This->cs);
3170 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3172 if (hr == S_OK)
3173 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3175 LeaveCriticalSection(&This->cs);
3177 return hr;
3180 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface,
3181 LONG *pSourceLeft) {
3182 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3183 IBasicVideo* pBasicVideo;
3184 HRESULT hr;
3186 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3188 EnterCriticalSection(&This->cs);
3190 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3192 if (hr == S_OK)
3193 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3195 LeaveCriticalSection(&This->cs);
3197 return hr;
3200 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface,
3201 LONG SourceWidth) {
3202 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3203 IBasicVideo* pBasicVideo;
3204 HRESULT hr;
3206 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3208 EnterCriticalSection(&This->cs);
3210 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3212 if (hr == S_OK)
3213 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3215 LeaveCriticalSection(&This->cs);
3217 return hr;
3220 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface,
3221 LONG *pSourceWidth) {
3222 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3223 IBasicVideo* pBasicVideo;
3224 HRESULT hr;
3226 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3228 EnterCriticalSection(&This->cs);
3230 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3232 if (hr == S_OK)
3233 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3235 LeaveCriticalSection(&This->cs);
3237 return hr;
3240 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface,
3241 LONG SourceTop) {
3242 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3243 IBasicVideo* pBasicVideo;
3244 HRESULT hr;
3246 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3248 EnterCriticalSection(&This->cs);
3250 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3252 if (hr == S_OK)
3253 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3255 LeaveCriticalSection(&This->cs);
3257 return hr;
3260 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface,
3261 LONG *pSourceTop) {
3262 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3263 IBasicVideo* pBasicVideo;
3264 HRESULT hr;
3266 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3268 EnterCriticalSection(&This->cs);
3270 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3272 if (hr == S_OK)
3273 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3275 LeaveCriticalSection(&This->cs);
3277 return hr;
3280 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface,
3281 LONG SourceHeight) {
3282 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3283 IBasicVideo* pBasicVideo;
3284 HRESULT hr;
3286 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3288 EnterCriticalSection(&This->cs);
3290 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3292 if (hr == S_OK)
3293 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3295 LeaveCriticalSection(&This->cs);
3297 return hr;
3300 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface,
3301 LONG *pSourceHeight) {
3302 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3303 IBasicVideo* pBasicVideo;
3304 HRESULT hr;
3306 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3308 EnterCriticalSection(&This->cs);
3310 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3312 if (hr == S_OK)
3313 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3315 LeaveCriticalSection(&This->cs);
3317 return hr;
3320 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface,
3321 LONG DestinationLeft) {
3322 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3323 IBasicVideo* pBasicVideo;
3324 HRESULT hr;
3326 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3328 EnterCriticalSection(&This->cs);
3330 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3332 if (hr == S_OK)
3333 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3335 LeaveCriticalSection(&This->cs);
3337 return hr;
3340 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface,
3341 LONG *pDestinationLeft) {
3342 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3343 IBasicVideo* pBasicVideo;
3344 HRESULT hr;
3346 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3348 EnterCriticalSection(&This->cs);
3350 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3352 if (hr == S_OK)
3353 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3355 LeaveCriticalSection(&This->cs);
3357 return hr;
3360 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface,
3361 LONG DestinationWidth) {
3362 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3363 IBasicVideo* pBasicVideo;
3364 HRESULT hr;
3366 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3368 EnterCriticalSection(&This->cs);
3370 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3372 if (hr == S_OK)
3373 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3375 LeaveCriticalSection(&This->cs);
3377 return hr;
3380 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface,
3381 LONG *pDestinationWidth) {
3382 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3383 IBasicVideo* pBasicVideo;
3384 HRESULT hr;
3386 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3388 EnterCriticalSection(&This->cs);
3390 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3392 if (hr == S_OK)
3393 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3395 LeaveCriticalSection(&This->cs);
3397 return hr;
3400 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface,
3401 LONG DestinationTop) {
3402 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3403 IBasicVideo* pBasicVideo;
3404 HRESULT hr;
3406 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3408 EnterCriticalSection(&This->cs);
3410 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3412 if (hr == S_OK)
3413 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3415 LeaveCriticalSection(&This->cs);
3417 return hr;
3420 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface,
3421 LONG *pDestinationTop) {
3422 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3423 IBasicVideo* pBasicVideo;
3424 HRESULT hr;
3426 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3428 EnterCriticalSection(&This->cs);
3430 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3432 if (hr == S_OK)
3433 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3435 LeaveCriticalSection(&This->cs);
3437 return hr;
3440 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface,
3441 LONG DestinationHeight) {
3442 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3443 IBasicVideo* pBasicVideo;
3444 HRESULT hr;
3446 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3448 EnterCriticalSection(&This->cs);
3450 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3452 if (hr == S_OK)
3453 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3455 LeaveCriticalSection(&This->cs);
3457 return hr;
3460 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3461 LONG *pDestinationHeight) {
3462 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3463 IBasicVideo* pBasicVideo;
3464 HRESULT hr;
3466 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3468 EnterCriticalSection(&This->cs);
3470 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3472 if (hr == S_OK)
3473 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3475 LeaveCriticalSection(&This->cs);
3477 return hr;
3480 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface,
3481 LONG Left,
3482 LONG Top,
3483 LONG Width,
3484 LONG Height) {
3485 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3486 IBasicVideo* pBasicVideo;
3487 HRESULT hr;
3489 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3491 EnterCriticalSection(&This->cs);
3493 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3495 if (hr == S_OK)
3496 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3498 LeaveCriticalSection(&This->cs);
3500 return hr;
3503 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface,
3504 LONG *pLeft,
3505 LONG *pTop,
3506 LONG *pWidth,
3507 LONG *pHeight) {
3508 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3509 IBasicVideo* pBasicVideo;
3510 HRESULT hr;
3512 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3514 EnterCriticalSection(&This->cs);
3516 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3518 if (hr == S_OK)
3519 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3521 LeaveCriticalSection(&This->cs);
3523 return hr;
3526 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface) {
3527 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3528 IBasicVideo* pBasicVideo;
3529 HRESULT hr;
3531 TRACE("(%p/%p)->()\n", This, iface);
3533 EnterCriticalSection(&This->cs);
3535 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3537 if (hr == S_OK)
3538 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3540 LeaveCriticalSection(&This->cs);
3542 return hr;
3545 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface,
3546 LONG Left,
3547 LONG Top,
3548 LONG Width,
3549 LONG Height) {
3550 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3551 IBasicVideo* pBasicVideo;
3552 HRESULT hr;
3554 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3556 EnterCriticalSection(&This->cs);
3558 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3560 if (hr == S_OK)
3561 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3563 LeaveCriticalSection(&This->cs);
3565 return hr;
3568 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface,
3569 LONG *pLeft,
3570 LONG *pTop,
3571 LONG *pWidth,
3572 LONG *pHeight) {
3573 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3574 IBasicVideo* pBasicVideo;
3575 HRESULT hr;
3577 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3579 EnterCriticalSection(&This->cs);
3581 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3583 if (hr == S_OK)
3584 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3586 LeaveCriticalSection(&This->cs);
3588 return hr;
3591 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface) {
3592 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3593 IBasicVideo* pBasicVideo;
3594 HRESULT hr;
3596 TRACE("(%p/%p)->()\n", This, iface);
3598 EnterCriticalSection(&This->cs);
3600 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3602 if (hr == S_OK)
3603 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3605 LeaveCriticalSection(&This->cs);
3607 return hr;
3610 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface,
3611 LONG *pWidth,
3612 LONG *pHeight) {
3613 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3614 IBasicVideo* pBasicVideo;
3615 HRESULT hr;
3617 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3619 EnterCriticalSection(&This->cs);
3621 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3623 if (hr == S_OK)
3624 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3626 LeaveCriticalSection(&This->cs);
3628 return hr;
3631 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface,
3632 LONG StartIndex,
3633 LONG Entries,
3634 LONG *pRetrieved,
3635 LONG *pPalette) {
3636 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3637 IBasicVideo* pBasicVideo;
3638 HRESULT hr;
3640 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3642 EnterCriticalSection(&This->cs);
3644 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3646 if (hr == S_OK)
3647 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3649 LeaveCriticalSection(&This->cs);
3651 return hr;
3654 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface,
3655 LONG *pBufferSize,
3656 LONG *pDIBImage) {
3657 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3658 IBasicVideo* pBasicVideo;
3659 HRESULT hr;
3661 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3663 EnterCriticalSection(&This->cs);
3665 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3667 if (hr == S_OK)
3668 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3670 LeaveCriticalSection(&This->cs);
3672 return hr;
3675 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface) {
3676 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3677 IBasicVideo* pBasicVideo;
3678 HRESULT hr;
3680 TRACE("(%p/%p)->()\n", This, iface);
3682 EnterCriticalSection(&This->cs);
3684 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3686 if (hr == S_OK)
3687 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3689 LeaveCriticalSection(&This->cs);
3691 return hr;
3694 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface) {
3695 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3696 IBasicVideo* pBasicVideo;
3697 HRESULT hr;
3699 TRACE("(%p/%p)->()\n", This, iface);
3701 EnterCriticalSection(&This->cs);
3703 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3705 if (hr == S_OK)
3706 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3708 LeaveCriticalSection(&This->cs);
3710 return hr;
3713 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX, LONG *plAspectY) {
3714 ICOM_THIS_MULTI(IFilterGraphImpl, IBasicVideo_vtbl, iface);
3715 IBasicVideo2 *pBasicVideo2;
3716 HRESULT hr;
3718 TRACE("(%p/%p)->()\n", This, iface);
3720 EnterCriticalSection(&This->cs);
3722 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3724 if (hr == S_OK)
3725 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3727 LeaveCriticalSection(&This->cs);
3729 return hr;
3732 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3734 BasicVideo_QueryInterface,
3735 BasicVideo_AddRef,
3736 BasicVideo_Release,
3737 BasicVideo_GetTypeInfoCount,
3738 BasicVideo_GetTypeInfo,
3739 BasicVideo_GetIDsOfNames,
3740 BasicVideo_Invoke,
3741 BasicVideo_get_AvgTimePerFrame,
3742 BasicVideo_get_BitRate,
3743 BasicVideo_get_BitErrorRate,
3744 BasicVideo_get_VideoWidth,
3745 BasicVideo_get_VideoHeight,
3746 BasicVideo_put_SourceLeft,
3747 BasicVideo_get_SourceLeft,
3748 BasicVideo_put_SourceWidth,
3749 BasicVideo_get_SourceWidth,
3750 BasicVideo_put_SourceTop,
3751 BasicVideo_get_SourceTop,
3752 BasicVideo_put_SourceHeight,
3753 BasicVideo_get_SourceHeight,
3754 BasicVideo_put_DestinationLeft,
3755 BasicVideo_get_DestinationLeft,
3756 BasicVideo_put_DestinationWidth,
3757 BasicVideo_get_DestinationWidth,
3758 BasicVideo_put_DestinationTop,
3759 BasicVideo_get_DestinationTop,
3760 BasicVideo_put_DestinationHeight,
3761 BasicVideo_get_DestinationHeight,
3762 BasicVideo_SetSourcePosition,
3763 BasicVideo_GetSourcePosition,
3764 BasicVideo_SetDefaultSourcePosition,
3765 BasicVideo_SetDestinationPosition,
3766 BasicVideo_GetDestinationPosition,
3767 BasicVideo_SetDefaultDestinationPosition,
3768 BasicVideo_GetVideoSize,
3769 BasicVideo_GetVideoPaletteEntries,
3770 BasicVideo_GetCurrentImage,
3771 BasicVideo_IsUsingDefaultSource,
3772 BasicVideo_IsUsingDefaultDestination,
3773 BasicVideo2_GetPreferredAspectRatio
3777 /*** IUnknown methods ***/
3778 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface,
3779 REFIID riid,
3780 LPVOID*ppvObj) {
3781 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3783 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3785 return Filtergraph_QueryInterface(This, riid, ppvObj);
3788 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface) {
3789 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3791 TRACE("(%p/%p)->()\n", This, iface);
3793 return Filtergraph_AddRef(This);
3796 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface) {
3797 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3799 TRACE("(%p/%p)->()\n", This, iface);
3801 return Filtergraph_Release(This);
3804 /*** IDispatch methods ***/
3805 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface,
3806 UINT*pctinfo) {
3807 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3808 IVideoWindow* pVideoWindow;
3809 HRESULT hr;
3811 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3813 EnterCriticalSection(&This->cs);
3815 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3817 if (hr == S_OK)
3818 hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
3820 LeaveCriticalSection(&This->cs);
3822 return hr;
3825 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface,
3826 UINT iTInfo,
3827 LCID lcid,
3828 ITypeInfo**ppTInfo) {
3829 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3830 IVideoWindow* pVideoWindow;
3831 HRESULT hr;
3833 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3835 EnterCriticalSection(&This->cs);
3837 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3839 if (hr == S_OK)
3840 hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
3842 LeaveCriticalSection(&This->cs);
3844 return hr;
3847 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface,
3848 REFIID riid,
3849 LPOLESTR*rgszNames,
3850 UINT cNames,
3851 LCID lcid,
3852 DISPID*rgDispId) {
3853 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3854 IVideoWindow* pVideoWindow;
3855 HRESULT hr;
3857 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3859 EnterCriticalSection(&This->cs);
3861 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3863 if (hr == S_OK)
3864 hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
3866 LeaveCriticalSection(&This->cs);
3868 return hr;
3871 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface,
3872 DISPID dispIdMember,
3873 REFIID riid,
3874 LCID lcid,
3875 WORD wFlags,
3876 DISPPARAMS*pDispParams,
3877 VARIANT*pVarResult,
3878 EXCEPINFO*pExepInfo,
3879 UINT*puArgErr) {
3880 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3881 IVideoWindow* pVideoWindow;
3882 HRESULT hr;
3884 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3886 EnterCriticalSection(&This->cs);
3888 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3890 if (hr == S_OK)
3891 hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3893 LeaveCriticalSection(&This->cs);
3895 return hr;
3899 /*** IVideoWindow methods ***/
3900 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface,
3901 BSTR strCaption) {
3902 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3903 IVideoWindow* pVideoWindow;
3904 HRESULT hr;
3906 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
3908 EnterCriticalSection(&This->cs);
3910 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3912 if (hr == S_OK)
3913 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
3915 LeaveCriticalSection(&This->cs);
3917 return hr;
3920 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface,
3921 BSTR *strCaption) {
3922 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3923 IVideoWindow* pVideoWindow;
3924 HRESULT hr;
3926 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
3928 EnterCriticalSection(&This->cs);
3930 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3932 if (hr == S_OK)
3933 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
3935 LeaveCriticalSection(&This->cs);
3937 return hr;
3940 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface,
3941 LONG WindowStyle) {
3942 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3943 IVideoWindow* pVideoWindow;
3944 HRESULT hr;
3946 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
3948 EnterCriticalSection(&This->cs);
3950 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3952 if (hr == S_OK)
3953 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
3955 LeaveCriticalSection(&This->cs);
3957 return hr;
3960 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface,
3961 LONG *WindowStyle) {
3962 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3963 IVideoWindow* pVideoWindow;
3964 HRESULT hr;
3966 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
3968 EnterCriticalSection(&This->cs);
3970 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3972 if (hr == S_OK)
3973 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
3975 LeaveCriticalSection(&This->cs);
3977 return hr;
3980 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface,
3981 LONG WindowStyleEx) {
3982 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
3983 IVideoWindow* pVideoWindow;
3984 HRESULT hr;
3986 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
3988 EnterCriticalSection(&This->cs);
3990 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3992 if (hr == S_OK)
3993 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
3995 LeaveCriticalSection(&This->cs);
3997 return hr;
4000 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface,
4001 LONG *WindowStyleEx) {
4002 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4003 IVideoWindow* pVideoWindow;
4004 HRESULT hr;
4006 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
4008 EnterCriticalSection(&This->cs);
4010 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4012 if (hr == S_OK)
4013 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
4015 LeaveCriticalSection(&This->cs);
4017 return hr;
4020 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface,
4021 LONG AutoShow) {
4022 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4023 IVideoWindow* pVideoWindow;
4024 HRESULT hr;
4026 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
4028 EnterCriticalSection(&This->cs);
4030 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4032 if (hr == S_OK)
4033 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4035 LeaveCriticalSection(&This->cs);
4037 return hr;
4040 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface,
4041 LONG *AutoShow) {
4042 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4043 IVideoWindow* pVideoWindow;
4044 HRESULT hr;
4046 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4048 EnterCriticalSection(&This->cs);
4050 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4052 if (hr == S_OK)
4053 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4055 LeaveCriticalSection(&This->cs);
4057 return hr;
4060 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface,
4061 LONG WindowState) {
4062 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4063 IVideoWindow* pVideoWindow;
4064 HRESULT hr;
4066 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4068 EnterCriticalSection(&This->cs);
4070 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4072 if (hr == S_OK)
4073 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4075 LeaveCriticalSection(&This->cs);
4077 return hr;
4080 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface,
4081 LONG *WindowState) {
4082 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4083 IVideoWindow* pVideoWindow;
4084 HRESULT hr;
4086 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4088 EnterCriticalSection(&This->cs);
4090 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4092 if (hr == S_OK)
4093 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4095 LeaveCriticalSection(&This->cs);
4097 return hr;
4100 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface,
4101 LONG BackgroundPalette) {
4102 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4103 IVideoWindow* pVideoWindow;
4104 HRESULT hr;
4106 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4108 EnterCriticalSection(&This->cs);
4110 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4112 if (hr == S_OK)
4113 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4115 LeaveCriticalSection(&This->cs);
4117 return hr;
4120 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4121 LONG *pBackgroundPalette) {
4122 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4123 IVideoWindow* pVideoWindow;
4124 HRESULT hr;
4126 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4128 EnterCriticalSection(&This->cs);
4130 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4132 if (hr == S_OK)
4133 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4135 LeaveCriticalSection(&This->cs);
4137 return hr;
4140 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface,
4141 LONG Visible) {
4142 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4143 IVideoWindow* pVideoWindow;
4144 HRESULT hr;
4146 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4148 EnterCriticalSection(&This->cs);
4150 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4152 if (hr == S_OK)
4153 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4155 LeaveCriticalSection(&This->cs);
4157 return hr;
4160 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface,
4161 LONG *pVisible) {
4162 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4163 IVideoWindow* pVideoWindow;
4164 HRESULT hr;
4166 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4168 EnterCriticalSection(&This->cs);
4170 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4172 if (hr == S_OK)
4173 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4175 LeaveCriticalSection(&This->cs);
4177 return hr;
4180 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface,
4181 LONG Left) {
4182 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4183 IVideoWindow* pVideoWindow;
4184 HRESULT hr;
4186 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4188 EnterCriticalSection(&This->cs);
4190 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4192 if (hr == S_OK)
4193 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4195 LeaveCriticalSection(&This->cs);
4197 return hr;
4200 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface,
4201 LONG *pLeft) {
4202 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4203 IVideoWindow* pVideoWindow;
4204 HRESULT hr;
4206 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4208 EnterCriticalSection(&This->cs);
4210 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4212 if (hr == S_OK)
4213 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4215 LeaveCriticalSection(&This->cs);
4217 return hr;
4220 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface,
4221 LONG Width) {
4222 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4223 IVideoWindow* pVideoWindow;
4224 HRESULT hr;
4226 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4228 EnterCriticalSection(&This->cs);
4230 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4232 if (hr == S_OK)
4233 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4235 LeaveCriticalSection(&This->cs);
4237 return hr;
4240 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface,
4241 LONG *pWidth) {
4242 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4243 IVideoWindow* pVideoWindow;
4244 HRESULT hr;
4246 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4248 EnterCriticalSection(&This->cs);
4250 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4252 if (hr == S_OK)
4253 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4255 LeaveCriticalSection(&This->cs);
4257 return hr;
4260 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface,
4261 LONG Top) {
4262 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4263 IVideoWindow* pVideoWindow;
4264 HRESULT hr;
4266 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4268 EnterCriticalSection(&This->cs);
4270 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4272 if (hr == S_OK)
4273 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4275 LeaveCriticalSection(&This->cs);
4277 return hr;
4280 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface,
4281 LONG *pTop) {
4282 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4283 IVideoWindow* pVideoWindow;
4284 HRESULT hr;
4286 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4288 EnterCriticalSection(&This->cs);
4290 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4292 if (hr == S_OK)
4293 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4295 LeaveCriticalSection(&This->cs);
4297 return hr;
4300 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface,
4301 LONG Height) {
4302 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4303 IVideoWindow* pVideoWindow;
4304 HRESULT hr;
4306 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4308 EnterCriticalSection(&This->cs);
4310 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4312 if (hr == S_OK)
4313 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4315 LeaveCriticalSection(&This->cs);
4317 return hr;
4320 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface,
4321 LONG *pHeight) {
4322 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4323 IVideoWindow* pVideoWindow;
4324 HRESULT hr;
4326 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4328 EnterCriticalSection(&This->cs);
4330 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4332 if (hr == S_OK)
4333 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4335 LeaveCriticalSection(&This->cs);
4337 return hr;
4340 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface,
4341 OAHWND Owner) {
4342 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4343 IVideoWindow* pVideoWindow;
4344 HRESULT hr;
4346 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4348 EnterCriticalSection(&This->cs);
4350 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4352 if (hr == S_OK)
4353 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4355 LeaveCriticalSection(&This->cs);
4357 return hr;
4360 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface,
4361 OAHWND *Owner) {
4362 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4363 IVideoWindow* pVideoWindow;
4364 HRESULT hr;
4366 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4368 EnterCriticalSection(&This->cs);
4370 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4372 if (hr == S_OK)
4373 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4375 LeaveCriticalSection(&This->cs);
4377 return hr;
4380 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface,
4381 OAHWND Drain) {
4382 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4383 IVideoWindow* pVideoWindow;
4384 HRESULT hr;
4386 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4388 EnterCriticalSection(&This->cs);
4390 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4392 if (hr == S_OK)
4393 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4395 LeaveCriticalSection(&This->cs);
4397 return hr;
4400 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface,
4401 OAHWND *Drain) {
4402 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4403 IVideoWindow* pVideoWindow;
4404 HRESULT hr;
4406 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4408 EnterCriticalSection(&This->cs);
4410 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4412 if (hr == S_OK)
4413 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4415 LeaveCriticalSection(&This->cs);
4417 return hr;
4420 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface,
4421 LONG *Color) {
4422 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4423 IVideoWindow* pVideoWindow;
4424 HRESULT hr;
4426 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4428 EnterCriticalSection(&This->cs);
4430 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4432 if (hr == S_OK)
4433 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4435 LeaveCriticalSection(&This->cs);
4437 return hr;
4440 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface,
4441 LONG Color) {
4442 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4443 IVideoWindow* pVideoWindow;
4444 HRESULT hr;
4446 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4448 EnterCriticalSection(&This->cs);
4450 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4452 if (hr == S_OK)
4453 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4455 LeaveCriticalSection(&This->cs);
4457 return hr;
4460 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface,
4461 LONG *FullScreenMode) {
4462 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4463 IVideoWindow* pVideoWindow;
4464 HRESULT hr;
4466 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4468 EnterCriticalSection(&This->cs);
4470 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4472 if (hr == S_OK)
4473 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4475 LeaveCriticalSection(&This->cs);
4477 return hr;
4480 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface,
4481 LONG FullScreenMode) {
4482 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4483 IVideoWindow* pVideoWindow;
4484 HRESULT hr;
4486 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4488 EnterCriticalSection(&This->cs);
4490 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4492 if (hr == S_OK)
4493 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4495 LeaveCriticalSection(&This->cs);
4497 return hr;
4500 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface,
4501 LONG Focus) {
4502 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4503 IVideoWindow* pVideoWindow;
4504 HRESULT hr;
4506 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4508 EnterCriticalSection(&This->cs);
4510 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4512 if (hr == S_OK)
4513 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4515 LeaveCriticalSection(&This->cs);
4517 return hr;
4520 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface,
4521 OAHWND hwnd,
4522 LONG uMsg,
4523 LONG_PTR wParam,
4524 LONG_PTR lParam) {
4525 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4526 IVideoWindow* pVideoWindow;
4527 HRESULT hr;
4529 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4531 EnterCriticalSection(&This->cs);
4533 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4535 if (hr == S_OK)
4536 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4538 LeaveCriticalSection(&This->cs);
4540 return hr;
4543 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface,
4544 LONG Left,
4545 LONG Top,
4546 LONG Width,
4547 LONG Height) {
4548 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4549 IVideoWindow* pVideoWindow;
4550 HRESULT hr;
4552 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4554 EnterCriticalSection(&This->cs);
4556 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4558 if (hr == S_OK)
4559 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4561 LeaveCriticalSection(&This->cs);
4563 return hr;
4566 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface,
4567 LONG *pLeft,
4568 LONG *pTop,
4569 LONG *pWidth,
4570 LONG *pHeight) {
4571 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4572 IVideoWindow* pVideoWindow;
4573 HRESULT hr;
4575 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4577 EnterCriticalSection(&This->cs);
4579 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4581 if (hr == S_OK)
4582 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4584 LeaveCriticalSection(&This->cs);
4586 return hr;
4589 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface,
4590 LONG *pWidth,
4591 LONG *pHeight) {
4592 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4593 IVideoWindow* pVideoWindow;
4594 HRESULT hr;
4596 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4598 EnterCriticalSection(&This->cs);
4600 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4602 if (hr == S_OK)
4603 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4605 LeaveCriticalSection(&This->cs);
4607 return hr;
4610 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface,
4611 LONG *pWidth,
4612 LONG *pHeight) {
4613 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4614 IVideoWindow* pVideoWindow;
4615 HRESULT hr;
4617 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4619 EnterCriticalSection(&This->cs);
4621 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4623 if (hr == S_OK)
4624 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4626 LeaveCriticalSection(&This->cs);
4628 return hr;
4631 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface,
4632 LONG *pLeft,
4633 LONG *pTop,
4634 LONG *pWidth,
4635 LONG *pHeight) {
4636 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4637 IVideoWindow* pVideoWindow;
4638 HRESULT hr;
4640 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4642 EnterCriticalSection(&This->cs);
4644 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4646 if (hr == S_OK)
4647 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4649 LeaveCriticalSection(&This->cs);
4651 return hr;
4654 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface,
4655 LONG HideCursor) {
4656 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4657 IVideoWindow* pVideoWindow;
4658 HRESULT hr;
4660 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4662 EnterCriticalSection(&This->cs);
4664 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4666 if (hr == S_OK)
4667 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4669 LeaveCriticalSection(&This->cs);
4671 return hr;
4674 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface,
4675 LONG *CursorHidden) {
4676 ICOM_THIS_MULTI(IFilterGraphImpl, IVideoWindow_vtbl, iface);
4677 IVideoWindow* pVideoWindow;
4678 HRESULT hr;
4680 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4682 EnterCriticalSection(&This->cs);
4684 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4686 if (hr == S_OK)
4687 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4689 LeaveCriticalSection(&This->cs);
4691 return hr;
4695 static const IVideoWindowVtbl IVideoWindow_VTable =
4697 VideoWindow_QueryInterface,
4698 VideoWindow_AddRef,
4699 VideoWindow_Release,
4700 VideoWindow_GetTypeInfoCount,
4701 VideoWindow_GetTypeInfo,
4702 VideoWindow_GetIDsOfNames,
4703 VideoWindow_Invoke,
4704 VideoWindow_put_Caption,
4705 VideoWindow_get_Caption,
4706 VideoWindow_put_WindowStyle,
4707 VideoWindow_get_WindowStyle,
4708 VideoWindow_put_WindowStyleEx,
4709 VideoWindow_get_WindowStyleEx,
4710 VideoWindow_put_AutoShow,
4711 VideoWindow_get_AutoShow,
4712 VideoWindow_put_WindowState,
4713 VideoWindow_get_WindowState,
4714 VideoWindow_put_BackgroundPalette,
4715 VideoWindow_get_BackgroundPalette,
4716 VideoWindow_put_Visible,
4717 VideoWindow_get_Visible,
4718 VideoWindow_put_Left,
4719 VideoWindow_get_Left,
4720 VideoWindow_put_Width,
4721 VideoWindow_get_Width,
4722 VideoWindow_put_Top,
4723 VideoWindow_get_Top,
4724 VideoWindow_put_Height,
4725 VideoWindow_get_Height,
4726 VideoWindow_put_Owner,
4727 VideoWindow_get_Owner,
4728 VideoWindow_put_MessageDrain,
4729 VideoWindow_get_MessageDrain,
4730 VideoWindow_get_BorderColor,
4731 VideoWindow_put_BorderColor,
4732 VideoWindow_get_FullScreenMode,
4733 VideoWindow_put_FullScreenMode,
4734 VideoWindow_SetWindowForeground,
4735 VideoWindow_NotifyOwnerMessage,
4736 VideoWindow_SetWindowPosition,
4737 VideoWindow_GetWindowPosition,
4738 VideoWindow_GetMinIdealImageSize,
4739 VideoWindow_GetMaxIdealImageSize,
4740 VideoWindow_GetRestorePosition,
4741 VideoWindow_HideCursor,
4742 VideoWindow_IsCursorHidden
4746 /*** IUnknown methods ***/
4747 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface,
4748 REFIID riid,
4749 LPVOID*ppvObj) {
4750 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4752 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
4754 return Filtergraph_QueryInterface(This, riid, ppvObj);
4757 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface) {
4758 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4760 TRACE("(%p/%p)->()\n", This, iface);
4762 return Filtergraph_AddRef(This);
4765 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface) {
4766 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4768 TRACE("(%p/%p)->()\n", This, iface);
4770 return Filtergraph_Release(This);
4773 /*** IDispatch methods ***/
4774 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface,
4775 UINT*pctinfo) {
4776 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4778 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
4780 return S_OK;
4783 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface,
4784 UINT iTInfo,
4785 LCID lcid,
4786 ITypeInfo**ppTInfo) {
4787 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4789 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
4791 return S_OK;
4794 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface,
4795 REFIID riid,
4796 LPOLESTR*rgszNames,
4797 UINT cNames,
4798 LCID lcid,
4799 DISPID*rgDispId) {
4800 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4802 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
4804 return S_OK;
4807 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface,
4808 DISPID dispIdMember,
4809 REFIID riid,
4810 LCID lcid,
4811 WORD wFlags,
4812 DISPPARAMS*pDispParams,
4813 VARIANT*pVarResult,
4814 EXCEPINFO*pExepInfo,
4815 UINT*puArgErr) {
4816 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4818 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4820 return S_OK;
4823 /*** IMediaEvent methods ***/
4824 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface,
4825 OAEVENT *hEvent) {
4826 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4828 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
4830 *hEvent = (OAEVENT)This->evqueue.msg_event;
4832 return S_OK;
4835 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface,
4836 LONG *lEventCode,
4837 LONG_PTR *lParam1,
4838 LONG_PTR *lParam2,
4839 LONG msTimeout) {
4840 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4841 Event evt;
4843 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
4845 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
4847 *lEventCode = evt.lEventCode;
4848 *lParam1 = evt.lParam1;
4849 *lParam2 = evt.lParam2;
4850 return S_OK;
4853 *lEventCode = 0;
4854 return E_ABORT;
4857 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface,
4858 LONG msTimeout,
4859 LONG *pEvCode) {
4860 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4862 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
4864 if (This->state != State_Running)
4865 return VFW_E_WRONG_STATE;
4867 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
4869 *pEvCode = This->CompletionStatus;
4870 return S_OK;
4873 *pEvCode = 0;
4874 return E_ABORT;
4877 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface,
4878 LONG lEvCode) {
4879 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4881 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4883 if (lEvCode == EC_COMPLETE)
4884 This->HandleEcComplete = FALSE;
4885 else if (lEvCode == EC_REPAINT)
4886 This->HandleEcRepaint = FALSE;
4887 else if (lEvCode == EC_CLOCK_CHANGED)
4888 This->HandleEcClockChanged = FALSE;
4889 else
4890 return S_FALSE;
4892 return S_OK;
4895 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface,
4896 LONG lEvCode) {
4897 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4899 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4901 if (lEvCode == EC_COMPLETE)
4902 This->HandleEcComplete = TRUE;
4903 else if (lEvCode == EC_REPAINT)
4904 This->HandleEcRepaint = TRUE;
4905 else if (lEvCode == EC_CLOCK_CHANGED)
4906 This->HandleEcClockChanged = TRUE;
4907 else
4908 return S_FALSE;
4910 return S_OK;
4913 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface,
4914 LONG lEvCode,
4915 LONG_PTR lParam1,
4916 LONG_PTR lParam2) {
4917 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4919 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
4921 return S_OK;
4924 /*** IMediaEventEx methods ***/
4925 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface,
4926 OAHWND hwnd,
4927 LONG lMsg,
4928 LONG_PTR lInstanceData) {
4929 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4931 TRACE("(%p/%p)->(%08lx, %d, %08lx)\n", This, iface, hwnd, lMsg, lInstanceData);
4933 This->notif.hWnd = (HWND)hwnd;
4934 This->notif.msg = lMsg;
4935 This->notif.instance = lInstanceData;
4937 return S_OK;
4940 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface,
4941 LONG lNoNotifyFlags) {
4942 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4944 TRACE("(%p/%p)->(%d)\n", This, iface, lNoNotifyFlags);
4946 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
4947 return E_INVALIDARG;
4949 This->notif.disabled = lNoNotifyFlags;
4951 return S_OK;
4954 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface,
4955 LONG *lplNoNotifyFlags) {
4956 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventEx_vtbl, iface);
4958 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
4960 if (!lplNoNotifyFlags)
4961 return E_POINTER;
4963 *lplNoNotifyFlags = This->notif.disabled;
4965 return S_OK;
4969 static const IMediaEventExVtbl IMediaEventEx_VTable =
4971 MediaEvent_QueryInterface,
4972 MediaEvent_AddRef,
4973 MediaEvent_Release,
4974 MediaEvent_GetTypeInfoCount,
4975 MediaEvent_GetTypeInfo,
4976 MediaEvent_GetIDsOfNames,
4977 MediaEvent_Invoke,
4978 MediaEvent_GetEventHandle,
4979 MediaEvent_GetEvent,
4980 MediaEvent_WaitForCompletion,
4981 MediaEvent_CancelDefaultHandling,
4982 MediaEvent_RestoreDefaultHandling,
4983 MediaEvent_FreeEventParams,
4984 MediaEvent_SetNotifyWindow,
4985 MediaEvent_SetNotifyFlags,
4986 MediaEvent_GetNotifyFlags
4990 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, LPVOID *ppv)
4992 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
4994 return Filtergraph_QueryInterface(This, riid, ppv);
4997 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
4999 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5001 return Filtergraph_AddRef(This);
5004 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
5006 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5008 return Filtergraph_Release(This);
5011 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
5013 FIXME("(%p): stub\n", pClassID);
5015 return E_NOTIMPL;
5018 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
5020 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5021 return MediaControl_Stop((IMediaControl*)&This->IMediaControl_vtbl);
5024 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5026 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5027 return MediaControl_Pause((IMediaControl*)&This->IMediaControl_vtbl);
5030 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
5032 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5033 if (tStart)
5034 FIXME("Run called with non-null tStart: %x%08x\n",
5035 (int)(tStart>>32), (int)tStart);
5036 return MediaControl_Run((IMediaControl*)&This->IMediaControl_vtbl);
5039 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout, FILTER_STATE * pState)
5041 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5042 return MediaControl_GetState((IMediaControl*)&This->IMediaControl_vtbl, dwMsTimeout, (OAFilterState*)pState);
5045 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5047 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5048 HRESULT hr = S_OK;
5049 int i;
5051 TRACE("(%p/%p)->(%p)\n", iface, This, pClock);
5053 EnterCriticalSection(&This->cs);
5055 for (i = 0;i < This->nFilters;i++)
5057 hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5058 if (FAILED(hr))
5059 break;
5062 if (FAILED(hr))
5064 for(;i >= 0;i--)
5065 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5067 else
5069 if (This->refClock)
5070 IReferenceClock_Release(This->refClock);
5071 This->refClock = pClock;
5072 if (This->refClock)
5073 IReferenceClock_AddRef(This->refClock);
5075 if (This->HandleEcClockChanged)
5077 IMediaEventSink *pEventSink;
5078 HRESULT eshr;
5080 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (LPVOID)&pEventSink);
5081 if (SUCCEEDED(eshr))
5083 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5084 IMediaEventSink_Release(pEventSink);
5089 LeaveCriticalSection(&This->cs);
5091 return hr;
5094 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5096 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaFilter_vtbl, iface);
5098 TRACE("(%p/%p)->(%p)\n", iface, This, ppClock);
5100 if (!ppClock)
5101 return E_POINTER;
5103 EnterCriticalSection(&This->cs);
5105 *ppClock = This->refClock;
5106 if (*ppClock)
5107 IReferenceClock_AddRef(*ppClock);
5109 LeaveCriticalSection(&This->cs);
5111 return S_OK;
5114 static const IMediaFilterVtbl IMediaFilter_VTable =
5116 MediaFilter_QueryInterface,
5117 MediaFilter_AddRef,
5118 MediaFilter_Release,
5119 MediaFilter_GetClassID,
5120 MediaFilter_Stop,
5121 MediaFilter_Pause,
5122 MediaFilter_Run,
5123 MediaFilter_GetState,
5124 MediaFilter_SetSyncSource,
5125 MediaFilter_GetSyncSource
5128 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, LPVOID *ppv)
5130 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5132 return Filtergraph_QueryInterface(This, riid, ppv);
5135 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5137 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5139 return Filtergraph_AddRef(This);
5142 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5144 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5146 return Filtergraph_Release(This);
5149 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG EventCode, LONG_PTR EventParam1, LONG_PTR EventParam2)
5151 ICOM_THIS_MULTI(IFilterGraphImpl, IMediaEventSink_vtbl, iface);
5152 Event evt;
5154 TRACE("(%p/%p)->(%d, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5156 /* We need thread safety here, let's use the events queue's one */
5157 EnterCriticalSection(&This->evqueue.msg_crst);
5159 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5161 TRACE("Process EC_COMPLETE notification\n");
5162 if (++This->EcCompleteCount == This->nRenderers)
5164 evt.lEventCode = EC_COMPLETE;
5165 evt.lParam1 = S_OK;
5166 evt.lParam2 = 0;
5167 TRACE("Send EC_COMPLETE to app\n");
5168 EventsQueue_PutEvent(&This->evqueue, &evt);
5169 if (!This->notif.disabled && This->notif.hWnd)
5171 TRACE("Send Window message\n");
5172 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5174 This->CompletionStatus = EC_COMPLETE;
5175 SetEvent(This->hEventCompletion);
5178 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5180 /* FIXME: Not handled yet */
5182 else
5184 evt.lEventCode = EventCode;
5185 evt.lParam1 = EventParam1;
5186 evt.lParam2 = EventParam2;
5187 EventsQueue_PutEvent(&This->evqueue, &evt);
5188 if (!This->notif.disabled && This->notif.hWnd)
5189 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5192 LeaveCriticalSection(&This->evqueue.msg_crst);
5193 return S_OK;
5196 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5198 MediaEventSink_QueryInterface,
5199 MediaEventSink_AddRef,
5200 MediaEventSink_Release,
5201 MediaEventSink_Notify
5204 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, LPVOID *ppv)
5206 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5208 return Filtergraph_QueryInterface(This, riid, ppv);
5211 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5213 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5215 return Filtergraph_AddRef(This);
5218 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5220 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5222 return Filtergraph_Release(This);
5225 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface,
5226 IPin* pOutputPin,
5227 IPin* pInputPin,
5228 const AM_MEDIA_TYPE* pmtFirstConnection,
5229 IBaseFilter* pUsingFilter,
5230 HANDLE hAbortEvent,
5231 DWORD dwFlags)
5233 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5235 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5237 return E_NOTIMPL;
5240 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface,
5241 IGraphConfigCallback* pCallback,
5242 PVOID pvContext,
5243 DWORD dwFlags,
5244 HANDLE hAbortEvent)
5246 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5247 HRESULT hr;
5249 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5251 if (hAbortEvent)
5252 FIXME("The parameter hAbortEvent is not handled!\n");
5254 EnterCriticalSection(&This->cs);
5256 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5258 LeaveCriticalSection(&This->cs);
5260 return hr;
5263 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface,
5264 IBaseFilter* pFilter)
5266 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5268 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5270 return E_NOTIMPL;
5273 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface,
5274 IEnumFilters** pEnum)
5276 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5278 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5280 return E_NOTIMPL;
5283 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface,
5284 IBaseFilter* pFilter)
5286 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5288 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5290 return E_NOTIMPL;
5293 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface,
5294 REFERENCE_TIME* prtStart)
5296 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5298 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5300 return E_NOTIMPL;
5303 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface,
5304 IPin* pOutputPin,
5305 IPinConnection* pConnection,
5306 HANDLE hEventAbort)
5308 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5310 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5312 return E_NOTIMPL;
5315 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface,
5316 IBaseFilter* pFilter,
5317 DWORD dwFlags)
5319 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5321 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5323 return E_NOTIMPL;
5326 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface,
5327 IBaseFilter* pFilter,
5328 DWORD* dwFlags)
5330 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5332 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5334 return E_NOTIMPL;
5337 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface,
5338 IBaseFilter* pFilter,
5339 DWORD dwFlags)
5341 ICOM_THIS_MULTI(IFilterGraphImpl, IGraphConfig_vtbl, iface);
5343 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5345 return E_NOTIMPL;
5348 static const IGraphConfigVtbl IGraphConfig_VTable =
5350 GraphConfig_QueryInterface,
5351 GraphConfig_AddRef,
5352 GraphConfig_Release,
5353 GraphConfig_Reconnect,
5354 GraphConfig_Reconfigure,
5355 GraphConfig_AddFilterToCache,
5356 GraphConfig_EnumCacheFilter,
5357 GraphConfig_RemoveFilterFromCache,
5358 GraphConfig_GetStartTime,
5359 GraphConfig_PushThroughData,
5360 GraphConfig_SetFilterFlags,
5361 GraphConfig_GetFilterFlags,
5362 GraphConfig_RemoveFilterEx
5365 static const IUnknownVtbl IInner_VTable =
5367 FilterGraphInner_QueryInterface,
5368 FilterGraphInner_AddRef,
5369 FilterGraphInner_Release
5372 static HRESULT Filtergraph_QueryInterface(IFilterGraphImpl *This,
5373 REFIID riid,
5374 LPVOID * ppv) {
5375 if (This->bAggregatable)
5376 This->bUnkOuterValid = TRUE;
5378 if (This->pUnkOuter)
5380 if (This->bAggregatable)
5381 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
5383 if (IsEqualIID(riid, &IID_IUnknown))
5385 HRESULT hr;
5387 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5388 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5389 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5390 This->bAggregatable = TRUE;
5391 return hr;
5394 *ppv = NULL;
5395 return E_NOINTERFACE;
5398 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
5401 static ULONG Filtergraph_AddRef(IFilterGraphImpl *This) {
5402 if (This->pUnkOuter && This->bUnkOuterValid)
5403 return IUnknown_AddRef(This->pUnkOuter);
5404 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
5407 static ULONG Filtergraph_Release(IFilterGraphImpl *This) {
5408 if (This->pUnkOuter && This->bUnkOuterValid)
5409 return IUnknown_Release(This->pUnkOuter);
5410 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
5413 /* This is the only function that actually creates a FilterGraph class... */
5414 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5416 IFilterGraphImpl *fimpl;
5417 HRESULT hr;
5419 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5421 *ppObj = NULL;
5423 fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5424 fimpl->pUnkOuter = pUnkOuter;
5425 fimpl->bUnkOuterValid = FALSE;
5426 fimpl->bAggregatable = FALSE;
5427 fimpl->IInner_vtbl = &IInner_VTable;
5428 fimpl->IFilterGraph2_vtbl = &IFilterGraph2_VTable;
5429 fimpl->IMediaControl_vtbl = &IMediaControl_VTable;
5430 fimpl->IMediaSeeking_vtbl = &IMediaSeeking_VTable;
5431 fimpl->IBasicAudio_vtbl = &IBasicAudio_VTable;
5432 fimpl->IBasicVideo_vtbl = &IBasicVideo_VTable;
5433 fimpl->IVideoWindow_vtbl = &IVideoWindow_VTable;
5434 fimpl->IMediaEventEx_vtbl = &IMediaEventEx_VTable;
5435 fimpl->IMediaFilter_vtbl = &IMediaFilter_VTable;
5436 fimpl->IMediaEventSink_vtbl = &IMediaEventSink_VTable;
5437 fimpl->IGraphConfig_vtbl = &IGraphConfig_VTable;
5438 fimpl->IMediaPosition_vtbl = &IMediaPosition_VTable;
5439 fimpl->ref = 1;
5440 fimpl->ppFiltersInGraph = NULL;
5441 fimpl->pFilterNames = NULL;
5442 fimpl->nFilters = 0;
5443 fimpl->filterCapacity = 0;
5444 fimpl->nameIndex = 1;
5445 fimpl->refClock = NULL;
5446 fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5447 fimpl->HandleEcComplete = TRUE;
5448 fimpl->HandleEcRepaint = TRUE;
5449 fimpl->HandleEcClockChanged = TRUE;
5450 fimpl->notif.hWnd = 0;
5451 fimpl->notif.disabled = FALSE;
5452 fimpl->nRenderers = 0;
5453 fimpl->EcCompleteCount = 0;
5454 fimpl->state = State_Stopped;
5455 EventsQueue_Init(&fimpl->evqueue);
5456 InitializeCriticalSection(&fimpl->cs);
5457 fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5458 fimpl->nItfCacheEntries = 0;
5459 memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5460 fimpl->start_time = fimpl->pause_time = 0;
5461 fimpl->stop_position = -1;
5462 fimpl->punkFilterMapper2 = NULL;
5463 fimpl->recursioncount = 0;
5465 /* create Filtermapper aggregated. */
5466 hr = CoCreateInstance(&CLSID_FilterMapper2, pUnkOuter ? pUnkOuter : (IUnknown*)&fimpl->IInner_vtbl, CLSCTX_INPROC_SERVER,
5467 &IID_IUnknown, (LPVOID*)&fimpl->punkFilterMapper2);
5469 if (SUCCEEDED(hr)) {
5470 hr = IUnknown_QueryInterface(fimpl->punkFilterMapper2, &IID_IFilterMapper2, (LPVOID*)&fimpl->pFilterMapper2);
5473 if (SUCCEEDED(hr)) {
5474 /* Release controlling IUnknown - compensate refcount increase from caching IFilterMapper2 interface. */
5475 if (pUnkOuter) IUnknown_Release(pUnkOuter);
5476 else IUnknown_Release((IUnknown*)&fimpl->IInner_vtbl);
5479 if (FAILED(hr)) {
5480 ERR("Unable to create filter mapper (%x)\n", hr);
5481 if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5482 CloseHandle(fimpl->hEventCompletion);
5483 EventsQueue_Destroy(&fimpl->evqueue);
5484 fimpl->cs.DebugInfo->Spare[0] = 0;
5485 DeleteCriticalSection(&fimpl->cs);
5486 CoTaskMemFree(fimpl);
5487 return hr;
5489 IFilterGraph2_SetDefaultSyncSource((IFilterGraph2*)fimpl);
5491 *ppObj = fimpl;
5492 return S_OK;
5495 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5497 FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5498 return FilterGraph_create(pUnkOuter, ppObj);