unified socket application interface (for asterisk and maybe other apps)
[lcr.git] / tones.c
diff --git a/tones.c b/tones.c
index 5d64125..4a386ff 100644 (file)
--- a/tones.c
+++ b/tones.c
@@ -278,10 +278,15 @@ int open_tone(char *file, int *codec, signed long *length, signed long *left)
  * the len must be the number of samples, NOT for the bytes to read!!
  * the data returned is law-code
  */
-int read_tone(int fh, void *buffer, int codec, int len, signed long size, signed long *left, int speed)
+int read_tone(int fh, unsigned char *buffer, int codec, int len, signed long size, signed long *left, int speed)
 {
        int l;
        int offset;
+       signed short buffer16[len], *buf16 = buffer16;
+       signed short buffer32[len<<1], *buf32 = buffer32;
+       unsigned char buffer8[len], *buf8 = buffer8;
+       signed long sample;
+       int i = 0;
 //printf("left=%ld\n",*left);
 
        /* if no *left is given (law has unknown length) */
@@ -320,9 +325,6 @@ int read_tone(int fh, void *buffer, int codec, int len, signed long size, signed
                break;
 
                case CODEC_MONO:
-                       signed short buffer16[len], *buf16 = buffer16;
-                       signed long sample;
-                       int i = 0;
                        l = read(fh, buf16, len<<1);
                        if (l>0)
                        {
@@ -342,9 +344,6 @@ int read_tone(int fh, void *buffer, int codec, int len, signed long size, signed
 
                case CODEC_STEREO:
                {
-                       signed short buffer32[len<<1], *buf32 = buffer32;
-                       signed long sample;
-                       int i = 0;
                        l = read(fh, buf32, len<<2);
                        if (l>0)
                        {
@@ -365,8 +364,6 @@ int read_tone(int fh, void *buffer, int codec, int len, signed long size, signed
 
                case CODEC_8BIT:
                {
-                       unsigned char buffer8[len], *buf8 = buffer8;
-                       int i = 0;
                        l = read(fh, buf8, len);
                        if (l>0)
                        {
@@ -380,8 +377,7 @@ int read_tone(int fh, void *buffer, int codec, int len, signed long size, signed
                break;
 
                default:
-               PERROR("codec %d is not supported, exitting...\n", codec);
-               exit(-1);
+               FATAL("codec %d is not supported.\n", codec);
        }
 
        if (l>0 && left)
@@ -409,12 +405,12 @@ void free_tones(void)
                {
                        temp = tonesettone_temp;
                        tonesettone_temp = tonesettone_temp->next;
-                       free(temp);
+                       FREE(temp, sizeof(struct tonesettone));
                        memuse--;
                }
                temp = toneset_temp;
                toneset_temp = toneset_temp->next;
-               free(temp);
+               FREE(temp, sizeof(struct toneset));
                memuse--;
        }
        toneset_first = NULL;
@@ -468,15 +464,9 @@ int fetch_tones(void)
                printf("PBX: Fetching tones '%s'\n", p);
                PDEBUG(DEBUG_PORT, "fetching tones directory '%s'\n", p);
 
-               *toneset_nextpointer = (struct toneset *)calloc(1, sizeof(struct toneset));
-               if (*toneset_nextpointer == NULL)
-               {
-                       PERROR("No memory for tone set: '%s'\n",p);
-                       return(0);
-               }
+               *toneset_nextpointer = (struct toneset *)MALLOC(sizeof(struct toneset));
                memuse++;
                memory += sizeof(struct toneset);
-               memset(*toneset_nextpointer, 0 , sizeof(struct toneset));
                SCPY((*toneset_nextpointer)->directory, p);
                tonesettone_nextpointer = &(*toneset_nextpointer)->first;
 
@@ -529,18 +519,10 @@ int fetch_tones(void)
                                continue;
                        }
 
-                       /* allocate tone */
-                       *tonesettone_nextpointer = (struct tonesettone *)calloc(1, sizeof(struct tonesettone)+tone_size);
-                       if (*toneset_nextpointer == NULL)
-                       {
-                               PERROR("No memory for tone set: '%s'\n",p);
-                               close(fh);
-                               fduse--;
-                               return(0);
-                       }
+                       /* Allocate tone */
+                       *tonesettone_nextpointer = (struct tonesettone *)MALLOC(sizeof(struct tonesettone)+tone_size);
                        memuse++;
 //printf("tone:%s, %ld bytes\n", name, tone_size);
-                       memset(*tonesettone_nextpointer, 0 , sizeof(struct tonesettone)+tone_size);
                        memory += sizeof(struct tonesettone)+tone_size;
                        samples ++;