po: Update Lithuanian translation.
[wine.git] / dlls / quartz / filtergraph.c
bloba8c6cc3391c0e713c57e99eb4ec44fe55f11cb1b
1 /* DirectShow FilterGraph object (QUARTZ.DLL)
3 * Copyright 2002 Lionel Ulmer
4 * Copyright 2004 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <assert.h>
22 #include <stdarg.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "shlwapi.h"
31 #include "dshow.h"
32 #include "wine/debug.h"
33 #include "quartz_private.h"
34 #include "ole2.h"
35 #include "olectl.h"
36 #include "strmif.h"
37 #include "vfwmsgs.h"
38 #include "evcode.h"
39 #include "wine/heap.h"
40 #include "wine/list.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
45 struct media_event
47 struct list entry;
48 LONG code;
49 LONG_PTR param1, param2;
52 #define MAX_ITF_CACHE_ENTRIES 3
53 typedef struct _ITF_CACHE_ENTRY {
54 const IID* riid;
55 IBaseFilter* filter;
56 IUnknown* iface;
57 } ITF_CACHE_ENTRY;
59 struct filter
61 struct list entry;
62 IBaseFilter *filter;
63 IMediaSeeking *seeking;
64 WCHAR *name;
65 BOOL sorting;
68 struct filter_graph
70 IUnknown IUnknown_inner;
71 IFilterGraph2 IFilterGraph2_iface;
72 IMediaControl IMediaControl_iface;
73 IMediaSeeking IMediaSeeking_iface;
74 IBasicAudio IBasicAudio_iface;
75 IBasicVideo2 IBasicVideo2_iface;
76 IVideoWindow IVideoWindow_iface;
77 IMediaEventEx IMediaEventEx_iface;
78 IMediaFilter IMediaFilter_iface;
79 IMediaEventSink IMediaEventSink_iface;
80 IGraphConfig IGraphConfig_iface;
81 IMediaPosition IMediaPosition_iface;
82 IObjectWithSite IObjectWithSite_iface;
83 IGraphVersion IGraphVersion_iface;
84 /* IAMGraphStreams */
85 /* IAMStats */
86 /* IFilterChain */
87 /* IFilterMapper2 */
88 /* IQueueCommand */
89 /* IRegisterServiceProvider */
90 /* IResourceManager */
91 /* IServiceProvider */
92 IVideoFrameStep IVideoFrameStep_iface;
94 IUnknown *outer_unk;
95 LONG ref;
96 IUnknown *punkFilterMapper2;
98 struct list filters;
99 unsigned int name_index;
101 OAFilterState state;
102 TP_WORK *async_run_work;
104 IReferenceClock *refClock;
105 IBaseFilter *refClockProvider;
107 struct list media_events;
108 HANDLE media_event_handle;
109 HWND media_event_window;
110 UINT media_event_message;
111 LPARAM media_event_lparam;
112 HANDLE hEventCompletion;
113 int CompletionStatus;
114 int nRenderers;
115 int EcCompleteCount;
116 int HandleEcComplete;
117 int HandleEcRepaint;
118 int HandleEcClockChanged;
120 CRITICAL_SECTION cs;
121 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
122 int nItfCacheEntries;
123 BOOL defaultclock;
124 GUID timeformatseek;
125 IUnknown *pSite;
126 LONG version;
128 HANDLE message_thread, message_thread_ret;
129 DWORD message_thread_id;
131 /* Respectively: the last timestamp at which we started streaming, and the
132 * current offset within the stream. */
133 REFERENCE_TIME stream_start, stream_elapsed;
134 REFERENCE_TIME stream_stop;
135 LONGLONG current_pos;
137 unsigned int needs_async_run : 1;
138 unsigned int got_ec_complete : 1;
139 unsigned int media_events_disabled : 1;
142 struct enum_filters
144 IEnumFilters IEnumFilters_iface;
145 LONG ref;
146 struct filter_graph *graph;
147 LONG version;
148 struct list *cursor;
151 static HRESULT create_enum_filters(struct filter_graph *graph, struct list *cursor, IEnumFilters **out);
153 static inline struct enum_filters *impl_from_IEnumFilters(IEnumFilters *iface)
155 return CONTAINING_RECORD(iface, struct enum_filters, IEnumFilters_iface);
158 static HRESULT WINAPI EnumFilters_QueryInterface(IEnumFilters *iface, REFIID iid, void **out)
160 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
161 TRACE("enum_filters %p, iid %s, out %p.\n", enum_filters, qzdebugstr_guid(iid), out);
163 if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IEnumFilters))
165 IEnumFilters_AddRef(*out = iface);
166 return S_OK;
169 WARN("%s not implemented, returning E_NOINTERFACE.\n", qzdebugstr_guid(iid));
170 *out = NULL;
171 return E_NOINTERFACE;
174 static ULONG WINAPI EnumFilters_AddRef(IEnumFilters *iface)
176 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
177 ULONG ref = InterlockedIncrement(&enum_filters->ref);
179 TRACE("%p increasing refcount to %u.\n", enum_filters, ref);
181 return ref;
184 static ULONG WINAPI EnumFilters_Release(IEnumFilters *iface)
186 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
187 ULONG ref = InterlockedDecrement(&enum_filters->ref);
189 TRACE("%p decreasing refcount to %u.\n", enum_filters, ref);
191 if (!ref)
193 IUnknown_Release(enum_filters->graph->outer_unk);
194 heap_free(enum_filters);
197 return ref;
200 static HRESULT WINAPI EnumFilters_Next(IEnumFilters *iface, ULONG count,
201 IBaseFilter **filters, ULONG *fetched)
203 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
204 unsigned int i = 0;
206 TRACE("enum_filters %p, count %u, filters %p, fetched %p.\n",
207 enum_filters, count, filters, fetched);
209 if (enum_filters->version != enum_filters->graph->version)
210 return VFW_E_ENUM_OUT_OF_SYNC;
212 if (!filters)
213 return E_POINTER;
215 for (i = 0; i < count; ++i)
217 struct filter *filter = LIST_ENTRY(enum_filters->cursor, struct filter, entry);
219 if (!enum_filters->cursor)
220 break;
222 IBaseFilter_AddRef(filters[i] = filter->filter);
223 enum_filters->cursor = list_next(&enum_filters->graph->filters, enum_filters->cursor);
226 if (fetched)
227 *fetched = i;
229 return (i == count) ? S_OK : S_FALSE;
232 static HRESULT WINAPI EnumFilters_Skip(IEnumFilters *iface, ULONG count)
234 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
236 TRACE("enum_filters %p, count %u.\n", enum_filters, count);
238 if (enum_filters->version != enum_filters->graph->version)
239 return VFW_E_ENUM_OUT_OF_SYNC;
241 if (!enum_filters->cursor)
242 return E_INVALIDARG;
244 while (count--)
246 if (!(enum_filters->cursor = list_next(&enum_filters->graph->filters, enum_filters->cursor)))
247 return count ? S_FALSE : S_OK;
250 return S_OK;
253 static HRESULT WINAPI EnumFilters_Reset(IEnumFilters *iface)
255 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
257 TRACE("enum_filters %p.\n", enum_filters);
259 enum_filters->cursor = list_head(&enum_filters->graph->filters);
260 enum_filters->version = enum_filters->graph->version;
261 return S_OK;
264 static HRESULT WINAPI EnumFilters_Clone(IEnumFilters *iface, IEnumFilters **out)
266 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
268 TRACE("enum_filters %p, out %p.\n", enum_filters, out);
270 return create_enum_filters(enum_filters->graph, enum_filters->cursor, out);
273 static const IEnumFiltersVtbl EnumFilters_vtbl =
275 EnumFilters_QueryInterface,
276 EnumFilters_AddRef,
277 EnumFilters_Release,
278 EnumFilters_Next,
279 EnumFilters_Skip,
280 EnumFilters_Reset,
281 EnumFilters_Clone,
284 static HRESULT create_enum_filters(struct filter_graph *graph, struct list *cursor, IEnumFilters **out)
286 struct enum_filters *enum_filters;
288 if (!(enum_filters = heap_alloc(sizeof(*enum_filters))))
289 return E_OUTOFMEMORY;
291 enum_filters->IEnumFilters_iface.lpVtbl = &EnumFilters_vtbl;
292 enum_filters->ref = 1;
293 enum_filters->cursor = cursor;
294 enum_filters->graph = graph;
295 IUnknown_AddRef(graph->outer_unk);
296 enum_filters->version = graph->version;
298 *out = &enum_filters->IEnumFilters_iface;
299 return S_OK;
302 static BOOL queue_media_event(struct filter_graph *graph, LONG code,
303 LONG_PTR param1, LONG_PTR param2)
305 struct media_event *event;
307 if (!(event = malloc(sizeof(*event))))
308 return FALSE;
310 event->code = code;
311 event->param1 = param1;
312 event->param2 = param2;
313 list_add_tail(&graph->media_events, &event->entry);
315 SetEvent(graph->media_event_handle);
316 if (graph->media_event_window)
317 PostMessageW(graph->media_event_window, graph->media_event_message, 0, graph->media_event_lparam);
319 return TRUE;
322 static void flush_media_events(struct filter_graph *graph)
324 struct list *cursor;
326 while ((cursor = list_head(&graph->media_events)))
328 struct media_event *event = LIST_ENTRY(cursor, struct media_event, entry);
330 list_remove(&event->entry);
331 free(event);
335 static struct filter_graph *impl_from_IUnknown(IUnknown *iface)
337 return CONTAINING_RECORD(iface, struct filter_graph, IUnknown_inner);
340 static HRESULT WINAPI FilterGraphInner_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObj)
342 struct filter_graph *This = impl_from_IUnknown(iface);
343 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObj);
345 if (IsEqualGUID(&IID_IUnknown, riid)) {
346 *ppvObj = &This->IUnknown_inner;
347 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
348 } else if (IsEqualGUID(&IID_IFilterGraph, riid) ||
349 IsEqualGUID(&IID_IFilterGraph2, riid) ||
350 IsEqualGUID(&IID_IGraphBuilder, riid)) {
351 *ppvObj = &This->IFilterGraph2_iface;
352 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj);
353 } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
354 *ppvObj = &This->IMediaControl_iface;
355 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj);
356 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
357 *ppvObj = &This->IMediaSeeking_iface;
358 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
359 } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
360 *ppvObj = &This->IBasicAudio_iface;
361 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj);
362 } else if (IsEqualGUID(&IID_IBasicVideo, riid) ||
363 IsEqualGUID(&IID_IBasicVideo2, riid)) {
364 *ppvObj = &This->IBasicVideo2_iface;
365 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj);
366 } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
367 *ppvObj = &This->IVideoWindow_iface;
368 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj);
369 } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
370 IsEqualGUID(&IID_IMediaEventEx, riid)) {
371 *ppvObj = &This->IMediaEventEx_iface;
372 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
373 } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
374 IsEqualGUID(&IID_IPersist, riid)) {
375 *ppvObj = &This->IMediaFilter_iface;
376 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj);
377 } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
378 *ppvObj = &This->IMediaEventSink_iface;
379 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj);
380 } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
381 *ppvObj = &This->IGraphConfig_iface;
382 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
383 } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
384 *ppvObj = &This->IMediaPosition_iface;
385 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj);
386 } else if (IsEqualGUID(&IID_IObjectWithSite, riid)) {
387 *ppvObj = &This->IObjectWithSite_iface;
388 TRACE(" returning IObjectWithSite interface (%p)\n", *ppvObj);
389 } else if (IsEqualGUID(&IID_IFilterMapper, riid)) {
390 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj);
391 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
392 } else if (IsEqualGUID(&IID_IFilterMapper2, riid)) {
393 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
394 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
395 } else if (IsEqualGUID(&IID_IFilterMapper3, riid)) {
396 TRACE(" returning IFilterMapper3 interface from aggregated filtermapper (%p)\n", *ppvObj);
397 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
398 } else if (IsEqualGUID(&IID_IGraphVersion, riid)) {
399 *ppvObj = &This->IGraphVersion_iface;
400 TRACE(" returning IGraphVersion interface (%p)\n", *ppvObj);
401 } else if (IsEqualGUID(&IID_IVideoFrameStep, riid)) {
402 *ppvObj = &This->IVideoFrameStep_iface;
403 TRACE(" returning IVideoFrameStep interface (%p)\n", *ppvObj);
404 } else {
405 *ppvObj = NULL;
406 FIXME("unknown interface %s\n", debugstr_guid(riid));
407 return E_NOINTERFACE;
410 IUnknown_AddRef((IUnknown *)*ppvObj);
411 return S_OK;
414 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown *iface)
416 struct filter_graph *This = impl_from_IUnknown(iface);
417 ULONG ref = InterlockedIncrement(&This->ref);
419 TRACE("(%p)->(): new ref = %d\n", This, ref);
421 return ref;
424 static ULONG WINAPI FilterGraphInner_Release(IUnknown *iface)
426 struct filter_graph *This = impl_from_IUnknown(iface);
427 ULONG ref = InterlockedDecrement(&This->ref);
428 struct list *cursor;
430 TRACE("(%p)->(): new ref = %d\n", This, ref);
432 if (ref == 0) {
433 int i;
435 This->ref = 1; /* guard against reentrancy (aggregation). */
437 IMediaControl_Stop(&This->IMediaControl_iface);
439 while ((cursor = list_head(&This->filters)))
441 struct filter *filter = LIST_ENTRY(cursor, struct filter, entry);
443 IFilterGraph2_RemoveFilter(&This->IFilterGraph2_iface, filter->filter);
446 if (This->refClock)
447 IReferenceClock_Release(This->refClock);
449 for (i = 0; i < This->nItfCacheEntries; i++)
451 if (This->ItfCacheEntries[i].iface)
452 IUnknown_Release(This->ItfCacheEntries[i].iface);
455 IUnknown_Release(This->punkFilterMapper2);
457 if (This->pSite) IUnknown_Release(This->pSite);
459 flush_media_events(This);
460 CloseHandle(This->media_event_handle);
462 This->cs.DebugInfo->Spare[0] = 0;
463 if (This->message_thread)
465 PostThreadMessageW(This->message_thread_id, WM_USER + 1, 0, 0);
466 WaitForSingleObject(This->message_thread, INFINITE);
467 CloseHandle(This->message_thread);
468 CloseHandle(This->message_thread_ret);
470 DeleteCriticalSection(&This->cs);
471 free(This);
473 InterlockedDecrement(&object_locks);
475 return ref;
478 static struct filter_graph *impl_from_IFilterGraph2(IFilterGraph2 *iface)
480 return CONTAINING_RECORD(iface, struct filter_graph, IFilterGraph2_iface);
483 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface, REFIID iid, void **out)
485 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
486 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
489 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface)
491 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
492 return IUnknown_AddRef(graph->outer_unk);
495 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface)
497 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
498 return IUnknown_Release(graph->outer_unk);
501 static IBaseFilter *find_filter_by_name(struct filter_graph *graph, const WCHAR *name)
503 struct filter *filter;
505 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
507 if (!wcscmp(filter->name, name))
508 return filter->filter;
511 return NULL;
514 static BOOL has_output_pins(IBaseFilter *filter)
516 IEnumPins *enumpins;
517 PIN_DIRECTION dir;
518 IPin *pin;
520 if (FAILED(IBaseFilter_EnumPins(filter, &enumpins)))
521 return FALSE;
523 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
525 IPin_QueryDirection(pin, &dir);
526 IPin_Release(pin);
527 if (dir == PINDIR_OUTPUT)
529 IEnumPins_Release(enumpins);
530 return TRUE;
534 IEnumPins_Release(enumpins);
535 return FALSE;
538 static void update_seeking(struct filter *filter)
540 IMediaSeeking *seeking;
542 if (!filter->seeking)
544 /* The Legend of Heroes: Trails of Cold Steel II destroys its filter when
545 * its IMediaSeeking interface is released, so cache the interface instead
546 * of querying for it every time.
547 * Some filters (e.g. MediaStreamFilter) can become seekable when they are
548 * already in the graph, so always try to query IMediaSeeking if it's not
549 * cached yet. */
550 if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IMediaSeeking, (void **)&seeking)))
552 if (IMediaSeeking_IsFormatSupported(seeking, &TIME_FORMAT_MEDIA_TIME) == S_OK)
553 filter->seeking = seeking;
554 else
555 IMediaSeeking_Release(seeking);
560 static BOOL is_renderer(struct filter *filter)
562 IAMFilterMiscFlags *flags;
563 BOOL ret = FALSE;
565 if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IAMFilterMiscFlags, (void **)&flags)))
567 if (IAMFilterMiscFlags_GetMiscFlags(flags) & AM_FILTER_MISC_FLAGS_IS_RENDERER)
568 ret = TRUE;
569 IAMFilterMiscFlags_Release(flags);
571 else
573 update_seeking(filter);
574 if (filter->seeking && !has_output_pins(filter->filter))
575 ret = TRUE;
577 return ret;
580 /*** IFilterGraph methods ***/
581 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface,
582 IBaseFilter *filter, const WCHAR *name)
584 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
585 BOOL duplicate_name = FALSE;
586 struct filter *entry;
587 unsigned int i;
588 HRESULT hr;
590 TRACE("graph %p, filter %p, name %s.\n", graph, filter, debugstr_w(name));
592 if (!filter)
593 return E_POINTER;
595 if (!(entry = heap_alloc(sizeof(*entry))))
596 return E_OUTOFMEMORY;
598 if (!(entry->name = CoTaskMemAlloc((name ? wcslen(name) + 6 : 5) * sizeof(WCHAR))))
600 heap_free(entry);
601 return E_OUTOFMEMORY;
604 if (name && find_filter_by_name(graph, name))
605 duplicate_name = TRUE;
607 if (!name || duplicate_name)
609 for (i = 0; i < 10000 ; ++i)
611 if (name)
612 swprintf(entry->name, name ? wcslen(name) + 6 : 5, L"%s %04u", name, graph->name_index);
613 else
614 swprintf(entry->name, name ? wcslen(name) + 6 : 5, L"%04u", graph->name_index);
616 graph->name_index = (graph->name_index + 1) % 10000;
618 if (!find_filter_by_name(graph, entry->name))
619 break;
622 if (i == 10000)
624 CoTaskMemFree(entry->name);
625 heap_free(entry);
626 return VFW_E_DUPLICATE_NAME;
629 else
630 wcscpy(entry->name, name);
632 if (FAILED(hr = IBaseFilter_JoinFilterGraph(filter,
633 (IFilterGraph *)&graph->IFilterGraph2_iface, entry->name)))
635 CoTaskMemFree(entry->name);
636 heap_free(entry);
637 return hr;
640 IBaseFilter_AddRef(entry->filter = filter);
642 list_add_head(&graph->filters, &entry->entry);
643 entry->sorting = FALSE;
644 entry->seeking = NULL;
645 ++graph->version;
647 return duplicate_name ? VFW_S_DUPLICATE_NAME : hr;
650 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
652 struct filter_graph *This = impl_from_IFilterGraph2(iface);
653 struct filter *entry;
654 int i;
655 HRESULT hr = E_FAIL;
657 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
659 LIST_FOR_EACH_ENTRY(entry, &This->filters, struct filter, entry)
661 if (entry->filter == pFilter)
663 IEnumPins *penumpins = NULL;
665 if (This->defaultclock && This->refClockProvider == pFilter)
667 IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, NULL);
668 This->defaultclock = TRUE;
671 TRACE("Removing filter %s.\n", debugstr_w(entry->name));
673 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
674 if (SUCCEEDED(hr)) {
675 IPin *ppin;
676 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
678 IPin *peer = NULL;
679 HRESULT hr;
681 IPin_ConnectedTo(ppin, &peer);
682 if (peer)
684 if (FAILED(hr = IPin_Disconnect(peer)))
686 WARN("Failed to disconnect peer %p, hr %#x.\n", peer, hr);
687 IPin_Release(peer);
688 IPin_Release(ppin);
689 IEnumPins_Release(penumpins);
690 return hr;
692 IPin_Release(peer);
694 if (FAILED(hr = IPin_Disconnect(ppin)))
696 WARN("Failed to disconnect pin %p, hr %#x.\n", ppin, hr);
697 IPin_Release(ppin);
698 IEnumPins_Release(penumpins);
699 return hr;
702 IPin_Release(ppin);
704 IEnumPins_Release(penumpins);
707 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, NULL);
708 if (SUCCEEDED(hr))
710 IBaseFilter_SetSyncSource(pFilter, NULL);
711 IBaseFilter_Release(pFilter);
712 if (entry->seeking)
713 IMediaSeeking_Release(entry->seeking);
714 list_remove(&entry->entry);
715 CoTaskMemFree(entry->name);
716 heap_free(entry);
717 This->version++;
718 /* Invalidate interfaces in the cache */
719 for (i = 0; i < This->nItfCacheEntries; i++)
720 if (pFilter == This->ItfCacheEntries[i].filter)
722 IUnknown_Release(This->ItfCacheEntries[i].iface);
723 This->ItfCacheEntries[i].iface = NULL;
724 This->ItfCacheEntries[i].filter = NULL;
726 return S_OK;
728 break;
732 return hr; /* FIXME: check this error code */
735 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface, IEnumFilters **out)
737 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
739 TRACE("graph %p, out %p.\n", graph, out);
741 return create_enum_filters(graph, list_head(&graph->filters), out);
744 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface,
745 const WCHAR *name, IBaseFilter **filter)
747 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
749 TRACE("graph %p, name %s, filter %p.\n", graph, debugstr_w(name), filter);
751 if (!filter)
752 return E_POINTER;
754 if ((*filter = find_filter_by_name(graph, name)))
756 IBaseFilter_AddRef(*filter);
757 return S_OK;
760 return VFW_E_NOT_FOUND;
763 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
764 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
766 static HRESULT CheckCircularConnection(struct filter_graph *This, IPin *out, IPin *in)
768 #if 1
769 HRESULT hr;
770 PIN_INFO info_out, info_in;
772 hr = IPin_QueryPinInfo(out, &info_out);
773 if (FAILED(hr))
774 return hr;
775 if (info_out.dir != PINDIR_OUTPUT)
777 IBaseFilter_Release(info_out.pFilter);
778 return VFW_E_CANNOT_CONNECT;
781 hr = IPin_QueryPinInfo(in, &info_in);
782 if (SUCCEEDED(hr))
783 IBaseFilter_Release(info_in.pFilter);
784 if (FAILED(hr))
785 goto out;
786 if (info_in.dir != PINDIR_INPUT)
788 hr = VFW_E_CANNOT_CONNECT;
789 goto out;
792 if (info_out.pFilter == info_in.pFilter)
793 hr = VFW_E_CIRCULAR_GRAPH;
794 else
796 IEnumPins *enumpins;
797 IPin *test;
799 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
800 if (FAILED(hr))
801 goto out;
803 IEnumPins_Reset(enumpins);
804 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
806 PIN_DIRECTION dir = PINDIR_OUTPUT;
807 IPin_QueryDirection(test, &dir);
808 if (dir == PINDIR_INPUT)
810 IPin *victim = NULL;
811 IPin_ConnectedTo(test, &victim);
812 if (victim)
814 hr = CheckCircularConnection(This, victim, in);
815 IPin_Release(victim);
816 if (FAILED(hr))
818 IPin_Release(test);
819 break;
823 IPin_Release(test);
825 IEnumPins_Release(enumpins);
828 out:
829 IBaseFilter_Release(info_out.pFilter);
830 if (FAILED(hr))
831 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
832 return hr;
833 #else
834 /* Debugging filtergraphs not enabled */
835 return S_OK;
836 #endif
839 static struct filter *find_sorted_filter(struct filter_graph *graph, IBaseFilter *iface)
841 struct filter *filter;
843 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
845 if (filter->filter == iface)
846 return filter;
849 return NULL;
852 static void sort_filter_recurse(struct filter_graph *graph, struct filter *filter, struct list *sorted)
854 struct filter *peer_filter;
855 IEnumPins *enumpins;
856 PIN_DIRECTION dir;
857 IPin *pin, *peer;
858 PIN_INFO info;
860 TRACE("Sorting filter %p.\n", filter->filter);
862 /* Cyclic connections should be caught by CheckCircularConnection(). */
863 assert(!filter->sorting);
865 filter->sorting = TRUE;
867 IBaseFilter_EnumPins(filter->filter, &enumpins);
868 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
870 IPin_QueryDirection(pin, &dir);
872 if (dir == PINDIR_INPUT && IPin_ConnectedTo(pin, &peer) == S_OK)
874 IPin_QueryPinInfo(peer, &info);
875 /* Note that the filter may have already been sorted. */
876 if ((peer_filter = find_sorted_filter(graph, info.pFilter)))
877 sort_filter_recurse(graph, peer_filter, sorted);
878 IBaseFilter_Release(info.pFilter);
879 IPin_Release(peer);
881 IPin_Release(pin);
883 IEnumPins_Release(enumpins);
885 filter->sorting = FALSE;
887 list_remove(&filter->entry);
888 list_add_head(sorted, &filter->entry);
891 static void sort_filters(struct filter_graph *graph)
893 struct list sorted = LIST_INIT(sorted), *cursor;
895 while ((cursor = list_head(&graph->filters)))
897 struct filter *filter = LIST_ENTRY(cursor, struct filter, entry);
898 sort_filter_recurse(graph, filter, &sorted);
901 list_move_tail(&graph->filters, &sorted);
904 /* NOTE: despite the implication, it doesn't matter which
905 * way round you put in the input and output pins */
906 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppinIn, IPin *ppinOut,
907 const AM_MEDIA_TYPE *pmt)
909 struct filter_graph *This = impl_from_IFilterGraph2(iface);
910 PIN_DIRECTION dir;
911 HRESULT hr;
913 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
914 strmbase_dump_media_type(pmt);
916 /* FIXME: check pins are in graph */
918 if (TRACE_ON(quartz))
920 PIN_INFO PinInfo;
922 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
923 if (FAILED(hr))
924 return hr;
926 TRACE("Filter owning ppinIn(%p) => %p\n", ppinIn, PinInfo.pFilter);
927 IBaseFilter_Release(PinInfo.pFilter);
929 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
930 if (FAILED(hr))
931 return hr;
933 TRACE("Filter owning ppinOut(%p) => %p\n", ppinOut, PinInfo.pFilter);
934 IBaseFilter_Release(PinInfo.pFilter);
937 hr = IPin_QueryDirection(ppinIn, &dir);
938 if (SUCCEEDED(hr))
940 if (dir == PINDIR_INPUT)
942 hr = CheckCircularConnection(This, ppinOut, ppinIn);
943 if (SUCCEEDED(hr))
944 hr = IPin_Connect(ppinOut, ppinIn, pmt);
946 else
948 hr = CheckCircularConnection(This, ppinIn, ppinOut);
949 if (SUCCEEDED(hr))
950 hr = IPin_Connect(ppinIn, ppinOut, pmt);
954 return hr;
957 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface, IPin *pin)
959 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
961 TRACE("graph %p, pin %p.\n", graph, pin);
963 return IFilterGraph2_ReconnectEx(iface, pin, NULL);
966 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
968 struct filter_graph *This = impl_from_IFilterGraph2(iface);
970 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
972 if (!ppin)
973 return E_POINTER;
975 return IPin_Disconnect(ppin);
978 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
980 struct filter_graph *This = impl_from_IFilterGraph2(iface);
981 IReferenceClock *pClock = NULL;
982 struct filter *filter;
983 HRESULT hr = S_OK;
985 TRACE("(%p/%p)->() live sources not handled properly!\n", This, iface);
987 EnterCriticalSection(&This->cs);
989 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
991 if (IBaseFilter_QueryInterface(filter->filter, &IID_IReferenceClock, (void **)&pClock) == S_OK)
992 break;
995 if (!pClock)
997 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
998 This->refClockProvider = NULL;
1000 else
1002 filter = LIST_ENTRY(list_tail(&This->filters), struct filter, entry);
1003 This->refClockProvider = filter->filter;
1006 if (SUCCEEDED(hr))
1008 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
1009 This->defaultclock = TRUE;
1010 IReferenceClock_Release(pClock);
1012 LeaveCriticalSection(&This->cs);
1014 return hr;
1017 struct filter_create_params
1019 HRESULT hr;
1020 IMoniker *moniker;
1021 IBaseFilter *filter;
1024 static DWORD WINAPI message_thread_run(void *ctx)
1026 struct filter_graph *graph = ctx;
1027 MSG msg;
1029 /* Make sure we have a message queue. */
1030 PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE);
1031 SetEvent(graph->message_thread_ret);
1033 CoInitializeEx(NULL, COINIT_MULTITHREADED);
1035 for (;;)
1037 GetMessageW(&msg, NULL, 0, 0);
1039 if (!msg.hwnd && msg.message == WM_USER)
1041 struct filter_create_params *params = (struct filter_create_params *)msg.wParam;
1043 params->hr = IMoniker_BindToObject(params->moniker, NULL, NULL,
1044 &IID_IBaseFilter, (void **)&params->filter);
1045 SetEvent(graph->message_thread_ret);
1047 else if (!msg.hwnd && msg.message == WM_USER + 1)
1049 break;
1051 else
1053 TranslateMessage(&msg);
1054 DispatchMessageW(&msg);
1058 CoUninitialize();
1059 return 0;
1062 static HRESULT create_filter(struct filter_graph *graph, IMoniker *moniker, IBaseFilter **filter)
1064 if (graph->message_thread)
1066 struct filter_create_params params;
1068 params.moniker = moniker;
1069 PostThreadMessageW(graph->message_thread_id, WM_USER, (WPARAM)&params, 0);
1070 WaitForSingleObject(graph->message_thread_ret, INFINITE);
1071 *filter = params.filter;
1072 return params.hr;
1074 else
1075 return IMoniker_BindToObject(moniker, NULL, NULL, &IID_IBaseFilter, (void **)filter);
1078 static HRESULT autoplug(struct filter_graph *graph, IPin *source, IPin *sink,
1079 BOOL render_to_existing, unsigned int recursion_depth);
1081 static HRESULT autoplug_through_sink(struct filter_graph *graph, IPin *source,
1082 IBaseFilter *filter, IPin *middle_sink, IPin *sink,
1083 BOOL render_to_existing, unsigned int recursion_depth)
1085 BOOL any = FALSE, all = TRUE;
1086 IPin *middle_source, *peer;
1087 IEnumPins *source_enum;
1088 PIN_DIRECTION dir;
1089 PIN_INFO info;
1090 HRESULT hr;
1092 TRACE("Trying to autoplug %p to %p through %p.\n", source, sink, middle_sink);
1094 IPin_QueryDirection(middle_sink, &dir);
1095 if (dir != PINDIR_INPUT)
1096 return E_FAIL;
1098 if (IPin_ConnectedTo(middle_sink, &peer) == S_OK)
1100 IPin_Release(peer);
1101 return E_FAIL;
1104 if (FAILED(hr = IFilterGraph2_ConnectDirect(&graph->IFilterGraph2_iface, source, middle_sink, NULL)))
1105 return E_FAIL;
1107 if (FAILED(hr = IBaseFilter_EnumPins(filter, &source_enum)))
1108 goto err;
1110 while (IEnumPins_Next(source_enum, 1, &middle_source, NULL) == S_OK)
1112 IPin_QueryPinInfo(middle_source, &info);
1113 IBaseFilter_Release(info.pFilter);
1114 if (info.dir != PINDIR_OUTPUT)
1116 IPin_Release(middle_source);
1117 continue;
1119 if (info.achName[0] == '~')
1121 TRACE("Skipping non-rendered pin %s.\n", debugstr_w(info.achName));
1122 IPin_Release(middle_source);
1123 continue;
1125 if (IPin_ConnectedTo(middle_source, &peer) == S_OK)
1127 IPin_Release(peer);
1128 IPin_Release(middle_source);
1129 continue;
1132 hr = autoplug(graph, middle_source, sink, render_to_existing, recursion_depth + 1);
1133 IPin_Release(middle_source);
1134 if (SUCCEEDED(hr) && sink)
1136 IEnumPins_Release(source_enum);
1137 return hr;
1139 if (SUCCEEDED(hr))
1140 any = TRUE;
1141 if (hr != S_OK)
1142 all = FALSE;
1144 IEnumPins_Release(source_enum);
1146 if (!sink)
1148 if (all)
1149 return S_OK;
1150 if (any)
1151 return VFW_S_PARTIAL_RENDER;
1154 err:
1155 IFilterGraph2_Disconnect(&graph->IFilterGraph2_iface, source);
1156 IFilterGraph2_Disconnect(&graph->IFilterGraph2_iface, middle_sink);
1157 return E_FAIL;
1160 static HRESULT autoplug_through_filter(struct filter_graph *graph, IPin *source,
1161 IBaseFilter *filter, IPin *sink, BOOL render_to_existing,
1162 unsigned int recursion_depth)
1164 IEnumPins *sink_enum;
1165 IPin *filter_sink;
1166 HRESULT hr;
1168 TRACE("Trying to autoplug %p to %p through %p.\n", source, sink, filter);
1170 if (FAILED(hr = IBaseFilter_EnumPins(filter, &sink_enum)))
1171 return hr;
1173 while (IEnumPins_Next(sink_enum, 1, &filter_sink, NULL) == S_OK)
1175 hr = autoplug_through_sink(graph, source, filter, filter_sink, sink,
1176 render_to_existing, recursion_depth);
1177 IPin_Release(filter_sink);
1178 if (SUCCEEDED(hr))
1180 IEnumPins_Release(sink_enum);
1181 return hr;
1184 IEnumPins_Release(sink_enum);
1185 return VFW_E_CANNOT_CONNECT;
1188 /* Common helper for IGraphBuilder::Connect() and IGraphBuilder::Render(), which
1189 * share most of the same code. Render() calls this with a NULL sink. */
1190 static HRESULT autoplug(struct filter_graph *graph, IPin *source, IPin *sink,
1191 BOOL render_to_existing, unsigned int recursion_depth)
1193 IAMGraphBuilderCallback *callback = NULL;
1194 IEnumMediaTypes *enummt;
1195 IFilterMapper2 *mapper;
1196 struct filter *filter;
1197 AM_MEDIA_TYPE *mt;
1198 HRESULT hr;
1200 TRACE("Trying to autoplug %p to %p, recursion depth %u.\n", source, sink, recursion_depth);
1202 if (recursion_depth >= 5)
1204 WARN("Recursion depth has reached 5; aborting.\n");
1205 return VFW_E_CANNOT_CONNECT;
1208 if (sink)
1210 /* Try to connect directly to this sink. */
1211 hr = IFilterGraph2_ConnectDirect(&graph->IFilterGraph2_iface, source, sink, NULL);
1213 /* If direct connection succeeded, we should propagate that return value.
1214 * If it returned VFW_E_NOT_CONNECTED or VFW_E_NO_AUDIO_HARDWARE, then don't
1215 * even bother trying intermediate filters, since they won't succeed. */
1216 if (SUCCEEDED(hr) || hr == VFW_E_NOT_CONNECTED || hr == VFW_E_NO_AUDIO_HARDWARE)
1217 return hr;
1220 /* Always prefer filters in the graph. */
1221 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1223 if (SUCCEEDED(hr = autoplug_through_filter(graph, source, filter->filter,
1224 sink, render_to_existing, recursion_depth)))
1225 return hr;
1228 IUnknown_QueryInterface(graph->punkFilterMapper2, &IID_IFilterMapper2, (void **)&mapper);
1230 if (FAILED(hr = IPin_EnumMediaTypes(source, &enummt)))
1232 IFilterMapper2_Release(mapper);
1233 return hr;
1236 if (graph->pSite)
1237 IUnknown_QueryInterface(graph->pSite, &IID_IAMGraphBuilderCallback, (void **)&callback);
1239 while (IEnumMediaTypes_Next(enummt, 1, &mt, NULL) == S_OK)
1241 GUID types[2] = {mt->majortype, mt->subtype};
1242 IEnumMoniker *enummoniker;
1243 IBaseFilter *filter;
1244 IMoniker *moniker;
1246 DeleteMediaType(mt);
1248 if (FAILED(hr = IFilterMapper2_EnumMatchingFilters(mapper, &enummoniker,
1249 0, FALSE, MERIT_UNLIKELY, TRUE, 1, types, NULL, NULL, FALSE,
1250 render_to_existing, 0, NULL, NULL, NULL)))
1251 goto out;
1253 while (IEnumMoniker_Next(enummoniker, 1, &moniker, NULL) == S_OK)
1255 IPropertyBag *bag;
1256 VARIANT var;
1258 VariantInit(&var);
1259 IMoniker_BindToStorage(moniker, NULL, NULL, &IID_IPropertyBag, (void **)&bag);
1260 hr = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL);
1261 IPropertyBag_Release(bag);
1262 if (FAILED(hr))
1264 IMoniker_Release(moniker);
1265 continue;
1268 if (callback && FAILED(hr = IAMGraphBuilderCallback_SelectedFilter(callback, moniker)))
1270 TRACE("Filter rejected by IAMGraphBuilderCallback::SelectedFilter(), hr %#x.\n", hr);
1271 IMoniker_Release(moniker);
1272 continue;
1275 hr = create_filter(graph, moniker, &filter);
1276 IMoniker_Release(moniker);
1277 if (FAILED(hr))
1279 ERR("Failed to create filter for %s, hr %#x.\n", debugstr_w(V_BSTR(&var)), hr);
1280 VariantClear(&var);
1281 continue;
1284 if (callback && FAILED(hr = IAMGraphBuilderCallback_CreatedFilter(callback, filter)))
1286 TRACE("Filter rejected by IAMGraphBuilderCallback::CreatedFilter(), hr %#x.\n", hr);
1287 IBaseFilter_Release(filter);
1288 continue;
1291 hr = IFilterGraph2_AddFilter(&graph->IFilterGraph2_iface, filter, V_BSTR(&var));
1292 VariantClear(&var);
1293 if (FAILED(hr))
1295 ERR("Failed to add filter, hr %#x.\n", hr);
1296 IBaseFilter_Release(filter);
1297 continue;
1300 hr = autoplug_through_filter(graph, source, filter, sink, render_to_existing, recursion_depth);
1301 if (SUCCEEDED(hr))
1303 IBaseFilter_Release(filter);
1304 goto out;
1307 IFilterGraph2_RemoveFilter(&graph->IFilterGraph2_iface, filter);
1308 IBaseFilter_Release(filter);
1310 IEnumMoniker_Release(enummoniker);
1313 hr = VFW_E_CANNOT_CONNECT;
1315 out:
1316 if (callback) IAMGraphBuilderCallback_Release(callback);
1317 IEnumMediaTypes_Release(enummt);
1318 IFilterMapper2_Release(mapper);
1319 return hr;
1322 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *source, IPin *sink)
1324 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1325 PIN_DIRECTION dir;
1326 HRESULT hr;
1328 TRACE("graph %p, source %p, sink %p.\n", graph, source, sink);
1330 if (!source || !sink)
1331 return E_POINTER;
1333 if (FAILED(hr = IPin_QueryDirection(source, &dir)))
1334 return hr;
1336 if (dir == PINDIR_INPUT)
1338 IPin *temp;
1340 TRACE("Directions seem backwards, swapping pins\n");
1342 temp = sink;
1343 sink = source;
1344 source = temp;
1347 EnterCriticalSection(&graph->cs);
1349 hr = autoplug(graph, source, sink, TRUE, 0);
1351 LeaveCriticalSection(&graph->cs);
1353 TRACE("Returning %#x.\n", hr);
1354 return hr;
1357 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *source)
1359 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1360 HRESULT hr;
1362 TRACE("graph %p, source %p.\n", graph, source);
1364 EnterCriticalSection(&graph->cs);
1365 hr = autoplug(graph, source, NULL, FALSE, 0);
1366 LeaveCriticalSection(&graph->cs);
1367 if (hr == VFW_E_CANNOT_CONNECT)
1368 hr = VFW_E_CANNOT_RENDER;
1370 TRACE("Returning %#x.\n", hr);
1371 return hr;
1374 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface, LPCWSTR lpcwstrFile,
1375 LPCWSTR lpcwstrPlayList)
1377 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1378 IBaseFilter* preader = NULL;
1379 IPin* ppinreader = NULL;
1380 IEnumPins* penumpins = NULL;
1381 struct filter *filter;
1382 HRESULT hr;
1383 BOOL partial = FALSE;
1384 BOOL any = FALSE;
1386 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1388 if (lpcwstrPlayList != NULL)
1389 return E_INVALIDARG;
1391 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, L"Reader", &preader);
1392 if (FAILED(hr))
1393 return hr;
1395 hr = IBaseFilter_EnumPins(preader, &penumpins);
1396 if (SUCCEEDED(hr))
1398 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1400 PIN_DIRECTION dir;
1402 IPin_QueryDirection(ppinreader, &dir);
1403 if (dir == PINDIR_OUTPUT)
1405 hr = IFilterGraph2_Render(iface, ppinreader);
1407 TRACE("Filters in chain:\n");
1408 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
1409 TRACE("- %s.\n", debugstr_w(filter->name));
1411 if (SUCCEEDED(hr))
1412 any = TRUE;
1413 if (hr != S_OK)
1414 partial = TRUE;
1416 IPin_Release(ppinreader);
1418 IEnumPins_Release(penumpins);
1420 if (!any)
1421 hr = VFW_E_CANNOT_RENDER;
1422 else if (partial)
1423 hr = VFW_S_PARTIAL_RENDER;
1424 else
1425 hr = S_OK;
1427 IBaseFilter_Release(preader);
1429 TRACE("--> %08x\n", hr);
1430 return hr;
1433 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface,
1434 const WCHAR *filename, const WCHAR *filter_name, IBaseFilter **ret_filter)
1436 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1437 IFileSourceFilter *filesource;
1438 IBaseFilter *filter;
1439 HRESULT hr;
1440 GUID clsid;
1442 TRACE("graph %p, filename %s, filter_name %s, ret_filter %p.\n",
1443 graph, debugstr_w(filename), debugstr_w(filter_name), ret_filter);
1445 if (!get_media_type(filename, NULL, NULL, &clsid))
1446 clsid = CLSID_AsyncReader;
1447 TRACE("Using source filter %s.\n", debugstr_guid(&clsid));
1449 if (FAILED(hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER,
1450 &IID_IBaseFilter, (void **)&filter)))
1452 WARN("Failed to create filter, hr %#x.\n", hr);
1453 return hr;
1456 if (FAILED(hr = IBaseFilter_QueryInterface(filter, &IID_IFileSourceFilter, (void **)&filesource)))
1458 WARN("Failed to get IFileSourceFilter, hr %#x.\n", hr);
1459 IBaseFilter_Release(filter);
1460 return hr;
1463 hr = IFileSourceFilter_Load(filesource, filename, NULL);
1464 IFileSourceFilter_Release(filesource);
1465 if (FAILED(hr))
1467 WARN("Failed to load file, hr %#x.\n", hr);
1468 return hr;
1471 if (FAILED(hr = IFilterGraph2_AddFilter(iface, filter, filter_name)))
1473 IBaseFilter_Release(filter);
1474 return hr;
1477 if (ret_filter)
1478 *ret_filter = filter;
1479 return S_OK;
1482 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR hFile)
1484 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1486 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1488 return S_OK;
1491 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1493 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1495 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1497 return S_OK;
1500 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1502 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1504 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1506 return S_OK;
1509 /*** IFilterGraph2 methods ***/
1510 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1511 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1513 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1514 HRESULT hr;
1515 IBaseFilter* pfilter;
1517 TRACE("(%p/%p)->(%p %p %s %p)\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1519 hr = IMoniker_BindToObject(pMoniker, pCtx, NULL, &IID_IBaseFilter, (void**)&pfilter);
1520 if(FAILED(hr)) {
1521 WARN("Unable to bind moniker to filter object (%x)\n", hr);
1522 return hr;
1525 hr = IFilterGraph2_AddFilter(iface, pfilter, lpcwstrFilterName);
1526 if (FAILED(hr)) {
1527 WARN("Unable to add filter (%x)\n", hr);
1528 IBaseFilter_Release(pfilter);
1529 return hr;
1532 if(ppFilter)
1533 *ppFilter = pfilter;
1534 else IBaseFilter_Release(pfilter);
1536 return S_OK;
1539 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *pin, const AM_MEDIA_TYPE *mt)
1541 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1542 PIN_DIRECTION dir;
1543 HRESULT hr;
1544 IPin *peer;
1546 TRACE("graph %p, pin %p, mt %p.\n", graph, pin, mt);
1548 if (FAILED(hr = IPin_ConnectedTo(pin, &peer)))
1549 return hr;
1551 IPin_QueryDirection(pin, &dir);
1552 IFilterGraph2_Disconnect(iface, peer);
1553 IFilterGraph2_Disconnect(iface, pin);
1555 if (dir == PINDIR_INPUT)
1556 hr = IFilterGraph2_ConnectDirect(iface, peer, pin, mt);
1557 else
1558 hr = IFilterGraph2_ConnectDirect(iface, pin, peer, mt);
1560 IPin_Release(peer);
1561 return hr;
1564 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *source, DWORD flags, DWORD *context)
1566 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1567 HRESULT hr;
1569 TRACE("graph %p, source %p, flags %#x, context %p.\n", graph, source, flags, context);
1571 if (flags & ~AM_RENDEREX_RENDERTOEXISTINGRENDERERS)
1572 FIXME("Unknown flags %#x.\n", flags);
1574 EnterCriticalSection(&graph->cs);
1575 hr = autoplug(graph, source, NULL, !!(flags & AM_RENDEREX_RENDERTOEXISTINGRENDERERS), 0);
1576 LeaveCriticalSection(&graph->cs);
1577 if (hr == VFW_E_CANNOT_CONNECT)
1578 hr = VFW_E_CANNOT_RENDER;
1580 TRACE("Returning %#x.\n", hr);
1581 return hr;
1585 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1587 FilterGraph2_QueryInterface,
1588 FilterGraph2_AddRef,
1589 FilterGraph2_Release,
1590 FilterGraph2_AddFilter,
1591 FilterGraph2_RemoveFilter,
1592 FilterGraph2_EnumFilters,
1593 FilterGraph2_FindFilterByName,
1594 FilterGraph2_ConnectDirect,
1595 FilterGraph2_Reconnect,
1596 FilterGraph2_Disconnect,
1597 FilterGraph2_SetDefaultSyncSource,
1598 FilterGraph2_Connect,
1599 FilterGraph2_Render,
1600 FilterGraph2_RenderFile,
1601 FilterGraph2_AddSourceFilter,
1602 FilterGraph2_SetLogFile,
1603 FilterGraph2_Abort,
1604 FilterGraph2_ShouldOperationContinue,
1605 FilterGraph2_AddSourceFilterForMoniker,
1606 FilterGraph2_ReconnectEx,
1607 FilterGraph2_RenderEx
1610 static struct filter_graph *impl_from_IMediaControl(IMediaControl *iface)
1612 return CONTAINING_RECORD(iface, struct filter_graph, IMediaControl_iface);
1615 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID iid, void **out)
1617 struct filter_graph *graph = impl_from_IMediaControl(iface);
1618 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
1621 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1623 struct filter_graph *graph = impl_from_IMediaControl(iface);
1624 return IUnknown_AddRef(graph->outer_unk);
1627 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1629 struct filter_graph *graph = impl_from_IMediaControl(iface);
1630 return IUnknown_Release(graph->outer_unk);
1634 /*** IDispatch methods ***/
1635 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *pctinfo)
1637 struct filter_graph *This = impl_from_IMediaControl(iface);
1639 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1641 return S_OK;
1644 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT iTInfo, LCID lcid,
1645 ITypeInfo **ppTInfo)
1647 struct filter_graph *This = impl_from_IMediaControl(iface);
1649 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1651 return S_OK;
1654 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID riid,
1655 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1657 struct filter_graph *This = impl_from_IMediaControl(iface);
1659 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
1660 cNames, lcid, rgDispId);
1662 return S_OK;
1665 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID dispIdMember, REFIID riid,
1666 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
1667 UINT *puArgErr)
1669 struct filter_graph *This = impl_from_IMediaControl(iface);
1671 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
1672 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
1674 return S_OK;
1677 static void update_render_count(struct filter_graph *graph)
1679 /* Some filters (e.g. MediaStreamFilter) can become renderers when they are
1680 * already in the graph. */
1681 struct filter *filter;
1682 graph->nRenderers = 0;
1683 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1685 if (is_renderer(filter))
1686 ++graph->nRenderers;
1690 /* Perform the paused -> running transition. The caller must hold graph->cs. */
1691 static HRESULT graph_start(struct filter_graph *graph, REFERENCE_TIME stream_start)
1693 struct media_event *event, *next;
1694 REFERENCE_TIME stream_stop;
1695 struct filter *filter;
1696 HRESULT hr = S_OK;
1698 graph->EcCompleteCount = 0;
1699 update_render_count(graph);
1701 LIST_FOR_EACH_ENTRY_SAFE(event, next, &graph->media_events, struct media_event, entry)
1703 if (event->code == EC_COMPLETE)
1705 list_remove(&event->entry);
1706 free(event);
1709 if (list_empty(&graph->media_events))
1710 ResetEvent(graph->media_event_handle);
1712 if (graph->defaultclock && !graph->refClock)
1713 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
1715 if (!stream_start && graph->refClock)
1717 IReferenceClock_GetTime(graph->refClock, &graph->stream_start);
1718 stream_start = graph->stream_start - graph->stream_elapsed;
1719 /* Delay presentation time by 200 ms, to give filters time to
1720 * initialize. */
1721 stream_start += 200 * 10000;
1724 if (SUCCEEDED(IMediaSeeking_GetStopPosition(&graph->IMediaSeeking_iface, &stream_stop)))
1725 graph->stream_stop = stream_stop;
1727 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1729 HRESULT filter_hr = IBaseFilter_Run(filter->filter, stream_start);
1730 if (hr == S_OK)
1731 hr = filter_hr;
1732 TRACE("Filter %p returned %#x.\n", filter->filter, filter_hr);
1735 if (FAILED(hr))
1736 WARN("Failed to start stream, hr %#x.\n", hr);
1738 return hr;
1741 static void CALLBACK async_run_cb(TP_CALLBACK_INSTANCE *instance, void *context, TP_WORK *work)
1743 struct filter_graph *graph = context;
1744 struct filter *filter;
1745 FILTER_STATE state;
1746 HRESULT hr;
1748 TRACE("Performing asynchronous state change.\n");
1750 /* We can't just call GetState(), since that will return State_Running and
1751 * VFW_S_STATE_INTERMEDIATE regardless of whether we're done pausing yet.
1752 * Instead replicate it here. */
1754 for (;;)
1756 IBaseFilter *async_filter = NULL;
1758 hr = S_OK;
1760 EnterCriticalSection(&graph->cs);
1762 if (!graph->needs_async_run)
1763 break;
1765 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1767 hr = IBaseFilter_GetState(filter->filter, 0, &state);
1769 if (hr == VFW_S_STATE_INTERMEDIATE)
1770 async_filter = filter->filter;
1772 if (SUCCEEDED(hr) && state != State_Paused)
1773 ERR("Filter %p reported incorrect state %u.\n", filter->filter, state);
1775 if (hr != S_OK)
1776 break;
1779 if (hr != VFW_S_STATE_INTERMEDIATE)
1780 break;
1782 LeaveCriticalSection(&graph->cs);
1784 IBaseFilter_GetState(async_filter, 10, &state);
1787 if (hr == S_OK && graph->needs_async_run)
1789 sort_filters(graph);
1790 graph_start(graph, 0);
1791 graph->needs_async_run = 0;
1794 LeaveCriticalSection(&graph->cs);
1797 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
1799 struct filter_graph *graph = impl_from_IMediaControl(iface);
1800 BOOL need_async_run = TRUE;
1801 struct filter *filter;
1802 FILTER_STATE state;
1803 HRESULT hr = S_OK;
1805 TRACE("graph %p.\n", graph);
1807 EnterCriticalSection(&graph->cs);
1809 if (graph->state == State_Running)
1811 LeaveCriticalSection(&graph->cs);
1812 return S_OK;
1815 sort_filters(graph);
1816 update_render_count(graph);
1818 if (graph->state == State_Stopped)
1820 if (graph->defaultclock && !graph->refClock)
1821 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
1823 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1825 HRESULT filter_hr = IBaseFilter_Pause(filter->filter);
1826 if (hr == S_OK)
1827 hr = filter_hr;
1828 TRACE("Filter %p returned %#x.\n", filter->filter, filter_hr);
1830 /* If a filter returns VFW_S_CANT_CUE, we shouldn't wait for a
1831 * paused state. */
1832 filter_hr = IBaseFilter_GetState(filter->filter, 0, &state);
1833 if (filter_hr != S_OK && filter_hr != VFW_S_STATE_INTERMEDIATE)
1834 need_async_run = FALSE;
1837 if (FAILED(hr))
1839 LeaveCriticalSection(&graph->cs);
1840 WARN("Failed to pause, hr %#x.\n", hr);
1841 return hr;
1845 graph->state = State_Running;
1847 if (SUCCEEDED(hr))
1849 if (hr != S_OK && need_async_run)
1851 if (!graph->async_run_work)
1852 graph->async_run_work = CreateThreadpoolWork(async_run_cb, graph, NULL);
1853 graph->needs_async_run = 1;
1854 SubmitThreadpoolWork(graph->async_run_work);
1856 else
1858 graph_start(graph, 0);
1862 LeaveCriticalSection(&graph->cs);
1863 return hr;
1866 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
1868 struct filter_graph *graph = impl_from_IMediaControl(iface);
1870 TRACE("graph %p.\n", graph);
1872 return IMediaFilter_Pause(&graph->IMediaFilter_iface);
1875 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
1877 struct filter_graph *graph = impl_from_IMediaControl(iface);
1879 TRACE("graph %p.\n", graph);
1881 return IMediaFilter_Stop(&graph->IMediaFilter_iface);
1884 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG timeout, OAFilterState *state)
1886 struct filter_graph *graph = impl_from_IMediaControl(iface);
1888 TRACE("graph %p, timeout %u, state %p.\n", graph, timeout, state);
1890 if (timeout < 0) timeout = INFINITE;
1892 return IMediaFilter_GetState(&graph->IMediaFilter_iface, timeout, (FILTER_STATE *)state);
1895 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
1897 struct filter_graph *This = impl_from_IMediaControl(iface);
1899 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strFilename), strFilename);
1901 return IFilterGraph2_RenderFile(&This->IFilterGraph2_iface, strFilename, NULL);
1904 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
1905 IDispatch **ppUnk)
1907 struct filter_graph *This = impl_from_IMediaControl(iface);
1909 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
1911 return S_OK;
1914 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
1916 struct filter_graph *This = impl_from_IMediaControl(iface);
1918 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
1920 return S_OK;
1923 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
1925 struct filter_graph *This = impl_from_IMediaControl(iface);
1927 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
1929 return S_OK;
1932 static void CALLBACK wait_pause_cb(TP_CALLBACK_INSTANCE *instance, void *context)
1934 IMediaControl *control = context;
1935 OAFilterState state;
1936 HRESULT hr;
1938 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
1939 ERR("Failed to get paused state, hr %#x.\n", hr);
1941 if (FAILED(hr = IMediaControl_Stop(control)))
1942 ERR("Failed to stop, hr %#x.\n", hr);
1944 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
1945 ERR("Failed to get paused state, hr %#x.\n", hr);
1947 IMediaControl_Release(control);
1950 static void CALLBACK wait_stop_cb(TP_CALLBACK_INSTANCE *instance, void *context)
1952 IMediaControl *control = context;
1953 OAFilterState state;
1954 HRESULT hr;
1956 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
1957 ERR("Failed to get state, hr %#x.\n", hr);
1959 IMediaControl_Release(control);
1962 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
1964 struct filter_graph *graph = impl_from_IMediaControl(iface);
1965 HRESULT hr;
1967 TRACE("graph %p.\n", graph);
1969 /* Even if we are already stopped, we still pause. */
1970 hr = IMediaControl_Pause(iface);
1971 if (FAILED(hr))
1972 return hr;
1973 else if (hr == S_FALSE)
1975 IMediaControl_AddRef(iface);
1976 TrySubmitThreadpoolCallback(wait_pause_cb, iface, NULL);
1977 return S_FALSE;
1980 hr = IMediaControl_Stop(iface);
1981 if (FAILED(hr))
1982 return hr;
1983 else if (hr == S_FALSE)
1985 IMediaControl_AddRef(iface);
1986 TrySubmitThreadpoolCallback(wait_stop_cb, iface, NULL);
1987 return S_FALSE;
1990 return S_OK;
1994 static const IMediaControlVtbl IMediaControl_VTable =
1996 MediaControl_QueryInterface,
1997 MediaControl_AddRef,
1998 MediaControl_Release,
1999 MediaControl_GetTypeInfoCount,
2000 MediaControl_GetTypeInfo,
2001 MediaControl_GetIDsOfNames,
2002 MediaControl_Invoke,
2003 MediaControl_Run,
2004 MediaControl_Pause,
2005 MediaControl_Stop,
2006 MediaControl_GetState,
2007 MediaControl_RenderFile,
2008 MediaControl_AddSourceFilter,
2009 MediaControl_get_FilterCollection,
2010 MediaControl_get_RegFilterCollection,
2011 MediaControl_StopWhenReady
2014 static struct filter_graph *impl_from_IMediaSeeking(IMediaSeeking *iface)
2016 return CONTAINING_RECORD(iface, struct filter_graph, IMediaSeeking_iface);
2019 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID iid, void **out)
2021 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2022 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2025 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2027 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2028 return IUnknown_AddRef(graph->outer_unk);
2031 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2033 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2034 return IUnknown_Release(graph->outer_unk);
2037 typedef HRESULT (WINAPI *fnFoundSeek)(struct filter_graph *This, IMediaSeeking*, DWORD_PTR arg);
2039 static HRESULT all_renderers_seek(struct filter_graph *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2040 BOOL allnotimpl = TRUE;
2041 HRESULT hr, hr_return = S_OK;
2042 struct filter *filter;
2044 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2045 /* Send a message to all renderers, they are responsible for broadcasting it further */
2047 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
2049 update_seeking(filter);
2050 if (!filter->seeking)
2051 continue;
2052 hr = FoundSeek(This, filter->seeking, arg);
2053 if (hr_return != E_NOTIMPL)
2054 allnotimpl = FALSE;
2055 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2056 hr_return = hr;
2059 if (allnotimpl)
2060 return E_NOTIMPL;
2061 return hr_return;
2064 static HRESULT WINAPI FoundCapabilities(struct filter_graph *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2066 HRESULT hr;
2067 DWORD caps = 0;
2069 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2070 if (FAILED(hr))
2071 return hr;
2073 /* Only add common capabilities everything supports */
2074 *(DWORD*)pcaps &= caps;
2076 return hr;
2079 /*** IMediaSeeking methods ***/
2080 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2082 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2083 HRESULT hr;
2085 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2087 if (!pCapabilities)
2088 return E_POINTER;
2090 EnterCriticalSection(&This->cs);
2091 *pCapabilities = 0xffffffff;
2093 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2094 LeaveCriticalSection(&This->cs);
2096 return hr;
2099 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2101 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2102 DWORD originalcaps;
2103 HRESULT hr;
2105 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2107 if (!pCapabilities)
2108 return E_POINTER;
2110 EnterCriticalSection(&This->cs);
2111 originalcaps = *pCapabilities;
2112 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2113 LeaveCriticalSection(&This->cs);
2115 if (FAILED(hr))
2116 return hr;
2118 if (!*pCapabilities)
2119 return E_FAIL;
2120 if (*pCapabilities != originalcaps)
2121 return S_FALSE;
2122 return S_OK;
2125 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2127 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2129 if (!pFormat)
2130 return E_POINTER;
2132 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2134 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2136 WARN("Unhandled time format %s\n", debugstr_guid(pFormat));
2137 return S_FALSE;
2140 return S_OK;
2143 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2145 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2147 if (!pFormat)
2148 return E_POINTER;
2150 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2151 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2153 return S_OK;
2156 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2158 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2160 if (!pFormat)
2161 return E_POINTER;
2163 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2164 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2166 return S_OK;
2169 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2171 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2173 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2174 if (!pFormat)
2175 return E_POINTER;
2177 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2178 return S_FALSE;
2180 return S_OK;
2183 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2185 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2187 if (!pFormat)
2188 return E_POINTER;
2190 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2192 if (This->state != State_Stopped)
2193 return VFW_E_WRONG_STATE;
2195 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2197 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2198 return E_INVALIDARG;
2201 return S_OK;
2204 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *duration)
2206 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2207 HRESULT hr = E_NOTIMPL, filter_hr;
2208 LONGLONG filter_duration;
2209 struct filter *filter;
2211 TRACE("graph %p, duration %p.\n", graph, duration);
2213 if (!duration)
2214 return E_POINTER;
2216 *duration = 0;
2218 EnterCriticalSection(&graph->cs);
2220 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2222 update_seeking(filter);
2223 if (!filter->seeking)
2224 continue;
2226 filter_hr = IMediaSeeking_GetDuration(filter->seeking, &filter_duration);
2227 if (SUCCEEDED(filter_hr))
2229 hr = S_OK;
2230 *duration = max(*duration, filter_duration);
2232 else if (filter_hr != E_NOTIMPL)
2234 LeaveCriticalSection(&graph->cs);
2235 return filter_hr;
2239 LeaveCriticalSection(&graph->cs);
2241 TRACE("Returning hr %#x, duration %s (%s seconds).\n", hr,
2242 wine_dbgstr_longlong(*duration), debugstr_time(*duration));
2243 return hr;
2246 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *stop)
2248 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2249 HRESULT hr = E_NOTIMPL, filter_hr;
2250 struct filter *filter;
2251 LONGLONG filter_stop;
2253 TRACE("graph %p, stop %p.\n", graph, stop);
2255 if (!stop)
2256 return E_POINTER;
2258 *stop = 0;
2260 EnterCriticalSection(&graph->cs);
2262 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2264 update_seeking(filter);
2265 if (!filter->seeking)
2266 continue;
2268 filter_hr = IMediaSeeking_GetStopPosition(filter->seeking, &filter_stop);
2269 if (SUCCEEDED(filter_hr))
2271 hr = S_OK;
2272 *stop = max(*stop, filter_stop);
2274 else if (filter_hr != E_NOTIMPL)
2276 LeaveCriticalSection(&graph->cs);
2277 return filter_hr;
2281 LeaveCriticalSection(&graph->cs);
2283 TRACE("Returning %s (%s seconds).\n", wine_dbgstr_longlong(*stop), debugstr_time(*stop));
2284 return hr;
2287 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *current)
2289 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2290 LONGLONG ret = graph->current_pos;
2292 TRACE("graph %p, current %p.\n", graph, current);
2294 if (!current)
2295 return E_POINTER;
2297 EnterCriticalSection(&graph->cs);
2299 if (graph->got_ec_complete)
2301 ret = graph->stream_stop;
2303 else if (graph->state == State_Running && !graph->needs_async_run && graph->refClock)
2305 REFERENCE_TIME time;
2306 IReferenceClock_GetTime(graph->refClock, &time);
2307 if (time)
2308 ret += time - graph->stream_start;
2311 LeaveCriticalSection(&graph->cs);
2313 TRACE("Returning %s (%s seconds).\n", wine_dbgstr_longlong(ret), debugstr_time(ret));
2314 *current = ret;
2316 return S_OK;
2319 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2320 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2322 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2324 TRACE("(%p/%p)->(%p, %s, 0x%s, %s)\n", This, iface, pTarget,
2325 debugstr_guid(pTargetFormat), wine_dbgstr_longlong(Source), debugstr_guid(pSourceFormat));
2327 if (!pSourceFormat)
2328 pSourceFormat = &This->timeformatseek;
2330 if (!pTargetFormat)
2331 pTargetFormat = &This->timeformatseek;
2333 if (IsEqualGUID(pTargetFormat, pSourceFormat))
2334 *pTarget = Source;
2335 else
2336 FIXME("conversion %s->%s not supported\n", debugstr_guid(pSourceFormat), debugstr_guid(pTargetFormat));
2338 return S_OK;
2341 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *current_ptr,
2342 DWORD current_flags, LONGLONG *stop_ptr, DWORD stop_flags)
2344 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2345 HRESULT hr = E_NOTIMPL, filter_hr;
2346 struct filter *filter;
2347 FILTER_STATE state;
2349 TRACE("graph %p, current %s, current_flags %#x, stop %s, stop_flags %#x.\n", graph,
2350 current_ptr ? wine_dbgstr_longlong(*current_ptr) : "<null>", current_flags,
2351 stop_ptr ? wine_dbgstr_longlong(*stop_ptr): "<null>", stop_flags);
2352 if (current_ptr)
2353 TRACE("Setting current position to %s (%s seconds).\n",
2354 wine_dbgstr_longlong(*current_ptr), debugstr_time(*current_ptr));
2355 if (stop_ptr)
2356 TRACE("Setting stop position to %s (%s seconds).\n",
2357 wine_dbgstr_longlong(*stop_ptr), debugstr_time(*stop_ptr));
2359 if ((current_flags & 0x7) != AM_SEEKING_AbsolutePositioning
2360 && (current_flags & 0x7) != AM_SEEKING_NoPositioning)
2361 FIXME("Unhandled current_flags %#x.\n", current_flags & 0x7);
2363 if ((stop_flags & 0x7) != AM_SEEKING_NoPositioning
2364 && (stop_flags & 0x7) != AM_SEEKING_AbsolutePositioning)
2365 FIXME("Unhandled stop_flags %#x.\n", stop_flags & 0x7);
2367 EnterCriticalSection(&graph->cs);
2369 state = graph->state;
2370 if (state == State_Running && !graph->needs_async_run)
2371 IMediaControl_Pause(&graph->IMediaControl_iface);
2373 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2375 LONGLONG current = current_ptr ? *current_ptr : 0, stop = stop_ptr ? *stop_ptr : 0;
2377 update_seeking(filter);
2378 if (!filter->seeking)
2379 continue;
2381 filter_hr = IMediaSeeking_SetPositions(filter->seeking, &current,
2382 current_flags | AM_SEEKING_ReturnTime, &stop, stop_flags);
2383 if (SUCCEEDED(filter_hr))
2385 hr = S_OK;
2387 if (current_ptr && (current_flags & AM_SEEKING_ReturnTime))
2388 *current_ptr = current;
2389 if (stop_ptr && (stop_flags & AM_SEEKING_ReturnTime))
2390 *stop_ptr = stop;
2391 graph->current_pos = current;
2393 else if (filter_hr != E_NOTIMPL)
2395 LeaveCriticalSection(&graph->cs);
2396 return filter_hr;
2400 if ((current_flags & 0x7) != AM_SEEKING_NoPositioning && graph->refClock)
2402 IReferenceClock_GetTime(graph->refClock, &graph->stream_start);
2403 graph->stream_elapsed = 0;
2406 if (state == State_Running && !graph->needs_async_run)
2407 IMediaControl_Run(&graph->IMediaControl_iface);
2409 LeaveCriticalSection(&graph->cs);
2410 return hr;
2413 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface,
2414 LONGLONG *current, LONGLONG *stop)
2416 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2417 HRESULT hr = S_OK;
2419 TRACE("graph %p, current %p, stop %p.\n", graph, current, stop);
2421 if (current)
2422 hr = IMediaSeeking_GetCurrentPosition(iface, current);
2423 if (SUCCEEDED(hr) && stop)
2424 hr = IMediaSeeking_GetStopPosition(iface, stop);
2426 return hr;
2429 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2430 LONGLONG *pLatest)
2432 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2434 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2436 return S_OK;
2439 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2441 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2443 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2445 return S_OK;
2448 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2450 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2452 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2454 if (!pdRate)
2455 return E_POINTER;
2457 *pdRate = 1.0;
2459 return S_OK;
2462 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2464 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2466 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2468 return S_OK;
2472 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2474 MediaSeeking_QueryInterface,
2475 MediaSeeking_AddRef,
2476 MediaSeeking_Release,
2477 MediaSeeking_GetCapabilities,
2478 MediaSeeking_CheckCapabilities,
2479 MediaSeeking_IsFormatSupported,
2480 MediaSeeking_QueryPreferredFormat,
2481 MediaSeeking_GetTimeFormat,
2482 MediaSeeking_IsUsingTimeFormat,
2483 MediaSeeking_SetTimeFormat,
2484 MediaSeeking_GetDuration,
2485 MediaSeeking_GetStopPosition,
2486 MediaSeeking_GetCurrentPosition,
2487 MediaSeeking_ConvertTimeFormat,
2488 MediaSeeking_SetPositions,
2489 MediaSeeking_GetPositions,
2490 MediaSeeking_GetAvailable,
2491 MediaSeeking_SetRate,
2492 MediaSeeking_GetRate,
2493 MediaSeeking_GetPreroll
2496 static struct filter_graph *impl_from_IMediaPosition(IMediaPosition *iface)
2498 return CONTAINING_RECORD(iface, struct filter_graph, IMediaPosition_iface);
2501 /*** IUnknown methods ***/
2502 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition *iface, REFIID iid, void **out)
2504 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2505 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2508 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2510 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2511 return IUnknown_AddRef(graph->outer_unk);
2514 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2516 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2517 return IUnknown_Release(graph->outer_unk);
2520 /*** IDispatch methods ***/
2521 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo)
2523 FIXME("(%p) stub!\n", iface);
2524 return E_NOTIMPL;
2527 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
2529 FIXME("(%p) stub!\n", iface);
2530 return E_NOTIMPL;
2533 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
2535 FIXME("(%p) stub!\n", iface);
2536 return E_NOTIMPL;
2539 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2541 FIXME("(%p) stub!\n", iface);
2542 return E_NOTIMPL;
2545 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2547 GUID time_format;
2548 HRESULT hr;
2550 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2551 if (FAILED(hr))
2552 return hr;
2553 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2555 FIXME("Unsupported time format.\n");
2556 return E_NOTIMPL;
2559 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2560 return S_OK;
2563 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2565 GUID time_format;
2566 HRESULT hr;
2568 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2569 if (FAILED(hr))
2570 return hr;
2571 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2573 FIXME("Unsupported time format.\n");
2574 return E_NOTIMPL;
2577 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2578 return S_OK;
2581 /*** IMediaPosition methods ***/
2582 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2584 LONGLONG duration;
2585 struct filter_graph *This = impl_from_IMediaPosition( iface );
2586 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2587 if (FAILED(hr))
2588 return hr;
2589 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2592 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2594 struct filter_graph *This = impl_from_IMediaPosition( iface );
2595 LONGLONG reftime;
2596 HRESULT hr;
2598 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2599 if (FAILED(hr))
2600 return hr;
2601 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2602 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2605 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2607 struct filter_graph *This = impl_from_IMediaPosition( iface );
2608 LONGLONG pos;
2609 HRESULT hr;
2611 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2612 if (FAILED(hr))
2613 return hr;
2614 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2617 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2619 struct filter_graph *This = impl_from_IMediaPosition( iface );
2620 LONGLONG pos;
2621 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2622 if (FAILED(hr))
2623 return hr;
2624 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2627 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2629 struct filter_graph *This = impl_from_IMediaPosition( iface );
2630 LONGLONG reftime;
2631 HRESULT hr;
2633 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2634 if (FAILED(hr))
2635 return hr;
2636 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2637 &reftime, AM_SEEKING_AbsolutePositioning);
2640 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime)
2642 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2643 return E_NOTIMPL;
2646 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime)
2648 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2649 return E_NOTIMPL;
2652 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2654 struct filter_graph *This = impl_from_IMediaPosition( iface );
2655 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2658 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2660 struct filter_graph *This = impl_from_IMediaPosition( iface );
2661 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2664 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward)
2666 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2667 return E_NOTIMPL;
2670 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward)
2672 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2673 return E_NOTIMPL;
2677 static const IMediaPositionVtbl IMediaPosition_VTable =
2679 MediaPosition_QueryInterface,
2680 MediaPosition_AddRef,
2681 MediaPosition_Release,
2682 MediaPosition_GetTypeInfoCount,
2683 MediaPosition_GetTypeInfo,
2684 MediaPosition_GetIDsOfNames,
2685 MediaPosition_Invoke,
2686 MediaPosition_get_Duration,
2687 MediaPosition_put_CurrentPosition,
2688 MediaPosition_get_CurrentPosition,
2689 MediaPosition_get_StopTime,
2690 MediaPosition_put_StopTime,
2691 MediaPosition_get_PrerollTime,
2692 MediaPosition_put_PrerollTime,
2693 MediaPosition_put_Rate,
2694 MediaPosition_get_Rate,
2695 MediaPosition_CanSeekForward,
2696 MediaPosition_CanSeekBackward
2699 static struct filter_graph *impl_from_IObjectWithSite(IObjectWithSite *iface)
2701 return CONTAINING_RECORD(iface, struct filter_graph, IObjectWithSite_iface);
2704 /*** IUnknown methods ***/
2705 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID iid, void **out)
2707 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2708 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2711 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
2713 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2714 return IUnknown_AddRef(graph->outer_unk);
2717 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
2719 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2720 return IUnknown_Release(graph->outer_unk);
2723 /*** IObjectWithSite methods ***/
2725 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
2727 struct filter_graph *This = impl_from_IObjectWithSite( iface );
2729 TRACE("(%p/%p)->()\n", This, iface);
2730 if (This->pSite) IUnknown_Release(This->pSite);
2731 This->pSite = pUnkSite;
2732 IUnknown_AddRef(This->pSite);
2733 return S_OK;
2736 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, PVOID *ppvSite)
2738 struct filter_graph *This = impl_from_IObjectWithSite( iface );
2740 TRACE("(%p/%p)->(%s)\n", This, iface,debugstr_guid(riid));
2742 *ppvSite = NULL;
2743 if (!This->pSite)
2744 return E_FAIL;
2745 else
2746 return IUnknown_QueryInterface(This->pSite, riid, ppvSite);
2749 static const IObjectWithSiteVtbl IObjectWithSite_VTable =
2751 ObjectWithSite_QueryInterface,
2752 ObjectWithSite_AddRef,
2753 ObjectWithSite_Release,
2754 ObjectWithSite_SetSite,
2755 ObjectWithSite_GetSite,
2758 static HRESULT GetTargetInterface(struct filter_graph* pGraph, REFIID riid, LPVOID* ppvObj)
2760 struct filter *filter;
2761 HRESULT hr;
2762 int entry;
2764 /* Check if the interface type is already registered */
2765 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2766 if (riid == pGraph->ItfCacheEntries[entry].riid)
2768 if (pGraph->ItfCacheEntries[entry].iface)
2770 /* Return the interface if available */
2771 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2772 return S_OK;
2774 break;
2777 if (entry >= MAX_ITF_CACHE_ENTRIES)
2779 FIXME("Not enough space to store interface in the cache\n");
2780 return E_OUTOFMEMORY;
2783 /* Find a filter supporting the requested interface */
2784 LIST_FOR_EACH_ENTRY(filter, &pGraph->filters, struct filter, entry)
2786 hr = IBaseFilter_QueryInterface(filter->filter, riid, ppvObj);
2787 if (hr == S_OK)
2789 pGraph->ItfCacheEntries[entry].riid = riid;
2790 pGraph->ItfCacheEntries[entry].filter = filter->filter;
2791 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2792 if (entry >= pGraph->nItfCacheEntries)
2793 pGraph->nItfCacheEntries++;
2794 return S_OK;
2796 if (hr != E_NOINTERFACE)
2797 return hr;
2800 return IsEqualGUID(riid, &IID_IBasicAudio) ? E_NOTIMPL : E_NOINTERFACE;
2803 static struct filter_graph *impl_from_IBasicAudio(IBasicAudio *iface)
2805 return CONTAINING_RECORD(iface, struct filter_graph, IBasicAudio_iface);
2808 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID iid, void **out)
2810 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2811 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2814 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
2816 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2817 return IUnknown_AddRef(graph->outer_unk);
2820 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
2822 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2823 return IUnknown_Release(graph->outer_unk);
2826 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *count)
2828 TRACE("iface %p, count %p.\n", iface, count);
2829 *count = 1;
2830 return S_OK;
2833 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT index,
2834 LCID lcid, ITypeInfo **typeinfo)
2836 TRACE("iface %p, index %u, lcid %#x, typeinfo %p.\n", iface, index, lcid, typeinfo);
2837 return strmbase_get_typeinfo(IBasicAudio_tid, typeinfo);
2840 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID iid,
2841 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
2843 ITypeInfo *typeinfo;
2844 HRESULT hr;
2846 TRACE("iface %p, iid %s, names %p, count %u, lcid %#x, ids %p.\n",
2847 iface, debugstr_guid(iid), names, count, lcid, ids);
2849 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicAudio_tid, &typeinfo)))
2851 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
2852 ITypeInfo_Release(typeinfo);
2854 return hr;
2857 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID id, REFIID iid, LCID lcid,
2858 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
2860 ITypeInfo *typeinfo;
2861 HRESULT hr;
2863 TRACE("iface %p, id %d, iid %s, lcid %#x, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
2864 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
2866 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicAudio_tid, &typeinfo)))
2868 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
2869 ITypeInfo_Release(typeinfo);
2871 return hr;
2874 /*** IBasicAudio methods ***/
2875 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
2877 struct filter_graph *This = impl_from_IBasicAudio(iface);
2878 IBasicAudio* pBasicAudio;
2879 HRESULT hr;
2881 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
2883 EnterCriticalSection(&This->cs);
2885 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2887 if (hr == S_OK)
2888 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
2890 LeaveCriticalSection(&This->cs);
2892 return hr;
2895 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
2897 struct filter_graph *This = impl_from_IBasicAudio(iface);
2898 IBasicAudio* pBasicAudio;
2899 HRESULT hr;
2901 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
2903 EnterCriticalSection(&This->cs);
2905 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2907 if (hr == S_OK)
2908 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
2910 LeaveCriticalSection(&This->cs);
2912 return hr;
2915 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
2917 struct filter_graph *This = impl_from_IBasicAudio(iface);
2918 IBasicAudio* pBasicAudio;
2919 HRESULT hr;
2921 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
2923 EnterCriticalSection(&This->cs);
2925 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2927 if (hr == S_OK)
2928 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
2930 LeaveCriticalSection(&This->cs);
2932 return hr;
2935 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
2937 struct filter_graph *This = impl_from_IBasicAudio(iface);
2938 IBasicAudio* pBasicAudio;
2939 HRESULT hr;
2941 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
2943 EnterCriticalSection(&This->cs);
2945 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2947 if (hr == S_OK)
2948 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
2950 LeaveCriticalSection(&This->cs);
2952 return hr;
2955 static const IBasicAudioVtbl IBasicAudio_VTable =
2957 BasicAudio_QueryInterface,
2958 BasicAudio_AddRef,
2959 BasicAudio_Release,
2960 BasicAudio_GetTypeInfoCount,
2961 BasicAudio_GetTypeInfo,
2962 BasicAudio_GetIDsOfNames,
2963 BasicAudio_Invoke,
2964 BasicAudio_put_Volume,
2965 BasicAudio_get_Volume,
2966 BasicAudio_put_Balance,
2967 BasicAudio_get_Balance
2970 static struct filter_graph *impl_from_IBasicVideo2(IBasicVideo2 *iface)
2972 return CONTAINING_RECORD(iface, struct filter_graph, IBasicVideo2_iface);
2975 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID iid, void **out)
2977 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
2978 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2981 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
2983 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
2984 return IUnknown_AddRef(graph->outer_unk);
2987 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
2989 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
2990 return IUnknown_Release(graph->outer_unk);
2993 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *count)
2995 TRACE("iface %p, count %p.\n", iface, count);
2996 *count = 1;
2997 return S_OK;
3000 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT index,
3001 LCID lcid, ITypeInfo **typeinfo)
3003 TRACE("iface %p, index %u, lcid %#x, typeinfo %p.\n", iface, index, lcid, typeinfo);
3004 return strmbase_get_typeinfo(IBasicVideo_tid, typeinfo);
3007 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID iid,
3008 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
3010 ITypeInfo *typeinfo;
3011 HRESULT hr;
3013 TRACE("iface %p, iid %s, names %p, count %u, lcid %#x, ids %p.\n",
3014 iface, debugstr_guid(iid), names, count, lcid, ids);
3016 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicVideo_tid, &typeinfo)))
3018 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
3019 ITypeInfo_Release(typeinfo);
3021 return hr;
3024 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID id, REFIID iid, LCID lcid,
3025 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
3027 ITypeInfo *typeinfo;
3028 HRESULT hr;
3030 TRACE("iface %p, id %d, iid %s, lcid %#x, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
3031 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
3033 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicVideo_tid, &typeinfo)))
3035 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
3036 ITypeInfo_Release(typeinfo);
3038 return hr;
3041 /*** IBasicVideo methods ***/
3042 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3044 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3045 IBasicVideo *pBasicVideo;
3046 HRESULT hr;
3048 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3050 EnterCriticalSection(&This->cs);
3052 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3054 if (hr == S_OK)
3055 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3057 LeaveCriticalSection(&This->cs);
3059 return hr;
3062 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3064 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3065 IBasicVideo *pBasicVideo;
3066 HRESULT hr;
3068 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3070 EnterCriticalSection(&This->cs);
3072 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3074 if (hr == S_OK)
3075 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3077 LeaveCriticalSection(&This->cs);
3079 return hr;
3082 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3084 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3085 IBasicVideo *pBasicVideo;
3086 HRESULT hr;
3088 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3090 EnterCriticalSection(&This->cs);
3092 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3094 if (hr == S_OK)
3095 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3097 LeaveCriticalSection(&This->cs);
3099 return hr;
3102 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3104 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3105 IBasicVideo *pBasicVideo;
3106 HRESULT hr;
3108 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3110 EnterCriticalSection(&This->cs);
3112 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3114 if (hr == S_OK)
3115 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3117 LeaveCriticalSection(&This->cs);
3119 return hr;
3122 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3124 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3125 IBasicVideo *pBasicVideo;
3126 HRESULT hr;
3128 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3130 EnterCriticalSection(&This->cs);
3132 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3134 if (hr == S_OK)
3135 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3137 LeaveCriticalSection(&This->cs);
3139 return hr;
3142 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3144 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3145 IBasicVideo *pBasicVideo;
3146 HRESULT hr;
3148 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3150 EnterCriticalSection(&This->cs);
3152 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3154 if (hr == S_OK)
3155 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3157 LeaveCriticalSection(&This->cs);
3159 return hr;
3162 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3164 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3165 IBasicVideo *pBasicVideo;
3166 HRESULT hr;
3168 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3170 EnterCriticalSection(&This->cs);
3172 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3174 if (hr == S_OK)
3175 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3177 LeaveCriticalSection(&This->cs);
3179 return hr;
3182 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3184 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3185 IBasicVideo *pBasicVideo;
3186 HRESULT hr;
3188 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3190 EnterCriticalSection(&This->cs);
3192 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3194 if (hr == S_OK)
3195 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3197 LeaveCriticalSection(&This->cs);
3199 return hr;
3202 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3204 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3205 IBasicVideo *pBasicVideo;
3206 HRESULT hr;
3208 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3210 EnterCriticalSection(&This->cs);
3212 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3214 if (hr == S_OK)
3215 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3217 LeaveCriticalSection(&This->cs);
3219 return hr;
3222 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3224 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3225 IBasicVideo *pBasicVideo;
3226 HRESULT hr;
3228 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3230 EnterCriticalSection(&This->cs);
3232 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3234 if (hr == S_OK)
3235 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3237 LeaveCriticalSection(&This->cs);
3239 return hr;
3242 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3244 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3245 IBasicVideo *pBasicVideo;
3246 HRESULT hr;
3248 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3250 EnterCriticalSection(&This->cs);
3252 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3254 if (hr == S_OK)
3255 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3257 LeaveCriticalSection(&This->cs);
3259 return hr;
3262 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3264 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3265 IBasicVideo *pBasicVideo;
3266 HRESULT hr;
3268 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3270 EnterCriticalSection(&This->cs);
3272 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3274 if (hr == S_OK)
3275 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3277 LeaveCriticalSection(&This->cs);
3279 return hr;
3282 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3284 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3285 IBasicVideo *pBasicVideo;
3286 HRESULT hr;
3288 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3290 EnterCriticalSection(&This->cs);
3292 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3294 if (hr == S_OK)
3295 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3297 LeaveCriticalSection(&This->cs);
3299 return hr;
3302 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3304 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3305 IBasicVideo *pBasicVideo;
3306 HRESULT hr;
3308 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3310 EnterCriticalSection(&This->cs);
3312 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3314 if (hr == S_OK)
3315 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3317 LeaveCriticalSection(&This->cs);
3319 return hr;
3322 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3324 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3325 IBasicVideo *pBasicVideo;
3326 HRESULT hr;
3328 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3330 EnterCriticalSection(&This->cs);
3332 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3334 if (hr == S_OK)
3335 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3337 LeaveCriticalSection(&This->cs);
3339 return hr;
3342 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3344 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3345 IBasicVideo *pBasicVideo;
3346 HRESULT hr;
3348 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3350 EnterCriticalSection(&This->cs);
3352 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3354 if (hr == S_OK)
3355 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3357 LeaveCriticalSection(&This->cs);
3359 return hr;
3362 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3364 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3365 IBasicVideo *pBasicVideo;
3366 HRESULT hr;
3368 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3370 EnterCriticalSection(&This->cs);
3372 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3374 if (hr == S_OK)
3375 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3377 LeaveCriticalSection(&This->cs);
3379 return hr;
3382 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3384 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3385 IBasicVideo *pBasicVideo;
3386 HRESULT hr;
3388 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3390 EnterCriticalSection(&This->cs);
3392 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3394 if (hr == S_OK)
3395 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3397 LeaveCriticalSection(&This->cs);
3399 return hr;
3402 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3404 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3405 IBasicVideo *pBasicVideo;
3406 HRESULT hr;
3408 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3410 EnterCriticalSection(&This->cs);
3412 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3414 if (hr == S_OK)
3415 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3417 LeaveCriticalSection(&This->cs);
3419 return hr;
3422 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3424 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3425 IBasicVideo *pBasicVideo;
3426 HRESULT hr;
3428 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3430 EnterCriticalSection(&This->cs);
3432 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3434 if (hr == S_OK)
3435 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3437 LeaveCriticalSection(&This->cs);
3439 return hr;
3442 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3443 LONG *pDestinationHeight)
3445 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3446 IBasicVideo *pBasicVideo;
3447 HRESULT hr;
3449 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3451 EnterCriticalSection(&This->cs);
3453 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3455 if (hr == S_OK)
3456 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3458 LeaveCriticalSection(&This->cs);
3460 return hr;
3463 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3464 LONG Width, LONG Height)
3466 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3467 IBasicVideo *pBasicVideo;
3468 HRESULT hr;
3470 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3472 EnterCriticalSection(&This->cs);
3474 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3476 if (hr == S_OK)
3477 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3479 LeaveCriticalSection(&This->cs);
3481 return hr;
3484 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3485 LONG *pWidth, LONG *pHeight)
3487 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3488 IBasicVideo *pBasicVideo;
3489 HRESULT hr;
3491 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3493 EnterCriticalSection(&This->cs);
3495 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3497 if (hr == S_OK)
3498 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3500 LeaveCriticalSection(&This->cs);
3502 return hr;
3505 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3507 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3508 IBasicVideo *pBasicVideo;
3509 HRESULT hr;
3511 TRACE("(%p/%p)->()\n", This, iface);
3513 EnterCriticalSection(&This->cs);
3515 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3517 if (hr == S_OK)
3518 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3520 LeaveCriticalSection(&This->cs);
3522 return hr;
3525 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3526 LONG Width, LONG Height)
3528 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3529 IBasicVideo *pBasicVideo;
3530 HRESULT hr;
3532 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3534 EnterCriticalSection(&This->cs);
3536 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3538 if (hr == S_OK)
3539 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3541 LeaveCriticalSection(&This->cs);
3543 return hr;
3546 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3547 LONG *pTop, LONG *pWidth, LONG *pHeight)
3549 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3550 IBasicVideo *pBasicVideo;
3551 HRESULT hr;
3553 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3555 EnterCriticalSection(&This->cs);
3557 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3559 if (hr == S_OK)
3560 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3562 LeaveCriticalSection(&This->cs);
3564 return hr;
3567 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3569 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3570 IBasicVideo *pBasicVideo;
3571 HRESULT hr;
3573 TRACE("(%p/%p)->()\n", This, iface);
3575 EnterCriticalSection(&This->cs);
3577 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3579 if (hr == S_OK)
3580 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3582 LeaveCriticalSection(&This->cs);
3584 return hr;
3587 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3589 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3590 IBasicVideo *pBasicVideo;
3591 HRESULT hr;
3593 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3595 EnterCriticalSection(&This->cs);
3597 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3599 if (hr == S_OK)
3600 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3602 LeaveCriticalSection(&This->cs);
3604 return hr;
3607 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3608 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3610 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3611 IBasicVideo *pBasicVideo;
3612 HRESULT hr;
3614 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3616 EnterCriticalSection(&This->cs);
3618 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3620 if (hr == S_OK)
3621 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3623 LeaveCriticalSection(&This->cs);
3625 return hr;
3628 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3629 LONG *pDIBImage)
3631 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3632 IBasicVideo *pBasicVideo;
3633 HRESULT hr;
3635 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3637 EnterCriticalSection(&This->cs);
3639 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3641 if (hr == S_OK)
3642 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3644 LeaveCriticalSection(&This->cs);
3646 return hr;
3649 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3651 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3652 IBasicVideo *pBasicVideo;
3653 HRESULT hr;
3655 TRACE("(%p/%p)->()\n", This, iface);
3657 EnterCriticalSection(&This->cs);
3659 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3661 if (hr == S_OK)
3662 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3664 LeaveCriticalSection(&This->cs);
3666 return hr;
3669 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3671 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3672 IBasicVideo *pBasicVideo;
3673 HRESULT hr;
3675 TRACE("(%p/%p)->()\n", This, iface);
3677 EnterCriticalSection(&This->cs);
3679 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3681 if (hr == S_OK)
3682 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3684 LeaveCriticalSection(&This->cs);
3686 return hr;
3689 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3690 LONG *plAspectY)
3692 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3693 IBasicVideo2 *pBasicVideo2;
3694 HRESULT hr;
3696 TRACE("(%p/%p)->()\n", This, iface);
3698 EnterCriticalSection(&This->cs);
3700 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3702 if (hr == S_OK)
3703 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3705 LeaveCriticalSection(&This->cs);
3707 return hr;
3710 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3712 BasicVideo_QueryInterface,
3713 BasicVideo_AddRef,
3714 BasicVideo_Release,
3715 BasicVideo_GetTypeInfoCount,
3716 BasicVideo_GetTypeInfo,
3717 BasicVideo_GetIDsOfNames,
3718 BasicVideo_Invoke,
3719 BasicVideo_get_AvgTimePerFrame,
3720 BasicVideo_get_BitRate,
3721 BasicVideo_get_BitErrorRate,
3722 BasicVideo_get_VideoWidth,
3723 BasicVideo_get_VideoHeight,
3724 BasicVideo_put_SourceLeft,
3725 BasicVideo_get_SourceLeft,
3726 BasicVideo_put_SourceWidth,
3727 BasicVideo_get_SourceWidth,
3728 BasicVideo_put_SourceTop,
3729 BasicVideo_get_SourceTop,
3730 BasicVideo_put_SourceHeight,
3731 BasicVideo_get_SourceHeight,
3732 BasicVideo_put_DestinationLeft,
3733 BasicVideo_get_DestinationLeft,
3734 BasicVideo_put_DestinationWidth,
3735 BasicVideo_get_DestinationWidth,
3736 BasicVideo_put_DestinationTop,
3737 BasicVideo_get_DestinationTop,
3738 BasicVideo_put_DestinationHeight,
3739 BasicVideo_get_DestinationHeight,
3740 BasicVideo_SetSourcePosition,
3741 BasicVideo_GetSourcePosition,
3742 BasicVideo_SetDefaultSourcePosition,
3743 BasicVideo_SetDestinationPosition,
3744 BasicVideo_GetDestinationPosition,
3745 BasicVideo_SetDefaultDestinationPosition,
3746 BasicVideo_GetVideoSize,
3747 BasicVideo_GetVideoPaletteEntries,
3748 BasicVideo_GetCurrentImage,
3749 BasicVideo_IsUsingDefaultSource,
3750 BasicVideo_IsUsingDefaultDestination,
3751 BasicVideo2_GetPreferredAspectRatio
3754 static struct filter_graph *impl_from_IVideoWindow(IVideoWindow *iface)
3756 return CONTAINING_RECORD(iface, struct filter_graph, IVideoWindow_iface);
3759 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID iid, void **out)
3761 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3762 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
3765 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
3767 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3768 return IUnknown_AddRef(graph->outer_unk);
3771 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
3773 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3774 return IUnknown_Release(graph->outer_unk);
3777 HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *count)
3779 TRACE("iface %p, count %p.\n", iface, count);
3780 *count = 1;
3781 return S_OK;
3784 HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT index,
3785 LCID lcid, ITypeInfo **typeinfo)
3787 TRACE("iface %p, index %u, lcid %#x, typeinfo %p.\n", iface, index, lcid, typeinfo);
3788 return strmbase_get_typeinfo(IVideoWindow_tid, typeinfo);
3791 HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID iid,
3792 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
3794 ITypeInfo *typeinfo;
3795 HRESULT hr;
3797 TRACE("iface %p, iid %s, names %p, count %u, lcid %#x, ids %p.\n",
3798 iface, debugstr_guid(iid), names, count, lcid, ids);
3800 if (SUCCEEDED(hr = strmbase_get_typeinfo(IVideoWindow_tid, &typeinfo)))
3802 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
3803 ITypeInfo_Release(typeinfo);
3805 return hr;
3808 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID id, REFIID iid, LCID lcid,
3809 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
3811 ITypeInfo *typeinfo;
3812 HRESULT hr;
3814 TRACE("iface %p, id %d, iid %s, lcid %#x, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
3815 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
3817 if (SUCCEEDED(hr = strmbase_get_typeinfo(IVideoWindow_tid, &typeinfo)))
3819 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
3820 ITypeInfo_Release(typeinfo);
3822 return hr;
3825 /*** IVideoWindow methods ***/
3826 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
3828 struct filter_graph *This = impl_from_IVideoWindow(iface);
3829 IVideoWindow *pVideoWindow;
3830 HRESULT hr;
3832 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
3834 EnterCriticalSection(&This->cs);
3836 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3838 if (hr == S_OK)
3839 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
3841 LeaveCriticalSection(&This->cs);
3843 return hr;
3846 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
3848 struct filter_graph *This = impl_from_IVideoWindow(iface);
3849 IVideoWindow *pVideoWindow;
3850 HRESULT hr;
3852 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
3854 EnterCriticalSection(&This->cs);
3856 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3858 if (hr == S_OK)
3859 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
3861 LeaveCriticalSection(&This->cs);
3863 return hr;
3866 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
3868 struct filter_graph *This = impl_from_IVideoWindow(iface);
3869 IVideoWindow *pVideoWindow;
3870 HRESULT hr;
3872 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
3874 EnterCriticalSection(&This->cs);
3876 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3878 if (hr == S_OK)
3879 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
3881 LeaveCriticalSection(&This->cs);
3883 return hr;
3886 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
3888 struct filter_graph *This = impl_from_IVideoWindow(iface);
3889 IVideoWindow *pVideoWindow;
3890 HRESULT hr;
3892 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
3894 EnterCriticalSection(&This->cs);
3896 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3898 if (hr == S_OK)
3899 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
3901 LeaveCriticalSection(&This->cs);
3903 return hr;
3906 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
3908 struct filter_graph *This = impl_from_IVideoWindow(iface);
3909 IVideoWindow *pVideoWindow;
3910 HRESULT hr;
3912 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
3914 EnterCriticalSection(&This->cs);
3916 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3918 if (hr == S_OK)
3919 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
3921 LeaveCriticalSection(&This->cs);
3923 return hr;
3926 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
3928 struct filter_graph *This = impl_from_IVideoWindow(iface);
3929 IVideoWindow *pVideoWindow;
3930 HRESULT hr;
3932 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
3934 EnterCriticalSection(&This->cs);
3936 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3938 if (hr == S_OK)
3939 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
3941 LeaveCriticalSection(&This->cs);
3943 return hr;
3946 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
3948 struct filter_graph *This = impl_from_IVideoWindow(iface);
3949 IVideoWindow *pVideoWindow;
3950 HRESULT hr;
3952 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
3954 EnterCriticalSection(&This->cs);
3956 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3958 if (hr == S_OK)
3959 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
3961 LeaveCriticalSection(&This->cs);
3963 return hr;
3966 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
3968 struct filter_graph *This = impl_from_IVideoWindow(iface);
3969 IVideoWindow *pVideoWindow;
3970 HRESULT hr;
3972 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
3974 EnterCriticalSection(&This->cs);
3976 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3978 if (hr == S_OK)
3979 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
3981 LeaveCriticalSection(&This->cs);
3983 return hr;
3986 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
3988 struct filter_graph *This = impl_from_IVideoWindow(iface);
3989 IVideoWindow *pVideoWindow;
3990 HRESULT hr;
3992 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
3994 EnterCriticalSection(&This->cs);
3996 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3998 if (hr == S_OK)
3999 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4001 LeaveCriticalSection(&This->cs);
4003 return hr;
4006 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4008 struct filter_graph *This = impl_from_IVideoWindow(iface);
4009 IVideoWindow *pVideoWindow;
4010 HRESULT hr;
4012 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4014 EnterCriticalSection(&This->cs);
4016 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4018 if (hr == S_OK)
4019 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4021 LeaveCriticalSection(&This->cs);
4023 return hr;
4026 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4028 struct filter_graph *This = impl_from_IVideoWindow(iface);
4029 IVideoWindow *pVideoWindow;
4030 HRESULT hr;
4032 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4034 EnterCriticalSection(&This->cs);
4036 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4038 if (hr == S_OK)
4039 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4041 LeaveCriticalSection(&This->cs);
4043 return hr;
4046 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4047 LONG *pBackgroundPalette)
4049 struct filter_graph *This = impl_from_IVideoWindow(iface);
4050 IVideoWindow *pVideoWindow;
4051 HRESULT hr;
4053 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4055 EnterCriticalSection(&This->cs);
4057 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4059 if (hr == S_OK)
4060 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4062 LeaveCriticalSection(&This->cs);
4064 return hr;
4067 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4069 struct filter_graph *This = impl_from_IVideoWindow(iface);
4070 IVideoWindow *pVideoWindow;
4071 HRESULT hr;
4073 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4075 EnterCriticalSection(&This->cs);
4077 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4079 if (hr == S_OK)
4080 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4082 LeaveCriticalSection(&This->cs);
4084 return hr;
4087 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4089 struct filter_graph *This = impl_from_IVideoWindow(iface);
4090 IVideoWindow *pVideoWindow;
4091 HRESULT hr;
4093 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4095 EnterCriticalSection(&This->cs);
4097 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4099 if (hr == S_OK)
4100 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4102 LeaveCriticalSection(&This->cs);
4104 return hr;
4107 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4109 struct filter_graph *This = impl_from_IVideoWindow(iface);
4110 IVideoWindow *pVideoWindow;
4111 HRESULT hr;
4113 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4115 EnterCriticalSection(&This->cs);
4117 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4119 if (hr == S_OK)
4120 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4122 LeaveCriticalSection(&This->cs);
4124 return hr;
4127 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4129 struct filter_graph *This = impl_from_IVideoWindow(iface);
4130 IVideoWindow *pVideoWindow;
4131 HRESULT hr;
4133 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4135 EnterCriticalSection(&This->cs);
4137 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4139 if (hr == S_OK)
4140 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4142 LeaveCriticalSection(&This->cs);
4144 return hr;
4147 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4149 struct filter_graph *This = impl_from_IVideoWindow(iface);
4150 IVideoWindow *pVideoWindow;
4151 HRESULT hr;
4153 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4155 EnterCriticalSection(&This->cs);
4157 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4159 if (hr == S_OK)
4160 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4162 LeaveCriticalSection(&This->cs);
4164 return hr;
4167 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4169 struct filter_graph *This = impl_from_IVideoWindow(iface);
4170 IVideoWindow *pVideoWindow;
4171 HRESULT hr;
4173 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4175 EnterCriticalSection(&This->cs);
4177 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4179 if (hr == S_OK)
4180 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4182 LeaveCriticalSection(&This->cs);
4184 return hr;
4187 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4189 struct filter_graph *This = impl_from_IVideoWindow(iface);
4190 IVideoWindow *pVideoWindow;
4191 HRESULT hr;
4193 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4195 EnterCriticalSection(&This->cs);
4197 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4199 if (hr == S_OK)
4200 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4202 LeaveCriticalSection(&This->cs);
4204 return hr;
4207 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4209 struct filter_graph *This = impl_from_IVideoWindow(iface);
4210 IVideoWindow *pVideoWindow;
4211 HRESULT hr;
4213 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4215 EnterCriticalSection(&This->cs);
4217 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4219 if (hr == S_OK)
4220 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4222 LeaveCriticalSection(&This->cs);
4224 return hr;
4227 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4229 struct filter_graph *This = impl_from_IVideoWindow(iface);
4230 IVideoWindow *pVideoWindow;
4231 HRESULT hr;
4233 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4235 EnterCriticalSection(&This->cs);
4237 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4239 if (hr == S_OK)
4240 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4242 LeaveCriticalSection(&This->cs);
4244 return hr;
4247 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4249 struct filter_graph *This = impl_from_IVideoWindow(iface);
4250 IVideoWindow *pVideoWindow;
4251 HRESULT hr;
4253 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4255 EnterCriticalSection(&This->cs);
4257 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4259 if (hr == S_OK)
4260 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4262 LeaveCriticalSection(&This->cs);
4264 return hr;
4267 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4269 struct filter_graph *This = impl_from_IVideoWindow(iface);
4270 IVideoWindow *pVideoWindow;
4271 HRESULT hr;
4273 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4275 EnterCriticalSection(&This->cs);
4277 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4279 if (hr == S_OK)
4280 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4282 LeaveCriticalSection(&This->cs);
4284 return hr;
4287 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4289 struct filter_graph *This = impl_from_IVideoWindow(iface);
4290 IVideoWindow *pVideoWindow;
4291 HRESULT hr;
4293 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4295 EnterCriticalSection(&This->cs);
4297 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4299 if (hr == S_OK)
4300 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4302 LeaveCriticalSection(&This->cs);
4304 return hr;
4307 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4309 struct filter_graph *This = impl_from_IVideoWindow(iface);
4310 IVideoWindow *pVideoWindow;
4311 HRESULT hr;
4313 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4315 EnterCriticalSection(&This->cs);
4317 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4319 if (hr == S_OK)
4320 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4322 LeaveCriticalSection(&This->cs);
4324 return hr;
4327 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4329 struct filter_graph *This = impl_from_IVideoWindow(iface);
4330 IVideoWindow *pVideoWindow;
4331 HRESULT hr;
4333 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4335 EnterCriticalSection(&This->cs);
4337 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4339 if (hr == S_OK)
4340 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4342 LeaveCriticalSection(&This->cs);
4344 return hr;
4347 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4349 struct filter_graph *This = impl_from_IVideoWindow(iface);
4350 IVideoWindow *pVideoWindow;
4351 HRESULT hr;
4353 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4355 EnterCriticalSection(&This->cs);
4357 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4359 if (hr == S_OK)
4360 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4362 LeaveCriticalSection(&This->cs);
4364 return hr;
4367 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4369 struct filter_graph *This = impl_from_IVideoWindow(iface);
4370 IVideoWindow *pVideoWindow;
4371 HRESULT hr;
4373 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4375 EnterCriticalSection(&This->cs);
4377 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4379 if (hr == S_OK)
4380 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4382 LeaveCriticalSection(&This->cs);
4384 return hr;
4387 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4389 struct filter_graph *This = impl_from_IVideoWindow(iface);
4390 IVideoWindow *pVideoWindow;
4391 HRESULT hr;
4393 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4395 EnterCriticalSection(&This->cs);
4397 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4399 if (hr == S_OK)
4400 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4402 LeaveCriticalSection(&This->cs);
4404 return hr;
4407 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4409 struct filter_graph *This = impl_from_IVideoWindow(iface);
4410 IVideoWindow *pVideoWindow;
4411 HRESULT hr;
4413 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4415 EnterCriticalSection(&This->cs);
4417 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4419 if (hr == S_OK)
4420 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4422 LeaveCriticalSection(&This->cs);
4424 return hr;
4427 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4429 struct filter_graph *This = impl_from_IVideoWindow(iface);
4430 IVideoWindow *pVideoWindow;
4431 HRESULT hr;
4433 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4435 EnterCriticalSection(&This->cs);
4437 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4439 if (hr == S_OK)
4440 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4442 LeaveCriticalSection(&This->cs);
4444 return hr;
4447 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4448 LONG_PTR wParam, LONG_PTR lParam)
4450 struct filter_graph *This = impl_from_IVideoWindow(iface);
4451 IVideoWindow *pVideoWindow;
4452 HRESULT hr;
4454 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4456 EnterCriticalSection(&This->cs);
4458 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4460 if (hr == S_OK)
4461 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4463 LeaveCriticalSection(&This->cs);
4465 return hr;
4468 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4469 LONG Width, LONG Height)
4471 struct filter_graph *This = impl_from_IVideoWindow(iface);
4472 IVideoWindow *pVideoWindow;
4473 HRESULT hr;
4475 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4477 EnterCriticalSection(&This->cs);
4479 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4481 if (hr == S_OK)
4482 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4484 LeaveCriticalSection(&This->cs);
4486 return hr;
4489 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4490 LONG *pWidth, LONG *pHeight)
4492 struct filter_graph *This = impl_from_IVideoWindow(iface);
4493 IVideoWindow *pVideoWindow;
4494 HRESULT hr;
4496 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4498 EnterCriticalSection(&This->cs);
4500 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4502 if (hr == S_OK)
4503 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4505 LeaveCriticalSection(&This->cs);
4507 return hr;
4510 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4511 LONG *pHeight)
4513 struct filter_graph *This = impl_from_IVideoWindow(iface);
4514 IVideoWindow *pVideoWindow;
4515 HRESULT hr;
4517 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4519 EnterCriticalSection(&This->cs);
4521 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4523 if (hr == S_OK)
4524 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4526 LeaveCriticalSection(&This->cs);
4528 return hr;
4531 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4532 LONG *pHeight)
4534 struct filter_graph *This = impl_from_IVideoWindow(iface);
4535 IVideoWindow *pVideoWindow;
4536 HRESULT hr;
4538 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4540 EnterCriticalSection(&This->cs);
4542 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4544 if (hr == S_OK)
4545 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4547 LeaveCriticalSection(&This->cs);
4549 return hr;
4552 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4553 LONG *pWidth, LONG *pHeight)
4555 struct filter_graph *This = impl_from_IVideoWindow(iface);
4556 IVideoWindow *pVideoWindow;
4557 HRESULT hr;
4559 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4561 EnterCriticalSection(&This->cs);
4563 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4565 if (hr == S_OK)
4566 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4568 LeaveCriticalSection(&This->cs);
4570 return hr;
4573 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4575 struct filter_graph *This = impl_from_IVideoWindow(iface);
4576 IVideoWindow *pVideoWindow;
4577 HRESULT hr;
4579 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4581 EnterCriticalSection(&This->cs);
4583 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4585 if (hr == S_OK)
4586 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4588 LeaveCriticalSection(&This->cs);
4590 return hr;
4593 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4595 struct filter_graph *This = impl_from_IVideoWindow(iface);
4596 IVideoWindow *pVideoWindow;
4597 HRESULT hr;
4599 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4601 EnterCriticalSection(&This->cs);
4603 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4605 if (hr == S_OK)
4606 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4608 LeaveCriticalSection(&This->cs);
4610 return hr;
4614 static const IVideoWindowVtbl IVideoWindow_VTable =
4616 VideoWindow_QueryInterface,
4617 VideoWindow_AddRef,
4618 VideoWindow_Release,
4619 VideoWindow_GetTypeInfoCount,
4620 VideoWindow_GetTypeInfo,
4621 VideoWindow_GetIDsOfNames,
4622 VideoWindow_Invoke,
4623 VideoWindow_put_Caption,
4624 VideoWindow_get_Caption,
4625 VideoWindow_put_WindowStyle,
4626 VideoWindow_get_WindowStyle,
4627 VideoWindow_put_WindowStyleEx,
4628 VideoWindow_get_WindowStyleEx,
4629 VideoWindow_put_AutoShow,
4630 VideoWindow_get_AutoShow,
4631 VideoWindow_put_WindowState,
4632 VideoWindow_get_WindowState,
4633 VideoWindow_put_BackgroundPalette,
4634 VideoWindow_get_BackgroundPalette,
4635 VideoWindow_put_Visible,
4636 VideoWindow_get_Visible,
4637 VideoWindow_put_Left,
4638 VideoWindow_get_Left,
4639 VideoWindow_put_Width,
4640 VideoWindow_get_Width,
4641 VideoWindow_put_Top,
4642 VideoWindow_get_Top,
4643 VideoWindow_put_Height,
4644 VideoWindow_get_Height,
4645 VideoWindow_put_Owner,
4646 VideoWindow_get_Owner,
4647 VideoWindow_put_MessageDrain,
4648 VideoWindow_get_MessageDrain,
4649 VideoWindow_get_BorderColor,
4650 VideoWindow_put_BorderColor,
4651 VideoWindow_get_FullScreenMode,
4652 VideoWindow_put_FullScreenMode,
4653 VideoWindow_SetWindowForeground,
4654 VideoWindow_NotifyOwnerMessage,
4655 VideoWindow_SetWindowPosition,
4656 VideoWindow_GetWindowPosition,
4657 VideoWindow_GetMinIdealImageSize,
4658 VideoWindow_GetMaxIdealImageSize,
4659 VideoWindow_GetRestorePosition,
4660 VideoWindow_HideCursor,
4661 VideoWindow_IsCursorHidden
4664 static struct filter_graph *impl_from_IMediaEventEx(IMediaEventEx *iface)
4666 return CONTAINING_RECORD(iface, struct filter_graph, IMediaEventEx_iface);
4669 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID iid, void **out)
4671 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4672 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
4675 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
4677 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4678 return IUnknown_AddRef(graph->outer_unk);
4681 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
4683 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4684 return IUnknown_Release(graph->outer_unk);
4687 /*** IDispatch methods ***/
4688 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *pctinfo)
4690 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4692 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
4694 return S_OK;
4697 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT iTInfo, LCID lcid,
4698 ITypeInfo **ppTInfo)
4700 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4702 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
4704 return S_OK;
4707 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID riid,
4708 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4710 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4712 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
4713 cNames, lcid, rgDispId);
4715 return S_OK;
4718 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID dispIdMember, REFIID riid,
4719 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4720 UINT *puArgErr)
4722 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4724 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
4725 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4727 return S_OK;
4730 /*** IMediaEvent methods ***/
4731 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *event)
4733 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4735 TRACE("graph %p, event %p.\n", graph, event);
4737 *event = (OAEVENT)graph->media_event_handle;
4738 return S_OK;
4741 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *code,
4742 LONG_PTR *param1, LONG_PTR *param2, LONG timeout)
4744 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4745 struct media_event *event;
4746 struct list *entry;
4748 TRACE("graph %p, code %p, param1 %p, param2 %p, timeout %d.\n", graph, code, param1, param2, timeout);
4750 *code = 0;
4752 if (WaitForSingleObject(graph->media_event_handle, timeout))
4753 return E_ABORT;
4755 EnterCriticalSection(&graph->cs);
4757 if (!(entry = list_head(&graph->media_events)))
4759 ResetEvent(graph->media_event_handle);
4760 LeaveCriticalSection(&graph->cs);
4761 return E_ABORT;
4763 event = LIST_ENTRY(entry, struct media_event, entry);
4764 list_remove(&event->entry);
4765 *code = event->code;
4766 *param1 = event->param1;
4767 *param2 = event->param2;
4768 free(event);
4770 LeaveCriticalSection(&graph->cs);
4771 return S_OK;
4774 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
4775 LONG *pEvCode)
4777 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4779 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
4781 if (This->state != State_Running)
4782 return VFW_E_WRONG_STATE;
4784 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
4786 *pEvCode = This->CompletionStatus;
4787 return S_OK;
4790 *pEvCode = 0;
4791 return E_ABORT;
4794 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
4796 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4798 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4800 if (lEvCode == EC_COMPLETE)
4801 This->HandleEcComplete = FALSE;
4802 else if (lEvCode == EC_REPAINT)
4803 This->HandleEcRepaint = FALSE;
4804 else if (lEvCode == EC_CLOCK_CHANGED)
4805 This->HandleEcClockChanged = FALSE;
4806 else
4807 return S_FALSE;
4809 return S_OK;
4812 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
4814 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4816 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4818 if (lEvCode == EC_COMPLETE)
4819 This->HandleEcComplete = TRUE;
4820 else if (lEvCode == EC_REPAINT)
4821 This->HandleEcRepaint = TRUE;
4822 else if (lEvCode == EC_CLOCK_CHANGED)
4823 This->HandleEcClockChanged = TRUE;
4824 else
4825 return S_FALSE;
4827 return S_OK;
4830 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG lEvCode,
4831 LONG_PTR lParam1, LONG_PTR lParam2)
4833 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4835 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
4837 return S_OK;
4840 /*** IMediaEventEx methods ***/
4841 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface,
4842 OAHWND window, LONG message, LONG_PTR lparam)
4844 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4846 TRACE("graph %p, window %#Ix, message %#x, lparam %#Ix.\n", graph, window, message, lparam);
4848 graph->media_event_window = (HWND)window;
4849 graph->media_event_message = message;
4850 graph->media_event_lparam = lparam;
4852 return S_OK;
4855 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG flags)
4857 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4859 TRACE("graph %p, flags %#x.\n", graph, flags);
4861 if (flags & ~AM_MEDIAEVENT_NONOTIFY)
4863 WARN("Invalid flags %#x, returning E_INVALIDARG.\n", flags);
4864 return E_INVALIDARG;
4867 graph->media_events_disabled = flags;
4869 if (flags)
4871 flush_media_events(graph);
4872 ResetEvent(graph->media_event_handle);
4875 return S_OK;
4878 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *flags)
4880 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4882 TRACE("graph %p, flags %p.\n", graph, flags);
4884 if (!flags)
4885 return E_POINTER;
4887 *flags = graph->media_events_disabled;
4889 return S_OK;
4893 static const IMediaEventExVtbl IMediaEventEx_VTable =
4895 MediaEvent_QueryInterface,
4896 MediaEvent_AddRef,
4897 MediaEvent_Release,
4898 MediaEvent_GetTypeInfoCount,
4899 MediaEvent_GetTypeInfo,
4900 MediaEvent_GetIDsOfNames,
4901 MediaEvent_Invoke,
4902 MediaEvent_GetEventHandle,
4903 MediaEvent_GetEvent,
4904 MediaEvent_WaitForCompletion,
4905 MediaEvent_CancelDefaultHandling,
4906 MediaEvent_RestoreDefaultHandling,
4907 MediaEvent_FreeEventParams,
4908 MediaEvent_SetNotifyWindow,
4909 MediaEvent_SetNotifyFlags,
4910 MediaEvent_GetNotifyFlags
4914 static struct filter_graph *impl_from_IMediaFilter(IMediaFilter *iface)
4916 return CONTAINING_RECORD(iface, struct filter_graph, IMediaFilter_iface);
4919 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID iid, void **out)
4921 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4923 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
4926 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
4928 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4930 return IUnknown_AddRef(graph->outer_unk);
4933 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
4935 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4937 return IUnknown_Release(graph->outer_unk);
4940 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
4942 FIXME("(%p): stub\n", pClassID);
4944 return E_NOTIMPL;
4947 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
4949 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4950 HRESULT hr = S_OK, filter_hr;
4951 struct filter *filter;
4952 TP_WORK *work;
4954 TRACE("graph %p.\n", graph);
4956 EnterCriticalSection(&graph->cs);
4958 if (graph->state == State_Stopped)
4960 LeaveCriticalSection(&graph->cs);
4961 return S_OK;
4964 sort_filters(graph);
4966 if (graph->state == State_Running)
4968 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
4970 filter_hr = IBaseFilter_Pause(filter->filter);
4971 if (hr == S_OK)
4972 hr = filter_hr;
4976 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
4978 filter_hr = IBaseFilter_Stop(filter->filter);
4979 if (hr == S_OK)
4980 hr = filter_hr;
4983 graph->state = State_Stopped;
4984 graph->needs_async_run = 0;
4985 work = graph->async_run_work;
4986 graph->got_ec_complete = 0;
4988 /* Update the current position, probably to synchronize multiple streams. */
4989 IMediaSeeking_SetPositions(&graph->IMediaSeeking_iface, &graph->current_pos,
4990 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
4992 LeaveCriticalSection(&graph->cs);
4994 if (work)
4995 WaitForThreadpoolWorkCallbacks(work, TRUE);
4997 return hr;
5000 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5002 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5003 HRESULT hr = S_OK, filter_hr;
5004 struct filter *filter;
5005 TP_WORK *work;
5007 TRACE("graph %p.\n", graph);
5009 EnterCriticalSection(&graph->cs);
5011 if (graph->state == State_Paused)
5013 LeaveCriticalSection(&graph->cs);
5014 return S_OK;
5017 sort_filters(graph);
5018 update_render_count(graph);
5020 if (graph->defaultclock && !graph->refClock)
5021 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
5023 if (graph->state == State_Running && graph->refClock)
5025 REFERENCE_TIME time;
5026 IReferenceClock_GetTime(graph->refClock, &time);
5027 graph->stream_elapsed += time - graph->stream_start;
5028 graph->current_pos += graph->stream_elapsed;
5031 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5033 filter_hr = IBaseFilter_Pause(filter->filter);
5034 if (hr == S_OK)
5035 hr = filter_hr;
5038 graph->state = State_Paused;
5039 graph->needs_async_run = 0;
5040 work = graph->async_run_work;
5042 LeaveCriticalSection(&graph->cs);
5044 if (work)
5045 WaitForThreadpoolWorkCallbacks(work, TRUE);
5047 return hr;
5050 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME start)
5052 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5053 HRESULT hr;
5055 TRACE("graph %p, start %s.\n", graph, debugstr_time(start));
5057 EnterCriticalSection(&graph->cs);
5059 if (graph->state == State_Running)
5061 LeaveCriticalSection(&graph->cs);
5062 return S_OK;
5065 sort_filters(graph);
5067 hr = graph_start(graph, start);
5069 graph->state = State_Running;
5070 graph->needs_async_run = 0;
5072 LeaveCriticalSection(&graph->cs);
5073 return hr;
5076 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD timeout, FILTER_STATE *state)
5078 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5079 DWORD end = GetTickCount() + timeout;
5080 FILTER_STATE expect_state;
5081 HRESULT hr;
5083 TRACE("graph %p, timeout %u, state %p.\n", graph, timeout, state);
5085 if (!state)
5086 return E_POINTER;
5088 /* Thread safety is a little tricky here. GetState() shouldn't block other
5089 * functions from being called on the filter graph. However, we can't just
5090 * call IBaseFilter::GetState() in one loop and drop the lock on every
5091 * iteration, since the filter list might change beneath us. So instead we
5092 * do what native does, and poll for it every 10 ms. */
5094 EnterCriticalSection(&graph->cs);
5095 *state = graph->state;
5096 expect_state = graph->needs_async_run ? State_Paused : graph->state;
5098 for (;;)
5100 IBaseFilter *async_filter = NULL;
5101 FILTER_STATE filter_state;
5102 struct filter *filter;
5104 hr = S_OK;
5106 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5108 HRESULT filter_hr = IBaseFilter_GetState(filter->filter, 0, &filter_state);
5110 TRACE("Filter %p returned hr %#x, state %u.\n", filter->filter, filter_hr, filter_state);
5112 if (filter_hr == VFW_S_STATE_INTERMEDIATE)
5113 async_filter = filter->filter;
5115 if (hr == S_OK && filter_hr == VFW_S_STATE_INTERMEDIATE)
5116 hr = VFW_S_STATE_INTERMEDIATE;
5117 else if (filter_hr != S_OK && filter_hr != VFW_S_STATE_INTERMEDIATE)
5118 hr = filter_hr;
5120 if (hr == S_OK && filter_state == State_Paused && graph->state != State_Paused)
5122 async_filter = filter->filter;
5123 hr = VFW_S_STATE_INTERMEDIATE;
5125 else if (filter_state != graph->state && filter_state != State_Paused)
5126 hr = E_FAIL;
5128 if (filter_state != expect_state)
5129 ERR("Filter %p reported incorrect state %u (expected %u).\n",
5130 filter->filter, filter_state, expect_state);
5133 LeaveCriticalSection(&graph->cs);
5135 if (hr != VFW_S_STATE_INTERMEDIATE || (timeout != INFINITE && GetTickCount() >= end))
5136 break;
5138 IBaseFilter_GetState(async_filter, 10, &filter_state);
5140 EnterCriticalSection(&graph->cs);
5143 TRACE("Returning %#x, state %u.\n", hr, *state);
5144 return hr;
5147 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5149 struct filter_graph *This = impl_from_IMediaFilter(iface);
5150 struct filter *filter;
5151 HRESULT hr = S_OK;
5153 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
5155 EnterCriticalSection(&This->cs);
5157 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
5159 hr = IBaseFilter_SetSyncSource(filter->filter, pClock);
5160 if (FAILED(hr))
5161 break;
5164 if (FAILED(hr))
5166 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
5167 IBaseFilter_SetSyncSource(filter->filter, This->refClock);
5169 else
5171 if (This->refClock)
5172 IReferenceClock_Release(This->refClock);
5173 This->refClock = pClock;
5174 if (This->refClock)
5175 IReferenceClock_AddRef(This->refClock);
5176 This->defaultclock = FALSE;
5178 if (This->HandleEcClockChanged)
5180 IMediaEventSink *pEventSink;
5181 HRESULT eshr;
5183 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (void **)&pEventSink);
5184 if (SUCCEEDED(eshr))
5186 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5187 IMediaEventSink_Release(pEventSink);
5192 LeaveCriticalSection(&This->cs);
5194 return hr;
5197 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5199 struct filter_graph *This = impl_from_IMediaFilter(iface);
5201 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
5203 if (!ppClock)
5204 return E_POINTER;
5206 EnterCriticalSection(&This->cs);
5208 *ppClock = This->refClock;
5209 if (*ppClock)
5210 IReferenceClock_AddRef(*ppClock);
5212 LeaveCriticalSection(&This->cs);
5214 return S_OK;
5217 static const IMediaFilterVtbl IMediaFilter_VTable =
5219 MediaFilter_QueryInterface,
5220 MediaFilter_AddRef,
5221 MediaFilter_Release,
5222 MediaFilter_GetClassID,
5223 MediaFilter_Stop,
5224 MediaFilter_Pause,
5225 MediaFilter_Run,
5226 MediaFilter_GetState,
5227 MediaFilter_SetSyncSource,
5228 MediaFilter_GetSyncSource
5231 static struct filter_graph *impl_from_IMediaEventSink(IMediaEventSink *iface)
5233 return CONTAINING_RECORD(iface, struct filter_graph, IMediaEventSink_iface);
5236 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID iid, void **out)
5238 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5240 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5243 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5245 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5247 return IUnknown_AddRef(graph->outer_unk);
5250 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5252 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5254 return IUnknown_Release(graph->outer_unk);
5257 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG code,
5258 LONG_PTR param1, LONG_PTR param2)
5260 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5262 TRACE("graph %p, code %#x, param1 %#Ix, param2 %#Ix.\n", graph, code, param1, param2);
5264 EnterCriticalSection(&graph->cs);
5266 if (code == EC_COMPLETE && graph->HandleEcComplete)
5268 if (++graph->EcCompleteCount == graph->nRenderers)
5270 if (graph->media_events_disabled)
5271 SetEvent(graph->media_event_handle);
5272 else
5273 queue_media_event(graph, EC_COMPLETE, S_OK, 0);
5274 graph->CompletionStatus = EC_COMPLETE;
5275 graph->got_ec_complete = 1;
5276 SetEvent(graph->hEventCompletion);
5279 else if ((code == EC_REPAINT) && graph->HandleEcRepaint)
5281 FIXME("EC_REPAINT is not handled.\n");
5283 else if (!graph->media_events_disabled)
5285 queue_media_event(graph, code, param1, param2);
5288 LeaveCriticalSection(&graph->cs);
5289 return S_OK;
5292 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5294 MediaEventSink_QueryInterface,
5295 MediaEventSink_AddRef,
5296 MediaEventSink_Release,
5297 MediaEventSink_Notify
5300 static struct filter_graph *impl_from_IGraphConfig(IGraphConfig *iface)
5302 return CONTAINING_RECORD(iface, struct filter_graph, IGraphConfig_iface);
5305 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID iid, void **out)
5307 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5309 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5312 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5314 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5316 return IUnknown_AddRef(graph->outer_unk);
5319 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5321 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5323 return IUnknown_Release(graph->outer_unk);
5326 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *pOutputPin, IPin *pInputPin,
5327 const AM_MEDIA_TYPE *pmtFirstConnection, IBaseFilter *pUsingFilter, HANDLE hAbortEvent,
5328 DWORD dwFlags)
5330 struct filter_graph *This = impl_from_IGraphConfig(iface);
5332 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5333 strmbase_dump_media_type(pmtFirstConnection);
5335 return E_NOTIMPL;
5338 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface, IGraphConfigCallback *pCallback,
5339 void *pvContext, DWORD dwFlags, HANDLE hAbortEvent)
5341 struct filter_graph *This = impl_from_IGraphConfig(iface);
5342 HRESULT hr;
5344 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5346 if (hAbortEvent)
5347 FIXME("The parameter hAbortEvent is not handled!\n");
5349 EnterCriticalSection(&This->cs);
5351 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5353 LeaveCriticalSection(&This->cs);
5355 return hr;
5358 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5360 struct filter_graph *This = impl_from_IGraphConfig(iface);
5362 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5364 return E_NOTIMPL;
5367 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5369 struct filter_graph *This = impl_from_IGraphConfig(iface);
5371 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5373 return E_NOTIMPL;
5376 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5378 struct filter_graph *This = impl_from_IGraphConfig(iface);
5380 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5382 return E_NOTIMPL;
5385 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5387 struct filter_graph *This = impl_from_IGraphConfig(iface);
5389 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5391 return E_NOTIMPL;
5394 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5395 IPinConnection *pConnection, HANDLE hEventAbort)
5397 struct filter_graph *This = impl_from_IGraphConfig(iface);
5399 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5401 return E_NOTIMPL;
5404 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5405 DWORD dwFlags)
5407 struct filter_graph *This = impl_from_IGraphConfig(iface);
5409 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5411 return E_NOTIMPL;
5414 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5415 DWORD *dwFlags)
5417 struct filter_graph *This = impl_from_IGraphConfig(iface);
5419 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5421 return E_NOTIMPL;
5424 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *pFilter,
5425 DWORD dwFlags)
5427 struct filter_graph *This = impl_from_IGraphConfig(iface);
5429 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5431 return E_NOTIMPL;
5434 static const IGraphConfigVtbl IGraphConfig_VTable =
5436 GraphConfig_QueryInterface,
5437 GraphConfig_AddRef,
5438 GraphConfig_Release,
5439 GraphConfig_Reconnect,
5440 GraphConfig_Reconfigure,
5441 GraphConfig_AddFilterToCache,
5442 GraphConfig_EnumCacheFilter,
5443 GraphConfig_RemoveFilterFromCache,
5444 GraphConfig_GetStartTime,
5445 GraphConfig_PushThroughData,
5446 GraphConfig_SetFilterFlags,
5447 GraphConfig_GetFilterFlags,
5448 GraphConfig_RemoveFilterEx
5451 static struct filter_graph *impl_from_IGraphVersion(IGraphVersion *iface)
5453 return CONTAINING_RECORD(iface, struct filter_graph, IGraphVersion_iface);
5456 static HRESULT WINAPI GraphVersion_QueryInterface(IGraphVersion *iface, REFIID iid, void **out)
5458 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5460 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5463 static ULONG WINAPI GraphVersion_AddRef(IGraphVersion *iface)
5465 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5467 return IUnknown_AddRef(graph->outer_unk);
5470 static ULONG WINAPI GraphVersion_Release(IGraphVersion *iface)
5472 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5474 return IUnknown_Release(graph->outer_unk);
5477 static HRESULT WINAPI GraphVersion_QueryVersion(IGraphVersion *iface, LONG *pVersion)
5479 struct filter_graph *This = impl_from_IGraphVersion(iface);
5481 if(!pVersion)
5482 return E_POINTER;
5484 TRACE("(%p)->(%p): current version %i\n", This, pVersion, This->version);
5486 *pVersion = This->version;
5487 return S_OK;
5490 static const IGraphVersionVtbl IGraphVersion_VTable =
5492 GraphVersion_QueryInterface,
5493 GraphVersion_AddRef,
5494 GraphVersion_Release,
5495 GraphVersion_QueryVersion,
5498 static struct filter_graph *impl_from_IVideoFrameStep(IVideoFrameStep *iface)
5500 return CONTAINING_RECORD(iface, struct filter_graph, IVideoFrameStep_iface);
5503 static HRESULT WINAPI VideoFrameStep_QueryInterface(IVideoFrameStep *iface, REFIID iid, void **out)
5505 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5506 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5509 static ULONG WINAPI VideoFrameStep_AddRef(IVideoFrameStep *iface)
5511 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5512 return IUnknown_AddRef(graph->outer_unk);
5515 static ULONG WINAPI VideoFrameStep_Release(IVideoFrameStep *iface)
5517 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5518 return IUnknown_Release(graph->outer_unk);
5521 static HRESULT WINAPI VideoFrameStep_Step(IVideoFrameStep *iface, DWORD frame_count, IUnknown *filter)
5523 FIXME("iface %p, frame_count %u, filter %p, stub!\n", iface, frame_count, filter);
5524 return E_NOTIMPL;
5527 static HRESULT WINAPI VideoFrameStep_CanStep(IVideoFrameStep *iface, LONG multiple, IUnknown *filter)
5529 FIXME("iface %p, multiple %d, filter %p, stub!\n", iface, multiple, filter);
5530 return E_NOTIMPL;
5533 static HRESULT WINAPI VideoFrameStep_CancelStep(IVideoFrameStep *iface)
5535 FIXME("iface %p, stub!\n", iface);
5536 return E_NOTIMPL;
5539 static const IVideoFrameStepVtbl VideoFrameStep_vtbl =
5541 VideoFrameStep_QueryInterface,
5542 VideoFrameStep_AddRef,
5543 VideoFrameStep_Release,
5544 VideoFrameStep_Step,
5545 VideoFrameStep_CanStep,
5546 VideoFrameStep_CancelStep
5549 static const IUnknownVtbl IInner_VTable =
5551 FilterGraphInner_QueryInterface,
5552 FilterGraphInner_AddRef,
5553 FilterGraphInner_Release
5556 static HRESULT filter_graph_common_create(IUnknown *outer, IUnknown **out, BOOL threaded)
5558 struct filter_graph *object;
5559 HRESULT hr;
5561 *out = NULL;
5563 if (!(object = calloc(1, sizeof(*object))))
5564 return E_OUTOFMEMORY;
5566 object->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5567 object->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5568 object->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5569 object->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5570 object->IGraphVersion_iface.lpVtbl = &IGraphVersion_VTable;
5571 object->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5572 object->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5573 object->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5574 object->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5575 object->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5576 object->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5577 object->IObjectWithSite_iface.lpVtbl = &IObjectWithSite_VTable;
5578 object->IUnknown_inner.lpVtbl = &IInner_VTable;
5579 object->IVideoFrameStep_iface.lpVtbl = &VideoFrameStep_vtbl;
5580 object->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5581 object->ref = 1;
5582 object->outer_unk = outer ? outer : &object->IUnknown_inner;
5584 if (FAILED(hr = CoCreateInstance(&CLSID_FilterMapper2, object->outer_unk,
5585 CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&object->punkFilterMapper2)))
5587 ERR("Failed to create filter mapper, hr %#x.\n", hr);
5588 free(object);
5589 return hr;
5592 InitializeCriticalSection(&object->cs);
5593 object->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": filter_graph.cs");
5595 object->defaultclock = TRUE;
5597 object->media_event_handle = CreateEventW(NULL, TRUE, FALSE, NULL);
5598 list_init(&object->media_events);
5599 list_init(&object->filters);
5600 object->HandleEcClockChanged = TRUE;
5601 object->HandleEcComplete = TRUE;
5602 object->HandleEcRepaint = TRUE;
5603 object->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5605 object->name_index = 1;
5606 object->timeformatseek = TIME_FORMAT_MEDIA_TIME;
5608 if (threaded)
5610 object->message_thread_ret = CreateEventW(NULL, FALSE, FALSE, NULL);
5611 object->message_thread = CreateThread(NULL, 0, message_thread_run, object, 0, &object->message_thread_id);
5612 WaitForSingleObject(object->message_thread_ret, INFINITE);
5614 else
5615 object->message_thread = NULL;
5617 TRACE("Created %sthreaded filter graph %p.\n", threaded ? "" : "non-", object);
5618 *out = &object->IUnknown_inner;
5619 return S_OK;
5622 HRESULT filter_graph_create(IUnknown *outer, IUnknown **out)
5624 return filter_graph_common_create(outer, out, TRUE);
5627 HRESULT filter_graph_no_thread_create(IUnknown *outer, IUnknown **out)
5629 return filter_graph_common_create(outer, out, FALSE);