Reland "Remove RTPVideoHeader::h264() accessors."

Downstream projects have been updated, so this can now be relanded.
This is a revert (and rebase) of: https://webrtc-review.googlesource.com/c/src/+/88820

Bug: none
Change-Id: I424664ddef7aeebd3c6c94ae67c7f70a342dc9a4
Reviewed-on: https://webrtc-review.googlesource.com/92082
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Commit-Queue: Philip Eliasson <philipel@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24181}
diff --git a/modules/video_coding/h264_sps_pps_tracker.cc b/modules/video_coding/h264_sps_pps_tracker.cc
index 51931f8..d67d827 100644
--- a/modules/video_coding/h264_sps_pps_tracker.cc
+++ b/modules/video_coding/h264_sps_pps_tracker.cc
@@ -36,14 +36,15 @@
   const uint8_t* data = packet->dataPtr;
   const size_t data_size = packet->sizeBytes;
   const RTPVideoHeader& video_header = packet->video_header;
-  RTPVideoHeaderH264* codec_header = &packet->video_header.h264();
+  auto& h264_header =
+      absl::get<RTPVideoHeaderH264>(packet->video_header.video_type_header);
 
   bool append_sps_pps = false;
   auto sps = sps_data_.end();
   auto pps = pps_data_.end();
 
-  for (size_t i = 0; i < codec_header->nalus_length; ++i) {
-    const NaluInfo& nalu = codec_header->nalus[i];
+  for (size_t i = 0; i < h264_header.nalus_length; ++i) {
+    const NaluInfo& nalu = h264_header.nalus[i];
     switch (nalu.type) {
       case H264::NaluType::kSps: {
         sps_data_[nalu.sps_id].width = packet->width;
@@ -110,7 +111,7 @@
     required_size += pps->second.size + sizeof(start_code_h264);
   }
 
-  if (codec_header->packetization_type == kH264StapA) {
+  if (h264_header.packetization_type == kH264StapA) {
     const uint8_t* nalu_ptr = data + 1;
     while (nalu_ptr < data + data_size) {
       RTC_DCHECK(video_header.is_first_packet_in_frame);
@@ -155,9 +156,9 @@
     pps_info.type = H264::NaluType::kPps;
     pps_info.sps_id = sps->first;
     pps_info.pps_id = pps->first;
-    if (codec_header->nalus_length + 2 <= kMaxNalusPerPacket) {
-      codec_header->nalus[codec_header->nalus_length++] = sps_info;
-      codec_header->nalus[codec_header->nalus_length++] = pps_info;
+    if (h264_header.nalus_length + 2 <= kMaxNalusPerPacket) {
+      h264_header.nalus[h264_header.nalus_length++] = sps_info;
+      h264_header.nalus[h264_header.nalus_length++] = pps_info;
     } else {
       RTC_LOG(LS_WARNING) << "Not enough space in H.264 codec header to insert "
                              "SPS/PPS provided out-of-band.";
@@ -165,7 +166,7 @@
   }
 
   // Copy the rest of the bitstream and insert start codes.
-  if (codec_header->packetization_type == kH264StapA) {
+  if (h264_header.packetization_type == kH264StapA) {
     const uint8_t* nalu_ptr = data + 1;
     while (nalu_ptr < data + data_size) {
       memcpy(insert_at, start_code_h264, sizeof(start_code_h264));
diff --git a/modules/video_coding/h264_sps_pps_tracker_unittest.cc b/modules/video_coding/h264_sps_pps_tracker_unittest.cc
index 4b43955..dad8294 100644
--- a/modules/video_coding/h264_sps_pps_tracker_unittest.cc
+++ b/modules/video_coding/h264_sps_pps_tracker_unittest.cc
@@ -46,21 +46,29 @@
   EXPECT_TRUE(contains_idr);
 }
 
+class H264VcmPacket : public VCMPacket {
+ public:
+  H264VcmPacket() {
+    codec = kVideoCodecH264;
+    video_header.is_first_packet_in_frame = false;
+    auto& type_header =
+        video_header.video_type_header.emplace<RTPVideoHeaderH264>();
+    type_header.nalus_length = 0;
+    type_header.packetization_type = kH264SingleNalu;
+  }
+
+  RTPVideoHeaderH264& h264() {
+    return absl::get<RTPVideoHeaderH264>(video_header.video_type_header);
+  }
+};
+
 }  // namespace
 
 class TestH264SpsPpsTracker : public ::testing::Test {
  public:
-  VCMPacket GetDefaultPacket() {
-    VCMPacket packet;
-    packet.codec = kVideoCodecH264;
-    packet.video_header.h264().nalus_length = 0;
-    packet.video_header.is_first_packet_in_frame = false;
-    packet.video_header.h264().packetization_type = kH264SingleNalu;
-
-    return packet;
-  }
-
-  void AddSps(VCMPacket* packet, uint8_t sps_id, std::vector<uint8_t>* data) {
+  void AddSps(H264VcmPacket* packet,
+              uint8_t sps_id,
+              std::vector<uint8_t>* data) {
     NaluInfo info;
     info.type = H264::NaluType::kSps;
     info.sps_id = sps_id;
@@ -68,11 +76,10 @@
     data->push_back(H264::NaluType::kSps);
     data->push_back(sps_id);  // The sps data, just a single byte.
 
-    packet->video_header.h264()
-        .nalus[packet->video_header.h264().nalus_length++] = info;
+    packet->h264().nalus[packet->h264().nalus_length++] = info;
   }
 
-  void AddPps(VCMPacket* packet,
+  void AddPps(H264VcmPacket* packet,
               uint8_t sps_id,
               uint8_t pps_id,
               std::vector<uint8_t>* data) {
@@ -83,18 +90,16 @@
     data->push_back(H264::NaluType::kPps);
     data->push_back(pps_id);  // The pps data, just a single byte.
 
-    packet->video_header.h264()
-        .nalus[packet->video_header.h264().nalus_length++] = info;
+    packet->h264().nalus[packet->h264().nalus_length++] = info;
   }
 
-  void AddIdr(VCMPacket* packet, int pps_id) {
+  void AddIdr(H264VcmPacket* packet, int pps_id) {
     NaluInfo info;
     info.type = H264::NaluType::kIdr;
     info.sps_id = -1;
     info.pps_id = pps_id;
 
-    packet->video_header.h264()
-        .nalus[packet->video_header.h264().nalus_length++] = info;
+    packet->h264().nalus[packet->h264().nalus_length++] = info;
   }
 
  protected:
@@ -103,8 +108,8 @@
 
 TEST_F(TestH264SpsPpsTracker, NoNalus) {
   uint8_t data[] = {1, 2, 3};
-  VCMPacket packet = GetDefaultPacket();
-  packet.video_header.h264().packetization_type = kH264FuA;
+  H264VcmPacket packet;
+  packet.h264().packetization_type = kH264FuA;
   packet.dataPtr = data;
   packet.sizeBytes = sizeof(data);
 
@@ -115,8 +120,8 @@
 
 TEST_F(TestH264SpsPpsTracker, FuAFirstPacket) {
   uint8_t data[] = {1, 2, 3};
-  VCMPacket packet = GetDefaultPacket();
-  packet.video_header.h264().packetization_type = kH264FuA;
+  H264VcmPacket packet;
+  packet.h264().packetization_type = kH264FuA;
   packet.video_header.is_first_packet_in_frame = true;
   packet.dataPtr = data;
   packet.sizeBytes = sizeof(data);
@@ -131,8 +136,8 @@
 
 TEST_F(TestH264SpsPpsTracker, StapAIncorrectSegmentLength) {
   uint8_t data[] = {0, 0, 2, 0};
-  VCMPacket packet = GetDefaultPacket();
-  packet.video_header.h264().packetization_type = kH264StapA;
+  H264VcmPacket packet;
+  packet.h264().packetization_type = kH264StapA;
   packet.video_header.is_first_packet_in_frame = true;
   packet.dataPtr = data;
   packet.sizeBytes = sizeof(data);
@@ -142,7 +147,7 @@
 
 TEST_F(TestH264SpsPpsTracker, NoNalusFirstPacket) {
   uint8_t data[] = {1, 2, 3};
-  VCMPacket packet = GetDefaultPacket();
+  H264VcmPacket packet;
   packet.video_header.is_first_packet_in_frame = true;
   packet.dataPtr = data;
   packet.sizeBytes = sizeof(data);
@@ -157,8 +162,8 @@
 
 TEST_F(TestH264SpsPpsTracker, IdrNoSpsPpsInserted) {
   std::vector<uint8_t> data = {1, 2, 3};
-  VCMPacket packet = GetDefaultPacket();
-  packet.video_header.h264().packetization_type = kH264FuA;
+  H264VcmPacket packet;
+  packet.h264().packetization_type = kH264FuA;
 
   AddIdr(&packet, 0);
   packet.dataPtr = data.data();
@@ -171,7 +176,7 @@
 
 TEST_F(TestH264SpsPpsTracker, IdrFirstPacketNoSpsPpsInserted) {
   std::vector<uint8_t> data = {1, 2, 3};
-  VCMPacket packet = GetDefaultPacket();
+  H264VcmPacket packet;
   packet.video_header.is_first_packet_in_frame = true;
 
   AddIdr(&packet, 0);
@@ -184,7 +189,7 @@
 
 TEST_F(TestH264SpsPpsTracker, IdrFirstPacketNoPpsInserted) {
   std::vector<uint8_t> data = {1, 2, 3};
-  VCMPacket packet = GetDefaultPacket();
+  H264VcmPacket packet;
   packet.video_header.is_first_packet_in_frame = true;
 
   AddSps(&packet, 0, &data);
@@ -198,7 +203,7 @@
 
 TEST_F(TestH264SpsPpsTracker, IdrFirstPacketNoSpsInserted) {
   std::vector<uint8_t> data = {1, 2, 3};
-  VCMPacket packet = GetDefaultPacket();
+  H264VcmPacket packet;
   packet.video_header.is_first_packet_in_frame = true;
 
   AddPps(&packet, 0, 0, &data);
@@ -212,7 +217,7 @@
 
 TEST_F(TestH264SpsPpsTracker, SpsPpsPacketThenIdrFirstPacket) {
   std::vector<uint8_t> data;
-  VCMPacket sps_pps_packet = GetDefaultPacket();
+  H264VcmPacket sps_pps_packet;
 
   // Insert SPS/PPS
   AddSps(&sps_pps_packet, 0, &data);
@@ -225,7 +230,7 @@
   data.clear();
 
   // Insert first packet of the IDR
-  VCMPacket idr_packet = GetDefaultPacket();
+  H264VcmPacket idr_packet;
   idr_packet.video_header.is_first_packet_in_frame = true;
   AddIdr(&idr_packet, 1);
   data.insert(data.end(), {1, 2, 3});
@@ -243,8 +248,8 @@
 
 TEST_F(TestH264SpsPpsTracker, SpsPpsIdrInStapA) {
   std::vector<uint8_t> data;
-  VCMPacket packet = GetDefaultPacket();
-  packet.video_header.h264().packetization_type = kH264StapA;
+  H264VcmPacket packet;
+  packet.h264().packetization_type = kH264StapA;
   packet.video_header.is_first_packet_in_frame = true;  // Always true for StapA
 
   data.insert(data.end(), {0});     // First byte is ignored
@@ -284,18 +289,18 @@
   tracker_.InsertSpsPpsNalus(sps, pps);
 
   // Insert first packet of the IDR.
-  VCMPacket idr_packet = GetDefaultPacket();
+  H264VcmPacket idr_packet;
   idr_packet.video_header.is_first_packet_in_frame = true;
   AddIdr(&idr_packet, 0);
   idr_packet.dataPtr = kData;
   idr_packet.sizeBytes = sizeof(kData);
-  EXPECT_EQ(1u, idr_packet.video_header.h264().nalus_length);
+  EXPECT_EQ(1u, idr_packet.h264().nalus_length);
   EXPECT_EQ(H264SpsPpsTracker::kInsert,
             tracker_.CopyAndFixBitstream(&idr_packet));
-  EXPECT_EQ(3u, idr_packet.video_header.h264().nalus_length);
+  EXPECT_EQ(3u, idr_packet.h264().nalus_length);
   EXPECT_EQ(320, idr_packet.width);
   EXPECT_EQ(240, idr_packet.height);
-  ExpectSpsPpsIdr(idr_packet.video_header.h264(), 0, 0);
+  ExpectSpsPpsIdr(idr_packet.h264(), 0, 0);
 
   if (idr_packet.dataPtr != kData) {
     // In case CopyAndFixBitStream() prepends SPS/PPS nalus to the packet, it
@@ -317,7 +322,7 @@
   tracker_.InsertSpsPpsNalus(sps, pps);
 
   // Insert first packet of the IDR.
-  VCMPacket idr_packet = GetDefaultPacket();
+  H264VcmPacket idr_packet;
   idr_packet.video_header.is_first_packet_in_frame = true;
   AddIdr(&idr_packet, 0);
   idr_packet.dataPtr = kData;
@@ -336,7 +341,7 @@
   tracker_.InsertSpsPpsNalus(sps, pps);
 
   // Insert first packet of the IDR.
-  VCMPacket idr_packet = GetDefaultPacket();
+  H264VcmPacket idr_packet;
   idr_packet.video_header.is_first_packet_in_frame = true;
   AddIdr(&idr_packet, 0);
   idr_packet.dataPtr = kData;
@@ -350,7 +355,7 @@
 
   // Insert an SPS/PPS packet with width/height and make sure
   // that information is set on the first IDR packet.
-  VCMPacket sps_pps_packet = GetDefaultPacket();
+  H264VcmPacket sps_pps_packet;
   AddSps(&sps_pps_packet, 0, &data);
   AddPps(&sps_pps_packet, 0, 1, &data);
   sps_pps_packet.dataPtr = data.data();
@@ -361,7 +366,7 @@
             tracker_.CopyAndFixBitstream(&sps_pps_packet));
   delete[] sps_pps_packet.dataPtr;
 
-  VCMPacket idr_packet = GetDefaultPacket();
+  H264VcmPacket idr_packet;
   idr_packet.video_header.is_first_packet_in_frame = true;
   AddIdr(&idr_packet, 1);
   data.insert(data.end(), {1, 2, 3});
diff --git a/modules/video_coding/jitter_buffer_unittest.cc b/modules/video_coding/jitter_buffer_unittest.cc
index adb495d..756dc52 100644
--- a/modules/video_coding/jitter_buffer_unittest.cc
+++ b/modules/video_coding/jitter_buffer_unittest.cc
@@ -1155,17 +1155,19 @@
 TEST_F(TestBasicJitterBuffer, SpsAndPpsHandling) {
   jitter_buffer_->SetDecodeErrorMode(kNoErrors);
 
+  auto& h264_header =
+      packet_->video_header.video_type_header.emplace<RTPVideoHeaderH264>();
   packet_->timestamp = timestamp_;
   packet_->frameType = kVideoFrameKey;
   packet_->is_first_packet_in_frame = true;
   packet_->markerBit = true;
   packet_->codec = kVideoCodecH264;
   packet_->video_header.codec = kVideoCodecH264;
-  packet_->video_header.h264().nalu_type = H264::NaluType::kIdr;
-  packet_->video_header.h264().nalus[0].type = H264::NaluType::kIdr;
-  packet_->video_header.h264().nalus[0].sps_id = -1;
-  packet_->video_header.h264().nalus[0].pps_id = 0;
-  packet_->video_header.h264().nalus_length = 1;
+  h264_header.nalu_type = H264::NaluType::kIdr;
+  h264_header.nalus[0].type = H264::NaluType::kIdr;
+  h264_header.nalus[0].sps_id = -1;
+  h264_header.nalus[0].pps_id = 0;
+  h264_header.nalus_length = 1;
   bool retransmitted = false;
   EXPECT_EQ(kCompleteSession,
             jitter_buffer_->InsertPacket(*packet_, &retransmitted));
@@ -1181,14 +1183,14 @@
   packet_->markerBit = false;
   packet_->codec = kVideoCodecH264;
   packet_->video_header.codec = kVideoCodecH264;
-  packet_->video_header.h264().nalu_type = H264::NaluType::kStapA;
-  packet_->video_header.h264().nalus[0].type = H264::NaluType::kSps;
-  packet_->video_header.h264().nalus[0].sps_id = 0;
-  packet_->video_header.h264().nalus[0].pps_id = -1;
-  packet_->video_header.h264().nalus[1].type = H264::NaluType::kPps;
-  packet_->video_header.h264().nalus[1].sps_id = 0;
-  packet_->video_header.h264().nalus[1].pps_id = 0;
-  packet_->video_header.h264().nalus_length = 2;
+  h264_header.nalu_type = H264::NaluType::kStapA;
+  h264_header.nalus[0].type = H264::NaluType::kSps;
+  h264_header.nalus[0].sps_id = 0;
+  h264_header.nalus[0].pps_id = -1;
+  h264_header.nalus[1].type = H264::NaluType::kPps;
+  h264_header.nalus[1].sps_id = 0;
+  h264_header.nalus[1].pps_id = 0;
+  h264_header.nalus_length = 2;
   // Not complete since the marker bit hasn't been received.
   EXPECT_EQ(kIncomplete,
             jitter_buffer_->InsertPacket(*packet_, &retransmitted));
@@ -1200,11 +1202,11 @@
   packet_->markerBit = true;
   packet_->codec = kVideoCodecH264;
   packet_->video_header.codec = kVideoCodecH264;
-  packet_->video_header.h264().nalu_type = H264::NaluType::kIdr;
-  packet_->video_header.h264().nalus[0].type = H264::NaluType::kIdr;
-  packet_->video_header.h264().nalus[0].sps_id = -1;
-  packet_->video_header.h264().nalus[0].pps_id = 0;
-  packet_->video_header.h264().nalus_length = 1;
+  h264_header.nalu_type = H264::NaluType::kIdr;
+  h264_header.nalus[0].type = H264::NaluType::kIdr;
+  h264_header.nalus[0].sps_id = -1;
+  h264_header.nalus[0].pps_id = 0;
+  h264_header.nalus_length = 1;
   // Complete and decodable since the pps and sps are received in the first
   // packet of this frame.
   EXPECT_EQ(kCompleteSession,
@@ -1222,11 +1224,11 @@
   packet_->markerBit = true;
   packet_->codec = kVideoCodecH264;
   packet_->video_header.codec = kVideoCodecH264;
-  packet_->video_header.h264().nalu_type = H264::NaluType::kSlice;
-  packet_->video_header.h264().nalus[0].type = H264::NaluType::kSlice;
-  packet_->video_header.h264().nalus[0].sps_id = -1;
-  packet_->video_header.h264().nalus[0].pps_id = 0;
-  packet_->video_header.h264().nalus_length = 1;
+  h264_header.nalu_type = H264::NaluType::kSlice;
+  h264_header.nalus[0].type = H264::NaluType::kSlice;
+  h264_header.nalus[0].sps_id = -1;
+  h264_header.nalus[0].pps_id = 0;
+  h264_header.nalus_length = 1;
   // Complete and decodable since sps, pps and key frame has been received.
   EXPECT_EQ(kCompleteSession,
             jitter_buffer_->InsertPacket(*packet_, &retransmitted));
diff --git a/modules/video_coding/packet_buffer.cc b/modules/video_coding/packet_buffer.cc
index 28ade46..e1172b3 100644
--- a/modules/video_coding/packet_buffer.cc
+++ b/modules/video_coding/packet_buffer.cc
@@ -303,18 +303,17 @@
           break;
 
         if (is_h264 && !is_h264_keyframe) {
-          const RTPVideoHeaderH264& header =
-              data_buffer_[start_index].video_header.h264();
-
-          if (header.nalus_length >= kMaxNalusPerPacket)
+          const auto* h264_header = absl::get_if<RTPVideoHeaderH264>(
+              &data_buffer_[start_index].video_header.video_type_header);
+          if (!h264_header || h264_header->nalus_length >= kMaxNalusPerPacket)
             return found_frames;
 
-          for (size_t j = 0; j < header.nalus_length; ++j) {
-            if (header.nalus[j].type == H264::NaluType::kSps) {
+          for (size_t j = 0; j < h264_header->nalus_length; ++j) {
+            if (h264_header->nalus[j].type == H264::NaluType::kSps) {
               has_h264_sps = true;
-            } else if (header.nalus[j].type == H264::NaluType::kPps) {
+            } else if (h264_header->nalus[j].type == H264::NaluType::kPps) {
               has_h264_pps = true;
-            } else if (header.nalus[j].type == H264::NaluType::kIdr) {
+            } else if (h264_header->nalus[j].type == H264::NaluType::kIdr) {
               has_h264_idr = true;
             }
           }
diff --git a/modules/video_coding/session_info.cc b/modules/video_coding/session_info.cc
index 834684e..b0066ab 100644
--- a/modules/video_coding/session_info.cc
+++ b/modules/video_coding/session_info.cc
@@ -112,8 +112,10 @@
     return std::vector<NaluInfo>();
   std::vector<NaluInfo> nalu_infos;
   for (const VCMPacket& packet : packets_) {
-    for (size_t i = 0; i < packet.video_header.h264().nalus_length; ++i) {
-      nalu_infos.push_back(packet.video_header.h264().nalus[i]);
+    const auto& h264 =
+        absl::get<RTPVideoHeaderH264>(packet.video_header.video_type_header);
+    for (size_t i = 0; i < h264.nalus_length; ++i) {
+      nalu_infos.push_back(h264.nalus[i]);
     }
   }
   return nalu_infos;
@@ -177,8 +179,9 @@
   // header supplied by the H264 depacketizer.
   const size_t kH264NALHeaderLengthInBytes = 1;
   const size_t kLengthFieldLength = 2;
-  if (packet.video_header.codec == kVideoCodecH264 &&
-      packet.video_header.h264().packetization_type == kH264StapA) {
+  const auto* h264 =
+      absl::get_if<RTPVideoHeaderH264>(&packet.video_header.video_type_header);
+  if (h264 && h264->packetization_type == kH264StapA) {
     size_t required_length = 0;
     const uint8_t* nalu_ptr = packet_buffer + kH264NALHeaderLengthInBytes;
     while (nalu_ptr < packet_buffer + packet.sizeBytes) {
diff --git a/modules/video_coding/video_packet_buffer_unittest.cc b/modules/video_coding/video_packet_buffer_unittest.cc
index 58611ff..f588026 100644
--- a/modules/video_coding/video_packet_buffer_unittest.cc
+++ b/modules/video_coding/video_packet_buffer_unittest.cc
@@ -508,17 +508,19 @@
                   uint8_t* data = nullptr) {  // data pointer
     VCMPacket packet;
     packet.codec = kVideoCodecH264;
+    auto& h264_header =
+        packet.video_header.video_type_header.emplace<RTPVideoHeaderH264>();
     packet.seqNum = seq_num;
     packet.timestamp = timestamp;
     if (keyframe == kKeyFrame) {
       if (sps_pps_idr_is_keyframe_) {
-        packet.video_header.h264().nalus[0].type = H264::NaluType::kSps;
-        packet.video_header.h264().nalus[1].type = H264::NaluType::kPps;
-        packet.video_header.h264().nalus[2].type = H264::NaluType::kIdr;
-        packet.video_header.h264().nalus_length = 3;
+        h264_header.nalus[0].type = H264::NaluType::kSps;
+        h264_header.nalus[1].type = H264::NaluType::kPps;
+        h264_header.nalus[2].type = H264::NaluType::kIdr;
+        h264_header.nalus_length = 3;
       } else {
-        packet.video_header.h264().nalus[0].type = H264::NaluType::kIdr;
-        packet.video_header.h264().nalus_length = 1;
+        h264_header.nalus[0].type = H264::NaluType::kIdr;
+        h264_header.nalus_length = 1;
       }
     }
     packet.is_first_packet_in_frame = first == kFirst;
@@ -592,12 +594,14 @@
       new uint8_t[sizeof(data_data) + EncodedImage::kBufferPaddingBytesH264]);
 
   VCMPacket packet;
-  packet.video_header.h264().nalus_length = 1;
-  packet.video_header.h264().nalus[0].type = H264::NaluType::kIdr;
+  auto& h264_header =
+      packet.video_header.video_type_header.emplace<RTPVideoHeaderH264>();
+  h264_header.nalus_length = 1;
+  h264_header.nalus[0].type = H264::NaluType::kIdr;
+  h264_header.packetization_type = kH264SingleNalu;
   packet.seqNum = seq_num;
   packet.codec = kVideoCodecH264;
   packet.insertStartCode = true;
-  packet.video_header.h264().packetization_type = kH264SingleNalu;
   packet.dataPtr = data;
   packet.sizeBytes = sizeof(data_data);
   packet.is_first_packet_in_frame = true;
@@ -755,7 +759,9 @@
   EXPECT_TRUE(packet_buffer_->InsertPacket(&packet));
 
   packet.codec = kVideoCodecH264;
-  packet.video_header.h264().nalus_length = 1;
+  auto& h264_header =
+      packet.video_header.video_type_header.emplace<RTPVideoHeaderH264>();
+  h264_header.nalus_length = 1;
   packet.timestamp = 3;
   packet.seqNum = 3;
   EXPECT_TRUE(packet_buffer_->InsertPacket(&packet));
@@ -778,7 +784,9 @@
   packet.frameType = kVideoFrameKey;
   packet.is_first_packet_in_frame = true;
   packet.markerBit = true;
-  packet.video_header.h264().nalus_length = kMaxNalusPerPacket;
+  auto& h264_header =
+      packet.video_header.video_type_header.emplace<RTPVideoHeaderH264>();
+  h264_header.nalus_length = kMaxNalusPerPacket;
   packet.sizeBytes = 0;
   packet.dataPtr = nullptr;
   EXPECT_TRUE(packet_buffer_->InsertPacket(&packet));
@@ -873,9 +881,10 @@
 };
 
 TEST_F(TestPacketBufferH264IdrIsKeyframe, IdrIsKeyframe) {
-  packet_.video_header.h264().nalus[0].type = H264::NaluType::kIdr;
-  packet_.video_header.h264().nalus_length = 1;
-
+  auto& h264_header =
+      packet_.video_header.video_type_header.emplace<RTPVideoHeaderH264>();
+  h264_header.nalus[0].type = H264::NaluType::kIdr;
+  h264_header.nalus_length = 1;
   packet_buffer_->InsertPacket(&packet_);
 
   ASSERT_EQ(1u, frames_from_callback_.size());
@@ -883,10 +892,12 @@
 }
 
 TEST_F(TestPacketBufferH264IdrIsKeyframe, SpsPpsIdrIsKeyframe) {
-  packet_.video_header.h264().nalus[0].type = H264::NaluType::kSps;
-  packet_.video_header.h264().nalus[1].type = H264::NaluType::kPps;
-  packet_.video_header.h264().nalus[2].type = H264::NaluType::kIdr;
-  packet_.video_header.h264().nalus_length = 3;
+  auto& h264_header =
+      packet_.video_header.video_type_header.emplace<RTPVideoHeaderH264>();
+  h264_header.nalus[0].type = H264::NaluType::kSps;
+  h264_header.nalus[1].type = H264::NaluType::kPps;
+  h264_header.nalus[2].type = H264::NaluType::kIdr;
+  h264_header.nalus_length = 3;
 
   packet_buffer_->InsertPacket(&packet_);
 
@@ -902,8 +913,10 @@
 };
 
 TEST_F(TestPacketBufferH264SpsPpsIdrIsKeyframe, IdrIsNotKeyframe) {
-  packet_.video_header.h264().nalus[0].type = H264::NaluType::kIdr;
-  packet_.video_header.h264().nalus_length = 1;
+  auto& h264_header =
+      packet_.video_header.video_type_header.emplace<RTPVideoHeaderH264>();
+  h264_header.nalus[0].type = H264::NaluType::kIdr;
+  h264_header.nalus_length = 1;
 
   packet_buffer_->InsertPacket(&packet_);
 
@@ -912,9 +925,11 @@
 }
 
 TEST_F(TestPacketBufferH264SpsPpsIdrIsKeyframe, SpsPpsIsNotKeyframe) {
-  packet_.video_header.h264().nalus[0].type = H264::NaluType::kSps;
-  packet_.video_header.h264().nalus[1].type = H264::NaluType::kPps;
-  packet_.video_header.h264().nalus_length = 2;
+  auto& h264_header =
+      packet_.video_header.video_type_header.emplace<RTPVideoHeaderH264>();
+  h264_header.nalus[0].type = H264::NaluType::kSps;
+  h264_header.nalus[1].type = H264::NaluType::kPps;
+  h264_header.nalus_length = 2;
 
   packet_buffer_->InsertPacket(&packet_);
 
@@ -923,10 +938,12 @@
 }
 
 TEST_F(TestPacketBufferH264SpsPpsIdrIsKeyframe, SpsPpsIdrIsKeyframe) {
-  packet_.video_header.h264().nalus[0].type = H264::NaluType::kSps;
-  packet_.video_header.h264().nalus[1].type = H264::NaluType::kPps;
-  packet_.video_header.h264().nalus[2].type = H264::NaluType::kIdr;
-  packet_.video_header.h264().nalus_length = 3;
+  auto& h264_header =
+      packet_.video_header.video_type_header.emplace<RTPVideoHeaderH264>();
+  h264_header.nalus[0].type = H264::NaluType::kSps;
+  h264_header.nalus[1].type = H264::NaluType::kPps;
+  h264_header.nalus[2].type = H264::NaluType::kIdr;
+  h264_header.nalus_length = 3;
 
   packet_buffer_->InsertPacket(&packet_);
 
diff --git a/modules/video_coding/video_receiver_unittest.cc b/modules/video_coding/video_receiver_unittest.cc
index 8b64e77..a4778e8 100644
--- a/modules/video_coding/video_receiver_unittest.cc
+++ b/modules/video_coding/video_receiver_unittest.cc
@@ -98,8 +98,7 @@
       0, receiver_->RegisterPacketRequestCallback(&packet_request_callback_));
   const size_t kPaddingSize = 220;
   const uint8_t payload[kPaddingSize] = {0};
-  WebRtcRTPHeader header;
-  memset(&header, 0, sizeof(header));
+  WebRtcRTPHeader header = {};
   header.frameType = kEmptyFrame;
   header.header.markerBit = false;
   header.header.paddingLength = kPaddingSize;
@@ -122,8 +121,7 @@
   const size_t kFrameSize = 1200;
   const size_t kPaddingSize = 220;
   const uint8_t payload[kFrameSize] = {0};
-  WebRtcRTPHeader header;
-  memset(&header, 0, sizeof(header));
+  WebRtcRTPHeader header = {};
   header.frameType = kEmptyFrame;
   header.header.markerBit = false;
   header.header.paddingLength = kPaddingSize;
@@ -173,8 +171,7 @@
   const size_t kFrameSize = 1200;
   const size_t kPaddingSize = 220;
   const uint8_t payload[kFrameSize] = {0};
-  WebRtcRTPHeader header;
-  memset(&header, 0, sizeof(header));
+  WebRtcRTPHeader header = {};
   header.frameType = kEmptyFrame;
   header.video_header().is_first_packet_in_frame = false;
   header.header.markerBit = false;