Update matroska parser.
This commit is contained in:
1 parent
7e14b78afa
commit
8235bfab97
3 files changed
+1840
-1308
No files matched your search
+1521
-977
File diff suppressed because it is too large.
Load diff
+201
-155
@@ -24,13 +24,13 @@
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* $Id: MatroskaParser.h,v 1.22 2008/04/29 21:03:09 mike Exp $
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MATROSKA_PARSER_H
|
||||
#define MATROSKA_PARSER_H
|
||||
#define MATROSKA_PARSER_H
|
||||
|
||||
/* Random notes:
|
||||
*
|
||||
@@ -42,7 +42,7 @@
|
||||
*/
|
||||
|
||||
#ifdef MPDLLBUILD
|
||||
#define X __declspec(dllexport)
|
||||
#define X __declspec(dllexport)
|
||||
#else
|
||||
#ifdef MPDLL
|
||||
#define X __declspec(dllimport)
|
||||
@@ -53,7 +53,7 @@
|
||||
#endif
|
||||
|
||||
#define MATROSKA_COMPRESSION_SUPPORT
|
||||
#define MATROSKA_INTEGER_ONLY
|
||||
//#define MATROSKA_INTEGER_ONLY
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -61,7 +61,7 @@ extern "C" {
|
||||
|
||||
/* 64-bit integers */
|
||||
#ifdef _WIN32_WCE
|
||||
typedef signed __int64 longlong;
|
||||
typedef signed __int64 longlong;
|
||||
typedef unsigned __int64 ulonglong;
|
||||
#else
|
||||
typedef signed long long longlong;
|
||||
@@ -71,16 +71,16 @@ typedef unsigned long long ulonglong;
|
||||
/* MKFLOATing point */
|
||||
#ifdef MATROSKA_INTEGER_ONLY
|
||||
typedef struct {
|
||||
longlong v;
|
||||
longlong v;
|
||||
} MKFLOAT;
|
||||
#else
|
||||
typedef double MKFLOAT;
|
||||
typedef double MKFLOAT;
|
||||
#endif
|
||||
|
||||
/* generic I/O */
|
||||
struct InputStream {
|
||||
/* read bytes from stream */
|
||||
int (*read)(struct InputStream *cc,ulonglong pos,void *buffer,int count);
|
||||
int (*read)(struct InputStream *cc,ulonglong pos,void *buffer,int count);
|
||||
/* scan for a four byte signature, bytes must be nonzero */
|
||||
longlong (*scan)(struct InputStream *cc,ulonglong start,unsigned signature);
|
||||
/* get cache size, this is used to cap readahead */
|
||||
@@ -88,11 +88,11 @@ struct InputStream {
|
||||
/* fetch last error message */
|
||||
const char *(*geterror)(struct InputStream *cc);
|
||||
/* memory allocation */
|
||||
void *(*memalloc)(struct InputStream *cc,size_t size);
|
||||
void *(*memrealloc)(struct InputStream *cc,void *mem,size_t newsize);
|
||||
void (*memfree)(struct InputStream *cc,void *mem);
|
||||
void *(*memalloc)(struct InputStream *cc,size_t size);
|
||||
void *(*memrealloc)(struct InputStream *cc,void *mem,size_t newsize);
|
||||
void (*memfree)(struct InputStream *cc,void *mem);
|
||||
/* zero return causes parser to abort open */
|
||||
int (*progress)(struct InputStream *cc,ulonglong cur,ulonglong max);
|
||||
int (*progress)(struct InputStream *cc,ulonglong cur,ulonglong max);
|
||||
/* get file size, optional, can be NULL or return -1 if filesize is unknown */
|
||||
longlong (*getfilesize)(struct InputStream *cc);
|
||||
};
|
||||
@@ -104,34 +104,36 @@ struct MatroskaFile; /* opaque */
|
||||
|
||||
typedef struct MatroskaFile MatroskaFile;
|
||||
|
||||
#define COMP_ZLIB 0
|
||||
#define COMP_BZIP 1
|
||||
#define COMP_LZO1X 2
|
||||
#define COMP_PREPEND 3
|
||||
#define COMP_ZLIB 0
|
||||
#define COMP_BZIP 1
|
||||
#define COMP_LZO1X 2
|
||||
#define COMP_PREPEND 3
|
||||
|
||||
#define TT_VIDEO 1
|
||||
#define TT_AUDIO 2
|
||||
#define TT_SUB 17
|
||||
#define TT_VIDEO 1
|
||||
#define TT_AUDIO 2
|
||||
#define TT_SUB 17
|
||||
|
||||
struct TrackInfo {
|
||||
unsigned char Number;
|
||||
unsigned char Type;
|
||||
unsigned char TrackOverlay;
|
||||
ulonglong UID;
|
||||
ulonglong MinCache;
|
||||
ulonglong MaxCache;
|
||||
ulonglong DefaultDuration;
|
||||
MKFLOAT TimecodeScale;
|
||||
void *CodecPrivate;
|
||||
unsigned CodecPrivateSize;
|
||||
unsigned int CodecDelay;
|
||||
unsigned CompMethod;
|
||||
void *CompMethodPrivate;
|
||||
unsigned CompMethodPrivateSize;
|
||||
unsigned MaxBlockAdditionID;
|
||||
unsigned char Number;
|
||||
unsigned char Type;
|
||||
unsigned char TrackOverlay;
|
||||
ulonglong UID;
|
||||
ulonglong MinCache;
|
||||
ulonglong MaxCache;
|
||||
ulonglong DefaultDuration;
|
||||
ulonglong CodecDelay;
|
||||
ulonglong SeekPreRoll;
|
||||
MKFLOAT TimecodeScale;
|
||||
void *CodecPrivate;
|
||||
unsigned CodecPrivateSize;
|
||||
unsigned CompMethod;
|
||||
void *CompMethodPrivate;
|
||||
unsigned CompMethodPrivateSize;
|
||||
unsigned MaxBlockAdditionID;
|
||||
|
||||
unsigned int Enabled:1;
|
||||
unsigned int Default:1;
|
||||
unsigned int Forced:1;
|
||||
unsigned int Lacing:1;
|
||||
unsigned int DecodeAll:1;
|
||||
unsigned int CompEnabled:1;
|
||||
@@ -147,129 +149,162 @@ struct TrackInfo {
|
||||
unsigned int DisplayHeight;
|
||||
unsigned int CropL, CropT, CropR, CropB;
|
||||
unsigned int ColourSpace;
|
||||
MKFLOAT GammaValue;
|
||||
|
||||
MKFLOAT GammaValue;
|
||||
struct {
|
||||
unsigned int MatrixCoefficients;
|
||||
unsigned int BitsPerChannel;
|
||||
unsigned int TransferCharacteristics;
|
||||
unsigned int Primaries;
|
||||
unsigned int MatrixCoefficients;
|
||||
unsigned int BitsPerChannel;
|
||||
unsigned int ChromaSubsamplingHorz;
|
||||
unsigned int ChromaSubsamplingVert;
|
||||
unsigned int CbSubsamplingHorz;
|
||||
unsigned int CbSubsamplingVert;
|
||||
unsigned int ChromaSitingHorz;
|
||||
unsigned int ChromaSitingVert;
|
||||
unsigned int Range;
|
||||
unsigned int TransferCharacteristics;
|
||||
unsigned int Primaries;
|
||||
unsigned int MaxCLL;
|
||||
unsigned int MaxFALL;
|
||||
struct {
|
||||
float PrimaryRChromaticityX;
|
||||
float PrimaryRChromaticityY;
|
||||
float PrimaryGChromaticityX;
|
||||
float PrimaryGChromaticityY;
|
||||
float PrimaryBChromaticityX;
|
||||
float PrimaryBChromaticityY;
|
||||
float WhitePointChromaticityX;
|
||||
float WhitePointChromaticityY;
|
||||
float LuminanceMax;
|
||||
float LuminanceMin;
|
||||
} MasteringMetadata;
|
||||
} Colour;
|
||||
|
||||
unsigned int Interlaced:1;
|
||||
} Video;
|
||||
struct {
|
||||
MKFLOAT SamplingFreq;
|
||||
MKFLOAT OutputSamplingFreq;
|
||||
MKFLOAT SamplingFreq;
|
||||
MKFLOAT OutputSamplingFreq;
|
||||
unsigned char Channels;
|
||||
unsigned char BitDepth;
|
||||
} Audio;
|
||||
} AV;
|
||||
|
||||
/* various strings */
|
||||
char *Name;
|
||||
char Language[4];
|
||||
char *CodecID;
|
||||
char *Name;
|
||||
char Language[4];
|
||||
char *CodecID;
|
||||
|
||||
unsigned int NeedKeyframes;
|
||||
};
|
||||
|
||||
typedef struct TrackInfo TrackInfo;
|
||||
|
||||
struct SegmentInfo {
|
||||
char UID[16];
|
||||
char PrevUID[16];
|
||||
char NextUID[16];
|
||||
char *Filename;
|
||||
char *PrevFilename;
|
||||
char *NextFilename;
|
||||
char *Title;
|
||||
char *MuxingApp;
|
||||
char *WritingApp;
|
||||
ulonglong TimecodeScale;
|
||||
ulonglong Duration;
|
||||
longlong DateUTC;
|
||||
char DateUTCValid;
|
||||
char UID[16];
|
||||
char PrevUID[16];
|
||||
char NextUID[16];
|
||||
char *Filename;
|
||||
char *PrevFilename;
|
||||
char *NextFilename;
|
||||
char *Title;
|
||||
char *MuxingApp;
|
||||
char *WritingApp;
|
||||
ulonglong TimecodeScale;
|
||||
ulonglong Duration;
|
||||
longlong DateUTC;
|
||||
char DateUTCValid;
|
||||
};
|
||||
|
||||
typedef struct SegmentInfo SegmentInfo;
|
||||
|
||||
struct Attachment {
|
||||
ulonglong Position;
|
||||
ulonglong Length;
|
||||
ulonglong UID;
|
||||
char *Name;
|
||||
char *Description;
|
||||
char *MimeType;
|
||||
ulonglong Position;
|
||||
ulonglong Length;
|
||||
ulonglong UID;
|
||||
char *Name;
|
||||
char *Description;
|
||||
char *MimeType;
|
||||
};
|
||||
|
||||
typedef struct Attachment Attachment;
|
||||
|
||||
struct ChapterDisplay {
|
||||
char *String;
|
||||
char Language[4];
|
||||
char Country[4];
|
||||
char *String;
|
||||
char Language[4];
|
||||
char Country[4];
|
||||
};
|
||||
|
||||
struct ChapterCommand {
|
||||
unsigned Time;
|
||||
unsigned CommandLength;
|
||||
void *Command;
|
||||
unsigned Time;
|
||||
unsigned CommandLength;
|
||||
void *Command;
|
||||
};
|
||||
|
||||
struct ChapterProcess {
|
||||
unsigned CodecID;
|
||||
unsigned CodecPrivateLength;
|
||||
void *CodecPrivate;
|
||||
unsigned nCommands,nCommandsSize;
|
||||
struct ChapterCommand *Commands;
|
||||
unsigned CodecID;
|
||||
unsigned CodecPrivateLength;
|
||||
void *CodecPrivate;
|
||||
unsigned nCommands,nCommandsSize;
|
||||
struct ChapterCommand *Commands;
|
||||
};
|
||||
|
||||
struct Chapter {
|
||||
ulonglong UID;
|
||||
ulonglong Start;
|
||||
ulonglong End;
|
||||
ulonglong UID;
|
||||
ulonglong Start;
|
||||
ulonglong End;
|
||||
|
||||
unsigned nTracks,nTracksSize;
|
||||
ulonglong *Tracks;
|
||||
unsigned nDisplay,nDisplaySize;
|
||||
struct ChapterDisplay *Display;
|
||||
unsigned nChildren,nChildrenSize;
|
||||
struct Chapter *Children;
|
||||
unsigned nProcess,nProcessSize;
|
||||
struct ChapterProcess *Process;
|
||||
unsigned nTracks,nTracksSize;
|
||||
ulonglong *Tracks;
|
||||
unsigned nDisplay,nDisplaySize;
|
||||
struct ChapterDisplay *Display;
|
||||
unsigned nChildren,nChildrenSize;
|
||||
struct Chapter *Children;
|
||||
unsigned nProcess,nProcessSize;
|
||||
struct ChapterProcess *Process;
|
||||
|
||||
char SegmentUID[16];
|
||||
char SegmentUID[16];
|
||||
|
||||
unsigned int Hidden:1;
|
||||
unsigned int Enabled:1;
|
||||
unsigned int Hidden:1;
|
||||
unsigned int Enabled:1;
|
||||
|
||||
// Editions
|
||||
unsigned int Default:1;
|
||||
unsigned int Ordered:1;
|
||||
unsigned int Default:1;
|
||||
unsigned int Ordered:1;
|
||||
};
|
||||
|
||||
typedef struct Chapter Chapter;
|
||||
typedef struct Chapter Chapter;
|
||||
|
||||
#define TARGET_TRACK 0
|
||||
#define TARGET_CHAPTER 1
|
||||
#define TARGET_ATTACHMENT 2
|
||||
#define TARGET_EDITION 3
|
||||
struct Cue {
|
||||
ulonglong Time;
|
||||
ulonglong Duration;
|
||||
ulonglong Position;
|
||||
ulonglong RelativePosition;
|
||||
ulonglong Block;
|
||||
unsigned char Track;
|
||||
};
|
||||
|
||||
typedef struct Cue Cue;
|
||||
|
||||
#define TARGET_TRACK 0
|
||||
#define TARGET_CHAPTER 1
|
||||
#define TARGET_ATTACHMENT 2
|
||||
#define TARGET_EDITION 3
|
||||
struct Target {
|
||||
ulonglong UID;
|
||||
unsigned Type;
|
||||
ulonglong UID;
|
||||
unsigned Type;
|
||||
};
|
||||
|
||||
struct SimpleTag {
|
||||
char *Name;
|
||||
char *Value;
|
||||
char Language[4];
|
||||
unsigned Default:1;
|
||||
char *Name;
|
||||
char *Value;
|
||||
char Language[4];
|
||||
unsigned Default:1;
|
||||
};
|
||||
|
||||
struct Tag {
|
||||
unsigned nTargets,nTargetsSize;
|
||||
struct Target *Targets;
|
||||
unsigned nTargets,nTargetsSize;
|
||||
struct Target *Targets;
|
||||
|
||||
unsigned nSimpleTags,nSimpleTagsSize;
|
||||
unsigned nSimpleTags,nSimpleTagsSize;
|
||||
struct SimpleTag *SimpleTags;
|
||||
};
|
||||
|
||||
@@ -279,21 +314,26 @@ typedef struct Tag Tag;
|
||||
* io pointer is recorded inside MatroskaFile
|
||||
*/
|
||||
X MatroskaFile *mkv_Open(/* in */ InputStream *io,
|
||||
/* out */ char *err_msg,
|
||||
/* in */ unsigned msgsize);
|
||||
/* out */ char *err_msg,
|
||||
/* in */ unsigned msgsize);
|
||||
|
||||
#define MKVF_AVOID_SEEKS 1 /* use sequential reading only */
|
||||
#define MKVF_AVOID_SEEKS 1 /* use sequential reading only */
|
||||
|
||||
X MatroskaFile *mkv_OpenEx(/* in */ InputStream *io,
|
||||
/* in */ ulonglong base,
|
||||
/* in */ unsigned flags,
|
||||
/* out */ char *err_msg,
|
||||
/* in */ unsigned msgsize);
|
||||
/* in */ ulonglong base,
|
||||
/* in */ unsigned flags,
|
||||
/* out */ char *err_msg,
|
||||
/* in */ unsigned msgsize);
|
||||
|
||||
/* Open the file and only parse enough information to find the segment uid */
|
||||
X MatroskaFile *mkv_OpenSparse(/* in */ InputStream *io,
|
||||
/* out */ char *err_msg,
|
||||
/* in */ unsigned msgsize);
|
||||
|
||||
/* Close and deallocate mf
|
||||
* NULL pointer is ok and is simply ignored
|
||||
*/
|
||||
X void mkv_Close(/* in */ MatroskaFile *mf);
|
||||
X void mkv_Close(/* in */ MatroskaFile *mf);
|
||||
|
||||
/* Fetch the error message of the last failed operation */
|
||||
X const char *mkv_GetLastError(/* in */ MatroskaFile *mf);
|
||||
@@ -306,15 +346,17 @@ X unsigned int mkv_GetNumTracks(/* in */ MatroskaFile *mf);
|
||||
X TrackInfo *mkv_GetTrackInfo(/* in */ MatroskaFile *mf,/* in */ unsigned track);
|
||||
|
||||
/* chapters, tags and attachments */
|
||||
X void mkv_GetAttachments(/* in */ MatroskaFile *mf,
|
||||
/* out */ Attachment **at,
|
||||
/* out */ unsigned *count);
|
||||
X void mkv_GetChapters(/* in */ MatroskaFile *mf,
|
||||
/* out */ Chapter **ch,
|
||||
/* out */ unsigned *count);
|
||||
X void mkv_GetTags(/* in */ MatroskaFile *mf,
|
||||
/* out */ Tag **tag,
|
||||
/* out */ unsigned *count);
|
||||
X void mkv_GetAttachments(/* in */ MatroskaFile *mf,
|
||||
/* out */ Attachment **at,
|
||||
/* out */ unsigned *count);
|
||||
X void mkv_GetChapters(/* in */ MatroskaFile *mf,
|
||||
/* out */ Chapter **ch,
|
||||
/* out */ unsigned *count);
|
||||
X void mkv_GetTags(/* in */ MatroskaFile *mf,
|
||||
/* out */ Tag **tag,
|
||||
/* out */ unsigned *count);
|
||||
|
||||
X void mkv_GetCues(MatroskaFile *mf, Cue **cue, unsigned *count);
|
||||
|
||||
X ulonglong mkv_GetSegmentTop(MatroskaFile *mf);
|
||||
|
||||
@@ -323,51 +365,55 @@ X ulonglong mkv_GetSegmentTop(MatroskaFile *mf);
|
||||
* all tracks are set to return EOF
|
||||
* on next read
|
||||
*/
|
||||
#define MKVF_SEEK_TO_PREV_KEYFRAME 1
|
||||
#define MKVF_SEEK_TO_PREV_KEYFRAME_STRICT 2
|
||||
#define MKVF_SEEK_TO_PREV_KEYFRAME 1
|
||||
#define MKVF_SEEK_TO_PREV_KEYFRAME_STRICT 2
|
||||
|
||||
X void mkv_Seek(/* in */ MatroskaFile *mf,
|
||||
/* in */ ulonglong timecode /* in ns */,
|
||||
/* in */ unsigned flags);
|
||||
X void mkv_Seek(/* in */ MatroskaFile *mf,
|
||||
/* in */ ulonglong timecode /* in ns */,
|
||||
/* in */ unsigned flags);
|
||||
|
||||
X void mkv_SkipToKeyframe(MatroskaFile *mf);
|
||||
X void mkv_Seek_CueAware(MatroskaFile *mf, ulonglong timecode, unsigned flags, unsigned fuzzy);
|
||||
|
||||
X void mkv_SkipToKeyframe(MatroskaFile *mf);
|
||||
|
||||
X ulonglong mkv_GetLowestQTimecode(MatroskaFile *mf);
|
||||
|
||||
X int mkv_TruncFloat(MKFLOAT f);
|
||||
X int mkv_TruncFloat(MKFLOAT f);
|
||||
|
||||
/*************************************************************************
|
||||
* reading data, pull model
|
||||
*/
|
||||
|
||||
/* frame flags */
|
||||
#define FRAME_UNKNOWN_START 0x00000001
|
||||
#define FRAME_UNKNOWN_END 0x00000002
|
||||
#define FRAME_KF 0x00000004
|
||||
#define FRAME_GAP 0x00800000
|
||||
#define FRAME_STREAM_MASK 0xff000000
|
||||
#define FRAME_STREAM_SHIFT 24
|
||||
#define FRAME_UNKNOWN_START 0x00000001
|
||||
#define FRAME_UNKNOWN_END 0x00000002
|
||||
#define FRAME_KF 0x00000004
|
||||
#define FRAME_GAP 0x00800000
|
||||
#define FRAME_STREAM_MASK 0xff000000
|
||||
#define FRAME_STREAM_SHIFT 24
|
||||
|
||||
/* This sets the masking flags for the parser,
|
||||
* masked tracks [with 1s in their bit positions]
|
||||
* will be ignored when reading file data.
|
||||
* This call discards all parsed and queued frames
|
||||
*/
|
||||
X void mkv_SetTrackMask(/* in */ MatroskaFile *mf,/* in */ unsigned long mask);
|
||||
X void mkv_SetTrackMask(/* in */ MatroskaFile *mf,/* in */ ulonglong mask);
|
||||
|
||||
/* Read one frame from the queue.
|
||||
* mask specifies what tracks to ignore.
|
||||
* Returns -1 if there are no more frames in the specified
|
||||
* set of tracks, 0 on success
|
||||
*/
|
||||
X int mkv_ReadFrame(/* in */ MatroskaFile *mf,
|
||||
/* in */ unsigned int mask,
|
||||
/* out */ unsigned int *track,
|
||||
/* out */ ulonglong *StartTime /* in ns */,
|
||||
/* out */ ulonglong *EndTime /* in ns */,
|
||||
/* out */ ulonglong *FilePos /* in bytes from start of file */,
|
||||
/* out */ unsigned int *FrameSize /* in bytes */,
|
||||
/* out */ unsigned int *FrameFlags);
|
||||
X int mkv_ReadFrame(/* in */ MatroskaFile *mf,
|
||||
/* in */ ulonglong mask,
|
||||
/* out */ unsigned int *track,
|
||||
/* out */ ulonglong *StartTime /* in ns */,
|
||||
/* out */ ulonglong *EndTime /* in ns */,
|
||||
/* out */ ulonglong *FilePos /* in bytes from start of file */,
|
||||
/* out */ unsigned int *FrameSize /* in bytes */,
|
||||
/* out */ char **FrameData,
|
||||
/* out */ unsigned int *FrameFlags,
|
||||
/* out */ longlong *FrameDiscard);
|
||||
|
||||
#ifdef MATROSKA_COMPRESSION_SUPPORT
|
||||
/* Compressed streams support */
|
||||
@@ -375,24 +421,24 @@ struct CompressedStream;
|
||||
|
||||
typedef struct CompressedStream CompressedStream;
|
||||
|
||||
X CompressedStream *cs_Create(/* in */ MatroskaFile *mf,
|
||||
/* in */ unsigned tracknum,
|
||||
/* out */ char *errormsg,
|
||||
/* in */ unsigned msgsize);
|
||||
X void cs_Destroy(/* in */ CompressedStream *cs);
|
||||
X CompressedStream *cs_Create(/* in */ MatroskaFile *mf,
|
||||
/* in */ unsigned tracknum,
|
||||
/* out */ char *errormsg,
|
||||
/* in */ unsigned msgsize);
|
||||
X void cs_Destroy(/* in */ CompressedStream *cs);
|
||||
|
||||
/* advance to the next frame in matroska stream, you need to pass values returned
|
||||
* by mkv_ReadFrame */
|
||||
X void cs_NextFrame(/* in */ CompressedStream *cs,
|
||||
/* in */ ulonglong pos,
|
||||
/* in */ unsigned size);
|
||||
X void cs_NextFrame(/* in */ CompressedStream *cs,
|
||||
/* in */ unsigned size,
|
||||
/* in */ char *frame_data);
|
||||
|
||||
/* read and decode more data from current frame, return number of bytes decoded,
|
||||
* 0 on end of frame, or -1 on error */
|
||||
X int cs_ReadData(CompressedStream *cs,char *buffer,unsigned bufsize);
|
||||
X int cs_ReadData(CompressedStream *cs,char *buffer,unsigned bufsize);
|
||||
|
||||
/* return error message for the last error */
|
||||
X const char *cs_GetLastError(CompressedStream *cs);
|
||||
X const char *cs_GetLastError(CompressedStream *cs);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in new issue
Block a user