mkvmuxerutil.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #include "mkvmuxertypes.h"
  11. #include "stdint.h"
  12. namespace mkvmuxer {
  13. class Cluster;
  14. class Frame;
  15. class IMkvWriter;
  16. // TODO(tomfinegan): mkvmuxer:: integer types continue to be used here because
  17. // changing them causes pain for downstream projects. It would be nice if a
  18. // solution that allows removal of the mkvmuxer:: integer types while avoiding
  19. // pain for downstream users of libwebm. Considering that mkvmuxerutil.{cc,h}
  20. // are really, for the great majority of cases, EBML size calculation and writer
  21. // functions, perhaps a more EBML focused utility would be the way to go as a
  22. // first step.
  23. const uint64 kEbmlUnknownValue = 0x01FFFFFFFFFFFFFFULL;
  24. const int64 kMaxBlockTimecode = 0x07FFFLL;
  25. // Writes out |value| in Big Endian order. Returns 0 on success.
  26. int32 SerializeInt(IMkvWriter* writer, int64 value, int32 size);
  27. // Returns the size in bytes of the element.
  28. int32 GetUIntSize(uint64 value);
  29. int32 GetIntSize(int64 value);
  30. int32 GetCodedUIntSize(uint64 value);
  31. uint64 EbmlMasterElementSize(uint64 type, uint64 value);
  32. uint64 EbmlElementSize(uint64 type, int64 value);
  33. uint64 EbmlElementSize(uint64 type, uint64 value);
  34. uint64 EbmlElementSize(uint64 type, float value);
  35. uint64 EbmlElementSize(uint64 type, const char* value);
  36. uint64 EbmlElementSize(uint64 type, const uint8* value, uint64 size);
  37. uint64 EbmlDateElementSize(uint64 type);
  38. // Returns the size in bytes of the element assuming that the element was
  39. // written using |fixed_size| bytes. If |fixed_size| is set to zero, then it
  40. // computes the necessary number of bytes based on |value|.
  41. uint64 EbmlElementSize(uint64 type, uint64 value, uint64 fixed_size);
  42. // Creates an EBML coded number from |value| and writes it out. The size of
  43. // the coded number is determined by the value of |value|. |value| must not
  44. // be in a coded form. Returns 0 on success.
  45. int32 WriteUInt(IMkvWriter* writer, uint64 value);
  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 WriteUIntSize(IMkvWriter* writer, uint64 value, int32 size);
  50. // Output an Mkv master element. Returns true if the element was written.
  51. bool WriteEbmlMasterElement(IMkvWriter* writer, uint64 value, uint64 size);
  52. // Outputs an Mkv ID, calls |IMkvWriter::ElementStartNotify|, and passes the
  53. // ID to |SerializeInt|. Returns 0 on success.
  54. int32 WriteID(IMkvWriter* writer, uint64 type);
  55. // Output an Mkv non-master element. Returns true if the element was written.
  56. bool WriteEbmlElement(IMkvWriter* writer, uint64 type, uint64 value);
  57. bool WriteEbmlElement(IMkvWriter* writer, uint64 type, int64 value);
  58. bool WriteEbmlElement(IMkvWriter* writer, uint64 type, float value);
  59. bool WriteEbmlElement(IMkvWriter* writer, uint64 type, const char* value);
  60. bool WriteEbmlElement(IMkvWriter* writer, uint64 type, const uint8* value,
  61. uint64 size);
  62. bool WriteEbmlDateElement(IMkvWriter* writer, uint64 type, int64 value);
  63. // Output an Mkv non-master element using fixed size. The element will be
  64. // written out using exactly |fixed_size| bytes. If |fixed_size| is set to zero
  65. // then it computes the necessary number of bytes based on |value|. Returns true
  66. // if the element was written.
  67. bool WriteEbmlElement(IMkvWriter* writer, uint64 type, uint64 value,
  68. uint64 fixed_size);
  69. // Output a Mkv Frame. It decides the correct element to write (Block vs
  70. // SimpleBlock) based on the parameters of the Frame.
  71. uint64 WriteFrame(IMkvWriter* writer, const Frame* const frame,
  72. Cluster* cluster);
  73. // Output a void element. |size| must be the entire size in bytes that will be
  74. // void. The function will calculate the size of the void header and subtract
  75. // it from |size|.
  76. uint64 WriteVoidElement(IMkvWriter* writer, uint64 size);
  77. // Returns the version number of the muxer in |major|, |minor|, |build|,
  78. // and |revision|.
  79. void GetVersion(int32* major, int32* minor, int32* build, int32* revision);
  80. // Returns a random number to be used for UID, using |seed| to seed
  81. // the random-number generator (see POSIX rand_r() for semantics).
  82. uint64 MakeUID(unsigned int* seed);
  83. // Colour field validation helpers. All return true when |value| is valid.
  84. bool IsMatrixCoefficientsValueValid(uint64_t value);
  85. bool IsChromaSitingHorzValueValid(uint64_t value);
  86. bool IsChromaSitingVertValueValid(uint64_t value);
  87. bool IsColourRangeValueValid(uint64_t value);
  88. bool IsTransferCharacteristicsValueValid(uint64_t value);
  89. bool IsPrimariesValueValid(uint64_t value);
  90. } // namespace mkvmuxer
  91. #endif // MKVMUXER_MKVMUXERUTIL_H_