matroska.h 9.9 KB
Newer Older
1
/*
Steve Lhomme's avatar
Steve Lhomme committed
2
 * $Id$
3
 * Copyright (c) 2008-2011, Matroska (non-profit organisation)
4 5 6 7 8 9 10 11 12
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
13
 *     * Neither the name of the Matroska assocation nor the
14 15 16
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
17
 * THIS SOFTWARE IS PROVIDED BY the Matroska association ``AS IS'' AND ANY
18 19 20 21 22 23 24 25 26 27
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL The Matroska Foundation BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY 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.
 */
28 29 30
#ifndef MATROSKA_MATROSKA_H
#define MATROSKA_MATROSKA_H

31 32 33 34 35 36 37 38 39 40
#include "ebml/ebml.h"

#if defined(MATROSKA2_EXPORTS)
#define MATROSKA_DLL DLLEXPORT
#elif defined(MATROSKA2_IMPORTS)
#define MATROSKA_DLL DLLIMPORT
#else
#define MATROSKA_DLL
#endif

41 42
#define CONTEXT_LIBMATROSKA_VERSION  0x401

43 44 45
// if a profile is set in ebml_semantic.DisabledProfile that means the element is not available for that profile
#define PROFILE_MATROSKA_V1          1
#define PROFILE_MATROSKA_V2          2
46 47 48
#define PROFILE_MATROSKA_V3          4
#define PROFILE_WEBM                 8
#define PROFILE_DIVX                16
49

50 51
#define MATROSKA_VERSION  2

52
#define MATROSKA_BLOCK_COMPR_NONE   -1
53 54 55 56 57
#define MATROSKA_BLOCK_COMPR_ZLIB    0
#define MATROSKA_BLOCK_COMPR_BZLIB   1
#define MATROSKA_BLOCK_COMPR_LZO1X   2
#define MATROSKA_BLOCK_COMPR_HEADER  3

58 59 60 61
#define MATROSKA_COMPR_SCOPE_BLOCK   1
#define MATROSKA_COMPR_SCOPE_PRIVATE 2
#define MATROSKA_COMPR_SCOPE_NEXT    4

62 63 64 65 66
#define MATROSKA_DISPLAY_UNIT_PIXEL  0
#define MATROSKA_DISPLAY_UNIT_CM     1
#define MATROSKA_DISPLAY_UNIT_INCHES 2
#define MATROSKA_DISPLAY_UNIT_DAR    3

67

68 69 70
EBML_DLL err_t MATROSKA_Init(nodecontext *p);
EBML_DLL err_t MATROSKA_Done(nodecontext *p);

71 72 73
#define INVALID_TIMECODE_T      MAX_INT64
typedef int64_t    timecode_t; // in nanoseconds

74 75 76 77 78 79 80
#define TRACK_TYPE_VIDEO    1
#define TRACK_TYPE_AUDIO    2
#define TRACK_TYPE_COMPLEX  3
#define TRACK_TYPE_SUBTITLE 17
#define TRACK_TYPE_LOGO     16
#define TRACK_TYPE_BUTTONS  18
#define TRACK_TYPE_CONTROL  32
81

82 83 84 85 86 87 88 89 90 91 92 93 94
#define TRACK_STEREO_MODE_MONO                 0
#define TRACK_STEREO_MODE_SIDEBYSIDE_L         1
#define TRACK_STEREO_MODE_TOPBOTTOM_R          2
#define TRACK_STEREO_MODE_TOPBOTTOM_L          3
#define TRACK_STEREO_MODE_CHECKBOARD_R         4
#define TRACK_STEREO_MODE_CHECKBOARD_L         5
#define TRACK_STEREO_MODE_INTERLEAVED_R        6
#define TRACK_STEREO_MODE_INTERLEAVED_L        7
#define TRACK_STEREO_MODE_COL_INTERLEAVED_L    8
#define TRACK_STEREO_MODE_COL_INTERLEAVED_R    9
#define TRACK_STEREO_MODE_ANAGLYPH_CYAN_RED   10
#define TRACK_STEREO_MODE_SIDEBYSIDE_R        11
#define TRACK_STEREO_MODE_ANAGLYPH_GREEN_MAG  12
95 96
#define TRACK_STEREO_MODE_ALTERNATE_PACKED_L  13
#define TRACK_STEREO_MODE_ALTERNATE_PACKED_R  14
97

98 99 100 101
#define TRACK_PLANE_LEFT        0
#define TRACK_PLANE_RIGHT       1
#define TRACK_PLANE_BACKGROUND  2

102 103 104 105 106
#define TRACK_OLD_STEREOMODE_MONO   0
#define TRACK_OLD_STEREOMODE_RIGHT  1
#define TRACK_OLD_STEREOMODE_LEFT   2
#define TRACK_OLD_STEREOMODE_BOTH   3

107 108 109
typedef struct matroska_block matroska_block;
typedef struct matroska_cuepoint matroska_cuepoint;
typedef struct matroska_cluster matroska_cluster;
110
typedef struct matroska_seekpoint matroska_seekpoint;
111
typedef struct matroska_trackentry matroska_trackentry;
112

113 114 115 116 117 118 119 120 121
typedef struct matroska_frame
{
    uint8_t *Data;
    uint32_t Size;
    timecode_t Timecode;
    timecode_t Duration;

} matroska_frame;

122 123
EBML_DLL err_t MATROSKA_LinkMetaSeekElement(matroska_seekpoint *MetaSeek, ebml_element *Link);
EBML_DLL err_t MATROSKA_MetaSeekUpdate(matroska_seekpoint *MetaSeek);
124 125 126 127
EBML_DLL err_t MATROSKA_LinkClusterReadSegmentInfo(matroska_cluster *Cluster, ebml_master *SegmentInfo, bool_t UseForWriteToo);
EBML_DLL err_t MATROSKA_LinkBlockWithReadTracks(matroska_block *Block, ebml_master *Tracks, bool_t UseForWriteToo);
EBML_DLL err_t MATROSKA_LinkBlockReadTrack(matroska_block *Block, ebml_master *Track, bool_t UseForWriteToo);
EBML_DLL err_t MATROSKA_LinkBlockReadSegmentInfo(matroska_block *Block, ebml_master *SegmentInfo, bool_t UseForWriteToo);
128
#if defined(CONFIG_EBML_WRITING)
129 130 131 132
EBML_DLL err_t MATROSKA_LinkClusterWriteSegmentInfo(matroska_cluster *Cluster, ebml_master *SegmentInfo);
EBML_DLL err_t MATROSKA_LinkBlockWithWriteTracks(matroska_block *Block, ebml_master *Tracks);
EBML_DLL err_t MATROSKA_LinkBlockWriteTrack(matroska_block *Block, ebml_master *Track);
EBML_DLL err_t MATROSKA_LinkBlockWriteSegmentInfo(matroska_block *Block, ebml_master *SegmentInfo);
133
#endif
134
//EBML_DLL err_t MATROSKA_LinkCueTrack(const ebml_element *Cue, ebml_element *Tracks);
135
EBML_DLL err_t MATROSKA_LinkCueSegmentInfo(matroska_cuepoint *Cue, ebml_master *SegmentInfo);
136 137
EBML_DLL err_t MATROSKA_LinkCuePointBlock(matroska_cuepoint *Cue, matroska_block *Block);
EBML_DLL err_t MATROSKA_CuePointUpdate(matroska_cuepoint *Cue, ebml_element *Segment);
138 139
EBML_DLL double MATROSKA_TrackTimecodeScale(const ebml_master *Track);
EBML_DLL timecode_t MATROSKA_SegmentInfoTimecodeScale(const ebml_master *SegmentInfo);
140
EBML_DLL void MATROSKA_ClusterSetTimecode(matroska_cluster *Cluster, timecode_t Timecode);
141
EBML_DLL err_t MATROSKA_BlockSetTimecode(matroska_block *Block, timecode_t Timecode, timecode_t ClusterTimecode);
142
EBML_DLL timecode_t MATROSKA_ClusterTimecode(matroska_cluster *Cluster);
143
EBML_DLL timecode_t MATROSKA_ClusterTimecodeScale(matroska_cluster *Cluster, bool_t Read);
144
EBML_DLL timecode_t MATROSKA_BlockTimecode(matroska_block *Block);
145
EBML_DLL timecode_t MATROSKA_CueTimecode(const matroska_cuepoint *Cue);
146
EBML_DLL filepos_t MATROSKA_CuePosInSegment(const matroska_cuepoint *Cue);
147
EBML_DLL int16_t MATROSKA_BlockTrackNum(const matroska_block *Block);
148
EBML_DLL bool_t MATROSKA_BlockKeyframe(const matroska_block *Block);
149
EBML_DLL bool_t MATROSKA_BlockDiscardable(const matroska_block *Block);
150
EBML_DLL bool_t MATROSKA_BlockLaced(const matroska_block *Block);
151
EBML_DLL err_t MATROSKA_BlockReadData(matroska_block *Block, stream *Input);
152
EBML_DLL err_t MATROSKA_BlockReleaseData(matroska_block *Block, bool_t IncludingNotRead);
153
EBML_DLL int16_t MATROSKA_CueTrackNum(const matroska_cuepoint *Cue);
154
EBML_DLL void MATROSKA_CuesSort(ebml_master *Cues);
155
EBML_DLL void MATROSKA_AttachmentSort(ebml_master *Attachments);
156
EBML_DLL fourcc_t MATROSKA_MetaSeekID(const matroska_seekpoint *MetaSeek);
157
EBML_DLL bool_t MATROSKA_MetaSeekIsClass(const matroska_seekpoint *MetaSeek, const ebml_context *Class);
158 159
EBML_DLL filepos_t MATROSKA_MetaSeekPosInSegment(const matroska_seekpoint *MetaSeek);
EBML_DLL filepos_t MATROSKA_MetaSeekAbsolutePos(const matroska_seekpoint *MetaSeek);
160

161 162
EBML_DLL matroska_cuepoint *MATROSKA_CuesGetTimecodeStart(const ebml_element *Cues, timecode_t Timecode);

163
#if defined(CONFIG_EBML_WRITING)
164 165 166 167
EBML_DLL int MATROSKA_TrackGetBlockCompression(const matroska_trackentry *TrackEntry);
EBML_DLL bool_t MATROSKA_TrackSetCompressionZlib(matroska_trackentry *TrackEntry, int Scope);
EBML_DLL bool_t MATROSKA_TrackSetCompressionHeader(matroska_trackentry *TrackEntry, const uint8_t *Header, size_t HeaderSize);
EBML_DLL bool_t MATROSKA_TrackSetCompressionNone(matroska_trackentry *TrackEntry);
168 169 170
EBML_DLL err_t CompressFrameZLib(const uint8_t *Cursor, size_t CursorSize, uint8_t **OutBuf, size_t *OutSize);
#endif

171 172
EBML_DLL void MATROSKA_ClusterSort(matroska_cluster *Cluster); // not good with P frames!!!

173
EBML_DLL ebml_element *MATROSKA_BlockReadTrack(const matroska_block *Block);
174
EBML_DLL ebml_element *MATROSKA_BlockReadSegmentInfo(const matroska_block *Block);
175
#if defined(CONFIG_EBML_WRITING)
176
EBML_DLL ebml_element *MATROSKA_BlockWriteTrack(const matroska_block *Block);
177
EBML_DLL ebml_element *MATROSKA_BlockWriteSegmentInfo(const matroska_block *Block);
178
#endif
179

180
EBML_DLL err_t MATROSKA_BlockSkipToFrame(const matroska_block *Block, stream *Input, size_t FrameNum);
181
EBML_DLL void MATROSKA_BlockSetKeyframe(matroska_block *Block, bool_t Set);
182
EBML_DLL void MATROSKA_BlockSetDiscardable(matroska_block *Block, bool_t Set);
183
EBML_DLL err_t MATROSKA_BlockProcessFrameDurations(matroska_block *Block, stream *Input);
184 185 186 187
EBML_DLL size_t MATROSKA_BlockGetFrameCount(const matroska_block *Block);
EBML_DLL timecode_t MATROSKA_BlockGetFrameDuration(const matroska_block *Block, size_t FrameNum);
EBML_DLL timecode_t MATROSKA_BlockGetFrameStart(const matroska_block *Block, size_t FrameNum);
EBML_DLL timecode_t MATROSKA_BlockGetFrameEnd(const matroska_block *Block, size_t FrameNum);
188
EBML_DLL size_t MATROSKA_BlockGetLength(const matroska_block *Block, size_t FrameNum);
189

190
EBML_DLL err_t MATROSKA_BlockGetFrame(const matroska_block *Block, size_t FrameNum, matroska_frame *Frame, bool_t WithData);
191
EBML_DLL err_t MATROSKA_BlockAppendFrame(matroska_block *Block, const matroska_frame *Frame, timecode_t ClusterTimecode);
192 193


194
EBML_DLL matroska_block *MATROSKA_GetBlockForTimecode(matroska_cluster *Cluster, timecode_t Timecode, int16_t Track);
195
EBML_DLL void MATROSKA_LinkClusterBlocks(matroska_cluster *Cluster, ebml_master *RSegmentInfo, ebml_master *Tracks, bool_t KeepUnmatched);
196

197 198
extern const ebml_context MATROSKA_ContextStream;

199
#endif // MATROSKA_MATROSKA_H