Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 #define IMPLEMENT_MovieExtendsAtom
     19 
     20 #include "movieextendsatom.h"
     21 
     22 typedef Oscl_Vector <PVA_FF_TrackExtendsAtom*, OsclMemAllocator> PVA_FF_TrackExtendsAtomVecType;
     23 
     24 // constructor
     25 PVA_FF_MovieExtendsAtom::PVA_FF_MovieExtendsAtom()
     26         : PVA_FF_Atom(MOVIE_EXTENDS_ATOM)
     27 {
     28     PV_MP4_FF_NEW(fp->auditCB, PVA_FF_MovieExtendsHeaderAtom, (), _pMehdAtom);
     29     _pMehdAtom->setParent(this);
     30 
     31     PV_MP4_FF_NEW(fp->auditCB, PVA_FF_TrackExtendsAtomVecType, (), _pTrexAtomVec);
     32 
     33     recomputeSize();
     34 
     35 }
     36 
     37 //destructor
     38 PVA_FF_MovieExtendsAtom::~PVA_FF_MovieExtendsAtom()
     39 {
     40     PV_MP4_FF_DELETE(NULL, PVA_FF_MovieExtendsHeaderAtom, _pMehdAtom);
     41 
     42     // Delete trex atoms
     43     for (uint32 ii = 0; ii < _pTrexAtomVec->size(); ii++)
     44     {
     45         PV_MP4_FF_DELETE(NULL, PVA_FF_TrackExtendAtom, (*_pTrexAtomVec)[ii]);
     46     }
     47     PV_MP4_FF_TEMPLATED_DELETE(NULL, PVA_FF_TrackExtendsAtomVecType, Oscl_Vector, _pTrexAtomVec);
     48 
     49 }
     50 
     51 
     52 // returns pointer to movie extension header atom
     53 PVA_FF_MovieExtendsHeaderAtom*
     54 PVA_FF_MovieExtendsAtom::getMehdAtom()
     55 {
     56     return _pMehdAtom;
     57 }
     58 
     59 
     60 // set movie fragment duration
     61 void
     62 PVA_FF_MovieExtendsAtom::setMovieFragmentDuration(uint32 duration)
     63 {
     64     _pMehdAtom->setFragmentDuration(duration);
     65 }
     66 
     67 
     68 // update fragment duration
     69 void
     70 PVA_FF_MovieExtendsAtom::updateMovieFragmentDuration(uint32 ts)
     71 {
     72 
     73     _pMehdAtom->updateMovieFragmentDuration(ts);
     74 }
     75 
     76 // write fragment duration into target file
     77 void
     78 PVA_FF_MovieExtendsAtom::writeMovieFragmentDuration(MP4_AUTHOR_FF_FILE_IO_WRAP* fp)
     79 {
     80     _pMehdAtom->writeMovieFragmentDuration(fp);
     81 }
     82 
     83 // return fragement duration
     84 uint32
     85 PVA_FF_MovieExtendsAtom::getDuration()
     86 {
     87     return  _pMehdAtom->getFragmentDuration();
     88 }
     89 
     90 
     91 // add new trex atom to the list
     92 void
     93 PVA_FF_MovieExtendsAtom::addTrexAtom(PVA_FF_TrackExtendsAtom *pTrexAtom)
     94 {
     95     _pTrexAtomVec->push_back(pTrexAtom);
     96     pTrexAtom->setParent(this);
     97 
     98     recomputeSize();
     99 }
    100 
    101 
    102 // returns trex atom corressponding to track id
    103 PVA_FF_TrackExtendsAtom*
    104 PVA_FF_MovieExtendsAtom::getTrexAtom(uint32 trackId)
    105 {
    106     if (_pTrexAtomVec->size() != 0)
    107     {
    108         for (uint32 ii = 0; ii < _pTrexAtomVec->size(); ii++)
    109         {
    110             if (trackId == ((*_pTrexAtomVec)[ii])->getTrackId())
    111                 return ((*_pTrexAtomVec)[ii]);
    112         }
    113     }
    114 
    115     return NULL;
    116 }
    117 
    118 
    119 // Recomputes the size of the current atom by checking all contained atoms
    120 void
    121 PVA_FF_MovieExtendsAtom::recomputeSize()
    122 {
    123     int32 size = getDefaultSize(); // From base class
    124 
    125     // add size of mehd atom
    126     size += _pMehdAtom->getSize();
    127 
    128     // add size of Trex atoms
    129     if (_pTrexAtomVec->size() != 0)
    130     {
    131         for (uint32 ii = 0; ii < _pTrexAtomVec->size(); ii++)
    132         {
    133             size += ((*_pTrexAtomVec)[ii])->getSize();
    134         }
    135     }
    136 
    137     _size = size;
    138 
    139     // Update the size of the parent atom since this child atom may have changed
    140     if (_pparent != NULL)
    141     {
    142         _pparent->recomputeSize();
    143     }
    144 }
    145 
    146 
    147 // Write the atom into target file
    148 bool
    149 PVA_FF_MovieExtendsAtom::renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP* fp)
    150 {
    151     uint32 rendered = 0;
    152 
    153     if (!renderAtomBaseMembers(fp))
    154     {
    155         return false;
    156     }
    157     rendered += getDefaultSize();
    158 
    159     // Render the movie extend header atom
    160     if (!_pMehdAtom->renderToFileStream(fp))
    161     {
    162         return false;
    163     }
    164     rendered += getMehdAtom()->getSize();
    165 
    166     // render track extend atoms
    167     if (_pTrexAtomVec->size() != 0)
    168     {
    169         for (uint32 ii = 0; ii < _pTrexAtomVec->size(); ii++)
    170         {
    171             if (!((*_pTrexAtomVec)[ii])->renderToFileStream(fp))
    172             {
    173                 return false;
    174             }
    175             rendered += ((*_pTrexAtomVec)[ii])->getSize();
    176         }
    177     }
    178 
    179     return true;
    180 }
    181