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 /*********************************************************************************/
     19 /*     -------------------------------------------------------------------       */
     20 /*                     MPEG-4 InitialObjectDescriptor Class                      */
     21 /*     -------------------------------------------------------------------       */
     22 /*********************************************************************************/
     23 
     24 
     25 #define IMPLEMENT_InitialObjectDescriptor
     26 
     27 #include "initialobjectdescriptor.h"
     28 #include "atomutils.h"
     29 
     30 typedef Oscl_Vector<ES_ID_Inc*, OsclMemAllocator> ES_ID_IncVecType;
     31 
     32 // Stream-in Constructor
     33 InitialObjectDescriptor::InitialObjectDescriptor(MP4_FF_FILE *fp)
     34         : ObjectDescriptor(fp, false)
     35 {
     36     if (_success)
     37     {
     38 
     39         _pES_ID_Inc = NULL;
     40 
     41         _reserved = 0xf;
     42 
     43         uint16 data;
     44         if (!AtomUtils::read16(fp, data))
     45             _success = false;
     46 
     47         _objectDescriptorID = (uint16)(data >> 6);
     48 
     49         _urlFlag = false;
     50         if (((data >> 5) & 0x0001) == 1)
     51         {
     52             _urlFlag = true;
     53         }
     54 
     55         _includeInlineProfilesFlag = false;
     56         if (((data >> 4) & 0x0001) == 1)
     57         {
     58             _includeInlineProfilesFlag = true;
     59         }
     60 
     61         if (_urlFlag)
     62         {
     63             if (!AtomUtils::read8(fp, _urlLength))
     64                 _success = false;
     65 
     66             _urlStringPtr = (uint8 *) oscl_malloc(_urlLength + 1); // +1 for the null termination
     67 
     68             if (!AtomUtils::readByteData(fp, _urlLength, _urlStringPtr))
     69                 _success = false;
     70         }
     71         else
     72         {
     73             if (!AtomUtils::read8(fp, _ODProfileLevelIndication))
     74                 _success = false;
     75             if (!AtomUtils::read8(fp, _sceneProfileLevelIndication))
     76                 _success = false;
     77             if (!AtomUtils::read8(fp, _audioProfileLevelIndication))
     78                 _success = false;
     79             if (!AtomUtils::read8(fp, _visualProfileLevelIndication))
     80                 _success = false;
     81             if (!AtomUtils::read8(fp, _graphicsProfileLevelIndication))
     82                 _success = false;
     83 
     84             // Read in ESDescriptor references (i.e. ESIDs)
     85             int32 readIn = getSizeOfSizeField();
     86             readIn += 1; // For tag
     87             readIn += 5; // For 5 level indicators
     88             readIn += 2; // For 10-bit ODID, etc.
     89             int32 delta = _sizeOfClass - readIn;
     90 
     91             uint8  tag;
     92             tag = AtomUtils::peekNextByte(fp);
     93             if (tag == 0)   //ES_ID, old version
     94             {
     95                 for (int32 i = 0; i < delta; i++)
     96                 {
     97                     uint8 data_8;
     98 
     99                     if (!AtomUtils::read8(fp, data_8))
    100                     {
    101                         _success = false;
    102                         break;
    103                     }
    104                 }
    105             }
    106             else if (tag == ES_DESCRIPTOR_TAG)
    107             {
    108                 // TO TAKE CARE OF THE CASE WHERE IN
    109                 // WE HAVE THE "ES_DecsrTag" AS OPPOSSED
    110                 // TO AN "ES_ID_IncTag"
    111                 for (int32 i = 0; i < delta; i++)
    112                 {
    113                     uint8 data_8;
    114                     if (!AtomUtils::read8(fp, data_8))
    115                     {
    116                         _success = false;
    117                         break;
    118                     }
    119                 }
    120             }
    121             else
    122             {//new version ES_ID_Inc and ES_ID_Ref
    123                 ES_ID_Inc *esIDInc;
    124 
    125                 PV_MP4_FF_NEW(fp->auditCB, ES_ID_IncVecType, (), _pES_ID_Inc);
    126 
    127                 while (delta > 0)
    128                 {
    129 
    130                     tag = AtomUtils::peekNextByte(fp);
    131 
    132                     if (tag == ES_ID_INC_TAG)
    133                     {
    134                         PV_MP4_FF_NEW(fp->auditCB, ES_ID_Inc, (fp), esIDInc);
    135                         delta -= esIDInc->getSize();
    136                         (*_pES_ID_Inc).push_back(esIDInc);
    137                     }
    138                     else
    139                     {
    140                         ExpandableBaseClass* tempDesc = NULL;
    141                         PV_MP4_FF_NEW(fp->auditCB, ExpandableBaseClass, (fp, false), tempDesc);
    142                         if (!tempDesc->MP4Success())
    143                         {
    144                             _success = false;
    145                             break;
    146                         }
    147                         uint32 totaltempDescSize = tempDesc->getSize();
    148                         uint32 tempDescSize = 1; //for tag
    149                         tempDescSize += tempDesc->getSizeOfSizeField();
    150                         uint32 remDescSize = (totaltempDescSize - tempDescSize);
    151                         if (totaltempDescSize > (uint32)delta)
    152                         {
    153                             _success = false;
    154                             break;
    155                         }
    156                         AtomUtils::seekFromCurrPos(fp, remDescSize);
    157                         delta -= totaltempDescSize;
    158 
    159                         PV_MP4_FF_DELETE(NULL, ExpandableBaseClass, tempDesc);
    160                     }
    161                 }
    162             }
    163         }
    164 
    165         if (!_success)
    166             _mp4ErrorCode = READ_INITIAL_OBJECT_DESCRIPTOR_FAILED;
    167     }
    168     else
    169     {
    170         _mp4ErrorCode = READ_INITIAL_OBJECT_DESCRIPTOR_FAILED;
    171     }
    172 
    173 }
    174 
    175 // Destructor
    176 InitialObjectDescriptor::~InitialObjectDescriptor()
    177 {
    178     uint32 i;
    179     if (_pES_ID_Inc != NULL)
    180     {
    181         for (i = 0; i < _pES_ID_Inc->size(); i++)
    182             PV_MP4_FF_DELETE(NULL, ES_ID_Inc, (*_pES_ID_Inc)[i]);
    183 
    184         PV_MP4_FF_TEMPLATED_DELETE(NULL, ES_ID_IncVecType, Oscl_Vector, _pES_ID_Inc);
    185     }
    186     // EMPTY - The vector of ESIDs gets handled in the base class destructor
    187 }
    188 
    189 
    190