ieframe: Fix memory leak in PersistFile_Save.
[wine.git] / dlls / quartz / filtergraph.c
blob580388292175df0f68030e2b5634aba9945d3ffb
1 /* DirectShow FilterGraph object (QUARTZ.DLL)
3 * Copyright 2002 Lionel Ulmer
4 * Copyright 2004 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <assert.h>
22 #include <stdarg.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "shlwapi.h"
31 #include "dshow.h"
32 #include "wine/debug.h"
33 #include "quartz_private.h"
34 #include "ole2.h"
35 #include "olectl.h"
36 #include "strmif.h"
37 #include "vfwmsgs.h"
38 #include "evcode.h"
39 #include "wine/heap.h"
40 #include "wine/list.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
45 typedef struct {
46 HWND hWnd; /* Target window */
47 UINT msg; /* User window message */
48 LONG_PTR instance; /* User data */
49 int disabled; /* Disabled messages posting */
50 } WndNotify;
52 typedef struct {
53 LONG lEventCode; /* Event code */
54 LONG_PTR lParam1; /* Param1 */
55 LONG_PTR lParam2; /* Param2 */
56 } Event;
58 /* messages ring implementation for queuing events (taken from winmm) */
59 #define EVENTS_RING_BUFFER_INCREMENT 64
60 typedef struct {
61 Event* messages;
62 int ring_buffer_size;
63 int msg_tosave;
64 int msg_toget;
65 CRITICAL_SECTION msg_crst;
66 HANDLE msg_event; /* Signaled for no empty queue */
67 } EventsQueue;
69 static int EventsQueue_Init(EventsQueue* omr)
71 omr->msg_toget = 0;
72 omr->msg_tosave = 0;
73 omr->msg_event = CreateEventW(NULL, TRUE, FALSE, NULL);
74 omr->ring_buffer_size = EVENTS_RING_BUFFER_INCREMENT;
75 omr->messages = CoTaskMemAlloc(omr->ring_buffer_size * sizeof(Event));
76 ZeroMemory(omr->messages, omr->ring_buffer_size * sizeof(Event));
78 InitializeCriticalSection(&omr->msg_crst);
79 omr->msg_crst.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": EventsQueue.msg_crst");
80 return TRUE;
83 static int EventsQueue_Destroy(EventsQueue* omr)
85 CloseHandle(omr->msg_event);
86 CoTaskMemFree(omr->messages);
87 omr->msg_crst.DebugInfo->Spare[0] = 0;
88 DeleteCriticalSection(&omr->msg_crst);
89 return TRUE;
92 static BOOL EventsQueue_PutEvent(EventsQueue* omr, const Event* evt)
94 EnterCriticalSection(&omr->msg_crst);
95 if (omr->msg_toget == ((omr->msg_tosave + 1) % omr->ring_buffer_size))
97 int old_ring_buffer_size = omr->ring_buffer_size;
98 omr->ring_buffer_size += EVENTS_RING_BUFFER_INCREMENT;
99 TRACE("omr->ring_buffer_size=%d\n",omr->ring_buffer_size);
100 omr->messages = CoTaskMemRealloc(omr->messages, omr->ring_buffer_size * sizeof(Event));
101 /* Now we need to rearrange the ring buffer so that the new
102 buffers just allocated are in between omr->msg_tosave and
103 omr->msg_toget.
105 if (omr->msg_tosave < omr->msg_toget)
107 memmove(&(omr->messages[omr->msg_toget + EVENTS_RING_BUFFER_INCREMENT]),
108 &(omr->messages[omr->msg_toget]),
109 sizeof(Event)*(old_ring_buffer_size - omr->msg_toget)
111 omr->msg_toget += EVENTS_RING_BUFFER_INCREMENT;
114 omr->messages[omr->msg_tosave] = *evt;
115 SetEvent(omr->msg_event);
116 omr->msg_tosave = (omr->msg_tosave + 1) % omr->ring_buffer_size;
117 LeaveCriticalSection(&omr->msg_crst);
118 return TRUE;
121 static BOOL EventsQueue_GetEvent(EventsQueue* omr, Event* evt, LONG msTimeOut)
123 if (WaitForSingleObject(omr->msg_event, msTimeOut) != WAIT_OBJECT_0)
124 return FALSE;
126 EnterCriticalSection(&omr->msg_crst);
128 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
130 LeaveCriticalSection(&omr->msg_crst);
131 return FALSE;
134 *evt = omr->messages[omr->msg_toget];
135 omr->msg_toget = (omr->msg_toget + 1) % omr->ring_buffer_size;
137 /* Mark the buffer as empty if needed */
138 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
139 ResetEvent(omr->msg_event);
141 LeaveCriticalSection(&omr->msg_crst);
142 return TRUE;
145 #define MAX_ITF_CACHE_ENTRIES 3
146 typedef struct _ITF_CACHE_ENTRY {
147 const IID* riid;
148 IBaseFilter* filter;
149 IUnknown* iface;
150 } ITF_CACHE_ENTRY;
152 struct filter
154 struct list entry;
155 IBaseFilter *filter;
156 IMediaSeeking *seeking;
157 WCHAR *name;
158 BOOL sorting;
161 struct filter_graph
163 IUnknown IUnknown_inner;
164 IFilterGraph2 IFilterGraph2_iface;
165 IMediaControl IMediaControl_iface;
166 IMediaSeeking IMediaSeeking_iface;
167 IBasicAudio IBasicAudio_iface;
168 IBasicVideo2 IBasicVideo2_iface;
169 IVideoWindow IVideoWindow_iface;
170 IMediaEventEx IMediaEventEx_iface;
171 IMediaFilter IMediaFilter_iface;
172 IMediaEventSink IMediaEventSink_iface;
173 IGraphConfig IGraphConfig_iface;
174 IMediaPosition IMediaPosition_iface;
175 IObjectWithSite IObjectWithSite_iface;
176 IGraphVersion IGraphVersion_iface;
177 /* IAMGraphStreams */
178 /* IAMStats */
179 /* IFilterChain */
180 /* IFilterMapper2 */
181 /* IQueueCommand */
182 /* IRegisterServiceProvider */
183 /* IResourceManager */
184 /* IServiceProvider */
185 IVideoFrameStep IVideoFrameStep_iface;
187 IUnknown *outer_unk;
188 LONG ref;
189 IUnknown *punkFilterMapper2;
191 struct list filters;
192 unsigned int name_index;
194 OAFilterState state;
195 TP_WORK *async_run_work;
197 IReferenceClock *refClock;
198 IBaseFilter *refClockProvider;
199 EventsQueue evqueue;
200 HANDLE hEventCompletion;
201 int CompletionStatus;
202 WndNotify notif;
203 int nRenderers;
204 int EcCompleteCount;
205 int HandleEcComplete;
206 int HandleEcRepaint;
207 int HandleEcClockChanged;
208 CRITICAL_SECTION cs;
209 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
210 int nItfCacheEntries;
211 BOOL defaultclock;
212 GUID timeformatseek;
213 IUnknown *pSite;
214 LONG version;
216 HANDLE message_thread, message_thread_ret;
217 DWORD message_thread_id;
219 /* Respectively: the last timestamp at which we started streaming, and the
220 * current offset within the stream. */
221 REFERENCE_TIME stream_start, stream_elapsed;
222 REFERENCE_TIME stream_stop;
223 LONGLONG current_pos;
225 unsigned int needs_async_run : 1;
226 unsigned int got_ec_complete : 1;
229 struct enum_filters
231 IEnumFilters IEnumFilters_iface;
232 LONG ref;
233 struct filter_graph *graph;
234 LONG version;
235 struct list *cursor;
238 static HRESULT create_enum_filters(struct filter_graph *graph, struct list *cursor, IEnumFilters **out);
240 static inline struct enum_filters *impl_from_IEnumFilters(IEnumFilters *iface)
242 return CONTAINING_RECORD(iface, struct enum_filters, IEnumFilters_iface);
245 static HRESULT WINAPI EnumFilters_QueryInterface(IEnumFilters *iface, REFIID iid, void **out)
247 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
248 TRACE("enum_filters %p, iid %s, out %p.\n", enum_filters, qzdebugstr_guid(iid), out);
250 if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IEnumFilters))
252 IEnumFilters_AddRef(*out = iface);
253 return S_OK;
256 WARN("%s not implemented, returning E_NOINTERFACE.\n", qzdebugstr_guid(iid));
257 *out = NULL;
258 return E_NOINTERFACE;
261 static ULONG WINAPI EnumFilters_AddRef(IEnumFilters *iface)
263 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
264 ULONG ref = InterlockedIncrement(&enum_filters->ref);
266 TRACE("%p increasing refcount to %u.\n", enum_filters, ref);
268 return ref;
271 static ULONG WINAPI EnumFilters_Release(IEnumFilters *iface)
273 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
274 ULONG ref = InterlockedDecrement(&enum_filters->ref);
276 TRACE("%p decreasing refcount to %u.\n", enum_filters, ref);
278 if (!ref)
280 IUnknown_Release(enum_filters->graph->outer_unk);
281 heap_free(enum_filters);
284 return ref;
287 static HRESULT WINAPI EnumFilters_Next(IEnumFilters *iface, ULONG count,
288 IBaseFilter **filters, ULONG *fetched)
290 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
291 unsigned int i = 0;
293 TRACE("enum_filters %p, count %u, filters %p, fetched %p.\n",
294 enum_filters, count, filters, fetched);
296 if (enum_filters->version != enum_filters->graph->version)
297 return VFW_E_ENUM_OUT_OF_SYNC;
299 if (!filters)
300 return E_POINTER;
302 for (i = 0; i < count; ++i)
304 struct filter *filter = LIST_ENTRY(enum_filters->cursor, struct filter, entry);
306 if (!enum_filters->cursor)
307 break;
309 IBaseFilter_AddRef(filters[i] = filter->filter);
310 enum_filters->cursor = list_next(&enum_filters->graph->filters, enum_filters->cursor);
313 if (fetched)
314 *fetched = i;
316 return (i == count) ? S_OK : S_FALSE;
319 static HRESULT WINAPI EnumFilters_Skip(IEnumFilters *iface, ULONG count)
321 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
323 TRACE("enum_filters %p, count %u.\n", enum_filters, count);
325 if (enum_filters->version != enum_filters->graph->version)
326 return VFW_E_ENUM_OUT_OF_SYNC;
328 if (!enum_filters->cursor)
329 return E_INVALIDARG;
331 while (count--)
333 if (!(enum_filters->cursor = list_next(&enum_filters->graph->filters, enum_filters->cursor)))
334 return count ? S_FALSE : S_OK;
337 return S_OK;
340 static HRESULT WINAPI EnumFilters_Reset(IEnumFilters *iface)
342 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
344 TRACE("enum_filters %p.\n", enum_filters);
346 enum_filters->cursor = list_head(&enum_filters->graph->filters);
347 enum_filters->version = enum_filters->graph->version;
348 return S_OK;
351 static HRESULT WINAPI EnumFilters_Clone(IEnumFilters *iface, IEnumFilters **out)
353 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
355 TRACE("enum_filters %p, out %p.\n", enum_filters, out);
357 return create_enum_filters(enum_filters->graph, enum_filters->cursor, out);
360 static const IEnumFiltersVtbl EnumFilters_vtbl =
362 EnumFilters_QueryInterface,
363 EnumFilters_AddRef,
364 EnumFilters_Release,
365 EnumFilters_Next,
366 EnumFilters_Skip,
367 EnumFilters_Reset,
368 EnumFilters_Clone,
371 static HRESULT create_enum_filters(struct filter_graph *graph, struct list *cursor, IEnumFilters **out)
373 struct enum_filters *enum_filters;
375 if (!(enum_filters = heap_alloc(sizeof(*enum_filters))))
376 return E_OUTOFMEMORY;
378 enum_filters->IEnumFilters_iface.lpVtbl = &EnumFilters_vtbl;
379 enum_filters->ref = 1;
380 enum_filters->cursor = cursor;
381 enum_filters->graph = graph;
382 IUnknown_AddRef(graph->outer_unk);
383 enum_filters->version = graph->version;
385 *out = &enum_filters->IEnumFilters_iface;
386 return S_OK;
389 static struct filter_graph *impl_from_IUnknown(IUnknown *iface)
391 return CONTAINING_RECORD(iface, struct filter_graph, IUnknown_inner);
394 static HRESULT WINAPI FilterGraphInner_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObj)
396 struct filter_graph *This = impl_from_IUnknown(iface);
397 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObj);
399 if (IsEqualGUID(&IID_IUnknown, riid)) {
400 *ppvObj = &This->IUnknown_inner;
401 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
402 } else if (IsEqualGUID(&IID_IFilterGraph, riid) ||
403 IsEqualGUID(&IID_IFilterGraph2, riid) ||
404 IsEqualGUID(&IID_IGraphBuilder, riid)) {
405 *ppvObj = &This->IFilterGraph2_iface;
406 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj);
407 } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
408 *ppvObj = &This->IMediaControl_iface;
409 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj);
410 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
411 *ppvObj = &This->IMediaSeeking_iface;
412 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
413 } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
414 *ppvObj = &This->IBasicAudio_iface;
415 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj);
416 } else if (IsEqualGUID(&IID_IBasicVideo, riid) ||
417 IsEqualGUID(&IID_IBasicVideo2, riid)) {
418 *ppvObj = &This->IBasicVideo2_iface;
419 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj);
420 } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
421 *ppvObj = &This->IVideoWindow_iface;
422 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj);
423 } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
424 IsEqualGUID(&IID_IMediaEventEx, riid)) {
425 *ppvObj = &This->IMediaEventEx_iface;
426 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
427 } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
428 IsEqualGUID(&IID_IPersist, riid)) {
429 *ppvObj = &This->IMediaFilter_iface;
430 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj);
431 } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
432 *ppvObj = &This->IMediaEventSink_iface;
433 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj);
434 } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
435 *ppvObj = &This->IGraphConfig_iface;
436 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
437 } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
438 *ppvObj = &This->IMediaPosition_iface;
439 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj);
440 } else if (IsEqualGUID(&IID_IObjectWithSite, riid)) {
441 *ppvObj = &This->IObjectWithSite_iface;
442 TRACE(" returning IObjectWithSite interface (%p)\n", *ppvObj);
443 } else if (IsEqualGUID(&IID_IFilterMapper, riid)) {
444 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj);
445 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
446 } else if (IsEqualGUID(&IID_IFilterMapper2, riid)) {
447 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
448 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
449 } else if (IsEqualGUID(&IID_IFilterMapper3, riid)) {
450 TRACE(" returning IFilterMapper3 interface from aggregated filtermapper (%p)\n", *ppvObj);
451 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
452 } else if (IsEqualGUID(&IID_IGraphVersion, riid)) {
453 *ppvObj = &This->IGraphVersion_iface;
454 TRACE(" returning IGraphVersion interface (%p)\n", *ppvObj);
455 } else if (IsEqualGUID(&IID_IVideoFrameStep, riid)) {
456 *ppvObj = &This->IVideoFrameStep_iface;
457 TRACE(" returning IVideoFrameStep interface (%p)\n", *ppvObj);
458 } else {
459 *ppvObj = NULL;
460 FIXME("unknown interface %s\n", debugstr_guid(riid));
461 return E_NOINTERFACE;
464 IUnknown_AddRef((IUnknown *)*ppvObj);
465 return S_OK;
468 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown *iface)
470 struct filter_graph *This = impl_from_IUnknown(iface);
471 ULONG ref = InterlockedIncrement(&This->ref);
473 TRACE("(%p)->(): new ref = %d\n", This, ref);
475 return ref;
478 static ULONG WINAPI FilterGraphInner_Release(IUnknown *iface)
480 struct filter_graph *This = impl_from_IUnknown(iface);
481 ULONG ref = InterlockedDecrement(&This->ref);
482 struct filter *filter, *next;
484 TRACE("(%p)->(): new ref = %d\n", This, ref);
486 if (ref == 0) {
487 int i;
489 This->ref = 1; /* guard against reentrancy (aggregation). */
491 IMediaControl_Stop(&This->IMediaControl_iface);
493 LIST_FOR_EACH_ENTRY_SAFE(filter, next, &This->filters, struct filter, entry)
495 IFilterGraph2_RemoveFilter(&This->IFilterGraph2_iface, filter->filter);
498 if (This->refClock)
499 IReferenceClock_Release(This->refClock);
501 for (i = 0; i < This->nItfCacheEntries; i++)
503 if (This->ItfCacheEntries[i].iface)
504 IUnknown_Release(This->ItfCacheEntries[i].iface);
507 IUnknown_Release(This->punkFilterMapper2);
509 if (This->pSite) IUnknown_Release(This->pSite);
511 CloseHandle(This->hEventCompletion);
512 EventsQueue_Destroy(&This->evqueue);
513 This->cs.DebugInfo->Spare[0] = 0;
514 if (This->message_thread)
516 PostThreadMessageW(This->message_thread_id, WM_USER + 1, 0, 0);
517 WaitForSingleObject(This->message_thread, INFINITE);
518 CloseHandle(This->message_thread);
519 CloseHandle(This->message_thread_ret);
521 DeleteCriticalSection(&This->cs);
522 free(This);
524 InterlockedDecrement(&object_locks);
526 return ref;
529 static struct filter_graph *impl_from_IFilterGraph2(IFilterGraph2 *iface)
531 return CONTAINING_RECORD(iface, struct filter_graph, IFilterGraph2_iface);
534 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface, REFIID iid, void **out)
536 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
537 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
540 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface)
542 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
543 return IUnknown_AddRef(graph->outer_unk);
546 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface)
548 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
549 return IUnknown_Release(graph->outer_unk);
552 static IBaseFilter *find_filter_by_name(struct filter_graph *graph, const WCHAR *name)
554 struct filter *filter;
556 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
558 if (!wcscmp(filter->name, name))
559 return filter->filter;
562 return NULL;
565 static BOOL has_output_pins(IBaseFilter *filter)
567 IEnumPins *enumpins;
568 PIN_DIRECTION dir;
569 IPin *pin;
571 if (FAILED(IBaseFilter_EnumPins(filter, &enumpins)))
572 return FALSE;
574 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
576 IPin_QueryDirection(pin, &dir);
577 IPin_Release(pin);
578 if (dir == PINDIR_OUTPUT)
580 IEnumPins_Release(enumpins);
581 return TRUE;
585 IEnumPins_Release(enumpins);
586 return FALSE;
589 static void update_seeking(struct filter *filter)
591 IMediaSeeking *seeking;
593 if (!filter->seeking)
595 /* The Legend of Heroes: Trails of Cold Steel II destroys its filter when
596 * its IMediaSeeking interface is released, so cache the interface instead
597 * of querying for it every time.
598 * Some filters (e.g. MediaStreamFilter) can become seekable when they are
599 * already in the graph, so always try to query IMediaSeeking if it's not
600 * cached yet. */
601 if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IMediaSeeking, (void **)&seeking)))
603 if (IMediaSeeking_IsFormatSupported(seeking, &TIME_FORMAT_MEDIA_TIME) == S_OK)
604 filter->seeking = seeking;
605 else
606 IMediaSeeking_Release(seeking);
611 static BOOL is_renderer(struct filter *filter)
613 IAMFilterMiscFlags *flags;
614 BOOL ret = FALSE;
616 if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IAMFilterMiscFlags, (void **)&flags)))
618 if (IAMFilterMiscFlags_GetMiscFlags(flags) & AM_FILTER_MISC_FLAGS_IS_RENDERER)
619 ret = TRUE;
620 IAMFilterMiscFlags_Release(flags);
622 else
624 update_seeking(filter);
625 if (filter->seeking && !has_output_pins(filter->filter))
626 ret = TRUE;
628 return ret;
631 /*** IFilterGraph methods ***/
632 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface,
633 IBaseFilter *filter, const WCHAR *name)
635 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
636 BOOL duplicate_name = FALSE;
637 struct filter *entry;
638 unsigned int i;
639 HRESULT hr;
641 TRACE("graph %p, filter %p, name %s.\n", graph, filter, debugstr_w(name));
643 if (!filter)
644 return E_POINTER;
646 if (!(entry = heap_alloc(sizeof(*entry))))
647 return E_OUTOFMEMORY;
649 if (!(entry->name = CoTaskMemAlloc((name ? wcslen(name) + 6 : 5) * sizeof(WCHAR))))
651 heap_free(entry);
652 return E_OUTOFMEMORY;
655 if (name && find_filter_by_name(graph, name))
656 duplicate_name = TRUE;
658 if (!name || duplicate_name)
660 for (i = 0; i < 10000 ; ++i)
662 if (name)
663 swprintf(entry->name, name ? wcslen(name) + 6 : 5, L"%s %04u", name, graph->name_index);
664 else
665 swprintf(entry->name, name ? wcslen(name) + 6 : 5, L"%04u", graph->name_index);
667 graph->name_index = (graph->name_index + 1) % 10000;
669 if (!find_filter_by_name(graph, entry->name))
670 break;
673 if (i == 10000)
675 CoTaskMemFree(entry->name);
676 heap_free(entry);
677 return VFW_E_DUPLICATE_NAME;
680 else
681 wcscpy(entry->name, name);
683 if (FAILED(hr = IBaseFilter_JoinFilterGraph(filter,
684 (IFilterGraph *)&graph->IFilterGraph2_iface, entry->name)))
686 CoTaskMemFree(entry->name);
687 heap_free(entry);
688 return hr;
691 IBaseFilter_AddRef(entry->filter = filter);
693 list_add_head(&graph->filters, &entry->entry);
694 entry->sorting = FALSE;
695 entry->seeking = NULL;
696 ++graph->version;
698 return duplicate_name ? VFW_S_DUPLICATE_NAME : hr;
701 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
703 struct filter_graph *This = impl_from_IFilterGraph2(iface);
704 struct filter *entry;
705 int i;
706 HRESULT hr = E_FAIL;
708 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
710 LIST_FOR_EACH_ENTRY(entry, &This->filters, struct filter, entry)
712 if (entry->filter == pFilter)
714 IEnumPins *penumpins = NULL;
716 if (This->defaultclock && This->refClockProvider == pFilter)
718 IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, NULL);
719 This->defaultclock = TRUE;
722 TRACE("Removing filter %s.\n", debugstr_w(entry->name));
724 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
725 if (SUCCEEDED(hr)) {
726 IPin *ppin;
727 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
729 IPin *peer = NULL;
730 HRESULT hr;
732 IPin_ConnectedTo(ppin, &peer);
733 if (peer)
735 if (FAILED(hr = IPin_Disconnect(peer)))
737 WARN("Failed to disconnect peer %p, hr %#x.\n", peer, hr);
738 IPin_Release(peer);
739 IPin_Release(ppin);
740 IEnumPins_Release(penumpins);
741 return hr;
743 IPin_Release(peer);
745 if (FAILED(hr = IPin_Disconnect(ppin)))
747 WARN("Failed to disconnect pin %p, hr %#x.\n", ppin, hr);
748 IPin_Release(ppin);
749 IEnumPins_Release(penumpins);
750 return hr;
753 IPin_Release(ppin);
755 IEnumPins_Release(penumpins);
758 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, NULL);
759 if (SUCCEEDED(hr))
761 IBaseFilter_SetSyncSource(pFilter, NULL);
762 IBaseFilter_Release(pFilter);
763 if (entry->seeking)
764 IMediaSeeking_Release(entry->seeking);
765 list_remove(&entry->entry);
766 CoTaskMemFree(entry->name);
767 heap_free(entry);
768 This->version++;
769 /* Invalidate interfaces in the cache */
770 for (i = 0; i < This->nItfCacheEntries; i++)
771 if (pFilter == This->ItfCacheEntries[i].filter)
773 IUnknown_Release(This->ItfCacheEntries[i].iface);
774 This->ItfCacheEntries[i].iface = NULL;
775 This->ItfCacheEntries[i].filter = NULL;
777 return S_OK;
779 break;
783 return hr; /* FIXME: check this error code */
786 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface, IEnumFilters **out)
788 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
790 TRACE("graph %p, out %p.\n", graph, out);
792 return create_enum_filters(graph, list_head(&graph->filters), out);
795 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface,
796 const WCHAR *name, IBaseFilter **filter)
798 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
800 TRACE("graph %p, name %s, filter %p.\n", graph, debugstr_w(name), filter);
802 if (!filter)
803 return E_POINTER;
805 if ((*filter = find_filter_by_name(graph, name)))
807 IBaseFilter_AddRef(*filter);
808 return S_OK;
811 return VFW_E_NOT_FOUND;
814 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
815 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
817 static HRESULT CheckCircularConnection(struct filter_graph *This, IPin *out, IPin *in)
819 #if 1
820 HRESULT hr;
821 PIN_INFO info_out, info_in;
823 hr = IPin_QueryPinInfo(out, &info_out);
824 if (FAILED(hr))
825 return hr;
826 if (info_out.dir != PINDIR_OUTPUT)
828 IBaseFilter_Release(info_out.pFilter);
829 return VFW_E_CANNOT_CONNECT;
832 hr = IPin_QueryPinInfo(in, &info_in);
833 if (SUCCEEDED(hr))
834 IBaseFilter_Release(info_in.pFilter);
835 if (FAILED(hr))
836 goto out;
837 if (info_in.dir != PINDIR_INPUT)
839 hr = VFW_E_CANNOT_CONNECT;
840 goto out;
843 if (info_out.pFilter == info_in.pFilter)
844 hr = VFW_E_CIRCULAR_GRAPH;
845 else
847 IEnumPins *enumpins;
848 IPin *test;
850 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
851 if (FAILED(hr))
852 goto out;
854 IEnumPins_Reset(enumpins);
855 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
857 PIN_DIRECTION dir = PINDIR_OUTPUT;
858 IPin_QueryDirection(test, &dir);
859 if (dir == PINDIR_INPUT)
861 IPin *victim = NULL;
862 IPin_ConnectedTo(test, &victim);
863 if (victim)
865 hr = CheckCircularConnection(This, victim, in);
866 IPin_Release(victim);
867 if (FAILED(hr))
869 IPin_Release(test);
870 break;
874 IPin_Release(test);
876 IEnumPins_Release(enumpins);
879 out:
880 IBaseFilter_Release(info_out.pFilter);
881 if (FAILED(hr))
882 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
883 return hr;
884 #else
885 /* Debugging filtergraphs not enabled */
886 return S_OK;
887 #endif
890 static struct filter *find_sorted_filter(struct filter_graph *graph, IBaseFilter *iface)
892 struct filter *filter;
894 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
896 if (filter->filter == iface)
897 return filter;
900 return NULL;
903 static void sort_filter_recurse(struct filter_graph *graph, struct filter *filter, struct list *sorted)
905 struct filter *peer_filter;
906 IEnumPins *enumpins;
907 PIN_DIRECTION dir;
908 IPin *pin, *peer;
909 PIN_INFO info;
911 TRACE("Sorting filter %p.\n", filter->filter);
913 /* Cyclic connections should be caught by CheckCircularConnection(). */
914 assert(!filter->sorting);
916 filter->sorting = TRUE;
918 IBaseFilter_EnumPins(filter->filter, &enumpins);
919 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
921 IPin_QueryDirection(pin, &dir);
923 if (dir == PINDIR_INPUT && IPin_ConnectedTo(pin, &peer) == S_OK)
925 IPin_QueryPinInfo(peer, &info);
926 /* Note that the filter may have already been sorted. */
927 if ((peer_filter = find_sorted_filter(graph, info.pFilter)))
928 sort_filter_recurse(graph, peer_filter, sorted);
929 IBaseFilter_Release(info.pFilter);
930 IPin_Release(peer);
932 IPin_Release(pin);
934 IEnumPins_Release(enumpins);
936 filter->sorting = FALSE;
938 list_remove(&filter->entry);
939 list_add_head(sorted, &filter->entry);
942 static void sort_filters(struct filter_graph *graph)
944 struct list sorted = LIST_INIT(sorted), *cursor;
946 while ((cursor = list_head(&graph->filters)))
948 struct filter *filter = LIST_ENTRY(cursor, struct filter, entry);
949 sort_filter_recurse(graph, filter, &sorted);
952 list_move_tail(&graph->filters, &sorted);
955 /* NOTE: despite the implication, it doesn't matter which
956 * way round you put in the input and output pins */
957 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppinIn, IPin *ppinOut,
958 const AM_MEDIA_TYPE *pmt)
960 struct filter_graph *This = impl_from_IFilterGraph2(iface);
961 PIN_DIRECTION dir;
962 HRESULT hr;
964 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
965 strmbase_dump_media_type(pmt);
967 /* FIXME: check pins are in graph */
969 if (TRACE_ON(quartz))
971 PIN_INFO PinInfo;
973 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
974 if (FAILED(hr))
975 return hr;
977 TRACE("Filter owning ppinIn(%p) => %p\n", ppinIn, PinInfo.pFilter);
978 IBaseFilter_Release(PinInfo.pFilter);
980 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
981 if (FAILED(hr))
982 return hr;
984 TRACE("Filter owning ppinOut(%p) => %p\n", ppinOut, PinInfo.pFilter);
985 IBaseFilter_Release(PinInfo.pFilter);
988 hr = IPin_QueryDirection(ppinIn, &dir);
989 if (SUCCEEDED(hr))
991 if (dir == PINDIR_INPUT)
993 hr = CheckCircularConnection(This, ppinOut, ppinIn);
994 if (SUCCEEDED(hr))
995 hr = IPin_Connect(ppinOut, ppinIn, pmt);
997 else
999 hr = CheckCircularConnection(This, ppinIn, ppinOut);
1000 if (SUCCEEDED(hr))
1001 hr = IPin_Connect(ppinIn, ppinOut, pmt);
1005 return hr;
1008 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface, IPin *pin)
1010 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1012 TRACE("graph %p, pin %p.\n", graph, pin);
1014 return IFilterGraph2_ReconnectEx(iface, pin, NULL);
1017 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
1019 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1021 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
1023 if (!ppin)
1024 return E_POINTER;
1026 return IPin_Disconnect(ppin);
1029 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
1031 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1032 IReferenceClock *pClock = NULL;
1033 struct filter *filter;
1034 HRESULT hr = S_OK;
1036 TRACE("(%p/%p)->() live sources not handled properly!\n", This, iface);
1038 EnterCriticalSection(&This->cs);
1040 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
1042 if (IBaseFilter_QueryInterface(filter->filter, &IID_IReferenceClock, (void **)&pClock) == S_OK)
1043 break;
1046 if (!pClock)
1048 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
1049 This->refClockProvider = NULL;
1051 else
1053 filter = LIST_ENTRY(list_tail(&This->filters), struct filter, entry);
1054 This->refClockProvider = filter->filter;
1057 if (SUCCEEDED(hr))
1059 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
1060 This->defaultclock = TRUE;
1061 IReferenceClock_Release(pClock);
1063 LeaveCriticalSection(&This->cs);
1065 return hr;
1068 struct filter_create_params
1070 HRESULT hr;
1071 IMoniker *moniker;
1072 IBaseFilter *filter;
1075 static DWORD WINAPI message_thread_run(void *ctx)
1077 struct filter_graph *graph = ctx;
1078 MSG msg;
1080 /* Make sure we have a message queue. */
1081 PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE);
1082 SetEvent(graph->message_thread_ret);
1084 CoInitializeEx(NULL, COINIT_MULTITHREADED);
1086 for (;;)
1088 GetMessageW(&msg, NULL, 0, 0);
1090 if (!msg.hwnd && msg.message == WM_USER)
1092 struct filter_create_params *params = (struct filter_create_params *)msg.wParam;
1094 params->hr = IMoniker_BindToObject(params->moniker, NULL, NULL,
1095 &IID_IBaseFilter, (void **)&params->filter);
1096 SetEvent(graph->message_thread_ret);
1098 else if (!msg.hwnd && msg.message == WM_USER + 1)
1100 break;
1102 else
1104 TranslateMessage(&msg);
1105 DispatchMessageW(&msg);
1109 CoUninitialize();
1110 return 0;
1113 static HRESULT create_filter(struct filter_graph *graph, IMoniker *moniker, IBaseFilter **filter)
1115 if (graph->message_thread)
1117 struct filter_create_params params;
1119 params.moniker = moniker;
1120 PostThreadMessageW(graph->message_thread_id, WM_USER, (WPARAM)&params, 0);
1121 WaitForSingleObject(graph->message_thread_ret, INFINITE);
1122 *filter = params.filter;
1123 return params.hr;
1125 else
1126 return IMoniker_BindToObject(moniker, NULL, NULL, &IID_IBaseFilter, (void **)filter);
1129 static HRESULT autoplug(struct filter_graph *graph, IPin *source, IPin *sink,
1130 BOOL render_to_existing, unsigned int recursion_depth);
1132 static HRESULT autoplug_through_sink(struct filter_graph *graph, IPin *source,
1133 IBaseFilter *filter, IPin *middle_sink, IPin *sink,
1134 BOOL render_to_existing, unsigned int recursion_depth)
1136 BOOL any = FALSE, all = TRUE;
1137 IPin *middle_source, *peer;
1138 IEnumPins *source_enum;
1139 PIN_DIRECTION dir;
1140 PIN_INFO info;
1141 HRESULT hr;
1143 TRACE("Trying to autoplug %p to %p through %p.\n", source, sink, middle_sink);
1145 IPin_QueryDirection(middle_sink, &dir);
1146 if (dir != PINDIR_INPUT)
1147 return E_FAIL;
1149 if (IPin_ConnectedTo(middle_sink, &peer) == S_OK)
1151 IPin_Release(peer);
1152 return E_FAIL;
1155 if (FAILED(hr = IFilterGraph2_ConnectDirect(&graph->IFilterGraph2_iface, source, middle_sink, NULL)))
1156 return E_FAIL;
1158 if (FAILED(hr = IBaseFilter_EnumPins(filter, &source_enum)))
1159 goto err;
1161 while (IEnumPins_Next(source_enum, 1, &middle_source, NULL) == S_OK)
1163 IPin_QueryPinInfo(middle_source, &info);
1164 IBaseFilter_Release(info.pFilter);
1165 if (info.dir != PINDIR_OUTPUT)
1167 IPin_Release(middle_source);
1168 continue;
1170 if (info.achName[0] == '~')
1172 TRACE("Skipping non-rendered pin %s.\n", debugstr_w(info.achName));
1173 IPin_Release(middle_source);
1174 continue;
1176 if (IPin_ConnectedTo(middle_source, &peer) == S_OK)
1178 IPin_Release(peer);
1179 IPin_Release(middle_source);
1180 continue;
1183 hr = autoplug(graph, middle_source, sink, render_to_existing, recursion_depth + 1);
1184 IPin_Release(middle_source);
1185 if (SUCCEEDED(hr) && sink)
1187 IEnumPins_Release(source_enum);
1188 return hr;
1190 if (SUCCEEDED(hr))
1191 any = TRUE;
1192 if (hr != S_OK)
1193 all = FALSE;
1195 IEnumPins_Release(source_enum);
1197 if (!sink)
1199 if (all)
1200 return S_OK;
1201 if (any)
1202 return VFW_S_PARTIAL_RENDER;
1205 err:
1206 IFilterGraph2_Disconnect(&graph->IFilterGraph2_iface, source);
1207 IFilterGraph2_Disconnect(&graph->IFilterGraph2_iface, middle_sink);
1208 return E_FAIL;
1211 static HRESULT autoplug_through_filter(struct filter_graph *graph, IPin *source,
1212 IBaseFilter *filter, IPin *sink, BOOL render_to_existing,
1213 unsigned int recursion_depth)
1215 IEnumPins *sink_enum;
1216 IPin *filter_sink;
1217 HRESULT hr;
1219 TRACE("Trying to autoplug %p to %p through %p.\n", source, sink, filter);
1221 if (FAILED(hr = IBaseFilter_EnumPins(filter, &sink_enum)))
1222 return hr;
1224 while (IEnumPins_Next(sink_enum, 1, &filter_sink, NULL) == S_OK)
1226 hr = autoplug_through_sink(graph, source, filter, filter_sink, sink,
1227 render_to_existing, recursion_depth);
1228 IPin_Release(filter_sink);
1229 if (SUCCEEDED(hr))
1231 IEnumPins_Release(sink_enum);
1232 return hr;
1235 IEnumPins_Release(sink_enum);
1236 return VFW_E_CANNOT_CONNECT;
1239 /* Common helper for IGraphBuilder::Connect() and IGraphBuilder::Render(), which
1240 * share most of the same code. Render() calls this with a NULL sink. */
1241 static HRESULT autoplug(struct filter_graph *graph, IPin *source, IPin *sink,
1242 BOOL render_to_existing, unsigned int recursion_depth)
1244 IAMGraphBuilderCallback *callback = NULL;
1245 IEnumMediaTypes *enummt;
1246 IFilterMapper2 *mapper;
1247 struct filter *filter;
1248 AM_MEDIA_TYPE *mt;
1249 HRESULT hr;
1251 TRACE("Trying to autoplug %p to %p, recursion depth %u.\n", source, sink, recursion_depth);
1253 if (recursion_depth >= 5)
1255 WARN("Recursion depth has reached 5; aborting.\n");
1256 return VFW_E_CANNOT_CONNECT;
1259 if (sink)
1261 /* Try to connect directly to this sink. */
1262 hr = IFilterGraph2_ConnectDirect(&graph->IFilterGraph2_iface, source, sink, NULL);
1264 /* If direct connection succeeded, we should propagate that return value.
1265 * If it returned VFW_E_NOT_CONNECTED or VFW_E_NO_AUDIO_HARDWARE, then don't
1266 * even bother trying intermediate filters, since they won't succeed. */
1267 if (SUCCEEDED(hr) || hr == VFW_E_NOT_CONNECTED || hr == VFW_E_NO_AUDIO_HARDWARE)
1268 return hr;
1271 /* Always prefer filters in the graph. */
1272 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1274 if (SUCCEEDED(hr = autoplug_through_filter(graph, source, filter->filter,
1275 sink, render_to_existing, recursion_depth)))
1276 return hr;
1279 IUnknown_QueryInterface(graph->punkFilterMapper2, &IID_IFilterMapper2, (void **)&mapper);
1281 if (FAILED(hr = IPin_EnumMediaTypes(source, &enummt)))
1283 IFilterMapper2_Release(mapper);
1284 return hr;
1287 if (graph->pSite)
1288 IUnknown_QueryInterface(graph->pSite, &IID_IAMGraphBuilderCallback, (void **)&callback);
1290 while (IEnumMediaTypes_Next(enummt, 1, &mt, NULL) == S_OK)
1292 GUID types[2] = {mt->majortype, mt->subtype};
1293 IEnumMoniker *enummoniker;
1294 IBaseFilter *filter;
1295 IMoniker *moniker;
1297 DeleteMediaType(mt);
1299 if (FAILED(hr = IFilterMapper2_EnumMatchingFilters(mapper, &enummoniker,
1300 0, FALSE, MERIT_UNLIKELY, TRUE, 1, types, NULL, NULL, FALSE,
1301 render_to_existing, 0, NULL, NULL, NULL)))
1302 goto out;
1304 while (IEnumMoniker_Next(enummoniker, 1, &moniker, NULL) == S_OK)
1306 IPropertyBag *bag;
1307 VARIANT var;
1309 VariantInit(&var);
1310 IMoniker_BindToStorage(moniker, NULL, NULL, &IID_IPropertyBag, (void **)&bag);
1311 hr = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL);
1312 IPropertyBag_Release(bag);
1313 if (FAILED(hr))
1315 IMoniker_Release(moniker);
1316 continue;
1319 if (callback && FAILED(hr = IAMGraphBuilderCallback_SelectedFilter(callback, moniker)))
1321 TRACE("Filter rejected by IAMGraphBuilderCallback::SelectedFilter(), hr %#x.\n", hr);
1322 IMoniker_Release(moniker);
1323 continue;
1326 hr = create_filter(graph, moniker, &filter);
1327 IMoniker_Release(moniker);
1328 if (FAILED(hr))
1330 ERR("Failed to create filter for %s, hr %#x.\n", debugstr_w(V_BSTR(&var)), hr);
1331 VariantClear(&var);
1332 continue;
1335 if (callback && FAILED(hr = IAMGraphBuilderCallback_CreatedFilter(callback, filter)))
1337 TRACE("Filter rejected by IAMGraphBuilderCallback::CreatedFilter(), hr %#x.\n", hr);
1338 IBaseFilter_Release(filter);
1339 continue;
1342 hr = IFilterGraph2_AddFilter(&graph->IFilterGraph2_iface, filter, V_BSTR(&var));
1343 VariantClear(&var);
1344 if (FAILED(hr))
1346 ERR("Failed to add filter, hr %#x.\n", hr);
1347 IBaseFilter_Release(filter);
1348 continue;
1351 hr = autoplug_through_filter(graph, source, filter, sink, render_to_existing, recursion_depth);
1352 if (SUCCEEDED(hr))
1354 IBaseFilter_Release(filter);
1355 goto out;
1358 IFilterGraph2_RemoveFilter(&graph->IFilterGraph2_iface, filter);
1359 IBaseFilter_Release(filter);
1361 IEnumMoniker_Release(enummoniker);
1364 hr = VFW_E_CANNOT_CONNECT;
1366 out:
1367 if (callback) IAMGraphBuilderCallback_Release(callback);
1368 IEnumMediaTypes_Release(enummt);
1369 IFilterMapper2_Release(mapper);
1370 return hr;
1373 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *source, IPin *sink)
1375 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1376 PIN_DIRECTION dir;
1377 HRESULT hr;
1379 TRACE("graph %p, source %p, sink %p.\n", graph, source, sink);
1381 if (!source || !sink)
1382 return E_POINTER;
1384 if (FAILED(hr = IPin_QueryDirection(source, &dir)))
1385 return hr;
1387 if (dir == PINDIR_INPUT)
1389 IPin *temp;
1391 TRACE("Directions seem backwards, swapping pins\n");
1393 temp = sink;
1394 sink = source;
1395 source = temp;
1398 EnterCriticalSection(&graph->cs);
1400 hr = autoplug(graph, source, sink, TRUE, 0);
1402 LeaveCriticalSection(&graph->cs);
1404 TRACE("Returning %#x.\n", hr);
1405 return hr;
1408 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *source)
1410 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1411 HRESULT hr;
1413 TRACE("graph %p, source %p.\n", graph, source);
1415 EnterCriticalSection(&graph->cs);
1416 hr = autoplug(graph, source, NULL, FALSE, 0);
1417 LeaveCriticalSection(&graph->cs);
1418 if (hr == VFW_E_CANNOT_CONNECT)
1419 hr = VFW_E_CANNOT_RENDER;
1421 TRACE("Returning %#x.\n", hr);
1422 return hr;
1425 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface, LPCWSTR lpcwstrFile,
1426 LPCWSTR lpcwstrPlayList)
1428 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1429 IBaseFilter* preader = NULL;
1430 IPin* ppinreader = NULL;
1431 IEnumPins* penumpins = NULL;
1432 struct filter *filter;
1433 HRESULT hr;
1434 BOOL partial = FALSE;
1435 BOOL any = FALSE;
1437 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1439 if (lpcwstrPlayList != NULL)
1440 return E_INVALIDARG;
1442 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, L"Reader", &preader);
1443 if (FAILED(hr))
1444 return hr;
1446 hr = IBaseFilter_EnumPins(preader, &penumpins);
1447 if (SUCCEEDED(hr))
1449 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1451 PIN_DIRECTION dir;
1453 IPin_QueryDirection(ppinreader, &dir);
1454 if (dir == PINDIR_OUTPUT)
1456 hr = IFilterGraph2_Render(iface, ppinreader);
1458 TRACE("Filters in chain:\n");
1459 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
1460 TRACE("- %s.\n", debugstr_w(filter->name));
1462 if (SUCCEEDED(hr))
1463 any = TRUE;
1464 if (hr != S_OK)
1465 partial = TRUE;
1467 IPin_Release(ppinreader);
1469 IEnumPins_Release(penumpins);
1471 if (!any)
1472 hr = VFW_E_CANNOT_RENDER;
1473 else if (partial)
1474 hr = VFW_S_PARTIAL_RENDER;
1475 else
1476 hr = S_OK;
1478 IBaseFilter_Release(preader);
1480 TRACE("--> %08x\n", hr);
1481 return hr;
1484 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface,
1485 const WCHAR *filename, const WCHAR *filter_name, IBaseFilter **ret_filter)
1487 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1488 IFileSourceFilter *filesource;
1489 IBaseFilter *filter;
1490 HRESULT hr;
1491 GUID clsid;
1493 TRACE("graph %p, filename %s, filter_name %s, ret_filter %p.\n",
1494 graph, debugstr_w(filename), debugstr_w(filter_name), ret_filter);
1496 if (!get_media_type(filename, NULL, NULL, &clsid))
1497 clsid = CLSID_AsyncReader;
1498 TRACE("Using source filter %s.\n", debugstr_guid(&clsid));
1500 if (FAILED(hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER,
1501 &IID_IBaseFilter, (void **)&filter)))
1503 WARN("Failed to create filter, hr %#x.\n", hr);
1504 return hr;
1507 if (FAILED(hr = IBaseFilter_QueryInterface(filter, &IID_IFileSourceFilter, (void **)&filesource)))
1509 WARN("Failed to get IFileSourceFilter, hr %#x.\n", hr);
1510 IBaseFilter_Release(filter);
1511 return hr;
1514 hr = IFileSourceFilter_Load(filesource, filename, NULL);
1515 IFileSourceFilter_Release(filesource);
1516 if (FAILED(hr))
1518 WARN("Failed to load file, hr %#x.\n", hr);
1519 return hr;
1522 if (FAILED(hr = IFilterGraph2_AddFilter(iface, filter, filter_name)))
1524 IBaseFilter_Release(filter);
1525 return hr;
1528 if (ret_filter)
1529 *ret_filter = filter;
1530 return S_OK;
1533 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR hFile)
1535 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1537 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1539 return S_OK;
1542 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1544 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1546 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1548 return S_OK;
1551 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1553 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1555 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1557 return S_OK;
1560 /*** IFilterGraph2 methods ***/
1561 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1562 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1564 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1565 HRESULT hr;
1566 IBaseFilter* pfilter;
1568 TRACE("(%p/%p)->(%p %p %s %p)\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1570 hr = IMoniker_BindToObject(pMoniker, pCtx, NULL, &IID_IBaseFilter, (void**)&pfilter);
1571 if(FAILED(hr)) {
1572 WARN("Unable to bind moniker to filter object (%x)\n", hr);
1573 return hr;
1576 hr = IFilterGraph2_AddFilter(iface, pfilter, lpcwstrFilterName);
1577 if (FAILED(hr)) {
1578 WARN("Unable to add filter (%x)\n", hr);
1579 IBaseFilter_Release(pfilter);
1580 return hr;
1583 if(ppFilter)
1584 *ppFilter = pfilter;
1585 else IBaseFilter_Release(pfilter);
1587 return S_OK;
1590 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *pin, const AM_MEDIA_TYPE *mt)
1592 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1593 PIN_DIRECTION dir;
1594 HRESULT hr;
1595 IPin *peer;
1597 TRACE("graph %p, pin %p, mt %p.\n", graph, pin, mt);
1599 if (FAILED(hr = IPin_ConnectedTo(pin, &peer)))
1600 return hr;
1602 IPin_QueryDirection(pin, &dir);
1603 IFilterGraph2_Disconnect(iface, peer);
1604 IFilterGraph2_Disconnect(iface, pin);
1606 if (dir == PINDIR_INPUT)
1607 hr = IFilterGraph2_ConnectDirect(iface, peer, pin, mt);
1608 else
1609 hr = IFilterGraph2_ConnectDirect(iface, pin, peer, mt);
1611 IPin_Release(peer);
1612 return hr;
1615 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *source, DWORD flags, DWORD *context)
1617 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1618 HRESULT hr;
1620 TRACE("graph %p, source %p, flags %#x, context %p.\n", graph, source, flags, context);
1622 if (flags & ~AM_RENDEREX_RENDERTOEXISTINGRENDERERS)
1623 FIXME("Unknown flags %#x.\n", flags);
1625 EnterCriticalSection(&graph->cs);
1626 hr = autoplug(graph, source, NULL, !!(flags & AM_RENDEREX_RENDERTOEXISTINGRENDERERS), 0);
1627 LeaveCriticalSection(&graph->cs);
1628 if (hr == VFW_E_CANNOT_CONNECT)
1629 hr = VFW_E_CANNOT_RENDER;
1631 TRACE("Returning %#x.\n", hr);
1632 return hr;
1636 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1638 FilterGraph2_QueryInterface,
1639 FilterGraph2_AddRef,
1640 FilterGraph2_Release,
1641 FilterGraph2_AddFilter,
1642 FilterGraph2_RemoveFilter,
1643 FilterGraph2_EnumFilters,
1644 FilterGraph2_FindFilterByName,
1645 FilterGraph2_ConnectDirect,
1646 FilterGraph2_Reconnect,
1647 FilterGraph2_Disconnect,
1648 FilterGraph2_SetDefaultSyncSource,
1649 FilterGraph2_Connect,
1650 FilterGraph2_Render,
1651 FilterGraph2_RenderFile,
1652 FilterGraph2_AddSourceFilter,
1653 FilterGraph2_SetLogFile,
1654 FilterGraph2_Abort,
1655 FilterGraph2_ShouldOperationContinue,
1656 FilterGraph2_AddSourceFilterForMoniker,
1657 FilterGraph2_ReconnectEx,
1658 FilterGraph2_RenderEx
1661 static struct filter_graph *impl_from_IMediaControl(IMediaControl *iface)
1663 return CONTAINING_RECORD(iface, struct filter_graph, IMediaControl_iface);
1666 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID iid, void **out)
1668 struct filter_graph *graph = impl_from_IMediaControl(iface);
1669 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
1672 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1674 struct filter_graph *graph = impl_from_IMediaControl(iface);
1675 return IUnknown_AddRef(graph->outer_unk);
1678 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1680 struct filter_graph *graph = impl_from_IMediaControl(iface);
1681 return IUnknown_Release(graph->outer_unk);
1685 /*** IDispatch methods ***/
1686 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *pctinfo)
1688 struct filter_graph *This = impl_from_IMediaControl(iface);
1690 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1692 return S_OK;
1695 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT iTInfo, LCID lcid,
1696 ITypeInfo **ppTInfo)
1698 struct filter_graph *This = impl_from_IMediaControl(iface);
1700 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1702 return S_OK;
1705 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID riid,
1706 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1708 struct filter_graph *This = impl_from_IMediaControl(iface);
1710 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
1711 cNames, lcid, rgDispId);
1713 return S_OK;
1716 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID dispIdMember, REFIID riid,
1717 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
1718 UINT *puArgErr)
1720 struct filter_graph *This = impl_from_IMediaControl(iface);
1722 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
1723 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
1725 return S_OK;
1728 static void update_render_count(struct filter_graph *graph)
1730 /* Some filters (e.g. MediaStreamFilter) can become renderers when they are
1731 * already in the graph. */
1732 struct filter *filter;
1733 graph->nRenderers = 0;
1734 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1736 if (is_renderer(filter))
1737 ++graph->nRenderers;
1741 /* Perform the paused -> running transition. The caller must hold graph->cs. */
1742 static HRESULT graph_start(struct filter_graph *graph, REFERENCE_TIME stream_start)
1744 REFERENCE_TIME stream_stop;
1745 struct filter *filter;
1746 HRESULT hr = S_OK;
1748 graph->EcCompleteCount = 0;
1749 update_render_count(graph);
1751 if (graph->defaultclock && !graph->refClock)
1752 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
1754 if (!stream_start && graph->refClock)
1756 IReferenceClock_GetTime(graph->refClock, &graph->stream_start);
1757 stream_start = graph->stream_start - graph->stream_elapsed;
1758 /* Delay presentation time by 200 ms, to give filters time to
1759 * initialize. */
1760 stream_start += 200 * 10000;
1763 if (SUCCEEDED(IMediaSeeking_GetStopPosition(&graph->IMediaSeeking_iface, &stream_stop)))
1764 graph->stream_stop = stream_stop;
1766 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1768 HRESULT filter_hr = IBaseFilter_Run(filter->filter, stream_start);
1769 if (hr == S_OK)
1770 hr = filter_hr;
1771 TRACE("Filter %p returned %#x.\n", filter->filter, filter_hr);
1774 if (FAILED(hr))
1775 WARN("Failed to start stream, hr %#x.\n", hr);
1777 return hr;
1780 static void CALLBACK async_run_cb(TP_CALLBACK_INSTANCE *instance, void *context, TP_WORK *work)
1782 struct filter_graph *graph = context;
1783 struct filter *filter;
1784 FILTER_STATE state;
1785 HRESULT hr;
1787 TRACE("Performing asynchronous state change.\n");
1789 /* We can't just call GetState(), since that will return State_Running and
1790 * VFW_S_STATE_INTERMEDIATE regardless of whether we're done pausing yet.
1791 * Instead replicate it here. */
1793 for (;;)
1795 IBaseFilter *async_filter = NULL;
1797 hr = S_OK;
1799 EnterCriticalSection(&graph->cs);
1801 if (!graph->needs_async_run)
1802 break;
1804 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1806 hr = IBaseFilter_GetState(filter->filter, 0, &state);
1808 if (hr == VFW_S_STATE_INTERMEDIATE)
1809 async_filter = filter->filter;
1811 if (SUCCEEDED(hr) && state != State_Paused)
1812 ERR("Filter %p reported incorrect state %u.\n", filter->filter, state);
1814 if (hr != S_OK)
1815 break;
1818 if (hr != VFW_S_STATE_INTERMEDIATE)
1819 break;
1821 LeaveCriticalSection(&graph->cs);
1823 IBaseFilter_GetState(async_filter, 10, &state);
1826 if (hr == S_OK && graph->needs_async_run)
1828 sort_filters(graph);
1829 graph_start(graph, 0);
1830 graph->needs_async_run = 0;
1833 LeaveCriticalSection(&graph->cs);
1836 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
1838 struct filter_graph *graph = impl_from_IMediaControl(iface);
1839 BOOL need_async_run = TRUE;
1840 struct filter *filter;
1841 FILTER_STATE state;
1842 HRESULT hr = S_OK;
1844 TRACE("graph %p.\n", graph);
1846 EnterCriticalSection(&graph->cs);
1848 if (graph->state == State_Running)
1850 LeaveCriticalSection(&graph->cs);
1851 return S_OK;
1854 sort_filters(graph);
1855 update_render_count(graph);
1857 if (graph->state == State_Stopped)
1859 if (graph->defaultclock && !graph->refClock)
1860 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
1862 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1864 HRESULT filter_hr = IBaseFilter_Pause(filter->filter);
1865 if (hr == S_OK)
1866 hr = filter_hr;
1867 TRACE("Filter %p returned %#x.\n", filter->filter, filter_hr);
1869 /* If a filter returns VFW_S_CANT_CUE, we shouldn't wait for a
1870 * paused state. */
1871 filter_hr = IBaseFilter_GetState(filter->filter, 0, &state);
1872 if (filter_hr != S_OK && filter_hr != VFW_S_STATE_INTERMEDIATE)
1873 need_async_run = FALSE;
1876 if (FAILED(hr))
1878 LeaveCriticalSection(&graph->cs);
1879 WARN("Failed to pause, hr %#x.\n", hr);
1880 return hr;
1884 graph->state = State_Running;
1886 if (SUCCEEDED(hr))
1888 if (hr != S_OK && need_async_run)
1890 if (!graph->async_run_work)
1891 graph->async_run_work = CreateThreadpoolWork(async_run_cb, graph, NULL);
1892 graph->needs_async_run = 1;
1893 SubmitThreadpoolWork(graph->async_run_work);
1895 else
1897 graph_start(graph, 0);
1901 LeaveCriticalSection(&graph->cs);
1902 return hr;
1905 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
1907 struct filter_graph *graph = impl_from_IMediaControl(iface);
1909 TRACE("graph %p.\n", graph);
1911 return IMediaFilter_Pause(&graph->IMediaFilter_iface);
1914 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
1916 struct filter_graph *graph = impl_from_IMediaControl(iface);
1918 TRACE("graph %p.\n", graph);
1920 return IMediaFilter_Stop(&graph->IMediaFilter_iface);
1923 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG timeout, OAFilterState *state)
1925 struct filter_graph *graph = impl_from_IMediaControl(iface);
1927 TRACE("graph %p, timeout %u, state %p.\n", graph, timeout, state);
1929 if (timeout < 0) timeout = INFINITE;
1931 return IMediaFilter_GetState(&graph->IMediaFilter_iface, timeout, (FILTER_STATE *)state);
1934 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
1936 struct filter_graph *This = impl_from_IMediaControl(iface);
1938 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strFilename), strFilename);
1940 return IFilterGraph2_RenderFile(&This->IFilterGraph2_iface, strFilename, NULL);
1943 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
1944 IDispatch **ppUnk)
1946 struct filter_graph *This = impl_from_IMediaControl(iface);
1948 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
1950 return S_OK;
1953 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
1955 struct filter_graph *This = impl_from_IMediaControl(iface);
1957 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
1959 return S_OK;
1962 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
1964 struct filter_graph *This = impl_from_IMediaControl(iface);
1966 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
1968 return S_OK;
1971 static void CALLBACK wait_pause_cb(TP_CALLBACK_INSTANCE *instance, void *context)
1973 IMediaControl *control = context;
1974 OAFilterState state;
1975 HRESULT hr;
1977 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
1978 ERR("Failed to get paused state, hr %#x.\n", hr);
1980 if (FAILED(hr = IMediaControl_Stop(control)))
1981 ERR("Failed to stop, hr %#x.\n", hr);
1983 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
1984 ERR("Failed to get paused state, hr %#x.\n", hr);
1986 IMediaControl_Release(control);
1989 static void CALLBACK wait_stop_cb(TP_CALLBACK_INSTANCE *instance, void *context)
1991 IMediaControl *control = context;
1992 OAFilterState state;
1993 HRESULT hr;
1995 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
1996 ERR("Failed to get state, hr %#x.\n", hr);
1998 IMediaControl_Release(control);
2001 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
2003 struct filter_graph *graph = impl_from_IMediaControl(iface);
2004 HRESULT hr;
2006 TRACE("graph %p.\n", graph);
2008 /* Even if we are already stopped, we still pause. */
2009 hr = IMediaControl_Pause(iface);
2010 if (FAILED(hr))
2011 return hr;
2012 else if (hr == S_FALSE)
2014 IMediaControl_AddRef(iface);
2015 TrySubmitThreadpoolCallback(wait_pause_cb, iface, NULL);
2016 return S_FALSE;
2019 hr = IMediaControl_Stop(iface);
2020 if (FAILED(hr))
2021 return hr;
2022 else if (hr == S_FALSE)
2024 IMediaControl_AddRef(iface);
2025 TrySubmitThreadpoolCallback(wait_stop_cb, iface, NULL);
2026 return S_FALSE;
2029 return S_OK;
2033 static const IMediaControlVtbl IMediaControl_VTable =
2035 MediaControl_QueryInterface,
2036 MediaControl_AddRef,
2037 MediaControl_Release,
2038 MediaControl_GetTypeInfoCount,
2039 MediaControl_GetTypeInfo,
2040 MediaControl_GetIDsOfNames,
2041 MediaControl_Invoke,
2042 MediaControl_Run,
2043 MediaControl_Pause,
2044 MediaControl_Stop,
2045 MediaControl_GetState,
2046 MediaControl_RenderFile,
2047 MediaControl_AddSourceFilter,
2048 MediaControl_get_FilterCollection,
2049 MediaControl_get_RegFilterCollection,
2050 MediaControl_StopWhenReady
2053 static struct filter_graph *impl_from_IMediaSeeking(IMediaSeeking *iface)
2055 return CONTAINING_RECORD(iface, struct filter_graph, IMediaSeeking_iface);
2058 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID iid, void **out)
2060 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2061 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2064 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2066 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2067 return IUnknown_AddRef(graph->outer_unk);
2070 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2072 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2073 return IUnknown_Release(graph->outer_unk);
2076 typedef HRESULT (WINAPI *fnFoundSeek)(struct filter_graph *This, IMediaSeeking*, DWORD_PTR arg);
2078 static HRESULT all_renderers_seek(struct filter_graph *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2079 BOOL allnotimpl = TRUE;
2080 HRESULT hr, hr_return = S_OK;
2081 struct filter *filter;
2083 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2084 /* Send a message to all renderers, they are responsible for broadcasting it further */
2086 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
2088 update_seeking(filter);
2089 if (!filter->seeking)
2090 continue;
2091 hr = FoundSeek(This, filter->seeking, arg);
2092 if (hr_return != E_NOTIMPL)
2093 allnotimpl = FALSE;
2094 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2095 hr_return = hr;
2098 if (allnotimpl)
2099 return E_NOTIMPL;
2100 return hr_return;
2103 static HRESULT WINAPI FoundCapabilities(struct filter_graph *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2105 HRESULT hr;
2106 DWORD caps = 0;
2108 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2109 if (FAILED(hr))
2110 return hr;
2112 /* Only add common capabilities everything supports */
2113 *(DWORD*)pcaps &= caps;
2115 return hr;
2118 /*** IMediaSeeking methods ***/
2119 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2121 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2122 HRESULT hr;
2124 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2126 if (!pCapabilities)
2127 return E_POINTER;
2129 EnterCriticalSection(&This->cs);
2130 *pCapabilities = 0xffffffff;
2132 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2133 LeaveCriticalSection(&This->cs);
2135 return hr;
2138 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2140 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2141 DWORD originalcaps;
2142 HRESULT hr;
2144 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2146 if (!pCapabilities)
2147 return E_POINTER;
2149 EnterCriticalSection(&This->cs);
2150 originalcaps = *pCapabilities;
2151 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2152 LeaveCriticalSection(&This->cs);
2154 if (FAILED(hr))
2155 return hr;
2157 if (!*pCapabilities)
2158 return E_FAIL;
2159 if (*pCapabilities != originalcaps)
2160 return S_FALSE;
2161 return S_OK;
2164 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2166 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2168 if (!pFormat)
2169 return E_POINTER;
2171 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2173 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2175 WARN("Unhandled time format %s\n", debugstr_guid(pFormat));
2176 return S_FALSE;
2179 return S_OK;
2182 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2184 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2186 if (!pFormat)
2187 return E_POINTER;
2189 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2190 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2192 return S_OK;
2195 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2197 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2199 if (!pFormat)
2200 return E_POINTER;
2202 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2203 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2205 return S_OK;
2208 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2210 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2212 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2213 if (!pFormat)
2214 return E_POINTER;
2216 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2217 return S_FALSE;
2219 return S_OK;
2222 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2224 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2226 if (!pFormat)
2227 return E_POINTER;
2229 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2231 if (This->state != State_Stopped)
2232 return VFW_E_WRONG_STATE;
2234 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2236 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2237 return E_INVALIDARG;
2240 return S_OK;
2243 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *duration)
2245 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2246 HRESULT hr = E_NOTIMPL, filter_hr;
2247 LONGLONG filter_duration;
2248 struct filter *filter;
2250 TRACE("graph %p, duration %p.\n", graph, duration);
2252 if (!duration)
2253 return E_POINTER;
2255 *duration = 0;
2257 EnterCriticalSection(&graph->cs);
2259 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2261 update_seeking(filter);
2262 if (!filter->seeking)
2263 continue;
2265 filter_hr = IMediaSeeking_GetDuration(filter->seeking, &filter_duration);
2266 if (SUCCEEDED(filter_hr))
2268 hr = S_OK;
2269 *duration = max(*duration, filter_duration);
2271 else if (filter_hr != E_NOTIMPL)
2273 LeaveCriticalSection(&graph->cs);
2274 return filter_hr;
2278 LeaveCriticalSection(&graph->cs);
2280 TRACE("Returning hr %#x, duration %s (%s seconds).\n", hr,
2281 wine_dbgstr_longlong(*duration), debugstr_time(*duration));
2282 return hr;
2285 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *stop)
2287 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2288 HRESULT hr = E_NOTIMPL, filter_hr;
2289 struct filter *filter;
2290 LONGLONG filter_stop;
2292 TRACE("graph %p, stop %p.\n", graph, stop);
2294 if (!stop)
2295 return E_POINTER;
2297 *stop = 0;
2299 EnterCriticalSection(&graph->cs);
2301 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2303 update_seeking(filter);
2304 if (!filter->seeking)
2305 continue;
2307 filter_hr = IMediaSeeking_GetStopPosition(filter->seeking, &filter_stop);
2308 if (SUCCEEDED(filter_hr))
2310 hr = S_OK;
2311 *stop = max(*stop, filter_stop);
2313 else if (filter_hr != E_NOTIMPL)
2315 LeaveCriticalSection(&graph->cs);
2316 return filter_hr;
2320 LeaveCriticalSection(&graph->cs);
2322 TRACE("Returning %s (%s seconds).\n", wine_dbgstr_longlong(*stop), debugstr_time(*stop));
2323 return hr;
2326 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *current)
2328 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2329 LONGLONG ret = graph->current_pos;
2331 TRACE("graph %p, current %p.\n", graph, current);
2333 if (!current)
2334 return E_POINTER;
2336 EnterCriticalSection(&graph->cs);
2338 if (graph->got_ec_complete)
2340 ret = graph->stream_stop;
2342 else if (graph->state == State_Running && !graph->needs_async_run && graph->refClock)
2344 REFERENCE_TIME time;
2345 IReferenceClock_GetTime(graph->refClock, &time);
2346 if (time)
2347 ret += time - graph->stream_start;
2350 LeaveCriticalSection(&graph->cs);
2352 TRACE("Returning %s (%s seconds).\n", wine_dbgstr_longlong(ret), debugstr_time(ret));
2353 *current = ret;
2355 return S_OK;
2358 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2359 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2361 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2363 TRACE("(%p/%p)->(%p, %s, 0x%s, %s)\n", This, iface, pTarget,
2364 debugstr_guid(pTargetFormat), wine_dbgstr_longlong(Source), debugstr_guid(pSourceFormat));
2366 if (!pSourceFormat)
2367 pSourceFormat = &This->timeformatseek;
2369 if (!pTargetFormat)
2370 pTargetFormat = &This->timeformatseek;
2372 if (IsEqualGUID(pTargetFormat, pSourceFormat))
2373 *pTarget = Source;
2374 else
2375 FIXME("conversion %s->%s not supported\n", debugstr_guid(pSourceFormat), debugstr_guid(pTargetFormat));
2377 return S_OK;
2380 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *current_ptr,
2381 DWORD current_flags, LONGLONG *stop_ptr, DWORD stop_flags)
2383 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2384 HRESULT hr = E_NOTIMPL, filter_hr;
2385 struct filter *filter;
2386 FILTER_STATE state;
2388 TRACE("graph %p, current %s, current_flags %#x, stop %s, stop_flags %#x.\n", graph,
2389 current_ptr ? wine_dbgstr_longlong(*current_ptr) : "<null>", current_flags,
2390 stop_ptr ? wine_dbgstr_longlong(*stop_ptr): "<null>", stop_flags);
2391 if (current_ptr)
2392 TRACE("Setting current position to %s (%s seconds).\n",
2393 wine_dbgstr_longlong(*current_ptr), debugstr_time(*current_ptr));
2394 if (stop_ptr)
2395 TRACE("Setting stop position to %s (%s seconds).\n",
2396 wine_dbgstr_longlong(*stop_ptr), debugstr_time(*stop_ptr));
2398 if ((current_flags & 0x7) != AM_SEEKING_AbsolutePositioning
2399 && (current_flags & 0x7) != AM_SEEKING_NoPositioning)
2400 FIXME("Unhandled current_flags %#x.\n", current_flags & 0x7);
2402 if ((stop_flags & 0x7) != AM_SEEKING_NoPositioning
2403 && (stop_flags & 0x7) != AM_SEEKING_AbsolutePositioning)
2404 FIXME("Unhandled stop_flags %#x.\n", stop_flags & 0x7);
2406 EnterCriticalSection(&graph->cs);
2408 state = graph->state;
2409 if (state == State_Running && !graph->needs_async_run)
2410 IMediaControl_Pause(&graph->IMediaControl_iface);
2412 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2414 LONGLONG current = current_ptr ? *current_ptr : 0, stop = stop_ptr ? *stop_ptr : 0;
2416 update_seeking(filter);
2417 if (!filter->seeking)
2418 continue;
2420 filter_hr = IMediaSeeking_SetPositions(filter->seeking, &current,
2421 current_flags | AM_SEEKING_ReturnTime, &stop, stop_flags);
2422 if (SUCCEEDED(filter_hr))
2424 hr = S_OK;
2426 if (current_ptr && (current_flags & AM_SEEKING_ReturnTime))
2427 *current_ptr = current;
2428 if (stop_ptr && (stop_flags & AM_SEEKING_ReturnTime))
2429 *stop_ptr = stop;
2430 graph->current_pos = current;
2432 else if (filter_hr != E_NOTIMPL)
2434 LeaveCriticalSection(&graph->cs);
2435 return filter_hr;
2439 if ((current_flags & 0x7) != AM_SEEKING_NoPositioning && graph->refClock)
2441 IReferenceClock_GetTime(graph->refClock, &graph->stream_start);
2442 graph->stream_elapsed = 0;
2445 if (state == State_Running && !graph->needs_async_run)
2446 IMediaControl_Run(&graph->IMediaControl_iface);
2448 LeaveCriticalSection(&graph->cs);
2449 return hr;
2452 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface,
2453 LONGLONG *current, LONGLONG *stop)
2455 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2456 HRESULT hr = S_OK;
2458 TRACE("graph %p, current %p, stop %p.\n", graph, current, stop);
2460 if (current)
2461 hr = IMediaSeeking_GetCurrentPosition(iface, current);
2462 if (SUCCEEDED(hr) && stop)
2463 hr = IMediaSeeking_GetStopPosition(iface, stop);
2465 return hr;
2468 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2469 LONGLONG *pLatest)
2471 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2473 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2475 return S_OK;
2478 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2480 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2482 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2484 return S_OK;
2487 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2489 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2491 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2493 if (!pdRate)
2494 return E_POINTER;
2496 *pdRate = 1.0;
2498 return S_OK;
2501 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2503 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2505 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2507 return S_OK;
2511 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2513 MediaSeeking_QueryInterface,
2514 MediaSeeking_AddRef,
2515 MediaSeeking_Release,
2516 MediaSeeking_GetCapabilities,
2517 MediaSeeking_CheckCapabilities,
2518 MediaSeeking_IsFormatSupported,
2519 MediaSeeking_QueryPreferredFormat,
2520 MediaSeeking_GetTimeFormat,
2521 MediaSeeking_IsUsingTimeFormat,
2522 MediaSeeking_SetTimeFormat,
2523 MediaSeeking_GetDuration,
2524 MediaSeeking_GetStopPosition,
2525 MediaSeeking_GetCurrentPosition,
2526 MediaSeeking_ConvertTimeFormat,
2527 MediaSeeking_SetPositions,
2528 MediaSeeking_GetPositions,
2529 MediaSeeking_GetAvailable,
2530 MediaSeeking_SetRate,
2531 MediaSeeking_GetRate,
2532 MediaSeeking_GetPreroll
2535 static struct filter_graph *impl_from_IMediaPosition(IMediaPosition *iface)
2537 return CONTAINING_RECORD(iface, struct filter_graph, IMediaPosition_iface);
2540 /*** IUnknown methods ***/
2541 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition *iface, REFIID iid, void **out)
2543 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2544 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2547 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2549 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2550 return IUnknown_AddRef(graph->outer_unk);
2553 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2555 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2556 return IUnknown_Release(graph->outer_unk);
2559 /*** IDispatch methods ***/
2560 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo)
2562 FIXME("(%p) stub!\n", iface);
2563 return E_NOTIMPL;
2566 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
2568 FIXME("(%p) stub!\n", iface);
2569 return E_NOTIMPL;
2572 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
2574 FIXME("(%p) stub!\n", iface);
2575 return E_NOTIMPL;
2578 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2580 FIXME("(%p) stub!\n", iface);
2581 return E_NOTIMPL;
2584 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2586 GUID time_format;
2587 HRESULT hr;
2589 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2590 if (FAILED(hr))
2591 return hr;
2592 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2594 FIXME("Unsupported time format.\n");
2595 return E_NOTIMPL;
2598 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2599 return S_OK;
2602 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2604 GUID time_format;
2605 HRESULT hr;
2607 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2608 if (FAILED(hr))
2609 return hr;
2610 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2612 FIXME("Unsupported time format.\n");
2613 return E_NOTIMPL;
2616 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2617 return S_OK;
2620 /*** IMediaPosition methods ***/
2621 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2623 LONGLONG duration;
2624 struct filter_graph *This = impl_from_IMediaPosition( iface );
2625 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2626 if (FAILED(hr))
2627 return hr;
2628 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2631 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2633 struct filter_graph *This = impl_from_IMediaPosition( iface );
2634 LONGLONG reftime;
2635 HRESULT hr;
2637 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2638 if (FAILED(hr))
2639 return hr;
2640 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2641 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2644 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2646 struct filter_graph *This = impl_from_IMediaPosition( iface );
2647 LONGLONG pos;
2648 HRESULT hr;
2650 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2651 if (FAILED(hr))
2652 return hr;
2653 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2656 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2658 struct filter_graph *This = impl_from_IMediaPosition( iface );
2659 LONGLONG pos;
2660 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2661 if (FAILED(hr))
2662 return hr;
2663 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2666 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2668 struct filter_graph *This = impl_from_IMediaPosition( iface );
2669 LONGLONG reftime;
2670 HRESULT hr;
2672 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2673 if (FAILED(hr))
2674 return hr;
2675 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2676 &reftime, AM_SEEKING_AbsolutePositioning);
2679 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime)
2681 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2682 return E_NOTIMPL;
2685 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime)
2687 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2688 return E_NOTIMPL;
2691 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2693 struct filter_graph *This = impl_from_IMediaPosition( iface );
2694 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2697 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2699 struct filter_graph *This = impl_from_IMediaPosition( iface );
2700 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2703 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward)
2705 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2706 return E_NOTIMPL;
2709 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward)
2711 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2712 return E_NOTIMPL;
2716 static const IMediaPositionVtbl IMediaPosition_VTable =
2718 MediaPosition_QueryInterface,
2719 MediaPosition_AddRef,
2720 MediaPosition_Release,
2721 MediaPosition_GetTypeInfoCount,
2722 MediaPosition_GetTypeInfo,
2723 MediaPosition_GetIDsOfNames,
2724 MediaPosition_Invoke,
2725 MediaPosition_get_Duration,
2726 MediaPosition_put_CurrentPosition,
2727 MediaPosition_get_CurrentPosition,
2728 MediaPosition_get_StopTime,
2729 MediaPosition_put_StopTime,
2730 MediaPosition_get_PrerollTime,
2731 MediaPosition_put_PrerollTime,
2732 MediaPosition_put_Rate,
2733 MediaPosition_get_Rate,
2734 MediaPosition_CanSeekForward,
2735 MediaPosition_CanSeekBackward
2738 static struct filter_graph *impl_from_IObjectWithSite(IObjectWithSite *iface)
2740 return CONTAINING_RECORD(iface, struct filter_graph, IObjectWithSite_iface);
2743 /*** IUnknown methods ***/
2744 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID iid, void **out)
2746 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2747 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2750 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
2752 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2753 return IUnknown_AddRef(graph->outer_unk);
2756 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
2758 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2759 return IUnknown_Release(graph->outer_unk);
2762 /*** IObjectWithSite methods ***/
2764 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
2766 struct filter_graph *This = impl_from_IObjectWithSite( iface );
2768 TRACE("(%p/%p)->()\n", This, iface);
2769 if (This->pSite) IUnknown_Release(This->pSite);
2770 This->pSite = pUnkSite;
2771 IUnknown_AddRef(This->pSite);
2772 return S_OK;
2775 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, PVOID *ppvSite)
2777 struct filter_graph *This = impl_from_IObjectWithSite( iface );
2779 TRACE("(%p/%p)->(%s)\n", This, iface,debugstr_guid(riid));
2781 *ppvSite = NULL;
2782 if (!This->pSite)
2783 return E_FAIL;
2784 else
2785 return IUnknown_QueryInterface(This->pSite, riid, ppvSite);
2788 static const IObjectWithSiteVtbl IObjectWithSite_VTable =
2790 ObjectWithSite_QueryInterface,
2791 ObjectWithSite_AddRef,
2792 ObjectWithSite_Release,
2793 ObjectWithSite_SetSite,
2794 ObjectWithSite_GetSite,
2797 static HRESULT GetTargetInterface(struct filter_graph* pGraph, REFIID riid, LPVOID* ppvObj)
2799 struct filter *filter;
2800 HRESULT hr;
2801 int entry;
2803 /* Check if the interface type is already registered */
2804 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2805 if (riid == pGraph->ItfCacheEntries[entry].riid)
2807 if (pGraph->ItfCacheEntries[entry].iface)
2809 /* Return the interface if available */
2810 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2811 return S_OK;
2813 break;
2816 if (entry >= MAX_ITF_CACHE_ENTRIES)
2818 FIXME("Not enough space to store interface in the cache\n");
2819 return E_OUTOFMEMORY;
2822 /* Find a filter supporting the requested interface */
2823 LIST_FOR_EACH_ENTRY(filter, &pGraph->filters, struct filter, entry)
2825 hr = IBaseFilter_QueryInterface(filter->filter, riid, ppvObj);
2826 if (hr == S_OK)
2828 pGraph->ItfCacheEntries[entry].riid = riid;
2829 pGraph->ItfCacheEntries[entry].filter = filter->filter;
2830 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2831 if (entry >= pGraph->nItfCacheEntries)
2832 pGraph->nItfCacheEntries++;
2833 return S_OK;
2835 if (hr != E_NOINTERFACE)
2836 return hr;
2839 return IsEqualGUID(riid, &IID_IBasicAudio) ? E_NOTIMPL : E_NOINTERFACE;
2842 static struct filter_graph *impl_from_IBasicAudio(IBasicAudio *iface)
2844 return CONTAINING_RECORD(iface, struct filter_graph, IBasicAudio_iface);
2847 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID iid, void **out)
2849 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2850 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2853 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
2855 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2856 return IUnknown_AddRef(graph->outer_unk);
2859 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
2861 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2862 return IUnknown_Release(graph->outer_unk);
2865 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *count)
2867 TRACE("iface %p, count %p.\n", iface, count);
2868 *count = 1;
2869 return S_OK;
2872 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT index,
2873 LCID lcid, ITypeInfo **typeinfo)
2875 TRACE("iface %p, index %u, lcid %#x, typeinfo %p.\n", iface, index, lcid, typeinfo);
2876 return strmbase_get_typeinfo(IBasicAudio_tid, typeinfo);
2879 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID iid,
2880 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
2882 ITypeInfo *typeinfo;
2883 HRESULT hr;
2885 TRACE("iface %p, iid %s, names %p, count %u, lcid %#x, ids %p.\n",
2886 iface, debugstr_guid(iid), names, count, lcid, ids);
2888 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicAudio_tid, &typeinfo)))
2890 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
2891 ITypeInfo_Release(typeinfo);
2893 return hr;
2896 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID id, REFIID iid, LCID lcid,
2897 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
2899 ITypeInfo *typeinfo;
2900 HRESULT hr;
2902 TRACE("iface %p, id %d, iid %s, lcid %#x, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
2903 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
2905 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicAudio_tid, &typeinfo)))
2907 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
2908 ITypeInfo_Release(typeinfo);
2910 return hr;
2913 /*** IBasicAudio methods ***/
2914 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
2916 struct filter_graph *This = impl_from_IBasicAudio(iface);
2917 IBasicAudio* pBasicAudio;
2918 HRESULT hr;
2920 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
2922 EnterCriticalSection(&This->cs);
2924 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2926 if (hr == S_OK)
2927 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
2929 LeaveCriticalSection(&This->cs);
2931 return hr;
2934 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
2936 struct filter_graph *This = impl_from_IBasicAudio(iface);
2937 IBasicAudio* pBasicAudio;
2938 HRESULT hr;
2940 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
2942 EnterCriticalSection(&This->cs);
2944 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2946 if (hr == S_OK)
2947 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
2949 LeaveCriticalSection(&This->cs);
2951 return hr;
2954 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
2956 struct filter_graph *This = impl_from_IBasicAudio(iface);
2957 IBasicAudio* pBasicAudio;
2958 HRESULT hr;
2960 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
2962 EnterCriticalSection(&This->cs);
2964 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2966 if (hr == S_OK)
2967 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
2969 LeaveCriticalSection(&This->cs);
2971 return hr;
2974 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
2976 struct filter_graph *This = impl_from_IBasicAudio(iface);
2977 IBasicAudio* pBasicAudio;
2978 HRESULT hr;
2980 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
2982 EnterCriticalSection(&This->cs);
2984 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2986 if (hr == S_OK)
2987 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
2989 LeaveCriticalSection(&This->cs);
2991 return hr;
2994 static const IBasicAudioVtbl IBasicAudio_VTable =
2996 BasicAudio_QueryInterface,
2997 BasicAudio_AddRef,
2998 BasicAudio_Release,
2999 BasicAudio_GetTypeInfoCount,
3000 BasicAudio_GetTypeInfo,
3001 BasicAudio_GetIDsOfNames,
3002 BasicAudio_Invoke,
3003 BasicAudio_put_Volume,
3004 BasicAudio_get_Volume,
3005 BasicAudio_put_Balance,
3006 BasicAudio_get_Balance
3009 static struct filter_graph *impl_from_IBasicVideo2(IBasicVideo2 *iface)
3011 return CONTAINING_RECORD(iface, struct filter_graph, IBasicVideo2_iface);
3014 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID iid, void **out)
3016 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
3017 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
3020 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
3022 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
3023 return IUnknown_AddRef(graph->outer_unk);
3026 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
3028 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
3029 return IUnknown_Release(graph->outer_unk);
3032 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *count)
3034 TRACE("iface %p, count %p.\n", iface, count);
3035 *count = 1;
3036 return S_OK;
3039 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT index,
3040 LCID lcid, ITypeInfo **typeinfo)
3042 TRACE("iface %p, index %u, lcid %#x, typeinfo %p.\n", iface, index, lcid, typeinfo);
3043 return strmbase_get_typeinfo(IBasicVideo_tid, typeinfo);
3046 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID iid,
3047 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
3049 ITypeInfo *typeinfo;
3050 HRESULT hr;
3052 TRACE("iface %p, iid %s, names %p, count %u, lcid %#x, ids %p.\n",
3053 iface, debugstr_guid(iid), names, count, lcid, ids);
3055 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicVideo_tid, &typeinfo)))
3057 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
3058 ITypeInfo_Release(typeinfo);
3060 return hr;
3063 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID id, REFIID iid, LCID lcid,
3064 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
3066 ITypeInfo *typeinfo;
3067 HRESULT hr;
3069 TRACE("iface %p, id %d, iid %s, lcid %#x, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
3070 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
3072 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicVideo_tid, &typeinfo)))
3074 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
3075 ITypeInfo_Release(typeinfo);
3077 return hr;
3080 /*** IBasicVideo methods ***/
3081 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3083 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3084 IBasicVideo *pBasicVideo;
3085 HRESULT hr;
3087 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3089 EnterCriticalSection(&This->cs);
3091 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3093 if (hr == S_OK)
3094 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3096 LeaveCriticalSection(&This->cs);
3098 return hr;
3101 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3103 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3104 IBasicVideo *pBasicVideo;
3105 HRESULT hr;
3107 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3109 EnterCriticalSection(&This->cs);
3111 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3113 if (hr == S_OK)
3114 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3116 LeaveCriticalSection(&This->cs);
3118 return hr;
3121 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3123 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3124 IBasicVideo *pBasicVideo;
3125 HRESULT hr;
3127 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3129 EnterCriticalSection(&This->cs);
3131 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3133 if (hr == S_OK)
3134 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3136 LeaveCriticalSection(&This->cs);
3138 return hr;
3141 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3143 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3144 IBasicVideo *pBasicVideo;
3145 HRESULT hr;
3147 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3149 EnterCriticalSection(&This->cs);
3151 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3153 if (hr == S_OK)
3154 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3156 LeaveCriticalSection(&This->cs);
3158 return hr;
3161 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3163 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3164 IBasicVideo *pBasicVideo;
3165 HRESULT hr;
3167 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3169 EnterCriticalSection(&This->cs);
3171 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3173 if (hr == S_OK)
3174 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3176 LeaveCriticalSection(&This->cs);
3178 return hr;
3181 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3183 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3184 IBasicVideo *pBasicVideo;
3185 HRESULT hr;
3187 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3189 EnterCriticalSection(&This->cs);
3191 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3193 if (hr == S_OK)
3194 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3196 LeaveCriticalSection(&This->cs);
3198 return hr;
3201 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3203 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3204 IBasicVideo *pBasicVideo;
3205 HRESULT hr;
3207 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3209 EnterCriticalSection(&This->cs);
3211 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3213 if (hr == S_OK)
3214 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3216 LeaveCriticalSection(&This->cs);
3218 return hr;
3221 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3223 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3224 IBasicVideo *pBasicVideo;
3225 HRESULT hr;
3227 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3229 EnterCriticalSection(&This->cs);
3231 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3233 if (hr == S_OK)
3234 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3236 LeaveCriticalSection(&This->cs);
3238 return hr;
3241 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3243 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3244 IBasicVideo *pBasicVideo;
3245 HRESULT hr;
3247 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3249 EnterCriticalSection(&This->cs);
3251 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3253 if (hr == S_OK)
3254 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3256 LeaveCriticalSection(&This->cs);
3258 return hr;
3261 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3263 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3264 IBasicVideo *pBasicVideo;
3265 HRESULT hr;
3267 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3269 EnterCriticalSection(&This->cs);
3271 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3273 if (hr == S_OK)
3274 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3276 LeaveCriticalSection(&This->cs);
3278 return hr;
3281 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3283 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3284 IBasicVideo *pBasicVideo;
3285 HRESULT hr;
3287 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3289 EnterCriticalSection(&This->cs);
3291 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3293 if (hr == S_OK)
3294 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3296 LeaveCriticalSection(&This->cs);
3298 return hr;
3301 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3303 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3304 IBasicVideo *pBasicVideo;
3305 HRESULT hr;
3307 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3309 EnterCriticalSection(&This->cs);
3311 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3313 if (hr == S_OK)
3314 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3316 LeaveCriticalSection(&This->cs);
3318 return hr;
3321 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3323 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3324 IBasicVideo *pBasicVideo;
3325 HRESULT hr;
3327 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3329 EnterCriticalSection(&This->cs);
3331 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3333 if (hr == S_OK)
3334 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3336 LeaveCriticalSection(&This->cs);
3338 return hr;
3341 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3343 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3344 IBasicVideo *pBasicVideo;
3345 HRESULT hr;
3347 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3349 EnterCriticalSection(&This->cs);
3351 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3353 if (hr == S_OK)
3354 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3356 LeaveCriticalSection(&This->cs);
3358 return hr;
3361 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3363 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3364 IBasicVideo *pBasicVideo;
3365 HRESULT hr;
3367 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3369 EnterCriticalSection(&This->cs);
3371 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3373 if (hr == S_OK)
3374 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3376 LeaveCriticalSection(&This->cs);
3378 return hr;
3381 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3383 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3384 IBasicVideo *pBasicVideo;
3385 HRESULT hr;
3387 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3389 EnterCriticalSection(&This->cs);
3391 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3393 if (hr == S_OK)
3394 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3396 LeaveCriticalSection(&This->cs);
3398 return hr;
3401 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3403 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3404 IBasicVideo *pBasicVideo;
3405 HRESULT hr;
3407 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3409 EnterCriticalSection(&This->cs);
3411 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3413 if (hr == S_OK)
3414 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3416 LeaveCriticalSection(&This->cs);
3418 return hr;
3421 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3423 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3424 IBasicVideo *pBasicVideo;
3425 HRESULT hr;
3427 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3429 EnterCriticalSection(&This->cs);
3431 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3433 if (hr == S_OK)
3434 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3436 LeaveCriticalSection(&This->cs);
3438 return hr;
3441 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3443 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3444 IBasicVideo *pBasicVideo;
3445 HRESULT hr;
3447 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3449 EnterCriticalSection(&This->cs);
3451 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3453 if (hr == S_OK)
3454 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3456 LeaveCriticalSection(&This->cs);
3458 return hr;
3461 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3463 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3464 IBasicVideo *pBasicVideo;
3465 HRESULT hr;
3467 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3469 EnterCriticalSection(&This->cs);
3471 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3473 if (hr == S_OK)
3474 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3476 LeaveCriticalSection(&This->cs);
3478 return hr;
3481 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3482 LONG *pDestinationHeight)
3484 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3485 IBasicVideo *pBasicVideo;
3486 HRESULT hr;
3488 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3490 EnterCriticalSection(&This->cs);
3492 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3494 if (hr == S_OK)
3495 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3497 LeaveCriticalSection(&This->cs);
3499 return hr;
3502 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3503 LONG Width, LONG Height)
3505 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3506 IBasicVideo *pBasicVideo;
3507 HRESULT hr;
3509 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3511 EnterCriticalSection(&This->cs);
3513 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3515 if (hr == S_OK)
3516 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3518 LeaveCriticalSection(&This->cs);
3520 return hr;
3523 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3524 LONG *pWidth, LONG *pHeight)
3526 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3527 IBasicVideo *pBasicVideo;
3528 HRESULT hr;
3530 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3532 EnterCriticalSection(&This->cs);
3534 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3536 if (hr == S_OK)
3537 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3539 LeaveCriticalSection(&This->cs);
3541 return hr;
3544 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3546 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3547 IBasicVideo *pBasicVideo;
3548 HRESULT hr;
3550 TRACE("(%p/%p)->()\n", This, iface);
3552 EnterCriticalSection(&This->cs);
3554 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3556 if (hr == S_OK)
3557 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3559 LeaveCriticalSection(&This->cs);
3561 return hr;
3564 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3565 LONG Width, LONG Height)
3567 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3568 IBasicVideo *pBasicVideo;
3569 HRESULT hr;
3571 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3573 EnterCriticalSection(&This->cs);
3575 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3577 if (hr == S_OK)
3578 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3580 LeaveCriticalSection(&This->cs);
3582 return hr;
3585 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3586 LONG *pTop, LONG *pWidth, LONG *pHeight)
3588 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3589 IBasicVideo *pBasicVideo;
3590 HRESULT hr;
3592 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3594 EnterCriticalSection(&This->cs);
3596 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3598 if (hr == S_OK)
3599 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3601 LeaveCriticalSection(&This->cs);
3603 return hr;
3606 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3608 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3609 IBasicVideo *pBasicVideo;
3610 HRESULT hr;
3612 TRACE("(%p/%p)->()\n", This, iface);
3614 EnterCriticalSection(&This->cs);
3616 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3618 if (hr == S_OK)
3619 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3621 LeaveCriticalSection(&This->cs);
3623 return hr;
3626 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3628 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3629 IBasicVideo *pBasicVideo;
3630 HRESULT hr;
3632 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3634 EnterCriticalSection(&This->cs);
3636 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3638 if (hr == S_OK)
3639 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3641 LeaveCriticalSection(&This->cs);
3643 return hr;
3646 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3647 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3649 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3650 IBasicVideo *pBasicVideo;
3651 HRESULT hr;
3653 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3655 EnterCriticalSection(&This->cs);
3657 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3659 if (hr == S_OK)
3660 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3662 LeaveCriticalSection(&This->cs);
3664 return hr;
3667 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3668 LONG *pDIBImage)
3670 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3671 IBasicVideo *pBasicVideo;
3672 HRESULT hr;
3674 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3676 EnterCriticalSection(&This->cs);
3678 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3680 if (hr == S_OK)
3681 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3683 LeaveCriticalSection(&This->cs);
3685 return hr;
3688 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3690 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3691 IBasicVideo *pBasicVideo;
3692 HRESULT hr;
3694 TRACE("(%p/%p)->()\n", This, iface);
3696 EnterCriticalSection(&This->cs);
3698 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3700 if (hr == S_OK)
3701 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3703 LeaveCriticalSection(&This->cs);
3705 return hr;
3708 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3710 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3711 IBasicVideo *pBasicVideo;
3712 HRESULT hr;
3714 TRACE("(%p/%p)->()\n", This, iface);
3716 EnterCriticalSection(&This->cs);
3718 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3720 if (hr == S_OK)
3721 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3723 LeaveCriticalSection(&This->cs);
3725 return hr;
3728 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3729 LONG *plAspectY)
3731 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3732 IBasicVideo2 *pBasicVideo2;
3733 HRESULT hr;
3735 TRACE("(%p/%p)->()\n", This, iface);
3737 EnterCriticalSection(&This->cs);
3739 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3741 if (hr == S_OK)
3742 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3744 LeaveCriticalSection(&This->cs);
3746 return hr;
3749 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3751 BasicVideo_QueryInterface,
3752 BasicVideo_AddRef,
3753 BasicVideo_Release,
3754 BasicVideo_GetTypeInfoCount,
3755 BasicVideo_GetTypeInfo,
3756 BasicVideo_GetIDsOfNames,
3757 BasicVideo_Invoke,
3758 BasicVideo_get_AvgTimePerFrame,
3759 BasicVideo_get_BitRate,
3760 BasicVideo_get_BitErrorRate,
3761 BasicVideo_get_VideoWidth,
3762 BasicVideo_get_VideoHeight,
3763 BasicVideo_put_SourceLeft,
3764 BasicVideo_get_SourceLeft,
3765 BasicVideo_put_SourceWidth,
3766 BasicVideo_get_SourceWidth,
3767 BasicVideo_put_SourceTop,
3768 BasicVideo_get_SourceTop,
3769 BasicVideo_put_SourceHeight,
3770 BasicVideo_get_SourceHeight,
3771 BasicVideo_put_DestinationLeft,
3772 BasicVideo_get_DestinationLeft,
3773 BasicVideo_put_DestinationWidth,
3774 BasicVideo_get_DestinationWidth,
3775 BasicVideo_put_DestinationTop,
3776 BasicVideo_get_DestinationTop,
3777 BasicVideo_put_DestinationHeight,
3778 BasicVideo_get_DestinationHeight,
3779 BasicVideo_SetSourcePosition,
3780 BasicVideo_GetSourcePosition,
3781 BasicVideo_SetDefaultSourcePosition,
3782 BasicVideo_SetDestinationPosition,
3783 BasicVideo_GetDestinationPosition,
3784 BasicVideo_SetDefaultDestinationPosition,
3785 BasicVideo_GetVideoSize,
3786 BasicVideo_GetVideoPaletteEntries,
3787 BasicVideo_GetCurrentImage,
3788 BasicVideo_IsUsingDefaultSource,
3789 BasicVideo_IsUsingDefaultDestination,
3790 BasicVideo2_GetPreferredAspectRatio
3793 static struct filter_graph *impl_from_IVideoWindow(IVideoWindow *iface)
3795 return CONTAINING_RECORD(iface, struct filter_graph, IVideoWindow_iface);
3798 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID iid, void **out)
3800 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3801 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
3804 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
3806 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3807 return IUnknown_AddRef(graph->outer_unk);
3810 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
3812 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3813 return IUnknown_Release(graph->outer_unk);
3816 HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *count)
3818 TRACE("iface %p, count %p.\n", iface, count);
3819 *count = 1;
3820 return S_OK;
3823 HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT index,
3824 LCID lcid, ITypeInfo **typeinfo)
3826 TRACE("iface %p, index %u, lcid %#x, typeinfo %p.\n", iface, index, lcid, typeinfo);
3827 return strmbase_get_typeinfo(IVideoWindow_tid, typeinfo);
3830 HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID iid,
3831 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
3833 ITypeInfo *typeinfo;
3834 HRESULT hr;
3836 TRACE("iface %p, iid %s, names %p, count %u, lcid %#x, ids %p.\n",
3837 iface, debugstr_guid(iid), names, count, lcid, ids);
3839 if (SUCCEEDED(hr = strmbase_get_typeinfo(IVideoWindow_tid, &typeinfo)))
3841 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
3842 ITypeInfo_Release(typeinfo);
3844 return hr;
3847 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID id, REFIID iid, LCID lcid,
3848 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
3850 ITypeInfo *typeinfo;
3851 HRESULT hr;
3853 TRACE("iface %p, id %d, iid %s, lcid %#x, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
3854 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
3856 if (SUCCEEDED(hr = strmbase_get_typeinfo(IVideoWindow_tid, &typeinfo)))
3858 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
3859 ITypeInfo_Release(typeinfo);
3861 return hr;
3864 /*** IVideoWindow methods ***/
3865 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
3867 struct filter_graph *This = impl_from_IVideoWindow(iface);
3868 IVideoWindow *pVideoWindow;
3869 HRESULT hr;
3871 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
3873 EnterCriticalSection(&This->cs);
3875 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3877 if (hr == S_OK)
3878 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
3880 LeaveCriticalSection(&This->cs);
3882 return hr;
3885 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
3887 struct filter_graph *This = impl_from_IVideoWindow(iface);
3888 IVideoWindow *pVideoWindow;
3889 HRESULT hr;
3891 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
3893 EnterCriticalSection(&This->cs);
3895 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3897 if (hr == S_OK)
3898 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
3900 LeaveCriticalSection(&This->cs);
3902 return hr;
3905 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
3907 struct filter_graph *This = impl_from_IVideoWindow(iface);
3908 IVideoWindow *pVideoWindow;
3909 HRESULT hr;
3911 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
3913 EnterCriticalSection(&This->cs);
3915 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3917 if (hr == S_OK)
3918 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
3920 LeaveCriticalSection(&This->cs);
3922 return hr;
3925 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
3927 struct filter_graph *This = impl_from_IVideoWindow(iface);
3928 IVideoWindow *pVideoWindow;
3929 HRESULT hr;
3931 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
3933 EnterCriticalSection(&This->cs);
3935 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3937 if (hr == S_OK)
3938 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
3940 LeaveCriticalSection(&This->cs);
3942 return hr;
3945 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
3947 struct filter_graph *This = impl_from_IVideoWindow(iface);
3948 IVideoWindow *pVideoWindow;
3949 HRESULT hr;
3951 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
3953 EnterCriticalSection(&This->cs);
3955 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3957 if (hr == S_OK)
3958 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
3960 LeaveCriticalSection(&This->cs);
3962 return hr;
3965 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
3967 struct filter_graph *This = impl_from_IVideoWindow(iface);
3968 IVideoWindow *pVideoWindow;
3969 HRESULT hr;
3971 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
3973 EnterCriticalSection(&This->cs);
3975 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3977 if (hr == S_OK)
3978 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
3980 LeaveCriticalSection(&This->cs);
3982 return hr;
3985 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
3987 struct filter_graph *This = impl_from_IVideoWindow(iface);
3988 IVideoWindow *pVideoWindow;
3989 HRESULT hr;
3991 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
3993 EnterCriticalSection(&This->cs);
3995 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3997 if (hr == S_OK)
3998 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4000 LeaveCriticalSection(&This->cs);
4002 return hr;
4005 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
4007 struct filter_graph *This = impl_from_IVideoWindow(iface);
4008 IVideoWindow *pVideoWindow;
4009 HRESULT hr;
4011 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4013 EnterCriticalSection(&This->cs);
4015 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4017 if (hr == S_OK)
4018 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4020 LeaveCriticalSection(&This->cs);
4022 return hr;
4025 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
4027 struct filter_graph *This = impl_from_IVideoWindow(iface);
4028 IVideoWindow *pVideoWindow;
4029 HRESULT hr;
4031 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4033 EnterCriticalSection(&This->cs);
4035 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4037 if (hr == S_OK)
4038 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4040 LeaveCriticalSection(&This->cs);
4042 return hr;
4045 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4047 struct filter_graph *This = impl_from_IVideoWindow(iface);
4048 IVideoWindow *pVideoWindow;
4049 HRESULT hr;
4051 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4053 EnterCriticalSection(&This->cs);
4055 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4057 if (hr == S_OK)
4058 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4060 LeaveCriticalSection(&This->cs);
4062 return hr;
4065 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4067 struct filter_graph *This = impl_from_IVideoWindow(iface);
4068 IVideoWindow *pVideoWindow;
4069 HRESULT hr;
4071 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4073 EnterCriticalSection(&This->cs);
4075 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4077 if (hr == S_OK)
4078 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4080 LeaveCriticalSection(&This->cs);
4082 return hr;
4085 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4086 LONG *pBackgroundPalette)
4088 struct filter_graph *This = impl_from_IVideoWindow(iface);
4089 IVideoWindow *pVideoWindow;
4090 HRESULT hr;
4092 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4094 EnterCriticalSection(&This->cs);
4096 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4098 if (hr == S_OK)
4099 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4101 LeaveCriticalSection(&This->cs);
4103 return hr;
4106 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4108 struct filter_graph *This = impl_from_IVideoWindow(iface);
4109 IVideoWindow *pVideoWindow;
4110 HRESULT hr;
4112 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4114 EnterCriticalSection(&This->cs);
4116 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4118 if (hr == S_OK)
4119 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4121 LeaveCriticalSection(&This->cs);
4123 return hr;
4126 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4128 struct filter_graph *This = impl_from_IVideoWindow(iface);
4129 IVideoWindow *pVideoWindow;
4130 HRESULT hr;
4132 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4134 EnterCriticalSection(&This->cs);
4136 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4138 if (hr == S_OK)
4139 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4141 LeaveCriticalSection(&This->cs);
4143 return hr;
4146 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4148 struct filter_graph *This = impl_from_IVideoWindow(iface);
4149 IVideoWindow *pVideoWindow;
4150 HRESULT hr;
4152 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4154 EnterCriticalSection(&This->cs);
4156 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4158 if (hr == S_OK)
4159 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4161 LeaveCriticalSection(&This->cs);
4163 return hr;
4166 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4168 struct filter_graph *This = impl_from_IVideoWindow(iface);
4169 IVideoWindow *pVideoWindow;
4170 HRESULT hr;
4172 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4174 EnterCriticalSection(&This->cs);
4176 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4178 if (hr == S_OK)
4179 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4181 LeaveCriticalSection(&This->cs);
4183 return hr;
4186 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4188 struct filter_graph *This = impl_from_IVideoWindow(iface);
4189 IVideoWindow *pVideoWindow;
4190 HRESULT hr;
4192 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4194 EnterCriticalSection(&This->cs);
4196 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4198 if (hr == S_OK)
4199 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4201 LeaveCriticalSection(&This->cs);
4203 return hr;
4206 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4208 struct filter_graph *This = impl_from_IVideoWindow(iface);
4209 IVideoWindow *pVideoWindow;
4210 HRESULT hr;
4212 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4214 EnterCriticalSection(&This->cs);
4216 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4218 if (hr == S_OK)
4219 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4221 LeaveCriticalSection(&This->cs);
4223 return hr;
4226 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4228 struct filter_graph *This = impl_from_IVideoWindow(iface);
4229 IVideoWindow *pVideoWindow;
4230 HRESULT hr;
4232 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4234 EnterCriticalSection(&This->cs);
4236 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4238 if (hr == S_OK)
4239 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4241 LeaveCriticalSection(&This->cs);
4243 return hr;
4246 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4248 struct filter_graph *This = impl_from_IVideoWindow(iface);
4249 IVideoWindow *pVideoWindow;
4250 HRESULT hr;
4252 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4254 EnterCriticalSection(&This->cs);
4256 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4258 if (hr == S_OK)
4259 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4261 LeaveCriticalSection(&This->cs);
4263 return hr;
4266 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4268 struct filter_graph *This = impl_from_IVideoWindow(iface);
4269 IVideoWindow *pVideoWindow;
4270 HRESULT hr;
4272 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4274 EnterCriticalSection(&This->cs);
4276 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4278 if (hr == S_OK)
4279 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4281 LeaveCriticalSection(&This->cs);
4283 return hr;
4286 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4288 struct filter_graph *This = impl_from_IVideoWindow(iface);
4289 IVideoWindow *pVideoWindow;
4290 HRESULT hr;
4292 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4294 EnterCriticalSection(&This->cs);
4296 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4298 if (hr == S_OK)
4299 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4301 LeaveCriticalSection(&This->cs);
4303 return hr;
4306 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4308 struct filter_graph *This = impl_from_IVideoWindow(iface);
4309 IVideoWindow *pVideoWindow;
4310 HRESULT hr;
4312 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4314 EnterCriticalSection(&This->cs);
4316 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4318 if (hr == S_OK)
4319 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4321 LeaveCriticalSection(&This->cs);
4323 return hr;
4326 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4328 struct filter_graph *This = impl_from_IVideoWindow(iface);
4329 IVideoWindow *pVideoWindow;
4330 HRESULT hr;
4332 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4334 EnterCriticalSection(&This->cs);
4336 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4338 if (hr == S_OK)
4339 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4341 LeaveCriticalSection(&This->cs);
4343 return hr;
4346 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4348 struct filter_graph *This = impl_from_IVideoWindow(iface);
4349 IVideoWindow *pVideoWindow;
4350 HRESULT hr;
4352 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4354 EnterCriticalSection(&This->cs);
4356 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4358 if (hr == S_OK)
4359 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4361 LeaveCriticalSection(&This->cs);
4363 return hr;
4366 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4368 struct filter_graph *This = impl_from_IVideoWindow(iface);
4369 IVideoWindow *pVideoWindow;
4370 HRESULT hr;
4372 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4374 EnterCriticalSection(&This->cs);
4376 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4378 if (hr == S_OK)
4379 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4381 LeaveCriticalSection(&This->cs);
4383 return hr;
4386 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4388 struct filter_graph *This = impl_from_IVideoWindow(iface);
4389 IVideoWindow *pVideoWindow;
4390 HRESULT hr;
4392 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4394 EnterCriticalSection(&This->cs);
4396 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4398 if (hr == S_OK)
4399 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4401 LeaveCriticalSection(&This->cs);
4403 return hr;
4406 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4408 struct filter_graph *This = impl_from_IVideoWindow(iface);
4409 IVideoWindow *pVideoWindow;
4410 HRESULT hr;
4412 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4414 EnterCriticalSection(&This->cs);
4416 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4418 if (hr == S_OK)
4419 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4421 LeaveCriticalSection(&This->cs);
4423 return hr;
4426 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4428 struct filter_graph *This = impl_from_IVideoWindow(iface);
4429 IVideoWindow *pVideoWindow;
4430 HRESULT hr;
4432 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4434 EnterCriticalSection(&This->cs);
4436 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4438 if (hr == S_OK)
4439 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4441 LeaveCriticalSection(&This->cs);
4443 return hr;
4446 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4448 struct filter_graph *This = impl_from_IVideoWindow(iface);
4449 IVideoWindow *pVideoWindow;
4450 HRESULT hr;
4452 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4454 EnterCriticalSection(&This->cs);
4456 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4458 if (hr == S_OK)
4459 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4461 LeaveCriticalSection(&This->cs);
4463 return hr;
4466 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4468 struct filter_graph *This = impl_from_IVideoWindow(iface);
4469 IVideoWindow *pVideoWindow;
4470 HRESULT hr;
4472 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4474 EnterCriticalSection(&This->cs);
4476 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4478 if (hr == S_OK)
4479 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4481 LeaveCriticalSection(&This->cs);
4483 return hr;
4486 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4487 LONG_PTR wParam, LONG_PTR lParam)
4489 struct filter_graph *This = impl_from_IVideoWindow(iface);
4490 IVideoWindow *pVideoWindow;
4491 HRESULT hr;
4493 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4495 EnterCriticalSection(&This->cs);
4497 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4499 if (hr == S_OK)
4500 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4502 LeaveCriticalSection(&This->cs);
4504 return hr;
4507 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4508 LONG Width, LONG Height)
4510 struct filter_graph *This = impl_from_IVideoWindow(iface);
4511 IVideoWindow *pVideoWindow;
4512 HRESULT hr;
4514 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4516 EnterCriticalSection(&This->cs);
4518 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4520 if (hr == S_OK)
4521 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4523 LeaveCriticalSection(&This->cs);
4525 return hr;
4528 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4529 LONG *pWidth, LONG *pHeight)
4531 struct filter_graph *This = impl_from_IVideoWindow(iface);
4532 IVideoWindow *pVideoWindow;
4533 HRESULT hr;
4535 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4537 EnterCriticalSection(&This->cs);
4539 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4541 if (hr == S_OK)
4542 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4544 LeaveCriticalSection(&This->cs);
4546 return hr;
4549 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4550 LONG *pHeight)
4552 struct filter_graph *This = impl_from_IVideoWindow(iface);
4553 IVideoWindow *pVideoWindow;
4554 HRESULT hr;
4556 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4558 EnterCriticalSection(&This->cs);
4560 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4562 if (hr == S_OK)
4563 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4565 LeaveCriticalSection(&This->cs);
4567 return hr;
4570 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4571 LONG *pHeight)
4573 struct filter_graph *This = impl_from_IVideoWindow(iface);
4574 IVideoWindow *pVideoWindow;
4575 HRESULT hr;
4577 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4579 EnterCriticalSection(&This->cs);
4581 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4583 if (hr == S_OK)
4584 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4586 LeaveCriticalSection(&This->cs);
4588 return hr;
4591 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4592 LONG *pWidth, LONG *pHeight)
4594 struct filter_graph *This = impl_from_IVideoWindow(iface);
4595 IVideoWindow *pVideoWindow;
4596 HRESULT hr;
4598 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4600 EnterCriticalSection(&This->cs);
4602 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4604 if (hr == S_OK)
4605 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4607 LeaveCriticalSection(&This->cs);
4609 return hr;
4612 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4614 struct filter_graph *This = impl_from_IVideoWindow(iface);
4615 IVideoWindow *pVideoWindow;
4616 HRESULT hr;
4618 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4620 EnterCriticalSection(&This->cs);
4622 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4624 if (hr == S_OK)
4625 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4627 LeaveCriticalSection(&This->cs);
4629 return hr;
4632 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4634 struct filter_graph *This = impl_from_IVideoWindow(iface);
4635 IVideoWindow *pVideoWindow;
4636 HRESULT hr;
4638 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4640 EnterCriticalSection(&This->cs);
4642 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4644 if (hr == S_OK)
4645 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4647 LeaveCriticalSection(&This->cs);
4649 return hr;
4653 static const IVideoWindowVtbl IVideoWindow_VTable =
4655 VideoWindow_QueryInterface,
4656 VideoWindow_AddRef,
4657 VideoWindow_Release,
4658 VideoWindow_GetTypeInfoCount,
4659 VideoWindow_GetTypeInfo,
4660 VideoWindow_GetIDsOfNames,
4661 VideoWindow_Invoke,
4662 VideoWindow_put_Caption,
4663 VideoWindow_get_Caption,
4664 VideoWindow_put_WindowStyle,
4665 VideoWindow_get_WindowStyle,
4666 VideoWindow_put_WindowStyleEx,
4667 VideoWindow_get_WindowStyleEx,
4668 VideoWindow_put_AutoShow,
4669 VideoWindow_get_AutoShow,
4670 VideoWindow_put_WindowState,
4671 VideoWindow_get_WindowState,
4672 VideoWindow_put_BackgroundPalette,
4673 VideoWindow_get_BackgroundPalette,
4674 VideoWindow_put_Visible,
4675 VideoWindow_get_Visible,
4676 VideoWindow_put_Left,
4677 VideoWindow_get_Left,
4678 VideoWindow_put_Width,
4679 VideoWindow_get_Width,
4680 VideoWindow_put_Top,
4681 VideoWindow_get_Top,
4682 VideoWindow_put_Height,
4683 VideoWindow_get_Height,
4684 VideoWindow_put_Owner,
4685 VideoWindow_get_Owner,
4686 VideoWindow_put_MessageDrain,
4687 VideoWindow_get_MessageDrain,
4688 VideoWindow_get_BorderColor,
4689 VideoWindow_put_BorderColor,
4690 VideoWindow_get_FullScreenMode,
4691 VideoWindow_put_FullScreenMode,
4692 VideoWindow_SetWindowForeground,
4693 VideoWindow_NotifyOwnerMessage,
4694 VideoWindow_SetWindowPosition,
4695 VideoWindow_GetWindowPosition,
4696 VideoWindow_GetMinIdealImageSize,
4697 VideoWindow_GetMaxIdealImageSize,
4698 VideoWindow_GetRestorePosition,
4699 VideoWindow_HideCursor,
4700 VideoWindow_IsCursorHidden
4703 static struct filter_graph *impl_from_IMediaEventEx(IMediaEventEx *iface)
4705 return CONTAINING_RECORD(iface, struct filter_graph, IMediaEventEx_iface);
4708 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID iid, void **out)
4710 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4711 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
4714 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
4716 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4717 return IUnknown_AddRef(graph->outer_unk);
4720 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
4722 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4723 return IUnknown_Release(graph->outer_unk);
4726 /*** IDispatch methods ***/
4727 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *pctinfo)
4729 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4731 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
4733 return S_OK;
4736 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT iTInfo, LCID lcid,
4737 ITypeInfo **ppTInfo)
4739 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4741 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
4743 return S_OK;
4746 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID riid,
4747 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4749 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4751 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
4752 cNames, lcid, rgDispId);
4754 return S_OK;
4757 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID dispIdMember, REFIID riid,
4758 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4759 UINT *puArgErr)
4761 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4763 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
4764 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4766 return S_OK;
4769 /*** IMediaEvent methods ***/
4770 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *hEvent)
4772 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4774 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
4776 *hEvent = (OAEVENT)This->evqueue.msg_event;
4778 return S_OK;
4781 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *lEventCode, LONG_PTR *lParam1,
4782 LONG_PTR *lParam2, LONG msTimeout)
4784 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4785 Event evt;
4787 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
4789 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
4791 *lEventCode = evt.lEventCode;
4792 *lParam1 = evt.lParam1;
4793 *lParam2 = evt.lParam2;
4794 return S_OK;
4797 *lEventCode = 0;
4798 return E_ABORT;
4801 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
4802 LONG *pEvCode)
4804 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4806 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
4808 if (This->state != State_Running)
4809 return VFW_E_WRONG_STATE;
4811 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
4813 *pEvCode = This->CompletionStatus;
4814 return S_OK;
4817 *pEvCode = 0;
4818 return E_ABORT;
4821 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
4823 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4825 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4827 if (lEvCode == EC_COMPLETE)
4828 This->HandleEcComplete = FALSE;
4829 else if (lEvCode == EC_REPAINT)
4830 This->HandleEcRepaint = FALSE;
4831 else if (lEvCode == EC_CLOCK_CHANGED)
4832 This->HandleEcClockChanged = FALSE;
4833 else
4834 return S_FALSE;
4836 return S_OK;
4839 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
4841 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4843 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4845 if (lEvCode == EC_COMPLETE)
4846 This->HandleEcComplete = TRUE;
4847 else if (lEvCode == EC_REPAINT)
4848 This->HandleEcRepaint = TRUE;
4849 else if (lEvCode == EC_CLOCK_CHANGED)
4850 This->HandleEcClockChanged = TRUE;
4851 else
4852 return S_FALSE;
4854 return S_OK;
4857 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG lEvCode,
4858 LONG_PTR lParam1, LONG_PTR lParam2)
4860 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4862 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
4864 return S_OK;
4867 /*** IMediaEventEx methods ***/
4868 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface, OAHWND hwnd, LONG lMsg,
4869 LONG_PTR lInstanceData)
4871 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4873 TRACE("(%p/%p)->(%08lx, %d, %08lx)\n", This, iface, hwnd, lMsg, lInstanceData);
4875 This->notif.hWnd = (HWND)hwnd;
4876 This->notif.msg = lMsg;
4877 This->notif.instance = lInstanceData;
4879 return S_OK;
4882 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG lNoNotifyFlags)
4884 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4886 TRACE("(%p/%p)->(%d)\n", This, iface, lNoNotifyFlags);
4888 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
4889 return E_INVALIDARG;
4891 This->notif.disabled = lNoNotifyFlags;
4893 return S_OK;
4896 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *lplNoNotifyFlags)
4898 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4900 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
4902 if (!lplNoNotifyFlags)
4903 return E_POINTER;
4905 *lplNoNotifyFlags = This->notif.disabled;
4907 return S_OK;
4911 static const IMediaEventExVtbl IMediaEventEx_VTable =
4913 MediaEvent_QueryInterface,
4914 MediaEvent_AddRef,
4915 MediaEvent_Release,
4916 MediaEvent_GetTypeInfoCount,
4917 MediaEvent_GetTypeInfo,
4918 MediaEvent_GetIDsOfNames,
4919 MediaEvent_Invoke,
4920 MediaEvent_GetEventHandle,
4921 MediaEvent_GetEvent,
4922 MediaEvent_WaitForCompletion,
4923 MediaEvent_CancelDefaultHandling,
4924 MediaEvent_RestoreDefaultHandling,
4925 MediaEvent_FreeEventParams,
4926 MediaEvent_SetNotifyWindow,
4927 MediaEvent_SetNotifyFlags,
4928 MediaEvent_GetNotifyFlags
4932 static struct filter_graph *impl_from_IMediaFilter(IMediaFilter *iface)
4934 return CONTAINING_RECORD(iface, struct filter_graph, IMediaFilter_iface);
4937 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID iid, void **out)
4939 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4941 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
4944 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
4946 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4948 return IUnknown_AddRef(graph->outer_unk);
4951 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
4953 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4955 return IUnknown_Release(graph->outer_unk);
4958 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
4960 FIXME("(%p): stub\n", pClassID);
4962 return E_NOTIMPL;
4965 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
4967 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4968 HRESULT hr = S_OK, filter_hr;
4969 struct filter *filter;
4970 TP_WORK *work;
4972 TRACE("graph %p.\n", graph);
4974 EnterCriticalSection(&graph->cs);
4976 if (graph->state == State_Stopped)
4978 LeaveCriticalSection(&graph->cs);
4979 return S_OK;
4982 sort_filters(graph);
4984 if (graph->state == State_Running)
4986 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
4988 filter_hr = IBaseFilter_Pause(filter->filter);
4989 if (hr == S_OK)
4990 hr = filter_hr;
4994 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
4996 filter_hr = IBaseFilter_Stop(filter->filter);
4997 if (hr == S_OK)
4998 hr = filter_hr;
5001 graph->state = State_Stopped;
5002 graph->needs_async_run = 0;
5003 work = graph->async_run_work;
5004 graph->got_ec_complete = 0;
5006 /* Update the current position, probably to synchronize multiple streams. */
5007 IMediaSeeking_SetPositions(&graph->IMediaSeeking_iface, &graph->current_pos,
5008 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
5010 LeaveCriticalSection(&graph->cs);
5012 if (work)
5013 WaitForThreadpoolWorkCallbacks(work, TRUE);
5015 return hr;
5018 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5020 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5021 HRESULT hr = S_OK, filter_hr;
5022 struct filter *filter;
5023 TP_WORK *work;
5025 TRACE("graph %p.\n", graph);
5027 EnterCriticalSection(&graph->cs);
5029 if (graph->state == State_Paused)
5031 LeaveCriticalSection(&graph->cs);
5032 return S_OK;
5035 sort_filters(graph);
5036 update_render_count(graph);
5038 if (graph->defaultclock && !graph->refClock)
5039 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
5041 if (graph->state == State_Running && graph->refClock)
5043 REFERENCE_TIME time;
5044 IReferenceClock_GetTime(graph->refClock, &time);
5045 graph->stream_elapsed += time - graph->stream_start;
5046 graph->current_pos += graph->stream_elapsed;
5049 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5051 filter_hr = IBaseFilter_Pause(filter->filter);
5052 if (hr == S_OK)
5053 hr = filter_hr;
5056 graph->state = State_Paused;
5057 graph->needs_async_run = 0;
5058 work = graph->async_run_work;
5060 LeaveCriticalSection(&graph->cs);
5062 if (work)
5063 WaitForThreadpoolWorkCallbacks(work, TRUE);
5065 return hr;
5068 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME start)
5070 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5071 HRESULT hr;
5073 TRACE("graph %p, start %s.\n", graph, debugstr_time(start));
5075 EnterCriticalSection(&graph->cs);
5077 if (graph->state == State_Running)
5079 LeaveCriticalSection(&graph->cs);
5080 return S_OK;
5083 sort_filters(graph);
5085 hr = graph_start(graph, start);
5087 graph->state = State_Running;
5088 graph->needs_async_run = 0;
5090 LeaveCriticalSection(&graph->cs);
5091 return hr;
5094 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD timeout, FILTER_STATE *state)
5096 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5097 DWORD end = GetTickCount() + timeout;
5098 FILTER_STATE expect_state;
5099 HRESULT hr;
5101 TRACE("graph %p, timeout %u, state %p.\n", graph, timeout, state);
5103 if (!state)
5104 return E_POINTER;
5106 /* Thread safety is a little tricky here. GetState() shouldn't block other
5107 * functions from being called on the filter graph. However, we can't just
5108 * call IBaseFilter::GetState() in one loop and drop the lock on every
5109 * iteration, since the filter list might change beneath us. So instead we
5110 * do what native does, and poll for it every 10 ms. */
5112 EnterCriticalSection(&graph->cs);
5113 *state = graph->state;
5114 expect_state = graph->needs_async_run ? State_Paused : graph->state;
5116 for (;;)
5118 IBaseFilter *async_filter = NULL;
5119 FILTER_STATE filter_state;
5120 struct filter *filter;
5122 hr = S_OK;
5124 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5126 HRESULT filter_hr = IBaseFilter_GetState(filter->filter, 0, &filter_state);
5128 TRACE("Filter %p returned hr %#x, state %u.\n", filter->filter, filter_hr, filter_state);
5130 if (filter_hr == VFW_S_STATE_INTERMEDIATE)
5131 async_filter = filter->filter;
5133 if (hr == S_OK && filter_hr == VFW_S_STATE_INTERMEDIATE)
5134 hr = VFW_S_STATE_INTERMEDIATE;
5135 else if (filter_hr != S_OK && filter_hr != VFW_S_STATE_INTERMEDIATE)
5136 hr = filter_hr;
5138 if (hr == S_OK && filter_state == State_Paused && graph->state != State_Paused)
5140 async_filter = filter->filter;
5141 hr = VFW_S_STATE_INTERMEDIATE;
5143 else if (filter_state != graph->state && filter_state != State_Paused)
5144 hr = E_FAIL;
5146 if (filter_state != expect_state)
5147 ERR("Filter %p reported incorrect state %u (expected %u).\n",
5148 filter->filter, filter_state, expect_state);
5151 LeaveCriticalSection(&graph->cs);
5153 if (hr != VFW_S_STATE_INTERMEDIATE || (timeout != INFINITE && GetTickCount() >= end))
5154 break;
5156 IBaseFilter_GetState(async_filter, 10, &filter_state);
5158 EnterCriticalSection(&graph->cs);
5161 TRACE("Returning %#x, state %u.\n", hr, *state);
5162 return hr;
5165 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5167 struct filter_graph *This = impl_from_IMediaFilter(iface);
5168 struct filter *filter;
5169 HRESULT hr = S_OK;
5171 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
5173 EnterCriticalSection(&This->cs);
5175 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
5177 hr = IBaseFilter_SetSyncSource(filter->filter, pClock);
5178 if (FAILED(hr))
5179 break;
5182 if (FAILED(hr))
5184 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
5185 IBaseFilter_SetSyncSource(filter->filter, This->refClock);
5187 else
5189 if (This->refClock)
5190 IReferenceClock_Release(This->refClock);
5191 This->refClock = pClock;
5192 if (This->refClock)
5193 IReferenceClock_AddRef(This->refClock);
5194 This->defaultclock = FALSE;
5196 if (This->HandleEcClockChanged)
5198 IMediaEventSink *pEventSink;
5199 HRESULT eshr;
5201 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (void **)&pEventSink);
5202 if (SUCCEEDED(eshr))
5204 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5205 IMediaEventSink_Release(pEventSink);
5210 LeaveCriticalSection(&This->cs);
5212 return hr;
5215 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5217 struct filter_graph *This = impl_from_IMediaFilter(iface);
5219 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
5221 if (!ppClock)
5222 return E_POINTER;
5224 EnterCriticalSection(&This->cs);
5226 *ppClock = This->refClock;
5227 if (*ppClock)
5228 IReferenceClock_AddRef(*ppClock);
5230 LeaveCriticalSection(&This->cs);
5232 return S_OK;
5235 static const IMediaFilterVtbl IMediaFilter_VTable =
5237 MediaFilter_QueryInterface,
5238 MediaFilter_AddRef,
5239 MediaFilter_Release,
5240 MediaFilter_GetClassID,
5241 MediaFilter_Stop,
5242 MediaFilter_Pause,
5243 MediaFilter_Run,
5244 MediaFilter_GetState,
5245 MediaFilter_SetSyncSource,
5246 MediaFilter_GetSyncSource
5249 static struct filter_graph *impl_from_IMediaEventSink(IMediaEventSink *iface)
5251 return CONTAINING_RECORD(iface, struct filter_graph, IMediaEventSink_iface);
5254 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID iid, void **out)
5256 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5258 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5261 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5263 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5265 return IUnknown_AddRef(graph->outer_unk);
5268 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5270 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5272 return IUnknown_Release(graph->outer_unk);
5275 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG EventCode,
5276 LONG_PTR EventParam1, LONG_PTR EventParam2)
5278 struct filter_graph *This = impl_from_IMediaEventSink(iface);
5279 Event evt;
5281 TRACE("(%p/%p)->(%d, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5283 /* We need thread safety here, let's use the events queue's one */
5284 EnterCriticalSection(&This->evqueue.msg_crst);
5286 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5288 TRACE("Process EC_COMPLETE notification\n");
5289 if (++This->EcCompleteCount == This->nRenderers)
5291 evt.lEventCode = EC_COMPLETE;
5292 evt.lParam1 = S_OK;
5293 evt.lParam2 = 0;
5294 TRACE("Send EC_COMPLETE to app\n");
5295 EventsQueue_PutEvent(&This->evqueue, &evt);
5296 if (!This->notif.disabled && This->notif.hWnd)
5298 TRACE("Send Window message\n");
5299 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5301 This->CompletionStatus = EC_COMPLETE;
5302 This->got_ec_complete = 1;
5303 SetEvent(This->hEventCompletion);
5306 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5308 /* FIXME: Not handled yet */
5310 else
5312 evt.lEventCode = EventCode;
5313 evt.lParam1 = EventParam1;
5314 evt.lParam2 = EventParam2;
5315 EventsQueue_PutEvent(&This->evqueue, &evt);
5316 if (!This->notif.disabled && This->notif.hWnd)
5317 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5320 LeaveCriticalSection(&This->evqueue.msg_crst);
5321 return S_OK;
5324 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5326 MediaEventSink_QueryInterface,
5327 MediaEventSink_AddRef,
5328 MediaEventSink_Release,
5329 MediaEventSink_Notify
5332 static struct filter_graph *impl_from_IGraphConfig(IGraphConfig *iface)
5334 return CONTAINING_RECORD(iface, struct filter_graph, IGraphConfig_iface);
5337 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID iid, void **out)
5339 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5341 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5344 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5346 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5348 return IUnknown_AddRef(graph->outer_unk);
5351 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5353 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5355 return IUnknown_Release(graph->outer_unk);
5358 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *pOutputPin, IPin *pInputPin,
5359 const AM_MEDIA_TYPE *pmtFirstConnection, IBaseFilter *pUsingFilter, HANDLE hAbortEvent,
5360 DWORD dwFlags)
5362 struct filter_graph *This = impl_from_IGraphConfig(iface);
5364 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5365 strmbase_dump_media_type(pmtFirstConnection);
5367 return E_NOTIMPL;
5370 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface, IGraphConfigCallback *pCallback,
5371 void *pvContext, DWORD dwFlags, HANDLE hAbortEvent)
5373 struct filter_graph *This = impl_from_IGraphConfig(iface);
5374 HRESULT hr;
5376 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5378 if (hAbortEvent)
5379 FIXME("The parameter hAbortEvent is not handled!\n");
5381 EnterCriticalSection(&This->cs);
5383 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5385 LeaveCriticalSection(&This->cs);
5387 return hr;
5390 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5392 struct filter_graph *This = impl_from_IGraphConfig(iface);
5394 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5396 return E_NOTIMPL;
5399 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5401 struct filter_graph *This = impl_from_IGraphConfig(iface);
5403 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5405 return E_NOTIMPL;
5408 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5410 struct filter_graph *This = impl_from_IGraphConfig(iface);
5412 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5414 return E_NOTIMPL;
5417 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5419 struct filter_graph *This = impl_from_IGraphConfig(iface);
5421 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5423 return E_NOTIMPL;
5426 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5427 IPinConnection *pConnection, HANDLE hEventAbort)
5429 struct filter_graph *This = impl_from_IGraphConfig(iface);
5431 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5433 return E_NOTIMPL;
5436 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5437 DWORD dwFlags)
5439 struct filter_graph *This = impl_from_IGraphConfig(iface);
5441 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5443 return E_NOTIMPL;
5446 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5447 DWORD *dwFlags)
5449 struct filter_graph *This = impl_from_IGraphConfig(iface);
5451 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5453 return E_NOTIMPL;
5456 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *pFilter,
5457 DWORD dwFlags)
5459 struct filter_graph *This = impl_from_IGraphConfig(iface);
5461 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5463 return E_NOTIMPL;
5466 static const IGraphConfigVtbl IGraphConfig_VTable =
5468 GraphConfig_QueryInterface,
5469 GraphConfig_AddRef,
5470 GraphConfig_Release,
5471 GraphConfig_Reconnect,
5472 GraphConfig_Reconfigure,
5473 GraphConfig_AddFilterToCache,
5474 GraphConfig_EnumCacheFilter,
5475 GraphConfig_RemoveFilterFromCache,
5476 GraphConfig_GetStartTime,
5477 GraphConfig_PushThroughData,
5478 GraphConfig_SetFilterFlags,
5479 GraphConfig_GetFilterFlags,
5480 GraphConfig_RemoveFilterEx
5483 static struct filter_graph *impl_from_IGraphVersion(IGraphVersion *iface)
5485 return CONTAINING_RECORD(iface, struct filter_graph, IGraphVersion_iface);
5488 static HRESULT WINAPI GraphVersion_QueryInterface(IGraphVersion *iface, REFIID iid, void **out)
5490 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5492 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5495 static ULONG WINAPI GraphVersion_AddRef(IGraphVersion *iface)
5497 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5499 return IUnknown_AddRef(graph->outer_unk);
5502 static ULONG WINAPI GraphVersion_Release(IGraphVersion *iface)
5504 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5506 return IUnknown_Release(graph->outer_unk);
5509 static HRESULT WINAPI GraphVersion_QueryVersion(IGraphVersion *iface, LONG *pVersion)
5511 struct filter_graph *This = impl_from_IGraphVersion(iface);
5513 if(!pVersion)
5514 return E_POINTER;
5516 TRACE("(%p)->(%p): current version %i\n", This, pVersion, This->version);
5518 *pVersion = This->version;
5519 return S_OK;
5522 static const IGraphVersionVtbl IGraphVersion_VTable =
5524 GraphVersion_QueryInterface,
5525 GraphVersion_AddRef,
5526 GraphVersion_Release,
5527 GraphVersion_QueryVersion,
5530 static struct filter_graph *impl_from_IVideoFrameStep(IVideoFrameStep *iface)
5532 return CONTAINING_RECORD(iface, struct filter_graph, IVideoFrameStep_iface);
5535 static HRESULT WINAPI VideoFrameStep_QueryInterface(IVideoFrameStep *iface, REFIID iid, void **out)
5537 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5538 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5541 static ULONG WINAPI VideoFrameStep_AddRef(IVideoFrameStep *iface)
5543 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5544 return IUnknown_AddRef(graph->outer_unk);
5547 static ULONG WINAPI VideoFrameStep_Release(IVideoFrameStep *iface)
5549 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5550 return IUnknown_Release(graph->outer_unk);
5553 static HRESULT WINAPI VideoFrameStep_Step(IVideoFrameStep *iface, DWORD frame_count, IUnknown *filter)
5555 FIXME("iface %p, frame_count %u, filter %p, stub!\n", iface, frame_count, filter);
5556 return E_NOTIMPL;
5559 static HRESULT WINAPI VideoFrameStep_CanStep(IVideoFrameStep *iface, LONG multiple, IUnknown *filter)
5561 FIXME("iface %p, multiple %d, filter %p, stub!\n", iface, multiple, filter);
5562 return E_NOTIMPL;
5565 static HRESULT WINAPI VideoFrameStep_CancelStep(IVideoFrameStep *iface)
5567 FIXME("iface %p, stub!\n", iface);
5568 return E_NOTIMPL;
5571 static const IVideoFrameStepVtbl VideoFrameStep_vtbl =
5573 VideoFrameStep_QueryInterface,
5574 VideoFrameStep_AddRef,
5575 VideoFrameStep_Release,
5576 VideoFrameStep_Step,
5577 VideoFrameStep_CanStep,
5578 VideoFrameStep_CancelStep
5581 static const IUnknownVtbl IInner_VTable =
5583 FilterGraphInner_QueryInterface,
5584 FilterGraphInner_AddRef,
5585 FilterGraphInner_Release
5588 static HRESULT filter_graph_common_create(IUnknown *outer, IUnknown **out, BOOL threaded)
5590 struct filter_graph *object;
5591 HRESULT hr;
5593 *out = NULL;
5595 if (!(object = calloc(1, sizeof(*object))))
5596 return E_OUTOFMEMORY;
5598 object->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5599 object->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5600 object->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5601 object->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5602 object->IGraphVersion_iface.lpVtbl = &IGraphVersion_VTable;
5603 object->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5604 object->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5605 object->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5606 object->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5607 object->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5608 object->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5609 object->IObjectWithSite_iface.lpVtbl = &IObjectWithSite_VTable;
5610 object->IUnknown_inner.lpVtbl = &IInner_VTable;
5611 object->IVideoFrameStep_iface.lpVtbl = &VideoFrameStep_vtbl;
5612 object->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5613 object->ref = 1;
5614 object->outer_unk = outer ? outer : &object->IUnknown_inner;
5616 if (FAILED(hr = CoCreateInstance(&CLSID_FilterMapper2, object->outer_unk,
5617 CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&object->punkFilterMapper2)))
5619 ERR("Failed to create filter mapper, hr %#x.\n", hr);
5620 free(object);
5621 return hr;
5624 InitializeCriticalSection(&object->cs);
5625 object->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": filter_graph.cs");
5627 object->defaultclock = TRUE;
5628 EventsQueue_Init(&object->evqueue);
5629 list_init(&object->filters);
5630 object->HandleEcClockChanged = TRUE;
5631 object->HandleEcComplete = TRUE;
5632 object->HandleEcRepaint = TRUE;
5633 object->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5634 object->name_index = 1;
5635 object->timeformatseek = TIME_FORMAT_MEDIA_TIME;
5637 if (threaded)
5639 object->message_thread_ret = CreateEventW(NULL, FALSE, FALSE, NULL);
5640 object->message_thread = CreateThread(NULL, 0, message_thread_run, object, 0, &object->message_thread_id);
5641 WaitForSingleObject(object->message_thread_ret, INFINITE);
5643 else
5644 object->message_thread = NULL;
5646 TRACE("Created %sthreaded filter graph %p.\n", threaded ? "" : "non-", object);
5647 *out = &object->IUnknown_inner;
5648 return S_OK;
5651 HRESULT filter_graph_create(IUnknown *outer, IUnknown **out)
5653 return filter_graph_common_create(outer, out, TRUE);
5656 HRESULT filter_graph_no_thread_create(IUnknown *outer, IUnknown **out)
5658 return filter_graph_common_create(outer, out, FALSE);