g729acodec.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include "precompile.h"
  2. #include "g729acodec.h"
  3. #include "g729a.h"
  4. #define NB_CLOCK 8000
  5. #define WB_CLOCK 16000
  6. static codec_factory_t g_g729a_factory;
  7. typedef struct g729a_codec_t
  8. {
  9. codec_t base;
  10. g729a_encoder_t *encoder;
  11. g729a_decoder_t *decoder;
  12. } g729a_codec_t;
  13. static codec_t* g729a_codec_create(apr_pool_t *pool, int clock, int ptime)
  14. {
  15. g729a_codec_t *codec;
  16. if (clock != NB_CLOCK || ptime != 10)
  17. return NULL;
  18. codec = apr_palloc(pool, sizeof(g729a_codec_t));
  19. codec->base.pool = pool;
  20. codec->base.ptime = ptime;
  21. codec->base.clock = clock;
  22. codec->base.factory = &g_g729a_factory;
  23. codec->base.kvp_table = apr_table_make(pool, 3);
  24. g729a_encoder_create(&codec->encoder);
  25. g729a_decoder_create(&codec->decoder);
  26. return &codec->base;
  27. }
  28. static void g729a_codec_destroy(codec_t *c)
  29. {
  30. g729a_codec_t *codec = (g729a_codec_t *)c;
  31. g729a_encoder_destroy(codec->encoder);
  32. g729a_decoder_destroy(codec->decoder);
  33. }
  34. static apr_status_t g729a_codec_set_param(codec_t *codec,
  35. const char *key,
  36. const char *value)
  37. {
  38. return APR_ENOTIMPL;
  39. }
  40. static apr_status_t g729a_codec_get_param(codec_t *codec,
  41. const char *key,
  42. char *value)
  43. {
  44. return APR_ENOTIMPL;
  45. }
  46. static apr_status_t g729a_codec_init(codec_t *codec)
  47. {
  48. return APR_SUCCESS;
  49. }
  50. static apr_status_t g729a_codec_term(codec_t *codec)
  51. {
  52. return APR_SUCCESS;
  53. }
  54. static apr_status_t g729a_codec_encode(codec_t *c,
  55. const void *inbuf,
  56. int insize,
  57. void *outbuf,
  58. int *outsize)
  59. {
  60. g729a_codec_t *codec = (g729a_codec_t *)c;
  61. if (insize) {
  62. if (g729a_encoder_encode(codec->encoder, inbuf, insize, outbuf, outsize) != 0) {
  63. *outsize = 0;
  64. }
  65. } else {
  66. *outsize = 0;
  67. }
  68. return APR_SUCCESS;
  69. }
  70. static apr_status_t g729a_codec_decode(codec_t *c,
  71. const void *inbuf,
  72. int insize,
  73. void *outbuf,
  74. int *outsize)
  75. {
  76. g729a_codec_t *codec = (g729a_codec_t *)c;
  77. if (insize) {
  78. if (g729a_decoder_decode(codec->decoder, inbuf, insize, outbuf, outsize) != 0) {
  79. *outsize = 0;
  80. }
  81. } else {
  82. *outsize = 0;
  83. }
  84. return APR_SUCCESS;
  85. }
  86. apr_status_t audio_g729a_codec_decode(const void *inbuf,int insize,void *outbuf,int *outsize)
  87. {
  88. //g729a_codec_decode(NULL, inbuf, insize, outbuf, outsize);
  89. return APR_SUCCESS;
  90. }
  91. apr_status_t g729a_codec_factory_init()
  92. {
  93. apr_status_t status;
  94. g729a_init();
  95. g_g729a_factory.name = "G729";
  96. g_g729a_factory.create = &g729a_codec_create;
  97. g_g729a_factory.destroy = &g729a_codec_destroy;
  98. g_g729a_factory.set_param = &g729a_codec_set_param;
  99. g_g729a_factory.get_param = &g729a_codec_get_param;
  100. g_g729a_factory.init = &g729a_codec_init;
  101. g_g729a_factory.term = &g729a_codec_term;
  102. g_g729a_factory.encode = &g729a_codec_encode;
  103. g_g729a_factory.decode = &g729a_codec_decode;
  104. status = codec_factory_register(&g_g729a_factory);
  105. if (status != APR_SUCCESS)
  106. return status;
  107. return status;
  108. }
  109. apr_status_t g729a_codec_factory_term()
  110. {
  111. apr_status_t status;
  112. status = codec_factory_unregister(&g_g729a_factory);
  113. if (status != APR_SUCCESS)
  114. return status;
  115. g729a_term();
  116. return status;
  117. }