res_format_attr_siren14.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 Siren14 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. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  29. #include "asterisk/module.h"
  30. #include "asterisk/format.h"
  31. /* Destroy is a required callback and must exist */
  32. static void siren14_destroy(struct ast_format *format)
  33. {
  34. }
  35. /* Clone is a required callback and must exist */
  36. static int siren14_clone(const struct ast_format *src, struct ast_format *dst)
  37. {
  38. return 0;
  39. }
  40. static struct ast_format *siren14_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
  41. {
  42. unsigned int val;
  43. if (sscanf(attributes, "bitrate=%30u", &val) == 1) {
  44. if (val != 48000) {
  45. ast_log(LOG_WARNING, "Got siren14 offer at %u bps, but only 48000 bps supported; ignoring.\n", val);
  46. return NULL;
  47. }
  48. }
  49. /* We aren't modifying the format and once passed back it won't be touched, so use what we were given */
  50. return ao2_bump((struct ast_format *)format);
  51. }
  52. static void siren14_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str)
  53. {
  54. ast_str_append(str, 0, "a=fmtp:%u bitrate=48000\r\n", payload);
  55. }
  56. static struct ast_format_interface siren14_interface = {
  57. .format_destroy = siren14_destroy,
  58. .format_clone = siren14_clone,
  59. .format_parse_sdp_fmtp = siren14_parse_sdp_fmtp,
  60. .format_generate_sdp_fmtp = siren14_generate_sdp_fmtp,
  61. };
  62. static int load_module(void)
  63. {
  64. if (ast_format_interface_register("siren14", &siren14_interface)) {
  65. return AST_MODULE_LOAD_DECLINE;
  66. }
  67. return AST_MODULE_LOAD_SUCCESS;
  68. }
  69. static int unload_module(void)
  70. {
  71. return 0;
  72. }
  73. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Siren14 Format Attribute Module",
  74. .support_level = AST_MODULE_SUPPORT_CORE,
  75. .load = load_module,
  76. .unload = unload_module,
  77. .load_pri = AST_MODPRI_CHANNEL_DEPEND,
  78. );