123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- #include "precompile.h"
- #include "g729acodec.h"
- #include "g729a.h"
- #define NB_CLOCK 8000
- #define WB_CLOCK 16000
- static codec_factory_t g_g729a_factory;
- typedef struct g729a_codec_t
- {
- codec_t base;
- g729a_encoder_t *encoder;
- g729a_decoder_t *decoder;
- } g729a_codec_t;
- static codec_t* g729a_codec_create(apr_pool_t *pool, int clock, int ptime)
- {
- g729a_codec_t *codec;
- if (clock != NB_CLOCK || ptime != 10)
- return NULL;
- codec = apr_palloc(pool, sizeof(g729a_codec_t));
- codec->base.pool = pool;
- codec->base.ptime = ptime;
- codec->base.clock = clock;
- codec->base.factory = &g_g729a_factory;
- codec->base.kvp_table = apr_table_make(pool, 3);
- g729a_encoder_create(&codec->encoder);
- g729a_decoder_create(&codec->decoder);
- return &codec->base;
- }
- static void g729a_codec_destroy(codec_t *c)
- {
- g729a_codec_t *codec = (g729a_codec_t *)c;
- g729a_encoder_destroy(codec->encoder);
- g729a_decoder_destroy(codec->decoder);
- }
- static apr_status_t g729a_codec_set_param(codec_t *codec,
- const char *key,
- const char *value)
- {
- return APR_ENOTIMPL;
- }
- static apr_status_t g729a_codec_get_param(codec_t *codec,
- const char *key,
- char *value)
- {
- return APR_ENOTIMPL;
- }
- static apr_status_t g729a_codec_init(codec_t *codec)
- {
- return APR_SUCCESS;
- }
- static apr_status_t g729a_codec_term(codec_t *codec)
- {
- return APR_SUCCESS;
- }
- static apr_status_t g729a_codec_encode(codec_t *c,
- const void *inbuf,
- int insize,
- void *outbuf,
- int *outsize)
- {
- g729a_codec_t *codec = (g729a_codec_t *)c;
- if (insize) {
- if (g729a_encoder_encode(codec->encoder, inbuf, insize, outbuf, outsize) != 0) {
- *outsize = 0;
- }
- } else {
- *outsize = 0;
- }
- return APR_SUCCESS;
- }
- static apr_status_t g729a_codec_decode(codec_t *c,
- const void *inbuf,
- int insize,
- void *outbuf,
- int *outsize)
- {
- g729a_codec_t *codec = (g729a_codec_t *)c;
- if (insize) {
- if (g729a_decoder_decode(codec->decoder, inbuf, insize, outbuf, outsize) != 0) {
- *outsize = 0;
- }
- } else {
- *outsize = 0;
- }
- return APR_SUCCESS;
- }
- apr_status_t audio_g729a_codec_decode(const void *inbuf,int insize,void *outbuf,int *outsize)
- {
- //g729a_codec_decode(NULL, inbuf, insize, outbuf, outsize);
- return APR_SUCCESS;
- }
- apr_status_t g729a_codec_factory_init()
- {
- apr_status_t status;
- g729a_init();
- g_g729a_factory.name = "G729";
- g_g729a_factory.create = &g729a_codec_create;
- g_g729a_factory.destroy = &g729a_codec_destroy;
- g_g729a_factory.set_param = &g729a_codec_set_param;
- g_g729a_factory.get_param = &g729a_codec_get_param;
- g_g729a_factory.init = &g729a_codec_init;
- g_g729a_factory.term = &g729a_codec_term;
- g_g729a_factory.encode = &g729a_codec_encode;
- g_g729a_factory.decode = &g729a_codec_decode;
- status = codec_factory_register(&g_g729a_factory);
- if (status != APR_SUCCESS)
- return status;
- return status;
- }
- apr_status_t g729a_codec_factory_term()
- {
- apr_status_t status;
- status = codec_factory_unregister(&g_g729a_factory);
- if (status != APR_SUCCESS)
- return status;
- g729a_term();
- return status;
- }
|