summaryrefslogtreecommitdiff
path: root/formats
diff options
context:
space:
mode:
Diffstat (limited to 'formats')
-rw-r--r--formats/format_g719.c15
-rw-r--r--formats/format_g723.c14
-rw-r--r--formats/format_g726.c15
-rw-r--r--formats/format_g729.c15
-rw-r--r--formats/format_gsm.c14
-rw-r--r--formats/format_h263.c26
-rw-r--r--formats/format_h264.c26
-rw-r--r--formats/format_ilbc.c14
-rw-r--r--formats/format_jpeg.c13
-rw-r--r--formats/format_ogg_vorbis.c16
-rw-r--r--formats/format_pcm.c31
-rw-r--r--formats/format_siren14.c14
-rw-r--r--formats/format_siren7.c14
-rw-r--r--formats/format_sln.c78
-rw-r--r--formats/format_vox.c14
-rw-r--r--formats/format_wav.c26
-rw-r--r--formats/format_wav_gsm.c15
17 files changed, 88 insertions, 272 deletions
diff --git a/formats/format_g719.c b/formats/format_g719.c
index ee9221230..8d508f0e3 100644
--- a/formats/format_g719.c
+++ b/formats/format_g719.c
@@ -34,6 +34,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
#define BUF_SIZE 160 /* 20 milliseconds == 160 bytes, 960 samples */
#define SAMPLES_TO_BYTES(x) ((typeof(x)) x / ((float) 960 / 160))
@@ -44,9 +45,6 @@ static struct ast_frame *g719read(struct ast_filestream *s, int *whennext)
int res;
/* Send a frame from the file to the appropriate channel */
- s->fr.frametype = AST_FRAME_VOICE;
- ast_format_set(&s->fr.subclass.format, AST_FORMAT_G719, 0);
- s->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
if (res)
@@ -61,14 +59,6 @@ static int g719write(struct ast_filestream *fs, struct ast_frame *f)
{
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_G719) {
- ast_log(LOG_WARNING, "Asked to write non-G.719 frame (%s)!\n", ast_getformatname(&f->subclass.format));
- return -1;
- }
if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) {
ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
return -1;
@@ -147,7 +137,8 @@ static struct ast_format_def g719_f = {
static int load_module(void)
{
- ast_format_set(&g719_f.format, AST_FORMAT_G719, 0);
+ g719_f.format = ast_format_g719;
+
if (ast_format_def_register(&g719_f))
return AST_MODULE_LOAD_DECLINE;
return AST_MODULE_LOAD_SUCCESS;
diff --git a/formats/format_g723.c b/formats/format_g723.c
index c3c194d15..51fe6b049 100644
--- a/formats/format_g723.c
+++ b/formats/format_g723.c
@@ -35,6 +35,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
+#include "asterisk/format_cache.h"
#define G723_MAX_SIZE 1024
@@ -64,9 +65,6 @@ static struct ast_frame *g723_read(struct ast_filestream *s, int *whennext)
return NULL;
}
/* Read the data into the buffer */
- s->fr.frametype = AST_FRAME_VOICE;
- ast_format_set(&s->fr.subclass.format, AST_FORMAT_G723_1, 0);
- s->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, size);
if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != size) {
ast_log(LOG_WARNING, "Short read (%d of %d bytes) (%s)!\n", res, size, strerror(errno));
@@ -82,14 +80,6 @@ static int g723_write(struct ast_filestream *s, struct ast_frame *f)
uint16_t size;
int res;
/* XXX there used to be a check s->fr means a read stream */
- 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_G723_1) {
- ast_log(LOG_WARNING, "Asked to write non-g723 frame!\n");
- return -1;
- }
delay = 0;
if (f->datalen <= 0) {
ast_log(LOG_WARNING, "Short frame ignored (%d bytes long?)\n", f->datalen);
@@ -151,7 +141,7 @@ static struct ast_format_def g723_1_f = {
static int load_module(void)
{
- ast_format_set(&g723_1_f.format, AST_FORMAT_G723_1, 0);
+ g723_1_f.format = ast_format_g723;
if (ast_format_def_register(&g723_1_f))
return AST_MODULE_LOAD_FAILURE;
diff --git a/formats/format_g726.c b/formats/format_g726.c
index 636aff091..bde3e2d06 100644
--- a/formats/format_g726.c
+++ b/formats/format_g726.c
@@ -39,6 +39,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
#define RATE_40 0
#define RATE_32 1
@@ -122,9 +123,6 @@ static struct ast_frame *g726_read(struct ast_filestream *s, int *whennext)
struct g726_desc *fs = (struct g726_desc *)s->_private;
/* Send a frame from the file to the appropriate channel */
- s->fr.frametype = AST_FRAME_VOICE;
- ast_format_set(&s->fr.subclass.format, AST_FORMAT_G726, 0);
- s->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, frame_size[fs->rate]);
s->fr.samples = 8 * FRAME_TIME;
if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
@@ -141,15 +139,6 @@ static int g726_write(struct ast_filestream *s, struct ast_frame *f)
int res;
struct g726_desc *fs = (struct g726_desc *)s->_private;
- 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_G726) {
- ast_log(LOG_WARNING, "Asked to write non-G726 frame (%s)!\n",
- ast_getformatname(&f->subclass.format));
- return -1;
- }
if (f->datalen % frame_size[fs->rate]) {
ast_log(LOG_WARNING, "Invalid data length %d, should be multiple of %d\n",
f->datalen, frame_size[fs->rate]);
@@ -239,7 +228,7 @@ static int load_module(void)
int i;
for (i = 0; f[i].desc_size ; i++) {
- ast_format_set(&f[i].format, AST_FORMAT_G726, 0);
+ f[i].format = ast_format_g726;
if (ast_format_def_register(&f[i])) { /* errors are fatal */
ast_log(LOG_WARNING, "Failed to register format %s.\n", f[i].name);
return AST_MODULE_LOAD_FAILURE;
diff --git a/formats/format_g729.c b/formats/format_g729.c
index f11fa97d9..7d562ede7 100644
--- a/formats/format_g729.c
+++ b/formats/format_g729.c
@@ -37,6 +37,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
/* Some Ideas for this code came from makeg729e.c by Jeffrey Chilton */
@@ -49,9 +50,6 @@ static struct ast_frame *g729_read(struct ast_filestream *s, int *whennext)
{
int res;
/* Send a frame from the file to the appropriate channel */
- s->fr.frametype = AST_FRAME_VOICE;
- ast_format_set(&s->fr.subclass.format, AST_FORMAT_G729A, 0);
- s->fr.mallocd = 0;
s->fr.samples = G729A_SAMPLES;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
@@ -66,14 +64,7 @@ static struct ast_frame *g729_read(struct ast_filestream *s, int *whennext)
static int g729_write(struct ast_filestream *fs, struct ast_frame *f)
{
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_G729A) {
- ast_log(LOG_WARNING, "Asked to write non-G729 frame (%s)!\n", ast_getformatname(&f->subclass.format));
- return -1;
- }
+
if (f->datalen % 10) {
ast_log(LOG_WARNING, "Invalid data length, %d, should be multiple of 10\n", f->datalen);
return -1;
@@ -147,7 +138,7 @@ static struct ast_format_def g729_f = {
static int load_module(void)
{
- ast_format_set(&g729_f.format, AST_FORMAT_G729A, 0);
+ g729_f.format = ast_format_g729;
if (ast_format_def_register(&g729_f))
return AST_MODULE_LOAD_FAILURE;
return AST_MODULE_LOAD_SUCCESS;
diff --git a/formats/format_gsm.c b/formats/format_gsm.c
index 47ed41c3a..fe1e55c7a 100644
--- a/formats/format_gsm.c
+++ b/formats/format_gsm.c
@@ -34,6 +34,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
#include "msgsm.h"
@@ -56,10 +57,7 @@ static struct ast_frame *gsm_read(struct ast_filestream *s, int *whennext)
{
int res;
- s->fr.frametype = AST_FRAME_VOICE;
- ast_format_set(&s->fr.subclass.format, AST_FORMAT_GSM, 0);
AST_FRAME_SET_BUFFER(&(s->fr), s->buf, AST_FRIENDLY_OFFSET, GSM_FRAME_SIZE)
- s->fr.mallocd = 0;
if ((res = fread(s->fr.data.ptr, 1, GSM_FRAME_SIZE, s->f)) != GSM_FRAME_SIZE) {
if (res)
ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
@@ -74,14 +72,6 @@ static int gsm_write(struct ast_filestream *fs, struct ast_frame *f)
int res;
unsigned char gsm[2*GSM_FRAME_SIZE];
- 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_GSM) {
- ast_log(LOG_WARNING, "Asked to write non-GSM frame (%s)!\n", ast_getformatname(&f->subclass.format));
- return -1;
- }
if (!(f->datalen % 65)) {
/* This is in MSGSM format, need to be converted */
int len=0;
@@ -193,7 +183,7 @@ static struct ast_format_def gsm_f = {
static int load_module(void)
{
- ast_format_set(&gsm_f.format, AST_FORMAT_GSM, 0);
+ gsm_f.format = ast_format_gsm;
if (ast_format_def_register(&gsm_f))
return AST_MODULE_LOAD_FAILURE;
return AST_MODULE_LOAD_SUCCESS;
diff --git a/formats/format_h263.c b/formats/format_h263.c
index 56e9b3aa0..6511cef04 100644
--- a/formats/format_h263.c
+++ b/formats/format_h263.c
@@ -35,6 +35,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
/* Some Ideas for this code came from makeh263e.c by Jeffrey Chilton */
@@ -48,6 +49,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
* ridiculously large). */
#define BUF_SIZE 32768 /* Four real h.263 Frames */
+#define FRAME_ENDED 0x8000
+
struct h263_desc {
unsigned int lastts;
};
@@ -76,15 +79,12 @@ static struct ast_frame *h263_read(struct ast_filestream *s, int *whennext)
if ((res = fread(&len, 1, sizeof(len), s->f)) < 1)
return NULL;
len = ntohs(len);
- mark = (len & 0x8000) ? 1 : 0;
+ mark = (len & FRAME_ENDED) ? 1 : 0;
len &= 0x7fff;
if (len > BUF_SIZE) {
ast_log(LOG_WARNING, "Length %d is too long\n", len);
return NULL;
}
- s->fr.frametype = AST_FRAME_VIDEO;
- ast_format_set(&s->fr.subclass.format, AST_FORMAT_H263, 0);
- s->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, len);
if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
if (res)
@@ -93,11 +93,7 @@ static struct ast_frame *h263_read(struct ast_filestream *s, int *whennext)
}
s->fr.samples = fs->lastts; /* XXX what ? */
s->fr.datalen = len;
- if (mark) {
- ast_format_set_video_mark(&s->fr.subclass.format);
- }
- s->fr.delivery.tv_sec = 0;
- s->fr.delivery.tv_usec = 0;
+ s->fr.subclass.frame_ending = mark;
if ((res = fread(&ts, 1, sizeof(ts), s->f)) == sizeof(ts)) {
fs->lastts = ntohl(ts);
*whennext = fs->lastts * 4/45;
@@ -112,15 +108,7 @@ static int h263_write(struct ast_filestream *fs, struct ast_frame *f)
unsigned int ts;
unsigned short len;
uint32_t mark = 0;
- if (f->frametype != AST_FRAME_VIDEO) {
- ast_log(LOG_WARNING, "Asked to write non-video frame!\n");
- return -1;
- }
- mark = ast_format_get_video_mark(&f->subclass.format) ? 0x8000 : 0;
- if (f->subclass.format.id != AST_FORMAT_H263) {
- ast_log(LOG_WARNING, "Asked to write non-h263 frame (%s)!\n", ast_getformatname(&f->subclass.format));
- return -1;
- }
+ mark = f->subclass.frame_ending ? FRAME_ENDED : 0;
ts = htonl(f->samples);
if ((res = fwrite(&ts, 1, sizeof(ts), fs->f)) != sizeof(ts)) {
ast_log(LOG_WARNING, "Bad write (%d/4): %s\n", res, strerror(errno));
@@ -182,7 +170,7 @@ static struct ast_format_def h263_f = {
static int load_module(void)
{
- ast_format_set(&h263_f.format, AST_FORMAT_H263, 0);
+ h263_f.format = ast_format_h263;
if (ast_format_def_register(&h263_f))
return AST_MODULE_LOAD_FAILURE;
return AST_MODULE_LOAD_SUCCESS;
diff --git a/formats/format_h264.c b/formats/format_h264.c
index e090c2bac..56ec007c0 100644
--- a/formats/format_h264.c
+++ b/formats/format_h264.c
@@ -35,12 +35,15 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
/* Some Ideas for this code came from makeh264e.c by Jeffrey Chilton */
/* Portions of the conversion code are by guido@sienanet.it */
/*! \todo Check this buf size estimate, it may be totally wrong for large frame video */
+#define FRAME_ENDED 0x8000
+
#define BUF_SIZE 4096 /* Two Real h264 Frames */
struct h264_desc {
unsigned int lastts;
@@ -68,15 +71,12 @@ static struct ast_frame *h264_read(struct ast_filestream *s, int *whennext)
if ((res = fread(&len, 1, sizeof(len), s->f)) < 1)
return NULL;
len = ntohs(len);
- mark = (len & 0x8000) ? 1 : 0;
+ mark = (len & FRAME_ENDED) ? 1 : 0;
len &= 0x7fff;
if (len > BUF_SIZE) {
ast_log(LOG_WARNING, "Length %d is too long\n", len);
len = BUF_SIZE; /* XXX truncate */
}
- s->fr.frametype = AST_FRAME_VIDEO;
- ast_format_set(&s->fr.subclass.format, AST_FORMAT_H264, 0);
- s->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, len);
if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
if (res)
@@ -85,11 +85,7 @@ static struct ast_frame *h264_read(struct ast_filestream *s, int *whennext)
}
s->fr.samples = fs->lastts;
s->fr.datalen = len;
- if (mark) {
- ast_format_set_video_mark(&s->fr.subclass.format);
- }
- s->fr.delivery.tv_sec = 0;
- s->fr.delivery.tv_usec = 0;
+ s->fr.subclass.frame_ending = mark;
if ((res = fread(&ts, 1, sizeof(ts), s->f)) == sizeof(ts)) {
fs->lastts = ntohl(ts);
*whennext = fs->lastts * 4/45;
@@ -105,15 +101,7 @@ static int h264_write(struct ast_filestream *s, struct ast_frame *f)
unsigned short len;
int mark;
- if (f->frametype != AST_FRAME_VIDEO) {
- ast_log(LOG_WARNING, "Asked to write non-video frame!\n");
- return -1;
- }
- mark = ast_format_get_video_mark(&f->subclass.format) ? 0x8000 : 0;
- if (f->subclass.format.id != AST_FORMAT_H264) {
- ast_log(LOG_WARNING, "Asked to write non-h264 frame (%s)!\n", ast_getformatname(&f->subclass.format));
- return -1;
- }
+ mark = f->subclass.frame_ending ? FRAME_ENDED : 0;
ts = htonl(f->samples);
if ((res = fwrite(&ts, 1, sizeof(ts), s->f)) != sizeof(ts)) {
ast_log(LOG_WARNING, "Bad write (%d/4): %s\n", res, strerror(errno));
@@ -175,7 +163,7 @@ static struct ast_format_def h264_f = {
static int load_module(void)
{
- ast_format_set(&h264_f.format, AST_FORMAT_H264, 0);
+ h264_f.format = ast_format_h264;
if (ast_format_def_register(&h264_f))
return AST_MODULE_LOAD_FAILURE;
return AST_MODULE_LOAD_SUCCESS;
diff --git a/formats/format_ilbc.c b/formats/format_ilbc.c
index 07155b717..ce5135f7b 100644
--- a/formats/format_ilbc.c
+++ b/formats/format_ilbc.c
@@ -36,6 +36,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
/* Some Ideas for this code came from makeg729e.c by Jeffrey Chilton */
@@ -48,9 +49,6 @@ static struct ast_frame *ilbc_read(struct ast_filestream *s, int *whennext)
{
int res;
/* Send a frame from the file to the appropriate channel */
- s->fr.frametype = AST_FRAME_VOICE;
- ast_format_set(&s->fr.subclass.format, AST_FORMAT_ILBC, 0);
- s->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, ILBC_BUF_SIZE);
if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
if (res)
@@ -64,14 +62,6 @@ static struct ast_frame *ilbc_read(struct ast_filestream *s, int *whennext)
static int ilbc_write(struct ast_filestream *fs, struct ast_frame *f)
{
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_ILBC) {
- ast_log(LOG_WARNING, "Asked to write non-iLBC frame (%s)!\n", ast_getformatname(&f->subclass.format));
- return -1;
- }
if (f->datalen % 50) {
ast_log(LOG_WARNING, "Invalid data length, %d, should be multiple of 50\n", f->datalen);
return -1;
@@ -145,7 +135,7 @@ static struct ast_format_def ilbc_f = {
static int load_module(void)
{
- ast_format_set(&ilbc_f.format, AST_FORMAT_ILBC, 0);
+ ilbc_f.format = ast_format_ilbc;
if (ast_format_def_register(&ilbc_f))
return AST_MODULE_LOAD_FAILURE;
return AST_MODULE_LOAD_SUCCESS;
diff --git a/formats/format_jpeg.c b/formats/format_jpeg.c
index d6733020e..1e91482f7 100644
--- a/formats/format_jpeg.c
+++ b/formats/format_jpeg.c
@@ -36,6 +36,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/module.h"
#include "asterisk/image.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
static struct ast_frame *jpeg_read_image(int fd, int len)
{
@@ -52,7 +53,7 @@ static struct ast_frame *jpeg_read_image(int fd, int len)
}
memset(&fr, 0, sizeof(fr));
fr.frametype = AST_FRAME_IMAGE;
- ast_format_set(&fr.subclass.format, AST_FORMAT_JPEG, 0);
+ fr.subclass.format = ast_format_jpeg;
fr.data.ptr = buf;
fr.src = "JPEG Read";
fr.datalen = len;
@@ -74,14 +75,6 @@ static int jpeg_identify(int fd)
static int jpeg_write_image(int fd, struct ast_frame *fr)
{
int res=0;
- if (fr->frametype != AST_FRAME_IMAGE) {
- ast_log(LOG_WARNING, "Not an image\n");
- return -1;
- }
- if (fr->subclass.format.id != AST_FORMAT_JPEG) {
- ast_log(LOG_WARNING, "Not a jpeg image\n");
- return -1;
- }
if (fr->datalen) {
res = write(fd, fr->data.ptr, fr->datalen);
if (res != fr->datalen) {
@@ -103,7 +96,7 @@ static struct ast_imager jpeg_format = {
static int load_module(void)
{
- ast_format_set(&jpeg_format.format, AST_FORMAT_JPEG, 0);
+ jpeg_format.format = ast_format_jpeg;
if (ast_image_register(&jpeg_format))
return AST_MODULE_LOAD_FAILURE;
return AST_MODULE_LOAD_SUCCESS;
diff --git a/formats/format_ogg_vorbis.c b/formats/format_ogg_vorbis.c
index 9eb390066..6171491a8 100644
--- a/formats/format_ogg_vorbis.c
+++ b/formats/format_ogg_vorbis.c
@@ -45,6 +45,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
+#include "asterisk/format_cache.h"
/*
* this is the number of samples we deal with. Samples are converted
@@ -242,16 +243,6 @@ static int ogg_vorbis_write(struct ast_filestream *fs, struct ast_frame *f)
ast_log(LOG_ERROR, "This stream is not set up for writing!\n");
return -1;
}
-
- 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) {
- ast_log(LOG_WARNING, "Asked to write non-SLINEAR frame (%s)!\n",
- ast_getformatname(&f->subclass.format));
- return -1;
- }
if (!f->datalen)
return -1;
@@ -310,9 +301,6 @@ static struct ast_frame *ogg_vorbis_read(struct ast_filestream *fs,
}
/* initialize frame */
- fs->fr.frametype = AST_FRAME_VOICE;
- ast_format_set(&fs->fr.subclass.format, AST_FORMAT_SLINEAR, 0);
- fs->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&fs->fr, fs->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
out_buf = (char *) (fs->fr.data.ptr); /* SLIN data buffer */
@@ -435,7 +423,7 @@ static struct ast_format_def vorbis_f = {
static int load_module(void)
{
- ast_format_set(&vorbis_f.format, AST_FORMAT_SLINEAR, 0);
+ vorbis_f.format = ast_format_slin;
if (ast_format_def_register(&vorbis_f))
return AST_MODULE_LOAD_FAILURE;
return AST_MODULE_LOAD_SUCCESS;
diff --git a/formats/format_pcm.c b/formats/format_pcm.c
index 1ee333fba..2d864078e 100644
--- a/formats/format_pcm.c
+++ b/formats/format_pcm.c
@@ -37,6 +37,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/endian.h"
#include "asterisk/ulaw.h"
#include "asterisk/alaw.h"
+#include "asterisk/format_cache.h"
#define BUF_SIZE 160 /* 160 bytes, and same number of samples */
@@ -66,7 +67,7 @@ static unsigned long get_time(void)
static int pcma_open(struct ast_filestream *s)
{
- if (s->fmt->format == AST_FORMAT_ALAW)
+ if (ast_format_cmp(s->fmt->format, ast_format_alaw) == AST_FORMAT_CMP_EQUAL)
pd->starttime = get_time();
return 0;
}
@@ -83,9 +84,6 @@ static struct ast_frame *pcm_read(struct ast_filestream *s, int *whennext)
/* Send a frame from the file to the appropriate channel */
- s->fr.frametype = AST_FRAME_VOICE;
- ast_format_copy(&s->fr.subclass.format, &s->fmt->format);
- s->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) < 1) {
if (res)
@@ -93,7 +91,7 @@ static struct ast_frame *pcm_read(struct ast_filestream *s, int *whennext)
return NULL;
}
s->fr.datalen = res;
- if (s->fmt->format.id == AST_FORMAT_G722)
+ if (ast_format_cmp(s->fmt->format, ast_format_g722) == AST_FORMAT_CMP_EQUAL)
*whennext = s->fr.samples = res * 2;
else
*whennext = s->fr.samples = res;
@@ -141,7 +139,7 @@ static int pcm_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
}
if (whence == SEEK_FORCECUR && offset > max) { /* extend the file */
size_t left = offset - max;
- const char *src = (fs->fmt->format.id == AST_FORMAT_ALAW) ? alaw_silence : ulaw_silence;
+ const char *src = (ast_format_cmp(fs->fmt->format, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) ? alaw_silence : ulaw_silence;
while (left) {
size_t written = fwrite(src, 1, (left > BUF_SIZE) ? BUF_SIZE : left, fs->f);
@@ -185,17 +183,8 @@ static int pcm_write(struct ast_filestream *fs, struct ast_frame *f)
{
int res;
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if (ast_format_cmp(&f->subclass.format, &fs->fmt->format) == AST_FORMAT_CMP_NOT_EQUAL) {
- ast_log(LOG_WARNING, "Asked to write incompatible format frame (%s)!\n", ast_getformatname(&f->subclass.format));
- return -1;
- }
-
#ifdef REALTIME_WRITE
- if (s->fmt->format == AST_FORMAT_ALAW) {
+ if (ast_format_cmp(s->fmt->format, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) {
struct pcm_desc *pd = (struct pcm_desc *)fs->_private;
struct stat stat_buf;
unsigned long cur_time = get_time();
@@ -399,7 +388,7 @@ static int au_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
off_t min = AU_HEADER_SIZE, max, cur;
long offset = 0, bytes;
- if (fs->fmt->format.id == AST_FORMAT_G722)
+ if (ast_format_cmp(fs->fmt->format, ast_format_g722) == AST_FORMAT_CMP_EQUAL)
bytes = sample_offset / 2;
else
bytes = sample_offset;
@@ -523,10 +512,10 @@ static int load_module(void)
for (i = 0; i < ARRAY_LEN(alaw_silence); i++)
alaw_silence[i] = AST_LIN2A(0);
- ast_format_set(&pcm_f.format, AST_FORMAT_ULAW, 0);
- ast_format_set(&alaw_f.format, AST_FORMAT_ALAW, 0);
- ast_format_set(&au_f.format, AST_FORMAT_ULAW, 0);
- ast_format_set(&g722_f.format, AST_FORMAT_G722, 0);
+ pcm_f.format = ast_format_ulaw;
+ alaw_f.format = ast_format_alaw;
+ au_f.format = ast_format_ulaw;
+ g722_f.format = ast_format_g722;
if ( ast_format_def_register(&pcm_f)
|| ast_format_def_register(&alaw_f)
|| ast_format_def_register(&au_f)
diff --git a/formats/format_siren14.c b/formats/format_siren14.c
index 77a9fe3ef..b7e2de1ec 100644
--- a/formats/format_siren14.c
+++ b/formats/format_siren14.c
@@ -34,6 +34,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
#define BUF_SIZE 120 /* 20 milliseconds == 120 bytes, 640 samples */
#define SAMPLES_TO_BYTES(x) ((typeof(x)) x / ((float) 640 / 120))
@@ -44,9 +45,6 @@ static struct ast_frame *siren14read(struct ast_filestream *s, int *whennext)
int res;
/* Send a frame from the file to the appropriate channel */
- s->fr.frametype = AST_FRAME_VOICE;
- ast_format_set(&s->fr.subclass.format, AST_FORMAT_SIREN14, 0);
- s->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
if (res)
@@ -61,14 +59,6 @@ static int siren14write(struct ast_filestream *fs, struct ast_frame *f)
{
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_SIREN14) {
- ast_log(LOG_WARNING, "Asked to write non-Siren14 frame (%s)!\n", ast_getformatname(&f->subclass.format));
- return -1;
- }
if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) {
ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
return -1;
@@ -148,7 +138,7 @@ static struct ast_format_def siren14_f = {
static int load_module(void)
{
- ast_format_set(&siren14_f.format, AST_FORMAT_SIREN14, 0);
+ siren14_f.format = ast_format_siren14;
if (ast_format_def_register(&siren14_f))
return AST_MODULE_LOAD_DECLINE;
diff --git a/formats/format_siren7.c b/formats/format_siren7.c
index 35e2a3460..0b3c75d9c 100644
--- a/formats/format_siren7.c
+++ b/formats/format_siren7.c
@@ -34,6 +34,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
#define BUF_SIZE 80 /* 20 milliseconds == 80 bytes, 320 samples */
#define SAMPLES_TO_BYTES(x) x / (320 / 80)
@@ -44,9 +45,6 @@ static struct ast_frame *siren7read(struct ast_filestream *s, int *whennext)
int res;
/* Send a frame from the file to the appropriate channel */
- s->fr.frametype = AST_FRAME_VOICE;
- ast_format_set(&s->fr.subclass.format, AST_FORMAT_SIREN7, 0);
- s->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
if (res)
@@ -61,14 +59,6 @@ static int siren7write(struct ast_filestream *fs, struct ast_frame *f)
{
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_SIREN7) {
- ast_log(LOG_WARNING, "Asked to write non-Siren7 frame (%s)!\n", ast_getformatname(&f->subclass.format));
- return -1;
- }
if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) {
ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
return -1;
@@ -148,7 +138,7 @@ static struct ast_format_def siren7_f = {
static int load_module(void)
{
- ast_format_set(&siren7_f.format, AST_FORMAT_SIREN7, 0);
+ siren7_f.format = ast_format_siren7;
if (ast_format_def_register(&siren7_f))
return AST_MODULE_LOAD_DECLINE;
diff --git a/formats/format_sln.c b/formats/format_sln.c
index 30a1ebe31..a3230637c 100644
--- a/formats/format_sln.c
+++ b/formats/format_sln.c
@@ -32,15 +32,13 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
-static struct ast_frame *generic_read(struct ast_filestream *s, int *whennext, unsigned int buf_size, enum ast_format_id id)
+static struct ast_frame *generic_read(struct ast_filestream *s, int *whennext, unsigned int buf_size)
{
int res;
/* Send a frame from the file to the appropriate channel */
- s->fr.frametype = AST_FRAME_VOICE;
- ast_format_set(&s->fr.subclass.format, id, 0);
- s->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, buf_size);
if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) < 1) {
if (res)
@@ -52,17 +50,9 @@ static struct ast_frame *generic_read(struct ast_filestream *s, int *whennext, u
return &s->fr;
}
-static int generic_write(struct ast_filestream *fs, struct ast_frame *f, enum ast_format_id id)
+static int slinear_write(struct ast_filestream *fs, struct ast_frame *f)
{
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 != id) {
- ast_log(LOG_WARNING, "Asked to write non-slinear frame (%s)!\n", ast_getformatname(&f->subclass.format));
- return -1;
- }
if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) {
ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
return -1;
@@ -127,8 +117,7 @@ static off_t slinear_tell(struct ast_filestream *fs)
return ftello(fs->f) / 2;
}
-static int slinear_write(struct ast_filestream *fs, struct ast_frame *f){return generic_write(fs, f, AST_FORMAT_SLINEAR);}
-static struct ast_frame *slinear_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 320, AST_FORMAT_SLINEAR);}
+static struct ast_frame *slinear_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 320);}
static struct ast_format_def slin_f = {
.name = "sln",
.exts = "sln|raw",
@@ -140,12 +129,11 @@ static struct ast_format_def slin_f = {
.buf_size = 320 + AST_FRIENDLY_OFFSET,
};
-static int slinear12_write(struct ast_filestream *fs, struct ast_frame *f){return generic_write(fs, f, AST_FORMAT_SLINEAR12);}
-static struct ast_frame *slinear12_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 480, AST_FORMAT_SLINEAR12);}
+static struct ast_frame *slinear12_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 480);}
static struct ast_format_def slin12_f = {
.name = "sln12",
.exts = "sln12",
- .write = slinear12_write,
+ .write = slinear_write,
.seek = slinear_seek,
.trunc = slinear_trunc,
.tell = slinear_tell,
@@ -153,12 +141,11 @@ static struct ast_format_def slin12_f = {
.buf_size = 480 + AST_FRIENDLY_OFFSET,
};
-static int slinear16_write(struct ast_filestream *fs, struct ast_frame *f){return generic_write(fs, f, AST_FORMAT_SLINEAR16);}
-static struct ast_frame *slinear16_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 640, AST_FORMAT_SLINEAR16);}
+static struct ast_frame *slinear16_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 640);}
static struct ast_format_def slin16_f = {
.name = "sln16",
.exts = "sln16",
- .write = slinear16_write,
+ .write = slinear_write,
.seek = slinear_seek,
.trunc = slinear_trunc,
.tell = slinear_tell,
@@ -166,12 +153,11 @@ static struct ast_format_def slin16_f = {
.buf_size = 640 + AST_FRIENDLY_OFFSET,
};
-static int slinear24_write(struct ast_filestream *fs, struct ast_frame *f){return generic_write(fs, f, AST_FORMAT_SLINEAR24);}
-static struct ast_frame *slinear24_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 960, AST_FORMAT_SLINEAR24);}
+static struct ast_frame *slinear24_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 960);}
static struct ast_format_def slin24_f = {
.name = "sln24",
.exts = "sln24",
- .write = slinear24_write,
+ .write = slinear_write,
.seek = slinear_seek,
.trunc = slinear_trunc,
.tell = slinear_tell,
@@ -179,12 +165,11 @@ static struct ast_format_def slin24_f = {
.buf_size = 960 + AST_FRIENDLY_OFFSET,
};
-static int slinear32_write(struct ast_filestream *fs, struct ast_frame *f){return generic_write(fs, f, AST_FORMAT_SLINEAR32);}
-static struct ast_frame *slinear32_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 1280, AST_FORMAT_SLINEAR32);}
+static struct ast_frame *slinear32_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 1280);}
static struct ast_format_def slin32_f = {
.name = "sln32",
.exts = "sln32",
- .write = slinear32_write,
+ .write = slinear_write,
.seek = slinear_seek,
.trunc = slinear_trunc,
.tell = slinear_tell,
@@ -192,12 +177,11 @@ static struct ast_format_def slin32_f = {
.buf_size = 1280 + AST_FRIENDLY_OFFSET,
};
-static int slinear44_write(struct ast_filestream *fs, struct ast_frame *f){return generic_write(fs, f, AST_FORMAT_SLINEAR44);}
-static struct ast_frame *slinear44_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 1764, AST_FORMAT_SLINEAR44);}
+static struct ast_frame *slinear44_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 1764);}
static struct ast_format_def slin44_f = {
.name = "sln44",
.exts = "sln44",
- .write = slinear44_write,
+ .write = slinear_write,
.seek = slinear_seek,
.trunc = slinear_trunc,
.tell = slinear_tell,
@@ -205,12 +189,11 @@ static struct ast_format_def slin44_f = {
.buf_size = 1764 + AST_FRIENDLY_OFFSET,
};
-static int slinear48_write(struct ast_filestream *fs, struct ast_frame *f){return generic_write(fs, f, AST_FORMAT_SLINEAR48);}
-static struct ast_frame *slinear48_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 1920, AST_FORMAT_SLINEAR48);}
+static struct ast_frame *slinear48_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 1920);}
static struct ast_format_def slin48_f = {
.name = "sln48",
.exts = "sln48",
- .write = slinear48_write,
+ .write = slinear_write,
.seek = slinear_seek,
.trunc = slinear_trunc,
.tell = slinear_tell,
@@ -218,12 +201,11 @@ static struct ast_format_def slin48_f = {
.buf_size = 1920 + AST_FRIENDLY_OFFSET,
};
-static int slinear96_write(struct ast_filestream *fs, struct ast_frame *f){return generic_write(fs, f, AST_FORMAT_SLINEAR96);}
-static struct ast_frame *slinear96_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 3840, AST_FORMAT_SLINEAR96);}
+static struct ast_frame *slinear96_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 3840);}
static struct ast_format_def slin96_f = {
.name = "sln96",
.exts = "sln96",
- .write = slinear96_write,
+ .write = slinear_write,
.seek = slinear_seek,
.trunc = slinear_trunc,
.tell = slinear_tell,
@@ -231,12 +213,11 @@ static struct ast_format_def slin96_f = {
.buf_size = 3840 + AST_FRIENDLY_OFFSET,
};
-static int slinear192_write(struct ast_filestream *fs, struct ast_frame *f){return generic_write(fs, f, AST_FORMAT_SLINEAR192);}
-static struct ast_frame *slinear192_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 7680, AST_FORMAT_SLINEAR192);}
+static struct ast_frame *slinear192_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 7680);}
static struct ast_format_def slin192_f = {
.name = "sln192",
.exts = "sln192",
- .write = slinear192_write,
+ .write = slinear_write,
.seek = slinear_seek,
.trunc = slinear_trunc,
.tell = slinear_tell,
@@ -259,15 +240,16 @@ static struct ast_format_def *slin_list[] = {
static int load_module(void)
{
int i;
- ast_format_set(&slin_f.format, AST_FORMAT_SLINEAR, 0);
- ast_format_set(&slin12_f.format, AST_FORMAT_SLINEAR12, 0);
- ast_format_set(&slin16_f.format, AST_FORMAT_SLINEAR16, 0);
- ast_format_set(&slin24_f.format, AST_FORMAT_SLINEAR24, 0);
- ast_format_set(&slin32_f.format, AST_FORMAT_SLINEAR32, 0);
- ast_format_set(&slin44_f.format, AST_FORMAT_SLINEAR44, 0);
- ast_format_set(&slin48_f.format, AST_FORMAT_SLINEAR48, 0);
- ast_format_set(&slin96_f.format, AST_FORMAT_SLINEAR96, 0);
- ast_format_set(&slin192_f.format, AST_FORMAT_SLINEAR192, 0);
+
+ slin_f.format = ast_format_slin;
+ slin12_f.format = ast_format_slin12;
+ slin16_f.format = ast_format_slin16;
+ slin24_f.format = ast_format_slin24;
+ slin32_f.format = ast_format_slin32;
+ slin44_f.format = ast_format_slin44;
+ slin48_f.format = ast_format_slin48;
+ slin96_f.format = ast_format_slin96;
+ slin192_f.format = ast_format_slin192;
for (i = 0; i < ARRAY_LEN(slin_list); i++) {
if (ast_format_def_register(slin_list[i])) {
diff --git a/formats/format_vox.c b/formats/format_vox.c
index f640021d8..7beec5e6a 100644
--- a/formats/format_vox.c
+++ b/formats/format_vox.c
@@ -35,6 +35,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
#define BUF_SIZE 80 /* 80 bytes, 160 samples */
#define VOX_SAMPLES 160
@@ -44,9 +45,6 @@ static struct ast_frame *vox_read(struct ast_filestream *s, int *whennext)
int res;
/* Send a frame from the file to the appropriate channel */
- s->fr.frametype = AST_FRAME_VOICE;
- ast_format_set(&s->fr.subclass.format, AST_FORMAT_ADPCM, 0);
- s->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) < 1) {
if (res)
@@ -61,14 +59,6 @@ static struct ast_frame *vox_read(struct ast_filestream *s, int *whennext)
static int vox_write(struct ast_filestream *s, struct ast_frame *f)
{
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_ADPCM) {
- ast_log(LOG_WARNING, "Asked to write non-ADPCM frame (%s)!\n", ast_getformatname(&f->subclass.format));
- return -1;
- }
if ((res = fwrite(f->data.ptr, 1, f->datalen, s->f)) != f->datalen) {
ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
return -1;
@@ -147,7 +137,7 @@ static struct ast_format_def vox_f = {
static int load_module(void)
{
- ast_format_set(&vox_f.format, AST_FORMAT_ADPCM, 0);
+ vox_f.format = ast_format_adpcm;
if (ast_format_def_register(&vox_f))
return AST_MODULE_LOAD_FAILURE;
return AST_MODULE_LOAD_SUCCESS;
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;
diff --git a/formats/format_wav_gsm.c b/formats/format_wav_gsm.c
index c8d83ff4c..bbb1977a9 100644
--- a/formats/format_wav_gsm.c
+++ b/formats/format_wav_gsm.c
@@ -38,6 +38,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
#include "msgsm.h"
@@ -409,11 +410,7 @@ static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
/* Send a frame from the file to the appropriate channel */
struct wavg_desc *fs = (struct wavg_desc *)s->_private;
- s->fr.frametype = AST_FRAME_VOICE;
- ast_format_set(&s->fr.subclass.format, AST_FORMAT_GSM, 0);
- s->fr.offset = AST_FRIENDLY_OFFSET;
s->fr.samples = GSM_SAMPLES;
- s->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, GSM_FRAME_SIZE);
if (fs->secondhalf) {
/* Just return a frame based on the second GSM frame */
@@ -443,14 +440,6 @@ static int wav_write(struct ast_filestream *s, struct ast_frame *f)
int size;
struct wavg_desc *fs = (struct wavg_desc *)s->_private;
- 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_GSM) {
- ast_log(LOG_WARNING, "Asked to write non-GSM frame (%s)!\n", ast_getformatname(&f->subclass.format));
- return -1;
- }
/* XXX this might fail... if the input is a multiple of MSGSM_FRAME_SIZE
* we assume it is already in the correct format.
*/
@@ -577,7 +566,7 @@ static struct ast_format_def wav49_f = {
static int load_module(void)
{
- ast_format_set(&wav49_f.format, AST_FORMAT_GSM, 0);
+ wav49_f.format = ast_format_gsm;
if (ast_format_def_register(&wav49_f))
return AST_MODULE_LOAD_FAILURE;
return AST_MODULE_LOAD_SUCCESS;