1 // RegisterCodec.h
2 
3 #ifndef __REGISTER_CODEC_H
4 #define __REGISTER_CODEC_H
5 
6 #include "../Common/MethodId.h"
7 
8 #include "../ICoder.h"
9 
10 typedef void * (*CreateCodecP)();
11 
12 struct CCodecInfo
13 {
14   CreateCodecP CreateDecoder;
15   CreateCodecP CreateEncoder;
16   CMethodId Id;
17   const char *Name;
18   UInt32 NumStreams;
19   bool IsFilter;
20 };
21 
22 void RegisterCodec(const CCodecInfo *codecInfo) throw();
23 
24 
25 #define REGISTER_CODEC_CREATE_2(name, cls, i) static void *name() { return (void *)(i *)(new cls); }
26 #define REGISTER_CODEC_CREATE(name, cls) REGISTER_CODEC_CREATE_2(name, cls, ICompressCoder)
27 
28 #define REGISTER_CODEC_NAME(x) CRegisterCodec ## x
29 #define REGISTER_CODEC_VAR static const CCodecInfo g_CodecInfo =
30 
31 #define REGISTER_CODEC(x) struct REGISTER_CODEC_NAME(x) { \
32     REGISTER_CODEC_NAME(x)() { RegisterCodec(&g_CodecInfo); }}; \
33     static REGISTER_CODEC_NAME(x) g_RegisterCodec;
34 
35 
36 #define REGISTER_CODECS_NAME(x) CRegisterCodecs ## x
37 #define REGISTER_CODECS_VAR static const CCodecInfo g_CodecsInfo[] =
38 
39 #define REGISTER_CODECS(x) struct REGISTER_CODECS_NAME(x) { \
40     REGISTER_CODECS_NAME(x)() { for (unsigned i = 0; i < ARRAY_SIZE(g_CodecsInfo); i++) \
41     RegisterCodec(&g_CodecsInfo[i]); }}; \
42     static REGISTER_CODECS_NAME(x) g_RegisterCodecs;
43 
44 
45 #define REGISTER_CODEC_2(x, crDec, crEnc, id, name) \
46     REGISTER_CODEC_VAR \
47     { crDec, crEnc, id, name, 1, false }; \
48     REGISTER_CODEC(x)
49 
50 
51 #ifdef EXTRACT_ONLY
52   #define REGISTER_CODEC_E(x, clsDec, clsEnc, id, name) \
53     REGISTER_CODEC_CREATE(CreateDec, clsDec) \
54     REGISTER_CODEC_2(x, CreateDec, NULL, id, name)
55 #else
56   #define REGISTER_CODEC_E(x, clsDec, clsEnc, id, name) \
57     REGISTER_CODEC_CREATE(CreateDec, clsDec) \
58     REGISTER_CODEC_CREATE(CreateEnc, clsEnc) \
59     REGISTER_CODEC_2(x, CreateDec, CreateEnc, id, name)
60 #endif
61 
62 
63 
64 #define REGISTER_FILTER_CREATE(name, cls) REGISTER_CODEC_CREATE_2(name, cls, ICompressFilter)
65 
66 #define REGISTER_FILTER_ITEM(crDec, crEnc, id, name) \
67     { crDec, crEnc, id, name, 1, true }
68 
69 #define REGISTER_FILTER(x, crDec, crEnc, id, name) \
70     REGISTER_CODEC_VAR \
71     REGISTER_FILTER_ITEM(crDec, crEnc, id, name); \
72     REGISTER_CODEC(x)
73 
74 #ifdef EXTRACT_ONLY
75   #define REGISTER_FILTER_E(x, clsDec, clsEnc, id, name) \
76     REGISTER_FILTER_CREATE(CreateDec, clsDec) \
77     REGISTER_FILTER(x, CreateDec, NULL, id, name)
78 #else
79   #define REGISTER_FILTER_E(x, clsDec, clsEnc, id, name) \
80     REGISTER_FILTER_CREATE(CreateDec, clsDec) \
81     REGISTER_FILTER_CREATE(CreateEnc, clsEnc) \
82     REGISTER_FILTER(x, CreateDec, CreateEnc, id, name)
83 #endif
84 
85 
86 
87 struct CHasherInfo
88 {
89   IHasher * (*CreateHasher)();
90   CMethodId Id;
91   const char *Name;
92   UInt32 DigestSize;
93 };
94 
95 void RegisterHasher(const CHasherInfo *hasher) throw();
96 
97 #define REGISTER_HASHER_NAME(x) CRegHasher_ ## x
98 
99 #define REGISTER_HASHER(cls, id, name, size) \
100     STDMETHODIMP_(UInt32) cls::GetDigestSize() throw() { return size; } \
101     static IHasher *CreateHasherSpec() { return new cls(); } \
102     static const CHasherInfo g_HasherInfo = { CreateHasherSpec, id, name, size }; \
103     struct REGISTER_HASHER_NAME(cls) { REGISTER_HASHER_NAME(cls)() { RegisterHasher(&g_HasherInfo); }}; \
104     static REGISTER_HASHER_NAME(cls) g_RegisterHasher;
105 
106 #endif
107