You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.4KB

  1. /*
  2. * Interface to libgsm for gsm encoding/decoding
  3. * Copyright (c) 2005 Alban Bedel <albeu@free.fr>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file libgsm.c
  23. * Interface to libgsm for gsm encoding/decoding
  24. */
  25. #include "avcodec.h"
  26. #include <gsm.h>
  27. // gsm.h miss some essential constants
  28. #define GSM_BLOCK_SIZE 33
  29. #define GSM_FRAME_SIZE 160
  30. static int libgsm_init(AVCodecContext *avctx) {
  31. if (avctx->channels > 1 || avctx->sample_rate != 8000)
  32. return -1;
  33. avctx->frame_size = GSM_FRAME_SIZE;
  34. avctx->block_align = GSM_BLOCK_SIZE;
  35. avctx->priv_data = gsm_create();
  36. avctx->coded_frame= avcodec_alloc_frame();
  37. avctx->coded_frame->key_frame= 1;
  38. return 0;
  39. }
  40. static int libgsm_close(AVCodecContext *avctx) {
  41. gsm_destroy(avctx->priv_data);
  42. avctx->priv_data = NULL;
  43. return 0;
  44. }
  45. static int libgsm_encode_frame(AVCodecContext *avctx,
  46. unsigned char *frame, int buf_size, void *data) {
  47. // we need a full block
  48. if(buf_size < GSM_BLOCK_SIZE) return 0;
  49. gsm_encode(avctx->priv_data,data,frame);
  50. return GSM_BLOCK_SIZE;
  51. }
  52. AVCodec libgsm_encoder = {
  53. "gsm",
  54. CODEC_TYPE_AUDIO,
  55. CODEC_ID_GSM,
  56. 0,
  57. libgsm_init,
  58. libgsm_encode_frame,
  59. libgsm_close,
  60. };
  61. static int libgsm_decode_frame(AVCodecContext *avctx,
  62. void *data, int *data_size,
  63. uint8_t *buf, int buf_size) {
  64. if(buf_size < GSM_BLOCK_SIZE) return 0;
  65. if(gsm_decode(avctx->priv_data,buf,data)) return -1;
  66. *data_size = GSM_FRAME_SIZE*2;
  67. return GSM_BLOCK_SIZE;
  68. }
  69. AVCodec libgsm_decoder = {
  70. "gsm",
  71. CODEC_TYPE_AUDIO,
  72. CODEC_ID_GSM,
  73. 0,
  74. libgsm_init,
  75. NULL,
  76. libgsm_close,
  77. libgsm_decode_frame,
  78. };