Tue Nov 4 13:20:38 2008

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"

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)

Definition at line 61 of file format_g726.c.

Referenced by g729_read(), g729_seek(), g729_tell(), h263_read(), h264_read(), ogg_vorbis_read(), pcm_read(), pcm_seek(), slinear_read(), and vox_read().

#define FRAME_TIME   10

Definition at line 59 of file format_g726.c.

#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(), RATE_16, and s.

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(), RATE_16, and s.

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(), RATE_24, and s.

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(), RATE_24, and s.

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(), RATE_32, and s.

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(), RATE_32, and s.

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(), RATE_40, and s.

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(), RATE_40, and s.

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, 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]

Definition at line 131 of file format_g726.c.

References AST_FORMAT_G726, AST_FRAME_SET_BUFFER, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), errno, LOG_WARNING, g726_desc::rate, and s.

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_FORMAT_G726, AST_FRAME_VOICE, ast_log(), errno, f, LOG_WARNING, g726_desc::rate, and s.

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(), f, 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(), f, 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_format_register(), __ast_play_and_record(), __ast_read(), __ast_request_and_dial(), __ast_smoother_feed(), __attempt_transmit(), __auto_congest(), __oh323_update_info(), __send_command(), __zt_exception(), action_zapdialoffhook(), adpcmtolin_framein(), adpcmtolin_sample(), agent_ack_sleep(), agent_read(), agent_write(), alawtolin_framein(), alawtolin_sample(), alawtoulaw_framein(), alawtoulaw_sample(), alloc_profile(), alsa_call(), alsa_read(), alsa_write(), app_exec(), ast_autoservice_stop(), ast_bridge_call(), ast_channel_free(), ast_closestream(), ast_codec_get_samples(), ast_dsp_frame_freed(), ast_dsp_silence(), ast_el_read_history(), ast_feature_request_and_dial(), ast_filehelper(), ast_frame_adjust_volume(), ast_frame_dump(), ast_frame_header_new(), ast_frdup(), ast_generic_bridge(), ast_jb_destroy(), ast_jb_put(), ast_masq_park_call(), ast_queue_control(), ast_queue_control_data(), ast_queue_frame(), ast_queue_hangup(), ast_read_generator_actions(), ast_read_image(), ast_readfile(), ast_readframe(), ast_recvtext(), ast_rtcp_read(), ast_rtp_raw_write(), ast_rtp_read(), ast_rtp_write(), ast_safe_sleep_conditional(), ast_send_image(), ast_slinfactory_destroy(), ast_slinfactory_feed(), ast_tonepair(), ast_trans_frameout(), ast_translate(), ast_translate_frame_freed(), ast_udptl_bridge(), ast_udptl_write(), ast_ulaw_init(), ast_waitfordigit_full(), ast_write(), ast_writefile(), ast_writestream(), async_wait(), auth_exec(), autoservice_run(), calc_cost(), calc_timestamp(), channel_spy(), check_goto_on_transfer(), cli_audio_convert(), cli_audio_convert_deprecated(), close_logger(), compile_script(), conf_exec(), conf_flush(), conf_queue_dtmf(), conf_run(), config_text_file_load(), config_text_file_save(), console_answer(), console_answer_deprecated(), console_dial(), console_dial_deprecated(), console_flash(), console_flash_deprecated(), console_sendtext(), console_sendtext_deprecated(), decode_frame(), decrypt_frame(), demodulador(), dictate_exec(), disa_exec(), do_atxfer(), do_parking_thread(), do_waiting(), echo_exec(), fakesrc_sample(), features_read(), features_write(), find_cache(), fn_wrapper(), frame_cache_cleanup(), framein(), free_numbers(), g722tolin_framein(), g722tolin_sample(), g723_write(), g726_write(), g726aal2tolin_framein(), g726tog726aal2_framein(), g726tolin_framein(), g726tolin_sample(), g729_write(), gen_generate(), gen_readframe(), gsm_write(), gsmtolin_framein(), gsmtolin_sample(), gtalk_handle_dtmf(), gtalk_rtp_read(), h263_write(), h264_write(), handle_invite_replaces(), handle_keypad_button_message(), handle_recordfile(), handle_request(), handle_request_info(), iax2_bridge(), iax2_queue_frame(), iax2_send(), iax2_trunk_queue(), iax2_write(), iax_frame_wrap(), iax_park_thread(), iax_showframe(), ices_exec(), ilbc_write(), ilbctolin_framein(), ilbctolin_sample(), init_profile(), isAnsweringMachine(), jb_get_and_deliver(), linear_generator(), lintoadpcm_framein(), lintoadpcm_frameout(), lintoadpcm_sample(), lintoalaw_framein(), lintoalaw_sample(), lintog722_framein(), lintog722_sample(), lintog726_framein(), lintog726_sample(), lintog726aal2_framein(), lintogsm_framein(), lintogsm_sample(), lintoilbc_framein(), lintoilbc_sample(), lintolpc10_framein(), lintolpc10_sample(), lintospeex_framein(), lintospeex_sample(), lintoulaw_framein(), lintoulaw_sample(), load_module(), local_digit_begin(), local_digit_end(), local_hangup(), local_indicate(), local_queue_frame(), local_sendhtml(), local_sendtext(), local_write(), lpc10tolin_framein(), lpc10tolin_sample(), main(), measurenoise(), mgcp_queue_control(), mgcp_queue_frame(), mgcp_read(), mgcp_rtp_read(), misdn_bridge(), misdn_lib_nt_debug_init(), moh_files_generator(), moh_files_readframe(), mp3_exec(), NBScat_exec(), network_thread(), ogg_vorbis_write(), oh323_rtp_read(), oh323_simulate_dtmf_end(), oss_call(), oss_read(), oss_write(), parse(), parse_request(), pcm_write(), process_ast_dsp(), process_cisco_dtmf(), process_rfc2833(), process_rfc3389(), profile_set_param(), readdirqueue(), receive_digit(), receive_dtmf_digits(), receive_message(), record_exec(), recordthread(), reload_followme(), reload_logger(), remove_from_queue(), rpt(), rpt_exec(), rtpread(), run_agi(), safe_append(), scan_service(), send_apathetic_reply(), send_packet(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), show_file_formats(), show_file_formats_deprecated(), sip_new(), sip_rtp_read(), skinny_rtp_read(), slinear_write(), sms_exec(), sms_generate(), sms_nextoutgoing(), socket_process(), speech_background(), speextolin_framein(), speextolin_sample(), spy_generate(), ss_thread(), strip_quotes(), testclient_exec(), testserver_exec(), transmit_trunk(), try_load_key(), udptlread(), ulawtoalaw_framein(), ulawtoalaw_sample(), ulawtolin_framein(), ulawtolin_sample(), unload_module(), update_packet(), vnak_retransmit(), vox_write(), wait_for_answer(), wait_for_hangup(), wait_for_winner(), waitforring_exec(), wav_write(), writefile(), zap_framein(), zap_queue_frame(), zt_bridge(), zt_exception(), zt_handle_dtmfup(), zt_handle_event(), and zt_read().

int frame_size[4] [static]

Definition at line 63 of file format_g726.c.


Generated on Tue Nov 4 13:20:38 2008 for Asterisk - the Open Source PBX by  doxygen 1.4.7