32 #if defined(ASTERISK_REGISTER_FILE)
33 ASTERISK_REGISTER_FILE()
34 #elif defined(ASTERISK_FILE_VERSION)
35 ASTERISK_FILE_VERSION(__FILE__,
"$Revision: $")
41 #include "asterisk/opus.h"
51 unsigned int maxbitrate;
52 unsigned int maxplayrate;
58 unsigned int spropmaxcapturerate;
59 unsigned int spropstereo;
62 static struct opus_attr default_opus_attr = {
63 .maxplayrate = CODEC_OPUS_DEFAULT_MAX_PLAYBACK_RATE,
64 .spropmaxcapturerate = CODEC_OPUS_DEFAULT_MAX_PLAYBACK_RATE,
65 .maxbitrate = CODEC_OPUS_DEFAULT_BITRATE,
66 .stereo = CODEC_OPUS_DEFAULT_STEREO,
67 .spropstereo = CODEC_OPUS_DEFAULT_STEREO,
68 .cbr = CODEC_OPUS_DEFAULT_CBR,
69 .fec = CODEC_OPUS_DEFAULT_FEC,
70 .dtx = CODEC_OPUS_DEFAULT_DTX,
73 static void opus_destroy(
struct ast_format *format)
92 *attr = default_opus_attr;
100 static struct ast_format *opus_parse_sdp_fmtp(
const struct ast_format *format,
const char *attributes)
113 if ((kvp = strstr(attributes,
"maxplaybackrate")) && sscanf(kvp,
"maxplaybackrate=%30u", &val) == 1) {
114 attr->maxplayrate = val;
116 attr->maxplayrate = 48000;
119 if ((kvp = strstr(attributes,
"sprop-maxcapturerate")) && sscanf(kvp,
"sprop-maxcapturerate=%30u", &val) == 1) {
120 attr->spropmaxcapturerate = val;
122 attr->spropmaxcapturerate = 48000;
125 if ((kvp = strstr(attributes,
"maxaveragebitrate")) && sscanf(kvp,
"maxaveragebitrate=%30u", &val) == 1) {
126 attr->maxbitrate = val;
128 attr->maxbitrate = 510000;
131 if (!strncmp(attributes,
"stereo=1", 8)) {
133 }
else if (strstr(attributes,
" stereo=1")) {
135 }
else if (strstr(attributes,
";stereo=1")) {
141 if (strstr(attributes,
"sprop-stereo=1")) {
142 attr->spropstereo = 1;
144 attr->spropstereo = 0;
147 if (strstr(attributes,
"cbr=1")) {
153 if (strstr(attributes,
"useinbandfec=1")) {
159 if (strstr(attributes,
"usedtx=1")) {
168 static void opus_generate_sdp_fmtp(
const struct ast_format *format,
unsigned int payload,
struct ast_str **str)
179 attr = &default_opus_attr;
182 if (48000 != attr->maxplayrate) {
191 if (48000 != attr->spropmaxcapturerate) {
197 ast_str_append(str, 0,
"sprop-maxcapturerate=%u", attr->spropmaxcapturerate);
200 if (510000 != attr->maxbitrate) {
209 if (0 != attr->stereo) {
218 if (0 != attr->spropstereo) {
227 if (0 != attr->cbr) {
236 if (0 != attr->fec) {
245 if (0 != attr->dtx) {
267 attr1 = &default_opus_attr;
271 attr2 = &default_opus_attr;
280 attr_res->dtx = attr1->dtx || attr2->dtx ? 1 : 0;
284 attr_res->fec = attr1->fec && attr2->fec ? 1 : 0;
286 attr_res->cbr = attr1->cbr || attr2->cbr ? 1 : 0;
287 attr_res->spropstereo = attr1->spropstereo || attr2->spropstereo ? 1 : 0;
291 attr_res->stereo = attr1->stereo && attr2->stereo ? 1 : 0;
293 attr_res->maxbitrate = MIN(attr1->maxbitrate, attr2->maxbitrate);
294 attr_res->spropmaxcapturerate = MIN(attr1->spropmaxcapturerate, attr2->spropmaxcapturerate);
295 attr_res->maxplayrate = MIN(attr1->maxplayrate, attr2->maxplayrate);
306 if (sscanf(value,
"%30u", &val) != 1) {
307 ast_log(LOG_WARNING,
"Unknown value '%s' for attribute type '%s'\n",
318 if (!strcasecmp(name,
"max_bitrate")) {
319 attr->maxbitrate = val;
320 }
else if (!strcasecmp(name,
"max_playrate")) {
321 attr->maxplayrate = val;
322 }
else if (!strcasecmp(name,
"minptime")) {
324 }
else if (!strcasecmp(name,
"stereo")) {
326 }
else if (!strcasecmp(name,
"cbr")) {
328 }
else if (!strcasecmp(name,
"fec")) {
330 }
else if (!strcasecmp(name,
"dtx")) {
332 }
else if (!strcasecmp(name,
"sprop_capture_rate")) {
333 attr->spropmaxcapturerate = val;
334 }
else if (!strcasecmp(name,
"sprop_stereo")) {
335 attr->spropstereo = val;
337 ast_log(LOG_WARNING,
"unknown attribute type %s\n", name);
345 .format_clone = opus_clone,
346 .format_get_joint = opus_getjoint,
347 .format_attribute_set = opus_set,
348 .format_parse_sdp_fmtp = opus_parse_sdp_fmtp,
349 .format_generate_sdp_fmtp = opus_generate_sdp_fmtp,
352 static int load_module(
void)
361 static int unload_module(
void)
366 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER,
"Opus Format Attribute Module",
367 .support_level = AST_MODULE_SUPPORT_CORE,
369 .unload = unload_module,
Asterisk main include file. File version handling, generic pbx functions.
String manipulation functions.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Opus attribute structure.
#define ast_malloc(len)
A wrapper for malloc()
Support for dynamic strings.
Support for logging to various files, console and syslog Configuration in file logger.conf.
Module has failed to load, may be in an inconsistent state.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.