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_AVCConfigurationBox 19 20 #include "avcsampleentry.h" 21 #include "atomutils.h" 22 #include "atomdefs.h" 23 24 #define LENGTH_SIZE_MINUS_ONE_MASK 0x03 25 #define NUM_SEQUENCE_PARAM_SETS_MASK 0x01F 26 27 typedef Oscl_Vector<AVCConfigurationBox::ParameterSet*, OsclMemAllocator> parameterSetVecType; 28 29 AVCConfigurationBox::AVCConfigurationBox(MP4_FF_FILE *fp, uint32 size, uint32 type) 30 : Atom(fp, size, type) 31 { 32 _mp4ErrorCode = READ_AVC_CONFIG_BOX_FAILED; 33 34 _sequenceParameterSetVec = NULL; 35 _pictureParameterSetVec = NULL; 36 _totalSeqParameterSetLength = 0; 37 _totalPicutureParameterSetLength = 0; 38 39 if (_success) 40 { 41 _success = false; 42 _pparent = NULL; 43 44 PV_MP4_FF_NEW(fp->auditCB, parameterSetVecType, (), _sequenceParameterSetVec); 45 PV_MP4_FF_NEW(fp->auditCB, parameterSetVecType, (), _pictureParameterSetVec); 46 47 if (!AtomUtils::read8(fp, _configurationVersion)) 48 { 49 return; 50 } 51 if (!AtomUtils::read8(fp, _avcProfileIndication)) 52 { 53 return; 54 } 55 if (!AtomUtils::read8(fp, _profileCompatibility)) 56 { 57 return; 58 } 59 60 if (!AtomUtils::read8(fp, _avcLevelIndication)) 61 { 62 return; 63 } 64 65 _constraint_set0_flag = (uint8)((_profileCompatibility & ~0x7F) >> 7); 66 _constraint_set1_flag = (uint8)((_profileCompatibility & ~0xBF) >> 6); 67 _constraint_set2_flag = (uint8)((_profileCompatibility & ~0xDF) >> 5); 68 _reserved_zero_5bits = 0; 69 70 if (!AtomUtils::read8(fp, _lengthSizeMinusOne)) 71 { 72 return; 73 } 74 _lengthSizeMinusOne &= LENGTH_SIZE_MINUS_ONE_MASK; 75 76 if (!AtomUtils::read8(fp, _numSequenceParameterSets)) 77 { 78 return; 79 } 80 _numSequenceParameterSets &= NUM_SEQUENCE_PARAM_SETS_MASK; 81 82 uint8 i; 83 uint16 parameterSetLen; 84 85 for (i = 0; i < _numSequenceParameterSets; i++) 86 { 87 if (!AtomUtils::read16(fp, parameterSetLen)) 88 { 89 return; 90 } 91 92 _totalSeqParameterSetLength += parameterSetLen; 93 94 ParameterSet *paramSet = NULL; 95 PV_MP4_FF_NEW(fp->auditCB, ParameterSet, (parameterSetLen, fp), paramSet); 96 97 if (!(paramSet->getSuccess())) 98 { 99 PV_MP4_FF_DELETE(NULL, ParameterSet, paramSet); 100 return; 101 } 102 103 (*_sequenceParameterSetVec).push_back(paramSet); 104 105 } 106 107 if (!AtomUtils::read8(fp, _numPictureParameterSets)) 108 { 109 return; 110 } 111 112 for (i = 0; i < _numPictureParameterSets; i++) 113 { 114 if (!AtomUtils::read16(fp, parameterSetLen)) 115 { 116 return; 117 } 118 119 _totalPicutureParameterSetLength += parameterSetLen; 120 121 ParameterSet *paramSet = NULL; 122 PV_MP4_FF_NEW(fp->auditCB, ParameterSet, (parameterSetLen, fp), paramSet); 123 124 if (!(paramSet->getSuccess())) 125 { 126 PV_MP4_FF_DELETE(NULL, ParameterSet, paramSet); 127 return; 128 } 129 130 (*_pictureParameterSetVec).push_back(paramSet); 131 132 } 133 _success = true; 134 _mp4ErrorCode = EVERYTHING_FINE; 135 136 } 137 } 138 139 OSCL_EXPORT_REF bool AVCConfigurationBox::getPictureParamSet(int32 index, uint16 &length, uint8* ¶mSet) 140 { 141 if ((uint32)index < _pictureParameterSetVec->size()) 142 { 143 ParameterSet *pSet = (*_pictureParameterSetVec)[index]; 144 145 length = pSet->getParameterSetLength(); 146 paramSet = pSet->getParameterSet(); 147 148 return true; 149 } 150 else 151 { 152 length = 0; 153 paramSet = NULL; 154 return false; 155 } 156 } 157 158 OSCL_EXPORT_REF bool AVCConfigurationBox::getSequenceParamSet(int32 index, uint16 &length, uint8* ¶mSet) 159 { 160 if ((uint32)index < _sequenceParameterSetVec->size()) 161 { 162 ParameterSet *pSet = (*_sequenceParameterSetVec)[index]; 163 164 length = pSet->getParameterSetLength(); 165 paramSet = pSet->getParameterSet(); 166 167 return true; 168 } 169 else 170 { 171 length = 0; 172 paramSet = NULL; 173 return false; 174 } 175 } 176 177 AVCConfigurationBox::ParameterSet::ParameterSet(uint16 length, MP4_FF_FILE *fp) 178 { 179 _parameterSetLength = 0; 180 _pParameterSet = NULL; 181 _success = false; 182 183 if ((int16)(length) > 0) 184 { 185 _parameterSetLength = length; 186 187 PV_MP4_FF_ARRAY_NEW(NULL, uint8, _parameterSetLength, _pParameterSet); 188 189 if (!AtomUtils::readByteData(fp, _parameterSetLength, _pParameterSet)) 190 { 191 return ; 192 } 193 _success = true; 194 } 195 } 196 197 // Destructor 198 AVCConfigurationBox::~AVCConfigurationBox() 199 { 200 if (_sequenceParameterSetVec != NULL) 201 { 202 for (uint32 i = 0; i < _sequenceParameterSetVec->size(); i++) 203 { 204 PV_MP4_FF_DELETE(NULL, ParameterSet, (*_sequenceParameterSetVec)[i]); 205 } 206 PV_MP4_FF_TEMPLATED_DELETE(NULL, parameterSetVecType, Oscl_Vector, _sequenceParameterSetVec); 207 } 208 if (_pictureParameterSetVec != NULL) 209 { 210 for (uint32 i = 0; i < _pictureParameterSetVec->size(); i++) 211 { 212 PV_MP4_FF_DELETE(NULL, ParameterSet, (*_pictureParameterSetVec)[i]); 213 } 214 PV_MP4_FF_TEMPLATED_DELETE(NULL, parameterSetVecType, Oscl_Vector, _pictureParameterSetVec); 215 } 216 } 217