OggRawAudioExtractorInputPin.cpp

Go to the documentation of this file.
00001 //===========================================================================
00002 //Copyright (C) 2003, 2004, 2005 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 "OggRawAudioExtractorInputPin.h"
00034 
00035 OggRawAudioExtractorInputPin::OggRawAudioExtractorInputPin(OggRawAudioExtractorFilter* inParentFilter, HRESULT* outHR)
00036         :       CTransformInputPin(NAME("OggAudioExtractorInputPin"), inParentFilter, outHR, L"Ogg Raw Audio In")
00037 
00038         ,       mSetupState(VSS_SEEN_NOTHING)
00039 {
00040 
00041 }
00042 
00043 OggRawAudioExtractorInputPin::~OggRawAudioExtractorInputPin(void)
00044 {
00045 
00046 }
00047 
00048 STDMETHODIMP OggRawAudioExtractorInputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv)
00049 {
00050         if (riid == IID_IMediaSeeking) {
00051                 *ppv = (IMediaSeeking*)this;
00052                 ((IUnknown*)*ppv)->AddRef();
00053                 return NOERROR;
00054         } else if (riid == IID_IOggDecoder) {
00055                 *ppv = (IOggDecoder*)this;
00056                 //((IUnknown*)*ppv)->AddRef();
00057                 return NOERROR;
00058 
00059         }
00060 
00061         return CBaseInputPin::NonDelegatingQueryInterface(riid, ppv); 
00062 }
00063 
00064 HRESULT OggRawAudioExtractorInputPin::SetMediaType(const CMediaType* inMediaType) 
00065 {
00066         //FIX:::Error checking
00067         //RESOLVED::: Bit better.
00068         if (CheckMediaType(inMediaType) == S_OK) {
00069                 //((OGMDecodeFilter*)m_pFilter)->setOGMFormat(inMediaType->pbFormat);
00070                 
00071         } else {
00072                 throw 0;
00073         }
00074         return CBaseInputPin::SetMediaType(inMediaType);
00075 
00076 }
00077 
00078 HRESULT OggRawAudioExtractorInputPin::CheckMediaType(const CMediaType *inMediaType)
00079 {
00080         if (            (inMediaType->majortype == MEDIATYPE_OggPacketStream)
00081                         &&      (inMediaType->subtype == MEDIASUBTYPE_None)
00082                         &&      (inMediaType->formattype == FORMAT_OggIdentHeader)) {
00083                 if (inMediaType->cbFormat == OGG_RAW_AUDIO_IDENT_HEADER_SIZE) {
00084                         if (strncmp((char*)inMediaType->pbFormat, "PCM     ", 8) == 0) {
00085                                 //TODO::: Possibly verify version
00086                                 return S_OK;
00087                         }
00088                 }
00089         }
00090         return S_FALSE;
00091         
00092 }
00093 HRESULT OggRawAudioExtractorInputPin::GetAllocatorRequirements(ALLOCATOR_PROPERTIES *outRequestedProps)
00094 {
00095         outRequestedProps->cbBuffer = 65536;
00096         outRequestedProps->cBuffers = OGG_RAW_AUDIO_NUM_BUFFERS;
00097         outRequestedProps->cbAlign = 1;
00098         outRequestedProps->cbPrefix = 0;
00099 
00100         return S_OK;
00101 }
00102 LOOG_INT64 OggRawAudioExtractorInputPin::convertGranuleToTime(LOOG_INT64 inGranule)
00103 {
00104         return (inGranule * UNITS) / mFormatBlock.samplesPerSec;
00105 }
00106 
00107 LOOG_INT64 OggRawAudioExtractorInputPin::mustSeekBefore(LOOG_INT64 inGranule)
00108 {
00109         //TODO::: Get adjustment from block size info... for now, it doesn't matter if no preroll
00110         return inGranule;
00111 }
00112 IOggDecoder::eAcceptHeaderResult OggRawAudioExtractorInputPin::showHeaderPacket(OggPacket* inCodecHeaderPacket)
00113 {
00114         switch (mSetupState) {
00115                 case VSS_SEEN_NOTHING:
00116                         if (strncmp((char*)inCodecHeaderPacket->packetData(), "PCM     ", 8) == 0) {
00117                                 handleHeaderPacket(inCodecHeaderPacket);
00118                                 mSetupState = VSS_SEEN_BOS;
00119                                 return IOggDecoder::AHR_MORE_HEADERS_TO_COME;
00120                         }
00121                         mSetupState = VSS_ERROR;
00122                         return IOggDecoder::AHR_INVALID_HEADER;
00123                         
00124                 case VSS_SEEN_BOS:
00125                         //TODO::: Handle extra headers
00126                         mSetupState = VSS_ALL_HEADERS_SEEN;
00127                         return IOggDecoder::AHR_ALL_HEADERS_RECEIVED;
00128                         
00129                         //return IOggDecoder::AHR_INVALID_HEADER;
00130                 
00131         
00132                 case VSS_ALL_HEADERS_SEEN:
00133                 case VSS_ERROR:
00134                 default:
00135                         return IOggDecoder::AHR_UNEXPECTED;
00136         }
00137 }
00138 
00139 
00140 
00141 bool OggRawAudioExtractorInputPin::handleHeaderPacket(OggPacket* inHeaderPack)
00142 {
00143         
00144         //mVideoFormatBlock = new VIDEOINFOHEADER;
00145 
00146         mFormatBlock.samplesPerSec = iBE_Math::charArrToULong(inHeaderPack->packetData() + 16);
00147         mFormatBlock.maxFramesPerPacket = iBE_Math::charArrToULong(inHeaderPack->packetData() + 22) >> 16;
00148         mFormatBlock.numChannels = inHeaderPack->packetData()[21];
00149         mFormatBlock.numHeaders = iBE_Math::charArrToULong(inHeaderPack->packetData() + 24);
00150         
00151         switch(iBE_Math::charArrToULong(inHeaderPack->packetData() + 12)) {
00152                 case FMT_S8:
00153                 case FMT_U8:
00154                         mFormatBlock.bitsPerSample = 8;
00155                         break;
00156                 case FMT_S16_LE:
00157                 case FMT_S16_BE:
00158                         mFormatBlock.bitsPerSample = 16;
00159                         break;
00160 
00161                 default:
00162                         throw 0;
00163 
00164                 //case FMT_S24_LE,
00165                 //case FMT_S24_BE,
00166                 //case FMT_S32_LE,
00167                 //case FMT_S32_BE,
00168 
00169                 //case FMT_ULAW         =       0x10,
00170                 //case FMT_ALAW,
00171 
00172                 //case FMT_FLT32_LE     =       0x20,
00173                 //case FMT_FLT32_BE,
00174                 //case FMT_FLT64_LE,
00175                 //case FMT_FLT64_BE,
00176                 
00177         }
00178         
00179         
00180 
00181         return true;
00182 }
00183 string OggRawAudioExtractorInputPin::getCodecShortName()
00184 {
00185         return "Ogg Raw Audio";
00186 }
00187 string OggRawAudioExtractorInputPin::getCodecIdentString()
00188 {
00189         //TODO:::
00190         return "Ogg Raw Audio";
00191 }
00192 

Generated on Thu Feb 16 23:48:08 2006 for oggdsf by  doxygen 1.3.9