format_g723.c File Reference

Old-style G.723.1 frame/timestamp format. More...

#include "asterisk.h"
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/format_cache.h"

Include dependency graph for format_g723.c:

Go to the source code of this file.

Defines

#define G723_MAX_SIZE   1024

Functions

static void __reg_module (void)
static void __unreg_module (void)
static struct ast_frameg723_read (struct ast_filestream *s, int *whennext)
static int g723_seek (struct ast_filestream *fs, off_t sample_offset, int whence)
static off_t g723_tell (struct ast_filestream *fs)
static int g723_trunc (struct ast_filestream *fs)
static int g723_write (struct ast_filestream *s, 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 = "G.723.1 Simple Timestamp File Format" , .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 g723_1_f


Detailed Description

Old-style G.723.1 frame/timestamp format.

Definition in file format_g723.c.


Define Documentation

#define G723_MAX_SIZE   1024

Definition at line 40 of file format_g723.c.

Referenced by g723_read().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 161 of file format_g723.c.

static void __unreg_module ( void   )  [static]

Definition at line 161 of file format_g723.c.

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

Definition at line 42 of file format_g723.c.

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

00043 {
00044    unsigned short size;
00045    int res;
00046    int delay;
00047    /* Read the delay for the next packet, and schedule again if necessary */
00048    /* XXX is this ignored ? */
00049    if (fread(&delay, 1, 4, s->f) == 4) 
00050       delay = ntohl(delay);
00051    else
00052       delay = -1;
00053    if (fread(&size, 1, 2, s->f) != 2) {
00054       /* Out of data, or the file is no longer valid.  In any case
00055          go ahead and stop the stream */
00056       return NULL;
00057    }
00058    /* Looks like we have a frame to read from here */
00059    size = ntohs(size);
00060    if (size > G723_MAX_SIZE) {
00061       ast_log(LOG_WARNING, "Size %d is invalid\n", size);
00062       /* The file is apparently no longer any good, as we
00063          shouldn't ever get frames even close to this 
00064          size.  */
00065       return NULL;
00066    }
00067    /* Read the data into the buffer */
00068    AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, size);
00069    if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != size) {
00070       ast_log(LOG_WARNING, "Short read (%d of %d bytes) (%s)!\n", res, size, strerror(errno));
00071       return NULL;
00072    }
00073    *whennext = s->fr.samples = 240;
00074    return &s->fr;
00075 }

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

Definition at line 104 of file format_g723.c.

00105 {
00106    return -1;
00107 }

static off_t g723_tell ( struct ast_filestream fs  )  [static]

Definition at line 126 of file format_g723.c.

00127 {
00128    return -1;
00129 }

static int g723_trunc ( struct ast_filestream fs  )  [static]

Definition at line 109 of file format_g723.c.

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

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

static int g723_write ( struct ast_filestream s,
struct ast_frame f 
) [static]

Definition at line 77 of file format_g723.c.

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

00078 {
00079    uint32_t delay;
00080    uint16_t size;
00081    int res;
00082    /* XXX there used to be a check s->fr means a read stream */
00083    delay = 0;
00084    if (f->datalen <= 0) {
00085       ast_log(LOG_WARNING, "Short frame ignored (%d bytes long?)\n", f->datalen);
00086       return 0;
00087    }
00088    if ((res = fwrite(&delay, 1, 4, s->f)) != 4) {
00089       ast_log(LOG_WARNING, "Unable to write delay: res=%d (%s)\n", res, strerror(errno));
00090       return -1;
00091    }
00092    size = htons(f->datalen);
00093    if ((res = fwrite(&size, 1, 2, s->f)) != 2) {
00094       ast_log(LOG_WARNING, "Unable to write size: res=%d (%s)\n", res, strerror(errno));
00095       return -1;
00096    }
00097    if ((res = fwrite(f->data.ptr, 1, f->datalen, s->f)) != f->datalen) {
00098       ast_log(LOG_WARNING, "Unable to write frame: res=%d (%s)\n", res, strerror(errno));
00099       return -1;
00100    }  
00101    return 0;
00102 }

static int load_module ( void   )  [static]

static int unload_module ( void   )  [static]

Definition at line 151 of file format_g723.c.

References ast_format_def_unregister(), and ast_format_def::name.

00152 {
00153    return ast_format_def_unregister(g723_1_f.name);
00154 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "G.723.1 Simple Timestamp File Format" , .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 161 of file format_g723.c.

Definition at line 161 of file format_g723.c.

struct ast_format_def g723_1_f [static]

Definition at line 131 of file format_g723.c.


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