[svn-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r300163 - in /team/dvossel/f...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jan 3 22:29:38 UTC 2011


Author: dvossel
Date: Mon Jan  3 16:29:34 2011
New Revision: 300163

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=300163
Log:
Combination of phase 1 step 1 and 2

Added:
    team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h   (with props)
    team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h   (with props)
    team/dvossel/fixtheworld_phase1_step3/main/format.c   (with props)
    team/dvossel/fixtheworld_phase1_step3/main/format_cap.c   (with props)
Modified:
    team/dvossel/fixtheworld_phase1_step3/include/asterisk/translate.h
    team/dvossel/fixtheworld_phase1_step3/main/asterisk.c
    team/dvossel/fixtheworld_phase1_step3/main/translate.c

Added: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h?view=auto&rev=300163
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h (added)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h Mon Jan  3 16:29:34 2011
@@ -1,0 +1,257 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2010, 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 Format API
+ *
+ * \author David Vossel <dvossel at digium.com>
+ */
+
+#ifndef _AST_FORMATNEW_H_
+#define _AST_FORMATNEW_H_
+
+#define AST_FORMATNEW_ATTR_SIZE 128
+
+#define AST_FORMATNEW_INC 100000
+
+/*! This is the value that ends a var list of format attribute
+ * key value pairs. */
+#define AST_FORMATNEW_ATTR_END -1
+
+/*! XXX TODO note, the FORMATNEW tag used in all of the following
+ * enums and defines is temporary and will be replaced by FORMAT once the
+ * conversion from format_t to ast_format takes place. */
+
+/* \brief Format Categories*/
+enum ast_format_type {
+	AST_FORMATNEW_TYPE_AUDIO = 1 * AST_FORMATNEW_INC,
+	AST_FORMATNEW_TYPE_VIDEO = 2 * AST_FORMATNEW_INC,
+	AST_FORMATNEW_TYPE_IMAGE = 3 * AST_FORMATNEW_INC,
+	AST_FORMATNEW_TYPE_TEXT  = 4 * AST_FORMATNEW_INC,
+};
+
+enum ast_format_id {
+	/*! G.723.1 compression */
+	AST_FORMATNEW_G723_1			= 1 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! GSM compression */
+	AST_FORMATNEW_GSM				= 2 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! Raw mu-law data (G.711) */
+	AST_FORMATNEW_ULAW				= 3 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! Raw A-law data (G.711) */
+	AST_FORMATNEW_ALAW				= 4 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! ADPCM (G.726, 32kbps, AAL2 codeword packing) */
+	AST_FORMATNEW_G726_AAL2			= 5 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! ADPCM (IMA) */
+	AST_FORMATNEW_ADPCM				= 6 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! Raw 16-bit Signed Linear (8000 Hz) PCM */
+	AST_FORMATNEW_SLINEAR			= 7 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! LPC10, 180 samples/frame */
+	AST_FORMATNEW_LPC10				= 8 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! G.729A audio */
+	AST_FORMATNEW_G729A				= 9 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! SpeeX Free Compression */
+	AST_FORMATNEW_SPEEX				= 10 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! iLBC Free Compression */
+	AST_FORMATNEW_ILBC				= 11 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
+	AST_FORMATNEW_G726				= 12 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! G.722 */
+	AST_FORMATNEW_G722				= 13 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! G.722.1 (also known as Siren7, 32kbps assumed) */
+	AST_FORMATNEW_SIREN7			= 14 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! G.722.1 Annex C (also known as Siren14, 48kbps assumed) */
+	AST_FORMATNEW_SIREN14			= 15 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! Raw 16-bit Signed Linear (16000 Hz) PCM */
+	AST_FORMATNEW_SLINEAR16			= 16 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! G.719 (64 kbps assumed) */
+	AST_FORMATNEW_G719				= 17 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! SpeeX Wideband (16kHz) Free Compression */
+	AST_FORMATNEW_SPEEX16			= 18 + AST_FORMATNEW_TYPE_AUDIO,
+	/*! Raw mu-law data (G.711) */
+	AST_FORMATNEW_TESTLAW			= 19 + AST_FORMATNEW_TYPE_AUDIO,
+
+	/*! H.261 Video */
+	AST_FORMATNEW_H261				= 1 + AST_FORMATNEW_TYPE_VIDEO,
+	/*! H.263 Video */
+	AST_FORMATNEW_H263				= 2 + AST_FORMATNEW_TYPE_VIDEO,
+	/*! H.263+ Video */
+	AST_FORMATNEW_H263_PLUS			= 3 + AST_FORMATNEW_TYPE_VIDEO,
+	/*! H.264 Video */
+	AST_FORMATNEW_H264				= 4 + AST_FORMATNEW_TYPE_VIDEO,
+	/*! MPEG4 Video */
+	AST_FORMATNEW_MP4_VIDEO			= 5 + AST_FORMATNEW_TYPE_VIDEO,
+
+	/*! JPEG Images */
+	AST_FORMATNEW_JPEG				= 1 + AST_FORMATNEW_TYPE_IMAGE,
+	/*! PNG Images */
+	AST_FORMATNEW_PNG				= 2 + AST_FORMATNEW_TYPE_IMAGE,
+
+	/*! T.140 RED Text format RFC 4103 */
+	AST_FORMATNEW_T140RED			= 1 + AST_FORMATNEW_TYPE_TEXT,
+	/*! T.140 Text format - ITU T.140, RFC 4103 */
+	AST_FORMATNEW_T140				= 2 + AST_FORMATNEW_TYPE_TEXT,
+};
+
+/*! Determine what type of media a ast_format_id is. */
+#define AST_FORMATNEW_GET_TYPE(id) (((enum ast_format_id) (id / AST_FORMATNEW_INC)) * AST_FORMATNEW_INC)
+
+/*! \brief This structure contains the buffer used for format attributes */
+struct ast_format_attr {
+	uint8_t format_attr[AST_FORMATNEW_ATTR_SIZE];
+};
+
+/*! \brief Represents a media format within Asterisk. */
+struct ast_format {
+	/*! The unique id representing this format from all the other formats. */
+	enum ast_format_id id;
+	/*!  Attribute structure used to associate attributes with a format. */
+	struct ast_format_attr fattr;
+};
+
+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 A format must register an attribute interface if it requires the use of the format attributes void pointer */
+struct ast_format_attr_interface {
+	/*! format type */
+	enum ast_format_id id;
+
+	/*! \brief Determine if format_attr 1 is a subset of format_attr 2.
+	 *
+	 * \retval ast_format_cmp_res representing the result of comparing fattr1 and fattr2.
+	 */
+	enum ast_format_cmp_res (* const format_attr_cmp)(struct ast_format_attr *fattr1, struct ast_format_attr *fattr2);
+
+	/*! \brief Get joint attributes of same format type if they exist.
+	 *
+	 * \retval 0 if joint attributes exist
+	 * \retval -1 if no joint attributes are present
+	 */
+	int (* const format_attr_get_joint)(struct ast_format_attr *fattr1, struct ast_format_attr *fattr2, struct ast_format_attr *result);
+
+	/*! \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 This function is used to set an ast_format object to represent a media format
+ * with optional format attributes represented by format specific key value pairs.
+ *
+ * \param format to set
+ * \param id, format id to set on format
+ * \param set_attributes, are there attributes to set on this format. 0 == false, 1 == True.
+ * \param var list of attribute key value pairs, must end with AST_FORMATNEW_ATTR_END;
+ *
+ * \details Example usage.
+ * ast_format_set(format, AST_FORMATNEW_ULAW, 0); // no capability attributes are needed for ULAW
+ *
+ * ast_format_set(format, AST_FORMATNEW_SILK, 1, // SILK has capability attributes.
+ *	  AST_FORMATNEW_SILK_ATTR_RATE, 24000,
+ *	  AST_FORMATNEW_SILK_ATTR_RATE, 16000,
+ *	  AST_FORMATNEW_SILK_ATTR_RATE, 12000,
+ *	  AST_FORMATNEW_SILK_ATTR_RATE, 8000,
+ *	  AST_FORMATNEW_ATTR_END);
+ *
+ * \return Pointer to ast_format object, same pointer that is passed in
+ * by the first argument.
+ */
+struct ast_format *ast_format_set(struct ast_format *format, enum ast_format_id id, int set_attributes, ... );
+
+/*!
+ * \brief This function is used to set an ast_format object to represent a media format
+ * with optional capability attributes represented by format specific key value pairs.
+ *
+ * \details Example usage. Is this SILK format capable of 8khz
+ * is_8khz = ast_format_isset(format, AST_FORMATNEW_SILK_CAP_RATE, 8000);
+ *
+ * \return 0, The format key value pairs are within the capabilities defined in this structure.
+ * \return -1, The format key value pairs are _NOT_ within the capabilities of this structure.
+ */
+int ast_format_isset(struct ast_format *format, ... );
+
+/*!
+ * \brief Compare ast_formats structures
+ *
+ * \retval ast_format_cmp_res representing the result of comparing format1 and format2.
+ */
+enum ast_format_cmp_res ast_format_cmp(struct ast_format *format1, struct ast_format *format2);
+
+/*!
+ * \brief Find joint format attributes of two ast_format
+ * structures containing the same uid and return the intersection in the
+ * result structure.
+ *
+ * retval 0, joint attribute capabilities exist.
+ * retval -1, no joint attribute capabilities exist.
+ */
+int ast_format_joint(struct ast_format *format1, struct ast_format *format2, struct ast_format *result);
+
+/*!
+ * \brief copy format src into format dst.
+ */
+void ast_format_copy(struct ast_format *src, struct ast_format *dst);
+
+/*!
+ * \brief ast_format to iax2 bitfield format represenatation
+ *
+ * \note This is only to be used for IAX2 compatibility 
+ *
+ * \retval iax2 representation of ast_format
+ * \retval 0, if no representation existis for iax2
+ */
+uint64_t ast_format_to_iax2(struct ast_format *format);
+
+/*!
+ * \brief convert iax2 bitfield format to ast_format represenatation
+ * \note This is only to be used for IAX2 compatibility 
+ *
+ * \retval on success, pointer to the dst format in the input parameters
+ * \retval on failure, NULL
+ */
+struct ast_format *ast_format_from_iax2(uint64_t src, struct ast_format *dst);
+
+/*!
+ * \brief register ast_format_attr_interface with core.
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ */
+int ast_format_attr_reg_interface(struct ast_format_attr_interface *interface);
+
+/*!
+ * \brief unregister format_attr interface with core.
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ */
+int ast_format_attr_unreg_interface(struct ast_format_attr_interface *interface);
+
+/*!
+ * \brief Init the ast_format attribute interface register container.
+ */
+int ast_format_attr_init(void);
+
+#endif /* _AST_FORMATNEW_H */

Propchange: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h?view=auto&rev=300163
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h (added)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h Mon Jan  3 16:29:34 2011
@@ -1,0 +1,152 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2010, 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 Format Capability API
+ *
+ * \author David Vossel <dvossel at digium.com>
+ */
+
+#ifndef _AST_FORMATCAP_H_
+#define _AST_FORMATCAP_H_
+
+/*! Capabilities are represented by an opaque structure statically defined in format_capability.c */
+struct ast_cap;
+
+/*!
+ * \brief Allocate a new ast_cap structure.
+ *
+ * \retval ast_cap object on success.
+ * \retval NULL on failure.
+ */
+struct ast_cap *ast_cap_alloc(void);
+
+/*!
+ * \brief Destroy an ast_cap structure.
+ *
+ * \return NULL
+ */
+void *ast_cap_destroy(struct ast_cap *cap);
+
+/*!
+ * \brief Add format capability to capabilities structure.
+ *
+ * \note A copy of the input format is made and that copy is
+ * what is placed in the ast_cap structure.  The actual
+ * input format ptr is not stored.
+ */
+void ast_cap_add(struct ast_cap *cap, struct ast_format *format);
+
+/*!
+ * \brief Remove format capability from capability structure.
+ *
+ * \Note format must match Exactly to format in ast_cap object in order
+ * to be removed.
+ *
+ * \retval 0, remove was successful
+ * \retval -1, remove failed. Could not find format to remove
+ */
+int ast_cap_remove(struct ast_cap *cap, struct ast_format *format);
+
+/*!
+ * \brief Remove all format capabilities from capability
+ * structure for a specific format id.
+ *
+ * \Note This will remove _ALL_ formats matching the format id from the
+ * capabilities structure.
+ *
+ * \retval 0, remove was successful
+ * \retval -1, remove failed. Could not find formats to remove
+ */
+int ast_cap_remove_byid(struct ast_cap *cap, enum ast_format_id id);
+
+/*!
+ * \brief Find if ast_format is within the capabilities of the ast_cap object.
+ *
+ * retval 1 format is compatible with formats held in ast_cap object.
+ * retval 0 format is not compatible with any formats in ast_cap object.
+ */
+int ast_cap_iscompatible(struct ast_cap *cap, struct ast_format *format);
+
+/*!
+ * \brief Get joint capability structure.
+ *
+ * \retval !NULL success
+ * \retval NULL failure
+ */
+struct ast_cap *ast_cap_joint(struct ast_cap *cap1, struct ast_cap *cap2);
+
+/*!
+ * \brief Get all capabilities for a specific media type
+ *
+ * \retval !NULL success
+ * \retval NULL failure
+ */
+struct ast_cap *ast_cap_get_type(struct ast_cap *cap, enum ast_format_type ftype);
+
+
+/*! \brief Start iterating formats */
+void ast_cap_iter_start(struct ast_cap *cap);
+
+/*!
+ * \brief Next format in interation
+ *
+ * \details
+ * Here is how to use the ast_cap iterator.
+ *
+ * 1. call ast_cap_iter_start
+ * 2. call ast_cap_iter_next in a loop until it returns -1
+ * 3. call ast_cap_iter_end to terminate the iterator.
+ *
+ * example:
+ *
+ * ast_cap_iter_start(cap);
+ * while (!ast_cap_iter_next(cap, &format)) {
+ *
+ * }
+ * ast_cap_iter_end(Cap);
+ *
+ * \retval 0 on success, new format is copied into input format struct
+ * \retval -1, no more formats are present.
+ */
+int ast_cap_iter_next(struct ast_cap *cap, struct ast_format *format);
+
+/*!
+ * \brief Ends ast_cap iteration.
+ * \note this must be call after every ast_cap_iter_start
+ */
+void ast_cap_iter_end(struct ast_cap *cap);
+
+/*!
+ * \brief ast_cap to iax2 bitfield format represenatation
+ *
+ * \note This is only to be used for IAX2 compatibility 
+ *
+ * \retval iax2 representation of ast_cap
+ * \retval 0, if no iax2 capabilities are present in ast_cap
+ */
+uint64_t ast_cap_to_iax2(struct ast_cap *cap);
+
+/*!
+ * \brief convert iax2 bitfield format to ast_cap represenatation
+ * \note This is only to be used for IAX2 compatibility 
+ */
+void ast_cap_from_iax2(uint64_t src, struct ast_cap *dst);
+
+#endif /* _AST_FORMATCAP_H */

Propchange: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/translate.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/translate.h?view=diff&rev=300163&r1=300162&r2=300163
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/translate.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/translate.h Mon Jan  3 16:29:34 2011
@@ -40,6 +40,74 @@
 
 struct ast_trans_pvt;	/* declared below */
 
+/*!
+ * \brief Translator Cost Table definition.
+ *
+ * \note The defined values in this table must be used to set
+ * the translator's table_cost value.
+ *
+ * \note The cost value of the first two values must always add
+ * up to be greater than the largest value defined in this table.
+ * This is done to guarantee a direct translation will always
+ * have precedence over a multi step translation.
+ *
+ * \details This table is built in a way that allows translation
+ * paths to be built that guarantee the best possible balance
+ * between performance and quality.  With this table direct
+ * translation paths between two formats always takes precedence
+ * over multi step paths, lossless intermediate steps are always
+ * chosen over lossy intermediate steps, and preservation of
+ * sample rate across the translation will always have precedence
+ * over a path that involves any re-sampling.
+ */
+enum ast_trans_cost_table {
+
+	/* Lossless Source Translation Costs */
+
+	/*! [lossless -> lossless] original sampling */
+	AST_TRANS_COST_LL_LL_ORIGSAMP = 400000,
+	/*! [lossless -> lossy]    original sampling */
+	AST_TRANS_COST_LL_LY_ORIGSAMP = 600000,
+
+	/*! [lossless -> lossless] up sample */
+	AST_TRANS_COST_LL_LL_UPSAMP   = 800000,
+	/*! [lossless -> lossy]    up sample */
+	AST_TRANS_COST_LL_LY_UPSAMP   = 825000,
+
+	/*! [lossless -> lossless] down sample */
+	AST_TRANS_COST_LL_LL_DOWNSAMP = 850000,
+	/*! [lossless -> lossy]    down sample */
+	AST_TRANS_COST_LL_LY_DOWNSAMP = 875000,
+
+	/*! [lossless -> unknown]    unknown.
+	 * This value is for a lossless source translation
+	 * with an unknown destination and or sample rate conversion. */
+	AST_TRANS_COST_LL_UNKNOWN     = 885000,
+
+	/* Lossy Source Translation Costs */
+
+	/*! [lossy -> lossless]    original sampling */
+	AST_TRANS_COST_LY_LL_ORIGSAMP = 900000,
+	/*! [lossy -> lossy]       original sampling */
+	AST_TRANS_COST_LY_LY_ORIGSAMP = 915000,
+
+	/*! [lossy -> lossless]    up sample */
+	AST_TRANS_COST_LY_LL_UPSAMP   = 930000,
+	/*! [lossy -> lossy]       up sample */
+	AST_TRANS_COST_LY_LY_UPSAMP   = 945000,
+
+	/*! [lossy -> lossless]    down sample */
+	AST_TRANS_COST_LY_LL_DOWNSAMP = 960000,
+	/*! [lossy -> lossy]       down sample */
+	AST_TRANS_COST_LY_LY_DOWNSAMP = 975000,
+
+	/*! [lossy -> unknown]    unknown.
+	 * This value is for a lossy source translation
+	 * with an unknown destination and or sample rate conversion. */
+	AST_TRANS_COST_LY_UNKNOWN     = 985000,
+
+};
+
 /*! \brief
  * Descriptor of a translator. 
  *
@@ -74,6 +142,11 @@
 	                                        *   converted to index during registration) */
 	format_t dstfmt;                       /*!< Destination format (note: bit position,
 	                                        *   converted to index during registration) */
+	int table_cost;                        /*!< Cost value associated with this translator based
+	                                        *   on translation cost table. */
+	int comp_cost;                         /*!< Cost value associated with this translator based
+	                                        *   on computation time. This cost value is computed based
+											*   on the time required to translate sample data. */
 
 	int (*newpvt)(struct ast_trans_pvt *); /*!< initialize private data 
                                             *   associated with the translator */
@@ -109,7 +182,6 @@
 
 	struct ast_module *module;             /*!< opaque reference to the parent module */
 
-	int cost;                              /*!< Cost in milliseconds for encoding/decoding 1 second of sound */
 	int active;                            /*!< Whether this translator should be used or not */
 	AST_LIST_ENTRY(ast_translator) list;   /*!< link field */
 };
@@ -262,6 +334,13 @@
  */
 const char *ast_translate_path_to_str(struct ast_trans_pvt *t, struct ast_str **str);
 
+/*!
+ * \brief Initialize the translation matrix and index to format conversion table.
+ * \retval 0 on success
+ * \retval -1 on failure
+ */
+int ast_translate_init(void);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/dvossel/fixtheworld_phase1_step3/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/asterisk.c?view=diff&rev=300163&r1=300162&r2=300163
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/asterisk.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/asterisk.c Mon Jan  3 16:29:34 2011
@@ -111,6 +111,7 @@
 #include "asterisk/network.h"
 #include "asterisk/cli.h"
 #include "asterisk/channel.h"
+#include "asterisk/translate.h"
 #include "asterisk/features.h"
 #include "asterisk/ulaw.h"
 #include "asterisk/alaw.h"
@@ -142,6 +143,7 @@
 #include "asterisk/poll-compat.h"
 #include "asterisk/ccss.h"
 #include "asterisk/test.h"
+#include "asterisk/format.h"
 #include "asterisk/aoc.h"
 
 #include "../defaults.h"
@@ -3669,6 +3671,11 @@
 	}
 #endif
 
+	if (ast_translate_init()) {
+		printf("%s", term_quit());
+		exit(1);
+	}
+
 	ast_aoc_cli_init();
 
 	ast_makesocket();
@@ -3700,6 +3707,8 @@
 
 	astobj2_init();
 
+	ast_format_attr_init();
+
 	ast_autoservice_init();
 
 	if (ast_timing_init()) {

Added: team/dvossel/fixtheworld_phase1_step3/main/format.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/format.c?view=auto&rev=300163
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/format.c (added)
+++ team/dvossel/fixtheworld_phase1_step3/main/format.c Mon Jan  3 16:29:34 2011
@@ -1,0 +1,524 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2010, 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 Format API
+ *
+ * \author David Vossel <dvossel at digium.com>
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$");
+
+#include "asterisk/_private.h"
+#include "asterisk/version.h"
+#include "asterisk/format.h"
+#include "asterisk/astobj2.h"
+#include "asterisk/lock.h"
+
+/*! This is the container for all the format attribute interfaces.
+ *  An ao2 container was chosen for fast lookup. */
+static struct ao2_container *interfaces;
+
+/*! This is the lock used to protect the interfaces container.  Yes, ao2_containers
+ * do have their own locking, but we need the capability of performing read/write
+ * locks on this specific container. */
+static ast_rwlock_t ilock;
+
+/*! a wrapper is used put interfaces into the ao2 container. */
+struct interface_ao2_wrapper {
+	enum ast_format_id id;
+	struct ast_format_attr_interface *interface;
+	/*! a read write lock must be used to protect the wrapper instead
+	 * of the ao2 lock. */
+	ast_rwlock_t wraplock;
+};
+
+static int interface_cmp_cb(void *obj, void *arg, int flags)
+{
+	struct interface_ao2_wrapper *wrapper1 = obj;
+	struct interface_ao2_wrapper *wrapper2 = arg;
+
+	return (wrapper2->id == wrapper1->id) ? CMP_MATCH | CMP_STOP : 0;
+}
+
+static int interface_hash_cb(const void *obj, const int flags)
+{
+	const struct interface_ao2_wrapper *wrapper = obj;
+	return wrapper->id;
+}
+
+static void interface_destroy_cb(void *obj)
+{
+	struct interface_ao2_wrapper *wrapper = obj;
+	ast_rwlock_destroy(&wrapper->wraplock);
+}
+
+void ast_format_copy(struct ast_format *src, struct ast_format *dst)
+{
+	memcpy(dst, src, sizeof(struct ast_format));
+}
+
+/*! \internal
+ * \brief set format attributes using an interface
+ */
+static int format_set_helper(struct ast_format *format, va_list ap)
+{
+	struct interface_ao2_wrapper *wrapper;
+	struct interface_ao2_wrapper tmp_wrapper = {
+		.id = format->id,
+	};
+
+	ast_rwlock_rdlock(&ilock);
+	if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
+		ast_log(LOG_WARNING, "Could not find format interface to set\n");
+		ast_rwlock_unlock(&ilock);
+		return -1;
+	}
+	ast_rwlock_unlock(&ilock);
+
+	ast_rwlock_rdlock(&wrapper->wraplock);
+	if (!wrapper->interface || !wrapper->interface->format_attr_set) {
+		ast_rwlock_unlock(&wrapper->wraplock);
+		ao2_ref(wrapper, -1);
+		return -1;
+	}
+
+	wrapper->interface->format_attr_set(&format->fattr, ap);
+
+	ast_rwlock_unlock(&wrapper->wraplock);
+	ao2_ref(wrapper, -1);
+
+	return 0;
+}
+
+struct ast_format *ast_format_set(struct ast_format *format, enum ast_format_id id, int set_attributes, ... )
+{
+	if (format->id != id) {
+		memset(&format->fattr, 0, sizeof(format->fattr));
+	}
+	format->id = id;
+
+	if (set_attributes) {
+		va_list ap;
+		va_start(ap, set_attributes);
+		format_set_helper(format, ap);
+		va_end(ap);
+	}
+
+	return format;
+}
+
+/*! \internal
+ * \brief determine if a list of attribute key value pairs are set on a format
+ */
+static int format_isset_helper(struct ast_format *format, va_list ap)
+{
+	int res;
+	struct interface_ao2_wrapper *wrapper;
+	struct interface_ao2_wrapper tmp_wrapper = {
+		.id = format->id,
+	};
+	struct ast_format tmp = {
+		.id = format->id,
+		.fattr = { { 0, }, },
+	};
+
+	ast_rwlock_rdlock(&ilock);
+	if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
+		ast_rwlock_unlock(&ilock);
+		return -1;
+	}
+	ast_rwlock_unlock(&ilock);
+
+	ast_rwlock_rdlock(&wrapper->wraplock);
+	if (!wrapper->interface ||
+		!wrapper->interface->format_attr_set ||
+		!wrapper->interface->format_attr_cmp) {
+
+		ast_rwlock_unlock(&wrapper->wraplock);
+		ao2_ref(wrapper, -1);
+		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);
+
+	ast_rwlock_unlock(&wrapper->wraplock);
+	ao2_ref(wrapper, -1);
+
+	return (res == AST_FORMAT_CMP_NOT_EQUAL) ? -1 : 0;
+}
+
+int ast_format_isset(struct ast_format *format, ... )
+{
+	va_list ap;
+	int res;
+
+	va_start(ap, format);
+	res = format_isset_helper(format, ap);
+	va_end(ap);
+	return res;
+}
+
+
+/*! \internal
+ * \brief cmp format attributes using an interface
+ */
+static enum ast_format_cmp_res format_cmp_helper(struct ast_format *format1, struct ast_format *format2)
+{
+	enum ast_format_cmp_res res = AST_FORMAT_CMP_EQUAL;
+	struct interface_ao2_wrapper *wrapper;
+	struct interface_ao2_wrapper tmp_wrapper = {
+		.id = format1->id,
+	};
+
+	ast_rwlock_rdlock(&ilock);
+	if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
+		ast_rwlock_unlock(&ilock);
+		return res;
+	}
+	ast_rwlock_unlock(&ilock);
+
+	ast_rwlock_rdlock(&wrapper->wraplock);
+	if (!wrapper->interface || !wrapper->interface->format_attr_cmp) {
+		ast_rwlock_unlock(&wrapper->wraplock);
+		ao2_ref(wrapper, -1);
+		return res;
+	}
+
+	res = wrapper->interface->format_attr_cmp(&format1->fattr, &format2->fattr);
+
+	ast_rwlock_unlock(&wrapper->wraplock);
+	ao2_ref(wrapper, -1);
+
+	return res;
+}
+
+enum ast_format_cmp_res ast_format_cmp(struct ast_format *format1, struct ast_format *format2)
+{
+	if (format1->id != format2->id) {
+		return AST_FORMAT_CMP_NOT_EQUAL;
+	}
+
+	return format_cmp_helper(format1, format2);
+}
+
+/*! \internal
+ * \brief get joint format attributes using an interface
+ */
+static int format_joint_helper(struct ast_format *format1, struct ast_format *format2, struct ast_format *result)
+{
+	int res = 0;
+	struct interface_ao2_wrapper *wrapper;
+	struct interface_ao2_wrapper tmp_wrapper = {
+		.id = format1->id,
+	};
+
+	ast_rwlock_rdlock(&ilock);
+	if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
+		/* if no interface is present, we assume formats are joint by id alone */
+		ast_rwlock_unlock(&ilock);
+		return res;
+	}
+	ast_rwlock_unlock(&ilock);
+
+	ast_rwlock_rdlock(&wrapper->wraplock);
+	if (!wrapper->interface || !wrapper->interface->format_attr_get_joint) {
+		ast_rwlock_unlock(&wrapper->wraplock);
+		ao2_ref(wrapper, -1);
+		return res;
+	}
+
+	res = wrapper->interface->format_attr_get_joint(&format1->fattr, &format2->fattr, &result->fattr);
+
+	ast_rwlock_unlock(&wrapper->wraplock);
+	ao2_ref(wrapper, -1);
+
+	return res;
+}
+
+int ast_format_joint(struct ast_format *format1, struct ast_format *format2, struct ast_format *result)
+{
+	if (format1->id != format2->id) {
+		return -1;
+	}
+	result->id = format1->id;
+	return format_joint_helper(format1, format2, result);
+}
+
+uint64_t ast_format_to_iax2(struct ast_format *format)
+{
+	switch (format->id) {
+	/*! G.723.1 compression */
+	case AST_FORMATNEW_G723_1:
+		return (1ULL << 0);
+	/*! GSM compression */
+	case AST_FORMATNEW_GSM:
+		return (1ULL << 1);
+	/*! Raw mu-law data (G.711) */
+	case AST_FORMATNEW_ULAW:
+		return (1ULL << 2);
+	/*! Raw A-law data (G.711) */
+	case AST_FORMATNEW_ALAW:
+		return (1ULL << 3);
+	/*! ADPCM (G.726, 32kbps, AAL2 codeword packing) */
+	case AST_FORMATNEW_G726_AAL2:
+		return (1ULL << 4);
+	/*! ADPCM (IMA) */
+	case AST_FORMATNEW_ADPCM:
+		return (1ULL << 5);
+	/*! Raw 16-bit Signed Linear (8000 Hz) PCM */
+	case AST_FORMATNEW_SLINEAR:
+		return (1ULL << 6);
+	/*! LPC10, 180 samples/frame */
+	case AST_FORMATNEW_LPC10:
+		return (1ULL << 7);
+	/*! G.729A audio */
+	case AST_FORMATNEW_G729A:
+		return (1ULL << 8);
+	/*! SpeeX Free Compression */
+	case AST_FORMATNEW_SPEEX:
+		return (1ULL << 9);
+	/*! iLBC Free Compression */
+	case AST_FORMATNEW_ILBC:
+		return (1ULL << 10);
+	/*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
+	case AST_FORMATNEW_G726:
+		return (1ULL << 11);
+	/*! G.722 */
+	case AST_FORMATNEW_G722:
+		return (1ULL << 12);
+	/*! G.722.1 (also known as Siren7, 32kbps assumed) */
+	case AST_FORMATNEW_SIREN7:
+		return (1ULL << 13);
+	/*! G.722.1 Annex C (also known as Siren14, 48kbps assumed) */
+	case AST_FORMATNEW_SIREN14:
+		return (1ULL << 14);
+	/*! Raw 16-bit Signed Linear (16000 Hz) PCM */
+	case AST_FORMATNEW_SLINEAR16:
+		return (1ULL << 15);
+	/*! G.719 (64 kbps assumed) */
+	case AST_FORMATNEW_G719:
+		return (1ULL << 32);
+	/*! SpeeX Wideband (16kHz) Free Compression */
+	case AST_FORMATNEW_SPEEX16:
+		return (1ULL << 33);
+	/*! Raw mu-law data (G.711) */
+	case AST_FORMATNEW_TESTLAW:
+		return (1ULL << 47);
+
+	/*! H.261 Video */
+	case AST_FORMATNEW_H261:
+		return (1ULL << 18);
+	/*! H.263 Video */
+	case AST_FORMATNEW_H263:
+		return (1ULL << 19);
+	/*! H.263+ Video */
+	case AST_FORMATNEW_H263_PLUS:
+		return (1ULL << 20);
+	/*! H.264 Video */
+	case AST_FORMATNEW_H264:
+		return (1ULL << 21);
+	/*! MPEG4 Video */
+	case AST_FORMATNEW_MP4_VIDEO:
+		return (1ULL << 22);
+
+	/*! JPEG Images */
+	case AST_FORMATNEW_JPEG:
+		return (1ULL << 16);
+	/*! PNG Images */
+	case AST_FORMATNEW_PNG:
+		return (1ULL << 17);
+
+	/*! T.140 RED Text format RFC 4103 */
+	case AST_FORMATNEW_T140RED:
+		return (1ULL << 26);
+	/*! T.140 Text format - ITU T.140, RFC 4103 */
+	case AST_FORMATNEW_T140:
+		return (1ULL << 27);
+	}
+
+	return 0;
+}
+struct ast_format *ast_format_from_iax2(uint64_t src, struct ast_format *dst)
+{
+	switch (src) {
+	/*! G.723.1 compression */
+	case (1ULL << 0):
+		return ast_format_set(dst, AST_FORMATNEW_G723_1, 0);
+	/*! GSM compression */
+	case (1ULL << 1):
+		return ast_format_set(dst, AST_FORMATNEW_GSM, 0);
+	/*! Raw mu-law data (G.711) */
+	case (1ULL << 2):
+		return ast_format_set(dst, AST_FORMATNEW_ULAW, 0);
+	/*! Raw A-law data (G.711) */
+	case (1ULL << 3):
+		return ast_format_set(dst, AST_FORMATNEW_ALAW, 0);
+	/*! ADPCM (G.726, 32kbps, AAL2 codeword packing) */
+	case (1ULL << 4):
+		return ast_format_set(dst, AST_FORMATNEW_G726_AAL2, 0);
+	/*! ADPCM (IMA) */
+	case (1ULL << 5):
+		return ast_format_set(dst, AST_FORMATNEW_ADPCM, 0);
+	/*! Raw 16-bit Signed Linear (8000 Hz) PCM */
+	case (1ULL << 6):
+		return ast_format_set(dst, AST_FORMATNEW_SLINEAR, 0);
+	/*! LPC10, 180 samples/frame */
+	case (1ULL << 7):
+		return ast_format_set(dst, AST_FORMATNEW_LPC10, 0);
+	/*! G.729A audio */
+	case (1ULL << 8):
+		return ast_format_set(dst, AST_FORMATNEW_G729A, 0);
+	/*! SpeeX Free Compression */
+	case (1ULL << 9):
+		return ast_format_set(dst, AST_FORMATNEW_SPEEX, 0);
+	/*! iLBC Free Compression */
+	case (1ULL << 10):
+		return ast_format_set(dst, AST_FORMATNEW_ILBC, 0);
+	/*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
+	case (1ULL << 11):
+		return ast_format_set(dst, AST_FORMATNEW_G726, 0);
+	/*! G.722 */
+	case (1ULL << 12):
+		return ast_format_set(dst, AST_FORMATNEW_G722, 0);
+	/*! G.722.1 (also known as Siren7, 32kbps assumed) */
+	case (1ULL << 13):
+		return ast_format_set(dst, AST_FORMATNEW_SIREN7, 0);
+	/*! G.722.1 Annex C (also known as Siren14, 48kbps assumed) */
+	case (1ULL << 14):
+		return ast_format_set(dst, AST_FORMATNEW_SIREN14, 0);
+	/*! Raw 16-bit Signed Linear (16000 Hz) PCM */
+	case (1ULL << 15):
+		return ast_format_set(dst, AST_FORMATNEW_SLINEAR16, 0);
+	/*! G.719 (64 kbps assumed) */
+	case (1ULL << 32):
+		return ast_format_set(dst, AST_FORMATNEW_G719, 0);
+	/*! SpeeX Wideband (16kHz) Free Compression */
+	case (1ULL << 33):
+		return ast_format_set(dst, AST_FORMATNEW_SPEEX16, 0);
+	/*! Raw mu-law data (G.711) */
+	case (1ULL << 47):
+		return ast_format_set(dst, AST_FORMATNEW_TESTLAW, 0);
+
+	/*! H.261 Video */
+	case (1ULL << 18):
+		return ast_format_set(dst, AST_FORMATNEW_H261, 0);
+	/*! H.263 Video */
+	case (1ULL << 19):
+		return ast_format_set(dst, AST_FORMATNEW_H263, 0);
+	/*! H.263+ Video */
+	case (1ULL << 20):
+		return ast_format_set(dst, AST_FORMATNEW_H263_PLUS, 0);
+	/*! H.264 Video */
+	case (1ULL << 21):
+		return ast_format_set(dst, AST_FORMATNEW_H264, 0);
+	/*! MPEG4 Video */
+	case (1ULL << 22):
+		return ast_format_set(dst, AST_FORMATNEW_MP4_VIDEO, 0);
+
+	/*! JPEG Images */
+	case (1ULL << 16):
+		return ast_format_set(dst, AST_FORMATNEW_JPEG, 0);
+	/*! PNG Images */
+	case (1ULL << 17):
+		return ast_format_set(dst, AST_FORMATNEW_PNG, 0);
+
+	/*! T.140 RED Text format RFC 4103 */
+	case (1ULL << 26):
+		return ast_format_set(dst, AST_FORMATNEW_T140RED, 0);
+	/*! T.140 Text format - ITU T.140, RFC 4103 */
+	case (1ULL << 27):
+		return ast_format_set(dst, AST_FORMATNEW_T140, 0);
+	}
+
+	return NULL;
+}
+
+int ast_format_attr_init()
+{
+	if (!(interfaces = ao2_container_alloc(256, interface_hash_cb, interface_cmp_cb))) {
+		return -1;
+	}
+	ast_rwlock_init(&ilock);
+	return 0;
+}
+
+int ast_format_attr_reg_interface(struct ast_format_attr_interface *interface)
+{
+	struct interface_ao2_wrapper *wrapper;
+	struct interface_ao2_wrapper tmp_wrapper = {
+		.id = interface->id,
+	};
+
+	/* check for duplicates first*/
+	ast_rwlock_wrlock(&ilock);
+	if ((wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
+		ast_rwlock_unlock(&ilock);
+		ast_log(LOG_WARNING, "Can not register attribute interface for format id %d, interface already exists.\n", interface->id);
+		ao2_ref(wrapper, -1);
+		return -1;
+	}
+	ast_rwlock_unlock(&ilock);
+
+	if (!(wrapper = ao2_alloc(sizeof(*wrapper), interface_destroy_cb))) {
+		return -1;
+	}
+
+	wrapper->interface = interface;
+	wrapper->id = interface->id;
+	ast_rwlock_init(&wrapper->wraplock);
+
+	/* use the write lock whenever the interface container is modified */
+	ast_rwlock_wrlock(&ilock);
+	ao2_link(interfaces, wrapper);
+	ast_rwlock_unlock(&ilock);
+
+	ao2_ref(wrapper, -1);
+
+	return 0;
+}
+
+int ast_format_attr_unreg_interface(struct ast_format_attr_interface *interface)
+{
+	struct interface_ao2_wrapper *wrapper;
+	struct interface_ao2_wrapper tmp_wrapper = {
+		.id = interface->id,
+	};
+
+	/* use the write lock whenever the interface container is modified */
+	ast_rwlock_wrlock(&ilock);
+	if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_UNLINK | OBJ_NOLOCK)))) {
+		ast_rwlock_unlock(&ilock);
+		return -1;
+	}
+	ast_rwlock_unlock(&ilock);
+
+	ast_rwlock_wrlock(&wrapper->wraplock);
+	wrapper->interface = NULL;
+	ast_rwlock_unlock(&wrapper->wraplock);
+
+	ao2_ref(wrapper, -1);
+
+	return 0;
+}

Propchange: team/dvossel/fixtheworld_phase1_step3/main/format.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/dvossel/fixtheworld_phase1_step3/main/format.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/dvossel/fixtheworld_phase1_step3/main/format.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/dvossel/fixtheworld_phase1_step3/main/format_cap.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/format_cap.c?view=auto&rev=300163
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/format_cap.c (added)
+++ team/dvossel/fixtheworld_phase1_step3/main/format_cap.c Mon Jan  3 16:29:34 2011
@@ -1,0 +1,318 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2010, 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 Format Capability API
+ *
+ * \author David Vossel <dvossel at digium.com>
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$");
+
+#include "asterisk/_private.h"
+#include "asterisk/version.h"
+#include "asterisk/format.h"
+#include "asterisk/format_cap.h"
+#include "asterisk/astobj2.h"
+#include "asterisk/utils.h"
+
+
+struct ast_cap {
+	/* The capabilities structure is just an ao2 container of ast_formats */
+	struct ao2_container *formats;
+	struct ao2_iterator it;
+};
+
+/*! format exists within capabilities structure if it is identical to
+ * another format, or if the format is a proper subset of another format. */
+static int cmp_cb(void *obj, void *arg, int flags)
+{
+	struct ast_format *format1 = arg;
+	struct ast_format *format2 = obj;

[... 1712 lines stripped ...]



More information about the svn-commits mailing list