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_MovieFragmentRandomAccessAtom
19
20 #include "moviefragmentrandomaccessatom.h"
21
22 typedef Oscl_Vector <PVA_FF_TfraAtom*, OsclMemAllocator>
23 PVA_FF_TrackFragmentRandomAccessAtomVecType;
24
25 // constructor
PVA_FF_MovieFragmentRandomAccessAtom()26 PVA_FF_MovieFragmentRandomAccessAtom::PVA_FF_MovieFragmentRandomAccessAtom()
27 : PVA_FF_Atom(MOVIE_FRAGMENT_RANDOM_ACCESS_ATOM)
28 {
29 // Initialise movie fragment random access offset atom
30 PV_MP4_FF_NEW(fp->auditCB, PVA_FF_MfroAtom, (), _pMfroAtom);
31 _pMfroAtom->setParent(this);
32
33 // initialise track fragment random access atom list
34 PV_MP4_FF_NEW(fp->auditCB, PVA_FF_TrackFragmentRandomAccessAtomVecType, (), _pTfraList);
35
36 recomputeSize();
37 }
38
39
40 //destructor
~PVA_FF_MovieFragmentRandomAccessAtom()41 PVA_FF_MovieFragmentRandomAccessAtom::~PVA_FF_MovieFragmentRandomAccessAtom()
42 {
43 // delete movie fragment random access offset atom
44 PV_MP4_FF_DELETE(NULL, PVA_FF_MfroAtom, _pMfroAtom);
45
46 // Delete track fragment random access atom list
47 for (uint32 ii = 0; ii < _pTfraList->size(); ii++)
48 {
49 PV_MP4_FF_DELETE(NULL, PVA_FF_TfraAtom, (*_pTfraList)[ii]);
50 }
51 PV_MP4_FF_TEMPLATED_DELETE(NULL, PVA_FF_TrackFragmentRandomAccessAtomVecType,
52 Oscl_Vector, _pTfraList);
53
54 }
55
56 // add new track
57 void
addTrackFragmentRandomAccessAtom(uint32 trackId)58 PVA_FF_MovieFragmentRandomAccessAtom::addTrackFragmentRandomAccessAtom(uint32 trackId)
59 {
60 PVA_FF_TfraAtom* pTfraAtom;
61 PV_MP4_FF_NEW(fp->auditCB, PVA_FF_TfraAtom, ((trackId)), pTfraAtom);
62
63 _pTfraList->push_back(pTfraAtom);
64 pTfraAtom->setParent(this);
65
66 recomputeSize();
67 }
68
69
70 // return TFRA for given Track id
71 PVA_FF_TfraAtom*
getTfraAtom(uint32 trackId)72 PVA_FF_MovieFragmentRandomAccessAtom::getTfraAtom(uint32 trackId)
73 {
74 if (_pTfraList->size() != 0)
75 {
76 for (uint32 ii = 0; ii < _pTfraList->size(); ii++)
77 {
78 if (trackId == ((*_pTfraList)[ii])->getTrackId())
79 return ((*_pTfraList)[ii]);
80 }
81 }
82
83 return NULL;
84
85 }
86
87 // add new random access entry for given track
88 void
addSampleEntry(uint32 trackId,uint32 time,uint32 moofOffset,uint32 trafNumber,uint32 trunNumber,uint32 sampleNumber)89 PVA_FF_MovieFragmentRandomAccessAtom::addSampleEntry(uint32 trackId, uint32 time,
90 uint32 moofOffset, uint32 trafNumber,
91 uint32 trunNumber, uint32 sampleNumber)
92 {
93 if (_pTfraList->size() != 0)
94 {
95 for (uint32 ii = 0; ii < _pTfraList->size(); ii++)
96 {
97 if (trackId == ((*_pTfraList)[ii])->getTrackId())
98 (*_pTfraList)[ii]->addSampleEntry(time, moofOffset, trafNumber,
99 trunNumber, sampleNumber);
100 }
101 }
102
103
104
105 }
106
107
108 // update moof offset of current moof atom by the given offset for all TFRA atoms
109 void
updateMoofOffset(uint32 offset)110 PVA_FF_MovieFragmentRandomAccessAtom::updateMoofOffset(uint32 offset)
111 {
112 if (_pTfraList->size() != 0)
113 {
114 for (uint32 ii = 0; ii < _pTfraList->size(); ii++)
115 {
116 (*_pTfraList)[ii]->updateMoofOffset(offset);
117 }
118 }
119
120 }
121
122 // recompute size of atom
123 void
recomputeSize()124 PVA_FF_MovieFragmentRandomAccessAtom::recomputeSize()
125 {
126 int32 size = getDefaultSize();
127
128 // add size of mfro atom
129 size += _pMfroAtom->getSize();
130
131 // add size of Tfra list
132 if (_pTfraList->size() != 0)
133 {
134 for (uint32 ii = 0; ii < _pTfraList->size(); ii++)
135 {
136 size += ((*_pTfraList)[ii])->getSize();
137 }
138 }
139
140 _size = size;
141
142 // Update the parent atom size
143 if (_pparent != NULL)
144 {
145 _pparent->recomputeSize();
146 }
147 }
148
149
150
151 // write atom in target file
152 bool
renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP * fp)153 PVA_FF_MovieFragmentRandomAccessAtom::renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP* fp)
154 {
155 uint32 rendered = 0;
156
157 if (!renderAtomBaseMembers(fp))
158 {
159 return false;
160 }
161 rendered += getDefaultSize();
162
163 // render track fragment random access atoms
164 if (_pTfraList->size() != 0)
165 {
166 for (uint32 ii = 0; ii < _pTfraList->size(); ii++)
167 {
168 if (!((*_pTfraList)[ii])->renderToFileStream(fp))
169 {
170 return false;
171 }
172 rendered += ((*_pTfraList)[ii])->getSize();
173 }
174 }
175
176 // Render the movie fragment random access offset atom
177 _pMfroAtom->setSize(_size); // before rendering set the size field in MFRO atom
178 if (!_pMfroAtom->renderToFileStream(fp))
179 {
180 return false;
181 }
182 rendered += _pMfroAtom->getSize();
183
184 return true;
185 }
186