[svn-commits] dvossel: branch dvossel/fixtheworld_phase2 r307230 - in /team/dvossel/fixthew...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Wed Feb 9 14:02:20 CST 2011
Author: dvossel
Date: Wed Feb 9 14:02:16 2011
New Revision: 307230
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=307230
Log:
Introduction of SILK bitrate and dtx codecs.conf options
Added:
team/dvossel/fixtheworld_phase2/include/asterisk/silk.h (with props)
Modified:
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/frame.h
team/dvossel/fixtheworld_phase2/main/format.c
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=307230&r1=307229&r2=307230
==============================================================================
--- team/dvossel/fixtheworld_phase2/configs/codecs.conf.sample (original)
+++ team/dvossel/fixtheworld_phase2/configs/codecs.conf.sample Wed Feb 9 14:02:16 2011
@@ -79,20 +79,41 @@
; host=dynamic
; disallow=all
; allow=silk8 ;custom codec defined in codecs.conf
+;
+; LIMITATIONS
+; Custom formats can only be defined at startup. Any changes to this
+; file made after startup will not take into effect until after Asterisk
+; is restarted.
+;
-; Custom SILK format definitions
+; Default Custom SILK format definitions, only one custom SILK format per
+; sample rate is allowed.
[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.
[silk12]
type=silk
samprate=12000
+maxbitrate = 12000
[silk16]
type=silk
samprate=16000
+maxbitrate = 20000
[silk24]
type=silk
samprate=24000
+maxbitrate = 30000
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=307230&r1=307229&r2=307230
==============================================================================
--- team/dvossel/fixtheworld_phase2/formats/format_attr_silk.c (original)
+++ team/dvossel/fixtheworld_phase2/formats/format_attr_silk.c Wed Feb 9 14:02:16 2011
@@ -30,8 +30,16 @@
#include "asterisk/module.h"
#include "asterisk/format.h"
+/*!
+ * \brief SILK attribute structure.
+ *
+ * \note The only attribute that affects compatibility here is the sample rate.
+ */
struct silk_attr {
int samplerate;
+ int maxbitrate;
+ int dtx;
+ int noFEC;
};
static enum ast_format_cmp_res silk_cmp(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2)
@@ -46,7 +54,64 @@
return AST_FORMAT_CMP_NOT_EQUAL;
}
return AST_FORMAT_CMP_SUBSET;
+}
+static int silk_get_val(const struct ast_format_attr *fattr, int key, void *result)
+{
+ const struct silk_attr *attr = (struct silk_attr *) fattr;
+
+ switch (key) {
+ int *val;
+ case SILK_ATTR_KEY_SAMP_RATE:
+ val = result;
+ *val = attr->samplerate;
+ break;
+ case SILK_ATTR_KEY_MAX_BITRATE:
+ val = result;
+ *val = attr->maxbitrate;
+ break;
+ case SILK_ATTR_KEY_DTX:
+ val = result;
+ *val = attr->dtx;
+ break;
+ default:
+ return -1;
+ ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
+ }
+ return 0;
+}
+
+static int silk_isset(const struct ast_format_attr *fattr, va_list ap)
+{
+ enum silk_attr_keys key;
+ const struct silk_attr *attr = (struct silk_attr *) fattr;
+
+ for (key = va_arg(ap, int);
+ key != AST_FORMAT_ATTR_END;
+ key = va_arg(ap, int))
+ {
+ switch (key) {
+ case SILK_ATTR_KEY_SAMP_RATE:
+ if (attr->samplerate != (va_arg(ap, int))) {
+ return -1;
+ }
+ break;
+ case SILK_ATTR_KEY_MAX_BITRATE:
+ if (attr->maxbitrate != (va_arg(ap, int))) {
+ return -1;
+ }
+ break;
+ case SILK_ATTR_KEY_DTX:
+ if (attr->dtx != (va_arg(ap, int))) {
+ return -1;
+ }
+ break;
+ default:
+ return -1;
+ ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
+ }
+ }
+ return 0;
}
static int silk_getjoint(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2, struct ast_format_attr *result)
{
@@ -73,7 +138,13 @@
{
switch (key) {
case SILK_ATTR_KEY_SAMP_RATE:
- attr->samplerate = (va_arg(ap, int) | attr->samplerate);
+ attr->samplerate = (va_arg(ap, int));
+ break;
+ case SILK_ATTR_KEY_MAX_BITRATE:
+ attr->maxbitrate = (va_arg(ap, int));
+ break;
+ case SILK_ATTR_KEY_DTX:
+ attr->dtx = (va_arg(ap, int));
break;
default:
ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
@@ -85,7 +156,9 @@
.id = AST_FORMAT_SILK,
.format_attr_cmp = silk_cmp,
.format_attr_get_joint = silk_getjoint,
- .format_attr_set = silk_set
+ .format_attr_set = silk_set,
+ .format_attr_isset = silk_isset,
+ .format_attr_get_val = silk_get_val,
};
static int load_module(void)
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=307230&r1=307229&r2=307230
==============================================================================
--- team/dvossel/fixtheworld_phase2/include/asterisk/format.h (original)
+++ team/dvossel/fixtheworld_phase2/include/asterisk/format.h Wed Feb 9 14:02:16 2011
@@ -27,6 +27,7 @@
#define _AST_FORMAT_H_
#include "asterisk/astobj2.h"
+#include "asterisk/silk.h"
#define AST_FORMAT_ATTR_SIZE 128
#define AST_FORMAT_INC 100000
@@ -125,18 +126,6 @@
#define AST_FORMAT_GET_TYPE(id) (((int) (id / AST_FORMAT_INC)) * AST_FORMAT_INC)
-/*! SILK format attribute key value pairs */
-enum silk_attr_keys {
- SILK_ATTR_KEY_SAMP_RATE,
-};
-
-enum silk_attr_vals {
- SILK_ATTR_VAL_SAMP_8KHZ = (1 << 0),
- SILK_ATTR_VAL_SAMP_12KHZ = (1 << 1),
- SILK_ATTR_VAL_SAMP_16KHZ = (1 << 2),
- SILK_ATTR_VAL_SAMP_24KHZ = (1 << 3),
-};
-
/*! \brief This structure contains the buffer used for format attributes */
struct ast_format_attr {
/*! The buffer formats can use to represent attributes */
@@ -200,6 +189,34 @@
/*! \brief Set format capabilities from a list of key value pairs ending with AST_FORMAT_ATTR_END.
* \note This function does not need to call va_end of the va_list. */
void (* const format_attr_set)(struct ast_format_attr *format_attr, va_list ap);
+
+ /*!
+ * \brief Find out if format capabilities in va_list are in format.
+ * \note This function does not need to call va_end of the va_list.
+ *
+ * \note This function is optional. In many cases the format_attr_cmp
+ * function can be used to derive these results. If it is possible
+ * that some format attributes have no bearing on the equality of two formats, this
+ * function must exist.
+ *
+ * \retval 0 if all attributes exist
+ * \retval -1 if any of the attributes not present
+ */
+ int (* const format_attr_isset)(const struct ast_format_attr *format_attr, va_list ap);
+
+ /*
+ * \brief Return a value for a specific format key. Return that value in the void pointer.
+ *
+ * \note It is not expected that all key value pairs can be returned, but those that can should
+ * be documented as such.
+ *
+ * \note This function is optional if key value pairs are not allowed to be accessed. This
+ * will result in -1 always being returned.
+ *
+ * \retval 0 Success, value was found and copied into void pointer.
+ * \retval -1 failure, Value was either not found, or not allowed to be accessed.
+ */
+ int (* const format_attr_get_val)(const struct ast_format_attr *format_attr, int key, void *val);
};
/*!
@@ -267,6 +284,17 @@
int ast_format_isset(const struct ast_format *format, ... );
/*!
+ * \brief Get a value from a format containing attributes.
+ * \note The key represents the format attribute to be retrieved, and the void pointer
+ * is to the structure that value will be stored in. It must be known what structure a
+ * key represents.
+ *
+ * \retval 0, success
+ * \retval -1, failure
+ */
+int ast_format_get_value(const struct ast_format *format, int key, void *value);
+
+/*!
* \brief Compare ast_formats structures
*
* \retval ast_format_cmp_res representing the result of comparing format1 and format2.
@@ -363,6 +391,11 @@
* \return This returns a static string identifying the format on success, 0 on error.
*/
const char *ast_codec2str(struct ast_format *format);
+
+/*!
+ * \brief Get the sample rate for a given format.
+ */
+int ast_format_rate(const struct ast_format *format);
/*!
* \brief register ast_format_attr_interface with core.
Modified: team/dvossel/fixtheworld_phase2/include/asterisk/frame.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/include/asterisk/frame.h?view=diff&rev=307230&r1=307229&r2=307230
==============================================================================
--- team/dvossel/fixtheworld_phase2/include/asterisk/frame.h (original)
+++ team/dvossel/fixtheworld_phase2/include/asterisk/frame.h Wed Feb 9 14:02:16 2011
@@ -572,59 +572,6 @@
int ast_frame_slinear_sum(struct ast_frame *f1, struct ast_frame *f2);
/*!
- * \brief Get the sample rate for a given format.
- */
-static force_inline int ast_format_rate(const struct ast_format *format)
-{
- switch (format->id) {
- case AST_FORMAT_SLINEAR12:
- return 12000;
- case AST_FORMAT_SLINEAR24:
- return 24000;
- case AST_FORMAT_SLINEAR32:
- return 32000;
- case AST_FORMAT_SLINEAR44:
- return 44100;
- case AST_FORMAT_SLINEAR48:
- return 48000;
- case AST_FORMAT_SLINEAR96:
- return 96000;
- case AST_FORMAT_SLINEAR192:
- return 192000;
- case AST_FORMAT_G722:
- case AST_FORMAT_SLINEAR16:
- case AST_FORMAT_SIREN7:
- case AST_FORMAT_SPEEX16:
- return 16000;
- case AST_FORMAT_SIREN14:
- return 32000;
- case AST_FORMAT_G719:
- return 48000;
- case AST_FORMAT_SILK:
- if (!(ast_format_isset(format,
- SILK_ATTR_KEY_SAMP_RATE,
- SILK_ATTR_VAL_SAMP_24KHZ,
- AST_FORMAT_ATTR_END))) {
- return 24000;
- } else if (!(ast_format_isset(format,
- SILK_ATTR_KEY_SAMP_RATE,
- SILK_ATTR_VAL_SAMP_16KHZ,
- AST_FORMAT_ATTR_END))) {
- return 16000;
- } else if (!(ast_format_isset(format,
- SILK_ATTR_KEY_SAMP_RATE,
- SILK_ATTR_VAL_SAMP_12KHZ,
- AST_FORMAT_ATTR_END))) {
- return 12000;
- } else {
- return 8000;
- }
- default:
- return 8000;
- }
-}
-
-/*!
* \brief Clear all audio samples from an ast_frame. The frame must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR
*/
int ast_frame_clear(struct ast_frame *frame);
Added: team/dvossel/fixtheworld_phase2/include/asterisk/silk.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/include/asterisk/silk.h?view=auto&rev=307230
==============================================================================
--- team/dvossel/fixtheworld_phase2/include/asterisk/silk.h (added)
+++ team/dvossel/fixtheworld_phase2/include/asterisk/silk.h Wed Feb 9 14:02:16 2011
@@ -1,0 +1,42 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2011, Digium, Inc.
+ *
+ * David Vossel <dvossel at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief SILK Format Attributes
+ *
+ * \author David Vossel <dvossel at digium.com>
+ */
+#ifndef _AST_FORMAT_SILK_H_
+#define _AST_FORMAT_SILK_H_
+
+/*! SILK format attribute key value pairs */
+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_MAX_BITRATE, /*!< value is an int */
+};
+
+enum silk_attr_vals {
+ SILK_ATTR_VAL_SAMP_8KHZ = (1 << 0),
+ SILK_ATTR_VAL_SAMP_12KHZ = (1 << 1),
+ SILK_ATTR_VAL_SAMP_16KHZ = (1 << 2),
+ SILK_ATTR_VAL_SAMP_24KHZ = (1 << 3),
+};
+
+#endif /* _AST_FORMAT_SILK_H */
Propchange: team/dvossel/fixtheworld_phase2/include/asterisk/silk.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/dvossel/fixtheworld_phase2/include/asterisk/silk.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/dvossel/fixtheworld_phase2/include/asterisk/silk.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=307230&r1=307229&r2=307230
==============================================================================
--- team/dvossel/fixtheworld_phase2/main/format.c (original)
+++ team/dvossel/fixtheworld_phase2/main/format.c Wed Feb 9 14:02:16 2011
@@ -226,15 +226,21 @@
return -1;
}
- wrapper->interface->format_attr_set(&tmp.fattr, ap);
-
- /* use our tmp structure to tell if the attributes are set or not */
- res = wrapper->interface->format_attr_cmp(&tmp.fattr, &format->fattr);
+ /* if isset is present, use that function, else just build a new
+ * format and use the cmp function */
+ if (wrapper->interface->format_attr_isset) {
+ res = wrapper->interface->format_attr_isset(&format->fattr, ap);
+ } else {
+ wrapper->interface->format_attr_set(&tmp.fattr, ap);
+ /* use our tmp structure to tell if the attributes are set or not */
+ res = wrapper->interface->format_attr_cmp(&tmp.fattr, &format->fattr);
+ res = (res == AST_FORMAT_CMP_NOT_EQUAL) ? -1 : 0;
+ }
ast_rwlock_unlock(&wrapper->wraplock);
ao2_ref(wrapper, -1);
- return (res == AST_FORMAT_CMP_NOT_EQUAL) ? -1 : 0;
+ return res;
}
int ast_format_isset(const struct ast_format *format, ... )
@@ -248,6 +254,29 @@
return res;
}
+int ast_format_get_value(const struct ast_format *format, int key, void *value)
+{
+ int res = 0;
+ struct interface_ao2_wrapper *wrapper;
+ if (!(wrapper = find_interface(format))) {
+ return -1;
+ }
+ ast_rwlock_rdlock(&wrapper->wraplock);
+ if (!wrapper->interface ||
+ !wrapper->interface->format_attr_get_val) {
+
+ ast_rwlock_unlock(&wrapper->wraplock);
+ ao2_ref(wrapper, -1);
+ return -1;
+ }
+
+ res = wrapper->interface->format_attr_get_val(&format->fattr, key, value);
+
+ ast_rwlock_unlock(&wrapper->wraplock);
+ ao2_ref(wrapper, -1);
+
+ return res;
+}
/*! \internal
* \brief cmp format attributes using an interface
@@ -635,6 +664,55 @@
return ret;
}
+int ast_format_rate(const struct ast_format *format)
+{
+ switch (format->id) {
+ case AST_FORMAT_SLINEAR12:
+ return 12000;
+ case AST_FORMAT_SLINEAR24:
+ return 24000;
+ case AST_FORMAT_SLINEAR32:
+ return 32000;
+ case AST_FORMAT_SLINEAR44:
+ return 44100;
+ case AST_FORMAT_SLINEAR48:
+ return 48000;
+ case AST_FORMAT_SLINEAR96:
+ return 96000;
+ case AST_FORMAT_SLINEAR192:
+ return 192000;
+ case AST_FORMAT_G722:
+ case AST_FORMAT_SLINEAR16:
+ case AST_FORMAT_SIREN7:
+ case AST_FORMAT_SPEEX16:
+ return 16000;
+ case AST_FORMAT_SIREN14:
+ return 32000;
+ case AST_FORMAT_G719:
+ return 48000;
+ case AST_FORMAT_SILK:
+ if (!(ast_format_isset(format,
+ SILK_ATTR_KEY_SAMP_RATE,
+ SILK_ATTR_VAL_SAMP_24KHZ,
+ AST_FORMAT_ATTR_END))) {
+ return 24000;
+ } else if (!(ast_format_isset(format,
+ SILK_ATTR_KEY_SAMP_RATE,
+ SILK_ATTR_VAL_SAMP_16KHZ,
+ AST_FORMAT_ATTR_END))) {
+ return 16000;
+ } else if (!(ast_format_isset(format,
+ SILK_ATTR_KEY_SAMP_RATE,
+ SILK_ATTR_VAL_SAMP_12KHZ,
+ AST_FORMAT_ATTR_END))) {
+ return 12000;
+ } else {
+ return 8000;
+ }
+ default:
+ return 8000;
+ }
+}
static char *show_codecs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
@@ -961,7 +1039,7 @@
return -1;
}
-static int custom_silk_format(struct ast_format_list *entry)
+static int custom_silk_format(struct ast_format_list *entry, unsigned int maxbitrate)
{
if (!entry->samplespersecond) {
ast_log(LOG_WARNING, "Custom SILK format definition '%s' requires sample rate to be defined.\n", entry->name);
@@ -997,6 +1075,11 @@
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,
+ SILK_ATTR_KEY_MAX_BITRATE, maxbitrate,
+ AST_FORMAT_ATTR_END);
+ }
ast_copy_string(entry->desc, "SILK Custom Format", sizeof(entry->desc));
entry->fr_len = 80;
entry->min_ms = 20;
@@ -1015,6 +1098,7 @@
char *cat = NULL;
enum ast_format_id id;
int add_it = 0;
+ unsigned int maxbitrate = 0;
if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID)
return 0;
@@ -1028,6 +1112,7 @@
memset(&entry, 0, sizeof(entry));
id = 0;
add_it = 0;
+ maxbitrate = 0;
if (!(ast_variable_retrieve(cfg, cat, "type"))) {
continue;
}
@@ -1059,12 +1144,16 @@
} else {
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);
+ }
}
}
switch (id) {
case AST_FORMAT_SILK:
- if (!(custom_silk_format(&entry))) {
+ if (!(custom_silk_format(&entry, maxbitrate))) {
add_it = 1;
}
break;
More information about the svn-commits
mailing list