From 65a8a591f1ca6447bb68e78c84aac827a01e56c2 Mon Sep 17 00:00:00 2001 From: shatty Date: Wed, 18 Feb 2004 22:56:41 +0000 Subject: [PATCH] less whacking on the disk during seek to zero. prettier debug output. :-) git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6641 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/media/plugins/ogg/OggSeekable.cpp | 77 ++++++++++--------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/src/add-ons/media/plugins/ogg/OggSeekable.cpp b/src/add-ons/media/plugins/ogg/OggSeekable.cpp index 226bb608cb..ebfaf36808 100644 --- a/src/add-ons/media/plugins/ogg/OggSeekable.cpp +++ b/src/add-ons/media/plugins/ogg/OggSeekable.cpp @@ -323,46 +323,51 @@ OggSeekable::Seek(uint32 seekTo, int64 *frame, bigtime_t *time) // how to handle this? } - // binary search to find our place int64 left_granulepos = 0; - off_t right = GetLastPagePosition(); int64 right_granulepos = 0; - while (true) { - TRACE(" Seek: [%llu,%llu]: ", left, right); - ogg_sync_reset(&fSync); - ogg_stream_reset(&fStreamState); - if (right - left > B_PAGE_SIZE) { - fPosition = (right + left) / 2; - } else { - fPosition = left; - break; - } - do { - status = ReadPage(&page, B_PAGE_SIZE); - if (status != B_OK) { - TRACE("OggSeekable::Seek: ReadPage = %s\n", strerror(status)); - return status; + // if not the first, perform a binary search + if (granulepos != fFirstGranulepos) { + // binary search to find our place + off_t right = GetLastPagePosition(); + uint width = (uint)log10(max_c(1, fFirstGranulepos + right)) + 2; + while (true) { + ogg_sync_reset(&fSync); + ogg_stream_reset(&fStreamState); + if (right - left > B_PAGE_SIZE) { + TRACE(" Seek: [%*lld,%*lld]: ", width, left, width, right); + fPosition = (right + left) / 2; + } else { + TRACE(" Seek: [%*lld,...]\n", width, left); + fPosition = left; + break; } - if (ogg_stream_pagein(&fStreamState, &page) != 0) { - TRACE("OggSeekable::Seek: ogg_stream_pagein: failed??\n"); - return B_ERROR; + do { + status = ReadPage(&page, B_PAGE_SIZE); + if (status != B_OK) { + TRACE("OggSeekable::Seek: ReadPage = %s\n", strerror(status)); + return status; + } + if (ogg_stream_pagein(&fStreamState, &page) != 0) { + TRACE("OggSeekable::Seek: ogg_stream_pagein: failed??\n"); + return B_ERROR; + } + } while (ogg_page_granulepos(&page) == -1); + TRACE("granulepos = %*lld, ", width, ogg_page_granulepos(&page)); + TRACE("fPosition = %*llu\n", width, fPosition); + // check the granulepos of the page against the requested frame + if (ogg_page_granulepos(&page) < granulepos) { + // The packet that the frame is in is someplace after + // the last complete packet in this page. (It may yet + // be in this page, but in a packet completed on the + // next page.) + left = (right + left) / 2; + left_granulepos = ogg_page_granulepos(&page); + continue; + } else { + right = (right + left) / 2; + right_granulepos = ogg_page_granulepos(&page); + continue; } - } while (ogg_page_granulepos(&page) == -1); - TRACE("granulepos = %lld, ", ogg_page_granulepos(&page)); - TRACE("fPosition = %llu\n", fPosition); - // check the granulepos of the page against the requested frame - if (ogg_page_granulepos(&page) < granulepos) { - // The packet that the frame is in is someplace after - // the last complete packet in this page. (It may yet - // be in this page, but in a packet completed on the - // next page.) - left = (right + left) / 2; - left_granulepos = ogg_page_granulepos(&page); - continue; - } else { - right = (right + left) / 2; - right_granulepos = ogg_page_granulepos(&page); - continue; } }