Wed Jan 8 2020 09:50:12

Asterisk developer's documentation


format_g726.c File Reference

Headerless G.726 (16/24/32/40kbps) data format for Asterisk. More...

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

Go to the source code of this file.

Data Structures

struct  g726_desc
 

Macros

#define BUF_SIZE   (5*FRAME_TIME) /* max frame size in bytes ? */
 
#define FRAME_TIME   10 /* 10 ms size */
 
#define RATE_16   3
 
#define RATE_24   2
 
#define RATE_32   1
 
#define RATE_40   0
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int g726_16_open (struct ast_filestream *s)
 
static int g726_16_rewrite (struct ast_filestream *s, const char *comment)
 
static int g726_24_open (struct ast_filestream *s)
 
static int g726_24_rewrite (struct ast_filestream *s, const char *comment)
 
static int g726_32_open (struct ast_filestream *s)
 
static int g726_32_rewrite (struct ast_filestream *s, const char *comment)
 
static int g726_40_open (struct ast_filestream *s)
 
static int g726_40_rewrite (struct ast_filestream *s, const char *comment)
 
static int g726_open (struct ast_filestream *tmp, int rate)
 
static struct ast_frameg726_read (struct ast_filestream *s, int *whennext)
 
static int g726_seek (struct ast_filestream *fs, off_t sample_offset, int whence)
 
static off_t g726_tell (struct ast_filestream *fs)
 
static int g726_trunc (struct ast_filestream *fs)
 
static int g726_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 = "Raw G.726 (16/24/32/40kbps) data" , .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 f []
 
static int frame_size [4]
 

Detailed Description

Headerless G.726 (16/24/32/40kbps) data format for Asterisk.

File name extensions:

  • 40 kbps: g726-40
  • 32 kbps: g726-32
  • 24 kbps: g726-24
  • 16 kbps: g726-16

Definition in file format_g726.c.

Macro Definition Documentation

#define BUF_SIZE   (5*FRAME_TIME) /* max frame size in bytes ? */

Definition at line 51 of file format_g726.c.

#define FRAME_TIME   10 /* 10 ms size */

Definition at line 49 of file format_g726.c.

Referenced by g726_read().

#define RATE_16   3

Definition at line 46 of file format_g726.c.

Referenced by g726_16_open(), and g726_16_rewrite().

#define RATE_24   2

Definition at line 45 of file format_g726.c.

Referenced by g726_24_open(), and g726_24_rewrite().

#define RATE_32   1

Definition at line 44 of file format_g726.c.

Referenced by g726_32_open(), and g726_32_rewrite().

#define RATE_40   0

Definition at line 43 of file format_g726.c.

Referenced by g726_40_open(), and g726_40_rewrite().

Function Documentation

static void __reg_module ( void  )
static

Definition at line 269 of file format_g726.c.

static void __unreg_module ( void  )
static

Definition at line 269 of file format_g726.c.

static int g726_16_open ( struct ast_filestream s)
static

Definition at line 90 of file format_g726.c.

References g726_open(), and RATE_16.

91 {
92  return g726_open(s, RATE_16);
93 }
static int g726_open(struct ast_filestream *tmp, int rate)
Definition: format_g726.c:67
#define RATE_16
Definition: format_g726.c:46
static int g726_16_rewrite ( struct ast_filestream s,
const char *  comment 
)
static

Definition at line 110 of file format_g726.c.

References g726_open(), and RATE_16.

111 {
112  return g726_open(s, RATE_16);
113 }
static int g726_open(struct ast_filestream *tmp, int rate)
Definition: format_g726.c:67
#define RATE_16
Definition: format_g726.c:46
static int g726_24_open ( struct ast_filestream s)
static

Definition at line 85 of file format_g726.c.

References g726_open(), and RATE_24.

86 {
87  return g726_open(s, RATE_24);
88 }
#define RATE_24
Definition: format_g726.c:45
static int g726_open(struct ast_filestream *tmp, int rate)
Definition: format_g726.c:67
static int g726_24_rewrite ( struct ast_filestream s,
const char *  comment 
)
static

Definition at line 105 of file format_g726.c.

References g726_open(), and RATE_24.

106 {
107  return g726_open(s, RATE_24);
108 }
#define RATE_24
Definition: format_g726.c:45
static int g726_open(struct ast_filestream *tmp, int rate)
Definition: format_g726.c:67
static int g726_32_open ( struct ast_filestream s)
static

Definition at line 80 of file format_g726.c.

References g726_open(), and RATE_32.

81 {
82  return g726_open(s, RATE_32);
83 }
static int g726_open(struct ast_filestream *tmp, int rate)
Definition: format_g726.c:67
#define RATE_32
Definition: format_g726.c:44
static int g726_32_rewrite ( struct ast_filestream s,
const char *  comment 
)
static

Definition at line 100 of file format_g726.c.

References g726_open(), and RATE_32.

101 {
102  return g726_open(s, RATE_32);
103 }
static int g726_open(struct ast_filestream *tmp, int rate)
Definition: format_g726.c:67
#define RATE_32
Definition: format_g726.c:44
static int g726_40_open ( struct ast_filestream s)
static

Definition at line 75 of file format_g726.c.

References g726_open(), and RATE_40.

76 {
77  return g726_open(s, RATE_40);
78 }
static int g726_open(struct ast_filestream *tmp, int rate)
Definition: format_g726.c:67
#define RATE_40
Definition: format_g726.c:43
static int g726_40_rewrite ( struct ast_filestream s,
const char *  comment 
)
static

Definition at line 95 of file format_g726.c.

References g726_open(), and RATE_40.

96 {
97  return g726_open(s, RATE_40);
98 }
static int g726_open(struct ast_filestream *tmp, int rate)
Definition: format_g726.c:67
#define RATE_40
Definition: format_g726.c:43
static int g726_open ( struct ast_filestream tmp,
int  rate 
)
static

Definition at line 67 of file format_g726.c.

References ast_filestream::_private, ast_debug, and g726_desc::rate.

Referenced by g726_16_open(), g726_16_rewrite(), g726_24_open(), g726_24_rewrite(), g726_32_open(), g726_32_rewrite(), g726_40_open(), and g726_40_rewrite().

68 {
69  struct g726_desc *s = (struct g726_desc *)tmp->_private;
70  s->rate = rate;
71  ast_debug(1, "Created filestream G.726-%dk.\n", 40 - s->rate * 8);
72  return 0;
73 }
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
void * _private
Definition: mod_format.h:119
static struct ast_frame* g726_read ( struct ast_filestream s,
int *  whennext 
)
static

Definition at line 119 of file format_g726.c.

References ast_filestream::_private, AST_FORMAT_G726, 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, FRAME_TIME, ast_frame::frametype, LOG_WARNING, ast_frame::mallocd, ast_frame::ptr, g726_desc::rate, ast_frame::samples, and ast_frame::subclass.

120 {
121  int res;
122  struct g726_desc *fs = (struct g726_desc *)s->_private;
123 
124  /* Send a frame from the file to the appropriate channel */
127  s->fr.mallocd = 0;
129  s->fr.samples = 8 * FRAME_TIME;
130  if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
131  if (res)
132  ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
133  return NULL;
134  }
135  *whennext = s->fr.samples;
136  return &s->fr;
137 }
union ast_frame_subclass subclass
Definition: frame.h:146
void * ptr
Definition: frame.h:160
#define LOG_WARNING
Definition: logger.h:144
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
#define AST_FORMAT_G726
Definition: frame.h:264
struct ast_frame fr
Definition: mod_format.h:117
void * _private
Definition: mod_format.h:119
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
#define FRAME_TIME
Definition: format_g726.c:49
union ast_frame::@172 data
int samples
Definition: frame.h:150
static int frame_size[4]
Definition: format_g726.c:53
static int g726_seek ( struct ast_filestream fs,
off_t  sample_offset,
int  whence 
)
static

Definition at line 166 of file format_g726.c.

167 {
168  return -1;
169 }
static off_t g726_tell ( struct ast_filestream fs)
static

Definition at line 176 of file format_g726.c.

177 {
178  return -1;
179 }
static int g726_trunc ( struct ast_filestream fs)
static

Definition at line 171 of file format_g726.c.

172 {
173  return -1;
174 }
static int g726_write ( struct ast_filestream s,
struct ast_frame f 
)
static

Definition at line 139 of file format_g726.c.

References ast_filestream::_private, AST_FORMAT_G726, AST_FRAME_VOICE, ast_getformatname(), ast_log(), ast_frame_subclass::codec, ast_frame::data, ast_frame::datalen, errno, ast_filestream::f, ast_frame::frametype, if(), LOG_WARNING, ast_frame::ptr, g726_desc::rate, and ast_frame::subclass.

140 {
141  int res;
142  struct g726_desc *fs = (struct g726_desc *)s->_private;
143 
144  if (f->frametype != AST_FRAME_VOICE) {
145  ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
146  return -1;
147  }
148  if (f->subclass.codec != AST_FORMAT_G726) {
149  ast_log(LOG_WARNING, "Asked to write non-G726 frame (%s)!\n",
151  return -1;
152  }
153  if (f->datalen % frame_size[fs->rate]) {
154  ast_log(LOG_WARNING, "Invalid data length %d, should be multiple of %d\n",
155  f->datalen, frame_size[fs->rate]);
156  return -1;
157  }
158  if ((res = fwrite(f->data.ptr, 1, f->datalen, s->f)) != f->datalen) {
159  ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n",
160  res, frame_size[fs->rate], strerror(errno));
161  return -1;
162  }
163  return 0;
164 }
union ast_frame_subclass subclass
Definition: frame.h:146
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
#define AST_FORMAT_G726
Definition: frame.h:264
void * _private
Definition: mod_format.h:119
char * ast_getformatname(format_t format)
Get the name of a format.
Definition: frame.c:578
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
if(yyss+yystacksize-1<=yyssp)
Definition: ast_expr2.c:1874
enum ast_frame_type frametype
Definition: frame.h:144
union ast_frame::@172 data
static int frame_size[4]
Definition: format_g726.c:53
static int load_module ( void  )
static

Definition at line 241 of file format_g726.c.

References ast_format_register, ast_log(), AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_format::format, LOG_WARNING, and name.

242 {
243  int i;
244 
245  for (i = 0; f[i].format ; i++) {
246  if (ast_format_register(&f[i])) { /* errors are fatal */
247  ast_log(LOG_WARNING, "Failed to register format %s.\n", f[i].name);
249  }
250  }
252 }
#define ast_format_register(f)
Definition: mod_format.h:131
#define LOG_WARNING
Definition: logger.h:144
format_t format
Definition: mod_format.h:47
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
static const char name[]
static struct ast_format f[]
Definition: format_g726.c:181
static int unload_module ( void  )
static

Definition at line 254 of file format_g726.c.

References ast_format_unregister(), ast_log(), ast_format::format, LOG_WARNING, and name.

255 {
256  int i;
257 
258  for (i = 0; f[i].format ; i++) {
259  if (ast_format_unregister(f[i].name))
260  ast_log(LOG_WARNING, "Failed to unregister format %s.\n", f[i].name);
261  }
262  return(0);
263 }
#define LOG_WARNING
Definition: logger.h:144
format_t format
Definition: mod_format.h:47
int ast_format_unregister(const char *name)
Unregisters a file format.
Definition: file.c:104
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
static const char name[]
static struct ast_format f[]
Definition: format_g726.c:181

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Raw G.726 (16/24/32/40kbps) data" , .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 269 of file format_g726.c.

Definition at line 269 of file format_g726.c.

struct ast_format f[]
static

Definition at line 181 of file format_g726.c.

Referenced by __adsi_transmit_messages(), __analog_handle_event(), __analog_ss_thread(), __ast_format_register(), __ast_play_and_record(), __ast_queue_frame(), __ast_read(), __ast_request_and_dial(), __ast_smoother_feed(), __attempt_transmit(), __dahdi_exception(), adpcm_sample(), adsi_message(), agent_ack_sleep(), agent_read(), alaw_sample(), alloc_profile(), alsa_read(), analog_exception(), analog_handle_dtmf(), analog_ss_thread(), app_exec(), ast_autoservice_stop(), ast_bridge_call(), ast_channel_destructor(), ast_config_text_file_save(), ast_el_read_history(), ast_filehelper(), ast_format_str_reduce(), ast_frame_header_new(), ast_generic_bridge(), ast_jb_destroy(), ast_read_image(), ast_readfile(), ast_recvtext(), ast_rtcp_read(), ast_rtp_read(), ast_rtp_write(), ast_safe_sleep_conditional(), ast_send_image(), ast_slinfactory_destroy(), ast_slinfactory_feed(), ast_trans_frameout(), ast_translate(), ast_udptl_bridge(), ast_ulaw_init(), ast_writefile(), async_agi_read_frame(), async_wait(), auth_exec(), autoservice_run(), cache_cmp(), calc_cost(), channel_spy(), check_bridge(), close_logger(), compile_script(), conf_flush(), conf_run(), config_text_file_load(), create_video_frame(), dahdi_accept_r2_call_exec(), dahdi_bridge(), dahdi_exception(), dahdi_handle_dtmf(), dahdi_handle_event(), dahdi_read(), dictate_exec(), disa_exec(), do_idle_thread(), do_waiting(), echo_exec(), eivr_comm(), execif_exec(), fakesrc_sample(), feature_request_and_dial(), filestream_destructor(), find_cache(), fn_wrapper(), frame_cache_cleanup(), function_realtime_store(), g722_sample(), g726_sample(), gen_generate(), gen_readframe(), generic_fax_exec(), get_bit_raw(), gsm_sample(), gtalk_rtp_read(), h261_encap(), h263_encap(), h263p_encap(), h264_encap(), handle_cli_core_show_file_formats(), handle_cli_file_convert(), handle_recordfile(), handle_request_info(), http_post_callback(), iax2_bridge(), iax2_trunk_queue(), ices_exec(), ilbc_sample(), isAnsweringMachine(), jack_exec(), jb_empty_and_reset_adaptive(), jb_get_and_deliver(), jingle_rtp_read(), key_history(), lintoadpcm_frameout(), load_pktccops_config(), lpc10_sample(), lua_read_extensions_file(), main(), manage_parked_call(), measurenoise(), mgcp_read(), mgcp_rtp_read(), misdn_bridge(), misdn_lib_nt_debug_init(), moh_files_generator(), moh_files_readframe(), mp3_exec(), mpeg4_encap(), multicast_rtp_write(), my_handle_dtmf(), NBScat_exec(), oh323_rtp_read(), op_func(), oss_read(), parse(), process_ast_dsp(), process_dtmf_cisco(), process_dtmf_rfc2833(), queue_signalling(), readdirqueue(), receive_dtmf_digits(), receive_message(), record_exec(), recordthread(), reload_followme(), reload_logger(), remove_from_queue(), run_agi(), safe_append(), scan_service(), send_string(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), session_destroy(), show_history(), sip_rtp_read(), skinny_rtp_read(), slin16_sample(), slin8_sample(), sms_handleincoming_proto2(), sms_hexdump(), spandsp_fax_read(), speech_background(), speex16_sample(), speex_sample(), spy_generate(), strip_quotes(), t38_tx_packet_handler(), testclient_exec(), testserver_exec(), try_load_key(), udptlread(), ulaw_sample(), unistim_rtp_read(), unload_module(), vnak_retransmit(), wait_for_answer(), wait_for_hangup(), wait_for_winner(), waitforring_exec(), write_history(), and writefile().

int frame_size[4]
static

Definition at line 53 of file format_g726.c.

Referenced by local_attended_transfer(), and masquerade_colp_transfer().