Wed Oct 28 11:52:25 2009

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"

Include dependency graph for format_g726.c:

Go to the source code of this file.

Data Structures

struct  g726_desc

Defines

#define BUF_SIZE   (5*FRAME_TIME)
#define FRAME_TIME   10
#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_DEFAULT , .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, }
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:

Definition in file format_g726.c.


Define Documentation

#define BUF_SIZE   (5*FRAME_TIME)

#define FRAME_TIME   10

Definition at line 45 of file format_g726.c.

Referenced by g726_read().

#define RATE_16   3

Definition at line 42 of file format_g726.c.

Referenced by g726_16_open(), and g726_16_rewrite().

#define RATE_24   2

Definition at line 41 of file format_g726.c.

Referenced by g726_24_open(), and g726_24_rewrite().

#define RATE_32   1

Definition at line 40 of file format_g726.c.

Referenced by g726_32_open(), and g726_32_rewrite().

#define RATE_40   0

Definition at line 39 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 261 of file format_g726.c.

static void __unreg_module ( void   )  [static]

Definition at line 261 of file format_g726.c.

static int g726_16_open ( struct ast_filestream s  )  [static]

Definition at line 86 of file format_g726.c.

References g726_open(), and RATE_16.

00087 {
00088    return g726_open(s, RATE_16);
00089 }

static int g726_16_rewrite ( struct ast_filestream s,
const char *  comment 
) [static]

Definition at line 106 of file format_g726.c.

References g726_open(), and RATE_16.

00107 {
00108    return g726_open(s, RATE_16);
00109 }

static int g726_24_open ( struct ast_filestream s  )  [static]

Definition at line 81 of file format_g726.c.

References g726_open(), and RATE_24.

00082 {
00083    return g726_open(s, RATE_24);
00084 }

static int g726_24_rewrite ( struct ast_filestream s,
const char *  comment 
) [static]

Definition at line 101 of file format_g726.c.

References g726_open(), and RATE_24.

00102 {
00103    return g726_open(s, RATE_24);
00104 }

static int g726_32_open ( struct ast_filestream s  )  [static]

Definition at line 76 of file format_g726.c.

References g726_open(), and RATE_32.

00077 {
00078    return g726_open(s, RATE_32);
00079 }

static int g726_32_rewrite ( struct ast_filestream s,
const char *  comment 
) [static]

Definition at line 96 of file format_g726.c.

References g726_open(), and RATE_32.

00097 {
00098    return g726_open(s, RATE_32);
00099 }

static int g726_40_open ( struct ast_filestream s  )  [static]

Definition at line 71 of file format_g726.c.

References g726_open(), and RATE_40.

00072 {
00073    return g726_open(s, RATE_40);
00074 }

static int g726_40_rewrite ( struct ast_filestream s,
const char *  comment 
) [static]

Definition at line 91 of file format_g726.c.

References g726_open(), and RATE_40.

00092 {
00093    return g726_open(s, RATE_40);
00094 }

static int g726_open ( struct ast_filestream tmp,
int  rate 
) [static]

Definition at line 63 of file format_g726.c.

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

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().

00064 {
00065    struct g726_desc *s = (struct g726_desc *)tmp->_private;
00066    s->rate = rate;
00067    ast_debug(1, "Created filestream G.726-%dk.\n", 40 - s->rate * 8);
00068    return 0;
00069 }

static struct ast_frame* g726_read ( struct ast_filestream s,
int *  whennext 
) [static, read]

Definition at line 115 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::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.

00116 {
00117    int res;
00118    struct g726_desc *fs = (struct g726_desc *)s->_private;
00119 
00120    /* Send a frame from the file to the appropriate channel */
00121    s->fr.frametype = AST_FRAME_VOICE;
00122    s->fr.subclass = AST_FORMAT_G726;
00123    s->fr.mallocd = 0;
00124    AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, frame_size[fs->rate]);
00125    s->fr.samples = 8 * FRAME_TIME;
00126    if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
00127       if (res)
00128          ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
00129       return NULL;
00130    }
00131    *whennext = s->fr.samples;
00132    return &s->fr;
00133 }

static int g726_seek ( struct ast_filestream fs,
off_t  sample_offset,
int  whence 
) [static]

Definition at line 162 of file format_g726.c.

00163 {
00164    return -1;
00165 }

static off_t g726_tell ( struct ast_filestream fs  )  [static]

Definition at line 172 of file format_g726.c.

00173 {
00174    return -1;
00175 }

static int g726_trunc ( struct ast_filestream fs  )  [static]

Definition at line 167 of file format_g726.c.

00168 {
00169    return -1;
00170 }

static int g726_write ( struct ast_filestream s,
struct ast_frame f 
) [static]

Definition at line 135 of file format_g726.c.

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

00136 {
00137    int res;
00138    struct g726_desc *fs = (struct g726_desc *)s->_private;
00139 
00140    if (f->frametype != AST_FRAME_VOICE) {
00141       ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
00142       return -1;
00143    }
00144    if (f->subclass != AST_FORMAT_G726) {
00145       ast_log(LOG_WARNING, "Asked to write non-G726 frame (%d)!\n", 
00146                   f->subclass);
00147       return -1;
00148    }
00149    if (f->datalen % frame_size[fs->rate]) {
00150       ast_log(LOG_WARNING, "Invalid data length %d, should be multiple of %d\n", 
00151                   f->datalen, frame_size[fs->rate]);
00152       return -1;
00153    }
00154    if ((res = fwrite(f->data.ptr, 1, f->datalen, s->f)) != f->datalen) {
00155       ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", 
00156             res, frame_size[fs->rate], strerror(errno));
00157          return -1;
00158    }
00159    return 0;
00160 }

static int load_module ( void   )  [static]

Definition at line 237 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.

00238 {
00239    int i;
00240 
00241    for (i = 0; f[i].format ; i++) {
00242       if (ast_format_register(&f[i])) {   /* errors are fatal */
00243          ast_log(LOG_WARNING, "Failed to register format %s.\n", f[i].name);
00244          return AST_MODULE_LOAD_FAILURE;
00245       }
00246    }
00247    return AST_MODULE_LOAD_SUCCESS;
00248 }

static int unload_module ( void   )  [static]

Definition at line 250 of file format_g726.c.

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

00251 {
00252    int i;
00253 
00254    for (i = 0; f[i].format ; i++) {
00255       if (ast_format_unregister(f[i].name))
00256          ast_log(LOG_WARNING, "Failed to unregister format %s.\n", f[i].name);
00257    }
00258    return(0);
00259 }  


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static]

Definition at line 261 of file format_g726.c.

Definition at line 261 of file format_g726.c.

struct ast_format f[] [static]

Definition at line 177 of file format_g726.c.

Referenced by __adsi_transmit_messages(), __ast_play_and_record(), __ast_queue_frame(), __ast_read(), __ast_request_and_dial(), __attempt_transmit(), __dahdi_exception(), agent_ack_sleep(), agent_read(), alloc_profile(), app_exec(), ast_autoservice_stop(), ast_bridge_call(), ast_channel_free(), ast_el_read_history(), ast_feature_request_and_dial(), ast_filehelper(), 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_tonepair(), ast_trans_frameout(), ast_udptl_bridge(), ast_ulaw_init(), ast_waitfordigit_full(), ast_write(), ast_writefile(), async_wait(), auth_exec(), autoservice_run(), builtin_atxfer(), calc_cost(), channel_spy(), check_goto_on_transfer(), close_logger(), compile_script(), conf_exec(), conf_flush(), conf_run(), config_text_file_load(), config_text_file_save(), create_video_frame(), dahdi_bridge(), dahdi_exception(), dahdi_handle_dtmfup(), dahdi_handle_event(), dahdi_read(), dictate_exec(), disa_exec(), do_waiting(), echo_exec(), eivr_comm(), execif_exec(), filestream_destructor(), find_cache(), fn_wrapper(), frame_cache_cleanup(), function_realtime_store(), gen_generate(), gen_readframe(), get_bit_raw(), gtalk_rtp_read(), h261_encap(), h263_encap(), h263p_encap(), h264_encap(), handle_cli_core_show_file_formats(), handle_cli_file_convert(), handle_recordfile(), http_post_callback(), iax2_bridge(), iax2_trunk_queue(), iax_park_thread(), ices_exec(), isAnsweringMachine(), jack_exec(), jb_empty_and_reset_adaptive(), jb_get_and_deliver(), jingle_rtp_read(), key_history(), launch_asyncagi(), lintoadpcm_frameout(), load_file(), lua_read_extensions_file(), main(), manage_parkinglot(), masq_park_call(), measurenoise(), mgcp_read(), mgcp_rtp_read(), misdn_bridge(), misdn_lib_nt_debug_init(), moh_files_generator(), moh_files_readframe(), mp3_exec(), mpeg4_encap(), NBScat_exec(), network_thread(), oh323_rtp_read(), op_func(), oss_read(), parse(), process_ast_dsp(), process_cisco_dtmf(), process_rfc2833(), process_rfc3389(), readdirqueue(), receive_dtmf_digits(), record_exec(), recordthread(), reload_followme(), reload_logger(), remove_from_queue(), rtpread(), run_agi(), safe_append(), scan_service(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), show_history(), sip_rtp_read(), skinny_rtp_read(), sms_handleincoming_proto2(), sms_hexdump(), speech_background(), spy_generate(), ss_thread(), store_rxctcssadj(), store_rxgain(), store_rxvoiceadj(), strip_quotes(), testclient_exec(), testserver_exec(), try_load_key(), udptlread(), unistim_rtp_read(), unload_module(), usbradio_read(), 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 49 of file format_g726.c.


Generated on Wed Oct 28 11:52:25 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6