[asterisk-commits] file: branch group/media_formats r407957 - in /team/group/media_formats: form...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Feb 11 12:03:57 CST 2014
Author: file
Date: Tue Feb 11 12:03:49 2014
New Revision: 407957
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=407957
Log:
Move formats over.
This commit also removes lots of checking. I'm going to use this opportunity
to put some guarantees in place for these implementations. They'll never receive
a frame they wouldn't expect.
Modified:
team/group/media_formats/formats/format_g719.c
team/group/media_formats/formats/format_g723.c
team/group/media_formats/formats/format_g726.c
team/group/media_formats/formats/format_g729.c
team/group/media_formats/formats/format_gsm.c
team/group/media_formats/formats/format_ilbc.c
team/group/media_formats/formats/format_jpeg.c
team/group/media_formats/formats/format_ogg_vorbis.c
team/group/media_formats/formats/format_pcm.c
team/group/media_formats/formats/format_siren14.c
team/group/media_formats/formats/format_siren7.c
team/group/media_formats/formats/format_sln.c
team/group/media_formats/formats/format_vox.c
team/group/media_formats/formats/format_wav.c
team/group/media_formats/formats/format_wav_gsm.c
team/group/media_formats/include/asterisk/format_cache.h
team/group/media_formats/include/asterisk/image.h
team/group/media_formats/main/file.c
Modified: team/group/media_formats/formats/format_g719.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/formats/format_g719.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/formats/format_g719.c (original)
+++ team/group/media_formats/formats/format_g719.c Tue Feb 11 12:03:49 2014
@@ -34,6 +34,7 @@
#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 @@
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 @@
{
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 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;
Modified: team/group/media_formats/formats/format_g723.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/formats/format_g723.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/formats/format_g723.c (original)
+++ team/group/media_formats/formats/format_g723.c Tue Feb 11 12:03:49 2014
@@ -35,6 +35,7 @@
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
+#include "asterisk/format_cache.h"
#define G723_MAX_SIZE 1024
@@ -64,9 +65,6 @@
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 @@
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 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;
Modified: team/group/media_formats/formats/format_g726.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/formats/format_g726.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/formats/format_g726.c (original)
+++ team/group/media_formats/formats/format_g726.c Tue Feb 11 12:03:49 2014
@@ -39,6 +39,7 @@
#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 @@
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 @@
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 @@
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;
Modified: team/group/media_formats/formats/format_g729.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/formats/format_g729.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/formats/format_g729.c (original)
+++ team/group/media_formats/formats/format_g729.c Tue Feb 11 12:03:49 2014
@@ -37,6 +37,7 @@
#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 @@
{
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 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 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;
Modified: team/group/media_formats/formats/format_gsm.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/formats/format_gsm.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/formats/format_gsm.c (original)
+++ team/group/media_formats/formats/format_gsm.c Tue Feb 11 12:03:49 2014
@@ -34,6 +34,7 @@
#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 @@
{
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 @@
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 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;
Modified: team/group/media_formats/formats/format_ilbc.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/formats/format_ilbc.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/formats/format_ilbc.c (original)
+++ team/group/media_formats/formats/format_ilbc.c Tue Feb 11 12:03:49 2014
@@ -36,6 +36,7 @@
#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 @@
{
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 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 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;
Modified: team/group/media_formats/formats/format_jpeg.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/formats/format_jpeg.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/formats/format_jpeg.c (original)
+++ team/group/media_formats/formats/format_jpeg.c Tue Feb 11 12:03:49 2014
@@ -36,6 +36,7 @@
#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 @@
}
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_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 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;
Modified: team/group/media_formats/formats/format_ogg_vorbis.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/formats/format_ogg_vorbis.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/formats/format_ogg_vorbis.c (original)
+++ team/group/media_formats/formats/format_ogg_vorbis.c Tue Feb 11 12:03:49 2014
@@ -45,6 +45,7 @@
#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 @@
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 @@
}
/* 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 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;
Modified: team/group/media_formats/formats/format_pcm.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/formats/format_pcm.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/formats/format_pcm.c (original)
+++ team/group/media_formats/formats/format_pcm.c Tue Feb 11 12:03:49 2014
@@ -37,6 +37,7 @@
#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 */
@@ -83,9 +84,6 @@
/* 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 @@
return NULL;
}
s->fr.datalen = res;
- if (s->fmt->format.id == AST_FORMAT_G722)
+ if (s->fmt->format == ast_format_g722)
*whennext = s->fr.samples = res * 2;
else
*whennext = s->fr.samples = res;
@@ -141,7 +139,7 @@
}
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 = (fs->fmt->format == ast_format_alaw) ? alaw_silence : ulaw_silence;
while (left) {
size_t written = fwrite(src, 1, (left > BUF_SIZE) ? BUF_SIZE : left, fs->f);
@@ -185,17 +183,8 @@
{
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 (s->fmt->format == ast_format_alaw) {
struct pcm_desc *pd = (struct pcm_desc *)fs->_private;
struct stat stat_buf;
unsigned long cur_time = get_time();
@@ -399,7 +388,7 @@
off_t min = AU_HEADER_SIZE, max, cur;
long offset = 0, bytes;
- if (fs->fmt->format.id == AST_FORMAT_G722)
+ if (fs->fmt->format == ast_format_g722)
bytes = sample_offset / 2;
else
bytes = sample_offset;
@@ -523,10 +512,10 @@
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)
Modified: team/group/media_formats/formats/format_siren14.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/formats/format_siren14.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/formats/format_siren14.c (original)
+++ team/group/media_formats/formats/format_siren14.c Tue Feb 11 12:03:49 2014
@@ -34,6 +34,7 @@
#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 @@
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 @@
{
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 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;
Modified: team/group/media_formats/formats/format_siren7.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/formats/format_siren7.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/formats/format_siren7.c (original)
+++ team/group/media_formats/formats/format_siren7.c Tue Feb 11 12:03:49 2014
@@ -34,6 +34,7 @@
#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 @@
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 @@
{
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 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;
Modified: team/group/media_formats/formats/format_sln.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/formats/format_sln.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/formats/format_sln.c (original)
+++ team/group/media_formats/formats/format_sln.c Tue Feb 11 12:03:49 2014
@@ -32,15 +32,13 @@
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
-
-static struct ast_frame *generic_read(struct ast_filestream *s, int *whennext, unsigned int buf_size, enum ast_format_id id)
+#include "asterisk/format_cache.h"
+
+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 @@
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 @@
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 @@
.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 @@
.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 @@
.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 @@
.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 @@
.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 @@
.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 @@
.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 @@
.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 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])) {
Modified: team/group/media_formats/formats/format_vox.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/formats/format_vox.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/formats/format_vox.c (original)
+++ team/group/media_formats/formats/format_vox.c Tue Feb 11 12:03:49 2014
@@ -35,6 +35,7 @@
#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 @@
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 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 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;
Modified: team/group/media_formats/formats/format_wav.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/formats/format_wav.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/formats/format_wav.c (original)
+++ team/group/media_formats/formats/format_wav.c Tue Feb 11 12:03:49 2014
@@ -35,6 +35,9 @@
#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 @@
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, s->fmt->format->codec->sample_rate)) < 0)
return -1;
return 0;
}
@@ -331,7 +334,7 @@
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 = s->fmt->format->codec->sample_rate;
if (write_header(s->f,tmp->hz))
return -1;
return 0;
@@ -379,9 +382,6 @@
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 @@
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 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;
Modified: team/group/media_formats/formats/format_wav_gsm.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/formats/format_wav_gsm.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/formats/format_wav_gsm.c (original)
+++ team/group/media_formats/formats/format_wav_gsm.c Tue Feb 11 12:03:49 2014
@@ -38,6 +38,7 @@
#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 @@
/* 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 @@
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 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;
Modified: team/group/media_formats/include/asterisk/format_cache.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/format_cache.h?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/include/asterisk/format_cache.h (original)
+++ team/group/media_formats/include/asterisk/format_cache.h Tue Feb 11 12:03:49 2014
@@ -134,6 +134,31 @@
extern struct ast_format *ast_format_g729;
/*!
+ * \brief Built-in cached g719 format.
+ */
+extern struct ast_format *ast_format_g719;
+
+/*!
+ * \brief Built-in cached h263 format.
+ */
+extern struct ast_format *ast_format_h263;
+
+/*!
+ * \brief Built-in cached jpeg format.
+ */
+extern struct ast_format *ast_format_jpeg;
+
+/*!
+ * \brief Built-in cached siren14 format.
+ */
+extern struct ast_format *ast_format_siren14;
+
+/*!
+ * \brief Built-in cached siren7 format.
+ */
+extern struct ast_format *ast_format_siren7;
+
+/*!
* \brief Initialize format cache support within the core.
*
* \retval 0 success
Modified: team/group/media_formats/include/asterisk/image.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/image.h?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/include/asterisk/image.h (original)
+++ team/group/media_formats/include/asterisk/image.h Tue Feb 11 12:03:49 2014
@@ -28,7 +28,7 @@
char *name; /*!< Name */
char *desc; /*!< Description */
char *exts; /*!< Extension(s) (separated by '|' ) */
- struct ast_format format; /*!< Image format */
+ struct ast_format *format; /*!< Image format */
struct ast_frame *(*read_image)(int fd, int len); /*!< Read an image from a file descriptor */
int (*identify)(int fd); /*!< Identify if this is that type of file */
int (*write_image)(int fd, struct ast_frame *frame); /*!< Returns length written */
Modified: team/group/media_formats/main/file.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/file.c?view=diff&rev=407957&r1=407956&r2=407957
==============================================================================
--- team/group/media_formats/main/file.c (original)
+++ team/group/media_formats/main/file.c Tue Feb 11 12:03:49 2014
@@ -545,6 +545,9 @@
ast_free(fn); /* cannot allocate descriptor */
continue;
}
+ s->fr.frametype = AST_FRAME_VOICE;
+ ast_format_set(&s->fr.subclass.format, AST_FORMAT_G719, 0);
+ s->fr.mallocd = 0;
if (open_wrapper(s)) {
ast_free(fn);
ast_closestream(s);
More information about the asterisk-commits
mailing list