Wed Jan 8 2020 09:50:12

Asterisk developer's documentation


format_pcm.c File Reference

Flat, binary, ulaw PCM file format. More...

#include "asterisk.h"
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
#include "asterisk/ulaw.h"
#include "asterisk/alaw.h"

Go to the source code of this file.

Macros

#define AU_ENC_8BIT_ULAW   1
 
#define AU_HDR_CHANNELS_OFF   5
 
#define AU_HDR_DATA_SIZE_OFF   2
 
#define AU_HDR_ENCODING_OFF   3
 
#define AU_HDR_HDR_SIZE_OFF   1
 
#define AU_HDR_MAGIC_OFF   0
 
#define AU_HDR_SAMPLE_RATE_OFF   4
 
#define AU_HEADER(var)   uint32_t var[6]
 
#define AU_HEADER_SIZE   24
 
#define AU_MAGIC   0x2e736e64
 
#define BUF_SIZE   160 /* 160 bytes, and same number of samples */
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int au_open (struct ast_filestream *s)
 
static int au_rewrite (struct ast_filestream *s, const char *comment)
 
static int au_seek (struct ast_filestream *fs, off_t sample_offset, int whence)
 
static off_t au_tell (struct ast_filestream *fs)
 
static int au_trunc (struct ast_filestream *fs)
 
static int check_header (FILE *f)
 
static int load_module (void)
 
static struct ast_framepcm_read (struct ast_filestream *s, int *whennext)
 
static int pcm_seek (struct ast_filestream *fs, off_t sample_offset, int whence)
 
static off_t pcm_tell (struct ast_filestream *fs)
 
static int pcm_trunc (struct ast_filestream *fs)
 
static int pcm_write (struct ast_filestream *fs, struct ast_frame *f)
 
static int unload_module (void)
 
static int update_header (FILE *f)
 
static int write_header (FILE *f)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Raw/Sun uLaw/ALaw 8KHz (PCM,PCMA,AU), G.722 16Khz" , .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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND }
 
static struct ast_format alaw_f
 
static char alaw_silence [BUF_SIZE]
 
static struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_format au_f
 
static struct ast_format g722_f
 
static struct ast_format pcm_f
 
static char ulaw_silence [BUF_SIZE]
 

Detailed Description

Flat, binary, ulaw PCM file format.

  • File name extension: alaw, al, alw, pcm, ulaw, ul, mu, ulw, g722, au

Definition in file format_pcm.c.

Macro Definition Documentation

#define AU_ENC_8BIT_ULAW   1

Definition at line 257 of file format_pcm.c.

Referenced by check_header(), and write_header().

#define AU_HDR_CHANNELS_OFF   5

Definition at line 255 of file format_pcm.c.

Referenced by check_header(), and write_header().

#define AU_HDR_DATA_SIZE_OFF   2

Definition at line 252 of file format_pcm.c.

Referenced by update_header(), and write_header().

#define AU_HDR_ENCODING_OFF   3

Definition at line 253 of file format_pcm.c.

Referenced by check_header(), and write_header().

#define AU_HDR_HDR_SIZE_OFF   1

Definition at line 251 of file format_pcm.c.

Referenced by check_header(), and write_header().

#define AU_HDR_MAGIC_OFF   0

Definition at line 250 of file format_pcm.c.

Referenced by check_header(), and write_header().

#define AU_HDR_SAMPLE_RATE_OFF   4

Definition at line 254 of file format_pcm.c.

Referenced by check_header(), and write_header().

#define AU_HEADER (   var)    uint32_t var[6]

Definition at line 248 of file format_pcm.c.

Referenced by check_header(), and write_header().

#define AU_HEADER_SIZE   24

Definition at line 247 of file format_pcm.c.

Referenced by au_seek(), au_tell(), check_header(), update_header(), and write_header().

#define AU_MAGIC   0x2e736e64

Definition at line 259 of file format_pcm.c.

Referenced by check_header(), and write_header().

#define BUF_SIZE   160 /* 160 bytes, and same number of samples */

Definition at line 41 of file format_pcm.c.

Referenced by pcm_read(), and pcm_seek().

Function Documentation

static void __reg_module ( void  )
static

Definition at line 550 of file format_pcm.c.

static void __unreg_module ( void  )
static

Definition at line 550 of file format_pcm.c.

static int au_open ( struct ast_filestream s)
static

Definition at line 382 of file format_pcm.c.

References check_header(), and ast_filestream::f.

383 {
384  if (check_header(s->f) < 0)
385  return -1;
386  return 0;
387 }
static int check_header(FILE *f)
Definition: format_pcm.c:282
static int au_rewrite ( struct ast_filestream s,
const char *  comment 
)
static

Definition at line 389 of file format_pcm.c.

References ast_filestream::f, and write_header().

390 {
391  if (write_header(s->f))
392  return -1;
393  return 0;
394 }
static int write_header(FILE *f)
Definition: format_pcm.c:362
static int au_seek ( struct ast_filestream fs,
off_t  sample_offset,
int  whence 
)
static

Definition at line 397 of file format_pcm.c.

References AST_FORMAT_G722, ast_log(), AST_LOG_WARNING, AU_HEADER_SIZE, errno, ast_filestream::f, ast_filestream::fmt, ast_format::format, and SEEK_FORCECUR.

398 {
399  off_t min = AU_HEADER_SIZE, max, cur;
400  long offset = 0, bytes;
401 
402  if (fs->fmt->format == AST_FORMAT_G722)
403  bytes = sample_offset / 2;
404  else
405  bytes = sample_offset;
406 
407  if ((cur = ftello(fs->f)) < 0) {
408  ast_log(AST_LOG_WARNING, "Unable to determine current position in au filestream %p: %s\n", fs, strerror(errno));
409  return -1;
410  }
411 
412  if (fseeko(fs->f, 0, SEEK_END) < 0) {
413  ast_log(AST_LOG_WARNING, "Unable to seek to end of au filestream %p: %s\n", fs, strerror(errno));
414  return -1;
415  }
416 
417  if ((max = ftello(fs->f)) < 0) {
418  ast_log(AST_LOG_WARNING, "Unable to determine max position in au filestream %p: %s\n", fs, strerror(errno));
419  return -1;
420  }
421 
422  if (whence == SEEK_SET)
423  offset = bytes + min;
424  else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
425  offset = bytes + cur;
426  else if (whence == SEEK_END)
427  offset = max - bytes;
428 
429  if (whence != SEEK_FORCECUR) {
430  offset = (offset > max) ? max : offset;
431  }
432 
433  /* always protect the header space. */
434  offset = (offset < min) ? min : offset;
435 
436  return fseeko(fs->f, offset, SEEK_SET);
437 }
#define AST_LOG_WARNING
Definition: logger.h:149
format_t format
Definition: mod_format.h:47
struct ast_format * fmt
Definition: mod_format.h:102
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
#define SEEK_FORCECUR
Definition: file.h:50
#define AU_HEADER_SIZE
Definition: format_pcm.c:247
#define AST_FORMAT_G722
Definition: frame.h:266
static off_t au_tell ( struct ast_filestream fs)
static

Definition at line 459 of file format_pcm.c.

References AU_HEADER_SIZE, and ast_filestream::f.

460 {
461  off_t offset = ftello(fs->f);
462  return offset - AU_HEADER_SIZE;
463 }
#define AU_HEADER_SIZE
Definition: format_pcm.c:247
static int au_trunc ( struct ast_filestream fs)
static

Definition at line 439 of file format_pcm.c.

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

440 {
441  int fd;
442  off_t cur;
443 
444  if ((fd = fileno(fs->f)) < 0) {
445  ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for au filestream %p: %s\n", fs, strerror(errno));
446  return -1;
447  }
448  if ((cur = ftello(fs->f)) < 0) {
449  ast_log(AST_LOG_WARNING, "Unable to determine current position in au filestream %p: %s\n", fs, strerror(errno));
450  return -1;
451  }
452  /* Truncate file to current length */
453  if (ftruncate(fd, cur)) {
454  return -1;
455  }
456  return update_header(fs->f);
457 }
#define AST_LOG_WARNING
Definition: logger.h:149
static int update_header(FILE *f)
Definition: format_pcm.c:330
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
static int check_header ( FILE *  f)
static

Definition at line 282 of file format_pcm.c.

References ast_log(), AU_ENC_8BIT_ULAW, AU_HDR_CHANNELS_OFF, AU_HDR_ENCODING_OFF, AU_HDR_HDR_SIZE_OFF, AU_HDR_MAGIC_OFF, AU_HDR_SAMPLE_RATE_OFF, AU_HEADER, AU_HEADER_SIZE, AU_MAGIC, channels, DEFAULT_SAMPLE_RATE, encoding, and LOG_WARNING.

Referenced by au_open().

283 {
284  AU_HEADER(header);
285  uint32_t magic;
286  uint32_t hdr_size;
287  uint32_t data_size;
288  uint32_t encoding;
289  uint32_t sample_rate;
290  uint32_t channels;
291 
292  if (fread(header, 1, AU_HEADER_SIZE, f) != AU_HEADER_SIZE) {
293  ast_log(LOG_WARNING, "Read failed (header)\n");
294  return -1;
295  }
296  magic = ltohl(header[AU_HDR_MAGIC_OFF]);
297  if (magic != (uint32_t) AU_MAGIC) {
298  ast_log(LOG_WARNING, "Bad magic: 0x%x\n", magic);
299  }
300  hdr_size = ltohl(header[AU_HDR_HDR_SIZE_OFF]);
301  if (hdr_size < AU_HEADER_SIZE) {
302  hdr_size = AU_HEADER_SIZE;
303  }
304 /* data_size = ltohl(header[AU_HDR_DATA_SIZE_OFF]); */
305  encoding = ltohl(header[AU_HDR_ENCODING_OFF]);
306  if (encoding != AU_ENC_8BIT_ULAW) {
307  ast_log(LOG_WARNING, "Unexpected format: %u. Only 8bit ULAW allowed (%d)\n", encoding, AU_ENC_8BIT_ULAW);
308  return -1;
309  }
310  sample_rate = ltohl(header[AU_HDR_SAMPLE_RATE_OFF]);
311  if (sample_rate != DEFAULT_SAMPLE_RATE) {
312  ast_log(LOG_WARNING, "Sample rate can only be 8000 not %u\n", sample_rate);
313  return -1;
314  }
315  channels = ltohl(header[AU_HDR_CHANNELS_OFF]);
316  if (channels != 1) {
317  ast_log(LOG_WARNING, "Not in mono: channels=%u\n", channels);
318  return -1;
319  }
320  /* Skip to data */
321  fseek(f, 0, SEEK_END);
322  data_size = ftell(f) - hdr_size;
323  if (fseek(f, hdr_size, SEEK_SET) == -1 ) {
324  ast_log(LOG_WARNING, "Failed to skip to data: %u\n", hdr_size);
325  return -1;
326  }
327  return data_size;
328 }
#define AU_HDR_SAMPLE_RATE_OFF
Definition: format_pcm.c:254
static char * encoding
Definition: cdr_pgsql.c:56
#define DEFAULT_SAMPLE_RATE
Definition: asterisk.h:41
#define AU_HDR_HDR_SIZE_OFF
Definition: format_pcm.c:251
#define LOG_WARNING
Definition: logger.h:144
#define AU_HDR_ENCODING_OFF
Definition: format_pcm.c:253
#define AU_ENC_8BIT_ULAW
Definition: format_pcm.c:257
#define AU_HEADER(var)
Definition: format_pcm.c:248
#define AU_HDR_MAGIC_OFF
Definition: format_pcm.c:250
#define AU_MAGIC
Definition: format_pcm.c:259
static struct channel_usage channels
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define AU_HEADER_SIZE
Definition: format_pcm.c:247
static struct ast_format f[]
Definition: format_g726.c:181
#define AU_HDR_CHANNELS_OFF
Definition: format_pcm.c:255
static int load_module ( void  )
static

Definition at line 520 of file format_pcm.c.

References ARRAY_LEN, ast_format_register, AST_LIN2A, AST_LIN2MU, AST_MODULE_LOAD_FAILURE, and AST_MODULE_LOAD_SUCCESS.

521 {
522  int i;
523 
524  /* XXX better init ? */
525  for (i = 0; i < ARRAY_LEN(ulaw_silence); i++)
526  ulaw_silence[i] = AST_LIN2MU(0);
527  for (i = 0; i < ARRAY_LEN(alaw_silence); i++)
528  alaw_silence[i] = AST_LIN2A(0);
529 
536 }
#define ast_format_register(f)
Definition: mod_format.h:131
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static char ulaw_silence[BUF_SIZE]
Definition: format_pcm.c:43
static char alaw_silence[BUF_SIZE]
Definition: format_pcm.c:44
static struct ast_format g722_f
Definition: format_pcm.c:494
static struct ast_format alaw_f
Definition: format_pcm.c:465
static struct ast_format pcm_f
Definition: format_pcm.c:482
static struct ast_format au_f
Definition: format_pcm.c:506
#define AST_LIN2MU(a)
Definition: ulaw.h:49
#define AST_LIN2A(a)
Definition: alaw.h:50
static struct ast_frame* pcm_read ( struct ast_filestream s,
int *  whennext 
)
static

Definition at line 80 of file format_pcm.c.

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

81 {
82  int res;
83 
84  /* Send a frame from the file to the appropriate channel */
85 
87  s->fr.subclass.codec = s->fmt->format;
88  s->fr.mallocd = 0;
90  if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) < 1) {
91  if (res)
92  ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
93  return NULL;
94  }
95  s->fr.datalen = res;
96  if (s->fmt->format == AST_FORMAT_G722)
97  *whennext = s->fr.samples = res * 2;
98  else
99  *whennext = s->fr.samples = res;
100  return &s->fr;
101 }
union ast_frame_subclass subclass
Definition: frame.h:146
void * ptr
Definition: frame.h:160
#define LOG_WARNING
Definition: logger.h:144
format_t codec
Definition: frame.h:137
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
Definition: frame.h:183
format_t format
Definition: mod_format.h:47
#define AST_FRIENDLY_OFFSET
Offset into a frame&#39;s data buffer.
Definition: frame.h:204
int datalen
Definition: frame.h:148
struct ast_frame fr
Definition: mod_format.h:117
struct ast_format * fmt
Definition: mod_format.h:102
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
int mallocd
Definition: frame.h:152
#define AST_FORMAT_G722
Definition: frame.h:266
enum ast_frame_type frametype
Definition: frame.h:144
#define BUF_SIZE
Definition: format_pcm.c:41
union ast_frame::@172 data
int samples
Definition: frame.h:150
static int pcm_seek ( struct ast_filestream fs,
off_t  sample_offset,
int  whence 
)
static

Definition at line 103 of file format_pcm.c.

References AST_FORMAT_ALAW, ast_log(), AST_LOG_WARNING, BUF_SIZE, errno, ast_filestream::f, ast_filestream::fmt, ast_format::format, LOG_WARNING, ast_frame::offset, SEEK_FORCECUR, and ast_frame::src.

104 {
105  off_t cur, max, offset = 0;
106  int ret = -1; /* assume error */
107 
108  if ((cur = ftello(fs->f)) < 0) {
109  ast_log(AST_LOG_WARNING, "Unable to determine current position in pcm filestream %p: %s\n", fs, strerror(errno));
110  return -1;
111  }
112 
113  if (fseeko(fs->f, 0, SEEK_END) < 0) {
114  ast_log(AST_LOG_WARNING, "Unable to seek to end of pcm filestream %p: %s\n", fs, strerror(errno));
115  return -1;
116  }
117 
118  if ((max = ftello(fs->f)) < 0) {
119  ast_log(AST_LOG_WARNING, "Unable to determine max position in pcm filestream %p: %s\n", fs, strerror(errno));
120  return -1;
121  }
122 
123  switch (whence) {
124  case SEEK_SET:
125  offset = sample_offset;
126  break;
127  case SEEK_END:
128  offset = max - sample_offset;
129  break;
130  case SEEK_CUR:
131  case SEEK_FORCECUR:
132  offset = cur + sample_offset;
133  break;
134  default:
135  ast_log(LOG_WARNING, "invalid whence %d, assuming SEEK_SET\n", whence);
136  offset = sample_offset;
137  }
138  if (offset < 0) {
139  ast_log(LOG_WARNING, "negative offset %ld, resetting to 0\n", (long) offset);
140  offset = 0;
141  }
142  if (whence == SEEK_FORCECUR && offset > max) { /* extend the file */
143  size_t left = offset - max;
144  const char *src = (fs->fmt->format == AST_FORMAT_ALAW) ? alaw_silence : ulaw_silence;
145 
146  while (left) {
147  size_t written = fwrite(src, 1, (left > BUF_SIZE) ? BUF_SIZE : left, fs->f);
148  if (written == -1)
149  break; /* error */
150  left -= written;
151  }
152  ret = 0; /* successful */
153  } else {
154  if (offset > max) {
155  ast_log(LOG_WARNING, "offset too large %ld, truncating to %ld\n", (long) offset, (long) max);
156  offset = max;
157  }
158  ret = fseeko(fs->f, offset, SEEK_SET);
159  }
160  return ret;
161 }
static char ulaw_silence[BUF_SIZE]
Definition: format_pcm.c:43
#define LOG_WARNING
Definition: logger.h:144
#define AST_LOG_WARNING
Definition: logger.h:149
static char alaw_silence[BUF_SIZE]
Definition: format_pcm.c:44
format_t format
Definition: mod_format.h:47
#define AST_FORMAT_ALAW
Definition: frame.h:248
struct ast_format * fmt
Definition: mod_format.h:102
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
#define SEEK_FORCECUR
Definition: file.h:50
#define BUF_SIZE
Definition: format_pcm.c:41
static off_t pcm_tell ( struct ast_filestream fs)
static

Definition at line 179 of file format_pcm.c.

References ast_filestream::f.

180 {
181  return ftello(fs->f);
182 }
static int pcm_trunc ( struct ast_filestream fs)
static

Definition at line 163 of file format_pcm.c.

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

164 {
165  int cur, fd;
166 
167  if ((fd = fileno(fs->f)) < 0) {
168  ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for pcm filestream %p: %s\n", fs, strerror(errno));
169  return -1;
170  }
171  if ((cur = ftello(fs->f)) < 0) {
172  ast_log(AST_LOG_WARNING, "Unable to determine current position in pcm filestream %p: %s\n", fs, strerror(errno));
173  return -1;
174  }
175  /* Truncate file to current length */
176  return ftruncate(fd, cur);
177 }
#define AST_LOG_WARNING
Definition: logger.h:149
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
static int pcm_write ( struct ast_filestream fs,
struct ast_frame f 
)
static

Definition at line 184 of file format_pcm.c.

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

185 {
186  int res;
187 
188  if (f->frametype != AST_FRAME_VOICE) {
189  ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
190  return -1;
191  }
192  if (f->subclass.codec != fs->fmt->format) {
193  ast_log(LOG_WARNING, "Asked to write incompatible format frame (%s)!\n", ast_getformatname(f->subclass.codec));
194  return -1;
195  }
196 
197 #ifdef REALTIME_WRITE
198  if (s->fmt->format == AST_FORMAT_ALAW) {
199  struct pcm_desc *pd = (struct pcm_desc *)fs->_private;
200  struct stat stat_buf;
201  unsigned long cur_time = get_time();
202  unsigned long fpos = ( cur_time - pd->start_time ) * 8; /* 8 bytes per msec */
203  /* Check if we have written to this position yet. If we have, then increment pos by one frame
204  * for some degree of protection against receiving packets in the same clock tick.
205  */
206 
207  fstat(fileno(fs->f), &stat_buf );
208  if (stat_buf.st_size > fpos )
209  fpos += f->datalen; /* Incrementing with the size of this current frame */
210 
211  if (stat_buf.st_size < fpos) {
212  /* fill the gap with 0x55 rather than 0. */
213  char buf[1024];
214  unsigned long cur, to_write;
215 
216  cur = stat_buf.st_size;
217  if (fseek(fs->f, cur, SEEK_SET) < 0) {
218  ast_log( LOG_WARNING, "Cannot seek in file: %s\n", strerror(errno) );
219  return -1;
220  }
221  memset(buf, 0x55, 512);
222  while (cur < fpos) {
223  to_write = fpos - cur;
224  if (to_write > sizeof(buf))
225  to_write = sizeof(buf);
226  fwrite(buf, 1, to_write, fs->f);
227  cur += to_write;
228  }
229  }
230 
231  if (fseek(s->f, fpos, SEEK_SET) < 0) {
232  ast_log( LOG_WARNING, "Cannot seek in file: %s\n", strerror(errno) );
233  return -1;
234  }
235  }
236 #endif /* REALTIME_WRITE */
237 
238  if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) {
239  ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
240  return -1;
241  }
242  return 0;
243 }
union ast_frame_subclass subclass
Definition: frame.h:146
void * ptr
Definition: frame.h:160
#define LOG_WARNING
Definition: logger.h:144
format_t codec
Definition: frame.h:137
format_t format
Definition: mod_format.h:47
#define AST_FORMAT_ALAW
Definition: frame.h:248
int datalen
Definition: frame.h:148
struct ast_format * fmt
Definition: mod_format.h:102
void * _private
Definition: mod_format.h:119
char * ast_getformatname(format_t format)
Get the name of a format.
Definition: frame.c:578
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
enum ast_frame_type frametype
Definition: frame.h:144
union ast_frame::@172 data
static int unload_module ( void  )
static

Definition at line 538 of file format_pcm.c.

References ast_format_unregister(), and ast_format::name.

539 {
544 }
static struct ast_format g722_f
Definition: format_pcm.c:494
int ast_format_unregister(const char *name)
Unregisters a file format.
Definition: file.c:104
char name[80]
Definition: mod_format.h:44
static struct ast_format alaw_f
Definition: format_pcm.c:465
static struct ast_format pcm_f
Definition: format_pcm.c:482
static struct ast_format au_f
Definition: format_pcm.c:506
static int update_header ( FILE *  f)
static

Definition at line 330 of file format_pcm.c.

References ast_log(), AU_HDR_DATA_SIZE_OFF, AU_HEADER_SIZE, and LOG_WARNING.

Referenced by au_trunc().

331 {
332  off_t cur, end;
333  uint32_t datalen;
334  int bytes;
335 
336  cur = ftell(f);
337  fseek(f, 0, SEEK_END);
338  end = ftell(f);
339  /* data starts 24 bytes in */
340  bytes = end - AU_HEADER_SIZE;
341  datalen = htoll(bytes);
342 
343  if (cur < 0) {
344  ast_log(LOG_WARNING, "Unable to find our position\n");
345  return -1;
346  }
347  if (fseek(f, AU_HDR_DATA_SIZE_OFF * sizeof(uint32_t), SEEK_SET)) {
348  ast_log(LOG_WARNING, "Unable to set our position\n");
349  return -1;
350  }
351  if (fwrite(&datalen, 1, sizeof(datalen), f) != sizeof(datalen)) {
352  ast_log(LOG_WARNING, "Unable to set write file size\n");
353  return -1;
354  }
355  if (fseek(f, cur, SEEK_SET)) {
356  ast_log(LOG_WARNING, "Unable to return to position\n");
357  return -1;
358  }
359  return 0;
360 }
#define LOG_WARNING
Definition: logger.h:144
#define AU_HDR_DATA_SIZE_OFF
Definition: format_pcm.c:252
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define AU_HEADER_SIZE
Definition: format_pcm.c:247
static struct ast_format f[]
Definition: format_g726.c:181
static int write_header ( FILE *  f)
static

Definition at line 362 of file format_pcm.c.

References ast_log(), AU_ENC_8BIT_ULAW, AU_HDR_CHANNELS_OFF, AU_HDR_DATA_SIZE_OFF, AU_HDR_ENCODING_OFF, AU_HDR_HDR_SIZE_OFF, AU_HDR_MAGIC_OFF, AU_HDR_SAMPLE_RATE_OFF, AU_HEADER, AU_HEADER_SIZE, AU_MAGIC, DEFAULT_SAMPLE_RATE, and LOG_WARNING.

Referenced by au_rewrite().

363 {
364  AU_HEADER(header);
365 
366  header[AU_HDR_MAGIC_OFF] = htoll((uint32_t) AU_MAGIC);
367  header[AU_HDR_HDR_SIZE_OFF] = htoll(AU_HEADER_SIZE);
368  header[AU_HDR_DATA_SIZE_OFF] = 0;
369  header[AU_HDR_ENCODING_OFF] = htoll(AU_ENC_8BIT_ULAW);
371  header[AU_HDR_CHANNELS_OFF] = htoll(1);
372 
373  /* Write an au header, ignoring sizes which will be filled in later */
374  fseek(f, 0, SEEK_SET);
375  if (fwrite(header, 1, AU_HEADER_SIZE, f) != AU_HEADER_SIZE) {
376  ast_log(LOG_WARNING, "Unable to write header\n");
377  return -1;
378  }
379  return 0;
380 }
#define AU_HDR_SAMPLE_RATE_OFF
Definition: format_pcm.c:254
#define DEFAULT_SAMPLE_RATE
Definition: asterisk.h:41
#define AU_HDR_HDR_SIZE_OFF
Definition: format_pcm.c:251
#define LOG_WARNING
Definition: logger.h:144
#define AU_HDR_DATA_SIZE_OFF
Definition: format_pcm.c:252
#define AU_HDR_ENCODING_OFF
Definition: format_pcm.c:253
#define AU_ENC_8BIT_ULAW
Definition: format_pcm.c:257
#define AU_HEADER(var)
Definition: format_pcm.c:248
#define AU_HDR_MAGIC_OFF
Definition: format_pcm.c:250
#define AU_MAGIC
Definition: format_pcm.c:259
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define AU_HEADER_SIZE
Definition: format_pcm.c:247
static struct ast_format f[]
Definition: format_g726.c:181
#define AU_HDR_CHANNELS_OFF
Definition: format_pcm.c:255

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Raw/Sun uLaw/ALaw 8KHz (PCM,PCMA,AU), G.722 16Khz" , .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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND }
static

Definition at line 550 of file format_pcm.c.

struct ast_format alaw_f
static

Definition at line 465 of file format_pcm.c.

char alaw_silence[BUF_SIZE]
static

Definition at line 44 of file format_pcm.c.

Definition at line 550 of file format_pcm.c.

struct ast_format au_f
static

Definition at line 506 of file format_pcm.c.

struct ast_format g722_f
static

Definition at line 494 of file format_pcm.c.

struct ast_format pcm_f
static

Definition at line 482 of file format_pcm.c.

char ulaw_silence[BUF_SIZE]
static

Definition at line 43 of file format_pcm.c.