riched20/tests: Don't cast NULL.
[wine.git] / dlls / quartz / filtergraph.c
blob47b9da9510bac4cabb57c33106f691335336a919
1 /* DirectShow FilterGraph object (QUARTZ.DLL)
3 * Copyright 2002 Lionel Ulmer
4 * Copyright 2004 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <assert.h>
22 #include <stdarg.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "shlwapi.h"
31 #include "dshow.h"
32 #include "wine/debug.h"
33 #include "quartz_private.h"
34 #include "ole2.h"
35 #include "olectl.h"
36 #include "strmif.h"
37 #include "vfwmsgs.h"
38 #include "evcode.h"
39 #include "wine/heap.h"
40 #include "wine/list.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
45 struct media_event
47 struct list entry;
48 LONG code;
49 LONG_PTR param1, param2;
52 #define MAX_ITF_CACHE_ENTRIES 3
53 typedef struct _ITF_CACHE_ENTRY {
54 const IID* riid;
55 IBaseFilter* filter;
56 IUnknown* iface;
57 } ITF_CACHE_ENTRY;
59 struct filter
61 struct list entry;
62 IBaseFilter *filter;
63 IMediaSeeking *seeking;
64 WCHAR *name;
65 BOOL sorting;
68 struct filter_graph
70 IUnknown IUnknown_inner;
71 IFilterGraph2 IFilterGraph2_iface;
72 IMediaControl IMediaControl_iface;
73 IMediaSeeking IMediaSeeking_iface;
74 IBasicAudio IBasicAudio_iface;
75 IBasicVideo2 IBasicVideo2_iface;
76 IVideoWindow IVideoWindow_iface;
77 IMediaEventEx IMediaEventEx_iface;
78 IMediaFilter IMediaFilter_iface;
79 IMediaEventSink IMediaEventSink_iface;
80 IGraphConfig IGraphConfig_iface;
81 IMediaPosition IMediaPosition_iface;
82 IObjectWithSite IObjectWithSite_iface;
83 IGraphVersion IGraphVersion_iface;
84 /* IAMGraphStreams */
85 /* IAMStats */
86 /* IFilterChain */
87 /* IFilterMapper2 */
88 /* IQueueCommand */
89 /* IRegisterServiceProvider */
90 /* IResourceManager */
91 /* IServiceProvider */
92 IVideoFrameStep IVideoFrameStep_iface;
94 IUnknown *outer_unk;
95 LONG ref;
96 IUnknown *punkFilterMapper2;
98 struct list filters;
99 unsigned int name_index;
101 OAFilterState state;
102 TP_WORK *async_run_work;
104 IReferenceClock *refClock;
105 IBaseFilter *refClockProvider;
107 /* We may indirectly wait for streaming threads while holding graph->cs in
108 * IMediaFilter::Stop() or IMediaSeeking::SetPositions(). Since streaming
109 * threads call IMediaEventSink::Notify() to queue EC_COMPLETE, we must
110 * use a separate lock to avoid them deadlocking on graph->cs. */
111 CRITICAL_SECTION event_cs;
112 struct list media_events;
113 HANDLE media_event_handle;
114 HWND media_event_window;
115 UINT media_event_message;
116 LPARAM media_event_lparam;
117 HANDLE hEventCompletion;
118 int CompletionStatus;
119 int nRenderers;
120 int EcCompleteCount;
121 int HandleEcComplete;
122 int HandleEcRepaint;
123 int HandleEcClockChanged;
124 unsigned int got_ec_complete : 1;
125 unsigned int media_events_disabled : 1;
127 CRITICAL_SECTION cs;
128 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
129 int nItfCacheEntries;
130 BOOL defaultclock;
131 GUID timeformatseek;
132 IUnknown *pSite;
133 LONG version;
135 HANDLE message_thread, message_thread_ret;
136 DWORD message_thread_id;
138 /* Respectively: the last timestamp at which we started streaming, and the
139 * current offset within the stream. */
140 REFERENCE_TIME stream_start, stream_elapsed;
141 REFERENCE_TIME stream_stop;
142 LONGLONG current_pos;
144 unsigned int needs_async_run : 1;
147 struct enum_filters
149 IEnumFilters IEnumFilters_iface;
150 LONG ref;
151 struct filter_graph *graph;
152 LONG version;
153 struct list *cursor;
156 static HRESULT create_enum_filters(struct filter_graph *graph, struct list *cursor, IEnumFilters **out);
158 static inline struct enum_filters *impl_from_IEnumFilters(IEnumFilters *iface)
160 return CONTAINING_RECORD(iface, struct enum_filters, IEnumFilters_iface);
163 static HRESULT WINAPI EnumFilters_QueryInterface(IEnumFilters *iface, REFIID iid, void **out)
165 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
166 TRACE("enum_filters %p, iid %s, out %p.\n", enum_filters, qzdebugstr_guid(iid), out);
168 if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IEnumFilters))
170 IEnumFilters_AddRef(*out = iface);
171 return S_OK;
174 WARN("%s not implemented, returning E_NOINTERFACE.\n", qzdebugstr_guid(iid));
175 *out = NULL;
176 return E_NOINTERFACE;
179 static ULONG WINAPI EnumFilters_AddRef(IEnumFilters *iface)
181 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
182 ULONG ref = InterlockedIncrement(&enum_filters->ref);
184 TRACE("%p increasing refcount to %u.\n", enum_filters, ref);
186 return ref;
189 static ULONG WINAPI EnumFilters_Release(IEnumFilters *iface)
191 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
192 ULONG ref = InterlockedDecrement(&enum_filters->ref);
194 TRACE("%p decreasing refcount to %u.\n", enum_filters, ref);
196 if (!ref)
198 IUnknown_Release(enum_filters->graph->outer_unk);
199 heap_free(enum_filters);
202 return ref;
205 static HRESULT WINAPI EnumFilters_Next(IEnumFilters *iface, ULONG count,
206 IBaseFilter **filters, ULONG *fetched)
208 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
209 unsigned int i = 0;
211 TRACE("enum_filters %p, count %u, filters %p, fetched %p.\n",
212 enum_filters, count, filters, fetched);
214 if (enum_filters->version != enum_filters->graph->version)
215 return VFW_E_ENUM_OUT_OF_SYNC;
217 if (!filters)
218 return E_POINTER;
220 for (i = 0; i < count; ++i)
222 struct filter *filter = LIST_ENTRY(enum_filters->cursor, struct filter, entry);
224 if (!enum_filters->cursor)
225 break;
227 IBaseFilter_AddRef(filters[i] = filter->filter);
228 enum_filters->cursor = list_next(&enum_filters->graph->filters, enum_filters->cursor);
231 if (fetched)
232 *fetched = i;
234 return (i == count) ? S_OK : S_FALSE;
237 static HRESULT WINAPI EnumFilters_Skip(IEnumFilters *iface, ULONG count)
239 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
241 TRACE("enum_filters %p, count %u.\n", enum_filters, count);
243 if (enum_filters->version != enum_filters->graph->version)
244 return VFW_E_ENUM_OUT_OF_SYNC;
246 if (!enum_filters->cursor)
247 return E_INVALIDARG;
249 while (count--)
251 if (!(enum_filters->cursor = list_next(&enum_filters->graph->filters, enum_filters->cursor)))
252 return count ? S_FALSE : S_OK;
255 return S_OK;
258 static HRESULT WINAPI EnumFilters_Reset(IEnumFilters *iface)
260 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
262 TRACE("enum_filters %p.\n", enum_filters);
264 enum_filters->cursor = list_head(&enum_filters->graph->filters);
265 enum_filters->version = enum_filters->graph->version;
266 return S_OK;
269 static HRESULT WINAPI EnumFilters_Clone(IEnumFilters *iface, IEnumFilters **out)
271 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
273 TRACE("enum_filters %p, out %p.\n", enum_filters, out);
275 return create_enum_filters(enum_filters->graph, enum_filters->cursor, out);
278 static const IEnumFiltersVtbl EnumFilters_vtbl =
280 EnumFilters_QueryInterface,
281 EnumFilters_AddRef,
282 EnumFilters_Release,
283 EnumFilters_Next,
284 EnumFilters_Skip,
285 EnumFilters_Reset,
286 EnumFilters_Clone,
289 static HRESULT create_enum_filters(struct filter_graph *graph, struct list *cursor, IEnumFilters **out)
291 struct enum_filters *enum_filters;
293 if (!(enum_filters = heap_alloc(sizeof(*enum_filters))))
294 return E_OUTOFMEMORY;
296 enum_filters->IEnumFilters_iface.lpVtbl = &EnumFilters_vtbl;
297 enum_filters->ref = 1;
298 enum_filters->cursor = cursor;
299 enum_filters->graph = graph;
300 IUnknown_AddRef(graph->outer_unk);
301 enum_filters->version = graph->version;
303 *out = &enum_filters->IEnumFilters_iface;
304 return S_OK;
307 static BOOL queue_media_event(struct filter_graph *graph, LONG code,
308 LONG_PTR param1, LONG_PTR param2)
310 struct media_event *event;
312 if (!(event = malloc(sizeof(*event))))
313 return FALSE;
315 event->code = code;
316 event->param1 = param1;
317 event->param2 = param2;
318 list_add_tail(&graph->media_events, &event->entry);
320 SetEvent(graph->media_event_handle);
321 if (graph->media_event_window)
322 PostMessageW(graph->media_event_window, graph->media_event_message, 0, graph->media_event_lparam);
324 return TRUE;
327 static void flush_media_events(struct filter_graph *graph)
329 struct list *cursor;
331 while ((cursor = list_head(&graph->media_events)))
333 struct media_event *event = LIST_ENTRY(cursor, struct media_event, entry);
335 list_remove(&event->entry);
336 free(event);
340 static struct filter_graph *impl_from_IUnknown(IUnknown *iface)
342 return CONTAINING_RECORD(iface, struct filter_graph, IUnknown_inner);
345 static HRESULT WINAPI FilterGraphInner_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObj)
347 struct filter_graph *This = impl_from_IUnknown(iface);
348 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObj);
350 if (IsEqualGUID(&IID_IUnknown, riid)) {
351 *ppvObj = &This->IUnknown_inner;
352 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
353 } else if (IsEqualGUID(&IID_IFilterGraph, riid) ||
354 IsEqualGUID(&IID_IFilterGraph2, riid) ||
355 IsEqualGUID(&IID_IGraphBuilder, riid)) {
356 *ppvObj = &This->IFilterGraph2_iface;
357 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj);
358 } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
359 *ppvObj = &This->IMediaControl_iface;
360 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj);
361 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
362 *ppvObj = &This->IMediaSeeking_iface;
363 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
364 } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
365 *ppvObj = &This->IBasicAudio_iface;
366 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj);
367 } else if (IsEqualGUID(&IID_IBasicVideo, riid) ||
368 IsEqualGUID(&IID_IBasicVideo2, riid)) {
369 *ppvObj = &This->IBasicVideo2_iface;
370 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj);
371 } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
372 *ppvObj = &This->IVideoWindow_iface;
373 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj);
374 } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
375 IsEqualGUID(&IID_IMediaEventEx, riid)) {
376 *ppvObj = &This->IMediaEventEx_iface;
377 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
378 } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
379 IsEqualGUID(&IID_IPersist, riid)) {
380 *ppvObj = &This->IMediaFilter_iface;
381 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj);
382 } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
383 *ppvObj = &This->IMediaEventSink_iface;
384 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj);
385 } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
386 *ppvObj = &This->IGraphConfig_iface;
387 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
388 } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
389 *ppvObj = &This->IMediaPosition_iface;
390 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj);
391 } else if (IsEqualGUID(&IID_IObjectWithSite, riid)) {
392 *ppvObj = &This->IObjectWithSite_iface;
393 TRACE(" returning IObjectWithSite interface (%p)\n", *ppvObj);
394 } else if (IsEqualGUID(&IID_IFilterMapper, riid)) {
395 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj);
396 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
397 } else if (IsEqualGUID(&IID_IFilterMapper2, riid)) {
398 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
399 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
400 } else if (IsEqualGUID(&IID_IFilterMapper3, riid)) {
401 TRACE(" returning IFilterMapper3 interface from aggregated filtermapper (%p)\n", *ppvObj);
402 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
403 } else if (IsEqualGUID(&IID_IGraphVersion, riid)) {
404 *ppvObj = &This->IGraphVersion_iface;
405 TRACE(" returning IGraphVersion interface (%p)\n", *ppvObj);
406 } else if (IsEqualGUID(&IID_IVideoFrameStep, riid)) {
407 *ppvObj = &This->IVideoFrameStep_iface;
408 TRACE(" returning IVideoFrameStep interface (%p)\n", *ppvObj);
409 } else {
410 *ppvObj = NULL;
411 FIXME("unknown interface %s\n", debugstr_guid(riid));
412 return E_NOINTERFACE;
415 IUnknown_AddRef((IUnknown *)*ppvObj);
416 return S_OK;
419 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown *iface)
421 struct filter_graph *This = impl_from_IUnknown(iface);
422 ULONG ref = InterlockedIncrement(&This->ref);
424 TRACE("(%p)->(): new ref = %d\n", This, ref);
426 return ref;
429 static ULONG WINAPI FilterGraphInner_Release(IUnknown *iface)
431 struct filter_graph *This = impl_from_IUnknown(iface);
432 ULONG ref = InterlockedDecrement(&This->ref);
433 struct list *cursor;
435 TRACE("(%p)->(): new ref = %d\n", This, ref);
437 if (ref == 0) {
438 int i;
440 This->ref = 1; /* guard against reentrancy (aggregation). */
442 IMediaControl_Stop(&This->IMediaControl_iface);
444 while ((cursor = list_head(&This->filters)))
446 struct filter *filter = LIST_ENTRY(cursor, struct filter, entry);
448 IFilterGraph2_RemoveFilter(&This->IFilterGraph2_iface, filter->filter);
451 if (This->refClock)
452 IReferenceClock_Release(This->refClock);
454 for (i = 0; i < This->nItfCacheEntries; i++)
456 if (This->ItfCacheEntries[i].iface)
457 IUnknown_Release(This->ItfCacheEntries[i].iface);
460 IUnknown_Release(This->punkFilterMapper2);
462 if (This->pSite) IUnknown_Release(This->pSite);
464 flush_media_events(This);
465 CloseHandle(This->media_event_handle);
467 This->cs.DebugInfo->Spare[0] = 0;
468 if (This->message_thread)
470 PostThreadMessageW(This->message_thread_id, WM_USER + 1, 0, 0);
471 WaitForSingleObject(This->message_thread, INFINITE);
472 CloseHandle(This->message_thread);
473 CloseHandle(This->message_thread_ret);
475 DeleteCriticalSection(&This->event_cs);
476 DeleteCriticalSection(&This->cs);
477 free(This);
479 return ref;
482 static struct filter_graph *impl_from_IFilterGraph2(IFilterGraph2 *iface)
484 return CONTAINING_RECORD(iface, struct filter_graph, IFilterGraph2_iface);
487 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface, REFIID iid, void **out)
489 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
490 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
493 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface)
495 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
496 return IUnknown_AddRef(graph->outer_unk);
499 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface)
501 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
502 return IUnknown_Release(graph->outer_unk);
505 static IBaseFilter *find_filter_by_name(struct filter_graph *graph, const WCHAR *name)
507 struct filter *filter;
509 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
511 if (!wcscmp(filter->name, name))
512 return filter->filter;
515 return NULL;
518 static BOOL has_output_pins(IBaseFilter *filter)
520 IEnumPins *enumpins;
521 PIN_DIRECTION dir;
522 IPin *pin;
524 if (FAILED(IBaseFilter_EnumPins(filter, &enumpins)))
525 return FALSE;
527 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
529 IPin_QueryDirection(pin, &dir);
530 IPin_Release(pin);
531 if (dir == PINDIR_OUTPUT)
533 IEnumPins_Release(enumpins);
534 return TRUE;
538 IEnumPins_Release(enumpins);
539 return FALSE;
542 static void update_seeking(struct filter *filter)
544 IMediaSeeking *seeking;
546 if (!filter->seeking)
548 /* The Legend of Heroes: Trails of Cold Steel II destroys its filter when
549 * its IMediaSeeking interface is released, so cache the interface instead
550 * of querying for it every time.
551 * Some filters (e.g. MediaStreamFilter) can become seekable when they are
552 * already in the graph, so always try to query IMediaSeeking if it's not
553 * cached yet. */
554 if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IMediaSeeking, (void **)&seeking)))
556 if (IMediaSeeking_IsFormatSupported(seeking, &TIME_FORMAT_MEDIA_TIME) == S_OK)
557 filter->seeking = seeking;
558 else
559 IMediaSeeking_Release(seeking);
564 static BOOL is_renderer(struct filter *filter)
566 IMediaPosition *media_position;
567 IAMFilterMiscFlags *flags;
568 BOOL ret = FALSE;
570 if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IAMFilterMiscFlags, (void **)&flags)))
572 if (IAMFilterMiscFlags_GetMiscFlags(flags) & AM_FILTER_MISC_FLAGS_IS_RENDERER)
573 ret = TRUE;
574 IAMFilterMiscFlags_Release(flags);
576 else if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IMediaPosition, (void **)&media_position)))
578 if (!has_output_pins(filter->filter))
579 ret = TRUE;
580 IMediaPosition_Release(media_position);
582 else
584 update_seeking(filter);
585 if (filter->seeking && !has_output_pins(filter->filter))
586 ret = TRUE;
588 return ret;
591 /*** IFilterGraph methods ***/
592 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface,
593 IBaseFilter *filter, const WCHAR *name)
595 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
596 BOOL duplicate_name = FALSE;
597 struct filter *entry;
598 unsigned int i;
599 HRESULT hr;
601 TRACE("graph %p, filter %p, name %s.\n", graph, filter, debugstr_w(name));
603 if (!filter)
604 return E_POINTER;
606 if (!(entry = heap_alloc(sizeof(*entry))))
607 return E_OUTOFMEMORY;
609 if (!(entry->name = CoTaskMemAlloc((name ? wcslen(name) + 6 : 5) * sizeof(WCHAR))))
611 heap_free(entry);
612 return E_OUTOFMEMORY;
615 if (name && find_filter_by_name(graph, name))
616 duplicate_name = TRUE;
618 if (!name || duplicate_name)
620 for (i = 0; i < 10000 ; ++i)
622 if (name)
623 swprintf(entry->name, name ? wcslen(name) + 6 : 5, L"%s %04u", name, graph->name_index);
624 else
625 swprintf(entry->name, name ? wcslen(name) + 6 : 5, L"%04u", graph->name_index);
627 graph->name_index = (graph->name_index + 1) % 10000;
629 if (!find_filter_by_name(graph, entry->name))
630 break;
633 if (i == 10000)
635 CoTaskMemFree(entry->name);
636 heap_free(entry);
637 return VFW_E_DUPLICATE_NAME;
640 else
641 wcscpy(entry->name, name);
643 if (FAILED(hr = IBaseFilter_JoinFilterGraph(filter,
644 (IFilterGraph *)&graph->IFilterGraph2_iface, entry->name)))
646 CoTaskMemFree(entry->name);
647 heap_free(entry);
648 return hr;
651 IBaseFilter_AddRef(entry->filter = filter);
653 list_add_head(&graph->filters, &entry->entry);
654 entry->sorting = FALSE;
655 entry->seeking = NULL;
656 ++graph->version;
658 return duplicate_name ? VFW_S_DUPLICATE_NAME : hr;
661 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
663 struct filter_graph *This = impl_from_IFilterGraph2(iface);
664 struct filter *entry;
665 int i;
666 HRESULT hr = E_FAIL;
668 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
670 LIST_FOR_EACH_ENTRY(entry, &This->filters, struct filter, entry)
672 if (entry->filter == pFilter)
674 IEnumPins *penumpins = NULL;
676 if (This->defaultclock && This->refClockProvider == pFilter)
678 IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, NULL);
679 This->defaultclock = TRUE;
682 TRACE("Removing filter %s.\n", debugstr_w(entry->name));
684 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
685 if (SUCCEEDED(hr)) {
686 IPin *ppin;
687 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
689 IPin *peer = NULL;
690 HRESULT hr;
692 IPin_ConnectedTo(ppin, &peer);
693 if (peer)
695 if (FAILED(hr = IPin_Disconnect(peer)))
697 WARN("Failed to disconnect peer %p, hr %#x.\n", peer, hr);
698 IPin_Release(peer);
699 IPin_Release(ppin);
700 IEnumPins_Release(penumpins);
701 return hr;
703 IPin_Release(peer);
705 if (FAILED(hr = IPin_Disconnect(ppin)))
707 WARN("Failed to disconnect pin %p, hr %#x.\n", ppin, hr);
708 IPin_Release(ppin);
709 IEnumPins_Release(penumpins);
710 return hr;
713 IPin_Release(ppin);
715 IEnumPins_Release(penumpins);
718 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, NULL);
719 if (SUCCEEDED(hr))
721 IBaseFilter_SetSyncSource(pFilter, NULL);
722 IBaseFilter_Release(pFilter);
723 if (entry->seeking)
724 IMediaSeeking_Release(entry->seeking);
725 list_remove(&entry->entry);
726 CoTaskMemFree(entry->name);
727 heap_free(entry);
728 This->version++;
729 /* Invalidate interfaces in the cache */
730 for (i = 0; i < This->nItfCacheEntries; i++)
731 if (pFilter == This->ItfCacheEntries[i].filter)
733 IUnknown_Release(This->ItfCacheEntries[i].iface);
734 This->ItfCacheEntries[i].iface = NULL;
735 This->ItfCacheEntries[i].filter = NULL;
737 return S_OK;
739 break;
743 return hr; /* FIXME: check this error code */
746 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface, IEnumFilters **out)
748 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
750 TRACE("graph %p, out %p.\n", graph, out);
752 return create_enum_filters(graph, list_head(&graph->filters), out);
755 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface,
756 const WCHAR *name, IBaseFilter **filter)
758 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
760 TRACE("graph %p, name %s, filter %p.\n", graph, debugstr_w(name), filter);
762 if (!filter)
763 return E_POINTER;
765 if ((*filter = find_filter_by_name(graph, name)))
767 IBaseFilter_AddRef(*filter);
768 return S_OK;
771 return VFW_E_NOT_FOUND;
774 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
775 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
777 static HRESULT CheckCircularConnection(struct filter_graph *This, IPin *out, IPin *in)
779 #if 1
780 HRESULT hr;
781 PIN_INFO info_out, info_in;
783 hr = IPin_QueryPinInfo(out, &info_out);
784 if (FAILED(hr))
785 return hr;
786 if (info_out.dir != PINDIR_OUTPUT)
788 IBaseFilter_Release(info_out.pFilter);
789 return VFW_E_CANNOT_CONNECT;
792 hr = IPin_QueryPinInfo(in, &info_in);
793 if (SUCCEEDED(hr))
794 IBaseFilter_Release(info_in.pFilter);
795 if (FAILED(hr))
796 goto out;
797 if (info_in.dir != PINDIR_INPUT)
799 hr = VFW_E_CANNOT_CONNECT;
800 goto out;
803 if (info_out.pFilter == info_in.pFilter)
804 hr = VFW_E_CIRCULAR_GRAPH;
805 else
807 IEnumPins *enumpins;
808 IPin *test;
810 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
811 if (FAILED(hr))
812 goto out;
814 IEnumPins_Reset(enumpins);
815 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
817 PIN_DIRECTION dir = PINDIR_OUTPUT;
818 IPin_QueryDirection(test, &dir);
819 if (dir == PINDIR_INPUT)
821 IPin *victim = NULL;
822 IPin_ConnectedTo(test, &victim);
823 if (victim)
825 hr = CheckCircularConnection(This, victim, in);
826 IPin_Release(victim);
827 if (FAILED(hr))
829 IPin_Release(test);
830 break;
834 IPin_Release(test);
836 IEnumPins_Release(enumpins);
839 out:
840 IBaseFilter_Release(info_out.pFilter);
841 if (FAILED(hr))
842 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
843 return hr;
844 #else
845 /* Debugging filtergraphs not enabled */
846 return S_OK;
847 #endif
850 static struct filter *find_sorted_filter(struct filter_graph *graph, IBaseFilter *iface)
852 struct filter *filter;
854 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
856 if (filter->filter == iface)
857 return filter;
860 return NULL;
863 static void sort_filter_recurse(struct filter_graph *graph, struct filter *filter, struct list *sorted)
865 struct filter *peer_filter;
866 IEnumPins *enumpins;
867 PIN_DIRECTION dir;
868 IPin *pin, *peer;
869 PIN_INFO info;
871 TRACE("Sorting filter %p.\n", filter->filter);
873 /* Cyclic connections should be caught by CheckCircularConnection(). */
874 assert(!filter->sorting);
876 filter->sorting = TRUE;
878 IBaseFilter_EnumPins(filter->filter, &enumpins);
879 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
881 IPin_QueryDirection(pin, &dir);
883 if (dir == PINDIR_INPUT && IPin_ConnectedTo(pin, &peer) == S_OK)
885 IPin_QueryPinInfo(peer, &info);
886 /* Note that the filter may have already been sorted. */
887 if ((peer_filter = find_sorted_filter(graph, info.pFilter)))
888 sort_filter_recurse(graph, peer_filter, sorted);
889 IBaseFilter_Release(info.pFilter);
890 IPin_Release(peer);
892 IPin_Release(pin);
894 IEnumPins_Release(enumpins);
896 filter->sorting = FALSE;
898 list_remove(&filter->entry);
899 list_add_head(sorted, &filter->entry);
902 static void sort_filters(struct filter_graph *graph)
904 struct list sorted = LIST_INIT(sorted), *cursor;
906 while ((cursor = list_head(&graph->filters)))
908 struct filter *filter = LIST_ENTRY(cursor, struct filter, entry);
909 sort_filter_recurse(graph, filter, &sorted);
912 list_move_tail(&graph->filters, &sorted);
915 /* NOTE: despite the implication, it doesn't matter which
916 * way round you put in the input and output pins */
917 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppinIn, IPin *ppinOut,
918 const AM_MEDIA_TYPE *pmt)
920 struct filter_graph *This = impl_from_IFilterGraph2(iface);
921 PIN_DIRECTION dir;
922 HRESULT hr;
924 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
925 strmbase_dump_media_type(pmt);
927 /* FIXME: check pins are in graph */
929 if (TRACE_ON(quartz))
931 PIN_INFO PinInfo;
933 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
934 if (FAILED(hr))
935 return hr;
937 TRACE("Filter owning ppinIn(%p) => %p\n", ppinIn, PinInfo.pFilter);
938 IBaseFilter_Release(PinInfo.pFilter);
940 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
941 if (FAILED(hr))
942 return hr;
944 TRACE("Filter owning ppinOut(%p) => %p\n", ppinOut, PinInfo.pFilter);
945 IBaseFilter_Release(PinInfo.pFilter);
948 hr = IPin_QueryDirection(ppinIn, &dir);
949 if (SUCCEEDED(hr))
951 if (dir == PINDIR_INPUT)
953 hr = CheckCircularConnection(This, ppinOut, ppinIn);
954 if (SUCCEEDED(hr))
955 hr = IPin_Connect(ppinOut, ppinIn, pmt);
957 else
959 hr = CheckCircularConnection(This, ppinIn, ppinOut);
960 if (SUCCEEDED(hr))
961 hr = IPin_Connect(ppinIn, ppinOut, pmt);
965 return hr;
968 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface, IPin *pin)
970 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
972 TRACE("graph %p, pin %p.\n", graph, pin);
974 return IFilterGraph2_ReconnectEx(iface, pin, NULL);
977 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
979 struct filter_graph *This = impl_from_IFilterGraph2(iface);
981 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
983 if (!ppin)
984 return E_POINTER;
986 return IPin_Disconnect(ppin);
989 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
991 struct filter_graph *This = impl_from_IFilterGraph2(iface);
992 IReferenceClock *pClock = NULL;
993 struct filter *filter;
994 HRESULT hr = S_OK;
996 TRACE("(%p/%p)->() live sources not handled properly!\n", This, iface);
998 EnterCriticalSection(&This->cs);
1000 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
1002 if (IBaseFilter_QueryInterface(filter->filter, &IID_IReferenceClock, (void **)&pClock) == S_OK)
1003 break;
1006 if (!pClock)
1008 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
1009 This->refClockProvider = NULL;
1011 else
1013 filter = LIST_ENTRY(list_tail(&This->filters), struct filter, entry);
1014 This->refClockProvider = filter->filter;
1017 if (SUCCEEDED(hr))
1019 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
1020 This->defaultclock = TRUE;
1021 IReferenceClock_Release(pClock);
1023 LeaveCriticalSection(&This->cs);
1025 return hr;
1028 struct filter_create_params
1030 HRESULT hr;
1031 IMoniker *moniker;
1032 IBaseFilter *filter;
1035 static DWORD WINAPI message_thread_run(void *ctx)
1037 struct filter_graph *graph = ctx;
1038 MSG msg;
1040 /* Make sure we have a message queue. */
1041 PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE);
1042 SetEvent(graph->message_thread_ret);
1044 CoInitializeEx(NULL, COINIT_MULTITHREADED);
1046 for (;;)
1048 GetMessageW(&msg, NULL, 0, 0);
1050 if (!msg.hwnd && msg.message == WM_USER)
1052 struct filter_create_params *params = (struct filter_create_params *)msg.wParam;
1054 params->hr = IMoniker_BindToObject(params->moniker, NULL, NULL,
1055 &IID_IBaseFilter, (void **)&params->filter);
1056 SetEvent(graph->message_thread_ret);
1058 else if (!msg.hwnd && msg.message == WM_USER + 1)
1060 break;
1062 else
1064 TranslateMessage(&msg);
1065 DispatchMessageW(&msg);
1069 CoUninitialize();
1070 return 0;
1073 static HRESULT create_filter(struct filter_graph *graph, IMoniker *moniker, IBaseFilter **filter)
1075 if (graph->message_thread)
1077 struct filter_create_params params;
1079 params.moniker = moniker;
1080 PostThreadMessageW(graph->message_thread_id, WM_USER, (WPARAM)&params, 0);
1081 WaitForSingleObject(graph->message_thread_ret, INFINITE);
1082 *filter = params.filter;
1083 return params.hr;
1085 else
1086 return IMoniker_BindToObject(moniker, NULL, NULL, &IID_IBaseFilter, (void **)filter);
1089 static HRESULT autoplug(struct filter_graph *graph, IPin *source, IPin *sink,
1090 BOOL render_to_existing, unsigned int recursion_depth);
1092 static HRESULT autoplug_through_sink(struct filter_graph *graph, IPin *source,
1093 IBaseFilter *filter, IPin *middle_sink, IPin *sink,
1094 BOOL render_to_existing, unsigned int recursion_depth)
1096 BOOL any = FALSE, all = TRUE;
1097 IPin *middle_source, *peer;
1098 IEnumPins *source_enum;
1099 PIN_DIRECTION dir;
1100 PIN_INFO info;
1101 HRESULT hr;
1103 TRACE("Trying to autoplug %p to %p through %p.\n", source, sink, middle_sink);
1105 IPin_QueryDirection(middle_sink, &dir);
1106 if (dir != PINDIR_INPUT)
1107 return E_FAIL;
1109 if (IPin_ConnectedTo(middle_sink, &peer) == S_OK)
1111 IPin_Release(peer);
1112 return E_FAIL;
1115 if (FAILED(hr = IFilterGraph2_ConnectDirect(&graph->IFilterGraph2_iface, source, middle_sink, NULL)))
1116 return E_FAIL;
1118 if (FAILED(hr = IBaseFilter_EnumPins(filter, &source_enum)))
1119 goto err;
1121 while (IEnumPins_Next(source_enum, 1, &middle_source, NULL) == S_OK)
1123 IPin_QueryPinInfo(middle_source, &info);
1124 IBaseFilter_Release(info.pFilter);
1125 if (info.dir != PINDIR_OUTPUT)
1127 IPin_Release(middle_source);
1128 continue;
1130 if (info.achName[0] == '~')
1132 TRACE("Skipping non-rendered pin %s.\n", debugstr_w(info.achName));
1133 IPin_Release(middle_source);
1134 continue;
1136 if (IPin_ConnectedTo(middle_source, &peer) == S_OK)
1138 IPin_Release(peer);
1139 IPin_Release(middle_source);
1140 continue;
1143 hr = autoplug(graph, middle_source, sink, render_to_existing, recursion_depth + 1);
1144 IPin_Release(middle_source);
1145 if (SUCCEEDED(hr) && sink)
1147 IEnumPins_Release(source_enum);
1148 return hr;
1150 if (SUCCEEDED(hr))
1151 any = TRUE;
1152 if (hr != S_OK)
1153 all = FALSE;
1155 IEnumPins_Release(source_enum);
1157 if (!sink)
1159 if (all)
1160 return S_OK;
1161 if (any)
1162 return VFW_S_PARTIAL_RENDER;
1165 err:
1166 IFilterGraph2_Disconnect(&graph->IFilterGraph2_iface, source);
1167 IFilterGraph2_Disconnect(&graph->IFilterGraph2_iface, middle_sink);
1168 return E_FAIL;
1171 static HRESULT autoplug_through_filter(struct filter_graph *graph, IPin *source,
1172 IBaseFilter *filter, IPin *sink, BOOL render_to_existing,
1173 unsigned int recursion_depth)
1175 IEnumPins *sink_enum;
1176 IPin *filter_sink;
1177 HRESULT hr;
1179 TRACE("Trying to autoplug %p to %p through %p.\n", source, sink, filter);
1181 if (FAILED(hr = IBaseFilter_EnumPins(filter, &sink_enum)))
1182 return hr;
1184 while (IEnumPins_Next(sink_enum, 1, &filter_sink, NULL) == S_OK)
1186 hr = autoplug_through_sink(graph, source, filter, filter_sink, sink,
1187 render_to_existing, recursion_depth);
1188 IPin_Release(filter_sink);
1189 if (SUCCEEDED(hr))
1191 IEnumPins_Release(sink_enum);
1192 return hr;
1195 IEnumPins_Release(sink_enum);
1196 return VFW_E_CANNOT_CONNECT;
1199 /* Common helper for IGraphBuilder::Connect() and IGraphBuilder::Render(), which
1200 * share most of the same code. Render() calls this with a NULL sink. */
1201 static HRESULT autoplug(struct filter_graph *graph, IPin *source, IPin *sink,
1202 BOOL render_to_existing, unsigned int recursion_depth)
1204 IAMGraphBuilderCallback *callback = NULL;
1205 IEnumMediaTypes *enummt;
1206 IFilterMapper2 *mapper;
1207 struct filter *filter;
1208 AM_MEDIA_TYPE *mt;
1209 HRESULT hr;
1211 TRACE("Trying to autoplug %p to %p, recursion depth %u.\n", source, sink, recursion_depth);
1213 if (recursion_depth >= 5)
1215 WARN("Recursion depth has reached 5; aborting.\n");
1216 return VFW_E_CANNOT_CONNECT;
1219 if (sink)
1221 /* Try to connect directly to this sink. */
1222 hr = IFilterGraph2_ConnectDirect(&graph->IFilterGraph2_iface, source, sink, NULL);
1224 /* If direct connection succeeded, we should propagate that return value.
1225 * If it returned VFW_E_NOT_CONNECTED or VFW_E_NO_AUDIO_HARDWARE, then don't
1226 * even bother trying intermediate filters, since they won't succeed. */
1227 if (SUCCEEDED(hr) || hr == VFW_E_NOT_CONNECTED || hr == VFW_E_NO_AUDIO_HARDWARE)
1228 return hr;
1231 /* Always prefer filters in the graph. */
1232 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1234 if (SUCCEEDED(hr = autoplug_through_filter(graph, source, filter->filter,
1235 sink, render_to_existing, recursion_depth)))
1236 return hr;
1239 IUnknown_QueryInterface(graph->punkFilterMapper2, &IID_IFilterMapper2, (void **)&mapper);
1241 if (FAILED(hr = IPin_EnumMediaTypes(source, &enummt)))
1243 IFilterMapper2_Release(mapper);
1244 return hr;
1247 if (graph->pSite)
1248 IUnknown_QueryInterface(graph->pSite, &IID_IAMGraphBuilderCallback, (void **)&callback);
1250 while (IEnumMediaTypes_Next(enummt, 1, &mt, NULL) == S_OK)
1252 GUID types[2] = {mt->majortype, mt->subtype};
1253 IEnumMoniker *enummoniker;
1254 IBaseFilter *filter;
1255 IMoniker *moniker;
1257 DeleteMediaType(mt);
1259 if (FAILED(hr = IFilterMapper2_EnumMatchingFilters(mapper, &enummoniker,
1260 0, FALSE, MERIT_UNLIKELY, TRUE, 1, types, NULL, NULL, FALSE,
1261 render_to_existing, 0, NULL, NULL, NULL)))
1262 goto out;
1264 while (IEnumMoniker_Next(enummoniker, 1, &moniker, NULL) == S_OK)
1266 IPropertyBag *bag;
1267 VARIANT var;
1269 VariantInit(&var);
1270 IMoniker_BindToStorage(moniker, NULL, NULL, &IID_IPropertyBag, (void **)&bag);
1271 hr = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL);
1272 IPropertyBag_Release(bag);
1273 if (FAILED(hr))
1275 IMoniker_Release(moniker);
1276 continue;
1279 if (callback && FAILED(hr = IAMGraphBuilderCallback_SelectedFilter(callback, moniker)))
1281 TRACE("Filter rejected by IAMGraphBuilderCallback::SelectedFilter(), hr %#x.\n", hr);
1282 IMoniker_Release(moniker);
1283 continue;
1286 hr = create_filter(graph, moniker, &filter);
1287 IMoniker_Release(moniker);
1288 if (FAILED(hr))
1290 ERR("Failed to create filter for %s, hr %#x.\n", debugstr_w(V_BSTR(&var)), hr);
1291 VariantClear(&var);
1292 continue;
1295 if (callback && FAILED(hr = IAMGraphBuilderCallback_CreatedFilter(callback, filter)))
1297 TRACE("Filter rejected by IAMGraphBuilderCallback::CreatedFilter(), hr %#x.\n", hr);
1298 IBaseFilter_Release(filter);
1299 continue;
1302 hr = IFilterGraph2_AddFilter(&graph->IFilterGraph2_iface, filter, V_BSTR(&var));
1303 VariantClear(&var);
1304 if (FAILED(hr))
1306 ERR("Failed to add filter, hr %#x.\n", hr);
1307 IBaseFilter_Release(filter);
1308 continue;
1311 hr = autoplug_through_filter(graph, source, filter, sink, render_to_existing, recursion_depth);
1312 if (SUCCEEDED(hr))
1314 IBaseFilter_Release(filter);
1315 goto out;
1318 IFilterGraph2_RemoveFilter(&graph->IFilterGraph2_iface, filter);
1319 IBaseFilter_Release(filter);
1321 IEnumMoniker_Release(enummoniker);
1324 hr = VFW_E_CANNOT_CONNECT;
1326 out:
1327 if (callback) IAMGraphBuilderCallback_Release(callback);
1328 IEnumMediaTypes_Release(enummt);
1329 IFilterMapper2_Release(mapper);
1330 return hr;
1333 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *source, IPin *sink)
1335 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1336 PIN_DIRECTION dir;
1337 HRESULT hr;
1339 TRACE("graph %p, source %p, sink %p.\n", graph, source, sink);
1341 if (!source || !sink)
1342 return E_POINTER;
1344 if (FAILED(hr = IPin_QueryDirection(source, &dir)))
1345 return hr;
1347 if (dir == PINDIR_INPUT)
1349 IPin *temp;
1351 TRACE("Directions seem backwards, swapping pins\n");
1353 temp = sink;
1354 sink = source;
1355 source = temp;
1358 EnterCriticalSection(&graph->cs);
1360 hr = autoplug(graph, source, sink, TRUE, 0);
1362 LeaveCriticalSection(&graph->cs);
1364 TRACE("Returning %#x.\n", hr);
1365 return hr;
1368 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *source)
1370 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1371 HRESULT hr;
1373 TRACE("graph %p, source %p.\n", graph, source);
1375 EnterCriticalSection(&graph->cs);
1376 hr = autoplug(graph, source, NULL, FALSE, 0);
1377 LeaveCriticalSection(&graph->cs);
1378 if (hr == VFW_E_CANNOT_CONNECT)
1379 hr = VFW_E_CANNOT_RENDER;
1381 TRACE("Returning %#x.\n", hr);
1382 return hr;
1385 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface, LPCWSTR lpcwstrFile,
1386 LPCWSTR lpcwstrPlayList)
1388 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1389 IBaseFilter* preader = NULL;
1390 IPin* ppinreader = NULL;
1391 IEnumPins* penumpins = NULL;
1392 struct filter *filter;
1393 HRESULT hr;
1394 BOOL partial = FALSE;
1395 BOOL any = FALSE;
1397 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1399 if (lpcwstrPlayList != NULL)
1400 return E_INVALIDARG;
1402 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, L"Reader", &preader);
1403 if (FAILED(hr))
1404 return hr;
1406 hr = IBaseFilter_EnumPins(preader, &penumpins);
1407 if (SUCCEEDED(hr))
1409 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1411 PIN_DIRECTION dir;
1413 IPin_QueryDirection(ppinreader, &dir);
1414 if (dir == PINDIR_OUTPUT)
1416 hr = IFilterGraph2_Render(iface, ppinreader);
1418 TRACE("Filters in chain:\n");
1419 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
1420 TRACE("- %s.\n", debugstr_w(filter->name));
1422 if (SUCCEEDED(hr))
1423 any = TRUE;
1424 if (hr != S_OK)
1425 partial = TRUE;
1427 IPin_Release(ppinreader);
1429 IEnumPins_Release(penumpins);
1431 if (!any)
1433 if (FAILED(hr = IFilterGraph2_RemoveFilter(iface, preader)))
1434 ERR("Failed to remove source filter, hr %#x.\n", hr);
1435 hr = VFW_E_CANNOT_RENDER;
1437 else if (partial)
1439 hr = VFW_S_PARTIAL_RENDER;
1441 else
1443 hr = S_OK;
1446 IBaseFilter_Release(preader);
1448 TRACE("--> %08x\n", hr);
1449 return hr;
1452 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface,
1453 const WCHAR *filename, const WCHAR *filter_name, IBaseFilter **ret_filter)
1455 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1456 IFileSourceFilter *filesource;
1457 IBaseFilter *filter;
1458 HRESULT hr;
1459 GUID clsid;
1461 TRACE("graph %p, filename %s, filter_name %s, ret_filter %p.\n",
1462 graph, debugstr_w(filename), debugstr_w(filter_name), ret_filter);
1464 if (!get_media_type(filename, NULL, NULL, &clsid))
1465 clsid = CLSID_AsyncReader;
1466 TRACE("Using source filter %s.\n", debugstr_guid(&clsid));
1468 if (FAILED(hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER,
1469 &IID_IBaseFilter, (void **)&filter)))
1471 WARN("Failed to create filter, hr %#x.\n", hr);
1472 return hr;
1475 if (FAILED(hr = IBaseFilter_QueryInterface(filter, &IID_IFileSourceFilter, (void **)&filesource)))
1477 WARN("Failed to get IFileSourceFilter, hr %#x.\n", hr);
1478 IBaseFilter_Release(filter);
1479 return hr;
1482 hr = IFileSourceFilter_Load(filesource, filename, NULL);
1483 IFileSourceFilter_Release(filesource);
1484 if (FAILED(hr))
1486 WARN("Failed to load file, hr %#x.\n", hr);
1487 return hr;
1490 if (FAILED(hr = IFilterGraph2_AddFilter(iface, filter, filter_name)))
1492 IBaseFilter_Release(filter);
1493 return hr;
1496 if (ret_filter)
1497 *ret_filter = filter;
1498 return S_OK;
1501 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR hFile)
1503 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1505 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1507 return S_OK;
1510 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1512 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1514 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1516 return S_OK;
1519 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1521 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1523 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1525 return S_OK;
1528 /*** IFilterGraph2 methods ***/
1529 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1530 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1532 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1533 HRESULT hr;
1534 IBaseFilter* pfilter;
1536 TRACE("(%p/%p)->(%p %p %s %p)\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1538 hr = IMoniker_BindToObject(pMoniker, pCtx, NULL, &IID_IBaseFilter, (void**)&pfilter);
1539 if(FAILED(hr)) {
1540 WARN("Unable to bind moniker to filter object (%x)\n", hr);
1541 return hr;
1544 hr = IFilterGraph2_AddFilter(iface, pfilter, lpcwstrFilterName);
1545 if (FAILED(hr)) {
1546 WARN("Unable to add filter (%x)\n", hr);
1547 IBaseFilter_Release(pfilter);
1548 return hr;
1551 if(ppFilter)
1552 *ppFilter = pfilter;
1553 else IBaseFilter_Release(pfilter);
1555 return S_OK;
1558 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *pin, const AM_MEDIA_TYPE *mt)
1560 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1561 PIN_DIRECTION dir;
1562 HRESULT hr;
1563 IPin *peer;
1565 TRACE("graph %p, pin %p, mt %p.\n", graph, pin, mt);
1567 if (FAILED(hr = IPin_ConnectedTo(pin, &peer)))
1568 return hr;
1570 IPin_QueryDirection(pin, &dir);
1571 IFilterGraph2_Disconnect(iface, peer);
1572 IFilterGraph2_Disconnect(iface, pin);
1574 if (dir == PINDIR_INPUT)
1575 hr = IFilterGraph2_ConnectDirect(iface, peer, pin, mt);
1576 else
1577 hr = IFilterGraph2_ConnectDirect(iface, pin, peer, mt);
1579 IPin_Release(peer);
1580 return hr;
1583 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *source, DWORD flags, DWORD *context)
1585 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1586 HRESULT hr;
1588 TRACE("graph %p, source %p, flags %#x, context %p.\n", graph, source, flags, context);
1590 if (flags & ~AM_RENDEREX_RENDERTOEXISTINGRENDERERS)
1591 FIXME("Unknown flags %#x.\n", flags);
1593 EnterCriticalSection(&graph->cs);
1594 hr = autoplug(graph, source, NULL, !!(flags & AM_RENDEREX_RENDERTOEXISTINGRENDERERS), 0);
1595 LeaveCriticalSection(&graph->cs);
1596 if (hr == VFW_E_CANNOT_CONNECT)
1597 hr = VFW_E_CANNOT_RENDER;
1599 TRACE("Returning %#x.\n", hr);
1600 return hr;
1604 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1606 FilterGraph2_QueryInterface,
1607 FilterGraph2_AddRef,
1608 FilterGraph2_Release,
1609 FilterGraph2_AddFilter,
1610 FilterGraph2_RemoveFilter,
1611 FilterGraph2_EnumFilters,
1612 FilterGraph2_FindFilterByName,
1613 FilterGraph2_ConnectDirect,
1614 FilterGraph2_Reconnect,
1615 FilterGraph2_Disconnect,
1616 FilterGraph2_SetDefaultSyncSource,
1617 FilterGraph2_Connect,
1618 FilterGraph2_Render,
1619 FilterGraph2_RenderFile,
1620 FilterGraph2_AddSourceFilter,
1621 FilterGraph2_SetLogFile,
1622 FilterGraph2_Abort,
1623 FilterGraph2_ShouldOperationContinue,
1624 FilterGraph2_AddSourceFilterForMoniker,
1625 FilterGraph2_ReconnectEx,
1626 FilterGraph2_RenderEx
1629 static struct filter_graph *impl_from_IMediaControl(IMediaControl *iface)
1631 return CONTAINING_RECORD(iface, struct filter_graph, IMediaControl_iface);
1634 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID iid, void **out)
1636 struct filter_graph *graph = impl_from_IMediaControl(iface);
1637 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
1640 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1642 struct filter_graph *graph = impl_from_IMediaControl(iface);
1643 return IUnknown_AddRef(graph->outer_unk);
1646 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1648 struct filter_graph *graph = impl_from_IMediaControl(iface);
1649 return IUnknown_Release(graph->outer_unk);
1653 /*** IDispatch methods ***/
1654 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *pctinfo)
1656 struct filter_graph *This = impl_from_IMediaControl(iface);
1658 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1660 return S_OK;
1663 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT iTInfo, LCID lcid,
1664 ITypeInfo **ppTInfo)
1666 struct filter_graph *This = impl_from_IMediaControl(iface);
1668 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1670 return S_OK;
1673 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID riid,
1674 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1676 struct filter_graph *This = impl_from_IMediaControl(iface);
1678 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
1679 cNames, lcid, rgDispId);
1681 return S_OK;
1684 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID dispIdMember, REFIID riid,
1685 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
1686 UINT *puArgErr)
1688 struct filter_graph *This = impl_from_IMediaControl(iface);
1690 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
1691 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
1693 return S_OK;
1696 static void update_render_count(struct filter_graph *graph)
1698 /* Some filters (e.g. MediaStreamFilter) can become renderers when they are
1699 * already in the graph. */
1700 struct filter *filter;
1701 graph->nRenderers = 0;
1702 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1704 if (is_renderer(filter))
1705 ++graph->nRenderers;
1709 /* Perform the paused -> running transition. The caller must hold graph->cs. */
1710 static HRESULT graph_start(struct filter_graph *graph, REFERENCE_TIME stream_start)
1712 struct media_event *event, *next;
1713 REFERENCE_TIME stream_stop;
1714 struct filter *filter;
1715 HRESULT hr = S_OK;
1717 EnterCriticalSection(&graph->event_cs);
1718 graph->EcCompleteCount = 0;
1719 update_render_count(graph);
1720 LeaveCriticalSection(&graph->event_cs);
1722 LIST_FOR_EACH_ENTRY_SAFE(event, next, &graph->media_events, struct media_event, entry)
1724 if (event->code == EC_COMPLETE)
1726 list_remove(&event->entry);
1727 free(event);
1730 if (list_empty(&graph->media_events))
1731 ResetEvent(graph->media_event_handle);
1733 if (graph->defaultclock && !graph->refClock)
1734 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
1736 if (!stream_start && graph->refClock)
1738 IReferenceClock_GetTime(graph->refClock, &graph->stream_start);
1739 stream_start = graph->stream_start - graph->stream_elapsed;
1740 /* Delay presentation time by 200 ms, to give filters time to
1741 * initialize. */
1742 stream_start += 200 * 10000;
1745 if (SUCCEEDED(IMediaSeeking_GetStopPosition(&graph->IMediaSeeking_iface, &stream_stop)))
1746 graph->stream_stop = stream_stop;
1748 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1750 HRESULT filter_hr = IBaseFilter_Run(filter->filter, stream_start);
1751 if (hr == S_OK)
1752 hr = filter_hr;
1753 TRACE("Filter %p returned %#x.\n", filter->filter, filter_hr);
1756 if (FAILED(hr))
1757 WARN("Failed to start stream, hr %#x.\n", hr);
1759 return hr;
1762 static void CALLBACK async_run_cb(TP_CALLBACK_INSTANCE *instance, void *context, TP_WORK *work)
1764 struct filter_graph *graph = context;
1765 struct filter *filter;
1766 FILTER_STATE state;
1767 HRESULT hr;
1769 TRACE("Performing asynchronous state change.\n");
1771 /* We can't just call GetState(), since that will return State_Running and
1772 * VFW_S_STATE_INTERMEDIATE regardless of whether we're done pausing yet.
1773 * Instead replicate it here. */
1775 for (;;)
1777 IBaseFilter *async_filter = NULL;
1779 hr = S_OK;
1781 EnterCriticalSection(&graph->cs);
1783 if (!graph->needs_async_run)
1784 break;
1786 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1788 hr = IBaseFilter_GetState(filter->filter, 0, &state);
1790 if (hr == VFW_S_STATE_INTERMEDIATE)
1791 async_filter = filter->filter;
1793 if (SUCCEEDED(hr) && state != State_Paused)
1794 ERR("Filter %p reported incorrect state %u.\n", filter->filter, state);
1796 if (hr != S_OK)
1797 break;
1800 if (hr != VFW_S_STATE_INTERMEDIATE)
1801 break;
1803 LeaveCriticalSection(&graph->cs);
1805 IBaseFilter_GetState(async_filter, 10, &state);
1808 if (hr == S_OK && graph->needs_async_run)
1810 sort_filters(graph);
1811 graph_start(graph, 0);
1812 graph->needs_async_run = 0;
1815 LeaveCriticalSection(&graph->cs);
1818 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
1820 struct filter_graph *graph = impl_from_IMediaControl(iface);
1821 BOOL need_async_run = TRUE;
1822 struct filter *filter;
1823 FILTER_STATE state;
1824 HRESULT hr = S_OK;
1826 TRACE("graph %p.\n", graph);
1828 EnterCriticalSection(&graph->cs);
1830 if (graph->state == State_Running)
1832 LeaveCriticalSection(&graph->cs);
1833 return S_OK;
1836 sort_filters(graph);
1838 EnterCriticalSection(&graph->event_cs);
1839 update_render_count(graph);
1840 LeaveCriticalSection(&graph->event_cs);
1842 if (graph->state == State_Stopped)
1844 if (graph->defaultclock && !graph->refClock)
1845 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
1847 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1849 HRESULT filter_hr = IBaseFilter_Pause(filter->filter);
1850 if (hr == S_OK)
1851 hr = filter_hr;
1852 TRACE("Filter %p returned %#x.\n", filter->filter, filter_hr);
1854 /* If a filter returns VFW_S_CANT_CUE, we shouldn't wait for a
1855 * paused state. */
1856 filter_hr = IBaseFilter_GetState(filter->filter, 0, &state);
1857 if (filter_hr != S_OK && filter_hr != VFW_S_STATE_INTERMEDIATE)
1858 need_async_run = FALSE;
1861 if (FAILED(hr))
1863 LeaveCriticalSection(&graph->cs);
1864 WARN("Failed to pause, hr %#x.\n", hr);
1865 return hr;
1869 graph->state = State_Running;
1871 if (SUCCEEDED(hr))
1873 if (hr != S_OK && need_async_run)
1875 if (!graph->async_run_work)
1876 graph->async_run_work = CreateThreadpoolWork(async_run_cb, graph, NULL);
1877 graph->needs_async_run = 1;
1878 SubmitThreadpoolWork(graph->async_run_work);
1880 else
1882 graph_start(graph, 0);
1886 LeaveCriticalSection(&graph->cs);
1887 return hr;
1890 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
1892 struct filter_graph *graph = impl_from_IMediaControl(iface);
1894 TRACE("graph %p.\n", graph);
1896 return IMediaFilter_Pause(&graph->IMediaFilter_iface);
1899 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
1901 struct filter_graph *graph = impl_from_IMediaControl(iface);
1903 TRACE("graph %p.\n", graph);
1905 return IMediaFilter_Stop(&graph->IMediaFilter_iface);
1908 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG timeout, OAFilterState *state)
1910 struct filter_graph *graph = impl_from_IMediaControl(iface);
1912 TRACE("graph %p, timeout %u, state %p.\n", graph, timeout, state);
1914 if (timeout < 0) timeout = INFINITE;
1916 return IMediaFilter_GetState(&graph->IMediaFilter_iface, timeout, (FILTER_STATE *)state);
1919 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
1921 struct filter_graph *This = impl_from_IMediaControl(iface);
1923 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strFilename), strFilename);
1925 return IFilterGraph2_RenderFile(&This->IFilterGraph2_iface, strFilename, NULL);
1928 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
1929 IDispatch **ppUnk)
1931 struct filter_graph *This = impl_from_IMediaControl(iface);
1933 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
1935 return S_OK;
1938 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
1940 struct filter_graph *This = impl_from_IMediaControl(iface);
1942 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
1944 return S_OK;
1947 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
1949 struct filter_graph *This = impl_from_IMediaControl(iface);
1951 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
1953 return S_OK;
1956 static void CALLBACK wait_pause_cb(TP_CALLBACK_INSTANCE *instance, void *context)
1958 IMediaControl *control = context;
1959 OAFilterState state;
1960 HRESULT hr;
1962 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
1963 ERR("Failed to get paused state, hr %#x.\n", hr);
1965 if (FAILED(hr = IMediaControl_Stop(control)))
1966 ERR("Failed to stop, hr %#x.\n", hr);
1968 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
1969 ERR("Failed to get paused state, hr %#x.\n", hr);
1971 IMediaControl_Release(control);
1974 static void CALLBACK wait_stop_cb(TP_CALLBACK_INSTANCE *instance, void *context)
1976 IMediaControl *control = context;
1977 OAFilterState state;
1978 HRESULT hr;
1980 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
1981 ERR("Failed to get state, hr %#x.\n", hr);
1983 IMediaControl_Release(control);
1986 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
1988 struct filter_graph *graph = impl_from_IMediaControl(iface);
1989 HRESULT hr;
1991 TRACE("graph %p.\n", graph);
1993 /* Even if we are already stopped, we still pause. */
1994 hr = IMediaControl_Pause(iface);
1995 if (FAILED(hr))
1996 return hr;
1997 else if (hr == S_FALSE)
1999 IMediaControl_AddRef(iface);
2000 TrySubmitThreadpoolCallback(wait_pause_cb, iface, NULL);
2001 return S_FALSE;
2004 hr = IMediaControl_Stop(iface);
2005 if (FAILED(hr))
2006 return hr;
2007 else if (hr == S_FALSE)
2009 IMediaControl_AddRef(iface);
2010 TrySubmitThreadpoolCallback(wait_stop_cb, iface, NULL);
2011 return S_FALSE;
2014 return S_OK;
2018 static const IMediaControlVtbl IMediaControl_VTable =
2020 MediaControl_QueryInterface,
2021 MediaControl_AddRef,
2022 MediaControl_Release,
2023 MediaControl_GetTypeInfoCount,
2024 MediaControl_GetTypeInfo,
2025 MediaControl_GetIDsOfNames,
2026 MediaControl_Invoke,
2027 MediaControl_Run,
2028 MediaControl_Pause,
2029 MediaControl_Stop,
2030 MediaControl_GetState,
2031 MediaControl_RenderFile,
2032 MediaControl_AddSourceFilter,
2033 MediaControl_get_FilterCollection,
2034 MediaControl_get_RegFilterCollection,
2035 MediaControl_StopWhenReady
2038 static struct filter_graph *impl_from_IMediaSeeking(IMediaSeeking *iface)
2040 return CONTAINING_RECORD(iface, struct filter_graph, IMediaSeeking_iface);
2043 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID iid, void **out)
2045 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2046 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2049 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2051 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2052 return IUnknown_AddRef(graph->outer_unk);
2055 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2057 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2058 return IUnknown_Release(graph->outer_unk);
2061 typedef HRESULT (WINAPI *fnFoundSeek)(struct filter_graph *This, IMediaSeeking*, DWORD_PTR arg);
2063 static HRESULT all_renderers_seek(struct filter_graph *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2064 BOOL allnotimpl = TRUE;
2065 HRESULT hr, hr_return = S_OK;
2066 struct filter *filter;
2068 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2069 /* Send a message to all renderers, they are responsible for broadcasting it further */
2071 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
2073 update_seeking(filter);
2074 if (!filter->seeking)
2075 continue;
2076 hr = FoundSeek(This, filter->seeking, arg);
2077 if (hr_return != E_NOTIMPL)
2078 allnotimpl = FALSE;
2079 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2080 hr_return = hr;
2083 if (allnotimpl)
2084 return E_NOTIMPL;
2085 return hr_return;
2088 static HRESULT WINAPI FoundCapabilities(struct filter_graph *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2090 HRESULT hr;
2091 DWORD caps = 0;
2093 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2094 if (FAILED(hr))
2095 return hr;
2097 /* Only add common capabilities everything supports */
2098 *(DWORD*)pcaps &= caps;
2100 return hr;
2103 /*** IMediaSeeking methods ***/
2104 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2106 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2107 HRESULT hr;
2109 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2111 if (!pCapabilities)
2112 return E_POINTER;
2114 EnterCriticalSection(&This->cs);
2115 *pCapabilities = 0xffffffff;
2117 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2118 LeaveCriticalSection(&This->cs);
2120 return hr;
2123 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2125 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2126 DWORD originalcaps;
2127 HRESULT hr;
2129 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2131 if (!pCapabilities)
2132 return E_POINTER;
2134 EnterCriticalSection(&This->cs);
2135 originalcaps = *pCapabilities;
2136 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2137 LeaveCriticalSection(&This->cs);
2139 if (FAILED(hr))
2140 return hr;
2142 if (!*pCapabilities)
2143 return E_FAIL;
2144 if (*pCapabilities != originalcaps)
2145 return S_FALSE;
2146 return S_OK;
2149 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2151 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2153 if (!pFormat)
2154 return E_POINTER;
2156 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2158 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2160 WARN("Unhandled time format %s\n", debugstr_guid(pFormat));
2161 return S_FALSE;
2164 return S_OK;
2167 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2169 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2171 if (!pFormat)
2172 return E_POINTER;
2174 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2175 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2177 return S_OK;
2180 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2182 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2184 if (!pFormat)
2185 return E_POINTER;
2187 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2188 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2190 return S_OK;
2193 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2195 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2197 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2198 if (!pFormat)
2199 return E_POINTER;
2201 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2202 return S_FALSE;
2204 return S_OK;
2207 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2209 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2211 if (!pFormat)
2212 return E_POINTER;
2214 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2216 if (This->state != State_Stopped)
2217 return VFW_E_WRONG_STATE;
2219 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2221 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2222 return E_INVALIDARG;
2225 return S_OK;
2228 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *duration)
2230 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2231 HRESULT hr = E_NOTIMPL, filter_hr;
2232 LONGLONG filter_duration;
2233 struct filter *filter;
2235 TRACE("graph %p, duration %p.\n", graph, duration);
2237 if (!duration)
2238 return E_POINTER;
2240 *duration = 0;
2242 EnterCriticalSection(&graph->cs);
2244 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2246 update_seeking(filter);
2247 if (!filter->seeking)
2248 continue;
2250 filter_hr = IMediaSeeking_GetDuration(filter->seeking, &filter_duration);
2251 if (SUCCEEDED(filter_hr))
2253 hr = S_OK;
2254 *duration = max(*duration, filter_duration);
2256 else if (filter_hr != E_NOTIMPL)
2258 LeaveCriticalSection(&graph->cs);
2259 return filter_hr;
2263 LeaveCriticalSection(&graph->cs);
2265 TRACE("Returning hr %#x, duration %s (%s seconds).\n", hr,
2266 wine_dbgstr_longlong(*duration), debugstr_time(*duration));
2267 return hr;
2270 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *stop)
2272 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2273 HRESULT hr = E_NOTIMPL, filter_hr;
2274 struct filter *filter;
2275 LONGLONG filter_stop;
2277 TRACE("graph %p, stop %p.\n", graph, stop);
2279 if (!stop)
2280 return E_POINTER;
2282 *stop = 0;
2284 EnterCriticalSection(&graph->cs);
2286 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2288 update_seeking(filter);
2289 if (!filter->seeking)
2290 continue;
2292 filter_hr = IMediaSeeking_GetStopPosition(filter->seeking, &filter_stop);
2293 if (SUCCEEDED(filter_hr))
2295 hr = S_OK;
2296 *stop = max(*stop, filter_stop);
2298 else if (filter_hr != E_NOTIMPL)
2300 LeaveCriticalSection(&graph->cs);
2301 return filter_hr;
2305 LeaveCriticalSection(&graph->cs);
2307 TRACE("Returning %s (%s seconds).\n", wine_dbgstr_longlong(*stop), debugstr_time(*stop));
2308 return hr;
2311 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *current)
2313 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2314 LONGLONG ret = graph->current_pos;
2316 TRACE("graph %p, current %p.\n", graph, current);
2318 if (!current)
2319 return E_POINTER;
2321 EnterCriticalSection(&graph->cs);
2323 if (graph->got_ec_complete)
2325 ret = graph->stream_stop;
2327 else if (graph->state == State_Running && !graph->needs_async_run && graph->refClock)
2329 REFERENCE_TIME time;
2330 IReferenceClock_GetTime(graph->refClock, &time);
2331 if (time)
2332 ret += time - graph->stream_start;
2335 LeaveCriticalSection(&graph->cs);
2337 TRACE("Returning %s (%s seconds).\n", wine_dbgstr_longlong(ret), debugstr_time(ret));
2338 *current = ret;
2340 return S_OK;
2343 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2344 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2346 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2348 TRACE("(%p/%p)->(%p, %s, 0x%s, %s)\n", This, iface, pTarget,
2349 debugstr_guid(pTargetFormat), wine_dbgstr_longlong(Source), debugstr_guid(pSourceFormat));
2351 if (!pSourceFormat)
2352 pSourceFormat = &This->timeformatseek;
2354 if (!pTargetFormat)
2355 pTargetFormat = &This->timeformatseek;
2357 if (IsEqualGUID(pTargetFormat, pSourceFormat))
2358 *pTarget = Source;
2359 else
2360 FIXME("conversion %s->%s not supported\n", debugstr_guid(pSourceFormat), debugstr_guid(pTargetFormat));
2362 return S_OK;
2365 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *current_ptr,
2366 DWORD current_flags, LONGLONG *stop_ptr, DWORD stop_flags)
2368 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2369 HRESULT hr = E_NOTIMPL, filter_hr;
2370 struct filter *filter;
2371 FILTER_STATE state;
2373 TRACE("graph %p, current %s, current_flags %#x, stop %s, stop_flags %#x.\n", graph,
2374 current_ptr ? wine_dbgstr_longlong(*current_ptr) : "<null>", current_flags,
2375 stop_ptr ? wine_dbgstr_longlong(*stop_ptr): "<null>", stop_flags);
2376 if (current_ptr)
2377 TRACE("Setting current position to %s (%s seconds).\n",
2378 wine_dbgstr_longlong(*current_ptr), debugstr_time(*current_ptr));
2379 if (stop_ptr)
2380 TRACE("Setting stop position to %s (%s seconds).\n",
2381 wine_dbgstr_longlong(*stop_ptr), debugstr_time(*stop_ptr));
2383 if ((current_flags & 0x7) != AM_SEEKING_AbsolutePositioning
2384 && (current_flags & 0x7) != AM_SEEKING_NoPositioning)
2385 FIXME("Unhandled current_flags %#x.\n", current_flags & 0x7);
2387 if ((stop_flags & 0x7) != AM_SEEKING_NoPositioning
2388 && (stop_flags & 0x7) != AM_SEEKING_AbsolutePositioning)
2389 FIXME("Unhandled stop_flags %#x.\n", stop_flags & 0x7);
2391 EnterCriticalSection(&graph->cs);
2393 state = graph->state;
2394 if (state == State_Running && !graph->needs_async_run)
2395 IMediaControl_Pause(&graph->IMediaControl_iface);
2397 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2399 LONGLONG current = current_ptr ? *current_ptr : 0, stop = stop_ptr ? *stop_ptr : 0;
2401 update_seeking(filter);
2402 if (!filter->seeking)
2403 continue;
2405 filter_hr = IMediaSeeking_SetPositions(filter->seeking, &current,
2406 current_flags | AM_SEEKING_ReturnTime, &stop, stop_flags);
2407 if (SUCCEEDED(filter_hr))
2409 hr = S_OK;
2411 if (current_ptr && (current_flags & AM_SEEKING_ReturnTime))
2412 *current_ptr = current;
2413 if (stop_ptr && (stop_flags & AM_SEEKING_ReturnTime))
2414 *stop_ptr = stop;
2415 graph->current_pos = current;
2417 else if (filter_hr != E_NOTIMPL)
2419 LeaveCriticalSection(&graph->cs);
2420 return filter_hr;
2424 if ((current_flags & 0x7) != AM_SEEKING_NoPositioning && graph->refClock)
2426 IReferenceClock_GetTime(graph->refClock, &graph->stream_start);
2427 graph->stream_elapsed = 0;
2430 if (state == State_Running && !graph->needs_async_run)
2431 IMediaControl_Run(&graph->IMediaControl_iface);
2433 LeaveCriticalSection(&graph->cs);
2434 return hr;
2437 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface,
2438 LONGLONG *current, LONGLONG *stop)
2440 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2441 HRESULT hr = S_OK;
2443 TRACE("graph %p, current %p, stop %p.\n", graph, current, stop);
2445 if (current)
2446 hr = IMediaSeeking_GetCurrentPosition(iface, current);
2447 if (SUCCEEDED(hr) && stop)
2448 hr = IMediaSeeking_GetStopPosition(iface, stop);
2450 return hr;
2453 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2454 LONGLONG *pLatest)
2456 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2458 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2460 return S_OK;
2463 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2465 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2467 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2469 return S_OK;
2472 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2474 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2476 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2478 if (!pdRate)
2479 return E_POINTER;
2481 *pdRate = 1.0;
2483 return S_OK;
2486 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2488 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2490 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2492 return S_OK;
2496 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2498 MediaSeeking_QueryInterface,
2499 MediaSeeking_AddRef,
2500 MediaSeeking_Release,
2501 MediaSeeking_GetCapabilities,
2502 MediaSeeking_CheckCapabilities,
2503 MediaSeeking_IsFormatSupported,
2504 MediaSeeking_QueryPreferredFormat,
2505 MediaSeeking_GetTimeFormat,
2506 MediaSeeking_IsUsingTimeFormat,
2507 MediaSeeking_SetTimeFormat,
2508 MediaSeeking_GetDuration,
2509 MediaSeeking_GetStopPosition,
2510 MediaSeeking_GetCurrentPosition,
2511 MediaSeeking_ConvertTimeFormat,
2512 MediaSeeking_SetPositions,
2513 MediaSeeking_GetPositions,
2514 MediaSeeking_GetAvailable,
2515 MediaSeeking_SetRate,
2516 MediaSeeking_GetRate,
2517 MediaSeeking_GetPreroll
2520 static struct filter_graph *impl_from_IMediaPosition(IMediaPosition *iface)
2522 return CONTAINING_RECORD(iface, struct filter_graph, IMediaPosition_iface);
2525 /*** IUnknown methods ***/
2526 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition *iface, REFIID iid, void **out)
2528 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2529 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2532 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2534 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2535 return IUnknown_AddRef(graph->outer_unk);
2538 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2540 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2541 return IUnknown_Release(graph->outer_unk);
2544 /*** IDispatch methods ***/
2545 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo)
2547 FIXME("(%p) stub!\n", iface);
2548 return E_NOTIMPL;
2551 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
2553 FIXME("(%p) stub!\n", iface);
2554 return E_NOTIMPL;
2557 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
2559 FIXME("(%p) stub!\n", iface);
2560 return E_NOTIMPL;
2563 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2565 FIXME("(%p) stub!\n", iface);
2566 return E_NOTIMPL;
2569 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2571 GUID time_format;
2572 HRESULT hr;
2574 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2575 if (FAILED(hr))
2576 return hr;
2577 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2579 FIXME("Unsupported time format.\n");
2580 return E_NOTIMPL;
2583 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2584 return S_OK;
2587 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2589 GUID time_format;
2590 HRESULT hr;
2592 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2593 if (FAILED(hr))
2594 return hr;
2595 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2597 FIXME("Unsupported time format.\n");
2598 return E_NOTIMPL;
2601 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2602 return S_OK;
2605 /*** IMediaPosition methods ***/
2606 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2608 LONGLONG duration;
2609 struct filter_graph *This = impl_from_IMediaPosition( iface );
2610 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2611 if (FAILED(hr))
2612 return hr;
2613 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2616 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2618 struct filter_graph *This = impl_from_IMediaPosition( iface );
2619 LONGLONG reftime;
2620 HRESULT hr;
2622 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2623 if (FAILED(hr))
2624 return hr;
2625 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2626 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2629 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2631 struct filter_graph *This = impl_from_IMediaPosition( iface );
2632 LONGLONG pos;
2633 HRESULT hr;
2635 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2636 if (FAILED(hr))
2637 return hr;
2638 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2641 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2643 struct filter_graph *This = impl_from_IMediaPosition( iface );
2644 LONGLONG pos;
2645 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2646 if (FAILED(hr))
2647 return hr;
2648 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2651 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2653 struct filter_graph *This = impl_from_IMediaPosition( iface );
2654 LONGLONG reftime;
2655 HRESULT hr;
2657 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2658 if (FAILED(hr))
2659 return hr;
2660 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2661 &reftime, AM_SEEKING_AbsolutePositioning);
2664 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime)
2666 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2667 return E_NOTIMPL;
2670 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime)
2672 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2673 return E_NOTIMPL;
2676 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2678 struct filter_graph *This = impl_from_IMediaPosition( iface );
2679 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2682 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2684 struct filter_graph *This = impl_from_IMediaPosition( iface );
2685 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2688 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward)
2690 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2691 return E_NOTIMPL;
2694 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward)
2696 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2697 return E_NOTIMPL;
2701 static const IMediaPositionVtbl IMediaPosition_VTable =
2703 MediaPosition_QueryInterface,
2704 MediaPosition_AddRef,
2705 MediaPosition_Release,
2706 MediaPosition_GetTypeInfoCount,
2707 MediaPosition_GetTypeInfo,
2708 MediaPosition_GetIDsOfNames,
2709 MediaPosition_Invoke,
2710 MediaPosition_get_Duration,
2711 MediaPosition_put_CurrentPosition,
2712 MediaPosition_get_CurrentPosition,
2713 MediaPosition_get_StopTime,
2714 MediaPosition_put_StopTime,
2715 MediaPosition_get_PrerollTime,
2716 MediaPosition_put_PrerollTime,
2717 MediaPosition_put_Rate,
2718 MediaPosition_get_Rate,
2719 MediaPosition_CanSeekForward,
2720 MediaPosition_CanSeekBackward
2723 static struct filter_graph *impl_from_IObjectWithSite(IObjectWithSite *iface)
2725 return CONTAINING_RECORD(iface, struct filter_graph, IObjectWithSite_iface);
2728 /*** IUnknown methods ***/
2729 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID iid, void **out)
2731 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2732 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2735 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
2737 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2738 return IUnknown_AddRef(graph->outer_unk);
2741 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
2743 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2744 return IUnknown_Release(graph->outer_unk);
2747 /*** IObjectWithSite methods ***/
2749 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
2751 struct filter_graph *This = impl_from_IObjectWithSite( iface );
2753 TRACE("(%p/%p)->()\n", This, iface);
2754 if (This->pSite) IUnknown_Release(This->pSite);
2755 This->pSite = pUnkSite;
2756 IUnknown_AddRef(This->pSite);
2757 return S_OK;
2760 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, PVOID *ppvSite)
2762 struct filter_graph *This = impl_from_IObjectWithSite( iface );
2764 TRACE("(%p/%p)->(%s)\n", This, iface,debugstr_guid(riid));
2766 *ppvSite = NULL;
2767 if (!This->pSite)
2768 return E_FAIL;
2769 else
2770 return IUnknown_QueryInterface(This->pSite, riid, ppvSite);
2773 static const IObjectWithSiteVtbl IObjectWithSite_VTable =
2775 ObjectWithSite_QueryInterface,
2776 ObjectWithSite_AddRef,
2777 ObjectWithSite_Release,
2778 ObjectWithSite_SetSite,
2779 ObjectWithSite_GetSite,
2782 static HRESULT GetTargetInterface(struct filter_graph* pGraph, REFIID riid, LPVOID* ppvObj)
2784 struct filter *filter;
2785 HRESULT hr;
2786 int entry;
2788 /* Check if the interface type is already registered */
2789 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2790 if (riid == pGraph->ItfCacheEntries[entry].riid)
2792 if (pGraph->ItfCacheEntries[entry].iface)
2794 /* Return the interface if available */
2795 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2796 return S_OK;
2798 break;
2801 if (entry >= MAX_ITF_CACHE_ENTRIES)
2803 FIXME("Not enough space to store interface in the cache\n");
2804 return E_OUTOFMEMORY;
2807 /* Find a filter supporting the requested interface */
2808 LIST_FOR_EACH_ENTRY(filter, &pGraph->filters, struct filter, entry)
2810 hr = IBaseFilter_QueryInterface(filter->filter, riid, ppvObj);
2811 if (hr == S_OK)
2813 pGraph->ItfCacheEntries[entry].riid = riid;
2814 pGraph->ItfCacheEntries[entry].filter = filter->filter;
2815 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2816 if (entry >= pGraph->nItfCacheEntries)
2817 pGraph->nItfCacheEntries++;
2818 return S_OK;
2820 if (hr != E_NOINTERFACE)
2821 return hr;
2824 return IsEqualGUID(riid, &IID_IBasicAudio) ? E_NOTIMPL : E_NOINTERFACE;
2827 static struct filter_graph *impl_from_IBasicAudio(IBasicAudio *iface)
2829 return CONTAINING_RECORD(iface, struct filter_graph, IBasicAudio_iface);
2832 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID iid, void **out)
2834 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2835 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2838 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
2840 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2841 return IUnknown_AddRef(graph->outer_unk);
2844 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
2846 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2847 return IUnknown_Release(graph->outer_unk);
2850 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *count)
2852 TRACE("iface %p, count %p.\n", iface, count);
2853 *count = 1;
2854 return S_OK;
2857 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT index,
2858 LCID lcid, ITypeInfo **typeinfo)
2860 TRACE("iface %p, index %u, lcid %#x, typeinfo %p.\n", iface, index, lcid, typeinfo);
2861 return strmbase_get_typeinfo(IBasicAudio_tid, typeinfo);
2864 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID iid,
2865 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
2867 ITypeInfo *typeinfo;
2868 HRESULT hr;
2870 TRACE("iface %p, iid %s, names %p, count %u, lcid %#x, ids %p.\n",
2871 iface, debugstr_guid(iid), names, count, lcid, ids);
2873 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicAudio_tid, &typeinfo)))
2875 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
2876 ITypeInfo_Release(typeinfo);
2878 return hr;
2881 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID id, REFIID iid, LCID lcid,
2882 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
2884 ITypeInfo *typeinfo;
2885 HRESULT hr;
2887 TRACE("iface %p, id %d, iid %s, lcid %#x, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
2888 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
2890 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicAudio_tid, &typeinfo)))
2892 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
2893 ITypeInfo_Release(typeinfo);
2895 return hr;
2898 /*** IBasicAudio methods ***/
2899 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
2901 struct filter_graph *This = impl_from_IBasicAudio(iface);
2902 IBasicAudio* pBasicAudio;
2903 HRESULT hr;
2905 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
2907 EnterCriticalSection(&This->cs);
2909 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2911 if (hr == S_OK)
2912 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
2914 LeaveCriticalSection(&This->cs);
2916 return hr;
2919 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
2921 struct filter_graph *This = impl_from_IBasicAudio(iface);
2922 IBasicAudio* pBasicAudio;
2923 HRESULT hr;
2925 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
2927 EnterCriticalSection(&This->cs);
2929 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2931 if (hr == S_OK)
2932 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
2934 LeaveCriticalSection(&This->cs);
2936 return hr;
2939 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
2941 struct filter_graph *This = impl_from_IBasicAudio(iface);
2942 IBasicAudio* pBasicAudio;
2943 HRESULT hr;
2945 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
2947 EnterCriticalSection(&This->cs);
2949 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2951 if (hr == S_OK)
2952 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
2954 LeaveCriticalSection(&This->cs);
2956 return hr;
2959 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
2961 struct filter_graph *This = impl_from_IBasicAudio(iface);
2962 IBasicAudio* pBasicAudio;
2963 HRESULT hr;
2965 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
2967 EnterCriticalSection(&This->cs);
2969 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2971 if (hr == S_OK)
2972 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
2974 LeaveCriticalSection(&This->cs);
2976 return hr;
2979 static const IBasicAudioVtbl IBasicAudio_VTable =
2981 BasicAudio_QueryInterface,
2982 BasicAudio_AddRef,
2983 BasicAudio_Release,
2984 BasicAudio_GetTypeInfoCount,
2985 BasicAudio_GetTypeInfo,
2986 BasicAudio_GetIDsOfNames,
2987 BasicAudio_Invoke,
2988 BasicAudio_put_Volume,
2989 BasicAudio_get_Volume,
2990 BasicAudio_put_Balance,
2991 BasicAudio_get_Balance
2994 static struct filter_graph *impl_from_IBasicVideo2(IBasicVideo2 *iface)
2996 return CONTAINING_RECORD(iface, struct filter_graph, IBasicVideo2_iface);
2999 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID iid, void **out)
3001 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
3002 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
3005 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
3007 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
3008 return IUnknown_AddRef(graph->outer_unk);
3011 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
3013 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
3014 return IUnknown_Release(graph->outer_unk);
3017 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *count)
3019 TRACE("iface %p, count %p.\n", iface, count);
3020 *count = 1;
3021 return S_OK;
3024 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT index,
3025 LCID lcid, ITypeInfo **typeinfo)
3027 TRACE("iface %p, index %u, lcid %#x, typeinfo %p.\n", iface, index, lcid, typeinfo);
3028 return strmbase_get_typeinfo(IBasicVideo_tid, typeinfo);
3031 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID iid,
3032 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
3034 ITypeInfo *typeinfo;
3035 HRESULT hr;
3037 TRACE("iface %p, iid %s, names %p, count %u, lcid %#x, ids %p.\n",
3038 iface, debugstr_guid(iid), names, count, lcid, ids);
3040 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicVideo_tid, &typeinfo)))
3042 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
3043 ITypeInfo_Release(typeinfo);
3045 return hr;
3048 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID id, REFIID iid, LCID lcid,
3049 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
3051 ITypeInfo *typeinfo;
3052 HRESULT hr;
3054 TRACE("iface %p, id %d, iid %s, lcid %#x, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
3055 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
3057 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicVideo_tid, &typeinfo)))
3059 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
3060 ITypeInfo_Release(typeinfo);
3062 return hr;
3065 /*** IBasicVideo methods ***/
3066 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3068 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3069 IBasicVideo *pBasicVideo;
3070 HRESULT hr;
3072 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3074 EnterCriticalSection(&This->cs);
3076 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3078 if (hr == S_OK)
3079 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3081 LeaveCriticalSection(&This->cs);
3083 return hr;
3086 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3088 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3089 IBasicVideo *pBasicVideo;
3090 HRESULT hr;
3092 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3094 EnterCriticalSection(&This->cs);
3096 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3098 if (hr == S_OK)
3099 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3101 LeaveCriticalSection(&This->cs);
3103 return hr;
3106 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3108 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3109 IBasicVideo *pBasicVideo;
3110 HRESULT hr;
3112 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3114 EnterCriticalSection(&This->cs);
3116 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3118 if (hr == S_OK)
3119 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3121 LeaveCriticalSection(&This->cs);
3123 return hr;
3126 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3128 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3129 IBasicVideo *pBasicVideo;
3130 HRESULT hr;
3132 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3134 EnterCriticalSection(&This->cs);
3136 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3138 if (hr == S_OK)
3139 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3141 LeaveCriticalSection(&This->cs);
3143 return hr;
3146 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3148 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3149 IBasicVideo *pBasicVideo;
3150 HRESULT hr;
3152 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3154 EnterCriticalSection(&This->cs);
3156 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3158 if (hr == S_OK)
3159 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3161 LeaveCriticalSection(&This->cs);
3163 return hr;
3166 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3168 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3169 IBasicVideo *pBasicVideo;
3170 HRESULT hr;
3172 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3174 EnterCriticalSection(&This->cs);
3176 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3178 if (hr == S_OK)
3179 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3181 LeaveCriticalSection(&This->cs);
3183 return hr;
3186 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3188 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3189 IBasicVideo *pBasicVideo;
3190 HRESULT hr;
3192 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3194 EnterCriticalSection(&This->cs);
3196 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3198 if (hr == S_OK)
3199 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3201 LeaveCriticalSection(&This->cs);
3203 return hr;
3206 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3208 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3209 IBasicVideo *pBasicVideo;
3210 HRESULT hr;
3212 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3214 EnterCriticalSection(&This->cs);
3216 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3218 if (hr == S_OK)
3219 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3221 LeaveCriticalSection(&This->cs);
3223 return hr;
3226 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3228 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3229 IBasicVideo *pBasicVideo;
3230 HRESULT hr;
3232 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3234 EnterCriticalSection(&This->cs);
3236 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3238 if (hr == S_OK)
3239 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3241 LeaveCriticalSection(&This->cs);
3243 return hr;
3246 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3248 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3249 IBasicVideo *pBasicVideo;
3250 HRESULT hr;
3252 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3254 EnterCriticalSection(&This->cs);
3256 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3258 if (hr == S_OK)
3259 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3261 LeaveCriticalSection(&This->cs);
3263 return hr;
3266 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3268 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3269 IBasicVideo *pBasicVideo;
3270 HRESULT hr;
3272 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3274 EnterCriticalSection(&This->cs);
3276 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3278 if (hr == S_OK)
3279 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3281 LeaveCriticalSection(&This->cs);
3283 return hr;
3286 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3288 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3289 IBasicVideo *pBasicVideo;
3290 HRESULT hr;
3292 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3294 EnterCriticalSection(&This->cs);
3296 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3298 if (hr == S_OK)
3299 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3301 LeaveCriticalSection(&This->cs);
3303 return hr;
3306 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3308 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3309 IBasicVideo *pBasicVideo;
3310 HRESULT hr;
3312 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3314 EnterCriticalSection(&This->cs);
3316 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3318 if (hr == S_OK)
3319 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3321 LeaveCriticalSection(&This->cs);
3323 return hr;
3326 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3328 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3329 IBasicVideo *pBasicVideo;
3330 HRESULT hr;
3332 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3334 EnterCriticalSection(&This->cs);
3336 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3338 if (hr == S_OK)
3339 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3341 LeaveCriticalSection(&This->cs);
3343 return hr;
3346 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3348 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3349 IBasicVideo *pBasicVideo;
3350 HRESULT hr;
3352 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3354 EnterCriticalSection(&This->cs);
3356 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3358 if (hr == S_OK)
3359 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3361 LeaveCriticalSection(&This->cs);
3363 return hr;
3366 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3368 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3369 IBasicVideo *pBasicVideo;
3370 HRESULT hr;
3372 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3374 EnterCriticalSection(&This->cs);
3376 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3378 if (hr == S_OK)
3379 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3381 LeaveCriticalSection(&This->cs);
3383 return hr;
3386 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3388 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3389 IBasicVideo *pBasicVideo;
3390 HRESULT hr;
3392 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3394 EnterCriticalSection(&This->cs);
3396 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3398 if (hr == S_OK)
3399 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3401 LeaveCriticalSection(&This->cs);
3403 return hr;
3406 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3408 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3409 IBasicVideo *pBasicVideo;
3410 HRESULT hr;
3412 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3414 EnterCriticalSection(&This->cs);
3416 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3418 if (hr == S_OK)
3419 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3421 LeaveCriticalSection(&This->cs);
3423 return hr;
3426 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3428 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3429 IBasicVideo *pBasicVideo;
3430 HRESULT hr;
3432 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3434 EnterCriticalSection(&This->cs);
3436 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3438 if (hr == S_OK)
3439 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3441 LeaveCriticalSection(&This->cs);
3443 return hr;
3446 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3448 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3449 IBasicVideo *pBasicVideo;
3450 HRESULT hr;
3452 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3454 EnterCriticalSection(&This->cs);
3456 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3458 if (hr == S_OK)
3459 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3461 LeaveCriticalSection(&This->cs);
3463 return hr;
3466 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3467 LONG *pDestinationHeight)
3469 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3470 IBasicVideo *pBasicVideo;
3471 HRESULT hr;
3473 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3475 EnterCriticalSection(&This->cs);
3477 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3479 if (hr == S_OK)
3480 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3482 LeaveCriticalSection(&This->cs);
3484 return hr;
3487 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3488 LONG Width, LONG Height)
3490 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3491 IBasicVideo *pBasicVideo;
3492 HRESULT hr;
3494 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3496 EnterCriticalSection(&This->cs);
3498 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3500 if (hr == S_OK)
3501 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3503 LeaveCriticalSection(&This->cs);
3505 return hr;
3508 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3509 LONG *pWidth, LONG *pHeight)
3511 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3512 IBasicVideo *pBasicVideo;
3513 HRESULT hr;
3515 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3517 EnterCriticalSection(&This->cs);
3519 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3521 if (hr == S_OK)
3522 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3524 LeaveCriticalSection(&This->cs);
3526 return hr;
3529 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3531 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3532 IBasicVideo *pBasicVideo;
3533 HRESULT hr;
3535 TRACE("(%p/%p)->()\n", This, iface);
3537 EnterCriticalSection(&This->cs);
3539 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3541 if (hr == S_OK)
3542 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3544 LeaveCriticalSection(&This->cs);
3546 return hr;
3549 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3550 LONG Width, LONG Height)
3552 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3553 IBasicVideo *pBasicVideo;
3554 HRESULT hr;
3556 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3558 EnterCriticalSection(&This->cs);
3560 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3562 if (hr == S_OK)
3563 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3565 LeaveCriticalSection(&This->cs);
3567 return hr;
3570 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3571 LONG *pTop, LONG *pWidth, LONG *pHeight)
3573 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3574 IBasicVideo *pBasicVideo;
3575 HRESULT hr;
3577 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3579 EnterCriticalSection(&This->cs);
3581 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3583 if (hr == S_OK)
3584 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3586 LeaveCriticalSection(&This->cs);
3588 return hr;
3591 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3593 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3594 IBasicVideo *pBasicVideo;
3595 HRESULT hr;
3597 TRACE("(%p/%p)->()\n", This, iface);
3599 EnterCriticalSection(&This->cs);
3601 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3603 if (hr == S_OK)
3604 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3606 LeaveCriticalSection(&This->cs);
3608 return hr;
3611 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3613 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3614 IBasicVideo *pBasicVideo;
3615 HRESULT hr;
3617 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3619 EnterCriticalSection(&This->cs);
3621 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3623 if (hr == S_OK)
3624 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3626 LeaveCriticalSection(&This->cs);
3628 return hr;
3631 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3632 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3634 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3635 IBasicVideo *pBasicVideo;
3636 HRESULT hr;
3638 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3640 EnterCriticalSection(&This->cs);
3642 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3644 if (hr == S_OK)
3645 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3647 LeaveCriticalSection(&This->cs);
3649 return hr;
3652 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3653 LONG *pDIBImage)
3655 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3656 IBasicVideo *pBasicVideo;
3657 HRESULT hr;
3659 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3661 EnterCriticalSection(&This->cs);
3663 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3665 if (hr == S_OK)
3666 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3668 LeaveCriticalSection(&This->cs);
3670 return hr;
3673 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3675 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3676 IBasicVideo *pBasicVideo;
3677 HRESULT hr;
3679 TRACE("(%p/%p)->()\n", This, iface);
3681 EnterCriticalSection(&This->cs);
3683 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3685 if (hr == S_OK)
3686 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3688 LeaveCriticalSection(&This->cs);
3690 return hr;
3693 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3695 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3696 IBasicVideo *pBasicVideo;
3697 HRESULT hr;
3699 TRACE("(%p/%p)->()\n", This, iface);
3701 EnterCriticalSection(&This->cs);
3703 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3705 if (hr == S_OK)
3706 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3708 LeaveCriticalSection(&This->cs);
3710 return hr;
3713 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3714 LONG *plAspectY)
3716 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3717 IBasicVideo2 *pBasicVideo2;
3718 HRESULT hr;
3720 TRACE("(%p/%p)->()\n", This, iface);
3722 EnterCriticalSection(&This->cs);
3724 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3726 if (hr == S_OK)
3727 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3729 LeaveCriticalSection(&This->cs);
3731 return hr;
3734 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3736 BasicVideo_QueryInterface,
3737 BasicVideo_AddRef,
3738 BasicVideo_Release,
3739 BasicVideo_GetTypeInfoCount,
3740 BasicVideo_GetTypeInfo,
3741 BasicVideo_GetIDsOfNames,
3742 BasicVideo_Invoke,
3743 BasicVideo_get_AvgTimePerFrame,
3744 BasicVideo_get_BitRate,
3745 BasicVideo_get_BitErrorRate,
3746 BasicVideo_get_VideoWidth,
3747 BasicVideo_get_VideoHeight,
3748 BasicVideo_put_SourceLeft,
3749 BasicVideo_get_SourceLeft,
3750 BasicVideo_put_SourceWidth,
3751 BasicVideo_get_SourceWidth,
3752 BasicVideo_put_SourceTop,
3753 BasicVideo_get_SourceTop,
3754 BasicVideo_put_SourceHeight,
3755 BasicVideo_get_SourceHeight,
3756 BasicVideo_put_DestinationLeft,
3757 BasicVideo_get_DestinationLeft,
3758 BasicVideo_put_DestinationWidth,
3759 BasicVideo_get_DestinationWidth,
3760 BasicVideo_put_DestinationTop,
3761 BasicVideo_get_DestinationTop,
3762 BasicVideo_put_DestinationHeight,
3763 BasicVideo_get_DestinationHeight,
3764 BasicVideo_SetSourcePosition,
3765 BasicVideo_GetSourcePosition,
3766 BasicVideo_SetDefaultSourcePosition,
3767 BasicVideo_SetDestinationPosition,
3768 BasicVideo_GetDestinationPosition,
3769 BasicVideo_SetDefaultDestinationPosition,
3770 BasicVideo_GetVideoSize,
3771 BasicVideo_GetVideoPaletteEntries,
3772 BasicVideo_GetCurrentImage,
3773 BasicVideo_IsUsingDefaultSource,
3774 BasicVideo_IsUsingDefaultDestination,
3775 BasicVideo2_GetPreferredAspectRatio
3778 static struct filter_graph *impl_from_IVideoWindow(IVideoWindow *iface)
3780 return CONTAINING_RECORD(iface, struct filter_graph, IVideoWindow_iface);
3783 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID iid, void **out)
3785 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3786 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
3789 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
3791 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3792 return IUnknown_AddRef(graph->outer_unk);
3795 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
3797 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3798 return IUnknown_Release(graph->outer_unk);
3801 HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *count)
3803 TRACE("iface %p, count %p.\n", iface, count);
3804 *count = 1;
3805 return S_OK;
3808 HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT index,
3809 LCID lcid, ITypeInfo **typeinfo)
3811 TRACE("iface %p, index %u, lcid %#x, typeinfo %p.\n", iface, index, lcid, typeinfo);
3812 return strmbase_get_typeinfo(IVideoWindow_tid, typeinfo);
3815 HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID iid,
3816 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
3818 ITypeInfo *typeinfo;
3819 HRESULT hr;
3821 TRACE("iface %p, iid %s, names %p, count %u, lcid %#x, ids %p.\n",
3822 iface, debugstr_guid(iid), names, count, lcid, ids);
3824 if (SUCCEEDED(hr = strmbase_get_typeinfo(IVideoWindow_tid, &typeinfo)))
3826 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
3827 ITypeInfo_Release(typeinfo);
3829 return hr;
3832 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID id, REFIID iid, LCID lcid,
3833 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
3835 ITypeInfo *typeinfo;
3836 HRESULT hr;
3838 TRACE("iface %p, id %d, iid %s, lcid %#x, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
3839 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
3841 if (SUCCEEDED(hr = strmbase_get_typeinfo(IVideoWindow_tid, &typeinfo)))
3843 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
3844 ITypeInfo_Release(typeinfo);
3846 return hr;
3849 /*** IVideoWindow methods ***/
3850 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
3852 struct filter_graph *This = impl_from_IVideoWindow(iface);
3853 IVideoWindow *pVideoWindow;
3854 HRESULT hr;
3856 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
3858 EnterCriticalSection(&This->cs);
3860 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3862 if (hr == S_OK)
3863 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
3865 LeaveCriticalSection(&This->cs);
3867 return hr;
3870 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
3872 struct filter_graph *This = impl_from_IVideoWindow(iface);
3873 IVideoWindow *pVideoWindow;
3874 HRESULT hr;
3876 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
3878 EnterCriticalSection(&This->cs);
3880 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3882 if (hr == S_OK)
3883 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
3885 LeaveCriticalSection(&This->cs);
3887 return hr;
3890 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
3892 struct filter_graph *This = impl_from_IVideoWindow(iface);
3893 IVideoWindow *pVideoWindow;
3894 HRESULT hr;
3896 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
3898 EnterCriticalSection(&This->cs);
3900 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3902 if (hr == S_OK)
3903 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
3905 LeaveCriticalSection(&This->cs);
3907 return hr;
3910 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
3912 struct filter_graph *This = impl_from_IVideoWindow(iface);
3913 IVideoWindow *pVideoWindow;
3914 HRESULT hr;
3916 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
3918 EnterCriticalSection(&This->cs);
3920 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3922 if (hr == S_OK)
3923 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
3925 LeaveCriticalSection(&This->cs);
3927 return hr;
3930 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
3932 struct filter_graph *This = impl_from_IVideoWindow(iface);
3933 IVideoWindow *pVideoWindow;
3934 HRESULT hr;
3936 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
3938 EnterCriticalSection(&This->cs);
3940 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3942 if (hr == S_OK)
3943 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
3945 LeaveCriticalSection(&This->cs);
3947 return hr;
3950 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
3952 struct filter_graph *This = impl_from_IVideoWindow(iface);
3953 IVideoWindow *pVideoWindow;
3954 HRESULT hr;
3956 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
3958 EnterCriticalSection(&This->cs);
3960 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3962 if (hr == S_OK)
3963 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
3965 LeaveCriticalSection(&This->cs);
3967 return hr;
3970 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
3972 struct filter_graph *This = impl_from_IVideoWindow(iface);
3973 IVideoWindow *pVideoWindow;
3974 HRESULT hr;
3976 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
3978 EnterCriticalSection(&This->cs);
3980 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3982 if (hr == S_OK)
3983 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
3985 LeaveCriticalSection(&This->cs);
3987 return hr;
3990 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
3992 struct filter_graph *This = impl_from_IVideoWindow(iface);
3993 IVideoWindow *pVideoWindow;
3994 HRESULT hr;
3996 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
3998 EnterCriticalSection(&This->cs);
4000 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4002 if (hr == S_OK)
4003 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4005 LeaveCriticalSection(&This->cs);
4007 return hr;
4010 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
4012 struct filter_graph *This = impl_from_IVideoWindow(iface);
4013 IVideoWindow *pVideoWindow;
4014 HRESULT hr;
4016 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4018 EnterCriticalSection(&This->cs);
4020 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4022 if (hr == S_OK)
4023 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4025 LeaveCriticalSection(&This->cs);
4027 return hr;
4030 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4032 struct filter_graph *This = impl_from_IVideoWindow(iface);
4033 IVideoWindow *pVideoWindow;
4034 HRESULT hr;
4036 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4038 EnterCriticalSection(&This->cs);
4040 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4042 if (hr == S_OK)
4043 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4045 LeaveCriticalSection(&This->cs);
4047 return hr;
4050 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4052 struct filter_graph *This = impl_from_IVideoWindow(iface);
4053 IVideoWindow *pVideoWindow;
4054 HRESULT hr;
4056 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4058 EnterCriticalSection(&This->cs);
4060 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4062 if (hr == S_OK)
4063 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4065 LeaveCriticalSection(&This->cs);
4067 return hr;
4070 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4071 LONG *pBackgroundPalette)
4073 struct filter_graph *This = impl_from_IVideoWindow(iface);
4074 IVideoWindow *pVideoWindow;
4075 HRESULT hr;
4077 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4079 EnterCriticalSection(&This->cs);
4081 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4083 if (hr == S_OK)
4084 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4086 LeaveCriticalSection(&This->cs);
4088 return hr;
4091 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4093 struct filter_graph *This = impl_from_IVideoWindow(iface);
4094 IVideoWindow *pVideoWindow;
4095 HRESULT hr;
4097 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4099 EnterCriticalSection(&This->cs);
4101 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4103 if (hr == S_OK)
4104 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4106 LeaveCriticalSection(&This->cs);
4108 return hr;
4111 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4113 struct filter_graph *This = impl_from_IVideoWindow(iface);
4114 IVideoWindow *pVideoWindow;
4115 HRESULT hr;
4117 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4119 EnterCriticalSection(&This->cs);
4121 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4123 if (hr == S_OK)
4124 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4126 LeaveCriticalSection(&This->cs);
4128 return hr;
4131 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4133 struct filter_graph *This = impl_from_IVideoWindow(iface);
4134 IVideoWindow *pVideoWindow;
4135 HRESULT hr;
4137 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4139 EnterCriticalSection(&This->cs);
4141 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4143 if (hr == S_OK)
4144 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4146 LeaveCriticalSection(&This->cs);
4148 return hr;
4151 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4153 struct filter_graph *This = impl_from_IVideoWindow(iface);
4154 IVideoWindow *pVideoWindow;
4155 HRESULT hr;
4157 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4159 EnterCriticalSection(&This->cs);
4161 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4163 if (hr == S_OK)
4164 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4166 LeaveCriticalSection(&This->cs);
4168 return hr;
4171 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4173 struct filter_graph *This = impl_from_IVideoWindow(iface);
4174 IVideoWindow *pVideoWindow;
4175 HRESULT hr;
4177 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4179 EnterCriticalSection(&This->cs);
4181 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4183 if (hr == S_OK)
4184 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4186 LeaveCriticalSection(&This->cs);
4188 return hr;
4191 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4193 struct filter_graph *This = impl_from_IVideoWindow(iface);
4194 IVideoWindow *pVideoWindow;
4195 HRESULT hr;
4197 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4199 EnterCriticalSection(&This->cs);
4201 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4203 if (hr == S_OK)
4204 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4206 LeaveCriticalSection(&This->cs);
4208 return hr;
4211 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4213 struct filter_graph *This = impl_from_IVideoWindow(iface);
4214 IVideoWindow *pVideoWindow;
4215 HRESULT hr;
4217 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4219 EnterCriticalSection(&This->cs);
4221 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4223 if (hr == S_OK)
4224 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4226 LeaveCriticalSection(&This->cs);
4228 return hr;
4231 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4233 struct filter_graph *This = impl_from_IVideoWindow(iface);
4234 IVideoWindow *pVideoWindow;
4235 HRESULT hr;
4237 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4239 EnterCriticalSection(&This->cs);
4241 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4243 if (hr == S_OK)
4244 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4246 LeaveCriticalSection(&This->cs);
4248 return hr;
4251 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4253 struct filter_graph *This = impl_from_IVideoWindow(iface);
4254 IVideoWindow *pVideoWindow;
4255 HRESULT hr;
4257 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4259 EnterCriticalSection(&This->cs);
4261 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4263 if (hr == S_OK)
4264 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4266 LeaveCriticalSection(&This->cs);
4268 return hr;
4271 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4273 struct filter_graph *This = impl_from_IVideoWindow(iface);
4274 IVideoWindow *pVideoWindow;
4275 HRESULT hr;
4277 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4279 EnterCriticalSection(&This->cs);
4281 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4283 if (hr == S_OK)
4284 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4286 LeaveCriticalSection(&This->cs);
4288 return hr;
4291 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4293 struct filter_graph *This = impl_from_IVideoWindow(iface);
4294 IVideoWindow *pVideoWindow;
4295 HRESULT hr;
4297 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4299 EnterCriticalSection(&This->cs);
4301 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4303 if (hr == S_OK)
4304 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4306 LeaveCriticalSection(&This->cs);
4308 return hr;
4311 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4313 struct filter_graph *This = impl_from_IVideoWindow(iface);
4314 IVideoWindow *pVideoWindow;
4315 HRESULT hr;
4317 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4319 EnterCriticalSection(&This->cs);
4321 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4323 if (hr == S_OK)
4324 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4326 LeaveCriticalSection(&This->cs);
4328 return hr;
4331 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4333 struct filter_graph *This = impl_from_IVideoWindow(iface);
4334 IVideoWindow *pVideoWindow;
4335 HRESULT hr;
4337 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4339 EnterCriticalSection(&This->cs);
4341 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4343 if (hr == S_OK)
4344 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4346 LeaveCriticalSection(&This->cs);
4348 return hr;
4351 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4353 struct filter_graph *This = impl_from_IVideoWindow(iface);
4354 IVideoWindow *pVideoWindow;
4355 HRESULT hr;
4357 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4359 EnterCriticalSection(&This->cs);
4361 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4363 if (hr == S_OK)
4364 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4366 LeaveCriticalSection(&This->cs);
4368 return hr;
4371 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4373 struct filter_graph *This = impl_from_IVideoWindow(iface);
4374 IVideoWindow *pVideoWindow;
4375 HRESULT hr;
4377 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4379 EnterCriticalSection(&This->cs);
4381 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4383 if (hr == S_OK)
4384 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4386 LeaveCriticalSection(&This->cs);
4388 return hr;
4391 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4393 struct filter_graph *This = impl_from_IVideoWindow(iface);
4394 IVideoWindow *pVideoWindow;
4395 HRESULT hr;
4397 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4399 EnterCriticalSection(&This->cs);
4401 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4403 if (hr == S_OK)
4404 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4406 LeaveCriticalSection(&This->cs);
4408 return hr;
4411 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4413 struct filter_graph *This = impl_from_IVideoWindow(iface);
4414 IVideoWindow *pVideoWindow;
4415 HRESULT hr;
4417 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4419 EnterCriticalSection(&This->cs);
4421 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4423 if (hr == S_OK)
4424 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4426 LeaveCriticalSection(&This->cs);
4428 return hr;
4431 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4433 struct filter_graph *This = impl_from_IVideoWindow(iface);
4434 IVideoWindow *pVideoWindow;
4435 HRESULT hr;
4437 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4439 EnterCriticalSection(&This->cs);
4441 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4443 if (hr == S_OK)
4444 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4446 LeaveCriticalSection(&This->cs);
4448 return hr;
4451 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4453 struct filter_graph *This = impl_from_IVideoWindow(iface);
4454 IVideoWindow *pVideoWindow;
4455 HRESULT hr;
4457 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4459 EnterCriticalSection(&This->cs);
4461 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4463 if (hr == S_OK)
4464 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4466 LeaveCriticalSection(&This->cs);
4468 return hr;
4471 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4472 LONG_PTR wParam, LONG_PTR lParam)
4474 struct filter_graph *This = impl_from_IVideoWindow(iface);
4475 IVideoWindow *pVideoWindow;
4476 HRESULT hr;
4478 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4480 EnterCriticalSection(&This->cs);
4482 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4484 if (hr == S_OK)
4485 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4487 LeaveCriticalSection(&This->cs);
4489 return hr;
4492 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4493 LONG Width, LONG Height)
4495 struct filter_graph *This = impl_from_IVideoWindow(iface);
4496 IVideoWindow *pVideoWindow;
4497 HRESULT hr;
4499 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4501 EnterCriticalSection(&This->cs);
4503 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4505 if (hr == S_OK)
4506 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4508 LeaveCriticalSection(&This->cs);
4510 return hr;
4513 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4514 LONG *pWidth, LONG *pHeight)
4516 struct filter_graph *This = impl_from_IVideoWindow(iface);
4517 IVideoWindow *pVideoWindow;
4518 HRESULT hr;
4520 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4522 EnterCriticalSection(&This->cs);
4524 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4526 if (hr == S_OK)
4527 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4529 LeaveCriticalSection(&This->cs);
4531 return hr;
4534 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4535 LONG *pHeight)
4537 struct filter_graph *This = impl_from_IVideoWindow(iface);
4538 IVideoWindow *pVideoWindow;
4539 HRESULT hr;
4541 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4543 EnterCriticalSection(&This->cs);
4545 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4547 if (hr == S_OK)
4548 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4550 LeaveCriticalSection(&This->cs);
4552 return hr;
4555 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4556 LONG *pHeight)
4558 struct filter_graph *This = impl_from_IVideoWindow(iface);
4559 IVideoWindow *pVideoWindow;
4560 HRESULT hr;
4562 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4564 EnterCriticalSection(&This->cs);
4566 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4568 if (hr == S_OK)
4569 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4571 LeaveCriticalSection(&This->cs);
4573 return hr;
4576 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4577 LONG *pWidth, LONG *pHeight)
4579 struct filter_graph *This = impl_from_IVideoWindow(iface);
4580 IVideoWindow *pVideoWindow;
4581 HRESULT hr;
4583 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4585 EnterCriticalSection(&This->cs);
4587 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4589 if (hr == S_OK)
4590 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4592 LeaveCriticalSection(&This->cs);
4594 return hr;
4597 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4599 struct filter_graph *This = impl_from_IVideoWindow(iface);
4600 IVideoWindow *pVideoWindow;
4601 HRESULT hr;
4603 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4605 EnterCriticalSection(&This->cs);
4607 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4609 if (hr == S_OK)
4610 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4612 LeaveCriticalSection(&This->cs);
4614 return hr;
4617 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4619 struct filter_graph *This = impl_from_IVideoWindow(iface);
4620 IVideoWindow *pVideoWindow;
4621 HRESULT hr;
4623 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4625 EnterCriticalSection(&This->cs);
4627 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4629 if (hr == S_OK)
4630 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4632 LeaveCriticalSection(&This->cs);
4634 return hr;
4638 static const IVideoWindowVtbl IVideoWindow_VTable =
4640 VideoWindow_QueryInterface,
4641 VideoWindow_AddRef,
4642 VideoWindow_Release,
4643 VideoWindow_GetTypeInfoCount,
4644 VideoWindow_GetTypeInfo,
4645 VideoWindow_GetIDsOfNames,
4646 VideoWindow_Invoke,
4647 VideoWindow_put_Caption,
4648 VideoWindow_get_Caption,
4649 VideoWindow_put_WindowStyle,
4650 VideoWindow_get_WindowStyle,
4651 VideoWindow_put_WindowStyleEx,
4652 VideoWindow_get_WindowStyleEx,
4653 VideoWindow_put_AutoShow,
4654 VideoWindow_get_AutoShow,
4655 VideoWindow_put_WindowState,
4656 VideoWindow_get_WindowState,
4657 VideoWindow_put_BackgroundPalette,
4658 VideoWindow_get_BackgroundPalette,
4659 VideoWindow_put_Visible,
4660 VideoWindow_get_Visible,
4661 VideoWindow_put_Left,
4662 VideoWindow_get_Left,
4663 VideoWindow_put_Width,
4664 VideoWindow_get_Width,
4665 VideoWindow_put_Top,
4666 VideoWindow_get_Top,
4667 VideoWindow_put_Height,
4668 VideoWindow_get_Height,
4669 VideoWindow_put_Owner,
4670 VideoWindow_get_Owner,
4671 VideoWindow_put_MessageDrain,
4672 VideoWindow_get_MessageDrain,
4673 VideoWindow_get_BorderColor,
4674 VideoWindow_put_BorderColor,
4675 VideoWindow_get_FullScreenMode,
4676 VideoWindow_put_FullScreenMode,
4677 VideoWindow_SetWindowForeground,
4678 VideoWindow_NotifyOwnerMessage,
4679 VideoWindow_SetWindowPosition,
4680 VideoWindow_GetWindowPosition,
4681 VideoWindow_GetMinIdealImageSize,
4682 VideoWindow_GetMaxIdealImageSize,
4683 VideoWindow_GetRestorePosition,
4684 VideoWindow_HideCursor,
4685 VideoWindow_IsCursorHidden
4688 static struct filter_graph *impl_from_IMediaEventEx(IMediaEventEx *iface)
4690 return CONTAINING_RECORD(iface, struct filter_graph, IMediaEventEx_iface);
4693 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID iid, void **out)
4695 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4696 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
4699 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
4701 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4702 return IUnknown_AddRef(graph->outer_unk);
4705 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
4707 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4708 return IUnknown_Release(graph->outer_unk);
4711 /*** IDispatch methods ***/
4712 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *pctinfo)
4714 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4716 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
4718 return S_OK;
4721 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT iTInfo, LCID lcid,
4722 ITypeInfo **ppTInfo)
4724 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4726 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
4728 return S_OK;
4731 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID riid,
4732 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4734 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4736 TRACE("(%p/%p)->(%s, %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), rgszNames,
4737 cNames, lcid, rgDispId);
4739 return S_OK;
4742 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID dispIdMember, REFIID riid,
4743 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4744 UINT *puArgErr)
4746 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4748 TRACE("(%p/%p)->(%d, %s, %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember,
4749 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4751 return S_OK;
4754 /*** IMediaEvent methods ***/
4755 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *event)
4757 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4759 TRACE("graph %p, event %p.\n", graph, event);
4761 *event = (OAEVENT)graph->media_event_handle;
4762 return S_OK;
4765 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *code,
4766 LONG_PTR *param1, LONG_PTR *param2, LONG timeout)
4768 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4769 struct media_event *event;
4770 struct list *entry;
4772 TRACE("graph %p, code %p, param1 %p, param2 %p, timeout %d.\n", graph, code, param1, param2, timeout);
4774 *code = 0;
4776 if (WaitForSingleObject(graph->media_event_handle, timeout))
4777 return E_ABORT;
4779 EnterCriticalSection(&graph->event_cs);
4781 if (!(entry = list_head(&graph->media_events)))
4783 ResetEvent(graph->media_event_handle);
4784 LeaveCriticalSection(&graph->event_cs);
4785 return E_ABORT;
4787 event = LIST_ENTRY(entry, struct media_event, entry);
4788 list_remove(&event->entry);
4789 *code = event->code;
4790 *param1 = event->param1;
4791 *param2 = event->param2;
4792 free(event);
4794 LeaveCriticalSection(&graph->event_cs);
4795 return S_OK;
4798 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
4799 LONG *pEvCode)
4801 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4803 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
4805 if (This->state != State_Running)
4806 return VFW_E_WRONG_STATE;
4808 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
4810 *pEvCode = This->CompletionStatus;
4811 return S_OK;
4814 *pEvCode = 0;
4815 return E_ABORT;
4818 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
4820 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4822 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4824 if (lEvCode == EC_COMPLETE)
4825 This->HandleEcComplete = FALSE;
4826 else if (lEvCode == EC_REPAINT)
4827 This->HandleEcRepaint = FALSE;
4828 else if (lEvCode == EC_CLOCK_CHANGED)
4829 This->HandleEcClockChanged = FALSE;
4830 else
4831 return S_FALSE;
4833 return S_OK;
4836 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
4838 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4840 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
4842 if (lEvCode == EC_COMPLETE)
4843 This->HandleEcComplete = TRUE;
4844 else if (lEvCode == EC_REPAINT)
4845 This->HandleEcRepaint = TRUE;
4846 else if (lEvCode == EC_CLOCK_CHANGED)
4847 This->HandleEcClockChanged = TRUE;
4848 else
4849 return S_FALSE;
4851 return S_OK;
4854 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG lEvCode,
4855 LONG_PTR lParam1, LONG_PTR lParam2)
4857 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4859 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
4861 return S_OK;
4864 /*** IMediaEventEx methods ***/
4865 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface,
4866 OAHWND window, LONG message, LONG_PTR lparam)
4868 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4870 TRACE("graph %p, window %#Ix, message %#x, lparam %#Ix.\n", graph, window, message, lparam);
4872 graph->media_event_window = (HWND)window;
4873 graph->media_event_message = message;
4874 graph->media_event_lparam = lparam;
4876 return S_OK;
4879 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG flags)
4881 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4883 TRACE("graph %p, flags %#x.\n", graph, flags);
4885 if (flags & ~AM_MEDIAEVENT_NONOTIFY)
4887 WARN("Invalid flags %#x, returning E_INVALIDARG.\n", flags);
4888 return E_INVALIDARG;
4891 graph->media_events_disabled = flags;
4893 if (flags)
4895 flush_media_events(graph);
4896 ResetEvent(graph->media_event_handle);
4899 return S_OK;
4902 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *flags)
4904 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4906 TRACE("graph %p, flags %p.\n", graph, flags);
4908 if (!flags)
4909 return E_POINTER;
4911 *flags = graph->media_events_disabled;
4913 return S_OK;
4917 static const IMediaEventExVtbl IMediaEventEx_VTable =
4919 MediaEvent_QueryInterface,
4920 MediaEvent_AddRef,
4921 MediaEvent_Release,
4922 MediaEvent_GetTypeInfoCount,
4923 MediaEvent_GetTypeInfo,
4924 MediaEvent_GetIDsOfNames,
4925 MediaEvent_Invoke,
4926 MediaEvent_GetEventHandle,
4927 MediaEvent_GetEvent,
4928 MediaEvent_WaitForCompletion,
4929 MediaEvent_CancelDefaultHandling,
4930 MediaEvent_RestoreDefaultHandling,
4931 MediaEvent_FreeEventParams,
4932 MediaEvent_SetNotifyWindow,
4933 MediaEvent_SetNotifyFlags,
4934 MediaEvent_GetNotifyFlags
4938 static struct filter_graph *impl_from_IMediaFilter(IMediaFilter *iface)
4940 return CONTAINING_RECORD(iface, struct filter_graph, IMediaFilter_iface);
4943 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID iid, void **out)
4945 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4947 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
4950 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
4952 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4954 return IUnknown_AddRef(graph->outer_unk);
4957 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
4959 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4961 return IUnknown_Release(graph->outer_unk);
4964 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
4966 FIXME("(%p): stub\n", pClassID);
4968 return E_NOTIMPL;
4971 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
4973 struct filter_graph *graph = impl_from_IMediaFilter(iface);
4974 HRESULT hr = S_OK, filter_hr;
4975 struct filter *filter;
4976 TP_WORK *work;
4978 TRACE("graph %p.\n", graph);
4980 EnterCriticalSection(&graph->cs);
4982 if (graph->state == State_Stopped)
4984 LeaveCriticalSection(&graph->cs);
4985 return S_OK;
4988 sort_filters(graph);
4990 if (graph->state == State_Running)
4992 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
4994 filter_hr = IBaseFilter_Pause(filter->filter);
4995 if (hr == S_OK)
4996 hr = filter_hr;
5000 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5002 filter_hr = IBaseFilter_Stop(filter->filter);
5003 if (hr == S_OK)
5004 hr = filter_hr;
5007 graph->state = State_Stopped;
5008 graph->needs_async_run = 0;
5009 work = graph->async_run_work;
5010 graph->got_ec_complete = 0;
5012 /* Update the current position, probably to synchronize multiple streams. */
5013 IMediaSeeking_SetPositions(&graph->IMediaSeeking_iface, &graph->current_pos,
5014 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
5016 LeaveCriticalSection(&graph->cs);
5018 if (work)
5019 WaitForThreadpoolWorkCallbacks(work, TRUE);
5021 return hr;
5024 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5026 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5027 HRESULT hr = S_OK, filter_hr;
5028 struct filter *filter;
5029 TP_WORK *work;
5031 TRACE("graph %p.\n", graph);
5033 EnterCriticalSection(&graph->cs);
5035 if (graph->state == State_Paused)
5037 LeaveCriticalSection(&graph->cs);
5038 return S_OK;
5041 sort_filters(graph);
5043 EnterCriticalSection(&graph->event_cs);
5044 update_render_count(graph);
5045 LeaveCriticalSection(&graph->event_cs);
5047 if (graph->defaultclock && !graph->refClock)
5048 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
5050 if (graph->state == State_Running && graph->refClock)
5052 REFERENCE_TIME time;
5053 IReferenceClock_GetTime(graph->refClock, &time);
5054 graph->stream_elapsed += time - graph->stream_start;
5055 graph->current_pos += graph->stream_elapsed;
5058 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5060 filter_hr = IBaseFilter_Pause(filter->filter);
5061 if (hr == S_OK)
5062 hr = filter_hr;
5065 graph->state = State_Paused;
5066 graph->needs_async_run = 0;
5067 work = graph->async_run_work;
5069 LeaveCriticalSection(&graph->cs);
5071 if (work)
5072 WaitForThreadpoolWorkCallbacks(work, TRUE);
5074 return hr;
5077 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME start)
5079 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5080 HRESULT hr;
5082 TRACE("graph %p, start %s.\n", graph, debugstr_time(start));
5084 EnterCriticalSection(&graph->cs);
5086 if (graph->state == State_Running)
5088 LeaveCriticalSection(&graph->cs);
5089 return S_OK;
5092 sort_filters(graph);
5094 hr = graph_start(graph, start);
5096 graph->state = State_Running;
5097 graph->needs_async_run = 0;
5099 LeaveCriticalSection(&graph->cs);
5100 return hr;
5103 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD timeout, FILTER_STATE *state)
5105 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5106 DWORD end = GetTickCount() + timeout;
5107 HRESULT hr;
5109 TRACE("graph %p, timeout %u, state %p.\n", graph, timeout, state);
5111 if (!state)
5112 return E_POINTER;
5114 /* Thread safety is a little tricky here. GetState() shouldn't block other
5115 * functions from being called on the filter graph. However, we can't just
5116 * call IBaseFilter::GetState() in one loop and drop the lock on every
5117 * iteration, since the filter list might change beneath us. So instead we
5118 * do what native does, and poll for it every 10 ms. */
5120 EnterCriticalSection(&graph->cs);
5121 *state = graph->state;
5123 for (;;)
5125 IBaseFilter *async_filter = NULL;
5126 FILTER_STATE filter_state;
5127 struct filter *filter;
5129 hr = S_OK;
5131 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5133 HRESULT filter_hr = IBaseFilter_GetState(filter->filter, 0, &filter_state);
5135 TRACE("Filter %p returned hr %#x, state %u.\n", filter->filter, filter_hr, filter_state);
5137 if (filter_hr == VFW_S_STATE_INTERMEDIATE)
5138 async_filter = filter->filter;
5140 if (hr == S_OK && filter_hr == VFW_S_STATE_INTERMEDIATE)
5141 hr = VFW_S_STATE_INTERMEDIATE;
5142 else if (filter_hr != S_OK && filter_hr != VFW_S_STATE_INTERMEDIATE)
5143 hr = filter_hr;
5145 if (hr == S_OK && filter_state == State_Paused && graph->state != State_Paused)
5147 async_filter = filter->filter;
5148 hr = VFW_S_STATE_INTERMEDIATE;
5150 else if (filter_state != graph->state && filter_state != State_Paused)
5151 hr = E_FAIL;
5153 if (graph->needs_async_run)
5155 if (filter_state != State_Paused && filter_state != State_Running)
5156 ERR("Filter %p reported incorrect state %u (expected %u or %u).\n",
5157 filter->filter, filter_state, State_Paused, State_Running);
5159 else
5161 if (filter_state != graph->state)
5162 ERR("Filter %p reported incorrect state %u (expected %u).\n",
5163 filter->filter, filter_state, graph->state);
5167 LeaveCriticalSection(&graph->cs);
5169 if (hr != VFW_S_STATE_INTERMEDIATE || (timeout != INFINITE && GetTickCount() >= end))
5170 break;
5172 IBaseFilter_GetState(async_filter, 10, &filter_state);
5174 EnterCriticalSection(&graph->cs);
5177 TRACE("Returning %#x, state %u.\n", hr, *state);
5178 return hr;
5181 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5183 struct filter_graph *This = impl_from_IMediaFilter(iface);
5184 struct filter *filter;
5185 HRESULT hr = S_OK;
5187 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
5189 EnterCriticalSection(&This->cs);
5191 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
5193 hr = IBaseFilter_SetSyncSource(filter->filter, pClock);
5194 if (FAILED(hr))
5195 break;
5198 if (FAILED(hr))
5200 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
5201 IBaseFilter_SetSyncSource(filter->filter, This->refClock);
5203 else
5205 if (This->refClock)
5206 IReferenceClock_Release(This->refClock);
5207 This->refClock = pClock;
5208 if (This->refClock)
5209 IReferenceClock_AddRef(This->refClock);
5210 This->defaultclock = FALSE;
5212 if (This->HandleEcClockChanged)
5214 IMediaEventSink *pEventSink;
5215 HRESULT eshr;
5217 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (void **)&pEventSink);
5218 if (SUCCEEDED(eshr))
5220 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5221 IMediaEventSink_Release(pEventSink);
5226 LeaveCriticalSection(&This->cs);
5228 return hr;
5231 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5233 struct filter_graph *This = impl_from_IMediaFilter(iface);
5235 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
5237 if (!ppClock)
5238 return E_POINTER;
5240 EnterCriticalSection(&This->cs);
5242 *ppClock = This->refClock;
5243 if (*ppClock)
5244 IReferenceClock_AddRef(*ppClock);
5246 LeaveCriticalSection(&This->cs);
5248 return S_OK;
5251 static const IMediaFilterVtbl IMediaFilter_VTable =
5253 MediaFilter_QueryInterface,
5254 MediaFilter_AddRef,
5255 MediaFilter_Release,
5256 MediaFilter_GetClassID,
5257 MediaFilter_Stop,
5258 MediaFilter_Pause,
5259 MediaFilter_Run,
5260 MediaFilter_GetState,
5261 MediaFilter_SetSyncSource,
5262 MediaFilter_GetSyncSource
5265 static struct filter_graph *impl_from_IMediaEventSink(IMediaEventSink *iface)
5267 return CONTAINING_RECORD(iface, struct filter_graph, IMediaEventSink_iface);
5270 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID iid, void **out)
5272 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5274 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5277 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5279 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5281 return IUnknown_AddRef(graph->outer_unk);
5284 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5286 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5288 return IUnknown_Release(graph->outer_unk);
5291 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG code,
5292 LONG_PTR param1, LONG_PTR param2)
5294 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5296 TRACE("graph %p, code %#x, param1 %#Ix, param2 %#Ix.\n", graph, code, param1, param2);
5298 EnterCriticalSection(&graph->event_cs);
5300 if (code == EC_COMPLETE && graph->HandleEcComplete)
5302 if (++graph->EcCompleteCount == graph->nRenderers)
5304 if (graph->media_events_disabled)
5305 SetEvent(graph->media_event_handle);
5306 else
5307 queue_media_event(graph, EC_COMPLETE, S_OK, 0);
5308 graph->CompletionStatus = EC_COMPLETE;
5309 graph->got_ec_complete = 1;
5310 SetEvent(graph->hEventCompletion);
5313 else if ((code == EC_REPAINT) && graph->HandleEcRepaint)
5315 FIXME("EC_REPAINT is not handled.\n");
5317 else if (!graph->media_events_disabled)
5319 queue_media_event(graph, code, param1, param2);
5322 LeaveCriticalSection(&graph->event_cs);
5323 return S_OK;
5326 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5328 MediaEventSink_QueryInterface,
5329 MediaEventSink_AddRef,
5330 MediaEventSink_Release,
5331 MediaEventSink_Notify
5334 static struct filter_graph *impl_from_IGraphConfig(IGraphConfig *iface)
5336 return CONTAINING_RECORD(iface, struct filter_graph, IGraphConfig_iface);
5339 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID iid, void **out)
5341 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5343 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5346 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5348 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5350 return IUnknown_AddRef(graph->outer_unk);
5353 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5355 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5357 return IUnknown_Release(graph->outer_unk);
5360 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *pOutputPin, IPin *pInputPin,
5361 const AM_MEDIA_TYPE *pmtFirstConnection, IBaseFilter *pUsingFilter, HANDLE hAbortEvent,
5362 DWORD dwFlags)
5364 struct filter_graph *This = impl_from_IGraphConfig(iface);
5366 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5367 strmbase_dump_media_type(pmtFirstConnection);
5369 return E_NOTIMPL;
5372 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface, IGraphConfigCallback *pCallback,
5373 void *pvContext, DWORD dwFlags, HANDLE hAbortEvent)
5375 struct filter_graph *This = impl_from_IGraphConfig(iface);
5376 HRESULT hr;
5378 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5380 if (hAbortEvent)
5381 FIXME("The parameter hAbortEvent is not handled!\n");
5383 EnterCriticalSection(&This->cs);
5385 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5387 LeaveCriticalSection(&This->cs);
5389 return hr;
5392 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5394 struct filter_graph *This = impl_from_IGraphConfig(iface);
5396 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5398 return E_NOTIMPL;
5401 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5403 struct filter_graph *This = impl_from_IGraphConfig(iface);
5405 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5407 return E_NOTIMPL;
5410 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5412 struct filter_graph *This = impl_from_IGraphConfig(iface);
5414 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5416 return E_NOTIMPL;
5419 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5421 struct filter_graph *This = impl_from_IGraphConfig(iface);
5423 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5425 return E_NOTIMPL;
5428 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5429 IPinConnection *pConnection, HANDLE hEventAbort)
5431 struct filter_graph *This = impl_from_IGraphConfig(iface);
5433 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5435 return E_NOTIMPL;
5438 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5439 DWORD dwFlags)
5441 struct filter_graph *This = impl_from_IGraphConfig(iface);
5443 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5445 return E_NOTIMPL;
5448 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5449 DWORD *dwFlags)
5451 struct filter_graph *This = impl_from_IGraphConfig(iface);
5453 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5455 return E_NOTIMPL;
5458 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *pFilter,
5459 DWORD dwFlags)
5461 struct filter_graph *This = impl_from_IGraphConfig(iface);
5463 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5465 return E_NOTIMPL;
5468 static const IGraphConfigVtbl IGraphConfig_VTable =
5470 GraphConfig_QueryInterface,
5471 GraphConfig_AddRef,
5472 GraphConfig_Release,
5473 GraphConfig_Reconnect,
5474 GraphConfig_Reconfigure,
5475 GraphConfig_AddFilterToCache,
5476 GraphConfig_EnumCacheFilter,
5477 GraphConfig_RemoveFilterFromCache,
5478 GraphConfig_GetStartTime,
5479 GraphConfig_PushThroughData,
5480 GraphConfig_SetFilterFlags,
5481 GraphConfig_GetFilterFlags,
5482 GraphConfig_RemoveFilterEx
5485 static struct filter_graph *impl_from_IGraphVersion(IGraphVersion *iface)
5487 return CONTAINING_RECORD(iface, struct filter_graph, IGraphVersion_iface);
5490 static HRESULT WINAPI GraphVersion_QueryInterface(IGraphVersion *iface, REFIID iid, void **out)
5492 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5494 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5497 static ULONG WINAPI GraphVersion_AddRef(IGraphVersion *iface)
5499 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5501 return IUnknown_AddRef(graph->outer_unk);
5504 static ULONG WINAPI GraphVersion_Release(IGraphVersion *iface)
5506 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5508 return IUnknown_Release(graph->outer_unk);
5511 static HRESULT WINAPI GraphVersion_QueryVersion(IGraphVersion *iface, LONG *pVersion)
5513 struct filter_graph *This = impl_from_IGraphVersion(iface);
5515 if(!pVersion)
5516 return E_POINTER;
5518 TRACE("(%p)->(%p): current version %i\n", This, pVersion, This->version);
5520 *pVersion = This->version;
5521 return S_OK;
5524 static const IGraphVersionVtbl IGraphVersion_VTable =
5526 GraphVersion_QueryInterface,
5527 GraphVersion_AddRef,
5528 GraphVersion_Release,
5529 GraphVersion_QueryVersion,
5532 static struct filter_graph *impl_from_IVideoFrameStep(IVideoFrameStep *iface)
5534 return CONTAINING_RECORD(iface, struct filter_graph, IVideoFrameStep_iface);
5537 static HRESULT WINAPI VideoFrameStep_QueryInterface(IVideoFrameStep *iface, REFIID iid, void **out)
5539 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5540 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5543 static ULONG WINAPI VideoFrameStep_AddRef(IVideoFrameStep *iface)
5545 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5546 return IUnknown_AddRef(graph->outer_unk);
5549 static ULONG WINAPI VideoFrameStep_Release(IVideoFrameStep *iface)
5551 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5552 return IUnknown_Release(graph->outer_unk);
5555 static HRESULT WINAPI VideoFrameStep_Step(IVideoFrameStep *iface, DWORD frame_count, IUnknown *filter)
5557 FIXME("iface %p, frame_count %u, filter %p, stub!\n", iface, frame_count, filter);
5558 return E_NOTIMPL;
5561 static HRESULT WINAPI VideoFrameStep_CanStep(IVideoFrameStep *iface, LONG multiple, IUnknown *filter)
5563 FIXME("iface %p, multiple %d, filter %p, stub!\n", iface, multiple, filter);
5564 return E_NOTIMPL;
5567 static HRESULT WINAPI VideoFrameStep_CancelStep(IVideoFrameStep *iface)
5569 FIXME("iface %p, stub!\n", iface);
5570 return E_NOTIMPL;
5573 static const IVideoFrameStepVtbl VideoFrameStep_vtbl =
5575 VideoFrameStep_QueryInterface,
5576 VideoFrameStep_AddRef,
5577 VideoFrameStep_Release,
5578 VideoFrameStep_Step,
5579 VideoFrameStep_CanStep,
5580 VideoFrameStep_CancelStep
5583 static const IUnknownVtbl IInner_VTable =
5585 FilterGraphInner_QueryInterface,
5586 FilterGraphInner_AddRef,
5587 FilterGraphInner_Release
5590 static HRESULT filter_graph_common_create(IUnknown *outer, IUnknown **out, BOOL threaded)
5592 struct filter_graph *object;
5593 HRESULT hr;
5595 *out = NULL;
5597 if (!(object = calloc(1, sizeof(*object))))
5598 return E_OUTOFMEMORY;
5600 object->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5601 object->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5602 object->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5603 object->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5604 object->IGraphVersion_iface.lpVtbl = &IGraphVersion_VTable;
5605 object->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5606 object->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5607 object->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5608 object->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5609 object->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5610 object->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5611 object->IObjectWithSite_iface.lpVtbl = &IObjectWithSite_VTable;
5612 object->IUnknown_inner.lpVtbl = &IInner_VTable;
5613 object->IVideoFrameStep_iface.lpVtbl = &VideoFrameStep_vtbl;
5614 object->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5615 object->ref = 1;
5616 object->outer_unk = outer ? outer : &object->IUnknown_inner;
5618 if (FAILED(hr = CoCreateInstance(&CLSID_FilterMapper2, object->outer_unk,
5619 CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&object->punkFilterMapper2)))
5621 ERR("Failed to create filter mapper, hr %#x.\n", hr);
5622 free(object);
5623 return hr;
5626 InitializeCriticalSection(&object->cs);
5627 object->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": filter_graph.cs");
5628 InitializeCriticalSection(&object->event_cs);
5629 object->event_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": filter_graph.event_cs");
5631 object->defaultclock = TRUE;
5633 object->media_event_handle = CreateEventW(NULL, TRUE, FALSE, NULL);
5634 list_init(&object->media_events);
5635 list_init(&object->filters);
5636 object->HandleEcClockChanged = TRUE;
5637 object->HandleEcComplete = TRUE;
5638 object->HandleEcRepaint = TRUE;
5639 object->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5641 object->name_index = 1;
5642 object->timeformatseek = TIME_FORMAT_MEDIA_TIME;
5644 if (threaded)
5646 object->message_thread_ret = CreateEventW(NULL, FALSE, FALSE, NULL);
5647 object->message_thread = CreateThread(NULL, 0, message_thread_run, object, 0, &object->message_thread_id);
5648 WaitForSingleObject(object->message_thread_ret, INFINITE);
5650 else
5651 object->message_thread = NULL;
5653 TRACE("Created %sthreaded filter graph %p.\n", threaded ? "" : "non-", object);
5654 *out = &object->IUnknown_inner;
5655 return S_OK;
5658 HRESULT filter_graph_create(IUnknown *outer, IUnknown **out)
5660 return filter_graph_common_create(outer, out, TRUE);
5663 HRESULT filter_graph_no_thread_create(IUnknown *outer, IUnknown **out)
5665 return filter_graph_common_create(outer, out, FALSE);