Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Macros | Functions | Variables
format_g729.c File Reference

Save to raw, headerless G729 data. 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_g729.c:

Go to the source code of this file.

Macros

#define BUF_SIZE   20 /* two G729 frames */
 
#define G729A_SAMPLES   160
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static struct ast_frameg729_read (struct ast_filestream *s, int *whennext)
 
static int g729_seek (struct ast_filestream *fs, off_t sample_offset, int whence)
 
static off_t g729_tell (struct ast_filestream *fs)
 
static int g729_trunc (struct ast_filestream *fs)
 
static int g729_write (struct ast_filestream *fs, struct ast_frame *f)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Raw G.729 data" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .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 g729_f
 

Detailed Description

Save to raw, headerless G729 data.

Note
This is not an encoder/decoder. The codec for g729 is only available with a commercial license from Digium, due to patent restrictions. Check http://www.digium.com for information.
  • Extensions: g729

Definition in file format_g729.c.

Macro Definition Documentation

◆ BUF_SIZE

#define BUF_SIZE   20 /* two G729 frames */

Definition at line 44 of file format_g729.c.

◆ G729A_SAMPLES

#define G729A_SAMPLES   160

Definition at line 45 of file format_g729.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 159 of file format_g729.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 159 of file format_g729.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 159 of file format_g729.c.

◆ g729_read()

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

Definition at line 47 of file format_g729.c.

48{
49 size_t res;
50
51 /* Send a frame from the file to the appropriate channel */
54 if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
55 if (res && res != 10) /* XXX what for ? */ {
56 ast_log(LOG_WARNING, "Short read of %s data (expected %d bytes, read %zu): %s\n",
58 strerror(errno));
59 }
60 return NULL;
61 }
62 *whennext = s->fr.samples;
63 return &s->fr;
64}
#define ast_log
Definition astobj2.c:42
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition format.c:334
#define BUF_SIZE
Definition format_g729.c:44
#define G729A_SAMPLES
Definition format_g729.c:45
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
#define LOG_WARNING
int errno
#define NULL
Definition resample.c:96
struct ast_frame fr
frame produced by read, typically
Definition mod_format.h:122
struct ast_format * format
struct ast_frame_subclass subclass
union ast_frame::@239 data

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, G729A_SAMPLES, LOG_WARNING, NULL, ast_frame::ptr, ast_frame::samples, and ast_frame::subclass.

◆ g729_seek()

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

Definition at line 81 of file format_g729.c.

82{
83 long bytes;
84 off_t min,cur,max,offset=0;
85 min = 0;
86 cur = ftello(fs->f);
87 fseeko(fs->f, 0, SEEK_END);
88 max = ftello(fs->f);
89
90 bytes = BUF_SIZE * (sample_offset / G729A_SAMPLES);
91 if (whence == SEEK_SET)
92 offset = bytes;
93 else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
94 offset = cur + bytes;
95 else if (whence == SEEK_END)
96 offset = max - bytes;
97 if (whence != SEEK_FORCECUR) {
98 offset = (offset > max)?max:offset;
99 }
100 /* protect against seeking beyond begining. */
101 offset = (offset < min)?min:offset;
102 if (fseeko(fs->f, offset, SEEK_SET) < 0)
103 return -1;
104 return 0;
105}
#define min(a, b)
Definition f2c.h:197
#define max(a, b)
Definition f2c.h:198
#define SEEK_FORCECUR
Definition file.h:51

References BUF_SIZE, ast_filestream::f, G729A_SAMPLES, max, min, ast_frame::offset, and SEEK_FORCECUR.

◆ g729_tell()

static off_t g729_tell ( struct ast_filestream fs)
static

Definition at line 124 of file format_g729.c.

125{
126 off_t offset = ftello(fs->f);
127 return (offset/BUF_SIZE)*G729A_SAMPLES;
128}

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

◆ g729_trunc()

static int g729_trunc ( struct ast_filestream fs)
static

Definition at line 107 of file format_g729.c.

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

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

◆ g729_write()

static int g729_write ( struct ast_filestream fs,
struct ast_frame f 
)
static

Definition at line 66 of file format_g729.c.

67{
68 int res;
69
70 if (f->datalen % 10) {
71 ast_log(LOG_WARNING, "Invalid data length, %d, should be multiple of 10\n", f->datalen);
72 return -1;
73 }
74 if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) {
75 ast_log(LOG_WARNING, "Bad write (%d/10): %s\n", res, strerror(errno));
76 return -1;
77 }
78 return 0;
79}

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

◆ load_module()

static int load_module ( void  )
static

Definition at line 141 of file format_g729.c.

142{
147}
struct ast_format * ast_format_g729
Built-in cached g729 format.
static struct ast_format_def g729_f
#define ast_format_def_register(f)
Definition mod_format.h:136
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition module.h:78
struct ast_format * format
Definition mod_format.h:48

References ast_format_def_register, ast_format_g729, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_format_def::format, and g729_f.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 149 of file format_g729.c.

150{
152}
int ast_format_def_unregister(const char *name)
Unregisters a file format.
Definition file.c:163
char name[80]
Definition mod_format.h:44

References ast_format_def_unregister(), g729_f, and ast_format_def::name.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Raw G.729 data" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND }
static

Definition at line 159 of file format_g729.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 159 of file format_g729.c.

◆ g729_f

struct ast_format_def g729_f
static

Definition at line 130 of file format_g729.c.

130 {
131 .name = "g729",
132 .exts = "g729",
133 .write = g729_write,
134 .seek = g729_seek,
135 .trunc = g729_trunc,
136 .tell = g729_tell,
137 .read = g729_read,
138 .buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,
139};
static int g729_trunc(struct ast_filestream *fs)
static off_t g729_tell(struct ast_filestream *fs)
static struct ast_frame * g729_read(struct ast_filestream *s, int *whennext)
Definition format_g729.c:47
static int g729_write(struct ast_filestream *fs, struct ast_frame *f)
Definition format_g729.c:66
static int g729_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
Definition format_g729.c:81

Referenced by load_module(), and unload_module().