35 #include "asterisk/mod_format.h"
50 unsigned long start_time;
54 static unsigned long get_time(
void)
64 return cur * 1000 / sysconf( _SC_CLK_TCK );
70 pd->starttime = get_time();
105 off_t cur, max,
offset = 0;
108 if ((cur = ftello(fs->
f)) < 0) {
113 if (fseeko(fs->
f, 0, SEEK_END) < 0) {
118 if ((max = ftello(fs->
f)) < 0) {
125 offset = sample_offset;
128 offset = max - sample_offset;
132 offset = cur + sample_offset;
136 offset = sample_offset;
143 size_t left = offset - max;
155 ast_log(
LOG_WARNING,
"offset too large %ld, truncating to %ld\n", (
long) offset, (
long) max);
158 ret = fseeko(fs->
f, offset, SEEK_SET);
167 if ((fd = fileno(fs->
f)) < 0) {
171 if ((cur = ftello(fs->
f)) < 0) {
176 return ftruncate(fd, cur);
181 return ftello(fs->
f);
197 #ifdef REALTIME_WRITE
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;
207 fstat(fileno(fs->
f), &stat_buf );
208 if (stat_buf.st_size > fpos )
211 if (stat_buf.st_size < fpos) {
214 unsigned long cur, to_write;
216 cur = stat_buf.st_size;
217 if (fseek(fs->
f, cur, SEEK_SET) < 0) {
221 memset(buf, 0x55, 512);
223 to_write = fpos - cur;
224 if (to_write >
sizeof(buf))
225 to_write =
sizeof(buf);
226 fwrite(buf, 1, to_write, fs->
f);
231 if (fseek(s->
f, fpos, SEEK_SET) < 0) {
247 #define AU_HEADER_SIZE 24
248 #define AU_HEADER(var) uint32_t var[6]
250 #define AU_HDR_MAGIC_OFF 0
251 #define AU_HDR_HDR_SIZE_OFF 1
252 #define AU_HDR_DATA_SIZE_OFF 2
253 #define AU_HDR_ENCODING_OFF 3
254 #define AU_HDR_SAMPLE_RATE_OFF 4
255 #define AU_HDR_CHANNELS_OFF 5
257 #define AU_ENC_8BIT_ULAW 1
259 #define AU_MAGIC 0x2e736e64
260 #if __BYTE_ORDER == __BIG_ENDIAN
266 #if __BYTE_ORDER == __LITTLE_ENDIAN
268 (((((b) ) & 0xFF) << 24) | \
269 ((((b) >> 8) & 0xFF) << 16) | \
270 ((((b) >> 16) & 0xFF) << 8) | \
271 ((((b) >> 24) & 0xFF) ))
273 (((((b) ) & 0xFF) << 8) | \
274 ((((b) >> 8) & 0xFF) ))
275 #define ltohl(b) htoll(b)
276 #define ltohs(b) htols(b)
278 #error "Endianess not defined"
289 uint32_t sample_rate;
321 fseek(f, 0, SEEK_END);
322 data_size = ftell(f) - hdr_size;
323 if (fseek(f, hdr_size, SEEK_SET) == -1 ) {
337 fseek(f, 0, SEEK_END);
341 datalen = htoll(bytes);
351 if (fwrite(&datalen, 1,
sizeof(datalen), f) !=
sizeof(datalen)) {
355 if (fseek(f, cur, SEEK_SET)) {
374 fseek(f, 0, SEEK_SET);
400 long offset = 0, bytes;
403 bytes = sample_offset / 2;
405 bytes = sample_offset;
407 if ((cur = ftello(fs->
f)) < 0) {
412 if (fseeko(fs->
f, 0, SEEK_END) < 0) {
417 if ((max = ftello(fs->
f)) < 0) {
422 if (whence == SEEK_SET)
423 offset = bytes + min;
425 offset = bytes + cur;
426 else if (whence == SEEK_END)
427 offset = max - bytes;
430 offset = (offset > max) ? max : offset;
434 offset = (offset < min) ? min : offset;
436 return fseeko(fs->
f, offset, SEEK_SET);
444 if ((fd = fileno(fs->
f)) < 0) {
448 if ((cur = ftello(fs->
f)) < 0) {
453 if (ftruncate(fd, cur)) {
461 off_t offset = ftello(fs->
f);
467 .exts =
"alaw|al|alw",
475 #ifdef REALTIME_WRITE
477 .rewrite = pcma_rewrite,
478 .desc_size =
sizeof(
struct pcm_desc),
484 .exts =
"pcm|ulaw|ul|mu|ulw",
503 .buf_size = (
BUF_SIZE * 2) + AST_FRIENDLY_OFFSET,
525 for (i = 0; i <
ARRAY_LEN(ulaw_silence); i++)
527 for (i = 0; i <
ARRAY_LEN(alaw_silence); i++)
A-Law to Signed linear conversion.
union ast_frame_subclass subclass
Asterisk main include file. File version handling, generic pbx functions.
#define DEFAULT_SAMPLE_RATE
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
u-Law to Signed linear conversion
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
Asterisk architecture endianess compatibility definitions.
static struct channel_usage channels
char * ast_getformatname(format_t format)
Get the name of a format.
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...
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
Data structure associated with a single frame of data.
enum ast_frame_type frametype
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
union ast_frame::@172 data
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.