| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#include "asterisk.h" |
| 33 |
|
| 34 |
#include <ctype.h> |
| 35 |
|
| 36 |
#include "asterisk/module.h" |
| 37 |
#include "asterisk/format.h" |
| 38 |
#include "asterisk/strings.h" |
| 39 |
#include "asterisk/utils.h" |
| 40 |
|
| 41 |
#include "asterisk/ilbc.h" |
| 42 |
|
| 43 |
static struct ilbc_attr default_ilbc_attr = { |
| 44 |
.mode = 20, |
| 45 |
}; |
| 46 |
|
| 47 |
static void ilbc_destroy(struct ast_format *format) |
| 48 |
{ |
| 49 |
struct ilbc_attr *attr = ast_format_get_attribute_data(format); |
| 50 |
|
| 51 |
ast_free(attr); |
| 52 |
} |
| 53 |
|
| 54 |
static int ilbc_clone(const struct ast_format *src, struct ast_format *dst) |
| 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 |
|
| 69 |
ast_format_set_attribute_data(dst, attr); |
| 70 |
|
| 71 |
return 0; |
| 72 |
} |
| 73 |
|
| 74 |
static struct ast_format *ilbc_parse_sdp_fmtp(const struct ast_format *format, const char *attributes) |
| 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 |
|
| 89 |
for (attrib = attribs; *attrib; ++attrib) { |
| 90 |
*attrib = tolower(*attrib); |
| 91 |
} |
| 92 |
|
| 93 |
if ((kvp = strstr(attribs, "mode")) && sscanf(kvp, "mode=%30u", &val) == 1) { |
| 94 |
attr->mode = val; |
| 95 |
} else { |
| 96 |
attr->mode = 30; |
| 97 |
} |
| 98 |
|
| 99 |
return cloned; |
| 100 |
} |
| 101 |
|
| 102 |
static void ilbc_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str) |
| 103 |
{ |
| 104 |
struct ilbc_attr *attr = ast_format_get_attribute_data(format); |
| 105 |
|
| 106 |
if (!attr) { |
| 107 |
attr = &default_ilbc_attr; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
{ |
| 118 |
ast_str_append(str, 0, "a=fmtp:%u mode=%u\r\n", payload, attr->mode); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
static struct ast_format *ilbc_getjoint(const struct ast_format *format1, const struct ast_format *format2) |
| 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 |
} |
| 149 |
|
| 150 |
static struct ast_format_interface ilbc_interface = { |
| 151 |
.format_destroy = ilbc_destroy, |
| 152 |
.format_clone = ilbc_clone, |
| 153 |
.format_cmp = NULL, |
| 154 |
.format_get_joint = ilbc_getjoint, |
| 155 |
.format_attribute_set = NULL, |
| 156 |
.format_parse_sdp_fmtp = ilbc_parse_sdp_fmtp, |
| 157 |
.format_generate_sdp_fmtp = ilbc_generate_sdp_fmtp, |
| 158 |
}; |
| 159 |
|
| 160 |
static int load_module(void) |
| 161 |
{ |
| 162 |
if (ast_format_interface_register("ilbc", &ilbc_interface)) { |
| 163 |
return AST_MODULE_LOAD_DECLINE; |
| 164 |
} |
| 165 |
|
| 166 |
return AST_MODULE_LOAD_SUCCESS; |
| 167 |
} |
| 168 |
|
| 169 |
static int unload_module(void) |
| 170 |
{ |
| 171 |
return 0; |
| 172 |
} |
| 173 |
|
| 174 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "iLBC Format Attribute Module", |
| 175 |
.support_level = AST_MODULE_SUPPORT_CORE, |
| 176 |
.load = load_module, |
| 177 |
.unload = unload_module, |
| 178 |
.load_pri = AST_MODPRI_CHANNEL_DEPEND, |
| 179 |
); |