00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "stdafx.h"
00033 #include "FLACDecodeFilter.h"
00034
00035
00036
00037 CFactoryTemplate g_Templates[] =
00038 {
00039 {
00040 L"FLAC Decode Filter",
00041 &CLSID_FLACDecodeFilter,
00042 FLACDecodeFilter::CreateInstance,
00043 NULL,
00044 NULL
00045 }
00046
00047 };
00048
00049
00050 int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]);
00051
00052 FLACDecodeFilter::FLACDecodeFilter(void)
00053 : AbstractTransformFilter(NAME("FLAC Audio Decoder"), CLSID_FLACDecodeFilter)
00054 , mFLACFormatBlock(NULL)
00055 {
00056 bool locWasConstructed = ConstructPins();
00057 }
00058
00059 FLACDecodeFilter::~FLACDecodeFilter(void)
00060 {
00061 delete mFLACFormatBlock;
00062 mFLACFormatBlock = NULL;
00063 }
00064
00065 bool FLACDecodeFilter::ConstructPins()
00066 {
00067
00068 vector<CMediaType*> locAcceptableTypes;
00069
00070
00071 CMediaType* locAcceptMediaType = new CMediaType(&MEDIATYPE_Audio);
00072 locAcceptMediaType->subtype = MEDIASUBTYPE_PCM;
00073 locAcceptMediaType->formattype = FORMAT_WaveFormatEx;
00074
00075 locAcceptableTypes.push_back(locAcceptMediaType);
00076
00077
00078 mOutputPin = new FLACDecodeOutputPin(this, m_pLock, locAcceptableTypes);
00079
00080
00081 locAcceptableTypes.clear();
00082
00083
00084 locAcceptMediaType = NULL;
00085 locAcceptMediaType = new CMediaType(&MEDIATYPE_Audio);
00086
00087 locAcceptMediaType->majortype = MEDIATYPE_OggPacketStream;
00088 locAcceptMediaType->subtype = MEDIASUBTYPE_None;
00089 locAcceptMediaType->formattype = FORMAT_OggIdentHeader;
00090
00091 locAcceptableTypes.push_back(locAcceptMediaType);
00092
00093 mInputPin = new FLACDecodeInputPin(this, m_pLock, mOutputPin, locAcceptableTypes);
00094 return true;
00095
00096 }
00097
00098 CUnknown* WINAPI FLACDecodeFilter::CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr)
00099 {
00100
00101 FLACDecodeFilter *pNewObject = new FLACDecodeFilter();
00102 if (pNewObject == NULL) {
00103 *pHr = E_OUTOFMEMORY;
00104 }
00105 return pNewObject;
00106 }
00107
00108 sFLACFormatBlock* FLACDecodeFilter::getFLACFormatBlock()
00109 {
00110 return mFLACFormatBlock;
00111 }
00112 void FLACDecodeFilter::setFLACFormatBlock(BYTE* inFormatBlock)
00113 {
00114 delete mFLACFormatBlock;
00115 mFLACFormatBlock = new sFLACFormatBlock;
00116
00117 const unsigned char FLAC_CHANNEL_MASK = 14;
00118 const unsigned char FLAC_BPS_START_MASK = 1;
00119 const unsigned char FLAC_BPS_END_MASK = 240;
00120 mFLACFormatBlock = new sFLACFormatBlock;
00121
00122
00123
00124
00125
00126 mFLACFormatBlock->numChannels = (((inFormatBlock[20]) & FLAC_CHANNEL_MASK) >> 1) + 1;
00127 mFLACFormatBlock->samplesPerSec = (iBE_Math::charArrToULong(inFormatBlock + 18)) >> 12;
00128
00129 mFLACFormatBlock->numBitsPerSample = (((inFormatBlock[20] & FLAC_BPS_START_MASK) << 4) |
00130 ((inFormatBlock[21] & FLAC_BPS_END_MASK) >> 4)) + 1;
00131
00132
00133
00134 }