Sun Dec 18 20:55:50 2011

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 <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <sys/time.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "asterisk/lock.h"
#include "asterisk/options.h"
#include "asterisk/channel.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/sched.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

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Raw G.726 (16/24/32/40kbps) data")
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_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 59 of file format_g726.c.

Referenced by g726_read().

#define RATE_16   3

Definition at line 56 of file format_g726.c.

Referenced by g726_16_open(), and g726_16_rewrite().

#define RATE_24   2

Definition at line 55 of file format_g726.c.

Referenced by g726_24_open(), and g726_24_rewrite().

#define RATE_32   1

Definition at line 54 of file format_g726.c.

Referenced by g726_32_open(), and g726_32_rewrite().

#define RATE_40   0

Definition at line 53 of file format_g726.c.

Referenced by g726_40_open(), and g726_40_rewrite().


Function Documentation

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Raw G.726 (16/24/32/40kbps) data"   
)

static int g726_16_open ( struct ast_filestream s  )  [static]

Definition at line 102 of file format_g726.c.

References g726_open(), and RATE_16.

00103 {
00104    return g726_open(s, RATE_16);
00105 }

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

Definition at line 122 of file format_g726.c.

References g726_open(), and RATE_16.

00123 {
00124    return g726_open(s, RATE_16);
00125 }

static int g726_24_open ( struct ast_filestream s  )  [static]

Definition at line 97 of file format_g726.c.

References g726_open(), and RATE_24.

00098 {
00099    return g726_open(s, RATE_24);
00100 }

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

Definition at line 117 of file format_g726.c.

References g726_open(), and RATE_24.

00118 {
00119    return g726_open(s, RATE_24);
00120 }

static int g726_32_open ( struct ast_filestream s  )  [static]

Definition at line 92 of file format_g726.c.

References g726_open(), and RATE_32.

00093 {
00094    return g726_open(s, RATE_32);
00095 }

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

Definition at line 112 of file format_g726.c.

References g726_open(), and RATE_32.

00113 {
00114    return g726_open(s, RATE_32);
00115 }

static int g726_40_open ( struct ast_filestream s  )  [static]

Definition at line 87 of file format_g726.c.

References g726_open(), and RATE_40.

00088 {
00089    return g726_open(s, RATE_40);
00090 }

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

Definition at line 107 of file format_g726.c.

References g726_open(), and RATE_40.

00108 {
00109    return g726_open(s, RATE_40);
00110 }

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

Definition at line 77 of file format_g726.c.

References ast_filestream::_private, ast_log(), LOG_DEBUG, option_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().

00078 {
00079    struct g726_desc *s = (struct g726_desc *)tmp->_private;
00080    s->rate = rate;
00081    if (option_debug)
00082       ast_log(LOG_DEBUG, "Created filestream G.726-%dk.\n", 
00083             40 - s->rate * 8);
00084    return 0;
00085 }

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

Definition at line 131 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, g726_desc::rate, ast_frame::samples, and ast_frame::subclass.

00132 {
00133    int res;
00134    struct g726_desc *fs = (struct g726_desc *)s->_private;
00135 
00136    /* Send a frame from the file to the appropriate channel */
00137    s->fr.frametype = AST_FRAME_VOICE;
00138    s->fr.subclass = AST_FORMAT_G726;
00139    s->fr.mallocd = 0;
00140    AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, frame_size[fs->rate]);
00141    s->fr.samples = 8 * FRAME_TIME;
00142    if ((res = fread(s->fr.data, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
00143       if (res)
00144          ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
00145       return NULL;
00146    }
00147    *whennext = s->fr.samples;
00148    return &s->fr;
00149 }

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

Definition at line 178 of file format_g726.c.

00179 {
00180    return -1;
00181 }

static off_t g726_tell ( struct ast_filestream fs  )  [static]

Definition at line 188 of file format_g726.c.

00189 {
00190    return -1;
00191 }

static int g726_trunc ( struct ast_filestream fs  )  [static]

Definition at line 183 of file format_g726.c.

00184 {
00185    return -1;
00186 }

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

Definition at line 151 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, g726_desc::rate, and ast_frame::subclass.

00152 {
00153    int res;
00154    struct g726_desc *fs = (struct g726_desc *)s->_private;
00155 
00156    if (f->frametype != AST_FRAME_VOICE) {
00157       ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
00158       return -1;
00159    }
00160    if (f->subclass != AST_FORMAT_G726) {
00161       ast_log(LOG_WARNING, "Asked to write non-G726 frame (%d)!\n", 
00162                   f->subclass);
00163       return -1;
00164    }
00165    if (f->datalen % frame_size[fs->rate]) {
00166       ast_log(LOG_WARNING, "Invalid data length %d, should be multiple of %d\n", 
00167                   f->datalen, frame_size[fs->rate]);
00168       return -1;
00169    }
00170    if ((res = fwrite(f->data, 1, f->datalen, s->f)) != f->datalen) {
00171       ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", 
00172             res, frame_size[fs->rate], strerror(errno));
00173          return -1;
00174    }
00175    return 0;
00176 }

static int load_module ( void   )  [static]

Definition at line 253 of file format_g726.c.

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

00254 {
00255    int i;
00256 
00257    for (i = 0; f[i].format ; i++) {
00258       if (ast_format_register(&f[i])) {   /* errors are fatal */
00259          ast_log(LOG_WARNING, "Failed to register format %s.\n", f[i].name);
00260          return -1;
00261       }
00262    }
00263    return 0;
00264 }

static int unload_module ( void   )  [static]

Definition at line 266 of file format_g726.c.

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

00267 {
00268    int i;
00269 
00270    for (i = 0; f[i].format ; i++) {
00271       if (ast_format_unregister(f[i].name))
00272          ast_log(LOG_WARNING, "Failed to unregister format %s.\n", f[i].name);
00273    }
00274    return(0);
00275 }  


Variable Documentation

struct ast_format f[] [static]

Definition at line 193 of file format_g726.c.

Referenced by __adsi_transmit_messages(), __ast_play_and_record(), __ast_read(), __ast_request_and_dial_uniqueid(), __attempt_transmit(), agent_ack_sleep(), agent_read(), alloc_profile(), app_exec(), ast_autoservice_stop(), ast_bridge_call(), ast_channel_free(), ast_dsp_frame_freed(), ast_el_read_history(), ast_feature_request_and_dial(), ast_filehelper(), ast_frame_header_new(), ast_generic_bridge(), ast_jb_destroy(), ast_masq_autoanswer_login(), ast_masq_hold_call(), ast_masq_park_call(), ast_queue_frame(), ast_read_image(), ast_readfile(), ast_readframe(), 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_translate_frame_freed(), 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(), cli_audio_convert(), cli_audio_convert_deprecated(), close_logger(), compile_script(), conf_exec(), conf_flush(), conf_run(), config_text_file_load(), config_text_file_save(), dictate_exec(), disa_exec(), do_autoanswer_thread(), do_holding_thread(), do_parking_thread(), do_waiting(), echo_exec(), features_read(), find_cache(), fn_wrapper(), frame_cache_cleanup(), gen_generate(), gen_readframe(), get_bit_raw(), gtalk_rtp_read(), handle_invite_replaces(), handle_recordfile(), iax2_bridge(), iax2_trunk_queue(), iax_park_thread(), ices_exec(), isAnsweringMachine(), jb_get_and_deliver(), lintoadpcm_frameout(), main(), measurenoise(), mgcp_read(), mgcp_rtp_read(), misdn_bridge(), misdn_lib_nt_debug_init(), moh_files_generator(), moh_files_readframe(), mp3_exec(), NBScat_exec(), network_thread(), oh323_rtp_read(), oss_read(), parse(), parse_request(), 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_file_formats(), show_file_formats_deprecated(), sip_rtp_read(), skinny_rtp_read(), sms_exec(), sms_nextoutgoing(), speech_background(), spy_generate(), strip_quotes(), testclient_exec(), testserver_exec(), try_load_key(), udptlread(), unload_module(), vnak_retransmit(), wait_for_answer(), wait_for_hangup(), wait_for_winner(), waitforring_exec(), and writefile().

int frame_size[4] [static]

Definition at line 63 of file format_g726.c.


Generated on Sun Dec 18 20:55:50 2011 for Asterisk - the Open Source PBX by  doxygen 1.5.6