Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
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 "asterisk/format_cache.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)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static struct ast_framegeneric_read (struct ast_filestream *s, int *whennext, unsigned int buf_size)
 
static int load_module (void)
 
static struct ast_frameslinear12_read (struct ast_filestream *s, int *whennext)
 
static struct ast_frameslinear16_read (struct ast_filestream *s, int *whennext)
 
static struct ast_frameslinear192_read (struct ast_filestream *s, int *whennext)
 
static struct ast_frameslinear24_read (struct ast_filestream *s, int *whennext)
 
static struct ast_frameslinear32_read (struct ast_filestream *s, int *whennext)
 
static struct ast_frameslinear44_read (struct ast_filestream *s, int *whennext)
 
static struct ast_frameslinear48_read (struct ast_filestream *s, int *whennext)
 
static struct ast_frameslinear96_read (struct ast_filestream *s, int *whennext)
 
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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND }
 
static const 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

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 289 of file format_sln.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 289 of file format_sln.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 289 of file format_sln.c.

◆ generic_read()

static struct ast_frame* generic_read ( struct ast_filestream s,
int *  whennext,
unsigned int  buf_size 
)
static

Definition at line 35 of file format_sln.c.

References ast_format_get_name(), AST_FRAME_SET_BUFFER, 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, LOG_WARNING, NULL, 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().

36 {
37  size_t res;
38 
39  /* Send a frame from the file to the appropriate channel */
40  AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, buf_size);
41  if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) < 1) {
42  if (res) {
43  ast_log(LOG_WARNING, "Short read of %s data (expected %d bytes, read %zu): %s\n",
45  strerror(errno));
46  }
47  return NULL;
48  }
49  *whennext = s->fr.samples = res/2;
50  s->fr.datalen = res;
51  return &s->fr;
52 }
#define LOG_WARNING
Definition: logger.h:274
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
#define NULL
Definition: resample.c:96
struct ast_frame_subclass subclass
#define ast_log
Definition: astobj2.c:42
#define AST_FRIENDLY_OFFSET
Offset into a frame&#39;s data buffer.
struct ast_frame fr
frame produced by read, typically
Definition: mod_format.h:122
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
int errno
union ast_frame::@263 data
struct ast_format * format

◆ load_module()

static int load_module ( void  )
static

Definition at line 260 of file format_sln.c.

References ARRAY_LEN, ast_format_def_register, ast_format_slin, ast_format_slin12, ast_format_slin16, ast_format_slin192, ast_format_slin24, ast_format_slin32, ast_format_slin44, ast_format_slin48, ast_format_slin96, AST_MODFLAG_LOAD_ORDER, AST_MODPRI_APP_DEPEND, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_CORE, ASTERISK_GPL_KEY, ast_format_def::format, and unload_module().

261 {
262  int i;
263 
273 
274  for (i = 0; i < ARRAY_LEN(slin_list); i++) {
276  unload_module();
278  }
279  }
280 
282 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
struct ast_format * ast_format_slin192
Built-in cached signed linear 192kHz format.
Definition: format_cache.c:81
struct ast_format * ast_format_slin32
Built-in cached signed linear 32kHz format.
Definition: format_cache.c:61
struct ast_format * ast_format_slin96
Built-in cached signed linear 96kHz format.
Definition: format_cache.c:76
static struct ast_format_def * slin_list[]
Definition: format_sln.c:235
struct ast_format * ast_format_slin24
Built-in cached signed linear 24kHz format.
Definition: format_cache.c:56
static struct ast_format_def slin_f
Definition: format_sln.c:128
static struct ast_format_def slin48_f
Definition: format_sln.c:200
static int unload_module(void)
Definition: format_sln.c:247
struct ast_format * ast_format_slin12
Built-in cached signed linear 12kHz format.
Definition: format_cache.c:46
static struct ast_format_def slin12_f
Definition: format_sln.c:140
#define ast_format_def_register(f)
Definition: mod_format.h:136
static struct ast_format_def slin96_f
Definition: format_sln.c:212
struct ast_format * format
Definition: mod_format.h:48
static struct ast_format_def slin16_f
Definition: format_sln.c:152
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static struct ast_format_def slin44_f
Definition: format_sln.c:188
struct ast_format * ast_format_slin44
Built-in cached signed linear 44kHz format.
Definition: format_cache.c:66
struct ast_format * ast_format_slin16
Built-in cached signed linear 16kHz format.
Definition: format_cache.c:51
static struct ast_format_def slin192_f
Definition: format_sln.c:224
static struct ast_format_def slin24_f
Definition: format_sln.c:164
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
struct ast_format * ast_format_slin48
Built-in cached signed linear 48kHz format.
Definition: format_cache.c:71
static struct ast_format_def slin32_f
Definition: format_sln.c:176

◆ slinear12_read()

static struct ast_frame* slinear12_read ( struct ast_filestream s,
int *  whennext 
)
static

Definition at line 139 of file format_sln.c.

References generic_read().

139 {return generic_read(s, whennext, 480);}
static struct ast_frame * generic_read(struct ast_filestream *s, int *whennext, unsigned int buf_size)
Definition: format_sln.c:35

◆ slinear16_read()

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

Definition at line 151 of file format_sln.c.

References generic_read().

151 {return generic_read(s, whennext, 640);}
static struct ast_frame * generic_read(struct ast_filestream *s, int *whennext, unsigned int buf_size)
Definition: format_sln.c:35

◆ slinear192_read()

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

Definition at line 223 of file format_sln.c.

References generic_read().

223 {return generic_read(s, whennext, 7680);}
static struct ast_frame * generic_read(struct ast_filestream *s, int *whennext, unsigned int buf_size)
Definition: format_sln.c:35

◆ slinear24_read()

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

Definition at line 163 of file format_sln.c.

References generic_read().

163 {return generic_read(s, whennext, 960);}
static struct ast_frame * generic_read(struct ast_filestream *s, int *whennext, unsigned int buf_size)
Definition: format_sln.c:35

◆ slinear32_read()

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

Definition at line 175 of file format_sln.c.

References generic_read().

175 {return generic_read(s, whennext, 1280);}
static struct ast_frame * generic_read(struct ast_filestream *s, int *whennext, unsigned int buf_size)
Definition: format_sln.c:35

◆ slinear44_read()

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

Definition at line 187 of file format_sln.c.

References generic_read().

187 {return generic_read(s, whennext, 1764);}
static struct ast_frame * generic_read(struct ast_filestream *s, int *whennext, unsigned int buf_size)
Definition: format_sln.c:35

◆ slinear48_read()

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

Definition at line 199 of file format_sln.c.

References generic_read().

199 {return generic_read(s, whennext, 1920);}
static struct ast_frame * generic_read(struct ast_filestream *s, int *whennext, unsigned int buf_size)
Definition: format_sln.c:35

◆ slinear96_read()

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

Definition at line 211 of file format_sln.c.

References generic_read().

211 {return generic_read(s, whennext, 3840);}
static struct ast_frame * generic_read(struct ast_filestream *s, int *whennext, unsigned int buf_size)
Definition: format_sln.c:35

◆ slinear_read()

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

Definition at line 127 of file format_sln.c.

References generic_read().

127 {return generic_read(s, whennext, 320);}
static struct ast_frame * generic_read(struct ast_filestream *s, int *whennext, unsigned int buf_size)
Definition: format_sln.c:35

◆ slinear_seek()

static int slinear_seek ( struct ast_filestream fs,
off_t  sample_offset,
int  whence 
)
static

Definition at line 70 of file format_sln.c.

References ast_log, AST_LOG_WARNING, errno, ast_filestream::f, max, min, ast_frame::offset, and SEEK_FORCECUR.

71 {
72  off_t offset=0, min = 0, cur, max;
73 
74  sample_offset <<= 1;
75 
76  if ((cur = ftello(fs->f)) < 0) {
77  ast_log(AST_LOG_WARNING, "Unable to determine current position in sln filestream %p: %s\n", fs, strerror(errno));
78  return -1;
79  }
80 
81  if (fseeko(fs->f, 0, SEEK_END) < 0) {
82  ast_log(AST_LOG_WARNING, "Unable to seek to end of sln filestream %p: %s\n", fs, strerror(errno));
83  return -1;
84  }
85 
86  if ((max = ftello(fs->f)) < 0) {
87  ast_log(AST_LOG_WARNING, "Unable to determine max position in sln filestream %p: %s\n", fs, strerror(errno));
88  return -1;
89  }
90 
91  if (whence == SEEK_SET)
92  offset = sample_offset;
93  else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
94  offset = sample_offset + cur;
95  else if (whence == SEEK_END)
96  offset = max - sample_offset;
97  if (whence != SEEK_FORCECUR) {
98  offset = (offset > max)?max:offset;
99  }
100  /* always protect against seeking past begining. */
101  offset = (offset < min)?min:offset;
102  return fseeko(fs->f, offset, SEEK_SET);
103 }
#define AST_LOG_WARNING
Definition: logger.h:279
#define ast_log
Definition: astobj2.c:42
int errno
#define SEEK_FORCECUR
Definition: file.h:51
#define min(a, b)
Definition: f2c.h:197
#define max(a, b)
Definition: f2c.h:198

◆ slinear_tell()

static off_t slinear_tell ( struct ast_filestream fs)
static

Definition at line 122 of file format_sln.c.

References ast_filestream::f.

123 {
124  return ftello(fs->f) / 2;
125 }

◆ slinear_trunc()

static int slinear_trunc ( struct ast_filestream fs)
static

Definition at line 105 of file format_sln.c.

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

106 {
107  int fd;
108  off_t cur;
109 
110  if ((fd = fileno(fs->f)) < 0) {
111  ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for sln filestream %p: %s\n", fs, strerror(errno));
112  return -1;
113  }
114  if ((cur = ftello(fs->f)) < 0) {
115  ast_log(AST_LOG_WARNING, "Unable to determine current position in sln filestream %p: %s\n", fs, strerror(errno));
116  return -1;
117  }
118  /* Truncate file to current length */
119  return ftruncate(fd, cur);
120 }
#define AST_LOG_WARNING
Definition: logger.h:279
#define ast_log
Definition: astobj2.c:42
int errno

◆ slinear_write()

static int slinear_write ( struct ast_filestream fs,
struct ast_frame f 
)
static

Definition at line 54 of file format_sln.c.

References ast_log, ast_frame::data, ast_frame::datalen, errno, ast_filestream::f, LOG_WARNING, and ast_frame::ptr.

55 {
56  int res;
57 
58  /* Don't try to write an interpolated frame */
59  if (f->datalen == 0) {
60  return 0;
61  }
62 
63  if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) {
64  ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
65  return -1;
66  }
67  return 0;
68 }
#define LOG_WARNING
Definition: logger.h:274
#define ast_log
Definition: astobj2.c:42
int errno
union ast_frame::@263 data

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 247 of file format_sln.c.

References ARRAY_LEN, ast_format_def_unregister(), and name.

Referenced by load_module().

248 {
249  int res = 0;
250  int i = 0;
251 
252  for (i = 0; i < ARRAY_LEN(slin_list); i++) {
254  res = -1;
255  }
256  }
257  return res;
258 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct ast_format_def * slin_list[]
Definition: format_sln.c:235
int ast_format_def_unregister(const char *name)
Unregisters a file format.
Definition: file.c:162
static const char name[]
Definition: cdr_mysql.c:74

Variable Documentation

◆ __mod_info

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND }
static

Definition at line 289 of file format_sln.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 289 of file format_sln.c.

◆ slin12_f

struct ast_format_def slin12_f
static

Definition at line 140 of file format_sln.c.

◆ slin16_f

struct ast_format_def slin16_f
static

Definition at line 152 of file format_sln.c.

◆ slin192_f

struct ast_format_def slin192_f
static

Definition at line 224 of file format_sln.c.

◆ slin24_f

struct ast_format_def slin24_f
static

Definition at line 164 of file format_sln.c.

◆ slin32_f

struct ast_format_def slin32_f
static

Definition at line 176 of file format_sln.c.

◆ slin44_f

struct ast_format_def slin44_f
static

Definition at line 188 of file format_sln.c.

◆ slin48_f

struct ast_format_def slin48_f
static

Definition at line 200 of file format_sln.c.

◆ slin96_f

struct ast_format_def slin96_f
static

Definition at line 212 of file format_sln.c.

◆ slin_f

struct ast_format_def slin_f
static

Definition at line 128 of file format_sln.c.

◆ slin_list

struct ast_format_def* slin_list[]
static

Definition at line 235 of file format_sln.c.