[WebRTC] Removing `RtpPacketInfo` map from video receivers 16/297816/1
authorAdam Bujalski <a.bujalski@samsung.com>
Wed, 31 May 2023 12:07:20 +0000 (14:07 +0200)
committerj.gajownik2 <j.gajownik2@samsung.com>
Thu, 24 Aug 2023 16:11:13 +0000 (18:11 +0200)
`RtpVideoStreamReceiver` and `RtpVideoStreamReceiver2` classes uses map
of `RtpPacketInfo` to track information of parsed packet. This patch
moves such association directly to the `PacketBuffer::Packet` class.

Such association removes map lookups which on high bitrate contents are
time consuming.

Bug: Bug: https://cam.sprc.samsung.pl/browse/VDGAME-249
Change-Id: I96272c3b1337d383546941897e4a13a9c96c4b0b

third_party/webrtc/modules/video_coding/packet_buffer.h
third_party/webrtc/video/rtp_video_stream_receiver.cc
third_party/webrtc/video/rtp_video_stream_receiver.h
third_party/webrtc/video/rtp_video_stream_receiver2.cc
third_party/webrtc/video/rtp_video_stream_receiver2.h

index 51528a6cbbe33396baa00b69728457e2d58a755f..329510ec6283107e40da338609c7844ed24a0cf2 100644 (file)
@@ -63,6 +63,7 @@ class PacketBuffer {
 
     rtc::CopyOnWriteBuffer video_payload;
     RTPVideoHeader video_header;
+    RtpPacketInfo packet_info;
   };
   struct InsertResult {
     std::vector<std::unique_ptr<Packet>> packets;
index 0bdf567158ab4e3e6d4088125f7c8f52d11b5be9..506d2bf7942319a863f6679e63ef11bd8147d4cf 100644 (file)
@@ -665,19 +665,12 @@ void RtpVideoStreamReceiver::OnReceivedPayloadData(
   video_coding::PacketBuffer::InsertResult insert_result;
   {
     MutexLock lock(&packet_buffer_lock_);
-    int64_t unwrapped_rtp_seq_num =
-        rtp_seq_num_unwrapper_.Unwrap(rtp_packet.SequenceNumber());
-    auto& packet_info =
-        packet_infos_
-            .emplace(
-                unwrapped_rtp_seq_num,
-                RtpPacketInfo(
-                    rtp_packet.Ssrc(), rtp_packet.Csrcs(),
-                    rtp_packet.Timestamp(),
-                    /*audio_level=*/absl::nullopt,
-                    rtp_packet.GetExtension<AbsoluteCaptureTimeExtension>(),
-                    /*receive_time_ms=*/clock_->TimeInMilliseconds()))
-            .first->second;
+    packet->packet_info = RtpPacketInfo(
+        rtp_packet.Ssrc(), rtp_packet.Csrcs(), rtp_packet.Timestamp(),
+        /*audio_level=*/absl::nullopt,
+        rtp_packet.GetExtension<AbsoluteCaptureTimeExtension>(),
+        /*receive_time_ms=*/clock_->TimeInMilliseconds());
+    auto& packet_info = packet->packet_info;
 
     // Try to extrapolate absolute capture time if it is missing.
     packet_info.set_absolute_capture_time(
@@ -792,10 +785,7 @@ void RtpVideoStreamReceiver::OnInsertedPacket(
       // PacketBuffer promisses frame boundaries are correctly set on each
       // packet. Document that assumption with the DCHECKs.
       RTC_DCHECK_EQ(frame_boundary, packet->is_first_packet_in_frame());
-      int64_t unwrapped_rtp_seq_num =
-          rtp_seq_num_unwrapper_.Unwrap(packet->seq_num);
-      RTC_DCHECK(packet_infos_.count(unwrapped_rtp_seq_num) > 0);
-      RtpPacketInfo& packet_info = packet_infos_[unwrapped_rtp_seq_num];
+      RtpPacketInfo& packet_info = packet->packet_info;
       if (packet->is_first_packet_in_frame()) {
         first_packet = packet.get();
         max_nack_count = packet->times_nacked;
@@ -848,10 +838,6 @@ void RtpVideoStreamReceiver::OnInsertedPacket(
       }
     }
     RTC_DCHECK(frame_boundary);
-
-    if (result.buffer_cleared) {
-      packet_infos_.clear();
-    }
   }  // packet_buffer_lock_
 
   if (result.buffer_cleared) {
@@ -1181,9 +1167,6 @@ void RtpVideoStreamReceiver::FrameDecoded(int64_t picture_id) {
     {
       MutexLock lock(&packet_buffer_lock_);
       packet_buffer_.ClearTo(seq_num);
-      int64_t unwrapped_rtp_seq_num = rtp_seq_num_unwrapper_.Unwrap(seq_num);
-      packet_infos_.erase(packet_infos_.begin(),
-                          packet_infos_.upper_bound(unwrapped_rtp_seq_num));
     }
     MutexLock lock(&reference_finder_lock_);
     reference_finder_->ClearTo(seq_num);
index b3984ba52db2338703e5656e9753eacc6ab0f254..8e33c8e65c343e20ba34cc18375ba7e60b9b21ab 100644 (file)
@@ -430,8 +430,6 @@ class RtpVideoStreamReceiver : public LossNotificationSender,
 
   SeqNumUnwrapper<uint16_t> rtp_seq_num_unwrapper_
       RTC_GUARDED_BY(packet_buffer_lock_);
-  std::map<int64_t, RtpPacketInfo> packet_infos_
-      RTC_GUARDED_BY(packet_buffer_lock_);
 };
 
 }  // namespace webrtc
index 089f9135effc032fc6f8540d09791678bbe714fb..d753cce181eac37cd93b2577e850372e2a522be5 100644 (file)
@@ -476,18 +476,12 @@ void RtpVideoStreamReceiver2::OnReceivedPayloadData(
   auto packet =
       std::make_unique<video_coding::PacketBuffer::Packet>(rtp_packet, video);
 
-  int64_t unwrapped_rtp_seq_num =
-      rtp_seq_num_unwrapper_.Unwrap(rtp_packet.SequenceNumber());
-  auto& packet_info =
-      packet_infos_
-          .emplace(
-              unwrapped_rtp_seq_num,
-              RtpPacketInfo(
-                  rtp_packet.Ssrc(), rtp_packet.Csrcs(), rtp_packet.Timestamp(),
-                  /*audio_level=*/absl::nullopt,
-                  rtp_packet.GetExtension<AbsoluteCaptureTimeExtension>(),
-                  /*receive_time_ms=*/clock_->CurrentTime()))
-          .first->second;
+  packet->packet_info = RtpPacketInfo(
+      rtp_packet.Ssrc(), rtp_packet.Csrcs(), rtp_packet.Timestamp(),
+      /*audio_level=*/absl::nullopt,
+      rtp_packet.GetExtension<AbsoluteCaptureTimeExtension>(),
+      /*receive_time_ms=*/clock_->CurrentTime());
+  auto& packet_info = packet->packet_info;
 
   // Try to extrapolate absolute capture time if it is missing.
   packet_info.set_absolute_capture_time(
@@ -755,10 +749,7 @@ void RtpVideoStreamReceiver2::OnInsertedPacket(
     // PacketBuffer promisses frame boundaries are correctly set on each
     // packet. Document that assumption with the DCHECKs.
     RTC_DCHECK_EQ(frame_boundary, packet->is_first_packet_in_frame());
-    int64_t unwrapped_rtp_seq_num =
-        rtp_seq_num_unwrapper_.Unwrap(packet->seq_num);
-    RTC_DCHECK(packet_infos_.count(unwrapped_rtp_seq_num) > 0);
-    RtpPacketInfo& packet_info = packet_infos_[unwrapped_rtp_seq_num];
+    RtpPacketInfo& packet_info = packet->packet_info;
     if (packet->is_first_packet_in_frame()) {
       first_packet = packet.get();
       max_nack_count = packet->times_nacked;
@@ -812,7 +803,6 @@ void RtpVideoStreamReceiver2::OnInsertedPacket(
     last_received_rtp_system_time_.reset();
     last_received_keyframe_rtp_system_time_.reset();
     last_received_keyframe_rtp_timestamp_.reset();
-    packet_infos_.clear();
     RequestKeyFrame();
   }
 }
@@ -1100,9 +1090,6 @@ void RtpVideoStreamReceiver2::FrameDecoded(int64_t picture_id) {
   }
 
   if (seq_num != -1) {
-    int64_t unwrapped_rtp_seq_num = rtp_seq_num_unwrapper_.Unwrap(seq_num);
-    packet_infos_.erase(packet_infos_.begin(),
-                        packet_infos_.upper_bound(unwrapped_rtp_seq_num));
     packet_buffer_.ClearTo(seq_num);
     reference_finder_->ClearTo(seq_num);
   }
index e0c06d64ccb9331d3cd66c1138137917ad2e2e45..89f7e522bafd09dab009a05766e95e3180f264fc 100644 (file)
@@ -399,8 +399,6 @@ class RtpVideoStreamReceiver2 : public LossNotificationSender,
 
   SeqNumUnwrapper<uint16_t> rtp_seq_num_unwrapper_
       RTC_GUARDED_BY(packet_sequence_checker_);
-  std::map<int64_t, RtpPacketInfo> packet_infos_
-      RTC_GUARDED_BY(packet_sequence_checker_);
 };
 
 }  // namespace webrtc