* \arg File name extensions: siren14
* \ingroup formats
*/
-
-#include "asterisk.h"
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+/*** MODULEINFO
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
#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))
static struct ast_frame *siren14read(struct ast_filestream *s, int *whennext)
{
- int res;
- /* Send a frame from the file to the appropriate channel */
+ size_t res;
- s->fr.frametype = AST_FRAME_VOICE;
- s->fr.subclass.codec = AST_FORMAT_SIREN14;
- s->fr.mallocd = 0;
+ /* Send a frame from the file to the appropriate channel */
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)
- ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
+ if (res) {
+ ast_log(LOG_WARNING, "Short read of %s data (expected %d bytes, read %zu): %s\n",
+ ast_format_get_name(s->fr.subclass.format), s->fr.datalen, res,
+ strerror(errno));
+ }
return NULL;
}
*whennext = s->fr.samples = BYTES_TO_SAMPLES(res);
{
int res;
- if (f->frametype != AST_FRAME_VOICE) {
- ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
- return -1;
- }
- if (f->subclass.codec != AST_FORMAT_SIREN14) {
- ast_log(LOG_WARNING, "Asked to write non-Siren14 frame (%s)!\n", ast_getformatname(f->subclass.codec));
- 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;
sample_offset = SAMPLES_TO_BYTES(sample_offset);
- cur = ftello(fs->f);
+ if ((cur = ftello(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in siren14 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
- fseeko(fs->f, 0, SEEK_END);
+ if (fseeko(fs->f, 0, SEEK_END) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to seek to end of siren14 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
- max = ftello(fs->f);
+ if ((max = ftello(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine max position in siren14 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
if (whence == SEEK_SET)
offset = sample_offset;
static int siren14trunc(struct ast_filestream *fs)
{
- return ftruncate(fileno(fs->f), ftello(fs->f));
+ int fd;
+ off_t cur;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for siren14 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in siren14 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ /* Truncate file to current length */
+ return ftruncate(fd, cur);
}
static off_t siren14tell(struct ast_filestream *fs)
return BYTES_TO_SAMPLES(ftello(fs->f));
}
-static const struct ast_format siren14_f = {
+static struct ast_format_def siren14_f = {
.name = "siren14",
.exts = "siren14",
- .format = AST_FORMAT_SIREN14,
.write = siren14write,
.seek = siren14seek,
.trunc = siren14trunc,
static int load_module(void)
{
- if (ast_format_register(&siren14_f))
+ siren14_f.format = ast_format_siren14;
+ if (ast_format_def_register(&siren14_f))
return AST_MODULE_LOAD_DECLINE;
return AST_MODULE_LOAD_SUCCESS;
static int unload_module(void)
{
- return ast_format_unregister(siren14_f.name);
+ return ast_format_def_unregister(siren14_f.name);
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "ITU G.722.1 Annex C (Siren14, licensed from Polycom)",
+ .support_level = AST_MODULE_SUPPORT_CORE,
.load = load_module,
.unload = unload_module,
.load_pri = AST_MODPRI_APP_DEPEND