qtdemux: use GstByteReader for atom dumping and fix a few bugs

This commit is contained in:
Tim-Philipp Müller 2009-08-19 01:36:33 +01:00
parent c8c9b0f35d
commit 3abeb1e578
4 changed files with 449 additions and 299 deletions

View file

@ -148,4 +148,32 @@ qt_atom_parser_get_offset_unchecked (QtAtomParser * parser, guint off_size)
} }
} }
static inline guint8 *
qt_atom_parser_peek_bytes_unchecked (QtAtomParser * parser)
{
return (guint8 *) parser->data + parser->byte;
}
static inline gboolean
qt_atom_parser_get_fourcc (QtAtomParser * parser, guint32 * fourcc)
{
guint32 f_be;
if (G_UNLIKELY (qt_atom_parser_get_remaining (parser) < 4))
return FALSE;
f_be = qt_atom_parser_get_uint32_unchecked (parser);
*fourcc = GUINT32_SWAP_LE_BE (f_be);
return TRUE;
}
static inline guint32
qt_atom_parser_get_fourcc_unchecked (QtAtomParser * parser)
{
guint32 fourcc;
fourcc = qt_atom_parser_get_uint32_unchecked (parser);
return GUINT32_SWAP_LE_BE (fourcc);
}
#endif /* QT_ATOM_PARSER_H */ #endif /* QT_ATOM_PARSER_H */

View file

@ -1,5 +1,6 @@
/* GStreamer /* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) 2009 Tim-Philipp Müller <tim centricular net>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
@ -20,386 +21,493 @@
#include "qtdemux_types.h" #include "qtdemux_types.h"
#include "qtdemux_dump.h" #include "qtdemux_dump.h"
void #include <gst/base/gstbytereader.h>
qtdemux_dump_mvhd (GstQTDemux * qtdemux, guint8 * buffer, int depth)
#include <string.h>
#define GET_UINT8(data) qt_atom_parser_get_uint8_unchecked(data)
#define GET_UINT16(data) qt_atom_parser_get_uint16_unchecked(data)
#define GET_UINT32(data) qt_atom_parser_get_uint32_unchecked(data)
#define GET_UINT64(data) qt_atom_parser_get_uint64_unchecked(data)
#define GET_FP32(data) (qt_atom_parser_get_uint32_unchecked(data)/65536.0)
#define GET_FP16(data) (qt_atom_parser_get_uint16_unchecked(data)/256.0)
#define GET_FOURCC(data) qt_atom_parser_get_fourcc_unchecked(data)
gboolean
qtdemux_dump_mvhd (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
GST_LOG ("%*s version/flags: %08x", depth, "", QT_UINT32 (buffer + 8)); if (qt_atom_parser_get_remaining (data) < 100)
GST_LOG ("%*s creation time: %u", depth, "", QT_UINT32 (buffer + 12)); return FALSE;
GST_LOG ("%*s modify time: %u", depth, "", QT_UINT32 (buffer + 16));
GST_LOG ("%*s time scale: 1/%u sec", depth, "", QT_UINT32 (buffer + 20)); GST_LOG ("%*s version/flags: %08x", depth, "", GET_UINT32 (data));
GST_LOG ("%*s duration: %u", depth, "", QT_UINT32 (buffer + 24)); GST_LOG ("%*s creation time: %u", depth, "", GET_UINT32 (data));
GST_LOG ("%*s pref. rate: %g", depth, "", QT_FP32 (buffer + 28)); GST_LOG ("%*s modify time: %u", depth, "", GET_UINT32 (data));
GST_LOG ("%*s pref. volume: %g", depth, "", QT_FP16 (buffer + 32)); GST_LOG ("%*s time scale: 1/%u sec", depth, "", GET_UINT32 (data));
GST_LOG ("%*s preview time: %u", depth, "", QT_UINT32 (buffer + 80)); GST_LOG ("%*s duration: %u", depth, "", GET_UINT32 (data));
GST_LOG ("%*s preview dur.: %u", depth, "", QT_UINT32 (buffer + 84)); GST_LOG ("%*s pref. rate: %g", depth, "", GET_FP32 (data));
GST_LOG ("%*s poster time: %u", depth, "", QT_UINT32 (buffer + 88)); GST_LOG ("%*s pref. volume: %g", depth, "", GET_FP16 (data));
GST_LOG ("%*s select time: %u", depth, "", QT_UINT32 (buffer + 92)); qt_atom_parser_skip (data, 46);
GST_LOG ("%*s select dur.: %u", depth, "", QT_UINT32 (buffer + 96)); GST_LOG ("%*s preview time: %u", depth, "", GET_UINT32 (data));
GST_LOG ("%*s current time: %u", depth, "", QT_UINT32 (buffer + 100)); GST_LOG ("%*s preview dur.: %u", depth, "", GET_UINT32 (data));
GST_LOG ("%*s next track ID: %d", depth, "", QT_UINT32 (buffer + 104)); GST_LOG ("%*s poster time: %u", depth, "", GET_UINT32 (data));
GST_LOG ("%*s select time: %u", depth, "", GET_UINT32 (data));
GST_LOG ("%*s select dur.: %u", depth, "", GET_UINT32 (data));
GST_LOG ("%*s current time: %u", depth, "", GET_UINT32 (data));
GST_LOG ("%*s next track ID: %d", depth, "", GET_UINT32 (data));
return TRUE;
} }
void gboolean
qtdemux_dump_tkhd (GstQTDemux * qtdemux, guint8 * buffer, int depth) qtdemux_dump_tkhd (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
GST_LOG ("%*s version/flags: %08x", depth, "", QT_UINT32 (buffer + 8)); guint64 duration, ctime, mtime;
GST_LOG ("%*s creation time: %u", depth, "", QT_UINT32 (buffer + 12)); guint32 version, track_id, iwidth, iheight;
GST_LOG ("%*s modify time: %u", depth, "", QT_UINT32 (buffer + 16)); guint16 layer, alt_group, ivol;
GST_LOG ("%*s track ID: %u", depth, "", QT_UINT32 (buffer + 20)); guint value_size;
GST_LOG ("%*s duration: %u", depth, "", QT_UINT32 (buffer + 28));
GST_LOG ("%*s layer: %u", depth, "", QT_UINT16 (buffer + 36));
GST_LOG ("%*s alt group: %u", depth, "", QT_UINT16 (buffer + 38));
GST_LOG ("%*s volume: %g", depth, "", QT_FP16 (buffer + 44));
GST_LOG ("%*s track width: %g", depth, "", QT_FP32 (buffer + 84));
GST_LOG ("%*s track height: %g", depth, "", QT_FP32 (buffer + 88));
} if (!qt_atom_parser_get_uint32 (data, &version))
return FALSE;
void GST_LOG ("%*s version/flags: %08x", depth, "", version);
qtdemux_dump_elst (GstQTDemux * qtdemux, guint8 * buffer, int depth)
{
int i;
int n;
GST_LOG ("%*s version/flags: %08x", depth, "", QT_UINT32 (buffer + 8)); value_size = ((version >> 24) == 1) ? sizeof (guint64) : sizeof (guint32);
GST_LOG ("%*s n entries: %u", depth, "", QT_UINT32 (buffer + 12));
n = QT_UINT32 (buffer + 12); if (qt_atom_parser_get_offset (data, value_size, &ctime) &&
for (i = 0; i < n; i++) { qt_atom_parser_get_offset (data, value_size, &mtime) &&
GST_LOG ("%*s track dur: %u", depth, "", qt_atom_parser_get_uint32 (data, &track_id) &&
QT_UINT32 (buffer + 16 + i * 12)); qt_atom_parser_skip (data, 4) &&
GST_LOG ("%*s media time: %u", depth, "", qt_atom_parser_get_offset (data, value_size, &duration) &&
QT_UINT32 (buffer + 20 + i * 12)); qt_atom_parser_skip (data, 4) &&
GST_LOG ("%*s media rate: %g", depth, "", qt_atom_parser_get_uint16 (data, &layer) &&
QT_FP32 (buffer + 24 + i * 12)); qt_atom_parser_get_uint16 (data, &alt_group) &&
qt_atom_parser_skip (data, 4) &&
qt_atom_parser_get_uint16 (data, &ivol) &&
qt_atom_parser_skip (data, 2 + (9 * 4)) &&
qt_atom_parser_get_uint32 (data, &iwidth) &&
qt_atom_parser_get_uint32 (data, &iheight)) {
GST_LOG ("%*s creation time: %" G_GUINT64_FORMAT, depth, "", ctime);
GST_LOG ("%*s modify time: %" G_GUINT64_FORMAT, depth, "", mtime);
GST_LOG ("%*s track ID: %u", depth, "", track_id);
GST_LOG ("%*s duration: %" G_GUINT64_FORMAT, depth, "", duration);
GST_LOG ("%*s layer: %u", depth, "", layer);
GST_LOG ("%*s alt group: %u", depth, "", alt_group);
GST_LOG ("%*s volume: %g", depth, "", ivol / 256.0);
GST_LOG ("%*s track width: %g", depth, "", iwidth / 65536.0);
GST_LOG ("%*s track height: %g", depth, "", iheight / 65536.0);
return TRUE;
} }
return FALSE;
} }
void gboolean
qtdemux_dump_mdhd (GstQTDemux * qtdemux, guint8 * buffer, int depth) qtdemux_dump_elst (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{
guint32 ver_flags, num_entries, i;
if (!qt_atom_parser_get_uint32 (data, &ver_flags) ||
!qt_atom_parser_get_uint32 (data, &num_entries))
return FALSE;
GST_LOG ("%*s version/flags: %08x", depth, "", ver_flags);
GST_LOG ("%*s n entries: %d", depth, "", num_entries);
if (qt_atom_parser_get_remaining (data) < (num_entries * (4 + 4 + 4)))
return FALSE;
for (i = 0; i < num_entries; i++) {
GST_LOG ("%*s track dur: %u", depth, "", GET_UINT32 (data));
GST_LOG ("%*s media time: %u", depth, "", GET_UINT32 (data));
GST_LOG ("%*s media rate: %g", depth, "", GET_FP32 (data));
}
return TRUE;
}
gboolean
qtdemux_dump_mdhd (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
guint32 version; guint32 version;
guint64 duration, ctime, mtime; guint64 duration, ctime, mtime;
guint32 time_scale; guint32 time_scale;
guint16 language, quality; guint16 language, quality;
guint value_size;
if (!qt_atom_parser_get_uint32 (data, &version))
return FALSE;
version = QT_UINT32 (buffer + 8);
GST_LOG ("%*s version/flags: %08x", depth, "", version); GST_LOG ("%*s version/flags: %08x", depth, "", version);
if (version == 0x01000000) { value_size = ((version >> 24) == 1) ? sizeof (guint64) : sizeof (guint32);
ctime = QT_UINT64 (buffer + 12);
mtime = QT_UINT64 (buffer + 20); if (qt_atom_parser_get_offset (data, value_size, &ctime) &&
time_scale = QT_UINT32 (buffer + 28); qt_atom_parser_get_offset (data, value_size, &mtime) &&
duration = QT_UINT64 (buffer + 32); qt_atom_parser_get_uint32 (data, &time_scale) &&
language = QT_UINT16 (buffer + 40); qt_atom_parser_get_offset (data, value_size, &duration) &&
quality = QT_UINT16 (buffer + 42); qt_atom_parser_get_uint16 (data, &language) &&
} else { qt_atom_parser_get_uint16 (data, &quality)) {
ctime = QT_UINT32 (buffer + 12); GST_LOG ("%*s creation time: %" G_GUINT64_FORMAT, depth, "", ctime);
mtime = QT_UINT32 (buffer + 16); GST_LOG ("%*s modify time: %" G_GUINT64_FORMAT, depth, "", mtime);
time_scale = QT_UINT32 (buffer + 20); GST_LOG ("%*s time scale: 1/%u sec", depth, "", time_scale);
duration = QT_UINT32 (buffer + 24); GST_LOG ("%*s duration: %" G_GUINT64_FORMAT, depth, "", duration);
language = QT_UINT16 (buffer + 28); GST_LOG ("%*s language: %u", depth, "", language);
quality = QT_UINT16 (buffer + 30); GST_LOG ("%*s quality: %u", depth, "", quality);
return TRUE;
} }
GST_LOG ("%*s creation time: %" G_GUINT64_FORMAT, depth, "", ctime); return FALSE;
GST_LOG ("%*s modify time: %" G_GUINT64_FORMAT, depth, "", mtime);
GST_LOG ("%*s time scale: 1/%u sec", depth, "", time_scale);
GST_LOG ("%*s duration: %" G_GUINT64_FORMAT, depth, "", duration);
GST_LOG ("%*s language: %u", depth, "", language);
GST_LOG ("%*s quality: %u", depth, "", quality);
} }
void gboolean
qtdemux_dump_hdlr (GstQTDemux * qtdemux, guint8 * buffer, int depth) qtdemux_dump_hdlr (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
GST_LOG ("%*s version/flags: %08x", depth, "", QT_UINT32 (buffer + 8)); guint32 version, type, subtype, manufacturer;
const gchar *name;
if (qt_atom_parser_get_remaining (data) < (4 + 4 + 4 + 4 + 4 + 4 + 1))
return FALSE;
version = GET_UINT32 (data);
type = GET_FOURCC (data);
subtype = GET_FOURCC (data);
manufacturer = GET_FOURCC (data);
GST_LOG ("%*s version/flags: %08x", depth, "", version);
GST_LOG ("%*s type: %" GST_FOURCC_FORMAT, depth, "", GST_LOG ("%*s type: %" GST_FOURCC_FORMAT, depth, "",
GST_FOURCC_ARGS (QT_FOURCC (buffer + 12))); GST_FOURCC_ARGS (type));
GST_LOG ("%*s subtype: %" GST_FOURCC_FORMAT, depth, "", GST_LOG ("%*s subtype: %" GST_FOURCC_FORMAT, depth, "",
GST_FOURCC_ARGS (QT_FOURCC (buffer + 16))); GST_FOURCC_ARGS (subtype));
GST_LOG ("%*s manufacturer: %" GST_FOURCC_FORMAT, depth, "", GST_LOG ("%*s manufacturer: %" GST_FOURCC_FORMAT, depth, "",
GST_FOURCC_ARGS (QT_FOURCC (buffer + 20))); GST_FOURCC_ARGS (manufacturer));
GST_LOG ("%*s flags: %08x", depth, "", QT_UINT32 (buffer + 24)); GST_LOG ("%*s flags: %08x", depth, "", GET_UINT32 (data));
GST_LOG ("%*s flags mask: %08x", depth, "", QT_UINT32 (buffer + 28)); GST_LOG ("%*s flags mask: %08x", depth, "", GET_UINT32 (data));
GST_LOG ("%*s name: %*s", depth, "",
QT_UINT8 (buffer + 32), (char *) (buffer + 33));
} /* quicktime uses pascal string, mp4 zero-terminated string */
if (gst_byte_reader_peek_string (data, &name)) {
GST_LOG ("%*s name: %s", depth, "", name);
} else {
gchar buf[256];
guint len;
void len = qt_atom_parser_get_uint8_unchecked (data);
qtdemux_dump_vmhd (GstQTDemux * qtdemux, guint8 * buffer, int depth) if (qt_atom_parser_get_remaining (data) >= len) {
{ memcpy (buf, qt_atom_parser_peek_bytes_unchecked (data), len);
GST_LOG ("%*s version/flags: %08x", depth, "", QT_UINT32 (buffer + 8)); buf[len] = '\0';
GST_LOG ("%*s mode/color: %08x", depth, "", QT_UINT32 (buffer + 16)); GST_LOG ("%*s name: %s", depth, "", buf);
} }
void
qtdemux_dump_dref (GstQTDemux * qtdemux, guint8 * buffer, int depth)
{
int n;
int i;
int offset;
GST_LOG ("%*s version/flags: %08x", depth, "", QT_UINT32 (buffer + 8));
GST_LOG ("%*s n entries: %u", depth, "", QT_UINT32 (buffer + 12));
n = QT_UINT32 (buffer + 12);
offset = 16;
for (i = 0; i < n; i++) {
GST_LOG ("%*s size: %u", depth, "",
QT_UINT32 (buffer + offset));
GST_LOG ("%*s type: %" GST_FOURCC_FORMAT, depth, "",
GST_FOURCC_ARGS (QT_FOURCC (buffer + offset + 4)));
offset += QT_UINT32 (buffer + offset);
} }
return TRUE;
} }
void gboolean
qtdemux_dump_stsd (GstQTDemux * qtdemux, guint8 * buffer, int depth) qtdemux_dump_vmhd (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
int i; if (qt_atom_parser_get_remaining (data) < (4 + 4))
int n; return FALSE;
int offset;
GST_LOG ("%*s version/flags: %08x", depth, "", QT_UINT32 (buffer + 8)); GST_LOG ("%*s version/flags: %08x", depth, "", GET_UINT32 (data));
GST_LOG ("%*s n entries: %d", depth, "", QT_UINT32 (buffer + 12)); GST_LOG ("%*s mode/color: %08x", depth, "", GET_UINT32 (data));
n = QT_UINT32 (buffer + 12); return TRUE;
offset = 16; }
for (i = 0; i < n; i++) {
GST_LOG ("%*s size: %u", depth, "", gboolean
QT_UINT32 (buffer + offset)); qtdemux_dump_dref (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{
guint32 ver_flags, num_entries, i;
if (!qt_atom_parser_get_uint32 (data, &ver_flags) ||
!qt_atom_parser_get_uint32 (data, &num_entries))
return FALSE;
GST_LOG ("%*s version/flags: %08x", depth, "", ver_flags);
GST_LOG ("%*s n entries: %u", depth, "", num_entries);
for (i = 0; i < num_entries; i++) {
guint32 size, fourcc;
if (!qt_atom_parser_get_uint32 (data, &size) ||
!qt_atom_parser_get_fourcc (data, &fourcc) || size < 8 ||
!qt_atom_parser_skip (data, size - 8))
return FALSE;
GST_LOG ("%*s size: %u", depth, "", size);
GST_LOG ("%*s type: %" GST_FOURCC_FORMAT, depth, "", GST_LOG ("%*s type: %" GST_FOURCC_FORMAT, depth, "",
GST_FOURCC_ARGS (QT_FOURCC (buffer + offset + 4))); GST_FOURCC_ARGS (fourcc));
GST_LOG ("%*s data reference:%d", depth, "", }
QT_UINT16 (buffer + offset + 14)); return TRUE;
}
GST_LOG ("%*s version/rev.: %08x", depth, "", gboolean
QT_UINT32 (buffer + offset + 16)); qtdemux_dump_stsd (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{
guint32 ver_flags, num_entries, i;
if (!qt_atom_parser_get_uint32 (data, &ver_flags) ||
!qt_atom_parser_get_uint32 (data, &num_entries))
return FALSE;
GST_LOG ("%*s version/flags: %08x", depth, "", ver_flags);
GST_LOG ("%*s n entries: %d", depth, "", num_entries);
for (i = 0; i < num_entries; i++) {
QtAtomParser sub;
guint32 size, fourcc;
if (!qt_atom_parser_get_uint32 (data, &size) ||
!qt_atom_parser_get_fourcc (data, &fourcc))
return FALSE;
GST_LOG ("%*s size: %u", depth, "", size);
GST_LOG ("%*s type: %" GST_FOURCC_FORMAT, depth, "",
GST_FOURCC_ARGS (fourcc));
if (size < (6 + 2 + 4 + 4 + 4 + 4 + 2 + 2 + 4 + 4 + 4 + 2 + 1 + 31 + 2 + 2))
return FALSE;
qt_atom_parser_peek_sub (data, 0, 78, &sub);
qt_atom_parser_skip (&sub, 6);
GST_LOG ("%*s data reference:%d", depth, "", GET_UINT16 (&sub));
GST_LOG ("%*s version/rev.: %08x", depth, "", GET_UINT32 (&sub));
fourcc = GET_FOURCC (&sub);
GST_LOG ("%*s vendor: %" GST_FOURCC_FORMAT, depth, "", GST_LOG ("%*s vendor: %" GST_FOURCC_FORMAT, depth, "",
GST_FOURCC_ARGS (QT_FOURCC (buffer + offset + 20))); GST_FOURCC_ARGS (fourcc));
GST_LOG ("%*s temporal qual: %u", depth, "", GST_LOG ("%*s temporal qual: %u", depth, "", GET_UINT32 (&sub));
QT_UINT32 (buffer + offset + 24)); GST_LOG ("%*s spatial qual: %u", depth, "", GET_UINT32 (&sub));
GST_LOG ("%*s spatial qual: %u", depth, "", GST_LOG ("%*s width: %u", depth, "", GET_UINT16 (&sub));
QT_UINT32 (buffer + offset + 28)); GST_LOG ("%*s height: %u", depth, "", GET_UINT16 (&sub));
GST_LOG ("%*s width: %u", depth, "", GST_LOG ("%*s horiz. resol: %g", depth, "", GET_FP32 (&sub));
QT_UINT16 (buffer + offset + 32)); GST_LOG ("%*s vert. resol.: %g", depth, "", GET_FP32 (&sub));
GST_LOG ("%*s height: %u", depth, "", GST_LOG ("%*s data size: %u", depth, "", GET_UINT32 (&sub));
QT_UINT16 (buffer + offset + 34)); GST_LOG ("%*s frame count: %u", depth, "", GET_UINT16 (&sub));
GST_LOG ("%*s horiz. resol: %g", depth, "", /* something is not right with this, it's supposed to be a string but it's
QT_FP32 (buffer + offset + 36)); * not apparently, so just skip this for now */
GST_LOG ("%*s vert. resol.: %g", depth, "", qt_atom_parser_skip (&sub, 1 + 31);
QT_FP32 (buffer + offset + 40)); GST_LOG ("%*s compressor: (skipped)", depth, "");
GST_LOG ("%*s data size: %u", depth, "", GST_LOG ("%*s depth: %u", depth, "", GET_UINT16 (&sub));
QT_UINT32 (buffer + offset + 44)); GST_LOG ("%*s color table ID:%u", depth, "", GET_UINT16 (&sub));
GST_LOG ("%*s frame count: %u", depth, "", if (!qt_atom_parser_skip (data, size - (4 + 4)))
QT_UINT16 (buffer + offset + 48)); return FALSE;
GST_LOG ("%*s compressor: %d %d %d", depth, "",
QT_UINT8 (buffer + offset + 49),
QT_UINT8 (buffer + offset + 50), QT_UINT8 (buffer + offset + 51));
//(char *) (buffer + offset + 51));
GST_LOG ("%*s depth: %u", depth, "",
QT_UINT16 (buffer + offset + 82));
GST_LOG ("%*s color table ID:%u", depth, "",
QT_UINT16 (buffer + offset + 84));
offset += QT_UINT32 (buffer + offset);
} }
return TRUE;
} }
void gboolean
qtdemux_dump_stts (GstQTDemux * qtdemux, guint8 * buffer, int depth) qtdemux_dump_stts (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
int i; guint32 ver_flags, num_entries, i;
int n;
int offset;
GST_LOG ("%*s version/flags: %08x", depth, "", QT_UINT32 (buffer + 8)); if (!qt_atom_parser_get_uint32 (data, &ver_flags) ||
GST_LOG ("%*s n entries: %d", depth, "", QT_UINT32 (buffer + 12)); !qt_atom_parser_get_uint32 (data, &num_entries))
n = QT_UINT32 (buffer + 12); return FALSE;
offset = 16;
for (i = 0; i < n; i++) {
GST_LOG ("%*s count: %u", depth, "",
QT_UINT32 (buffer + offset));
GST_LOG ("%*s duration: %u", depth, "",
QT_UINT32 (buffer + offset + 4));
offset += 8; GST_LOG ("%*s version/flags: %08x", depth, "", ver_flags);
GST_LOG ("%*s n entries: %d", depth, "", num_entries);
if (qt_atom_parser_get_remaining (data) < (num_entries * (4 + 4)))
return FALSE;
for (i = 0; i < num_entries; i++) {
GST_LOG ("%*s count: %u", depth, "", GET_UINT32 (data));
GST_LOG ("%*s duration: %u", depth, "",GET_UINT32 (data));
} }
return TRUE;
} }
void gboolean
qtdemux_dump_stps (GstQTDemux * qtdemux, guint8 * buffer, int depth) qtdemux_dump_stps (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
int i; guint32 ver_flags, num_entries, i;
int n;
int offset;
GST_LOG ("%*s version/flags: %08x", depth, "", QT_UINT32 (buffer + 8)); if (!qt_atom_parser_get_uint32 (data, &ver_flags) ||
GST_LOG ("%*s n entries: %d", depth, "", QT_UINT32 (buffer + 12)); !qt_atom_parser_get_uint32 (data, &num_entries))
n = QT_UINT32 (buffer + 12); return FALSE;
offset = 16;
for (i = 0; i < n; i++) {
GST_LOG ("%*s sample: %u", depth, "",
QT_UINT32 (buffer + offset));
offset += 4; GST_LOG ("%*s version/flags: %08x", depth, "", ver_flags);
GST_LOG ("%*s n entries: %d", depth, "", num_entries);
if (qt_atom_parser_get_remaining (data) < (num_entries * 4))
return FALSE;
for (i = 0; i < num_entries; i++) {
GST_LOG ("%*s sample: %u", depth, "", GET_UINT32 (data));
} }
return TRUE;
} }
void gboolean
qtdemux_dump_stss (GstQTDemux * qtdemux, guint8 * buffer, int depth) qtdemux_dump_stss (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
int i; guint32 ver_flags, num_entries, i;
int n;
int offset;
GST_LOG ("%*s version/flags: %08x", depth, "", QT_UINT32 (buffer + 8)); if (!qt_atom_parser_get_uint32 (data, &ver_flags) ||
GST_LOG ("%*s n entries: %d", depth, "", QT_UINT32 (buffer + 12)); !qt_atom_parser_get_uint32 (data, &num_entries))
n = QT_UINT32 (buffer + 12); return FALSE;
offset = 16;
for (i = 0; i < n; i++) {
GST_LOG ("%*s sample: %u", depth, "",
QT_UINT32 (buffer + offset));
offset += 4; GST_LOG ("%*s version/flags: %08x", depth, "", ver_flags);
GST_LOG ("%*s n entries: %d", depth, "", num_entries);
if (qt_atom_parser_get_remaining (data) < (num_entries * 4))
return FALSE;
for (i = 0; i < num_entries; i++) {
GST_LOG ("%*s sample: %u", depth, "", GET_UINT32 (data));
} }
return TRUE;
} }
void gboolean
qtdemux_dump_stsc (GstQTDemux * qtdemux, guint8 * buffer, int depth) qtdemux_dump_stsc (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
int i; guint32 ver_flags, num_entries, i;
int n;
int offset;
GST_LOG ("%*s version/flags: %08x", depth, "", QT_UINT32 (buffer + 8)); if (!qt_atom_parser_get_uint32 (data, &ver_flags) ||
GST_LOG ("%*s n entries: %d", depth, "", QT_UINT32 (buffer + 12)); !qt_atom_parser_get_uint32 (data, &num_entries))
n = QT_UINT32 (buffer + 12); return FALSE;
offset = 16;
for (i = 0; i < n; i++) {
GST_LOG ("%*s first chunk: %u", depth, "",
QT_UINT32 (buffer + offset));
GST_LOG ("%*s sample per ch: %u", depth, "",
QT_UINT32 (buffer + offset + 4));
GST_LOG ("%*s sample desc id:%08x", depth, "",
QT_UINT32 (buffer + offset + 8));
offset += 12; GST_LOG ("%*s version/flags: %08x", depth, "", ver_flags);
GST_LOG ("%*s n entries: %d", depth, "", num_entries);
if (qt_atom_parser_get_remaining (data) < (num_entries * (4 + 4 + 4)))
return FALSE;
for (i = 0; i < num_entries; i++) {
GST_LOG ("%*s first chunk: %u", depth, "", GET_UINT32 (data));
GST_LOG ("%*s sample per ch: %u", depth, "", GET_UINT32 (data));
GST_LOG ("%*s sample desc id:%08x", depth, "", GET_UINT32 (data));
} }
return TRUE;
} }
void gboolean
qtdemux_dump_stsz (GstQTDemux * qtdemux, guint8 * buffer, int depth) qtdemux_dump_stsz (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
//int i; guint32 ver_flags, sample_size, num_entries;
int n;
int offset;
int sample_size;
GST_LOG ("%*s version/flags: %08x", depth, "", QT_UINT32 (buffer + 8)); if (!qt_atom_parser_get_uint32 (data, &ver_flags) ||
sample_size = QT_UINT32 (buffer + 12); !qt_atom_parser_get_uint32 (data, &sample_size))
return FALSE;
GST_LOG ("%*s version/flags: %08x", depth, "", ver_flags);
GST_LOG ("%*s sample size: %d", depth, "", sample_size); GST_LOG ("%*s sample size: %d", depth, "", sample_size);
if (sample_size == 0) {
GST_LOG ("%*s n entries: %d", depth, "", QT_UINT32 (buffer + 16));
n = QT_UINT32 (buffer + 16);
offset = 20;
#if 0
for (i = 0; i < n; i++) {
GST_LOG ("%*s sample size: %u", depth, "",
QT_UINT32 (buffer + offset));
offset += 4; if (sample_size == 0) {
if (!qt_atom_parser_get_uint32 (data, &num_entries))
return FALSE;
GST_LOG ("%*s n entries: %d", depth, "", num_entries);
#if 0
if (qt_atom_parser_get_remaining (data) < (num_entries * 4)))
goto too_short;
for (i = 0; i < num_entries; i++) {
GST_LOG ("%*s sample size: %u", depth, "", GET_UINT32 (data));
} }
#endif #endif
} }
return TRUE;
} }
void gboolean
qtdemux_dump_stco (GstQTDemux * qtdemux, guint8 * buffer, int depth) qtdemux_dump_stco (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
int i; guint32 ver_flags, num_entries, i;
int n;
int offset;
GST_LOG ("%*s version/flags: %08x", depth, "", QT_UINT32 (buffer + 8)); if (!qt_atom_parser_get_uint32 (data, &ver_flags) ||
n = QT_UINT32 (buffer + 12); !qt_atom_parser_get_uint32 (data, &num_entries))
GST_LOG ("%*s n entries: %d", depth, "", n); return FALSE;
offset = 16;
for (i = 0; i < n; i++) {
GST_LOG ("%*s chunk offset: %d", depth, "",
QT_UINT32 (buffer + offset));
offset += 4; GST_LOG ("%*s version/flags: %08x", depth, "", ver_flags);
GST_LOG ("%*s n entries: %d", depth, "", num_entries);
if (qt_atom_parser_get_remaining (data) < (num_entries * 4))
return FALSE;
for (i = 0; i < num_entries; i++) {
GST_LOG ("%*s chunk offset: %u", depth, "", GET_UINT32 (data));
} }
return TRUE;
} }
void gboolean
qtdemux_dump_ctts (GstQTDemux * qtdemux, guint8 * buffer, int depth) qtdemux_dump_ctts (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
int i; guint32 ver_flags, num_entries, i, count, offset;
int n;
int offset;
GST_LOG ("%*s version/flags: %08x", depth, "", QT_UINT32 (buffer + 8)); if (!qt_atom_parser_get_uint32 (data, &ver_flags) ||
n = QT_UINT32 (buffer + 12); !qt_atom_parser_get_uint32 (data, &num_entries))
GST_LOG ("%*s n entries: %d", depth, "", n); return FALSE;
offset = 16;
for (i = 0; i < n; i++) {
GST_LOG ("%*s sample count :%8d offset: %8d",
depth, "", QT_UINT32 (buffer + offset),
QT_UINT32 (buffer + offset + 4));
offset += 8; GST_LOG ("%*s version/flags: %08x", depth, "", ver_flags);
GST_LOG ("%*s n entries: %d", depth, "", num_entries);
if (qt_atom_parser_get_remaining (data) < (num_entries * (4 + 4)))
return FALSE;
for (i = 0; i < num_entries; i++) {
count = GET_UINT32 (data);
offset = GET_UINT32 (data);
GST_LOG ("%*s sample count :%8d offset: %8d", depth, "", count, offset);
} }
return TRUE;
} }
void gboolean
qtdemux_dump_co64 (GstQTDemux * qtdemux, guint8 * buffer, int depth) qtdemux_dump_co64 (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
//int i; guint32 ver_flags, num_entries, i;
int n;
int offset;
GST_LOG ("%*s version/flags: %08x", depth, "", QT_UINT32 (buffer + 8)); if (!qt_atom_parser_get_uint32 (data, &ver_flags) ||
GST_LOG ("%*s n entries: %d", depth, "", QT_UINT32 (buffer + 12)); !qt_atom_parser_get_uint32 (data, &num_entries))
n = QT_UINT32 (buffer + 12); return FALSE;
offset = 16;
#if 0 GST_LOG ("%*s version/flags: %08x", depth, "", ver_flags);
for (i = 0; i < n; i++) { GST_LOG ("%*s n entries: %d", depth, "", num_entries);
if (qt_atom_parser_get_remaining (data) < (num_entries * 8))
return FALSE;
for (i = 0; i < num_entries; i++) {
GST_LOG ("%*s chunk offset: %" G_GUINT64_FORMAT, depth, "", GST_LOG ("%*s chunk offset: %" G_GUINT64_FORMAT, depth, "",
QTDEMUX_GUINT64_GET (buffer + offset)); GET_UINT64 (data));
offset += 8;
} }
#endif return TRUE;
} }
void gboolean
qtdemux_dump_dcom (GstQTDemux * qtdemux, guint8 * buffer, int depth) qtdemux_dump_dcom (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
if (qt_atom_parser_get_remaining (data) < 4)
return FALSE;
GST_LOG ("%*s compression type: %" GST_FOURCC_FORMAT, depth, "", GST_LOG ("%*s compression type: %" GST_FOURCC_FORMAT, depth, "",
GST_FOURCC_ARGS (QT_FOURCC (buffer + 8))); GST_FOURCC_ARGS (GET_FOURCC (data)));
return TRUE;
} }
void gboolean
qtdemux_dump_cmvd (GstQTDemux * qtdemux, guint8 * buffer, int depth) qtdemux_dump_cmvd (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
GST_LOG ("%*s length: %d", depth, "", QT_UINT32 (buffer + 8)); if (qt_atom_parser_get_remaining (data) < 4)
return FALSE;
GST_LOG ("%*s length: %d", depth, "", GET_UINT32 (data));
return TRUE;
} }
void gboolean
qtdemux_dump_unknown (GstQTDemux * qtdemux, guint8 * buffer, int depth) qtdemux_dump_unknown (GstQTDemux * qtdemux, QtAtomParser * data, int depth)
{ {
int len; int len;
GST_LOG ("%*s length: %d", depth, "", QT_UINT32 (buffer + 0)); len = qt_atom_parser_get_remaining (data);
GST_LOG ("%*s length: %d", depth, "", len);
len = QT_UINT32 (buffer + 0); GST_MEMDUMP_OBJECT (qtdemux, "unknown atom data",
GST_MEMDUMP_OBJECT (qtdemux, "unknown atom data", buffer, len); qt_atom_parser_peek_bytes_unchecked (data), len);
return TRUE;
} }
static gboolean static gboolean
qtdemux_node_dump_foreach (GNode * node, gpointer qtdemux) qtdemux_node_dump_foreach (GNode * node, gpointer qtdemux)
{ {
QtAtomParser parser;
guint8 *buffer = (guint8 *) node->data; guint8 *buffer = (guint8 *) node->data;
guint32 node_length; guint32 node_length;
guint32 fourcc; guint32 fourcc;
@ -409,24 +517,37 @@ qtdemux_node_dump_foreach (GNode * node, gpointer qtdemux)
node_length = GST_READ_UINT32_BE (buffer); node_length = GST_READ_UINT32_BE (buffer);
fourcc = GST_READ_UINT32_LE (buffer + 4); fourcc = GST_READ_UINT32_LE (buffer + 4);
g_warn_if_fail (node_length >= 8);
qt_atom_parser_init (&parser, buffer + 8, node_length - 8);
type = qtdemux_type_get (fourcc); type = qtdemux_type_get (fourcc);
depth = (g_node_depth (node) - 1) * 2; depth = (g_node_depth (node) - 1) * 2;
GST_LOG ("%*s'%" GST_FOURCC_FORMAT "', [%d], %s", GST_LOG ("%*s'%" GST_FOURCC_FORMAT "', [%d], %s",
depth, "", GST_FOURCC_ARGS (fourcc), node_length, type->name); depth, "", GST_FOURCC_ARGS (fourcc), node_length, type->name);
if (type->dump) if (type->dump) {
type->dump (GST_QTDEMUX_CAST (qtdemux), buffer, depth); gboolean ret;
ret = type->dump (GST_QTDEMUX_CAST (qtdemux), &parser, depth);
if (!ret) {
GST_WARNING ("%*s not enough data parsing atom %" GST_FOURCC_FORMAT,
depth, "", GST_FOURCC_ARGS (fourcc));
}
}
return FALSE; return FALSE;
} }
void gboolean
qtdemux_node_dump (GstQTDemux * qtdemux, GNode * node) qtdemux_node_dump (GstQTDemux * qtdemux, GNode * node)
{ {
if (__gst_debug_min < GST_LEVEL_LOG) if (__gst_debug_min < GST_LEVEL_LOG)
return; return TRUE;
g_node_traverse (qtdemux->moov_node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, g_node_traverse (qtdemux->moov_node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
qtdemux_node_dump_foreach, qtdemux); qtdemux_node_dump_foreach, qtdemux);
return TRUE;
} }

View file

@ -25,27 +25,27 @@
G_BEGIN_DECLS G_BEGIN_DECLS
void qtdemux_dump_mvhd (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_mvhd (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_tkhd (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_tkhd (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_elst (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_elst (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_mdhd (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_mdhd (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_hdlr (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_hdlr (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_vmhd (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_vmhd (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_dref (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_dref (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_stsd (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_stsd (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_stts (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_stts (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_stss (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_stss (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_stps (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_stps (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_stsc (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_stsc (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_stsz (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_stsz (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_stco (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_stco (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_co64 (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_co64 (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_dcom (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_dcom (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_cmvd (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_cmvd (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_ctts (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_ctts (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_dump_unknown (GstQTDemux * qtdemux, guint8 * buffer, int depth); gboolean qtdemux_dump_unknown (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
void qtdemux_node_dump (GstQTDemux * qtdemux, GNode * node); gboolean qtdemux_node_dump (GstQTDemux * qtdemux, GNode * node);
G_END_DECLS G_END_DECLS

View file

@ -22,11 +22,12 @@
#include <gst/gst.h> #include <gst/gst.h>
#include "qtatomparser.h"
#include "qtdemux.h" #include "qtdemux.h"
G_BEGIN_DECLS G_BEGIN_DECLS
typedef void (*QtDumpFunc) (GstQTDemux * qtdemux, guint8 * buffer, int depth); typedef gboolean (*QtDumpFunc) (GstQTDemux * qtdemux, QtAtomParser * data, int depth);
typedef struct _QtNodeType QtNodeType; typedef struct _QtNodeType QtNodeType;