Home | History | Annotate | Download | only in Common
      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 
     39   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 
     64   bool IsSet() const { return GetCodecs != NULL || GetHashers != NULL; }
     65 
     66   HRESULT Load();
     67 
     68   void ClearAndRelease()
     69   {
     70     Hashers.Clear();
     71     Codecs.Clear();
     72     GetHashers.Release();
     73     GetCodecs.Release();
     74   }
     75 
     76   ~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 int FindMethod_Index(
    120     DECL_EXTERNAL_CODECS_LOC_VARS
    121     const AString &name,
    122     bool encode,
    123     CMethodId &methodId,
    124     UInt32 &numStreams);
    125 
    126 bool FindMethod(
    127     DECL_EXTERNAL_CODECS_LOC_VARS
    128     CMethodId methodId,
    129     AString &name);
    130 
    131 bool FindHashMethod(
    132     DECL_EXTERNAL_CODECS_LOC_VARS
    133     const AString &name,
    134     CMethodId &methodId);
    135 
    136 void GetHashMethods(
    137     DECL_EXTERNAL_CODECS_LOC_VARS
    138     CRecordVector<CMethodId> &methods);
    139 
    140 
    141 struct CCreatedCoder
    142 {
    143   CMyComPtr<ICompressCoder> Coder;
    144   CMyComPtr<ICompressCoder2> Coder2;
    145 
    146   bool IsExternal;
    147   bool IsFilter; // = true, if Coder was created from filter
    148   UInt32 NumStreams;
    149 
    150   // CCreatedCoder(): IsExternal(false), IsFilter(false), NumStreams(1) {}
    151 };
    152 
    153 
    154 HRESULT CreateCoder_Index(
    155     DECL_EXTERNAL_CODECS_LOC_VARS
    156     unsigned codecIndex, bool encode,
    157     CMyComPtr<ICompressFilter> &filter,
    158     CCreatedCoder &cod);
    159 
    160 HRESULT CreateCoder_Index(
    161     DECL_EXTERNAL_CODECS_LOC_VARS
    162     unsigned index, bool encode,
    163     CCreatedCoder &cod);
    164 
    165 HRESULT CreateCoder_Id(
    166     DECL_EXTERNAL_CODECS_LOC_VARS
    167     CMethodId methodId, bool encode,
    168     CMyComPtr<ICompressFilter> &filter,
    169     CCreatedCoder &cod);
    170 
    171 HRESULT CreateCoder_Id(
    172     DECL_EXTERNAL_CODECS_LOC_VARS
    173     CMethodId methodId, bool encode,
    174     CCreatedCoder &cod);
    175 
    176 HRESULT CreateCoder_Id(
    177     DECL_EXTERNAL_CODECS_LOC_VARS
    178     CMethodId methodId, bool encode,
    179     CMyComPtr<ICompressCoder> &coder);
    180 
    181 HRESULT CreateFilter(
    182     DECL_EXTERNAL_CODECS_LOC_VARS
    183     CMethodId methodId, bool encode,
    184     CMyComPtr<ICompressFilter> &filter);
    185 
    186 HRESULT CreateHasher(
    187     DECL_EXTERNAL_CODECS_LOC_VARS
    188     CMethodId methodId,
    189     AString &name,
    190     CMyComPtr<IHasher> &hasher);
    191 
    192 #endif
    193