From 0ddfc5020f8f967cbb3daf9dc73cf96e29381de6 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Sun, 26 May 2019 05:05:06 +1000 Subject: [PATCH] qtdemux: Move some tree parsing files out to a separate file. Reduce a tiny bit of the bulk of qtdemux.c by moving some agnostic helper functions out. Part-of: --- gst/isomp4/meson.build | 1 + gst/isomp4/qtdemux.c | 94 +---------------------------------- gst/isomp4/qtdemux_tree.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++ gst/isomp4/qtdemux_tree.h | 47 ++++++++++++++++++ 4 files changed, 171 insertions(+), 93 deletions(-) create mode 100644 gst/isomp4/qtdemux_tree.c create mode 100644 gst/isomp4/qtdemux_tree.h diff --git a/gst/isomp4/meson.build b/gst/isomp4/meson.build index 656eed3..d5b8afc 100644 --- a/gst/isomp4/meson.build +++ b/gst/isomp4/meson.build @@ -5,6 +5,7 @@ mp4_sources = [ 'qtdemux_types.c', 'qtdemux_dump.c', 'qtdemux_lang.c', + 'qtdemux_tree.c', 'gstisoff.c', 'gstqtmux.c', 'gstqtmoovrecover.c', diff --git a/gst/isomp4/qtdemux.c b/gst/isomp4/qtdemux.c index 423eb3b..77c6320 100644 --- a/gst/isomp4/qtdemux.c +++ b/gst/isomp4/qtdemux.c @@ -68,6 +68,7 @@ #include "qtdemux_lang.h" #include "qtdemux.h" #include "qtpalette.h" +#include "qtdemux_tree.h" #include #include @@ -488,13 +489,6 @@ qt_demux_state_string (enum QtDemuxState state) } } -static GNode *qtdemux_tree_get_child_by_type (GNode * node, guint32 fourcc); -static GNode *qtdemux_tree_get_child_by_type_full (GNode * node, - guint32 fourcc, GstByteReader * parser); -static GNode *qtdemux_tree_get_sibling_by_type (GNode * node, guint32 fourcc); -static GNode *qtdemux_tree_get_sibling_by_type_full (GNode * node, - guint32 fourcc, GstByteReader * parser); - static GstFlowReturn qtdemux_add_fragmented_samples (GstQTDemux * qtdemux); static void gst_qtdemux_check_send_pending_segment (GstQTDemux * demux); @@ -8340,92 +8334,6 @@ broken_atom_size: } } -static GNode * -qtdemux_tree_get_child_by_type (GNode * node, guint32 fourcc) -{ - GNode *child; - guint8 *buffer; - guint32 child_fourcc; - - for (child = g_node_first_child (node); child; - child = g_node_next_sibling (child)) { - buffer = (guint8 *) child->data; - - child_fourcc = QT_FOURCC (buffer + 4); - - if (G_UNLIKELY (child_fourcc == fourcc)) { - return child; - } - } - return NULL; -} - -static GNode * -qtdemux_tree_get_child_by_type_full (GNode * node, guint32 fourcc, - GstByteReader * parser) -{ - GNode *child; - guint8 *buffer; - guint32 child_fourcc, child_len; - - for (child = g_node_first_child (node); child; - child = g_node_next_sibling (child)) { - buffer = (guint8 *) child->data; - - child_len = QT_UINT32 (buffer); - child_fourcc = QT_FOURCC (buffer + 4); - - if (G_UNLIKELY (child_fourcc == fourcc)) { - if (G_UNLIKELY (child_len < (4 + 4))) - return NULL; - /* FIXME: must verify if atom length < parent atom length */ - gst_byte_reader_init (parser, buffer + (4 + 4), child_len - (4 + 4)); - return child; - } - } - return NULL; -} - -static GNode * -qtdemux_tree_get_child_by_index (GNode * node, guint index) -{ - return g_node_nth_child (node, index); -} - -static GNode * -qtdemux_tree_get_sibling_by_type_full (GNode * node, guint32 fourcc, - GstByteReader * parser) -{ - GNode *child; - guint8 *buffer; - guint32 child_fourcc, child_len; - - for (child = g_node_next_sibling (node); child; - child = g_node_next_sibling (child)) { - buffer = (guint8 *) child->data; - - child_fourcc = QT_FOURCC (buffer + 4); - - if (child_fourcc == fourcc) { - if (parser) { - child_len = QT_UINT32 (buffer); - if (G_UNLIKELY (child_len < (4 + 4))) - return NULL; - /* FIXME: must verify if atom length < parent atom length */ - gst_byte_reader_init (parser, buffer + (4 + 4), child_len - (4 + 4)); - } - return child; - } - } - return NULL; -} - -static GNode * -qtdemux_tree_get_sibling_by_type (GNode * node, guint32 fourcc) -{ - return qtdemux_tree_get_sibling_by_type_full (node, fourcc, NULL); -} - static void qtdemux_do_allocation (QtDemuxStream * stream, GstQTDemux * qtdemux) { diff --git a/gst/isomp4/qtdemux_tree.c b/gst/isomp4/qtdemux_tree.c new file mode 100644 index 0000000..e27dc45 --- /dev/null +++ b/gst/isomp4/qtdemux_tree.c @@ -0,0 +1,122 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) <2003> David A. Schleef + * Copyright (C) <2006> Wim Taymans + * Copyright (C) <2007> Julien Moutte + * Copyright (C) <2009> Tim-Philipp Müller + * Copyright (C) <2009> STEricsson + * Copyright (C) <2013> Sreerenj Balachandran + * Copyright (C) <2013> Intel Corporation + * Copyright (C) <2014> Centricular Ltd + * Copyright (C) <2015> YouView TV Ltd. + * Copyright (C) <2016> British Broadcasting Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "qtdemux_tree.h" +#include "qtdemux_types.h" +#include "fourcc.h" + +GNode * +qtdemux_tree_get_child_by_type (GNode * node, guint32 fourcc) +{ + GNode *child; + guint8 *buffer; + guint32 child_fourcc; + + for (child = g_node_first_child (node); child; + child = g_node_next_sibling (child)) { + buffer = (guint8 *) child->data; + + child_fourcc = QT_FOURCC (buffer + 4); + + if (G_UNLIKELY (child_fourcc == fourcc)) { + return child; + } + } + return NULL; +} + +GNode * +qtdemux_tree_get_child_by_type_full (GNode * node, guint32 fourcc, + GstByteReader * parser) +{ + GNode *child; + guint8 *buffer; + guint32 child_fourcc, child_len; + + for (child = g_node_first_child (node); child; + child = g_node_next_sibling (child)) { + buffer = (guint8 *) child->data; + + child_len = QT_UINT32 (buffer); + child_fourcc = QT_FOURCC (buffer + 4); + + if (G_UNLIKELY (child_fourcc == fourcc)) { + if (G_UNLIKELY (child_len < (4 + 4))) + return NULL; + /* FIXME: must verify if atom length < parent atom length */ + gst_byte_reader_init (parser, buffer + (4 + 4), child_len - (4 + 4)); + return child; + } + } + return NULL; +} + +GNode * +qtdemux_tree_get_child_by_index (GNode * node, guint index) +{ + return g_node_nth_child (node, index); +} + +GNode * +qtdemux_tree_get_sibling_by_type_full (GNode * node, guint32 fourcc, + GstByteReader * parser) +{ + GNode *child; + guint8 *buffer; + guint32 child_fourcc, child_len; + + for (child = g_node_next_sibling (node); child; + child = g_node_next_sibling (child)) { + buffer = (guint8 *) child->data; + + child_fourcc = QT_FOURCC (buffer + 4); + + if (child_fourcc == fourcc) { + if (parser) { + child_len = QT_UINT32 (buffer); + if (G_UNLIKELY (child_len < (4 + 4))) + return NULL; + /* FIXME: must verify if atom length < parent atom length */ + gst_byte_reader_init (parser, buffer + (4 + 4), child_len - (4 + 4)); + } + return child; + } + } + return NULL; +} + +GNode * +qtdemux_tree_get_sibling_by_type (GNode * node, guint32 fourcc) +{ + return qtdemux_tree_get_sibling_by_type_full (node, fourcc, NULL); +} diff --git a/gst/isomp4/qtdemux_tree.h b/gst/isomp4/qtdemux_tree.h new file mode 100644 index 0000000..1438181 --- /dev/null +++ b/gst/isomp4/qtdemux_tree.h @@ -0,0 +1,47 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) <2003> David A. Schleef + * Copyright (C) <2006> Wim Taymans + * Copyright (C) <2007> Julien Moutte + * Copyright (C) <2009> Tim-Philipp Müller + * Copyright (C) <2009> STEricsson + * Copyright (C) <2013> Sreerenj Balachandran + * Copyright (C) <2013> Intel Corporation + * Copyright (C) <2014> Centricular Ltd + * Copyright (C) <2015> YouView TV Ltd. + * Copyright (C) <2016> British Broadcasting Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#include +#include + +#ifndef __QTDEMUX_TREE_H__ +#define __QTDEMUX_TREE_H__ + +G_BEGIN_DECLS + +GNode *qtdemux_tree_get_child_by_type (GNode * node, guint32 fourcc); +GNode *qtdemux_tree_get_child_by_type_full (GNode * node, + guint32 fourcc, GstByteReader * parser); +GNode *qtdemux_tree_get_sibling_by_type (GNode * node, guint32 fourcc); +GNode *qtdemux_tree_get_sibling_by_type_full (GNode * node, + guint32 fourcc, GstByteReader * parser); +GNode *qtdemux_tree_get_child_by_index (GNode * node, guint index); + +G_END_DECLS + +#endif -- 2.7.4