#include "asterisk/channel.h"
#include "asterisk/frame.h"
#include <fcntl.h>
Go to the source code of this file.
Data Structures | |
struct | ast_filestream |
struct | ast_format |
struct | ast_format_lock |
Defines | |
#define | AST_DIGIT_ANY "0123456789#*ABCD" |
#define | AST_DIGIT_ANYNUM "0123456789" |
#define | ast_format_register(f) __ast_format_register(f, ast_module_info->self) |
#define | AST_RESERVED_POINTERS 20 |
#define | SEEK_FORCECUR 10 |
Functions | |
int | __ast_format_register (const struct ast_format *f, struct ast_module *mod) |
int | ast_applystream (struct ast_channel *chan, struct ast_filestream *s) |
int | ast_closestream (struct ast_filestream *f) |
int | ast_file_init (void) |
int | ast_filecopy (const char *oldname, const char *newname, const char *fmt) |
int | ast_filedelete (const char *filename, const char *fmt) |
int | ast_fileexists (const char *filename, const char *fmt, const char *preflang) |
int | ast_filerename (const char *oldname, const char *newname, const char *fmt) |
int | ast_format_unregister (const char *name) |
struct ast_filestream * | ast_openstream (struct ast_channel *chan, const char *filename, const char *preflang) |
struct ast_filestream * | ast_openstream_full (struct ast_channel *chan, const char *filename, const char *preflang, int asis) |
struct ast_filestream * | ast_openvstream (struct ast_channel *chan, const char *filename, const char *preflang) |
int | ast_playstream (struct ast_filestream *s) |
struct ast_filestream * | ast_readfile (const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode) |
struct ast_frame * | ast_readframe (struct ast_filestream *s) |
int | ast_seekstream (struct ast_filestream *fs, off_t sample_offset, int whence) |
int | ast_stopstream (struct ast_channel *c) |
int | ast_stream_and_wait (struct ast_channel *chan, const char *file, const char *language, const char *digits) |
int | ast_stream_fastforward (struct ast_filestream *fs, off_t ms) |
int | ast_stream_rewind (struct ast_filestream *fs, off_t ms) |
int | ast_streamfile (struct ast_channel *c, const char *filename, const char *preflang) |
off_t | ast_tellstream (struct ast_filestream *fs) |
int | ast_truncstream (struct ast_filestream *fs) |
int | ast_waitstream (struct ast_channel *c, const char *breakon) |
int | ast_waitstream_exten (struct ast_channel *c, const char *context) |
int | ast_waitstream_fr (struct ast_channel *c, const char *breakon, const char *forward, const char *rewind, int ms) |
int | ast_waitstream_full (struct ast_channel *c, const char *breakon, int audiofd, int monfd) |
struct ast_filestream * | ast_writefile (const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode) |
int | ast_writestream (struct ast_filestream *fs, struct ast_frame *f) |
Definition in file file.h.
#define AST_DIGIT_ANY "0123456789#*ABCD" |
Convenient for waiting
Definition at line 40 of file file.h.
Referenced by __login_exec(), ast_ivr_menu_run_internal(), ast_play_and_wait(), ast_readstring_full(), ast_record_review(), bridge_playfile(), builtin_atxfer(), builtin_blindtransfer(), conf_exec(), conf_run(), dictate_exec(), directory_exec(), festival_exec(), get_folder(), ivr_dispatch(), pbx_builtin_background(), play_file(), play_mailbox_owner(), play_message(), play_message_callerid(), play_message_datetime(), play_message_duration(), play_record_review(), retrydial_exec(), say_and_wait(), say_position(), sayunixtime_exec(), try_calling(), vm_intro_gr(), vm_intro_pt(), vm_intro_pt_BR(), and wait_file2().
#define AST_DIGIT_ANYNUM "0123456789" |
#define ast_format_register | ( | f | ) | __ast_format_register(f, ast_module_info->self) |
#define SEEK_FORCECUR 10 |
Definition at line 138 of file file.h.
Referenced by __ast_read(), ast_write(), au_seek(), g729_seek(), gsm_seek(), ilbc_seek(), pcm_seek(), slinear_seek(), vox_seek(), and wav_seek().
int __ast_format_register | ( | const struct ast_format * | f, | |
struct ast_module * | mod | |||
) |
Register a new file format capability Adds a format to Asterisk's format abilities. returns 0 on success, -1 on failure
Definition at line 68 of file file.c.
References ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_verbose(), ast_format::buf_size, ast_format::exts, LOG_WARNING, ast_format::module, ast_format::name, option_verbose, and VERBOSE_PREFIX_2.
00069 { 00070 struct ast_format *tmp; 00071 00072 if (AST_LIST_LOCK(&formats)) { 00073 ast_log(LOG_WARNING, "Unable to lock format list\n"); 00074 return -1; 00075 } 00076 AST_LIST_TRAVERSE(&formats, tmp, list) { 00077 if (!strcasecmp(f->name, tmp->name)) { 00078 AST_LIST_UNLOCK(&formats); 00079 ast_log(LOG_WARNING, "Tried to register '%s' format, already registered\n", f->name); 00080 return -1; 00081 } 00082 } 00083 if (!(tmp = ast_calloc(1, sizeof(*tmp)))) { 00084 AST_LIST_UNLOCK(&formats); 00085 return -1; 00086 } 00087 *tmp = *f; 00088 tmp->module = mod; 00089 if (tmp->buf_size) { 00090 /* 00091 * Align buf_size properly, rounding up to the machine-specific 00092 * alignment for pointers. 00093 */ 00094 struct _test_align { void *a, *b; } p; 00095 int align = (char *)&p.b - (char *)&p.a; 00096 tmp->buf_size = ((f->buf_size + align - 1)/align)*align; 00097 } 00098 00099 memset(&tmp->list, 0, sizeof(tmp->list)); 00100 00101 AST_LIST_INSERT_HEAD(&formats, tmp, list); 00102 AST_LIST_UNLOCK(&formats); 00103 if (option_verbose > 1) 00104 ast_verbose( VERBOSE_PREFIX_2 "Registered file format %s, extension(s) %s\n", f->name, f->exts); 00105 00106 return 0; 00107 }
int ast_applystream | ( | struct ast_channel * | chan, | |
struct ast_filestream * | s | |||
) |
Applys a open stream to a channel.
chan | channel to work | |
s | ast_filestream to apply Returns 0 for success, -1 on failure |
Definition at line 669 of file file.c.
References ast_filestream::owner.
00670 { 00671 s->owner = chan; 00672 return 0; 00673 }
int ast_closestream | ( | struct ast_filestream * | f | ) |
Closes a stream
f | filestream to close Close a playback or recording stream Returns 0 on success, -1 on failure |
Definition at line 709 of file file.c.
References ast_closestream(), AST_FORMAT_MAX_AUDIO, ast_module_unref(), ast_safe_system(), ast_sched_del(), ast_settimeout(), ast_translator_free_path(), ast_format::close, ast_filestream::f, ast_filestream::filename, ast_filestream::fmt, ast_format::format, free, ast_format::module, ast_filestream::owner, ast_filestream::realfilename, ast_channel::sched, ast_channel::stream, ast_channel::streamid, ast_filestream::trans, ast_filestream::vfs, ast_channel::vstream, and ast_channel::vstreamid.
00710 { 00711 char *cmd = NULL; 00712 size_t size = 0; 00713 /* Stop a running stream if there is one */ 00714 if (f->owner) { 00715 if (f->fmt->format < AST_FORMAT_MAX_AUDIO) { 00716 f->owner->stream = NULL; 00717 if (f->owner->streamid > -1) 00718 ast_sched_del(f->owner->sched, f->owner->streamid); 00719 f->owner->streamid = -1; 00720 #ifdef HAVE_ZAPTEL 00721 ast_settimeout(f->owner, 0, NULL, NULL); 00722 #endif 00723 } else { 00724 f->owner->vstream = NULL; 00725 if (f->owner->vstreamid > -1) 00726 ast_sched_del(f->owner->sched, f->owner->vstreamid); 00727 f->owner->vstreamid = -1; 00728 } 00729 } 00730 /* destroy the translator on exit */ 00731 if (f->trans) 00732 ast_translator_free_path(f->trans); 00733 00734 if (f->realfilename && f->filename) { 00735 size = strlen(f->filename) + strlen(f->realfilename) + 15; 00736 cmd = alloca(size); 00737 memset(cmd,0,size); 00738 snprintf(cmd,size,"/bin/mv -f %s %s",f->filename,f->realfilename); 00739 ast_safe_system(cmd); 00740 } 00741 00742 if (f->filename) 00743 free(f->filename); 00744 if (f->realfilename) 00745 free(f->realfilename); 00746 if (f->fmt->close) 00747 f->fmt->close(f); 00748 fclose(f->f); 00749 if (f->vfs) 00750 ast_closestream(f->vfs); 00751 ast_module_unref(f->fmt->module); 00752 free(f); 00753 return 0; 00754 }
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
Definition at line 1210 of file file.c.
References ast_cli_register_multiple().
01211 { 01212 ast_cli_register_multiple(cli_file, sizeof(cli_file) / sizeof(struct ast_cli_entry)); 01213 return 0; 01214 }
int ast_filecopy | ( | const char * | oldname, | |
const char * | newname, | |||
const char * | fmt | |||
) |
Copies a file
oldname | name of the file you wish to copy (minus extension) | |
newname | name you wish the file to be copied to (minus extension) | |
fmt | the 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 784 of file file.c.
References ACTION_COPY, and ast_filehelper().
00785 { 00786 return ast_filehelper(filename, filename2, fmt, ACTION_COPY); 00787 }
int ast_filedelete | ( | const char * | filename, | |
const char * | fmt | |||
) |
Deletes a file
filename | name of the file you wish to delete (minus the extension) | |
fmt | of the file Delete a given file in a given format, or if fmt is NULL, then do so for all |
Definition at line 774 of file file.c.
References ACTION_DELETE, and ast_filehelper().
00775 { 00776 return ast_filehelper(filename, NULL, fmt, ACTION_DELETE); 00777 }
int ast_fileexists | ( | const char * | filename, | |
const char * | fmt, | |||
const char * | preflang | |||
) |
Checks for the existence of a given file
filename | name of the file you wish to check, minus the extension | |
fmt | the 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. Returns -1 if file does not exist, non-zero positive otherwise. |
Definition at line 760 of file file.c.
References fileexists_core().
00761 { 00762 char *buf; 00763 int buflen; 00764 00765 if (preflang == NULL) 00766 preflang = ""; 00767 buflen = strlen(preflang) + strlen(filename) + 2; /* room for everything */ 00768 buf = alloca(buflen); 00769 if (buf == NULL) 00770 return 0; 00771 return fileexists_core(filename, fmt, preflang, buf, buflen); 00772 }
int ast_filerename | ( | const char * | oldname, | |
const char * | newname, | |||
const char * | fmt | |||
) |
Renames a file
oldname | the name of the file you wish to act upon (minus the extension) | |
newname | the name you wish to rename the file to (minus the extension) | |
fmt | the format of the file Rename a given file in a given format, or if fmt is NULL, then do so for all Returns -1 on failure |
Definition at line 779 of file file.c.
References ACTION_RENAME, and ast_filehelper().
00780 { 00781 return ast_filehelper(filename, filename2, fmt, ACTION_RENAME); 00782 }
int ast_format_unregister | ( | const char * | name | ) |
Unregisters a file format
name | the name of the format you wish to unregister Unregisters a format based on the name of the format. Returns 0 on success, -1 on failure to unregister |
Definition at line 109 of file file.c.
References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log(), ast_verbose(), free, LOG_WARNING, ast_format::name, option_verbose, and VERBOSE_PREFIX_2.
00110 { 00111 struct ast_format *tmp; 00112 int res = -1; 00113 00114 if (AST_LIST_LOCK(&formats)) { 00115 ast_log(LOG_WARNING, "Unable to lock format list\n"); 00116 return -1; 00117 } 00118 AST_LIST_TRAVERSE_SAFE_BEGIN(&formats, tmp, list) { 00119 if (!strcasecmp(name, tmp->name)) { 00120 AST_LIST_REMOVE_CURRENT(&formats, list); 00121 free(tmp); 00122 res = 0; 00123 } 00124 } 00125 AST_LIST_TRAVERSE_SAFE_END 00126 AST_LIST_UNLOCK(&formats); 00127 00128 if (!res) { 00129 if (option_verbose > 1) 00130 ast_verbose( VERBOSE_PREFIX_2 "Unregistered format %s\n", name); 00131 } else 00132 ast_log(LOG_WARNING, "Tried to unregister format %s, already unregistered\n", name); 00133 00134 return res; 00135 }
struct ast_filestream* ast_openstream | ( | struct ast_channel * | chan, | |
const char * | filename, | |||
const char * | preflang | |||
) | [read] |
Opens stream for use in seeking, playing
chan | channel to work with | |
filename | to use | |
preflang | prefered language to use Returns a ast_filestream pointer if it opens the file, NULL on error |
Definition at line 532 of file file.c.
References ast_openstream_full().
00533 { 00534 return ast_openstream_full(chan, filename, preflang, 0); 00535 }
struct ast_filestream* ast_openstream_full | ( | struct ast_channel * | chan, | |
const char * | filename, | |||
const char * | preflang, | |||
int | asis | |||
) | [read] |
Opens stream for use in seeking, playing
chan | channel to work with | |
filename | to use | |
preflang | prefered language to use | |
asis | if set, don't clear generators Returns a ast_filestream pointer if it opens the file, NULL on error |
Definition at line 537 of file file.c.
References ACTION_OPEN, ast_deactivate_generator(), ast_filehelper(), AST_FORMAT_AUDIO_MASK, ast_log(), ast_set_write_format(), ast_stopstream(), ast_filestream::buf, fileexists_core(), ast_channel::generator, LOG_WARNING, ast_channel::oldwriteformat, ast_channel::stream, and ast_channel::writeformat.
00538 { 00539 /* 00540 * Use fileexists_core() to find a file in a compatible 00541 * language and format, set up a suitable translator, 00542 * and open the stream. 00543 */ 00544 int fmts, res, buflen; 00545 char *buf; 00546 00547 if (!asis) { 00548 /* do this first, otherwise we detect the wrong writeformat */ 00549 ast_stopstream(chan); 00550 if (chan->generator) 00551 ast_deactivate_generator(chan); 00552 } 00553 if (preflang == NULL) 00554 preflang = ""; 00555 buflen = strlen(preflang) + strlen(filename) + 2; 00556 buf = alloca(buflen); 00557 if (buf == NULL) 00558 return NULL; 00559 fmts = fileexists_core(filename, NULL, preflang, buf, buflen); 00560 if (fmts > 0) 00561 fmts &= AST_FORMAT_AUDIO_MASK; 00562 if (fmts < 1) { 00563 ast_log(LOG_WARNING, "File %s does not exist in any format\n", filename); 00564 return NULL; 00565 } 00566 chan->oldwriteformat = chan->writeformat; 00567 /* Set the channel to a format we can work with */ 00568 res = ast_set_write_format(chan, fmts); 00569 res = ast_filehelper(buf, chan, NULL, ACTION_OPEN); 00570 if (res >= 0) 00571 return chan->stream; 00572 return NULL; 00573 }
struct ast_filestream* ast_openvstream | ( | struct ast_channel * | chan, | |
const char * | filename, | |||
const char * | preflang | |||
) | [read] |
Opens stream for use in seeking, playing
chan | channel to work with | |
filename | to use | |
preflang | prefered language to use Returns a ast_filestream pointer if it opens the file, NULL on error |
Definition at line 575 of file file.c.
References ACTION_OPEN, ast_filehelper(), AST_FORMAT_MAX_AUDIO, AST_FORMAT_MAX_VIDEO, ast_getformatname(), ast_log(), ast_filestream::buf, fileexists_core(), fmt, format, LOG_WARNING, ast_channel::nativeformats, and ast_channel::vstream.
00576 { 00577 /* As above, but for video. But here we don't have translators 00578 * so we must enforce a format. 00579 */ 00580 unsigned int format; 00581 char *buf; 00582 int buflen; 00583 00584 if (preflang == NULL) 00585 preflang = ""; 00586 buflen = strlen(preflang) + strlen(filename) + 2; 00587 buf = alloca(buflen); 00588 if (buf == NULL) 00589 return NULL; 00590 00591 for (format = AST_FORMAT_MAX_AUDIO << 1; format <= AST_FORMAT_MAX_VIDEO; format = format << 1) { 00592 int fd; 00593 const char *fmt; 00594 00595 if (!(chan->nativeformats & format)) 00596 continue; 00597 fmt = ast_getformatname(format); 00598 if ( fileexists_core(filename, fmt, preflang, buf, buflen) < 1) /* no valid format */ 00599 continue; 00600 fd = ast_filehelper(buf, chan, fmt, ACTION_OPEN); 00601 if (fd >= 0) 00602 return chan->vstream; 00603 ast_log(LOG_WARNING, "File %s has video but couldn't be opened\n", filename); 00604 } 00605 return NULL; 00606 }
int ast_playstream | ( | struct ast_filestream * | s | ) |
play a open stream on a channel.
s | filestream to play Returns 0 for success, -1 on failure |
Definition at line 675 of file file.c.
References AST_FORMAT_MAX_AUDIO, ast_readaudio_callback(), ast_readvideo_callback(), ast_filestream::fmt, and ast_format::format.
00676 { 00677 if (s->fmt->format < AST_FORMAT_MAX_AUDIO) 00678 ast_readaudio_callback(s); 00679 else 00680 ast_readvideo_callback(s); 00681 return 0; 00682 }
struct ast_filestream* ast_readfile | ( | const char * | filename, | |
const char * | type, | |||
const char * | comment, | |||
int | flags, | |||
int | check, | |||
mode_t | mode | |||
) | [read] |
Starts reading from a file
filename | the name of the file to read from | |
type | format of file you wish to read from | |
comment | comment to go with | |
flags | file flags | |
check | (unimplemented, hence negligible) | |
mode | Open 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, NULL on failure |
Definition at line 817 of file file.c.
References ast_free, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), build_filename(), ast_format::exts, exts_compare(), f, ast_filestream::filename, ast_filestream::flags, ast_filestream::fmt, free, get_filestream(), LOG_WARNING, ast_filestream::mode, open_wrapper(), strdup, ast_filestream::trans, and ast_filestream::vfs.
00818 { 00819 FILE *bfile; 00820 struct ast_format *f; 00821 struct ast_filestream *fs = NULL; 00822 char *fn; 00823 00824 if (AST_LIST_LOCK(&formats)) { 00825 ast_log(LOG_WARNING, "Unable to lock format list\n"); 00826 return NULL; 00827 } 00828 00829 AST_LIST_TRAVERSE(&formats, f, list) { 00830 fs = NULL; 00831 if (!exts_compare(f->exts, type)) 00832 continue; 00833 00834 fn = build_filename(filename, type); 00835 errno = 0; 00836 bfile = fopen(fn, "r"); 00837 if (!bfile || (fs = get_filestream(f, bfile)) == NULL || 00838 open_wrapper(fs) ) { 00839 ast_log(LOG_WARNING, "Unable to open %s\n", fn); 00840 if (fs) 00841 ast_free(fs); 00842 if (bfile) 00843 fclose(bfile); 00844 free(fn); 00845 continue; 00846 } 00847 /* found it */ 00848 fs->trans = NULL; 00849 fs->fmt = f; 00850 fs->flags = flags; 00851 fs->mode = mode; 00852 fs->filename = strdup(filename); 00853 fs->vfs = NULL; 00854 break; 00855 } 00856 00857 AST_LIST_UNLOCK(&formats); 00858 if (!fs) 00859 ast_log(LOG_WARNING, "No such format '%s'\n", type); 00860 00861 return fs; 00862 }
struct ast_frame* ast_readframe | ( | struct ast_filestream * | s | ) | [read] |
Read a frame from a filestream
s | ast_filestream to act on Returns a frame or NULL if read failed |
Definition at line 608 of file file.c.
References f, ast_filestream::fmt, and ast_format::read.
00609 { 00610 struct ast_frame *f = NULL; 00611 int whennext = 0; 00612 if (s && s->fmt) 00613 f = s->fmt->read(s, &whennext); 00614 return f; 00615 }
int ast_seekstream | ( | struct ast_filestream * | fs, | |
off_t | sample_offset, | |||
int | whence | |||
) |
Seeks into stream
fs | ast_filestream to perform seek on | |
sample_offset | numbers of samples to seek | |
whence | SEEK_SET, SEEK_CUR, SEEK_END Returns 0 for success, or -1 for error |
Definition at line 684 of file file.c.
References ast_filestream::fmt, and ast_format::seek.
int ast_stopstream | ( | struct ast_channel * | c | ) |
Stops a stream
c | The channel you wish to stop playback on Stop playback of a stream Returns 0 regardless |
Definition at line 137 of file file.c.
References ast_closestream(), ast_log(), ast_set_write_format(), LOG_WARNING, ast_channel::oldwriteformat, ast_channel::stream, and ast_channel::vstream.
00138 { 00139 /* Stop a running stream if there is one */ 00140 if (tmp->stream) { 00141 ast_closestream(tmp->stream); 00142 tmp->stream = NULL; 00143 if (tmp->oldwriteformat && ast_set_write_format(tmp, tmp->oldwriteformat)) 00144 ast_log(LOG_WARNING, "Unable to restore format back to %d\n", tmp->oldwriteformat); 00145 } 00146 /* Stop the video stream too */ 00147 if (tmp->vstream != NULL) { 00148 ast_closestream(tmp->vstream); 00149 tmp->vstream = NULL; 00150 } 00151 return 0; 00152 }
int ast_stream_and_wait | ( | struct ast_channel * | chan, | |
const char * | file, | |||
const char * | language, | |||
const char * | digits | |||
) |
Definition at line 1129 of file file.c.
References ast_streamfile(), ast_strlen_zero(), and ast_waitstream().
01131 { 01132 int res = 0; 01133 if (!ast_strlen_zero(file)) { 01134 res = ast_streamfile(chan, file, language); 01135 if (!res) 01136 res = ast_waitstream(chan, digits); 01137 } 01138 return res; 01139 }
int ast_stream_fastforward | ( | struct ast_filestream * | fs, | |
off_t | ms | |||
) |
Fast forward stream ms
fs | filestream to act on | |
ms | milliseconds to move Returns 0 for success, or -1 for error |
Definition at line 699 of file file.c.
References ast_seekstream(), and DEFAULT_SAMPLES_PER_MS.
00700 { 00701 return ast_seekstream(fs, ms * DEFAULT_SAMPLES_PER_MS, SEEK_CUR); 00702 }
int ast_stream_rewind | ( | struct ast_filestream * | fs, | |
off_t | ms | |||
) |
Rewind stream ms
fs | filestream to act on | |
ms | milliseconds to move Returns 0 for success, or -1 for error |
Definition at line 704 of file file.c.
References ast_seekstream(), and DEFAULT_SAMPLES_PER_MS.
00705 { 00706 return ast_seekstream(fs, -ms * DEFAULT_SAMPLES_PER_MS, SEEK_CUR); 00707 }
int ast_streamfile | ( | struct ast_channel * | c, | |
const char * | filename, | |||
const char * | preflang | |||
) |
Streams a file
c | channel to stream the file to | |
filename | the name of the file you wish to stream, minus the extension | |
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. Returns 0 on success, or -1 on failure. |
Definition at line 789 of file file.c.
References ast_applystream(), ast_getformatname(), ast_getformatname_multiple(), ast_log(), ast_openstream(), ast_openvstream(), ast_playstream(), ast_verbose(), ast_filestream::fmt, fmt, ast_format::format, LOG_DEBUG, LOG_WARNING, ast_channel::nativeformats, option_verbose, VERBOSE_PREFIX_3, and ast_filestream::vfs.
00790 { 00791 struct ast_filestream *fs; 00792 struct ast_filestream *vfs=NULL; 00793 char fmt[256]; 00794 00795 fs = ast_openstream(chan, filename, preflang); 00796 if (fs) 00797 vfs = ast_openvstream(chan, filename, preflang); 00798 if (vfs) 00799 ast_log(LOG_DEBUG, "Ooh, found a video stream, too, format %s\n", ast_getformatname(vfs->fmt->format)); 00800 if (fs){ 00801 if (ast_applystream(chan, fs)) 00802 return -1; 00803 if (vfs && ast_applystream(chan, vfs)) 00804 return -1; 00805 ast_playstream(fs); 00806 if (vfs) 00807 ast_playstream(vfs); 00808 if (option_verbose > 2) 00809 ast_verbose(VERBOSE_PREFIX_3 "<%s> Playing '%s' (language '%s')\n", chan->name, filename, preflang ? preflang : "default"); 00810 00811 return 0; 00812 } 00813 ast_log(LOG_WARNING, "Unable to open %s (format %s): %s\n", filename, ast_getformatname_multiple(fmt, sizeof(fmt), chan->nativeformats), strerror(errno)); 00814 return -1; 00815 }
off_t ast_tellstream | ( | struct ast_filestream * | fs | ) |
Tell where we are in a stream
fs | fs to act on Returns a long as a sample offset into stream |
Definition at line 694 of file file.c.
References ast_filestream::fmt, and ast_format::tell.
int ast_truncstream | ( | struct ast_filestream * | fs | ) |
Trunc stream at current location
fs | filestream to act on Returns 0 for success, or -1 for error |
Definition at line 689 of file file.c.
References ast_filestream::fmt, and ast_format::trunc.
int ast_waitstream | ( | struct ast_channel * | c, | |
const char * | breakon | |||
) |
Waits for a stream to stop or digit to be pressed
c | channel to waitstream on | |
breakon | string 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, Returns 0 if the stream finishes, the character if it was interrupted, and -1 on error |
Definition at line 1102 of file file.c.
References waitstream_core().
01103 { 01104 return waitstream_core(c, breakon, NULL, NULL, 0, -1, -1, NULL); 01105 }
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
c | channel to waitstream on | |
context | string 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, Returns 0 if the stream finishes, the character if it was interrupted, and -1 on error |
Definition at line 1113 of file file.c.
References ast_channel::context, and waitstream_core().
01114 { 01115 /* Waitstream, with return in the case of a valid 1 digit extension */ 01116 /* in the current or specified context being pressed */ 01117 01118 if (!context) 01119 context = c->context; 01120 return waitstream_core(c, NULL, NULL, NULL, 0, 01121 -1, -1, context); 01122 }
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
c | channel to waitstream on | |
breakon | string of DTMF digits to break upon | |
forward | DTMF digit to fast forward upon | |
rewind | DTMF digit to rewind upon | |
ms | How 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, Returns 0 if the stream finishes, the character if it was interrupted, and -1 on error |
Definition at line 1096 of file file.c.
References waitstream_core().
01097 { 01098 return waitstream_core(c, breakon, forward, rewind, ms, 01099 -1 /* no audiofd */, -1 /* no cmdfd */, NULL /* no context */); 01100 }
int ast_waitstream_full | ( | struct ast_channel * | c, | |
const char * | breakon, | |||
int | audiofd, | |||
int | monfd | |||
) |
Definition at line 1107 of file file.c.
References waitstream_core().
01108 { 01109 return waitstream_core(c, breakon, NULL, NULL, 0, 01110 audiofd, cmdfd, NULL /* no context */); 01111 }
struct ast_filestream* ast_writefile | ( | const char * | filename, | |
const char * | type, | |||
const char * | comment, | |||
int | flags, | |||
int | check, | |||
mode_t | mode | |||
) | [read] |
Starts writing a file
filename | the name of the file to write to | |
type | format of file you wish to write out to | |
comment | comment to go with | |
flags | output file flags | |
check | (unimplemented, hence negligible) | |
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. Returns a struct ast_filestream on success, NULL on failure |
Definition at line 864 of file file.c.
References ast_free, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_opt_cache_record_files, ast_strdupa, ast_filestream::buf, build_filename(), ast_format::exts, exts_compare(), f, ast_filestream::filename, ast_filestream::flags, ast_filestream::fmt, free, get_filestream(), LOG_WARNING, ast_filestream::mode, ast_filestream::realfilename, record_cache_dir, rewrite_wrapper(), ast_format::seek, strdup, ast_filestream::trans, and ast_filestream::vfs.
00865 { 00866 int fd, myflags = 0; 00867 /* compiler claims this variable can be used before initialization... */ 00868 FILE *bfile = NULL; 00869 struct ast_format *f; 00870 struct ast_filestream *fs = NULL; 00871 char *buf = NULL; 00872 size_t size = 0; 00873 int format_found = 0; 00874 00875 if (AST_LIST_LOCK(&formats)) { 00876 ast_log(LOG_WARNING, "Unable to lock format list\n"); 00877 return NULL; 00878 } 00879 00880 /* set the O_TRUNC flag if and only if there is no O_APPEND specified */ 00881 /* We really can't use O_APPEND as it will break WAV header updates */ 00882 if (flags & O_APPEND) { 00883 flags &= ~O_APPEND; 00884 } else { 00885 myflags = O_TRUNC; 00886 } 00887 00888 myflags |= O_WRONLY | O_CREAT; 00889 00890 /* XXX need to fix this - we should just do the fopen, 00891 * not open followed by fdopen() 00892 */ 00893 AST_LIST_TRAVERSE(&formats, f, list) { 00894 char *fn, *orig_fn = NULL; 00895 if (fs) 00896 break; 00897 00898 if (!exts_compare(f->exts, type)) 00899 continue; 00900 else 00901 format_found = 1; 00902 00903 fn = build_filename(filename, type); 00904 fd = open(fn, flags | myflags, mode); 00905 if (fd > -1) { 00906 /* fdopen() the resulting file stream */ 00907 bfile = fdopen(fd, ((flags | myflags) & O_RDWR) ? "w+" : "w"); 00908 if (!bfile) { 00909 ast_log(LOG_WARNING, "Whoa, fdopen failed: %s!\n", strerror(errno)); 00910 close(fd); 00911 fd = -1; 00912 } 00913 } 00914 00915 if (ast_opt_cache_record_files && (fd > -1)) { 00916 char *c; 00917 00918 fclose(bfile); /* this also closes fd */ 00919 /* 00920 We touch orig_fn just as a place-holder so other things (like vmail) see the file is there. 00921 What we are really doing is writing to record_cache_dir until we are done then we will mv the file into place. 00922 */ 00923 orig_fn = ast_strdupa(fn); 00924 for (c = fn; *c; c++) 00925 if (*c == '/') 00926 *c = '_'; 00927 00928 size = strlen(fn) + strlen(record_cache_dir) + 2; 00929 buf = alloca(size); 00930 strcpy(buf, record_cache_dir); 00931 strcat(buf, "/"); 00932 strcat(buf, fn); 00933 free(fn); 00934 fn = buf; 00935 fd = open(fn, flags | myflags, mode); 00936 if (fd > -1) { 00937 /* fdopen() the resulting file stream */ 00938 bfile = fdopen(fd, ((flags | myflags) & O_RDWR) ? "w+" : "w"); 00939 if (!bfile) { 00940 ast_log(LOG_WARNING, "Whoa, fdopen failed: %s!\n", strerror(errno)); 00941 close(fd); 00942 fd = -1; 00943 } 00944 } 00945 } 00946 if (fd > -1) { 00947 errno = 0; 00948 fs = get_filestream(f, bfile); 00949 if (!fs || rewrite_wrapper(fs, comment)) { 00950 ast_log(LOG_WARNING, "Unable to rewrite %s\n", fn); 00951 close(fd); 00952 if (orig_fn) { 00953 unlink(fn); 00954 unlink(orig_fn); 00955 } 00956 if (fs) 00957 ast_free(fs); 00958 fs = NULL; 00959 continue; 00960 } 00961 fs->trans = NULL; 00962 fs->fmt = f; 00963 fs->flags = flags; 00964 fs->mode = mode; 00965 if (orig_fn) { 00966 fs->realfilename = strdup(orig_fn); 00967 fs->filename = strdup(fn); 00968 } else { 00969 fs->realfilename = NULL; 00970 fs->filename = strdup(filename); 00971 } 00972 fs->vfs = NULL; 00973 /* If truncated, we'll be at the beginning; if not truncated, then append */ 00974 f->seek(fs, 0, SEEK_END); 00975 } else if (errno != EEXIST) { 00976 ast_log(LOG_WARNING, "Unable to open file %s: %s\n", fn, strerror(errno)); 00977 if (orig_fn) 00978 unlink(orig_fn); 00979 } 00980 /* if buf != NULL then fn is already free and pointing to it */ 00981 if (!buf) 00982 free(fn); 00983 } 00984 00985 AST_LIST_UNLOCK(&formats); 00986 00987 if (!format_found) 00988 ast_log(LOG_WARNING, "No such format '%s'\n", type); 00989 00990 return fs; 00991 }
int ast_writestream | ( | struct ast_filestream * | fs, | |
struct ast_frame * | f | |||
) |
Writes a frame to a stream
fs | filestream to write to | |
f | frame to write to the filestream Send a frame to a filestream -- note: does NOT free the frame, call ast_frfree manually Returns 0 on success, -1 on failure. |
Definition at line 154 of file file.c.
References AST_FORMAT_MAX_AUDIO, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_getformatname(), ast_log(), ast_translate(), ast_translator_build_path(), ast_translator_free_path(), ast_writefile(), ast_writestream(), ast_filestream::filename, ast_filestream::flags, ast_filestream::fmt, ast_format::format, ast_frame::frametype, ast_filestream::lastwriteformat, LOG_DEBUG, LOG_WARNING, ast_filestream::mode, ast_format::name, ast_frame::subclass, ast_filestream::trans, type, ast_filestream::vfs, and ast_format::write.
00155 { 00156 int res = -1; 00157 int alt = 0; 00158 if (f->frametype == AST_FRAME_VIDEO) { 00159 if (fs->fmt->format < AST_FORMAT_MAX_AUDIO) { 00160 /* This is the audio portion. Call the video one... */ 00161 if (!fs->vfs && fs->filename) { 00162 const char *type = ast_getformatname(f->subclass & ~0x1); 00163 fs->vfs = ast_writefile(fs->filename, type, NULL, fs->flags, 0, fs->mode); 00164 ast_log(LOG_DEBUG, "Opened video output file\n"); 00165 } 00166 if (fs->vfs) 00167 return ast_writestream(fs->vfs, f); 00168 /* else ignore */ 00169 return 0; 00170 } else { 00171 /* Might / might not have mark set */ 00172 alt = 1; 00173 } 00174 } else if (f->frametype != AST_FRAME_VOICE) { 00175 ast_log(LOG_WARNING, "Tried to write non-voice frame\n"); 00176 return -1; 00177 } 00178 if (((fs->fmt->format | alt) & f->subclass) == f->subclass) { 00179 res = fs->fmt->write(fs, f); 00180 if (res < 0) 00181 ast_log(LOG_WARNING, "Natural write failed\n"); 00182 else if (res > 0) 00183 ast_log(LOG_WARNING, "Huh??\n"); 00184 } else { 00185 /* XXX If they try to send us a type of frame that isn't the normal frame, and isn't 00186 the one we've setup a translator for, we do the "wrong thing" XXX */ 00187 if (fs->trans && f->subclass != fs->lastwriteformat) { 00188 ast_translator_free_path(fs->trans); 00189 fs->trans = NULL; 00190 } 00191 if (!fs->trans) 00192 fs->trans = ast_translator_build_path(fs->fmt->format, f->subclass); 00193 if (!fs->trans) 00194 ast_log(LOG_WARNING, "Unable to translate to format %s, source format %s\n", 00195 fs->fmt->name, ast_getformatname(f->subclass)); 00196 else { 00197 struct ast_frame *trf; 00198 fs->lastwriteformat = f->subclass; 00199 /* Get the translated frame but don't consume the original in case they're using it on another stream */ 00200 trf = ast_translate(fs->trans, f, 0); 00201 if (trf) { 00202 res = fs->fmt->write(fs, trf); 00203 if (res) 00204 ast_log(LOG_WARNING, "Translated frame write failed\n"); 00205 } else 00206 res = 0; 00207 } 00208 } 00209 return res; 00210 }