[xiph-commits] r7476 - in trunk/oggdsf/src/lib/core:

illiminable at motherfish-iii.xiph.org illiminable
Thu Aug 5 19:10:36 PDT 2004


directshow/dsfAnxDemux directshow/dsfOggDemux ogg/libOOOgg
Message-ID: <E1BsuBo-0001tX-8B at motherfish-III>

Author: illiminable
Date: Thu Aug  5 19:10:36 2004
New Revision: 7476

Modified:
trunk/oggdsf/src/lib/core/directshow/dsfAnxDemux/AnxStreamMapper.cpp
trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggDemuxSourceFilter.cpp
trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggDemuxSourcePin.h
trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStream.cpp
trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStream.h
trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStreamFactory.cpp
trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStreamMapper.cpp
trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStreamMapper.h
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/OggPacketiser.cpp
trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPacketiser.h
Log:
* New packetising code, now working in all codec except flac, due to the way the number of header packets are counted.
* Seeking has gone back to being slightly delayed... i suspect some wrongly set gran pos after the seek.

Modified: trunk/oggdsf/src/lib/core/directshow/dsfAnxDemux/AnxStreamMapper.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfAnxDemux/AnxStreamMapper.cpp	2004-08-04 06:17:46 UTC (rev 7475)
+++ trunk/oggdsf/src/lib/core/directshow/dsfAnxDemux/AnxStreamMapper.cpp	2004-08-04 09:05:56 UTC (rev 7476)
@@ -61,7 +61,7 @@
}
bool AnxStreamMapper::acceptOggPage(OggPage* inOggPage)
{
-
+	//ANXTOFIX::: This was changed in the ogg demux.
if(!isReady()) {
mDataStartsAt += inOggPage->pageSize();
}

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggDemuxSourceFilter.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggDemuxSourceFilter.cpp	2004-08-04 06:17:46 UTC (rev 7475)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggDemuxSourceFilter.cpp	2004-08-04 09:05:56 UTC (rev 7476)
@@ -469,9 +469,12 @@
//Before opening make the interface
mDataSource = DataSourceFactory::createDataSource(StringHelper::toNarrowStr(mFileName).c_str());
mDataSource->open(StringHelper::toNarrowStr(mFileName).c_str());
-		mDataSource->seek(mStreamMapper->startOfData());
-		mJustReset = true;
-		//
+		mDataSource->seek(mStreamMapper->startOfData());   //Should always be zero for now.
+
+		//TODO::: Should be doing stuff with the demux state here ? or packetiser ?>?
+
+		mJustReset = true;   //TODO::: Look into this !
+
}
for (unsigned long i = 0; i < mStreamMapper->numStreams(); i++) {
mStreamMapper->getOggStream(i)->setSendExcess(true);
@@ -633,6 +636,11 @@
}

}
+
+	mStreamMapper->setAllowDispatch(true);
+	mStreamMapper->toStartOfData();			//Flushes all streams and sets them to ignore the right number of headers.
+	mOggBuffer.clearData();
+	mDataSource->seek(0);			//TODO::: This is bad for streams.
//Memory leak
//FIXED
delete locBuff;

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggDemuxSourcePin.h
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggDemuxSourcePin.h	2004-08-04 06:17:46 UTC (rev 7475)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggDemuxSourcePin.h	2004-08-04 09:05:56 UTC (rev 7476)
@@ -60,8 +60,8 @@


virtual ~OggDemuxSourcePin(void);
-	static const unsigned long BUFFER_SIZE = 80000;			//What should this be ????
-	static const unsigned long NUM_BUFFERS = 10;
+	static const unsigned long BUFFER_SIZE = 65536;			//What should this be ????
+	static const unsigned long NUM_BUFFERS = 100;


virtual bool deliverOggPacket(StampedOggPacket* inOggPacket);

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStream.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStream.cpp	2004-08-04 06:17:46 UTC (rev 7475)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStream.cpp	2004-08-04 09:05:56 UTC (rev 7476)
@@ -45,6 +45,7 @@
,	mLastEndGranulePos(0)
,	mLastStartGranulePos(0)
,	mStreamLock(NULL)
+	,	mAllowDispatch(false)
{
//osDebug.open("C:\\ostream.log", ios_base::out);
//Need to do something here !
@@ -77,7 +78,9 @@
unsigned long OggStream::serialNo() {
return mSerialNo;
}
-
+void OggStream::setAllowDispatch(bool inAllowDispatch) {
+	mAllowDispatch = inAllowDispatch;
+}
bool OggStream::acceptStampedOggPacket(StampedOggPacket* inPacket) {
if (!mStreamReady) {
//Streams not ready, still headers.
@@ -92,14 +95,19 @@
}
} else {
//Data packets...
-		if (mFirstRun) {
-			mFirstRun = false;
+		if (mAllowDispatch) {
+			if (mFirstRun) {
+				mFirstRun = false;

-			//Deliver the header data
-			deliverCodecHeaders();
-		}
-
-		processDataPacket(inPacket);
+				//Deliver the header data
+				deliverCodecHeaders();
+			}
+
+			processDataPacket(inPacket);
+		} else {
+			//processExcessPacket(inPacket);
+			return false;
+		}
}

return true;
@@ -221,6 +229,10 @@
return new CMediaType(locAMMediaType);
}

+unsigned long OggStream::numCodecHeaders() {
+	//TODO::: Check for null.
+	return mCodecHeaders->numPackets();
+}
void OggStream::flush() {
CAutoLock locLock(mStreamLock);
//delete mPartialPacket;
@@ -228,6 +240,15 @@
//mPartialPacket = NULL;
mPacketiser.reset();
}
+
+void OggStream::flush(unsigned short inNumPacketsToIgnore) {
+	CAutoLock locLock(mStreamLock);
+	//delete mPartialPacket;
+	//TODO::: Tell the packetiser to flush.
+	//mPartialPacket = NULL;
+	mPacketiser.reset();
+	mPacketiser.setNumIgnorePackets(inNumPacketsToIgnore);
+}
//ANX::: Need to override here to create anx pins
bool OggStream::AddPin() {
createFormatBlock();

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStream.h
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStream.h	2004-08-04 06:17:46 UTC (rev 7475)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStream.h	2004-08-04 09:05:56 UTC (rev 7476)
@@ -83,8 +83,12 @@
virtual OggDemuxSourcePin* getPin();
virtual bool OggStream::AddPin();

+	void setAllowDispatch(bool inAllowDispatch);
bool streamReady();
+	unsigned long numCodecHeaders();
+
void flush();
+	void flush(unsigned short inNumPacketsToIgnore);
protected:
virtual bool acceptStampedOggPacket(StampedOggPacket* inPacket);

@@ -103,6 +107,7 @@
bool mFirstRun;
bool mSendExcess;
bool mAllowSeek;
+	bool mAllowDispatch;

__int64 mLastEndGranulePos;
__int64 mLastStartGranulePos;

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStreamFactory.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStreamFactory.cpp	2004-08-04 06:17:46 UTC (rev 7475)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStreamFactory.cpp	2004-08-04 09:05:56 UTC (rev 7476)
@@ -54,6 +54,7 @@
return new TheoraStream(inOggPage, inOwningFilter, inAllowSeek);
case StreamHeaders::FFDSHOW_VIDEO:
return new FFDShowVideoStream(inOggPage, inOwningFilter, inAllowSeek);
+
case StreamHeaders::NONE:
default:
return NULL;

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStreamMapper.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStreamMapper.cpp	2004-08-04 06:17:46 UTC (rev 7475)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStreamMapper.cpp	2004-08-04 09:05:56 UTC (rev 7476)
@@ -45,6 +45,8 @@
delete mStreamList[i];
}
}
+
+//Sends the page to *only one* stream if it matches the serial number.
bool OggStreamMapper::dispatchPage(OggPage* inOggPage)
{
for (unsigned long i = 0; i < mStreamList.size(); i++) {
@@ -65,11 +67,12 @@
bool OggStreamMapper::acceptOggPage(OggPage* inOggPage)
{

-	if(!isReady()) {
-		mDataStartsAt += inOggPage->pageSize();
-	}
+	//FIXED::: Data starts a 0.
+	//if(!isReady()) {
+	//	mDataStartsAt += inOggPage->pageSize();
+	//}

-	if (inOggPage->header()->isBOS()) {
+	if (!isReady() && inOggPage->header()->isBOS()) {
bool locAllowSeekThrough = false;

//We only want one of the pins to delegate their seek to us.
@@ -89,7 +92,23 @@
return dispatchPage(inOggPage);
}
}
+bool OggStreamMapper::toStartOfData() {
+	if (isReady()) {  //CHECK::: Should check for allow dsipatch ???
+		for (unsigned long i = 0; i < mStreamList.size(); i++) {
+			//Flush each stream, then ignore the codec headers.
+			mStreamList[i]->flush(mStreamList[i]->numCodecHeaders());
+		}
+		return true;
+	} else {
+		return false;
+	}
+}

+void OggStreamMapper::setAllowDispatch(bool inAllowDispatch) {
+	for (unsigned long i = 0; i < mStreamList.size(); i++) {
+		mStreamList[i]->setAllowDispatch(inAllowDispatch);;
+	}
+}
bool OggStreamMapper::isReady() {
bool retVal = true;
bool locWasAny = false;

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStreamMapper.h
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStreamMapper.h	2004-08-04 06:17:46 UTC (rev 7475)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/OggStreamMapper.h	2004-08-04 09:05:56 UTC (rev 7476)
@@ -51,12 +51,13 @@
unsigned long numStreams();
unsigned long startOfData();

-	bool dispatchPage(OggPage* inOggPage);
+	bool dispatchPage(OggPage* inOggPage);				//Should this be private or protected ?
//IOggCalback INterface
virtual bool acceptOggPage(OggPage* inOggPage);

virtual bool isReady();
-
+	virtual void setAllowDispatch(bool inAllowDispatch);
+	bool toStartOfData();

protected:
unsigned long mDataStartsAt;

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp	2004-08-04 06:17:46 UTC (rev 7475)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp	2004-08-04 09:05:56 UTC (rev 7476)
@@ -166,7 +166,7 @@
//Delete the previous page
delete pendingPage;

-		//make a fresh one
+		//Make a fresh ogg page
pendingPage = new OggPage;

//Make a local buffer for the header
@@ -276,7 +276,7 @@

//If its the last segment  in the page or if the lacing value is not 255(ie packet boundary.

-		/*TRUTH TABLE:
+		/* 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.
@@ -344,6 +344,8 @@
//debugLog<<"ProcessDataSegment : Transition to AWAITING_BASE_HEADER"<<endl;
mState = AWAITING_BASE_HEADER;
return PROCESS_OK;
+	} else if (locRet == DISPATCH_FALSE) {
+		return PROCESS_DISPATCH_FALSE;
} else {
//debugLog<<"ProcessDataSegment : Dispatch failed."<<endl;
return PROCESS_DISPATCH_FAILED;

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h	2004-08-04 06:17:46 UTC (rev 7475)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h	2004-08-04 09:05:56 UTC (rev 7476)
@@ -69,6 +69,7 @@
PROCESS_OK,
PROCESS_UNKNOWN_INTERNAL_ERROR = 512,
PROCESS_STREAM_READ_ERROR,
+		PROCESS_DISPATCH_FALSE,
PROCESS_DISPATCH_FAILED,
PROCESS_FAILED_TO_SET_HEADER,
PROCESS_LOST_SYNC = 4096

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPacketiser.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPacketiser.cpp	2004-08-04 06:17:46 UTC (rev 7475)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPacketiser.cpp	2004-08-04 09:05:56 UTC (rev 7476)
@@ -4,7 +4,11 @@
OggPacketiser::OggPacketiser(void)
:	mPacketSink(NULL)
,	mPendingPacket(NULL)
-	,	mPacketiserState(PKRSTATE_OK)
+	,	mPacketiserState(PKRSTATE_OK)
+	,	mLooseMode(true)						//FIX::: This affects the validator.
+	,	mNumIgnorePackets(0)
+	,	mPrevGranPos(0)
+	,	mCurrentGranPos(0)
{

}
@@ -12,6 +16,10 @@
:	mPacketSink(inPacketSink)
,	mPendingPacket(NULL)
,	mPacketiserState(PKRSTATE_OK)
+	,	mLooseMode(true)						//FIX::: This affects the validator.
+	,	mNumIgnorePackets(0)
+	,	mPrevGranPos(0)
+	,	mCurrentGranPos(0)
{

}
@@ -30,7 +38,10 @@
bool OggPacketiser::reset() {
delete mPendingPacket;
mPendingPacket = NULL;
+	mNumIgnorePackets = 0;
mPacketiserState = PKRSTATE_OK;
+	mPrevGranPos = 0;
+	mCurrentGranPos = 0;
return true;
}
bool OggPacketiser::acceptOggPage(OggPage* inOggPage) {
@@ -41,6 +52,17 @@
// to avoid reusing them.
//

+	//If the page isn't a -1 page and it's got a different granpos save it.
+	if ( (inOggPage->header()->GranulePos() != -1) && (inOggPage->header()->GranulePos() != mCurrentGranPos)) {
+		mPrevGranPos = mCurrentGranPos;
+
+		//If the previous is higher than the
+		if (mPrevGranPos > mCurrentGranPos) {
+			mPrevGranPos = -1;
+		}
+		mCurrentGranPos = inOggPage->header()->GranulePos();
+	}
+
//If the page header says its a continuation page...
if ((inOggPage->header()->HeaderFlags() & 1) == 1) {
///... and there is at least 1 packet...
@@ -79,7 +101,9 @@
//TODO::: Static alternative here ?

//Deliver the packet to the packet sink...
-						mPacketSink->acceptStampedOggPacket(mPendingPacket);
+						if (dispatchStampedOggPacket(mPendingPacket) == false) {
+							return false;
+						}

//Go back to OK state
mPacketiserState = PKRSTATE_OK;
@@ -94,9 +118,22 @@
throw 0;
}
} else {
-				//Unexpected continuation
-				mPacketiserState = PKRSTATE_INVALID_STREAM;
-				throw 0;
+				if (mLooseMode == true) {
+					//Just ignore when we get continuation pages, just drop the broken bit of packet.
+
+					mPendingPacket = NULL;   //MEMCHECK::: Did i just leak memory ?
+					mPacketiserState = PKRSTATE_OK;
+
+					//TODO::: Should really return false here if this returns false.
+					if( processPage(inOggPage, false, false) == false) {
+						//TODO::: State change ???
+						return false;
+					}
+				} else {
+					//Unexpected continuation
+					mPacketiserState = PKRSTATE_INVALID_STREAM;
+					throw 0;
+				}
}
} else {
//Is this something ?
@@ -107,9 +144,15 @@
} else {
//Normal page, no continuations... just dump the packets, except the last one
if (inOggPage->numPackets() == 1) {
-			processPage(inOggPage, true, true);			//If there was only one pack process it.
+			if (processPage(inOggPage, true, true) == false ) {			//If there was only one pack process it.
+				//TODO::: State change
+				return false;
+			}
} else {
-			processPage(inOggPage, true, false);			//If there was only one packet, no packets would be written
+			if (processPage(inOggPage, true, false) == false ) {			//If there was only one packet, no packets would be written
+				//TODO::: State change
+				return false;
+			}
}

//The first packet is delivered.
@@ -141,7 +184,10 @@
//We are in the OK state, with no pending packets, and the last packet is not truncated.

//Deliver to the packet sink.
-				mPacketSink->acceptStampedOggPacket( (StampedOggPacket*)(inOggPage->getStampedPacket(inOggPage->numPackets() - 1)->clone()) );
+				if ( dispatchStampedOggPacket( (StampedOggPacket*)(inOggPage->getStampedPacket(inOggPage->numPackets() - 1)->clone()) ) == false ) {
+					//TODO::: State change ?
+					return false;
+				}
//The last packet is complete. So send it.
}
} else if (mPacketiserState == PKRSTATE_AWAITING_CONTINUATION) {
@@ -171,6 +217,7 @@
}

bool OggPacketiser::processPage(OggPage* inOggPage, bool inIncludeFirst, bool inIncludeLast) {
+	//Returns false only if one of the acceptStampedOggPacket calls return false... means we should stop sending stuff and return.
bool locIsOK = true;

//Adjusts the loop parameters so that only packets excluding those specified are written.
@@ -179,11 +226,36 @@
i++)
{

-				locIsOK = (locIsOK && mPacketSink->acceptStampedOggPacket(inOggPage->getStampedPacket(i)));
+				locIsOK = (locIsOK && dispatchStampedOggPacket(inOggPage->getStampedPacket(i)));
if (!locIsOK) {
+					//TODO::: State change ???
return false;
}
}
return true;

+}
+
+bool OggPacketiser::dispatchStampedOggPacket(StampedOggPacket* inPacket) {
+	if (mNumIgnorePackets > 0) {
+		//Ignore this packet.
+		mNumIgnorePackets--;
+
+		//MEMCHECK::: Should probably delete this packet here.
+		return true;
+	} else {
+		//Modify the header packet to include the gran pos of previous page.
+		if (mPrevGranPos != -1) {
+			inPacket->setTimeStamp(mPrevGranPos, mCurrentGranPos, StampedOggPacket::eStampType::OGG_BOTH);
+		}
+		//Dispatch it.
+		return mPacketSink->acceptStampedOggPacket(inPacket);
+	}
+}
+
+void OggPacketiser::setNumIgnorePackets(unsigned long inNumIgnorePackets) {
+	mNumIgnorePackets = inNumIgnorePackets;
+}
+unsigned long OggPacketiser::numIgnorePackets() {
+	return mNumIgnorePackets;
}
\ No newline at end of file

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPacketiser.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPacketiser.h	2004-08-04 06:17:46 UTC (rev 7475)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPacketiser.h	2004-08-04 09:05:56 UTC (rev 7476)
@@ -2,34 +2,48 @@
#include "IOggCallback.h"
#include "IStampedOggPacketSink.h"
#include "OggPage.h"
+
+//TODO::: Loose mode controls
class LIBOOOGG_API OggPacketiser
:	public IOggCallback
{
public:
-
+	//Constants
enum ePacketiserState {
PKRSTATE_OK,
PKRSTATE_AWAITING_CONTINUATION,
PKRSTATE_INVALID_STREAM
};

+	//Constructors
OggPacketiser(void);
OggPacketiser(IStampedOggPacketSink* inPacketSink);
virtual ~OggPacketiser(void);

+	//IOggCallback implementation
+	virtual bool acceptOggPage(OggPage* inOggPage);
+
+	//Packet sink control
void setPacketSink(IStampedOggPacketSink* inPacketSink);
-	//void setPacketSink(IStampedOggPacketSink* inPacketSink):
IStampedOggPacketSink* packetSink();
-	//void setPacketSink(IStampedOggPacketSink* inPacketSink):

-	//IOggCallback implementation
-	virtual bool acceptOggPage(OggPage* inOggPage);
+	//Ignore packets controls.
+	void setNumIgnorePackets(unsigned long inNumIgnorePackets);
+	unsigned long numIgnorePackets();

+	//Packetiser state control
bool reset();
+
protected:
IStampedOggPacketSink* mPacketSink;
StampedOggPacket* mPendingPacket;

+	virtual bool dispatchStampedOggPacket(StampedOggPacket* inPacket);
+
+	bool mLooseMode;
+	unsigned long mNumIgnorePackets;
+	__int64 mPrevGranPos;
+	__int64 mCurrentGranPos;
bool processPage(OggPage* inOggPage, bool inIncludeFirst, bool inIncludeLast);
ePacketiserState mPacketiserState;
};



More information about the commits mailing list