AnxMuxInputPin.cpp

Go to the documentation of this file.
00001 //===========================================================================
00002 //Copyright (C) 2003, 2004 Zentaro Kavanagh
00003 //
00004 //Copyright (C) 2003, 2004 Commonwealth Scientific and Industrial Research
00005 //   Organisation (CSIRO) Australia
00006 //
00007 //Redistribution and use in source and binary forms, with or without
00008 //modification, are permitted provided that the following conditions
00009 //are met:
00010 //
00011 //- Redistributions of source code must retain the above copyright
00012 //  notice, this list of conditions and the following disclaimer.
00013 //
00014 //- Redistributions in binary form must reproduce the above copyright
00015 //  notice, this list of conditions and the following disclaimer in the
00016 //  documentation and/or other materials provided with the distribution.
00017 //
00018 //- Neither the name of Zentaro Kavanagh nor the names of contributors 
00019 //  may be used to endorse or promote products derived from this software 
00020 //  without specific prior written permission.
00021 //
00022 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 //``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00025 //PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
00026 //CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00027 //EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00028 //PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00029 //PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00030 //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031 //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 //===========================================================================
00034 #include "stdafx.h"
00035 #include ".\anxmuxinputpin.h"
00036 #include "AnxMuxFilter.h"
00037 AnxMuxInputPin::AnxMuxInputPin(AnxMuxFilter* inOwningFilter, CCritSec* inFilterLock, HRESULT* inHR, OggMuxStream* inMuxStream, unsigned long inAnxVersionMajor, unsigned long inAnxVersionMinor)
00038         :       OggMuxInputPin(inOwningFilter, inFilterLock, inHR, inMuxStream)
00039         ,       mAnxDataPacket(NULL)
00040         ,       mFishBonePacket(NULL)
00041         //,     mExtraPacket(NULL)
00042         ,       mAnxVersionMajor(inAnxVersionMajor)
00043         ,       mAnxVersionMinor(inAnxVersionMinor)
00044 {
00045 #ifdef OGGCODECS_LOGGING
00046         debugLog.open("g:\\logs\\anxmuxinputpin.log", ios_base::out);
00047 #endif
00048         mExtraPackets.clear();
00049 }
00050 
00051 AnxMuxInputPin::~AnxMuxInputPin(void)
00052 {
00053 }
00054 
00055 
00056 HRESULT AnxMuxInputPin::CompleteConnect(IPin* inReceivePin) {
00057         
00058         //Set our delegate to the pin that is connecting to us... we'll send them our seek messages.
00059         IMediaSeeking* locSeeker = NULL;
00060         inReceivePin->QueryInterface(IID_IMediaSeeking, (void**)&locSeeker);
00061         SetDelegate(locSeeker);
00062         
00063         mMuxStream->setIsActive(true);
00064 
00065         HRESULT locHR = mParentFilter->addAnotherPin();
00066         if ((locHR == S_OK)) {// && (mAnxDataPacket != NULL)) {
00067                 //ANX3::: Only do this for anx2... in anx 3 we need to get the fishbone some other way.
00068                 if ((mAnxVersionMajor == 2) && (mAnxVersionMinor == 0) && (mAnxDataPacket != NULL)) {
00069                         mPaginator.acceptStampedOggPacket(mAnxDataPacket);
00070                         return S_OK;
00071                 } else if ((mAnxVersionMajor == 3) && (mAnxVersionMinor == 0) && (mFishBonePacket != NULL)) {
00072                         //Force in a CMML Packet BOS
00073                         if (mExtraPackets.size() != 0) {
00074                                 for (size_t i = 0; i < mExtraPackets.size(); i++) {
00075                                         mPaginator.acceptStampedOggPacket(mExtraPackets[i]);
00076                                 }
00077                         }
00078                         return S_OK;
00079                 } else {
00080                         return S_FALSE;
00081                 }
00082                 
00083         } else {
00084                 return S_FALSE;
00085         }
00086 }
00087 
00088 
00089 HRESULT AnxMuxInputPin::SetMediaType(const CMediaType* inMediaType) 
00090 {
00091 
00092         bool locWasOK = false;
00093         unsigned __int64 locGranRateNum = 0;
00094         unsigned __int64 locGranRateDenom = 0;
00095         unsigned long locNumHeaders = 0;
00096         unsigned long locPreroll = 0;
00097         unsigned long locGranuleShift = 0;
00098         StreamHeaders::eCodecType locCodecID = StreamHeaders::NONE;
00099 
00100         
00101         if ((inMediaType->majortype == MEDIATYPE_Video) && (inMediaType->subtype == MEDIASUBTYPE_Theora)) {
00102                 //Theora
00103                 
00104                 sTheoraFormatBlock* locTheora = (sTheoraFormatBlock*)inMediaType->pbFormat;
00105                 //debugLog<<"Theo sample rate = "<<locTheora->frameRateNumerator<<" / "<<locTheora->frameRateDenominator<<endl;
00106                 //debugLog<<"Theo KFI = "<<locTheora->maxKeyframeInterval<<endl;
00107                 mMuxStream->setConversionParams(locTheora->frameRateNumerator, locTheora->frameRateDenominator, 10000000, locTheora->maxKeyframeInterval);
00108                 mMuxStream->setNumHeaders(3);
00109                 mPaginator.setNumHeaders(3);
00110 
00111                 locGranuleShift = locTheora->maxKeyframeInterval;
00112                 locWasOK = true;
00113                 locGranRateNum = locTheora->frameRateNumerator;
00114                 locGranRateDenom = locTheora->frameRateDenominator;
00115                 locNumHeaders = 3;
00116                 locCodecID = StreamHeaders::THEORA;
00117 
00118         } else if (inMediaType->majortype == MEDIATYPE_Audio) {
00119                 if (inMediaType->subtype == MEDIASUBTYPE_Vorbis) {
00120                         //Vorbis
00121                         sVorbisFormatBlock* locVorbis = (sVorbisFormatBlock*)inMediaType->pbFormat;
00122                         //debugLog<<"Vorbis sample rate = "<<locVorbis->samplesPerSec<<endl;
00123                         mMuxStream->setConversionParams(locVorbis->samplesPerSec, 1, 10000000);
00124                         mMuxStream->setNumHeaders(3);
00125                         mPaginator.setNumHeaders(3);
00126 
00127                         locWasOK = true;
00128                         locGranRateNum = locVorbis->samplesPerSec;
00129                         locGranRateDenom = 1;
00130                         locNumHeaders = 3;
00131                         locPreroll = 2;
00132 
00133                         locCodecID = StreamHeaders::VORBIS;
00134 
00135                         
00136                 } else if (inMediaType->subtype == MEDIASUBTYPE_Speex) {
00137                         //Speex
00138                         sSpeexFormatBlock* locSpeex = (sSpeexFormatBlock*)inMediaType->pbFormat;
00139                         mMuxStream->setConversionParams(locSpeex->samplesPerSec, 1, 10000000);
00140                         mMuxStream->setNumHeaders(2);
00141                         mPaginator.setNumHeaders(2);
00142 
00143 
00144                         locWasOK = true;
00145                         locGranRateNum = locSpeex->samplesPerSec;
00146                         locGranRateDenom = 1;
00147                         locNumHeaders = 2;
00148                         locCodecID = StreamHeaders::SPEEX;
00149                 }
00150 
00151                 //TODO::: Add a num headers field to the flac format block.
00152 
00153                 //} else if (inMediaType->subtype == MEDIASUBTYPE_OggFLAC_1_0) {
00154                 //      //We are connected to the encoder nd getting individual metadata packets.
00155                 //      sFLACFormatBlock* locFLAC = (sFLACFormatBlock*)inMediaType->pbFormat;
00156                 //      mMuxStream->setConversionParams(locFLAC->samplesPerSec, 1, 10000000);
00157                 //      //debugLog<<"FLAC sample rate = "<<locFLAC->samplesPerSec<<endl;
00158                 //      //mNeedsFLACHeaderTweak = true;
00159                 //      mNeedsFLACHeaderCount = true;
00160                 //} else if (inMediaType->subtype == MEDIASUBTYPE_FLAC) {
00161                 //      //We are connected directly to the demux and are getting metadata in one block
00162                 //      // Need to use the header splitter class.
00163                 //      sFLACFormatBlock* locFLAC = (sFLACFormatBlock*)inMediaType->pbFormat;
00164                 //      mMuxStream->setConversionParams(locFLAC->samplesPerSec, 1, 10000000);
00165                 //      //debugLog<<"FLAC sample rate = "<<locFLAC->samplesPerSec<<endl;
00166                 //      mNeedsFLACHeaderTweak = true;
00167                 //} 
00168 
00169                 
00170         } else if(inMediaType->majortype == MEDIATYPE_Text) {
00171                 if (inMediaType->subtype == MEDIASUBTYPE_CMML) {
00172                         //CMML
00173                         sCMMLFormatBlock* locCMML = (sCMMLFormatBlock*)inMediaType->pbFormat;
00174                         
00175 
00176 
00177                         //ANX3::: 1 for anx 2, 2 for anx 3.
00178                         if ((mAnxVersionMajor == 3) && (mAnxVersionMinor == 0)) {
00179                                 mMuxStream->setConversionParams(locCMML->granuleNumerator, locCMML->granuleDenominator, 10000000, 5);
00180                                 //ZZZZZ:::: sould be 3
00181                                 locNumHeaders = 3;
00182                         } else {
00183                                 mMuxStream->setConversionParams(locCMML->granuleNumerator, locCMML->granuleDenominator, 10000000);
00184                                 locNumHeaders = 1;
00185                         }
00186 
00187                         mPaginator.setNumHeaders(locNumHeaders);
00188                         mPaginator.parameters()->mMaxPacksPerPage = 1;
00189                         mMuxStream->setNumHeaders(locNumHeaders);
00190 
00191 
00192                         locWasOK = true;
00193                         locGranRateNum = locCMML->granuleNumerator;
00194                         locGranRateDenom = locCMML->granuleDenominator;
00195 
00196 
00197                         locCodecID = StreamHeaders::CMML;                       
00198                 }
00199         }
00200         if (locWasOK) {
00201                 //ANX3::: Need to make our fishbone here.
00202                 
00203                 
00204                 if ((mAnxVersionMajor == 2) && (mAnxVersionMinor == 0)) {
00205                         //Save the packet, we'll push it into the stream when the connection is established
00206                         mAnxDataPacket = AnxPacketMaker::makeAnxData_2_0(2, 0, locGranRateNum, locGranRateDenom, locNumHeaders, AnxPacketMaker::makeMessageHeaders(locCodecID));
00207                 } else if ((mAnxVersionMajor == 3) && (mAnxVersionMinor == 0)) {
00208                         mFishBonePacket = FishSkeleton::makeFishBone_3_0(locGranRateNum, locGranRateDenom, 0, locNumHeaders, mPaginator.parameters()->mSerialNo, locGranuleShift, locPreroll, AnxPacketMaker::makeMessageHeaders(locCodecID));
00209                         if (locCodecID == StreamHeaders::CMML) {
00210                                 mExtraPackets.push_back(FishSkeleton::makeCMMLBOS());
00211                                 mExtraPackets.push_back(FishSkeleton::makeCMML_XML_Thing());
00212                         } else {
00213                                 mExtraPackets.clear();
00214                                 //mExtraPacket = NULL;
00215                         }
00216                 }
00217         return S_OK;
00218         } else {
00219                 return S_FALSE;
00220         }
00221 }

Generated on Tue Feb 15 14:54:18 2005 for oggdsf by  doxygen 1.3.9