aboutsummaryrefslogtreecommitdiffstats
path: root/formats
diff options
context:
space:
mode:
authorbbryant <bbryant@f38db490-d61c-443f-a65b-d21fe96a405b>2010-09-09 18:51:52 +0000
committerbbryant <bbryant@f38db490-d61c-443f-a65b-d21fe96a405b>2010-09-09 18:51:52 +0000
commit722eb3c4c3cfa1c0cee915c949c5f95199ee24dd (patch)
tree25683963c5e51bdedd6211cd0ea92a85639505c3 /formats
parent815b5b09da5e555add7bba3d8fca588e7611248a (diff)
Merged revisions 285710 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ........ r285710 | bbryant | 2010-09-09 14:50:13 -0400 (Thu, 09 Sep 2010) | 8 lines Fixes an issue with dialplan pattern matching where the specificity for pattern ranges and pattern special characters was inconsistent. (closes issue #16903) Reported by: Nick_Lewis Patches: pbx.c-specificity.patch uploaded by Nick Lewis (license 657) Tested by: Nick_Lewis ........ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.8@285711 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'formats')
-rw-r--r--formats/format_wav.c69
1 files changed, 53 insertions, 16 deletions
diff --git a/formats/format_wav.c b/formats/format_wav.c
index 37d81e58a..91a309ef4 100644
--- a/formats/format_wav.c
+++ b/formats/format_wav.c
@@ -39,6 +39,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#define WAV_BUF_SIZE 320
struct wav_desc { /* format-specific parameters */
+ int hz;
int bytes;
int lasttimeout;
int maxlen;
@@ -70,7 +71,7 @@ struct wav_desc { /* format-specific parameters */
#endif
-static int check_header(FILE *f)
+static int check_header(FILE *f, int hz)
{
int type, size, formtype;
int fmt, hsize;
@@ -135,8 +136,10 @@ static int check_header(FILE *f)
ast_log(LOG_WARNING, "Read failed (freq)\n");
return -1;
}
- if (ltohl(freq) != DEFAULT_SAMPLE_RATE) {
- ast_log(LOG_WARNING, "Unexpected frequency %d\n", ltohl(freq));
+ if (((ltohl(freq) != 8000) && (ltohl(freq) != 16000)) ||
+ ((ltohl(freq) == 8000) && (hz != 8000)) ||
+ ((ltohl(freq) == 16000) && (hz != 16000))) {
+ ast_log(LOG_WARNING, "Unexpected frequency mismatch %d (expecting %d)\n", ltohl(freq),hz);
return -1;
}
/* Ignore the byte frequency */
@@ -239,16 +242,24 @@ static int update_header(FILE *f)
return 0;
}
-static int write_header(FILE *f)
+static int write_header(FILE *f, int writehz)
{
- unsigned int hz=htoll(8000);
- unsigned int bhz = htoll(16000);
+ unsigned int hz;
+ unsigned int bhz;
unsigned int hs = htoll(16);
unsigned short fmt = htols(1);
unsigned short chans = htols(1);
unsigned short bysam = htols(2);
unsigned short bisam = htols(16);
unsigned int size = htoll(0);
+
+ if (writehz == 16000) {
+ hz = htoll(16000);
+ bhz = htoll(32000);
+ } else {
+ hz = htoll(8000);
+ bhz = htoll(16000);
+ }
/* Write a wav header, ignoring sizes which will be filled in later */
fseek(f,0,SEEK_SET);
if (fwrite("RIFF", 1, 4, f) != 4) {
@@ -308,7 +319,7 @@ static int wav_open(struct ast_filestream *s)
if we did, it would go here. We also might want to check
and be sure it's a valid file. */
struct wav_desc *tmp = (struct wav_desc *)s->_private;
- if ((tmp->maxlen = check_header(s->f)) < 0)
+ if ((tmp->maxlen = check_header(s->f, (s->fmt->format == AST_FORMAT_SLINEAR16 ? 16000 : 8000))) < 0)
return -1;
return 0;
}
@@ -319,7 +330,9 @@ static int wav_rewrite(struct ast_filestream *s, const char *comment)
if we did, it would go here. We also might want to check
and be sure it's a valid file. */
- if (write_header(s->f))
+ struct wav_desc *tmp = (struct wav_desc *)s->_private;
+ tmp->hz = (s->fmt->format == AST_FORMAT_SLINEAR16 ? 16000 : 8000);
+ if (write_header(s->f,tmp->hz))
return -1;
return 0;
}
@@ -349,11 +362,13 @@ static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
int x;
#endif
short *tmp;
- int bytes = WAV_BUF_SIZE; /* in bytes */
+ int bytes;
off_t here;
/* Send a frame from the file to the appropriate channel */
struct wav_desc *fs = (struct wav_desc *)s->_private;
+ bytes = (fs->hz == 16000 ? (WAV_BUF_SIZE * 2) : WAV_BUF_SIZE);
+
here = ftello(s->f);
if (fs->maxlen - here < bytes) /* truncate if necessary */
bytes = fs->maxlen - here;
@@ -361,7 +376,7 @@ static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
bytes = 0;
/* ast_debug(1, "here: %d, maxlen: %d, bytes: %d\n", here, s->maxlen, bytes); */
s->fr.frametype = AST_FRAME_VOICE;
- s->fr.subclass.codec = AST_FORMAT_SLINEAR;
+ s->fr.subclass.codec = (fs->hz == 16000 ? AST_FORMAT_SLINEAR16 : AST_FORMAT_SLINEAR);
s->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, bytes);
@@ -388,7 +403,7 @@ static int wav_write(struct ast_filestream *fs, struct ast_frame *f)
{
#if __BYTE_ORDER == __BIG_ENDIAN
int x;
- short tmp[8000], *tmpi;
+ short tmp[16000], *tmpi;
#endif
struct wav_desc *s = (struct wav_desc *)fs->_private;
int res;
@@ -397,8 +412,12 @@ static int wav_write(struct ast_filestream *fs, struct ast_frame *f)
ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
return -1;
}
- if (f->subclass.codec != AST_FORMAT_SLINEAR) {
- ast_log(LOG_WARNING, "Asked to write non-SLINEAR frame (%s)!\n", ast_getformatname(f->subclass.codec));
+ if ((f->subclass.codec != AST_FORMAT_SLINEAR) && (f->subclass.codec != AST_FORMAT_SLINEAR16)) {
+ ast_log(LOG_WARNING, "Asked to write non-SLINEAR%s frame (%s)!\n", s->hz == 16000 ? "16" : "", ast_getformatname(f->subclass.codec));
+ return -1;
+ }
+ if (f->subclass.codec != fs->fmt->format) {
+ ast_log(LOG_WARNING, "Can't change SLINEAR frequency during write\n");
return -1;
}
if (!f->datalen)
@@ -467,6 +486,22 @@ static off_t wav_tell(struct ast_filestream *fs)
return (offset - 44)/2;
}
+static const struct ast_format wav16_f = {
+ .name = "wav16",
+ .exts = "wav16",
+ .format = AST_FORMAT_SLINEAR16,
+ .open = wav_open,
+ .rewrite = wav_rewrite,
+ .write = wav_write,
+ .seek = wav_seek,
+ .trunc = wav_trunc,
+ .tell = wav_tell,
+ .read = wav_read,
+ .close = wav_close,
+ .buf_size = (WAV_BUF_SIZE * 2) + AST_FRIENDLY_OFFSET,
+ .desc_size = sizeof(struct wav_desc),
+};
+
static const struct ast_format wav_f = {
.name = "wav",
.exts = "wav",
@@ -485,17 +520,19 @@ static const struct ast_format wav_f = {
static int load_module(void)
{
- if (ast_format_register(&wav_f))
+ if (ast_format_register(&wav_f)
+ || ast_format_register(&wav16_f))
return AST_MODULE_LOAD_FAILURE;
return AST_MODULE_LOAD_SUCCESS;
}
static int unload_module(void)
{
- return ast_format_unregister(wav_f.name);
+ return ast_format_unregister(wav_f.name)
+ || ast_format_unregister(wav16_f.name);
}
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Microsoft WAV format (8000Hz Signed Linear)",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Microsoft WAV/WAV16 format (8kHz/16kHz Signed Linear)",
.load = load_module,
.unload = unload_module,
.load_pri = AST_MODPRI_APP_DEPEND