1 // CreateCoder.h 2 3 #ifndef __CREATE_CODER_H 4 #define __CREATE_CODER_H 5 6 #include "../../Common/MyCom.h" 7 #include "../../Common/MyString.h" 8 9 #include "../ICoder.h" 10 11 #include "MethodId.h" 12 13 /* 14 if EXTERNAL_CODECS is not defined, the code supports only codecs that 15 are statically linked at compile-time and link-time. 16 17 if EXTERNAL_CODECS is defined, the code supports also codecs from another 18 executable modules, that can be linked dynamically at run-time: 19 - EXE module can use codecs from external DLL files. 20 - DLL module can use codecs from external EXE and DLL files. 21 22 CExternalCodecs contains information about codecs and interfaces to create them. 23 24 The order of codecs: 25 1) Internal codecs 26 2) External codecs 27 */ 28 29 #ifdef EXTERNAL_CODECS 30 31 struct CCodecInfoEx 32 { 33 CMethodId Id; 34 AString Name; 35 UInt32 NumStreams; 36 bool EncoderIsAssigned; 37 bool DecoderIsAssigned; 38 CCodecInfoExCCodecInfoEx39 CCodecInfoEx(): EncoderIsAssigned(false), DecoderIsAssigned(false) {} 40 }; 41 42 struct CHasherInfoEx 43 { 44 CMethodId Id; 45 AString Name; 46 }; 47 48 #define PUBLIC_ISetCompressCodecsInfo public ISetCompressCodecsInfo, 49 #define QUERY_ENTRY_ISetCompressCodecsInfo MY_QUERYINTERFACE_ENTRY(ISetCompressCodecsInfo) 50 #define DECL_ISetCompressCodecsInfo STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo); 51 #define IMPL_ISetCompressCodecsInfo2(x) \ 52 STDMETHODIMP x::SetCompressCodecsInfo(ICompressCodecsInfo *compressCodecsInfo) { \ 53 COM_TRY_BEGIN __externalCodecs.GetCodecs = compressCodecsInfo; return __externalCodecs.Load(); COM_TRY_END } 54 #define IMPL_ISetCompressCodecsInfo IMPL_ISetCompressCodecsInfo2(CHandler) 55 56 struct CExternalCodecs 57 { 58 CMyComPtr<ICompressCodecsInfo> GetCodecs; 59 CMyComPtr<IHashers> GetHashers; 60 61 CObjectVector<CCodecInfoEx> Codecs; 62 CObjectVector<CHasherInfoEx> Hashers; 63 IsSetCExternalCodecs64 bool IsSet() const { return GetCodecs != NULL || GetHashers != NULL; } 65 66 HRESULT Load(); 67 ClearAndReleaseCExternalCodecs68 void ClearAndRelease() 69 { 70 Hashers.Clear(); 71 Codecs.Clear(); 72 GetHashers.Release(); 73 GetCodecs.Release(); 74 } 75 ~CExternalCodecsCExternalCodecs76 ~CExternalCodecs() 77 { 78 GetHashers.Release(); 79 GetCodecs.Release(); 80 } 81 }; 82 83 extern CExternalCodecs g_ExternalCodecs; 84 85 #define EXTERNAL_CODECS_VARS2 (__externalCodecs.IsSet() ? &__externalCodecs : &g_ExternalCodecs) 86 #define EXTERNAL_CODECS_VARS2_L (&__externalCodecs) 87 #define EXTERNAL_CODECS_VARS2_G (&g_ExternalCodecs) 88 89 #define DECL_EXTERNAL_CODECS_VARS CExternalCodecs __externalCodecs; 90 91 #define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2, 92 #define EXTERNAL_CODECS_VARS_L EXTERNAL_CODECS_VARS2_L, 93 #define EXTERNAL_CODECS_VARS_G EXTERNAL_CODECS_VARS2_G, 94 95 #define DECL_EXTERNAL_CODECS_LOC_VARS2 const CExternalCodecs *__externalCodecs 96 #define EXTERNAL_CODECS_LOC_VARS2 __externalCodecs 97 98 #define DECL_EXTERNAL_CODECS_LOC_VARS DECL_EXTERNAL_CODECS_LOC_VARS2, 99 #define EXTERNAL_CODECS_LOC_VARS EXTERNAL_CODECS_LOC_VARS2, 100 101 #else 102 103 #define PUBLIC_ISetCompressCodecsInfo 104 #define QUERY_ENTRY_ISetCompressCodecsInfo 105 #define DECL_ISetCompressCodecsInfo 106 #define IMPL_ISetCompressCodecsInfo 107 #define EXTERNAL_CODECS_VARS2 108 #define DECL_EXTERNAL_CODECS_VARS 109 #define EXTERNAL_CODECS_VARS 110 #define EXTERNAL_CODECS_VARS_L 111 #define EXTERNAL_CODECS_VARS_G 112 #define DECL_EXTERNAL_CODECS_LOC_VARS2 113 #define EXTERNAL_CODECS_LOC_VARS2 114 #define DECL_EXTERNAL_CODECS_LOC_VARS 115 #define EXTERNAL_CODECS_LOC_VARS 116 117 #endif 118 119 120 121 122 bool FindMethod( 123 DECL_EXTERNAL_CODECS_LOC_VARS 124 const AString &name, 125 CMethodId &methodId, UInt32 &numStreams); 126 127 bool FindMethod( 128 DECL_EXTERNAL_CODECS_LOC_VARS 129 CMethodId methodId, 130 AString &name); 131 132 bool FindHashMethod( 133 DECL_EXTERNAL_CODECS_LOC_VARS 134 const AString &name, 135 CMethodId &methodId); 136 137 void GetHashMethods( 138 DECL_EXTERNAL_CODECS_LOC_VARS 139 CRecordVector<CMethodId> &methods); 140 141 142 struct CCreatedCoder 143 { 144 CMyComPtr<ICompressCoder> Coder; 145 CMyComPtr<ICompressCoder2> Coder2; 146 147 bool IsExternal; 148 bool IsFilter; // = true, if Coder was created from filter 149 UInt32 NumStreams; 150 151 // CCreatedCoder(): IsExternal(false), IsFilter(false), NumStreams(1) {} 152 }; 153 154 155 HRESULT CreateCoder( 156 DECL_EXTERNAL_CODECS_LOC_VARS 157 CMethodId methodId, bool encode, 158 CMyComPtr<ICompressFilter> &filter, 159 CCreatedCoder &cod); 160 161 HRESULT CreateCoder( 162 DECL_EXTERNAL_CODECS_LOC_VARS 163 CMethodId methodId, bool encode, 164 CCreatedCoder &cod); 165 166 HRESULT CreateCoder( 167 DECL_EXTERNAL_CODECS_LOC_VARS 168 CMethodId methodId, bool encode, 169 CMyComPtr<ICompressCoder> &coder); 170 171 HRESULT CreateFilter( 172 DECL_EXTERNAL_CODECS_LOC_VARS 173 CMethodId methodId, bool encode, 174 CMyComPtr<ICompressFilter> &filter); 175 176 HRESULT CreateHasher( 177 DECL_EXTERNAL_CODECS_LOC_VARS 178 CMethodId methodId, 179 AString &name, 180 CMyComPtr<IHasher> &hasher); 181 182 #endif 183