include "logger.h" and errno.h from asterisk.h - usage shows that they
[asterisk/asterisk.git] / formats / format_pcm.c
index c2b6262..df5b415 100644 (file)
  * \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 <netinet/in.h>
+#include <arpa/inet.h>
+
 #include "asterisk/lock.h"
 #include "asterisk/channel.h"
 #include "asterisk/file.h"
-#include "asterisk/logger.h"
 #include "asterisk/sched.h"
 #include "asterisk/module.h"
 #include "asterisk/endian.h"
@@ -229,7 +222,7 @@ static int pcm_write(struct ast_filestream *fs, struct ast_frame *f)
 /* SUN .au support routines */
 
 #define AU_HEADER_SIZE         24
-#define AU_HEADER(var)         u_int32_t var[6]
+#define AU_HEADER(var)         uint32_t var[6]
 
 #define AU_HDR_MAGIC_OFF       0
 #define AU_HDR_HDR_SIZE_OFF    1
@@ -266,19 +259,19 @@ static int pcm_write(struct ast_filestream *fs, struct ast_frame *f)
 static int check_header(FILE *f)
 {
        AU_HEADER(header);
-       u_int32_t magic;
-       u_int32_t hdr_size;
-       u_int32_t data_size;
-       u_int32_t encoding;
-       u_int32_t sample_rate;
-       u_int32_t channels;
+       uint32_t magic;
+       uint32_t hdr_size;
+       uint32_t data_size;
+       uint32_t encoding;
+       uint32_t sample_rate;
+       uint32_t channels;
 
        if (fread(header, 1, AU_HEADER_SIZE, f) != AU_HEADER_SIZE) {
                ast_log(LOG_WARNING, "Read failed (header)\n");
                return -1;
        }
        magic = ltohl(header[AU_HDR_MAGIC_OFF]);
-       if (magic != (u_int32_t) AU_MAGIC) {
+       if (magic != (uint32_t) AU_MAGIC) {
                ast_log(LOG_WARNING, "Bad magic: 0x%x\n", magic);
        }
 /*     hdr_size = ltohl(header[AU_HDR_HDR_SIZE_OFF]);
@@ -313,7 +306,7 @@ static int check_header(FILE *f)
 static int update_header(FILE *f)
 {
        off_t cur, end;
-       u_int32_t datalen;
+       uint32_t datalen;
        int bytes;
 
        cur = ftell(f);
@@ -327,7 +320,7 @@ static int update_header(FILE *f)
                ast_log(LOG_WARNING, "Unable to find our position\n");
                return -1;
        }
-       if (fseek(f, AU_HDR_DATA_SIZE_OFF * sizeof(u_int32_t), SEEK_SET)) {
+       if (fseek(f, AU_HDR_DATA_SIZE_OFF * sizeof(uint32_t), SEEK_SET)) {
                ast_log(LOG_WARNING, "Unable to set our position\n");
                return -1;
        }
@@ -346,7 +339,7 @@ static int write_header(FILE *f)
 {
        AU_HEADER(header);
 
-       header[AU_HDR_MAGIC_OFF] = htoll((u_int32_t) AU_MAGIC);
+       header[AU_HDR_MAGIC_OFF] = htoll((uint32_t) AU_MAGIC);
        header[AU_HDR_HDR_SIZE_OFF] = htoll(AU_HEADER_SIZE);
        header[AU_HDR_DATA_SIZE_OFF] = 0;
        header[AU_HDR_ENCODING_OFF] = htoll(AU_ENC_8BIT_ULAW);
@@ -424,7 +417,6 @@ static const struct ast_format alaw_f = {
        .tell = pcm_tell,
        .read = pcm_read,
        .buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,
-       .module = &mod_data, /* XXX */
 #ifdef REALTIME_WRITE
        .open = pcma_open,
        .rewrite = pcma_rewrite,
@@ -442,7 +434,18 @@ static const struct ast_format pcm_f = {
        .tell = pcm_tell,
        .read = pcm_read,
        .buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,
-       .module = &mod_data, /* XXX */
+};
+
+static const struct ast_format g722_f = {
+       .name = "g722",
+       .exts = "g722",
+       .format = AST_FORMAT_G722,
+       .write = pcm_write,
+       .seek = pcm_seek,
+       .trunc = pcm_trunc,
+       .tell = pcm_tell,
+       .read = pcm_read,
+       .buf_size = (BUF_SIZE * 2) + AST_FRIENDLY_OFFSET,
 };
 
 static const struct ast_format au_f = {
@@ -457,10 +460,9 @@ static const struct ast_format au_f = {
        .tell = au_tell,
        .read = pcm_read,
        .buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,     /* this many shorts */
-       .module = &mod_data, /* XXX */
 };
 
-static int load_module(void *mod)
+static int load_module(void)
 {
        int index;
 
@@ -470,24 +472,20 @@ static int load_module(void *mod)
        for (index = 0; index < (sizeof(alaw_silence) / sizeof(alaw_silence[0])); index++)
                alaw_silence[index] = AST_LIN2A(0);
 
-       return ast_format_register(&pcm_f) || ast_format_register(&alaw_f)
-               || ast_format_register(&au_f);
+       if ( ast_format_register(&pcm_f)
+               || ast_format_register(&alaw_f)
+               || ast_format_register(&au_f)
+               || ast_format_register(&g722_f) )
+               return AST_MODULE_LOAD_FAILURE;
+       return AST_MODULE_LOAD_SUCCESS;
 }
 
-static int unload_module(void *mod)
+static int unload_module(void)
 {
-       return ast_format_unregister(pcm_f.name) || ast_format_unregister(alaw_f.name)
-               || ast_format_unregister(au_f.name);
+       return ast_format_unregister(pcm_f.name)
+               || ast_format_unregister(alaw_f.name)
+               || ast_format_unregister(au_f.name)
+               || ast_format_unregister(g722_f.name);
 }      
 
-static const char *description(void)
-{
-       return "Raw/Sun uLaw/ALaw 8khz Audio support (PCM,PCMA,AU)";
-}
-
-static const char *key(void)
-{
-       return ASTERISK_GPL_KEY;
-}
-
-STD_MOD1;
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Raw/Sun uLaw/ALaw 8KHz (PCM,PCMA,AU), G.722 16Khz");