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: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/634>
This commit is contained in:
Jan Schmidt 2019-05-26 05:05:06 +10:00 committed by GStreamer Merge Bot
parent e2d75939bb
commit 0ddfc5020f
4 changed files with 171 additions and 93 deletions

View file

@ -5,6 +5,7 @@ mp4_sources = [
'qtdemux_types.c',
'qtdemux_dump.c',
'qtdemux_lang.c',
'qtdemux_tree.c',
'gstisoff.c',
'gstqtmux.c',
'gstqtmoovrecover.c',

View file

@ -68,6 +68,7 @@
#include "qtdemux_lang.h"
#include "qtdemux.h"
#include "qtpalette.h"
#include "qtdemux_tree.h"
#include <stdio.h>
#include <stdlib.h>
@ -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)
{

122
gst/isomp4/qtdemux_tree.c Normal file
View file

@ -0,0 +1,122 @@
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) <2003> David A. Schleef <ds@schleef.org>
* Copyright (C) <2006> Wim Taymans <wim@fluendo.com>
* Copyright (C) <2007> Julien Moutte <julien@fluendo.com>
* Copyright (C) <2009> Tim-Philipp Müller <tim centricular net>
* Copyright (C) <2009> STEricsson <benjamin.gaignard@stericsson.com>
* Copyright (C) <2013> Sreerenj Balachandran <sreerenj.balachandran@intel.com>
* 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);
}

47
gst/isomp4/qtdemux_tree.h Normal file
View file

@ -0,0 +1,47 @@
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) <2003> David A. Schleef <ds@schleef.org>
* Copyright (C) <2006> Wim Taymans <wim@fluendo.com>
* Copyright (C) <2007> Julien Moutte <julien@fluendo.com>
* Copyright (C) <2009> Tim-Philipp Müller <tim centricular net>
* Copyright (C) <2009> STEricsson <benjamin.gaignard@stericsson.com>
* Copyright (C) <2013> Sreerenj Balachandran <sreerenj.balachandran@intel.com>
* 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 <gst/gst.h>
#include <gst/base/gstbytereader.h>
#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