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"
42 #include "wine/unicode.h"
43 #include "wine/debug.h"
45 #include "transform.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
49 static const WCHAR wcsInputPinName
[] = {'i','n','p','u','t',' ','p','i','n',0};
50 static const WCHAR wcsOutputPinName
[] = {'o','u','t','p','u','t',' ','p','i','n',0};
52 static const IBaseFilterVtbl TransformFilter_Vtbl
;
53 static const IPinVtbl TransformFilter_InputPin_Vtbl
;
54 static const IMemInputPinVtbl MemInputPin_Vtbl
;
55 static const IPinVtbl TransformFilter_OutputPin_Vtbl
;
57 static HRESULT
TransformFilter_Sample(LPVOID iface
, IMediaSample
* pSample
)
59 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
61 TRACE("%p %p\n", iface
, pSample
);
63 return This
->pFuncsTable
->pfnProcessSampleData(This
, pSample
);
66 static HRESULT
TransformFilter_Input_QueryAccept(LPVOID iface
, const AM_MEDIA_TYPE
* pmt
)
68 TransformFilterImpl
* This
= (TransformFilterImpl
*)iface
;
70 dump_AM_MEDIA_TYPE(pmt
);
72 if (This
->pFuncsTable
->pfnQueryConnect
)
73 return This
->pFuncsTable
->pfnQueryConnect(This
, pmt
);
74 /* Assume OK if there's no query method (the connection will fail if
80 static HRESULT
TransformFilter_Output_QueryAccept(LPVOID iface
, const AM_MEDIA_TYPE
* pmt
)
82 TransformFilterImpl
* pTransformFilter
= (TransformFilterImpl
*)iface
;
83 AM_MEDIA_TYPE
* outpmt
= &((OutputPin
*)pTransformFilter
->ppPins
[1])->pin
.mtCurrent
;
86 if (IsEqualIID(&pmt
->majortype
, &outpmt
->majortype
) && IsEqualIID(&pmt
->subtype
, &outpmt
->subtype
))
91 static HRESULT
TransformFilter_InputPin_Construct(const PIN_INFO
* pPinInfo
, SAMPLEPROC pSampleProc
, LPVOID pUserData
, QUERYACCEPTPROC pQueryAccept
, LPCRITICAL_SECTION pCritSec
, IPin
** ppPin
)
97 if (pPinInfo
->dir
!= PINDIR_INPUT
)
99 ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo
->dir
);
103 pPinImpl
= CoTaskMemAlloc(sizeof(*pPinImpl
));
106 return E_OUTOFMEMORY
;
108 if (SUCCEEDED(InputPin_Init(pPinInfo
, pSampleProc
, pUserData
, pQueryAccept
, pCritSec
, pPinImpl
)))
110 pPinImpl
->pin
.lpVtbl
= &TransformFilter_InputPin_Vtbl
;
111 pPinImpl
->lpVtblMemInput
= &MemInputPin_Vtbl
;
113 *ppPin
= (IPin
*)(&pPinImpl
->pin
.lpVtbl
);
119 static HRESULT
TransformFilter_OutputPin_Construct(const PIN_INFO
* pPinInfo
, ALLOCATOR_PROPERTIES
*props
, LPVOID pUserData
, QUERYACCEPTPROC pQueryAccept
, LPCRITICAL_SECTION pCritSec
, IPin
** ppPin
)
121 OutputPin
* pPinImpl
;
125 if (pPinInfo
->dir
!= PINDIR_OUTPUT
)
127 ERR("Pin direction(%x) != PINDIR_OUTPUT\n", pPinInfo
->dir
);
131 pPinImpl
= CoTaskMemAlloc(sizeof(*pPinImpl
));
134 return E_OUTOFMEMORY
;
136 if (SUCCEEDED(OutputPin_Init(pPinInfo
, props
, pUserData
, pQueryAccept
, pCritSec
, pPinImpl
)))
138 pPinImpl
->pin
.lpVtbl
= &TransformFilter_OutputPin_Vtbl
;
140 *ppPin
= (IPin
*)(&pPinImpl
->pin
.lpVtbl
);
146 HRESULT
TransformFilter_Create(TransformFilterImpl
* pTransformFilter
, const CLSID
* pClsid
, const TransformFuncsTable
* pFuncsTable
)
152 /* pTransformFilter is already allocated */
153 pTransformFilter
->clsid
= *pClsid
;
154 pTransformFilter
->pFuncsTable
= pFuncsTable
;
156 pTransformFilter
->lpVtbl
= &TransformFilter_Vtbl
;
158 pTransformFilter
->refCount
= 1;
159 InitializeCriticalSection(&pTransformFilter
->csFilter
);
160 pTransformFilter
->csFilter
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": TransformFilterImpl.csFilter");
161 pTransformFilter
->state
= State_Stopped
;
162 pTransformFilter
->pClock
= NULL
;
163 ZeroMemory(&pTransformFilter
->filterInfo
, sizeof(FILTER_INFO
));
165 pTransformFilter
->ppPins
= CoTaskMemAlloc(2 * sizeof(IPin
*));
167 /* construct input pin */
168 piInput
.dir
= PINDIR_INPUT
;
169 piInput
.pFilter
= (IBaseFilter
*)pTransformFilter
;
170 lstrcpynW(piInput
.achName
, wcsInputPinName
, sizeof(piInput
.achName
) / sizeof(piInput
.achName
[0]));
171 piOutput
.dir
= PINDIR_OUTPUT
;
172 piOutput
.pFilter
= (IBaseFilter
*)pTransformFilter
;
173 lstrcpynW(piOutput
.achName
, wcsOutputPinName
, sizeof(piOutput
.achName
) / sizeof(piOutput
.achName
[0]));
175 hr
= TransformFilter_InputPin_Construct(&piInput
, TransformFilter_Sample
, pTransformFilter
, TransformFilter_Input_QueryAccept
, &pTransformFilter
->csFilter
, &pTransformFilter
->ppPins
[0]);
179 ALLOCATOR_PROPERTIES props
;
182 props
.cbBuffer
= 0; /* Will be updated at connection time */
185 hr
= TransformFilter_OutputPin_Construct(&piOutput
, &props
, pTransformFilter
, TransformFilter_Output_QueryAccept
, &pTransformFilter
->csFilter
, &pTransformFilter
->ppPins
[1]);
188 ERR("Cannot create output pin (%x)\n", hr
);
192 CoTaskMemFree(pTransformFilter
->ppPins
);
193 pTransformFilter
->csFilter
.DebugInfo
->Spare
[0] = 0;
194 DeleteCriticalSection(&pTransformFilter
->csFilter
);
195 CoTaskMemFree(pTransformFilter
);
201 static HRESULT WINAPI
TransformFilter_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
203 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
204 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
208 if (IsEqualIID(riid
, &IID_IUnknown
))
210 else if (IsEqualIID(riid
, &IID_IPersist
))
212 else if (IsEqualIID(riid
, &IID_IMediaFilter
))
214 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
219 IUnknown_AddRef((IUnknown
*)(*ppv
));
223 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
225 return E_NOINTERFACE
;
228 static ULONG WINAPI
TransformFilter_AddRef(IBaseFilter
* iface
)
230 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
231 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
233 TRACE("(%p/%p)->() AddRef from %d\n", This
, iface
, refCount
- 1);
238 static ULONG WINAPI
TransformFilter_Release(IBaseFilter
* iface
)
240 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
241 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
243 TRACE("(%p/%p)->() Release from %d\n", This
, iface
, refCount
+ 1);
250 IReferenceClock_Release(This
->pClock
);
252 for (i
= 0; i
< 2; i
++)
256 if (SUCCEEDED(IPin_ConnectedTo(This
->ppPins
[i
], &pConnectedTo
)))
258 IPin_Disconnect(pConnectedTo
);
259 IPin_Release(pConnectedTo
);
261 IPin_Disconnect(This
->ppPins
[i
]);
263 IPin_Release(This
->ppPins
[i
]);
266 CoTaskMemFree(This
->ppPins
);
269 This
->csFilter
.DebugInfo
->Spare
[0] = 0;
270 DeleteCriticalSection(&This
->csFilter
);
272 TRACE("Destroying transform filter\n");
281 /** IPersist methods **/
283 static HRESULT WINAPI
TransformFilter_GetClassID(IBaseFilter
* iface
, CLSID
* pClsid
)
285 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
287 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClsid
);
289 *pClsid
= This
->clsid
;
294 /** IMediaFilter methods **/
296 static HRESULT WINAPI
TransformFilter_Stop(IBaseFilter
* iface
)
298 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
300 TRACE("(%p/%p)\n", This
, iface
);
302 EnterCriticalSection(&This
->csFilter
);
304 This
->state
= State_Stopped
;
305 if (This
->pFuncsTable
->pfnProcessEnd
)
306 This
->pFuncsTable
->pfnProcessEnd(This
);
308 LeaveCriticalSection(&This
->csFilter
);
313 static HRESULT WINAPI
TransformFilter_Pause(IBaseFilter
* iface
)
315 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
317 TRACE("(%p/%p)->()\n", This
, iface
);
319 EnterCriticalSection(&This
->csFilter
);
321 This
->state
= State_Paused
;
323 LeaveCriticalSection(&This
->csFilter
);
328 static HRESULT WINAPI
TransformFilter_Run(IBaseFilter
* iface
, REFERENCE_TIME tStart
)
331 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
333 TRACE("(%p/%p)->(%s)\n", This
, iface
, wine_dbgstr_longlong(tStart
));
335 EnterCriticalSection(&This
->csFilter
);
337 This
->rtStreamStart
= tStart
;
338 This
->state
= State_Running
;
339 OutputPin_CommitAllocator((OutputPin
*)This
->ppPins
[1]);
340 if (This
->pFuncsTable
->pfnProcessBegin
)
341 This
->pFuncsTable
->pfnProcessBegin(This
);
343 LeaveCriticalSection(&This
->csFilter
);
348 static HRESULT WINAPI
TransformFilter_GetState(IBaseFilter
* iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
350 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
352 TRACE("(%p/%p)->(%d, %p)\n", This
, iface
, dwMilliSecsTimeout
, pState
);
354 EnterCriticalSection(&This
->csFilter
);
356 *pState
= This
->state
;
358 LeaveCriticalSection(&This
->csFilter
);
363 static HRESULT WINAPI
TransformFilter_SetSyncSource(IBaseFilter
* iface
, IReferenceClock
*pClock
)
365 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
367 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClock
);
369 EnterCriticalSection(&This
->csFilter
);
372 IReferenceClock_Release(This
->pClock
);
373 This
->pClock
= pClock
;
375 IReferenceClock_AddRef(This
->pClock
);
377 LeaveCriticalSection(&This
->csFilter
);
382 static HRESULT WINAPI
TransformFilter_GetSyncSource(IBaseFilter
* iface
, IReferenceClock
**ppClock
)
384 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
386 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppClock
);
388 EnterCriticalSection(&This
->csFilter
);
390 *ppClock
= This
->pClock
;
391 IReferenceClock_AddRef(This
->pClock
);
393 LeaveCriticalSection(&This
->csFilter
);
398 /** IBaseFilter implementation **/
400 static HRESULT WINAPI
TransformFilter_EnumPins(IBaseFilter
* iface
, IEnumPins
**ppEnum
)
403 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
405 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
407 epd
.cPins
= 2; /* input and output pins */
408 epd
.ppPins
= This
->ppPins
;
409 return IEnumPinsImpl_Construct(&epd
, ppEnum
);
412 static HRESULT WINAPI
TransformFilter_FindPin(IBaseFilter
* iface
, LPCWSTR Id
, IPin
**ppPin
)
414 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
416 TRACE("(%p/%p)->(%p,%p)\n", This
, iface
, debugstr_w(Id
), ppPin
);
421 static HRESULT WINAPI
TransformFilter_QueryFilterInfo(IBaseFilter
* iface
, FILTER_INFO
*pInfo
)
423 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
425 TRACE("(%p/%p)->(%p)\n", This
, iface
, pInfo
);
427 strcpyW(pInfo
->achName
, This
->filterInfo
.achName
);
428 pInfo
->pGraph
= This
->filterInfo
.pGraph
;
431 IFilterGraph_AddRef(pInfo
->pGraph
);
436 static HRESULT WINAPI
TransformFilter_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
439 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
441 TRACE("(%p/%p)->(%p, %s)\n", This
, iface
, pGraph
, debugstr_w(pName
));
443 EnterCriticalSection(&This
->csFilter
);
446 strcpyW(This
->filterInfo
.achName
, pName
);
448 *This
->filterInfo
.achName
= '\0';
449 This
->filterInfo
.pGraph
= pGraph
; /* NOTE: do NOT increase ref. count */
451 LeaveCriticalSection(&This
->csFilter
);
456 static HRESULT WINAPI
TransformFilter_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
458 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
459 TRACE("(%p/%p)->(%p)\n", This
, iface
, pVendorInfo
);
463 static const IBaseFilterVtbl TransformFilter_Vtbl
=
465 TransformFilter_QueryInterface
,
466 TransformFilter_AddRef
,
467 TransformFilter_Release
,
468 TransformFilter_GetClassID
,
469 TransformFilter_Stop
,
470 TransformFilter_Pause
,
472 TransformFilter_GetState
,
473 TransformFilter_SetSyncSource
,
474 TransformFilter_GetSyncSource
,
475 TransformFilter_EnumPins
,
476 TransformFilter_FindPin
,
477 TransformFilter_QueryFilterInfo
,
478 TransformFilter_JoinFilterGraph
,
479 TransformFilter_QueryVendorInfo
482 static HRESULT WINAPI
TransformFilter_InputPin_EndOfStream(IPin
* iface
)
484 InputPin
* This
= (InputPin
*) iface
;
485 TransformFilterImpl
* pTransform
;
489 TRACE("(%p)->()\n", iface
);
491 /* Since we process samples synchronously, just forward notification downstream */
492 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
496 hr
= IPin_ConnectedTo(pTransform
->ppPins
[1], &ppin
);
499 hr
= IPin_EndOfStream(ppin
);
508 static HRESULT WINAPI
TransformFilter_InputPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
510 InputPin
* This
= (InputPin
*) iface
;
511 TransformFilterImpl
* pTransform
;
514 TRACE("(%p)->(%p, %p)\n", iface
, pReceivePin
, pmt
);
516 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
518 hr
= pTransform
->pFuncsTable
->pfnConnectInput(pTransform
, pmt
);
521 hr
= InputPin_ReceiveConnection(iface
, pReceivePin
, pmt
);
523 pTransform
->pFuncsTable
->pfnCleanup(pTransform
);
529 static HRESULT WINAPI
TransformFilter_InputPin_Disconnect(IPin
* iface
)
531 InputPin
* This
= (InputPin
*) iface
;
532 TransformFilterImpl
* pTransform
;
534 TRACE("(%p)->()\n", iface
);
536 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
537 pTransform
->pFuncsTable
->pfnCleanup(pTransform
);
539 return IPinImpl_Disconnect(iface
);
542 static const IPinVtbl TransformFilter_InputPin_Vtbl
=
544 InputPin_QueryInterface
,
548 TransformFilter_InputPin_ReceiveConnection
,
549 TransformFilter_InputPin_Disconnect
,
550 IPinImpl_ConnectedTo
,
551 IPinImpl_ConnectionMediaType
,
552 IPinImpl_QueryPinInfo
,
553 IPinImpl_QueryDirection
,
555 IPinImpl_QueryAccept
,
556 IPinImpl_EnumMediaTypes
,
557 IPinImpl_QueryInternalConnections
,
558 TransformFilter_InputPin_EndOfStream
,
564 static HRESULT WINAPI
TransformFilter_Output_EnumMediaTypes(IPin
* iface
, IEnumMediaTypes
** ppEnum
)
566 IPinImpl
*This
= (IPinImpl
*)iface
;
567 ENUMMEDIADETAILS emd
;
569 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
572 emd
.pMediaTypes
= &This
->mtCurrent
;
574 return IEnumMediaTypesImpl_Construct(&emd
, ppEnum
);
577 static const IPinVtbl TransformFilter_OutputPin_Vtbl
=
579 OutputPin_QueryInterface
,
583 OutputPin_ReceiveConnection
,
584 OutputPin_Disconnect
,
585 IPinImpl_ConnectedTo
,
586 IPinImpl_ConnectionMediaType
,
587 IPinImpl_QueryPinInfo
,
588 IPinImpl_QueryDirection
,
590 IPinImpl_QueryAccept
,
591 TransformFilter_Output_EnumMediaTypes
,
592 IPinImpl_QueryInternalConnections
,
593 OutputPin_EndOfStream
,
594 OutputPin_BeginFlush
,
599 static const IMemInputPinVtbl MemInputPin_Vtbl
=
601 MemInputPin_QueryInterface
,
604 MemInputPin_GetAllocator
,
605 MemInputPin_NotifyAllocator
,
606 MemInputPin_GetAllocatorRequirements
,
608 MemInputPin_ReceiveMultiple
,
609 MemInputPin_ReceiveCanBlock