00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 2010, Digium, Inc. 00005 * 00006 * David Vossel <dvossel@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 Capability API 00022 * 00023 * \author David Vossel <dvossel@digium.com> 00024 */ 00025 00026 #ifndef _AST_FORMATCAP_H_ 00027 #define _AST_FORMATCAP_H_ 00028 00029 /*! Capabilities are represented by an opaque structure statically defined in format_capability.c */ 00030 struct ast_format_cap; 00031 00032 /*! 00033 * \brief Allocate a new ast_format_cap structure. 00034 * 00035 * \note Allocation of this object assumes locking 00036 * is already occuring and that the point of contention 00037 * is above this capabilities structure. For example, 00038 * a tech_pvt object referencing a capabilities structure 00039 * can use this function as long as it always holds the 00040 * tech_pvt lock while accessing its capabilities. 00041 * 00042 * \retval ast_format_cap object on success. 00043 * \retval NULL on failure. 00044 */ 00045 struct ast_format_cap *ast_format_cap_alloc_nolock(void); 00046 00047 /*! 00048 * \brief Allocate a new ast_format_cap structure with locking 00049 * 00050 * \note If no other form of locking is taking place, use this function. 00051 * This function makes most sense for globally accessible capabilities structures 00052 * that have no other means of locking. 00053 * 00054 * \retval ast_format_cap object on success. 00055 * \retval NULL on failure. 00056 */ 00057 struct ast_format_cap *ast_format_cap_alloc(void); 00058 00059 /*! 00060 * \brief Destroy an ast_format_cap structure. 00061 * 00062 * \return NULL 00063 */ 00064 void *ast_format_cap_destroy(struct ast_format_cap *cap); 00065 00066 /*! 00067 * \brief Add format capability to capabilities structure. 00068 * 00069 * \note A copy of the input format is made and that copy is 00070 * what is placed in the ast_format_cap structure. The actual 00071 * input format ptr is not stored. 00072 */ 00073 void ast_format_cap_add(struct ast_format_cap *cap, const struct ast_format *format); 00074 00075 /*! 00076 * \brief Add all formats Asterisk knows about for a specific type to 00077 * the capabilities structure. Formats with attributes are set, but their 00078 * attributes are initilized to 0's. An attribute structure of 0's should 00079 * indicate to the format attribute interface that the format has full 00080 * capabilities. 00081 * 00082 * \note A copy of the input format is made and that copy is 00083 * what is placed in the ast_format_cap structure. The actual 00084 * input format ptr is not stored. 00085 */ 00086 void ast_format_cap_add_all_by_type(struct ast_format_cap *cap, enum ast_format_type type); 00087 00088 /*! 00089 * \brief Add all known formats to the capabilities structure using default format attribute. */ 00090 void ast_format_cap_add_all(struct ast_format_cap *cap); 00091 00092 /*! 00093 * \brief Append the formats in src to dst 00094 */ 00095 void ast_format_cap_append(struct ast_format_cap *dst, const struct ast_format_cap *src); 00096 00097 /*! 00098 * \brief Copy all items in src to dst. 00099 * \note any items in dst will be removed before copying 00100 */ 00101 void ast_format_cap_copy(struct ast_format_cap *dst, const struct ast_format_cap *src); 00102 00103 /*! 00104 * \brief create a deep copy of an ast_format_cap structure 00105 * 00106 * \retval cap on success 00107 * \retval NULL on failure 00108 */ 00109 struct ast_format_cap *ast_format_cap_dup(const struct ast_format_cap *src); 00110 00111 /*! 00112 * \brief determine if a capabilities structure is empty or not 00113 * 00114 * \retval 1, true is empty 00115 * \retval 0, false, not empty 00116 */ 00117 int ast_format_cap_is_empty(const struct ast_format_cap *cap); 00118 00119 /*! 00120 * \brief Remove format capability from capability structure. 00121 * 00122 * \Note format must match Exactly to format in ast_format_cap object in order 00123 * to be removed. 00124 * 00125 * \retval 0, remove was successful 00126 * \retval -1, remove failed. Could not find format to remove 00127 */ 00128 int ast_format_cap_remove(struct ast_format_cap *cap, struct ast_format *format); 00129 00130 /*! 00131 * \brief Remove all format capabilities from capability 00132 * structure for a specific format id. 00133 * 00134 * \Note This will remove _ALL_ formats matching the format id from the 00135 * capabilities structure. 00136 * 00137 * \retval 0, remove was successful 00138 * \retval -1, remove failed. Could not find formats to remove 00139 */ 00140 int ast_format_cap_remove_byid(struct ast_format_cap *cap, enum ast_format_id id); 00141 00142 /*! 00143 * \brief Remove all formats matching a specific format type. 00144 */ 00145 void ast_format_cap_remove_bytype(struct ast_format_cap *cap, enum ast_format_type type); 00146 00147 /*! 00148 * \brief Remove all format capabilities from capability structure 00149 */ 00150 void ast_format_cap_remove_all(struct ast_format_cap *cap); 00151 00152 /*! 00153 * \brief Remove all previous formats and set a single new format. 00154 */ 00155 void ast_format_cap_set(struct ast_format_cap *cap, struct ast_format *format); 00156 00157 /*! 00158 * \brief Find if input ast_format is within the capabilities of the ast_format_cap object 00159 * then return the compatible format from the capabilities structure in the result. 00160 * 00161 * \retval 1 format is compatible with formats held in ast_format_cap object. 00162 * \retval 0 format is not compatible with any formats in ast_format_cap object. 00163 */ 00164 int ast_format_cap_get_compatible_format(const struct ast_format_cap *cap, const struct ast_format *format, struct ast_format *result); 00165 00166 /*! 00167 * \brief Find if ast_format is within the capabilities of the ast_format_cap object. 00168 * 00169 * retval 1 format is compatible with formats held in ast_format_cap object. 00170 * retval 0 format is not compatible with any formats in ast_format_cap object. 00171 */ 00172 int ast_format_cap_iscompatible(const struct ast_format_cap *cap, const struct ast_format *format); 00173 00174 /*! 00175 * \brief Finds the best quality audio format for a given format id and returns it in result. 00176 * 00177 * \retval 1 format found and set to result structure. 00178 * \retval 0 no format found, result structure is cleared. 00179 */ 00180 int ast_format_cap_best_byid(const struct ast_format_cap *cap, enum ast_format_id, struct ast_format *result); 00181 00182 /*! 00183 * \brief is cap1 identical to cap2 00184 * 00185 * retval 1 true, identical 00186 * retval 0 false, not identical 00187 */ 00188 int ast_format_cap_identical(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2); 00189 00190 /*! 00191 * \brief Get joint capability structure. 00192 * 00193 * \note returns an ast_format_cap object containing the joint capabilities on success. This new 00194 * capabilities structure is allocated with _NO_ locking enabled. If a joint structure requires 00195 * locking, allocate it and use the ast_format_cap_joint_copy function to fill it with the joint 00196 * capabilities. 00197 * 00198 * \retval !NULL success, joint capabilties structure with _NO_ locking enabled. 00199 * \retval NULL failure 00200 */ 00201 struct ast_format_cap *ast_format_cap_joint(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2); 00202 00203 /*! 00204 * \brief Get joint capability structure, copy into result capabilities structure 00205 * 00206 * \retval 1, joint capabilities exist 00207 * \retval 0, joint capabilities do not exist 00208 */ 00209 int ast_format_cap_joint_copy(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2, struct ast_format_cap *result); 00210 00211 /*! 00212 * \brief Get joint capability structure, append into result capabilities structure 00213 * 00214 * \retval 1, joint capabilities exist 00215 * \retval 0, joint capabilities do not exist 00216 */ 00217 int ast_format_cap_joint_append(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2, struct ast_format_cap *result); 00218 00219 /*! 00220 * \brief Find out if capability structures have any joint capabilities without 00221 * returning those capabilities. 00222 * 00223 * \retval 1 true, has joint capabilities 00224 * \retval 0 false, failure 00225 */ 00226 int ast_format_cap_has_joint(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2); 00227 00228 /*! 00229 * \brief Get all capabilities for a specific media type 00230 * 00231 * \retval !NULL success, new capabilities structure with _NO_ locking enabled on the new structure. 00232 * \retval NULL failure 00233 */ 00234 struct ast_format_cap *ast_format_cap_get_type(const struct ast_format_cap *cap, enum ast_format_type ftype); 00235 00236 /*! 00237 * \brief Find out if the capabilities structure has any formats 00238 * of a specific type. 00239 * 00240 * \retval 1 true 00241 * \retval 0 false, no formats of specific type. 00242 */ 00243 int ast_format_cap_has_type(const struct ast_format_cap *cap, enum ast_format_type type); 00244 00245 /*! \brief Start iterating formats */ 00246 void ast_format_cap_iter_start(struct ast_format_cap *cap); 00247 00248 /*! 00249 * \brief Next format in interation 00250 * 00251 * \details 00252 * Here is how to use the ast_format_cap iterator. 00253 * 00254 * 1. call ast_format_cap_iter_start 00255 * 2. call ast_format_cap_iter_next in a loop until it returns -1 00256 * 3. call ast_format_cap_iter_end to terminate the iterator. 00257 * 00258 * example: 00259 * 00260 * ast_format_cap_iter_start(cap); 00261 * while (!ast_format_cap_iter_next(cap, &format)) { 00262 * 00263 * } 00264 * ast_format_cap_iter_end(Cap); 00265 * 00266 * \Note Unless the container was alloced using no_lock, the container 00267 * will be locked during the entire iteration until ast_format_cap_iter_end 00268 * is called. XXX Remember this, and do not attempt to lock any containers 00269 * within this iteration that will violate locking order. 00270 * 00271 * \retval 0 on success, new format is copied into input format struct 00272 * \retval -1, no more formats are present. 00273 */ 00274 int ast_format_cap_iter_next(struct ast_format_cap *cap, struct ast_format *format); 00275 00276 /*! 00277 * \brief Ends ast_format_cap iteration. 00278 * \note this must be call after every ast_format_cap_iter_start 00279 */ 00280 void ast_format_cap_iter_end(struct ast_format_cap *cap); 00281 00282 /*! 00283 * \brief ast_format_cap to old bitfield format represenatation 00284 * 00285 * \note This is only to be used for IAX2 compatibility 00286 * 00287 * \retval old bitfield representation of ast_format_cap 00288 * \retval 0, if no old bitfield capabilities are present in ast_format_cap 00289 */ 00290 uint64_t ast_format_cap_to_old_bitfield(const struct ast_format_cap *cap); 00291 00292 /*! 00293 * \brief convert old bitfield format to ast_format_cap represenatation 00294 * \note This is only to be used for IAX2 compatibility 00295 */ 00296 void ast_format_cap_from_old_bitfield(struct ast_format_cap *dst, uint64_t src); 00297 00298 /*! \brief Get the names of a set of formats 00299 * \param buf a buffer for the output string 00300 * \param size size of buf (bytes) 00301 * \param format the format (combined IDs of codecs) 00302 * Prints a list of readable codec names corresponding to "format". 00303 * ex: for format=AST_FORMAT_GSM|AST_FORMAT_SPEEX|AST_FORMAT_ILBC it will return "0x602 (GSM|SPEEX|ILBC)" 00304 * \return The return value is buf. 00305 */ 00306 char* ast_getformatname_multiple(char *buf, size_t size, struct ast_format_cap *cap); 00307 00308 #endif /* _AST_FORMATCAP_H */