Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions | Variables
format_ilbc.c File Reference

Save to raw, headerless iLBC data. 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_ilbc.c:

Go to the source code of this file.

Macros

#define ILBC_BUF_SIZE   50 /* One Real iLBC Frame */
 
#define ILBC_SAMPLES   240
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static struct ast_frameilbc_read (struct ast_filestream *s, int *whennext)
 
static int ilbc_seek (struct ast_filestream *fs, off_t sample_offset, int whence)
 
static off_t ilbc_tell (struct ast_filestream *fs)
 
static int ilbc_trunc (struct ast_filestream *fs)
 
static int ilbc_write (struct ast_filestream *fs, struct ast_frame *f)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Raw iLBC data" , .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 ilbc_f
 

Detailed Description

Save to raw, headerless iLBC data.

Definition in file format_ilbc.c.

Macro Definition Documentation

◆ ILBC_BUF_SIZE

#define ILBC_BUF_SIZE   50 /* One Real iLBC Frame */

Definition at line 43 of file format_ilbc.c.

Referenced by ilbc_read(), ilbc_seek(), and ilbc_tell().

◆ ILBC_SAMPLES

#define ILBC_SAMPLES   240

Definition at line 44 of file format_ilbc.c.

Referenced by ilbc_read(), ilbc_seek(), and ilbc_tell().

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 156 of file format_ilbc.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 156 of file format_ilbc.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 156 of file format_ilbc.c.

◆ ilbc_read()

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

Definition at line 46 of file format_ilbc.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, ILBC_BUF_SIZE, ILBC_SAMPLES, LOG_WARNING, NULL, ast_frame::ptr, ast_frame::samples, and ast_frame::subclass.

47 {
48  size_t res;
49 
50  /* Send a frame from the file to the appropriate channel */
52  if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
53  if (res) {
54  ast_log(LOG_WARNING, "Short read of %s data (expected %d bytes, read %zu): %s\n",
56  strerror(errno));
57  }
58  return NULL;
59  }
60  *whennext = s->fr.samples = ILBC_SAMPLES;
61  return &s->fr;
62 }
#define LOG_WARNING
Definition: logger.h:274
#define ILBC_SAMPLES
Definition: format_ilbc.c:44
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'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
#define ILBC_BUF_SIZE
Definition: format_ilbc.c:43
union ast_frame::@263 data
struct ast_format * format

◆ ilbc_seek()

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

Definition at line 78 of file format_ilbc.c.

References ast_filestream::f, ILBC_BUF_SIZE, ILBC_SAMPLES, max, min, ast_frame::offset, and SEEK_FORCECUR.

79 {
80  long bytes;
81  off_t min,cur,max,offset=0;
82  min = 0;
83  cur = ftello(fs->f);
84  fseeko(fs->f, 0, SEEK_END);
85  max = ftello(fs->f);
86 
87  bytes = ILBC_BUF_SIZE * (sample_offset / ILBC_SAMPLES);
88  if (whence == SEEK_SET)
89  offset = bytes;
90  else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
91  offset = cur + bytes;
92  else if (whence == SEEK_END)
93  offset = max - bytes;
94  if (whence != SEEK_FORCECUR) {
95  offset = (offset > max)?max:offset;
96  }
97  /* protect against seeking beyond begining. */
98  offset = (offset < min)?min:offset;
99  if (fseeko(fs->f, offset, SEEK_SET) < 0)
100  return -1;
101  return 0;
102 }
#define ILBC_SAMPLES
Definition: format_ilbc.c:44
#define ILBC_BUF_SIZE
Definition: format_ilbc.c:43
#define SEEK_FORCECUR
Definition: file.h:51
#define min(a, b)
Definition: f2c.h:197
#define max(a, b)
Definition: f2c.h:198

◆ ilbc_tell()

static off_t ilbc_tell ( struct ast_filestream fs)
static

Definition at line 121 of file format_ilbc.c.

References ast_filestream::f, ILBC_BUF_SIZE, ILBC_SAMPLES, and ast_frame::offset.

122 {
123  off_t offset = ftello(fs->f);
124  return (offset/ILBC_BUF_SIZE)*ILBC_SAMPLES;
125 }
#define ILBC_SAMPLES
Definition: format_ilbc.c:44
#define ILBC_BUF_SIZE
Definition: format_ilbc.c:43

◆ ilbc_trunc()

static int ilbc_trunc ( struct ast_filestream fs)
static

Definition at line 104 of file format_ilbc.c.

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

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

◆ ilbc_write()

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

Definition at line 64 of file format_ilbc.c.

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

65 {
66  int res;
67  if (f->datalen % 50) {
68  ast_log(LOG_WARNING, "Invalid data length, %d, should be multiple of 50\n", f->datalen);
69  return -1;
70  }
71  if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) {
72  ast_log(LOG_WARNING, "Bad write (%d/50): %s\n", res, strerror(errno));
73  return -1;
74  }
75  return 0;
76 }
#define LOG_WARNING
Definition: logger.h:274
#define ast_log
Definition: astobj2.c:42
int errno
union ast_frame::@263 data

◆ load_module()

static int load_module ( void  )
static

Definition at line 138 of file format_ilbc.c.

References ast_format_def_register, ast_format_ilbc, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and ast_format_def::format.

Referenced by unload_module().

139 {
144 }
#define ast_format_def_register(f)
Definition: mod_format.h:136
struct ast_format * format
Definition: mod_format.h:48
static struct ast_format_def ilbc_f
Definition: format_ilbc.c:127
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
struct ast_format * ast_format_ilbc
Built-in cached ilbc format.
Definition: format_cache.c:126

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 146 of file format_ilbc.c.

References ast_format_def_unregister(), AST_MODFLAG_LOAD_ORDER, AST_MODPRI_APP_DEPEND, AST_MODULE_INFO(), AST_MODULE_SUPPORT_CORE, ASTERISK_GPL_KEY, load_module(), and ast_format_def::name.

147 {
149 }
int ast_format_def_unregister(const char *name)
Unregisters a file format.
Definition: file.c:162
char name[80]
Definition: mod_format.h:44
static struct ast_format_def ilbc_f
Definition: format_ilbc.c:127

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Raw iLBC data" , .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 156 of file format_ilbc.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 156 of file format_ilbc.c.

◆ ilbc_f

struct ast_format_def ilbc_f
static

Definition at line 127 of file format_ilbc.c.