Mon May 14 04:51:12 2007

Asterisk developer's documentation


slinfactory.h File Reference

A machine to gather up arbitrary frames and convert them to raw slinear on demand. More...

#include <stdlib.h>
#include <unistd.h>
#include <string.h>

Include dependency graph for slinfactory.h:

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

Go to the source code of this file.

Data Structures

struct  ast_slinfactory

Functions

unsigned int ast_slinfactory_available (const struct ast_slinfactory *sf)
void ast_slinfactory_destroy (struct ast_slinfactory *sf)
int ast_slinfactory_feed (struct ast_slinfactory *sf, struct ast_frame *f)
void ast_slinfactory_init (struct ast_slinfactory *sf)
int ast_slinfactory_read (struct ast_slinfactory *sf, short *buf, size_t samples)


Detailed Description

A machine to gather up arbitrary frames and convert them to raw slinear on demand.

Definition in file slinfactory.h.


Function Documentation

unsigned int ast_slinfactory_available ( const struct ast_slinfactory sf  ) 

Definition at line 142 of file slinfactory.c.

References ast_slinfactory::size.

Referenced by ast_write().

00143 {
00144    return sf->size;
00145 }

void ast_slinfactory_destroy ( struct ast_slinfactory sf  ) 

Definition at line 44 of file slinfactory.c.

References ast_frfree(), AST_LIST_REMOVE_HEAD, ast_translator_free_path(), f, and ast_slinfactory::trans.

Referenced by ast_channel_whisper_stop().

00045 {
00046    struct ast_frame *f;
00047 
00048    if (sf->trans) {
00049       ast_translator_free_path(sf->trans);
00050       sf->trans = NULL;
00051    }
00052 
00053    while ((f = AST_LIST_REMOVE_HEAD(&sf->queue, frame_list)))
00054       ast_frfree(f);
00055 }

int ast_slinfactory_feed ( struct ast_slinfactory sf,
struct ast_frame f 
)

Definition at line 57 of file slinfactory.c.

References AST_FORMAT_SLINEAR, ast_frdup(), ast_getformatname(), AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), ast_translate(), ast_translator_build_path(), ast_translator_free_path(), f, ast_slinfactory::format, LOG_WARNING, ast_slinfactory::size, and ast_slinfactory::trans.

Referenced by ast_channel_whisper_feed().

00058 {
00059    struct ast_frame *begin_frame = f, *duped_frame = NULL, *frame_ptr;
00060    unsigned int x;
00061 
00062    if (f->subclass != AST_FORMAT_SLINEAR) {
00063       if (sf->trans && f->subclass != sf->format) {
00064          ast_translator_free_path(sf->trans);
00065          sf->trans = NULL;
00066       }
00067       if (!sf->trans) {
00068          if ((sf->trans = ast_translator_build_path(AST_FORMAT_SLINEAR, f->subclass)) == NULL) {
00069             ast_log(LOG_WARNING, "Cannot build a path from %s to slin\n", ast_getformatname(f->subclass));
00070             return 0;
00071          } else {
00072             sf->format = f->subclass;
00073          }
00074       }
00075    }
00076 
00077    if ((sf->trans && (!(begin_frame = ast_translate(sf->trans, f, 0)))) || (!(duped_frame = ast_frdup(begin_frame))))
00078       return 0;
00079 
00080    x = 0;
00081    AST_LIST_TRAVERSE(&sf->queue, frame_ptr, frame_list)
00082       x++;
00083 
00084    AST_LIST_INSERT_TAIL(&sf->queue, duped_frame, frame_list);
00085 
00086    sf->size += duped_frame->samples;
00087 
00088    return x;
00089 }

void ast_slinfactory_init ( struct ast_slinfactory sf  ) 

Definition at line 38 of file slinfactory.c.

Referenced by ast_channel_whisper_start().

00039 {
00040    memset(sf, 0, sizeof(*sf));
00041    sf->offset = sf->hold;
00042 }

int ast_slinfactory_read ( struct ast_slinfactory sf,
short *  buf,
size_t  samples 
)

Definition at line 91 of file slinfactory.c.

References ast_frfree(), AST_LIST_REMOVE_HEAD, ast_frame::data, ast_slinfactory::hold, ast_slinfactory::holdlen, ast_slinfactory::offset, offset, ast_frame::samples, and ast_slinfactory::size.

Referenced by ast_write().

00092 {
00093    struct ast_frame *frame_ptr;
00094    unsigned int sofar = 0, ineed, remain;
00095    short *frame_data, *offset = buf;
00096 
00097    while (sofar < samples) {
00098       ineed = samples - sofar;
00099 
00100       if (sf->holdlen) {
00101          if ((sofar + sf->holdlen) <= ineed) {
00102             memcpy(offset, sf->hold, sf->holdlen * sizeof(*offset));
00103             sofar += sf->holdlen;
00104             offset += sf->holdlen;
00105             sf->holdlen = 0;
00106             sf->offset = sf->hold;
00107          } else {
00108             remain = sf->holdlen - ineed;
00109             memcpy(offset, sf->offset, ineed * sizeof(*offset));
00110             sofar += ineed;
00111             sf->offset += ineed;
00112             sf->holdlen = remain;
00113          }
00114          continue;
00115       }
00116       
00117       if ((frame_ptr = AST_LIST_REMOVE_HEAD(&sf->queue, frame_list))) {
00118          frame_data = frame_ptr->data;
00119          
00120          if ((sofar + frame_ptr->samples) <= ineed) {
00121             memcpy(offset, frame_data, frame_ptr->samples * sizeof(*offset));
00122             sofar += frame_ptr->samples;
00123             offset += frame_ptr->samples;
00124          } else {
00125             remain = frame_ptr->samples - ineed;
00126             memcpy(offset, frame_data, ineed * sizeof(*offset));
00127             sofar += ineed;
00128             frame_data += ineed;
00129             memcpy(sf->hold, frame_data, remain * sizeof(*offset));
00130             sf->holdlen = remain;
00131          }
00132          ast_frfree(frame_ptr);
00133       } else {
00134          break;
00135       }
00136    }
00137 
00138    sf->size -= sofar;
00139    return sofar;
00140 }


Generated on Mon May 14 04:51:12 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1