Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Functions | Variables
res_format_attr_silk.c File Reference

SILK format attribute interface. More...

#include "asterisk.h"
#include <ctype.h>
#include "asterisk/module.h"
#include "asterisk/format.h"
#include "asterisk/logger.h"
#include "asterisk/strings.h"
#include "asterisk/utils.h"
Include dependency graph for res_format_attr_silk.c:

Go to the source code of this file.

Data Structures

struct  silk_attr
 SILK attribute structure. More...
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static void attr_init (struct silk_attr *attr)
 
static int load_module (void)
 
static int silk_clone (const struct ast_format *src, struct ast_format *dst)
 
static enum ast_format_cmp_res silk_cmp (const struct ast_format *format1, const struct ast_format *format2)
 
static void silk_destroy (struct ast_format *format)
 
static void silk_generate_sdp_fmtp (const struct ast_format *format, unsigned int payload, struct ast_str **str)
 
static const void * silk_get (const struct ast_format *format, const char *name)
 
static struct ast_formatsilk_getjoint (const struct ast_format *format1, const struct ast_format *format2)
 
static struct ast_formatsilk_parse_sdp_fmtp (const struct ast_format *format, const char *attributes)
 
static struct ast_formatsilk_set (const struct ast_format *format, const char *name, const char *value)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "SILK Format Attribute Module" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_format_interface silk_interface
 

Detailed Description

SILK format attribute interface.

Author
David Vossel dvoss.nosp@m.el@d.nosp@m.igium.nosp@m..com

Definition in file res_format_attr_silk.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 267 of file res_format_attr_silk.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 267 of file res_format_attr_silk.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 267 of file res_format_attr_silk.c.

◆ attr_init()

static void attr_init ( struct silk_attr attr)
static

Definition at line 59 of file res_format_attr_silk.c.

60{
61 memset(attr, 0, sizeof(*attr));
62}

Referenced by silk_clone(), and silk_getjoint().

◆ load_module()

static int load_module ( void  )
static

Definition at line 248 of file res_format_attr_silk.c.

249{
252 }
253
255}
#define ast_format_interface_register(codec, interface)
Register a format interface for use with the provided codec.
Definition: format.h:273
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static struct ast_format_interface silk_interface

References ast_format_interface_register, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and silk_interface.

◆ silk_clone()

static int silk_clone ( const struct ast_format src,
struct ast_format dst 
)
static

Definition at line 64 of file res_format_attr_silk.c.

65{
66 struct silk_attr *original = ast_format_get_attribute_data(src);
67 struct silk_attr *attr = ast_malloc(sizeof(*attr));
68
69 if (!attr) {
70 return -1;
71 }
72
73 if (original) {
74 *attr = *original;
75 } else {
76 attr_init(attr);
77 }
78
80
81 return 0;
82}
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
void ast_format_set_attribute_data(struct ast_format *format, void *attribute_data)
Set the attribute data on a format.
Definition: format.c:130
static void attr_init(struct silk_attr *attr)
SILK attribute structure.

References ast_format_get_attribute_data(), ast_format_set_attribute_data(), ast_malloc, and attr_init().

◆ silk_cmp()

static enum ast_format_cmp_res silk_cmp ( const struct ast_format format1,
const struct ast_format format2 
)
static

Definition at line 135 of file res_format_attr_silk.c.

136{
139 }
140
142}
unsigned int ast_format_get_sample_rate(const struct ast_format *format)
Get the sample rate of a media format.
Definition: format.c:379
@ AST_FORMAT_CMP_EQUAL
Definition: format.h:36
@ AST_FORMAT_CMP_NOT_EQUAL
Definition: format.h:38

References AST_FORMAT_CMP_EQUAL, AST_FORMAT_CMP_NOT_EQUAL, and ast_format_get_sample_rate().

◆ silk_destroy()

static void silk_destroy ( struct ast_format format)
static

Definition at line 52 of file res_format_attr_silk.c.

53{
54 struct silk_attr *attr = ast_format_get_attribute_data(format);
55
56 ast_free(attr);
57}
#define ast_free(a)
Definition: astmm.h:180

References ast_format_get_attribute_data(), and ast_free.

◆ silk_generate_sdp_fmtp()

static void silk_generate_sdp_fmtp ( const struct ast_format format,
unsigned int  payload,
struct ast_str **  str 
)
static

Definition at line 115 of file res_format_attr_silk.c.

116{
117 struct silk_attr *attr = ast_format_get_attribute_data(format);
118
119 if (!attr) {
120 return;
121 }
122
123 if ((attr->maxbitrate > 5000) && (attr->maxbitrate < 40000)) {
124 ast_str_append(str, 0, "a=fmtp:%u maxaveragebitrate=%u\r\n", payload, attr->maxbitrate);
125 }
126
127 if (attr->dtx) {
128 ast_str_append(str, 0, "a=fmtp:%u usedtx=%u\r\n", payload, attr->dtx);
129 }
130 if (attr->fec) {
131 ast_str_append(str, 0, "a=fmtp:%u useinbandfec=%u\r\n", payload, attr->fec);
132 }
133}
const char * str
Definition: app_jack.c:147
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:1139
unsigned int fec
unsigned int maxbitrate
unsigned int dtx

References ast_format_get_attribute_data(), ast_str_append(), silk_attr::dtx, silk_attr::fec, silk_attr::maxbitrate, and str.

◆ silk_get()

static const void * silk_get ( const struct ast_format format,
const char *  name 
)
static

Definition at line 216 of file res_format_attr_silk.c.

217{
218 struct silk_attr *attr = ast_format_get_attribute_data(format);
219 unsigned int *val;
220
221 if (!strcasecmp(name, "max_bitrate")) {
222 val = &attr->maxbitrate;
223 } else if (!strcasecmp(name, "dtx")) {
224 val = &attr->dtx;
225 } else if (!strcasecmp(name, "fec")) {
226 val = &attr->fec;
227 } else if (!strcasecmp(name, "packetloss_percentage")) {
228 val = &attr->packetloss_percentage;
229 } else {
230 ast_log(LOG_WARNING, "unknown attribute type %s\n", name);
231 return NULL;
232 }
233
234 return val;
235}
#define ast_log
Definition: astobj2.c:42
static const char name[]
Definition: format_mp3.c:68
#define LOG_WARNING
#define NULL
Definition: resample.c:96
unsigned int packetloss_percentage
Definition: ast_expr2.c:325

References ast_format_get_attribute_data(), ast_log, silk_attr::dtx, silk_attr::fec, LOG_WARNING, silk_attr::maxbitrate, name, NULL, and silk_attr::packetloss_percentage.

◆ silk_getjoint()

static struct ast_format * silk_getjoint ( const struct ast_format format1,
const struct ast_format format2 
)
static

Definition at line 144 of file res_format_attr_silk.c.

145{
146 struct silk_attr *attr1 = ast_format_get_attribute_data(format1);
147 struct silk_attr *attr2 = ast_format_get_attribute_data(format2);
148 struct ast_format *jointformat;
149 struct silk_attr *attr_res;
150
152 return NULL;
153 }
154
155 jointformat = ast_format_clone(format1);
156 if (!jointformat) {
157 return NULL;
158 }
159 attr_res = ast_format_get_attribute_data(jointformat);
160
161 if (!attr1 || !attr2) {
162 attr_init(attr_res);
163 } else {
164 /* Take the lowest max bitrate */
165 attr_res->maxbitrate = MIN(attr1->maxbitrate, attr2->maxbitrate);
166
167 /* Only do dtx if both sides want it. DTX is a trade off between
168 * computational complexity and bandwidth. */
169 attr_res->dtx = attr1->dtx && attr2->dtx ? 1 : 0;
170
171 /* Only do FEC if both sides want it. If a peer specifically requests not
172 * to receive with FEC, it may be a waste of bandwidth. */
173 attr_res->fec = attr1->fec && attr2->fec ? 1 : 0;
174
175 /* Use the maximum packetloss percentage between the two attributes. This affects how
176 * much redundancy is used in the FEC. */
178 }
179
180 return jointformat;
181}
struct ast_format * ast_format_clone(const struct ast_format *format)
Clone an existing media format so it can be modified.
Definition: format.c:180
Definition of a media format.
Definition: format.c:43
#define MIN(a, b)
Definition: utils.h:231
#define MAX(a, b)
Definition: utils.h:233

References ast_format_clone(), ast_format_get_attribute_data(), ast_format_get_sample_rate(), attr_init(), silk_attr::dtx, silk_attr::fec, MAX, silk_attr::maxbitrate, MIN, NULL, and silk_attr::packetloss_percentage.

◆ silk_parse_sdp_fmtp()

static struct ast_format * silk_parse_sdp_fmtp ( const struct ast_format format,
const char *  attributes 
)
static

Definition at line 84 of file res_format_attr_silk.c.

85{
86 char *attribs = ast_strdupa(attributes), *attrib;
87 struct ast_format *cloned;
88 struct silk_attr *attr;
89 unsigned int val;
90
91 cloned = ast_format_clone(format);
92 if (!cloned) {
93 return NULL;
94 }
95 attr = ast_format_get_attribute_data(cloned);
96
97 /* lower-case everything, so we are case-insensitive */
98 for (attrib = attribs; *attrib; ++attrib) {
99 *attrib = tolower(*attrib);
100 } /* based on channels/chan_sip.c:process_a_sdp_image() */
101
102 if (sscanf(attribs, "maxaveragebitrate=%30u", &val) == 1) {
103 attr->maxbitrate = val;
104 }
105 if (sscanf(attribs, "usedtx=%30u", &val) == 1) {
106 attr->dtx = val;
107 }
108 if (sscanf(attribs, "useinbandfec=%30u", &val) == 1) {
109 attr->fec = val;
110 }
111
112 return cloned;
113}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298

References ast_format_clone(), ast_format_get_attribute_data(), ast_strdupa, silk_attr::dtx, silk_attr::fec, silk_attr::maxbitrate, and NULL.

◆ silk_set()

static struct ast_format * silk_set ( const struct ast_format format,
const char *  name,
const char *  value 
)
static

Definition at line 183 of file res_format_attr_silk.c.

184{
185 struct ast_format *cloned;
186 struct silk_attr *attr;
187 unsigned int val;
188
189 if (sscanf(value, "%30u", &val) != 1) {
190 ast_log(LOG_WARNING, "Unknown value '%s' for attribute type '%s'\n",
191 value, name);
192 return NULL;
193 }
194
195 cloned = ast_format_clone(format);
196 if (!cloned) {
197 return NULL;
198 }
199 attr = ast_format_get_attribute_data(cloned);
200
201 if (!strcasecmp(name, "max_bitrate")) {
202 attr->maxbitrate = val;
203 } else if (!strcasecmp(name, "dtx")) {
204 attr->dtx = val;
205 } else if (!strcasecmp(name, "fec")) {
206 attr->fec = val;
207 } else if (!strcasecmp(name, "packetloss_percentage")) {
209 } else {
210 ast_log(LOG_WARNING, "unknown attribute type %s\n", name);
211 }
212
213 return cloned;
214}
int value
Definition: syslog.c:37

References ast_format_clone(), ast_format_get_attribute_data(), ast_log, silk_attr::dtx, silk_attr::fec, LOG_WARNING, silk_attr::maxbitrate, name, NULL, silk_attr::packetloss_percentage, and value.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 257 of file res_format_attr_silk.c.

258{
259 return 0;
260}

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "SILK Format Attribute Module" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND, }
static

Definition at line 267 of file res_format_attr_silk.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 267 of file res_format_attr_silk.c.

◆ silk_interface

struct ast_format_interface silk_interface
static

Definition at line 237 of file res_format_attr_silk.c.

Referenced by load_module().