From 801227279c01f38eb8285131e365d82bdd455b28 Mon Sep 17 00:00:00 2001 From: shatty Date: Sun, 25 Jan 2004 12:45:14 +0000 Subject: [PATCH] static variables in functions are all fun and good until you realize that they are not equivalent to class level variables when that function is a method git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6277 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../media/plugins/ogg/OggFrameInfo.cpp | 12 ++++---- src/add-ons/media/plugins/ogg/OggFrameInfo.h | 11 ++++---- .../media/plugins/ogg/OggReaderPlugin.cpp | 8 ++++-- .../media/plugins/ogg/OggReaderPlugin.h | 2 ++ src/add-ons/media/plugins/ogg/OggStream.cpp | 28 +++++++++++++------ 5 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/add-ons/media/plugins/ogg/OggFrameInfo.cpp b/src/add-ons/media/plugins/ogg/OggFrameInfo.cpp index 7418218c51..bc448a28da 100644 --- a/src/add-ons/media/plugins/ogg/OggFrameInfo.cpp +++ b/src/add-ons/media/plugins/ogg/OggFrameInfo.cpp @@ -9,10 +9,9 @@ OggFrameInfo::OggFrameInfo(uint page, uint packetonpage, uint packet) } void -OggFrameInfo::SetNext(uint page, uint packetonpage, uint packet) +OggFrameInfo::SetNextIsNewPage(bool newpage) { - nextpage = page; - nextpacketonpage = packetonpage; + this->newpage = newpage; } /* virtual */ @@ -41,17 +40,18 @@ OggFrameInfo::GetPacket() const uint OggFrameInfo::GetNextPage() const { - return nextpage; + return (newpage ? page + 1 : page); } uint OggFrameInfo::GetNextPacketOnPage() const { - return nextpacketonpage; + return (newpage ? 0 : packetonpage + 1); } uint OggFrameInfo::GetNextPacket() const { - return packet+1; + return packet + 1; } + diff --git a/src/add-ons/media/plugins/ogg/OggFrameInfo.h b/src/add-ons/media/plugins/ogg/OggFrameInfo.h index fc94fc19c0..3a7d8eb9af 100644 --- a/src/add-ons/media/plugins/ogg/OggFrameInfo.h +++ b/src/add-ons/media/plugins/ogg/OggFrameInfo.h @@ -1,27 +1,26 @@ #ifndef _OGG_FRAME_INFO_H #define _OGG_FRAME_INFO_H -#include +#include class OggFrameInfo { public: OggFrameInfo(uint page, uint packetonpage, uint packet); virtual ~OggFrameInfo(); - void SetNext(uint page, uint packetonpage, uint packet); + void SetNextIsNewPage(bool newpage = true); uint GetPage() const; uint GetPacketOnPage() const; uint GetPacket() const; + uint GetNextPage() const; uint GetNextPacketOnPage() const; uint GetNextPacket() const; private: uint page; // the page the frame started on - uint packetonpage; // of all the packets on that page which packet is this + uint16 packetonpage; // of all the packets on that page which packet is this uint packet; // the packet the frame started on - uint nextpage; // the next page after this page - uint nextpacketonpage; // of all the packets on next page which packet is the next - uint nextpacket; // the next packet after this packet + bool newpage; }; #endif _OGG_FRAME_INFO_H diff --git a/src/add-ons/media/plugins/ogg/OggReaderPlugin.cpp b/src/add-ons/media/plugins/ogg/OggReaderPlugin.cpp index 0ed85b4161..03526f5e2a 100644 --- a/src/add-ons/media/plugins/ogg/OggReaderPlugin.cpp +++ b/src/add-ons/media/plugins/ogg/OggReaderPlugin.cpp @@ -33,6 +33,7 @@ OggReader::~OggReader() delete j->second; } ogg_sync_clear(&fSync); + fNextPosition = -1; } @@ -48,8 +49,7 @@ OggReader::GetPage(ogg_page * page, int read_size, bool short_page) { // TRACE("OggReader::GetPage\n"); retry: - static off_t next_position = (fSeekable ? fSeekable->Position() : -1); - off_t position = next_position; + off_t position = fNextPosition; int result = ogg_sync_pageout(&fSync,page); // first read leftovers while (result == 0) { char * buffer = ogg_sync_buffer(&fSync,read_size); @@ -82,7 +82,7 @@ retry: return B_ERROR; } #endif - next_position += page->header_len + page->body_len; + fNextPosition += (fSeekable ? page->header_len + page->body_len : 0); long serialno = ogg_page_serialno(page); if (fStreams.find(serialno) == fStreams.end()) { // this is an unknown serialno @@ -233,6 +233,8 @@ OggReader::Sniff(int32 *streamCount) #endif fSeekable = get_seekable(Source()); + fNextPosition = (fSeekable ? fSeekable->Position() : -1); + ogg_page page; if (GetPage(&page,4096,short_page) != B_OK) { return B_ERROR; diff --git a/src/add-ons/media/plugins/ogg/OggReaderPlugin.h b/src/add-ons/media/plugins/ogg/OggReaderPlugin.h index 4ad48fb155..fc93d34963 100644 --- a/src/add-ons/media/plugins/ogg/OggReaderPlugin.h +++ b/src/add-ons/media/plugins/ogg/OggReaderPlugin.h @@ -51,6 +51,8 @@ protected: BPositionIO * fSeekable; private: + off_t fNextPosition; + class GetPageInterface { public: virtual status_t GetNextPage() = 0; diff --git a/src/add-ons/media/plugins/ogg/OggStream.cpp b/src/add-ons/media/plugins/ogg/OggStream.cpp index 016578c38f..93277ac918 100644 --- a/src/add-ons/media/plugins/ogg/OggStream.cpp +++ b/src/add-ons/media/plugins/ogg/OggStream.cpp @@ -97,18 +97,20 @@ OggStream::GetSerial() const status_t OggStream::AddPage(off_t position, ogg_page * page) { - TRACE("OggStream::AddPage %llu\n",position); + TRACE("OggStream::AddPage"); if (position >= 0) { + TRACE(" %lld", position); fPagePositions.push_back(position); } + TRACE("\n"); BAutolock autolock(fSyncLock); char * buffer; - buffer = ogg_sync_buffer(&fSync,page->header_len); - memcpy(buffer,page->header,page->header_len); - ogg_sync_wrote(&fSync,page->header_len); - buffer = ogg_sync_buffer(&fSync,page->body_len); - memcpy(buffer,page->body,page->body_len); - ogg_sync_wrote(&fSync,page->body_len); + buffer = ogg_sync_buffer(&fSync, page->header_len); + memcpy(buffer,page->header, page->header_len); + ogg_sync_wrote(&fSync, page->header_len); + buffer = ogg_sync_buffer(&fSync, page->body_len); + memcpy(buffer,page->body, page->body_len); + ogg_sync_wrote(&fSync, page->body_len); return B_OK; } @@ -202,7 +204,7 @@ OggStream::Seek(uint32 seekTo, int64 *frame, bigtime_t *time) // instead we just let it go out of scope fCurrentPage = fOggFrameInfos[*frame].GetNextPage(); fPacketOnCurrentPage = fOggFrameInfos[*frame].GetNextPacketOnPage(); - fCurrentPacket = fOggFrameInfos[*frame].GetNextPacket(); + fCurrentPacket = fOggFrameInfos[*frame].GetPacket()+1; } else if (seekTo & B_MEDIA_SEEK_TO_TIME) { *frame = *time/50000; return Seek(B_MEDIA_SEEK_TO_FRAME,frame,time); @@ -216,13 +218,15 @@ OggStream::GetNextChunk(void **chunkBuffer, int32 *chunkSize, media_header *mediaHeader) { static ogg_packet packet; + uint page = fEndPage; if (fCurrentPacket - fHeaderPackets.size() == fOggFrameInfos.size()) { OggFrameInfo info(fEndPage,fPacketOnEndPage,fEndPacket); fOggFrameInfos.push_back(info); } status_t result = GetPacket(&packet); if (fCurrentPacket - fHeaderPackets.size() == fOggFrameInfos.size()) { - fOggFrameInfos[fOggFrameInfos.size()-1].SetNext(fEndPage,fPacketOnEndPage,fEndPacket); + if (page != fEndPage) { + } } if (result != B_OK) { TRACE("OggStream::GetNextChunk failed: GetPacket = %s\n", strerror(result)); @@ -268,6 +272,12 @@ OggStream::GetPacket(ogg_packet * packet) } fEndPacket++; if (pageno != fEndPage) { + size_t last_info = fOggFrameInfos.size(); + if (last_info > 0) { + if (fOggFrameInfos[last_info-1].GetNextPacket() == fEndPacket) { + fOggFrameInfos[last_info-1].SetNextIsNewPage(); + } + } fPacketOnEndPage = 0; } else { fPacketOnEndPage++;