1999-11-21 02:26:43 +00:00
|
|
|
/*
|
2005-08-30 18:32:10 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
1999-11-21 02:26:43 +00:00
|
|
|
*
|
2006-08-21 02:11:39 +00:00
|
|
|
* Copyright (C) 1999 - 2006, Digium, Inc.
|
2005-08-30 18:32:10 +00:00
|
|
|
*
|
|
|
|
* Mark Spencer <markster@digium.com>
|
1999-11-21 02:26:43 +00:00
|
|
|
*
|
2005-08-30 18:32:10 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
1999-11-21 02:26:43 +00:00
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
2005-08-30 18:32:10 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
|
|
|
* \brief Generic File Format Support.
|
2007-11-22 00:53:49 +00:00
|
|
|
* Should be included by clients of the file handling routines.
|
|
|
|
* File service providers should instead include mod_format.h
|
1999-11-21 02:26:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ASTERISK_FILE_H
|
|
|
|
#define _ASTERISK_FILE_H
|
|
|
|
|
Start untangling header inclusion in a way that does not affect
build times - tested, there is no measureable difference before and
after this commit.
In this change:
use asterisk/compat.h to include a small set of system headers:
inttypes.h, unistd.h, stddef.h, stddint.h, sys/types.h, stdarg.h,
stdlib.h, alloca.h, stdio.h
Where available, the inclusion is conditional on HAVE_FOO_H as determined
by autoconf.
Normally, source files should not include any of the above system headers,
and instead use either "asterisk.h" or "asterisk/compat.h" which does it
better.
For the time being I have left alone second-level directories
(main/db1-ast, etc.).
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89333 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-16 20:04:58 +00:00
|
|
|
#ifdef HAVE_FCNTL_H
|
1999-11-21 02:26:43 +00:00
|
|
|
#include <fcntl.h>
|
Start untangling header inclusion in a way that does not affect
build times - tested, there is no measureable difference before and
after this commit.
In this change:
use asterisk/compat.h to include a small set of system headers:
inttypes.h, unistd.h, stddef.h, stddint.h, sys/types.h, stdarg.h,
stdlib.h, alloca.h, stdio.h
Where available, the inclusion is conditional on HAVE_FOO_H as determined
by autoconf.
Normally, source files should not include any of the above system headers,
and instead use either "asterisk.h" or "asterisk/compat.h" which does it
better.
For the time being I have left alone second-level directories
(main/db1-ast, etc.).
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89333 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-16 20:04:58 +00:00
|
|
|
#endif
|
1999-11-21 02:26:43 +00:00
|
|
|
|
2007-12-14 23:33:24 +00:00
|
|
|
#ifdef HAVE_MMAP
|
2007-12-15 11:34:33 +00:00
|
|
|
#include <sys/mman.h>
|
2007-12-14 23:33:24 +00:00
|
|
|
#endif
|
|
|
|
|
1999-11-21 02:26:43 +00:00
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2007-11-22 00:53:49 +00:00
|
|
|
struct ast_filestream;
|
|
|
|
struct ast_format;
|
1999-11-21 02:26:43 +00:00
|
|
|
|
2009-11-30 21:31:55 +00:00
|
|
|
/*! The maximum number of formats we expect to see in a format string */
|
|
|
|
#define AST_MAX_FORMATS 10
|
|
|
|
|
2005-01-15 23:48:12 +00:00
|
|
|
/*! Convenient for waiting */
|
2011-12-09 20:27:03 +00:00
|
|
|
#define AST_DIGIT_NONE ""
|
2005-02-09 17:15:35 +00:00
|
|
|
#define AST_DIGIT_ANY "0123456789#*ABCD"
|
2005-02-13 17:02:39 +00:00
|
|
|
#define AST_DIGIT_ANYNUM "0123456789"
|
1999-11-21 02:26:43 +00:00
|
|
|
|
2003-08-28 20:02:10 +00:00
|
|
|
#define SEEK_FORCECUR 10
|
2012-06-04 20:26:12 +00:00
|
|
|
|
|
|
|
/*! The type of event associated with a ast_waitstream_fr_cb invocation */
|
|
|
|
enum ast_waitstream_fr_cb_values {
|
|
|
|
AST_WAITSTREAM_CB_REWIND = 1,
|
|
|
|
AST_WAITSTREAM_CB_FASTFORWARD,
|
|
|
|
AST_WAITSTREAM_CB_START
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief callback used during dtmf controlled file playback to indicate
|
|
|
|
* location of playback in a file after rewinding or fastfowarding
|
|
|
|
* a file.
|
|
|
|
*/
|
|
|
|
typedef void (ast_waitstream_fr_cb)(struct ast_channel *chan, long ms, enum ast_waitstream_fr_cb_values val);
|
|
|
|
|
2013-07-03 17:58:45 +00:00
|
|
|
/*!
|
|
|
|
* \brief Streams a file
|
2001-12-27 11:07:33 +00:00
|
|
|
* \param c channel to stream the file to
|
|
|
|
* \param filename the name of the file you wish to stream, minus the extension
|
|
|
|
* \param preflang the preferred language you wish to have the file streamed to you in
|
|
|
|
* Prepares a channel for the streaming of a file. To start the stream, afterward do a ast_waitstream() on the channel
|
|
|
|
* Also, it will stop any existing streams on the channel.
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval 0 on success.
|
|
|
|
* \retval -1 on failure.
|
2001-12-27 11:07:33 +00:00
|
|
|
*/
|
2004-11-13 16:13:07 +00:00
|
|
|
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang);
|
1999-11-21 02:26:43 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief stream file until digit
|
|
|
|
* If the file name is non-empty, try to play it.
|
|
|
|
* \note If digits == "" then we can simply check for non-zero.
|
|
|
|
* \return 0 if success.
|
|
|
|
* \retval -1 if error.
|
|
|
|
* \retval digit if interrupted by a digit.
|
2006-04-21 20:28:32 +00:00
|
|
|
*/
|
2006-11-17 23:18:51 +00:00
|
|
|
int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char *digits);
|
2006-04-21 20:28:32 +00:00
|
|
|
|
2013-07-03 17:58:45 +00:00
|
|
|
/*!
|
|
|
|
* \brief Stops a stream
|
2007-11-29 00:07:32 +00:00
|
|
|
*
|
2001-12-27 11:07:33 +00:00
|
|
|
* \param c The channel you wish to stop playback on
|
2007-11-29 00:07:32 +00:00
|
|
|
*
|
2013-07-03 17:58:45 +00:00
|
|
|
* Stop playback of a stream
|
2007-11-29 00:07:32 +00:00
|
|
|
*
|
|
|
|
* \retval 0 always
|
|
|
|
*
|
|
|
|
* \note The channel does not need to be locked before calling this function.
|
2001-12-27 11:07:33 +00:00
|
|
|
*/
|
1999-11-21 02:26:43 +00:00
|
|
|
int ast_stopstream(struct ast_channel *c);
|
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Checks for the existence of a given file
|
2001-12-27 11:07:33 +00:00
|
|
|
* \param filename name of the file you wish to check, minus the extension
|
|
|
|
* \param fmt the format you wish to check (the extension)
|
|
|
|
* \param preflang (the preferred language you wisht to find the file in)
|
|
|
|
* See if a given file exists in a given format. If fmt is NULL, any format is accepted.
|
2011-02-03 16:22:10 +00:00
|
|
|
* \retval 0, false. The file does not exist
|
|
|
|
* \retval 1, true. The file does exist.
|
2001-12-27 11:07:33 +00:00
|
|
|
*/
|
2004-11-13 16:13:07 +00:00
|
|
|
int ast_fileexists(const char *filename, const char *fmt, const char *preflang);
|
1999-11-21 02:26:43 +00:00
|
|
|
|
2001-12-27 11:07:33 +00:00
|
|
|
/*!
|
2007-07-16 02:51:56 +00:00
|
|
|
* \brief Renames a file
|
2001-12-27 11:07:33 +00:00
|
|
|
* \param oldname the name of the file you wish to act upon (minus the extension)
|
|
|
|
* \param newname the name you wish to rename the file to (minus the extension)
|
|
|
|
* \param fmt the format of the file
|
|
|
|
* Rename a given file in a given format, or if fmt is NULL, then do so for all
|
2007-07-16 02:51:56 +00:00
|
|
|
* \return -1 on failure
|
2001-12-27 11:07:33 +00:00
|
|
|
*/
|
2004-11-13 16:13:07 +00:00
|
|
|
int ast_filerename(const char *oldname, const char *newname, const char *fmt);
|
1999-11-21 02:26:43 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Deletes a file
|
2001-12-27 11:07:33 +00:00
|
|
|
* \param filename name of the file you wish to delete (minus the extension)
|
2005-10-26 23:11:36 +00:00
|
|
|
* \param fmt of the file
|
2001-12-27 11:07:33 +00:00
|
|
|
* Delete a given file in a given format, or if fmt is NULL, then do so for all
|
|
|
|
*/
|
2004-11-13 16:13:07 +00:00
|
|
|
int ast_filedelete(const char *filename, const char *fmt);
|
1999-11-21 02:26:43 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Copies a file
|
2001-12-27 11:07:33 +00:00
|
|
|
* \param oldname name of the file you wish to copy (minus extension)
|
|
|
|
* \param newname name you wish the file to be copied to (minus extension)
|
|
|
|
* \param fmt the format of the file
|
|
|
|
* Copy a given file in a given format, or if fmt is NULL, then do so for all
|
|
|
|
*/
|
2004-11-13 16:13:07 +00:00
|
|
|
int ast_filecopy(const char *oldname, const char *newname, const char *fmt);
|
2001-06-13 20:36:52 +00:00
|
|
|
|
2013-01-22 15:16:20 +00:00
|
|
|
/*!
|
2007-07-16 02:51:56 +00:00
|
|
|
* \brief Waits for a stream to stop or digit to be pressed
|
2006-10-30 16:33:02 +00:00
|
|
|
* \param c channel to waitstream on
|
2001-12-27 11:07:33 +00:00
|
|
|
* \param breakon string of DTMF digits to break upon
|
|
|
|
* Begins playback of a stream...
|
2013-01-22 15:16:20 +00:00
|
|
|
* Wait for a stream to stop or for any one of a given digit to arrive,
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval 0 if the stream finishes
|
2013-01-22 15:16:20 +00:00
|
|
|
* \retval the character if it was interrupted by the channel.
|
|
|
|
* \retval -1 on error
|
2001-12-27 11:07:33 +00:00
|
|
|
*/
|
2005-06-05 15:04:43 +00:00
|
|
|
int ast_waitstream(struct ast_channel *c, const char *breakon);
|
1999-11-21 02:26:43 +00:00
|
|
|
|
2013-01-22 15:16:20 +00:00
|
|
|
/*!
|
|
|
|
* \brief Waits for a stream to stop or digit matching a valid one digit exten to be pressed
|
2006-10-30 16:33:02 +00:00
|
|
|
* \param c channel to waitstream on
|
2005-07-12 01:34:06 +00:00
|
|
|
* \param context string of context to match digits to break upon
|
|
|
|
* Begins playback of a stream...
|
2013-01-22 15:16:20 +00:00
|
|
|
* Wait for a stream to stop or for any one of a valid extension digit to arrive,
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval 0 if the stream finishes.
|
|
|
|
* \retval the character if it was interrupted.
|
|
|
|
* \retval -1 on error.
|
2005-07-12 01:34:06 +00:00
|
|
|
*/
|
|
|
|
int ast_waitstream_exten(struct ast_channel *c, const char *context);
|
|
|
|
|
2013-01-22 15:16:20 +00:00
|
|
|
/*!
|
|
|
|
* \brief Same as waitstream but allows stream to be forwarded or rewound
|
2006-10-30 16:33:02 +00:00
|
|
|
* \param c channel to waitstream on
|
2003-04-03 07:37:30 +00:00
|
|
|
* \param breakon string of DTMF digits to break upon
|
|
|
|
* \param forward DTMF digit to fast forward upon
|
|
|
|
* \param rewind DTMF digit to rewind upon
|
2003-04-09 02:10:29 +00:00
|
|
|
* \param ms How many miliseconds to skip forward/back
|
2003-04-03 07:37:30 +00:00
|
|
|
* Begins playback of a stream...
|
2013-01-22 15:16:20 +00:00
|
|
|
* Wait for a stream to stop or for any one of a given digit to arrive,
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval 0 if the stream finishes.
|
2013-01-22 15:16:20 +00:00
|
|
|
* \retval the character if it was interrupted,
|
|
|
|
* \retval the value of the control frame if it was interrupted by some other party,
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval -1 on error.
|
2003-04-03 07:37:30 +00:00
|
|
|
*/
|
2005-06-05 15:04:43 +00:00
|
|
|
int ast_waitstream_fr(struct ast_channel *c, const char *breakon, const char *forward, const char *rewind, int ms);
|
2003-04-03 07:37:30 +00:00
|
|
|
|
2013-01-22 15:16:20 +00:00
|
|
|
/*!
|
2012-06-04 20:26:12 +00:00
|
|
|
* \brief Same as waitstream_fr but allows a callback to be alerted when a user
|
|
|
|
* fastforwards or rewinds the file.
|
|
|
|
* \param c channel to waitstream on
|
|
|
|
* \param breakon string of DTMF digits to break upon
|
|
|
|
* \param forward DTMF digit to fast forward upon
|
|
|
|
* \param rewind DTMF digit to rewind upon
|
|
|
|
* \param ms How many milliseconds to skip forward/back
|
2013-01-22 15:16:20 +00:00
|
|
|
* \param cb to call when rewind or fastfoward occurs.
|
2012-06-04 20:26:12 +00:00
|
|
|
* Begins playback of a stream...
|
2013-01-22 15:16:20 +00:00
|
|
|
* Wait for a stream to stop or for any one of a given digit to arrive,
|
2012-06-04 20:26:12 +00:00
|
|
|
* \retval 0 if the stream finishes.
|
2013-01-22 15:16:20 +00:00
|
|
|
* \retval the character if it was interrupted,
|
|
|
|
* \retval the value of the control frame if it was interrupted by some other party,
|
2012-06-04 20:26:12 +00:00
|
|
|
* \retval -1 on error.
|
|
|
|
*/
|
|
|
|
int ast_waitstream_fr_w_cb(struct ast_channel *c,
|
|
|
|
const char *breakon,
|
|
|
|
const char *forward,
|
|
|
|
const char *rewind,
|
|
|
|
int ms,
|
|
|
|
ast_waitstream_fr_cb cb);
|
|
|
|
|
2007-09-26 06:31:05 +00:00
|
|
|
/*!
|
|
|
|
* Same as waitstream, but with audio output to fd and monitored fd checking.
|
|
|
|
*
|
|
|
|
* \return 1 if monfd is ready for reading
|
|
|
|
*/
|
2005-06-05 15:04:43 +00:00
|
|
|
int ast_waitstream_full(struct ast_channel *c, const char *breakon, int audiofd, int monfd);
|
2003-02-23 06:00:11 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Starts reading from a file
|
2004-02-25 22:31:51 +00:00
|
|
|
* \param filename the name of the file to read from
|
|
|
|
* \param type format of file you wish to read from
|
2003-12-19 18:06:29 +00:00
|
|
|
* \param comment comment to go with
|
2004-02-25 22:31:51 +00:00
|
|
|
* \param flags file flags
|
2003-12-19 18:06:29 +00:00
|
|
|
* \param check (unimplemented, hence negligible)
|
|
|
|
* \param mode Open mode
|
2004-02-25 22:31:51 +00:00
|
|
|
* Open an incoming file stream. flags are flags for the open() command, and
|
|
|
|
* if check is non-zero, then it will not read a file if there are any files that
|
2003-12-19 18:06:29 +00:00
|
|
|
* start with that name and have an extension
|
|
|
|
* Please note, this is a blocking function. Program execution will not return until ast_waitstream completes it's execution.
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval a struct ast_filestream on success.
|
|
|
|
* \retval NULL on failure.
|
2003-12-19 18:06:29 +00:00
|
|
|
*/
|
2004-11-13 16:13:07 +00:00
|
|
|
struct ast_filestream *ast_readfile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode);
|
2003-12-19 18:06:29 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Starts writing a file
|
2001-12-27 11:07:33 +00:00
|
|
|
* \param filename the name of the file to write to
|
|
|
|
* \param type format of file you wish to write out to
|
|
|
|
* \param comment comment to go with
|
2005-10-26 23:11:36 +00:00
|
|
|
* \param flags output file flags
|
2001-12-27 11:07:33 +00:00
|
|
|
* \param check (unimplemented, hence negligible)
|
|
|
|
* \param mode Open mode
|
|
|
|
* Create an outgoing file stream. oflags are flags for the open() command, and
|
|
|
|
* if check is non-zero, then it will not write a file if there are any files that
|
|
|
|
* start with that name and have an extension
|
|
|
|
* Please note, this is a blocking function. Program execution will not return until ast_waitstream completes it's execution.
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval a struct ast_filestream on success.
|
|
|
|
* \retval NULL on failure.
|
2001-12-27 11:07:33 +00:00
|
|
|
*/
|
2004-11-13 16:13:07 +00:00
|
|
|
struct ast_filestream *ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode);
|
1999-11-21 02:26:43 +00:00
|
|
|
|
2001-12-27 11:07:33 +00:00
|
|
|
/*!
|
2007-07-16 02:51:56 +00:00
|
|
|
* \brief Writes a frame to a stream
|
2001-12-27 11:07:33 +00:00
|
|
|
* \param fs filestream to write to
|
|
|
|
* \param f frame to write to the filestream
|
|
|
|
* Send a frame to a filestream -- note: does NOT free the frame, call ast_frfree manually
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval 0 on success.
|
|
|
|
* \retval -1 on failure.
|
2001-12-27 11:07:33 +00:00
|
|
|
*/
|
1999-11-21 02:26:43 +00:00
|
|
|
int ast_writestream(struct ast_filestream *fs, struct ast_frame *f);
|
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Closes a stream
|
2001-12-27 11:07:33 +00:00
|
|
|
* \param f filestream to close
|
|
|
|
* Close a playback or recording stream
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval 0 on success.
|
|
|
|
* \retval -1 on failure.
|
2001-12-27 11:07:33 +00:00
|
|
|
*/
|
1999-11-21 02:26:43 +00:00
|
|
|
int ast_closestream(struct ast_filestream *f);
|
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Opens stream for use in seeking, playing
|
2003-02-06 22:11:43 +00:00
|
|
|
* \param chan channel to work with
|
|
|
|
* \param filename to use
|
|
|
|
* \param preflang prefered language to use
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval a ast_filestream pointer if it opens the file.
|
|
|
|
* \retval NULL on error.
|
2003-02-06 22:11:43 +00:00
|
|
|
*/
|
2004-11-13 16:13:07 +00:00
|
|
|
struct ast_filestream *ast_openstream(struct ast_channel *chan, const char *filename, const char *preflang);
|
2003-06-29 03:24:39 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Opens stream for use in seeking, playing
|
2004-12-24 01:40:07 +00:00
|
|
|
* \param chan channel to work with
|
|
|
|
* \param filename to use
|
|
|
|
* \param preflang prefered language to use
|
|
|
|
* \param asis if set, don't clear generators
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval a ast_filestream pointer if it opens the file.
|
|
|
|
* \retval NULL on error.
|
2004-12-24 01:40:07 +00:00
|
|
|
*/
|
|
|
|
struct ast_filestream *ast_openstream_full(struct ast_channel *chan, const char *filename, const char *preflang, int asis);
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Opens stream for use in seeking, playing
|
2003-06-29 03:24:39 +00:00
|
|
|
* \param chan channel to work with
|
|
|
|
* \param filename to use
|
|
|
|
* \param preflang prefered language to use
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval a ast_filestream pointer if it opens the file.
|
|
|
|
* \retval NULL on error.
|
2003-06-29 03:24:39 +00:00
|
|
|
*/
|
2004-11-13 16:13:07 +00:00
|
|
|
struct ast_filestream *ast_openvstream(struct ast_channel *chan, const char *filename, const char *preflang);
|
2003-02-06 22:11:43 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Applys a open stream to a channel.
|
2003-02-06 22:11:43 +00:00
|
|
|
* \param chan channel to work
|
2005-10-26 23:11:36 +00:00
|
|
|
* \param s ast_filestream to apply
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval 0 on success.
|
|
|
|
* \retval -1 on failure.
|
2003-02-06 22:11:43 +00:00
|
|
|
*/
|
|
|
|
int ast_applystream(struct ast_channel *chan, struct ast_filestream *s);
|
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Play a open stream on a channel.
|
2005-10-26 23:11:36 +00:00
|
|
|
* \param s filestream to play
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval 0 on success.
|
|
|
|
* \retval -1 on failure.
|
2003-02-06 22:11:43 +00:00
|
|
|
*/
|
|
|
|
int ast_playstream(struct ast_filestream *s);
|
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Seeks into stream
|
2005-10-26 23:11:36 +00:00
|
|
|
* \param fs ast_filestream to perform seek on
|
2003-02-06 22:11:43 +00:00
|
|
|
* \param sample_offset numbers of samples to seek
|
|
|
|
* \param whence SEEK_SET, SEEK_CUR, SEEK_END
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval 0 on success.
|
|
|
|
* \retval -1 on failure.
|
2003-02-06 22:11:43 +00:00
|
|
|
*/
|
2006-02-20 23:35:12 +00:00
|
|
|
int ast_seekstream(struct ast_filestream *fs, off_t sample_offset, int whence);
|
2003-02-06 22:11:43 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Trunc stream at current location
|
2005-10-26 23:11:36 +00:00
|
|
|
* \param fs filestream to act on
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval 0 on success.
|
|
|
|
* \retval -1 on failure.
|
2003-02-06 22:11:43 +00:00
|
|
|
*/
|
|
|
|
int ast_truncstream(struct ast_filestream *fs);
|
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Fast forward stream ms
|
2005-10-26 23:11:36 +00:00
|
|
|
* \param fs filestream to act on
|
2003-02-06 22:11:43 +00:00
|
|
|
* \param ms milliseconds to move
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval 0 on success.
|
|
|
|
* \retval -1 on failure.
|
2003-02-06 22:11:43 +00:00
|
|
|
*/
|
2006-02-20 23:35:12 +00:00
|
|
|
int ast_stream_fastforward(struct ast_filestream *fs, off_t ms);
|
2003-02-06 22:11:43 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Rewind stream ms
|
2005-10-26 23:11:36 +00:00
|
|
|
* \param fs filestream to act on
|
2003-02-06 22:11:43 +00:00
|
|
|
* \param ms milliseconds to move
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval 0 on success.
|
|
|
|
* \retval -1 on failure.
|
2003-02-06 22:11:43 +00:00
|
|
|
*/
|
2006-02-20 23:35:12 +00:00
|
|
|
int ast_stream_rewind(struct ast_filestream *fs, off_t ms);
|
2003-02-06 22:11:43 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Tell where we are in a stream
|
2005-10-26 23:11:36 +00:00
|
|
|
* \param fs fs to act on
|
2007-07-16 02:51:56 +00:00
|
|
|
* \return a long as a sample offset into stream
|
2003-02-06 22:11:43 +00:00
|
|
|
*/
|
2006-02-20 23:35:12 +00:00
|
|
|
off_t ast_tellstream(struct ast_filestream *fs);
|
2003-02-06 22:11:43 +00:00
|
|
|
|
2014-09-16 16:32:49 +00:00
|
|
|
/*!
|
|
|
|
* \brief Return the sample rate of the stream's format
|
|
|
|
* \param fs fs to act on
|
|
|
|
* \return sample rate in Hz
|
|
|
|
*/
|
|
|
|
int ast_ratestream(struct ast_filestream *fs);
|
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Read a frame from a filestream
|
2005-10-26 23:11:36 +00:00
|
|
|
* \param s ast_filestream to act on
|
2007-07-16 02:51:56 +00:00
|
|
|
* \return a frame.
|
|
|
|
* \retval NULL if read failed.
|
2003-12-19 18:06:29 +00:00
|
|
|
*/
|
|
|
|
struct ast_frame *ast_readframe(struct ast_filestream *s);
|
|
|
|
|
2008-11-20 18:20:00 +00:00
|
|
|
/*! Initialize file stuff */
|
|
|
|
/*!
|
|
|
|
* Initializes all the various file stuff. Basically just registers the cli stuff
|
|
|
|
* Returns 0 all the time
|
|
|
|
*/
|
|
|
|
int ast_file_init(void);
|
|
|
|
|
|
|
|
|
|
|
|
#define AST_RESERVED_POINTERS 20
|
|
|
|
|
2009-11-30 21:31:55 +00:00
|
|
|
/*! Remove duplicate formats from a format string. */
|
|
|
|
/*!
|
|
|
|
* \param fmts a format string, this string will be modified
|
|
|
|
* \retval NULL error
|
|
|
|
* \return a pointer to the reduced format string, this is a pointer to fmts
|
|
|
|
*/
|
|
|
|
char *ast_format_str_reduce(char *fmts);
|
|
|
|
|
2013-06-24 13:49:20 +00:00
|
|
|
/*!
|
|
|
|
* \brief Get the ast_format associated with the given file extension
|
|
|
|
* \since 12
|
|
|
|
*
|
|
|
|
* \param file_ext The file extension for which to find the format
|
|
|
|
*
|
|
|
|
* \retval NULL if not found
|
|
|
|
* \retval A pointer to the ast_format associated with this file extension
|
|
|
|
*/
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
struct ast_format *ast_get_format_for_file_ext(const char *file_ext);
|
2013-06-24 13:49:20 +00:00
|
|
|
|
1999-11-21 02:26:43 +00:00
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-08-30 18:32:10 +00:00
|
|
|
#endif /* _ASTERISK_FILE_H */
|