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 AudioSampleEntry Class */ 21 /* ------------------------------------------------------------------- */ 22 /*********************************************************************************/ 23 /* 24 This AudioSampleEntry Class is used for visual streams. 25 */ 26 27 #define IMPLEMENT_AMRSampleEntry 28 29 #include "amrsampleentry.h" 30 #include "amrdecoderspecificinfo.h" 31 #include "atomutils.h" 32 #include "atomdefs.h" 33 34 typedef Oscl_Vector<DecoderSpecificInfo*, OsclMemAllocator> decoderSpecificInfoVecType; 35 // Stream-in ctor 36 AMRSampleEntry::AMRSampleEntry(MP4_FF_FILE *fp, uint32 size, uint32 type) 37 : Atom(fp, size, type) 38 { 39 _pAMRSpecificAtom = NULL; 40 _pAMRDecSpecInfoArray = NULL; 41 42 if (_success) 43 { 44 // Read reserved values 45 if (!AtomUtils::read8read8(fp, _reserved[0], _reserved[1])) 46 _success = false; 47 if (!AtomUtils::read8read8(fp, _reserved[2], _reserved[3])) 48 _success = false; 49 if (!AtomUtils::read8read8(fp, _reserved[4], _reserved[5])) 50 _success = false; 51 52 if (!AtomUtils::read16(fp, _dataReferenceIndex)) 53 _success = false; 54 55 if (!AtomUtils::read32read32(fp, _reserved1[0], _reserved1[1])) 56 _success = false; 57 if (!AtomUtils::read16read16(fp, _reserved2, _reserved3)) 58 _success = false; 59 if (!AtomUtils::read32(fp, _reserved4)) 60 _success = false; 61 62 if (!AtomUtils::read16read16(fp, _timeScale, _reserved5)) 63 _success = false; 64 65 if (_success) 66 { 67 uint32 atom_type = UNKNOWN_ATOM; 68 uint32 atom_size = 0; 69 70 AtomUtils::getNextAtomType(fp, atom_size, atom_type); 71 72 if (atom_type != AMR_SPECIFIC_ATOM) 73 { 74 _success = false; 75 _mp4ErrorCode = READ_AMR_SAMPLE_ENTRY_FAILED; 76 } 77 else 78 { 79 PV_MP4_FF_NEW(fp->auditCB, AMRSpecificAtom, (fp, atom_size, atom_type), _pAMRSpecificAtom); 80 81 if (!_pAMRSpecificAtom->MP4Success()) 82 { 83 _success = false; 84 _mp4ErrorCode = READ_AMR_SAMPLE_ENTRY_FAILED; 85 } 86 87 PV_MP4_FF_NEW(fp->auditCB, decoderSpecificInfoVecType, (), _pAMRDecSpecInfoArray); 88 89 for (uint32 i = 0; i < 16; i++) 90 { 91 AMRDecoderSpecificInfo *pinfo = NULL; 92 PV_MP4_FF_NEW(fp->auditCB, AMRDecoderSpecificInfo, (fp, true), pinfo); 93 94 pinfo->_frame_type = (uint8)i; 95 pinfo->_codec_version = _pAMRSpecificAtom->getDecoderVersion(); 96 pinfo->_mode_change_period = _pAMRSpecificAtom->getModeChangePeriod(); 97 pinfo->_mode_set = _pAMRSpecificAtom->getModeSet(); 98 pinfo->_mode_change_neighbour = false; 99 100 (*_pAMRDecSpecInfoArray).push_back(pinfo); 101 } 102 } 103 } 104 else 105 { 106 _mp4ErrorCode = READ_AMR_SAMPLE_ENTRY_FAILED; 107 } 108 } 109 else 110 { 111 _mp4ErrorCode = READ_AMR_SAMPLE_ENTRY_FAILED; 112 } 113 114 } 115 116 // Destructor 117 AMRSampleEntry::~AMRSampleEntry() 118 { 119 if (_pAMRSpecificAtom != NULL) 120 { 121 // Cleanup ESDAtom 122 PV_MP4_FF_DELETE(NULL, AMRSpecificAtom, _pAMRSpecificAtom); 123 } 124 if (_pAMRDecSpecInfoArray != NULL) 125 { 126 for (uint32 i = 0; i < _pAMRDecSpecInfoArray->size(); i++) 127 { 128 PV_MP4_FF_DELETE(NULL, DecoderSpecificInfo, (*_pAMRDecSpecInfoArray)[i]); 129 } 130 } 131 132 if (_pAMRDecSpecInfoArray != NULL) 133 { 134 PV_MP4_FF_TEMPLATED_DELETE(NULL, decoderSpecificInfoVecType, Oscl_Vector, _pAMRDecSpecInfoArray); 135 _pAMRDecSpecInfoArray = NULL; 136 } 137 138 } 139 140 DecoderSpecificInfo * 141 AMRSampleEntry::getDecoderSpecificInfo(uint32 index) 142 { 143 if ((_pAMRDecSpecInfoArray->size() == 0) || 144 (index >= (uint32)(_pAMRDecSpecInfoArray->size()))) 145 { 146 return NULL; 147 } 148 else 149 { 150 return ((*_pAMRDecSpecInfoArray)[index]); 151 } 152 } 153