Asterisk - The Open Source Telephony Project GIT-master-2de1a68
Functions | Variables
res_format_attr_ilbc.c File Reference

iLBC format attribute interface More...

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

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int ilbc_clone (const struct ast_format *src, struct ast_format *dst)
 
static void ilbc_destroy (struct ast_format *format)
 
static void ilbc_generate_sdp_fmtp (const struct ast_format *format, unsigned int payload, struct ast_str **str)
 
static struct ast_formatilbc_getjoint (const struct ast_format *format1, const struct ast_format *format2)
 
static struct ast_formatilbc_parse_sdp_fmtp (const struct ast_format *format, const char *attributes)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "iLBC 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 ilbc_attr default_ilbc_attr
 
static struct ast_format_interface ilbc_interface
 

Detailed Description

iLBC format attribute interface

Author
Alexander Traud pabst.nosp@m.raud.nosp@m.@comp.nosp@m.user.nosp@m.ve.co.nosp@m.m
Note
http://tools.ietf.org/html/rfc3952

Definition in file res_format_attr_ilbc.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 179 of file res_format_attr_ilbc.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 179 of file res_format_attr_ilbc.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 179 of file res_format_attr_ilbc.c.

◆ ilbc_clone()

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

Definition at line 54 of file res_format_attr_ilbc.c.

55{
56 struct ilbc_attr *original = ast_format_get_attribute_data(src);
57 struct ilbc_attr *attr = ast_malloc(sizeof(*attr));
58
59 if (!attr) {
60 return -1;
61 }
62
63 if (original) {
64 *attr = *original;
65 } else {
66 *attr = default_ilbc_attr;
67 }
68
70
71 return 0;
72}
#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 struct ilbc_attr default_ilbc_attr
Definition: ilbc.h:4

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

◆ ilbc_destroy()

static void ilbc_destroy ( struct ast_format format)
static

Definition at line 47 of file res_format_attr_ilbc.c.

48{
49 struct ilbc_attr *attr = ast_format_get_attribute_data(format);
50
51 ast_free(attr);
52}
#define ast_free(a)
Definition: astmm.h:180

References ast_format_get_attribute_data(), and ast_free.

◆ ilbc_generate_sdp_fmtp()

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

Definition at line 102 of file res_format_attr_ilbc.c.

103{
104 struct ilbc_attr *attr = ast_format_get_attribute_data(format);
105
106 if (!attr) {
107 attr = &default_ilbc_attr;
108 }
109
110 /* When the VoIP/SIP client Zoiper calls Asterisk and its
111 * iLBC 20 is disabled but iLBC 30 enabled, Zoiper still
112 * falls back to iLBC 20, when there is no mode=30 in the
113 * answer. Consequently, Zoiper defaults to iLBC 20. To
114 * make that client happy, Asterisk sends mode always.
115 * tested in June 2016, Zoiper Premium 1.13.2 for iPhone
116 */
117 /* if (attr->mode != 30) */ {
118 ast_str_append(str, 0, "a=fmtp:%u mode=%u\r\n", payload, attr->mode);
119 }
120}
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 mode
Definition: ilbc.h:5

References ast_format_get_attribute_data(), ast_str_append(), default_ilbc_attr, ilbc_attr::mode, and str.

◆ ilbc_getjoint()

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

Definition at line 122 of file res_format_attr_ilbc.c.

123{
124 struct ast_format *jointformat;
125 struct ilbc_attr *attr1 = ast_format_get_attribute_data(format1);
126 struct ilbc_attr *attr2 = ast_format_get_attribute_data(format2);
127 struct ilbc_attr *attr_res;
128
129 if (!attr1) {
130 attr1 = &default_ilbc_attr;
131 }
132
133 if (!attr2) {
134 attr2 = &default_ilbc_attr;
135 }
136
137 jointformat = ast_format_clone(format1);
138 if (!jointformat) {
139 return NULL;
140 }
141 attr_res = ast_format_get_attribute_data(jointformat);
142
143 if (attr1->mode != attr2->mode) {
144 attr_res->mode = 30;
145 }
146
147 return jointformat;
148}
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
#define NULL
Definition: resample.c:96
Definition of a media format.
Definition: format.c:43

References ast_format_clone(), ast_format_get_attribute_data(), default_ilbc_attr, ilbc_attr::mode, and NULL.

◆ ilbc_parse_sdp_fmtp()

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

Definition at line 74 of file res_format_attr_ilbc.c.

75{
76 char *attribs = ast_strdupa(attributes), *attrib;
77 struct ast_format *cloned;
78 struct ilbc_attr *attr;
79 const char *kvp;
80 unsigned int val;
81
82 cloned = ast_format_clone(format);
83 if (!cloned) {
84 return NULL;
85 }
86 attr = ast_format_get_attribute_data(cloned);
87
88 /* lower-case everything, so we are case-insensitive */
89 for (attrib = attribs; *attrib; ++attrib) {
90 *attrib = tolower(*attrib);
91 } /* based on channels/chan_sip.c:process_a_sdp_image() */
92
93 if ((kvp = strstr(attribs, "mode")) && sscanf(kvp, "mode=%30u", &val) == 1) {
94 attr->mode = val;
95 } else {
96 attr->mode = 30; /* optional attribute; 30 is default value */
97 }
98
99 return cloned;
100}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
Definition: ast_expr2.c:325

References ast_format_clone(), ast_format_get_attribute_data(), ast_strdupa, ilbc_attr::mode, and NULL.

◆ load_module()

static int load_module ( void  )
static

Definition at line 160 of file res_format_attr_ilbc.c.

161{
164 }
165
167}
#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 ilbc_interface

References ast_format_interface_register, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and ilbc_interface.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 169 of file res_format_attr_ilbc.c.

170{
171 return 0;
172}

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "iLBC 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 179 of file res_format_attr_ilbc.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 179 of file res_format_attr_ilbc.c.

◆ default_ilbc_attr

struct ilbc_attr default_ilbc_attr
static
Initial value:
= {
.mode = 20,
}

Definition at line 43 of file res_format_attr_ilbc.c.

Referenced by ilbc_clone(), ilbc_generate_sdp_fmtp(), and ilbc_getjoint().

◆ ilbc_interface

struct ast_format_interface ilbc_interface
static

Definition at line 150 of file res_format_attr_ilbc.c.

Referenced by load_module().