- goto err;
- ret = -E_OGG_INFO;
- vi = ov_info(&of, 0);
- if (!vi)
- goto err;
- afi->seconds_total = ov_time_total(&of, -1);
- afi->frequency = vi->rate;
- afi->bitrate = ov_bitrate(&of, 0) / 1000;
- 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),
- afi->frequency / 1000, vi->channels, afi->bitrate
- );
- afi->chunk_tv.tv_sec = 0;
- afi->chunk_tv.tv_usec = 250 * 1000;
- tv_scale(3, &afi->chunk_tv, &afi->eof_tv);
- ret = 1;
-err:
- ov_clear(&of); /* keeps the file open */
+ goto out;
+ oss.returned = 0;
+ oss.fill = numbytes;
+ /* count ogg packages and get duration of the file */
+ for (i = 0; ogg_sync_pageseek(&oss, &op) > 0; i++)
+ num_frames = ogg_page_granulepos(&op);
+ PARA_INFO_LOG("%d pages, %llu frames\n", i, num_frames);
+ ret = -E_OGG_EMPTY;
+ if (i == 0)
+ goto out;
+ afhi->seconds_total = num_frames / afhi->frequency;
+ /* use roughly one page per chunk */
+ frames_per_chunk = num_frames / i;
+ PARA_INFO_LOG("%lu seconds, %d frames/chunk\n",
+ afhi->seconds_total, frames_per_chunk);
+ ct_size = 250;
+ afhi->chunk_table = para_malloc(ct_size * sizeof(uint32_t));
+ afhi->chunk_table[0] = 0;
+ afhi->chunk_table[1] = afhi->header_len;
+ oss.returned = afhi->header_len;
+ oss.fill = numbytes;
+ for (i = 0, j = 1; ogg_sync_pageseek(&oss, &op) > 0; i++) {
+ int granule = ogg_page_granulepos(&op);
+
+ while (granule > j * frames_per_chunk) {
+ j++;
+ if (j >= ct_size) {
+ ct_size *= 2;
+ afhi->chunk_table = para_realloc(
+ afhi->chunk_table,
+ ct_size * sizeof(uint32_t));
+ }
+ afhi->chunk_table[j] = oss.returned;
+ }
+ }
+ afhi->chunks_total = j;
+ set_chunk_tv(num_frames, j, afhi->frequency, &afhi->chunk_tv);
+ ret = 0;
+out:
+ ogg_sync_clear(&oss);