- ogg_sync_init(sync_in);
- vorbis_info_init(&vi);
- vorbis_comment_init(&vc);
- buf = ogg_sync_buffer(sync_in, (long)len);
- memcpy(buf, map, len);
- ogg_sync_wrote(sync_in, (long)len);
- ret = -E_SYNC_PAGEOUT;
- if (ogg_sync_pageout(sync_in, &page) <= 0) {
- free(stream_in);
- free(stream_out);
- goto err1;
- }
- serial = ogg_page_serialno(&page);
- ogg_stream_init(stream_in, serial);
- ogg_stream_init(stream_out, serial);
- ret = ogg_stream_pagein(stream_in, &page);
- if (ret < 0) {
- ret = -E_STREAM_PAGEIN;
- goto err2;
- }
- ret = ogg_stream_packetout(stream_in, &packet);
- if (ret != 1) {
- ret = -E_STREAM_PACKETOUT;
- goto err2;
- }
- ret = -E_VORBIS;
- if (vorbis_synthesis_headerin(&vi, &vc, &packet) < 0)
- goto err2;
- PARA_DEBUG_LOG("channels: %i, rate: %li\n", vi.channels, vi.rate);
- ogg_stream_packetin(stream_out, &packet);
- ret = ogg_sync_pageout(sync_in, &page);
- if (ret <= 0) {
- ret = -E_SYNC_PAGEOUT;
- goto err2;
+ PARA_DEBUG_LOG("processing ogg packet #%d\n", packet_num);
+ if (packet_num > 2)
+ return 0;
+ if (packet_num == 0) {
+ ogg_stream_init(&vghd->os, serial);
+ ret = ogg_stream_packetin(&vghd->os, packet);
+ if (ret < 0)
+ goto out;
+ ret = -E_OGG_STREAM_FLUSH;
+ if (ogg_stream_flush(&vghd->os, &og) == 0)
+ goto out;
+ add_ogg_page(&og, vghd);
+ return 1;