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_TrackExtendsAtom 19 20 #include "trackextendsatom.h" 21 22 // constructor 23 PVA_FF_TrackExtendsAtom::PVA_FF_TrackExtendsAtom(uint32 mediaType, 24 int32 codecType, 25 uint32 trackId) 26 : PVA_FF_FullAtom(TRACK_EXTENDS_ATOM, (uint8)0, (uint32)0) 27 { 28 _mediaType = mediaType; 29 30 _codecType = codecType; 31 32 _trackId = trackId; 33 34 _defaultSampleDescriptionIndex = 0; // all flags are kept 0 35 _defaultSampleDuration = 0; 36 _defaultSampleSize = 0; 37 _defaultSampleFlags = 0; 38 39 recomputeSize(); 40 } 41 42 //destructor 43 PVA_FF_TrackExtendsAtom::~PVA_FF_TrackExtendsAtom() 44 { 45 // do nothing 46 } 47 48 // return trackId 49 uint32 50 PVA_FF_TrackExtendsAtom::getTrackId() 51 { 52 return _trackId; 53 } 54 55 //set value of trackId 56 void 57 PVA_FF_TrackExtendsAtom::setTrackId(uint32 trackId) 58 { 59 _trackId = trackId; 60 } 61 62 63 // recompute size of atom 64 void 65 PVA_FF_TrackExtendsAtom::recomputeSize() 66 { 67 int32 size = getDefaultSize(); 68 69 size += 4; // For trackId 70 size += 4; // For sample description 71 size += 4; // For sample duration 72 size += 4; // For sample size 73 size += 4; // For sample flags 74 75 _size = size; 76 77 // Update the parent atom size 78 if (_pparent != NULL) 79 { 80 _pparent->recomputeSize(); 81 } 82 } 83 84 85 // write atom in target file 86 bool 87 PVA_FF_TrackExtendsAtom::renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP* fp) 88 { 89 90 uint32 rendered = 0; 91 92 if (!renderAtomBaseMembers(fp)) 93 { 94 return false; 95 } 96 rendered += getDefaultSize(); 97 98 if (!PVA_FF_AtomUtils::render32(fp, _trackId)) 99 { 100 return false; 101 } 102 rendered += 4; 103 104 if (!PVA_FF_AtomUtils::render32(fp, _defaultSampleDescriptionIndex)) 105 { 106 return false; 107 } 108 rendered += 4; 109 110 if (!PVA_FF_AtomUtils::render32(fp, _defaultSampleDuration)) 111 { 112 return false; 113 } 114 rendered += 4; 115 116 if (!PVA_FF_AtomUtils::render32(fp, _defaultSampleSize)) 117 { 118 return false; 119 } 120 rendered += 4; 121 122 if (!PVA_FF_AtomUtils::render32(fp, _defaultSampleFlags)) 123 { 124 return false; 125 } 126 rendered += 4; 127 128 return true; 129 } 130