Asterisk - The Open Source Telephony Project GIT-master-70eff7f
Loading...
Searching...
No Matches
Macros | Typedefs | Enumerations | Functions
file.h File Reference

Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h. More...

Go to the source code of this file.

Macros

#define AST_DIGIT_ANY   "0123456789#*ABCD"
 
#define AST_DIGIT_ANYNUM   "0123456789"
 
#define AST_DIGIT_NONE   ""
 
#define ast_file_read_dir(dir_name, on_file, obj)   ast_file_read_dirs(dir_name, on_file, obj, 1)
 Iterate over each file in a given directory.
 
#define AST_MAX_FORMATS   10
 
#define AST_RESERVED_POINTERS   20
 
#define SEEK_FORCECUR   10
 

Typedefs

typedef int(* ast_file_on_file) (const char *dir_name, const char *filename, void *obj)
 Callback called for each file found when reading directories.
 
typedef void() ast_waitstream_fr_cb(struct ast_channel *chan, long ms, enum ast_waitstream_fr_cb_values val)
 callback used during dtmf controlled file playback to indicate location of playback in a file after rewinding or fastforwarding a file.
 

Enumerations

enum  ast_waitstream_fr_cb_values { AST_WAITSTREAM_CB_REWIND = 1 , AST_WAITSTREAM_CB_FASTFORWARD , AST_WAITSTREAM_CB_START }
 

Functions

int ast_applystream (struct ast_channel *chan, struct ast_filestream *s)
 Applies a open stream to a channel.
 
int ast_closestream (struct ast_filestream *f)
 Closes a stream.
 
int ast_file_fdtemp (const char *path, char **filename, const char *template_name)
 Create a temporary file located at path.
 
int ast_file_init (void)
 
FILE * ast_file_mkftemp (char *template_name, mode_t mode)
 same as mkstemp, but return a FILE
 
int ast_file_read_dirs (const char *dir_name, ast_file_on_file on_file, void *obj, int max_depth)
 Recursively iterate through files and directories up to max_depth.
 
int ast_filecopy (const char *oldname, const char *newname, const char *fmt)
 Copies a file.
 
int ast_filedelete (const char *filename, const char *fmt)
 Deletes a file.
 
int ast_fileexists (const char *filename, const char *fmt, const char *preflang)
 Checks for the existence of a given file.
 
int ast_filerename (const char *oldname, const char *newname, const char *fmt)
 Renames a file.
 
char * ast_format_str_reduce (char *fmts)
 
int ast_get_extension_for_mime_type (const char *mime_type, char *buffer, size_t capacity)
 Get a suitable filename extension for the given MIME type.
 
struct ast_formatast_get_format_for_file_ext (const char *file_ext)
 Get the ast_format associated with the given file extension.
 
struct ast_filestreamast_openstream (struct ast_channel *chan, const char *filename, const char *preflang)
 Opens stream for use in seeking, playing.
 
struct ast_filestreamast_openstream_full (struct ast_channel *chan, const char *filename, const char *preflang, int asis)
 Opens stream for use in seeking, playing.
 
struct ast_filestreamast_openvstream (struct ast_channel *chan, const char *filename, const char *preflang)
 Opens stream for use in seeking, playing.
 
int ast_playstream (struct ast_filestream *s)
 Play a open stream on a channel.
 
int ast_ratestream (struct ast_filestream *fs)
 Return the sample rate of the stream's format.
 
struct ast_filestreamast_readfile (const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
 Starts reading from a file.
 
struct ast_frameast_readframe (struct ast_filestream *s)
 Read a frame from a filestream.
 
int ast_seekstream (struct ast_filestream *fs, off_t sample_offset, int whence)
 Seeks into stream.
 
int ast_stopstream (struct ast_channel *c)
 Stops a stream.
 
int ast_stream_and_wait (struct ast_channel *chan, const char *file, const char *digits)
 stream file until digit If the file name is non-empty, try to play it.
 
int ast_stream_fastforward (struct ast_filestream *fs, off_t ms)
 Fast forward stream ms.
 
int ast_stream_rewind (struct ast_filestream *fs, off_t ms)
 Rewind stream ms.
 
int ast_streamfile (struct ast_channel *c, const char *filename, const char *preflang)
 Streams a file.
 
off_t ast_tellstream (struct ast_filestream *fs)
 Tell where we are in a stream.
 
int ast_truncstream (struct ast_filestream *fs)
 Trunc stream at current location.
 
int ast_waitstream (struct ast_channel *c, const char *breakon)
 Waits for a stream to stop or digit to be pressed.
 
int ast_waitstream_exten (struct ast_channel *c, const char *context)
 Waits for a stream to stop or digit matching a valid one digit exten to be pressed.
 
int ast_waitstream_fr (struct ast_channel *c, const char *breakon, const char *forward, const char *rewind, int ms)
 Same as waitstream but allows stream to be forwarded or rewound.
 
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)
 Same as waitstream_fr but allows a callback to be alerted when a user fastforwards or rewinds the file.
 
int ast_waitstream_full (struct ast_channel *c, const char *breakon, int audiofd, int monfd)
 
struct ast_filestreamast_writefile (const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
 Starts writing a file.
 
int ast_writestream (struct ast_filestream *fs, struct ast_frame *f)
 Writes a frame to a stream.
 

Detailed Description

Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.

Definition in file file.h.

Macro Definition Documentation

◆ AST_DIGIT_ANY

#define AST_DIGIT_ANY   "0123456789#*ABCD"

Definition at line 48 of file file.h.

◆ AST_DIGIT_ANYNUM

#define AST_DIGIT_ANYNUM   "0123456789"

Definition at line 49 of file file.h.

◆ AST_DIGIT_NONE

#define AST_DIGIT_NONE   ""

Convenient for waiting

Definition at line 47 of file file.h.

◆ ast_file_read_dir

#define ast_file_read_dir (   dir_name,
  on_file,
  obj 
)    ast_file_read_dirs(dir_name, on_file, obj, 1)

Iterate over each file in a given directory.

Parameters
dir_namethe name of the directory to search
on_filecallback called on each file
objuser data object
Returns
-1
Return values
errnoon failure
0otherwise

Definition at line 203 of file file.h.

◆ AST_MAX_FORMATS

#define AST_MAX_FORMATS   10

The maximum number of formats we expect to see in a format string

Definition at line 44 of file file.h.

◆ AST_RESERVED_POINTERS

#define AST_RESERVED_POINTERS   20

Definition at line 441 of file file.h.

◆ SEEK_FORCECUR

#define SEEK_FORCECUR   10

Definition at line 51 of file file.h.

Typedef Documentation

◆ ast_file_on_file

typedef int(* ast_file_on_file) (const char *dir_name, const char *filename, void *obj)

Callback called for each file found when reading directories.

Parameters
dir_namethe name of the directory
filenamethe name of the file
objuser data object
Return values
non-zeroto stop reading, otherwise zero to continue
Note
dir_name is not processed by realpath or other functions, symbolic links are not resolved. This ensures dir_name always starts with the exact string originally passed to ast_file_read_dir or ast_file_read_dirs.

Definition at line 180 of file file.h.

◆ ast_waitstream_fr_cb

typedef void() ast_waitstream_fr_cb(struct ast_channel *chan, long ms, enum ast_waitstream_fr_cb_values val)

callback used during dtmf controlled file playback to indicate location of playback in a file after rewinding or fastforwarding a file.

Definition at line 65 of file file.h.

Enumeration Type Documentation

◆ ast_waitstream_fr_cb_values

The type of event associated with a ast_waitstream_fr_cb invocation

Enumerator
AST_WAITSTREAM_CB_REWIND 
AST_WAITSTREAM_CB_FASTFORWARD 
AST_WAITSTREAM_CB_START 

Definition at line 54 of file file.h.

54 {
58};
@ AST_WAITSTREAM_CB_FASTFORWARD
Definition file.h:56
@ AST_WAITSTREAM_CB_REWIND
Definition file.h:55
@ AST_WAITSTREAM_CB_START
Definition file.h:57

Function Documentation

◆ ast_applystream()

int ast_applystream ( struct ast_channel chan,
struct ast_filestream s 
)

Applies a open stream to a channel.

Parameters
chanchannel to work
sast_filestream to apply
Return values
0on success.
-1on failure.

Definition at line 1084 of file file.c.

1085{
1086 s->owner = chan;
1087 return 0;
1088}
struct ast_channel * owner
Definition mod_format.h:116

References ast_filestream::owner.

Referenced by ast_streamfile(), handle_getoption(), handle_recordfile(), handle_streamfile(), speech_streamfile(), and speech_streamfile().

◆ ast_closestream()

int ast_closestream ( struct ast_filestream f)

Closes a stream.

Parameters
ffilestream to close Close a playback or recording stream
Return values
0on success.
-1on failure.

Definition at line 1138 of file file.c.

1139{
1140 /* This used to destroy the filestream, but it now just decrements a refcount.
1141 * We close the stream in order to quit queuing frames now, because we might
1142 * change the writeformat, which could result in a subsequent write error, if
1143 * the format is different. */
1144 if (f == NULL) {
1145 return 0;
1146 }
1148 ao2_ref(f, -1);
1149 return 0;
1150}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
static void filestream_close(struct ast_filestream *f)
Definition file.c:403
#define NULL
Definition resample.c:96

References ao2_ref, ast_filestream::f, filestream_close(), and NULL.

Referenced by __ast_play_and_record(), ast_hangup(), ast_readfile(), ast_stopstream(), ast_writefile(), dictate_exec(), filehelper(), filestream_destructor(), gen_closestream(), handle_cli_file_convert(), handle_recordfile(), local_ast_moh_stop(), mixmonitor_ds_close_fs(), moh_files_next(), moh_files_release(), msg_create_from_file(), record_exec(), and recordthread().

◆ ast_file_fdtemp()

int ast_file_fdtemp ( const char *  path,
char **  filename,
const char *  template_name 
)

Create a temporary file located at path.

Note
The directory containing path will be created if it does not exist
This function assumes path does not end with a '/'
Parameters
pathThe directory path to create the file in
filenameFunction allocates memory and stores full filename (including path) here
template_namemkstemp template to use. Must end with XXXXXX.
Note
filename will need to be freed with ast_free if this function succeeds
Return values
-1on failure
Returns
file descriptor on success

Definition at line 203 of file file.c.

204{
205 int fd;
206
207 if (ast_asprintf(filename, "%s/%s", path, template_name) < 0) {
208 ast_log(LOG_ERROR, "Failed to set up temporary file path\n");
209 return -1;
210 }
211
212 ast_mkdir(path, 0644);
213
214 if ((fd = mkstemp(*filename)) < 0) {
215 ast_log(LOG_NOTICE, "Failed to create temporary file\n");
216 ast_free(*filename);
217 return -1;
218 }
219
220 return fd;
221}
#define ast_free(a)
Definition astmm.h:180
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition astmm.h:267
#define ast_log
Definition astobj2.c:42
#define LOG_ERROR
#define LOG_NOTICE
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition utils.c:2513

References ast_asprintf, ast_free, ast_log, ast_mkdir(), LOG_ERROR, and LOG_NOTICE.

◆ ast_file_init()

int ast_file_init ( void  )

Initialize file stuff

Initializes all the various file stuff. Basically just registers the cli stuff Returns 0 all the time

Provided by file.c

Definition at line 2093 of file file.c.

2094{
2099 return 0;
2100}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition clicompat.c:19
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition cli.h:265
static void file_shutdown(void)
Definition file.c:2086
static struct ast_cli_entry cli_file[]
Definition file.c:2082
struct stasis_message_type * ast_format_unregister_type(void)
Get the message type used for signaling a format unregistration.
struct stasis_message_type * ast_format_register_type(void)
Get the message type used for signaling a format registration.
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition stasis.h:1524
#define ARRAY_LEN(a)
Definition utils.h:706

◆ ast_file_mkftemp()

FILE * ast_file_mkftemp ( char *  template_name,
mode_t  mode 
)

same as mkstemp, but return a FILE

Parameters
template_nameThe template for the unique file name to generate. Modified in place to return the file name.
modeThe mode for file permissions
Returns
FILE handle to the temporary file on success or NULL if creation failed

Definition at line 188 of file file.c.

189{
190 FILE *p = NULL;
191 int pfd = mkstemp(template_name);
192 chmod(template_name, mode);
193 if (pfd > -1) {
194 p = fdopen(pfd, "w+");
195 if (!p) {
196 close(pfd);
197 pfd = -1;
198 }
199 }
200 return p;
201}

References ast_format_def::close, and NULL.

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), sendmail(), and sendpage().

◆ ast_file_read_dirs()

int ast_file_read_dirs ( const char *  dir_name,
ast_file_on_file  on_file,
void *  obj,
int  max_depth 
)

Recursively iterate through files and directories up to max_depth.

Parameters
dir_namethe name of the directory to search
on_filecallback called on each file
objuser data object
max_depthre-curse into sub-directories up to a given maximum (-1 = infinite)
Return values
-1on failure
errnoon failure
0otherwise

Definition at line 1301 of file file.c.

1302{
1303 int res;
1304
1305 errno = 0;
1306
1307#if !defined(__GLIBC__)
1309#endif
1310
1311 res = __ast_file_read_dirs(dir_name, on_file, obj, max_depth);
1312
1313#if !defined(__GLIBC__)
1315#endif
1316
1317 return res;
1318}
static ast_mutex_t read_dirs_lock
Lock to hold when iterating over directories.
Definition file.c:1298
static int __ast_file_read_dirs(const char *path, ast_file_on_file on_file, void *obj, int max_depth)
Definition file.c:1183
#define ast_mutex_unlock(a)
Definition lock.h:197
#define ast_mutex_lock(a)
Definition lock.h:196
int errno

References __ast_file_read_dirs(), ast_mutex_lock, ast_mutex_unlock, errno, and read_dirs_lock.

Referenced by _crypto_load_cert_store(), _crypto_load_crl_store(), ast_media_index_update_for_file(), AST_TEST_DEFINE(), crypto_load(), module_load_helper(), and stasis_app_stored_recording_find_all().

◆ ast_filecopy()

int ast_filecopy ( const char *  oldname,
const char *  newname,
const char *  fmt 
)

Copies a file.

Parameters
oldnamename of the file you wish to copy (minus extension)
newnamename you wish the file to be copied to (minus extension)
fmtthe format of the file Copy a given file in a given format, or if fmt is NULL, then do so for all

Definition at line 1178 of file file.c.

1179{
1180 return filehelper(filename, filename2, fmt, ACTION_COPY);
1181}
static int filehelper(const char *filename, const void *arg2, const char *fmt, const enum file_action action)
Definition file.c:560
@ ACTION_COPY
Definition file.c:546

References ACTION_COPY, filehelper(), ast_filestream::filename, and ast_filestream::fmt.

Referenced by copy_plain_file(), msg_create_from_file(), stasis_app_stored_recording_copy(), and vm_forwardoptions().

◆ ast_filedelete()

int ast_filedelete ( const char *  filename,
const char *  fmt 
)

Deletes a file.

Parameters
filenamename of the file you wish to delete (minus the extension)
fmtof the file Delete a given file in a given format, or if fmt is NULL, then do so for all

Definition at line 1168 of file file.c.

1169{
1170 return filehelper(filename, NULL, fmt, ACTION_DELETE);
1171}
@ ACTION_DELETE
Definition file.c:543

References ACTION_DELETE, filehelper(), ast_filestream::filename, ast_filestream::fmt, and NULL.

Referenced by __ast_play_and_record(), announce_thread(), async_delete_name_rec_task(), conf_free(), conf_rec_name(), conf_run(), confbridge_exec(), dial_exec_full(), handle_cli_file_convert(), leave_voicemail(), leave_voicemail(), mixmonitor_thread(), msg_create_from_file(), play_record_review(), record_exec(), recording_cancel(), setup_privacy_args(), vm_delete(), and vm_delete().

◆ ast_fileexists()

int ast_fileexists ( const char *  filename,
const char *  fmt,
const char *  preflang 
)

Checks for the existence of a given file.

Parameters
filenamename of the file you wish to check, minus the extension
fmtthe format you wish to check (the extension)
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.
Return values
0The file does not exist
1The file does exist.

Definition at line 1156 of file file.c.

1157{
1158 char *buf;
1159 int buflen;
1160
1161 if (preflang == NULL)
1162 preflang = "";
1163 buflen = strlen(preflang) + strlen(filename) + 4; /* room for everything */
1164 buf = ast_alloca(buflen);
1165 return fileexists_core(filename, fmt, preflang, buf, buflen, NULL) ? 1 : 0;
1166}
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition astmm.h:288
char buf[BUFSIZE]
Definition eagi_proxy.c:66
static int fileexists_core(const char *filename, const char *fmt, const char *preflang, char *buf, int buflen, struct ast_format_cap *result_cap)
helper routine to locate a file with a given format and language preference.
Definition file.c:760

References ast_alloca, buf, fileexists_core(), ast_filestream::filename, ast_filestream::fmt, and NULL.

Referenced by announce_thread(), app_exec(), ast_get_character_str(), ast_get_digit_str(), ast_get_phonetic_str(), common_exec(), conf_run(), dial_exec_full(), eivr_comm(), forward_message(), get_folder(), invent_message(), invent_message(), leave_voicemail(), leave_voicemail(), meetme_menu_admin_extended(), minivm_delete_exec(), moh_files_next(), msg_create_from_file(), page_exec(), play_file(), play_message(), play_message_by_id_helper(), play_message_callerid(), readexten_exec(), record_exec(), retrydial_exec(), sayname(), setup_privacy_args(), sound_file_exists(), stasis_app_control_record(), vm_intro(), vm_msg_play(), vm_newuser_setup(), vm_options(), and vm_tempgreeting().

◆ ast_filerename()

int ast_filerename ( const char *  oldname,
const char *  newname,
const char *  fmt 
)

Renames a file.

Parameters
oldnamethe name of the file you wish to act upon (minus the extension)
newnamethe name you wish to rename the file to (minus the extension)
fmtthe format of the file Rename a given file in a given format, or if fmt is NULL, then do so for all
Return values
-1on failure

Definition at line 1173 of file file.c.

1174{
1175 return filehelper(filename, filename2, fmt, ACTION_RENAME);
1176}
@ ACTION_RENAME
Definition file.c:544

References ACTION_RENAME, filehelper(), ast_filestream::filename, and ast_filestream::fmt.

Referenced by __ast_play_and_record(), forward_message(), leave_voicemail(), msg_create_from_file(), play_record_review(), rename_file(), and vm_forwardoptions().

◆ ast_format_str_reduce()

char * ast_format_str_reduce ( char *  fmts)

Remove duplicate formats from a format string.

Parameters
fmtsa format string, this string will be modified
Return values
NULLerror
Returns
a pointer to the reduced format string, this is a pointer to fmts

Definition at line 1936 of file file.c.

1937{
1938 struct ast_format_def *f;
1939 struct ast_format_def *fmts_ptr[AST_MAX_FORMATS];
1940 char *fmts_str[AST_MAX_FORMATS];
1941 char *stringp, *type;
1942 char *orig = fmts;
1943 int i, j, x, first, found = 0;
1944 int len = strlen(fmts) + 1;
1945 int res;
1946
1947 if (AST_RWLIST_RDLOCK(&formats)) {
1948 ast_log(LOG_WARNING, "Unable to lock format list\n");
1949 return NULL;
1950 }
1951
1952 stringp = ast_strdupa(fmts);
1953
1954 for (x = 0; (type = strsep(&stringp, "|")) && x < AST_MAX_FORMATS; x++) {
1956 if (exts_compare(f->exts, type)) {
1957 found = 1;
1958 break;
1959 }
1960 }
1961
1962 fmts_str[x] = type;
1963 if (found) {
1964 fmts_ptr[x] = f;
1965 } else {
1966 fmts_ptr[x] = NULL;
1967 }
1968 }
1970
1971 first = 1;
1972 for (i = 0; i < x; i++) {
1973 /* ignore invalid entries */
1974 if (!fmts_ptr[i]) {
1975 ast_log(LOG_WARNING, "ignoring unknown format '%s'\n", fmts_str[i]);
1976 continue;
1977 }
1978
1979 /* special handling for the first entry */
1980 if (first) {
1981 res = snprintf(fmts, len, "%s", fmts_str[i]);
1982 fmts += res;
1983 len -= res;
1984 first = 0;
1985 continue;
1986 }
1987
1988 found = 0;
1989 for (j = 0; j < i; j++) {
1990 /* this is a duplicate */
1991 if (fmts_ptr[j] == fmts_ptr[i]) {
1992 found = 1;
1993 break;
1994 }
1995 }
1996
1997 if (!found) {
1998 res = snprintf(fmts, len, "|%s", fmts_str[i]);
1999 fmts += res;
2000 len -= res;
2001 }
2002 }
2003
2004 if (first) {
2005 ast_log(LOG_WARNING, "no known formats found in format list (%s)\n", orig);
2006 return NULL;
2007 }
2008
2009 return orig;
2010}
struct sla_ringing_trunk * first
Definition app_sla.c:338
char * strsep(char **str, const char *delims)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
static const char type[]
#define exts_compare(list, type)
Definition file.c:397
#define AST_MAX_FORMATS
Definition file.h:44
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define LOG_WARNING
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition linkedlists.h:78
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
#define AST_RWLIST_TRAVERSE
Each supported file format is described by the following structure.
Definition mod_format.h:43
struct ast_format_def::@252 list
char exts[80]
Definition mod_format.h:45
Definition file.c:70

References ast_log, AST_MAX_FORMATS, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdupa, ast_format_def::exts, exts_compare, first, len(), ast_format_def::list, LOG_WARNING, NULL, strsep(), and type.

Referenced by actual_load_config(), and AST_TEST_DEFINE().

◆ ast_get_extension_for_mime_type()

int ast_get_extension_for_mime_type ( const char *  mime_type,
char *  buffer,
size_t  capacity 
)

Get a suitable filename extension for the given MIME type.

Parameters
mime_typeThe MIME type for which to find extensions
bufferA pointer to a buffer to receive the extension
capacityThe size of 'buffer' in bytes
Return values
1if an extension was found for the provided MIME type
0if the MIME type was not found

Definition at line 2061 of file file.c.

2062{
2063 struct ast_format_def *f;
2065
2066 ast_assert(buffer && capacity);
2067
2069 if (type_in_list(f->mime_types, mime_type, strcasecmp)) {
2070 size_t item_len = strcspn(f->exts, "|");
2071 size_t bytes_written = snprintf(buffer, capacity, ".%.*s", (int) item_len, f->exts);
2072 if (bytes_written < capacity) {
2073 /* Only return success if we didn't truncate */
2074 return 1;
2075 }
2076 }
2077 }
2078
2079 return 0;
2080}
ast_mutex_t lock
Definition app_sla.c:337
static int type_in_list(const char *list, const char *type, int(*cmp)(const char *s1, const char *s2))
Definition file.c:384
#define SCOPED_RDLOCK(varname, lock)
scoped lock specialization for read locks
Definition lock.h:601
char mime_types[80]
Definition mod_format.h:47
ast_rwlock_t lock
Definition file.c:70
#define ast_assert(a)
Definition utils.h:779

References ast_assert, AST_RWLIST_TRAVERSE, ast_format_def::exts, ast_format_def::list, lock, formats::lock, ast_format_def::mime_types, SCOPED_RDLOCK, and type_in_list().

Referenced by derive_extension_from_mime_type().

◆ ast_get_format_for_file_ext()

struct ast_format * ast_get_format_for_file_ext ( const char *  file_ext)

Get the ast_format associated with the given file extension.

Since
12
Parameters
file_extThe file extension for which to find the format
Return values
NULLif not found
Returns
A pointer to the ast_format associated with this file extension

Definition at line 2048 of file file.c.

2049{
2050 struct ast_format_def *f;
2053 if (exts_compare(f->exts, file_ext)) {
2054 return f->format;
2055 }
2056 }
2057
2058 return NULL;
2059}
struct ast_format * format
Definition mod_format.h:48

References AST_RWLIST_TRAVERSE, ast_format_def::exts, exts_compare, ast_format_def::format, ast_format_def::list, lock, formats::lock, NULL, and SCOPED_RDLOCK.

Referenced by ast_ari_bridges_record(), ast_ari_channels_record(), ast_ari_recordings_get_stored_file(), file_extension_from_string(), is_recording(), and process_media_file().

◆ ast_openstream()

struct ast_filestream * ast_openstream ( struct ast_channel chan,
const char *  filename,
const char *  preflang 
)

Opens stream for use in seeking, playing.

Parameters
chanchannel to work with
filenameto use
preflangprefered language to use
Returns
a ast_filestream pointer if it opens the file.
Return values
NULLon error.

Definition at line 864 of file file.c.

865{
866 return openstream_internal(chan, filename, preflang, 0, 0);
867}
static struct ast_filestream * openstream_internal(struct ast_channel *chan, const char *filename, const char *preflang, int asis, int quiet)
Definition file.c:809

References ast_filestream::filename, and openstream_internal().

Referenced by ast_streamfile(), dictate_exec(), handle_getoption(), handle_streamfile(), speech_streamfile(), and speech_streamfile().

◆ ast_openstream_full()

struct ast_filestream * ast_openstream_full ( struct ast_channel chan,
const char *  filename,
const char *  preflang,
int  asis 
)

Opens stream for use in seeking, playing.

Parameters
chanchannel to work with
filenameto use
preflangprefered language to use
asisif set, don't clear generators
Return values
aast_filestream pointer if it opens the file.
NULLon error.

Definition at line 869 of file file.c.

871{
872 return openstream_internal(chan, filename, preflang, asis, 0);
873}

References ast_filestream::filename, and openstream_internal().

Referenced by gen_nextfile(), and moh_files_next().

◆ ast_openvstream()

struct ast_filestream * ast_openvstream ( struct ast_channel chan,
const char *  filename,
const char *  preflang 
)

Opens stream for use in seeking, playing.

Parameters
chanchannel to work with
filenameto use
preflangprefered language to use
Returns
a ast_filestream pointer if it opens the file.
Return values
NULLon error.

Definition at line 875 of file file.c.

877{
878 /* As above, but for video. But here we don't have translators
879 * so we must enforce a format.
880 */
881 struct ast_format_cap *nativeformats, *tmp_cap;
882 char *buf;
883 int buflen;
884 int i, fd;
885
886 if (preflang == NULL) {
887 preflang = "";
888 }
889 buflen = strlen(preflang) + strlen(filename) + 4;
890 buf = ast_alloca(buflen);
891
892 ast_channel_lock(chan);
893 nativeformats = ao2_bump(ast_channel_nativeformats(chan));
894 ast_channel_unlock(chan);
895
896 /* is the channel capable of video without translation ?*/
897 if (!ast_format_cap_has_type(nativeformats, AST_MEDIA_TYPE_VIDEO)) {
898 ao2_cleanup(nativeformats);
899 return NULL;
900 }
902 ao2_cleanup(nativeformats);
903 return NULL;
904 }
905 /* Video is supported, so see what video formats exist for this file */
906 if (!fileexists_core(filename, NULL, preflang, buf, buflen, tmp_cap)) {
907 ao2_ref(tmp_cap, -1);
908 ao2_cleanup(nativeformats);
909 return NULL;
910 }
911
912 /* iterate over file formats and pick the first one compatible with the channel's native formats */
913 for (i = 0; i < ast_format_cap_count(tmp_cap); ++i) {
914 struct ast_format *format = ast_format_cap_get_format(tmp_cap, i);
915
916 if ((ast_format_get_type(format) != AST_MEDIA_TYPE_VIDEO) ||
917 !ast_format_cap_iscompatible(nativeformats, tmp_cap)) {
918 ao2_ref(format, -1);
919 continue;
920 }
921
922 fd = filehelper(buf, chan, ast_format_get_name(format), ACTION_OPEN);
923 if (fd >= 0) {
924 ao2_ref(format, -1);
925 ao2_ref(tmp_cap, -1);
926 ao2_cleanup(nativeformats);
927 return ast_channel_vstream(chan);
928 }
929 ast_log(LOG_WARNING, "File %s has video but couldn't be opened\n", filename);
930 ao2_ref(format, -1);
931 }
932 ao2_ref(tmp_cap, -1);
933 ao2_cleanup(nativeformats);
934
935 return NULL;
936}
#define ao2_cleanup(obj)
Definition astobj2.h:1934
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition astobj2.h:480
#define ast_channel_lock(chan)
Definition channel.h:2983
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
struct ast_filestream * ast_channel_vstream(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition channel.h:2984
@ AST_MEDIA_TYPE_VIDEO
Definition codec.h:33
@ ACTION_OPEN
Definition file.c:545
enum ast_media_type ast_format_get_type(const struct ast_format *format)
Get the media type of a format.
Definition format.c:354
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition format.c:334
struct ast_format * ast_format_cap_get_format(const struct ast_format_cap *cap, int position)
Get the format at a specific index.
Definition format_cap.c:408
@ AST_FORMAT_CAP_FLAG_DEFAULT
Definition format_cap.h:38
int ast_format_cap_has_type(const struct ast_format_cap *cap, enum ast_media_type type)
Find out if the capabilities structure has any formats of a specific type.
Definition format_cap.c:621
int ast_format_cap_iscompatible(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2)
Determine if any joint capabilities exist between two capabilities structures.
Definition format_cap.c:661
#define ast_format_cap_alloc(flags)
Allocate a new ast_format_cap structure.
Definition format_cap.h:49
size_t ast_format_cap_count(const struct ast_format_cap *cap)
Get the number of formats present within the capabilities structure.
Definition format_cap.c:403
Format capabilities structure, holds formats + preference order + etc.
Definition format_cap.c:54
Definition of a media format.
Definition format.c:43

References ACTION_OPEN, ao2_bump, ao2_cleanup, ao2_ref, ast_alloca, ast_channel_lock, ast_channel_nativeformats(), ast_channel_unlock, ast_channel_vstream(), ast_format_cap_alloc, ast_format_cap_count(), AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_get_format(), ast_format_cap_has_type(), ast_format_cap_iscompatible(), ast_format_get_name(), ast_format_get_type(), ast_log, AST_MEDIA_TYPE_VIDEO, buf, fileexists_core(), filehelper(), LOG_WARNING, and NULL.

Referenced by ast_streamfile(), handle_getoption(), and handle_streamfile().

◆ ast_playstream()

int ast_playstream ( struct ast_filestream s)

Play a open stream on a channel.

Parameters
sfilestream to play
Return values
0on success.
-1on failure.

Definition at line 1090 of file file.c.

1091{
1092 enum fsread_res res;
1093
1095 res = ast_readaudio_callback(s);
1096 else
1097 res = ast_readvideo_callback(s);
1098
1099 return (res == FSREAD_FAILURE) ? -1 : 0;
1100}
@ AST_MEDIA_TYPE_AUDIO
Definition codec.h:32
fsread_res
Definition file.c:970
@ FSREAD_FAILURE
Definition file.c:971
static enum fsread_res ast_readaudio_callback(struct ast_filestream *s)
Definition file.c:978
static enum fsread_res ast_readvideo_callback(struct ast_filestream *s)
Definition file.c:1041
struct ast_format_def * fmt
Definition mod_format.h:103

References ast_format_get_type(), AST_MEDIA_TYPE_AUDIO, ast_readaudio_callback(), ast_readvideo_callback(), ast_filestream::fmt, ast_format_def::format, and FSREAD_FAILURE.

Referenced by ast_streamfile(), handle_getoption(), handle_streamfile(), speech_streamfile(), and speech_streamfile().

◆ ast_ratestream()

int ast_ratestream ( struct ast_filestream fs)

Return the sample rate of the stream's format.

Parameters
fsfs to act on
Returns
sample rate in Hz

Definition at line 1117 of file file.c.

1118{
1120}
unsigned int ast_format_get_sample_rate(const struct ast_format *format)
Get the sample rate of a media format.
Definition format.c:379

References ast_format_get_sample_rate(), ast_filestream::fmt, and ast_format_def::format.

Referenced by msg_create_from_file().

◆ ast_readfile()

struct ast_filestream * ast_readfile ( const char *  filename,
const char *  type,
const char *  comment,
int  flags,
int  check,
mode_t  mode 
)

Starts reading from a file.

Parameters
filenamethe name of the file to read from
typeformat of file you wish to read from
commentcomment to go with
flagsfile flags
check(unimplemented, hence negligible)
modeOpen mode 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 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.
Returns
a struct ast_filestream on success.
Return values
NULLon failure.

Definition at line 1413 of file file.c.

1414{
1415 FILE *bfile;
1416 struct ast_format_def *f;
1417 struct ast_filestream *fs = NULL;
1418 char *fn;
1419 int format_found = 0;
1420
1422
1423 AST_RWLIST_TRAVERSE(&formats, f, list) {
1424 fs = NULL;
1425 if (!exts_compare(f->exts, type))
1426 continue;
1427 else
1428 format_found = 1;
1429
1431 if (!fn) {
1432 continue;
1433 }
1434 errno = 0;
1435 bfile = fopen(fn, "r");
1436
1437 if (!bfile || (fs = get_filestream(f, bfile)) == NULL || open_wrapper(fs) ) {
1438 ast_log(LOG_WARNING, "Unable to open %s\n", fn);
1439 if (fs) {
1440 ast_closestream(fs);
1441 }
1442 fs = NULL;
1443 bfile = NULL;
1444 ast_free(fn);
1445 break;
1446 }
1447 /* found it */
1448 fs->trans = NULL;
1449 fs->fmt = f;
1450 fs->flags = flags;
1451 fs->mode = mode;
1453 fs->vfs = NULL;
1454 ast_free(fn);
1455 break;
1456 }
1457
1459 if (!format_found)
1460 ast_log(LOG_WARNING, "No such format '%s'\n", type);
1461
1462 return fs;
1463}
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
static char * build_filename(const char *filename, const char *ext)
construct a filename. Absolute pathnames are preserved, relative names are prefixed by the sounds/ di...
Definition file.c:360
int ast_closestream(struct ast_filestream *f)
Closes a stream.
Definition file.c:1138
static int open_wrapper(struct ast_filestream *s)
Definition file.c:536
static struct ast_filestream * get_filestream(struct ast_format_def *fmt, FILE *bfile)
Definition file.c:474
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
Definition mod_format.h:101
struct ast_filestream * vfs
Definition mod_format.h:110
struct ast_trans_pvt * trans
Definition mod_format.h:112

References ast_closestream(), ast_free, ast_log, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, build_filename(), errno, exts_compare, ast_filestream::f, ast_filestream::filename, ast_filestream::flags, ast_filestream::fmt, get_filestream(), LOG_WARNING, ast_filestream::mode, NULL, open_wrapper(), ast_filestream::trans, type, and ast_filestream::vfs.

Referenced by __ast_play_and_record(), handle_cli_file_convert(), and msg_create_from_file().

◆ ast_readframe()

struct ast_frame * ast_readframe ( struct ast_filestream s)

Read a frame from a filestream.

Parameters
sast_filestream to act on
Returns
a frame.
Return values
NULLif read failed.

Definition at line 963 of file file.c.

964{
965 int whennext = 0;
966
967 return read_frame(s, &whennext);
968}
static struct ast_frame * read_frame(struct ast_filestream *s, int *whennext)
Definition file.c:938

References read_frame().

Referenced by __ast_play_and_record(), dictate_exec(), gen_readframe(), handle_cli_file_convert(), and moh_files_readframe().

◆ ast_seekstream()

int ast_seekstream ( struct ast_filestream fs,
off_t  sample_offset,
int  whence 
)

Seeks into stream.

Parameters
fsast_filestream to perform seek on
sample_offsetnumbers of samples to seek
whenceSEEK_SET, SEEK_CUR, SEEK_END
Return values
0on success.
-1on failure.

Definition at line 1102 of file file.c.

1103{
1104 return fs->fmt->seek(fs, sample_offset, whence);
1105}
int(* seek)(struct ast_filestream *, off_t, int)
Definition mod_format.h:68

References ast_filestream::fmt, and ast_format_def::seek.

Referenced by ast_stream_fastforward(), ast_stream_rewind(), ast_streamfile(), control_streamfile(), dictate_exec(), handle_getoption(), handle_recordfile(), handle_streamfile(), moh_files_next(), msg_create_from_file(), and speech_streamfile().

◆ ast_stopstream()

int ast_stopstream ( struct ast_channel c)

Stops a stream.

Parameters
cThe channel you wish to stop playback on

Stop playback of a stream

Return values
0always
Note
The channel does not need to be locked before calling this function.
Examples
app_skel.c.

Definition at line 223 of file file.c.

224{
225 struct ast_json * cel_event = NULL;
226
227 ast_channel_lock(tmp);
228
229 /* Stop a running stream if there is one */
230 if (ast_channel_stream(tmp)) {
233
234 cel_event = ast_json_pack("{ s: s }", "event", "FILE_STREAM_END");
235 if (cel_event) {
237 }
238
240 ast_log(LOG_WARNING, "Unable to restore format back to %s\n", ast_format_get_name(ast_channel_oldwriteformat(tmp)));
241 }
242 ast_json_unref(cel_event);
243
244 /* Stop the video stream too */
245 if (ast_channel_vstream(tmp) != NULL) {
248 }
249
251
252 return 0;
253}
void ast_cel_publish_event(struct ast_channel *chan, enum ast_cel_event_type event_type, struct ast_json *blob)
Publish a CEL event.
Definition cel.c:1762
@ AST_CEL_STREAM_END
A stream ended.
Definition cel.h:84
void ast_channel_stream_set(struct ast_channel *chan, struct ast_filestream *value)
struct ast_format * ast_channel_oldwriteformat(struct ast_channel *chan)
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
Definition channel.c:5826
struct ast_filestream * ast_channel_stream(const struct ast_channel *chan)
void ast_channel_vstream_set(struct ast_channel *chan, struct ast_filestream *value)
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition json.c:73
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition json.c:612
Abstract JSON element (object, array, string, int, ...).

References ast_cel_publish_event(), AST_CEL_STREAM_END, ast_channel_lock, ast_channel_oldwriteformat(), ast_channel_stream(), ast_channel_stream_set(), ast_channel_unlock, ast_channel_vstream(), ast_channel_vstream_set(), ast_closestream(), ast_format_get_name(), ast_json_pack(), ast_json_unref(), ast_log, ast_set_write_format(), LOG_WARNING, and NULL.

Referenced by action_playback_and_continue(), adsi_transmit_message_full(), agent_alert(), announce_to_dial(), ast_play_and_wait(), ast_readstring_full(), ast_say_enumeration_full_da(), ast_say_enumeration_full_de(), ast_say_enumeration_full_dr(), ast_say_enumeration_full_en(), ast_say_enumeration_full_he(), ast_say_enumeration_full_is(), ast_say_enumeration_full_ps(), ast_say_enumeration_full_vi(), ast_say_number_full_cs(), ast_say_number_full_da(), ast_say_number_full_de(), ast_say_number_full_dr(), ast_say_number_full_en_GB(), ast_say_number_full_es(), ast_say_number_full_fr(), ast_say_number_full_gr(), ast_say_number_full_he(), ast_say_number_full_hu(), ast_say_number_full_is(), ast_say_number_full_it(), ast_say_number_full_ja(), ast_say_number_full_ka(), ast_say_number_full_nl(), ast_say_number_full_no(), ast_say_number_full_ps(), ast_say_number_full_pt(), ast_say_number_full_ru(), ast_say_number_full_se(), ast_say_number_full_th(), ast_say_number_full_ur(), ast_say_number_full_vi(), ast_say_number_full_zh(), ast_stream_and_wait(), background_detect_exec(), conf_exec(), conf_run(), control_streamfile(), dial_exec_full(), directory_exec(), grab_transfer(), handle_getoption(), handle_speechrecognize(), handle_streamfile(), isAnsweringMachine(), ivr_dispatch(), leave_voicemail(), meetme_menu_admin(), meetme_menu_admin_extended(), minivm_greet_exec(), mp3_exec(), openstream_internal(), pbx_builtin_background(), pl_odtworz_plik(), play_file(), play_file(), play_files_helper(), play_mailbox_owner(), playback_exec(), queue_exec(), read_exec(), readexten_exec(), recordthread(), s_streamwait3(), say_filenames(), select_item_seq(), send_waveform_to_channel(), speech_background(), vm_authenticate(), vm_execmain(), wait_for_winner(), waitstream_core(), and zapateller_exec().

◆ ast_stream_and_wait()

int ast_stream_and_wait ( struct ast_channel chan,
const char *  file,
const char *  digits 
)

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.
If a failure is encountered, the stream will be closed before returning.
Return values
0if success.
-1if error.
digitif interrupted by a digit.
Examples
app_skel.c.

Definition at line 1920 of file file.c.

1921{
1922 int res = 0;
1923 if (!ast_strlen_zero(file)) {
1924 res = ast_streamfile(chan, file, ast_channel_language(chan));
1925 if (!res) {
1926 res = ast_waitstream(chan, digits);
1927 }
1928 }
1929 if (res == -1) {
1930 ast_stopstream(chan);
1931 }
1932
1933 return res;
1934}
const char * ast_channel_language(const struct ast_channel *chan)
int ast_streamfile(struct ast_channel *chan, const char *filename, const char *preflang)
Streams a file.
Definition file.c:1320
int ast_stopstream(struct ast_channel *tmp)
Stops a stream.
Definition file.c:223
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition file.c:1882
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65

References ast_channel_language(), ast_stopstream(), ast_streamfile(), ast_strlen_zero(), and ast_waitstream().

Referenced by __ast_play_and_record(), action_playback(), action_toggle_mute_participants(), agent_alert(), agent_login_exec(), announce_user_count(), app_exec(), ast_bridge_channel_playfile(), ast_pickup_call(), ast_record_review(), bridge_features_duration_callback(), confbridge_exec(), directory_exec(), forward_message(), grab_transfer(), invent_message(), ivr_dispatch(), join_conference_bridge(), leave_voicemail(), limits_interval_playback(), mixmonitor_thread(), park_app_exec(), parked_call_app_exec(), play_file(), play_files_helper(), play_mailbox_owner(), play_message_callerid(), play_prompt_to_user(), play_record_review(), play_record_review(), playback_common(), record_exec(), sayname(), select_item_seq(), setup_mixmonitor_ds(), stream_failsound(), vm_forwardoptions(), vmsayname_exec(), and wait_file2().

◆ ast_stream_fastforward()

int ast_stream_fastforward ( struct ast_filestream fs,
off_t  ms 
)

Fast forward stream ms.

Parameters
fsfilestream to act on
msmilliseconds to move
Return values
0on success.
-1on failure.

Definition at line 1122 of file file.c.

1123{
1124 return ast_seekstream(fs, ms * DEFAULT_SAMPLES_PER_MS, SEEK_CUR);
1125}
#define DEFAULT_SAMPLES_PER_MS
Definition asterisk.h:49
int ast_seekstream(struct ast_filestream *fs, off_t sample_offset, int whence)
Seeks into stream.
Definition file.c:1102

References ast_seekstream(), and DEFAULT_SAMPLES_PER_MS.

Referenced by waitstream_control().

◆ ast_stream_rewind()

int ast_stream_rewind ( struct ast_filestream fs,
off_t  ms 
)

Rewind stream ms.

Parameters
fsfilestream to act on
msmilliseconds to move
Return values
0on success.
-1on failure.

Definition at line 1127 of file file.c.

1128{
1129 off_t offset = ast_tellstream(fs);
1130 if (ms * DEFAULT_SAMPLES_PER_MS > offset) {
1131 /* Don't even bother asking the file format to seek to a negative offset... */
1132 ast_debug(1, "Restarting, rather than seeking to negative offset %ld\n", (long) (offset - (ms * DEFAULT_SAMPLES_PER_MS)));
1133 return ast_seekstream(fs, 0, SEEK_SET);
1134 }
1135 return ast_seekstream(fs, -ms * DEFAULT_SAMPLES_PER_MS, SEEK_CUR);
1136}
off_t ast_tellstream(struct ast_filestream *fs)
Tell where we are in a stream.
Definition file.c:1112
#define ast_debug(level,...)
Log a DEBUG message.

References ast_debug, ast_seekstream(), ast_tellstream(), and DEFAULT_SAMPLES_PER_MS.

Referenced by __ast_play_and_record(), handle_recordfile(), record_exec(), and waitstream_control().

◆ ast_streamfile()

int ast_streamfile ( struct ast_channel c,
const char *  filename,
const char *  preflang 
)

Streams a file.

Parameters
cchannel to stream the file to
filenamethe name of the file you wish to stream, minus the extension
preflangthe 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.
Return values
0on success.
-1on failure.

Definition at line 1320 of file file.c.

1322{
1323 struct ast_json * cel_event = NULL;
1324 struct ast_filestream *fs = NULL;
1325 struct ast_filestream *vfs = NULL;
1326 off_t pos;
1327 int seekattempt;
1328 int res;
1329 char custom_filename[256];
1330 char *tmp_filename;
1331
1332 /* If file with the same name exists in /var/lib/asterisk/sounds/custom directory, use that file.
1333 * Otherwise, use the original file*/
1334
1336 memset(custom_filename, 0, sizeof(custom_filename));
1337 snprintf(custom_filename, sizeof(custom_filename), "custom/%s", filename);
1338 fs = openstream_internal(chan, custom_filename, preflang, 0, 1); /* open stream, do not warn for missing files */
1339 if (fs) {
1340 tmp_filename = custom_filename;
1341 ast_debug(3, "Found file %s in custom directory\n", filename);
1342 }
1343 }
1344
1345 if (!fs) {
1346 fs = ast_openstream(chan, filename, preflang);
1347 if (!fs) {
1348 struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
1349 ast_channel_lock(chan);
1350 ast_log(LOG_WARNING, "Unable to open %s (format %s)\n",
1351 filename, ast_format_cap_get_names(ast_channel_nativeformats(chan), &codec_buf));
1352 ast_channel_unlock(chan);
1353 return -1;
1354 }
1355 tmp_filename = (char *)filename;
1356 }
1357
1358 /* check to see if there is any data present (not a zero length file),
1359 * done this way because there is no where for ast_openstream_full to
1360 * return the file had no data. */
1361 pos = ftello(fs->f);
1362 seekattempt = fseeko(fs->f, -1, SEEK_END);
1363 if (seekattempt) {
1364 if (errno == EINVAL) {
1365 /* Zero-length file, as opposed to a pipe */
1366 return 0;
1367 } else {
1368 ast_seekstream(fs, 0, SEEK_SET);
1369 }
1370 } else {
1371 fseeko(fs->f, pos, SEEK_SET);
1372 }
1373
1374 vfs = ast_openvstream(chan, tmp_filename, preflang);
1375 if (vfs) {
1376 ast_debug(1, "Ooh, found a video stream, too, format %s\n", ast_format_get_name(vfs->fmt->format));
1377 }
1378
1381 if (ast_applystream(chan, fs))
1382 return -1;
1383 if (vfs && ast_applystream(chan, vfs))
1384 return -1;
1385 ast_test_suite_event_notify("PLAYBACK", "Message: %s\r\nChannel: %s", tmp_filename, ast_channel_name(chan));
1386 res = ast_playstream(fs);
1387 if (!res && vfs)
1388 res = ast_playstream(vfs);
1389
1390 cel_event = ast_json_pack("{ s: s, s: {s: s, s: s, s: s}}",
1391 "event", "FILE_STREAM_BEGIN",
1392 "extra",
1393 "sound", tmp_filename,
1395 "language", preflang ? preflang : "default"
1396 );
1397 if (cel_event) {
1399 } else {
1400 ast_log(LOG_WARNING, "Unable to build extradata for sound file STREAM_BEGIN event on channel %s", ast_channel_name(chan));
1401 }
1402 ast_json_unref(cel_event);
1403
1404 if (VERBOSITY_ATLEAST(3)) {
1405 ast_channel_lock(chan);
1406 ast_verb(3, "<%s> Playing '%s.%s' (language '%s')\n", ast_channel_name(chan), tmp_filename, ast_format_get_name(ast_channel_writeformat(chan)), preflang ? preflang : "default");
1407 ast_channel_unlock(chan);
1408 }
1409
1410 return res;
1411}
@ AST_CEL_STREAM_BEGIN
A stream started.
Definition cel.h:82
const char * ast_channel_name(const struct ast_channel *chan)
@ AST_FLAG_MASQ_NOSTREAM
Definition channel.h:1034
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
struct ast_filestream * ast_openstream(struct ast_channel *chan, const char *filename, const char *preflang)
Opens stream for use in seeking, playing.
Definition file.c:864
int ast_applystream(struct ast_channel *chan, struct ast_filestream *s)
Applies a open stream to a channel.
Definition file.c:1084
struct ast_filestream * ast_openvstream(struct ast_channel *chan, const char *filename, const char *preflang)
Opens stream for use in seeking, playing.
Definition file.c:875
static int is_absolute_path(const char *filename)
Definition file.c:694
int ast_playstream(struct ast_filestream *s)
Play a open stream on a channel.
Definition file.c:1090
#define AST_FORMAT_CAP_NAMES_LEN
Definition format_cap.h:324
const char * ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf)
Get the names of codecs of a set of formats.
Definition format_cap.c:742
#define VERBOSITY_ATLEAST(level)
#define ast_verb(level,...)
#define ast_opt_sounds_search_custom
Definition options.h:148
#define ast_str_alloca(init_len)
Definition strings.h:848
const char * orig_chan_name
Definition mod_format.h:125
Support for dynamic strings.
Definition strings.h:623
#define ast_test_suite_event_notify(s, f,...)
Definition test.h:189
#define ast_test_flag(p, flag)
Definition utils.h:64

References ast_applystream(), ast_cel_publish_event(), AST_CEL_STREAM_BEGIN, ast_channel_flags(), ast_channel_lock, ast_channel_name(), ast_channel_nativeformats(), ast_channel_unlock, ast_channel_writeformat(), ast_debug, AST_FLAG_MASQ_NOSTREAM, ast_format_cap_get_names(), AST_FORMAT_CAP_NAMES_LEN, ast_format_get_name(), ast_json_pack(), ast_json_unref(), ast_log, ast_openstream(), ast_openvstream(), ast_opt_sounds_search_custom, ast_playstream(), ast_seekstream(), ast_str_alloca, ast_strdup, ast_test_flag, ast_test_suite_event_notify, ast_verb, errno, ast_filestream::f, ast_filestream::filename, ast_filestream::fmt, ast_format_def::format, is_absolute_path(), LOG_WARNING, NULL, openstream_internal(), ast_filestream::orig_chan_name, VERBOSITY_ATLEAST, and ast_filestream::vfs.

Referenced by __analog_ss_thread(), action_playback_and_continue(), analog_ss_thread(), announce_thread(), announce_to_dial(), app_exec(), ast_app_getdata_full(), ast_app_getdata_terminator(), ast_play_and_wait(), ast_say_date_da(), ast_say_date_de(), ast_say_date_en(), ast_say_date_fr(), ast_say_date_gr(), ast_say_date_he(), ast_say_date_hu(), ast_say_date_is(), ast_say_date_ja(), ast_say_date_ka(), ast_say_date_nl(), ast_say_date_th(), ast_say_date_with_format_gr(), ast_say_datetime_en(), ast_say_datetime_fr(), ast_say_datetime_from_now_en(), ast_say_datetime_from_now_fr(), ast_say_datetime_from_now_he(), ast_say_datetime_from_now_ka(), ast_say_datetime_gr(), ast_say_datetime_he(), ast_say_datetime_ja(), ast_say_datetime_nl(), ast_say_datetime_pt(), ast_say_datetime_th(), ast_say_datetime_zh(), ast_say_enumeration_full_da(), ast_say_enumeration_full_de(), ast_say_enumeration_full_dr(), ast_say_enumeration_full_en(), ast_say_enumeration_full_he(), ast_say_enumeration_full_is(), ast_say_enumeration_full_ps(), ast_say_enumeration_full_vi(), ast_say_number_full_cs(), ast_say_number_full_da(), ast_say_number_full_de(), ast_say_number_full_dr(), ast_say_number_full_en_GB(), ast_say_number_full_es(), ast_say_number_full_fr(), ast_say_number_full_gr(), ast_say_number_full_he(), ast_say_number_full_hu(), ast_say_number_full_is(), ast_say_number_full_it(), ast_say_number_full_ja(), ast_say_number_full_ka(), ast_say_number_full_nl(), ast_say_number_full_no(), ast_say_number_full_ps(), ast_say_number_full_pt(), ast_say_number_full_ru(), ast_say_number_full_se(), ast_say_number_full_th(), ast_say_number_full_ur(), ast_say_number_full_vi(), ast_say_number_full_zh(), ast_say_time_de(), ast_say_time_en(), ast_say_time_fr(), ast_say_time_gr(), ast_say_time_hu(), ast_say_time_ja(), ast_say_time_ka(), ast_say_time_nl(), ast_say_time_zh(), ast_stream_and_wait(), auth_exec(), background_detect_exec(), common_exec(), conf_exec(), conf_get_pin(), conf_run(), control_streamfile(), dial_exec_full(), do_directory(), find_conf_realtime(), forward_message(), gr_say_number_female(), handle_recordfile(), invent_message(), isAnsweringMachine(), leave_voicemail(), leave_voicemail(), meetme_menu_admin(), meetme_menu_admin_extended(), meetme_menu_normal(), minivm_greet_exec(), page_exec(), pbx_builtin_background(), pl_odtworz_plik(), play_and_wait(), play_file(), play_record_review(), playback_exec(), privacy_exec(), readexten_exec(), retrydial_exec(), s_streamwait3(), say_filenames(), select_item_menu(), setup_privacy_args(), vm_authenticate(), wait_file(), wait_for_answer(), and wait_for_winner().

◆ ast_tellstream()

off_t ast_tellstream ( struct ast_filestream fs)

Tell where we are in a stream.

Parameters
fsfs to act on
Returns
a long as a sample offset into stream

Definition at line 1112 of file file.c.

1113{
1114 return fs->fmt->tell(fs);
1115}
off_t(* tell)(struct ast_filestream *fs)
Definition mod_format.h:70

References ast_filestream::fmt, and ast_format_def::tell.

Referenced by __ast_play_and_record(), ast_stream_rewind(), control_streamfile(), handle_getoption(), handle_recordfile(), handle_speechrecognize(), handle_streamfile(), moh_files_next(), msg_create_from_file(), waitstream_control(), and waitstream_core().

◆ ast_truncstream()

int ast_truncstream ( struct ast_filestream fs)

Trunc stream at current location.

Parameters
fsfilestream to act on
Return values
0on success.
-1on failure.

Definition at line 1107 of file file.c.

1108{
1109 return fs->fmt->trunc(fs);
1110}
int(* trunc)(struct ast_filestream *fs)
Definition mod_format.h:69

References ast_filestream::fmt, and ast_format_def::trunc.

Referenced by __ast_play_and_record(), handle_recordfile(), and record_exec().

◆ ast_waitstream()

int ast_waitstream ( struct ast_channel c,
const char *  breakon 
)

Waits for a stream to stop or digit to be pressed.

Parameters
cchannel to waitstream on
breakonstring of DTMF digits to break upon Begins playback of a stream... Wait for a stream to stop or for any one of a given digit to arrive,
Return values
0if the stream finishes
characterif it was interrupted by the channel.
-1on error

Definition at line 1882 of file file.c.

1883{
1884 int res;
1885
1886 res = waitstream_core(c, breakon, NULL, NULL, 0, -1, -1, NULL, NULL /* no callback */);
1887
1888 return sanitize_waitstream_return(res);
1889}
static int sanitize_waitstream_return(int return_value)
Definition file.c:1865
static int waitstream_core(struct ast_channel *c, const char *breakon, const char *forward, const char *reverse, int skip_ms, int audiofd, int cmdfd, const char *context, ast_waitstream_fr_cb cb)
the core of all waitstream() functions
Definition file.c:1655
static struct test_val c

References c, NULL, sanitize_waitstream_return(), and waitstream_core().

Referenced by __analog_ss_thread(), action_playback_and_continue(), analog_ss_thread(), announce_thread(), announce_to_dial(), app_exec(), ast_play_and_wait(), ast_say_date_da(), ast_say_date_de(), ast_say_date_en(), ast_say_date_fr(), ast_say_date_gr(), ast_say_date_he(), ast_say_date_hu(), ast_say_date_is(), ast_say_date_ja(), ast_say_date_ka(), ast_say_date_nl(), ast_say_date_th(), ast_say_date_with_format_gr(), ast_say_datetime_en(), ast_say_datetime_fr(), ast_say_datetime_from_now_en(), ast_say_datetime_from_now_fr(), ast_say_datetime_from_now_he(), ast_say_datetime_from_now_ka(), ast_say_datetime_gr(), ast_say_datetime_he(), ast_say_datetime_ja(), ast_say_datetime_nl(), ast_say_datetime_pt(), ast_say_datetime_th(), ast_say_datetime_zh(), ast_say_enumeration_full_da(), ast_say_enumeration_full_de(), ast_say_enumeration_full_dr(), ast_say_enumeration_full_en(), ast_say_enumeration_full_he(), ast_say_enumeration_full_is(), ast_say_enumeration_full_ps(), ast_say_enumeration_full_vi(), ast_say_number_full_cs(), ast_say_number_full_da(), ast_say_number_full_de(), ast_say_number_full_dr(), ast_say_number_full_en_GB(), ast_say_number_full_es(), ast_say_number_full_fr(), ast_say_number_full_gr(), ast_say_number_full_he(), ast_say_number_full_hu(), ast_say_number_full_is(), ast_say_number_full_it(), ast_say_number_full_ja(), ast_say_number_full_ka(), ast_say_number_full_nl(), ast_say_number_full_no(), ast_say_number_full_ps(), ast_say_number_full_pt(), ast_say_number_full_ru(), ast_say_number_full_se(), ast_say_number_full_th(), ast_say_number_full_ur(), ast_say_number_full_vi(), ast_say_number_full_zh(), ast_say_time_de(), ast_say_time_en(), ast_say_time_fr(), ast_say_time_gr(), ast_say_time_he(), ast_say_time_hu(), ast_say_time_ja(), ast_say_time_ka(), ast_say_time_nl(), ast_say_time_zh(), ast_stream_and_wait(), auth_exec(), common_exec(), conf_exec(), conf_get_pin(), conf_run(), directory_exec(), find_conf_realtime(), gr_say_number_female(), handle_recordfile(), invent_message(), leave_voicemail(), leave_voicemail(), meetme_menu_admin(), meetme_menu_admin_extended(), meetme_menu_normal(), minivm_greet_exec(), page_exec(), pbx_builtin_background(), pl_odtworz_plik(), play_and_wait(), play_file(), play_record_review(), playback_exec(), privacy_exec(), retrydial_exec(), s_streamwait3(), say_filenames(), select_item_menu(), setup_privacy_args(), vm_authenticate(), and wait_file().

◆ ast_waitstream_exten()

int ast_waitstream_exten ( struct ast_channel c,
const char *  context 
)

Waits for a stream to stop or digit matching a valid one digit exten to be pressed.

Parameters
cchannel to waitstream on
contextstring of context to match digits to break upon Begins playback of a stream... Wait for a stream to stop or for any one of a valid extension digit to arrive,
Return values
0if the stream finishes.
characterif it was interrupted.
-1on error.

Definition at line 1901 of file file.c.

1902{
1903 int res;
1904
1905 /* Waitstream, with return in the case of a valid 1 digit extension */
1906 /* in the current or specified context being pressed */
1907 if (!context)
1909 res = waitstream_core(c, NULL, NULL, NULL, 0,
1910 -1, -1, context, NULL /* no callback */);
1911
1912 return sanitize_waitstream_return(res);
1913}
const char * ast_channel_context(const struct ast_channel *chan)

References ast_channel_context(), c, NULL, sanitize_waitstream_return(), and waitstream_core().

Referenced by pbx_builtin_background().

◆ ast_waitstream_fr()

int ast_waitstream_fr ( struct ast_channel c,
const char *  breakon,
const char *  forward,
const char *  rewind,
int  ms 
)

Same as waitstream but allows stream to be forwarded or rewound.

Parameters
cchannel to waitstream on
breakonstring of DTMF digits to break upon
forwardDTMF digit to fast forward upon
rewindDTMF digit to rewind upon
msHow many miliseconds to skip forward/back Begins playback of a stream... Wait for a stream to stop or for any one of a given digit to arrive,
Return values
0if the stream finishes.
characterif it was interrupted,
Returns
the value of the control frame if it was interrupted by some other party,
Return values
-1on error.

Definition at line 1851 of file file.c.

1852{
1853 return waitstream_core(c, breakon, forward, reverse, ms,
1854 -1 /* no audiofd */, -1 /* no cmdfd */, NULL /* no context */, NULL /* no callback */);
1855}

References c, NULL, and waitstream_core().

Referenced by control_streamfile().

◆ ast_waitstream_fr_w_cb()

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 
)

Same as waitstream_fr but allows a callback to be alerted when a user fastforwards or rewinds the file.

Parameters
cchannel to waitstream on
breakonstring of DTMF digits to break upon
forwardDTMF digit to fast forward upon
rewindDTMF digit to rewind upon
msHow many milliseconds to skip forward/back
cbto call when rewind or fastforward occurs. Begins playback of a stream... Wait for a stream to stop or for any one of a given digit to arrive,
Return values
0if the stream finishes.
characterif it was interrupted,
Returns
the value of the control frame if it was interrupted by some other party,
Return values
-1on error.

Definition at line 1840 of file file.c.

1846{
1847 return waitstream_core(c, breakon, forward, reverse, ms,
1848 -1 /* no audiofd */, -1 /* no cmdfd */, NULL /* no context */, cb);
1849}

References c, NULL, and waitstream_core().

Referenced by control_streamfile().

◆ ast_waitstream_full()

int ast_waitstream_full ( struct ast_channel c,
const char *  breakon,
int  audiofd,
int  monfd 
)

◆ ast_writefile()

struct ast_filestream * ast_writefile ( const char *  filename,
const char *  type,
const char *  comment,
int  flags,
int  check,
mode_t  mode 
)

Starts writing a file.

Parameters
filenamethe name of the file to write to
typeformat of file you wish to write out to
commentcomment to go with
flagsoutput file flags
check(unimplemented, hence negligible)
modeOpen 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.
Returns
a struct ast_filestream on success.
Return values
NULLon failure.

Definition at line 1465 of file file.c.

1466{
1467 int fd, myflags = 0;
1468 /* compiler claims this variable can be used before initialization... */
1469 FILE *bfile = NULL;
1470 struct ast_format_def *f;
1471 struct ast_filestream *fs = NULL;
1472 char *buf = NULL;
1473 size_t size = 0;
1474 int format_found = 0;
1475
1477
1478 /* set the O_TRUNC flag if and only if there is no O_APPEND specified */
1479 /* We really can't use O_APPEND as it will break WAV header updates */
1480 if (flags & O_APPEND) {
1481 flags &= ~O_APPEND;
1482 } else {
1483 myflags = O_TRUNC;
1484 }
1485
1486 myflags |= O_WRONLY | O_CREAT;
1487
1488 /* XXX need to fix this - we should just do the fopen,
1489 * not open followed by fdopen()
1490 */
1491 AST_RWLIST_TRAVERSE(&formats, f, list) {
1492 char *fn, *orig_fn = NULL;
1493 if (fs)
1494 break;
1495
1496 if (!exts_compare(f->exts, type))
1497 continue;
1498 else
1499 format_found = 1;
1500
1502 if (!fn) {
1503 continue;
1504 }
1505 fd = open(fn, flags | myflags, mode);
1506 if (fd > -1) {
1507 /* fdopen() the resulting file stream */
1508 bfile = fdopen(fd, ((flags | myflags) & O_RDWR) ? "w+" : "w");
1509 if (!bfile) {
1510 ast_log(LOG_WARNING, "Whoa, fdopen failed: %s!\n", strerror(errno));
1511 close(fd);
1512 fd = -1;
1513 }
1514 }
1515
1516 if (ast_opt_cache_record_files && (fd > -1)) {
1517 char *c;
1518
1519 fclose(bfile); /* this also closes fd */
1520 /*
1521 We touch orig_fn just as a place-holder so other things (like vmail) see the file is there.
1522 What we are really doing is writing to record_cache_dir until we are done then we will mv the file into place.
1523 */
1524 orig_fn = ast_strdup(fn);
1525 for (c = fn; *c; c++)
1526 if (*c == '/')
1527 *c = '_';
1528
1529 size = strlen(fn) + strlen(record_cache_dir) + 2;
1530 buf = ast_malloc(size);
1531 strcpy(buf, record_cache_dir);
1532 strcat(buf, "/");
1533 strcat(buf, fn);
1534 ast_free(fn);
1535 fn = buf;
1536 fd = open(fn, flags | myflags, mode);
1537 if (fd > -1) {
1538 /* fdopen() the resulting file stream */
1539 bfile = fdopen(fd, ((flags | myflags) & O_RDWR) ? "w+" : "w");
1540 if (!bfile) {
1541 ast_log(LOG_WARNING, "Whoa, fdopen failed: %s!\n", strerror(errno));
1542 close(fd);
1543 fd = -1;
1544 }
1545 }
1546 }
1547 if (fd > -1) {
1548 errno = 0;
1549 fs = get_filestream(f, bfile);
1550 if (fs) {
1551 if ((fs->write_buffer = ast_malloc(32768))) {
1552 setvbuf(fs->f, fs->write_buffer, _IOFBF, 32768);
1553 }
1554 }
1555 if (!fs || rewrite_wrapper(fs, comment)) {
1556 ast_log(LOG_WARNING, "Unable to rewrite %s\n", fn);
1557 close(fd);
1558 if (orig_fn) {
1559 unlink(fn);
1560 unlink(orig_fn);
1561 ast_free(orig_fn);
1562 }
1563 if (fs) {
1564 ast_closestream(fs);
1565 fs = NULL;
1566 }
1567 /*
1568 * 'fn' was has either been allocated from build_filename, or that was freed
1569 * and now 'fn' points to memory allocated for 'buf'. Either way the memory
1570 * now needs to be released.
1571 */
1572 ast_free(fn);
1573 continue;
1574 }
1575 fs->trans = NULL;
1576 fs->fmt = f;
1577 fs->flags = flags;
1578 fs->mode = mode;
1579 if (orig_fn) {
1580 fs->realfilename = orig_fn;
1581 fs->filename = fn;
1582 /*
1583 * The above now manages the memory allocated for 'orig_fn' and 'fn', so
1584 * set them to NULL, so they don't get released at the end of the loop.
1585 */
1586 orig_fn = NULL;
1587 fn = NULL;
1588 } else {
1589 fs->realfilename = NULL;
1591 }
1592 fs->vfs = NULL;
1593 /* If truncated, we'll be at the beginning; if not truncated, then append */
1594 f->seek(fs, 0, SEEK_END);
1595 } else if (errno != EEXIST) {
1596 ast_log(LOG_WARNING, "Unable to open file %s: %s\n", fn, strerror(errno));
1597 if (orig_fn)
1598 unlink(orig_fn);
1599 }
1600 /* Free 'fn', or if 'fn' points to 'buf' then free 'buf' */
1601 ast_free(fn);
1602 ast_free(orig_fn);
1603 }
1604
1606
1607 if (!format_found)
1608 ast_log(LOG_WARNING, "No such format '%s'\n", type);
1609
1610 return fs;
1611}
#define comment
Definition ael_lex.c:965
#define ast_malloc(len)
A wrapper for malloc()
Definition astmm.h:191
static int rewrite_wrapper(struct ast_filestream *s, const char *comment)
Definition file.c:531
char record_cache_dir[AST_CACHE_DIR_LEN]
Definition options.c:97
#define ast_opt_cache_record_files
Definition options.h:130
char * realfilename
Definition mod_format.h:108
char * write_buffer
Definition mod_format.h:126

References ast_closestream(), ast_free, ast_log, ast_malloc, ast_opt_cache_record_files, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, buf, build_filename(), c, comment, errno, exts_compare, ast_filestream::f, ast_filestream::filename, ast_filestream::flags, ast_filestream::fmt, get_filestream(), LOG_WARNING, ast_filestream::mode, NULL, ast_filestream::realfilename, record_cache_dir, rewrite_wrapper(), ast_filestream::trans, type, ast_filestream::vfs, and ast_filestream::write_buffer.

Referenced by __ast_play_and_record(), ast_writestream(), dictate_exec(), handle_cli_file_convert(), handle_recordfile(), mixmonitor_save_prep(), record_exec(), and recordthread().

◆ ast_writestream()

int ast_writestream ( struct ast_filestream fs,
struct ast_frame f 
)

Writes a frame to a stream.

Parameters
fsfilestream to write to
fframe to write to the filestream Send a frame to a filestream – note: does NOT free the frame, call ast_frfree manually
Return values
0on success.
-1on failure.

Definition at line 255 of file file.c.

256{
257 int res = -1;
258 if (f->frametype == AST_FRAME_VIDEO) {
260 /* This is the audio portion. Call the video one... */
261 if (!fs->vfs && fs->filename) {
262 const char *type = ast_format_get_name(f->subclass.format);
263 fs->vfs = ast_writefile(fs->filename, type, NULL, fs->flags, 0, fs->mode);
264 ast_debug(1, "Opened video output file\n");
265 }
266 if (fs->vfs)
267 return ast_writestream(fs->vfs, f);
268 /* else ignore */
269 return 0;
270 }
271 } else if (f->frametype != AST_FRAME_VOICE) {
272 ast_log(LOG_WARNING, "Tried to write non-voice frame\n");
273 return -1;
274 }
276 res = fs->fmt->write(fs, f);
277 if (res < 0)
278 ast_log(LOG_WARNING, "Natural write failed\n");
279 else if (res > 0)
280 ast_log(LOG_WARNING, "Huh??\n");
281 } else {
282 /* XXX If they try to send us a type of frame that isn't the normal frame, and isn't
283 the one we've setup a translator for, we do the "wrong thing" XXX */
286 fs->trans = NULL;
287 }
288 if (!fs->trans) {
290 }
291 if (!fs->trans) {
292 ast_log(LOG_WARNING, "Unable to translate to format %s, source format %s\n",
294 } else {
295 struct ast_frame *trf;
297 /* Get the translated frame but don't consume the original in case they're using it on another stream */
298 if ((trf = ast_translate(fs->trans, f, 0))) {
299 struct ast_frame *cur;
300
301 /* the translator may have returned multiple frames, so process them */
302 for (cur = trf; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
303 if ((res = fs->fmt->write(fs, cur))) {
304 ast_log(LOG_WARNING, "Translated frame write failed\n");
305 break;
306 }
307 }
308 ast_frfree(trf);
309 } else {
310 res = 0;
311 }
312 }
313 }
314 return res;
315}
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
Definition astobj2.h:501
int ast_writestream(struct ast_filestream *fs, struct ast_frame *f)
Writes a frame to a stream.
Definition file.c:255
struct ast_filestream * ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
Starts writing a file.
Definition file.c:1465
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition format.c:201
@ AST_FORMAT_CMP_EQUAL
Definition format.h:36
@ AST_FORMAT_CMP_NOT_EQUAL
Definition format.h:38
#define ast_frfree(fr)
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
struct ast_format * lastwriteformat
Definition mod_format.h:114
int(* write)(struct ast_filestream *, struct ast_frame *)
Definition mod_format.h:66
char name[80]
Definition mod_format.h:44
struct ast_format * format
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
enum ast_frame_type frametype
struct ast_frame * ast_translate(struct ast_trans_pvt *tr, struct ast_frame *f, int consume)
translates one or more frames Apply an input frame into the translator and receive zero or one output...
Definition translate.c:623
void ast_translator_free_path(struct ast_trans_pvt *tr)
Frees a translator path Frees the given translator path structure.
Definition translate.c:533
struct ast_trans_pvt * ast_translator_build_path(struct ast_format *dest, struct ast_format *source)
Builds a translator path Build a path (possibly NULL) from source to dest.
Definition translate.c:543

References ao2_replace, ast_debug, ast_format_cmp(), AST_FORMAT_CMP_EQUAL, AST_FORMAT_CMP_NOT_EQUAL, ast_format_get_name(), ast_format_get_type(), AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, AST_LIST_NEXT, ast_log, AST_MEDIA_TYPE_AUDIO, ast_translate(), ast_translator_build_path(), ast_translator_free_path(), ast_writefile(), ast_writestream(), ast_filestream::filename, ast_filestream::flags, ast_filestream::fmt, ast_frame_subclass::format, ast_format_def::format, ast_frame::frametype, ast_filestream::lastwriteformat, LOG_WARNING, ast_filestream::mode, ast_format_def::name, NULL, ast_frame::subclass, ast_filestream::trans, type, ast_filestream::vfs, and ast_format_def::write.

Referenced by __ast_play_and_record(), ast_writestream(), dictate_exec(), handle_cli_file_convert(), handle_recordfile(), mixmonitor_thread(), record_exec(), and recordthread().