asyncrdr.h

00001 #pragma once
00002 
00003 //
00004 // AsyncRdr
00005 //
00006 // Defines an IO source filter.
00007 //
00008 // This filter (CAsyncReader) supports IBaseFilter and IFileSourceFilter interfaces from the
00009 // filter object itself. It has a single output pin (CAsyncOutputPin)
00010 // which supports IPin and IAsyncReader.
00011 //
00012 // This filter is essentially a wrapper for the CAsyncFile class that does
00013 // all the work.
00014 //
00015 
00016 // the filter class (defined below)
00017 class CAsyncReader;
00018 
00019 
00020 // the output pin class
00021 class CAsyncOutputPin
00022   : public IAsyncReader,
00023     public CBasePin
00024 {
00025 protected:
00026     CAsyncReader* m_pReader;
00027     CAsyncIo * m_pIo;
00028 
00029     //  This is set every time we're asked to return an IAsyncReader
00030     //  interface
00031     //  This allows us to know if the downstream pin can use
00032     //  this transport, otherwise we can hook up to thinks like the
00033     //  dump filter and nothing happens
00034     BOOL         m_bQueriedForAsyncReader;
00035 
00036     HRESULT InitAllocator(IMemAllocator **ppAlloc);
00037 
00038 public:
00039     // constructor and destructor
00040     CAsyncOutputPin(
00041         HRESULT * phr,
00042         CAsyncReader *pReader,
00043         CAsyncIo *pIo,
00044         CCritSec * pLock);
00045 
00046     ~CAsyncOutputPin();
00047 
00048     // --- CUnknown ---
00049 
00050     // need to expose IAsyncReader
00051     DECLARE_IUNKNOWN
00052     STDMETHODIMP NonDelegatingQueryInterface(REFIID, void**);
00053 
00054     // --- IPin methods ---
00055     STDMETHODIMP Connect(
00056         IPin * pReceivePin,
00057         const AM_MEDIA_TYPE *pmt   // optional media type
00058     );
00059 
00060     // --- CBasePin methods ---
00061 
00062     // return the types we prefer - this will return the known
00063     // file type
00064     HRESULT GetMediaType(int iPosition, CMediaType *pMediaType);
00065 
00066     // can we support this type?
00067     HRESULT CheckMediaType(const CMediaType* pType);
00068 
00069     // Clear the flag so we see if IAsyncReader is queried for
00070     HRESULT CheckConnect(IPin *pPin)
00071     {
00072         m_bQueriedForAsyncReader = FALSE;
00073         return CBasePin::CheckConnect(pPin);
00074     }
00075 
00076     // See if it was asked for
00077     HRESULT CompleteConnect(IPin *pReceivePin)
00078     {
00079         if (m_bQueriedForAsyncReader) {
00080             return CBasePin::CompleteConnect(pReceivePin);
00081         } else {
00082 #ifdef VFW_E_NO_TRANSPORT
00083             return VFW_E_NO_TRANSPORT;
00084 #else
00085             return E_FAIL;
00086 #endif
00087         }
00088     }
00089 
00090     //  Remove our connection status
00091     HRESULT BreakConnect()
00092     {
00093         m_bQueriedForAsyncReader = FALSE;
00094         return CBasePin::BreakConnect();
00095     }
00096 
00097     // --- IAsyncReader methods ---
00098     // pass in your preferred allocator and your preferred properties.
00099     // method returns the actual allocator to be used. Call GetProperties
00100     // on returned allocator to learn alignment and prefix etc chosen.
00101     // this allocator will be not be committed and decommitted by
00102     // the async reader, only by the consumer.
00103     STDMETHODIMP RequestAllocator(
00104                       IMemAllocator* pPreferred,
00105                       ALLOCATOR_PROPERTIES* pProps,
00106                       IMemAllocator ** ppActual);
00107 
00108     // queue a request for data.
00109     // media sample start and stop times contain the requested absolute
00110     // byte position (start inclusive, stop exclusive).
00111     // may fail if sample not obtained from agreed allocator.
00112     // may fail if start/stop position does not match agreed alignment.
00113     // samples allocated from source pin's allocator may fail
00114     // GetPointer until after returning from WaitForNext.
00115     STDMETHODIMP Request(
00116                      IMediaSample* pSample,
00117                      DWORD dwUser);             // user context
00118 
00119     // block until the next sample is completed or the timeout occurs.
00120     // timeout (millisecs) may be 0 or INFINITE. Samples may not
00121     // be delivered in order. If there is a read error of any sort, a
00122     // notification will already have been sent by the source filter,
00123     // and STDMETHODIMP will be an error.
00124     STDMETHODIMP WaitForNext(
00125                       DWORD dwTimeout,
00126                       IMediaSample** ppSample,  // completed sample
00127                       DWORD * pdwUser);         // user context
00128 
00129     // sync read of data. Sample passed in must have been acquired from
00130     // the agreed allocator. Start and stop position must be aligned.
00131     // equivalent to a Request/WaitForNext pair, but may avoid the
00132     // need for a thread on the source filter.
00133     STDMETHODIMP SyncReadAligned(
00134                       IMediaSample* pSample);
00135 
00136 
00137     // sync read. works in stopped state as well as run state.
00138     // need not be aligned. Will fail if read is beyond actual total
00139     // length.
00140     STDMETHODIMP SyncRead(
00141                       LONGLONG llPosition,      // absolute file position
00142                       LONG lLength,             // nr bytes required
00143                       BYTE* pBuffer);           // write data here
00144 
00145     // return total length of stream, and currently available length.
00146     // reads for beyond the available length but within the total length will
00147     // normally succeed but may block for a long period.
00148     STDMETHODIMP Length(
00149                       LONGLONG* pTotal,
00150                       LONGLONG* pAvailable);
00151 
00152     // cause all outstanding reads to return, possibly with a failure code
00153     // (VFW_E_TIMEOUT) indicating they were cancelled.
00154     // these are defined on IAsyncReader and IPin
00155     STDMETHODIMP BeginFlush(void);
00156     STDMETHODIMP EndFlush(void);
00157 
00158 };
00159 
00160 
00161 //
00162 // The filter object itself. Supports IBaseFilter through
00163 // CBaseFilter and also IFileSourceFilter directly in this object
00164 
00165 class CAsyncReader : public CBaseFilter, public IAMFilterMiscFlags
00166 {
00167 
00168 protected:
00169     // filter-wide lock
00170     CCritSec m_csFilter;
00171 
00172     // all i/o done here
00173     CAsyncIo m_Io;
00174 
00175     // our output pin
00176     CAsyncOutputPin m_OutputPin;
00177 
00178     // Type we think our data is
00179     CMediaType            m_mt;
00180 
00181 public:
00182                 
00183     // construction / destruction
00184 
00185     CAsyncReader(
00186         TCHAR *pName,
00187         LPUNKNOWN pUnk,
00188         CAsyncStream *pStream,
00189         HRESULT *phr,
00190                 const CLSID& clsid);
00191     ~CAsyncReader();
00192 
00193         DECLARE_IUNKNOWN;
00194     STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
00195 
00196         // IAMFilterMiscFlags
00197         STDMETHODIMP_(ULONG) GetMiscFlags();
00198 
00199     // --- CBaseFilter methods ---
00200     int GetPinCount();
00201     CBasePin *GetPin(int n);
00202 
00203     // --- Access our media type
00204     const CMediaType *LoadType() const
00205     {
00206         return &m_mt;
00207     }
00208 
00209     virtual HRESULT Connect(
00210         IPin * pReceivePin,
00211         const AM_MEDIA_TYPE *pmt   // optional media type
00212     )
00213     {
00214         return m_OutputPin.CBasePin::Connect(pReceivePin, pmt);
00215     }
00216 };

Generated on Tue Dec 13 14:47:23 2005 for guliverkli by  doxygen 1.4.5