73 if (!strcasecmp(f->
name, tmp->
name)) {
90 struct _test_align {
void *a, *b; } p;
91 int align = (
char *)&p.b - (
char *)&p.a;
95 memset(&tmp->
list, 0,
sizeof(tmp->
list));
99 ast_verb(2,
"Registered file format %s, extension(s) %s\n", f->
name, f->
exts);
111 if (!strcasecmp(name, tmp->
name)) {
121 ast_verb(2,
"Unregistered format %s\n", name);
160 ast_debug(1,
"Opened video output file\n");
201 if ((res = fs->
fmt->
write(fs, trf))) {
215 static int copy(
const char *infile,
const char *outfile)
220 if ((ifd = open(infile, O_RDONLY)) < 0) {
224 if ((ofd = open(outfile, O_WRONLY | O_TRUNC | O_CREAT,
AST_FILE_MODE)) < 0) {
229 while ( (len = read(ifd, buf,
sizeof(buf)) ) ) {
236 res = write(ofd, buf, len);
262 if (!strcmp(ext,
"wav49"))
265 if (filename[0] ==
'/') {
283 char *stringp = tmp, *
ext;
286 while ((ext =
strsep(&stringp,
"|"))) {
287 if (!strcmp(ext, type))
342 waitpid(pid, &status, 0);
373 s->
buf = (
char *)(s + 1);
437 char *stringp, *
ext = NULL;
447 while ( (ext =
strsep(&stringp,
"|")) ) {
454 if ( stat(fn, &st) ) {
472 if ( (bfile = fopen(fn,
"r")) == NULL) {
487 if (st.st_size == 0) {
517 if ( (res = unlink(fn)) )
531 fn, nfn, strerror(
errno));
549 return filename[0] ==
'/';
553 char *
buf,
int buflen)
561 snprintf(buf, buflen,
"%s/%s", lang, filename);
563 snprintf(buf, buflen,
"%s", filename);
566 strcpy(buf, filename);
569 const char *c = strrchr(filename,
'/');
570 int offset = c ? c - filename + 1 : 0;
571 snprintf(buf + offset, buflen - offset,
"%s/%s", lang, filename + offset);
587 char *
buf,
int buflen)
613 if ((end = strrchr(lang,
'_')) != NULL) {
658 if (preflang == NULL)
660 buflen = strlen(preflang) + strlen(filename) + 4;
690 if (preflang == NULL)
692 buflen = strlen(preflang) + strlen(filename) + 4;
720 if (!(fr = s->
fmt->
read(s, whennext))) {
783 rate = (
unsigned int)
roundf(samp_rate / ((
float) whennext));
881 return fs->
fmt->
seek(fs, sample_offset, whence);
924 if (preflang == NULL)
926 buflen = strlen(preflang) + strlen(filename) + 4;
965 seekattempt = fseeko(fs->
f, -1, SEEK_END);
967 if (
errno == EINVAL) {
974 fseeko(fs->
f, pos, SEEK_SET);
1003 int format_found = 0;
1019 bfile = fopen(fn,
"r");
1051 int fd, myflags = 0;
1058 int format_found = 0;
1064 if (flags & O_APPEND) {
1070 myflags |= O_WRONLY | O_CREAT;
1076 char *fn, *orig_fn = NULL;
1089 fd = open(fn, flags | myflags, mode);
1092 bfile = fdopen(fd, ((flags | myflags) & O_RDWR) ?
"w+" :
"w");
1109 for (c = fn; *c; c++)
1120 fd = open(fn, flags | myflags, mode);
1123 bfile = fdopen(fd, ((flags | myflags) & O_RDWR) ?
"w+" :
"w");
1168 f->
seek(fs, 0, SEEK_END);
1169 }
else if (
errno != EEXIST) {
1191 const char *forward,
const char *reverse,
int skip_ms,
1192 int audiofd,
int cmdfd,
const char *
context)
1214 if (orig_chan_name && strcasecmp(orig_chan_name, c->
name)) {
1222 if (ms < 0 && !c->timingfunc) {
1238 if (!rchan && (outfd < 0) && (ms)) {
1245 }
else if (outfd > -1) {
1251 res = rchan ? 1 : 0;
1272 if (strchr(forward, res)) {
1275 eoftest = fgetc(c->
stream->
f);
1279 ungetc(eoftest, c->
stream->
f);
1281 }
else if (strchr(reverse, res)) {
1283 }
else if (strchr(breakon, res)) {
1351 audiofd, cmdfd, NULL );
1387 char *stringp, *
type;
1389 int i, j, x,
first, found = 0;
1390 int len = strlen(fmts) + 1;
1418 for (i = 0; i < x; i++) {
1427 res = snprintf(fmts, len,
"%s", fmts_str[i]);
1435 for (j = 0; j < i; j++) {
1437 if (fmts_ptr[j] == fmts_ptr[i]) {
1444 res = snprintf(fmts, len,
"|%s", fmts_str[i]);
1460 #define FORMAT "%-10s %-10s %-20s\n"
1461 #define FORMAT2 "%-10s %-10s %-20s\n"
1467 e->
command =
"core show file formats";
1469 "Usage: core show file formats\n"
1470 " Displays currently registered file formats (if any).\n";
1488 ast_cli(a->
fd,
"%d file formats registered.\n", count_fmt);
int ast_filecopy(const char *oldname, const char *newname, const char *fmt)
Copies a file.
static enum fsread_res ast_readvideo_callback(struct ast_filestream *s)
union ast_frame_subclass subclass
#define ast_channel_lock(chan)
static char exten[AST_MAX_EXTENSION]
Main Channel structure associated with a channel.
#define AST_CLI_DEFINE(fn, txt,...)
char * str
Subscriber phone number (Malloced)
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
static format_t fileexists_test(const char *filename, const char *fmt, const char *lang, char *buf, int buflen)
void ast_module_unref(struct ast_module *)
struct ast_party_caller caller
Channel Caller ID information.
char * strsep(char **str, const char *delims)
int ast_safe_fork(int stop_reaper)
Common routine to safely fork without a chance of a signal handler firing badly in the child...
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
#define ast_test_flag(p, flag)
Support for translation of data formats. translate.c.
static struct ast_cli_entry cli_file[]
int ast_sched_add(struct sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
Adds a scheduled event Schedule an event to take place at some point in the future. callback will be called with data as the argument, when milliseconds into the future (approximately) If callback returns 0, no further events will be re-scheduled.
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
char context[AST_MAX_CONTEXT]
#define ast_set_flag(p, flag)
static void filestream_close(struct ast_filestream *f)
descriptor for a cli entry.
static format_t fileexists_core(const char *filename, const char *fmt, const char *preflang, char *buf, int buflen)
helper routine to locate a file with a given format and language preference. Try preflang, preflang with stripped '_' suffices, or NULL.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
int ast_settimeout_full(struct ast_channel *c, unsigned int rate, int(*func)(const void *data), void *data, unsigned int is_ao2_obj)
struct ast_generator * generator
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
static int rewrite_wrapper(struct ast_filestream *s, const char *comment)
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
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)
the core of all waitstream() functions
static char * handle_cli_core_show_file_formats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static force_inline int ast_format_rate(format_t format)
Get the sample rate for a given format.
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.
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...
struct ast_frame * ast_frisolate(struct ast_frame *fr)
Makes a frame independent of any static storage.
int ast_filedelete(const char *filename, const char *fmt)
Deletes a file.
void ast_cli(int fd, const char *fmt,...)
static void file_shutdown(void)
struct ast_channel * ast_waitfor_nandfds(struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms)
Waits for activity on a group of channels.
#define ast_verb(level,...)
static int ast_fsread_video(const void *data)
int ast_stream_fastforward(struct ast_filestream *fs, off_t ms)
Fast forward stream ms.
static int open_wrapper(struct ast_filestream *s)
off_t ast_tellstream(struct ast_filestream *fs)
Tell where we are in a stream.
struct ast_trans_pvt * ast_translator_build_path(format_t dest, format_t source)
Builds a translator path Build a path (possibly NULL) from source to dest.
struct ast_party_id id
Caller party ID.
int ast_set_write_format(struct ast_channel *chan, format_t format)
Sets write format on channel chan Set write format for channel to whichever component of "format" is ...
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
#define ast_asprintf(a, b, c...)
static int exts_compare(const char *exts, const char *type)
#define AST_RWLIST_INSERT_HEAD
#define ast_debug(level,...)
Log a DEBUG message.
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...
static int fn_wrapper(struct ast_filestream *s, const char *comment, enum wrap_fn mode)
static int is_absolute_path(const char *filename)
int ast_playstream(struct ast_filestream *s)
Play a open stream on a channel.
struct ast_filestream * ast_openvstream(struct ast_channel *chan, const char *filename, const char *preflang)
Opens stream for use in seeking, playing.
General Asterisk PBX channel definitions.
#define AST_SCHED_DEL(sched, id)
a loop construct to ensure that the scheduled task get deleted. The idea is that if we loop attemptin...
Asterisk file paths, configured in asterisk.conf.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
int ast_language_is_prefix
#define AST_RWLIST_TRAVERSE
int ast_settimeout(struct ast_channel *c, unsigned int rate, int(*func)(const void *data), void *data)
Enable or disable timer ticks for a channel.
Scheduler Routines (derived from cheops)
#define ao2_ref(o, delta)
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
const char * orig_chan_name
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
#define AST_RWLIST_REMOVE_CURRENT
static format_t ast_filehelper(const char *filename, const void *arg2, const char *fmt, const enum file_action action)
perform various actions on a file. Second argument arg2 depends on the command: unused for EXISTS and...
struct sched_context * sched
A set of macros to manage forward-linked lists.
char * ast_format_str_reduce(char *fmts)
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_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Core PBX routines and definitions.
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
#define ast_test_suite_event_notify(s, f,...)
const char * ast_config_AST_DATA_DIR
#define ast_strdupa(s)
duplicate a string in memory from the stack
char * ast_getformatname(format_t format)
Get the name of a format.
int ast_applystream(struct ast_channel *chan, struct ast_filestream *s)
Applys a open stream to a channel.
struct ast_frame * ast_readframe(struct ast_filestream *s)
Read a frame from a filestream.
int ast_stream_rewind(struct ast_filestream *fs, off_t ms)
Rewind stream ms.
struct ast_channel * owner
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
const ast_string_field name
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.
struct sla_ringing_trunk * first
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
#define ao2_alloc(data_size, destructor_fn)
#define AST_FORMAT_FIRST_VIDEO_BIT
int ast_seekstream(struct ast_filestream *fs, off_t sample_offset, int whence)
Seeks into stream.
struct ast_trans_pvt * trans
#define AST_FORMAT_VIDEO_MASK
#define ast_channel_unlock(chan)
#define ast_opt_cache_record_files
struct ast_filestream * vstream
#define AST_FORMAT_AUDIO_MASK
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_closestream(struct ast_filestream *f)
Closes a stream.
static struct ast_frame * read_frame(struct ast_filestream *s, int *whennext)
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Prototypes for public functions only of internal interest,.
if(yyss+yystacksize-1<=yyssp)
#define ast_clear_flag(p, flag)
int ast_truncstream(struct ast_filestream *fs)
Trunc stream at current location.
int ast_sched_runq(struct sched_context *con)
Runs the queue.
char record_cache_dir[AST_CACHE_DIR_LEN]
void ast_deactivate_generator(struct ast_channel *chan)
int ast_waitstream_full(struct ast_channel *c, const char *breakon, int audiofd, int monfd)
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Standard Command Line Interface.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
int ast_writestream(struct ast_filestream *fs, struct ast_frame *f)
Writes a frame to a stream.
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
int ast_fileexists(const char *filename, const char *fmt, const char *preflang)
Checks for the existence of a given file.
#define DEFAULT_SAMPLES_PER_MS
int ast_sched_wait(struct sched_context *con) attribute_warn_unused_result
Determines number of seconds until the next outstanding event to take place Determine the number of s...
static int ast_fsread_audio(const void *data)
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
char * ast_getformatname_multiple(char *buf, size_t size, format_t format)
Get the names of a set of formats.
Data structure associated with a single frame of data.
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.
static enum fsread_res ast_readaudio_callback(struct ast_filestream *s)
int ast_filerename(const char *oldname, const char *newname, const char *fmt)
Renames a file.
enum ast_frame_type frametype
static int copy(const char *infile, const char *outfile)
struct ast_filestream * vfs
static char context[AST_MAX_CONTEXT]
static void filestream_destructor(void *arg)
struct ast_filestream * stream
Asterisk module definitions.
static snd_pcm_format_t format
union ast_frame::@172 data
unsigned char valid
TRUE if the number information is valid/present.
#define AST_RWLIST_TRAVERSE_SAFE_END
const ast_string_field language
int ast_stopstream(struct ast_channel *c)
Stops a stream.
static struct ast_filestream * get_filestream(struct ast_format *fmt, FILE *bfile)
struct ast_filestream * ast_openstream(struct ast_channel *chan, const char *filename, const char *preflang)
Opens stream for use in seeking, playing.
void ast_translator_free_path(struct ast_trans_pvt *tr)
Frees a translator path Frees the given translator path structure.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
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.
struct ast_module * ast_module_ref(struct ast_module *)
struct ast_party_number number
Subscriber phone number.