1 | /* $Id: EbmlWriter.h 50041 2014-01-09 16:13:28Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * EbmlWriter.h - EBML writer + WebM container.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /*
|
---|
19 | * This code is based on:
|
---|
20 | *
|
---|
21 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
---|
22 | *
|
---|
23 | * Use of this source code is governed by a BSD-style license
|
---|
24 | * that can be found in the LICENSE file in the root of the source
|
---|
25 | * tree. An additional intellectual property rights grant can be found
|
---|
26 | * in the file PATENTS. All contributing project authors may
|
---|
27 | * be found in the AUTHORS file in the root of the source tree.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef ____EBMLWRITER
|
---|
31 | #define ____EBMLWRITER
|
---|
32 |
|
---|
33 | #include <iprt/file.h>
|
---|
34 | #include <vpx/vpx_encoder.h>
|
---|
35 |
|
---|
36 | enum mkv
|
---|
37 | {
|
---|
38 | EBML = 0x1A45DFA3,
|
---|
39 | EBMLVersion = 0x4286,
|
---|
40 | EBMLReadVersion = 0x42F7,
|
---|
41 | EBMLMaxIDLength = 0x42F2,
|
---|
42 | EBMLMaxSizeLength = 0x42F3,
|
---|
43 | DocType = 0x4282,
|
---|
44 | DocTypeVersion = 0x4287,
|
---|
45 | DocTypeReadVersion = 0x4285,
|
---|
46 | // CRC_32 = 0xBF,
|
---|
47 | Void = 0xEC,
|
---|
48 | SignatureSlot = 0x1B538667,
|
---|
49 | SignatureAlgo = 0x7E8A,
|
---|
50 | SignatureHash = 0x7E9A,
|
---|
51 | SignaturePublicKey = 0x7EA5,
|
---|
52 | Signature = 0x7EB5,
|
---|
53 | SignatureElements = 0x7E5B,
|
---|
54 | SignatureElementList = 0x7E7B,
|
---|
55 | SignedElement = 0x6532,
|
---|
56 | //segment
|
---|
57 | Segment = 0x18538067,
|
---|
58 | //Meta Seek Information
|
---|
59 | SeekHead = 0x114D9B74,
|
---|
60 | Seek = 0x4DBB,
|
---|
61 | SeekID = 0x53AB,
|
---|
62 | SeekPosition = 0x53AC,
|
---|
63 | //Segment Information
|
---|
64 | Info = 0x1549A966,
|
---|
65 | // SegmentUID = 0x73A4,
|
---|
66 | // SegmentFilename = 0x7384,
|
---|
67 | // PrevUID = 0x3CB923,
|
---|
68 | // PrevFilename = 0x3C83AB,
|
---|
69 | // NextUID = 0x3EB923,
|
---|
70 | // NextFilename = 0x3E83BB,
|
---|
71 | // SegmentFamily = 0x4444,
|
---|
72 | // ChapterTranslate = 0x6924,
|
---|
73 | // ChapterTranslateEditionUID = 0x69FC,
|
---|
74 | // ChapterTranslateCodec = 0x69BF,
|
---|
75 | // ChapterTranslateID = 0x69A5,
|
---|
76 | TimecodeScale = 0x2AD7B1,
|
---|
77 | Segment_Duration = 0x4489,
|
---|
78 | DateUTC = 0x4461,
|
---|
79 | // Title = 0x7BA9,
|
---|
80 | MuxingApp = 0x4D80,
|
---|
81 | WritingApp = 0x5741,
|
---|
82 | //Cluster
|
---|
83 | Cluster = 0x1F43B675,
|
---|
84 | Timecode = 0xE7,
|
---|
85 | // SilentTracks = 0x5854,
|
---|
86 | // SilentTrackNumber = 0x58D7,
|
---|
87 | // Position = 0xA7,
|
---|
88 | PrevSize = 0xAB,
|
---|
89 | BlockGroup = 0xA0,
|
---|
90 | Block = 0xA1,
|
---|
91 | // BlockVirtual = 0xA2,
|
---|
92 | // BlockAdditions = 0x75A1,
|
---|
93 | // BlockMore = 0xA6,
|
---|
94 | // BlockAddID = 0xEE,
|
---|
95 | // BlockAdditional = 0xA5,
|
---|
96 | BlockDuration = 0x9B,
|
---|
97 | // ReferencePriority = 0xFA,
|
---|
98 | ReferenceBlock = 0xFB,
|
---|
99 | // ReferenceVirtual = 0xFD,
|
---|
100 | // CodecState = 0xA4,
|
---|
101 | // Slices = 0x8E,
|
---|
102 | // TimeSlice = 0xE8,
|
---|
103 | LaceNumber = 0xCC,
|
---|
104 | // FrameNumber = 0xCD,
|
---|
105 | // BlockAdditionID = 0xCB,
|
---|
106 | // MkvDelay = 0xCE,
|
---|
107 | // Cluster_Duration = 0xCF,
|
---|
108 | SimpleBlock = 0xA3,
|
---|
109 | // EncryptedBlock = 0xAF,
|
---|
110 | //Track
|
---|
111 | Tracks = 0x1654AE6B,
|
---|
112 | TrackEntry = 0xAE,
|
---|
113 | TrackNumber = 0xD7,
|
---|
114 | TrackUID = 0x73C5,
|
---|
115 | TrackType = 0x83,
|
---|
116 | FlagEnabled = 0xB9,
|
---|
117 | FlagDefault = 0x88,
|
---|
118 | FlagForced = 0x55AA,
|
---|
119 | FlagLacing = 0x9C,
|
---|
120 | // MinCache = 0x6DE7,
|
---|
121 | // MaxCache = 0x6DF8,
|
---|
122 | DefaultDuration = 0x23E383,
|
---|
123 | // TrackTimecodeScale = 0x23314F,
|
---|
124 | // TrackOffset = 0x537F,
|
---|
125 | // MaxBlockAdditionID = 0x55EE,
|
---|
126 | Name = 0x536E,
|
---|
127 | Language = 0x22B59C,
|
---|
128 | CodecID = 0x86,
|
---|
129 | CodecPrivate = 0x63A2,
|
---|
130 | CodecName = 0x258688,
|
---|
131 | // AttachmentLink = 0x7446,
|
---|
132 | // CodecSettings = 0x3A9697,
|
---|
133 | // CodecInfoURL = 0x3B4040,
|
---|
134 | // CodecDownloadURL = 0x26B240,
|
---|
135 | // CodecDecodeAll = 0xAA,
|
---|
136 | // TrackOverlay = 0x6FAB,
|
---|
137 | // TrackTranslate = 0x6624,
|
---|
138 | // TrackTranslateEditionUID = 0x66FC,
|
---|
139 | // TrackTranslateCodec = 0x66BF,
|
---|
140 | // TrackTranslateTrackID = 0x66A5,
|
---|
141 | //video
|
---|
142 | Video = 0xE0,
|
---|
143 | FlagInterlaced = 0x9A,
|
---|
144 | // StereoMode = 0x53B8,
|
---|
145 | PixelWidth = 0xB0,
|
---|
146 | PixelHeight = 0xBA,
|
---|
147 | PixelCropBottom = 0x54AA,
|
---|
148 | PixelCropTop = 0x54BB,
|
---|
149 | PixelCropLeft = 0x54CC,
|
---|
150 | PixelCropRight = 0x54DD,
|
---|
151 | DisplayWidth = 0x54B0,
|
---|
152 | DisplayHeight = 0x54BA,
|
---|
153 | DisplayUnit = 0x54B2,
|
---|
154 | AspectRatioType = 0x54B3,
|
---|
155 | // ColourSpace = 0x2EB524,
|
---|
156 | // GammaValue = 0x2FB523,
|
---|
157 | FrameRate = 0x2383E3,
|
---|
158 | //end video
|
---|
159 | //audio
|
---|
160 | Audio = 0xE1,
|
---|
161 | SamplingFrequency = 0xB5,
|
---|
162 | OutputSamplingFrequency = 0x78B5,
|
---|
163 | Channels = 0x9F,
|
---|
164 | // ChannelPositions = 0x7D7B,
|
---|
165 | BitDepth = 0x6264,
|
---|
166 | //end audio
|
---|
167 | //content encoding
|
---|
168 | // ContentEncodings = 0x6d80,
|
---|
169 | // ContentEncoding = 0x6240,
|
---|
170 | // ContentEncodingOrder = 0x5031,
|
---|
171 | // ContentEncodingScope = 0x5032,
|
---|
172 | // ContentEncodingType = 0x5033,
|
---|
173 | // ContentCompression = 0x5034,
|
---|
174 | // ContentCompAlgo = 0x4254,
|
---|
175 | // ContentCompSettings = 0x4255,
|
---|
176 | // ContentEncryption = 0x5035,
|
---|
177 | // ContentEncAlgo = 0x47e1,
|
---|
178 | // ContentEncKeyID = 0x47e2,
|
---|
179 | // ContentSignature = 0x47e3,
|
---|
180 | // ContentSigKeyID = 0x47e4,
|
---|
181 | // ContentSigAlgo = 0x47e5,
|
---|
182 | // ContentSigHashAlgo = 0x47e6,
|
---|
183 | //end content encoding
|
---|
184 | //Cueing Data
|
---|
185 | Cues = 0x1C53BB6B,
|
---|
186 | CuePoint = 0xBB,
|
---|
187 | CueTime = 0xB3,
|
---|
188 | CueTrackPositions = 0xB7,
|
---|
189 | CueTrack = 0xF7,
|
---|
190 | CueClusterPosition = 0xF1,
|
---|
191 | CueBlockNumber = 0x5378
|
---|
192 | // CueCodecState = 0xEA,
|
---|
193 | // CueReference = 0xDB,
|
---|
194 | // CueRefTime = 0x96,
|
---|
195 | // CueRefCluster = 0x97,
|
---|
196 | // CueRefNumber = 0x535F,
|
---|
197 | // CueRefCodecState = 0xEB,
|
---|
198 | //Attachment
|
---|
199 | // Attachments = 0x1941A469,
|
---|
200 | // AttachedFile = 0x61A7,
|
---|
201 | // FileDescription = 0x467E,
|
---|
202 | // FileName = 0x466E,
|
---|
203 | // FileMimeType = 0x4660,
|
---|
204 | // FileData = 0x465C,
|
---|
205 | // FileUID = 0x46AE,
|
---|
206 | // FileReferral = 0x4675,
|
---|
207 | //Chapters
|
---|
208 | // Chapters = 0x1043A770,
|
---|
209 | // EditionEntry = 0x45B9,
|
---|
210 | // EditionUID = 0x45BC,
|
---|
211 | // EditionFlagHidden = 0x45BD,
|
---|
212 | // EditionFlagDefault = 0x45DB,
|
---|
213 | // EditionFlagOrdered = 0x45DD,
|
---|
214 | // ChapterAtom = 0xB6,
|
---|
215 | // ChapterUID = 0x73C4,
|
---|
216 | // ChapterTimeStart = 0x91,
|
---|
217 | // ChapterTimeEnd = 0x92,
|
---|
218 | // ChapterFlagHidden = 0x98,
|
---|
219 | // ChapterFlagEnabled = 0x4598,
|
---|
220 | // ChapterSegmentUID = 0x6E67,
|
---|
221 | // ChapterSegmentEditionUID = 0x6EBC,
|
---|
222 | // ChapterPhysicalEquiv = 0x63C3,
|
---|
223 | // ChapterTrack = 0x8F,
|
---|
224 | // ChapterTrackNumber = 0x89,
|
---|
225 | // ChapterDisplay = 0x80,
|
---|
226 | // ChapString = 0x85,
|
---|
227 | // ChapLanguage = 0x437C,
|
---|
228 | // ChapCountry = 0x437E,
|
---|
229 | // ChapProcess = 0x6944,
|
---|
230 | // ChapProcessCodecID = 0x6955,
|
---|
231 | // ChapProcessPrivate = 0x450D,
|
---|
232 | // ChapProcessCommand = 0x6911,
|
---|
233 | // ChapProcessTime = 0x6922,
|
---|
234 | // ChapProcessData = 0x6933,
|
---|
235 | //Tagging
|
---|
236 | // Tags = 0x1254C367,
|
---|
237 | // Tag = 0x7373,
|
---|
238 | // Targets = 0x63C0,
|
---|
239 | // TargetTypeValue = 0x68CA,
|
---|
240 | // TargetType = 0x63CA,
|
---|
241 | // Tagging_TrackUID = 0x63C5,
|
---|
242 | // Tagging_EditionUID = 0x63C9,
|
---|
243 | // Tagging_ChapterUID = 0x63C4,
|
---|
244 | // AttachmentUID = 0x63C6,
|
---|
245 | // SimpleTag = 0x67C8,
|
---|
246 | // TagName = 0x45A3,
|
---|
247 | // TagLanguage = 0x447A,
|
---|
248 | // TagDefault = 0x4484,
|
---|
249 | // TagString = 0x4487,
|
---|
250 | // TagBinary = 0x4485,
|
---|
251 | };
|
---|
252 |
|
---|
253 | struct cue_entry
|
---|
254 | {
|
---|
255 | uint32_t time;
|
---|
256 | uint64_t loc;
|
---|
257 | };
|
---|
258 |
|
---|
259 | struct EbmlGlobal
|
---|
260 | {
|
---|
261 | int debug;
|
---|
262 | RTFILE file;
|
---|
263 | int64_t last_pts_ms;
|
---|
264 | vpx_rational_t framerate;
|
---|
265 |
|
---|
266 | uint64_t position_reference;
|
---|
267 | uint64_t seek_info_pos;
|
---|
268 | uint64_t segment_info_pos;
|
---|
269 | uint64_t track_pos;
|
---|
270 | uint64_t cue_pos;
|
---|
271 | uint64_t cluster_pos;
|
---|
272 |
|
---|
273 | uint64_t track_id_pos;
|
---|
274 |
|
---|
275 | uint64_t startSegment;
|
---|
276 | uint64_t startCluster;
|
---|
277 |
|
---|
278 | uint32_t cluster_timecode;
|
---|
279 | int cluster_open;
|
---|
280 |
|
---|
281 | struct cue_entry *cue_list;
|
---|
282 | unsigned int cues;
|
---|
283 | };
|
---|
284 |
|
---|
285 | int Ebml_WriteWebMSeekElement(EbmlGlobal *ebml, uint32_t id, uint64_t pos);
|
---|
286 | int Ebml_WriteWebMSeekInfo(EbmlGlobal *ebml);
|
---|
287 | int Ebml_WriteWebMFileHeader(EbmlGlobal *glob, const vpx_codec_enc_cfg_t *cfg, const struct vpx_rational *fps);
|
---|
288 | int Ebml_WriteWebMBlock(EbmlGlobal *glob, const vpx_codec_enc_cfg_t *cfg, const vpx_codec_cx_pkt_t *pkt);
|
---|
289 | int Ebml_WriteWebMFileFooter(EbmlGlobal *glob, long hash);
|
---|
290 |
|
---|
291 | #endif
|
---|