[xiph-commits] r7324 - trunk/oggdsf/src/lib/core/ogg/libOOOgg
illiminable at dactyl.lonelymoon.com
illiminable
Sun Jul 25 05:42:42 PDT 2004
Author: illiminable
Date: Sun Jul 25 05:42:42 2004
New Revision: 7324
Modified:
trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp
trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h
trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPage.cpp
trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPage.h
trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.cpp
trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggSegmentTable.cpp
Log:
* Changed the Ogg page class a bit
* Made changes to the demuxer.
Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp 2004-07-25 10:58:55 UTC (rev 7323)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp 2004-07-25 12:42:41 UTC (rev 7324)
@@ -130,42 +130,37 @@
}
OggDataBuffer::eFeedResult OggDataBuffer::feed(const char* inData, unsigned long inNumBytes) {
-
-
if (inNumBytes != 0) {
if (inData != NULL) {
//Buffer is not null and there is at least 1 byte of data.
+
debugLog<<"********** Fed "<<inNumBytes<<" bytes..."<<endl;
+ ///STREAM ACCESS::: WRite
+ //Write the data into the stream buffer
mStream.write(inData, inNumBytes);
+
+ if(mStream.fail()) {
+ debugLog<<"ProcessBaseHeader : Buffer write Write FAILED"<<endl;
+ return FEED_BUFFER_WRITE_ERROR;
+ }
- //DEBUGGING_FIX:::
- //FIX ::: Need error checking.
- bool retVal = processBuffer();
- debugLog<<"########## End feed - After process buffer"<<endl;
- if (retVal == true) {
- return FEED_OK;
- } else {
- ret:::::::
- }
- return retVal;
+ return (eFeedResult)processBuffer();
+
} else {
//Numbytes not equal to zero but inData point is NULL
+ debugLog<<"Feed : Fed NULL Pointer"<<endl;
return FEED_NULL_POINTER;
}
} else {
//numbytes was zero... we do nothing and it's not an error.
+ debugLog<<"Feed : Fed *zero* bytes... Not an error, do nothing, return ok."<<endl;
return FEED_OK;
}
- } else {
- debugLog<<"Fed *zero* bytes or inData was NULL..."<<endl;
- return true;
- }
-
-
+
}
-void OggDataBuffer::processBaseHeader() {
+OggDataBuffer::eProcessResult OggDataBuffer::processBaseHeader() {
debugLog<<"ProcessBaseHeader : "<<endl;
//Delete the previous page
@@ -204,13 +199,16 @@
debugLog<<"ProcessBaseHeader : Bytes needed for seg table = "<<mNumBytesNeeded<<endl;
}
-void OggDataBuffer::processSegTable() {
+OggDataBuffer::eProcessResult OggDataBuffer::processSegTable() {
+ //Assumes a valid pending page, with numPagesegments set in the header already.
+ //creates a chunk of memory size numpagesegments and stores it,.
+
debugLog<<"ProcessSegTable : "<<endl;
//TODAY::: What happens when numpage segments is zero.
- //Save a local copy of the number of page segments.
+ //Save a local copy of the number of page segments - Get this from the already set header.
unsigned char locNumSegs = pendingPage->header()->NumPageSegments();
debugLog<<"ProcessSegTable : Num segs = "<<(int)locNumSegs<<endl;
@@ -224,25 +222,32 @@
mStream.read((char*)locBuff, (size_t)locNumSegs);
if(mStream.fail()) {
debugLog<<"ProcessSegTable : Read FAILED"<<endl;
+ delete locBuff;
+ return false;
}
//TODAY::: Check out the page header class.
- //TODAY::: Needs a return value.
- //Set the data into the pending pages segtable
- pendingPage->header()->setSegmentTable(locBuff);
+ //Make a new segment table from the bufferd data.
+ OggSegmentTable* locSegTable = new OggSegmentTable();
+ unsigned long locDataSize = locSegTable->setSegmentTable(locBuff, locNumSegs);
+
+ //Set the data into the pending pages segtable... giving the pointer away, don't use any more.
//NOTE ::: The seg table will delete the buffer itself. Don't delete here.
+ pendingPage->header()->setSegmentTable(locSegTable);
+ locSegTable = NULL;
+ //Set the number of bytes we want for next time - which is the size of the page data.
+ mNumBytesNeeded = locDataSize;
+ debugLog<<"ProcessSegTable : Num bytes needed for data = "<< mNumBytesNeeded<<endl;
+
debugLog<<"ProcessSegTable : Transition to AWAITING_DATA"<<endl;
mState = AWAITING_DATA;
+ return true;
-
- //Set the number of bytes we want for next time
- mNumBytesNeeded = pendingPage->header()->dataSize();
- debugLog<<"ProcessSegTable : Num bytes needed for data = "<< mNumBytesNeeded<<endl;
}
-bool OggDataBuffer::processDataSegment() {
+OggDataBuffer::eProcessResult OggDataBuffer::processDataSegment() {
debugLog<<"ProcessDataSegment : "<<endl;
//Make a local buffer
@@ -253,39 +258,73 @@
unsigned char* locBuff = NULL;// = new unsigned char[locPageDataSize];
//unsigned long locPacketOffset = 0;
+ //THis is a raw pointer into the segment table, don't delete it.
unsigned char* locSegTable = pendingPage->header()->SegmentTable()->segmentTable();
unsigned int locNumSegs = pendingPage->header()->SegmentTable()->numSegments();
debugLog<<"ProcessDataSegment : Num segs = "<<locNumSegs<<endl;
+
+
unsigned long locCurrPackSize = 0;
- bool locIsLastSeg = false;
//Read from the stream buffer to it
for (unsigned long i = 0; i < locNumSegs; i++) {
+ //Packet sums the lacing values of the segment table.
locCurrPackSize += locSegTable[i];
- locIsLastSeg = (locNumSegs - 1 == i);
- if ( (locSegTable[i] != 255) || locIsLastSeg ) {
+ //If its the last segment in the page or if the lacing value is not 255(ie packet boundary.
+
+ /*TRUTH TABLE:
+ last lacing value lacing value is *not* 255
+ ================= =========================
+ true true } If its the last one or a packet boundary(255 lacing value) we add it.
+ true false }
+ false true }
+ false false If it is a 255 (packet continues) and it's not the last one do nothibng
+ it is the last lacing value on the page
+
+
+ Lacing values for a Packet never end with 255... if multiple of 255 have a next 0 lacing value.
+ */
+ if ( (locSegTable[i] != 255) || (locNumSegs - 1 == i) ) {
+ //If its the last lacing value or the the lacing value is not 255 (ie packet boundry)
+
//This pointer is given to the packet... it deletes it.
locBuff = new unsigned char[locCurrPackSize];
+
+ //STREAM ACCESS:::
+ //Read data from the stream into the local buffer.
mStream.read((char*)(locBuff), locCurrPackSize);
+
debugLog<<"ProcessDataSegment : Adding packet size = "<<locCurrPackSize<<endl;
+
+ //A packet ends when a lacing value is not 255. So the check for != 255 means the isComplete property of the packet is not set unless the
+ // lacing value is not equal to 255.
pendingPage->addPacket( new StampedOggPacket(locBuff, locCurrPackSize, (locSegTable[i] != 255), 0, pendingPage->header()->GranulePos()->value(), StampedOggPacket::OGG_END_ONLY ) );
- //locPacketOffset += locCurrPackSize;
+ //Reset the packet size counter.
locCurrPackSize = 0;
}
}
- debugLog<<"ProcessDataSegment : Transition to AWAITING_BASE_HEADER"<<endl;
- mState = AWAITING_BASE_HEADER;
-
+
+ //Update the state for how many bytes are now needed
mNumBytesNeeded = OggPageHeader::OGG_BASE_HEADER_SIZE;
+
debugLog<<"ProcessDataSegment : num bytes needed = "<<mNumBytesNeeded<<endl;
- return dispatch(pendingPage);
-
+
+ bool locRet = dispatch(pendingPage);
+ if (locRet == true) {
+ debugLog<<"ProcessDataSegment : Transition to AWAITING_BASE_HEADER"<<endl;
+ mState = AWAITING_BASE_HEADER;
+ return true;
+ } else {
+ debugLog<<"ProcessDataSegment : Dispatch failed."<<endl;
+ return false;
+ }
+
}
void OggDataBuffer::clearData() {
mStream.clear();
@@ -302,9 +341,11 @@
mNumBytesNeeded = OggPageHeader::OGG_BASE_HEADER_SIZE;
debugLog<<"ClearData : Num bytes needed = "<<mNumBytesNeeded<<endl;
}
-bool OggDataBuffer::processBuffer() {
+OggDataBuffer::eProcessResult OggDataBuffer::processBuffer() {
debugLog<<"ProcessBuffer :"<<endl;
bool locErr;
+ eProcessResult locProcessResult = PROCESS_OK;
+
while (numBytesAvail() >= mNumBytesNeeded) {
debugLog<<"ProcessBuffer : Bytes Needed = "<<mNumBytesNeeded<<" --- "<<"Bytes avail = "<<numBytesAvail()<<endl;
switch (mState) {
@@ -314,7 +355,8 @@
//If theres enough data to form the base header
if (numBytesAvail() >= OggPageHeader::OGG_BASE_HEADER_SIZE) {
debugLog<<"ProcessBuffer : Enough to process..."<<endl;
- processBaseHeader();
+ return processBaseHeader();
+ }
}
break;
@@ -323,7 +365,7 @@
//If there is enough data to get the segt table
if (numBytesAvail() >= pendingPage->header()->NumPageSegments()) {
debugLog<<"ProcessBuffer : Enough to process..."<<endl;
- processSegTable();
+ return processSegTable();
}
break;
@@ -332,19 +374,17 @@
//If all the data segment is available
if (numBytesAvail() >= pendingPage->header()->dataSize()) {
debugLog<<"ProcessBuffer : Enough to process..."<<endl;
- locErr = processDataSegment();
- if (!locErr) {
- return false;
- }
+ return processDataSegment();
}
break;
default:
//Do sometyhing ??
debugLog<<"ProcessBuffer : Ogg Buffer Error"<<endl;
+ return PROCESS_UNKNOWN_INTERNAL_ERROR;
break;
}
}
- return true;
+ return PROCESS_OK;
}
Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h 2004-07-25 10:58:55 UTC (rev 7323)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h 2004-07-25 12:42:41 UTC (rev 7324)
@@ -59,12 +59,17 @@
enum eFeedResult {
FEED_OK,
FEED_NULL_POINTER = 64,
+ FEED_BUFFER_WRITE_ERROR
+
};
enum eProcessResult {
PROCESS_OK,
+ PROCESS_UNKNOWN_INTERNAL_ERROR = 256,
+ PROCESS_FILE_READ_ERROR
+
};
OggDataBuffer(void);
//Debug only
@@ -78,7 +83,7 @@
void clearData();
- bool feed(const char* inData, unsigned long inNumBytes);
+ OggDataBuffer::eFeedResult feed(const char* inData, unsigned long inNumBytes);
//FIX ::: Add later
//void unRegisterSerialNo(unsigned long inSerialNo);
@@ -95,7 +100,7 @@
stringstream mStream;
eState mState;
- bool processBuffer();
+ eProcessResult processBuffer();
virtual bool dispatch(OggPage* inOggPage);
unsigned long mNumBytesNeeded;
Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPage.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPage.cpp 2004-07-25 10:58:55 UTC (rev 7323)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPage.cpp 2004-07-25 12:42:41 UTC (rev 7324)
@@ -33,7 +33,6 @@
#include "oggpage.h"
OggPage::OggPage(void)
- : mPageData(NULL)
{
mHeader = new OggPageHeader;
@@ -68,7 +67,7 @@
OggPage* OggPage::clone() {
OggPage* retClone = new OggPage;
retClone->mHeader = mHeader->clone();
- for (int i = 0; i < mPacketList.size(); i++) {
+ for (size_t i = 0; i < mPacketList.size(); i++) {
retClone->mPacketList.push_back(mPacketList[i]);
}
@@ -106,7 +105,7 @@
mHeader->rawData(locPage, mHeader->pageSize());
unsigned long locOffset = mHeader->headerSize();
- for (int i = 0; i < mPacketList.size(); i++) {
+ for (size_t i = 0; i < mPacketList.size(); i++) {
OggPacket* locPack = mPacketList[i];
memcpy((void*)(locPage + locOffset), (const void*)(locPack->packetData()), locPack->packetSize());
locOffset += locPack->packetSize();
@@ -124,11 +123,7 @@
}
-void OggPage::setPageData(unsigned char* inPtr)
-{
- mHeader->setPageState(OggPageHeader::COMPLETE);
- mPageData = inPtr;
-}
+
unsigned long OggPage::pageSize()
{
return mHeader->pageSize();
@@ -142,96 +137,93 @@
return mHeader->dataSize();
}
-unsigned char* OggPage::PageData()
-{
- return mPageData;
-}
-string OggPage::toString()
-{
-
- return NULL;
-}
-void OggPage::screenDump()
-{
- //Dump the header
- cout<< mHeader->toString();
- //Dump the data
- dataDumpAsHex();
-}
+//string OggPage::toString()
+//{
+//
+// return NULL;
+//}
-void OggPage::dumpNChars(unsigned char* inStartPoint, unsigned long inNumChars) {
+//void OggPage::screenDump()
+//{
+// //Dump the header
+// cout<< mHeader->toString();
+// //Dump the data
+// dataDumpAsHex();
+//}
+//
+//void OggPage::dumpNChars(unsigned char* inStartPoint, unsigned long inNumChars) {
+//
+// //NOTE::: Also needs reworking
+// const unsigned char BELL = 7;
+// //Set the fill character back to space ' '
+// cout << setfill(' ');
+//
+// //Put some space after the hex section
+// unsigned long locPadding = 3 * (HEX_DUMP_LINE_LENGTH - inNumChars) + 4;
+// cout << setw(locPadding) << " ";
+//
+// //Loop through the characters
+// for (unsigned long i = 0; i < inNumChars; i++) {
+//
+// //If they are *not* going to mess up the layout (\r, \n or \t or bell(7))
+// if ( (inStartPoint[i] != '\n') && (inStartPoint[i] != '\r') && (inStartPoint[i] != '\t') && (inStartPoint[i] != BELL )) {
+// //Write them out
+// cout << inStartPoint[i];
+// } else {
+// //Otherwise just write a null char
+// cout << (char) 0;
+// }
+// }
+// //End the line and put the fill character back to a number 0
+// cout << endl << setfill('0');
+//
+//}
+//
+//
+//
+//void OggPage::dataDumpAsHex() {
+// ///NOTE::: ShOuld be reworked.
+// //Needs dataSize and data pointer
+//
+// //Put the stream in hex mode with a fill character of 0
+// hex(cout);
+// cout << setfill('0');
+//
+// //Loop through every character of data
+// for (unsigned long i = 0; i < mHeader->dataSize(); i++) {
+// //If it is the end of the previous hex dump line or first line)
+// if ( (i % HEX_DUMP_LINE_LENGTH == 0) ) {
+// //And this is not the first line
+// if ( i != 0 ) {
+// //Write the actual characters out at the end of the line
+// dumpNChars( &mPageData[i - HEX_DUMP_LINE_LENGTH], HEX_DUMP_LINE_LENGTH);
+// }
+//
+// //At the start of the line write out the base address in an 8 hex-digit field
+// cout << setw(8) << i << ": ";
+// }
+//
+// //Write out the value of the character in a 2 hex-digit field
+// cout << setw(2) << (int)mPageData[i] << " ";
+// }
+//
+// //Find out how many leftover charcters didn't get written out.
+// unsigned long locLeftovers = (mHeader->dataSize() % HEX_DUMP_LINE_LENGTH);
+// locLeftovers = (locLeftovers > 0) ? (locLeftovers)
+// : (HEX_DUMP_LINE_LENGTH);
+//
+//
+// //If there was any data in this dump
+// if ( mHeader->dataSize() > 0 ) {
+// //Dump the last part out
+// dumpNChars( &mPageData[mHeader->dataSize() - locLeftovers], locLeftovers );
+// }
+//
+// cout << "==============================================================================" << endl;
+// //Put the stream back to decimal mode
+// dec(cout);
+//}
- //NOTE::: Also needs reworking
- const unsigned char BELL = 7;
- //Set the fill character back to space ' '
- cout << setfill(' ');
-
- //Put some space after the hex section
- unsigned long locPadding = 3 * (HEX_DUMP_LINE_LENGTH - inNumChars) + 4;
- cout << setw(locPadding) << " ";
-
- //Loop through the characters
- for (unsigned long i = 0; i < inNumChars; i++) {
-
- //If they are *not* going to mess up the layout (\r, \n or \t or bell(7))
- if ( (inStartPoint[i] != '\n') && (inStartPoint[i] != '\r') && (inStartPoint[i] != '\t') && (inStartPoint[i] != BELL )) {
- //Write them out
- cout << inStartPoint[i];
- } else {
- //Otherwise just write a null char
- cout << (char) 0;
- }
- }
- //End the line and put the fill character back to a number 0
- cout << endl << setfill('0');
-
-}
-
-
-
-void OggPage::dataDumpAsHex() {
- ///NOTE::: ShOuld be reworked.
- //Needs dataSize and data pointer
-
- //Put the stream in hex mode with a fill character of 0
- hex(cout);
- cout << setfill('0');
-
- //Loop through every character of data
- for (unsigned long i = 0; i < mHeader->dataSize(); i++) {
- //If it is the end of the previous hex dump line or first line)
- if ( (i % HEX_DUMP_LINE_LENGTH == 0) ) {
- //And this is not the first line
- if ( i != 0 ) {
- //Write the actual characters out at the end of the line
- dumpNChars( &mPageData[i - HEX_DUMP_LINE_LENGTH], HEX_DUMP_LINE_LENGTH);
- }
-
- //At the start of the line write out the base address in an 8 hex-digit field
- cout << setw(8) << i << ": ";
- }
-
- //Write out the value of the character in a 2 hex-digit field
- cout << setw(2) << (int)mPageData[i] << " ";
- }
-
- //Find out how many leftover charcters didn't get written out.
- unsigned long locLeftovers = (mHeader->dataSize() % HEX_DUMP_LINE_LENGTH);
- locLeftovers = (locLeftovers > 0) ? (locLeftovers)
- : (HEX_DUMP_LINE_LENGTH);
-
-
- //If there was any data in this dump
- if ( mHeader->dataSize() > 0 ) {
- //Dump the last part out
- dumpNChars( &mPageData[mHeader->dataSize() - locLeftovers], locLeftovers );
- }
-
- cout << "==============================================================================" << endl;
- //Put the stream back to decimal mode
- dec(cout);
-}
-
Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPage.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPage.h 2004-07-25 10:58:55 UTC (rev 7323)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPage.h 2004-07-25 12:42:41 UTC (rev 7324)
@@ -30,8 +30,10 @@
//===========================================================================
#pragma once
+
#include <vector>
using namespace std;
+
#include "StampedOggPacket.h"
#include "OggPageHeader.h"
#include "IOggPackSource.h"
@@ -44,60 +46,44 @@
public:
OggPage(void);
~OggPage(void);
-
+ OggPage* clone();
static const unsigned long HEX_DUMP_LINE_LENGTH = 16;
+ //Size functions
unsigned long pageSize();
unsigned long headerSize();
unsigned long dataSize();
- //IOggPackSource
+ //IOggPackSource Implementation
OggPacket* getPacket(unsigned long inPacketNo);
+ unsigned long numPackets();
+ //
+ //Packet access
StampedOggPacket* getStampedPacket(unsigned long inPacketNo);
bool addPacket(StampedOggPacket* inPacket);
- unsigned long numPackets();
- OggPage* clone();
-
- unsigned char* createRawPageData();
- //Basic output stuff
- string toString();
-
+ //Header access
OggPageHeader* header();
-
- void screenDump();
- void dataDumpAsHex();
+ //
+ //Serialise
+ unsigned char* createRawPageData();
- //bool setPageDataCopy(unsigned char* inData);
-
-
- //Get rid of this.
- unsigned char* PageData();
-
- //MUTATORS
-
- void setPageData(unsigned char* inPtr);
protected:
-
+ //Member data of packets and header.
vector<StampedOggPacket*> mPacketList;
-
- //string mCapturePattern; //Const = "OggS" 4 bytes
-
-
OggPageHeader* mHeader;
- //This is obsolete... can it !
- unsigned char* mPageData;
+
+
+ ////Basic output stuff
+ //// Some of this should get out of here.
+ //string toString();
+ //void screenDump();
+ //void dataDumpAsHex();
+ //void dumpNChars(unsigned char* inStartPoint, unsigned long inNumChars);
-
-
- void dumpNChars(unsigned char* inStartPoint, unsigned long inNumChars);
-
-public:
-
-
};
Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.cpp 2004-07-25 10:58:55 UTC (rev 7323)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.cpp 2004-07-25 12:42:41 UTC (rev 7324)
@@ -274,16 +274,18 @@
}
bool OggPageHeader::setSegmentTable(unsigned char* inSegTable) {
+
+ //This assumes that mNumPageSegments is set.
//ISSUE ::: What happens when numPageSegments is zero ?
if ( /*(mPageState == BASE_HEAD_SET) && */ (mSegmentTable == NULL)) {
//Make a new segtable object
OggSegmentTable* locSegTable = new OggSegmentTable;
//Put the data in it and set the pagedata size
- //NOTE ::: Nested Side effects
- setDataSize( locSegTable->setSegmentTable(inSegTable, mNumPageSegments) );
+ unsigned long locDataSize = locSegTable->setSegmentTable(inSegTable, mNumPageSegments);
+ setDataSize( locDataSize );
- //Assign the segtable into the page
+ //Assign the segtable into the page, the page header will look after deleing the memory.
setSegmentTable(locSegTable);
mPageState = FULL_HEAD_SET;
return true;
@@ -349,6 +351,7 @@
}
void OggPageHeader::setSegmentTable(OggSegmentTable* inPtr)
{
+ //Keeps your pointer !
mSegmentTable = inPtr;
}
Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggSegmentTable.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggSegmentTable.cpp 2004-07-25 10:58:55 UTC (rev 7323)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggSegmentTable.cpp 2004-07-25 12:42:41 UTC (rev 7324)
@@ -78,6 +78,7 @@
}
unsigned long OggSegmentTable::setSegmentTable(const unsigned char* inSegTable, unsigned char inNumSegments)
{
+ //Copies the buffer.
if (inNumSegments != 0) {
if (inSegTable == NULL) {
//do nothing if pointer was null and numsegments is not 0.
More information about the commits
mailing list