[asterisk-commits] dvossel: branch dvossel/opus_codec_ftw r329525 - in /team/dvossel/opus_codec_...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jul 25 15:53:24 CDT 2011
Author: dvossel
Date: Mon Jul 25 15:53:20 2011
New Revision: 329525
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=329525
Log:
codec opus format attribute module and header file.
Added:
team/dvossel/opus_codec_ftw/include/asterisk/opus.h (with props)
team/dvossel/opus_codec_ftw/res/res_format_attr_opus.c (with props)
Modified:
team/dvossel/opus_codec_ftw/include/asterisk/format.h
Modified: team/dvossel/opus_codec_ftw/include/asterisk/format.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/opus_codec_ftw/include/asterisk/format.h?view=diff&rev=329525&r1=329524&r2=329525
==============================================================================
--- team/dvossel/opus_codec_ftw/include/asterisk/format.h (original)
+++ team/dvossel/opus_codec_ftw/include/asterisk/format.h Mon Jul 25 15:53:20 2011
@@ -29,6 +29,7 @@
#include "asterisk/astobj2.h"
#include "asterisk/silk.h"
#include "asterisk/celt.h"
+#include "asterisk/opus.h"
#define AST_FORMAT_ATTR_SIZE 128
#define AST_FORMAT_INC 100000
@@ -101,6 +102,7 @@
AST_FORMAT_SLINEAR192 = 27 + AST_FORMAT_TYPE_AUDIO,
AST_FORMAT_SPEEX32 = 28 + AST_FORMAT_TYPE_AUDIO,
AST_FORMAT_CELT = 29 + AST_FORMAT_TYPE_AUDIO,
+ AST_FORMAT_OPUS = 30 + AST_FORMAT_TYPE_AUDIO,
/*! H.261 Video */
AST_FORMAT_H261 = 1 + AST_FORMAT_TYPE_VIDEO,
Added: team/dvossel/opus_codec_ftw/include/asterisk/opus.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/opus_codec_ftw/include/asterisk/opus.h?view=auto&rev=329525
==============================================================================
--- team/dvossel/opus_codec_ftw/include/asterisk/opus.h (added)
+++ team/dvossel/opus_codec_ftw/include/asterisk/opus.h Mon Jul 25 15:53:20 2011
@@ -1,0 +1,45 @@
+/*
+ * 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 OPUS Format Attributes
+ *
+ * \author David Vossel <dvossel at digium.com>
+ */
+#ifndef _AST_FORMAT_OPUS_H_
+#define _AST_FORMAT_OPUS_H_
+
+/*! OPUS format attribute key value pairs, all are accessible through ast_format_get_value()*/
+enum opus_attr_keys {
+ OPUS_ATTR_KEY_SAMP_RATE, /*!< value is opus_attr_vals enum */
+ OPUS_ATTR_KEY_DTX, /*!< value is an int, 1 dtx is enabled, 0 dtx not enabled. */
+ OPUS_ATTR_KEY_FEC, /*!< value is an int, 1 encode with FEC, 0 do not use FEC. */
+ OPUS_ATTR_KEY_CBR, /*!< value is an int, 1 encode with constant bit rate, 0 do not encode with constant bit rate. */
+ OPUS_ATTR_KEY_MAX_BITRATE, /*!< value is an int */
+};
+
+enum opus_attr_vals {
+ OPUS_ATTR_VAL_SAMP_8KHZ = (1 << 0),
+ OPUS_ATTR_VAL_SAMP_12KHZ = (1 << 1),
+ OPUS_ATTR_VAL_SAMP_16KHZ = (1 << 2),
+ OPUS_ATTR_VAL_SAMP_24KHZ = (1 << 3),
+ OPUS_ATTR_VAL_SAMP_48KHZ = (1 << 4),
+};
+
+#endif /* _AST_FORMAT_OPUS_H */
Propchange: team/dvossel/opus_codec_ftw/include/asterisk/opus.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/dvossel/opus_codec_ftw/include/asterisk/opus.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/dvossel/opus_codec_ftw/include/asterisk/opus.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: team/dvossel/opus_codec_ftw/res/res_format_attr_opus.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/opus_codec_ftw/res/res_format_attr_opus.c?view=auto&rev=329525
==============================================================================
--- team/dvossel/opus_codec_ftw/res/res_format_attr_opus.c (added)
+++ team/dvossel/opus_codec_ftw/res/res_format_attr_opus.c Mon Jul 25 15:53:20 2011
@@ -1,0 +1,215 @@
+/*
+ * 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 OPUS format attribute interface
+ *
+ * \author David Vossel <dvossel at digium.com>
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/format.h"
+
+/*!
+ * \brief OPUS attribute structure.
+ *
+ * \note The only attribute that affects compatibility here is the sample rate.
+ */
+struct opus_attr {
+ unsigned int samplerate;
+ unsigned int maxbitrate;
+ unsigned int dtx;
+ unsigned int fec;
+ unsigned int cbr;
+};
+
+static enum ast_format_cmp_res opus_cmp(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2)
+{
+ struct opus_attr *attr1 = (struct opus_attr *) fattr1;
+ struct opus_attr *attr2 = (struct opus_attr *) fattr2;
+
+ if (attr1->samplerate == attr2->samplerate) {
+ return AST_FORMAT_CMP_EQUAL;
+ }
+ return AST_FORMAT_CMP_NOT_EQUAL;
+}
+
+static int opus_get_val(const struct ast_format_attr *fattr, int key, void *result)
+{
+ const struct opus_attr *attr = (struct opus_attr *) fattr;
+ int *val = result;
+
+ switch (key) {
+ case OPUS_ATTR_KEY_SAMP_RATE:
+ *val = attr->samplerate;
+ break;
+ case OPUS_ATTR_KEY_MAX_BITRATE:
+ *val = attr->maxbitrate;
+ break;
+ case OPUS_ATTR_KEY_DTX:
+ *val = attr->dtx;
+ break;
+ case OPUS_ATTR_KEY_FEC:
+ *val = attr->fec;
+ break;
+ case OPUS_ATTR_KEY_CBR:
+ *val = attr->cbr;
+ break;
+ default:
+ return -1;
+ ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
+ }
+ return 0;
+}
+
+static int opus_isset(const struct ast_format_attr *fattr, va_list ap)
+{
+ enum opus_attr_keys key;
+ const struct opus_attr *attr = (struct opus_attr *) fattr;
+
+ for (key = va_arg(ap, int);
+ key != AST_FORMAT_ATTR_END;
+ key = va_arg(ap, int))
+ {
+ switch (key) {
+ case OPUS_ATTR_KEY_SAMP_RATE:
+ if (attr->samplerate != (va_arg(ap, int))) {
+ return -1;
+ }
+ break;
+ case OPUS_ATTR_KEY_MAX_BITRATE:
+ if (attr->maxbitrate != (va_arg(ap, int))) {
+ return -1;
+ }
+ break;
+ case OPUS_ATTR_KEY_DTX:
+ if (attr->dtx != (va_arg(ap, int))) {
+ return -1;
+ }
+ break;
+ case OPUS_ATTR_KEY_FEC:
+ if (attr->fec != (va_arg(ap, int))) {
+ return -1;
+ }
+ break;
+ case OPUS_ATTR_KEY_CBR:
+ if (attr->cbr != (va_arg(ap, int))) {
+ return -1;
+ }
+ break;
+ default:
+ return -1;
+ ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
+ }
+ }
+ return 0;
+}
+static int opus_getjoint(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2, struct ast_format_attr *result)
+{
+ struct opus_attr *attr1 = (struct opus_attr *) fattr1;
+ struct opus_attr *attr2 = (struct opus_attr *) fattr2;
+ struct opus_attr *attr_res = (struct opus_attr *) result;
+ int joint = -1;
+
+ attr_res->samplerate = attr1->samplerate & attr2->samplerate;
+ /* sample rate is the only attribute that has any bearing on if joint capabilities exist or not */
+ if (attr_res->samplerate) {
+ joint = 0;
+ }
+ /* Take the lowest max bitrate */
+ attr_res->maxbitrate = MIN(attr1->maxbitrate, attr2->maxbitrate);
+
+ /* 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;
+
+ /* If CBR is requested, use it */
+ attr_res->cbr = attr1->cbr || attr2->cbr ? 1 : 0;
+
+ return joint;
+}
+
+static void opus_set(struct ast_format_attr *fattr, va_list ap)
+{
+ enum opus_attr_keys key;
+ struct opus_attr *attr = (struct opus_attr *) fattr;
+
+ for (key = va_arg(ap, int);
+ key != AST_FORMAT_ATTR_END;
+ key = va_arg(ap, int))
+ {
+ switch (key) {
+ case OPUS_ATTR_KEY_SAMP_RATE:
+ attr->samplerate = (va_arg(ap, int));
+ break;
+ case OPUS_ATTR_KEY_MAX_BITRATE:
+ attr->maxbitrate = (va_arg(ap, int));
+ break;
+ case OPUS_ATTR_KEY_DTX:
+ attr->dtx = (va_arg(ap, int));
+ break;
+ case OPUS_ATTR_KEY_FEC:
+ attr->fec = (va_arg(ap, int));
+ break;
+ case OPUS_ATTR_KEY_CBR:
+ attr->cbr = (va_arg(ap, int));
+ break;
+ default:
+ ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
+ }
+ }
+}
+
+static struct ast_format_attr_interface opus_interface = {
+ .id = AST_FORMAT_OPUS,
+ .format_attr_cmp = opus_cmp,
+ .format_attr_get_joint = opus_getjoint,
+ .format_attr_set = opus_set,
+ .format_attr_isset = opus_isset,
+ .format_attr_get_val = opus_get_val,
+};
+
+static int load_module(void)
+{
+ if (ast_format_attr_reg_interface(&opus_interface)) {
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+static int unload_module(void)
+{
+ ast_format_attr_unreg_interface(&opus_interface);
+ return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "OPUS Format Attribute Module",
+ .load = load_module,
+ .unload = unload_module,
+ .load_pri = AST_MODPRI_CHANNEL_DEPEND,
+);
Propchange: team/dvossel/opus_codec_ftw/res/res_format_attr_opus.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/dvossel/opus_codec_ftw/res/res_format_attr_opus.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/dvossel/opus_codec_ftw/res/res_format_attr_opus.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list