00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 2005, Anthony Minessale II 00005 * 00006 * Anthony Minessale <anthmct@yahoo.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 /*! \file 00020 * \brief A machine to gather up arbitrary frames and convert them 00021 * to raw slinear on demand. 00022 */ 00023 00024 #ifndef _ASTERISK_SLINFACTORY_H 00025 #define _ASTERISK_SLINFACTORY_H 00026 00027 #include "asterisk/format.h" 00028 00029 #if defined(__cplusplus) || defined(c_plusplus) 00030 extern "C" { 00031 #endif 00032 00033 #define AST_SLINFACTORY_MAX_HOLD 1280 00034 00035 struct ast_slinfactory { 00036 AST_LIST_HEAD_NOLOCK(, ast_frame) queue; /*!< A list of unaltered frames */ 00037 struct ast_trans_pvt *trans; /*!< Translation path that converts fed frames into signed linear */ 00038 short hold[AST_SLINFACTORY_MAX_HOLD]; /*!< Hold for audio that no longer belongs to a frame (ie: if only some samples were taken from a frame) */ 00039 short *offset; /*!< Offset into the hold where audio begins */ 00040 size_t holdlen; /*!< Number of samples currently in the hold */ 00041 unsigned int size; /*!< Number of samples currently in the factory */ 00042 struct ast_format format; /*!< Current format the translation path is converting from */ 00043 struct ast_format output_format; /*!< The output format desired */ 00044 }; 00045 00046 /*! 00047 * \brief Initialize a slinfactory 00048 * 00049 * \param sf The slinfactory to initialize 00050 * 00051 * \return Nothing 00052 */ 00053 void ast_slinfactory_init(struct ast_slinfactory *sf); 00054 00055 /*! 00056 * \brief Initialize a slinfactory 00057 * 00058 * \param sf The slinfactory to initialize 00059 * \param slin_out the slinear output format desired. 00060 * 00061 * \return 0 on success, non-zero on failure 00062 */ 00063 int ast_slinfactory_init_with_format(struct ast_slinfactory *sf, const struct ast_format *slin_out); 00064 00065 /*! 00066 * \brief Destroy the contents of a slinfactory 00067 * 00068 * \param sf The slinfactory that is no longer needed 00069 * 00070 * This function will free any memory allocated for the contents of the 00071 * slinfactory. It does not free the slinfactory itself. If the sf is 00072 * malloc'd, then it must be explicitly free'd after calling this function. 00073 * 00074 * \return Nothing 00075 */ 00076 void ast_slinfactory_destroy(struct ast_slinfactory *sf); 00077 00078 /*! 00079 * \brief Feed audio into a slinfactory 00080 * 00081 * \param sf The slinfactory to feed into 00082 * \param f Frame containing audio to feed in 00083 * 00084 * \return Number of frames currently in factory 00085 */ 00086 int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f); 00087 00088 /*! 00089 * \brief Read samples from a slinfactory 00090 * 00091 * \param sf The slinfactory to read from 00092 * \param buf Buffer to put samples into 00093 * \param samples Number of samples wanted 00094 * 00095 * \return Number of samples read 00096 */ 00097 int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t samples); 00098 00099 /*! 00100 * \brief Retrieve number of samples currently in a slinfactory 00101 * 00102 * \param sf The slinfactory to peek into 00103 * 00104 * \return Number of samples in slinfactory 00105 */ 00106 unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf); 00107 00108 /*! 00109 * \brief Flush the contents of a slinfactory 00110 * 00111 * \param sf The slinfactory to flush 00112 * 00113 * \return Nothing 00114 */ 00115 void ast_slinfactory_flush(struct ast_slinfactory *sf); 00116 00117 #if defined(__cplusplus) || defined(c_plusplus) 00118 } 00119 #endif 00120 00121 #endif /* _ASTERISK_SLINFACTORY_H */