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
)))
76 HRESULT
TransformFilter_Create(TransformFilterImpl
* pTransformFilter
, const CLSID
* pClsid
, const TransformFuncsTable
* pFuncsTable
)
82 /* pTransformFilter is already allocated */
83 pTransformFilter
->clsid
= *pClsid
;
84 pTransformFilter
->pFuncsTable
= pFuncsTable
;
86 pTransformFilter
->lpVtbl
= &TransformFilter_Vtbl
;
88 pTransformFilter
->refCount
= 1;
89 InitializeCriticalSection(&pTransformFilter
->csFilter
);
90 pTransformFilter
->csFilter
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": TransformFilterImpl.csFilter");
91 pTransformFilter
->state
= State_Stopped
;
92 pTransformFilter
->pClock
= NULL
;
93 ZeroMemory(&pTransformFilter
->filterInfo
, sizeof(FILTER_INFO
));
94 ZeroMemory(&pTransformFilter
->pmt
, sizeof(pTransformFilter
->pmt
));
95 pTransformFilter
->npins
= 2;
97 pTransformFilter
->ppPins
= CoTaskMemAlloc(2 * sizeof(IPin
*));
99 /* construct input pin */
100 piInput
.dir
= PINDIR_INPUT
;
101 piInput
.pFilter
= (IBaseFilter
*)pTransformFilter
;
102 lstrcpynW(piInput
.achName
, wcsInputPinName
, sizeof(piInput
.achName
) / sizeof(piInput
.achName
[0]));
103 piOutput
.dir
= PINDIR_OUTPUT
;
104 piOutput
.pFilter
= (IBaseFilter
*)pTransformFilter
;
105 lstrcpynW(piOutput
.achName
, wcsOutputPinName
, sizeof(piOutput
.achName
) / sizeof(piOutput
.achName
[0]));
107 hr
= InputPin_Construct(&TransformFilter_InputPin_Vtbl
, &piInput
, (SAMPLEPROC_PUSH
)pFuncsTable
->pfnProcessSampleData
, NULL
, TransformFilter_Input_QueryAccept
, NULL
, &pTransformFilter
->csFilter
, NULL
, &pTransformFilter
->ppPins
[0]);
111 ALLOCATOR_PROPERTIES props
;
114 props
.cbBuffer
= 0; /* Will be updated at connection time */
117 ((InputPin
*)pTransformFilter
->ppPins
[0])->pin
.pUserData
= pTransformFilter
->ppPins
[0];
119 hr
= OutputPin_Construct(&TransformFilter_OutputPin_Vtbl
, sizeof(OutputPin
), &piOutput
, &props
, pTransformFilter
, TransformFilter_Output_QueryAccept
, &pTransformFilter
->csFilter
, &pTransformFilter
->ppPins
[1]);
122 ERR("Cannot create output pin (%x)\n", hr
);
125 ISeekingPassThru
*passthru
;
126 hr
= CoCreateInstance(&CLSID_SeekingPassThru
, (IUnknown
*)pTransformFilter
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void**)&pTransformFilter
->seekthru_unk
);
127 IUnknown_QueryInterface(pTransformFilter
->seekthru_unk
, &IID_ISeekingPassThru
, (void**)&passthru
);
128 ISeekingPassThru_Init(passthru
, FALSE
, (IPin
*)pTransformFilter
->ppPins
[0]);
129 ISeekingPassThru_Release(passthru
);
134 CoTaskMemFree(pTransformFilter
->ppPins
);
135 pTransformFilter
->csFilter
.DebugInfo
->Spare
[0] = 0;
136 DeleteCriticalSection(&pTransformFilter
->csFilter
);
137 CoTaskMemFree(pTransformFilter
);
143 static HRESULT WINAPI
TransformFilter_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
145 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
146 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
150 if (IsEqualIID(riid
, &IID_IUnknown
))
152 else if (IsEqualIID(riid
, &IID_IPersist
))
154 else if (IsEqualIID(riid
, &IID_IMediaFilter
))
156 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
158 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
159 return IUnknown_QueryInterface(This
->seekthru_unk
, riid
, ppv
);
163 IUnknown_AddRef((IUnknown
*)(*ppv
));
167 if (!IsEqualIID(riid
, &IID_IPin
) && !IsEqualIID(riid
, &IID_IVideoWindow
))
168 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
170 return E_NOINTERFACE
;
173 static ULONG WINAPI
TransformFilter_AddRef(IBaseFilter
* iface
)
175 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
176 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
178 TRACE("(%p/%p)->() AddRef from %d\n", This
, iface
, refCount
- 1);
183 static ULONG WINAPI
TransformFilter_Release(IBaseFilter
* iface
)
185 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
186 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
188 TRACE("(%p/%p)->() Release from %d\n", This
, iface
, refCount
+ 1);
195 IReferenceClock_Release(This
->pClock
);
197 for (i
= 0; i
< This
->npins
; i
++)
201 if (SUCCEEDED(IPin_ConnectedTo(This
->ppPins
[i
], &pConnectedTo
)))
203 IPin_Disconnect(pConnectedTo
);
204 IPin_Release(pConnectedTo
);
206 IPin_Disconnect(This
->ppPins
[i
]);
208 IPin_Release(This
->ppPins
[i
]);
211 CoTaskMemFree(This
->ppPins
);
214 This
->csFilter
.DebugInfo
->Spare
[0] = 0;
215 DeleteCriticalSection(&This
->csFilter
);
217 TRACE("Destroying transform filter\n");
218 FreeMediaType(&This
->pmt
);
227 /** IPersist methods **/
229 static HRESULT WINAPI
TransformFilter_GetClassID(IBaseFilter
* iface
, CLSID
* pClsid
)
231 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
233 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClsid
);
235 *pClsid
= This
->clsid
;
240 /** IMediaFilter methods **/
242 static HRESULT WINAPI
TransformFilter_Stop(IBaseFilter
* iface
)
244 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
247 TRACE("(%p/%p)\n", This
, iface
);
249 EnterCriticalSection(&This
->csFilter
);
251 This
->state
= State_Stopped
;
252 if (This
->pFuncsTable
->pfnProcessEnd
)
253 hr
= This
->pFuncsTable
->pfnProcessEnd(This
);
255 LeaveCriticalSection(&This
->csFilter
);
260 static HRESULT WINAPI
TransformFilter_Pause(IBaseFilter
* iface
)
262 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
265 TRACE("(%p/%p)->()\n", This
, iface
);
267 EnterCriticalSection(&This
->csFilter
);
269 if (This
->state
== State_Stopped
)
270 hr
= IBaseFilter_Run(iface
, -1);
275 This
->state
= State_Paused
;
277 LeaveCriticalSection(&This
->csFilter
);
282 static HRESULT WINAPI
TransformFilter_Run(IBaseFilter
* iface
, REFERENCE_TIME tStart
)
285 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
287 TRACE("(%p/%p)->(%s)\n", This
, iface
, wine_dbgstr_longlong(tStart
));
289 EnterCriticalSection(&This
->csFilter
);
291 if (This
->state
== State_Stopped
)
293 ((InputPin
*)This
->ppPins
[0])->end_of_stream
= 0;
294 if (This
->pFuncsTable
->pfnProcessBegin
)
295 hr
= This
->pFuncsTable
->pfnProcessBegin(This
);
297 hr
= OutputPin_CommitAllocator((OutputPin
*)This
->ppPins
[1]);
302 This
->rtStreamStart
= tStart
;
303 This
->state
= State_Running
;
306 LeaveCriticalSection(&This
->csFilter
);
311 static HRESULT WINAPI
TransformFilter_GetState(IBaseFilter
* iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
313 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
315 TRACE("(%p/%p)->(%d, %p)\n", This
, iface
, dwMilliSecsTimeout
, pState
);
317 EnterCriticalSection(&This
->csFilter
);
319 *pState
= This
->state
;
321 LeaveCriticalSection(&This
->csFilter
);
326 static HRESULT WINAPI
TransformFilter_SetSyncSource(IBaseFilter
* iface
, IReferenceClock
*pClock
)
328 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
330 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClock
);
332 EnterCriticalSection(&This
->csFilter
);
335 IReferenceClock_Release(This
->pClock
);
336 This
->pClock
= pClock
;
338 IReferenceClock_AddRef(This
->pClock
);
340 LeaveCriticalSection(&This
->csFilter
);
345 static HRESULT WINAPI
TransformFilter_GetSyncSource(IBaseFilter
* iface
, IReferenceClock
**ppClock
)
347 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
349 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppClock
);
351 EnterCriticalSection(&This
->csFilter
);
353 *ppClock
= This
->pClock
;
355 IReferenceClock_AddRef(This
->pClock
);
357 LeaveCriticalSection(&This
->csFilter
);
362 /** IBaseFilter implementation **/
364 static HRESULT
TransformFilter_GetPin(IBaseFilter
*iface
, ULONG pos
, IPin
**pin
, DWORD
*lastsynctick
)
366 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
368 /* Our pins are static, not changing so setting static tick count is ok */
371 if (pos
>= This
->npins
)
374 *pin
= This
->ppPins
[pos
];
379 static HRESULT WINAPI
TransformFilter_EnumPins(IBaseFilter
* iface
, IEnumPins
**ppEnum
)
381 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
383 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
385 return IEnumPinsImpl_Construct(ppEnum
, TransformFilter_GetPin
, iface
);
388 static HRESULT WINAPI
TransformFilter_FindPin(IBaseFilter
* iface
, LPCWSTR Id
, IPin
**ppPin
)
390 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
392 TRACE("(%p/%p)->(%p,%p)\n", This
, iface
, debugstr_w(Id
), ppPin
);
397 static HRESULT WINAPI
TransformFilter_QueryFilterInfo(IBaseFilter
* iface
, FILTER_INFO
*pInfo
)
399 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
401 TRACE("(%p/%p)->(%p)\n", This
, iface
, pInfo
);
403 strcpyW(pInfo
->achName
, This
->filterInfo
.achName
);
404 pInfo
->pGraph
= This
->filterInfo
.pGraph
;
407 IFilterGraph_AddRef(pInfo
->pGraph
);
412 static HRESULT WINAPI
TransformFilter_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
415 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
417 TRACE("(%p/%p)->(%p, %s)\n", This
, iface
, pGraph
, debugstr_w(pName
));
419 EnterCriticalSection(&This
->csFilter
);
422 strcpyW(This
->filterInfo
.achName
, pName
);
424 *This
->filterInfo
.achName
= '\0';
425 This
->filterInfo
.pGraph
= pGraph
; /* NOTE: do NOT increase ref. count */
427 LeaveCriticalSection(&This
->csFilter
);
432 static HRESULT WINAPI
TransformFilter_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
434 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
435 TRACE("(%p/%p)->(%p)\n", This
, iface
, pVendorInfo
);
439 static const IBaseFilterVtbl TransformFilter_Vtbl
=
441 TransformFilter_QueryInterface
,
442 TransformFilter_AddRef
,
443 TransformFilter_Release
,
444 TransformFilter_GetClassID
,
445 TransformFilter_Stop
,
446 TransformFilter_Pause
,
448 TransformFilter_GetState
,
449 TransformFilter_SetSyncSource
,
450 TransformFilter_GetSyncSource
,
451 TransformFilter_EnumPins
,
452 TransformFilter_FindPin
,
453 TransformFilter_QueryFilterInfo
,
454 TransformFilter_JoinFilterGraph
,
455 TransformFilter_QueryVendorInfo
458 static HRESULT WINAPI
TransformFilter_InputPin_EndOfStream(IPin
* iface
)
460 InputPin
* This
= (InputPin
*) iface
;
461 TransformFilterImpl
* pTransform
;
465 TRACE("(%p)->()\n", iface
);
467 /* Since we process samples synchronously, just forward notification downstream */
468 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
472 hr
= IPin_ConnectedTo(pTransform
->ppPins
[1], &ppin
);
475 hr
= IPin_EndOfStream(ppin
);
484 static HRESULT WINAPI
TransformFilter_InputPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
486 InputPin
* This
= (InputPin
*) iface
;
487 TransformFilterImpl
* pTransform
;
490 TRACE("(%p)->(%p, %p)\n", iface
, pReceivePin
, pmt
);
492 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
494 hr
= pTransform
->pFuncsTable
->pfnConnectInput(This
, pmt
);
497 hr
= InputPin_ReceiveConnection(iface
, pReceivePin
, pmt
);
499 pTransform
->pFuncsTable
->pfnCleanup(This
);
505 static HRESULT WINAPI
TransformFilter_InputPin_Disconnect(IPin
* iface
)
507 InputPin
* This
= (InputPin
*) iface
;
508 TransformFilterImpl
* pTransform
;
510 TRACE("(%p)->()\n", iface
);
512 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
513 pTransform
->pFuncsTable
->pfnCleanup(This
);
515 return IPinImpl_Disconnect(iface
);
518 static HRESULT WINAPI
TransformFilter_InputPin_BeginFlush(IPin
* iface
)
520 InputPin
* This
= (InputPin
*) iface
;
521 TransformFilterImpl
* pTransform
;
524 TRACE("(%p)->()\n", iface
);
526 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
527 EnterCriticalSection(&pTransform
->csFilter
);
528 if (pTransform
->pFuncsTable
->pfnBeginFlush
)
529 hr
= pTransform
->pFuncsTable
->pfnBeginFlush(This
);
531 hr
= InputPin_BeginFlush(iface
);
532 LeaveCriticalSection(&pTransform
->csFilter
);
536 static HRESULT WINAPI
TransformFilter_InputPin_EndFlush(IPin
* iface
)
538 InputPin
* This
= (InputPin
*) iface
;
539 TransformFilterImpl
* pTransform
;
542 TRACE("(%p)->()\n", iface
);
544 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
545 EnterCriticalSection(&pTransform
->csFilter
);
546 if (pTransform
->pFuncsTable
->pfnEndFlush
)
547 hr
= pTransform
->pFuncsTable
->pfnEndFlush(This
);
549 hr
= InputPin_EndFlush(iface
);
550 LeaveCriticalSection(&pTransform
->csFilter
);
554 static HRESULT WINAPI
TransformFilter_InputPin_NewSegment(IPin
* iface
, REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
556 InputPin
* This
= (InputPin
*) iface
;
557 TransformFilterImpl
* pTransform
;
560 TRACE("(%p)->()\n", iface
);
562 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
563 EnterCriticalSection(&pTransform
->csFilter
);
564 if (pTransform
->pFuncsTable
->pfnNewSegment
)
565 hr
= pTransform
->pFuncsTable
->pfnNewSegment(This
, tStart
, tStop
, dRate
);
567 hr
= InputPin_NewSegment(iface
, tStart
, tStop
, dRate
);
568 LeaveCriticalSection(&pTransform
->csFilter
);
572 static const IPinVtbl TransformFilter_InputPin_Vtbl
=
574 InputPin_QueryInterface
,
578 TransformFilter_InputPin_ReceiveConnection
,
579 TransformFilter_InputPin_Disconnect
,
580 IPinImpl_ConnectedTo
,
581 IPinImpl_ConnectionMediaType
,
582 IPinImpl_QueryPinInfo
,
583 IPinImpl_QueryDirection
,
585 IPinImpl_QueryAccept
,
586 IPinImpl_EnumMediaTypes
,
587 IPinImpl_QueryInternalConnections
,
588 TransformFilter_InputPin_EndOfStream
,
589 TransformFilter_InputPin_BeginFlush
,
590 TransformFilter_InputPin_EndFlush
,
591 TransformFilter_InputPin_NewSegment
594 static HRESULT WINAPI
TransformFilter_Output_EnumMediaTypes(IPin
* iface
, IEnumMediaTypes
** ppEnum
)
596 IPinImpl
*This
= (IPinImpl
*)iface
;
597 TransformFilterImpl
*pTransform
= (TransformFilterImpl
*)This
->pinInfo
.pFilter
;
598 ENUMMEDIADETAILS emd
;
600 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
603 emd
.pMediaTypes
= &pTransform
->pmt
;
605 return IEnumMediaTypesImpl_Construct(&emd
, ppEnum
);
608 static const IPinVtbl TransformFilter_OutputPin_Vtbl
=
610 OutputPin_QueryInterface
,
614 OutputPin_ReceiveConnection
,
615 OutputPin_Disconnect
,
616 IPinImpl_ConnectedTo
,
617 IPinImpl_ConnectionMediaType
,
618 IPinImpl_QueryPinInfo
,
619 IPinImpl_QueryDirection
,
621 IPinImpl_QueryAccept
,
622 TransformFilter_Output_EnumMediaTypes
,
623 IPinImpl_QueryInternalConnections
,
624 OutputPin_EndOfStream
,
625 OutputPin_BeginFlush
,