Merged revisions 94540 via svnmerge from
[asterisk/asterisk.git] / formats / format_g726.c
index 135e0a8..e27476f 100644 (file)
  * \ingroup formats
  */
  
  * \ingroup formats
  */
  
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
-#include "asterisk/lock.h"
-#include "asterisk/options.h"
-#include "asterisk/channel.h"
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/sched.h"
+#include "asterisk/mod_format.h"
 #include "asterisk/module.h"
 #include "asterisk/endian.h"
 
 #include "asterisk/module.h"
 #include "asterisk/endian.h"
 
@@ -76,11 +62,9 @@ struct g726_desc  {
  */
 static int g726_open(struct ast_filestream *tmp, int rate)
 {
  */
 static int g726_open(struct ast_filestream *tmp, int rate)
 {
-       struct g726_desc *s = (struct g726_desc *)tmp->private;
+       struct g726_desc *s = (struct g726_desc *)tmp->_private;
        s->rate = rate;
        s->rate = rate;
-       if (option_debug)
-               ast_log(LOG_DEBUG, "Created filestream G.726-%dk.\n", 
-                               40 - s->rate * 8);
+       ast_debug(1, "Created filestream G.726-%dk.\n", 40 - s->rate * 8);
        return 0;
 }
 
        return 0;
 }
 
@@ -131,13 +115,13 @@ static int g726_16_rewrite(struct ast_filestream *s, const char *comment)
 static struct ast_frame *g726_read(struct ast_filestream *s, int *whennext)
 {
        int res;
 static struct ast_frame *g726_read(struct ast_filestream *s, int *whennext)
 {
        int res;
-       struct g726_desc *fs = (struct g726_desc *)s->private;
+       struct g726_desc *fs = (struct g726_desc *)s->_private;
 
        /* Send a frame from the file to the appropriate channel */
        s->fr.frametype = AST_FRAME_VOICE;
        s->fr.subclass = AST_FORMAT_G726;
        s->fr.mallocd = 0;
 
        /* Send a frame from the file to the appropriate channel */
        s->fr.frametype = AST_FRAME_VOICE;
        s->fr.subclass = AST_FORMAT_G726;
        s->fr.mallocd = 0;
-       FR_SET_BUF(&s->fr, s->buf, AST_FRIENDLY_OFFSET, frame_size[fs->rate]);
+       AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, frame_size[fs->rate]);
        s->fr.samples = 8 * FRAME_TIME;
        if ((res = fread(s->fr.data, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
                if (res)
        s->fr.samples = 8 * FRAME_TIME;
        if ((res = fread(s->fr.data, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
                if (res)
@@ -151,7 +135,7 @@ static struct ast_frame *g726_read(struct ast_filestream *s, int *whennext)
 static int g726_write(struct ast_filestream *s, struct ast_frame *f)
 {
        int res;
 static int g726_write(struct ast_filestream *s, struct ast_frame *f)
 {
        int res;
-       struct g726_desc *fs = (struct g726_desc *)s->private;
+       struct g726_desc *fs = (struct g726_desc *)s->_private;
 
        if (f->frametype != AST_FRAME_VOICE) {
                ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
 
        if (f->frametype != AST_FRAME_VOICE) {
                ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
@@ -190,8 +174,6 @@ static off_t g726_tell(struct ast_filestream *fs)
        return -1;
 }
 
        return -1;
 }
 
-static struct ast_format_lock me = { .usecnt = -1 };
-
 static const struct ast_format f[] = {
        {
                .name = "g726-40",
 static const struct ast_format f[] = {
        {
                .name = "g726-40",
@@ -206,7 +188,6 @@ static const struct ast_format f[] = {
                .read = g726_read,
                .buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,
                .desc_size = sizeof(struct g726_desc),
                .read = g726_read,
                .buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,
                .desc_size = sizeof(struct g726_desc),
-               .lockp = &me,
        },
        {
                .name = "g726-32",
        },
        {
                .name = "g726-32",
@@ -221,7 +202,6 @@ static const struct ast_format f[] = {
                .read = g726_read,
                .buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,
                .desc_size = sizeof(struct g726_desc),
                .read = g726_read,
                .buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,
                .desc_size = sizeof(struct g726_desc),
-               .lockp = &me,
        },
        {
                .name = "g726-24",
        },
        {
                .name = "g726-24",
@@ -236,7 +216,6 @@ static const struct ast_format f[] = {
                .read = g726_read,
                .buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,
                .desc_size = sizeof(struct g726_desc),
                .read = g726_read,
                .buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,
                .desc_size = sizeof(struct g726_desc),
-               .lockp = &me,
        },
        {
                .name = "g726-16",
        },
        {
                .name = "g726-16",
@@ -251,28 +230,24 @@ static const struct ast_format f[] = {
                .read = g726_read,
                .buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,
                .desc_size = sizeof(struct g726_desc),
                .read = g726_read,
                .buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,
                .desc_size = sizeof(struct g726_desc),
-               .lockp = &me,
        },
        {       .format = 0 }   /* terminator */
 };
 
        },
        {       .format = 0 }   /* terminator */
 };
 
-/*
- * Module interface (load_module, unload_module, usecount, description, key)
- */
-int load_module()
+static int load_module(void)
 {
        int i;
 
        for (i = 0; f[i].format ; i++) {
                if (ast_format_register(&f[i])) {       /* errors are fatal */
                        ast_log(LOG_WARNING, "Failed to register format %s.\n", f[i].name);
 {
        int i;
 
        for (i = 0; f[i].format ; i++) {
                if (ast_format_register(&f[i])) {       /* errors are fatal */
                        ast_log(LOG_WARNING, "Failed to register format %s.\n", f[i].name);
-                       return -1;
+                       return AST_MODULE_LOAD_FAILURE;
                }
        }
                }
        }
-       return 0;
+       return AST_MODULE_LOAD_SUCCESS;
 }
 
 }
 
-int unload_module()
+static int unload_module(void)
 {
        int i;
 
 {
        int i;
 
@@ -283,18 +258,4 @@ int unload_module()
        return(0);
 }      
 
        return(0);
 }      
 
-int usecount()
-{
-       return me.usecnt;
-}
-
-const char *description()
-{
-       return "Raw G.726 (16/24/32/40kbps) data";
-}
-
-const char *key()
-{
-       return ASTERISK_GPL_KEY;
-}
-
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Raw G.726 (16/24/32/40kbps) data");