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.

75 lines
2.1KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. /**
  19. * @file
  20. * Sipr audio parser
  21. */
  22. #include "parser.h"
  23. typedef struct SiprParserContext{
  24. ParseContext pc;
  25. } SiprParserContext;
  26. static int sipr_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
  27. {
  28. int next;
  29. switch (avctx->block_align) {
  30. case 20:
  31. case 19:
  32. case 29:
  33. case 37: next = avctx->block_align; break;
  34. default:
  35. if (avctx->bit_rate > 12200) next = 20;
  36. else if (avctx->bit_rate > 7500 ) next = 19;
  37. else if (avctx->bit_rate > 5750 ) next = 29;
  38. else next = 37;
  39. }
  40. return FFMIN(next, buf_size);
  41. }
  42. static int sipr_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
  43. const uint8_t **poutbuf, int *poutbuf_size,
  44. const uint8_t *buf, int buf_size)
  45. {
  46. SiprParserContext *s = s1->priv_data;
  47. ParseContext *pc = &s->pc;
  48. int next;
  49. next = sipr_split(avctx, buf, buf_size);
  50. if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
  51. *poutbuf = NULL;
  52. *poutbuf_size = 0;
  53. return buf_size;
  54. }
  55. *poutbuf = buf;
  56. *poutbuf_size = buf_size;
  57. return next;
  58. }
  59. AVCodecParser ff_sipr_parser = {
  60. .codec_ids = { AV_CODEC_ID_SIPR },
  61. .priv_data_size = sizeof(SiprParserContext),
  62. .parser_parse = sipr_parse,
  63. .parser_close = ff_parse_close,
  64. };