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

file.h File Reference

#include <asterisk/channel.h>
#include <asterisk/frame.h>
#include <fcntl.h>

Go to the source code of this file.

Defines

#define AST_DIGIT_ANY   "0123456789#*"
 Convenient for waiting.
#define SEEK_FORCECUR   10
#define AST_RESERVED_POINTERS   20

Functions

int ast_format_register (char *name, char *exts, int format, struct ast_filestream *(*open)(int fd), struct ast_filestream *(*rewrite)(int fd, char *comment), int(*write)(struct ast_filestream *, struct ast_frame *), int(*seek)(struct ast_filestream *, long offset, int whence), int(*trunc)(struct ast_filestream *), long(*tell)(struct ast_filestream *), struct ast_frame *(*read)(struct ast_filestream *, int *timetonext), void(*close)(struct ast_filestream *), char *(*getcomment)(struct ast_filestream *))
 Registers a new file format.
int ast_format_unregister (char *name)
 Unregisters a file format.
int ast_streamfile (struct ast_channel *c, char *filename, char *preflang)
 Streams a file.
int ast_stopstream (struct ast_channel *c)
 Stops a stream.
int ast_fileexists (char *filename, char *fmt, char *preflang)
 Checks for the existence of a given file.
int ast_filerename (char *oldname, char *newname, char *fmt)
 Renames a file.
int ast_filedelete (char *filename, char *fmt)
 Deletes a file.
int ast_filecopy (char *oldname, char *newname, char *fmt)
 Copies a file.
char ast_waitstream (struct ast_channel *c, char *breakon)
 Waits for a stream to stop or digit to be pressed.
char ast_waitstream_fr (struct ast_channel *c, char *breakon, char *forward, char *rewind, int ms)
 Same as waitstream but allows stream to be forwarded or rewound.
char ast_waitstream_full (struct ast_channel *c, char *breakon, int audiofd, int monfd)
ast_filestreamast_readfile (char *filename, char *type, char *comment, int flags, int check, mode_t mode)
 Starts reading from a file.
ast_filestreamast_writefile (char *filename, char *type, 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.
int ast_closestream (struct ast_filestream *f)
 Closes a stream.
ast_filestreamast_openstream (struct ast_channel *chan, char *filename, char *preflang)
 Opens stream for use in seeking, playing.
ast_filestreamast_openvstream (struct ast_channel *chan, char *filename, char *preflang)
 Opens stream for use in seeking, playing.
int ast_applystream (struct ast_channel *chan, struct ast_filestream *s)
 Applys a open stream to a channel.
int ast_playstream (struct ast_filestream *s)
 play a open stream on a channel.
int ast_seekstream (struct ast_filestream *fs, long sample_offset, int whence)
 Seeks into stream.
int ast_truncstream (struct ast_filestream *fs)
 Trunc stream at current location.
int ast_stream_fastforward (struct ast_filestream *fs, long ms)
 Fast forward stream ms.
int ast_stream_rewind (struct ast_filestream *fs, long ms)
 Rewind stream ms.
long ast_tellstream (struct ast_filestream *fs)
 Tell where we are in a stream.
ast_frameast_readframe (struct ast_filestream *s)
 Read a frame from a filestream.
int ast_file_init (void)
 Initialize file stuff.


Define Documentation

#define AST_DIGIT_ANY   "0123456789#*"
 

Convenient for waiting.

Definition at line 28 of file file.h.

Referenced by ast_readstring(), and ast_readstring_full().

#define AST_RESERVED_POINTERS   20
 

Definition at line 295 of file file.h.

#define SEEK_FORCECUR   10
 

Definition at line 30 of file file.h.

Referenced by ast_read(), and ast_write().


Function Documentation

int ast_applystream struct ast_channel chan,
struct ast_filestream s
 

Applys a open stream to a channel.

Parameters:
chan channel to work
ast_filestream s to apply Returns 0 for success, -1 on failure
Definition at line 605 of file file.c.

References s.

Referenced by ast_streamfile().

00606 { 00607 s->owner = chan; 00608 return 0; 00609 }

int ast_closestream struct ast_filestream f  ) 
 

Closes a stream.

Parameters:
f filestream to close Close a playback or recording stream Returns 0 on success, -1 on failure
Definition at line 650 of file file.c.

References AST_FORMAT_MAX_AUDIO, ast_sched_del(), ast_settimeout(), ast_translator_free_path(), ast_format::close, ast_filestream::filename, ast_filestream::fmt, ast_format::format, free, ast_filestream::owner, ast_channel::sched, ast_channel::stream, ast_channel::streamid, ast_filestream::trans, ast_channel::vstream, and ast_channel::vstreamid.

Referenced by ast_app_getvoice(), ast_hangup(), and ast_stopstream().

00651 { 00652 /* Stop a running stream if there is one */ 00653 if (f->owner) { 00654 if (f->fmt->format < AST_FORMAT_MAX_AUDIO) { 00655 f->owner->stream = NULL; 00656 if (f->owner->streamid > -1) 00657 ast_sched_del(f->owner->sched, f->owner->streamid); 00658 f->owner->streamid = -1; 00659 #ifdef ZAPTEL_OPTIMIZATIONS 00660 ast_settimeout(f->owner, 0, NULL, NULL); 00661 #endif 00662 } else { 00663 f->owner->vstream = NULL; 00664 if (f->owner->vstreamid > -1) 00665 ast_sched_del(f->owner->sched, f->owner->vstreamid); 00666 f->owner->vstreamid = -1; 00667 } 00668 } 00669 /* destroy the translator on exit */ 00670 if (f->trans) { 00671 ast_translator_free_path(f->trans); 00672 f->trans = NULL; 00673 } 00674 if (f->filename) 00675 free(f->filename); 00676 f->filename = NULL; 00677 f->fmt->close(f); 00678 return 0; 00679 }

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 1085 of file file.c.

References ast_cli_register(), and show_file.

Referenced by main().

01086 { 01087 ast_cli_register(&show_file); 01088 return 0; 01089 }

int ast_filecopy char *  oldname,
char *  newname,
char *  fmt
 

Copies a file.

Parameters:
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 732 of file file.c.

References ACTION_COPY.

00733 { 00734 return ast_filehelper(filename, filename2, fmt, ACTION_COPY); 00735 }

int ast_filedelete char *  filename,
char *  fmt
 

Deletes a file.

Parameters:
filename name of the file you wish to delete (minus the extension)
format of the file Delete a given file in a given format, or if fmt is NULL, then do so for all
Definition at line 722 of file file.c.

References ACTION_DELETE.

00723 { 00724 return ast_filehelper(filename, NULL, fmt, ACTION_DELETE); 00725 }

int ast_fileexists char *  filename,
char *  fmt,
char *  preflang
 

Checks for the existence of a given file.

Parameters:
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 682 of file file.c.

References ACTION_EXISTS, and MAX_LANGUAGE.

Referenced by ast_openstream(), and ast_openvstream().

00683 { 00684 char filename2[256]; 00685 char tmp[256]; 00686 char *postfix; 00687 char *prefix; 00688 char *c; 00689 char lang2[MAX_LANGUAGE]; 00690 int res = -1; 00691 if (preflang && !ast_strlen_zero(preflang)) { 00692 /* Insert the language between the last two parts of the path */ 00693 strncpy(tmp, filename, sizeof(tmp) - 1); 00694 c = strrchr(tmp, '/'); 00695 if (c) { 00696 *c = '\0'; 00697 postfix = c+1; 00698 prefix = tmp; 00699 } else { 00700 postfix = tmp; 00701 prefix=""; 00702 } 00703 snprintf(filename2, sizeof(filename2), "%s/%s/%s", prefix, preflang, postfix); 00704 res = ast_filehelper(filename2, NULL, fmt, ACTION_EXISTS); 00705 if (res < 1) { 00706 char *stringp=NULL; 00707 strncpy(lang2, preflang, sizeof(lang2)-1); 00708 stringp=lang2; 00709 strsep(&stringp, "_"); 00710 if (strcmp(lang2, preflang)) { 00711 snprintf(filename2, sizeof(filename2), "%s/%s/%s", prefix, lang2, postfix); 00712 res = ast_filehelper(filename2, NULL, fmt, ACTION_EXISTS); 00713 } 00714 } 00715 } 00716 if (res < 1) { 00717 res = ast_filehelper(filename, NULL, fmt, ACTION_EXISTS); 00718 } 00719 return res; 00720 }

int ast_filerename char *  oldname,
char *  newname,
char *  fmt
 

Renames a file.

Parameters:
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 727 of file file.c.

References ACTION_RENAME.

00728 { 00729 return ast_filehelper(filename, filename2, fmt, ACTION_RENAME); 00730 }

int ast_format_register char *  name,
char *  exts,
int  format,
struct ast_filestream *(*  open)(int fd),
struct ast_filestream *(*  rewrite)(int fd, char *comment),
int(*  write)(struct ast_filestream *, struct ast_frame *),
int(*  seek)(struct ast_filestream *, long offset, int whence),
int(*  trunc)(struct ast_filestream *),
long(*  tell)(struct ast_filestream *),
struct ast_frame *(*  read)(struct ast_filestream *, int *timetonext),
void(*  close)(struct ast_filestream *),
char *(*  getcomment)(struct ast_filestream *)
 

Registers a new file format.

Register a new file format capability Adds a format to asterisk's format abilities. Fill in the fields, and it will work. For examples, look at some of the various format code. returns 0 on success, -1 on failure

int ast_format_unregister char *  name  ) 
 

Unregisters a file format.

Parameters:
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 139 of file file.c.

References ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_verbose(), free, LOG_WARNING, ast_format::next, option_verbose, and VERBOSE_PREFIX_2.

00140 { 00141 struct ast_format *tmp, *tmpl = NULL; 00142 if (ast_mutex_lock(&formatlock)) { 00143 ast_log(LOG_WARNING, "Unable to lock format list\n"); 00144 return -1; 00145 } 00146 tmp = formats; 00147 while(tmp) { 00148 if (!strcasecmp(name, tmp->name)) { 00149 if (tmpl) 00150 tmpl->next = tmp->next; 00151 else 00152 formats = tmp->next; 00153 free(tmp); 00154 ast_mutex_unlock(&formatlock); 00155 if (option_verbose > 1) 00156 ast_verbose( VERBOSE_PREFIX_2 "Unregistered format %s\n", name); 00157 return 0; 00158 } 00159 tmpl = tmp; 00160 tmp = tmp->next; 00161 } 00162 ast_log(LOG_WARNING, "Tried to unregister format %s, already unregistered\n", name); 00163 return -1; 00164 }

struct ast_filestream* ast_openstream struct ast_channel chan,
char *  filename,
char *  preflang
 

Opens stream for use in seeking, playing.

Parameters:
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 433 of file file.c.

References ACTION_OPEN, ast_deactivate_generator(), ast_fileexists(), ast_log(), ast_set_write_format(), ast_stopstream(), ast_channel::generator, LOG_WARNING, ast_channel::oldwriteformat, and ast_channel::writeformat.

Referenced by ast_streamfile().

00434 { 00435 /* This is a fairly complex routine. Essentially we should do 00436 the following: 00437 00438 1) Find which file handlers produce our type of format. 00439 2) Look for a filename which it can handle. 00440 3) If we find one, then great. 00441 4) If not, see what files are there 00442 5) See what we can actually support 00443 6) Choose the one with the least costly translator path and 00444 set it up. 00445 00446 */ 00447 int fd = -1; 00448 int fmts = -1; 00449 char filename2[256]=""; 00450 char filename3[256]=""; 00451 char *endpart; 00452 int res; 00453 ast_stopstream(chan); 00454 /* do this first, otherwise we detect the wrong writeformat */ 00455 if (chan->generator) 00456 ast_deactivate_generator(chan); 00457 if (preflang && !ast_strlen_zero(preflang)) { 00458 strncpy(filename3, filename, sizeof(filename3) - 1); 00459 endpart = strrchr(filename3, '/'); 00460 if (endpart) { 00461 *endpart = '\0'; 00462 endpart++; 00463 snprintf(filename2, sizeof(filename2), "%s/%s/%s", filename3, preflang, endpart); 00464 } else 00465 snprintf(filename2, sizeof(filename2), "%s/%s", preflang, filename); 00466 fmts = ast_fileexists(filename2, NULL, NULL); 00467 } 00468 if (fmts < 1) { 00469 strncpy(filename2, filename, sizeof(filename2)-1); 00470 fmts = ast_fileexists(filename2, NULL, NULL); 00471 } 00472 if (fmts < 1) { 00473 ast_log(LOG_WARNING, "File %s does not exist in any format\n", filename); 00474 return NULL; 00475 } 00476 chan->oldwriteformat = chan->writeformat; 00477 /* Set the channel to a format we can work with */ 00478 res = ast_set_write_format(chan, fmts); 00479 00480 fd = ast_filehelper(filename2, (char *)chan, NULL, ACTION_OPEN); 00481 if(fd >= 0) 00482 return chan->stream; 00483 return NULL; 00484 }

struct ast_filestream* ast_openvstream struct ast_channel chan,
char *  filename,
char *  preflang
 

Opens stream for use in seeking, playing.

Parameters:
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 486 of file file.c.

References ACTION_OPEN, ast_fileexists(), ast_log(), LOG_WARNING, and MAX_LANGUAGE.

Referenced by ast_streamfile().

00487 { 00488 /* This is a fairly complex routine. Essentially we should do 00489 the following: 00490 00491 1) Find which file handlers produce our type of format. 00492 2) Look for a filename which it can handle. 00493 3) If we find one, then great. 00494 4) If not, see what files are there 00495 5) See what we can actually support 00496 6) Choose the one with the least costly translator path and 00497 set it up. 00498 00499 */ 00500 int fd = -1; 00501 int fmts = -1; 00502 char filename2[256]; 00503 char lang2[MAX_LANGUAGE]; 00504 /* XXX H.263 only XXX */ 00505 char *fmt = "h263"; 00506 if (preflang && !ast_strlen_zero(preflang)) { 00507 snprintf(filename2, sizeof(filename2), "%s/%s", preflang, filename); 00508 fmts = ast_fileexists(filename2, fmt, NULL); 00509 if (fmts < 1) { 00510 strncpy(lang2, preflang, sizeof(lang2)-1); 00511 snprintf(filename2, sizeof(filename2), "%s/%s", lang2, filename); 00512 fmts = ast_fileexists(filename2, fmt, NULL); 00513 } 00514 } 00515 if (fmts < 1) { 00516 strncpy(filename2, filename, sizeof(filename2)-1); 00517 fmts = ast_fileexists(filename2, fmt, NULL); 00518 } 00519 if (fmts < 1) { 00520 return NULL; 00521 } 00522 fd = ast_filehelper(filename2, (char *)chan, fmt, ACTION_OPEN); 00523 if(fd >= 0) 00524 return chan->vstream; 00525 ast_log(LOG_WARNING, "File %s has video but couldn't be opened\n", filename); 00526 return NULL; 00527 }

int ast_playstream struct ast_filestream s  ) 
 

play a open stream on a channel.

Parameters:
ast_filestream s to play Returns 0 for success, -1 on failure
Definition at line 611 of file file.c.

References AST_FORMAT_MAX_AUDIO, and s.

Referenced by ast_streamfile().

00612 { 00613 if (s->fmt->format < AST_FORMAT_MAX_AUDIO) 00614 ast_readaudio_callback(s); 00615 else 00616 ast_readvideo_callback(s); 00617 return 0; 00618 }

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

Starts reading from a file.

Parameters:
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 765 of file file.c.

References ast_log(), ast_mutex_lock, ast_mutex_unlock, free, LOG_WARNING, strdup, and type.

00766 { 00767 int fd,myflags = 0; 00768 struct ast_format *f; 00769 struct ast_filestream *fs=NULL; 00770 char *fn; 00771 char *ext; 00772 if (ast_mutex_lock(&formatlock)) { 00773 ast_log(LOG_WARNING, "Unable to lock format list\n"); 00774 return NULL; 00775 } 00776 f = formats; 00777 while(f) { 00778 if (exts_compare(f->exts, type)) { 00779 char *stringp=NULL; 00780 /* XXX Implement check XXX */ 00781 ext = strdup(f->exts); 00782 stringp=ext; 00783 ext = strsep(&stringp, "|"); 00784 fn = build_filename(filename, ext); 00785 fd = open(fn, flags | myflags); 00786 if (fd >= 0) { 00787 errno = 0; 00788 if ((fs = f->open(fd))) { 00789 fs->trans = NULL; 00790 fs->fmt = f; 00791 fs->flags = flags; 00792 fs->mode = mode; 00793 fs->filename = strdup(filename); 00794 fs->vfs = NULL; 00795 } else { 00796 ast_log(LOG_WARNING, "Unable to open %s\n", fn); 00797 close(fd); 00798 unlink(fn); 00799 } 00800 } else if (errno != EEXIST) 00801 ast_log(LOG_WARNING, "Unable to open file %s: %s\n", fn, strerror(errno)); 00802 free(fn); 00803 free(ext); 00804 break; 00805 } 00806 f = f->next; 00807 } 00808 ast_mutex_unlock(&formatlock); 00809 if (!f) 00810 ast_log(LOG_WARNING, "No such format '%s'\n", type); 00811 return fs; 00812 }

struct ast_frame* ast_readframe struct ast_filestream s  ) 
 

Read a frame from a filestream.

Parameters:
ast_filestream fs to act on Returns a frame or NULL if read failed
Definition at line 529 of file file.c.

References s.

00530 { 00531 struct ast_frame *f = NULL; 00532 int whennext = 0; 00533 if (s && s->fmt) 00534 f = s->fmt->read(s, &whennext); 00535 return f; 00536 }

int ast_seekstream struct ast_filestream fs,
long  sample_offset,
int  whence
 

Seeks into stream.

Parameters:
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 620 of file file.c.

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

Referenced by ast_read(), ast_stream_fastforward(), ast_stream_rewind(), and ast_write().

00621 { 00622 return fs->fmt->seek(fs, sample_offset, whence); 00623 }

int ast_stopstream struct ast_channel c  ) 
 

Stops a stream.

Parameters:
c The channel you wish to stop playback on Stop playback of a stream Returns 0 regardless
Definition at line 166 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.

Referenced by ast_control_streamfile(), ast_openstream(), ast_readstring(), ast_readstring_full(), ast_say_character_str(), ast_say_character_str_full(), ast_say_digit_str(), ast_say_digit_str_full(), ast_say_phonetic_str(), ast_say_phonetic_str_full(), ast_waitstream(), ast_waitstream_fr(), and ast_waitstream_full().

00167 { 00168 /* Stop a running stream if there is one */ 00169 if (tmp->vstream) 00170 ast_closestream(tmp->vstream); 00171 if (tmp->stream) { 00172 ast_closestream(tmp->stream); 00173 if (tmp->oldwriteformat && ast_set_write_format(tmp, tmp->oldwriteformat)) 00174 ast_log(LOG_WARNING, "Unable to restore format back to %d\n", tmp->oldwriteformat); 00175 } 00176 return 0; 00177 }

int ast_stream_fastforward struct ast_filestream fs,
long  ms
 

Fast forward stream ms.

Parameters:
ast_filestream fs filestream to act on
ms milliseconds to move Returns 0 for success, or -1 for error
Definition at line 635 of file file.c.

References ast_seekstream().

Referenced by ast_control_streamfile(), and ast_waitstream_fr().

00636 { 00637 /* I think this is right, 8000 samples per second, 1000 ms a second so 8 00638 * samples per ms */ 00639 long samples = ms * 8; 00640 return ast_seekstream(fs, samples, SEEK_CUR); 00641 }

int ast_stream_rewind struct ast_filestream fs,
long  ms
 

Rewind stream ms.

Parameters:
ast_filestream fs filestream to act on
ms milliseconds to move Returns 0 for success, or -1 for error
Definition at line 643 of file file.c.

References ast_seekstream().

Referenced by ast_waitstream_fr().

00644 { 00645 long samples = ms * 8; 00646 samples = samples * -1; 00647 return ast_seekstream(fs, samples, SEEK_CUR); 00648 }

int ast_streamfile struct ast_channel c,
char *  filename,
char *  preflang
 

Streams a file.

Parameters:
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 737 of file file.c.

References ast_applystream(), ast_getformatname(), ast_log(), ast_openstream(), ast_openvstream(), ast_playstream(), ast_verbose(), LOG_DEBUG, LOG_WARNING, ast_channel::nativeformats, option_verbose, and VERBOSE_PREFIX_3.

Referenced by ast_app_getdata(), ast_app_getdata_full(), ast_app_getvoice(), ast_control_streamfile(), ast_say_character_str(), ast_say_character_str_full(), ast_say_digit_str(), ast_say_digit_str_full(), ast_say_phonetic_str(), and ast_say_phonetic_str_full().

00738 { 00739 struct ast_filestream *fs; 00740 struct ast_filestream *vfs; 00741 00742 fs = ast_openstream(chan, filename, preflang); 00743 vfs = ast_openvstream(chan, filename, preflang); 00744 if (vfs) 00745 ast_log(LOG_DEBUG, "Ooh, found a video stream, too\n"); 00746 if(fs){ 00747 if(ast_applystream(chan, fs)) 00748 return -1; 00749 if(vfs && ast_applystream(chan, vfs)) 00750 return -1; 00751 if(ast_playstream(fs)) 00752 return -1; 00753 if(vfs && ast_playstream(vfs)) 00754 return -1; 00755 #if 1 00756 if (option_verbose > 2) 00757 ast_verbose(VERBOSE_PREFIX_3 "Playing '%s' (language '%s')\n", filename, preflang ? preflang : "default"); 00758 #endif 00759 return 0; 00760 } 00761 ast_log(LOG_WARNING, "Unable to open %s (format %s): %s\n", filename, ast_getformatname(chan->nativeformats), strerror(errno)); 00762 return -1; 00763 }

long ast_tellstream struct ast_filestream fs  ) 
 

Tell where we are in a stream.

Parameters:
ast_filestream fs to act on Returns a long as a sample offset into stream
Definition at line 630 of file file.c.

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

00631 { 00632 return fs->fmt->tell(fs); 00633 }

int ast_truncstream struct ast_filestream fs  ) 
 

Trunc stream at current location.

Parameters:
ast_filestream fs Returns 0 for success, or -1 for error
Definition at line 625 of file file.c.

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

00626 { 00627 return fs->fmt->trunc(fs); 00628 }

char ast_waitstream struct ast_channel c,
char *  breakon
 

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

Parameters:
c channel to waitstram 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 869 of file file.c.

References ast_channel::_softhangup, AST_CONTROL_ANSWER, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, AST_FRAME_CONTROL, AST_FRAME_DTMF, ast_frfree(), ast_log(), ast_read(), ast_sched_runq(), ast_sched_wait(), ast_stopstream(), ast_waitfor(), LOG_DEBUG, LOG_WARNING, ast_channel::sched, ast_channel::stream, and ast_channel::timingfunc.

Referenced by ast_app_getvoice(), ast_readstring(), ast_say_character_str(), ast_say_digit_str(), and ast_say_phonetic_str().

00870 { 00871 /* XXX Maybe I should just front-end ast_waitstream_full ? XXX */ 00872 int res; 00873 struct ast_frame *fr; 00874 if (!breakon) breakon = ""; 00875 while(c->stream) { 00876 res = ast_sched_wait(c->sched); 00877 if ((res < 0) && !c->timingfunc) { 00878 ast_stopstream(c); 00879 break; 00880 } 00881 if (res < 0) 00882 res = 1000; 00883 res = ast_waitfor(c, res); 00884 if (res < 0) { 00885 ast_log(LOG_WARNING, "Select failed (%s)\n", strerror(errno)); 00886 return res; 00887 } else if (res > 0) { 00888 fr = ast_read(c); 00889 if (!fr) { 00890 #if 0 00891 ast_log(LOG_DEBUG, "Got hung up\n"); 00892 #endif 00893 return -1; 00894 } 00895 00896 switch(fr->frametype) { 00897 case AST_FRAME_DTMF: 00898 res = fr->subclass; 00899 if (strchr(breakon, res)) { 00900 ast_frfree(fr); 00901 return res; 00902 } 00903 break; 00904 case AST_FRAME_CONTROL: 00905 switch(fr->subclass) { 00906 case AST_CONTROL_HANGUP: 00907 ast_frfree(fr); 00908 return -1; 00909 case AST_CONTROL_RINGING: 00910 case AST_CONTROL_ANSWER: 00911 /* Unimportant */ 00912 break; 00913 default: 00914 ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", fr->subclass); 00915 } 00916 } 00917 /* Ignore */ 00918 ast_frfree(fr); 00919 } 00920 ast_sched_runq(c->sched); 00921 } 00922 return (c->_softhangup ? -1 : 0); 00923 }

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

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

Parameters:
c channel to waitstram 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 925 of file file.c.

References ast_channel::_softhangup, AST_CONTROL_ANSWER, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, AST_FRAME_CONTROL, AST_FRAME_DTMF, ast_frfree(), ast_log(), ast_read(), ast_sched_runq(), ast_sched_wait(), ast_stopstream(), ast_stream_fastforward(), ast_stream_rewind(), ast_waitfor(), LOG_DEBUG, LOG_WARNING, ast_channel::sched, ast_channel::stream, and ast_channel::timingfunc.

Referenced by ast_control_streamfile().

00926 { 00927 int res; 00928 struct ast_frame *fr; 00929 while(c->stream) { 00930 res = ast_sched_wait(c->sched); 00931 if ((res < 0) && !c->timingfunc) { 00932 ast_stopstream(c); 00933 break; 00934 } 00935 if (res < 0) 00936 res = 1000; 00937 res = ast_waitfor(c, res); 00938 if (res < 0) { 00939 ast_log(LOG_WARNING, "Select failed (%s)\n", strerror(errno)); 00940 return res; 00941 } else 00942 if (res > 0) { 00943 fr = ast_read(c); 00944 if (!fr) { 00945 #if 0 00946 ast_log(LOG_DEBUG, "Got hung up\n"); 00947 #endif 00948 return -1; 00949 } 00950 00951 switch(fr->frametype) { 00952 case AST_FRAME_DTMF: 00953 res = fr->subclass; 00954 if (strchr(forward,res)) { 00955 ast_stream_fastforward(c->stream, ms); 00956 } else if (strchr(rewind,res)) { 00957 ast_stream_rewind(c->stream, ms); 00958 } else if (strchr(breakon, res)) { 00959 ast_frfree(fr); 00960 return res; 00961 } 00962 break; 00963 case AST_FRAME_CONTROL: 00964 switch(fr->subclass) { 00965 case AST_CONTROL_HANGUP: 00966 ast_frfree(fr); 00967 return -1; 00968 case AST_CONTROL_RINGING: 00969 case AST_CONTROL_ANSWER: 00970 /* Unimportant */ 00971 break; 00972 default: 00973 ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", fr->subclass); 00974 } 00975 } 00976 /* Ignore */ 00977 ast_frfree(fr); 00978 } else 00979 ast_sched_runq(c->sched); 00980 00981 00982 } 00983 return (c->_softhangup ? -1 : 0); 00984 }

char ast_waitstream_full struct ast_channel c,
char *  breakon,
int  audiofd,
int  monfd
 

Definition at line 986 of file file.c.

References ast_channel::_softhangup, AST_CONTROL_ANSWER, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_VOICE, ast_frfree(), ast_log(), ast_read(), ast_sched_runq(), ast_sched_wait(), ast_stopstream(), ast_waitfor_nandfds(), LOG_DEBUG, LOG_WARNING, ast_channel::sched, ast_channel::stream, and ast_channel::timingfunc.

Referenced by ast_readstring_full(), ast_say_character_str_full(), ast_say_digit_str_full(), and ast_say_phonetic_str_full().

00987 { 00988 int res; 00989 int ms; 00990 int outfd; 00991 struct ast_frame *fr; 00992 struct ast_channel *rchan; 00993 00994 while(c->stream) { 00995 ms = ast_sched_wait(c->sched); 00996 if ((ms < 0) && !c->timingfunc) { 00997 ast_stopstream(c); 00998 break; 00999 } 01000 if (ms < 0) 01001 ms = 1000; 01002 rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms); 01003 if (!rchan && (outfd < 0) && (ms)) { 01004 ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno)); 01005 return -1; 01006 } else if (outfd > -1) { 01007 /* The FD we were watching has something waiting */ 01008 return 1; 01009 } else if (rchan) { 01010 fr = ast_read(c); 01011 if (!fr) { 01012 #if 0 01013 ast_log(LOG_DEBUG, "Got hung up\n"); 01014 #endif 01015 return -1; 01016 } 01017 01018 switch(fr->frametype) { 01019 case AST_FRAME_DTMF: 01020 res = fr->subclass; 01021 if (strchr(breakon, res)) { 01022 ast_frfree(fr); 01023 return res; 01024 } 01025 break; 01026 case AST_FRAME_CONTROL: 01027 switch(fr->subclass) { 01028 case AST_CONTROL_HANGUP: 01029 ast_frfree(fr); 01030 return -1; 01031 case AST_CONTROL_RINGING: 01032 case AST_CONTROL_ANSWER: 01033 /* Unimportant */ 01034 break; 01035 default: 01036 ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", fr->subclass); 01037 } 01038 case AST_FRAME_VOICE: 01039 /* Write audio if appropriate */ 01040 if (audiofd > -1) 01041 write(audiofd, fr->data, fr->datalen); 01042 } 01043 /* Ignore */ 01044 ast_frfree(fr); 01045 } 01046 ast_sched_runq(c->sched); 01047 01048 01049 } 01050 return (c->_softhangup ? -1 : 0); 01051 }

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

Starts writing a file.

Parameters:
filename the name of the file to write to
type format of file you wish to write out to
comment comment to go with
oflags 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 814 of file file.c.

References ast_log(), ast_mutex_lock, ast_mutex_unlock, free, LOG_WARNING, strdup, and type.

Referenced by ast_app_getvoice(), and ast_writestream().

00815 { 00816 int fd,myflags = 0; 00817 struct ast_format *f; 00818 struct ast_filestream *fs=NULL; 00819 char *fn; 00820 char *ext; 00821 if (ast_mutex_lock(&formatlock)) { 00822 ast_log(LOG_WARNING, "Unable to lock format list\n"); 00823 return NULL; 00824 } 00825 /* set the O_TRUNC flag if and only if there is no O_APPEND specified */ 00826 if (!(flags & O_APPEND)) 00827 myflags = O_TRUNC; 00828 00829 myflags |= O_WRONLY | O_CREAT; 00830 00831 f = formats; 00832 while(f) { 00833 if (exts_compare(f->exts, type)) { 00834 char *stringp=NULL; 00835 /* XXX Implement check XXX */ 00836 ext = strdup(f->exts); 00837 stringp=ext; 00838 ext = strsep(&stringp, "|"); 00839 fn = build_filename(filename, ext); 00840 fd = open(fn, flags | myflags, mode); 00841 if (fd >= 0) { 00842 errno = 0; 00843 if ((fs = f->rewrite(fd, comment))) { 00844 fs->trans = NULL; 00845 fs->fmt = f; 00846 fs->flags = flags; 00847 fs->mode = mode; 00848 fs->filename = strdup(filename); 00849 fs->vfs = NULL; 00850 } else { 00851 ast_log(LOG_WARNING, "Unable to rewrite %s\n", fn); 00852 close(fd); 00853 unlink(fn); 00854 } 00855 } else if (errno != EEXIST) 00856 ast_log(LOG_WARNING, "Unable to open file %s: %s\n", fn, strerror(errno)); 00857 free(fn); 00858 free(ext); 00859 break; 00860 } 00861 f = f->next; 00862 } 00863 ast_mutex_unlock(&formatlock); 00864 if (!f) 00865 ast_log(LOG_WARNING, "No such format '%s'\n", type); 00866 return fs; 00867 }

int ast_writestream struct ast_filestream fs,
struct ast_frame f
 

Writes a frame to a stream.

Parameters:
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 179 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_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.

Referenced by ast_read(), and ast_write().

00180 { 00181 struct ast_frame *trf; 00182 int res = -1; 00183 int alt=0; 00184 if (f->frametype == AST_FRAME_VIDEO) { 00185 if (fs->fmt->format < AST_FORMAT_MAX_AUDIO) { 00186 /* This is the audio portion. Call the video one... */ 00187 if (!fs->vfs && fs->filename) { 00188 /* XXX Support other video formats XXX */ 00189 char *type = "h263"; 00190 fs->vfs = ast_writefile(fs->filename, type, NULL, fs->flags, 0, fs->mode); 00191 ast_log(LOG_DEBUG, "Opened video output file\n"); 00192 } 00193 if (fs->vfs) 00194 return ast_writestream(fs->vfs, f); 00195 /* Ignore */ 00196 return 0; 00197 } else { 00198 /* Might / might not have mark set */ 00199 alt = 1; 00200 } 00201 } else if (f->frametype != AST_FRAME_VOICE) { 00202 ast_log(LOG_WARNING, "Tried to write non-voice frame\n"); 00203 return -1; 00204 } 00205 if (((fs->fmt->format | alt) & f->subclass) == f->subclass) { 00206 res = fs->fmt->write(fs, f); 00207 if (res < 0) 00208 ast_log(LOG_WARNING, "Natural write failed\n"); 00209 if (res > 0) 00210 ast_log(LOG_WARNING, "Huh??\n"); 00211 return res; 00212 } else { 00213 /* XXX If they try to send us a type of frame that isn't the normal frame, and isn't 00214 the one we've setup a translator for, we do the "wrong thing" XXX */ 00215 if (fs->trans && (f->subclass != fs->lastwriteformat)) { 00216 ast_translator_free_path(fs->trans); 00217 fs->trans = NULL; 00218 } 00219 if (!fs->trans) 00220 fs->trans = ast_translator_build_path(fs->fmt->format, f->subclass); 00221 if (!fs->trans) 00222 ast_log(LOG_WARNING, "Unable to translate to format %s, source format %s\n", fs->fmt->name, ast_getformatname(f->subclass)); 00223 else { 00224 fs->lastwriteformat = f->subclass; 00225 res = 0; 00226 /* Get the translated frame but don't consume the original in case they're using it on another stream */ 00227 trf = ast_translate(fs->trans, f, 0); 00228 if (trf) { 00229 res = fs->fmt->write(fs, trf); 00230 if (res) 00231 ast_log(LOG_WARNING, "Translated frame write failed\n"); 00232 } else 00233 res = 0; 00234 } 00235 return res; 00236 } 00237 }


Generated on Tue Aug 17 16:13:55 2004 for Asterisk by doxygen 1.3.8