Add HdrMetadata to VideoFrame

Bug: webrtc:8651
Change-Id: I28aacbc63e346328633fb862662343f47e966bf1
Reviewed-on: https://webrtc-review.googlesource.com/c/108320
Commit-Queue: Johannes Kron <kron@webrtc.org>
Reviewed-by: Emircan Uysaler <emircan@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25513}
diff --git a/api/video/hdr_metadata.cc b/api/video/hdr_metadata.cc
index 25cd752..bfe54ce 100644
--- a/api/video/hdr_metadata.cc
+++ b/api/video/hdr_metadata.cc
@@ -15,12 +15,21 @@
 HdrMasteringMetadata::Chromaticity::Chromaticity() = default;
 HdrMasteringMetadata::Chromaticity::Chromaticity(const Chromaticity& rhs) =
     default;
+HdrMasteringMetadata::Chromaticity::Chromaticity(Chromaticity&& rhs) = default;
+HdrMasteringMetadata::Chromaticity& HdrMasteringMetadata::Chromaticity::
+operator=(const Chromaticity& rhs) = default;
 
 HdrMasteringMetadata::HdrMasteringMetadata() = default;
 HdrMasteringMetadata::HdrMasteringMetadata(const HdrMasteringMetadata& rhs) =
     default;
+HdrMasteringMetadata::HdrMasteringMetadata(HdrMasteringMetadata&& rhs) =
+    default;
+HdrMasteringMetadata& HdrMasteringMetadata::operator=(
+    const HdrMasteringMetadata& rhs) = default;
 
 HdrMetadata::HdrMetadata() = default;
 HdrMetadata::HdrMetadata(const HdrMetadata& rhs) = default;
+HdrMetadata::HdrMetadata(HdrMetadata&& rhs) = default;
+HdrMetadata& HdrMetadata::operator=(const HdrMetadata& rhs) = default;
 
 }  // namespace webrtc
diff --git a/api/video/hdr_metadata.h b/api/video/hdr_metadata.h
index 8a2e6e8..be0c173 100644
--- a/api/video/hdr_metadata.h
+++ b/api/video/hdr_metadata.h
@@ -31,6 +31,8 @@
 
     Chromaticity();
     Chromaticity(const Chromaticity& rhs);
+    Chromaticity(Chromaticity&& rhs);
+    Chromaticity& operator=(const Chromaticity& rhs);
   };
 
   // The nominal primaries of the mastering display.
@@ -53,6 +55,8 @@
 
   HdrMasteringMetadata();
   HdrMasteringMetadata(const HdrMasteringMetadata& rhs);
+  HdrMasteringMetadata(HdrMasteringMetadata&& rhs);
+  HdrMasteringMetadata& operator=(const HdrMasteringMetadata& rhs);
 
   bool operator==(const HdrMasteringMetadata& rhs) const {
     return ((primary_r == rhs.primary_r) && (primary_g == rhs.primary_g) &&
@@ -76,6 +80,8 @@
 
   HdrMetadata();
   HdrMetadata(const HdrMetadata& rhs);
+  HdrMetadata(HdrMetadata&& rhs);
+  HdrMetadata& operator=(const HdrMetadata& rhs);
 
   bool operator==(const HdrMetadata& rhs) const {
     return (
diff --git a/api/video/video_frame.cc b/api/video/video_frame.cc
index 5521ad8..12da43f 100644
--- a/api/video/video_frame.cc
+++ b/api/video/video_frame.cc
@@ -21,7 +21,7 @@
 
 VideoFrame VideoFrame::Builder::build() {
   return VideoFrame(video_frame_buffer_, timestamp_us_, timestamp_rtp_,
-                    ntp_time_ms_, rotation_, color_space_);
+                    ntp_time_ms_, rotation_, color_space_, hdr_metadata_);
 }
 
 VideoFrame::Builder& VideoFrame::Builder::set_video_frame_buffer(
@@ -64,6 +64,12 @@
   return *this;
 }
 
+VideoFrame::Builder& VideoFrame::Builder::set_hdr_metadata(
+    const HdrMetadata& hdr_metadata) {
+  hdr_metadata_ = hdr_metadata;
+  return *this;
+}
+
 VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
                        webrtc::VideoRotation rotation,
                        int64_t timestamp_us)
@@ -90,13 +96,15 @@
                        uint32_t timestamp_rtp,
                        int64_t ntp_time_ms,
                        VideoRotation rotation,
-                       const absl::optional<ColorSpace>& color_space)
+                       const absl::optional<ColorSpace>& color_space,
+                       const absl::optional<HdrMetadata>& hdr_metadata)
     : video_frame_buffer_(buffer),
       timestamp_rtp_(timestamp_rtp),
       ntp_time_ms_(ntp_time_ms),
       timestamp_us_(timestamp_us),
       rotation_(rotation),
-      color_space_(color_space) {}
+      color_space_(color_space),
+      hdr_metadata_(hdr_metadata) {}
 
 VideoFrame::~VideoFrame() = default;
 
diff --git a/api/video/video_frame.h b/api/video/video_frame.h
index 83b45b2..58362b0 100644
--- a/api/video/video_frame.h
+++ b/api/video/video_frame.h
@@ -15,6 +15,7 @@
 
 #include "absl/types/optional.h"
 #include "api/video/color_space.h"
+#include "api/video/hdr_metadata.h"
 #include "api/video/video_frame_buffer.h"
 #include "api/video/video_rotation.h"
 #include "rtc_base/scoped_ref_ptr.h"
@@ -39,6 +40,7 @@
     Builder& set_ntp_time_ms(int64_t ntp_time_ms);
     Builder& set_rotation(VideoRotation rotation);
     Builder& set_color_space(const ColorSpace& color_space);
+    Builder& set_hdr_metadata(const HdrMetadata& hdr_metadata);
 
    private:
     rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_;
@@ -47,6 +49,7 @@
     int64_t ntp_time_ms_ = 0;
     VideoRotation rotation_ = kVideoRotation_0;
     absl::optional<ColorSpace> color_space_;
+    absl::optional<HdrMetadata> hdr_metadata_;
   };
 
   // To be deprecated. Migrate all use to Builder.
@@ -112,9 +115,12 @@
   VideoRotation rotation() const { return rotation_; }
   void set_rotation(VideoRotation rotation) { rotation_ = rotation; }
 
-  // Set Color space when available.
+  // Get color space when available.
   absl::optional<ColorSpace> color_space() const { return color_space_; }
 
+  // Get HDR metadata when available.
+  absl::optional<HdrMetadata> hdr_metadata() const { return hdr_metadata_; }
+
   // Get render time in milliseconds.
   // TODO(nisse): Deprecated. Migrate all users to timestamp_us().
   int64_t render_time_ms() const;
@@ -135,7 +141,8 @@
              uint32_t timestamp_rtp,
              int64_t ntp_time_ms,
              VideoRotation rotation,
-             const absl::optional<ColorSpace>& color_space);
+             const absl::optional<ColorSpace>& color_space,
+             const absl::optional<HdrMetadata>& hdr_metadata);
 
   // An opaque reference counted handle that stores the pixel data.
   rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_;
@@ -144,6 +151,7 @@
   int64_t timestamp_us_;
   VideoRotation rotation_;
   absl::optional<ColorSpace> color_space_;
+  absl::optional<HdrMetadata> hdr_metadata_;
 };
 
 }  // namespace webrtc