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

ITU G.719 , 64kbps bitrate only. 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_g719.c:

Go to the source code of this file.

Macros

#define BUF_SIZE   160 /* 20 milliseconds == 160 bytes, 960 samples */
 
#define BYTES_TO_SAMPLES(x)   ((typeof(x)) x * ((float) 960 / 160))
 
#define SAMPLES_TO_BYTES(x)   ((typeof(x)) x / ((float) 960 / 160))
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static struct ast_frameg719read (struct ast_filestream *s, int *whennext)
 
static int g719seek (struct ast_filestream *fs, off_t sample_offset, int whence)
 
static off_t g719tell (struct ast_filestream *fs)
 
static int g719trunc (struct ast_filestream *fs)
 
static int g719write (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 = "ITU G.719" , .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 g719_f
 

Detailed Description

ITU G.719 , 64kbps bitrate only.

Definition in file format_g719.c.

Macro Definition Documentation

◆ BUF_SIZE

#define BUF_SIZE   160 /* 20 milliseconds == 160 bytes, 960 samples */

Definition at line 37 of file format_g719.c.

Referenced by g719read().

◆ BYTES_TO_SAMPLES

#define BYTES_TO_SAMPLES (   x)    ((typeof(x)) x * ((float) 960 / 160))

Definition at line 39 of file format_g719.c.

Referenced by g719read(), and g719tell().

◆ SAMPLES_TO_BYTES

#define SAMPLES_TO_BYTES (   x)    ((typeof(x)) x / ((float) 960 / 160))

Definition at line 38 of file format_g719.c.

Referenced by g719seek().

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 158 of file format_g719.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 158 of file format_g719.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 158 of file format_g719.c.

◆ g719read()

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

Definition at line 41 of file format_g719.c.

References ast_format_get_name(), AST_FRAME_SET_BUFFER, AST_FRIENDLY_OFFSET, ast_log, ast_filestream::buf, BUF_SIZE, BYTES_TO_SAMPLES, 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)) != s->fr.datalen) {
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 = BYTES_TO_SAMPLES(res);
56  return &s->fr;
57 }
#define BUF_SIZE
Definition: format_g719.c:37
#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'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 BYTES_TO_SAMPLES(x)
Definition: format_g719.c:39

◆ g719seek()

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

Definition at line 70 of file format_g719.c.

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

71 {
72  off_t offset = 0, min = 0, cur, max;
73 
74  sample_offset = SAMPLES_TO_BYTES(sample_offset);
75 
76  if ((cur = ftello(fs->f)) < 0) {
77  ast_log(AST_LOG_WARNING, "Unable to determine current position in g719 filestream %p: %s\n", fs, strerror(errno));
78  return -1;
79  }
80 
81  if (fseeko(fs->f, 0, SEEK_END) < 0) {
82  ast_log(AST_LOG_WARNING, "Unable to seek to end of g719 filestream %p: %s\n", fs, strerror(errno));
83  return -1;
84  }
85 
86  if ((max = ftello(fs->f)) < 0) {
87  ast_log(AST_LOG_WARNING, "Unable to determine max position in g719 filestream %p: %s\n", fs, strerror(errno));
88  return -1;
89  }
90 
91  if (whence == SEEK_SET)
92  offset = sample_offset;
93  else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
94  offset = sample_offset + cur;
95  else if (whence == SEEK_END)
96  offset = max - sample_offset;
97 
98  if (whence != SEEK_FORCECUR)
99  offset = (offset > max) ? max : offset;
100 
101  /* always protect against seeking past begining. */
102  offset = (offset < min) ? min : offset;
103 
104  return fseeko(fs->f, offset, SEEK_SET);
105 }
#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 SAMPLES_TO_BYTES(x)
Definition: format_g719.c:38
#define max(a, b)
Definition: f2c.h:198

◆ g719tell()

static off_t g719tell ( struct ast_filestream fs)
static

Definition at line 123 of file format_g719.c.

References BYTES_TO_SAMPLES, and ast_filestream::f.

124 {
125  return BYTES_TO_SAMPLES(ftello(fs->f));
126 }
#define BYTES_TO_SAMPLES(x)
Definition: format_g719.c:39

◆ g719trunc()

static int g719trunc ( struct ast_filestream fs)
static

Definition at line 107 of file format_g719.c.

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

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 g719 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 g719 filestream %p: %s\n", fs, strerror(errno));
118  return -1;
119  }
120  return ftruncate(fd, cur);
121 }
#define AST_LOG_WARNING
Definition: logger.h:279
#define ast_log
Definition: astobj2.c:42
int errno

◆ g719write()

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

Definition at line 59 of file format_g719.c.

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

60 {
61  int res;
62 
63  if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->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

◆ load_module()

static int load_module ( void  )
static

Definition at line 139 of file format_g719.c.

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

Referenced by unload_module().

140 {
142 
146 }
static struct ast_format_def g719_f
Definition: format_g719.c:128
struct ast_format * ast_format_g719
Built-in cached g719 format.
Definition: format_cache.c:161
#define ast_format_def_register(f)
Definition: mod_format.h:136
struct ast_format * format
Definition: mod_format.h:48
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 148 of file format_g719.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.

149 {
151 }
static struct ast_format_def g719_f
Definition: format_g719.c:128
int ast_format_def_unregister(const char *name)
Unregisters a file format.
Definition: file.c:162
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 = "ITU G.719" , .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 158 of file format_g719.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 158 of file format_g719.c.

◆ g719_f

struct ast_format_def g719_f
static

Definition at line 128 of file format_g719.c.