source: trunk/Utilities/MediaFoundation/EnumerateTransforms/Application.cpp @ 939

Last change on this file since 939 was 660, checked in by roman, 8 years ago
File size: 9.3 KB
Line 
1////////////////////////////////////////////////////////////
2// Copyright (C) Roman Ryltsov, 2008-2015
3// Created by Roman Ryltsov roman@alax.info
4//
5// A permission to use the source code is granted as long as reference to
6// source website http://alax.info is retained.
7
8#include "stdafx.h"
9#include "rodshow.h"
10#include "romf.h"
11
12////////////////////////////////////////////////////////////
13// CModule
14
15class CModule :
16        public CAtlExeModuleT<CModule>
17{
18public:
19        static CString FormatTransformFlags(ULONG nTransformFlags)
20        {
21                CRoArrayT<CString> Array;
22                static const struct { ULONG nValue; LPCSTR pszName; } g_pMap[] = 
23                {
24                        #define A(x) { x, #x },
25                        A(MFT_ENUM_FLAG_SYNCMFT)
26                        A(MFT_ENUM_FLAG_ASYNCMFT)
27                        A(MFT_ENUM_FLAG_HARDWARE)
28                        A(MFT_ENUM_FLAG_FIELDOFUSE)
29                        A(MFT_ENUM_FLAG_LOCALMFT)
30                        A(MFT_ENUM_FLAG_TRANSCODE_ONLY)
31                        //A(MFT_ENUM_FLAG_SORTANDFILTER)
32                        //A(MFT_ENUM_FLAG_ALL)
33                        #undef A
34                };
35                for(SIZE_T nIndex = 0; nIndex < DIM(g_pMap); nIndex++)
36                        if(nTransformFlags & g_pMap[nIndex].nValue)
37                        {
38                                _W(Array.Add(CA2CT(g_pMap[nIndex].pszName)) >= 0);
39                                nTransformFlags &= ~g_pMap[nIndex].nValue;
40                        }
41                if(!Array.IsEmpty())
42                {
43                        if(nTransformFlags)
44                                _W(Array.Add(AtlFormatString(_T("0x%x"), nTransformFlags)) >= 0);
45                        return _StringHelper::Join(Array, _T(" | "));
46                }
47                if(!nTransformFlags)
48                        return _T("0");
49                return AtlFormatString(_T("0x%x"), nTransformFlags);
50        }
51
52public:
53// CModule
54        CModule()
55        {
56                AtlTraceSetDefaultSettings();
57                _Z4_THIS();
58                _W(CExceptionFilter::Initialize());
59        }
60        ~CModule()
61        {
62                _Z4_THIS();
63                CExceptionFilter::Terminate();
64        }
65        HRESULT PreMessageLoop(INT nShowCommand)
66        {
67                const HRESULT nResult = __super::PreMessageLoop(nShowCommand);
68                return SUCCEEDED(nResult) ? S_OK : nResult;
69        }
70        VOID RunMessageLoop()
71        {
72                static const CEnumerationNameT<GUID> g_pCategoryMap[] = 
73                {
74                        #define A(x) { x, #x },
75                        A(MFT_CATEGORY_VIDEO_DECODER)
76                        A(MFT_CATEGORY_VIDEO_ENCODER)
77                        A(MFT_CATEGORY_VIDEO_EFFECT)
78                        A(MFT_CATEGORY_MULTIPLEXER)
79                        A(MFT_CATEGORY_DEMULTIPLEXER)
80                        A(MFT_CATEGORY_AUDIO_DECODER)
81                        A(MFT_CATEGORY_AUDIO_ENCODER)
82                        A(MFT_CATEGORY_AUDIO_EFFECT)
83                        A(MFT_CATEGORY_VIDEO_PROCESSOR)
84                        A(MFT_CATEGORY_OTHER)
85                        #if (WINVER >= _WIN32_WINNT_WIN10_RS1)
86                                A(MFT_CATEGORY_ENCRYPTOR)
87                        #endif
88                        A(CLSID_VideoInputDeviceCategory) // Kernel streaming (KS) minidriver backed hardware transforms https://msdn.microsoft.com/en-us/library/windows/desktop/ms700134#live_sources
89                        A(KSCATEGORY_BRIDGE)
90                        A(KSCATEGORY_CAPTURE) // Video and Audio capture stuff
91                        A(KSCATEGORY_VIDEO_CAMERA)
92                        A(KSCATEGORY_RENDER)
93                        A(KSCATEGORY_MIXER)
94                        A(KSCATEGORY_SPLITTER)
95                        A(KSCATEGORY_DATACOMPRESSOR)
96                        A(KSCATEGORY_DATADECOMPRESSOR)
97                        A(KSCATEGORY_DATATRANSFORM)
98                        A(KSCATEGORY_COMMUNICATIONSTRANSFORM)
99                        A(KSCATEGORY_INTERFACETRANSFORM)
100                        A(KSCATEGORY_MEDIUMTRANSFORM)
101                        A(KSCATEGORY_FILESYSTEM)
102                        A(KSCATEGORY_CLOCK)
103                        A(KSCATEGORY_PROXY)
104                        A(KSCATEGORY_QUALITY)
105                        #undef A
106                };
107                for(auto&& CategoryItem: g_pCategoryMap)
108                {
109                        _tprintf(_T("Category: %hs %ls\n"), (LPCSTR) CategoryItem.pszName, (LPCWSTR) _PersistHelper::StringFromIdentifier(CategoryItem.Value));
110                        _tprintf(_T("\n"));
111                        _ATLTRY
112                        {
113                                MF::CActivateArray ActivateArray;
114                                ActivateArray.Enumerate(CategoryItem.Value);
115                                UINT nActivateIndex = 0;
116                                for(auto&& pActivate: ActivateArray)
117                                {
118                                        CString sItem = AtlFormatString(_T("#%d"), nActivateIndex++);
119                                        CString sFriendlyName;
120                                        if(pActivate.TryGetString(MFT_FRIENDLY_NAME_Attribute, sFriendlyName))
121                                                sItem.Insert(0, AtlFormatString(_T("%s "), sFriendlyName));
122                                        _tprintf(_T("\t") _T("%s\n"), (LPCTSTR) sItem);
123                                        _ATLTRY
124                                        {
125                                                UINT32 nItemCount = 0;
126                                                __C(pActivate->GetCount(&nItemCount));
127                                                for(UINT32 nItemIndex = 0; nItemIndex < nItemCount; nItemIndex++)
128                                                {
129                                                        GUID Key;
130                                                        MF::CPropVariant vValue;
131                                                        __C(pActivate->GetItemByIndex(nItemIndex, &Key, &vValue));
132                                                        // NOTE: See PROPVARIANT Type Constants http://msdn.microsoft.com/en-us/library/cc235506
133                                                        if(Key == MF_TRANSFORM_CATEGORY_Attribute && vValue.vt == VT_CLSID && *vValue.puuid == CategoryItem.Value)
134                                                                continue; // Matches Category
135                                                        if(Key == MFT_FRIENDLY_NAME_Attribute)
136                                                                continue; // Already Printed
137                                                        CString sStringValue;
138                                                        BOOL bStringValueAvailable = FALSE;
139                                                        BOOL bDefault = TRUE;
140                                                        #pragma region Format as Attribute
141                                                        if(Key == MF_TRANSFORM_FLAGS_Attribute && vValue.vt == VT_UI4)
142                                                        {
143                                                                sStringValue = FormatTransformFlags(vValue.ulVal);
144                                                                bStringValueAvailable = TRUE;
145                                                                bDefault = FALSE;
146                                                        } else
147                                                        if((Key == MFT_INPUT_TYPES_Attributes || Key == MFT_OUTPUT_TYPES_Attributes) && vValue.vt == (VT_VECTOR | VT_UI1))
148                                                        {
149                                                                _A(!(vValue.caub.cElems % sizeof (MFT_REGISTER_TYPE_INFO)));
150                                                                const MFT_REGISTER_TYPE_INFO* pData = (MFT_REGISTER_TYPE_INFO*) vValue.caub.pElems;
151                                                                const SIZE_T nDataCount = vValue.caub.cElems / sizeof *pData;
152                                                                CRoArrayT<CString> Array;
153                                                                for(SIZE_T nIndex = 0; nIndex < nDataCount; nIndex++)
154                                                                        _W(Array.Add(AtlFormatString(_T("\t\t\t") _T("%s %s"), MF::FormatKey(pData[nIndex].guidMajorType), MF::FormatKey(pData[nIndex].guidSubtype))) >= 0);
155                                                                sStringValue += _StringHelper::Join(Array, _T("\n"));
156                                                                if(!sStringValue.IsEmpty())
157                                                                {
158                                                                        sStringValue.Insert(0, _T("\n"));
159                                                                        sStringValue.Append(_T("\n") _T("\t\t\t"));
160                                                                }
161                                                                bStringValueAvailable = TRUE;
162                                                                bDefault = FALSE;
163                                                        } else
164                                                                ;
165                                                        #pragma endregion
166                                                        #pragma region Format as Type
167                                                        if(bDefault)
168                                                        {
169                                                                sStringValue = vValue.Format();
170                                                                bStringValueAvailable = !sStringValue.IsEmpty();
171                                                        }
172                                                        #pragma endregion
173                                                        if(bStringValueAvailable)
174                                                                _tprintf(_T("\t") _T("\t") _T("%s: %s\n"), (LPCTSTR) MF::FormatKey(Key), (LPCTSTR) sStringValue);
175                                                        else
176                                                                _tprintf(_T("\t") _T("\t") _T("%s: ??? (%s)\n"), (LPCTSTR) MF::FormatKey(Key), (LPCTSTR) MF::CPropVariant::FormatType(vValue.vt));
177                                                }
178                                                //_ATLTRY
179                                                //{
180                                                //      CComPtr<IMFTransform> pTransform;
181                                                //      __C(pActivate->ActivateObject(__uuidof(IMFTransform), (VOID**) &pTransform));
182                                                //      const CComQIPtr<ISpecifyPropertyPages> pSpecifyPropertyPages = pTransform;
183                                                //      if(pSpecifyPropertyPages)
184                                                //      {
185                                                //              CAUUID Pages;
186                                                //              ZeroMemory(&Pages, sizeof Pages);
187                                                //              __C(pSpecifyPropertyPages->GetPages(&Pages));
188                                                //      }
189                                                //}
190                                                //_ATLCATCHALL()
191                                                //{
192                                                //      _Z_EXCEPTION();
193                                                //}
194                                        }
195                                        _ATLCATCHALL()
196                                        {
197                                                _Z_EXCEPTION();
198                                        }
199                                        _tprintf(_T("\n"));
200                                }
201                        }
202                        _ATLCATCHALL()
203                        {
204                                _Z_EXCEPTION();
205                        }
206                }
207        }
208};
209
210////////////////////////////////////////////////////////////
211// CArgumentException
212
213class CArgumentException :
214        public CAtlException
215{
216public:
217        CString m_sMessage;
218
219public:
220// CArgumentException
221        CArgumentException(const CString& sMessage, HRESULT nCode = E_FAIL) throw() :
222                CAtlException(nCode),
223                m_sMessage(sMessage)
224        {
225        }
226};
227
228////////////////////////////////////////////////////////////
229// Main
230
231int _tmain(int argc, _TCHAR* argv[])
232{
233        CModule Module;
234        _ATLTRY
235        {
236                #pragma region Syntax
237                //if(argc <= 1)
238                //{
239                //      CPath sName = FindFileName(argv[0]);
240                //      sName.RemoveExtension();
241                //      _tprintf(_T("Syntax:  %s [options] <media-file-path>\n"), sName);
242                //      _tprintf(_T("\n"));
243                //      _tprintf(_T("Options: ") _T("/x") _T(" - ") _T("show message box before running the graph\n"));
244                //      _tprintf(_T("\n"));
245                //      return 2;
246                //}
247                #pragma endregion
248                //for(INT nArgumentIndex = 1; nArgumentIndex < argc; nArgumentIndex++)
249                //{
250                //      CString sArgument = argv[nArgumentIndex];
251                //      _A(!sArgument.IsEmpty());
252                //      if(_tcschr(_T("-/"), sArgument[0]))
253                //      {
254                //              sArgument.Delete(0, 1);
255                //              if(sArgument.IsEmpty())
256                //                      throw CArgumentException(_T("Unexpected argument"));
257                //              switch(sArgument[0])
258                //              {
259                //              case 'X':
260                //              case 'x':
261                //                      Module.m_bShowMessageBox = TRUE;
262                //                      break;
263                //              default:
264                //                      throw CArgumentException(AtlFormatString(_T("Unexpected argument (%s)"), sArgument));
265                //              }
266                //              continue;
267                //      }
268                //      if(_tcslen(Module.m_sPath))
269                //              throw CArgumentException(_T("Unexpected argument: Input file name already specified"));
270                //      Module.m_sPath = (LPCTSTR) sArgument;
271                //      //throw CArgumentException(AtlFormatString(_T("Unexpected argument (%s)"), sArgument));
272                //}
273                //if(!_tcslen(Module.m_sPath))
274                //      throw CArgumentException(_T("Missing argument: No input file name specified"));
275                Module.WinMain(SW_SHOWNORMAL);
276        }
277        catch(CArgumentException Exception)
278        {
279                _tprintf(_T("Fatal Error: %s\n"), (LPCTSTR) Exception.m_sMessage);
280                return 1;
281        }
282        _ATLCATCH(Exception)
283        {
284                _tprintf(_T("Fatal Error: 0x%08X %s\n"), (HRESULT) Exception, (LPCTSTR) AtlFormatSystemMessage(Exception).TrimRight(_T("\t\n\r .")));
285                return 1;
286        }
287        _ATLCATCHALL()
288        {
289                _tprintf(_T("Fatal Error\n"));
290                return 1;
291        }
292        return 0;
293}
294
295// NOTE: See also Matthew van Eerde's "How to enumerate Media Foundation transforms on your system"
296//       http://blogs.msdn.com/b/matthew_van_eerde/archive/2010/05/03/how-to-enumerate-media-foundation-transforms-on-your-system.aspx
Note: See TracBrowser for help on using the repository browser.