]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - aac_afh.c
aac_afh.c: Kill global variable num_chunks
[paraslash.git] / aac_afh.c
index 5e5ea965eb3d31ba3241928132b4ed7594719163..cd374c818709e6a520910b7c58cc55df5071a2e9 100644 (file)
--- a/aac_afh.c
+++ b/aac_afh.c
 #include "fd.h"
 
 /** size of the input buffer, must be big enough to hold header */
 #include "fd.h"
 
 /** size of the input buffer, must be big enough to hold header */
-#define DEFAULT_INBUF_SIZE 65536
+#define AAC_INBUF_SIZE 65536
 
 static struct audio_format_handler *af;
 static FILE *infile;
 static unsigned char *inbuf;
 
 static struct audio_format_handler *af;
 static FILE *infile;
 static unsigned char *inbuf;
-static size_t inbuf_size, inbuf_len, num_chunks;
+static size_t inbuf_len;
 
 static void aac_close_audio_file(void)
 {
 
 static void aac_close_audio_file(void)
 {
@@ -82,19 +82,19 @@ static int read_chunk_table(struct audio_format_info *afi, size_t skip)
                ret = aac_find_stsz(inbuf, inbuf_len, &skip);
                if (ret >= 0)
                        break;
                ret = aac_find_stsz(inbuf, inbuf_len, &skip);
                if (ret >= 0)
                        break;
-               ret = read(fileno(infile), inbuf, inbuf_size);
+               ret = read(fileno(infile), inbuf, AAC_INBUF_SIZE);
                if (ret <= 0)
                        return -E_AAC_READ;
                PARA_INFO_LOG("next buffer: %d bytes\n", ret);
        }
                if (ret <= 0)
                        return -E_AAC_READ;
                PARA_INFO_LOG("next buffer: %d bytes\n", ret);
        }
-       num_chunks = ret;
-       PARA_INFO_LOG("sz table has %zu entries\n", num_chunks);
-       afi->chunk_table = para_malloc((num_chunks + 1) * sizeof(size_t));
-       for (i = 1; i <= num_chunks; i++) {
+       afi->chunks_total = ret;
+       PARA_INFO_LOG("sz table has %lu entries\n", afi->chunks_total);
+       afi->chunk_table = para_malloc((afi->chunks_total + 1) * sizeof(size_t));
+       for (i = 1; i <= afi->chunks_total; i++) {
                if (skip + 4 > inbuf_len) {
                        skip = inbuf_len - skip;
                        memmove(inbuf, inbuf + inbuf_len - skip, skip);
                if (skip + 4 > inbuf_len) {
                        skip = inbuf_len - skip;
                        memmove(inbuf, inbuf + inbuf_len - skip, skip);
-                       ret = read(fileno(infile), inbuf + skip, inbuf_size - skip);
+                       ret = read(fileno(infile), inbuf + skip, AAC_INBUF_SIZE - skip);
                        if (ret <= 0)
                                return -E_AAC_READ;
                        inbuf_len = ret + skip;
                        if (ret <= 0)
                                return -E_AAC_READ;
                        inbuf_len = ret + skip;
@@ -104,7 +104,7 @@ static int read_chunk_table(struct audio_format_info *afi, size_t skip)
                sum += aac_read_int32(inbuf + skip);
                afi->chunk_table[i] = sum;
                skip += 4;
                sum += aac_read_int32(inbuf + skip);
                afi->chunk_table[i] = sum;
                skip += 4;
-               if (i < 10 || i + 10 > num_chunks)
+               if (i < 10 || i + 10 > afi->chunks_total)
                        PARA_DEBUG_LOG("offset #%d: %zu\n", i, afi->chunk_table[i]);
        }
        return 1;
                        PARA_DEBUG_LOG("offset #%d: %zu\n", i, afi->chunk_table[i]);
        }
        return 1;
@@ -114,14 +114,14 @@ static long unsigned aac_set_chunk_tv(struct audio_format_info *afi,
                mp4AudioSpecificConfig *mp4ASC)
 {
        float tmp = mp4ASC->sbr_present_flag == 1? 2047 : 1023,
                mp4AudioSpecificConfig *mp4ASC)
 {
        float tmp = mp4ASC->sbr_present_flag == 1? 2047 : 1023,
-               ms = 1000.0 * num_chunks * tmp / mp4ASC->samplingFrequency;
+               ms = 1000.0 * afi->chunks_total * tmp / mp4ASC->samplingFrequency;
        struct timeval total;
 
        ms2tv(ms, &total);
        struct timeval total;
 
        ms2tv(ms, &total);
-       tv_divide(num_chunks, &total, &afi->chunk_tv);
-       PARA_INFO_LOG("%luHz, %fs (%zd x %lums)\n",
+       tv_divide(afi->chunks_total, &total, &afi->chunk_tv);
+       PARA_INFO_LOG("%luHz, %fs (%lu x %lums)\n",
                mp4ASC->samplingFrequency, ms / 1000,
                mp4ASC->samplingFrequency, ms / 1000,
-               num_chunks, tv2ms(&afi->chunk_tv));
+               afi->chunks_total, tv2ms(&afi->chunk_tv));
        return ms / 1000;
 }
 
        return ms / 1000;
 }
 
@@ -137,11 +137,10 @@ static int aac_get_file_info(FILE *file, struct audio_format_info *afi)
        mp4AudioSpecificConfig mp4ASC;
        NeAACDecHandle handle;
 
        mp4AudioSpecificConfig mp4ASC;
        NeAACDecHandle handle;
 
-       inbuf_size = DEFAULT_INBUF_SIZE;
-       inbuf = para_malloc(inbuf_size);
+       inbuf = para_malloc(AAC_INBUF_SIZE);
        infile = file;
 
        infile = file;
 
-       ret = read(fileno(infile), inbuf, inbuf_size);
+       ret = read(fileno(infile), inbuf, AAC_INBUF_SIZE);
        if (ret <= 0)
                return -E_AAC_READ;
        inbuf_len = ret;
        if (ret <= 0)
                return -E_AAC_READ;
        inbuf_len = ret;
@@ -163,24 +162,23 @@ static int aac_get_file_info(FILE *file, struct audio_format_info *afi)
        ret = read_chunk_table(afi, skip);
        if (ret < 0)
                return ret;
        ret = read_chunk_table(afi, skip);
        if (ret < 0)
                return ret;
-       afi->chunks_total = num_chunks;
        afi->seconds_total = aac_set_chunk_tv(afi, &mp4ASC);
        for (;;) {
                ret = aac_find_entry_point(inbuf, inbuf_len, &skip);
                if (ret >= 0)
                        break;
        afi->seconds_total = aac_set_chunk_tv(afi, &mp4ASC);
        for (;;) {
                ret = aac_find_entry_point(inbuf, inbuf_len, &skip);
                if (ret >= 0)
                        break;
-               ret = read(fileno(infile), inbuf, inbuf_size);
+               ret = read(fileno(infile), inbuf, AAC_INBUF_SIZE);
                if (ret <= 0)
                        return -E_AAC_READ;
                PARA_INFO_LOG("next buffer: %d bytes\n", ret);
        }
        afi->chunk_table[0] = ret;
                if (ret <= 0)
                        return -E_AAC_READ;
                PARA_INFO_LOG("next buffer: %d bytes\n", ret);
        }
        afi->chunk_table[0] = ret;
-       for (i = 1; i<= num_chunks; i++)
+       for (i = 1; i<= afi->chunks_total; i++)
                afi->chunk_table[i] += ret;
                afi->chunk_table[i] += ret;
-       sprintf(afi->info_string, "audio_file_info1:%zu x %lums\n"
+       sprintf(afi->info_string, "audio_file_info1:%lu x %lums\n"
                "audio_file_info2:\n"
                "audio_file_info3:\n",
                "audio_file_info2:\n"
                "audio_file_info3:\n",
-               num_chunks,
+               afi->chunks_total,
                tv2ms(&afi->chunk_tv));
        tv_scale(20, &afi->chunk_tv, &afi->eof_tv);
        return 1;
                tv2ms(&afi->chunk_tv));
        tv_scale(20, &afi->chunk_tv, &afi->eof_tv);
        return 1;