DSUtil.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 #ifdef UNICODE
00025 #ifdef DEBUG
00026 #pragma comment(lib, "dsutilDU")
00027 #else
00028 #pragma comment(lib, "dsutilRU")
00029 #endif
00030 #else
00031 #ifdef DEBUG
00032 #pragma comment(lib, "dsutilD")
00033 #else
00034 #pragma comment(lib, "dsutilR")
00035 #endif
00036 #endif
00037 
00038 #include <afx.h>
00039 #include <afxwin.h>
00040 #include <afxtempl.h>
00041 #include "NullRenderers.h"
00042 //#include "MediaTypes.h"
00043 #include "MediaTypeEx.h"
00044 #include "vd.h"
00045 #include "text.h"
00046 
00047 extern void DumpStreamConfig(TCHAR* fn, IAMStreamConfig* pAMVSCCap);
00048 extern int CountPins(IBaseFilter* pBF, int& nIn, int& nOut, int& nInC, int& nOutC);
00049 extern bool IsSplitter(IBaseFilter* pBF, bool fCountConnectedOnly = false);
00050 extern bool IsMultiplexer(IBaseFilter* pBF, bool fCountConnectedOnly = false);
00051 extern bool IsStreamStart(IBaseFilter* pBF);
00052 extern bool IsStreamEnd(IBaseFilter* pBF);
00053 extern bool IsVideoRenderer(IBaseFilter* pBF);
00054 extern bool IsAudioWaveRenderer(IBaseFilter* pBF);
00055 extern IBaseFilter* GetUpStreamFilter(IBaseFilter* pBF, IPin* pInputPin = NULL);
00056 extern IPin* GetUpStreamPin(IBaseFilter* pBF, IPin* pInputPin = NULL);
00057 extern IPin* GetFirstPin(IBaseFilter* pBF, PIN_DIRECTION dir = PINDIR_INPUT);
00058 extern IPin* GetFirstDisconnectedPin(IBaseFilter* pBF, PIN_DIRECTION dir);
00059 extern int RenderFilterPins(IBaseFilter* pBF, IGraphBuilder* pGB, bool fAll = false);
00060 extern void NukeDownstream(IBaseFilter* pBF, IFilterGraph* pFG);
00061 extern void NukeDownstream(IPin* pPin, IFilterGraph* pFG);
00062 extern HRESULT AddFilterToGraph(IFilterGraph* pFG, IBaseFilter* pBF, WCHAR* pName);
00063 extern IBaseFilter* FindFilter(LPCWSTR clsid, IFilterGraph* pFG);
00064 extern IBaseFilter* FindFilter(const CLSID& clsid, IFilterGraph* pFG);
00065 extern CStringW GetFilterName(IBaseFilter* pBF);
00066 extern CStringW GetPinName(IPin* pPin);
00067 extern IFilterGraph* GetGraphFromFilter(IBaseFilter* pBF);
00068 extern IBaseFilter* GetFilterFromPin(IPin* pPin);
00069 extern IPin* AppendFilter(IPin* pPin, CString DisplayName, IGraphBuilder* pGB);
00070 extern IPin* InsertFilter(IPin* pPin, CString DisplayName, IGraphBuilder* pGB);
00071 extern void ShowPPage(CString DisplayName, HWND hParentWnd);
00072 extern void ShowPPage(IUnknown* pUnknown, HWND hParentWnd);
00073 extern CLSID GetCLSID(IBaseFilter* pBF);
00074 extern CLSID GetCLSID(IPin* pPin);
00075 extern bool IsCLSIDRegistered(LPCTSTR clsid);
00076 extern bool IsCLSIDRegistered(const CLSID& clsid);
00077 extern void StringToBin(CString s, CByteArray& data);
00078 extern CString BinToString(BYTE* ptr, int len);
00079 typedef enum {CDROM_NotFound, CDROM_Audio, CDROM_VideoCD, CDROM_DVDVideo, CDROM_Unknown} cdrom_t;
00080 extern cdrom_t GetCDROMType(TCHAR drive, CList<CString>& files);
00081 extern CString GetDriveLabel(TCHAR drive);
00082 extern bool GetKeyFrames(CString fn, CUIntArray& kfs);
00083 extern DVD_HMSF_TIMECODE RT2HMSF(REFERENCE_TIME rt, double fps = 0);
00084 extern REFERENCE_TIME HMSF2RT(DVD_HMSF_TIMECODE hmsf, double fps = 0);
00085 extern HRESULT AddToRot(IUnknown* pUnkGraph, DWORD* pdwRegister);
00086 extern void RemoveFromRot(DWORD& dwRegister);
00087 extern void memsetd(void* dst, unsigned int c, int nbytes);
00088 extern bool ExtractBIH(const AM_MEDIA_TYPE* pmt, BITMAPINFOHEADER* bih);
00089 extern bool ExtractBIH(IMediaSample* pMS, BITMAPINFOHEADER* bih);
00090 extern bool ExtractDim(const AM_MEDIA_TYPE* pmt, int& w, int& h, int& arx, int& ary);
00091 extern bool MakeMPEG2MediaType(CMediaType& mt, BYTE* seqhdr, DWORD len, int w, int h);
00092 extern unsigned __int64 GetFileVersion(LPCTSTR fn);
00093 extern bool CreateFilter(CStringW DisplayName, IBaseFilter** ppBF, CStringW& FriendlyName);
00094 extern IBaseFilter* AppendFilter(IPin* pPin, IMoniker* pMoniker, IGraphBuilder* pGB);
00095 extern CStringW GetFriendlyName(CStringW DisplayName);
00096 extern HRESULT LoadExternalObject(LPCTSTR path, REFCLSID clsid, REFIID iid, void** ppv);
00097 extern HRESULT LoadExternalFilter(LPCTSTR path, REFCLSID clsid, IBaseFilter** ppBF);
00098 extern HRESULT LoadExternalPropertyPage(IPersist* pP, REFCLSID clsid, IPropertyPage** ppPP);
00099 extern void UnloadExternalObjects();
00100 extern CString MakeFullPath(LPCTSTR path);
00101 extern CString GetMediaTypeName(const GUID& guid);
00102 extern GUID GUIDFromCString(CString str);
00103 extern CString CStringFromGUID(const GUID& guid);
00104 extern CStringW UTF8To16(LPCSTR utf8);
00105 extern CStringA UTF16To8(LPCWSTR utf16);
00106 extern CString ISO6391ToLanguage(LPCSTR code);
00107 extern CString ISO6392ToLanguage(LPCSTR code);
00108 extern CString ISO6391To6392(LPCSTR code);
00109 extern CString LanguageToISO6392(LPCTSTR lang);
00110 extern int MakeAACInitData(BYTE* pData, int profile, int freq, int channels);
00111 extern BOOL CFileGetStatus(LPCTSTR lpszFileName, CFileStatus& status);
00112 extern bool DeleteRegKey(LPCTSTR pszKey, LPCTSTR pszSubkey);
00113 extern bool SetRegKeyValue(LPCTSTR pszKey, LPCTSTR pszSubkey, LPCTSTR pszValueName, LPCTSTR pszValue);
00114 extern bool SetRegKeyValue(LPCTSTR pszKey, LPCTSTR pszSubkey, LPCTSTR pszValue);
00115 extern void RegisterSourceFilter(const CLSID& clsid, const GUID& subtype2, LPCTSTR chkbytes, LPCTSTR ext = NULL, ...);
00116 extern void RegisterSourceFilter(const CLSID& clsid, const GUID& subtype2, const CList<CString>& chkbytes, LPCTSTR ext = NULL, ...);
00117 extern void UnRegisterSourceFilter(const GUID& subtype);
00118 
00119 class CPinInfo : public PIN_INFO
00120 {
00121 public:
00122         CPinInfo() {pFilter = NULL;}
00123         ~CPinInfo() {if(pFilter) pFilter->Release();}
00124 };
00125 
00126 class CFilterInfo : public FILTER_INFO
00127 {
00128 public:
00129         CFilterInfo() {pGraph = NULL;}
00130         ~CFilterInfo() {if(pGraph) pGraph->Release();}
00131 };
00132 
00133 #define BeginEnumFilters(pFilterGraph, pEnumFilters, pBaseFilter) \
00134         {CComPtr<IEnumFilters> pEnumFilters; \
00135         if(pFilterGraph && SUCCEEDED(pFilterGraph->EnumFilters(&pEnumFilters))) \
00136         { \
00137                 for(CComPtr<IBaseFilter> pBaseFilter; S_OK == pEnumFilters->Next(1, &pBaseFilter, 0); pBaseFilter = NULL) \
00138                 { \
00139 
00140 #define EndEnumFilters }}}
00141 
00142 #define BeginEnumPins(pBaseFilter, pEnumPins, pPin) \
00143         {CComPtr<IEnumPins> pEnumPins; \
00144         if(pBaseFilter && SUCCEEDED(pBaseFilter->EnumPins(&pEnumPins))) \
00145         { \
00146                 for(CComPtr<IPin> pPin; S_OK == pEnumPins->Next(1, &pPin, 0); pPin = NULL) \
00147                 { \
00148 
00149 #define EndEnumPins }}}
00150 
00151 #define BeginEnumMediaTypes(pPin, pEnumMediaTypes, pMediaType) \
00152         {CComPtr<IEnumMediaTypes> pEnumMediaTypes; \
00153         if(pPin && SUCCEEDED(pPin->EnumMediaTypes(&pEnumMediaTypes))) \
00154         { \
00155                 AM_MEDIA_TYPE* pMediaType = NULL; \
00156                 for(; S_OK == pEnumMediaTypes->Next(1, &pMediaType, NULL); DeleteMediaType(pMediaType), pMediaType = NULL) \
00157                 { \
00158 
00159 #define EndEnumMediaTypes(pMediaType) } if(pMediaType) DeleteMediaType(pMediaType); }}
00160 
00161 #define BeginEnumSysDev(clsid, pMoniker) \
00162         {CComPtr<ICreateDevEnum> pDevEnum4$##clsid; \
00163         pDevEnum4$##clsid.CoCreateInstance(CLSID_SystemDeviceEnum); \
00164         CComPtr<IEnumMoniker> pClassEnum4$##clsid; \
00165         if(SUCCEEDED(pDevEnum4$##clsid->CreateClassEnumerator(clsid, &pClassEnum4$##clsid, 0)) \
00166         && pClassEnum4$##clsid) \
00167         { \
00168                 for(CComPtr<IMoniker> pMoniker; pClassEnum4$##clsid->Next(1, &pMoniker, 0) == S_OK; pMoniker = NULL) \
00169                 { \
00170 
00171 #define EndEnumSysDev }}}
00172 
00173 #define QI(i) (riid == __uuidof(i)) ? GetInterface((i*)this, ppv) :
00174 #define QI2(i) (riid == IID_##i) ? GetInterface((i*)this, ppv) :
00175 
00176 template <typename T> __inline void INITDDSTRUCT(T& dd)
00177 {
00178     ZeroMemory(&dd, sizeof(dd));
00179     dd.dwSize = sizeof(dd);
00180 }
00181 
00182 #define countof(array) (sizeof(array)/sizeof(array[0]))
00183 
00184 template <class T>
00185 static CUnknown* WINAPI CreateInstance(LPUNKNOWN lpunk, HRESULT* phr)
00186 {
00187         *phr = S_OK;
00188     CUnknown* punk = new T(lpunk, phr);
00189     if(punk == NULL) *phr = E_OUTOFMEMORY;
00190         return punk;
00191 }

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