- 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);
- if (ret < 0)
+ int ret;
+ struct vorbis_get_header_data *vghd = private_data;
+ ogg_page og;
+ static unsigned char dummy_packet[] = {
+ 0x03,
+ 'v', 'o', 'r', 'b', 'i', 's',
+ 0x06, 0x00, 0x00, 0x00,
+ 'd', 'u', 'm', 'm', 'y', '\0',
+ 0x00, 0x00, 0x00, 0x00, /* no comment :) */
+ 0xff /* framing bit */
+ };
+
+ PARA_DEBUG_LOG("processing ogg packet #%d (%li bytes)\n",
+ packet_num, packet->bytes);
+ if (packet_num > 2)
+ return 0;
+ if (packet_num == 0) {
+ ogg_stream_init(&vghd->os, serial);
+ ret = -E_OGG_PACKET_IN;
+ 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;
+ }
+ if (packet_num == 1) {
+ PARA_INFO_LOG("replacing metadata packet (saved %ld bytes)\n",
+ packet->bytes - sizeof(dummy_packet));
+ ogg_packet replacement = *packet;
+ replacement.packet = dummy_packet;
+ replacement.bytes = sizeof(dummy_packet);
+ ret = -E_OGG_PACKET_IN;
+ if (ogg_stream_packetin(&vghd->os, &replacement) < 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;
+ }
+ ret = -E_OGG_PACKET_IN;
+ if (ogg_stream_packetin(&vghd->os, packet) < 0)