[xiph-commits] r8089 - in trunk/oggdsf: sln/oggdsf_all
src/lib/codecs/flac/filters/dsfNativeFLACSource
illiminable at motherfish-iii.xiph.org
illiminable at motherfish-iii.xiph.org
Mon Oct 25 03:03:48 PDT 2004
Author: illiminable
Date: 2004-10-25 03:03:48 -0700 (Mon, 25 Oct 2004)
New Revision: 8089
Added:
trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSource.def
Modified:
trunk/oggdsf/sln/oggdsf_all/oggdsf_all.sln
trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.cpp
trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.h
trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourcePin.cpp
trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourcePin.h
trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/dsfNativeFLACSource.h
trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/dsfNativeFLACSource.vcproj
Log:
* FLAC native source mostly meated out.
Modified: trunk/oggdsf/sln/oggdsf_all/oggdsf_all.sln
===================================================================
--- trunk/oggdsf/sln/oggdsf_all/oggdsf_all.sln 2004-10-25 08:22:27 UTC (rev 8088)
+++ trunk/oggdsf/sln/oggdsf_all/oggdsf_all.sln 2004-10-25 10:03:48 UTC (rev 8089)
@@ -1214,6 +1214,7 @@
{6B548F29-04A2-4F61-946F-72B86B4845DA} = {6B548F29-04A2-4F61-946F-72B86B4845DA}
{4CBC0173-27E6-4218-AE06-5EFDCA7B2547} = {4CBC0173-27E6-4218-AE06-5EFDCA7B2547}
{A0004AEB-B47C-4A0A-8FE7-4F65B5FD48FA} = {A0004AEB-B47C-4A0A-8FE7-4F65B5FD48FA}
+ {2DA569EC-3E22-4BC9-A242-C7A56EB9C6F4} = {2DA569EC-3E22-4BC9-A242-C7A56EB9C6F4}
EndProjectSection
EndProject
Global
Added: trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSource.def
===================================================================
--- trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSource.def 2004-10-25 08:22:27 UTC (rev 8088)
+++ trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSource.def 2004-10-25 10:03:48 UTC (rev 8089)
@@ -0,0 +1,7 @@
+LIBRARY dsfNativeFLACSource
+EXPORTS
+ DllMain PRIVATE
+ DllGetClassObject PRIVATE
+ DllCanUnloadNow PRIVATE
+ DllRegisterServer PRIVATE
+ DllUnregisterServer PRIVATE
Modified: trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.cpp
===================================================================
--- trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.cpp 2004-10-25 08:22:27 UTC (rev 8088)
+++ trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.cpp 2004-10-25 10:03:48 UTC (rev 8089)
@@ -58,14 +58,21 @@
NativeFLACSourceFilter::NativeFLACSourceFilter(void)
: CBaseFilter(NAME("NativeFLACSourceFilter"), NULL, m_pLock, CLSID_NativeFLACSourceFilter)
+ , mNumChannels(0)
+ , mSampleRate(0)
+ , mBitsPerSample(0)
+ , mBegun(false)
+ , mUpto(0)
//, mDecoder(NULL)
{
+ debugLog.open("G:\\logs\\NativeFLAC.log", ios_base::out);
mFLACSourcePin = new NativeFLACSourcePin(this, m_pLock);
}
NativeFLACSourceFilter::~NativeFLACSourceFilter(void)
{
+ debugLog.close();
delete mFLACSourcePin;
mFLACSourcePin = NULL;
}
@@ -105,6 +112,33 @@
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);
+ debugLog<<"File size is = "<<mFileSize<<endl;
+
+ 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
+
+ //Fix the format block data... use header version and other version.
+ //mFLACFormatBlock->FLACVersion = FLACMath::charArrToULong(mCodecHeaders->getPacket(1)->packetData() + 28);
+ 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;
+
+
+ debugLog<<mNumChannels<<" channels with "<<mSampleRate<<" Hz @ "<<mBitsPerSample<<" bits per sample"<<endl;
+ mInputFile.seekg(0, ios_base::beg);
+
+
+
//Strip the extension...
//size_t locDotPos = mFileName.find_last_of('.');
//if (locDotPos != ios_base::npos) {
@@ -207,27 +241,91 @@
::FLAC__SeekableStreamDecoderReadStatus NativeFLACSourceFilter::read_callback(FLAC__byte outBuffer[], unsigned int* outNumBytes) {
+ const unsigned long BUFF_SIZE = 8192;
+ mInputFile.read((char*)outBuffer, BUFF_SIZE);
+ *outNumBytes = mInputFile.gcount();
+ debugLog<<"Read num bytes = "<<*outNumBytes<<endl;
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
}
::FLAC__SeekableStreamDecoderSeekStatus NativeFLACSourceFilter::seek_callback(FLAC__uint64 inSeekPos) {
+ debugLog<<"Seeking to "<<inSeekPos<<endl;
+ mInputFile.seekg(inSeekPos);
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
}
::FLAC__SeekableStreamDecoderTellStatus NativeFLACSourceFilter::tell_callback(FLAC__uint64* outTellPos) {
+ *outTellPos = mInputFile.tellg();
+ debugLog<<"Tell = "<<*outTellPos<<endl;
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
}
::FLAC__SeekableStreamDecoderLengthStatus NativeFLACSourceFilter::length_callback(FLAC__uint64* outLength) {
+ *outLength = mFileSize;
+ debugLog<<"Requested length = "<<mFileSize<<endl;
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
}
-::FLAC__StreamDecoderWriteStatus NativeFLACSourceFilter::write_callback(const FLAC__Frame* outFrame,const FLAC__int32 *const outBuffer[]) {
+::FLAC__StreamDecoderWriteStatus NativeFLACSourceFilter::write_callback(const FLAC__Frame* inFrame,const FLAC__int32 *const inBuffer[]) {
+ //Do the magic !
+ if (! mBegun) {
+
+ mBegun = true;
+ const int SIZE_16_BITS = 2;
+ mNumChannels = inFrame->header.channels;
+ mFrameSize = mNumChannels * SIZE_16_BITS;
+ mSampleRate = inFrame->header.sample_rate;
+
+ }
+ unsigned long locNumFrames = inFrame->header.blocksize;
+ unsigned long locActualSize = locNumFrames * mFrameSize;
+ unsigned long locTotalFrameCount = locNumFrames * mNumChannels;
+
+ //BUG::: There's a bug here. Implicitly assumes 2 channels.
+ unsigned char* locBuff = new unsigned char[locActualSize];
+
+
+ signed short* locShortBuffer = (signed short*)locBuff; //Don't delete this.
+
+ signed short tempInt = 0;
+ int tempLong = 0;
+ float tempFloat = 0;
+
+ //FIX:::Move the clipping to the abstract function
+ //Make sure our sample buffer is big enough
+
+ //Modified for FLAC int32 not float
+
+
+ //Must interleave and convert sample size.
+ for(unsigned long i = 0; i < locNumFrames; i++) {
+ for (unsigned long j = 0; j < mNumChannels; j++) {
+
+
+ //No clipping required for ints
+ //FIX:::Take out the unnescessary variable.
+ tempLong = inBuffer[j][i];
+ //Convert 32 bit to 16 bit
+
+ //FIX::: Why on earth are you dividing by 2 ? It does not make sense !
+ tempInt = (signed short)(tempLong/2);
+
+ *locShortBuffer = tempInt;
+ locShortBuffer++;
+ }
+ }
+
+
+
+
+ mFLACSourcePin->deliverData(locBuff, locActualSize, (mUpto*UNITS) / mSampleRate, ((mUpto+locNumFrames)*UNITS) / mSampleRate);
+ mUpto += locNumFrames;
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
void NativeFLACSourceFilter::metadata_callback(const FLAC__StreamMetadata* inMetaData) {
-
+ debugLog<<"Meta callback..."<<endl;
}
void NativeFLACSourceFilter::error_callback(FLAC__StreamDecoderErrorStatus inStatus) {
-
+ debugLog<<"Error callback..."<<endl;
}
bool NativeFLACSourceFilter::eof_callback(void) {
- return false;
+ debugLog<<"EOF Req"<<endl;
+ return mInputFile.eof();
}
\ No newline at end of file
Modified: trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.h
===================================================================
--- trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.h 2004-10-25 08:22:27 UTC (rev 8088)
+++ trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.h 2004-10-25 10:03:48 UTC (rev 8089)
@@ -32,6 +32,8 @@
#include "dsfNativeFLACSource.h"
#include "NativeFLACSourcePin.h"
#include "FLAC++/decoder.h"
+#include "StringHelper.h"
+#include "iBE_Math.h"
#include <string>
using namespace std;
using namespace FLAC::Decoder;
@@ -46,6 +48,7 @@
, protected FLAC::Decoder::SeekableStream
{
public:
+ friend class NativeFLACSourcePin;
enum eThreadCommands {
THREAD_EXIT = 0,
THREAD_PAUSE = 1,
@@ -102,5 +105,19 @@
wstring mFileName;
wstring mHDRFileName;
+ fstream mInputFile;
+ unsigned long mFileSize;
+
+ fstream debugLog;
+
+ bool mBegun;
+
+ unsigned long mUpto;
+
+ unsigned long mNumChannels;
+ unsigned long mFrameSize;
+ unsigned long mSampleRate;
+ unsigned long mBitsPerSample;
+
};
Modified: trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourcePin.cpp
===================================================================
--- trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourcePin.cpp 2004-10-25 08:22:27 UTC (rev 8088)
+++ trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourcePin.cpp 2004-10-25 10:03:48 UTC (rev 8089)
@@ -33,6 +33,8 @@
NativeFLACSourcePin::NativeFLACSourcePin(NativeFLACSourceFilter* inParentFilter, CCritSec* inFilterLock)
: CBaseOutputPin(NAME("Native FLAC Source Pin"), inParentFilter, inFilterLock, &mFilterHR, L"PCM Out")
+ , mParentFilter(inParentFilter)
+
{
}
@@ -101,15 +103,24 @@
//NOTE::: May want to check for null pointers
//outMediaType->SetFormat(mMediaType->Format(), mMediaType->FormatLength());
if (inPosition == 0) {
- CMediaType locMediaType;
+
- locMediaType.majortype = MEDIATYPE_Audio;
- locMediaType.subtype = MEDIASUBTYPE_PCM;
- locMediaType.formattype = FORMAT_WaveFormatEx;
- locMediaType.cbFormat = sizeof(WAVEFORMATEX);
- locMediaType.pbFormat = NULL; //(BYTE*)mCMMLFormatBlock; //(BYTE*)locSpeexFormatInfo;
- locMediaType.pUnk = NULL;
- *outMediaType = locMediaType;
+ outMediaType->majortype = MEDIATYPE_Audio;
+ outMediaType->subtype = MEDIASUBTYPE_PCM;
+ outMediaType->formattype = FORMAT_WaveFormatEx;
+ outMediaType->cbFormat = sizeof(WAVEFORMATEX);
+
+ WAVEFORMATEX* locFormat = (WAVEFORMATEX*)outMediaType->AllocFormatBuffer(sizeof(WAVEFORMATEX));
+ locFormat->wFormatTag = WAVE_FORMAT_PCM;
+
+ locFormat->nChannels = mParentFilter->mNumChannels;
+ locFormat->nSamplesPerSec = mParentFilter->mSampleRate;
+ locFormat->wBitsPerSample = mParentFilter->mBitsPerSample;
+ locFormat->nBlockAlign = (mParentFilter->mNumChannels) * (mParentFilter->mBitsPerSample >> 3);
+ locFormat->nAvgBytesPerSec = ((mParentFilter->mNumChannels) * (mParentFilter->mBitsPerSample >> 3)) * mParentFilter->mSampleRate;
+ locFormat->cbSize = 0;
+
+
return S_OK;
} else {
return VFW_S_NO_MORE_ITEMS;
@@ -147,4 +158,60 @@
}
+HRESULT NativeFLACSourcePin::deliverData(unsigned char* inBuff, unsigned long inBuffSize, __int64 inStart, __int64 inEnd) {
+ //Locks !!
+
+ IMediaSample* locSample = NULL;
+ REFERENCE_TIME locStart = inStart;
+ REFERENCE_TIME locStop = inEnd;
+ //debugLog<<"Start : "<<locStart<<endl;
+ //debugLog<<"End : "<<locStop<<endl;
+ DbgLog((LOG_TRACE, 2, "Getting Buffer in Source Pin..."));
+ HRESULT locHR = GetDeliveryBuffer(&locSample, &locStart, &locStop, NULL);
+ DbgLog((LOG_TRACE, 2, "* After get Buffer in Source Pin..."));
+ //Error checks
+ if (locHR != S_OK) {
+ //Stopping, fluching or error
+ //debugLog<<"Failure... No buffer"<<endl;
+ return locHR;
+ }
+ //More hacks so we can send a timebase after a seek, since granule pos in theora
+ // is not convertible in both directions to time.
+
+ //TIMESTAMP FIXING !
+ locSample->SetTime(&locStart, &locStop);
+
+ //Yes this is way dodgy !
+ //locSample->SetMediaTime(&mParentFilter->mSeekTimeBase, &mParentFilter->mSeekTimeBase);
+ locSample->SetSyncPoint(TRUE);
+
+
+ // Create a pointer for the samples buffer
+ BYTE* locBuffer = NULL;
+ locSample->GetPointer(&locBuffer);
+
+ //DbgLog((LOG_TRACE, 2, "* Packet size is %d"));
+ if (locSample->GetSize() >= inBuffSize) {
+
+ memcpy((void*)locBuffer, (const void*)inBuff, inBuffSize);
+ locSample->SetActualDataLength(inBuffSize);
+
+ locHR = mDataQueue->Receive(locSample);
+
+ //REF_CHECK::: In theory should release here.
+ //The sample has ref_count of 1 by virtue of it's creation... we should release that 1 ref count here.
+
+ if (locHR != S_OK) {
+ //debugLog << "Failure... Queue rejected sample..."<<endl;
+ //Stopping ??
+ return locHR;
+
+ } else {
+ return S_OK;
+ }
+ } else {
+ DbgLog((LOG_TRACE, 2, "* BUFFER TOO SMALL... FATALITY !!"));
+ throw 0;
+ }
+}
Modified: trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourcePin.h
===================================================================
--- trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourcePin.h 2004-10-25 08:22:27 UTC (rev 8088)
+++ trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourcePin.h 2004-10-25 10:03:48 UTC (rev 8089)
@@ -64,9 +64,14 @@
virtual HRESULT DeliverEndOfStream(void);
virtual HRESULT DeliverEndFlush(void);
virtual HRESULT DeliverBeginFlush(void);
+
+ //
+ HRESULT deliverData(unsigned char* inBuff, unsigned long inBuffSize, __int64 inStart, __int64 inEnd);
protected:
//fstream debugLog;
HRESULT mFilterHR;
COutputQueue* mDataQueue;
+
+ NativeFLACSourceFilter* mParentFilter;
};
Modified: trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/dsfNativeFLACSource.h
===================================================================
--- trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/dsfNativeFLACSource.h 2004-10-25 08:22:27 UTC (rev 8088)
+++ trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/dsfNativeFLACSource.h 2004-10-25 10:03:48 UTC (rev 8089)
@@ -43,3 +43,36 @@
+
+
+const REGPINTYPES FLACSourceOutputTypes = {
+ &MEDIATYPE_Audio,
+ &MEDIASUBTYPE_PCM
+};
+
+const REGFILTERPINS FLACSourcePinReg[] = {
+ {
+ L"PCM Output", //Name (obsoleted)
+ FALSE, //Renders from this pin ?? Not sure about this.
+ TRUE, //Is an output pin
+ FALSE, //Cannot have zero instances of this pin
+ FALSE, //Cannot have more than one instance of this pin
+ NULL, //Connects to filter (obsoleted)
+ NULL, //Connects to pin (obsoleted)
+ 1, //Only support one media type
+ &FLACSourceOutputTypes //Pointer to media type (Audio/PCM)
+
+ }
+};
+
+
+
+const REGFILTER2 FLACEncodeFilterReg = {
+ 1,
+ MERIT_DO_NOT_USE,
+ 0,
+ FLACSourcePinReg
+
+};
+
+
Modified: trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/dsfNativeFLACSource.vcproj
===================================================================
--- trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/dsfNativeFLACSource.vcproj 2004-10-25 08:22:27 UTC (rev 8088)
+++ trunk/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/dsfNativeFLACSource.vcproj 2004-10-25 10:03:48 UTC (rev 8089)
@@ -19,7 +19,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
- AdditionalIncludeDirectories=""C:\DXSDK\Samples\C++\DirectShow\BaseClasses";..\..\libs\libflac\include"
+ AdditionalIncludeDirectories=""C:\DXSDK\Samples\C++\DirectShow\BaseClasses";..\..\libs\libflac\include;..\..\..\..\helper\libilliCore"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;DSFNATIVEFLACSOURCE_EXPORTS"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
@@ -37,6 +37,7 @@
OutputFile="$(OutDir)/dsfNativeFLACSource.dll"
LinkIncremental="2"
AdditionalLibraryDirectories=""C:\DXSDK\Samples\C++\DirectShow\BaseClasses\Debug""
+ ModuleDefinitionFile="NativeFLACSource.def"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/dsfNativeFLACSource.pdb"
SubSystem="2"
@@ -71,7 +72,7 @@
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
- AdditionalIncludeDirectories=""C:\DXSDK\Samples\C++\DirectShow\BaseClasses";..\..\libs\libflac\include"
+ AdditionalIncludeDirectories=""C:\DXSDK\Samples\C++\DirectShow\BaseClasses";..\..\libs\libflac\include;..\..\..\..\helper\libilliCore"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSFNATIVEFLACSOURCE_EXPORTS"
RuntimeLibrary="2"
UsePrecompiledHeader="3"
@@ -87,6 +88,7 @@
OutputFile="$(OutDir)/dsfNativeFLACSource.dll"
LinkIncremental="1"
AdditionalLibraryDirectories=""C:\DXSDK\Samples\C++\DirectShow\BaseClasses\Release""
+ ModuleDefinitionFile="NativeFLACSource.def"
GenerateDebugInformation="TRUE"
SubSystem="2"
OptimizeReferences="2"
@@ -126,6 +128,9 @@
RelativePath=".\dsfNativeFLACSource.cpp">
</File>
<File
+ RelativePath=".\NativeFLACSource.def">
+ </File>
+ <File
RelativePath=".\NativeFLACSourceFilter.cpp">
</File>
<File
More information about the commits
mailing list