[svn-commits] dvossel: branch dvossel/fixtheworld_phase2 r307672 - in /team/dvossel/fixthew...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Fri Feb 11 11:39:09 CST 2011
Author: dvossel
Date: Fri Feb 11 11:39:01 2011
New Revision: 307672
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=307672
Log:
Allow SILK fec and packetloss percentage attributes to be set and negotiated over sip
Modified:
team/dvossel/fixtheworld_phase2/channels/chan_sip.c
team/dvossel/fixtheworld_phase2/configs/codecs.conf.sample
team/dvossel/fixtheworld_phase2/formats/format_attr_silk.c
team/dvossel/fixtheworld_phase2/include/asterisk/format.h
team/dvossel/fixtheworld_phase2/include/asterisk/format_cap.h
team/dvossel/fixtheworld_phase2/include/asterisk/silk.h
team/dvossel/fixtheworld_phase2/include/asterisk/translate.h
team/dvossel/fixtheworld_phase2/main/channel.c
team/dvossel/fixtheworld_phase2/main/format.c
team/dvossel/fixtheworld_phase2/main/format_pref.c
team/dvossel/fixtheworld_phase2/main/rtp_engine.c
Modified: team/dvossel/fixtheworld_phase2/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/channels/chan_sip.c?view=diff&rev=307672&r1=307671&r2=307672
==============================================================================
--- team/dvossel/fixtheworld_phase2/channels/chan_sip.c (original)
+++ team/dvossel/fixtheworld_phase2/channels/chan_sip.c Fri Feb 11 11:39:01 2011
@@ -8879,7 +8879,6 @@
ast_codec_choose(&p->prefs, p->jointcaps, 1, &tmp_fmt);
- ast_format_cap_remove_all(p->owner->nativeformats);
ast_format_cap_set(p->owner->nativeformats, &tmp_fmt);
ast_format_cap_joint_append(p->caps, vpeercapability, p->owner->nativeformats);
ast_format_cap_joint_append(p->caps, tpeercapability, p->owner->nativeformats);
@@ -9138,6 +9137,9 @@
if (sscanf(fmtp_string, "usedtx=%30u", &val) == 1) {
ast_format_append(format, SILK_ATTR_KEY_DTX, val ? 1 : 0, AST_FORMAT_ATTR_END);
}
+ if (sscanf(fmtp_string, "useinbandfec=%30u", &val) == 1) {
+ ast_format_append(format, SILK_ATTR_KEY_FEC, val ? 1 : 0, AST_FORMAT_ATTR_END);
+ }
break;
}
}
@@ -10508,6 +10510,9 @@
}
if (!ast_format_get_value(format, SILK_ATTR_KEY_DTX, &val)) {
ast_str_append(a_buf, 0, "a=fmtp:%d usedtx=%u\r\n", rtp_code, val ? 1 : 0);
+ }
+ if (!ast_format_get_value(format, SILK_ATTR_KEY_FEC, &val)) {
+ ast_str_append(a_buf, 0, "a=fmtp:%d useinbandfec=%u\r\n", rtp_code, val ? 1 : 0);
}
break;
}
Modified: team/dvossel/fixtheworld_phase2/configs/codecs.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/configs/codecs.conf.sample?view=diff&rev=307672&r1=307671&r2=307672
==============================================================================
--- team/dvossel/fixtheworld_phase2/configs/codecs.conf.sample (original)
+++ team/dvossel/fixtheworld_phase2/configs/codecs.conf.sample Fri Feb 11 11:39:01 2011
@@ -91,29 +91,46 @@
[silk8]
type=silk
samprate=8000
-maxbitrate = 10000 ; Use the table below to make sure a useful bitrate is choosen
- ; for maxbitrate. If not set or value is not within the bounds
- ; of the encoder, a default value is chosen.
- ;
- ; sample rate | bitrate range
- ; 8khz | 5000 - 20000 bps
- ; 12khz | 7000 - 25000 bps
- ; 16khz | 8000 - 30000 bps
- ; 24khz | 20000- 40000 bps
- ;
-;dtx=true ; encode using discontinuous transmission mode or not. default off.
+fec=true ; turn on or off encoding with forward error correction.
+ ; On recommended, off by default.
+packetloss_percentage=10 ; Estimated packet loss percentage in uplink direction. This
+ ; affects how much redundancy is built in when using fec.
+ ; The higher the percentage, the larger amount of bandwidth is
+ ; used. Default is 0%, 10% is recommended when fec is in use.
+
+maxbitrate=10000 ; Use the table below to make sure a useful bitrate is choosen
+ ; for maxbitrate. If not set or value is not within the bounds
+ ; of the encoder, a default value is chosen.
+ ;
+ ; sample rate | bitrate range
+ ; 8khz | 5000 - 20000 bps
+ ; 12khz | 7000 - 25000 bps
+ ; 16khz | 8000 - 30000 bps
+ ; 24khz | 20000- 40000 bps
+ ;
+;dtx=true ; Encode using discontinuous transmission mode or not. Turning this
+ ; on will save bandwidth during periods of silence at the cost of
+ ; increased computational complexity. Off by default.
[silk12]
type=silk
samprate=12000
-maxbitrate = 12000
+maxbitrate=12000
+fec=true
+packetloss_percentage=10;
[silk16]
type=silk
samprate=16000
-maxbitrate = 20000
+maxbitrate=20000
+fec=true
+packetloss_percentage=10;
+
[silk24]
type=silk
samprate=24000
-maxbitrate = 30000
+maxbitrate=30000
+fec=true
+packetloss_percentage=10;
+
Modified: team/dvossel/fixtheworld_phase2/formats/format_attr_silk.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/formats/format_attr_silk.c?view=diff&rev=307672&r1=307671&r2=307672
==============================================================================
--- team/dvossel/fixtheworld_phase2/formats/format_attr_silk.c (original)
+++ team/dvossel/fixtheworld_phase2/formats/format_attr_silk.c Fri Feb 11 11:39:01 2011
@@ -39,7 +39,8 @@
int samplerate;
int maxbitrate;
int dtx;
- int noFEC;
+ int fec;
+ int packetloss_percentage;
};
static enum ast_format_cmp_res silk_cmp(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2)
@@ -50,10 +51,7 @@
if (attr1->samplerate == attr2->samplerate) {
return AST_FORMAT_CMP_EQUAL;
}
- if (attr1->samplerate != (attr1->samplerate & attr2->samplerate)) {
- return AST_FORMAT_CMP_NOT_EQUAL;
- }
- return AST_FORMAT_CMP_SUBSET;
+ return AST_FORMAT_CMP_NOT_EQUAL;
}
static int silk_get_val(const struct ast_format_attr *fattr, int key, void *result)
@@ -73,6 +71,14 @@
case SILK_ATTR_KEY_DTX:
val = result;
*val = attr->dtx;
+ break;
+ case SILK_ATTR_KEY_FEC:
+ val = result;
+ *val = attr->fec;
+ break;
+ case SILK_ATTR_KEY_PACKETLOSS_PERCENTAGE:
+ val = result;
+ *val = attr->packetloss_percentage;
break;
default:
return -1;
@@ -106,6 +112,16 @@
return -1;
}
break;
+ case SILK_ATTR_KEY_FEC:
+ if (attr->fec != (va_arg(ap, int))) {
+ return -1;
+ }
+ break;
+ case SILK_ATTR_KEY_PACKETLOSS_PERCENTAGE:
+ if (attr->packetloss_percentage != (va_arg(ap, int))) {
+ return -1;
+ }
+ break;
default:
return -1;
ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
@@ -125,11 +141,20 @@
if (attr_res->samplerate) {
joint = 0;
}
- /* take the lowest max bitrate */
+ /* Take the lowest max bitrate */
attr_res->maxbitrate = MIN(attr1->maxbitrate, attr2->maxbitrate);
- /* Only do dtx if both sides want it */
+ /* Only do dtx if both sides want it. DTX is a trade off between
+ * computational complexity and bandwidth. */
attr_res->dtx = attr1->dtx && attr2->dtx ? 1 : 0;
+
+ /* Only do FEC if both sides want it. If a peer specifically requests not
+ * to receive with FEC, it may be a waste of bandwidth. */
+ attr_res->fec = attr1->fec && attr2->fec ? 1 : 0;
+
+ /* Use the maximum packetloss percentage between the two attributes. This affects how
+ * much redundancy is used in the FEC. */
+ attr_res->packetloss_percentage = MAX(attr1->packetloss_percentage, attr2->packetloss_percentage);
return joint;
}
@@ -151,6 +176,12 @@
break;
case SILK_ATTR_KEY_DTX:
attr->dtx = (va_arg(ap, int));
+ break;
+ case SILK_ATTR_KEY_FEC:
+ attr->fec = (va_arg(ap, int));
+ break;
+ case SILK_ATTR_KEY_PACKETLOSS_PERCENTAGE:
+ attr->packetloss_percentage = (va_arg(ap, int));
break;
default:
ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
Modified: team/dvossel/fixtheworld_phase2/include/asterisk/format.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/include/asterisk/format.h?view=diff&rev=307672&r1=307671&r2=307672
==============================================================================
--- team/dvossel/fixtheworld_phase2/include/asterisk/format.h (original)
+++ team/dvossel/fixtheworld_phase2/include/asterisk/format.h Fri Feb 11 11:39:01 2011
@@ -360,7 +360,16 @@
*/
enum ast_format_id ast_format_id_from_old_bitfield(uint64_t src);
+/*!
+ * \brief Retrieve the global format list in a read only array.
+ * \note ast_format_list_destroy must be called on every format
+ * list retrieved from this function.
+ */
const struct ast_format_list *ast_format_list_get(size_t *size);
+
+/*!
+ * \brief Destroy an ast_format_list gotten from ast_format_list_get()
+ */
const struct ast_format_list *ast_format_list_destroy(const struct ast_format_list *list);
/*! \brief Get the name of a format
Modified: team/dvossel/fixtheworld_phase2/include/asterisk/format_cap.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/include/asterisk/format_cap.h?view=diff&rev=307672&r1=307671&r2=307672
==============================================================================
--- team/dvossel/fixtheworld_phase2/include/asterisk/format_cap.h (original)
+++ team/dvossel/fixtheworld_phase2/include/asterisk/format_cap.h Fri Feb 11 11:39:01 2011
@@ -155,8 +155,8 @@
void ast_format_cap_set(struct ast_format_cap *cap, struct ast_format *format);
/*!
- * \brief Find if ast_format is within the capabilities of the ast_format_cap object
- * then return the compatibly format from the capabilities structure in the result.
+ * \brief Find if input ast_format is within the capabilities of the ast_format_cap object
+ * then return the compatible format from the capabilities structure in the result.
*
* retval 1 format is compatible with formats held in ast_format_cap object.
* retval 0 format is not compatible with any formats in ast_format_cap object.
Modified: team/dvossel/fixtheworld_phase2/include/asterisk/silk.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/include/asterisk/silk.h?view=diff&rev=307672&r1=307671&r2=307672
==============================================================================
--- team/dvossel/fixtheworld_phase2/include/asterisk/silk.h (original)
+++ team/dvossel/fixtheworld_phase2/include/asterisk/silk.h Fri Feb 11 11:39:01 2011
@@ -25,10 +25,12 @@
#ifndef _AST_FORMAT_SILK_H_
#define _AST_FORMAT_SILK_H_
-/*! SILK format attribute key value pairs */
+/*! SILK format attribute key value pairs, all are accessible through ast_format_get_value()*/
enum silk_attr_keys {
SILK_ATTR_KEY_SAMP_RATE, /*!< value is silk_attr_vals enum */
SILK_ATTR_KEY_DTX, /*!< value is an int, 1 dtx is enabled, 0 dtx not enabled. */
+ SILK_ATTR_KEY_FEC, /*!< value is an int, 1 encode with FEC, 0 do not use FEC. */
+ SILK_ATTR_KEY_PACKETLOSS_PERCENTAGE, /*!< value is an int (0-100), Represents estimated packetloss in uplink direction.*/
SILK_ATTR_KEY_MAX_BITRATE, /*!< value is an int */
};
Modified: team/dvossel/fixtheworld_phase2/include/asterisk/translate.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/include/asterisk/translate.h?view=diff&rev=307672&r1=307671&r2=307672
==============================================================================
--- team/dvossel/fixtheworld_phase2/include/asterisk/translate.h (original)
+++ team/dvossel/fixtheworld_phase2/include/asterisk/translate.h Fri Feb 11 11:39:01 2011
@@ -207,8 +207,8 @@
/*! If a translation path using a format with attributes requires the output
* to be a specific set of attributes, this variable will be set describing those
* attributes to the translator. Otherwise, the translator must choose a set
- * of format attributes that preserves the quality of the audio in the best way
- * possible. */
+ * of format attributes for the destination that preserves the quality of the
+ * audio in the best way possible. */
struct ast_format explicit_dst;
int samples; /*!< samples available in outbuf */
/*! \brief actual space used in outbuf */
Modified: team/dvossel/fixtheworld_phase2/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/main/channel.c?view=diff&rev=307672&r1=307671&r2=307672
==============================================================================
--- team/dvossel/fixtheworld_phase2/main/channel.c (original)
+++ team/dvossel/fixtheworld_phase2/main/channel.c Fri Feb 11 11:39:01 2011
@@ -1030,7 +1030,7 @@
AST_FORMAT_SPEEX32,
AST_FORMAT_SPEEX16,
AST_FORMAT_SPEEX,
- /*! SILK is just had to go somewhere */
+ /*! SILK is pretty awesome. */
AST_FORMAT_SILK,
/*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough
to use it */
Modified: team/dvossel/fixtheworld_phase2/main/format.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/main/format.c?view=diff&rev=307672&r1=307671&r2=307672
==============================================================================
--- team/dvossel/fixtheworld_phase2/main/format.c (original)
+++ team/dvossel/fixtheworld_phase2/main/format.c Fri Feb 11 11:39:01 2011
@@ -439,7 +439,7 @@
case AST_FORMAT_T140:
return (1ULL << 27);
default:
- return 0; /* SILK IS NOT SUPPORTED BY OLD BITFIELD */
+ return 0; /* not supported by old bitfield. */
}
return 0;
@@ -1041,7 +1041,7 @@
return -1;
}
-static int custom_silk_format(struct ast_format_list *entry, unsigned int maxbitrate, int usedtx)
+static int custom_silk_format(struct ast_format_list *entry, unsigned int maxbitrate, int usedtx, int usefec, int packetloss_percentage)
{
if (!entry->samplespersecond) {
ast_log(LOG_WARNING, "Custom SILK format definition '%s' requires sample rate to be defined.\n", entry->name);
@@ -1054,21 +1054,25 @@
switch (entry->samplespersecond) {
case 8000:
+ ast_copy_string(entry->desc, "SILK Custom Format 8khz", sizeof(entry->desc));
ast_format_append(&entry->format,
SILK_ATTR_KEY_SAMP_RATE, SILK_ATTR_VAL_SAMP_8KHZ,
AST_FORMAT_ATTR_END);
break;
case 12000:
+ ast_copy_string(entry->desc, "SILK Custom Format 12khz", sizeof(entry->desc));
ast_format_append(&entry->format,
SILK_ATTR_KEY_SAMP_RATE, SILK_ATTR_VAL_SAMP_12KHZ,
AST_FORMAT_ATTR_END);
break;
case 16000:
+ ast_copy_string(entry->desc, "SILK Custom Format 16khz", sizeof(entry->desc));
ast_format_append(&entry->format,
SILK_ATTR_KEY_SAMP_RATE, SILK_ATTR_VAL_SAMP_16KHZ,
AST_FORMAT_ATTR_END);
break;
case 24000:
+ ast_copy_string(entry->desc, "SILK Custom Format 24khz", sizeof(entry->desc));
ast_format_append(&entry->format,
SILK_ATTR_KEY_SAMP_RATE, SILK_ATTR_VAL_SAMP_24KHZ,
AST_FORMAT_ATTR_END);
@@ -1077,17 +1081,13 @@
ast_log(LOG_WARNING, "Custom SILK format definition '%s' can not support sample rate %d\n", entry->name, entry->samplespersecond);
return -1;
}
- if (maxbitrate) {
- ast_format_append(&entry->format,
+ ast_format_append(&entry->format,
SILK_ATTR_KEY_MAX_BITRATE, maxbitrate,
+ SILK_ATTR_KEY_DTX, usedtx ? 1 : 0,
+ SILK_ATTR_KEY_FEC, usefec ? 1 : 0,
+ SILK_ATTR_KEY_PACKETLOSS_PERCENTAGE, packetloss_percentage,
AST_FORMAT_ATTR_END);
- }
- if (usedtx) {
- ast_format_append(&entry->format,
- SILK_ATTR_KEY_DTX, 1,
- AST_FORMAT_ATTR_END);
- }
- ast_copy_string(entry->desc, "SILK Custom Format", sizeof(entry->desc));
+
entry->fr_len = 80;
entry->min_ms = 20;
entry->max_ms = 20;
@@ -1103,10 +1103,15 @@
struct ast_format_list entry;
struct ast_variable *var;
char *cat = NULL;
- enum ast_format_id id;
int add_it = 0;
- unsigned int maxbitrate = 0;
- int usedtx = 0;
+
+ struct {
+ enum ast_format_id id;
+ unsigned int maxbitrate;
+ unsigned int packetloss_percentage;
+ int usefec;
+ int usedtx;
+ } settings;
if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID)
return 0;
@@ -1118,23 +1123,21 @@
while ((cat = ast_category_browse(cfg, cat))) {
memset(&entry, 0, sizeof(entry));
- id = 0;
+ memset(&settings, 0, sizeof(settings));
add_it = 0;
- maxbitrate = 0;
- usedtx = 0;
+
if (!(ast_variable_retrieve(cfg, cat, "type"))) {
continue;
}
-
ast_copy_string(entry.name, cat, sizeof(entry.name));
-
var = ast_variable_browse(cfg, cat);
for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
if (!strcasecmp(var->name, "type")) {
if (!strcasecmp(var->value, "silk")) {
- id = AST_FORMAT_SILK;
+ settings.id = AST_FORMAT_SILK;
} else {
- ast_log(LOG_WARNING, "Can not make custom format type for '%s' at line %d of %s\n", var->value, var->lineno, FORMAT_CONFIG);
+ ast_log(LOG_WARNING, "Can not make custom format type for '%s' at line %d of %s\n",
+ var->value, var->lineno, FORMAT_CONFIG);
continue;
}
} else if (!strcasecmp(var->name, "samprate")) {
@@ -1151,20 +1154,30 @@
} else if (!strcasecmp(var->value, "48000")) {
entry.samplespersecond = 48000;
} else {
- ast_log(LOG_WARNING, "Sample rate '%s' at line %d of %s is not supported.\n", var->value, var->lineno, FORMAT_CONFIG);
+ ast_log(LOG_WARNING, "Sample rate '%s' at line %d of %s is not supported.\n",
+ var->value, var->lineno, FORMAT_CONFIG);
}
} else if (!strcasecmp(var->name, "maxbitrate")) {
- if (sscanf(var->value, "%30u", &maxbitrate) != 1) {
- ast_log(LOG_WARNING, "maxbitrate '%s' at line %d of %s is not supported.\n", var->value, var->lineno, FORMAT_CONFIG);
+ if (sscanf(var->value, "%30u", &settings.maxbitrate) != 1) {
+ ast_log(LOG_WARNING, "maxbitrate '%s' at line %d of %s is not supported.\n",
+ var->value, var->lineno, FORMAT_CONFIG);
}
} else if (!strcasecmp(var->name, "dtx")) {
- usedtx = ast_true(var->value) ? 1 : 0;
+ settings.usedtx = ast_true(var->value) ? 1 : 0;
+ } else if (!strcasecmp(var->name, "fec")) {
+ settings.usefec = ast_true(var->value) ? 1 : 0;
+ } else if (!strcasecmp(var->name, "packetloss_percentage")) {
+ if ((sscanf(var->value, "%30u", &settings.packetloss_percentage) != 1) ||
+ (settings.packetloss_percentage >= 0) || (settings.packetloss_percentage <= 100)) {
+ ast_log(LOG_WARNING, "packetloss_percentage '%s' at line %d of %s is not supported.\n",
+ var->value, var->lineno, FORMAT_CONFIG);
+ }
}
}
- switch (id) {
+ switch (settings.id) {
case AST_FORMAT_SILK:
- if (!(custom_silk_format(&entry, maxbitrate, usedtx))) {
+ if (!(custom_silk_format(&entry, settings.maxbitrate, settings.usedtx, settings.usefec, settings.packetloss_percentage))) {
add_it = 1;
}
break;
Modified: team/dvossel/fixtheworld_phase2/main/format_pref.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/main/format_pref.c?view=diff&rev=307672&r1=307671&r2=307672
==============================================================================
--- team/dvossel/fixtheworld_phase2/main/format_pref.c (original)
+++ team/dvossel/fixtheworld_phase2/main/format_pref.c Fri Feb 11 11:39:01 2011
@@ -117,17 +117,20 @@
struct ast_codec_pref oldorder;
int x, y = 0;
size_t f_len = 0;
- const const struct ast_format_list *f_list = ast_format_list_get(&f_len);
-
- if (!pref->order[0])
+ const const struct ast_format_list *f_list;
+
+ if (!pref->order[0]) {
return;
-
+ }
+
+ f_list = ast_format_list_get(&f_len);
memcpy(&oldorder, pref, sizeof(oldorder));
memset(pref, 0, sizeof(*pref));
for (x = 0; x < f_len; x++) {
- if (!oldorder.order[x])
- break;
+ if (!oldorder.order[x]) {
+ break;
+ }
if (ast_format_cmp(&f_list[oldorder.order[x]-1].format, format) == AST_FORMAT_CMP_NOT_EQUAL) {
pref->order[y] = oldorder.order[x];
ast_format_copy(&pref->formats[y], &oldorder.formats[x]);
Modified: team/dvossel/fixtheworld_phase2/main/rtp_engine.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/main/rtp_engine.c?view=diff&rev=307672&r1=307671&r2=307672
==============================================================================
--- team/dvossel/fixtheworld_phase2/main/rtp_engine.c (original)
+++ team/dvossel/fixtheworld_phase2/main/rtp_engine.c Fri Feb 11 11:39:01 2011
@@ -88,10 +88,9 @@
char *type;
char *subtype;
unsigned int sample_rate;
-} ast_rtp_mime_types[64];
+} ast_rtp_mime_types[128]; /* This will Likely not need to grow any time soon. */
static ast_rwlock_t mime_types_lock;
static int mime_types_len = 0;
-
/*!
* \brief Mapping between Asterisk codecs and rtp payload types
More information about the svn-commits
mailing list