*len = ss;
return 1;
}
-static int aac_find_stsz(char *buf, size_t buflen, off_t *skip)
+static int aac_find_stsz(char *buf, size_t buflen, size_t *skip)
{
int i;
PARA_INFO_LOG("no meta data\n");
}
-static ssize_t aac_compute_chunk_table(struct afh_info *afhi,
- char *map, size_t numbytes)
+static ssize_t aac_compute_chunk_info(struct afh_info *afhi,
+ char *map, size_t numbytes, mp4AudioSpecificConfig *mp4ASC)
{
int ret, i;
- size_t sum = 0;
- off_t skip;
+ size_t skip;
+ float tmp = mp4ASC->sbr_present_flag == 1? 2047 : 1023;
+ struct timeval total;
+ long unsigned ms;
+ afhi->chunk_table = NULL;
ret = aac_find_stsz(map, numbytes, &skip);
if (ret < 0)
return ret;
afhi->chunks_total = ret;
+ afhi->max_chunk_size = 0;
PARA_DEBUG_LOG("sz table has %" PRIu32 " entries\n", afhi->chunks_total);
- afhi->chunk_table = para_malloc((afhi->chunks_total + 1) * sizeof(size_t));
for (i = 1; i <= afhi->chunks_total; i++) {
+ uint32_t val;
if (skip + 4 > numbytes)
break;
- sum += read_u32_be(map + skip);
- afhi->chunk_table[i] = sum;
+ val = read_u32_be(map + skip);
+ afhi->max_chunk_size = PARA_MAX(afhi->max_chunk_size, val);
skip += 4;
-// if (i < 10 || i + 10 > afhi->chunks_total)
-// PARA_DEBUG_LOG("offset #%d: %zu\n", i, afhi->chunk_table[i]);
}
- return skip;
-}
-
-static int aac_set_chunk_tv(struct afh_info *afhi,
- mp4AudioSpecificConfig *mp4ASC, uint32_t *seconds)
-{
- float tmp = mp4ASC->sbr_present_flag == 1? 2047 : 1023;
- struct timeval total;
- long unsigned ms;
ms = 1000.0 * afhi->chunks_total * tmp / mp4ASC->samplingFrequency;
ms2tv(ms, &total);
afhi->chunks_total, tv2ms(&afhi->chunk_tv));
if (ms < 1000)
return -E_MP4ASC;
- *seconds = ms / 1000;
+ afhi->seconds_total = ms / 1000;
+ ret = aac_find_entry_point(map, numbytes, &skip);
+ if (ret < 0)
+ return ret;
+ ret = (numbytes - ret) * 8;
+ ret += (afhi->channels * afhi->seconds_total * 500); /* avoid rounding error */
+ afhi->bitrate = ret / (afhi->channels * afhi->seconds_total * 1000);
return 1;
}
static int aac_get_file_info(char *map, size_t numbytes, __a_unused int fd,
struct afh_info *afhi)
{
- int i;
size_t skip;
ssize_t ret;
unsigned long rate = 0, decoder_len;
goto out;
if (!channels)
goto out;
+ afhi->channels = channels;
+ afhi->frequency = rate;
PARA_DEBUG_LOG("rate: %lu, channels: %d\n", rate, channels);
ret = -E_MP4ASC;
if (NeAACDecAudioSpecificConfig((unsigned char *)map + skip,
goto out;
if (!mp4ASC.samplingFrequency)
goto out;
- ret = aac_compute_chunk_table(afhi, map, numbytes);
- if (ret < 0)
- goto out;
- skip = ret;
- ret = aac_set_chunk_tv(afhi, &mp4ASC, &afhi->seconds_total);
- if (ret < 0)
- goto out;
- ret = aac_find_entry_point(map + skip, numbytes - skip, &skip);
+ ret = aac_compute_chunk_info(afhi, map, numbytes, &mp4ASC);
if (ret < 0)
goto out;
- afhi->chunk_table[0] = ret;
- for (i = 1; i<= afhi->chunks_total; i++)
- afhi->chunk_table[i] += ret;
- set_max_chunk_size(afhi);
- afhi->channels = channels;
- afhi->frequency = rate;
- ret = (afhi->chunk_table[afhi->chunks_total] - afhi->chunk_table[0]) * 8; /* bits */
- ret += (channels * afhi->seconds_total * 500); /* avoid rounding error */
- afhi->bitrate = ret / (channels * afhi->seconds_total * 1000);
ret = 1;
out:
if (handle)