[xiph-commits] r10297 - branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder

illiminable at svn.xiph.org illiminable at svn.xiph.org
Mon Oct 24 15:01:16 PDT 2005


Author: illiminable
Date: 2005-10-24 15:01:08 -0700 (Mon, 24 Oct 2005)
New Revision: 10297

Modified:
   branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeFilter.cpp
   branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeFilter.h
   branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeInputPin.cpp
   branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeInputPin.h
   branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/dsfTheoraDecoder.vcproj
Log:
* Implement IOggDecoder on theora decoder
* Change the media type negotiation to the new system

Modified: branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeFilter.cpp
===================================================================
--- branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeFilter.cpp	2005-10-24 20:51:54 UTC (rev 10296)
+++ branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeFilter.cpp	2005-10-24 22:01:08 UTC (rev 10297)
@@ -134,16 +134,24 @@
 	return true;
 }
 
-HRESULT TheoraDecodeFilter::CheckInputType(const CMediaType* inMediaType) {
+HRESULT TheoraDecodeFilter::CheckInputType(const CMediaType* inMediaType) 
+{
+
 	
-	if	( (inMediaType->majortype == MEDIATYPE_Video) &&
-			(inMediaType->subtype == MEDIASUBTYPE_Theora) && (inMediaType->formattype == FORMAT_Theora)
+	if	( (inMediaType->majortype == MEDIATYPE_OggPacketStream) &&
+			(inMediaType->subtype == MEDIASUBTYPE_None) && (inMediaType->formattype == FORMAT_OggIdentHeader)
 		)
 	{
-		return S_OK;
-	} else {
-		return S_FALSE;
+		if (inMediaType->cbFormat == THEORA_IDENT_HEADER_SIZE) {
+			if (strncmp((char*)inMediaType->pbFormat, "\200theora", 7) == 0) {
+				//TODO::: Possibly verify version
+				return S_OK;
+			}
+		}
+
 	}
+	return S_FALSE;
+	
 }
 HRESULT TheoraDecodeFilter::CheckTransform(const CMediaType* inInputMediaType, const CMediaType* inOutputMediaType) {
 	if ((CheckInputType(inInputMediaType) == S_OK) &&
@@ -316,7 +324,9 @@
 	}
 }
 
-void TheoraDecodeFilter::ResetFrameCount() {
+void TheoraDecodeFilter::ResetFrameCount() 
+{
+	//XTODO::: Maybe not needed
 	mFrameCount = 0;
 	
 }
@@ -614,18 +624,13 @@
 HRESULT TheoraDecodeFilter::SetMediaType(PIN_DIRECTION inDirection, const CMediaType* inMediaType) {
 
 	if (inDirection == PINDIR_INPUT) {
-		if (inMediaType->subtype == MEDIASUBTYPE_Theora) {
+		if (CheckInputType(inMediaType) == S_OK) {
 			//debugLog<<"Setting format block"<<endl;
-			setTheoraFormat((sTheoraFormatBlock*)inMediaType->pbFormat);
+			setTheoraFormat(inMediaType->pbFormat);
 			
 			//Set some other stuff here too...
-			mXOffset = ((sTheoraFormatBlock*)inMediaType->pbFormat)->xOffset;
-			mYOffset = ((sTheoraFormatBlock*)inMediaType->pbFormat)->yOffset;
-			//mHeight = ((sTheoraFormatBlock*)inMediaType->pbFormat)->frameHeight;
-			//mWidth = ((sTheoraFormatBlock*)inMediaType->pbFormat)->frameWidth;
-			//debugLog<<"Setting height width to "<<mWidth<<" x "<<mHeight<<endl;
-			//debugLog<<"Frame Dims were "<<((sTheoraFormatBlock*)inMediaType->pbFormat)->frameWidth<<" x "<<((sTheoraFormatBlock*)inMediaType->pbFormat)->frameHeight<<endl;
-
+			mXOffset = mTheoraFormatInfo->xOffset;
+			mYOffset = mTheoraFormatInfo->xOffset;
 		} else {
 			//Failed... should never be here !
 			throw 0;
@@ -668,11 +673,48 @@
 {
 	return mTheoraFormatInfo;
 }
-void TheoraDecodeFilter::setTheoraFormat(sTheoraFormatBlock* inFormatBlock) 
+void TheoraDecodeFilter::setTheoraFormat(BYTE* inFormatBlock) 
 {
+
 	delete mTheoraFormatInfo;
 	mTheoraFormatInfo = new sTheoraFormatBlock;			//Deelted in destructor.
-	*mTheoraFormatInfo = *inFormatBlock;
+
+	//0		-	55			theora ident						0	-	6
+	//56	-	63			ver major							7	-	7
+	//64	-	71			ver minor							8	-	8
+	//72	-	79			ver subversion						9	=	9
+	//80	-	95			width/16							10	-	11
+	//96	-	111			height/16							12	-	13
+	//112	-	135			framewidth							14	-	16
+	//136	-	159			frameheight							17	-	19
+	//160	-	167			xoffset								20	-	20
+	//168	-	175			yoffset								21	-	21
+	//176	-	207			framerateNum						22	-	25
+	//208	-	239			frameratedenom						26	-	29
+	//240	-	263			aspectNum							30	-	32
+	//264	-	287			aspectdenom							33	-	35
+	//288	-	295			colourspace							36	-	36
+	//296	-	319			targetbitrate						37	-	39
+	//320	-	325			targetqual							40	-	40.75
+	//326	-	330			keyframintlog						40.75-  41.375
+
+	unsigned char* locIdentHeader = inFormatBlock;
+	mTheoraFormatInfo->theoraVersion = (iBE_Math::charArrToULong(locIdentHeader + 7)) >>8;
+	mTheoraFormatInfo->outerFrameWidth = (iBE_Math::charArrToUShort(locIdentHeader + 10)) * 16;
+	mTheoraFormatInfo->outerFrameHeight = (iBE_Math::charArrToUShort(locIdentHeader + 12)) * 16;
+	mTheoraFormatInfo->pictureWidth = (iBE_Math::charArrToULong(locIdentHeader + 14)) >>8;
+	mTheoraFormatInfo->pictureHeight = (iBE_Math::charArrToULong(locIdentHeader + 17)) >>8;
+	mTheoraFormatInfo->xOffset = locIdentHeader[20];
+	mTheoraFormatInfo->yOffset = locIdentHeader[21];
+	mTheoraFormatInfo->frameRateNumerator = iBE_Math::charArrToULong(locIdentHeader + 22);
+	mTheoraFormatInfo->frameRateDenominator = iBE_Math::charArrToULong(locIdentHeader + 26);
+	mTheoraFormatInfo->aspectNumerator = (iBE_Math::charArrToULong(locIdentHeader + 30)) >>8;
+	mTheoraFormatInfo->aspectDenominator = (iBE_Math::charArrToULong(locIdentHeader + 33)) >>8;
+	mTheoraFormatInfo->colourSpace = locIdentHeader[36];
+	mTheoraFormatInfo->targetBitrate = (iBE_Math::charArrToULong(locIdentHeader + 37)) >>8;
+	mTheoraFormatInfo->targetQuality = (locIdentHeader[40]) >> 2;
+
+	mTheoraFormatInfo->maxKeyframeInterval= (((locIdentHeader[40]) % 4) << 3) + (locIdentHeader[41] >> 5);
 }
 
 CBasePin* TheoraDecodeFilter::GetPin(int inPinNo)

Modified: branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeFilter.h
===================================================================
--- branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeFilter.h	2005-10-24 20:51:54 UTC (rev 10296)
+++ branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeFilter.h	2005-10-24 22:01:08 UTC (rev 10297)
@@ -34,6 +34,8 @@
 #include "Theoradecoderdllstuff.h"
 #include "theoradecodeoutputpin.h"
 #include "theoradecodeinputpin.h"
+
+#include <libilliCore/iBE_Math.h>
 #include <math.h>
 //#include "DSStringer.h"
 #include "TheoraDecoder.h"
@@ -45,6 +47,7 @@
 
 {
 public:
+	friend class TheoraDecodeInputPin;
 	TheoraDecodeFilter(void);
 	virtual ~TheoraDecodeFilter(void);
 
@@ -65,8 +68,10 @@
 	virtual CBasePin* TheoraDecodeFilter::GetPin(int inPinNo);
 	//Helpers
 	sTheoraFormatBlock* getTheoraFormatBlock();
-	void setTheoraFormat(sTheoraFormatBlock* inFormatBlock);
+	void setTheoraFormat(BYTE* inFormatBlock);
 protected:
+
+	static const unsigned long THEORA_IDENT_HEADER_SIZE = 50;
 	virtual void ResetFrameCount();
 	void FillMediaType(CMediaType* outMediaType, unsigned long inSampleSize);
 	bool FillVideoInfoHeader(VIDEOINFOHEADER* inFormatBuffer);

Modified: branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeInputPin.cpp
===================================================================
--- branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeInputPin.cpp	2005-10-24 20:51:54 UTC (rev 10296)
+++ branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeInputPin.cpp	2005-10-24 22:01:08 UTC (rev 10297)
@@ -35,6 +35,7 @@
 
 TheoraDecodeInputPin::TheoraDecodeInputPin(CTransformFilter* inParentFilter, HRESULT* outHR) 
 	:	CTransformInputPin(NAME("Theora Input Pin"), inParentFilter, outHR, L"Theora In")
+	,	mSetupState(VSS_SEEN_NOTHING)
 {
 	//debugLog.open("G:\\logs\\theoinput.log", ios_base::out);
 }
@@ -42,14 +43,22 @@
 	//debugLog.close();
 }
 
-STDMETHODIMP TheoraDecodeInputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv) {
-	//debugLog<<"Querying interface"<<endl;
+STDMETHODIMP TheoraDecodeInputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv) 
+{
+
+
+
 	if (riid == IID_IMediaSeeking) {
 		//debugLog<<"Got Seeker"<<endl;
 		*ppv = (IMediaSeeking*)this;
 		((IUnknown*)*ppv)->AddRef();
 		
 		return NOERROR;
+	} else if (riid == IID_IOggDecoder) {
+		*ppv = (IOggDecoder*)this;
+		//((IUnknown*)*ppv)->AddRef();
+		return NOERROR;
+
 	}
 
 	return CBaseInputPin::NonDelegatingQueryInterface(riid, ppv); 
@@ -74,3 +83,93 @@
 	return CTransformInputPin::CompleteConnect(inReceivePin);
 }
 
+LOOG_INT64 TheoraDecodeInputPin::convertGranuleToTime(LOOG_INT64 inGranule)
+{
+	//if (mBegun) {	
+	//	return (inGranule * UNITS) / mSampleRate;
+	//} else {
+	//	return -1;
+	//}
+
+	//XTODO:::
+	return -1;
+}
+
+LOOG_INT64 TheoraDecodeInputPin::mustSeekBefore(LOOG_INT64 inGranule)
+{
+	//TODO::: Get adjustment from block size info... for now, it doesn't matter if no preroll
+	return inGranule;
+}
+IOggDecoder::eAcceptHeaderResult TheoraDecodeInputPin::showHeaderPacket(OggPacket* inCodecHeaderPacket)
+{
+	unsigned char* locPacketData = new unsigned char[inCodecHeaderPacket->packetSize()];
+	memcpy((void*)locPacketData, (const void**)inCodecHeaderPacket->packetData(), inCodecHeaderPacket->packetSize());
+	StampedOggPacket* locStamped = new StampedOggPacket(locPacketData, inCodecHeaderPacket->packetSize(), false, false, 0,0, StampedOggPacket::NONE);
+
+	TheoraDecodeFilter* locParent = (TheoraDecodeFilter*)m_pFilter;
+
+	IOggDecoder::eAcceptHeaderResult retResult = IOggDecoder::AHR_INVALID_HEADER;
+	switch (mSetupState) {
+		case VSS_SEEN_NOTHING:
+			if (strncmp((char*)inCodecHeaderPacket->packetData(), "\200theora", 7) == 0) {
+				//TODO::: Possibly verify version
+				if (locParent->mTheoraDecoder->decodeTheora(locStamped) == NULL) {
+					mSetupState = VSS_SEEN_BOS;
+					retResult = IOggDecoder::AHR_MORE_HEADERS_TO_COME;
+				}
+			}
+			//return IOggDecoder::AHR_INVALID_HEADER;
+			break;
+			
+			
+		case VSS_SEEN_BOS:
+			if (strncmp((char*)inCodecHeaderPacket->packetData(), "\201theora", 7) == 0) {
+				if (locParent->mTheoraDecoder->decodeTheora(locStamped) == NULL) {
+					mSetupState = VSS_SEEN_COMMENT;
+					retResult = IOggDecoder::AHR_MORE_HEADERS_TO_COME;
+				}
+				
+				
+			}
+			//return IOggDecoder::AHR_INVALID_HEADER;
+			break;
+			
+			
+		case VSS_SEEN_COMMENT:
+			if (strncmp((char*)inCodecHeaderPacket->packetData(), "\202theora", 7) == 0) {
+				if (locParent->mTheoraDecoder->decodeTheora(locStamped) == NULL) {
+		
+					//fish_sound_command (mFishSound, FISH_SOUND_GET_INFO, &(mFishInfo), sizeof (FishSoundInfo)); 
+					//Is mBegun useful ?
+					//mBegun = true;
+			
+					//mNumChannels = mFishInfo.channels;
+					//mFrameSize = mNumChannels * SIZE_16_BITS;
+					//mSampleRate = mFishInfo.samplerate;
+
+		
+					mSetupState = VSS_ALL_HEADERS_SEEN;
+					retResult = IOggDecoder::AHR_ALL_HEADERS_RECEIVED;
+				}
+				
+			}
+			//return IOggDecoder::AHR_INVALID_HEADER;
+			break;
+			
+		case VSS_ALL_HEADERS_SEEN:
+		case VSS_ERROR:
+		default:
+			retResult = IOggDecoder::AHR_UNEXPECTED;
+	}
+	delete locStamped;
+	return retResult;
+}
+string TheoraDecodeInputPin::getCodecShortName()
+{
+	return "theora";
+}
+string TheoraDecodeInputPin::getCodecIdentString()
+{
+	//TODO:::
+	return "theora";
+}
\ No newline at end of file

Modified: branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeInputPin.h
===================================================================
--- branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeInputPin.h	2005-10-24 20:51:54 UTC (rev 10296)
+++ branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/TheoraDecodeInputPin.h	2005-10-24 22:01:08 UTC (rev 10297)
@@ -30,9 +30,12 @@
 //===========================================================================
 
 #pragma once
+#include "IOggDecoder.h"
 #include "Theoradecoderdllstuff.h"
 #include "BasicSeekPassThrough.h"
 
+#include "TheoraDecodeFilter.h"
+
 #include <fstream>
 using namespace std;
 class TheoraDecodeInputPin 
@@ -52,5 +55,27 @@
 	virtual HRESULT BreakConnect();
 	virtual HRESULT CompleteConnect (IPin *inReceivePin);
 
+	//XTODO::: Add a new segment override to get an integer rate change
+	//XTODO::: Possibly add an endflush override to clear buffered data
+	//XTODO::: Implement IOggDecoder interface
+	//XTODO::: Implement getallocator requirements to tell demux what buffers to use
+
+	//IOggDecoder Interface
+	virtual LOOG_INT64 convertGranuleToTime(LOOG_INT64 inGranule);
+	virtual LOOG_INT64 mustSeekBefore(LOOG_INT64 inGranule);
+	virtual IOggDecoder::eAcceptHeaderResult showHeaderPacket(OggPacket* inCodecHeaderPacket);
+	virtual string getCodecShortName();
+	virtual string getCodecIdentString();
 	//fstream debugLog;
+
+protected:
+	enum eTheoraSetupState {
+		VSS_SEEN_NOTHING,
+		VSS_SEEN_BOS,
+		VSS_SEEN_COMMENT,
+		VSS_ALL_HEADERS_SEEN,
+		VSS_ERROR
+	};
+
+	eTheoraSetupState mSetupState;
 };

Modified: branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/dsfTheoraDecoder.vcproj
===================================================================
--- branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/dsfTheoraDecoder.vcproj	2005-10-24 20:51:54 UTC (rev 10296)
+++ branches/oggdsf_new_demux/src/lib/codecs/theora/filters/dsfTheoraDecoder/dsfTheoraDecoder.vcproj	2005-10-24 22:01:08 UTC (rev 10297)
@@ -19,7 +19,7 @@
 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="..\..\..\..\core\directshow\dsfAbstractVideoDecoder;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\libs\libOOTheora;..\..\libs\libtheora\include;..\..\..\..\core\ogg;..\..\..\..\core\ogg\libogg\include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\helper;..\..\..\..\helper\iDSHelper"
+				AdditionalIncludeDirectories="..\..\..\..\core\directshow\dsfAbstractVideoDecoder;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\libs\libOOTheora;..\..\libs\libtheora\include;..\..\..\..\core\ogg;..\..\..\..\core\ogg\libogg\include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\helper;..\..\..\..\helper\iDSHelper;..\..\..\..\core\directshow\dsfOggDemux2"
 				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;DSFTHEORADECODER_EXPORTS"
 				MinimalRebuild="TRUE"
 				BasicRuntimeChecks="3"
@@ -80,7 +80,7 @@
 				FavorSizeOrSpeed="1"
 				OmitFramePointers="TRUE"
 				OptimizeForProcessor="3"
-				AdditionalIncludeDirectories="..\..\..\..\core\directshow\dsfAbstractVideoDecoder;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\libs\libOOTheora;..\..\libs\libtheora\include;..\..\..\..\core\ogg;..\..\..\..\core\ogg\libogg\include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\helper;..\..\..\..\helper\iDSHelper"
+				AdditionalIncludeDirectories="..\..\..\..\core\directshow\dsfAbstractVideoDecoder;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\libs\libOOTheora;..\..\libs\libtheora\include;..\..\..\..\core\ogg;..\..\..\..\core\ogg\libogg\include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\helper;..\..\..\..\helper\iDSHelper;..\..\..\..\core\directshow\dsfOggDemux2"
 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSFTHEORADECODER_EXPORTS"
 				StringPooling="TRUE"
 				RuntimeLibrary="2"
@@ -143,7 +143,7 @@
 				FavorSizeOrSpeed="1"
 				OmitFramePointers="TRUE"
 				OptimizeForProcessor="3"
-				AdditionalIncludeDirectories="..\..\..\..\core\directshow\dsfAbstractVideoDecoder;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\libs\libOOTheora;..\..\libs\libtheora\include;..\..\..\..\core\ogg;..\..\..\..\core\ogg\libogg\include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\helper;..\..\..\..\helper\iDSHelper"
+				AdditionalIncludeDirectories="..\..\..\..\core\directshow\dsfAbstractVideoDecoder;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\libs\libOOTheora;..\..\libs\libtheora\include;..\..\..\..\core\ogg;..\..\..\..\core\ogg\libogg\include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\helper;..\..\..\..\helper\iDSHelper;..\..\..\..\core\directshow\dsfOggDemux2"
 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSFTHEORADECODER_EXPORTS"
 				StringPooling="TRUE"
 				RuntimeLibrary="2"
@@ -207,7 +207,7 @@
 				FavorSizeOrSpeed="1"
 				OmitFramePointers="TRUE"
 				OptimizeForProcessor="3"
-				AdditionalIncludeDirectories="..\..\..\..\core\directshow\dsfAbstractVideoDecoder;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\libs\libOOTheora;..\..\libs\libtheora\include;..\..\..\..\core\ogg;..\..\..\..\core\ogg\libogg\include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\helper;..\..\..\..\helper\iDSHelper"
+				AdditionalIncludeDirectories="..\..\..\..\core\directshow\dsfAbstractVideoDecoder;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\libs\libOOTheora;..\..\libs\libtheora\include;..\..\..\..\core\ogg;..\..\..\..\core\ogg\libogg\include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\helper;..\..\..\..\helper\iDSHelper;..\..\..\..\core\directshow\dsfOggDemux2"
 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSFTHEORADECODER_EXPORTS"
 				StringPooling="TRUE"
 				RuntimeLibrary="2"



More information about the commits mailing list