Bug Summary

File:build-analysis/../src/plugins/mp4/mp4ff/mp4atom.c
Warning:line 371, column 5
Value stored to 'size' is never read

Annotated Source Code

1/*
2** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18**
19** Any non-GPL usage of this software or parts of this software is strictly
20** forbidden.
21**
22** The "appropriate copyright message" mentioned in section 2c of the GPLv2
23** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
24**
25** Commercial non-GPL licensing of this software is possible.
26** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
27**
28** $Id: mp4atom.c,v 1.29 2009/01/19 23:56:30 menno Exp $
29**/
30
31#include <stdlib.h>
32#ifdef HAVE_CONFIG_H
33#include "config.h"
34#elif _WIN32
35#include <tchar.h>
36#include <windows.h>
37#endif
38#ifdef HAVE_GETPWUID
39# include <pwd.h>
40#endif
41#ifdef HAVE_STRING_H
42# include <string.h>
43#endif
44#include "mp4ffint.h"
45
46#define COPYRIGHT_SYMBOL((int8_t)0xA9) ((int8_t)0xA9)
47
48/* parse atom header size */
49int32_t mp4ff_atom_get_size(const uint8_t *data)
50{
51 uint32_t result;
52 uint32_t a, b, c, d;
53
54 a = (uint8_t)data[0];
55 b = (uint8_t)data[1];
56 c = (uint8_t)data[2];
57 d = (uint8_t)data[3];
58
59 result = (a<<24) | (b<<16) | (c<<8) | d;
60 //if (result > 0 && result < 8) result = 8;
61
62 return (int32_t)result;
63}
64
65/* comnapre 2 atom names, returns 1 for equal, 0 for unequal */
66int32_t mp4ff_atom_compare(const int8_t a1, const int8_t b1, const int8_t c1, const int8_t d1,
67 const int8_t a2, const int8_t b2, const int8_t c2, const int8_t d2)
68{
69 if (a1 == a2 && b1 == b2 && c1 == c2 && d1 == d2)
70 return 1;
71 else
72 return 0;
73}
74
75uint8_t mp4ff_atom_name_to_type(const int8_t a, const int8_t b,
76 const int8_t c, const int8_t d)
77{
78 if (a == 'm')
79 {
80 if (mp4ff_atom_compare(a,b,c,d, 'm','o','o','v'))
81 return ATOM_MOOV1;
82 else if (mp4ff_atom_compare(a,b,c,d, 'm','i','n','f'))
83 return ATOM_MINF5;
84 else if (mp4ff_atom_compare(a,b,c,d, 'm','d','i','a'))
85 return ATOM_MDIA4;
86 else if (mp4ff_atom_compare(a,b,c,d, 'm','d','a','t'))
87 return ATOM_MDAT130;
88 else if (mp4ff_atom_compare(a,b,c,d, 'm','d','h','d'))
89 return ATOM_MDHD134;
90 else if (mp4ff_atom_compare(a,b,c,d, 'm','v','h','d'))
91 return ATOM_MVHD131;
92 else if (mp4ff_atom_compare(a,b,c,d, 'm','p','4','a'))
93 return ATOM_MP4A144;
94 else if (mp4ff_atom_compare(a,b,c,d, 'm','p','4','v'))
95 return ATOM_MP4V145;
96 else if (mp4ff_atom_compare(a,b,c,d, 'm','p','4','s'))
97 return ATOM_MP4S146;
98 else if (mp4ff_atom_compare(a,b,c,d, 'm','e','t','a'))
99 return ATOM_META148;
100 } else if (a == 't') {
101 if (mp4ff_atom_compare(a,b,c,d, 't','r','a','k'))
102 return ATOM_TRAK2;
103 else if (mp4ff_atom_compare(a,b,c,d, 't','k','h','d'))
104 return ATOM_TKHD132;
105 else if (mp4ff_atom_compare(a,b,c,d, 't','r','e','f'))
106 return ATOM_TREF133;
107 else if (mp4ff_atom_compare(a,b,c,d, 't','r','k','n'))
108 return ATOM_TRACK17;
109 else if (mp4ff_atom_compare(a,b,c,d, 't','m','p','o'))
110 return ATOM_TEMPO21;
111 else if (mp4ff_atom_compare(a,b,c,d, 't','v','n','n'))
112 return ATOM_NETWORK161;
113 else if (mp4ff_atom_compare(a,b,c,d, 't','v','s','h'))
114 return ATOM_SHOW162;
115 else if (mp4ff_atom_compare(a,b,c,d, 't','v','e','n'))
116 return ATOM_EPISODENAME163;
117 else if (mp4ff_atom_compare(a,b,c,d, 't','v','s','n'))
118 return ATOM_SEASON170;
119 else if (mp4ff_atom_compare(a,b,c,d, 't','v','e','s'))
120 return ATOM_EPISODE171;
121 } else if (a == 's') {
122 if (mp4ff_atom_compare(a,b,c,d, 's','t','b','l'))
123 return ATOM_STBL6;
124 else if (mp4ff_atom_compare(a,b,c,d, 's','m','h','d'))
125 return ATOM_SMHD136;
126 else if (mp4ff_atom_compare(a,b,c,d, 's','t','s','d'))
127 return ATOM_STSD138;
128 else if (mp4ff_atom_compare(a,b,c,d, 's','t','t','s'))
129 return ATOM_STTS139;
130 else if (mp4ff_atom_compare(a,b,c,d, 's','t','c','o'))
131 return ATOM_STCO142;
132 else if (mp4ff_atom_compare(a,b,c,d, 's','t','s','c'))
133 return ATOM_STSC143;
134 else if (mp4ff_atom_compare(a,b,c,d, 's','t','s','z'))
135 return ATOM_STSZ140;
136 else if (mp4ff_atom_compare(a,b,c,d, 's','t','z','2'))
137 return ATOM_STZ2141;
138 else if (mp4ff_atom_compare(a,b,c,d, 's','k','i','p'))
139 return ATOM_SKIP255;
140 else if (mp4ff_atom_compare(a,b,c,d, 's','i','n','f'))
141 return ATOM_SINF24;
142 else if (mp4ff_atom_compare(a,b,c,d, 's','c','h','i'))
143 return ATOM_SCHI25;
144 else if (mp4ff_atom_compare(a,b,c,d, 's','o','n','m'))
145 return ATOM_SORTTITLE164;
146 else if (mp4ff_atom_compare(a,b,c,d, 's','o','a','l'))
147 return ATOM_SORTALBUM165;
148 else if (mp4ff_atom_compare(a,b,c,d, 's','o','a','r'))
149 return ATOM_SORTARTIST166;
150 else if (mp4ff_atom_compare(a,b,c,d, 's','o','a','a'))
151 return ATOM_SORTALBUMARTIST167;
152 else if (mp4ff_atom_compare(a,b,c,d, 's','o','c','o'))
153 return ATOM_SORTWRITER168;
154 else if (mp4ff_atom_compare(a,b,c,d, 's','o','s','n'))
155 return ATOM_SORTSHOW169;
156 } else if (a == COPYRIGHT_SYMBOL((int8_t)0xA9)) {
157 if (mp4ff_atom_compare(a,b,c,d, COPYRIGHT_SYMBOL((int8_t)0xA9),'n','a','m'))
158 return ATOM_TITLE9;
159 else if (mp4ff_atom_compare(a,b,c,d, COPYRIGHT_SYMBOL((int8_t)0xA9),'A','R','T'))
160 return ATOM_ARTIST10;
161 else if (mp4ff_atom_compare(a,b,c,d, COPYRIGHT_SYMBOL((int8_t)0xA9),'w','r','t'))
162 return ATOM_WRITER11;
163 else if (mp4ff_atom_compare(a,b,c,d, COPYRIGHT_SYMBOL((int8_t)0xA9),'a','l','b'))
164 return ATOM_ALBUM12;
165 else if (mp4ff_atom_compare(a,b,c,d, COPYRIGHT_SYMBOL((int8_t)0xA9),'d','a','y'))
166 return ATOM_DATE13;
167 else if (mp4ff_atom_compare(a,b,c,d, COPYRIGHT_SYMBOL((int8_t)0xA9),'t','o','o'))
168 return ATOM_TOOL14;
169 else if (mp4ff_atom_compare(a,b,c,d, COPYRIGHT_SYMBOL((int8_t)0xA9),'c','m','t'))
170 return ATOM_COMMENT15;
171 else if (mp4ff_atom_compare(a,b,c,d, COPYRIGHT_SYMBOL((int8_t)0xA9),'g','e','n'))
172 return ATOM_GENRE116;
173 else if (mp4ff_atom_compare(a,b,c,d, COPYRIGHT_SYMBOL((int8_t)0xA9),'g','r','p'))
174 return ATOM_CONTENTGROUP158;
175 else if (mp4ff_atom_compare(a,b,c,d, COPYRIGHT_SYMBOL((int8_t)0xA9),'l','y','r'))
176 return ATOM_LYRICS159;
177 }
178
179 if (mp4ff_atom_compare(a,b,c,d, 'e','d','t','s'))
180 return ATOM_EDTS3;
181 else if (mp4ff_atom_compare(a,b,c,d, 'e','s','d','s'))
182 return ATOM_ESDS147;
183 else if (mp4ff_atom_compare(a,b,c,d, 'f','t','y','p'))
184 return ATOM_FTYP129;
185 else if (mp4ff_atom_compare(a,b,c,d, 'f','r','e','e'))
186 return ATOM_FREE255;
187 else if (mp4ff_atom_compare(a,b,c,d, 'h','m','h','d'))
188 return ATOM_HMHD137;
189 else if (mp4ff_atom_compare(a,b,c,d, 'v','m','h','d'))
190 return ATOM_VMHD135;
191 else if (mp4ff_atom_compare(a,b,c,d, 'u','d','t','a'))
192 return ATOM_UDTA7;
193 else if (mp4ff_atom_compare(a,b,c,d, 'i','l','s','t'))
194 return ATOM_ILST8;
195 else if (mp4ff_atom_compare(a,b,c,d, 'n','a','m','e'))
196 return ATOM_NAME149;
197 else if (mp4ff_atom_compare(a,b,c,d, 'd','a','t','a'))
198 return ATOM_DATA150;
199 else if (mp4ff_atom_compare(a,b,c,d, 'd','i','s','k'))
200 return ATOM_DISC18;
201 else if (mp4ff_atom_compare(a,b,c,d, 'g','n','r','e'))
202 return ATOM_GENRE220;
203 else if (mp4ff_atom_compare(a,b,c,d, 'c','o','v','r'))
204 return ATOM_COVER22;
205 else if (mp4ff_atom_compare(a,b,c,d, 'c','p','i','l'))
206 return ATOM_COMPILATION19;
207 else if (mp4ff_atom_compare(a,b,c,d, 'c','t','t','s'))
208 return ATOM_CTTS151;
209 else if (mp4ff_atom_compare(a,b,c,d, 'd','r','m','s'))
210 return ATOM_DRMS23;
211 else if (mp4ff_atom_compare(a,b,c,d, 'f','r','m','a'))
212 return ATOM_FRMA152;
213 else if (mp4ff_atom_compare(a,b,c,d, 'p','r','i','v'))
214 return ATOM_PRIV154;
215 else if (mp4ff_atom_compare(a,b,c,d, 'i','v','i','v'))
216 return ATOM_IVIV153;
217 else if (mp4ff_atom_compare(a,b,c,d, 'u','s','e','r'))
218 return ATOM_USER155;
219 else if (mp4ff_atom_compare(a,b,c,d, 'k','e','y',' '))
220 return ATOM_KEY156;
221 else if (mp4ff_atom_compare(a,b,c,d, 'a','l','a','c'))
222 return ATOM_ALAC192;
223 else if (mp4ff_atom_compare(a,b,c,d, 'a','A','R','T'))
224 return ATOM_ALBUM_ARTIST157;
225 else if (mp4ff_atom_compare(a,b,c,d, 'd','e','s','c'))
226 return ATOM_DESCRIPTION160;
227 else if (mp4ff_atom_compare(a,b,c,d, 'p','c','s','t'))
228 return ATOM_PODCAST172;
229 else
230 return ATOM_UNKNOWN255;
231}
232
233/* read atom header, return atom size, atom size is with header included */
234uint64_t mp4ff_atom_read_header(mp4ff_t *f, uint8_t *atom_type, uint8_t *header_size)
235{
236 uint64_t size;
237 int32_t ret;
238 uint8_t atom_header[8];
239
240 ret = mp4ff_read_data(f, atom_header, 8);
241 if (ret != 8)
242 return 0;
243
244 size = mp4ff_atom_get_size(atom_header);
245 *header_size = 8;
246
247 /* check for 64 bit atom size */
248 if (size == 1)
249 {
250 *header_size = 16;
251 size = mp4ff_read_int64(f);
252 }
253
254 //printf("%c%c%c%c\n", atom_header[4], atom_header[5], atom_header[6], atom_header[7]);
255
256 *atom_type = mp4ff_atom_name_to_type(atom_header[4], atom_header[5], atom_header[6], atom_header[7]);
257
258 return size;
259}
260
261int32_t mp4ff_read_stsz(mp4ff_t *f)
262{
263 mp4ff_read_char(f); /* version */
264 mp4ff_read_int24(f); /* flags */
265 f->track[f->total_tracks - 1]->stsz_sample_size = mp4ff_read_int32(f);
266 f->track[f->total_tracks - 1]->stsz_sample_count = mp4ff_read_int32(f);
267
268 if (f->track[f->total_tracks - 1]->stsz_sample_size == 0)
269 {
270 int32_t i;
271 f->track[f->total_tracks - 1]->stsz_table =
272 (int32_t*)malloc(f->track[f->total_tracks - 1]->stsz_sample_count*sizeof(int32_t));
273
274 for (i = 0; i < f->track[f->total_tracks - 1]->stsz_sample_count; i++)
275 {
276 f->track[f->total_tracks - 1]->stsz_table[i] = mp4ff_read_int32(f);
277 }
278 }
279
280 return 0;
281}
282
283int32_t mp4ff_read_esds(mp4ff_t *f)
284{
285 uint8_t tag;
286 uint32_t temp;
287
288 mp4ff_read_char(f); /* version */
289 mp4ff_read_int24(f); /* flags */
290
291 /* get and verify ES_DescrTag */
292 tag = mp4ff_read_char(f);
293 if (tag == 0x03)
294 {
295 /* read length */
296 if (mp4ff_read_mp4_descr_length(f) < 5 + 15)
297 {
298 return 1;
299 }
300 /* skip 3 bytes */
301 mp4ff_read_int24(f);
302 } else {
303 /* skip 2 bytes */
304 mp4ff_read_int16(f);
305 }
306
307 /* get and verify DecoderConfigDescrTab */
308 if (mp4ff_read_char(f) != 0x04)
309 {
310 return 1;
311 }
312
313 /* read length */
314 temp = mp4ff_read_mp4_descr_length(f);
315 if (temp < 13) return 1;
316
317 f->track[f->total_tracks - 1]->audioType = mp4ff_read_char(f);
318 mp4ff_read_int32(f);//0x15000414 ????
319 f->track[f->total_tracks - 1]->maxBitrate = mp4ff_read_int32(f);
320 f->track[f->total_tracks - 1]->avgBitrate = mp4ff_read_int32(f);
321
322 /* get and verify DecSpecificInfoTag */
323 if (mp4ff_read_char(f) != 0x05)
324 {
325 return 1;
326 }
327
328 /* read length */
329 f->track[f->total_tracks - 1]->decoderConfigLen = mp4ff_read_mp4_descr_length(f);
330
331 if (f->track[f->total_tracks - 1]->decoderConfig)
332 free(f->track[f->total_tracks - 1]->decoderConfig);
333 f->track[f->total_tracks - 1]->decoderConfig = malloc(f->track[f->total_tracks - 1]->decoderConfigLen);
334 if (f->track[f->total_tracks - 1]->decoderConfig)
335 {
336 mp4ff_read_data(f, f->track[f->total_tracks - 1]->decoderConfig, f->track[f->total_tracks - 1]->decoderConfigLen);
337 } else {
338 f->track[f->total_tracks - 1]->decoderConfigLen = 0;
339 }
340
341 /* will skip the remainder of the atom */
342 return 0;
343}
344
345int32_t mp4ff_read_mp4a(mp4ff_t *f)
346{
347 uint64_t size;
348 int32_t i;
349 uint8_t atom_type = 0;
350 uint8_t header_size = 0;
351
352 for (i = 0; i < 6; i++)
353 {
354 mp4ff_read_char(f); /* reserved */
355 }
356 /* data_reference_index */ mp4ff_read_int16(f);
357
358 mp4ff_read_int32(f); /* reserved */
359 mp4ff_read_int32(f); /* reserved */
360
361 f->track[f->total_tracks - 1]->channelCount = mp4ff_read_int16(f);
362 f->track[f->total_tracks - 1]->sampleSize = mp4ff_read_int16(f);
363
364 mp4ff_read_int16(f);
365 mp4ff_read_int16(f);
366
367 f->track[f->total_tracks - 1]->sampleRate = mp4ff_read_int16(f);
368
369 mp4ff_read_int16(f);
370
371 size = mp4ff_atom_read_header(f, &atom_type, &header_size);
Value stored to 'size' is never read
372 if (atom_type == ATOM_ESDS147)
373 {
374 mp4ff_read_esds(f);
375 }
376
377 return 0;
378}
379
380int32_t mp4ff_read_alac(mp4ff_t *f)
381{
382 mp4ff_track_t *current_track = f->track[f->total_tracks - 1];
383
384 mp4ff_read_int32(f);
385 mp4ff_read_int32(f);
386 mp4ff_read_int32(f);
387 mp4ff_read_int32(f);
388 mp4ff_read_int32(f);
389 mp4ff_read_int32(f);
390 mp4ff_read_int32(f);
391
392 current_track->decoderConfigLen = 36;
393 if (current_track->decoderConfig)
394 free(current_track->decoderConfig);
395 current_track->decoderConfig = calloc(1, current_track->decoderConfigLen);
396
397 if (current_track->decoderConfig)
398 {
399 mp4ff_read_data(f, current_track->decoderConfig,
400 current_track->decoderConfigLen);
401 } else {
402 current_track->decoderConfigLen = 0;
403 }
404
405 current_track->channelCount = current_track->decoderConfig[21];
406 current_track->avgBitrate = (current_track->decoderConfig[28] << 24) |
407 (current_track->decoderConfig[29] << 16) |
408 (current_track->decoderConfig[30] << 8) |
409 current_track->decoderConfig[31];
410 current_track->sampleRate = (current_track->decoderConfig[32] << 24) |
411 (current_track->decoderConfig[33] << 16) |
412 (current_track->decoderConfig[34] << 8) |
413 current_track->decoderConfig[35];
414 current_track->audioType = 0xff;
415
416 /* will skip the remainder of the atom */
417 return 0;
418}
419
420int32_t mp4ff_read_stsd(mp4ff_t *f)
421{
422 int32_t i;
423 uint8_t header_size = 0;
424
425 mp4ff_read_char(f); /* version */
426 mp4ff_read_int24(f); /* flags */
427
428 f->track[f->total_tracks - 1]->stsd_entry_count = mp4ff_read_int32(f);
429
430 for (i = 0; i < f->track[f->total_tracks - 1]->stsd_entry_count; i++)
431 {
432 uint64_t skip = mp4ff_position(f);
433 uint64_t size;
434 uint8_t atom_type = 0;
435 size = mp4ff_atom_read_header(f, &atom_type, &header_size);
436 skip += size;
437
438 if (atom_type == ATOM_MP4A144)
439 {
440 f->track[f->total_tracks - 1]->type = TRACK_AUDIO1;
441 mp4ff_read_mp4a(f);
442 } else if (atom_type == ATOM_ALAC192) {
443 f->track[f->total_tracks - 1]->type = TRACK_AUDIO1;
444 mp4ff_read_alac(f);
445 } else if (atom_type == ATOM_MP4V145) {
446 f->track[f->total_tracks - 1]->type = TRACK_VIDEO2;
447 } else if (atom_type == ATOM_MP4S146) {
448 f->track[f->total_tracks - 1]->type = TRACK_SYSTEM3;
449 } else {
450 f->track[f->total_tracks - 1]->type = TRACK_UNKNOWN0;
451 }
452
453 mp4ff_set_position(f, skip);
454 }
455
456 return 0;
457}
458
459int32_t mp4ff_read_stsc(mp4ff_t *f)
460{
461 int32_t i;
462
463 mp4ff_read_char(f); /* version */
464 mp4ff_read_int24(f); /* flags */
465 f->track[f->total_tracks - 1]->stsc_entry_count = mp4ff_read_int32(f);
466
467 f->track[f->total_tracks - 1]->stsc_first_chunk =
468 (int32_t*)malloc(f->track[f->total_tracks - 1]->stsc_entry_count*sizeof(int32_t));
469 f->track[f->total_tracks - 1]->stsc_samples_per_chunk =
470 (int32_t*)malloc(f->track[f->total_tracks - 1]->stsc_entry_count*sizeof(int32_t));
471 f->track[f->total_tracks - 1]->stsc_sample_desc_index =
472 (int32_t*)malloc(f->track[f->total_tracks - 1]->stsc_entry_count*sizeof(int32_t));
473
474 for (i = 0; i < f->track[f->total_tracks - 1]->stsc_entry_count; i++)
475 {
476 f->track[f->total_tracks - 1]->stsc_first_chunk[i] = mp4ff_read_int32(f);
477 f->track[f->total_tracks - 1]->stsc_samples_per_chunk[i] = mp4ff_read_int32(f);
478 f->track[f->total_tracks - 1]->stsc_sample_desc_index[i] = mp4ff_read_int32(f);
479 }
480
481 return 0;
482}
483
484int32_t mp4ff_read_stco(mp4ff_t *f)
485{
486 int32_t i;
487
488 mp4ff_read_char(f); /* version */
489 mp4ff_read_int24(f); /* flags */
490 f->track[f->total_tracks - 1]->stco_entry_count = mp4ff_read_int32(f);
491
492 f->track[f->total_tracks - 1]->stco_chunk_offset =
493 (int32_t*)malloc(f->track[f->total_tracks - 1]->stco_entry_count*sizeof(int32_t));
494
495 for (i = 0; i < f->track[f->total_tracks - 1]->stco_entry_count; i++)
496 {
497 f->track[f->total_tracks - 1]->stco_chunk_offset[i] = mp4ff_read_int32(f);
498 }
499
500 return 0;
501}
502
503static int32_t mp4ff_read_ctts(mp4ff_t *f)
504{
505 int32_t i;
506 mp4ff_track_t * p_track = f->track[f->total_tracks - 1];
507
508 if (p_track->ctts_entry_count) return 0;
509
510 mp4ff_read_char(f); /* version */
511 mp4ff_read_int24(f); /* flags */
512 p_track->ctts_entry_count = mp4ff_read_int32(f);
513
514 p_track->ctts_sample_count = (int32_t*)malloc(p_track->ctts_entry_count * sizeof(int32_t));
515 p_track->ctts_sample_offset = (int32_t*)malloc(p_track->ctts_entry_count * sizeof(int32_t));
516
517 if (p_track->ctts_sample_count == 0 || p_track->ctts_sample_offset == 0)
518 {
519 if (p_track->ctts_sample_count) {free(p_track->ctts_sample_count);p_track->ctts_sample_count=0;}
520 if (p_track->ctts_sample_offset) {free(p_track->ctts_sample_offset);p_track->ctts_sample_offset=0;}
521 p_track->ctts_entry_count = 0;
522 return 0;
523 }
524 else
525 {
526 for (i = 0; i < f->track[f->total_tracks - 1]->ctts_entry_count; i++)
527 {
528 p_track->ctts_sample_count[i] = mp4ff_read_int32(f);
529 p_track->ctts_sample_offset[i] = mp4ff_read_int32(f);
530 }
531 return 1;
532 }
533}
534
535int32_t mp4ff_read_stts(mp4ff_t *f)
536{
537 int32_t i;
538 mp4ff_track_t * p_track = f->track[f->total_tracks - 1];
539
540 if (p_track->stts_entry_count) return 0;
541
542 mp4ff_read_char(f); /* version */
543 mp4ff_read_int24(f); /* flags */
544 p_track->stts_entry_count = mp4ff_read_int32(f);
545
546 p_track->stts_sample_count = (int32_t*)malloc(p_track->stts_entry_count * sizeof(int32_t));
547 p_track->stts_sample_delta = (int32_t*)malloc(p_track->stts_entry_count * sizeof(int32_t));
548
549 if (p_track->stts_sample_count == 0 || p_track->stts_sample_delta == 0)
550 {
551 if (p_track->stts_sample_count) {free(p_track->stts_sample_count);p_track->stts_sample_count=0;}
552 if (p_track->stts_sample_delta) {free(p_track->stts_sample_delta);p_track->stts_sample_delta=0;}
553 p_track->stts_entry_count = 0;
554 return 0;
555 }
556 else
557 {
558 for (i = 0; i < f->track[f->total_tracks - 1]->stts_entry_count; i++)
559 {
560 p_track->stts_sample_count[i] = mp4ff_read_int32(f);
561 p_track->stts_sample_delta[i] = mp4ff_read_int32(f);
562 }
563 return 1;
564 }
565}
566
567static int32_t mp4ff_read_mvhd(mp4ff_t *f)
568{
569 int32_t i;
570
571 mp4ff_read_char(f); /* version */
572 mp4ff_read_int24(f); /* flags */
573 /* creation_time */ mp4ff_read_int32(f);
574 /* modification_time */ mp4ff_read_int32(f);
575 f->time_scale = mp4ff_read_int32(f);
576 f->duration = mp4ff_read_int32(f);
577 /* preferred_rate */ mp4ff_read_int32(f); /*mp4ff_read_fixed32(f);*/
578 /* preferred_volume */ mp4ff_read_int16(f); /*mp4ff_read_fixed16(f);*/
579 for (i = 0; i < 10; i++)
580 {
581 /* reserved */ mp4ff_read_char(f);
582 }
583 for (i = 0; i < 9; i++)
584 {
585 mp4ff_read_int32(f); /* matrix */
586 }
587 /* preview_time */ mp4ff_read_int32(f);
588 /* preview_duration */ mp4ff_read_int32(f);
589 /* poster_time */ mp4ff_read_int32(f);
590 /* selection_time */ mp4ff_read_int32(f);
591 /* selection_duration */ mp4ff_read_int32(f);
592 /* current_time */ mp4ff_read_int32(f);
593 /* next_track_id */ mp4ff_read_int32(f);
594
595 return 0;
596}
597
598#if 0
599static int32_t mp4ff_read_tkhd(mp4ff_t *f)
600{
601 uint8_t version;
602 uint32_t flags;
603 version = mp4ff_read_char(f); /* version */
604 flags = mp4ff_read_int24(f); /* flags */
605 if (version==1)
606 {
607 mp4ff_read_int64(f);//creation-time
608 mp4ff_read_int64(f);//modification-time
609 mp4ff_read_int32(f);//track-id
610 mp4ff_read_int32(f);//reserved
611 f->track[f->total_tracks - 1]->duration = mp4ff_read_int64(f);//duration
612 }
613 else //version == 0
614 {
615 mp4ff_read_int32(f);//creation-time
616 mp4ff_read_int32(f);//modification-time
617 mp4ff_read_int32(f);//track-id
618 mp4ff_read_int32(f);//reserved
619 f->track[f->total_tracks - 1]->duration = mp4ff_read_int32(f);//duration
620 if (f->track[f->total_tracks - 1]->duration == 0xFFFFFFFF)
621 f->track[f->total_tracks - 1]->duration = 0xFFFFFFFFFFFFFFFF;
622
623 }
624 mp4ff_read_int32(f);//reserved
625 mp4ff_read_int32(f);//reserved
626 mp4ff_read_int16(f);//layer
627 mp4ff_read_int16(f);//pre-defined
628 mp4ff_read_int16(f);//volume
629 mp4ff_read_int16(f);//reserved
630
631 //matrix
632 mp4ff_read_int32(f); mp4ff_read_int32(f); mp4ff_read_int32(f);
633 mp4ff_read_int32(f); mp4ff_read_int32(f); mp4ff_read_int32(f);
634 mp4ff_read_int32(f); mp4ff_read_int32(f); mp4ff_read_int32(f);
635 mp4ff_read_int32(f);//width
636 mp4ff_read_int32(f);//height
637 return 1;
638}
639#endif
640
641static int32_t mp4ff_read_mdhd(mp4ff_t *f)
642{
643 uint32_t version;
644
645 version = mp4ff_read_int32(f);
646 if (version==1)
647 {
648 mp4ff_read_int64(f);//creation-time
649 mp4ff_read_int64(f);//modification-time
650 f->track[f->total_tracks - 1]->timeScale = mp4ff_read_int32(f);//timescale
651 f->track[f->total_tracks - 1]->duration = mp4ff_read_int64(f);//duration
652 }
653 else //version == 0
654 {
655 uint32_t temp;
656
657 mp4ff_read_int32(f);//creation-time
658 mp4ff_read_int32(f);//modification-time
659 f->track[f->total_tracks - 1]->timeScale = mp4ff_read_int32(f);//timescale
660 temp = mp4ff_read_int32(f);
661 f->track[f->total_tracks - 1]->duration = (temp == (uint32_t)(-1)) ? (uint64_t)(-1) : (uint64_t)(temp);
662 }
663 mp4ff_read_int16(f);
664 mp4ff_read_int16(f);
665 return 1;
666}
667#ifdef USE_TAGGING1
668int32_t mp4ff_read_meta(mp4ff_t *f, const uint64_t size)
669{
670 uint64_t subsize, sumsize = 0;
671 uint8_t atom_type;
672 uint8_t header_size = 0;
673
674 mp4ff_read_char(f); /* version */
675 mp4ff_read_int24(f); /* flags */
676
677 while (sumsize < (size-(header_size+4)))
678 {
679 subsize = mp4ff_atom_read_header(f, &atom_type, &header_size);
680 if (subsize <= header_size+4)
681 return 1;
682 if (atom_type == ATOM_ILST8)
683 {
684 mp4ff_parse_metadata(f, (uint32_t)(subsize-(header_size+4)));
685 } else {
686 mp4ff_set_position(f, mp4ff_position(f)+subsize-header_size);
687 }
688 sumsize += subsize;
689 }
690
691 return 0;
692}
693#endif
694
695int32_t mp4ff_atom_read(mp4ff_t *f, const int32_t size, const uint8_t atom_type)
696{
697 uint64_t dest_position = mp4ff_position(f)+size-8;
698 if (atom_type == ATOM_STSZ140)
699 {
700 /* sample size box */
701 mp4ff_read_stsz(f);
702 } else if (atom_type == ATOM_STTS139) {
703 /* time to sample box */
704 mp4ff_read_stts(f);
705 } else if (atom_type == ATOM_CTTS151) {
706 /* composition offset box */
707 mp4ff_read_ctts(f);
708 } else if (atom_type == ATOM_STSC143) {
709 /* sample to chunk box */
710 mp4ff_read_stsc(f);
711 } else if (atom_type == ATOM_STCO142) {
712 /* chunk offset box */
713 mp4ff_read_stco(f);
714 } else if (atom_type == ATOM_STSD138) {
715 /* sample description box */
716 mp4ff_read_stsd(f);
717 } else if (atom_type == ATOM_MVHD131) {
718 /* movie header box */
719 mp4ff_read_mvhd(f);
720 } else if (atom_type == ATOM_MDHD134) {
721 /* track header */
722 mp4ff_read_mdhd(f);
723#ifdef USE_TAGGING1
724 } else if (atom_type == ATOM_META148) {
725 /* iTunes Metadata box */
726 mp4ff_read_meta(f, size);
727#endif
728 }
729
730 mp4ff_set_position(f, dest_position);
731
732
733 return 0;
734}