123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- #include "precompile.h"
- #pragma warning(disable: 4005)
- #include "bvcodec.h"
- #include "broadvoice.h"
- #define NB_CLOCK 8000
- #define WB_CLOCK 16000
- static codec_factory_t g_bv16_factory;
- typedef struct bv16_codec_t
- {
- codec_t base;
- bv16_encode_state_t *encoder;
- bv16_decode_state_t *decoder;
- } bv16_codec_t;
- static codec_t* bv16_codec_create(apr_pool_t *pool, int clock, int ptime)
- {
- bv16_codec_t *codec;
- if (clock != NB_CLOCK)
- return NULL;
- codec = apr_palloc(pool, sizeof(bv16_codec_t));
- codec->base.pool = pool;
- codec->base.ptime = ptime;
- codec->base.clock = clock;
- codec->base.factory = &g_bv16_factory;
- codec->base.kvp_table = apr_table_make(pool, 3);
- codec->encoder = bv16_encode_init(NULL);
- codec->decoder = bv16_decode_init(NULL);
- return &codec->base;
- }
- static void bv16_codec_destroy(codec_t *c)
- {
- bv16_codec_t *codec = (bv16_codec_t *)c;
- bv16_encode_free(codec->encoder);
- bv16_decode_free(codec->decoder);
- }
- static apr_status_t bv16_codec_set_param(codec_t *codec,
- const char *key,
- const char *value)
- {
- return APR_ENOTIMPL;
- }
- static apr_status_t bv16_codec_get_param(codec_t *codec,
- const char *key,
- char *value)
- {
- return APR_ENOTIMPL;
- }
- static apr_status_t bv16_codec_init(codec_t *codec)
- {
- return APR_SUCCESS;
- }
- static apr_status_t bv16_codec_term(codec_t *codec)
- {
- return APR_SUCCESS;
- }
- static apr_status_t bv16_codec_encode(codec_t *c,
- const void *inbuf,
- int insize,
- void *outbuf,
- int *outsize)
- {
- bv16_codec_t *codec = (bv16_codec_t *)c;
- if (insize) {
- *outsize = bv16_encode(codec->encoder, outbuf, inbuf, insize/2);
- } else {
- *outsize = 0;
- }
- return APR_SUCCESS;
- }
- static apr_status_t bv16_codec_decode(codec_t *c,
- const void *inbuf,
- int insize,
- void *outbuf,
- int *outsize)
- {
- bv16_codec_t *codec = (bv16_codec_t *)c;
- if (insize) {
- *outsize = 2 * bv16_decode(codec->decoder, outbuf, inbuf, insize);
- } else {
- *outsize = 0;
- }
- return APR_SUCCESS;
- }
- static codec_factory_t g_bv32_factory;
- typedef struct bv32_codec_t
- {
- codec_t base;
- bv32_encode_state_t *encoder;
- bv32_decode_state_t *decoder;
- } bv32_codec_t;
- static codec_t* bv32_codec_create(apr_pool_t *pool, int clock, int ptime)
- {
- bv32_codec_t *codec;
- apr_status_t status;
- apr_pool_t *subpool;
- if (clock != WB_CLOCK)
- return NULL;
- status = apr_pool_create(&subpool, pool);
- if (status != APR_SUCCESS)
- return NULL;
- codec = apr_palloc(pool, sizeof(bv32_codec_t));
- codec->base.pool = subpool;
- codec->base.ptime = ptime;
- codec->base.clock = clock;
- codec->base.factory = &g_bv16_factory;
- codec->base.kvp_table = apr_table_make(subpool, 3);
- codec->encoder = bv32_encode_init(NULL);
- codec->decoder = bv32_decode_init(NULL);
- return &codec->base;
- }
- static void bv32_codec_destroy(codec_t *c)
- {
- bv32_codec_t *codec = (bv32_codec_t *)c;
- bv32_encode_free(codec->encoder);
- bv32_decode_free(codec->decoder);
- apr_pool_destroy(codec->base.pool);
- }
- static apr_status_t bv32_codec_set_param(codec_t *codec,
- const char *key,
- const char *value)
- {
- return APR_ENOTIMPL;
- }
- static apr_status_t bv32_codec_get_param(codec_t *codec,
- const char *key,
- char *value)
- {
- return APR_ENOTIMPL;
- }
- static apr_status_t bv32_codec_init(codec_t *codec)
- {
- return APR_SUCCESS;
- }
- static apr_status_t bv32_codec_term(codec_t *codec)
- {
- return APR_SUCCESS;
- }
- static apr_status_t bv32_codec_encode(codec_t *c,
- const void *inbuf,
- int insize,
- void *outbuf,
- int *outsize)
- {
- bv32_codec_t *codec = (bv32_codec_t *)c;
- if (insize) {
- *outsize = bv32_encode(codec->encoder, outbuf, inbuf, insize/2);
- } else {
- *outsize = 0;
- }
- return APR_SUCCESS;
- }
- static apr_status_t bv32_codec_decode(codec_t *c,
- const void *inbuf,
- int insize,
- void *outbuf,
- int *outsize)
- {
- bv32_codec_t *codec = (bv32_codec_t *)c;
- if (insize) {
- *outsize = 2 * bv32_decode(codec->decoder, outbuf, inbuf, insize);
- } else {
- *outsize = 0;
- }
- return APR_SUCCESS;
- }
- apr_status_t bv_codec_factory_init()
- {
- apr_status_t status;
- g_bv16_factory.name = "BV16";
- g_bv16_factory.create = &bv16_codec_create;
- g_bv16_factory.destroy = &bv16_codec_destroy;
- g_bv16_factory.set_param = &bv16_codec_set_param;
- g_bv16_factory.get_param = &bv16_codec_get_param;
- g_bv16_factory.init = &bv16_codec_init;
- g_bv16_factory.term = &bv16_codec_term;
- g_bv16_factory.encode = &bv16_codec_encode;
- g_bv16_factory.decode = &bv16_codec_decode;
- status = codec_factory_register(&g_bv16_factory);
- if (status != APR_SUCCESS)
- return status;
- g_bv32_factory.name = "BV32";
- g_bv32_factory.create = &bv32_codec_create;
- g_bv32_factory.destroy = &bv32_codec_destroy;
- g_bv32_factory.set_param = &bv32_codec_set_param;
- g_bv32_factory.get_param = &bv32_codec_get_param;
- g_bv32_factory.init = &bv32_codec_init;
- g_bv32_factory.term = &bv32_codec_term;
- g_bv32_factory.encode = &bv32_codec_encode;
- g_bv32_factory.decode = &bv32_codec_decode;
- status = codec_factory_register(&g_bv32_factory);
- if (status != APR_SUCCESS)
- return status;
- return status;
- }
- apr_status_t bv_codec_factory_term()
- {
- apr_status_t status;
- status = codec_factory_unregister(&g_bv16_factory);
- if (status != APR_SUCCESS)
- return status;
- status = codec_factory_unregister(&g_bv32_factory);
- if (status != APR_SUCCESS)
- return status;
- return status;
- }
|