frame.c File Reference

#include <asterisk/lock.h>
#include <asterisk/frame.h>
#include <asterisk/logger.h>
#include <asterisk/options.h>
#include <asterisk/channel.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"

Include dependency graph for frame.c:

Go to the source code of this file.

Data Structures

struct  ast_format_list
struct  ast_smoother
struct  ast_codec_alias_table

Defines

#define SMOOTHER_SIZE   8000

Functions

void ast_smoother_reset (struct ast_smoother *s, int size)
struct 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, int swap)
struct 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.
struct ast_frameast_frisolate (struct ast_frame *fr)
 Copies a frame.
struct ast_frameast_frdup (struct ast_frame *f)
 Copies a frame.
struct ast_frameast_fr_fdread (int fd)
 Chains a frame -- unimplemented.
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.
void ast_memcpy_byteswap (void *dst, void *src, int samples)
struct ast_format_listast_get_format_list_index (int index)
struct ast_format_listast_get_format_list (size_t *size)
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.
void ast_frame_dump (char *name, struct ast_frame *f, char *prefix)
int init_framer (void)
void ast_codec_pref_shift (struct ast_codec_pref *pref, char *buf, size_t size, int right)
int ast_codec_pref_string (struct ast_codec_pref *pref, char *buf, size_t size)
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)

Variables

struct ast_cli_entry cli_show_codecs
struct ast_cli_entry cli_show_codecs_audio
struct ast_cli_entry cli_show_codecs_video
struct ast_cli_entry cli_show_codecs_image
struct ast_cli_entry cli_show_codec_n


Define Documentation

#define SMOOTHER_SIZE   8000

Definition at line 35 of file frame.c.


Function Documentation

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

Definition at line 86 of file frame.c.

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    if (swap)
00133       ast_memcpy_byteswap(s->data+s->len, f->data, f->samples);
00134    else
00135       memcpy(s->data + s->len, f->data, f->datalen);
00136    /* If either side is empty, reset the delivery time */
00137    if (!s->len || (!f->delivery.tv_sec && !f->delivery.tv_usec) ||
00138          (!s->delivery.tv_sec && !s->delivery.tv_usec))
00139       s->delivery = f->delivery;
00140    s->len += f->datalen;
00141    return 0;
00142 }

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

00529                                {
00530    int x = 0;
00531    char *ret = "unknown";
00532    for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
00533       if(AST_FORMAT_LIST[x].visible && AST_FORMAT_LIST[x].bits == codec) {
00534          ret = AST_FORMAT_LIST[x].desc;
00535          break;
00536       }
00537    }
00538    return ret;
00539 }

int ast_codec_choose ( struct ast_codec_pref pref,
int  formats,
int  find_best 
)

Definition at line 952 of file frame.c.

00953 {
00954    size_t size = 0;
00955    int x = 0, ret = 0, slot = 0;
00956 
00957    size = sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list);
00958    for (x = 0; x < size; x++) {
00959       slot = pref->order[x];
00960 
00961       if(!slot)
00962          break;
00963       if ( formats & AST_FORMAT_LIST[slot-1].bits ) {
00964          ret = AST_FORMAT_LIST[slot-1].bits;
00965          break;
00966       }
00967    }
00968    if(ret)
00969       return ret;
00970 
00971       return find_best ? ast_best_codec(formats) : 0;
00972 }

int ast_codec_pref_append ( struct ast_codec_pref pref,
int  format 
)

Definition at line 923 of file frame.c.

00924 {
00925    size_t size = 0;
00926    int x = 0, newindex = -1;
00927 
00928    ast_codec_pref_remove(pref, format);
00929    size = sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list);
00930 
00931    for (x = 0; x < size; x++) {
00932       if(AST_FORMAT_LIST[x].bits == format) {
00933          newindex = x + 1;
00934          break;
00935       }
00936    }
00937 
00938    if(newindex) {
00939       for (x = 0; x < size; x++) {
00940          if(!pref->order[x]) {
00941             pref->order[x] = newindex;
00942             break;
00943          }
00944       }
00945    }
00946 
00947    return x;
00948 }

int ast_codec_pref_index ( struct ast_codec_pref pref,
int  index 
)

Definition at line 884 of file frame.c.

00885 {
00886    int slot = 0;
00887 
00888    
00889    if((index >= 0) && (index < sizeof(pref->order))) {
00890       slot = pref->order[index];
00891    }
00892 
00893    return slot ? AST_FORMAT_LIST[slot-1].bits : 0;
00894 }

void ast_codec_pref_remove ( struct ast_codec_pref pref,
int  format 
)

Definition at line 897 of file frame.c.

00898 {
00899    struct ast_codec_pref oldorder;
00900    int x=0, y=0;
00901    size_t size = 0;
00902    int slot = 0;
00903 
00904    if(!pref->order[0])
00905       return;
00906 
00907    size = sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list);
00908 
00909    memcpy(&oldorder,pref,sizeof(struct ast_codec_pref));
00910    memset(pref,0,sizeof(struct ast_codec_pref));
00911 
00912    for (x = 0; x < size; x++) {
00913       slot = oldorder.order[x];
00914       if(! slot)
00915          break;
00916       if(AST_FORMAT_LIST[slot-1].bits != format)
00917          pref->order[y++] = slot;
00918    }
00919    
00920 }

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

Definition at line 826 of file frame.c.

00827 {
00828    int x = 0, differential = 65, mem = 0;
00829    char *from = NULL, *to = NULL;
00830 
00831    if(right) {
00832       from = pref->order;
00833       to = buf;
00834       mem = size;
00835    } else {
00836       to = pref->order;
00837       from = buf;
00838       mem = 32;
00839    }
00840 
00841    memset(to, 0, mem);
00842    for (x = 0; x < 32 ; x++) {
00843       if(!from[x])
00844          break;
00845       to[x] = right ? (from[x] + differential) : (from[x] - differential);
00846    }
00847 }

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

Definition at line 849 of file frame.c.

00850 {
00851    int x = 0, codec = 0; 
00852    size_t total_len = 0, slen = 0;
00853    char *formatname = 0;
00854    
00855    memset(buf,0,size);
00856    total_len = size;
00857    buf[0] = '(';
00858    total_len--;
00859    for(x = 0; x < 32 ; x++) {
00860       if(total_len <= 0)
00861          break;
00862       if(!(codec = ast_codec_pref_index(pref,x)))
00863          break;
00864       if((formatname = ast_getformatname(codec))) {
00865          slen = strlen(formatname);
00866          if(slen > total_len)
00867             break;
00868          strncat(buf,formatname,total_len);
00869          total_len -= slen;
00870       }
00871       if(total_len && x < 31 && ast_codec_pref_index(pref , x + 1)) {
00872          strncat(buf,"|",total_len);
00873          total_len--;
00874       }
00875    }
00876    if(total_len) {
00877       strncat(buf,")",total_len);
00878       total_len--;
00879    }
00880 
00881    return size - total_len;
00882 }

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

00397 {
00398    struct ast_frame hangup = {
00399       AST_FRAME_CONTROL,
00400       AST_CONTROL_HANGUP
00401    };
00402    return ast_fr_fdwrite(fd, &hangup);
00403 }

struct ast_frame* ast_fr_fdread ( int  fd  )  [read]

Chains a frame -- unimplemented.

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

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

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

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

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

Definition at line 627 of file frame.c.

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

struct ast_frame* ast_frdup ( struct ast_frame fr  )  [read]

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

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

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

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

struct ast_frame* ast_frisolate ( struct ast_frame fr  )  [read]

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

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

struct ast_format_list* ast_get_format_list ( size_t *  size  )  [read]

Definition at line 447 of file frame.c.

00447                                                           {
00448    *size = (sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list));
00449    return AST_FORMAT_LIST;
00450 }

struct ast_format_list* ast_get_format_list_index ( int  index  )  [read]

Definition at line 443 of file frame.c.

00443                                                              {
00444    return &AST_FORMAT_LIST[index];
00445 }

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

00512 {
00513    int x = 0, all = 0, format = 0;
00514 
00515    all = strcasecmp(name, "all") ? 0 : 1;
00516    for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
00517       if(AST_FORMAT_LIST[x].visible && (all || 
00518                                 !strcasecmp(AST_FORMAT_LIST[x].name,name) ||
00519                                 !strcasecmp(AST_FORMAT_LIST[x].name,ast_expand_codec_alias(name)))) {
00520          format |= AST_FORMAT_LIST[x].bits;
00521          if(!all)
00522             break;
00523       }
00524    }
00525 
00526    return format;
00527 }

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

00453 {
00454    int x = 0;
00455    char *ret = "unknown";
00456    for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
00457       if(AST_FORMAT_LIST[x].visible && AST_FORMAT_LIST[x].bits == format) {
00458          ret = AST_FORMAT_LIST[x].name;
00459          break;
00460       }
00461    }
00462    return ret;
00463 }

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

00465                                                                      {
00466 
00467    int x = 0;
00468    unsigned len;
00469    char *end = buf;
00470    char *start = buf;
00471    if (!size) return buf;
00472    snprintf(end, size, "0x%x (", format);
00473    len = strlen(end);
00474    end += len;
00475    size -= len;
00476    start = end;
00477    for (x = 0 ; x < sizeof(AST_FORMAT_LIST) / sizeof(struct ast_format_list) ; x++) {
00478       if (AST_FORMAT_LIST[x].visible && (AST_FORMAT_LIST[x].bits & format)) {
00479          snprintf(end, size,"%s|",AST_FORMAT_LIST[x].name);
00480          len = strlen(end);
00481          end += len;
00482          size -= len;
00483       }
00484    }
00485    if (start == end)
00486       snprintf(start, size, "nothing)");
00487    else if (size > 1)
00488       *(end -1) = ')';
00489    return buf;
00490 }

void ast_memcpy_byteswap ( void *  dst,
void *  src,
int  samples 
)

Definition at line 405 of file frame.c.

00406 {
00407    int i;
00408    unsigned short *dst_s = dst;
00409    unsigned short *src_s = src;
00410 
00411    for (i=0; i<samples; i++)
00412       dst_s[i] = (src_s[i]<<8)|(src_s[i]>>8);
00413 }

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

Definition at line 974 of file frame.c.

00975 {
00976    int format_i = 0;
00977    char *next_format = NULL, *last_format = NULL;
00978 
00979    last_format = ast_strdupa(list);
00980    while(last_format) {
00981       if((next_format = strchr(last_format, ','))) {
00982          *next_format = '\0';
00983          next_format++;
00984       }
00985       if ((format_i = ast_getformatbyname(last_format)) > 0) {
00986          if (mask) {
00987             if (allowing)
00988                (*mask) |= format_i;
00989             else
00990                (*mask) &= ~format_i;
00991          }
00992          /* can't consider 'all' a prefered codec*/
00993          if(pref && strcasecmp(last_format, "all")) {
00994             if(allowing)
00995                ast_codec_pref_append(pref, format_i);
00996             else
00997                ast_codec_pref_remove(pref, format_i);
00998          } else if(!allowing) /* disallow all must clear your prefs or it makes no sense */
00999             memset(pref, 0, sizeof(struct ast_codec_pref));
01000       } else
01001          ast_log(LOG_WARNING, "Cannot %s unknown format '%s'\n", allowing ? "allow" : "disallow", last_format);
01002 
01003       last_format = next_format;
01004    }
01005 }

void ast_smoother_free ( struct ast_smoother s  ) 

Definition at line 198 of file frame.c.

00199 {
00200    free(s);
00201 }

int ast_smoother_get_flags ( struct ast_smoother s  ) 

Definition at line 76 of file frame.c.

00077 {
00078    return s->flags;
00079 }

struct ast_smoother* ast_smoother_new ( int  size  )  [read]

Definition at line 65 of file frame.c.

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  )  [read]

Definition at line 144 of file frame.c.

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

void ast_smoother_reset ( struct ast_smoother s,
int  size 
)

Definition at line 59 of file frame.c.

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

void ast_smoother_set_flags ( struct ast_smoother s,
int  flags 
)

Definition at line 81 of file frame.c.

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

int init_framer ( void   ) 

Definition at line 813 of file frame.c.

00814 {
00815 #ifdef TRACE_FRAMES
00816    ast_cli_register(&cli_frame_stats);
00817 #endif
00818    ast_cli_register(&cli_show_codecs);
00819    ast_cli_register(&cli_show_codecs_audio);
00820    ast_cli_register(&cli_show_codecs_video);
00821    ast_cli_register(&cli_show_codecs_image);
00822    ast_cli_register(&cli_show_codec_n);
00823    return 0;   
00824 }


Variable Documentation

Initial value:

{ { "show", "codec", NULL }, show_codec_n, "Shows a specific codec", frame_show_codec_n_usage }

Definition at line 624 of file frame.c.

Initial value:

{ { "show", "codecs", NULL }, show_codecs, "Shows codecs", frame_show_codecs_usage }

Definition at line 589 of file frame.c.

Initial value:

{ { "show", "audio", "codecs", NULL }, show_codecs, "Shows audio codecs", frame_show_codecs_usage }

Definition at line 591 of file frame.c.

Initial value:

{ { "show", "image", "codecs", NULL }, show_codecs, "Shows image codecs", frame_show_codecs_usage }

Definition at line 595 of file frame.c.

Initial value:

{ { "show", "video", "codecs", NULL }, show_codecs, "Shows video codecs", frame_show_codecs_usage }

Definition at line 593 of file frame.c.


Generated on Wed Oct 28 17:00:55 2009 for Asterisk by  doxygen 1.5.6