]> granicus.if.org Git - libvpx/blob - third_party/libwebm/mkvmuxer/mkvmuxerutil.h
0e21a2dcbe52bc2a6f1edc6d00cc568502336a08
[libvpx] / third_party / libwebm / mkvmuxer / mkvmuxerutil.h
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 #ifndef MKVMUXER_MKVMUXERUTIL_H_
9 #define MKVMUXER_MKVMUXERUTIL_H_
10
11 #include <stdint.h>
12
13 namespace mkvmuxer {
14 class Cluster;
15 class Frame;
16 class IMkvWriter;
17
18 const uint64_t kEbmlUnknownValue = 0x01FFFFFFFFFFFFFFULL;
19 const int64_t kMaxBlockTimecode = 0x07FFFLL;
20
21 // Writes out |value| in Big Endian order. Returns 0 on success.
22 int32_t SerializeInt(IMkvWriter* writer, int64_t value, int32_t size);
23
24 // Returns the size in bytes of the element.
25 int32_t GetUIntSize(uint64_t value);
26 int32_t GetIntSize(int64_t value);
27 int32_t GetCodedUIntSize(uint64_t value);
28 uint64_t EbmlMasterElementSize(uint64_t type, uint64_t value);
29 uint64_t EbmlElementSize(uint64_t type, int64_t value);
30 uint64_t EbmlElementSize(uint64_t type, uint64_t value);
31 uint64_t EbmlElementSize(uint64_t type, float value);
32 uint64_t EbmlElementSize(uint64_t type, const char* value);
33 uint64_t EbmlElementSize(uint64_t type, const uint8_t* value, uint64_t size);
34 uint64_t EbmlDateElementSize(uint64_t type);
35
36 // Returns the size in bytes of the element assuming that the element was
37 // written using |fixed_size| bytes. If |fixed_size| is set to zero, then it
38 // computes the necessary number of bytes based on |value|.
39 uint64_t EbmlElementSize(uint64_t type, uint64_t value, uint64_t fixed_size);
40
41 // Creates an EBML coded number from |value| and writes it out. The size of
42 // the coded number is determined by the value of |value|. |value| must not
43 // be in a coded form. Returns 0 on success.
44 int32_t WriteUInt(IMkvWriter* writer, uint64_t value);
45
46 // Creates an EBML coded number from |value| and writes it out. The size of
47 // the coded number is determined by the value of |size|. |value| must not
48 // be in a coded form. Returns 0 on success.
49 int32_t WriteUIntSize(IMkvWriter* writer, uint64_t value, int32_t size);
50
51 // Output an Mkv master element. Returns true if the element was written.
52 bool WriteEbmlMasterElement(IMkvWriter* writer, uint64_t value, uint64_t size);
53
54 // Outputs an Mkv ID, calls |IMkvWriter::ElementStartNotify|, and passes the
55 // ID to |SerializeInt|. Returns 0 on success.
56 int32_t WriteID(IMkvWriter* writer, uint64_t type);
57
58 // Output an Mkv non-master element. Returns true if the element was written.
59 bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, uint64_t value);
60 bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, int64_t value);
61 bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, float value);
62 bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, const char* value);
63 bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, const uint8_t* value,
64                       uint64_t size);
65 bool WriteEbmlDateElement(IMkvWriter* writer, uint64_t type, int64_t value);
66
67 // Output an Mkv non-master element using fixed size. The element will be
68 // written out using exactly |fixed_size| bytes. If |fixed_size| is set to zero
69 // then it computes the necessary number of bytes based on |value|. Returns true
70 // if the element was written.
71 bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, uint64_t value,
72                       uint64_t fixed_size);
73
74 // Output a Mkv Frame. It decides the correct element to write (Block vs
75 // SimpleBlock) based on the parameters of the Frame.
76 uint64_t WriteFrame(IMkvWriter* writer, const Frame* const frame,
77                     Cluster* cluster);
78
79 // Output a void element. |size| must be the entire size in bytes that will be
80 // void. The function will calculate the size of the void header and subtract
81 // it from |size|.
82 uint64_t WriteVoidElement(IMkvWriter* writer, uint64_t size);
83
84 // Returns the version number of the muxer in |major|, |minor|, |build|,
85 // and |revision|.
86 void GetVersion(int32_t* major, int32_t* minor, int32_t* build,
87                 int32_t* revision);
88
89 // Returns a random number to be used for UID, using |seed| to seed
90 // the random-number generator (see POSIX rand_r() for semantics).
91 uint64_t MakeUID(unsigned int* seed);
92
93 }  // namespace mkvmuxer
94
95 #endif  // MKVMUXER_MKVMUXERUTIL_H_