- vorbis_info_init(&vi);
- vorbis_comment_init(&vc);
-
- ret = -E_SYNC_PAGEOUT;
- if (ogg_sync_pageout(oss, &page) != 1)
- goto out;
-
- ret = ogg_page_serialno(&page);
- ogg_stream_init(&stream, ret);
-
- ret = -E_STREAM_PAGEIN;
- if (ogg_stream_pagein(&stream, &page) < 0)
- goto out;
-
- ret = -E_STREAM_PACKETOUT;
- if (ogg_stream_packetout(&stream, &packet) != 1)
- goto out;
-
- ret = -E_VORBIS;
- if (vorbis_synthesis_headerin(&vi, &vc, &packet) < 0)
- goto out;
- if (vi.rate == 0)
- goto out;
- afhi->channels = vi.channels;
- afhi->frequency = vi.rate;
- afhi->bitrate = vi.bitrate_nominal / 1000;
- PARA_DEBUG_LOG("channels: %i, sampling rate: %i, bitrate: %i\n",
- afhi->channels, afhi->frequency, afhi->bitrate);
- ret = read_vorbis_comment(oss, &stream, &vi, &vc);
+static int vorbis_get_header_callback(ogg_packet *packet, int packet_num,
+ int serial, __a_unused struct afh_info *afhi, void *private_data)
+{
+ int ret;
+ struct oac_custom_header *h = private_data;
+ 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\n", packet_num);
+ if (packet_num == 0) {
+ oac_custom_header_init(serial, h);
+ ret = oac_custom_header_append(packet, h);
+ if (ret < 0)
+ return ret;
+ oac_custom_header_flush(h);
+ return 1;
+ }
+ if (packet_num == 1) {
+ ogg_packet replacement = *packet;
+ PARA_INFO_LOG("replacing metadata packet\n");
+ replacement.packet = dummy_packet;
+ replacement.bytes = sizeof(dummy_packet);
+ ret = oac_custom_header_append(&replacement, h);
+ return ret < 0? ret : 1;
+ }
+ assert(packet_num == 2);
+ ret = oac_custom_header_append(packet, h);