aac: fix some signedness warnings
[paraslash.git] / ogg_afh.c
index eaed162..5adcc25 100644 (file)
--- a/ogg_afh.c
+++ b/ogg_afh.c
@@ -22,9 +22,7 @@
 #include <vorbis/codec.h>
 #include <vorbis/vorbisfile.h>
 
-#include "server.cmdline.h"
 #include "server.h"
-#include "vss.h"
 #include "error.h"
 #include "string.h"
 
@@ -119,12 +117,6 @@ static int ogg_open_callbacks(void *datasource, OggVorbis_File *vf, ov_callbacks
 
 }
 
-static void ogg_save_header(char *map, struct audio_format_info *afi)
-{
-       afi->header = para_malloc(afi->header_len);
-       memcpy(afi->header, map, afi->header_len);
-}
-
 static int ogg_compute_header_len(char *map, off_t numbytes,
                struct audio_format_info *afi)
 {
@@ -189,7 +181,7 @@ static int ogg_compute_header_len(char *map, off_t numbytes,
        while (ogg_stream_flush(stream_out, &page))
                afi->header_len += page.body_len + page.header_len;
        PARA_INFO_LOG("header_len = %d\n", afi->header_len);
-       ogg_save_header(map, afi);
+       afi->header_offset = 0;
        ret = 1;
 err2:
        ogg_stream_destroy(stream_in);
@@ -218,10 +210,10 @@ static long unsigned ogg_compute_chunk_table(OggVorbis_File *of,
        num = time_total / chunk_time + 3;
        PARA_DEBUG_LOG("chunk time: %g allocating %d chunk pointers\n",
                chunk_time, num);
-       afi->chunk_table = para_malloc(num * sizeof(size_t));
+       afi->chunk_table = para_malloc((num + 1) * sizeof(size_t));
        afi->chunk_table[0] = 0;
        max_chunk_len = 0;
-       for (i = 1; ret == 0; i++) {
+       for (i = 1; ret <= num; i++) {
                ogg_int64_t diff;
                ret = ov_time_seek(of, i * chunk_time);
                if (ret)
@@ -238,7 +230,7 @@ static long unsigned ogg_compute_chunk_table(OggVorbis_File *of,
                old_pos = pos;
        }
        num_chunks = i - 1;
-       afi->chunk_table[i] = pos;
+//fi->chunk_table[i] = pos;
        PARA_INFO_LOG("%lu chunks (%fs), max chunk: %zd, min chunk: %zd\n",
                num_chunks, chunk_time, max_chunk_len, min);
        return num_chunks;
@@ -251,10 +243,7 @@ static int ogg_get_file_info(char *map, off_t numbytes,
                struct audio_format_info *afi)
 {
        int ret;
-       double time_total;
        vorbis_info *vi;
-       ogg_int64_t raw_total;
-       long vi_sampling_rate, vi_bitrate;
        OggVorbis_File of;
        const ov_callbacks ovc = {
                .read_func = cb_read,
@@ -274,18 +263,17 @@ static int ogg_get_file_info(char *map, off_t numbytes,
        vi = ov_info(&of, 0);
        if (!vi)
                goto err;
-       time_total = ov_time_total(&of, -1);
-       raw_total = ov_raw_total(&of, -1);
-       afi->seconds_total = time_total;
-       vi_sampling_rate = vi->rate;
-       vi_bitrate = ov_bitrate(&of, 0);
-       afi->chunks_total = ogg_compute_chunk_table(&of, afi, time_total);
-       sprintf(afi->info_string, "audio_file_info1:%lu x %lu, %ldkHz, "
-               "%d channels, %ldkbps\n"
+       afi->seconds_total = ov_time_total(&of, -1);
+       afi->frequency = vi->rate;
+       afi->bitrate = ov_bitrate(&of, 0);
+       afi->channels = vi->channels;
+       afi->chunks_total = ogg_compute_chunk_table(&of, afi, afi->seconds_total);
+       sprintf(afi->info_string, "audio_file_info1:%lu x %lu, %ukHz, "
+               "%d channels, %ukbps\n"
                "audio_file_info2: \n"
                "audio_file_info3: \n",
                afi->chunks_total, (long unsigned) (chunk_time * 1000 * 1000),
-               vi_sampling_rate / 1000, vi->channels, vi_bitrate / 1000
+               afi->frequency / 1000, vi->channels, afi->bitrate / 1000
                );
        afi->chunk_tv.tv_sec = 0;
        afi->chunk_tv.tv_usec = 250 * 1000;
@@ -293,8 +281,6 @@ static int ogg_get_file_info(char *map, off_t numbytes,
        ret = 1;
 err:
        ov_clear(&of); /* keeps the file open */
-       if (ret < 0)
-               free(afi->header);
        return ret;
 }