Asterisk - The Open Source Telephony Project  18.5.0
res_format_attr_siren7.c
Go to the documentation of this file.
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 
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)) {
88  }
89 
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 );
static struct ast_format * siren7_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
Asterisk main include file. File version handling, generic pbx functions.
Optional format interface to extend format operations.
Definition: format.h:44
String manipulation functions.
Definition: ast_expr2.c:325
#define LOG_WARNING
Definition: logger.h:274
static void siren7_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str)
Definition of a media format.
Definition: format.c:43
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
const char * str
Definition: app_jack.c:147
static int load_module(void)
#define NULL
Definition: resample.c:96
Media Format API.
#define ao2_bump(obj)
Definition: astobj2.h:491
#define ast_log
Definition: astobj2.c:42
static int unload_module(void)
void(*const format_destroy)(struct ast_format *format)
Callback for when the format is destroyed, used to release attribute resources.
Definition: format.h:50
static void siren7_destroy(struct ast_format *format)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_format_interface_register(codec, interface)
Register a format interface for use with the provided codec.
Definition: format.h:273
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static int siren7_clone(const struct ast_format *src, struct ast_format *dst)
Support for logging to various files, console and syslog Configuration in file logger.conf.
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
static struct ast_format_interface siren7_interface
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.
static snd_pcm_format_t format
Definition: chan_alsa.c:102