1370b324cSopenharmony_ci// RegisterCodec.h 2370b324cSopenharmony_ci 3370b324cSopenharmony_ci#ifndef ZIP7_INC_REGISTER_CODEC_H 4370b324cSopenharmony_ci#define ZIP7_INC_REGISTER_CODEC_H 5370b324cSopenharmony_ci 6370b324cSopenharmony_ci#include "../Common/MethodId.h" 7370b324cSopenharmony_ci 8370b324cSopenharmony_ci#include "../ICoder.h" 9370b324cSopenharmony_ci 10370b324cSopenharmony_citypedef void * (*CreateCodecP)(); 11370b324cSopenharmony_ci 12370b324cSopenharmony_cistruct CCodecInfo 13370b324cSopenharmony_ci{ 14370b324cSopenharmony_ci CreateCodecP CreateDecoder; 15370b324cSopenharmony_ci CreateCodecP CreateEncoder; 16370b324cSopenharmony_ci CMethodId Id; 17370b324cSopenharmony_ci const char *Name; 18370b324cSopenharmony_ci UInt32 NumStreams; 19370b324cSopenharmony_ci bool IsFilter; 20370b324cSopenharmony_ci}; 21370b324cSopenharmony_ci 22370b324cSopenharmony_civoid RegisterCodec(const CCodecInfo *codecInfo) throw(); 23370b324cSopenharmony_ci 24370b324cSopenharmony_ci 25370b324cSopenharmony_ci#define REGISTER_CODEC_CREATE_2(name, cls, i) static void *name() { return (void *)(i *)(new cls); } 26370b324cSopenharmony_ci#define REGISTER_CODEC_CREATE(name, cls) REGISTER_CODEC_CREATE_2(name, cls, ICompressCoder) 27370b324cSopenharmony_ci 28370b324cSopenharmony_ci#define REGISTER_CODEC_NAME(x) CRegisterCodec ## x 29370b324cSopenharmony_ci#define REGISTER_CODEC_VAR(x) static const CCodecInfo g_CodecInfo_ ## x = 30370b324cSopenharmony_ci 31370b324cSopenharmony_ci#define REGISTER_CODEC(x) struct REGISTER_CODEC_NAME(x) { \ 32370b324cSopenharmony_ci REGISTER_CODEC_NAME(x)() { RegisterCodec(&g_CodecInfo_ ## x); }}; \ 33370b324cSopenharmony_ci static REGISTER_CODEC_NAME(x) g_RegisterCodec_ ## x; 34370b324cSopenharmony_ci 35370b324cSopenharmony_ci 36370b324cSopenharmony_ci#define REGISTER_CODECS_NAME(x) CRegisterCodecs ## x 37370b324cSopenharmony_ci#define REGISTER_CODECS_VAR static const CCodecInfo g_CodecsInfo[] = 38370b324cSopenharmony_ci 39370b324cSopenharmony_ci#define REGISTER_CODECS(x) struct REGISTER_CODECS_NAME(x) { \ 40370b324cSopenharmony_ci REGISTER_CODECS_NAME(x)() { for (unsigned i = 0; i < Z7_ARRAY_SIZE(g_CodecsInfo); i++) \ 41370b324cSopenharmony_ci RegisterCodec(&g_CodecsInfo[i]); }}; \ 42370b324cSopenharmony_ci static REGISTER_CODECS_NAME(x) g_RegisterCodecs; 43370b324cSopenharmony_ci 44370b324cSopenharmony_ci 45370b324cSopenharmony_ci#define REGISTER_CODEC_2(x, crDec, crEnc, id, name) \ 46370b324cSopenharmony_ci REGISTER_CODEC_VAR(x) \ 47370b324cSopenharmony_ci { crDec, crEnc, id, name, 1, false }; \ 48370b324cSopenharmony_ci REGISTER_CODEC(x) 49370b324cSopenharmony_ci 50370b324cSopenharmony_ci 51370b324cSopenharmony_ci#ifdef Z7_EXTRACT_ONLY 52370b324cSopenharmony_ci #define REGISTER_CODEC_E(x, clsDec, clsEnc, id, name) \ 53370b324cSopenharmony_ci REGISTER_CODEC_CREATE(CreateDec, clsDec) \ 54370b324cSopenharmony_ci REGISTER_CODEC_2(x, CreateDec, NULL, id, name) 55370b324cSopenharmony_ci#else 56370b324cSopenharmony_ci #define REGISTER_CODEC_E(x, clsDec, clsEnc, id, name) \ 57370b324cSopenharmony_ci REGISTER_CODEC_CREATE(CreateDec, clsDec) \ 58370b324cSopenharmony_ci REGISTER_CODEC_CREATE(CreateEnc, clsEnc) \ 59370b324cSopenharmony_ci REGISTER_CODEC_2(x, CreateDec, CreateEnc, id, name) 60370b324cSopenharmony_ci#endif 61370b324cSopenharmony_ci 62370b324cSopenharmony_ci 63370b324cSopenharmony_ci 64370b324cSopenharmony_ci#define REGISTER_FILTER_CREATE(name, cls) REGISTER_CODEC_CREATE_2(name, cls, ICompressFilter) 65370b324cSopenharmony_ci 66370b324cSopenharmony_ci#define REGISTER_FILTER_ITEM(crDec, crEnc, id, name) \ 67370b324cSopenharmony_ci { crDec, crEnc, id, name, 1, true } 68370b324cSopenharmony_ci 69370b324cSopenharmony_ci#define REGISTER_FILTER(x, crDec, crEnc, id, name) \ 70370b324cSopenharmony_ci REGISTER_CODEC_VAR(x) \ 71370b324cSopenharmony_ci REGISTER_FILTER_ITEM(crDec, crEnc, id, name); \ 72370b324cSopenharmony_ci REGISTER_CODEC(x) 73370b324cSopenharmony_ci 74370b324cSopenharmony_ci#ifdef Z7_EXTRACT_ONLY 75370b324cSopenharmony_ci #define REGISTER_FILTER_E(x, clsDec, clsEnc, id, name) \ 76370b324cSopenharmony_ci REGISTER_FILTER_CREATE(x ## _CreateDec, clsDec) \ 77370b324cSopenharmony_ci REGISTER_FILTER(x, x ## _CreateDec, NULL, id, name) 78370b324cSopenharmony_ci#else 79370b324cSopenharmony_ci #define REGISTER_FILTER_E(x, clsDec, clsEnc, id, name) \ 80370b324cSopenharmony_ci REGISTER_FILTER_CREATE(x ## _CreateDec, clsDec) \ 81370b324cSopenharmony_ci REGISTER_FILTER_CREATE(x ## _CreateEnc, clsEnc) \ 82370b324cSopenharmony_ci REGISTER_FILTER(x, x ## _CreateDec, x ## _CreateEnc, id, name) 83370b324cSopenharmony_ci#endif 84370b324cSopenharmony_ci 85370b324cSopenharmony_ci 86370b324cSopenharmony_ci 87370b324cSopenharmony_cistruct CHasherInfo 88370b324cSopenharmony_ci{ 89370b324cSopenharmony_ci IHasher * (*CreateHasher)(); 90370b324cSopenharmony_ci CMethodId Id; 91370b324cSopenharmony_ci const char *Name; 92370b324cSopenharmony_ci UInt32 DigestSize; 93370b324cSopenharmony_ci}; 94370b324cSopenharmony_ci 95370b324cSopenharmony_civoid RegisterHasher(const CHasherInfo *hasher) throw(); 96370b324cSopenharmony_ci 97370b324cSopenharmony_ci#define REGISTER_HASHER_NAME(x) CRegHasher_ ## x 98370b324cSopenharmony_ci 99370b324cSopenharmony_ci#define REGISTER_HASHER(cls, id, name, size) \ 100370b324cSopenharmony_ci Z7_COM7F_IMF2(UInt32, cls::GetDigestSize()) { return size; } \ 101370b324cSopenharmony_ci static IHasher *CreateHasherSpec() { return new cls(); } \ 102370b324cSopenharmony_ci static const CHasherInfo g_HasherInfo = { CreateHasherSpec, id, name, size }; \ 103370b324cSopenharmony_ci struct REGISTER_HASHER_NAME(cls) { REGISTER_HASHER_NAME(cls)() { RegisterHasher(&g_HasherInfo); }}; \ 104370b324cSopenharmony_ci static REGISTER_HASHER_NAME(cls) g_RegisterHasher; 105370b324cSopenharmony_ci 106370b324cSopenharmony_ci#endif 107