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 IPinVtbl TransformFilter_OutputPin_Vtbl
;
50 static HRESULT
TransformFilter_Input_QueryAccept(LPVOID iface
, const AM_MEDIA_TYPE
* pmt
)
52 TransformFilterImpl
* This
= (TransformFilterImpl
*)((IPinImpl
*)iface
)->pinInfo
.pFilter
;
54 dump_AM_MEDIA_TYPE(pmt
);
56 if (This
->pFuncsTable
->pfnQueryConnect
)
57 return This
->pFuncsTable
->pfnQueryConnect(This
, pmt
);
58 /* Assume OK if there's no query method (the connection will fail if
64 static HRESULT
TransformFilter_Output_QueryAccept(LPVOID iface
, const AM_MEDIA_TYPE
* pmt
)
66 TransformFilterImpl
* pTransformFilter
= iface
;
67 AM_MEDIA_TYPE
* outpmt
= &pTransformFilter
->pmt
;
70 if (IsEqualIID(&pmt
->majortype
, &outpmt
->majortype
)
71 && (IsEqualIID(&pmt
->subtype
, &outpmt
->subtype
) || IsEqualIID(&outpmt
->subtype
, &GUID_NULL
)))
77 static inline TransformFilterImpl
*impl_from_IMediaSeeking( IMediaSeeking
*iface
)
79 return (TransformFilterImpl
*)((char*)iface
- FIELD_OFFSET(TransformFilterImpl
, mediaSeeking
.lpVtbl
));
82 static HRESULT WINAPI
TransformFilter_Seeking_QueryInterface(IMediaSeeking
* iface
, REFIID riid
, LPVOID
* ppv
)
84 TransformFilterImpl
*This
= impl_from_IMediaSeeking(iface
);
86 return IUnknown_QueryInterface((IUnknown
*)This
, riid
, ppv
);
89 static ULONG WINAPI
TransformFilter_Seeking_AddRef(IMediaSeeking
* iface
)
91 TransformFilterImpl
*This
= impl_from_IMediaSeeking(iface
);
93 return IUnknown_AddRef((IUnknown
*)This
);
96 static ULONG WINAPI
TransformFilter_Seeking_Release(IMediaSeeking
* iface
)
98 TransformFilterImpl
*This
= impl_from_IMediaSeeking(iface
);
100 return IUnknown_Release((IUnknown
*)This
);
103 static const IMediaSeekingVtbl TransformFilter_Seeking_Vtbl
=
105 TransformFilter_Seeking_QueryInterface
,
106 TransformFilter_Seeking_AddRef
,
107 TransformFilter_Seeking_Release
,
108 MediaSeekingImpl_GetCapabilities
,
109 MediaSeekingImpl_CheckCapabilities
,
110 MediaSeekingImpl_IsFormatSupported
,
111 MediaSeekingImpl_QueryPreferredFormat
,
112 MediaSeekingImpl_GetTimeFormat
,
113 MediaSeekingImpl_IsUsingTimeFormat
,
114 MediaSeekingImpl_SetTimeFormat
,
115 MediaSeekingImpl_GetDuration
,
116 MediaSeekingImpl_GetStopPosition
,
117 MediaSeekingImpl_GetCurrentPosition
,
118 MediaSeekingImpl_ConvertTimeFormat
,
119 MediaSeekingImpl_SetPositions
,
120 MediaSeekingImpl_GetPositions
,
121 MediaSeekingImpl_GetAvailable
,
122 MediaSeekingImpl_SetRate
,
123 MediaSeekingImpl_GetRate
,
124 MediaSeekingImpl_GetPreroll
127 /* These shouldn't be implemented by default.
128 * Usually only source filters should implement these
129 * and even it's not needed all of the time
131 static HRESULT
TransformFilter_ChangeCurrent(IBaseFilter
*iface
)
133 TRACE("(%p) filter hasn't implemented current position change!\n", iface
);
137 static HRESULT
TransformFilter_ChangeStop(IBaseFilter
*iface
)
139 TRACE("(%p) filter hasn't implemented stop position change!\n", iface
);
143 static HRESULT
TransformFilter_ChangeRate(IBaseFilter
*iface
)
145 TRACE("(%p) filter hasn't implemented rate change!\n", iface
);
149 HRESULT
TransformFilter_Create(TransformFilterImpl
* pTransformFilter
, const CLSID
* pClsid
, const TransformFuncsTable
* pFuncsTable
, CHANGEPROC stop
, CHANGEPROC current
, CHANGEPROC rate
)
155 /* pTransformFilter is already allocated */
156 pTransformFilter
->clsid
= *pClsid
;
157 pTransformFilter
->pFuncsTable
= pFuncsTable
;
159 pTransformFilter
->lpVtbl
= &TransformFilter_Vtbl
;
161 pTransformFilter
->refCount
= 1;
162 InitializeCriticalSection(&pTransformFilter
->csFilter
);
163 pTransformFilter
->csFilter
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": TransformFilterImpl.csFilter");
164 pTransformFilter
->state
= State_Stopped
;
165 pTransformFilter
->pClock
= NULL
;
166 ZeroMemory(&pTransformFilter
->filterInfo
, sizeof(FILTER_INFO
));
167 ZeroMemory(&pTransformFilter
->pmt
, sizeof(pTransformFilter
->pmt
));
168 pTransformFilter
->npins
= 2;
170 pTransformFilter
->ppPins
= CoTaskMemAlloc(2 * sizeof(IPin
*));
172 /* construct input pin */
173 piInput
.dir
= PINDIR_INPUT
;
174 piInput
.pFilter
= (IBaseFilter
*)pTransformFilter
;
175 lstrcpynW(piInput
.achName
, wcsInputPinName
, sizeof(piInput
.achName
) / sizeof(piInput
.achName
[0]));
176 piOutput
.dir
= PINDIR_OUTPUT
;
177 piOutput
.pFilter
= (IBaseFilter
*)pTransformFilter
;
178 lstrcpynW(piOutput
.achName
, wcsOutputPinName
, sizeof(piOutput
.achName
) / sizeof(piOutput
.achName
[0]));
180 hr
= InputPin_Construct(&TransformFilter_InputPin_Vtbl
, &piInput
, (SAMPLEPROC_PUSH
)pFuncsTable
->pfnProcessSampleData
, NULL
, TransformFilter_Input_QueryAccept
, NULL
, &pTransformFilter
->csFilter
, NULL
, &pTransformFilter
->ppPins
[0]);
184 ALLOCATOR_PROPERTIES props
;
187 props
.cbBuffer
= 0; /* Will be updated at connection time */
190 ((InputPin
*)pTransformFilter
->ppPins
[0])->pin
.pUserData
= pTransformFilter
->ppPins
[0];
192 hr
= OutputPin_Construct(&TransformFilter_OutputPin_Vtbl
, sizeof(OutputPin
), &piOutput
, &props
, pTransformFilter
, TransformFilter_Output_QueryAccept
, &pTransformFilter
->csFilter
, &pTransformFilter
->ppPins
[1]);
195 ERR("Cannot create output pin (%x)\n", hr
);
199 stop
= TransformFilter_ChangeStop
;
201 current
= TransformFilter_ChangeCurrent
;
203 rate
= TransformFilter_ChangeRate
;
205 MediaSeekingImpl_Init((IBaseFilter
*)pTransformFilter
, stop
, current
, rate
, &pTransformFilter
->mediaSeeking
, &pTransformFilter
->csFilter
);
206 pTransformFilter
->mediaSeeking
.lpVtbl
= &TransformFilter_Seeking_Vtbl
;
211 CoTaskMemFree(pTransformFilter
->ppPins
);
212 pTransformFilter
->csFilter
.DebugInfo
->Spare
[0] = 0;
213 DeleteCriticalSection(&pTransformFilter
->csFilter
);
214 CoTaskMemFree(pTransformFilter
);
220 static HRESULT WINAPI
TransformFilter_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
222 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
223 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
227 if (IsEqualIID(riid
, &IID_IUnknown
))
229 else if (IsEqualIID(riid
, &IID_IPersist
))
231 else if (IsEqualIID(riid
, &IID_IMediaFilter
))
233 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
235 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
236 *ppv
= &This
->mediaSeeking
;
240 IUnknown_AddRef((IUnknown
*)(*ppv
));
244 if (!IsEqualIID(riid
, &IID_IPin
) && !IsEqualIID(riid
, &IID_IVideoWindow
))
245 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
247 return E_NOINTERFACE
;
250 static ULONG WINAPI
TransformFilter_AddRef(IBaseFilter
* iface
)
252 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
253 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
255 TRACE("(%p/%p)->() AddRef from %d\n", This
, iface
, refCount
- 1);
260 static ULONG WINAPI
TransformFilter_Release(IBaseFilter
* iface
)
262 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
263 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
265 TRACE("(%p/%p)->() Release from %d\n", This
, iface
, refCount
+ 1);
272 IReferenceClock_Release(This
->pClock
);
274 for (i
= 0; i
< This
->npins
; i
++)
278 if (SUCCEEDED(IPin_ConnectedTo(This
->ppPins
[i
], &pConnectedTo
)))
280 IPin_Disconnect(pConnectedTo
);
281 IPin_Release(pConnectedTo
);
283 IPin_Disconnect(This
->ppPins
[i
]);
285 IPin_Release(This
->ppPins
[i
]);
288 CoTaskMemFree(This
->ppPins
);
291 This
->csFilter
.DebugInfo
->Spare
[0] = 0;
292 DeleteCriticalSection(&This
->csFilter
);
294 TRACE("Destroying transform filter\n");
295 FreeMediaType(&This
->pmt
);
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
;
324 TRACE("(%p/%p)\n", This
, iface
);
326 EnterCriticalSection(&This
->csFilter
);
328 This
->state
= State_Stopped
;
329 if (This
->pFuncsTable
->pfnProcessEnd
)
330 hr
= This
->pFuncsTable
->pfnProcessEnd(This
);
332 LeaveCriticalSection(&This
->csFilter
);
337 static HRESULT WINAPI
TransformFilter_Pause(IBaseFilter
* iface
)
339 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
342 TRACE("(%p/%p)->()\n", This
, iface
);
344 EnterCriticalSection(&This
->csFilter
);
346 if (This
->state
== State_Stopped
)
347 hr
= IBaseFilter_Run(iface
, -1);
352 This
->state
= State_Paused
;
354 LeaveCriticalSection(&This
->csFilter
);
359 static HRESULT WINAPI
TransformFilter_Run(IBaseFilter
* iface
, REFERENCE_TIME tStart
)
362 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
364 TRACE("(%p/%p)->(%s)\n", This
, iface
, wine_dbgstr_longlong(tStart
));
366 EnterCriticalSection(&This
->csFilter
);
368 if (This
->state
== State_Stopped
)
370 ((InputPin
*)This
->ppPins
[0])->end_of_stream
= 0;
371 if (This
->pFuncsTable
->pfnProcessBegin
)
372 hr
= This
->pFuncsTable
->pfnProcessBegin(This
);
374 hr
= OutputPin_CommitAllocator((OutputPin
*)This
->ppPins
[1]);
379 This
->rtStreamStart
= tStart
;
380 This
->state
= State_Running
;
383 LeaveCriticalSection(&This
->csFilter
);
388 static HRESULT WINAPI
TransformFilter_GetState(IBaseFilter
* iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
390 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
392 TRACE("(%p/%p)->(%d, %p)\n", This
, iface
, dwMilliSecsTimeout
, pState
);
394 EnterCriticalSection(&This
->csFilter
);
396 *pState
= This
->state
;
398 LeaveCriticalSection(&This
->csFilter
);
403 static HRESULT WINAPI
TransformFilter_SetSyncSource(IBaseFilter
* iface
, IReferenceClock
*pClock
)
405 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
407 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClock
);
409 EnterCriticalSection(&This
->csFilter
);
412 IReferenceClock_Release(This
->pClock
);
413 This
->pClock
= pClock
;
415 IReferenceClock_AddRef(This
->pClock
);
417 LeaveCriticalSection(&This
->csFilter
);
422 static HRESULT WINAPI
TransformFilter_GetSyncSource(IBaseFilter
* iface
, IReferenceClock
**ppClock
)
424 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
426 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppClock
);
428 EnterCriticalSection(&This
->csFilter
);
430 *ppClock
= This
->pClock
;
432 IReferenceClock_AddRef(This
->pClock
);
434 LeaveCriticalSection(&This
->csFilter
);
439 /** IBaseFilter implementation **/
441 static HRESULT
TransformFilter_GetPin(IBaseFilter
*iface
, ULONG pos
, IPin
**pin
, DWORD
*lastsynctick
)
443 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
445 /* Our pins are static, not changing so setting static tick count is ok */
448 if (pos
>= This
->npins
)
451 *pin
= This
->ppPins
[pos
];
456 static HRESULT WINAPI
TransformFilter_EnumPins(IBaseFilter
* iface
, IEnumPins
**ppEnum
)
458 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
460 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
462 return IEnumPinsImpl_Construct(ppEnum
, TransformFilter_GetPin
, iface
);
465 static HRESULT WINAPI
TransformFilter_FindPin(IBaseFilter
* iface
, LPCWSTR Id
, IPin
**ppPin
)
467 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
469 TRACE("(%p/%p)->(%p,%p)\n", This
, iface
, debugstr_w(Id
), ppPin
);
474 static HRESULT WINAPI
TransformFilter_QueryFilterInfo(IBaseFilter
* iface
, FILTER_INFO
*pInfo
)
476 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
478 TRACE("(%p/%p)->(%p)\n", This
, iface
, pInfo
);
480 strcpyW(pInfo
->achName
, This
->filterInfo
.achName
);
481 pInfo
->pGraph
= This
->filterInfo
.pGraph
;
484 IFilterGraph_AddRef(pInfo
->pGraph
);
489 static HRESULT WINAPI
TransformFilter_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
492 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
494 TRACE("(%p/%p)->(%p, %s)\n", This
, iface
, pGraph
, debugstr_w(pName
));
496 EnterCriticalSection(&This
->csFilter
);
499 strcpyW(This
->filterInfo
.achName
, pName
);
501 *This
->filterInfo
.achName
= '\0';
502 This
->filterInfo
.pGraph
= pGraph
; /* NOTE: do NOT increase ref. count */
504 LeaveCriticalSection(&This
->csFilter
);
509 static HRESULT WINAPI
TransformFilter_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
511 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
512 TRACE("(%p/%p)->(%p)\n", This
, iface
, pVendorInfo
);
516 static const IBaseFilterVtbl TransformFilter_Vtbl
=
518 TransformFilter_QueryInterface
,
519 TransformFilter_AddRef
,
520 TransformFilter_Release
,
521 TransformFilter_GetClassID
,
522 TransformFilter_Stop
,
523 TransformFilter_Pause
,
525 TransformFilter_GetState
,
526 TransformFilter_SetSyncSource
,
527 TransformFilter_GetSyncSource
,
528 TransformFilter_EnumPins
,
529 TransformFilter_FindPin
,
530 TransformFilter_QueryFilterInfo
,
531 TransformFilter_JoinFilterGraph
,
532 TransformFilter_QueryVendorInfo
535 static HRESULT WINAPI
TransformFilter_InputPin_EndOfStream(IPin
* iface
)
537 InputPin
* This
= (InputPin
*) iface
;
538 TransformFilterImpl
* pTransform
;
542 TRACE("(%p)->()\n", iface
);
544 /* Since we process samples synchronously, just forward notification downstream */
545 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
549 hr
= IPin_ConnectedTo(pTransform
->ppPins
[1], &ppin
);
552 hr
= IPin_EndOfStream(ppin
);
561 static HRESULT WINAPI
TransformFilter_InputPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
563 InputPin
* This
= (InputPin
*) iface
;
564 TransformFilterImpl
* pTransform
;
567 TRACE("(%p)->(%p, %p)\n", iface
, pReceivePin
, pmt
);
569 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
571 hr
= pTransform
->pFuncsTable
->pfnConnectInput(This
, pmt
);
574 hr
= InputPin_ReceiveConnection(iface
, pReceivePin
, pmt
);
576 pTransform
->pFuncsTable
->pfnCleanup(This
);
582 static HRESULT WINAPI
TransformFilter_InputPin_Disconnect(IPin
* iface
)
584 InputPin
* This
= (InputPin
*) iface
;
585 TransformFilterImpl
* pTransform
;
587 TRACE("(%p)->()\n", iface
);
589 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
590 pTransform
->pFuncsTable
->pfnCleanup(This
);
592 return IPinImpl_Disconnect(iface
);
595 static const IPinVtbl TransformFilter_InputPin_Vtbl
=
597 InputPin_QueryInterface
,
601 TransformFilter_InputPin_ReceiveConnection
,
602 TransformFilter_InputPin_Disconnect
,
603 IPinImpl_ConnectedTo
,
604 IPinImpl_ConnectionMediaType
,
605 IPinImpl_QueryPinInfo
,
606 IPinImpl_QueryDirection
,
608 IPinImpl_QueryAccept
,
609 IPinImpl_EnumMediaTypes
,
610 IPinImpl_QueryInternalConnections
,
611 TransformFilter_InputPin_EndOfStream
,
617 static HRESULT WINAPI
TransformFilter_Output_EnumMediaTypes(IPin
* iface
, IEnumMediaTypes
** ppEnum
)
619 IPinImpl
*This
= (IPinImpl
*)iface
;
620 TransformFilterImpl
*pTransform
= (TransformFilterImpl
*)This
->pinInfo
.pFilter
;
621 ENUMMEDIADETAILS emd
;
623 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
626 emd
.pMediaTypes
= &pTransform
->pmt
;
628 return IEnumMediaTypesImpl_Construct(&emd
, ppEnum
);
631 static const IPinVtbl TransformFilter_OutputPin_Vtbl
=
633 OutputPin_QueryInterface
,
637 OutputPin_ReceiveConnection
,
638 OutputPin_Disconnect
,
639 IPinImpl_ConnectedTo
,
640 IPinImpl_ConnectionMediaType
,
641 IPinImpl_QueryPinInfo
,
642 IPinImpl_QueryDirection
,
644 IPinImpl_QueryAccept
,
645 TransformFilter_Output_EnumMediaTypes
,
646 IPinImpl_QueryInternalConnections
,
647 OutputPin_EndOfStream
,
648 OutputPin_BeginFlush
,