7 #include "../../../Windows/FileFind.h"
8 #include "../../../Windows/DLL.h"
9 #include "../../../Windows/PropVariant.h"
10 #include "../../../Windows/Synchronization.h"
12 #include "../../ICoder.h"
13 #include "../Common/CodecsPath.h"
15 using namespace NWindows
;
20 static CObjectVector
<CMethodInfo2
> g_Methods
;
21 static bool g_Loaded
= false;
23 typedef UInt32 (WINAPI
*GetNumberOfMethodsFunc
)(UInt32
*numMethods
);
25 typedef UInt32 (WINAPI
*GetMethodPropertyFunc
)(
26 UInt32 index
, PROPID propID
, PROPVARIANT
*value
);
28 static void Load(const CSysString
&folderPrefix
)
30 NFile::NFind::CEnumerator
enumerator(folderPrefix
+ CSysString(TEXT("*")));
31 NFile::NFind::CFileInfo fileInfo
;
32 while (enumerator
.Next(fileInfo
))
34 if (fileInfo
.IsDirectory())
36 CSysString filePath
= folderPrefix
+ fileInfo
.Name
;
38 NDLL::CLibrary library
;
39 if (!library
.LoadEx(filePath
, LOAD_LIBRARY_AS_DATAFILE
))
42 NDLL::CLibrary library
;
43 if (!library
.Load(filePath
))
45 GetMethodPropertyFunc getMethodProperty
= (GetMethodPropertyFunc
)
46 library
.GetProcAddress("GetMethodProperty");
47 if (getMethodProperty
== NULL
)
50 UInt32 numMethods
= 1;
51 GetNumberOfMethodsFunc getNumberOfMethodsFunc
= (GetNumberOfMethodsFunc
)
52 library
.GetProcAddress("GetNumberOfMethods");
53 if (getNumberOfMethodsFunc
!= NULL
)
54 if (getNumberOfMethodsFunc(&numMethods
) != S_OK
)
57 for(UInt32 i
= 0; i
< numMethods
; i
++)
60 info
.FilePath
= filePath
;
62 NWindows::NCOM::CPropVariant propVariant
;
63 if (getMethodProperty(i
, NMethodPropID::kID
, &propVariant
) != S_OK
)
65 if (propVariant
.vt
!= VT_BSTR
)
67 info
.MethodID
.IDSize
= SysStringByteLen(propVariant
.bstrVal
);
68 memmove(info
.MethodID
.ID
, propVariant
.bstrVal
, info
.MethodID
.IDSize
);
71 if (getMethodProperty(i
, NMethodPropID::kName
, &propVariant
) != S_OK
)
73 if (propVariant
.vt
== VT_EMPTY
)
76 else if (propVariant
.vt
== VT_BSTR
)
77 info
.Name
= propVariant
.bstrVal
;
82 if (getMethodProperty (i
, NMethodPropID::kEncoder
, &propVariant
) != S_OK
)
84 if (propVariant
.vt
== VT_EMPTY
)
85 info
.EncoderIsAssigned
= false;
86 else if (propVariant
.vt
== VT_BSTR
)
88 info
.EncoderIsAssigned
= true;
89 info
.Encoder
= *(const GUID
*)propVariant
.bstrVal
;
95 if (getMethodProperty (i
, NMethodPropID::kDecoder
, &propVariant
) != S_OK
)
97 if (propVariant
.vt
== VT_EMPTY
)
98 info
.DecoderIsAssigned
= false;
99 else if (propVariant
.vt
== VT_BSTR
)
101 info
.DecoderIsAssigned
= true;
102 info
.Decoder
= *(const GUID
*)propVariant
.bstrVal
;
108 if (getMethodProperty (i
, NMethodPropID::kInStreams
, &propVariant
) != S_OK
)
110 if (propVariant
.vt
== VT_EMPTY
)
111 info
.NumInStreams
= 1;
112 else if (propVariant
.vt
== VT_UI4
)
113 info
.NumInStreams
= propVariant
.ulVal
;
118 if (getMethodProperty (i
, NMethodPropID::kOutStreams
, &propVariant
) != S_OK
)
120 if (propVariant
.vt
== VT_EMPTY
)
121 info
.NumOutStreams
= 1;
122 else if (propVariant
.vt
== VT_UI4
)
123 info
.NumOutStreams
= propVariant
.ulVal
;
133 static NSynchronization::CCriticalSection g_CriticalSection
;
137 NSynchronization::CCriticalSectionLock
lock(g_CriticalSection
);
141 Load(GetCodecsFolderPrefix());
144 bool GetMethodInfo(const CMethodID
&methodID
, CMethodInfo
&methodInfo
)
146 for(int i
= 0; i
< g_Methods
.Size(); i
++)
148 const CMethodInfo2
&method
= g_Methods
[i
];
149 if (method
.MethodID
== methodID
)
151 methodInfo
= (CMethodInfo
)method
;
158 bool GetMethodInfo(const UString
&name
, CMethodInfo2
&methodInfo
)
160 for(int i
= 0; i
< g_Methods
.Size(); i
++)
162 const CMethodInfo2
&method
= g_Methods
[i
];
163 if (method
.Name
.CompareNoCase(name
) == 0)