- FILE *f = datasource;
- return ftell(f);
-}
-
-int ogg_open_callbacks(void *datasource, OggVorbis_File *vf, ov_callbacks c)
-{
- int ret = ov_open_callbacks(datasource, vf,
- NULL, /* no initial buffer */
- 0, /* no initial bytes */
- c); /* the ov_open_callbacks */
-
- /* FIXME: provide better error codes */
- if (ret == OV_EREAD)
- return -E_OGG_READ;
- if (ret == OV_ENOTVORBIS)
- return -E_OGG_READ;
- if (ret == OV_EVERSION)
- return -E_OGG_READ;
- if (ret == OV_EBADHEADER)
- return -E_OGG_READ;
- if (ret < 0)
- return -E_OGG_READ;
- return 1;
-
-}
-
-static int ogg_compute_header_len(FILE *file)
-{
- int ret, len, in = fileno(file);
- unsigned int serial;
- char *buf;
- ogg_page page;
- ogg_packet packet;
- vorbis_comment vc;
- vorbis_info vi;
- ogg_stream_state *stream_in = para_malloc(sizeof(ogg_stream_state));
- ogg_stream_state *stream_out = para_malloc(sizeof(ogg_stream_state));
- ogg_sync_state *sync_in = para_malloc(sizeof(ogg_sync_state));
-
- ogg_sync_init(sync_in);
- vorbis_info_init(&vi);
- vorbis_comment_init(&vc);
- buf = ogg_sync_buffer(sync_in, CHUNK_SIZE);
- len = read(in, buf, CHUNK_SIZE);
- ret = -E_OGG_READ;
- if (len <= 0)
- goto err1;
- ogg_sync_wrote(sync_in, len);
- ret = -E_SYNC_PAGEOUT;
- if (ogg_sync_pageout(sync_in, &page) <= 0)
- 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_INFO_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;
- }
- ogg_stream_pagein(stream_in, &page);
- ogg_stream_packetout(stream_in, &packet);
- ogg_stream_packetin(stream_out, &packet);
-
- ret = ogg_sync_pageout(sync_in, &page);
- if (ret <= 0) {
- ret = -E_SYNC_PAGEOUT;
- goto err2;
- }
- ogg_stream_pagein(stream_in, &page);
- ogg_stream_packetout(stream_in, &packet);
- ogg_stream_packetin(stream_out, &packet);