Wed Jan 8 2020 09:50:12

Asterisk developer's documentation


format_g723.c File Reference

Old-style G.723.1 frame/timestamp format. More...

#include "asterisk.h"
#include "asterisk/mod_format.h"
#include "asterisk/module.h"

Go to the source code of this file.

Macros

#define G723_MAX_SIZE   1024
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static struct ast_frameg723_read (struct ast_filestream *s, int *whennext)
 
static int g723_seek (struct ast_filestream *fs, off_t sample_offset, int whence)
 
static off_t g723_tell (struct ast_filestream *fs)
 
static int g723_trunc (struct ast_filestream *fs)
 
static int g723_write (struct ast_filestream *s, 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 = "G.723.1 Simple Timestamp 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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND }
 
static struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_format g723_1_f
 

Detailed Description

Old-style G.723.1 frame/timestamp format.

  • Extensions: g723, g723sf

Definition in file format_g723.c.

Macro Definition Documentation

#define G723_MAX_SIZE   1024

Definition at line 39 of file format_g723.c.

Referenced by g723_read().

Function Documentation

static void __reg_module ( void  )
static

Definition at line 169 of file format_g723.c.

static void __unreg_module ( void  )
static

Definition at line 169 of file format_g723.c.

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

Definition at line 41 of file format_g723.c.

References AST_FORMAT_G723_1, AST_FRAME_SET_BUFFER, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_filestream::buf, ast_frame_subclass::codec, ast_frame::data, ast_frame::datalen, errno, ast_filestream::f, ast_filestream::fr, ast_frame::frametype, G723_MAX_SIZE, LOG_WARNING, ast_frame::mallocd, ast_frame::ptr, ast_frame::samples, and ast_frame::subclass.

42 {
43  unsigned short size;
44  int res;
45  int delay;
46  /* Read the delay for the next packet, and schedule again if necessary */
47  /* XXX is this ignored ? */
48  if (fread(&delay, 1, 4, s->f) == 4)
49  delay = ntohl(delay);
50  else
51  delay = -1;
52  if (fread(&size, 1, 2, s->f) != 2) {
53  /* Out of data, or the file is no longer valid. In any case
54  go ahead and stop the stream */
55  return NULL;
56  }
57  /* Looks like we have a frame to read from here */
58  size = ntohs(size);
59  if (size > G723_MAX_SIZE) {
60  ast_log(LOG_WARNING, "Size %d is invalid\n", size);
61  /* The file is apparently no longer any good, as we
62  shouldn't ever get frames even close to this
63  size. */
64  return NULL;
65  }
66  /* Read the data into the buffer */
69  s->fr.mallocd = 0;
71  if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != size) {
72  ast_log(LOG_WARNING, "Short read (%d of %d bytes) (%s)!\n", res, size, strerror(errno));
73  return NULL;
74  }
75  *whennext = s->fr.samples = 240;
76  return &s->fr;
77 }
union ast_frame_subclass subclass
Definition: frame.h:146
#define AST_FORMAT_G723_1
Definition: frame.h:242
void * ptr
Definition: frame.h:160
#define LOG_WARNING
Definition: logger.h:144
#define G723_MAX_SIZE
Definition: format_g723.c:39
format_t codec
Definition: frame.h:137
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
Definition: frame.h:183
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
Definition: frame.h:204
int datalen
Definition: frame.h:148
struct ast_frame fr
Definition: mod_format.h:117
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
int mallocd
Definition: frame.h:152
enum ast_frame_type frametype
Definition: frame.h:144
union ast_frame::@172 data
int samples
Definition: frame.h:150
static int g723_seek ( struct ast_filestream fs,
off_t  sample_offset,
int  whence 
)
static

Definition at line 114 of file format_g723.c.

115 {
116  return -1;
117 }
static off_t g723_tell ( struct ast_filestream fs)
static

Definition at line 136 of file format_g723.c.

137 {
138  return -1;
139 }
static int g723_trunc ( struct ast_filestream fs)
static

Definition at line 119 of file format_g723.c.

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

120 {
121  int fd;
122  off_t cur;
123 
124  if ((fd = fileno(fs->f)) < 0) {
125  ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for g723 filestream %p: %s\n", fs, strerror(errno));
126  return -1;
127  }
128  if ((cur = ftello(fs->f)) < 0) {
129  ast_log(AST_LOG_WARNING, "Unable to determine current position in g723 filestream %p: %s\n", fs, strerror(errno));
130  return -1;
131  }
132  /* Truncate file to current length */
133  return ftruncate(fd, cur);
134 }
#define AST_LOG_WARNING
Definition: logger.h:149
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
static int g723_write ( struct ast_filestream s,
struct ast_frame f 
)
static

Definition at line 79 of file format_g723.c.

References AST_FORMAT_G723_1, AST_FRAME_VOICE, ast_log(), ast_frame_subclass::codec, ast_frame::data, ast_frame::datalen, errno, ast_filestream::f, ast_frame::frametype, LOG_WARNING, ast_frame::ptr, and ast_frame::subclass.

80 {
81  uint32_t delay;
82  uint16_t size;
83  int res;
84  /* XXX there used to be a check s->fr means a read stream */
85  if (f->frametype != AST_FRAME_VOICE) {
86  ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
87  return -1;
88  }
89  if (f->subclass.codec != AST_FORMAT_G723_1) {
90  ast_log(LOG_WARNING, "Asked to write non-g723 frame!\n");
91  return -1;
92  }
93  delay = 0;
94  if (f->datalen <= 0) {
95  ast_log(LOG_WARNING, "Short frame ignored (%d bytes long?)\n", f->datalen);
96  return 0;
97  }
98  if ((res = fwrite(&delay, 1, 4, s->f)) != 4) {
99  ast_log(LOG_WARNING, "Unable to write delay: res=%d (%s)\n", res, strerror(errno));
100  return -1;
101  }
102  size = htons(f->datalen);
103  if ((res = fwrite(&size, 1, 2, s->f)) != 2) {
104  ast_log(LOG_WARNING, "Unable to write size: res=%d (%s)\n", res, strerror(errno));
105  return -1;
106  }
107  if ((res = fwrite(f->data.ptr, 1, f->datalen, s->f)) != f->datalen) {
108  ast_log(LOG_WARNING, "Unable to write frame: res=%d (%s)\n", res, strerror(errno));
109  return -1;
110  }
111  return 0;
112 }
union ast_frame_subclass subclass
Definition: frame.h:146
#define AST_FORMAT_G723_1
Definition: frame.h:242
void * ptr
Definition: frame.h:160
#define LOG_WARNING
Definition: logger.h:144
format_t codec
Definition: frame.h:137
int datalen
Definition: frame.h:148
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
enum ast_frame_type frametype
Definition: frame.h:144
union ast_frame::@172 data
static int load_module ( void  )
static

Definition at line 153 of file format_g723.c.

References ast_format_register, AST_MODULE_LOAD_FAILURE, and AST_MODULE_LOAD_SUCCESS.

154 {
158 }
#define ast_format_register(f)
Definition: mod_format.h:131
static struct ast_format g723_1_f
Definition: format_g723.c:141
static int unload_module ( void  )
static

Definition at line 160 of file format_g723.c.

References ast_format_unregister(), and ast_format::name.

161 {
163 }
int ast_format_unregister(const char *name)
Unregisters a file format.
Definition: file.c:104
char name[80]
Definition: mod_format.h:44
static struct ast_format g723_1_f
Definition: format_g723.c:141

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "G.723.1 Simple Timestamp 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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND }
static

Definition at line 169 of file format_g723.c.

Definition at line 169 of file format_g723.c.

struct ast_format g723_1_f
static

Definition at line 141 of file format_g723.c.