BaseSource.h

00001 /* 
00002  *      Copyright (C) 2003-2005 Gabest
00003  *      http://www.gabest.org
00004  *
00005  *  This Program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2, or (at your option)
00008  *  any later version.
00009  *   
00010  *  This Program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  *  GNU General Public License for more details.
00014  *   
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with GNU Make; see the file COPYING.  If not, write to
00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
00018  *  http://www.gnu.org/copyleft/gpl.html
00019  *
00020  */
00021 
00022 #pragma once
00023 
00024 #include "..\..\..\DSUtil\DSUtil.h"
00025 
00026 template<class TStream>
00027 class CBaseSource
00028         : public CSource
00029         , public IFileSourceFilter
00030         , public IAMFilterMiscFlags
00031 {
00032 protected:
00033         CStringW m_fn;
00034 
00035 public:
00036         CBaseSource(TCHAR* name, LPUNKNOWN lpunk, HRESULT* phr, const CLSID& clsid)
00037                 : CSource(name, lpunk, clsid)
00038         {
00039                 if(phr) *phr = S_OK;
00040         }
00041 
00042         DECLARE_IUNKNOWN;
00043     STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv)
00044         {
00045                 CheckPointer(ppv, E_POINTER);
00046 
00047                 return 
00048                         QI(IFileSourceFilter)
00049                         QI(IAMFilterMiscFlags)
00050                         __super::NonDelegatingQueryInterface(riid, ppv);
00051         }
00052 
00053         // IFileSourceFilter
00054 
00055         STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
00056         {
00057                 // TODO: destroy any already existing pins and create new, now we are just going die nicely instead of doing it :)
00058                 if(GetPinCount() > 0)
00059                         return VFW_E_ALREADY_CONNECTED;
00060 
00061                 HRESULT hr = S_OK;
00062                 if(!(new TStream(pszFileName, this, &hr)))
00063                         return E_OUTOFMEMORY;
00064 
00065                 if(FAILED(hr))
00066                         return hr;
00067 
00068                 m_fn = pszFileName;
00069 
00070                 return S_OK;
00071         }
00072 
00073         STDMETHODIMP GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
00074         {
00075                 if(!ppszFileName) return E_POINTER;
00076                 
00077                 if(!(*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength()+1)*sizeof(WCHAR))))
00078                         return E_OUTOFMEMORY;
00079 
00080                 wcscpy(*ppszFileName, m_fn);
00081 
00082                 return S_OK;
00083         }
00084 
00085         // IAMFilterMiscFlags
00086 
00087         STDMETHODIMP_(ULONG) GetMiscFlags()
00088         {
00089                 return AM_FILTER_MISC_FLAGS_IS_SOURCE;
00090         }
00091 };
00092 
00093 class CBaseStream 
00094         : public CSourceStream
00095         , public CSourceSeeking
00096 {
00097 protected:
00098         CCritSec m_cSharedState;
00099 
00100         REFERENCE_TIME m_AvgTimePerFrame;
00101         REFERENCE_TIME m_rtSampleTime, m_rtPosition;
00102 
00103         BOOL m_bDiscontinuity, m_bFlushing;
00104 
00105         HRESULT OnThreadStartPlay();
00106         HRESULT OnThreadCreate();
00107 
00108 private:
00109         void UpdateFromSeek();
00110         STDMETHODIMP SetRate(double dRate);
00111 
00112         HRESULT ChangeStart();
00113     HRESULT ChangeStop();
00114     HRESULT ChangeRate() {return S_OK;}
00115 
00116 public:
00117     CBaseStream(TCHAR* name, CSource* pParent, HRESULT* phr);
00118         virtual ~CBaseStream();
00119 
00120     STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
00121 
00122     HRESULT FillBuffer(IMediaSample* pSample);
00123 
00124     virtual HRESULT FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len /*in+out*/) = 0;
00125 
00126         STDMETHODIMP Notify(IBaseFilter* pSender, Quality q);
00127 };

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