Debian Codegraph @

res/res_format_attr_siren7.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2016, Digium, Inc.
5 *
6 * Joshua Colp <[email protected]>
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 /*!
20 * \file
21 * \brief Siren7 format attribute interface
22 *
23 * \author Joshua Colp <[email protected]>
24 */
25
26 /*** MODULEINFO
27 <support_level>core</support_level>
28 ***/
29
30 #include "asterisk.h"
31
32 #include <ctype.h> /* for tolower */
33
34 #include "asterisk/module.h"
35 #include "asterisk/format.h"
36 #include "asterisk/astobj2.h" /* for ao2_bump */
37 #include "asterisk/logger.h" /* for ast_log, LOG_WARNING */
38 #include "asterisk/strings.h" /* for ast_str_append */
39
40 /* Destroy is a required callback and must exist */
41 static void siren7_destroy(struct ast_format *format)
42 {
43 }
44
45 /* Clone is a required callback and must exist */
46 static int siren7_clone(const struct ast_format *src, struct ast_format *dst)
47 {
48 return 0;
49 }
50
51 static struct ast_format *siren7_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
52 {
53 char *attribs = ast_strdupa(attributes), *attrib;
54 unsigned int val;
55
56 /* lower-case everything, so we are case-insensitive */
57 for (attrib = attribs; *attrib; ++attrib) {
58 *attrib = tolower(*attrib);
59 } /* based on channels/chan_sip.c:process_a_sdp_image() */
60
61 if (sscanf(attribs, "bitrate=%30u", &val) == 1) {
62 if (val != 32000) {
63 ast_log(LOG_WARNING, "Got Siren7 offer at %u bps, but only 32000 bps supported; ignoring.\n", val);
64 return NULL;
65 }
66 }
67
68 /* We aren't modifying the format and once passed back it won't be touched, so use what we were given */
69 return ao2_bump((struct ast_format *)format);
70 }
71
72 static void siren7_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str)
73 {
74 ast_str_append(str, 0, "a=fmtp:%u bitrate=32000\r\n", payload);
75 }
76
77 static struct ast_format_interface siren7_interface = {
78 .format_destroy = siren7_destroy,
79 .format_clone = siren7_clone,
80 .format_parse_sdp_fmtp = siren7_parse_sdp_fmtp,
81 .format_generate_sdp_fmtp = siren7_generate_sdp_fmtp,
82 };
83
84 static int load_module(void)
85 {
86 if (ast_format_interface_register("siren7", &siren7_interface)) {
87 return AST_MODULE_LOAD_DECLINE;
88 }
89
90 return AST_MODULE_LOAD_SUCCESS;
91 }
92
93 static int unload_module(void)
94 {
95 return 0;
96 }
97
98 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Siren7 Format Attribute Module",
99 .support_level = AST_MODULE_SUPPORT_CORE,
100 .load = load_module,
101 .unload = unload_module,
102 .load_pri = AST_MODPRI_CHANNEL_DEPEND,
103 );