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_MediaAtom Class contains all the objects that declare information 20 about the media data within the stream. 21*/ 22 23#define IMPLEMENT_MediaAtom_H__ 24 25#include "mediaatom.h" 26#include "a_atomdefs.h" 27#include "atomutils.h" 28 29// Constructor 30PVA_FF_MediaAtom::PVA_FF_MediaAtom(int32 mediaType, 31 int32 codecType, 32 uint32 fileAuthoringFlags, 33 uint32 protocol, 34 uint8 profile, 35 uint8 profileComp, 36 uint8 level) 37 38 : PVA_FF_Atom(MEDIA_ATOM) 39{ 40 PV_MP4_FF_NEW(fp->auditCB, PVA_FF_MediaHeaderAtom, (), _pmediaHeader); 41 42 PV_MP4_FF_NEW(fp->auditCB, PVA_FF_HandlerAtom, (mediaType, (uint8)0, (uint8)0), _phandler); 43 44 PV_MP4_FF_NEW(fp->auditCB, PVA_FF_MediaInformationAtom, (mediaType, 45 codecType, 46 fileAuthoringFlags, 47 protocol, profile, 48 profileComp, level), _pmediaInformation); 49 50 recomputeSize(); 51 _pmediaHeader->setParent(this); 52 _phandler->setParent(this); 53 _pmediaInformation->setParent(this); 54} 55 56// Destructor 57PVA_FF_MediaAtom::~PVA_FF_MediaAtom() 58{ 59 PV_MP4_FF_DELETE(NULL, PVA_FF_MediaHeaderAtom, _pmediaHeader); 60 PV_MP4_FF_DELETE(NULL, PVA_FF_HandlerAtom, _phandler); 61 PV_MP4_FF_DELETE(NULL, PVA_FF_MediaInformationAtom, _pmediaInformation); 62} 63 64void 65PVA_FF_MediaAtom::nextSample(int32 mediaType, 66 void *psample, 67 uint32 size, 68 uint32 ts, 69 uint8 flags, 70 uint32 baseOffset, 71 bool oChunkStart) 72{ 73 _pmediaInformation->nextSample(mediaType, psample, size, ts, 74 flags, baseOffset, oChunkStart); 75 _pmediaHeader->addSample(ts); 76} 77 78void 79PVA_FF_MediaAtom::nextTextSample(int32 mediaType, 80 void *psample, 81 uint32 size, 82 uint32 ts, 83 uint8 flags, 84 int32 index, 85 uint32 baseOffset, 86 bool oChunkStart) 87{ 88 _pmediaInformation->nextTextSample(mediaType, psample, size, ts, 89 flags, index, baseOffset, oChunkStart); 90 _pmediaHeader->addSample(ts); 91} 92 93void 94PVA_FF_MediaAtom::nextSample(int32 mediaType, 95 Oscl_Vector <OsclMemoryFragment, OsclMemAllocator>& fragmentList, 96 uint32 size, 97 uint32 ts, 98 uint8 flags, 99 uint32 baseOffset, 100 bool oChunkStart) 101{ 102 _pmediaInformation->nextSample(mediaType, fragmentList, size, ts, 103 flags, baseOffset, oChunkStart); 104 105 _pmediaHeader->addSample(ts); 106} 107 108void 109PVA_FF_MediaAtom::nextTextSample(int32 mediaType, 110 Oscl_Vector <OsclMemoryFragment, OsclMemAllocator>& fragmentList, 111 uint32 size, 112 uint32 ts, 113 uint8 flags, 114 int32 index, 115 uint32 baseOffset, 116 bool oChunkStart) 117{ 118 _pmediaInformation->nextTextSample(mediaType, fragmentList, size, ts, 119 flags, index, baseOffset, oChunkStart); 120 121 _pmediaHeader->addSample(ts); 122} 123 124bool 125PVA_FF_MediaAtom::reAuthorFirstSample(uint32 size, 126 uint32 baseOffset) 127{ 128 return( 129 _pmediaInformation->reAuthorFirstSample(size, 130 baseOffset)); 131} 132 133// in movie fragment mode set the actual duration of 134// last sample 135void 136PVA_FF_MediaAtom::updateLastTSEntry(uint32 ts) 137{ 138 139 _pmediaInformation->updateLastTSEntry(ts); 140 141 _pmediaHeader->updateLastTSEntry(ts); 142} 143 144 145void 146PVA_FF_MediaAtom::recomputeSize() 147{ 148 int32 size = getDefaultSize(); // Get size of base class members 149 150 // Include sizes of all members 151 size += _pmediaHeader->getSize(); 152 size += _phandler->getSize(); 153 size += _pmediaInformation->getSize(); 154 155 _size = size; 156 157 // Update size of parent atom if it exists 158 if (_pparent != NULL) 159 { 160 _pparent->recomputeSize(); 161 } 162} 163 164// Rendering the PVA_FF_Atom in proper format (bitlengths, etc.) to an ostream 165bool 166PVA_FF_MediaAtom::renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP *fp) 167{ 168 int32 rendered = 0; // Keep track of number of bytes rendered 169 170 // Render PVA_FF_Atom type and size 171 if (!renderAtomBaseMembers(fp)) 172 { 173 return false; 174 } 175 rendered += getDefaultSize(); 176 177 // Render all member atoms 178 if (!_pmediaHeader->renderToFileStream(fp)) 179 { 180 return false; 181 } 182 rendered += _pmediaHeader->getSize(); 183 184 if (!_phandler->renderToFileStream(fp)) 185 { 186 return false; 187 } 188 rendered += _phandler->getSize(); 189 190 if (!_pmediaInformation->renderToFileStream(fp)) 191 { 192 return false; 193 } 194 rendered += _pmediaInformation->getSize(); 195 196 return true; 197} 198 199void 200PVA_FF_MediaAtom::SetMaxSampleSize(uint32 aSize) 201{ 202 _pmediaInformation->SetMaxSampleSize(aSize); 203} 204 205void 206PVA_FF_MediaAtom::writeMaxSampleSize(MP4_AUTHOR_FF_FILE_IO_WRAP *_afp) 207{ 208 _pmediaInformation->writeMaxSampleSize(_afp); 209} 210