1 // Copyright (c) 2012 The WebM project authors. All Rights Reserved. 2 // 3 // Use of this source code is governed by a BSD-style license 4 // that can be found in the LICENSE file in the root of the source 5 // tree. An additional intellectual property rights grant can be found 6 // in the file PATENTS. All contributing project authors may 7 // be found in the AUTHORS file in the root of the source tree. 8 9 #ifndef MKVMUXERUTIL_HPP 10 #define MKVMUXERUTIL_HPP 11 12 #include "mkvmuxertypes.hpp" 13 14 namespace mkvmuxer { 15 16 class IMkvWriter; 17 18 const uint64 kEbmlUnknownValue = 0x01FFFFFFFFFFFFFFULL; 19 const int64 kMaxBlockTimecode = 0x07FFFLL; 20 21 // Writes out |value| in Big Endian order. Returns 0 on success. 22 int32 SerializeInt(IMkvWriter* writer, int64 value, int32 size); 23 24 // Returns the size in bytes of the element. 25 int32 GetUIntSize(uint64 value); 26 int32 GetCodedUIntSize(uint64 value); 27 uint64 EbmlMasterElementSize(uint64 type, uint64 value); 28 uint64 EbmlElementSize(uint64 type, int64 value); 29 uint64 EbmlElementSize(uint64 type, uint64 value); 30 uint64 EbmlElementSize(uint64 type, float value); 31 uint64 EbmlElementSize(uint64 type, const char* value); 32 uint64 EbmlElementSize(uint64 type, const uint8* value, uint64 size); 33 34 // Creates an EBML coded number from |value| and writes it out. The size of 35 // the coded number is determined by the value of |value|. |value| must not 36 // be in a coded form. Returns 0 on success. 37 int32 WriteUInt(IMkvWriter* writer, uint64 value); 38 39 // Creates an EBML coded number from |value| and writes it out. The size of 40 // the coded number is determined by the value of |size|. |value| must not 41 // be in a coded form. Returns 0 on success. 42 int32 WriteUIntSize(IMkvWriter* writer, uint64 value, int32 size); 43 44 // Output an Mkv master element. Returns true if the element was written. 45 bool WriteEbmlMasterElement(IMkvWriter* writer, uint64 value, uint64 size); 46 47 // Outputs an Mkv ID, calls |IMkvWriter::ElementStartNotify|, and passes the 48 // ID to |SerializeInt|. Returns 0 on success. 49 int32 WriteID(IMkvWriter* writer, uint64 type); 50 51 // Output an Mkv non-master element. Returns true if the element was written. 52 bool WriteEbmlElement(IMkvWriter* writer, uint64 type, uint64 value); 53 bool WriteEbmlElement(IMkvWriter* writer, uint64 type, float value); 54 bool WriteEbmlElement(IMkvWriter* writer, uint64 type, const char* value); 55 bool WriteEbmlElement(IMkvWriter* writer, 56 uint64 type, 57 const uint8* value, 58 uint64 size); 59 60 // Output an Mkv Simple Block. 61 // Inputs: 62 // data: Pointer to the data. 63 // length: Length of the data. 64 // track_number: Track to add the data to. Value returned by Add track 65 // functions. Only values in the range [1, 126] are 66 // permitted. 67 // timecode: Relative timecode of the Block. Only values in the 68 // range [0, 2^15) are permitted. 69 // is_key: Non-zero value specifies that frame is a key frame. 70 uint64 WriteSimpleBlock(IMkvWriter* writer, 71 const uint8* data, 72 uint64 length, 73 uint64 track_number, 74 int64 timecode, 75 uint64 is_key); 76 77 // Output a metadata keyframe, using a Block Group element. 78 // Inputs: 79 // data: Pointer to the (meta)data. 80 // length: Length of the (meta)data. 81 // track_number: Track to add the data to. Value returned by Add track 82 // functions. Only values in the range [1, 126] are 83 // permitted. 84 // timecode Timecode of frame, relative to cluster timecode. Only 85 // values in the range [0, 2^15) are permitted. 86 // duration_timecode Duration of frame, using timecode units. 87 uint64 WriteMetadataBlock(IMkvWriter* writer, 88 const uint8* data, 89 uint64 length, 90 uint64 track_number, 91 int64 timecode, 92 uint64 duration_timecode); 93 94 // Output an Mkv Block with BlockAdditional data. 95 // Inputs: 96 // data: Pointer to the data. 97 // length: Length of the data. 98 // additional: Pointer to the additional data 99 // additional_length: Length of the additional data. 100 // add_id: Value of BlockAddID element. 101 // track_number: Track to add the data to. Value returned by Add track 102 // functions. Only values in the range [1, 126] are 103 // permitted. 104 // timecode: Relative timecode of the Block. Only values in the 105 // range [0, 2^15) are permitted. 106 // is_key: Non-zero value specifies that frame is a key frame. 107 uint64 WriteBlockWithAdditional(IMkvWriter* writer, 108 const uint8* data, 109 uint64 length, 110 const uint8* additional, 111 uint64 additional_length, 112 uint64 add_id, 113 uint64 track_number, 114 int64 timecode, 115 uint64 is_key); 116 117 // Output an Mkv Block with a DiscardPadding element. 118 // Inputs: 119 // data: Pointer to the data. 120 // length: Length of the data. 121 // discard_padding: DiscardPadding value. 122 // track_number: Track to add the data to. Value returned by Add track 123 // functions. Only values in the range [1, 126] are 124 // permitted. 125 // timecode: Relative timecode of the Block. Only values in the 126 // range [0, 2^15) are permitted. 127 // is_key: Non-zero value specifies that frame is a key frame. 128 uint64 WriteBlockWithDiscardPadding(IMkvWriter* writer, 129 const uint8* data, 130 uint64 length, 131 int64 discard_padding, 132 uint64 track_number, 133 int64 timecode, 134 uint64 is_key); 135 136 // Output a void element. |size| must be the entire size in bytes that will be 137 // void. The function will calculate the size of the void header and subtract 138 // it from |size|. 139 uint64 WriteVoidElement(IMkvWriter* writer, uint64 size); 140 141 // Returns the version number of the muxer in |major|, |minor|, |build|, 142 // and |revision|. 143 void GetVersion(int32* major, int32* minor, int32* build, int32* revision); 144 145 // Returns a random number to be used for UID, using |seed| to seed 146 // the random-number generator (see POSIX rand_r() for semantics). 147 uint64 MakeUID(unsigned int* seed); 148 149 } //end namespace mkvmuxer 150 151 #endif // MKVMUXERUTIL_HPP 152