Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions | Variables
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"
#include "asterisk/format_cache.h"
Include dependency graph for format_g723.c:

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)
 
struct ast_moduleAST_MODULE_SELF_SYM (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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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 g723_1_f
 

Detailed Description

Old-style G.723.1 frame/timestamp format.

Definition in file format_g723.c.

Macro Definition Documentation

◆ G723_MAX_SIZE

#define G723_MAX_SIZE   1024

Definition at line 38 of file format_g723.c.

Referenced by g723_read().

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 163 of file format_g723.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 163 of file format_g723.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 163 of file format_g723.c.

◆ g723_read()

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

Definition at line 40 of file format_g723.c.

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

41 {
42  unsigned short size;
43  size_t res;
44  int delay;
45  /* Read the delay for the next packet, and schedule again if necessary */
46  /* XXX is this ignored ? */
47  if (fread(&delay, 1, 4, s->f) == 4)
48  delay = ntohl(delay);
49  else
50  delay = -1;
51  if (fread(&size, 1, 2, s->f) != 2) {
52  /* Out of data, or the file is no longer valid. In any case
53  go ahead and stop the stream */
54  return NULL;
55  }
56  /* Looks like we have a frame to read from here */
57  size = ntohs(size);
58  if (size > G723_MAX_SIZE) {
59  ast_log(LOG_WARNING, "Size %d is invalid\n", size);
60  /* The file is apparently no longer any good, as we
61  shouldn't ever get frames even close to this
62  size. */
63  return NULL;
64  }
65  /* Read the data into the buffer */
67  if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
68  if (res) {
69  ast_log(LOG_WARNING, "Short read of %s data (expected %d bytes, read %zu): %s\n",
71  strerror(errno));
72  }
73  return NULL;
74  }
75  *whennext = s->fr.samples = 240;
76  return &s->fr;
77 }
#define LOG_WARNING
Definition: logger.h:274
#define G723_MAX_SIZE
Definition: format_g723.c:38
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'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

◆ g723_seek()

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

Definition at line 106 of file format_g723.c.

107 {
108  return -1;
109 }

◆ g723_tell()

static off_t g723_tell ( struct ast_filestream fs)
static

Definition at line 128 of file format_g723.c.

129 {
130  return -1;
131 }

◆ g723_trunc()

static int g723_trunc ( struct ast_filestream fs)
static

Definition at line 111 of file format_g723.c.

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

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

◆ g723_write()

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

Definition at line 79 of file format_g723.c.

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

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  delay = 0;
86  if (f->datalen <= 0) {
87  ast_log(LOG_WARNING, "Short frame ignored (%d bytes long?)\n", f->datalen);
88  return 0;
89  }
90  if ((res = fwrite(&delay, 1, 4, s->f)) != 4) {
91  ast_log(LOG_WARNING, "Unable to write delay: res=%d (%s)\n", res, strerror(errno));
92  return -1;
93  }
94  size = htons(f->datalen);
95  if ((res = fwrite(&size, 1, 2, s->f)) != 2) {
96  ast_log(LOG_WARNING, "Unable to write size: res=%d (%s)\n", res, strerror(errno));
97  return -1;
98  }
99  if ((res = fwrite(f->data.ptr, 1, f->datalen, s->f)) != f->datalen) {
100  ast_log(LOG_WARNING, "Unable to write frame: res=%d (%s)\n", res, strerror(errno));
101  return -1;
102  }
103  return 0;
104 }
#define LOG_WARNING
Definition: logger.h:274
#define ast_log
Definition: astobj2.c:42
int errno
union ast_frame::@263 data

◆ load_module()

static int load_module ( void  )
static

Definition at line 144 of file format_g723.c.

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

Referenced by unload_module().

145 {
147 
151 }
struct ast_format * ast_format_g723
Built-in cached g723.1 format.
Definition: format_cache.c:151
#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 g723_1_f
Definition: format_g723.c:133
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 153 of file format_g723.c.

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

154 {
156 }
int ast_format_def_unregister(const char *name)
Unregisters a file format.
Definition: file.c:162
static struct ast_format_def g723_1_f
Definition: format_g723.c:133
char name[80]
Definition: mod_format.h:44

Variable Documentation

◆ __mod_info

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND }
static

Definition at line 163 of file format_g723.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 163 of file format_g723.c.

◆ g723_1_f

struct ast_format_def g723_1_f
static

Definition at line 133 of file format_g723.c.