rtpdec_ilbc.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * RTP iLBC Depacketizer, RFC 3952
  3. * Copyright (c) 2012 Martin Storsjo
  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. #include "avformat.h"
  22. #include "rtpdec_formats.h"
  23. #include "libavutil/avstring.h"
  24. static int ilbc_parse_fmtp(AVStream *stream, PayloadContext *data,
  25. char *attr, char *value)
  26. {
  27. if (!strcmp(attr, "mode")) {
  28. int mode = atoi(value);
  29. switch (mode) {
  30. case 20:
  31. stream->codec->block_align = 38;
  32. break;
  33. case 30:
  34. stream->codec->block_align = 50;
  35. break;
  36. default:
  37. av_log(NULL, AV_LOG_ERROR, "Unsupported iLBC mode %d\n", mode);
  38. return AVERROR(EINVAL);
  39. }
  40. }
  41. return 0;
  42. }
  43. static int ilbc_parse_sdp_line(AVFormatContext *s, int st_index,
  44. PayloadContext *data, const char *line)
  45. {
  46. const char *p;
  47. AVStream *st;
  48. if (st_index < 0)
  49. return 0;
  50. st = s->streams[st_index];
  51. if (av_strstart(line, "fmtp:", &p)) {
  52. int ret = ff_parse_fmtp(st, data, p, ilbc_parse_fmtp);
  53. if (ret < 0)
  54. return ret;
  55. if (!st->codec->block_align) {
  56. av_log(s, AV_LOG_ERROR, "No iLBC mode set\n");
  57. return AVERROR(EINVAL);
  58. }
  59. }
  60. return 0;
  61. }
  62. RTPDynamicProtocolHandler ff_ilbc_dynamic_handler = {
  63. .enc_name = "iLBC",
  64. .codec_type = AVMEDIA_TYPE_AUDIO,
  65. .codec_id = AV_CODEC_ID_ILBC,
  66. .parse_sdp_a_line = ilbc_parse_sdp_line,
  67. };