do not copy the audio file header
[paraslash.git] / aac_afh.c
index 17b7225020417e732fa5bf4ea2c0a966b2c73fe0..e9417d2c5c004304979af625fe87f15dbefc496f 100644 (file)
--- a/aac_afh.c
+++ b/aac_afh.c
 
 /** \file aac_afh.c para_server's aac audio format handler */
 
-#include "server.cmdline.h"
 #include "server.h"
-#include "vss.h"
 #include "error.h"
 #include "string.h"
 #include "aac.h"
-#include "fd.h"
 
 static int aac_find_stsz(unsigned char *buf, off_t buflen, off_t *skip)
 {
@@ -91,13 +88,13 @@ static long unsigned aac_set_chunk_tv(struct audio_format_info *afi,
        PARA_INFO_LOG("%luHz, %fs (%lu x %lums)\n",
                mp4ASC->samplingFrequency, ms / 1000,
                afi->chunks_total, tv2ms(&afi->chunk_tv));
-       return ms / 1000;
+       return ms < 1000? -E_MP4ASC : ms / 1000;
 }
 
 /*
  * Init m4a file and write some tech data to given pointers.
  */
-static int aac_get_file_info(__a_unused FILE *file, char *map, off_t numbytes,
+static int aac_get_file_info(char *map, off_t numbytes,
                struct audio_format_info *afi)
 {
        int i;
@@ -116,10 +113,14 @@ static int aac_get_file_info(__a_unused FILE *file, char *map, off_t numbytes,
        ret = -E_AACDEC_INIT;
        if (NeAACDecInit(handle, map + skip, decoder_len, &rate, &channels))
                goto out;
+       if (!channels)
+               goto out;
        PARA_INFO_LOG("rate: %lu, channels: %d\n", rate, channels);
        ret = -E_MP4ASC;
        if (NeAACDecAudioSpecificConfig(map + skip, numbytes - skip, &mp4ASC))
                goto out;
+       if (!mp4ASC.samplingFrequency)
+               goto out;
        ret = aac_compute_chunk_table(afi, map, numbytes);
        if (ret < 0)
                goto out;
@@ -131,11 +132,18 @@ static int aac_get_file_info(__a_unused FILE *file, char *map, off_t numbytes,
        afi->chunk_table[0] = ret;
        for (i = 1; i<= afi->chunks_total; i++)
                afi->chunk_table[i] += ret;
-       sprintf(afi->info_string, "audio_file_info1:%lu x %lums\n"
+       afi->channels = channels;
+       afi->frequency = rate;
+       ret = (afi->chunk_table[afi->chunks_total] - afi->chunk_table[0]) * 8; /* bits */
+       ret += (channels * afi->seconds_total * 500); /* avoid rounding error */
+       afi->bitrate = ret / (channels * afi->seconds_total * 1000);
+       sprintf(afi->info_string, "audio_file_info1:%lu x %lums, "
+               "%uHz, %d channel%s, %ukb/s\n"
                "audio_file_info2:\n"
                "audio_file_info3:\n",
-               afi->chunks_total,
-               tv2ms(&afi->chunk_tv));
+               afi->chunks_total, tv2ms(&afi->chunk_tv),
+               afi->frequency, channels, channels == 1? "" : "s", afi->bitrate
+       );
        tv_scale(20, &afi->chunk_tv, &afi->eof_tv);
        ret = 1;
 out: