res_format_attr_siren7.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2016, Digium, Inc.
  5. *
  6. * Joshua Colp <jcolp@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*!
  19. * \file
  20. * \brief Siren7 format attribute interface
  21. *
  22. * \author Joshua Colp <jcolp@digium.com>
  23. */
  24. /*** MODULEINFO
  25. <support_level>core</support_level>
  26. ***/
  27. #include "asterisk.h"
  28. #include <ctype.h> /* for tolower */
  29. #include "asterisk/module.h"
  30. #include "asterisk/format.h"
  31. #include "asterisk/astobj2.h" /* for ao2_bump */
  32. #include "asterisk/logger.h" /* for ast_log, LOG_WARNING */
  33. #include "asterisk/strings.h" /* for ast_str_append */
  34. /* Destroy is a required callback and must exist */
  35. static void siren7_destroy(struct ast_format *format)
  36. {
  37. }
  38. /* Clone is a required callback and must exist */
  39. static int siren7_clone(const struct ast_format *src, struct ast_format *dst)
  40. {
  41. return 0;
  42. }
  43. static struct ast_format *siren7_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
  44. {
  45. char *attribs = ast_strdupa(attributes), *attrib;
  46. unsigned int val;
  47. /* lower-case everything, so we are case-insensitive */
  48. for (attrib = attribs; *attrib; ++attrib) {
  49. *attrib = tolower(*attrib);
  50. } /* based on channels/chan_sip.c:process_a_sdp_image() */
  51. if (sscanf(attribs, "bitrate=%30u", &val) == 1) {
  52. if (val != 32000) {
  53. ast_log(LOG_WARNING, "Got Siren7 offer at %u bps, but only 32000 bps supported; ignoring.\n", val);
  54. return NULL;
  55. }
  56. }
  57. /* We aren't modifying the format and once passed back it won't be touched, so use what we were given */
  58. return ao2_bump((struct ast_format *)format);
  59. }
  60. static void siren7_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str)
  61. {
  62. ast_str_append(str, 0, "a=fmtp:%u bitrate=32000\r\n", payload);
  63. }
  64. static struct ast_format_interface siren7_interface = {
  65. .format_destroy = siren7_destroy,
  66. .format_clone = siren7_clone,
  67. .format_parse_sdp_fmtp = siren7_parse_sdp_fmtp,
  68. .format_generate_sdp_fmtp = siren7_generate_sdp_fmtp,
  69. };
  70. static int load_module(void)
  71. {
  72. if (ast_format_interface_register("siren7", &siren7_interface)) {
  73. return AST_MODULE_LOAD_DECLINE;
  74. }
  75. return AST_MODULE_LOAD_SUCCESS;
  76. }
  77. static int unload_module(void)
  78. {
  79. return 0;
  80. }
  81. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Siren7 Format Attribute Module",
  82. .support_level = AST_MODULE_SUPPORT_CORE,
  83. .load = load_module,
  84. .unload = unload_module,
  85. .load_pri = AST_MODPRI_CHANNEL_DEPEND,
  86. );