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 void
OggFrameInfo::SetNext(uint page, uint packetonpage, uint packet) OggFrameInfo::SetNextIsNewPage(bool newpage)
{ {
nextpage = page; this->newpage = newpage;
nextpacketonpage = packetonpage;
} }
/* virtual */ /* virtual */
@@ -41,17 +40,18 @@ OggFrameInfo::GetPacket() const
uint uint
OggFrameInfo::GetNextPage() const OggFrameInfo::GetNextPage() const
{ {
return nextpage; return (newpage ? page + 1 : page);
} }
uint uint
OggFrameInfo::GetNextPacketOnPage() const OggFrameInfo::GetNextPacketOnPage() const
{ {
return nextpacketonpage; return (newpage ? 0 : packetonpage + 1);
} }
uint uint
OggFrameInfo::GetNextPacket() const OggFrameInfo::GetNextPacket() const
{ {
return packet+1; return packet + 1;
} }
+5 -6
View File
@@ -1,27 +1,26 @@
#ifndef _OGG_FRAME_INFO_H #ifndef _OGG_FRAME_INFO_H
#define _OGG_FRAME_INFO_H #define _OGG_FRAME_INFO_H
#include <sys/types.h> #include <SupportDefs.h>
class OggFrameInfo { class OggFrameInfo {
public: public:
OggFrameInfo(uint page, uint packetonpage, uint packet); OggFrameInfo(uint page, uint packetonpage, uint packet);
virtual ~OggFrameInfo(); virtual ~OggFrameInfo();
void SetNext(uint page, uint packetonpage, uint packet); void SetNextIsNewPage(bool newpage = true);
uint GetPage() const; uint GetPage() const;
uint GetPacketOnPage() const; uint GetPacketOnPage() const;
uint GetPacket() const; uint GetPacket() const;
uint GetNextPage() const; uint GetNextPage() const;
uint GetNextPacketOnPage() const; uint GetNextPacketOnPage() const;
uint GetNextPacket() const; uint GetNextPacket() const;
private: private:
uint page; // the page the frame started on 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 packet; // the packet the frame started on
uint nextpage; // the next page after this page bool newpage;
uint nextpacketonpage; // of all the packets on next page which packet is the next
uint nextpacket; // the next packet after this packet
}; };
#endif _OGG_FRAME_INFO_H #endif _OGG_FRAME_INFO_H
@@ -33,6 +33,7 @@ OggReader::~OggReader()
delete j->second; delete j->second;
} }
ogg_sync_clear(&fSync); 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"); // TRACE("OggReader::GetPage\n");
retry: retry:
static off_t next_position = (fSeekable ? fSeekable->Position() : -1); off_t position = fNextPosition;
off_t position = next_position;
int result = ogg_sync_pageout(&fSync,page); // first read leftovers int result = ogg_sync_pageout(&fSync,page); // first read leftovers
while (result == 0) { while (result == 0) {
char * buffer = ogg_sync_buffer(&fSync,read_size); char * buffer = ogg_sync_buffer(&fSync,read_size);
@@ -82,7 +82,7 @@ retry:
return B_ERROR; return B_ERROR;
} }
#endif #endif
next_position += page->header_len + page->body_len; fNextPosition += (fSeekable ? page->header_len + page->body_len : 0);
long serialno = ogg_page_serialno(page); long serialno = ogg_page_serialno(page);
if (fStreams.find(serialno) == fStreams.end()) { if (fStreams.find(serialno) == fStreams.end()) {
// this is an unknown serialno // this is an unknown serialno
@@ -233,6 +233,8 @@ OggReader::Sniff(int32 *streamCount)
#endif #endif
fSeekable = get_seekable(Source()); fSeekable = get_seekable(Source());
fNextPosition = (fSeekable ? fSeekable->Position() : -1);
ogg_page page; ogg_page page;
if (GetPage(&page,4096,short_page) != B_OK) { if (GetPage(&page,4096,short_page) != B_OK) {
return B_ERROR; return B_ERROR;
@@ -51,6 +51,8 @@ protected:
BPositionIO * fSeekable; BPositionIO * fSeekable;
private: private:
off_t fNextPosition;
class GetPageInterface { class GetPageInterface {
public: public:
virtual status_t GetNextPage() = 0; virtual status_t GetNextPage() = 0;
+19 -9
View File
@@ -97,18 +97,20 @@ OggStream::GetSerial() const
status_t status_t
OggStream::AddPage(off_t position, ogg_page * page) OggStream::AddPage(off_t position, ogg_page * page)
{ {
TRACE("OggStream::AddPage %llu\n",position); TRACE("OggStream::AddPage");
if (position >= 0) { if (position >= 0) {
TRACE(" %lld", position);
fPagePositions.push_back(position); fPagePositions.push_back(position);
} }
TRACE("\n");
BAutolock autolock(fSyncLock); BAutolock autolock(fSyncLock);
char * buffer; char * buffer;
buffer = ogg_sync_buffer(&fSync,page->header_len); buffer = ogg_sync_buffer(&fSync, page->header_len);
memcpy(buffer,page->header,page->header_len); memcpy(buffer,page->header, page->header_len);
ogg_sync_wrote(&fSync,page->header_len); ogg_sync_wrote(&fSync, page->header_len);
buffer = ogg_sync_buffer(&fSync,page->body_len); buffer = ogg_sync_buffer(&fSync, page->body_len);
memcpy(buffer,page->body,page->body_len); memcpy(buffer,page->body, page->body_len);
ogg_sync_wrote(&fSync,page->body_len); ogg_sync_wrote(&fSync, page->body_len);
return B_OK; 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 // instead we just let it go out of scope
fCurrentPage = fOggFrameInfos[*frame].GetNextPage(); fCurrentPage = fOggFrameInfos[*frame].GetNextPage();
fPacketOnCurrentPage = fOggFrameInfos[*frame].GetNextPacketOnPage(); fPacketOnCurrentPage = fOggFrameInfos[*frame].GetNextPacketOnPage();
fCurrentPacket = fOggFrameInfos[*frame].GetNextPacket(); fCurrentPacket = fOggFrameInfos[*frame].GetPacket()+1;
} else if (seekTo & B_MEDIA_SEEK_TO_TIME) { } else if (seekTo & B_MEDIA_SEEK_TO_TIME) {
*frame = *time/50000; *frame = *time/50000;
return Seek(B_MEDIA_SEEK_TO_FRAME,frame,time); return Seek(B_MEDIA_SEEK_TO_FRAME,frame,time);
@@ -216,13 +218,15 @@ OggStream::GetNextChunk(void **chunkBuffer, int32 *chunkSize,
media_header *mediaHeader) media_header *mediaHeader)
{ {
static ogg_packet packet; static ogg_packet packet;
uint page = fEndPage;
if (fCurrentPacket - fHeaderPackets.size() == fOggFrameInfos.size()) { if (fCurrentPacket - fHeaderPackets.size() == fOggFrameInfos.size()) {
OggFrameInfo info(fEndPage,fPacketOnEndPage,fEndPacket); OggFrameInfo info(fEndPage,fPacketOnEndPage,fEndPacket);
fOggFrameInfos.push_back(info); fOggFrameInfos.push_back(info);
} }
status_t result = GetPacket(&packet); status_t result = GetPacket(&packet);
if (fCurrentPacket - fHeaderPackets.size() == fOggFrameInfos.size()) { if (fCurrentPacket - fHeaderPackets.size() == fOggFrameInfos.size()) {
fOggFrameInfos[fOggFrameInfos.size()-1].SetNext(fEndPage,fPacketOnEndPage,fEndPacket); if (page != fEndPage) {
}
} }
if (result != B_OK) { if (result != B_OK) {
TRACE("OggStream::GetNextChunk failed: GetPacket = %s\n", strerror(result)); TRACE("OggStream::GetNextChunk failed: GetPacket = %s\n", strerror(result));
@@ -268,6 +272,12 @@ OggStream::GetPacket(ogg_packet * packet)
} }
fEndPacket++; fEndPacket++;
if (pageno != fEndPage) { 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; fPacketOnEndPage = 0;
} else { } else {
fPacketOnEndPage++; fPacketOnEndPage++;