Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

file.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- A telephony toolkit for Linux.
00003  *
00004  * Generic File Format Support.
00005  * 
00006  * Copyright (C) 1999, Mark Spencer
00007  *
00008  * Mark Spencer <markster@linux-support.net>
00009  *
00010  * This program is free software, distributed under the terms of
00011  * the GNU General Public License
00012  */
00013 
00014 #ifndef _ASTERISK_FILE_H
00015 #define _ASTERISK_FILE_H
00016 
00017 #include <asterisk/channel.h>
00018 #include <asterisk/frame.h>
00019 #include <fcntl.h>
00020 
00021 
00022 #if defined(__cplusplus) || defined(c_plusplus)
00023 extern "C" {
00024 #endif
00025 
00026 
00027 //! Convenient for waiting
00028 #define AST_DIGIT_ANY   "0123456789#*"
00029 
00030 #define SEEK_FORCECUR   10
00031    
00032 /* Defined by individual formats.  First item MUST be a
00033    pointer for use by the stream manager */
00034 struct ast_filestream;
00035 
00036 //! Registers a new file format
00037 /*! Register a new file format capability
00038  * Adds a format to asterisk's format abilities.  Fill in the fields, and it will work. For examples, look at some of the various format code.
00039  * returns 0 on success, -1 on failure
00040  */
00041 int ast_format_register(char *name, char *exts, int format,
00042                   struct ast_filestream * (*open)(int fd),
00043                   struct ast_filestream * (*rewrite)(int fd, char *comment),
00044                   int (*write)(struct ast_filestream *, struct ast_frame *),
00045                   int (*seek)(struct ast_filestream *, long offset, int whence),
00046                   int (*trunc)(struct ast_filestream *),
00047                   long (*tell)(struct ast_filestream *),
00048                   struct ast_frame * (*read)(struct ast_filestream *, int *timetonext),
00049                   void (*close)(struct ast_filestream *),
00050                   char * (*getcomment)(struct ast_filestream *));
00051    
00052 //! Unregisters a file format
00053 /*!
00054  * \param name the name of the format you wish to unregister
00055  * Unregisters a format based on the name of the format.
00056  * Returns 0 on success, -1 on failure to unregister
00057  */
00058 int ast_format_unregister(char *name);
00059 
00060 //! Streams a file
00061 /*!
00062  * \param c channel to stream the file to
00063  * \param filename the name of the file you wish to stream, minus the extension
00064  * \param preflang the preferred language you wish to have the file streamed to you in
00065  * Prepares a channel for the streaming of a file.  To start the stream, afterward do a ast_waitstream() on the channel
00066  * Also, it will stop any existing streams on the channel.
00067  * Returns 0 on success, or -1 on failure.
00068  */
00069 int ast_streamfile(struct ast_channel *c, char *filename, char *preflang);
00070 
00071 //! Stops a stream
00072 /*!
00073  * \param c The channel you wish to stop playback on
00074  * Stop playback of a stream 
00075  * Returns 0 regardless
00076  */
00077 int ast_stopstream(struct ast_channel *c);
00078 
00079 //! Checks for the existence of a given file
00080 /*!
00081  * \param filename name of the file you wish to check, minus the extension
00082  * \param fmt the format you wish to check (the extension)
00083  * \param preflang (the preferred language you wisht to find the file in)
00084  * See if a given file exists in a given format.  If fmt is NULL,  any format is accepted.
00085  * Returns -1 if file does not exist, non-zero positive otherwise.
00086  */
00087 int ast_fileexists(char *filename, char *fmt, char *preflang);
00088 
00089 //! Renames a file
00090 /*! 
00091  * \param oldname the name of the file you wish to act upon (minus the extension)
00092  * \param newname the name you wish to rename the file to (minus the extension)
00093  * \param fmt the format of the file
00094  * Rename a given file in a given format, or if fmt is NULL, then do so for all 
00095  * Returns -1 on failure
00096  */
00097 int ast_filerename(char *oldname, char *newname, char *fmt);
00098 
00099 //! Deletes a file
00100 /*! 
00101  * \param filename name of the file you wish to delete (minus the extension)
00102  * \param format of the file
00103  * Delete a given file in a given format, or if fmt is NULL, then do so for all 
00104  */
00105 int ast_filedelete(char *filename, char *fmt);
00106 
00107 //! Copies a file
00108 /*!
00109  * \param oldname name of the file you wish to copy (minus extension)
00110  * \param newname name you wish the file to be copied to (minus extension)
00111  * \param fmt the format of the file
00112  * Copy a given file in a given format, or if fmt is NULL, then do so for all 
00113  */
00114 int ast_filecopy(char *oldname, char *newname, char *fmt);
00115 
00116 //! Waits for a stream to stop or digit to be pressed
00117 /*!
00118  * \param c channel to waitstram on
00119  * \param breakon string of DTMF digits to break upon
00120  * Begins playback of a stream...
00121  * Wait for a stream to stop or for any one of a given digit to arrive,  Returns 0 
00122  * if the stream finishes, the character if it was interrupted, and -1 on error 
00123  */
00124 char ast_waitstream(struct ast_channel *c, char *breakon);
00125 
00126 //! Same as waitstream but allows stream to be forwarded or rewound
00127 /*!
00128  * \param c channel to waitstram on
00129  * \param breakon string of DTMF digits to break upon
00130  * \param forward DTMF digit to fast forward upon
00131  * \param rewind DTMF digit to rewind upon
00132  * \param ms How many miliseconds to skip forward/back
00133  * Begins playback of a stream...
00134  * Wait for a stream to stop or for any one of a given digit to arrive,  Returns 0 
00135  * if the stream finishes, the character if it was interrupted, and -1 on error 
00136  */
00137 char ast_waitstream_fr(struct ast_channel *c, char *breakon, char *forward, char *rewind, int ms);
00138 
00139 /* Same as waitstream, but with audio output to fd and monitored fd checking.  Returns
00140    1 if monfd is ready for reading */
00141 char ast_waitstream_full(struct ast_channel *c, char *breakon, int audiofd, int monfd);
00142 
00143 //! Starts reading from a file
00144 /*!
00145  * \param filename the name of the file to read from
00146  * \param type format of file you wish to read from
00147  * \param comment comment to go with
00148  * \param flags file flags
00149  * \param check (unimplemented, hence negligible)
00150  * \param mode Open mode
00151  * Open an incoming file stream.  flags are flags for the open() command, and 
00152  * if check is non-zero, then it will not read a file if there are any files that 
00153  * start with that name and have an extension
00154  * Please note, this is a blocking function.  Program execution will not return until ast_waitstream completes it's execution.
00155  * Returns a struct ast_filestream on success, NULL on failure
00156  */
00157 struct ast_filestream *ast_readfile(char *filename, char *type, char *comment, int flags, int check, mode_t mode);
00158 
00159 //! Starts writing a file
00160 /*!
00161  * \param filename the name of the file to write to
00162  * \param type format of file you wish to write out to
00163  * \param comment comment to go with
00164  * \param oflags output file flags
00165  * \param check (unimplemented, hence negligible)
00166  * \param mode Open mode
00167  * Create an outgoing file stream.  oflags are flags for the open() command, and 
00168  * if check is non-zero, then it will not write a file if there are any files that 
00169  * start with that name and have an extension
00170  * Please note, this is a blocking function.  Program execution will not return until ast_waitstream completes it's execution.
00171  * Returns a struct ast_filestream on success, NULL on failure
00172  */
00173 struct ast_filestream *ast_writefile(char *filename, char *type, char *comment, int flags, int check, mode_t mode);
00174 
00175 //! Writes a frame to a stream
00176 /*! 
00177  * \param fs filestream to write to
00178  * \param f frame to write to the filestream
00179  * Send a frame to a filestream -- note: does NOT free the frame, call ast_frfree manually
00180  * Returns 0 on success, -1 on failure.
00181  */
00182 int ast_writestream(struct ast_filestream *fs, struct ast_frame *f);
00183 
00184 //! Closes a stream
00185 /*!
00186  * \param f filestream to close
00187  * Close a playback or recording stream
00188  * Returns 0 on success, -1 on failure
00189  */
00190 int ast_closestream(struct ast_filestream *f);
00191 
00192 //! Opens stream for use in seeking, playing
00193 /*!
00194  * \param chan channel to work with
00195  * \param filename to use
00196  * \param preflang prefered language to use
00197  * Returns a ast_filestream pointer if it opens the file, NULL on error
00198  */
00199 struct ast_filestream *ast_openstream(struct ast_channel *chan, char *filename, char *preflang);
00200 
00201 //! Opens stream for use in seeking, playing
00202 /*!
00203  * \param chan channel to work with
00204  * \param filename to use
00205  * \param preflang prefered language to use
00206  * Returns a ast_filestream pointer if it opens the file, NULL on error
00207  */
00208 struct ast_filestream *ast_openvstream(struct ast_channel *chan, char *filename, char *preflang);
00209 
00210 //! Applys a open stream to a channel.
00211 /*!
00212  * \param chan channel to work
00213  * \param ast_filestream s to apply
00214  * Returns 0 for success, -1 on failure
00215  */
00216 int ast_applystream(struct ast_channel *chan, struct ast_filestream *s);
00217 
00218 //! play a open stream on a channel.
00219 /*!
00220  * \param ast_filestream s to play
00221  * Returns 0 for success, -1 on failure
00222  */
00223 int ast_playstream(struct ast_filestream *s);
00224 
00225 //! Seeks into stream
00226 /*!
00227  * \param ast_filestream to perform seek on
00228  * \param sample_offset numbers of samples to seek
00229  * \param whence SEEK_SET, SEEK_CUR, SEEK_END 
00230  * Returns 0 for success, or -1 for error
00231  */
00232 int ast_seekstream(struct ast_filestream *fs, long sample_offset, int whence);
00233 
00234 //! Trunc stream at current location
00235 /*!
00236  * \param ast_filestream fs 
00237  * Returns 0 for success, or -1 for error
00238  */
00239 int ast_truncstream(struct ast_filestream *fs);
00240 
00241 //! Fast forward stream ms
00242 /*!
00243  * \param ast_filestream fs filestream to act on
00244  * \param ms milliseconds to move
00245  * Returns 0 for success, or -1 for error
00246  */
00247 int ast_stream_fastforward(struct ast_filestream *fs, long ms);
00248 
00249 //! Rewind stream ms
00250 /*!
00251  * \param ast_filestream fs filestream to act on
00252  * \param ms milliseconds to move
00253  * Returns 0 for success, or -1 for error
00254  */
00255 int ast_stream_rewind(struct ast_filestream *fs, long ms);
00256 
00257 //! Fast forward stream ms
00258 /*!
00259  * \param ast_filestream fs filestream to act on
00260  * \param ms milliseconds to move
00261  * Returns 0 for success, or -1 for error
00262  */
00263 int ast_stream_fastforward(struct ast_filestream *fs, long ms);
00264 
00265 //! Rewind stream ms
00266 /*!
00267  * \param ast_filestream fs filestream to act on
00268  * \param ms milliseconds to move
00269  * Returns 0 for success, or -1 for error
00270  */
00271 int ast_stream_rewind(struct ast_filestream *fs, long ms);
00272 
00273 //! Tell where we are in a stream
00274 /*!
00275  * \param ast_filestream fs to act on
00276  * Returns a long as a sample offset into stream
00277  */
00278 long ast_tellstream(struct ast_filestream *fs);
00279 
00280 //! Read a frame from a filestream
00281 /*!
00282  * \param ast_filestream fs to act on
00283  * Returns a frame or NULL if read failed
00284  */ 
00285 struct ast_frame *ast_readframe(struct ast_filestream *s);
00286 
00287 //! Initialize file stuff
00288 /*!
00289  * Initializes all the various file stuff.  Basically just registers the cli stuff
00290  * Returns 0 all the time
00291  */
00292 extern int ast_file_init(void);
00293 
00294 
00295 #define AST_RESERVED_POINTERS 20
00296 
00297 #if defined(__cplusplus) || defined(c_plusplus)
00298 }
00299 #endif
00300 
00301 
00302 
00303 #endif

Generated on Sat Nov 25 19:09:37 2006 for Asterisk by  doxygen 1.4.2