00001 //=========================================================================== 00002 //Copyright (C) 2003, 2004 Zentaro Kavanagh 00003 // 00004 //Redistribution and use in source and binary forms, with or without 00005 //modification, are permitted provided that the following conditions 00006 //are met: 00007 // 00008 //- Redistributions of source code must retain the above copyright 00009 // notice, this list of conditions and the following disclaimer. 00010 // 00011 //- Redistributions in binary form must reproduce the above copyright 00012 // notice, this list of conditions and the following disclaimer in the 00013 // documentation and/or other materials provided with the distribution. 00014 // 00015 //- Neither the name of Zentaro Kavanagh nor the names of contributors 00016 // may be used to endorse or promote products derived from this software 00017 // without specific prior written permission. 00018 // 00019 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 //``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00022 //PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR 00023 //CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00024 //EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00025 //PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00026 //PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00027 //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00028 //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 //=========================================================================== 00031 00032 #include "stdafx.h" 00033 #include "vorbisdecodefilter.h" 00034 00035 //Include Files 00036 #include "stdafx.h" 00037 #include "VorbisDecodeFilter.h" 00038 00039 //COM Factory Template 00040 CFactoryTemplate g_Templates[] = 00041 { 00042 { 00043 L"Vorbis Decode Filter", // Name 00044 &CLSID_VorbisDecodeFilter, // CLSID 00045 VorbisDecodeFilter::CreateInstance, // Method to create an instance of MyComponent 00046 NULL, // Initialization function 00047 NULL // Set-up information (for filters) 00048 } 00049 00050 }; 00051 00052 // Generic way of determining the number of items in the template 00053 int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]); 00054 00055 00056 00057 //************************************************************************************************* 00058 VorbisDecodeFilter::VorbisDecodeFilter() 00059 : AbstractTransformFilter(NAME("Vorbis Decoder"), CLSID_VorbisDecodeFilter) 00060 , mVorbisFormatInfo(NULL) 00061 { 00062 00063 bool locWasConstructed = ConstructPins(); 00064 //TODO::: Error check ! 00065 } 00066 00067 bool VorbisDecodeFilter::ConstructPins() 00068 { 00069 //Vector to hold our set of media types we want to accept. 00070 vector<CMediaType*> locAcceptableTypes; 00071 00072 //Setup the media types for the output pin. 00073 CMediaType* locAcceptMediaType = new CMediaType(&MEDIATYPE_Audio); //Deleted in pin destructor 00074 locAcceptMediaType->subtype = MEDIASUBTYPE_PCM; 00075 locAcceptMediaType->formattype = FORMAT_WaveFormatEx; 00076 00077 locAcceptableTypes.push_back(locAcceptMediaType); 00078 00079 //Output pin must be done first because it's passed to the input pin. 00080 mOutputPin = new VorbisDecodeOutputPin(this, m_pLock, locAcceptableTypes); //Deleted in base class destructor 00081 00082 //Clear out the vector, now we've already passed it to the output pin. 00083 locAcceptableTypes.clear(); 00084 00085 //Setup the media Types for the input pin. 00086 locAcceptMediaType = NULL; 00087 locAcceptMediaType = new CMediaType(&MEDIATYPE_Audio); //Deleted by pin 00088 00089 locAcceptMediaType->subtype = MEDIASUBTYPE_Vorbis; 00090 locAcceptMediaType->formattype = FORMAT_Vorbis; 00091 00092 locAcceptableTypes.push_back(locAcceptMediaType); 00093 00094 mInputPin = new VorbisDecodeInputPin(this, m_pLock, mOutputPin, locAcceptableTypes); //Deleted in base class filter destructor. 00095 return true; 00096 } 00097 00098 VorbisDecodeFilter::~VorbisDecodeFilter(void) 00099 { 00100 DbgLog((LOG_TRACE,1,TEXT("Vorbis Destructor..."))); 00101 //DestroyPins(); 00102 delete mVorbisFormatInfo; 00103 } 00104 00105 CUnknown* WINAPI VorbisDecodeFilter::CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr) 00106 { 00107 00108 VorbisDecodeFilter *pNewObject = new VorbisDecodeFilter(); 00109 if (pNewObject == NULL) { 00110 *pHr = E_OUTOFMEMORY; 00111 } 00112 return pNewObject; 00113 } 00114 00115 //QUERY::: Do we need these ? Aren't we all friedns here ?? 00116 //RESULT::: Keep them, set function must be kept... get could go... but keep for consistency 00117 sVorbisFormatBlock* VorbisDecodeFilter::getVorbisFormatBlock() 00118 { 00119 return mVorbisFormatInfo; 00120 } 00121 void VorbisDecodeFilter::setVorbisFormat(sVorbisFormatBlock* inFormatBlock) 00122 { 00123 delete mVorbisFormatInfo; 00124 mVorbisFormatInfo = new sVorbisFormatBlock; //Deleted in destructor. 00125 *mVorbisFormatInfo = *inFormatBlock; 00126 } 00127 00128 //Old imp 00129 //****************************************************************** 00130 //#include "stdafx.h" 00131 //#include "vorbisdecodefilter.h" 00132 // 00134 //#include "stdafx.h" 00135 //#include "VorbisDecodeFilter.h" 00136 // 00138 //CFactoryTemplate g_Templates[] = 00139 //{ 00140 // { 00141 // L"Vorbis Decode Filter", // Name 00142 // &CLSID_VorbisDecodeFilter, // CLSID 00143 // VorbisDecodeFilter::CreateInstance, // Method to create an instance of MyComponent 00144 // NULL, // Initialization function 00145 // NULL // Set-up information (for filters) 00146 // } 00147 // 00148 //}; 00149 // 00151 //int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]); 00152 // 00153 // 00154 // 00156 //VorbisDecodeFilter::VorbisDecodeFilter() 00157 // : AbstractAudioDecodeFilter(NAME("Vorbis Decoder"), CLSID_VorbisDecodeFilter, VORBIS) 00158 // , mVorbisFormatInfo(NULL) 00159 //{ 00160 // 00161 // bool locWasConstructed = ConstructPins(); 00162 //} 00163 // 00164 //bool VorbisDecodeFilter::ConstructPins() 00165 //{ 00166 // DbgLog((LOG_TRACE,1,TEXT("Vorbis Constructor..."))); 00167 // //Output pin must be done first because it's passed to the input pin. 00168 // mOutputPin = new VorbisDecodeOutputPin(this, m_pLock); //Deleted in base class destructor 00169 // 00170 // CMediaType* locAcceptMediaType = new CMediaType(&MEDIATYPE_Audio); //Deleted in pin destructor 00171 // locAcceptMediaType->subtype = MEDIASUBTYPE_Vorbis; 00172 // locAcceptMediaType->formattype = FORMAT_Vorbis; 00173 // mInputPin = new VorbisDecodeInputPin(this, m_pLock, mOutputPin, locAcceptMediaType); //Deleted in base class filter destructor. 00174 // return true; 00175 //} 00176 // 00177 //VorbisDecodeFilter::~VorbisDecodeFilter(void) 00178 //{ 00179 // DbgLog((LOG_TRACE,1,TEXT("Vorbis Destructor..."))); 00180 // //DestroyPins(); 00181 // delete mVorbisFormatInfo; 00182 //} 00183 // 00184 //CUnknown* WINAPI VorbisDecodeFilter::CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr) 00185 //{ 00186 // 00187 // VorbisDecodeFilter *pNewObject = new VorbisDecodeFilter(); 00188 // if (pNewObject == NULL) { 00189 // *pHr = E_OUTOFMEMORY; 00190 // } 00191 // return pNewObject; 00192 //} 00193 // 00196 //sVorbisFormatBlock* VorbisDecodeFilter::getVorbisFormatBlock() 00197 //{ 00198 // return mVorbisFormatInfo; 00199 //} 00200 //void VorbisDecodeFilter::setVorbisFormat(sVorbisFormatBlock* inFormatBlock) 00201 //{ 00202 // delete mVorbisFormatInfo; 00203 // mVorbisFormatInfo = new sVorbisFormatBlock; //Deleted in destructor. 00204 // *mVorbisFormatInfo = *inFormatBlock; 00205 //}