Mercurial > audlegacy
comparison Input/aac/libmp4v2/mp4info.cpp @ 2:6efb9e514224 trunk
[svn] Import AAC stuff.
author | nenolod |
---|---|
date | Mon, 24 Oct 2005 10:44:27 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:cc6293c827ec | 2:6efb9e514224 |
---|---|
1 /* | |
2 * The contents of this file are subject to the Mozilla Public | |
3 * License Version 1.1 (the "License"); you may not use this file | |
4 * except in compliance with the License. You may obtain a copy of | |
5 * the License at http://www.mozilla.org/MPL/ | |
6 * | |
7 * Software distributed under the License is distributed on an "AS | |
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | |
9 * implied. See the License for the specific language governing | |
10 * rights and limitations under the License. | |
11 * | |
12 * The Original Code is MPEG4IP. | |
13 * | |
14 * The Initial Developer of the Original Code is Cisco Systems Inc. | |
15 * Portions created by Cisco Systems Inc. are | |
16 * Copyright (C) Cisco Systems Inc. 2001-2002. All Rights Reserved. | |
17 * | |
18 * Contributor(s): | |
19 * Dave Mackie dmackie@cisco.com | |
20 */ | |
21 | |
22 #include "mp4common.h" | |
23 | |
24 static char* PrintAudioInfo( | |
25 MP4FileHandle mp4File, | |
26 MP4TrackId trackId) | |
27 { | |
28 static const char* mpeg4AudioNames[] = { | |
29 "MPEG-4 Main @ L1", | |
30 "MPEG-4 Main @ L2", | |
31 "MPEG-4 Main @ L3", | |
32 "MPEG-4 Main @ L4", | |
33 "MPEG-4 Scalable @ L1", | |
34 "MPEG-4 Scalable @ L2", | |
35 "MPEG-4 Scalable @ L3", | |
36 "MPEG-4 Scalable @ L4", | |
37 "MPEG-4 Speech @ L1", | |
38 "MPEG-4 Speech @ L2", | |
39 "MPEG-4 Synthesis @ L1", | |
40 "MPEG-4 Synthesis @ L2", | |
41 "MPEG-4 Synthesis @ L3", | |
42 }; | |
43 static u_int8_t numMpeg4AudioTypes = | |
44 sizeof(mpeg4AudioNames) / sizeof(char*); | |
45 | |
46 static u_int8_t mpegAudioTypes[] = { | |
47 MP4_MPEG2_AAC_MAIN_AUDIO_TYPE, // 0x66 | |
48 MP4_MPEG2_AAC_LC_AUDIO_TYPE, // 0x67 | |
49 MP4_MPEG2_AAC_SSR_AUDIO_TYPE, // 0x68 | |
50 MP4_MPEG2_AUDIO_TYPE, // 0x69 | |
51 MP4_MPEG1_AUDIO_TYPE, // 0x6B | |
52 MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE, | |
53 MP4_VORBIS_AUDIO_TYPE, | |
54 MP4_ALAW_AUDIO_TYPE, | |
55 MP4_ULAW_AUDIO_TYPE, | |
56 MP4_G723_AUDIO_TYPE, | |
57 MP4_PCM16_BIG_ENDIAN_AUDIO_TYPE, | |
58 }; | |
59 static const char* mpegAudioNames[] = { | |
60 "MPEG-2 AAC Main", | |
61 "MPEG-2 AAC LC", | |
62 "MPEG-2 AAC SSR", | |
63 "MPEG-2 (MP3)", | |
64 "MPEG-1 (MP3)", | |
65 "PCM16 (little endian)", | |
66 "OGG VORBIS", | |
67 "G.711 aLaw", | |
68 "G.711 uLaw", | |
69 "G.723.1", | |
70 "PCM16 (big endian)", | |
71 }; | |
72 static u_int8_t numMpegAudioTypes = | |
73 sizeof(mpegAudioTypes) / sizeof(u_int8_t); | |
74 | |
75 u_int8_t type = | |
76 MP4GetTrackAudioType(mp4File, trackId); | |
77 const char* typeName = "Unknown"; | |
78 | |
79 if (type == MP4_MPEG4_AUDIO_TYPE) { | |
80 type = MP4GetAudioProfileLevel(mp4File); | |
81 if (type > 0 && type <= numMpeg4AudioTypes) { | |
82 typeName = mpeg4AudioNames[type - 1]; | |
83 } else { | |
84 typeName = "MPEG-4"; | |
85 } | |
86 } else { | |
87 for (u_int8_t i = 0; i < numMpegAudioTypes; i++) { | |
88 if (type == mpegAudioTypes[i]) { | |
89 typeName = mpegAudioNames[i]; | |
90 break; | |
91 } | |
92 } | |
93 } | |
94 | |
95 u_int32_t timeScale = | |
96 MP4GetTrackTimeScale(mp4File, trackId); | |
97 | |
98 MP4Duration trackDuration = | |
99 MP4GetTrackDuration(mp4File, trackId); | |
100 | |
101 double msDuration = | |
102 #ifdef _WIN32 | |
103 (int64_t) | |
104 #endif | |
105 MP4ConvertFromTrackDuration(mp4File, trackId, | |
106 trackDuration, MP4_MSECS_TIME_SCALE); | |
107 | |
108 u_int32_t avgBitRate = | |
109 MP4GetTrackBitRate(mp4File, trackId); | |
110 | |
111 char *sInfo = (char*)MP4Malloc(256); | |
112 | |
113 // type duration avgBitrate samplingFrequency | |
114 sprintf(sInfo, | |
115 "%u\taudio\t%s, %.3f secs, %u kbps, %u Hz\n", | |
116 trackId, | |
117 typeName, | |
118 msDuration / 1000.0, | |
119 (avgBitRate + 500) / 1000, | |
120 timeScale); | |
121 | |
122 return sInfo; | |
123 } | |
124 | |
125 static char* PrintVideoInfo( | |
126 MP4FileHandle mp4File, | |
127 MP4TrackId trackId) | |
128 { | |
129 static const char* mpeg4VideoNames[] = { | |
130 "MPEG-4 Simple @ L3", | |
131 "MPEG-4 Simple @ L2", | |
132 "MPEG-4 Simple @ L1", | |
133 "MPEG-4 Simple Scalable @ L2", | |
134 "MPEG-4 Simple Scalable @ L1", | |
135 "MPEG-4 Core @ L2", | |
136 "MPEG-4 Core @ L1", | |
137 "MPEG-4 Main @ L4", | |
138 "MPEG-4 Main @ L3", | |
139 "MPEG-4 Main @ L2", | |
140 "MPEG-4 Main @ L1", | |
141 "MPEG-4 N-Bit @ L2", | |
142 "MPEG-4 Hybrid @ L2", | |
143 "MPEG-4 Hybrid @ L1", | |
144 "MPEG-4 Hybrid @ L1", | |
145 }; | |
146 static u_int8_t numMpeg4VideoTypes = | |
147 sizeof(mpeg4VideoNames) / sizeof(char*); | |
148 | |
149 static u_int8_t mpegVideoTypes[] = { | |
150 MP4_MPEG2_SIMPLE_VIDEO_TYPE, // 0x60 | |
151 MP4_MPEG2_MAIN_VIDEO_TYPE, // 0x61 | |
152 MP4_MPEG2_SNR_VIDEO_TYPE, // 0x62 | |
153 MP4_MPEG2_SPATIAL_VIDEO_TYPE, // 0x63 | |
154 MP4_MPEG2_HIGH_VIDEO_TYPE, // 0x64 | |
155 MP4_MPEG2_442_VIDEO_TYPE, // 0x65 | |
156 MP4_MPEG1_VIDEO_TYPE, // 0x6A | |
157 MP4_JPEG_VIDEO_TYPE, // 0x6C | |
158 MP4_YUV12_VIDEO_TYPE, | |
159 MP4_H264_VIDEO_TYPE, | |
160 MP4_H263_VIDEO_TYPE, | |
161 MP4_H261_VIDEO_TYPE, | |
162 }; | |
163 static const char* mpegVideoNames[] = { | |
164 "MPEG-2 Simple", | |
165 "MPEG-2 Main", | |
166 "MPEG-2 SNR", | |
167 "MPEG-2 Spatial", | |
168 "MPEG-2 High", | |
169 "MPEG-2 4:2:2", | |
170 "MPEG-1", | |
171 "JPEG", | |
172 "YUV12", | |
173 "H.264", | |
174 "H.263", | |
175 "H.261", | |
176 }; | |
177 static u_int8_t numMpegVideoTypes = | |
178 sizeof(mpegVideoTypes) / sizeof(u_int8_t); | |
179 | |
180 u_int8_t type = | |
181 MP4GetTrackVideoType(mp4File, trackId); | |
182 const char* typeName = "Unknown"; | |
183 | |
184 if (type == MP4_MPEG4_VIDEO_TYPE) { | |
185 type = MP4GetVideoProfileLevel(mp4File); | |
186 if (type > 0 && type <= numMpeg4VideoTypes) { | |
187 typeName = mpeg4VideoNames[type - 1]; | |
188 } else { | |
189 typeName = "MPEG-4"; | |
190 } | |
191 } else { | |
192 for (u_int8_t i = 0; i < numMpegVideoTypes; i++) { | |
193 if (type == mpegVideoTypes[i]) { | |
194 typeName = mpegVideoNames[i]; | |
195 break; | |
196 } | |
197 } | |
198 } | |
199 | |
200 MP4Duration trackDuration = | |
201 MP4GetTrackDuration(mp4File, trackId); | |
202 | |
203 double msDuration = | |
204 #ifdef _WIN32 | |
205 (int64_t) | |
206 #endif | |
207 MP4ConvertFromTrackDuration(mp4File, trackId, | |
208 trackDuration, MP4_MSECS_TIME_SCALE); | |
209 | |
210 u_int32_t avgBitRate = | |
211 MP4GetTrackBitRate(mp4File, trackId); | |
212 | |
213 // Note not all mp4 implementations set width and height correctly | |
214 // The real answer can be buried inside the ES configuration info | |
215 u_int16_t width = MP4GetTrackVideoWidth(mp4File, trackId); | |
216 | |
217 u_int16_t height = MP4GetTrackVideoHeight(mp4File, trackId); | |
218 | |
219 float fps = MP4GetTrackVideoFrameRate(mp4File, trackId); | |
220 | |
221 char *sInfo = (char*)MP4Malloc(256); | |
222 | |
223 // type duration avgBitrate frameSize frameRate | |
224 sprintf(sInfo, | |
225 "%u\tvideo\t%s, %.3f secs, %u kbps, %ux%u @ %.2f fps\n", | |
226 trackId, | |
227 typeName, | |
228 msDuration / 1000.0, | |
229 (avgBitRate + 500) / 1000, | |
230 width, | |
231 height, | |
232 fps | |
233 ); | |
234 | |
235 return sInfo; | |
236 } | |
237 | |
238 static char* PrintHintInfo( | |
239 MP4FileHandle mp4File, | |
240 MP4TrackId trackId) | |
241 { | |
242 MP4TrackId referenceTrackId = | |
243 MP4GetHintTrackReferenceTrackId(mp4File, trackId); | |
244 | |
245 char* payloadName = NULL; | |
246 MP4GetHintTrackRtpPayload(mp4File, trackId, &payloadName); | |
247 | |
248 char *sInfo = (char*)MP4Malloc(256); | |
249 | |
250 sprintf(sInfo, | |
251 "%u\thint\tPayload %s for track %u\n", | |
252 trackId, | |
253 payloadName, | |
254 referenceTrackId); | |
255 | |
256 free(payloadName); | |
257 | |
258 return sInfo; | |
259 } | |
260 | |
261 static char* PrintTrackInfo( | |
262 MP4FileHandle mp4File, | |
263 MP4TrackId trackId) | |
264 { | |
265 char* trackInfo = NULL; | |
266 | |
267 const char* trackType = | |
268 MP4GetTrackType(mp4File, trackId); | |
269 | |
270 if (!strcmp(trackType, MP4_AUDIO_TRACK_TYPE)) { | |
271 trackInfo = PrintAudioInfo(mp4File, trackId); | |
272 } else if (!strcmp(trackType, MP4_VIDEO_TRACK_TYPE)) { | |
273 trackInfo = PrintVideoInfo(mp4File, trackId); | |
274 } else if (!strcmp(trackType, MP4_HINT_TRACK_TYPE)) { | |
275 trackInfo = PrintHintInfo(mp4File, trackId); | |
276 } else { | |
277 trackInfo = (char*)MP4Malloc(256); | |
278 if (!strcmp(trackType, MP4_OD_TRACK_TYPE)) { | |
279 sprintf(trackInfo, | |
280 "%u\tod\tObject Descriptors\n", | |
281 trackId); | |
282 } else if (!strcmp(trackType, MP4_SCENE_TRACK_TYPE)) { | |
283 sprintf(trackInfo, | |
284 "%u\tscene\tBIFS\n", | |
285 trackId); | |
286 } else { | |
287 sprintf(trackInfo, | |
288 "%u\t%s\n", | |
289 trackId, trackType); | |
290 } | |
291 } | |
292 | |
293 return trackInfo; | |
294 } | |
295 | |
296 extern "C" char* MP4Info( | |
297 MP4FileHandle mp4File, | |
298 MP4TrackId trackId) | |
299 { | |
300 char* info = NULL; | |
301 | |
302 if (MP4_IS_VALID_FILE_HANDLE(mp4File)) { | |
303 try { | |
304 if (trackId == MP4_INVALID_TRACK_ID) { | |
305 info = (char*)MP4Calloc(4*1024); | |
306 | |
307 sprintf(info, "Track\tType\tInfo\n"); | |
308 | |
309 u_int32_t numTracks = MP4GetNumberOfTracks(mp4File); | |
310 | |
311 for (u_int32_t i = 0; i < numTracks; i++) { | |
312 trackId = MP4FindTrackId(mp4File, i); | |
313 char* trackInfo = PrintTrackInfo(mp4File, trackId); | |
314 strcat(info, trackInfo); | |
315 MP4Free(trackInfo); | |
316 } | |
317 } else { | |
318 info = PrintTrackInfo(mp4File, trackId); | |
319 } | |
320 } | |
321 catch (MP4Error* e) { | |
322 delete e; | |
323 } | |
324 } | |
325 | |
326 return info; | |
327 } | |
328 | |
329 extern "C" char* MP4FileInfo( | |
330 const char* fileName, | |
331 MP4TrackId trackId) | |
332 { | |
333 MP4FileHandle mp4File = | |
334 MP4Read(fileName); | |
335 | |
336 if (!mp4File) { | |
337 return NULL; | |
338 } | |
339 | |
340 char* info = MP4Info(mp4File, trackId); | |
341 | |
342 MP4Close(mp4File); | |
343 | |
344 return info; // caller should free this | |
345 } | |
346 |