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_TrackFragmentHeaderAtom 19 20 #include "trackfragmentheaderatom.h" 21 22 23 // constructor 24 PVA_FF_TrackFragmentHeaderAtom::PVA_FF_TrackFragmentHeaderAtom(uint32 trackId) 25 : PVA_FF_FullAtom(TRACK_FRAGMENT_HEADER_ATOM, (uint8)0, (uint32)FLAGS_TFHD_ATOM) 26 { 27 _trackId = trackId; 28 _baseDataOffset = 0; 29 _sampleDescriptionIndex = 0; 30 _defaultSampleDuration = 0; 31 _defaultSampleSize = 0; 32 _defaultSampleFlags = 0; 33 34 recomputeSize(); 35 } 36 37 // destructor 38 PVA_FF_TrackFragmentHeaderAtom::~PVA_FF_TrackFragmentHeaderAtom() 39 { 40 // do nothing 41 } 42 43 44 // set header data 45 void 46 PVA_FF_TrackFragmentHeaderAtom::setHeaderData() 47 { 48 // parameters to sample default parameters will be introduced later 49 } 50 51 52 53 // set base data offset 54 void 55 PVA_FF_TrackFragmentHeaderAtom::setBaseDataOffset(uint64 offset) 56 { 57 _baseDataOffset = offset; 58 } 59 60 61 62 uint32 63 PVA_FF_TrackFragmentHeaderAtom::getBaseDataOffset() 64 { 65 return (uint32)_baseDataOffset; 66 } 67 68 uint32 69 PVA_FF_TrackFragmentHeaderAtom::getTrackId() 70 { 71 return _trackId; 72 } 73 74 75 76 // recompute size of atom 77 void 78 PVA_FF_TrackFragmentHeaderAtom::recomputeSize() 79 { 80 int32 size = getDefaultSize(); 81 82 // add size various fields 83 size += 4; // track Id 84 85 uint32 flags = getFlags(); 86 87 if (flags & 0x000001) 88 size += 8; // base data offset 89 90 if (flags & 0x000002) 91 size += 4; // description index 92 93 if (flags & 0x000008) 94 size += 4; // sample duration 95 96 if (flags & 0x000010) 97 size += 4; // sample size 98 99 if (flags & 0x000020) 100 size += 4; // sample flags 101 102 _size = size; 103 104 // Update the parent atom size 105 if (_pparent != NULL) 106 { 107 _pparent->recomputeSize(); 108 } 109 } 110 111 112 // write atom to target file 113 bool 114 PVA_FF_TrackFragmentHeaderAtom::renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP* fp) 115 { 116 uint32 rendered = 0; 117 118 if (!renderAtomBaseMembers(fp)) 119 { 120 return false; 121 } 122 rendered += getDefaultSize(); 123 124 if (!PVA_FF_AtomUtils::render32(fp, _trackId)) 125 { 126 return false; 127 } 128 rendered += 4; 129 130 uint32 flags = getFlags(); 131 132 if (flags & 0x000001) 133 { 134 if (!PVA_FF_AtomUtils::render64(fp, _baseDataOffset)) 135 { 136 return false; 137 } 138 rendered += 8; 139 } 140 141 if (flags & 0x000002) 142 { 143 if (!PVA_FF_AtomUtils::render32(fp, _sampleDescriptionIndex)) 144 { 145 return false; 146 } 147 rendered += 4; 148 } 149 150 151 if (flags & 0x000008) 152 { 153 if (!PVA_FF_AtomUtils::render32(fp, _defaultSampleDuration)) 154 { 155 return false; 156 } 157 rendered += 4; 158 } 159 160 if (flags & 0x000010) 161 { 162 if (!PVA_FF_AtomUtils::render32(fp, _defaultSampleSize)) 163 { 164 return false; 165 } 166 rendered += 4; 167 } 168 169 if (flags & 0x000020) 170 { 171 if (!PVA_FF_AtomUtils::render32(fp, _defaultSampleFlags)) 172 { 173 return false; 174 } 175 rendered += 4; 176 } 177 178 return true; 179 } 180 181