CMMLStream.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 
00035 #include "stdafx.h"
00036 #include "cmmlstream.h"
00037 
00038 CMMLStream::CMMLStream(OggPage* inBOSPage, OggDemuxSourceFilter* inOwningFilter, bool inAllowSeek)
00039         :       OggStream(inBOSPage, inOwningFilter, inAllowSeek)
00040         ,       mCMMLFormatBlock(NULL)
00041 {
00042         InitCodec(inBOSPage->getStampedPacket(0));
00043         //debugLog.open("G:\\logs\\cmmlstream.log", ios_base::out);
00044 }
00045 
00046 CMMLStream::~CMMLStream(void)
00047 {
00048         delete mCMMLFormatBlock;
00049 }
00050 
00051 bool CMMLStream::AddPin() {
00052         createFormatBlock();
00053         CMediaType* locMediaType = createMediaType(     getMajorTypeGUID(),
00054                                                                                                 getSubtypeGUID(), 
00055                                                                                                 getFormatGUID(), 
00056                                                                                                 getFormatBlockSize(), 
00057                                                                                                 getFormatBlock());
00058 
00059         //LEAK CHECK::: Where does this get deleted ?
00060         OggDemuxSourcePin* locSourcePin = new CMMLSourcePin(    NAME("Ogg Source Pin"), 
00061                                                                                                                                 mOwningFilter, 
00062                                                                                                                                 mOwningFilter->theLock(), 
00063                                                                                                                                 mCodecHeaders, 
00064                                                                                                                                 locMediaType, 
00065                                                                                                                                 getPinName(),
00066                                                                                                                                 getNumBuffers(),
00067                                                                                                                                 getBufferSize());
00068         mStreamReady = true;
00069         mSourcePin = locSourcePin;
00070         
00071         return true;
00072         
00073 }
00074 bool CMMLStream::InitCodec(StampedOggPacket* inOggPacket) {
00075         mCodecHeaders = new StreamHeaders;
00076         mCodecHeaders->mCodecType = StreamHeaders::CMML;
00077         mAnxDataPacket = inOggPacket->clone();
00078         //mCodecHeaders->addPacket((StampedOggPacket*)inOggPacket->clone());
00079         mNumHeadersNeeded = 1;          //TODO::: This should be 1 ???
00080         return true;
00081 }
00082 
00083 BYTE* CMMLStream::getFormatBlock() {
00084 
00085         return (BYTE*)mCMMLFormatBlock;
00086 
00087 }
00088 bool CMMLStream::createFormatBlock() {
00089         //Check where this gets deleted
00090         mCMMLFormatBlock = new sCMMLFormatBlock;
00091         mCMMLFormatBlock->granuleNumerator = iLE_Math::charArrToULong(mAnxDataPacket->packetData() + 8) + ((iLE_Math::charArrToULong(mAnxDataPacket->packetData() + 12)) << 32);
00092         mCMMLFormatBlock->granuleDenominator = iLE_Math::charArrToULong(mAnxDataPacket->packetData() + 16) + ((iLE_Math::charArrToULong(mAnxDataPacket->packetData() + 20)) << 32);
00093 
00094         return true;
00095 }
00096 
00097 void CMMLStream::setLastEndGranPos(__int64 inPos) {
00098         //debugLog<<"CMML Stream Reset : inPos = "<<inPos<<"   --  last end gran = ";
00099         //debugLog<<"gran rate = "<<mCMMLFormatBlock->granuleNumerator<<" / "<<mCMMLFormatBlock->granuleDenominator<<endl;
00100         mLastEndGranulePos = ((inPos * mCMMLFormatBlock->granuleNumerator) / mCMMLFormatBlock->granuleDenominator)/ UNITS;
00101         //debugLog<<mLastEndGranulePos<<endl;
00102         //osDebug<<"Vorbis sets End Gran : "<<mLastEndGranulePos<<endl;
00103 }
00104 unsigned long CMMLStream::getFormatBlockSize() {
00105         return sizeof(sCMMLFormatBlock);
00106 }
00107 GUID CMMLStream::getFormatGUID() {
00108         return FORMAT_CMML;
00109 }
00110 GUID CMMLStream::getSubtypeGUID() {
00111         return MEDIASUBTYPE_CMML;
00112 }
00113 wstring CMMLStream::getPinName() {
00114         wstring retName = L"CMML Out";
00115         return retName;
00116 }
00117 GUID CMMLStream::getMajorTypeGUID() {
00118         return MEDIATYPE_Text;
00119 }
00120 
00121 LONGLONG CMMLStream::getCurrentPos() {
00122         return (mLastEndGranulePos * UNITS * mCMMLFormatBlock->granuleDenominator) / mCMMLFormatBlock->granuleNumerator;
00123 }
00124 
00125 unsigned long CMMLStream::getNumBuffers() {
00126         return CMML_NUM_BUFFERS;
00127 }
00128 unsigned long CMMLStream::getBufferSize() {
00129         return CMML_BUFFER_SIZE;
00130 }

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