[xiph-commits] r8008 - in trunk/oggdsf: sln/oggdsf_all src/lib/codecs/flac/libs/libFLACHelper src/lib/core/directshow/dsfOggMux

illiminable at motherfish-iii.xiph.org illiminable at motherfish-iii.xiph.org
Fri Oct 15 03:12:45 PDT 2004


Author: illiminable
Date: 2004-10-15 03:12:45 -0700 (Fri, 15 Oct 2004)
New Revision: 8008

Modified:
   trunk/oggdsf/sln/oggdsf_all/oggdsf_all.sln
   trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACHeaderTweaker.cpp
   trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACMetadataSplitter.cpp
   trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACMetadataSplitter.h
   trunk/oggdsf/src/lib/core/directshow/dsfOggMux/OggMuxInputPin.cpp
   trunk/oggdsf/src/lib/core/directshow/dsfOggMux/OggMuxInputPin.h
   trunk/oggdsf/src/lib/core/directshow/dsfOggMux/dsfOggMux.vcproj
   trunk/oggdsf/src/lib/core/directshow/dsfOggMux/oggmuxdllstuff.h
Log:
* Change the mux so it can handle inputs of the old flac or new flac and convert to the new flac.

Modified: trunk/oggdsf/sln/oggdsf_all/oggdsf_all.sln
===================================================================
--- trunk/oggdsf/sln/oggdsf_all/oggdsf_all.sln	2004-10-15 09:23:39 UTC (rev 8007)
+++ trunk/oggdsf/sln/oggdsf_all/oggdsf_all.sln	2004-10-15 10:12:45 UTC (rev 8008)
@@ -55,6 +55,7 @@
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dsfOggMux", "..\..\src\lib\core\directshow\dsfOggMux\dsfOggMux.vcproj", "{2EBA839A-CE6E-406E-9A43-CC6FB25A78CB}"
 	ProjectSection(ProjectDependencies) = postProject
 		{223ACC19-608E-4E1B-A054-067F0CACB272} = {223ACC19-608E-4E1B-A054-067F0CACB272}
+		{7F213248-16F2-4AAE-B941-C402670082BC} = {7F213248-16F2-4AAE-B941-C402670082BC}
 		{A882A968-3013-4A27-B653-E18CF5C791FE} = {A882A968-3013-4A27-B653-E18CF5C791FE}
 		{4CBC0173-27E6-4218-AE06-5EFDCA7B2547} = {4CBC0173-27E6-4218-AE06-5EFDCA7B2547}
 		{2DA569EC-3E22-4BC9-A242-C7A56EB9C6F4} = {2DA569EC-3E22-4BC9-A242-C7A56EB9C6F4}

Modified: trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACHeaderTweaker.cpp
===================================================================
--- trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACHeaderTweaker.cpp	2004-10-15 09:23:39 UTC (rev 8007)
+++ trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACHeaderTweaker.cpp	2004-10-15 10:12:45 UTC (rev 8008)
@@ -184,7 +184,7 @@
 }
 OggPacket* FLACHeaderTweaker::getHeader(unsigned long inHeaderNo) {
 	if (inHeaderNo < mNewHeaderList.size() ) {
-		return mNewHeaderList[inHeaderNo];
+		return mNewHeaderList[inHeaderNo]->clone();
 	} else {
 		return NULL;
 	}

Modified: trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACMetadataSplitter.cpp
===================================================================
--- trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACMetadataSplitter.cpp	2004-10-15 09:23:39 UTC (rev 8007)
+++ trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACMetadataSplitter.cpp	2004-10-15 10:12:45 UTC (rev 8008)
@@ -35,14 +35,27 @@
 FLACMetadataSplitter::FLACMetadataSplitter(void)
 	:	mMetadataBlock(NULL)
 {
+	debugLog.open("G:\\logs\\flacsplitter.log", ios_base::out);
 }
 
 FLACMetadataSplitter::~FLACMetadataSplitter(void)
 {
+	debugLog.close();
 }
+StampedOggPacket* FLACMetadataSplitter::convertToStampedPacket(OggPacket* inPacket) {
+	//Convert the old packet to the new one.
+	//This function deletes the incoming packet... and transfers the buffer directly into
+	// the stamped packet without a memcpy
 
+	StampedOggPacket* locStamped = new StampedOggPacket(inPacket->packetData(), inPacket->packetSize(), false, false, 0,0,StampedOggPacket::OGG_END_ONLY);
+	//Ensure when we delete the old packet, it doesn't delete it's buffer
+	inPacket->setPacketData(NULL);
+	delete inPacket;
+	return locStamped;
+}
 
 bool FLACMetadataSplitter::loadMetadata(OggPacket* inMetadata) {
+	debugLog<<"Load Metadata"<<endl;
 	delete mMetadataBlock;
 	mMetadataBlock = inMetadata;
 	return splitMetadata();
@@ -52,7 +65,7 @@
 }
 StampedOggPacket* FLACMetadataSplitter::getHeader(unsigned long inIndex) {
 	if (inIndex < mHeaderTweaker.numNewHeaders()) {
-		return reinterpret_cast<StampedOggPacket*>(mHeaderTweaker.getHeader(inIndex));
+		return (FLACMetadataSplitter::convertToStampedPacket(mHeaderTweaker.getHeader(inIndex)->clone()));
 	} else {
 		return NULL;
 	}
@@ -63,6 +76,7 @@
 
 }
 bool FLACMetadataSplitter::splitMetadata() {
+	debugLog<<"Splitmetadata"<<endl;
 	//emptyList();
 	//OggPacket* locPacket = NULL;
 	unsigned char* locBuff = NULL;
@@ -70,9 +84,11 @@
 		return false;
 	} else {
 		if (verifyCodecID()) {
+			debugLog<<"Start adding packets..."<<endl;
 			addCodecIdent();
 			addStreamInfo();
 			addOtherHeaders();
+			debugLog<<"Done adding packets..."<<endl;
 		} else {
 			return false;
 		}
@@ -82,14 +98,16 @@
 }
 
 bool FLACMetadataSplitter::addOtherHeaders() {
+	debugLog<<"Add other headers..."<<endl;
 	unsigned long locUpto = 42;
 	unsigned long locMetaSize = mMetadataBlock->packetSize();
 	unsigned char* locSourceBuff = mMetadataBlock->packetData();	//Don't delete !
 	unsigned char* locNewBuff = NULL;
 	unsigned long locPacketSize = 0;
-	StampedOggPacket* locPacket = NULL;
+	OggPacket* locPacket = NULL;
 
 	while ( locUpto < locMetaSize) {
+		debugLog<<"Add others loop... upto = "<<locUpto<<endl;
 		for (int i = 0; i < 3; i++) {
 			locPacketSize <<=8;
 			locPacketSize += locSourceBuff[locUpto+i];
@@ -100,43 +118,47 @@
 		locNewBuff = new unsigned char[locPacketSize];
 		memcpy((void*)locNewBuff, (const void*)locSourceBuff, locPacketSize);
 
-		locPacket = new StampedOggPacket(locNewBuff, locPacketSize, false, false, 0, 0, StampedOggPacket::OGG_END_ONLY);
+		locPacket = new OggPacket(locNewBuff, locPacketSize, false, false);
 
 		mHeaderTweaker.acceptHeader(locPacket);
 		locPacket = NULL;
 
 		locUpto += locPacketSize;
+		
 
-
 	}
 
 	return true;
 }
 bool FLACMetadataSplitter::addStreamInfo() {
-	StampedOggPacket* locPacket = NULL;
+	debugLog<<"addstreaminfo..."<<endl;
+	OggPacket* locPacket = NULL;
 	unsigned char* locBuff = new unsigned char[38];
-
+	
 	memcpy((void*)locBuff, (const void*)(mMetadataBlock->packetData()+4), 38);
-	locPacket = new StampedOggPacket(locBuff, 38, false, false, 0, 0, StampedOggPacket::OGG_END_ONLY);
+	locPacket = new OggPacket(locBuff, 38, false, false);
 	mHeaderTweaker.acceptHeader(locPacket);
 	return true;
 }
 bool FLACMetadataSplitter::addCodecIdent() {
-	StampedOggPacket* locPacket = NULL;
+	debugLog<<"Add codec ident"<<endl;
+	OggPacket* locPacket = NULL;
 	unsigned char* locBuff = new unsigned char[4];
 	locBuff[0] = 'f';
 	locBuff[1] = 'L';
 	locBuff[2] = 'a';
 	locBuff[3] = 'C';
-	locPacket = new StampedOggPacket(locBuff, 4, false, false, 0, 0, StampedOggPacket::OGG_END_ONLY);
+	locPacket = new OggPacket(locBuff, 4, false, false);
 	mHeaderTweaker.acceptHeader(locPacket);
 	return true;
 }
 
 bool FLACMetadataSplitter::verifyCodecID() {
 	if ((strncmp((char*)mMetadataBlock->packetData(), "fLaC\000\000\000\042", 8)) == 0) {
+		debugLog<<"Codec verified"<<endl;
 		return true;
 	} else {
+		debugLog<<"Codec NOT VERIFIED"<<endl;
 		return false;
 	}
 

Modified: trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACMetadataSplitter.h
===================================================================
--- trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACMetadataSplitter.h	2004-10-15 09:23:39 UTC (rev 8007)
+++ trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACMetadataSplitter.h	2004-10-15 10:12:45 UTC (rev 8008)
@@ -30,18 +30,26 @@
 //===========================================================================
 #pragma once
 #include "dllstuff.h"
+#include "OggPacket.h"
 #include "StampedOggPacket.h"
 #include "FLACHeaderTweaker.h"
+
+#include <fstream>
+
+using namespace std;
+
 class FLACMetadataSplitter
 {
 public:
 	FLACMetadataSplitter(void);
 	~FLACMetadataSplitter(void);
 
+	
 	bool loadMetadata(OggPacket* inMetadata);
 	unsigned long numHeaders();
 	StampedOggPacket* getHeader(unsigned long inIndex);
 protected:
+	static StampedOggPacket* convertToStampedPacket(OggPacket* inPacket);
 	OggPacket* mMetadataBlock;
 	FLACHeaderTweaker mHeaderTweaker;
 
@@ -52,4 +60,6 @@
 	bool addCodecIdent();
 
 	bool splitMetadata();
+
+	fstream debugLog;
 };

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggMux/OggMuxInputPin.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggMux/OggMuxInputPin.cpp	2004-10-15 09:23:39 UTC (rev 8007)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggMux/OggMuxInputPin.cpp	2004-10-15 10:12:45 UTC (rev 8008)
@@ -35,6 +35,8 @@
 	:	CBaseInputPin(NAME("OggMuxInputPin"), inParentFilter, inFilterLock, inHR, L"Ogg Packet In")
 	,	mParentFilter(inParentFilter)
 	,	mMuxStream(inMuxStream)
+	,	mNeedsFLACHeaderTweak(false)
+	,	mFLACSplitter(NULL)
 {
 	OggPaginatorSettings* locSettings = new OggPaginatorSettings;
 	locSettings->mMinPageSize = 4096;
@@ -87,9 +89,19 @@
 			sSpeexFormatBlock* locSpeex = (sSpeexFormatBlock*)inMediaType->pbFormat;
 			mMuxStream->setConversionParams(locSpeex->samplesPerSec, 1, 10000000);
 		} else if (inMediaType->subtype == MEDIASUBTYPE_OggFLAC_1_0) {
+			//We are connected to the encoder nd getting individual metadata packets.
 			sFLACFormatBlock* locFLAC = (sFLACFormatBlock*)inMediaType->pbFormat;
 			mMuxStream->setConversionParams(locFLAC->samplesPerSec, 1, 10000000);
+			//mNeedsFLACHeaderTweak = true;
+		} else if (inMediaType->subtype == MEDIASUBTYPE_FLAC) {
+			//We are connected directly to the mux and are getting metadata in one block
+			// Need to use the header splitter class.
+			sFLACFormatBlock* locFLAC = (sFLACFormatBlock*)inMediaType->pbFormat;
+			mMuxStream->setConversionParams(locFLAC->samplesPerSec, 1, 10000000);
+			mNeedsFLACHeaderTweak = true;
 		} 
+
+		
 	}
 	return S_OK;
 }
@@ -152,11 +164,47 @@
 	long locBuffSize = inSample->GetActualDataLength();
 	unsigned char* locBuff = new unsigned char[locBuffSize];
 	memcpy((void*)locBuff, (const void*)locSampleBuff, inSample->GetActualDataLength());
-																								//Not truncated or contuned... its a full packet.
 	StampedOggPacket* locPacket = new StampedOggPacket(locBuff, inSample->GetActualDataLength(), false, false, locStart, locEnd, StampedOggPacket::OGG_END_ONLY);
 	
-	mPaginator.acceptStampedOggPacket(locPacket);
+	if ((mNeedsFLACHeaderTweak)) {
+		//The first packet in FLAC has all the metadata in one block...
+		// It needs to be broken up for correct muxing....
 
+		//A note about the header formats used for flac in directshow.
+		//
+		//MEDIASUBTYPE_FLAC
+		//	The first packet is all the meta data in one block.
+		//	The only filter to output this is the demux.
+		//	The demux never outputs type MEDIASUBTYPE_OGG_FLAC_1_0
+		//	Even if the input is a new FLAC stream, it is translated before leaving the filter.
+		//
+		//MEDIASUBTYPE_OggFLAC_1_0
+		//	The metadata packets are all seperated.
+		//	This is the only format outputted by the encoder
+		//
+		//
+
+		//If we are in this section of code... it means that the demux has
+		// been connected directly to the mux.
+		//This could be to mux multi stream flac.
+		//Alternatively this configuration could be used to convert the old format to the new.
+
+		mFLACSplitter = new FLACMetadataSplitter;
+
+		mFLACSplitter->loadMetadata(locPacket->clone());
+		delete locPacket;
+
+		for (int i = 0; i < mFLACSplitter->numHeaders(); i++) {
+			mPaginator.acceptStampedOggPacket(mFLACSplitter->getHeader(i));
+		}
+		mNeedsFLACHeaderTweak = false;
+	} else {
+		//Not truncated or contuned... its a full packet.
+		
+	
+		mPaginator.acceptStampedOggPacket(locPacket);
+	}
+
 	return S_OK;
 }
 

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggMux/OggMuxInputPin.h
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggMux/OggMuxInputPin.h	2004-10-15 09:23:39 UTC (rev 8007)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggMux/OggMuxInputPin.h	2004-10-15 10:12:45 UTC (rev 8008)
@@ -34,6 +34,7 @@
 #include "OggPaginator.h"
 #include "OggMuxStream.h"
 #include "BasicSeekable.h"
+#include "FLACMetadataSplitter.h"
 #include <time.h>
 #include <fstream>
 #include <windows.h>
@@ -78,6 +79,8 @@
 protected:
 	OggMuxFilter* mParentFilter;
 
+	bool mNeedsFLACHeaderTweak;
+	FLACMetadataSplitter* mFLACSplitter;
 	OggPaginator mPaginator;
 	OggMuxStream* mMuxStream;
 	//fstream debugLog;

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggMux/dsfOggMux.vcproj
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggMux/dsfOggMux.vcproj	2004-10-15 09:23:39 UTC (rev 8007)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggMux/dsfOggMux.vcproj	2004-10-15 10:12:45 UTC (rev 8008)
@@ -19,7 +19,7 @@
 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="C:\DXSDK\Include;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;..\..\ogg\libOOOgg;..\dsfSeeking;..\..\..\helper\libilliCore"
+				AdditionalIncludeDirectories="C:\DXSDK\Include;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;..\..\ogg\libOOOgg;..\dsfSeeking;..\..\..\helper\libilliCore;..\..\..\codecs\flac\libs\libFLACHelper"
 				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;DSFOGGMUX_EXPORTS"
 				MinimalRebuild="TRUE"
 				BasicRuntimeChecks="3"
@@ -80,7 +80,7 @@
 				FavorSizeOrSpeed="1"
 				OmitFramePointers="TRUE"
 				OptimizeForProcessor="3"
-				AdditionalIncludeDirectories="C:\DXSDK\Include;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;..\..\ogg\libOOOgg;..\dsfSeeking;..\..\..\helper\libilliCore"
+				AdditionalIncludeDirectories="C:\DXSDK\Include;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;..\..\ogg\libOOOgg;..\dsfSeeking;..\..\..\helper\libilliCore;..\..\..\codecs\flac\libs\libFLACHelper"
 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSFOGGMUX_EXPORTS"
 				StringPooling="TRUE"
 				RuntimeLibrary="2"
@@ -143,7 +143,7 @@
 				FavorSizeOrSpeed="1"
 				OmitFramePointers="TRUE"
 				OptimizeForProcessor="3"
-				AdditionalIncludeDirectories="C:\DXSDK\Include;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;..\..\ogg\libOOOgg;..\dsfSeeking;..\..\..\helper\libilliCore"
+				AdditionalIncludeDirectories="C:\DXSDK\Include;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;..\..\ogg\libOOOgg;..\dsfSeeking;..\..\..\helper\libilliCore;..\..\..\codecs\flac\libs\libFLACHelper"
 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSFOGGMUX_EXPORTS"
 				StringPooling="TRUE"
 				RuntimeLibrary="2"
@@ -207,7 +207,7 @@
 				FavorSizeOrSpeed="1"
 				OmitFramePointers="TRUE"
 				OptimizeForProcessor="3"
-				AdditionalIncludeDirectories="C:\DXSDK\Include;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;..\..\ogg\libOOOgg;..\dsfSeeking;..\..\..\helper\libilliCore"
+				AdditionalIncludeDirectories="C:\DXSDK\Include;&quot;C:\DXSDK\Samples\C++\DirectShow\BaseClasses&quot;;..\..\ogg\libOOOgg;..\dsfSeeking;..\..\..\helper\libilliCore;..\..\..\codecs\flac\libs\libFLACHelper"
 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSFOGGMUX_EXPORTS"
 				StringPooling="TRUE"
 				RuntimeLibrary="2"

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggMux/oggmuxdllstuff.h
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggMux/oggmuxdllstuff.h	2004-10-15 09:23:39 UTC (rev 8007)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggMux/oggmuxdllstuff.h	2004-10-15 10:12:45 UTC (rev 8008)
@@ -57,9 +57,9 @@
 DEFINE_GUID(CLSID_OggMuxFilter, 
 0x1f3effe4, 0xe70, 0x47c7, 0x9c, 0x48, 0x5, 0xeb, 0x99, 0xe2, 0x0, 0x11);
 
-//// {3913F0AB-E7ED-41c4-979B-1D1FDD983C07}
-//DEFINE_GUID(MEDIASUBTYPE_FLAC, 
-//0x3913f0ab, 0xe7ed, 0x41c4, 0x97, 0x9b, 0x1d, 0x1f, 0xdd, 0x98, 0x3c, 0x7);
+// {3913F0AB-E7ED-41c4-979B-1D1FDD983C07}
+DEFINE_GUID(MEDIASUBTYPE_FLAC, 
+0x3913f0ab, 0xe7ed, 0x41c4, 0x97, 0x9b, 0x1d, 0x1f, 0xdd, 0x98, 0x3c, 0x7);
 
 // {2C409DB0-95BF-47ba-B0F5-587256F1EDCF}
 DEFINE_GUID(MEDIASUBTYPE_OggFLAC_1_0, 



More information about the commits mailing list