Sat Apr 26 2014 22:02:50

Asterisk developer's documentation


format_sln.c File Reference

RAW SLINEAR Formats. More...

#include "asterisk.h"
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
Include dependency graph for format_sln.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
static struct ast_framegeneric_read (struct ast_filestream *s, int *whennext, unsigned int buf_size, enum ast_format_id id)
static int generic_write (struct ast_filestream *fs, struct ast_frame *f, enum ast_format_id id)
static int load_module (void)
static struct ast_frameslinear12_read (struct ast_filestream *s, int *whennext)
static int slinear12_write (struct ast_filestream *fs, struct ast_frame *f)
static struct ast_frameslinear16_read (struct ast_filestream *s, int *whennext)
static int slinear16_write (struct ast_filestream *fs, struct ast_frame *f)
static struct ast_frameslinear192_read (struct ast_filestream *s, int *whennext)
static int slinear192_write (struct ast_filestream *fs, struct ast_frame *f)
static struct ast_frameslinear24_read (struct ast_filestream *s, int *whennext)
static int slinear24_write (struct ast_filestream *fs, struct ast_frame *f)
static struct ast_frameslinear32_read (struct ast_filestream *s, int *whennext)
static int slinear32_write (struct ast_filestream *fs, struct ast_frame *f)
static struct ast_frameslinear44_read (struct ast_filestream *s, int *whennext)
static int slinear44_write (struct ast_filestream *fs, struct ast_frame *f)
static struct ast_frameslinear48_read (struct ast_filestream *s, int *whennext)
static int slinear48_write (struct ast_filestream *fs, struct ast_frame *f)
static struct ast_frameslinear96_read (struct ast_filestream *s, int *whennext)
static int slinear96_write (struct ast_filestream *fs, struct ast_frame *f)
static struct ast_frameslinear_read (struct ast_filestream *s, int *whennext)
static int slinear_seek (struct ast_filestream *fs, off_t sample_offset, int whence)
static off_t slinear_tell (struct ast_filestream *fs)
static int slinear_trunc (struct ast_filestream *fs)
static int slinear_write (struct ast_filestream *fs, struct ast_frame *f)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Raw Signed Linear Audio support (SLN) 8khz-192khz" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND }
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_format_def slin12_f
static struct ast_format_def slin16_f
static struct ast_format_def slin192_f
static struct ast_format_def slin24_f
static struct ast_format_def slin32_f
static struct ast_format_def slin44_f
static struct ast_format_def slin48_f
static struct ast_format_def slin96_f
static struct ast_format_def slin_f
static struct ast_format_defslin_list []

Detailed Description

RAW SLINEAR Formats.

Definition in file format_sln.c.


Function Documentation

static void __reg_module ( void  ) [static]

Definition at line 298 of file format_sln.c.

static void __unreg_module ( void  ) [static]

Definition at line 298 of file format_sln.c.

static struct ast_frame* generic_read ( struct ast_filestream s,
int *  whennext,
unsigned int  buf_size,
enum ast_format_id  id 
) [static, read]

Definition at line 36 of file format_sln.c.

References ast_format_set(), AST_FRAME_SET_BUFFER, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_filestream::buf, ast_frame::data, ast_frame::datalen, errno, ast_filestream::f, ast_frame_subclass::format, ast_filestream::fr, ast_frame::frametype, LOG_WARNING, ast_frame::mallocd, ast_frame::ptr, ast_frame::samples, and ast_frame::subclass.

Referenced by slinear12_read(), slinear16_read(), slinear192_read(), slinear24_read(), slinear32_read(), slinear44_read(), slinear48_read(), slinear96_read(), and slinear_read().

{
   int res;
   /* Send a frame from the file to the appropriate channel */

   s->fr.frametype = AST_FRAME_VOICE;
   ast_format_set(&s->fr.subclass.format, id, 0);
   s->fr.mallocd = 0;
   AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, buf_size);
   if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) < 1) {
      if (res)
         ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
      return NULL;
   }
   *whennext = s->fr.samples = res/2;
   s->fr.datalen = res;
   return &s->fr;
}
static int generic_write ( struct ast_filestream fs,
struct ast_frame f,
enum ast_format_id  id 
) [static]

Definition at line 55 of file format_sln.c.

References AST_FRAME_VOICE, ast_getformatname(), ast_log(), ast_frame::data, ast_frame::datalen, errno, ast_filestream::f, ast_frame_subclass::format, ast_frame::frametype, ast_format::id, LOG_WARNING, ast_frame::ptr, and ast_frame::subclass.

Referenced by slinear12_write(), slinear16_write(), slinear192_write(), slinear24_write(), slinear32_write(), slinear44_write(), slinear48_write(), slinear96_write(), and slinear_write().

{
   int res;
   if (f->frametype != AST_FRAME_VOICE) {
      ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
      return -1;
   }
   if (f->subclass.format.id != id) {
      ast_log(LOG_WARNING, "Asked to write non-slinear frame (%s)!\n", ast_getformatname(&f->subclass.format));
      return -1;
   }
   if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) {
         ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
         return -1;
   }
   return 0;
}
static struct ast_frame* slinear12_read ( struct ast_filestream s,
int *  whennext 
) [static, read]

Definition at line 144 of file format_sln.c.

References AST_FORMAT_SLINEAR12, and generic_read().

{return generic_read(s, whennext, 480, AST_FORMAT_SLINEAR12);}
static int slinear12_write ( struct ast_filestream fs,
struct ast_frame f 
) [static]

Definition at line 143 of file format_sln.c.

References AST_FORMAT_SLINEAR12, and generic_write().

static struct ast_frame* slinear16_read ( struct ast_filestream s,
int *  whennext 
) [static, read]

Definition at line 157 of file format_sln.c.

References AST_FORMAT_SLINEAR16, and generic_read().

{return generic_read(s, whennext, 640, AST_FORMAT_SLINEAR16);}
static int slinear16_write ( struct ast_filestream fs,
struct ast_frame f 
) [static]

Definition at line 156 of file format_sln.c.

References AST_FORMAT_SLINEAR16, and generic_write().

static struct ast_frame* slinear192_read ( struct ast_filestream s,
int *  whennext 
) [static, read]

Definition at line 235 of file format_sln.c.

References AST_FORMAT_SLINEAR192, and generic_read().

{return generic_read(s, whennext, 7680, AST_FORMAT_SLINEAR192);}
static int slinear192_write ( struct ast_filestream fs,
struct ast_frame f 
) [static]

Definition at line 234 of file format_sln.c.

References AST_FORMAT_SLINEAR192, and generic_write().

static struct ast_frame* slinear24_read ( struct ast_filestream s,
int *  whennext 
) [static, read]

Definition at line 170 of file format_sln.c.

References AST_FORMAT_SLINEAR24, and generic_read().

{return generic_read(s, whennext, 960, AST_FORMAT_SLINEAR24);}
static int slinear24_write ( struct ast_filestream fs,
struct ast_frame f 
) [static]

Definition at line 169 of file format_sln.c.

References AST_FORMAT_SLINEAR24, and generic_write().

static struct ast_frame* slinear32_read ( struct ast_filestream s,
int *  whennext 
) [static, read]

Definition at line 183 of file format_sln.c.

References AST_FORMAT_SLINEAR32, and generic_read().

{return generic_read(s, whennext, 1280, AST_FORMAT_SLINEAR32);}
static int slinear32_write ( struct ast_filestream fs,
struct ast_frame f 
) [static]

Definition at line 182 of file format_sln.c.

References AST_FORMAT_SLINEAR32, and generic_write().

static struct ast_frame* slinear44_read ( struct ast_filestream s,
int *  whennext 
) [static, read]

Definition at line 196 of file format_sln.c.

References AST_FORMAT_SLINEAR44, and generic_read().

{return generic_read(s, whennext, 1764, AST_FORMAT_SLINEAR44);}
static int slinear44_write ( struct ast_filestream fs,
struct ast_frame f 
) [static]

Definition at line 195 of file format_sln.c.

References AST_FORMAT_SLINEAR44, and generic_write().

static struct ast_frame* slinear48_read ( struct ast_filestream s,
int *  whennext 
) [static, read]

Definition at line 209 of file format_sln.c.

References AST_FORMAT_SLINEAR48, and generic_read().

{return generic_read(s, whennext, 1920, AST_FORMAT_SLINEAR48);}
static int slinear48_write ( struct ast_filestream fs,
struct ast_frame f 
) [static]

Definition at line 208 of file format_sln.c.

References AST_FORMAT_SLINEAR48, and generic_write().

static struct ast_frame* slinear96_read ( struct ast_filestream s,
int *  whennext 
) [static, read]

Definition at line 222 of file format_sln.c.

References AST_FORMAT_SLINEAR96, and generic_read().

{return generic_read(s, whennext, 3840, AST_FORMAT_SLINEAR96);}
static int slinear96_write ( struct ast_filestream fs,
struct ast_frame f 
) [static]

Definition at line 221 of file format_sln.c.

References AST_FORMAT_SLINEAR96, and generic_write().

static struct ast_frame* slinear_read ( struct ast_filestream s,
int *  whennext 
) [static, read]

Definition at line 131 of file format_sln.c.

References AST_FORMAT_SLINEAR, and generic_read().

{return generic_read(s, whennext, 320, AST_FORMAT_SLINEAR);}
static int slinear_seek ( struct ast_filestream fs,
off_t  sample_offset,
int  whence 
) [static]

Definition at line 73 of file format_sln.c.

References ast_log(), AST_LOG_WARNING, errno, ast_filestream::f, ast_frame::offset, and SEEK_FORCECUR.

{
   off_t offset=0, min = 0, cur, max;

   sample_offset <<= 1;

   if ((cur = ftello(fs->f)) < 0) {
      ast_log(AST_LOG_WARNING, "Unable to determine current position in sln filestream %p: %s\n", fs, strerror(errno));
      return -1;
   }

   if (fseeko(fs->f, 0, SEEK_END) < 0) {
      ast_log(AST_LOG_WARNING, "Unable to seek to end of sln filestream %p: %s\n", fs, strerror(errno));
      return -1;
   }

   if ((max = ftello(fs->f)) < 0) {
      ast_log(AST_LOG_WARNING, "Unable to determine max position in sln filestream %p: %s\n", fs, strerror(errno));
      return -1;
   }

   if (whence == SEEK_SET)
      offset = sample_offset;
   else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
      offset = sample_offset + cur;
   else if (whence == SEEK_END)
      offset = max - sample_offset;
   if (whence != SEEK_FORCECUR) {
      offset = (offset > max)?max:offset;
   }
   /* always protect against seeking past begining. */
   offset = (offset < min)?min:offset;
   return fseeko(fs->f, offset, SEEK_SET);
}
static off_t slinear_tell ( struct ast_filestream fs) [static]

Definition at line 125 of file format_sln.c.

References ast_filestream::f.

{
   return ftello(fs->f) / 2;
}
static int slinear_trunc ( struct ast_filestream fs) [static]

Definition at line 108 of file format_sln.c.

References ast_log(), AST_LOG_WARNING, errno, and ast_filestream::f.

{
   int fd;
   off_t cur;

   if ((fd = fileno(fs->f)) < 0) {
      ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for sln filestream %p: %s\n", fs, strerror(errno));
      return -1;
   }
   if ((cur = ftello(fs->f)) < 0) {
      ast_log(AST_LOG_WARNING, "Unable to determine current position in sln filestream %p: %s\n", fs, strerror(errno));
      return -1;
   }
   /* Truncate file to current length */
   return ftruncate(fd, cur);
}
static int slinear_write ( struct ast_filestream fs,
struct ast_frame f 
) [static]

Definition at line 130 of file format_sln.c.

References AST_FORMAT_SLINEAR, and generic_write().

static int unload_module ( void  ) [static]

Definition at line 281 of file format_sln.c.

References ARRAY_LEN, ast_format_def_unregister(), AST_MODULE_LOAD_FAILURE, and name.

{
   int res = 0;
   int i = 0;

   for (i = 0; i < ARRAY_LEN(slin_list); i++) {
      if (ast_format_def_unregister(slin_list[i]->name)) {
         res |= AST_MODULE_LOAD_FAILURE;
      }
   }
   return res;
}

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Raw Signed Linear Audio support (SLN) 8khz-192khz" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND } [static]

Definition at line 298 of file format_sln.c.

Definition at line 298 of file format_sln.c.

struct ast_format_def slin12_f [static]

Definition at line 145 of file format_sln.c.

struct ast_format_def slin16_f [static]

Definition at line 158 of file format_sln.c.

struct ast_format_def slin192_f [static]

Definition at line 236 of file format_sln.c.

struct ast_format_def slin24_f [static]

Definition at line 171 of file format_sln.c.

struct ast_format_def slin32_f [static]

Definition at line 184 of file format_sln.c.

struct ast_format_def slin44_f [static]

Definition at line 197 of file format_sln.c.

struct ast_format_def slin48_f [static]

Definition at line 210 of file format_sln.c.

struct ast_format_def slin96_f [static]

Definition at line 223 of file format_sln.c.

struct ast_format_def slin_f [static]

Definition at line 132 of file format_sln.c.

struct ast_format_def* slin_list[] [static]

Definition at line 247 of file format_sln.c.