00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 2010, Digium, Inc. 00005 * 00006 * Mark Spencer <markster@digium.com> 00007 * 00008 * See http://www.asterisk.org for more information about 00009 * the Asterisk project. Please do not directly contact 00010 * any of the maintainers of this project for assistance; 00011 * the project provides a web site, mailing lists and IRC 00012 * channels for your use. 00013 * 00014 * This program is free software, distributed under the terms of 00015 * the GNU General Public License Version 2. See the LICENSE file 00016 * at the top of the source tree. 00017 */ 00018 00019 /*! 00020 * \file 00021 * \brief Format Preference API 00022 */ 00023 00024 #ifndef _AST_FORMATPREF_H_ 00025 #define _AST_FORMATPREF_H_ 00026 00027 #include "asterisk/format.h" 00028 #include "asterisk/format_cap.h" 00029 00030 #define AST_CODEC_PREF_SIZE 64 00031 struct ast_codec_pref { 00032 /*! This array represents the each format in the pref list */ 00033 struct ast_format formats[AST_CODEC_PREF_SIZE]; 00034 /*! This array represents the format id's index in the global format list. */ 00035 char order[AST_CODEC_PREF_SIZE]; 00036 /*! This array represents the format's framing size if present. */ 00037 int framing[AST_CODEC_PREF_SIZE]; 00038 }; 00039 00040 /*! \page AudioCodecPref Audio Codec Preferences 00041 00042 In order to negotiate audio codecs in the order they are configured 00043 in <channel>.conf for a device, we set up codec preference lists 00044 in addition to the codec capabilities setting. The capabilities 00045 setting is a bitmask of audio and video codecs with no internal 00046 order. This will reflect the offer given to the other side, where 00047 the prefered codecs will be added to the top of the list in the 00048 order indicated by the "allow" lines in the device configuration. 00049 00050 Video codecs are not included in the preference lists since they 00051 can't be transcoded and we just have to pick whatever is supported 00052 */ 00053 00054 /*! 00055 *\brief Initialize an audio codec preference to "no preference". 00056 * \arg \ref AudioCodecPref 00057 */ 00058 void ast_codec_pref_init(struct ast_codec_pref *pref); 00059 00060 /*! 00061 * \brief Codec located at a particular place in the preference index. 00062 * \param preference structure to get the codec out of 00063 * \param index to retrieve from 00064 * \param retult ast_format structure to store the index value in 00065 * \return pointer to input ast_format on success, NULL on failure 00066 */ 00067 struct ast_format *ast_codec_pref_index(struct ast_codec_pref *pref, int index, struct ast_format *result); 00068 00069 /*! \brief Remove audio a codec from a preference list */ 00070 void ast_codec_pref_remove(struct ast_codec_pref *pref, struct ast_format *format); 00071 00072 /*! \brief Append a audio codec to a preference list, removing it first if it was already there 00073 */ 00074 int ast_codec_pref_append(struct ast_codec_pref *pref, struct ast_format *format); 00075 00076 /*! \brief Prepend an audio codec to a preference list, removing it first if it was already there 00077 */ 00078 void ast_codec_pref_prepend(struct ast_codec_pref *pref, struct ast_format *format, int only_if_existing); 00079 00080 /*! \brief Select the best audio format according to preference list from supplied options. 00081 * Best audio format is returned in the result format. 00082 * 00083 * \note If "find_best" is non-zero then if nothing is found, the "Best" format of 00084 * the format list is selected and returned in the result structure, otherwise 00085 * NULL is returned 00086 * 00087 * \retval ptr to result struture. 00088 * \retval NULL, best codec was not found 00089 */ 00090 struct ast_format *ast_codec_choose(struct ast_codec_pref *pref, struct ast_format_cap *cap, int find_best, struct ast_format *result); 00091 00092 /*! \brief Set packet size for codec 00093 */ 00094 int ast_codec_pref_setsize(struct ast_codec_pref *pref, struct ast_format *format, int framems); 00095 00096 /*! \brief Get packet size for codec 00097 */ 00098 struct ast_format_list ast_codec_pref_getsize(struct ast_codec_pref *pref, struct ast_format *format); 00099 00100 /*! \brief Dump audio codec preference list into a string */ 00101 int ast_codec_pref_string(struct ast_codec_pref *pref, char *buf, size_t size); 00102 00103 /*! \brief Shift an audio codec preference list up or down 65 bytes so that it becomes an ASCII string 00104 * \note Due to a misunderstanding in how codec preferences are stored, this 00105 * list starts at 'B', not 'A'. For backwards compatibility reasons, this 00106 * cannot change. 00107 * \param pref A codec preference list structure 00108 * \param buf A string denoting codec preference, appropriate for use in line transmission 00109 * \param size Size of \a buf 00110 * \param right Boolean: if 0, convert from \a buf to \a pref; if 1, convert from \a pref to \a buf. 00111 */ 00112 void ast_codec_pref_convert(struct ast_codec_pref *pref, char *buf, size_t size, int right); 00113 00114 #endif /* _AST_FORMATPREF_H */