summaryrefslogtreecommitdiff
path: root/formats/format_wav.c
diff options
context:
space:
mode:
Diffstat (limited to 'formats/format_wav.c')
-rw-r--r--formats/format_wav.c26
1 files changed, 7 insertions, 19 deletions
diff --git a/formats/format_wav.c b/formats/format_wav.c
index 06d6ae12d..fb810625f 100644
--- a/formats/format_wav.c
+++ b/formats/format_wav.c
@@ -35,6 +35,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
+#include "asterisk/format.h"
+#include "asterisk/codec.h"
/* Some Ideas for this code came from makewave.c by Jeffrey Chilton */
@@ -319,7 +322,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, (s->fmt->format.id == AST_FORMAT_SLINEAR16 ? 16000 : 8000))) < 0)
+ if ((tmp->maxlen = check_header(s->f, ast_format_get_sample_rate(s->fmt->format))) < 0)
return -1;
return 0;
}
@@ -331,7 +334,7 @@ static int wav_rewrite(struct ast_filestream *s, const char *comment)
and be sure it's a valid file. */
struct wav_desc *tmp = (struct wav_desc *)s->_private;
- tmp->hz = (s->fmt->format.id == AST_FORMAT_SLINEAR16 ? 16000 : 8000);
+ tmp->hz = ast_format_get_sample_rate(s->fmt->format);
if (write_header(s->f,tmp->hz))
return -1;
return 0;
@@ -379,9 +382,6 @@ static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
if (bytes < 0)
bytes = 0;
/* ast_debug(1, "here: %d, maxlen: %d, bytes: %d\n", here, s->maxlen, bytes); */
- s->fr.frametype = AST_FRAME_VOICE;
- ast_format_set(&s->fr.subclass.format, (fs->hz == 16000 ? AST_FORMAT_SLINEAR16 : AST_FORMAT_SLINEAR), 0);
- s->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, bytes);
if ( (res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) <= 0 ) {
@@ -412,18 +412,6 @@ static int wav_write(struct ast_filestream *fs, struct ast_frame *f)
struct wav_desc *s = (struct wav_desc *)fs->_private;
int res;
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if ((f->subclass.format.id != AST_FORMAT_SLINEAR) && (f->subclass.format.id != AST_FORMAT_SLINEAR16)) {
- ast_log(LOG_WARNING, "Asked to write non-SLINEAR%s frame (%s)!\n", s->hz == 16000 ? "16" : "", ast_getformatname(&f->subclass.format));
- return -1;
- }
- if (ast_format_cmp(&f->subclass.format, &fs->fmt->format) == AST_FORMAT_CMP_NOT_EQUAL) {
- ast_log(LOG_WARNING, "Can't change SLINEAR frequency during write\n");
- return -1;
- }
if (!f->datalen)
return -1;
@@ -547,8 +535,8 @@ static struct ast_format_def wav_f = {
static int load_module(void)
{
- ast_format_set(&wav_f.format, AST_FORMAT_SLINEAR, 0);
- ast_format_set(&wav16_f.format, AST_FORMAT_SLINEAR16, 0);
+ wav_f.format = ast_format_slin;
+ wav16_f.format = ast_format_slin16;
if (ast_format_def_register(&wav_f)
|| ast_format_def_register(&wav16_f))
return AST_MODULE_LOAD_FAILURE;