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

frame.c File Reference

#include <asterisk/lock.h>
#include <asterisk/frame.h>
#include <asterisk/logger.h>
#include <asterisk/options.h>
#include <asterisk/cli.h>
#include <asterisk/term.h>
#include <asterisk/utils.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include "asterisk.h"

Go to the source code of this file.

Data Structures

struct  ast_smoother

Defines

#define SMOOTHER_SIZE   8000

Functions

void ast_smoother_reset (struct ast_smoother *s, int size)
ast_smootherast_smoother_new (int size)
int ast_smoother_get_flags (struct ast_smoother *s)
void ast_smoother_set_flags (struct ast_smoother *s, int flags)
int ast_smoother_feed (struct ast_smoother *s, struct ast_frame *f)
ast_frameast_smoother_read (struct ast_smoother *s)
void ast_smoother_free (struct ast_smoother *s)
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 *f)
 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.
void ast_frame_dump (char *name, struct ast_frame *f, char *prefix)
int init_framer (void)

Variables

ast_cli_entry cli_show_codecs
ast_cli_entry cli_show_codecs_audio
ast_cli_entry cli_show_codecs_video
ast_cli_entry cli_show_codecs_image
ast_cli_entry cli_show_codec_n


Define Documentation

#define SMOOTHER_SIZE   8000
 

Definition at line 34 of file frame.c.

Referenced by ast_smoother_feed().


Function Documentation

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

Referenced by ast_dsp_process().

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

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

References AST_CONTROL_HANGUP, ast_fr_fdwrite(), and AST_FRAME_CONTROL.

00383 { 00384 struct ast_frame hangup = { 00385 AST_FRAME_CONTROL, 00386 AST_CONTROL_HANGUP 00387 }; 00388 return ast_fr_fdwrite(fd, &hangup); 00389 }

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

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

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

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

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

Referenced by ast_fr_fdhangup().

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

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

Definition at line 599 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().

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

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 282 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().

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

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 215 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_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().

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

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 241 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().

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

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 453 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.

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

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 391 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_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().

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

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

References ast_getformatname().

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

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

References free, and s.

Referenced by ast_rtp_destroy(), and ast_rtp_write().

00185 { 00186 free(s); 00187 }

int ast_smoother_get_flags struct ast_smoother s  ) 
 

Definition at line 68 of file frame.c.

References s.

00069 { 00070 return s->flags; 00071 }

struct ast_smoother* ast_smoother_new int  size  ) 
 

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

void ast_smoother_reset struct ast_smoother s,
int  size
 

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 s,
int  flags
 

Definition at line 73 of file frame.c.

References s.

Referenced by ast_rtp_write().

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

int init_framer void   ) 
 

Definition at line 781 of file frame.c.

References ast_cli_register(), cli_show_codec_n, cli_show_codecs, cli_show_codecs_audio, cli_show_codecs_image, and cli_show_codecs_video.

Referenced by main().

00782 { 00783 #ifdef TRACE_FRAMES 00784 ast_cli_register(&cli_frame_stats); 00785 #endif 00786 ast_cli_register(&cli_show_codecs); 00787 ast_cli_register(&cli_show_codecs_audio); 00788 ast_cli_register(&cli_show_codecs_video); 00789 ast_cli_register(&cli_show_codecs_image); 00790 ast_cli_register(&cli_show_codec_n); 00791 return 0; 00792 }


Variable Documentation

struct ast_cli_entry cli_show_codec_n
 

Initial value:

{ { "show", "codec", NULL }, show_codec_n, "Shows a specific codec", frame_show_codec_n_usage }
Definition at line 596 of file frame.c.

Referenced by init_framer().

struct ast_cli_entry cli_show_codecs
 

Initial value:

{ { "show", "codecs", NULL }, show_codecs, "Shows codecs", frame_show_codecs_usage }
Definition at line 561 of file frame.c.

Referenced by init_framer().

struct ast_cli_entry cli_show_codecs_audio
 

Initial value:

{ { "show", "audio", "codecs", NULL }, show_codecs, "Shows audio codecs", frame_show_codecs_usage }
Definition at line 563 of file frame.c.

Referenced by init_framer().

struct ast_cli_entry cli_show_codecs_image
 

Initial value:

{ { "show", "image", "codecs", NULL }, show_codecs, "Shows image codecs", frame_show_codecs_usage }
Definition at line 567 of file frame.c.

Referenced by init_framer().

struct ast_cli_entry cli_show_codecs_video
 

Initial value:

{ { "show", "video", "codecs", NULL }, show_codecs, "Shows video codecs", frame_show_codecs_usage }
Definition at line 565 of file frame.c.

Referenced by init_framer().


Generated on Tue Aug 17 16:13:55 2004 for Asterisk by doxygen 1.3.8