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     This PVA_FF_SLConfigDescriptor Class
     20 */
     21 
     22 
     23 #define IMPLEMENT_SLConfigDescriptor
     24 
     25 #include "slconfigdescriptor.h"
     26 #include "atomutils.h"
     27 
     28 // Constructor
     29 PVA_FF_SLConfigDescriptor::PVA_FF_SLConfigDescriptor()
     30         : PVA_FF_BaseDescriptor(0x06)
     31 {
     32     init();
     33 }
     34 
     35 // Destructor
     36 PVA_FF_SLConfigDescriptor::~PVA_FF_SLConfigDescriptor()
     37 {
     38     // Empty
     39 }
     40 
     41 void
     42 PVA_FF_SLConfigDescriptor::init()
     43 {
     44     _predefined = 0x02; // According to MPEG4 File Format specification
     45     // - section 13.1.3.2 "Handling of elementary streams"
     46     // (last paragraph)
     47     _reserved2 = 0x7f;
     48     _OCRStreamFlag = false;
     49     _OCRESID = 0;
     50 
     51     if (_predefined == 0x01)
     52     {
     53         _useAccessUnitStartFlag = false;
     54         _useAccessUnitEndFlag = false;
     55         _useRandomAccessPointFlag = false;
     56         _usePaddingFlag = false;
     57         _useTimeStampsFlag = false;
     58         _useIdleFlag = false;
     59         _AULength = 0;
     60         _degradationPriorityLength = 0;
     61         _AUSeqNumLength = 0;
     62         _packetSeqNumLength = 0;
     63         _reserved1 = 0x3; // 0b11
     64     }
     65 
     66 
     67     recomputeSize();
     68 }
     69 
     70 // Rendering the Descriptor in proper format (bitlengths, etc.) to an ostream
     71 bool
     72 PVA_FF_SLConfigDescriptor::renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP *fp)
     73 {
     74     int32 rendered = 0; // Keep track of number of bytes rendered
     75 
     76     // Render the base class members
     77     int32 numBytes = renderBaseDescriptorMembers(fp);
     78 
     79     if (numBytes == 0)
     80     {
     81         return false;
     82     }
     83     rendered += numBytes;
     84 
     85     if (!PVA_FF_AtomUtils::render8(fp, _predefined))
     86     {
     87         return false;
     88     }
     89     rendered += 1;
     90 
     91     return true;
     92 }
     93 
     94 void
     95 PVA_FF_SLConfigDescriptor::recomputeSize()
     96 {
     97     int32 contents = 0;
     98     contents += 1; //(8 bits for predefined flag)
     99 
    100     if (_predefined == 0)
    101     {
    102         contents += 1; //(8 bits for packet boolean flags)
    103         contents += 4; // (32 bits for TS resolution)
    104         contents += 4; // (32 bits for OCR resolution)
    105         contents += 1; // (8 bits for TS length)
    106         contents += 1; // (8 bits for OCR length)
    107         contents += 1; // (8 bits for AU length)
    108         contents += 1; // (8 bits for instant bitrate length)
    109         contents += 2; // (16 bits for packed DP, AUSN, pacSN lengths plus reserved)
    110         contents += 4; // (32 bits for timescale)
    111         contents += 2; // (16 bits for AU duration)
    112         contents += 2; // (16 bits for CU duration)
    113 
    114         contents += 4; // (32 bits for start Dec TS)
    115         contents += 4; // (32 bits for start Comp TS)
    116     }
    117     _sizeOfClass = contents;
    118     _sizeOfSizeField = PVA_FF_AtomUtils::getNumberOfBytesUsedToStoreSizeOfClass(contents);
    119 
    120     // Have the parent descriptor recompute its size based on this update
    121     if (_pparent != NULL)
    122     {
    123         _pparent->recomputeSize();
    124     }
    125 }
    126