00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 1999 - 2006, 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 /*! \file 00020 * \brief Generic File Format Support. 00021 * Should be included by clients of the file handling routines. 00022 * File service providers should instead include mod_format.h 00023 */ 00024 00025 #ifndef _ASTERISK_FILE_H 00026 #define _ASTERISK_FILE_H 00027 00028 #ifdef HAVE_FCNTL_H 00029 #include <fcntl.h> 00030 #endif 00031 00032 #ifdef HAVE_MMAP 00033 #include <sys/mman.h> 00034 #endif 00035 00036 #if defined(__cplusplus) || defined(c_plusplus) 00037 extern "C" { 00038 #endif 00039 00040 struct ast_filestream; 00041 struct ast_format; 00042 00043 /*! The maximum number of formats we expect to see in a format string */ 00044 #define AST_MAX_FORMATS 10 00045 00046 /*! Convenient for waiting */ 00047 #define AST_DIGIT_NONE "" 00048 #define AST_DIGIT_ANY "0123456789#*ABCD" 00049 #define AST_DIGIT_ANYNUM "0123456789" 00050 00051 #define SEEK_FORCECUR 10 00052 00053 /*! 00054 * \brief Streams a file 00055 * \param c channel to stream the file to 00056 * \param filename the name of the file you wish to stream, minus the extension 00057 * \param preflang the preferred language you wish to have the file streamed to you in 00058 * Prepares a channel for the streaming of a file. To start the stream, afterward do a ast_waitstream() on the channel 00059 * Also, it will stop any existing streams on the channel. 00060 * \retval 0 on success. 00061 * \retval -1 on failure. 00062 */ 00063 int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang); 00064 00065 /*! 00066 * \brief stream file until digit 00067 * If the file name is non-empty, try to play it. 00068 * \note If digits == "" then we can simply check for non-zero. 00069 * \return 0 if success. 00070 * \retval -1 if error. 00071 * \retval digit if interrupted by a digit. 00072 */ 00073 int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char *digits); 00074 00075 /*! 00076 * \brief Stops a stream 00077 * 00078 * \param c The channel you wish to stop playback on 00079 * 00080 * Stop playback of a stream 00081 * 00082 * \retval 0 always 00083 * 00084 * \note The channel does not need to be locked before calling this function. 00085 */ 00086 int ast_stopstream(struct ast_channel *c); 00087 00088 /*! 00089 * \brief Checks for the existence of a given file 00090 * \param filename name of the file you wish to check, minus the extension 00091 * \param fmt the format you wish to check (the extension) 00092 * \param preflang (the preferred language you wisht to find the file in) 00093 * See if a given file exists in a given format. If fmt is NULL, any format is accepted. 00094 * \retval 0, false. The file does not exist 00095 * \retval 1, true. The file does exist. 00096 */ 00097 int ast_fileexists(const char *filename, const char *fmt, const char *preflang); 00098 00099 /*! 00100 * \brief Renames a file 00101 * \param oldname the name of the file you wish to act upon (minus the extension) 00102 * \param newname the name you wish to rename the file to (minus the extension) 00103 * \param fmt the format of the file 00104 * Rename a given file in a given format, or if fmt is NULL, then do so for all 00105 * \return -1 on failure 00106 */ 00107 int ast_filerename(const char *oldname, const char *newname, const char *fmt); 00108 00109 /*! 00110 * \brief Deletes a file 00111 * \param filename name of the file you wish to delete (minus the extension) 00112 * \param fmt of the file 00113 * Delete a given file in a given format, or if fmt is NULL, then do so for all 00114 */ 00115 int ast_filedelete(const char *filename, const char *fmt); 00116 00117 /*! 00118 * \brief Copies a file 00119 * \param oldname name of the file you wish to copy (minus extension) 00120 * \param newname name you wish the file to be copied to (minus extension) 00121 * \param fmt the format of the file 00122 * Copy a given file in a given format, or if fmt is NULL, then do so for all 00123 */ 00124 int ast_filecopy(const char *oldname, const char *newname, const char *fmt); 00125 00126 /*! 00127 * \brief Waits for a stream to stop or digit to be pressed 00128 * \param c channel to waitstream on 00129 * \param breakon string of DTMF digits to break upon 00130 * Begins playback of a stream... 00131 * Wait for a stream to stop or for any one of a given digit to arrive, 00132 * \retval 0 if the stream finishes 00133 * \retval the character if it was interrupted, 00134 * \retval -1 on error 00135 */ 00136 int ast_waitstream(struct ast_channel *c, const char *breakon); 00137 00138 /*! 00139 * \brief Waits for a stream to stop or digit matching a valid one digit exten to be pressed 00140 * \param c channel to waitstream on 00141 * \param context string of context to match digits to break upon 00142 * Begins playback of a stream... 00143 * Wait for a stream to stop or for any one of a valid extension digit to arrive, 00144 * \retval 0 if the stream finishes. 00145 * \retval the character if it was interrupted. 00146 * \retval -1 on error. 00147 */ 00148 int ast_waitstream_exten(struct ast_channel *c, const char *context); 00149 00150 /*! 00151 * \brief Same as waitstream but allows stream to be forwarded or rewound 00152 * \param c channel to waitstream on 00153 * \param breakon string of DTMF digits to break upon 00154 * \param forward DTMF digit to fast forward upon 00155 * \param rewind DTMF digit to rewind upon 00156 * \param ms How many miliseconds to skip forward/back 00157 * Begins playback of a stream... 00158 * Wait for a stream to stop or for any one of a given digit to arrive, 00159 * \retval 0 if the stream finishes. 00160 * \retval the character if it was interrupted. 00161 * \retval -1 on error. 00162 */ 00163 int ast_waitstream_fr(struct ast_channel *c, const char *breakon, const char *forward, const char *rewind, int ms); 00164 00165 /*! 00166 * Same as waitstream, but with audio output to fd and monitored fd checking. 00167 * 00168 * \return 1 if monfd is ready for reading 00169 */ 00170 int ast_waitstream_full(struct ast_channel *c, const char *breakon, int audiofd, int monfd); 00171 00172 /*! 00173 * \brief Starts reading from a file 00174 * \param filename the name of the file to read from 00175 * \param type format of file you wish to read from 00176 * \param comment comment to go with 00177 * \param flags file flags 00178 * \param check (unimplemented, hence negligible) 00179 * \param mode Open mode 00180 * Open an incoming file stream. flags are flags for the open() command, and 00181 * if check is non-zero, then it will not read a file if there are any files that 00182 * start with that name and have an extension 00183 * Please note, this is a blocking function. Program execution will not return until ast_waitstream completes it's execution. 00184 * \retval a struct ast_filestream on success. 00185 * \retval NULL on failure. 00186 */ 00187 struct ast_filestream *ast_readfile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode); 00188 00189 /*! 00190 * \brief Starts writing a file 00191 * \param filename the name of the file to write to 00192 * \param type format of file you wish to write out to 00193 * \param comment comment to go with 00194 * \param flags output file flags 00195 * \param check (unimplemented, hence negligible) 00196 * \param mode Open mode 00197 * Create an outgoing file stream. oflags are flags for the open() command, and 00198 * if check is non-zero, then it will not write a file if there are any files that 00199 * start with that name and have an extension 00200 * Please note, this is a blocking function. Program execution will not return until ast_waitstream completes it's execution. 00201 * \retval a struct ast_filestream on success. 00202 * \retval NULL on failure. 00203 */ 00204 struct ast_filestream *ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode); 00205 00206 /*! 00207 * \brief Writes a frame to a stream 00208 * \param fs filestream to write to 00209 * \param f frame to write to the filestream 00210 * Send a frame to a filestream -- note: does NOT free the frame, call ast_frfree manually 00211 * \retval 0 on success. 00212 * \retval -1 on failure. 00213 */ 00214 int ast_writestream(struct ast_filestream *fs, struct ast_frame *f); 00215 00216 /*! 00217 * \brief Closes a stream 00218 * \param f filestream to close 00219 * Close a playback or recording stream 00220 * \retval 0 on success. 00221 * \retval -1 on failure. 00222 */ 00223 int ast_closestream(struct ast_filestream *f); 00224 00225 /*! 00226 * \brief Opens stream for use in seeking, playing 00227 * \param chan channel to work with 00228 * \param filename to use 00229 * \param preflang prefered language to use 00230 * \retval a ast_filestream pointer if it opens the file. 00231 * \retval NULL on error. 00232 */ 00233 struct ast_filestream *ast_openstream(struct ast_channel *chan, const char *filename, const char *preflang); 00234 00235 /*! 00236 * \brief Opens stream for use in seeking, playing 00237 * \param chan channel to work with 00238 * \param filename to use 00239 * \param preflang prefered language to use 00240 * \param asis if set, don't clear generators 00241 * \retval a ast_filestream pointer if it opens the file. 00242 * \retval NULL on error. 00243 */ 00244 struct ast_filestream *ast_openstream_full(struct ast_channel *chan, const char *filename, const char *preflang, int asis); 00245 /*! 00246 * \brief Opens stream for use in seeking, playing 00247 * \param chan channel to work with 00248 * \param filename to use 00249 * \param preflang prefered language to use 00250 * \retval a ast_filestream pointer if it opens the file. 00251 * \retval NULL on error. 00252 */ 00253 struct ast_filestream *ast_openvstream(struct ast_channel *chan, const char *filename, const char *preflang); 00254 00255 /*! 00256 * \brief Applys a open stream to a channel. 00257 * \param chan channel to work 00258 * \param s ast_filestream to apply 00259 * \retval 0 on success. 00260 * \retval -1 on failure. 00261 */ 00262 int ast_applystream(struct ast_channel *chan, struct ast_filestream *s); 00263 00264 /*! 00265 * \brief Play a open stream on a channel. 00266 * \param s filestream to play 00267 * \retval 0 on success. 00268 * \retval -1 on failure. 00269 */ 00270 int ast_playstream(struct ast_filestream *s); 00271 00272 /*! 00273 * \brief Seeks into stream 00274 * \param fs ast_filestream to perform seek on 00275 * \param sample_offset numbers of samples to seek 00276 * \param whence SEEK_SET, SEEK_CUR, SEEK_END 00277 * \retval 0 on success. 00278 * \retval -1 on failure. 00279 */ 00280 int ast_seekstream(struct ast_filestream *fs, off_t sample_offset, int whence); 00281 00282 /*! 00283 * \brief Trunc stream at current location 00284 * \param fs filestream to act on 00285 * \retval 0 on success. 00286 * \retval -1 on failure. 00287 */ 00288 int ast_truncstream(struct ast_filestream *fs); 00289 00290 /*! 00291 * \brief Fast forward stream ms 00292 * \param fs filestream to act on 00293 * \param ms milliseconds to move 00294 * \retval 0 on success. 00295 * \retval -1 on failure. 00296 */ 00297 int ast_stream_fastforward(struct ast_filestream *fs, off_t ms); 00298 00299 /*! 00300 * \brief Rewind stream ms 00301 * \param fs filestream to act on 00302 * \param ms milliseconds to move 00303 * \retval 0 on success. 00304 * \retval -1 on failure. 00305 */ 00306 int ast_stream_rewind(struct ast_filestream *fs, off_t ms); 00307 00308 /*! 00309 * \brief Tell where we are in a stream 00310 * \param fs fs to act on 00311 * \return a long as a sample offset into stream 00312 */ 00313 off_t ast_tellstream(struct ast_filestream *fs); 00314 00315 /*! 00316 * \brief Read a frame from a filestream 00317 * \param s ast_filestream to act on 00318 * \return a frame. 00319 * \retval NULL if read failed. 00320 */ 00321 struct ast_frame *ast_readframe(struct ast_filestream *s); 00322 00323 /*! Initialize file stuff */ 00324 /*! 00325 * Initializes all the various file stuff. Basically just registers the cli stuff 00326 * Returns 0 all the time 00327 */ 00328 int ast_file_init(void); 00329 00330 00331 #define AST_RESERVED_POINTERS 20 00332 00333 /*! Remove duplicate formats from a format string. */ 00334 /*! 00335 * \param fmts a format string, this string will be modified 00336 * \retval NULL error 00337 * \return a pointer to the reduced format string, this is a pointer to fmts 00338 */ 00339 char *ast_format_str_reduce(char *fmts); 00340 00341 #if defined(__cplusplus) || defined(c_plusplus) 00342 } 00343 #endif 00344 00345 #endif /* _ASTERISK_FILE_H */
1.5.6