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.

93 lines
2.5KB

  1. /*
  2. * Copyright (c) 2012 Justin Ruggles
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * GSM audio parser
  23. *
  24. * Splits packets into individual blocks.
  25. */
  26. #include "parser.h"
  27. #include "gsm.h"
  28. typedef struct GSMParseContext {
  29. ParseContext pc;
  30. int block_size;
  31. int duration;
  32. int remaining;
  33. } GSMParseContext;
  34. static int gsm_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
  35. const uint8_t **poutbuf, int *poutbuf_size,
  36. const uint8_t *buf, int buf_size)
  37. {
  38. GSMParseContext *s = s1->priv_data;
  39. ParseContext *pc = &s->pc;
  40. int next;
  41. if (!s->block_size) {
  42. switch (avctx->codec_id) {
  43. case AV_CODEC_ID_GSM:
  44. s->block_size = GSM_BLOCK_SIZE;
  45. s->duration = GSM_FRAME_SIZE;
  46. break;
  47. case AV_CODEC_ID_GSM_MS:
  48. s->block_size = GSM_MS_BLOCK_SIZE;
  49. s->duration = GSM_FRAME_SIZE * 2;
  50. break;
  51. default:
  52. *poutbuf = buf;
  53. *poutbuf_size = buf_size;
  54. av_log(avctx, AV_LOG_ERROR, "Invalid codec_id\n");
  55. return buf_size;
  56. }
  57. }
  58. if (!s->remaining)
  59. s->remaining = s->block_size;
  60. if (s->remaining <= buf_size) {
  61. next = s->remaining;
  62. s->remaining = 0;
  63. } else {
  64. next = END_NOT_FOUND;
  65. s->remaining -= buf_size;
  66. }
  67. if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) {
  68. *poutbuf = NULL;
  69. *poutbuf_size = 0;
  70. return buf_size;
  71. }
  72. s1->duration = s->duration;
  73. *poutbuf = buf;
  74. *poutbuf_size = buf_size;
  75. return next;
  76. }
  77. AVCodecParser ff_gsm_parser = {
  78. .codec_ids = { AV_CODEC_ID_GSM, AV_CODEC_ID_GSM_MS },
  79. .priv_data_size = sizeof(GSMParseContext),
  80. .parser_parse = gsm_parse,
  81. .parser_close = ff_parse_close,
  82. };