Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.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_stss (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_stsc (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 + 4 + 4))
366     return FALSE;
367
368   for (i = 0; i < num_entries; i++) {
369     GST_LOG ("%*s    first chunk:   %u", depth, "", GET_UINT32 (data));
370     GST_LOG ("%*s    sample per ch: %u", depth, "", GET_UINT32 (data));
371     GST_LOG ("%*s    sample desc id:%08x", depth, "", GET_UINT32 (data));
372   }
373   return TRUE;
374 }
375
376 gboolean
377 qtdemux_dump_stsz (GstQTDemux * qtdemux, GstByteReader * data, int depth)
378 {
379   guint32 ver_flags = 0, sample_size = 0, num_entries = 0;
380
381   if (!gst_byte_reader_get_uint32_be (data, &ver_flags) ||
382       !gst_byte_reader_get_uint32_be (data, &sample_size))
383     return FALSE;
384
385   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
386   GST_LOG ("%*s  sample size:   %d", depth, "", sample_size);
387
388   if (sample_size == 0) {
389     if (!gst_byte_reader_get_uint32_be (data, &num_entries))
390       return FALSE;
391
392     GST_LOG ("%*s  n entries:     %d", depth, "", num_entries);
393 #if 0
394     if (!qt_atom_parser_has_chunks (data, num_entries, 4))
395       return FALSE;
396     for (i = 0; i < num_entries; i++) {
397       GST_LOG ("%*s    sample size:   %u", depth, "", GET_UINT32 (data));
398     }
399 #endif
400   }
401   return TRUE;
402 }
403
404 gboolean
405 qtdemux_dump_stco (GstQTDemux * qtdemux, GstByteReader * data, int depth)
406 {
407   guint32 ver_flags = 0, num_entries = 0, i;
408
409   if (!gst_byte_reader_get_uint32_be (data, &ver_flags) ||
410       !gst_byte_reader_get_uint32_be (data, &num_entries))
411     return FALSE;
412
413   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
414   GST_LOG ("%*s  n entries:     %d", depth, "", num_entries);
415
416   if (!qt_atom_parser_has_chunks (data, num_entries, 4))
417     return FALSE;
418
419   for (i = 0; i < num_entries; i++) {
420     GST_LOG ("%*s    chunk offset:  %u", depth, "", GET_UINT32 (data));
421   }
422   return TRUE;
423 }
424
425 gboolean
426 qtdemux_dump_ctts (GstQTDemux * qtdemux, GstByteReader * data, int depth)
427 {
428   guint32 ver_flags = 0, num_entries = 0, i, count, offset;
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 + 4))
438     return FALSE;
439
440   for (i = 0; i < num_entries; i++) {
441     count = GET_UINT32 (data);
442     offset = GET_UINT32 (data);
443     GST_LOG ("%*s    sample count :%8d offset: %8d", depth, "", count, offset);
444   }
445   return TRUE;
446 }
447
448 gboolean
449 qtdemux_dump_co64 (GstQTDemux * qtdemux, GstByteReader * data, int depth)
450 {
451   guint32 ver_flags = 0, num_entries = 0, i;
452
453   if (!gst_byte_reader_get_uint32_be (data, &ver_flags) ||
454       !gst_byte_reader_get_uint32_be (data, &num_entries))
455     return FALSE;
456
457   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
458   GST_LOG ("%*s  n entries:     %d", depth, "", num_entries);
459
460   if (!qt_atom_parser_has_chunks (data, num_entries, 8))
461     return FALSE;
462
463   for (i = 0; i < num_entries; i++) {
464     GST_LOG ("%*s    chunk offset:  %" G_GUINT64_FORMAT, depth, "",
465         GET_UINT64 (data));
466   }
467   return TRUE;
468 }
469
470 gboolean
471 qtdemux_dump_mfro (GstQTDemux * qtdemux, GstByteReader * data, int depth)
472 {
473   if (!qt_atom_parser_has_remaining (data, 4))
474     return FALSE;
475
476   GST_LOG ("%*s  size: %d", depth, "", GET_UINT32 (data));
477   return TRUE;
478 }
479
480 gboolean
481 qtdemux_dump_tfra (GstQTDemux * qtdemux, GstByteReader * data, int depth)
482 {
483   guint64 time = 0, moof_offset = 0;
484   guint32 len = 0, num_entries = 0, ver_flags = 0, track_id = 0, i;
485   guint value_size, traf_size, trun_size, sample_size;
486
487   if (!gst_byte_reader_get_uint32_be (data, &ver_flags))
488     return FALSE;
489
490   GST_LOG ("%*s  version/flags: %08x", depth, "", ver_flags);
491
492   if (!gst_byte_reader_get_uint32_be (data, &track_id) ||
493       gst_byte_reader_get_uint32_be (data, &len) ||
494       gst_byte_reader_get_uint32_be (data, &num_entries))
495     return FALSE;
496
497   GST_LOG ("%*s  track ID:      %u", depth, "", track_id);
498   GST_LOG ("%*s  length:        0x%x", depth, "", len);
499   GST_LOG ("%*s  n entries:     %u", depth, "", num_entries);
500
501   value_size = ((ver_flags >> 24) == 1) ? sizeof (guint64) : sizeof (guint32);
502   sample_size = (len & 3) + 1;
503   trun_size = ((len & 12) >> 2) + 1;
504   traf_size = ((len & 48) >> 4) + 1;
505
506   if (!qt_atom_parser_has_chunks (data, num_entries,
507           value_size + value_size + traf_size + trun_size + sample_size))
508     return FALSE;
509
510   for (i = 0; i < num_entries; i++) {
511     qt_atom_parser_get_offset (data, value_size, &time);
512     qt_atom_parser_get_offset (data, value_size, &moof_offset);
513     GST_LOG ("%*s    time:          %" G_GUINT64_FORMAT, depth, "", time);
514     GST_LOG ("%*s    moof_offset:   %" G_GUINT64_FORMAT,
515         depth, "", moof_offset);
516     GST_LOG ("%*s    traf_number:   %u", depth, "",
517         qt_atom_parser_get_uint_with_size_unchecked (data, traf_size));
518     GST_LOG ("%*s    trun_number:   %u", depth, "",
519         qt_atom_parser_get_uint_with_size_unchecked (data, trun_size));
520     GST_LOG ("%*s    sample_number: %u", depth, "",
521         qt_atom_parser_get_uint_with_size_unchecked (data, sample_size));
522   }
523
524   return TRUE;
525 }
526
527 gboolean
528 qtdemux_dump_tfhd (GstQTDemux * qtdemux, GstByteReader * data, int depth)
529 {
530   guint32 flags = 0, n = 0, track_id = 0;
531   guint64 base_data_offset = 0;
532
533   if (!gst_byte_reader_skip (data, 1) ||
534       !gst_byte_reader_get_uint24_be (data, &flags))
535     return FALSE;
536   GST_LOG ("%*s  flags: %08x", depth, "", flags);
537
538   if (!gst_byte_reader_get_uint32_be (data, &track_id))
539     return FALSE;
540   GST_LOG ("%*s  track_id: %u", depth, "", track_id);
541
542   if (flags & TF_BASE_DATA_OFFSET) {
543     if (!gst_byte_reader_get_uint64_be (data, &base_data_offset))
544       return FALSE;
545     GST_LOG ("%*s    base-data-offset: %" G_GUINT64_FORMAT,
546         depth, "", base_data_offset);
547   }
548
549   if (flags & TF_SAMPLE_DESCRIPTION_INDEX) {
550     if (!gst_byte_reader_get_uint32_be (data, &n))
551       return FALSE;
552     GST_LOG ("%*s    sample-description-index: %u", depth, "", n);
553   }
554
555   if (flags & TF_DEFAULT_SAMPLE_DURATION) {
556     if (!gst_byte_reader_get_uint32_be (data, &n))
557       return FALSE;
558     GST_LOG ("%*s    default-sample-duration:  %u", depth, "", n);
559   }
560
561   if (flags & TF_DEFAULT_SAMPLE_SIZE) {
562     if (!gst_byte_reader_get_uint32_be (data, &n))
563       return FALSE;
564     GST_LOG ("%*s    default-sample-size:  %u", depth, "", n);
565   }
566
567   if (flags & TF_DEFAULT_SAMPLE_FLAGS) {
568     if (!gst_byte_reader_get_uint32_be (data, &n))
569       return FALSE;
570     GST_LOG ("%*s    default-sample-flags:  %u", depth, "", n);
571   }
572
573   GST_LOG ("%*s    duration-is-empty:     %s", depth, "",
574       flags & TF_DURATION_IS_EMPTY ? "yes" : "no");
575
576   return TRUE;
577 }
578
579 gboolean
580 qtdemux_dump_trun (GstQTDemux * qtdemux, GstByteReader * data, int depth)
581 {
582   guint32 flags = 0, samples_count = 0, data_offset = 0, first_sample_flags = 0;
583   guint32 sample_duration = 0, sample_size = 0, sample_flags =
584       0, composition_time_offsets = 0;
585   int i = 0;
586
587   if (!gst_byte_reader_skip (data, 1) ||
588       !gst_byte_reader_get_uint24_be (data, &flags))
589     return FALSE;
590
591   GST_LOG ("%*s  flags: %08x", depth, "", flags);
592
593   if (!gst_byte_reader_get_uint32_be (data, &samples_count))
594     return FALSE;
595   GST_LOG ("%*s  samples_count: %u", depth, "", samples_count);
596
597   if (flags & TR_DATA_OFFSET) {
598     if (!gst_byte_reader_get_uint32_be (data, &data_offset))
599       return FALSE;
600     GST_LOG ("%*s    data-offset: %u", depth, "", data_offset);
601   }
602
603   if (flags & TR_FIRST_SAMPLE_FLAGS) {
604     if (!gst_byte_reader_get_uint32_be (data, &first_sample_flags))
605       return FALSE;
606     GST_LOG ("%*s    first-sample-flags: %u", depth, "", first_sample_flags);
607   }
608
609   for (i = 0; i < samples_count; i++) {
610     if (flags & TR_SAMPLE_DURATION) {
611       if (!gst_byte_reader_get_uint32_be (data, &sample_duration))
612         return FALSE;
613       GST_LOG ("%*s    sample-duration:  %u", depth, "", sample_duration);
614     }
615
616     if (flags & TR_SAMPLE_SIZE) {
617       if (!gst_byte_reader_get_uint32_be (data, &sample_size))
618         return FALSE;
619       GST_LOG ("%*s    sample-size:  %u", depth, "", sample_size);
620     }
621
622     if (flags & TR_SAMPLE_FLAGS) {
623       if (!gst_byte_reader_get_uint32_be (data, &sample_flags))
624         return FALSE;
625       GST_LOG ("%*s    sample-flags:  %u", depth, "", sample_flags);
626     }
627
628     if (flags & TR_COMPOSITION_TIME_OFFSETS) {
629       if (!gst_byte_reader_get_uint32_be (data, &composition_time_offsets))
630         return FALSE;
631       GST_LOG ("%*s    composition_time_offsets:  %u", depth, "",
632           composition_time_offsets);
633     }
634   }
635
636   return TRUE;
637 }
638
639 gboolean
640 qtdemux_dump_trex (GstQTDemux * qtdemux, GstByteReader * data, int depth)
641 {
642   if (!qt_atom_parser_has_remaining (data, 4 + 4 + 4 + 4 + 4 + 4))
643     return FALSE;
644
645   GST_LOG ("%*s  version/flags: %08x", depth, "", GET_UINT32 (data));
646   GST_LOG ("%*s  track ID:      %08x", depth, "", GET_UINT32 (data));
647   GST_LOG ("%*s  default sample desc. index: %08x", depth, "",
648       GET_UINT32 (data));
649   GST_LOG ("%*s  default sample duration:    %08x", depth, "",
650       GET_UINT32 (data));
651   GST_LOG ("%*s  default sample size:        %08x", depth, "",
652       GET_UINT32 (data));
653   GST_LOG ("%*s  default sample flags:       %08x", depth, "",
654       GET_UINT32 (data));
655
656   return TRUE;
657 }
658
659 gboolean
660 qtdemux_dump_mehd (GstQTDemux * qtdemux, GstByteReader * data, int depth)
661 {
662   guint32 version = 0;
663   guint64 fragment_duration;
664   guint value_size;
665
666   if (!gst_byte_reader_get_uint32_be (data, &version))
667     return FALSE;
668
669   GST_LOG ("%*s  version/flags: %08x", depth, "", version);
670
671   value_size = ((version >> 24) == 1) ? sizeof (guint64) : sizeof (guint32);
672   if (qt_atom_parser_get_offset (data, value_size, &fragment_duration)) {
673     GST_LOG ("%*s  fragment duration: %" G_GUINT64_FORMAT,
674         depth, "", fragment_duration);
675     return TRUE;
676   }
677
678   return FALSE;
679 }
680
681 gboolean
682 qtdemux_dump_sdtp (GstQTDemux * qtdemux, GstByteReader * data, int depth)
683 {
684   guint32 version;
685   guint8 val;
686   guint i = 1;
687
688   version = GET_UINT32 (data);
689   GST_LOG ("%*s  version/flags: %08x", depth, "", version);
690
691   /* the sample_count is specified in the stsz or stz2 box.
692    * the information for a sample is stored in a single byte,
693    * so we read until there are no remaining bytes */
694   while (qt_atom_parser_has_remaining (data, 1)) {
695     val = GET_UINT8 (data);
696     GST_LOG ("%*s     sample number: %d", depth, "", i);
697     GST_LOG ("%*s     sample_depends_on: %d", depth, "",
698         ((guint16) (val)) & 0x3);
699     GST_LOG ("%*s     sample_is_depended_on: %d", depth, "",
700         ((guint16) (val >> 2)) & 0x3);
701     GST_LOG ("%*s     sample_has_redundancy: %d", depth, "",
702         ((guint16) (val >> 4)) & 0x3);
703     ++i;
704   }
705   return TRUE;
706 }
707
708 gboolean
709 qtdemux_dump_unknown (GstQTDemux * qtdemux, GstByteReader * data, int depth)
710 {
711   int len;
712
713   len = gst_byte_reader_get_remaining (data);
714   GST_LOG ("%*s  length: %d", depth, "", len);
715
716   GST_MEMDUMP_OBJECT (qtdemux, "unknown atom data",
717       gst_byte_reader_peek_data_unchecked (data), len);
718   return TRUE;
719 }
720
721 static gboolean
722 qtdemux_node_dump_foreach (GNode * node, gpointer qtdemux)
723 {
724   GstByteReader parser;
725   guint8 *buffer = (guint8 *) node->data;       /* FIXME: move to byte reader */
726   guint32 node_length;
727   guint32 fourcc;
728   const QtNodeType *type;
729   int depth;
730
731   node_length = GST_READ_UINT32_BE (buffer);
732   fourcc = GST_READ_UINT32_LE (buffer + 4);
733
734   g_warn_if_fail (node_length >= 8);
735
736   gst_byte_reader_init (&parser, buffer + 8, node_length - 8);
737
738   type = qtdemux_type_get (fourcc);
739
740   depth = (g_node_depth (node) - 1) * 2;
741   GST_LOG ("%*s'%" GST_FOURCC_FORMAT "', [%d], %s",
742       depth, "", GST_FOURCC_ARGS (fourcc), node_length, type->name);
743
744   if (type->dump) {
745     gboolean ret;
746
747     ret = type->dump (GST_QTDEMUX_CAST (qtdemux), &parser, depth);
748
749     if (!ret) {
750       GST_WARNING ("%*s  not enough data parsing atom %" GST_FOURCC_FORMAT,
751           depth, "", GST_FOURCC_ARGS (fourcc));
752     }
753   }
754
755   return FALSE;
756 }
757
758 gboolean
759 qtdemux_node_dump (GstQTDemux * qtdemux, GNode * node)
760 {
761   if (__gst_debug_min < GST_LEVEL_LOG)
762     return TRUE;
763
764   g_node_traverse (node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
765       qtdemux_node_dump_foreach, qtdemux);
766   return TRUE;
767 }