winewayland.drv: Implement vkGetPhysicalDeviceSurfaceSupportKHR.
[wine.git] / dlls / quartz / filtergraph.c
blob4100e71be3a0c42f67fae983518ccb265328f52d
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 DECLARE_CRITICAL_SECTION(message_cs);
47 struct filter_create_params
49 HRESULT hr;
50 IMoniker *moniker;
51 IBaseFilter *filter;
54 static HANDLE message_thread, message_thread_ret;
55 static DWORD message_thread_id;
56 static unsigned int message_thread_refcount;
58 struct media_event
60 struct list entry;
61 LONG code;
62 LONG_PTR param1, param2;
65 #define MAX_ITF_CACHE_ENTRIES 3
66 typedef struct _ITF_CACHE_ENTRY {
67 const IID* riid;
68 IBaseFilter* filter;
69 IUnknown* iface;
70 } ITF_CACHE_ENTRY;
72 struct filter
74 struct list entry;
75 IBaseFilter *filter;
76 IMediaSeeking *seeking;
77 WCHAR *name;
78 BOOL sorting;
81 struct filter_graph
83 IUnknown IUnknown_inner;
84 IFilterGraph2 IFilterGraph2_iface;
85 IMediaControl IMediaControl_iface;
86 IMediaSeeking IMediaSeeking_iface;
87 IBasicAudio IBasicAudio_iface;
88 IBasicVideo2 IBasicVideo2_iface;
89 IVideoWindow IVideoWindow_iface;
90 IMediaEventEx IMediaEventEx_iface;
91 IMediaFilter IMediaFilter_iface;
92 IMediaEventSink IMediaEventSink_iface;
93 IGraphConfig IGraphConfig_iface;
94 IMediaPosition IMediaPosition_iface;
95 IObjectWithSite IObjectWithSite_iface;
96 IGraphVersion IGraphVersion_iface;
97 /* IAMGraphStreams */
98 /* IAMStats */
99 /* IFilterChain */
100 /* IFilterMapper2 */
101 /* IQueueCommand */
102 /* IRegisterServiceProvider */
103 /* IResourceManager */
104 /* IServiceProvider */
105 IVideoFrameStep IVideoFrameStep_iface;
107 IUnknown *outer_unk;
108 LONG ref;
109 IUnknown *punkFilterMapper2;
111 struct list filters;
112 unsigned int name_index;
114 FILTER_STATE state;
115 TP_WORK *async_run_work;
117 IReferenceClock *refClock;
118 IBaseFilter *refClockProvider;
120 /* We may indirectly wait for streaming threads while holding graph->cs in
121 * IMediaFilter::Stop() or IMediaSeeking::SetPositions(). Since streaming
122 * threads call IMediaEventSink::Notify() to queue EC_COMPLETE, we must
123 * use a separate lock to avoid them deadlocking on graph->cs. */
124 CRITICAL_SECTION event_cs;
125 struct list media_events;
126 HANDLE media_event_handle;
127 HWND media_event_window;
128 UINT media_event_message;
129 LPARAM media_event_lparam;
130 HANDLE hEventCompletion;
131 int CompletionStatus;
132 int nRenderers;
133 int EcCompleteCount;
134 int HandleEcComplete;
135 int HandleEcRepaint;
136 int HandleEcClockChanged;
137 unsigned int got_ec_complete : 1;
138 unsigned int media_events_disabled : 1;
140 CRITICAL_SECTION cs;
141 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
142 int nItfCacheEntries;
143 BOOL defaultclock;
144 GUID timeformatseek;
145 IUnknown *pSite;
146 LONG version;
148 /* Respectively: the last timestamp at which we started streaming, and the
149 * current offset within the stream. */
150 REFERENCE_TIME stream_start, stream_elapsed;
151 REFERENCE_TIME stream_stop;
152 LONGLONG current_pos;
154 unsigned int needs_async_run : 1;
155 unsigned int threaded : 1;
158 struct enum_filters
160 IEnumFilters IEnumFilters_iface;
161 LONG ref;
162 struct filter_graph *graph;
163 LONG version;
164 struct list *cursor;
167 static HRESULT create_enum_filters(struct filter_graph *graph, struct list *cursor, IEnumFilters **out);
169 static inline struct enum_filters *impl_from_IEnumFilters(IEnumFilters *iface)
171 return CONTAINING_RECORD(iface, struct enum_filters, IEnumFilters_iface);
174 static HRESULT WINAPI EnumFilters_QueryInterface(IEnumFilters *iface, REFIID iid, void **out)
176 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
177 TRACE("enum_filters %p, iid %s, out %p.\n", enum_filters, qzdebugstr_guid(iid), out);
179 if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IEnumFilters))
181 IEnumFilters_AddRef(*out = iface);
182 return S_OK;
185 WARN("%s not implemented, returning E_NOINTERFACE.\n", qzdebugstr_guid(iid));
186 *out = NULL;
187 return E_NOINTERFACE;
190 static ULONG WINAPI EnumFilters_AddRef(IEnumFilters *iface)
192 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
193 ULONG ref = InterlockedIncrement(&enum_filters->ref);
195 TRACE("%p increasing refcount to %lu.\n", enum_filters, ref);
197 return ref;
200 static ULONG WINAPI EnumFilters_Release(IEnumFilters *iface)
202 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
203 ULONG ref = InterlockedDecrement(&enum_filters->ref);
205 TRACE("%p decreasing refcount to %lu.\n", enum_filters, ref);
207 if (!ref)
209 IUnknown_Release(enum_filters->graph->outer_unk);
210 heap_free(enum_filters);
213 return ref;
216 static HRESULT WINAPI EnumFilters_Next(IEnumFilters *iface, ULONG count,
217 IBaseFilter **filters, ULONG *fetched)
219 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
220 unsigned int i = 0;
222 TRACE("enum_filters %p, count %lu, filters %p, fetched %p.\n",
223 enum_filters, count, filters, fetched);
225 if (enum_filters->version != enum_filters->graph->version)
226 return VFW_E_ENUM_OUT_OF_SYNC;
228 if (!filters)
229 return E_POINTER;
231 for (i = 0; i < count; ++i)
233 struct filter *filter = LIST_ENTRY(enum_filters->cursor, struct filter, entry);
235 if (!enum_filters->cursor)
236 break;
238 IBaseFilter_AddRef(filters[i] = filter->filter);
239 enum_filters->cursor = list_next(&enum_filters->graph->filters, enum_filters->cursor);
242 if (fetched)
243 *fetched = i;
245 return (i == count) ? S_OK : S_FALSE;
248 static HRESULT WINAPI EnumFilters_Skip(IEnumFilters *iface, ULONG count)
250 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
252 TRACE("enum_filters %p, count %lu.\n", enum_filters, count);
254 if (enum_filters->version != enum_filters->graph->version)
255 return VFW_E_ENUM_OUT_OF_SYNC;
257 if (!enum_filters->cursor)
258 return E_INVALIDARG;
260 while (count--)
262 if (!(enum_filters->cursor = list_next(&enum_filters->graph->filters, enum_filters->cursor)))
263 return count ? S_FALSE : S_OK;
266 return S_OK;
269 static HRESULT WINAPI EnumFilters_Reset(IEnumFilters *iface)
271 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
273 TRACE("enum_filters %p.\n", enum_filters);
275 enum_filters->cursor = list_head(&enum_filters->graph->filters);
276 enum_filters->version = enum_filters->graph->version;
277 return S_OK;
280 static HRESULT WINAPI EnumFilters_Clone(IEnumFilters *iface, IEnumFilters **out)
282 struct enum_filters *enum_filters = impl_from_IEnumFilters(iface);
284 TRACE("enum_filters %p, out %p.\n", enum_filters, out);
286 return create_enum_filters(enum_filters->graph, enum_filters->cursor, out);
289 static const IEnumFiltersVtbl EnumFilters_vtbl =
291 EnumFilters_QueryInterface,
292 EnumFilters_AddRef,
293 EnumFilters_Release,
294 EnumFilters_Next,
295 EnumFilters_Skip,
296 EnumFilters_Reset,
297 EnumFilters_Clone,
300 static HRESULT create_enum_filters(struct filter_graph *graph, struct list *cursor, IEnumFilters **out)
302 struct enum_filters *enum_filters;
304 if (!(enum_filters = heap_alloc(sizeof(*enum_filters))))
305 return E_OUTOFMEMORY;
307 enum_filters->IEnumFilters_iface.lpVtbl = &EnumFilters_vtbl;
308 enum_filters->ref = 1;
309 enum_filters->cursor = cursor;
310 enum_filters->graph = graph;
311 IUnknown_AddRef(graph->outer_unk);
312 enum_filters->version = graph->version;
314 *out = &enum_filters->IEnumFilters_iface;
315 return S_OK;
318 static BOOL queue_media_event(struct filter_graph *graph, LONG code,
319 LONG_PTR param1, LONG_PTR param2)
321 struct media_event *event;
323 if (!(event = malloc(sizeof(*event))))
324 return FALSE;
326 event->code = code;
327 event->param1 = param1;
328 event->param2 = param2;
329 list_add_tail(&graph->media_events, &event->entry);
331 SetEvent(graph->media_event_handle);
332 if (graph->media_event_window)
333 PostMessageW(graph->media_event_window, graph->media_event_message, 0, graph->media_event_lparam);
335 return TRUE;
338 static void flush_media_events(struct filter_graph *graph)
340 struct list *cursor;
342 while ((cursor = list_head(&graph->media_events)))
344 struct media_event *event = LIST_ENTRY(cursor, struct media_event, entry);
346 list_remove(&event->entry);
347 free(event);
351 static struct filter_graph *impl_from_IUnknown(IUnknown *iface)
353 return CONTAINING_RECORD(iface, struct filter_graph, IUnknown_inner);
356 static HRESULT WINAPI FilterGraphInner_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObj)
358 struct filter_graph *This = impl_from_IUnknown(iface);
359 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObj);
361 if (IsEqualGUID(&IID_IUnknown, riid)) {
362 *ppvObj = &This->IUnknown_inner;
363 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
364 } else if (IsEqualGUID(&IID_IFilterGraph, riid) ||
365 IsEqualGUID(&IID_IFilterGraph2, riid) ||
366 IsEqualGUID(&IID_IGraphBuilder, riid)) {
367 *ppvObj = &This->IFilterGraph2_iface;
368 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj);
369 } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
370 *ppvObj = &This->IMediaControl_iface;
371 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj);
372 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
373 *ppvObj = &This->IMediaSeeking_iface;
374 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
375 } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
376 *ppvObj = &This->IBasicAudio_iface;
377 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj);
378 } else if (IsEqualGUID(&IID_IBasicVideo, riid) ||
379 IsEqualGUID(&IID_IBasicVideo2, riid)) {
380 *ppvObj = &This->IBasicVideo2_iface;
381 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj);
382 } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
383 *ppvObj = &This->IVideoWindow_iface;
384 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj);
385 } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
386 IsEqualGUID(&IID_IMediaEventEx, riid)) {
387 *ppvObj = &This->IMediaEventEx_iface;
388 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
389 } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
390 IsEqualGUID(&IID_IPersist, riid)) {
391 *ppvObj = &This->IMediaFilter_iface;
392 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj);
393 } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
394 *ppvObj = &This->IMediaEventSink_iface;
395 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj);
396 } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
397 *ppvObj = &This->IGraphConfig_iface;
398 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
399 } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
400 *ppvObj = &This->IMediaPosition_iface;
401 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj);
402 } else if (IsEqualGUID(&IID_IObjectWithSite, riid)) {
403 *ppvObj = &This->IObjectWithSite_iface;
404 TRACE(" returning IObjectWithSite interface (%p)\n", *ppvObj);
405 } else if (IsEqualGUID(&IID_IFilterMapper, riid)) {
406 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj);
407 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
408 } else if (IsEqualGUID(&IID_IFilterMapper2, riid)) {
409 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
410 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
411 } else if (IsEqualGUID(&IID_IFilterMapper3, riid)) {
412 TRACE(" returning IFilterMapper3 interface from aggregated filtermapper (%p)\n", *ppvObj);
413 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
414 } else if (IsEqualGUID(&IID_IGraphVersion, riid)) {
415 *ppvObj = &This->IGraphVersion_iface;
416 TRACE(" returning IGraphVersion interface (%p)\n", *ppvObj);
417 } else if (IsEqualGUID(&IID_IVideoFrameStep, riid)) {
418 *ppvObj = &This->IVideoFrameStep_iface;
419 TRACE(" returning IVideoFrameStep interface (%p)\n", *ppvObj);
420 } else {
421 *ppvObj = NULL;
422 FIXME("unknown interface %s\n", debugstr_guid(riid));
423 return E_NOINTERFACE;
426 IUnknown_AddRef((IUnknown *)*ppvObj);
427 return S_OK;
430 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown *iface)
432 struct filter_graph *graph = impl_from_IUnknown(iface);
433 ULONG refcount = InterlockedIncrement(&graph->ref);
435 TRACE("%p increasing refcount to %lu.\n", graph, refcount);
437 return refcount;
440 static ULONG WINAPI FilterGraphInner_Release(IUnknown *iface)
442 struct filter_graph *This = impl_from_IUnknown(iface);
443 ULONG refcount = InterlockedDecrement(&This->ref);
444 struct list *cursor;
446 TRACE("%p decreasing refcount to %lu.\n", This, refcount);
448 if (!refcount)
450 int i;
452 This->ref = 1; /* guard against reentrancy (aggregation). */
454 IMediaControl_Stop(&This->IMediaControl_iface);
456 while ((cursor = list_head(&This->filters)))
458 struct filter *filter = LIST_ENTRY(cursor, struct filter, entry);
460 IFilterGraph2_RemoveFilter(&This->IFilterGraph2_iface, filter->filter);
463 if (This->refClock)
464 IReferenceClock_Release(This->refClock);
466 for (i = 0; i < This->nItfCacheEntries; i++)
468 if (This->ItfCacheEntries[i].iface)
469 IUnknown_Release(This->ItfCacheEntries[i].iface);
472 IUnknown_Release(This->punkFilterMapper2);
474 if (This->pSite) IUnknown_Release(This->pSite);
476 flush_media_events(This);
477 CloseHandle(This->media_event_handle);
479 EnterCriticalSection(&message_cs);
480 if (This->threaded && !--message_thread_refcount)
482 PostThreadMessageW(message_thread_id, WM_USER + 1, 0, 0);
483 WaitForSingleObject(message_thread, INFINITE);
484 CloseHandle(message_thread);
485 CloseHandle(message_thread_ret);
487 LeaveCriticalSection(&message_cs);
489 This->event_cs.DebugInfo->Spare[0] = 0;
490 DeleteCriticalSection(&This->event_cs);
491 This->cs.DebugInfo->Spare[0] = 0;
492 DeleteCriticalSection(&This->cs);
493 free(This);
495 return refcount;
498 static struct filter_graph *impl_from_IFilterGraph2(IFilterGraph2 *iface)
500 return CONTAINING_RECORD(iface, struct filter_graph, IFilterGraph2_iface);
503 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface, REFIID iid, void **out)
505 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
506 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
509 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface)
511 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
512 return IUnknown_AddRef(graph->outer_unk);
515 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface)
517 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
518 return IUnknown_Release(graph->outer_unk);
521 static IBaseFilter *find_filter_by_name(struct filter_graph *graph, const WCHAR *name)
523 struct filter *filter;
525 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
527 if (!wcscmp(filter->name, name))
528 return filter->filter;
531 return NULL;
534 static BOOL has_output_pins(IBaseFilter *filter)
536 IEnumPins *enumpins;
537 PIN_DIRECTION dir;
538 IPin *pin;
540 if (FAILED(IBaseFilter_EnumPins(filter, &enumpins)))
541 return FALSE;
543 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
545 IPin_QueryDirection(pin, &dir);
546 IPin_Release(pin);
547 if (dir == PINDIR_OUTPUT)
549 IEnumPins_Release(enumpins);
550 return TRUE;
554 IEnumPins_Release(enumpins);
555 return FALSE;
558 static void update_seeking(struct filter *filter)
560 IMediaSeeking *seeking;
562 if (!filter->seeking)
564 /* The Legend of Heroes: Trails of Cold Steel II destroys its filter when
565 * its IMediaSeeking interface is released, so cache the interface instead
566 * of querying for it every time.
567 * Some filters (e.g. MediaStreamFilter) can become seekable when they are
568 * already in the graph, so always try to query IMediaSeeking if it's not
569 * cached yet. */
570 if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IMediaSeeking, (void **)&seeking)))
572 if (IMediaSeeking_IsFormatSupported(seeking, &TIME_FORMAT_MEDIA_TIME) == S_OK)
573 filter->seeking = seeking;
574 else
575 IMediaSeeking_Release(seeking);
580 static BOOL is_renderer(struct filter *filter)
582 IMediaPosition *media_position;
583 IAMFilterMiscFlags *flags;
584 BOOL ret = FALSE;
586 if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IAMFilterMiscFlags, (void **)&flags)))
588 if (IAMFilterMiscFlags_GetMiscFlags(flags) & AM_FILTER_MISC_FLAGS_IS_RENDERER)
589 ret = TRUE;
590 IAMFilterMiscFlags_Release(flags);
592 else if (SUCCEEDED(IBaseFilter_QueryInterface(filter->filter, &IID_IMediaPosition, (void **)&media_position)))
594 if (!has_output_pins(filter->filter))
595 ret = TRUE;
596 IMediaPosition_Release(media_position);
598 else
600 update_seeking(filter);
601 if (filter->seeking && !has_output_pins(filter->filter))
602 ret = TRUE;
604 return ret;
607 /*** IFilterGraph methods ***/
608 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface,
609 IBaseFilter *filter, const WCHAR *name)
611 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
612 BOOL duplicate_name = FALSE;
613 struct filter *entry;
614 unsigned int i;
615 HRESULT hr;
617 TRACE("graph %p, filter %p, name %s.\n", graph, filter, debugstr_w(name));
619 if (!filter)
620 return E_POINTER;
622 if (!(entry = heap_alloc(sizeof(*entry))))
623 return E_OUTOFMEMORY;
625 if (!(entry->name = CoTaskMemAlloc((name ? wcslen(name) + 6 : 5) * sizeof(WCHAR))))
627 heap_free(entry);
628 return E_OUTOFMEMORY;
631 if (name && find_filter_by_name(graph, name))
632 duplicate_name = TRUE;
634 if (!name || duplicate_name)
636 for (i = 0; i < 10000 ; ++i)
638 if (name)
639 swprintf(entry->name, name ? wcslen(name) + 6 : 5, L"%s %04u", name, graph->name_index);
640 else
641 swprintf(entry->name, name ? wcslen(name) + 6 : 5, L"%04u", graph->name_index);
643 graph->name_index = (graph->name_index + 1) % 10000;
645 if (!find_filter_by_name(graph, entry->name))
646 break;
649 if (i == 10000)
651 CoTaskMemFree(entry->name);
652 heap_free(entry);
653 return VFW_E_DUPLICATE_NAME;
656 else
657 wcscpy(entry->name, name);
659 if (FAILED(hr = IBaseFilter_JoinFilterGraph(filter,
660 (IFilterGraph *)&graph->IFilterGraph2_iface, entry->name)))
662 CoTaskMemFree(entry->name);
663 heap_free(entry);
664 return hr;
667 IBaseFilter_SetSyncSource(filter, graph->refClock);
669 IBaseFilter_AddRef(entry->filter = filter);
671 list_add_head(&graph->filters, &entry->entry);
672 entry->sorting = FALSE;
673 entry->seeking = NULL;
674 ++graph->version;
676 return duplicate_name ? VFW_S_DUPLICATE_NAME : hr;
679 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
681 struct filter_graph *This = impl_from_IFilterGraph2(iface);
682 struct filter *entry;
683 int i;
684 HRESULT hr = E_FAIL;
686 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
688 LIST_FOR_EACH_ENTRY(entry, &This->filters, struct filter, entry)
690 if (entry->filter == pFilter)
692 IEnumPins *penumpins = NULL;
694 if (This->defaultclock && This->refClockProvider == pFilter)
696 IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, NULL);
697 This->defaultclock = TRUE;
700 TRACE("Removing filter %s.\n", debugstr_w(entry->name));
702 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
703 if (SUCCEEDED(hr)) {
704 IPin *ppin;
705 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
707 IPin *peer = NULL;
708 HRESULT hr;
710 IPin_ConnectedTo(ppin, &peer);
711 if (peer)
713 if (FAILED(hr = IPin_Disconnect(peer)))
715 WARN("Failed to disconnect peer %p, hr %#lx.\n", peer, hr);
716 IPin_Release(peer);
717 IPin_Release(ppin);
718 IEnumPins_Release(penumpins);
719 return hr;
721 IPin_Release(peer);
723 if (FAILED(hr = IPin_Disconnect(ppin)))
725 WARN("Failed to disconnect pin %p, hr %#lx.\n", ppin, hr);
726 IPin_Release(ppin);
727 IEnumPins_Release(penumpins);
728 return hr;
731 IPin_Release(ppin);
733 IEnumPins_Release(penumpins);
736 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, NULL);
737 if (SUCCEEDED(hr))
739 IBaseFilter_SetSyncSource(pFilter, NULL);
740 IBaseFilter_Release(pFilter);
741 if (entry->seeking)
742 IMediaSeeking_Release(entry->seeking);
743 list_remove(&entry->entry);
744 CoTaskMemFree(entry->name);
745 heap_free(entry);
746 This->version++;
747 /* Invalidate interfaces in the cache */
748 for (i = 0; i < This->nItfCacheEntries; i++)
749 if (pFilter == This->ItfCacheEntries[i].filter)
751 IUnknown_Release(This->ItfCacheEntries[i].iface);
752 This->ItfCacheEntries[i].iface = NULL;
753 This->ItfCacheEntries[i].filter = NULL;
755 return S_OK;
757 break;
761 return hr; /* FIXME: check this error code */
764 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface, IEnumFilters **out)
766 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
768 TRACE("graph %p, out %p.\n", graph, out);
770 return create_enum_filters(graph, list_head(&graph->filters), out);
773 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface,
774 const WCHAR *name, IBaseFilter **filter)
776 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
778 TRACE("graph %p, name %s, filter %p.\n", graph, debugstr_w(name), filter);
780 if (!filter)
781 return E_POINTER;
783 if ((*filter = find_filter_by_name(graph, name)))
785 IBaseFilter_AddRef(*filter);
786 return S_OK;
789 return VFW_E_NOT_FOUND;
792 static HRESULT check_cyclic_connection(IPin *source, IPin *sink)
794 IPin *upstream_source, *upstream_sink;
795 PIN_INFO source_info, sink_info;
796 IEnumPins *enumpins;
797 HRESULT hr;
799 hr = IPin_QueryPinInfo(sink, &sink_info);
800 if (FAILED(hr))
802 ERR("Failed to query pin, hr %#lx.\n", hr);
803 return hr;
805 IBaseFilter_Release(sink_info.pFilter);
807 hr = IPin_QueryPinInfo(source, &source_info);
808 if (FAILED(hr))
810 ERR("Failed to query pin, hr %#lx.\n", hr);
811 return hr;
814 if (sink_info.pFilter == source_info.pFilter)
816 WARN("Cyclic connection detected; returning VFW_E_CIRCULAR_GRAPH.\n");
817 IBaseFilter_Release(source_info.pFilter);
818 return VFW_E_CIRCULAR_GRAPH;
821 hr = IBaseFilter_EnumPins(source_info.pFilter, &enumpins);
822 if (FAILED(hr))
824 ERR("Failed to enumerate pins, hr %#lx.\n", hr);
825 IBaseFilter_Release(source_info.pFilter);
826 return hr;
829 while ((hr = IEnumPins_Next(enumpins, 1, &upstream_sink, NULL)) == S_OK)
831 PIN_DIRECTION dir = PINDIR_OUTPUT;
833 IPin_QueryDirection(upstream_sink, &dir);
834 if (dir == PINDIR_INPUT && IPin_ConnectedTo(upstream_sink, &upstream_source) == S_OK)
836 hr = check_cyclic_connection(upstream_source, sink);
837 IPin_Release(upstream_source);
838 if (FAILED(hr))
840 IPin_Release(upstream_sink);
841 IEnumPins_Release(enumpins);
842 IBaseFilter_Release(source_info.pFilter);
843 return hr;
846 IPin_Release(upstream_sink);
848 IEnumPins_Release(enumpins);
850 IBaseFilter_Release(source_info.pFilter);
851 return S_OK;
854 static struct filter *find_sorted_filter(struct filter_graph *graph, IBaseFilter *iface)
856 struct filter *filter;
858 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
860 if (filter->filter == iface)
861 return filter;
864 return NULL;
867 static void sort_filter_recurse(struct filter_graph *graph, struct filter *filter, struct list *sorted)
869 struct filter *peer_filter;
870 IEnumPins *enumpins;
871 PIN_DIRECTION dir;
872 IPin *pin, *peer;
873 PIN_INFO info;
875 TRACE("Sorting filter %p.\n", filter->filter);
877 /* Cyclic connections should be caught by check_cyclic_connection(). */
878 assert(!filter->sorting);
880 filter->sorting = TRUE;
882 IBaseFilter_EnumPins(filter->filter, &enumpins);
883 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
885 IPin_QueryDirection(pin, &dir);
887 if (dir == PINDIR_INPUT && IPin_ConnectedTo(pin, &peer) == S_OK)
889 IPin_QueryPinInfo(peer, &info);
890 /* Note that the filter may have already been sorted. */
891 if ((peer_filter = find_sorted_filter(graph, info.pFilter)))
892 sort_filter_recurse(graph, peer_filter, sorted);
893 IBaseFilter_Release(info.pFilter);
894 IPin_Release(peer);
896 IPin_Release(pin);
898 IEnumPins_Release(enumpins);
900 filter->sorting = FALSE;
902 list_remove(&filter->entry);
903 list_add_head(sorted, &filter->entry);
906 static void sort_filters(struct filter_graph *graph)
908 struct list sorted = LIST_INIT(sorted), *cursor;
910 while ((cursor = list_head(&graph->filters)))
912 struct filter *filter = LIST_ENTRY(cursor, struct filter, entry);
913 sort_filter_recurse(graph, filter, &sorted);
916 list_move_tail(&graph->filters, &sorted);
919 /* NOTE: despite the implication, it doesn't matter which
920 * way round you put in the input and output pins */
921 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppinIn, IPin *ppinOut,
922 const AM_MEDIA_TYPE *pmt)
924 struct filter_graph *This = impl_from_IFilterGraph2(iface);
925 PIN_DIRECTION dir;
926 HRESULT hr;
928 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
929 strmbase_dump_media_type(pmt);
931 /* FIXME: check pins are in graph */
933 if (TRACE_ON(quartz))
935 PIN_INFO PinInfo;
937 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
938 if (FAILED(hr))
939 return hr;
941 TRACE("Filter owning ppinIn(%p) => %p\n", ppinIn, PinInfo.pFilter);
942 IBaseFilter_Release(PinInfo.pFilter);
944 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
945 if (FAILED(hr))
946 return hr;
948 TRACE("Filter owning ppinOut(%p) => %p\n", ppinOut, PinInfo.pFilter);
949 IBaseFilter_Release(PinInfo.pFilter);
952 hr = IPin_QueryDirection(ppinIn, &dir);
953 if (SUCCEEDED(hr))
955 if (dir == PINDIR_INPUT)
957 hr = check_cyclic_connection(ppinOut, ppinIn);
958 if (SUCCEEDED(hr))
959 hr = IPin_Connect(ppinOut, ppinIn, pmt);
961 else
963 hr = check_cyclic_connection(ppinIn, ppinOut);
964 if (SUCCEEDED(hr))
965 hr = IPin_Connect(ppinIn, ppinOut, pmt);
969 return hr;
972 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface, IPin *pin)
974 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
976 TRACE("graph %p, pin %p.\n", graph, pin);
978 return IFilterGraph2_ReconnectEx(iface, pin, NULL);
981 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
983 struct filter_graph *This = impl_from_IFilterGraph2(iface);
985 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
987 if (!ppin)
988 return E_POINTER;
990 return IPin_Disconnect(ppin);
993 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
995 struct filter_graph *This = impl_from_IFilterGraph2(iface);
996 IReferenceClock *pClock = NULL;
997 struct filter *filter;
998 HRESULT hr = S_OK;
1000 TRACE("(%p/%p)->() live sources not handled properly!\n", This, iface);
1002 EnterCriticalSection(&This->cs);
1004 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
1006 if (IBaseFilter_QueryInterface(filter->filter, &IID_IReferenceClock, (void **)&pClock) == S_OK)
1007 break;
1010 if (!pClock)
1012 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
1013 This->refClockProvider = NULL;
1015 else
1017 filter = LIST_ENTRY(list_tail(&This->filters), struct filter, entry);
1018 This->refClockProvider = filter->filter;
1021 if (SUCCEEDED(hr))
1023 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
1024 This->defaultclock = TRUE;
1025 IReferenceClock_Release(pClock);
1027 LeaveCriticalSection(&This->cs);
1029 return hr;
1032 static DWORD WINAPI message_thread_run(void *ctx)
1034 MSG msg;
1036 /* Make sure we have a message queue. */
1037 PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE);
1038 SetEvent(message_thread_ret);
1040 CoInitializeEx(NULL, COINIT_MULTITHREADED);
1042 for (;;)
1044 GetMessageW(&msg, NULL, 0, 0);
1046 if (!msg.hwnd && msg.message == WM_USER)
1048 struct filter_create_params *params = (struct filter_create_params *)msg.wParam;
1050 params->hr = IMoniker_BindToObject(params->moniker, NULL, NULL,
1051 &IID_IBaseFilter, (void **)&params->filter);
1052 SetEvent(message_thread_ret);
1054 else if (!msg.hwnd && msg.message == WM_USER + 1)
1056 break;
1058 else
1060 TranslateMessage(&msg);
1061 DispatchMessageW(&msg);
1065 CoUninitialize();
1066 return 0;
1069 static HRESULT create_filter(struct filter_graph *graph, IMoniker *moniker, IBaseFilter **filter)
1071 if (graph->threaded)
1073 struct filter_create_params params;
1075 params.moniker = moniker;
1077 EnterCriticalSection(&message_cs);
1078 PostThreadMessageW(message_thread_id, WM_USER, (WPARAM)&params, 0);
1079 WaitForSingleObject(message_thread_ret, INFINITE);
1080 LeaveCriticalSection(&message_cs);
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 static HRESULT get_autoplug_types(IPin *source, unsigned int *ret_count, GUID **ret_types)
1201 unsigned int i, mt_count = 0, mt_capacity = 16;
1202 AM_MEDIA_TYPE **mts = NULL;
1203 IEnumMediaTypes *enummt;
1204 GUID *types = NULL;
1205 HRESULT hr;
1207 if (FAILED(hr = IPin_EnumMediaTypes(source, &enummt)))
1209 ERR("Failed to enumerate media types, hr %#lx.\n", hr);
1210 return hr;
1213 for (;;)
1215 ULONG count;
1217 if (!(mts = realloc(mts, mt_capacity * sizeof(*mts))))
1219 hr = E_OUTOFMEMORY;
1220 goto out;
1223 if (FAILED(hr = IEnumMediaTypes_Next(enummt, mt_capacity - mt_count, mts + mt_count, &count)))
1225 ERR("Failed to get media types, hr %#lx.\n", hr);
1226 goto out;
1229 mt_count += count;
1230 if (hr == S_FALSE)
1231 break;
1233 mt_capacity *= 2;
1236 if (!(types = malloc(mt_count * 2 * sizeof(*types))))
1238 hr = E_OUTOFMEMORY;
1239 goto out;
1242 for (i = 0; i < mt_count; ++i)
1244 types[i * 2] = mts[i]->majortype;
1245 types[i * 2 + 1] = mts[i]->subtype;
1246 DeleteMediaType(mts[i]);
1249 *ret_count = mt_count;
1250 *ret_types = types;
1252 hr = S_OK;
1253 out:
1254 free(mts);
1255 IEnumMediaTypes_Release(enummt);
1256 return hr;
1259 /* Common helper for IGraphBuilder::Connect() and IGraphBuilder::Render(), which
1260 * share most of the same code. Render() calls this with a NULL sink. */
1261 static HRESULT autoplug(struct filter_graph *graph, IPin *source, IPin *sink,
1262 BOOL render_to_existing, unsigned int recursion_depth)
1264 IAMGraphBuilderCallback *callback = NULL;
1265 struct filter *graph_filter;
1266 IEnumMoniker *enummoniker;
1267 unsigned int type_count;
1268 IFilterMapper2 *mapper;
1269 IBaseFilter *filter;
1270 GUID *types = NULL;
1271 IMoniker *moniker;
1272 HRESULT hr;
1274 TRACE("Trying to autoplug %p to %p, recursion depth %u.\n", source, sink, recursion_depth);
1276 if (recursion_depth >= 5)
1278 WARN("Recursion depth has reached 5; aborting.\n");
1279 return VFW_E_CANNOT_CONNECT;
1282 if (sink)
1284 /* Try to connect directly to this sink. */
1285 hr = IFilterGraph2_ConnectDirect(&graph->IFilterGraph2_iface, source, sink, NULL);
1287 /* If direct connection succeeded, we should propagate that return value.
1288 * If it returned VFW_E_NOT_CONNECTED or VFW_E_NO_AUDIO_HARDWARE, then don't
1289 * even bother trying intermediate filters, since they won't succeed. */
1290 if (SUCCEEDED(hr) || hr == VFW_E_NOT_CONNECTED || hr == VFW_E_NO_AUDIO_HARDWARE)
1291 return hr;
1294 /* Always prefer filters in the graph. */
1295 LIST_FOR_EACH_ENTRY(graph_filter, &graph->filters, struct filter, entry)
1297 if (SUCCEEDED(hr = autoplug_through_filter(graph, source, graph_filter->filter,
1298 sink, render_to_existing, recursion_depth)))
1299 return hr;
1302 IUnknown_QueryInterface(graph->punkFilterMapper2, &IID_IFilterMapper2, (void **)&mapper);
1304 if (FAILED(hr = get_autoplug_types(source, &type_count, &types)))
1306 IFilterMapper2_Release(mapper);
1307 return hr;
1310 if (graph->pSite)
1311 IUnknown_QueryInterface(graph->pSite, &IID_IAMGraphBuilderCallback, (void **)&callback);
1313 if (FAILED(hr = IFilterMapper2_EnumMatchingFilters(mapper, &enummoniker,
1314 0, FALSE, MERIT_UNLIKELY, TRUE, type_count, types, NULL, NULL, FALSE,
1315 render_to_existing, 0, NULL, NULL, NULL)))
1316 goto out;
1318 while (IEnumMoniker_Next(enummoniker, 1, &moniker, NULL) == S_OK)
1320 IPropertyBag *bag;
1321 VARIANT var;
1323 VariantInit(&var);
1324 IMoniker_BindToStorage(moniker, NULL, NULL, &IID_IPropertyBag, (void **)&bag);
1325 hr = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL);
1326 IPropertyBag_Release(bag);
1327 if (FAILED(hr))
1329 IMoniker_Release(moniker);
1330 continue;
1333 if (callback && FAILED(hr = IAMGraphBuilderCallback_SelectedFilter(callback, moniker)))
1335 TRACE("Filter rejected by IAMGraphBuilderCallback::SelectedFilter(), hr %#lx.\n", hr);
1336 IMoniker_Release(moniker);
1337 continue;
1340 hr = create_filter(graph, moniker, &filter);
1341 IMoniker_Release(moniker);
1342 if (FAILED(hr))
1344 ERR("Failed to create filter for %s, hr %#lx.\n", debugstr_w(V_BSTR(&var)), hr);
1345 VariantClear(&var);
1346 continue;
1349 if (callback && FAILED(hr = IAMGraphBuilderCallback_CreatedFilter(callback, filter)))
1351 TRACE("Filter rejected by IAMGraphBuilderCallback::CreatedFilter(), hr %#lx.\n", hr);
1352 IBaseFilter_Release(filter);
1353 continue;
1356 hr = IFilterGraph2_AddFilter(&graph->IFilterGraph2_iface, filter, V_BSTR(&var));
1357 VariantClear(&var);
1358 if (FAILED(hr))
1360 ERR("Failed to add filter, hr %#lx.\n", hr);
1361 IBaseFilter_Release(filter);
1362 continue;
1365 hr = autoplug_through_filter(graph, source, filter, sink, render_to_existing, recursion_depth);
1366 if (SUCCEEDED(hr))
1368 IBaseFilter_Release(filter);
1369 goto out;
1372 IFilterGraph2_RemoveFilter(&graph->IFilterGraph2_iface, filter);
1373 IBaseFilter_Release(filter);
1375 IEnumMoniker_Release(enummoniker);
1377 hr = VFW_E_CANNOT_CONNECT;
1379 out:
1380 free(types);
1381 if (callback) IAMGraphBuilderCallback_Release(callback);
1382 IFilterMapper2_Release(mapper);
1383 return hr;
1386 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *source, IPin *sink)
1388 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1389 PIN_DIRECTION dir;
1390 HRESULT hr;
1392 TRACE("graph %p, source %p, sink %p.\n", graph, source, sink);
1394 if (!source || !sink)
1395 return E_POINTER;
1397 if (FAILED(hr = IPin_QueryDirection(source, &dir)))
1398 return hr;
1400 if (dir == PINDIR_INPUT)
1402 IPin *temp;
1404 TRACE("Directions seem backwards, swapping pins\n");
1406 temp = sink;
1407 sink = source;
1408 source = temp;
1411 EnterCriticalSection(&graph->cs);
1413 hr = autoplug(graph, source, sink, TRUE, 0);
1415 LeaveCriticalSection(&graph->cs);
1417 TRACE("Returning %#lx.\n", hr);
1418 return hr;
1421 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *source)
1423 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1424 HRESULT hr;
1426 TRACE("graph %p, source %p.\n", graph, source);
1428 EnterCriticalSection(&graph->cs);
1429 hr = autoplug(graph, source, NULL, FALSE, 0);
1430 LeaveCriticalSection(&graph->cs);
1431 if (hr == VFW_E_CANNOT_CONNECT)
1432 hr = VFW_E_CANNOT_RENDER;
1434 TRACE("Returning %#lx.\n", hr);
1435 return hr;
1438 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface, LPCWSTR lpcwstrFile,
1439 LPCWSTR lpcwstrPlayList)
1441 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1442 IBaseFilter* preader = NULL;
1443 IPin* ppinreader = NULL;
1444 IEnumPins* penumpins = NULL;
1445 struct filter *filter;
1446 HRESULT hr;
1447 BOOL partial = FALSE;
1448 BOOL any = FALSE;
1450 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1452 if (lpcwstrPlayList != NULL)
1453 return E_INVALIDARG;
1455 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, L"Reader", &preader);
1456 if (FAILED(hr))
1457 return hr;
1459 hr = IBaseFilter_EnumPins(preader, &penumpins);
1460 if (SUCCEEDED(hr))
1462 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1464 PIN_DIRECTION dir;
1466 IPin_QueryDirection(ppinreader, &dir);
1467 if (dir == PINDIR_OUTPUT)
1469 hr = IFilterGraph2_Render(iface, ppinreader);
1471 TRACE("Filters in chain:\n");
1472 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
1473 TRACE("- %s.\n", debugstr_w(filter->name));
1475 if (SUCCEEDED(hr))
1476 any = TRUE;
1477 if (hr != S_OK)
1478 partial = TRUE;
1480 IPin_Release(ppinreader);
1482 IEnumPins_Release(penumpins);
1484 if (!any)
1486 if (FAILED(hr = IFilterGraph2_RemoveFilter(iface, preader)))
1487 ERR("Failed to remove source filter, hr %#lx.\n", hr);
1488 hr = VFW_E_CANNOT_RENDER;
1490 else if (partial)
1492 hr = VFW_S_PARTIAL_RENDER;
1494 else
1496 hr = S_OK;
1499 IBaseFilter_Release(preader);
1501 TRACE("Returning %#lx.\n", hr);
1502 return hr;
1505 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface,
1506 const WCHAR *filename, const WCHAR *filter_name, IBaseFilter **ret_filter)
1508 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1509 IFileSourceFilter *filesource;
1510 IBaseFilter *filter;
1511 HRESULT hr;
1512 GUID clsid;
1514 TRACE("graph %p, filename %s, filter_name %s, ret_filter %p.\n",
1515 graph, debugstr_w(filename), debugstr_w(filter_name), ret_filter);
1517 if (!get_media_type(filename, NULL, NULL, &clsid))
1518 clsid = CLSID_AsyncReader;
1519 TRACE("Using source filter %s.\n", debugstr_guid(&clsid));
1521 if (FAILED(hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER,
1522 &IID_IBaseFilter, (void **)&filter)))
1524 WARN("Failed to create filter, hr %#lx.\n", hr);
1525 return hr;
1528 if (FAILED(hr = IBaseFilter_QueryInterface(filter, &IID_IFileSourceFilter, (void **)&filesource)))
1530 WARN("Failed to get IFileSourceFilter, hr %#lx.\n", hr);
1531 IBaseFilter_Release(filter);
1532 return hr;
1535 hr = IFileSourceFilter_Load(filesource, filename, NULL);
1536 IFileSourceFilter_Release(filesource);
1537 if (FAILED(hr))
1539 WARN("Failed to load file, hr %#lx.\n", hr);
1540 return hr;
1543 if (FAILED(hr = IFilterGraph2_AddFilter(iface, filter, filter_name)))
1545 IBaseFilter_Release(filter);
1546 return hr;
1549 if (ret_filter)
1550 *ret_filter = filter;
1551 return S_OK;
1554 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR file)
1556 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1558 TRACE("graph %p, file %#Ix.\n", graph, file);
1560 return S_OK;
1563 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1565 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1567 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1569 return S_OK;
1572 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1574 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1576 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1578 return S_OK;
1581 /*** IFilterGraph2 methods ***/
1582 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1583 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1585 struct filter_graph *This = impl_from_IFilterGraph2(iface);
1586 HRESULT hr;
1587 IBaseFilter* pfilter;
1589 TRACE("(%p/%p)->(%p %p %s %p)\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1591 hr = IMoniker_BindToObject(pMoniker, pCtx, NULL, &IID_IBaseFilter, (void**)&pfilter);
1592 if(FAILED(hr)) {
1593 WARN("Failed to bind moniker, hr %#lx.\n", hr);
1594 return hr;
1597 hr = IFilterGraph2_AddFilter(iface, pfilter, lpcwstrFilterName);
1598 if (FAILED(hr)) {
1599 WARN("Failed to add filter, hr %#lx.\n", hr);
1600 IBaseFilter_Release(pfilter);
1601 return hr;
1604 if(ppFilter)
1605 *ppFilter = pfilter;
1606 else IBaseFilter_Release(pfilter);
1608 return S_OK;
1611 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *pin, const AM_MEDIA_TYPE *mt)
1613 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1614 PIN_DIRECTION dir;
1615 HRESULT hr;
1616 IPin *peer;
1618 TRACE("graph %p, pin %p, mt %p.\n", graph, pin, mt);
1620 if (FAILED(hr = IPin_ConnectedTo(pin, &peer)))
1621 return hr;
1623 IPin_QueryDirection(pin, &dir);
1624 IFilterGraph2_Disconnect(iface, peer);
1625 IFilterGraph2_Disconnect(iface, pin);
1627 if (dir == PINDIR_INPUT)
1628 hr = IFilterGraph2_ConnectDirect(iface, peer, pin, mt);
1629 else
1630 hr = IFilterGraph2_ConnectDirect(iface, pin, peer, mt);
1632 IPin_Release(peer);
1633 return hr;
1636 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *source, DWORD flags, DWORD *context)
1638 struct filter_graph *graph = impl_from_IFilterGraph2(iface);
1639 HRESULT hr;
1641 TRACE("graph %p, source %p, flags %#lx, context %p.\n", graph, source, flags, context);
1643 if (flags & ~AM_RENDEREX_RENDERTOEXISTINGRENDERERS)
1644 FIXME("Unknown flags %#lx.\n", flags);
1646 EnterCriticalSection(&graph->cs);
1647 hr = autoplug(graph, source, NULL, !!(flags & AM_RENDEREX_RENDERTOEXISTINGRENDERERS), 0);
1648 LeaveCriticalSection(&graph->cs);
1649 if (hr == VFW_E_CANNOT_CONNECT)
1650 hr = VFW_E_CANNOT_RENDER;
1652 TRACE("Returning %#lx.\n", hr);
1653 return hr;
1657 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1659 FilterGraph2_QueryInterface,
1660 FilterGraph2_AddRef,
1661 FilterGraph2_Release,
1662 FilterGraph2_AddFilter,
1663 FilterGraph2_RemoveFilter,
1664 FilterGraph2_EnumFilters,
1665 FilterGraph2_FindFilterByName,
1666 FilterGraph2_ConnectDirect,
1667 FilterGraph2_Reconnect,
1668 FilterGraph2_Disconnect,
1669 FilterGraph2_SetDefaultSyncSource,
1670 FilterGraph2_Connect,
1671 FilterGraph2_Render,
1672 FilterGraph2_RenderFile,
1673 FilterGraph2_AddSourceFilter,
1674 FilterGraph2_SetLogFile,
1675 FilterGraph2_Abort,
1676 FilterGraph2_ShouldOperationContinue,
1677 FilterGraph2_AddSourceFilterForMoniker,
1678 FilterGraph2_ReconnectEx,
1679 FilterGraph2_RenderEx
1682 static struct filter_graph *impl_from_IMediaControl(IMediaControl *iface)
1684 return CONTAINING_RECORD(iface, struct filter_graph, IMediaControl_iface);
1687 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID iid, void **out)
1689 struct filter_graph *graph = impl_from_IMediaControl(iface);
1690 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
1693 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1695 struct filter_graph *graph = impl_from_IMediaControl(iface);
1696 return IUnknown_AddRef(graph->outer_unk);
1699 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1701 struct filter_graph *graph = impl_from_IMediaControl(iface);
1702 return IUnknown_Release(graph->outer_unk);
1706 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *count)
1708 TRACE("iface %p, count %p.\n", iface, count);
1709 *count = 1;
1710 return S_OK;
1713 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT index,
1714 LCID lcid, ITypeInfo **typeinfo)
1716 TRACE("iface %p, index %u, lcid %#lx, typeinfo %p.\n", iface, index, lcid, typeinfo);
1717 return strmbase_get_typeinfo(IMediaControl_tid, typeinfo);
1720 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID iid,
1721 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
1723 ITypeInfo *typeinfo;
1724 HRESULT hr;
1726 TRACE("iface %p, iid %s, names %p, count %u, lcid %#lx, ids %p.\n",
1727 iface, debugstr_guid(iid), names, count, lcid, ids);
1729 if (SUCCEEDED(hr = strmbase_get_typeinfo(IMediaControl_tid, &typeinfo)))
1731 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
1732 ITypeInfo_Release(typeinfo);
1734 return hr;
1737 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID id, REFIID iid, LCID lcid,
1738 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
1740 ITypeInfo *typeinfo;
1741 HRESULT hr;
1743 TRACE("iface %p, id %ld, iid %s, lcid %#lx, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
1744 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
1746 if (SUCCEEDED(hr = strmbase_get_typeinfo(IMediaControl_tid, &typeinfo)))
1748 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
1749 ITypeInfo_Release(typeinfo);
1751 return hr;
1754 static void update_render_count(struct filter_graph *graph)
1756 /* Some filters (e.g. MediaStreamFilter) can become renderers when they are
1757 * already in the graph. */
1758 struct filter *filter;
1759 graph->nRenderers = 0;
1760 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1762 if (is_renderer(filter))
1763 ++graph->nRenderers;
1767 /* Perform the paused -> running transition. The caller must hold graph->cs. */
1768 static HRESULT graph_start(struct filter_graph *graph, REFERENCE_TIME stream_start)
1770 struct media_event *event, *next;
1771 REFERENCE_TIME stream_stop;
1772 struct filter *filter;
1773 HRESULT hr = S_OK;
1775 EnterCriticalSection(&graph->event_cs);
1776 graph->EcCompleteCount = 0;
1777 update_render_count(graph);
1778 LeaveCriticalSection(&graph->event_cs);
1780 LIST_FOR_EACH_ENTRY_SAFE(event, next, &graph->media_events, struct media_event, entry)
1782 if (event->code == EC_COMPLETE)
1784 list_remove(&event->entry);
1785 free(event);
1788 if (list_empty(&graph->media_events))
1789 ResetEvent(graph->media_event_handle);
1791 if (graph->defaultclock && !graph->refClock)
1792 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
1794 if (!stream_start && graph->refClock)
1796 IReferenceClock_GetTime(graph->refClock, &graph->stream_start);
1797 stream_start = graph->stream_start - graph->stream_elapsed;
1798 /* Delay presentation time by 200 ms, to give filters time to
1799 * initialize. */
1800 stream_start += 200 * 10000;
1803 if (SUCCEEDED(IMediaSeeking_GetStopPosition(&graph->IMediaSeeking_iface, &stream_stop)))
1804 graph->stream_stop = stream_stop;
1806 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1808 HRESULT filter_hr = IBaseFilter_Run(filter->filter, stream_start);
1809 if (hr == S_OK)
1810 hr = filter_hr;
1811 TRACE("Filter %p returned %#lx.\n", filter->filter, filter_hr);
1814 if (FAILED(hr))
1815 WARN("Failed to start stream, hr %#lx.\n", hr);
1817 return hr;
1820 static void CALLBACK async_run_cb(TP_CALLBACK_INSTANCE *instance, void *context, TP_WORK *work)
1822 struct filter_graph *graph = context;
1823 struct filter *filter;
1824 FILTER_STATE state;
1825 HRESULT hr;
1827 TRACE("Performing asynchronous state change.\n");
1829 /* We can't just call GetState(), since that will return State_Running and
1830 * VFW_S_STATE_INTERMEDIATE regardless of whether we're done pausing yet.
1831 * Instead replicate it here. */
1833 for (;;)
1835 IBaseFilter *async_filter = NULL;
1837 hr = S_OK;
1839 EnterCriticalSection(&graph->cs);
1841 if (!graph->needs_async_run)
1842 break;
1844 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1846 hr = IBaseFilter_GetState(filter->filter, 0, &state);
1848 if (hr == VFW_S_STATE_INTERMEDIATE)
1849 async_filter = filter->filter;
1851 if (SUCCEEDED(hr) && state != State_Paused)
1852 ERR("Filter %p reported incorrect state %u.\n", filter->filter, state);
1854 if (hr != S_OK)
1855 break;
1858 if (hr != VFW_S_STATE_INTERMEDIATE)
1859 break;
1861 LeaveCriticalSection(&graph->cs);
1863 IBaseFilter_GetState(async_filter, 10, &state);
1866 if (hr == S_OK && graph->needs_async_run)
1868 sort_filters(graph);
1869 graph_start(graph, 0);
1870 graph->needs_async_run = 0;
1873 LeaveCriticalSection(&graph->cs);
1876 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
1878 struct filter_graph *graph = impl_from_IMediaControl(iface);
1879 BOOL need_async_run = TRUE;
1880 struct filter *filter;
1881 FILTER_STATE state;
1882 HRESULT hr = S_OK;
1884 TRACE("graph %p.\n", graph);
1886 EnterCriticalSection(&graph->cs);
1888 if (graph->state == State_Running)
1890 LeaveCriticalSection(&graph->cs);
1891 return S_OK;
1894 sort_filters(graph);
1896 EnterCriticalSection(&graph->event_cs);
1897 update_render_count(graph);
1898 LeaveCriticalSection(&graph->event_cs);
1900 if (graph->state == State_Stopped)
1902 if (graph->defaultclock && !graph->refClock)
1903 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
1905 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
1907 HRESULT filter_hr = IBaseFilter_Pause(filter->filter);
1908 if (hr == S_OK)
1909 hr = filter_hr;
1910 TRACE("Filter %p returned %#lx.\n", filter->filter, filter_hr);
1912 /* If a filter returns VFW_S_CANT_CUE, we shouldn't wait for a
1913 * paused state. */
1914 filter_hr = IBaseFilter_GetState(filter->filter, 0, &state);
1915 if (filter_hr != S_OK && filter_hr != VFW_S_STATE_INTERMEDIATE)
1916 need_async_run = FALSE;
1919 if (FAILED(hr))
1921 LeaveCriticalSection(&graph->cs);
1922 WARN("Failed to pause, hr %#lx.\n", hr);
1923 return hr;
1927 graph->state = State_Running;
1929 if (SUCCEEDED(hr))
1931 if (hr != S_OK && need_async_run)
1933 if (!graph->async_run_work)
1934 graph->async_run_work = CreateThreadpoolWork(async_run_cb, graph, NULL);
1935 graph->needs_async_run = 1;
1936 SubmitThreadpoolWork(graph->async_run_work);
1938 else
1940 graph_start(graph, 0);
1944 LeaveCriticalSection(&graph->cs);
1945 return hr;
1948 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
1950 struct filter_graph *graph = impl_from_IMediaControl(iface);
1952 TRACE("graph %p.\n", graph);
1954 return IMediaFilter_Pause(&graph->IMediaFilter_iface);
1957 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
1959 struct filter_graph *graph = impl_from_IMediaControl(iface);
1961 TRACE("graph %p.\n", graph);
1963 return IMediaFilter_Stop(&graph->IMediaFilter_iface);
1966 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG timeout, OAFilterState *state)
1968 struct filter_graph *graph = impl_from_IMediaControl(iface);
1970 TRACE("graph %p, timeout %ld, state %p.\n", graph, timeout, state);
1972 if (timeout < 0) timeout = INFINITE;
1974 return IMediaFilter_GetState(&graph->IMediaFilter_iface, timeout, (FILTER_STATE *)state);
1977 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
1979 struct filter_graph *This = impl_from_IMediaControl(iface);
1981 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strFilename), strFilename);
1983 return IFilterGraph2_RenderFile(&This->IFilterGraph2_iface, strFilename, NULL);
1986 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
1987 IDispatch **ppUnk)
1989 struct filter_graph *This = impl_from_IMediaControl(iface);
1991 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
1993 return S_OK;
1996 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
1998 struct filter_graph *This = impl_from_IMediaControl(iface);
2000 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2002 return S_OK;
2005 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2007 struct filter_graph *This = impl_from_IMediaControl(iface);
2009 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2011 return S_OK;
2014 static void CALLBACK wait_pause_cb(TP_CALLBACK_INSTANCE *instance, void *context)
2016 IMediaControl *control = context;
2017 OAFilterState state;
2018 HRESULT hr;
2020 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
2021 ERR("Failed to get paused state, hr %#lx.\n", hr);
2023 if (FAILED(hr = IMediaControl_Stop(control)))
2024 ERR("Failed to stop, hr %#lx.\n", hr);
2026 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
2027 ERR("Failed to get paused state, hr %#lx.\n", hr);
2029 IMediaControl_Release(control);
2032 static void CALLBACK wait_stop_cb(TP_CALLBACK_INSTANCE *instance, void *context)
2034 IMediaControl *control = context;
2035 OAFilterState state;
2036 HRESULT hr;
2038 if ((hr = IMediaControl_GetState(control, INFINITE, &state)) != S_OK)
2039 ERR("Failed to get state, hr %#lx.\n", hr);
2041 IMediaControl_Release(control);
2044 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
2046 struct filter_graph *graph = impl_from_IMediaControl(iface);
2047 HRESULT hr;
2049 TRACE("graph %p.\n", graph);
2051 /* Even if we are already stopped, we still pause. */
2052 hr = IMediaControl_Pause(iface);
2053 if (FAILED(hr))
2054 return hr;
2055 else if (hr == S_FALSE)
2057 IMediaControl_AddRef(iface);
2058 TrySubmitThreadpoolCallback(wait_pause_cb, iface, NULL);
2059 return S_FALSE;
2062 hr = IMediaControl_Stop(iface);
2063 if (FAILED(hr))
2064 return hr;
2065 else if (hr == S_FALSE)
2067 IMediaControl_AddRef(iface);
2068 TrySubmitThreadpoolCallback(wait_stop_cb, iface, NULL);
2069 return S_FALSE;
2072 return S_OK;
2076 static const IMediaControlVtbl IMediaControl_VTable =
2078 MediaControl_QueryInterface,
2079 MediaControl_AddRef,
2080 MediaControl_Release,
2081 MediaControl_GetTypeInfoCount,
2082 MediaControl_GetTypeInfo,
2083 MediaControl_GetIDsOfNames,
2084 MediaControl_Invoke,
2085 MediaControl_Run,
2086 MediaControl_Pause,
2087 MediaControl_Stop,
2088 MediaControl_GetState,
2089 MediaControl_RenderFile,
2090 MediaControl_AddSourceFilter,
2091 MediaControl_get_FilterCollection,
2092 MediaControl_get_RegFilterCollection,
2093 MediaControl_StopWhenReady
2096 static struct filter_graph *impl_from_IMediaSeeking(IMediaSeeking *iface)
2098 return CONTAINING_RECORD(iface, struct filter_graph, IMediaSeeking_iface);
2101 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID iid, void **out)
2103 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2104 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2107 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2109 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2110 return IUnknown_AddRef(graph->outer_unk);
2113 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2115 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2116 return IUnknown_Release(graph->outer_unk);
2119 typedef HRESULT (WINAPI *fnFoundSeek)(struct filter_graph *This, IMediaSeeking*, DWORD_PTR arg);
2121 static HRESULT all_renderers_seek(struct filter_graph *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2122 BOOL allnotimpl = TRUE;
2123 HRESULT hr, hr_return = S_OK;
2124 struct filter *filter;
2126 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
2128 update_seeking(filter);
2129 if (!filter->seeking)
2130 continue;
2131 hr = FoundSeek(This, filter->seeking, arg);
2132 if (hr_return != E_NOTIMPL)
2133 allnotimpl = FALSE;
2134 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2135 hr_return = hr;
2138 if (allnotimpl)
2139 return E_NOTIMPL;
2140 return hr_return;
2143 static HRESULT WINAPI FoundCapabilities(struct filter_graph *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2145 HRESULT hr;
2146 DWORD caps = 0;
2148 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2149 if (FAILED(hr))
2150 return hr;
2152 /* Only add common capabilities everything supports */
2153 *(DWORD*)pcaps &= caps;
2155 return hr;
2158 /*** IMediaSeeking methods ***/
2159 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2161 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2162 HRESULT hr;
2164 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2166 if (!pCapabilities)
2167 return E_POINTER;
2169 EnterCriticalSection(&This->cs);
2170 *pCapabilities = 0xffffffff;
2172 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2173 LeaveCriticalSection(&This->cs);
2175 return hr;
2178 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2180 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2181 DWORD originalcaps;
2182 HRESULT hr;
2184 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2186 if (!pCapabilities)
2187 return E_POINTER;
2189 EnterCriticalSection(&This->cs);
2190 originalcaps = *pCapabilities;
2191 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2192 LeaveCriticalSection(&This->cs);
2194 if (FAILED(hr))
2195 return hr;
2197 if (!*pCapabilities)
2198 return E_FAIL;
2199 if (*pCapabilities != originalcaps)
2200 return S_FALSE;
2201 return S_OK;
2204 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2206 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2208 if (!pFormat)
2209 return E_POINTER;
2211 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2213 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2215 WARN("Unhandled time format %s\n", debugstr_guid(pFormat));
2216 return S_FALSE;
2219 return S_OK;
2222 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2224 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2226 if (!pFormat)
2227 return E_POINTER;
2229 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2230 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2232 return S_OK;
2235 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2237 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2239 if (!pFormat)
2240 return E_POINTER;
2242 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2243 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2245 return S_OK;
2248 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2250 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2252 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2253 if (!pFormat)
2254 return E_POINTER;
2256 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2257 return S_FALSE;
2259 return S_OK;
2262 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2264 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2266 if (!pFormat)
2267 return E_POINTER;
2269 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2271 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2273 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2274 return E_INVALIDARG;
2277 return S_OK;
2280 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *duration)
2282 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2283 HRESULT hr = E_NOTIMPL, filter_hr;
2284 LONGLONG filter_duration;
2285 struct filter *filter;
2287 TRACE("graph %p, duration %p.\n", graph, duration);
2289 if (!duration)
2290 return E_POINTER;
2292 *duration = 0;
2294 EnterCriticalSection(&graph->cs);
2296 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2298 update_seeking(filter);
2299 if (!filter->seeking)
2300 continue;
2302 filter_hr = IMediaSeeking_GetDuration(filter->seeking, &filter_duration);
2303 if (SUCCEEDED(filter_hr))
2305 hr = S_OK;
2306 *duration = max(*duration, filter_duration);
2308 else if (filter_hr != E_NOTIMPL)
2310 LeaveCriticalSection(&graph->cs);
2311 return filter_hr;
2315 LeaveCriticalSection(&graph->cs);
2317 TRACE("Returning hr %#lx, duration %s (%s seconds).\n", hr,
2318 wine_dbgstr_longlong(*duration), debugstr_time(*duration));
2319 return hr;
2322 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *stop)
2324 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2325 HRESULT hr = E_NOTIMPL, filter_hr;
2326 struct filter *filter;
2327 LONGLONG filter_stop;
2329 TRACE("graph %p, stop %p.\n", graph, stop);
2331 if (!stop)
2332 return E_POINTER;
2334 *stop = 0;
2336 EnterCriticalSection(&graph->cs);
2338 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2340 update_seeking(filter);
2341 if (!filter->seeking)
2342 continue;
2344 filter_hr = IMediaSeeking_GetStopPosition(filter->seeking, &filter_stop);
2345 if (SUCCEEDED(filter_hr))
2347 hr = S_OK;
2348 *stop = max(*stop, filter_stop);
2350 else if (filter_hr != E_NOTIMPL)
2352 LeaveCriticalSection(&graph->cs);
2353 return filter_hr;
2357 LeaveCriticalSection(&graph->cs);
2359 TRACE("Returning %s (%s seconds).\n", wine_dbgstr_longlong(*stop), debugstr_time(*stop));
2360 return hr;
2363 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *current)
2365 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2366 LONGLONG ret = graph->current_pos;
2368 TRACE("graph %p, current %p.\n", graph, current);
2370 if (!current)
2371 return E_POINTER;
2373 EnterCriticalSection(&graph->cs);
2375 if (graph->got_ec_complete)
2377 ret = graph->stream_stop;
2379 else if (graph->state == State_Running && !graph->needs_async_run && graph->refClock)
2381 REFERENCE_TIME time;
2382 IReferenceClock_GetTime(graph->refClock, &time);
2383 if (time)
2384 ret += time - graph->stream_start;
2387 LeaveCriticalSection(&graph->cs);
2389 TRACE("Returning %s (%s seconds).\n", wine_dbgstr_longlong(ret), debugstr_time(ret));
2390 *current = ret;
2392 return S_OK;
2395 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2396 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2398 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2400 TRACE("(%p/%p)->(%p, %s, 0x%s, %s)\n", This, iface, pTarget,
2401 debugstr_guid(pTargetFormat), wine_dbgstr_longlong(Source), debugstr_guid(pSourceFormat));
2403 if (!pSourceFormat)
2404 pSourceFormat = &This->timeformatseek;
2406 if (!pTargetFormat)
2407 pTargetFormat = &This->timeformatseek;
2409 if (IsEqualGUID(pTargetFormat, pSourceFormat))
2410 *pTarget = Source;
2411 else
2412 FIXME("conversion %s->%s not supported\n", debugstr_guid(pSourceFormat), debugstr_guid(pTargetFormat));
2414 return S_OK;
2417 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *current_ptr,
2418 DWORD current_flags, LONGLONG *stop_ptr, DWORD stop_flags)
2420 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2421 HRESULT hr = E_NOTIMPL, filter_hr;
2422 struct filter *filter;
2423 FILTER_STATE state;
2425 TRACE("graph %p, current %s, current_flags %#lx, stop %s, stop_flags %#lx.\n", graph,
2426 current_ptr ? wine_dbgstr_longlong(*current_ptr) : "<null>", current_flags,
2427 stop_ptr ? wine_dbgstr_longlong(*stop_ptr): "<null>", stop_flags);
2428 if (current_ptr)
2429 TRACE("Setting current position to %s (%s seconds).\n",
2430 wine_dbgstr_longlong(*current_ptr), debugstr_time(*current_ptr));
2431 if (stop_ptr)
2432 TRACE("Setting stop position to %s (%s seconds).\n",
2433 wine_dbgstr_longlong(*stop_ptr), debugstr_time(*stop_ptr));
2435 if ((current_flags & 0x7) != AM_SEEKING_AbsolutePositioning
2436 && (current_flags & 0x7) != AM_SEEKING_NoPositioning)
2437 FIXME("Unhandled current_flags %#lx.\n", current_flags & 0x7);
2439 if ((stop_flags & 0x7) != AM_SEEKING_NoPositioning
2440 && (stop_flags & 0x7) != AM_SEEKING_AbsolutePositioning)
2441 FIXME("Unhandled stop_flags %#lx.\n", stop_flags & 0x7);
2443 EnterCriticalSection(&graph->cs);
2445 state = graph->state;
2446 if (state == State_Running && !graph->needs_async_run)
2447 IMediaControl_Pause(&graph->IMediaControl_iface);
2449 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
2451 LONGLONG current = current_ptr ? *current_ptr : 0, stop = stop_ptr ? *stop_ptr : 0;
2453 update_seeking(filter);
2454 if (!filter->seeking)
2455 continue;
2457 filter_hr = IMediaSeeking_SetPositions(filter->seeking, &current,
2458 current_flags | AM_SEEKING_ReturnTime, &stop, stop_flags);
2459 if (SUCCEEDED(filter_hr))
2461 hr = S_OK;
2463 if (current_ptr && (current_flags & AM_SEEKING_ReturnTime))
2464 *current_ptr = current;
2465 if (stop_ptr && (stop_flags & AM_SEEKING_ReturnTime))
2466 *stop_ptr = stop;
2467 graph->current_pos = current;
2469 else if (filter_hr != E_NOTIMPL)
2471 LeaveCriticalSection(&graph->cs);
2472 return filter_hr;
2476 if ((current_flags & 0x7) != AM_SEEKING_NoPositioning && graph->refClock)
2478 IReferenceClock_GetTime(graph->refClock, &graph->stream_start);
2479 graph->stream_elapsed = 0;
2482 if (state == State_Running && !graph->needs_async_run)
2483 IMediaControl_Run(&graph->IMediaControl_iface);
2485 LeaveCriticalSection(&graph->cs);
2486 return hr;
2489 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface,
2490 LONGLONG *current, LONGLONG *stop)
2492 struct filter_graph *graph = impl_from_IMediaSeeking(iface);
2493 HRESULT hr = S_OK;
2495 TRACE("graph %p, current %p, stop %p.\n", graph, current, stop);
2497 if (current)
2498 hr = IMediaSeeking_GetCurrentPosition(iface, current);
2499 if (SUCCEEDED(hr) && stop)
2500 hr = IMediaSeeking_GetStopPosition(iface, stop);
2502 return hr;
2505 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2506 LONGLONG *pLatest)
2508 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2510 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2512 return S_OK;
2515 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2517 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2519 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2521 return S_OK;
2524 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2526 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2528 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2530 if (!pdRate)
2531 return E_POINTER;
2533 *pdRate = 1.0;
2535 return S_OK;
2538 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2540 struct filter_graph *This = impl_from_IMediaSeeking(iface);
2542 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2544 return S_OK;
2548 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2550 MediaSeeking_QueryInterface,
2551 MediaSeeking_AddRef,
2552 MediaSeeking_Release,
2553 MediaSeeking_GetCapabilities,
2554 MediaSeeking_CheckCapabilities,
2555 MediaSeeking_IsFormatSupported,
2556 MediaSeeking_QueryPreferredFormat,
2557 MediaSeeking_GetTimeFormat,
2558 MediaSeeking_IsUsingTimeFormat,
2559 MediaSeeking_SetTimeFormat,
2560 MediaSeeking_GetDuration,
2561 MediaSeeking_GetStopPosition,
2562 MediaSeeking_GetCurrentPosition,
2563 MediaSeeking_ConvertTimeFormat,
2564 MediaSeeking_SetPositions,
2565 MediaSeeking_GetPositions,
2566 MediaSeeking_GetAvailable,
2567 MediaSeeking_SetRate,
2568 MediaSeeking_GetRate,
2569 MediaSeeking_GetPreroll
2572 static struct filter_graph *impl_from_IMediaPosition(IMediaPosition *iface)
2574 return CONTAINING_RECORD(iface, struct filter_graph, IMediaPosition_iface);
2577 /*** IUnknown methods ***/
2578 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition *iface, REFIID iid, void **out)
2580 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2581 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2584 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2586 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2587 return IUnknown_AddRef(graph->outer_unk);
2590 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2592 struct filter_graph *graph = impl_from_IMediaPosition(iface);
2593 return IUnknown_Release(graph->outer_unk);
2596 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT *count)
2598 TRACE("iface %p, count %p.\n", iface, count);
2599 *count = 1;
2600 return S_OK;
2603 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT index,
2604 LCID lcid, ITypeInfo **typeinfo)
2606 TRACE("iface %p, index %u, lcid %#lx, typeinfo %p.\n", iface, index, lcid, typeinfo);
2607 return strmbase_get_typeinfo(IMediaPosition_tid, typeinfo);
2610 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition *iface, REFIID iid,
2611 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
2613 ITypeInfo *typeinfo;
2614 HRESULT hr;
2616 TRACE("iface %p, iid %s, names %p, count %u, lcid %#lx, ids %p.\n",
2617 iface, debugstr_guid(iid), names, count, lcid, ids);
2619 if (SUCCEEDED(hr = strmbase_get_typeinfo(IMediaPosition_tid, &typeinfo)))
2621 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
2622 ITypeInfo_Release(typeinfo);
2624 return hr;
2627 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition *iface, DISPID id, REFIID iid, LCID lcid,
2628 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
2630 ITypeInfo *typeinfo;
2631 HRESULT hr;
2633 TRACE("iface %p, id %ld, iid %s, lcid %#lx, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
2634 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
2636 if (SUCCEEDED(hr = strmbase_get_typeinfo(IMediaPosition_tid, &typeinfo)))
2638 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
2639 ITypeInfo_Release(typeinfo);
2641 return hr;
2644 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2646 GUID time_format;
2647 HRESULT hr;
2649 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2650 if (FAILED(hr))
2651 return hr;
2652 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2654 FIXME("Unsupported time format.\n");
2655 return E_NOTIMPL;
2658 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2659 return S_OK;
2662 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2664 GUID time_format;
2665 HRESULT hr;
2667 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2668 if (FAILED(hr))
2669 return hr;
2670 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2672 FIXME("Unsupported time format.\n");
2673 return E_NOTIMPL;
2676 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2677 return S_OK;
2680 /*** IMediaPosition methods ***/
2681 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2683 LONGLONG duration;
2684 struct filter_graph *This = impl_from_IMediaPosition( iface );
2685 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2686 if (FAILED(hr))
2687 return hr;
2688 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2691 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2693 struct filter_graph *This = impl_from_IMediaPosition( iface );
2694 LONGLONG reftime;
2695 HRESULT hr;
2697 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2698 if (FAILED(hr))
2699 return hr;
2700 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2701 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2704 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2706 struct filter_graph *This = impl_from_IMediaPosition( iface );
2707 LONGLONG pos;
2708 HRESULT hr;
2710 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2711 if (FAILED(hr))
2712 return hr;
2713 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2716 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2718 struct filter_graph *This = impl_from_IMediaPosition( iface );
2719 LONGLONG pos;
2720 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2721 if (FAILED(hr))
2722 return hr;
2723 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2726 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2728 struct filter_graph *This = impl_from_IMediaPosition( iface );
2729 LONGLONG reftime;
2730 HRESULT hr;
2732 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2733 if (FAILED(hr))
2734 return hr;
2735 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2736 &reftime, AM_SEEKING_AbsolutePositioning);
2739 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime)
2741 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2742 return E_NOTIMPL;
2745 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime)
2747 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2748 return E_NOTIMPL;
2751 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2753 struct filter_graph *This = impl_from_IMediaPosition( iface );
2754 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2757 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2759 struct filter_graph *This = impl_from_IMediaPosition( iface );
2760 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2763 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward)
2765 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2766 return E_NOTIMPL;
2769 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward)
2771 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2772 return E_NOTIMPL;
2776 static const IMediaPositionVtbl IMediaPosition_VTable =
2778 MediaPosition_QueryInterface,
2779 MediaPosition_AddRef,
2780 MediaPosition_Release,
2781 MediaPosition_GetTypeInfoCount,
2782 MediaPosition_GetTypeInfo,
2783 MediaPosition_GetIDsOfNames,
2784 MediaPosition_Invoke,
2785 MediaPosition_get_Duration,
2786 MediaPosition_put_CurrentPosition,
2787 MediaPosition_get_CurrentPosition,
2788 MediaPosition_get_StopTime,
2789 MediaPosition_put_StopTime,
2790 MediaPosition_get_PrerollTime,
2791 MediaPosition_put_PrerollTime,
2792 MediaPosition_put_Rate,
2793 MediaPosition_get_Rate,
2794 MediaPosition_CanSeekForward,
2795 MediaPosition_CanSeekBackward
2798 static struct filter_graph *impl_from_IObjectWithSite(IObjectWithSite *iface)
2800 return CONTAINING_RECORD(iface, struct filter_graph, IObjectWithSite_iface);
2803 /*** IUnknown methods ***/
2804 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID iid, void **out)
2806 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2807 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2810 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
2812 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2813 return IUnknown_AddRef(graph->outer_unk);
2816 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
2818 struct filter_graph *graph = impl_from_IObjectWithSite(iface);
2819 return IUnknown_Release(graph->outer_unk);
2822 /*** IObjectWithSite methods ***/
2824 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
2826 struct filter_graph *This = impl_from_IObjectWithSite( iface );
2828 TRACE("(%p/%p)->()\n", This, iface);
2829 if (This->pSite) IUnknown_Release(This->pSite);
2830 This->pSite = pUnkSite;
2831 IUnknown_AddRef(This->pSite);
2832 return S_OK;
2835 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, PVOID *ppvSite)
2837 struct filter_graph *This = impl_from_IObjectWithSite( iface );
2839 TRACE("(%p/%p)->(%s)\n", This, iface,debugstr_guid(riid));
2841 *ppvSite = NULL;
2842 if (!This->pSite)
2843 return E_FAIL;
2844 else
2845 return IUnknown_QueryInterface(This->pSite, riid, ppvSite);
2848 static const IObjectWithSiteVtbl IObjectWithSite_VTable =
2850 ObjectWithSite_QueryInterface,
2851 ObjectWithSite_AddRef,
2852 ObjectWithSite_Release,
2853 ObjectWithSite_SetSite,
2854 ObjectWithSite_GetSite,
2857 static HRESULT GetTargetInterface(struct filter_graph* pGraph, REFIID riid, LPVOID* ppvObj)
2859 struct filter *filter;
2860 HRESULT hr;
2861 int entry;
2863 /* Check if the interface type is already registered */
2864 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2865 if (riid == pGraph->ItfCacheEntries[entry].riid)
2867 if (pGraph->ItfCacheEntries[entry].iface)
2869 /* Return the interface if available */
2870 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2871 return S_OK;
2873 break;
2876 if (entry >= MAX_ITF_CACHE_ENTRIES)
2878 FIXME("Not enough space to store interface in the cache\n");
2879 return E_OUTOFMEMORY;
2882 /* Find a filter supporting the requested interface */
2883 LIST_FOR_EACH_ENTRY(filter, &pGraph->filters, struct filter, entry)
2885 hr = IBaseFilter_QueryInterface(filter->filter, riid, ppvObj);
2886 if (hr == S_OK)
2888 pGraph->ItfCacheEntries[entry].riid = riid;
2889 pGraph->ItfCacheEntries[entry].filter = filter->filter;
2890 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2891 if (entry >= pGraph->nItfCacheEntries)
2892 pGraph->nItfCacheEntries++;
2893 return S_OK;
2895 if (hr != E_NOINTERFACE)
2896 return hr;
2899 return IsEqualGUID(riid, &IID_IBasicAudio) ? E_NOTIMPL : E_NOINTERFACE;
2902 static struct filter_graph *impl_from_IBasicAudio(IBasicAudio *iface)
2904 return CONTAINING_RECORD(iface, struct filter_graph, IBasicAudio_iface);
2907 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID iid, void **out)
2909 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2910 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
2913 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
2915 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2916 return IUnknown_AddRef(graph->outer_unk);
2919 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
2921 struct filter_graph *graph = impl_from_IBasicAudio(iface);
2922 return IUnknown_Release(graph->outer_unk);
2925 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *count)
2927 TRACE("iface %p, count %p.\n", iface, count);
2928 *count = 1;
2929 return S_OK;
2932 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT index,
2933 LCID lcid, ITypeInfo **typeinfo)
2935 TRACE("iface %p, index %u, lcid %#lx, typeinfo %p.\n", iface, index, lcid, typeinfo);
2936 return strmbase_get_typeinfo(IBasicAudio_tid, typeinfo);
2939 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID iid,
2940 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
2942 ITypeInfo *typeinfo;
2943 HRESULT hr;
2945 TRACE("iface %p, iid %s, names %p, count %u, lcid %#lx, ids %p.\n",
2946 iface, debugstr_guid(iid), names, count, lcid, ids);
2948 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicAudio_tid, &typeinfo)))
2950 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
2951 ITypeInfo_Release(typeinfo);
2953 return hr;
2956 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID id, REFIID iid, LCID lcid,
2957 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
2959 ITypeInfo *typeinfo;
2960 HRESULT hr;
2962 TRACE("iface %p, id %ld, iid %s, lcid %#lx, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
2963 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
2965 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicAudio_tid, &typeinfo)))
2967 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
2968 ITypeInfo_Release(typeinfo);
2970 return hr;
2973 /*** IBasicAudio methods ***/
2974 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
2976 struct filter_graph *This = impl_from_IBasicAudio(iface);
2977 IBasicAudio* pBasicAudio;
2978 HRESULT hr;
2980 TRACE("graph %p, volume %ld.\n", This, lVolume);
2982 EnterCriticalSection(&This->cs);
2984 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2986 if (hr == S_OK)
2987 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
2989 LeaveCriticalSection(&This->cs);
2991 return hr;
2994 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
2996 struct filter_graph *This = impl_from_IBasicAudio(iface);
2997 IBasicAudio* pBasicAudio;
2998 HRESULT hr;
3000 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
3002 EnterCriticalSection(&This->cs);
3004 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3006 if (hr == S_OK)
3007 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
3009 LeaveCriticalSection(&This->cs);
3011 return hr;
3014 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
3016 struct filter_graph *This = impl_from_IBasicAudio(iface);
3017 IBasicAudio* pBasicAudio;
3018 HRESULT hr;
3020 TRACE("graph %p, balance %ld.\n", This, lBalance);
3022 EnterCriticalSection(&This->cs);
3024 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3026 if (hr == S_OK)
3027 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
3029 LeaveCriticalSection(&This->cs);
3031 return hr;
3034 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
3036 struct filter_graph *This = impl_from_IBasicAudio(iface);
3037 IBasicAudio* pBasicAudio;
3038 HRESULT hr;
3040 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
3042 EnterCriticalSection(&This->cs);
3044 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3046 if (hr == S_OK)
3047 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
3049 LeaveCriticalSection(&This->cs);
3051 return hr;
3054 static const IBasicAudioVtbl IBasicAudio_VTable =
3056 BasicAudio_QueryInterface,
3057 BasicAudio_AddRef,
3058 BasicAudio_Release,
3059 BasicAudio_GetTypeInfoCount,
3060 BasicAudio_GetTypeInfo,
3061 BasicAudio_GetIDsOfNames,
3062 BasicAudio_Invoke,
3063 BasicAudio_put_Volume,
3064 BasicAudio_get_Volume,
3065 BasicAudio_put_Balance,
3066 BasicAudio_get_Balance
3069 static struct filter_graph *impl_from_IBasicVideo2(IBasicVideo2 *iface)
3071 return CONTAINING_RECORD(iface, struct filter_graph, IBasicVideo2_iface);
3074 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID iid, void **out)
3076 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
3077 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
3080 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
3082 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
3083 return IUnknown_AddRef(graph->outer_unk);
3086 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
3088 struct filter_graph *graph = impl_from_IBasicVideo2(iface);
3089 return IUnknown_Release(graph->outer_unk);
3092 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *count)
3094 TRACE("iface %p, count %p.\n", iface, count);
3095 *count = 1;
3096 return S_OK;
3099 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT index,
3100 LCID lcid, ITypeInfo **typeinfo)
3102 TRACE("iface %p, index %u, lcid %#lx, typeinfo %p.\n", iface, index, lcid, typeinfo);
3103 return strmbase_get_typeinfo(IBasicVideo_tid, typeinfo);
3106 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID iid,
3107 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
3109 ITypeInfo *typeinfo;
3110 HRESULT hr;
3112 TRACE("iface %p, iid %s, names %p, count %u, lcid %#lx, ids %p.\n",
3113 iface, debugstr_guid(iid), names, count, lcid, ids);
3115 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicVideo_tid, &typeinfo)))
3117 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
3118 ITypeInfo_Release(typeinfo);
3120 return hr;
3123 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID id, REFIID iid, LCID lcid,
3124 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
3126 ITypeInfo *typeinfo;
3127 HRESULT hr;
3129 TRACE("iface %p, id %ld, iid %s, lcid %#lx, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
3130 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
3132 if (SUCCEEDED(hr = strmbase_get_typeinfo(IBasicVideo_tid, &typeinfo)))
3134 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
3135 ITypeInfo_Release(typeinfo);
3137 return hr;
3140 /*** IBasicVideo methods ***/
3141 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3143 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3144 IBasicVideo *pBasicVideo;
3145 HRESULT hr;
3147 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3149 EnterCriticalSection(&This->cs);
3151 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3153 if (hr == S_OK)
3154 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3156 LeaveCriticalSection(&This->cs);
3158 return hr;
3161 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3163 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3164 IBasicVideo *pBasicVideo;
3165 HRESULT hr;
3167 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3169 EnterCriticalSection(&This->cs);
3171 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3173 if (hr == S_OK)
3174 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3176 LeaveCriticalSection(&This->cs);
3178 return hr;
3181 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3183 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3184 IBasicVideo *pBasicVideo;
3185 HRESULT hr;
3187 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3189 EnterCriticalSection(&This->cs);
3191 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3193 if (hr == S_OK)
3194 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3196 LeaveCriticalSection(&This->cs);
3198 return hr;
3201 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3203 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3204 IBasicVideo *pBasicVideo;
3205 HRESULT hr;
3207 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3209 EnterCriticalSection(&This->cs);
3211 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3213 if (hr == S_OK)
3214 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3216 LeaveCriticalSection(&This->cs);
3218 return hr;
3221 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3223 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3224 IBasicVideo *pBasicVideo;
3225 HRESULT hr;
3227 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3229 EnterCriticalSection(&This->cs);
3231 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3233 if (hr == S_OK)
3234 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3236 LeaveCriticalSection(&This->cs);
3238 return hr;
3241 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3243 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3244 IBasicVideo *pBasicVideo;
3245 HRESULT hr;
3247 TRACE("graph %p, left %ld.\n", This, SourceLeft);
3249 EnterCriticalSection(&This->cs);
3251 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3253 if (hr == S_OK)
3254 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3256 LeaveCriticalSection(&This->cs);
3258 return hr;
3261 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3263 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3264 IBasicVideo *pBasicVideo;
3265 HRESULT hr;
3267 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3269 EnterCriticalSection(&This->cs);
3271 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3273 if (hr == S_OK)
3274 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3276 LeaveCriticalSection(&This->cs);
3278 return hr;
3281 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3283 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3284 IBasicVideo *pBasicVideo;
3285 HRESULT hr;
3287 TRACE("graph %p, width %ld.\n", This, SourceWidth);
3289 EnterCriticalSection(&This->cs);
3291 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3293 if (hr == S_OK)
3294 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3296 LeaveCriticalSection(&This->cs);
3298 return hr;
3301 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3303 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3304 IBasicVideo *pBasicVideo;
3305 HRESULT hr;
3307 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3309 EnterCriticalSection(&This->cs);
3311 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3313 if (hr == S_OK)
3314 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3316 LeaveCriticalSection(&This->cs);
3318 return hr;
3321 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3323 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3324 IBasicVideo *pBasicVideo;
3325 HRESULT hr;
3327 TRACE("graph %p, top %ld.\n", This, SourceTop);
3329 EnterCriticalSection(&This->cs);
3331 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3333 if (hr == S_OK)
3334 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3336 LeaveCriticalSection(&This->cs);
3338 return hr;
3341 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3343 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3344 IBasicVideo *pBasicVideo;
3345 HRESULT hr;
3347 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3349 EnterCriticalSection(&This->cs);
3351 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3353 if (hr == S_OK)
3354 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3356 LeaveCriticalSection(&This->cs);
3358 return hr;
3361 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3363 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3364 IBasicVideo *pBasicVideo;
3365 HRESULT hr;
3367 TRACE("graph %p, height %ld.\n", This, SourceHeight);
3369 EnterCriticalSection(&This->cs);
3371 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3373 if (hr == S_OK)
3374 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3376 LeaveCriticalSection(&This->cs);
3378 return hr;
3381 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3383 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3384 IBasicVideo *pBasicVideo;
3385 HRESULT hr;
3387 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3389 EnterCriticalSection(&This->cs);
3391 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3393 if (hr == S_OK)
3394 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3396 LeaveCriticalSection(&This->cs);
3398 return hr;
3401 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3403 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3404 IBasicVideo *pBasicVideo;
3405 HRESULT hr;
3407 TRACE("graph %p, left %ld.\n", This, DestinationLeft);
3409 EnterCriticalSection(&This->cs);
3411 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3413 if (hr == S_OK)
3414 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3416 LeaveCriticalSection(&This->cs);
3418 return hr;
3421 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3423 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3424 IBasicVideo *pBasicVideo;
3425 HRESULT hr;
3427 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3429 EnterCriticalSection(&This->cs);
3431 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3433 if (hr == S_OK)
3434 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3436 LeaveCriticalSection(&This->cs);
3438 return hr;
3441 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3443 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3444 IBasicVideo *pBasicVideo;
3445 HRESULT hr;
3447 TRACE("graph %p, width %ld.\n", This, DestinationWidth);
3449 EnterCriticalSection(&This->cs);
3451 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3453 if (hr == S_OK)
3454 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3456 LeaveCriticalSection(&This->cs);
3458 return hr;
3461 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3463 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3464 IBasicVideo *pBasicVideo;
3465 HRESULT hr;
3467 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3469 EnterCriticalSection(&This->cs);
3471 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3473 if (hr == S_OK)
3474 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3476 LeaveCriticalSection(&This->cs);
3478 return hr;
3481 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3483 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3484 IBasicVideo *pBasicVideo;
3485 HRESULT hr;
3487 TRACE("graph %p, top %ld.\n", This, DestinationTop);
3489 EnterCriticalSection(&This->cs);
3491 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3493 if (hr == S_OK)
3494 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3496 LeaveCriticalSection(&This->cs);
3498 return hr;
3501 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3503 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3504 IBasicVideo *pBasicVideo;
3505 HRESULT hr;
3507 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3509 EnterCriticalSection(&This->cs);
3511 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3513 if (hr == S_OK)
3514 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3516 LeaveCriticalSection(&This->cs);
3518 return hr;
3521 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3523 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3524 IBasicVideo *pBasicVideo;
3525 HRESULT hr;
3527 TRACE("graph %p, height %ld.\n", This, DestinationHeight);
3529 EnterCriticalSection(&This->cs);
3531 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3533 if (hr == S_OK)
3534 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3536 LeaveCriticalSection(&This->cs);
3538 return hr;
3541 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3542 LONG *pDestinationHeight)
3544 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3545 IBasicVideo *pBasicVideo;
3546 HRESULT hr;
3548 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3550 EnterCriticalSection(&This->cs);
3552 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3554 if (hr == S_OK)
3555 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3557 LeaveCriticalSection(&This->cs);
3559 return hr;
3562 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3563 LONG Width, LONG Height)
3565 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3566 IBasicVideo *pBasicVideo;
3567 HRESULT hr;
3569 TRACE("graph %p, left %ld, top %ld, width %ld, height %ld.\n", This, Left, Top, Width, Height);
3571 EnterCriticalSection(&This->cs);
3573 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3575 if (hr == S_OK)
3576 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3578 LeaveCriticalSection(&This->cs);
3580 return hr;
3583 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3584 LONG *pWidth, LONG *pHeight)
3586 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3587 IBasicVideo *pBasicVideo;
3588 HRESULT hr;
3590 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3592 EnterCriticalSection(&This->cs);
3594 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3596 if (hr == S_OK)
3597 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3599 LeaveCriticalSection(&This->cs);
3601 return hr;
3604 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3606 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3607 IBasicVideo *pBasicVideo;
3608 HRESULT hr;
3610 TRACE("(%p/%p)->()\n", This, iface);
3612 EnterCriticalSection(&This->cs);
3614 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3616 if (hr == S_OK)
3617 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3619 LeaveCriticalSection(&This->cs);
3621 return hr;
3624 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3625 LONG Width, LONG Height)
3627 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3628 IBasicVideo *pBasicVideo;
3629 HRESULT hr;
3631 TRACE("graph %p, left %ld, top %ld, width %ld, height %ld.\n", This, Left, Top, Width, Height);
3633 EnterCriticalSection(&This->cs);
3635 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3637 if (hr == S_OK)
3638 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3640 LeaveCriticalSection(&This->cs);
3642 return hr;
3645 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3646 LONG *pTop, LONG *pWidth, LONG *pHeight)
3648 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3649 IBasicVideo *pBasicVideo;
3650 HRESULT hr;
3652 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3654 EnterCriticalSection(&This->cs);
3656 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3658 if (hr == S_OK)
3659 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3661 LeaveCriticalSection(&This->cs);
3663 return hr;
3666 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3668 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3669 IBasicVideo *pBasicVideo;
3670 HRESULT hr;
3672 TRACE("(%p/%p)->()\n", This, iface);
3674 EnterCriticalSection(&This->cs);
3676 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3678 if (hr == S_OK)
3679 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3681 LeaveCriticalSection(&This->cs);
3683 return hr;
3686 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3688 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3689 IBasicVideo *pBasicVideo;
3690 HRESULT hr;
3692 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3694 EnterCriticalSection(&This->cs);
3696 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3698 if (hr == S_OK)
3699 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3701 LeaveCriticalSection(&This->cs);
3703 return hr;
3706 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3707 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3709 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3710 IBasicVideo *pBasicVideo;
3711 HRESULT hr;
3713 TRACE("graph %p, start_index %ld, count %ld, ret_count %p, entries %p.\n",
3714 This, StartIndex, Entries, pRetrieved, pPalette);
3716 EnterCriticalSection(&This->cs);
3718 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3720 if (hr == S_OK)
3721 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3723 LeaveCriticalSection(&This->cs);
3725 return hr;
3728 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3729 LONG *pDIBImage)
3731 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3732 IBasicVideo *pBasicVideo;
3733 HRESULT hr;
3735 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3737 EnterCriticalSection(&This->cs);
3739 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3741 if (hr == S_OK)
3742 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3744 LeaveCriticalSection(&This->cs);
3746 return hr;
3749 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3751 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3752 IBasicVideo *pBasicVideo;
3753 HRESULT hr;
3755 TRACE("(%p/%p)->()\n", This, iface);
3757 EnterCriticalSection(&This->cs);
3759 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3761 if (hr == S_OK)
3762 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3764 LeaveCriticalSection(&This->cs);
3766 return hr;
3769 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3771 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3772 IBasicVideo *pBasicVideo;
3773 HRESULT hr;
3775 TRACE("(%p/%p)->()\n", This, iface);
3777 EnterCriticalSection(&This->cs);
3779 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3781 if (hr == S_OK)
3782 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3784 LeaveCriticalSection(&This->cs);
3786 return hr;
3789 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3790 LONG *plAspectY)
3792 struct filter_graph *This = impl_from_IBasicVideo2(iface);
3793 IBasicVideo2 *pBasicVideo2;
3794 HRESULT hr;
3796 TRACE("(%p/%p)->()\n", This, iface);
3798 EnterCriticalSection(&This->cs);
3800 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3802 if (hr == S_OK)
3803 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3805 LeaveCriticalSection(&This->cs);
3807 return hr;
3810 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3812 BasicVideo_QueryInterface,
3813 BasicVideo_AddRef,
3814 BasicVideo_Release,
3815 BasicVideo_GetTypeInfoCount,
3816 BasicVideo_GetTypeInfo,
3817 BasicVideo_GetIDsOfNames,
3818 BasicVideo_Invoke,
3819 BasicVideo_get_AvgTimePerFrame,
3820 BasicVideo_get_BitRate,
3821 BasicVideo_get_BitErrorRate,
3822 BasicVideo_get_VideoWidth,
3823 BasicVideo_get_VideoHeight,
3824 BasicVideo_put_SourceLeft,
3825 BasicVideo_get_SourceLeft,
3826 BasicVideo_put_SourceWidth,
3827 BasicVideo_get_SourceWidth,
3828 BasicVideo_put_SourceTop,
3829 BasicVideo_get_SourceTop,
3830 BasicVideo_put_SourceHeight,
3831 BasicVideo_get_SourceHeight,
3832 BasicVideo_put_DestinationLeft,
3833 BasicVideo_get_DestinationLeft,
3834 BasicVideo_put_DestinationWidth,
3835 BasicVideo_get_DestinationWidth,
3836 BasicVideo_put_DestinationTop,
3837 BasicVideo_get_DestinationTop,
3838 BasicVideo_put_DestinationHeight,
3839 BasicVideo_get_DestinationHeight,
3840 BasicVideo_SetSourcePosition,
3841 BasicVideo_GetSourcePosition,
3842 BasicVideo_SetDefaultSourcePosition,
3843 BasicVideo_SetDestinationPosition,
3844 BasicVideo_GetDestinationPosition,
3845 BasicVideo_SetDefaultDestinationPosition,
3846 BasicVideo_GetVideoSize,
3847 BasicVideo_GetVideoPaletteEntries,
3848 BasicVideo_GetCurrentImage,
3849 BasicVideo_IsUsingDefaultSource,
3850 BasicVideo_IsUsingDefaultDestination,
3851 BasicVideo2_GetPreferredAspectRatio
3854 static struct filter_graph *impl_from_IVideoWindow(IVideoWindow *iface)
3856 return CONTAINING_RECORD(iface, struct filter_graph, IVideoWindow_iface);
3859 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID iid, void **out)
3861 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3862 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
3865 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
3867 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3868 return IUnknown_AddRef(graph->outer_unk);
3871 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
3873 struct filter_graph *graph = impl_from_IVideoWindow(iface);
3874 return IUnknown_Release(graph->outer_unk);
3877 HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *count)
3879 TRACE("iface %p, count %p.\n", iface, count);
3880 *count = 1;
3881 return S_OK;
3884 HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT index,
3885 LCID lcid, ITypeInfo **typeinfo)
3887 TRACE("iface %p, index %u, lcid %#lx, typeinfo %p.\n", iface, index, lcid, typeinfo);
3888 return strmbase_get_typeinfo(IVideoWindow_tid, typeinfo);
3891 HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID iid,
3892 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
3894 ITypeInfo *typeinfo;
3895 HRESULT hr;
3897 TRACE("iface %p, iid %s, names %p, count %u, lcid %#lx, ids %p.\n",
3898 iface, debugstr_guid(iid), names, count, lcid, ids);
3900 if (SUCCEEDED(hr = strmbase_get_typeinfo(IVideoWindow_tid, &typeinfo)))
3902 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
3903 ITypeInfo_Release(typeinfo);
3905 return hr;
3908 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID id, REFIID iid, LCID lcid,
3909 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
3911 ITypeInfo *typeinfo;
3912 HRESULT hr;
3914 TRACE("iface %p, id %ld, iid %s, lcid %#lx, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
3915 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
3917 if (SUCCEEDED(hr = strmbase_get_typeinfo(IVideoWindow_tid, &typeinfo)))
3919 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
3920 ITypeInfo_Release(typeinfo);
3922 return hr;
3925 /*** IVideoWindow methods ***/
3926 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
3928 struct filter_graph *This = impl_from_IVideoWindow(iface);
3929 IVideoWindow *pVideoWindow;
3930 HRESULT hr;
3932 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
3934 EnterCriticalSection(&This->cs);
3936 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3938 if (hr == S_OK)
3939 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
3941 LeaveCriticalSection(&This->cs);
3943 return hr;
3946 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
3948 struct filter_graph *This = impl_from_IVideoWindow(iface);
3949 IVideoWindow *pVideoWindow;
3950 HRESULT hr;
3952 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
3954 EnterCriticalSection(&This->cs);
3956 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3958 if (hr == S_OK)
3959 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
3961 LeaveCriticalSection(&This->cs);
3963 return hr;
3966 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
3968 struct filter_graph *This = impl_from_IVideoWindow(iface);
3969 IVideoWindow *pVideoWindow;
3970 HRESULT hr;
3972 TRACE("graph %p, style %#lx.\n", This, WindowStyle);
3974 EnterCriticalSection(&This->cs);
3976 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3978 if (hr == S_OK)
3979 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
3981 LeaveCriticalSection(&This->cs);
3983 return hr;
3986 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
3988 struct filter_graph *This = impl_from_IVideoWindow(iface);
3989 IVideoWindow *pVideoWindow;
3990 HRESULT hr;
3992 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
3994 EnterCriticalSection(&This->cs);
3996 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
3998 if (hr == S_OK)
3999 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
4001 LeaveCriticalSection(&This->cs);
4003 return hr;
4006 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
4008 struct filter_graph *This = impl_from_IVideoWindow(iface);
4009 IVideoWindow *pVideoWindow;
4010 HRESULT hr;
4012 TRACE("graph %p, style %#lx.\n", This, WindowStyleEx);
4014 EnterCriticalSection(&This->cs);
4016 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4018 if (hr == S_OK)
4019 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
4021 LeaveCriticalSection(&This->cs);
4023 return hr;
4026 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
4028 struct filter_graph *This = impl_from_IVideoWindow(iface);
4029 IVideoWindow *pVideoWindow;
4030 HRESULT hr;
4032 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
4034 EnterCriticalSection(&This->cs);
4036 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4038 if (hr == S_OK)
4039 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
4041 LeaveCriticalSection(&This->cs);
4043 return hr;
4046 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
4048 struct filter_graph *This = impl_from_IVideoWindow(iface);
4049 IVideoWindow *pVideoWindow;
4050 HRESULT hr;
4052 TRACE("graph %p, show %#lx.\n", This, AutoShow);
4054 EnterCriticalSection(&This->cs);
4056 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4058 if (hr == S_OK)
4059 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4061 LeaveCriticalSection(&This->cs);
4063 return hr;
4066 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
4068 struct filter_graph *This = impl_from_IVideoWindow(iface);
4069 IVideoWindow *pVideoWindow;
4070 HRESULT hr;
4072 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4074 EnterCriticalSection(&This->cs);
4076 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4078 if (hr == S_OK)
4079 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4081 LeaveCriticalSection(&This->cs);
4083 return hr;
4086 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
4088 struct filter_graph *This = impl_from_IVideoWindow(iface);
4089 IVideoWindow *pVideoWindow;
4090 HRESULT hr;
4092 TRACE("graph %p, state %ld.\n", This, WindowState);
4094 EnterCriticalSection(&This->cs);
4096 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4098 if (hr == S_OK)
4099 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4101 LeaveCriticalSection(&This->cs);
4103 return hr;
4106 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4108 struct filter_graph *This = impl_from_IVideoWindow(iface);
4109 IVideoWindow *pVideoWindow;
4110 HRESULT hr;
4112 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4114 EnterCriticalSection(&This->cs);
4116 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4118 if (hr == S_OK)
4119 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4121 LeaveCriticalSection(&This->cs);
4123 return hr;
4126 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4128 struct filter_graph *This = impl_from_IVideoWindow(iface);
4129 IVideoWindow *pVideoWindow;
4130 HRESULT hr;
4132 TRACE("graph %p, palette %ld.\n", This, BackgroundPalette);
4134 EnterCriticalSection(&This->cs);
4136 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4138 if (hr == S_OK)
4139 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4141 LeaveCriticalSection(&This->cs);
4143 return hr;
4146 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4147 LONG *pBackgroundPalette)
4149 struct filter_graph *This = impl_from_IVideoWindow(iface);
4150 IVideoWindow *pVideoWindow;
4151 HRESULT hr;
4153 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4155 EnterCriticalSection(&This->cs);
4157 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4159 if (hr == S_OK)
4160 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4162 LeaveCriticalSection(&This->cs);
4164 return hr;
4167 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4169 struct filter_graph *This = impl_from_IVideoWindow(iface);
4170 IVideoWindow *pVideoWindow;
4171 HRESULT hr;
4173 TRACE("graph %p, visible %ld.\n", This, Visible);
4175 EnterCriticalSection(&This->cs);
4177 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4179 if (hr == S_OK)
4180 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4182 LeaveCriticalSection(&This->cs);
4184 return hr;
4187 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4189 struct filter_graph *This = impl_from_IVideoWindow(iface);
4190 IVideoWindow *pVideoWindow;
4191 HRESULT hr;
4193 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4195 EnterCriticalSection(&This->cs);
4197 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4199 if (hr == S_OK)
4200 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4202 LeaveCriticalSection(&This->cs);
4204 return hr;
4207 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4209 struct filter_graph *This = impl_from_IVideoWindow(iface);
4210 IVideoWindow *pVideoWindow;
4211 HRESULT hr;
4213 TRACE("graph %p, left %ld.\n", This, Left);
4215 EnterCriticalSection(&This->cs);
4217 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4219 if (hr == S_OK)
4220 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4222 LeaveCriticalSection(&This->cs);
4224 return hr;
4227 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4229 struct filter_graph *This = impl_from_IVideoWindow(iface);
4230 IVideoWindow *pVideoWindow;
4231 HRESULT hr;
4233 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4235 EnterCriticalSection(&This->cs);
4237 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4239 if (hr == S_OK)
4240 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4242 LeaveCriticalSection(&This->cs);
4244 return hr;
4247 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4249 struct filter_graph *This = impl_from_IVideoWindow(iface);
4250 IVideoWindow *pVideoWindow;
4251 HRESULT hr;
4253 TRACE("graph %p, width %ld.\n", This, Width);
4255 EnterCriticalSection(&This->cs);
4257 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4259 if (hr == S_OK)
4260 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4262 LeaveCriticalSection(&This->cs);
4264 return hr;
4267 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4269 struct filter_graph *This = impl_from_IVideoWindow(iface);
4270 IVideoWindow *pVideoWindow;
4271 HRESULT hr;
4273 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4275 EnterCriticalSection(&This->cs);
4277 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4279 if (hr == S_OK)
4280 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4282 LeaveCriticalSection(&This->cs);
4284 return hr;
4287 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4289 struct filter_graph *This = impl_from_IVideoWindow(iface);
4290 IVideoWindow *pVideoWindow;
4291 HRESULT hr;
4293 TRACE("graph %p, top %ld.\n", This, Top);
4295 EnterCriticalSection(&This->cs);
4297 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4299 if (hr == S_OK)
4300 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4302 LeaveCriticalSection(&This->cs);
4304 return hr;
4307 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4309 struct filter_graph *This = impl_from_IVideoWindow(iface);
4310 IVideoWindow *pVideoWindow;
4311 HRESULT hr;
4313 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4315 EnterCriticalSection(&This->cs);
4317 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4319 if (hr == S_OK)
4320 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4322 LeaveCriticalSection(&This->cs);
4324 return hr;
4327 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4329 struct filter_graph *This = impl_from_IVideoWindow(iface);
4330 IVideoWindow *pVideoWindow;
4331 HRESULT hr;
4333 TRACE("graph %p, height %ld.\n", This, Height);
4335 EnterCriticalSection(&This->cs);
4337 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4339 if (hr == S_OK)
4340 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4342 LeaveCriticalSection(&This->cs);
4344 return hr;
4347 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4349 struct filter_graph *This = impl_from_IVideoWindow(iface);
4350 IVideoWindow *pVideoWindow;
4351 HRESULT hr;
4353 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4355 EnterCriticalSection(&This->cs);
4357 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4359 if (hr == S_OK)
4360 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4362 LeaveCriticalSection(&This->cs);
4364 return hr;
4367 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4369 struct filter_graph *This = impl_from_IVideoWindow(iface);
4370 IVideoWindow *pVideoWindow;
4371 HRESULT hr;
4373 TRACE("graph %p, owner %#Ix.\n", This, Owner);
4375 EnterCriticalSection(&This->cs);
4377 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4379 if (hr == S_OK)
4380 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4382 LeaveCriticalSection(&This->cs);
4384 return hr;
4387 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4389 struct filter_graph *This = impl_from_IVideoWindow(iface);
4390 IVideoWindow *pVideoWindow;
4391 HRESULT hr;
4393 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4395 EnterCriticalSection(&This->cs);
4397 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4399 if (hr == S_OK)
4400 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4402 LeaveCriticalSection(&This->cs);
4404 return hr;
4407 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4409 struct filter_graph *This = impl_from_IVideoWindow(iface);
4410 IVideoWindow *pVideoWindow;
4411 HRESULT hr;
4413 TRACE("graph %p, drain %#Ix.\n", This, Drain);
4415 EnterCriticalSection(&This->cs);
4417 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4419 if (hr == S_OK)
4420 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4422 LeaveCriticalSection(&This->cs);
4424 return hr;
4427 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4429 struct filter_graph *This = impl_from_IVideoWindow(iface);
4430 IVideoWindow *pVideoWindow;
4431 HRESULT hr;
4433 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4435 EnterCriticalSection(&This->cs);
4437 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4439 if (hr == S_OK)
4440 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4442 LeaveCriticalSection(&This->cs);
4444 return hr;
4447 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4449 struct filter_graph *This = impl_from_IVideoWindow(iface);
4450 IVideoWindow *pVideoWindow;
4451 HRESULT hr;
4453 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4455 EnterCriticalSection(&This->cs);
4457 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4459 if (hr == S_OK)
4460 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4462 LeaveCriticalSection(&This->cs);
4464 return hr;
4467 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4469 struct filter_graph *This = impl_from_IVideoWindow(iface);
4470 IVideoWindow *pVideoWindow;
4471 HRESULT hr;
4473 TRACE("graph %p, colour %#lx.\n", This, Color);
4475 EnterCriticalSection(&This->cs);
4477 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4479 if (hr == S_OK)
4480 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4482 LeaveCriticalSection(&This->cs);
4484 return hr;
4487 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4489 struct filter_graph *This = impl_from_IVideoWindow(iface);
4490 IVideoWindow *pVideoWindow;
4491 HRESULT hr;
4493 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4495 EnterCriticalSection(&This->cs);
4497 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4499 if (hr == S_OK)
4500 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4502 LeaveCriticalSection(&This->cs);
4504 return hr;
4507 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4509 struct filter_graph *This = impl_from_IVideoWindow(iface);
4510 IVideoWindow *pVideoWindow;
4511 HRESULT hr;
4513 TRACE("graph %p, fullscreen %ld.\n", This, FullScreenMode);
4515 EnterCriticalSection(&This->cs);
4517 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4519 if (hr == S_OK)
4520 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4522 LeaveCriticalSection(&This->cs);
4524 return hr;
4527 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4529 struct filter_graph *This = impl_from_IVideoWindow(iface);
4530 IVideoWindow *pVideoWindow;
4531 HRESULT hr;
4533 TRACE("graph %p, focus %ld.\n", This, Focus);
4535 EnterCriticalSection(&This->cs);
4537 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4539 if (hr == S_OK)
4540 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4542 LeaveCriticalSection(&This->cs);
4544 return hr;
4547 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4548 LONG_PTR wParam, LONG_PTR lParam)
4550 struct filter_graph *This = impl_from_IVideoWindow(iface);
4551 IVideoWindow *pVideoWindow;
4552 HRESULT hr;
4554 TRACE("graph %p, hwnd %#Ix, message %#lx, wparam %#Ix, lparam %#Ix.\n", This, hwnd, uMsg, wParam, lParam);
4556 EnterCriticalSection(&This->cs);
4558 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4560 if (hr == S_OK)
4561 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4563 LeaveCriticalSection(&This->cs);
4565 return hr;
4568 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4569 LONG Width, LONG Height)
4571 struct filter_graph *This = impl_from_IVideoWindow(iface);
4572 IVideoWindow *pVideoWindow;
4573 HRESULT hr;
4575 TRACE("graph %p, left %ld, top %ld, width %ld, height %ld.\n", This, Left, Top, Width, Height);
4577 EnterCriticalSection(&This->cs);
4579 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4581 if (hr == S_OK)
4582 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4584 LeaveCriticalSection(&This->cs);
4586 return hr;
4589 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4590 LONG *pWidth, LONG *pHeight)
4592 struct filter_graph *This = impl_from_IVideoWindow(iface);
4593 IVideoWindow *pVideoWindow;
4594 HRESULT hr;
4596 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4598 EnterCriticalSection(&This->cs);
4600 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4602 if (hr == S_OK)
4603 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4605 LeaveCriticalSection(&This->cs);
4607 return hr;
4610 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4611 LONG *pHeight)
4613 struct filter_graph *This = impl_from_IVideoWindow(iface);
4614 IVideoWindow *pVideoWindow;
4615 HRESULT hr;
4617 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4619 EnterCriticalSection(&This->cs);
4621 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4623 if (hr == S_OK)
4624 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4626 LeaveCriticalSection(&This->cs);
4628 return hr;
4631 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4632 LONG *pHeight)
4634 struct filter_graph *This = impl_from_IVideoWindow(iface);
4635 IVideoWindow *pVideoWindow;
4636 HRESULT hr;
4638 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4640 EnterCriticalSection(&This->cs);
4642 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4644 if (hr == S_OK)
4645 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4647 LeaveCriticalSection(&This->cs);
4649 return hr;
4652 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4653 LONG *pWidth, LONG *pHeight)
4655 struct filter_graph *This = impl_from_IVideoWindow(iface);
4656 IVideoWindow *pVideoWindow;
4657 HRESULT hr;
4659 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4661 EnterCriticalSection(&This->cs);
4663 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4665 if (hr == S_OK)
4666 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4668 LeaveCriticalSection(&This->cs);
4670 return hr;
4673 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4675 struct filter_graph *This = impl_from_IVideoWindow(iface);
4676 IVideoWindow *pVideoWindow;
4677 HRESULT hr;
4679 TRACE("graph %p, hide %ld.\n", This, HideCursor);
4681 EnterCriticalSection(&This->cs);
4683 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4685 if (hr == S_OK)
4686 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4688 LeaveCriticalSection(&This->cs);
4690 return hr;
4693 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4695 struct filter_graph *This = impl_from_IVideoWindow(iface);
4696 IVideoWindow *pVideoWindow;
4697 HRESULT hr;
4699 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4701 EnterCriticalSection(&This->cs);
4703 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4705 if (hr == S_OK)
4706 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4708 LeaveCriticalSection(&This->cs);
4710 return hr;
4714 static const IVideoWindowVtbl IVideoWindow_VTable =
4716 VideoWindow_QueryInterface,
4717 VideoWindow_AddRef,
4718 VideoWindow_Release,
4719 VideoWindow_GetTypeInfoCount,
4720 VideoWindow_GetTypeInfo,
4721 VideoWindow_GetIDsOfNames,
4722 VideoWindow_Invoke,
4723 VideoWindow_put_Caption,
4724 VideoWindow_get_Caption,
4725 VideoWindow_put_WindowStyle,
4726 VideoWindow_get_WindowStyle,
4727 VideoWindow_put_WindowStyleEx,
4728 VideoWindow_get_WindowStyleEx,
4729 VideoWindow_put_AutoShow,
4730 VideoWindow_get_AutoShow,
4731 VideoWindow_put_WindowState,
4732 VideoWindow_get_WindowState,
4733 VideoWindow_put_BackgroundPalette,
4734 VideoWindow_get_BackgroundPalette,
4735 VideoWindow_put_Visible,
4736 VideoWindow_get_Visible,
4737 VideoWindow_put_Left,
4738 VideoWindow_get_Left,
4739 VideoWindow_put_Width,
4740 VideoWindow_get_Width,
4741 VideoWindow_put_Top,
4742 VideoWindow_get_Top,
4743 VideoWindow_put_Height,
4744 VideoWindow_get_Height,
4745 VideoWindow_put_Owner,
4746 VideoWindow_get_Owner,
4747 VideoWindow_put_MessageDrain,
4748 VideoWindow_get_MessageDrain,
4749 VideoWindow_get_BorderColor,
4750 VideoWindow_put_BorderColor,
4751 VideoWindow_get_FullScreenMode,
4752 VideoWindow_put_FullScreenMode,
4753 VideoWindow_SetWindowForeground,
4754 VideoWindow_NotifyOwnerMessage,
4755 VideoWindow_SetWindowPosition,
4756 VideoWindow_GetWindowPosition,
4757 VideoWindow_GetMinIdealImageSize,
4758 VideoWindow_GetMaxIdealImageSize,
4759 VideoWindow_GetRestorePosition,
4760 VideoWindow_HideCursor,
4761 VideoWindow_IsCursorHidden
4764 static struct filter_graph *impl_from_IMediaEventEx(IMediaEventEx *iface)
4766 return CONTAINING_RECORD(iface, struct filter_graph, IMediaEventEx_iface);
4769 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID iid, void **out)
4771 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4772 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
4775 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
4777 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4778 return IUnknown_AddRef(graph->outer_unk);
4781 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
4783 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4784 return IUnknown_Release(graph->outer_unk);
4787 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *count)
4789 TRACE("iface %p, count %p.\n", iface, count);
4790 *count = 1;
4791 return S_OK;
4794 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT index,
4795 LCID lcid, ITypeInfo **typeinfo)
4797 TRACE("iface %p, index %u, lcid %#lx, typeinfo %p.\n", iface, index, lcid, typeinfo);
4798 return strmbase_get_typeinfo(IMediaEvent_tid, typeinfo);
4801 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID iid,
4802 LPOLESTR *names, UINT count, LCID lcid, DISPID *ids)
4804 ITypeInfo *typeinfo;
4805 HRESULT hr;
4807 TRACE("iface %p, iid %s, names %p, count %u, lcid %#lx, ids %p.\n",
4808 iface, debugstr_guid(iid), names, count, lcid, ids);
4810 if (SUCCEEDED(hr = strmbase_get_typeinfo(IMediaEvent_tid, &typeinfo)))
4812 hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, ids);
4813 ITypeInfo_Release(typeinfo);
4815 return hr;
4818 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID id, REFIID iid, LCID lcid,
4819 WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *error_arg)
4821 ITypeInfo *typeinfo;
4822 HRESULT hr;
4824 TRACE("iface %p, id %ld, iid %s, lcid %#lx, flags %#x, params %p, result %p, excepinfo %p, error_arg %p.\n",
4825 iface, id, debugstr_guid(iid), lcid, flags, params, result, excepinfo, error_arg);
4827 if (SUCCEEDED(hr = strmbase_get_typeinfo(IMediaEvent_tid, &typeinfo)))
4829 hr = ITypeInfo_Invoke(typeinfo, iface, id, flags, params, result, excepinfo, error_arg);
4830 ITypeInfo_Release(typeinfo);
4832 return hr;
4835 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *event)
4837 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4839 TRACE("graph %p, event %p.\n", graph, event);
4841 *event = (OAEVENT)graph->media_event_handle;
4842 return S_OK;
4845 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *code,
4846 LONG_PTR *param1, LONG_PTR *param2, LONG timeout)
4848 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4849 struct media_event *event;
4850 struct list *entry;
4852 TRACE("graph %p, code %p, param1 %p, param2 %p, timeout %ld.\n", graph, code, param1, param2, timeout);
4854 *code = 0;
4856 if (WaitForSingleObject(graph->media_event_handle, timeout))
4857 return E_ABORT;
4859 EnterCriticalSection(&graph->event_cs);
4861 if (!(entry = list_head(&graph->media_events)))
4863 ResetEvent(graph->media_event_handle);
4864 LeaveCriticalSection(&graph->event_cs);
4865 return E_ABORT;
4867 event = LIST_ENTRY(entry, struct media_event, entry);
4868 list_remove(&event->entry);
4869 *code = event->code;
4870 *param1 = event->param1;
4871 *param2 = event->param2;
4872 free(event);
4874 LeaveCriticalSection(&graph->event_cs);
4875 return S_OK;
4878 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
4879 LONG *pEvCode)
4881 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4883 TRACE("graph %p, timeout %ld, code %p.\n", This, msTimeout, pEvCode);
4885 if (This->state != State_Running)
4886 return VFW_E_WRONG_STATE;
4888 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
4890 *pEvCode = This->CompletionStatus;
4891 return S_OK;
4894 *pEvCode = 0;
4895 return E_ABORT;
4898 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
4900 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4902 TRACE("graph %p, code %#lx.\n", This, lEvCode);
4904 if (lEvCode == EC_COMPLETE)
4905 This->HandleEcComplete = FALSE;
4906 else if (lEvCode == EC_REPAINT)
4907 This->HandleEcRepaint = FALSE;
4908 else if (lEvCode == EC_CLOCK_CHANGED)
4909 This->HandleEcClockChanged = FALSE;
4910 else
4911 return S_FALSE;
4913 return S_OK;
4916 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
4918 struct filter_graph *This = impl_from_IMediaEventEx(iface);
4920 TRACE("graph %p, code %#lx.\n", This, lEvCode);
4922 if (lEvCode == EC_COMPLETE)
4923 This->HandleEcComplete = TRUE;
4924 else if (lEvCode == EC_REPAINT)
4925 This->HandleEcRepaint = TRUE;
4926 else if (lEvCode == EC_CLOCK_CHANGED)
4927 This->HandleEcClockChanged = TRUE;
4928 else
4929 return S_FALSE;
4931 return S_OK;
4934 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG code,
4935 LONG_PTR param1, LONG_PTR param2)
4937 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4939 WARN("graph %p, code %#lx, param1 %Id, param2 %Id, stub!\n", graph, code, param1, param2);
4941 return S_OK;
4944 /*** IMediaEventEx methods ***/
4945 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface,
4946 OAHWND window, LONG message, LONG_PTR lparam)
4948 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4950 TRACE("graph %p, window %#Ix, message %#lx, lparam %#Ix.\n", graph, window, message, lparam);
4952 graph->media_event_window = (HWND)window;
4953 graph->media_event_message = message;
4954 graph->media_event_lparam = lparam;
4956 return S_OK;
4959 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG flags)
4961 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4963 TRACE("graph %p, flags %#lx.\n", graph, flags);
4965 if (flags & ~AM_MEDIAEVENT_NONOTIFY)
4967 WARN("Invalid flags %#lx, returning E_INVALIDARG.\n", flags);
4968 return E_INVALIDARG;
4971 graph->media_events_disabled = flags;
4973 if (flags)
4975 flush_media_events(graph);
4976 ResetEvent(graph->media_event_handle);
4979 return S_OK;
4982 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *flags)
4984 struct filter_graph *graph = impl_from_IMediaEventEx(iface);
4986 TRACE("graph %p, flags %p.\n", graph, flags);
4988 if (!flags)
4989 return E_POINTER;
4991 *flags = graph->media_events_disabled;
4993 return S_OK;
4997 static const IMediaEventExVtbl IMediaEventEx_VTable =
4999 MediaEvent_QueryInterface,
5000 MediaEvent_AddRef,
5001 MediaEvent_Release,
5002 MediaEvent_GetTypeInfoCount,
5003 MediaEvent_GetTypeInfo,
5004 MediaEvent_GetIDsOfNames,
5005 MediaEvent_Invoke,
5006 MediaEvent_GetEventHandle,
5007 MediaEvent_GetEvent,
5008 MediaEvent_WaitForCompletion,
5009 MediaEvent_CancelDefaultHandling,
5010 MediaEvent_RestoreDefaultHandling,
5011 MediaEvent_FreeEventParams,
5012 MediaEvent_SetNotifyWindow,
5013 MediaEvent_SetNotifyFlags,
5014 MediaEvent_GetNotifyFlags
5018 static struct filter_graph *impl_from_IMediaFilter(IMediaFilter *iface)
5020 return CONTAINING_RECORD(iface, struct filter_graph, IMediaFilter_iface);
5023 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID iid, void **out)
5025 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5027 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5030 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
5032 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5034 return IUnknown_AddRef(graph->outer_unk);
5037 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
5039 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5041 return IUnknown_Release(graph->outer_unk);
5044 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
5046 FIXME("(%p): stub\n", pClassID);
5048 return E_NOTIMPL;
5051 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
5053 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5054 HRESULT hr = S_OK, filter_hr;
5055 struct filter *filter;
5056 TP_WORK *work;
5058 TRACE("graph %p.\n", graph);
5060 EnterCriticalSection(&graph->cs);
5062 if (graph->state == State_Stopped)
5064 LeaveCriticalSection(&graph->cs);
5065 return S_OK;
5068 sort_filters(graph);
5070 if (graph->state == State_Running)
5072 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5074 filter_hr = IBaseFilter_Pause(filter->filter);
5075 if (hr == S_OK)
5076 hr = filter_hr;
5080 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5082 filter_hr = IBaseFilter_Stop(filter->filter);
5083 if (hr == S_OK)
5084 hr = filter_hr;
5087 graph->state = State_Stopped;
5088 graph->needs_async_run = 0;
5089 work = graph->async_run_work;
5090 graph->got_ec_complete = 0;
5092 /* Update the current position, probably to synchronize multiple streams. */
5093 IMediaSeeking_SetPositions(&graph->IMediaSeeking_iface, &graph->current_pos,
5094 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
5096 LeaveCriticalSection(&graph->cs);
5098 if (work)
5099 WaitForThreadpoolWorkCallbacks(work, TRUE);
5101 return hr;
5104 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5106 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5107 HRESULT hr = S_OK, filter_hr;
5108 struct filter *filter;
5109 TP_WORK *work;
5111 TRACE("graph %p.\n", graph);
5113 EnterCriticalSection(&graph->cs);
5115 if (graph->state == State_Paused)
5117 LeaveCriticalSection(&graph->cs);
5118 return S_OK;
5121 sort_filters(graph);
5123 EnterCriticalSection(&graph->event_cs);
5124 update_render_count(graph);
5125 LeaveCriticalSection(&graph->event_cs);
5127 if (graph->defaultclock && !graph->refClock)
5128 IFilterGraph2_SetDefaultSyncSource(&graph->IFilterGraph2_iface);
5130 if (graph->state == State_Running && !graph->needs_async_run && graph->refClock)
5132 REFERENCE_TIME time;
5133 IReferenceClock_GetTime(graph->refClock, &time);
5134 graph->stream_elapsed += time - graph->stream_start;
5135 graph->current_pos += graph->stream_elapsed;
5138 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5140 filter_hr = IBaseFilter_Pause(filter->filter);
5141 if (hr == S_OK)
5142 hr = filter_hr;
5145 graph->state = State_Paused;
5146 graph->needs_async_run = 0;
5147 work = graph->async_run_work;
5149 LeaveCriticalSection(&graph->cs);
5151 if (work)
5152 WaitForThreadpoolWorkCallbacks(work, TRUE);
5154 return hr;
5157 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME start)
5159 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5160 HRESULT hr;
5162 TRACE("graph %p, start %s.\n", graph, debugstr_time(start));
5164 EnterCriticalSection(&graph->cs);
5166 if (graph->state == State_Running)
5168 LeaveCriticalSection(&graph->cs);
5169 return S_OK;
5172 sort_filters(graph);
5174 hr = graph_start(graph, start);
5176 graph->state = State_Running;
5177 graph->needs_async_run = 0;
5179 LeaveCriticalSection(&graph->cs);
5180 return hr;
5183 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD timeout, FILTER_STATE *state)
5185 struct filter_graph *graph = impl_from_IMediaFilter(iface);
5186 DWORD end = GetTickCount() + timeout;
5187 HRESULT hr;
5189 TRACE("graph %p, timeout %lu, state %p.\n", graph, timeout, state);
5191 if (!state)
5192 return E_POINTER;
5194 /* Thread safety is a little tricky here. GetState() shouldn't block other
5195 * functions from being called on the filter graph. However, we can't just
5196 * call IBaseFilter::GetState() in one loop and drop the lock on every
5197 * iteration, since the filter list might change beneath us. So instead we
5198 * do what native does, and poll for it every 10 ms. */
5200 EnterCriticalSection(&graph->cs);
5201 *state = graph->state;
5203 for (;;)
5205 IBaseFilter *async_filter = NULL;
5206 FILTER_STATE filter_state;
5207 struct filter *filter;
5209 hr = S_OK;
5211 LIST_FOR_EACH_ENTRY(filter, &graph->filters, struct filter, entry)
5213 HRESULT filter_hr = IBaseFilter_GetState(filter->filter, 0, &filter_state);
5215 TRACE("Filter %p returned hr %#lx, state %u.\n", filter->filter, filter_hr, filter_state);
5217 if (filter_hr == VFW_S_STATE_INTERMEDIATE)
5218 async_filter = filter->filter;
5220 if (hr == S_OK && filter_hr == VFW_S_STATE_INTERMEDIATE)
5221 hr = VFW_S_STATE_INTERMEDIATE;
5222 else if (filter_hr != S_OK && filter_hr != VFW_S_STATE_INTERMEDIATE)
5223 hr = filter_hr;
5225 if (hr == S_OK && filter_state == State_Paused && graph->state != State_Paused)
5227 async_filter = filter->filter;
5228 hr = VFW_S_STATE_INTERMEDIATE;
5230 else if (filter_state != graph->state && filter_state != State_Paused)
5231 hr = E_FAIL;
5233 if (graph->needs_async_run)
5235 if (filter_state != State_Paused && filter_state != State_Running)
5236 ERR("Filter %p reported incorrect state %u (expected %u or %u).\n",
5237 filter->filter, filter_state, State_Paused, State_Running);
5239 else
5241 if (filter_state != graph->state)
5242 ERR("Filter %p reported incorrect state %u (expected %u).\n",
5243 filter->filter, filter_state, graph->state);
5247 LeaveCriticalSection(&graph->cs);
5249 if (hr != VFW_S_STATE_INTERMEDIATE || (timeout != INFINITE && GetTickCount() >= end))
5250 break;
5252 IBaseFilter_GetState(async_filter, 10, &filter_state);
5254 EnterCriticalSection(&graph->cs);
5257 TRACE("Returning %#lx, state %u.\n", hr, *state);
5258 return hr;
5261 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5263 struct filter_graph *This = impl_from_IMediaFilter(iface);
5264 struct filter *filter;
5265 HRESULT hr = S_OK;
5267 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
5269 EnterCriticalSection(&This->cs);
5271 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
5273 hr = IBaseFilter_SetSyncSource(filter->filter, pClock);
5274 if (FAILED(hr))
5275 break;
5278 if (FAILED(hr))
5280 LIST_FOR_EACH_ENTRY(filter, &This->filters, struct filter, entry)
5281 IBaseFilter_SetSyncSource(filter->filter, This->refClock);
5283 else
5285 if (This->refClock)
5286 IReferenceClock_Release(This->refClock);
5287 This->refClock = pClock;
5288 if (This->refClock)
5289 IReferenceClock_AddRef(This->refClock);
5290 This->defaultclock = FALSE;
5292 if (This->HandleEcClockChanged)
5294 IMediaEventSink *pEventSink;
5295 HRESULT eshr;
5297 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (void **)&pEventSink);
5298 if (SUCCEEDED(eshr))
5300 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5301 IMediaEventSink_Release(pEventSink);
5306 LeaveCriticalSection(&This->cs);
5308 return hr;
5311 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5313 struct filter_graph *This = impl_from_IMediaFilter(iface);
5315 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
5317 if (!ppClock)
5318 return E_POINTER;
5320 EnterCriticalSection(&This->cs);
5322 *ppClock = This->refClock;
5323 if (*ppClock)
5324 IReferenceClock_AddRef(*ppClock);
5326 LeaveCriticalSection(&This->cs);
5328 return S_OK;
5331 static const IMediaFilterVtbl IMediaFilter_VTable =
5333 MediaFilter_QueryInterface,
5334 MediaFilter_AddRef,
5335 MediaFilter_Release,
5336 MediaFilter_GetClassID,
5337 MediaFilter_Stop,
5338 MediaFilter_Pause,
5339 MediaFilter_Run,
5340 MediaFilter_GetState,
5341 MediaFilter_SetSyncSource,
5342 MediaFilter_GetSyncSource
5345 static struct filter_graph *impl_from_IMediaEventSink(IMediaEventSink *iface)
5347 return CONTAINING_RECORD(iface, struct filter_graph, IMediaEventSink_iface);
5350 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID iid, void **out)
5352 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5354 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5357 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5359 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5361 return IUnknown_AddRef(graph->outer_unk);
5364 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5366 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5368 return IUnknown_Release(graph->outer_unk);
5371 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG code,
5372 LONG_PTR param1, LONG_PTR param2)
5374 struct filter_graph *graph = impl_from_IMediaEventSink(iface);
5376 TRACE("graph %p, code %#lx, param1 %#Ix, param2 %#Ix.\n", graph, code, param1, param2);
5378 EnterCriticalSection(&graph->event_cs);
5380 if (code == EC_COMPLETE && graph->HandleEcComplete)
5382 if (++graph->EcCompleteCount == graph->nRenderers)
5384 if (graph->media_events_disabled)
5385 SetEvent(graph->media_event_handle);
5386 else
5387 queue_media_event(graph, EC_COMPLETE, S_OK, 0);
5388 graph->CompletionStatus = EC_COMPLETE;
5389 graph->got_ec_complete = 1;
5390 SetEvent(graph->hEventCompletion);
5393 else if ((code == EC_REPAINT) && graph->HandleEcRepaint)
5395 FIXME("EC_REPAINT is not handled.\n");
5397 else if (!graph->media_events_disabled)
5399 queue_media_event(graph, code, param1, param2);
5402 LeaveCriticalSection(&graph->event_cs);
5403 return S_OK;
5406 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5408 MediaEventSink_QueryInterface,
5409 MediaEventSink_AddRef,
5410 MediaEventSink_Release,
5411 MediaEventSink_Notify
5414 static struct filter_graph *impl_from_IGraphConfig(IGraphConfig *iface)
5416 return CONTAINING_RECORD(iface, struct filter_graph, IGraphConfig_iface);
5419 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID iid, void **out)
5421 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5423 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5426 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5428 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5430 return IUnknown_AddRef(graph->outer_unk);
5433 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5435 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5437 return IUnknown_Release(graph->outer_unk);
5440 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *source, IPin *sink,
5441 const AM_MEDIA_TYPE *mt, IBaseFilter *filter, HANDLE abort_event, DWORD flags)
5443 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5445 FIXME("graph %p, source %p, sink %p, mt %p, filter %p, abort_event %p, flags %#lx, stub!\n",
5446 graph, source, sink, mt, filter, abort_event, flags);
5447 strmbase_dump_media_type(mt);
5449 return E_NOTIMPL;
5452 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface,
5453 IGraphConfigCallback *callback, void *context, DWORD flags, HANDLE abort_event)
5455 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5456 HRESULT hr;
5458 TRACE("graph %p, callback %p, context %p, flags %#lx, abort_event %p.\n",
5459 graph, callback, context, flags, abort_event);
5461 if (abort_event)
5462 FIXME("The parameter hAbortEvent is not handled!\n");
5464 EnterCriticalSection(&graph->cs);
5466 hr = IGraphConfigCallback_Reconfigure(callback, context, flags);
5468 LeaveCriticalSection(&graph->cs);
5470 return hr;
5473 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5475 struct filter_graph *This = impl_from_IGraphConfig(iface);
5477 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5479 return E_NOTIMPL;
5482 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5484 struct filter_graph *This = impl_from_IGraphConfig(iface);
5486 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5488 return E_NOTIMPL;
5491 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5493 struct filter_graph *This = impl_from_IGraphConfig(iface);
5495 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5497 return E_NOTIMPL;
5500 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5502 struct filter_graph *This = impl_from_IGraphConfig(iface);
5504 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5506 return E_NOTIMPL;
5509 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5510 IPinConnection *pConnection, HANDLE hEventAbort)
5512 struct filter_graph *This = impl_from_IGraphConfig(iface);
5514 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5516 return E_NOTIMPL;
5519 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *filter, DWORD flags)
5521 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5523 FIXME("graph %p, filter %p, flags %#lx, stub!\n", graph, filter, flags);
5525 return E_NOTIMPL;
5528 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5529 DWORD *dwFlags)
5531 struct filter_graph *This = impl_from_IGraphConfig(iface);
5533 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5535 return E_NOTIMPL;
5538 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *filter, DWORD flags)
5540 struct filter_graph *graph = impl_from_IGraphConfig(iface);
5542 FIXME("graph %p, filter %p, flags %#lx, stub!\n", graph, filter, flags);
5544 return E_NOTIMPL;
5547 static const IGraphConfigVtbl IGraphConfig_VTable =
5549 GraphConfig_QueryInterface,
5550 GraphConfig_AddRef,
5551 GraphConfig_Release,
5552 GraphConfig_Reconnect,
5553 GraphConfig_Reconfigure,
5554 GraphConfig_AddFilterToCache,
5555 GraphConfig_EnumCacheFilter,
5556 GraphConfig_RemoveFilterFromCache,
5557 GraphConfig_GetStartTime,
5558 GraphConfig_PushThroughData,
5559 GraphConfig_SetFilterFlags,
5560 GraphConfig_GetFilterFlags,
5561 GraphConfig_RemoveFilterEx
5564 static struct filter_graph *impl_from_IGraphVersion(IGraphVersion *iface)
5566 return CONTAINING_RECORD(iface, struct filter_graph, IGraphVersion_iface);
5569 static HRESULT WINAPI GraphVersion_QueryInterface(IGraphVersion *iface, REFIID iid, void **out)
5571 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5573 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5576 static ULONG WINAPI GraphVersion_AddRef(IGraphVersion *iface)
5578 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5580 return IUnknown_AddRef(graph->outer_unk);
5583 static ULONG WINAPI GraphVersion_Release(IGraphVersion *iface)
5585 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5587 return IUnknown_Release(graph->outer_unk);
5590 static HRESULT WINAPI GraphVersion_QueryVersion(IGraphVersion *iface, LONG *version)
5592 struct filter_graph *graph = impl_from_IGraphVersion(iface);
5594 TRACE("graph %p, version %p, returning %ld.\n", graph, version, graph->version);
5596 if (!version)
5597 return E_POINTER;
5599 *version = graph->version;
5600 return S_OK;
5603 static const IGraphVersionVtbl IGraphVersion_VTable =
5605 GraphVersion_QueryInterface,
5606 GraphVersion_AddRef,
5607 GraphVersion_Release,
5608 GraphVersion_QueryVersion,
5611 static struct filter_graph *impl_from_IVideoFrameStep(IVideoFrameStep *iface)
5613 return CONTAINING_RECORD(iface, struct filter_graph, IVideoFrameStep_iface);
5616 static HRESULT WINAPI VideoFrameStep_QueryInterface(IVideoFrameStep *iface, REFIID iid, void **out)
5618 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5619 return IUnknown_QueryInterface(graph->outer_unk, iid, out);
5622 static ULONG WINAPI VideoFrameStep_AddRef(IVideoFrameStep *iface)
5624 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5625 return IUnknown_AddRef(graph->outer_unk);
5628 static ULONG WINAPI VideoFrameStep_Release(IVideoFrameStep *iface)
5630 struct filter_graph *graph = impl_from_IVideoFrameStep(iface);
5631 return IUnknown_Release(graph->outer_unk);
5634 static HRESULT WINAPI VideoFrameStep_Step(IVideoFrameStep *iface, DWORD frame_count, IUnknown *filter)
5636 FIXME("iface %p, frame_count %lu, filter %p, stub!\n", iface, frame_count, filter);
5637 return E_NOTIMPL;
5640 static HRESULT WINAPI VideoFrameStep_CanStep(IVideoFrameStep *iface, LONG multiple, IUnknown *filter)
5642 FIXME("iface %p, multiple %ld, filter %p, stub!\n", iface, multiple, filter);
5643 return E_NOTIMPL;
5646 static HRESULT WINAPI VideoFrameStep_CancelStep(IVideoFrameStep *iface)
5648 FIXME("iface %p, stub!\n", iface);
5649 return E_NOTIMPL;
5652 static const IVideoFrameStepVtbl VideoFrameStep_vtbl =
5654 VideoFrameStep_QueryInterface,
5655 VideoFrameStep_AddRef,
5656 VideoFrameStep_Release,
5657 VideoFrameStep_Step,
5658 VideoFrameStep_CanStep,
5659 VideoFrameStep_CancelStep
5662 static const IUnknownVtbl IInner_VTable =
5664 FilterGraphInner_QueryInterface,
5665 FilterGraphInner_AddRef,
5666 FilterGraphInner_Release
5669 static HRESULT filter_graph_common_create(IUnknown *outer, IUnknown **out, BOOL threaded)
5671 struct filter_graph *object;
5672 HRESULT hr;
5674 *out = NULL;
5676 if (!(object = calloc(1, sizeof(*object))))
5677 return E_OUTOFMEMORY;
5679 object->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5680 object->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5681 object->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5682 object->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5683 object->IGraphVersion_iface.lpVtbl = &IGraphVersion_VTable;
5684 object->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5685 object->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5686 object->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5687 object->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5688 object->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5689 object->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5690 object->IObjectWithSite_iface.lpVtbl = &IObjectWithSite_VTable;
5691 object->IUnknown_inner.lpVtbl = &IInner_VTable;
5692 object->IVideoFrameStep_iface.lpVtbl = &VideoFrameStep_vtbl;
5693 object->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5694 object->ref = 1;
5695 object->outer_unk = outer ? outer : &object->IUnknown_inner;
5697 if (FAILED(hr = CoCreateInstance(&CLSID_FilterMapper2, object->outer_unk,
5698 CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&object->punkFilterMapper2)))
5700 ERR("Failed to create filter mapper, hr %#lx.\n", hr);
5701 free(object);
5702 return hr;
5705 InitializeCriticalSection(&object->cs);
5706 object->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": filter_graph.cs");
5707 InitializeCriticalSection(&object->event_cs);
5708 object->event_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": filter_graph.event_cs");
5710 object->defaultclock = TRUE;
5712 object->media_event_handle = CreateEventW(NULL, TRUE, FALSE, NULL);
5713 list_init(&object->media_events);
5714 list_init(&object->filters);
5715 object->HandleEcClockChanged = TRUE;
5716 object->HandleEcComplete = TRUE;
5717 object->HandleEcRepaint = TRUE;
5718 object->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5720 object->name_index = 1;
5721 object->timeformatseek = TIME_FORMAT_MEDIA_TIME;
5723 object->threaded = !!threaded;
5725 EnterCriticalSection(&message_cs);
5726 if (threaded && !message_thread_refcount++)
5728 message_thread_ret = CreateEventW(NULL, FALSE, FALSE, NULL);
5729 message_thread = CreateThread(NULL, 0, message_thread_run, object, 0, &message_thread_id);
5730 WaitForSingleObject(message_thread_ret, INFINITE);
5732 LeaveCriticalSection(&message_cs);
5734 TRACE("Created %sthreaded filter graph %p.\n", threaded ? "" : "non-", object);
5735 *out = &object->IUnknown_inner;
5736 return S_OK;
5739 HRESULT filter_graph_create(IUnknown *outer, IUnknown **out)
5741 return filter_graph_common_create(outer, out, TRUE);
5744 HRESULT filter_graph_no_thread_create(IUnknown *outer, IUnknown **out)
5746 return filter_graph_common_create(outer, out, FALSE);