[asterisk-commits] dvossel: branch dvossel/celt_codec_ftw r312995 - in /team/dvossel/celt_codec_...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 6 13:57:11 CDT 2011
Author: dvossel
Date: Wed Apr 6 13:57:07 2011
New Revision: 312995
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=312995
Log:
CELT format attribute module and attribute header file
Added:
team/dvossel/celt_codec_ftw/formats/format_attr_celt.c (with props)
team/dvossel/celt_codec_ftw/include/asterisk/celt.h (with props)
Modified:
team/dvossel/celt_codec_ftw/include/asterisk/format.h
Added: team/dvossel/celt_codec_ftw/formats/format_attr_celt.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/celt_codec_ftw/formats/format_attr_celt.c?view=auto&rev=312995
==============================================================================
--- team/dvossel/celt_codec_ftw/formats/format_attr_celt.c (added)
+++ team/dvossel/celt_codec_ftw/formats/format_attr_celt.c Wed Apr 6 13:57:07 2011
@@ -1,0 +1,181 @@
+/*
+ * 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 CELT 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 CELT attribute structure.
+ *
+ * \note The only attribute that affects compatibility here is the sample rate.
+ */
+struct celt_attr {
+ unsigned int samplerate;
+ unsigned int maxbitrate;
+ unsigned int framesize;
+};
+
+static enum ast_format_cmp_res celt_cmp(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2)
+{
+ struct celt_attr *attr1 = (struct celt_attr *) fattr1;
+ struct celt_attr *attr2 = (struct celt_attr *) fattr2;
+
+ if (attr1->samplerate == attr2->samplerate) {
+ return AST_FORMAT_CMP_EQUAL;
+ }
+ return AST_FORMAT_CMP_NOT_EQUAL;
+}
+
+static int celt_get_val(const struct ast_format_attr *fattr, int key, void *result)
+{
+ const struct celt_attr *attr = (struct celt_attr *) fattr;
+ int *val = result;
+
+ switch (key) {
+ case CELT_ATTR_KEY_SAMP_RATE:
+ *val = attr->samplerate;
+ break;
+ case CELT_ATTR_KEY_MAX_BITRATE:
+ *val = attr->maxbitrate;
+ break;
+ case CELT_ATTR_KEY_FRAME_SIZE:
+ *val = attr->framesize;
+ break;
+ default:
+ return -1;
+ ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
+ }
+ return 0;
+}
+
+static int celt_isset(const struct ast_format_attr *fattr, va_list ap)
+{
+ enum celt_attr_keys key;
+ const struct celt_attr *attr = (struct celt_attr *) fattr;
+
+ for (key = va_arg(ap, int);
+ key != AST_FORMAT_ATTR_END;
+ key = va_arg(ap, int))
+ {
+ switch (key) {
+ case CELT_ATTR_KEY_SAMP_RATE:
+ if (attr->samplerate != (va_arg(ap, int))) {
+ return -1;
+ }
+ break;
+ case CELT_ATTR_KEY_MAX_BITRATE:
+ if (attr->maxbitrate != (va_arg(ap, int))) {
+ return -1;
+ }
+ break;
+ case CELT_ATTR_KEY_FRAME_SIZE:
+ if (attr->framesize != (va_arg(ap, int))) {
+ return -1;
+ }
+ break;
+ default:
+ return -1;
+ ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
+ }
+ }
+ return 0;
+}
+static int celt_getjoint(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2, struct ast_format_attr *result)
+{
+ struct celt_attr *attr1 = (struct celt_attr *) fattr1;
+ struct celt_attr *attr2 = (struct celt_attr *) fattr2;
+ struct celt_attr *attr_res = (struct celt_attr *) result;
+
+ /* sample rate is the only attribute that has any bearing on if joint capabilities exist or not */
+ if (attr1->samplerate != attr2->samplerate) {
+ return -1;
+ }
+ /* either would work, they are guaranteed the same at this point. */
+ attr_res->samplerate = attr1->samplerate;
+ /* Take the lowest max bitrate */
+ attr_res->maxbitrate = MIN(attr1->maxbitrate, attr2->maxbitrate);
+
+ attr_res->framesize = attr2->framesize; /* TODO figure out what joint framesize means */
+ return 0;
+}
+
+static void celt_set(struct ast_format_attr *fattr, va_list ap)
+{
+ enum celt_attr_keys key;
+ struct celt_attr *attr = (struct celt_attr *) fattr;
+
+ for (key = va_arg(ap, int);
+ key != AST_FORMAT_ATTR_END;
+ key = va_arg(ap, int))
+ {
+ switch (key) {
+ case CELT_ATTR_KEY_SAMP_RATE:
+ attr->samplerate = (va_arg(ap, int));
+ break;
+ case CELT_ATTR_KEY_MAX_BITRATE:
+ attr->maxbitrate = (va_arg(ap, int));
+ break;
+ case CELT_ATTR_KEY_FRAME_SIZE:
+ attr->framesize = (va_arg(ap, int));
+ break;
+ default:
+ ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
+ }
+ }
+}
+
+static struct ast_format_attr_interface celt_interface = {
+ .id = AST_FORMAT_CELT,
+ .format_attr_cmp = celt_cmp,
+ .format_attr_get_joint = celt_getjoint,
+ .format_attr_set = celt_set,
+ .format_attr_isset = celt_isset,
+ .format_attr_get_val = celt_get_val,
+};
+
+static int load_module(void)
+{
+ if (ast_format_attr_reg_interface(&celt_interface)) {
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+static int unload_module(void)
+{
+ ast_format_attr_unreg_interface(&celt_interface);
+ return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "CELT Format Attribute Module",
+ .load = load_module,
+ .unload = unload_module,
+ .load_pri = AST_MODPRI_CHANNEL_DEPEND,
+);
Propchange: team/dvossel/celt_codec_ftw/formats/format_attr_celt.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/dvossel/celt_codec_ftw/formats/format_attr_celt.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/dvossel/celt_codec_ftw/formats/format_attr_celt.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: team/dvossel/celt_codec_ftw/include/asterisk/celt.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/celt_codec_ftw/include/asterisk/celt.h?view=auto&rev=312995
==============================================================================
--- team/dvossel/celt_codec_ftw/include/asterisk/celt.h (added)
+++ team/dvossel/celt_codec_ftw/include/asterisk/celt.h Wed Apr 6 13:57:07 2011
@@ -1,0 +1,35 @@
+/*
+ * 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 CELT Format Attributes
+ *
+ * \author David Vossel <dvossel at digium.com>
+ */
+#ifndef _AST_FORMAT_CELT_H_
+#define _AST_FORMAT_CELT_H_
+
+/*! CELT format attribute key value pairs, all are accessible through ast_format_get_value()*/
+enum celt_attr_keys {
+ CELT_ATTR_KEY_SAMP_RATE, /*!< value is an unsigned integer representing sample rate */
+ CELT_ATTR_KEY_MAX_BITRATE, /*!< value is an int */
+ CELT_ATTR_KEY_FRAME_SIZE, /*!< value is an int */
+};
+
+#endif /* _AST_FORMAT_CELT_H */
Propchange: team/dvossel/celt_codec_ftw/include/asterisk/celt.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/dvossel/celt_codec_ftw/include/asterisk/celt.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/dvossel/celt_codec_ftw/include/asterisk/celt.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: team/dvossel/celt_codec_ftw/include/asterisk/format.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/celt_codec_ftw/include/asterisk/format.h?view=diff&rev=312995&r1=312994&r2=312995
==============================================================================
--- team/dvossel/celt_codec_ftw/include/asterisk/format.h (original)
+++ team/dvossel/celt_codec_ftw/include/asterisk/format.h Wed Apr 6 13:57:07 2011
@@ -28,6 +28,7 @@
#include "asterisk/astobj2.h"
#include "asterisk/silk.h"
+#include "asterisk/celt.h"
#define AST_FORMAT_ATTR_SIZE 128
#define AST_FORMAT_INC 100000
@@ -99,6 +100,7 @@
/*! Raw 16-bit Signed Linear (192000 Hz) PCM. maybe we're taking this too far. */
AST_FORMAT_SLINEAR192 = 27 + AST_FORMAT_TYPE_AUDIO,
AST_FORMAT_SPEEX32 = 28 + AST_FORMAT_TYPE_AUDIO,
+ AST_FORMAT_CELT = 29 + AST_FORMAT_TYPE_AUDIO,
/*! H.261 Video */
AST_FORMAT_H261 = 1 + AST_FORMAT_TYPE_VIDEO,
More information about the asterisk-commits
mailing list