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.

91 lines
2.5KB

  1. /*
  2. * Copyright (c) 2012 Justin Ruggles
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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 = avctx->block_align ? avctx->block_align
  49. : GSM_MS_BLOCK_SIZE;
  50. s->duration = GSM_FRAME_SIZE * 2;
  51. break;
  52. default:
  53. return AVERROR(EINVAL);
  54. }
  55. }
  56. if (!s->remaining)
  57. s->remaining = s->block_size;
  58. if (s->remaining <= buf_size) {
  59. next = s->remaining;
  60. s->remaining = 0;
  61. } else {
  62. next = END_NOT_FOUND;
  63. s->remaining -= buf_size;
  64. }
  65. if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) {
  66. *poutbuf = NULL;
  67. *poutbuf_size = 0;
  68. return buf_size;
  69. }
  70. s1->duration = s->duration;
  71. *poutbuf = buf;
  72. *poutbuf_size = buf_size;
  73. return next;
  74. }
  75. AVCodecParser ff_gsm_parser = {
  76. .codec_ids = { AV_CODEC_ID_GSM, AV_CODEC_ID_GSM_MS },
  77. .priv_data_size = sizeof(GSMParseContext),
  78. .parser_parse = gsm_parse,
  79. .parser_close = ff_parse_close,
  80. };