include "logger.h" and errno.h from asterisk.h - usage shows that they
[asterisk/asterisk.git] / formats / format_pcm.c
index 4624de5..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"
@@ -95,7 +88,7 @@ static struct ast_frame *pcm_read(struct ast_filestream *s, int *whennext)
        s->fr.frametype = AST_FRAME_VOICE;
        s->fr.subclass = s->fmt->format;
        s->fr.mallocd = 0;
-       FR_SET_BUF(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
+       AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
        if ((res = fread(s->fr.data, 1, s->fr.datalen, s->f)) < 1) {
                if (res)
                        ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
@@ -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);
@@ -414,8 +407,6 @@ static off_t au_tell(struct ast_filestream *fs)
        return offset - AU_HEADER_SIZE;
 }
 
-static struct ast_format_lock me = { .usecnt = -1 };
-
 static const struct ast_format alaw_f = {
        .name = "alaw",
        .exts = "alaw|al",
@@ -426,7 +417,6 @@ static const struct ast_format alaw_f = {
        .tell = pcm_tell,
        .read = pcm_read,
        .buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,
-       .lockp = &me,
 #ifdef REALTIME_WRITE
        .open = pcma_open,
        .rewrite = pcma_rewrite,
@@ -444,7 +434,18 @@ static const struct ast_format pcm_f = {
        .tell = pcm_tell,
        .read = pcm_read,
        .buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,
-       .lockp = &me,
+};
+
+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 = {
@@ -459,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 */
-       .lockp = &me,
 };
 
-int load_module()
+static int load_module(void)
 {
        int index;
 
@@ -472,27 +472,20 @@ int load_module()
        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;
 }
 
-int unload_module()
+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);
 }      
 
-int usecount()
-{
-       return me.usecnt;
-}
-
-char *description()
-{
-       return "Raw/Sun uLaw/ALaw 8khz Audio support (PCM,PCMA,AU)";
-}
-
-char *key()
-{
-       return ASTERISK_GPL_KEY;
-}
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Raw/Sun uLaw/ALaw 8KHz (PCM,PCMA,AU), G.722 16Khz");