+static ssize_t aac_compute_chunk_table(struct afh_info *afhi,
+ unsigned char *map, size_t numbytes)
+{
+ int ret, i;
+ size_t sum = 0;
+ off_t skip;
+
+ ret = aac_find_stsz(map, numbytes, &skip);
+ if (ret < 0)
+ return ret;
+ afhi->chunks_total = ret;
+ 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++) {
+ if (skip + 4 > numbytes)
+ break;
+ sum += aac_read_int32(map + skip);
+ afhi->chunk_table[i] = sum;
+ 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;
+
+ if (!mp4ASC->samplingFrequency)
+ return -E_MP4ASC;
+ ms = 1000.0 * afhi->chunks_total * tmp / mp4ASC->samplingFrequency;
+ ms2tv(ms, &total);
+ tv_divide(afhi->chunks_total, &total, &afhi->chunk_tv);
+ PARA_INFO_LOG("%luHz, %lus (%" PRIu32 " x %lums)\n",
+ mp4ASC->samplingFrequency, ms / 1000,
+ afhi->chunks_total, tv2ms(&afhi->chunk_tv));
+ if (ms < 1000)
+ return -E_MP4ASC;
+ *seconds = ms / 1000;
+ return 1;
+}