[svn-commits] file: branch group/media_formats r406486 - in /team/group/media_formats: incl...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Jan 25 09:29:11 CST 2014


Author: file
Date: Sat Jan 25 09:29:09 2014
New Revision: 406486

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=406486
Log:
Add the beginnings of the new format capabilities code.

Added:
    team/group/media_formats/include/asterisk/format_cap_ng.h   (with props)
    team/group/media_formats/main/format_cap_ng.c   (with props)

Added: team/group/media_formats/include/asterisk/format_cap_ng.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/format_cap_ng.h?view=auto&rev=406486
==============================================================================
--- team/group/media_formats/include/asterisk/format_cap_ng.h (added)
+++ team/group/media_formats/include/asterisk/format_cap_ng.h Sat Jan 25 09:29:09 2014
@@ -1,0 +1,92 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2014, Digium, Inc.
+ *
+ * Joshua Colp <jcolp 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 Format Capabilities API
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ */
+
+#ifndef _AST_FORMAT_CAP_H_
+#define _AST_FORMAT_CAP_H_
+
+#include "asterisk/codec.h"
+
+/*! Capabilities are represented by an opaque structure statically defined in format_cap.c */
+struct ast_format_cap;
+
+enum ast_format_cap_flags {
+	/*!
+	 * The ast_format_cap will be allocated with no lock.
+	 * Useful if there is a separate lock used to protect the structure
+	 */
+	AST_FORMAT_CAP_FLAG_NOLOCK = (1 << 0),
+};
+
+/*!
+ * \brief Allocate a new ast_format_cap structure
+ *
+ * \param flags Modifiers of struct behavior.
+ *
+ * \retval ast_format_cap object on success.
+ * \retval NULL on failure.
+ */
+struct ast_format_cap *ast_format_cap_alloc(enum ast_format_cap_flags flags);
+
+/*!
+ * \brief Add format capability to capabilities structure.
+ *
+ * \param cap The capabilities structure to add to.
+ * \param format The format to add.
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * \note A reference to the format is taken and used in the capabilities structure.
+ *
+ * \note The order in which add is called determines the format preference order.
+ */
+int ast_format_cap_add(struct ast_format_cap *cap, struct ast_format *format);
+
+/*!
+ * \brief Add all codecs Asterisk knows about for a specific type to
+ * the capabilities structure.
+ *
+ * \param cap The capabilities structure to add to.
+ * \param type The type of formats to add.
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * \note A generic format with no attributes is created using the codec.
+ */
+int ast_format_cap_add_all_by_type(struct ast_format_cap *cap, enum ast_media_type type);
+
+/*!
+ * \brief Append the formats in src to dst
+ *
+ * \param dst The destination capabilities structure
+ * \param src The source capabilities structure
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ */
+int ast_format_cap_append(struct ast_format_cap *dst, const struct ast_format_cap *src);
+
+#endif /* _AST_FORMAT_CAP_H */

Propchange: team/group/media_formats/include/asterisk/format_cap_ng.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/media_formats/include/asterisk/format_cap_ng.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/media_formats/include/asterisk/format_cap_ng.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/group/media_formats/main/format_cap_ng.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/format_cap_ng.c?view=auto&rev=406486
==============================================================================
--- team/group/media_formats/main/format_cap_ng.c (added)
+++ team/group/media_formats/main/format_cap_ng.c Sat Jan 25 09:29:09 2014
@@ -1,0 +1,155 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2014, Digium, Inc.
+ *
+ * Joshua Colp <jcolp 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 Format Capabilities API
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ */
+
+/*** MODULEINFO
+	<support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/logger.h"
+#include "asterisk/format_ng.h"
+#include "asterisk/format_cap_ng.h"
+#include "asterisk/codec.h"
+#include "asterisk/astobj2.h"
+#include "asterisk/strings.h"
+#include "asterisk/vector.h"
+
+/*! \brief Structure used for capability formats, adds framing */
+struct format_cap_framed {
+	/*! \brief A pointer to the format */
+	struct ast_format *format;
+	/*! \brief The format framing size */
+	unsigned int framing;
+};
+
+/*! \brief Format capabilities structure, holds formats + preference order + etc */
+struct ast_format_cap {
+	/*! \brief Vector of formats, indexed using the codec identifier */
+	AST_VECTOR(, struct format_cap_framed *) formats;
+	/*! \brief Vector of formats, added in preference order */
+	AST_VECTOR(, struct format_cap_framed *) preference_order;
+	/*! \brief Global framing size, applies to all formats if no framing present on format */
+	unsigned int framing;
+};
+
+/*! \brief Destructor for format capabilities structure */
+static void format_cap_destroy(void *obj)
+{
+	struct ast_format_cap *cap = obj;
+	int idx;
+
+	for (idx = 0; idx < AST_VECTOR_SIZE(&cap->formats); idx++) {
+		struct format_cap_framed *framed = AST_VECTOR_GET(&cap->formats, idx);
+
+		/* Unlike the preference order it is possible for there to be nothing present,
+		 * which means there are no formats with the codec present in this capabilities
+		 * structure.
+		 */
+		if (!framed) {
+			continue;
+		}
+
+		ao2_ref(framed, -1);
+	}
+
+	for (idx = 0; idx < AST_VECTOR_SIZE(&cap->preference_order); idx++) {
+		struct format_cap_framed *framed = AST_VECTOR_GET(&cap->preference_order, idx);
+
+		/* This will always be non-null, unlike formats */
+		ao2_ref(framed, -1);
+	}
+	AST_VECTOR_FREE(&cap->preference_order);
+}
+
+struct ast_format_cap *ast_format_cap_alloc(enum ast_format_cap_flags flags)
+{
+	struct ast_format_cap *cap;
+
+	cap = ao2_alloc(sizeof(*cap), format_cap_destroy);
+	if (!cap) {
+		return NULL;
+	}
+
+	AST_VECTOR_INIT(&cap->formats, 0);
+
+	/* TODO: Look at common usage of this and determine a good starting point */
+	AST_VECTOR_INIT(&cap->preference_order, 5);
+
+	return cap;
+}
+
+/*! \brief Destructor for format capabilities framed structure */
+static void format_cap_framed_destroy(void *obj)
+{
+	struct format_cap_framed *framed = obj;
+
+	ao2_cleanup(framed->format);
+}
+
+int ast_format_cap_add(struct ast_format_cap *cap, struct ast_format *format)
+{
+	struct format_cap_framed *framed;
+
+	/* If a codec is already present bail out for now */
+	if (AST_VECTOR_GET(&cap->formats, format->codec->id)) {
+		return -1;
+	}
+
+	framed = ao2_alloc_options(sizeof(*framed), format_cap_framed_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
+	if (!framed) {
+		return -1;
+	}
+
+	framed->format = ao2_bump(format);
+
+	ao2_ref(framed, +1);
+	AST_VECTOR_INSERT(&cap->formats, format->codec->id, framed);
+
+	/* This takes the allocation reference */
+	AST_VECTOR_APPEND(&cap->preference_order, framed);
+
+	return 0;
+}
+
+int ast_format_cap_add_all_by_type(struct ast_format_cap *cap, enum ast_media_type type)
+{
+	return -1;
+}
+
+int ast_format_cap_append(struct ast_format_cap *dst, const struct ast_format_cap *src)
+{
+	int idx, res = 0;
+
+	for (idx = 0; (idx < AST_VECTOR_SIZE(&src->preference_order)) && !res; ++idx) {
+		struct format_cap_framed *framed = AST_VECTOR_GET(&src->preference_order, idx);
+
+		res = ast_format_cap_add(dst, framed->format);
+	}
+
+	return res;
+}

Propchange: team/group/media_formats/main/format_cap_ng.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/media_formats/main/format_cap_ng.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/media_formats/main/format_cap_ng.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the svn-commits mailing list