X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=ogg_afh_common.c;h=777e2138ec3f858b5fe14e5706e9f74806944821;hb=3569c4ac0d5b35318e741b0123bc707473261ad9;hp=353bc9bb51a3e18a5e26fac359dd8aebfdcbbb8e;hpb=dae03f0046d6695172aa32722600e1b9deea1e9c;p=paraslash.git diff --git a/ogg_afh_common.c b/ogg_afh_common.c index 353bc9bb..777e2138 100644 --- a/ogg_afh_common.c +++ b/ogg_afh_common.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2010 Andre Noll + * Copyright (C) 2004-2011 Andre Noll * * 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; @@ -64,9 +71,10 @@ static int process_ogg_packets(ogg_sync_state *oss, struct afh_info *afhi, ogg_page page; int ret; - ret = -E_SYNC_PAGEOUT; if (ogg_sync_pageout(oss, &page) != 1) - goto out; + 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); @@ -78,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); @@ -111,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. @@ -144,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 */ @@ -164,7 +175,7 @@ int ogg_get_file_info(char *map, size_t numbytes, struct afh_info *afhi, afhi->chunk_table[1] = afhi->header_len; oss.returned = afhi->header_len; oss.fill = numbytes; - for (i = 0, j = 1; ogg_sync_pageseek(&oss, &op) > 0; i++) { + for (j = 1; ogg_sync_pageseek(&oss, &op) > 0; /* nothing */) { int granule = ogg_page_granulepos(&op); while (granule > j * frames_per_chunk) {