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>
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.
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.
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.
22 #include "piffdemux_types.h"
23 #include "piffdemux_dump.h"
25 #include "piffatomparser.h"
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) piff_atom_parser_get_fourcc_unchecked(data)
38 piffdemux_dump_vmhd (GstPiffDemux * piffdemux, GstByteReader * data, int depth)
40 if (!piff_atom_parser_has_remaining (data, 4 + 4))
43 GST_LOG ("%*s version/flags: %08x", depth, "", GET_UINT32 (data));
44 GST_LOG ("%*s mode/color: %08x", depth, "", GET_UINT32 (data));
50 piffdemux_dump_mfro (GstPiffDemux * piffdemux, GstByteReader * data, int depth)
52 if (!piff_atom_parser_has_remaining (data, 4))
55 GST_LOG ("%*s size: %d", depth, "", GET_UINT32 (data));
60 piffdemux_dump_tfra (GstPiffDemux * piffdemux, GstByteReader * data, int depth)
62 guint64 time = 0, moof_offset = 0;
63 guint32 len = 0, num_entries = 0, ver_flags = 0, track_id = 0, i;
64 guint value_size, traf_size, trun_size, sample_size;
66 if (!gst_byte_reader_get_uint32_be (data, &ver_flags))
69 GST_LOG ("%*s version/flags: %08x", depth, "", ver_flags);
71 if (!gst_byte_reader_get_uint32_be (data, &track_id) ||
72 gst_byte_reader_get_uint32_be (data, &len) ||
73 gst_byte_reader_get_uint32_be (data, &num_entries))
76 GST_LOG ("%*s track ID: %u", depth, "", track_id);
77 GST_LOG ("%*s length: 0x%x", depth, "", len);
78 GST_LOG ("%*s n entries: %u", depth, "", num_entries);
80 value_size = ((ver_flags >> 24) == 1) ? sizeof (guint64) : sizeof (guint32);
81 sample_size = (len & 3) + 1;
82 trun_size = ((len & 12) >> 2) + 1;
83 traf_size = ((len & 48) >> 4) + 1;
85 if (!piff_atom_parser_has_chunks (data, num_entries,
86 value_size + value_size + traf_size + trun_size + sample_size))
89 for (i = 0; i < num_entries; i++) {
90 piff_atom_parser_get_offset (data, value_size, &time);
91 piff_atom_parser_get_offset (data, value_size, &moof_offset);
92 GST_LOG ("%*s time: %" G_GUINT64_FORMAT, depth, "", time);
93 GST_LOG ("%*s moof_offset: %" G_GUINT64_FORMAT,
94 depth, "", moof_offset);
95 GST_LOG ("%*s traf_number: %u", depth, "",
96 piff_atom_parser_get_uint_with_size_unchecked (data, traf_size));
97 GST_LOG ("%*s trun_number: %u", depth, "",
98 piff_atom_parser_get_uint_with_size_unchecked (data, trun_size));
99 GST_LOG ("%*s sample_number: %u", depth, "",
100 piff_atom_parser_get_uint_with_size_unchecked (data, sample_size));
107 piffdemux_dump_tfhd (GstPiffDemux * piffdemux, GstByteReader * data, int depth)
109 guint32 flags = 0, n = 0, track_id = 0;
110 guint64 base_data_offset = 0;
112 if (!gst_byte_reader_skip (data, 1) ||
113 !gst_byte_reader_get_uint24_be (data, &flags))
115 GST_LOG ("%*s flags: %08x", depth, "", flags);
117 if (!gst_byte_reader_get_uint32_be (data, &track_id))
119 GST_LOG ("%*s track_id: %u", depth, "", track_id);
121 if (flags & TF_BASE_DATA_OFFSET) {
122 if (!gst_byte_reader_get_uint64_be (data, &base_data_offset))
124 GST_LOG ("%*s base-data-offset: %" G_GUINT64_FORMAT,
125 depth, "", base_data_offset);
128 if (flags & TF_SAMPLE_DESCRIPTION_INDEX) {
129 if (!gst_byte_reader_get_uint32_be (data, &n))
131 GST_LOG ("%*s sample-description-index: %u", depth, "", n);
134 if (flags & TF_DEFAULT_SAMPLE_DURATION) {
135 if (!gst_byte_reader_get_uint32_be (data, &n))
137 GST_LOG ("%*s default-sample-duration: %u", depth, "", n);
140 if (flags & TF_DEFAULT_SAMPLE_SIZE) {
141 if (!gst_byte_reader_get_uint32_be (data, &n))
143 GST_LOG ("%*s default-sample-size: %u", depth, "", n);
146 if (flags & TF_DEFAULT_SAMPLE_FLAGS) {
147 if (!gst_byte_reader_get_uint32_be (data, &n))
149 GST_LOG ("%*s default-sample-flags: %u", depth, "", n);
152 GST_LOG ("%*s duration-is-empty: %s", depth, "",
153 flags & TF_DURATION_IS_EMPTY ? "yes" : "no");
159 piffdemux_dump_trun (GstPiffDemux * piffdemux, GstByteReader * data, int depth)
161 guint32 flags = 0, samples_count = 0, data_offset = 0, first_sample_flags = 0;
162 guint32 sample_duration = 0, sample_size = 0, sample_flags =
163 0, composition_time_offsets = 0;
166 if (!gst_byte_reader_skip (data, 1) ||
167 !gst_byte_reader_get_uint24_be (data, &flags))
170 GST_LOG ("%*s flags: %08x", depth, "", flags);
172 if (!gst_byte_reader_get_uint32_be (data, &samples_count))
174 GST_LOG ("%*s samples_count: %u", depth, "", samples_count);
176 if (flags & TR_DATA_OFFSET) {
177 if (!gst_byte_reader_get_uint32_be (data, &data_offset))
179 GST_LOG ("%*s data-offset: %u", depth, "", data_offset);
182 if (flags & TR_FIRST_SAMPLE_FLAGS) {
183 if (!gst_byte_reader_get_uint32_be (data, &first_sample_flags))
185 GST_LOG ("%*s first-sample-flags: %u", depth, "", first_sample_flags);
188 for (i = 0; i < samples_count; i++) {
189 if (flags & TR_SAMPLE_DURATION) {
190 if (!gst_byte_reader_get_uint32_be (data, &sample_duration))
192 GST_LOG ("%*s sample-duration: %u", depth, "", sample_duration);
195 if (flags & TR_SAMPLE_SIZE) {
196 if (!gst_byte_reader_get_uint32_be (data, &sample_size))
198 GST_LOG ("%*s sample-size: %u", depth, "", sample_size);
201 if (flags & TR_SAMPLE_FLAGS) {
202 if (!gst_byte_reader_get_uint32_be (data, &sample_flags))
204 GST_LOG ("%*s sample-flags: %u", depth, "", sample_flags);
207 if (flags & TR_COMPOSITION_TIME_OFFSETS) {
208 if (!gst_byte_reader_get_uint32_be (data, &composition_time_offsets))
210 GST_LOG ("%*s composition_time_offsets: %u", depth, "",
211 composition_time_offsets);
219 piffdemux_dump_trex (GstPiffDemux * piffdemux, GstByteReader * data, int depth)
221 if (!piff_atom_parser_has_remaining (data, 4 + 4 + 4 + 4 + 4 + 4))
224 GST_LOG ("%*s version/flags: %08x", depth, "", GET_UINT32 (data));
225 GST_LOG ("%*s track ID: %08x", depth, "", GET_UINT32 (data));
226 GST_LOG ("%*s default sample desc. index: %08x", depth, "",
228 GST_LOG ("%*s default sample duration: %08x", depth, "",
230 GST_LOG ("%*s default sample size: %08x", depth, "",
232 GST_LOG ("%*s default sample flags: %08x", depth, "",
240 piffdemux_dump_sdtp (GstPiffDemux * piffdemux, GstByteReader * data, int depth)
246 version = GET_UINT32 (data);
247 GST_LOG ("%*s version/flags: %08x", depth, "", version);
249 /* the sample_count is specified in the stsz or stz2 box.
250 * the information for a sample is stored in a single byte,
251 * so we read until there are no remaining bytes */
252 while (piff_atom_parser_has_remaining (data, 1)) {
253 val = GET_UINT8 (data);
254 GST_LOG ("%*s sample number: %d", depth, "", i);
255 GST_LOG ("%*s sample_depends_on: %d", depth, "",
256 ((guint16) (val)) & 0x3);
257 GST_LOG ("%*s sample_is_depended_on: %d", depth, "",
258 ((guint16) (val >> 2)) & 0x3);
259 GST_LOG ("%*s sample_has_redundancy: %d", depth, "",
260 ((guint16) (val >> 4)) & 0x3);
267 piffdemux_dump_unknown (GstPiffDemux * piffdemux, GstByteReader * data, int depth)
271 len = gst_byte_reader_get_remaining (data);
272 GST_LOG ("%*s length: %d", depth, "", len);
274 GST_MEMDUMP_OBJECT (piffdemux, "unknown atom data",
275 gst_byte_reader_peek_data_unchecked (data), len);
280 piffdemux_node_dump_foreach (GNode * node, gpointer piffdemux)
282 GstByteReader parser;
283 guint8 *buffer = (guint8 *) node->data; /* FIXME: move to byte reader */
286 const PiffNodeType *type;
289 node_length = GST_READ_UINT32_BE (buffer);
290 fourcc = GST_READ_UINT32_LE (buffer + 4);
292 g_warn_if_fail (node_length >= 8);
294 gst_byte_reader_init (&parser, buffer + 8, node_length - 8);
296 type = piffdemux_type_get (fourcc);
298 depth = (g_node_depth (node) - 1) * 2;
299 GST_LOG ("%*s'%" GST_FOURCC_FORMAT "', [%d], %s",
300 depth, "", GST_FOURCC_ARGS (fourcc), node_length, type->name);
305 ret = type->dump (GST_PIFFDEMUX_CAST (piffdemux), &parser, depth);
308 GST_WARNING ("%*s not enough data parsing atom %" GST_FOURCC_FORMAT,
309 depth, "", GST_FOURCC_ARGS (fourcc));
317 piffdemux_node_dump (GstPiffDemux * piffdemux, GNode * node)
319 if (__gst_debug_min < GST_LEVEL_LOG)
322 g_node_traverse (node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
323 piffdemux_node_dump_foreach, piffdemux);