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 "quartz_private.h"
24 HWND hWnd
; /* Target window */
25 UINT msg
; /* User window message */
26 LONG_PTR instance
; /* User data */
27 int disabled
; /* Disabled messages posting */
31 LONG lEventCode
; /* Event code */
32 LONG_PTR lParam1
; /* Param1 */
33 LONG_PTR lParam2
; /* Param2 */
36 /* messages ring implementation for queuing events (taken from winmm) */
37 #define EVENTS_RING_BUFFER_INCREMENT 64
43 CRITICAL_SECTION msg_crst
;
44 HANDLE msg_event
; /* Signaled for no empty queue */
47 static int EventsQueue_Init(EventsQueue
* omr
)
51 omr
->msg_event
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
52 omr
->ring_buffer_size
= EVENTS_RING_BUFFER_INCREMENT
;
53 omr
->messages
= CoTaskMemAlloc(omr
->ring_buffer_size
* sizeof(Event
));
54 ZeroMemory(omr
->messages
, omr
->ring_buffer_size
* sizeof(Event
));
56 InitializeCriticalSection(&omr
->msg_crst
);
57 omr
->msg_crst
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": EventsQueue.msg_crst");
61 static int EventsQueue_Destroy(EventsQueue
* omr
)
63 CloseHandle(omr
->msg_event
);
64 CoTaskMemFree(omr
->messages
);
65 omr
->msg_crst
.DebugInfo
->Spare
[0] = 0;
66 DeleteCriticalSection(&omr
->msg_crst
);
70 static BOOL
EventsQueue_PutEvent(EventsQueue
* omr
, const Event
* evt
)
72 EnterCriticalSection(&omr
->msg_crst
);
73 if (omr
->msg_toget
== ((omr
->msg_tosave
+ 1) % omr
->ring_buffer_size
))
75 int old_ring_buffer_size
= omr
->ring_buffer_size
;
76 omr
->ring_buffer_size
+= EVENTS_RING_BUFFER_INCREMENT
;
77 TRACE("omr->ring_buffer_size=%d\n",omr
->ring_buffer_size
);
78 omr
->messages
= CoTaskMemRealloc(omr
->messages
, omr
->ring_buffer_size
* sizeof(Event
));
79 /* Now we need to rearrange the ring buffer so that the new
80 buffers just allocated are in between omr->msg_tosave and
83 if (omr
->msg_tosave
< omr
->msg_toget
)
85 memmove(&(omr
->messages
[omr
->msg_toget
+ EVENTS_RING_BUFFER_INCREMENT
]),
86 &(omr
->messages
[omr
->msg_toget
]),
87 sizeof(Event
)*(old_ring_buffer_size
- omr
->msg_toget
)
89 omr
->msg_toget
+= EVENTS_RING_BUFFER_INCREMENT
;
92 omr
->messages
[omr
->msg_tosave
] = *evt
;
93 SetEvent(omr
->msg_event
);
94 omr
->msg_tosave
= (omr
->msg_tosave
+ 1) % omr
->ring_buffer_size
;
95 LeaveCriticalSection(&omr
->msg_crst
);
99 static BOOL
EventsQueue_GetEvent(EventsQueue
* omr
, Event
* evt
, LONG msTimeOut
)
101 if (WaitForSingleObject(omr
->msg_event
, msTimeOut
) != WAIT_OBJECT_0
)
104 EnterCriticalSection(&omr
->msg_crst
);
106 if (omr
->msg_toget
== omr
->msg_tosave
) /* buffer empty ? */
108 LeaveCriticalSection(&omr
->msg_crst
);
112 *evt
= omr
->messages
[omr
->msg_toget
];
113 omr
->msg_toget
= (omr
->msg_toget
+ 1) % omr
->ring_buffer_size
;
115 /* Mark the buffer as empty if needed */
116 if (omr
->msg_toget
== omr
->msg_tosave
) /* buffer empty ? */
117 ResetEvent(omr
->msg_event
);
119 LeaveCriticalSection(&omr
->msg_crst
);
123 #define MAX_ITF_CACHE_ENTRIES 3
124 typedef struct _ITF_CACHE_ENTRY
{
130 typedef struct _IFilterGraphImpl
{
131 IUnknown IUnknown_inner
;
132 IFilterGraph2 IFilterGraph2_iface
;
133 IMediaControl IMediaControl_iface
;
134 IMediaSeeking IMediaSeeking_iface
;
135 IBasicAudio IBasicAudio_iface
;
136 IBasicVideo2 IBasicVideo2_iface
;
137 IVideoWindow IVideoWindow_iface
;
138 IMediaEventEx IMediaEventEx_iface
;
139 IMediaFilter IMediaFilter_iface
;
140 IMediaEventSink IMediaEventSink_iface
;
141 IGraphConfig IGraphConfig_iface
;
142 IMediaPosition IMediaPosition_iface
;
143 IObjectWithSite IObjectWithSite_iface
;
144 IGraphVersion IGraphVersion_iface
;
145 /* IAMGraphStreams */
150 /* IRegisterServiceProvider */
151 /* IResourceMananger */
152 /* IServiceProvider */
153 /* IVideoFrameStep */
157 IUnknown
*punkFilterMapper2
;
158 IBaseFilter
** ppFiltersInGraph
;
159 LPWSTR
* pFilterNames
;
163 IReferenceClock
*refClock
;
164 IBaseFilter
*refClockProvider
;
166 HANDLE hEventCompletion
;
167 int CompletionStatus
;
171 int HandleEcComplete
;
173 int HandleEcClockChanged
;
176 ITF_CACHE_ENTRY ItfCacheEntries
[MAX_ITF_CACHE_ENTRIES
];
177 int nItfCacheEntries
;
180 REFERENCE_TIME start_time
;
181 REFERENCE_TIME pause_time
;
187 static inline IFilterGraphImpl
*impl_from_IUnknown(IUnknown
*iface
)
189 return CONTAINING_RECORD(iface
, IFilterGraphImpl
, IUnknown_inner
);
192 static HRESULT WINAPI
FilterGraphInner_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppvObj
)
194 IFilterGraphImpl
*This
= impl_from_IUnknown(iface
);
195 TRACE("(%p)->(%s (%p), %p)\n", This
, debugstr_guid(riid
), riid
, ppvObj
);
197 if (IsEqualGUID(&IID_IUnknown
, riid
)) {
198 *ppvObj
= &This
->IUnknown_inner
;
199 TRACE(" returning IUnknown interface (%p)\n", *ppvObj
);
200 } else if (IsEqualGUID(&IID_IFilterGraph
, riid
) ||
201 IsEqualGUID(&IID_IFilterGraph2
, riid
) ||
202 IsEqualGUID(&IID_IGraphBuilder
, riid
)) {
203 *ppvObj
= &This
->IFilterGraph2_iface
;
204 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj
);
205 } else if (IsEqualGUID(&IID_IMediaControl
, riid
)) {
206 *ppvObj
= &This
->IMediaControl_iface
;
207 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj
);
208 } else if (IsEqualGUID(&IID_IMediaSeeking
, riid
)) {
209 *ppvObj
= &This
->IMediaSeeking_iface
;
210 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj
);
211 } else if (IsEqualGUID(&IID_IBasicAudio
, riid
)) {
212 *ppvObj
= &This
->IBasicAudio_iface
;
213 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj
);
214 } else if (IsEqualGUID(&IID_IBasicVideo
, riid
) ||
215 IsEqualGUID(&IID_IBasicVideo2
, riid
)) {
216 *ppvObj
= &This
->IBasicVideo2_iface
;
217 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj
);
218 } else if (IsEqualGUID(&IID_IVideoWindow
, riid
)) {
219 *ppvObj
= &This
->IVideoWindow_iface
;
220 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj
);
221 } else if (IsEqualGUID(&IID_IMediaEvent
, riid
) ||
222 IsEqualGUID(&IID_IMediaEventEx
, riid
)) {
223 *ppvObj
= &This
->IMediaEventEx_iface
;
224 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj
);
225 } else if (IsEqualGUID(&IID_IMediaFilter
, riid
) ||
226 IsEqualGUID(&IID_IPersist
, riid
)) {
227 *ppvObj
= &This
->IMediaFilter_iface
;
228 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj
);
229 } else if (IsEqualGUID(&IID_IMediaEventSink
, riid
)) {
230 *ppvObj
= &This
->IMediaEventSink_iface
;
231 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj
);
232 } else if (IsEqualGUID(&IID_IGraphConfig
, riid
)) {
233 *ppvObj
= &This
->IGraphConfig_iface
;
234 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj
);
235 } else if (IsEqualGUID(&IID_IMediaPosition
, riid
)) {
236 *ppvObj
= &This
->IMediaPosition_iface
;
237 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj
);
238 } else if (IsEqualGUID(&IID_IObjectWithSite
, riid
)) {
239 *ppvObj
= &This
->IObjectWithSite_iface
;
240 TRACE(" returning IObjectWithSite interface (%p)\n", *ppvObj
);
241 } else if (IsEqualGUID(&IID_IFilterMapper
, riid
)) {
242 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj
);
243 return IUnknown_QueryInterface(This
->punkFilterMapper2
, riid
, ppvObj
);
244 } else if (IsEqualGUID(&IID_IFilterMapper2
, riid
)) {
245 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj
);
246 return IUnknown_QueryInterface(This
->punkFilterMapper2
, riid
, ppvObj
);
247 } else if (IsEqualGUID(&IID_IFilterMapper3
, riid
)) {
248 TRACE(" returning IFilterMapper3 interface from aggregated filtermapper (%p)\n", *ppvObj
);
249 return IUnknown_QueryInterface(This
->punkFilterMapper2
, riid
, ppvObj
);
250 } else if (IsEqualGUID(&IID_IGraphVersion
, riid
)) {
251 *ppvObj
= &This
->IGraphConfig_iface
;
252 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj
);
255 FIXME("unknown interface %s\n", debugstr_guid(riid
));
256 return E_NOINTERFACE
;
259 IUnknown_AddRef((IUnknown
*)*ppvObj
);
263 static ULONG WINAPI
FilterGraphInner_AddRef(IUnknown
*iface
)
265 IFilterGraphImpl
*This
= impl_from_IUnknown(iface
);
266 ULONG ref
= InterlockedIncrement(&This
->ref
);
268 TRACE("(%p)->(): new ref = %d\n", This
, ref
);
273 static ULONG WINAPI
FilterGraphInner_Release(IUnknown
*iface
)
275 IFilterGraphImpl
*This
= impl_from_IUnknown(iface
);
276 ULONG ref
= InterlockedDecrement(&This
->ref
);
278 TRACE("(%p)->(): new ref = %d\n", This
, ref
);
283 This
->ref
= 1; /* guard against reentrancy (aggregation). */
285 IMediaControl_Stop(&This
->IMediaControl_iface
);
287 while (This
->nFilters
)
288 IFilterGraph2_RemoveFilter(&This
->IFilterGraph2_iface
, This
->ppFiltersInGraph
[0]);
291 IReferenceClock_Release(This
->refClock
);
293 for (i
= 0; i
< This
->nItfCacheEntries
; i
++)
295 if (This
->ItfCacheEntries
[i
].iface
)
296 IUnknown_Release(This
->ItfCacheEntries
[i
].iface
);
299 IUnknown_Release(This
->punkFilterMapper2
);
301 if (This
->pSite
) IUnknown_Release(This
->pSite
);
303 CloseHandle(This
->hEventCompletion
);
304 EventsQueue_Destroy(&This
->evqueue
);
305 This
->cs
.DebugInfo
->Spare
[0] = 0;
306 DeleteCriticalSection(&This
->cs
);
307 CoTaskMemFree(This
->ppFiltersInGraph
);
308 CoTaskMemFree(This
->pFilterNames
);
314 static inline IFilterGraphImpl
*impl_from_IFilterGraph2(IFilterGraph2
*iface
)
316 return CONTAINING_RECORD(iface
, IFilterGraphImpl
, IFilterGraph2_iface
);
319 static HRESULT WINAPI
FilterGraph2_QueryInterface(IFilterGraph2
*iface
, REFIID riid
, void **ppvObj
)
321 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
323 TRACE("(%p/%p)->(%s (%p), %p)\n", This
, iface
, debugstr_guid(riid
), riid
, ppvObj
);
325 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppvObj
);
328 static ULONG WINAPI
FilterGraph2_AddRef(IFilterGraph2
*iface
)
330 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
332 TRACE("(%p/%p)->()\n", This
, iface
);
334 return IUnknown_AddRef(This
->outer_unk
);
337 static ULONG WINAPI
FilterGraph2_Release(IFilterGraph2
*iface
)
339 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
341 TRACE("(%p/%p)->()\n", This
, iface
);
343 return IUnknown_Release(This
->outer_unk
);
346 /*** IFilterGraph methods ***/
347 static HRESULT WINAPI
FilterGraph2_AddFilter(IFilterGraph2
*iface
, IBaseFilter
*pFilter
,
350 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
353 WCHAR
* wszFilterName
= NULL
;
354 BOOL duplicate_name
= FALSE
;
356 TRACE("(%p/%p)->(%p, %s (%p))\n", This
, iface
, pFilter
, debugstr_w(pName
), pName
);
361 wszFilterName
= CoTaskMemAlloc( (pName
? strlenW(pName
) + 6 : 5) * sizeof(WCHAR
) );
365 /* Check if name already exists */
366 for(i
= 0; i
< This
->nFilters
; i
++)
367 if (!strcmpW(This
->pFilterNames
[i
], pName
))
369 duplicate_name
= TRUE
;
374 /* If no name given or name already existing, generate one */
375 if (!pName
|| duplicate_name
)
377 static const WCHAR wszFmt1
[] = {'%','s',' ','%','0','4','d',0};
378 static const WCHAR wszFmt2
[] = {'%','0','4','d',0};
380 for (j
= 0; j
< 10000 ; j
++)
384 sprintfW(wszFilterName
, wszFmt1
, pName
, This
->nameIndex
);
386 sprintfW(wszFilterName
, wszFmt2
, This
->nameIndex
);
387 TRACE("Generated name %s\n", debugstr_w(wszFilterName
));
389 /* Check if the generated name already exists */
390 for(i
= 0; i
< This
->nFilters
; i
++)
391 if (!strcmpW(This
->pFilterNames
[i
], wszFilterName
))
394 /* Compute next index and exit if generated name is suitable */
395 if (This
->nameIndex
++ == 10000)
397 if (i
== This
->nFilters
)
400 /* Unable to find a suitable name */
403 CoTaskMemFree(wszFilterName
);
404 return VFW_E_DUPLICATE_NAME
;
408 memcpy(wszFilterName
, pName
, (strlenW(pName
) + 1) * sizeof(WCHAR
));
410 if (This
->nFilters
+ 1 > This
->filterCapacity
)
412 int newCapacity
= This
->filterCapacity
? 2 * This
->filterCapacity
: 1;
413 IBaseFilter
** ppNewFilters
= CoTaskMemAlloc(newCapacity
* sizeof(IBaseFilter
*));
414 LPWSTR
* pNewNames
= CoTaskMemAlloc(newCapacity
* sizeof(LPWSTR
));
415 memcpy(ppNewFilters
, This
->ppFiltersInGraph
, This
->nFilters
* sizeof(IBaseFilter
*));
416 memcpy(pNewNames
, This
->pFilterNames
, This
->nFilters
* sizeof(LPWSTR
));
417 if (This
->filterCapacity
)
419 CoTaskMemFree(This
->ppFiltersInGraph
);
420 CoTaskMemFree(This
->pFilterNames
);
422 This
->ppFiltersInGraph
= ppNewFilters
;
423 This
->pFilterNames
= pNewNames
;
424 This
->filterCapacity
= newCapacity
;
427 hr
= IBaseFilter_JoinFilterGraph(pFilter
, (IFilterGraph
*)&This
->IFilterGraph2_iface
, wszFilterName
);
431 IBaseFilter_AddRef(pFilter
);
432 This
->ppFiltersInGraph
[This
->nFilters
] = pFilter
;
433 This
->pFilterNames
[This
->nFilters
] = wszFilterName
;
436 IBaseFilter_SetSyncSource(pFilter
, This
->refClock
);
439 CoTaskMemFree(wszFilterName
);
441 if (SUCCEEDED(hr
) && duplicate_name
)
442 return VFW_S_DUPLICATE_NAME
;
447 static HRESULT WINAPI
FilterGraph2_RemoveFilter(IFilterGraph2
*iface
, IBaseFilter
*pFilter
)
449 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
453 TRACE("(%p/%p)->(%p)\n", This
, iface
, pFilter
);
455 /* FIXME: check graph is stopped */
457 for (i
= 0; i
< This
->nFilters
; i
++)
459 if (This
->ppFiltersInGraph
[i
] == pFilter
)
461 IEnumPins
*penumpins
= NULL
;
464 if (This
->defaultclock
&& This
->refClockProvider
== pFilter
)
466 IMediaFilter_SetSyncSource(&This
->IMediaFilter_iface
, NULL
);
467 This
->defaultclock
= TRUE
;
470 TRACE("Removing filter %s\n", debugstr_w(This
->pFilterNames
[i
]));
471 IBaseFilter_GetState(pFilter
, 0, &state
);
472 if (state
== State_Running
)
473 IBaseFilter_Pause(pFilter
);
474 if (state
!= State_Stopped
)
475 IBaseFilter_Stop(pFilter
);
477 hr
= IBaseFilter_EnumPins(pFilter
, &penumpins
);
480 while(IEnumPins_Next(penumpins
, 1, &ppin
, NULL
) == S_OK
)
484 IPin_ConnectedTo(ppin
, &victim
);
487 h
= IPin_Disconnect(victim
);
488 TRACE("Disconnect other side: %08x\n", h
);
489 if (h
== VFW_E_NOT_STOPPED
)
492 IPin_QueryPinInfo(victim
, &pinfo
);
494 IBaseFilter_GetState(pinfo
.pFilter
, 0, &state
);
495 if (state
== State_Running
)
496 IBaseFilter_Pause(pinfo
.pFilter
);
497 IBaseFilter_Stop(pinfo
.pFilter
);
498 IBaseFilter_Release(pinfo
.pFilter
);
499 h
= IPin_Disconnect(victim
);
500 TRACE("Disconnect retry: %08x\n", h
);
502 IPin_Release(victim
);
504 h
= IPin_Disconnect(ppin
);
505 TRACE("Disconnect 2: %08x\n", h
);
509 IEnumPins_Release(penumpins
);
512 hr
= IBaseFilter_JoinFilterGraph(pFilter
, NULL
, This
->pFilterNames
[i
]);
515 IBaseFilter_SetSyncSource(pFilter
, NULL
);
516 IBaseFilter_Release(pFilter
);
517 CoTaskMemFree(This
->pFilterNames
[i
]);
518 memmove(This
->ppFiltersInGraph
+i
, This
->ppFiltersInGraph
+i
+1, sizeof(IBaseFilter
*)*(This
->nFilters
- 1 - i
));
519 memmove(This
->pFilterNames
+i
, This
->pFilterNames
+i
+1, sizeof(LPWSTR
)*(This
->nFilters
- 1 - i
));
522 /* Invalidate interfaces in the cache */
523 for (i
= 0; i
< This
->nItfCacheEntries
; i
++)
524 if (pFilter
== This
->ItfCacheEntries
[i
].filter
)
526 IUnknown_Release(This
->ItfCacheEntries
[i
].iface
);
527 This
->ItfCacheEntries
[i
].iface
= NULL
;
528 This
->ItfCacheEntries
[i
].filter
= NULL
;
536 return hr
; /* FIXME: check this error code */
539 static HRESULT WINAPI
FilterGraph2_EnumFilters(IFilterGraph2
*iface
, IEnumFilters
**ppEnum
)
541 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
543 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
545 return IEnumFiltersImpl_Construct(&This
->IGraphVersion_iface
, &This
->ppFiltersInGraph
, &This
->nFilters
, ppEnum
);
548 static HRESULT WINAPI
FilterGraph2_FindFilterByName(IFilterGraph2
*iface
, LPCWSTR pName
,
549 IBaseFilter
**ppFilter
)
551 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
554 TRACE("(%p/%p)->(%s (%p), %p)\n", This
, iface
, debugstr_w(pName
), pName
, ppFilter
);
559 for (i
= 0; i
< This
->nFilters
; i
++)
561 if (!strcmpW(pName
, This
->pFilterNames
[i
]))
563 *ppFilter
= This
->ppFiltersInGraph
[i
];
564 IBaseFilter_AddRef(*ppFilter
);
570 return VFW_E_NOT_FOUND
;
573 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
574 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
576 static HRESULT
CheckCircularConnection(IFilterGraphImpl
*This
, IPin
*out
, IPin
*in
)
580 PIN_INFO info_out
, info_in
;
582 hr
= IPin_QueryPinInfo(out
, &info_out
);
585 if (info_out
.dir
!= PINDIR_OUTPUT
)
587 IBaseFilter_Release(info_out
.pFilter
);
588 return VFW_E_CANNOT_CONNECT
;
591 hr
= IPin_QueryPinInfo(in
, &info_in
);
593 IBaseFilter_Release(info_in
.pFilter
);
596 if (info_in
.dir
!= PINDIR_INPUT
)
598 hr
= VFW_E_CANNOT_CONNECT
;
602 if (info_out
.pFilter
== info_in
.pFilter
)
603 hr
= VFW_E_CIRCULAR_GRAPH
;
609 hr
= IBaseFilter_EnumPins(info_out
.pFilter
, &enumpins
);
613 IEnumPins_Reset(enumpins
);
614 while ((hr
= IEnumPins_Next(enumpins
, 1, &test
, NULL
)) == S_OK
)
616 PIN_DIRECTION dir
= PINDIR_OUTPUT
;
617 IPin_QueryDirection(test
, &dir
);
618 if (dir
== PINDIR_INPUT
)
621 IPin_ConnectedTo(test
, &victim
);
624 hr
= CheckCircularConnection(This
, victim
, in
);
625 IPin_Release(victim
);
635 IEnumPins_Release(enumpins
);
639 IBaseFilter_Release(info_out
.pFilter
);
641 ERR("Checking filtergraph returned %08x, something's not right!\n", hr
);
644 /* Debugging filtergraphs not enabled */
650 /* NOTE: despite the implication, it doesn't matter which
651 * way round you put in the input and output pins */
652 static HRESULT WINAPI
FilterGraph2_ConnectDirect(IFilterGraph2
*iface
, IPin
*ppinIn
, IPin
*ppinOut
,
653 const AM_MEDIA_TYPE
*pmt
)
655 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
659 TRACE("(%p/%p)->(%p, %p, %p)\n", This
, iface
, ppinIn
, ppinOut
, pmt
);
661 /* FIXME: check pins are in graph */
663 if (TRACE_ON(quartz
))
667 hr
= IPin_QueryPinInfo(ppinIn
, &PinInfo
);
671 TRACE("Filter owning first pin => %p\n", PinInfo
.pFilter
);
672 IBaseFilter_Release(PinInfo
.pFilter
);
674 hr
= IPin_QueryPinInfo(ppinOut
, &PinInfo
);
678 TRACE("Filter owning second pin => %p\n", PinInfo
.pFilter
);
679 IBaseFilter_Release(PinInfo
.pFilter
);
682 hr
= IPin_QueryDirection(ppinIn
, &dir
);
685 if (dir
== PINDIR_INPUT
)
687 hr
= CheckCircularConnection(This
, ppinOut
, ppinIn
);
689 hr
= IPin_Connect(ppinOut
, ppinIn
, pmt
);
693 hr
= CheckCircularConnection(This
, ppinIn
, ppinOut
);
695 hr
= IPin_Connect(ppinIn
, ppinOut
, pmt
);
702 static HRESULT WINAPI
FilterGraph2_Reconnect(IFilterGraph2
*iface
, IPin
*ppin
)
704 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
705 IPin
*pConnectedTo
= NULL
;
707 PIN_DIRECTION pindir
;
709 IPin_QueryDirection(ppin
, &pindir
);
710 hr
= IPin_ConnectedTo(ppin
, &pConnectedTo
);
712 TRACE("Querying connected to failed: %x\n", hr
);
715 IPin_Disconnect(ppin
);
716 IPin_Disconnect(pConnectedTo
);
717 if (pindir
== PINDIR_INPUT
)
718 hr
= IPin_Connect(pConnectedTo
, ppin
, NULL
);
720 hr
= IPin_Connect(ppin
, pConnectedTo
, NULL
);
721 IPin_Release(pConnectedTo
);
723 WARN("Reconnecting pins failed, pins are not connected now..\n");
724 TRACE("(%p->%p) -- %p %p -> %x\n", iface
, This
, ppin
, pConnectedTo
, hr
);
728 static HRESULT WINAPI
FilterGraph2_Disconnect(IFilterGraph2
*iface
, IPin
*ppin
)
730 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
732 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppin
);
737 return IPin_Disconnect(ppin
);
740 static HRESULT WINAPI
FilterGraph2_SetDefaultSyncSource(IFilterGraph2
*iface
)
742 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
743 IReferenceClock
*pClock
= NULL
;
747 TRACE("(%p/%p)->() live sources not handled properly!\n", iface
, This
);
749 EnterCriticalSection(&This
->cs
);
751 for (i
= 0; i
< This
->nFilters
; ++i
)
754 IAMFilterMiscFlags
*flags
= NULL
;
755 IBaseFilter_QueryInterface(This
->ppFiltersInGraph
[i
], &IID_IAMFilterMiscFlags
, (void**)&flags
);
758 miscflags
= IAMFilterMiscFlags_GetMiscFlags(flags
);
759 IAMFilterMiscFlags_Release(flags
);
760 if (miscflags
== AM_FILTER_MISC_FLAGS_IS_RENDERER
)
761 IBaseFilter_QueryInterface(This
->ppFiltersInGraph
[i
], &IID_IReferenceClock
, (void**)&pClock
);
768 hr
= CoCreateInstance(&CLSID_SystemClock
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IReferenceClock
, (LPVOID
*)&pClock
);
769 This
->refClockProvider
= NULL
;
772 This
->refClockProvider
= This
->ppFiltersInGraph
[i
];
776 hr
= IMediaFilter_SetSyncSource(&This
->IMediaFilter_iface
, pClock
);
777 This
->defaultclock
= TRUE
;
778 IReferenceClock_Release(pClock
);
780 LeaveCriticalSection(&This
->cs
);
785 static HRESULT
GetFilterInfo(IMoniker
* pMoniker
, VARIANT
* pvar
)
787 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
788 IPropertyBag
* pPropBagCat
= NULL
;
793 hr
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
796 hr
= IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, pvar
, NULL
);
799 TRACE("Moniker = %s\n", debugstr_w(V_BSTR(pvar
)));
802 IPropertyBag_Release(pPropBagCat
);
807 static HRESULT
GetInternalConnections(IBaseFilter
* pfilter
, IPin
* pinputpin
, IPin
*** pppins
, ULONG
* pnb
)
812 TRACE("(%p, %p, %p, %p)\n", pfilter
, pinputpin
, pppins
, pnb
);
813 hr
= IPin_QueryInternalConnections(pinputpin
, NULL
, &nb
);
816 } else if (hr
== S_FALSE
) {
817 *pppins
= CoTaskMemAlloc(sizeof(IPin
*)*nb
);
818 hr
= IPin_QueryInternalConnections(pinputpin
, *pppins
, &nb
);
820 WARN("Error (%x)\n", hr
);
822 } else if (hr
== E_NOTIMPL
) {
823 /* Input connected to all outputs */
824 IEnumPins
* penumpins
;
827 TRACE("E_NOTIMPL\n");
828 hr
= IBaseFilter_EnumPins(pfilter
, &penumpins
);
830 WARN("filter Enumpins failed (%x)\n", hr
);
834 /* Count output pins */
835 while(IEnumPins_Next(penumpins
, 1, &ppin
, &nb
) == S_OK
) {
836 PIN_DIRECTION pindir
;
837 IPin_QueryDirection(ppin
, &pindir
);
838 if (pindir
== PINDIR_OUTPUT
)
842 *pppins
= CoTaskMemAlloc(sizeof(IPin
*)*i
);
843 /* Retrieve output pins */
844 IEnumPins_Reset(penumpins
);
846 while(IEnumPins_Next(penumpins
, 1, &ppin
, &nb
) == S_OK
) {
847 PIN_DIRECTION pindir
;
848 IPin_QueryDirection(ppin
, &pindir
);
849 if (pindir
== PINDIR_OUTPUT
)
850 (*pppins
)[i
++] = ppin
;
854 IEnumPins_Release(penumpins
);
857 WARN("Next failed (%x)\n", hr
);
860 } else if (FAILED(hr
)) {
861 WARN("Cannot get internal connection (%x)\n", hr
);
869 /*** IGraphBuilder methods ***/
870 static HRESULT WINAPI
FilterGraph2_Connect(IFilterGraph2
*iface
, IPin
*ppinOut
, IPin
*ppinIn
)
872 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
874 AM_MEDIA_TYPE
* mt
= NULL
;
875 IEnumMediaTypes
* penummt
= NULL
;
877 IEnumPins
* penumpins
;
878 IEnumMoniker
* pEnumMoniker
;
887 IFilterMapper2
*pFilterMapper2
= NULL
;
889 TRACE("(%p/%p)->(%p, %p)\n", This
, iface
, ppinOut
, ppinIn
);
891 if(!ppinOut
|| !ppinIn
)
894 if (TRACE_ON(quartz
))
896 hr
= IPin_QueryPinInfo(ppinIn
, &PinInfo
);
900 TRACE("Filter owning first pin => %p\n", PinInfo
.pFilter
);
901 IBaseFilter_Release(PinInfo
.pFilter
);
903 hr
= IPin_QueryPinInfo(ppinOut
, &PinInfo
);
907 TRACE("Filter owning second pin => %p\n", PinInfo
.pFilter
);
908 IBaseFilter_Release(PinInfo
.pFilter
);
911 EnterCriticalSection(&This
->cs
);
912 ++This
->recursioncount
;
913 if (This
->recursioncount
>= 5)
915 WARN("Recursion count has reached %d\n", This
->recursioncount
);
916 hr
= VFW_E_CANNOT_CONNECT
;
920 hr
= IPin_QueryDirection(ppinOut
, &dir
);
924 if (dir
== PINDIR_INPUT
)
933 hr
= CheckCircularConnection(This
, ppinOut
, ppinIn
);
937 /* Try direct connection first */
938 hr
= IPin_Connect(ppinOut
, ppinIn
, NULL
);
942 TRACE("Direct connection failed, trying to render using extra filters\n");
944 hr
= IPin_QueryPinInfo(ppinIn
, &PinInfo
);
948 hr
= IBaseFilter_GetClassID(PinInfo
.pFilter
, &FilterCLSID
);
949 IBaseFilter_Release(PinInfo
.pFilter
);
953 /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream
954 * filter to the minor mediatype of input pin of the renderer */
955 hr
= IPin_EnumMediaTypes(ppinOut
, &penummt
);
958 WARN("EnumMediaTypes (%x)\n", hr
);
962 hr
= IEnumMediaTypes_Next(penummt
, 1, &mt
, &nbmt
);
964 WARN("IEnumMediaTypes_Next (%x)\n", hr
);
970 WARN("No media type found!\n");
971 hr
= VFW_E_INVALIDMEDIATYPE
;
974 TRACE("MajorType %s\n", debugstr_guid(&mt
->majortype
));
975 TRACE("SubType %s\n", debugstr_guid(&mt
->subtype
));
977 hr
= IUnknown_QueryInterface(This
->punkFilterMapper2
, &IID_IFilterMapper2
, (void**)&pFilterMapper2
);
979 WARN("Unable to get IFilterMapper2 (%x)\n", hr
);
983 /* Try to find a suitable filter that can connect to the pin to render */
984 tab
[0] = mt
->majortype
;
985 tab
[1] = mt
->subtype
;
986 hr
= IFilterMapper2_EnumMatchingFilters(pFilterMapper2
, &pEnumMoniker
, 0, FALSE
, MERIT_UNLIKELY
, TRUE
, 1, tab
, NULL
, NULL
, FALSE
, FALSE
, 0, NULL
, NULL
, NULL
);
988 WARN("Unable to enum filters (%x)\n", hr
);
992 hr
= VFW_E_CANNOT_RENDER
;
993 while(IEnumMoniker_Next(pEnumMoniker
, 1, &pMoniker
, &nb
) == S_OK
)
998 IPin
* ppinfilter
= NULL
;
999 IBaseFilter
* pfilter
= NULL
;
1000 IAMGraphBuilderCallback
*callback
= NULL
;
1002 hr
= GetFilterInfo(pMoniker
, &var
);
1004 WARN("Unable to retrieve filter info (%x)\n", hr
);
1008 hr
= IMoniker_BindToObject(pMoniker
, NULL
, NULL
, &IID_IBaseFilter
, (LPVOID
*)&pfilter
);
1009 IMoniker_Release(pMoniker
);
1011 WARN("Unable to create filter (%x), trying next one\n", hr
);
1015 hr
= IBaseFilter_GetClassID(pfilter
, &clsid
);
1018 IBaseFilter_Release(pfilter
);
1022 if (IsEqualGUID(&clsid
, &FilterCLSID
)) {
1023 /* Skip filter (same as the one the output pin belongs to) */
1024 IBaseFilter_Release(pfilter
);
1030 IUnknown_QueryInterface(This
->pSite
, &IID_IAMGraphBuilderCallback
, (LPVOID
*)&callback
);
1034 rc
= IAMGraphBuilderCallback_SelectedFilter(callback
, pMoniker
);
1037 TRACE("Filter rejected by IAMGraphBuilderCallback_SelectedFilter\n");
1038 IAMGraphBuilderCallback_Release(callback
);
1047 rc
= IAMGraphBuilderCallback_CreatedFilter(callback
, pfilter
);
1048 IAMGraphBuilderCallback_Release(callback
);
1051 IBaseFilter_Release(pfilter
);
1053 TRACE("Filter rejected by IAMGraphBuilderCallback_CreatedFilter\n");
1058 hr
= IFilterGraph2_AddFilter(iface
, pfilter
, V_BSTR(&var
));
1060 WARN("Unable to add filter (%x)\n", hr
);
1061 IBaseFilter_Release(pfilter
);
1068 hr
= IBaseFilter_EnumPins(pfilter
, &penumpins
);
1070 WARN("Enumpins (%x)\n", hr
);
1074 hr
= IEnumPins_Next(penumpins
, 1, &ppinfilter
, &pin
);
1075 IEnumPins_Release(penumpins
);
1078 WARN("Obtaining next pin: (%x)\n", hr
);
1082 WARN("Cannot use this filter: no pins\n");
1086 hr
= IPin_Connect(ppinOut
, ppinfilter
, NULL
);
1088 TRACE("Cannot connect to filter (%x), trying next one\n", hr
);
1091 TRACE("Successfully connected to filter, follow chain...\n");
1093 /* Render all output pins of the filter by calling IFilterGraph2_Connect on each of them */
1094 hr
= GetInternalConnections(pfilter
, ppinfilter
, &ppins
, &nb
);
1096 if (SUCCEEDED(hr
)) {
1098 IPin_Disconnect(ppinfilter
);
1099 IPin_Disconnect(ppinOut
);
1102 TRACE("pins to consider: %d\n", nb
);
1103 for(i
= 0; i
< nb
; i
++)
1105 LPWSTR pinname
= NULL
;
1107 TRACE("Processing pin %u\n", i
);
1109 hr
= IPin_QueryId(ppins
[i
], &pinname
);
1112 if (pinname
[0] == '~')
1114 TRACE("Pinname=%s, skipping\n", debugstr_w(pinname
));
1118 hr
= IFilterGraph2_Connect(iface
, ppins
[i
], ppinIn
);
1119 CoTaskMemFree(pinname
);
1123 TRACE("Cannot connect pin %p (%x)\n", ppinfilter
, hr
);
1125 IPin_Release(ppins
[i
]);
1126 if (SUCCEEDED(hr
)) break;
1128 while (++i
< nb
) IPin_Release(ppins
[i
]);
1129 CoTaskMemFree(ppins
);
1130 IPin_Release(ppinfilter
);
1131 IBaseFilter_Release(pfilter
);
1134 IPin_Disconnect(ppinfilter
);
1135 IPin_Disconnect(ppinOut
);
1136 IFilterGraph2_RemoveFilter(iface
, pfilter
);
1144 if (ppinfilter
) IPin_Release(ppinfilter
);
1146 IFilterGraph2_RemoveFilter(iface
, pfilter
);
1147 IBaseFilter_Release(pfilter
);
1149 while (++i
< nb
) IPin_Release(ppins
[i
]);
1150 CoTaskMemFree(ppins
);
1153 IEnumMoniker_Release(pEnumMoniker
);
1157 IFilterMapper2_Release(pFilterMapper2
);
1159 IEnumMediaTypes_Release(penummt
);
1161 DeleteMediaType(mt
);
1162 --This
->recursioncount
;
1163 LeaveCriticalSection(&This
->cs
);
1164 TRACE("--> %08x\n", hr
);
1165 return SUCCEEDED(hr
) ? S_OK
: hr
;
1168 static HRESULT
FilterGraph2_RenderRecurse(IFilterGraphImpl
*This
, IPin
*ppinOut
)
1170 /* This pin has been connected now, try to call render on all pins that aren't connected */
1173 IEnumPins
*enumpins
= NULL
;
1174 BOOL renderany
= FALSE
;
1175 BOOL renderall
= TRUE
;
1177 IPin_QueryPinInfo(ppinOut
, &info
);
1179 IBaseFilter_EnumPins(info
.pFilter
, &enumpins
);
1180 /* Don't need to hold a reference, IEnumPins does */
1181 IBaseFilter_Release(info
.pFilter
);
1183 IEnumPins_Reset(enumpins
);
1184 while (IEnumPins_Next(enumpins
, 1, &to
, NULL
) == S_OK
)
1186 PIN_DIRECTION dir
= PINDIR_INPUT
;
1188 IPin_QueryDirection(to
, &dir
);
1190 if (dir
== PINDIR_OUTPUT
)
1194 IPin_ConnectedTo(to
, &out
);
1198 hr
= IFilterGraph2_Render(&This
->IFilterGraph2_iface
, to
);
1211 IEnumPins_Release(enumpins
);
1217 return VFW_S_PARTIAL_RENDER
;
1219 return VFW_E_CANNOT_RENDER
;
1222 /* Ogg hates me if I create a direct rendering method
1224 * It can only connect to a pin properly once, so use a recursive method that does
1226 * +----+ --- (PIN 1) (Render is called on this pin)
1228 * +----+ --- (PIN 2)
1230 * Enumerate possible renderers that EXACTLY match the requested type
1232 * If none is available, try to add intermediate filters that can connect to the input pin
1233 * then call Render on that intermediate pin's output pins
1234 * if it succeeds: Render returns success, if it doesn't, the intermediate filter is removed,
1235 * and another filter that can connect to the input pin is tried
1236 * if we run out of filters that can, give up and return VFW_E_CANNOT_RENDER
1237 * It's recursive, but fun!
1240 static HRESULT WINAPI
FilterGraph2_Render(IFilterGraph2
*iface
, IPin
*ppinOut
)
1242 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
1243 IEnumMediaTypes
* penummt
;
1248 IEnumMoniker
* pEnumMoniker
;
1253 IFilterMapper2
*pFilterMapper2
= NULL
;
1255 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppinOut
);
1257 if (TRACE_ON(quartz
))
1261 hr
= IPin_QueryPinInfo(ppinOut
, &PinInfo
);
1265 TRACE("Filter owning pin => %p\n", PinInfo
.pFilter
);
1266 IBaseFilter_Release(PinInfo
.pFilter
);
1269 /* Try to find out if there is a renderer for the specified subtype already, and use that
1271 EnterCriticalSection(&This
->cs
);
1272 for (x
= 0; x
< This
->nFilters
; ++x
)
1274 IEnumPins
*enumpins
= NULL
;
1277 hr
= IBaseFilter_EnumPins(This
->ppFiltersInGraph
[x
], &enumpins
);
1279 if (FAILED(hr
) || !enumpins
)
1282 IEnumPins_Reset(enumpins
);
1283 while (IEnumPins_Next(enumpins
, 1, &pin
, NULL
) == S_OK
)
1286 PIN_DIRECTION dir
= PINDIR_OUTPUT
;
1288 IPin_QueryDirection(pin
, &dir
);
1289 if (dir
!= PINDIR_INPUT
)
1294 IPin_ConnectedTo(pin
, &to
);
1298 hr
= FilterGraph2_ConnectDirect(iface
, ppinOut
, pin
, NULL
);
1301 TRACE("Connected successfully %p/%p, %08x look if we should render more!\n", ppinOut
, pin
, hr
);
1304 hr
= FilterGraph2_RenderRecurse(This
, pin
);
1307 IPin_Disconnect(ppinOut
);
1308 IPin_Disconnect(pin
);
1311 IEnumPins_Release(enumpins
);
1312 LeaveCriticalSection(&This
->cs
);
1315 WARN("Could not connect!\n");
1322 IEnumPins_Release(enumpins
);
1325 LeaveCriticalSection(&This
->cs
);
1327 hr
= IPin_EnumMediaTypes(ppinOut
, &penummt
);
1329 WARN("EnumMediaTypes (%x)\n", hr
);
1333 IEnumMediaTypes_Reset(penummt
);
1335 /* Looks like no existing renderer of the kind exists
1336 * Try adding new ones
1338 tab
[0] = tab
[1] = GUID_NULL
;
1339 while (SUCCEEDED(hr
))
1341 hr
= IEnumMediaTypes_Next(penummt
, 1, &mt
, &nbmt
);
1343 WARN("IEnumMediaTypes_Next (%x)\n", hr
);
1348 hr
= VFW_E_CANNOT_RENDER
;
1353 TRACE("MajorType %s\n", debugstr_guid(&mt
->majortype
));
1354 TRACE("SubType %s\n", debugstr_guid(&mt
->subtype
));
1356 /* Only enumerate once, this doesn't account for all previous ones, but this should be enough nonetheless */
1357 if (IsEqualIID(&tab
[0], &mt
->majortype
) && IsEqualIID(&tab
[1], &mt
->subtype
))
1359 DeleteMediaType(mt
);
1363 if (pFilterMapper2
== NULL
)
1365 hr
= IUnknown_QueryInterface(This
->punkFilterMapper2
, &IID_IFilterMapper2
, (void**)&pFilterMapper2
);
1368 WARN("Unable to query IFilterMapper2 (%x)\n", hr
);
1373 /* Try to find a suitable renderer with the same media type */
1374 tab
[0] = mt
->majortype
;
1375 tab
[1] = mt
->subtype
;
1376 hr
= IFilterMapper2_EnumMatchingFilters(pFilterMapper2
, &pEnumMoniker
, 0, FALSE
, MERIT_UNLIKELY
, TRUE
, 1, tab
, NULL
, NULL
, FALSE
, FALSE
, 0, NULL
, NULL
, NULL
);
1379 WARN("Unable to enum filters (%x)\n", hr
);
1385 while (IEnumMoniker_Next(pEnumMoniker
, 1, &pMoniker
, &nb
) == S_OK
)
1389 IBaseFilter
* pfilter
= NULL
;
1390 IEnumPins
* penumpins
= NULL
;
1393 hr
= GetFilterInfo(pMoniker
, &var
);
1395 WARN("Unable to retrieve filter info (%x)\n", hr
);
1399 hr
= IMoniker_BindToObject(pMoniker
, NULL
, NULL
, &IID_IBaseFilter
, (LPVOID
*)&pfilter
);
1400 IMoniker_Release(pMoniker
);
1403 WARN("Unable to create filter (%x), trying next one\n", hr
);
1407 hr
= IFilterGraph2_AddFilter(iface
, pfilter
, V_BSTR(&var
));
1409 WARN("Unable to add filter (%x)\n", hr
);
1410 IBaseFilter_Release(pfilter
);
1415 hr
= IBaseFilter_EnumPins(pfilter
, &penumpins
);
1417 WARN("Splitter Enumpins (%x)\n", hr
);
1421 while ((hr
= IEnumPins_Next(penumpins
, 1, &ppinfilter
, &pin
)) == S_OK
)
1431 hr
= IPin_QueryDirection(ppinfilter
, &dir
);
1433 IPin_Release(ppinfilter
);
1434 WARN("QueryDirection failed (%x)\n", hr
);
1437 if (dir
!= PINDIR_INPUT
) {
1438 IPin_Release(ppinfilter
);
1439 continue; /* Wrong direction */
1442 /* Connect the pin to the "Renderer" */
1443 hr
= IPin_Connect(ppinOut
, ppinfilter
, NULL
);
1444 IPin_Release(ppinfilter
);
1447 WARN("Unable to connect %s to renderer (%x)\n", debugstr_w(V_BSTR(&var
)), hr
);
1450 TRACE("Connected, recursing %s\n", debugstr_w(V_BSTR(&var
)));
1454 hr
= FilterGraph2_RenderRecurse(This
, ppinfilter
);
1456 WARN("Unable to connect recursively (%x)\n", hr
);
1459 IBaseFilter_Release(pfilter
);
1462 if (SUCCEEDED(hr
)) {
1463 IEnumPins_Release(penumpins
);
1464 break; /* out of IEnumMoniker_Next loop */
1467 /* IEnumPins_Next failed, all other failure case caught by goto error */
1468 WARN("IEnumPins_Next (%x)\n", hr
);
1474 IEnumPins_Release(penumpins
);
1476 IFilterGraph2_RemoveFilter(iface
, pfilter
);
1477 IBaseFilter_Release(pfilter
);
1479 if (SUCCEEDED(hr
)) DebugBreak();
1482 IEnumMoniker_Release(pEnumMoniker
);
1484 DeleteMediaType(mt
);
1491 IFilterMapper2_Release(pFilterMapper2
);
1493 IEnumMediaTypes_Release(penummt
);
1497 static HRESULT WINAPI
FilterGraph2_RenderFile(IFilterGraph2
*iface
, LPCWSTR lpcwstrFile
,
1498 LPCWSTR lpcwstrPlayList
)
1500 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
1501 static const WCHAR string
[] = {'R','e','a','d','e','r',0};
1502 IBaseFilter
* preader
= NULL
;
1503 IPin
* ppinreader
= NULL
;
1504 IEnumPins
* penumpins
= NULL
;
1506 BOOL partial
= FALSE
;
1509 TRACE("(%p/%p)->(%s, %s)\n", This
, iface
, debugstr_w(lpcwstrFile
), debugstr_w(lpcwstrPlayList
));
1511 if (lpcwstrPlayList
!= NULL
)
1512 return E_INVALIDARG
;
1514 hr
= IFilterGraph2_AddSourceFilter(iface
, lpcwstrFile
, string
, &preader
);
1519 hr
= IBaseFilter_EnumPins(preader
, &penumpins
);
1522 while (IEnumPins_Next(penumpins
, 1, &ppinreader
, NULL
) == S_OK
)
1526 IPin_QueryDirection(ppinreader
, &dir
);
1527 if (dir
== PINDIR_OUTPUT
)
1531 hr
= IFilterGraph2_Render(iface
, ppinreader
);
1532 TRACE("Render %08x\n", hr
);
1534 for (i
= 0; i
< This
->nFilters
; ++i
)
1535 TRACE("Filters in chain: %s\n", debugstr_w(This
->pFilterNames
[i
]));
1542 IPin_Release(ppinreader
);
1544 IEnumPins_Release(penumpins
);
1547 hr
= VFW_E_CANNOT_RENDER
;
1549 hr
= VFW_S_PARTIAL_RENDER
;
1553 IBaseFilter_Release(preader
);
1555 TRACE("--> %08x\n", hr
);
1559 static HRESULT
CreateFilterInstanceAndLoadFile(GUID
* clsid
, LPCOLESTR pszFileName
, IBaseFilter
**filter
)
1561 IFileSourceFilter
*source
= NULL
;
1562 HRESULT hr
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IBaseFilter
, (LPVOID
*)filter
);
1563 TRACE("CLSID: %s\n", debugstr_guid(clsid
));
1567 hr
= IBaseFilter_QueryInterface(*filter
, &IID_IFileSourceFilter
, (LPVOID
*)&source
);
1570 IBaseFilter_Release(*filter
);
1574 /* Load the file in the file source filter */
1575 hr
= IFileSourceFilter_Load(source
, pszFileName
, NULL
);
1576 IFileSourceFilter_Release(source
);
1578 WARN("Load (%x)\n", hr
);
1579 IBaseFilter_Release(*filter
);
1586 /* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
1587 static HRESULT
GetFileSourceFilter(LPCOLESTR pszFileName
, IBaseFilter
**filter
)
1591 IAsyncReader
* pReader
= NULL
;
1592 IFileSourceFilter
* pSource
= NULL
;
1593 IPin
* pOutputPin
= NULL
;
1594 static const WCHAR wszOutputPinName
[] = { 'O','u','t','p','u','t',0 };
1596 /* Try to find a match without reading the file first */
1597 hr
= GetClassMediaFile(NULL
, pszFileName
, NULL
, NULL
, &clsid
);
1600 return CreateFilterInstanceAndLoadFile(&clsid
, pszFileName
, filter
);
1602 /* Now create a AyncReader instance, to check for signature bytes in the file */
1603 hr
= CoCreateInstance(&CLSID_AsyncReader
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IBaseFilter
, (LPVOID
*)filter
);
1607 hr
= IBaseFilter_QueryInterface(*filter
, &IID_IFileSourceFilter
, (LPVOID
*)&pSource
);
1610 IBaseFilter_Release(*filter
);
1614 hr
= IFileSourceFilter_Load(pSource
, pszFileName
, NULL
);
1615 IFileSourceFilter_Release(pSource
);
1618 IBaseFilter_Release(*filter
);
1622 hr
= IBaseFilter_FindPin(*filter
, wszOutputPinName
, &pOutputPin
);
1625 IBaseFilter_Release(*filter
);
1629 hr
= IPin_QueryInterface(pOutputPin
, &IID_IAsyncReader
, (LPVOID
*)&pReader
);
1630 IPin_Release(pOutputPin
);
1633 IBaseFilter_Release(*filter
);
1637 /* Try again find a match */
1638 hr
= GetClassMediaFile(pReader
, pszFileName
, NULL
, NULL
, &clsid
);
1639 IAsyncReader_Release(pReader
);
1643 /* Release the AsyncReader filter and create the matching one */
1644 IBaseFilter_Release(*filter
);
1645 return CreateFilterInstanceAndLoadFile(&clsid
, pszFileName
, filter
);
1648 /* Return the AsyncReader filter */
1652 static HRESULT WINAPI
FilterGraph2_AddSourceFilter(IFilterGraph2
*iface
, LPCWSTR lpcwstrFileName
,
1653 LPCWSTR lpcwstrFilterName
, IBaseFilter
**ppFilter
)
1655 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
1657 IBaseFilter
* preader
;
1658 IFileSourceFilter
* pfile
= NULL
;
1662 TRACE("(%p/%p)->(%s, %s, %p)\n", This
, iface
, debugstr_w(lpcwstrFileName
), debugstr_w(lpcwstrFilterName
), ppFilter
);
1664 /* Try from file name first, then fall back to default asynchronous reader */
1665 hr
= GetFileSourceFilter(lpcwstrFileName
, &preader
);
1667 WARN("Unable to create file source filter (%x)\n", hr
);
1671 hr
= IFilterGraph2_AddFilter(iface
, preader
, lpcwstrFilterName
);
1673 WARN("Unable add filter (%x)\n", hr
);
1674 IBaseFilter_Release(preader
);
1678 hr
= IBaseFilter_QueryInterface(preader
, &IID_IFileSourceFilter
, (LPVOID
*)&pfile
);
1680 WARN("Unable to get IFileSourceInterface (%x)\n", hr
);
1684 /* The file has been already loaded */
1685 hr
= IFileSourceFilter_GetCurFile(pfile
, &filename
, &mt
);
1687 WARN("GetCurFile (%x)\n", hr
);
1691 TRACE("File %s\n", debugstr_w(filename
));
1692 TRACE("MajorType %s\n", debugstr_guid(&mt
.majortype
));
1693 TRACE("SubType %s\n", debugstr_guid(&mt
.subtype
));
1696 *ppFilter
= preader
;
1697 IFileSourceFilter_Release(pfile
);
1703 IFileSourceFilter_Release(pfile
);
1704 IFilterGraph2_RemoveFilter(iface
, preader
);
1705 IBaseFilter_Release(preader
);
1710 static HRESULT WINAPI
FilterGraph2_SetLogFile(IFilterGraph2
*iface
, DWORD_PTR hFile
)
1712 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
1714 TRACE("(%p/%p)->(%08x): stub !!!\n", This
, iface
, (DWORD
) hFile
);
1719 static HRESULT WINAPI
FilterGraph2_Abort(IFilterGraph2
*iface
)
1721 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
1723 TRACE("(%p/%p)->(): stub !!!\n", This
, iface
);
1728 static HRESULT WINAPI
FilterGraph2_ShouldOperationContinue(IFilterGraph2
*iface
)
1730 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
1732 TRACE("(%p/%p)->(): stub !!!\n", This
, iface
);
1737 /*** IFilterGraph2 methods ***/
1738 static HRESULT WINAPI
FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2
*iface
,
1739 IMoniker
*pMoniker
, IBindCtx
*pCtx
, LPCWSTR lpcwstrFilterName
, IBaseFilter
**ppFilter
)
1741 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
1743 IBaseFilter
* pfilter
;
1745 TRACE("(%p/%p)->(%p %p %s %p)\n", This
, iface
, pMoniker
, pCtx
, debugstr_w(lpcwstrFilterName
), ppFilter
);
1747 hr
= IMoniker_BindToObject(pMoniker
, pCtx
, NULL
, &IID_IBaseFilter
, (void**)&pfilter
);
1749 WARN("Unable to bind moniker to filter object (%x)\n", hr
);
1753 hr
= IFilterGraph2_AddFilter(iface
, pfilter
, lpcwstrFilterName
);
1755 WARN("Unable to add filter (%x)\n", hr
);
1756 IBaseFilter_Release(pfilter
);
1761 *ppFilter
= pfilter
;
1762 else IBaseFilter_Release(pfilter
);
1767 static HRESULT WINAPI
FilterGraph2_ReconnectEx(IFilterGraph2
*iface
, IPin
*ppin
,
1768 const AM_MEDIA_TYPE
*pmt
)
1770 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
1772 TRACE("(%p/%p)->(%p %p): stub !!!\n", This
, iface
, ppin
, pmt
);
1777 static HRESULT WINAPI
FilterGraph2_RenderEx(IFilterGraph2
*iface
, IPin
*pPinOut
, DWORD dwFlags
,
1780 IFilterGraphImpl
*This
= impl_from_IFilterGraph2(iface
);
1782 TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This
, iface
, pPinOut
, dwFlags
, pvContext
);
1788 static const IFilterGraph2Vtbl IFilterGraph2_VTable
=
1790 FilterGraph2_QueryInterface
,
1791 FilterGraph2_AddRef
,
1792 FilterGraph2_Release
,
1793 FilterGraph2_AddFilter
,
1794 FilterGraph2_RemoveFilter
,
1795 FilterGraph2_EnumFilters
,
1796 FilterGraph2_FindFilterByName
,
1797 FilterGraph2_ConnectDirect
,
1798 FilterGraph2_Reconnect
,
1799 FilterGraph2_Disconnect
,
1800 FilterGraph2_SetDefaultSyncSource
,
1801 FilterGraph2_Connect
,
1802 FilterGraph2_Render
,
1803 FilterGraph2_RenderFile
,
1804 FilterGraph2_AddSourceFilter
,
1805 FilterGraph2_SetLogFile
,
1807 FilterGraph2_ShouldOperationContinue
,
1808 FilterGraph2_AddSourceFilterForMoniker
,
1809 FilterGraph2_ReconnectEx
,
1810 FilterGraph2_RenderEx
1813 static inline IFilterGraphImpl
*impl_from_IMediaControl(IMediaControl
*iface
)
1815 return CONTAINING_RECORD(iface
, IFilterGraphImpl
, IMediaControl_iface
);
1818 static HRESULT WINAPI
MediaControl_QueryInterface(IMediaControl
*iface
, REFIID riid
, void **ppvObj
)
1820 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
1822 TRACE("(%p/%p)->(%s (%p), %p)\n", This
, iface
, debugstr_guid(riid
), riid
, ppvObj
);
1824 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppvObj
);
1827 static ULONG WINAPI
MediaControl_AddRef(IMediaControl
*iface
)
1829 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
1831 TRACE("(%p/%p)->()\n", This
, iface
);
1833 return IUnknown_AddRef(This
->outer_unk
);
1836 static ULONG WINAPI
MediaControl_Release(IMediaControl
*iface
)
1838 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
1840 TRACE("(%p/%p)->()\n", This
, iface
);
1842 return IUnknown_Release(This
->outer_unk
);
1846 /*** IDispatch methods ***/
1847 static HRESULT WINAPI
MediaControl_GetTypeInfoCount(IMediaControl
*iface
, UINT
*pctinfo
)
1849 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
1851 TRACE("(%p/%p)->(%p): stub !!!\n", This
, iface
, pctinfo
);
1856 static HRESULT WINAPI
MediaControl_GetTypeInfo(IMediaControl
*iface
, UINT iTInfo
, LCID lcid
,
1857 ITypeInfo
**ppTInfo
)
1859 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
1861 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This
, iface
, iTInfo
, lcid
, ppTInfo
);
1866 static HRESULT WINAPI
MediaControl_GetIDsOfNames(IMediaControl
*iface
, REFIID riid
,
1867 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1869 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
1871 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This
, iface
, debugstr_guid(riid
), riid
, rgszNames
, cNames
, lcid
, rgDispId
);
1876 static HRESULT WINAPI
MediaControl_Invoke(IMediaControl
*iface
, DISPID dispIdMember
, REFIID riid
,
1877 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExepInfo
,
1880 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
1882 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p): stub !!!\n", This
, iface
, dispIdMember
, debugstr_guid(riid
), riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExepInfo
, puArgErr
);
1887 typedef HRESULT(WINAPI
*fnFoundFilter
)(IBaseFilter
*, DWORD_PTR data
);
1889 static HRESULT
ExploreGraph(IFilterGraphImpl
* pGraph
, IPin
* pOutputPin
, fnFoundFilter FoundFilter
, DWORD_PTR data
)
1898 TRACE("%p %p\n", pGraph
, pOutputPin
);
1899 PinInfo
.pFilter
= NULL
;
1901 hr
= IPin_ConnectedTo(pOutputPin
, &pInputPin
);
1905 hr
= IPin_QueryPinInfo(pInputPin
, &PinInfo
);
1907 hr
= GetInternalConnections(PinInfo
.pFilter
, pInputPin
, &ppPins
, &nb
);
1908 IPin_Release(pInputPin
);
1915 TRACE("Reached a renderer\n");
1916 /* Count renderers for end of stream notification */
1917 pGraph
->nRenderers
++;
1921 for(i
= 0; i
< nb
; i
++)
1923 /* Explore the graph downstream from this pin
1924 * FIXME: We should prevent exploring from a pin more than once. This can happens when
1925 * several input pins are connected to the same output (a MUX for instance). */
1926 ExploreGraph(pGraph
, ppPins
[i
], FoundFilter
, data
);
1927 IPin_Release(ppPins
[i
]);
1930 CoTaskMemFree(ppPins
);
1932 TRACE("Doing stuff with filter %p\n", PinInfo
.pFilter
);
1934 FoundFilter(PinInfo
.pFilter
, data
);
1937 if (PinInfo
.pFilter
) IBaseFilter_Release(PinInfo
.pFilter
);
1941 static HRESULT WINAPI
SendRun(IBaseFilter
*pFilter
, DWORD_PTR data
)
1943 REFERENCE_TIME time
= *(REFERENCE_TIME
*)data
;
1944 return IBaseFilter_Run(pFilter
, time
);
1947 static HRESULT WINAPI
SendPause(IBaseFilter
*pFilter
, DWORD_PTR data
)
1949 return IBaseFilter_Pause(pFilter
);
1952 static HRESULT WINAPI
SendStop(IBaseFilter
*pFilter
, DWORD_PTR data
)
1954 return IBaseFilter_Stop(pFilter
);
1957 static HRESULT WINAPI
SendGetState(IBaseFilter
*pFilter
, DWORD_PTR data
)
1960 DWORD time_end
= data
;
1961 DWORD time_now
= GetTickCount();
1964 if (time_end
== INFINITE
)
1968 else if (time_end
> time_now
)
1970 wait
= time_end
- time_now
;
1975 return IBaseFilter_GetState(pFilter
, wait
, &state
);
1979 static HRESULT
SendFilterMessage(IFilterGraphImpl
*This
, fnFoundFilter FoundFilter
, DWORD_PTR data
)
1982 IBaseFilter
* pfilter
;
1989 TRACE("(%p)->()\n", This
);
1991 /* Explorer the graph from source filters to renderers, determine renderers
1992 * number and run filters from renderers to source filters */
1993 This
->nRenderers
= 0;
1994 ResetEvent(This
->hEventCompletion
);
1996 for(i
= 0; i
< This
->nFilters
; i
++)
1999 pfilter
= This
->ppFiltersInGraph
[i
];
2000 hr
= IBaseFilter_EnumPins(pfilter
, &pEnum
);
2003 WARN("Enum pins failed %x\n", hr
);
2006 /* Check if it is a source filter */
2007 while(IEnumPins_Next(pEnum
, 1, &pPin
, &dummy
) == S_OK
)
2009 IPin_QueryDirection(pPin
, &dir
);
2011 if (dir
== PINDIR_INPUT
)
2019 TRACE("Found a source filter %p\n", pfilter
);
2020 IEnumPins_Reset(pEnum
);
2021 while(IEnumPins_Next(pEnum
, 1, &pPin
, &dummy
) == S_OK
)
2023 /* Explore the graph downstream from this pin */
2024 ExploreGraph(This
, pPin
, FoundFilter
, data
);
2027 FoundFilter(pfilter
, data
);
2029 IEnumPins_Release(pEnum
);
2035 /*** IMediaControl methods ***/
2036 static HRESULT WINAPI
MediaControl_Run(IMediaControl
*iface
)
2038 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
2040 TRACE("(%p/%p)->()\n", This
, iface
);
2042 EnterCriticalSection(&This
->cs
);
2043 if (This
->state
== State_Running
)
2045 This
->EcCompleteCount
= 0;
2047 if (This
->defaultclock
&& !This
->refClock
)
2048 IFilterGraph2_SetDefaultSyncSource(&This
->IFilterGraph2_iface
);
2053 IReferenceClock_GetTime(This
->refClock
, &now
);
2054 if (This
->state
== State_Stopped
)
2055 This
->start_time
= now
+ 500000;
2056 else if (This
->pause_time
>= 0)
2057 This
->start_time
+= now
- This
->pause_time
;
2059 This
->start_time
= now
;
2061 else This
->start_time
= 0;
2063 SendFilterMessage(This
, SendRun
, (DWORD_PTR
)&This
->start_time
);
2064 This
->state
= State_Running
;
2066 LeaveCriticalSection(&This
->cs
);
2070 static HRESULT WINAPI
MediaControl_Pause(IMediaControl
*iface
)
2072 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
2074 TRACE("(%p/%p)->()\n", This
, iface
);
2076 EnterCriticalSection(&This
->cs
);
2077 if (This
->state
== State_Paused
)
2080 if (This
->state
== State_Running
&& This
->refClock
&& This
->start_time
>= 0)
2081 IReferenceClock_GetTime(This
->refClock
, &This
->pause_time
);
2083 This
->pause_time
= -1;
2085 SendFilterMessage(This
, SendPause
, 0);
2086 This
->state
= State_Paused
;
2088 LeaveCriticalSection(&This
->cs
);
2092 static HRESULT WINAPI
MediaControl_Stop(IMediaControl
*iface
)
2094 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
2096 TRACE("(%p/%p)->()\n", This
, iface
);
2098 if (This
->state
== State_Stopped
) return S_OK
;
2100 EnterCriticalSection(&This
->cs
);
2101 if (This
->state
== State_Running
) SendFilterMessage(This
, SendPause
, 0);
2102 SendFilterMessage(This
, SendStop
, 0);
2103 This
->state
= State_Stopped
;
2104 LeaveCriticalSection(&This
->cs
);
2108 static HRESULT WINAPI
MediaControl_GetState(IMediaControl
*iface
, LONG msTimeout
,
2111 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
2114 TRACE("(%p/%p)->(%d, %p)\n", This
, iface
, msTimeout
, pfs
);
2119 EnterCriticalSection(&This
->cs
);
2124 end
= GetTickCount() + msTimeout
;
2126 else if (msTimeout
< 0)
2135 SendFilterMessage(This
, SendGetState
, end
);
2137 LeaveCriticalSection(&This
->cs
);
2142 static HRESULT WINAPI
MediaControl_RenderFile(IMediaControl
*iface
, BSTR strFilename
)
2144 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
2146 TRACE("(%p/%p)->(%s (%p))\n", This
, iface
, debugstr_w(strFilename
), strFilename
);
2148 return IFilterGraph2_RenderFile(&This
->IFilterGraph2_iface
, strFilename
, NULL
);
2151 static HRESULT WINAPI
MediaControl_AddSourceFilter(IMediaControl
*iface
, BSTR strFilename
,
2154 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
2156 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This
, iface
, debugstr_w(strFilename
), strFilename
, ppUnk
);
2161 static HRESULT WINAPI
MediaControl_get_FilterCollection(IMediaControl
*iface
, IDispatch
**ppUnk
)
2163 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
2165 FIXME("(%p/%p)->(%p): stub !!!\n", This
, iface
, ppUnk
);
2170 static HRESULT WINAPI
MediaControl_get_RegFilterCollection(IMediaControl
*iface
, IDispatch
**ppUnk
)
2172 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
2174 FIXME("(%p/%p)->(%p): stub !!!\n", This
, iface
, ppUnk
);
2179 static HRESULT WINAPI
MediaControl_StopWhenReady(IMediaControl
*iface
)
2181 IFilterGraphImpl
*This
= impl_from_IMediaControl(iface
);
2183 FIXME("(%p/%p)->(): stub !!!\n", This
, iface
);
2189 static const IMediaControlVtbl IMediaControl_VTable
=
2191 MediaControl_QueryInterface
,
2192 MediaControl_AddRef
,
2193 MediaControl_Release
,
2194 MediaControl_GetTypeInfoCount
,
2195 MediaControl_GetTypeInfo
,
2196 MediaControl_GetIDsOfNames
,
2197 MediaControl_Invoke
,
2201 MediaControl_GetState
,
2202 MediaControl_RenderFile
,
2203 MediaControl_AddSourceFilter
,
2204 MediaControl_get_FilterCollection
,
2205 MediaControl_get_RegFilterCollection
,
2206 MediaControl_StopWhenReady
2209 static inline IFilterGraphImpl
*impl_from_IMediaSeeking(IMediaSeeking
*iface
)
2211 return CONTAINING_RECORD(iface
, IFilterGraphImpl
, IMediaSeeking_iface
);
2214 static HRESULT WINAPI
MediaSeeking_QueryInterface(IMediaSeeking
*iface
, REFIID riid
, void **ppvObj
)
2216 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2218 TRACE("(%p/%p)->(%s (%p), %p)\n", This
, iface
, debugstr_guid(riid
), riid
, ppvObj
);
2220 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppvObj
);
2223 static ULONG WINAPI
MediaSeeking_AddRef(IMediaSeeking
*iface
)
2225 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2227 TRACE("(%p/%p)->()\n", This
, iface
);
2229 return IUnknown_AddRef(This
->outer_unk
);
2232 static ULONG WINAPI
MediaSeeking_Release(IMediaSeeking
*iface
)
2234 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2236 TRACE("(%p/%p)->()\n", This
, iface
);
2238 return IUnknown_Release(This
->outer_unk
);
2241 typedef HRESULT (WINAPI
*fnFoundSeek
)(IFilterGraphImpl
*This
, IMediaSeeking
*, DWORD_PTR arg
);
2243 static HRESULT
all_renderers_seek(IFilterGraphImpl
*This
, fnFoundSeek FoundSeek
, DWORD_PTR arg
) {
2244 BOOL allnotimpl
= TRUE
;
2246 HRESULT hr
, hr_return
= S_OK
;
2248 TRACE("(%p)->(%p %08lx)\n", This
, FoundSeek
, arg
);
2249 /* Send a message to all renderers, they are responsible for broadcasting it further */
2251 for(i
= 0; i
< This
->nFilters
; i
++)
2253 IMediaSeeking
*seek
= NULL
;
2254 IBaseFilter
* pfilter
= This
->ppFiltersInGraph
[i
];
2255 IAMFilterMiscFlags
*flags
= NULL
;
2257 IBaseFilter_QueryInterface(pfilter
, &IID_IAMFilterMiscFlags
, (void**)&flags
);
2260 filterflags
= IAMFilterMiscFlags_GetMiscFlags(flags
);
2261 IAMFilterMiscFlags_Release(flags
);
2262 if (filterflags
!= AM_FILTER_MISC_FLAGS_IS_RENDERER
)
2265 IBaseFilter_QueryInterface(pfilter
, &IID_IMediaSeeking
, (void**)&seek
);
2268 hr
= FoundSeek(This
, seek
, arg
);
2269 IMediaSeeking_Release(seek
);
2270 if (hr_return
!= E_NOTIMPL
)
2272 if (hr_return
== S_OK
|| (FAILED(hr
) && hr
!= E_NOTIMPL
&& SUCCEEDED(hr_return
)))
2281 static HRESULT WINAPI
FoundCapabilities(IFilterGraphImpl
*This
, IMediaSeeking
*seek
, DWORD_PTR pcaps
)
2286 hr
= IMediaSeeking_GetCapabilities(seek
, &caps
);
2290 /* Only add common capabilities everything supports */
2291 *(DWORD
*)pcaps
&= caps
;
2296 /*** IMediaSeeking methods ***/
2297 static HRESULT WINAPI
MediaSeeking_GetCapabilities(IMediaSeeking
*iface
, DWORD
*pCapabilities
)
2299 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2302 TRACE("(%p/%p)->(%p)\n", This
, iface
, pCapabilities
);
2307 EnterCriticalSection(&This
->cs
);
2308 *pCapabilities
= 0xffffffff;
2310 hr
= all_renderers_seek(This
, FoundCapabilities
, (DWORD_PTR
)pCapabilities
);
2311 LeaveCriticalSection(&This
->cs
);
2316 static HRESULT WINAPI
MediaSeeking_CheckCapabilities(IMediaSeeking
*iface
, DWORD
*pCapabilities
)
2318 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2322 TRACE("(%p/%p)->(%p)\n", This
, iface
, pCapabilities
);
2327 EnterCriticalSection(&This
->cs
);
2328 originalcaps
= *pCapabilities
;
2329 hr
= all_renderers_seek(This
, FoundCapabilities
, (DWORD_PTR
)pCapabilities
);
2330 LeaveCriticalSection(&This
->cs
);
2335 if (!*pCapabilities
)
2337 if (*pCapabilities
!= originalcaps
)
2342 static HRESULT WINAPI
MediaSeeking_IsFormatSupported(IMediaSeeking
*iface
, const GUID
*pFormat
)
2344 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2349 TRACE("(%p/%p)->(%s)\n", This
, iface
, debugstr_guid(pFormat
));
2351 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME
, pFormat
))
2353 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat
));
2360 static HRESULT WINAPI
MediaSeeking_QueryPreferredFormat(IMediaSeeking
*iface
, GUID
*pFormat
)
2362 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2367 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This
, iface
, pFormat
);
2368 memcpy(pFormat
, &TIME_FORMAT_MEDIA_TIME
, sizeof(GUID
));
2373 static HRESULT WINAPI
MediaSeeking_GetTimeFormat(IMediaSeeking
*iface
, GUID
*pFormat
)
2375 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2380 TRACE("(%p/%p)->(%p)\n", This
, iface
, pFormat
);
2381 memcpy(pFormat
, &This
->timeformatseek
, sizeof(GUID
));
2386 static HRESULT WINAPI
MediaSeeking_IsUsingTimeFormat(IMediaSeeking
*iface
, const GUID
*pFormat
)
2388 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2390 TRACE("(%p/%p)->(%p)\n", This
, iface
, pFormat
);
2394 if (memcmp(pFormat
, &This
->timeformatseek
, sizeof(GUID
)))
2400 static HRESULT WINAPI
MediaSeeking_SetTimeFormat(IMediaSeeking
*iface
, const GUID
*pFormat
)
2402 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2407 TRACE("(%p/%p)->(%s)\n", This
, iface
, debugstr_guid(pFormat
));
2409 if (This
->state
!= State_Stopped
)
2410 return VFW_E_WRONG_STATE
;
2412 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME
, pFormat
))
2414 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat
));
2415 return E_INVALIDARG
;
2421 static HRESULT WINAPI
FoundDuration(IFilterGraphImpl
*This
, IMediaSeeking
*seek
, DWORD_PTR pduration
)
2424 LONGLONG duration
= 0, *pdur
= (LONGLONG
*)pduration
;
2426 hr
= IMediaSeeking_GetDuration(seek
, &duration
);
2430 if (*pdur
< duration
)
2435 static HRESULT WINAPI
MediaSeeking_GetDuration(IMediaSeeking
*iface
, LONGLONG
*pDuration
)
2437 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2440 TRACE("(%p/%p)->(%p)\n", This
, iface
, pDuration
);
2445 EnterCriticalSection(&This
->cs
);
2447 hr
= all_renderers_seek(This
, FoundDuration
, (DWORD_PTR
)pDuration
);
2448 LeaveCriticalSection(&This
->cs
);
2450 TRACE("--->%08x\n", hr
);
2454 static HRESULT WINAPI
MediaSeeking_ConvertTimeFormat(IMediaSeeking
*iface
, LONGLONG
*pTarget
,
2455 const GUID
*pTargetFormat
, LONGLONG Source
, const GUID
*pSourceFormat
)
2457 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2459 TRACE("(%p/%p)->(%p, %s, 0x%s, %s)\n", This
, iface
, pTarget
,
2460 debugstr_guid(pTargetFormat
), wine_dbgstr_longlong(Source
), debugstr_guid(pSourceFormat
));
2463 pSourceFormat
= &This
->timeformatseek
;
2465 if (IsEqualGUID(pTargetFormat
, pSourceFormat
))
2468 FIXME("conversion %s->%s not supported\n", debugstr_guid(pSourceFormat
), debugstr_guid(pTargetFormat
));
2474 LONGLONG
* current
, *stop
;
2475 DWORD curflags
, stopflags
;
2478 static HRESULT WINAPI
found_setposition(IFilterGraphImpl
*This
, IMediaSeeking
*seek
, DWORD_PTR pargs
)
2480 struct pos_args
*args
= (void*)pargs
;
2482 return IMediaSeeking_SetPositions(seek
, args
->current
, args
->curflags
, args
->stop
, args
->stopflags
);
2485 static HRESULT WINAPI
MediaSeeking_SetPositions(IMediaSeeking
*iface
, LONGLONG
*pCurrent
,
2486 DWORD dwCurrentFlags
, LONGLONG
*pStop
, DWORD dwStopFlags
)
2488 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2491 struct pos_args args
;
2493 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This
, iface
, pCurrent
, dwCurrentFlags
, pStop
, dwStopFlags
);
2495 EnterCriticalSection(&This
->cs
);
2496 state
= This
->state
;
2497 TRACE("State: %s\n", state
== State_Running
? "Running" : (state
== State_Paused
? "Paused" : (state
== State_Stopped
? "Stopped" : "UNKNOWN")));
2499 if ((dwCurrentFlags
& 0x7) != AM_SEEKING_AbsolutePositioning
&&
2500 (dwCurrentFlags
& 0x7) != AM_SEEKING_NoPositioning
)
2501 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags
& 0x7);
2503 if (state
== State_Running
&& !(dwCurrentFlags
& AM_SEEKING_NoFlush
))
2504 IMediaControl_Pause(&This
->IMediaControl_iface
);
2505 args
.current
= pCurrent
;
2507 args
.curflags
= dwCurrentFlags
;
2508 args
.stopflags
= dwStopFlags
;
2509 hr
= all_renderers_seek(This
, found_setposition
, (DWORD_PTR
)&args
);
2511 if ((dwCurrentFlags
& 0x7) != AM_SEEKING_NoPositioning
)
2512 This
->pause_time
= This
->start_time
= -1;
2513 if (state
== State_Running
&& !(dwCurrentFlags
& AM_SEEKING_NoFlush
))
2514 IMediaControl_Run(&This
->IMediaControl_iface
);
2515 LeaveCriticalSection(&This
->cs
);
2520 static HRESULT WINAPI
found_getposition(IFilterGraphImpl
*This
, IMediaSeeking
*seek
, DWORD_PTR pargs
)
2522 struct pos_args
*args
= (void*)pargs
;
2524 return IMediaSeeking_GetPositions(seek
, args
->current
, args
->stop
);
2527 static HRESULT WINAPI
MediaSeeking_GetPositions(IMediaSeeking
*iface
, LONGLONG
*pCurrent
,
2530 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2531 struct pos_args args
;
2535 TRACE("(%p/%p)->(%p, %p)\n", This
, iface
, pCurrent
, pStop
);
2537 args
.current
= pCurrent
;
2539 EnterCriticalSection(&This
->cs
);
2540 hr
= all_renderers_seek(This
, found_getposition
, (DWORD_PTR
)&args
);
2541 if (This
->state
== State_Running
&& This
->refClock
&& This
->start_time
>= 0)
2543 IReferenceClock_GetTime(This
->refClock
, &time
);
2545 time
-= This
->start_time
;
2547 if (This
->pause_time
> 0)
2548 time
+= This
->pause_time
;
2550 LeaveCriticalSection(&This
->cs
);
2555 static HRESULT WINAPI
MediaSeeking_GetCurrentPosition(IMediaSeeking
*iface
, LONGLONG
*pCurrent
)
2563 hr
= MediaSeeking_GetPositions(iface
, pCurrent
, &time
);
2565 TRACE("Time: %u.%03u\n", (DWORD
)(*pCurrent
/ 10000000), (DWORD
)((*pCurrent
/ 10000)%1000));
2570 static HRESULT WINAPI
MediaSeeking_GetStopPosition(IMediaSeeking
*iface
, LONGLONG
*pStop
)
2572 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2576 TRACE("(%p/%p)->(%p)\n", This
, iface
, pStop
);
2581 hr
= MediaSeeking_GetPositions(iface
, &time
, pStop
);
2586 static HRESULT WINAPI
MediaSeeking_GetAvailable(IMediaSeeking
*iface
, LONGLONG
*pEarliest
,
2589 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2591 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This
, iface
, pEarliest
, pLatest
);
2596 static HRESULT WINAPI
MediaSeeking_SetRate(IMediaSeeking
*iface
, double dRate
)
2598 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2600 FIXME("(%p/%p)->(%f): stub !!!\n", This
, iface
, dRate
);
2605 static HRESULT WINAPI
MediaSeeking_GetRate(IMediaSeeking
*iface
, double *pdRate
)
2607 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2609 FIXME("(%p/%p)->(%p): stub !!!\n", This
, iface
, pdRate
);
2614 static HRESULT WINAPI
MediaSeeking_GetPreroll(IMediaSeeking
*iface
, LONGLONG
*pllPreroll
)
2616 IFilterGraphImpl
*This
= impl_from_IMediaSeeking(iface
);
2618 FIXME("(%p/%p)->(%p): stub !!!\n", This
, iface
, pllPreroll
);
2624 static const IMediaSeekingVtbl IMediaSeeking_VTable
=
2626 MediaSeeking_QueryInterface
,
2627 MediaSeeking_AddRef
,
2628 MediaSeeking_Release
,
2629 MediaSeeking_GetCapabilities
,
2630 MediaSeeking_CheckCapabilities
,
2631 MediaSeeking_IsFormatSupported
,
2632 MediaSeeking_QueryPreferredFormat
,
2633 MediaSeeking_GetTimeFormat
,
2634 MediaSeeking_IsUsingTimeFormat
,
2635 MediaSeeking_SetTimeFormat
,
2636 MediaSeeking_GetDuration
,
2637 MediaSeeking_GetStopPosition
,
2638 MediaSeeking_GetCurrentPosition
,
2639 MediaSeeking_ConvertTimeFormat
,
2640 MediaSeeking_SetPositions
,
2641 MediaSeeking_GetPositions
,
2642 MediaSeeking_GetAvailable
,
2643 MediaSeeking_SetRate
,
2644 MediaSeeking_GetRate
,
2645 MediaSeeking_GetPreroll
2648 static inline IFilterGraphImpl
*impl_from_IMediaPosition(IMediaPosition
*iface
)
2650 return CONTAINING_RECORD(iface
, IFilterGraphImpl
, IMediaPosition_iface
);
2653 /*** IUnknown methods ***/
2654 static HRESULT WINAPI
MediaPosition_QueryInterface(IMediaPosition
* iface
, REFIID riid
, void** ppvObj
)
2656 IFilterGraphImpl
*This
= impl_from_IMediaPosition( iface
);
2658 TRACE("(%p/%p)->(%s (%p), %p)\n", This
, iface
, debugstr_guid(riid
), riid
, ppvObj
);
2660 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppvObj
);
2663 static ULONG WINAPI
MediaPosition_AddRef(IMediaPosition
*iface
)
2665 IFilterGraphImpl
*This
= impl_from_IMediaPosition( iface
);
2667 TRACE("(%p/%p)->()\n", This
, iface
);
2669 return IUnknown_AddRef(This
->outer_unk
);
2672 static ULONG WINAPI
MediaPosition_Release(IMediaPosition
*iface
)
2674 IFilterGraphImpl
*This
= impl_from_IMediaPosition( iface
);
2676 TRACE("(%p/%p)->()\n", This
, iface
);
2678 return IUnknown_Release(This
->outer_unk
);
2681 /*** IDispatch methods ***/
2682 static HRESULT WINAPI
MediaPosition_GetTypeInfoCount(IMediaPosition
*iface
, UINT
* pctinfo
)
2684 FIXME("(%p) stub!\n", iface
);
2688 static HRESULT WINAPI
MediaPosition_GetTypeInfo(IMediaPosition
*iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
2690 FIXME("(%p) stub!\n", iface
);
2694 static HRESULT WINAPI
MediaPosition_GetIDsOfNames(IMediaPosition
* iface
, REFIID riid
, LPOLESTR
* rgszNames
, UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
2696 FIXME("(%p) stub!\n", iface
);
2700 static HRESULT WINAPI
MediaPosition_Invoke(IMediaPosition
* iface
, DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
, EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
2702 FIXME("(%p) stub!\n", iface
);
2706 static HRESULT
ConvertFromREFTIME(IMediaSeeking
*seek
, REFTIME time_in
, LONGLONG
*time_out
)
2711 hr
= MediaSeeking_GetTimeFormat(seek
, &time_format
);
2714 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME
, &time_format
))
2716 FIXME("Unsupported time format.\n");
2720 *time_out
= (LONGLONG
) (time_in
* 10000000); /* convert from 1 second intervals to 100 ns intervals */
2724 static HRESULT
ConvertToREFTIME(IMediaSeeking
*seek
, LONGLONG time_in
, REFTIME
*time_out
)
2729 hr
= MediaSeeking_GetTimeFormat(seek
, &time_format
);
2732 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME
, &time_format
))
2734 FIXME("Unsupported time format.\n");
2738 *time_out
= (REFTIME
)time_in
/ 10000000; /* convert from 100 ns intervals to 1 second intervals */
2742 /*** IMediaPosition methods ***/
2743 static HRESULT WINAPI
MediaPosition_get_Duration(IMediaPosition
* iface
, REFTIME
*plength
)
2746 IFilterGraphImpl
*This
= impl_from_IMediaPosition( iface
);
2747 HRESULT hr
= IMediaSeeking_GetDuration(&This
->IMediaSeeking_iface
, &duration
);
2750 return ConvertToREFTIME(&This
->IMediaSeeking_iface
, duration
, plength
);
2753 static HRESULT WINAPI
MediaPosition_put_CurrentPosition(IMediaPosition
* iface
, REFTIME llTime
)
2755 IFilterGraphImpl
*This
= impl_from_IMediaPosition( iface
);
2759 hr
= ConvertFromREFTIME(&This
->IMediaSeeking_iface
, llTime
, &reftime
);
2762 return IMediaSeeking_SetPositions(&This
->IMediaSeeking_iface
, &reftime
,
2763 AM_SEEKING_AbsolutePositioning
, NULL
, AM_SEEKING_NoPositioning
);
2766 static HRESULT WINAPI
MediaPosition_get_CurrentPosition(IMediaPosition
* iface
, REFTIME
*pllTime
)
2768 IFilterGraphImpl
*This
= impl_from_IMediaPosition( iface
);
2772 hr
= IMediaSeeking_GetCurrentPosition(&This
->IMediaSeeking_iface
, &pos
);
2775 return ConvertToREFTIME(&This
->IMediaSeeking_iface
, pos
, pllTime
);
2778 static HRESULT WINAPI
MediaPosition_get_StopTime(IMediaPosition
* iface
, REFTIME
*pllTime
)
2780 IFilterGraphImpl
*This
= impl_from_IMediaPosition( iface
);
2782 HRESULT hr
= IMediaSeeking_GetStopPosition(&This
->IMediaSeeking_iface
, &pos
);
2785 return ConvertToREFTIME(&This
->IMediaSeeking_iface
, pos
, pllTime
);
2788 static HRESULT WINAPI
MediaPosition_put_StopTime(IMediaPosition
* iface
, REFTIME llTime
)
2790 IFilterGraphImpl
*This
= impl_from_IMediaPosition( iface
);
2794 hr
= ConvertFromREFTIME(&This
->IMediaSeeking_iface
, llTime
, &reftime
);
2797 return IMediaSeeking_SetPositions(&This
->IMediaSeeking_iface
, NULL
, AM_SEEKING_NoPositioning
,
2798 &reftime
, AM_SEEKING_AbsolutePositioning
);
2801 static HRESULT WINAPI
MediaPosition_get_PrerollTime(IMediaPosition
* iface
, REFTIME
*pllTime
)
2803 FIXME("(%p)->(%p) stub!\n", iface
, pllTime
);
2807 static HRESULT WINAPI
MediaPosition_put_PrerollTime(IMediaPosition
* iface
, REFTIME llTime
)
2809 FIXME("(%p)->(%f) stub!\n", iface
, llTime
);
2813 static HRESULT WINAPI
MediaPosition_put_Rate(IMediaPosition
* iface
, double dRate
)
2815 IFilterGraphImpl
*This
= impl_from_IMediaPosition( iface
);
2816 return IMediaSeeking_SetRate(&This
->IMediaSeeking_iface
, dRate
);
2819 static HRESULT WINAPI
MediaPosition_get_Rate(IMediaPosition
* iface
, double *pdRate
)
2821 IFilterGraphImpl
*This
= impl_from_IMediaPosition( iface
);
2822 return IMediaSeeking_GetRate(&This
->IMediaSeeking_iface
, pdRate
);
2825 static HRESULT WINAPI
MediaPosition_CanSeekForward(IMediaPosition
* iface
, LONG
*pCanSeekForward
)
2827 FIXME("(%p)->(%p) stub!\n", iface
, pCanSeekForward
);
2831 static HRESULT WINAPI
MediaPosition_CanSeekBackward(IMediaPosition
* iface
, LONG
*pCanSeekBackward
)
2833 FIXME("(%p)->(%p) stub!\n", iface
, pCanSeekBackward
);
2838 static const IMediaPositionVtbl IMediaPosition_VTable
=
2840 MediaPosition_QueryInterface
,
2841 MediaPosition_AddRef
,
2842 MediaPosition_Release
,
2843 MediaPosition_GetTypeInfoCount
,
2844 MediaPosition_GetTypeInfo
,
2845 MediaPosition_GetIDsOfNames
,
2846 MediaPosition_Invoke
,
2847 MediaPosition_get_Duration
,
2848 MediaPosition_put_CurrentPosition
,
2849 MediaPosition_get_CurrentPosition
,
2850 MediaPosition_get_StopTime
,
2851 MediaPosition_put_StopTime
,
2852 MediaPosition_get_PrerollTime
,
2853 MediaPosition_put_PrerollTime
,
2854 MediaPosition_put_Rate
,
2855 MediaPosition_get_Rate
,
2856 MediaPosition_CanSeekForward
,
2857 MediaPosition_CanSeekBackward
2860 static inline IFilterGraphImpl
*impl_from_IObjectWithSite(IObjectWithSite
*iface
)
2862 return CONTAINING_RECORD(iface
, IFilterGraphImpl
, IObjectWithSite_iface
);
2865 /*** IUnknown methods ***/
2866 static HRESULT WINAPI
ObjectWithSite_QueryInterface(IObjectWithSite
* iface
, REFIID riid
, void** ppvObj
)
2868 IFilterGraphImpl
*This
= impl_from_IObjectWithSite( iface
);
2870 TRACE("(%p/%p)->(%s (%p), %p)\n", This
, iface
, debugstr_guid(riid
), riid
, ppvObj
);
2872 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppvObj
);
2875 static ULONG WINAPI
ObjectWithSite_AddRef(IObjectWithSite
*iface
)
2877 IFilterGraphImpl
*This
= impl_from_IObjectWithSite( iface
);
2879 TRACE("(%p/%p)->()\n", This
, iface
);
2881 return IUnknown_AddRef(This
->outer_unk
);
2884 static ULONG WINAPI
ObjectWithSite_Release(IObjectWithSite
*iface
)
2886 IFilterGraphImpl
*This
= impl_from_IObjectWithSite( iface
);
2888 TRACE("(%p/%p)->()\n", This
, iface
);
2890 return IUnknown_Release(This
->outer_unk
);
2893 /*** IObjectWithSite methods ***/
2895 static HRESULT WINAPI
ObjectWithSite_SetSite(IObjectWithSite
*iface
, IUnknown
*pUnkSite
)
2897 IFilterGraphImpl
*This
= impl_from_IObjectWithSite( iface
);
2899 TRACE("(%p/%p)->()\n", This
, iface
);
2900 if (This
->pSite
) IUnknown_Release(This
->pSite
);
2901 This
->pSite
= pUnkSite
;
2902 IUnknown_AddRef(This
->pSite
);
2906 static HRESULT WINAPI
ObjectWithSite_GetSite(IObjectWithSite
*iface
, REFIID riid
, PVOID
*ppvSite
)
2908 IFilterGraphImpl
*This
= impl_from_IObjectWithSite( iface
);
2910 TRACE("(%p/%p)->(%s)\n", This
, iface
,debugstr_guid(riid
));
2916 return IUnknown_QueryInterface(This
->pSite
, riid
, ppvSite
);
2919 static const IObjectWithSiteVtbl IObjectWithSite_VTable
=
2921 ObjectWithSite_QueryInterface
,
2922 ObjectWithSite_AddRef
,
2923 ObjectWithSite_Release
,
2924 ObjectWithSite_SetSite
,
2925 ObjectWithSite_GetSite
,
2928 static HRESULT
GetTargetInterface(IFilterGraphImpl
* pGraph
, REFIID riid
, LPVOID
* ppvObj
)
2930 HRESULT hr
= E_NOINTERFACE
;
2934 /* Check if the interface type is already registered */
2935 for (entry
= 0; entry
< pGraph
->nItfCacheEntries
; entry
++)
2936 if (riid
== pGraph
->ItfCacheEntries
[entry
].riid
)
2938 if (pGraph
->ItfCacheEntries
[entry
].iface
)
2940 /* Return the interface if available */
2941 *ppvObj
= pGraph
->ItfCacheEntries
[entry
].iface
;
2947 if (entry
>= MAX_ITF_CACHE_ENTRIES
)
2949 FIXME("Not enough space to store interface in the cache\n");
2950 return E_OUTOFMEMORY
;
2953 /* Find a filter supporting the requested interface */
2954 for (i
= 0; i
< pGraph
->nFilters
; i
++)
2956 hr
= IBaseFilter_QueryInterface(pGraph
->ppFiltersInGraph
[i
], riid
, ppvObj
);
2959 pGraph
->ItfCacheEntries
[entry
].riid
= riid
;
2960 pGraph
->ItfCacheEntries
[entry
].filter
= pGraph
->ppFiltersInGraph
[i
];
2961 pGraph
->ItfCacheEntries
[entry
].iface
= *ppvObj
;
2962 if (entry
>= pGraph
->nItfCacheEntries
)
2963 pGraph
->nItfCacheEntries
++;
2966 if (hr
!= E_NOINTERFACE
)
2973 static inline IFilterGraphImpl
*impl_from_IBasicAudio(IBasicAudio
*iface
)
2975 return CONTAINING_RECORD(iface
, IFilterGraphImpl
, IBasicAudio_iface
);
2978 static HRESULT WINAPI
BasicAudio_QueryInterface(IBasicAudio
*iface
, REFIID riid
, void **ppvObj
)
2980 IFilterGraphImpl
*This
= impl_from_IBasicAudio(iface
);
2982 TRACE("(%p/%p)->(%s (%p), %p)\n", This
, iface
, debugstr_guid(riid
), riid
, ppvObj
);
2984 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppvObj
);
2987 static ULONG WINAPI
BasicAudio_AddRef(IBasicAudio
*iface
)
2989 IFilterGraphImpl
*This
= impl_from_IBasicAudio(iface
);
2991 TRACE("(%p/%p)->()\n", This
, iface
);
2993 return IUnknown_AddRef(This
->outer_unk
);
2996 static ULONG WINAPI
BasicAudio_Release(IBasicAudio
*iface
)
2998 IFilterGraphImpl
*This
= impl_from_IBasicAudio(iface
);
3000 TRACE("(%p/%p)->()\n", This
, iface
);
3002 return IUnknown_Release(This
->outer_unk
);
3005 /*** IDispatch methods ***/
3006 static HRESULT WINAPI
BasicAudio_GetTypeInfoCount(IBasicAudio
*iface
, UINT
*pctinfo
)
3008 IFilterGraphImpl
*This
= impl_from_IBasicAudio(iface
);
3009 IBasicAudio
* pBasicAudio
;
3012 TRACE("(%p/%p)->(%p)\n", This
, iface
, pctinfo
);
3014 EnterCriticalSection(&This
->cs
);
3016 hr
= GetTargetInterface(This
, &IID_IBasicAudio
, (LPVOID
*)&pBasicAudio
);
3019 hr
= IBasicAudio_GetTypeInfoCount(pBasicAudio
, pctinfo
);
3021 LeaveCriticalSection(&This
->cs
);
3026 static HRESULT WINAPI
BasicAudio_GetTypeInfo(IBasicAudio
*iface
, UINT iTInfo
, LCID lcid
,
3027 ITypeInfo
**ppTInfo
)
3029 IFilterGraphImpl
*This
= impl_from_IBasicAudio(iface
);
3030 IBasicAudio
* pBasicAudio
;
3033 TRACE("(%p/%p)->(%d, %d, %p)\n", This
, iface
, iTInfo
, lcid
, ppTInfo
);
3035 EnterCriticalSection(&This
->cs
);
3037 hr
= GetTargetInterface(This
, &IID_IBasicAudio
, (LPVOID
*)&pBasicAudio
);
3040 hr
= IBasicAudio_GetTypeInfo(pBasicAudio
, iTInfo
, lcid
, ppTInfo
);
3042 LeaveCriticalSection(&This
->cs
);
3047 static HRESULT WINAPI
BasicAudio_GetIDsOfNames(IBasicAudio
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
3048 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
3050 IFilterGraphImpl
*This
= impl_from_IBasicAudio(iface
);
3051 IBasicAudio
* pBasicAudio
;
3054 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This
, iface
, debugstr_guid(riid
), riid
, rgszNames
, cNames
, lcid
, rgDispId
);
3056 EnterCriticalSection(&This
->cs
);
3058 hr
= GetTargetInterface(This
, &IID_IBasicAudio
, (LPVOID
*)&pBasicAudio
);
3061 hr
= IBasicAudio_GetIDsOfNames(pBasicAudio
, riid
, rgszNames
, cNames
, lcid
, rgDispId
);
3063 LeaveCriticalSection(&This
->cs
);
3068 static HRESULT WINAPI
BasicAudio_Invoke(IBasicAudio
*iface
, DISPID dispIdMember
, REFIID riid
,
3069 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExepInfo
,
3072 IFilterGraphImpl
*This
= impl_from_IBasicAudio(iface
);
3073 IBasicAudio
* pBasicAudio
;
3076 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p)\n", This
, iface
, dispIdMember
, debugstr_guid(riid
), riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExepInfo
, puArgErr
);
3078 EnterCriticalSection(&This
->cs
);
3080 hr
= GetTargetInterface(This
, &IID_IBasicAudio
, (LPVOID
*)&pBasicAudio
);
3083 hr
= IBasicAudio_Invoke(pBasicAudio
, dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExepInfo
, puArgErr
);
3085 LeaveCriticalSection(&This
->cs
);
3090 /*** IBasicAudio methods ***/
3091 static HRESULT WINAPI
BasicAudio_put_Volume(IBasicAudio
*iface
, LONG lVolume
)
3093 IFilterGraphImpl
*This
= impl_from_IBasicAudio(iface
);
3094 IBasicAudio
* pBasicAudio
;
3097 TRACE("(%p/%p)->(%d)\n", This
, iface
, lVolume
);
3099 EnterCriticalSection(&This
->cs
);
3101 hr
= GetTargetInterface(This
, &IID_IBasicAudio
, (LPVOID
*)&pBasicAudio
);
3104 hr
= IBasicAudio_put_Volume(pBasicAudio
, lVolume
);
3106 LeaveCriticalSection(&This
->cs
);
3111 static HRESULT WINAPI
BasicAudio_get_Volume(IBasicAudio
*iface
, LONG
*plVolume
)
3113 IFilterGraphImpl
*This
= impl_from_IBasicAudio(iface
);
3114 IBasicAudio
* pBasicAudio
;
3117 TRACE("(%p/%p)->(%p)\n", This
, iface
, plVolume
);
3119 EnterCriticalSection(&This
->cs
);
3121 hr
= GetTargetInterface(This
, &IID_IBasicAudio
, (LPVOID
*)&pBasicAudio
);
3124 hr
= IBasicAudio_get_Volume(pBasicAudio
, plVolume
);
3126 LeaveCriticalSection(&This
->cs
);
3131 static HRESULT WINAPI
BasicAudio_put_Balance(IBasicAudio
*iface
, LONG lBalance
)
3133 IFilterGraphImpl
*This
= impl_from_IBasicAudio(iface
);
3134 IBasicAudio
* pBasicAudio
;
3137 TRACE("(%p/%p)->(%d)\n", This
, iface
, lBalance
);
3139 EnterCriticalSection(&This
->cs
);
3141 hr
= GetTargetInterface(This
, &IID_IBasicAudio
, (LPVOID
*)&pBasicAudio
);
3144 hr
= IBasicAudio_put_Balance(pBasicAudio
, lBalance
);
3146 LeaveCriticalSection(&This
->cs
);
3151 static HRESULT WINAPI
BasicAudio_get_Balance(IBasicAudio
*iface
, LONG
*plBalance
)
3153 IFilterGraphImpl
*This
= impl_from_IBasicAudio(iface
);
3154 IBasicAudio
* pBasicAudio
;
3157 TRACE("(%p/%p)->(%p)\n", This
, iface
, plBalance
);
3159 EnterCriticalSection(&This
->cs
);
3161 hr
= GetTargetInterface(This
, &IID_IBasicAudio
, (LPVOID
*)&pBasicAudio
);
3164 hr
= IBasicAudio_get_Balance(pBasicAudio
, plBalance
);
3166 LeaveCriticalSection(&This
->cs
);
3171 static const IBasicAudioVtbl IBasicAudio_VTable
=
3173 BasicAudio_QueryInterface
,
3176 BasicAudio_GetTypeInfoCount
,
3177 BasicAudio_GetTypeInfo
,
3178 BasicAudio_GetIDsOfNames
,
3180 BasicAudio_put_Volume
,
3181 BasicAudio_get_Volume
,
3182 BasicAudio_put_Balance
,
3183 BasicAudio_get_Balance
3186 static inline IFilterGraphImpl
*impl_from_IBasicVideo2(IBasicVideo2
*iface
)
3188 return CONTAINING_RECORD(iface
, IFilterGraphImpl
, IBasicVideo2_iface
);
3191 static HRESULT WINAPI
BasicVideo_QueryInterface(IBasicVideo2
*iface
, REFIID riid
, void **ppvObj
)
3193 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3195 TRACE("(%p/%p)->(%s (%p), %p)\n", This
, iface
, debugstr_guid(riid
), riid
, ppvObj
);
3197 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppvObj
);
3200 static ULONG WINAPI
BasicVideo_AddRef(IBasicVideo2
*iface
)
3202 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3204 TRACE("(%p/%p)->()\n", This
, iface
);
3206 return IUnknown_AddRef(This
->outer_unk
);
3209 static ULONG WINAPI
BasicVideo_Release(IBasicVideo2
*iface
)
3211 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3213 TRACE("(%p/%p)->()\n", This
, iface
);
3215 return IUnknown_Release(This
->outer_unk
);
3218 /*** IDispatch methods ***/
3219 static HRESULT WINAPI
BasicVideo_GetTypeInfoCount(IBasicVideo2
*iface
, UINT
*pctinfo
)
3221 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3222 IBasicVideo
*pBasicVideo
;
3225 TRACE("(%p/%p)->(%p)\n", This
, iface
, pctinfo
);
3227 EnterCriticalSection(&This
->cs
);
3229 hr
= GetTargetInterface(This
, &IID_IBasicVideo
, (LPVOID
*)&pBasicVideo
);
3232 hr
= IBasicVideo_GetTypeInfoCount(pBasicVideo
, pctinfo
);
3234 LeaveCriticalSection(&This
->cs
);
3239 static HRESULT WINAPI
BasicVideo_GetTypeInfo(IBasicVideo2
*iface
, UINT iTInfo
, LCID lcid
,
3240 ITypeInfo
**ppTInfo
)
3242 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3243 IBasicVideo
*pBasicVideo
;
3246 TRACE("(%p/%p)->(%d, %d, %p)\n", This
, iface
, iTInfo
, lcid
, ppTInfo
);
3248 EnterCriticalSection(&This
->cs
);
3250 hr
= GetTargetInterface(This
, &IID_IBasicVideo
, (LPVOID
*)&pBasicVideo
);
3253 hr
= IBasicVideo_GetTypeInfo(pBasicVideo
, iTInfo
, lcid
, ppTInfo
);
3255 LeaveCriticalSection(&This
->cs
);
3260 static HRESULT WINAPI
BasicVideo_GetIDsOfNames(IBasicVideo2
*iface
, REFIID riid
,
3261 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
3263 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3264 IBasicVideo
*pBasicVideo
;
3267 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This
, iface
, debugstr_guid(riid
), riid
, rgszNames
, cNames
, lcid
, rgDispId
);
3269 EnterCriticalSection(&This
->cs
);
3271 hr
= GetTargetInterface(This
, &IID_IBasicVideo
, (LPVOID
*)&pBasicVideo
);
3274 hr
= IBasicVideo_GetIDsOfNames(pBasicVideo
, riid
, rgszNames
, cNames
, lcid
, rgDispId
);
3276 LeaveCriticalSection(&This
->cs
);
3281 static HRESULT WINAPI
BasicVideo_Invoke(IBasicVideo2
*iface
, DISPID dispIdMember
, REFIID riid
,
3282 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExepInfo
,
3285 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3286 IBasicVideo
*pBasicVideo
;
3289 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p)\n", This
, iface
, dispIdMember
, debugstr_guid(riid
), riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExepInfo
, puArgErr
);
3291 EnterCriticalSection(&This
->cs
);
3293 hr
= GetTargetInterface(This
, &IID_IBasicVideo
, (LPVOID
*)&pBasicVideo
);
3296 hr
= IBasicVideo_Invoke(pBasicVideo
, dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExepInfo
, puArgErr
);
3298 LeaveCriticalSection(&This
->cs
);
3303 /*** IBasicVideo methods ***/
3304 static HRESULT WINAPI
BasicVideo_get_AvgTimePerFrame(IBasicVideo2
*iface
, REFTIME
*pAvgTimePerFrame
)
3306 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3307 IBasicVideo
*pBasicVideo
;
3310 TRACE("(%p/%p)->(%p)\n", This
, iface
, pAvgTimePerFrame
);
3312 EnterCriticalSection(&This
->cs
);
3314 hr
= GetTargetInterface(This
, &IID_IBasicVideo
, (LPVOID
*)&pBasicVideo
);
3317 hr
= IBasicVideo_get_AvgTimePerFrame(pBasicVideo
, pAvgTimePerFrame
);
3319 LeaveCriticalSection(&This
->cs
);
3324 static HRESULT WINAPI
BasicVideo_get_BitRate(IBasicVideo2
*iface
, LONG
*pBitRate
)
3326 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3327 IBasicVideo
*pBasicVideo
;
3330 TRACE("(%p/%p)->(%p)\n", This
, iface
, pBitRate
);
3332 EnterCriticalSection(&This
->cs
);
3334 hr
= GetTargetInterface(This
, &IID_IBasicVideo
, (LPVOID
*)&pBasicVideo
);
3337 hr
= IBasicVideo_get_BitRate(pBasicVideo
, pBitRate
);
3339 LeaveCriticalSection(&This
->cs
);
3344 static HRESULT WINAPI
BasicVideo_get_BitErrorRate(IBasicVideo2
*iface
, LONG
*pBitErrorRate
)
3346 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3347 IBasicVideo
*pBasicVideo
;
3350 TRACE("(%p/%p)->(%p)\n", This
, iface
, pBitErrorRate
);
3352 EnterCriticalSection(&This
->cs
);
3354 hr
= GetTargetInterface(This
, &IID_IBasicVideo
, (LPVOID
*)&pBasicVideo
);
3357 hr
= IBasicVideo_get_BitErrorRate(pBasicVideo
, pBitErrorRate
);
3359 LeaveCriticalSection(&This
->cs
);
3364 static HRESULT WINAPI
BasicVideo_get_VideoWidth(IBasicVideo2
*iface
, LONG
*pVideoWidth
)
3366 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3367 IBasicVideo
*pBasicVideo
;
3370 TRACE("(%p/%p)->(%p)\n", This
, iface
, pVideoWidth
);
3372 EnterCriticalSection(&This
->cs
);
3374 hr
= GetTargetInterface(This
, &IID_IBasicVideo
, (LPVOID
*)&pBasicVideo
);
3377 hr
= IBasicVideo_get_VideoWidth(pBasicVideo
, pVideoWidth
);
3379 LeaveCriticalSection(&This
->cs
);
3384 static HRESULT WINAPI
BasicVideo_get_VideoHeight(IBasicVideo2
*iface
, LONG
*pVideoHeight
)
3386 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3387 IBasicVideo
*pBasicVideo
;
3390 TRACE("(%p/%p)->(%p)\n", This
, iface
, pVideoHeight
);
3392 EnterCriticalSection(&This
->cs
);
3394 hr
= GetTargetInterface(This
, &IID_IBasicVideo
, (LPVOID
*)&pBasicVideo
);
3397 hr
= IBasicVideo_get_VideoHeight(pBasicVideo
, pVideoHeight
);
3399 LeaveCriticalSection(&This
->cs
);
3404 static HRESULT WINAPI
BasicVideo_put_SourceLeft(IBasicVideo2
*iface
, LONG SourceLeft
)
3406 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3407 IBasicVideo
*pBasicVideo
;
3410 TRACE("(%p/%p)->(%d)\n", This
, iface
, SourceLeft
);
3412 EnterCriticalSection(&This
->cs
);
3414 hr
= GetTargetInterface(This
, &IID_IBasicVideo
, (LPVOID
*)&pBasicVideo
);
3417 hr
= IBasicVideo_put_SourceLeft(pBasicVideo
, SourceLeft
);
3419 LeaveCriticalSection(&This
->cs
);
3424 static HRESULT WINAPI
BasicVideo_get_SourceLeft(IBasicVideo2
*iface
, LONG
*pSourceLeft
)
3426 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3427 IBasicVideo
*pBasicVideo
;
3430 TRACE("(%p/%p)->(%p)\n", This
, iface
, pSourceLeft
);
3432 EnterCriticalSection(&This
->cs
);
3434 hr
= GetTargetInterface(This
, &IID_IBasicVideo
, (LPVOID
*)&pBasicVideo
);
3437 hr
= IBasicVideo_get_SourceLeft(pBasicVideo
, pSourceLeft
);
3439 LeaveCriticalSection(&This
->cs
);
3444 static HRESULT WINAPI
BasicVideo_put_SourceWidth(IBasicVideo2
*iface
, LONG SourceWidth
)
3446 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3447 IBasicVideo
*pBasicVideo
;
3450 TRACE("(%p/%p)->(%d)\n", This
, iface
, SourceWidth
);
3452 EnterCriticalSection(&This
->cs
);
3454 hr
= GetTargetInterface(This
, &IID_IBasicVideo
, (LPVOID
*)&pBasicVideo
);
3457 hr
= IBasicVideo_put_SourceWidth(pBasicVideo
, SourceWidth
);
3459 LeaveCriticalSection(&This
->cs
);
3464 static HRESULT WINAPI
BasicVideo_get_SourceWidth(IBasicVideo2
*iface
, LONG
*pSourceWidth
)
3466 IFilterGraphImpl
*This
= impl_from_IBasicVideo2(iface
);
3467 IBasicVideo
*pBasicVideo
;
3470 TRACE("(%p/%p)->(%p)\n", This
, iface
, pSourceWidth
);
3472 EnterCriticalSection(&This
->cs
);
3474 hr
= GetTargetInterface(