- int ret, i;
- 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);
- for (i = 1; i <= afhi->chunks_total; i++) {
- uint32_t val;
- if (skip + 4 > numbytes)
- break;
- val = read_u32_be(map + skip);
- afhi->max_chunk_size = PARA_MAX(afhi->max_chunk_size, val);
- skip += 4;
- }
-
- 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;
- 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;