[asterisk-commits] file: branch group/media_formats r406167 - in /team/group/media_formats: incl...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jan 22 08:53:14 CST 2014
Author: file
Date: Wed Jan 22 08:53:07 2014
New Revision: 406167
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=406167
Log:
Start work on the format side of things.
This will eventually be moved to format.c and format.h but
I'm developing it beside the old one for now.
Added:
team/group/media_formats/include/asterisk/format_ng.h (with props)
team/group/media_formats/main/format_ng.c (with props)
Added: team/group/media_formats/include/asterisk/format_ng.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/format_ng.h?view=auto&rev=406167
==============================================================================
--- team/group/media_formats/include/asterisk/format_ng.h (added)
+++ team/group/media_formats/include/asterisk/format_ng.h Wed Jan 22 08:53:07 2014
@@ -1,0 +1,164 @@
+/*
+ * 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 Media Format API
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ */
+
+#ifndef _AST_FORMAT_H_
+#define _AST_FORMAT_H_
+
+struct ast_codec;
+struct ast_format;
+
+/*! \brief Format comparison results */
+enum ast_format_cmp_res {
+ /*! structure 1 is identical to structure 2. */
+ AST_FORMAT_CMP_EQUAL = 0,
+ /*! structure 1 contains elements not in structure 2. */
+ AST_FORMAT_CMP_NOT_EQUAL,
+ /*! structure 1 is a proper subset of the elements in structure 2.*/
+ AST_FORMAT_CMP_SUBSET,
+};
+
+/*! \brief Optional format interface to extend format operations */
+struct ast_format_interface {
+ /*!
+ * \brief Determine if format 1 is a subset of format 2.
+ *
+ * \retval ast_format_cmp_res representing the result of comparing format1 and format2.
+ */
+ enum ast_format_cmp_res (* const format_cmp)(const struct ast_format *format1,
+ const struct ast_format *format2);
+
+ /*!
+ * \brief Get joint attributes of same format type if they exist.
+ *
+ * \retval non-NULL if joint format
+ * \retval NULL if no joint format
+ *
+ * \note The returned format has its reference count incremented and must be released using
+ * ao2_ref or ao2_cleanup.
+ */
+ struct ast_format *(* const format_get_joint)(const struct ast_format *format1,
+ const struct ast_format *format2);
+
+ /*!
+ * \brief Set an attribute on a format
+ */
+ int (* const format_attribute_set)(struct ast_format *format, const char *name, const char *value);
+
+ /*
+ * \brief Parse SDP attribute information, interpret it, and store it in the format structure.
+ *
+ * \retval 0 Success, values were valid
+ * \retval -1 Failure, some values were not acceptable
+ */
+ int (* const format_sdp_parse)(struct ast_format *format, const char *attributes);
+
+ /*!
+ * \brief Generate SDP attribute information from an ast_format_attr structure.
+ *
+ * \note This callback should generate a full fmtp line using the provided payload number.
+ */
+ void (* const format_sdp_generate)(const struct ast_format *format, unsigned int payload,
+ struct ast_str **str);
+};
+
+/*! \brief Definition of a media format */
+struct ast_format {
+ /*! \brief Pointer to the codec in use for this format */
+ struct ast_codec *codec;
+ /*! \brief Attribute specific data, implementation specific */
+ void *attribute_data;
+ /*! \brief Pointer to the optional format interface */
+ struct ast_format_interface *interface;
+};
+
+/*!
+ * \brief Create a new media format
+ *
+ * \param codec The codec to use
+ *
+ * \param non-NULL success
+ * \param NULL failure
+ *
+ * \note The format is returned with reference count incremented. It must be released using
+ * ao2_ref or ao2_cleanup.
+ */
+struct ast_format *ast_format_create(struct ast_codec *codec);
+
+/*!
+ * \brief Compare two formats
+ *
+ * \retval ast_format_cmp_res representing the result of comparing format1 and format2.
+ */
+enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2);
+
+/*1
+ * \brief Get a common joint capability between two formats
+ *
+ * \retval non-NULL if joint capability exists
+ * \retval NULL if no joint capability exists
+ */
+struct ast_format *ast_format_joint(const struct ast_format *format1, const struct ast_format *format2);
+
+/*!
+ * \brief Copy a media format
+ */
+struct ast_format *ast_format_copy(struct ast_format *format);
+
+/*!
+ * \brief Set an attribute on a format to a specific value
+ *
+ * \param format The format to set the attribute on
+ * \param name Attribute name
+ * \param value Attribute value
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ */
+int ast_format_attribute_set(struct ast_format *format, const char *name, const char *value);
+
+/*!
+ * \brief This function is used to have a media format aware module parse and interpret
+ * SDP attribute information. Once interpreted this information is stored on the format
+ * itself using Asterisk format attributes.
+ *
+ * \param format to set
+ * \param attributes string containing the fmtp line from the SDP
+ *
+ * \retval 0 success, attribute values were valid
+ * \retval -1 failure, values were not acceptable
+ */
+int ast_format_sdp_parse(struct ast_format *format, const char *attributes);
+
+/*!
+ * \brief This function is used to produce an fmtp SDP line for an Asterisk format. The
+ * attributes present on the Asterisk format are translated into the SDP equivalent.
+ *
+ * \param format to generate an fmtp line for
+ * \param payload numerical payload for the fmtp line
+ * \param str structure that the fmtp line will be appended to
+ */
+void ast_format_sdp_generate(const struct ast_format *format, unsigned int payload, struct ast_str **str);
+
+#endif /* _AST_FORMAT_H */
Propchange: team/group/media_formats/include/asterisk/format_ng.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/group/media_formats/include/asterisk/format_ng.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/group/media_formats/include/asterisk/format_ng.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: team/group/media_formats/main/format_ng.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/format_ng.c?view=auto&rev=406167
==============================================================================
--- team/group/media_formats/main/format_ng.c (added)
+++ team/group/media_formats/main/format_ng.c Wed Jan 22 08:53:07 2014
@@ -1,0 +1,122 @@
+/*
+ * 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 Media Format 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/codec.h"
+#include "asterisk/format_ng.h"
+#include "asterisk/astobj2.h"
+
+/*! \brief Destructor for media formats */
+static void format_destroy(void *obj)
+{
+ struct ast_format *format = obj;
+
+ ao2_cleanup(format->codec);
+}
+
+struct ast_format *ast_format_create(struct ast_codec *codec)
+{
+ struct ast_format *format;
+
+ format = ao2_alloc(sizeof(*format), format_destroy);
+ if (!format) {
+ return NULL;
+ }
+
+ format->codec = ao2_bump(codec);
+
+ return format;
+}
+
+enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
+{
+ if (format1->codec != format2->codec) {
+ return AST_FORMAT_CMP_NOT_EQUAL;
+ }
+
+ if (format1->interface) {
+ return format1->interface->format_cmp(format1, format2);
+ }
+
+ return AST_FORMAT_CMP_EQUAL;
+}
+
+struct ast_format *ast_format_joint(const struct ast_format *format1, const struct ast_format *format2)
+{
+ if (format1->codec != format2->codec) {
+ return NULL;
+ }
+
+ /* If no attribute data exists these are the same format, and thus we don't need to
+ * create a new one - we can just return one of them with reference count bumped!
+ */
+ if (!format1->attribute_data && !format2->attribute_data) {
+ return ao2_bump((struct ast_format*)format1);
+ }
+
+ /* If there is attribute data on either there has to be an interface */
+ return format1->interface->format_get_joint(format1, format2);
+}
+
+struct ast_format *ast_format_copy(struct ast_format *format)
+{
+ return ao2_bump(format);
+}
+
+int ast_format_attribute_set(struct ast_format *format, const char *name, const char *value)
+{
+ if (!format->interface || !format->interface->format_attribute_set) {
+ return -1;
+ }
+
+ return format->interface->format_attribute_set(format, name, value);
+}
+
+int ast_format_sdp_parse(struct ast_format *format, const char *attributes)
+{
+ if (!format->interface || !format->interface->format_sdp_parse) {
+ return -1;
+ }
+
+ return format->interface->format_sdp_parse(format, attributes);
+}
+
+void ast_format_sdp_generate(const struct ast_format *format, unsigned int payload, struct ast_str **str)
+{
+ if (!format->interface || !format->interface->format_sdp_generate) {
+ return;
+ }
+
+ format->interface->format_sdp_generate(format, payload, str);
+}
+
Propchange: team/group/media_formats/main/format_ng.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/group/media_formats/main/format_ng.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/group/media_formats/main/format_ng.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list