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_TrackFragmentRandomAccessAtom
19
20 #include "trackfragmentrandomaccess.h"
21 #include "atomutils.h"
22 #include "atomdefs.h"
23
24 typedef Oscl_Vector<TFRAEntries*, OsclMemAllocator> TFRAEntriesVecType;
25
TFRAEntries(MP4_FF_FILE * fp,uint32 version,uint8 length_size_of_traf_num,uint8 length_size_of_trun_num,uint8 length_size_of_sample_num)26 TFRAEntries::TFRAEntries(MP4_FF_FILE *fp , uint32 version,
27 uint8 length_size_of_traf_num,
28 uint8 length_size_of_trun_num,
29 uint8 length_size_of_sample_num)
30 {
31 _version = version;
32 _time64 = 0;
33 _moof_offset64 = 0;
34 _time32 = 0;
35 _moof_offset32 = 0;
36 _traf_number = 0;
37 _trun_number = 0;
38 _sample_number = 0;
39
40 if (_version == 1)
41 {
42 if (!AtomUtils::read64(fp, _time64))
43 {
44 return;
45 }
46 if (!AtomUtils::read64(fp, _moof_offset64))
47 {
48 return;
49 }
50 }
51 else
52 {
53 if (!AtomUtils::read32(fp, _time32))
54 {
55 return;
56 }
57 if (!AtomUtils::read32(fp, _moof_offset32))
58 {
59 return;
60 }
61
62 }
63 switch (length_size_of_traf_num)
64 {
65 case 0:
66 {
67 uint8 tmp = 0;
68 if (!AtomUtils::read8(fp, tmp))
69 {
70 return;
71 }
72 _traf_number = tmp;
73 }
74 break;
75 case 1:
76 {
77 uint16 tmp = 0;
78 if (!AtomUtils::read16(fp, tmp))
79 {
80 return;
81 }
82 _traf_number = tmp;
83 }
84 break;
85 case 2:
86 if (!AtomUtils::read24(fp, _traf_number))
87 {
88 return;
89 }
90 break;
91 case 3:
92 if (!AtomUtils::read32(fp, _traf_number))
93 {
94 return;
95 }
96 break;
97 }
98
99 switch (length_size_of_trun_num)
100 {
101 case 0:
102 {
103 uint8 tmp = 0;
104 if (!AtomUtils::read8(fp, tmp))
105 {
106 return;
107 }
108 _trun_number = tmp;
109 }
110 break;
111 case 1:
112 {
113 uint16 tmp = 0;
114 if (!AtomUtils::read16(fp, tmp))
115 {
116 return;
117 }
118 _trun_number = tmp;
119 }
120 break;
121 case 2:
122 if (!AtomUtils::read24(fp, _trun_number))
123 {
124 return;
125 }
126 break;
127 case 3:
128 if (!AtomUtils::read32(fp, _trun_number))
129 {
130 return;
131 }
132 break;
133 }
134
135 switch (length_size_of_sample_num)
136 {
137 case 0:
138 {
139 uint8 tmp = 0;
140 if (!AtomUtils::read8(fp, tmp))
141 {
142 return;
143 }
144 _sample_number = tmp;
145 }
146 break;
147 case 1:
148 {
149 uint16 tmp = 0;
150 if (!AtomUtils::read16(fp, tmp))
151 {
152 return;
153 }
154 _sample_number = tmp;
155 }
156 break;
157 case 2:
158 if (!AtomUtils::read24(fp, _sample_number))
159 {
160 return;
161 }
162 break;
163 case 3:
164 if (!AtomUtils::read32(fp, _sample_number))
165 {
166 return;
167 }
168 break;
169 }
170
171 }
172
TrackFragmentRandomAccessAtom(MP4_FF_FILE * fp,uint32 size,uint32 type)173 TrackFragmentRandomAccessAtom ::TrackFragmentRandomAccessAtom(MP4_FF_FILE *fp, uint32 size, uint32 type)
174 : FullAtom(fp, size, type)
175 {
176 OSCL_UNUSED_ARG(type);
177 _trackId = 0;
178 _length_size_of_traf_num = 0;
179 _length_size_of_trun_num = 0;
180 _length_size_of_sample_num = 0;
181 _entry_count = 0;
182 _version = getVersion();
183
184 iLogger = PVLogger::GetLoggerObject("mp4ffparser");
185 iStateVarLogger = PVLogger::GetLoggerObject("mp4ffparser_mediasamplestats");
186 iParsedDataLogger = PVLogger::GetLoggerObject("mp4ffparser_parseddata");
187
188 if (_success)
189 {
190 PV_MP4_FF_NEW(fp->auditCB, TFRAEntriesVecType, (), _pTFRAEntriesVec);
191
192 if (!AtomUtils::read32(fp, _trackId))
193 {
194 _success = false;
195 _mp4ErrorCode = READ_TRACK_FRAGMENT_RANDOM_ACCESS_ATOM_FAILED;
196 return;
197 }
198
199 if (!AtomUtils::read32(fp, _reserved))
200 {
201 _success = false;
202 _mp4ErrorCode = READ_TRACK_FRAGMENT_RANDOM_ACCESS_ATOM_FAILED;
203 return;
204 }
205 _length_size_of_traf_num = (_reserved & 0x00000003);
206 _length_size_of_trun_num = ((_reserved >> 2) & 0x00000003);
207 _length_size_of_sample_num = ((_reserved >> 4) & 0x00000003);
208
209 if (!AtomUtils::read32(fp, _entry_count))
210 {
211 _success = false;
212 _mp4ErrorCode = READ_TRACK_FRAGMENT_RANDOM_ACCESS_ATOM_FAILED;
213 return;
214 }
215 for (uint32 idx = 0; idx < _entry_count ; idx++)
216 {
217 TFRAEntries *pTFRAEntries = NULL;
218 PV_MP4_FF_NEW(fp->auditCB, TFRAEntries, (fp, _version, _length_size_of_traf_num,
219 _length_size_of_trun_num,
220 _length_size_of_sample_num),
221 pTFRAEntries);
222 _pTFRAEntriesVec->push_back(pTFRAEntries);
223 PVMF_MP4FFPARSER_LOGMEDIASAMPELSTATEVARIABLES((0, "TrackFragmentRandom Access Point _sample_number[%d] =%d", idx, pTFRAEntries->_sample_number));
224 PVMF_MP4FFPARSER_LOGMEDIASAMPELSTATEVARIABLES((0, "TrackFragmentRandom Access Point TimeStamp [%d] =%d", idx, pTFRAEntries->getTimeStamp()));
225 PVMF_MP4FFPARSER_LOGMEDIASAMPELSTATEVARIABLES((0, "TrackFragmentRandom Access Point MoofOffset [%d] =%d", idx, pTFRAEntries->getTimeMoofOffset()));
226 PVMF_MP4FFPARSER_LOGMEDIASAMPELSTATEVARIABLES((0, "TrackFragmentRandom Access Point _traf_number [%d] =%d", idx, pTFRAEntries->_traf_number));
227 PVMF_MP4FFPARSER_LOGMEDIASAMPELSTATEVARIABLES((0, "TrackFragmentRandom Access Point _trun_number [%d] =%d", idx, pTFRAEntries->_trun_number));
228
229 }
230
231 }
232 }
233 // Destructor
~TrackFragmentRandomAccessAtom()234 TrackFragmentRandomAccessAtom::~TrackFragmentRandomAccessAtom()
235 {
236 if (_pTFRAEntriesVec != NULL)
237 {
238 // CLEAN UP VECTOR!!
239 for (uint32 i = 0; i < _pTFRAEntriesVec->size(); i++)
240 {
241 PV_MP4_FF_DELETE(NULL, TFRAEntries, (*_pTFRAEntriesVec)[i]);
242 }
243 PV_MP4_FF_TEMPLATED_DELETE(NULL, TFRAEntriesVecType, Oscl_Vector, _pTFRAEntriesVec);
244 }
245
246 }
247
248
249