- int ret;
- double time_total;
- vorbis_info *vi;
- ogg_int64_t raw_total;
- long vi_sampling_rate, vi_bitrate;
- OggVorbis_File of;
- const ov_callbacks ovc = {
- .read_func = cb_read,
- .seek_func = cb_seek,
- .close_func = cb_close,
- .tell_func = cb_tell
- };
- struct ogg_datasource ods = {.map = map, .numbytes = numbytes, .fpos = 0};
-
- ret = ogg_compute_header_len(map, numbytes, afi);
- if (ret < 0)
- return ret;
- ret = ogg_open_callbacks(&ods, &of, ovc);
- if (ret < 0)
- goto err;
- ret = -E_OGG_INFO;
- vi = ov_info(&of, 0);
- if (!vi)
- goto err;
- time_total = ov_time_total(&of, -1);
- raw_total = ov_raw_total(&of, -1);
- afi->seconds_total = time_total;
- vi_sampling_rate = vi->rate;
- vi_bitrate = ov_bitrate(&of, 0);
- afi->chunks_total = ogg_compute_chunk_table(&of, afi, time_total);
- sprintf(afi->info_string, "audio_file_info1:%lu x %lu, %ldkHz, "
- "%d channels, %ldkbps\n"
- "audio_file_info2: \n"
- "audio_file_info3: \n",
- afi->chunks_total, (long unsigned) (chunk_time * 1000 * 1000),
- vi_sampling_rate / 1000, vi->channels, vi_bitrate / 1000
- );
- 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 */
+ ogg_sync_state oss;
+ ogg_page op;
+ long len = numbytes;
+ char *buf;
+ int ret, i, j, frames_per_chunk, ct_size;
+ long long unsigned num_frames = 0;
+
+ ogg_sync_init(&oss);
+ ret = -E_OGG_SYNC;
+ buf = ogg_sync_buffer(&oss, len);
+ if (!buf)
+ goto out;
+ memcpy(buf, map, len);
+ ret = -E_OGG_SYNC;
+ if (ogg_sync_wrote(&oss, len) < 0)
+ goto out;
+ ret = read_vorbis_info(&oss, afhi);