2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
26 #pragma comment(lib, "dsutilDU")
28 #pragma comment(lib, "dsutilRU")
32 #pragma comment(lib, "dsutilD")
34 #pragma comment(lib, "dsutilR")
38 #include "NullRenderers.h"
39 //#include "MediaTypes.h"
40 #include "MediaTypeEx.h"
44 #define LCID_NOSUBTITLES -1
46 extern void DumpStreamConfig(TCHAR
* fn
, IAMStreamConfig
* pAMVSCCap
);
47 extern int CountPins(IBaseFilter
* pBF
, int& nIn
, int& nOut
, int& nInC
, int& nOutC
);
48 extern bool IsSplitter(IBaseFilter
* pBF
, bool fCountConnectedOnly
= false);
49 extern bool IsMultiplexer(IBaseFilter
* pBF
, bool fCountConnectedOnly
= false);
50 extern bool IsStreamStart(IBaseFilter
* pBF
);
51 extern bool IsStreamEnd(IBaseFilter
* pBF
);
52 extern bool IsVideoRenderer(IBaseFilter
* pBF
);
53 extern bool IsAudioWaveRenderer(IBaseFilter
* pBF
);
54 extern IBaseFilter
* GetUpStreamFilter(IBaseFilter
* pBF
, IPin
* pInputPin
= NULL
);
55 extern IPin
* GetUpStreamPin(IBaseFilter
* pBF
, IPin
* pInputPin
= NULL
);
56 extern IPin
* GetFirstPin(IBaseFilter
* pBF
, PIN_DIRECTION dir
= PINDIR_INPUT
);
57 extern IPin
* GetFirstDisconnectedPin(IBaseFilter
* pBF
, PIN_DIRECTION dir
);
58 extern void NukeDownstream(IBaseFilter
* pBF
, IFilterGraph
* pFG
);
59 extern void NukeDownstream(IPin
* pPin
, IFilterGraph
* pFG
);
60 extern IBaseFilter
* FindFilter(LPCWSTR clsid
, IFilterGraph
* pFG
);
61 extern IBaseFilter
* FindFilter(const CLSID
& clsid
, IFilterGraph
* pFG
);
62 extern CStringW
GetFilterName(IBaseFilter
* pBF
);
63 extern CStringW
GetPinName(IPin
* pPin
);
64 extern IFilterGraph
* GetGraphFromFilter(IBaseFilter
* pBF
);
65 extern IBaseFilter
* GetFilterFromPin(IPin
* pPin
);
66 extern IPin
* AppendFilter(IPin
* pPin
, CString DisplayName
, IGraphBuilder
* pGB
);
67 extern IPin
* InsertFilter(IPin
* pPin
, CString DisplayName
, IGraphBuilder
* pGB
);
68 extern void ExtractMediaTypes(IPin
* pPin
, CAtlArray
<GUID
>& types
);
69 extern void ExtractMediaTypes(IPin
* pPin
, CAtlList
<CMediaType
>& mts
);
70 extern void ShowPPage(CString DisplayName
, HWND hParentWnd
);
71 extern void ShowPPage(IUnknown
* pUnknown
, HWND hParentWnd
);
72 extern CLSID
GetCLSID(IBaseFilter
* pBF
);
73 extern CLSID
GetCLSID(IPin
* pPin
);
74 extern bool IsCLSIDRegistered(LPCTSTR clsid
);
75 extern bool IsCLSIDRegistered(const CLSID
& clsid
);
76 extern void CStringToBin(CString str
, CAtlArray
<BYTE
>& data
);
77 extern CString
BinToCString(BYTE
* ptr
, int len
);
78 typedef enum {CDROM_NotFound
, CDROM_Audio
, CDROM_VideoCD
, CDROM_DVDVideo
, CDROM_Unknown
} cdrom_t
;
79 extern cdrom_t
GetCDROMType(TCHAR drive
, CAtlList
<CString
>& files
);
80 extern CString
GetDriveLabel(TCHAR drive
);
81 extern bool GetKeyFrames(CString fn
, CUIntArray
& kfs
);
82 extern DVD_HMSF_TIMECODE
RT2HMSF(REFERENCE_TIME rt
, double fps
= 0);
83 extern REFERENCE_TIME
HMSF2RT(DVD_HMSF_TIMECODE hmsf
, double fps
= 0);
84 extern void memsetd(void* dst
, unsigned int c
, size_t nbytes
);
85 extern void memsetw(void* dst
, unsigned short c
, size_t nbytes
);
86 extern bool ExtractBIH(const AM_MEDIA_TYPE
* pmt
, BITMAPINFOHEADER
* bih
);
87 extern bool ExtractBIH(IMediaSample
* pMS
, BITMAPINFOHEADER
* bih
);
88 extern bool ExtractDim(const AM_MEDIA_TYPE
* pmt
, int& w
, int& h
, int& arx
, int& ary
);
89 extern bool MakeMPEG2MediaType(CMediaType
& mt
, BYTE
* seqhdr
, DWORD len
, int w
, int h
);
90 extern unsigned __int64
GetFileVersion(LPCTSTR fn
);
91 extern bool CreateFilter(CStringW DisplayName
, IBaseFilter
** ppBF
, CStringW
& FriendlyName
);
92 extern IBaseFilter
* AppendFilter(IPin
* pPin
, IMoniker
* pMoniker
, IGraphBuilder
* pGB
);
93 extern CStringW
GetFriendlyName(CStringW DisplayName
);
94 extern HRESULT
LoadExternalObject(LPCTSTR path
, REFCLSID clsid
, REFIID iid
, void** ppv
);
95 extern HRESULT
LoadExternalFilter(LPCTSTR path
, REFCLSID clsid
, IBaseFilter
** ppBF
);
96 extern HRESULT
LoadExternalPropertyPage(IPersist
* pP
, REFCLSID clsid
, IPropertyPage
** ppPP
);
97 extern void UnloadExternalObjects();
98 extern CString
MakeFullPath(LPCTSTR path
);
99 extern CString
GetMediaTypeName(const GUID
& guid
);
100 extern GUID
GUIDFromCString(CString str
);
101 extern HRESULT
GUIDFromCString(CString str
, GUID
& guid
);
102 extern CString
CStringFromGUID(const GUID
& guid
);
103 extern CStringW
UTF8To16(LPCSTR utf8
);
104 extern CStringA
UTF16To8(LPCWSTR utf16
);
105 extern CString
ISO6391ToLanguage(LPCSTR code
);
106 extern CString
ISO6392ToLanguage(LPCSTR code
);
107 extern LCID
ISO6391ToLcid(LPCSTR code
);
108 extern LCID
ISO6392ToLcid(LPCSTR code
);
109 extern CString
ISO6391To6392(LPCSTR code
);
110 extern CString
ISO6392To6391(LPCSTR code
);
111 extern CString
LanguageToISO6392(LPCTSTR lang
);
112 extern int MakeAACInitData(BYTE
* pData
, int profile
, int freq
, int channels
);
113 extern BOOL
CFileGetStatus(LPCTSTR lpszFileName
, CFileStatus
& status
);
114 extern bool DeleteRegKey(LPCTSTR pszKey
, LPCTSTR pszSubkey
);
115 extern bool SetRegKeyValue(LPCTSTR pszKey
, LPCTSTR pszSubkey
, LPCTSTR pszValueName
, LPCTSTR pszValue
);
116 extern bool SetRegKeyValue(LPCTSTR pszKey
, LPCTSTR pszSubkey
, LPCTSTR pszValue
);
117 extern void RegisterSourceFilter(const CLSID
& clsid
, const GUID
& subtype2
, LPCTSTR chkbytes
, LPCTSTR ext
= NULL
, ...);
118 extern void RegisterSourceFilter(const CLSID
& clsid
, const GUID
& subtype2
, const CAtlList
<CString
>& chkbytes
, LPCTSTR ext
= NULL
, ...);
119 extern void UnRegisterSourceFilter(const GUID
& subtype
);
120 extern LPCTSTR
GetDXVAMode(const GUID
* guidDecoder
);
121 extern void DumpBuffer(BYTE
* pBuffer
, int nSize
);
122 extern CString
ReftimeToString(const REFERENCE_TIME
& rtVal
);
123 extern CString
ReftimeToString2(const REFERENCE_TIME
& rtVal
);
124 extern CString
DVDtimeToString(const DVD_HMSF_TIMECODE
& rtVal
, bool bAlwaysShowHours
=false);
125 REFERENCE_TIME
StringToReftime(LPCTSTR strVal
);
126 extern COLORREF
YCrCbToRGB_Rec601(BYTE Y
, BYTE Cr
, BYTE Cb
);
127 extern COLORREF
YCrCbToRGB_Rec709(BYTE Y
, BYTE Cr
, BYTE Cb
);
128 extern DWORD
YCrCbToRGB_Rec601(BYTE A
, BYTE Y
, BYTE Cr
, BYTE Cb
);
129 extern DWORD
YCrCbToRGB_Rec709(BYTE A
, BYTE Y
, BYTE Cr
, BYTE Cb
);
130 extern void TraceFilterInfo(IBaseFilter
* pBF
);
131 extern void TracePinInfo(IPin
* pPin
);
132 extern void SetThreadName( DWORD dwThreadID
, LPCSTR szThreadName
);
133 extern void HexDump(CString fName
, BYTE
* buf
, int size
);
134 extern DWORD
GetDefChannelMask(WORD nChannels
);
135 extern void CorrectComboListWidth(CComboBox
& m_pComboBox
);
137 class CPinInfo
: public PIN_INFO
140 CPinInfo() {pFilter
= NULL
;}
141 ~CPinInfo() {if(pFilter
) pFilter
->Release();}
144 class CFilterInfo
: public FILTER_INFO
147 CFilterInfo() {pGraph
= NULL
;}
148 ~CFilterInfo() {if(pGraph
) pGraph
->Release();}
151 #define BeginEnumFilters(pFilterGraph, pEnumFilters, pBaseFilter) \
152 {CComPtr<IEnumFilters> pEnumFilters; \
153 if(pFilterGraph && SUCCEEDED(pFilterGraph->EnumFilters(&pEnumFilters))) \
155 for(CComPtr<IBaseFilter> pBaseFilter; S_OK == pEnumFilters->Next(1, &pBaseFilter, 0); pBaseFilter = NULL) \
158 #define EndEnumFilters }}}
160 #define BeginEnumCachedFilters(pGraphConfig, pEnumFilters, pBaseFilter) \
161 {CComPtr<IEnumFilters> pEnumFilters; \
162 if(pGraphConfig && SUCCEEDED(pGraphConfig->EnumCacheFilter(&pEnumFilters))) \
164 for(CComPtr<IBaseFilter> pBaseFilter; S_OK == pEnumFilters->Next(1, &pBaseFilter, 0); pBaseFilter = NULL) \
167 #define EndEnumCachedFilters }}}
169 #define BeginEnumPins(pBaseFilter, pEnumPins, pPin) \
170 {CComPtr<IEnumPins> pEnumPins; \
171 if(pBaseFilter && SUCCEEDED(pBaseFilter->EnumPins(&pEnumPins))) \
173 for(CComPtr<IPin> pPin; S_OK == pEnumPins->Next(1, &pPin, 0); pPin = NULL) \
176 #define EndEnumPins }}}
178 #define BeginEnumMediaTypes(pPin, pEnumMediaTypes, pMediaType) \
179 {CComPtr<IEnumMediaTypes> pEnumMediaTypes; \
180 if(pPin && SUCCEEDED(pPin->EnumMediaTypes(&pEnumMediaTypes))) \
182 AM_MEDIA_TYPE* pMediaType = NULL; \
183 for(; S_OK == pEnumMediaTypes->Next(1, &pMediaType, NULL); DeleteMediaType(pMediaType), pMediaType = NULL) \
186 #define EndEnumMediaTypes(pMediaType) } if(pMediaType) DeleteMediaType(pMediaType); }}
188 #define BeginEnumSysDev(clsid, pMoniker) \
189 {CComPtr<ICreateDevEnum> pDevEnum4$##clsid; \
190 pDevEnum4$##clsid.CoCreateInstance(CLSID_SystemDeviceEnum); \
191 CComPtr<IEnumMoniker> pClassEnum4$##clsid; \
192 if(SUCCEEDED(pDevEnum4$##clsid->CreateClassEnumerator(clsid, &pClassEnum4$##clsid, 0)) \
193 && pClassEnum4$##clsid) \
195 for(CComPtr<IMoniker> pMoniker; pClassEnum4$##clsid->Next(1, &pMoniker, 0) == S_OK; pMoniker = NULL) \
198 #define EndEnumSysDev }}}
200 #define QI(i) (riid == __uuidof(i)) ? GetInterface((i*)this, ppv) :
201 #define QI2(i) (riid == IID_##i) ? GetInterface((i*)this, ppv) :
203 template <typename T
> __inline
void INITDDSTRUCT(T
& dd
)
205 ZeroMemory(&dd
, sizeof(dd
));
206 dd
.dwSize
= sizeof(dd
);
209 #define countof(array) (sizeof(array)/sizeof(array[0]))
212 static CUnknown
* WINAPI
CreateInstance(LPUNKNOWN lpunk
, HRESULT
* phr
)
215 CUnknown
* punk
= new T(lpunk
, phr
);
216 if(punk
== NULL
) *phr
= E_OUTOFMEMORY
;
219 #define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
220 #define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } }
221 #define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
222 inline int LNKO(int a
, int b
)
224 if(a
== 0 || b
== 0) {