ntdll: Make wine_build a hidden symbol.
[wine.git] / dlls / quartz / filtergraph.c
bloba1f3757a202d52f2cb56aed2b2b02fb6e77cdbea
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 struct media_event
47 struct list entry;
48 LONG code;
49 LONG_PTR param1, param2;
52 #define MAX_ITF_CACHE_ENTRIES 3
53 typedef struct _ITF_CACHE_ENTRY {
54 const IID* riid;
55 IBaseFilter* filter;
56 IUnknown* iface;
57 } ITF_CACHE_ENTRY;
59 struct filter
61 struct list entry;
62 IBaseFilter *filter;
63 IMediaSeeking *seeking;
64 WCHAR *name;
65 BOOL sorting;
68 struct filter_graph
70 IUnknown IUnknown_inner;
71 IFilterGraph2 IFilterGraph2_iface;
72 IMediaControl IMediaControl_iface;
73 IMediaSeeking IMediaSeeking_iface;
74 IBasicAudio IBasicAudio_iface;
75 IBasicVideo2 IBasicVideo2_iface;
76 IVideoWindow IVideoWindow_iface;
77 IMediaEventEx IMediaEventEx_iface;
78 IMediaFilter IMediaFilter_iface;
79 IMediaEventSink IMediaEventSink_iface;
80 IGraphConfig IGraphConfig_iface;
81 IMediaPosition IMediaPosition_iface;
82 IObjectWithSite IObjectWithSite_iface;
83 IGraphVersion IGraphVersion_iface;
84 /* IAMGraphStreams */
85 /* IAMStats */
86 /* IFilterChain */
87 /* IFilterMapper2 */
88 /* IQueueCommand */
89 /* IRegisterServiceProvider */
90 /* IResourceManager */
91 /* IServiceProvider */
92 IVideoFrameStep IVideoFrameStep_iface;
94 IUnknown *outer_unk;
95 LONG ref;
96 IUnknown *punkFilterMapper2;
98 struct list filters;
99 unsigned int name_index;
101 OAFilterState state;
102 TP_WORK *async_run_work;
104 IReferenceClock *refClock;
105 IBaseFilter *refClockProvider;
107 /* We may indirectly wait for streaming threads while holding graph->cs in
108 * IMediaFilter::Stop() or IMediaSeeking::SetPositions(). Since streaming
109 * threads call IMediaEventSink::Notify() to queue EC_COMPLETE, we must
110 * use a separate lock to avoid them deadlocking on graph->cs. */
111 CRITICAL_SECTION event_cs;
112 struct list media_events;
113 HANDLE media_event_handle;
114 HWND media_event_window;
115 UINT media_event_message;
116 LPARAM media_event_lparam;
117 HANDLE hEventCompletion;
118 int CompletionStatus;
119 int nRenderers;
120 int EcCompleteCount;
121 int HandleEcComplete;
122 int HandleEcRepaint;
123 int HandleEcClockChanged;
124 unsigned int got_ec_complete : 1;
125 unsigned int media_events_disabled : 1;
127 CRITICAL_SECTION cs;
128 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
129 int nItfCacheEntries;
130 BOOL defaultclock;
131 GUID timeformatseek;
132 IUnknown *pSite;
133 LONG version;
135 HANDLE message_thread, message_thread_ret;
136 DWORD message_thread_id;
138 /* Respectively: the last timestamp at which we started streaming, and the
139 * current offset within the stream. */
140 REFERENCE_TIME stream_start, stream_elapsed;
141 REFERENCE_TIME stream_stop;
142 LONGLONG current_pos;
144 unsigned int needs_async_run : 1;
147 struct enum_filters
149 IEnumFilters IEnumFilters_iface;
150 LONG ref;
151 struct filter_graph *graph;
152 LONG version;
153 struct list *cursor;
156 static HRESULT create_enum_filters(struct filter_graph *graph, struct list *cursor, IEnumFilters **out);
158 static inline struct enum_filters *impl_from_IEnumFilters(IEnumFilters *iface)
160 return CONTAINING_RECORD(iface, struct enum_filters, IEnumFilters_iface);
163 static HRESULT WINAPI EnumFilters_QueryInterface(IEnumFilters *iface, REFIID iid, void **out)
165 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
166 TRACE("enum_filters %p, iid %s, out %p.\n", enum_filters, qzdebugstr_guid(iid), out);
168 if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IEnumFilters))
170 IEnumFilters_AddRef(*out = iface);
171 return S_OK;
174 WARN("%s not implemented, returning E_NOINTERFACE.\n", qzdebugstr_guid(iid));
175 *out = NULL;
176 return E_NOINTERFACE;
179 static ULONG WINAPI EnumFilters_AddRef(IEnumFilters *iface)
181 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
182 ULONG ref = InterlockedIncrement(&enum_filters->ref);
184 TRACE("%p increasing refcount to %u.\n", enum_filters, ref);
186 return ref;
189 static ULONG WINAPI EnumFilters_Release(IEnumFilters *iface)
191 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
192 ULONG ref = InterlockedDecrement(&enum_filters->ref);
194 TRACE("%p decreasing refcount to %u.\n", enum_filters, ref);
196 if (!ref)
198 IUnknown_Release(enum_filters->graph->outer_unk);
199 heap_free(enum_filters);
202 return ref;
205 static HRESULT WINAPI EnumFilters_Next(IEnumFilters *iface, ULONG count,
206 IBaseFilter **filters, ULONG *fetched)
208 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
209 unsigned int i = 0;
211 TRACE("enum_filters %p, count %u, filters %p, fetched %p.\n",
212 enum_filters, count, filters, fetched);
214 if (enum_filters->version != enum_filters->graph->version)
215 return VFW_E_ENUM_OUT_OF_SYNC;
217 if (!filters)
218 return E_POINTER;
220 for (i = 0; i < count; ++i)
222 struct filter *filter = LIST_ENTRY(enum_filters->cursor, struct filter, entry);
224 if (!enum_filters->cursor)
225 break;
227 IBaseFilter_AddRef(filters[i] = filter->filter);
228 enum_filters->cursor = list_next(&enum_filters->graph->filters, enum_filters->cursor);
231 if (fetched)
232 *fetched = i;
234 return (i == count) ? S_OK : S_FALSE;
237 static HRESULT WINAPI EnumFilters_Skip(IEnumFilters *iface, ULONG count)
239 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
241 TRACE("enum_filters %p, count %u.\n", enum_filters, count);
243 if (enum_filters->version != enum_filters->graph->version)
244 return VFW_E_ENUM_OUT_OF_SYNC;
246 if (!enum_filters->cursor)
247 return E_INVALIDARG;
249 while (count--)
251 if (!(enum_filters->cursor = list_next(&enum_filters->graph->filters, enum_filters->cursor)))
252 return count ? S_FALSE : S_OK;
255 return S_OK;
258 static HRESULT WINAPI EnumFilters_Reset(IEnumFilters *iface)
260 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
262 TRACE("enum_filters %p.\n", enum_filters);
264 enum_filters->cursor = list_head(&enum_filters->graph->filters);
265 enum_filters->version = enum_filters->graph->version;
266 return S_OK;
269 static HRESULT WINAPI EnumFilters_Clone(IEnumFilters *iface, IEnumFilters **out)
271 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
273 TRACE("enum_filters %p, out %p.\n", enum_filters, out);
275 return create_enum_filters(enum_filters->graph, enum_filters->cursor, out);
278 static const IEnumFiltersVtbl EnumFilters_vtbl =
280 EnumFilters_QueryInterface,
281 EnumFilters_AddRef,
282 EnumFilters_Release,
283 EnumFilters_Next,
284 EnumFilters_Skip,
285 EnumFilters_Reset,
286 EnumFilters_Clone,
289 static HRESULT create_enum_filters(struct filter_graph *graph, struct list *cursor, IEnumFilters **out)
291 struct enum_filters *enum_filters;
293 if (!(enum_filters = heap_alloc(sizeof(*enum_filters))))
294 return E_OUTOFMEMORY;
296 enum_filters->IEnumFilters_iface.lpVtbl = &EnumFilters_vtbl;
297 enum_filters->ref = 1;
298 enum_filters->cursor = cursor;
299 enum_filters->graph = graph;
300 IUnknown_AddRef(graph->outer_unk);
301 enum_filters->version = graph->version;
303 *out = &enum_filters->IEnumFilters_iface;
304 return S_OK;
307 static BOOL queue_media_event(struct filter_graph *graph, LONG code,
308 LONG_PTR param1, LONG_PTR param2)
310 struct media_event *event;
312 if (!(event = malloc(sizeof(*event))))
313 return FALSE;
315 event->code = code;
316 event->param1 = param1;
317 event->param2 = param2;
318 list_add_tail(&graph->media_events, &event->entry);
320 SetEvent(graph->media_event_handle);
321 if (graph->media_event_window)
322 PostMessageW(graph->media_event_window, graph->media_event_message, 0, graph->media_event_lparam);
324 return TRUE;
327 static void flush_media_events(struct filter_graph *graph)
329 struct list *cursor;
331 while ((cursor = list_head(&graph->media_events)))
333 struct media_event *event = LIST_ENTRY(cursor, struct media_event, entry);
335 list_remove(&event->entry);
336 free(event);
340 static struct filter_graph *impl_from_IUnknown(IUnknown *iface)
342 return CONTAINING_RECORD(iface, struct filter_graph, IUnknown_inner);
345 static HRESULT WINAPI FilterGraphInner_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObj)
347 struct filter_graph *This = impl_from_IUnknown(iface);
348 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObj);
350 if (IsEqualGUID(&IID_IUnknown, riid)) {
351 *ppvObj = &This->IUnknown_inner;
352 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
353 } else if (IsEqualGUID(&IID_IFilterGraph, riid) ||
354 IsEqualGUID(&IID_IFilterGraph2, riid) ||
355 IsEqualGUID(&IID_IGraphBuilder, riid)) {
356 *ppvObj = &This->IFilterGraph2_iface;
357 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj);
358 } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
359 *ppvObj = &This->IMediaControl_iface;
360 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj);
361 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
362 *ppvObj = &This->IMediaSeeking_iface;
363 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
364 } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
365 *ppvObj = &This->IBasicAudio_iface;
366 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj);
367 } else if (IsEqualGUID(&IID_IBasicVideo, riid) ||
368 IsEqualGUID(&IID_IBasicVideo2, riid)) {
369 *ppvObj = &This->IBasicVideo2_iface;
370 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj);
371 } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
372 *ppvObj = &This->IVideoWindow_iface;
373 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj);
374 } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
375 IsEqualGUID(&IID_IMediaEventEx, riid)) {
376 *ppvObj = &This->IMediaEventEx_iface;
377 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
378 } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
379 IsEqualGUID(&IID_IPersist, riid)) {
380 *ppvObj = &This->IMediaFilter_iface;
381 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj);
382 } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
383 *ppvObj = &This->IMediaEventSink_iface;
384 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj);
385 } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
386 *ppvObj = &This->IGraphConfig_iface;
387 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
388 } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
389 *ppvObj = &This->IMediaPosition_iface;
390 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj);
391 } else if (IsEqualGUID(&IID_IObjectWithSite, riid)) {
392 *ppvObj = &This->IObjectWithSite_iface;
393 TRACE(" returning IObjectWithSite interface (%p)\n", *ppvObj);
394 } else if (IsEqualGUID(&IID_IFilterMapper, riid)) {
395 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj);
396 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
397 } else if (IsEqualGUID(&IID_IFilterMapper2, riid)) {
398 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
399 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
400 } else if (IsEqualGUID(&IID_IFilterMapper3, riid)) {
401 TRACE(" returning IFilterMapper3 interface from aggregated filtermapper (%p)\n", *ppvObj);
402 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
403 } else if (IsEqualGUID(&IID_IGraphVersion, riid)) {
404 *ppvObj = &This->IGraphVersion_iface;
405 TRACE(" returning IGraphVersion interface (%p)\n", *ppvObj);
406 } else if (IsEqualGUID(&IID_IVideoFrameStep, riid)) {
407 *ppvObj = &This->IVideoFrameStep_iface;
408 TRACE(" returning IVideoFrameStep interface (%p)\n", *ppvObj);
409 } else {
410 *ppvObj = NULL;
411 FIXME("unknown interface %s\n", debugstr_guid(riid));
412 return E_NOINTERFACE;
415 IUnknown_AddRef((IUnknown *)*ppvObj);
416 return S_OK;
419 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown *iface)
421 struct filter_graph *This = impl_from_IUnknown(iface);
422 ULONG ref = InterlockedIncrement(&This->ref);
424 TRACE("(%p)->(): new ref = %d\n", This, ref);
426 return ref;
429 static ULONG WINAPI FilterGraphInner_Release(IUnknown *iface)
431 struct filter_graph *This = impl_from_IUnknown(iface);
432 ULONG ref = InterlockedDecrement(&This->ref);
433 struct list *cursor;
435 TRACE("(%p)->(): new ref = %d\n", This, ref);
437 if (ref == 0) {
438 int i;
440 This->ref = 1; /* guard against reentrancy (aggregation). */
442 IMediaControl_Stop(&This->IMediaControl_iface);
444 while ((cursor = list_head(&This->filters)))
446 struct filter *filter = LIST_ENTRY(cursor, struct filter, entry);
448 IFilterGraph2_RemoveFilter(&This->IFilterGraph2_iface, filter->filter);
451 if (This->refClock)
452 IReferenceClock_Release(This->refClock);
454 for (i = 0; i < This->nItfCacheEntries; i++)
456 if (This->ItfCacheEntries[i].iface)
457 IUnknown_Release(This->ItfCacheEntries[i].iface);
460 IUnknown_Release(This->punkFilterMapper2);
462 if (This->pSite) IUnknown_Release(This->pSite);
464 flush_media_events(This);
465 CloseHandle(This->media_event_handle);
467 This->cs.DebugInfo->Spare[0] = 0;
468 if (This->message_thread)
470 PostThreadMessageW(This->message_thread_id, WM_USER + 1, 0, 0);
471 WaitForSingleObject(This->message_thread, INFINITE);
472 CloseHandle(This->message_thread);
473 CloseHandle(This->message_thread_ret);
475 DeleteCriticalSection(&This->event_cs);
476 DeleteCriticalSection(&This->cs);
477 free(This);
479 InterlockedDecrement(&object_locks);
481 return ref;
484 static struct filter_graph *impl_from_IFilterGraph2(IFilterGraph2 *iface)
486 return CONTAINING_RECORD(iface, struct filter_graph, IFilterGraph2_iface);
489 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface, REFIID iid, void **out)
491 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
492 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
495 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface)
497 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
498 return IUnknown_AddRef(graph->outer_unk);
501 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface)
503 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
504 return IUnknown_Release(graph->outer_unk);
507 static IBaseFilter *find_filter_by_name(struct filter_graph *graph, const WCHAR *name)
509 struct filter *filter;
511 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
513 if (!wcscmp(filter->name, name))
514 return filter->filter;
517 return NULL;
520 static BOOL has_output_pins(IBaseFilter *filter)
522 IEnumPins *enumpins;
523 PIN_DIRECTION dir;
524 IPin *pin;
526 if (FAILED(IBaseFilter_EnumPins(filter, &enumpins)))
527 return FALSE;
529 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
531 IPin_QueryDirection(pin, &dir);
532 IPin_Release(pin);
533 if (dir == PINDIR_OUTPUT)
535 IEnumPins_Release(enumpins);
536 return TRUE;
540 IEnumPins_Release(enumpins);
541 return FALSE;
544 static void update_seeking(struct filter *filter)
546 IMediaSeeking *seeking;
548 if (!filter->seeking)
550 /* The Legend of Heroes: Trails of Cold Steel II destroys its filter when
551 * its IMediaSeeking interface is released, so cache the interface instead
552 * of querying for it every time.
553 * Some filters (e.g. MediaStreamFilter) can become seekable when they are
554 * already in the graph, so always try to query IMediaSeeking if it's not
555 * cached yet. */
556 if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IMediaSeeking, (void **)&seeking)))
558 if (IMediaSeeking_IsFormatSupported(seeking, &TIME_FORMAT_MEDIA_TIME) == S_OK)
559 filter->seeking = seeking;
560 else
561 IMediaSeeking_Release(seeking);
566 static BOOL is_renderer(struct filter *filter)
568 IMediaPosition *media_position;
569 IAMFilterMiscFlags *flags;
570 BOOL ret = FALSE;
572 if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IAMFilterMiscFlags, (void **)&flags)))
574 if (IAMFilterMiscFlags_GetMiscFlags(flags) & AM_FILTER_MISC_FLAGS_IS_RENDERER)
575 ret = TRUE;
576 IAMFilterMiscFlags_Release(flags);
578 else if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IMediaPosition, (void **)&media_position)))
580 if (!has_output_pins(filter->filter))
581 ret = TRUE;
582 IMediaPosition_Release(media_position);
584 else
586 update_seeking(filter);
587 if (filter->seeking && !has_output_pins(filter->filter))
588 ret = TRUE;
590 return ret;
593 /*** IFilterGraph methods ***/
594 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface,
595 IBaseFilter *filter, const WCHAR *name)
597 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
598 BOOL duplicate_name = FALSE;
599 struct filter *entry;
600 unsigned int i;
601 HRESULT hr;
603 TRACE("graph %p, filter %p, name %s.\n", graph, filter, debugstr_w(name));
605 if (!filter)
606 return E_POINTER;
608 if (!(entry = heap_alloc(sizeof(*entry))))
609 return E_OUTOFMEMORY;
611 if (!(entry->name = CoTaskMemAlloc((name ? wcslen(name) + 6 : 5) * sizeof(WCHAR))))
613 heap_free(entry);
614 return E_OUTOFMEMORY;
617 if (name && find_filter_by_name(graph, name))
618 duplicate_name = TRUE;
620 if (!name || duplicate_name)
622 for (i = 0; i < 10000 ; ++i)
624 if (name)
625 swprintf(entry->name, name ? wcslen(name) + 6 : 5, L"%s %04u", name, graph->name_index);
626 else
627 swprintf(entry->name, name ? wcslen(name) + 6 : 5, L"%04u", graph->name_index);
629 graph->name_index = (graph->name_index + 1) % 10000;
631 if (!find_filter_by_name(graph, entry->name))
632 break;
635 if (i == 10000)
637 CoTaskMemFree(entry->name);
638 heap_free(entry);
639 return VFW_E_DUPLICATE_NAME;
642 else
643 wcscpy(entry->name, name);
645 if (FAILED(hr = IBaseFilter_JoinFilterGraph(filter,
646 (IFilterGraph *)&graph->IFilterGraph2_iface, entry->name)))
648 CoTaskMemFree(entry->name);
649 heap_free(entry);
650 return hr;
653 IBaseFilter_AddRef(entry->filter = filter);
655 list_add_head(&graph->filters, &entry->entry);
656 entry->sorting = FALSE;
657 entry->seeking = NULL;
658 ++graph->version;
660 return duplicate_name ? VFW_S_DUPLICATE_NAME : hr;
663 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
665 struct filter_graph *This = impl_from_IFilterGraph2(iface);
666 struct filter *entry;
667 int i;
668 HRESULT hr = E_FAIL;
670 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
672 LIST_FOR_EACH_ENTRY(entry, &This->filters, struct filter, entry)
674 if (entry->filter == pFilter)
676 IEnumPins *penumpins = NULL;
678 if (This->defaultclock && This->refClockProvider == pFilter)
680 IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, NULL);
681 This->defaultclock = TRUE;
684 TRACE("Removing filter %s.\n", debugstr_w(entry->name));
686 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
687 if (SUCCEEDED(hr)) {
688 IPin *ppin;
689 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
691 IPin *peer = NULL;
692 HRESULT hr;
694 IPin_ConnectedTo(ppin, &peer);
695 if (peer)
697 if (FAILED(hr = IPin_Disconnect(peer)))
699 WARN("Failed to disconnect peer %p, hr %#x.\n", peer, hr);
700 IPin_Release(peer);
701 IPin_Release(ppin);
702 IEnumPins_Release(penumpins);
703 return hr;
705 IPin_Release(peer);
707 if (FAILED(hr = IPin_Disconnect(ppin)))
709 WARN("Failed to disconnect pin %p, hr %#x.\n", ppin, hr);
710 IPin_Release(ppin);
711 IEnumPins_Release(penumpins);
712 return hr;
715 IPin_Release(ppin);
717 IEnumPins_Release(penumpins);
720 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, NULL);
721 if (SUCCEEDED(hr))
723 IBaseFilter_SetSyncSource(pFilter, NULL);
724 IBaseFilter_Release(pFilter);
725 if (entry->seeking)
726 IMediaSeeking_Release(entry->seeking);
727 list_remove(&entry->entry);
728 CoTaskMemFree(entry->name);
729 heap_free(entry);
730 This->version++;
731 /* Invalidate interfaces in the cache */
732 for (i = 0; i < This->nItfCacheEntries; i++)
733 if (pFilter == This->ItfCacheEntries[i].filter)
735 IUnknown_Release(This->ItfCacheEntries[i].iface);
736 This->ItfCacheEntries[i].iface = NULL;
737 This->ItfCacheEntries[i].filter = NULL;
739 return S_OK;
741 break;
745 return hr; /* FIXME: check this error code */
748 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface, IEnumFilters **out)
750 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
752 TRACE("graph %p, out %p.\n", graph, out);
754 return create_enum_filters(graph, list_head(&graph->filters), out);
757 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface,
758 const WCHAR *name, IBaseFilter **filter)
760 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
762 TRACE("graph %p, name %s, filter %p.\n", graph, debugstr_w(name), filter);
764 if (!filter)
765 return E_POINTER;
767 if ((*filter = find_filter_by_name(graph, name)))
769 IBaseFilter_AddRef(*filter);
770 return S_OK;
773 return VFW_E_NOT_FOUND;
776 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
777 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
779 static HRESULT CheckCircularConnection(struct filter_graph *This, IPin *out, IPin *in)
781 #if 1
782 HRESULT hr;
783 PIN_INFO info_out, info_in;
785 hr = IPin_QueryPinInfo(out, &info_out);
786 if (FAILED(hr))
787 return hr;
788 if (info_out.dir != PINDIR_OUTPUT)
790 IBaseFilter_Release(info_out.pFilter);
791 return VFW_E_CANNOT_CONNECT;
794 hr = IPin_QueryPinInfo(in, &info_in);
795 if (SUCCEEDED(hr))
796 IBaseFilter_Release(info_in.pFilter);
797 if (FAILED(hr))
798 goto out;
799 if (info_in.dir != PINDIR_INPUT)
801 hr = VFW_E_CANNOT_CONNECT;
802 goto out;
805 if (info_out.pFilter == info_in.pFilter)
806 hr = VFW_E_CIRCULAR_GRAPH;
807 else
809 IEnumPins *enumpins;
810 IPin *test;
812 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
813 if (FAILED(hr))
814 goto out;
816 IEnumPins_Reset(enumpins);
817 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
819 PIN_DIRECTION dir = PINDIR_OUTPUT;
820 IPin_QueryDirection(test, &dir);
821 if (dir == PINDIR_INPUT)
823 IPin *victim = NULL;
824 IPin_ConnectedTo(test, &victim);
825 if (victim)
827 hr = CheckCircularConnection(This, victim, in);
828 IPin_Release(victim);
829 if (FAILED(hr))
831 IPin_Release(test);
832 break;
836 IPin_Release(test);
838 IEnumPins_Release(enumpins);
841 out:
842 IBaseFilter_Release(info_out.pFilter);
843 if (FAILED(hr))
844 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
845 return hr;
846 #else
847 /* Debugging filtergraphs not enabled */
848 return S_OK;
849 #endif
852 static struct filter *find_sorted_filter(struct filter_graph *graph, IBaseFilter *iface)
854 struct filter *filter;
856 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
858 if (filter->filter == iface)
859 return filter;
862 return NULL;
865 static void sort_filter_recurse(struct filter_graph *graph, struct filter *filter, struct list *sorted)
867 struct filter *peer_filter;
868 IEnumPins *enumpins;
869 PIN_DIRECTION dir;
870 IPin *pin, *peer;
871 PIN_INFO info;
873 TRACE("Sorting filter %p.\n", filter->filter);
875 /* Cyclic connections should be caught by CheckCircularConnection(). */
876 assert(!filter->sorting);
878 filter->sorting = TRUE;
880 IBaseFilter_EnumPins(filter->filter, &enumpins);
881 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
883 IPin_QueryDirection(pin, &dir);
885 if (dir == PINDIR_INPUT && IPin_ConnectedTo(pin, &peer) == S_OK)
887 IPin_QueryPinInfo(peer, &info);
888 /* Note that the filter may have already been sorted. */
889 if ((peer_filter = find_sorted_filter(graph, info.pFilter)))
890 sort_filter_recurse(graph, peer_filter, sorted);
891 IBaseFilter_Release(info.pFilter);
892 IPin_Release(peer);
894 IPin_Release(pin);
896 IEnumPins_Release(enumpins);
898 filter->sorting = FALSE;
900 list_remove(&filter->entry);
901 list_add_head(sorted, &filter->entry);
904 static void sort_filters(struct filter_graph *graph)
906 struct list sorted = LIST_INIT(sorted), *cursor;
908 while ((cursor = list_head(&graph->filters)))
910 struct filter *filter = LIST_ENTRY(cursor, struct filter, entry);
911 sort_filter_recurse(graph, filter, &sorted);
914 list_move_tail(&graph->filters, &sorted);
917 /* NOTE: despite the implication, it doesn't matter which
918 * way round you put in the input and output pins */
919 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppinIn, IPin *ppinOut,
920 const AM_MEDIA_TYPE *pmt)
922 struct filter_graph *This = impl_from_IFilterGraph2(iface);
923 PIN_DIRECTION dir;
924 HRESULT hr;
926 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
927 strmbase_dump_media_type(pmt);
929 /* FIXME: check pins are in graph */
931 if (TRACE_ON(quartz))
933 PIN_INFO PinInfo;
935 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
936 if (FAILED(hr))
937 return hr;
939 TRACE("Filter owning ppinIn(%p) => %p\n", ppinIn, PinInfo.pFilter);
940 IBaseFilter_Release(PinInfo.pFilter);
942 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
943 if (FAILED(hr))
944 return hr;
946 TRACE("Filter owning ppinOut(%p) => %p\n", ppinOut, PinInfo.pFilter);
947 IBaseFilter_Release(PinInfo.pFilter);
950 hr = IPin_QueryDirection(ppinIn, &dir);
951 if (SUCCEEDED(hr))
953 if (dir == PINDIR_INPUT)
955 hr = CheckCircularConnection(This, ppinOut, ppinIn);
956 if (SUCCEEDED(hr))
957 hr = IPin_Connect(ppinOut, ppinIn, pmt);
959 else
961 hr = CheckCircularConnection(This, ppinIn, ppinOut);
962 if (SUCCEEDED(hr))
963 hr = IPin_Connect(ppinIn, ppinOut, pmt);
967 return hr;
970 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface, IPin *pin)
972 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
974 TRACE("graph %p, pin %p.\n", graph, pin);
976 return IFilterGraph2_ReconnectEx(iface, pin, NULL);
979 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
981 struct filter_graph *This = impl_from_IFilterGraph2(iface);
983 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
985 if (!ppin)
986 return E_POINTER;
988 return IPin_Disconnect(ppin);
991 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
993 struct filter_graph *This = impl_from_IFilterGraph2(iface);
994 IReferenceClock *pClock = NULL;
995 struct filter *filter;
996 HRESULT hr = S_OK;
998 TRACE("(%p/%p)->() live sources not handled properly!\n", This, iface);
1000 EnterCriticalSection(&This->cs);
1002 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
1004 if (IBaseFilter_QueryInterface(filter->filter, &IID_IReferenceClock, (void **)&pClock) == S_OK)
1005 break;
1008 if (!pClock)
1010 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
1011 This->refClockProvider = NULL;
1013 else
1015 filter = LIST_ENTRY(list_tail(&This->filters), struct filter, entry);
1016 This->refClockProvider = filter->filter;
1019 if (SUCCEEDED(hr))
1021 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
1022 This->defaultclock = TRUE;
1023 IReferenceClock_Release(pClock);
1025 LeaveCriticalSection(&This->cs);
1027 return hr;
1030 struct filter_create_params
1032 HRESULT hr;
1033 IMoniker *moniker;
1034 IBaseFilter *filter;
1037 static DWORD WINAPI message_thread_run(void *ctx)
1039 struct filter_graph *graph = ctx;
1040 MSG msg;
1042 /* Make sure we have a message queue. */
1043 PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE);
1044 SetEvent(graph->message_thread_ret);
1046 CoInitializeEx(NULL, COINIT_MULTITHREADED);
1048 for (;;)
1050 GetMessageW(&msg, NULL, 0, 0);
1052 if (!msg.hwnd && msg.message == WM_USER)
1054 struct filter_create_params *params = (struct filter_create_params *)msg.wParam;
1056 params->hr = IMoniker_BindToObject(params->moniker, NULL, NULL,
1057 &IID_IBaseFilter, (void **)&params->filter);
1058 SetEvent(graph->message_thread_ret);
1060 else if (!msg.hwnd && msg.message == WM_USER + 1)
1062 break;
1064 else
1066 TranslateMessage(&msg);
1067 DispatchMessageW(&msg);
1071 CoUninitialize();
1072 return 0;
1075 static HRESULT create_filter(struct filter_graph *graph, IMoniker *moniker, IBaseFilter **filter)
1077 if (graph->message_thread)
1079 struct filter_create_params params;
1081 params.moniker = moniker;
1082 PostThreadMessageW(graph->message_thread_id, WM_USER, (WPARAM)&params, 0);
1083 WaitForSingleObject(graph->message_thread_ret, INFINITE);
1084 *filter = params.filter;
1085 return params.hr;
1087 else
1088 return IMoniker_BindToObject(moniker, NULL, NULL, &IID_IBaseFilter, (void **)filter);
1091 static HRESULT autoplug(struct filter_graph *graph, IPin *source, IPin *sink,
1092 BOOL render_to_existing, unsigned int recursion_depth);
1094 static HRESULT autoplug_through_sink(struct filter_graph *graph, IPin *source,
1095 IBaseFilter *filter, IPin *middle_sink, IPin *sink,
1096 BOOL render_to_existing, unsigned int recursion_depth)
1098 BOOL any = FALSE, all = TRUE;
1099 IPin *middle_source, *peer;
1100 IEnumPins *source_enum;
1101 PIN_DIRECTION dir;
1102 PIN_INFO info;
1103 HRESULT hr;
1105 TRACE("Trying to autoplug %p to %p through %p.\n", source, sink, middle_sink);
1107 IPin_QueryDirection(middle_sink, &dir);
1108 if (dir != PINDIR_INPUT)
1109 return E_FAIL;
1111 if (IPin_ConnectedTo(middle_sink, &peer) == S_OK)
1113 IPin_Release(peer);
1114 return E_FAIL;
1117 if (FAILED(hr = IFilterGraph2_ConnectDirect(&graph->IFilterGraph2_iface, source, middle_sink, NULL)))
1118 return E_FAIL;
1120 if (FAILED(hr = IBaseFilter_EnumPins(filter, &source_enum)))
1121 goto err;
1123 while (IEnumPins_Next(source_enum, 1, &middle_source, NULL) == S_OK)
1125 IPin_QueryPinInfo(middle_source, &info);
1126 IBaseFilter_Release(info.pFilter);
1127 if (info.dir != PINDIR_OUTPUT)
1129 IPin_Release(middle_source);
1130 continue;
1132 if (info.achName[0] == '~')
1134 TRACE("Skipping non-rendered pin %s.\n", debugstr_w(info.achName));
1135 IPin_Release(middle_source);
1136 continue;
1138 if (IPin_ConnectedTo(middle_source, &peer) == S_OK)
1140 IPin_Release(peer);
1141 IPin_Release(middle_source);
1142 continue;
1145 hr = autoplug(graph, middle_source, sink, render_to_existing, recursion_depth + 1);
1146 IPin_Release(middle_source);
1147 if (SUCCEEDED(hr) && sink)
1149 IEnumPins_Release(source_enum);
1150 return hr;
1152 if (SUCCEEDED(hr))
1153 any = TRUE;
1154 if (hr != S_OK)
1155 all = FALSE;
1157 IEnumPins_Release(source_enum);
1159 if (!sink)
1161 if (all)
1162 return S_OK;
1163 if (any)
1164 return VFW_S_PARTIAL_RENDER;
1167 err:
1168 IFilterGraph2_Disconnect(&graph->IFilterGraph2_iface, source);
1169 IFilterGraph2_Disconnect(&graph->IFilterGraph2_iface, middle_sink);
1170 return E_FAIL;
1173 static HRESULT autoplug_through_filter(struct filter_graph *graph, IPin *source,
1174 IBaseFilter *filter, IPin *sink, BOOL render_to_existing,
1175 unsigned int recursion_depth)
1177 IEnumPins *sink_enum;
1178 IPin *filter_sink;
1179 HRESULT hr;
1181 TRACE("Trying to autoplug %p to %p through %p.\n", source, sink, filter);
1183 if (FAILED(hr = IBaseFilter_EnumPins(filter, &sink_enum)))
1184 return hr;
1186 while (IEnumPins_Next(sink_enum, 1, &filter_sink, NULL) == S_OK)
1188 hr = autoplug_through_sink(graph, source, filter, filter_sink, sink,
1189 render_to_existing, recursion_depth);
1190 IPin_Release(filter_sink);
1191 if (SUCCEEDED(hr))
1193 IEnumPins_Release(sink_enum);
1194 return hr;
1197 IEnumPins_Release(sink_enum);
1198 return VFW_E_CANNOT_CONNECT;
1201 /* Common helper for IGraphBuilder::Connect() and IGraphBuilder::Render(), which
1202 * share most of the same code. Render() calls this with a NULL sink. */
1203 static HRESULT autoplug(struct filter_graph *graph, IPin *source, IPin *sink,
1204 BOOL render_to_existing, unsigned int recursion_depth)
1206 IAMGraphBuilderCallback *callback = NULL;
1207 IEnumMediaTypes *enummt;
1208 IFilterMapper2 *mapper;
1209 struct filter *filter;
1210 AM_MEDIA_TYPE *mt;
1211 HRESULT hr;
1213 TRACE("Trying to autoplug %p to %p, recursion depth %u.\n", source, sink, recursion_depth);
1215 if (recursion_depth >= 5)
1217 WARN("Recursion depth has reached 5; aborting.\n");
1218 return VFW_E_CANNOT_CONNECT;
1221 if (sink)
1223 /* Try to connect directly to this sink. */
1224 hr = IFilterGraph2_ConnectDirect(&graph->IFilterGraph2_iface, source, sink, NULL);
1226 /* If direct connection succeeded, we should propagate that return value.
1227 * If it returned VFW_E_NOT_CONNECTED or VFW_E_NO_AUDIO_HARDWARE, then don't
1228 * even bother trying intermediate filters, since they won't succeed. */
1229 if (SUCCEEDED(hr) || hr == VFW_E_NOT_CONNECTED || hr == VFW_E_NO_AUDIO_HARDWARE)
1230 return hr;
1233 /* Always prefer filters in the graph. */
1234 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1236 if (SUCCEEDED(hr = autoplug_through_filter(graph, source, filter->filter,
1237 sink, render_to_existing, recursion_depth)))
1238 return hr;
1241 IUnknown_QueryInterface(graph->punkFilterMapper2, &IID_IFilterMapper2, (void **)&mapper);
1243 if (FAILED(hr = IPin_EnumMediaTypes(source, &enummt)))
1245 IFilterMapper2_Release(mapper);
1246 return hr;
1249 if (graph->pSite)
1250 IUnknown_QueryInterface(graph->pSite, &IID_IAMGraphBuilderCallback, (void **)&callback);
1252 while (IEnumMediaTypes_Next(enummt, 1, &mt, NULL) == S_OK)
1254 GUID types[2] = {mt->majortype, mt->subtype};
1255 IEnumMoniker *enummoniker;
1256 IBaseFilter *filter;
1257 IMoniker *moniker;
1259 DeleteMediaType(mt);
1261 if (FAILED(hr = IFilterMapper2_EnumMatchingFilters(mapper, &enummoniker,
1262 0, FALSE, MERIT_UNLIKELY, TRUE, 1, types, NULL, NULL, FALSE,
1263 render_to_existing, 0, NULL, NULL, NULL)))
1264 goto out;
1266 while (IEnumMoniker_Next(enummoniker, 1, &moniker, NULL) == S_OK)
1268 IPropertyBag *bag;
1269 VARIANT var;
1271 VariantInit(&var);
1272 IMoniker_BindToStorage(moniker, NULL, NULL, &IID_IPropertyBag, (void **)&bag);
1273 hr = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL);
1274 IPropertyBag_Release(bag);
1275 if (FAILED(hr))
1277 IMoniker_Release(moniker);
1278 continue;
1281 if (callback && FAILED(hr = IAMGraphBuilderCallback_SelectedFilter(callback, moniker)))
1283 TRACE("Filter rejected by IAMGraphBuilderCallback::SelectedFilter(), hr %#x.\n", hr);
1284 IMoniker_Release(moniker);
1285 continue;
1288 hr = create_filter(graph, moniker, &filter);
1289 IMoniker_Release(moniker);
1290 if (FAILED(hr))
1292 ERR("Failed to create filter for %s, hr %#x.\n", debugstr_w(V_BSTR(&var)), hr);
1293 VariantClear(&var);
1294 continue;
1297 if (callback && FAILED(hr = IAMGraphBuilderCallback_CreatedFilter(callback, filter)))
1299 TRACE("Filter rejected by IAMGraphBuilderCallback::CreatedFilter(), hr %#x.\n", hr);
1300 IBaseFilter_Release(filter);
1301 continue;
1304 hr = IFilterGraph2_AddFilter(&graph->IFilterGraph2_iface, filter, V_BSTR(&var));
1305 VariantClear(&var);
1306 if (FAILED(hr))
1308 ERR("Failed to add filter, hr %#x.\n", hr);
1309 IBaseFilter_Release(filter);
1310 continue;
1313 hr = autoplug_through_filter(graph, source, filter, sink, render_to_existing, recursion_depth);
1314 if (SUCCEEDED(hr))
1316 IBaseFilter_Release(filter);
1317 goto out;
1320 IFilterGraph2_RemoveFilter(&graph->IFilterGraph2_iface, filter);
1321 IBaseFilter_Release(filter);
1323 IEnumMoniker_Release(enummoniker);
1326 hr = VFW_E_CANNOT_CONNECT;
1328 out:
1329 if (callback) IAMGraphBuilderCallback_Release(callback);
1330 IEnumMediaTypes_Release(enummt);
1331 IFilterMapper2_Release(mapper);
1332 return hr;
1335 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *source, IPin *sink)
1337 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1338 PIN_DIRECTION dir;
1339 HRESULT hr;
1341 TRACE("graph %p, source %p, sink %p.\n", graph, source, sink);
1343 if (!source || !sink)
1344 return E_POINTER;
1346 if (FAILED(hr = IPin_QueryDirection(source, &dir)))
1347 return hr;
1349 if (dir == PINDIR_INPUT)
1351 IPin *temp;
1353 TRACE("Directions seem backwards, swapping pins\n");
1355 temp = sink;
1356 sink = source;
1357 source = temp;
1360 EnterCriticalSection(&graph->cs);
1362 hr = autoplug(graph, source, sink, TRUE, 0);
1364 LeaveCriticalSection(&graph->cs);
1366 TRACE("Returning %#x.\n", hr);
1367 return hr;
1370 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *source)
1372 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1373 HRESULT hr;
1375 TRACE("graph %p, source %p.\n", graph, source);
1377 EnterCriticalSection(&graph->cs);
1378 hr = autoplug(graph, source, NULL, FALSE, 0);
1379 LeaveCriticalSection(&graph->cs);
1380 if (hr == VFW_E_CANNOT_CONNECT)
1381 hr = VFW_E_CANNOT_RENDER;
1383 TRACE("Returning %#x.\n", hr);
1384 return hr;
1387 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface, LPCWSTR lpcwstrFile,
1388 LPCWSTR lpcwstrPlayList)
1390 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1391 IBaseFilter* preader = NULL;
1392 IPin* ppinreader = NULL;
1393 IEnumPins* penumpins = NULL;
1394 struct filter *filter;
1395 HRESULT hr;
1396 BOOL partial = FALSE;
1397 BOOL any = FALSE;
1399 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1401 if (lpcwstrPlayList != NULL)
1402 return E_INVALIDARG;
1404 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, L"Reader", &preader);
1405 if (FAILED(hr))
1406 return hr;
1408 hr = IBaseFilter_EnumPins(preader, &penumpins);
1409 if (SUCCEEDED(hr))
1411 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1413 PIN_DIRECTION dir;
1415 IPin_QueryDirection(ppinreader, &dir);
1416 if (dir == PINDIR_OUTPUT)
1418 hr = IFilterGraph2_Render(iface, ppinreader);
1420 TRACE("Filters in chain:\n");
1421 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
1422 TRACE("- %s.\n", debugstr_w(filter->name));
1424 if (SUCCEEDED(hr))
1425 any = TRUE;
1426 if (hr != S_OK)
1427 partial = TRUE;
1429 IPin_Release(ppinreader);
1431 IEnumPins_Release(penumpins);
1433 if (!any)
1435 if (FAILED(hr = IFilterGraph2_RemoveFilter(iface, preader)))
1436 ERR("Failed to remove source filter, hr %#x.\n", hr);
1437 hr = VFW_E_CANNOT_RENDER;
1439 else if (partial)
1441 hr = VFW_S_PARTIAL_RENDER;
1443 else
1445 hr = S_OK;
1448 IBaseFilter_Release(preader);
1450 TRACE("--> %08x\n", hr);
1451 return hr;
1454 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface,
1455 const WCHAR *filename, const WCHAR *filter_name, IBaseFilter **ret_filter)
1457 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1458 IFileSourceFilter *filesource;
1459 IBaseFilter *filter;
1460 HRESULT hr;
1461 GUID clsid;
1463 TRACE("graph %p, filename %s, filter_name %s, ret_filter %p.\n",
1464 graph, debugstr_w(filename), debugstr_w(filter_name), ret_filter);
1466 if (!get_media_type(filename, NULL, NULL, &clsid))
1467 clsid = CLSID_AsyncReader;
1468 TRACE("Using source filter %s.\n", debugstr_guid(&clsid));
1470 if (FAILED(hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER,
1471 &IID_IBaseFilter, (void **)&filter)))
1473 WARN("Failed to create filter, hr %#x.\n", hr);
1474 return hr;
1477 if (FAILED(hr = IBaseFilter_QueryInterface(filter, &IID_IFileSourceFilter, (void **)&filesource)))
1479 WARN("Failed to get IFileSourceFilter, hr %#x.\n", hr);
1480 IBaseFilter_Release(filter);
1481 return hr;
1484 hr = IFileSourceFilter_Load(filesource, filename, NULL);
1485 IFileSourceFilter_Release(filesource);
1486 if (FAILED(hr))
1488 WARN("Failed to load file, hr %#x.\n", hr);
1489 return hr;
1492 if (FAILED(hr = IFilterGraph2_AddFilter(iface, filter, filter_name)))
1494 IBaseFilter_Release(filter);
1495 return hr;
1498 if (ret_filter)
1499 *ret_filter = filter;
1500 return S_OK;
1503 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR hFile)
1505 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1507 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1509 return S_OK;
1512 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1514 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1516 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1518 return S_OK;
1521 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1523 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1525 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1527 return S_OK;
1530 /*** IFilterGraph2 methods ***/
1531 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1532 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1534 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1535 HRESULT hr;
1536 IBaseFilter* pfilter;
1538 TRACE("(%p/%p)->(%p %p %s %p)\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1540 hr = IMoniker_BindToObject(pMoniker, pCtx, NULL, &IID_IBaseFilter, (void**)&pfilter);
1541 if(FAILED(hr)) {
1542 WARN("Unable to bind moniker to filter object (%x)\n", hr);
1543 return hr;
1546 hr = IFilterGraph2_AddFilter(iface, pfilter, lpcwstrFilterName);
1547 if (FAILED(hr)) {
1548 WARN("Unable to add filter (%x)\n", hr);
1549 IBaseFilter_Release(pfilter);
1550 return hr;
1553 if(ppFilter)
1554 *ppFilter = pfilter;
1555 else IBaseFilter_Release(pfilter);
1557 return S_OK;
1560 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *pin, const AM_MEDIA_TYPE *mt)
1562 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1563 PIN_DIRECTION dir;
1564 HRESULT hr;
1565 IPin *peer;
1567 TRACE("graph %p, pin %p, mt %p.\n", graph, pin, mt);
1569 if (FAILED(hr = IPin_ConnectedTo(pin, &peer)))
1570 return hr;
1572 IPin_QueryDirection(pin, &dir);
1573 IFilterGraph2_Disconnect(iface, peer);
1574 IFilterGraph2_Disconnect(iface, pin);
1576 if (dir == PINDIR_INPUT)
1577 hr = IFilterGraph2_ConnectDirect(iface, peer, pin, mt);
1578 else
1579 hr = IFilterGraph2_ConnectDirect(iface, pin, peer, mt);
1581 IPin_Release(peer);
1582 return hr;
1585 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *source, DWORD flags, DWORD *context)
1587 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1588 HRESULT hr;
1590 TRACE("graph %p, source %p, flags %#x, context %p.\n", graph, source, flags, context);
1592 if (flags & ~AM_RENDEREX_RENDERTOEXISTINGRENDERERS)
1593 FIXME("Unknown flags %#x.\n", flags);
1595 EnterCriticalSection(&graph->cs);
1596 hr = autoplug(graph, source, NULL, !!(flags & AM_RENDEREX_RENDERTOEXISTINGRENDERERS), 0);
1597 LeaveCriticalSection(&graph->cs);
1598 if (hr == VFW_E_CANNOT_CONNECT)
1599 hr = VFW_E_CANNOT_RENDER;
1601 TRACE("Returning %#x.\n", hr);
1602 return hr;
1606 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1608 FilterGraph2_QueryInterface,
1609 FilterGraph2_AddRef,
1610 FilterGraph2_Release,
1611 FilterGraph2_AddFilter,
1612 FilterGraph2_RemoveFilter,
1613 FilterGraph2_EnumFilters,
1614 FilterGraph2_FindFilterByName,
1615 FilterGraph2_ConnectDirect,
1616 FilterGraph2_Reconnect,
1617 FilterGraph2_Disconnect,
1618 FilterGraph2_SetDefaultSyncSource,
1619 FilterGraph2_Connect,
1620 FilterGraph2_Render,
1621 FilterGraph2_RenderFile,
1622 FilterGraph2_AddSourceFilter,
1623 FilterGraph2_SetLogFile,
1624 FilterGraph2_Abort,
1625 FilterGraph2_ShouldOperationContinue,
1626 FilterGraph2_AddSourceFilterForMoniker,
1627 FilterGraph2_ReconnectEx,
1628 FilterGraph2_RenderEx
1631 static struct filter_graph *impl_from_IMediaControl(IMediaControl *iface)
1633 return CONTAINING_RECORD(iface, struct filter_graph, IMediaControl_iface);
1636 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID iid, void **out)
1638 struct filter_graph *graph = impl_from_IMediaControl(iface);
1639 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
1642 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1644 struct filter_graph *graph = impl_from_IMediaControl(iface);
1645 return IUnknown_AddRef(graph->outer_unk);
1648 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1650 struct filter_graph *graph = impl_from_IMediaControl(iface);
1651 return IUnknown_Release(graph->outer_unk);
1655 /*** IDispatch methods ***/
1656 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *pctinfo)
1658 struct filter_graph *This = impl_from_IMediaControl(iface);
1660 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1662 return S_OK;
1665 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT iTInfo, LCID lcid,
1666 ITypeInfo **ppTInfo)
1668 struct filter_graph *This = impl_from_IMediaControl(iface);
1670 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1672 return S_OK;
1675 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID riid,
1676 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1678 struct filter_graph *This = impl_from_IMediaControl(iface);
1680 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
1681 cNames, lcid, rgDispId);
1683 return S_OK;
1686 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID dispIdMember, REFIID riid,
1687 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
1688 UINT *puArgErr)
1690 struct filter_graph *This = impl_from_IMediaControl(iface);
1692 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
1693 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
1695 return S_OK;
1698 static void update_render_count(struct filter_graph *graph)
1700 /* Some filters (e.g. MediaStreamFilter) can become renderers when they are
1701 * already in the graph. */
1702 struct filter *filter;
1703 graph->nRenderers = 0;
1704 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1706 if (is_renderer(filter))
1707 ++graph->nRenderers;
1711 /* Perform the paused -> running transition. The caller must hold graph->cs. */
1712 static HRESULT graph_start(struct filter_graph *graph, REFERENCE_TIME stream_start)
1714 struct media_event *event, *next;
1715 REFERENCE_TIME stream_stop;
1716 struct filter *filter;
1717 HRESULT hr = S_OK;
1719 EnterCriticalSection(&graph->event_cs);
1720 graph->EcCompleteCount = 0;
1721 update_render_count(graph);
1722 LeaveCriticalSection(&graph->event_cs);
1724 LIST_FOR_EACH_ENTRY_SAFE(event, next, &graph->media_events, struct media_event, entry)
1726 if (event->code == EC_COMPLETE)
1728 list_remove(&event->entry);
1729 free(event);
1732 if (list_empty(&graph->media_events))
1733 ResetEvent(graph->media_event_handle);
1735 if (graph->defaultclock && !graph->refClock)
1736 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
1738 if (!stream_start && graph->refClock)
1740 IReferenceClock_GetTime(graph->refClock, &graph->stream_start);
1741 stream_start = graph->stream_start - graph->stream_elapsed;
1742 /* Delay presentation time by 200 ms, to give filters time to
1743 * initialize. */
1744 stream_start += 200 * 10000;
1747 if (SUCCEEDED(IMediaSeeking_GetStopPosition(&graph->IMediaSeeking_iface, &stream_stop)))
1748 graph->stream_stop = stream_stop;
1750 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1752 HRESULT filter_hr = IBaseFilter_Run(filter->filter, stream_start);
1753 if (hr == S_OK)
1754 hr = filter_hr;
1755 TRACE("Filter %p returned %#x.\n", filter->filter, filter_hr);
1758 if (FAILED(hr))
1759 WARN("Failed to start stream, hr %#x.\n", hr);
1761 return hr;
1764 static void CALLBACK async_run_cb(TP_CALLBACK_INSTANCE *instance, void *context, TP_WORK *work)
1766 struct filter_graph *graph = context;
1767 struct filter *filter;
1768 FILTER_STATE state;
1769 HRESULT hr;
1771 TRACE("Performing asynchronous state change.\n");
1773 /* We can't just call GetState(), since that will return State_Running and
1774 * VFW_S_STATE_INTERMEDIATE regardless of whether we're done pausing yet.
1775 * Instead replicate it here. */
1777 for (;;)
1779 IBaseFilter *async_filter = NULL;
1781 hr = S_OK;
1783 EnterCriticalSection(&graph->cs);
1785 if (!graph->needs_async_run)
1786 break;
1788 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1790 hr = IBaseFilter_GetState(filter->filter, 0, &state);
1792 if (hr == VFW_S_STATE_INTERMEDIATE)
1793 async_filter = filter->filter;
1795 if (SUCCEEDED(hr) && state != State_Paused)
1796 ERR("Filter %p reported incorrect state %u.\n", filter->filter, state);
1798 if (hr != S_OK)
1799 break;
1802 if (hr != VFW_S_STATE_INTERMEDIATE)
1803 break;
1805 LeaveCriticalSection(&graph->cs);
1807 IBaseFilter_GetState(async_filter, 10, &state);
1810 if (hr == S_OK && graph->needs_async_run)
1812 sort_filters(graph);
1813 graph_start(graph, 0);
1814 graph->needs_async_run = 0;
1817 LeaveCriticalSection(&graph->cs);
1820 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
1822 struct filter_graph *graph = impl_from_IMediaControl(iface);
1823 BOOL need_async_run = TRUE;
1824 struct filter *filter;
1825 FILTER_STATE state;
1826 HRESULT hr = S_OK;
1828 TRACE("graph %p.\n", graph);
1830 EnterCriticalSection(&graph->cs);
1832 if (graph->state == State_Running)
1834 LeaveCriticalSection(&graph->cs);
1835 return S_OK;
1838 sort_filters(graph);
1840 EnterCriticalSection(&graph->event_cs);
1841 update_render_count(graph);
1842 LeaveCriticalSection(&graph->event_cs);
1844 if (graph->state == State_Stopped)
1846 if (graph->defaultclock && !graph->refClock)
1847 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
1849 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1851 HRESULT filter_hr = IBaseFilter_Pause(filter->filter);
1852 if (hr == S_OK)
1853 hr = filter_hr;
1854 TRACE("Filter %p returned %#x.\n", filter->filter, filter_hr);
1856 /* If a filter returns VFW_S_CANT_CUE, we shouldn't wait for a
1857 * paused state. */
1858 filter_hr = IBaseFilter_GetState(filter->filter, 0, &state);
1859 if (filter_hr != S_OK && filter_hr != VFW_S_STATE_INTERMEDIATE)
1860 need_async_run = FALSE;
1863 if (FAILED(hr))
1865 LeaveCriticalSection(&graph->cs);
1866 WARN("Failed to pause, hr %#x.\n", hr);
1867 return hr;
1871 graph->state = State_Running;
1873 if (SUCCEEDED(hr))
1875 if (hr != S_OK && need_async_run)
1877 if (!graph->async_run_work)
1878 graph->async_run_work = CreateThreadpoolWork(async_run_cb, graph, NULL);
1879 graph->needs_async_run = 1;
1880 SubmitThreadpoolWork(graph->async_run_work);
1882 else
1884 graph_start(graph, 0);
1888 LeaveCriticalSection(&graph->cs);
1889 return hr;
1892 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
1894 struct filter_graph *graph = impl_from_IMediaControl(iface);
1896 TRACE("graph %p.\n", graph);
1898 return IMediaFilter_Pause(&graph->IMediaFilter_iface);
1901 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
1903 struct filter_graph *graph = impl_from_IMediaControl(iface);
1905 TRACE("graph %p.\n", graph);
1907 return IMediaFilter_Stop(&graph->IMediaFilter_iface);
1910 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG timeout, OAFilterState *state)
1912 struct filter_graph *graph = impl_from_IMediaControl(iface);
1914 TRACE("graph %p, timeout %u, state %p.\n", graph, timeout, state);
1916 if (timeout < 0) timeout = INFINITE;
1918 return IMediaFilter_GetState(&graph->IMediaFilter_iface, timeout, (FILTER_STATE *)state);
1921 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
1923 struct filter_graph *This = impl_from_IMediaControl(iface);
1925 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strFilename), strFilename);
1927 return IFilterGraph2_RenderFile(&This->IFilterGraph2_iface, strFilename, NULL);
1930 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
1931 IDispatch **ppUnk)
1933 struct filter_graph *This = impl_from_IMediaControl(iface);
1935 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
1937 return S_OK;
1940 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
1942 struct filter_graph *This = impl_from_IMediaControl(iface);
1944 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
1946 return S_OK;
1949 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
1951 struct filter_graph *This = impl_from_IMediaControl(iface);
1953 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
1955 return S_OK;
1958 static void CALLBACK wait_pause_cb(TP_CALLBACK_INSTANCE *instance, void *context)
1960 IMediaControl *control = context;
1961 OAFilterState state;
1962 HRESULT hr;
1964 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
1965 ERR("Failed to get paused state, hr %#x.\n", hr);
1967 if (FAILED(hr = IMediaControl_Stop(control)))
1968 ERR("Failed to stop, hr %#x.\n", hr);
1970 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
1971 ERR("Failed to get paused state, hr %#x.\n", hr);
1973 IMediaControl_Release(control);
1976 static void CALLBACK wait_stop_cb(TP_CALLBACK_INSTANCE *instance, void *context)
1978 IMediaControl *control = context;
1979 OAFilterState state;
1980 HRESULT hr;
1982 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
1983 ERR("Failed to get state, hr %#x.\n", hr);
1985 IMediaControl_Release(control);
1988 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
1990 struct filter_graph *graph = impl_from_IMediaControl(iface);
1991 HRESULT hr;
1993 TRACE("graph %p.\n", graph);
1995 /* Even if we are already stopped, we still pause. */
1996 hr = IMediaControl_Pause(iface);
1997 if (FAILED(hr))
1998 return hr;
1999 else if (hr == S_FALSE)
2001 IMediaControl_AddRef(iface);
2002 TrySubmitThreadpoolCallback(wait_pause_cb, iface, NULL);
2003 return S_FALSE;
2006 hr = IMediaControl_Stop(iface);
2007 if (FAILED(hr))
2008 return hr;
2009 else if (hr == S_FALSE)
2011 IMediaControl_AddRef(iface);
2012 TrySubmitThreadpoolCallback(wait_stop_cb, iface, NULL);
2013 return S_FALSE;
2016 return S_OK;
2020 static const IMediaControlVtbl IMediaControl_VTable =
2022 MediaControl_QueryInterface,
2023 MediaControl_AddRef,
2024 MediaControl_Release,
2025 MediaControl_GetTypeInfoCount,
2026 MediaControl_GetTypeInfo,
2027 MediaControl_GetIDsOfNames,
2028 MediaControl_Invoke,
2029 MediaControl_Run,
2030 MediaControl_Pause,
2031 MediaControl_Stop,
2032 MediaControl_GetState,
2033 MediaControl_RenderFile,
2034 MediaControl_AddSourceFilter,
2035 MediaControl_get_FilterCollection,
2036 MediaControl_get_RegFilterCollection,
2037 MediaControl_StopWhenReady
2040 static struct filter_graph *impl_from_IMediaSeeking(IMediaSeeking *iface)
2042 return CONTAINING_RECORD(iface, struct filter_graph, IMediaSeeking_iface);
2045 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID iid, void **out)
2047 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2048 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2051 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2053 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2054 return IUnknown_AddRef(graph->outer_unk);
2057 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2059 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2060 return IUnknown_Release(graph->outer_unk);
2063 typedef HRESULT (WINAPI *fnFoundSeek)(struct filter_graph *This, IMediaSeeking*, DWORD_PTR arg);
2065 static HRESULT all_renderers_seek(struct filter_graph *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2066 BOOL allnotimpl = TRUE;
2067 HRESULT hr, hr_return = S_OK;
2068 struct filter *filter;
2070 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2071 /* Send a message to all renderers, they are responsible for broadcasting it further */
2073 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
2075 update_seeking(filter);
2076 if (!filter->seeking)
2077 continue;
2078 hr = FoundSeek(This, filter->seeking, arg);
2079 if (hr_return != E_NOTIMPL)
2080 allnotimpl = FALSE;
2081 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2082 hr_return = hr;
2085 if (allnotimpl)
2086 return E_NOTIMPL;
2087 return hr_return;
2090 static HRESULT WINAPI FoundCapabilities(struct filter_graph *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2092 HRESULT hr;
2093 DWORD caps = 0;
2095 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2096 if (FAILED(hr))
2097 return hr;
2099 /* Only add common capabilities everything supports */
2100 *(DWORD*)pcaps &= caps;
2102 return hr;
2105 /*** IMediaSeeking methods ***/
2106 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2108 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2109 HRESULT hr;
2111 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2113 if (!pCapabilities)
2114 return E_POINTER;
2116 EnterCriticalSection(&This->cs);
2117 *pCapabilities = 0xffffffff;
2119 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2120 LeaveCriticalSection(&This->cs);
2122 return hr;
2125 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2127 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2128 DWORD originalcaps;
2129 HRESULT hr;
2131 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2133 if (!pCapabilities)
2134 return E_POINTER;
2136 EnterCriticalSection(&This->cs);
2137 originalcaps = *pCapabilities;
2138 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2139 LeaveCriticalSection(&This->cs);
2141 if (FAILED(hr))
2142 return hr;
2144 if (!*pCapabilities)
2145 return E_FAIL;
2146 if (*pCapabilities != originalcaps)
2147 return S_FALSE;
2148 return S_OK;
2151 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2153 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2155 if (!pFormat)
2156 return E_POINTER;
2158 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2160 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2162 WARN("Unhandled time format %s\n", debugstr_guid(pFormat));
2163 return S_FALSE;
2166 return S_OK;
2169 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2171 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2173 if (!pFormat)
2174 return E_POINTER;
2176 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2177 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2179 return S_OK;
2182 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2184 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2186 if (!pFormat)
2187 return E_POINTER;
2189 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2190 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2192 return S_OK;
2195 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2197 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2199 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2200 if (!pFormat)
2201 return E_POINTER;
2203 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2204 return S_FALSE;
2206 return S_OK;
2209 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2211 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2213 if (!pFormat)
2214 return E_POINTER;
2216 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2218 if (This->state != State_Stopped)
2219 return VFW_E_WRONG_STATE;
2221 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2223 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2224 return E_INVALIDARG;
2227 return S_OK;
2230 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *duration)
2232 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2233 HRESULT hr = E_NOTIMPL, filter_hr;
2234 LONGLONG filter_duration;
2235 struct filter *filter;
2237 TRACE("graph %p, duration %p.\n", graph, duration);
2239 if (!duration)
2240 return E_POINTER;
2242 *duration = 0;
2244 EnterCriticalSection(&graph->cs);
2246 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2248 update_seeking(filter);
2249 if (!filter->seeking)
2250 continue;
2252 filter_hr = IMediaSeeking_GetDuration(filter->seeking, &filter_duration);
2253 if (SUCCEEDED(filter_hr))
2255 hr = S_OK;
2256 *duration = max(*duration, filter_duration);
2258 else if (filter_hr != E_NOTIMPL)
2260 LeaveCriticalSection(&graph->cs);
2261 return filter_hr;
2265 LeaveCriticalSection(&graph->cs);
2267 TRACE("Returning hr %#x, duration %s (%s seconds).\n", hr,
2268 wine_dbgstr_longlong(*duration), debugstr_time(*duration));
2269 return hr;
2272 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *stop)
2274 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2275 HRESULT hr = E_NOTIMPL, filter_hr;
2276 struct filter *filter;
2277 LONGLONG filter_stop;
2279 TRACE("graph %p, stop %p.\n", graph, stop);
2281 if (!stop)
2282 return E_POINTER;
2284 *stop = 0;
2286 EnterCriticalSection(&graph->cs);
2288 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2290 update_seeking(filter);
2291 if (!filter->seeking)
2292 continue;
2294 filter_hr = IMediaSeeking_GetStopPosition(filter->seeking, &filter_stop);
2295 if (SUCCEEDED(filter_hr))
2297 hr = S_OK;
2298 *stop = max(*stop, filter_stop);
2300 else if (filter_hr != E_NOTIMPL)
2302 LeaveCriticalSection(&graph->cs);
2303 return filter_hr;
2307 LeaveCriticalSection(&graph->cs);
2309 TRACE("Returning %s (%s seconds).\n", wine_dbgstr_longlong(*stop), debugstr_time(*stop));
2310 return hr;
2313 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *current)
2315 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2316 LONGLONG ret = graph->current_pos;
2318 TRACE("graph %p, current %p.\n", graph, current);
2320 if (!current)
2321 return E_POINTER;
2323 EnterCriticalSection(&graph->cs);
2325 if (graph->got_ec_complete)
2327 ret = graph->stream_stop;
2329 else if (graph->state == State_Running && !graph->needs_async_run && graph->refClock)
2331 REFERENCE_TIME time;
2332 IReferenceClock_GetTime(graph->refClock, &time);
2333 if (time)
2334 ret += time - graph->stream_start;
2337 LeaveCriticalSection(&graph->cs);
2339 TRACE("Returning %s (%s seconds).\n", wine_dbgstr_longlong(ret), debugstr_time(ret));
2340 *current = ret;
2342 return S_OK;
2345 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2346 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2348 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2350 TRACE("(%p/%p)->(%p, %s, 0x%s, %s)\n", This, iface, pTarget,
2351 debugstr_guid(pTargetFormat), wine_dbgstr_longlong(Source), debugstr_guid(pSourceFormat));
2353 if (!pSourceFormat)
2354 pSourceFormat = &This->timeformatseek;
2356 if (!pTargetFormat)
2357 pTargetFormat = &This->timeformatseek;
2359 if (IsEqualGUID(pTargetFormat, pSourceFormat))
2360 *pTarget = Source;
2361 else
2362 FIXME("conversion %s->%s not supported\n", debugstr_guid(pSourceFormat), debugstr_guid(pTargetFormat));
2364 return S_OK;
2367 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *current_ptr,
2368 DWORD current_flags, LONGLONG *stop_ptr, DWORD stop_flags)
2370 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2371 HRESULT hr = E_NOTIMPL, filter_hr;
2372 struct filter *filter;
2373 FILTER_STATE state;
2375 TRACE("graph %p, current %s, current_flags %#x, stop %s, stop_flags %#x.\n", graph,
2376 current_ptr ? wine_dbgstr_longlong(*current_ptr) : "<null>", current_flags,
2377 stop_ptr ? wine_dbgstr_longlong(*stop_ptr): "<null>", stop_flags);
2378 if (current_ptr)
2379 TRACE("Setting current position to %s (%s seconds).\n",
2380 wine_dbgstr_longlong(*current_ptr), debugstr_time(*current_ptr));
2381 if (stop_ptr)
2382 TRACE("Setting stop position to %s (%s seconds).\n",
2383 wine_dbgstr_longlong(*stop_ptr), debugstr_time(*stop_ptr));
2385 if ((current_flags & 0x7) != AM_SEEKING_AbsolutePositioning
2386 && (current_flags & 0x7) != AM_SEEKING_NoPositioning)
2387 FIXME("Unhandled current_flags %#x.\n", current_flags & 0x7);
2389 if ((stop_flags & 0x7) != AM_SEEKING_NoPositioning
2390 && (stop_flags & 0x7) != AM_SEEKING_AbsolutePositioning)
2391 FIXME("Unhandled stop_flags %#x.\n", stop_flags & 0x7);
2393 EnterCriticalSection(&graph->cs);
2395 state = graph->state;
2396 if (state == State_Running && !graph->needs_async_run)
2397 IMediaControl_Pause(&graph->IMediaControl_iface);
2399 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2401 LONGLONG current = current_ptr ? *current_ptr : 0, stop = stop_ptr ? *stop_ptr : 0;
2403 update_seeking(filter);
2404 if (!filter->seeking)
2405 continue;
2407 filter_hr = IMediaSeeking_SetPositions(filter->seeking, &current,
2408 current_flags | AM_SEEKING_ReturnTime, &stop, stop_flags);
2409 if (SUCCEEDED(filter_hr))
2411 hr = S_OK;
2413 if (current_ptr && (current_flags & AM_SEEKING_ReturnTime))
2414 *current_ptr = current;
2415 if (stop_ptr && (stop_flags & AM_SEEKING_ReturnTime))
2416 *stop_ptr = stop;
2417 graph->current_pos = current;
2419 else if (filter_hr != E_NOTIMPL)
2421 LeaveCriticalSection(&graph->cs);
2422 return filter_hr;
2426 if ((current_flags & 0x7) != AM_SEEKING_NoPositioning && graph->refClock)
2428 IReferenceClock_GetTime(graph->refClock, &graph->stream_start);
2429 graph->stream_elapsed = 0;
2432 if (state == State_Running && !graph->needs_async_run)
2433 IMediaControl_Run(&graph->IMediaControl_iface);
2435 LeaveCriticalSection(&graph->cs);
2436 return hr;
2439 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface,
2440 LONGLONG *current, LONGLONG *stop)
2442 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2443 HRESULT hr = S_OK;
2445 TRACE("graph %p, current %p, stop %p.\n", graph, current, stop);
2447 if (current)
2448 hr = IMediaSeeking_GetCurrentPosition(iface, current);
2449 if (SUCCEEDED(hr) && stop)
2450 hr = IMediaSeeking_GetStopPosition(iface, stop);
2452 return hr;
2455 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2456 LONGLONG *pLatest)
2458 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2460 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2462 return S_OK;
2465 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2467 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2469 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2471 return S_OK;
2474 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2476 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2478 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2480 if (!pdRate)
2481 return E_POINTER;
2483 *pdRate = 1.0;
2485 return S_OK;
2488 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2490 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2492 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2494 return S_OK;
2498 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2500 MediaSeeking_QueryInterface,
2501 MediaSeeking_AddRef,
2502 MediaSeeking_Release,
2503 MediaSeeking_GetCapabilities,
2504 MediaSeeking_CheckCapabilities,
2505 MediaSeeking_IsFormatSupported,
2506 MediaSeeking_QueryPreferredFormat,
2507 MediaSeeking_GetTimeFormat,
2508 MediaSeeking_IsUsingTimeFormat,
2509 MediaSeeking_SetTimeFormat,
2510 MediaSeeking_GetDuration,
2511 MediaSeeking_GetStopPosition,
2512 MediaSeeking_GetCurrentPosition,
2513 MediaSeeking_ConvertTimeFormat,
2514 MediaSeeking_SetPositions,
2515 MediaSeeking_GetPositions,
2516 MediaSeeking_GetAvailable,
2517 MediaSeeking_SetRate,
2518 MediaSeeking_GetRate,
2519 MediaSeeking_GetPreroll
2522 static struct filter_graph *impl_from_IMediaPosition(IMediaPosition *iface)
2524 return CONTAINING_RECORD(iface, struct filter_graph, IMediaPosition_iface);
2527 /*** IUnknown methods ***/
2528 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition *iface, REFIID iid, void **out)
2530 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2531 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2534 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2536 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2537 return IUnknown_AddRef(graph->outer_unk);
2540 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2542 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2543 return IUnknown_Release(graph->outer_unk);
2546 /*** IDispatch methods ***/
2547 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo)
2549 FIXME("(%p) stub!\n", iface);
2550 return E_NOTIMPL;
2553 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
2555 FIXME("(%p) stub!\n", iface);
2556 return E_NOTIMPL;
2559 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
2561 FIXME("(%p) stub!\n", iface);
2562 return E_NOTIMPL;
2565 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2567 FIXME("(%p) stub!\n", iface);
2568 return E_NOTIMPL;
2571 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2573 GUID time_format;
2574 HRESULT hr;
2576 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2577 if (FAILED(hr))
2578 return hr;
2579 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2581 FIXME("Unsupported time format.\n");
2582 return E_NOTIMPL;
2585 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2586 return S_OK;
2589 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2591 GUID time_format;
2592 HRESULT hr;
2594 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2595 if (FAILED(hr))
2596 return hr;
2597 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2599 FIXME("Unsupported time format.\n");
2600 return E_NOTIMPL;
2603 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2604 return S_OK;
2607 /*** IMediaPosition methods ***/
2608 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2610 LONGLONG duration;
2611 struct filter_graph *This = impl_from_IMediaPosition( iface );
2612 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2613 if (FAILED(hr))
2614 return hr;
2615 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2618 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2620 struct filter_graph *This = impl_from_IMediaPosition( iface );
2621 LONGLONG reftime;
2622 HRESULT hr;
2624 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2625 if (FAILED(hr))
2626 return hr;
2627 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2628 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2631 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2633 struct filter_graph *This = impl_from_IMediaPosition( iface );
2634 LONGLONG pos;
2635 HRESULT hr;
2637 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2638 if (FAILED(hr))
2639 return hr;
2640 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2643 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2645 struct filter_graph *This = impl_from_IMediaPosition( iface );
2646 LONGLONG pos;
2647 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2648 if (FAILED(hr))
2649 return hr;
2650 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2653 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2655 struct filter_graph *This = impl_from_IMediaPosition( iface );
2656 LONGLONG reftime;
2657 HRESULT hr;
2659 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2660 if (FAILED(hr))
2661 return hr;
2662 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2663 &reftime, AM_SEEKING_AbsolutePositioning);
2666 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime)
2668 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2669 return E_NOTIMPL;
2672 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime)
2674 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2675 return E_NOTIMPL;
2678 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2680 struct filter_graph *This = impl_from_IMediaPosition( iface );
2681 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2684 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2686 struct filter_graph *This = impl_from_IMediaPosition( iface );
2687 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2690 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward)
2692 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2693 return E_NOTIMPL;
2696 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward)
2698 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2699 return E_NOTIMPL;
2703 static const IMediaPositionVtbl IMediaPosition_VTable =
2705 MediaPosition_QueryInterface,
2706 MediaPosition_AddRef,
2707 MediaPosition_Release,
2708 MediaPosition_GetTypeInfoCount,
2709 MediaPosition_GetTypeInfo,
2710 MediaPosition_GetIDsOfNames,
2711 MediaPosition_Invoke,
2712 MediaPosition_get_Duration,
2713 MediaPosition_put_CurrentPosition,
2714 MediaPosition_get_CurrentPosition,
2715 MediaPosition_get_StopTime,
2716 MediaPosition_put_StopTime,
2717 MediaPosition_get_PrerollTime,
2718 MediaPosition_put_PrerollTime,
2719 MediaPosition_put_Rate,
2720 MediaPosition_get_Rate,
2721 MediaPosition_CanSeekForward,
2722 MediaPosition_CanSeekBackward
2725 static struct filter_graph *impl_from_IObjectWithSite(IObjectWithSite *iface)
2727 return CONTAINING_RECORD(iface, struct filter_graph, IObjectWithSite_iface);
2730 /*** IUnknown methods ***/
2731 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID iid, void **out)
2733 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2734 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2737 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
2739 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2740 return IUnknown_AddRef(graph->outer_unk);
2743 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
2745 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2746 return IUnknown_Release(graph->outer_unk);
2749 /*** IObjectWithSite methods ***/
2751 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
2753 struct filter_graph *This = impl_from_IObjectWithSite( iface );
2755 TRACE("(%p/%p)->()\n", This, iface);
2756 if (This->pSite) IUnknown_Release(This->pSite);
2757 This->pSite = pUnkSite;
2758 IUnknown_AddRef(This->pSite);
2759 return S_OK;
2762 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, PVOID *ppvSite)
2764 struct filter_graph *This = impl_from_IObjectWithSite( iface );
2766 TRACE("(%p/%p)->(%s)\n", This, iface,debugstr_guid(riid));
2768 *ppvSite = NULL;
2769 if (!This->pSite)
2770 return E_FAIL;
2771 else
2772 return IUnknown_QueryInterface(This->pSite, riid, ppvSite);
2775 static const IObjectWithSiteVtbl IObjectWithSite_VTable =
2777 ObjectWithSite_QueryInterface,
2778 ObjectWithSite_AddRef,
2779 ObjectWithSite_Release,
2780 ObjectWithSite_SetSite,
2781 ObjectWithSite_GetSite,
2784 static HRESULT GetTargetInterface(struct filter_graph* pGraph, REFIID riid, LPVOID* ppvObj)
2786 struct filter *filter;
2787 HRESULT hr;
2788 int entry;
2790 /* Check if the interface type is already registered */
2791 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2792 if (riid == pGraph->ItfCacheEntries[entry].riid)
2794 if (pGraph->ItfCacheEntries[entry].iface)
2796 /* Return the interface if available */
2797 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2798 return S_OK;
2800 break;
2803 if (entry >= MAX_ITF_CACHE_ENTRIES)
2805 FIXME("Not enough space to store interface in the cache\n");
2806 return E_OUTOFMEMORY;
2809 /* Find a filter supporting the requested interface */
2810 LIST_FOR_EACH_ENTRY(filter, &pGraph->filters, struct filter, entry)
2812 hr = IBaseFilter_QueryInterface(filter->filter, riid, ppvObj);
2813 if (hr == S_OK)
2815 pGraph->ItfCacheEntries[entry].riid = riid;
2816 pGraph->ItfCacheEntries[entry].filter = filter->filter;
2817 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2818 if (entry >= pGraph->nItfCacheEntries)
2819 pGraph->nItfCacheEntries++;
2820 return S_OK;
2822 if (hr != E_NOINTERFACE)
2823 return hr;
2826 return IsEqualGUID(riid, &IID_IBasicAudio) ? E_NOTIMPL : E_NOINTERFACE;
2829 static struct filter_graph *impl_from_IBasicAudio(IBasicAudio *iface)
2831 return CONTAINING_RECORD(iface, struct filter_graph, IBasicAudio_iface);
2834 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID iid, void **out)
2836 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2837 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2840 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
2842 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2843 return IUnknown_AddRef(graph->outer_unk);
2846 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
2848 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2849 return IUnknown_Release(graph->outer_unk);
2852 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *count)
2854 TRACE("iface %p, count %p.\n", iface, count);
2855 *count = 1;
2856 return S_OK;
2859 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT index,
2860 LCID lcid, ITypeInfo **typeinfo)
2862 TRACE("iface %p, index %u, lcid %#x, typeinfo %p.\n", iface, index, lcid, typeinfo);
2863 return strmbase_get_typeinfo(IBasicAudio_tid, typeinfo);
2866 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID iid,
2867 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
2869 ITypeInfo *typeinfo;
2870 HRESULT hr;
2872 TRACE("iface %p, iid %s, names %p, count %u, lcid %#x, ids %p.\n",
2873 iface, debugstr_guid(iid), names, count, lcid, ids);
2875 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicAudio_tid, &typeinfo)))
2877 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
2878 ITypeInfo_Release(typeinfo);
2880 return hr;
2883 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID id, REFIID iid, LCID lcid,
2884 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
2886 ITypeInfo *typeinfo;
2887 HRESULT hr;
2889 TRACE("iface %p, id %d, iid %s, lcid %#x, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
2890 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
2892 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicAudio_tid, &typeinfo)))
2894 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
2895 ITypeInfo_Release(typeinfo);
2897 return hr;
2900 /*** IBasicAudio methods ***/
2901 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
2903 struct filter_graph *This = impl_from_IBasicAudio(iface);
2904 IBasicAudio* pBasicAudio;
2905 HRESULT hr;
2907 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
2909 EnterCriticalSection(&This->cs);
2911 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2913 if (hr == S_OK)
2914 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
2916 LeaveCriticalSection(&This->cs);
2918 return hr;
2921 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
2923 struct filter_graph *This = impl_from_IBasicAudio(iface);
2924 IBasicAudio* pBasicAudio;
2925 HRESULT hr;
2927 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
2929 EnterCriticalSection(&This->cs);
2931 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2933 if (hr == S_OK)
2934 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
2936 LeaveCriticalSection(&This->cs);
2938 return hr;
2941 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
2943 struct filter_graph *This = impl_from_IBasicAudio(iface);
2944 IBasicAudio* pBasicAudio;
2945 HRESULT hr;
2947 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
2949 EnterCriticalSection(&This->cs);
2951 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2953 if (hr == S_OK)
2954 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
2956 LeaveCriticalSection(&This->cs);
2958 return hr;
2961 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
2963 struct filter_graph *This = impl_from_IBasicAudio(iface);
2964 IBasicAudio* pBasicAudio;
2965 HRESULT hr;
2967 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
2969 EnterCriticalSection(&This->cs);
2971 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2973 if (hr == S_OK)
2974 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
2976 LeaveCriticalSection(&This->cs);
2978 return hr;
2981 static const IBasicAudioVtbl IBasicAudio_VTable =
2983 BasicAudio_QueryInterface,
2984 BasicAudio_AddRef,
2985 BasicAudio_Release,
2986 BasicAudio_GetTypeInfoCount,
2987 BasicAudio_GetTypeInfo,
2988 BasicAudio_GetIDsOfNames,
2989 BasicAudio_Invoke,
2990 BasicAudio_put_Volume,
2991 BasicAudio_get_Volume,
2992 BasicAudio_put_Balance,
2993 BasicAudio_get_Balance
2996 static struct filter_graph *impl_from_IBasicVideo2(IBasicVideo2 *iface)
2998 return CONTAINING_RECORD(iface, struct filter_graph, IBasicVideo2_iface);
3001 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID iid, void **out)
3003 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
3004 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
3007 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
3009 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
3010 return IUnknown_AddRef(graph->outer_unk);
3013 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
3015 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
3016 return IUnknown_Release(graph->outer_unk);
3019 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *count)
3021 TRACE("iface %p, count %p.\n", iface, count);
3022 *count = 1;
3023 return S_OK;
3026 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT index,
3027 LCID lcid, ITypeInfo **typeinfo)
3029 TRACE("iface %p, index %u, lcid %#x, typeinfo %p.\n", iface, index, lcid, typeinfo);
3030 return strmbase_get_typeinfo(IBasicVideo_tid, typeinfo);
3033 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID iid,
3034 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
3036 ITypeInfo *typeinfo;
3037 HRESULT hr;
3039 TRACE("iface %p, iid %s, names %p, count %u, lcid %#x, ids %p.\n",
3040 iface, debugstr_guid(iid), names, count, lcid, ids);
3042 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicVideo_tid, &typeinfo)))
3044 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
3045 ITypeInfo_Release(typeinfo);
3047 return hr;
3050 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID id, REFIID iid, LCID lcid,
3051 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
3053 ITypeInfo *typeinfo;
3054 HRESULT hr;
3056 TRACE("iface %p, id %d, iid %s, lcid %#x, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
3057 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
3059 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicVideo_tid, &typeinfo)))
3061 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
3062 ITypeInfo_Release(typeinfo);
3064 return hr;
3067 /*** IBasicVideo methods ***/
3068 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3070 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3071 IBasicVideo *pBasicVideo;
3072 HRESULT hr;
3074 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3076 EnterCriticalSection(&This->cs);
3078 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3080 if (hr == S_OK)
3081 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3083 LeaveCriticalSection(&This->cs);
3085 return hr;
3088 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3090 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3091 IBasicVideo *pBasicVideo;
3092 HRESULT hr;
3094 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3096 EnterCriticalSection(&This->cs);
3098 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3100 if (hr == S_OK)
3101 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3103 LeaveCriticalSection(&This->cs);
3105 return hr;
3108 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3110 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3111 IBasicVideo *pBasicVideo;
3112 HRESULT hr;
3114 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3116 EnterCriticalSection(&This->cs);
3118 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3120 if (hr == S_OK)
3121 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3123 LeaveCriticalSection(&This->cs);
3125 return hr;
3128 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3130 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3131 IBasicVideo *pBasicVideo;
3132 HRESULT hr;
3134 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3136 EnterCriticalSection(&This->cs);
3138 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3140 if (hr == S_OK)
3141 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3143 LeaveCriticalSection(&This->cs);
3145 return hr;
3148 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3150 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3151 IBasicVideo *pBasicVideo;
3152 HRESULT hr;
3154 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3156 EnterCriticalSection(&This->cs);
3158 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3160 if (hr == S_OK)
3161 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3163 LeaveCriticalSection(&This->cs);
3165 return hr;
3168 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3170 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3171 IBasicVideo *pBasicVideo;
3172 HRESULT hr;
3174 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3176 EnterCriticalSection(&This->cs);
3178 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3180 if (hr == S_OK)
3181 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3183 LeaveCriticalSection(&This->cs);
3185 return hr;
3188 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3190 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3191 IBasicVideo *pBasicVideo;
3192 HRESULT hr;
3194 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3196 EnterCriticalSection(&This->cs);
3198 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3200 if (hr == S_OK)
3201 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3203 LeaveCriticalSection(&This->cs);
3205 return hr;
3208 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3210 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3211 IBasicVideo *pBasicVideo;
3212 HRESULT hr;
3214 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3216 EnterCriticalSection(&This->cs);
3218 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3220 if (hr == S_OK)
3221 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3223 LeaveCriticalSection(&This->cs);
3225 return hr;
3228 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3230 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3231 IBasicVideo *pBasicVideo;
3232 HRESULT hr;
3234 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3236 EnterCriticalSection(&This->cs);
3238 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3240 if (hr == S_OK)
3241 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3243 LeaveCriticalSection(&This->cs);
3245 return hr;
3248 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3250 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3251 IBasicVideo *pBasicVideo;
3252 HRESULT hr;
3254 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3256 EnterCriticalSection(&This->cs);
3258 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3260 if (hr == S_OK)
3261 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3263 LeaveCriticalSection(&This->cs);
3265 return hr;
3268 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3270 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3271 IBasicVideo *pBasicVideo;
3272 HRESULT hr;
3274 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3276 EnterCriticalSection(&This->cs);
3278 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3280 if (hr == S_OK)
3281 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3283 LeaveCriticalSection(&This->cs);
3285 return hr;
3288 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3290 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3291 IBasicVideo *pBasicVideo;
3292 HRESULT hr;
3294 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3296 EnterCriticalSection(&This->cs);
3298 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3300 if (hr == S_OK)
3301 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3303 LeaveCriticalSection(&This->cs);
3305 return hr;
3308 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3310 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3311 IBasicVideo *pBasicVideo;
3312 HRESULT hr;
3314 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3316 EnterCriticalSection(&This->cs);
3318 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3320 if (hr == S_OK)
3321 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3323 LeaveCriticalSection(&This->cs);
3325 return hr;
3328 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3330 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3331 IBasicVideo *pBasicVideo;
3332 HRESULT hr;
3334 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3336 EnterCriticalSection(&This->cs);
3338 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3340 if (hr == S_OK)
3341 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3343 LeaveCriticalSection(&This->cs);
3345 return hr;
3348 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3350 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3351 IBasicVideo *pBasicVideo;
3352 HRESULT hr;
3354 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3356 EnterCriticalSection(&This->cs);
3358 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3360 if (hr == S_OK)
3361 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3363 LeaveCriticalSection(&This->cs);
3365 return hr;
3368 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3370 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3371 IBasicVideo *pBasicVideo;
3372 HRESULT hr;
3374 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3376 EnterCriticalSection(&This->cs);
3378 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3380 if (hr == S_OK)
3381 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3383 LeaveCriticalSection(&This->cs);
3385 return hr;
3388 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3390 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3391 IBasicVideo *pBasicVideo;
3392 HRESULT hr;
3394 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3396 EnterCriticalSection(&This->cs);
3398 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3400 if (hr == S_OK)
3401 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3403 LeaveCriticalSection(&This->cs);
3405 return hr;
3408 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3410 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3411 IBasicVideo *pBasicVideo;
3412 HRESULT hr;
3414 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3416 EnterCriticalSection(&This->cs);
3418 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3420 if (hr == S_OK)
3421 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3423 LeaveCriticalSection(&This->cs);
3425 return hr;
3428 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3430 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3431 IBasicVideo *pBasicVideo;
3432 HRESULT hr;
3434 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3436 EnterCriticalSection(&This->cs);
3438 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3440 if (hr == S_OK)
3441 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3443 LeaveCriticalSection(&This->cs);
3445 return hr;
3448 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3450 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3451 IBasicVideo *pBasicVideo;
3452 HRESULT hr;
3454 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3456 EnterCriticalSection(&This->cs);
3458 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3460 if (hr == S_OK)
3461 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3463 LeaveCriticalSection(&This->cs);
3465 return hr;
3468 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3469 LONG *pDestinationHeight)
3471 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3472 IBasicVideo *pBasicVideo;
3473 HRESULT hr;
3475 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3477 EnterCriticalSection(&This->cs);
3479 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3481 if (hr == S_OK)
3482 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3484 LeaveCriticalSection(&This->cs);
3486 return hr;
3489 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3490 LONG Width, LONG Height)
3492 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3493 IBasicVideo *pBasicVideo;
3494 HRESULT hr;
3496 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3498 EnterCriticalSection(&This->cs);
3500 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3502 if (hr == S_OK)
3503 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3505 LeaveCriticalSection(&This->cs);
3507 return hr;
3510 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3511 LONG *pWidth, LONG *pHeight)
3513 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3514 IBasicVideo *pBasicVideo;
3515 HRESULT hr;
3517 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3519 EnterCriticalSection(&This->cs);
3521 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3523 if (hr == S_OK)
3524 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3526 LeaveCriticalSection(&This->cs);
3528 return hr;
3531 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3533 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3534 IBasicVideo *pBasicVideo;
3535 HRESULT hr;
3537 TRACE("(%p/%p)->()\n", This, iface);
3539 EnterCriticalSection(&This->cs);
3541 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3543 if (hr == S_OK)
3544 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3546 LeaveCriticalSection(&This->cs);
3548 return hr;
3551 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3552 LONG Width, LONG Height)
3554 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3555 IBasicVideo *pBasicVideo;
3556 HRESULT hr;
3558 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3560 EnterCriticalSection(&This->cs);
3562 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3564 if (hr == S_OK)
3565 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3567 LeaveCriticalSection(&This->cs);
3569 return hr;
3572 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3573 LONG *pTop, LONG *pWidth, LONG *pHeight)
3575 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3576 IBasicVideo *pBasicVideo;
3577 HRESULT hr;
3579 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3581 EnterCriticalSection(&This->cs);
3583 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3585 if (hr == S_OK)
3586 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3588 LeaveCriticalSection(&This->cs);
3590 return hr;
3593 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3595 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3596 IBasicVideo *pBasicVideo;
3597 HRESULT hr;
3599 TRACE("(%p/%p)->()\n", This, iface);
3601 EnterCriticalSection(&This->cs);
3603 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3605 if (hr == S_OK)
3606 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3608 LeaveCriticalSection(&This->cs);
3610 return hr;
3613 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3615 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3616 IBasicVideo *pBasicVideo;
3617 HRESULT hr;
3619 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3621 EnterCriticalSection(&This->cs);
3623 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3625 if (hr == S_OK)
3626 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3628 LeaveCriticalSection(&This->cs);
3630 return hr;
3633 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3634 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3636 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3637 IBasicVideo *pBasicVideo;
3638 HRESULT hr;
3640 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3642 EnterCriticalSection(&This->cs);
3644 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3646 if (hr == S_OK)
3647 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3649 LeaveCriticalSection(&This->cs);
3651 return hr;
3654 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3655 LONG *pDIBImage)
3657 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3658 IBasicVideo *pBasicVideo;
3659 HRESULT hr;
3661 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3663 EnterCriticalSection(&This->cs);
3665 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3667 if (hr == S_OK)
3668 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3670 LeaveCriticalSection(&This->cs);
3672 return hr;
3675 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3677 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3678 IBasicVideo *pBasicVideo;
3679 HRESULT hr;
3681 TRACE("(%p/%p)->()\n", This, iface);
3683 EnterCriticalSection(&This->cs);
3685 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3687 if (hr == S_OK)
3688 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3690 LeaveCriticalSection(&This->cs);
3692 return hr;
3695 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3697 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3698 IBasicVideo *pBasicVideo;
3699 HRESULT hr;
3701 TRACE("(%p/%p)->()\n", This, iface);
3703 EnterCriticalSection(&This->cs);
3705 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3707 if (hr == S_OK)
3708 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3710 LeaveCriticalSection(&This->cs);
3712 return hr;
3715 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3716 LONG *plAspectY)
3718 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3719 IBasicVideo2 *pBasicVideo2;
3720 HRESULT hr;
3722 TRACE("(%p/%p)->()\n", This, iface);
3724 EnterCriticalSection(&This->cs);
3726 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3728 if (hr == S_OK)
3729 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3731 LeaveCriticalSection(&This->cs);
3733 return hr;
3736 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3738 BasicVideo_QueryInterface,
3739 BasicVideo_AddRef,
3740 BasicVideo_Release,
3741 BasicVideo_GetTypeInfoCount,
3742 BasicVideo_GetTypeInfo,
3743 BasicVideo_GetIDsOfNames,
3744 BasicVideo_Invoke,
3745 BasicVideo_get_AvgTimePerFrame,
3746 BasicVideo_get_BitRate,
3747 BasicVideo_get_BitErrorRate,
3748 BasicVideo_get_VideoWidth,
3749 BasicVideo_get_VideoHeight,
3750 BasicVideo_put_SourceLeft,
3751 BasicVideo_get_SourceLeft,
3752 BasicVideo_put_SourceWidth,
3753 BasicVideo_get_SourceWidth,
3754 BasicVideo_put_SourceTop,
3755 BasicVideo_get_SourceTop,
3756 BasicVideo_put_SourceHeight,
3757 BasicVideo_get_SourceHeight,
3758 BasicVideo_put_DestinationLeft,
3759 BasicVideo_get_DestinationLeft,
3760 BasicVideo_put_DestinationWidth,
3761 BasicVideo_get_DestinationWidth,
3762 BasicVideo_put_DestinationTop,
3763 BasicVideo_get_DestinationTop,
3764 BasicVideo_put_DestinationHeight,
3765 BasicVideo_get_DestinationHeight,
3766 BasicVideo_SetSourcePosition,
3767 BasicVideo_GetSourcePosition,
3768 BasicVideo_SetDefaultSourcePosition,
3769 BasicVideo_SetDestinationPosition,
3770 BasicVideo_GetDestinationPosition,
3771 BasicVideo_SetDefaultDestinationPosition,
3772 BasicVideo_GetVideoSize,
3773 BasicVideo_GetVideoPaletteEntries,
3774 BasicVideo_GetCurrentImage,
3775 BasicVideo_IsUsingDefaultSource,
3776 BasicVideo_IsUsingDefaultDestination,
3777 BasicVideo2_GetPreferredAspectRatio
3780 static struct filter_graph *impl_from_IVideoWindow(IVideoWindow *iface)
3782 return CONTAINING_RECORD(iface, struct filter_graph, IVideoWindow_iface);
3785 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID iid, void **out)
3787 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3788 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
3791 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
3793 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3794 return IUnknown_AddRef(graph->outer_unk);
3797 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
3799 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3800 return IUnknown_Release(graph->outer_unk);
3803 HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *count)
3805 TRACE("iface %p, count %p.\n", iface, count);
3806 *count = 1;
3807 return S_OK;
3810 HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT index,
3811 LCID lcid, ITypeInfo **typeinfo)
3813 TRACE("iface %p, index %u, lcid %#x, typeinfo %p.\n", iface, index, lcid, typeinfo);
3814 return strmbase_get_typeinfo(IVideoWindow_tid, typeinfo);
3817 HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID iid,
3818 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
3820 ITypeInfo *typeinfo;
3821 HRESULT hr;
3823 TRACE("iface %p, iid %s, names %p, count %u, lcid %#x, ids %p.\n",
3824 iface, debugstr_guid(iid), names, count, lcid, ids);
3826 if (SUCCEEDED(hr = strmbase_get_typeinfo(IVideoWindow_tid, &typeinfo)))
3828 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
3829 ITypeInfo_Release(typeinfo);
3831 return hr;
3834 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID id, REFIID iid, LCID lcid,
3835 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
3837 ITypeInfo *typeinfo;
3838 HRESULT hr;
3840 TRACE("iface %p, id %d, iid %s, lcid %#x, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
3841 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
3843 if (SUCCEEDED(hr = strmbase_get_typeinfo(IVideoWindow_tid, &typeinfo)))
3845 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
3846 ITypeInfo_Release(typeinfo);
3848 return hr;
3851 /*** IVideoWindow methods ***/
3852 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
3854 struct filter_graph *This = impl_from_IVideoWindow(iface);
3855 IVideoWindow *pVideoWindow;
3856 HRESULT hr;
3858 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
3860 EnterCriticalSection(&This->cs);
3862 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3864 if (hr == S_OK)
3865 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
3867 LeaveCriticalSection(&This->cs);
3869 return hr;
3872 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
3874 struct filter_graph *This = impl_from_IVideoWindow(iface);
3875 IVideoWindow *pVideoWindow;
3876 HRESULT hr;
3878 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
3880 EnterCriticalSection(&This->cs);
3882 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3884 if (hr == S_OK)
3885 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
3887 LeaveCriticalSection(&This->cs);
3889 return hr;
3892 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
3894 struct filter_graph *This = impl_from_IVideoWindow(iface);
3895 IVideoWindow *pVideoWindow;
3896 HRESULT hr;
3898 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
3900 EnterCriticalSection(&This->cs);
3902 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3904 if (hr == S_OK)
3905 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
3907 LeaveCriticalSection(&This->cs);
3909 return hr;
3912 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
3914 struct filter_graph *This = impl_from_IVideoWindow(iface);
3915 IVideoWindow *pVideoWindow;
3916 HRESULT hr;
3918 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
3920 EnterCriticalSection(&This->cs);
3922 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3924 if (hr == S_OK)
3925 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
3927 LeaveCriticalSection(&This->cs);
3929 return hr;
3932 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
3934 struct filter_graph *This = impl_from_IVideoWindow(iface);
3935 IVideoWindow *pVideoWindow;
3936 HRESULT hr;
3938 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
3940 EnterCriticalSection(&This->cs);
3942 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3944 if (hr == S_OK)
3945 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
3947 LeaveCriticalSection(&This->cs);
3949 return hr;
3952 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
3954 struct filter_graph *This = impl_from_IVideoWindow(iface);
3955 IVideoWindow *pVideoWindow;
3956 HRESULT hr;
3958 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
3960 EnterCriticalSection(&This->cs);
3962 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3964 if (hr == S_OK)
3965 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
3967 LeaveCriticalSection(&This->cs);
3969 return hr;
3972 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
3974 struct filter_graph *This = impl_from_IVideoWindow(iface);
3975 IVideoWindow *pVideoWindow;
3976 HRESULT hr;
3978 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
3980 EnterCriticalSection(&This->cs);
3982 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3984 if (hr == S_OK)
3985 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
3987 LeaveCriticalSection(&This->cs);
3989 return hr;
3992 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
3994 struct filter_graph *This = impl_from_IVideoWindow(iface);
3995 IVideoWindow *pVideoWindow;
3996 HRESULT hr;
3998 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4000 EnterCriticalSection(&This->cs);
4002 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4004 if (hr == S_OK)
4005 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4007 LeaveCriticalSection(&This->cs);
4009 return hr;
4012 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
4014 struct filter_graph *This = impl_from_IVideoWindow(iface);
4015 IVideoWindow *pVideoWindow;
4016 HRESULT hr;
4018 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4020 EnterCriticalSection(&This->cs);
4022 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4024 if (hr == S_OK)
4025 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4027 LeaveCriticalSection(&This->cs);
4029 return hr;
4032 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4034 struct filter_graph *This = impl_from_IVideoWindow(iface);
4035 IVideoWindow *pVideoWindow;
4036 HRESULT hr;
4038 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4040 EnterCriticalSection(&This->cs);
4042 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4044 if (hr == S_OK)
4045 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4047 LeaveCriticalSection(&This->cs);
4049 return hr;
4052 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4054 struct filter_graph *This = impl_from_IVideoWindow(iface);
4055 IVideoWindow *pVideoWindow;
4056 HRESULT hr;
4058 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4060 EnterCriticalSection(&This->cs);
4062 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4064 if (hr == S_OK)
4065 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4067 LeaveCriticalSection(&This->cs);
4069 return hr;
4072 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4073 LONG *pBackgroundPalette)
4075 struct filter_graph *This = impl_from_IVideoWindow(iface);
4076 IVideoWindow *pVideoWindow;
4077 HRESULT hr;
4079 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4081 EnterCriticalSection(&This->cs);
4083 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4085 if (hr == S_OK)
4086 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4088 LeaveCriticalSection(&This->cs);
4090 return hr;
4093 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4095 struct filter_graph *This = impl_from_IVideoWindow(iface);
4096 IVideoWindow *pVideoWindow;
4097 HRESULT hr;
4099 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4101 EnterCriticalSection(&This->cs);
4103 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4105 if (hr == S_OK)
4106 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4108 LeaveCriticalSection(&This->cs);
4110 return hr;
4113 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4115 struct filter_graph *This = impl_from_IVideoWindow(iface);
4116 IVideoWindow *pVideoWindow;
4117 HRESULT hr;
4119 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4121 EnterCriticalSection(&This->cs);
4123 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4125 if (hr == S_OK)
4126 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4128 LeaveCriticalSection(&This->cs);
4130 return hr;
4133 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4135 struct filter_graph *This = impl_from_IVideoWindow(iface);
4136 IVideoWindow *pVideoWindow;
4137 HRESULT hr;
4139 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4141 EnterCriticalSection(&This->cs);
4143 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4145 if (hr == S_OK)
4146 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4148 LeaveCriticalSection(&This->cs);
4150 return hr;
4153 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4155 struct filter_graph *This = impl_from_IVideoWindow(iface);
4156 IVideoWindow *pVideoWindow;
4157 HRESULT hr;
4159 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4161 EnterCriticalSection(&This->cs);
4163 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4165 if (hr == S_OK)
4166 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4168 LeaveCriticalSection(&This->cs);
4170 return hr;
4173 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4175 struct filter_graph *This = impl_from_IVideoWindow(iface);
4176 IVideoWindow *pVideoWindow;
4177 HRESULT hr;
4179 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4181 EnterCriticalSection(&This->cs);
4183 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4185 if (hr == S_OK)
4186 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4188 LeaveCriticalSection(&This->cs);
4190 return hr;
4193 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4195 struct filter_graph *This = impl_from_IVideoWindow(iface);
4196 IVideoWindow *pVideoWindow;
4197 HRESULT hr;
4199 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4201 EnterCriticalSection(&This->cs);
4203 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4205 if (hr == S_OK)
4206 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4208 LeaveCriticalSection(&This->cs);
4210 return hr;
4213 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4215 struct filter_graph *This = impl_from_IVideoWindow(iface);
4216 IVideoWindow *pVideoWindow;
4217 HRESULT hr;
4219 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4221 EnterCriticalSection(&This->cs);
4223 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4225 if (hr == S_OK)
4226 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4228 LeaveCriticalSection(&This->cs);
4230 return hr;
4233 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4235 struct filter_graph *This = impl_from_IVideoWindow(iface);
4236 IVideoWindow *pVideoWindow;
4237 HRESULT hr;
4239 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4241 EnterCriticalSection(&This->cs);
4243 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4245 if (hr == S_OK)
4246 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4248 LeaveCriticalSection(&This->cs);
4250 return hr;
4253 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4255 struct filter_graph *This = impl_from_IVideoWindow(iface);
4256 IVideoWindow *pVideoWindow;
4257 HRESULT hr;
4259 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4261 EnterCriticalSection(&This->cs);
4263 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4265 if (hr == S_OK)
4266 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4268 LeaveCriticalSection(&This->cs);
4270 return hr;
4273 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4275 struct filter_graph *This = impl_from_IVideoWindow(iface);
4276 IVideoWindow *pVideoWindow;
4277 HRESULT hr;
4279 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4281 EnterCriticalSection(&This->cs);
4283 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4285 if (hr == S_OK)
4286 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4288 LeaveCriticalSection(&This->cs);
4290 return hr;
4293 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4295 struct filter_graph *This = impl_from_IVideoWindow(iface);
4296 IVideoWindow *pVideoWindow;
4297 HRESULT hr;
4299 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4301 EnterCriticalSection(&This->cs);
4303 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4305 if (hr == S_OK)
4306 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4308 LeaveCriticalSection(&This->cs);
4310 return hr;
4313 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4315 struct filter_graph *This = impl_from_IVideoWindow(iface);
4316 IVideoWindow *pVideoWindow;
4317 HRESULT hr;
4319 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4321 EnterCriticalSection(&This->cs);
4323 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4325 if (hr == S_OK)
4326 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4328 LeaveCriticalSection(&This->cs);
4330 return hr;
4333 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4335 struct filter_graph *This = impl_from_IVideoWindow(iface);
4336 IVideoWindow *pVideoWindow;
4337 HRESULT hr;
4339 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4341 EnterCriticalSection(&This->cs);
4343 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4345 if (hr == S_OK)
4346 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4348 LeaveCriticalSection(&This->cs);
4350 return hr;
4353 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4355 struct filter_graph *This = impl_from_IVideoWindow(iface);
4356 IVideoWindow *pVideoWindow;
4357 HRESULT hr;
4359 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4361 EnterCriticalSection(&This->cs);
4363 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4365 if (hr == S_OK)
4366 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4368 LeaveCriticalSection(&This->cs);
4370 return hr;
4373 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4375 struct filter_graph *This = impl_from_IVideoWindow(iface);
4376 IVideoWindow *pVideoWindow;
4377 HRESULT hr;
4379 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4381 EnterCriticalSection(&This->cs);
4383 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4385 if (hr == S_OK)
4386 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4388 LeaveCriticalSection(&This->cs);
4390 return hr;
4393 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4395 struct filter_graph *This = impl_from_IVideoWindow(iface);
4396 IVideoWindow *pVideoWindow;
4397 HRESULT hr;
4399 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4401 EnterCriticalSection(&This->cs);
4403 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4405 if (hr == S_OK)
4406 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4408 LeaveCriticalSection(&This->cs);
4410 return hr;
4413 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4415 struct filter_graph *This = impl_from_IVideoWindow(iface);
4416 IVideoWindow *pVideoWindow;
4417 HRESULT hr;
4419 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4421 EnterCriticalSection(&This->cs);
4423 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4425 if (hr == S_OK)
4426 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4428 LeaveCriticalSection(&This->cs);
4430 return hr;
4433 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4435 struct filter_graph *This = impl_from_IVideoWindow(iface);
4436 IVideoWindow *pVideoWindow;
4437 HRESULT hr;
4439 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4441 EnterCriticalSection(&This->cs);
4443 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4445 if (hr == S_OK)
4446 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4448 LeaveCriticalSection(&This->cs);
4450 return hr;
4453 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4455 struct filter_graph *This = impl_from_IVideoWindow(iface);
4456 IVideoWindow *pVideoWindow;
4457 HRESULT hr;
4459 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4461 EnterCriticalSection(&This->cs);
4463 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4465 if (hr == S_OK)
4466 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4468 LeaveCriticalSection(&This->cs);
4470 return hr;
4473 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4474 LONG_PTR wParam, LONG_PTR lParam)
4476 struct filter_graph *This = impl_from_IVideoWindow(iface);
4477 IVideoWindow *pVideoWindow;
4478 HRESULT hr;
4480 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4482 EnterCriticalSection(&This->cs);
4484 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4486 if (hr == S_OK)
4487 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4489 LeaveCriticalSection(&This->cs);
4491 return hr;
4494 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4495 LONG Width, LONG Height)
4497 struct filter_graph *This = impl_from_IVideoWindow(iface);
4498 IVideoWindow *pVideoWindow;
4499 HRESULT hr;
4501 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4503 EnterCriticalSection(&This->cs);
4505 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4507 if (hr == S_OK)
4508 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4510 LeaveCriticalSection(&This->cs);
4512 return hr;
4515 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4516 LONG *pWidth, LONG *pHeight)
4518 struct filter_graph *This = impl_from_IVideoWindow(iface);
4519 IVideoWindow *pVideoWindow;
4520 HRESULT hr;
4522 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4524 EnterCriticalSection(&This->cs);
4526 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4528 if (hr == S_OK)
4529 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4531 LeaveCriticalSection(&This->cs);
4533 return hr;
4536 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4537 LONG *pHeight)
4539 struct filter_graph *This = impl_from_IVideoWindow(iface);
4540 IVideoWindow *pVideoWindow;
4541 HRESULT hr;
4543 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4545 EnterCriticalSection(&This->cs);
4547 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4549 if (hr == S_OK)
4550 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4552 LeaveCriticalSection(&This->cs);
4554 return hr;
4557 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4558 LONG *pHeight)
4560 struct filter_graph *This = impl_from_IVideoWindow(iface);
4561 IVideoWindow *pVideoWindow;
4562 HRESULT hr;
4564 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4566 EnterCriticalSection(&This->cs);
4568 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4570 if (hr == S_OK)
4571 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4573 LeaveCriticalSection(&This->cs);
4575 return hr;
4578 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4579 LONG *pWidth, LONG *pHeight)
4581 struct filter_graph *This = impl_from_IVideoWindow(iface);
4582 IVideoWindow *pVideoWindow;
4583 HRESULT hr;
4585 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4587 EnterCriticalSection(&This->cs);
4589 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4591 if (hr == S_OK)
4592 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4594 LeaveCriticalSection(&This->cs);
4596 return hr;
4599 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4601 struct filter_graph *This = impl_from_IVideoWindow(iface);
4602 IVideoWindow *pVideoWindow;
4603 HRESULT hr;
4605 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4607 EnterCriticalSection(&This->cs);
4609 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4611 if (hr == S_OK)
4612 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4614 LeaveCriticalSection(&This->cs);
4616 return hr;
4619 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4621 struct filter_graph *This = impl_from_IVideoWindow(iface);
4622 IVideoWindow *pVideoWindow;
4623 HRESULT hr;
4625 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4627 EnterCriticalSection(&This->cs);
4629 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4631 if (hr == S_OK)
4632 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4634 LeaveCriticalSection(&This->cs);
4636 return hr;
4640 static const IVideoWindowVtbl IVideoWindow_VTable =
4642 VideoWindow_QueryInterface,
4643 VideoWindow_AddRef,
4644 VideoWindow_Release,
4645 VideoWindow_GetTypeInfoCount,
4646 VideoWindow_GetTypeInfo,
4647 VideoWindow_GetIDsOfNames,
4648 VideoWindow_Invoke,
4649 VideoWindow_put_Caption,
4650 VideoWindow_get_Caption,
4651 VideoWindow_put_WindowStyle,
4652 VideoWindow_get_WindowStyle,
4653 VideoWindow_put_WindowStyleEx,
4654 VideoWindow_get_WindowStyleEx,
4655 VideoWindow_put_AutoShow,
4656 VideoWindow_get_AutoShow,
4657 VideoWindow_put_WindowState,
4658 VideoWindow_get_WindowState,
4659 VideoWindow_put_BackgroundPalette,
4660 VideoWindow_get_BackgroundPalette,
4661 VideoWindow_put_Visible,
4662 VideoWindow_get_Visible,
4663 VideoWindow_put_Left,
4664 VideoWindow_get_Left,
4665 VideoWindow_put_Width,
4666 VideoWindow_get_Width,
4667 VideoWindow_put_Top,
4668 VideoWindow_get_Top,
4669 VideoWindow_put_Height,
4670 VideoWindow_get_Height,
4671 VideoWindow_put_Owner,
4672 VideoWindow_get_Owner,
4673 VideoWindow_put_MessageDrain,
4674 VideoWindow_get_MessageDrain,
4675 VideoWindow_get_BorderColor,
4676 VideoWindow_put_BorderColor,
4677 VideoWindow_get_FullScreenMode,
4678 VideoWindow_put_FullScreenMode,
4679 VideoWindow_SetWindowForeground,
4680 VideoWindow_NotifyOwnerMessage,
4681 VideoWindow_SetWindowPosition,
4682 VideoWindow_GetWindowPosition,
4683 VideoWindow_GetMinIdealImageSize,
4684 VideoWindow_GetMaxIdealImageSize,
4685 VideoWindow_GetRestorePosition,
4686 VideoWindow_HideCursor,
4687 VideoWindow_IsCursorHidden
4690 static struct filter_graph *impl_from_IMediaEventEx(IMediaEventEx *iface)
4692 return CONTAINING_RECORD(iface, struct filter_graph, IMediaEventEx_iface);
4695 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID iid, void **out)
4697 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4698 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
4701 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
4703 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4704 return IUnknown_AddRef(graph->outer_unk);
4707 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
4709 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4710 return IUnknown_Release(graph->outer_unk);
4713 /*** IDispatch methods ***/
4714 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *pctinfo)
4716 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4718 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
4720 return S_OK;
4723 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT iTInfo, LCID lcid,
4724 ITypeInfo **ppTInfo)
4726 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4728 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
4730 return S_OK;
4733 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID riid,
4734 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4736 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4738 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
4739 cNames, lcid, rgDispId);
4741 return S_OK;
4744 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID dispIdMember, REFIID riid,
4745 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4746 UINT *puArgErr)
4748 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4750 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
4751 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4753 return S_OK;
4756 /*** IMediaEvent methods ***/
4757 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *event)
4759 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4761 TRACE("graph %p, event %p.\n", graph, event);
4763 *event = (OAEVENT)graph->media_event_handle;
4764 return S_OK;
4767 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *code,
4768 LONG_PTR *param1, LONG_PTR *param2, LONG timeout)
4770 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4771 struct media_event *event;
4772 struct list *entry;
4774 TRACE("graph %p, code %p, param1 %p, param2 %p, timeout %d.\n", graph, code, param1, param2, timeout);
4776 *code = 0;
4778 if (WaitForSingleObject(graph->media_event_handle, timeout))
4779 return E_ABORT;
4781 EnterCriticalSection(&graph->event_cs);
4783 if (!(entry = list_head(&graph->media_events)))
4785 ResetEvent(graph->media_event_handle);
4786 LeaveCriticalSection(&graph->event_cs);
4787 return E_ABORT;
4789 event = LIST_ENTRY(entry, struct media_event, entry);
4790 list_remove(&event->entry);
4791 *code = event->code;
4792 *param1 = event->param1;
4793 *param2 = event->param2;
4794 free(event);
4796 LeaveCriticalSection(&graph->event_cs);
4797 return S_OK;
4800 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
4801 LONG *pEvCode)
4803 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4805 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
4807 if (This->state != State_Running)
4808 return VFW_E_WRONG_STATE;
4810 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
4812 *pEvCode = This->CompletionStatus;
4813 return S_OK;
4816 *pEvCode = 0;
4817 return E_ABORT;
4820 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
4822 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4824 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4826 if (lEvCode == EC_COMPLETE)
4827 This->HandleEcComplete = FALSE;
4828 else if (lEvCode == EC_REPAINT)
4829 This->HandleEcRepaint = FALSE;
4830 else if (lEvCode == EC_CLOCK_CHANGED)
4831 This->HandleEcClockChanged = FALSE;
4832 else
4833 return S_FALSE;
4835 return S_OK;
4838 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
4840 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4842 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4844 if (lEvCode == EC_COMPLETE)
4845 This->HandleEcComplete = TRUE;
4846 else if (lEvCode == EC_REPAINT)
4847 This->HandleEcRepaint = TRUE;
4848 else if (lEvCode == EC_CLOCK_CHANGED)
4849 This->HandleEcClockChanged = TRUE;
4850 else
4851 return S_FALSE;
4853 return S_OK;
4856 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG lEvCode,
4857 LONG_PTR lParam1, LONG_PTR lParam2)
4859 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4861 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
4863 return S_OK;
4866 /*** IMediaEventEx methods ***/
4867 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface,
4868 OAHWND window, LONG message, LONG_PTR lparam)
4870 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4872 TRACE("graph %p, window %#Ix, message %#x, lparam %#Ix.\n", graph, window, message, lparam);
4874 graph->media_event_window = (HWND)window;
4875 graph->media_event_message = message;
4876 graph->media_event_lparam = lparam;
4878 return S_OK;
4881 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG flags)
4883 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4885 TRACE("graph %p, flags %#x.\n", graph, flags);
4887 if (flags & ~AM_MEDIAEVENT_NONOTIFY)
4889 WARN("Invalid flags %#x, returning E_INVALIDARG.\n", flags);
4890 return E_INVALIDARG;
4893 graph->media_events_disabled = flags;
4895 if (flags)
4897 flush_media_events(graph);
4898 ResetEvent(graph->media_event_handle);
4901 return S_OK;
4904 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *flags)
4906 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4908 TRACE("graph %p, flags %p.\n", graph, flags);
4910 if (!flags)
4911 return E_POINTER;
4913 *flags = graph->media_events_disabled;
4915 return S_OK;
4919 static const IMediaEventExVtbl IMediaEventEx_VTable =
4921 MediaEvent_QueryInterface,
4922 MediaEvent_AddRef,
4923 MediaEvent_Release,
4924 MediaEvent_GetTypeInfoCount,
4925 MediaEvent_GetTypeInfo,
4926 MediaEvent_GetIDsOfNames,
4927 MediaEvent_Invoke,
4928 MediaEvent_GetEventHandle,
4929 MediaEvent_GetEvent,
4930 MediaEvent_WaitForCompletion,
4931 MediaEvent_CancelDefaultHandling,
4932 MediaEvent_RestoreDefaultHandling,
4933 MediaEvent_FreeEventParams,
4934 MediaEvent_SetNotifyWindow,
4935 MediaEvent_SetNotifyFlags,
4936 MediaEvent_GetNotifyFlags
4940 static struct filter_graph *impl_from_IMediaFilter(IMediaFilter *iface)
4942 return CONTAINING_RECORD(iface, struct filter_graph, IMediaFilter_iface);
4945 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID iid, void **out)
4947 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4949 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
4952 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
4954 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4956 return IUnknown_AddRef(graph->outer_unk);
4959 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
4961 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4963 return IUnknown_Release(graph->outer_unk);
4966 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
4968 FIXME("(%p): stub\n", pClassID);
4970 return E_NOTIMPL;
4973 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
4975 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4976 HRESULT hr = S_OK, filter_hr;
4977 struct filter *filter;
4978 TP_WORK *work;
4980 TRACE("graph %p.\n", graph);
4982 EnterCriticalSection(&graph->cs);
4984 if (graph->state == State_Stopped)
4986 LeaveCriticalSection(&graph->cs);
4987 return S_OK;
4990 sort_filters(graph);
4992 if (graph->state == State_Running)
4994 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
4996 filter_hr = IBaseFilter_Pause(filter->filter);
4997 if (hr == S_OK)
4998 hr = filter_hr;
5002 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5004 filter_hr = IBaseFilter_Stop(filter->filter);
5005 if (hr == S_OK)
5006 hr = filter_hr;
5009 graph->state = State_Stopped;
5010 graph->needs_async_run = 0;
5011 work = graph->async_run_work;
5012 graph->got_ec_complete = 0;
5014 /* Update the current position, probably to synchronize multiple streams. */
5015 IMediaSeeking_SetPositions(&graph->IMediaSeeking_iface, &graph->current_pos,
5016 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
5018 LeaveCriticalSection(&graph->cs);
5020 if (work)
5021 WaitForThreadpoolWorkCallbacks(work, TRUE);
5023 return hr;
5026 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5028 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5029 HRESULT hr = S_OK, filter_hr;
5030 struct filter *filter;
5031 TP_WORK *work;
5033 TRACE("graph %p.\n", graph);
5035 EnterCriticalSection(&graph->cs);
5037 if (graph->state == State_Paused)
5039 LeaveCriticalSection(&graph->cs);
5040 return S_OK;
5043 sort_filters(graph);
5045 EnterCriticalSection(&graph->event_cs);
5046 update_render_count(graph);
5047 LeaveCriticalSection(&graph->event_cs);
5049 if (graph->defaultclock && !graph->refClock)
5050 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
5052 if (graph->state == State_Running && graph->refClock)
5054 REFERENCE_TIME time;
5055 IReferenceClock_GetTime(graph->refClock, &time);
5056 graph->stream_elapsed += time - graph->stream_start;
5057 graph->current_pos += graph->stream_elapsed;
5060 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5062 filter_hr = IBaseFilter_Pause(filter->filter);
5063 if (hr == S_OK)
5064 hr = filter_hr;
5067 graph->state = State_Paused;
5068 graph->needs_async_run = 0;
5069 work = graph->async_run_work;
5071 LeaveCriticalSection(&graph->cs);
5073 if (work)
5074 WaitForThreadpoolWorkCallbacks(work, TRUE);
5076 return hr;
5079 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME start)
5081 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5082 HRESULT hr;
5084 TRACE("graph %p, start %s.\n", graph, debugstr_time(start));
5086 EnterCriticalSection(&graph->cs);
5088 if (graph->state == State_Running)
5090 LeaveCriticalSection(&graph->cs);
5091 return S_OK;
5094 sort_filters(graph);
5096 hr = graph_start(graph, start);
5098 graph->state = State_Running;
5099 graph->needs_async_run = 0;
5101 LeaveCriticalSection(&graph->cs);
5102 return hr;
5105 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD timeout, FILTER_STATE *state)
5107 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5108 DWORD end = GetTickCount() + timeout;
5109 HRESULT hr;
5111 TRACE("graph %p, timeout %u, state %p.\n", graph, timeout, state);
5113 if (!state)
5114 return E_POINTER;
5116 /* Thread safety is a little tricky here. GetState() shouldn't block other
5117 * functions from being called on the filter graph. However, we can't just
5118 * call IBaseFilter::GetState() in one loop and drop the lock on every
5119 * iteration, since the filter list might change beneath us. So instead we
5120 * do what native does, and poll for it every 10 ms. */
5122 EnterCriticalSection(&graph->cs);
5123 *state = graph->state;
5125 for (;;)
5127 IBaseFilter *async_filter = NULL;
5128 FILTER_STATE filter_state;
5129 struct filter *filter;
5131 hr = S_OK;
5133 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5135 HRESULT filter_hr = IBaseFilter_GetState(filter->filter, 0, &filter_state);
5137 TRACE("Filter %p returned hr %#x, state %u.\n", filter->filter, filter_hr, filter_state);
5139 if (filter_hr == VFW_S_STATE_INTERMEDIATE)
5140 async_filter = filter->filter;
5142 if (hr == S_OK && filter_hr == VFW_S_STATE_INTERMEDIATE)
5143 hr = VFW_S_STATE_INTERMEDIATE;
5144 else if (filter_hr != S_OK && filter_hr != VFW_S_STATE_INTERMEDIATE)
5145 hr = filter_hr;
5147 if (hr == S_OK && filter_state == State_Paused && graph->state != State_Paused)
5149 async_filter = filter->filter;
5150 hr = VFW_S_STATE_INTERMEDIATE;
5152 else if (filter_state != graph->state && filter_state != State_Paused)
5153 hr = E_FAIL;
5155 if (graph->needs_async_run)
5157 if (filter_state != State_Paused && filter_state != State_Running)
5158 ERR("Filter %p reported incorrect state %u (expected %u or %u).\n",
5159 filter->filter, filter_state, State_Paused, State_Running);
5161 else
5163 if (filter_state != graph->state)
5164 ERR("Filter %p reported incorrect state %u (expected %u).\n",
5165 filter->filter, filter_state, graph->state);
5169 LeaveCriticalSection(&graph->cs);
5171 if (hr != VFW_S_STATE_INTERMEDIATE || (timeout != INFINITE && GetTickCount() >= end))
5172 break;
5174 IBaseFilter_GetState(async_filter, 10, &filter_state);
5176 EnterCriticalSection(&graph->cs);
5179 TRACE("Returning %#x, state %u.\n", hr, *state);
5180 return hr;
5183 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5185 struct filter_graph *This = impl_from_IMediaFilter(iface);
5186 struct filter *filter;
5187 HRESULT hr = S_OK;
5189 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
5191 EnterCriticalSection(&This->cs);
5193 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
5195 hr = IBaseFilter_SetSyncSource(filter->filter, pClock);
5196 if (FAILED(hr))
5197 break;
5200 if (FAILED(hr))
5202 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
5203 IBaseFilter_SetSyncSource(filter->filter, This->refClock);
5205 else
5207 if (This->refClock)
5208 IReferenceClock_Release(This->refClock);
5209 This->refClock = pClock;
5210 if (This->refClock)
5211 IReferenceClock_AddRef(This->refClock);
5212 This->defaultclock = FALSE;
5214 if (This->HandleEcClockChanged)
5216 IMediaEventSink *pEventSink;
5217 HRESULT eshr;
5219 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (void **)&pEventSink);
5220 if (SUCCEEDED(eshr))
5222 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5223 IMediaEventSink_Release(pEventSink);
5228 LeaveCriticalSection(&This->cs);
5230 return hr;
5233 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5235 struct filter_graph *This = impl_from_IMediaFilter(iface);
5237 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
5239 if (!ppClock)
5240 return E_POINTER;
5242 EnterCriticalSection(&This->cs);
5244 *ppClock = This->refClock;
5245 if (*ppClock)
5246 IReferenceClock_AddRef(*ppClock);
5248 LeaveCriticalSection(&This->cs);
5250 return S_OK;
5253 static const IMediaFilterVtbl IMediaFilter_VTable =
5255 MediaFilter_QueryInterface,
5256 MediaFilter_AddRef,
5257 MediaFilter_Release,
5258 MediaFilter_GetClassID,
5259 MediaFilter_Stop,
5260 MediaFilter_Pause,
5261 MediaFilter_Run,
5262 MediaFilter_GetState,
5263 MediaFilter_SetSyncSource,
5264 MediaFilter_GetSyncSource
5267 static struct filter_graph *impl_from_IMediaEventSink(IMediaEventSink *iface)
5269 return CONTAINING_RECORD(iface, struct filter_graph, IMediaEventSink_iface);
5272 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID iid, void **out)
5274 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5276 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5279 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5281 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5283 return IUnknown_AddRef(graph->outer_unk);
5286 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5288 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5290 return IUnknown_Release(graph->outer_unk);
5293 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG code,
5294 LONG_PTR param1, LONG_PTR param2)
5296 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5298 TRACE("graph %p, code %#x, param1 %#Ix, param2 %#Ix.\n", graph, code, param1, param2);
5300 EnterCriticalSection(&graph->event_cs);
5302 if (code == EC_COMPLETE && graph->HandleEcComplete)
5304 if (++graph->EcCompleteCount == graph->nRenderers)
5306 if (graph->media_events_disabled)
5307 SetEvent(graph->media_event_handle);
5308 else
5309 queue_media_event(graph, EC_COMPLETE, S_OK, 0);
5310 graph->CompletionStatus = EC_COMPLETE;
5311 graph->got_ec_complete = 1;
5312 SetEvent(graph->hEventCompletion);
5315 else if ((code == EC_REPAINT) && graph->HandleEcRepaint)
5317 FIXME("EC_REPAINT is not handled.\n");
5319 else if (!graph->media_events_disabled)
5321 queue_media_event(graph, code, param1, param2);
5324 LeaveCriticalSection(&graph->event_cs);
5325 return S_OK;
5328 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5330 MediaEventSink_QueryInterface,
5331 MediaEventSink_AddRef,
5332 MediaEventSink_Release,
5333 MediaEventSink_Notify
5336 static struct filter_graph *impl_from_IGraphConfig(IGraphConfig *iface)
5338 return CONTAINING_RECORD(iface, struct filter_graph, IGraphConfig_iface);
5341 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID iid, void **out)
5343 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5345 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5348 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5350 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5352 return IUnknown_AddRef(graph->outer_unk);
5355 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5357 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5359 return IUnknown_Release(graph->outer_unk);
5362 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *pOutputPin, IPin *pInputPin,
5363 const AM_MEDIA_TYPE *pmtFirstConnection, IBaseFilter *pUsingFilter, HANDLE hAbortEvent,
5364 DWORD dwFlags)
5366 struct filter_graph *This = impl_from_IGraphConfig(iface);
5368 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5369 strmbase_dump_media_type(pmtFirstConnection);
5371 return E_NOTIMPL;
5374 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface, IGraphConfigCallback *pCallback,
5375 void *pvContext, DWORD dwFlags, HANDLE hAbortEvent)
5377 struct filter_graph *This = impl_from_IGraphConfig(iface);
5378 HRESULT hr;
5380 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5382 if (hAbortEvent)
5383 FIXME("The parameter hAbortEvent is not handled!\n");
5385 EnterCriticalSection(&This->cs);
5387 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5389 LeaveCriticalSection(&This->cs);
5391 return hr;
5394 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5396 struct filter_graph *This = impl_from_IGraphConfig(iface);
5398 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5400 return E_NOTIMPL;
5403 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5405 struct filter_graph *This = impl_from_IGraphConfig(iface);
5407 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5409 return E_NOTIMPL;
5412 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5414 struct filter_graph *This = impl_from_IGraphConfig(iface);
5416 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5418 return E_NOTIMPL;
5421 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5423 struct filter_graph *This = impl_from_IGraphConfig(iface);
5425 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5427 return E_NOTIMPL;
5430 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5431 IPinConnection *pConnection, HANDLE hEventAbort)
5433 struct filter_graph *This = impl_from_IGraphConfig(iface);
5435 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5437 return E_NOTIMPL;
5440 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5441 DWORD dwFlags)
5443 struct filter_graph *This = impl_from_IGraphConfig(iface);
5445 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5447 return E_NOTIMPL;
5450 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5451 DWORD *dwFlags)
5453 struct filter_graph *This = impl_from_IGraphConfig(iface);
5455 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5457 return E_NOTIMPL;
5460 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *pFilter,
5461 DWORD dwFlags)
5463 struct filter_graph *This = impl_from_IGraphConfig(iface);
5465 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5467 return E_NOTIMPL;
5470 static const IGraphConfigVtbl IGraphConfig_VTable =
5472 GraphConfig_QueryInterface,
5473 GraphConfig_AddRef,
5474 GraphConfig_Release,
5475 GraphConfig_Reconnect,
5476 GraphConfig_Reconfigure,
5477 GraphConfig_AddFilterToCache,
5478 GraphConfig_EnumCacheFilter,
5479 GraphConfig_RemoveFilterFromCache,
5480 GraphConfig_GetStartTime,
5481 GraphConfig_PushThroughData,
5482 GraphConfig_SetFilterFlags,
5483 GraphConfig_GetFilterFlags,
5484 GraphConfig_RemoveFilterEx
5487 static struct filter_graph *impl_from_IGraphVersion(IGraphVersion *iface)
5489 return CONTAINING_RECORD(iface, struct filter_graph, IGraphVersion_iface);
5492 static HRESULT WINAPI GraphVersion_QueryInterface(IGraphVersion *iface, REFIID iid, void **out)
5494 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5496 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5499 static ULONG WINAPI GraphVersion_AddRef(IGraphVersion *iface)
5501 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5503 return IUnknown_AddRef(graph->outer_unk);
5506 static ULONG WINAPI GraphVersion_Release(IGraphVersion *iface)
5508 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5510 return IUnknown_Release(graph->outer_unk);
5513 static HRESULT WINAPI GraphVersion_QueryVersion(IGraphVersion *iface, LONG *pVersion)
5515 struct filter_graph *This = impl_from_IGraphVersion(iface);
5517 if(!pVersion)
5518 return E_POINTER;
5520 TRACE("(%p)->(%p): current version %i\n", This, pVersion, This->version);
5522 *pVersion = This->version;
5523 return S_OK;
5526 static const IGraphVersionVtbl IGraphVersion_VTable =
5528 GraphVersion_QueryInterface,
5529 GraphVersion_AddRef,
5530 GraphVersion_Release,
5531 GraphVersion_QueryVersion,
5534 static struct filter_graph *impl_from_IVideoFrameStep(IVideoFrameStep *iface)
5536 return CONTAINING_RECORD(iface, struct filter_graph, IVideoFrameStep_iface);
5539 static HRESULT WINAPI VideoFrameStep_QueryInterface(IVideoFrameStep *iface, REFIID iid, void **out)
5541 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5542 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5545 static ULONG WINAPI VideoFrameStep_AddRef(IVideoFrameStep *iface)
5547 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5548 return IUnknown_AddRef(graph->outer_unk);
5551 static ULONG WINAPI VideoFrameStep_Release(IVideoFrameStep *iface)
5553 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5554 return IUnknown_Release(graph->outer_unk);
5557 static HRESULT WINAPI VideoFrameStep_Step(IVideoFrameStep *iface, DWORD frame_count, IUnknown *filter)
5559 FIXME("iface %p, frame_count %u, filter %p, stub!\n", iface, frame_count, filter);
5560 return E_NOTIMPL;
5563 static HRESULT WINAPI VideoFrameStep_CanStep(IVideoFrameStep *iface, LONG multiple, IUnknown *filter)
5565 FIXME("iface %p, multiple %d, filter %p, stub!\n", iface, multiple, filter);
5566 return E_NOTIMPL;
5569 static HRESULT WINAPI VideoFrameStep_CancelStep(IVideoFrameStep *iface)
5571 FIXME("iface %p, stub!\n", iface);
5572 return E_NOTIMPL;
5575 static const IVideoFrameStepVtbl VideoFrameStep_vtbl =
5577 VideoFrameStep_QueryInterface,
5578 VideoFrameStep_AddRef,
5579 VideoFrameStep_Release,
5580 VideoFrameStep_Step,
5581 VideoFrameStep_CanStep,
5582 VideoFrameStep_CancelStep
5585 static const IUnknownVtbl IInner_VTable =
5587 FilterGraphInner_QueryInterface,
5588 FilterGraphInner_AddRef,
5589 FilterGraphInner_Release
5592 static HRESULT filter_graph_common_create(IUnknown *outer, IUnknown **out, BOOL threaded)
5594 struct filter_graph *object;
5595 HRESULT hr;
5597 *out = NULL;
5599 if (!(object = calloc(1, sizeof(*object))))
5600 return E_OUTOFMEMORY;
5602 object->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5603 object->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5604 object->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5605 object->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5606 object->IGraphVersion_iface.lpVtbl = &IGraphVersion_VTable;
5607 object->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5608 object->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5609 object->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5610 object->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5611 object->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5612 object->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5613 object->IObjectWithSite_iface.lpVtbl = &IObjectWithSite_VTable;
5614 object->IUnknown_inner.lpVtbl = &IInner_VTable;
5615 object->IVideoFrameStep_iface.lpVtbl = &VideoFrameStep_vtbl;
5616 object->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5617 object->ref = 1;
5618 object->outer_unk = outer ? outer : &object->IUnknown_inner;
5620 if (FAILED(hr = CoCreateInstance(&CLSID_FilterMapper2, object->outer_unk,
5621 CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&object->punkFilterMapper2)))
5623 ERR("Failed to create filter mapper, hr %#x.\n", hr);
5624 free(object);
5625 return hr;
5628 InitializeCriticalSection(&object->cs);
5629 object->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": filter_graph.cs");
5630 InitializeCriticalSection(&object->event_cs);
5631 object->event_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": filter_graph.event_cs");
5633 object->defaultclock = TRUE;
5635 object->media_event_handle = CreateEventW(NULL, TRUE, FALSE, NULL);
5636 list_init(&object->media_events);
5637 list_init(&object->filters);
5638 object->HandleEcClockChanged = TRUE;
5639 object->HandleEcComplete = TRUE;
5640 object->HandleEcRepaint = TRUE;
5641 object->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5643 object->name_index = 1;
5644 object->timeformatseek = TIME_FORMAT_MEDIA_TIME;
5646 if (threaded)
5648 object->message_thread_ret = CreateEventW(NULL, FALSE, FALSE, NULL);
5649 object->message_thread = CreateThread(NULL, 0, message_thread_run, object, 0, &object->message_thread_id);
5650 WaitForSingleObject(object->message_thread_ret, INFINITE);
5652 else
5653 object->message_thread = NULL;
5655 TRACE("Created %sthreaded filter graph %p.\n", threaded ? "" : "non-", object);
5656 *out = &object->IUnknown_inner;
5657 return S_OK;
5660 HRESULT filter_graph_create(IUnknown *outer, IUnknown **out)
5662 return filter_graph_common_create(outer, out, TRUE);
5665 HRESULT filter_graph_no_thread_create(IUnknown *outer, IUnknown **out)
5667 return filter_graph_common_create(outer, out, FALSE);