Sat Mar 10 01:54:17 2012

Asterisk developer's documentation


file.h

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

Generated on Sat Mar 10 01:54:17 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7