[xiph-commits] r10339 - in branches/oggdsf_new_demux/src/lib/codecs/speex/filters: dsfSpeexDecoder dsfSpeexEncoder

illiminable at svn.xiph.org illiminable at svn.xiph.org
Sat Nov 5 04:37:32 PST 2005


Author: illiminable
Date: 2005-11-05 04:37:23 -0800 (Sat, 05 Nov 2005)
New Revision: 10339

Modified:
   branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/SpeexDecodeInputPin.cpp
   branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/SpeexDecodeInputPin.h
   branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/speexdecoderdllstuff.h
   branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/stdafx.h
   branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexEncoder/dsfSpeexEncoder.vcproj
Log:
* Add part of sample accurate seeking to speex decoder
* Implement IOggDecoder

Modified: branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/SpeexDecodeInputPin.cpp
===================================================================
--- branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/SpeexDecodeInputPin.cpp	2005-11-05 12:05:31 UTC (rev 10338)
+++ branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/SpeexDecodeInputPin.cpp	2005-11-05 12:37:23 UTC (rev 10339)
@@ -199,8 +199,110 @@
 
 }
 
+STDMETHODIMP SpeexDecodeInputPin::Receive(IMediaSample* inSample) 
+{
+	CAutoLock locLock(mStreamLock);
 
+	HRESULT locHR = CheckStreaming();
 
+	if (locHR == S_OK) {
+
+
+		BYTE* locBuff = NULL;
+		locHR = inSample->GetPointer(&locBuff);
+
+		if (locHR != S_OK) {
+			//TODO::: Do a debug dump or something here with specific error info.
+			return locHR;
+		} else {
+			REFERENCE_TIME locStart = -1;
+			REFERENCE_TIME locEnd = -1;
+			__int64 locSampleDuration = 0;
+			inSample->GetTime(&locStart, &locEnd);
+
+			HRESULT locResult = TransformData(locBuff, inSample->GetActualDataLength());
+			if (locResult != S_OK) {
+				return S_FALSE;
+			}
+			if (locEnd > 0) {
+				//Can dump it all downstream now	
+				IMediaSample* locSample;
+				unsigned long locBytesCopied = 0;
+				unsigned long locBytesToCopy = 0;
+
+				locStart = convertGranuleToTime(locEnd) - (((mDecodedByteCount / mFrameSize) * UNITS) / mSampleRate);
+				do {
+					HRESULT locHR = mOutputPin->GetDeliveryBuffer(&locSample, NULL, NULL, NULL);
+					if (locHR != S_OK) {
+						return locHR;
+					}
+
+					BYTE* locBuffer = NULL;
+					locHR = locSample->GetPointer(&locBuffer);
+				
+					if (locHR != S_OK) {
+						return locHR;
+					}
+
+					locBytesToCopy = ((mDecodedByteCount - locBytesCopied) <= locSample->GetSize()) ? (mDecodedByteCount - locBytesCopied) : locSample->GetSize();
+					//locBytesCopied += locBytesToCopy;
+
+					locSampleDuration = (((locBytesToCopy/mFrameSize) * UNITS) / mSampleRate);
+					locEnd = locStart + locSampleDuration;
+
+					//Adjust the time stamps for rate and seeking
+					REFERENCE_TIME locAdjustedStart = (locStart * RATE_DENOMINATOR) / mRateNumerator;
+					REFERENCE_TIME locAdjustedEnd = (locEnd * RATE_DENOMINATOR) / mRateNumerator;
+					locAdjustedStart -= m_tStart;
+					locAdjustedEnd -= m_tStart;
+
+					__int64 locSeekStripOffset = 0;
+					if (locAdjustedEnd < 0) {
+						locSample->Release();
+					} else {
+						if (locAdjustedStart < 0) {
+							locSeekStripOffset = (-locAdjustedStart) * mSampleRate;
+							locSeekStripOffset *= mFrameSize;
+							locSeekStripOffset /= UNITS;
+							locSeekStripOffset += (mFrameSize - (locSeekStripOffset % mFrameSize));
+							__int64 locStrippedDuration = (((locSeekStripOffset/mFrameSize) * UNITS) / mSampleRate);
+							locAdjustedStart += locStrippedDuration;
+						}
+							
+
+					
+
+						memcpy((void*)locBuffer, (const void*)&mDecodedBuffer[locBytesCopied + locSeekStripOffset], locBytesToCopy - locSeekStripOffset);
+
+						locSample->SetTime(&locAdjustedStart, &locAdjustedEnd);
+						locSample->SetMediaTime(&locStart, &locEnd);
+						locSample->SetSyncPoint(TRUE);
+						locSample->SetActualDataLength(locBytesToCopy - locSeekStripOffset);
+						locHR = ((SpeexDecodeOutputPin*)(mOutputPin))->mDataQueue->Receive(locSample);
+						if (locHR != S_OK) {
+							return locHR;
+						}
+						locStart += locSampleDuration;
+
+					}
+					locBytesCopied += locBytesToCopy;
+
+				
+				} while(locBytesCopied < mDecodedByteCount);
+
+				mDecodedByteCount = 0;
+				
+			}
+			return S_OK;
+
+		}
+	} else {
+		//Not streaming - Bail out.
+		return S_FALSE;
+	}
+}
+
+
 HRESULT SpeexDecodeInputPin::TransformData(BYTE* inBuf, long inNumBytes) 
 {
 	long locErr = fish_sound_decode(mFishSound, inBuf, inNumBytes);
@@ -248,3 +350,63 @@
 	
 }
 
+LOOG_INT64 SpeexDecodeInputPin::convertGranuleToTime(LOOG_INT64 inGranule)
+{
+	if (mBegun) {	
+		return (inGranule * UNITS) / mSampleRate;
+	} else {
+		return -1;
+	}
+}
+
+LOOG_INT64 SpeexDecodeInputPin::mustSeekBefore(LOOG_INT64 inGranule)
+{
+	//TODO::: Get adjustment from block size info... for now, it doesn't matter if no preroll
+	return inGranule;
+}
+IOggDecoder::eAcceptHeaderResult SpeexDecodeInputPin::showHeaderPacket(OggPacket* inCodecHeaderPacket)
+{
+	switch (mSetupState) {
+		case VSS_SEEN_NOTHING:
+			if (strncmp((char*)inCodecHeaderPacket->packetData(), "speex   ", 8) == 0) {
+				//TODO::: Possibly verify version
+				if (fish_sound_decode(mFishSound, inCodecHeaderPacket->packetData(), inCodecHeaderPacket->packetSize()) >= 0) {
+					mSetupState = VSS_SEEN_BOS;
+					return IOggDecoder::AHR_MORE_HEADERS_TO_COME;
+				}
+			}
+			return IOggDecoder::AHR_INVALID_HEADER;
+			
+			
+		case VSS_SEEN_BOS:
+			//The comment packet can't be easily identified in speex.
+			//Just ignore the second packet we see, and hope fishsound does better.
+
+			//if (strncmp((char*)inCodecHeaderPacket->packetData(), "\003vorbis", 7) == 0) {
+				if (fish_sound_decode(mFishSound, inCodecHeaderPacket->packetData(), inCodecHeaderPacket->packetSize()) >= 0) {
+					mSetupState = VSS_ALL_HEADERS_SEEN;
+					return IOggDecoder::AHR_ALL_HEADERS_RECEIVED;
+				}
+				
+				
+			//}
+			return IOggDecoder::AHR_INVALID_HEADER;
+			
+			
+	
+		case VSS_ALL_HEADERS_SEEN:
+		case VSS_ERROR:
+		default:
+			return IOggDecoder::AHR_UNEXPECTED;
+	}
+}
+string SpeexDecodeInputPin::getCodecShortName()
+{
+	return "speex";
+}
+string SpeexDecodeInputPin::getCodecIdentString()
+{
+	//TODO:::
+	return "speex";
+}
+

Modified: branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/SpeexDecodeInputPin.h
===================================================================
--- branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/SpeexDecodeInputPin.h	2005-11-05 12:05:31 UTC (rev 10338)
+++ branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/SpeexDecodeInputPin.h	2005-11-05 12:37:23 UTC (rev 10339)
@@ -31,6 +31,7 @@
 
 #pragma once
 #include "speexdecoderdllstuff.h"
+#include "IOggDecoder.h"
 #include "AbstractTransformInputPin.h"
 #include "SpeexDecodeInputPin.h"
 
@@ -62,6 +63,14 @@
 
 	virtual STDMETHODIMP GetAllocatorRequirements(ALLOCATOR_PROPERTIES *outRequestedProps);
 
+	//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();
+
+
 protected:
 	static const unsigned long SPEEX_IDENT_HEADER_SIZE = 80;
 	static const unsigned long SPEEX_NUM_BUFFERS = 75;

Modified: branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/speexdecoderdllstuff.h
===================================================================
--- branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/speexdecoderdllstuff.h	2005-11-05 12:05:31 UTC (rev 10338)
+++ branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/speexdecoderdllstuff.h	2005-11-05 12:37:23 UTC (rev 10339)
@@ -30,6 +30,7 @@
 //===========================================================================
 
 #pragma once
+#include "libOOOgg/OggPacket.h"
 //#include <streams.h>
 //#include <pullpin.h>
 //#include <initguid.h>

Modified: branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/stdafx.h
===================================================================
--- branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/stdafx.h	2005-11-05 12:05:31 UTC (rev 10338)
+++ branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexDecoder/stdafx.h	2005-11-05 12:37:23 UTC (rev 10339)
@@ -40,6 +40,8 @@
 // Windows Header Files:
 #include <windows.h>
 
+#include <libOOOgg/libOOOgg.h>
+
 // TODO: reference additional headers your program requires here
 
 #include "AbstractTransformFilter.h"

Modified: branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexEncoder/dsfSpeexEncoder.vcproj
===================================================================
--- branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexEncoder/dsfSpeexEncoder.vcproj	2005-11-05 12:05:31 UTC (rev 10338)
+++ branches/oggdsf_new_demux/src/lib/codecs/speex/filters/dsfSpeexEncoder/dsfSpeexEncoder.vcproj	2005-11-05 12:37:23 UTC (rev 10339)
@@ -19,7 +19,7 @@
 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\core\ogg;..\..\..\helper\libfishsound\include;..\..\..\helper\libfishsound\win32"
+				AdditionalIncludeDirectories="&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\core\ogg;..\..\..\helper\libfishsound\include;..\..\..\helper\libfishsound\win32;..\..\..\..\core\directshow\dsfOggDemux2"
 				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;DSFSPEEXENCODER_EXPORTS"
 				MinimalRebuild="TRUE"
 				BasicRuntimeChecks="3"
@@ -80,7 +80,7 @@
 				FavorSizeOrSpeed="1"
 				OmitFramePointers="TRUE"
 				OptimizeForProcessor="3"
-				AdditionalIncludeDirectories="&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\core\ogg;..\..\..\helper\libfishsound\include;..\..\..\helper\libfishsound\win32"
+				AdditionalIncludeDirectories="&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\core\ogg;..\..\..\helper\libfishsound\include;..\..\..\helper\libfishsound\win32;..\..\..\..\core\directshow\dsfOggDemux2"
 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSFSPEEXENCODER_EXPORTS"
 				StringPooling="TRUE"
 				RuntimeLibrary="2"
@@ -143,7 +143,7 @@
 				FavorSizeOrSpeed="1"
 				OmitFramePointers="TRUE"
 				OptimizeForProcessor="3"
-				AdditionalIncludeDirectories="&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\core\ogg;..\..\..\helper\libfishsound\include;..\..\..\helper\libfishsound\win32"
+				AdditionalIncludeDirectories="&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\core\ogg;..\..\..\helper\libfishsound\include;..\..\..\helper\libfishsound\win32;..\..\..\..\core\directshow\dsfOggDemux2"
 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSFSPEEXENCODER_EXPORTS"
 				StringPooling="TRUE"
 				RuntimeLibrary="2"
@@ -207,7 +207,7 @@
 				FavorSizeOrSpeed="1"
 				OmitFramePointers="TRUE"
 				OptimizeForProcessor="3"
-				AdditionalIncludeDirectories="&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\core\ogg;..\..\..\helper\libfishsound\include;..\..\..\helper\libfishsound\win32"
+				AdditionalIncludeDirectories="&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;C:\DXSDK\Include;..\..\..\..\core\directshow\libDirectshowAbstracts;..\..\..\..\core\ogg;..\..\..\helper\libfishsound\include;..\..\..\helper\libfishsound\win32;..\..\..\..\core\directshow\dsfOggDemux2"
 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSFSPEEXENCODER_EXPORTS"
 				StringPooling="TRUE"
 				RuntimeLibrary="2"



More information about the commits mailing list