Main Page | Alphabetical List | Data Structures | 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.

Data Structures

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

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, unsigned n, 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_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)


Define Documentation

#define AST_CONTROL_ANSWER   4
 

Remote end has answered Definition at line 197 of file frame.h.

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

#define AST_CONTROL_BUSY   5
 

Remote end is busy Definition at line 199 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 205 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 207 of file frame.h.

Referenced by ast_frame_dump().

#define AST_CONTROL_HANGUP   1
 

Other end has hungup Definition at line 191 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(), ast_waitfordigit_full(), ast_waitstream(), ast_waitstream_fr(), and ast_waitstream_full().

#define AST_CONTROL_OFFHOOK   7
 

Line is off hook Definition at line 203 of file frame.h.

Referenced by ast_frame_dump().

#define AST_CONTROL_OPTION   11
 

Set a low-level option Definition at line 211 of file frame.h.

Referenced by ast_frame_dump().

#define AST_CONTROL_PROCEEDING   15
 

Indicate CALL PROCEEDING Definition at line 219 of file frame.h.

Referenced by ast_indicate().

#define AST_CONTROL_PROGRESS   14
 

Indicate PROGRESS Definition at line 217 of file frame.h.

Referenced by __ast_request_and_dial(), and ast_indicate().

#define AST_CONTROL_RADIO_KEY   12
 

Key Radio Definition at line 213 of file frame.h.

Referenced by ast_frame_dump().

#define AST_CONTROL_RADIO_UNKEY   13
 

Un-Key Radio Definition at line 215 of file frame.h.

Referenced by ast_frame_dump().

#define AST_CONTROL_RING   2
 

Local ring Definition at line 193 of file frame.h.

Referenced by ast_frame_dump().

#define AST_CONTROL_RINGING   3
 

Remote end is ringing Definition at line 195 of file frame.h.

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

#define AST_CONTROL_TAKEOFFHOOK   6
 

Make it go off hook Definition at line 201 of file frame.h.

Referenced by ast_frame_dump().

#define AST_CONTROL_WINK   10
 

Wink Definition at line 209 of file frame.h.

Referenced by ast_frame_dump().

#define AST_FORMAT_ADPCM   (1 << 5)
 

ADPCM (IMA) Definition at line 165 of file frame.h.

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

#define AST_FORMAT_ALAW   (1 << 3)
 

Raw A-law data (G.711) Definition at line 161 of file frame.h.

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

#define AST_FORMAT_G723_1   (1 << 0)
 

G.723.1 compression Definition at line 155 of file frame.h.

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

#define AST_FORMAT_G726   (1 << 4)
 

ADPCM (G.726, 32kbps) Definition at line 163 of file frame.h.

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

#define AST_FORMAT_G729A   (1 << 8)
 

G.729A audio Definition at line 171 of file frame.h.

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

#define AST_FORMAT_GSM   (1 << 1)
 

GSM compression Definition at line 157 of file frame.h.

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

#define AST_FORMAT_H261   (1 << 18)
 

H.261 Video Definition at line 183 of file frame.h.

Referenced by ast_getformatbyname(), ast_getformatname(), and ast_rtp_write().

#define AST_FORMAT_H263   (1 << 19)
 

H.263 Video Definition at line 185 of file frame.h.

Referenced by ast_getformatbyname(), ast_getformatname(), and ast_rtp_write().

#define AST_FORMAT_ILBC   (1 << 10)
 

iLBC Free Compression Definition at line 175 of file frame.h.

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

#define AST_FORMAT_JPEG   (1 << 16)
 

JPEG Images Definition at line 179 of file frame.h.

Referenced by ast_getformatname().

#define AST_FORMAT_LPC10   (1 << 7)
 

LPC10, 180 samples/frame Definition at line 169 of file frame.h.

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

#define AST_FORMAT_MAX_AUDIO   (1 << 15)
 

Maximum audio format Definition at line 177 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 187 of file frame.h.

#define AST_FORMAT_PNG   (1 << 17)
 

PNG Images Definition at line 181 of file frame.h.

Referenced by ast_getformatname().

#define AST_FORMAT_SLINEAR   (1 << 6)
 

Raw 16-bit Signed Linear (8000 Hz) PCM Definition at line 167 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_getformatbyname(), ast_getformatname(), ast_play_and_prepend(), ast_play_and_record(), and ast_rtp_read().

#define AST_FORMAT_SPEEX   (1 << 9)
 

SpeeX Free Compression Definition at line 173 of file frame.h.

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

#define AST_FORMAT_ULAW   (1 << 2)
 

Raw mu-law data (G.711) Definition at line 159 of file frame.h.

Referenced by ast_best_codec(), ast_dsp_process(), ast_getformatbyname(), ast_getformatname(), 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 131 of file frame.h.

Referenced by ast_read().

#define AST_FRAME_CONTROL   4
 

A control frame, subclass is AST_CONTROL_* Definition at line 118 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(), ast_waitstream(), ast_waitstream_fr(), ast_waitstream_full(), and ast_write().

#define AST_FRAME_DTMF   1
 

A DTMF digit, subclass is the digit Definition at line 112 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(), ast_waitstream(), ast_waitstream_fr(), ast_waitstream_full(), and ast_write().

#define AST_FRAME_HTML   9
 

HTML Frame Definition at line 128 of file frame.h.

Referenced by ast_frame_dump().

#define AST_FRAME_IAX   6
 

Inter Asterisk Exchange private frame type Definition at line 122 of file frame.h.

Referenced by ast_frame_dump().

#define AST_FRAME_IMAGE   8
 

Image Frames Definition at line 126 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 120 of file frame.h.

Referenced by ast_channel_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 124 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 116 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 114 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 98 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 139 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_DATA   2
 

Data frame Definition at line 137 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_END   8
 

End frame Definition at line 141 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_LDCOMPLETE   16
 

Load is complete Definition at line 143 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_LINKREJECT   20
 

Reject link request Definition at line 151 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_LINKURL   18
 

Send URL, and track Definition at line 147 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_NOSUPPORT   17
 

Peer is unable to support HTML Definition at line 145 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_UNLINK   19
 

No more HTML linkage Definition at line 149 of file frame.h.

Referenced by ast_frame_dump().

#define AST_HTML_URL   1
 

Sending a URL Definition at line 135 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 106 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 104 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 108 of file frame.h.

Referenced by ast_frfree(), and ast_frisolate().

#define AST_MIN_OFFSET   32
 

Definition at line 101 of file frame.h.

Referenced by ast_smoother_feed().

#define AST_OPTION_AUDIO_MODE   4
 

Definition at line 242 of file frame.h.

#define AST_OPTION_FLAG_ACCEPT   1
 

Definition at line 225 of file frame.h.

#define AST_OPTION_FLAG_ANSWER   5
 

Definition at line 228 of file frame.h.

#define AST_OPTION_FLAG_QUERY   4
 

Definition at line 227 of file frame.h.

#define AST_OPTION_FLAG_REJECT   2
 

Definition at line 226 of file frame.h.

#define AST_OPTION_FLAG_REQUEST   0
 

Definition at line 224 of file frame.h.

#define AST_OPTION_FLAG_WTF   6
 

Definition at line 229 of file frame.h.

#define AST_OPTION_RELAXDTMF   3
 

Definition at line 239 of file frame.h.

#define AST_OPTION_TDD   2
 

Definition at line 236 of file frame.h.

#define AST_OPTION_TONE_VERIFY   1
 

Definition at line 233 of file frame.h.

#define AST_SMOOTHER_FLAG_G729   (1 << 0)
 

Definition at line 221 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 233 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.

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

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

Referenced by ast_dsp_process().

00489 { 00490 static char codecs[25][30] = { 00491 /* Audio formats */ 00492 "G.723.1", /* 0 */ 00493 "GSM", /* 1 */ 00494 "G.711 u-law", /* 2 */ 00495 "G.711 A-law", /* 3 */ 00496 "G.726", /* 4 */ 00497 "ADPCM", /* 5 */ 00498 "16 bit Signed Linear PCM", /* 6 */ 00499 "LPC10", /* 7 */ 00500 "G.729A audio", /* 8 */ 00501 "SpeeX", /* 9 */ 00502 "iLBC", /* 10 */ 00503 "undefined", /* 11 */ 00504 "undefined", /* 12 */ 00505 "undefined", /* 13 */ 00506 "undefined", /* 14 */ 00507 "Maximum audio format", /* 15 */ 00508 /* Image formats */ 00509 "JPEG image", /* 16 */ 00510 "PNG image", /* 17 */ 00511 "H.261 Video", /* 18 */ 00512 "H.263 Video", /* 19 */ 00513 "undefined", /* 20 */ 00514 "undefined", /* 21 */ 00515 "undefined", /* 22 */ 00516 "undefined", /* 23 */ 00517 "Maximum video format", /* 24 */ 00518 }; 00519 if ((codec >= 0) && (codec <= 24)) 00520 return codecs[codec]; 00521 else 00522 return "unknown"; 00523 }

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

References AST_CONTROL_HANGUP, ast_fr_fdwrite(), and AST_FRAME_CONTROL.

00386 { 00387 struct ast_frame hangup = { 00388 AST_FRAME_CONTROL, 00389 AST_CONTROL_HANGUP 00390 }; 00391 return ast_fr_fdwrite(fd, &hangup); 00392 }

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

References AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_frisolate(), ast_log(), and LOG_WARNING.

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

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

References ast_log(), ast_frame::data, ast_frame::datalen, and LOG_WARNING.

Referenced by ast_fr_fdhangup().

00372 { 00373 /* Write the frame exactly */ 00374 if (write(fd, frame, sizeof(struct ast_frame)) != sizeof(struct ast_frame)) { 00375 ast_log(LOG_WARNING, "Write error: %s\n", strerror(errno)); 00376 return -1; 00377 } 00378 if (write(fd, frame->data, frame->datalen) != frame->datalen) { 00379 ast_log(LOG_WARNING, "Write error: %s\n", strerror(errno)); 00380 return -1; 00381 } 00382 return 0; 00383 }

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

Definition at line 602 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, ast_frame::data, ast_frame::frametype, ast_frame::subclass, and term_color().

Referenced by ast_read(), and ast_write().

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

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 285 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::samples, ast_frame::src, and ast_frame::subclass.

Referenced by ast_queue_frame(), and ast_rtp_write().

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

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

References AST_MALLOCD_DATA, AST_MALLOCD_HDR, AST_MALLOCD_SRC, ast_mutex_lock, ast_mutex_unlock, ast_frame::data, free, ast_frame::mallocd, ast_frame::next, ast_frame::offset, ast_frame::prev, and ast_frame::src.

Referenced by __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_fr(), ast_waitstream_full(), and ast_write().

00219 { 00220 if (fr->mallocd & AST_MALLOCD_DATA) { 00221 if (fr->data) 00222 free(fr->data - fr->offset); 00223 } 00224 if (fr->mallocd & AST_MALLOCD_SRC) { 00225 if (fr->src) 00226 free(fr->src); 00227 } 00228 if (fr->mallocd & AST_MALLOCD_HDR) { 00229 #ifdef TRACE_FRAMES 00230 headers--; 00231 ast_mutex_lock(&framelock); 00232 if (fr->next) 00233 fr->next->prev = fr->prev; 00234 if (fr->prev) 00235 fr->prev->next = fr->next; 00236 else 00237 headerlist = fr->next; 00238 ast_mutex_unlock(&framelock); 00239 #endif 00240 free(fr); 00241 } 00242 }

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 244 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::samples, ast_frame::src, strdup, and ast_frame::subclass.

Referenced by ast_fr_fdread().

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

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

References AST_FORMAT_ADPCM, AST_FORMAT_ALAW, AST_FORMAT_G723_1, AST_FORMAT_G726, AST_FORMAT_G729A, AST_FORMAT_GSM, AST_FORMAT_H261, AST_FORMAT_H263, AST_FORMAT_ILBC, AST_FORMAT_LPC10, AST_FORMAT_SLINEAR, AST_FORMAT_SPEEX, and AST_FORMAT_ULAW.

00457 { 00458 if (!strcasecmp(name, "g723.1")) 00459 return AST_FORMAT_G723_1; 00460 else if (!strcasecmp(name, "gsm")) 00461 return AST_FORMAT_GSM; 00462 else if (!strcasecmp(name, "ulaw")) 00463 return AST_FORMAT_ULAW; 00464 else if (!strcasecmp(name, "alaw")) 00465 return AST_FORMAT_ALAW; 00466 else if (!strcasecmp(name, "g726")) 00467 return AST_FORMAT_G726; 00468 else if (!strcasecmp(name, "slinear")) 00469 return AST_FORMAT_SLINEAR; 00470 else if (!strcasecmp(name, "lpc10")) 00471 return AST_FORMAT_LPC10; 00472 else if (!strcasecmp(name, "adpcm")) 00473 return AST_FORMAT_ADPCM; 00474 else if (!strcasecmp(name, "g729")) 00475 return AST_FORMAT_G729A; 00476 else if (!strcasecmp(name, "speex")) 00477 return AST_FORMAT_SPEEX; 00478 else if (!strcasecmp(name, "ilbc")) 00479 return AST_FORMAT_ILBC; 00480 else if (!strcasecmp(name, "h261")) 00481 return AST_FORMAT_H261; 00482 else if (!strcasecmp(name, "h263")) 00483 return AST_FORMAT_H263; 00484 else if (!strcasecmp(name, "all")) 00485 return 0x7FFFFFFF; 00486 return 0; 00487 }

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

References AST_FORMAT_ADPCM, AST_FORMAT_ALAW, AST_FORMAT_G723_1, AST_FORMAT_G726, AST_FORMAT_G729A, AST_FORMAT_GSM, AST_FORMAT_H261, AST_FORMAT_H263, AST_FORMAT_ILBC, AST_FORMAT_JPEG, AST_FORMAT_LPC10, AST_FORMAT_PNG, AST_FORMAT_SLINEAR, AST_FORMAT_SPEEX, and AST_FORMAT_ULAW.

Referenced by ast_frame_dump(), ast_getformatname_multiple(), 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().

00395 { 00396 if (format == AST_FORMAT_G723_1) 00397 return "G723"; 00398 else if (format == AST_FORMAT_GSM) 00399 return "GSM"; 00400 else if (format == AST_FORMAT_ULAW) 00401 return "ULAW"; 00402 else if (format == AST_FORMAT_ALAW) 00403 return "ALAW"; 00404 else if (format == AST_FORMAT_G726) 00405 return "G726"; 00406 else if (format == AST_FORMAT_SLINEAR) 00407 return "SLINR"; 00408 else if (format == AST_FORMAT_LPC10) 00409 return "LPC10"; 00410 else if (format == AST_FORMAT_ADPCM) 00411 return "ADPCM"; 00412 else if (format == AST_FORMAT_G729A) 00413 return "G729A"; 00414 else if (format == AST_FORMAT_SPEEX) 00415 return "SPEEX"; 00416 else if (format == AST_FORMAT_ILBC) 00417 return "ILBC"; 00418 else if (format == AST_FORMAT_JPEG) 00419 return "JPEG"; 00420 else if (format == AST_FORMAT_PNG) 00421 return "PNG"; 00422 else if (format == AST_FORMAT_H261) 00423 return "H261"; 00424 else if (format == AST_FORMAT_H263) 00425 return "H263"; 00426 return "UNKN"; 00427 }

char* ast_getformatname_multiple char *  buf,
unsigned  n,
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 429 of file frame.c.

References ast_getformatname().

00429 { 00430 unsigned u=1; 00431 unsigned len; 00432 char *b = buf; 00433 char *start = buf; 00434 if (!n) return buf; 00435 snprintf(b,n,"0x%x(",format); 00436 len = strlen(b); 00437 b += len; 00438 n -= len; 00439 start = b; 00440 while (u) { 00441 if (u&format) { 00442 snprintf(b,n,"%s|",ast_getformatname(u)); 00443 len = strlen(b); 00444 b += len; 00445 n -= len; 00446 } 00447 u *= 2; 00448 } 00449 if (start==b) 00450 snprintf(start,n,"EMPTY)"); 00451 else if (n>1) 00452 b[-1]=')'; 00453 return buf; 00454 }

int ast_smoother_feed struct ast_smoother s,
struct ast_frame f
 

Definition at line 78 of file frame.c.

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

Referenced by ast_rtp_write().

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

void ast_smoother_free struct ast_smoother s  ) 
 

Definition at line 187 of file frame.c.

References free, and s.

Referenced by ast_rtp_destroy(), and ast_rtp_write().

00188 { 00189 free(s); 00190 }

int ast_smoother_get_flags struct ast_smoother smoother  ) 
 

Definition at line 68 of file frame.c.

References s.

00069 { 00070 return s->flags; 00071 }

struct ast_smoother* ast_smoother_new int  bytes  ) 
 

Definition at line 57 of file frame.c.

References ast_smoother_reset(), malloc, and s.

Referenced by ast_rtp_write().

00058 { 00059 struct ast_smoother *s; 00060 if (size < 1) 00061 return NULL; 00062 s = malloc(sizeof(struct ast_smoother)); 00063 if (s) 00064 ast_smoother_reset(s, size); 00065 return s; 00066 }

struct ast_frame* ast_smoother_read struct ast_smoother s  ) 
 

Definition at line 133 of file frame.c.

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

Referenced by ast_rtp_write().

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

void ast_smoother_reset struct ast_smoother s,
int  bytes
 

Definition at line 51 of file frame.c.

References s.

Referenced by ast_smoother_new().

00052 { 00053 memset(s, 0, sizeof(struct ast_smoother)); 00054 s->size = size; 00055 }

void ast_smoother_set_flags struct ast_smoother smoother,
int  flags
 

Definition at line 73 of file frame.c.

References s.

Referenced by ast_rtp_write().

00074 { 00075 s->flags = flags; 00076 }


Generated on Fri Sep 24 21:03:52 2004 for Asterisk by doxygen 1.3.8