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_Input_QueryAccept(LPVOID iface
, const AM_MEDIA_TYPE
* pmt
)
53 TransformFilterImpl
* This
= (TransformFilterImpl
*)iface
;
55 dump_AM_MEDIA_TYPE(pmt
);
57 if (This
->pFuncsTable
->pfnQueryConnect
)
58 return This
->pFuncsTable
->pfnQueryConnect(This
, pmt
);
59 /* Assume OK if there's no query method (the connection will fail if
65 static HRESULT
TransformFilter_Output_QueryAccept(LPVOID iface
, const AM_MEDIA_TYPE
* pmt
)
67 TransformFilterImpl
* pTransformFilter
= (TransformFilterImpl
*)iface
;
68 AM_MEDIA_TYPE
* outpmt
= &((OutputPin
*)pTransformFilter
->ppPins
[1])->pin
.mtCurrent
;
71 if (IsEqualIID(&pmt
->majortype
, &outpmt
->majortype
) && IsEqualIID(&pmt
->subtype
, &outpmt
->subtype
))
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
));
168 pTransformFilter
->ppPins
= CoTaskMemAlloc(2 * sizeof(IPin
*));
170 /* construct input pin */
171 piInput
.dir
= PINDIR_INPUT
;
172 piInput
.pFilter
= (IBaseFilter
*)pTransformFilter
;
173 lstrcpynW(piInput
.achName
, wcsInputPinName
, sizeof(piInput
.achName
) / sizeof(piInput
.achName
[0]));
174 piOutput
.dir
= PINDIR_OUTPUT
;
175 piOutput
.pFilter
= (IBaseFilter
*)pTransformFilter
;
176 lstrcpynW(piOutput
.achName
, wcsOutputPinName
, sizeof(piOutput
.achName
) / sizeof(piOutput
.achName
[0]));
178 hr
= InputPin_Construct(&TransformFilter_InputPin_Vtbl
, &piInput
, (SAMPLEPROC_PUSH
)pFuncsTable
->pfnProcessSampleData
, pTransformFilter
, TransformFilter_Input_QueryAccept
, NULL
, &pTransformFilter
->csFilter
, NULL
, &pTransformFilter
->ppPins
[0]);
182 ALLOCATOR_PROPERTIES props
;
185 props
.cbBuffer
= 0; /* Will be updated at connection time */
188 hr
= OutputPin_Construct(&TransformFilter_OutputPin_Vtbl
, sizeof(OutputPin
), &piOutput
, &props
, pTransformFilter
, TransformFilter_Output_QueryAccept
, &pTransformFilter
->csFilter
, &pTransformFilter
->ppPins
[1]);
191 ERR("Cannot create output pin (%x)\n", hr
);
195 stop
= TransformFilter_ChangeStop
;
197 current
= TransformFilter_ChangeCurrent
;
199 rate
= TransformFilter_ChangeRate
;
201 MediaSeekingImpl_Init((IBaseFilter
*)pTransformFilter
, stop
, current
, rate
, &pTransformFilter
->mediaSeeking
, &pTransformFilter
->csFilter
);
202 pTransformFilter
->mediaSeeking
.lpVtbl
= &TransformFilter_Seeking_Vtbl
;
207 CoTaskMemFree(pTransformFilter
->ppPins
);
208 pTransformFilter
->csFilter
.DebugInfo
->Spare
[0] = 0;
209 DeleteCriticalSection(&pTransformFilter
->csFilter
);
210 CoTaskMemFree(pTransformFilter
);
216 static HRESULT WINAPI
TransformFilter_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
218 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
219 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
223 if (IsEqualIID(riid
, &IID_IUnknown
))
225 else if (IsEqualIID(riid
, &IID_IPersist
))
227 else if (IsEqualIID(riid
, &IID_IMediaFilter
))
229 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
231 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
232 *ppv
= &This
->mediaSeeking
;
236 IUnknown_AddRef((IUnknown
*)(*ppv
));
240 if (!IsEqualIID(riid
, &IID_IPin
) && !IsEqualIID(riid
, &IID_IVideoWindow
))
241 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
243 return E_NOINTERFACE
;
246 static ULONG WINAPI
TransformFilter_AddRef(IBaseFilter
* iface
)
248 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
249 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
251 TRACE("(%p/%p)->() AddRef from %d\n", This
, iface
, refCount
- 1);
256 static ULONG WINAPI
TransformFilter_Release(IBaseFilter
* iface
)
258 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
259 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
261 TRACE("(%p/%p)->() Release from %d\n", This
, iface
, refCount
+ 1);
268 IReferenceClock_Release(This
->pClock
);
270 for (i
= 0; i
< 2; i
++)
274 if (SUCCEEDED(IPin_ConnectedTo(This
->ppPins
[i
], &pConnectedTo
)))
276 IPin_Disconnect(pConnectedTo
);
277 IPin_Release(pConnectedTo
);
279 IPin_Disconnect(This
->ppPins
[i
]);
281 IPin_Release(This
->ppPins
[i
]);
284 CoTaskMemFree(This
->ppPins
);
287 This
->csFilter
.DebugInfo
->Spare
[0] = 0;
288 DeleteCriticalSection(&This
->csFilter
);
290 TRACE("Destroying transform filter\n");
299 /** IPersist methods **/
301 static HRESULT WINAPI
TransformFilter_GetClassID(IBaseFilter
* iface
, CLSID
* pClsid
)
303 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
305 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClsid
);
307 *pClsid
= This
->clsid
;
312 /** IMediaFilter methods **/
314 static HRESULT WINAPI
TransformFilter_Stop(IBaseFilter
* iface
)
316 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
318 TRACE("(%p/%p)\n", This
, iface
);
320 EnterCriticalSection(&This
->csFilter
);
322 This
->state
= State_Stopped
;
323 if (This
->pFuncsTable
->pfnProcessEnd
)
324 This
->pFuncsTable
->pfnProcessEnd(This
);
326 LeaveCriticalSection(&This
->csFilter
);
331 static HRESULT WINAPI
TransformFilter_Pause(IBaseFilter
* iface
)
333 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
335 TRACE("(%p/%p)->()\n", This
, iface
);
337 EnterCriticalSection(&This
->csFilter
);
339 if (This
->state
== State_Stopped
)
340 IBaseFilter_Run(iface
, -1);
342 This
->state
= State_Paused
;
344 LeaveCriticalSection(&This
->csFilter
);
349 static HRESULT WINAPI
TransformFilter_Run(IBaseFilter
* iface
, REFERENCE_TIME tStart
)
352 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
354 TRACE("(%p/%p)->(%s)\n", This
, iface
, wine_dbgstr_longlong(tStart
));
356 EnterCriticalSection(&This
->csFilter
);
358 if (This
->state
== State_Stopped
)
360 ((InputPin
*)This
->ppPins
[0])->end_of_stream
= 0;
361 if (This
->pFuncsTable
->pfnProcessBegin
)
362 This
->pFuncsTable
->pfnProcessBegin(This
);
363 OutputPin_CommitAllocator((OutputPin
*)This
->ppPins
[1]);
366 This
->rtStreamStart
= tStart
;
367 This
->state
= State_Running
;
369 LeaveCriticalSection(&This
->csFilter
);
374 static HRESULT WINAPI
TransformFilter_GetState(IBaseFilter
* iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
376 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
378 TRACE("(%p/%p)->(%d, %p)\n", This
, iface
, dwMilliSecsTimeout
, pState
);
380 EnterCriticalSection(&This
->csFilter
);
382 *pState
= This
->state
;
384 LeaveCriticalSection(&This
->csFilter
);
389 static HRESULT WINAPI
TransformFilter_SetSyncSource(IBaseFilter
* iface
, IReferenceClock
*pClock
)
391 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
393 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClock
);
395 EnterCriticalSection(&This
->csFilter
);
398 IReferenceClock_Release(This
->pClock
);
399 This
->pClock
= pClock
;
401 IReferenceClock_AddRef(This
->pClock
);
403 LeaveCriticalSection(&This
->csFilter
);
408 static HRESULT WINAPI
TransformFilter_GetSyncSource(IBaseFilter
* iface
, IReferenceClock
**ppClock
)
410 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
412 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppClock
);
414 EnterCriticalSection(&This
->csFilter
);
416 *ppClock
= This
->pClock
;
418 IReferenceClock_AddRef(This
->pClock
);
420 LeaveCriticalSection(&This
->csFilter
);
425 /** IBaseFilter implementation **/
427 static HRESULT
TransformFilter_GetPin(IBaseFilter
*iface
, ULONG pos
, IPin
**pin
, DWORD
*lastsynctick
)
429 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
431 /* Our pins are static, not changing so setting static tick count is ok */
437 *pin
= This
->ppPins
[pos
];
442 static HRESULT WINAPI
TransformFilter_EnumPins(IBaseFilter
* iface
, IEnumPins
**ppEnum
)
444 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
446 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
448 return IEnumPinsImpl_Construct(ppEnum
, TransformFilter_GetPin
, iface
);
451 static HRESULT WINAPI
TransformFilter_FindPin(IBaseFilter
* iface
, LPCWSTR Id
, IPin
**ppPin
)
453 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
455 TRACE("(%p/%p)->(%p,%p)\n", This
, iface
, debugstr_w(Id
), ppPin
);
460 static HRESULT WINAPI
TransformFilter_QueryFilterInfo(IBaseFilter
* iface
, FILTER_INFO
*pInfo
)
462 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
464 TRACE("(%p/%p)->(%p)\n", This
, iface
, pInfo
);
466 strcpyW(pInfo
->achName
, This
->filterInfo
.achName
);
467 pInfo
->pGraph
= This
->filterInfo
.pGraph
;
470 IFilterGraph_AddRef(pInfo
->pGraph
);
475 static HRESULT WINAPI
TransformFilter_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
478 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
480 TRACE("(%p/%p)->(%p, %s)\n", This
, iface
, pGraph
, debugstr_w(pName
));
482 EnterCriticalSection(&This
->csFilter
);
485 strcpyW(This
->filterInfo
.achName
, pName
);
487 *This
->filterInfo
.achName
= '\0';
488 This
->filterInfo
.pGraph
= pGraph
; /* NOTE: do NOT increase ref. count */
490 LeaveCriticalSection(&This
->csFilter
);
495 static HRESULT WINAPI
TransformFilter_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
497 TransformFilterImpl
*This
= (TransformFilterImpl
*)iface
;
498 TRACE("(%p/%p)->(%p)\n", This
, iface
, pVendorInfo
);
502 static const IBaseFilterVtbl TransformFilter_Vtbl
=
504 TransformFilter_QueryInterface
,
505 TransformFilter_AddRef
,
506 TransformFilter_Release
,
507 TransformFilter_GetClassID
,
508 TransformFilter_Stop
,
509 TransformFilter_Pause
,
511 TransformFilter_GetState
,
512 TransformFilter_SetSyncSource
,
513 TransformFilter_GetSyncSource
,
514 TransformFilter_EnumPins
,
515 TransformFilter_FindPin
,
516 TransformFilter_QueryFilterInfo
,
517 TransformFilter_JoinFilterGraph
,
518 TransformFilter_QueryVendorInfo
521 static HRESULT WINAPI
TransformFilter_InputPin_EndOfStream(IPin
* iface
)
523 InputPin
* This
= (InputPin
*) iface
;
524 TransformFilterImpl
* pTransform
;
528 TRACE("(%p)->()\n", iface
);
530 /* Since we process samples synchronously, just forward notification downstream */
531 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
535 hr
= IPin_ConnectedTo(pTransform
->ppPins
[1], &ppin
);
538 hr
= IPin_EndOfStream(ppin
);
547 static HRESULT WINAPI
TransformFilter_InputPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
549 InputPin
* This
= (InputPin
*) iface
;
550 TransformFilterImpl
* pTransform
;
553 TRACE("(%p)->(%p, %p)\n", iface
, pReceivePin
, pmt
);
555 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
557 hr
= pTransform
->pFuncsTable
->pfnConnectInput(pTransform
, pmt
);
560 hr
= InputPin_ReceiveConnection(iface
, pReceivePin
, pmt
);
562 pTransform
->pFuncsTable
->pfnCleanup(pTransform
);
568 static HRESULT WINAPI
TransformFilter_InputPin_Disconnect(IPin
* iface
)
570 InputPin
* This
= (InputPin
*) iface
;
571 TransformFilterImpl
* pTransform
;
573 TRACE("(%p)->()\n", iface
);
575 pTransform
= (TransformFilterImpl
*)This
->pin
.pinInfo
.pFilter
;
576 pTransform
->pFuncsTable
->pfnCleanup(pTransform
);
578 return IPinImpl_Disconnect(iface
);
581 static const IPinVtbl TransformFilter_InputPin_Vtbl
=
583 InputPin_QueryInterface
,
587 TransformFilter_InputPin_ReceiveConnection
,
588 TransformFilter_InputPin_Disconnect
,
589 IPinImpl_ConnectedTo
,
590 IPinImpl_ConnectionMediaType
,
591 IPinImpl_QueryPinInfo
,
592 IPinImpl_QueryDirection
,
594 IPinImpl_QueryAccept
,
595 IPinImpl_EnumMediaTypes
,
596 IPinImpl_QueryInternalConnections
,
597 TransformFilter_InputPin_EndOfStream
,
603 static HRESULT WINAPI
TransformFilter_Output_EnumMediaTypes(IPin
* iface
, IEnumMediaTypes
** ppEnum
)
605 IPinImpl
*This
= (IPinImpl
*)iface
;
606 ENUMMEDIADETAILS emd
;
608 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
611 emd
.pMediaTypes
= &This
->mtCurrent
;
613 return IEnumMediaTypesImpl_Construct(&emd
, ppEnum
);
616 static const IPinVtbl TransformFilter_OutputPin_Vtbl
=
618 OutputPin_QueryInterface
,
622 OutputPin_ReceiveConnection
,
623 OutputPin_Disconnect
,
624 IPinImpl_ConnectedTo
,
625 IPinImpl_ConnectionMediaType
,
626 IPinImpl_QueryPinInfo
,
627 IPinImpl_QueryDirection
,
629 IPinImpl_QueryAccept
,
630 TransformFilter_Output_EnumMediaTypes
,
631 IPinImpl_QueryInternalConnections
,
632 OutputPin_EndOfStream
,
633 OutputPin_BeginFlush
,
638 static const IMemInputPinVtbl MemInputPin_Vtbl
=
640 MemInputPin_QueryInterface
,
643 MemInputPin_GetAllocator
,
644 MemInputPin_NotifyAllocator
,
645 MemInputPin_GetAllocatorRequirements
,
647 MemInputPin_ReceiveMultiple
,
648 MemInputPin_ReceiveCanBlock