Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions | Variables
format_vox.c File Reference

Flat, binary, ADPCM vox file format. More...

#include "asterisk.h"
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
#include "asterisk/format_cache.h"
Include dependency graph for format_vox.c:

Go to the source code of this file.

Macros

#define BUF_SIZE   80 /* 80 bytes, 160 samples */
 
#define VOX_SAMPLES   160
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int unload_module (void)
 
static struct ast_framevox_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_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Dialogic VOX (ADPCM) File Format" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_format_def vox_f
 

Detailed Description

Flat, binary, ADPCM vox file format.

Definition in file format_vox.c.

Macro Definition Documentation

◆ BUF_SIZE

#define BUF_SIZE   80 /* 80 bytes, 160 samples */

Definition at line 38 of file format_vox.c.

Referenced by vox_read().

◆ VOX_SAMPLES

#define VOX_SAMPLES   160

Definition at line 39 of file format_vox.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 158 of file format_vox.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 158 of file format_vox.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 158 of file format_vox.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 140 of file format_vox.c.

References ast_format_adpcm, ast_format_def_register, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and ast_format_def::format.

Referenced by unload_module().

141 {
146 }
#define ast_format_def_register(f)
Definition: mod_format.h:136
struct ast_format * format
Definition: mod_format.h:48
static struct ast_format_def vox_f
Definition: format_vox.c:128
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
struct ast_format * ast_format_adpcm
Built-in cached adpcm format.
Definition: format_cache.c:106

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 148 of file format_vox.c.

References ast_format_def_unregister(), AST_MODFLAG_LOAD_ORDER, AST_MODPRI_APP_DEPEND, AST_MODULE_INFO(), AST_MODULE_SUPPORT_EXTENDED, ASTERISK_GPL_KEY, load_module(), and ast_format_def::name.

149 {
151 }
int ast_format_def_unregister(const char *name)
Unregisters a file format.
Definition: file.c:162
char name[80]
Definition: mod_format.h:44
static struct ast_format_def vox_f
Definition: format_vox.c:128

◆ vox_read()

static struct ast_frame* vox_read ( struct ast_filestream s,
int *  whennext 
)
static

Definition at line 41 of file format_vox.c.

References ast_format_get_name(), AST_FRAME_SET_BUFFER, AST_FRIENDLY_OFFSET, ast_log, ast_filestream::buf, BUF_SIZE, ast_frame::data, ast_frame::datalen, errno, ast_filestream::f, ast_frame_subclass::format, ast_filestream::fr, LOG_WARNING, NULL, ast_frame::ptr, ast_frame::samples, and ast_frame::subclass.

42 {
43  size_t res;
44 
45  /* Send a frame from the file to the appropriate channel */
47  if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) < 1) {
48  if (res) {
49  ast_log(LOG_WARNING, "Short read of %s data (expected %d bytes, read %zu): %s\n",
51  strerror(errno));
52  }
53  return NULL;
54  }
55  *whennext = s->fr.samples = res * 2;
56  s->fr.datalen = res;
57  return &s->fr;
58 }
#define LOG_WARNING
Definition: logger.h:274
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
#define NULL
Definition: resample.c:96
struct ast_frame_subclass subclass
#define ast_log
Definition: astobj2.c:42
#define AST_FRIENDLY_OFFSET
Offset into a frame&#39;s data buffer.
struct ast_frame fr
frame produced by read, typically
Definition: mod_format.h:122
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
int errno
union ast_frame::@263 data
struct ast_format * format
#define BUF_SIZE
Definition: format_vox.c:38

◆ vox_seek()

static int vox_seek ( struct ast_filestream fs,
off_t  sample_offset,
int  whence 
)
static

Definition at line 70 of file format_vox.c.

References ast_log, AST_LOG_WARNING, errno, ast_filestream::f, max, min, ast_frame::offset, and SEEK_FORCECUR.

71 {
72  off_t offset = 0, min = 0, cur, max, distance;
73 
74  if ((cur = ftello(fs->f)) < 0) {
75  ast_log(AST_LOG_WARNING, "Unable to determine current position in g719 filestream %p: %s\n", fs, strerror(errno));
76  return -1;
77  }
78 
79  if (fseeko(fs->f, 0, SEEK_END) < 0) {
80  ast_log(AST_LOG_WARNING, "Unable to seek to end of g719 filestream %p: %s\n", fs, strerror(errno));
81  return -1;
82  }
83 
84  if ((max = ftello(fs->f)) < 0) {
85  ast_log(AST_LOG_WARNING, "Unable to determine max position in g719 filestream %p: %s\n", fs, strerror(errno));
86  return -1;
87  }
88 
89  /* have to fudge to frame here, so not fully to sample */
90  distance = sample_offset/2;
91  if (whence == SEEK_SET) {
92  offset = distance;
93  } else if (whence == SEEK_CUR || whence == SEEK_FORCECUR) {
94  offset = distance + cur;
95  } else if (whence == SEEK_END) {
96  offset = max - distance;
97  }
98  if (whence != SEEK_FORCECUR) {
99  offset = (offset > max)?max:offset;
100  offset = (offset < min)?min:offset;
101  }
102  return fseeko(fs->f, offset, SEEK_SET);
103 }
#define AST_LOG_WARNING
Definition: logger.h:279
#define ast_log
Definition: astobj2.c:42
int errno
#define SEEK_FORCECUR
Definition: file.h:51
#define min(a, b)
Definition: f2c.h:197
#define max(a, b)
Definition: f2c.h:198

◆ vox_tell()

static off_t vox_tell ( struct ast_filestream fs)
static

Definition at line 121 of file format_vox.c.

References ast_filestream::f, and ast_frame::offset.

122 {
123  off_t offset;
124  offset = ftello(fs->f) << 1;
125  return offset;
126 }

◆ vox_trunc()

static int vox_trunc ( struct ast_filestream fs)
static

Definition at line 105 of file format_vox.c.

References ast_log, AST_LOG_WARNING, errno, and ast_filestream::f.

106 {
107  int fd;
108  off_t cur;
109 
110  if ((fd = fileno(fs->f)) < 0) {
111  ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for vox filestream %p: %s\n", fs, strerror(errno));
112  return -1;
113  }
114  if ((cur = ftello(fs->f)) < 0) {
115  ast_log(AST_LOG_WARNING, "Unable to determine current position in vox filestream %p: %s\n", fs, strerror(errno));
116  return -1;
117  }
118  /* Truncate file to current length */
119  return ftruncate(fd, cur);}
#define AST_LOG_WARNING
Definition: logger.h:279
#define ast_log
Definition: astobj2.c:42
int errno

◆ vox_write()

static int vox_write ( struct ast_filestream s,
struct ast_frame f 
)
static

Definition at line 60 of file format_vox.c.

References ast_log, ast_frame::data, ast_frame::datalen, errno, ast_filestream::f, LOG_WARNING, and ast_frame::ptr.

61 {
62  int res;
63  if ((res = fwrite(f->data.ptr, 1, f->datalen, s->f)) != f->datalen) {
64  ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
65  return -1;
66  }
67  return 0;
68 }
#define LOG_WARNING
Definition: logger.h:274
#define ast_log
Definition: astobj2.c:42
int errno
union ast_frame::@263 data

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Dialogic VOX (ADPCM) File Format" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND }
static

Definition at line 158 of file format_vox.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 158 of file format_vox.c.

◆ vox_f

struct ast_format_def vox_f
static

Definition at line 128 of file format_vox.c.