format_g729.c File Reference

Save to raw, headerless G729 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_g729.c:

Go to the source code of this file.

Defines

#define BUF_SIZE   20
#define G729A_SAMPLES   160

Functions

static void __reg_module (void)
static void __unreg_module (void)
static struct ast_frameg729_read (struct ast_filestream *s, int *whennext)
static int g729_seek (struct ast_filestream *fs, off_t sample_offset, int whence)
static off_t g729_tell (struct ast_filestream *fs)
static int g729_trunc (struct ast_filestream *fs)
static int g729_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 G.729 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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .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 g729_f


Detailed Description

Save to raw, headerless G729 data.

Note:
This is not an encoder/decoder. The codec fo g729 is only available with a commercial license from Digium, due to patent restrictions. Check http://www.digium.com for information.
  • Extensions: g729

Definition in file format_g729.c.


Define Documentation

#define BUF_SIZE   20

Definition at line 46 of file format_g729.c.

#define G729A_SAMPLES   160

Definition at line 47 of file format_g729.c.

Referenced by g729_read(), g729_seek(), and g729_tell().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 157 of file format_g729.c.

static void __unreg_module ( void   )  [static]

Definition at line 157 of file format_g729.c.

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

Definition at line 49 of file format_g729.c.

References AST_FRAME_SET_BUFFER, AST_FRIENDLY_OFFSET, ast_log, ast_filestream::buf, BUF_SIZE, ast_frame::data, ast_frame::datalen, errno, ast_filestream::f, ast_filestream::fr, G729A_SAMPLES, LOG_WARNING, NULL, ast_frame::ptr, and ast_frame::samples.

00050 {
00051    int res;
00052    /* Send a frame from the file to the appropriate channel */
00053    s->fr.samples = G729A_SAMPLES;
00054    AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
00055    if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
00056       if (res && (res != 10)) /* XXX what for ? */
00057          ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
00058       return NULL;
00059    }
00060    *whennext = s->fr.samples;
00061    return &s->fr;
00062 }

static int g729_seek ( struct ast_filestream fs,
off_t  sample_offset,
int  whence 
) [static]

Definition at line 79 of file format_g729.c.

References BUF_SIZE, ast_filestream::f, G729A_SAMPLES, max, min, ast_frame::offset, and SEEK_FORCECUR.

00080 {
00081    long bytes;
00082    off_t min,cur,max,offset=0;
00083    min = 0;
00084    cur = ftello(fs->f);
00085    fseeko(fs->f, 0, SEEK_END);
00086    max = ftello(fs->f);
00087    
00088    bytes = BUF_SIZE * (sample_offset / G729A_SAMPLES);
00089    if (whence == SEEK_SET)
00090       offset = bytes;
00091    else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
00092       offset = cur + bytes;
00093    else if (whence == SEEK_END)
00094       offset = max - bytes;
00095    if (whence != SEEK_FORCECUR) {
00096       offset = (offset > max)?max:offset;
00097    }
00098    /* protect against seeking beyond begining. */
00099    offset = (offset < min)?min:offset;
00100    if (fseeko(fs->f, offset, SEEK_SET) < 0)
00101       return -1;
00102    return 0;
00103 }

static off_t g729_tell ( struct ast_filestream fs  )  [static]

Definition at line 122 of file format_g729.c.

References BUF_SIZE, ast_filestream::f, G729A_SAMPLES, and ast_frame::offset.

00123 {
00124    off_t offset = ftello(fs->f);
00125    return (offset/BUF_SIZE)*G729A_SAMPLES;
00126 }

static int g729_trunc ( struct ast_filestream fs  )  [static]

Definition at line 105 of file format_g729.c.

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

00106 {
00107    int fd;
00108    off_t cur;
00109 
00110    if ((fd = fileno(fs->f)) < 0) {
00111       ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for g729 filestream %p: %s\n", fs, strerror(errno));
00112       return -1;
00113    }
00114    if ((cur = ftello(fs->f)) < 0) {
00115       ast_log(AST_LOG_WARNING, "Unable to determine current position in g729 filestream %p: %s\n", fs, strerror(errno));
00116       return -1;
00117    }
00118    /* Truncate file to current length */
00119    return ftruncate(fd, cur);
00120 }

static int g729_write ( struct ast_filestream fs,
struct ast_frame f 
) [static]

Definition at line 64 of file format_g729.c.

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

00065 {
00066    int res;
00067 
00068    if (f->datalen % 10) {
00069       ast_log(LOG_WARNING, "Invalid data length, %d, should be multiple of 10\n", f->datalen);
00070       return -1;
00071    }
00072    if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) {
00073          ast_log(LOG_WARNING, "Bad write (%d/10): %s\n", res, strerror(errno));
00074          return -1;
00075    }
00076    return 0;
00077 }

static int load_module ( void   )  [static]

static int unload_module ( void   )  [static]

Definition at line 147 of file format_g729.c.

References ast_format_def_unregister(), and ast_format_def::name.

00148 {
00149    return ast_format_def_unregister(g729_f.name);
00150 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Raw G.729 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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND } [static]

Definition at line 157 of file format_g729.c.

Definition at line 157 of file format_g729.c.

struct ast_format_def g729_f [static]

Definition at line 128 of file format_g729.c.


Generated on Thu Apr 16 06:31:05 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6