Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:01:33 2007

Asterisk developer's documentation :: Codename Pineapple


frame.h File Reference


Detailed Description

Asterisk internal frame definitions.

Definition in file frame.h.

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

Include dependency graph for frame.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_codec_pref
struct  ast_format_list
 Definition of supported media formats (codecs). More...
struct  ast_frame
 Data structure associated with a single frame of data. More...
struct  ast_option_header
struct  oprmode

Defines

#define AST_FORMAT_ADPCM   (1 << 5)
#define AST_FORMAT_ALAW   (1 << 3)
#define AST_FORMAT_AUDIO_MASK   ((1 << 16)-1)
#define AST_FORMAT_G722   (1 << 12)
#define AST_FORMAT_G723_1   (1 << 0)
#define AST_FORMAT_G726   (1 << 11)
#define AST_FORMAT_G726_AAL2   (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_H264   (1 << 21)
#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_TEXT   (1 << 26)
#define AST_FORMAT_MAX_VIDEO   (1 << 24)
#define AST_FORMAT_MP4_VIDEO   (1 << 22)
#define AST_FORMAT_PNG   (1 << 17)
#define AST_FORMAT_SLINEAR   (1 << 6)
#define AST_FORMAT_SPEEX   (1 << 9)
#define AST_FORMAT_T140   (1 << 25)
#define AST_FORMAT_TEXT_MASK   (((1 << 27)-1) & ~(AST_FORMAT_AUDIO_MASK) & ~(AST_FORMAT_VIDEO_MASK)))
#define AST_FORMAT_ULAW   (1 << 2)
#define AST_FORMAT_VIDEO_MASK   (((1 << 25)-1) & ~(AST_FORMAT_AUDIO_MASK))
#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_DTMF   AST_FRAME_DTMF_END
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
#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_MODEM_T38   1
#define AST_MODEM_V150   2
#define AST_OPTION_AUDIO_MODE   4
#define AST_OPTION_ECHOCAN   8
#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_OPRMODE   7
#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_BE   (1 << 1)
#define AST_SMOOTHER_FLAG_G729   (1 << 0)

Enumerations

enum  ast_control_frame_type {
  AST_CONTROL_HANGUP = 1, AST_CONTROL_RING = 2, AST_CONTROL_RINGING = 3, AST_CONTROL_ANSWER = 4,
  AST_CONTROL_BUSY = 5, AST_CONTROL_TAKEOFFHOOK = 6, AST_CONTROL_OFFHOOK = 7, AST_CONTROL_CONGESTION = 8,
  AST_CONTROL_FLASH = 9, AST_CONTROL_WINK = 10, AST_CONTROL_OPTION = 11, AST_CONTROL_RADIO_KEY = 12,
  AST_CONTROL_RADIO_UNKEY = 13, AST_CONTROL_PROGRESS = 14, AST_CONTROL_PROCEEDING = 15, AST_CONTROL_HOLD = 16,
  AST_CONTROL_UNHOLD = 17, AST_CONTROL_VIDUPDATE = 18
}
enum  ast_frame_type {
  AST_FRAME_DTMF_END = 1, AST_FRAME_VOICE, AST_FRAME_VIDEO, AST_FRAME_CONTROL,
  AST_FRAME_NULL, AST_FRAME_IAX, AST_FRAME_TEXT, AST_FRAME_IMAGE,
  AST_FRAME_HTML, AST_FRAME_CNG, AST_FRAME_MODEM, AST_FRAME_DTMF_BEGIN
}
 Frame types. More...

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 audio 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.
static 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 audio 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 an audio codec preference list up or down 65 bytes so that it becomes an ASCII string.
ast_format_list ast_codec_pref_getsize (struct ast_codec_pref *pref, int format)
 Get packet size for codec.
int ast_codec_pref_index (struct ast_codec_pref *pref, int index)
 Codec located at a particular place in the preference index See Audio Codec Preferences.
void ast_codec_pref_init (struct ast_codec_pref *pref)
 Initialize an audio codec preference to "no preference" See Audio Codec Preferences.
void ast_codec_pref_remove (struct ast_codec_pref *pref, int format)
 Remove audio a codec from a preference list.
int ast_codec_pref_setsize (struct ast_codec_pref *pref, int format, int framems)
 Set packet size for codec.
int ast_codec_pref_string (struct ast_codec_pref *pref, char *buf, size_t size)
 Dump audio codec preference list into a string.
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 (const char *name, struct ast_frame *f, char *prefix)
ast_frameast_frame_enqueue (struct ast_frame *head, struct ast_frame *f, int maxlen, int dupe)
 Appends a frame to the end of a list of frames, truncating the maximum length of the list.
void ast_frame_free (struct ast_frame *fr, int cache)
 Requests a frame to be allocated Frees a frame.
int ast_frame_slinear_sum (struct ast_frame *f1, struct ast_frame *f2)
 Sums two frames of audio samples.
ast_frameast_frdup (const struct ast_frame *fr)
 Copies a frame.
static void force_inline ast_frfree (struct ast_frame *fr)
ast_frameast_frisolate (struct ast_frame *fr)
 Makes a frame independent of any static storage.
ast_format_listast_get_format_list (size_t *size)
ast_format_listast_get_format_list_index (int index)
int ast_getformatbyname (const 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.
int ast_parse_allow_disallow (struct ast_codec_pref *pref, int *mask, const char *list, int allowing)
 Parse an "allow" or "deny" line in a channel or device configuration and update the capabilities mask and pref if provided. Video codecs are not added to codec preference lists, since we can not transcode.
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)
int ast_smoother_test_flag (struct ast_smoother *s, int flag)
void ast_swapcopy_samples (void *dst, const void *src, int samples)

Variables

ast_frame ast_null_frame


Define Documentation

#define AST_FORMAT_ADPCM   (1 << 5)
 

ADPCM (IMA)

Definition at line 231 of file frame.h.

Referenced by ast_best_codec(), ast_codec_get_len(), ast_codec_get_samples(), and convertcap().

#define AST_FORMAT_ALAW   (1 << 3)
 

Raw A-law data (G.711)

Definition at line 227 of file frame.h.

Referenced by ast_best_codec(), ast_codec_get_len(), ast_codec_get_samples(), ast_dsp_process(), cb_events(), codec_ast2skinny(), codec_skinny2ast(), convertcap(), misdn_read(), oh323_rtp_read(), read_config(), reset_global_settings(), zt_read(), and zt_write().

#define AST_FORMAT_AUDIO_MASK   ((1 << 16)-1)
 

Maximum audio mask

Definition at line 249 of file frame.h.

Referenced by add_sdp(), ast_best_codec(), ast_openstream_full(), ast_request(), ast_translate_available_formats(), gtalk_rtp_read(), jingle_rtp_read(), set_format(), sip_call(), sip_rtp_read(), and sip_write().

#define AST_FORMAT_G722   (1 << 12)
 

G.722

Definition at line 245 of file frame.h.

Referenced by ast_codec_get_samples(), and convertcap().

#define AST_FORMAT_G723_1   (1 << 0)
 

G.723.1 compression

Definition at line 221 of file frame.h.

Referenced by ast_best_codec(), ast_codec_get_len(), ast_codec_get_samples(), codec_ast2skinny(), codec_skinny2ast(), convertcap(), load_module(), phone_request(), phone_setup(), and phone_write().

#define AST_FORMAT_G726   (1 << 11)
 

ADPCM (G.726, 32kbps, RFC3551 codeword packing)

Definition at line 243 of file frame.h.

Referenced by ast_best_codec(), ast_codec_get_len(), ast_codec_get_samples(), and ast_rtp_set_rtpmap_type().

#define AST_FORMAT_G726_AAL2   (1 << 4)
 

ADPCM (G.726, 32kbps, AAL2 codeword packing)

Definition at line 229 of file frame.h.

Referenced by ast_best_codec(), ast_codec_get_len(), ast_codec_get_samples(), ast_rtp_lookup_mime_subtype(), ast_rtp_set_rtpmap_type(), codec_ast2skinny(), codec_skinny2ast(), and setup_rtp_connection().

#define AST_FORMAT_G729A   (1 << 8)
 

G.729A audio

Definition at line 237 of file frame.h.

Referenced by add_codec_to_sdp(), ast_best_codec(), ast_codec_get_len(), ast_codec_get_samples(), codec_ast2skinny(), codec_skinny2ast(), convertcap(), load_module(), phone_request(), phone_setup(), and phone_write().

#define AST_FORMAT_GSM   (1 << 1)
 

GSM compression

Definition at line 223 of file frame.h.

Referenced by ast_best_codec(), ast_codec_get_len(), ast_codec_get_samples(), convertcap(), and reset_global_settings().

#define AST_FORMAT_H261   (1 << 18)
 

H.261 Video

Definition at line 255 of file frame.h.

Referenced by codec_ast2skinny(), and codec_skinny2ast().

#define AST_FORMAT_H263   (1 << 19)
 

H.263 Video

Definition at line 257 of file frame.h.

Referenced by codec_ast2skinny(), codec_skinny2ast(), and reset_global_settings().

#define AST_FORMAT_H263_PLUS   (1 << 20)
 

H.263+ Video

Definition at line 259 of file frame.h.

#define AST_FORMAT_H264   (1 << 21)
 

H.264 Video

Definition at line 261 of file frame.h.

#define AST_FORMAT_ILBC   (1 << 10)
 

iLBC Free Compression

Definition at line 241 of file frame.h.

Referenced by add_codec_to_sdp(), ast_best_codec(), ast_codec_get_len(), ast_codec_get_samples(), ast_codec_interp_len(), and convertcap().

#define AST_FORMAT_JPEG   (1 << 16)
 

JPEG Images

Definition at line 251 of file frame.h.

#define AST_FORMAT_LPC10   (1 << 7)
 

LPC10, 180 samples/frame

Definition at line 235 of file frame.h.

Referenced by ast_best_codec(), and ast_codec_get_samples().

#define AST_FORMAT_MAX_AUDIO   (1 << 15)
 

Maximum audio format

Definition at line 247 of file frame.h.

Referenced by add_sdp(), ast_closestream(), ast_filehelper(), ast_openvstream(), ast_playstream(), ast_rtp_raw_write(), ast_rtp_read(), ast_translate_available_formats(), ast_writestream(), jingle_accept_call(), oh323_request(), phone_read(), sip_request_call(), skinny_request(), transmit_connect_with_sdp(), and transmit_modify_with_sdp().

#define AST_FORMAT_MAX_TEXT   (1 << 26)
 

Maximum text mask

Definition at line 270 of file frame.h.

#define AST_FORMAT_MAX_VIDEO   (1 << 24)
 

Maximum video format

Definition at line 265 of file frame.h.

Referenced by ast_openvstream().

#define AST_FORMAT_MP4_VIDEO   (1 << 22)
 

MPEG4 Video

Definition at line 263 of file frame.h.

#define AST_FORMAT_PNG   (1 << 17)
 

PNG Images

Definition at line 253 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 233 of file frame.h.

Referenced by __ast_register_translator(), action_originate(), agent_new(), alsa_new(), alsa_read(), alsa_request(), ast_best_codec(), ast_channel_make_compatible_helper(), ast_channel_spy_add(), ast_channel_start_silence_generator(), ast_channel_whisper_stop(), ast_codec_get_len(), ast_codec_get_samples(), ast_dsp_call_progress(), ast_dsp_digitdetect(), ast_dsp_process(), ast_dsp_silence(), ast_frame_adjust_volume(), ast_frame_slinear_sum(), ast_rtp_read(), ast_slinfactory_feed(), ast_write(), attempt_thread(), eagi_exec(), fast_originate(), handle_recordfile(), iax_frame_wrap(), linear_alloc(), linear_generator(), load_module(), load_moh_classes(), moh_class_malloc(), nbs_request(), nbs_xwrite(), oh323_rtp_read(), orig_app(), orig_exten(), oss_new(), oss_read(), oss_request(), phone_new(), phone_read(), phone_request(), phone_setup(), phone_write(), playtones_alloc(), queue_frame_to_spies(), read_config(), silence_generator_generate(), socket_process(), tonepair_alloc(), zt_read(), and zt_write().

#define AST_FORMAT_SPEEX   (1 << 9)
 

SpeeX Free Compression

Definition at line 239 of file frame.h.

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

#define AST_FORMAT_T140   (1 << 25)
 

T.140 Text format - ITU T.140, RFC 4351

Definition at line 268 of file frame.h.

#define AST_FORMAT_TEXT_MASK   (((1 << 27)-1) & ~(AST_FORMAT_AUDIO_MASK) & ~(AST_FORMAT_VIDEO_MASK)))
 

Definition at line 271 of file frame.h.

#define AST_FORMAT_ULAW   (1 << 2)
 

Raw mu-law data (G.711)

Definition at line 225 of file frame.h.

Referenced by __adsi_transmit_messages(), adsi_careful_send(), ast_adsi_transmit_message_full(), ast_best_codec(), ast_codec_get_len(), ast_codec_get_samples(), ast_dsp_process(), codec_ast2skinny(), codec_skinny2ast(), convertcap(), load_module(), oh323_rtp_read(), phone_request(), phone_setup(), phone_write(), reset_global_settings(), zt_read(), and zt_write().

#define AST_FORMAT_VIDEO_MASK   (((1 << 25)-1) & ~(AST_FORMAT_AUDIO_MASK))
 

Definition at line 266 of file frame.h.

Referenced by add_sdp(), ast_request(), ast_translate_available_formats(), check_peer_ok(), check_user_ok(), create_addr_from_peer(), gtalk_new(), gtalk_rtp_read(), jingle_new(), jingle_rtp_read(), sip_new(), and sip_rtp_read().

#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 424 of file frame.h.

Referenced by ast_rtp_read(), and socket_process().

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

Definition at line 423 of file frame.h.

Referenced by phone_read().

#define AST_FRAME_DTMF   AST_FRAME_DTMF_END
 

Definition at line 125 of file frame.h.

Referenced by __adsi_transmit_messages(), action_zapdialoffhook(), agent_ack_sleep(), ast_bridge_call(), ast_dsp_process(), ast_feature_request_and_dial(), ast_jb_put(), ast_waitfordigit_full(), cb_events(), console_dial(), do_immediate_setup(), gtalk_handle_dtmf(), handle_recordfile(), handle_request(), handle_request_info(), jingle_handle_dtmf(), mgcp_rtp_read(), misdn_bridge(), oh323_rtp_read(), phone_exception(), process_ast_dsp(), sip_rtp_read(), ss_thread(), zt_bridge(), and zt_read().

#define AST_FRAME_SET_BUFFER fr,
_base,
_ofs,
_datalen   ) 
 

Value:

{              \
   (fr)->data = (char *)_base + (_ofs);   \
   (fr)->offset = (_ofs);        \
   (fr)->datalen = (_datalen);      \
   }
Set the various field of a frame to point to a buffer. Typically you set the base address of the buffer, the offset as AST_FRIENDLY_OFFSET, and the datalen as the amount of bytes queued. The remaining things (to be done manually) is set the number of samples, which cannot be derived from the datalen unless you know the number of bits per sample.

Definition at line 170 of file frame.h.

#define AST_FRIENDLY_OFFSET   64
 

Definition at line 181 of file frame.h.

Referenced by __get_from_jb(), alsa_read(), ast_frdup(), ast_frisolate(), ast_prod(), ast_rtcp_read(), ast_rtp_read(), ast_smoother_read(), ast_trans_frameout(), ast_udptl_read(), iax_frame_wrap(), jb_get_and_deliver(), linear_generator(), moh_generate(), mohalloc(), newpvt(), oss_read(), phone_read(), process_rfc3389(), and zt_read().

#define AST_HTML_BEGIN   4
 

Beginning frame

Definition at line 205 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_DATA   2
 

Data frame

Definition at line 203 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_END   8
 

End frame

Definition at line 207 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_LDCOMPLETE   16
 

Load is complete

Definition at line 209 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_LINKREJECT   20
 

Reject link request

Definition at line 217 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_LINKURL   18
 

Send URL, and track

Definition at line 213 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_NOSUPPORT   17
 

Peer is unable to support HTML

Definition at line 211 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_UNLINK   19
 

No more HTML linkage

Definition at line 215 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_URL   1
 

Sending a URL

Definition at line 201 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 189 of file frame.h.

Referenced by ast_frame_free(), and ast_frisolate().

#define AST_MALLOCD_HDR   (1 << 0)
 

Need the header be free'd?

Definition at line 187 of file frame.h.

Referenced by ast_frame_free(), ast_frame_header_new(), ast_frdup(), and ast_frisolate().

#define AST_MALLOCD_SRC   (1 << 2)
 

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

Definition at line 191 of file frame.h.

Referenced by ast_frame_free(), and ast_frisolate().

#define AST_MIN_OFFSET   32
 

Definition at line 184 of file frame.h.

Referenced by __ast_smoother_feed().

#define AST_MODEM_T38   1
 

T.38 Fax-over-IP

Definition at line 195 of file frame.h.

Referenced by ast_frame_dump(), and udptl_rx_packet().

#define AST_MODEM_V150   2
 

V.150 Modem-over-IP

Definition at line 197 of file frame.h.

Referenced by ast_frame_dump().

#define AST_OPTION_AUDIO_MODE   4
 

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

Definition at line 316 of file frame.h.

Referenced by zt_hangup(), and zt_setoption().

#define AST_OPTION_ECHOCAN   8
 

Explicitly enable or disable echo cancelation for the given channel

Definition at line 338 of file frame.h.

Referenced by zt_setoption().

#define AST_OPTION_FLAG_ACCEPT   1
 

Definition at line 299 of file frame.h.

#define AST_OPTION_FLAG_ANSWER   5
 

Definition at line 302 of file frame.h.

#define AST_OPTION_FLAG_QUERY   4
 

Definition at line 301 of file frame.h.

#define AST_OPTION_FLAG_REJECT   2
 

Definition at line 300 of file frame.h.

#define AST_OPTION_FLAG_REQUEST   0
 

Definition at line 298 of file frame.h.

Referenced by ast_bridge_call(), and iax2_setoption().

#define AST_OPTION_FLAG_WTF   6
 

Definition at line 303 of file frame.h.

#define AST_OPTION_OPRMODE   7
 

Definition at line 335 of file frame.h.

Referenced by zt_setoption().

#define AST_OPTION_RELAXDTMF   3
 

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

Definition at line 313 of file frame.h.

Referenced by 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 332 of file frame.h.

Referenced by iax2_setoption(), and zt_setoption().

#define AST_OPTION_TDD   2
 

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

Definition at line 310 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 307 of file frame.h.

Referenced by 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 324 of file frame.h.

Referenced by iax2_setoption(), and zt_setoption().

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

Definition at line 486 of file frame.h.

Referenced by ast_rtp_write().

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

Definition at line 488 of file frame.h.

Referenced by ast_rtp_write().

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

Definition at line 489 of file frame.h.

#define AST_SMOOTHER_FLAG_BE   (1 << 1)
 

Definition at line 295 of file frame.h.

Referenced by ast_rtp_write().

#define AST_SMOOTHER_FLAG_G729   (1 << 0)
 

Definition at line 294 of file frame.h.

Referenced by __ast_smoother_feed(), and ast_smoother_read().


Enumeration Type Documentation

enum ast_control_frame_type
 

Enumerator:
AST_CONTROL_HANGUP  Other end has hungup
AST_CONTROL_RING  Local ring
AST_CONTROL_RINGING  Remote end is ringing
AST_CONTROL_ANSWER  Remote end has answered
AST_CONTROL_BUSY  Remote end is busy
AST_CONTROL_TAKEOFFHOOK  Make it go off hook
AST_CONTROL_OFFHOOK  Line is off hook
AST_CONTROL_CONGESTION  Congestion (circuits busy)
AST_CONTROL_FLASH  Flash hook
AST_CONTROL_WINK  Wink
AST_CONTROL_OPTION  Set a low-level option
AST_CONTROL_RADIO_KEY  Key Radio
AST_CONTROL_RADIO_UNKEY  Un-Key Radio
AST_CONTROL_PROGRESS  Indicate PROGRESS
AST_CONTROL_PROCEEDING  Indicate CALL PROCEEDING
AST_CONTROL_HOLD  Indicate call is placed on hold
AST_CONTROL_UNHOLD  Indicate call is left from hold
AST_CONTROL_VIDUPDATE  Indicate video frame update

Definition at line 273 of file frame.h.

00273                             {
00274    AST_CONTROL_HANGUP = 1,    /*!< Other end has hungup */
00275    AST_CONTROL_RING = 2,      /*!< Local ring */
00276    AST_CONTROL_RINGING = 3,   /*!< Remote end is ringing */
00277    AST_CONTROL_ANSWER = 4,    /*!< Remote end has answered */
00278    AST_CONTROL_BUSY = 5,      /*!< Remote end is busy */
00279    AST_CONTROL_TAKEOFFHOOK = 6,  /*!< Make it go off hook */
00280    AST_CONTROL_OFFHOOK = 7,   /*!< Line is off hook */
00281    AST_CONTROL_CONGESTION = 8,   /*!< Congestion (circuits busy) */
00282    AST_CONTROL_FLASH = 9,     /*!< Flash hook */
00283    AST_CONTROL_WINK = 10,     /*!< Wink */
00284    AST_CONTROL_OPTION = 11,   /*!< Set a low-level option */
00285    AST_CONTROL_RADIO_KEY = 12,   /*!< Key Radio */
00286    AST_CONTROL_RADIO_UNKEY = 13, /*!< Un-Key Radio */
00287    AST_CONTROL_PROGRESS = 14, /*!< Indicate PROGRESS */
00288    AST_CONTROL_PROCEEDING = 15,  /*!< Indicate CALL PROCEEDING */
00289    AST_CONTROL_HOLD = 16,     /*!< Indicate call is placed on hold */
00290    AST_CONTROL_UNHOLD = 17,   /*!< Indicate call is left from hold */
00291    AST_CONTROL_VIDUPDATE = 18,   /*!< Indicate video frame update */
00292 };

enum ast_frame_type
 

Frame types.

Note:
It is important that the values of each frame type are never changed, because it will break backwards compatability with older versions. This is because these constants are transmitted directly over IAX2.
Enumerator:
AST_FRAME_DTMF_END  DTMF end event, subclass is the digit
AST_FRAME_VOICE  Voice data, subclass is AST_FORMAT_*
AST_FRAME_VIDEO  Video frame, maybe?? :)
AST_FRAME_CONTROL  A control frame, subclass is AST_CONTROL_*
AST_FRAME_NULL  An empty, useless frame
AST_FRAME_IAX  Inter Asterisk Exchange private frame type
AST_FRAME_TEXT  Text messages
AST_FRAME_IMAGE  Image Frames
AST_FRAME_HTML  HTML Frame
AST_FRAME_CNG  Comfort Noise frame (subclass is level of CNG in -dBov), body may include zero or more 8-bit quantization coefficients
AST_FRAME_MODEM  Modem-over-IP data streams
AST_FRAME_DTMF_BEGIN  DTMF begin event, subclass is the digit

Definition at line 98 of file frame.h.

00098                     {
00099    /*! DTMF end event, subclass is the digit */
00100    AST_FRAME_DTMF_END = 1,
00101    /*! Voice data, subclass is AST_FORMAT_* */
00102    AST_FRAME_VOICE,
00103    /*! Video frame, maybe?? :) */
00104    AST_FRAME_VIDEO,
00105    /*! A control frame, subclass is AST_CONTROL_* */
00106    AST_FRAME_CONTROL,
00107    /*! An empty, useless frame */
00108    AST_FRAME_NULL,
00109    /*! Inter Asterisk Exchange private frame type */
00110    AST_FRAME_IAX,
00111    /*! Text messages */
00112    AST_FRAME_TEXT,
00113    /*! Image Frames */
00114    AST_FRAME_IMAGE,
00115    /*! HTML Frame */
00116    AST_FRAME_HTML,
00117    /*! Comfort Noise frame (subclass is level of CNG in -dBov), 
00118        body may include zero or more 8-bit quantization coefficients */
00119    AST_FRAME_CNG,
00120    /*! Modem-over-IP data streams */
00121    AST_FRAME_MODEM,  
00122    /*! DTMF begin event, subclass is the digit */
00123    AST_FRAME_DTMF_BEGIN,
00124 };


Function Documentation

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

Definition at line 175 of file frame.c.

References AST_FRAME_VOICE, ast_log(), AST_MIN_OFFSET, AST_SMOOTHER_FLAG_G729, ast_swapcopy_samples(), ast_frame::data, ast_frame::datalen, ast_frame::delivery, ast_smoother::f, ast_frame::frametype, LOG_NOTICE, LOG_WARNING, ast_frame::offset, s, ast_frame::samples, SMOOTHER_SIZE, and ast_frame::subclass.

00176 {
00177    if (f->frametype != AST_FRAME_VOICE) {
00178       ast_log(LOG_WARNING, "Huh?  Can't smooth a non-voice frame!\n");
00179       return -1;
00180    }
00181    if (!s->format) {
00182       s->format = f->subclass;
00183       s->samplesperbyte = (float)f->samples / (float)f->datalen;
00184    } else if (s->format != f->subclass) {
00185       ast_log(LOG_WARNING, "Smoother was working on %d format frames, now trying to feed %d?\n", s->format, f->subclass);
00186       return -1;
00187    }
00188    if (s->len + f->datalen > SMOOTHER_SIZE) {
00189       ast_log(LOG_WARNING, "Out of smoother space\n");
00190       return -1;
00191    }
00192    if (((f->datalen == s->size) || ((f->datalen < 10) && (s->flags & AST_SMOOTHER_FLAG_G729)))
00193              && !s->opt && (f->offset >= AST_MIN_OFFSET)) {
00194       if (!s->len) {
00195          /* Optimize by sending the frame we just got
00196             on the next read, thus eliminating the douple
00197             copy */
00198          if (swap)
00199             ast_swapcopy_samples(f->data, f->data, f->samples);
00200          s->opt = f;
00201          return 0;
00202       } else {
00203          s->optimizablestream++;
00204          if (s->optimizablestream > 10) {
00205             /* For the past 10 rounds, we have input and output
00206                frames of the correct size for this smoother, yet
00207                we were unable to optimize because there was still
00208                some cruft left over.  Lets just drop the cruft so
00209                we can move to a fully optimized path */
00210             if (swap)
00211                ast_swapcopy_samples(f->data, f->data, f->samples);
00212             s->len = 0;
00213             s->opt = f;
00214             return 0;
00215          }
00216       }
00217    } else 
00218       s->optimizablestream = 0;
00219    if (s->flags & AST_SMOOTHER_FLAG_G729) {
00220       if (s->len % 10) {
00221          ast_log(LOG_NOTICE, "Dropping extra frame of G.729 since we already have a VAD frame at the end\n");
00222          return 0;
00223       }
00224    }
00225    if (swap)
00226       ast_swapcopy_samples(s->data+s->len, f->data, f->samples);
00227    else
00228       memcpy(s->data + s->len, f->data, f->datalen);
00229    /* If either side is empty, reset the delivery time */
00230    if (!s->len || ast_tvzero(f->delivery) || ast_tvzero(s->delivery))   /* XXX really ? */
00231       s->delivery = f->delivery;
00232    s->len += f->datalen;
00233    return 0;
00234 }

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 610 of file frame.c.

References AST_FORMAT_LIST, and desc.

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

00611 {
00612    int x;
00613    char *ret = "unknown";
00614    for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
00615       if (AST_FORMAT_LIST[x].visible && AST_FORMAT_LIST[x].bits == codec) {
00616          ret = AST_FORMAT_LIST[x].desc;
00617          break;
00618       }
00619    }
00620    return ret;
00621 }

int ast_codec_choose struct ast_codec_pref pref,
int  formats,
int  find_best
 

Select the best audio 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 1139 of file frame.c.

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

Referenced by __oh323_new(), gtalk_new(), jingle_new(), sip_new(), and socket_process().

01140 {
01141    int x, ret = 0, slot;
01142 
01143    for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
01144       slot = pref->order[x];
01145 
01146       if (!slot)
01147          break;
01148       if (formats & AST_FORMAT_LIST[slot-1].bits) {
01149          ret = AST_FORMAT_LIST[slot-1].bits;
01150          break;
01151       }
01152    }
01153    if (ret & AST_FORMAT_AUDIO_MASK)
01154       return ret;
01155 
01156    if (option_debug > 3)
01157       ast_log(LOG_DEBUG, "Could not find preferred codec - %s\n", find_best ? "Going for the best codec" : "Returning zero codec");
01158 
01159       return find_best ? ast_best_codec(formats) : 0;
01160 }

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 1404 of file frame.c.

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

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

01405 {
01406    int len = 0;
01407 
01408    /* XXX Still need speex, g723, and lpc10 XXX */ 
01409    switch(format) {
01410    case AST_FORMAT_G723_1:
01411       len = (samples / 240) * 20;
01412       break;
01413    case AST_FORMAT_ILBC:
01414       len = (samples / 240) * 50;
01415       break;
01416    case AST_FORMAT_GSM:
01417       len = (samples / 160) * 33;
01418       break;
01419    case AST_FORMAT_G729A:
01420       len = samples / 8;
01421       break;
01422    case AST_FORMAT_SLINEAR:
01423       len = samples * 2;
01424       break;
01425    case AST_FORMAT_ULAW:
01426    case AST_FORMAT_ALAW:
01427       len = samples;
01428       break;
01429    case AST_FORMAT_ADPCM:
01430    case AST_FORMAT_G726:
01431    case AST_FORMAT_G726_AAL2:
01432       len = samples / 2;
01433       break;
01434    default:
01435       ast_log(LOG_WARNING, "Unable to calculate sample length for format %s\n", ast_getformatname(format));
01436    }
01437 
01438    return len;
01439 }

int ast_codec_get_samples struct ast_frame f  ) 
 

Returns the number of samples contained in the frame.

Definition at line 1361 of file frame.c.

References AST_FORMAT_ADPCM, AST_FORMAT_ALAW, AST_FORMAT_G722, AST_FORMAT_G723_1, AST_FORMAT_G726, AST_FORMAT_G726_AAL2, 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(), socket_process(), and socket_process_meta().

01362 {
01363    int samples=0;
01364    switch(f->subclass) {
01365    case AST_FORMAT_SPEEX:
01366       samples = speex_samples(f->data, f->datalen);
01367       break;
01368    case AST_FORMAT_G723_1:
01369                 samples = g723_samples(f->data, f->datalen);
01370       break;
01371    case AST_FORMAT_ILBC:
01372       samples = 240 * (f->datalen / 50);
01373       break;
01374    case AST_FORMAT_GSM:
01375       samples = 160 * (f->datalen / 33);
01376       break;
01377    case AST_FORMAT_G729A:
01378       samples = f->datalen * 8;
01379       break;
01380    case AST_FORMAT_SLINEAR:
01381       samples = f->datalen / 2;
01382       break;
01383    case AST_FORMAT_LPC10:
01384                 /* assumes that the RTP packet contains one LPC10 frame */
01385       samples = 22 * 8;
01386       samples += (((char *)(f->data))[7] & 0x1) * 8;
01387       break;
01388    case AST_FORMAT_ULAW:
01389    case AST_FORMAT_ALAW:
01390    case AST_FORMAT_G722:
01391       samples = f->datalen;
01392       break;
01393    case AST_FORMAT_ADPCM:
01394    case AST_FORMAT_G726:
01395    case AST_FORMAT_G726_AAL2:
01396       samples = f->datalen * 2;
01397       break;
01398    default:
01399       ast_log(LOG_WARNING, "Unable to calculate samples for format %s\n", ast_getformatname(f->subclass));
01400    }
01401    return samples;
01402 }

static int ast_codec_interp_len int  format  )  [inline, static]
 

Gets duration in ms of interpolation frame for a format.

Definition at line 560 of file frame.h.

References AST_FORMAT_ILBC.

Referenced by __get_from_jb(), and jb_get_and_deliver().

00561 { 
00562    return (format == AST_FORMAT_ILBC) ? 30 : 20;
00563 }

int ast_codec_pref_append struct ast_codec_pref pref,
int  format
 

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

Definition at line 1034 of file frame.c.

References ast_codec_pref_remove(), and AST_FORMAT_LIST.

Referenced by ast_parse_allow_disallow().

01035 {
01036    int x, newindex = -1;
01037 
01038    ast_codec_pref_remove(pref, format);
01039 
01040    for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
01041       if (AST_FORMAT_LIST[x].bits == format) {
01042          newindex = x + 1;
01043          break;
01044       }
01045    }
01046 
01047    if (newindex) {
01048       for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
01049          if (!pref->order[x]) {
01050             pref->order[x] = newindex;
01051             break;
01052          }
01053       }
01054    }
01055 
01056    return x;
01057 }

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

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

Definition at line 936 of file frame.c.

References ast_codec_pref::order.

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

00937 {
00938    int x, differential = (int) 'A', mem;
00939    char *from, *to;
00940 
00941    if (right) {
00942       from = pref->order;
00943       to = buf;
00944       mem = size;
00945    } else {
00946       to = pref->order;
00947       from = buf;
00948       mem = 32;
00949    }
00950 
00951    memset(to, 0, mem);
00952    for (x = 0; x < 32 ; x++) {
00953       if (!from[x])
00954          break;
00955       to[x] = right ? (from[x] + differential) : (from[x] - differential);
00956    }
00957 }

struct ast_format_list ast_codec_pref_getsize struct ast_codec_pref pref,
int  format
 

Get packet size for codec.

Definition at line 1100 of file frame.c.

Referenced by add_codec_to_sdp(), ast_rtp_write(), handle_open_receive_channel_ack_message(), and transmit_connect().

01101 {
01102    int x, index = -1, framems = 0;
01103    struct ast_format_list fmt = { 0, };
01104 
01105    for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
01106       if (AST_FORMAT_LIST[x].bits == format) {
01107          fmt = AST_FORMAT_LIST[x];
01108          index = x;
01109          break;
01110       }
01111    }
01112 
01113    for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
01114       if (pref->order[x] == (index + 1)) {
01115          framems = pref->framing[x];
01116          break;
01117       }
01118    }
01119 
01120    /* size validation */
01121    if (!framems)
01122       framems = AST_FORMAT_LIST[index].def_ms;
01123 
01124    if (AST_FORMAT_LIST[index].inc_ms && framems % AST_FORMAT_LIST[index].inc_ms) /* avoid division by zero */
01125       framems -= framems % AST_FORMAT_LIST[index].inc_ms;
01126 
01127    if (framems < AST_FORMAT_LIST[index].min_ms)
01128       framems = AST_FORMAT_LIST[index].min_ms;
01129 
01130    if (framems > AST_FORMAT_LIST[index].max_ms)
01131       framems = AST_FORMAT_LIST[index].max_ms;
01132 
01133    fmt.cur_ms = framems;
01134 
01135    return fmt;
01136 }

int ast_codec_pref_index struct ast_codec_pref pref,
int  index
 

Codec located at a particular place in the preference index See Audio Codec Preferences.

Definition at line 994 of file frame.c.

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

Referenced by _sip_show_device(), add_sdp(), ast_codec_pref_string(), function_iaxpeer(), function_sippeer(), gtalk_invite(), iax2_show_peer(), jingle_accept_call(), print_codec_to_cli(), and socket_process().

00995 {
00996    int slot = 0;
00997 
00998    
00999    if ((index >= 0) && (index < sizeof(pref->order))) {
01000       slot = pref->order[index];
01001    }
01002 
01003    return slot ? AST_FORMAT_LIST[slot-1].bits : 0;
01004 }

void ast_codec_pref_init struct ast_codec_pref pref  ) 
 

Initialize an audio codec preference to "no preference" See Audio Codec Preferences.

void ast_codec_pref_remove struct ast_codec_pref pref,
int  format
 

Remove audio a codec from a preference list.

Definition at line 1007 of file frame.c.

References AST_FORMAT_LIST, and ast_codec_pref::order.

Referenced by ast_codec_pref_append(), and ast_parse_allow_disallow().

01008 {
01009    struct ast_codec_pref oldorder;
01010    int x, y = 0;
01011    int slot;
01012    int size;
01013 
01014    if (!pref->order[0])
01015       return;
01016 
01017    memcpy(&oldorder, pref, sizeof(oldorder));
01018    memset(pref, 0, sizeof(*pref));
01019 
01020    for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
01021       slot = oldorder.order[x];
01022       size = oldorder.framing[x];
01023       if (! slot)
01024          break;
01025       if (AST_FORMAT_LIST[slot-1].bits != format) {
01026          pref->order[y] = slot;
01027          pref->framing[y++] = size;
01028       }
01029    }
01030    
01031 }

int ast_codec_pref_setsize struct ast_codec_pref pref,
int  format,
int  framems
 

Set packet size for codec.

Definition at line 1061 of file frame.c.

References AST_FORMAT_LIST.

Referenced by ast_parse_allow_disallow().

01062 {
01063    int x, index = -1;
01064 
01065    for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
01066       if (AST_FORMAT_LIST[x].bits == format) {
01067          index = x;
01068          break;
01069       }
01070    }
01071 
01072    if (index < 0)
01073       return -1;
01074 
01075    /* size validation */
01076    if (!framems)
01077       framems = AST_FORMAT_LIST[index].def_ms;
01078 
01079    if (AST_FORMAT_LIST[index].inc_ms && framems % AST_FORMAT_LIST[index].inc_ms) /* avoid division by zero */
01080       framems -= framems % AST_FORMAT_LIST[index].inc_ms;
01081 
01082    if (framems < AST_FORMAT_LIST[index].min_ms)
01083       framems = AST_FORMAT_LIST[index].min_ms;
01084 
01085    if (framems > AST_FORMAT_LIST[index].max_ms)
01086       framems = AST_FORMAT_LIST[index].max_ms;
01087 
01088 
01089    for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
01090       if (pref->order[x] == (index + 1)) {
01091          pref->framing[x] = framems;
01092          break;
01093       }
01094    }
01095 
01096    return x;
01097 }

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

Dump audio codec preference list into a string.

Definition at line 959 of file frame.c.

References ast_codec_pref_index(), and ast_getformatname().

Referenced by dump_prefs(), and socket_process().

00960 {
00961    int x, codec; 
00962    size_t total_len, slen;
00963    char *formatname;
00964    
00965    memset(buf,0,size);
00966    total_len = size;
00967    buf[0] = '(';
00968    total_len--;
00969    for(x = 0; x < 32 ; x++) {
00970       if (total_len <= 0)
00971          break;
00972       if (!(codec = ast_codec_pref_index(pref,x)))
00973          break;
00974       if ((formatname = ast_getformatname(codec))) {
00975          slen = strlen(formatname);
00976          if (slen > total_len)
00977             break;
00978          strncat(buf,formatname,total_len);
00979          total_len -= slen;
00980       }
00981       if (total_len && x < 31 && ast_codec_pref_index(pref , x + 1)) {
00982          strncat(buf,"|",total_len);
00983          total_len--;
00984       }
00985    }
00986    if (total_len) {
00987       strncat(buf,")",total_len);
00988       total_len--;
00989    }
00990 
00991    return size - total_len;
00992 }

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 1441 of file frame.c.

References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, 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 ast_write().

01442 {
01443    int count;
01444    short *fdata = f->data;
01445    short adjust_value = abs(adjustment);
01446 
01447    if ((f->frametype != AST_FRAME_VOICE) || (f->subclass != AST_FORMAT_SLINEAR))
01448       return -1;
01449 
01450    if (!adjustment)
01451       return 0;
01452 
01453    for (count = 0; count < f->samples; count++) {
01454       if (adjustment > 0) {
01455          ast_slinear_saturated_multiply(&fdata[count], &adjust_value);
01456       } else if (adjustment < 0) {
01457          ast_slinear_saturated_divide(&fdata[count], &adjust_value);
01458       }
01459    }
01460 
01461    return 0;
01462 }

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

Dump a frame for debugging purposes

Definition at line 698 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_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, 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_MODEM_T38, AST_MODEM_V150, 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().

00699 {
00700    const char noname[] = "unknown";
00701    char ftype[40] = "Unknown Frametype";
00702    char cft[80];
00703    char subclass[40] = "Unknown Subclass";
00704    char csub[80];
00705    char moreinfo[40] = "";
00706    char cn[60];
00707    char cp[40];
00708    char cmn[40];
00709 
00710    if (!name)
00711       name = noname;
00712 
00713 
00714    if (!f) {
00715       ast_verbose("%s [ %s (NULL) ] [%s]\n", 
00716          term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
00717          term_color(cft, "HANGUP", COLOR_BRRED, COLOR_BLACK, sizeof(cft)), 
00718          term_color(cn, name, COLOR_YELLOW, COLOR_BLACK, sizeof(cn)));
00719       return;
00720    }
00721    /* XXX We should probably print one each of voice and video when the format changes XXX */
00722    if (f->frametype == AST_FRAME_VOICE)
00723       return;
00724    if (f->frametype == AST_FRAME_VIDEO)
00725       return;
00726    switch(f->frametype) {
00727    case AST_FRAME_DTMF_BEGIN:
00728       strcpy(ftype, "DTMF Begin");
00729       subclass[0] = f->subclass;
00730       subclass[1] = '\0';
00731       break;
00732    case AST_FRAME_DTMF_END:
00733       strcpy(ftype, "DTMF End");
00734       subclass[0] = f->subclass;
00735       subclass[1] = '\0';
00736       break;
00737    case AST_FRAME_CONTROL:
00738       strcpy(ftype, "Control");
00739       switch(f->subclass) {
00740       case AST_CONTROL_HANGUP:
00741          strcpy(subclass, "Hangup");
00742          break;
00743       case AST_CONTROL_RING:
00744          strcpy(subclass, "Ring");
00745          break;
00746       case AST_CONTROL_RINGING:
00747          strcpy(subclass, "Ringing");
00748          break;
00749       case AST_CONTROL_ANSWER:
00750          strcpy(subclass, "Answer");
00751          break;
00752       case AST_CONTROL_BUSY:
00753          strcpy(subclass, "Busy");
00754          break;
00755       case AST_CONTROL_TAKEOFFHOOK:
00756          strcpy(subclass, "Take Off Hook");
00757          break;
00758       case AST_CONTROL_OFFHOOK:
00759          strcpy(subclass, "Line Off Hook");
00760          break;
00761       case AST_CONTROL_CONGESTION:
00762          strcpy(subclass, "Congestion");
00763          break;
00764       case AST_CONTROL_FLASH:
00765          strcpy(subclass, "Flash");
00766          break;
00767       case AST_CONTROL_WINK:
00768          strcpy(subclass, "Wink");
00769          break;
00770       case AST_CONTROL_OPTION:
00771          strcpy(subclass, "Option");
00772          break;
00773       case AST_CONTROL_RADIO_KEY:
00774          strcpy(subclass, "Key Radio");
00775          break;
00776       case AST_CONTROL_RADIO_UNKEY:
00777          strcpy(subclass, "Unkey Radio");
00778          break;
00779       case -1:
00780          strcpy(subclass, "Stop generators");
00781          break;
00782       default:
00783          snprintf(subclass, sizeof(subclass), "Unknown control '%d'", f->subclass);
00784       }
00785       break;
00786    case AST_FRAME_NULL:
00787       strcpy(ftype, "Null Frame");
00788       strcpy(subclass, "N/A");
00789       break;
00790    case AST_FRAME_IAX:
00791       /* Should never happen */
00792       strcpy(ftype, "IAX Specific");
00793       snprintf(subclass, sizeof(subclass), "IAX Frametype %d", f->subclass);
00794       break;
00795    case AST_FRAME_TEXT:
00796       strcpy(ftype, "Text");
00797       strcpy(subclass, "N/A");
00798       ast_copy_string(moreinfo, f->data, sizeof(moreinfo));
00799       break;
00800    case AST_FRAME_IMAGE:
00801       strcpy(ftype, "Image");
00802       snprintf(subclass, sizeof(subclass), "Image format %s\n", ast_getformatname(f->subclass));
00803       break;
00804    case AST_FRAME_HTML:
00805       strcpy(ftype, "HTML");
00806       switch(f->subclass) {
00807       case AST_HTML_URL:
00808          strcpy(subclass, "URL");
00809          ast_copy_string(moreinfo, f->data, sizeof(moreinfo));
00810          break;
00811       case AST_HTML_DATA:
00812          strcpy(subclass, "Data");
00813          break;
00814       case AST_HTML_BEGIN:
00815          strcpy(subclass, "Begin");
00816          break;
00817       case AST_HTML_END:
00818          strcpy(subclass, "End");
00819          break;
00820       case AST_HTML_LDCOMPLETE:
00821          strcpy(subclass, "Load Complete");
00822          break;
00823       case AST_HTML_NOSUPPORT:
00824          strcpy(subclass, "No Support");
00825          break;
00826       case AST_HTML_LINKURL:
00827          strcpy(subclass, "Link URL");
00828          ast_copy_string(moreinfo, f->data, sizeof(moreinfo));
00829          break;
00830       case AST_HTML_UNLINK:
00831          strcpy(subclass, "Unlink");
00832          break;
00833       case AST_HTML_LINKREJECT:
00834          strcpy(subclass, "Link Reject");
00835          break;
00836       default:
00837          snprintf(subclass, sizeof(subclass), "Unknown HTML frame '%d'\n", f->subclass);
00838          break;
00839       }
00840       break;
00841    case AST_FRAME_MODEM:
00842       strcpy(ftype, "Modem");
00843       switch (f->subclass) {
00844       case AST_MODEM_T38:
00845          strcpy(subclass, "T.38");
00846          break;
00847       case AST_MODEM_V150:
00848          strcpy(subclass, "V.150");
00849          break;
00850       default:
00851          snprintf(subclass, sizeof(subclass), "Unknown MODEM frame '%d'\n", f->subclass);
00852          break;
00853       }
00854       break;
00855    default:
00856       snprintf(ftype, sizeof(ftype), "Unknown Frametype '%d'", f->frametype);
00857    }
00858    if (!ast_strlen_zero(moreinfo))
00859       ast_verbose("%s [ TYPE: %s (%d) SUBCLASS: %s (%d) '%s' ] [%s]\n",  
00860              term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
00861              term_color(cft, ftype, COLOR_BRRED, COLOR_BLACK, sizeof(cft)),
00862              f->frametype, 
00863              term_color(csub, subclass, COLOR_BRCYAN, COLOR_BLACK, sizeof(csub)),
00864              f->subclass, 
00865              term_color(cmn, moreinfo, COLOR_BRGREEN, COLOR_BLACK, sizeof(cmn)),
00866              term_color(cn, name, COLOR_YELLOW, COLOR_BLACK, sizeof(cn)));
00867    else
00868       ast_verbose("%s [ TYPE: %s (%d) SUBCLASS: %s (%d) ] [%s]\n",  
00869              term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
00870              term_color(cft, ftype, COLOR_BRRED, COLOR_BLACK, sizeof(cft)),
00871              f->frametype, 
00872              term_color(csub, subclass, COLOR_BRCYAN, COLOR_BLACK, sizeof(csub)),
00873              f->subclass, 
00874              term_color(cn, name, COLOR_YELLOW, COLOR_BLACK, sizeof(cn)));
00875 }

struct ast_frame* ast_frame_enqueue struct ast_frame head,
struct ast_frame f,
int  maxlen,
int  dupe
 

Appends a frame to the end of a list of frames, truncating the maximum length of the list.

void ast_frame_free struct ast_frame fr,
int  cache
 

Requests a frame to be allocated Frees a frame.

Parameters:
fr Frame to free
cache Whether to consider this frame for frame caching

Definition at line 339 of file frame.c.

References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, AST_MALLOCD_DATA, AST_MALLOCD_HDR, AST_MALLOCD_SRC, ast_frame::data, FRAME_CACHE_MAX_SIZE, frames, free, ast_frame::mallocd, ast_frame::offset, and ast_frame::src.

Referenced by ast_frfree().

00340 {
00341    if (!fr->mallocd)
00342       return;
00343 
00344 #if !defined(LOW_MEMORY)
00345    if (cache && fr->mallocd == AST_MALLOCD_HDR) {
00346       /* Cool, only the header is malloc'd, let's just cache those for now 
00347        * to keep things simple... */
00348       struct ast_frame_cache *frames;
00349 
00350       if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames))) 
00351           && frames->size < FRAME_CACHE_MAX_SIZE) {
00352          AST_LIST_INSERT_HEAD(&frames->list, fr, frame_list);
00353          frames->size++;
00354          return;
00355       }
00356    }
00357 #endif
00358    
00359    if (fr->mallocd & AST_MALLOCD_DATA) {
00360       if (fr->data) 
00361          free(fr->data - fr->offset);
00362    }
00363    if (fr->mallocd & AST_MALLOCD_SRC) {
00364       if (fr->src)
00365          free((char *)fr->src);
00366    }
00367    if (fr->mallocd & AST_MALLOCD_HDR) {
00368 #ifdef TRACE_FRAMES
00369       AST_LIST_LOCK(&headerlist);
00370       headers--;
00371       AST_LIST_REMOVE(&headerlist, fr, frame_list);
00372       AST_LIST_UNLOCK(&headerlist);
00373 #endif         
00374       free(fr);
00375    }
00376 }

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 1464 of file frame.c.

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

Referenced by ast_channel_spy_read_frame(), and ast_write().

01465 {
01466    int count;
01467    short *data1, *data2;
01468 
01469    if ((f1->frametype != AST_FRAME_VOICE) || (f1->subclass != AST_FORMAT_SLINEAR))
01470       return -1;
01471 
01472    if ((f2->frametype != AST_FRAME_VOICE) || (f2->subclass != AST_FORMAT_SLINEAR))
01473       return -1;
01474 
01475    if (f1->samples != f2->samples)
01476       return -1;
01477 
01478    for (count = 0, data1 = f1->data, data2 = f2->data;
01479         count < f1->samples;
01480         count++, data1++, data2++)
01481       ast_slinear_saturated_add(data1, data2);
01482 
01483    return 0;
01484 }

struct ast_frame* ast_frdup const struct ast_frame fr  ) 
 

Copies a frame.

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

Definition at line 439 of file frame.c.

References ast_calloc_cache, AST_FRIENDLY_OFFSET, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_MALLOCD_HDR, ast_frame::data, ast_frame::datalen, ast_frame::delivery, frames, ast_frame::frametype, ast_frame::has_timing_info, ast_frame::len, len, ast_frame::mallocd, ast_frame::mallocd_hdr_len, ast_frame::offset, ast_frame::samples, ast_frame::seqno, ast_frame::src, ast_frame::subclass, and ast_frame::ts.

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

00440 {
00441    struct ast_frame *out = NULL;
00442    int len, srclen = 0;
00443    void *buf = NULL;
00444 
00445 #if !defined(LOW_MEMORY)
00446    struct ast_frame_cache *frames;
00447 #endif
00448 
00449    /* Start with standard stuff */
00450    len = sizeof(*out) + AST_FRIENDLY_OFFSET + f->datalen;
00451    /* If we have a source, add space for it */
00452    /*
00453     * XXX Watch out here - if we receive a src which is not terminated
00454     * properly, we can be easily attacked. Should limit the size we deal with.
00455     */
00456    if (f->src)
00457       srclen = strlen(f->src);
00458    if (srclen > 0)
00459       len += srclen + 1;
00460    
00461 #if !defined(LOW_MEMORY)
00462    if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames)))) {
00463       AST_LIST_TRAVERSE_SAFE_BEGIN(&frames->list, out, frame_list) {
00464          if (out->mallocd_hdr_len >= len) {
00465             size_t mallocd_len = out->mallocd_hdr_len;
00466             AST_LIST_REMOVE_CURRENT(&frames->list, frame_list);
00467             memset(out, 0, sizeof(*out));
00468             out->mallocd_hdr_len = mallocd_len;
00469             buf = out;
00470             frames->size--;
00471             break;
00472          }
00473       }
00474       AST_LIST_TRAVERSE_SAFE_END
00475    }
00476 #endif
00477 
00478    if (!buf) {
00479       if (!(buf = ast_calloc_cache(1, len)))
00480          return NULL;
00481       out = buf;
00482       out->mallocd_hdr_len = len;
00483    }
00484 
00485    out->frametype = f->frametype;
00486    out->subclass = f->subclass;
00487    out->datalen = f->datalen;
00488    out->samples = f->samples;
00489    out->delivery = f->delivery;
00490    /* Set us as having malloc'd header only, so it will eventually
00491       get freed. */
00492    out->mallocd = AST_MALLOCD_HDR;
00493    out->offset = AST_FRIENDLY_OFFSET;
00494    if (out->datalen) {
00495       out->data = buf + sizeof(*out) + AST_FRIENDLY_OFFSET;
00496       memcpy(out->data, f->data, out->datalen); 
00497    }
00498    if (srclen > 0) {
00499       out->src = buf + sizeof(*out) + AST_FRIENDLY_OFFSET + f->datalen;
00500       /* Must have space since we allocated for it */
00501       strcpy((char *)out->src, f->src);
00502    }
00503    out->has_timing_info = f->has_timing_info;
00504    out->ts = f->ts;
00505    out->len = f->len;
00506    out->seqno = f->seqno;
00507    return out;
00508 }

static void force_inline ast_frfree struct ast_frame fr  )  [static]
 

Definition at line 396 of file frame.h.

References ast_frame_free().

Referenced by __adsi_transmit_messages(), __ast_read(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), agent_read(), ast_bridge_call(), ast_channel_free(), ast_channel_spy_free(), ast_channel_spy_read_frame(), ast_dsp_process(), ast_feature_request_and_dial(), ast_jb_destroy(), ast_jb_put(), ast_masq_park_call(), ast_queue_frame(), ast_recvtext(), ast_rtp_write(), ast_safe_sleep_conditional(), ast_send_image(), ast_slinfactory_destroy(), ast_slinfactory_read(), ast_tonepair(), ast_waitfordigit_full(), ast_write(), async_wait(), autoservice_run(), bridge_p2p_loop(), builtin_atxfer(), calc_cost(), copy_data_from_queue(), create_jb(), do_parking_thread(), find_cache(), handle_invite_replaces(), handle_recordfile(), iax_park_thread(), jb_get_and_deliver(), moh_files_generator(), monitor_dial(), queue_frame_to_spies(), run_agi(), ss_thread(), wait_for_hangup(), waitstream_core(), and zt_bridge().

00397 {
00398    ast_frame_free(fr, 1);
00399 }

struct ast_frame* ast_frisolate struct ast_frame fr  ) 
 

Makes a frame independent of any static storage.

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 383 of file frame.c.

References ast_frame_header_new(), AST_FRIENDLY_OFFSET, ast_malloc, AST_MALLOCD_DATA, AST_MALLOCD_HDR, AST_MALLOCD_SRC, ast_strdup, ast_frame::data, ast_frame::datalen, ast_frame::frametype, free, ast_frame::has_timing_info, ast_frame::len, ast_frame::mallocd, ast_frame::offset, ast_frame::samples, ast_frame::seqno, ast_frame::src, ast_frame::subclass, and ast_frame::ts.

00384 {
00385    struct ast_frame *out;
00386    void *newdata;
00387    
00388    if (!(fr->mallocd & AST_MALLOCD_HDR)) {
00389       /* Allocate a new header if needed */
00390       if (!(out = ast_frame_header_new()))
00391          return NULL;
00392       out->frametype = fr->frametype;
00393       out->subclass = fr->subclass;
00394       out->datalen = fr->datalen;
00395       out->samples = fr->samples;
00396       out->offset = fr->offset;
00397       out->data = fr->data;
00398       /* Copy the timing data */
00399       out->has_timing_info = fr->has_timing_info;
00400       if (fr->has_timing_info) {
00401          out->ts = fr->ts;
00402          out->len = fr->len;
00403          out->seqno = fr->seqno;
00404       }
00405    } else
00406       out = fr;
00407    
00408    if (!(fr->mallocd & AST_MALLOCD_SRC)) {
00409       if (fr->src) {
00410          if (!(out->src = ast_strdup(fr->src))) {
00411             if (out != fr)
00412                free(out);
00413             return NULL;
00414          }
00415       }
00416    } else
00417       out->src = fr->src;
00418    
00419    if (!(fr->mallocd & AST_MALLOCD_DATA))  {
00420       if (!(newdata = ast_malloc(fr->datalen + AST_FRIENDLY_OFFSET))) {
00421          if (out->src != fr->src)
00422             free((void *) out->src);
00423          if (out != fr)
00424             free(out);
00425          return NULL;
00426       }
00427       newdata += AST_FRIENDLY_OFFSET;
00428       out->offset = AST_FRIENDLY_OFFSET;
00429       out->datalen = fr->datalen;
00430       memcpy(newdata, fr->data, fr->datalen);
00431       out->data = newdata;
00432    }
00433 
00434    out->mallocd = AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA;
00435    
00436    return out;
00437 }

struct ast_format_list* ast_get_format_list size_t *  size  ) 
 

Definition at line 526 of file frame.c.

References AST_FORMAT_LIST.

00527 {
00528    *size = (sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]));
00529    return AST_FORMAT_LIST;
00530 }

struct ast_format_list* ast_get_format_list_index int  index  ) 
 

Definition at line 521 of file frame.c.

References AST_FORMAT_LIST.

00522 {
00523    return &AST_FORMAT_LIST[index];
00524 }

int ast_getformatbyname const 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 592 of file frame.c.

References ast_expand_codec_alias(), AST_FORMAT_LIST, and format.

Referenced by ast_parse_allow_disallow(), iax_template_parse(), load_moh_classes(), reload_config(), and try_suggested_sip_codec().

00593 {
00594    int x, all, format = 0;
00595 
00596    all = strcasecmp(name, "all") ? 0 : 1;
00597    for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
00598       if (AST_FORMAT_LIST[x].visible && (all || 
00599            !strcasecmp(AST_FORMAT_LIST[x].name,name) ||
00600            !strcasecmp(AST_FORMAT_LIST[x].name,ast_expand_codec_alias(name)))) {
00601          format |= AST_FORMAT_LIST[x].bits;
00602          if (!all)
00603             break;
00604       }
00605    }
00606 
00607    return format;
00608 }

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 532 of file frame.c.

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

Referenced by __ast_read(), __ast_register_translator(), __login_exec(), __sip_show_channels(), _sip_show_device(), add_codec_to_answer(), 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_openvstream(), ast_rtp_write(), ast_slinfactory_feed(), ast_streamfile(), ast_translator_build_path(), ast_unregister_translator(), ast_writestream(), eagi_exec(), function_iaxpeer(), function_sippeer(), iax2_request(), iax2_show_peer(), iax_show_provisioning(), moh_classes_show(), moh_release(), oh323_rtp_read(), phone_setup(), print_codec_to_cli(), queue_frame_to_spies(), rebuild_matrix(), set_format(), set_peer_capabilities(), show_codecs(), show_file_formats(), show_image_formats(), show_translation(), sip_request_call(), socket_process(), and zt_read().

00533 {
00534    int x;
00535    char *ret = "unknown";
00536    for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
00537       if (AST_FORMAT_LIST[x].visible && AST_FORMAT_LIST[x].bits == format) {
00538          ret = AST_FORMAT_LIST[x].name;
00539          break;
00540       }
00541    }
00542    return ret;
00543 }

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 545 of file frame.c.

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

Referenced by _sip_show_device(), _sip_show_peer(), add_sdp(), ast_streamfile(), function_iaxpeer(), function_sippeer(), handle_showchan(), iax2_show_peer(), sip_new(), sip_request_call(), sip_show_channel(), sip_show_settings(), and sip_write().

00546 {
00547    int x;
00548    unsigned len;
00549    char *start, *end = buf;
00550 
00551    if (!size)
00552       return buf;
00553    snprintf(end, size, "0x%x (", format);
00554    len = strlen(end);
00555    end += len;
00556    size -= len;
00557    start = end;
00558    for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
00559       if (AST_FORMAT_LIST[x].visible && (AST_FORMAT_LIST[x].bits & format)) {
00560          snprintf(end, size,"%s|",AST_FORMAT_LIST[x].name);
00561          len = strlen(end);
00562          end += len;
00563          size -= len;
00564       }
00565    }
00566    if (start == end)
00567       snprintf(start, size, "nothing)");
00568    else if (size > 1)
00569       *(end -1) = ')';
00570    return buf;
00571 }

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

Parse an "allow" or "deny" line in a channel or device configuration and update the capabilities mask and pref if provided. Video codecs are not added to codec preference lists, since we can not transcode.

Returns:
Returns number of errors encountered during parsing

Definition at line 1162 of file frame.c.

References ast_codec_pref_append(), ast_codec_pref_remove(), ast_codec_pref_setsize(), ast_getformatbyname(), ast_log(), ast_strdupa, format, LOG_DEBUG, LOG_WARNING, option_debug, parse(), and strsep().

Referenced by build_device(), build_peer(), build_user(), gtalk_create_member(), gtalk_load_config(), jingle_create_member(), jingle_load_config(), reload_config(), set_config(), and update_common_options().

01163 {
01164    int errors = 0;
01165    char *parse = NULL, *this = NULL, *psize = NULL;
01166    int format = 0, framems = 0;
01167 
01168    parse = ast_strdupa(list);
01169    while ((this = strsep(&parse, ","))) {
01170       framems = 0;
01171       if ((psize = strrchr(this, ':'))) {
01172          *psize++ = '\0';
01173          if (option_debug)
01174             ast_log(LOG_DEBUG,"Packetization for codec: %s is %s\n", this, psize);
01175          framems = atoi(psize);
01176          if (framems < 0) {
01177             framems = 0;
01178             errors++;
01179             ast_log(LOG_WARNING, "Bad packetization value for codec %s\n", this);
01180          }
01181       }
01182       if (!(format = ast_getformatbyname(this))) {
01183          ast_log(LOG_WARNING, "Cannot %s unknown format '%s'\n", allowing ? "allow" : "disallow", this);
01184          errors++;
01185          continue;
01186       }
01187 
01188       if (mask) {
01189          if (allowing)
01190             *mask |= format;
01191          else
01192             *mask &= ~format;
01193       }
01194 
01195       /* Set up a preference list for audio. Do not include video in preferences 
01196          since we can not transcode video and have to use whatever is offered
01197        */
01198       if (pref && (format & AST_FORMAT_AUDIO_MASK)) {
01199          if (strcasecmp(this, "all")) {
01200             if (allowing) {
01201                ast_codec_pref_append(pref, format);
01202                ast_codec_pref_setsize(pref, format, framems);
01203             }
01204             else
01205                ast_codec_pref_remove(pref, format);
01206          } else if (!allowing) {
01207             memset(pref, 0, sizeof(*pref));
01208          }
01209       }
01210    }
01211    return errors;
01212 }

void ast_smoother_free struct ast_smoother s  ) 
 

Definition at line 286 of file frame.c.

References free, and s.

Referenced by ast_rtp_destroy(), and ast_rtp_write().

00287 {
00288    free(s);
00289 }

int ast_smoother_get_flags struct ast_smoother smoother  ) 
 

Definition at line 160 of file frame.c.

References s.

00161 {
00162    return s->flags;
00163 }

struct ast_smoother* ast_smoother_new int  bytes  ) 
 

Definition at line 150 of file frame.c.

References ast_malloc, ast_smoother_reset(), and s.

Referenced by ast_rtp_write().

00151 {
00152    struct ast_smoother *s;
00153    if (size < 1)
00154       return NULL;
00155    if ((s = ast_malloc(sizeof(*s))))
00156       ast_smoother_reset(s, size);
00157    return s;
00158 }

struct ast_frame* ast_smoother_read struct ast_smoother s  ) 
 

Definition at line 236 of file frame.c.

References AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), AST_SMOOTHER_FLAG_G729, ast_tvadd(), len, LOG_WARNING, and s.

Referenced by ast_rtp_write().

00237 {
00238    struct ast_frame *opt;
00239    int len;
00240 
00241    /* IF we have an optimization frame, send it */
00242    if (s->opt) {
00243       if (s->opt->offset < AST_FRIENDLY_OFFSET)
00244          ast_log(LOG_WARNING, "Returning a frame of inappropriate offset (%d).\n",
00245                      s->opt->offset);
00246       opt = s->opt;
00247       s->opt = NULL;
00248       return opt;
00249    }
00250 
00251    /* Make sure we have enough data */
00252    if (s->len < s->size) {
00253       /* Or, if this is a G.729 frame with VAD on it, send it immediately anyway */
00254       if (!((s->flags & AST_SMOOTHER_FLAG_G729) && (s->size % 10)))
00255          return NULL;
00256    }
00257    len = s->size;
00258    if (len > s->len)
00259       len = s->len;
00260    /* Make frame */
00261    s->f.frametype = AST_FRAME_VOICE;
00262    s->f.subclass = s->format;
00263    s->f.data = s->framedata + AST_FRIENDLY_OFFSET;
00264    s->f.offset = AST_FRIENDLY_OFFSET;
00265    s->f.datalen = len;
00266    /* Samples will be improper given VAD, but with VAD the concept really doesn't even exist */
00267    s->f.samples = len * s->samplesperbyte;   /* XXX rounding */
00268    s->f.delivery = s->delivery;
00269    /* Fill Data */
00270    memcpy(s->f.data, s->data, len);
00271    s->len -= len;
00272    /* Move remaining data to the front if applicable */
00273    if (s->len) {
00274       /* In principle this should all be fine because if we are sending
00275          G.729 VAD, the next timestamp will take over anyawy */
00276       memmove(s->data, s->data + len, s->len);
00277       if (!ast_tvzero(s->delivery)) {
00278          /* If we have delivery time, increment it, otherwise, leave it at 0 */
00279          s->delivery = ast_tvadd(s->delivery, ast_samp2tv(s->f.samples, 8000));
00280       }
00281    }
00282    /* Return frame */
00283    return &s->f;
00284 }

void ast_smoother_reset struct ast_smoother s,
int  bytes
 

Definition at line 144 of file frame.c.

References s.

Referenced by ast_smoother_new().

00145 {
00146    memset(s, 0, sizeof(*s));
00147    s->size = size;
00148 }

void ast_smoother_set_flags struct ast_smoother smoother,
int  flags
 

Definition at line 165 of file frame.c.

References s.

Referenced by ast_rtp_write().

00166 {
00167    s->flags = flags;
00168 }

int ast_smoother_test_flag struct ast_smoother s,
int  flag
 

Definition at line 170 of file frame.c.

References s.

Referenced by ast_rtp_write().

00171 {
00172    return (s->flags & flag);
00173 }

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

Definition at line 510 of file frame.c.

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

00511 {
00512    int i;
00513    unsigned short *dst_s = dst;
00514    const unsigned short *src_s = src;
00515 
00516    for (i = 0; i < samples; i++)
00517       dst_s[i] = (src_s[i]<<8) | (src_s[i]>>8);
00518 }


Variable Documentation

struct ast_frame ast_null_frame
 

Queueing a null frame is fairly common, so we declare a global null frame object for this purpose instead of having to declare one on the stack

Definition at line 142 of file frame.c.

Referenced by __ast_read(), __oh323_rtp_create(), __oh323_update_info(), agent_new(), agent_read(), ast_channel_masquerade(), ast_channel_setwhentohangup(), ast_rtcp_read(), ast_rtp_read(), ast_softhangup_nolock(), ast_udptl_read(), features_read(), gtalk_rtp_read(), handle_request_invite(), handle_response_answer(), handle_response_invite(), iax2_read(), jingle_rtp_read(), local_read(), mgcp_rtp_read(), oh323_read(), oh323_rtp_read(), send_dtmf(), sip_rtp_read(), and skinny_rtp_read().


Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen