xmllite/writer: Implement WriteNodeShallow().
[wine.git] / dlls / quartz / filtergraph.c
blob1849174cf97232e06ea8677f7096c23907d56d35
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 FILTER_STATE 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 %lu.\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 %lu.\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 %lu, 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 %lu.\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 *graph = impl_from_IUnknown(iface);
422 ULONG refcount = InterlockedIncrement(&graph->ref);
424 TRACE("%p increasing refcount to %lu.\n", graph, refcount);
426 return refcount;
429 static ULONG WINAPI FilterGraphInner_Release(IUnknown *iface)
431 struct filter_graph *This = impl_from_IUnknown(iface);
432 ULONG refcount = InterlockedDecrement(&This->ref);
433 struct list *cursor;
435 TRACE("%p decreasing refcount to %lu.\n", This, refcount);
437 if (!refcount)
439 int i;
441 This->ref = 1; /* guard against reentrancy (aggregation). */
443 IMediaControl_Stop(&This->IMediaControl_iface);
445 while ((cursor = list_head(&This->filters)))
447 struct filter *filter = LIST_ENTRY(cursor, struct filter, entry);
449 IFilterGraph2_RemoveFilter(&This->IFilterGraph2_iface, filter->filter);
452 if (This->refClock)
453 IReferenceClock_Release(This->refClock);
455 for (i = 0; i < This->nItfCacheEntries; i++)
457 if (This->ItfCacheEntries[i].iface)
458 IUnknown_Release(This->ItfCacheEntries[i].iface);
461 IUnknown_Release(This->punkFilterMapper2);
463 if (This->pSite) IUnknown_Release(This->pSite);
465 flush_media_events(This);
466 CloseHandle(This->media_event_handle);
468 This->cs.DebugInfo->Spare[0] = 0;
469 if (This->message_thread)
471 PostThreadMessageW(This->message_thread_id, WM_USER + 1, 0, 0);
472 WaitForSingleObject(This->message_thread, INFINITE);
473 CloseHandle(This->message_thread);
474 CloseHandle(This->message_thread_ret);
476 DeleteCriticalSection(&This->event_cs);
477 DeleteCriticalSection(&This->cs);
478 free(This);
480 return refcount;
483 static struct filter_graph *impl_from_IFilterGraph2(IFilterGraph2 *iface)
485 return CONTAINING_RECORD(iface, struct filter_graph, IFilterGraph2_iface);
488 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface, REFIID iid, void **out)
490 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
491 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
494 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface)
496 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
497 return IUnknown_AddRef(graph->outer_unk);
500 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface)
502 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
503 return IUnknown_Release(graph->outer_unk);
506 static IBaseFilter *find_filter_by_name(struct filter_graph *graph, const WCHAR *name)
508 struct filter *filter;
510 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
512 if (!wcscmp(filter->name, name))
513 return filter->filter;
516 return NULL;
519 static BOOL has_output_pins(IBaseFilter *filter)
521 IEnumPins *enumpins;
522 PIN_DIRECTION dir;
523 IPin *pin;
525 if (FAILED(IBaseFilter_EnumPins(filter, &enumpins)))
526 return FALSE;
528 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
530 IPin_QueryDirection(pin, &dir);
531 IPin_Release(pin);
532 if (dir == PINDIR_OUTPUT)
534 IEnumPins_Release(enumpins);
535 return TRUE;
539 IEnumPins_Release(enumpins);
540 return FALSE;
543 static void update_seeking(struct filter *filter)
545 IMediaSeeking *seeking;
547 if (!filter->seeking)
549 /* The Legend of Heroes: Trails of Cold Steel II destroys its filter when
550 * its IMediaSeeking interface is released, so cache the interface instead
551 * of querying for it every time.
552 * Some filters (e.g. MediaStreamFilter) can become seekable when they are
553 * already in the graph, so always try to query IMediaSeeking if it's not
554 * cached yet. */
555 if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IMediaSeeking, (void **)&seeking)))
557 if (IMediaSeeking_IsFormatSupported(seeking, &TIME_FORMAT_MEDIA_TIME) == S_OK)
558 filter->seeking = seeking;
559 else
560 IMediaSeeking_Release(seeking);
565 static BOOL is_renderer(struct filter *filter)
567 IMediaPosition *media_position;
568 IAMFilterMiscFlags *flags;
569 BOOL ret = FALSE;
571 if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IAMFilterMiscFlags, (void **)&flags)))
573 if (IAMFilterMiscFlags_GetMiscFlags(flags) & AM_FILTER_MISC_FLAGS_IS_RENDERER)
574 ret = TRUE;
575 IAMFilterMiscFlags_Release(flags);
577 else if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IMediaPosition, (void **)&media_position)))
579 if (!has_output_pins(filter->filter))
580 ret = TRUE;
581 IMediaPosition_Release(media_position);
583 else
585 update_seeking(filter);
586 if (filter->seeking && !has_output_pins(filter->filter))
587 ret = TRUE;
589 return ret;
592 /*** IFilterGraph methods ***/
593 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface,
594 IBaseFilter *filter, const WCHAR *name)
596 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
597 BOOL duplicate_name = FALSE;
598 struct filter *entry;
599 unsigned int i;
600 HRESULT hr;
602 TRACE("graph %p, filter %p, name %s.\n", graph, filter, debugstr_w(name));
604 if (!filter)
605 return E_POINTER;
607 if (!(entry = heap_alloc(sizeof(*entry))))
608 return E_OUTOFMEMORY;
610 if (!(entry->name = CoTaskMemAlloc((name ? wcslen(name) + 6 : 5) * sizeof(WCHAR))))
612 heap_free(entry);
613 return E_OUTOFMEMORY;
616 if (name && find_filter_by_name(graph, name))
617 duplicate_name = TRUE;
619 if (!name || duplicate_name)
621 for (i = 0; i < 10000 ; ++i)
623 if (name)
624 swprintf(entry->name, name ? wcslen(name) + 6 : 5, L"%s %04u", name, graph->name_index);
625 else
626 swprintf(entry->name, name ? wcslen(name) + 6 : 5, L"%04u", graph->name_index);
628 graph->name_index = (graph->name_index + 1) % 10000;
630 if (!find_filter_by_name(graph, entry->name))
631 break;
634 if (i == 10000)
636 CoTaskMemFree(entry->name);
637 heap_free(entry);
638 return VFW_E_DUPLICATE_NAME;
641 else
642 wcscpy(entry->name, name);
644 if (FAILED(hr = IBaseFilter_JoinFilterGraph(filter,
645 (IFilterGraph *)&graph->IFilterGraph2_iface, entry->name)))
647 CoTaskMemFree(entry->name);
648 heap_free(entry);
649 return hr;
652 IBaseFilter_AddRef(entry->filter = filter);
654 list_add_head(&graph->filters, &entry->entry);
655 entry->sorting = FALSE;
656 entry->seeking = NULL;
657 ++graph->version;
659 return duplicate_name ? VFW_S_DUPLICATE_NAME : hr;
662 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
664 struct filter_graph *This = impl_from_IFilterGraph2(iface);
665 struct filter *entry;
666 int i;
667 HRESULT hr = E_FAIL;
669 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
671 LIST_FOR_EACH_ENTRY(entry, &This->filters, struct filter, entry)
673 if (entry->filter == pFilter)
675 IEnumPins *penumpins = NULL;
677 if (This->defaultclock && This->refClockProvider == pFilter)
679 IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, NULL);
680 This->defaultclock = TRUE;
683 TRACE("Removing filter %s.\n", debugstr_w(entry->name));
685 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
686 if (SUCCEEDED(hr)) {
687 IPin *ppin;
688 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
690 IPin *peer = NULL;
691 HRESULT hr;
693 IPin_ConnectedTo(ppin, &peer);
694 if (peer)
696 if (FAILED(hr = IPin_Disconnect(peer)))
698 WARN("Failed to disconnect peer %p, hr %#lx.\n", peer, hr);
699 IPin_Release(peer);
700 IPin_Release(ppin);
701 IEnumPins_Release(penumpins);
702 return hr;
704 IPin_Release(peer);
706 if (FAILED(hr = IPin_Disconnect(ppin)))
708 WARN("Failed to disconnect pin %p, hr %#lx.\n", ppin, hr);
709 IPin_Release(ppin);
710 IEnumPins_Release(penumpins);
711 return hr;
714 IPin_Release(ppin);
716 IEnumPins_Release(penumpins);
719 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, NULL);
720 if (SUCCEEDED(hr))
722 IBaseFilter_SetSyncSource(pFilter, NULL);
723 IBaseFilter_Release(pFilter);
724 if (entry->seeking)
725 IMediaSeeking_Release(entry->seeking);
726 list_remove(&entry->entry);
727 CoTaskMemFree(entry->name);
728 heap_free(entry);
729 This->version++;
730 /* Invalidate interfaces in the cache */
731 for (i = 0; i < This->nItfCacheEntries; i++)
732 if (pFilter == This->ItfCacheEntries[i].filter)
734 IUnknown_Release(This->ItfCacheEntries[i].iface);
735 This->ItfCacheEntries[i].iface = NULL;
736 This->ItfCacheEntries[i].filter = NULL;
738 return S_OK;
740 break;
744 return hr; /* FIXME: check this error code */
747 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface, IEnumFilters **out)
749 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
751 TRACE("graph %p, out %p.\n", graph, out);
753 return create_enum_filters(graph, list_head(&graph->filters), out);
756 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface,
757 const WCHAR *name, IBaseFilter **filter)
759 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
761 TRACE("graph %p, name %s, filter %p.\n", graph, debugstr_w(name), filter);
763 if (!filter)
764 return E_POINTER;
766 if ((*filter = find_filter_by_name(graph, name)))
768 IBaseFilter_AddRef(*filter);
769 return S_OK;
772 return VFW_E_NOT_FOUND;
775 static HRESULT check_cyclic_connection(IPin *source, IPin *sink)
777 IPin *upstream_source, *upstream_sink;
778 PIN_INFO source_info, sink_info;
779 IEnumPins *enumpins;
780 HRESULT hr;
782 hr = IPin_QueryPinInfo(sink, &sink_info);
783 if (FAILED(hr))
785 ERR("Failed to query pin, hr %#lx.\n", hr);
786 return hr;
788 IBaseFilter_Release(sink_info.pFilter);
790 hr = IPin_QueryPinInfo(source, &source_info);
791 if (FAILED(hr))
793 ERR("Failed to query pin, hr %#lx.\n", hr);
794 return hr;
797 if (sink_info.pFilter == source_info.pFilter)
799 WARN("Cyclic connection detected; returning VFW_E_CIRCULAR_GRAPH.\n");
800 IBaseFilter_Release(source_info.pFilter);
801 return VFW_E_CIRCULAR_GRAPH;
804 hr = IBaseFilter_EnumPins(source_info.pFilter, &enumpins);
805 if (FAILED(hr))
807 ERR("Failed to enumerate pins, hr %#lx.\n", hr);
808 IBaseFilter_Release(source_info.pFilter);
809 return hr;
812 while ((hr = IEnumPins_Next(enumpins, 1, &upstream_sink, NULL)) == S_OK)
814 PIN_DIRECTION dir = PINDIR_OUTPUT;
816 IPin_QueryDirection(upstream_sink, &dir);
817 if (dir == PINDIR_INPUT && IPin_ConnectedTo(upstream_sink, &upstream_source) == S_OK)
819 hr = check_cyclic_connection(upstream_source, sink);
820 IPin_Release(upstream_source);
821 if (FAILED(hr))
823 IPin_Release(upstream_sink);
824 IEnumPins_Release(enumpins);
825 IBaseFilter_Release(source_info.pFilter);
826 return hr;
829 IPin_Release(upstream_sink);
831 IEnumPins_Release(enumpins);
833 IBaseFilter_Release(source_info.pFilter);
834 return S_OK;
837 static struct filter *find_sorted_filter(struct filter_graph *graph, IBaseFilter *iface)
839 struct filter *filter;
841 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
843 if (filter->filter == iface)
844 return filter;
847 return NULL;
850 static void sort_filter_recurse(struct filter_graph *graph, struct filter *filter, struct list *sorted)
852 struct filter *peer_filter;
853 IEnumPins *enumpins;
854 PIN_DIRECTION dir;
855 IPin *pin, *peer;
856 PIN_INFO info;
858 TRACE("Sorting filter %p.\n", filter->filter);
860 /* Cyclic connections should be caught by check_cyclic_connection(). */
861 assert(!filter->sorting);
863 filter->sorting = TRUE;
865 IBaseFilter_EnumPins(filter->filter, &enumpins);
866 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
868 IPin_QueryDirection(pin, &dir);
870 if (dir == PINDIR_INPUT && IPin_ConnectedTo(pin, &peer) == S_OK)
872 IPin_QueryPinInfo(peer, &info);
873 /* Note that the filter may have already been sorted. */
874 if ((peer_filter = find_sorted_filter(graph, info.pFilter)))
875 sort_filter_recurse(graph, peer_filter, sorted);
876 IBaseFilter_Release(info.pFilter);
877 IPin_Release(peer);
879 IPin_Release(pin);
881 IEnumPins_Release(enumpins);
883 filter->sorting = FALSE;
885 list_remove(&filter->entry);
886 list_add_head(sorted, &filter->entry);
889 static void sort_filters(struct filter_graph *graph)
891 struct list sorted = LIST_INIT(sorted), *cursor;
893 while ((cursor = list_head(&graph->filters)))
895 struct filter *filter = LIST_ENTRY(cursor, struct filter, entry);
896 sort_filter_recurse(graph, filter, &sorted);
899 list_move_tail(&graph->filters, &sorted);
902 /* NOTE: despite the implication, it doesn't matter which
903 * way round you put in the input and output pins */
904 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppinIn, IPin *ppinOut,
905 const AM_MEDIA_TYPE *pmt)
907 struct filter_graph *This = impl_from_IFilterGraph2(iface);
908 PIN_DIRECTION dir;
909 HRESULT hr;
911 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
912 strmbase_dump_media_type(pmt);
914 /* FIXME: check pins are in graph */
916 if (TRACE_ON(quartz))
918 PIN_INFO PinInfo;
920 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
921 if (FAILED(hr))
922 return hr;
924 TRACE("Filter owning ppinIn(%p) => %p\n", ppinIn, PinInfo.pFilter);
925 IBaseFilter_Release(PinInfo.pFilter);
927 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
928 if (FAILED(hr))
929 return hr;
931 TRACE("Filter owning ppinOut(%p) => %p\n", ppinOut, PinInfo.pFilter);
932 IBaseFilter_Release(PinInfo.pFilter);
935 hr = IPin_QueryDirection(ppinIn, &dir);
936 if (SUCCEEDED(hr))
938 if (dir == PINDIR_INPUT)
940 hr = check_cyclic_connection(ppinOut, ppinIn);
941 if (SUCCEEDED(hr))
942 hr = IPin_Connect(ppinOut, ppinIn, pmt);
944 else
946 hr = check_cyclic_connection(ppinIn, ppinOut);
947 if (SUCCEEDED(hr))
948 hr = IPin_Connect(ppinIn, ppinOut, pmt);
952 return hr;
955 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface, IPin *pin)
957 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
959 TRACE("graph %p, pin %p.\n", graph, pin);
961 return IFilterGraph2_ReconnectEx(iface, pin, NULL);
964 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
966 struct filter_graph *This = impl_from_IFilterGraph2(iface);
968 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
970 if (!ppin)
971 return E_POINTER;
973 return IPin_Disconnect(ppin);
976 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
978 struct filter_graph *This = impl_from_IFilterGraph2(iface);
979 IReferenceClock *pClock = NULL;
980 struct filter *filter;
981 HRESULT hr = S_OK;
983 TRACE("(%p/%p)->() live sources not handled properly!\n", This, iface);
985 EnterCriticalSection(&This->cs);
987 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
989 if (IBaseFilter_QueryInterface(filter->filter, &IID_IReferenceClock, (void **)&pClock) == S_OK)
990 break;
993 if (!pClock)
995 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
996 This->refClockProvider = NULL;
998 else
1000 filter = LIST_ENTRY(list_tail(&This->filters), struct filter, entry);
1001 This->refClockProvider = filter->filter;
1004 if (SUCCEEDED(hr))
1006 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
1007 This->defaultclock = TRUE;
1008 IReferenceClock_Release(pClock);
1010 LeaveCriticalSection(&This->cs);
1012 return hr;
1015 struct filter_create_params
1017 HRESULT hr;
1018 IMoniker *moniker;
1019 IBaseFilter *filter;
1022 static DWORD WINAPI message_thread_run(void *ctx)
1024 struct filter_graph *graph = ctx;
1025 MSG msg;
1027 /* Make sure we have a message queue. */
1028 PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE);
1029 SetEvent(graph->message_thread_ret);
1031 CoInitializeEx(NULL, COINIT_MULTITHREADED);
1033 for (;;)
1035 GetMessageW(&msg, NULL, 0, 0);
1037 if (!msg.hwnd && msg.message == WM_USER)
1039 struct filter_create_params *params = (struct filter_create_params *)msg.wParam;
1041 params->hr = IMoniker_BindToObject(params->moniker, NULL, NULL,
1042 &IID_IBaseFilter, (void **)&params->filter);
1043 SetEvent(graph->message_thread_ret);
1045 else if (!msg.hwnd && msg.message == WM_USER + 1)
1047 break;
1049 else
1051 TranslateMessage(&msg);
1052 DispatchMessageW(&msg);
1056 CoUninitialize();
1057 return 0;
1060 static HRESULT create_filter(struct filter_graph *graph, IMoniker *moniker, IBaseFilter **filter)
1062 if (graph->message_thread)
1064 struct filter_create_params params;
1066 params.moniker = moniker;
1067 PostThreadMessageW(graph->message_thread_id, WM_USER, (WPARAM)&params, 0);
1068 WaitForSingleObject(graph->message_thread_ret, INFINITE);
1069 *filter = params.filter;
1070 return params.hr;
1072 else
1073 return IMoniker_BindToObject(moniker, NULL, NULL, &IID_IBaseFilter, (void **)filter);
1076 static HRESULT autoplug(struct filter_graph *graph, IPin *source, IPin *sink,
1077 BOOL render_to_existing, unsigned int recursion_depth);
1079 static HRESULT autoplug_through_sink(struct filter_graph *graph, IPin *source,
1080 IBaseFilter *filter, IPin *middle_sink, IPin *sink,
1081 BOOL render_to_existing, unsigned int recursion_depth)
1083 BOOL any = FALSE, all = TRUE;
1084 IPin *middle_source, *peer;
1085 IEnumPins *source_enum;
1086 PIN_DIRECTION dir;
1087 PIN_INFO info;
1088 HRESULT hr;
1090 TRACE("Trying to autoplug %p to %p through %p.\n", source, sink, middle_sink);
1092 IPin_QueryDirection(middle_sink, &dir);
1093 if (dir != PINDIR_INPUT)
1094 return E_FAIL;
1096 if (IPin_ConnectedTo(middle_sink, &peer) == S_OK)
1098 IPin_Release(peer);
1099 return E_FAIL;
1102 if (FAILED(hr = IFilterGraph2_ConnectDirect(&graph->IFilterGraph2_iface, source, middle_sink, NULL)))
1103 return E_FAIL;
1105 if (FAILED(hr = IBaseFilter_EnumPins(filter, &source_enum)))
1106 goto err;
1108 while (IEnumPins_Next(source_enum, 1, &middle_source, NULL) == S_OK)
1110 IPin_QueryPinInfo(middle_source, &info);
1111 IBaseFilter_Release(info.pFilter);
1112 if (info.dir != PINDIR_OUTPUT)
1114 IPin_Release(middle_source);
1115 continue;
1117 if (info.achName[0] == '~')
1119 TRACE("Skipping non-rendered pin %s.\n", debugstr_w(info.achName));
1120 IPin_Release(middle_source);
1121 continue;
1123 if (IPin_ConnectedTo(middle_source, &peer) == S_OK)
1125 IPin_Release(peer);
1126 IPin_Release(middle_source);
1127 continue;
1130 hr = autoplug(graph, middle_source, sink, render_to_existing, recursion_depth + 1);
1131 IPin_Release(middle_source);
1132 if (SUCCEEDED(hr) && sink)
1134 IEnumPins_Release(source_enum);
1135 return hr;
1137 if (SUCCEEDED(hr))
1138 any = TRUE;
1139 if (hr != S_OK)
1140 all = FALSE;
1142 IEnumPins_Release(source_enum);
1144 if (!sink)
1146 if (all)
1147 return S_OK;
1148 if (any)
1149 return VFW_S_PARTIAL_RENDER;
1152 err:
1153 IFilterGraph2_Disconnect(&graph->IFilterGraph2_iface, source);
1154 IFilterGraph2_Disconnect(&graph->IFilterGraph2_iface, middle_sink);
1155 return E_FAIL;
1158 static HRESULT autoplug_through_filter(struct filter_graph *graph, IPin *source,
1159 IBaseFilter *filter, IPin *sink, BOOL render_to_existing,
1160 unsigned int recursion_depth)
1162 IEnumPins *sink_enum;
1163 IPin *filter_sink;
1164 HRESULT hr;
1166 TRACE("Trying to autoplug %p to %p through %p.\n", source, sink, filter);
1168 if (FAILED(hr = IBaseFilter_EnumPins(filter, &sink_enum)))
1169 return hr;
1171 while (IEnumPins_Next(sink_enum, 1, &filter_sink, NULL) == S_OK)
1173 hr = autoplug_through_sink(graph, source, filter, filter_sink, sink,
1174 render_to_existing, recursion_depth);
1175 IPin_Release(filter_sink);
1176 if (SUCCEEDED(hr))
1178 IEnumPins_Release(sink_enum);
1179 return hr;
1182 IEnumPins_Release(sink_enum);
1183 return VFW_E_CANNOT_CONNECT;
1186 /* Common helper for IGraphBuilder::Connect() and IGraphBuilder::Render(), which
1187 * share most of the same code. Render() calls this with a NULL sink. */
1188 static HRESULT autoplug(struct filter_graph *graph, IPin *source, IPin *sink,
1189 BOOL render_to_existing, unsigned int recursion_depth)
1191 IAMGraphBuilderCallback *callback = NULL;
1192 IEnumMediaTypes *enummt;
1193 IFilterMapper2 *mapper;
1194 struct filter *filter;
1195 AM_MEDIA_TYPE *mt;
1196 HRESULT hr;
1198 TRACE("Trying to autoplug %p to %p, recursion depth %u.\n", source, sink, recursion_depth);
1200 if (recursion_depth >= 5)
1202 WARN("Recursion depth has reached 5; aborting.\n");
1203 return VFW_E_CANNOT_CONNECT;
1206 if (sink)
1208 /* Try to connect directly to this sink. */
1209 hr = IFilterGraph2_ConnectDirect(&graph->IFilterGraph2_iface, source, sink, NULL);
1211 /* If direct connection succeeded, we should propagate that return value.
1212 * If it returned VFW_E_NOT_CONNECTED or VFW_E_NO_AUDIO_HARDWARE, then don't
1213 * even bother trying intermediate filters, since they won't succeed. */
1214 if (SUCCEEDED(hr) || hr == VFW_E_NOT_CONNECTED || hr == VFW_E_NO_AUDIO_HARDWARE)
1215 return hr;
1218 /* Always prefer filters in the graph. */
1219 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1221 if (SUCCEEDED(hr = autoplug_through_filter(graph, source, filter->filter,
1222 sink, render_to_existing, recursion_depth)))
1223 return hr;
1226 IUnknown_QueryInterface(graph->punkFilterMapper2, &IID_IFilterMapper2, (void **)&mapper);
1228 if (FAILED(hr = IPin_EnumMediaTypes(source, &enummt)))
1230 IFilterMapper2_Release(mapper);
1231 return hr;
1234 if (graph->pSite)
1235 IUnknown_QueryInterface(graph->pSite, &IID_IAMGraphBuilderCallback, (void **)&callback);
1237 while (IEnumMediaTypes_Next(enummt, 1, &mt, NULL) == S_OK)
1239 GUID types[2] = {mt->majortype, mt->subtype};
1240 IEnumMoniker *enummoniker;
1241 IBaseFilter *filter;
1242 IMoniker *moniker;
1244 DeleteMediaType(mt);
1246 if (FAILED(hr = IFilterMapper2_EnumMatchingFilters(mapper, &enummoniker,
1247 0, FALSE, MERIT_UNLIKELY, TRUE, 1, types, NULL, NULL, FALSE,
1248 render_to_existing, 0, NULL, NULL, NULL)))
1249 goto out;
1251 while (IEnumMoniker_Next(enummoniker, 1, &moniker, NULL) == S_OK)
1253 IPropertyBag *bag;
1254 VARIANT var;
1256 VariantInit(&var);
1257 IMoniker_BindToStorage(moniker, NULL, NULL, &IID_IPropertyBag, (void **)&bag);
1258 hr = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL);
1259 IPropertyBag_Release(bag);
1260 if (FAILED(hr))
1262 IMoniker_Release(moniker);
1263 continue;
1266 if (callback && FAILED(hr = IAMGraphBuilderCallback_SelectedFilter(callback, moniker)))
1268 TRACE("Filter rejected by IAMGraphBuilderCallback::SelectedFilter(), hr %#lx.\n", hr);
1269 IMoniker_Release(moniker);
1270 continue;
1273 hr = create_filter(graph, moniker, &filter);
1274 IMoniker_Release(moniker);
1275 if (FAILED(hr))
1277 ERR("Failed to create filter for %s, hr %#lx.\n", debugstr_w(V_BSTR(&var)), hr);
1278 VariantClear(&var);
1279 continue;
1282 if (callback && FAILED(hr = IAMGraphBuilderCallback_CreatedFilter(callback, filter)))
1284 TRACE("Filter rejected by IAMGraphBuilderCallback::CreatedFilter(), hr %#lx.\n", hr);
1285 IBaseFilter_Release(filter);
1286 continue;
1289 hr = IFilterGraph2_AddFilter(&graph->IFilterGraph2_iface, filter, V_BSTR(&var));
1290 VariantClear(&var);
1291 if (FAILED(hr))
1293 ERR("Failed to add filter, hr %#lx.\n", hr);
1294 IBaseFilter_Release(filter);
1295 continue;
1298 hr = autoplug_through_filter(graph, source, filter, sink, render_to_existing, recursion_depth);
1299 if (SUCCEEDED(hr))
1301 IBaseFilter_Release(filter);
1302 goto out;
1305 IFilterGraph2_RemoveFilter(&graph->IFilterGraph2_iface, filter);
1306 IBaseFilter_Release(filter);
1308 IEnumMoniker_Release(enummoniker);
1311 hr = VFW_E_CANNOT_CONNECT;
1313 out:
1314 if (callback) IAMGraphBuilderCallback_Release(callback);
1315 IEnumMediaTypes_Release(enummt);
1316 IFilterMapper2_Release(mapper);
1317 return hr;
1320 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *source, IPin *sink)
1322 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1323 PIN_DIRECTION dir;
1324 HRESULT hr;
1326 TRACE("graph %p, source %p, sink %p.\n", graph, source, sink);
1328 if (!source || !sink)
1329 return E_POINTER;
1331 if (FAILED(hr = IPin_QueryDirection(source, &dir)))
1332 return hr;
1334 if (dir == PINDIR_INPUT)
1336 IPin *temp;
1338 TRACE("Directions seem backwards, swapping pins\n");
1340 temp = sink;
1341 sink = source;
1342 source = temp;
1345 EnterCriticalSection(&graph->cs);
1347 hr = autoplug(graph, source, sink, TRUE, 0);
1349 LeaveCriticalSection(&graph->cs);
1351 TRACE("Returning %#lx.\n", hr);
1352 return hr;
1355 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *source)
1357 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1358 HRESULT hr;
1360 TRACE("graph %p, source %p.\n", graph, source);
1362 EnterCriticalSection(&graph->cs);
1363 hr = autoplug(graph, source, NULL, FALSE, 0);
1364 LeaveCriticalSection(&graph->cs);
1365 if (hr == VFW_E_CANNOT_CONNECT)
1366 hr = VFW_E_CANNOT_RENDER;
1368 TRACE("Returning %#lx.\n", hr);
1369 return hr;
1372 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface, LPCWSTR lpcwstrFile,
1373 LPCWSTR lpcwstrPlayList)
1375 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1376 IBaseFilter* preader = NULL;
1377 IPin* ppinreader = NULL;
1378 IEnumPins* penumpins = NULL;
1379 struct filter *filter;
1380 HRESULT hr;
1381 BOOL partial = FALSE;
1382 BOOL any = FALSE;
1384 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1386 if (lpcwstrPlayList != NULL)
1387 return E_INVALIDARG;
1389 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, L"Reader", &preader);
1390 if (FAILED(hr))
1391 return hr;
1393 hr = IBaseFilter_EnumPins(preader, &penumpins);
1394 if (SUCCEEDED(hr))
1396 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1398 PIN_DIRECTION dir;
1400 IPin_QueryDirection(ppinreader, &dir);
1401 if (dir == PINDIR_OUTPUT)
1403 hr = IFilterGraph2_Render(iface, ppinreader);
1405 TRACE("Filters in chain:\n");
1406 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
1407 TRACE("- %s.\n", debugstr_w(filter->name));
1409 if (SUCCEEDED(hr))
1410 any = TRUE;
1411 if (hr != S_OK)
1412 partial = TRUE;
1414 IPin_Release(ppinreader);
1416 IEnumPins_Release(penumpins);
1418 if (!any)
1420 if (FAILED(hr = IFilterGraph2_RemoveFilter(iface, preader)))
1421 ERR("Failed to remove source filter, hr %#lx.\n", hr);
1422 hr = VFW_E_CANNOT_RENDER;
1424 else if (partial)
1426 hr = VFW_S_PARTIAL_RENDER;
1428 else
1430 hr = S_OK;
1433 IBaseFilter_Release(preader);
1435 TRACE("Returning %#lx.\n", hr);
1436 return hr;
1439 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface,
1440 const WCHAR *filename, const WCHAR *filter_name, IBaseFilter **ret_filter)
1442 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1443 IFileSourceFilter *filesource;
1444 IBaseFilter *filter;
1445 HRESULT hr;
1446 GUID clsid;
1448 TRACE("graph %p, filename %s, filter_name %s, ret_filter %p.\n",
1449 graph, debugstr_w(filename), debugstr_w(filter_name), ret_filter);
1451 if (!get_media_type(filename, NULL, NULL, &clsid))
1452 clsid = CLSID_AsyncReader;
1453 TRACE("Using source filter %s.\n", debugstr_guid(&clsid));
1455 if (FAILED(hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER,
1456 &IID_IBaseFilter, (void **)&filter)))
1458 WARN("Failed to create filter, hr %#lx.\n", hr);
1459 return hr;
1462 if (FAILED(hr = IBaseFilter_QueryInterface(filter, &IID_IFileSourceFilter, (void **)&filesource)))
1464 WARN("Failed to get IFileSourceFilter, hr %#lx.\n", hr);
1465 IBaseFilter_Release(filter);
1466 return hr;
1469 hr = IFileSourceFilter_Load(filesource, filename, NULL);
1470 IFileSourceFilter_Release(filesource);
1471 if (FAILED(hr))
1473 WARN("Failed to load file, hr %#lx.\n", hr);
1474 return hr;
1477 if (FAILED(hr = IFilterGraph2_AddFilter(iface, filter, filter_name)))
1479 IBaseFilter_Release(filter);
1480 return hr;
1483 if (ret_filter)
1484 *ret_filter = filter;
1485 return S_OK;
1488 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR file)
1490 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1492 TRACE("graph %p, file %#Ix.\n", graph, file);
1494 return S_OK;
1497 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1499 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1501 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1503 return S_OK;
1506 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1508 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1510 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1512 return S_OK;
1515 /*** IFilterGraph2 methods ***/
1516 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1517 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1519 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1520 HRESULT hr;
1521 IBaseFilter* pfilter;
1523 TRACE("(%p/%p)->(%p %p %s %p)\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1525 hr = IMoniker_BindToObject(pMoniker, pCtx, NULL, &IID_IBaseFilter, (void**)&pfilter);
1526 if(FAILED(hr)) {
1527 WARN("Failed to bind moniker, hr %#lx.\n", hr);
1528 return hr;
1531 hr = IFilterGraph2_AddFilter(iface, pfilter, lpcwstrFilterName);
1532 if (FAILED(hr)) {
1533 WARN("Failed to add filter, hr %#lx.\n", hr);
1534 IBaseFilter_Release(pfilter);
1535 return hr;
1538 if(ppFilter)
1539 *ppFilter = pfilter;
1540 else IBaseFilter_Release(pfilter);
1542 return S_OK;
1545 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *pin, const AM_MEDIA_TYPE *mt)
1547 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1548 PIN_DIRECTION dir;
1549 HRESULT hr;
1550 IPin *peer;
1552 TRACE("graph %p, pin %p, mt %p.\n", graph, pin, mt);
1554 if (FAILED(hr = IPin_ConnectedTo(pin, &peer)))
1555 return hr;
1557 IPin_QueryDirection(pin, &dir);
1558 IFilterGraph2_Disconnect(iface, peer);
1559 IFilterGraph2_Disconnect(iface, pin);
1561 if (dir == PINDIR_INPUT)
1562 hr = IFilterGraph2_ConnectDirect(iface, peer, pin, mt);
1563 else
1564 hr = IFilterGraph2_ConnectDirect(iface, pin, peer, mt);
1566 IPin_Release(peer);
1567 return hr;
1570 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *source, DWORD flags, DWORD *context)
1572 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1573 HRESULT hr;
1575 TRACE("graph %p, source %p, flags %#lx, context %p.\n", graph, source, flags, context);
1577 if (flags & ~AM_RENDEREX_RENDERTOEXISTINGRENDERERS)
1578 FIXME("Unknown flags %#lx.\n", flags);
1580 EnterCriticalSection(&graph->cs);
1581 hr = autoplug(graph, source, NULL, !!(flags & AM_RENDEREX_RENDERTOEXISTINGRENDERERS), 0);
1582 LeaveCriticalSection(&graph->cs);
1583 if (hr == VFW_E_CANNOT_CONNECT)
1584 hr = VFW_E_CANNOT_RENDER;
1586 TRACE("Returning %#lx.\n", hr);
1587 return hr;
1591 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1593 FilterGraph2_QueryInterface,
1594 FilterGraph2_AddRef,
1595 FilterGraph2_Release,
1596 FilterGraph2_AddFilter,
1597 FilterGraph2_RemoveFilter,
1598 FilterGraph2_EnumFilters,
1599 FilterGraph2_FindFilterByName,
1600 FilterGraph2_ConnectDirect,
1601 FilterGraph2_Reconnect,
1602 FilterGraph2_Disconnect,
1603 FilterGraph2_SetDefaultSyncSource,
1604 FilterGraph2_Connect,
1605 FilterGraph2_Render,
1606 FilterGraph2_RenderFile,
1607 FilterGraph2_AddSourceFilter,
1608 FilterGraph2_SetLogFile,
1609 FilterGraph2_Abort,
1610 FilterGraph2_ShouldOperationContinue,
1611 FilterGraph2_AddSourceFilterForMoniker,
1612 FilterGraph2_ReconnectEx,
1613 FilterGraph2_RenderEx
1616 static struct filter_graph *impl_from_IMediaControl(IMediaControl *iface)
1618 return CONTAINING_RECORD(iface, struct filter_graph, IMediaControl_iface);
1621 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID iid, void **out)
1623 struct filter_graph *graph = impl_from_IMediaControl(iface);
1624 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
1627 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1629 struct filter_graph *graph = impl_from_IMediaControl(iface);
1630 return IUnknown_AddRef(graph->outer_unk);
1633 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1635 struct filter_graph *graph = impl_from_IMediaControl(iface);
1636 return IUnknown_Release(graph->outer_unk);
1640 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *count)
1642 TRACE("iface %p, count %p.\n", iface, count);
1643 *count = 1;
1644 return S_OK;
1647 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT index,
1648 LCID lcid, ITypeInfo **typeinfo)
1650 TRACE("iface %p, index %u, lcid %#lx, typeinfo %p.\n", iface, index, lcid, typeinfo);
1651 return strmbase_get_typeinfo(IMediaControl_tid, typeinfo);
1654 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID iid,
1655 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
1657 ITypeInfo *typeinfo;
1658 HRESULT hr;
1660 TRACE("iface %p, iid %s, names %p, count %u, lcid %#lx, ids %p.\n",
1661 iface, debugstr_guid(iid), names, count, lcid, ids);
1663 if (SUCCEEDED(hr = strmbase_get_typeinfo(IMediaControl_tid, &typeinfo)))
1665 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
1666 ITypeInfo_Release(typeinfo);
1668 return hr;
1671 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID id, REFIID iid, LCID lcid,
1672 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
1674 ITypeInfo *typeinfo;
1675 HRESULT hr;
1677 TRACE("iface %p, id %ld, iid %s, lcid %#lx, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
1678 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
1680 if (SUCCEEDED(hr = strmbase_get_typeinfo(IMediaControl_tid, &typeinfo)))
1682 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
1683 ITypeInfo_Release(typeinfo);
1685 return hr;
1688 static void update_render_count(struct filter_graph *graph)
1690 /* Some filters (e.g. MediaStreamFilter) can become renderers when they are
1691 * already in the graph. */
1692 struct filter *filter;
1693 graph->nRenderers = 0;
1694 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1696 if (is_renderer(filter))
1697 ++graph->nRenderers;
1701 /* Perform the paused -> running transition. The caller must hold graph->cs. */
1702 static HRESULT graph_start(struct filter_graph *graph, REFERENCE_TIME stream_start)
1704 struct media_event *event, *next;
1705 REFERENCE_TIME stream_stop;
1706 struct filter *filter;
1707 HRESULT hr = S_OK;
1709 EnterCriticalSection(&graph->event_cs);
1710 graph->EcCompleteCount = 0;
1711 update_render_count(graph);
1712 LeaveCriticalSection(&graph->event_cs);
1714 LIST_FOR_EACH_ENTRY_SAFE(event, next, &graph->media_events, struct media_event, entry)
1716 if (event->code == EC_COMPLETE)
1718 list_remove(&event->entry);
1719 free(event);
1722 if (list_empty(&graph->media_events))
1723 ResetEvent(graph->media_event_handle);
1725 if (graph->defaultclock && !graph->refClock)
1726 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
1728 if (!stream_start && graph->refClock)
1730 IReferenceClock_GetTime(graph->refClock, &graph->stream_start);
1731 stream_start = graph->stream_start - graph->stream_elapsed;
1732 /* Delay presentation time by 200 ms, to give filters time to
1733 * initialize. */
1734 stream_start += 200 * 10000;
1737 if (SUCCEEDED(IMediaSeeking_GetStopPosition(&graph->IMediaSeeking_iface, &stream_stop)))
1738 graph->stream_stop = stream_stop;
1740 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1742 HRESULT filter_hr = IBaseFilter_Run(filter->filter, stream_start);
1743 if (hr == S_OK)
1744 hr = filter_hr;
1745 TRACE("Filter %p returned %#lx.\n", filter->filter, filter_hr);
1748 if (FAILED(hr))
1749 WARN("Failed to start stream, hr %#lx.\n", hr);
1751 return hr;
1754 static void CALLBACK async_run_cb(TP_CALLBACK_INSTANCE *instance, void *context, TP_WORK *work)
1756 struct filter_graph *graph = context;
1757 struct filter *filter;
1758 FILTER_STATE state;
1759 HRESULT hr;
1761 TRACE("Performing asynchronous state change.\n");
1763 /* We can't just call GetState(), since that will return State_Running and
1764 * VFW_S_STATE_INTERMEDIATE regardless of whether we're done pausing yet.
1765 * Instead replicate it here. */
1767 for (;;)
1769 IBaseFilter *async_filter = NULL;
1771 hr = S_OK;
1773 EnterCriticalSection(&graph->cs);
1775 if (!graph->needs_async_run)
1776 break;
1778 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1780 hr = IBaseFilter_GetState(filter->filter, 0, &state);
1782 if (hr == VFW_S_STATE_INTERMEDIATE)
1783 async_filter = filter->filter;
1785 if (SUCCEEDED(hr) && state != State_Paused)
1786 ERR("Filter %p reported incorrect state %u.\n", filter->filter, state);
1788 if (hr != S_OK)
1789 break;
1792 if (hr != VFW_S_STATE_INTERMEDIATE)
1793 break;
1795 LeaveCriticalSection(&graph->cs);
1797 IBaseFilter_GetState(async_filter, 10, &state);
1800 if (hr == S_OK && graph->needs_async_run)
1802 sort_filters(graph);
1803 graph_start(graph, 0);
1804 graph->needs_async_run = 0;
1807 LeaveCriticalSection(&graph->cs);
1810 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
1812 struct filter_graph *graph = impl_from_IMediaControl(iface);
1813 BOOL need_async_run = TRUE;
1814 struct filter *filter;
1815 FILTER_STATE state;
1816 HRESULT hr = S_OK;
1818 TRACE("graph %p.\n", graph);
1820 EnterCriticalSection(&graph->cs);
1822 if (graph->state == State_Running)
1824 LeaveCriticalSection(&graph->cs);
1825 return S_OK;
1828 sort_filters(graph);
1830 EnterCriticalSection(&graph->event_cs);
1831 update_render_count(graph);
1832 LeaveCriticalSection(&graph->event_cs);
1834 if (graph->state == State_Stopped)
1836 if (graph->defaultclock && !graph->refClock)
1837 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
1839 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1841 HRESULT filter_hr = IBaseFilter_Pause(filter->filter);
1842 if (hr == S_OK)
1843 hr = filter_hr;
1844 TRACE("Filter %p returned %#lx.\n", filter->filter, filter_hr);
1846 /* If a filter returns VFW_S_CANT_CUE, we shouldn't wait for a
1847 * paused state. */
1848 filter_hr = IBaseFilter_GetState(filter->filter, 0, &state);
1849 if (filter_hr != S_OK && filter_hr != VFW_S_STATE_INTERMEDIATE)
1850 need_async_run = FALSE;
1853 if (FAILED(hr))
1855 LeaveCriticalSection(&graph->cs);
1856 WARN("Failed to pause, hr %#lx.\n", hr);
1857 return hr;
1861 graph->state = State_Running;
1863 if (SUCCEEDED(hr))
1865 if (hr != S_OK && need_async_run)
1867 if (!graph->async_run_work)
1868 graph->async_run_work = CreateThreadpoolWork(async_run_cb, graph, NULL);
1869 graph->needs_async_run = 1;
1870 SubmitThreadpoolWork(graph->async_run_work);
1872 else
1874 graph_start(graph, 0);
1878 LeaveCriticalSection(&graph->cs);
1879 return hr;
1882 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
1884 struct filter_graph *graph = impl_from_IMediaControl(iface);
1886 TRACE("graph %p.\n", graph);
1888 return IMediaFilter_Pause(&graph->IMediaFilter_iface);
1891 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
1893 struct filter_graph *graph = impl_from_IMediaControl(iface);
1895 TRACE("graph %p.\n", graph);
1897 return IMediaFilter_Stop(&graph->IMediaFilter_iface);
1900 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG timeout, OAFilterState *state)
1902 struct filter_graph *graph = impl_from_IMediaControl(iface);
1904 TRACE("graph %p, timeout %ld, state %p.\n", graph, timeout, state);
1906 if (timeout < 0) timeout = INFINITE;
1908 return IMediaFilter_GetState(&graph->IMediaFilter_iface, timeout, (FILTER_STATE *)state);
1911 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
1913 struct filter_graph *This = impl_from_IMediaControl(iface);
1915 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strFilename), strFilename);
1917 return IFilterGraph2_RenderFile(&This->IFilterGraph2_iface, strFilename, NULL);
1920 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
1921 IDispatch **ppUnk)
1923 struct filter_graph *This = impl_from_IMediaControl(iface);
1925 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
1927 return S_OK;
1930 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
1932 struct filter_graph *This = impl_from_IMediaControl(iface);
1934 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
1936 return S_OK;
1939 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
1941 struct filter_graph *This = impl_from_IMediaControl(iface);
1943 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
1945 return S_OK;
1948 static void CALLBACK wait_pause_cb(TP_CALLBACK_INSTANCE *instance, void *context)
1950 IMediaControl *control = context;
1951 OAFilterState state;
1952 HRESULT hr;
1954 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
1955 ERR("Failed to get paused state, hr %#lx.\n", hr);
1957 if (FAILED(hr = IMediaControl_Stop(control)))
1958 ERR("Failed to stop, hr %#lx.\n", hr);
1960 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
1961 ERR("Failed to get paused state, hr %#lx.\n", hr);
1963 IMediaControl_Release(control);
1966 static void CALLBACK wait_stop_cb(TP_CALLBACK_INSTANCE *instance, void *context)
1968 IMediaControl *control = context;
1969 OAFilterState state;
1970 HRESULT hr;
1972 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
1973 ERR("Failed to get state, hr %#lx.\n", hr);
1975 IMediaControl_Release(control);
1978 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
1980 struct filter_graph *graph = impl_from_IMediaControl(iface);
1981 HRESULT hr;
1983 TRACE("graph %p.\n", graph);
1985 /* Even if we are already stopped, we still pause. */
1986 hr = IMediaControl_Pause(iface);
1987 if (FAILED(hr))
1988 return hr;
1989 else if (hr == S_FALSE)
1991 IMediaControl_AddRef(iface);
1992 TrySubmitThreadpoolCallback(wait_pause_cb, iface, NULL);
1993 return S_FALSE;
1996 hr = IMediaControl_Stop(iface);
1997 if (FAILED(hr))
1998 return hr;
1999 else if (hr == S_FALSE)
2001 IMediaControl_AddRef(iface);
2002 TrySubmitThreadpoolCallback(wait_stop_cb, iface, NULL);
2003 return S_FALSE;
2006 return S_OK;
2010 static const IMediaControlVtbl IMediaControl_VTable =
2012 MediaControl_QueryInterface,
2013 MediaControl_AddRef,
2014 MediaControl_Release,
2015 MediaControl_GetTypeInfoCount,
2016 MediaControl_GetTypeInfo,
2017 MediaControl_GetIDsOfNames,
2018 MediaControl_Invoke,
2019 MediaControl_Run,
2020 MediaControl_Pause,
2021 MediaControl_Stop,
2022 MediaControl_GetState,
2023 MediaControl_RenderFile,
2024 MediaControl_AddSourceFilter,
2025 MediaControl_get_FilterCollection,
2026 MediaControl_get_RegFilterCollection,
2027 MediaControl_StopWhenReady
2030 static struct filter_graph *impl_from_IMediaSeeking(IMediaSeeking *iface)
2032 return CONTAINING_RECORD(iface, struct filter_graph, IMediaSeeking_iface);
2035 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID iid, void **out)
2037 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2038 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2041 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2043 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2044 return IUnknown_AddRef(graph->outer_unk);
2047 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2049 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2050 return IUnknown_Release(graph->outer_unk);
2053 typedef HRESULT (WINAPI *fnFoundSeek)(struct filter_graph *This, IMediaSeeking*, DWORD_PTR arg);
2055 static HRESULT all_renderers_seek(struct filter_graph *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2056 BOOL allnotimpl = TRUE;
2057 HRESULT hr, hr_return = S_OK;
2058 struct filter *filter;
2060 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
2062 update_seeking(filter);
2063 if (!filter->seeking)
2064 continue;
2065 hr = FoundSeek(This, filter->seeking, arg);
2066 if (hr_return != E_NOTIMPL)
2067 allnotimpl = FALSE;
2068 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2069 hr_return = hr;
2072 if (allnotimpl)
2073 return E_NOTIMPL;
2074 return hr_return;
2077 static HRESULT WINAPI FoundCapabilities(struct filter_graph *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2079 HRESULT hr;
2080 DWORD caps = 0;
2082 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2083 if (FAILED(hr))
2084 return hr;
2086 /* Only add common capabilities everything supports */
2087 *(DWORD*)pcaps &= caps;
2089 return hr;
2092 /*** IMediaSeeking methods ***/
2093 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2095 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2096 HRESULT hr;
2098 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2100 if (!pCapabilities)
2101 return E_POINTER;
2103 EnterCriticalSection(&This->cs);
2104 *pCapabilities = 0xffffffff;
2106 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2107 LeaveCriticalSection(&This->cs);
2109 return hr;
2112 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2114 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2115 DWORD originalcaps;
2116 HRESULT hr;
2118 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2120 if (!pCapabilities)
2121 return E_POINTER;
2123 EnterCriticalSection(&This->cs);
2124 originalcaps = *pCapabilities;
2125 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2126 LeaveCriticalSection(&This->cs);
2128 if (FAILED(hr))
2129 return hr;
2131 if (!*pCapabilities)
2132 return E_FAIL;
2133 if (*pCapabilities != originalcaps)
2134 return S_FALSE;
2135 return S_OK;
2138 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2140 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2142 if (!pFormat)
2143 return E_POINTER;
2145 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2147 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2149 WARN("Unhandled time format %s\n", debugstr_guid(pFormat));
2150 return S_FALSE;
2153 return S_OK;
2156 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2158 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2160 if (!pFormat)
2161 return E_POINTER;
2163 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2164 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2166 return S_OK;
2169 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2171 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2173 if (!pFormat)
2174 return E_POINTER;
2176 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2177 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2179 return S_OK;
2182 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2184 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2186 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2187 if (!pFormat)
2188 return E_POINTER;
2190 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2191 return S_FALSE;
2193 return S_OK;
2196 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2198 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2200 if (!pFormat)
2201 return E_POINTER;
2203 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2205 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2207 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2208 return E_INVALIDARG;
2211 return S_OK;
2214 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *duration)
2216 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2217 HRESULT hr = E_NOTIMPL, filter_hr;
2218 LONGLONG filter_duration;
2219 struct filter *filter;
2221 TRACE("graph %p, duration %p.\n", graph, duration);
2223 if (!duration)
2224 return E_POINTER;
2226 *duration = 0;
2228 EnterCriticalSection(&graph->cs);
2230 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2232 update_seeking(filter);
2233 if (!filter->seeking)
2234 continue;
2236 filter_hr = IMediaSeeking_GetDuration(filter->seeking, &filter_duration);
2237 if (SUCCEEDED(filter_hr))
2239 hr = S_OK;
2240 *duration = max(*duration, filter_duration);
2242 else if (filter_hr != E_NOTIMPL)
2244 LeaveCriticalSection(&graph->cs);
2245 return filter_hr;
2249 LeaveCriticalSection(&graph->cs);
2251 TRACE("Returning hr %#lx, duration %s (%s seconds).\n", hr,
2252 wine_dbgstr_longlong(*duration), debugstr_time(*duration));
2253 return hr;
2256 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *stop)
2258 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2259 HRESULT hr = E_NOTIMPL, filter_hr;
2260 struct filter *filter;
2261 LONGLONG filter_stop;
2263 TRACE("graph %p, stop %p.\n", graph, stop);
2265 if (!stop)
2266 return E_POINTER;
2268 *stop = 0;
2270 EnterCriticalSection(&graph->cs);
2272 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2274 update_seeking(filter);
2275 if (!filter->seeking)
2276 continue;
2278 filter_hr = IMediaSeeking_GetStopPosition(filter->seeking, &filter_stop);
2279 if (SUCCEEDED(filter_hr))
2281 hr = S_OK;
2282 *stop = max(*stop, filter_stop);
2284 else if (filter_hr != E_NOTIMPL)
2286 LeaveCriticalSection(&graph->cs);
2287 return filter_hr;
2291 LeaveCriticalSection(&graph->cs);
2293 TRACE("Returning %s (%s seconds).\n", wine_dbgstr_longlong(*stop), debugstr_time(*stop));
2294 return hr;
2297 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *current)
2299 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2300 LONGLONG ret = graph->current_pos;
2302 TRACE("graph %p, current %p.\n", graph, current);
2304 if (!current)
2305 return E_POINTER;
2307 EnterCriticalSection(&graph->cs);
2309 if (graph->got_ec_complete)
2311 ret = graph->stream_stop;
2313 else if (graph->state == State_Running && !graph->needs_async_run && graph->refClock)
2315 REFERENCE_TIME time;
2316 IReferenceClock_GetTime(graph->refClock, &time);
2317 if (time)
2318 ret += time - graph->stream_start;
2321 LeaveCriticalSection(&graph->cs);
2323 TRACE("Returning %s (%s seconds).\n", wine_dbgstr_longlong(ret), debugstr_time(ret));
2324 *current = ret;
2326 return S_OK;
2329 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2330 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2332 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2334 TRACE("(%p/%p)->(%p, %s, 0x%s, %s)\n", This, iface, pTarget,
2335 debugstr_guid(pTargetFormat), wine_dbgstr_longlong(Source), debugstr_guid(pSourceFormat));
2337 if (!pSourceFormat)
2338 pSourceFormat = &This->timeformatseek;
2340 if (!pTargetFormat)
2341 pTargetFormat = &This->timeformatseek;
2343 if (IsEqualGUID(pTargetFormat, pSourceFormat))
2344 *pTarget = Source;
2345 else
2346 FIXME("conversion %s->%s not supported\n", debugstr_guid(pSourceFormat), debugstr_guid(pTargetFormat));
2348 return S_OK;
2351 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *current_ptr,
2352 DWORD current_flags, LONGLONG *stop_ptr, DWORD stop_flags)
2354 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2355 HRESULT hr = E_NOTIMPL, filter_hr;
2356 struct filter *filter;
2357 FILTER_STATE state;
2359 TRACE("graph %p, current %s, current_flags %#lx, stop %s, stop_flags %#lx.\n", graph,
2360 current_ptr ? wine_dbgstr_longlong(*current_ptr) : "<null>", current_flags,
2361 stop_ptr ? wine_dbgstr_longlong(*stop_ptr): "<null>", stop_flags);
2362 if (current_ptr)
2363 TRACE("Setting current position to %s (%s seconds).\n",
2364 wine_dbgstr_longlong(*current_ptr), debugstr_time(*current_ptr));
2365 if (stop_ptr)
2366 TRACE("Setting stop position to %s (%s seconds).\n",
2367 wine_dbgstr_longlong(*stop_ptr), debugstr_time(*stop_ptr));
2369 if ((current_flags & 0x7) != AM_SEEKING_AbsolutePositioning
2370 && (current_flags & 0x7) != AM_SEEKING_NoPositioning)
2371 FIXME("Unhandled current_flags %#lx.\n", current_flags & 0x7);
2373 if ((stop_flags & 0x7) != AM_SEEKING_NoPositioning
2374 && (stop_flags & 0x7) != AM_SEEKING_AbsolutePositioning)
2375 FIXME("Unhandled stop_flags %#lx.\n", stop_flags & 0x7);
2377 EnterCriticalSection(&graph->cs);
2379 state = graph->state;
2380 if (state == State_Running && !graph->needs_async_run)
2381 IMediaControl_Pause(&graph->IMediaControl_iface);
2383 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2385 LONGLONG current = current_ptr ? *current_ptr : 0, stop = stop_ptr ? *stop_ptr : 0;
2387 update_seeking(filter);
2388 if (!filter->seeking)
2389 continue;
2391 filter_hr = IMediaSeeking_SetPositions(filter->seeking, &current,
2392 current_flags | AM_SEEKING_ReturnTime, &stop, stop_flags);
2393 if (SUCCEEDED(filter_hr))
2395 hr = S_OK;
2397 if (current_ptr && (current_flags & AM_SEEKING_ReturnTime))
2398 *current_ptr = current;
2399 if (stop_ptr && (stop_flags & AM_SEEKING_ReturnTime))
2400 *stop_ptr = stop;
2401 graph->current_pos = current;
2403 else if (filter_hr != E_NOTIMPL)
2405 LeaveCriticalSection(&graph->cs);
2406 return filter_hr;
2410 if ((current_flags & 0x7) != AM_SEEKING_NoPositioning && graph->refClock)
2412 IReferenceClock_GetTime(graph->refClock, &graph->stream_start);
2413 graph->stream_elapsed = 0;
2416 if (state == State_Running && !graph->needs_async_run)
2417 IMediaControl_Run(&graph->IMediaControl_iface);
2419 LeaveCriticalSection(&graph->cs);
2420 return hr;
2423 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface,
2424 LONGLONG *current, LONGLONG *stop)
2426 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2427 HRESULT hr = S_OK;
2429 TRACE("graph %p, current %p, stop %p.\n", graph, current, stop);
2431 if (current)
2432 hr = IMediaSeeking_GetCurrentPosition(iface, current);
2433 if (SUCCEEDED(hr) && stop)
2434 hr = IMediaSeeking_GetStopPosition(iface, stop);
2436 return hr;
2439 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2440 LONGLONG *pLatest)
2442 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2444 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2446 return S_OK;
2449 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2451 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2453 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2455 return S_OK;
2458 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2460 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2462 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2464 if (!pdRate)
2465 return E_POINTER;
2467 *pdRate = 1.0;
2469 return S_OK;
2472 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2474 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2476 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2478 return S_OK;
2482 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2484 MediaSeeking_QueryInterface,
2485 MediaSeeking_AddRef,
2486 MediaSeeking_Release,
2487 MediaSeeking_GetCapabilities,
2488 MediaSeeking_CheckCapabilities,
2489 MediaSeeking_IsFormatSupported,
2490 MediaSeeking_QueryPreferredFormat,
2491 MediaSeeking_GetTimeFormat,
2492 MediaSeeking_IsUsingTimeFormat,
2493 MediaSeeking_SetTimeFormat,
2494 MediaSeeking_GetDuration,
2495 MediaSeeking_GetStopPosition,
2496 MediaSeeking_GetCurrentPosition,
2497 MediaSeeking_ConvertTimeFormat,
2498 MediaSeeking_SetPositions,
2499 MediaSeeking_GetPositions,
2500 MediaSeeking_GetAvailable,
2501 MediaSeeking_SetRate,
2502 MediaSeeking_GetRate,
2503 MediaSeeking_GetPreroll
2506 static struct filter_graph *impl_from_IMediaPosition(IMediaPosition *iface)
2508 return CONTAINING_RECORD(iface, struct filter_graph, IMediaPosition_iface);
2511 /*** IUnknown methods ***/
2512 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition *iface, REFIID iid, void **out)
2514 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2515 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2518 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2520 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2521 return IUnknown_AddRef(graph->outer_unk);
2524 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2526 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2527 return IUnknown_Release(graph->outer_unk);
2530 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT *count)
2532 TRACE("iface %p, count %p.\n", iface, count);
2533 *count = 1;
2534 return S_OK;
2537 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT index,
2538 LCID lcid, ITypeInfo **typeinfo)
2540 TRACE("iface %p, index %u, lcid %#lx, typeinfo %p.\n", iface, index, lcid, typeinfo);
2541 return strmbase_get_typeinfo(IMediaPosition_tid, typeinfo);
2544 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition *iface, REFIID iid,
2545 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
2547 ITypeInfo *typeinfo;
2548 HRESULT hr;
2550 TRACE("iface %p, iid %s, names %p, count %u, lcid %#lx, ids %p.\n",
2551 iface, debugstr_guid(iid), names, count, lcid, ids);
2553 if (SUCCEEDED(hr = strmbase_get_typeinfo(IMediaPosition_tid, &typeinfo)))
2555 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
2556 ITypeInfo_Release(typeinfo);
2558 return hr;
2561 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition *iface, DISPID id, REFIID iid, LCID lcid,
2562 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
2564 ITypeInfo *typeinfo;
2565 HRESULT hr;
2567 TRACE("iface %p, id %ld, iid %s, lcid %#lx, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
2568 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
2570 if (SUCCEEDED(hr = strmbase_get_typeinfo(IMediaPosition_tid, &typeinfo)))
2572 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
2573 ITypeInfo_Release(typeinfo);
2575 return hr;
2578 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2580 GUID time_format;
2581 HRESULT hr;
2583 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2584 if (FAILED(hr))
2585 return hr;
2586 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2588 FIXME("Unsupported time format.\n");
2589 return E_NOTIMPL;
2592 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2593 return S_OK;
2596 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2598 GUID time_format;
2599 HRESULT hr;
2601 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2602 if (FAILED(hr))
2603 return hr;
2604 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2606 FIXME("Unsupported time format.\n");
2607 return E_NOTIMPL;
2610 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2611 return S_OK;
2614 /*** IMediaPosition methods ***/
2615 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2617 LONGLONG duration;
2618 struct filter_graph *This = impl_from_IMediaPosition( iface );
2619 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2620 if (FAILED(hr))
2621 return hr;
2622 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2625 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2627 struct filter_graph *This = impl_from_IMediaPosition( iface );
2628 LONGLONG reftime;
2629 HRESULT hr;
2631 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2632 if (FAILED(hr))
2633 return hr;
2634 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2635 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2638 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2640 struct filter_graph *This = impl_from_IMediaPosition( iface );
2641 LONGLONG pos;
2642 HRESULT hr;
2644 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2645 if (FAILED(hr))
2646 return hr;
2647 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2650 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2652 struct filter_graph *This = impl_from_IMediaPosition( iface );
2653 LONGLONG pos;
2654 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2655 if (FAILED(hr))
2656 return hr;
2657 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2660 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2662 struct filter_graph *This = impl_from_IMediaPosition( iface );
2663 LONGLONG reftime;
2664 HRESULT hr;
2666 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2667 if (FAILED(hr))
2668 return hr;
2669 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2670 &reftime, AM_SEEKING_AbsolutePositioning);
2673 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime)
2675 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2676 return E_NOTIMPL;
2679 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime)
2681 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2682 return E_NOTIMPL;
2685 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2687 struct filter_graph *This = impl_from_IMediaPosition( iface );
2688 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2691 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2693 struct filter_graph *This = impl_from_IMediaPosition( iface );
2694 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2697 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward)
2699 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2700 return E_NOTIMPL;
2703 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward)
2705 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2706 return E_NOTIMPL;
2710 static const IMediaPositionVtbl IMediaPosition_VTable =
2712 MediaPosition_QueryInterface,
2713 MediaPosition_AddRef,
2714 MediaPosition_Release,
2715 MediaPosition_GetTypeInfoCount,
2716 MediaPosition_GetTypeInfo,
2717 MediaPosition_GetIDsOfNames,
2718 MediaPosition_Invoke,
2719 MediaPosition_get_Duration,
2720 MediaPosition_put_CurrentPosition,
2721 MediaPosition_get_CurrentPosition,
2722 MediaPosition_get_StopTime,
2723 MediaPosition_put_StopTime,
2724 MediaPosition_get_PrerollTime,
2725 MediaPosition_put_PrerollTime,
2726 MediaPosition_put_Rate,
2727 MediaPosition_get_Rate,
2728 MediaPosition_CanSeekForward,
2729 MediaPosition_CanSeekBackward
2732 static struct filter_graph *impl_from_IObjectWithSite(IObjectWithSite *iface)
2734 return CONTAINING_RECORD(iface, struct filter_graph, IObjectWithSite_iface);
2737 /*** IUnknown methods ***/
2738 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID iid, void **out)
2740 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2741 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2744 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
2746 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2747 return IUnknown_AddRef(graph->outer_unk);
2750 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
2752 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2753 return IUnknown_Release(graph->outer_unk);
2756 /*** IObjectWithSite methods ***/
2758 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
2760 struct filter_graph *This = impl_from_IObjectWithSite( iface );
2762 TRACE("(%p/%p)->()\n", This, iface);
2763 if (This->pSite) IUnknown_Release(This->pSite);
2764 This->pSite = pUnkSite;
2765 IUnknown_AddRef(This->pSite);
2766 return S_OK;
2769 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, PVOID *ppvSite)
2771 struct filter_graph *This = impl_from_IObjectWithSite( iface );
2773 TRACE("(%p/%p)->(%s)\n", This, iface,debugstr_guid(riid));
2775 *ppvSite = NULL;
2776 if (!This->pSite)
2777 return E_FAIL;
2778 else
2779 return IUnknown_QueryInterface(This->pSite, riid, ppvSite);
2782 static const IObjectWithSiteVtbl IObjectWithSite_VTable =
2784 ObjectWithSite_QueryInterface,
2785 ObjectWithSite_AddRef,
2786 ObjectWithSite_Release,
2787 ObjectWithSite_SetSite,
2788 ObjectWithSite_GetSite,
2791 static HRESULT GetTargetInterface(struct filter_graph* pGraph, REFIID riid, LPVOID* ppvObj)
2793 struct filter *filter;
2794 HRESULT hr;
2795 int entry;
2797 /* Check if the interface type is already registered */
2798 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2799 if (riid == pGraph->ItfCacheEntries[entry].riid)
2801 if (pGraph->ItfCacheEntries[entry].iface)
2803 /* Return the interface if available */
2804 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2805 return S_OK;
2807 break;
2810 if (entry >= MAX_ITF_CACHE_ENTRIES)
2812 FIXME("Not enough space to store interface in the cache\n");
2813 return E_OUTOFMEMORY;
2816 /* Find a filter supporting the requested interface */
2817 LIST_FOR_EACH_ENTRY(filter, &pGraph->filters, struct filter, entry)
2819 hr = IBaseFilter_QueryInterface(filter->filter, riid, ppvObj);
2820 if (hr == S_OK)
2822 pGraph->ItfCacheEntries[entry].riid = riid;
2823 pGraph->ItfCacheEntries[entry].filter = filter->filter;
2824 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2825 if (entry >= pGraph->nItfCacheEntries)
2826 pGraph->nItfCacheEntries++;
2827 return S_OK;
2829 if (hr != E_NOINTERFACE)
2830 return hr;
2833 return IsEqualGUID(riid, &IID_IBasicAudio) ? E_NOTIMPL : E_NOINTERFACE;
2836 static struct filter_graph *impl_from_IBasicAudio(IBasicAudio *iface)
2838 return CONTAINING_RECORD(iface, struct filter_graph, IBasicAudio_iface);
2841 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID iid, void **out)
2843 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2844 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2847 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
2849 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2850 return IUnknown_AddRef(graph->outer_unk);
2853 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
2855 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2856 return IUnknown_Release(graph->outer_unk);
2859 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *count)
2861 TRACE("iface %p, count %p.\n", iface, count);
2862 *count = 1;
2863 return S_OK;
2866 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT index,
2867 LCID lcid, ITypeInfo **typeinfo)
2869 TRACE("iface %p, index %u, lcid %#lx, typeinfo %p.\n", iface, index, lcid, typeinfo);
2870 return strmbase_get_typeinfo(IBasicAudio_tid, typeinfo);
2873 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID iid,
2874 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
2876 ITypeInfo *typeinfo;
2877 HRESULT hr;
2879 TRACE("iface %p, iid %s, names %p, count %u, lcid %#lx, ids %p.\n",
2880 iface, debugstr_guid(iid), names, count, lcid, ids);
2882 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicAudio_tid, &typeinfo)))
2884 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
2885 ITypeInfo_Release(typeinfo);
2887 return hr;
2890 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID id, REFIID iid, LCID lcid,
2891 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
2893 ITypeInfo *typeinfo;
2894 HRESULT hr;
2896 TRACE("iface %p, id %ld, iid %s, lcid %#lx, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
2897 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
2899 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicAudio_tid, &typeinfo)))
2901 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
2902 ITypeInfo_Release(typeinfo);
2904 return hr;
2907 /*** IBasicAudio methods ***/
2908 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
2910 struct filter_graph *This = impl_from_IBasicAudio(iface);
2911 IBasicAudio* pBasicAudio;
2912 HRESULT hr;
2914 TRACE("graph %p, volume %ld.\n", This, lVolume);
2916 EnterCriticalSection(&This->cs);
2918 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2920 if (hr == S_OK)
2921 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
2923 LeaveCriticalSection(&This->cs);
2925 return hr;
2928 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
2930 struct filter_graph *This = impl_from_IBasicAudio(iface);
2931 IBasicAudio* pBasicAudio;
2932 HRESULT hr;
2934 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
2936 EnterCriticalSection(&This->cs);
2938 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2940 if (hr == S_OK)
2941 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
2943 LeaveCriticalSection(&This->cs);
2945 return hr;
2948 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
2950 struct filter_graph *This = impl_from_IBasicAudio(iface);
2951 IBasicAudio* pBasicAudio;
2952 HRESULT hr;
2954 TRACE("graph %p, balance %ld.\n", This, lBalance);
2956 EnterCriticalSection(&This->cs);
2958 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2960 if (hr == S_OK)
2961 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
2963 LeaveCriticalSection(&This->cs);
2965 return hr;
2968 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
2970 struct filter_graph *This = impl_from_IBasicAudio(iface);
2971 IBasicAudio* pBasicAudio;
2972 HRESULT hr;
2974 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
2976 EnterCriticalSection(&This->cs);
2978 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2980 if (hr == S_OK)
2981 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
2983 LeaveCriticalSection(&This->cs);
2985 return hr;
2988 static const IBasicAudioVtbl IBasicAudio_VTable =
2990 BasicAudio_QueryInterface,
2991 BasicAudio_AddRef,
2992 BasicAudio_Release,
2993 BasicAudio_GetTypeInfoCount,
2994 BasicAudio_GetTypeInfo,
2995 BasicAudio_GetIDsOfNames,
2996 BasicAudio_Invoke,
2997 BasicAudio_put_Volume,
2998 BasicAudio_get_Volume,
2999 BasicAudio_put_Balance,
3000 BasicAudio_get_Balance
3003 static struct filter_graph *impl_from_IBasicVideo2(IBasicVideo2 *iface)
3005 return CONTAINING_RECORD(iface, struct filter_graph, IBasicVideo2_iface);
3008 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID iid, void **out)
3010 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
3011 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
3014 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
3016 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
3017 return IUnknown_AddRef(graph->outer_unk);
3020 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
3022 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
3023 return IUnknown_Release(graph->outer_unk);
3026 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *count)
3028 TRACE("iface %p, count %p.\n", iface, count);
3029 *count = 1;
3030 return S_OK;
3033 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT index,
3034 LCID lcid, ITypeInfo **typeinfo)
3036 TRACE("iface %p, index %u, lcid %#lx, typeinfo %p.\n", iface, index, lcid, typeinfo);
3037 return strmbase_get_typeinfo(IBasicVideo_tid, typeinfo);
3040 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID iid,
3041 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
3043 ITypeInfo *typeinfo;
3044 HRESULT hr;
3046 TRACE("iface %p, iid %s, names %p, count %u, lcid %#lx, ids %p.\n",
3047 iface, debugstr_guid(iid), names, count, lcid, ids);
3049 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicVideo_tid, &typeinfo)))
3051 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
3052 ITypeInfo_Release(typeinfo);
3054 return hr;
3057 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID id, REFIID iid, LCID lcid,
3058 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
3060 ITypeInfo *typeinfo;
3061 HRESULT hr;
3063 TRACE("iface %p, id %ld, iid %s, lcid %#lx, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
3064 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
3066 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicVideo_tid, &typeinfo)))
3068 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
3069 ITypeInfo_Release(typeinfo);
3071 return hr;
3074 /*** IBasicVideo methods ***/
3075 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3077 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3078 IBasicVideo *pBasicVideo;
3079 HRESULT hr;
3081 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3083 EnterCriticalSection(&This->cs);
3085 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3087 if (hr == S_OK)
3088 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3090 LeaveCriticalSection(&This->cs);
3092 return hr;
3095 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3097 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3098 IBasicVideo *pBasicVideo;
3099 HRESULT hr;
3101 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3103 EnterCriticalSection(&This->cs);
3105 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3107 if (hr == S_OK)
3108 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3110 LeaveCriticalSection(&This->cs);
3112 return hr;
3115 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3117 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3118 IBasicVideo *pBasicVideo;
3119 HRESULT hr;
3121 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3123 EnterCriticalSection(&This->cs);
3125 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3127 if (hr == S_OK)
3128 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3130 LeaveCriticalSection(&This->cs);
3132 return hr;
3135 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3137 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3138 IBasicVideo *pBasicVideo;
3139 HRESULT hr;
3141 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3143 EnterCriticalSection(&This->cs);
3145 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3147 if (hr == S_OK)
3148 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3150 LeaveCriticalSection(&This->cs);
3152 return hr;
3155 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3157 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3158 IBasicVideo *pBasicVideo;
3159 HRESULT hr;
3161 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3163 EnterCriticalSection(&This->cs);
3165 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3167 if (hr == S_OK)
3168 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3170 LeaveCriticalSection(&This->cs);
3172 return hr;
3175 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3177 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3178 IBasicVideo *pBasicVideo;
3179 HRESULT hr;
3181 TRACE("graph %p, left %ld.\n", This, SourceLeft);
3183 EnterCriticalSection(&This->cs);
3185 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3187 if (hr == S_OK)
3188 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3190 LeaveCriticalSection(&This->cs);
3192 return hr;
3195 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3197 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3198 IBasicVideo *pBasicVideo;
3199 HRESULT hr;
3201 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3203 EnterCriticalSection(&This->cs);
3205 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3207 if (hr == S_OK)
3208 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3210 LeaveCriticalSection(&This->cs);
3212 return hr;
3215 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3217 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3218 IBasicVideo *pBasicVideo;
3219 HRESULT hr;
3221 TRACE("graph %p, width %ld.\n", This, SourceWidth);
3223 EnterCriticalSection(&This->cs);
3225 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3227 if (hr == S_OK)
3228 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3230 LeaveCriticalSection(&This->cs);
3232 return hr;
3235 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3237 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3238 IBasicVideo *pBasicVideo;
3239 HRESULT hr;
3241 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3243 EnterCriticalSection(&This->cs);
3245 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3247 if (hr == S_OK)
3248 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3250 LeaveCriticalSection(&This->cs);
3252 return hr;
3255 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3257 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3258 IBasicVideo *pBasicVideo;
3259 HRESULT hr;
3261 TRACE("graph %p, top %ld.\n", This, SourceTop);
3263 EnterCriticalSection(&This->cs);
3265 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3267 if (hr == S_OK)
3268 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3270 LeaveCriticalSection(&This->cs);
3272 return hr;
3275 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3277 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3278 IBasicVideo *pBasicVideo;
3279 HRESULT hr;
3281 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3283 EnterCriticalSection(&This->cs);
3285 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3287 if (hr == S_OK)
3288 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3290 LeaveCriticalSection(&This->cs);
3292 return hr;
3295 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3297 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3298 IBasicVideo *pBasicVideo;
3299 HRESULT hr;
3301 TRACE("graph %p, height %ld.\n", This, SourceHeight);
3303 EnterCriticalSection(&This->cs);
3305 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3307 if (hr == S_OK)
3308 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3310 LeaveCriticalSection(&This->cs);
3312 return hr;
3315 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3317 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3318 IBasicVideo *pBasicVideo;
3319 HRESULT hr;
3321 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3323 EnterCriticalSection(&This->cs);
3325 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3327 if (hr == S_OK)
3328 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3330 LeaveCriticalSection(&This->cs);
3332 return hr;
3335 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3337 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3338 IBasicVideo *pBasicVideo;
3339 HRESULT hr;
3341 TRACE("graph %p, left %ld.\n", This, DestinationLeft);
3343 EnterCriticalSection(&This->cs);
3345 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3347 if (hr == S_OK)
3348 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3350 LeaveCriticalSection(&This->cs);
3352 return hr;
3355 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3357 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3358 IBasicVideo *pBasicVideo;
3359 HRESULT hr;
3361 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3363 EnterCriticalSection(&This->cs);
3365 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3367 if (hr == S_OK)
3368 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3370 LeaveCriticalSection(&This->cs);
3372 return hr;
3375 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3377 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3378 IBasicVideo *pBasicVideo;
3379 HRESULT hr;
3381 TRACE("graph %p, width %ld.\n", This, DestinationWidth);
3383 EnterCriticalSection(&This->cs);
3385 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3387 if (hr == S_OK)
3388 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3390 LeaveCriticalSection(&This->cs);
3392 return hr;
3395 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3397 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3398 IBasicVideo *pBasicVideo;
3399 HRESULT hr;
3401 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3403 EnterCriticalSection(&This->cs);
3405 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3407 if (hr == S_OK)
3408 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3410 LeaveCriticalSection(&This->cs);
3412 return hr;
3415 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3417 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3418 IBasicVideo *pBasicVideo;
3419 HRESULT hr;
3421 TRACE("graph %p, top %ld.\n", This, DestinationTop);
3423 EnterCriticalSection(&This->cs);
3425 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3427 if (hr == S_OK)
3428 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3430 LeaveCriticalSection(&This->cs);
3432 return hr;
3435 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3437 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3438 IBasicVideo *pBasicVideo;
3439 HRESULT hr;
3441 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3443 EnterCriticalSection(&This->cs);
3445 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3447 if (hr == S_OK)
3448 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3450 LeaveCriticalSection(&This->cs);
3452 return hr;
3455 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3457 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3458 IBasicVideo *pBasicVideo;
3459 HRESULT hr;
3461 TRACE("graph %p, height %ld.\n", This, DestinationHeight);
3463 EnterCriticalSection(&This->cs);
3465 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3467 if (hr == S_OK)
3468 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3470 LeaveCriticalSection(&This->cs);
3472 return hr;
3475 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3476 LONG *pDestinationHeight)
3478 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3479 IBasicVideo *pBasicVideo;
3480 HRESULT hr;
3482 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3484 EnterCriticalSection(&This->cs);
3486 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3488 if (hr == S_OK)
3489 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3491 LeaveCriticalSection(&This->cs);
3493 return hr;
3496 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3497 LONG Width, LONG Height)
3499 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3500 IBasicVideo *pBasicVideo;
3501 HRESULT hr;
3503 TRACE("graph %p, left %ld, top %ld, width %ld, height %ld.\n", This, Left, Top, Width, Height);
3505 EnterCriticalSection(&This->cs);
3507 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3509 if (hr == S_OK)
3510 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3512 LeaveCriticalSection(&This->cs);
3514 return hr;
3517 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3518 LONG *pWidth, LONG *pHeight)
3520 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3521 IBasicVideo *pBasicVideo;
3522 HRESULT hr;
3524 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3526 EnterCriticalSection(&This->cs);
3528 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3530 if (hr == S_OK)
3531 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3533 LeaveCriticalSection(&This->cs);
3535 return hr;
3538 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3540 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3541 IBasicVideo *pBasicVideo;
3542 HRESULT hr;
3544 TRACE("(%p/%p)->()\n", This, iface);
3546 EnterCriticalSection(&This->cs);
3548 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3550 if (hr == S_OK)
3551 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3553 LeaveCriticalSection(&This->cs);
3555 return hr;
3558 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3559 LONG Width, LONG Height)
3561 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3562 IBasicVideo *pBasicVideo;
3563 HRESULT hr;
3565 TRACE("graph %p, left %ld, top %ld, width %ld, height %ld.\n", This, Left, Top, Width, Height);
3567 EnterCriticalSection(&This->cs);
3569 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3571 if (hr == S_OK)
3572 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3574 LeaveCriticalSection(&This->cs);
3576 return hr;
3579 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3580 LONG *pTop, LONG *pWidth, LONG *pHeight)
3582 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3583 IBasicVideo *pBasicVideo;
3584 HRESULT hr;
3586 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3588 EnterCriticalSection(&This->cs);
3590 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3592 if (hr == S_OK)
3593 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3595 LeaveCriticalSection(&This->cs);
3597 return hr;
3600 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3602 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3603 IBasicVideo *pBasicVideo;
3604 HRESULT hr;
3606 TRACE("(%p/%p)->()\n", This, iface);
3608 EnterCriticalSection(&This->cs);
3610 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3612 if (hr == S_OK)
3613 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3615 LeaveCriticalSection(&This->cs);
3617 return hr;
3620 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3622 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3623 IBasicVideo *pBasicVideo;
3624 HRESULT hr;
3626 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3628 EnterCriticalSection(&This->cs);
3630 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3632 if (hr == S_OK)
3633 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3635 LeaveCriticalSection(&This->cs);
3637 return hr;
3640 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3641 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3643 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3644 IBasicVideo *pBasicVideo;
3645 HRESULT hr;
3647 TRACE("graph %p, start_index %ld, count %ld, ret_count %p, entries %p.\n",
3648 This, StartIndex, Entries, pRetrieved, pPalette);
3650 EnterCriticalSection(&This->cs);
3652 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3654 if (hr == S_OK)
3655 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3657 LeaveCriticalSection(&This->cs);
3659 return hr;
3662 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3663 LONG *pDIBImage)
3665 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3666 IBasicVideo *pBasicVideo;
3667 HRESULT hr;
3669 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3671 EnterCriticalSection(&This->cs);
3673 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3675 if (hr == S_OK)
3676 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3678 LeaveCriticalSection(&This->cs);
3680 return hr;
3683 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3685 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3686 IBasicVideo *pBasicVideo;
3687 HRESULT hr;
3689 TRACE("(%p/%p)->()\n", This, iface);
3691 EnterCriticalSection(&This->cs);
3693 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3695 if (hr == S_OK)
3696 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3698 LeaveCriticalSection(&This->cs);
3700 return hr;
3703 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3705 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3706 IBasicVideo *pBasicVideo;
3707 HRESULT hr;
3709 TRACE("(%p/%p)->()\n", This, iface);
3711 EnterCriticalSection(&This->cs);
3713 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3715 if (hr == S_OK)
3716 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3718 LeaveCriticalSection(&This->cs);
3720 return hr;
3723 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3724 LONG *plAspectY)
3726 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3727 IBasicVideo2 *pBasicVideo2;
3728 HRESULT hr;
3730 TRACE("(%p/%p)->()\n", This, iface);
3732 EnterCriticalSection(&This->cs);
3734 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3736 if (hr == S_OK)
3737 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3739 LeaveCriticalSection(&This->cs);
3741 return hr;
3744 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3746 BasicVideo_QueryInterface,
3747 BasicVideo_AddRef,
3748 BasicVideo_Release,
3749 BasicVideo_GetTypeInfoCount,
3750 BasicVideo_GetTypeInfo,
3751 BasicVideo_GetIDsOfNames,
3752 BasicVideo_Invoke,
3753 BasicVideo_get_AvgTimePerFrame,
3754 BasicVideo_get_BitRate,
3755 BasicVideo_get_BitErrorRate,
3756 BasicVideo_get_VideoWidth,
3757 BasicVideo_get_VideoHeight,
3758 BasicVideo_put_SourceLeft,
3759 BasicVideo_get_SourceLeft,
3760 BasicVideo_put_SourceWidth,
3761 BasicVideo_get_SourceWidth,
3762 BasicVideo_put_SourceTop,
3763 BasicVideo_get_SourceTop,
3764 BasicVideo_put_SourceHeight,
3765 BasicVideo_get_SourceHeight,
3766 BasicVideo_put_DestinationLeft,
3767 BasicVideo_get_DestinationLeft,
3768 BasicVideo_put_DestinationWidth,
3769 BasicVideo_get_DestinationWidth,
3770 BasicVideo_put_DestinationTop,
3771 BasicVideo_get_DestinationTop,
3772 BasicVideo_put_DestinationHeight,
3773 BasicVideo_get_DestinationHeight,
3774 BasicVideo_SetSourcePosition,
3775 BasicVideo_GetSourcePosition,
3776 BasicVideo_SetDefaultSourcePosition,
3777 BasicVideo_SetDestinationPosition,
3778 BasicVideo_GetDestinationPosition,
3779 BasicVideo_SetDefaultDestinationPosition,
3780 BasicVideo_GetVideoSize,
3781 BasicVideo_GetVideoPaletteEntries,
3782 BasicVideo_GetCurrentImage,
3783 BasicVideo_IsUsingDefaultSource,
3784 BasicVideo_IsUsingDefaultDestination,
3785 BasicVideo2_GetPreferredAspectRatio
3788 static struct filter_graph *impl_from_IVideoWindow(IVideoWindow *iface)
3790 return CONTAINING_RECORD(iface, struct filter_graph, IVideoWindow_iface);
3793 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID iid, void **out)
3795 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3796 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
3799 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
3801 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3802 return IUnknown_AddRef(graph->outer_unk);
3805 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
3807 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3808 return IUnknown_Release(graph->outer_unk);
3811 HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *count)
3813 TRACE("iface %p, count %p.\n", iface, count);
3814 *count = 1;
3815 return S_OK;
3818 HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT index,
3819 LCID lcid, ITypeInfo **typeinfo)
3821 TRACE("iface %p, index %u, lcid %#lx, typeinfo %p.\n", iface, index, lcid, typeinfo);
3822 return strmbase_get_typeinfo(IVideoWindow_tid, typeinfo);
3825 HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID iid,
3826 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
3828 ITypeInfo *typeinfo;
3829 HRESULT hr;
3831 TRACE("iface %p, iid %s, names %p, count %u, lcid %#lx, ids %p.\n",
3832 iface, debugstr_guid(iid), names, count, lcid, ids);
3834 if (SUCCEEDED(hr = strmbase_get_typeinfo(IVideoWindow_tid, &typeinfo)))
3836 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
3837 ITypeInfo_Release(typeinfo);
3839 return hr;
3842 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID id, REFIID iid, LCID lcid,
3843 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
3845 ITypeInfo *typeinfo;
3846 HRESULT hr;
3848 TRACE("iface %p, id %ld, iid %s, lcid %#lx, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
3849 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
3851 if (SUCCEEDED(hr = strmbase_get_typeinfo(IVideoWindow_tid, &typeinfo)))
3853 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
3854 ITypeInfo_Release(typeinfo);
3856 return hr;
3859 /*** IVideoWindow methods ***/
3860 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
3862 struct filter_graph *This = impl_from_IVideoWindow(iface);
3863 IVideoWindow *pVideoWindow;
3864 HRESULT hr;
3866 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
3868 EnterCriticalSection(&This->cs);
3870 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3872 if (hr == S_OK)
3873 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
3875 LeaveCriticalSection(&This->cs);
3877 return hr;
3880 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
3882 struct filter_graph *This = impl_from_IVideoWindow(iface);
3883 IVideoWindow *pVideoWindow;
3884 HRESULT hr;
3886 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
3888 EnterCriticalSection(&This->cs);
3890 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3892 if (hr == S_OK)
3893 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
3895 LeaveCriticalSection(&This->cs);
3897 return hr;
3900 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
3902 struct filter_graph *This = impl_from_IVideoWindow(iface);
3903 IVideoWindow *pVideoWindow;
3904 HRESULT hr;
3906 TRACE("graph %p, style %#lx.\n", This, WindowStyle);
3908 EnterCriticalSection(&This->cs);
3910 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3912 if (hr == S_OK)
3913 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
3915 LeaveCriticalSection(&This->cs);
3917 return hr;
3920 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
3922 struct filter_graph *This = impl_from_IVideoWindow(iface);
3923 IVideoWindow *pVideoWindow;
3924 HRESULT hr;
3926 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
3928 EnterCriticalSection(&This->cs);
3930 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3932 if (hr == S_OK)
3933 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
3935 LeaveCriticalSection(&This->cs);
3937 return hr;
3940 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
3942 struct filter_graph *This = impl_from_IVideoWindow(iface);
3943 IVideoWindow *pVideoWindow;
3944 HRESULT hr;
3946 TRACE("graph %p, style %#lx.\n", This, WindowStyleEx);
3948 EnterCriticalSection(&This->cs);
3950 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3952 if (hr == S_OK)
3953 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
3955 LeaveCriticalSection(&This->cs);
3957 return hr;
3960 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
3962 struct filter_graph *This = impl_from_IVideoWindow(iface);
3963 IVideoWindow *pVideoWindow;
3964 HRESULT hr;
3966 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
3968 EnterCriticalSection(&This->cs);
3970 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3972 if (hr == S_OK)
3973 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
3975 LeaveCriticalSection(&This->cs);
3977 return hr;
3980 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
3982 struct filter_graph *This = impl_from_IVideoWindow(iface);
3983 IVideoWindow *pVideoWindow;
3984 HRESULT hr;
3986 TRACE("graph %p, show %#lx.\n", This, AutoShow);
3988 EnterCriticalSection(&This->cs);
3990 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3992 if (hr == S_OK)
3993 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
3995 LeaveCriticalSection(&This->cs);
3997 return hr;
4000 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
4002 struct filter_graph *This = impl_from_IVideoWindow(iface);
4003 IVideoWindow *pVideoWindow;
4004 HRESULT hr;
4006 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4008 EnterCriticalSection(&This->cs);
4010 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4012 if (hr == S_OK)
4013 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4015 LeaveCriticalSection(&This->cs);
4017 return hr;
4020 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
4022 struct filter_graph *This = impl_from_IVideoWindow(iface);
4023 IVideoWindow *pVideoWindow;
4024 HRESULT hr;
4026 TRACE("graph %p, state %ld.\n", This, WindowState);
4028 EnterCriticalSection(&This->cs);
4030 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4032 if (hr == S_OK)
4033 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4035 LeaveCriticalSection(&This->cs);
4037 return hr;
4040 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4042 struct filter_graph *This = impl_from_IVideoWindow(iface);
4043 IVideoWindow *pVideoWindow;
4044 HRESULT hr;
4046 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4048 EnterCriticalSection(&This->cs);
4050 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4052 if (hr == S_OK)
4053 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4055 LeaveCriticalSection(&This->cs);
4057 return hr;
4060 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4062 struct filter_graph *This = impl_from_IVideoWindow(iface);
4063 IVideoWindow *pVideoWindow;
4064 HRESULT hr;
4066 TRACE("graph %p, palette %ld.\n", This, BackgroundPalette);
4068 EnterCriticalSection(&This->cs);
4070 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4072 if (hr == S_OK)
4073 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4075 LeaveCriticalSection(&This->cs);
4077 return hr;
4080 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4081 LONG *pBackgroundPalette)
4083 struct filter_graph *This = impl_from_IVideoWindow(iface);
4084 IVideoWindow *pVideoWindow;
4085 HRESULT hr;
4087 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4089 EnterCriticalSection(&This->cs);
4091 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4093 if (hr == S_OK)
4094 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4096 LeaveCriticalSection(&This->cs);
4098 return hr;
4101 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4103 struct filter_graph *This = impl_from_IVideoWindow(iface);
4104 IVideoWindow *pVideoWindow;
4105 HRESULT hr;
4107 TRACE("graph %p, visible %ld.\n", This, Visible);
4109 EnterCriticalSection(&This->cs);
4111 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4113 if (hr == S_OK)
4114 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4116 LeaveCriticalSection(&This->cs);
4118 return hr;
4121 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4123 struct filter_graph *This = impl_from_IVideoWindow(iface);
4124 IVideoWindow *pVideoWindow;
4125 HRESULT hr;
4127 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4129 EnterCriticalSection(&This->cs);
4131 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4133 if (hr == S_OK)
4134 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4136 LeaveCriticalSection(&This->cs);
4138 return hr;
4141 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4143 struct filter_graph *This = impl_from_IVideoWindow(iface);
4144 IVideoWindow *pVideoWindow;
4145 HRESULT hr;
4147 TRACE("graph %p, left %ld.\n", This, Left);
4149 EnterCriticalSection(&This->cs);
4151 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4153 if (hr == S_OK)
4154 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4156 LeaveCriticalSection(&This->cs);
4158 return hr;
4161 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4163 struct filter_graph *This = impl_from_IVideoWindow(iface);
4164 IVideoWindow *pVideoWindow;
4165 HRESULT hr;
4167 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4169 EnterCriticalSection(&This->cs);
4171 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4173 if (hr == S_OK)
4174 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4176 LeaveCriticalSection(&This->cs);
4178 return hr;
4181 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4183 struct filter_graph *This = impl_from_IVideoWindow(iface);
4184 IVideoWindow *pVideoWindow;
4185 HRESULT hr;
4187 TRACE("graph %p, width %ld.\n", This, Width);
4189 EnterCriticalSection(&This->cs);
4191 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4193 if (hr == S_OK)
4194 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4196 LeaveCriticalSection(&This->cs);
4198 return hr;
4201 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4203 struct filter_graph *This = impl_from_IVideoWindow(iface);
4204 IVideoWindow *pVideoWindow;
4205 HRESULT hr;
4207 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4209 EnterCriticalSection(&This->cs);
4211 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4213 if (hr == S_OK)
4214 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4216 LeaveCriticalSection(&This->cs);
4218 return hr;
4221 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4223 struct filter_graph *This = impl_from_IVideoWindow(iface);
4224 IVideoWindow *pVideoWindow;
4225 HRESULT hr;
4227 TRACE("graph %p, top %ld.\n", This, Top);
4229 EnterCriticalSection(&This->cs);
4231 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4233 if (hr == S_OK)
4234 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4236 LeaveCriticalSection(&This->cs);
4238 return hr;
4241 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4243 struct filter_graph *This = impl_from_IVideoWindow(iface);
4244 IVideoWindow *pVideoWindow;
4245 HRESULT hr;
4247 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4249 EnterCriticalSection(&This->cs);
4251 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4253 if (hr == S_OK)
4254 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4256 LeaveCriticalSection(&This->cs);
4258 return hr;
4261 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4263 struct filter_graph *This = impl_from_IVideoWindow(iface);
4264 IVideoWindow *pVideoWindow;
4265 HRESULT hr;
4267 TRACE("graph %p, height %ld.\n", This, Height);
4269 EnterCriticalSection(&This->cs);
4271 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4273 if (hr == S_OK)
4274 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4276 LeaveCriticalSection(&This->cs);
4278 return hr;
4281 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4283 struct filter_graph *This = impl_from_IVideoWindow(iface);
4284 IVideoWindow *pVideoWindow;
4285 HRESULT hr;
4287 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4289 EnterCriticalSection(&This->cs);
4291 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4293 if (hr == S_OK)
4294 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4296 LeaveCriticalSection(&This->cs);
4298 return hr;
4301 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4303 struct filter_graph *This = impl_from_IVideoWindow(iface);
4304 IVideoWindow *pVideoWindow;
4305 HRESULT hr;
4307 TRACE("graph %p, owner %#Ix.\n", This, Owner);
4309 EnterCriticalSection(&This->cs);
4311 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4313 if (hr == S_OK)
4314 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4316 LeaveCriticalSection(&This->cs);
4318 return hr;
4321 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4323 struct filter_graph *This = impl_from_IVideoWindow(iface);
4324 IVideoWindow *pVideoWindow;
4325 HRESULT hr;
4327 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4329 EnterCriticalSection(&This->cs);
4331 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4333 if (hr == S_OK)
4334 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4336 LeaveCriticalSection(&This->cs);
4338 return hr;
4341 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4343 struct filter_graph *This = impl_from_IVideoWindow(iface);
4344 IVideoWindow *pVideoWindow;
4345 HRESULT hr;
4347 TRACE("graph %p, drain %#Ix.\n", This, Drain);
4349 EnterCriticalSection(&This->cs);
4351 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4353 if (hr == S_OK)
4354 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4356 LeaveCriticalSection(&This->cs);
4358 return hr;
4361 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4363 struct filter_graph *This = impl_from_IVideoWindow(iface);
4364 IVideoWindow *pVideoWindow;
4365 HRESULT hr;
4367 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4369 EnterCriticalSection(&This->cs);
4371 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4373 if (hr == S_OK)
4374 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4376 LeaveCriticalSection(&This->cs);
4378 return hr;
4381 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4383 struct filter_graph *This = impl_from_IVideoWindow(iface);
4384 IVideoWindow *pVideoWindow;
4385 HRESULT hr;
4387 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4389 EnterCriticalSection(&This->cs);
4391 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4393 if (hr == S_OK)
4394 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4396 LeaveCriticalSection(&This->cs);
4398 return hr;
4401 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4403 struct filter_graph *This = impl_from_IVideoWindow(iface);
4404 IVideoWindow *pVideoWindow;
4405 HRESULT hr;
4407 TRACE("graph %p, colour %#lx.\n", This, Color);
4409 EnterCriticalSection(&This->cs);
4411 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4413 if (hr == S_OK)
4414 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4416 LeaveCriticalSection(&This->cs);
4418 return hr;
4421 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4423 struct filter_graph *This = impl_from_IVideoWindow(iface);
4424 IVideoWindow *pVideoWindow;
4425 HRESULT hr;
4427 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4429 EnterCriticalSection(&This->cs);
4431 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4433 if (hr == S_OK)
4434 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4436 LeaveCriticalSection(&This->cs);
4438 return hr;
4441 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4443 struct filter_graph *This = impl_from_IVideoWindow(iface);
4444 IVideoWindow *pVideoWindow;
4445 HRESULT hr;
4447 TRACE("graph %p, fullscreen %ld.\n", This, FullScreenMode);
4449 EnterCriticalSection(&This->cs);
4451 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4453 if (hr == S_OK)
4454 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4456 LeaveCriticalSection(&This->cs);
4458 return hr;
4461 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4463 struct filter_graph *This = impl_from_IVideoWindow(iface);
4464 IVideoWindow *pVideoWindow;
4465 HRESULT hr;
4467 TRACE("graph %p, focus %ld.\n", This, Focus);
4469 EnterCriticalSection(&This->cs);
4471 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4473 if (hr == S_OK)
4474 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4476 LeaveCriticalSection(&This->cs);
4478 return hr;
4481 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4482 LONG_PTR wParam, LONG_PTR lParam)
4484 struct filter_graph *This = impl_from_IVideoWindow(iface);
4485 IVideoWindow *pVideoWindow;
4486 HRESULT hr;
4488 TRACE("graph %p, hwnd %#Ix, message %#lx, wparam %#Ix, lparam %#Ix.\n", This, hwnd, uMsg, wParam, lParam);
4490 EnterCriticalSection(&This->cs);
4492 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4494 if (hr == S_OK)
4495 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4497 LeaveCriticalSection(&This->cs);
4499 return hr;
4502 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4503 LONG Width, LONG Height)
4505 struct filter_graph *This = impl_from_IVideoWindow(iface);
4506 IVideoWindow *pVideoWindow;
4507 HRESULT hr;
4509 TRACE("graph %p, left %ld, top %ld, width %ld, height %ld.\n", This, Left, Top, Width, Height);
4511 EnterCriticalSection(&This->cs);
4513 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4515 if (hr == S_OK)
4516 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4518 LeaveCriticalSection(&This->cs);
4520 return hr;
4523 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4524 LONG *pWidth, LONG *pHeight)
4526 struct filter_graph *This = impl_from_IVideoWindow(iface);
4527 IVideoWindow *pVideoWindow;
4528 HRESULT hr;
4530 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4532 EnterCriticalSection(&This->cs);
4534 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4536 if (hr == S_OK)
4537 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4539 LeaveCriticalSection(&This->cs);
4541 return hr;
4544 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4545 LONG *pHeight)
4547 struct filter_graph *This = impl_from_IVideoWindow(iface);
4548 IVideoWindow *pVideoWindow;
4549 HRESULT hr;
4551 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4553 EnterCriticalSection(&This->cs);
4555 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4557 if (hr == S_OK)
4558 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4560 LeaveCriticalSection(&This->cs);
4562 return hr;
4565 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4566 LONG *pHeight)
4568 struct filter_graph *This = impl_from_IVideoWindow(iface);
4569 IVideoWindow *pVideoWindow;
4570 HRESULT hr;
4572 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4574 EnterCriticalSection(&This->cs);
4576 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4578 if (hr == S_OK)
4579 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4581 LeaveCriticalSection(&This->cs);
4583 return hr;
4586 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4587 LONG *pWidth, LONG *pHeight)
4589 struct filter_graph *This = impl_from_IVideoWindow(iface);
4590 IVideoWindow *pVideoWindow;
4591 HRESULT hr;
4593 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4595 EnterCriticalSection(&This->cs);
4597 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4599 if (hr == S_OK)
4600 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4602 LeaveCriticalSection(&This->cs);
4604 return hr;
4607 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4609 struct filter_graph *This = impl_from_IVideoWindow(iface);
4610 IVideoWindow *pVideoWindow;
4611 HRESULT hr;
4613 TRACE("graph %p, hide %ld.\n", This, HideCursor);
4615 EnterCriticalSection(&This->cs);
4617 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4619 if (hr == S_OK)
4620 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4622 LeaveCriticalSection(&This->cs);
4624 return hr;
4627 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4629 struct filter_graph *This = impl_from_IVideoWindow(iface);
4630 IVideoWindow *pVideoWindow;
4631 HRESULT hr;
4633 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4635 EnterCriticalSection(&This->cs);
4637 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4639 if (hr == S_OK)
4640 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4642 LeaveCriticalSection(&This->cs);
4644 return hr;
4648 static const IVideoWindowVtbl IVideoWindow_VTable =
4650 VideoWindow_QueryInterface,
4651 VideoWindow_AddRef,
4652 VideoWindow_Release,
4653 VideoWindow_GetTypeInfoCount,
4654 VideoWindow_GetTypeInfo,
4655 VideoWindow_GetIDsOfNames,
4656 VideoWindow_Invoke,
4657 VideoWindow_put_Caption,
4658 VideoWindow_get_Caption,
4659 VideoWindow_put_WindowStyle,
4660 VideoWindow_get_WindowStyle,
4661 VideoWindow_put_WindowStyleEx,
4662 VideoWindow_get_WindowStyleEx,
4663 VideoWindow_put_AutoShow,
4664 VideoWindow_get_AutoShow,
4665 VideoWindow_put_WindowState,
4666 VideoWindow_get_WindowState,
4667 VideoWindow_put_BackgroundPalette,
4668 VideoWindow_get_BackgroundPalette,
4669 VideoWindow_put_Visible,
4670 VideoWindow_get_Visible,
4671 VideoWindow_put_Left,
4672 VideoWindow_get_Left,
4673 VideoWindow_put_Width,
4674 VideoWindow_get_Width,
4675 VideoWindow_put_Top,
4676 VideoWindow_get_Top,
4677 VideoWindow_put_Height,
4678 VideoWindow_get_Height,
4679 VideoWindow_put_Owner,
4680 VideoWindow_get_Owner,
4681 VideoWindow_put_MessageDrain,
4682 VideoWindow_get_MessageDrain,
4683 VideoWindow_get_BorderColor,
4684 VideoWindow_put_BorderColor,
4685 VideoWindow_get_FullScreenMode,
4686 VideoWindow_put_FullScreenMode,
4687 VideoWindow_SetWindowForeground,
4688 VideoWindow_NotifyOwnerMessage,
4689 VideoWindow_SetWindowPosition,
4690 VideoWindow_GetWindowPosition,
4691 VideoWindow_GetMinIdealImageSize,
4692 VideoWindow_GetMaxIdealImageSize,
4693 VideoWindow_GetRestorePosition,
4694 VideoWindow_HideCursor,
4695 VideoWindow_IsCursorHidden
4698 static struct filter_graph *impl_from_IMediaEventEx(IMediaEventEx *iface)
4700 return CONTAINING_RECORD(iface, struct filter_graph, IMediaEventEx_iface);
4703 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID iid, void **out)
4705 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4706 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
4709 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
4711 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4712 return IUnknown_AddRef(graph->outer_unk);
4715 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
4717 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4718 return IUnknown_Release(graph->outer_unk);
4721 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *count)
4723 TRACE("iface %p, count %p.\n", iface, count);
4724 *count = 1;
4725 return S_OK;
4728 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT index,
4729 LCID lcid, ITypeInfo **typeinfo)
4731 TRACE("iface %p, index %u, lcid %#lx, typeinfo %p.\n", iface, index, lcid, typeinfo);
4732 return strmbase_get_typeinfo(IMediaEvent_tid, typeinfo);
4735 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID iid,
4736 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
4738 ITypeInfo *typeinfo;
4739 HRESULT hr;
4741 TRACE("iface %p, iid %s, names %p, count %u, lcid %#lx, ids %p.\n",
4742 iface, debugstr_guid(iid), names, count, lcid, ids);
4744 if (SUCCEEDED(hr = strmbase_get_typeinfo(IMediaEvent_tid, &typeinfo)))
4746 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
4747 ITypeInfo_Release(typeinfo);
4749 return hr;
4752 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID id, REFIID iid, LCID lcid,
4753 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
4755 ITypeInfo *typeinfo;
4756 HRESULT hr;
4758 TRACE("iface %p, id %ld, iid %s, lcid %#lx, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
4759 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
4761 if (SUCCEEDED(hr = strmbase_get_typeinfo(IMediaEvent_tid, &typeinfo)))
4763 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
4764 ITypeInfo_Release(typeinfo);
4766 return hr;
4769 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *event)
4771 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4773 TRACE("graph %p, event %p.\n", graph, event);
4775 *event = (OAEVENT)graph->media_event_handle;
4776 return S_OK;
4779 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *code,
4780 LONG_PTR *param1, LONG_PTR *param2, LONG timeout)
4782 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4783 struct media_event *event;
4784 struct list *entry;
4786 TRACE("graph %p, code %p, param1 %p, param2 %p, timeout %ld.\n", graph, code, param1, param2, timeout);
4788 *code = 0;
4790 if (WaitForSingleObject(graph->media_event_handle, timeout))
4791 return E_ABORT;
4793 EnterCriticalSection(&graph->event_cs);
4795 if (!(entry = list_head(&graph->media_events)))
4797 ResetEvent(graph->media_event_handle);
4798 LeaveCriticalSection(&graph->event_cs);
4799 return E_ABORT;
4801 event = LIST_ENTRY(entry, struct media_event, entry);
4802 list_remove(&event->entry);
4803 *code = event->code;
4804 *param1 = event->param1;
4805 *param2 = event->param2;
4806 free(event);
4808 LeaveCriticalSection(&graph->event_cs);
4809 return S_OK;
4812 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
4813 LONG *pEvCode)
4815 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4817 TRACE("graph %p, timeout %ld, code %p.\n", This, msTimeout, pEvCode);
4819 if (This->state != State_Running)
4820 return VFW_E_WRONG_STATE;
4822 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
4824 *pEvCode = This->CompletionStatus;
4825 return S_OK;
4828 *pEvCode = 0;
4829 return E_ABORT;
4832 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
4834 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4836 TRACE("graph %p, code %#lx.\n", This, lEvCode);
4838 if (lEvCode == EC_COMPLETE)
4839 This->HandleEcComplete = FALSE;
4840 else if (lEvCode == EC_REPAINT)
4841 This->HandleEcRepaint = FALSE;
4842 else if (lEvCode == EC_CLOCK_CHANGED)
4843 This->HandleEcClockChanged = FALSE;
4844 else
4845 return S_FALSE;
4847 return S_OK;
4850 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
4852 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4854 TRACE("graph %p, code %#lx.\n", This, lEvCode);
4856 if (lEvCode == EC_COMPLETE)
4857 This->HandleEcComplete = TRUE;
4858 else if (lEvCode == EC_REPAINT)
4859 This->HandleEcRepaint = TRUE;
4860 else if (lEvCode == EC_CLOCK_CHANGED)
4861 This->HandleEcClockChanged = TRUE;
4862 else
4863 return S_FALSE;
4865 return S_OK;
4868 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG code,
4869 LONG_PTR param1, LONG_PTR param2)
4871 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4873 WARN("graph %p, code %#lx, param1 %Id, param2 %Id, stub!\n", graph, code, param1, param2);
4875 return S_OK;
4878 /*** IMediaEventEx methods ***/
4879 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface,
4880 OAHWND window, LONG message, LONG_PTR lparam)
4882 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4884 TRACE("graph %p, window %#Ix, message %#lx, lparam %#Ix.\n", graph, window, message, lparam);
4886 graph->media_event_window = (HWND)window;
4887 graph->media_event_message = message;
4888 graph->media_event_lparam = lparam;
4890 return S_OK;
4893 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG flags)
4895 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4897 TRACE("graph %p, flags %#lx.\n", graph, flags);
4899 if (flags & ~AM_MEDIAEVENT_NONOTIFY)
4901 WARN("Invalid flags %#lx, returning E_INVALIDARG.\n", flags);
4902 return E_INVALIDARG;
4905 graph->media_events_disabled = flags;
4907 if (flags)
4909 flush_media_events(graph);
4910 ResetEvent(graph->media_event_handle);
4913 return S_OK;
4916 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *flags)
4918 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4920 TRACE("graph %p, flags %p.\n", graph, flags);
4922 if (!flags)
4923 return E_POINTER;
4925 *flags = graph->media_events_disabled;
4927 return S_OK;
4931 static const IMediaEventExVtbl IMediaEventEx_VTable =
4933 MediaEvent_QueryInterface,
4934 MediaEvent_AddRef,
4935 MediaEvent_Release,
4936 MediaEvent_GetTypeInfoCount,
4937 MediaEvent_GetTypeInfo,
4938 MediaEvent_GetIDsOfNames,
4939 MediaEvent_Invoke,
4940 MediaEvent_GetEventHandle,
4941 MediaEvent_GetEvent,
4942 MediaEvent_WaitForCompletion,
4943 MediaEvent_CancelDefaultHandling,
4944 MediaEvent_RestoreDefaultHandling,
4945 MediaEvent_FreeEventParams,
4946 MediaEvent_SetNotifyWindow,
4947 MediaEvent_SetNotifyFlags,
4948 MediaEvent_GetNotifyFlags
4952 static struct filter_graph *impl_from_IMediaFilter(IMediaFilter *iface)
4954 return CONTAINING_RECORD(iface, struct filter_graph, IMediaFilter_iface);
4957 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID iid, void **out)
4959 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4961 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
4964 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
4966 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4968 return IUnknown_AddRef(graph->outer_unk);
4971 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
4973 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4975 return IUnknown_Release(graph->outer_unk);
4978 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
4980 FIXME("(%p): stub\n", pClassID);
4982 return E_NOTIMPL;
4985 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
4987 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4988 HRESULT hr = S_OK, filter_hr;
4989 struct filter *filter;
4990 TP_WORK *work;
4992 TRACE("graph %p.\n", graph);
4994 EnterCriticalSection(&graph->cs);
4996 if (graph->state == State_Stopped)
4998 LeaveCriticalSection(&graph->cs);
4999 return S_OK;
5002 sort_filters(graph);
5004 if (graph->state == State_Running)
5006 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5008 filter_hr = IBaseFilter_Pause(filter->filter);
5009 if (hr == S_OK)
5010 hr = filter_hr;
5014 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5016 filter_hr = IBaseFilter_Stop(filter->filter);
5017 if (hr == S_OK)
5018 hr = filter_hr;
5021 graph->state = State_Stopped;
5022 graph->needs_async_run = 0;
5023 work = graph->async_run_work;
5024 graph->got_ec_complete = 0;
5026 /* Update the current position, probably to synchronize multiple streams. */
5027 IMediaSeeking_SetPositions(&graph->IMediaSeeking_iface, &graph->current_pos,
5028 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
5030 LeaveCriticalSection(&graph->cs);
5032 if (work)
5033 WaitForThreadpoolWorkCallbacks(work, TRUE);
5035 return hr;
5038 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5040 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5041 HRESULT hr = S_OK, filter_hr;
5042 struct filter *filter;
5043 TP_WORK *work;
5045 TRACE("graph %p.\n", graph);
5047 EnterCriticalSection(&graph->cs);
5049 if (graph->state == State_Paused)
5051 LeaveCriticalSection(&graph->cs);
5052 return S_OK;
5055 sort_filters(graph);
5057 EnterCriticalSection(&graph->event_cs);
5058 update_render_count(graph);
5059 LeaveCriticalSection(&graph->event_cs);
5061 if (graph->defaultclock && !graph->refClock)
5062 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
5064 if (graph->state == State_Running && !graph->needs_async_run && graph->refClock)
5066 REFERENCE_TIME time;
5067 IReferenceClock_GetTime(graph->refClock, &time);
5068 graph->stream_elapsed += time - graph->stream_start;
5069 graph->current_pos += graph->stream_elapsed;
5072 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5074 filter_hr = IBaseFilter_Pause(filter->filter);
5075 if (hr == S_OK)
5076 hr = filter_hr;
5079 graph->state = State_Paused;
5080 graph->needs_async_run = 0;
5081 work = graph->async_run_work;
5083 LeaveCriticalSection(&graph->cs);
5085 if (work)
5086 WaitForThreadpoolWorkCallbacks(work, TRUE);
5088 return hr;
5091 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME start)
5093 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5094 HRESULT hr;
5096 TRACE("graph %p, start %s.\n", graph, debugstr_time(start));
5098 EnterCriticalSection(&graph->cs);
5100 if (graph->state == State_Running)
5102 LeaveCriticalSection(&graph->cs);
5103 return S_OK;
5106 sort_filters(graph);
5108 hr = graph_start(graph, start);
5110 graph->state = State_Running;
5111 graph->needs_async_run = 0;
5113 LeaveCriticalSection(&graph->cs);
5114 return hr;
5117 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD timeout, FILTER_STATE *state)
5119 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5120 DWORD end = GetTickCount() + timeout;
5121 HRESULT hr;
5123 TRACE("graph %p, timeout %lu, state %p.\n", graph, timeout, state);
5125 if (!state)
5126 return E_POINTER;
5128 /* Thread safety is a little tricky here. GetState() shouldn't block other
5129 * functions from being called on the filter graph. However, we can't just
5130 * call IBaseFilter::GetState() in one loop and drop the lock on every
5131 * iteration, since the filter list might change beneath us. So instead we
5132 * do what native does, and poll for it every 10 ms. */
5134 EnterCriticalSection(&graph->cs);
5135 *state = graph->state;
5137 for (;;)
5139 IBaseFilter *async_filter = NULL;
5140 FILTER_STATE filter_state;
5141 struct filter *filter;
5143 hr = S_OK;
5145 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5147 HRESULT filter_hr = IBaseFilter_GetState(filter->filter, 0, &filter_state);
5149 TRACE("Filter %p returned hr %#lx, state %u.\n", filter->filter, filter_hr, filter_state);
5151 if (filter_hr == VFW_S_STATE_INTERMEDIATE)
5152 async_filter = filter->filter;
5154 if (hr == S_OK && filter_hr == VFW_S_STATE_INTERMEDIATE)
5155 hr = VFW_S_STATE_INTERMEDIATE;
5156 else if (filter_hr != S_OK && filter_hr != VFW_S_STATE_INTERMEDIATE)
5157 hr = filter_hr;
5159 if (hr == S_OK && filter_state == State_Paused && graph->state != State_Paused)
5161 async_filter = filter->filter;
5162 hr = VFW_S_STATE_INTERMEDIATE;
5164 else if (filter_state != graph->state && filter_state != State_Paused)
5165 hr = E_FAIL;
5167 if (graph->needs_async_run)
5169 if (filter_state != State_Paused && filter_state != State_Running)
5170 ERR("Filter %p reported incorrect state %u (expected %u or %u).\n",
5171 filter->filter, filter_state, State_Paused, State_Running);
5173 else
5175 if (filter_state != graph->state)
5176 ERR("Filter %p reported incorrect state %u (expected %u).\n",
5177 filter->filter, filter_state, graph->state);
5181 LeaveCriticalSection(&graph->cs);
5183 if (hr != VFW_S_STATE_INTERMEDIATE || (timeout != INFINITE && GetTickCount() >= end))
5184 break;
5186 IBaseFilter_GetState(async_filter, 10, &filter_state);
5188 EnterCriticalSection(&graph->cs);
5191 TRACE("Returning %#lx, state %u.\n", hr, *state);
5192 return hr;
5195 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5197 struct filter_graph *This = impl_from_IMediaFilter(iface);
5198 struct filter *filter;
5199 HRESULT hr = S_OK;
5201 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
5203 EnterCriticalSection(&This->cs);
5205 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
5207 hr = IBaseFilter_SetSyncSource(filter->filter, pClock);
5208 if (FAILED(hr))
5209 break;
5212 if (FAILED(hr))
5214 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
5215 IBaseFilter_SetSyncSource(filter->filter, This->refClock);
5217 else
5219 if (This->refClock)
5220 IReferenceClock_Release(This->refClock);
5221 This->refClock = pClock;
5222 if (This->refClock)
5223 IReferenceClock_AddRef(This->refClock);
5224 This->defaultclock = FALSE;
5226 if (This->HandleEcClockChanged)
5228 IMediaEventSink *pEventSink;
5229 HRESULT eshr;
5231 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (void **)&pEventSink);
5232 if (SUCCEEDED(eshr))
5234 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5235 IMediaEventSink_Release(pEventSink);
5240 LeaveCriticalSection(&This->cs);
5242 return hr;
5245 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5247 struct filter_graph *This = impl_from_IMediaFilter(iface);
5249 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
5251 if (!ppClock)
5252 return E_POINTER;
5254 EnterCriticalSection(&This->cs);
5256 *ppClock = This->refClock;
5257 if (*ppClock)
5258 IReferenceClock_AddRef(*ppClock);
5260 LeaveCriticalSection(&This->cs);
5262 return S_OK;
5265 static const IMediaFilterVtbl IMediaFilter_VTable =
5267 MediaFilter_QueryInterface,
5268 MediaFilter_AddRef,
5269 MediaFilter_Release,
5270 MediaFilter_GetClassID,
5271 MediaFilter_Stop,
5272 MediaFilter_Pause,
5273 MediaFilter_Run,
5274 MediaFilter_GetState,
5275 MediaFilter_SetSyncSource,
5276 MediaFilter_GetSyncSource
5279 static struct filter_graph *impl_from_IMediaEventSink(IMediaEventSink *iface)
5281 return CONTAINING_RECORD(iface, struct filter_graph, IMediaEventSink_iface);
5284 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID iid, void **out)
5286 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5288 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5291 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5293 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5295 return IUnknown_AddRef(graph->outer_unk);
5298 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5300 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5302 return IUnknown_Release(graph->outer_unk);
5305 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG code,
5306 LONG_PTR param1, LONG_PTR param2)
5308 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5310 TRACE("graph %p, code %#lx, param1 %#Ix, param2 %#Ix.\n", graph, code, param1, param2);
5312 EnterCriticalSection(&graph->event_cs);
5314 if (code == EC_COMPLETE && graph->HandleEcComplete)
5316 if (++graph->EcCompleteCount == graph->nRenderers)
5318 if (graph->media_events_disabled)
5319 SetEvent(graph->media_event_handle);
5320 else
5321 queue_media_event(graph, EC_COMPLETE, S_OK, 0);
5322 graph->CompletionStatus = EC_COMPLETE;
5323 graph->got_ec_complete = 1;
5324 SetEvent(graph->hEventCompletion);
5327 else if ((code == EC_REPAINT) && graph->HandleEcRepaint)
5329 FIXME("EC_REPAINT is not handled.\n");
5331 else if (!graph->media_events_disabled)
5333 queue_media_event(graph, code, param1, param2);
5336 LeaveCriticalSection(&graph->event_cs);
5337 return S_OK;
5340 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5342 MediaEventSink_QueryInterface,
5343 MediaEventSink_AddRef,
5344 MediaEventSink_Release,
5345 MediaEventSink_Notify
5348 static struct filter_graph *impl_from_IGraphConfig(IGraphConfig *iface)
5350 return CONTAINING_RECORD(iface, struct filter_graph, IGraphConfig_iface);
5353 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID iid, void **out)
5355 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5357 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5360 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5362 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5364 return IUnknown_AddRef(graph->outer_unk);
5367 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5369 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5371 return IUnknown_Release(graph->outer_unk);
5374 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *source, IPin *sink,
5375 const AM_MEDIA_TYPE *mt, IBaseFilter *filter, HANDLE abort_event, DWORD flags)
5377 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5379 FIXME("graph %p, source %p, sink %p, mt %p, filter %p, abort_event %p, flags %#lx, stub!\n",
5380 graph, source, sink, mt, filter, abort_event, flags);
5381 strmbase_dump_media_type(mt);
5383 return E_NOTIMPL;
5386 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface,
5387 IGraphConfigCallback *callback, void *context, DWORD flags, HANDLE abort_event)
5389 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5390 HRESULT hr;
5392 TRACE("graph %p, callback %p, context %p, flags %#lx, abort_event %p.\n",
5393 graph, callback, context, flags, abort_event);
5395 if (abort_event)
5396 FIXME("The parameter hAbortEvent is not handled!\n");
5398 EnterCriticalSection(&graph->cs);
5400 hr = IGraphConfigCallback_Reconfigure(callback, context, flags);
5402 LeaveCriticalSection(&graph->cs);
5404 return hr;
5407 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5409 struct filter_graph *This = impl_from_IGraphConfig(iface);
5411 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5413 return E_NOTIMPL;
5416 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5418 struct filter_graph *This = impl_from_IGraphConfig(iface);
5420 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5422 return E_NOTIMPL;
5425 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5427 struct filter_graph *This = impl_from_IGraphConfig(iface);
5429 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5431 return E_NOTIMPL;
5434 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5436 struct filter_graph *This = impl_from_IGraphConfig(iface);
5438 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5440 return E_NOTIMPL;
5443 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5444 IPinConnection *pConnection, HANDLE hEventAbort)
5446 struct filter_graph *This = impl_from_IGraphConfig(iface);
5448 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5450 return E_NOTIMPL;
5453 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *filter, DWORD flags)
5455 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5457 FIXME("graph %p, filter %p, flags %#lx, stub!\n", graph, filter, flags);
5459 return E_NOTIMPL;
5462 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5463 DWORD *dwFlags)
5465 struct filter_graph *This = impl_from_IGraphConfig(iface);
5467 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5469 return E_NOTIMPL;
5472 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *filter, DWORD flags)
5474 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5476 FIXME("graph %p, filter %p, flags %#lx, stub!\n", graph, filter, flags);
5478 return E_NOTIMPL;
5481 static const IGraphConfigVtbl IGraphConfig_VTable =
5483 GraphConfig_QueryInterface,
5484 GraphConfig_AddRef,
5485 GraphConfig_Release,
5486 GraphConfig_Reconnect,
5487 GraphConfig_Reconfigure,
5488 GraphConfig_AddFilterToCache,
5489 GraphConfig_EnumCacheFilter,
5490 GraphConfig_RemoveFilterFromCache,
5491 GraphConfig_GetStartTime,
5492 GraphConfig_PushThroughData,
5493 GraphConfig_SetFilterFlags,
5494 GraphConfig_GetFilterFlags,
5495 GraphConfig_RemoveFilterEx
5498 static struct filter_graph *impl_from_IGraphVersion(IGraphVersion *iface)
5500 return CONTAINING_RECORD(iface, struct filter_graph, IGraphVersion_iface);
5503 static HRESULT WINAPI GraphVersion_QueryInterface(IGraphVersion *iface, REFIID iid, void **out)
5505 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5507 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5510 static ULONG WINAPI GraphVersion_AddRef(IGraphVersion *iface)
5512 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5514 return IUnknown_AddRef(graph->outer_unk);
5517 static ULONG WINAPI GraphVersion_Release(IGraphVersion *iface)
5519 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5521 return IUnknown_Release(graph->outer_unk);
5524 static HRESULT WINAPI GraphVersion_QueryVersion(IGraphVersion *iface, LONG *version)
5526 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5528 TRACE("graph %p, version %p, returning %ld.\n", graph, version, graph->version);
5530 if (!version)
5531 return E_POINTER;
5533 *version = graph->version;
5534 return S_OK;
5537 static const IGraphVersionVtbl IGraphVersion_VTable =
5539 GraphVersion_QueryInterface,
5540 GraphVersion_AddRef,
5541 GraphVersion_Release,
5542 GraphVersion_QueryVersion,
5545 static struct filter_graph *impl_from_IVideoFrameStep(IVideoFrameStep *iface)
5547 return CONTAINING_RECORD(iface, struct filter_graph, IVideoFrameStep_iface);
5550 static HRESULT WINAPI VideoFrameStep_QueryInterface(IVideoFrameStep *iface, REFIID iid, void **out)
5552 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5553 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5556 static ULONG WINAPI VideoFrameStep_AddRef(IVideoFrameStep *iface)
5558 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5559 return IUnknown_AddRef(graph->outer_unk);
5562 static ULONG WINAPI VideoFrameStep_Release(IVideoFrameStep *iface)
5564 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5565 return IUnknown_Release(graph->outer_unk);
5568 static HRESULT WINAPI VideoFrameStep_Step(IVideoFrameStep *iface, DWORD frame_count, IUnknown *filter)
5570 FIXME("iface %p, frame_count %lu, filter %p, stub!\n", iface, frame_count, filter);
5571 return E_NOTIMPL;
5574 static HRESULT WINAPI VideoFrameStep_CanStep(IVideoFrameStep *iface, LONG multiple, IUnknown *filter)
5576 FIXME("iface %p, multiple %ld, filter %p, stub!\n", iface, multiple, filter);
5577 return E_NOTIMPL;
5580 static HRESULT WINAPI VideoFrameStep_CancelStep(IVideoFrameStep *iface)
5582 FIXME("iface %p, stub!\n", iface);
5583 return E_NOTIMPL;
5586 static const IVideoFrameStepVtbl VideoFrameStep_vtbl =
5588 VideoFrameStep_QueryInterface,
5589 VideoFrameStep_AddRef,
5590 VideoFrameStep_Release,
5591 VideoFrameStep_Step,
5592 VideoFrameStep_CanStep,
5593 VideoFrameStep_CancelStep
5596 static const IUnknownVtbl IInner_VTable =
5598 FilterGraphInner_QueryInterface,
5599 FilterGraphInner_AddRef,
5600 FilterGraphInner_Release
5603 static HRESULT filter_graph_common_create(IUnknown *outer, IUnknown **out, BOOL threaded)
5605 struct filter_graph *object;
5606 HRESULT hr;
5608 *out = NULL;
5610 if (!(object = calloc(1, sizeof(*object))))
5611 return E_OUTOFMEMORY;
5613 object->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5614 object->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5615 object->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5616 object->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5617 object->IGraphVersion_iface.lpVtbl = &IGraphVersion_VTable;
5618 object->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5619 object->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5620 object->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5621 object->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5622 object->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5623 object->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5624 object->IObjectWithSite_iface.lpVtbl = &IObjectWithSite_VTable;
5625 object->IUnknown_inner.lpVtbl = &IInner_VTable;
5626 object->IVideoFrameStep_iface.lpVtbl = &VideoFrameStep_vtbl;
5627 object->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5628 object->ref = 1;
5629 object->outer_unk = outer ? outer : &object->IUnknown_inner;
5631 if (FAILED(hr = CoCreateInstance(&CLSID_FilterMapper2, object->outer_unk,
5632 CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&object->punkFilterMapper2)))
5634 ERR("Failed to create filter mapper, hr %#lx.\n", hr);
5635 free(object);
5636 return hr;
5639 InitializeCriticalSection(&object->cs);
5640 object->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": filter_graph.cs");
5641 InitializeCriticalSection(&object->event_cs);
5642 object->event_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": filter_graph.event_cs");
5644 object->defaultclock = TRUE;
5646 object->media_event_handle = CreateEventW(NULL, TRUE, FALSE, NULL);
5647 list_init(&object->media_events);
5648 list_init(&object->filters);
5649 object->HandleEcClockChanged = TRUE;
5650 object->HandleEcComplete = TRUE;
5651 object->HandleEcRepaint = TRUE;
5652 object->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5654 object->name_index = 1;
5655 object->timeformatseek = TIME_FORMAT_MEDIA_TIME;
5657 if (threaded)
5659 object->message_thread_ret = CreateEventW(NULL, FALSE, FALSE, NULL);
5660 object->message_thread = CreateThread(NULL, 0, message_thread_run, object, 0, &object->message_thread_id);
5661 WaitForSingleObject(object->message_thread_ret, INFINITE);
5663 else
5664 object->message_thread = NULL;
5666 TRACE("Created %sthreaded filter graph %p.\n", threaded ? "" : "non-", object);
5667 *out = &object->IUnknown_inner;
5668 return S_OK;
5671 HRESULT filter_graph_create(IUnknown *outer, IUnknown **out)
5673 return filter_graph_common_create(outer, out, TRUE);
5676 HRESULT filter_graph_no_thread_create(IUnknown *outer, IUnknown **out)
5678 return filter_graph_common_create(outer, out, FALSE);