qtdemux: micro optimize qtdemux a little

Sprinkle some G_LIKELY around.

Avoid traversing and dumping the tree when debugging is not activated.
This commit is contained in:
Wim Taymans 2009-04-30 18:41:44 +02:00
parent b5d84439fd
commit ab0d1bc942
3 changed files with 20 additions and 15 deletions

View file

@ -318,7 +318,7 @@ gst_qtdemux_get_type (void)
{ {
static GType qtdemux_type = 0; static GType qtdemux_type = 0;
if (!qtdemux_type) { if (G_UNLIKELY (!qtdemux_type)) {
static const GTypeInfo qtdemux_info = { static const GTypeInfo qtdemux_info = {
sizeof (GstQTDemuxClass), sizeof (GstQTDemuxClass),
(GBaseInitFunc) gst_qtdemux_base_init, NULL, (GBaseInitFunc) gst_qtdemux_base_init, NULL,
@ -2891,24 +2891,24 @@ static gboolean
qtdemux_parse_container (GstQTDemux * qtdemux, GNode * node, guint8 * buf, qtdemux_parse_container (GstQTDemux * qtdemux, GNode * node, guint8 * buf,
guint8 * end) guint8 * end)
{ {
while (buf < end) { while (G_UNLIKELY (buf < end)) {
GNode *child; GNode *child;
guint32 len; guint32 len;
if (buf + 4 > end) { if (G_UNLIKELY (buf + 4 > end)) {
GST_LOG_OBJECT (qtdemux, "buffer overrun"); GST_LOG_OBJECT (qtdemux, "buffer overrun");
break; break;
} }
len = QT_UINT32 (buf); len = QT_UINT32 (buf);
if (len == 0) { if (G_UNLIKELY (len == 0)) {
GST_LOG_OBJECT (qtdemux, "empty container"); GST_LOG_OBJECT (qtdemux, "empty container");
break; break;
} }
if (len < 8) { if (G_UNLIKELY (len < 8)) {
GST_WARNING_OBJECT (qtdemux, "length too short (%d < 8)", len); GST_WARNING_OBJECT (qtdemux, "length too short (%d < 8)", len);
break; break;
} }
if (len > (end - buf)) { if (G_UNLIKELY (len > (end - buf))) {
GST_WARNING_OBJECT (qtdemux, "length too long (%d > %d)", len, end - buf); GST_WARNING_OBJECT (qtdemux, "length too long (%d > %d)", len, end - buf);
break; break;
} }
@ -2997,12 +2997,12 @@ qtdemux_parse_node (GstQTDemux * qtdemux, GNode * node, guint8 * buffer,
node_length = QT_UINT32 (buffer); node_length = QT_UINT32 (buffer);
fourcc = QT_FOURCC (buffer + 4); fourcc = QT_FOURCC (buffer + 4);
type = qtdemux_type_get (fourcc);
/* ignore empty nodes */ /* ignore empty nodes */
if (fourcc == 0 || node_length == 8) if (G_UNLIKELY (fourcc == 0 || node_length == 8))
return TRUE; return TRUE;
type = qtdemux_type_get (fourcc);
end = buffer + length; end = buffer + length;
GST_LOG_OBJECT (qtdemux, GST_LOG_OBJECT (qtdemux,
@ -3143,7 +3143,7 @@ qtdemux_tree_get_child_by_type (GNode * node, guint32 fourcc)
child_fourcc = QT_FOURCC (buffer + 4); child_fourcc = QT_FOURCC (buffer + 4);
if (child_fourcc == fourcc) { if (G_UNLIKELY (child_fourcc == fourcc)) {
return child; return child;
} }
} }
@ -3379,10 +3379,6 @@ qtdemux_parse_samples (GstQTDemux * qtdemux, QtDemuxStream * stream,
if (!(stts = qtdemux_tree_get_child_by_type (stbl, FOURCC_stts))) if (!(stts = qtdemux_tree_get_child_by_type (stbl, FOURCC_stts)))
goto corrupt_file; goto corrupt_file;
/* sample sync, can be NULL */
stss = qtdemux_tree_get_child_by_type (stbl, FOURCC_stss);
stps = qtdemux_tree_get_child_by_type (stbl, FOURCC_stps);
sample_size = QT_UINT32 (stsz_data + 12); sample_size = QT_UINT32 (stsz_data + 12);
if (sample_size == 0 || stream->sampled) { if (sample_size == 0 || stream->sampled) {
n_samples = QT_UINT32 (stsz_data + 16); n_samples = QT_UINT32 (stsz_data + 16);
@ -3465,6 +3461,10 @@ qtdemux_parse_samples (GstQTDemux * qtdemux, QtDemuxStream * stream,
index++; index++;
} }
} }
/* sample sync, can be NULL */
stss = qtdemux_tree_get_child_by_type (stbl, FOURCC_stss);
if (stss) { if (stss) {
/* mark keyframes */ /* mark keyframes */
guint32 n_sample_syncs; guint32 n_sample_syncs;
@ -3483,6 +3483,7 @@ qtdemux_parse_samples (GstQTDemux * qtdemux, QtDemuxStream * stream,
} }
} }
} }
stps = qtdemux_tree_get_child_by_type (stbl, FOURCC_stps);
if (stps) { if (stps) {
/* mark keyframes */ /* mark keyframes */
guint32 n_sample_syncs; guint32 n_sample_syncs;

View file

@ -431,6 +431,9 @@ qtdemux_node_dump_foreach (GNode * node, gpointer qtdemux)
void void
qtdemux_node_dump (GstQTDemux * qtdemux, GNode * node) qtdemux_node_dump (GstQTDemux * qtdemux, GNode * node)
{ {
if (__gst_debug_min < GST_LEVEL_LOG)
return;
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);
} }

View file

@ -146,11 +146,12 @@ qtdemux_type_get (guint32 fourcc)
int i; int i;
for (i = 0; i < n_qt_node_types; i++) { for (i = 0; i < n_qt_node_types; i++) {
if (qt_node_types[i].fourcc == fourcc) if (G_UNLIKELY (qt_node_types[i].fourcc == fourcc))
return qt_node_types + i; return qt_node_types + i;
} }
GST_WARNING ("unknown QuickTime node type %" GST_FOURCC_FORMAT, GST_WARNING ("unknown QuickTime node type %" GST_FOURCC_FORMAT,
GST_FOURCC_ARGS (fourcc)); GST_FOURCC_ARGS (fourcc));
return qt_node_types + n_qt_node_types - 1; return qt_node_types + n_qt_node_types - 1;
} }