TheoraDecodeInputPin.cpp

Go to the documentation of this file.
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 "theoradecodeinputpin.h"
00034 
00035 
00036 TheoraDecodeInputPin::TheoraDecodeInputPin(CTransformFilter* inParentFilter, HRESULT* outHR) 
00037         :       CTransformInputPin(NAME("Theora Input Pin"), inParentFilter, outHR, L"Theora In")
00038         ,       mSetupState(VSS_SEEN_NOTHING)
00039         ,       mOggOutputPinInterface(NULL)
00040         ,       mSentStreamOffset(false)
00041 {
00042         //debugLog.open("G:\\logs\\theoinput.log", ios_base::out);
00043 }
00044 TheoraDecodeInputPin::~TheoraDecodeInputPin() {
00045         //debugLog.close();
00046 }
00047 
00048 STDMETHODIMP TheoraDecodeInputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv) 
00049 {
00050 
00051 
00052 
00053         if (riid == IID_IMediaSeeking) {
00054                 //debugLog<<"Got Seeker"<<endl;
00055                 *ppv = (IMediaSeeking*)this;
00056                 ((IUnknown*)*ppv)->AddRef();
00057                 
00058                 return NOERROR;
00059         } else if (riid == IID_IOggDecoder) {
00060                 *ppv = (IOggDecoder*)this;
00061                 //((IUnknown*)*ppv)->AddRef();
00062                 return NOERROR;
00063 
00064         }
00065 
00066         return CBaseInputPin::NonDelegatingQueryInterface(riid, ppv); 
00067 }
00068 HRESULT TheoraDecodeInputPin::GetAllocatorRequirements(ALLOCATOR_PROPERTIES *outRequestedProps)
00069 {
00070         TheoraDecodeFilter* locParent = (TheoraDecodeFilter*)m_pFilter;
00071         unsigned long locBuffSize = ((unsigned long)locParent->mTheoraFormatInfo->outerFrameHeight * (unsigned long)locParent->mTheoraFormatInfo->outerFrameWidth * 3) >> 3;
00072         if (locBuffSize < 65536) {
00073                 locBuffSize = 65536;
00074         }
00075         outRequestedProps->cbBuffer =  locBuffSize;
00076         outRequestedProps->cBuffers = THEORA_NUM_BUFFERS;
00077         outRequestedProps->cbAlign = 1;
00078         outRequestedProps->cbPrefix = 0;
00079 
00080         return S_OK;
00081 }
00082 HRESULT TheoraDecodeInputPin::BreakConnect() {
00083         CAutoLock locLock(m_pLock);
00084         //debugLog<<"Break conenct"<<endl;
00085         //Need a lock ??
00086         ReleaseDelegate();
00087         return CTransformInputPin::BreakConnect();
00088 }
00089 HRESULT TheoraDecodeInputPin::CompleteConnect (IPin *inReceivePin) {
00090         CAutoLock locLock(m_pLock);
00091 
00092         //Offsets
00093         IOggOutputPin* locOggOutput = NULL;
00094         mSentStreamOffset = false;
00095         HRESULT locHR = inReceivePin->QueryInterface(IID_IOggOutputPin, (void**)&locOggOutput);
00096         if (locHR == S_OK) {
00097                 mOggOutputPinInterface = locOggOutput;
00098                 
00099         } else {
00100                 mOggOutputPinInterface = NULL;
00101         }
00102 
00103 
00104         //debugLog<<"Complete conenct"<<endl;
00105         IMediaSeeking* locSeeker = NULL;
00106         inReceivePin->QueryInterface(IID_IMediaSeeking, (void**)&locSeeker);
00107         if (locSeeker == NULL) {
00108                 //debugLog<<"Seeker is null"<<endl;
00109         }
00110         SetDelegate(locSeeker);
00111         return CTransformInputPin::CompleteConnect(inReceivePin);
00112 }
00113 
00114 LOOG_INT64 TheoraDecodeInputPin::convertGranuleToTime(LOOG_INT64 inGranule)
00115 {
00116         //if (mBegun) { 
00117         //      return (inGranule * UNITS) / mSampleRate;
00118         //} else {
00119         //      return -1;
00120         //}
00121         TheoraDecodeFilter* locParent = (TheoraDecodeFilter*)m_pFilter;
00122 
00123 
00124         LOOG_INT64 locMod = ((LOOG_INT64)1)<<locParent->getTheoraFormatBlock()->maxKeyframeInterval; //(unsigned long)pow((double) 2, (double) mGranulePosShift);
00125         LOOG_INT64 locInterFrameNo = (LOOG_INT64) ( inGranule % locMod );
00126                         
00127 
00128         //LOOG_INT64 retTime ((((inGranule >> locParent->getTheoraFormatBlock()->maxKeyframeInterval) + locInterFrameNo) * UNITS) * locParent->getTheoraFormatBlock()->frameRateDenominator) / locParent->getTheoraFormatBlock()->frameRateNumerator;
00129 
00130         LOOG_INT64 retTime = inGranule >> locParent->getTheoraFormatBlock()->maxKeyframeInterval;
00131         retTime += locInterFrameNo + 1;
00132         retTime *= UNITS;
00133         retTime *= locParent->getTheoraFormatBlock()->frameRateDenominator;
00134         retTime /= locParent->getTheoraFormatBlock()->frameRateNumerator;
00135         return retTime;
00136 
00137 }
00138 
00139 LOOG_INT64 TheoraDecodeInputPin::mustSeekBefore(LOOG_INT64 inGranule)
00140 {
00141         TheoraDecodeFilter* locParent = (TheoraDecodeFilter*)m_pFilter;
00142         LOOG_INT64 locShift = locParent->getTheoraFormatBlock()->maxKeyframeInterval;
00143         return (inGranule >> locShift) << locShift;
00144 }
00145 IOggDecoder::eAcceptHeaderResult TheoraDecodeInputPin::showHeaderPacket(OggPacket* inCodecHeaderPacket)
00146 {
00147         unsigned char* locPacketData = new unsigned char[inCodecHeaderPacket->packetSize()];
00148         memcpy((void*)locPacketData, (const void**)inCodecHeaderPacket->packetData(), inCodecHeaderPacket->packetSize());
00149         StampedOggPacket* locStamped = new StampedOggPacket(locPacketData, inCodecHeaderPacket->packetSize(), false, false, 0,0, StampedOggPacket::NONE);
00150 
00151         TheoraDecodeFilter* locParent = (TheoraDecodeFilter*)m_pFilter;
00152 
00153         IOggDecoder::eAcceptHeaderResult retResult = IOggDecoder::AHR_INVALID_HEADER;
00154         switch (mSetupState) {
00155                 case VSS_SEEN_NOTHING:
00156                         if (strncmp((char*)inCodecHeaderPacket->packetData(), "\200theora", 7) == 0) {
00157                                 //TODO::: Possibly verify version
00158                                 if (locParent->mTheoraDecoder->decodeTheora(locStamped) == NULL) {
00159                                         mSetupState = VSS_SEEN_BOS;
00160                                         retResult = IOggDecoder::AHR_MORE_HEADERS_TO_COME;
00161                                 }
00162                         }
00163                         //return IOggDecoder::AHR_INVALID_HEADER;
00164                         break;
00165                         
00166                         
00167                 case VSS_SEEN_BOS:
00168                         if (strncmp((char*)inCodecHeaderPacket->packetData(), "\201theora", 7) == 0) {
00169                                 if (locParent->mTheoraDecoder->decodeTheora(locStamped) == NULL) {
00170                                         mSetupState = VSS_SEEN_COMMENT;
00171                                         retResult = IOggDecoder::AHR_MORE_HEADERS_TO_COME;
00172                                 }
00173                                 
00174                                 
00175                         }
00176                         //return IOggDecoder::AHR_INVALID_HEADER;
00177                         break;
00178                         
00179                         
00180                 case VSS_SEEN_COMMENT:
00181                         if (strncmp((char*)inCodecHeaderPacket->packetData(), "\202theora", 7) == 0) {
00182                                 if (locParent->mTheoraDecoder->decodeTheora(locStamped) == NULL) {
00183                 
00184                                         //fish_sound_command (mFishSound, FISH_SOUND_GET_INFO, &(mFishInfo), sizeof (FishSoundInfo)); 
00185                                         //Is mBegun useful ?
00186                                         //mBegun = true;
00187                         
00188                                         //mNumChannels = mFishInfo.channels;
00189                                         //mFrameSize = mNumChannels * SIZE_16_BITS;
00190                                         //mSampleRate = mFishInfo.samplerate;
00191 
00192                 
00193                                         mSetupState = VSS_ALL_HEADERS_SEEN;
00194                                         retResult = IOggDecoder::AHR_ALL_HEADERS_RECEIVED;
00195                                 }
00196                                 
00197                         }
00198                         //return IOggDecoder::AHR_INVALID_HEADER;
00199                         break;
00200                         
00201                 case VSS_ALL_HEADERS_SEEN:
00202                 case VSS_ERROR:
00203                 default:
00204                         delete locStamped;
00205                         retResult = IOggDecoder::AHR_UNEXPECTED;
00206         }
00207         
00208         return retResult;
00209 }
00210 string TheoraDecodeInputPin::getCodecShortName()
00211 {
00212         return "theora";
00213 }
00214 string TheoraDecodeInputPin::getCodecIdentString()
00215 {
00216         //TODO:::
00217         return "theora";
00218 }

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