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
This commit is contained in:
shatty
2004-01-25 12:45:14 +00:00
parent a511a51332
commit 801227279c
5 changed files with 37 additions and 24 deletions
@@ -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,13 +40,13 @@ 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
@@ -55,3 +54,4 @@ OggFrameInfo::GetNextPacket() const
{
return packet + 1;
}
+5 -6
View File
@@ -1,27 +1,26 @@
#ifndef _OGG_FRAME_INFO_H
#define _OGG_FRAME_INFO_H
#include <sys/types.h>
#include <SupportDefs.h>
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
@@ -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;
@@ -51,6 +51,8 @@ protected:
BPositionIO * fSeekable;
private:
off_t fNextPosition;
class GetPageInterface {
public:
virtual status_t GetNextPage() = 0;
+13 -3
View File
@@ -97,10 +97,12 @@ 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);
@@ -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++;