2 * Transform Filter (Base for decoders, etc...)
4 * Copyright 2005 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
23 #include "quartz_private.h"
24 #include "control_private.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 #include "transform.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
43 static const WCHAR wcsInputPinName
[] = {'i','n','p','u','t',' ','p','i','n',0};
44 static const WCHAR wcsOutputPinName
[] = {'o','u','t','p','u','t',' ','p','i','n',0};
46 static const IBaseFilterVtbl TransformFilter_Vtbl
;
47 static const IPinVtbl TransformFilter_InputPin_Vtbl
;
48 static const IMemInputPinVtbl MemInputPin_Vtbl
;
49 static const IPinVtbl TransformFilter_OutputPin_Vtbl
;
51 static HRESULT
TransformFilter_Sample(LPVOID iface
, IMediaSample
* pSample
)
53 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
55 TRACE("%p %p\n", iface
, pSample
);
57 return This
->pFuncsTable
->pfnProcessSampleData(This
, pSample
);
60 static HRESULT
TransformFilter_Input_QueryAccept(LPVOID iface
, const AM_MEDIA_TYPE
* pmt
)
62 TransformFilterImpl
* This
= (TransformFilterImpl
*)iface
;
64 dump_AM_MEDIA_TYPE(pmt
);
66 if (This
->pFuncsTable
->pfnQueryConnect
)
67 return This
->pFuncsTable
->pfnQueryConnect(This
, pmt
);
68 /* Assume OK if there's no query method (the connection will fail if
74 static HRESULT
TransformFilter_Output_QueryAccept(LPVOID iface
, const AM_MEDIA_TYPE
* pmt
)
76 TransformFilterImpl
* pTransformFilter
= (TransformFilterImpl
*)iface
;
77 AM_MEDIA_TYPE
* outpmt
= &((OutputPin
*)pTransformFilter
->ppPins
[1])->pin
.mtCurrent
;
80 if (IsEqualIID(&pmt
->majortype
, &outpmt
->majortype
) && IsEqualIID(&pmt
->subtype
, &outpmt
->subtype
))
86 static inline TransformFilterImpl
*impl_from_IMediaSeeking( IMediaSeeking
*iface
)
88 return (TransformFilterImpl
*)((char*)iface
- FIELD_OFFSET(TransformFilterImpl
, mediaSeeking
.lpVtbl
));
91 static HRESULT WINAPI
TransformFilter_Seeking_QueryInterface(IMediaSeeking
* iface
, REFIID riid
, LPVOID
* ppv
)
93 TransformFilterImpl
*This
= impl_from_IMediaSeeking(iface
);
95 return IUnknown_QueryInterface((IUnknown
*)This
, riid
, ppv
);
98 static ULONG WINAPI
TransformFilter_Seeking_AddRef(IMediaSeeking
* iface
)
100 TransformFilterImpl
*This
= impl_from_IMediaSeeking(iface
);
102 return IUnknown_AddRef((IUnknown
*)This
);
105 static ULONG WINAPI
TransformFilter_Seeking_Release(IMediaSeeking
* iface
)
107 TransformFilterImpl
*This
= impl_from_IMediaSeeking(iface
);
109 return IUnknown_Release((IUnknown
*)This
);
112 static const IMediaSeekingVtbl TransformFilter_Seeking_Vtbl
=
114 TransformFilter_Seeking_QueryInterface
,
115 TransformFilter_Seeking_AddRef
,
116 TransformFilter_Seeking_Release
,
117 MediaSeekingImpl_GetCapabilities
,
118 MediaSeekingImpl_CheckCapabilities
,
119 MediaSeekingImpl_IsFormatSupported
,
120 MediaSeekingImpl_QueryPreferredFormat
,
121 MediaSeekingImpl_GetTimeFormat
,
122 MediaSeekingImpl_IsUsingTimeFormat
,
123 MediaSeekingImpl_SetTimeFormat
,
124 MediaSeekingImpl_GetDuration
,
125 MediaSeekingImpl_GetStopPosition
,
126 MediaSeekingImpl_GetCurrentPosition
,
127 MediaSeekingImpl_ConvertTimeFormat
,
128 MediaSeekingImpl_SetPositions
,
129 MediaSeekingImpl_GetPositions
,
130 MediaSeekingImpl_GetAvailable
,
131 MediaSeekingImpl_SetRate
,
132 MediaSeekingImpl_GetRate
,
133 MediaSeekingImpl_GetPreroll
136 static HRESULT
TransformFilter_ChangeCurrent(IBaseFilter
*iface
)
138 FIXME("(%p) filter hasn't implemented current position change!\n", iface
);
142 static HRESULT
TransformFilter_ChangeStop(IBaseFilter
*iface
)
144 FIXME("(%p) filter hasn't implemented stop position change!\n", iface
);
148 static HRESULT
TransformFilter_ChangeRate(IBaseFilter
*iface
)
150 FIXME("(%p) filter hasn't implemented rate change!\n", iface
);
154 HRESULT
TransformFilter_Create(TransformFilterImpl
* pTransformFilter
, const CLSID
* pClsid
, const TransformFuncsTable
* pFuncsTable
, CHANGEPROC stop
, CHANGEPROC current
, CHANGEPROC rate
)
160 /* pTransformFilter is already allocated */
161 pTransformFilter
->clsid
= *pClsid
;
162 pTransformFilter
->pFuncsTable
= pFuncsTable
;
164 pTransformFilter
->lpVtbl
= &TransformFilter_Vtbl
;
166 pTransformFilter
->refCount
= 1;
167 InitializeCriticalSection(&pTransformFilter
->csFilter
);
168 pTransformFilter
->csFilter
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": TransformFilterImpl.csFilter");
169 pTransformFilter
->state
= State_Stopped
;
170 pTransformFilter
->pClock
= NULL
;
171 ZeroMemory(&pTransformFilter
->filterInfo
, sizeof(FILTER_INFO
));
173 pTransformFilter
->ppPins
= CoTaskMemAlloc(2 * sizeof(IPin
*));
175 /* construct input pin */
176 piInput
.dir
= PINDIR_INPUT
;
177 piInput
.pFilter
= (IBaseFilter
*)pTransformFilter
;
178 lstrcpynW(piInput
.achName
, wcsInputPinName
, sizeof(piInput
.achName
) / sizeof(piInput
.achName
[0]));
179 piOutput
.dir
= PINDIR_OUTPUT
;
180 piOutput
.pFilter
= (IBaseFilter
*)pTransformFilter
;
181 lstrcpynW(piOutput
.achName
, wcsOutputPinName
, sizeof(piOutput
.achName
) / sizeof(piOutput
.achName
[0]));
183 hr
= InputPin_Construct(&TransformFilter_InputPin_Vtbl
, &piInput
, TransformFilter_Sample
, pTransformFilter
, TransformFilter_Input_QueryAccept
, NULL
, &pTransformFilter
->csFilter
, &pTransformFilter
->ppPins
[0]);
187 ALLOCATOR_PROPERTIES props
;
190 props
.cbBuffer
= 0; /* Will be updated at connection time */
193 hr
= OutputPin_Construct(&TransformFilter_OutputPin_Vtbl
, sizeof(OutputPin
), &piOutput
, &props
, pTransformFilter
, TransformFilter_Output_QueryAccept
, &pTransformFilter
->csFilter
, &pTransformFilter
->ppPins
[1]);
196 ERR("Cannot create output pin (%x)\n", hr
);
200 stop
= TransformFilter_ChangeStop
;
202 current
= TransformFilter_ChangeCurrent
;
204 rate
= TransformFilter_ChangeRate
;
206 MediaSeekingImpl_Init((IBaseFilter
*)pTransformFilter
, stop
, current
, rate
, &pTransformFilter
->mediaSeeking
, &pTransformFilter
->csFilter
);
207 pTransformFilter
->mediaSeeking
.lpVtbl
= &TransformFilter_Seeking_Vtbl
;
212 CoTaskMemFree(pTransformFilter
->ppPins
);
213 pTransformFilter
->csFilter
.DebugInfo
->Spare
[0] = 0;
214 DeleteCriticalSection(&pTransformFilter
->csFilter
);
215 CoTaskMemFree(pTransformFilter
);
221 static HRESULT WINAPI
TransformFilter_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
223 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
224 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
228 if (IsEqualIID(riid
, &IID_IUnknown
))
230 else if (IsEqualIID(riid
, &IID_IPersist
))
232 else if (IsEqualIID(riid
, &IID_IMediaFilter
))
234 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
236 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
237 *ppv
= &This
->mediaSeeking
;
241 IUnknown_AddRef((IUnknown
*)(*ppv
));
245 if (!IsEqualIID(riid
, &IID_IPin
))
246 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
248 return E_NOINTERFACE
;
251 static ULONG WINAPI
TransformFilter_AddRef(IBaseFilter
* iface
)
253 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
254 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
256 TRACE("(%p/%p)->() AddRef from %d\n", This
, iface
, refCount
- 1);
261 static ULONG WINAPI
TransformFilter_Release(IBaseFilter
* iface
)
263 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
264 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
266 TRACE("(%p/%p)->() Release from %d\n", This
, iface
, refCount
+ 1);
273 IReferenceClock_Release(This
->pClock
);
275 for (i
= 0; i
< 2; i
++)
279 if (SUCCEEDED(IPin_ConnectedTo(This
->ppPins
[i
], &pConnectedTo
)))
281 IPin_Disconnect(pConnectedTo
);
282 IPin_Release(pConnectedTo
);
284 IPin_Disconnect(This
->ppPins
[i
]);
286 IPin_Release(This
->ppPins
[i
]);
289 CoTaskMemFree(This
->ppPins
);
292 This
->csFilter
.DebugInfo
->Spare
[0] = 0;
293 DeleteCriticalSection(&This
->csFilter
);
295 TRACE("Destroying transform filter\n");
304 /** IPersist methods **/
306 static HRESULT WINAPI
TransformFilter_GetClassID(IBaseFilter
* iface
, CLSID
* pClsid
)
308 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
310 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClsid
);
312 *pClsid
= This
->clsid
;
317 /** IMediaFilter methods **/
319 static HRESULT WINAPI
TransformFilter_Stop(IBaseFilter
* iface
)
321 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
323 TRACE("(%p/%p)\n", This
, iface
);
325 EnterCriticalSection(&This
->csFilter
);
327 This
->state
= State_Stopped
;
328 if (This
->pFuncsTable
->pfnProcessEnd
)
329 This
->pFuncsTable
->pfnProcessEnd(This
);
331 LeaveCriticalSection(&This
->csFilter
);
336 static HRESULT WINAPI
TransformFilter_Pause(IBaseFilter
* iface
)
338 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
340 TRACE("(%p/%p)->()\n", This
, iface
);
342 EnterCriticalSection(&This
->csFilter
);
344 This
->state
= State_Paused
;
346 LeaveCriticalSection(&This
->csFilter
);
351 static HRESULT WINAPI
TransformFilter_Run(IBaseFilter
* iface
, REFERENCE_TIME tStart
)
354 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
356 TRACE("(%p/%p)->(%s)\n", This
, iface
, wine_dbgstr_longlong(tStart
));
358 EnterCriticalSection(&This
->csFilter
);
360 This
->rtStreamStart
= tStart
;
361 This
->state
= State_Running
;
362 OutputPin_CommitAllocator((OutputPin
*)This
->ppPins
[1]);
363 if (This
->pFuncsTable
->pfnProcessBegin
)
364 This
->pFuncsTable
->pfnProcessBegin(This
);
366 LeaveCriticalSection(&This
->csFilter
);
371 static HRESULT WINAPI
TransformFilter_GetState(IBaseFilter
* iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
373 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
375 TRACE("(%p/%p)->(%d, %p)\n", This
, iface
, dwMilliSecsTimeout
, pState
);
377 EnterCriticalSection(&This
->csFilter
);
379 *pState
= This
->state
;
381 LeaveCriticalSection(&This
->csFilter
);
386 static HRESULT WINAPI
TransformFilter_SetSyncSource(IBaseFilter
* iface
, IReferenceClock
*pClock
)
388 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
390 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClock
);
392 EnterCriticalSection(&This
->csFilter
);
395 IReferenceClock_Release(This
->pClock
);
396 This
->pClock
= pClock
;
398 IReferenceClock_AddRef(This
->pClock
);
400 LeaveCriticalSection(&This
->csFilter
);
405 static HRESULT WINAPI
TransformFilter_GetSyncSource(IBaseFilter
* iface
, IReferenceClock
**ppClock
)
407 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
409 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppClock
);
411 EnterCriticalSection(&This
->csFilter
);
413 *ppClock
= This
->pClock
;
414 IReferenceClock_AddRef(This
->pClock
);
416 LeaveCriticalSection(&This
->csFilter
);
421 /** IBaseFilter implementation **/
423 static HRESULT WINAPI
TransformFilter_EnumPins(IBaseFilter
* iface
, IEnumPins
**ppEnum
)
426 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
428 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
430 epd
.cPins
= 2; /* input and output pins */
431 epd
.ppPins
= This
->ppPins
;
432 return IEnumPinsImpl_Construct(&epd
, ppEnum
);
435 static HRESULT WINAPI
TransformFilter_FindPin(IBaseFilter
* iface
, LPCWSTR Id
, IPin
**ppPin
)
437 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
439 TRACE("(%p/%p)->(%p,%p)\n", This
, iface
, debugstr_w(Id
), ppPin
);
444 static HRESULT WINAPI
TransformFilter_QueryFilterInfo(IBaseFilter
* iface
, FILTER_INFO
*pInfo
)
446 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
448 TRACE("(%p/%p)->(%p)\n", This
, iface
, pInfo
);
450 strcpyW(pInfo
->achName
, This
->filterInfo
.achName
);
451 pInfo
->pGraph
= This
->filterInfo
.pGraph
;
454 IFilterGraph_AddRef(pInfo
->pGraph
);
459 static HRESULT WINAPI
TransformFilter_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
462 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
464 TRACE("(%p/%p)->(%p, %s)\n", This
, iface
, pGraph
, debugstr_w(pName
));
466 EnterCriticalSection(&This
->csFilter
);
469 strcpyW(This
->filterInfo
.achName
, pName
);
471 *This
->filterInfo
.achName
= '\0';
472 This
->filterInfo
.pGraph
= pGraph
; /* NOTE: do NOT increase ref. count */
474 LeaveCriticalSection(&This
->csFilter
);
479 static HRESULT WINAPI
TransformFilter_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
481 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
482 TRACE("(%p/%p)->(%p)\n", This
, iface
, pVendorInfo
);
486 static const IBaseFilterVtbl TransformFilter_Vtbl
=
488 TransformFilter_QueryInterface
,
489 TransformFilter_AddRef
,
490 TransformFilter_Release
,
491 TransformFilter_GetClassID
,
492 TransformFilter_Stop
,
493 TransformFilter_Pause
,
495 TransformFilter_GetState
,
496 TransformFilter_SetSyncSource
,
497 TransformFilter_GetSyncSource
,
498 TransformFilter_EnumPins
,
499 TransformFilter_FindPin
,
500 TransformFilter_QueryFilterInfo
,
501 TransformFilter_JoinFilterGraph
,
502 TransformFilter_QueryVendorInfo
505 static HRESULT WINAPI
TransformFilter_InputPin_EndOfStream(IPin
* iface
)
507 InputPin
* This
= (InputPin
*) iface
;
508 TransformFilterImpl
* pTransform
;
512 TRACE("(%p)->()\n", iface
);
514 /* Since we process samples synchronously, just forward notification downstream */
515 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
519 hr
= IPin_ConnectedTo(pTransform
->ppPins
[1], &ppin
);
522 hr
= IPin_EndOfStream(ppin
);
531 static HRESULT WINAPI
TransformFilter_InputPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
533 InputPin
* This
= (InputPin
*) iface
;
534 TransformFilterImpl
* pTransform
;
537 TRACE("(%p)->(%p, %p)\n", iface
, pReceivePin
, pmt
);
539 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
541 hr
= pTransform
->pFuncsTable
->pfnConnectInput(pTransform
, pmt
);
544 hr
= InputPin_ReceiveConnection(iface
, pReceivePin
, pmt
);
546 pTransform
->pFuncsTable
->pfnCleanup(pTransform
);
552 static HRESULT WINAPI
TransformFilter_InputPin_Disconnect(IPin
* iface
)
554 InputPin
* This
= (InputPin
*) iface
;
555 TransformFilterImpl
* pTransform
;
557 TRACE("(%p)->()\n", iface
);
559 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
560 pTransform
->pFuncsTable
->pfnCleanup(pTransform
);
562 return IPinImpl_Disconnect(iface
);
565 static const IPinVtbl TransformFilter_InputPin_Vtbl
=
567 InputPin_QueryInterface
,
571 TransformFilter_InputPin_ReceiveConnection
,
572 TransformFilter_InputPin_Disconnect
,
573 IPinImpl_ConnectedTo
,
574 IPinImpl_ConnectionMediaType
,
575 IPinImpl_QueryPinInfo
,
576 IPinImpl_QueryDirection
,
578 IPinImpl_QueryAccept
,
579 IPinImpl_EnumMediaTypes
,
580 IPinImpl_QueryInternalConnections
,
581 TransformFilter_InputPin_EndOfStream
,
587 static HRESULT WINAPI
TransformFilter_Output_EnumMediaTypes(IPin
* iface
, IEnumMediaTypes
** ppEnum
)
589 IPinImpl
*This
= (IPinImpl
*)iface
;
590 ENUMMEDIADETAILS emd
;
592 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
595 emd
.pMediaTypes
= &This
->mtCurrent
;
597 return IEnumMediaTypesImpl_Construct(&emd
, ppEnum
);
600 static const IPinVtbl TransformFilter_OutputPin_Vtbl
=
602 OutputPin_QueryInterface
,
606 OutputPin_ReceiveConnection
,
607 OutputPin_Disconnect
,
608 IPinImpl_ConnectedTo
,
609 IPinImpl_ConnectionMediaType
,
610 IPinImpl_QueryPinInfo
,
611 IPinImpl_QueryDirection
,
613 IPinImpl_QueryAccept
,
614 TransformFilter_Output_EnumMediaTypes
,
615 IPinImpl_QueryInternalConnections
,
616 OutputPin_EndOfStream
,
617 OutputPin_BeginFlush
,
622 static const IMemInputPinVtbl MemInputPin_Vtbl
=
624 MemInputPin_QueryInterface
,
627 MemInputPin_GetAllocator
,
628 MemInputPin_NotifyAllocator
,
629 MemInputPin_GetAllocatorRequirements
,
631 MemInputPin_ReceiveMultiple
,
632 MemInputPin_ReceiveCanBlock