From 53d4f7cf34fb61f0e122df918ac09f04e484460c Mon Sep 17 00:00:00 2001 From: shatty Date: Fri, 13 Feb 2004 08:16:22 +0000 Subject: [PATCH] FindLastPage fix for reading broken cd files (weird case where you can get 0 bytes read even if you seek in front of the end of the file). also some performance check on FindLastPages performance. print frame count/duration computed in GetStreamInfo. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6574 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../media/plugins/ogg/OggReaderPlugin.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/add-ons/media/plugins/ogg/OggReaderPlugin.cpp b/src/add-ons/media/plugins/ogg/OggReaderPlugin.cpp index 8ec331ccf2..a4a5efa0f3 100644 --- a/src/add-ons/media/plugins/ogg/OggReaderPlugin.cpp +++ b/src/add-ons/media/plugins/ogg/OggReaderPlugin.cpp @@ -287,7 +287,10 @@ OggReader::GetStreamInfo(void *cookie, int64 *frameCount, bigtime_t *duration, *infoBuffer = 0; *infoSize = 0; OggTrack * track = static_cast(cookie); - return track->GetStreamInfo(frameCount, duration, format); + status_t status = track->GetStreamInfo(frameCount, duration, format); + TRACE("OggReader::GetStreamInfo: cookie=%x, frame count = %lld, duration = %lld.%lld seconds\n", + *(int*)cookie, *frameCount, (*duration)/1000000, (*duration)%1000000); + return status; } @@ -317,6 +320,8 @@ status_t OggReader::FindLastPages() { TRACE("OggReader::FindLastPages\n"); + bigtime_t start_time = system_time(); + status_t result = B_ERROR; const int read_size = 256*256; @@ -331,10 +336,12 @@ OggReader::FindLastPages() uint serial_count = 0; while (serial_count < fCookies.size()) { int offset; + ssize_t bytes = 0; while ((offset = ogg_sync_pageseek(&sync, &page)) <= 0) { left += -offset; if (offset == 0) { - if (fSeekable->Position() >= right) { + off_t pos = fSeekable->Position(); + if (pos >= right || bytes == 0) { if (left == 0) { TRACE("OggReader::FindLastPages: couldn't find some stream's page!!!\n"); goto done; @@ -345,10 +352,9 @@ OggReader::FindLastPages() goto done; } ogg_sync_reset(&sync); - continue; } char * buffer = ogg_sync_buffer(&sync, read_size); - ssize_t bytes = fSeekable->Read(buffer, read_size); + bytes = fSeekable->Read(buffer, read_size); if (bytes < 0) { TRACE("OggReader::FindLastPages: Read: error\n"); result = bytes; @@ -381,6 +387,8 @@ OggReader::FindLastPages() result = B_OK; done: ogg_sync_clear(&sync); + TRACE("OggReader::FindLastPages took %lld microseconds\n", system_time() - start_time); + return result; }