1 // CreateCoder.h 2 3 #ifndef ZIP7_INC_CREATE_CODER_H 4 #define ZIP7_INC_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 Z7_EXTERNAL_CODECS is not defined, the code supports only codecs that 15 are statically linked at compile-time and link-time. 16 17 if Z7_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 Z7_EXTERNAL_CODECS 30 31 struct CCodecInfoEx 32 { 33 CMethodId Id; 34 AString Name; 35 UInt32 NumStreams; 36 bool EncoderIsAssigned; 37 bool DecoderIsAssigned; 38 bool IsFilter; // it's unused 39 CCodecInfoExCCodecInfoEx40 CCodecInfoEx(): EncoderIsAssigned(false), DecoderIsAssigned(false), IsFilter(false) {} 41 }; 42 43 struct CHasherInfoEx 44 { 45 CMethodId Id; 46 AString Name; 47 }; 48 49 #define Z7_PUBLIC_ISetCompressCodecsInfo_IFEC \ 50 public ISetCompressCodecsInfo, 51 #define Z7_COM_QI_ENTRY_ISetCompressCodecsInfo_IFEC \ 52 Z7_COM_QI_ENTRY(ISetCompressCodecsInfo) 53 #define DECL_ISetCompressCodecsInfo \ 54 Z7_COM7F_IMP(SetCompressCodecsInfo(ICompressCodecsInfo *compressCodecsInfo)) 55 #define IMPL_ISetCompressCodecsInfo2(cls) \ 56 Z7_COM7F_IMF(cls::SetCompressCodecsInfo(ICompressCodecsInfo *compressCodecsInfo)) \ 57 { COM_TRY_BEGIN _externalCodecs.GetCodecs = compressCodecsInfo; \ 58 return _externalCodecs.Load(); COM_TRY_END } 59 #define IMPL_ISetCompressCodecsInfo IMPL_ISetCompressCodecsInfo2(CHandler) 60 61 struct CExternalCodecs 62 { 63 CMyComPtr<ICompressCodecsInfo> GetCodecs; 64 CMyComPtr<IHashers> GetHashers; 65 66 CObjectVector<CCodecInfoEx> Codecs; 67 CObjectVector<CHasherInfoEx> Hashers; 68 IsSetCExternalCodecs69 bool IsSet() const { return GetCodecs != NULL || GetHashers != NULL; } 70 71 HRESULT Load(); 72 ClearAndReleaseCExternalCodecs73 void ClearAndRelease() 74 { 75 Hashers.Clear(); 76 Codecs.Clear(); 77 GetHashers.Release(); 78 GetCodecs.Release(); 79 } 80 ~CExternalCodecsCExternalCodecs81 ~CExternalCodecs() 82 { 83 GetHashers.Release(); 84 GetCodecs.Release(); 85 } 86 }; 87 88 extern CExternalCodecs g_ExternalCodecs; 89 90 #define EXTERNAL_CODECS_VARS2 (_externalCodecs.IsSet() ? &_externalCodecs : &g_ExternalCodecs) 91 #define EXTERNAL_CODECS_VARS2_L (&_externalCodecs) 92 #define EXTERNAL_CODECS_VARS2_G (&g_ExternalCodecs) 93 94 #define DECL_EXTERNAL_CODECS_VARS CExternalCodecs _externalCodecs; 95 96 #define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2, 97 #define EXTERNAL_CODECS_VARS_L EXTERNAL_CODECS_VARS2_L, 98 #define EXTERNAL_CODECS_VARS_G EXTERNAL_CODECS_VARS2_G, 99 100 #define DECL_EXTERNAL_CODECS_LOC_VARS2 const CExternalCodecs *_externalCodecs 101 #define DECL_EXTERNAL_CODECS_LOC_VARS DECL_EXTERNAL_CODECS_LOC_VARS2, 102 #define DECL_EXTERNAL_CODECS_LOC_VARS_DECL DECL_EXTERNAL_CODECS_LOC_VARS2; 103 104 #define EXTERNAL_CODECS_LOC_VARS2 _externalCodecs 105 #define EXTERNAL_CODECS_LOC_VARS EXTERNAL_CODECS_LOC_VARS2, 106 107 #else 108 109 #define Z7_PUBLIC_ISetCompressCodecsInfo_IFEC 110 #define Z7_COM_QI_ENTRY_ISetCompressCodecsInfo_IFEC 111 #define DECL_ISetCompressCodecsInfo 112 #define IMPL_ISetCompressCodecsInfo 113 #define EXTERNAL_CODECS_VARS2 114 #define DECL_EXTERNAL_CODECS_VARS 115 #define EXTERNAL_CODECS_VARS 116 #define EXTERNAL_CODECS_VARS_L 117 #define EXTERNAL_CODECS_VARS_G 118 #define DECL_EXTERNAL_CODECS_LOC_VARS2 119 #define DECL_EXTERNAL_CODECS_LOC_VARS 120 #define DECL_EXTERNAL_CODECS_LOC_VARS_DECL 121 #define EXTERNAL_CODECS_LOC_VARS2 122 #define EXTERNAL_CODECS_LOC_VARS 123 124 #endif 125 126 int FindMethod_Index( 127 DECL_EXTERNAL_CODECS_LOC_VARS 128 const AString &name, 129 bool encode, 130 CMethodId &methodId, 131 UInt32 &numStreams, 132 bool &isFilter); 133 134 bool FindMethod( 135 DECL_EXTERNAL_CODECS_LOC_VARS 136 CMethodId methodId, 137 AString &name); 138 139 bool FindHashMethod( 140 DECL_EXTERNAL_CODECS_LOC_VARS 141 const AString &name, 142 CMethodId &methodId); 143 144 void GetHashMethods( 145 DECL_EXTERNAL_CODECS_LOC_VARS 146 CRecordVector<CMethodId> &methods); 147 148 149 struct CCreatedCoder 150 { 151 CMyComPtr<ICompressCoder> Coder; 152 CMyComPtr<ICompressCoder2> Coder2; 153 154 bool IsExternal; 155 bool IsFilter; // = true, if Coder was created from filter 156 UInt32 NumStreams; 157 158 // CCreatedCoder(): IsExternal(false), IsFilter(false), NumStreams(1) {} 159 }; 160 161 162 HRESULT CreateCoder_Index( 163 DECL_EXTERNAL_CODECS_LOC_VARS 164 unsigned codecIndex, bool encode, 165 CMyComPtr<ICompressFilter> &filter, 166 CCreatedCoder &cod); 167 168 HRESULT CreateCoder_Index( 169 DECL_EXTERNAL_CODECS_LOC_VARS 170 unsigned index, bool encode, 171 CCreatedCoder &cod); 172 173 HRESULT CreateCoder_Id( 174 DECL_EXTERNAL_CODECS_LOC_VARS 175 CMethodId methodId, bool encode, 176 CMyComPtr<ICompressFilter> &filter, 177 CCreatedCoder &cod); 178 179 HRESULT CreateCoder_Id( 180 DECL_EXTERNAL_CODECS_LOC_VARS 181 CMethodId methodId, bool encode, 182 CCreatedCoder &cod); 183 184 HRESULT CreateCoder_Id( 185 DECL_EXTERNAL_CODECS_LOC_VARS 186 CMethodId methodId, bool encode, 187 CMyComPtr<ICompressCoder> &coder); 188 189 HRESULT CreateFilter( 190 DECL_EXTERNAL_CODECS_LOC_VARS 191 CMethodId methodId, bool encode, 192 CMyComPtr<ICompressFilter> &filter); 193 194 HRESULT CreateHasher( 195 DECL_EXTERNAL_CODECS_LOC_VARS 196 CMethodId methodId, 197 AString &name, 198 CMyComPtr<IHasher> &hasher); 199 200 #endif 201