From ab0d1bc942447cb4bd02be606ef6e7629c97c9a7 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 30 Apr 2009 18:41:44 +0200 Subject: [PATCH] qtdemux: micro optimize qtdemux a little Sprinkle some G_LIKELY around. Avoid traversing and dumping the tree when debugging is not activated. --- gst/qtdemux/qtdemux.c | 29 +++++++++++++++-------------- gst/qtdemux/qtdemux_dump.c | 3 +++ gst/qtdemux/qtdemux_types.c | 3 ++- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/gst/qtdemux/qtdemux.c b/gst/qtdemux/qtdemux.c index d18d4dfc83..4be965e47c 100644 --- a/gst/qtdemux/qtdemux.c +++ b/gst/qtdemux/qtdemux.c @@ -318,7 +318,7 @@ gst_qtdemux_get_type (void) { static GType qtdemux_type = 0; - if (!qtdemux_type) { + if (G_UNLIKELY (!qtdemux_type)) { static const GTypeInfo qtdemux_info = { sizeof (GstQTDemuxClass), (GBaseInitFunc) gst_qtdemux_base_init, NULL, @@ -2891,24 +2891,24 @@ static gboolean qtdemux_parse_container (GstQTDemux * qtdemux, GNode * node, guint8 * buf, guint8 * end) { - while (buf < end) { + while (G_UNLIKELY (buf < end)) { GNode *child; guint32 len; - if (buf + 4 > end) { + if (G_UNLIKELY (buf + 4 > end)) { GST_LOG_OBJECT (qtdemux, "buffer overrun"); break; } len = QT_UINT32 (buf); - if (len == 0) { + if (G_UNLIKELY (len == 0)) { GST_LOG_OBJECT (qtdemux, "empty container"); break; } - if (len < 8) { + if (G_UNLIKELY (len < 8)) { GST_WARNING_OBJECT (qtdemux, "length too short (%d < 8)", len); break; } - if (len > (end - buf)) { + if (G_UNLIKELY (len > (end - buf))) { GST_WARNING_OBJECT (qtdemux, "length too long (%d > %d)", len, end - buf); break; } @@ -2997,12 +2997,12 @@ qtdemux_parse_node (GstQTDemux * qtdemux, GNode * node, guint8 * buffer, node_length = QT_UINT32 (buffer); fourcc = QT_FOURCC (buffer + 4); - type = qtdemux_type_get (fourcc); - /* ignore empty nodes */ - if (fourcc == 0 || node_length == 8) + if (G_UNLIKELY (fourcc == 0 || node_length == 8)) return TRUE; + type = qtdemux_type_get (fourcc); + end = buffer + length; GST_LOG_OBJECT (qtdemux, @@ -3143,7 +3143,7 @@ qtdemux_tree_get_child_by_type (GNode * node, guint32 fourcc) child_fourcc = QT_FOURCC (buffer + 4); - if (child_fourcc == fourcc) { + if (G_UNLIKELY (child_fourcc == fourcc)) { return child; } } @@ -3379,10 +3379,6 @@ qtdemux_parse_samples (GstQTDemux * qtdemux, QtDemuxStream * stream, if (!(stts = qtdemux_tree_get_child_by_type (stbl, FOURCC_stts))) 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); if (sample_size == 0 || stream->sampled) { n_samples = QT_UINT32 (stsz_data + 16); @@ -3465,6 +3461,10 @@ qtdemux_parse_samples (GstQTDemux * qtdemux, QtDemuxStream * stream, index++; } } + + /* sample sync, can be NULL */ + stss = qtdemux_tree_get_child_by_type (stbl, FOURCC_stss); + if (stss) { /* mark keyframes */ 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) { /* mark keyframes */ guint32 n_sample_syncs; diff --git a/gst/qtdemux/qtdemux_dump.c b/gst/qtdemux/qtdemux_dump.c index 506a3f7ea5..7871609ca4 100644 --- a/gst/qtdemux/qtdemux_dump.c +++ b/gst/qtdemux/qtdemux_dump.c @@ -431,6 +431,9 @@ qtdemux_node_dump_foreach (GNode * node, gpointer qtdemux) void 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, qtdemux_node_dump_foreach, qtdemux); } diff --git a/gst/qtdemux/qtdemux_types.c b/gst/qtdemux/qtdemux_types.c index d2b7e5a7dd..ef79d1d26b 100644 --- a/gst/qtdemux/qtdemux_types.c +++ b/gst/qtdemux/qtdemux_types.c @@ -146,11 +146,12 @@ qtdemux_type_get (guint32 fourcc) int 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; } GST_WARNING ("unknown QuickTime node type %" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc)); + return qt_node_types + n_qt_node_types - 1; }