[xiph-commits] r10548 - in branches/oggdsf_new_demux: . src/lib/codecs/flac/filters/dsfNativeFLACSource

illiminable at svn.xiph.org illiminable at svn.xiph.org
Mon Dec 5 22:23:38 PST 2005


Author: illiminable
Date: 2005-12-05 22:23:31 -0800 (Mon, 05 Dec 2005)
New Revision: 10548

Modified:
   branches/oggdsf_new_demux/AUTHORS
   branches/oggdsf_new_demux/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.cpp
Log:
* Patch from Christophe Thibault to handle native flac files with id3 tags in them.

Modified: branches/oggdsf_new_demux/AUTHORS
===================================================================
--- branches/oggdsf_new_demux/AUTHORS	2005-12-06 03:02:44 UTC (rev 10547)
+++ branches/oggdsf_new_demux/AUTHORS	2005-12-06 06:23:31 UTC (rev 10548)
@@ -59,7 +59,6 @@
 *** dsfDiracEncodeFilter
 *** dsfFLACDecoder
 *** dsfFLACEncoder
-*** dsfNativeFLACSource
 *** dsfOggDemux
 *** dsfOggMux	
 *** dsfSeeking
@@ -86,6 +85,14 @@
 
 	Zentaro Kavanagh <ogg at illiminable.com>
 		- Design and coding.
+
+*** dsfNativeFLACSource
+
+	Zentaro Kavanagh <ogg at illiminable.com>
+		- Design and coding.
+
+	Christophe Thibault
+		- Patch to handle files with id3 tags.
 ==============================================================
 *** libfishsound
 	Conrad Parker <conrad at metadecks.org>

Modified: branches/oggdsf_new_demux/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.cpp
===================================================================
--- branches/oggdsf_new_demux/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.cpp	2005-12-06 03:02:44 UTC (rev 10547)
+++ branches/oggdsf_new_demux/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.cpp	2005-12-06 06:23:31 UTC (rev 10548)
@@ -105,16 +105,38 @@
 }
 
 
-STDMETHODIMP NativeFLACSourceFilter::Load(LPCOLESTR inFileName, const AM_MEDIA_TYPE* inMediaType) {
+STDMETHODIMP NativeFLACSourceFilter::Load(LPCOLESTR inFileName, const AM_MEDIA_TYPE* inMediaType) 
+{
 	//Initialise the file here and setup the stream
 	CAutoLock locLock(m_pLock);
 	mFileName = inFileName;
 
 	mInputFile.open(StringHelper::toNarrowStr(mFileName).c_str(), ios_base::in | ios_base::binary);
 
+	//CT> Added header check (for FLAC files with ID3 v1/2 tags in them)
+	//    We'll look in the first 128kb of the file
+	unsigned long locStart = 0;
+	int locHeaderFound = 0;
+	for(int j = 0; !locHeaderFound && j < 128; j++)	{
+		unsigned char locTempBuf[1024]={0,};
+		mInputFile.read((char*)&locTempBuf, sizeof(locTempBuf));
+		unsigned char* locPtr = locTempBuf;
+		for(int i = 0; i < 1023; i++) {
+			if(locPtr[i]=='f' && locPtr[i+1]=='L' && locPtr[i+2]=='a' && locPtr[i+3]=='C')			{
+				locHeaderFound = 1;
+				locStart = i + (j * 1024);
+				break;
+			}
+		}
+	}
+	if(!locHeaderFound) {
+		return E_FAIL;
+	}
+
 	mInputFile.seekg(0, ios_base::end);
 	mFileSize = mInputFile.tellg();
-	mInputFile.seekg(0, ios_base::beg);
+	mFileSize -= locStart;
+	mInputFile.seekg(locStart, ios_base::beg);
 
 	unsigned char locBuff[64];
 	mInputFile.read((char*)&locBuff, 64);
@@ -128,12 +150,40 @@
 	mTotalNumSamples = (((__int64)(locBuff[21] % 16)) << 32) + ((__int64)(iBE_Math::charArrToULong(&locBuff[22])));
 
 	//TODO::: NEed to handle the case where the number of samples is zero by making it non-seekable.
-	mInputFile.seekg(0, ios_base::beg);
+	mInputFile.seekg(locStart, ios_base::beg);
 
 	init();
 	bool locResult = process_until_end_of_metadata();
 
 	return S_OK;
+	////Initialise the file here and setup the stream
+	//CAutoLock locLock(m_pLock);
+	//mFileName = inFileName;
+
+	//mInputFile.open(StringHelper::toNarrowStr(mFileName).c_str(), ios_base::in | ios_base::binary);
+
+	//mInputFile.seekg(0, ios_base::end);
+	//mFileSize = mInputFile.tellg();
+	//mInputFile.seekg(0, ios_base::beg);
+
+	//unsigned char locBuff[64];
+	//mInputFile.read((char*)&locBuff, 64);
+	//const unsigned char FLAC_CHANNEL_MASK = 14;  //00001110
+	//const unsigned char FLAC_BPS_START_MASK = 1; //00000001
+	//const unsigned char FLAC_BPS_END_MASK = 240;  //11110000
+
+	//mNumChannels = (((locBuff[20]) & FLAC_CHANNEL_MASK) >> 1) + 1;
+	//mSampleRate = (iBE_Math::charArrToULong(&locBuff[18])) >> 12;
+	//mBitsPerSample =	(((locBuff[20] & FLAC_BPS_START_MASK) << 4)	| ((locBuff[21] & FLAC_BPS_END_MASK) >> 4)) + 1;	
+	//mTotalNumSamples = (((__int64)(locBuff[21] % 16)) << 32) + ((__int64)(iBE_Math::charArrToULong(&locBuff[22])));
+
+	////TODO::: NEed to handle the case where the number of samples is zero by making it non-seekable.
+	//mInputFile.seekg(0, ios_base::beg);
+
+	//init();
+	//bool locResult = process_until_end_of_metadata();
+
+	//return S_OK;
 }
 
 STDMETHODIMP NativeFLACSourceFilter::NonDelegatingQueryInterface(REFIID riid, void **ppv)



More information about the commits mailing list