annotate Plugins/Input/aac/mp4ff/mp4atom.c @ 1020:d70514b3b436 trunk

[svn] - stuff
author nenolod
date Wed, 10 May 2006 14:41:23 -0700
parents
children c59fe7000c95
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1020
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
1 /*
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
4 **
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
8 ** (at your option) any later version.
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
9 **
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
13 ** GNU General Public License for more details.
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
14 **
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
18 **
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
20 ** forbidden.
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
21 **
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
24 **
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
25 ** $Id: mp4atom.c,v 1.17 2004/01/11 15:52:18 menno Exp $
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
26 **/
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
27
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
28 #include <stdlib.h>
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
29 #include "mp4ffint.h"
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
30
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
31 #include "drms.h"
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
32
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
33 /* parse atom header size */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
34 int32_t mp4ff_atom_get_size(const int8_t *data)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
35 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
36 uint32_t result;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
37 uint32_t a, b, c, d;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
38
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
39 a = (uint8_t)data[0];
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
40 b = (uint8_t)data[1];
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
41 c = (uint8_t)data[2];
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
42 d = (uint8_t)data[3];
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
43
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
44 result = (a<<24) | (b<<16) | (c<<8) | d;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
45 //if (result > 0 && result < 8) result = 8;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
46
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
47 return (int32_t)result;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
48 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
49
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
50 /* comnapre 2 atom names, returns 1 for equal, 0 for unequal */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
51 int32_t mp4ff_atom_compare(const int8_t a1, const int8_t b1, const int8_t c1, const int8_t d1,
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
52 const int8_t a2, const int8_t b2, const int8_t c2, const int8_t d2)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
53 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
54 if (a1 == a2 && b1 == b2 && c1 == c2 && d1 == d2)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
55 return 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
56 else
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
57 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
58 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
59
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
60 uint8_t mp4ff_atom_name_to_type(const int8_t a, const int8_t b,
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
61 const int8_t c, const int8_t d)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
62 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
63 if (a == 'm')
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
64 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
65 if (mp4ff_atom_compare(a,b,c,d, 'm','o','o','v'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
66 return ATOM_MOOV;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
67 else if (mp4ff_atom_compare(a,b,c,d, 'm','i','n','f'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
68 return ATOM_MINF;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
69 else if (mp4ff_atom_compare(a,b,c,d, 'm','d','i','a'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
70 return ATOM_MDIA;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
71 else if (mp4ff_atom_compare(a,b,c,d, 'm','d','a','t'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
72 return ATOM_MDAT;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
73 else if (mp4ff_atom_compare(a,b,c,d, 'm','d','h','d'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
74 return ATOM_MDHD;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
75 else if (mp4ff_atom_compare(a,b,c,d, 'm','v','h','d'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
76 return ATOM_MVHD;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
77 else if (mp4ff_atom_compare(a,b,c,d, 'm','p','4','a'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
78 return ATOM_MP4A;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
79 else if (mp4ff_atom_compare(a,b,c,d, 'm','p','4','v'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
80 return ATOM_MP4V;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
81 else if (mp4ff_atom_compare(a,b,c,d, 'm','p','4','s'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
82 return ATOM_MP4S;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
83 else if (mp4ff_atom_compare(a,b,c,d, 'm','e','t','a'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
84 return ATOM_META;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
85 } else if (a == 't') {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
86 if (mp4ff_atom_compare(a,b,c,d, 't','r','a','k'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
87 return ATOM_TRAK;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
88 else if (mp4ff_atom_compare(a,b,c,d, 't','k','h','d'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
89 return ATOM_TKHD;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
90 else if (mp4ff_atom_compare(a,b,c,d, 't','r','e','f'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
91 return ATOM_TREF;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
92 else if (mp4ff_atom_compare(a,b,c,d, 't','r','k','n'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
93 return ATOM_TRACK;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
94 else if (mp4ff_atom_compare(a,b,c,d, 't','m','p','o'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
95 return ATOM_TEMPO;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
96 } else if (a == 's') {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
97 if (mp4ff_atom_compare(a,b,c,d, 's','t','b','l'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
98 return ATOM_STBL;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
99 else if (mp4ff_atom_compare(a,b,c,d, 's','m','h','d'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
100 return ATOM_SMHD;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
101 else if (mp4ff_atom_compare(a,b,c,d, 's','t','s','d'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
102 return ATOM_STSD;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
103 else if (mp4ff_atom_compare(a,b,c,d, 's','t','t','s'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
104 return ATOM_STTS;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
105 else if (mp4ff_atom_compare(a,b,c,d, 's','t','c','o'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
106 return ATOM_STCO;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
107 else if (mp4ff_atom_compare(a,b,c,d, 's','t','s','c'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
108 return ATOM_STSC;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
109 else if (mp4ff_atom_compare(a,b,c,d, 's','t','s','z'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
110 return ATOM_STSZ;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
111 else if (mp4ff_atom_compare(a,b,c,d, 's','t','z','2'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
112 return ATOM_STZ2;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
113 else if (mp4ff_atom_compare(a,b,c,d, 's','k','i','p'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
114 return ATOM_SKIP;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
115 else if (mp4ff_atom_compare(a,b,c,d, 's','i','n','f'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
116 return ATOM_SINF;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
117 else if (mp4ff_atom_compare(a,b,c,d, 's','c','h','i'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
118 return ATOM_SCHI;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
119 } else if (a == '©') {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
120 if (mp4ff_atom_compare(a,b,c,d, '©','n','a','m'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
121 return ATOM_TITLE;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
122 else if (mp4ff_atom_compare(a,b,c,d, '©','A','R','T'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
123 return ATOM_ARTIST;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
124 else if (mp4ff_atom_compare(a,b,c,d, '©','w','r','t'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
125 return ATOM_WRITER;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
126 else if (mp4ff_atom_compare(a,b,c,d, '©','a','l','b'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
127 return ATOM_ALBUM;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
128 else if (mp4ff_atom_compare(a,b,c,d, '©','d','a','y'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
129 return ATOM_DATE;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
130 else if (mp4ff_atom_compare(a,b,c,d, '©','t','o','o'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
131 return ATOM_TOOL;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
132 else if (mp4ff_atom_compare(a,b,c,d, '©','c','m','t'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
133 return ATOM_COMMENT;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
134 else if (mp4ff_atom_compare(a,b,c,d, '©','g','e','n'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
135 return ATOM_GENRE1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
136 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
137
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
138 if (mp4ff_atom_compare(a,b,c,d, 'e','d','t','s'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
139 return ATOM_EDTS;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
140 else if (mp4ff_atom_compare(a,b,c,d, 'e','s','d','s'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
141 return ATOM_ESDS;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
142 else if (mp4ff_atom_compare(a,b,c,d, 'f','t','y','p'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
143 return ATOM_FTYP;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
144 else if (mp4ff_atom_compare(a,b,c,d, 'f','r','e','e'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
145 return ATOM_FREE;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
146 else if (mp4ff_atom_compare(a,b,c,d, 'h','m','h','d'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
147 return ATOM_HMHD;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
148 else if (mp4ff_atom_compare(a,b,c,d, 'v','m','h','d'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
149 return ATOM_VMHD;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
150 else if (mp4ff_atom_compare(a,b,c,d, 'u','d','t','a'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
151 return ATOM_UDTA;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
152 else if (mp4ff_atom_compare(a,b,c,d, 'i','l','s','t'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
153 return ATOM_ILST;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
154 else if (mp4ff_atom_compare(a,b,c,d, 'n','a','m','e'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
155 return ATOM_NAME;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
156 else if (mp4ff_atom_compare(a,b,c,d, 'd','a','t','a'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
157 return ATOM_DATA;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
158 else if (mp4ff_atom_compare(a,b,c,d, 'd','i','s','k'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
159 return ATOM_DISC;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
160 else if (mp4ff_atom_compare(a,b,c,d, 'g','n','r','e'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
161 return ATOM_GENRE2;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
162 else if (mp4ff_atom_compare(a,b,c,d, 'c','o','v','r'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
163 return ATOM_COVER;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
164 else if (mp4ff_atom_compare(a,b,c,d, 'c','p','i','l'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
165 return ATOM_COMPILATION;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
166 else if (mp4ff_atom_compare(a,b,c,d, 'c','t','t','s'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
167 return ATOM_CTTS;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
168 else if (mp4ff_atom_compare(a,b,c,d, 'd','r','m','s'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
169 return ATOM_DRMS;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
170 else if (mp4ff_atom_compare(a,b,c,d, 'f','r','m','a'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
171 return ATOM_FRMA;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
172 else if (mp4ff_atom_compare(a,b,c,d, 'p','r','i','v'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
173 return ATOM_PRIV;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
174 else if (mp4ff_atom_compare(a,b,c,d, 'i','v','i','v'))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
175 return ATOM_IVIV;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
176 else
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
177 return ATOM_UNKNOWN;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
178 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
179
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
180 /* read atom header, return atom size, atom size is with header included */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
181 uint64_t mp4ff_atom_read_header(mp4ff_t *f, uint8_t *atom_type, uint8_t *header_size)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
182 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
183 uint64_t size;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
184 int32_t ret;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
185 int8_t atom_header[8];
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
186
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
187 ret = mp4ff_read_data(f, atom_header, 8);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
188 if (ret != 8)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
189 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
190
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
191 size = mp4ff_atom_get_size(atom_header);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
192 *header_size = 8;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
193
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
194 /* check for 64 bit atom size */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
195 if (size == 1)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
196 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
197 *header_size = 16;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
198 size = mp4ff_read_int64(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
199 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
200
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
201 //printf("%c%c%c%c\n", atom_header[4], atom_header[5], atom_header[6], atom_header[7]);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
202
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
203 *atom_type = mp4ff_atom_name_to_type(atom_header[4], atom_header[5], atom_header[6], atom_header[7]);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
204
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
205 return size;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
206 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
207
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
208 int32_t mp4ff_read_stsz(mp4ff_t *f)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
209 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
210 mp4ff_read_char(f); /* version */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
211 mp4ff_read_int24(f); /* flags */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
212 f->track[f->total_tracks - 1]->stsz_sample_size = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
213 f->track[f->total_tracks - 1]->stsz_sample_count = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
214
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
215 if (f->track[f->total_tracks - 1]->stsz_sample_size == 0)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
216 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
217 int32_t i;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
218 f->track[f->total_tracks - 1]->stsz_table =
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
219 (int32_t*)malloc(f->track[f->total_tracks - 1]->stsz_sample_count*sizeof(int32_t));
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
220
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
221 for (i = 0; i < f->track[f->total_tracks - 1]->stsz_sample_count; i++)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
222 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
223 f->track[f->total_tracks - 1]->stsz_table[i] = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
224 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
225 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
226
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
227 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
228 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
229
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
230 int32_t mp4ff_read_esds(mp4ff_t *f)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
231 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
232 uint8_t tag;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
233 uint32_t temp;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
234
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
235 mp4ff_read_char(f); /* version */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
236 mp4ff_read_int24(f); /* flags */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
237
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
238 /* get and verify ES_DescrTag */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
239 tag = mp4ff_read_char(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
240 if (tag == 0x03)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
241 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
242 /* read length */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
243 if (mp4ff_read_mp4_descr_length(f) < 5 + 15)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
244 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
245 return 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
246 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
247 /* skip 3 bytes */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
248 mp4ff_read_int24(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
249 } else {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
250 /* skip 2 bytes */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
251 mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
252 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
253
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
254 /* get and verify DecoderConfigDescrTab */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
255 if (mp4ff_read_char(f) != 0x04)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
256 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
257 return 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
258 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
259
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
260 /* read length */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
261 temp = mp4ff_read_mp4_descr_length(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
262 if (temp < 13) return 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
263
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
264 f->track[f->total_tracks - 1]->audioType = mp4ff_read_char(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
265 mp4ff_read_int32(f);//0x15000414 ????
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
266 f->track[f->total_tracks - 1]->maxBitrate = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
267 f->track[f->total_tracks - 1]->avgBitrate = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
268
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
269 /* get and verify DecSpecificInfoTag */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
270 if (mp4ff_read_char(f) != 0x05)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
271 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
272 return 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
273 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
274
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
275 /* read length */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
276 f->track[f->total_tracks - 1]->decoderConfigLen = mp4ff_read_mp4_descr_length(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
277
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
278 if (f->track[f->total_tracks - 1]->decoderConfig)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
279 free(f->track[f->total_tracks - 1]->decoderConfig);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
280 f->track[f->total_tracks - 1]->decoderConfig = malloc(f->track[f->total_tracks - 1]->decoderConfigLen);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
281 if (f->track[f->total_tracks - 1]->decoderConfig)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
282 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
283 mp4ff_read_data(f, f->track[f->total_tracks - 1]->decoderConfig, f->track[f->total_tracks - 1]->decoderConfigLen);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
284 } else {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
285 f->track[f->total_tracks - 1]->decoderConfigLen = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
286 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
287
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
288 /* will skip the remainder of the atom */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
289 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
290 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
291
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
292 int32_t mp4ff_read_mp4a(mp4ff_t *f)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
293 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
294 uint64_t size;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
295 int32_t i;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
296 uint8_t atom_type = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
297 uint8_t header_size = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
298
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
299 for (i = 0; i < 6; i++)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
300 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
301 mp4ff_read_char(f); /* reserved */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
302 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
303 /* data_reference_index */ mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
304
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
305 mp4ff_read_int32(f); /* reserved */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
306 mp4ff_read_int32(f); /* reserved */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
307
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
308 f->track[f->total_tracks - 1]->channelCount = mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
309 f->track[f->total_tracks - 1]->sampleSize = mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
310
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
311 mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
312 mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
313
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
314 f->track[f->total_tracks - 1]->sampleRate = mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
315
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
316 mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
317
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
318 size = mp4ff_atom_read_header(f, &atom_type, &header_size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
319 if (atom_type == ATOM_ESDS)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
320 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
321 mp4ff_read_esds(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
322 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
323
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
324 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
325 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
326
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
327 #ifdef ITUNES_DRM
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
328 int32_t mp4ff_read_drms(mp4ff_t *f, uint64_t skip)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
329 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
330 uint64_t size;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
331 int32_t i;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
332 uint8_t atom_type = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
333 uint8_t header_size = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
334 uint32_t drms_user_key[4];
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
335
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
336 if (drms_get_user_key(NULL, drms_user_key) == 0)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
337 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
338 f->track[f->total_tracks - 1]->p_drms = drms_alloc();
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
339
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
340 drms_init( f->track[f->total_tracks - 1]->p_drms,
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
341 DRMS_INIT_UKEY, (uint8_t *)drms_user_key,
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
342 sizeof(drms_user_key) );
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
343 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
344
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
345 for (i = 0; i < 6; i++)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
346 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
347 mp4ff_read_char(f); /* reserved */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
348 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
349 /* data_reference_index */ mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
350
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
351 mp4ff_read_int32(f); /* reserved */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
352 mp4ff_read_int32(f); /* reserved */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
353
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
354 f->track[f->total_tracks - 1]->channelCount = mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
355 f->track[f->total_tracks - 1]->sampleSize = mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
356
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
357 mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
358 mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
359
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
360 f->track[f->total_tracks - 1]->sampleRate = mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
361
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
362 mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
363
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
364 size = mp4ff_atom_read_header(f, &atom_type, &header_size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
365 if (atom_type == ATOM_ESDS)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
366 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
367 mp4ff_read_esds(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
368 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
369 mp4ff_set_position(f, skip+size+28);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
370
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
371 size = mp4ff_atom_read_header(f, &atom_type, &header_size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
372 if (atom_type == ATOM_SINF)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
373 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
374 parse_sub_atoms(f, size-header_size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
375 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
376
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
377 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
378 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
379
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
380 int32_t mp4ff_read_frma(mp4ff_t *f)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
381 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
382 uint8_t atom_type;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
383 int8_t type[4];
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
384
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
385 mp4ff_read_data(f, type, 4);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
386
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
387 atom_type = mp4ff_atom_name_to_type(type[0], type[1], type[2], type[3]);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
388
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
389 if (atom_type == ATOM_MP4A)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
390 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
391 f->track[f->total_tracks - 1]->type = TRACK_AUDIO;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
392 } else if (atom_type == ATOM_MP4V) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
393 f->track[f->total_tracks - 1]->type = TRACK_VIDEO;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
394 } else if (atom_type == ATOM_MP4S) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
395 f->track[f->total_tracks - 1]->type = TRACK_SYSTEM;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
396 } else {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
397 f->track[f->total_tracks - 1]->type = TRACK_UNKNOWN;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
398 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
399
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
400 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
401 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
402
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
403 int32_t mp4ff_read_name(mp4ff_t *f, uint64_t size)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
404 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
405 uint8_t *data = malloc(size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
406 mp4ff_read_data(f, data, size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
407
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
408 if (f->track[f->total_tracks - 1]->p_drms != NULL)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
409 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
410 drms_init(f->track[f->total_tracks - 1]->p_drms,
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
411 DRMS_INIT_NAME, data, strlen(data) );
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
412 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
413
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
414 if (data)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
415 free(data);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
416
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
417 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
418 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
419
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
420 int32_t mp4ff_read_priv(mp4ff_t *f, uint64_t size)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
421 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
422 uint8_t *data = malloc(size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
423 mp4ff_read_data(f, data, size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
424
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
425 if (f->track[f->total_tracks - 1]->p_drms != 0)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
426 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
427 drms_init(f->track[f->total_tracks - 1]->p_drms,
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
428 DRMS_INIT_PRIV, data, size );
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
429 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
430
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
431 if (data)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
432 free(data);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
433
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
434 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
435 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
436
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
437 int32_t mp4ff_read_iviv(mp4ff_t *f, uint64_t size)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
438 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
439 uint8_t *data = malloc(size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
440 mp4ff_read_data(f, data, size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
441
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
442 if (f->track[f->total_tracks - 1]->p_drms != 0)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
443 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
444 drms_init(f->track[f->total_tracks - 1]->p_drms,
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
445 DRMS_INIT_IVIV, data, sizeof(uint32_t) * 4 );
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
446 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
447
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
448 if (data)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
449 free(data);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
450
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
451 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
452 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
453 #endif
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
454
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
455 int32_t mp4ff_read_stsd(mp4ff_t *f)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
456 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
457 int32_t i;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
458 uint8_t header_size = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
459
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
460 mp4ff_read_char(f); /* version */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
461 mp4ff_read_int24(f); /* flags */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
462
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
463 f->track[f->total_tracks - 1]->stsd_entry_count = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
464
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
465 for (i = 0; i < f->track[f->total_tracks - 1]->stsd_entry_count; i++)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
466 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
467 uint64_t skip = mp4ff_position(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
468 uint64_t size;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
469 uint8_t atom_type = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
470 size = mp4ff_atom_read_header(f, &atom_type, &header_size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
471 skip += size;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
472
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
473 if (atom_type == ATOM_MP4A)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
474 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
475 f->track[f->total_tracks - 1]->type = TRACK_AUDIO;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
476 mp4ff_read_mp4a(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
477 } else if (atom_type == ATOM_MP4V) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
478 f->track[f->total_tracks - 1]->type = TRACK_VIDEO;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
479 } else if (atom_type == ATOM_MP4S) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
480 f->track[f->total_tracks - 1]->type = TRACK_SYSTEM;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
481 #ifdef ITUNES_DRM
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
482 } else if (atom_type == ATOM_DRMS) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
483 // track type is read from the "frma" atom
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
484 f->track[f->total_tracks - 1]->type = TRACK_UNKNOWN;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
485 mp4ff_read_drms(f, skip-size+header_size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
486 #endif
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
487 } else {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
488 f->track[f->total_tracks - 1]->type = TRACK_UNKNOWN;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
489 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
490
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
491 mp4ff_set_position(f, skip);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
492 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
493
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
494 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
495 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
496
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
497 int32_t mp4ff_read_stsc(mp4ff_t *f)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
498 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
499 int32_t i;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
500
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
501 mp4ff_read_char(f); /* version */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
502 mp4ff_read_int24(f); /* flags */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
503 f->track[f->total_tracks - 1]->stsc_entry_count = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
504
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
505 f->track[f->total_tracks - 1]->stsc_first_chunk =
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
506 (int32_t*)malloc(f->track[f->total_tracks - 1]->stsc_entry_count*sizeof(int32_t));
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
507 f->track[f->total_tracks - 1]->stsc_samples_per_chunk =
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
508 (int32_t*)malloc(f->track[f->total_tracks - 1]->stsc_entry_count*sizeof(int32_t));
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
509 f->track[f->total_tracks - 1]->stsc_sample_desc_index =
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
510 (int32_t*)malloc(f->track[f->total_tracks - 1]->stsc_entry_count*sizeof(int32_t));
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
511
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
512 for (i = 0; i < f->track[f->total_tracks - 1]->stsc_entry_count; i++)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
513 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
514 f->track[f->total_tracks - 1]->stsc_first_chunk[i] = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
515 f->track[f->total_tracks - 1]->stsc_samples_per_chunk[i] = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
516 f->track[f->total_tracks - 1]->stsc_sample_desc_index[i] = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
517 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
518
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
519 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
520 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
521
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
522 int32_t mp4ff_read_stco(mp4ff_t *f)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
523 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
524 int32_t i;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
525
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
526 mp4ff_read_char(f); /* version */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
527 mp4ff_read_int24(f); /* flags */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
528 f->track[f->total_tracks - 1]->stco_entry_count = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
529
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
530 f->track[f->total_tracks - 1]->stco_chunk_offset =
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
531 (int32_t*)malloc(f->track[f->total_tracks - 1]->stco_entry_count*sizeof(int32_t));
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
532
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
533 for (i = 0; i < f->track[f->total_tracks - 1]->stco_entry_count; i++)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
534 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
535 f->track[f->total_tracks - 1]->stco_chunk_offset[i] = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
536 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
537
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
538 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
539 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
540
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
541 int32_t mp4ff_read_ctts(mp4ff_t *f)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
542 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
543 int32_t i;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
544 mp4ff_track_t * p_track = f->track[f->total_tracks - 1];
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
545
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
546 if (p_track->ctts_entry_count) return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
547
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
548 mp4ff_read_char(f); /* version */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
549 mp4ff_read_int24(f); /* flags */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
550 p_track->ctts_entry_count = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
551
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
552 p_track->ctts_sample_count = (int32_t*)malloc(p_track->ctts_entry_count * sizeof(int32_t));
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
553 p_track->ctts_sample_offset = (int32_t*)malloc(p_track->ctts_entry_count * sizeof(int32_t));
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
554
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
555 if (p_track->ctts_sample_count == 0 || p_track->ctts_sample_offset == 0)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
556 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
557 if (p_track->ctts_sample_count) {free(p_track->ctts_sample_count);p_track->ctts_sample_count=0;}
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
558 if (p_track->ctts_sample_offset) {free(p_track->ctts_sample_offset);p_track->ctts_sample_offset=0;}
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
559 p_track->ctts_entry_count = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
560 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
561 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
562 else
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
563 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
564 for (i = 0; i < f->track[f->total_tracks - 1]->ctts_entry_count; i++)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
565 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
566 p_track->ctts_sample_count[i] = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
567 p_track->ctts_sample_offset[i] = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
568 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
569 return 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
570 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
571 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
572
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
573 int32_t mp4ff_read_stts(mp4ff_t *f)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
574 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
575 int32_t i;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
576 mp4ff_track_t * p_track = f->track[f->total_tracks - 1];
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
577
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
578 if (p_track->stts_entry_count) return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
579
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
580 mp4ff_read_char(f); /* version */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
581 mp4ff_read_int24(f); /* flags */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
582 p_track->stts_entry_count = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
583
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
584 p_track->stts_sample_count = (int32_t*)malloc(p_track->stts_entry_count * sizeof(int32_t));
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
585 p_track->stts_sample_delta = (int32_t*)malloc(p_track->stts_entry_count * sizeof(int32_t));
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
586
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
587 if (p_track->stts_sample_count == 0 || p_track->stts_sample_delta == 0)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
588 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
589 if (p_track->stts_sample_count) {free(p_track->stts_sample_count);p_track->stts_sample_count=0;}
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
590 if (p_track->stts_sample_delta) {free(p_track->stts_sample_delta);p_track->stts_sample_delta=0;}
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
591 p_track->stts_entry_count = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
592 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
593 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
594 else
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
595 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
596 for (i = 0; i < f->track[f->total_tracks - 1]->stts_entry_count; i++)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
597 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
598 p_track->stts_sample_count[i] = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
599 p_track->stts_sample_delta[i] = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
600 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
601 return 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
602 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
603 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
604
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
605 int32_t mp4ff_read_mvhd(mp4ff_t *f)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
606 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
607 int32_t i;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
608
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
609 mp4ff_read_char(f); /* version */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
610 mp4ff_read_int24(f); /* flags */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
611 /* creation_time */ mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
612 /* modification_time */ mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
613 f->time_scale = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
614 f->duration = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
615 /* preferred_rate */ mp4ff_read_int32(f); /*mp4ff_read_fixed32(f);*/
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
616 /* preferred_volume */ mp4ff_read_int16(f); /*mp4ff_read_fixed16(f);*/
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
617 for (i = 0; i < 10; i++)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
618 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
619 /* reserved */ mp4ff_read_char(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
620 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
621 for (i = 0; i < 9; i++)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
622 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
623 mp4ff_read_int32(f); /* matrix */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
624 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
625 /* preview_time */ mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
626 /* preview_duration */ mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
627 /* poster_time */ mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
628 /* selection_time */ mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
629 /* selection_duration */ mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
630 /* current_time */ mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
631 /* next_track_id */ mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
632
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
633 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
634 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
635
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
636 #if 0
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
637 int32_t mp4ff_read_tkhd(mp4ff_t *f)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
638 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
639 uint8_t version;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
640 uint32_t flags;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
641 version = mp4ff_read_char(f); /* version */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
642 flags = mp4ff_read_int24(f); /* flags */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
643 if (version==1)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
644 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
645 mp4ff_read_int64(f);//creation-time
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
646 mp4ff_read_int64(f);//modification-time
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
647 mp4ff_read_int32(f);//track-id
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
648 mp4ff_read_int32(f);//reserved
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
649 f->track[f->total_tracks - 1]->duration = mp4ff_read_int64(f);//duration
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
650 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
651 else //version == 0
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
652 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
653 mp4ff_read_int32(f);//creation-time
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
654 mp4ff_read_int32(f);//modification-time
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
655 mp4ff_read_int32(f);//track-id
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
656 mp4ff_read_int32(f);//reserved
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
657 f->track[f->total_tracks - 1]->duration = mp4ff_read_int32(f);//duration
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
658 if (f->track[f->total_tracks - 1]->duration == 0xFFFFFFFF)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
659 f->track[f->total_tracks - 1]->duration = 0xFFFFFFFFFFFFFFFF;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
660
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
661 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
662 mp4ff_read_int32(f);//reserved
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
663 mp4ff_read_int32(f);//reserved
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
664 mp4ff_read_int16(f);//layer
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
665 mp4ff_read_int16(f);//pre-defined
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
666 mp4ff_read_int16(f);//volume
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
667 mp4ff_read_int16(f);//reserved
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
668
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
669 //matrix
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
670 mp4ff_read_int32(f); mp4ff_read_int32(f); mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
671 mp4ff_read_int32(f); mp4ff_read_int32(f); mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
672 mp4ff_read_int32(f); mp4ff_read_int32(f); mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
673 mp4ff_read_int32(f);//width
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
674 mp4ff_read_int32(f);//height
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
675 return 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
676 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
677 #endif
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
678
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
679 int32_t mp4ff_read_mdhd(mp4ff_t *f)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
680 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
681 uint32_t version;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
682
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
683 version = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
684 if (version==1)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
685 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
686 mp4ff_read_int64(f);//creation-time
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
687 mp4ff_read_int64(f);//modification-time
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
688 f->track[f->total_tracks - 1]->timeScale = mp4ff_read_int32(f);//timescale
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
689 f->track[f->total_tracks - 1]->duration = mp4ff_read_int64(f);//duration
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
690 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
691 else //version == 0
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
692 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
693 uint32_t temp;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
694
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
695 mp4ff_read_int32(f);//creation-time
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
696 mp4ff_read_int32(f);//modification-time
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
697 f->track[f->total_tracks - 1]->timeScale = mp4ff_read_int32(f);//timescale
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
698 temp = mp4ff_read_int32(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
699 f->track[f->total_tracks - 1]->duration = (temp == (uint32_t)(-1)) ? (uint64_t)(-1) : (uint64_t)(temp);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
700 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
701 mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
702 mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
703 return 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
704 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
705 #ifdef USE_TAGGING
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
706 int32_t mp4ff_read_meta(mp4ff_t *f, const uint64_t size)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
707 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
708 uint64_t subsize, sumsize = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
709 uint8_t atom_type;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
710 uint8_t header_size = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
711
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
712 mp4ff_read_char(f); /* version */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
713 mp4ff_read_int24(f); /* flags */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
714
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
715 while (sumsize < (size-12))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
716 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
717 subsize = mp4ff_atom_read_header(f, &atom_type, &header_size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
718 if (atom_type == ATOM_ILST)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
719 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
720 mp4ff_parse_metadata(f, (uint32_t)(subsize-(header_size+4)));
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
721 } else {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
722 mp4ff_set_position(f, mp4ff_position(f)+subsize-header_size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
723 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
724 sumsize += subsize;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
725 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
726
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
727 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
728 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
729 #endif
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
730
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
731 int32_t mp4ff_atom_read(mp4ff_t *f, const int32_t size, const uint8_t atom_type)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
732 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
733 uint64_t dest_position = mp4ff_position(f)+size-8;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
734 if (atom_type == ATOM_STSZ)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
735 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
736 /* sample size box */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
737 mp4ff_read_stsz(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
738 } else if (atom_type == ATOM_STTS) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
739 /* time to sample box */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
740 mp4ff_read_stts(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
741 } else if (atom_type == ATOM_CTTS) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
742 /* composition offset box */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
743 mp4ff_read_ctts(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
744 } else if (atom_type == ATOM_STSC) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
745 /* sample to chunk box */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
746 mp4ff_read_stsc(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
747 } else if (atom_type == ATOM_STCO) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
748 /* chunk offset box */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
749 mp4ff_read_stco(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
750 } else if (atom_type == ATOM_STSD) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
751 /* sample description box */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
752 mp4ff_read_stsd(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
753 } else if (atom_type == ATOM_MVHD) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
754 /* movie header box */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
755 mp4ff_read_mvhd(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
756 } else if (atom_type == ATOM_MDHD) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
757 /* track header */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
758 mp4ff_read_mdhd(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
759 #ifdef ITUNES_DRM
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
760 } else if (atom_type == ATOM_FRMA) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
761 /* DRM track format */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
762 mp4ff_read_frma(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
763 } else if (atom_type == ATOM_IVIV) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
764 mp4ff_read_iviv(f, size-8);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
765 } else if (atom_type == ATOM_NAME) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
766 mp4ff_read_name(f, size-8);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
767 } else if (atom_type == ATOM_PRIV) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
768 mp4ff_read_priv(f, size-8);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
769 #endif
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
770 #ifdef USE_TAGGING
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
771 } else if (atom_type == ATOM_META) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
772 /* iTunes Metadata box */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
773 mp4ff_read_meta(f, size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
774 #endif
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
775 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
776
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
777 mp4ff_set_position(f, dest_position);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
778
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
779
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
780 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
781 }