Commit 28d191ad authored by John Koleszar's avatar John Koleszar

Import nestegg webm/mkv parser

Initial import of nestegg[1] parser lib, at commit 0d51131.

[1]: http://github.com/kinetiknz/nestegg
     commit 0d51131519a1014660b5e111e28a78785d76600f

Change-Id: I191d388b7e5140ef96624511ccdd65d0e183076d
parent bdf469c9
*.lo
*.o
*.swp
*~
.deps
.dirstamp
.libs
Makefile
Makefile.in
_stdint.h
aclocal.m4
autom4te.cache
compile
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
depcomp
docs/Doxyfile
docs/doxygen-build.stamp
docs/html
install-sh
libtool
ltmain.sh
m4/libtool.m4
m4/ltoptions.m4
m4/ltsugar.m4
m4/ltversion.m4
m4/lt~obsolete.m4
missing
nestegg-uninstalled.pc
nestegg.pc
src/.dirstamp
src/libnestegg.la
stamp-h1
test/test
include/nestegg/nestegg-stdint.h
Matthew Gregan <kinetik@flim.org>
Build instructions for libnestegg
=================================
0. Change directory into the source directory.
1. Run |autoreconf --install| to generate configure.
2. Run |./configure| to configure the build.
3. Run |make| to build.
4. Run |make check| to run the test suite.
Copyright © 2010 Mozilla Foundation
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
AUTOMAKE_OPTIONS = foreign 1.11 no-dist-gzip dist-bzip2 subdir-objects
ACLOCAL_AMFLAGS = -I m4
INCLUDES = -I$(top_srcdir)/include -I. -I$(top_srcdir)/halloc
AM_CFLAGS = -ansi -pedantic -Wall -Wextra -Wno-long-long -O0 -g
SUBDIRS = docs
EXTRA_DIST = \
AUTHORS README LICENSE \
nestegg-uninstalled.pc.in \
m4/as-ac-expand.m4 \
m4/pkg.m4 \
m4/ax_create_stdint_h.m4 \
halloc/src/halloc.c \
halloc/halloc.h \
halloc/src/align.h \
halloc/src/hlist.h \
halloc/src/macros.h
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = nestegg.pc
nesteggincludedir = $(includedir)/nestegg
nestegginclude_HEADERS = include/nestegg/nestegg.h include/nestegg/nestegg-stdint.h
lib_LTLIBRARIES = src/libnestegg.la
src_libnestegg_la_SOURCES = \
src/nestegg.c \
halloc/src/halloc.c \
halloc/halloc.h \
halloc/src/align.h \
halloc/src/hlist.h \
halloc/src/macros.h
check_PROGRAMS = test/test
test_test_SOURCES = test/test.c
test_test_LDADD = src/libnestegg.la
DISTCLEANFILES = include/nestegg/nestegg-stdint.h
dist-hook:
find $(distdir) -type d -name '.git' | xargs rm -rf
debug:
$(MAKE) all CFLAGS="@DEBUG@"
profile:
$(MAKE) all CFLAGS="@PROFILE@"
See INSTALL for build instructions.
Licensed under an ISC-style license. See LICENSE for details.
The source under the halloc/ directory is licensed under a BSD license. See
halloc/halloc.h for details.
- Document when read, seek, tell callbacks are used.
- Add an automated testsuite.
- Test (and fix, if necessary) support for unknown sizes.
- Test (and fix, if necessary) support for large files.
- Read past unknown elements rather than seeking.
- Try to handle unknown elements with unknown sizes.
- Formalize handling of default element values.
- Try to resynchronize stream when read_block fails so that failure to parse
a single block can be treated as non-fatal.
- Make logging more useful to API users.
- Avoid reparsing Cues and ignore any SeekHead at end of file.
- Optionally build a Cue index as Clusters are parsed.
- Support seeking without Cues.
- Avoid building a list of Clusters as they are parsed and retain only the
last one parsed.
- Add an asynchronous error code to struct nestegg and ensure that API calls
continue to fail safely one a fatal error has been returned.
- Modify parser/data structures to provide a clean separation. Perhaps the
parser should return a generic tree of nodes that a second pass uses to
initialize the main data structures.
- Use pool allocator for all allocations.
dnl ------------------------------------------------
dnl Initialization and Versioning
dnl ------------------------------------------------
AC_INIT(libnestegg,[0.1git])
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
AC_CONFIG_MACRO_DIR([m4])
AM_CONFIG_HEADER([config.h])
AC_CONFIG_SRCDIR([src/nestegg.c])
AM_INIT_AUTOMAKE
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
dnl Library versioning
dnl CURRENT, REVISION, AGE
dnl - library source changed -> increment REVISION
dnl - interfaces added/removed/changed -> increment CURRENT, REVISION = 0
dnl - interfaces added -> increment AGE
dnl - interfaces removed -> AGE = 0
NESTEGG_CURRENT=0
NESTEGG_REVISION=0
NESTEGG_AGE=1
AC_SUBST(NESTEGG_CURRENT)
AC_SUBST(NESTEGG_REVISION)
AC_SUBST(NESTEGG_AGE)
dnl --------------------------------------------------
dnl Check for programs
dnl --------------------------------------------------
dnl save $CFLAGS since AC_PROG_CC likes to insert "-g -O2"
dnl if $CFLAGS is blank
cflags_save="$CFLAGS"
AC_PROG_CC
AC_PROG_CPP
CFLAGS="$cflags_save"
AM_PROG_CC_C_O
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL
dnl Check for doxygen
AC_ARG_ENABLE([doc],
AS_HELP_STRING([--enable-doc], [Build API documentation]),
[ac_enable_doc=$enableval], [ac_enable_doc=auto])
if test "x$ac_enable_doc" != "xno"; then
AC_CHECK_PROG(HAVE_DOXYGEN, doxygen, true, false)
if test "x$HAVE_DOXYGEN" = "xfalse" -a "x$ac_enable_doc" = "xyes"; then
AC_MSG_ERROR([*** API documentation explicitly requested but Doxygen not found])
fi
else
HAVE_DOXYGEN=false
fi
AM_CONDITIONAL(HAVE_DOXYGEN,$HAVE_DOXYGEN)
if test $HAVE_DOXYGEN = "false"; then
AC_MSG_WARN([*** doxygen not found, API documentation will not be built])
fi
# Generate portable stdint.h replacement
AX_CREATE_STDINT_H(include/nestegg/nestegg-stdint.h)
# Test whenever ld supports -version-script
AC_PROG_LD
AC_PROG_LD_GNU
AC_MSG_CHECKING([how to control symbol export])
dnl --------------------------------------------------
dnl Do substitutions
dnl --------------------------------------------------
AC_SUBST(DEBUG)
AC_SUBST(PROFILE)
AC_OUTPUT([
Makefile
docs/Makefile
docs/Doxyfile
nestegg.pc
nestegg-uninstalled.pc
])
AS_AC_EXPAND(LIBDIR, ${libdir})
AS_AC_EXPAND(INCLUDEDIR, ${includedir})
AS_AC_EXPAND(BINDIR, ${bindir})
AS_AC_EXPAND(DOCDIR, ${docdir})
if test $HAVE_DOXYGEN = "false"; then
doc_build="no"
else
doc_build="yes"
fi
AC_MSG_RESULT([
------------------------------------------------------------------------
$PACKAGE $VERSION: Automatic configuration OK.
General configuration:
API Documentation: .......... ${doc_build}
Installation paths:
libnestegg: .................. ${LIBDIR}
C header files: .............. ${INCLUDEDIR}/nestegg
Documentation: ............... ${DOCDIR}
Building:
Type 'make' to compile $PACKAGE.
Type 'make install' to install $PACKAGE.
Example programs will be built but not installed.
------------------------------------------------------------------------
])
This diff is collapsed.
doc_DATA = doxygen-build.stamp
EXTRA_DIST = Doxyfile.in
if HAVE_DOXYGEN
doxygen-build.stamp: Doxyfile
doxygen
touch doxygen-build.stamp
else
doxygen-build.stamp:
echo "*** Warning: Doxygen not found; documentation will not be built."
touch doxygen-build.stamp
endif
dist_docdir = $(distdir)/libnestegg
dist-hook:
if test -d html; then \
mkdir $(dist_docdir); \
echo -n "copying built documenation..."; \
cp -rp html $(dist_docdir)/html; \
echo "OK"; \
fi
install-data-local: doxygen-build.stamp
$(mkinstalldirs) $(DESTDIR)$(docdir)
if test -d html; then \
cp -rp html $(DESTDIR)$(docdir)/html; \
fi
uninstall-local:
rm -rf $(DESTDIR)$(docdir)
clean-local:
if test -d html; then rm -rf html; fi
if test -f doxygen-build.stamp; then rm -f doxygen-build.stamp; fi
halloc 1.2.1
============
Hierarchical memory heap interface - an extension to standard
malloc/free interface that simplifies tasks of memory disposal
when allocated structures exhibit hierarchical properties.
http://swapped.cc/halloc
=
To build libhalloc.a with GNU tools run
make
To install in /usr/include and /usr/lib
make install
To cleanup the build files
make clean
=
halloc-1.2.1
* fixed a double-free bug in _set_allocator() as per
Matthew Gregan comments
* switched to using NULL instead of 0 where applicable
halloc-1.2.0
* added missing <string.h> include to halloc.c
* improved standard compliance thanks to the feedback
received from Stan Tobias. Two things were fixed -
- hblock_t structure no longer uses zero-sized 'data'
array, which happened to be common, but non-standard
extension;
- secondly, added the code to test the behaviour of
realloc(ptr, 0). Standard allows it NOT to act as
free(), in which case halloc will use its own version
of allocator calling free() when neccessary.
halloc-1.1.0
* initial public release (rewrite of hhmalloc library)
=============================================================================
Copyright (c) 2004-2010, Alex Pankratov (ap@swapped.cc). All rights reserved.
/*
* Copyright (c) 2004-2010 Alex Pankratov. All rights reserved.
*
* Hierarchical memory allocator, 1.2.1
* http://swapped.cc/halloc
*/
/*
* The program is distributed under terms of BSD license.
* You can obtain the copy of the license by visiting:
*
* http://www.opensource.org/licenses/bsd-license.php
*/
#ifndef _LIBP_HALLOC_H_
#define _LIBP_HALLOC_H_
#include <stddef.h> /* size_t */
/*
* Core API
*/
void * halloc (void * block, size_t len);
void hattach(void * block, void * parent);
/*
* standard malloc/free api
*/
void * h_malloc (size_t len);
void * h_calloc (size_t n, size_t len);
void * h_realloc(void * p, size_t len);
void h_free (void * p);
char * h_strdup (const char * str);
/*
* the underlying allocator
*/
typedef void * (* realloc_t)(void * ptr, size_t len);
extern realloc_t halloc_allocator;
#endif
/*
* Copyright (c) 2004-2010 Alex Pankratov. All rights reserved.
*
* Hierarchical memory allocator, 1.2.1
* http://swapped.cc/halloc
*/
/*
* The program is distributed under terms of BSD license.
* You can obtain the copy of the license by visiting:
*
* http://www.opensource.org/licenses/bsd-license.php
*/
#ifndef _LIBP_ALIGN_H_
#define _LIBP_ALIGN_H_
/*
* a type with the most strict alignment requirements
*/
union max_align
{
char c;
short s;
long l;
int i;
float f;
double d;
void * v;
void (*q)(void);
};
typedef union max_align max_align_t;
#endif
/*
* Copyright (c) 2004i-2010 Alex Pankratov. All rights reserved.
*
* Hierarchical memory allocator, 1.2.1
* http://swapped.cc/halloc
*/
/*
* The program is distributed under terms of BSD license.
* You can obtain the copy of the license by visiting:
*
* http://www.opensource.org/licenses/bsd-license.php
*/
#include <stdlib.h> /* realloc */
#include <string.h> /* memset & co */
#include "halloc.h"
#include "align.h"
#include "hlist.h"
/*
* block control header
*/
typedef struct hblock
{
#ifndef NDEBUG
#define HH_MAGIC 0x20040518L
long magic;
#endif
hlist_item_t siblings; /* 2 pointers */
hlist_head_t children; /* 1 pointer */
max_align_t data[1]; /* not allocated, see below */
} hblock_t;
#define sizeof_hblock offsetof(hblock_t, data)
/*
*
*/
realloc_t halloc_allocator = NULL;
#define allocator halloc_allocator
/*
* static methods
*/
static void _set_allocator(void);
static void * _realloc(void * ptr, size_t n);
static int _relate(hblock_t * b, hblock_t * p);
static void _free_children(hblock_t * p);
/*
* Core API
*/
void * halloc(void * ptr, size_t len)
{
hblock_t * p;
/* set up default allocator */
if (! allocator)
{
_set_allocator();
assert(allocator);
}
/* calloc */
if (! ptr)
{
if (! len)
return NULL;
p = allocator(0, len + sizeof_hblock);
if (! p)
return NULL;
#ifndef NDEBUG
p->magic = HH_MAGIC;
#endif
hlist_init(&p->children);
hlist_init_item(&p->siblings);
return p->data;
}
p = structof(ptr, hblock_t, data);
assert(p->magic == HH_MAGIC);
/* realloc */
if (len)
{
p = allocator(p, len + sizeof_hblock);
if (! p)
return NULL;
hlist_relink(&p->siblings);
hlist_relink_head(&p->children);
return p->data;
}
/* free */
_free_children(p);
hlist_del(&p->siblings);
allocator(p, 0);
return NULL;
}
void hattach(void * block, void * parent)
{
hblock_t * b, * p;
if (! block)
{
assert(! parent);
return;
}
/* detach */
b = structof(block, hblock_t, data);
assert(b->magic == HH_MAGIC);
hlist_del(&b->siblings);
if (! parent)
return;
/* attach */
p = structof(parent, hblock_t, data);
assert(p->magic == HH_MAGIC);
/* sanity checks */
assert(b != p); /* trivial */
assert(! _relate(p, b)); /* heavy ! */
hlist_add(&p->children, &b->siblings);
}
/*
* malloc/free api
*/
void * h_malloc(size_t len)
{
return halloc(0, len);
}
void * h_calloc(size_t n, size_t len)
{
void * ptr = halloc(0, len*=n);
return ptr ? memset(ptr, 0, len) : NULL;
}
void * h_realloc(void * ptr, size_t len)
{
return halloc(ptr, len);
}
void h_free(void * ptr)
{
halloc(ptr, 0);
}
char * h_strdup(const char * str)
{
size_t len = strlen(str);
char * ptr = halloc(0, len + 1);
return ptr ? (ptr[len] = 0, memcpy(ptr, str, len)) : NULL;
}
/*
* static stuff
*/
static void _set_allocator(void)
{
void * p;
assert(! allocator);
/*
* the purpose of the test below is to check the behaviour
* of realloc(ptr, 0), which is defined in the standard
* as an implementation-specific. if it returns zero,
* then it's equivalent to free(). it can however return
* non-zero, in which case it cannot be used for freeing
* memory blocks and we'll need to supply our own version
*
* Thanks to Stan Tobias for pointing this tricky part out.
*/
allocator = realloc;
if (! (p = malloc(1)))
/* hmm */
return;
if ((p = realloc(p, 0)))
{
/* realloc cannot be used as free() */
allocator = _realloc;
free(p);
}
}
static void * _realloc(void * ptr, size_t n)
{
/*
* free'ing realloc()
*/
if (n)
return realloc(ptr, n);
free(ptr);
return NULL;
}
static int _relate(hblock_t * b, hblock_t * p)
{
hlist_item_t * i;
if (!b || !p)
return 0;
/*
* since there is no 'parent' pointer, which would've allowed
* O(log(n)) upward traversal, the check must use O(n) downward
* iteration of the entire hierarchy; and this can be VERY SLOW
*/
hlist_for_each(i, &p->children)
{
hblock_t * q = structof(i, hblock_t, siblings);
if (q == b || _relate(b, q))
return 1;
}
return 0;
}
static void _free_children(hblock_t * p)
{
hlist_item_t * i, * tmp;
#ifndef NDEBUG
/*
* this catches loops in hierarchy with almost zero
* overhead (compared to _relate() running time)
*/
assert(p && p->magic == HH_MAGIC);
p->magic = 0;
#endif
hlist_for_each_safe(i, tmp, &p->children)
{
hblock_t * q = structof(i, hblock_t, siblings);
_free_children(q);
allocator(q, 0);
}
}
/*
* Copyright (c) 2004-2010 Alex Pankratov. All rights reserved.
*
* Hierarchical memory allocator, 1.2.1
* http://swapped.cc/halloc
*/
/*
* The program is distributed under terms of BSD license.
* You can obtain the copy of the license by visiting:
*
* http://www.opensource.org/licenses/bsd-license.php
*/
#ifndef _LIBP_HLIST_H_
#define _LIBP_HLIST_H_
#include <assert.h>
#include "macros.h" /* static_inline */
/*
* weak double-linked list w/ tail sentinel
*/
typedef struct hlist_head hlist_head_t;
typedef struct hlist_item hlist_item_t;
/*
*
*/
struct hlist_head
{
hlist_item_t * next;
};
struct hlist_item
{
hlist_item_t * next;
hlist_item_t ** prev;
};
/*
* shared tail sentinel
*/
struct hlist_item hlist_null;
/*
*
*/
#define __hlist_init(h) { &hlist_null }
#define __hlist_init_item(i) { &hlist_null, &(i).next }
static_inline void hlist_init(hlist_head_t * h);
static_inline void hlist_init_item(hlist_item_t * i);
/* static_inline void hlist_purge(hlist_head_t * h); */
/* static_inline bool_t hlist_empty(const hlist_head_t * h); */
/* static_inline hlist_item_t * hlist_head(const hlist_head_t * h); */
/* static_inline hlist_item_t * hlist_next(const hlist_item_t * i); */
/* static_inline hlist_item_t * hlist_prev(const hlist_item_t * i,
const hlist_head_t * h); */
static_inline void hlist_add(hlist_head_t * h, hlist_item_t * i);