Bug #1087. Fix wav49 format so it can be played. Make file functions

looking for extension use f->exts instead of f->name.  Fix bug
where error message didn't print file extension. Fix comments in header file.
Everything is completely backwards compatible


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2247 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
James Golovich
2004-02-25 22:31:51 +00:00
parent 38198d8cb3
commit 462cfbe8ae
5 changed files with 34 additions and 16 deletions

View File

@@ -30,13 +30,13 @@ static char *app = "Record";
static char *synopsis = "Record to a file"; static char *synopsis = "Record to a file";
static char *descrip = static char *descrip =
" Record(filename:extension|silence): Records from the channel into a given\n" " Record(filename:format|silence): Records from the channel into a given\n"
"filename. If the file exists it will be overwritten. \n" "filename. If the file exists it will be overwritten. \n"
"- 'extension' is the extension of the file type to be recorded (wav, gsm, etc).\n" "- 'format' is the format of the file type to be recorded (wav, gsm, etc).\n"
"- 'silence' is the number of seconds of silence to allow before returning.\n\n" "- 'silence' is the number of seconds of silence to allow before returning.\n\n"
"If filename contains '%d', these characters will be replaced with a number\n" "If filename contains '%d', these characters will be replaced with a number\n"
"incremented by one each time the file is recorded. \n\n" "incremented by one each time the file is recorded. \n\n"
"Extensions: g723, g729, gsm, h263, ulaw, alaw, vox, wav, WAV\n\n" "Formats: g723, g729, gsm, h263, ulaw, alaw, vox, wav, WAV\n\n"
"Returns -1 when the user hangs up.\n"; "Returns -1 when the user hangs up.\n";
STANDARD_LOCAL_USER; STANDARD_LOCAL_USER;

24
file.c
View File

@@ -287,6 +287,22 @@ static char *build_filename(char *filename, char *ext)
} }
static int exts_compare(char *exts, char *type)
{
char *stringp = NULL, *ext;
char tmp[256];
strncpy(tmp, exts, sizeof(tmp) - 1);
stringp = tmp;
while ((ext = strsep(&stringp, "|"))) {
if (!strcmp(ext, type)) {
return 1;
}
}
return 0;
}
#define ACTION_EXISTS 1 #define ACTION_EXISTS 1
#define ACTION_DELETE 2 #define ACTION_DELETE 2
#define ACTION_RENAME 3 #define ACTION_RENAME 3
@@ -319,7 +335,7 @@ static int ast_filehelper(char *filename, char *filename2, char *fmt, int action
} }
f = formats; f = formats;
while(f) { while(f) {
if (!fmt || !strcasecmp(f->name, fmt)) { if (!fmt || exts_compare(f->exts, fmt)) {
char *stringp=NULL; char *stringp=NULL;
exts = strdup(f->exts); exts = strdup(f->exts);
/* Try each kind of extension */ /* Try each kind of extension */
@@ -376,7 +392,7 @@ static int ast_filehelper(char *filename, char *filename2, char *fmt, int action
chan->vstream = s; chan->vstream = s;
} else { } else {
close(ret); close(ret);
ast_log(LOG_WARNING, "Unable to open fd on %s\n", filename); ast_log(LOG_WARNING, "Unable to open fd on %s\n", fn);
} }
} else } else
ast_log(LOG_WARNING, "Couldn't open file %s\n", fn); ast_log(LOG_WARNING, "Couldn't open file %s\n", fn);
@@ -748,7 +764,7 @@ struct ast_filestream *ast_readfile(char *filename, char *type, char *comment, i
} }
f = formats; f = formats;
while(f) { while(f) {
if (!strcasecmp(f->name, type)) { if (exts_compare(f->exts, type)) {
char *stringp=NULL; char *stringp=NULL;
/* XXX Implement check XXX */ /* XXX Implement check XXX */
ext = strdup(f->exts); ext = strdup(f->exts);
@@ -803,7 +819,7 @@ struct ast_filestream *ast_writefile(char *filename, char *type, char *comment,
f = formats; f = formats;
while(f) { while(f) {
if (!strcasecmp(f->name, type)) { if (exts_compare(f->exts, type)) {
char *stringp=NULL; char *stringp=NULL;
/* XXX Implement check XXX */ /* XXX Implement check XXX */
ext = strdup(f->exts); ext = strdup(f->exts);

View File

@@ -47,7 +47,7 @@ static int glistcnt = 0;
static char *name = "g723sf"; static char *name = "g723sf";
static char *desc = "G.723.1 Simple Timestamp File Format"; static char *desc = "G.723.1 Simple Timestamp File Format";
static char *exts = "g723"; static char *exts = "g723|g723sf";
static struct ast_filestream *g723_open(int fd) static struct ast_filestream *g723_open(int fd)
{ {

View File

@@ -68,7 +68,7 @@ static int glistcnt = 0;
static char *name = "wav49"; static char *name = "wav49";
static char *desc = "Microsoft WAV format (Proprietary GSM)"; static char *desc = "Microsoft WAV format (Proprietary GSM)";
static char *exts = "WAV"; static char *exts = "WAV|wav49";
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
#define htoll(b) (b) #define htoll(b) (b)
@@ -199,10 +199,12 @@ static int check_header(int fd)
ast_log(LOG_WARNING, "Read failed (data)\n"); ast_log(LOG_WARNING, "Read failed (data)\n");
return -1; return -1;
} }
#if 0 /* Does this header actually exist? It doesn't appear to in the files that are created with ast_writefile using this format */
if (memcmp(&data, "data", 4)) { if (memcmp(&data, "data", 4)) {
ast_log(LOG_WARNING, "Does not say data\n"); ast_log(LOG_WARNING, "Does not say data\n");
return -1; return -1;
} }
#endif
/* Ignore the data length */ /* Ignore the data length */
if (read(fd, &data, 4) != 4) { if (read(fd, &data, 4) != 4) {
ast_log(LOG_WARNING, "Read failed (data)\n"); ast_log(LOG_WARNING, "Read failed (data)\n");

View File

@@ -142,19 +142,19 @@ char ast_waitstream_full(struct ast_channel *c, char *breakon, int audiofd, int
//! Starts reading from a file //! Starts reading from a file
/*! /*!
* \param filename the name of the file to write to * \param filename the name of the file to read from
* \param type format of file you wish to write out to * \param type format of file you wish to read from
* \param comment comment to go with * \param comment comment to go with
* \param oflags output file flags * \param flags file flags
* \param check (unimplemented, hence negligible) * \param check (unimplemented, hence negligible)
* \param mode Open mode * \param mode Open mode
* Open an incoming file stream. oflags are flags for the open() command, and * Open an incoming file stream. flags 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 * 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 * 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. * 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 * Returns a struct ast_filestream on success, NULL on failure
*/ */
struct ast_filestream *ast_readfile(char *filename, char *type, char *comment, int oflags, int check, mode_t mode); struct ast_filestream *ast_readfile(char *filename, char *type, char *comment, int flags, int check, mode_t mode);
//! Starts writing a file //! Starts writing a file
/*! /*!
@@ -170,7 +170,7 @@ struct ast_filestream *ast_readfile(char *filename, char *type, char *comment, i
* Please note, this is a blocking function. Program execution will not return until ast_waitstream completes it's execution. * 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 * Returns a struct ast_filestream on success, NULL on failure
*/ */
struct ast_filestream *ast_writefile(char *filename, char *type, char *comment, int oflags, int check, mode_t mode); struct ast_filestream *ast_writefile(char *filename, char *type, char *comment, int flags, int check, mode_t mode);
//! Writes a frame to a stream //! Writes a frame to a stream
/*! /*!