hdr_metadata.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef API_VIDEO_HDR_METADATA_H_
  11. #define API_VIDEO_HDR_METADATA_H_
  12. namespace webrtc {
  13. // SMPTE ST 2086 mastering metadata,
  14. // see https://ieeexplore.ieee.org/document/8353899.
  15. struct HdrMasteringMetadata {
  16. struct Chromaticity {
  17. Chromaticity();
  18. bool operator==(const Chromaticity& rhs) const {
  19. return x == rhs.x && y == rhs.y;
  20. }
  21. bool Validate() const {
  22. return x >= 0.0 && x <= 1.0 && y >= 0.0 && y <= 1.0;
  23. }
  24. // xy chromaticity coordinates must be calculated as specified in ISO
  25. // 11664-3:2012 Section 7, and must be specified with four decimal places.
  26. // The x coordinate should be in the range [0.0001, 0.7400] and the y
  27. // coordinate should be in the range [0.0001, 0.8400]. Valid range [0.0000,
  28. // 1.0000].
  29. float x = 0.0f;
  30. float y = 0.0f;
  31. };
  32. HdrMasteringMetadata();
  33. bool operator==(const HdrMasteringMetadata& rhs) const {
  34. return ((primary_r == rhs.primary_r) && (primary_g == rhs.primary_g) &&
  35. (primary_b == rhs.primary_b) && (white_point == rhs.white_point) &&
  36. (luminance_max == rhs.luminance_max) &&
  37. (luminance_min == rhs.luminance_min));
  38. }
  39. bool Validate() const {
  40. return luminance_max >= 0.0 && luminance_max <= 20000.0 &&
  41. luminance_min >= 0.0 && luminance_min <= 5.0 &&
  42. primary_r.Validate() && primary_g.Validate() &&
  43. primary_b.Validate() && white_point.Validate();
  44. }
  45. // The nominal primaries of the mastering display.
  46. Chromaticity primary_r;
  47. Chromaticity primary_g;
  48. Chromaticity primary_b;
  49. // The nominal chromaticity of the white point of the mastering display.
  50. Chromaticity white_point;
  51. // The nominal maximum display luminance of the mastering display. Specified
  52. // in the unit candela/m2. The value should be in the range [5, 10000] with
  53. // zero decimal places. Valid range [0, 20000].
  54. float luminance_max = 0.0f;
  55. // The nominal minimum display luminance of the mastering display. Specified
  56. // in the unit candela/m2. The value should be in the range [0.0001, 5.0000]
  57. // with four decimal places. Valid range [0.0000, 5.0000].
  58. float luminance_min = 0.0f;
  59. };
  60. // High dynamic range (HDR) metadata common for HDR10 and WebM/VP9-based HDR
  61. // formats. This struct replicates the HDRMetadata struct defined in
  62. // https://cs.chromium.org/chromium/src/media/base/hdr_metadata.h
  63. struct HdrMetadata {
  64. HdrMetadata();
  65. bool operator==(const HdrMetadata& rhs) const {
  66. return (
  67. (max_content_light_level == rhs.max_content_light_level) &&
  68. (max_frame_average_light_level == rhs.max_frame_average_light_level) &&
  69. (mastering_metadata == rhs.mastering_metadata));
  70. }
  71. bool Validate() const {
  72. return max_content_light_level >= 0 && max_content_light_level <= 20000 &&
  73. max_frame_average_light_level >= 0 &&
  74. max_frame_average_light_level <= 20000 &&
  75. mastering_metadata.Validate();
  76. }
  77. HdrMasteringMetadata mastering_metadata;
  78. // Max content light level (CLL), i.e. maximum brightness level present in the
  79. // stream, in nits. 1 nit = 1 candela/m2. Valid range [0, 20000].
  80. int max_content_light_level = 0;
  81. // Max frame-average light level (FALL), i.e. maximum average brightness of
  82. // the brightest frame in the stream, in nits. Valid range [0, 20000].
  83. int max_frame_average_light_level = 0;
  84. };
  85. } // namespace webrtc
  86. #endif // API_VIDEO_HDR_METADATA_H_