CustomBaseFilter.cpp

Go to the documentation of this file.
00001 
00034 #include <DirectShow/stdafx.h>
00035 #include "CustomBaseFilter.h"
00036 
00037 CCustomBaseFilter::CCustomBaseFilter(TCHAR *pObjectName, LPUNKNOWN lpUnk, CLSID clsid)
00038 : CTransformFilter(pObjectName, lpUnk, clsid),
00039 m_nInHeight(0),
00040 m_nInWidth(0),
00041 m_nInPixels(0),
00042 m_nOutHeight(0),
00043 m_nOutWidth(0),
00044 m_nOutPixels(0),
00045 m_nBitCount(0)
00046 {
00047 }
00048 
00049 CCustomBaseFilter::~CCustomBaseFilter(void)
00050 {
00051 }
00052 
00053 void CCustomBaseFilter::AddInputType( const GUID* pType, const GUID* pSubType, const GUID* pFormat )
00054 {
00055         m_vInTypes.push_back((GUID*)pType);
00056         m_vInSubTypes.push_back((GUID*)pSubType);
00057         m_vInFormats.push_back((GUID*)pFormat);
00058 }
00059 
00060 HRESULT CCustomBaseFilter::CheckInputType( const CMediaType *pMediaType )
00061 {
00062         for (int i = 0; i < m_vInTypes.size(); i++)
00063         {
00064                 if (((pMediaType->majortype == *m_vInTypes[i]) && (m_vInTypes[i]))||(!m_vInTypes[i]))
00065                 {
00066                         //Compare sub type
00067                         if (((pMediaType->subtype == *m_vInSubTypes[i]) && (m_vInSubTypes[i]))||(!m_vInSubTypes[i]))
00068                         {
00069                                 //Compare formats
00070                                 if (((pMediaType->formattype == *m_vInFormats[i])&&(m_vInFormats[i]))||(!m_vInFormats[i]))
00071                                 {
00072                                         return S_OK;
00073                                 }
00074                         }
00075                 }
00076         }
00077         return VFW_E_TYPE_NOT_ACCEPTED;
00078 }
00079 
00080 HRESULT CCustomBaseFilter::SetMediaType( PIN_DIRECTION direction, const CMediaType *pmt )
00081 {
00082         if (direction == PINDIR_INPUT)
00083         {
00084                 if (pmt->formattype == FORMAT_VideoInfo)
00085                 {
00086                         // WARNING! In general you cannot just copy a VIDEOINFOHEADER
00087                         // struct, because the BITMAPINFOHEADER member may be followed by
00088                         // random amounts of palette entries or color masks. (See VIDEOINFO
00089                         // structure in the DShow SDK docs.) Here it's OK because we just
00090                         // want the information that's in the VIDEOINFOHEADER struct itself.
00091 
00092                         VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) pmt->pbFormat;
00093                         CopyMemory(&m_videoInHeader, pVih, sizeof(VIDEOINFOHEADER));
00094                         //Set these values now so we don't have to repeat it for each transform
00095                         m_nInHeight = abs(m_videoInHeader.bmiHeader.biHeight);
00096                         m_nInWidth = m_videoInHeader.bmiHeader.biWidth;
00097                         m_nInPixels = m_nInHeight * m_nInWidth;
00098                         m_nBitCount = m_videoInHeader.bmiHeader.biBitCount;
00099                 }
00100         }
00101         else   // output pin
00102         {
00103                 ASSERT(direction == PINDIR_OUTPUT);
00104                 if (pmt->formattype == FORMAT_VideoInfo)
00105                 {
00106                         // Store a copy of the video header info
00107                         VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmt->pbFormat;
00108                         CopyMemory(&m_videoOutHeader, pVih, sizeof(VIDEOINFOHEADER));
00109                         //Set these values now so we don't have to repeat it for each transform
00110                         m_nOutHeight = abs(m_videoOutHeader.bmiHeader.biHeight);
00111                         m_nOutWidth = m_videoOutHeader.bmiHeader.biWidth;
00112                         m_nOutPixels = m_nOutHeight * m_nOutWidth;
00113                 }
00114         }
00115         return S_OK;
00116 }
00117 
00118 HRESULT CCustomBaseFilter::Transform( IMediaSample *pSource, IMediaSample *pDest )
00119 {
00120         // Get pointers to the underlying buffers.
00121         long lSrcDataLen = pSource->GetSize();
00122         long lDestDataLen = pDest->GetSize();
00123 
00124         BYTE *pBufferIn, *pBufferOut;
00125         HRESULT hr = pSource->GetPointer(&pBufferIn);
00126         if (FAILED(hr))
00127         {
00128                 return hr;
00129         }
00130         
00131         hr = pDest->GetPointer(&pBufferOut);
00132         if (FAILED(hr))
00133         {
00134                 return hr;
00135         }
00136         // Process the data.
00137 
00138         DWORD cbDest = ApplyTransform(pBufferIn, pBufferOut);
00139         
00140         KASSERT((long)cbDest <= pDest->GetSize());
00141 
00142         pDest->SetActualDataLength(cbDest);
00143         pDest->SetSyncPoint(TRUE);
00144         return S_OK;
00145 }
00146 
00147 STDMETHODIMP CCustomBaseFilter::NonDelegatingQueryInterface( REFIID riid, void **ppv )
00148 {
00149         if(riid == (IID_ISettingsInterface))
00150         {
00151                 return GetInterface((ISettingsInterface*) this, ppv);
00152         }
00153         else if (riid == IID_IStatusInterface)
00154         {
00155                 return GetInterface((IStatusInterface*) this, ppv);
00156         }
00157         else
00158         {
00159                 return CTransformFilter::NonDelegatingQueryInterface(riid, ppv);
00160         }
00161 }
00162 
00163 STDMETHODIMP CCustomBaseFilter::GetParameter( const char* szParamName, char* szResult , int& nResultLength)
00164 {
00165         return S_FALSE;
00166 }
00167 
00168 STDMETHODIMP CCustomBaseFilter::SetParameter( const char* szParamName, const char* szValue )
00169 {
00170         return S_FALSE;
00171 }

Generated on Fri Mar 13 14:12:38 2009 for RTVC by  doxygen 1.5.3