Mon Mar 20 08:25:59 2006

Asterisk developer's documentation


Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

frame.h File Reference

Asterisk internal frame definitions. More...

#include <sys/types.h>
#include <sys/time.h>
#include "asterisk/endian.h"

Go to the source code of this file.

Data Structures

struct  ast_codec_pref
struct  ast_frame
 Data structure associated with a single frame of data. More...
struct  ast_option_header

Defines

#define AST_CONTROL_ANSWER   4
#define AST_CONTROL_BUSY   5
#define AST_CONTROL_CONGESTION   8
#define AST_CONTROL_FLASH   9
#define AST_CONTROL_HANGUP   1
#define AST_CONTROL_HOLD   16
#define AST_CONTROL_OFFHOOK   7
#define AST_CONTROL_OPTION   11
#define AST_CONTROL_PROCEEDING   15
#define AST_CONTROL_PROGRESS   14
#define AST_CONTROL_RADIO_KEY   12
#define AST_CONTROL_RADIO_UNKEY   13
#define AST_CONTROL_RING   2
#define AST_CONTROL_RINGING   3
#define AST_CONTROL_TAKEOFFHOOK   6
#define AST_CONTROL_UNHOLD   17
#define AST_CONTROL_VIDUPDATE   18
#define AST_CONTROL_WINK   10
#define AST_FORMAT_ADPCM   (1 << 5)
#define AST_FORMAT_ALAW   (1 << 3)
#define AST_FORMAT_G723_1   (1 << 0)
#define AST_FORMAT_G726   (1 << 4)
#define AST_FORMAT_G729A   (1 << 8)
#define AST_FORMAT_GSM   (1 << 1)
#define AST_FORMAT_H261   (1 << 18)
#define AST_FORMAT_H263   (1 << 19)
#define AST_FORMAT_H263_PLUS   (1 << 20)
#define AST_FORMAT_ILBC   (1 << 10)
#define AST_FORMAT_JPEG   (1 << 16)
#define AST_FORMAT_LPC10   (1 << 7)
#define AST_FORMAT_MAX_AUDIO   (1 << 15)
#define AST_FORMAT_MAX_VIDEO   (1 << 24)
#define AST_FORMAT_PNG   (1 << 17)
#define AST_FORMAT_SLINEAR   (1 << 6)
#define AST_FORMAT_SPEEX   (1 << 9)
#define AST_FORMAT_ULAW   (1 << 2)
#define ast_frame_byteswap_be(fr)   do { struct ast_frame *__f = (fr); ast_swapcopy_samples(__f->data, __f->data, __f->samples); } while(0)
#define ast_frame_byteswap_le(fr)   do { ; } while(0)
#define AST_FRAME_CNG   10
#define AST_FRAME_CONTROL   4
#define AST_FRAME_DTMF   1
#define AST_FRAME_HTML   9
#define AST_FRAME_IAX   6
#define AST_FRAME_IMAGE   8
#define AST_FRAME_NULL   5
#define AST_FRAME_T38   11
#define AST_FRAME_TEXT   7
#define AST_FRAME_VIDEO   3
#define AST_FRAME_VOICE   2
#define AST_FRIENDLY_OFFSET   64
#define AST_HTML_BEGIN   4
#define AST_HTML_DATA   2
#define AST_HTML_END   8
#define AST_HTML_LDCOMPLETE   16
#define AST_HTML_LINKREJECT   20
#define AST_HTML_LINKURL   18
#define AST_HTML_NOSUPPORT   17
#define AST_HTML_UNLINK   19
#define AST_HTML_URL   1
#define AST_MALLOCD_DATA   (1 << 1)
#define AST_MALLOCD_HDR   (1 << 0)
#define AST_MALLOCD_SRC   (1 << 2)
#define AST_MIN_OFFSET   32
#define AST_OPTION_AUDIO_MODE   4
#define AST_OPTION_FLAG_ACCEPT   1
#define AST_OPTION_FLAG_ANSWER   5
#define AST_OPTION_FLAG_QUERY   4
#define AST_OPTION_FLAG_REJECT   2
#define AST_OPTION_FLAG_REQUEST   0
#define AST_OPTION_FLAG_WTF   6
#define AST_OPTION_RELAXDTMF   3
#define AST_OPTION_RXGAIN   6
#define AST_OPTION_TDD   2
#define AST_OPTION_TONE_VERIFY   1
#define AST_OPTION_TXGAIN   5
#define ast_smoother_feed(s, f)   __ast_smoother_feed(s, f, 0)
#define ast_smoother_feed_be(s, f)   __ast_smoother_feed(s, f, 1)
#define ast_smoother_feed_le(s, f)   __ast_smoother_feed(s, f, 0)
#define AST_SMOOTHER_FLAG_G729   (1 << 0)

Functions

int __ast_smoother_feed (struct ast_smoother *s, struct ast_frame *f, int swap)
char * ast_codec2str (int codec)
 Get a name from a format Gets a name from a format.
int ast_codec_choose (struct ast_codec_pref *pref, int formats, int find_best)
 Select the best format according to preference list from supplied options. If "find_best" is non-zero then if nothing is found, the "Best" format of the format list is selected, otherwise 0 is returned.
int ast_codec_get_len (int format, int samples)
 Returns the number of bytes for the number of samples of the given format.
int ast_codec_get_samples (struct ast_frame *f)
 Returns the number of samples contained in the frame.
int ast_codec_interp_len (int format)
 Gets duration in ms of interpolation frame for a format.
int ast_codec_pref_append (struct ast_codec_pref *pref, int format)
 Append a codec to a preference list, removing it first if it was already there.
void ast_codec_pref_convert (struct ast_codec_pref *pref, char *buf, size_t size, int right)
 Shift a codec preference list up or down 65 bytes so that it becomes an ASCII string.
int ast_codec_pref_index (struct ast_codec_pref *pref, int index)
 Codec located at a particular place in the preference index.
void ast_codec_pref_init (struct ast_codec_pref *pref)
 Initialize a codec preference to "no preference".
void ast_codec_pref_remove (struct ast_codec_pref *pref, int format)
 Remove a codec from a preference list.
int ast_codec_pref_string (struct ast_codec_pref *pref, char *buf, size_t size)
 Dump codec preference list into a string.
int ast_fr_fdhangup (int fd)
 Sends a hangup to an fd Send a hangup (NULL equivalent) on an fd.
ast_frameast_fr_fdread (int fd)
 Reads a frame from an fd Read a frame from a stream or packet fd, as written by fd_write.
int ast_fr_fdwrite (int fd, struct ast_frame *frame)
int ast_frame_adjust_volume (struct ast_frame *f, int adjustment)
 Adjusts the volume of the audio samples contained in a frame.
void ast_frame_dump (char *name, struct ast_frame *f, char *prefix)
int ast_frame_slinear_sum (struct ast_frame *f1, struct ast_frame *f2)
 Sums two frames of audio samples.
ast_frameast_frdup (struct ast_frame *fr)
 Copies a frame.
void ast_frfree (struct ast_frame *fr)
 Requests a frame to be allocated Frees a frame.
ast_frameast_frisolate (struct ast_frame *fr)
 Copies a frame.
ast_format_listast_get_format_list (size_t *size)
ast_format_listast_get_format_list_index (int index)
int ast_getformatbyname (char *name)
 Gets a format from a name.
char * ast_getformatname (int format)
 Get the name of a format.
char * ast_getformatname_multiple (char *buf, size_t size, int format)
 Get the names of a set of formats.
void ast_parse_allow_disallow (struct ast_codec_pref *pref, int *mask, const char *list, int allowing)
 Parse an "allow" or "deny" line and update the mask and pref if provided.
void ast_smoother_free (struct ast_smoother *s)
int ast_smoother_get_flags (struct ast_smoother *smoother)
ast_smootherast_smoother_new (int bytes)
ast_frameast_smoother_read (struct ast_smoother *s)
void ast_smoother_reset (struct ast_smoother *s, int bytes)
void ast_smoother_set_flags (struct ast_smoother *smoother, int flags)
void ast_swapcopy_samples (void *dst, const void *src, int samples)


Detailed Description

Asterisk internal frame definitions.

Definition in file frame.h.


Define Documentation

#define AST_CONTROL_ANSWER   4
 

Remote end has answered

Definition at line 217 of file frame.h.

Referenced by agent_read(), ast_dsp_process(), ast_frame_dump(), ast_pickup_call(), ast_waitfordigit_full(), ast_waitstream(), ast_waitstream_exten(), ast_waitstream_fr(), ast_waitstream_full(), cb_events(), connection_made(), console_answer(), control2str(), handle_hd_hf(), handle_message(), handle_response_invite(), iax2_answer(), local_answer(), misdn_indication(), nbs_call(), oss_answer(), pickup_exec(), vpb_indicate(), and wait_for_answer().

#define AST_CONTROL_BUSY   5
 

Remote end is busy

Definition at line 219 of file frame.h.

Referenced by alsa_indicate(), ast_dsp_process(), ast_frame_dump(), ast_indicate(), builtin_atxfer(), control2str(), handle_response(), mgcp_indicate(), misdn_indication(), monitor_handle_owned(), oh323_indicate(), oss_indicate(), pbx_builtin_busy(), rpt_exec(), send_cause2ast(), sip_indicate(), skinny_call(), skinny_indicate(), vpb_indicate(), wait_for_answer(), and zt_indicate().

#define AST_CONTROL_CONGESTION   8
 

Congestion (circuits busy)

Definition at line 225 of file frame.h.

Referenced by alsa_indicate(), ast_dsp_process(), ast_frame_dump(), ast_indicate(), auto_congest(), control2str(), disa_exec(), handle_response(), handle_response_invite(), mgcp_indicate(), misdn_indication(), monitor_handle_owned(), nbs_call(), oh323_indicate(), oss_hangup(), oss_indicate(), pbx_builtin_congestion(), send_cause2ast(), sip_indicate(), skinny_indicate(), vpb_indicate(), wait_for_answer(), and zt_indicate().

#define AST_CONTROL_FLASH   9
 

Flash hook

Definition at line 227 of file frame.h.

Referenced by ast_bridge_call(), ast_frame_dump(), console_flash(), control2str(), misdn_indication(), wait_for_answer(), and zt_indicate().

#define AST_CONTROL_HANGUP   1
 

Other end has hungup

Definition at line 211 of file frame.h.

Referenced by ast_dsp_process(), ast_frame_dump(), ast_queue_hangup(), ast_waitfordigit_full(), ast_waitstream(), ast_waitstream_exten(), ast_waitstream_fr(), ast_waitstream_full(), control2str(), local_hangup(), monitor_handle_owned(), and vpb_indicate().

#define AST_CONTROL_HOLD   16
 

Indicate call is placed on hold

Definition at line 241 of file frame.h.

Referenced by ast_park_call(), builtin_atxfer(), builtin_blindtransfer(), control2str(), misdn_indication(), sip_indicate(), wait_for_answer(), and zt_indicate().

#define AST_CONTROL_OFFHOOK   7
 

Line is off hook

Definition at line 223 of file frame.h.

Referenced by ast_frame_dump(), control2str(), misdn_indication(), and wait_for_answer().

#define AST_CONTROL_OPTION   11
 

Set a low-level option

Definition at line 231 of file frame.h.

Referenced by ast_frame_dump(), control2str(), and iax2_setoption().

#define AST_CONTROL_PROCEEDING   15
 

Indicate CALL PROCEEDING

Definition at line 239 of file frame.h.

Referenced by control2str(), oh323_indicate(), sip_indicate(), skinny_indicate(), wait_for_answer(), and zt_indicate().

#define AST_CONTROL_PROGRESS   14
 

Indicate PROGRESS

Definition at line 237 of file frame.h.

Referenced by cb_events(), control2str(), handle_response(), handle_response_invite(), misdn_indication(), oh323_indicate(), pbx_builtin_progress(), progress(), setup_rtp_connection(), sip_indicate(), skinny_indicate(), socket_read(), wait_for_answer(), and zt_indicate().

#define AST_CONTROL_RADIO_KEY   12
 

Key Radio

Definition at line 233 of file frame.h.

Referenced by ast_frame_dump(), control2str(), function_remote(), handle_remote_data(), handle_remote_phone_dtmf(), rmt_telem_start(), rpt(), rpt_exec(), and zt_indicate().

#define AST_CONTROL_RADIO_UNKEY   13
 

Un-Key Radio

Definition at line 235 of file frame.h.

Referenced by ast_frame_dump(), control2str(), function_remote(), handle_remote_data(), handle_remote_phone_dtmf(), rmt_telem_finish(), rmt_telem_start(), rpt(), rpt_exec(), and zt_indicate().

#define AST_CONTROL_RING   2
 

Local ring

Definition at line 213 of file frame.h.

Referenced by ast_frame_dump(), control2str(), misdn_indication(), and oss_call().

#define AST_CONTROL_RINGING   3
 

Remote end is ringing

Definition at line 215 of file frame.h.

Referenced by alsa_indicate(), ast_bridge_call(), ast_dsp_process(), ast_feature_request_and_dial(), ast_frame_dump(), ast_indicate(), ast_waitfordigit_full(), ast_waitstream(), ast_waitstream_exten(), ast_waitstream_fr(), ast_waitstream_full(), attempt_transfer(), cb_events(), chan_ringing(), control2str(), dial_exec_full(), handle_response_invite(), mgcp_call(), mgcp_indicate(), misdn_indication(), oh323_indicate(), oss_indicate(), pbx_builtin_ringing(), phone_call(), progress(), queue_exec(), sip_indicate(), skinny_call(), skinny_indicate(), vpb_call(), vpb_fixup(), vpb_indicate(), wait_for_answer(), zt_fixup(), and zt_indicate().

#define AST_CONTROL_TAKEOFFHOOK   6
 

Make it go off hook

Definition at line 221 of file frame.h.

Referenced by ast_frame_dump(), control2str(), and misdn_indication().

#define AST_CONTROL_UNHOLD   17
 

Indicate call is left from hold

Definition at line 243 of file frame.h.

Referenced by builtin_atxfer(), builtin_blindtransfer(), control2str(), do_parking_thread(), misdn_indication(), park_exec(), sip_indicate(), wait_for_answer(), and zt_indicate().

#define AST_CONTROL_VIDUPDATE   18
 

Indicate video frame update

Definition at line 245 of file frame.h.

Referenced by alsa_indicate(), ast_play_and_record(), ast_waitstream(), handle_request_info(), oss_indicate(), record_exec(), sip_indicate(), and wait_for_answer().

#define AST_CONTROL_WINK   10
 

Wink

Definition at line 229 of file frame.h.

Referenced by ast_frame_dump(), and control2str().

#define AST_FORMAT_ADPCM   (1 << 5)
 

ADPCM (IMA)

Definition at line 183 of file frame.h.

Referenced by ast2vpbformat(), ast2vpbformatname(), ast_codec_get_len(), ast_codec_get_samples(), ast_rtp_write(), astformatbits(), convertcap(), and load_module().

#define AST_FORMAT_ALAW   (1 << 3)
 

Raw A-law data (G.711)

Definition at line 179 of file frame.h.

Referenced by ast2vpbformat(), ast2vpbformatname(), ast_codec_get_len(), ast_codec_get_samples(), ast_dsp_process(), ast_rtp_write(), astformatbits(), cb_events(), convertcap(), load_module(), misdn_set_opt_exec(), and sms_exec().

#define AST_FORMAT_G723_1   (1 << 0)
 

G.723.1 compression

Definition at line 173 of file frame.h.

Referenced by ast_codec_get_samples(), ast_rtp_write(), convertcap(), load_module(), phone_request(), and phone_write().

#define AST_FORMAT_G726   (1 << 4)
 

ADPCM (G.726, 32kbps)

Definition at line 181 of file frame.h.

Referenced by ast_codec_get_len(), ast_codec_get_samples(), ast_rtp_write(), and load_module().

#define AST_FORMAT_G729A   (1 << 8)
 

G.729A audio

Definition at line 189 of file frame.h.

Referenced by ast_codec_get_len(), ast_codec_get_samples(), ast_rtp_write(), convertcap(), and load_module().

#define AST_FORMAT_GSM   (1 << 1)
 

GSM compression

Definition at line 175 of file frame.h.

Referenced by ast_codec_get_len(), ast_codec_get_samples(), ast_rtp_write(), convertcap(), and load_module().

#define AST_FORMAT_H261   (1 << 18)
 

H.261 Video

Definition at line 201 of file frame.h.

Referenced by ast_rtp_write().

#define AST_FORMAT_H263   (1 << 19)
 

H.263 Video

Definition at line 203 of file frame.h.

Referenced by ast_rtp_write(), and load_module().

#define AST_FORMAT_H263_PLUS   (1 << 20)
 

H.263+ Video

Definition at line 205 of file frame.h.

Referenced by ast_rtp_write().

#define AST_FORMAT_ILBC   (1 << 10)
 

iLBC Free Compression

Definition at line 193 of file frame.h.

Referenced by ast_codec_get_len(), ast_codec_get_samples(), ast_rtp_write(), convertcap(), and load_module().

#define AST_FORMAT_JPEG   (1 << 16)
 

JPEG Images

Definition at line 197 of file frame.h.

#define AST_FORMAT_LPC10   (1 << 7)
 

LPC10, 180 samples/frame

Definition at line 187 of file frame.h.

Referenced by ast_codec_get_samples(), and ast_rtp_write().

#define AST_FORMAT_MAX_AUDIO   (1 << 15)
 

Maximum audio format

Definition at line 195 of file frame.h.

Referenced by oh323_request(), phone_read(), and sip_request_call().

#define AST_FORMAT_MAX_VIDEO   (1 << 24)
 

Maximum video format

Definition at line 207 of file frame.h.

Referenced by add_sdp().

#define AST_FORMAT_PNG   (1 << 17)
 

PNG Images

Definition at line 199 of file frame.h.

Referenced by phone_read().

#define AST_FORMAT_SLINEAR   (1 << 6)
 

Raw 16-bit Signed Linear (8000 Hz) PCM

Definition at line 185 of file frame.h.

Referenced by action_originate(), ast2vpbformat(), ast2vpbformatname(), ast_app_getvoice(), ast_channel_start_silence_generator(), ast_codec_get_len(), ast_codec_get_samples(), ast_dsp_process(), ast_moh_files_next(), ast_play_and_prepend(), ast_play_and_record(), ast_rtp_write(), ast_slinfactory_feed(), astformatbits(), attempt_reconnect(), attempt_thread(), background_detect_exec(), chanspy_exec(), conf_run(), dictate_exec(), do_waiting(), eagi_exec(), fast_originate(), function_ilink(), handle_recordfile(), ices_exec(), linear_alloc(), load_module(), measurenoise(), misdn_set_opt_exec(), moh_files_alloc(), mp3_exec(), NBScat_exec(), page_thread(), parkandannounce_exec(), phone_request(), phone_write(), playtones_alloc(), queue_frame_to_spies(), record_exec(), rpt(), rpt_call(), rpt_exec(), rpt_tele_thread(), send_waveform_to_channel(), sms_exec(), tonepair_alloc(), zt_new(), and zt_request().

#define AST_FORMAT_SPEEX   (1 << 9)
 

SpeeX Free Compression

Definition at line 191 of file frame.h.

Referenced by ast_codec_get_samples(), ast_rtp_write(), and convertcap().

#define AST_FORMAT_ULAW   (1 << 2)
 

Raw mu-law data (G.711)

Definition at line 177 of file frame.h.

Referenced by __adsi_transmit_messages(), adsi_transmit_message_full(), alarmreceiver_exec(), ast2vpbformat(), ast2vpbformatname(), ast_codec_get_len(), ast_codec_get_samples(), ast_dsp_process(), ast_rtp_write(), astformatbits(), build_conf(), conf_run(), convertcap(), disa_exec(), get_callerid_ast(), load_module(), and milliwatt_exec().

#define ast_frame_byteswap_be fr   )     do { struct ast_frame *__f = (fr); ast_swapcopy_samples(__f->data, __f->data, __f->samples); } while(0)
 

Definition at line 364 of file frame.h.

Referenced by ast_rtp_read(), and socket_read().

#define ast_frame_byteswap_le fr   )     do { ; } while(0)
 

Definition at line 363 of file frame.h.

Referenced by phone_read().

#define AST_FRAME_CNG   10
 

Comfort Noise frame (subclass is level of CNG in -dBov), body may include zero or more 8-bit quantization coefficients

Definition at line 147 of file frame.h.

#define AST_FRAME_CONTROL   4
 

A control frame, subclass is AST_CONTROL_*

Definition at line 134 of file frame.h.

Referenced by agent_read(), alsa_call(), ast_feature_request_and_dial(), ast_frame_dump(), ast_recvtext(), ast_waitfordigit_full(), ast_waitstream(), ast_waitstream_exten(), ast_waitstream_fr(), ast_waitstream_full(), ast_write(), iax2_answer(), iax2_indicate(), iax2_setoption(), monitor_handle_owned(), and socket_read().

#define AST_FRAME_DTMF   1
 

A DTMF digit, subclass is the digit

Definition at line 128 of file frame.h.

Referenced by agent_read(), ast_feature_request_and_dial(), ast_frame_dump(), ast_waitfordigit_full(), ast_waitstream(), ast_waitstream_exten(), ast_waitstream_fr(), ast_waitstream_full(), ast_write(), console_dial(), handle_recordfile(), iax2_digit(), and monitor_handle_owned().

#define AST_FRAME_HTML   9
 

HTML Frame

Definition at line 144 of file frame.h.

Referenced by ast_frame_dump(), ast_write(), and iax2_sendhtml().

#define AST_FRAME_IAX   6
 

Inter Asterisk Exchange private frame type

Definition at line 138 of file frame.h.

Referenced by ast_frame_dump(), attempt_transmit(), auth_reject(), authenticate_reply(), authenticate_request(), auto_hangup(), cache_get_callno_locked(), dp_lookup(), iax2_call(), iax2_do_register(), iax2_dprequest(), iax2_hangup(), iax2_poke_peer(), iax2_provision(), iax2_start_transfer(), iax2_transfer(), iax2_vnak(), registry_authrequest(), registry_rerequest(), send_lagrq(), send_ping(), socket_read(), try_transfer(), and update_registry().

#define AST_FRAME_IMAGE   8
 

Image Frames

Definition at line 142 of file frame.h.

Referenced by ast_frame_dump(), iax2_sendimage(), phone_read(), and sip_write().

#define AST_FRAME_NULL   5
 

An empty, useless frame

Definition at line 136 of file frame.h.

Referenced by agent_new(), ast_frame_dump(), ast_softhangup_nolock(), and vpb_read().

#define AST_FRAME_T38   11
 

T.38 Fax-over-IP data stream

Definition at line 149 of file frame.h.

#define AST_FRAME_TEXT   7
 

Text messages

Definition at line 140 of file frame.h.

Referenced by ast_frame_dump(), ast_write(), and iax2_sendtext().

#define AST_FRAME_VIDEO   3
 

Video frame, maybe?? :)

Definition at line 132 of file frame.h.

Referenced by ast_write(), and sip_write().

#define AST_FRAME_VOICE   2
 

Voice data, subclass is AST_FORMAT_*

Definition at line 130 of file frame.h.

Referenced by agent_read(), ast_prod(), ast_waitfordigit_full(), ast_waitstream_full(), ast_write(), handle_recordfile(), iax2_send(), phone_read(), phone_write(), schedule_delivery(), and sip_write().

#define AST_FRIENDLY_OFFSET   64
 

Definition at line 114 of file frame.h.

Referenced by alsa_read(), ast_frdup(), ast_frisolate(), ast_rtp_read(), g723_read(), linear_generator(), milliwatt_generate(), moh_generate(), oss_read(), and zt_read().

#define AST_HTML_BEGIN   4
 

Beginning frame

Definition at line 157 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_DATA   2
 

Data frame

Definition at line 155 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_END   8
 

End frame

Definition at line 159 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_LDCOMPLETE   16
 

Load is complete

Definition at line 161 of file frame.h.

Referenced by ast_frame_dump(), and sendurl_exec().

#define AST_HTML_LINKREJECT   20
 

Reject link request

Definition at line 169 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_LINKURL   18
 

Send URL, and track

Definition at line 165 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_NOSUPPORT   17
 

Peer is unable to support HTML

Definition at line 163 of file frame.h.

Referenced by ast_frame_dump(), and sendurl_exec().

#define AST_HTML_UNLINK   19
 

No more HTML linkage

Definition at line 167 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_URL   1
 

Sending a URL

Definition at line 153 of file frame.h.

Referenced by ast_channel_sendurl(), and ast_frame_dump().

#define AST_MALLOCD_DATA   (1 << 1)
 

Need the data be free'd?

Definition at line 122 of file frame.h.

#define AST_MALLOCD_HDR   (1 << 0)
 

Need the header be free'd?

Definition at line 120 of file frame.h.

Referenced by ast_frisolate().

#define AST_MALLOCD_SRC   (1 << 2)
 

Need the source be free'd? (haha!)

Definition at line 124 of file frame.h.

Referenced by ast_frisolate().

#define AST_MIN_OFFSET   32
 

Definition at line 117 of file frame.h.

#define AST_OPTION_AUDIO_MODE   4
 

Set (or clear) Audio (Not-Clear) Mode

Definition at line 268 of file frame.h.

Referenced by zt_hangup(), and zt_setoption().

#define AST_OPTION_FLAG_ACCEPT   1
 

Definition at line 251 of file frame.h.

#define AST_OPTION_FLAG_ANSWER   5
 

Definition at line 254 of file frame.h.

#define AST_OPTION_FLAG_QUERY   4
 

Definition at line 253 of file frame.h.

#define AST_OPTION_FLAG_REJECT   2
 

Definition at line 252 of file frame.h.

#define AST_OPTION_FLAG_REQUEST   0
 

Definition at line 250 of file frame.h.

#define AST_OPTION_FLAG_WTF   6
 

Definition at line 255 of file frame.h.

#define AST_OPTION_RELAXDTMF   3
 

Relax the parameters for DTMF reception (mainly for radio use)

Definition at line 265 of file frame.h.

Referenced by rpt(), and zt_setoption().

#define AST_OPTION_RXGAIN   6
 

Set channel receive gain Option data is a single signed char representing number of decibels (dB) to set gain to (on top of any gain specified in channel driver)

Definition at line 284 of file frame.h.

Referenced by iax2_setoption(), play_record_review(), reset_volumes(), set_talk_volume(), vm_forwardoptions(), and zt_setoption().

#define AST_OPTION_TDD   2
 

Put a compatible channel into TDD (TTY for the hearing-impared) mode

Definition at line 262 of file frame.h.

Referenced by handle_tddmode(), zt_hangup(), and zt_setoption().

#define AST_OPTION_TONE_VERIFY   1
 

Verify touchtones by muting audio transmission (and reception) and verify the tone is still present

Definition at line 259 of file frame.h.

Referenced by conf_run(), rpt(), try_calling(), zt_hangup(), and zt_setoption().

#define AST_OPTION_TXGAIN   5
 

Set channel transmit gain Option data is a single signed char representing number of decibels (dB) to set gain to (on top of any gain specified in channel driver)

Definition at line 276 of file frame.h.

Referenced by chanspy_exec(), iax2_setoption(), reset_volumes(), set_listen_volume(), set_volume(), and zt_setoption().

#define ast_smoother_feed s,
 )     __ast_smoother_feed(s, f, 0)
 

Definition at line 412 of file frame.h.

Referenced by ast_rtp_write().

#define ast_smoother_feed_be s,
 )     __ast_smoother_feed(s, f, 1)
 

Definition at line 414 of file frame.h.

Referenced by ast_rtp_write().

#define ast_smoother_feed_le s,
 )     __ast_smoother_feed(s, f, 0)
 

Definition at line 415 of file frame.h.

#define AST_SMOOTHER_FLAG_G729   (1 << 0)
 

Definition at line 247 of file frame.h.

Referenced by ast_rtp_write().


Function Documentation

int __ast_smoother_feed struct ast_smoother s,
struct ast_frame f,
int  swap
 

Definition at line 137 of file frame.c.

References ast_log(), ast_swapcopy_samples(), ast_frame::data, ast_smoother::data, ast_frame::datalen, ast_smoother::delivery, ast_frame::delivery, ast_smoother::flags, ast_smoother::format, ast_frame::frametype, ast_smoother::len, LOG_NOTICE, LOG_WARNING, ast_frame::offset, ast_smoother::opt, ast_smoother::optimizablestream, s, ast_frame::samples, ast_smoother::samplesperbyte, ast_smoother::size, and ast_frame::subclass.

00138 {
00139    if (f->frametype != AST_FRAME_VOICE) {
00140       ast_log(LOG_WARNING, "Huh?  Can't smooth a non-voice frame!\n");
00141       return -1;
00142    }
00143    if (!s->format) {
00144       s->format = f->subclass;
00145       s->samplesperbyte = (float)f->samples / (float)f->datalen;
00146    } else if (s->format != f->subclass) {
00147       ast_log(LOG_WARNING, "Smoother was working on %d format frames, now trying to feed %d?\n", s->format, f->subclass);
00148       return -1;
00149    }
00150    if (s->len + f->datalen > SMOOTHER_SIZE) {
00151       ast_log(LOG_WARNING, "Out of smoother space\n");
00152       return -1;
00153    }
00154    if (((f->datalen == s->size) || ((f->datalen < 10) && (s->flags & AST_SMOOTHER_FLAG_G729)))
00155              && !s->opt && (f->offset >= AST_MIN_OFFSET)) {
00156       if (!s->len) {
00157          /* Optimize by sending the frame we just got
00158             on the next read, thus eliminating the douple
00159             copy */
00160          s->opt = f;
00161          return 0;
00162       } else {
00163          s->optimizablestream++;
00164          if (s->optimizablestream > 10) {
00165             /* For the past 10 rounds, we have input and output
00166                frames of the correct size for this smoother, yet
00167                we were unable to optimize because there was still
00168                some cruft left over.  Lets just drop the cruft so
00169                we can move to a fully optimized path */
00170             s->len = 0;
00171             s->opt = f;
00172             return 0;
00173          }
00174       }
00175    } else 
00176       s->optimizablestream = 0;
00177    if (s->flags & AST_SMOOTHER_FLAG_G729) {
00178       if (s->len % 10) {
00179          ast_log(LOG_NOTICE, "Dropping extra frame of G.729 since we already have a VAD frame at the end\n");
00180          return 0;
00181       }
00182    }
00183    if (swap)
00184       ast_swapcopy_samples(s->data+s->len, f->data, f->samples);
00185    else
00186       memcpy(s->data + s->len, f->data, f->datalen);
00187    /* If either side is empty, reset the delivery time */
00188    if (!s->len || ast_tvzero(f->delivery) || ast_tvzero(s->delivery))   /* XXX really ? */
00189       s->delivery = f->delivery;
00190    s->len += f->datalen;
00191    return 0;
00192 }

char* ast_codec2str int  codec  ) 
 

Get a name from a format Gets a name from a format.

Parameters:
codec codec number (1,2,4,8,16,etc.)
Returns:
This returns a static string identifying the format on success, 0 on error.

Definition at line 570 of file frame.c.

References AST_FORMAT_LIST, ast_format_list::bits, ast_format_list::desc, and ast_format_list::visible.

Referenced by moh_alloc(), show_codec_n(), and show_codecs().

00570                                {
00571    int x = 0;
00572    char *ret = "unknown";
00573    for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
00574       if(AST_FORMAT_LIST[x].visible && AST_FORMAT_LIST[x].bits == codec) {
00575          ret = AST_FORMAT_LIST[x].desc;
00576          break;
00577       }
00578    }
00579    return ret;
00580 }

int ast_codec_choose struct ast_codec_pref pref,
int  formats,
int  find_best
 

Select the best format according to preference list from supplied options. If "find_best" is non-zero then if nothing is found, the "Best" format of the format list is selected, otherwise 0 is returned.

Definition at line 984 of file frame.c.

References ast_best_codec(), AST_FORMAT_LIST, ast_format_list::bits, and ast_codec_pref::order.

Referenced by process_sdp(), sip_new(), and socket_read().

00985 {
00986    size_t size = 0;
00987    int x = 0, ret = 0, slot = 0;
00988 
00989    size = sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list);
00990    for (x = 0; x < size; x++) {
00991       slot = pref->order[x];
00992 
00993       if(!slot)
00994          break;
00995       if ( formats & AST_FORMAT_LIST[slot-1].bits ) {
00996          ret = AST_FORMAT_LIST[slot-1].bits;
00997          break;
00998       }
00999    }
01000    if(ret)
01001       return ret;
01002 
01003       return find_best ? ast_best_codec(formats) : 0;
01004 }

int ast_codec_get_len int  format,
int  samples
 

Returns the number of bytes for the number of samples of the given format.

Definition at line 1225 of file frame.c.

References AST_FORMAT_ADPCM, AST_FORMAT_ALAW, AST_FORMAT_G726, AST_FORMAT_G729A, AST_FORMAT_GSM, AST_FORMAT_ILBC, AST_FORMAT_SLINEAR, AST_FORMAT_ULAW, ast_getformatname(), ast_log(), and LOG_WARNING.

Referenced by ast_channel_spy_read_frame(), copy_data_from_queue(), moh_generate(), and monmp3thread().

01226 {
01227    int len = 0;
01228 
01229    /* XXX Still need speex, g723, and lpc10 XXX */ 
01230    switch(format) {
01231    case AST_FORMAT_ILBC:
01232       len = (samples / 240) * 50;
01233       break;
01234    case AST_FORMAT_GSM:
01235       len = (samples / 160) * 33;
01236       break;
01237    case AST_FORMAT_G729A:
01238       len = samples / 8;
01239       break;
01240    case AST_FORMAT_SLINEAR:
01241       len = samples * 2;
01242       break;
01243    case AST_FORMAT_ULAW:
01244    case AST_FORMAT_ALAW:
01245       len = samples;
01246       break;
01247    case AST_FORMAT_ADPCM:
01248    case AST_FORMAT_G726:
01249       len = samples / 2;
01250       break;
01251    default:
01252       ast_log(LOG_WARNING, "Unable to calculate sample length for format %s\n", ast_getformatname(format));
01253    }
01254 
01255    return len;
01256 }

int ast_codec_get_samples struct ast_frame f  ) 
 

Returns the number of samples contained in the frame.

Definition at line 1184 of file frame.c.

References AST_FORMAT_ADPCM, AST_FORMAT_ALAW, AST_FORMAT_G723_1, AST_FORMAT_G726, AST_FORMAT_G729A, AST_FORMAT_GSM, AST_FORMAT_ILBC, AST_FORMAT_LPC10, AST_FORMAT_SLINEAR, AST_FORMAT_SPEEX, AST_FORMAT_ULAW, ast_getformatname(), ast_log(), ast_frame::data, ast_frame::datalen, g723_samples(), LOG_WARNING, speex_samples(), and ast_frame::subclass.

Referenced by ast_rtp_read(), moh_generate(), schedule_delivery(), and socket_read().

01185 {
01186    int samples=0;
01187    switch(f->subclass) {
01188    case AST_FORMAT_SPEEX:
01189       samples = speex_samples(f->data, f->datalen);
01190       break;
01191    case AST_FORMAT_G723_1:
01192                 samples = g723_samples(f->data, f->datalen);
01193       break;
01194    case AST_FORMAT_ILBC:
01195       samples = 240 * (f->datalen / 50);
01196       break;
01197    case AST_FORMAT_GSM:
01198       samples = 160 * (f->datalen / 33);
01199       break;
01200    case AST_FORMAT_G729A:
01201       samples = f->datalen * 8;
01202       break;
01203    case AST_FORMAT_SLINEAR:
01204       samples = f->datalen / 2;
01205       break;
01206    case AST_FORMAT_LPC10:
01207                 /* assumes that the RTP packet contains one LPC10 frame */
01208       samples = 22 * 8;
01209       samples += (((char *)(f->data))[7] & 0x1) * 8;
01210       break;
01211    case AST_FORMAT_ULAW:
01212    case AST_FORMAT_ALAW:
01213       samples = f->datalen;
01214       break;
01215    case AST_FORMAT_ADPCM:
01216    case AST_FORMAT_G726:
01217       samples = f->datalen * 2;
01218       break;
01219    default:
01220       ast_log(LOG_WARNING, "Unable to calculate samples for format %s\n", ast_getformatname(f->subclass));
01221    }
01222    return samples;
01223 }

int ast_codec_interp_len int  format  )  [inline, static]
 

Gets duration in ms of interpolation frame for a format.

Definition at line 456 of file frame.h.

00457 { 
00458    return (format == AST_FORMAT_ILBC) ? 30 : 20;
00459 }

int ast_codec_pref_append struct ast_codec_pref pref,
int  format
 

Append a codec to a preference list, removing it first if it was already there.

Definition at line 955 of file frame.c.

References ast_codec_pref_remove(), AST_FORMAT_LIST, ast_format_list::bits, and ast_codec_pref::order.

Referenced by ast_parse_allow_disallow().

00956 {
00957    size_t size = 0;
00958    int x = 0, newindex = -1;
00959 
00960    ast_codec_pref_remove(pref, format);
00961    size = sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list);
00962 
00963    for (x = 0; x < size; x++) {
00964       if(AST_FORMAT_LIST[x].bits == format) {
00965          newindex = x + 1;
00966          break;
00967       }
00968    }
00969 
00970    if(newindex) {
00971       for (x = 0; x < size; x++) {
00972          if(!pref->order[x]) {
00973             pref->order[x] = newindex;
00974             break;
00975          }
00976       }
00977    }
00978 
00979    return x;
00980 }

void ast_codec_pref_convert struct ast_codec_pref pref,
char *  buf,
size_t  size,
int  right
 

Shift a codec preference list up or down 65 bytes so that it becomes an ASCII string.

Definition at line 858 of file frame.c.

References ast_codec_pref::order.

Referenced by check_access(), create_addr(), dump_prefs(), and socket_read().

00859 {
00860    int x = 0, differential = (int) 'A', mem = 0;
00861    char *from = NULL, *to = NULL;
00862 
00863    if(right) {
00864       from = pref->order;
00865       to = buf;
00866       mem = size;
00867    } else {
00868       to = pref->order;
00869       from = buf;
00870       mem = 32;
00871    }
00872 
00873    memset(to, 0, mem);
00874    for (x = 0; x < 32 ; x++) {
00875       if(!from[x])
00876          break;
00877       to[x] = right ? (from[x] + differential) : (from[x] - differential);
00878    }
00879 }

int ast_codec_pref_index struct ast_codec_pref pref,
int  index
 

Codec located at a particular place in the preference index.

Definition at line 916 of file frame.c.

References AST_FORMAT_LIST, ast_format_list::bits, and ast_codec_pref::order.

Referenced by _sip_show_peer(), add_sdp(), ast_codec_pref_string(), function_iaxpeer(), function_sippeer(), iax2_show_peer(), print_codec_to_cli(), and sip_show_user().

00917 {
00918    int slot = 0;
00919 
00920    
00921    if((index >= 0) && (index < sizeof(pref->order))) {
00922       slot = pref->order[index];
00923    }
00924 
00925    return slot ? AST_FORMAT_LIST[slot-1].bits : 0;
00926 }

void ast_codec_pref_init struct ast_codec_pref pref  ) 
 

Initialize a codec preference to "no preference".

void ast_codec_pref_remove struct ast_codec_pref pref,
int  format
 

Remove a codec from a preference list.

Definition at line 929 of file frame.c.

References AST_FORMAT_LIST, ast_format_list::bits, and ast_codec_pref::order.

Referenced by ast_codec_pref_append(), and ast_parse_allow_disallow().

00930 {
00931    struct ast_codec_pref oldorder;
00932    int x=0, y=0;
00933    size_t size = 0;
00934    int slot = 0;
00935 
00936    if(!pref->order[0])
00937       return;
00938 
00939    size = sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list);
00940 
00941    memcpy(&oldorder,pref,sizeof(struct ast_codec_pref));
00942    memset(pref,0,sizeof(struct ast_codec_pref));
00943 
00944    for (x = 0; x < size; x++) {
00945       slot = oldorder.order[x];
00946       if(! slot)
00947          break;
00948       if(AST_FORMAT_LIST[slot-1].bits != format)
00949          pref->order[y++] = slot;
00950    }
00951    
00952 }

int ast_codec_pref_string struct ast_codec_pref pref,
char *  buf,
size_t  size
 

Dump codec preference list into a string.

Definition at line 881 of file frame.c.

References ast_codec_pref_index(), and ast_getformatname().

Referenced by dump_prefs(), and socket_read().

00882 {
00883    int x = 0, codec = 0; 
00884    size_t total_len = 0, slen = 0;
00885    char *formatname = 0;
00886    
00887    memset(buf,0,size);
00888    total_len = size;
00889    buf[0] = '(';
00890    total_len--;
00891    for(x = 0; x < 32 ; x++) {
00892       if(total_len <= 0)
00893          break;
00894       if(!(codec = ast_codec_pref_index(pref,x)))
00895          break;
00896       if((formatname = ast_getformatname(codec))) {
00897          slen = strlen(formatname);
00898          if(slen > total_len)
00899             break;
00900          strncat(buf,formatname,total_len);
00901          total_len -= slen;
00902       }
00903       if(total_len && x < 31 && ast_codec_pref_index(pref , x + 1)) {
00904          strncat(buf,"|",total_len);
00905          total_len--;
00906       }
00907    }
00908    if(total_len) {
00909       strncat(buf,")",total_len);
00910       total_len--;
00911    }
00912 
00913    return size - total_len;
00914 }

int ast_fr_fdhangup int  fd  ) 
 

Sends a hangup to an fd Send a hangup (NULL equivalent) on an fd.

Parameters:
fd fd to write to
Returns:
Returns 0 on success, -1 on failure

struct ast_frame* ast_fr_fdread int  fd  ) 
 

Reads a frame from an fd Read a frame from a stream or packet fd, as written by fd_write.

Parameters:
fd an opened fd to read from
Returns:
returns a frame on success, NULL on error

int ast_fr_fdwrite int  fd,
struct ast_frame frame
 

Writes a frame to an fd Write a frame to an fd

Parameters:
fd Which fd to write to
frame frame to write to the fd
Returns:
Returns 0 on success, -1 on failure

int ast_frame_adjust_volume struct ast_frame f,
int  adjustment
 

Adjusts the volume of the audio samples contained in a frame.

Parameters:
f The frame containing the samples (must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR)
adjustment The number of dB to adjust up or down.
Returns:
0 for success, non-zero for an error

Definition at line 1258 of file frame.c.

References ast_slinear_saturated_divide(), ast_slinear_saturated_multiply(), ast_frame::data, ast_frame::frametype, ast_frame::samples, and ast_frame::subclass.

Referenced by ast_channel_spy_read_frame(), and conf_run().

01259 {
01260    int count;
01261    short *fdata = f->data;
01262    short adjust_value = abs(adjustment);
01263 
01264    if ((f->frametype != AST_FRAME_VOICE) || (f->subclass != AST_FORMAT_SLINEAR))
01265       return -1;
01266 
01267    if (!adjustment)
01268       return 0;
01269 
01270    for (count = 0; count < f->samples; count++) {
01271       if (adjustment > 0) {
01272          ast_slinear_saturated_multiply(&fdata[count], &adjust_value);
01273       } else if (adjustment < 0) {
01274          ast_slinear_saturated_divide(&fdata[count], &adjust_value);
01275       }
01276    }
01277 
01278    return 0;
01279 }

void ast_frame_dump char *  name,
struct ast_frame f,
char *  prefix
 

Dump a frame for debugging purposes

Definition at line 657 of file frame.c.

References AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_OFFHOOK, AST_CONTROL_OPTION, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_RING, AST_CONTROL_RINGING, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_WINK, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_IMAGE, AST_FRAME_NULL, AST_FRAME_TEXT, ast_getformatname(), AST_HTML_BEGIN, AST_HTML_DATA, AST_HTML_END, AST_HTML_LDCOMPLETE, AST_HTML_LINKREJECT, AST_HTML_LINKURL, AST_HTML_NOSUPPORT, AST_HTML_UNLINK, AST_HTML_URL, ast_strlen_zero(), ast_verbose(), COLOR_BLACK, COLOR_BRCYAN, COLOR_BRGREEN, COLOR_BRMAGENTA, COLOR_BRRED, COLOR_YELLOW, ast_frame::data, ast_frame::frametype, ast_frame::subclass, and term_color().

Referenced by ast_read(), and ast_write().

00658 {
00659    char *n = "unknown";
00660    char ftype[40] = "Unknown Frametype";
00661    char cft[80];
00662    char subclass[40] = "Unknown Subclass";
00663    char csub[80];
00664    char moreinfo[40] = "";
00665    char cn[60];
00666    char cp[40];
00667    char cmn[40];
00668    if (name)
00669       n = name;
00670    if (!f) {
00671       ast_verbose("%s [ %s (NULL) ] [%s]\n", 
00672          term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
00673          term_color(cft, "HANGUP", COLOR_BRRED, COLOR_BLACK, sizeof(cft)), 
00674          term_color(cn, n, COLOR_YELLOW, COLOR_BLACK, sizeof(cn)));
00675       return;
00676    }
00677    /* XXX We should probably print one each of voice and video when the format changes XXX */
00678    if (f->frametype == AST_FRAME_VOICE)
00679       return;
00680    if (f->frametype == AST_FRAME_VIDEO)
00681       return;
00682    switch(f->frametype) {
00683    case AST_FRAME_DTMF:
00684       strcpy(ftype, "DTMF");
00685       subclass[0] = f->subclass;
00686       subclass[1] = '\0';
00687       break;
00688    case AST_FRAME_CONTROL:
00689       strcpy(ftype, "Control");
00690       switch(f->subclass) {
00691       case AST_CONTROL_HANGUP:
00692          strcpy(subclass, "Hangup");
00693          break;
00694       case AST_CONTROL_RING:
00695          strcpy(subclass, "Ring");
00696          break;
00697       case AST_CONTROL_RINGING:
00698          strcpy(subclass, "Ringing");
00699          break;
00700       case AST_CONTROL_ANSWER:
00701          strcpy(subclass, "Answer");
00702          break;
00703       case AST_CONTROL_BUSY:
00704          strcpy(subclass, "Busy");
00705          break;
00706       case AST_CONTROL_TAKEOFFHOOK:
00707          strcpy(subclass, "Take Off Hook");
00708          break;
00709       case AST_CONTROL_OFFHOOK:
00710          strcpy(subclass, "Line Off Hook");
00711          break;
00712       case AST_CONTROL_CONGESTION:
00713          strcpy(subclass, "Congestion");
00714          break;
00715       case AST_CONTROL_FLASH:
00716          strcpy(subclass, "Flash");
00717          break;
00718       case AST_CONTROL_WINK:
00719          strcpy(subclass, "Wink");
00720          break;
00721       case AST_CONTROL_OPTION:
00722          strcpy(subclass, "Option");
00723          break;
00724       case AST_CONTROL_RADIO_KEY:
00725          strcpy(subclass, "Key Radio");
00726          break;
00727       case AST_CONTROL_RADIO_UNKEY:
00728          strcpy(subclass, "Unkey Radio");
00729          break;
00730       case -1:
00731          strcpy(subclass, "Stop generators");
00732          break;
00733       default:
00734          snprintf(subclass, sizeof(subclass), "Unknown control '%d'", f->subclass);
00735       }
00736       break;
00737    case AST_FRAME_NULL:
00738       strcpy(ftype, "Null Frame");
00739       strcpy(subclass, "N/A");
00740       break;
00741    case AST_FRAME_IAX:
00742       /* Should never happen */
00743       strcpy(ftype, "IAX Specific");
00744       snprintf(subclass, sizeof(subclass), "IAX Frametype %d", f->subclass);
00745       break;
00746    case AST_FRAME_TEXT:
00747       strcpy(ftype, "Text");
00748       strcpy(subclass, "N/A");
00749       ast_copy_string(moreinfo, f->data, sizeof(moreinfo));
00750       break;
00751    case AST_FRAME_IMAGE:
00752       strcpy(ftype, "Image");
00753       snprintf(subclass, sizeof(subclass), "Image format %s\n", ast_getformatname(f->subclass));
00754       break;
00755    case AST_FRAME_HTML:
00756       strcpy(ftype, "HTML");
00757       switch(f->subclass) {
00758       case AST_HTML_URL:
00759          strcpy(subclass, "URL");
00760          ast_copy_string(moreinfo, f->data, sizeof(moreinfo));
00761          break;
00762       case AST_HTML_DATA:
00763          strcpy(subclass, "Data");
00764          break;
00765       case AST_HTML_BEGIN:
00766          strcpy(subclass, "Begin");
00767          break;
00768       case AST_HTML_END:
00769          strcpy(subclass, "End");
00770          break;
00771       case AST_HTML_LDCOMPLETE:
00772          strcpy(subclass, "Load Complete");
00773          break;
00774       case AST_HTML_NOSUPPORT:
00775          strcpy(subclass, "No Support");
00776          break;
00777       case AST_HTML_LINKURL:
00778          strcpy(subclass, "Link URL");
00779          ast_copy_string(moreinfo, f->data, sizeof(moreinfo));
00780          break;
00781       case AST_HTML_UNLINK:
00782          strcpy(subclass, "Unlink");
00783          break;
00784       case AST_HTML_LINKREJECT:
00785          strcpy(subclass, "Link Reject");
00786          break;
00787       default:
00788          snprintf(subclass, sizeof(subclass), "Unknown HTML frame '%d'\n", f->subclass);
00789          break;
00790       }
00791       break;
00792    default:
00793       snprintf(ftype, sizeof(ftype), "Unknown Frametype '%d'", f->frametype);
00794    }
00795    if (!ast_strlen_zero(moreinfo))
00796       ast_verbose("%s [ TYPE: %s (%d) SUBCLASS: %s (%d) '%s' ] [%s]\n",  
00797          term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
00798          term_color(cft, ftype, COLOR_BRRED, COLOR_BLACK, sizeof(cft)),
00799          f->frametype, 
00800          term_color(csub, subclass, COLOR_BRCYAN, COLOR_BLACK, sizeof(csub)),
00801          f->subclass, 
00802          term_color(cmn, moreinfo, COLOR_BRGREEN, COLOR_BLACK, sizeof(cmn)),
00803          term_color(cn, n, COLOR_YELLOW, COLOR_BLACK, sizeof(cn)));
00804    else
00805       ast_verbose("%s [ TYPE: %s (%d) SUBCLASS: %s (%d) ] [%s]\n",  
00806          term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
00807          term_color(cft, ftype, COLOR_BRRED, COLOR_BLACK, sizeof(cft)),
00808          f->frametype, 
00809          term_color(csub, subclass, COLOR_BRCYAN, COLOR_BLACK, sizeof(csub)),
00810          f->subclass, 
00811          term_color(cn, n, COLOR_YELLOW, COLOR_BLACK, sizeof(cn)));
00812 
00813 }

int ast_frame_slinear_sum struct ast_frame f1,
struct ast_frame f2
 

Sums two frames of audio samples.

Parameters:
f1 The first frame (which will contain the result)
f2 The second frame
Returns:
0 for success, non-zero for an error
The frames must be AST_FRAME_VOICE and must contain AST_FORMAT_SLINEAR samples, and must contain the same number of samples.

Definition at line 1281 of file frame.c.

References ast_slinear_saturated_add(), ast_frame::data, ast_frame::frametype, ast_frame::samples, and ast_frame::subclass.

Referenced by ast_channel_spy_read_frame().

01282 {
01283    int count;
01284    short *data1, *data2;
01285 
01286    if ((f1->frametype != AST_FRAME_VOICE) || (f1->subclass != AST_FORMAT_SLINEAR))
01287       return -1;
01288 
01289    if ((f2->frametype != AST_FRAME_VOICE) || (f2->subclass != AST_FORMAT_SLINEAR))
01290       return -1;
01291 
01292    if (f1->samples != f2->samples)
01293       return -1;
01294 
01295    for (count = 0, data1 = f1->data, data2 = f2->data;
01296         count < f1->samples;
01297         count++, data1++, data2++)
01298       ast_slinear_saturated_add(data1, data2);
01299 
01300    return 0;
01301 }

struct ast_frame* ast_frdup struct ast_frame fr  ) 
 

Copies a frame.

Parameters:
fr frame to copy Dupliates a frame -- should only rarely be used, typically frisolate is good enough
Returns:
Returns a frame on success, NULL on error

Definition at line 345 of file frame.c.

References AST_FRIENDLY_OFFSET, ast_frame::data, ast_frame::datalen, ast_frame::delivery, ast_frame::frametype, malloc, ast_frame::mallocd, ast_frame::next, ast_frame::offset, ast_frame::prev, ast_frame::samples, ast_frame::src, and ast_frame::subclass.

Referenced by ast_channel_spy_read_frame(), ast_queue_frame(), ast_rtp_write(), ast_slinfactory_feed(), and queue_frame_to_spies().

00346 {
00347    struct ast_frame *out;
00348    int len, srclen = 0;
00349    void *buf;
00350    /* Start with standard stuff */
00351    len = sizeof(struct ast_frame) + AST_FRIENDLY_OFFSET + f->datalen;
00352    /* If we have a source, add space for it */
00353    /*
00354     * XXX Watch out here - if we receive a src which is not terminated
00355     * properly, we can be easily attacked. Should limit the size we deal with.
00356     */
00357    if (f->src)
00358       srclen = strlen(f->src);
00359    if (srclen > 0)
00360       len += srclen + 1;
00361    buf = malloc(len);
00362    if (!buf)
00363       return NULL;
00364    out = buf;
00365    /* Set us as having malloc'd header only, so it will eventually
00366       get freed. */
00367    out->frametype = f->frametype;
00368    out->subclass = f->subclass;
00369    out->datalen = f->datalen;
00370    out->samples = f->samples;
00371    out->delivery = f->delivery;
00372    out->mallocd = AST_MALLOCD_HDR;
00373    out->offset = AST_FRIENDLY_OFFSET;
00374    out->data = buf + sizeof(struct ast_frame) + AST_FRIENDLY_OFFSET;
00375    if (srclen > 0) {
00376       out->src = out->data + f->datalen;
00377       /* Must have space since we allocated for it */
00378       strcpy((char *)out->src, f->src);
00379    } else
00380       out->src = NULL;
00381    out->prev = NULL;
00382    out->next = NULL;
00383    memcpy(out->data, f->data, out->datalen); 
00384    return out;
00385 }

void ast_frfree struct ast_frame fr  ) 
 

Requests a frame to be allocated Frees a frame.

Todo:
Important: I should be made more efficient. Frame headers should most definitely be cached

Definition at line 273 of file frame.c.

References ast_mutex_lock(), ast_mutex_unlock(), ast_frame::data, free, ast_frame::mallocd, ast_frame::next, ast_frame::offset, ast_frame::prev, and ast_frame::src.

Referenced by __adsi_transmit_messages(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), agent_read(), app_exec(), ast_app_getvoice(), ast_bridge_call(), ast_channel_free(), ast_channel_spy_read_frame(), ast_channel_spy_remove(), ast_dsp_process(), ast_feature_request_and_dial(), ast_generic_bridge(), ast_masq_park_call(), ast_play_and_prepend(), ast_play_and_record(), ast_queue_frame(), ast_read(), ast_recvtext(), ast_rtp_bridge(), ast_safe_sleep(), ast_safe_sleep_conditional(), ast_send_image(), ast_slinfactory_destroy(), ast_slinfactory_read(), ast_tonepair(), ast_translate(), ast_waitfordigit(), ast_waitfordigit_full(), ast_waitstream(), ast_waitstream_exten(), ast_waitstream_fr(), ast_waitstream_full(), ast_write(), async_wait(), autoservice_run(), background_detect_exec(), builtin_atxfer(), calc_cost(), channel_spy(), check_goto_on_transfer(), conf_exec(), conf_flush(), conf_run(), copy_data_from_queue(), dictate_exec(), disa_exec(), do_parking_thread(), do_waiting(), echo_exec(), find_cache(), gen_generate(), handle_recordfile(), iax2_bridge(), iax_park_thread(), ices_exec(), mixmonitor_thread(), moh_files_generator(), mp3_exec(), NBScat_exec(), queue_frame_to_spies(), receive_dtmf_digits(), record_exec(), recordthread(), rpt(), rpt_exec(), run_agi(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), sms_exec(), spy_generate(), ss_thread(), vpb_bridge(), wait_for_answer(), wait_for_hangup(), waitforring_exec(), and zt_bridge().

00274 {
00275    if (fr->mallocd & AST_MALLOCD_DATA) {
00276       if (fr->data) 
00277          free(fr->data - fr->offset);
00278    }
00279    if (fr->mallocd & AST_MALLOCD_SRC) {
00280       if (fr->src)
00281          free((char *)fr->src);
00282    }
00283    if (fr->mallocd & AST_MALLOCD_HDR) {
00284 #ifdef TRACE_FRAMES
00285       headers--;
00286       ast_mutex_lock(&framelock);
00287       if (fr->next)
00288          fr->next->prev = fr->prev;
00289       if (fr->prev)
00290          fr->prev->next = fr->next;
00291       else
00292          headerlist = fr->next;
00293       ast_mutex_unlock(&framelock);
00294 #endif         
00295       free(fr);
00296    }
00297 }

struct ast_frame* ast_frisolate struct ast_frame fr  ) 
 

Copies a frame.

Parameters:
fr frame to act upon Take a frame, and if it's not been malloc'd, make a malloc'd copy and if the data hasn't been malloced then make the data malloc'd. If you need to store frames, say for queueing, then you should call this function.
Returns:
Returns a frame on success, NULL on error

Definition at line 304 of file frame.c.

References ast_frame_header_new(), AST_FRIENDLY_OFFSET, ast_log(), AST_MALLOCD_HDR, AST_MALLOCD_SRC, ast_frame::data, ast_frame::datalen, ast_frame::frametype, free, LOG_WARNING, malloc, ast_frame::mallocd, ast_frame::offset, ast_frame::samples, ast_frame::src, strdup, and ast_frame::subclass.

Referenced by jpeg_read_image(), and monitor_handle_owned().

00305 {
00306    struct ast_frame *out;
00307    if (!(fr->mallocd & AST_MALLOCD_HDR)) {
00308       /* Allocate a new header if needed */
00309       out = ast_frame_header_new();
00310       if (!out) {
00311          ast_log(LOG_WARNING, "Out of memory\n");
00312          return NULL;
00313       }
00314       out->frametype = fr->frametype;
00315       out->subclass = fr->subclass;
00316       out->datalen = fr->datalen;
00317       out->samples = fr->samples;
00318       out->offset = fr->offset;
00319       out->src = NULL;
00320       out->data = fr->data;
00321    } else {
00322       out = fr;
00323    }
00324    if (!(fr->mallocd & AST_MALLOCD_SRC)) {
00325       if (fr->src)
00326          out->src = strdup(fr->src);
00327    } else
00328       out->src = fr->src;
00329    if (!(fr->mallocd & AST_MALLOCD_DATA))  {
00330       out->data = malloc(fr->datalen + AST_FRIENDLY_OFFSET);
00331       if (!out->data) {
00332          free(out);
00333          ast_log(LOG_WARNING, "Out of memory\n");
00334          return NULL;
00335       }
00336       out->data += AST_FRIENDLY_OFFSET;
00337       out->offset = AST_FRIENDLY_OFFSET;
00338       out->datalen = fr->datalen;
00339       memcpy(out->data, fr->data, fr->datalen);
00340    }
00341    out->mallocd = AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA;
00342    return out;
00343 }

struct ast_format_list* ast_get_format_list size_t *  size  ) 
 

Definition at line 487 of file frame.c.

00488 {
00489    *size = (sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list));
00490    return AST_FORMAT_LIST;
00491 }

struct ast_format_list* ast_get_format_list_index int  index  ) 
 

Definition at line 482 of file frame.c.

References AST_FORMAT_LIST.

00483 {
00484    return &AST_FORMAT_LIST[index];
00485 }

int ast_getformatbyname char *  name  ) 
 

Gets a format from a name.

Parameters:
name string of format
Returns:
This returns the form of the format in binary on success, 0 on error.

Definition at line 552 of file frame.c.

References ast_expand_codec_alias(), AST_FORMAT_LIST, ast_format_list::bits, name, and ast_format_list::visible.

Referenced by ast_parse_allow_disallow(), iax_template_parse(), load_moh_classes(), reload_config(), sip_answer(), and update_common_options().

00553 {
00554    int x = 0, all = 0, format = 0;
00555 
00556    all = strcasecmp(name, "all") ? 0 : 1;
00557    for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
00558       if(AST_FORMAT_LIST[x].visible && (all || 
00559                                 !strcasecmp(AST_FORMAT_LIST[x].name,name) ||
00560                                 !strcasecmp(AST_FORMAT_LIST[x].name,ast_expand_codec_alias(name)))) {
00561          format |= AST_FORMAT_LIST[x].bits;
00562          if(!all)
00563             break;
00564       }
00565    }
00566 
00567    return format;
00568 }

char* ast_getformatname int  format  ) 
 

Get the name of a format.

Parameters:
format id of format
Returns:
A static string containing the name of the format or "UNKN" if unknown.

Definition at line 493 of file frame.c.

References AST_FORMAT_LIST, ast_format_list::bits, ast_format_list::name, and ast_format_list::visible.

Referenced by __login_exec(), __sip_show_channels(), _sip_show_peer(), add_codec_to_sdp(), agent_call(), ast_channel_spy_add(), ast_codec_get_len(), ast_codec_get_samples(), ast_codec_pref_string(), ast_dsp_process(), ast_frame_dump(), ast_play_and_prepend(), ast_play_and_record(), ast_read(), ast_register_translator(), ast_rtp_write(), ast_slinfactory_feed(), ast_streamfile(), ast_translator_build_path(), ast_unregister_translator(), ast_writestream(), background_detect_exec(), do_waiting(), eagi_exec(), function_iaxpeer(), function_sippeer(), iax2_request(), iax2_show_channels(), iax2_show_peer(), iax_show_provisioning(), modem_request(), moh_classes_show(), moh_release(), phone_setup(), print_codec_to_cli(), queue_frame_to_spies(), rebuild_matrix(), set_format(), show_codecs(), show_file_formats(), show_image_formats(), show_translation(), sip_request_call(), sip_show_channel(), sip_show_user(), socket_read(), and zt_read().

00494 {
00495    int x = 0;
00496    char *ret = "unknown";
00497    for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
00498       if(AST_FORMAT_LIST[x].visible && AST_FORMAT_LIST[x].bits == format) {
00499          ret = AST_FORMAT_LIST[x].name;
00500          break;
00501       }
00502    }
00503    return ret;
00504 }

char* ast_getformatname_multiple char *  buf,
size_t  size,
int  format
 

Get the names of a set of formats.

Parameters:
buf a buffer for the output string
size size of buf (bytes)
format the format (combined IDs of codecs) Prints a list of readable codec names corresponding to "format". ex: for format=AST_FORMAT_GSM|AST_FORMAT_SPEEX|AST_FORMAT_ILBC it will return "0x602 (GSM|SPEEX|ILBC)"
Returns:
The return value is buf.

Definition at line 506 of file frame.c.

References AST_FORMAT_LIST, ast_format_list::bits, name, and ast_format_list::visible.

Referenced by _sip_show_peer(), function_iaxpeer(), function_sippeer(), iax2_bridge(), iax2_show_peer(), and process_sdp().

00506                                                                      {
00507 
00508    int x = 0;
00509    unsigned len;
00510    char *end = buf;
00511    char *start = buf;
00512    if (!size) return buf;
00513    snprintf(end, size, "0x%x (", format);
00514    len = strlen(end);
00515    end += len;
00516    size -= len;
00517    start = end;
00518    for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
00519       if (AST_FORMAT_LIST[x].visible && (AST_FORMAT_LIST[x].bits & format)) {
00520          snprintf(end, size,"%s|",AST_FORMAT_LIST[x].name);
00521          len = strlen(end);
00522          end += len;
00523          size -= len;
00524       }
00525    }
00526    if (start == end)
00527       snprintf(start, size, "nothing)");
00528    else if (size > 1)
00529       *(end -1) = ')';
00530    return buf;
00531 }

void ast_parse_allow_disallow struct ast_codec_pref pref,
int *  mask,
const char *  list,
int  allowing
 

Parse an "allow" or "deny" line and update the mask and pref if provided.

Definition at line 1006 of file frame.c.

References ast_codec_pref_append(), ast_codec_pref_remove(), ast_getformatbyname(), ast_log(), ast_strdupa, LOG_WARNING, and strsep().

Referenced by build_peer(), build_user(), reload_config(), and set_config().

01007 {
01008    char *parse;
01009    char *this;
01010    int format;
01011 
01012    parse = ast_strdupa(list);
01013    while ((this = strsep(&parse, ","))) {
01014       if (!(format = ast_getformatbyname(this))) {
01015          ast_log(LOG_WARNING, "Cannot %s unknown format '%s'\n", allowing ? "allow" : "disallow", this);
01016          continue;
01017       }
01018 
01019       if (mask) {
01020          if (allowing)
01021             *mask |= format;
01022          else
01023             *mask &= ~format;
01024       }
01025 
01026       if (pref) {
01027          if (strcasecmp(this, "all")) {
01028             if (allowing)
01029                ast_codec_pref_append(pref, format);
01030             else
01031                ast_codec_pref_remove(pref, format);
01032          } else if (!allowing) {
01033             memset(pref, 0, sizeof(*pref));
01034          }
01035       }
01036    }
01037 }

void ast_smoother_free struct ast_smoother s  ) 
 

Definition at line 243 of file frame.c.

References free, and s.

Referenced by ast_rtp_destroy(), and ast_rtp_write().

00244 {
00245    free(s);
00246 }

int ast_smoother_get_flags struct ast_smoother smoother  ) 
 

Definition at line 127 of file frame.c.

References ast_smoother::flags, and s.

00128 {
00129    return s->flags;
00130 }

struct ast_smoother* ast_smoother_new int  bytes  ) 
 

Definition at line 116 of file frame.c.

References ast_smoother_reset(), malloc, and s.

Referenced by ast_rtp_write().

00117 {
00118    struct ast_smoother *s;
00119    if (size < 1)
00120       return NULL;
00121    s = malloc(sizeof(struct ast_smoother));
00122    if (s)
00123       ast_smoother_reset(s, size);
00124    return s;
00125 }

struct ast_frame* ast_smoother_read struct ast_smoother s  ) 
 

Definition at line 194 of file frame.c.

References ast_log(), ast_tvadd(), ast_smoother::data, ast_frame::data, ast_frame::datalen, ast_smoother::delivery, ast_frame::delivery, ast_smoother::f, ast_smoother::flags, ast_smoother::format, ast_smoother::framedata, ast_frame::frametype, ast_smoother::len, LOG_WARNING, ast_frame::offset, ast_smoother::opt, s, ast_frame::samples, ast_smoother::samplesperbyte, ast_smoother::size, and ast_frame::subclass.

Referenced by ast_rtp_write().

00195 {
00196    struct ast_frame *opt;
00197    int len;
00198    /* IF we have an optimization frame, send it */
00199    if (s->opt) {
00200       if (s->opt->offset < AST_FRIENDLY_OFFSET)
00201          ast_log(LOG_WARNING, "Returning a frame of inappropriate offset (%d).",
00202                      s->opt->offset);
00203       opt = s->opt;
00204       s->opt = NULL;
00205       return opt;
00206    }
00207 
00208    /* Make sure we have enough data */
00209    if (s->len < s->size) {
00210       /* Or, if this is a G.729 frame with VAD on it, send it immediately anyway */
00211       if (!((s->flags & AST_SMOOTHER_FLAG_G729) && (s->size % 10)))
00212          return NULL;
00213    }
00214    len = s->size;
00215    if (len > s->len)
00216       len = s->len;
00217    /* Make frame */
00218    s->f.frametype = AST_FRAME_VOICE;
00219    s->f.subclass = s->format;
00220    s->f.data = s->framedata + AST_FRIENDLY_OFFSET;
00221    s->f.offset = AST_FRIENDLY_OFFSET;
00222    s->f.datalen = len;
00223    /* Samples will be improper given VAD, but with VAD the concept really doesn't even exist */
00224    s->f.samples = len * s->samplesperbyte;   /* XXX rounding */
00225    s->f.delivery = s->delivery;
00226    /* Fill Data */
00227    memcpy(s->f.data, s->data, len);
00228    s->len -= len;
00229    /* Move remaining data to the front if applicable */
00230    if (s->len) {
00231       /* In principle this should all be fine because if we are sending
00232          G.729 VAD, the next timestamp will take over anyawy */
00233       memmove(s->data, s->data + len, s->len);
00234       if (!ast_tvzero(s->delivery)) {
00235          /* If we have delivery time, increment it, otherwise, leave it at 0 */
00236          s->delivery = ast_tvadd(s->delivery, ast_samp2tv(s->f.samples, 8000));
00237       }
00238    }
00239    /* Return frame */
00240    return &s->f;
00241 }

void ast_smoother_reset struct ast_smoother s,
int  bytes
 

Definition at line 110 of file frame.c.

References s, and ast_smoother::size.

Referenced by ast_smoother_new().

00111 {
00112    memset(s, 0, sizeof(struct ast_smoother));
00113    s->size = size;
00114 }

void ast_smoother_set_flags struct ast_smoother smoother,
int  flags
 

Definition at line 132 of file frame.c.

References ast_smoother::flags, and s.

Referenced by ast_rtp_write().

00133 {
00134    s->flags = flags;
00135 }

void ast_swapcopy_samples void *  dst,
const void *  src,
int  samples
 

Definition at line 471 of file frame.c.

Referenced by __ast_smoother_feed(), iax_frame_wrap(), and phone_write_buf().

00472 {
00473    int i;
00474    unsigned short *dst_s = dst;
00475    const unsigned short *src_s = src;
00476 
00477    for (i=0; i<samples; i++)
00478       dst_s[i] = (src_s[i]<<8) | (src_s[i]>>8);
00479 }


Generated on Mon Mar 20 08:25:59 2006 for Asterisk - the Open Source PBX by  doxygen 1.3.9.1