GraphBuilder.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 <atlcoll.h>
00025 
00026 #define LMERIT(m) ((ULONGLONG(m))<<16)
00027 #define LMERIT_DO_NOT_USE LMERIT(MERIT_DO_NOT_USE)
00028 #define LMERIT_DO_USE LMERIT(MERIT_DO_NOT_USE+1)
00029 #define LMERIT_UNLIKELY (LMERIT(MERIT_UNLIKELY))
00030 #define LMERIT_NORMAL (LMERIT(MERIT_NORMAL))
00031 #define LMERIT_PREFERRED (LMERIT(MERIT_PREFERRED))
00032 #define LMERIT_ABOVE_DSHOW (LMERIT(1)<<32)
00033 
00034 class CGraphFilter
00035 {
00036 protected:
00037         CStringW m_name;
00038         struct {union {ULONGLONG val; struct {ULONGLONG low:16, mid:32, high:16;};};} m_merit;
00039         CLSID m_clsid;
00040         CList<GUID> m_guids;
00041 
00042 public:
00043         CGraphFilter(CStringW name = L"", ULONGLONG merit = LMERIT_DO_USE);
00044         virtual ~CGraphFilter() {}
00045 
00046         CStringW GetName() {return(m_name);}
00047         ULONGLONG GetMerit() {return(m_merit.val);}
00048         DWORD GetDWORDMerit() {return(m_merit.mid);}
00049         CLSID GetCLSID() {return(m_clsid);}
00050         void GetGUIDs(CList<GUID>& guids) {guids.RemoveAll(); guids.AddTail(&m_guids);}
00051         void SetGUIDs(CList<GUID>& guids) {m_guids.RemoveAll(); m_guids.AddTail(&guids);}
00052         bool IsExactMatch(CArray<GUID>& guids);
00053         bool IsCompatible(CArray<GUID>& guids);
00054 
00055         virtual HRESULT Create(IBaseFilter** ppBF, IUnknown** ppUnk) = 0;
00056 };
00057 
00058 class CGraphRegFilter : public CGraphFilter
00059 {
00060 protected:
00061         CStringW m_dispname;
00062         CComPtr<IMoniker> m_pMoniker;
00063 
00064         void ExtractFilterData(BYTE* p, UINT len);
00065 
00066 public:
00067         CGraphRegFilter(IMoniker* pMoniker, ULONGLONG merit = LMERIT_DO_USE);
00068         CGraphRegFilter(CStringW m_dispname, ULONGLONG merit = LMERIT_DO_USE);
00069         CGraphRegFilter(const CLSID& clsid, ULONGLONG merit = LMERIT_DO_USE);
00070 
00071         CStringW GetDispName() {return(m_dispname);}
00072         CComPtr<IMoniker> GetMoniker() {return(m_pMoniker);}
00073 
00074         HRESULT Create(IBaseFilter** ppBF, IUnknown** ppUnk);
00075 };
00076 
00077 class CGraphCustomFilter : public CGraphFilter
00078 {
00079 public:
00080         CGraphCustomFilter(const CLSID& clsid, CList<GUID>& guids, CStringW name = L"", ULONGLONG merit = LMERIT_DO_USE);
00081 
00082         HRESULT Create(IBaseFilter** ppBF, IUnknown** ppUnk);
00083 };
00084 
00085 class CGraphFileFilter : public CGraphCustomFilter
00086 {
00087 protected:
00088         CString m_path;
00089         HINSTANCE m_hInst;
00090 
00091 public:
00092         CGraphFileFilter(const CLSID& clsid, CList<GUID>& guids, CString path, CStringW name = L"", ULONGLONG merit = LMERIT_DO_USE);
00093 
00094         HRESULT Create(IBaseFilter** ppBF, IUnknown** ppUnk);
00095 };
00096 
00097 class CGraphRendererFilter : public CGraphFilter
00098 {
00099 protected:
00100         CLSID m_clsid;
00101         HWND m_hWnd;
00102 
00103 public:
00104         CGraphRendererFilter(const CLSID& clsid, HWND hWnd, CStringW name = L"", ULONGLONG merit = LMERIT_DO_USE);
00105 
00106         HRESULT Create(IBaseFilter** ppBF, IUnknown** ppUnk);
00107 };
00108 
00109 class CGraphBuilder
00110 {
00111 public:
00112         typedef struct {int nStream; CString clsid, filter, pin; CList<CMediaType> mts; CList<CString> path;} DeadEnd;
00113 
00114 protected:
00115         HWND m_hWnd;
00116         CComPtr<IGraphBuilder> m_pGB;
00117         CComPtr<IFilterMapper2> m_pFM;
00118         CInterfaceList<IUnknown, &IID_IUnknown> m_pUnks;
00119         CAutoPtrList<CGraphFilter> m_pMoreFilters;
00120         ULONGLONG m_VRMerit, m_ARMerit;
00121 
00122         UINT m_nTotalStreams, m_nCurrentStream;
00123         CList<CGraphFilter*> m_chain;
00124 
00125         void ExtractMediaTypes(IPin* pPin, CArray<GUID>& guids);
00126         void ExtractMediaTypes(IPin* pPin, CList<CMediaType>& mts);
00127 
00128         void SaveFilters(CInterfaceList<IBaseFilter>& bfl);
00129         void RestoreFilters(CInterfaceList<IBaseFilter>& bfl);
00130 
00131         HRESULT SafeAddFilter(IBaseFilter* pBF, LPCWSTR pName);
00132 
00133         CAutoPtrArray<DeadEnd> m_DeadEnds;
00134 /*
00135         CList<CString> m_log;
00136         void LOG(LPCTSTR fmt, ...);
00137 */
00138         HRESULT ConnectDirect(IPin* pPin, IBaseFilter* pBF, const AM_MEDIA_TYPE* pmt = NULL);
00139 
00140 public:
00141         CGraphBuilder(IGraphBuilder* pGB, HWND hWnd);
00142         virtual ~CGraphBuilder();
00143 
00144         void Reset();
00145 
00146         void AddFilter(CGraphFilter* pFilter) {if(pFilter) {CAutoPtr<CGraphFilter> f(pFilter); m_pMoreFilters.AddTail(f);}}
00147         void RemoveFilters() {m_pMoreFilters.RemoveAll();}
00148 
00149         HRESULT AddSourceFilter(LPCTSTR fn, IBaseFilter** ppBF, UINT SrcFilters = 0xffffffff);
00150 
00151         HRESULT Render(LPCTSTR fn);
00152         HRESULT Render(IBaseFilter* pBF);
00153         HRESULT Render(IPin* pPin);
00154 
00155         HRESULT FindInterface(REFIID iid, void** ppv);
00156 
00157         int GetStreamCount() {return m_nTotalStreams;}
00158         DeadEnd* GetDeadEnd(int i) {return (i >= 0 && i < (int)m_DeadEnds.GetCount()) ? (DeadEnd*)m_DeadEnds[i] : NULL;}
00159 };
00160 
00161 class CGraphBuilderFile : public CGraphBuilder
00162 {
00163 public:
00164         CGraphBuilderFile(IGraphBuilder* pGB, HWND hWnd);
00165 };
00166 
00167 class CGraphBuilderDVD : public CGraphBuilderFile
00168 {
00169 public:
00170         CGraphBuilderDVD(IGraphBuilder* pGB, HWND hWnd);
00171 
00172         HRESULT Render(CString fn, CString& path);
00173 };
00174 
00175 class CGraphBuilderCapture : public CGraphBuilderFile
00176 {
00177 public:
00178         CGraphBuilderCapture(IGraphBuilder* pGB, HWND hWnd);
00179 };

Generated on Tue Dec 13 14:46:51 2005 for guliverkli by  doxygen 1.4.5