- 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;
-
- afhi->info_string = NULL;
- 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);
- if (ret < 0)
- 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);
- tv_scale(3, &afhi->chunk_tv, &afhi->eof_tv);
- ret = 0;
-out:
- ogg_sync_clear(&oss);
- return ret;
+ vorbis_comment vc;
+ int ret;
+
+ vorbis_comment_init(&vc);
+ vorbis_comment_add_tag(&vc, "artist", tags->artist);
+ vorbis_comment_add_tag(&vc, "title", tags->title);
+ vorbis_comment_add_tag(&vc, "album", tags->album);
+ vorbis_comment_add_tag(&vc, "year", tags->year);
+ vorbis_comment_add_tag(&vc, "comment", tags->comment);
+ ret = vorbis_commentheader_out(&vc, result);
+ vorbis_comment_clear(&vc);
+ if (ret != 0)
+ return -E_VORBIS_COMMENTHEADER;
+ return 1;