| 1 |
//------------------------------------------------------------------------------ |
| 2 |
// File: TransIP.h |
| 3 |
// |
| 4 |
// Desc: DirectShow base classes - defines classes from which simple |
| 5 |
// Transform-In-Place filters may be derived. |
| 6 |
// |
| 7 |
// Copyright (c) 1992-2001 Microsoft Corporation. All rights reserved. |
| 8 |
//------------------------------------------------------------------------------ |
| 9 |
|
| 10 |
|
| 11 |
// |
| 12 |
// The difference between this and Transfrm.h is that Transfrm copies the data. |
| 13 |
// |
| 14 |
// It assumes the filter has one input and one output stream, and has no |
| 15 |
// interest in memory management, interface negotiation or anything else. |
| 16 |
// |
| 17 |
// Derive your class from this, and supply Transform and the media type/format |
| 18 |
// negotiation functions. Implement that class, compile and link and |
| 19 |
// you're done. |
| 20 |
|
| 21 |
|
| 22 |
#ifndef __TRANSIP__ |
| 23 |
#define __TRANSIP__ |
| 24 |
|
| 25 |
// ====================================================================== |
| 26 |
// This is the com object that represents a simple transform filter. It |
| 27 |
// supports IBaseFilter, IMediaFilter and two pins through nested interfaces |
| 28 |
// ====================================================================== |
| 29 |
|
| 30 |
class CTransInPlaceFilter; |
| 31 |
|
| 32 |
// Several of the pin functions call filter functions to do the work, |
| 33 |
// so you can often use the pin classes unaltered, just overriding the |
| 34 |
// functions in CTransInPlaceFilter. If that's not enough and you want |
| 35 |
// to derive your own pin class, override GetPin in the filter to supply |
| 36 |
// your own pin classes to the filter. |
| 37 |
|
| 38 |
// ================================================== |
| 39 |
// Implements the input pin |
| 40 |
// ================================================== |
| 41 |
|
| 42 |
class CTransInPlaceInputPin : public CTransformInputPin |
| 43 |
{ |
| 44 |
|
| 45 |
protected: |
| 46 |
CTransInPlaceFilter * const m_pTIPFilter; // our filter |
| 47 |
BOOL m_bReadOnly; // incoming stream is read only |
| 48 |
|
| 49 |
public: |
| 50 |
|
| 51 |
CTransInPlaceInputPin( |
| 52 |
__in_opt LPCTSTR pObjectName, |
| 53 |
__inout CTransInPlaceFilter *pFilter, |
| 54 |
__inout HRESULT *phr, |
| 55 |
__in_opt LPCWSTR pName); |
| 56 |
|
| 57 |
// --- IMemInputPin ----- |
| 58 |
|
| 59 |
// Provide an enumerator for media types by getting one from downstream |
| 60 |
STDMETHODIMP EnumMediaTypes( __deref_out IEnumMediaTypes **ppEnum ); |
| 61 |
|
| 62 |
// Say whether media type is acceptable. |
| 63 |
HRESULT CheckMediaType(const CMediaType* pmt); |
| 64 |
|
| 65 |
// Return our upstream allocator |
| 66 |
STDMETHODIMP GetAllocator(__deref_out IMemAllocator ** ppAllocator); |
| 67 |
|
| 68 |
// get told which allocator the upstream output pin is actually |
| 69 |
// going to use. |
| 70 |
STDMETHODIMP NotifyAllocator(IMemAllocator * pAllocator, |
| 71 |
BOOL bReadOnly); |
| 72 |
|
| 73 |
// Allow the filter to see what allocator we have |
| 74 |
// N.B. This does NOT AddRef |
| 75 |
__out IMemAllocator * PeekAllocator() const |
| 76 |
{ return m_pAllocator; } |
| 77 |
|
| 78 |
// Pass this on downstream if it ever gets called. |
| 79 |
STDMETHODIMP GetAllocatorRequirements(__out ALLOCATOR_PROPERTIES *pProps); |
| 80 |
|
| 81 |
HRESULT CompleteConnect(IPin *pReceivePin); |
| 82 |
|
| 83 |
inline const BOOL ReadOnly() { return m_bReadOnly ; } |
| 84 |
|
| 85 |
}; // CTransInPlaceInputPin |
| 86 |
|
| 87 |
// ================================================== |
| 88 |
// Implements the output pin |
| 89 |
// ================================================== |
| 90 |
|
| 91 |
class CTransInPlaceOutputPin : public CTransformOutputPin |
| 92 |
{ |
| 93 |
|
| 94 |
protected: |
| 95 |
// m_pFilter points to our CBaseFilter |
| 96 |
CTransInPlaceFilter * const m_pTIPFilter; |
| 97 |
|
| 98 |
public: |
| 99 |
|
| 100 |
CTransInPlaceOutputPin( |
| 101 |
__in_opt LPCTSTR pObjectName, |
| 102 |
__inout CTransInPlaceFilter *pFilter, |
| 103 |
__inout HRESULT *phr, |
| 104 |
__in_opt LPCWSTR pName); |
| 105 |
|
| 106 |
|
| 107 |
// --- CBaseOutputPin ------------ |
| 108 |
|
| 109 |
// negotiate the allocator and its buffer size/count |
| 110 |
// Insists on using our own allocator. (Actually the one upstream of us). |
| 111 |
// We don't override this - instead we just agree the default |
| 112 |
// then let the upstream filter decide for itself on reconnect |
| 113 |
// virtual HRESULT DecideAllocator(IMemInputPin * pPin, IMemAllocator ** pAlloc); |
| 114 |
|
| 115 |
// Provide a media type enumerator. Get it from upstream. |
| 116 |
STDMETHODIMP EnumMediaTypes( __deref_out IEnumMediaTypes **ppEnum ); |
| 117 |
|
| 118 |
// Say whether media type is acceptable. |
| 119 |
HRESULT CheckMediaType(const CMediaType* pmt); |
| 120 |
|
| 121 |
// This just saves the allocator being used on the output pin |
| 122 |
// Also called by input pin's GetAllocator() |
| 123 |
void SetAllocator(IMemAllocator * pAllocator); |
| 124 |
|
| 125 |
__out_opt IMemInputPin * ConnectedIMemInputPin() |
| 126 |
{ return m_pInputPin; } |
| 127 |
|
| 128 |
// Allow the filter to see what allocator we have |
| 129 |
// N.B. This does NOT AddRef |
| 130 |
__out IMemAllocator * PeekAllocator() const |
| 131 |
{ return m_pAllocator; } |
| 132 |
|
| 133 |
HRESULT CompleteConnect(IPin *pReceivePin); |
| 134 |
|
| 135 |
}; // CTransInPlaceOutputPin |
| 136 |
|
| 137 |
|
| 138 |
class AM_NOVTABLE CTransInPlaceFilter : public CTransformFilter |
| 139 |
{ |
| 140 |
|
| 141 |
public: |
| 142 |
|
| 143 |
// map getpin/getpincount for base enum of pins to owner |
| 144 |
// override this to return more specialised pin objects |
| 145 |
|
| 146 |
virtual CBasePin *GetPin(int n); |
| 147 |
|
| 148 |
public: |
| 149 |
|
| 150 |
// Set bModifiesData == false if your derived filter does |
| 151 |
// not modify the data samples (for instance it's just copying |
| 152 |
// them somewhere else or looking at the timestamps). |
| 153 |
|
| 154 |
CTransInPlaceFilter(__in_opt LPCTSTR, __inout_opt LPUNKNOWN, REFCLSID clsid, __inout HRESULT *, |
| 155 |
bool bModifiesData = true); |
| 156 |
#ifdef UNICODE |
| 157 |
CTransInPlaceFilter(__in_opt LPCSTR, __inout_opt LPUNKNOWN, REFCLSID clsid, __inout HRESULT *, |
| 158 |
bool bModifiesData = true); |
| 159 |
#endif |
| 160 |
// The following are defined to avoid undefined pure virtuals. |
| 161 |
// Even if they are never called, they will give linkage warnings/errors |
| 162 |
|
| 163 |
// We override EnumMediaTypes to bypass the transform class enumerator |
| 164 |
// which would otherwise call this. |
| 165 |
HRESULT GetMediaType(int iPosition, __inout CMediaType *pMediaType) |
| 166 |
{ DbgBreak("CTransInPlaceFilter::GetMediaType should never be called"); |
| 167 |
return E_UNEXPECTED; |
| 168 |
} |
| 169 |
|
| 170 |
// This is called when we actually have to provide our own allocator. |
| 171 |
HRESULT DecideBufferSize(IMemAllocator*, __inout ALLOCATOR_PROPERTIES *); |
| 172 |
|
| 173 |
// The functions which call this in CTransform are overridden in this |
| 174 |
// class to call CheckInputType with the assumption that the type |
| 175 |
// does not change. In Debug builds some calls will be made and |
| 176 |
// we just ensure that they do not assert. |
| 177 |
HRESULT CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut) |
| 178 |
{ |
| 179 |
return S_OK; |
| 180 |
}; |
| 181 |
|
| 182 |
|
| 183 |
// ================================================================= |
| 184 |
// ----- You may want to override this ----------------------------- |
| 185 |
// ================================================================= |
| 186 |
|
| 187 |
HRESULT CompleteConnect(PIN_DIRECTION dir,IPin *pReceivePin); |
| 188 |
|
| 189 |
// chance to customize the transform process |
| 190 |
virtual HRESULT Receive(IMediaSample *pSample); |
| 191 |
|
| 192 |
// ================================================================= |
| 193 |
// ----- You MUST override these ----------------------------------- |
| 194 |
// ================================================================= |
| 195 |
|
| 196 |
virtual HRESULT Transform(IMediaSample *pSample) PURE; |
| 197 |
|
| 198 |
// this goes in the factory template table to create new instances |
| 199 |
// static CCOMObject * CreateInstance(LPUNKNOWN, HRESULT *); |
| 200 |
|
| 201 |
|
| 202 |
#ifdef PERF |
| 203 |
// Override to register performance measurement with a less generic string |
| 204 |
// You should do this to avoid confusion with other filters |
| 205 |
virtual void RegisterPerfId() |
| 206 |
{m_idTransInPlace = MSR_REGISTER(TEXT("TransInPlace"));} |
| 207 |
#endif // PERF |
| 208 |
|
| 209 |
|
| 210 |
// implementation details |
| 211 |
|
| 212 |
protected: |
| 213 |
|
| 214 |
__out_opt IMediaSample * CTransInPlaceFilter::Copy(IMediaSample *pSource); |
| 215 |
|
| 216 |
#ifdef PERF |
| 217 |
int m_idTransInPlace; // performance measuring id |
| 218 |
#endif // PERF |
| 219 |
bool m_bModifiesData; // Does this filter change the data? |
| 220 |
|
| 221 |
// these hold our input and output pins |
| 222 |
|
| 223 |
friend class CTransInPlaceInputPin; |
| 224 |
friend class CTransInPlaceOutputPin; |
| 225 |
|
| 226 |
__out CTransInPlaceInputPin *InputPin() const |
| 227 |
{ |
| 228 |
return (CTransInPlaceInputPin *)m_pInput; |
| 229 |
}; |
| 230 |
__out CTransInPlaceOutputPin *OutputPin() const |
| 231 |
{ |
| 232 |
return (CTransInPlaceOutputPin *)m_pOutput; |
| 233 |
}; |
| 234 |
|
| 235 |
// Helper to see if the input and output types match |
| 236 |
BOOL TypesMatch() |
| 237 |
{ |
| 238 |
return InputPin()->CurrentMediaType() == |
| 239 |
OutputPin()->CurrentMediaType(); |
| 240 |
} |
| 241 |
|
| 242 |
// Are the input and output allocators different? |
| 243 |
BOOL UsingDifferentAllocators() const |
| 244 |
{ |
| 245 |
return InputPin()->PeekAllocator() != OutputPin()->PeekAllocator(); |
| 246 |
} |
| 247 |
}; // CTransInPlaceFilter |
| 248 |
|
| 249 |
#endif /* __TRANSIP__ */ |
| 250 |
|