Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

frame.h File Reference

#include <sys/types.h>
#include <sys/time.h>

Go to the source code of this file.

Defines

#define AST_FRIENDLY_OFFSET   64
#define AST_MIN_OFFSET   32
#define AST_MALLOCD_HDR   (1 << 0)
#define AST_MALLOCD_DATA   (1 << 1)
#define AST_MALLOCD_SRC   (1 << 2)
#define AST_FRAME_DTMF   1
#define AST_FRAME_VOICE   2
#define AST_FRAME_VIDEO   3
#define AST_FRAME_CONTROL   4
#define AST_FRAME_NULL   5
#define AST_FRAME_IAX   6
#define AST_FRAME_TEXT   7
#define AST_FRAME_IMAGE   8
#define AST_FRAME_HTML   9
#define AST_FRAME_CNG   10
#define AST_HTML_URL   1
#define AST_HTML_DATA   2
#define AST_HTML_BEGIN   4
#define AST_HTML_END   8
#define AST_HTML_LDCOMPLETE   16
#define AST_HTML_NOSUPPORT   17
#define AST_HTML_LINKURL   18
#define AST_HTML_UNLINK   19
#define AST_HTML_LINKREJECT   20
#define AST_FORMAT_G723_1   (1 << 0)
#define AST_FORMAT_GSM   (1 << 1)
#define AST_FORMAT_ULAW   (1 << 2)
#define AST_FORMAT_ALAW   (1 << 3)
#define AST_FORMAT_G726   (1 << 4)
#define AST_FORMAT_ADPCM   (1 << 5)
#define AST_FORMAT_SLINEAR   (1 << 6)
#define AST_FORMAT_LPC10   (1 << 7)
#define AST_FORMAT_G729A   (1 << 8)
#define AST_FORMAT_SPEEX   (1 << 9)
#define AST_FORMAT_ILBC   (1 << 10)
#define AST_FORMAT_MAX_AUDIO   (1 << 15)
#define AST_FORMAT_JPEG   (1 << 16)
#define AST_FORMAT_PNG   (1 << 17)
#define AST_FORMAT_H261   (1 << 18)
#define AST_FORMAT_H263   (1 << 19)
#define AST_FORMAT_MAX_VIDEO   (1 << 24)
#define AST_CONTROL_HANGUP   1
#define AST_CONTROL_RING   2
#define AST_CONTROL_RINGING   3
#define AST_CONTROL_ANSWER   4
#define AST_CONTROL_BUSY   5
#define AST_CONTROL_TAKEOFFHOOK   6
#define AST_CONTROL_OFFHOOK   7
#define AST_CONTROL_CONGESTION   8
#define AST_CONTROL_FLASH   9
#define AST_CONTROL_WINK   10
#define AST_CONTROL_OPTION   11
#define AST_CONTROL_RADIO_KEY   12
#define AST_CONTROL_RADIO_UNKEY   13
#define AST_CONTROL_PROGRESS   14
#define AST_CONTROL_PROCEEDING   15
#define AST_SMOOTHER_FLAG_G729   (1 << 0)
#define AST_OPTION_FLAG_REQUEST   0
#define AST_OPTION_FLAG_ACCEPT   1
#define AST_OPTION_FLAG_REJECT   2
#define AST_OPTION_FLAG_QUERY   4
#define AST_OPTION_FLAG_ANSWER   5
#define AST_OPTION_FLAG_WTF   6
#define AST_OPTION_TONE_VERIFY   1
#define AST_OPTION_TDD   2
#define AST_OPTION_RELAXDTMF   3
#define AST_OPTION_AUDIO_MODE   4

Functions

void ast_frfree (struct ast_frame *fr)
 Frees a frame.
ast_frameast_frisolate (struct ast_frame *fr)
 Copies a frame.
ast_frameast_frdup (struct ast_frame *fr)
 Copies a frame.
ast_frameast_fr_fdread (int fd)
 Reads a frame from an fd.
int ast_fr_fdwrite (int fd, struct ast_frame *frame)
 Writes a frame to an fd.
int ast_fr_fdhangup (int fd)
 Sends a hangup to an fd.
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_getformatbyname (char *name)
char * ast_codec2str (int codec)
 Get a name from a format.
int ast_best_codec (int fmts)
 Pick the best codec.
ast_format_listast_get_format_list_index (int index)
ast_format_listast_get_format_list (size_t *size)
ast_smootherast_smoother_new (int bytes)
void ast_smoother_set_flags (struct ast_smoother *smoother, int flags)
int ast_smoother_get_flags (struct ast_smoother *smoother)
void ast_smoother_free (struct ast_smoother *s)
void ast_smoother_reset (struct ast_smoother *s, int bytes)
int ast_smoother_feed (struct ast_smoother *s, struct ast_frame *f)
ast_frameast_smoother_read (struct ast_smoother *s)
void ast_frame_dump (char *name, struct ast_frame *f, char *prefix)
void ast_codec_pref_init (struct ast_codec_pref *pref)
int ast_codec_pref_index (struct ast_codec_pref *pref, int index)
void ast_codec_pref_remove (struct ast_codec_pref *pref, int format)
int ast_codec_pref_append (struct ast_codec_pref *pref, int format)
int ast_codec_choose (struct ast_codec_pref *pref, int formats, int find_best)
void ast_parse_allow_disallow (struct ast_codec_pref *pref, int *mask, char *list, int allowing)
int ast_codec_pref_string (struct ast_codec_pref *pref, char *buf, size_t size)
void ast_codec_pref_shift (struct ast_codec_pref *pref, char *buf, size_t size, int right)


Define Documentation

#define AST_CONTROL_ANSWER   4
 

Remote end has answered

Definition at line 202 of file frame.h.

Referenced by __ast_request_and_dial(), ast_dsp_process(), ast_frame_dump(), ast_read(), and ast_waitfordigit_full().

#define AST_CONTROL_BUSY   5
 

Remote end is busy

Definition at line 204 of file frame.h.

Referenced by __ast_request_and_dial(), ast_dsp_process(), ast_frame_dump(), and ast_indicate().

#define AST_CONTROL_CONGESTION   8
 

Congestion (circuits busy)

Definition at line 210 of file frame.h.

Referenced by __ast_request_and_dial(), ast_dsp_process(), ast_frame_dump(), and ast_indicate().

#define AST_CONTROL_FLASH   9
 

Flash hook

Definition at line 212 of file frame.h.

Referenced by ast_frame_dump().

#define AST_CONTROL_HANGUP   1
 

Other end has hungup

Definition at line 196 of file frame.h.

Referenced by __ast_request_and_dial(), ast_fr_fdhangup(), ast_fr_fdread(), ast_frame_dump(), ast_queue_frame(), ast_queue_hangup(), ast_read(), ast_recvchar(), and ast_waitfordigit_full().

#define AST_CONTROL_OFFHOOK   7
 

Line is off hook

Definition at line 208 of file frame.h.

Referenced by ast_frame_dump().

#define AST_CONTROL_OPTION   11
 

Set a low-level option

Definition at line 216 of file frame.h.

Referenced by ast_frame_dump().

#define AST_CONTROL_PROCEEDING   15
 

Indicate CALL PROCEEDING

Definition at line 224 of file frame.h.

Referenced by ast_indicate().

#define AST_CONTROL_PROGRESS   14
 

Indicate PROGRESS

Definition at line 222 of file frame.h.

Referenced by __ast_request_and_dial(), and ast_indicate().

#define AST_CONTROL_RADIO_KEY   12
 

Key Radio

Definition at line 218 of file frame.h.

Referenced by ast_frame_dump().

#define AST_CONTROL_RADIO_UNKEY   13
 

Un-Key Radio

Definition at line 220 of file frame.h.

Referenced by ast_frame_dump().

#define AST_CONTROL_RING   2
 

Local ring

Definition at line 198 of file frame.h.

Referenced by ast_frame_dump().

#define AST_CONTROL_RINGING   3
 

Remote end is ringing

Definition at line 200 of file frame.h.

Referenced by __ast_request_and_dial(), ast_dsp_process(), ast_frame_dump(), ast_indicate(), and ast_waitfordigit_full().

#define AST_CONTROL_TAKEOFFHOOK   6
 

Make it go off hook

Definition at line 206 of file frame.h.

Referenced by ast_frame_dump().

#define AST_CONTROL_WINK   10
 

Wink

Definition at line 214 of file frame.h.

Referenced by ast_frame_dump().

#define AST_FORMAT_ADPCM   (1 << 5)
 

ADPCM (IMA)

Definition at line 170 of file frame.h.

Referenced by ast_best_codec(), ast_rtp_read(), and ast_rtp_write().

#define AST_FORMAT_ALAW   (1 << 3)
 

Raw A-law data (G.711)

Definition at line 166 of file frame.h.

Referenced by ast_best_codec(), ast_dsp_process(), ast_rtp_read(), and ast_rtp_write().

#define AST_FORMAT_G723_1   (1 << 0)
 

G.723.1 compression

Definition at line 160 of file frame.h.

Referenced by ast_best_codec(), ast_rtp_read(), and ast_rtp_write().

#define AST_FORMAT_G726   (1 << 4)
 

ADPCM (G.726, 32kbps)

Definition at line 168 of file frame.h.

Referenced by ast_best_codec(), ast_rtp_read(), and ast_rtp_write().

#define AST_FORMAT_G729A   (1 << 8)
 

G.729A audio

Definition at line 176 of file frame.h.

Referenced by ast_best_codec(), ast_rtp_read(), and ast_rtp_write().

#define AST_FORMAT_GSM   (1 << 1)
 

GSM compression

Definition at line 162 of file frame.h.

Referenced by ast_best_codec(), ast_rtp_read(), and ast_rtp_write().

#define AST_FORMAT_H261   (1 << 18)
 

H.261 Video

Definition at line 188 of file frame.h.

Referenced by ast_rtp_write().

#define AST_FORMAT_H263   (1 << 19)
 

H.263 Video

Definition at line 190 of file frame.h.

Referenced by ast_rtp_write().

#define AST_FORMAT_ILBC   (1 << 10)
 

iLBC Free Compression

Definition at line 180 of file frame.h.

Referenced by ast_best_codec(), ast_rtp_read(), and ast_rtp_write().

#define AST_FORMAT_JPEG   (1 << 16)
 

JPEG Images

Definition at line 184 of file frame.h.

#define AST_FORMAT_LPC10   (1 << 7)
 

LPC10, 180 samples/frame

Definition at line 174 of file frame.h.

Referenced by ast_best_codec(), ast_rtp_read(), and ast_rtp_write().

#define AST_FORMAT_MAX_AUDIO   (1 << 15)
 

Maximum audio format

Definition at line 182 of file frame.h.

Referenced by ast_closestream(), ast_playstream(), ast_rtp_read(), and ast_writestream().

#define AST_FORMAT_MAX_VIDEO   (1 << 24)
 

Max one

Definition at line 192 of file frame.h.

#define AST_FORMAT_PNG   (1 << 17)
 

PNG Images

Definition at line 186 of file frame.h.

#define AST_FORMAT_SLINEAR   (1 << 6)
 

Raw 16-bit Signed Linear (8000 Hz) PCM

Definition at line 172 of file frame.h.

Referenced by ast_app_getvoice(), ast_best_codec(), ast_dsp_call_progress(), ast_dsp_digitdetect(), ast_dsp_process(), ast_dsp_silence(), ast_play_and_prepend(), ast_play_and_record(), and ast_rtp_read().

#define AST_FORMAT_SPEEX   (1 << 9)
 

SpeeX Free Compression

Definition at line 178 of file frame.h.

Referenced by ast_best_codec(), ast_rtp_read(), and ast_rtp_write().

#define AST_FORMAT_ULAW   (1 << 2)
 

Raw mu-law data (G.711)

Definition at line 164 of file frame.h.

Referenced by ast_best_codec(), ast_dsp_process(), ast_rtp_read(), and ast_rtp_write().

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

Referenced by ast_read().

#define AST_FRAME_CONTROL   4
 

A control frame, subclass is AST_CONTROL_*

Definition at line 123 of file frame.h.

Referenced by __ast_request_and_dial(), ast_channel_bridge(), ast_dsp_process(), ast_fr_fdhangup(), ast_fr_fdread(), ast_frame_dump(), ast_queue_control(), ast_queue_frame(), ast_queue_hangup(), ast_read(), ast_recvchar(), ast_waitfordigit_full(), and ast_write().

#define AST_FRAME_DTMF   1
 

A DTMF digit, subclass is the digit

Definition at line 117 of file frame.h.

Referenced by ast_app_getvoice(), ast_channel_bridge(), ast_dsp_process(), ast_dtmf_stream(), ast_frame_dump(), ast_play_and_prepend(), ast_play_and_record(), ast_read(), ast_rtp_bridge(), ast_waitfordigit(), ast_waitfordigit_full(), and ast_write().

#define AST_FRAME_HTML   9
 

HTML Frame

Definition at line 133 of file frame.h.

Referenced by ast_frame_dump().

#define AST_FRAME_IAX   6
 

Inter Asterisk Exchange private frame type

Definition at line 127 of file frame.h.

Referenced by ast_frame_dump().

#define AST_FRAME_IMAGE   8
 

Image Frames

Definition at line 131 of file frame.h.

Referenced by ast_channel_bridge(), and ast_frame_dump().

#define AST_FRAME_NULL   5
 

An empty, useless frame

Definition at line 125 of file frame.h.

Referenced by ast_channel_masquerade(), ast_channel_masquerade_locked(), ast_do_masquerade(), ast_dsp_process(), ast_frame_dump(), ast_read(), ast_rtcp_read(), ast_rtp_read(), and ast_softhangup_nolock().

#define AST_FRAME_TEXT   7
 

Text messages

Definition at line 129 of file frame.h.

Referenced by ast_channel_bridge(), ast_frame_dump(), ast_recvchar(), and ast_write().

#define AST_FRAME_VIDEO   3
 

Video frame, maybe?? :)

Definition at line 121 of file frame.h.

Referenced by ast_channel_bridge(), ast_frame_dump(), ast_play_and_prepend(), ast_play_and_record(), ast_rtp_bridge(), ast_rtp_read(), ast_rtp_write(), ast_write(), and ast_writestream().

#define AST_FRAME_VOICE   2
 

Voice data, subclass is AST_FORMAT_*

Definition at line 119 of file frame.h.

Referenced by ast_app_getvoice(), ast_channel_bridge(), ast_dsp_call_progress(), ast_dsp_digitdetect(), ast_dsp_process(), ast_dsp_silence(), ast_frame_dump(), ast_play_and_prepend(), ast_play_and_record(), ast_prod(), ast_queue_frame(), ast_read(), ast_rtp_bridge(), ast_rtp_read(), ast_rtp_write(), ast_smoother_feed(), ast_smoother_read(), ast_waitfordigit_full(), ast_waitstream_full(), ast_write(), and ast_writestream().

#define AST_FRIENDLY_OFFSET   64
 

Definition at line 103 of file frame.h.

Referenced by ast_frdup(), ast_frisolate(), ast_prod(), ast_rtp_read(), and ast_smoother_read().

#define AST_HTML_BEGIN   4
 

Beginning frame

Definition at line 144 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_DATA   2
 

Data frame

Definition at line 142 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_END   8
 

End frame

Definition at line 146 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_LDCOMPLETE   16
 

Load is complete

Definition at line 148 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_LINKREJECT   20
 

Reject link request

Definition at line 156 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_LINKURL   18
 

Send URL, and track

Definition at line 152 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_NOSUPPORT   17
 

Peer is unable to support HTML

Definition at line 150 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_UNLINK   19
 

No more HTML linkage

Definition at line 154 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_URL   1
 

Sending a URL

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

Referenced by ast_frfree(), and ast_frisolate().

#define AST_MALLOCD_HDR   (1 << 0)
 

Need the header be free'd?

Definition at line 109 of file frame.h.

Referenced by ast_frdup(), ast_frfree(), and ast_frisolate().

#define AST_MALLOCD_SRC   (1 << 2)
 

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

Definition at line 113 of file frame.h.

Referenced by ast_frfree(), and ast_frisolate().

#define AST_MIN_OFFSET   32
 

Definition at line 106 of file frame.h.

Referenced by ast_smoother_feed().

#define AST_OPTION_AUDIO_MODE   4
 

Definition at line 247 of file frame.h.

#define AST_OPTION_FLAG_ACCEPT   1
 

Definition at line 230 of file frame.h.

#define AST_OPTION_FLAG_ANSWER   5
 

Definition at line 233 of file frame.h.

#define AST_OPTION_FLAG_QUERY   4
 

Definition at line 232 of file frame.h.

#define AST_OPTION_FLAG_REJECT   2
 

Definition at line 231 of file frame.h.

#define AST_OPTION_FLAG_REQUEST   0
 

Definition at line 229 of file frame.h.

#define AST_OPTION_FLAG_WTF   6
 

Definition at line 234 of file frame.h.

#define AST_OPTION_RELAXDTMF   3
 

Definition at line 244 of file frame.h.

#define AST_OPTION_TDD   2
 

Definition at line 241 of file frame.h.

#define AST_OPTION_TONE_VERIFY   1
 

Definition at line 238 of file frame.h.

#define AST_SMOOTHER_FLAG_G729   (1 << 0)
 

Definition at line 226 of file frame.h.

Referenced by ast_rtp_write(), ast_smoother_feed(), and ast_smoother_read().


Function Documentation

int ast_best_codec int  fmts  ) 
 

Pick the best codec.

Definition at line 236 of file channel.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_log(), and LOG_WARNING.

Referenced by ast_codec_choose().

00237 {
00238    /* This just our opinion, expressed in code.  We are asked to choose
00239       the best codec to use, given no information */
00240    int x;
00241    static int prefs[] = 
00242    {
00243       /* Okay, ulaw is used by all telephony equipment, so start with it */
00244       AST_FORMAT_ULAW,
00245       /* Unless of course, you're a silly European, so then prefer ALAW */
00246       AST_FORMAT_ALAW,
00247       /* Okay, well, signed linear is easy to translate into other stuff */
00248       AST_FORMAT_SLINEAR,
00249       /* G.726 is standard ADPCM */
00250       AST_FORMAT_G726,
00251       /* ADPCM has great sound quality and is still pretty easy to translate */
00252       AST_FORMAT_ADPCM,
00253       /* Okay, we're down to vocoders now, so pick GSM because it's small and easier to
00254          translate and sounds pretty good */
00255       AST_FORMAT_GSM,
00256       /* iLBC is not too bad */
00257       AST_FORMAT_ILBC,
00258       /* Speex is free, but computationally more expensive than GSM */
00259       AST_FORMAT_SPEEX,
00260       /* Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough
00261          to use it */
00262       AST_FORMAT_LPC10,
00263       /* G.729a is faster than 723 and slightly less expensive */
00264       AST_FORMAT_G729A,
00265       /* Down to G.723.1 which is proprietary but at least designed for voice */
00266       AST_FORMAT_G723_1,
00267    };
00268    
00269    
00270    for (x=0;x<sizeof(prefs) / sizeof(prefs[0]); x++)
00271       if (fmts & prefs[x])
00272          return prefs[x];
00273    ast_log(LOG_WARNING, "Don't know any of 0x%x formats\n", fmts);
00274    return 0;
00275 }

char* ast_codec2str int  codec  ) 
 

Get a name from a format.

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

Definition at line 516 of file frame.c.

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

00516                                {
00517    int x = 0;
00518    char *ret = "unknown";
00519    for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
00520       if(AST_FORMAT_LIST[x].visible && AST_FORMAT_LIST[x].bits == codec) {
00521          ret = AST_FORMAT_LIST[x].desc;
00522          break;
00523       }
00524    }
00525    return ret;
00526 }

int ast_codec_choose struct ast_codec_pref pref,
int  formats,
int  find_best
 

Definition at line 939 of file frame.c.

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

00940 {
00941    size_t size = 0;
00942    int x = 0, ret = 0, slot = 0;
00943 
00944    size = sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list);
00945    for (x = 0; x < size; x++) {
00946       slot = pref->order[x];
00947 
00948       if(!slot)
00949          break;
00950       if ( formats & AST_FORMAT_LIST[slot-1].bits ) {
00951          ret = AST_FORMAT_LIST[slot-1].bits;
00952          break;
00953       }
00954    }
00955    if(ret)
00956       return ret;
00957 
00958       return find_best ? ast_best_codec(formats) : 0;
00959 }

int ast_codec_pref_append struct ast_codec_pref pref,
int  format
 

Definition at line 910 of file frame.c.

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

Referenced by ast_parse_allow_disallow().

00911 {
00912    size_t size = 0;
00913    int x = 0, newindex = -1;
00914 
00915    ast_codec_pref_remove(pref, format);
00916    size = sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list);
00917 
00918    for (x = 0; x < size; x++) {
00919       if(AST_FORMAT_LIST[x].bits == format) {
00920          newindex = x + 1;
00921          break;
00922       }
00923    }
00924 
00925    if(newindex) {
00926       for (x = 0; x < size; x++) {
00927          if(!pref->order[x]) {
00928             pref->order[x] = newindex;
00929             break;
00930          }
00931       }
00932    }
00933 
00934    return x;
00935 }

int ast_codec_pref_index struct ast_codec_pref pref,
int  index
 

Definition at line 871 of file frame.c.

References ast_format_list::bits.

Referenced by ast_codec_pref_string().

00872 {
00873    int slot = 0;
00874 
00875    
00876    if((index >= 0) && (index < sizeof(pref->order))) {
00877       slot = pref->order[index];
00878    }
00879 
00880    return slot ? AST_FORMAT_LIST[slot-1].bits : 0;
00881 }

void ast_codec_pref_init struct ast_codec_pref pref  ) 
 

void ast_codec_pref_remove struct ast_codec_pref pref,
int  format
 

Definition at line 884 of file frame.c.

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

Referenced by ast_codec_pref_append(), and ast_parse_allow_disallow().

00885 {
00886    struct ast_codec_pref oldorder;
00887    int x=0, y=0;
00888    size_t size = 0;
00889    int slot = 0;
00890 
00891    if(!pref->order[0])
00892       return;
00893 
00894    size = sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list);
00895 
00896    memcpy(&oldorder,pref,sizeof(struct ast_codec_pref));
00897    memset(pref,0,sizeof(struct ast_codec_pref));
00898 
00899    for (x = 0; x < size; x++) {
00900       slot = oldorder.order[x];
00901       if(! slot)
00902          break;
00903       if(AST_FORMAT_LIST[slot-1].bits != format)
00904          pref->order[y++] = slot;
00905    }
00906    
00907 }

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

Definition at line 813 of file frame.c.

00814 {
00815    int x = 0, differential = 65, mem = 0;
00816    char *from = NULL, *to = NULL;
00817 
00818    if(right) {
00819       from = pref->order;
00820       to = buf;
00821       mem = size;
00822    } else {
00823       to = pref->order;
00824       from = buf;
00825       mem = 32;
00826    }
00827 
00828    memset(to, 0, mem);
00829    for (x = 0; x < 32 ; x++) {
00830       if(!from[x])
00831          break;
00832       to[x] = right ? (from[x] + differential) : (from[x] - differential);
00833    }
00834 }

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

Definition at line 836 of file frame.c.

References ast_codec_pref_index(), and ast_getformatname().

00837 {
00838    int x = 0, codec = 0; 
00839    size_t total_len = 0, slen = 0;
00840    char *formatname = 0;
00841    
00842    memset(buf,0,size);
00843    total_len = size;
00844    buf[0] = '(';
00845    total_len--;
00846    for(x = 0; x < 32 ; x++) {
00847       if(total_len <= 0)
00848          break;
00849       if(!(codec = ast_codec_pref_index(pref,x)))
00850          break;
00851       if((formatname = ast_getformatname(codec))) {
00852          slen = strlen(formatname);
00853          if(slen > total_len)
00854             break;
00855          strncat(buf,formatname,total_len);
00856          total_len -= slen;
00857       }
00858       if(total_len && x < 31 && ast_codec_pref_index(pref , x + 1)) {
00859          strncat(buf,"|",total_len);
00860          total_len--;
00861       }
00862    }
00863    if(total_len) {
00864       strncat(buf,")",total_len);
00865       total_len--;
00866    }
00867 
00868    return size - total_len;
00869 }

int ast_fr_fdhangup int  fd  ) 
 

Sends a hangup to an fd.

Parameters:
fd fd to write to Send a hangup (NULL equivalent) on an fd Returns 0 on success, -1 on failure

Definition at line 393 of file frame.c.

References AST_CONTROL_HANGUP, ast_fr_fdwrite(), and AST_FRAME_CONTROL.

00394 {
00395    struct ast_frame hangup = {
00396       AST_FRAME_CONTROL,
00397       AST_CONTROL_HANGUP
00398    };
00399    return ast_fr_fdwrite(fd, &hangup);
00400 }

struct ast_frame* ast_fr_fdread int  fd  ) 
 

Reads a frame from an fd.

Parameters:
fd an opened fd to read from Read a frame from a stream or packet fd, as written by fd_write returns a frame on success, NULL on error

Definition at line 331 of file frame.c.

References AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_frisolate(), ast_log(), ast_frame::data, ast_frame::datalen, ast_frame::frametype, LOG_WARNING, ast_frame::mallocd, ast_frame::offset, ast_frame::src, and ast_frame::subclass.

00332 {
00333    char buf[65536];
00334    int res;
00335    int ttl = sizeof(struct ast_frame);
00336    struct ast_frame *f = (struct ast_frame *)buf;
00337    /* Read a frame directly from there.  They're always in the
00338       right format. */
00339    
00340    while(ttl) {
00341       res = read(fd, buf, ttl);
00342       if (res < 0) {
00343          ast_log(LOG_WARNING, "Bad read on %d: %s\n", fd, strerror(errno));
00344          return NULL;
00345       }
00346       ttl -= res;
00347    }
00348    
00349    /* read the frame header */
00350    f->mallocd = 0;
00351    /* Re-write data position */
00352    f->data = buf + sizeof(struct ast_frame);
00353    f->offset = 0;
00354    /* Forget about being mallocd */
00355    f->mallocd = 0;
00356    /* Re-write the source */
00357    f->src = __FUNCTION__;
00358    if (f->datalen > sizeof(buf) - sizeof(struct ast_frame)) {
00359       /* Really bad read */
00360       ast_log(LOG_WARNING, "Strange read (%d bytes)\n", f->datalen);
00361       return NULL;
00362    }
00363    if (f->datalen) {
00364       if ((res = read(fd, f->data, f->datalen)) != f->datalen) {
00365          /* Bad read */
00366          ast_log(LOG_WARNING, "How very strange, expected %d, got %d\n", f->datalen, res);
00367          return NULL;
00368       }
00369    }
00370    if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP)) {
00371       return NULL;
00372    }
00373    return ast_frisolate(f);
00374 }

int ast_fr_fdwrite int  fd,
struct ast_frame frame
 

Writes a frame to an fd.

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

Definition at line 379 of file frame.c.

References ast_log(), and LOG_WARNING.

Referenced by ast_fr_fdhangup().

00380 {
00381    /* Write the frame exactly */
00382    if (write(fd, frame, sizeof(struct ast_frame)) != sizeof(struct ast_frame)) {
00383       ast_log(LOG_WARNING, "Write error: %s\n", strerror(errno));
00384       return -1;
00385    }
00386    if (write(fd, frame->data, frame->datalen) != frame->datalen) {
00387       ast_log(LOG_WARNING, "Write error: %s\n", strerror(errno));
00388       return -1;
00389    }
00390    return 0;
00391 }

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

Definition at line 614 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_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_verbose(), COLOR_BLACK, COLOR_BRCYAN, COLOR_BRGREEN, COLOR_BRMAGENTA, COLOR_BRRED, COLOR_YELLOW, and term_color().

Referenced by ast_read(), and ast_write().

00615 {
00616    char *n = "unknown";
00617    char ftype[40] = "Unknown Frametype";
00618    char cft[80];
00619    char subclass[40] = "Unknown Subclass";
00620    char csub[80];
00621    char moreinfo[40] = "";
00622    char cn[60];
00623    char cp[40];
00624    char cmn[40];
00625    if (name)
00626       n = name;
00627    if (!f) {
00628       ast_verbose("%s [ %s (NULL) ] [%s]\n", 
00629          term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
00630          term_color(cft, "HANGUP", COLOR_BRRED, COLOR_BLACK, sizeof(cft)), 
00631          term_color(cn, n, COLOR_YELLOW, COLOR_BLACK, sizeof(cn)));
00632       return;
00633    }
00634    /* XXX We should probably print one each of voice and video when the format changes XXX */
00635    if (f->frametype == AST_FRAME_VOICE)
00636       return;
00637    if (f->frametype == AST_FRAME_VIDEO)
00638       return;
00639    switch(f->frametype) {
00640    case AST_FRAME_DTMF:
00641       strcpy(ftype, "DTMF");
00642       subclass[0] = f->subclass;
00643       subclass[1] = '\0';
00644       break;
00645    case AST_FRAME_CONTROL:
00646       strcpy(ftype, "Control");
00647       switch(f->subclass) {
00648       case AST_CONTROL_HANGUP:
00649          strcpy(subclass, "Hangup");
00650          break;
00651       case AST_CONTROL_RING:
00652          strcpy(subclass, "Ring");
00653          break;
00654       case AST_CONTROL_RINGING:
00655          strcpy(subclass, "Ringing");
00656          break;
00657       case AST_CONTROL_ANSWER:
00658          strcpy(subclass, "Answer");
00659          break;
00660       case AST_CONTROL_BUSY:
00661          strcpy(subclass, "Busy");
00662          break;
00663       case AST_CONTROL_TAKEOFFHOOK:
00664          strcpy(subclass, "Take Off Hook");
00665          break;
00666       case AST_CONTROL_OFFHOOK:
00667          strcpy(subclass, "Line Off Hook");
00668          break;
00669       case AST_CONTROL_CONGESTION:
00670          strcpy(subclass, "Congestion");
00671          break;
00672       case AST_CONTROL_FLASH:
00673          strcpy(subclass, "Flash");
00674          break;
00675       case AST_CONTROL_WINK:
00676          strcpy(subclass, "Wink");
00677          break;
00678       case AST_CONTROL_OPTION:
00679          strcpy(subclass, "Option");
00680          break;
00681       case AST_CONTROL_RADIO_KEY:
00682          strcpy(subclass, "Key Radio");
00683          break;
00684       case AST_CONTROL_RADIO_UNKEY:
00685          strcpy(subclass, "Unkey Radio");
00686          break;
00687       case -1:
00688          strcpy(subclass, "Stop generators");
00689          break;
00690       default:
00691          snprintf(subclass, sizeof(subclass), "Unknown control '%d'", f->subclass);
00692       }
00693       break;
00694    case AST_FRAME_NULL:
00695       strcpy(ftype, "Null Frame");
00696       strcpy(subclass, "N/A");
00697       break;
00698    case AST_FRAME_IAX:
00699       /* Should never happen */
00700       strcpy(ftype, "IAX Specific");
00701       snprintf(subclass, sizeof(subclass), "IAX Frametype %d", f->subclass);
00702       break;
00703    case AST_FRAME_TEXT:
00704       strcpy(ftype, "Text");
00705       strcpy(subclass, "N/A");
00706       strncpy(moreinfo, f->data, sizeof(moreinfo) - 1);
00707       break;
00708    case AST_FRAME_IMAGE:
00709       strcpy(ftype, "Image");
00710       snprintf(subclass, sizeof(subclass), "Image format %s\n", ast_getformatname(f->subclass));
00711       break;
00712    case AST_FRAME_HTML:
00713       strcpy(ftype, "HTML");
00714       switch(f->subclass) {
00715       case AST_HTML_URL:
00716          strcpy(subclass, "URL");
00717          strncpy(moreinfo, f->data, sizeof(moreinfo) - 1);
00718          break;
00719       case AST_HTML_DATA:
00720          strcpy(subclass, "Data");
00721          break;
00722       case AST_HTML_BEGIN:
00723          strcpy(subclass, "Begin");
00724          break;
00725       case AST_HTML_END:
00726          strcpy(subclass, "End");
00727          break;
00728       case AST_HTML_LDCOMPLETE:
00729          strcpy(subclass, "Load Complete");
00730          break;
00731       case AST_HTML_NOSUPPORT:
00732          strcpy(subclass, "No Support");
00733          break;
00734       case AST_HTML_LINKURL:
00735          strcpy(subclass, "Link URL");
00736          strncpy(moreinfo, f->data, sizeof(moreinfo) - 1);
00737          break;
00738       case AST_HTML_UNLINK:
00739          strcpy(subclass, "Unlink");
00740          break;
00741       case AST_HTML_LINKREJECT:
00742          strcpy(subclass, "Link Reject");
00743          break;
00744       default:
00745          snprintf(subclass, sizeof(subclass), "Unknown HTML frame '%d'\n", f->subclass);
00746          break;
00747       }
00748       break;
00749    default:
00750       snprintf(ftype, sizeof(ftype), "Unknown Frametype '%d'", f->frametype);
00751    }
00752    if (!ast_strlen_zero(moreinfo))
00753       ast_verbose("%s [ TYPE: %s (%d) SUBCLASS: %s (%d) '%s' ] [%s]\n",  
00754          term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
00755          term_color(cft, ftype, COLOR_BRRED, COLOR_BLACK, sizeof(cft)),
00756          f->frametype, 
00757          term_color(csub, subclass, COLOR_BRCYAN, COLOR_BLACK, sizeof(csub)),
00758          f->subclass, 
00759          term_color(cmn, moreinfo, COLOR_BRGREEN, COLOR_BLACK, sizeof(cmn)),
00760          term_color(cn, n, COLOR_YELLOW, COLOR_BLACK, sizeof(cn)));
00761    else
00762       ast_verbose("%s [ TYPE: %s (%d) SUBCLASS: %s (%d) ] [%s]\n",  
00763          term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
00764          term_color(cft, ftype, COLOR_BRRED, COLOR_BLACK, sizeof(cft)),
00765          f->frametype, 
00766          term_color(csub, subclass, COLOR_BRCYAN, COLOR_BLACK, sizeof(csub)),
00767          f->subclass, 
00768          term_color(cn, n, COLOR_YELLOW, COLOR_BLACK, sizeof(cn)));
00769 
00770 }

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 a frame on success, NULL on error

Definition at line 293 of file frame.c.

References AST_FRIENDLY_OFFSET, AST_MALLOCD_HDR, 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_queue_frame(), and ast_rtp_write().

00294 {
00295    struct ast_frame *out;
00296    int len, srclen = 0;
00297    void *buf;
00298    /* Start with standard stuff */
00299    len = sizeof(struct ast_frame) + AST_FRIENDLY_OFFSET + f->datalen;
00300    /* If we have a source, add space for it */
00301    if (f->src)
00302       srclen = strlen(f->src);
00303    if (srclen > 0)
00304       len += srclen + 1;
00305    buf = malloc(len);
00306    if (!buf)
00307       return NULL;
00308    out = buf;
00309    /* Set us as having malloc'd header only, so it will eventually
00310       get freed. */
00311    out->frametype = f->frametype;
00312    out->subclass = f->subclass;
00313    out->datalen = f->datalen;
00314    out->samples = f->samples;
00315    out->delivery = f->delivery;
00316    out->mallocd = AST_MALLOCD_HDR;
00317    out->offset = AST_FRIENDLY_OFFSET;
00318    out->data = buf + sizeof(struct ast_frame) + AST_FRIENDLY_OFFSET;
00319    if (srclen > 0) {
00320       out->src = out->data + f->datalen;
00321       /* Must have space since we allocated for it */
00322       strcpy(out->src, f->src);
00323    } else
00324       out->src = NULL;
00325    out->prev = NULL;
00326    out->next = NULL;
00327    memcpy(out->data, f->data, out->datalen); 
00328    return out;
00329 }

void ast_frfree struct ast_frame fr  ) 
 

Frees a frame.

Parameters:
fr Frame to free Free a frame, and the memory it used if applicable no return.

Definition at line 226 of file frame.c.

References AST_MALLOCD_DATA, AST_MALLOCD_HDR, AST_MALLOCD_SRC, ast_mutex_lock, ast_mutex_unlock, free, ast_frame::next, and ast_frame::prev.

Referenced by __ast_request_and_dial(), ast_app_getvoice(), ast_channel_bridge(), ast_channel_free(), ast_dsp_process(), ast_play_and_prepend(), ast_play_and_record(), ast_queue_frame(), ast_read(), ast_recvchar(), ast_rtp_bridge(), ast_safe_sleep(), ast_safe_sleep_conditional(), ast_send_image(), ast_tonepair(), ast_translate(), ast_waitfordigit(), ast_waitfordigit_full(), ast_waitstream(), ast_waitstream_full(), and ast_write().

00227 {
00228    if (fr->mallocd & AST_MALLOCD_DATA) {
00229       if (fr->data) 
00230          free(fr->data - fr->offset);
00231    }
00232    if (fr->mallocd & AST_MALLOCD_SRC) {
00233       if (fr->src)
00234          free(fr->src);
00235    }
00236    if (fr->mallocd & AST_MALLOCD_HDR) {
00237 #ifdef TRACE_FRAMES
00238       headers--;
00239       ast_mutex_lock(&framelock);
00240       if (fr->next)
00241          fr->next->prev = fr->prev;
00242       if (fr->prev)
00243          fr->prev->next = fr->next;
00244       else
00245          headerlist = fr->next;
00246       ast_mutex_unlock(&framelock);
00247 #endif         
00248       free(fr);
00249    }
00250 }

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 a frame on success, NULL on error

Definition at line 252 of file frame.c.

References AST_FRIENDLY_OFFSET, ast_log(), AST_MALLOCD_DATA, 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 ast_fr_fdread().

00253 {
00254    struct ast_frame *out;
00255    if (!(fr->mallocd & AST_MALLOCD_HDR)) {
00256       /* Allocate a new header if needed */
00257       out = ast_frame_header_new();
00258       if (!out) {
00259          ast_log(LOG_WARNING, "Out of memory\n");
00260          return NULL;
00261       }
00262       out->frametype = fr->frametype;
00263       out->subclass = fr->subclass;
00264       out->datalen = 0;
00265       out->samples = fr->samples;
00266       out->offset = 0;
00267       out->src = NULL;
00268       out->data = NULL;
00269    } else {
00270       out = fr;
00271    }
00272    if (!(fr->mallocd & AST_MALLOCD_SRC)) {
00273       if (fr->src)
00274          out->src = strdup(fr->src);
00275    } else
00276       out->src = fr->src;
00277    if (!(fr->mallocd & AST_MALLOCD_DATA))  {
00278       out->data = malloc(fr->datalen + AST_FRIENDLY_OFFSET);
00279       if (!out->data) {
00280          free(out);
00281          ast_log(LOG_WARNING, "Out of memory\n");
00282          return NULL;
00283       }
00284       out->data += AST_FRIENDLY_OFFSET;
00285       out->offset = AST_FRIENDLY_OFFSET;
00286       out->datalen = fr->datalen;
00287       memcpy(out->data, fr->data, fr->datalen);
00288    }
00289    out->mallocd = AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA;
00290    return out;
00291 }

struct ast_format_list* ast_get_format_list size_t *  size  ) 
 

Definition at line 434 of file frame.c.

00434                                                           {
00435    *size = (sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list));
00436    return AST_FORMAT_LIST;
00437 }

struct ast_format_list* ast_get_format_list_index int  index  ) 
 

Definition at line 430 of file frame.c.

00430                                                              {
00431    return &AST_FORMAT_LIST[index];
00432 }

int ast_getformatbyname char *  name  ) 
 

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

Definition at line 498 of file frame.c.

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

Referenced by ast_parse_allow_disallow().

00499 {
00500    int x = 0, all = 0, format = 0;
00501 
00502    all = strcasecmp(name, "all") ? 0 : 1;
00503    for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
00504       if(AST_FORMAT_LIST[x].visible && (all || 
00505                                 !strcasecmp(AST_FORMAT_LIST[x].name,name) ||
00506                                 !strcasecmp(AST_FORMAT_LIST[x].name,ast_expand_codec_alias(name)))) {
00507          format |= AST_FORMAT_LIST[x].bits;
00508          if(!all)
00509             break;
00510       }
00511    }
00512 
00513    return format;
00514 }

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

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

Referenced by 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_read(), ast_rtp_write(), ast_set_read_format(), ast_set_write_format(), ast_streamfile(), ast_translator_build_path(), ast_unregister_translator(), and ast_writestream().

00440 {
00441    int x = 0;
00442    char *ret = "unknown";
00443    for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
00444       if(AST_FORMAT_LIST[x].visible && AST_FORMAT_LIST[x].bits == format) {
00445          ret = AST_FORMAT_LIST[x].name;
00446          break;
00447       }
00448    }
00449    return ret;
00450 }

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

00452                                                                      {
00453 
00454    int x = 0;
00455    unsigned len;
00456    char *end = buf;
00457    char *start = buf;
00458    if (!size) return buf;
00459    snprintf(end, size, "0x%x (", format);
00460    len = strlen(end);
00461    end += len;
00462    size -= len;
00463    start = end;
00464    for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
00465       if (AST_FORMAT_LIST[x].visible && (AST_FORMAT_LIST[x].bits & format)) {
00466          snprintf(end, size,"%s|",AST_FORMAT_LIST[x].name);
00467          len = strlen(end);
00468          end += len;
00469          size -= len;
00470       }
00471    }
00472    if (start == end)
00473       snprintf(start, size, "nothing)");
00474    else if (size > 1)
00475       *(end -1) = ')';
00476    return buf;
00477 }

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

Definition at line 961 of file frame.c.

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

00962 {
00963    int format_i = 0;
00964    char *next_format = NULL, *last_format = NULL;
00965 
00966    last_format = ast_strdupa(list);
00967    while(last_format) {
00968       if((next_format = strchr(last_format, ','))) {
00969          *next_format = '\0';
00970          next_format++;
00971       }
00972       if ((format_i = ast_getformatbyname(last_format)) > 0) {
00973          if (mask) {
00974             if (allowing)
00975                (*mask) |= format_i;
00976             else
00977                (*mask) &= ~format_i;
00978          }
00979          /* can't consider 'all' a prefered codec*/
00980          if(pref && strcasecmp(last_format, "all")) {
00981             if(allowing)
00982                ast_codec_pref_append(pref, format_i);
00983             else
00984                ast_codec_pref_remove(pref, format_i);
00985          } else if(!allowing) /* disallow all must clear your prefs or it makes no sense */
00986             memset(pref, 0, sizeof(struct ast_codec_pref));
00987       } else
00988          ast_log(LOG_WARNING, "Cannot %s unknown format '%s'\n", allowing ? "allow" : "disallow", last_format);
00989 
00990       last_format = next_format;
00991    }
00992 }

int ast_smoother_feed struct ast_smoother s,
struct ast_frame f
 

Definition at line 86 of file frame.c.

References AST_FRAME_VOICE, ast_log(), AST_MIN_OFFSET, AST_SMOOTHER_FLAG_G729, ast_frame::datalen, ast_frame::delivery, ast_smoother::format, LOG_NOTICE, LOG_WARNING, ast_smoother::opt, s, ast_smoother::samplesperbyte, and SMOOTHER_SIZE.

Referenced by ast_rtp_write().

00087 {
00088    if (f->frametype != AST_FRAME_VOICE) {
00089       ast_log(LOG_WARNING, "Huh?  Can't smooth a non-voice frame!\n");
00090       return -1;
00091    }
00092    if (!s->format) {
00093       s->format = f->subclass;
00094       s->samplesperbyte = (float)f->samples / (float)f->datalen;
00095    } else if (s->format != f->subclass) {
00096       ast_log(LOG_WARNING, "Smoother was working on %d format frames, now trying to feed %d?\n", s->format, f->subclass);
00097       return -1;
00098    }
00099    if (s->len + f->datalen > SMOOTHER_SIZE) {
00100       ast_log(LOG_WARNING, "Out of smoother space\n");
00101       return -1;
00102    }
00103    if (((f->datalen == s->size) || ((f->datalen < 10) && (s->flags & AST_SMOOTHER_FLAG_G729)))
00104              && !s->opt && (f->offset >= AST_MIN_OFFSET)) {
00105       if (!s->len) {
00106          /* Optimize by sending the frame we just got
00107             on the next read, thus eliminating the douple
00108             copy */
00109          s->opt = f;
00110          return 0;
00111       } else {
00112          s->optimizablestream++;
00113          if (s->optimizablestream > 10) {
00114             /* For the past 10 rounds, we have input and output
00115                frames of the correct size for this smoother, yet
00116                we were unable to optimize because there was still
00117                some cruft left over.  Lets just drop the cruft so
00118                we can move to a fully optimized path */
00119             s->len = 0;
00120             s->opt = f;
00121             return 0;
00122          }
00123       }
00124    } else 
00125       s->optimizablestream = 0;
00126    if (s->flags & AST_SMOOTHER_FLAG_G729) {
00127       if (s->len % 10) {
00128          ast_log(LOG_NOTICE, "Dropping extra frame of G.729 since we already have a VAD frame at the end\n");
00129          return 0;
00130       }
00131    }
00132    memcpy(s->data + s->len, f->data, f->datalen);
00133    /* If either side is empty, reset the delivery time */
00134    if (!s->len || (!f->delivery.tv_sec && !f->delivery.tv_usec) ||
00135          (!s->delivery.tv_sec && !s->delivery.tv_usec))
00136       s->delivery = f->delivery;
00137    s->len += f->datalen;
00138    return 0;
00139 }

void ast_smoother_free struct ast_smoother s  ) 
 

Definition at line 195 of file frame.c.

References free, and s.

Referenced by ast_rtp_destroy(), and ast_rtp_write().

00196 {
00197    free(s);
00198 }

int ast_smoother_get_flags struct ast_smoother smoother  ) 
 

Definition at line 76 of file frame.c.

References ast_smoother::flags, and s.

00077 {
00078    return s->flags;
00079 }

struct ast_smoother* ast_smoother_new int  bytes  ) 
 

Definition at line 65 of file frame.c.

References ast_smoother_reset(), malloc, and s.

Referenced by ast_rtp_write().

00066 {
00067    struct ast_smoother *s;
00068    if (size < 1)
00069       return NULL;
00070    s = malloc(sizeof(struct ast_smoother));
00071    if (s)
00072       ast_smoother_reset(s, size);
00073    return s;
00074 }

struct ast_frame* ast_smoother_read struct ast_smoother s  ) 
 

Definition at line 141 of file frame.c.

References AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), AST_SMOOTHER_FLAG_G729, ast_frame::data, ast_frame::datalen, ast_frame::delivery, ast_frame::frametype, LOG_WARNING, ast_frame::offset, s, ast_frame::samples, and ast_frame::subclass.

Referenced by ast_rtp_write().

00142 {
00143    struct ast_frame *opt;
00144    int len;
00145    /* IF we have an optimization frame, send it */
00146    if (s->opt) {
00147       if (s->opt->offset < AST_FRIENDLY_OFFSET)
00148          ast_log(LOG_WARNING, "Returning a frame of inappropriate offset (%d).",
00149                      s->opt->offset);
00150       opt = s->opt;
00151       s->opt = NULL;
00152       return opt;
00153    }
00154 
00155    /* Make sure we have enough data */
00156    if (s->len < s->size) {
00157       /* Or, if this is a G.729 frame with VAD on it, send it immediately anyway */
00158       if (!((s->flags & AST_SMOOTHER_FLAG_G729) && (s->size % 10)))
00159          return NULL;
00160    }
00161    len = s->size;
00162    if (len > s->len)
00163       len = s->len;
00164    /* Make frame */
00165    s->f.frametype = AST_FRAME_VOICE;
00166    s->f.subclass = s->format;
00167    s->f.data = s->framedata + AST_FRIENDLY_OFFSET;
00168    s->f.offset = AST_FRIENDLY_OFFSET;
00169    s->f.datalen = len;
00170    /* Samples will be improper given VAD, but with VAD the concept really doesn't even exist */
00171    s->f.samples = len * s->samplesperbyte;
00172    s->f.delivery = s->delivery;
00173    /* Fill Data */
00174    memcpy(s->f.data, s->data, len);
00175    s->len -= len;
00176    /* Move remaining data to the front if applicable */
00177    if (s->len) {
00178       /* In principle this should all be fine because if we are sending
00179          G.729 VAD, the next timestamp will take over anyawy */
00180       memmove(s->data, s->data + len, s->len);
00181       if (s->delivery.tv_sec || s->delivery.tv_usec) {
00182          /* If we have delivery time, increment it, otherwise, leave it at 0 */
00183          s->delivery.tv_sec += (len * s->samplesperbyte) / 8000.0;
00184          s->delivery.tv_usec += (((int)(len * s->samplesperbyte)) % 8000) * 125;
00185          if (s->delivery.tv_usec > 1000000) {
00186             s->delivery.tv_usec -= 1000000;
00187             s->delivery.tv_sec += 1;
00188          }
00189       }
00190    }
00191    /* Return frame */
00192    return &s->f;
00193 }

void ast_smoother_reset struct ast_smoother s,
int  bytes
 

Definition at line 59 of file frame.c.

References s.

Referenced by ast_smoother_new().

00060 {
00061    memset(s, 0, sizeof(struct ast_smoother));
00062    s->size = size;
00063 }

void ast_smoother_set_flags struct ast_smoother smoother,
int  flags
 

Definition at line 81 of file frame.c.

References ast_smoother::flags, and s.

Referenced by ast_rtp_write().

00082 {
00083    s->flags = flags;
00084 }


Generated on Wed Mar 16 20:08:37 2005 for Asterisk by  doxygen 1.4.0