#include "asterisk.h"
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <sys/time.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/sched.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
Include dependency graph for format_vox.c:
Go to the source code of this file.
Defines | |
#define | BUF_SIZE 80 |
#define | VOX_SAMPLES 160 |
Functions | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Dialogic VOX (ADPCM) File Format") | |
static int | load_module (void) |
static int | unload_module (void) |
static struct ast_frame * | vox_read (struct ast_filestream *s, int *whennext) |
static int | vox_seek (struct ast_filestream *fs, off_t sample_offset, int whence) |
static off_t | vox_tell (struct ast_filestream *fs) |
static int | vox_trunc (struct ast_filestream *fs) |
static int | vox_write (struct ast_filestream *s, struct ast_frame *f) |
Variables | |
static struct ast_format | vox_f |
Definition in file format_vox.c.
#define BUF_SIZE 80 |
Definition at line 48 of file format_vox.c.
#define VOX_SAMPLES 160 |
Definition at line 49 of file format_vox.c.
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Dialogic VOX (ADPCM) File Format" | ||||
) |
static int load_module | ( | void | ) | [static] |
Definition at line 136 of file format_vox.c.
References ast_format_register, and vox_f.
00137 { 00138 return ast_format_register(&vox_f); 00139 }
static int unload_module | ( | void | ) | [static] |
Definition at line 141 of file format_vox.c.
References ast_format_unregister(), ast_format::name, and vox_f.
00142 { 00143 return ast_format_unregister(vox_f.name); 00144 }
static struct ast_frame* vox_read | ( | struct ast_filestream * | s, | |
int * | whennext | |||
) | [static] |
Definition at line 51 of file format_vox.c.
References AST_FORMAT_ADPCM, AST_FRAME_SET_BUFFER, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), BUF_SIZE, LOG_WARNING, and s.
00052 { 00053 int res; 00054 00055 /* Send a frame from the file to the appropriate channel */ 00056 s->fr.frametype = AST_FRAME_VOICE; 00057 s->fr.subclass = AST_FORMAT_ADPCM; 00058 s->fr.mallocd = 0; 00059 AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE); 00060 if ((res = fread(s->fr.data, 1, s->fr.datalen, s->f)) < 1) { 00061 if (res) 00062 ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno)); 00063 return NULL; 00064 } 00065 *whennext = s->fr.samples = res * 2; 00066 s->fr.datalen = res; 00067 return &s->fr; 00068 }
static int vox_seek | ( | struct ast_filestream * | fs, | |
off_t | sample_offset, | |||
int | whence | |||
) | [static] |
Definition at line 88 of file format_vox.c.
References ast_filestream::f, offset, and SEEK_FORCECUR.
00089 { 00090 off_t offset=0,min,cur,max,distance; 00091 00092 min = 0; 00093 cur = ftello(fs->f); 00094 fseeko(fs->f, 0, SEEK_END); 00095 max = ftello(fs->f); 00096 00097 /* have to fudge to frame here, so not fully to sample */ 00098 distance = sample_offset/2; 00099 if(whence == SEEK_SET) 00100 offset = distance; 00101 else if(whence == SEEK_CUR || whence == SEEK_FORCECUR) 00102 offset = distance + cur; 00103 else if(whence == SEEK_END) 00104 offset = max - distance; 00105 if (whence != SEEK_FORCECUR) { 00106 offset = (offset > max)?max:offset; 00107 offset = (offset < min)?min:offset; 00108 } 00109 return fseeko(fs->f, offset, SEEK_SET); 00110 }
static off_t vox_tell | ( | struct ast_filestream * | fs | ) | [static] |
static int vox_trunc | ( | struct ast_filestream * | fs | ) | [static] |
static int vox_write | ( | struct ast_filestream * | s, | |
struct ast_frame * | f | |||
) | [static] |
Definition at line 70 of file format_vox.c.
References AST_FORMAT_ADPCM, AST_FRAME_VOICE, ast_log(), f, LOG_WARNING, and s.
00071 { 00072 int res; 00073 if (f->frametype != AST_FRAME_VOICE) { 00074 ast_log(LOG_WARNING, "Asked to write non-voice frame!\n"); 00075 return -1; 00076 } 00077 if (f->subclass != AST_FORMAT_ADPCM) { 00078 ast_log(LOG_WARNING, "Asked to write non-ADPCM frame (%d)!\n", f->subclass); 00079 return -1; 00080 } 00081 if ((res = fwrite(f->data, 1, f->datalen, s->f)) != f->datalen) { 00082 ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno)); 00083 return -1; 00084 } 00085 return 0; 00086 }
struct ast_format vox_f [static] |