eqMerge remote-tracking branch 'origin/master' into 0.11
[platform/upstream/gst-plugins-good.git] / gst / isomp4 / qtdemux_dump.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) 2009 Tim-Philipp Müller <tim centricular net>
4  * Copyright (C) <2009> STEricsson <benjamin.gaignard@stericsson.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #include "qtdemux_types.h"
23 #include "qtdemux_dump.h"
24
25 #include "qtatomparser.h"
26
27 #include <string.h>
28
29 #define GET_UINT8(data)   gst_byte_reader_get_uint8_unchecked(data)
30 #define GET_UINT16(data)  gst_byte_reader_get_uint16_be_unchecked(data)
31 #define GET_UINT32(data)  gst_byte_reader_get_uint32_be_unchecked(data)
32 #define GET_UINT64(data)  gst_byte_reader_get_uint64_be_unchecked(data)
33 #define GET_FP32(data)   (gst_byte_reader_get_uint32_be_unchecked(data)/65536.0)
34 #define GET_FP16(data)   (gst_byte_reader_get_uint16_be_unchecked(data)/256.0)
35 #define GET_FOURCC(data)  qt_atom_parser_get_fourcc_unchecked(data)
36
37 gboolean
38 qtdemux_dump_mvhd (GstQTDemux * qtdemux, GstByteReader * data, int depth)
39 {
40   guint32 version = 0;
41
42   if (!qt_atom_parser_has_remaining (data, 100))
43     return FALSE;
44
45   version = GET_UINT32 (data);
46   GST_LOG ("%*s  version/flags: %08x", depth, "", version);
47
48   version = version >> 24;
49   if (version == 0) {
50     GST_LOG ("%*s  creation time: %u", depth, "", GET_UINT32 (data));
51     GST_LOG ("%*s  modify time:   %u", depth, "", GET_UINT32 (data));
52     GST_LOG ("%*s  time scale:    1/%u sec", depth, "", GET_UINT32 (data));
53     GST_LOG ("%*s  duration:      %u", depth, "", GET_UINT32 (data));
54   } else if (version == 1) {
55     GST_LOG ("%*s  creation time: %" G_GUINT64_FORMAT,
56         depth, "", GET_UINT64 (data));
57     GST_LOG ("%*s  modify time:   %" G_GUINT64_FORMAT,
58         depth, "", GET_UINT64 (data));
59     GST_LOG ("%*s  time scale:    1/%u sec", depth, "", GET_UINT32 (data));
60     GST_LOG ("%*s  duration:      %" G_GUINT64_FORMAT,
61         depth, "", GET_UINT64 (data));
62   } else
63     return FALSE;
64
65   GST_LOG ("%*s  pref. rate:    %g", depth, "", GET_FP32 (data));
66   GST_LOG ("%*s  pref. volume:  %g", depth, "", GET_FP16 (data));
67   gst_byte_reader_skip (data, 46);
68   GST_LOG ("%*s  preview time:  %u", depth, "", GET_UINT32 (data));
69   GST_LOG ("%*s  preview dur.:  %u", depth, "", GET_UINT32 (data));
70   GST_LOG ("%*s  poster time:   %u", depth, "", GET_UINT32 (data));
71   GST_LOG ("%*s  select time:   %u", depth, "", GET_UINT32 (data));
72   GST_LOG ("%*s  select dur.:   %u", depth, "", GET_UINT32 (data));
73   GST_LOG ("%*s  current time:  %u", depth, "", GET_UINT32 (data));
74   GST_LOG ("%*s  next track ID: %d", depth, "", GET_UINT32 (data));
75   return TRUE;
76 }
77
78 gboolean
79 qtdemux_dump_tkhd (GstQTDemux * qtdemux, GstByteReader * data, int depth)
80 {
81   guint64 duration, ctime, mtime;
82   guint32 version = 0, track_id = 0, iwidth = 0, iheight = 0;
83   guint16 layer = 0, alt_group = 0, ivol = 0;
84   guint value_size;
85
86   if (!gst_byte_reader_get_uint32_be (data, &version))
87     return FALSE;
88
89   GST_LOG ("%*s  version/flags: %08x", depth, "", version);
90
91   value_size = ((version >> 24) == 1) ? sizeof (guint64) : sizeof (guint32);
92
93   if (qt_atom_parser_get_offset (data, value_size, &ctime) &&
94       qt_atom_parser_get_offset (data, value_size, &mtime) &&
95       gst_byte_reader_get_uint32_be (data, &track_id) &&
96       gst_byte_reader_skip (data, 4) &&
97       qt_atom_parser_get_offset (data, value_size, &duration) &&
98       gst_byte_reader_skip (data, 4) &&
99       gst_byte_reader_get_uint16_be (data, &layer) &&
100       gst_byte_reader_get_uint16_be (data, &alt_group) &&
101       gst_byte_reader_skip (data, 4) &&
102       gst_byte_reader_get_uint16_be (data, &ivol) &&
103       gst_byte_reader_skip (data, 2 + (9 * 4)) &&
104       gst_byte_reader_get_uint32_be (data, &iwidth) &&
105       gst_byte_reader_get_uint32_be (data, &iheight)) {
106     GST_LOG ("%*s  creation time: %" G_GUINT64_FORMAT, depth, "", ctime);
107     GST_LOG ("%*s  modify time:   %" G_GUINT64_FORMAT, depth, "", mtime);
108     GST_LOG ("%*s  track ID:      %u", depth, "", track_id);
109     GST_LOG ("%*s  duration:      %" G_GUINT64_FORMAT, depth, "", duration);
110     GST_LOG ("%*s  layer:         %u", depth, "", layer);
111     GST_LOG ("%*s  alt group:     %u", depth, "", alt_group);
112     GST_LOG ("%*s  volume:        %g", depth, "", ivol / 256.0);
113     GST_LOG ("%*s  track width:   %g", depth, "", iwidth / 65536.0);
114     GST_LOG ("%*s  track height:  %g", depth, "", iheight / 65536.0);
115     return TRUE;
116   }
117
118   return FALSE;
119 }
120
121 gboolean
122 qtdemux_dump_elst (GstQTDemux * qtdemux, GstByteReader * data, int depth)
123 {
124   guint32 ver_flags = 0, num_entries = 0, i;
125
126   if (!gst_byte_reader_get_uint32_be (data, &ver_flags) ||
127       !gst_byte_reader_get_uint32_be (data, &num_entries))
128     return FALSE;
129
130   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
131   GST_LOG ("%*s  n entries:     %d", depth, "", num_entries);
132
133   if (!qt_atom_parser_has_chunks (data, num_entries, 4 + 4 + 4))
134     return FALSE;
135
136   for (i = 0; i < num_entries; i++) {
137     GST_LOG ("%*s    track dur:     %u", depth, "", GET_UINT32 (data));
138     GST_LOG ("%*s    media time:    %u", depth, "", GET_UINT32 (data));
139     GST_LOG ("%*s    media rate:    %g", depth, "", GET_FP32 (data));
140   }
141   return TRUE;
142 }
143
144 gboolean
145 qtdemux_dump_mdhd (GstQTDemux * qtdemux, GstByteReader * data, int depth)
146 {
147   guint32 version = 0;
148   guint64 duration, ctime, mtime;
149   guint32 time_scale = 0;
150   guint16 language = 0, quality = 0;
151   guint value_size;
152
153   if (!gst_byte_reader_get_uint32_be (data, &version))
154     return FALSE;
155
156   GST_LOG ("%*s  version/flags: %08x", depth, "", version);
157
158   value_size = ((version >> 24) == 1) ? sizeof (guint64) : sizeof (guint32);
159
160   if (qt_atom_parser_get_offset (data, value_size, &ctime) &&
161       qt_atom_parser_get_offset (data, value_size, &mtime) &&
162       gst_byte_reader_get_uint32_be (data, &time_scale) &&
163       qt_atom_parser_get_offset (data, value_size, &duration) &&
164       gst_byte_reader_get_uint16_be (data, &language) &&
165       gst_byte_reader_get_uint16_be (data, &quality)) {
166     GST_LOG ("%*s  creation time: %" G_GUINT64_FORMAT, depth, "", ctime);
167     GST_LOG ("%*s  modify time:   %" G_GUINT64_FORMAT, depth, "", mtime);
168     GST_LOG ("%*s  time scale:    1/%u sec", depth, "", time_scale);
169     GST_LOG ("%*s  duration:      %" G_GUINT64_FORMAT, depth, "", duration);
170     GST_LOG ("%*s  language:      %u", depth, "", language);
171     GST_LOG ("%*s  quality:       %u", depth, "", quality);
172     return TRUE;
173   }
174
175   return FALSE;
176 }
177
178 gboolean
179 qtdemux_dump_hdlr (GstQTDemux * qtdemux, GstByteReader * data, int depth)
180 {
181   guint32 version, type, subtype, manufacturer;
182   const gchar *name;
183
184   if (!qt_atom_parser_has_remaining (data, 4 + 4 + 4 + 4 + 4 + 4 + 1))
185     return FALSE;
186
187   version = GET_UINT32 (data);
188   type = GET_FOURCC (data);
189   subtype = GET_FOURCC (data);
190   manufacturer = GET_FOURCC (data);
191
192   GST_LOG ("%*s  version/flags: %08x", depth, "", version);
193   GST_LOG ("%*s  type:          %" GST_FOURCC_FORMAT, depth, "",
194       GST_FOURCC_ARGS (type));
195   GST_LOG ("%*s  subtype:       %" GST_FOURCC_FORMAT, depth, "",
196       GST_FOURCC_ARGS (subtype));
197   GST_LOG ("%*s  manufacturer:  %" GST_FOURCC_FORMAT, depth, "",
198       GST_FOURCC_ARGS (manufacturer));
199   GST_LOG ("%*s  flags:         %08x", depth, "", GET_UINT32 (data));
200   GST_LOG ("%*s  flags mask:    %08x", depth, "", GET_UINT32 (data));
201
202   /* quicktime uses pascal string, mp4 zero-terminated string */
203   if (gst_byte_reader_peek_string (data, &name)) {
204     GST_LOG ("%*s  name:          %s", depth, "", name);
205   } else {
206     gchar buf[256];
207     guint len;
208
209     len = gst_byte_reader_get_uint8_unchecked (data);
210     if (qt_atom_parser_has_remaining (data, len)) {
211       memcpy (buf, gst_byte_reader_peek_data_unchecked (data), len);
212       buf[len] = '\0';
213       GST_LOG ("%*s  name:          %s", depth, "", buf);
214     }
215   }
216   return TRUE;
217 }
218
219 gboolean
220 qtdemux_dump_vmhd (GstQTDemux * qtdemux, GstByteReader * data, int depth)
221 {
222   if (!qt_atom_parser_has_remaining (data, 4 + 4))
223     return FALSE;
224
225   GST_LOG ("%*s  version/flags: %08x", depth, "", GET_UINT32 (data));
226   GST_LOG ("%*s  mode/color:    %08x", depth, "", GET_UINT32 (data));
227   return TRUE;
228 }
229
230 gboolean
231 qtdemux_dump_dref (GstQTDemux * qtdemux, GstByteReader * data, int depth)
232 {
233   guint32 ver_flags = 0, num_entries = 0, i;
234
235   if (!gst_byte_reader_get_uint32_be (data, &ver_flags) ||
236       !gst_byte_reader_get_uint32_be (data, &num_entries))
237     return FALSE;
238
239   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
240   GST_LOG ("%*s  n entries:     %u", depth, "", num_entries);
241   for (i = 0; i < num_entries; i++) {
242     guint32 size = 0, fourcc;
243
244     if (!gst_byte_reader_get_uint32_be (data, &size) ||
245         !qt_atom_parser_get_fourcc (data, &fourcc) || size < 8 ||
246         !gst_byte_reader_skip (data, size - 8))
247       return FALSE;
248
249     GST_LOG ("%*s    size:          %u", depth, "", size);
250     GST_LOG ("%*s    type:          %" GST_FOURCC_FORMAT, depth, "",
251         GST_FOURCC_ARGS (fourcc));
252   }
253   return TRUE;
254 }
255
256 gboolean
257 qtdemux_dump_stsd (GstQTDemux * qtdemux, GstByteReader * data, int depth)
258 {
259   guint32 ver_flags = 0, num_entries = 0, i;
260
261   if (!gst_byte_reader_get_uint32_be (data, &ver_flags) ||
262       !gst_byte_reader_get_uint32_be (data, &num_entries))
263     return FALSE;
264
265   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
266   GST_LOG ("%*s  n entries:     %d", depth, "", num_entries);
267
268   for (i = 0; i < num_entries; i++) {
269     GstByteReader sub;
270     guint32 size = 0, fourcc;
271
272     if (!gst_byte_reader_get_uint32_be (data, &size) ||
273         !qt_atom_parser_get_fourcc (data, &fourcc))
274       return FALSE;
275
276     GST_LOG ("%*s    size:          %u", depth, "", size);
277     GST_LOG ("%*s    type:          %" GST_FOURCC_FORMAT, depth, "",
278         GST_FOURCC_ARGS (fourcc));
279
280     if (size < (6 + 2 + 4 + 4 + 4 + 4 + 2 + 2 + 4 + 4 + 4 + 2 + 1 + 31 + 2 + 2))
281       return FALSE;
282
283     qt_atom_parser_peek_sub (data, 0, 78, &sub);
284     gst_byte_reader_skip (&sub, 6);
285     GST_LOG ("%*s    data reference:%d", depth, "", GET_UINT16 (&sub));
286     GST_LOG ("%*s    version/rev.:  %08x", depth, "", GET_UINT32 (&sub));
287     fourcc = GET_FOURCC (&sub);
288     GST_LOG ("%*s    vendor:        %" GST_FOURCC_FORMAT, depth, "",
289         GST_FOURCC_ARGS (fourcc));
290     GST_LOG ("%*s    temporal qual: %u", depth, "", GET_UINT32 (&sub));
291     GST_LOG ("%*s    spatial qual:  %u", depth, "", GET_UINT32 (&sub));
292     GST_LOG ("%*s    width:         %u", depth, "", GET_UINT16 (&sub));
293     GST_LOG ("%*s    height:        %u", depth, "", GET_UINT16 (&sub));
294     GST_LOG ("%*s    horiz. resol:  %g", depth, "", GET_FP32 (&sub));
295     GST_LOG ("%*s    vert. resol.:  %g", depth, "", GET_FP32 (&sub));
296     GST_LOG ("%*s    data size:     %u", depth, "", GET_UINT32 (&sub));
297     GST_LOG ("%*s    frame count:   %u", depth, "", GET_UINT16 (&sub));
298     /* something is not right with this, it's supposed to be a string but it's
299      * not apparently, so just skip this for now */
300     gst_byte_reader_skip (&sub, 1 + 31);
301     GST_LOG ("%*s    compressor:    (skipped)", depth, "");
302     GST_LOG ("%*s    depth:         %u", depth, "", GET_UINT16 (&sub));
303     GST_LOG ("%*s    color table ID:%u", depth, "", GET_UINT16 (&sub));
304     if (!gst_byte_reader_skip (data, size - (4 + 4)))
305       return FALSE;
306   }
307   return TRUE;
308 }
309
310 gboolean
311 qtdemux_dump_stts (GstQTDemux * qtdemux, GstByteReader * data, int depth)
312 {
313   guint32 ver_flags = 0, num_entries = 0, i;
314
315   if (!gst_byte_reader_get_uint32_be (data, &ver_flags) ||
316       !gst_byte_reader_get_uint32_be (data, &num_entries))
317     return FALSE;
318
319   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
320   GST_LOG ("%*s  n entries:     %d", depth, "", num_entries);
321
322   if (!qt_atom_parser_has_chunks (data, num_entries, 4 + 4))
323     return FALSE;
324
325   for (i = 0; i < num_entries; i++) {
326     GST_LOG ("%*s    count:         %u", depth, "", GET_UINT32 (data));
327     GST_LOG ("%*s    duration:      %u", depth, "", GET_UINT32 (data));
328   }
329   return TRUE;
330 }
331
332 gboolean
333 qtdemux_dump_stps (GstQTDemux * qtdemux, GstByteReader * data, int depth)
334 {
335   guint32 ver_flags = 0, num_entries = 0, i;
336
337   if (!gst_byte_reader_get_uint32_be (data, &ver_flags) ||
338       !gst_byte_reader_get_uint32_be (data, &num_entries))
339     return FALSE;
340
341   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
342   GST_LOG ("%*s  n entries:     %d", depth, "", num_entries);
343
344   if (!qt_atom_parser_has_chunks (data, num_entries, 4))
345     return FALSE;
346
347   for (i = 0; i < num_entries; i++) {
348     GST_LOG ("%*s    sample:        %u", depth, "", GET_UINT32 (data));
349   }
350   return TRUE;
351 }
352
353 gboolean
354 qtdemux_dump_stss (GstQTDemux * qtdemux, GstByteReader * data, int depth)
355 {
356   guint32 ver_flags = 0, num_entries = 0, i;
357
358   if (!gst_byte_reader_get_uint32_be (data, &ver_flags) ||
359       !gst_byte_reader_get_uint32_be (data, &num_entries))
360     return FALSE;
361
362   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
363   GST_LOG ("%*s  n entries:     %d", depth, "", num_entries);
364
365   if (!qt_atom_parser_has_chunks (data, num_entries, 4))
366     return FALSE;
367
368   for (i = 0; i < num_entries; i++) {
369     GST_LOG ("%*s    sample:        %u", depth, "", GET_UINT32 (data));
370   }
371   return TRUE;
372 }
373
374 gboolean
375 qtdemux_dump_stsc (GstQTDemux * qtdemux, GstByteReader * data, int depth)
376 {
377   guint32 ver_flags = 0, num_entries = 0, i;
378
379   if (!gst_byte_reader_get_uint32_be (data, &ver_flags) ||
380       !gst_byte_reader_get_uint32_be (data, &num_entries))
381     return FALSE;
382
383   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
384   GST_LOG ("%*s  n entries:     %d", depth, "", num_entries);
385
386   if (!qt_atom_parser_has_chunks (data, num_entries, 4 + 4 + 4))
387     return FALSE;
388
389   for (i = 0; i < num_entries; i++) {
390     GST_LOG ("%*s    first chunk:   %u", depth, "", GET_UINT32 (data));
391     GST_LOG ("%*s    sample per ch: %u", depth, "", GET_UINT32 (data));
392     GST_LOG ("%*s    sample desc id:%08x", depth, "", GET_UINT32 (data));
393   }
394   return TRUE;
395 }
396
397 gboolean
398 qtdemux_dump_stsz (GstQTDemux * qtdemux, GstByteReader * data, int depth)
399 {
400   guint32 ver_flags = 0, sample_size = 0, num_entries = 0;
401
402   if (!gst_byte_reader_get_uint32_be (data, &ver_flags) ||
403       !gst_byte_reader_get_uint32_be (data, &sample_size))
404     return FALSE;
405
406   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
407   GST_LOG ("%*s  sample size:   %d", depth, "", sample_size);
408
409   if (sample_size == 0) {
410     if (!gst_byte_reader_get_uint32_be (data, &num_entries))
411       return FALSE;
412
413     GST_LOG ("%*s  n entries:     %d", depth, "", num_entries);
414 #if 0
415     if (!qt_atom_parser_has_chunks (data, num_entries, 4))
416       return FALSE;
417     for (i = 0; i < num_entries; i++) {
418       GST_LOG ("%*s    sample size:   %u", depth, "", GET_UINT32 (data));
419     }
420 #endif
421   }
422   return TRUE;
423 }
424
425 gboolean
426 qtdemux_dump_stco (GstQTDemux * qtdemux, GstByteReader * data, int depth)
427 {
428   guint32 ver_flags = 0, num_entries = 0, i;
429
430   if (!gst_byte_reader_get_uint32_be (data, &ver_flags) ||
431       !gst_byte_reader_get_uint32_be (data, &num_entries))
432     return FALSE;
433
434   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
435   GST_LOG ("%*s  n entries:     %d", depth, "", num_entries);
436
437   if (!qt_atom_parser_has_chunks (data, num_entries, 4))
438     return FALSE;
439
440   for (i = 0; i < num_entries; i++) {
441     GST_LOG ("%*s    chunk offset:  %u", depth, "", GET_UINT32 (data));
442   }
443   return TRUE;
444 }
445
446 gboolean
447 qtdemux_dump_ctts (GstQTDemux * qtdemux, GstByteReader * data, int depth)
448 {
449   guint32 ver_flags = 0, num_entries = 0, i, count, offset;
450
451   if (!gst_byte_reader_get_uint32_be (data, &ver_flags) ||
452       !gst_byte_reader_get_uint32_be (data, &num_entries))
453     return FALSE;
454
455   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
456   GST_LOG ("%*s  n entries:     %d", depth, "", num_entries);
457
458   if (!qt_atom_parser_has_chunks (data, num_entries, 4 + 4))
459     return FALSE;
460
461   for (i = 0; i < num_entries; i++) {
462     count = GET_UINT32 (data);
463     offset = GET_UINT32 (data);
464     GST_LOG ("%*s    sample count :%8d offset: %8d", depth, "", count, offset);
465   }
466   return TRUE;
467 }
468
469 gboolean
470 qtdemux_dump_co64 (GstQTDemux * qtdemux, GstByteReader * data, int depth)
471 {
472   guint32 ver_flags = 0, num_entries = 0, i;
473
474   if (!gst_byte_reader_get_uint32_be (data, &ver_flags) ||
475       !gst_byte_reader_get_uint32_be (data, &num_entries))
476     return FALSE;
477
478   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
479   GST_LOG ("%*s  n entries:     %d", depth, "", num_entries);
480
481   if (!qt_atom_parser_has_chunks (data, num_entries, 8))
482     return FALSE;
483
484   for (i = 0; i < num_entries; i++) {
485     GST_LOG ("%*s    chunk offset:  %" G_GUINT64_FORMAT, depth, "",
486         GET_UINT64 (data));
487   }
488   return TRUE;
489 }
490
491 gboolean
492 qtdemux_dump_dcom (GstQTDemux * qtdemux, GstByteReader * data, int depth)
493 {
494   if (!qt_atom_parser_has_remaining (data, 4))
495     return FALSE;
496
497   GST_LOG ("%*s  compression type: %" GST_FOURCC_FORMAT, depth, "",
498       GST_FOURCC_ARGS (GET_FOURCC (data)));
499   return TRUE;
500 }
501
502 gboolean
503 qtdemux_dump_cmvd (GstQTDemux * qtdemux, GstByteReader * data, int depth)
504 {
505   if (!qt_atom_parser_has_remaining (data, 4))
506     return FALSE;
507
508   GST_LOG ("%*s  length: %d", depth, "", GET_UINT32 (data));
509   return TRUE;
510 }
511
512 gboolean
513 qtdemux_dump_mfro (GstQTDemux * qtdemux, GstByteReader * data, int depth)
514 {
515   if (!qt_atom_parser_has_remaining (data, 4))
516     return FALSE;
517
518   GST_LOG ("%*s  size: %d", depth, "", GET_UINT32 (data));
519   return TRUE;
520 }
521
522 gboolean
523 qtdemux_dump_tfra (GstQTDemux * qtdemux, GstByteReader * data, int depth)
524 {
525   guint64 time = 0, moof_offset = 0;
526   guint32 len = 0, num_entries = 0, ver_flags = 0, track_id = 0, i;
527   guint value_size, traf_size, trun_size, sample_size;
528
529   if (!gst_byte_reader_get_uint32_be (data, &ver_flags))
530     return FALSE;
531
532   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
533
534   if (!gst_byte_reader_get_uint32_be (data, &track_id) ||
535       gst_byte_reader_get_uint32_be (data, &len) ||
536       gst_byte_reader_get_uint32_be (data, &num_entries))
537     return FALSE;
538
539   GST_LOG ("%*s  track ID:      %u", depth, "", track_id);
540   GST_LOG ("%*s  length:        0x%x", depth, "", len);
541   GST_LOG ("%*s  n entries:     %u", depth, "", num_entries);
542
543   value_size = ((ver_flags >> 24) == 1) ? sizeof (guint64) : sizeof (guint32);
544   sample_size = (len & 3) + 1;
545   trun_size = ((len & 12) >> 2) + 1;
546   traf_size = ((len & 48) >> 4) + 1;
547
548   if (!qt_atom_parser_has_chunks (data, num_entries,
549           value_size + value_size + traf_size + trun_size + sample_size))
550     return FALSE;
551
552   for (i = 0; i < num_entries; i++) {
553     qt_atom_parser_get_offset (data, value_size, &time);
554     qt_atom_parser_get_offset (data, value_size, &moof_offset);
555     GST_LOG ("%*s    time:          %" G_GUINT64_FORMAT, depth, "", time);
556     GST_LOG ("%*s    moof_offset:   %" G_GUINT64_FORMAT,
557         depth, "", moof_offset);
558     GST_LOG ("%*s    traf_number:   %u", depth, "",
559         qt_atom_parser_get_uint_with_size_unchecked (data, traf_size));
560     GST_LOG ("%*s    trun_number:   %u", depth, "",
561         qt_atom_parser_get_uint_with_size_unchecked (data, trun_size));
562     GST_LOG ("%*s    sample_number: %u", depth, "",
563         qt_atom_parser_get_uint_with_size_unchecked (data, sample_size));
564   }
565
566   return TRUE;
567 }
568
569 gboolean
570 qtdemux_dump_tfhd (GstQTDemux * qtdemux, GstByteReader * data, int depth)
571 {
572   guint32 flags = 0, n = 0, track_id = 0;
573   guint64 base_data_offset = 0;
574
575   if (!gst_byte_reader_skip (data, 1) ||
576       !gst_byte_reader_get_uint24_be (data, &flags))
577     return FALSE;
578   GST_LOG ("%*s  flags: %08x", depth, "", flags);
579
580   if (!gst_byte_reader_get_uint32_be (data, &track_id))
581     return FALSE;
582   GST_LOG ("%*s  track_id: %u", depth, "", track_id);
583
584   if (flags & TF_BASE_DATA_OFFSET) {
585     if (!gst_byte_reader_get_uint64_be (data, &base_data_offset))
586       return FALSE;
587     GST_LOG ("%*s    base-data-offset: %" G_GUINT64_FORMAT,
588         depth, "", base_data_offset);
589   }
590
591   if (flags & TF_SAMPLE_DESCRIPTION_INDEX) {
592     if (!gst_byte_reader_get_uint32_be (data, &n))
593       return FALSE;
594     GST_LOG ("%*s    sample-description-index: %u", depth, "", n);
595   }
596
597   if (flags & TF_DEFAULT_SAMPLE_DURATION) {
598     if (!gst_byte_reader_get_uint32_be (data, &n))
599       return FALSE;
600     GST_LOG ("%*s    default-sample-duration:  %u", depth, "", n);
601   }
602
603   if (flags & TF_DEFAULT_SAMPLE_SIZE) {
604     if (!gst_byte_reader_get_uint32_be (data, &n))
605       return FALSE;
606     GST_LOG ("%*s    default-sample-size:  %u", depth, "", n);
607   }
608
609   if (flags & TF_DEFAULT_SAMPLE_FLAGS) {
610     if (!gst_byte_reader_get_uint32_be (data, &n))
611       return FALSE;
612     GST_LOG ("%*s    default-sample-flags:  %u", depth, "", n);
613   }
614
615   GST_LOG ("%*s    duration-is-empty:     %s", depth, "",
616       flags & TF_DURATION_IS_EMPTY ? "yes" : "no");
617
618   return TRUE;
619 }
620
621 gboolean
622 qtdemux_dump_trun (GstQTDemux * qtdemux, GstByteReader * data, int depth)
623 {
624   guint32 flags = 0, samples_count = 0, data_offset = 0, first_sample_flags = 0;
625   guint32 sample_duration = 0, sample_size = 0, sample_flags =
626       0, composition_time_offsets = 0;
627   int i = 0;
628
629   if (!gst_byte_reader_skip (data, 1) ||
630       !gst_byte_reader_get_uint24_be (data, &flags))
631     return FALSE;
632
633   GST_LOG ("%*s  flags: %08x", depth, "", flags);
634
635   if (!gst_byte_reader_get_uint32_be (data, &samples_count))
636     return FALSE;
637   GST_LOG ("%*s  samples_count: %u", depth, "", samples_count);
638
639   if (flags & TR_DATA_OFFSET) {
640     if (!gst_byte_reader_get_uint32_be (data, &data_offset))
641       return FALSE;
642     GST_LOG ("%*s    data-offset: %u", depth, "", data_offset);
643   }
644
645   if (flags & TR_FIRST_SAMPLE_FLAGS) {
646     if (!gst_byte_reader_get_uint32_be (data, &first_sample_flags))
647       return FALSE;
648     GST_LOG ("%*s    first-sample-flags: %u", depth, "", first_sample_flags);
649   }
650
651   for (i = 0; i < samples_count; i++) {
652     if (flags & TR_SAMPLE_DURATION) {
653       if (!gst_byte_reader_get_uint32_be (data, &sample_duration))
654         return FALSE;
655       GST_LOG ("%*s    sample-duration:  %u", depth, "", sample_duration);
656     }
657
658     if (flags & TR_SAMPLE_SIZE) {
659       if (!gst_byte_reader_get_uint32_be (data, &sample_size))
660         return FALSE;
661       GST_LOG ("%*s    sample-size:  %u", depth, "", sample_size);
662     }
663
664     if (flags & TR_SAMPLE_FLAGS) {
665       if (!gst_byte_reader_get_uint32_be (data, &sample_flags))
666         return FALSE;
667       GST_LOG ("%*s    sample-flags:  %u", depth, "", sample_flags);
668     }
669
670     if (flags & TR_COMPOSITION_TIME_OFFSETS) {
671       if (!gst_byte_reader_get_uint32_be (data, &composition_time_offsets))
672         return FALSE;
673       GST_LOG ("%*s    composition_time_offsets:  %u", depth, "",
674           composition_time_offsets);
675     }
676   }
677
678   return TRUE;
679 }
680
681 gboolean
682 qtdemux_dump_trex (GstQTDemux * qtdemux, GstByteReader * data, int depth)
683 {
684   if (!qt_atom_parser_has_remaining (data, 4 + 4 + 4 + 4 + 4 + 4))
685     return FALSE;
686
687   GST_LOG ("%*s  version/flags: %08x", depth, "", GET_UINT32 (data));
688   GST_LOG ("%*s  track ID:      %08x", depth, "", GET_UINT32 (data));
689   GST_LOG ("%*s  default sample desc. index: %08x", depth, "",
690       GET_UINT32 (data));
691   GST_LOG ("%*s  default sample duration:    %08x", depth, "",
692       GET_UINT32 (data));
693   GST_LOG ("%*s  default sample size:        %08x", depth, "",
694       GET_UINT32 (data));
695   GST_LOG ("%*s  default sample flags:       %08x", depth, "",
696       GET_UINT32 (data));
697
698   return TRUE;
699 }
700
701 gboolean
702 qtdemux_dump_mehd (GstQTDemux * qtdemux, GstByteReader * data, int depth)
703 {
704   guint32 version = 0;
705   guint64 fragment_duration;
706   guint value_size;
707
708   if (!gst_byte_reader_get_uint32_be (data, &version))
709     return FALSE;
710
711   GST_LOG ("%*s  version/flags: %08x", depth, "", version);
712
713   value_size = ((version >> 24) == 1) ? sizeof (guint64) : sizeof (guint32);
714   if (qt_atom_parser_get_offset (data, value_size, &fragment_duration)) {
715     GST_LOG ("%*s  fragment duration: %" G_GUINT64_FORMAT,
716         depth, "", fragment_duration);
717     return TRUE;
718   }
719
720   return FALSE;
721 }
722
723 gboolean
724 qtdemux_dump_sdtp (GstQTDemux * qtdemux, GstByteReader * data, int depth)
725 {
726   guint32 version;
727   guint8 val;
728   guint i = 1;
729
730   version = GET_UINT32 (data);
731   GST_LOG ("%*s  version/flags: %08x", depth, "", version);
732
733   /* the sample_count is specified in the stsz or stz2 box.
734    * the information for a sample is stored in a single byte,
735    * so we read until there are no remaining bytes */
736   while (qt_atom_parser_has_remaining (data, 1)) {
737     val = GET_UINT8 (data);
738     GST_LOG ("%*s     sample number: %d", depth, "", i);
739     GST_LOG ("%*s     sample_depends_on: %d", depth, "",
740         ((guint16) (val)) & 0x3);
741     GST_LOG ("%*s     sample_is_depended_on: %d", depth, "",
742         ((guint16) (val >> 2)) & 0x3);
743     GST_LOG ("%*s     sample_has_redundancy: %d", depth, "",
744         ((guint16) (val >> 4)) & 0x3);
745     ++i;
746   }
747   return TRUE;
748 }
749
750 gboolean
751 qtdemux_dump_unknown (GstQTDemux * qtdemux, GstByteReader * data, int depth)
752 {
753   int len;
754
755   len = gst_byte_reader_get_remaining (data);
756   GST_LOG ("%*s  length: %d", depth, "", len);
757
758   GST_MEMDUMP_OBJECT (qtdemux, "unknown atom data",
759       gst_byte_reader_peek_data_unchecked (data), len);
760   return TRUE;
761 }
762
763 static gboolean
764 qtdemux_node_dump_foreach (GNode * node, gpointer qtdemux)
765 {
766   GstByteReader parser;
767   guint8 *buffer = (guint8 *) node->data;       /* FIXME: move to byte reader */
768   guint32 node_length;
769   guint32 fourcc;
770   const QtNodeType *type;
771   int depth;
772
773   node_length = GST_READ_UINT32_BE (buffer);
774   fourcc = GST_READ_UINT32_LE (buffer + 4);
775
776   g_warn_if_fail (node_length >= 8);
777
778   gst_byte_reader_init (&parser, buffer + 8, node_length - 8);
779
780   type = qtdemux_type_get (fourcc);
781
782   depth = (g_node_depth (node) - 1) * 2;
783   GST_LOG ("%*s'%" GST_FOURCC_FORMAT "', [%d], %s",
784       depth, "", GST_FOURCC_ARGS (fourcc), node_length, type->name);
785
786   if (type->dump) {
787     gboolean ret;
788
789     ret = type->dump (GST_QTDEMUX_CAST (qtdemux), &parser, depth);
790
791     if (!ret) {
792       GST_WARNING ("%*s  not enough data parsing atom %" GST_FOURCC_FORMAT,
793           depth, "", GST_FOURCC_ARGS (fourcc));
794     }
795   }
796
797   return FALSE;
798 }
799
800 gboolean
801 qtdemux_node_dump (GstQTDemux * qtdemux, GNode * node)
802 {
803   if (_gst_debug_min < GST_LEVEL_LOG)
804     return TRUE;
805
806   g_node_traverse (node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
807       qtdemux_node_dump_foreach, qtdemux);
808   return TRUE;
809 }