mkvmuxerutil.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. // Writes out |f| in Big Endian order. Returns 0 on success.
  28. int32 SerializeFloat(IMkvWriter* writer, float f);
  29. // Returns the size in bytes of the element.
  30. int32 GetUIntSize(uint64 value);
  31. int32 GetIntSize(int64 value);
  32. int32 GetCodedUIntSize(uint64 value);
  33. uint64 EbmlMasterElementSize(uint64 type, uint64 value);
  34. uint64 EbmlElementSize(uint64 type, int64 value);
  35. uint64 EbmlElementSize(uint64 type, uint64 value);
  36. uint64 EbmlElementSize(uint64 type, float value);
  37. uint64 EbmlElementSize(uint64 type, const char* value);
  38. uint64 EbmlElementSize(uint64 type, const uint8* value, uint64 size);
  39. uint64 EbmlDateElementSize(uint64 type);
  40. // Returns the size in bytes of the element assuming that the element was
  41. // written using |fixed_size| bytes. If |fixed_size| is set to zero, then it
  42. // computes the necessary number of bytes based on |value|.
  43. uint64 EbmlElementSize(uint64 type, uint64 value, uint64 fixed_size);
  44. // Creates an EBML coded number from |value| and writes it out. The size of
  45. // the coded number is determined by the value of |value|. |value| must not
  46. // be in a coded form. Returns 0 on success.
  47. int32 WriteUInt(IMkvWriter* writer, uint64 value);
  48. // Creates an EBML coded number from |value| and writes it out. The size of
  49. // the coded number is determined by the value of |size|. |value| must not
  50. // be in a coded form. Returns 0 on success.
  51. int32 WriteUIntSize(IMkvWriter* writer, uint64 value, int32 size);
  52. // Output an Mkv master element. Returns true if the element was written.
  53. bool WriteEbmlMasterElement(IMkvWriter* writer, uint64 value, uint64 size);
  54. // Outputs an Mkv ID, calls |IMkvWriter::ElementStartNotify|, and passes the
  55. // ID to |SerializeInt|. Returns 0 on success.
  56. int32 WriteID(IMkvWriter* writer, uint64 type);
  57. // Output an Mkv non-master element. Returns true if the element was written.
  58. bool WriteEbmlElement(IMkvWriter* writer, uint64 type, uint64 value);
  59. bool WriteEbmlElement(IMkvWriter* writer, uint64 type, int64 value);
  60. bool WriteEbmlElement(IMkvWriter* writer, uint64 type, float value);
  61. bool WriteEbmlElement(IMkvWriter* writer, uint64 type, const char* value);
  62. bool WriteEbmlElement(IMkvWriter* writer, uint64 type, const uint8* value,
  63. uint64 size);
  64. bool WriteEbmlDateElement(IMkvWriter* writer, uint64 type, int64 value);
  65. // Output an Mkv non-master element using fixed size. The element will be
  66. // written out using exactly |fixed_size| bytes. If |fixed_size| is set to zero
  67. // then it computes the necessary number of bytes based on |value|. Returns true
  68. // if the element was written.
  69. bool WriteEbmlElement(IMkvWriter* writer, uint64 type, uint64 value,
  70. uint64 fixed_size);
  71. // Output a Mkv Frame. It decides the correct element to write (Block vs
  72. // SimpleBlock) based on the parameters of the Frame.
  73. uint64 WriteFrame(IMkvWriter* writer, const Frame* const frame,
  74. Cluster* cluster);
  75. // Output a void element. |size| must be the entire size in bytes that will be
  76. // void. The function will calculate the size of the void header and subtract
  77. // it from |size|.
  78. uint64 WriteVoidElement(IMkvWriter* writer, uint64 size);
  79. // Returns the version number of the muxer in |major|, |minor|, |build|,
  80. // and |revision|.
  81. void GetVersion(int32* major, int32* minor, int32* build, int32* revision);
  82. // Returns a random number to be used for UID, using |seed| to seed
  83. // the random-number generator (see POSIX rand_r() for semantics).
  84. uint64 MakeUID(unsigned int* seed);
  85. // Colour field validation helpers. All return true when |value| is valid.
  86. bool IsMatrixCoefficientsValueValid(uint64_t value);
  87. bool IsChromaSitingHorzValueValid(uint64_t value);
  88. bool IsChromaSitingVertValueValid(uint64_t value);
  89. bool IsColourRangeValueValid(uint64_t value);
  90. bool IsTransferCharacteristicsValueValid(uint64_t value);
  91. bool IsPrimariesValueValid(uint64_t value);
  92. } // namespace mkvmuxer
  93. #endif // MKVMUXER_MKVMUXERUTIL_H_