AnxPageInterleaver.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 ".\anxpageinterleaver.h"
00036 
00037 AnxPageInterleaver::AnxPageInterleaver(IOggCallback* inFileWriter, INotifyComplete* inNotifier, unsigned long inVersionMajor, unsigned long inVersionMinor, AnxMuxFilter* inParentFilter)
00038         :       OggPageInterleaver(inFileWriter, inNotifier)
00039         ,       mParentFilter(inParentFilter)
00040         ,       mVersionMajor(inVersionMajor)
00041         ,       mVersionMinor(inVersionMinor)
00042         ,       mIsAnxSetup(false)
00043 {
00044         //This is the Annodex Logical Stream
00045         //mInputStreams.push_back(newStream());
00046 
00047         //Just make a random serial number
00048         mAnxSerialNo = 999;
00049 }
00050 
00051 AnxPageInterleaver::~AnxPageInterleaver(void)
00052 {
00053 
00054 }
00055 
00056 void AnxPageInterleaver::addAnnodex_2_0_BOS() {
00057         //Find the CMML data
00058         //TODO::: Need to grab the data from CMML page
00059 
00060         unsigned char* locUTC = new unsigned char[20];
00061         memset((void*)locUTC, 0, 20);
00062 
00063         OggPage* locBOSPage =                   AnxPacketMaker::makeAnnodexBOS_2_0(             mAnxSerialNo
00064                                                                                                                                         ,       2
00065                                                                                                                                         ,       0
00066                                                                                                                                         ,       0
00067                                                                                                                                         ,       0
00068                                                                                                                                         ,       locUTC);
00069 
00070         
00071         //Put the annodex BOS out to the file.
00072         mBytesWritten += locBOSPage->pageSize();
00073         mFileWriter->acceptOggPage(locBOSPage);
00074         delete locUTC;
00075 
00076 }
00077 
00078 void AnxPageInterleaver::addAllAnxData_2_0_BOS() {
00079         OggPage* locOggPage = NULL;
00080         for (size_t i = 0; i < mInputStreams.size() - 1; i++) {
00081                 locOggPage = mInputStreams[i]->popFront();
00082                 mBytesWritten += locOggPage->pageSize();
00083                 mFileWriter->acceptOggPage(locOggPage);
00084                 mInputStreams[i]->setNumHeaders(mInputStreams[i]->numHeaders() + 1);
00085         }
00086 
00087 }
00088 
00089 void AnxPageInterleaver::addAnnodexEOS() {
00090         //Make the EOS page and dump it
00091     
00092         OggPage* locEOSPage = new OggPage;
00093 
00094         locEOSPage->header()->setStreamSerialNo(mAnxSerialNo);
00095         locEOSPage->header()->setHeaderFlags(4);
00096         
00097 
00098         StampedOggPacket* locDudPacket = new StampedOggPacket(NULL, 0, false, false, 0, 0, StampedOggPacket::OGG_BOTH);
00099 
00100         locEOSPage->header()->setNumPageSegments(1);
00101         unsigned char* locSegTable = new unsigned char[1];
00102 
00103         locSegTable[0] = 0;
00104         
00105         
00106         locEOSPage->header()->setSegmentTable(locSegTable, 1);
00107         locEOSPage->header()->setHeaderSize(28);
00108         locEOSPage->header()->setDataSize(0);
00109         
00110         locEOSPage->addPacket(locDudPacket);
00111 
00112         AnxPacketMaker::setChecksum(locEOSPage);
00113         mBytesWritten += locEOSPage->pageSize();
00114         mFileWriter->acceptOggPage(locEOSPage);
00115 }
00116 
00117 //ANX3::: Need to make a new version of this which only returns true, when we actually have *ALL* the
00118 // header for the stream not just the first one.
00119 bool AnxPageInterleaver::gotAllHeaders() {
00120         //TODO::: The isActive needs to be clarified so we don't start empty streams because wasany goes to true
00121 
00122         bool locWasAny = false;
00123         bool locIsOK = true;
00124         for (size_t i = 0; i < mInputStreams.size(); i++) {
00125                 if (mInputStreams[i]->isActive()) {
00126                         
00127                         //if ((mInputStreams[i]->peekFront() != NULL) || (!mInputStreams[i]->isActive())) {
00128                         if (mInputStreams[i]->numAvail() > 1) {
00129                                 locWasAny = true;
00130                                 locIsOK = locIsOK && true;
00131                         } else {
00132                                 locIsOK = false;
00133                         }
00134                 }
00135         }
00136 
00137         return locWasAny && locIsOK;
00138 }
00139 
00140 bool AnxPageInterleaver::gotAllSecondaryHeaders() {
00141         //TODO::: The isActive needs to be clarified so we don't start empty streams because wasany goes to true
00142 
00143         bool locWasAny = false;
00144         bool locIsOK = true;
00145         for (size_t i = 0; i < mInputStreams.size(); i++) {
00146                 if (mInputStreams[i]->isActive()) {
00147                         
00148                         //if ((mInputStreams[i]->peekFront() != NULL) || (!mInputStreams[i]->isActive())) {
00149                         if (mInputStreams[i]->numAvail() >= mInputStreams[i]->numHeaders()) {
00150                                 locWasAny = true;
00151                                 locIsOK = locIsOK && true;
00152                         } else {
00153                                 locIsOK = false;
00154                         }
00155                 }
00156         }
00157 
00158         return locWasAny && locIsOK;
00159 }
00160 
00161 void AnxPageInterleaver::letsGetFishy()
00162 {
00163         
00164         unsigned long locSerialNo = 888;
00165         
00166         //Make the fishhead
00167         unsigned char* locUTC = new unsigned char[20];
00168         memset((void*)locUTC, 0, 20);
00169         OggPage* locFishHead = FishSkeleton::makeFishHeadBOS_3_0(locSerialNo, mVersionMajor, mVersionMinor, 0,0,0,0,locUTC);
00170 
00171         //Write out the fishHead
00172         mFileWriter->acceptOggPage(locFishHead);
00173 
00174         //Write out the BOS pages
00175         for (size_t i = 0; i < mInputStreams.size(); i++) {
00176                 if (mInputStreams[i]->isActive()) {
00177                         mFileWriter->acceptOggPage(mInputStreams[i]->popFront());
00178                 }
00179         }
00180 
00181         //Write out the fishbones.
00182         for (unsigned long i = 0; i < mParentFilter->GetPinCount() - 1; i++) {
00183                 AnxMuxInputPin* locPin = (AnxMuxInputPin*)mParentFilter->GetPin(i);
00184                 OggPage* locFishBonePage = FishSkeleton::makeFishBone_3_0_Page(locPin->mFishBonePacket, locSerialNo);
00185                 mFileWriter->acceptOggPage(locFishBonePage);
00186         }
00187 
00188         //Write out all the secondary headers
00189         for (size_t stream = 0; stream < mInputStreams.size(); stream++) {
00190                 if (mInputStreams[stream]->isActive()) {
00191                         for (unsigned long pack = 1; pack < mInputStreams[stream]->numHeaders(); pack++) {
00192                                 OggPage* locSecHead = mInputStreams[stream]->popFront();
00193                                 mFileWriter->acceptOggPage(locSecHead);
00194                         }
00195                 }
00196         }
00197 
00198         //Write the fish skeleton EOS
00199         mFileWriter->acceptOggPage(FishSkeleton::makeFishEOS(locSerialNo));
00200 
00201 
00202 
00203 }
00204 void AnxPageInterleaver::processData()
00205 {
00206         if ((mVersionMajor == 2) && (mVersionMinor == 0)) {
00207                 //IF seen all headers
00208                 //              CREATE ANNODEX BOS
00209                 //              CREATE ANXDATA BOS's
00210                 //              CREATE ANNODEX EOS
00211                 //ELSE
00212                 //              DO NOTHING
00213                 //ENDIF
00214                 //
00215         
00216                 if (!mIsAnxSetup) {
00217                         if (gotAllHeaders()) {
00218                                 
00219                                 mIsAnxSetup = true;
00220                                 addAnnodex_2_0_BOS();
00221                                 addAllAnxData_2_0_BOS();
00222                                 addAnnodexEOS();        
00223                                 //TODO::: Pump out these start pages.
00224                         }
00225                 } else {
00226                         OggPageInterleaver::processData();
00227                 }
00228         } else if ((mVersionMajor == 3) && (mVersionMinor == 0)) {
00229                 if (!mIsAnxSetup) {
00230                         if (gotAllSecondaryHeaders()) {
00231                                 //ANX3::: We need to make sure every stream has all of their headers
00232                                 //
00233                                 //Then we write :
00234                                 //Fishhead
00235                                 //Codec CMML BOS
00236                                 //Codec 2 BOS
00237                                 //Fishbones...
00238                                 //All other codec secondary headers...
00239 
00240                                 letsGetFishy();
00241 
00242                                 mIsAnxSetup = true;
00243                                 //addAnnodex_2_0_BOS();
00244                                 //addAllAnxData_2_0_BOS();
00245                                 //addAnnodexEOS();      
00246 
00247                                 //addFishyBits();
00248 
00249                                 //TODO::: Pump out these start pages.
00250                         }
00251                 } else {
00252                         OggPageInterleaver::processData();
00253                 }
00254 
00255         } else {
00256                 throw 0;
00257         }
00258 }

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