Create three ogg pages when skipping vorbis comments.
[paraslash.git] / ogg_afh_common.c
index 6642fed35208564c3b5f131c5be0740cb27a58db..777e2138ec3f858b5fe14e5706e9f74806944821 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004-2010 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2004-2011 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -32,18 +32,25 @@ static int process_packets_2_and_3(ogg_sync_state *oss,
                                break; /* Need more data */
                        if (ret != 1)
                                continue;
+                       PARA_DEBUG_LOG("next input page (header/body): %lu/%lu\n",
+                               page.header_len, page.body_len);
                        /*
                         * We can ignore any errors here as they'll also become
                         * apparent at packetout.
                         */
                        ogg_stream_pagein(stream, &page);
+                       PARA_DEBUG_LOG("ogg page serial: %d\n",
+                               ogg_page_serialno(&page));
                        while (i < 2) {
                                ret = ogg_stream_packetout(stream, &packet);
+                               PARA_DEBUG_LOG("packet #%d: %lu bytes\n", i + 1,
+                                       packet.bytes);
                                if (ret == 0)
                                        break;
                                if (ret < 0)
                                        return -E_STREAM_PACKETOUT;
-                               ret = ci->packet_callback(&packet, i + 1, afhi,
+                               ret = ci->packet_callback(&packet, i + 1,
+                                       ogg_page_serialno(&page), afhi,
                                        ci->private_data);
                                if (ret < 0)
                                        return ret;
@@ -66,6 +73,8 @@ static int process_ogg_packets(ogg_sync_state *oss, struct afh_info *afhi,
 
        if (ogg_sync_pageout(oss, &page) != 1)
                return -E_SYNC_PAGEOUT;
+       PARA_DEBUG_LOG("first input page (header/body): %lu/%lu\n",
+               page.header_len, page.body_len);
 
        ret = ogg_page_serialno(&page);
        ogg_stream_init(&stream, ret);
@@ -77,14 +86,14 @@ static int process_ogg_packets(ogg_sync_state *oss, struct afh_info *afhi,
        ret = -E_STREAM_PACKETOUT;
        if (ogg_stream_packetout(&stream, &packet) != 1)
                goto out;
-       ret = ci->packet_callback(&packet, 0, afhi, ci->private_data);
+       PARA_DEBUG_LOG("packet #0: %lu bytes\n", packet.bytes);
+       ret = ci->packet_callback(&packet, 0, ogg_page_serialno(&page),
+               afhi, ci->private_data);
        if (ret < 0)
                goto out;
        ret = process_packets_2_and_3(oss, &stream, afhi, ci);
        if (ret < 0)
                goto out;
-       afhi->header_offset = 0;
-       afhi->header_len = oss->returned;
        ret = 1;
 out:
        ogg_stream_clear(&stream);
@@ -110,9 +119,9 @@ static void set_chunk_tv(int num_frames, int num_chunks, int frequency,
  * given by \a map and \a numbytes and passes each packet to the callback
  * defined by \a ci.
  *
- * If the packet callback indicates success, the chunk table is built.  Chunk
- * zero contains the first three ogg packets while all other chunks consist of
- * exactly one ogg page.
+ * If the packet callback indicates success and \a afhi is not \p NULL, the
+ * chunk table is built. Chunk zero contains the first three ogg packets while
+ * all other chunks consist of exactly one ogg page.
  *
  * \param map Audio file data.
  * \param numbytes The length of \a map.
@@ -143,6 +152,9 @@ int ogg_get_file_info(char *map, size_t numbytes, struct afh_info *afhi,
        ret = process_ogg_packets(&oss, afhi, ci);
        if (ret < 0)
                goto out;
+       if (!afhi)
+               goto out;
+       afhi->header_len = oss.returned;
        oss.returned = 0;
        oss.fill = numbytes;
        /* count ogg packages and get duration of the file */