Commit 34f3f7ca authored by Aric Stewart's avatar Aric Stewart Committed by Alexandre Julliard

strmbase: Move TransformFilter implementation to strmbase.

parent 79108708
......@@ -24,7 +24,6 @@ C_SRCS = \
pin.c \
regsvr.c \
systemclock.c \
transform.c \
videorenderer.c \
waveparser.c
......
......@@ -37,13 +37,13 @@
#include "wine/unicode.h"
#include "wine/debug.h"
#include "transform.h"
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
typedef struct ACMWrapperImpl
{
TransformFilterImpl tf;
TransformFilter tf;
IUnknown *seekthru_unk;
HACMSTREAM has;
LPWAVEFORMATEX pWfIn;
LPWAVEFORMATEX pWfOut;
......@@ -52,10 +52,11 @@ typedef struct ACMWrapperImpl
LONGLONG lasttime_sent;
} ACMWrapperImpl;
static HRESULT WINAPI ACMWrapper_ProcessSampleData(IPin *iface, IMediaSample *pSample)
static const IBaseFilterVtbl ACMWrapper_Vtbl;
static HRESULT WINAPI ACMWrapper_Receive(TransformFilter *tf, IMediaSample *pSample)
{
BaseInputPin *pin = (BaseInputPin*) iface;
ACMWrapperImpl* This = (ACMWrapperImpl*)pin->pin.pinInfo.pFilter;
ACMWrapperImpl* This = (ACMWrapperImpl*)tf;
AM_MEDIA_TYPE amt;
IMediaSample* pOutSample = NULL;
DWORD cbDstStream, cbSrcStream;
......@@ -68,18 +69,6 @@ static HRESULT WINAPI ACMWrapper_ProcessSampleData(IPin *iface, IMediaSample *pS
LONGLONG tStart = -1, tStop = -1, tMed;
EnterCriticalSection(&This->tf.filter.csFilter);
if (This->tf.filter.state == State_Stopped)
{
LeaveCriticalSection(&This->tf.filter.csFilter);
return VFW_E_WRONG_STATE;
}
if (pin->end_of_stream || pin->flushing)
{
LeaveCriticalSection(&This->tf.filter.csFilter);
return S_FALSE;
}
hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
if (FAILED(hr))
{
......@@ -235,12 +224,15 @@ error:
return hr;
}
static HRESULT ACMWrapper_ConnectInput(BaseInputPin *pin, const AM_MEDIA_TYPE * pmt)
static HRESULT WINAPI ACMWrapper_SetMediaType(TransformFilter *tf, PIN_DIRECTION dir, const AM_MEDIA_TYPE * pmt)
{
ACMWrapperImpl* This = (ACMWrapperImpl *)pin->pin.pinInfo.pFilter;
ACMWrapperImpl* This = (ACMWrapperImpl *)tf;
MMRESULT res;
TRACE("(%p)->(%p)\n", This, pmt);
TRACE("(%p)->(%i %p)\n", This, dir, pmt);
if (dir != PINDIR_INPUT)
return S_OK;
/* Check root (GUID w/o FOURCC) */
if ((IsEqualIID(&pmt->majortype, &MEDIATYPE_Audio)) &&
......@@ -287,28 +279,62 @@ static HRESULT ACMWrapper_ConnectInput(BaseInputPin *pin, const AM_MEDIA_TYPE *
return VFW_E_TYPE_NOT_ACCEPTED;
}
static HRESULT ACMWrapper_Cleanup(BaseInputPin *pin)
static HRESULT WINAPI ACMWrapper_CompleteConnect(TransformFilter *tf, PIN_DIRECTION dir, IPin *pin)
{
ACMWrapperImpl *This = (ACMWrapperImpl *)pin->pin.pinInfo.pFilter;
ACMWrapperImpl* This = (ACMWrapperImpl *)tf;
MMRESULT res;
HACMSTREAM drv;
TRACE("(%p)->()\n", This);
TRACE("(%p)\n", This);
if (This->has)
acmStreamClose(This->has, 0);
if (dir != PINDIR_INPUT)
return S_OK;
This->has = 0;
This->lasttime_real = This->lasttime_sent = -1;
if (!(res = acmStreamOpen(&drv, NULL, This->pWfIn, This->pWfOut, NULL, 0, 0, 0)))
{
This->has = drv;
/* Update buffer size of media samples in output */
((BaseOutputPin*)This->tf.ppPins[1])->allocProps.cbBuffer = This->pWfOut->nAvgBytesPerSec / 2;
TRACE("Connection accepted\n");
return S_OK;
}
FIXME("acmStreamOpen returned %d\n", res);
TRACE("Unable to find a suitable ACM decompressor\n");
return VFW_E_TYPE_NOT_ACCEPTED;
}
static HRESULT WINAPI ACMWrapper_BreakConnect(TransformFilter *tf, PIN_DIRECTION dir)
{
ACMWrapperImpl *This = (ACMWrapperImpl *)tf;
TRACE("(%p)->(%i)\n", This,dir);
if (dir == PINDIR_INPUT)
{
if (This->has)
acmStreamClose(This->has, 0);
This->has = 0;
This->lasttime_real = This->lasttime_sent = -1;
}
return S_OK;
}
static const TransformFuncsTable ACMWrapper_FuncsTable = {
static const TransformFilterFuncTable ACMWrapper_FuncsTable = {
NULL,
ACMWrapper_Receive,
NULL,
NULL,
ACMWrapper_ProcessSampleData,
ACMWrapper_SetMediaType,
ACMWrapper_CompleteConnect,
ACMWrapper_BreakConnect,
NULL,
NULL,
ACMWrapper_ConnectInput,
ACMWrapper_Cleanup
NULL,
NULL
};
HRESULT ACMWrapper_create(IUnknown * pUnkOuter, LPVOID * ppv)
......@@ -323,17 +349,55 @@ HRESULT ACMWrapper_create(IUnknown * pUnkOuter, LPVOID * ppv)
if (pUnkOuter)
return CLASS_E_NOAGGREGATION;
/* Note: This memory is managed by the transform filter once created */
This = CoTaskMemAlloc(sizeof(ACMWrapperImpl));
ZeroMemory(This, sizeof(ACMWrapperImpl));
hr = TransformFilter_Create(&(This->tf), &CLSID_ACMWrapper, &ACMWrapper_FuncsTable);
hr = TransformFilter_Construct(&ACMWrapper_Vtbl, sizeof(ACMWrapperImpl), &CLSID_ACMWrapper, &ACMWrapper_FuncsTable, (IBaseFilter**)&This);
if (FAILED(hr))
return hr;
else
{
ISeekingPassThru *passthru;
hr = CoCreateInstance(&CLSID_SeekingPassThru, (IUnknown*)This, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void**)&This->seekthru_unk);
IUnknown_QueryInterface(This->seekthru_unk, &IID_ISeekingPassThru, (void**)&passthru);
ISeekingPassThru_Init(passthru, FALSE, (IPin*)This->tf.ppPins[0]);
ISeekingPassThru_Release(passthru);
}
*ppv = This;
This->lasttime_real = This->lasttime_sent = -1;
return hr;
}
HRESULT WINAPI ACMWrapper_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
{
HRESULT hr;
ACMWrapperImpl *This = (ACMWrapperImpl *)iface;
TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
if (IsEqualIID(riid, &IID_IMediaSeeking))
return IUnknown_QueryInterface(This->seekthru_unk, riid, ppv);
hr = TransformFilterImpl_QueryInterface(iface, riid, ppv);
return hr;
}
static const IBaseFilterVtbl ACMWrapper_Vtbl =
{
ACMWrapper_QueryInterface,
BaseFilterImpl_AddRef,
TransformFilterImpl_Release,
BaseFilterImpl_GetClassID,
TransformFilterImpl_Stop,
TransformFilterImpl_Pause,
TransformFilterImpl_Run,
BaseFilterImpl_GetState,
BaseFilterImpl_SetSyncSource,
BaseFilterImpl_GetSyncSource,
BaseFilterImpl_EnumPins,
TransformFilterImpl_FindPin,
BaseFilterImpl_QueryFilterInfo,
BaseFilterImpl_JoinFilterGraph,
BaseFilterImpl_QueryVendorInfo
};
......@@ -38,19 +38,21 @@
#include "wine/unicode.h"
#include "wine/debug.h"
#include "transform.h"
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
typedef struct AVIDecImpl
{
TransformFilterImpl tf;
TransformFilter tf;
IUnknown *seekthru_unk;
HIC hvid;
BITMAPINFOHEADER* pBihIn;
BITMAPINFOHEADER* pBihOut;
} AVIDecImpl;
static HRESULT AVIDec_ProcessBegin(TransformFilterImpl* pTransformFilter)
static const IBaseFilterVtbl AVIDec_Vtbl;
static HRESULT WINAPI AVIDec_StartStreaming(TransformFilter* pTransformFilter)
{
AVIDecImpl* This = (AVIDecImpl*)pTransformFilter;
DWORD result;
......@@ -66,10 +68,9 @@ static HRESULT AVIDec_ProcessBegin(TransformFilterImpl* pTransformFilter)
return S_OK;
}
static HRESULT WINAPI AVIDec_ProcessSampleData(IPin *iface, IMediaSample *pSample)
static HRESULT WINAPI AVIDec_Receive(TransformFilter *tf, IMediaSample *pSample)
{
BaseInputPin *pin = (BaseInputPin*)iface;
AVIDecImpl* This = (AVIDecImpl *)pin->pin.pinInfo.pFilter;
AVIDecImpl* This = (AVIDecImpl *)tf;
AM_MEDIA_TYPE amt;
HRESULT hr;
DWORD res;
......@@ -81,18 +82,6 @@ static HRESULT WINAPI AVIDec_ProcessSampleData(IPin *iface, IMediaSample *pSampl
LONGLONG tStart, tStop;
EnterCriticalSection(&This->tf.filter.csFilter);
if (This->tf.filter.state == State_Stopped)
{
LeaveCriticalSection(&This->tf.filter.csFilter);
return VFW_E_WRONG_STATE;
}
if (pin->end_of_stream || pin->flushing)
{
LeaveCriticalSection(&This->tf.filter.csFilter);
return S_FALSE;
}
hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
if (FAILED(hr))
{
......@@ -164,7 +153,7 @@ error:
return hr;
}
static HRESULT AVIDec_ProcessEnd(TransformFilterImpl* pTransformFilter)
static HRESULT WINAPI AVIDec_StopStreaming(TransformFilter* pTransformFilter)
{
AVIDecImpl* This = (AVIDecImpl*)pTransformFilter;
DWORD result;
......@@ -183,13 +172,16 @@ static HRESULT AVIDec_ProcessEnd(TransformFilterImpl* pTransformFilter)
return S_OK;
}
static HRESULT AVIDec_ConnectInput(BaseInputPin *pin, const AM_MEDIA_TYPE * pmt)
static HRESULT WINAPI AVIDec_SetMediaType(TransformFilter *tf, PIN_DIRECTION dir, const AM_MEDIA_TYPE * pmt)
{
AVIDecImpl* This = (AVIDecImpl*)pin->pin.pinInfo.pFilter;
AVIDecImpl* This = (AVIDecImpl*)tf;
HRESULT hr = VFW_E_TYPE_NOT_ACCEPTED;
TRACE("(%p)->(%p)\n", This, pmt);
if (dir != PINDIR_INPUT)
return S_OK;
/* Check root (GUID w/o FOURCC) */
if ((IsEqualIID(&pmt->majortype, &MEDIATYPE_Video)) &&
(!memcmp(((const char *)&pmt->subtype)+4, ((const char *)&MEDIATYPE_Video)+4, sizeof(GUID)-4)))
......@@ -269,9 +261,6 @@ static HRESULT AVIDec_ConnectInput(BaseInputPin *pin, const AM_MEDIA_TYPE * pmt)
else
assert(0);
/* Update buffer size of media samples in output */
((BaseOutputPin*)This->tf.ppPins[1])->allocProps.cbBuffer = This->pBihOut->biSizeImage;
TRACE("Connection accepted\n");
return S_OK;
}
......@@ -284,33 +273,55 @@ failed:
return hr;
}
static HRESULT AVIDec_Cleanup(BaseInputPin *pin)
static HRESULT WINAPI AVIDec_CompleteConnect(TransformFilter *tf, PIN_DIRECTION dir, IPin *pin)
{
AVIDecImpl *This = (AVIDecImpl *)pin->pin.pinInfo.pFilter;
AVIDecImpl* This = (AVIDecImpl*)tf;
TRACE("(%p)\n", This);
if (dir == PINDIR_INPUT)
{
/* Update buffer size of media samples in output */
((BaseOutputPin*)This->tf.ppPins[1])->allocProps.cbBuffer = This->pBihOut->biSizeImage;
}
return S_OK;
}
static HRESULT WINAPI AVIDec_BreakConnect(TransformFilter *tf, PIN_DIRECTION dir)
{
AVIDecImpl *This = (AVIDecImpl *)tf;
TRACE("(%p)->()\n", This);
if (This->hvid)
ICClose(This->hvid);
if (This->pBihIn)
CoTaskMemFree(This->pBihIn);
if (This->pBihOut)
CoTaskMemFree(This->pBihOut);
This->hvid = NULL;
This->pBihIn = NULL;
This->pBihOut = NULL;
if (dir == PINDIR_INPUT)
{
if (This->hvid)
ICClose(This->hvid);
if (This->pBihIn)
CoTaskMemFree(This->pBihIn);
if (This->pBihOut)
CoTaskMemFree(This->pBihOut);
This->hvid = NULL;
This->pBihIn = NULL;
This->pBihOut = NULL;
}
return S_OK;
}
static const TransformFuncsTable AVIDec_FuncsTable = {
AVIDec_ProcessBegin,
AVIDec_ProcessSampleData,
AVIDec_ProcessEnd,
static const TransformFilterFuncTable AVIDec_FuncsTable = {
AVIDec_StartStreaming,
AVIDec_Receive,
AVIDec_StopStreaming,
NULL,
AVIDec_SetMediaType,
AVIDec_CompleteConnect,
AVIDec_BreakConnect,
NULL,
AVIDec_ConnectInput,
AVIDec_Cleanup
NULL,
NULL,
NULL
};
HRESULT AVIDec_create(IUnknown * pUnkOuter, LPVOID * ppv)
......@@ -325,19 +336,57 @@ HRESULT AVIDec_create(IUnknown * pUnkOuter, LPVOID * ppv)
if (pUnkOuter)
return CLASS_E_NOAGGREGATION;
/* Note: This memory is managed by the transform filter once created */
This = CoTaskMemAlloc(sizeof(AVIDecImpl));
hr = TransformFilter_Construct(&AVIDec_Vtbl, sizeof(AVIDecImpl), &CLSID_AVIDec, &AVIDec_FuncsTable, (IBaseFilter**)&This);
if (FAILED(hr))
return hr;
else
{
ISeekingPassThru *passthru;
hr = CoCreateInstance(&CLSID_SeekingPassThru, (IUnknown*)This, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void**)&This->seekthru_unk);
IUnknown_QueryInterface(This->seekthru_unk, &IID_ISeekingPassThru, (void**)&passthru);
ISeekingPassThru_Init(passthru, FALSE, (IPin*)This->tf.ppPins[0]);
ISeekingPassThru_Release(passthru);
}
This->hvid = NULL;
This->pBihIn = NULL;
This->pBihOut = NULL;
hr = TransformFilter_Create(&(This->tf), &CLSID_AVIDec, &AVIDec_FuncsTable);
*ppv = This;
return hr;
}
if (FAILED(hr))
return hr;
HRESULT WINAPI AVIDec_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
{
HRESULT hr;
AVIDecImpl *This = (AVIDecImpl *)iface;
TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
*ppv = This;
if (IsEqualIID(riid, &IID_IMediaSeeking))
return IUnknown_QueryInterface(This->seekthru_unk, riid, ppv);
hr = TransformFilterImpl_QueryInterface(iface, riid, ppv);
return hr;
}
static const IBaseFilterVtbl AVIDec_Vtbl =
{
AVIDec_QueryInterface,
BaseFilterImpl_AddRef,
TransformFilterImpl_Release,
BaseFilterImpl_GetClassID,
TransformFilterImpl_Stop,
TransformFilterImpl_Pause,
TransformFilterImpl_Run,
BaseFilterImpl_GetState,
BaseFilterImpl_SetSyncSource,
BaseFilterImpl_GetSyncSource,
BaseFilterImpl_EnumPins,
TransformFilterImpl_FindPin,
BaseFilterImpl_QueryFilterInfo,
BaseFilterImpl_JoinFilterGraph,
BaseFilterImpl_QueryVendorInfo
};
/*
* Transform Filter declarations
*
* Copyright 2005 Christian Costa
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "control_private.h"
typedef struct TransformFilterImpl TransformFilterImpl;
typedef struct TransformFuncsTable {
HRESULT (*pfnProcessBegin) (TransformFilterImpl *This);
BaseInputPin_Receive pfnProcessSampleData;
HRESULT (*pfnProcessEnd) (TransformFilterImpl *This);
HRESULT (*pfnQueryConnect) (TransformFilterImpl *This, const AM_MEDIA_TYPE * pmt);
HRESULT (*pfnConnectInput) (BaseInputPin *pin, const AM_MEDIA_TYPE * pmt);
HRESULT (*pfnCleanup) (BaseInputPin *pin);
HRESULT (*pfnEndOfStream) (BaseInputPin *pin);
HRESULT (*pfnBeginFlush) (BaseInputPin *pin);
HRESULT (*pfnEndFlush) (BaseInputPin *pin);
HRESULT (*pfnNewSegment) (BaseInputPin *pin, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
} TransformFuncsTable;
struct TransformFilterImpl
{
BaseFilter filter;
IUnknown *seekthru_unk;
IPin **ppPins;
ULONG npins;
AM_MEDIA_TYPE pmt;
const TransformFuncsTable * pFuncsTable;
};
HRESULT TransformFilter_Create(TransformFilterImpl*, const CLSID*, const TransformFuncsTable* pFuncsTable);
......@@ -4,6 +4,7 @@ C_SRCS = \
enumpins.c \
filter.c \
mediatype.c \
pin.c
pin.c \
transform.c
@MAKE_IMPLIB_RULES@
......@@ -158,3 +158,51 @@ LONG WINAPI BaseFilterImpl_GetPinVersion(IBaseFilter* This);
VOID WINAPI BaseFilterImpl_IncrementPinVersion(IBaseFilter* This);
HRESULT WINAPI BaseFilter_Init(BaseFilter * This, const IBaseFilterVtbl *Vtbl, const CLSID *pClsid, DWORD_PTR DebugInfo, BaseFilter_GetPin pfGetPin, BaseFilter_GetPinCount pfGetPinCount);
/* Transform Filter */
typedef struct TransformFilter
{
BaseFilter filter;
IPin **ppPins;
ULONG npins;
AM_MEDIA_TYPE pmt;
const struct TransformFilterFuncTable * pFuncsTable;
} TransformFilter;
typedef HRESULT (WINAPI *TransformFilter_StartStreaming) (TransformFilter *iface);
typedef HRESULT (WINAPI *TransformFilter_StopStreaming) (TransformFilter *iface);
typedef HRESULT (WINAPI *TransformFilter_Receive) (TransformFilter* iface, IMediaSample* pIn);
typedef HRESULT (WINAPI *TransformFilter_CompleteConnect) (TransformFilter *iface, PIN_DIRECTION dir, IPin *pPin);
typedef HRESULT (WINAPI *TransformFilter_BreakConnect) (TransformFilter *iface, PIN_DIRECTION dir);
typedef HRESULT (WINAPI *TransformFilter_SetMediaType) (TransformFilter *iface, PIN_DIRECTION dir, const AM_MEDIA_TYPE *pMediaType);
typedef HRESULT (WINAPI *TransformFilter_CheckInputType) (TransformFilter *iface, const AM_MEDIA_TYPE *pMediaType);
typedef HRESULT (WINAPI *TransformFilter_EndOfStream) (TransformFilter *iface);
typedef HRESULT (WINAPI *TransformFilter_BeginFlush) (TransformFilter *iface);
typedef HRESULT (WINAPI *TransformFilter_EndFlush) (TransformFilter *iface);
typedef HRESULT (WINAPI *TransformFilter_NewSegment) (TransformFilter *iface,
REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
typedef struct TransformFilterFuncTable {
TransformFilter_StartStreaming pfnStartStreaming;
TransformFilter_Receive pfnReceive;
TransformFilter_StopStreaming pfnStopStreaming;
TransformFilter_CheckInputType pfnCheckInputType;
TransformFilter_SetMediaType pfnSetMediaType;
TransformFilter_CompleteConnect pfnCompleteConnect;
TransformFilter_BreakConnect pfnBreakConnect;
TransformFilter_EndOfStream pfnEndOfStream;
TransformFilter_BeginFlush pfnBeginFlush;
TransformFilter_EndFlush pfnEndFlush;
TransformFilter_NewSegment pfnNewSegment;
} TransformFilterFuncTable;
HRESULT WINAPI TransformFilterImpl_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv);
ULONG WINAPI TransformFilterImpl_Release(IBaseFilter * iface);
HRESULT WINAPI TransformFilterImpl_Stop(IBaseFilter * iface);
HRESULT WINAPI TransformFilterImpl_Pause(IBaseFilter * iface);
HRESULT WINAPI TransformFilterImpl_Run(IBaseFilter * iface, REFERENCE_TIME tStart);
HRESULT WINAPI TransformFilterImpl_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin);
HRESULT TransformFilter_Construct( const IBaseFilterVtbl *filterVtbl, LONG filter_size, const CLSID* pClsid, const TransformFilterFuncTable* pFuncsTable, IBaseFilter ** ppTransformFilter);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment