build: Reduce redundancy in configure.ac, convert osl detection.
[paraslash.git] / ogg_afh_common.c
index 777e213..61ded4d 100644 (file)
@@ -1,10 +1,10 @@
 /*
- * Copyright (C) 2004-2011 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2004 Andre Noll <maan@tuebingen.mpg.de>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
-/** \file ogg_afh_common.c Functions common to ogg/vorbis and ogg/speex. */
+/** \file ogg_afh_common.c Functions common to all ogg/ codecs. */
 
 #include <ogg/ogg.h>
 #include <regex.h>
@@ -32,19 +32,15 @@ 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",
+                       PARA_INFO_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)
@@ -73,8 +69,6 @@ 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);
@@ -86,7 +80,6 @@ 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;
-       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)
@@ -100,16 +93,15 @@ out:
        return ret;
 }
 
-static void set_chunk_tv(int num_frames, int num_chunks, int frequency,
+static void set_chunk_tv(int frames_per_chunk, int frequency,
                struct timeval *result)
 {
-       uint64_t x = (uint64_t)num_frames * 1000 * 1000
-               / frequency / num_chunks;
+       uint64_t x = (uint64_t)frames_per_chunk * 1000 * 1000 / frequency;
 
        result->tv_sec = x / 1000 / 1000;
        result->tv_usec = x % (1000 * 1000);
-       PARA_INFO_LOG("%d chunks, chunk time: %lums\n", num_chunks,
-               tv2ms(result));
+       PARA_INFO_LOG("%d frames per chunk, chunk time: %lums\n",
+               frames_per_chunk, tv2ms(result));
 }
 
 /**
@@ -157,7 +149,7 @@ int ogg_get_file_info(char *map, size_t numbytes, struct afh_info *afhi,
        afhi->header_len = oss.returned;
        oss.returned = 0;
        oss.fill = numbytes;
-       /* count ogg packages and get duration of the file */
+       /* count ogg pages and get duration of the file */
        for (i = 0; ogg_sync_pageseek(&oss, &op) > 0; i++)
                num_frames = ogg_page_granulepos(&op);
        PARA_INFO_LOG("%d pages, %llu frames\n", i, num_frames);
@@ -178,7 +170,7 @@ int ogg_get_file_info(char *map, size_t numbytes, struct afh_info *afhi,
        for (j = 1; ogg_sync_pageseek(&oss, &op) > 0; /* nothing */) {
                int granule = ogg_page_granulepos(&op);
 
-               while (granule > j * frames_per_chunk) {
+               while (granule >= (j + 1) * frames_per_chunk) {
                        j++;
                        if (j >= ct_size) {
                                ct_size *= 2;
@@ -190,7 +182,7 @@ int ogg_get_file_info(char *map, size_t numbytes, struct afh_info *afhi,
                }
        }
        afhi->chunks_total = j;
-       set_chunk_tv(num_frames, j, afhi->frequency, &afhi->chunk_tv);
+       set_chunk_tv(frames_per_chunk, afhi->frequency, &afhi->chunk_tv);
        ret = 0;
 out:
        ogg_sync_clear(&oss);