- int ret;
-
- header = para_malloc(len);
- rewind(file);
- ret = read(fileno(file), header, len);
- if (ret == len)
- return 1;
- free(header);
- return -E_OGG_READ;
-}
-
-/*
- * Init oggvorbis file and write some tech data to given pointers.
- */
-static int ogg_get_file_info(FILE *file, char *info_str, long unsigned *frames,
- int *seconds, size_t **vss_chunk_table)
-{
- int ret;
- double time_total;
- vorbis_info *vi;
- ogg_int64_t raw_total;
- long vi_sampling_rate, vi_bitrate;
- OggVorbis_File of;
- static const ov_callbacks ovc = {
- .read_func = cb_read,
- .seek_func = cb_seek,
- .close_func = cb_close,
- .tell_func = cb_tell
- };
-
- if (!file)
- return -E_OGG_NO_FILE;
- ret = ogg_compute_header_len(file);
- if (ret < 0)
- return ret;
- ret = ogg_save_header(file, header_len);
- if (ret < 0)
- return ret;
- rewind(file);
- ret = ogg_open_callbacks(file, &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);
- *seconds = time_total;
- vi_sampling_rate = vi->rate;
- vi_bitrate = ov_bitrate(&of, 0);
- rewind(file);
- *frames = ogg_compute_chunk_table(&of, time_total);
- rewind(file);
- *vss_chunk_table = chunk_table;
- sprintf(info_str, "audio_file_info1:%lu x %lu, %ldkHz, %d channels, %ldkbps\n"
- "audio_file_info2: \n"
- "audio_file_info3: \n",
- *frames, (long unsigned) (chunk_time * 1000 * 1000),
- vi_sampling_rate / 1000, vi->channels, vi_bitrate / 1000
- );
- rewind(file);
- audio_file = file;
- 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);