From 0a02b86d3911c696986ba9970b2fa3aaefebee10 Mon Sep 17 00:00:00 2001 From: Nathan Caldwell Date: Mon, 21 Apr 2008 19:15:36 -0600 Subject: [PATCH] Split EBML functions into their own header. --- src/Makefile.am | 2 +- src/ebml.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/matroska.h | 53 +++--------------------------------- 3 files changed, 87 insertions(+), 51 deletions(-) create mode 100644 src/ebml.h diff --git a/src/Makefile.am b/src/Makefile.am index a76e120..18d00a6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,4 +3,4 @@ INCLUDES = -I$(top_builddir) -I$(top_srcdir) -I$(top_srcdir)/include lib_LTLIBRARIES = libmkv.la -libmkv_la_SOURCES = matroska.c matroska.h tracks.c chapters.c ebml.c md5.h md5.c \ No newline at end of file +libmkv_la_SOURCES = matroska.c matroska.h tracks.c chapters.c ebml.h ebml.c md5.h md5.c diff --git a/src/ebml.h b/src/ebml.h new file mode 100644 index 0000000..624384c --- /dev/null +++ b/src/ebml.h @@ -0,0 +1,83 @@ +/***************************************************************************** + * ebml.h: + ***************************************************************************** + * Copyright (C) 2005 x264 project + * $Id: $ + * + * Authors: Mike Matsnev + * Nathan Caldwell + * + * 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, USA. + *****************************************************************************/ +#ifndef _EBML_H +#define _EBML_H 1 + +/* Copied from ffmpeg */ +/* EBML version supported */ +#define EBML_VERSION 1 + +/* top-level master-IDs */ +#define EBML_ID_HEADER 0x1A45DFA3 /* sub-elements */ + +/* IDs in the HEADER master */ +#define EBML_ID_EBMLVERSION 0x4286 /* u-integer */ +#define EBML_ID_EBMLREADVERSION 0x42F7 /* u-integer */ +#define EBML_ID_EBMLMAXIDLENGTH 0x42F2 /* u-integer */ +#define EBML_ID_EBMLMAXSIZELENGTH 0x42F3 /* u-integer */ +#define EBML_ID_DOCTYPE 0x4282 /* string */ +#define EBML_ID_DOCTYPEVERSION 0x4287 /* u-integer */ +#define EBML_ID_DOCTYPEREADVERSION 0x4285 /* u-integer */ + +/* general EBML types */ +#define EBML_ID_VOID 0xEC /* binary */ +/* Above copied from ffmpeg */ + +typedef struct mk_Context_s mk_Context; + +struct mk_Context_s { + mk_Context *next, **prev, *parent; + mk_Writer *owner; + unsigned id; + + void *data; + unsigned d_cur, d_max; +}; + +/* Contexts */ +mk_Context *mk_createContext(mk_Writer *w, mk_Context *parent, unsigned id); +int mk_appendContextData(mk_Context *c, const void *data, uint64_t size); +int mk_flushContextID(mk_Context *c); +int mk_flushContextData(mk_Context *c); +int mk_closeContext(mk_Context *c, int64_t *off); +void mk_destroyContexts(mk_Writer *w); +/* Contexts */ + +/* EBML */ +int mk_writeID(mk_Context *c, unsigned id); +int mk_writeSize(mk_Context *c, uint64_t size); +int mk_writeSSize(mk_Context *c, int64_t size); +int mk_writeStr(mk_Context *c, unsigned id, const char *str); +int mk_writeBin(mk_Context *c, unsigned id, const void *data, unsigned size); +int mk_writeUInt(mk_Context *c, unsigned id, uint64_t ui); +int mk_writeSInt(mk_Context *c, unsigned id, int64_t si); +int mk_writeFloatRaw(mk_Context *c, float f); +int mk_writeFloat(mk_Context *c, unsigned id, float f); +int mk_writeVoid(mk_Context *c, uint64_t length); +unsigned mk_ebmlSizeSize(uint64_t s); +unsigned mk_ebmlSIntSize(int64_t si); +int mk_writeEbmlHeader(mk_Writer *w, const char * doctype, uint64_t doctype_version, uint64_t doctype_readversion ); +/* EBML */ + +#endif /* _EBML_H */ diff --git a/src/matroska.h b/src/matroska.h index 00bc696..77ad87b 100644 --- a/src/matroska.h +++ b/src/matroska.h @@ -25,30 +25,15 @@ #define _MATROSKA_H 1 #include "md5.h" +#include "ebml.h" #define CLSIZE 1048576 #define CHECK(x) do { if ((x) < 0) return -1; } while (0) -/* Copied from ffmpeg */ -/* EBML version supported */ -#define EBML_VERSION 1 +/* Matroska version supported */ #define MATROSKA_VERSION 2 -/* top-level master-IDs */ -#define EBML_ID_HEADER 0x1A45DFA3 /* sub-elements */ - -/* IDs in the HEADER master */ -#define EBML_ID_EBMLVERSION 0x4286 /* u-integer */ -#define EBML_ID_EBMLREADVERSION 0x42F7 /* u-integer */ -#define EBML_ID_EBMLMAXIDLENGTH 0x42F2 /* u-integer */ -#define EBML_ID_EBMLMAXSIZELENGTH 0x42F3 /* u-integer */ -#define EBML_ID_DOCTYPE 0x4282 /* string */ -#define EBML_ID_DOCTYPEVERSION 0x4287 /* u-integer */ -#define EBML_ID_DOCTYPEREADVERSION 0x4285 /* u-integer */ - -/* general EBML types */ -#define EBML_ID_VOID 0xEC /* binary */ - +/* Copied from ffmpeg */ /* * Matroska element IDs. max. 32-bit. */ @@ -200,19 +185,9 @@ #define MATROSKA_ID_CHAPPROCESSTIME 0x6922 /* u-integer */ #define MATROSKA_ID_CHAPPROCESSDATA 0x6933 /* binary */ -typedef struct mk_Context_s mk_Context; typedef struct mk_Seek_s mk_Seek; typedef struct mk_Chapter_s mk_Chapter; -struct mk_Context_s { - mk_Context *next, **prev, *parent; - mk_Writer *owner; - unsigned id; - - void *data; - unsigned d_cur, d_max; -}; - struct mk_Writer_s { FILE *fp; uint64_t f_pos; @@ -283,28 +258,6 @@ struct mk_Track_s { } frame; }; -/* EBML */ -mk_Context *mk_createContext(mk_Writer *w, mk_Context *parent, unsigned id); -int mk_appendContextData(mk_Context *c, const void *data, uint64_t size); -int mk_writeID(mk_Context *c, unsigned id); -int mk_writeSize(mk_Context *c, uint64_t size); -int mk_writeSSize(mk_Context *c, int64_t size); -int mk_flushContextID(mk_Context *c); -int mk_flushContextData(mk_Context *c); -int mk_closeContext(mk_Context *c, int64_t *off); -void mk_destroyContexts(mk_Writer *w); -int mk_writeStr(mk_Context *c, unsigned id, const char *str); -int mk_writeBin(mk_Context *c, unsigned id, const void *data, unsigned size); -int mk_writeUInt(mk_Context *c, unsigned id, uint64_t ui); -int mk_writeSInt(mk_Context *c, unsigned id, int64_t si); -int mk_writeFloatRaw(mk_Context *c, float f); -int mk_writeFloat(mk_Context *c, unsigned id, float f); -int mk_writeVoid(mk_Context *c, uint64_t length); -unsigned mk_ebmlSizeSize(uint64_t s); -unsigned mk_ebmlSIntSize(int64_t si); -int mk_writeEbmlHeader(mk_Writer *w, const char * doctype, uint64_t doctype_version, uint64_t doctype_readversion ); -/* EBML */ - int mk_writeSeek(mk_Writer *w, mk_Context *c, unsigned seek_id, uint64_t seek_pos); int mk_writeSeekHead(mk_Writer *w, int64_t *pointer); int mk_writeTracks(mk_Writer *w, mk_Context *tracks); -- 2.11.4.GIT