shithub: aacdec

Download patch

ref: f3e79702fa8f102089633a9ac8b39c9b485415b4
parent: dbdd0f664f37a11b8e06e07905d12527509e2723
author: menno <menno>
date: Fri Nov 21 10:08:48 EST 2003

Almost completely new mp4 file library
nice and small

--- a/common/mp4ff/Makefile.am
+++ b/common/mp4ff/Makefile.am
@@ -2,12 +2,7 @@
 
 include_HEADERS = mp4ff.h
 
-libmp4ff_la_SOURCES = atom.c ctts.c dinf.c dref.c edts.c \
-	elst.c esds.c hdlr.c iods.c matrix.c mdat.c mdhd.c \
-	mdia.c minf.c moov.c mp4ff.c mvhd.c smhd.c stbl.c \
-	stco.c stsc.c stsd.c stsdtable.c stss.c stsz.c stts.c \
-	tkhd.c trak.c udta.c util.c vmhd.c \
-	funcprotos.h mp4ff.h private.h
+libmp4ff_la_SOURCES = mp4ff.c mp4atom.c mp4sample.c mp4util.c mp4ff.h
 
 AM_CFLAGS = -O2 -g
 LIBTOOL_DEPS =
--- a/common/mp4ff/README_ORIGINAL
+++ /dev/null
@@ -1,42 +1,0 @@
-Quicktime for Linux
-
-Author: Adam Williams    quicktime@altavista.net
-Homepage: heroinewarrior.com/quicktime
-Requires: libpthread
-------------------------------------------------------------------------
-
-***** 
-
-This is a Quicktime library for UNIX in a freely redistributable,
-statically linkable library.  You can statically link it in a program
-and charge money for the program.  The only condition is that if you
-use it in a program, you must put the author's name and email
-somewhere.  If you improve the library itself or add a free codec to
-it, you should release your improvements.  If you redistribute the
-code, you must also redistribute the author information and
-documentation.  At this time it's very popular to license stuff under
-the GPL.  You are free to include this library in a derived work and
-license the derived work under GPL.
-
-*****
-
-Building:
-type "make" in the quicktime/quicktime directory.
-type "make util" to get some Small Utilities.
-
-Configuration:
-
-The file "config.h" defines the size of a 16 bit word and what the
-maximum file size is.
-
-/*******************************************************
- * References:
- *********************************/
-
-Apple's quicktime file format information:
-
-http://developer.apple.com/techpubs/quicktime/qtdevdocs/REF/refQTFileFormat.htm
-
-Color space conversions:
-
-http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html
--- a/common/mp4ff/atom.c
+++ /dev/null
@@ -1,140 +1,0 @@
-#include "mp4ff.h"
-
-
-int mp4ff_atom_reset(mp4ff_atom_t *atom)
-{
-	atom->end = 0;
-	atom->type[0] = atom->type[1] = atom->type[2] = atom->type[3] = 0;
-	return 0;
-}
-
-int mp4ff_atom_read_header(mp4ff_t *file, mp4ff_atom_t *atom)
-{
-	char header[10];
-	int result;
-
-	atom->start = mp4ff_position(file);
-
-	mp4ff_atom_reset(atom);
-
-	if(!mp4ff_read_data(file, header, HEADER_LENGTH)) return 1;
-	result = mp4ff_atom_read_type(header, atom->type);
-	atom->size = mp4ff_atom_read_size(header);
-	if (atom->size == 0) {
-		atom->size = file->total_length - atom->start;
-	}
-	atom->end = atom->start + atom->size;
-
-/* Skip placeholder atom */
-	if(mp4ff_match_32(atom->type, "wide"))
-	{
-		atom->start = mp4ff_position(file);
-		mp4ff_atom_reset(atom);
-		if(!mp4ff_read_data(file, header, HEADER_LENGTH)) 
-			return 1;
-		result = mp4ff_atom_read_type(header, atom->type);
-		atom->size -= 8;
-		if(!atom->size)
-		{
-/* Wrapper ended.  Get new atom size */
-			atom->size = mp4ff_atom_read_size(header);
-			if (atom->size == 0) {
-				atom->size = file->total_length - atom->start;
-			}
-		}
-		atom->end = atom->start + atom->size;
-	}
-	else
-/* Get extended size */
-	if(atom->size == 1)
-	{
-		if(!mp4ff_read_data(file, header, HEADER_LENGTH)) return 1;
-		atom->size = mp4ff_atom_read_size64(header);
-	}
-
-
-#ifdef DEBUG
-	printf("Reading atom %.4s length %u\n", atom->type, atom->size);
-#endif
-	return result;
-}
-
-int mp4ff_atom_write_header(mp4ff_t *file, mp4ff_atom_t *atom, char *text)
-{
-	atom->start = mp4ff_position(file);
-	mp4ff_write_int32(file, 0);
-	mp4ff_write_char32(file, text);
-}
-
-int mp4ff_atom_write_footer(mp4ff_t *file, mp4ff_atom_t *atom)
-{
-	atom->end = mp4ff_position(file);
-	mp4ff_set_position(file, atom->start);
-	mp4ff_write_int32(file, atom->end - atom->start);
-	mp4ff_set_position(file, atom->end);
-}
-
-int mp4ff_atom_is(mp4ff_atom_t *atom, char *type)
-{
-	if(atom->type[0] == type[0] &&
-		atom->type[1] == type[1] &&
-		atom->type[2] == type[2] &&
-		atom->type[3] == type[3])
-	return 1;
-	else
-	return 0;
-}
-
-long mp4ff_atom_read_size(char *data)
-{
-	unsigned long result;
-	unsigned long a, b, c, d;
-	
-	a = (unsigned char)data[0];
-	b = (unsigned char)data[1];
-	c = (unsigned char)data[2];
-	d = (unsigned char)data[3];
-
-	result = (a<<24) | (b<<16) | (c<<8) | d;
-	if(result > 0 && result < HEADER_LENGTH) result = HEADER_LENGTH;
-	return (long)result;
-}
-
-uint64_t mp4ff_atom_read_size64(char *data)
-{
-	uint64_t result = 0;
-	int i;
-
-	for (i = 0; i < 8; i++) {
-		result |= data[i];
-		if (i < 7) {
-			result <<= 8;
-		}
-	}
-
-	if(result < HEADER_LENGTH) 
-		result = HEADER_LENGTH;
-	return result;
-}
-
-int mp4ff_atom_read_type(char *data, char *type)
-{
-	type[0] = data[4];
-	type[1] = data[5];
-	type[2] = data[6];
-	type[3] = data[7];
-
-/*printf("%c%c%c%c ", type[0], type[1], type[2], type[3]); */
-/* need this for mp4ff_check_sig */
-	if(isalpha(type[0]) && isalpha(type[1]) && isalpha(type[2]) && isalpha(type[3]))
-	return 0;
-	else
-	return 1;
-}
-
-int mp4ff_atom_skip(mp4ff_t *file, mp4ff_atom_t *atom)
-{
-	/* printf("skipping atom %.4s, size %u\n", atom->type, atom->size); */
-	return mp4ff_set_position(file, atom->end);
-}
-
--- a/common/mp4ff/ctts.c
+++ /dev/null
@@ -1,130 +1,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public
- * License Version 1.1 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- * 
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- * 
- * The Original Code is MPEG4IP.
- * 
- * The Initial Developer of the Original Code is Cisco Systems Inc.
- * Portions created by Cisco Systems Inc. are
- * Copyright (C) Cisco Systems Inc. 2000, 2001.  All Rights Reserved.
- * 
- * Contributor(s): 
- *		Dave Mackie		dmackie@cisco.com
- */
-
-#include "mp4ff.h"
-
-
-int mp4ff_ctts_init(mp4ff_ctts_t *ctts)
-{
-	ctts->version = 0;
-	ctts->flags = 0;
-	ctts->total_entries = 0;
-	ctts->entries_allocated = 0;
-}
-
-int mp4ff_ctts_init_table(mp4ff_ctts_t *ctts)
-{
-	if (!ctts->entries_allocated) {
-		ctts->entries_allocated = 1;
-		ctts->table = (mp4ff_ctts_table_t*)
-			malloc(sizeof(mp4ff_ctts_table_t) * ctts->entries_allocated);
-		ctts->total_entries = 1;
-	}
-}
-
-int mp4ff_ctts_init_common(mp4ff_t *file, mp4ff_ctts_t *ctts)
-{
-	mp4ff_ctts_table_t *table;
-	mp4ff_ctts_init_table(ctts);
-	table = &(ctts->table[0]);
-
-	table->sample_count = 0;      /* need to set this when closing */
-	table->sample_offset = 0;
-}
-
-int mp4ff_ctts_delete(mp4ff_ctts_t *ctts)
-{
-	if (ctts->total_entries) {
-		free(ctts->table);
-	}
-	ctts->total_entries = 0;
-}
-
-int mp4ff_ctts_dump(mp4ff_ctts_t *ctts)
-{
-	int i;
-	printf("     composition time to sample\n");
-	printf("      version %d\n", ctts->version);
-	printf("      flags %d\n", ctts->flags);
-	printf("      total_entries %d\n", ctts->total_entries);
-	for(i = 0; i < ctts->total_entries; i++) {
-		printf("       count %ld offset %ld\n", 
-			ctts->table[i].sample_count,
-			ctts->table[i].sample_offset);
-	}
-}
-
-int mp4ff_read_ctts(mp4ff_t *file, mp4ff_ctts_t *ctts)
-{
-	int i;
-	ctts->version = mp4ff_read_char(file);
-	ctts->flags = mp4ff_read_int24(file);
-	ctts->total_entries = mp4ff_read_int32(file);
-
-	ctts->table = (mp4ff_ctts_table_t*)
-		malloc(sizeof(mp4ff_ctts_table_t) * ctts->total_entries);
-
-	for (i = 0; i < ctts->total_entries; i++) {
-		ctts->table[i].sample_count = mp4ff_read_int32(file);
-		ctts->table[i].sample_offset = mp4ff_read_int32(file);
-	}
-}
-
-int mp4ff_write_ctts(mp4ff_t *file, mp4ff_ctts_t *ctts)
-{
-	int i;
-	mp4ff_atom_t atom;
-
-	if (ctts->total_entries == 1 && ctts->table[0].sample_offset == 0) {
-		return;
-	}
-
-	mp4ff_atom_write_header(file, &atom, "ctts");
-
-	mp4ff_write_char(file, ctts->version);
-	mp4ff_write_int24(file, ctts->flags);
-	mp4ff_write_int32(file, ctts->total_entries);
-	for(i = 0; i < ctts->total_entries; i++) {
-		mp4ff_write_int32(file, ctts->table[i].sample_count);
-		mp4ff_write_int32(file, ctts->table[i].sample_offset);
-	}
-	mp4ff_atom_write_footer(file, &atom);
-}
-
-int mp4ff_update_ctts(mp4ff_ctts_t *ctts, long sample_offset)
-{
-	if (sample_offset == ctts->table[ctts->total_entries-1].sample_offset) {
-		ctts->table[ctts->total_entries-1].sample_count++;
-	} else {
-		/* need a new entry in the table */
-
-		/* allocate more entries if necessary */
-		if (ctts->total_entries >= ctts->entries_allocated) {
-			ctts->entries_allocated *= 2;
-			ctts->table = (mp4ff_ctts_table_t*)realloc(ctts->table,
-				sizeof(mp4ff_ctts_table_t) * ctts->entries_allocated);
-		}
-	
-		ctts->table[ctts->total_entries].sample_count = 1;
-		ctts->table[ctts->total_entries].sample_offset = sample_offset;
-		ctts->total_entries++;
-	}
-}
--- a/common/mp4ff/dinf.c
+++ /dev/null
@@ -1,44 +1,0 @@
-#include "mp4ff.h"
-
-int mp4ff_dinf_init(mp4ff_dinf_t *dinf)
-{
-	mp4ff_dref_init(&(dinf->dref));
-}
-
-int mp4ff_dinf_delete(mp4ff_dinf_t *dinf)
-{
-	mp4ff_dref_delete(&(dinf->dref));
-}
-
-int mp4ff_dinf_init_all(mp4ff_dinf_t *dinf)
-{
-	mp4ff_dref_init_all(&(dinf->dref));
-}
-
-int mp4ff_dinf_dump(mp4ff_dinf_t *dinf)
-{
-	printf("    data information (dinf)\n");
-	mp4ff_dref_dump(&(dinf->dref));
-}
-
-int mp4ff_read_dinf(mp4ff_t *file, mp4ff_dinf_t *dinf, mp4ff_atom_t *dinf_atom)
-{
-	mp4ff_atom_t leaf_atom;
-
-	do
-	{
-		mp4ff_atom_read_header(file, &leaf_atom);
-		if(mp4ff_atom_is(&leaf_atom, "dref"))
-			{ mp4ff_read_dref(file, &(dinf->dref)); }
-		else
-			mp4ff_atom_skip(file, &leaf_atom);
-	}while(mp4ff_position(file) < dinf_atom->end);
-}
-
-int mp4ff_write_dinf(mp4ff_t *file, mp4ff_dinf_t *dinf)
-{
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, "dinf");
-	mp4ff_write_dref(file, &(dinf->dref));
-	mp4ff_atom_write_footer(file, &atom);
-}
--- a/common/mp4ff/dref.c
+++ /dev/null
@@ -1,130 +1,0 @@
-#include "mp4ff.h"
-
-int mp4ff_dref_table_init(mp4ff_dref_table_t *table)
-{
-	table->size = 0;
-	table->type[0] = 'a';
-	table->type[1] = 'l';
-	table->type[2] = 'i';
-	table->type[3] = 's';
-	table->version = 0;
-	table->flags = 0x0001;
-	table->data_reference = malloc(256);
-	table->data_reference[0] = 0;
-}
-
-int mp4ff_dref_table_delete(mp4ff_dref_table_t *table)
-{
-	if(table->data_reference) free(table->data_reference);
-	table->data_reference = 0;
-}
-
-int mp4ff_read_dref_table(mp4ff_t *file, mp4ff_dref_table_t *table)
-{
-	table->size = mp4ff_read_int32(file);
-	mp4ff_read_char32(file, table->type);
-	table->version = mp4ff_read_char(file);
-	table->flags = mp4ff_read_int24(file);
-	if(table->data_reference) free(table->data_reference);
-
-	table->data_reference = malloc(table->size);
-	if(table->size > 12)
-		mp4ff_read_data(file, table->data_reference, table->size - 12);
-	table->data_reference[table->size - 12] = 0;
-}
-
-int mp4ff_write_dref_table(mp4ff_t *file, mp4ff_dref_table_t *table)
-{
-	int len = strlen(table->data_reference);
-	mp4ff_write_int32(file, 12 + len);
-	mp4ff_write_char32(file, table->type);
-	mp4ff_write_char(file, table->version);
-	mp4ff_write_int24(file, table->flags);
-	if(len)
-		mp4ff_write_data(file, table->data_reference, len);
-}
-
-int mp4ff_dref_table_dump(mp4ff_dref_table_t *table)
-{
-	printf("      data reference table (dref)\n");
-	printf("       type %c%c%c%c\n", table->type[0], table->type[1], table->type[2], table->type[3]);
-	printf("       version %d\n", table->version);
-	printf("       flags %d\n", table->flags);
-	printf("       data %s\n", table->data_reference);
-}
-
-
-int mp4ff_dref_init(mp4ff_dref_t *dref)
-{
-	dref->version = 0;
-	dref->flags = 0;
-	dref->total_entries = 0;
-	dref->table = 0;
-}
-
-int mp4ff_dref_init_all(mp4ff_dref_t *dref)
-{
-	if(!dref->total_entries)
-	{
-		dref->total_entries = 1;
-		dref->table = (mp4ff_dref_table_t *)malloc(sizeof(mp4ff_dref_table_t) * dref->total_entries);
-		mp4ff_dref_table_init(&(dref->table[0]));
-	}
-}
-
-int mp4ff_dref_delete(mp4ff_dref_t *dref)
-{
-	if(dref->table)
-	{
-		int i;
-		for(i = 0; i < dref->total_entries; i++)
-			mp4ff_dref_table_delete(&(dref->table[i]));
-		free(dref->table);
-	}
-	dref->total_entries = 0;
-}
-
-int mp4ff_dref_dump(mp4ff_dref_t *dref)
-{
-	int i;
-	
-	printf("     data reference (dref)\n");
-	printf("      version %d\n", dref->version);
-	printf("      flags %d\n", dref->flags);
-	for(i = 0; i < dref->total_entries; i++)
-	{
-		mp4ff_dref_table_dump(&(dref->table[i]));
-	}
-}
-
-int mp4ff_read_dref(mp4ff_t *file, mp4ff_dref_t *dref)
-{
-	int i;
-
-	dref->version = mp4ff_read_char(file);
-	dref->flags = mp4ff_read_int24(file);
-	dref->total_entries = mp4ff_read_int32(file);
-	dref->table = (mp4ff_dref_table_t*)malloc(sizeof(mp4ff_dref_table_t) * dref->total_entries);
-	for(i = 0; i < dref->total_entries; i++)
-	{
-		mp4ff_dref_table_init(&(dref->table[i]));
-		mp4ff_read_dref_table(file, &(dref->table[i]));
-	}
-}
-
-int mp4ff_write_dref(mp4ff_t *file, mp4ff_dref_t *dref)
-{
-	int i;
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, "dref");
-
-	mp4ff_write_char(file, dref->version);
-	mp4ff_write_int24(file, dref->flags);
-	mp4ff_write_int32(file, dref->total_entries);
-
-	for(i = 0; i < dref->total_entries; i++)
-	{
-		mp4ff_write_dref_table(file, &(dref->table[i]));
-	}
-	mp4ff_atom_write_footer(file, &atom);
-}
--- a/common/mp4ff/edts.c
+++ /dev/null
@@ -1,44 +1,0 @@
-#include "mp4ff.h"
-
-int mp4ff_edts_init(mp4ff_edts_t *edts)
-{
-	mp4ff_elst_init(&(edts->elst));
-}
-
-int mp4ff_edts_delete(mp4ff_edts_t *edts)
-{
-	mp4ff_elst_delete(&(edts->elst));
-}
-
-int mp4ff_edts_init_table(mp4ff_edts_t *edts)
-{
-	mp4ff_elst_init_all(&(edts->elst));
-}
-
-int mp4ff_read_edts(mp4ff_t *file, mp4ff_edts_t *edts, mp4ff_atom_t *edts_atom)
-{
-	mp4ff_atom_t leaf_atom;
-
-	do
-	{
-		mp4ff_atom_read_header(file, &leaf_atom);
-		if(mp4ff_atom_is(&leaf_atom, "elst"))
-			{ mp4ff_read_elst(file, &(edts->elst)); }
-		else
-			mp4ff_atom_skip(file, &leaf_atom);
-	}while(mp4ff_position(file) < edts_atom->end);
-}
-
-int mp4ff_edts_dump(mp4ff_edts_t *edts)
-{
-	printf("  edit atom (edts)\n");
-	mp4ff_elst_dump(&(edts->elst));
-}
-
-int mp4ff_write_edts(mp4ff_t *file, mp4ff_edts_t *edts, long duration)
-{
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, "edts");
-	mp4ff_write_elst(file, &(edts->elst), duration);
-	mp4ff_atom_write_footer(file, &atom);
-}
--- a/common/mp4ff/elst.c
+++ /dev/null
@@ -1,112 +1,0 @@
-#include "mp4ff.h"
-
-
-int mp4ff_elst_table_init(mp4ff_elst_table_t *table)
-{
-	table->duration = 0;
-	table->time = 0;
-	table->rate = 1;
-}
-
-int mp4ff_elst_table_delete(mp4ff_elst_table_t *table)
-{
-}
-
-int mp4ff_read_elst_table(mp4ff_t *file, mp4ff_elst_table_t *table)
-{
-	table->duration = mp4ff_read_int32(file);
-	table->time = mp4ff_read_int32(file);
-	table->rate = mp4ff_read_fixed32(file);
-}
-
-int mp4ff_write_elst_table(mp4ff_t *file, mp4ff_elst_table_t *table, long duration)
-{
-	table->duration = duration;
-	mp4ff_write_int32(file, table->duration);
-	mp4ff_write_int32(file, table->time);
-	mp4ff_write_fixed32(file, table->rate);
-}
-
-int mp4ff_elst_table_dump(mp4ff_elst_table_t *table)
-{
-	printf("    edit list table\n");
-	printf("     duration %ld\n", table->duration);
-	printf("     time %ld\n", table->time);
-	printf("     rate %f\n", table->rate);
-}
-
-int mp4ff_elst_init(mp4ff_elst_t *elst)
-{
-	elst->version = 0;
-	elst->flags = 0;
-	elst->total_entries = 0;
-	elst->table = 0;
-}
-
-int mp4ff_elst_init_all(mp4ff_elst_t *elst)
-{
-	if(!elst->total_entries)
-	{
-		elst->total_entries = 1;
-		elst->table = (mp4ff_elst_table_t*)malloc(sizeof(mp4ff_elst_table_t) * elst->total_entries);
-		mp4ff_elst_table_init(&(elst->table[0]));
-	}
-}
-
-int mp4ff_elst_delete(mp4ff_elst_t *elst)
-{
-	int i;
-	if(elst->total_entries)
-	{
-		for(i = 0; i < elst->total_entries; i++)
-			mp4ff_elst_table_delete(&(elst->table[i]));
-		free(elst->table);
-	}
-	elst->total_entries = 0;
-}
-
-int mp4ff_elst_dump(mp4ff_elst_t *elst)
-{
-	int i;
-	printf("   edit list (elst)\n");
-	printf("    version %d\n", elst->version);
-	printf("    flags %d\n", elst->flags);
-	printf("    total_entries %d\n", elst->total_entries);
-
-	for(i = 0; i < elst->total_entries; i++)
-	{
-		mp4ff_elst_table_dump(&(elst->table[i]));
-	}
-}
-
-int mp4ff_read_elst(mp4ff_t *file, mp4ff_elst_t *elst)
-{
-	int i;
-
-	elst->version = mp4ff_read_char(file);
-	elst->flags = mp4ff_read_int24(file);
-	elst->total_entries = mp4ff_read_int32(file);
-	elst->table = (mp4ff_elst_table_t*)malloc(sizeof(mp4ff_elst_table_t) * elst->total_entries);
-	for(i = 0; i < elst->total_entries; i++)
-	{
-		mp4ff_elst_table_init(&(elst->table[i]));
-		mp4ff_read_elst_table(file, &(elst->table[i]));
-	}
-}
-
-int mp4ff_write_elst(mp4ff_t *file, mp4ff_elst_t *elst, long duration)
-{
-	mp4ff_atom_t atom;
-	int i;
-	mp4ff_atom_write_header(file, &atom, "elst");
-
-	mp4ff_write_char(file, elst->version);
-	mp4ff_write_int24(file, elst->flags);
-	mp4ff_write_int32(file, elst->total_entries);
-	for(i = 0; i < elst->total_entries; i++)
-	{
-		mp4ff_write_elst_table(file, elst->table, duration);
-	}
-
-	mp4ff_atom_write_footer(file, &atom);
-}
--- a/common/mp4ff/esds.c
+++ /dev/null
@@ -1,194 +1,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public
- * License Version 1.1 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- * 
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- * 
- * The Original Code is MPEG4IP.
- * 
- * The Initial Developer of the Original Code is Cisco Systems Inc.
- * Portions created by Cisco Systems Inc. are
- * Copyright (C) Cisco Systems Inc. 2000, 2001.  All Rights Reserved.
- * 
- * Contributor(s): 
- *		Dave Mackie		dmackie@cisco.com
- */
-
-#include "mp4ff.h"
-
-
-int mp4ff_esds_init(mp4ff_esds_t *esds)
-{
-	esds->version = 0;
-	esds->flags = 0;
-	esds->decoderConfigLen = 0;
-	esds->decoderConfig = NULL;
-	return 0;
-}
-
-int mp4ff_esds_get_decoder_config(mp4ff_esds_t* esds, unsigned char** ppBuf, int* pBufSize)
-{
-	if (esds->decoderConfig == NULL || esds->decoderConfigLen == 0) {
-		*ppBuf = NULL;
-		*pBufSize = 0;
-	} else {
-		*ppBuf = malloc(esds->decoderConfigLen);
-		if (*ppBuf == NULL) {
-			*pBufSize = 0;
-			return 1;
-		}
-		memcpy(*ppBuf, esds->decoderConfig, esds->decoderConfigLen);
-		*pBufSize = esds->decoderConfigLen;
-	}
-	return 0;
-}
-
-int mp4ff_esds_set_decoder_config(mp4ff_esds_t* esds, unsigned char* pBuf, int bufSize)
-{
-	free(esds->decoderConfig);
-	esds->decoderConfig = malloc(bufSize);
-	if (esds->decoderConfig) {
-		memcpy(esds->decoderConfig, pBuf, bufSize);
-		esds->decoderConfigLen = bufSize;
-		return 0;
-	}
-	return 1;
-}
-
-int mp4ff_esds_delete(mp4ff_esds_t *esds)
-{
-	free(esds->decoderConfig);
-	return 0;
-}
-
-int mp4ff_esds_dump(mp4ff_esds_t *esds)
-{
-	int i;
-
-	printf("       elementary stream descriptor\n");
-	printf("        version %d\n", esds->version);
-	printf("        flags %ld\n", esds->flags);
-	printf("        decoder config ");
-	for (i = 0; i < esds->decoderConfigLen; i++) {	
-		printf("%02x ", esds->decoderConfig[i]);
-	}
-	printf("\n");
-}
-
-int mp4ff_read_esds(mp4ff_t *file, mp4ff_esds_t *esds)
-{
-	uint8_t tag;
-
-	esds->version = mp4ff_read_char(file);
-	esds->flags = mp4ff_read_int24(file);
-
-	/* get and verify ES_DescrTag */
-	tag = mp4ff_read_char(file);
-	if (tag == 0x03) {
-		/* read length */
-		if (mp4ff_read_mp4_descr_length(file) < 5 + 15) {
-			return 1;
-		}
-		/* skip 3 bytes */
-		mp4ff_set_position(file, mp4ff_position(file) + 3);
-	} else {
-		/* skip 2 bytes */
-		mp4ff_set_position(file, mp4ff_position(file) + 2);
-	}
-
-	/* get and verify DecoderConfigDescrTab */
-	if (mp4ff_read_char(file) != 0x04) {
-		return 1;
-	}
-
-	/* read length */
-	if (mp4ff_read_mp4_descr_length(file) < 15) {
-		return 1;
-	}
-
-	/* skip 13 bytes */
-	mp4ff_set_position(file, mp4ff_position(file) + 13);
-
-	/* get and verify DecSpecificInfoTag */
-	if (mp4ff_read_char(file) != 0x05) {
-		return 1;
-	}
-
-	/* read length */
-	esds->decoderConfigLen = mp4ff_read_mp4_descr_length(file); 
-
-	free(esds->decoderConfig);
-	esds->decoderConfig = malloc(esds->decoderConfigLen);
-	if (esds->decoderConfig) {
-		mp4ff_read_data(file, esds->decoderConfig, esds->decoderConfigLen);
-	} else {
-		esds->decoderConfigLen = 0;
-	}
-
-	/* will skip the remainder of the atom */
-	return 0;
-}
-
-int mp4ff_write_esds_common(mp4ff_t *file, mp4ff_esds_t *esds, int esid, unsigned int objectType, unsigned int streamType)
-{
-	mp4ff_atom_t atom;
-
-	mp4ff_atom_write_header(file, &atom, "esds");
-
-	mp4ff_write_char(file, esds->version);
-	mp4ff_write_int24(file, esds->flags);
-
-	mp4ff_write_char(file, 0x03);	/* ES_DescrTag */
-	mp4ff_write_mp4_descr_length(file, 
-		3 + (5 + (13 + (5 + esds->decoderConfigLen))) + 3, /*FALSE*/0);
-
-	mp4ff_write_int16(file, esid);
-	mp4ff_write_char(file, 0x10);	/* streamPriorty = 16 (0-31) */
-
-	/* DecoderConfigDescriptor */
-	mp4ff_write_char(file, 0x04);	/* DecoderConfigDescrTag */
-	mp4ff_write_mp4_descr_length(file, 
-		13 + (5 + esds->decoderConfigLen), 0 /*FALSE*/);
-
-	mp4ff_write_char(file, objectType); /* objectTypeIndication */
-	mp4ff_write_char(file, streamType); /* streamType */
-
-	mp4ff_write_int24(file, 0);		/* buffer size */
-	mp4ff_write_int32(file, 0);		/* max bitrate */
-	mp4ff_write_int32(file, 0);		/* average bitrate */
-
-	mp4ff_write_char(file, 0x05);	/* DecSpecificInfoTag */
-	mp4ff_write_mp4_descr_length(file, esds->decoderConfigLen, 0 /*FALSE*/);
-	mp4ff_write_data(file, esds->decoderConfig, esds->decoderConfigLen);
-
-	/* SLConfigDescriptor */
-	mp4ff_write_char(file, 0x06);	/* SLConfigDescrTag */
-	mp4ff_write_char(file, 0x01);	/* length */
-	mp4ff_write_char(file, 0x02);	/* constant in mp4 files */
-
-	/* no IPI_DescrPointer */
-	/* no IP_IdentificationDataSet */
-	/* no IPMP_DescriptorPointer */
-	/* no LanguageDescriptor */
-	/* no QoS_Descriptor */
-	/* no RegistrationDescriptor */
-	/* no ExtensionDescriptor */
-
-	mp4ff_atom_write_footer(file, &atom);
-}
-
-int mp4ff_write_esds_audio(mp4ff_t *file, mp4ff_esds_t *esds, int esid)
-{
-	return mp4ff_write_esds_common(file, esds, esid, (unsigned int)0x40, (unsigned int)0x05);
-}
-
-int mp4ff_write_esds_video(mp4ff_t *file, mp4ff_esds_t *esds, int esid)
-{
-	return mp4ff_write_esds_common(file, esds, esid, (unsigned int)0x20, (unsigned int)0x04);
-}
-
--- a/common/mp4ff/funcprotos.h
+++ /dev/null
@@ -1,156 +1,0 @@
-#ifndef FUNCPROTOS_H
-#define FUNCPROTOS_H
-
-/* atom handling routines */
-long mp4ff_atom_read_size(char *data);
-uint64_t mp4ff_atom_read_size64(char *data);
-int mp4ff_atom_write_header(mp4ff_t *file, mp4ff_atom_t *atom, char *text);
-int mp4ff_atom_read_header(mp4ff_t *file, mp4ff_atom_t *atom);
-int mp4ff_atom_write_footer(mp4ff_t *file, mp4ff_atom_t *atom);
-
-mp4ff_trak_t* mp4ff_add_track(mp4ff_moov_t *moov);
-mp4ff_trak_t* mp4ff_find_track_by_id(mp4ff_moov_t *moov, int trackId);
-
-
-/* initializers for every atom */
-int mp4ff_matrix_init(mp4ff_matrix_t *matrix);
-int mp4ff_edts_init_table(mp4ff_edts_t *edts);
-int mp4ff_edts_init(mp4ff_edts_t *edts);
-int mp4ff_elst_init(mp4ff_elst_t *elst);
-int mp4ff_elst_init_all(mp4ff_elst_t *elst);
-int mp4ff_elst_table_init(mp4ff_elst_table_t *table); /* initialize a table */
-int mp4ff_tkhd_init(mp4ff_tkhd_t *tkhd);
-int mp4ff_tkhd_init_video(mp4ff_t *file, mp4ff_tkhd_t *tkhd, int frame_w, int frame_h);
-int mp4ff_stsd_table_init(mp4ff_stsd_table_t *table);
-int mp4ff_stsd_init(mp4ff_stsd_t *stsd);
-int mp4ff_stsd_init_table(mp4ff_stsd_t *stsd);
-int mp4ff_stsd_init_video(mp4ff_t *file, mp4ff_stsd_t *stsd, int frame_w, int frame_h, float frame_rate, char *compression);
-int mp4ff_stsd_init_audio(mp4ff_t *file, mp4ff_stsd_t *stsd, int channels, int sample_rate, int bits, char *compressor);
-int mp4ff_stts_init(mp4ff_stts_t *stts);
-int mp4ff_stts_init_table(mp4ff_stts_t *stts);
-int mp4ff_stts_init_video(mp4ff_t *file, mp4ff_stts_t *stts, int time_scale, float frame_rate);
-int mp4ff_stts_init_audio(mp4ff_t *file, mp4ff_stts_t *stts, int time_scale, int sample_duration);
-int mp4ff_stss_init(mp4ff_stss_t *stss);
-int mp4ff_stss_init_common(mp4ff_t *file, mp4ff_stss_t *stss);
-int mp4ff_stsc_init(mp4ff_stsc_t *stsc);
-int mp4ff_stsc_init_video(mp4ff_t *file, mp4ff_stsc_t *stsc);
-int mp4ff_stsc_init_audio(mp4ff_t *file, mp4ff_stsc_t *stsc);
-int mp4ff_stsz_init(mp4ff_stsz_t *stsz);
-int mp4ff_stsz_init_video(mp4ff_t *file, mp4ff_stsz_t *stsz);
-int mp4ff_stsz_init_audio(mp4ff_t *file, mp4ff_stsz_t *stsz, int sample_size);
-int mp4ff_stco_init(mp4ff_stco_t *stco);
-int mp4ff_stco_init_common(mp4ff_t *file, mp4ff_stco_t *stco);
-int mp4ff_stbl_init(mp4ff_stbl_t *tkhd);
-int mp4ff_stbl_init_video(mp4ff_t *file, mp4ff_stbl_t *stbl, int frame_w, int frame_h, int time_scale, float frame_rate, char *compressor);
-int mp4ff_stbl_init_audio(mp4ff_t *file, mp4ff_stbl_t *stbl, int channels, int sample_rate, int bits, int sample_size, int time_scale, int sample_duration, char *compressor);
-int mp4ff_vmhd_init(mp4ff_vmhd_t *vmhd);
-int mp4ff_vmhd_init_video(mp4ff_t *file, mp4ff_vmhd_t *vmhd, int frame_w, int frame_h, float frame_rate);
-int mp4ff_smhd_init(mp4ff_smhd_t *smhd);
-int mp4ff_dref_table_init(mp4ff_dref_table_t *table);
-int mp4ff_dref_init_all(mp4ff_dref_t *dref);
-int mp4ff_dref_init(mp4ff_dref_t *dref);
-int mp4ff_dinf_init_all(mp4ff_dinf_t *dinf);
-int mp4ff_dinf_init(mp4ff_dinf_t *dinf);
-int mp4ff_minf_init(mp4ff_minf_t *minf);
-int mp4ff_minf_init_video(mp4ff_t *file, mp4ff_minf_t *minf, int frame_w, int frame_h, int time_scale, float frame_rate, char *compressor);
-int mp4ff_minf_init_audio(mp4ff_t *file, mp4ff_minf_t *minf, int channels, int sample_rate, int bits, int sample_size, int time_scale, int sample_duration, char *compressor);
-int mp4ff_mdhd_init(mp4ff_mdhd_t *mdhd);
-int mp4ff_mdhd_init_video(mp4ff_t *file, mp4ff_mdhd_t *mdhd, int time_scale);
-int mp4ff_mdhd_init_audio(mp4ff_t *file, mp4ff_mdhd_t *mdhd, int time_scale);
-int mp4ff_mdia_init(mp4ff_mdia_t *mdia);
-int mp4ff_mdia_init_video(mp4ff_t *file, mp4ff_mdia_t *mdia, int frame_w, int frame_h, float frame_rate, int time_scale, char *compressor);
-int mp4ff_mdia_init_audio(mp4ff_t *file, mp4ff_mdia_t *mdia, int channels, int sample_rate, int bits, int sample_size, int time_scale, int sample_duration, char *compressor);
-int mp4ff_trak_init(mp4ff_trak_t *trak);
-int mp4ff_trak_init_video(mp4ff_t *file, mp4ff_trak_t *trak, int frame_w, int frame_h, float frame_rate, int time_scale, char *compressor);
-int mp4ff_trak_init_audio(mp4ff_t *file, mp4ff_trak_t *trak, int channels, int sample_rate, int bits, int sample_size, int time_scale, int sample_duration, char *compressor);
-int mp4ff_udta_init(mp4ff_udta_t *udta);
-int mp4ff_mvhd_init(mp4ff_mvhd_t *mvhd);
-int mp4ff_moov_init(mp4ff_moov_t *moov);
-int mp4ff_mdat_init(mp4ff_mdat_t *mdat);
-int mp4ff_init(mp4ff_t *file);
-int mp4ff_hdlr_init(mp4ff_hdlr_t *hdlr);
-int mp4ff_hdlr_init_video(mp4ff_hdlr_t *hdlr);
-int mp4ff_hdlr_init_audio(mp4ff_hdlr_t *hdlr);
-int mp4ff_hdlr_init_data(mp4ff_hdlr_t *hdlr);
-
-/* utilities for reading data types */
-int mp4ff_read_data(mp4ff_t *file, char *data, int size);
-int mp4ff_write_data(mp4ff_t *file, char *data, int size);
-int mp4ff_read_pascal(mp4ff_t *file, char *data);
-int mp4ff_write_pascal(mp4ff_t *file, char *data);
-float mp4ff_read_fixed32(mp4ff_t *file);
-int mp4ff_write_fixed32(mp4ff_t *file, float number);
-float mp4ff_read_fixed16(mp4ff_t *file);
-int mp4ff_write_fixed16(mp4ff_t *file, float number);
-uint64_t mp4ff_read_int64(mp4ff_t *file);
-int mp4ff_write_int64(mp4ff_t *file, uint64_t number);
-long mp4ff_read_int32(mp4ff_t *file);
-int mp4ff_write_int32(mp4ff_t *file, long number);
-long mp4ff_read_int24(mp4ff_t *file);
-int mp4ff_write_int24(mp4ff_t *file, long number);
-int mp4ff_read_int16(mp4ff_t *file);
-int mp4ff_write_int16(mp4ff_t *file, int number);
-int mp4ff_read_char(mp4ff_t *file);
-int mp4ff_write_char(mp4ff_t *file, char x);
-int mp4ff_read_char32(mp4ff_t *file, char *string);
-int mp4ff_write_char32(mp4ff_t *file, char *string);
-int mp4ff_copy_char32(char *output, char *input);
-long mp4ff_position(mp4ff_t *file);
-int mp4ff_read_mp4_descr_length(mp4ff_t *file);
-int mp4ff_write_mp4_descr_length(mp4ff_t *file, int length, unsigned char compact);
-
-/* Most codecs don't specify the actual number of bits on disk in the stbl. */
-/* Convert the samples to the number of bytes for reading depending on the codec. */
-long mp4ff_samples_to_bytes(mp4ff_trak_t *track, long samples);
-
-
-/* chunks always start on 1 */
-/* samples start on 0 */
-
-/* queries for every atom */
-/* the starting sample in the given chunk */
-long mp4ff_sample_of_chunk(mp4ff_trak_t *trak, long chunk);
-
-/* number of samples in the chunk */
-long mp4ff_chunk_samples(mp4ff_trak_t *trak, long chunk);
-
-/* the byte offset from mdat start of the chunk */
-long mp4ff_chunk_to_offset(mp4ff_trak_t *trak, long chunk);
-
-/* the chunk of any offset from mdat start */
-long mp4ff_offset_to_chunk(long *chunk_offset, mp4ff_trak_t *trak, long offset);
-
-/* the total number of samples in the track depending on the access mode */
-long mp4ff_track_samples(mp4ff_t *file, mp4ff_trak_t *trak);
-
-/* total bytes between the two samples */
-long mp4ff_sample_range_size(mp4ff_trak_t *trak, long chunk_sample, long sample);
-
-/* update the position pointers in all the tracks after a set_position */
-int mp4ff_update_positions(mp4ff_t *file);
-
-/* converting between mdat offsets to samples */
-long mp4ff_sample_to_offset(mp4ff_trak_t *trak, long sample);
-long mp4ff_offset_to_sample(mp4ff_trak_t *trak, long offset);
-
-mp4ff_trak_t* mp4ff_add_trak(mp4ff_moov_t *moov);
-int mp4ff_delete_trak(mp4ff_moov_t *moov, mp4ff_trak_t *trak);
-int mp4ff_get_timescale(float frame_rate);
-
-/* update all the tables after writing a buffer */
-/* set sample_size to 0 if no sample size should be set */
-int mp4ff_update_tables(mp4ff_t *file, 
-							mp4ff_trak_t *trak, 
-							long offset, 
-							long chunk, 
-							long sample, 
-							long samples, 
-							long sample_size,
-							long sample_duration,
-							unsigned char isSyncSample,
-							long renderingOffset);
-unsigned long mp4ff_current_time();
-
-void mp4ff_print_chars(char *desc, char *input, int len);
-
-#endif
--- a/common/mp4ff/hdlr.c
+++ /dev/null
@@ -1,98 +1,0 @@
-#include "mp4ff.h"
-
-
-
-int mp4ff_hdlr_init(mp4ff_hdlr_t *hdlr)
-{
-	hdlr->version = 0;
-	hdlr->flags = 0;
-	hdlr->component_type[0] = 'm';
-	hdlr->component_type[1] = 'h';
-	hdlr->component_type[2] = 'l';
-	hdlr->component_type[3] = 'r';
-	hdlr->component_subtype[0] = 'v';
-	hdlr->component_subtype[1] = 'i';
-	hdlr->component_subtype[2] = 'd';
-	hdlr->component_subtype[3] = 'e';
-	hdlr->component_manufacturer = 0;
-	hdlr->component_flags = 0;
-	hdlr->component_flag_mask = 0;
-	strcpy(hdlr->component_name, "Linux Media Handler");
-}
-
-int mp4ff_hdlr_init_video(mp4ff_hdlr_t *hdlr)
-{
-	hdlr->component_subtype[0] = 'v';
-	hdlr->component_subtype[1] = 'i';
-	hdlr->component_subtype[2] = 'd';
-	hdlr->component_subtype[3] = 'e';
-	strcpy(hdlr->component_name, "Linux Video Media Handler");
-}
-
-int mp4ff_hdlr_init_audio(mp4ff_hdlr_t *hdlr)
-{
-	hdlr->component_subtype[0] = 's';
-	hdlr->component_subtype[1] = 'o';
-	hdlr->component_subtype[2] = 'u';
-	hdlr->component_subtype[3] = 'n';
-	strcpy(hdlr->component_name, "Linux Sound Media Handler");
-}
-
-int mp4ff_hdlr_init_data(mp4ff_hdlr_t *hdlr)
-{
-	hdlr->component_type[0] = 'd';
-	hdlr->component_type[1] = 'h';
-	hdlr->component_type[2] = 'l';
-	hdlr->component_type[3] = 'r';
-	hdlr->component_subtype[0] = 'a';
-	hdlr->component_subtype[1] = 'l';
-	hdlr->component_subtype[2] = 'i';
-	hdlr->component_subtype[3] = 's';
-	strcpy(hdlr->component_name, "Linux Alias Data Handler");
-}
-
-int mp4ff_hdlr_delete(mp4ff_hdlr_t *hdlr)
-{
-}
-
-int mp4ff_hdlr_dump(mp4ff_hdlr_t *hdlr)
-{
-	printf("   handler reference (hdlr)\n");
-	printf("    version %d\n", hdlr->version);
-	printf("    flags %d\n", hdlr->flags);
-	printf("    component_type %c%c%c%c\n", hdlr->component_type[0], hdlr->component_type[1], hdlr->component_type[2], hdlr->component_type[3]);
-	printf("    component_subtype %c%c%c%c\n", hdlr->component_subtype[0], hdlr->component_subtype[1], hdlr->component_subtype[2], hdlr->component_subtype[3]);
-	printf("    component_name %s\n", hdlr->component_name);
-}
-
-int mp4ff_read_hdlr(mp4ff_t *file, mp4ff_hdlr_t *hdlr)
-{
-	hdlr->version = mp4ff_read_char(file);
-	hdlr->flags = mp4ff_read_int24(file);
-	mp4ff_read_char32(file, hdlr->component_type);
-	mp4ff_read_char32(file, hdlr->component_subtype);
-	hdlr->component_manufacturer = mp4ff_read_int32(file);
-	hdlr->component_flags = mp4ff_read_int32(file);
-	hdlr->component_flag_mask = mp4ff_read_int32(file);
-    // TBD read null terminated string
-}
-
-int mp4ff_write_hdlr(mp4ff_t *file, mp4ff_hdlr_t *hdlr)
-{
-	int i;
-
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, "hdlr");
-
-	mp4ff_write_char(file, hdlr->version);
-	mp4ff_write_int24(file, hdlr->flags);
-
-	mp4ff_write_int32(file, 0x00000000);
-	mp4ff_write_char32(file, hdlr->component_subtype);
-	for (i = 0; i < 3; i++) {
-		mp4ff_write_int32(file, 0x00000000);
-	}
-	mp4ff_write_data(file, hdlr->component_name, strlen(hdlr->component_name) + 1);
-
-	mp4ff_atom_write_footer(file, &atom);
-}
--- a/common/mp4ff/iods.c
+++ /dev/null
@@ -1,102 +1,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public
- * License Version 1.1 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- * 
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- * 
- * The Original Code is MPEG4IP.
- * 
- * The Initial Developer of the Original Code is Cisco Systems Inc.
- * Portions created by Cisco Systems Inc. are
- * Copyright (C) Cisco Systems Inc. 2000, 2001.  All Rights Reserved.
- * 
- * Contributor(s): 
- *		Dave Mackie		dmackie@cisco.com
- */
-
-#include "mp4ff.h"
-
-
-int mp4ff_iods_init(mp4ff_iods_t *iods)
-{
-	iods->version = 0;
-	iods->flags = 0;
-	iods->audioProfileId = 0xFF;
-	iods->videoProfileId = 0xFF;
-	return 0;
-}
-
-int mp4ff_iods_set_audio_profile(mp4ff_iods_t* iods, int id)
-{
-	iods->audioProfileId = id;
-}
-
-int mp4ff_iods_set_video_profile(mp4ff_iods_t* iods, int id)
-{
-	iods->videoProfileId = id;
-}
-
-int mp4ff_iods_delete(mp4ff_iods_t *iods)
-{
-	return 0;
-}
-
-int mp4ff_iods_dump(mp4ff_iods_t *iods)
-{
-	printf(" initial object descriptor\n");
-	printf("  version %d\n", iods->version);
-	printf("  flags %ld\n", iods->flags);
-	printf("  audioProfileId %u\n", iods->audioProfileId);
-	printf("  videoProfileId %u\n", iods->videoProfileId);
-}
-
-int mp4ff_read_iods(mp4ff_t *file, mp4ff_iods_t *iods)
-{
-	iods->version = mp4ff_read_char(file);
-	iods->flags = mp4ff_read_int24(file);
-	mp4ff_read_char(file); /* skip tag */
-	mp4ff_read_mp4_descr_length(file);	/* skip length */
-	/* skip ODID, ODProfile, sceneProfile */
-	mp4ff_set_position(file, mp4ff_position(file) + 4);
-	iods->audioProfileId = mp4ff_read_char(file);
-	iods->videoProfileId = mp4ff_read_char(file);
-	/* will skip the remainder of the atom */
-}
-
-int mp4ff_write_iods(mp4ff_t *file, mp4ff_iods_t *iods)
-{
-	mp4ff_atom_t atom;
-	int i;
-
-	mp4ff_atom_write_header(file, &atom, "iods");
-
-	mp4ff_write_char(file, iods->version);
-	mp4ff_write_int24(file, iods->flags);
-
-	mp4ff_write_char(file, 0x10);	/* MP4_IOD_Tag */
-	mp4ff_write_char(file, 7 + (file->moov.total_tracks * (1+1+4)));	/* length */
-	mp4ff_write_int16(file, 0x004F); /* ObjectDescriptorID = 1 */
-	mp4ff_write_char(file, 0xFF);	/* ODProfileLevel */
-	mp4ff_write_char(file, 0xFF);	/* sceneProfileLevel */
-	mp4ff_write_char(file, iods->audioProfileId);	/* audioProfileLevel */
-	mp4ff_write_char(file, iods->videoProfileId);	/* videoProfileLevel */
-	mp4ff_write_char(file, 0xFF);	/* graphicsProfileLevel */
-
-	for (i = 0; i < file->moov.total_tracks; i++) {
-		mp4ff_write_char(file, 0x0E);	/* ES_ID_IncTag */
-		mp4ff_write_char(file, 0x04);	/* length */
-		mp4ff_write_int32(file, file->moov.trak[i]->tkhd.track_id);	
-	}
-
-	/* no OCI_Descriptors */
-	/* no IPMP_DescriptorPointers */
-	/* no Extenstion_Descriptors */
-
-	mp4ff_atom_write_footer(file, &atom);
-}
-
--- a/common/mp4ff/matrix.c
+++ /dev/null
@@ -1,42 +1,0 @@
-#include "mp4ff.h"
-
-
-
-
-int mp4ff_matrix_init(mp4ff_matrix_t *matrix)
-{
-	int i;
-	for(i = 0; i < 9; i++) matrix->values[i] = 0;
-	matrix->values[0] = matrix->values[4] = 1;
-	matrix->values[8] = 16384;
-}
-
-int mp4ff_matrix_delete(mp4ff_matrix_t *matrix)
-{
-}
-
-int mp4ff_read_matrix(mp4ff_t *file, mp4ff_matrix_t *matrix)
-{
-	int i = 0;
-	for(i = 0; i < 9; i++)
-	{
-		matrix->values[i] = mp4ff_read_fixed32(file);
-	}
-}
-
-int mp4ff_matrix_dump(mp4ff_matrix_t *matrix)
-{
-	int i;
-	printf("   matrix");
-	for(i = 0; i < 9; i++) printf(" %f", matrix->values[i]);
-	printf("\n");
-}
-
-int mp4ff_write_matrix(mp4ff_t *file, mp4ff_matrix_t *matrix)
-{
-	int i;
-	for(i = 0; i < 9; i++)
-	{
-		mp4ff_write_fixed32(file, matrix->values[i]);
-	}
-}
--- a/common/mp4ff/mdat.c
+++ /dev/null
@@ -1,43 +1,0 @@
-#include "mp4ff.h"
-
-int mp4ff_mdat_init(mp4ff_mdat_t *mdat)
-{
-	mdat->size = 8;
-	mdat->start = 0;
-}
-
-int mp4ff_mdat_delete(mp4ff_mdat_t *mdat)
-{
-}
-
-int mp4ff_read_mdat(mp4ff_t *file, mp4ff_mdat_t *mdat, mp4ff_atom_t *parent_atom)
-{
-	mdat->size = parent_atom->size;
-	mdat->start = parent_atom->start;
-	mp4ff_atom_skip(file, parent_atom);
-}
-
-int mp4ff_write_mdat(mp4ff_t *file, mp4ff_mdat_t *mdat)
-{
-	long position, size = 0, new_size = 0;
-	int i, j;
-	
-	for(i = 0; i < file->total_atracks; i++)
-	{
-		new_size = mp4ff_track_end(file->atracks[i].track);
-		if(new_size > size) 
-			size = new_size;
-	}
-
-	for(i = 0; i < file->total_vtracks; i++)
-	{
-		new_size = mp4ff_track_end(file->vtracks[i].track);
-		if(new_size > size) 
-			size = new_size;
-	}
-	
-	mdat->size = size;
-	mp4ff_set_position(file, mdat->start);
-	mp4ff_write_int32(file, mdat->size);
-	mp4ff_set_position(file, mdat->start + mdat->size);
-}
--- a/common/mp4ff/mdhd.c
+++ /dev/null
@@ -1,76 +1,0 @@
-#include "mp4ff.h"
-
-int mp4ff_mdhd_init(mp4ff_mdhd_t *mdhd)
-{
-	mdhd->version = 0;
-	mdhd->flags = 0;
-	mdhd->creation_time = mp4ff_current_time();
-	mdhd->modification_time = mp4ff_current_time();
-	mdhd->time_scale = 0;
-	mdhd->duration = 0;
-	mdhd->language = 0;
-	mdhd->quality = 0;
-}
-
-int mp4ff_mdhd_init_video(mp4ff_t *file, 
-							mp4ff_mdhd_t *mdhd,
-							int time_scale)
-{
-	mdhd->time_scale = time_scale;
-	mdhd->duration = 0;      /* set this when closing */
-}
-
-int mp4ff_mdhd_init_audio(mp4ff_t *file, 
-							mp4ff_mdhd_t *mdhd, 
-							int time_scale)
-{
-	mdhd->time_scale = time_scale;
-	mdhd->duration = 0;      /* set this when closing */
-}
-
-mp4ff_mdhd_delete(mp4ff_mdhd_t *mdhd)
-{
-}
-
-int mp4ff_read_mdhd(mp4ff_t *file, mp4ff_mdhd_t *mdhd)
-{
-	mdhd->version = mp4ff_read_char(file);
-	mdhd->flags = mp4ff_read_int24(file);
-	mdhd->creation_time = mp4ff_read_int32(file);
-	mdhd->modification_time = mp4ff_read_int32(file);
-	mdhd->time_scale = mp4ff_read_int32(file);
-	mdhd->duration = mp4ff_read_int32(file);
-	mdhd->language = mp4ff_read_int16(file);
-	mdhd->quality = mp4ff_read_int16(file);
-}
-
-int mp4ff_mdhd_dump(mp4ff_mdhd_t *mdhd)
-{
-	printf("   media header\n");
-	printf("    version %d\n", mdhd->version);
-	printf("    flags %d\n", mdhd->flags);
-	printf("    creation_time %u\n", mdhd->creation_time);
-	printf("    modification_time %u\n", mdhd->modification_time);
-	printf("    time_scale %d\n", mdhd->time_scale);
-	printf("    duration %d\n", mdhd->duration);
-	printf("    language %d\n", mdhd->language);
-	printf("    quality %d\n", mdhd->quality);
-}
-
-int mp4ff_write_mdhd(mp4ff_t *file, mp4ff_mdhd_t *mdhd)
-{
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, "mdhd");
-
-	mp4ff_write_char(file, mdhd->version);
-	mp4ff_write_int24(file, mdhd->flags);
-	mp4ff_write_int32(file, mdhd->creation_time);
-	mp4ff_write_int32(file, mdhd->modification_time);
-	mp4ff_write_int32(file, mdhd->time_scale);
-	mp4ff_write_int32(file, mdhd->duration);
-	mp4ff_write_int16(file, mdhd->language);
-	mp4ff_write_int16(file, 0x0000);	
-
-	mp4ff_atom_write_footer(file, &atom);
-}
-
--- a/common/mp4ff/mdia.c
+++ /dev/null
@@ -1,93 +1,0 @@
-#include "mp4ff.h"
-
-
-int mp4ff_mdia_init(mp4ff_mdia_t *mdia)
-{
-	mp4ff_mdhd_init(&(mdia->mdhd));
-	mp4ff_hdlr_init(&(mdia->hdlr));
-	mp4ff_minf_init(&(mdia->minf));
-}
-
-int mp4ff_mdia_init_video(mp4ff_t *file, 
-								mp4ff_mdia_t *mdia,
-								int frame_w,
-								int frame_h, 
-								float frame_rate,
-								int time_scale,
-								char *compressor)
-{
-	mp4ff_mdhd_init_video(file, &(mdia->mdhd), time_scale);
-	mp4ff_minf_init_video(file, &(mdia->minf), frame_w, frame_h, mdia->mdhd.time_scale, frame_rate, compressor);
-	mp4ff_hdlr_init_video(&(mdia->hdlr));
-}
-
-int mp4ff_mdia_init_audio(mp4ff_t *file, 
-							mp4ff_mdia_t *mdia, 
-							int channels,
-							int sample_rate, 
-							int bits, 
-							int sample_size,
-							int time_scale,
-							int sample_duration,
-							char *compressor)
-{
-	mp4ff_mdhd_init_audio(file, &(mdia->mdhd), time_scale);
-	mp4ff_minf_init_audio(file, &(mdia->minf), channels, sample_rate, bits, sample_size, time_scale, sample_duration, compressor);
-	mp4ff_hdlr_init_audio(&(mdia->hdlr));
-}
-
-int mp4ff_mdia_delete(mp4ff_mdia_t *mdia)
-{
-	mp4ff_mdhd_delete(&(mdia->mdhd));
-	mp4ff_hdlr_delete(&(mdia->hdlr));
-	mp4ff_minf_delete(&(mdia->minf));
-}
-
-int mp4ff_mdia_dump(mp4ff_mdia_t *mdia)
-{
-	printf("  media\n");
-	mp4ff_mdhd_dump(&(mdia->mdhd));
-	mp4ff_hdlr_dump(&(mdia->hdlr));
-	mp4ff_minf_dump(&(mdia->minf));
-}
-
-int mp4ff_read_mdia(mp4ff_t *file, mp4ff_mdia_t *mdia, mp4ff_atom_t *trak_atom)
-{
-	mp4ff_atom_t leaf_atom;
-
-	do
-	{
-		mp4ff_atom_read_header(file, &leaf_atom);
-
-/* mandatory */
-		if(mp4ff_atom_is(&leaf_atom, "mdhd"))
-			{ mp4ff_read_mdhd(file, &(mdia->mdhd)); }
-		else
-		if(mp4ff_atom_is(&leaf_atom, "hdlr"))
-			{
-				mp4ff_read_hdlr(file, &(mdia->hdlr)); 
-/* Main Actor doesn't write component name */
-				mp4ff_atom_skip(file, &leaf_atom);
-/*printf("mp4ff_read_mdia %ld\n", mp4ff_position(file)); */
-			}
-		else
-		if(mp4ff_atom_is(&leaf_atom, "minf"))
-			{ mp4ff_read_minf(file, &(mdia->minf), &leaf_atom); }
-		else
-			mp4ff_atom_skip(file, &leaf_atom);
-	}while(mp4ff_position(file) < trak_atom->end);
-
-	return 0;
-}
-
-int mp4ff_write_mdia(mp4ff_t *file, mp4ff_mdia_t *mdia)
-{
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, "mdia");
-
-	mp4ff_write_mdhd(file, &(mdia->mdhd));
-	mp4ff_write_hdlr(file, &(mdia->hdlr));
-	mp4ff_write_minf(file, &(mdia->minf));
-
-	mp4ff_atom_write_footer(file, &atom);
-}
--- a/common/mp4ff/minf.c
+++ /dev/null
@@ -1,124 +1,0 @@
-#include "mp4ff.h"
-
-
-
-int mp4ff_minf_init(mp4ff_minf_t *minf)
-{
-	minf->is_video = minf->is_audio = 0;
-	mp4ff_vmhd_init(&(minf->vmhd));
-	mp4ff_smhd_init(&(minf->smhd));
-	mp4ff_hdlr_init(&(minf->hdlr));
-	mp4ff_dinf_init(&(minf->dinf));
-	mp4ff_stbl_init(&(minf->stbl));
-}
-
-int mp4ff_minf_init_video(mp4ff_t *file, 
-								mp4ff_minf_t *minf, 
-								int frame_w,
-								int frame_h, 
-								int time_scale, 
-								float frame_rate,
-								char *compressor)
-{
-	minf->is_video = 1;
-	mp4ff_vmhd_init_video(file, &(minf->vmhd), frame_w, frame_h, frame_rate);
-	mp4ff_stbl_init_video(file, &(minf->stbl), frame_w, frame_h, time_scale, frame_rate, compressor);
-	mp4ff_hdlr_init_data(&(minf->hdlr));
-	mp4ff_dinf_init_all(&(minf->dinf));
-}
-
-int mp4ff_minf_init_audio(mp4ff_t *file, 
-							mp4ff_minf_t *minf, 
-							int channels, 
-							int sample_rate, 
-							int bits,
-							int sample_size,
-							int time_scale,
-							int sample_duration,
-							char *compressor)
-{
-	minf->is_audio = 1;
-/* smhd doesn't store anything worth initializing */
-	mp4ff_stbl_init_audio(file, &(minf->stbl), channels, sample_rate, bits, sample_size, time_scale, sample_duration, compressor);
-	mp4ff_hdlr_init_data(&(minf->hdlr));
-	mp4ff_dinf_init_all(&(minf->dinf));
-}
-
-int mp4ff_minf_delete(mp4ff_minf_t *minf)
-{
-	mp4ff_vmhd_delete(&(minf->vmhd));
-	mp4ff_smhd_delete(&(minf->smhd));
-	mp4ff_dinf_delete(&(minf->dinf));
-	mp4ff_stbl_delete(&(minf->stbl));
-	mp4ff_hdlr_delete(&(minf->hdlr));
-}
-
-int mp4ff_minf_dump(mp4ff_minf_t *minf)
-{
-	printf("   media info\n");
-	printf("    is_audio %d\n", minf->is_audio);
-	printf("    is_video %d\n", minf->is_video);
-	if(minf->is_audio) mp4ff_smhd_dump(&(minf->smhd));
-	if(minf->is_video) mp4ff_vmhd_dump(&(minf->vmhd));
-	mp4ff_hdlr_dump(&(minf->hdlr));
-	mp4ff_dinf_dump(&(minf->dinf));
-	mp4ff_stbl_dump(minf, &(minf->stbl));
-}
-
-int mp4ff_read_minf(mp4ff_t *file, mp4ff_minf_t *minf, mp4ff_atom_t *parent_atom)
-{
-	mp4ff_atom_t leaf_atom;
-	long pos = mp4ff_position(file);
-
-	do
-	{
-		mp4ff_atom_read_header(file, &leaf_atom);
-
-/* mandatory */
-		if(mp4ff_atom_is(&leaf_atom, "vmhd"))
-			{ minf->is_video = 1; mp4ff_read_vmhd(file, &(minf->vmhd)); }
-		else
-		if(mp4ff_atom_is(&leaf_atom, "smhd"))
-			{ minf->is_audio = 1; mp4ff_read_smhd(file, &(minf->smhd)); }
-		else
-		if(mp4ff_atom_is(&leaf_atom, "hdlr"))
-			{ 
-				mp4ff_read_hdlr(file, &(minf->hdlr)); 
-/* Main Actor doesn't write component name */
-				mp4ff_atom_skip(file, &leaf_atom);
-			}
-		else
-		if(mp4ff_atom_is(&leaf_atom, "dinf"))
-			{ mp4ff_read_dinf(file, &(minf->dinf), &leaf_atom); }
-		else
-			mp4ff_atom_skip(file, &leaf_atom);
-	}while(mp4ff_position(file) < parent_atom->end);
-
-	mp4ff_set_position(file, pos);
-
-	do {
-		mp4ff_atom_read_header(file, &leaf_atom);
-
-		if(mp4ff_atom_is(&leaf_atom, "stbl")) {
-			mp4ff_read_stbl(file, minf, &(minf->stbl), &leaf_atom);
-		} else {
-			mp4ff_atom_skip(file, &leaf_atom);
-		}
-	} while(mp4ff_position(file) < parent_atom->end);
-
-	return 0;
-}
-
-int mp4ff_write_minf(mp4ff_t *file, mp4ff_minf_t *minf)
-{
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, "minf");
-
-	if(minf->is_video) mp4ff_write_vmhd(file, &(minf->vmhd));
-	if(minf->is_audio) mp4ff_write_smhd(file, &(minf->smhd));
-	mp4ff_write_hdlr(file, &(minf->hdlr));
-	mp4ff_write_dinf(file, &(minf->dinf));
-	mp4ff_write_stbl(file, minf, &(minf->stbl));
-
-	mp4ff_atom_write_footer(file, &atom);
-}
--- a/common/mp4ff/moov.c
+++ /dev/null
@@ -1,130 +1,0 @@
-#include "mp4ff.h"
-
-
-
-int mp4ff_moov_init(mp4ff_moov_t *moov)
-{
-	int i;
-
-	moov->total_tracks = 0;
-	for(i = 0 ; i < MAXTRACKS; i++) moov->trak[i] = 0;
-	mp4ff_mvhd_init(&(moov->mvhd));
-	mp4ff_iods_init(&(moov->iods));
-	mp4ff_udta_init(&(moov->udta));
-	return 0;
-}
-
-int mp4ff_moov_delete(mp4ff_moov_t *moov)
-{
-	int i;
-	while(moov->total_tracks) {
-		mp4ff_delete_trak(moov, moov->trak[moov->total_tracks - 1]);
-	}
-	mp4ff_mvhd_delete(&(moov->mvhd));
-	mp4ff_iods_delete(&(moov->iods));
-	mp4ff_udta_delete(&(moov->udta));
-	return 0;
-}
-
-int mp4ff_moov_dump(mp4ff_moov_t *moov)
-{
-	int i;
-	printf("movie\n");
-	mp4ff_mvhd_dump(&(moov->mvhd));
-	mp4ff_iods_dump(&(moov->iods));
-	mp4ff_udta_dump(&(moov->udta));
-	for(i = 0; i < moov->total_tracks; i++)
-		mp4ff_trak_dump(moov->trak[i]);
-}
-
-
-int mp4ff_read_moov(mp4ff_t *file, mp4ff_moov_t *moov, mp4ff_atom_t *parent_atom)
-{
-/* mandatory mvhd */
-	mp4ff_atom_t leaf_atom;
-
-	do
-	{
-		mp4ff_atom_read_header(file, &leaf_atom);
-		
-		if(mp4ff_atom_is(&leaf_atom, "mvhd"))
-		{
-			mp4ff_read_mvhd(file, &(moov->mvhd));
-		}
-		else
-		if(mp4ff_atom_is(&leaf_atom, "iods"))
-		{
-			mp4ff_read_iods(file, &(moov->iods));
-			mp4ff_atom_skip(file, &leaf_atom);
-		}
-		else
-		if(mp4ff_atom_is(&leaf_atom, "trak"))
-		{
-			mp4ff_trak_t *trak = mp4ff_add_trak(moov);
-			mp4ff_read_trak(file, trak, &leaf_atom);
-		}
-		else
-		if(mp4ff_atom_is(&leaf_atom, "udta"))
-		{
-			mp4ff_read_udta(file, &(moov->udta), &leaf_atom);
-			mp4ff_atom_skip(file, &leaf_atom);
-		}
-		else
-		{
-			mp4ff_atom_skip(file, &leaf_atom);
-		}
-	}while(mp4ff_position(file) < parent_atom->end);
-	
-	return 0;
-}
-
-int mp4ff_write_moov(mp4ff_t *file, mp4ff_moov_t *moov)
-{
-	mp4ff_atom_t atom;
-	int i;
-	long longest_duration = 0;
-	long duration, timescale;
-	mp4ff_atom_write_header(file, &atom, "moov");
-
-/* get the duration from the longest track in the mvhd's timescale */
-	for(i = 0; i < moov->total_tracks; i++)
-	{
-		mp4ff_trak_fix_counts(file, moov->trak[i]);
-		mp4ff_trak_duration(moov->trak[i], &duration, &timescale);
-
-		duration = (long)((float)duration / timescale * moov->mvhd.time_scale);
-
-		if(duration > longest_duration)
-		{
-			longest_duration = duration;
-		}
-	}
-	moov->mvhd.duration = longest_duration;
-	moov->mvhd.selection_duration = longest_duration;
-
-	mp4ff_write_mvhd(file, &(moov->mvhd));
-	mp4ff_write_iods(file, &(moov->iods));
-	mp4ff_write_udta(file, &(moov->udta));
-
-	for(i = 0; i < moov->total_tracks; i++)
-	{
-		mp4ff_write_trak(file, moov->trak[i], moov->mvhd.time_scale);
-	}
-
-	mp4ff_atom_write_footer(file, &atom);
-}
-
-int mp4ff_update_durations(mp4ff_moov_t *moov)
-{
-	
-}
-
-int mp4ff_shift_offsets(mp4ff_moov_t *moov, long offset)
-{
-	int i;
-	for(i = 0; i < moov->total_tracks; i++)
-	{
-		mp4ff_trak_shift_offsets(moov->trak[i], offset);
-	}
-	return 0;
-}
--- /dev/null
+++ b/common/mp4ff/mp4atom.c
@@ -1,0 +1,422 @@
+/*
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
+** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program 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 General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** Any non-GPL usage of this software or parts of this software is strictly
+** forbidden.
+**
+** Commercial non-GPL licensing of this software is possible.
+** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+**
+** $Id: mp4atom.c,v 1.1 2003/11/21 15:08:48 menno Exp $
+**/
+
+#include <stdlib.h>
+#include "mp4ff.h"
+
+
+/* parse atom header size */
+int32_t mp4ff_atom_get_size(int8_t *data)
+{
+    uint32_t result;
+    uint32_t a, b, c, d;
+
+    a = (uint8_t)data[0];
+    b = (uint8_t)data[1];
+    c = (uint8_t)data[2];
+    d = (uint8_t)data[3];
+
+    result = (a<<24) | (b<<16) | (c<<8) | d;
+    if (result > 0 && result < 8) result = 8;
+
+    return (int32_t)result;
+}
+
+/* comnapre 2 atom names, returns 1 for equal, 0 for unequal */
+int32_t mp4ff_atom_compare(int8_t a1, int8_t b1, int8_t c1, int8_t d1,
+                           int8_t a2, int8_t b2, int8_t c2, int8_t d2)
+{
+    if (a1 == a2 && b1 == b2 && c1 == c2 && d1 == d2)
+        return 1;
+    else
+        return 0;
+}
+
+uint8_t mp4ff_atom_name_to_type(int8_t a, int8_t b, int8_t c, int8_t d)
+{
+    if (a == 'm')
+    {
+        if (mp4ff_atom_compare(a,b,c,d, 'm','o','o','v'))
+            return ATOM_MOOV;
+        else if (mp4ff_atom_compare(a,b,c,d, 'm','i','n','f'))
+            return ATOM_MINF;
+        else if (mp4ff_atom_compare(a,b,c,d, 'm','d','i','a'))
+            return ATOM_MDIA;
+        else if (mp4ff_atom_compare(a,b,c,d, 'm','d','a','t'))
+            return ATOM_MDAT;
+        else if (mp4ff_atom_compare(a,b,c,d, 'm','d','h','d'))
+            return ATOM_MDHD;
+        else if (mp4ff_atom_compare(a,b,c,d, 'm','v','h','d'))
+            return ATOM_MVHD;
+        else if (mp4ff_atom_compare(a,b,c,d, 'm','p','4','a'))
+            return ATOM_MP4A;
+        else if (mp4ff_atom_compare(a,b,c,d, 'm','p','4','v'))
+            return ATOM_MP4V;
+        else if (mp4ff_atom_compare(a,b,c,d, 'm','p','4','s'))
+            return ATOM_MP4S;
+    } else if (a == 't') {
+        if (mp4ff_atom_compare(a,b,c,d, 't','r','a','k'))
+            return ATOM_TRAK;
+        else if (mp4ff_atom_compare(a,b,c,d, 't','k','h','d'))
+            return ATOM_TKHD;
+        else if (mp4ff_atom_compare(a,b,c,d, 't','r','e','f'))
+            return ATOM_TREF;
+    } else if (a == 's') {
+        if (mp4ff_atom_compare(a,b,c,d, 's','t','b','l'))
+            return ATOM_STBL;
+        else if (mp4ff_atom_compare(a,b,c,d, 's','m','h','d'))
+            return ATOM_SMHD;
+        else if (mp4ff_atom_compare(a,b,c,d, 's','t','s','d'))
+            return ATOM_STSD;
+        else if (mp4ff_atom_compare(a,b,c,d, 's','t','t','s'))
+            return ATOM_STTS;
+        else if (mp4ff_atom_compare(a,b,c,d, 's','t','c','o'))
+            return ATOM_STCO;
+        else if (mp4ff_atom_compare(a,b,c,d, 's','t','s','c'))
+            return ATOM_STSC;
+        else if (mp4ff_atom_compare(a,b,c,d, 's','t','s','z'))
+            return ATOM_STSZ;
+        else if (mp4ff_atom_compare(a,b,c,d, 's','t','z','2'))
+            return ATOM_STZ2;
+        else if (mp4ff_atom_compare(a,b,c,d, 's','k','i','p'))
+            return ATOM_SKIP;
+    }
+
+    if (mp4ff_atom_compare(a,b,c,d, 'e','d','t','s'))
+        return ATOM_EDTS;
+    else if (mp4ff_atom_compare(a,b,c,d, 'e','s','d','s'))
+        return ATOM_ESDS;
+    else if (mp4ff_atom_compare(a,b,c,d, 'f','t','y','p'))
+        return ATOM_FTYP;
+    else if (mp4ff_atom_compare(a,b,c,d, 'f','r','e','e'))
+        return ATOM_FREE;
+    else if (mp4ff_atom_compare(a,b,c,d, 'h','m','h','d'))
+        return ATOM_HMHD;
+    else if (mp4ff_atom_compare(a,b,c,d, 'v','m','h','d'))
+        return ATOM_VMHD;
+    else
+        return ATOM_UNKNOWN;
+}
+
+/* read atom header, return atom size, atom size is with header included */
+int32_t mp4ff_atom_read_header(mp4ff_t *f, uint8_t *atom_type)
+{
+    int32_t size;
+    int32_t ret;
+    int8_t atom_header[8];
+
+    ret = mp4ff_read_data(f, atom_header, 8);
+    if (ret != 8)
+        return 0;
+
+    size = mp4ff_atom_get_size(atom_header);
+
+    //fprintf(stdout, "%c%c%c%c\n", atom_header[4], atom_header[5], atom_header[6], atom_header[7]);
+
+    *atom_type = mp4ff_atom_name_to_type(atom_header[4], atom_header[5], atom_header[6], atom_header[7]);
+
+    return size;
+}
+
+
+int32_t mp4ff_read_stsz(mp4ff_t *f)
+{
+    /* version */ mp4ff_read_char(f);
+    /* flags */ mp4ff_read_int24(f);
+    f->track[f->total_tracks - 1]->stsz_sample_size = mp4ff_read_int32(f);
+    f->track[f->total_tracks - 1]->stsz_sample_count = mp4ff_read_int32(f);
+
+    if (f->track[f->total_tracks - 1]->stsz_sample_size == 0)
+    {
+        int32_t i;
+        f->track[f->total_tracks - 1]->stsz_table =
+            (int32_t*)malloc(f->track[f->total_tracks - 1]->stsz_sample_count*sizeof(int32_t));
+
+        for (i = 0; i < f->track[f->total_tracks - 1]->stsz_sample_count; i++)
+        {
+            f->track[f->total_tracks - 1]->stsz_table[i] = mp4ff_read_int32(f);
+        }
+    }
+
+    return 0;
+}
+
+int32_t mp4ff_read_esds(mp4ff_t *f)
+{
+    uint8_t tag;
+
+    mp4ff_read_char(f); /* version */
+    mp4ff_read_int24(f); /* flags */
+
+    /* get and verify ES_DescrTag */
+    tag = mp4ff_read_char(f);
+    if (tag == 0x03)
+    {
+        /* read length */
+        if (mp4ff_read_mp4_descr_length(f) < 5 + 15)
+        {
+            return 1;
+        }
+        /* skip 3 bytes */
+        mp4ff_read_int24(f);
+    } else {
+        /* skip 2 bytes */
+        mp4ff_read_int16(f);
+    }
+
+    /* get and verify DecoderConfigDescrTab */
+    if (mp4ff_read_char(f) != 0x04)
+    {
+        return 1;
+    }
+
+    /* read length */
+    if (mp4ff_read_mp4_descr_length(f) < 15)
+    {
+        return 1;
+    }
+
+    /* skip 13 bytes */
+    mp4ff_read_int32(f);
+    mp4ff_read_int32(f);
+    mp4ff_read_int32(f);
+    mp4ff_read_char(f);
+
+    /* get and verify DecSpecificInfoTag */
+    if (mp4ff_read_char(f) != 0x05)
+    {
+        return 1;
+    }
+
+    /* read length */
+    f->track[f->total_tracks - 1]->decoderConfigLen = mp4ff_read_mp4_descr_length(f); 
+
+    if (f->track[f->total_tracks - 1]->decoderConfig)
+        free(f->track[f->total_tracks - 1]->decoderConfig);
+    f->track[f->total_tracks - 1]->decoderConfig = malloc(f->track[f->total_tracks - 1]->decoderConfigLen);
+    if (f->track[f->total_tracks - 1]->decoderConfig)
+    {
+        mp4ff_read_data(f, f->track[f->total_tracks - 1]->decoderConfig, f->track[f->total_tracks - 1]->decoderConfigLen);
+    } else {
+        f->track[f->total_tracks - 1]->decoderConfigLen = 0;
+    }
+
+    /* will skip the remainder of the atom */
+    return 0;
+}
+
+int32_t mp4ff_read_mp4a(mp4ff_t *f)
+{
+    int32_t i, size;
+    uint8_t atom_type = 0;
+
+    for (i = 0; i < 6; i++)
+    {
+        mp4ff_read_char(f); /* reserved */
+    }
+    /* data_reference_index */ mp4ff_read_int16(f);
+
+    mp4ff_read_int32(f); /* reserved */
+    mp4ff_read_int32(f); /* reserved */
+
+    f->track[f->total_tracks - 1]->channelCount = mp4ff_read_int16(f);
+    f->track[f->total_tracks - 1]->sampleSize = mp4ff_read_int16(f);
+
+    mp4ff_read_int16(f);
+    mp4ff_read_int16(f);
+
+    f->track[f->total_tracks - 1]->sampleRate = mp4ff_read_int16(f);
+
+    mp4ff_read_int16(f);
+
+    size = mp4ff_atom_read_header(f, &atom_type);
+    if (atom_type == ATOM_ESDS)
+    {
+        mp4ff_read_esds(f);
+    }
+
+    return 0;
+}
+
+int32_t mp4ff_read_stsd(mp4ff_t *f)
+{
+    int32_t i;
+
+    mp4ff_read_char(f); /* version */
+    mp4ff_read_int24(f); /* flags */
+
+    f->track[f->total_tracks - 1]->stsd_entry_count = mp4ff_read_int32(f);
+
+    for (i = 0; i < f->track[f->total_tracks - 1]->stsd_entry_count; i++)
+    {
+        int32_t skip = mp4ff_position(f);
+        int32_t size;
+        uint8_t atom_type = 0;
+        size = mp4ff_atom_read_header(f, &atom_type);
+        skip += size;
+
+        if (atom_type == ATOM_MP4A)
+        {
+            f->track[f->total_tracks - 1]->type = TRACK_AUDIO;
+            mp4ff_read_mp4a(f);
+        } else if (atom_type == ATOM_MP4V) {
+            f->track[f->total_tracks - 1]->type = TRACK_VIDEO;
+        } else if (atom_type == ATOM_MP4S) {
+            f->track[f->total_tracks - 1]->type = TRACK_SYSTEM;
+        } else {
+            f->track[f->total_tracks - 1]->type = TRACK_UNKNOWN;
+        }
+
+        mp4ff_set_position(f, skip);
+    }
+
+    return 0;
+}
+
+int32_t mp4ff_read_stsc(mp4ff_t *f)
+{
+    int32_t i;
+
+    mp4ff_read_char(f); /* version */ 
+    mp4ff_read_int24(f); /* flags */ 
+    f->track[f->total_tracks - 1]->stsc_entry_count = mp4ff_read_int32(f);
+
+    f->track[f->total_tracks - 1]->stsc_first_chunk =
+        (int32_t*)malloc(f->track[f->total_tracks - 1]->stsc_entry_count*sizeof(int32_t));
+    f->track[f->total_tracks - 1]->stsc_samples_per_chunk =
+        (int32_t*)malloc(f->track[f->total_tracks - 1]->stsc_entry_count*sizeof(int32_t));
+    f->track[f->total_tracks - 1]->stsc_sample_desc_index =
+        (int32_t*)malloc(f->track[f->total_tracks - 1]->stsc_entry_count*sizeof(int32_t));
+
+    for (i = 0; i < f->track[f->total_tracks - 1]->stsc_entry_count; i++)
+    {
+        f->track[f->total_tracks - 1]->stsc_first_chunk[i] = mp4ff_read_int32(f);
+        f->track[f->total_tracks - 1]->stsc_samples_per_chunk[i] = mp4ff_read_int32(f);
+        f->track[f->total_tracks - 1]->stsc_sample_desc_index[i] = mp4ff_read_int32(f);
+    }
+
+    return 0;
+}
+
+int32_t mp4ff_read_stco(mp4ff_t *f)
+{
+    int32_t i;
+
+    /* version */ mp4ff_read_char(f);
+    /* flags */ mp4ff_read_int24(f);
+    f->track[f->total_tracks - 1]->stco_entry_count = mp4ff_read_int32(f);
+
+    f->track[f->total_tracks - 1]->stco_chunk_offset =
+        (int32_t*)malloc(f->track[f->total_tracks - 1]->stco_entry_count*sizeof(int32_t));
+
+    for (i = 0; i < f->track[f->total_tracks - 1]->stco_entry_count; i++)
+    {
+        f->track[f->total_tracks - 1]->stco_chunk_offset[i] = mp4ff_read_int32(f);
+    }
+
+    return 0;
+}
+
+int32_t mp4ff_read_stts(mp4ff_t *f)
+{
+    int32_t i;
+
+    /* version */ mp4ff_read_char(f);
+    /* flags */ mp4ff_read_int24(f);
+    f->track[f->total_tracks - 1]->stts_entry_count = mp4ff_read_int32(f);
+
+    f->track[f->total_tracks - 1]->stts_sample_count = (int32_t*)malloc(f->track[f->total_tracks - 1]->stts_entry_count * sizeof(int32_t));
+    f->track[f->total_tracks - 1]->stts_sample_delta = (int32_t*)malloc(f->track[f->total_tracks - 1]->stts_entry_count * sizeof(int32_t));
+
+    for (i = 0; i < f->track[f->total_tracks - 1]->stts_entry_count; i++)
+    {
+        f->track[f->total_tracks - 1]->stts_sample_count[i] = mp4ff_read_int32(f);
+        f->track[f->total_tracks - 1]->stts_sample_delta[i] = mp4ff_read_int32(f);
+    }
+
+    return 0;
+}
+
+int32_t mp4ff_read_mvhd(mp4ff_t *f)
+{
+    int32_t i;
+
+    /* version */ mp4ff_read_char(f);
+    /* flags */ mp4ff_read_int24(f);
+    /* creation_time */ mp4ff_read_int32(f);
+    /* modification_time */ mp4ff_read_int32(f);
+    f->time_scale = mp4ff_read_int32(f);
+    f->duration = mp4ff_read_int32(f);
+    /* preferred_rate */ mp4ff_read_int32(f); /*mp4ff_read_fixed32(f);*/
+    /* preferred_volume */ mp4ff_read_int16(f); /*mp4ff_read_fixed16(f);*/
+    for (i = 0; i < 10; i++)
+    {
+        /* reserved */ mp4ff_read_char(f);
+    }
+    for (i = 0; i < 9; i++)
+    {
+        mp4ff_read_int32(f); /* matrix */
+    }
+    /* preview_time */ mp4ff_read_int32(f);
+    /* preview_duration */ mp4ff_read_int32(f);
+    /* poster_time */ mp4ff_read_int32(f);
+    /* selection_time */ mp4ff_read_int32(f);
+    /* selection_duration */ mp4ff_read_int32(f);
+    /* current_time */ mp4ff_read_int32(f);
+    /* next_track_id */ mp4ff_read_int32(f);
+
+    return 0;
+}
+
+int32_t mp4ff_atom_read(mp4ff_t *f, int32_t size, int8_t atom_type)
+{
+    if (atom_type == ATOM_STSZ)
+    {
+        /* sample size box */
+        mp4ff_read_stsz(f);
+    } else if (atom_type == ATOM_STTS) {
+        /* time to sample box */
+        mp4ff_read_stts(f);
+    } else if (atom_type == ATOM_STSC) {
+        /* sample to chunk box */
+        mp4ff_read_stsc(f);
+    } else if (atom_type == ATOM_STCO) {
+        /* chunk offset box */
+        mp4ff_read_stco(f);
+    } else if (atom_type == ATOM_STSD) {
+        /* sample description box */
+        mp4ff_read_stsd(f);
+    } else if (atom_type == ATOM_MVHD) {
+        /* movie header box */
+        mp4ff_read_mvhd(f);
+    } else {
+        /* skip this atom: not needed for reading */
+        mp4ff_set_position(f, mp4ff_position(f)+size-8);
+    }
+
+    return 0;
+}
--- a/common/mp4ff/mp4ff.c
+++ b/common/mp4ff/mp4ff.c
@@ -1,1256 +1,249 @@
+/*
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
+** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program 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 General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** Any non-GPL usage of this software or parts of this software is strictly
+** forbidden.
+**
+** Commercial non-GPL licensing of this software is possible.
+** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+**
+** $Id: mp4ff.c,v 1.2 2003/11/21 15:08:48 menno Exp $
+**/
+
+#include <stdlib.h>
+#include <string.h>
 #include "mp4ff.h"
 
-#if 0
-int mp4ff_make_streamable(mp4_callback_t *in_path, mp4_callback_t *out_path)
+mp4ff_t *mp4ff_open_read(mp4ff_callback_t *f)
 {
-	mp4ff_t file, *old_file, new_file;
-	int moov_exists = 0, mdat_exists = 0, result, atoms = 1;
-	long mdat_start, mdat_size;
-	mp4ff_atom_t leaf_atom;
-	long moov_length;
+    mp4ff_t *ff = malloc(sizeof(mp4ff_t));
 
-	mp4ff_init(&file);
+    memset(ff, 0, sizeof(mp4ff_t));
 
-/* find the moov atom in the old file */
-	
-	if(!(file.stream = FOPEN(in_path, _T("rb"))))
-	{
-		//perror("mp4ff_make_streamable");
-		return 1;
-	}
+    ff->stream = f;
 
-	file.total_length = file.stream->get_length();
+    parse_atoms(ff);
 
-/* get the locations of moov and mdat atoms */
-	do
-	{
-/*printf("%x\n", mp4ff_position(&file)); */
-		result = mp4ff_atom_read_header(&file, &leaf_atom);
-
-		if(!result)
-		{
-			if(mp4ff_atom_is(&leaf_atom, "moov"))
-			{
-				moov_exists = atoms;
-				moov_length = leaf_atom.size;
-			}
-			else
-			if(mp4ff_atom_is(&leaf_atom, "mdat"))
-			{
-				mdat_start = mp4ff_position(&file) - HEADER_LENGTH;
-				mdat_size = leaf_atom.size;
-				mdat_exists = atoms;
-			}
-
-			mp4ff_atom_skip(&file, &leaf_atom);
-
-			atoms++;
-		}
-	}while(!result && mp4ff_position(&file) < file.total_length);
-
-	if(!moov_exists)
-	{
-		printf("mp4ff_make_streamable: no moov atom\n");
-		return 1;
-	}
-
-	if(!mdat_exists)
-	{
-		printf("mp4ff_make_streamable: no mdat atom\n");
-		return 1;
-	}
-
-/* copy the old file to the new file */
-	if(moov_exists && mdat_exists)
-	{
-/* moov wasn't the first atom */
-		if(moov_exists > 1)
-		{
-			char *buffer;
-			long buf_size = 1000000;
-
-			result = 0;
-
-/* read the header proper */
-			if(!(old_file = mp4ff_open(in_path, 1, 0, 0)))
-			{
-				return 1;
-			}
-
-			mp4ff_shift_offsets(&(old_file->moov), moov_length);
-
-/* open the output file */
-			if(!(new_file.stream = FOPEN(out_path, _T("wb"))))
-			{
-				//perror("mp4ff_make_streamable");
-				result =  1;
-			}
-			else
-			{
-/* set up some flags */
-				new_file.wr = 1;
-				new_file.rd = 0;
-				mp4ff_write_moov(&new_file, &(old_file->moov));
-
-				mp4ff_set_position(old_file, mdat_start);
-
-				if(!(buffer = calloc(1, buf_size)))
-				{
-					result = 1;
-					printf("mp4ff_make_streamable: out of memory\n");
-				}
-				else
-				{
-					while(mp4ff_position(old_file) < mdat_start + mdat_size && !result)
-					{
-						if(mp4ff_position(old_file) + buf_size > mdat_start + mdat_size)
-							buf_size = mdat_start + mdat_size - mp4ff_position(old_file);
-
-						if(!mp4ff_read_data(old_file, buffer, buf_size)) result = 1;
-						if(!result)
-						{
-							if(!mp4ff_write_data(&new_file, buffer, buf_size)) result = 1;
-						}
-					}
-					free(buffer);
-				}
-				fclose(new_file.stream);
-			}
-			mp4ff_close(old_file);
-		}
-		else
-		{
-			printf("mp4ff_make_streamable: header already at 0 offset\n");
-			return 0;
-		}
-	}
-	
-	return 0;
+    return ff;
 }
-#endif
 
-int mp4ff_set_time_scale(mp4ff_t *file, int time_scale)
+void mp4ff_close(mp4ff_t *ff)
 {
-	file->moov.mvhd.time_scale = time_scale;
-}
+    int32_t i;
 
-int mp4ff_set_copyright(mp4ff_t *file, char *string)
-{
-	mp4ff_set_udta_string(&(file->moov.udta.copyright), &(file->moov.udta.copyright_len), string);
-}
+    for (i = 0; i < ff->total_tracks; i++)
+    {
+        if (ff->track[i])
+        {
+            if (ff->track[i]->stsz_table)
+                free(ff->track[i]->stsz_table);
+            if (ff->track[i]->stts_sample_count)
+                free(ff->track[i]->stts_sample_count);
+            if (ff->track[i]->stts_sample_delta)
+                free(ff->track[i]->stts_sample_delta);
+            if (ff->track[i]->stsc_first_chunk)
+                free(ff->track[i]->stsc_first_chunk);
+            if (ff->track[i]->stsc_samples_per_chunk)
+                free(ff->track[i]->stsc_samples_per_chunk);
+            if (ff->track[i]->stsc_sample_desc_index)
+                free(ff->track[i]->stsc_sample_desc_index);
+            if (ff->track[i]->stco_chunk_offset)
+                free(ff->track[i]->stco_chunk_offset);
+            if (ff->track[i]->decoderConfig)
+                free(ff->track[i]->decoderConfig);
+            free(ff->track[i]);
+        }
+    }
 
-int mp4ff_set_name(mp4ff_t *file, char *string)
-{
-	mp4ff_set_udta_string(&(file->moov.udta.name), &(file->moov.udta.name_len), string);
+    if (ff) free(ff);
 }
 
-int mp4ff_set_info(mp4ff_t *file, char *string)
-{
-	mp4ff_set_udta_string(&(file->moov.udta.info), &(file->moov.udta.info_len), string);
-}
 
-int mp4ff_get_time_scale(mp4ff_t *file)
-{
-	return file->moov.mvhd.time_scale;
-}
 
-char* mp4ff_get_copyright(mp4ff_t *file)
+void mp4ff_track_add(mp4ff_t *f)
 {
-	return file->moov.udta.copyright;
-}
+    f->total_tracks++;
 
-char* mp4ff_get_name(mp4ff_t *file)
-{
-	return file->moov.udta.name;
-}
+    f->track[f->total_tracks - 1] = malloc(sizeof(mp4ff_track_t));
 
-char* mp4ff_get_info(mp4ff_t *file)
-{
-	return file->moov.udta.info;
+    memset(f->track[f->total_tracks - 1], 0, sizeof(mp4ff_track_t));
 }
 
-int mp4ff_get_iod_audio_profile_level(mp4ff_t *file)
+/* parse atoms that are sub atoms of other atoms */
+int32_t parse_sub_atoms(mp4ff_t *f, int32_t total_size)
 {
-	return file->moov.iods.audioProfileId;
-}
+    int32_t size;
+    uint8_t atom_type = 0;
+    int32_t counted_size = 0;
 
-int mp4ff_set_iod_audio_profile_level(mp4ff_t *file, int id)
-{
-	mp4ff_iods_set_audio_profile(&file->moov.iods, id);
-}
+    while (counted_size < total_size)
+    {
+        size = mp4ff_atom_read_header(f, &atom_type);
+        counted_size += size;
 
-int mp4ff_get_iod_video_profile_level(mp4ff_t *file)
-{
-	return file->moov.iods.videoProfileId;
-}
+        /* check for end of file */
+        if (size == 0)
+            break;
 
-int mp4ff_set_iod_video_profile_level(mp4ff_t *file, int id)
-{
-	mp4ff_iods_set_video_profile(&file->moov.iods, id);
-}
+        /* we're starting to read a new track, update index,
+         * so that all data and tables get written in the right place
+         */
+        if (atom_type == ATOM_TRAK)
+        {
+            mp4ff_track_add(f);
+        }
 
-int mp4ff_video_tracks(mp4ff_t *file)
-{
-	int i, result = 0;
-	for(i = 0; i < file->moov.total_tracks; i++)
-	{
-		if(file->moov.trak[i]->mdia.minf.is_video) result++;
-	}
-	return result;
-}
+        /* parse subatoms */
+        if (atom_type < SUBATOMIC)
+        {
+            parse_sub_atoms(f, size-8);
+        } else {
+            mp4ff_atom_read(f, size, atom_type);
+        }
+    }
 
-int mp4ff_audio_tracks(mp4ff_t *file)
-{
-	int i, result = 0;
-	mp4ff_minf_t *minf;
-	for(i = 0; i < file->moov.total_tracks; i++)
-	{
-		minf = &(file->moov.trak[i]->mdia.minf);
-		if(minf->is_audio)
-			result++;
-	}
-	return result;
+    return 0;
 }
 
-int mp4ff_set_audio(mp4ff_t *file, 
-						int channels,
-						long sample_rate,
-						int bits,
-						int sample_size,
-						int time_scale,
-						int sample_duration,	
-						char *compressor)
+/* parse root atoms */
+int32_t parse_atoms(mp4ff_t *f)
 {
-	int i, j;
-	mp4ff_trak_t *trak;
+    int32_t size;
+    uint8_t atom_type = 0;
 
-	/* delete any existing tracks */
-	for(i = 0; i < file->total_atracks; i++) {
-		mp4ff_delete_audio_map(&(file->atracks[i]));
-		mp4ff_delete_trak(&(file->moov), file->atracks[i].track);
-	}
-	free(file->atracks);
-	file->atracks = NULL;	
-	file->total_atracks = 0;
-
-	if(channels) {
-#if 0
-		/* Fake the bits parameter for some formats. */
-		if(mp4ff_match_32(compressor, mp4ff_ULAW) ||
-			mp4ff_match_32(compressor, mp4ff_IMA4)) bits = 16;
-#endif
-
-		file->atracks = (mp4ff_audio_map_t*)
-			calloc(1, sizeof(mp4ff_audio_map_t));
-		trak = mp4ff_add_track(&(file->moov));
-		mp4ff_trak_init_audio(file, trak, channels, sample_rate, bits, 
-			sample_size, time_scale, sample_duration, compressor);
-		mp4ff_init_audio_map(&(file->atracks[0]), trak);
-		file->atracks[file->total_atracks].track = trak;
-		file->atracks[file->total_atracks].channels = channels;
-		file->atracks[file->total_atracks].current_position = 0;
-		file->atracks[file->total_atracks].current_chunk = 1;
-		file->total_atracks++;
-	}
-	return 1;   /* Return the number of tracks created */
-}
-
-int mp4ff_set_video(mp4ff_t *file, 
-						int tracks, 
-						int frame_w, 
-						int frame_h,
-						float frame_rate,
-						int time_scale,
-						char *compressor)
-{
-	int i, j;
-	mp4ff_trak_t *trak;
-
-	/* delete any existing tracks */
-	for(i = 0; i < file->total_vtracks; i++) {
-		mp4ff_delete_video_map(&(file->vtracks[i]));
-		mp4ff_delete_trak(&(file->moov), file->vtracks[i].track);
-	}
-	free(file->vtracks);
-	file->vtracks = NULL;	
-	file->total_vtracks = 0;
-
-	if (tracks > 0) {
-		file->total_vtracks = tracks;
-		file->vtracks = (mp4ff_video_map_t*)calloc(1, sizeof(mp4ff_video_map_t) * file->total_vtracks);
-		for(i = 0; i < tracks; i++)
-		{
-			trak = mp4ff_add_track(&(file->moov));
-			mp4ff_trak_init_video(file, trak, frame_w, frame_h, frame_rate,
-				time_scale, compressor);
-			mp4ff_init_video_map(&(file->vtracks[i]), trak);
-		}
-	}
-	return 0;
-}
-
-int mp4ff_set_framerate(mp4ff_t *file, float framerate)
-{
-	int i;
-	int new_time_scale, new_sample_duration;
-	new_time_scale = mp4ff_get_timescale(framerate);
-	new_sample_duration = (int)((float)new_time_scale / framerate + 0.5);
-
-	for(i = 0; i < file->total_vtracks; i++)
-	{
-		file->vtracks[i].track->mdia.mdhd.time_scale = new_time_scale;
-		file->vtracks[i].track->mdia.minf.stbl.stts.table[0].sample_duration = new_sample_duration;
-	}
-}
-
-mp4ff_trak_t* mp4ff_add_track(mp4ff_moov_t *moov)
-{
-	mp4ff_trak_t *trak;
-	trak = moov->trak[moov->total_tracks] = calloc(1, sizeof(mp4ff_trak_t));
-	mp4ff_trak_init(trak);
-	trak->tkhd.track_id = moov->mvhd.next_track_id;
-	moov->mvhd.next_track_id++;
-	moov->total_tracks++;
-	return trak;
-}
-
-/* ============================= Initialization functions */
-
-int mp4ff_init(mp4ff_t *file)
-{
-	memset(file, 0, sizeof(mp4ff_t));
-	mp4ff_mdat_init(&(file->mdat));
-	mp4ff_moov_init(&(file->moov));
-	return 0;
-}
-
-int mp4ff_delete(mp4ff_t *file)
-{
-	int i;
-	if(file->total_atracks) 
-	{
-		for(i = 0; i < file->total_atracks; i++)
-			mp4ff_delete_audio_map(&(file->atracks[i]));
-		free(file->atracks);
-	}
-	if(file->total_vtracks)
-	{
-		for(i = 0; i < file->total_vtracks; i++)
-			mp4ff_delete_video_map(&(file->vtracks[i]));
-		free(file->vtracks);
-	}
-	file->total_atracks = 0;
-	file->total_vtracks = 0;
-	mp4ff_moov_delete(&(file->moov));
-	mp4ff_mdat_delete(&(file->mdat));
-	return 0;
-}
-
-/* =============================== Optimization functions */
-
-int mp4ff_get_timescale(float frame_rate)
-{
-	int timescale = 600;
-/* Encode the 29.97, 23.976, 59.94 framerates as per DV freaks */
-	if(frame_rate - (int)frame_rate != 0) timescale = (int)(frame_rate * 1001 + 0.5);
-	else
-	if((600 / frame_rate) - (int)(600 / frame_rate) != 0) timescale = (int)(frame_rate * 100 + 0.5);
-	return timescale;
-}
-
-int mp4ff_seek_end(mp4ff_t *file)
-{
-	mp4ff_set_position(file, file->mdat.size + file->mdat.start);
-/*printf("mp4ff_seek_end %ld\n", file->mdat.size + file->mdat.start); */
-	mp4ff_update_positions(file);
-	return 0;
-}
-
-int mp4ff_seek_start(mp4ff_t *file)
-{
-	mp4ff_set_position(file, file->mdat.start + HEADER_LENGTH);
-	mp4ff_update_positions(file);
-	return 0;
-}
-
-long mp4ff_audio_length(mp4ff_t *file, int track)
-{
-	if(file->total_atracks > 0) 
-		return mp4ff_track_samples(file, file->atracks[track].track);
-
-	return 0;
-}
-
-long mp4ff_video_length(mp4ff_t *file, int track)
-{
-/*printf("mp4ff_video_length %d %d\n", mp4ff_track_samples(file, file->vtracks[track].track), track); */
-	if(file->total_vtracks > 0)
-		return mp4ff_track_samples(file, file->vtracks[track].track);
-	return 0;
-}
-
-long mp4ff_audio_position(mp4ff_t *file, int track)
-{
-	return file->atracks[track].current_position;
-}
-
-long mp4ff_video_position(mp4ff_t *file, int track)
-{
-	return file->vtracks[track].current_position;
-}
-
-int mp4ff_update_positions(mp4ff_t *file)
-{
-/* Used for routines that change the positions of all tracks, like */
-/* seek_end and seek_start but not for routines that reposition one track, like */
-/* set_audio_position. */
-
-	long mdat_offset = mp4ff_position(file) - file->mdat.start;
-	long sample, chunk, chunk_offset;
-	int i;
-
-	if(file->total_atracks)
-	{
-		sample = mp4ff_offset_to_sample(file->atracks[0].track, mdat_offset);
-		chunk = mp4ff_offset_to_chunk(&chunk_offset, file->atracks[0].track, mdat_offset);
-		for(i = 0; i < file->total_atracks; i++)
-		{
-			file->atracks[i].current_position = sample;
-			file->atracks[i].current_chunk = chunk;
-		}
-	}
-
-	if(file->total_vtracks)
-	{
-		sample = mp4ff_offset_to_sample(file->vtracks[0].track, mdat_offset);
-		chunk = mp4ff_offset_to_chunk(&chunk_offset, file->vtracks[0].track, mdat_offset);
-		for(i = 0; i < file->total_vtracks; i++)
-		{
-			file->vtracks[i].current_position = sample;
-			file->vtracks[i].current_chunk = chunk;
-		}
-	}
-	return 0;
-}
-
-int mp4ff_set_audio_position(mp4ff_t *file, long sample, int track)
-{
-	long offset, chunk_sample, chunk;
-	mp4ff_trak_t *trak;
-
-	if(file->total_atracks)
-	{
-		trak = file->atracks[track].track;
-		file->atracks[track].current_position = sample;
-		mp4ff_chunk_of_sample(&chunk_sample, &chunk, trak, sample);
-		file->atracks[track].current_chunk = chunk;
-		offset = mp4ff_sample_to_offset(trak, sample);
-		mp4ff_set_position(file, offset);
-		/*mp4ff_update_positions(file); */
-	}
-
-	return 0;
-}
-
-int mp4ff_set_video_position(mp4ff_t *file, long frame, int track)
-{
-	long offset, chunk_sample, chunk;
-	mp4ff_trak_t *trak;
-
-	if(file->total_vtracks)
-	{
-		trak = file->vtracks[track].track;
-		file->vtracks[track].current_position = frame;
-		mp4ff_chunk_of_sample(&chunk_sample, &chunk, trak, frame);
-		file->vtracks[track].current_chunk = chunk;
-		offset = mp4ff_sample_to_offset(trak, frame);
-		mp4ff_set_position(file, offset);
-		/*mp4ff_update_positions(file); */
-	}
-	return 0;
-}
-
-int mp4ff_has_audio(mp4ff_t *file)
-{
-	if(mp4ff_audio_tracks(file)) return 1;
-	return 0;
-}
-
-long mp4ff_audio_sample_rate(mp4ff_t *file, int track)
-{
-	if(file->total_atracks)
-		return file->atracks[track].track->mdia.minf.stbl.stsd.table[0].sample_rate;
-	return 0;
-}
-
-int mp4ff_audio_bits(mp4ff_t *file, int track)
-{
-	if(file->total_atracks)
-		return file->atracks[track].track->mdia.minf.stbl.stsd.table[0].sample_size;
-
-	return 0;
-}
-
-int mp4ff_audio_time_scale(mp4ff_t *file, int track)
-{
-	if(file->total_atracks) {
-		return file->atracks[track].track->mdia.mdhd.time_scale;
-	}
-	return 0;
-}
-
-int mp4ff_audio_sample_duration(mp4ff_t *file, int track)
-{
-	if(file->total_atracks) {
-		return file->atracks[track].track->mdia.minf.stbl.stts.table[0].sample_duration;
-	}
-	return 0;
-}
-
-char* mp4ff_audio_compressor(mp4ff_t *file, int track)
-{
-  if (file->atracks[track].track == NULL)
-    return (NULL);
-	return file->atracks[track].track->mdia.minf.stbl.stsd.table[0].format;
-}
-
-int mp4ff_track_channels(mp4ff_t *file, int track)
-{
-	if(track < file->total_atracks)
-		return file->atracks[track].channels;
-
-	return 0;
-}
-
-int mp4ff_channel_location(mp4ff_t *file, int *mp4ff_track, int *mp4ff_channel, int channel)
-{
-	int current_channel = 0, current_track = 0;
-	*mp4ff_channel = 0;
-	*mp4ff_track = 0;
-	for(current_channel = 0, current_track = 0; current_track < file->total_atracks; )
-	{
-		if(channel >= current_channel)
-		{
-			*mp4ff_channel = channel - current_channel;
-			*mp4ff_track = current_track;
-		}
-
-		current_channel += file->atracks[current_track].channels;
-		current_track++;
-	}
-	return 0;
-}
-
-int mp4ff_has_video(mp4ff_t *file)
-{
-	if(mp4ff_video_tracks(file)) return 1;
-	return 0;
-}
-
-int mp4ff_video_width(mp4ff_t *file, int track)
-{
-	if(file->total_vtracks) {
-		int width = 
-			file->vtracks[track].track->mdia.minf.stbl.stsd.table[0].width;
-		if (width) {
-			return width;
-		}
-		return file->vtracks[track].track->tkhd.track_width;
-	}
-	return 0;
-}
-
-int mp4ff_video_height(mp4ff_t *file, int track)
-{
-	if(file->total_vtracks) {
-		int height = file->vtracks[track].track->mdia.minf.stbl.stsd.table[0].height;
-		if (height) {
-			return height;
-		}
-		return file->vtracks[track].track->tkhd.track_height;
-	}
-	return 0;
-}
+    while ((size = mp4ff_atom_read_header(f, &atom_type)) != 0)
+    {
+        if (atom_type == ATOM_MDAT && f->moov_read)
+        {
+            /* moov atom is before mdat, we can stop reading when mdat is encountered */
+            /* file position will stay at beginning of mdat data */
+            break;
+        }
 
-int mp4ff_video_depth(mp4ff_t *file, int track)
-{
-	if(file->total_vtracks)
-		return file->vtracks[track].track->mdia.minf.stbl.stsd.table[0].depth;
-	return 0;
-}
+        if (atom_type == ATOM_MDAT && size > 8)
+        {
+            f->mdat_read = 1;
+            f->mdat_offset = mp4ff_position(f);
+            f->mdat_size = size;
+        }
+        if (atom_type == ATOM_MOOV && size > 8)
+        {
+            f->moov_read = 1;
+            f->moov_offset = mp4ff_position(f);
+            f->moov_size = size;
+        }
 
-int mp4ff_set_depth(mp4ff_t *file, int depth, int track)
-{
-	int i;
+        /* parse subatoms */
+        if (atom_type < SUBATOMIC)
+        {
+            parse_sub_atoms(f, size-8);
+        } else {
+            /* skip this atom */
+            mp4ff_set_position(f, mp4ff_position(f)+size-8);
+        }
+    }
 
-	for(i = 0; i < file->total_vtracks; i++)
-	{
-		file->vtracks[i].track->mdia.minf.stbl.stsd.table[0].depth = depth;
-	}
-}
-
-float mp4ff_video_frame_rate(mp4ff_t *file, int track)
-{
-  float ret = 0;
-  int num = 0;
-  
-  if(file->total_vtracks) {
-    ret = file->vtracks[track].track->mdia.mdhd.time_scale;
-    if (file->vtracks[track].track->mdia.minf.stbl.stts.table[0].sample_duration == 0)
-      num = 1;
-    ret /= 
-	file->vtracks[track].track->mdia.minf.stbl.stts.table[num].sample_duration;
-  }
-  return ret;
-}
-
-char* mp4ff_video_compressor(mp4ff_t *file, int track)
-{
-  if (file->vtracks[track].track == NULL)
-    return (NULL);
-  
-	return file->vtracks[track].track->mdia.minf.stbl.stsd.table[0].format;
-}
-
-int mp4ff_video_time_scale(mp4ff_t *file, int track)
-{
-	if(file->total_vtracks) {
-		return file->vtracks[track].track->mdia.mdhd.time_scale;
-	}
-	return 0;
-}
-
-int mp4ff_video_frame_time(mp4ff_t *file, int track, long frame,
-	long *start, int *duration)
-{
-	mp4ff_stts_t *stts;
-	int i;
-	long f;
-
-	if (file->total_vtracks == 0) {
-		return 0;
-	}
-	stts = &(file->vtracks[track].track->mdia.minf.stbl.stts);
-
-	if (frame < file->last_frame) {
-		/* we need to reset our cached values */
-		file->last_frame = 0;
-		file->last_start = 0;
-		file->last_stts_index = 0;
-	}
-
-	i = file->last_stts_index;
-	f = file->last_frame;
-	*start = file->last_start;
-
-	while (i < stts->total_entries) {
-		if (f + stts->table[i].sample_count <= frame) {
-			*start += stts->table[i].sample_duration 
-				* stts->table[i].sample_count;
-			f += stts->table[i].sample_count;
-			i++;
-
-		} else {
-			/* cache the results for future use */
-			file->last_stts_index = i;
-			file->last_frame = f;
-			file->last_start = *start;
-
-			*start += stts->table[i].sample_duration * (frame - f);
-			*duration = stts->table[i].sample_duration;
-
-			return 1;
-		}
-	}
-
-	/* error */
-	return 0;
-}
-
-int mp4ff_get_mp4_video_decoder_config(mp4ff_t *file, int track, unsigned char** ppBuf, int* pBufSize)
-{
-	mp4ff_esds_t* esds;
-
-	if (!file->total_vtracks) {
-		return 0;
-	}
-	esds = &file->vtracks[track].track->mdia.minf.stbl.stsd.table[0].esds;
-	return mp4ff_esds_get_decoder_config(esds, ppBuf, pBufSize);
-}
-
-int mp4ff_set_mp4_video_decoder_config(mp4ff_t *file, int track, unsigned char* pBuf, int bufSize)
-{
-	mp4ff_esds_t* esds;
-
-	if (!file->total_vtracks) {
-		return 0;
-	}
-	esds = &file->vtracks[track].track->mdia.minf.stbl.stsd.table[0].esds;
-	return mp4ff_esds_set_decoder_config(esds, pBuf, bufSize);
-}
-
-int mp4ff_get_mp4_audio_decoder_config(mp4ff_t *file, int track, unsigned char** ppBuf, int* pBufSize)
-{
-	mp4ff_esds_t* esds;
-
-	if (!file->total_atracks) {
-		return 0;
-	}
-	esds = &file->atracks[track].track->mdia.minf.stbl.stsd.table[0].esds;
-	return mp4ff_esds_get_decoder_config(esds, ppBuf, pBufSize);
-}
-
-int mp4ff_set_mp4_audio_decoder_config(mp4ff_t *file, int track, unsigned char* pBuf, int bufSize)
-{
-	mp4ff_esds_t* esds;
-
-	if (!file->total_atracks) {
-		return 0;
-	}
-	esds = &file->atracks[track].track->mdia.minf.stbl.stsd.table[0].esds;
-	return mp4ff_esds_set_decoder_config(esds, pBuf, bufSize);
-}
-
-long mp4ff_samples_to_bytes(mp4ff_trak_t *track, long samples)
-{
-	return samples
-		* track->mdia.minf.stbl.stsd.table[0].channels
-		* track->mdia.minf.stbl.stsd.table[0].sample_size / 8;
-}
-
-int mp4ff_write_audio(mp4ff_t *file, char *audio_buffer, long samples, int track)
-{
-	long offset;
-	int result;
-	long bytes;
-
-/* Defeat 32 bit file size limit. */
-	if(mp4ff_test_position(file)) return 1;
-
-/* write chunk for 1 track */
-	bytes = samples * mp4ff_audio_bits(file, track) / 8 * file->atracks[track].channels;
-	offset = mp4ff_position(file);
-	result = mp4ff_write_data(file, audio_buffer, bytes);
-
-	if(result) result = 0; else result = 1; /* defeat fwrite's return */
-	mp4ff_update_tables(file, 
-						file->atracks[track].track, 
-						offset, 
-						file->atracks[track].current_chunk, 
-						file->atracks[track].current_position, 
-						samples, 
-						0,
-						0,
-						0,
-						0);
-	file->atracks[track].current_position += samples;
-	file->atracks[track].current_chunk++;
-	return result;
-}
-
-int mp4ff_write_audio_frame(mp4ff_t *file, unsigned char *audio_buffer, long bytes, int track)
-{
-	long offset = mp4ff_position(file);
-	int result = 0;
-
-	/* Defeat 32 bit file size limit. */
-	if(mp4ff_test_position(file)) return 1;
-
-	result = mp4ff_write_data(file, audio_buffer, bytes);
-	if(result) result = 0; else result = 1;
-
-	mp4ff_update_tables(file,
-						file->atracks[track].track,
-						offset,
-						file->atracks[track].current_chunk,
-						file->atracks[track].current_position,
-						1, 
-						bytes,
-						0,
-						0,
-						0);
-	file->atracks[track].current_position += 1;
-	file->atracks[track].current_chunk++;
-	return result;
-}
-
-int mp4ff_write_video_frame(mp4ff_t *file, 
-								unsigned char *video_buffer, 
-								long bytes, 
-								int track, 
-								unsigned char isKeyFrame,
-								long duration,
-								long renderingOffset)
-{
-	long offset = mp4ff_position(file);
-	int result = 0;
-
-	/* Defeat 32 bit file size limit. */
-	if(mp4ff_test_position(file)) return 1;
-
-	result = mp4ff_write_data(file, video_buffer, bytes);
-	if(result) result = 0; else result = 1;
-
-	mp4ff_update_tables(file,
-						file->vtracks[track].track,
-						offset,
-						file->vtracks[track].current_chunk,
-						file->vtracks[track].current_position,
-						1,
-						bytes,
-						duration,
-						isKeyFrame,
-						renderingOffset);
-	file->vtracks[track].current_position += 1;
-	file->vtracks[track].current_chunk++;
-	return result;
-}
-
-mp4_callback_t* mp4ff_get_fd(mp4ff_t *file)
-{
-    if (file->stream->get_position() != file->file_position)
-        file->stream->seek(file->file_position);
-    return file->stream;
-}
-
-int mp4ff_write_frame_init(mp4ff_t *file, int track)
-{
-    if(file->stream->get_position() != file->file_position)
-        file->stream->seek(file->file_position);
-    file->offset = mp4ff_position(file);
     return 0;
 }
 
-int mp4ff_write_frame_end(mp4ff_t *file, int track)
-{
-	long bytes;
-	file->file_position = file->stream->get_position();
-	bytes = mp4ff_position(file) - file->offset;
-	mp4ff_update_tables(file,
-						file->vtracks[track].track,
-						file->offset,
-						file->vtracks[track].current_chunk,
-						file->vtracks[track].current_position,
-						1,
-						bytes,
-						0,
-						0,
-						0);
-	file->vtracks[track].current_position += 1;
-	file->vtracks[track].current_chunk++;
-	return 0;
-}
 
-int mp4ff_write_audio_init(mp4ff_t *file, int track)
+int32_t mp4ff_get_sample_duration(mp4ff_t *f, int32_t track, int32_t sample)
 {
-	return mp4ff_write_frame_init(file, track);
-}
+    int32_t i, ci = 0, co = 0;
 
-int mp4ff_write_audio_end(mp4ff_t *file, int track, long samples)
-{
-	long bytes;
-	file->file_position = file->stream->get_position();
-	bytes = mp4ff_position(file) - file->offset;
-	mp4ff_update_tables(file, 
-						file->atracks[track].track,
-						file->offset,
-						file->atracks[track].current_chunk,
-						file->atracks[track].current_position,
-						samples,
-						bytes, 
-						0,
-						0,
-						0);
-	file->atracks[track].current_position += samples;
-	file->atracks[track].current_chunk++;
-	return 0;
-}
-
-
-long mp4ff_read_audio(mp4ff_t *file, char *audio_buffer, long samples, int track)
-{
-	long chunk_sample, chunk;
-	int result = 1, track_num;
-	mp4ff_trak_t *trak = file->atracks[track].track;
-	long fragment_len, chunk_end;
-	long position = file->atracks[track].current_position;
-	long start = position, end = position + samples;
-	long bytes, total_bytes = 0;
-	long buffer_offset;
-
-	mp4ff_chunk_of_sample(&chunk_sample, &chunk, trak, position);
-	buffer_offset = 0;
-
-	while(position < end && result)
-	{
-		mp4ff_set_audio_position(file, position, track);
-		fragment_len = mp4ff_chunk_samples(trak, chunk);
-		chunk_end = chunk_sample + fragment_len;
-		fragment_len -= position - chunk_sample;
-		if(position + fragment_len > chunk_end) fragment_len = chunk_end - position;
-		if(position + fragment_len > end) fragment_len = end - position;
-
-		bytes = mp4ff_samples_to_bytes(trak, fragment_len);
-		result = mp4ff_read_data(file, &audio_buffer[buffer_offset], bytes);
-
-		total_bytes += bytes;
-		position += fragment_len;
-		chunk_sample = position;
-		buffer_offset += bytes;
-		chunk++;
-	}
-
-	file->atracks[track].current_position = position;
-	if(!result) return 0;
-	return total_bytes;
-}
-
-int mp4ff_read_chunk(mp4ff_t *file, char *output, int track, long chunk, long byte_start, long byte_len)
-{
-	mp4ff_set_position(file, mp4ff_chunk_to_offset(file->atracks[track].track, chunk) + byte_start);
-	if(mp4ff_read_data(file, output, byte_len)) return 0;
-	else
-	return 1;
-}
-
-long mp4ff_frame_size(mp4ff_t *file, long frame, int track)
-{
-	int bytes;
-	mp4ff_trak_t *trak = file->vtracks[track].track;
-
-	if(trak->mdia.minf.stbl.stsz.sample_size)
-	{
-		bytes = trak->mdia.minf.stbl.stsz.sample_size;
-	}
-	else
-	{
-		bytes = trak->mdia.minf.stbl.stsz.table[frame].size;
-	}
-
-	return bytes;
-}
-
-long mp4ff_get_sample_duration(mp4ff_t *file, long frame, int track)
-{
-    int i, ci = 0, co = 0;
-    mp4ff_trak_t *trak = file->atracks[track].track;
-
-    for (i = 0; i < trak->mdia.minf.stbl.stts.total_entries; i++)
+    for (i = 0; i < f->track[track]->stts_entry_count; i++)
     {
-        int j;
-        for (j = 0; j < trak->mdia.minf.stbl.stts.table[i].sample_count; j++)
+        int32_t j;
+        for (j = 0; j < f->track[track]->stts_sample_count[i]; j++)
         {
-            if (co == frame)
-                return trak->mdia.minf.stbl.stts.table[ci].sample_duration;
+            if (co == sample)
+                return f->track[track]->stts_sample_delta[ci];
             co++;
         }
         ci++;
     }
-}
 
-long mp4ff_audio_frame_size(mp4ff_t *file, long frame, int track)
-{
-    int bytes;
-    mp4ff_trak_t *trak = file->atracks[track].track;
-
-    if(trak->mdia.minf.stbl.stsz.sample_size)
-    {
-        bytes = trak->mdia.minf.stbl.stsz.sample_size;
-    } else {
-        bytes = trak->mdia.minf.stbl.stsz.table[frame].size;
-    }
-
-    return bytes;
+    return 0;
 }
 
-long mp4ff_read_audio_frame(mp4ff_t *file, unsigned char *audio_buffer,  int maxBytes, int track)
+int32_t mp4ff_read_sample(mp4ff_t *f, int32_t track, int32_t sample, uint8_t **audio_buffer,  uint32_t *bytes)
 {
-	long bytes;
-	int result = 0;
-	mp4ff_trak_t *trak = file->atracks[track].track;
+    int32_t result = 0;
 
-	bytes = mp4ff_audio_frame_size(file, 
-		file->atracks[track].current_position, track);
+    *bytes = mp4ff_audio_frame_size(f, track, sample);
 
-	if (bytes > maxBytes) {
-		return -bytes;
-	}
+    *audio_buffer = (uint8_t*)malloc(*bytes);
 
-	mp4ff_set_audio_position(file, 
-		file->atracks[track].current_position, track);
+    mp4ff_set_sample_position(f, track, sample);
 
-	result = mp4ff_read_data(file, audio_buffer, bytes);
+    result = mp4ff_read_data(f, *audio_buffer, *bytes);
 
-	file->atracks[track].current_position++;
+    if (!result)
+        return 0;
 
-	if (!result)
-		return 0;
-	return bytes;
+    return *bytes;
 }
 
-long mp4ff_read_frame(mp4ff_t *file, unsigned char *video_buffer, int track)
+int32_t mp4ff_get_decoder_config(mp4ff_t *f, int32_t track, uint8_t** ppBuf, uint32_t* pBufSize)
 {
-	long bytes;
-	int result = 0;
-
-	mp4ff_trak_t *trak = file->vtracks[track].track;
-	bytes = mp4ff_frame_size(file, file->vtracks[track].current_position, track);
-
-	if(!file->vtracks[track].frames_cached)
-	{
-		mp4ff_set_video_position(file, file->vtracks[track].current_position, track);
-		result = mp4ff_read_data(file, video_buffer, bytes);
-	}
-	else
-	{
-		int i;
-		unsigned char *cached_frame;
-
-		if(file->vtracks[track].current_position >= file->vtracks[track].frames_cached) result = 1;
-		if(!result)
-		{
-			cached_frame = file->vtracks[track].frame_cache[file->vtracks[track].current_position];
-
-			for(i = 0; i < bytes; i++)
-				video_buffer[i] = cached_frame[i];
-		}
-	}
-	file->vtracks[track].current_position++;
-
-	if(!result) return 0;
-	return bytes;
-}
-
-int mp4ff_read_frame_init(mp4ff_t *file, int track)
-{
-	mp4ff_trak_t *trak = file->vtracks[track].track;
-	mp4ff_set_video_position(file, file->vtracks[track].current_position, track);
-	if(file->stream->get_position() != file->file_position)
-        file->stream->seek(file->file_position);
-	return 0;
-}
-
-int mp4ff_read_frame_end(mp4ff_t *file, int track)
-{
-	file->file_position = file->stream->get_position();
-	file->vtracks[track].current_position++;
-	return 0;
-}
-
-int mp4ff_init_video_map(mp4ff_video_map_t *vtrack, mp4ff_trak_t *trak)
-{
-	vtrack->track = trak;
-	vtrack->current_position = 0;
-	vtrack->current_chunk = 1;
-	vtrack->frame_cache = 0;
-	vtrack->frames_cached = 0;
-	return 0;
-}
-
-int mp4ff_delete_video_map(mp4ff_video_map_t *vtrack)
-{
-	int i;
-	if(vtrack->frames_cached)
-	{
-		for(i = 0; i < vtrack->frames_cached; i++)
-		{
-			free(vtrack->frame_cache[i]);
-		}
-		free(vtrack->frame_cache);
-		vtrack->frames_cached = 0;
-	}
-	return 0;
-}
-
-int mp4ff_init_audio_map(mp4ff_audio_map_t *atrack, mp4ff_trak_t *trak)
-{
-	atrack->track = trak;
-	atrack->channels = trak->mdia.minf.stbl.stsd.table[0].channels;
-	atrack->current_position = 0;
-	atrack->current_chunk = 1;
-	return 0;
-}
-
-int mp4ff_delete_audio_map(mp4ff_audio_map_t *atrack)
-{
-	int i;
-	return 0;
-}
-
-int mp4ff_read_info(mp4ff_t *file)
-{
-	int result = 0, found_moov = 0;
-	int i, j, k, m, channel, trak_channel, track;
-	long start_position = mp4ff_position(file);
-	mp4ff_atom_t leaf_atom;
-	mp4ff_trak_t *trak;
-
-	mp4ff_set_position(file, 0);
-
-	do
-	{
-		result = mp4ff_atom_read_header(file, &leaf_atom);
-		if(!result)
-		{
-			if(mp4ff_atom_is(&leaf_atom, "mdat")) {
-				mp4ff_read_mdat(file, &(file->mdat), &leaf_atom);
-			} else if(mp4ff_atom_is(&leaf_atom, "moov")) {
-				mp4ff_read_moov(file, &(file->moov), &leaf_atom);
-				found_moov = 1;
-			} else {
-				mp4ff_atom_skip(file, &leaf_atom);
-			}
-		}
-	}while(!result && mp4ff_position(file) < file->total_length);
-
-/* go back to the original position */
-	mp4ff_set_position(file, start_position);
-
-	if(found_moov) {
-
-		/* get tables for all the different tracks */
-		file->total_atracks = mp4ff_audio_tracks(file);
-		file->atracks = (mp4ff_audio_map_t*)calloc(1, 
-			sizeof(mp4ff_audio_map_t) * file->total_atracks);
-
-		for(i = 0, track = 0; i < file->total_atracks; i++) {
-			while(!file->moov.trak[track]->mdia.minf.is_audio)
-				track++;
-			mp4ff_init_audio_map(&(file->atracks[i]), file->moov.trak[track]);
-		}
-
-		file->total_vtracks = mp4ff_video_tracks(file);
-		file->vtracks = (mp4ff_video_map_t*)calloc(1, sizeof(mp4ff_video_map_t) * file->total_vtracks);
-
-		for(track = 0, i = 0; i < file->total_vtracks; i++)
-		{
-			while(!file->moov.trak[track]->mdia.minf.is_video)
-				track++;
-
-			mp4ff_init_video_map(&(file->vtracks[i]), file->moov.trak[track]);
-		}
-	}
-
-	if(found_moov) 
-		return 0; 
-	else 
-		return 1;
-}
-
-
-int mp4ff_dump(mp4ff_t *file)
-{
-	printf("mp4ff_dump\n");
-	printf("movie data\n");
-	printf(" size %ld\n", file->mdat.size);
-	printf(" start %ld\n", file->mdat.start);
-	mp4ff_moov_dump(&(file->moov));
-	return 0;
-}
-
-
-/* ================================== Entry points ========================== */
-
-int mp4ff_check_sig(mp4_callback_t *path)
-{
-	mp4ff_t file;
-	mp4ff_atom_t leaf_atom;
-	int result1 = 0, result2 = 0;
-
-	mp4ff_init(&file);
-    file.stream = path;
-
-	file.total_length = file.stream->get_length();
-
-	do
-	{
-		result1 = mp4ff_atom_read_header(&file, &leaf_atom);
-
-		if(!result1)
-		{
-/* just want the "moov" atom */
-			if(mp4ff_atom_is(&leaf_atom, "moov"))
-			{
-				result2 = 1;
-			}
-			else
-				mp4ff_atom_skip(&file, &leaf_atom);
-		}
-	}while(!result1 && !result2 && mp4ff_position(&file) < file.total_length);
-
-	mp4ff_delete(&file);
-	return result2;
-}
-
-mp4ff_t* mp4ff_open(mp4_callback_t *callbacks, int rd, int wr, int append)
-{
-    mp4ff_t *new_file = malloc(sizeof(mp4ff_t));
-    int exists = 0;
-
-    mp4ff_init(new_file);
-    new_file->stream = callbacks;
-    new_file->wr = wr;
-    new_file->rd = rd;
-    new_file->mdat.start = 0;
-
-    if(rd /*&& exists*/)
+    if (track >= f->total_tracks)
     {
-        new_file->total_length = new_file->stream->get_length();
-
-        if(mp4ff_read_info(new_file))
-        {
-            mp4ff_close(new_file);
-            new_file = 0;
-        }
+        *ppBuf = NULL;
+        *pBufSize = 0;
+        return 1;
     }
 
-    if(wr)
+    if (f->track[track]->decoderConfig == NULL || f->track[track]->decoderConfigLen == 0)
     {
-        if(!exists || !append)
+        *ppBuf = NULL;
+        *pBufSize = 0;
+    } else {
+        *ppBuf = malloc(f->track[track]->decoderConfigLen);
+        if (*ppBuf == NULL)
         {
-            /* start the data atom */
-            mp4ff_write_int32(new_file, 0);
-            mp4ff_write_char32(new_file, "mdat");
-        } else {
-            mp4ff_set_position(new_file,
-                new_file->mdat.start + new_file->mdat.size);
-            new_file->stream->seek(new_file->mdat.start + new_file->mdat.size);
+            *pBufSize = 0;
+            return 1;
         }
+        memcpy(*ppBuf, f->track[track]->decoderConfig, f->track[track]->decoderConfigLen);
+        *pBufSize = f->track[track]->decoderConfigLen;
     }
-    return new_file;
+
+    return 0;
 }
 
-int mp4ff_write(mp4ff_t *file)
+int32_t mp4ff_total_tracks(mp4ff_t *f)
 {
-	int result = -1;
-
-	if(!file->wr) {
-		return result;
-	}
-
-	mp4ff_write_mdat(file, &(file->mdat));
-	mp4ff_write_moov(file, &(file->moov));
-
-	return result;
+    return f->total_tracks;
 }
 
-int mp4ff_destroy(mp4ff_t *file)
+int32_t mp4ff_time_scale(mp4ff_t *f, int32_t track)
 {
-	mp4ff_delete(file);
-	free(file);
-	return 0;
+    return f->time_scale;
 }
 
-int mp4ff_close(mp4ff_t *file)
+int32_t mp4ff_num_samples(mp4ff_t *f, int32_t track)
 {
-	int result = 0;
-	if(file->wr)
-	{
-		mp4ff_write_mdat(file, &(file->mdat));
-		mp4ff_write_moov(file, &(file->moov));
-	}
+    int32_t i;
+    int32_t total = 0;
 
-	mp4ff_delete(file);
-	free(file);
-	return result;
+    for (i = 0; i < f->track[track]->stts_entry_count; i++)
+    {
+        total += f->track[track]->stts_sample_count[i];
+    }
+    return total;
 }
--- a/common/mp4ff/mp4ff.dsp
+++ b/common/mp4ff/mp4ff.dsp
@@ -40,8 +40,8 @@
 # PROP Output_Dir "Release"
 # PROP Intermediate_Dir "Release"
 # PROP Target_Dir ""
-MTL=midl.exe
 F90=df.exe
+MTL=midl.exe
 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
 # ADD CPP /nologo /MD /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
 # ADD BASE RSC /l 0x413 /d "NDEBUG"
@@ -65,8 +65,8 @@
 # PROP Output_Dir "Debug"
 # PROP Intermediate_Dir "Debug"
 # PROP Target_Dir ""
-MTL=midl.exe
 F90=df.exe
+MTL=midl.exe
 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /GZ /c
 # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /GZ /c
 # ADD BASE RSC /l 0x413 /d "_DEBUG"
@@ -89,128 +89,20 @@
 # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
 # Begin Source File
 
-SOURCE=.\atom.c
+SOURCE=.\mp4atom.c
 # End Source File
 # Begin Source File
 
-SOURCE=.\ctts.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dinf.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dref.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\edts.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\elst.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\esds.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\hdlr.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\iods.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\matrix.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\mdat.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\mdhd.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\mdia.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\minf.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\moov.c
-# End Source File
-# Begin Source File
-
 SOURCE=.\mp4ff.c
 # End Source File
 # Begin Source File
 
-SOURCE=.\mvhd.c
+SOURCE=.\mp4sample.c
 # End Source File
 # Begin Source File
 
-SOURCE=.\smhd.c
+SOURCE=.\mp4util.c
 # End Source File
-# Begin Source File
-
-SOURCE=.\stbl.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\stco.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\stsc.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\stsd.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\stsdtable.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\stss.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\stsz.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\stts.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\tkhd.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\trak.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\udta.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\util.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\vmhd.c
-# End Source File
 # End Group
 # Begin Group "Header Files"
 
@@ -217,15 +109,7 @@
 # PROP Default_Filter "h;hpp;hxx;hm;inl"
 # Begin Source File
 
-SOURCE=.\funcprotos.h
-# End Source File
-# Begin Source File
-
 SOURCE=.\mp4ff.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\private.h
 # End Source File
 # End Group
 # End Target
--- a/common/mp4ff/mp4ff.h
+++ b/common/mp4ff/mp4ff.h
@@ -1,246 +1,226 @@
+/*
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
+** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program 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 General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** Any non-GPL usage of this software or parts of this software is strictly
+** forbidden.
+**
+** Commercial non-GPL licensing of this software is possible.
+** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+**
+** $Id: mp4ff.h,v 1.4 2003/11/21 15:08:48 menno Exp $
+**/
+
 #ifndef MP4FF_H
 #define MP4FF_H
 
 #ifdef __cplusplus
 extern "C" {
-#endif
+#endif /* __cplusplus */
 
-#ifdef _WIN32
 
- #include <stdio.h>
- #include <stdlib.h>
+#define MAX_TRACKS 1024
+#define TRACK_UNKNOWN 0
+#define TRACK_AUDIO   1
+#define TRACK_VIDEO   2
+#define TRACK_SYSTEM  3
 
-#else
-#ifdef HAVE_CONFIG_H
-#  include "../../config.h"
-#endif
 
-#include <stdio.h>
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-#if STDC_HEADERS
-# include <stdlib.h>
-# include <stddef.h>
-#else
-# if HAVE_STDLIB_H
-#  include <stdlib.h>
-# endif
-#endif
-#if HAVE_STRING_H
-# if !STDC_HEADERS && HAVE_MEMORY_H
-#  include <memory.h>
-# endif
-# include <string.h>
-#endif
-#if HAVE_STRINGS_H
-# include <strings.h>
-#endif
-#if HAVE_INTTYPES_H
-# include <inttypes.h>
-#else
-# if HAVE_STDINT_H
-#  include <stdint.h>
-# else
-/* we need these... */
-typedef unsigned long long uint64_t;
-typedef unsigned long uint32_t;
-typedef unsigned short uint16_t;
-typedef unsigned char uint8_t;
-typedef long long int64_t;
-typedef long int32_t;
-typedef short int16_t;
-typedef char int8_t;
-# endif
-#endif
-#if HAVE_UNISTD_H
-# include <unistd.h>
-#endif
+#define SUBATOMIC 128
 
-#ifndef HAVE_FLOAT32_T
-typedef float float32_t;
-#endif
+/* atoms without subatoms */
+#define ATOM_FTYP 129
+#define ATOM_MDAT 130
+#define ATOM_MVHD 131
+#define ATOM_TKHD 132
+#define ATOM_TREF 133
+#define ATOM_MDHD 134
+#define ATOM_VMHD 135
+#define ATOM_SMHD 136
+#define ATOM_HMHD 137
+#define ATOM_STSD 138
+#define ATOM_STTS 139
+#define ATOM_STSZ 140
+#define ATOM_STZ2 141
+#define ATOM_STCO 142
+#define ATOM_STSC 143
+#define ATOM_MP4A 144
+#define ATOM_MP4V 145
+#define ATOM_MP4S 146
+#define ATOM_ESDS 147
 
-#if STDC_HEADERS
-# include <string.h>
+#define ATOM_UNKNOWN 255
+#define ATOM_FREE ATOM_UNKNOWN
+#define ATOM_SKIP ATOM_UNKNOWN
+
+/* atoms with subatoms */
+#define ATOM_MOOV 1
+#define ATOM_TRAK 2
+#define ATOM_EDTS 3
+#define ATOM_MDIA 4
+#define ATOM_MINF 5
+#define ATOM_STBL 6
+
+#ifdef _WIN32
+typedef __int8 int8_t;
+typedef unsigned __int8 uint8_t;
+typedef __int16 int16_t;
+typedef unsigned __int16 uint16_t;
+typedef __int32 int32_t;
+typedef unsigned __int32 uint32_t;
+typedef __int64 int64_t;
+typedef unsigned __int64 uint64_t;
 #else
-# if !HAVE_STRCHR
-#  define strchr index
-#  define strrchr rindex
-# endif
-char *strchr(), *strrchr();
-# if !HAVE_MEMCPY
-#  define memcpy(d, s, n) bcopy((s), (d), (n))
-#  define memmove(d, s, n) bcopy((s), (d), (n))
-# endif
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#else
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
 #endif
-
-#ifndef FALSE
-#define FALSE 0
+#define u_int8_t uint8_t
+#define u_int16_t uint16_t
+#define u_int32_t uint32_t
+#define u_int64_t uint64_t
 #endif
-#ifndef TRUE
-#define TRUE 1
 #endif
 
-#endif
+/* file callback structure */
+typedef struct
+{
+    int32_t (*read)(void *udata, void *buffer, int32_t length);
+    int32_t (*seek)(void *udata, int32_t position);
+    void *user_data;
+} mp4ff_callback_t;
 
+typedef struct
+{
+    int32_t type;
+    int32_t channelCount;
+    int32_t sampleSize;
+    int32_t sampleRate;
 
-#include "private.h"
-#include "funcprotos.h"
+    /* stsd */
+    int32_t stsd_entry_count;
 
+    /* stsz */
+	int32_t stsz_sample_size;
+	int32_t stsz_sample_count;
+    int32_t *stsz_table;
 
+    /* stts */
+	int32_t stts_entry_count;
+    int32_t *stts_sample_count;
+    int32_t *stts_sample_delta;
 
-/* This is the reference for all your library entry points. */
+    /* stsc */
+	int32_t stsc_entry_count;
+    int32_t *stsc_first_chunk;
+    int32_t *stsc_samples_per_chunk;
+    int32_t *stsc_sample_desc_index;
 
+    /* stsc */
+	int32_t stco_entry_count;
+    int32_t *stco_chunk_offset;
 
-/* =========================== public interface ========================= // */
+    /* esde */
+    uint8_t *decoderConfig;
+    int32_t decoderConfigLen;
 
-/* return 1 if the file is a quicktime file */
-int mp4ff_check_sig(mp4_callback_t *path);
+} mp4ff_track_t;
 
-/* call this first to open the file and create all the objects */
-mp4ff_t* mp4ff_open(mp4_callback_t *callbacks, int rd, int wr, int append);
+/* mp4 main file structure */
+typedef struct
+{
+    /* stream to read from */
+	mp4ff_callback_t *stream;
+    int32_t current_position;
 
-/* make the quicktime file streamable */
-int mp4ff_make_streamable(mp4_callback_t *in_path, mp4_callback_t *out_path);
+    int32_t moov_read;
+    int32_t moov_offset;
+    int32_t moov_size;
+    int32_t mdat_read;
+    int32_t mdat_offset;
+    int32_t mdat_size;
 
-/* Set various options in the file. */
-int mp4ff_set_time_scale(mp4ff_t *file, int time_scale);
-int mp4ff_set_copyright(mp4ff_t *file, char *string);
-int mp4ff_set_name(mp4ff_t *file, char *string);
-int mp4ff_set_info(mp4ff_t *file, char *string);
-int mp4ff_get_time_scale(mp4ff_t *file);
-char* mp4ff_get_copyright(mp4ff_t *file);
-char* mp4ff_get_name(mp4ff_t *file);
-char* mp4ff_get_info(mp4ff_t *file);
+    /* mvhd */
+    int32_t time_scale;
+    int32_t duration;
 
-/* Read all the information about the file. */
-/* Requires a MOOV atom be present in the file. */
-/* If no MOOV atom exists return 1 else return 0. */
-int mp4ff_read_info(mp4ff_t *file);
+    /* incremental track index while reading the file */
+    int32_t total_tracks;
 
-/* set up tracks in a new file after opening and before writing */
-/* returns the number of quicktime tracks allocated */
-/* audio is stored two channels per quicktime track */
-int mp4ff_set_audio(mp4ff_t *file, int channels, long sample_rate, int bits, int sample_size, int time_scale, int sample_duration, char *compressor);
+    /* track data */
+    mp4ff_track_t *track[MAX_TRACKS];
+} mp4ff_t;
 
-/* Samplerate can be set after file is created */
-int mp4ff_set_framerate(mp4ff_t *file, float framerate);
 
-/* video is stored one layer per quicktime track */
-int mp4ff_set_video(mp4ff_t *file, int tracks, int frame_w, int frame_h, float frame_rate, int time_scale, char *compressor);
 
-/* routines for setting various video parameters */
 
-/* Set the depth of the track. */
-int mp4ff_set_depth(mp4ff_t *file, int depth, int track);
-
-/* close the file and delete all the objects */
-int mp4ff_write(mp4ff_t *file);
-int mp4ff_destroy(mp4ff_t *file);
-int mp4ff_close(mp4ff_t *file);
-
-/* get length information */
-/* channel numbers start on 1 for audio and video */
-long mp4ff_audio_length(mp4ff_t *file, int track);
-long mp4ff_video_length(mp4ff_t *file, int track);
-
-/* get position information */
-long mp4ff_audio_position(mp4ff_t *file, int track);
-long mp4ff_video_position(mp4ff_t *file, int track);
-
-/* get file information */
-int mp4ff_video_tracks(mp4ff_t *file);
-int mp4ff_audio_tracks(mp4ff_t *file);
-
-int mp4ff_has_audio(mp4ff_t *file);
-long mp4ff_audio_sample_rate(mp4ff_t *file, int track);
-int mp4ff_audio_bits(mp4ff_t *file, int track);
-int mp4ff_track_channels(mp4ff_t *file, int track);
-int mp4ff_audio_time_scale(mp4ff_t *file, int track);
-int mp4ff_audio_sample_duration(mp4ff_t *file, int track);
-char* mp4ff_audio_compressor(mp4ff_t *file, int track);
-
-int mp4ff_has_video(mp4ff_t *file);
-int mp4ff_video_width(mp4ff_t *file, int track);
-int mp4ff_video_height(mp4ff_t *file, int track);
-int mp4ff_video_depth(mp4ff_t *file, int track);
-float mp4ff_video_frame_rate(mp4ff_t *file, int track);
-char* mp4ff_video_compressor(mp4ff_t *file, int track);
-int mp4ff_video_time_scale(mp4ff_t *file, int track);
-
-int mp4ff_video_frame_time(mp4ff_t *file, int track, long frame,
-    long *start_time, int *duration);
-
-int mp4ff_get_iod_audio_profile_level(mp4ff_t *file);
-int mp4ff_set_iod_audio_profile_level(mp4ff_t *file, int id);
-int mp4ff_get_iod_video_profile_level(mp4ff_t *file);
-int mp4ff_set_iod_video_profile_level(mp4ff_t *file, int id);
-
-int mp4ff_get_mp4_video_decoder_config(mp4ff_t *file, int track, unsigned char** ppBuf, int* pBufSize);
-int mp4ff_set_mp4_video_decoder_config(mp4ff_t *file, int track, unsigned char* pBuf, int bufSize);
-int mp4ff_get_mp4_audio_decoder_config(mp4ff_t *file, int track, unsigned char** ppBuf, int* pBufSize);
-int mp4ff_set_mp4_audio_decoder_config(mp4ff_t *file, int track, unsigned char* pBuf, int bufSize);
-
-/* number of bytes of raw data in this frame */
-long mp4ff_frame_size(mp4ff_t *file, long frame, int track);
-long mp4ff_audio_frame_size(mp4ff_t *file, long frame, int track);
-
-/* get the quicktime track and channel that the audio channel belongs to */
-/* channels and tracks start on 0 */
-int mp4ff_channel_location(mp4ff_t *file, int *mp4ff_track, int *mp4ff_channel, int channel);
-
-/* file positioning */
-int mp4ff_seek_end(mp4ff_t *file);
-int mp4ff_seek_start(mp4ff_t *file);
-
-/* set position of file descriptor relative to a track */
-int mp4ff_set_audio_position(mp4ff_t *file, long sample, int track);
-int mp4ff_set_video_position(mp4ff_t *file, long frame, int track);
-
-/* ========================== Access to raw data follows. */
-/* write data for one quicktime track */
-/* the user must handle conversion to the channels in this track */
-int mp4ff_write_audio(mp4ff_t *file, char *audio_buffer, long samples, int track);
-int mp4ff_write_audio_frame(mp4ff_t *file, unsigned char *audio_buffer, long bytes, int track);
-
-int mp4ff_write_video_frame(mp4ff_t *file, unsigned char *video_buffer, long bytes, int track, unsigned char isKeyFrame, long duration, long renderingOffset);
-
-/* for writing a frame using a library that needs a file descriptor */
-int mp4ff_write_frame_init(mp4ff_t *file, int track); /* call before fwrite */
-mp4_callback_t* mp4ff_get_fd(mp4ff_t *file);     /* return a file descriptor */
-int mp4ff_write_frame_end(mp4ff_t *file, int track); /* call after fwrite */
-
-/* For reading and writing audio to a file descriptor. */
-int mp4ff_write_audio_end(mp4ff_t *file, int track, long samples); /* call after fwrite */
-
-/* Read an entire chunk. */
-/* read the number of bytes starting at the byte_start in the specified chunk */
-/* You must provide enough space to store the chunk. */
-int mp4ff_read_chunk(mp4ff_t *file, char *output, int track, long chunk, long byte_start, long byte_len);
+/* mp4util.c */
+int32_t mp4ff_read_data(mp4ff_t *f, int8_t *data, int32_t size);
+int32_t mp4ff_read_int32(mp4ff_t *f);
+int32_t mp4ff_read_int24(mp4ff_t *f);
+int16_t mp4ff_read_int16(mp4ff_t *f);
+int8_t mp4ff_read_char(mp4ff_t *f);
+uint32_t mp4ff_read_mp4_descr_length(mp4ff_t *f);
+int32_t mp4ff_position(mp4ff_t *f);
+int32_t mp4ff_set_position(mp4ff_t *f, int32_t position);
 
-/* read raw data */
-long mp4ff_read_audio(mp4ff_t *file, char *audio_buffer, long samples, int track);
-long mp4ff_read_audio_frame(mp4ff_t *file, unsigned char *audio_buffer, int maxBytes, int track);
-long mp4ff_read_frame(mp4ff_t *file, unsigned char *video_buffer, int track);
-long mp4ff_get_sample_duration(mp4ff_t *file, long frame, int track);
+/* mp4atom.c */
+int32_t mp4ff_atom_get_size(int8_t *data);
+int32_t mp4ff_atom_compare(int8_t a1, int8_t b1, int8_t c1, int8_t d1,
+                           int8_t a2, int8_t b2, int8_t c2, int8_t d2);
+uint8_t mp4ff_atom_name_to_type(int8_t a, int8_t b, int8_t c, int8_t d);
+int32_t mp4ff_atom_read_header(mp4ff_t *f, uint8_t *atom_type);
+int32_t mp4ff_read_stsz(mp4ff_t *f);
+int32_t mp4ff_read_esds(mp4ff_t *f);
+int32_t mp4ff_read_mp4a(mp4ff_t *f);
+int32_t mp4ff_read_stsd(mp4ff_t *f);
+int32_t mp4ff_read_stsc(mp4ff_t *f);
+int32_t mp4ff_read_stco(mp4ff_t *f);
+int32_t mp4ff_read_stts(mp4ff_t *f);
+int32_t mp4ff_atom_read(mp4ff_t *f, int32_t size, int8_t atom_type);
 
-/* for reading frame using a library that needs a file descriptor */
-/* Frame caching doesn't work here. */
-int mp4ff_read_frame_init(mp4ff_t *file, int track);
-int mp4ff_read_frame_end(mp4ff_t *file, int track);
+/* mp4sample.c */
+int32_t mp4ff_chunk_of_sample(mp4ff_t *f, int32_t track, int32_t sample,
+                              int32_t *chunk_sample, int32_t *chunk);
+int32_t mp4ff_chunk_to_offset(mp4ff_t *f, int32_t track, int32_t chunk);
+int32_t mp4ff_sample_range_size(mp4ff_t *f, int32_t track, int32_t chunk_sample, int32_t sample);
+int32_t mp4ff_sample_to_offset(mp4ff_t *f, int32_t track, int32_t sample);
+int32_t mp4ff_audio_frame_size(mp4ff_t *f, int32_t track, int32_t sample);
+int32_t mp4ff_set_sample_position(mp4ff_t *f, int32_t track, int32_t sample);
 
-/* Dump the file structures for the currently opened file. */
-int mp4ff_dump(mp4ff_t *file);
 
-/* Test the 32 bit overflow */
-int mp4ff_test_position(mp4ff_t *file);
+/* mp4ff.c */
+mp4ff_t *mp4ff_open_read(mp4ff_callback_t *f);
+void mp4ff_close(mp4ff_t *ff);
+void mp4ff_track_add(mp4ff_t *f);
+int32_t parse_sub_atoms(mp4ff_t *f, int32_t total_size);
+int32_t parse_atoms(mp4ff_t *f);
+int32_t mp4ff_get_sample_duration(mp4ff_t *f, int32_t track, int32_t sample);
+int32_t mp4ff_read_sample(mp4ff_t *f, int32_t track, int32_t sample, uint8_t **audio_buffer,  uint32_t *bytes);
+int32_t mp4ff_get_decoder_config(mp4ff_t *f, int32_t track, uint8_t** ppBuf, uint32_t* pBufSize);
+int32_t mp4ff_total_tracks(mp4ff_t *f);
+int32_t mp4ff_time_scale(mp4ff_t *f, int32_t track);
+int32_t mp4ff_num_samples(mp4ff_t *f, int32_t track);
 
+
 #ifdef __cplusplus
 }
-#endif
+#endif /* __cplusplus */
 
-#endif
+#endif
\ No newline at end of file
--- /dev/null
+++ b/common/mp4ff/mp4sample.c
@@ -1,0 +1,143 @@
+/*
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
+** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program 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 General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** Any non-GPL usage of this software or parts of this software is strictly
+** forbidden.
+**
+** Commercial non-GPL licensing of this software is possible.
+** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+**
+** $Id: mp4sample.c,v 1.1 2003/11/21 15:08:48 menno Exp $
+**/
+
+#include <stdlib.h>
+#include "mp4ff.h"
+
+
+int32_t mp4ff_chunk_of_sample(mp4ff_t *f, int32_t track, int32_t sample,
+                              int32_t *chunk_sample, int32_t *chunk)
+{
+    int32_t total_entries = 0;
+    int32_t chunk2entry;
+    int32_t chunk1, chunk2, chunk1samples, range_samples, total = 0;
+
+    if (f->track[track] == NULL)
+    {
+        return -1;
+    }
+
+    total_entries = f->track[track]->stsc_entry_count;
+
+    chunk1 = 1;
+    chunk1samples = 0;
+    chunk2entry = 0;
+
+    do
+    {
+        chunk2 = f->track[track]->stsc_first_chunk[chunk2entry];
+        *chunk = chunk2 - chunk1;
+        range_samples = *chunk * chunk1samples;
+
+        if (sample < total + range_samples) break;
+
+        chunk1samples = f->track[track]->stsc_samples_per_chunk[chunk2entry];
+        chunk1 = chunk2;
+
+        if(chunk2entry < total_entries)
+        {
+            chunk2entry++;
+            total += range_samples;
+        }
+    } while (chunk2entry < total_entries);
+
+    if (chunk1samples)
+        *chunk = (sample - total) / chunk1samples + chunk1;
+    else
+        *chunk = 1;
+
+    *chunk_sample = total + (*chunk - chunk1) * chunk1samples;
+
+    return 0;
+}
+
+int32_t mp4ff_chunk_to_offset(mp4ff_t *f, int32_t track, int32_t chunk)
+{
+    if (f->track[track]->stco_entry_count && (chunk > f->track[track]->stco_entry_count))
+    {
+        return f->track[track]->stco_chunk_offset[f->track[track]->stco_entry_count - 1];
+    } else if (f->track[track]->stco_entry_count) {
+        return f->track[track]->stco_chunk_offset[chunk - 1];
+    } else {
+        return 8;
+    }
+    
+    return 0;
+}
+
+int32_t mp4ff_sample_range_size(mp4ff_t *f, int32_t track, int32_t chunk_sample, int32_t sample)
+{
+    int32_t i, total;
+
+    if (f->track[track]->stsz_sample_size)
+    {
+        return sample * f->track[track]->channelCount * f->track[track]->sampleSize/8;
+    } else {
+        for(i = chunk_sample, total = 0; i < sample; i++)
+        {
+            total += f->track[track]->stsz_table[i];
+        }
+    }
+
+    return total;
+}
+
+int32_t mp4ff_sample_to_offset(mp4ff_t *f, int32_t track, int32_t sample)
+{
+    int32_t chunk, chunk_sample, chunk_offset1, chunk_offset2;
+
+    mp4ff_chunk_of_sample(f, track, sample, &chunk_sample, &chunk);
+
+    chunk_offset1 = mp4ff_chunk_to_offset(f, track, chunk);
+    chunk_offset2 = chunk_offset1 + mp4ff_sample_range_size(f, track, chunk_sample, sample);
+
+	return chunk_offset2;
+}
+
+int32_t mp4ff_audio_frame_size(mp4ff_t *f, int32_t track, int32_t sample)
+{
+    int32_t bytes;
+
+    if (f->track[track]->stsz_sample_size)
+    {
+        bytes = f->track[track]->stsz_sample_size;
+    } else {
+        bytes = f->track[track]->stsz_table[sample];
+    }
+
+    return bytes;
+}
+
+int32_t mp4ff_set_sample_position(mp4ff_t *f, int32_t track, int32_t sample)
+{
+    int32_t offset;
+
+    offset = mp4ff_sample_to_offset(f, track, sample);
+    mp4ff_set_position(f, offset);
+
+    return 0;
+}
--- /dev/null
+++ b/common/mp4ff/mp4util.c
@@ -1,0 +1,120 @@
+/*
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
+** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program 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 General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** Any non-GPL usage of this software or parts of this software is strictly
+** forbidden.
+**
+** Commercial non-GPL licensing of this software is possible.
+** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+**
+** $Id: mp4util.c,v 1.1 2003/11/21 15:08:48 menno Exp $
+**/
+
+#include "mp4ff.h"
+
+int32_t mp4ff_read_data(mp4ff_t *f, int8_t *data, int32_t size)
+{
+    int32_t result = 1;
+
+    result = f->stream->read(f->stream->user_data, data, size);
+
+    f->current_position += size;
+
+    return result;
+}
+
+int32_t mp4ff_set_position(mp4ff_t *f, int32_t position)
+{
+    f->stream->seek(f->stream->user_data, position);
+    f->current_position = position;
+
+    return 0;
+}
+
+int32_t mp4ff_position(mp4ff_t *f)
+{
+    return f->current_position;
+}
+
+int32_t mp4ff_read_int32(mp4ff_t *f)
+{
+    uint32_t result;
+    uint32_t a, b, c, d;
+    int8_t data[4];
+    
+    mp4ff_read_data(f, data, 4);
+    a = (uint8_t)data[0];
+    b = (uint8_t)data[1];
+    c = (uint8_t)data[2];
+    d = (uint8_t)data[3];
+
+    result = (a<<24) | (b<<16) | (c<<8) | d;
+    return (int32_t)result;
+}
+
+int32_t mp4ff_read_int24(mp4ff_t *f)
+{
+    uint32_t result;
+    uint32_t a, b, c;
+    int8_t data[4];
+    
+    mp4ff_read_data(f, data, 3);
+    a = (uint8_t)data[0];
+    b = (uint8_t)data[1];
+    c = (uint8_t)data[2];
+
+    result = (a<<16) | (b<<8) | c;
+    return (int32_t)result;
+}
+
+int16_t mp4ff_read_int16(mp4ff_t *f)
+{
+    uint32_t result;
+    uint32_t a, b;
+    int8_t data[2];
+    
+    mp4ff_read_data(f, data, 2);
+    a = (uint8_t)data[0];
+    b = (uint8_t)data[1];
+
+    result = (a<<8) | b;
+    return (int16_t)result;
+}
+
+int8_t mp4ff_read_char(mp4ff_t *f)
+{
+    int8_t output;
+    mp4ff_read_data(f, &output, 1);
+    return output;
+}
+
+uint32_t mp4ff_read_mp4_descr_length(mp4ff_t *f)
+{
+    uint8_t b;
+    uint8_t numBytes = 0;
+    uint32_t length = 0;
+
+    do
+    {
+        b = mp4ff_read_char(f);
+        numBytes++;
+        length = (length << 7) | (b & 0x7F);
+    } while ((b & 0x80) && numBytes < 4);
+
+    return length;
+}
--- a/common/mp4ff/mvhd.c
+++ /dev/null
@@ -1,111 +1,0 @@
-#include "mp4ff.h"
-
-
-
-int mp4ff_mvhd_init(mp4ff_mvhd_t *mvhd)
-{
-	int i;
-	mvhd->version = 0;
-	mvhd->flags = 0;
-	mvhd->creation_time = mp4ff_current_time();
-	mvhd->modification_time = mp4ff_current_time();
-	mvhd->time_scale = 90000;
-	mvhd->duration = 0;
-	mvhd->preferred_rate = 1.0;
-	mvhd->preferred_volume = 0.996094;
-	for(i = 0; i < 10; i++) mvhd->reserved[i] = 0;
-	mp4ff_matrix_init(&(mvhd->matrix));
-	mvhd->preview_time = 0;
-	mvhd->preview_duration = 0;
-	mvhd->poster_time = 0;
-	mvhd->selection_time = 0;
-	mvhd->selection_duration = 0;
-	mvhd->current_time = 0;
-	mvhd->next_track_id = 1;
-	return 0;
-}
-
-int mp4ff_mvhd_delete(mp4ff_mvhd_t *mvhd)
-{
-	return 0;
-}
-
-int mp4ff_mvhd_dump(mp4ff_mvhd_t *mvhd)
-{
-	printf(" movie header\n");
-	printf("  version %d\n", mvhd->version);
-	printf("  flags %ld\n", mvhd->flags);
-	printf("  creation_time %u\n", mvhd->creation_time);
-	printf("  modification_time %u\n", mvhd->modification_time);
-	printf("  time_scale %ld\n", mvhd->time_scale);
-	printf("  duration %ld\n", mvhd->duration);
-	printf("  preferred_rate %f\n", mvhd->preferred_rate);
-	printf("  preferred_volume %f\n", mvhd->preferred_volume);
-	mp4ff_print_chars("  reserved ", mvhd->reserved, 10);
-	mp4ff_matrix_dump(&(mvhd->matrix));
-	printf("  preview_time %ld\n", mvhd->preview_time);
-	printf("  preview_duration %ld\n", mvhd->preview_duration);
-	printf("  poster_time %ld\n", mvhd->poster_time);
-	printf("  selection_time %ld\n", mvhd->selection_time);
-	printf("  selection_duration %ld\n", mvhd->selection_duration);
-	printf("  current_time %ld\n", mvhd->current_time);
-	printf("  next_track_id %ld\n", mvhd->next_track_id);
-}
-
-int mp4ff_read_mvhd(mp4ff_t *file, mp4ff_mvhd_t *mvhd)
-{
-	mvhd->version = mp4ff_read_char(file);
-	mvhd->flags = mp4ff_read_int24(file);
-	mvhd->creation_time = mp4ff_read_int32(file);
-	mvhd->modification_time = mp4ff_read_int32(file);
-	mvhd->time_scale = mp4ff_read_int32(file);
-	mvhd->duration = mp4ff_read_int32(file);
-	mvhd->preferred_rate = mp4ff_read_fixed32(file);
-	mvhd->preferred_volume = mp4ff_read_fixed16(file);
-	mp4ff_read_data(file, mvhd->reserved, 10);
-	mp4ff_read_matrix(file, &(mvhd->matrix));
-	mvhd->preview_time = mp4ff_read_int32(file);
-	mvhd->preview_duration = mp4ff_read_int32(file);
-	mvhd->poster_time = mp4ff_read_int32(file);
-	mvhd->selection_time = mp4ff_read_int32(file);
-	mvhd->selection_duration = mp4ff_read_int32(file);
-	mvhd->current_time = mp4ff_read_int32(file);
-	mvhd->next_track_id = mp4ff_read_int32(file);
-}
-
-int mp4ff_write_mvhd(mp4ff_t *file, mp4ff_mvhd_t *mvhd)
-{
-	int i;
-
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, "mvhd");
-
-	mp4ff_write_char(file, mvhd->version);
-	mp4ff_write_int24(file, mvhd->flags);
-	mp4ff_write_int32(file, mvhd->creation_time);
-	mp4ff_write_int32(file, mvhd->modification_time);
-	mp4ff_write_int32(file, mvhd->time_scale);
-	mp4ff_write_int32(file, mvhd->duration);
-
-	mp4ff_write_int32(file, 0x00010000);
-	mp4ff_write_int16(file, 0x0100);
-	mp4ff_write_int16(file, 0x0000);
-	mp4ff_write_int32(file, 0x00000000);
-	mp4ff_write_int32(file, 0x00000000);
-	mp4ff_write_int32(file, 0x00010000);
-	for (i = 0; i < 3; i++) {
-		mp4ff_write_int32(file, 0x00000000);
-	}
-	mp4ff_write_int32(file, 0x00010000);
-	for (i = 0; i < 3; i++) {
-		mp4ff_write_int32(file, 0x00000000);
-	}
-	mp4ff_write_int32(file, 0x40000000);
-	for (i = 0; i < 6; i++) {
-		mp4ff_write_int32(file, 0x00000000);
-	}
-
-	mp4ff_write_int32(file, mvhd->next_track_id);
-
-	mp4ff_atom_write_footer(file, &atom);
-}
--- a/common/mp4ff/private.h
+++ /dev/null
@@ -1,509 +1,0 @@
-#ifndef PRIVATE_H
-#define PRIVATE_H
-
-/* ================================= structures */
-
-#define HEADER_LENGTH 8
-#define MAXTRACKS 1024
-
-#ifdef _WIN32
-typedef __int8 int8_t;
-typedef unsigned __int8 uint8_t;
-typedef __int16 int16_t;
-typedef unsigned __int16 uint16_t;
-typedef __int32 int32_t;
-typedef unsigned __int32 uint32_t;
-typedef __int64 int64_t;
-typedef unsigned __int64 uint64_t;
-typedef __int64 off_t;
-#else
-#ifdef HAVE_INTTYPES_H
-#include <inttypes.h>
-#else
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#define u_int8_t uint8_t
-#define u_int16_t uint16_t
-#define u_int32_t uint32_t
-#define u_int64_t uint64_t
-#endif
-
-#endif
-
-
-typedef struct
-{
-	float values[9];
-} mp4ff_matrix_t;
-
-
-typedef struct
-{
-	int version;
-	long flags;
-	unsigned long creation_time;
-	unsigned long modification_time;
-	int track_id;
-	long reserved1;
-	long duration;
-	char reserved2[8];
-	int layer;
-	int alternate_group;
-	float volume;
-	long reserved3;
-	mp4ff_matrix_t matrix;
-	float track_width;
-	float track_height;
-	int is_video;
-	int is_audio;
-} mp4ff_tkhd_t;
-
-
-
-
-/* ===================== sample table ======================== // */
-
-
-
-/* sample description */
-
-typedef struct
-{
-	int version;
-	long flags;
-	int decoderConfigLen;
-	unsigned char* decoderConfig;
-} mp4ff_esds_t;
-
-typedef struct
-{
-	char format[4];
-	char reserved[6];
-	int data_reference;
-
-/* common to audio and video */
-	int version;
-	int revision;
-	char vendor[4];
-
-/* video description */
-	long temporal_quality;
-	long spatial_quality;
-	int width;
-	int height;
-	float dpi_horizontal;
-	float dpi_vertical;
-	long data_size;
-	int frames_per_sample;
-	char compressor_name[32];
-	int depth;
-	float gamma;
-	int fields;    /* 0, 1, or 2 */
-	int field_dominance;   /* 0 - unknown     1 - top first     2 - bottom first */
-
-/* audio description */
-	int channels;
-	int sample_size;
-	int compression_id;
-	int packet_size;
-	float sample_rate;
-
-/* MP4 elementary stream descriptor */
-	mp4ff_esds_t esds;
-
-} mp4ff_stsd_table_t;
-
-
-typedef struct
-{
-	int version;
-	long flags;
-	long total_entries;
-	mp4ff_stsd_table_t *table;
-} mp4ff_stsd_t;
-
-
-/* time to sample */
-typedef struct
-{
-	long sample_count;
-	long sample_duration;
-} mp4ff_stts_table_t;
-
-typedef struct
-{
-	int version;
-	long flags;
-	long total_entries;
-	long entries_allocated;
-	mp4ff_stts_table_t *table;
-} mp4ff_stts_t;
-
-
-/* sync sample */
-typedef struct
-{
-	long sample;
-} mp4ff_stss_table_t;
-
-typedef struct
-{
-	int version;
-	long flags;
-	long total_entries;
-	long entries_allocated;
-	mp4ff_stss_table_t *table;
-} mp4ff_stss_t;
-
-
-/* sample to chunk */
-typedef struct
-{
-	long chunk;
-	long samples;
-	long id;
-} mp4ff_stsc_table_t;
-
-typedef struct
-{
-	int version;
-	long flags;
-	long total_entries;
-	
-	long entries_allocated;
-	mp4ff_stsc_table_t *table;
-} mp4ff_stsc_t;
-
-
-/* sample size */
-typedef struct
-{
-	long size;
-} mp4ff_stsz_table_t;
-
-typedef struct
-{
-	int version;
-	long flags;
-	long sample_size;
-	long total_entries;
-
-	long entries_allocated;    /* used by the library for allocating a table */
-	mp4ff_stsz_table_t *table;
-} mp4ff_stsz_t;
-
-
-/* chunk offset */
-typedef struct
-{
-	long offset;
-} mp4ff_stco_table_t;
-
-typedef struct
-{
-	int version;
-	long flags;
-	long total_entries;
-	
-	long entries_allocated;    /* used by the library for allocating a table */
-	mp4ff_stco_table_t *table;
-} mp4ff_stco_t;
-
-/* composition time to sample */
-typedef struct
-{
-	long sample_count;
-	long sample_offset;
-} mp4ff_ctts_table_t;
-
-typedef struct
-{
-	int version;
-	long flags;
-	long total_entries;
-	long entries_allocated;
-	mp4ff_ctts_table_t *table;
-} mp4ff_ctts_t;
-
-
-/* sample table */
-typedef struct
-{
-	int version;
-	long flags;
-	mp4ff_stsd_t stsd;
-	mp4ff_stts_t stts;
-	mp4ff_stss_t stss;
-	mp4ff_stsc_t stsc;
-	mp4ff_stsz_t stsz;
-	mp4ff_stco_t stco;
-	mp4ff_ctts_t ctts;
-} mp4ff_stbl_t;
-
-/* data reference */
-
-typedef struct
-{
-	long size;
-	char type[4];
-	int version;
-	long flags;
-	char *data_reference;
-} mp4ff_dref_table_t;
-
-typedef struct
-{
-	int version;
-	long flags;
-	long total_entries;
-	mp4ff_dref_table_t *table;
-} mp4ff_dref_t;
-
-/* data information */
-
-typedef struct
-{
-	mp4ff_dref_t dref;
-} mp4ff_dinf_t;
-
-/* video media header */
-
-typedef struct
-{
-	int version;
-	long flags;
-	int graphics_mode;
-	int opcolor[3];
-} mp4ff_vmhd_t;
-
-
-/* sound media header */
-
-typedef struct
-{
-	int version;
-	long flags;
-	int balance;
-	int reserved;
-} mp4ff_smhd_t;
-
-/* handler reference */
-
-typedef struct
-{
-	int version;
-	long flags;
-	char component_type[4];
-	char component_subtype[4];
-	long component_manufacturer;
-	long component_flags;
-	long component_flag_mask;
-	char component_name[256];
-} mp4ff_hdlr_t;
-
-/* media information */
-
-typedef struct
-{
-	int is_video;
-	int is_audio;
-	mp4ff_vmhd_t vmhd;
-	mp4ff_smhd_t smhd;
-	mp4ff_stbl_t stbl;
-	mp4ff_hdlr_t hdlr;
-	mp4ff_dinf_t dinf;
-} mp4ff_minf_t;
-
-
-/* media header */
-
-typedef struct
-{
-	int version;
-	long flags;
-	unsigned long creation_time;
-	unsigned long modification_time;
-	long time_scale;
-	long duration;
-	int language;
-	int quality;
-} mp4ff_mdhd_t;
-
-
-/* media */
-
-typedef struct
-{
-	mp4ff_mdhd_t mdhd;
-	mp4ff_minf_t minf;
-	mp4ff_hdlr_t hdlr;
-} mp4ff_mdia_t;
-
-/* edit list */
-typedef struct
-{
-	long duration;
-	long time;
-	float rate;
-} mp4ff_elst_table_t;
-
-typedef struct
-{
-	int version;
-	long flags;
-	long total_entries;
-
-	mp4ff_elst_table_t *table;
-} mp4ff_elst_t;
-
-typedef struct
-{
-	mp4ff_elst_t elst;
-} mp4ff_edts_t;
-
-typedef struct
-{
-	mp4ff_tkhd_t tkhd;
-	mp4ff_mdia_t mdia;
-	mp4ff_edts_t edts;
-} mp4ff_trak_t;
-
-typedef struct
-{
-	int version;
-	long flags;
-	int audioProfileId;
-	int videoProfileId;
-} mp4ff_iods_t;
-
-typedef struct
-{
-	int version;
-	long flags;
-	unsigned long creation_time;
-	unsigned long modification_time;
-	long time_scale;
-	long duration;
-	float preferred_rate;
-	float preferred_volume;
-	char reserved[10];
-	mp4ff_matrix_t matrix;
-	long preview_time;
-	long preview_duration;
-	long poster_time;
-	long selection_time;
-	long selection_duration;
-	long current_time;
-	long next_track_id;
-} mp4ff_mvhd_t;
-
-typedef struct
-{
-	char *copyright;
-	int copyright_len;
-	char *name;
-	int name_len;
-	char *info;
-	int info_len;
-} mp4ff_udta_t;
-
-
-typedef struct
-{
-	int total_tracks;
-
-	mp4ff_mvhd_t mvhd;
-	mp4ff_iods_t iods;
-	mp4ff_trak_t *trak[MAXTRACKS];
-	mp4ff_udta_t udta;
-} mp4ff_moov_t;
-
-typedef struct
-{
-	long start;
-	long size;
-} mp4ff_mdat_t;
-
-
-typedef struct
-{
-	long start;      /* byte start in file */
-	long end;        /* byte endpoint in file */
-	long size;       /* byte size for writing */
-	char type[4];
-} mp4ff_atom_t;
-
-/* table of pointers to every track */
-typedef struct
-{
-	mp4ff_trak_t *track; /* real quicktime track corresponding to this table */
-	int channels;            /* number of audio channels in the track */
-	long current_position;   /* current sample in output file */
-	long current_chunk;      /* current chunk in output file */
-
-	void *codec;
-} mp4ff_audio_map_t;
-
-typedef struct
-{
-	mp4ff_trak_t *track;
-	long current_position;
-	long current_chunk;
-
-/* Array of pointers to frames of raw data when caching frames. */
-	unsigned char **frame_cache;
-	long frames_cached;
-
-	void *codec;
-} mp4ff_video_map_t;
-
-/* file descriptor passed to all routines */
-
-typedef struct
-{
-    size_t (*read)(void *buffer, size_t length);
-    size_t (*write)(void *buffer, size_t length);
-    off_t (*get_position)();
-    off_t (*get_length)();
-    int (*seek)(off_t position);
-} mp4_callback_t;
-
-typedef struct
-{
-	mp4_callback_t *stream;
-	long total_length;
-	mp4ff_mdat_t mdat;
-	mp4ff_moov_t moov;
-	int rd;
-	int wr;
-
-/* mapping of audio channels to movie tracks */
-/* one audio map entry exists for each channel */
-	int total_atracks;
-	mp4ff_audio_map_t *atracks;
-
-/* mapping of video tracks to movie tracks */
-	int total_vtracks;
-	mp4ff_video_map_t *vtracks;
-
-/* for begining and ending frame writes where the user wants to write the  */
-/* file descriptor directly */
-	long offset;
-
-/* I/O */
-	long file_position;      /* Current position of file descriptor */
-
-/* Parameters for frame currently being decoded */
-	int do_scaling;
-	int in_x, in_y, in_w, in_h, out_w, out_h;
-	int color_model;
-
-/* Cached value for mp4ff_video_frame */
-	long last_frame;
-	long last_start;
-	int last_stts_index;
-
-} mp4ff_t;
-
-#endif
--- a/common/mp4ff/smhd.c
+++ /dev/null
@@ -1,46 +1,0 @@
-#include "mp4ff.h"
-
-
-
-
-int mp4ff_smhd_init(mp4ff_smhd_t *smhd)
-{
-	smhd->version = 0;
-	smhd->flags = 0;
-	smhd->balance = 0;
-	smhd->reserved = 0;
-}
-
-int mp4ff_smhd_delete(mp4ff_smhd_t *smhd)
-{
-}
-
-int mp4ff_smhd_dump(mp4ff_smhd_t *smhd)
-{
-	printf("    sound media header\n");
-	printf("     version %d\n", smhd->version);
-	printf("     flags %d\n", smhd->flags);
-	printf("     balance %d\n", smhd->balance);
-	printf("     reserved %d\n", smhd->reserved);
-}
-
-int mp4ff_read_smhd(mp4ff_t *file, mp4ff_smhd_t *smhd)
-{
-	smhd->version = mp4ff_read_char(file);
-	smhd->flags = mp4ff_read_int24(file);
-	smhd->balance = mp4ff_read_int16(file);
-	smhd->reserved = mp4ff_read_int16(file);
-}
-
-int mp4ff_write_smhd(mp4ff_t *file, mp4ff_smhd_t *smhd)
-{
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, "smhd");
-
-	mp4ff_write_char(file, smhd->version);
-	mp4ff_write_int24(file, smhd->flags);
-
-	mp4ff_write_int32(file, 0x00000000);
-
-	mp4ff_atom_write_footer(file, &atom);
-}
--- a/common/mp4ff/stbl.c
+++ /dev/null
@@ -1,132 +1,0 @@
-#include "mp4ff.h"
-
-int mp4ff_stbl_init(mp4ff_stbl_t *stbl)
-{
-	stbl->version = 0;
-	stbl->flags = 0;
-	mp4ff_stsd_init(&(stbl->stsd));
-	mp4ff_stts_init(&(stbl->stts));
-	mp4ff_stss_init(&(stbl->stss));
-	mp4ff_stsc_init(&(stbl->stsc));
-	mp4ff_stsz_init(&(stbl->stsz));
-	mp4ff_stco_init(&(stbl->stco));
-	mp4ff_ctts_init(&(stbl->ctts));
-}
-
-int mp4ff_stbl_init_video(mp4ff_t *file, 
-							mp4ff_stbl_t *stbl, 
-							int frame_w,
-							int frame_h, 
-							int time_scale, 
-							float frame_rate,
-							char *compressor)
-{
-	mp4ff_stsd_init_video(file, &(stbl->stsd), frame_w, frame_h, frame_rate, compressor);
-	mp4ff_stts_init_video(file, &(stbl->stts), time_scale, frame_rate);
-	mp4ff_stss_init_common(file, &(stbl->stss));
-	mp4ff_stsc_init_video(file, &(stbl->stsc));
-	mp4ff_stsz_init_video(file, &(stbl->stsz));
-	mp4ff_stco_init_common(file, &(stbl->stco));
-	mp4ff_ctts_init_common(file, &(stbl->ctts));
-}
-
-
-int mp4ff_stbl_init_audio(mp4ff_t *file, 
-							mp4ff_stbl_t *stbl, 
-							int channels, 
-							int sample_rate, 
-							int bits, 
-							int sample_size,
-							int time_scale,
-							int sample_duration,
-							char *compressor)
-{
-	mp4ff_stsd_init_audio(file, &(stbl->stsd), channels, sample_rate, bits, compressor);
-	mp4ff_stts_init_audio(file, &(stbl->stts), time_scale, sample_duration);
-	mp4ff_stss_init_common(file, &(stbl->stss));
-	mp4ff_stsc_init_audio(file, &(stbl->stsc));
-	mp4ff_stsz_init_audio(file, &(stbl->stsz), sample_size);
-	mp4ff_stco_init_common(file, &(stbl->stco));
-	mp4ff_ctts_init_common(file, &(stbl->ctts));
-}
-
-int mp4ff_stbl_delete(mp4ff_stbl_t *stbl)
-{
-	mp4ff_stsd_delete(&(stbl->stsd));
-	mp4ff_stts_delete(&(stbl->stts));
-	mp4ff_stss_delete(&(stbl->stss));
-	mp4ff_stsc_delete(&(stbl->stsc));
-	mp4ff_stsz_delete(&(stbl->stsz));
-	mp4ff_stco_delete(&(stbl->stco));
-	mp4ff_ctts_delete(&(stbl->ctts));
-}
-
-int mp4ff_stbl_dump(void *minf_ptr, mp4ff_stbl_t *stbl)
-{
-	printf("    sample table\n");
-	mp4ff_stsd_dump(minf_ptr, &(stbl->stsd));
-	mp4ff_stts_dump(&(stbl->stts));
-	mp4ff_stss_dump(&(stbl->stss));
-	mp4ff_stsc_dump(&(stbl->stsc));
-	mp4ff_stsz_dump(&(stbl->stsz));
-	mp4ff_stco_dump(&(stbl->stco));
-	mp4ff_ctts_dump(&(stbl->ctts));
-}
-
-int mp4ff_read_stbl(mp4ff_t *file, mp4ff_minf_t *minf, mp4ff_stbl_t *stbl, mp4ff_atom_t *parent_atom)
-{
-	mp4ff_atom_t leaf_atom;
-
-	do
-	{
-		mp4ff_atom_read_header(file, &leaf_atom);
-
-/* mandatory */
-		if(mp4ff_atom_is(&leaf_atom, "stsd"))
-			{ 
-				mp4ff_read_stsd(file, minf, &(stbl->stsd)); 
-/* Some codecs store extra information at the end of this */
-				mp4ff_atom_skip(file, &leaf_atom);
-			}
-		else
-		if(mp4ff_atom_is(&leaf_atom, "stts"))
-			{ mp4ff_read_stts(file, &(stbl->stts)); }
-		else
-		if(mp4ff_atom_is(&leaf_atom, "stss"))
-			{ mp4ff_read_stss(file, &(stbl->stss)); }
-		else
-		if(mp4ff_atom_is(&leaf_atom, "stsc"))
-			{ mp4ff_read_stsc(file, &(stbl->stsc)); }
-		else
-		if(mp4ff_atom_is(&leaf_atom, "stsz"))
-			{ mp4ff_read_stsz(file, &(stbl->stsz)); }
-		else
-		if(mp4ff_atom_is(&leaf_atom, "stco"))
-			{ mp4ff_read_stco(file, &(stbl->stco)); }
-		else
-		if(mp4ff_atom_is(&leaf_atom, "ctts"))
-			{ mp4ff_read_ctts(file, &(stbl->ctts)); }
-		else
-			mp4ff_atom_skip(file, &leaf_atom);
-	}while(mp4ff_position(file) < parent_atom->end);
-
-	return 0;
-}
-
-int mp4ff_write_stbl(mp4ff_t *file, mp4ff_minf_t *minf, mp4ff_stbl_t *stbl)
-{
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, "stbl");
-
-	mp4ff_write_stsd(file, minf, &(stbl->stsd));
-	mp4ff_write_stts(file, &(stbl->stts));
-	mp4ff_write_stss(file, &(stbl->stss));
-	mp4ff_write_stsc(file, &(stbl->stsc));
-	mp4ff_write_stsz(file, &(stbl->stsz));
-	mp4ff_write_stco(file, &(stbl->stco));
-	mp4ff_write_ctts(file, &(stbl->ctts));
-
-	mp4ff_atom_write_footer(file, &atom);
-}
-
-
--- a/common/mp4ff/stco.c
+++ /dev/null
@@ -1,92 +1,0 @@
-#include "mp4ff.h"
-
-
-
-int mp4ff_stco_init(mp4ff_stco_t *stco)
-{
-	stco->version = 0;
-	stco->flags = 0;
-	stco->total_entries = 0;
-	stco->entries_allocated = 0;
-}
-
-int mp4ff_stco_delete(mp4ff_stco_t *stco)
-{
-	if(stco->total_entries) free(stco->table);
-	stco->total_entries = 0;
-	stco->entries_allocated = 0;
-}
-
-int mp4ff_stco_init_common(mp4ff_t *file, mp4ff_stco_t *stco)
-{
-	if(!stco->entries_allocated)
-	{
-		stco->entries_allocated = 2000;
-		stco->total_entries = 0;
-		stco->table = (mp4ff_stco_table_t*)malloc(sizeof(mp4ff_stco_table_t) * stco->entries_allocated);
-/*printf("mp4ff_stco_init_common %x\n", stco->table); */
-	}
-}
-
-int mp4ff_stco_dump(mp4ff_stco_t *stco)
-{
-	int i;
-	printf("     chunk offset\n");
-	printf("      version %d\n", stco->version);
-	printf("      flags %d\n", stco->flags);
-	printf("      total_entries %d\n", stco->total_entries);
-	for(i = 0; i < stco->total_entries; i++)
-	{
-		printf("       offset %d %x\n", i, stco->table[i].offset);
-	}
-}
-
-int mp4ff_read_stco(mp4ff_t *file, mp4ff_stco_t *stco)
-{
-	int i;
-	stco->version = mp4ff_read_char(file);
-	stco->flags = mp4ff_read_int24(file);
-	stco->total_entries = mp4ff_read_int32(file);
-/*printf("stco->total_entries %d %x\n", stco->total_entries, stco); */
-	stco->entries_allocated = stco->total_entries;
-	stco->table = (mp4ff_stco_table_t*)malloc(sizeof(mp4ff_stco_table_t) * stco->entries_allocated);
-	for(i = 0; i < stco->total_entries; i++)
-	{
-		stco->table[i].offset = mp4ff_read_int32(file);
-	}
-}
-
-int mp4ff_write_stco(mp4ff_t *file, mp4ff_stco_t *stco)
-{
-	int i;
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, "stco");
-
-	mp4ff_write_char(file, stco->version);
-	mp4ff_write_int24(file, stco->flags);
-	mp4ff_write_int32(file, stco->total_entries);
-	for(i = 0; i < stco->total_entries; i++)
-	{
-		mp4ff_write_int32(file, stco->table[i].offset);
-	}
-
-	mp4ff_atom_write_footer(file, &atom);
-}
-
-int mp4ff_update_stco(mp4ff_stco_t *stco, long chunk, long offset)
-{
-	mp4ff_stco_table_t *new_table;
-	long i;
-
-	if(chunk > stco->entries_allocated)
-	{
-		stco->entries_allocated = chunk * 2;
-		stco->table = (mp4ff_stco_table_t*)realloc(stco->table,
-			sizeof(mp4ff_stco_table_t) * stco->entries_allocated);
-	}
-	
-	stco->table[chunk - 1].offset = offset;
-	if(chunk > stco->total_entries) 
-		stco->total_entries = chunk;
-}
-
--- a/common/mp4ff/stsc.c
+++ /dev/null
@@ -1,146 +1,0 @@
-#include "mp4ff.h"
-
-
-
-int mp4ff_stsc_init(mp4ff_stsc_t *stsc)
-{
-	stsc->version = 0;
-	stsc->flags = 0;
-	stsc->total_entries = 0;
-	stsc->entries_allocated = 0;
-}
-
-int mp4ff_stsc_init_table(mp4ff_t *file, mp4ff_stsc_t *stsc)
-{
-	if(!stsc->total_entries)
-	{
-		stsc->total_entries = 1;
-		stsc->entries_allocated = 1;
-		stsc->table = (mp4ff_stsc_table_t*)malloc(sizeof(mp4ff_stsc_table_t) * stsc->entries_allocated);
-	}
-}
-
-int mp4ff_stsc_init_video(mp4ff_t *file, mp4ff_stsc_t *stsc)
-{
-	mp4ff_stsc_table_t *table;
-	mp4ff_stsc_init_table(file, stsc);
-	table = &(stsc->table[0]);
-	table->chunk = 1;
-	table->samples = 1;
-	table->id = 1;
-}
-
-int mp4ff_stsc_init_audio(mp4ff_t *file, mp4ff_stsc_t *stsc)
-{
-	mp4ff_stsc_table_t *table;
-	mp4ff_stsc_init_table(file, stsc);
-	table = &(stsc->table[0]);
-	table->chunk = 1;
-	table->samples = 0;         /* set this after completion or after every audio chunk is written */
-	table->id = 1;
-}
-
-int mp4ff_stsc_delete(mp4ff_stsc_t *stsc)
-{
-	if(stsc->total_entries) free(stsc->table);
-	stsc->total_entries = 0;
-}
-
-int mp4ff_stsc_dump(mp4ff_stsc_t *stsc)
-{
-	int i;
-	printf("     sample to chunk\n");
-	printf("      version %d\n", stsc->version);
-	printf("      flags %d\n", stsc->flags);
-	printf("      total_entries %d\n", stsc->total_entries);
-	for(i = 0; i < stsc->total_entries; i++)
-	{
-		printf("       chunk %d samples %d id %d\n", 
-			stsc->table[i].chunk, stsc->table[i].samples, stsc->table[i].id);
-	}
-}
-
-int mp4ff_read_stsc(mp4ff_t *file, mp4ff_stsc_t *stsc)
-{
-	int i;
-	stsc->version = mp4ff_read_char(file);
-	stsc->flags = mp4ff_read_int24(file);
-	stsc->total_entries = mp4ff_read_int32(file);
-	
-	stsc->entries_allocated = stsc->total_entries;
-	stsc->table = (mp4ff_stsc_table_t*)malloc(sizeof(mp4ff_stsc_table_t) * stsc->total_entries);
-	for(i = 0; i < stsc->total_entries; i++)
-	{
-		stsc->table[i].chunk = mp4ff_read_int32(file);
-		stsc->table[i].samples = mp4ff_read_int32(file);
-		stsc->table[i].id = mp4ff_read_int32(file);
-	}
-}
-
-
-int mp4ff_write_stsc(mp4ff_t *file, mp4ff_stsc_t *stsc)
-{
-	int i, last_same;
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, "stsc");
-
-	for(i = 1, last_same = 0; i < stsc->total_entries; i++)
-	{
-		if(stsc->table[i].samples != stsc->table[last_same].samples)
-		{
-/* An entry has a different sample count. */
-			last_same++;
-			if(last_same < i)
-			{
-/* Move it up the list. */
-				stsc->table[last_same] = stsc->table[i];
-			}
-		}
-	}
-	last_same++;
-	stsc->total_entries = last_same;
-
-
-	mp4ff_write_char(file, stsc->version);
-	mp4ff_write_int24(file, stsc->flags);
-	mp4ff_write_int32(file, stsc->total_entries);
-	for(i = 0; i < stsc->total_entries; i++)
-	{
-		mp4ff_write_int32(file, stsc->table[i].chunk);
-		mp4ff_write_int32(file, stsc->table[i].samples);
-		mp4ff_write_int32(file, stsc->table[i].id);
-	}
-
-	mp4ff_atom_write_footer(file, &atom);
-}
-
-int mp4ff_update_stsc(mp4ff_stsc_t *stsc, long chunk, long samples)
-{
-/*	mp4ff_stsc_table_t *table = stsc->table; */
-	mp4ff_stsc_table_t *new_table;
-	long i;
-
-	if(chunk > stsc->entries_allocated)
-	{
-		stsc->entries_allocated = chunk * 2;
-		new_table = (mp4ff_stsc_table_t*)malloc(sizeof(mp4ff_stsc_table_t) * stsc->entries_allocated);
-		for(i = 0; i < stsc->total_entries; i++) new_table[i] = stsc->table[i];
-		free(stsc->table);
-		stsc->table = new_table;
-	}
-
-	stsc->table[chunk - 1].samples = samples;
-	stsc->table[chunk - 1].chunk = chunk;
-	stsc->table[chunk - 1].id = 1;
-	if(chunk > stsc->total_entries) stsc->total_entries = chunk;
-	return 0;
-}
-
-/* Optimizing while writing doesn't allow seeks during recording so */
-/* entries are created for every chunk and only optimized during */
-/* writeout.  Unfortunately there's no way to keep audio synchronized */
-/* after overwriting  a recording as the fractional audio chunk in the */
-/* middle always overwrites the previous location of a larger chunk.  On */
-/* writing, the table must be optimized.  RealProducer requires an  */
-/* optimized table. */
-
--- a/common/mp4ff/stsd.c
+++ /dev/null
@@ -1,117 +1,0 @@
-#include "mp4ff.h"
-
-
-int mp4ff_stsd_init(mp4ff_stsd_t *stsd)
-{
-	stsd->version = 0;
-	stsd->flags = 0;
-	stsd->total_entries = 0;
-}
-
-int mp4ff_stsd_init_table(mp4ff_stsd_t *stsd)
-{
-	if(!stsd->total_entries)
-	{
-		stsd->total_entries = 1;
-		stsd->table = (mp4ff_stsd_table_t*)malloc(sizeof(mp4ff_stsd_table_t) * stsd->total_entries);
-		mp4ff_stsd_table_init(&(stsd->table[0]));
-	}
-}
-
-int mp4ff_stsd_init_video(mp4ff_t *file, 
-								mp4ff_stsd_t *stsd, 
-								int frame_w,
-								int frame_h, 
-								float frame_rate,
-								char *compression)
-{
-	mp4ff_stsd_table_t *table;
-	mp4ff_stsd_init_table(stsd);
-	table = &(stsd->table[0]);
-
-	mp4ff_copy_char32(table->format, compression);
-	table->width = frame_w;
-	table->height = frame_h;
-	table->frames_per_sample = 1;
-	table->depth = 24;
-}
-
-int mp4ff_stsd_init_audio(mp4ff_t *file, 
-							mp4ff_stsd_t *stsd, 
-							int channels,
-							int sample_rate, 
-							int bits, 
-							char *compressor)
-{
-	mp4ff_stsd_table_t *table;
-	mp4ff_stsd_init_table(stsd);
-	table = &(stsd->table[0]);
-
-	mp4ff_copy_char32(table->format, compressor);
-	table->channels = channels;
-	table->sample_size = bits;
-	table->sample_rate = sample_rate;
-}
-
-int mp4ff_stsd_delete(mp4ff_stsd_t *stsd)
-{
-	int i;
-	if(stsd->total_entries)
-	{
-		for(i = 0; i < stsd->total_entries; i++)
-			mp4ff_stsd_table_delete(&(stsd->table[i]));
-		free(stsd->table);
-	}
-
-	stsd->total_entries = 0;
-}
-
-int mp4ff_stsd_dump(void *minf_ptr, mp4ff_stsd_t *stsd)
-{
-	int i;
-	printf("     sample description\n");
-	printf("      version %d\n", stsd->version);
-	printf("      flags %d\n", stsd->flags);
-	printf("      total_entries %d\n", stsd->total_entries);
-	
-	for(i = 0; i < stsd->total_entries; i++)
-	{
-		mp4ff_stsd_table_dump(minf_ptr, &(stsd->table[i]));
-	}
-}
-
-int mp4ff_read_stsd(mp4ff_t *file, mp4ff_minf_t *minf, mp4ff_stsd_t *stsd)
-{
-	int i;
-	mp4ff_atom_t leaf_atom;
-
-	stsd->version = mp4ff_read_char(file);
-	stsd->flags = mp4ff_read_int24(file);
-	stsd->total_entries = mp4ff_read_int32(file);
-	stsd->table = (mp4ff_stsd_table_t*)malloc(sizeof(mp4ff_stsd_table_t) * stsd->total_entries);
-	for(i = 0; i < stsd->total_entries; i++)
-	{
-		mp4ff_stsd_table_init(&(stsd->table[i]));
-		mp4ff_read_stsd_table(file, minf, &(stsd->table[i]));
-	}
-}
-
-int mp4ff_write_stsd(mp4ff_t *file, mp4ff_minf_t *minf, mp4ff_stsd_t *stsd)
-{
-	mp4ff_atom_t atom;
-	int i;
-	mp4ff_atom_write_header(file, &atom, "stsd");
-
-	mp4ff_write_char(file, stsd->version);
-	mp4ff_write_int24(file, stsd->flags);
-	mp4ff_write_int32(file, stsd->total_entries);
-	for(i = 0; i < stsd->total_entries; i++)
-	{
-		mp4ff_write_stsd_table(file, minf, stsd->table);
-	}
-
-	mp4ff_atom_write_footer(file, &atom);
-}
-
-
-
--- a/common/mp4ff/stsdtable.c
+++ /dev/null
@@ -1,253 +1,0 @@
-#include "mp4ff.h"
-
-
-int mp4ff_stsd_table_init(mp4ff_stsd_table_t *table)
-{
-	int i;
-	table->format[0] = 'y';
-	table->format[1] = 'u';
-	table->format[2] = 'v';
-	table->format[3] = '2';
-	for(i = 0; i < 6; i++) table->reserved[i] = 0;
-	table->data_reference = 1;
-
-	table->version = 0;
-	table->revision = 0;
- 	table->vendor[0] = 'l';
- 	table->vendor[1] = 'n';
- 	table->vendor[2] = 'u';
- 	table->vendor[3] = 'x';
-
-	table->temporal_quality = 0;
-	table->spatial_quality = 258;
-	table->width = 0;
-	table->height = 0;
-	table->dpi_horizontal = 72;
-	table->dpi_vertical = 72;
-	table->data_size = 0;
-	table->frames_per_sample = 1;
-	for(i = 0; i < 32; i++) table->compressor_name[i] = 0;
-	sprintf(table->compressor_name, "Quicktime for Linux");
-	table->depth = 24;
-	table->gamma = 0;
-	table->fields = 0;
-	table->field_dominance = 1;
-	
-	table->channels = 0;
-	table->sample_size = 0;
-	table->compression_id = 0;
-	table->packet_size = 0;
-	table->sample_rate = 0;
-
-	mp4ff_esds_init(&(table->esds));
-}
-
-int mp4ff_stsd_table_delete(mp4ff_stsd_table_t *table)
-{
-	mp4ff_esds_delete(&(table->esds));
-}
-
-int mp4ff_stsd_table_dump(void *minf_ptr, mp4ff_stsd_table_t *table)
-{
-	mp4ff_minf_t *minf = minf_ptr;
-	printf("       format %c%c%c%c\n", table->format[0], table->format[1], table->format[2], table->format[3]);
-	mp4ff_print_chars("       reserved ", table->reserved, 6);
-	printf("       data_reference %d\n", table->data_reference);
-
-	if(minf->is_audio) mp4ff_stsd_audio_dump(table);
-	if(minf->is_video) mp4ff_stsd_video_dump(table);
-}
-
-int mp4ff_stsd_audio_dump(mp4ff_stsd_table_t *table)
-{
-	printf("       version %d\n", table->version);
-	printf("       revision %d\n", table->revision);
-	printf("       vendor %c%c%c%c\n", table->vendor[0], table->vendor[1], table->vendor[2], table->vendor[3]);
-	printf("       channels %d\n", table->channels);
-	printf("       sample_size %d\n", table->sample_size);
-	printf("       compression_id %d\n", table->compression_id);
-	printf("       packet_size %d\n", table->packet_size);
-	printf("       sample_rate %f\n", table->sample_rate);
-
-	mp4ff_esds_dump(&(table->esds));
-}
-
-int mp4ff_stsd_video_dump(mp4ff_stsd_table_t *table)
-{
-	printf("       version %d\n", table->version);
-	printf("       revision %d\n", table->revision);
-	printf("       vendor %c%c%c%c\n", table->vendor[0], table->vendor[1], table->vendor[2], table->vendor[3]);
-	printf("       temporal_quality %ld\n", table->temporal_quality);
-	printf("       spatial_quality %ld\n", table->spatial_quality);
-	printf("       width %d\n", table->width);
-	printf("       height %d\n", table->height);
-	printf("       dpi_horizontal %f\n", table->dpi_horizontal);
-	printf("       dpi_vertical %f\n", table->dpi_vertical);
-	printf("       data_size %ld\n", table->data_size);
-	printf("       frames_per_sample %d\n", table->frames_per_sample);
-	printf("       compressor_name %s\n", table->compressor_name);
-	printf("       depth %d\n", table->depth);
-	printf("       gamma %f\n", table->gamma);
-	if(table->fields)
-	{
-		printf("       fields %d\n", table->fields);
-		printf("       field dominance %d\n", table->field_dominance);
-	}
-	mp4ff_esds_dump(&(table->esds));
-}
-
-int mp4ff_read_stsd_table(mp4ff_t *file, mp4ff_minf_t *minf, mp4ff_stsd_table_t *table)
-{
-	mp4ff_atom_t leaf_atom;
-
-	mp4ff_atom_read_header(file, &leaf_atom);
-	
-	table->format[0] = leaf_atom.type[0];
-	table->format[1] = leaf_atom.type[1];
-	table->format[2] = leaf_atom.type[2];
-	table->format[3] = leaf_atom.type[3];
-	mp4ff_read_data(file, table->reserved, 6);
-	table->data_reference = mp4ff_read_int16(file);
-
-	if(minf->is_audio) mp4ff_read_stsd_audio(file, table, &leaf_atom);
-	if(minf->is_video) mp4ff_read_stsd_video(file, table, &leaf_atom);
-}
-
-int mp4ff_write_stsd_table(mp4ff_t *file, mp4ff_minf_t *minf, mp4ff_stsd_table_t *table)
-{
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, table->format);
-/*printf("mp4ff_write_stsd_table %c%c%c%c\n", table->format[0], table->format[1], table->format[2], table->format[3]); */
-	mp4ff_write_data(file, table->reserved, 6);
-	mp4ff_write_int16(file, table->data_reference);
-	
-	if(minf->is_audio) mp4ff_write_stsd_audio(file, table);
-	if(minf->is_video) mp4ff_write_stsd_video(file, table);
-
-	mp4ff_atom_write_footer(file, &atom);
-}
-
-int mp4ff_read_stsd_audio(mp4ff_t *file, mp4ff_stsd_table_t *table, mp4ff_atom_t *parent_atom)
-{
-	table->version = mp4ff_read_int16(file);
-	table->revision = mp4ff_read_int16(file);
-	mp4ff_read_data(file, table->vendor, 4);
-	table->channels = mp4ff_read_int16(file);
-	table->sample_size = mp4ff_read_int16(file);
-	table->compression_id = mp4ff_read_int16(file);
-	table->packet_size = mp4ff_read_int16(file);
-	table->sample_rate = mp4ff_read_fixed32(file);
-
-	while (mp4ff_position(file) < parent_atom->end) {
-		mp4ff_atom_t leaf_atom;
-
-		mp4ff_atom_read_header(file, &leaf_atom);
-
-		if(mp4ff_atom_is(&leaf_atom, "esds")) {
-			mp4ff_read_esds(file, &(table->esds));
-			mp4ff_atom_skip(file, &leaf_atom);
-		} else {
-			mp4ff_atom_skip(file, &leaf_atom);
-		}
-	}
-}
-
-int mp4ff_write_stsd_audio(mp4ff_t *file, mp4ff_stsd_table_t *table)
-{
-	mp4ff_write_int32(file, 0);
-	mp4ff_write_int32(file, 0);
-	mp4ff_write_int16(file, 2);
-	mp4ff_write_int16(file, 16);
-	mp4ff_write_int32(file, 0);
-	mp4ff_write_int16(file, table->sample_rate);
-	mp4ff_write_int16(file, 0);
-	mp4ff_write_esds_audio(file, &(table->esds), file->atracks[0].track->tkhd.track_id);
-}
-
-int mp4ff_read_stsd_video(mp4ff_t *file, mp4ff_stsd_table_t *table, mp4ff_atom_t *parent_atom)
-{
-	mp4ff_atom_t leaf_atom;
-	int len;
-	
-	table->version = mp4ff_read_int16(file);
-	table->revision = mp4ff_read_int16(file);
-	mp4ff_read_data(file, table->vendor, 4);
-	table->temporal_quality = mp4ff_read_int32(file);
-	table->spatial_quality = mp4ff_read_int32(file);
-	table->width = mp4ff_read_int16(file);
-	table->height = mp4ff_read_int16(file);
-	table->dpi_horizontal = mp4ff_read_fixed32(file);
-	table->dpi_vertical = mp4ff_read_fixed32(file);
-	table->data_size = mp4ff_read_int32(file);
-	table->frames_per_sample = mp4ff_read_int16(file);
-	len = mp4ff_read_char(file);
-	mp4ff_read_data(file, table->compressor_name, 31);
-	table->depth = mp4ff_read_int16(file);
-		
-	while(mp4ff_position(file) < parent_atom->end)
-	{
-		mp4ff_atom_read_header(file, &leaf_atom);
-		
-		if(mp4ff_atom_is(&leaf_atom, "gama"))
-		{
-			table->gamma= mp4ff_read_fixed32(file);
-		}
-		else
-		if(mp4ff_atom_is(&leaf_atom, "fiel"))
-		{
-			table->fields = mp4ff_read_char(file);
-			table->field_dominance = mp4ff_read_char(file);
-		}
-		else
-/* 		if(mp4ff_atom_is(&leaf_atom, "mjqt")) */
-/* 		{ */
-/* 			mp4ff_read_mjqt(file, &(table->mjqt)); */
-/* 		} */
-/* 		else */
-/* 		if(mp4ff_atom_is(&leaf_atom, "mjht")) */
-/* 		{ */
-/* 			mp4ff_read_mjht(file, &(table->mjht)); */
-/* 		} */
-/* 		else */
-		if(mp4ff_atom_is(&leaf_atom, "esds"))
-		{
-			mp4ff_read_esds(file, &(table->esds));
-			mp4ff_atom_skip(file, &leaf_atom);
-		}
-		else
-		{
-			mp4ff_atom_skip(file, &leaf_atom);
-		}
-	}
-}
-
-int mp4ff_write_stsd_video(mp4ff_t *file, mp4ff_stsd_table_t *table)
-{
-	int i;
-
-	for (i = 0; i < 4; i++) {
-		mp4ff_write_int32(file, 0);
-	}
-	mp4ff_write_int16(file, table->width);
-	mp4ff_write_int16(file, table->height);
-	mp4ff_write_int32(file, 0x00480000);
-	mp4ff_write_int32(file, 0x00480000);
-	mp4ff_write_int32(file, 0);
-	mp4ff_write_int16(file, 1);
-	for (i = 0; i < 32; i++) {
-		mp4ff_write_char(file, 0);
-	}
-	mp4ff_write_int16(file, 24);
-	mp4ff_write_int16(file, -1);
-	mp4ff_write_esds_video(file, &(table->esds), file->vtracks[0].track->tkhd.track_id);
-
-	if(table->fields)
-	{
-		mp4ff_atom_t atom;
-
-		mp4ff_atom_write_header(file, &atom, "fiel");
-		mp4ff_write_char(file, table->fields);
-		mp4ff_write_char(file, table->field_dominance);
-		mp4ff_atom_write_footer(file, &atom);
-	}
-}
--- a/common/mp4ff/stss.c
+++ /dev/null
@@ -1,87 +1,0 @@
-#include "mp4ff.h"
-
-
-int mp4ff_stss_init(mp4ff_stss_t *stss)
-{
-	stss->version = 0;
-	stss->flags = 0;
-	stss->total_entries = 0;
-	stss->entries_allocated = 0;
-}
-
-int mp4ff_stss_init_common(mp4ff_t *file, mp4ff_stss_t *stss)
-{
-	if (stss->entries_allocated == 0) {
-		stss->entries_allocated = 100;
-		stss->table = (mp4ff_stss_table_t*)
-			malloc(sizeof(mp4ff_stss_table_t) * stss->entries_allocated);
-	}
-}
-
-int mp4ff_stss_delete(mp4ff_stss_t *stss)
-{
-	if(stss->total_entries) 
-		free(stss->table);
-	stss->total_entries = 0;
-}
-
-int mp4ff_stss_dump(mp4ff_stss_t *stss)
-{
-	int i;
-	printf("     sync sample\n");
-	printf("      version %d\n", stss->version);
-	printf("      flags %d\n", stss->flags);
-	printf("      total_entries %d\n", stss->total_entries);
-	for(i = 0; i < stss->total_entries; i++)
-	{
-		printf("       sample %u\n", stss->table[i].sample);
-	}
-}
-
-int mp4ff_read_stss(mp4ff_t *file, mp4ff_stss_t *stss)
-{
-	int i;
-	stss->version = mp4ff_read_char(file);
-	stss->flags = mp4ff_read_int24(file);
-	stss->total_entries = mp4ff_read_int32(file);
-	
-	stss->table = (mp4ff_stss_table_t*)malloc(sizeof(mp4ff_stss_table_t) * stss->total_entries);
-	for(i = 0; i < stss->total_entries; i++)
-	{
-		stss->table[i].sample = mp4ff_read_int32(file);
-	}
-}
-
-
-int mp4ff_write_stss(mp4ff_t *file, mp4ff_stss_t *stss)
-{
-	int i;
-	mp4ff_atom_t atom;
-
-	if(stss->total_entries)
-	{
-		mp4ff_atom_write_header(file, &atom, "stss");
-
-		mp4ff_write_char(file, stss->version);
-		mp4ff_write_int24(file, stss->flags);
-		mp4ff_write_int32(file, stss->total_entries);
-		for(i = 0; i < stss->total_entries; i++)
-		{
-			mp4ff_write_int32(file, stss->table[i].sample);
-		}
-
-		mp4ff_atom_write_footer(file, &atom);
-	}
-}
-
-int mp4ff_update_stss(mp4ff_stss_t *stss, long sample)
-{
-	if (stss->total_entries >= stss->entries_allocated) {
-		stss->entries_allocated *= 2;
-		stss->table = (mp4ff_stss_table_t*)realloc(stss->table,
-			sizeof(mp4ff_stss_table_t) * stss->entries_allocated);
-	}
-	
-	stss->table[stss->total_entries++].sample = sample;
-}
-
--- a/common/mp4ff/stsz.c
+++ /dev/null
@@ -1,137 +1,0 @@
-#include "mp4ff.h"
-
-
-
-int mp4ff_stsz_init(mp4ff_stsz_t *stsz)
-{
-	stsz->version = 0;
-	stsz->flags = 0;
-	stsz->sample_size = 0;
-	stsz->total_entries = 0;
-	stsz->entries_allocated = 0;
-}
-
-int mp4ff_stsz_init_video(mp4ff_t *file, mp4ff_stsz_t *stsz)
-{
-	stsz->sample_size = 0;
-	if(!stsz->entries_allocated)
-	{
-		stsz->entries_allocated = 2000;
-		stsz->total_entries = 0;
-		stsz->table = (mp4ff_stsz_table_t*)malloc(sizeof(mp4ff_stsz_table_t) * stsz->entries_allocated);
-	}
-}
-
-int mp4ff_stsz_init_audio(mp4ff_t *file, mp4ff_stsz_t *stsz, int sample_size)
-{
-	stsz->sample_size = sample_size;	/* if == 0, then use table */
-	stsz->total_entries = 0;   /* set this when closing */
-	stsz->entries_allocated = 0;
-}
-
-int mp4ff_stsz_delete(mp4ff_stsz_t *stsz)
-{
-	if(!stsz->sample_size && stsz->total_entries) 
-		free(stsz->table);
-	stsz->total_entries = 0;
-	stsz->entries_allocated = 0;
-}
-
-int mp4ff_stsz_dump(mp4ff_stsz_t *stsz)
-{
-	int i;
-	printf("     sample size\n");
-	printf("      version %d\n", stsz->version);
-	printf("      flags %d\n", stsz->flags);
-	printf("      sample_size %d\n", stsz->sample_size);
-	printf("      total_entries %d\n", stsz->total_entries);
-	
-	if(!stsz->sample_size)
-	{
-		for(i = 0; i < stsz->total_entries; i++)
-		{
-			printf("       sample_size %d\n", stsz->table[i].size);
-		}
-	}
-}
-
-int mp4ff_read_stsz(mp4ff_t *file, mp4ff_stsz_t *stsz)
-{
-	int i;
-	stsz->version = mp4ff_read_char(file);
-	stsz->flags = mp4ff_read_int24(file);
-	stsz->sample_size = mp4ff_read_int32(file);
-	stsz->total_entries = mp4ff_read_int32(file);
-	stsz->entries_allocated = stsz->total_entries;
-	if(!stsz->sample_size)
-	{
-		stsz->table = (mp4ff_stsz_table_t*)malloc(sizeof(mp4ff_stsz_table_t) * stsz->entries_allocated);
-		for(i = 0; i < stsz->total_entries; i++)
-		{
-			stsz->table[i].size = mp4ff_read_int32(file);
-		}
-	}
-}
-
-int mp4ff_write_stsz(mp4ff_t *file, mp4ff_stsz_t *stsz)
-{
-	int i, result;
-	mp4ff_atom_t atom;
-
-	mp4ff_atom_write_header(file, &atom, "stsz");
-
-/* optimize if possible */
-/* Xanim requires an unoptimized table for video. */
-/* 	if(!stsz->sample_size) */
-/* 	{ */
-/* 		for(i = 0, result = 0; i < stsz->total_entries && !result; i++) */
-/* 		{ */
-/* 			if(stsz->table[i].size != stsz->table[0].size) result = 1; */
-/* 		} */
-/* 		 */
-/* 		if(!result) */
-/* 		{ */
-/* 			stsz->sample_size = stsz->table[0].size; */
-/* 			stsz->total_entries = 0; */
-/* 			free(stsz->table); */
-/* 		} */
-/* 	} */
-
-	mp4ff_write_char(file, stsz->version);
-	mp4ff_write_int24(file, stsz->flags);
-	mp4ff_write_int32(file, stsz->sample_size);
-	if(stsz->sample_size)
-	{
-		mp4ff_write_int32(file, stsz->total_entries);
-	}
-	else
-	{
-		mp4ff_write_int32(file, stsz->total_entries);
-		for(i = 0; i < stsz->total_entries; i++)
-		{
-			mp4ff_write_int32(file, stsz->table[i].size);
-		}
-	}
-
-	mp4ff_atom_write_footer(file, &atom);
-}
-
-int mp4ff_update_stsz(mp4ff_stsz_t *stsz, long sample, long sample_size)
-{
-	mp4ff_stsz_table_t *new_table;
-	int i;
-
-	if(!stsz->sample_size)
-	{
-		if(sample >= stsz->entries_allocated)
-		{
-			stsz->entries_allocated = sample * 2;
-			stsz->table = (mp4ff_stsz_table_t *)realloc(stsz->table,
-				sizeof(mp4ff_stsz_table_t) * stsz->entries_allocated);
-		}
-
-		stsz->table[sample].size = sample_size;
-		if(sample >= stsz->total_entries) 
-			stsz->total_entries = sample + 1;
-	}
-}
--- a/common/mp4ff/stts.c
+++ /dev/null
@@ -1,113 +1,0 @@
-#include "mp4ff.h"
-
-
-
-int mp4ff_stts_init(mp4ff_stts_t *stts)
-{
-	stts->version = 0;
-	stts->flags = 0;
-	stts->total_entries = 0;
-	stts->entries_allocated = 0;
-}
-
-int mp4ff_stts_init_table(mp4ff_stts_t *stts)
-{
-	if(!stts->entries_allocated)
-	{
-		stts->entries_allocated = 1;
-		stts->table = (mp4ff_stts_table_t*)
-			malloc(sizeof(mp4ff_stts_table_t) * stts->entries_allocated);
-		stts->total_entries = 1;
-	}
-}
-
-int mp4ff_stts_init_video(mp4ff_t *file, mp4ff_stts_t *stts, int time_scale, float frame_rate)
-{
-	mp4ff_stts_table_t *table;
-	mp4ff_stts_init_table(stts);
-	table = &(stts->table[0]);
-
-	table->sample_count = 0;      /* need to set this when closing */
-	table->sample_duration = time_scale / frame_rate;
-}
-
-int mp4ff_stts_init_audio(mp4ff_t *file, mp4ff_stts_t *stts, int time_scale, int sample_duration)
-{
-	mp4ff_stts_table_t *table;
-	mp4ff_stts_init_table(stts);
-	table = &(stts->table[0]);
-
-	table->sample_count = 0;     /* need to set this when closing or via update function */
-	table->sample_duration = sample_duration;
-}
-
-int mp4ff_stts_delete(mp4ff_stts_t *stts)
-{
-	if(stts->total_entries) free(stts->table);
-	stts->total_entries = 0;
-}
-
-int mp4ff_stts_dump(mp4ff_stts_t *stts)
-{
-	int i;
-	printf("     time to sample\n");
-	printf("      version %d\n", stts->version);
-	printf("      flags %d\n", stts->flags);
-	printf("      total_entries %d\n", stts->total_entries);
-	for(i = 0; i < stts->total_entries; i++)
-	{
-		printf("       count %ld duration %ld\n", stts->table[i].sample_count, stts->table[i].sample_duration);
-	}
-}
-
-int mp4ff_read_stts(mp4ff_t *file, mp4ff_stts_t *stts)
-{
-	int i;
-	stts->version = mp4ff_read_char(file);
-	stts->flags = mp4ff_read_int24(file);
-	stts->total_entries = mp4ff_read_int32(file);
-
-	stts->table = (mp4ff_stts_table_t*)malloc(sizeof(mp4ff_stts_table_t) * stts->total_entries);
-	for(i = 0; i < stts->total_entries; i++)
-	{
-		stts->table[i].sample_count = mp4ff_read_int32(file);
-		stts->table[i].sample_duration = mp4ff_read_int32(file);
-	}
-}
-
-int mp4ff_write_stts(mp4ff_t *file, mp4ff_stts_t *stts)
-{
-	int i;
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, "stts");
-
-	mp4ff_write_char(file, stts->version);
-	mp4ff_write_int24(file, stts->flags);
-	mp4ff_write_int32(file, stts->total_entries);
-	for(i = 0; i < stts->total_entries; i++)
-	{
-		mp4ff_write_int32(file, stts->table[i].sample_count);
-		mp4ff_write_int32(file, stts->table[i].sample_duration);
-	}
-	mp4ff_atom_write_footer(file, &atom);
-}
-
-int mp4ff_update_stts(mp4ff_stts_t *stts, long sample_duration)
-{
-	if (sample_duration == stts->table[stts->total_entries-1].sample_duration) {
-		stts->table[stts->total_entries-1].sample_count++;
-	} else {
-		/* need a new entry in the table */
-
-		/* allocate more entries if necessary */
-		if (stts->total_entries >= stts->entries_allocated) {
-			stts->entries_allocated *= 2;
-			stts->table = (mp4ff_stts_table_t*)realloc(stts->table,
-				sizeof(mp4ff_stts_table_t) * stts->entries_allocated);
-		}
-	
-		stts->table[stts->total_entries].sample_count = 1;
-		stts->table[stts->total_entries].sample_duration = sample_duration;
-		stts->total_entries++;
-	}
-}
--- a/common/mp4ff/tkhd.c
+++ /dev/null
@@ -1,136 +1,0 @@
-#include "mp4ff.h"
-
-
-int mp4ff_tkhd_init(mp4ff_tkhd_t *tkhd)
-{
-	int i;
-	tkhd->version = 0;
-	tkhd->flags = 15;
-	tkhd->creation_time = mp4ff_current_time();
-	tkhd->modification_time = mp4ff_current_time();
-	tkhd->track_id;
-	tkhd->reserved1 = 0;
-	tkhd->duration = 0;      /* need to set this when closing */
-	for(i = 0; i < 8; i++) tkhd->reserved2[i] = 0;
-	tkhd->layer = 0;
-	tkhd->alternate_group = 0;
-	tkhd->volume = 0.996094;
-	tkhd->reserved3 = 0;
-	mp4ff_matrix_init(&(tkhd->matrix));
-	tkhd->track_width = 0;
-	tkhd->track_height = 0;
-	tkhd->is_audio = 0 /*FALSE*/;
-	tkhd->is_video = 0 /*FALSE*/;
-	return 0;
-}
-
-int mp4ff_tkhd_init_audio(mp4ff_t *file, 
-								mp4ff_tkhd_t *tkhd)
-{
-	tkhd->is_audio = 1 /*TRUE*/;
-}
-
-int mp4ff_tkhd_init_video(mp4ff_t *file, 
-								mp4ff_tkhd_t *tkhd, 
-								int frame_w, 
-								int frame_h)
-{
-	tkhd->is_video = 1 /*TRUE*/;
-	tkhd->track_width = frame_w;
-	tkhd->track_height = frame_h;
-	tkhd->volume = 0;
-}
-
-int mp4ff_tkhd_delete(mp4ff_tkhd_t *tkhd)
-{
-	return 0;
-}
-
-int mp4ff_tkhd_dump(mp4ff_tkhd_t *tkhd)
-{
-	printf("  track header\n");
-	printf("   version %d\n", tkhd->version);
-	printf("   flags %ld\n", tkhd->flags);
-	printf("   creation_time %u\n", tkhd->creation_time);
-	printf("   modification_time %u\n", tkhd->modification_time);
-	printf("   track_id %d\n", tkhd->track_id);
-	printf("   reserved1 %ld\n", tkhd->reserved1);
-	printf("   duration %ld\n", tkhd->duration);
-	mp4ff_print_chars("   reserved2 ", tkhd->reserved2, 8);
-	printf("   layer %d\n", tkhd->layer);
-	printf("   alternate_group %d\n", tkhd->alternate_group);
-	printf("   volume %f\n", tkhd->volume);
-	printf("   reserved3 %d\n", tkhd->reserved3);
-	mp4ff_matrix_dump(&(tkhd->matrix));
-	printf("   track_width %f\n", tkhd->track_width);
-	printf("   track_height %f\n", tkhd->track_height);
-}
-
-int mp4ff_read_tkhd(mp4ff_t *file, mp4ff_tkhd_t *tkhd)
-{
-	tkhd->version = mp4ff_read_char(file);
-	tkhd->flags = mp4ff_read_int24(file);
-	tkhd->creation_time = mp4ff_read_int32(file);
-	tkhd->modification_time = mp4ff_read_int32(file);
-	tkhd->track_id = mp4ff_read_int32(file);
-	tkhd->reserved1 = mp4ff_read_int32(file);
-	tkhd->duration = mp4ff_read_int32(file);
-	mp4ff_read_data(file, tkhd->reserved2, 8);
-	tkhd->layer = mp4ff_read_int16(file);
-	tkhd->alternate_group = mp4ff_read_int16(file);
-	tkhd->volume = mp4ff_read_fixed16(file);
-	tkhd->reserved3 = mp4ff_read_int16(file);
-	mp4ff_read_matrix(file, &(tkhd->matrix));
-	tkhd->track_width = mp4ff_read_fixed32(file);
-	tkhd->track_height = mp4ff_read_fixed32(file);
-}
-
-int mp4ff_write_tkhd(mp4ff_t *file, mp4ff_tkhd_t *tkhd)
-{
-	int i;
-
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, "tkhd");
-
-	mp4ff_write_char(file, tkhd->version);
-	if (tkhd->flags != 0) {
-		mp4ff_write_int24(file, 1);
-	} else {
-		mp4ff_write_int24(file, tkhd->flags);
-	}
-	mp4ff_write_int32(file, tkhd->creation_time);
-	mp4ff_write_int32(file, tkhd->modification_time);
-	mp4ff_write_int32(file, tkhd->track_id);
-	mp4ff_write_int32(file, tkhd->reserved1);
-	mp4ff_write_int32(file, tkhd->duration);
-
-	for (i = 0; i < 3; i++) {
-		mp4ff_write_int32(file, 0x00000000);
-	}
-	if (tkhd->is_audio) {
-		mp4ff_write_int16(file, 0x0100);
-	} else {
-		mp4ff_write_int16(file, 0x0000);
-	}
-	mp4ff_write_int16(file, 0x0000);
-	mp4ff_write_int32(file, 0x00010000);
-	for (i = 0; i < 3; i++) {
-		mp4ff_write_int32(file, 0x00000000);
-	}
-	mp4ff_write_int32(file, 0x00010000);
-	for (i = 0; i < 3; i++) {
-		mp4ff_write_int32(file, 0x00000000);
-	}
-	mp4ff_write_int32(file, 0x40000000);
-	if (tkhd->is_video) {
-		mp4ff_write_int32(file, 0x01400000);
-		mp4ff_write_int32(file, 0x00F00000);
-	} else {
-		mp4ff_write_int32(file, 0x00000000);
-		mp4ff_write_int32(file, 0x00000000);
-	}
-
-	mp4ff_atom_write_footer(file, &atom);
-}
-
-
--- a/common/mp4ff/trak.c
+++ /dev/null
@@ -1,503 +1,0 @@
-#include "mp4ff.h"
-
-
-
-
-int mp4ff_trak_init(mp4ff_trak_t *trak)
-{
-	mp4ff_tkhd_init(&(trak->tkhd));
-	mp4ff_edts_init(&(trak->edts));
-	mp4ff_mdia_init(&(trak->mdia));
-	return 0;
-}
-
-int mp4ff_trak_init_video(mp4ff_t *file, 
-							mp4ff_trak_t *trak, 
-							int frame_w, 
-							int frame_h, 
-							float frame_rate,
-							int time_scale,
-							char *compressor)
-{
-	mp4ff_tkhd_init_video(file, &(trak->tkhd), frame_w, frame_h);
-	mp4ff_mdia_init_video(file, &(trak->mdia), frame_w, frame_h, 
-		frame_rate, time_scale, compressor);
-	mp4ff_edts_init_table(&(trak->edts));
-
-	return 0;
-}
-
-int mp4ff_trak_init_audio(mp4ff_t *file, 
-							mp4ff_trak_t *trak, 
-							int channels, 
-							int sample_rate, 
-							int bits, 
-							int sample_size,
-							int time_scale,
-							int sample_duration,
-							char *compressor)
-{
-	mp4ff_mdia_init_audio(file, &(trak->mdia), channels, sample_rate, bits,
-		sample_size, time_scale, sample_duration, compressor);
-	mp4ff_edts_init_table(&(trak->edts));
-
-	return 0;
-}
-
-int mp4ff_trak_delete(mp4ff_trak_t *trak)
-{
-	mp4ff_tkhd_delete(&(trak->tkhd));
-	return 0;
-}
-
-
-int mp4ff_trak_dump(mp4ff_trak_t *trak)
-{
-	printf(" track\n");
-	mp4ff_tkhd_dump(&(trak->tkhd));
-	mp4ff_edts_dump(&(trak->edts));
-	mp4ff_mdia_dump(&(trak->mdia));
-
-	return 0;
-}
-
-
-mp4ff_trak_t* mp4ff_add_trak(mp4ff_moov_t *moov)
-{
-	if(moov->total_tracks < MAXTRACKS)
-	{
-		moov->trak[moov->total_tracks] = malloc(sizeof(mp4ff_trak_t));
-		mp4ff_trak_init(moov->trak[moov->total_tracks]);
-		moov->total_tracks++;
-	}
-	return moov->trak[moov->total_tracks - 1];
-}
-
-mp4ff_trak_t* mp4ff_find_track_by_id(mp4ff_moov_t *moov, int trackId)
-{
-	int i;
-
-	for (i = 0; i < moov->total_tracks; i++) {
-		if (moov->trak[i]->tkhd.track_id == trackId) {
-			return moov->trak[i];
-		}
-	}
-	
-	return NULL;
-}
-
-int mp4ff_delete_trak(mp4ff_moov_t *moov, mp4ff_trak_t *trak)
-{
-	int i, j;
-
-	for (i = 0; i < moov->total_tracks; i++) {
-		if (moov->trak[i] == trak) {
-			mp4ff_trak_delete(trak);
-			free(trak);
-			moov->trak[i] = NULL;
-			for (j = i + 1; j < moov->total_tracks; j++, i++) {
-				moov->trak[i] = moov->trak[j];
-			}
-			moov->trak[j] = NULL;
-			moov->total_tracks--;
-			return 0;
-		}
-	}
-	return -1;
-}
-
-
-int mp4ff_read_trak(mp4ff_t *file, mp4ff_trak_t *trak, mp4ff_atom_t *trak_atom)
-{
-	mp4ff_atom_t leaf_atom;
-
-	do
-	{
-		mp4ff_atom_read_header(file, &leaf_atom);
-
-/* mandatory */
-		if(mp4ff_atom_is(&leaf_atom, "tkhd"))
-			{ mp4ff_read_tkhd(file, &(trak->tkhd)); }
-		else
-		if(mp4ff_atom_is(&leaf_atom, "mdia"))
-			{ mp4ff_read_mdia(file, &(trak->mdia), &leaf_atom); }
-		else
-/* optional */
-		if(mp4ff_atom_is(&leaf_atom, "edts"))
-			{ mp4ff_read_edts(file, &(trak->edts), &leaf_atom); }
-		else
-			mp4ff_atom_skip(file, &leaf_atom);
-	}while(mp4ff_position(file) < trak_atom->end);
-
-	return 0;
-}
-
-int mp4ff_write_trak(mp4ff_t *file, mp4ff_trak_t *trak, long moov_time_scale)
-{
-	long duration;
-	long timescale;
-	mp4ff_atom_t atom;
-	mp4ff_atom_write_header(file, &atom, "trak");
-	mp4ff_trak_duration(trak, &duration, &timescale);
-
-	/* printf("mp4ff_write_trak duration %d\n", duration); */
-
-	/* get duration in movie's units */
-	if (timescale) {
-		trak->tkhd.duration = 
-			(long)((float)duration / timescale * moov_time_scale);
-	} else {
-		trak->tkhd.duration = 0;
-	}
-	trak->mdia.mdhd.duration = duration;
-	trak->mdia.mdhd.time_scale = timescale;
-
-	mp4ff_write_tkhd(file, &(trak->tkhd));
-	mp4ff_write_edts(file, &(trak->edts), trak->tkhd.duration);
-	mp4ff_write_mdia(file, &(trak->mdia));
-
-	mp4ff_atom_write_footer(file, &atom);
-
-	return 0;
-}
-
-long mp4ff_track_end(mp4ff_trak_t *trak)
-{
-/* get the byte endpoint of the track in the file */
-	long size = 0;
-	long chunk, chunk_offset, chunk_samples, sample;
-	mp4ff_stsz_t *stsz = &(trak->mdia.minf.stbl.stsz);
-	mp4ff_stsz_table_t *table = stsz->table;
-	mp4ff_stsc_t *stsc = &(trak->mdia.minf.stbl.stsc);
-	mp4ff_stco_t *stco;
-
-/* get the last chunk offset */
-/* the chunk offsets contain the HEADER_LENGTH themselves */
-	stco = &(trak->mdia.minf.stbl.stco);
-	chunk = stco->total_entries;
-	size = chunk_offset = stco->table[chunk - 1].offset;
-
-/* get the number of samples in the last chunk */
-	chunk_samples = stsc->table[stsc->total_entries - 1].samples;
-
-/* get the size of last samples */
-#ifdef NOTDEF
-	if(stsz->sample_size)
-	{
-/* assume audio so calculate the sample size */
-		size += chunk_samples * stsz->sample_size
-			* trak->mdia.minf.stbl.stsd.table[0].channels 
-			* trak->mdia.minf.stbl.stsd.table[0].sample_size / 8;
-	}
-	else
-	{
-/* assume video */
-#endif
-		for(sample = stsz->total_entries - chunk_samples; 
-			sample >= 0 && sample < stsz->total_entries; sample++)
-		{
-			size += stsz->table[sample].size;
-		}
-#ifdef NOTDEF
-	}
-#endif
-
-	return size;
-}
-
-long mp4ff_track_samples(mp4ff_t *file, mp4ff_trak_t *trak)
-{
-/*printf("file->rd %d file->wr %d\n", file->rd, file->wr); */
-	if(file->wr)
-	{
-/* get the sample count when creating a new file */
- 		mp4ff_stsc_table_t *table = trak->mdia.minf.stbl.stsc.table;
-		long total_entries = trak->mdia.minf.stbl.stsc.total_entries;
-		long chunk = trak->mdia.minf.stbl.stco.total_entries;
-		long sample;
-
-		if(chunk)
-		{
-			sample = mp4ff_sample_of_chunk(trak, chunk);
-			sample += table[total_entries - 1].samples;
-		}
-		else 
-			sample = 0;
-		
-		return sample;
-	}
-	else
-	{
-/* get the sample count when reading only */
-		mp4ff_stts_t *stts = &(trak->mdia.minf.stbl.stts);
-		int i;
-		long total = 0;
-
-		for(i = 0; i < stts->total_entries; i++)
-		{
-			total += stts->table[i].sample_count;
-		}
-		return total;
-	}
-}
-
-long mp4ff_sample_of_chunk(mp4ff_trak_t *trak, long chunk)
-{
-	mp4ff_stsc_table_t *table = trak->mdia.minf.stbl.stsc.table;
-	long total_entries = trak->mdia.minf.stbl.stsc.total_entries;
-	long chunk1entry, chunk2entry;
-	long chunk1, chunk2, chunks, total = 0;
-
-	for(chunk1entry = total_entries - 1, chunk2entry = total_entries; 
-		chunk1entry >= 0; 
-		chunk1entry--, chunk2entry--)
-	{
-		chunk1 = table[chunk1entry].chunk;
-
-		if(chunk > chunk1)
-		{
-			if(chunk2entry < total_entries)
-			{
-				chunk2 = table[chunk2entry].chunk;
-
-				if(chunk < chunk2) chunk2 = chunk;
-			}
-			else
-				chunk2 = chunk;
-
-			chunks = chunk2 - chunk1;
-
-			total += chunks * table[chunk1entry].samples;
-		}
-	}
-
-	return total;
-}
-
-int mp4ff_chunk_of_sample(long *chunk_sample, long *chunk, mp4ff_trak_t *trak, long sample)
-{
-	mp4ff_stsc_table_t *table = NULL;
-	long total_entries = 0;
-	long chunk2entry;
-	long chunk1, chunk2, chunk1samples, range_samples, total = 0;
-
-	if (trak == NULL) {
-		return -1;
-	}
- 	table = trak->mdia.minf.stbl.stsc.table;
-	total_entries = trak->mdia.minf.stbl.stsc.total_entries;
-
-	chunk1 = 1;
-	chunk1samples = 0;
-	chunk2entry = 0;
-
-	do
-	{
-		chunk2 = table[chunk2entry].chunk;
-		*chunk = chunk2 - chunk1;
-		range_samples = *chunk * chunk1samples;
-
-		if(sample < total + range_samples) break;
-
-		chunk1samples = table[chunk2entry].samples;
-		chunk1 = chunk2;
-
-		if(chunk2entry < total_entries)
-		{
-			chunk2entry++;
-			total += range_samples;
-		}
-	}while(chunk2entry < total_entries);
-
-	if(chunk1samples)
-		*chunk = (sample - total) / chunk1samples + chunk1;
-	else
-		*chunk = 1;
-
-	*chunk_sample = total + (*chunk - chunk1) * chunk1samples;
-	return 0;
-}
-
-long mp4ff_chunk_to_offset(mp4ff_trak_t *trak, long chunk)
-{
-	mp4ff_stco_table_t *table = NULL;
-
-	if (trak == NULL) {
-		return -1;
-	}
-	table = trak->mdia.minf.stbl.stco.table;
-
-	if(trak->mdia.minf.stbl.stco.total_entries && chunk > trak->mdia.minf.stbl.stco.total_entries)
-		return table[trak->mdia.minf.stbl.stco.total_entries - 1].offset;
-	else
-	if(trak->mdia.minf.stbl.stco.total_entries)
-		return table[chunk - 1].offset;
-	else
-		return HEADER_LENGTH;
-	
-	return 0;
-}
-
-long mp4ff_offset_to_chunk(long *chunk_offset, mp4ff_trak_t *trak, long offset)
-{
-	mp4ff_stco_table_t *table = trak->mdia.minf.stbl.stco.table;
-	int i;
-
-	for(i = trak->mdia.minf.stbl.stco.total_entries - 1; i >= 0; i--)
-	{
-		if(table[i].offset <= offset)
-		{
-			*chunk_offset = table[i].offset;
-			return i + 1;
-		}
-	}
-	*chunk_offset = HEADER_LENGTH;
-	return 1;
-}
-
-long mp4ff_sample_range_size(mp4ff_trak_t *trak, long chunk_sample, long sample)
-{
-	mp4ff_stsz_table_t *table = trak->mdia.minf.stbl.stsz.table;
-	long i, total;
-
-	if(trak->mdia.minf.stbl.stsz.sample_size)
-	{
-/* assume audio */
-		return mp4ff_samples_to_bytes(trak, sample - chunk_sample);
-	}
-	else
-	{
-/* probably video */
-		for(i = chunk_sample, total = 0; i < sample; i++)
-		{
-			total += trak->mdia.minf.stbl.stsz.table[i].size;
-		}
-	}
-	return total;
-}
-
-long mp4ff_sample_to_offset(mp4ff_trak_t *trak, long sample)
-{
-	long chunk, chunk_sample, chunk_offset1, chunk_offset2;
-
-	if (trak == NULL) {
-		return -1;
-	}
-
-	mp4ff_chunk_of_sample(&chunk_sample, &chunk, trak, sample);
-	chunk_offset1 = mp4ff_chunk_to_offset(trak, chunk);
-	chunk_offset2 = chunk_offset1 + mp4ff_sample_range_size(trak, chunk_sample, sample);
-/*printf("mp4ff_sample_to_offset chunk %d sample %d chunk_offset %d chunk_sample %d chunk_offset + samples %d\n", */
-/*	 chunk, sample, chunk_offset1, chunk_sample, chunk_offset2); */
-	return chunk_offset2;
-}
-
-long mp4ff_offset_to_sample(mp4ff_trak_t *trak, long offset)
-{
-	long chunk_offset;
-	long chunk = mp4ff_offset_to_chunk(&chunk_offset, trak, offset);
-	long chunk_sample = mp4ff_sample_of_chunk(trak, chunk);
-	long sample, sample_offset;
-	mp4ff_stsz_table_t *table = trak->mdia.minf.stbl.stsz.table;
-	long total_samples = trak->mdia.minf.stbl.stsz.total_entries;
-
-	if(trak->mdia.minf.stbl.stsz.sample_size)
-	{
-		sample = chunk_sample + (offset - chunk_offset) / 
-			trak->mdia.minf.stbl.stsz.sample_size;
-	}
-	else
-	for(sample = chunk_sample, sample_offset = chunk_offset; 
-		sample_offset < offset && sample < total_samples; )
-	{
-		sample_offset += table[sample].size;
-		if(sample_offset < offset) sample++;
-	}
-	
-	return sample;
-}
-
-int mp4ff_update_tables(mp4ff_t *file, 
-							mp4ff_trak_t *trak, 
-							long offset, 
-							long chunk, 
-							long sample, 
-							long samples, 
-							long sample_size,
-							long sample_duration,
-							unsigned char isSyncSample,
-							long renderingOffset)
-{
-	if (offset + sample_size > file->mdat.size) {
-		file->mdat.size = offset + sample_size;
-	}
-	mp4ff_update_stco(&(trak->mdia.minf.stbl.stco), chunk, offset);
-	if (sample_size) {
-		mp4ff_update_stsz(&(trak->mdia.minf.stbl.stsz), sample, sample_size);
-	}
-	mp4ff_update_stsc(&(trak->mdia.minf.stbl.stsc), chunk, samples);
-	if (sample_duration) {
-		mp4ff_update_stts(&(trak->mdia.minf.stbl.stts), sample_duration);
-	}
-	if (isSyncSample) {
-		mp4ff_update_stss(&(trak->mdia.minf.stbl.stss), sample);
-	}
-	mp4ff_update_ctts(&(trak->mdia.minf.stbl.ctts), renderingOffset);
-	return 0;
-}
-
-int mp4ff_trak_duration(mp4ff_trak_t *trak, long *duration, long *timescale)
-{
-	mp4ff_stts_t *stts = &(trak->mdia.minf.stbl.stts);
-	int i;
-	*duration = 0;
-
-	for(i = 0; i < stts->total_entries; i++) {
-		*duration += stts->table[i].sample_duration * stts->table[i].sample_count;
-	}
-
-	*timescale = trak->mdia.mdhd.time_scale;
-	return 0;
-}
-
-int mp4ff_trak_fix_counts(mp4ff_t *file, mp4ff_trak_t *trak)
-{
-	long samples = mp4ff_track_samples(file, trak);
-
-	if (trak->mdia.minf.stbl.stts.total_entries == 1) {
-		trak->mdia.minf.stbl.stts.table[0].sample_count = samples;
-	}
-
-	if(trak->mdia.minf.stbl.stsz.sample_size)
-		trak->mdia.minf.stbl.stsz.total_entries = samples;
-
-	return 0;
-}
-
-long mp4ff_chunk_samples(mp4ff_trak_t *trak, long chunk)
-{
-	long result, current_chunk;
-	mp4ff_stsc_t *stsc = &(trak->mdia.minf.stbl.stsc);
-	long i = stsc->total_entries - 1;
-
-	do
-	{
-		current_chunk = stsc->table[i].chunk;
-		result = stsc->table[i].samples;
-		i--;
-	}while(i >= 0 && current_chunk > chunk);
-
-	return result;
-}
-
-int mp4ff_trak_shift_offsets(mp4ff_trak_t *trak, long offset)
-{
-	mp4ff_stco_t *stco = &(trak->mdia.minf.stbl.stco);
-	int i;
-
-	for(i = 0; i < stco->total_entries; i++)
-	{
-		stco->table[i].offset += offset;
-	}
-	return 0;
-}
--- a/common/mp4ff/udta.c
+++ /dev/null
@@ -1,164 +1,0 @@
-#include "mp4ff.h"
-
-#define DEFAULT_INFO "Made with Quicktime for Linux"
-
-int mp4ff_udta_init(mp4ff_udta_t *udta)
-{
-	udta->copyright = 0;
-	udta->copyright_len = 0;
-	udta->name = 0;
-	udta->name_len = 0;
-
-	udta->info = malloc(strlen(DEFAULT_INFO) + 1);
-	udta->info_len = strlen(DEFAULT_INFO);
-	sprintf(udta->info, DEFAULT_INFO);
-
-	return 0;
-}
-
-int mp4ff_udta_delete(mp4ff_udta_t *udta)
-{
-	if(udta->copyright_len)
-	{
-		free(udta->copyright);
-	}
-	if(udta->name_len)
-	{
-		free(udta->name);
-	}
-	if(udta->info_len)
-	{
-		free(udta->info);
-	}
-
-	mp4ff_udta_init(udta);
-	return 0;
-}
-
-int mp4ff_udta_dump(mp4ff_udta_t *udta)
-{
-	printf(" user data (udta)\n");
-	if(udta->copyright_len) printf("  copyright -> %s\n", udta->copyright);
-	if(udta->name_len) printf("  name -> %s\n", udta->name);
-	if(udta->info_len) printf("  info -> %s\n", udta->info);
-}
-
-int mp4ff_read_udta(mp4ff_t *file, mp4ff_udta_t *udta, mp4ff_atom_t *udta_atom)
-{
-	mp4ff_atom_t leaf_atom;
-	int result = 0;
-
-	do
-	{
-		/* udta atoms can be terminated by a 4 byte zero */
-		if (udta_atom->end - mp4ff_position(file) < HEADER_LENGTH) {
-			unsigned char trash[HEADER_LENGTH];
-			int remainder = udta_atom->end - mp4ff_position(file);
-			mp4ff_read_data(file, trash, remainder);
-			break;
-		}
-
-		mp4ff_atom_read_header(file, &leaf_atom);
-
-#if 0
-		if(mp4ff_atom_is(&leaf_atom, "�cpy"))
-		{
-			result += mp4ff_read_udta_string(file, &(udta->copyright), &(udta->copyright_len));
-		}
-		else
-		if(mp4ff_atom_is(&leaf_atom, "�nam"))
-		{
-			result += mp4ff_read_udta_string(file, &(udta->name), &(udta->name_len));
-		}
-		else
-		if(mp4ff_atom_is(&leaf_atom, "�inf"))
-		{
-			result += mp4ff_read_udta_string(file, &(udta->info), &(udta->info_len));
-		}
-		else
-#endif
-		mp4ff_atom_skip(file, &leaf_atom);
-	}while(mp4ff_position(file) < udta_atom->end);
-
-	return result;
-}
-
-int mp4ff_write_udta(mp4ff_t *file, mp4ff_udta_t *udta)
-{
-	mp4ff_atom_t atom, subatom;
-
-	/*
-	 * Empty udta atom makes Darwin Streaming Server unhappy
-	 * so avoid it
-	 */
-#if 1
-    return;
-#else
-	if (udta->copyright_len == 0 && udta->hnti.rtp.string == NULL) {
-        return;
-    }
-
-	mp4ff_atom_write_header(file, &atom, "udta");
-
-	if(udta->copyright_len)
-	{
-		mp4ff_atom_write_header(file, &subatom, "�cpy");
-		mp4ff_write_udta_string(file, udta->copyright, udta->copyright_len);
-		mp4ff_atom_write_footer(file, &subatom);
-	}
-
-#if 0
-	if(udta->name_len && !file->use_mp4)
-	{
-		mp4ff_atom_write_header(file, &subatom, "�nam");
-		mp4ff_write_udta_string(file, udta->name, udta->name_len);
-		mp4ff_atom_write_footer(file, &subatom);
-	}
-
-	if(udta->info_len && !file->use_mp4)
-	{
-		mp4ff_atom_write_header(file, &subatom, "�inf");
-		mp4ff_write_udta_string(file, udta->info, udta->info_len);
-		mp4ff_atom_write_footer(file, &subatom);
-	}
-#endif
-	if (udta->hnti.rtp.string != NULL) {
-		mp4ff_write_hnti(file, &(udta->hnti));
-	}
-
-	mp4ff_atom_write_footer(file, &atom);
-#endif
-}
-
-int mp4ff_read_udta_string(mp4ff_t *file, char **string, int *size)
-{
-	int result;
-
-	if(*size) free(*string);
-	*size = mp4ff_read_int16(file);  /* Size of string */
-	mp4ff_read_int16(file);  /* Discard language code */
-	*string = malloc(*size + 1);
-	result = mp4ff_read_data(file, *string, *size);
-	(*string)[*size] = 0;
-	return !result;
-}
-
-int mp4ff_write_udta_string(mp4ff_t *file, char *string, int size)
-{
-	int new_size = strlen(string);
-	int result;
-
-	mp4ff_write_int16(file, new_size);    /* String size */
-	mp4ff_write_int16(file, 0);    /* Language code */
-	result = mp4ff_write_data(file, string, new_size);
-	return !result;
-}
-
-int mp4ff_set_udta_string(char **string, int *size, char *new_string)
-{
-	if(*size) free(*string);
-	*size = strlen(new_string + 1);
-	*string = malloc(*size + 1);
-	strcpy(*string, new_string);
-	return 0;
-}
--- a/common/mp4ff/util.c
+++ /dev/null
@@ -1,356 +1,0 @@
-#include <time.h>
-#include "mp4ff.h"
-
-/* Disk I/O */
-
-
-int mp4ff_read_data(mp4ff_t *file, char *data, int size)
-{
-    int result = 1;
-
-    if (file->stream->get_position() != file->file_position)
-        file->stream->seek(file->file_position);
-    result = file->stream->read(data, size);
-
-    file->file_position += size;
-
-    return result;
-}
-
-int mp4ff_write_data(mp4ff_t *file, char *data, int size)
-{
-    int result;
-
-    if (file->stream->get_position() != file->file_position)
-        file->stream->seek(file->file_position);
-    result = file->stream->write(data, size);
-
-    file->file_position += size;
-
-    return result;
-}
-
-int mp4ff_test_position(mp4ff_t *file)
-{
-	if (mp4ff_position(file) < 0)
-	{
-		printf("mp4ff_test_position: 32 bit overflow\n");
-		return 1;
-	}
-	else
-	return 0;
-}
-
-int mp4ff_read_pascal(mp4ff_t *file, char *data)
-{
-	char len = mp4ff_read_char(file);
-	mp4ff_read_data(file, data, len);
-	data[len] = 0;
-}
-
-int mp4ff_write_pascal(mp4ff_t *file, char *data)
-{
-	char len = strlen(data);
-	mp4ff_write_data(file, &len, 1);
-	mp4ff_write_data(file, data, len);
-}
-
-float mp4ff_read_fixed32(mp4ff_t *file)
-{
-	unsigned long a, b, c, d;
-	unsigned char data[4];
-
-	mp4ff_read_data(file, data, 4);
-/*	fread(data, 4, 1, file->stream); */
-	a = data[0];
-	b = data[1];
-	c = data[2];
-	d = data[3];
-	
-	a = (a << 8) + b;
-	b = (c << 8) + d;
-
-	return (float)a + (float)b / 65536;
-}
-
-int mp4ff_write_fixed32(mp4ff_t *file, float number)
-{
-	unsigned char data[4];
-	int a, b;
-
-	a = number;
-	b = (number - a) * 65536;
-	data[0] = a >> 8;
-	data[1] = a & 0xff;
-	data[2] = b >> 8;
-	data[3] = b & 0xff;
-
-	return mp4ff_write_data(file, data, 4);
-}
-
-int mp4ff_write_int64(mp4ff_t *file, uint64_t value)
-{
-	unsigned char data[8];
-	int i;
-
-	for (i = 7; i >= 0; i--) {
-		data[i] = value & 0xff;
-		value >>= 8;
-	}
-
-	return mp4ff_write_data(file, data, 8);
-}
-
-int mp4ff_write_int32(mp4ff_t *file, long value)
-{
-	unsigned char data[4];
-
-	data[0] = (value & 0xff000000) >> 24;
-	data[1] = (value & 0xff0000) >> 16;
-	data[2] = (value & 0xff00) >> 8;
-	data[3] = value & 0xff;
-
-	return mp4ff_write_data(file, data, 4);
-}
-
-int mp4ff_write_char32(mp4ff_t *file, char *string)
-{
-	return mp4ff_write_data(file, string, 4);
-}
-
-
-float mp4ff_read_fixed16(mp4ff_t *file)
-{
-	unsigned char data[2];
-	
-	mp4ff_read_data(file, data, 2);
-	return (float)data[0] + (float)data[1] / 256;
-}
-
-int mp4ff_write_fixed16(mp4ff_t *file, float number)
-{
-	unsigned char data[2];
-	int a, b;
-
-	a = number;
-	b = (number - a) * 256;
-	data[0] = a;
-	data[1] = b;
-	
-	return mp4ff_write_data(file, data, 2);
-}
-
-uint64_t mp4ff_read_int64(mp4ff_t *file)
-{
-	unsigned char data[8];
-	uint64_t result = 0;
-	int i;
-
-	mp4ff_read_data(file, data, 8);
-
-	for (i = 0; i < 8; i++) {
-		result |= ((uint64_t)data[i]) << ((7 - i) * 8);
-	}
-
-	return result;
-}
-
-long mp4ff_read_int32(mp4ff_t *file)
-{
-	unsigned long result;
-	unsigned long a, b, c, d;
-	char data[4];
-	
-	mp4ff_read_data(file, data, 4);
-	a = (unsigned char)data[0];
-	b = (unsigned char)data[1];
-	c = (unsigned char)data[2];
-	d = (unsigned char)data[3];
-
-	result = (a<<24) | (b<<16) | (c<<8) | d;
-	return (long)result;
-}
-
-
-long mp4ff_read_int24(mp4ff_t *file)
-{
-	unsigned long result;
-	unsigned long a, b, c;
-	char data[4];
-	
-	mp4ff_read_data(file, data, 3);
-/*	fread(data, 3, 1, file->stream); */
-	a = (unsigned char)data[0];
-	b = (unsigned char)data[1];
-	c = (unsigned char)data[2];
-
-	result = (a<<16) | (b<<8) | c;
-	return (long)result;
-}
-
-int mp4ff_write_int24(mp4ff_t *file, long number)
-{
-	unsigned char data[3];
-	data[0] = (number & 0xff0000) >> 16;
-	data[1] = (number & 0xff00) >> 8;
-	data[2] = (number & 0xff);
-	
-	return mp4ff_write_data(file, data, 3);
-/*	return fwrite(data, 3, 1, file->stream); */
-}
-
-int mp4ff_read_int16(mp4ff_t *file)
-{
-	unsigned long result;
-	unsigned long a, b;
-	char data[2];
-	
-	mp4ff_read_data(file, data, 2);
-/*	fread(data, 2, 1, file->stream); */
-	a = (unsigned char)data[0];
-	b = (unsigned char)data[1];
-
-	result = (a<<8) | b;
-	return (int)result;
-}
-
-int mp4ff_write_int16(mp4ff_t *file, int number)
-{
-	unsigned char data[2];
-	data[0] = (number & 0xff00) >> 8;
-	data[1] = (number & 0xff);
-	
-	return mp4ff_write_data(file, data, 2);
-/*	return fwrite(data, 2, 1, file->stream); */
-}
-
-int mp4ff_read_char(mp4ff_t *file)
-{
-	char output;
-	mp4ff_read_data(file, &output, 1);
-	return output;
-}
-
-int mp4ff_write_char(mp4ff_t *file, char x)
-{
-	return mp4ff_write_data(file, &x, 1);
-}
-
-int mp4ff_read_char32(mp4ff_t *file, char *string)
-{
-	mp4ff_read_data(file, string, 4);
-/*	fread(string, 4, 1, file->stream); */
-}
-
-long mp4ff_position(mp4ff_t *file) 
-{ 
-	return file->file_position; 
-}
-
-int mp4ff_set_position(mp4ff_t *file, long position) 
-{
-	file->file_position = position;
-	return 0;
-/*	fseek(file->stream, position, SEEK_SET);  */
-}
-
-int mp4ff_copy_char32(char *output, char *input)
-{
-	*output++ = *input++;
-	*output++ = *input++;
-	*output++ = *input++;
-	*output = *input;
-}
-
-
-void mp4ff_print_chars(char *desc, char *input, int len)
-{
-	int i;
-
-    printf("%s", desc);
-    for(i = 0; i < len; i++)
-        printf("%c", input[i]);
-	printf("\n");
-}
-
-unsigned long mp4ff_current_time()
-{
-	time_t t = 0;
-	//time(&t);
-	return (t+(66*31536000)+1468800);
-}
-
-int mp4ff_match_32(char *input, char *output)
-{
-	if(input[0] == output[0] &&
-		input[1] == output[1] &&
-		input[2] == output[2] &&
-		input[3] == output[3])
-		return 1;
-	else 
-		return 0;
-}
-
-int mp4ff_read_mp4_descr_length(mp4ff_t *file)
-{
-	uint8_t b;
-	uint8_t numBytes = 0;
-	uint32_t length = 0;
-
-	do {
-		b = mp4ff_read_char(file);
-		numBytes++;
-		length = (length << 7) | (b & 0x7F);
-	} while ((b & 0x80) && numBytes < 4);
-
-	return length;
-}
-
-int mp4ff_write_mp4_descr_length(mp4ff_t *file, int length, unsigned char compact)
-{
-	uint8_t b;
-	int8_t i;
-	int8_t numBytes;
-
-	if (compact) {
-		if (length <= 0x7F) {
-			numBytes = 1;
-		} else if (length <= 0x3FFF) {
-			numBytes = 2;
-		} else if (length <= 0x1FFFFF) {
-			numBytes = 3;
-		} else {
-			numBytes = 4;
-		}
-	} else {
-		numBytes = 4;
-	}
-
-	for (i = numBytes-1; i >= 0; i--) {
-		b = (length >> (i * 7)) & 0x7F;
-		if (i != 0) {
-			b |= 0x80;
-		}
-		mp4ff_write_char(file, b);
-	}
-
-	return numBytes; 
-}
-
-void mp4ff_atom_hexdump(mp4ff_t* file, mp4ff_atom_t* atom)
-{
-	int i;
-	int oldPos;
-
-	oldPos = mp4ff_position(file);
-	mp4ff_set_position(file, atom->start);
-	printf("atom hex dump:\n");
-	for (i = 0; i < atom->size; i++) {
-		printf("%02x ", (uint8_t)mp4ff_read_char(file));
-		if ((i % 16) == 0 && i > 0) {
-			printf("\n");
-		}
-	}
-	printf("\n");
-	mp4ff_set_position(file, oldPos);
-}
--- a/common/mp4ff/vmhd.c
+++ /dev/null
@@ -1,58 +1,0 @@
-#include "mp4ff.h"
-
-
-int mp4ff_vmhd_init(mp4ff_vmhd_t *vmhd)
-{
-	vmhd->version = 0;
-	vmhd->flags = 1;
-	vmhd->graphics_mode = 64;
-	vmhd->opcolor[0] = 32768;
-	vmhd->opcolor[1] = 32768;
-	vmhd->opcolor[2] = 32768;
-}
-
-int mp4ff_vmhd_init_video(mp4ff_t *file, 
-								mp4ff_vmhd_t *vmhd, 
-								int frame_w,
-								int frame_h, 
-								float frame_rate)
-{
-}
-
-int mp4ff_vmhd_delete(mp4ff_vmhd_t *vmhd)
-{
-}
-
-int mp4ff_vmhd_dump(mp4ff_vmhd_t *vmhd)
-{
-	printf("    video media header\n");
-	printf("     version %d\n", vmhd->version);
-	printf("     flags %d\n", vmhd->flags);
-	printf("     graphics_mode %d\n", vmhd->graphics_mode);
-	printf("     opcolor %d %d %d\n", vmhd->opcolor[0], vmhd->opcolor[1], vmhd->opcolor[2]);
-}
-
-int mp4ff_read_vmhd(mp4ff_t *file, mp4ff_vmhd_t *vmhd)
-{
-	int i;
-	vmhd->version = mp4ff_read_char(file);
-	vmhd->flags = mp4ff_read_int24(file);
-	vmhd->graphics_mode = mp4ff_read_int16(file);
-	for(i = 0; i < 3; i++)
-		vmhd->opcolor[i] = mp4ff_read_int16(file);
-}
-
-int mp4ff_write_vmhd(mp4ff_t *file, mp4ff_vmhd_t *vmhd)
-{
-	mp4ff_atom_t atom;
-
-    mp4ff_atom_write_header(file, &atom, "vmhd");
-
-	mp4ff_write_char(file, vmhd->version);
-	mp4ff_write_int24(file, vmhd->flags);
-
-	mp4ff_write_int64(file, (uint64_t)0);
-
-	mp4ff_atom_write_footer(file, &atom);
-}
-