Simplify RtpVideoStreamReceiver::NotifyReceiverOfFecPacket.

This also has the benefit of deleting one unneeded call to
RTPPayloadRegistry::last_received_media_payload_type.

To make this work, also extend NackModule with a OnReceivedPacket
method taking only the sequence number and the is_keyframe flag,
rather than a complete VCMPacket.

Bug: webrtc:8995
Change-Id: Ice379581166e7b1609ec719e944a5a543d69acc1
Reviewed-on: https://webrtc-review.googlesource.com/64120
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22584}
diff --git a/modules/video_coding/nack_module.cc b/modules/video_coding/nack_module.cc
index ed2e82a..ab66b2b 100644
--- a/modules/video_coding/nack_module.cc
+++ b/modules/video_coding/nack_module.cc
@@ -55,16 +55,13 @@
   RTC_DCHECK(keyframe_request_sender_);
 }
 
-int NackModule::OnReceivedPacket(const VCMPacket& packet) {
+int NackModule::OnReceivedPacket(uint16_t seq_num, bool is_keyframe) {
   rtc::CritScope lock(&crit_);
-  uint16_t seq_num = packet.seqNum;
   // TODO(philipel): When the packet includes information whether it is
   //                 retransmitted or not, use that value instead. For
   //                 now set it to true, which will cause the reordering
   //                 statistics to never be updated.
   bool is_retransmitted = true;
-  bool is_keyframe =
-      packet.is_first_packet_in_frame && packet.frameType == kVideoFrameKey;
 
   if (!initialized_) {
     newest_seq_num_ = seq_num;
@@ -111,6 +108,12 @@
   return 0;
 }
 
+int NackModule::OnReceivedPacket(const VCMPacket& packet) {
+  return OnReceivedPacket(
+      packet.seqNum,
+      packet.is_first_packet_in_frame && packet.frameType == kVideoFrameKey);
+}
+
 void NackModule::ClearUpTo(uint16_t seq_num) {
   rtc::CritScope lock(&crit_);
   nack_list_.erase(nack_list_.begin(), nack_list_.lower_bound(seq_num));
diff --git a/modules/video_coding/nack_module.h b/modules/video_coding/nack_module.h
index 0b91f0b..c18c99f 100644
--- a/modules/video_coding/nack_module.h
+++ b/modules/video_coding/nack_module.h
@@ -32,6 +32,7 @@
              NackSender* nack_sender,
              KeyFrameRequestSender* keyframe_request_sender);
 
+  int OnReceivedPacket(uint16_t seq_num, bool is_keyframe);
   int OnReceivedPacket(const VCMPacket& packet);
   void ClearUpTo(uint16_t seq_num);
   void UpdateRtt(int64_t rtt_ms);
diff --git a/video/rtp_video_stream_receiver.cc b/video/rtp_video_stream_receiver.cc
index 41b8e9f..271a04d 100644
--- a/video/rtp_video_stream_receiver.cc
+++ b/video/rtp_video_stream_receiver.cc
@@ -209,12 +209,8 @@
       nack_module_ ? nack_module_->OnReceivedPacket(packet) : -1;
   packet.receive_time_ms = clock_->TimeInMilliseconds();
 
-  // In the case of a video stream without picture ids and no rtx the
-  // RtpFrameReferenceFinder will need to know about padding to
-  // correctly calculate frame references.
   if (packet.sizeBytes == 0) {
-    reference_finder_->PaddingReceived(packet.seqNum);
-    packet_buffer_->PaddingReceived(packet.seqNum);
+    NotifyReceiverOfEmptyPacket(packet.seqNum);
     return 0;
   }
 
@@ -436,41 +432,21 @@
   }
 }
 
+// In the case of a video stream without picture ids and no rtx the
+// RtpFrameReferenceFinder will need to know about padding to
+// correctly calculate frame references.
+void RtpVideoStreamReceiver::NotifyReceiverOfEmptyPacket(uint16_t seq_num) {
+  reference_finder_->PaddingReceived(seq_num);
+  packet_buffer_->PaddingReceived(seq_num);
+}
+
 void RtpVideoStreamReceiver::NotifyReceiverOfFecPacket(
     const RTPHeader& header) {
-  int8_t last_media_payload_type =
-      rtp_payload_registry_.last_received_media_payload_type();
-  if (last_media_payload_type < 0) {
-    RTC_LOG(LS_WARNING) << "Failed to get last media payload type.";
-    return;
+  if (nack_module_) {
+    nack_module_->OnReceivedPacket(header.sequenceNumber,
+                                   /* is_keyframe = */ false);
   }
-  // Fake an empty media packet.
-  WebRtcRTPHeader rtp_header = {};
-  rtp_header.header = header;
-  rtp_header.header.payloadType = last_media_payload_type;
-  rtp_header.header.paddingLength = 0;
-  const auto pl =
-      rtp_payload_registry_.PayloadTypeToPayload(last_media_payload_type);
-  if (!pl) {
-    RTC_LOG(LS_WARNING) << "Failed to get payload specifics.";
-    return;
-  }
-  rtp_header.type.Video.codec = pl->typeSpecific.video_payload().videoCodecType;
-  rtp_header.type.Video.rotation = kVideoRotation_0;
-  if (header.extension.hasVideoRotation) {
-    rtp_header.type.Video.rotation = header.extension.videoRotation;
-  }
-  rtp_header.type.Video.content_type = VideoContentType::UNSPECIFIED;
-  if (header.extension.hasVideoContentType) {
-    rtp_header.type.Video.content_type = header.extension.videoContentType;
-  }
-  rtp_header.type.Video.video_timing = {0u, 0u, 0u, 0u, 0u, 0u, false};
-  if (header.extension.has_video_timing) {
-    rtp_header.type.Video.video_timing = header.extension.video_timing;
-  }
-  rtp_header.type.Video.playout_delay = header.extension.playout_delay;
-
-  OnReceivedPayloadData(nullptr, 0, &rtp_header);
+  NotifyReceiverOfEmptyPacket(header.sequenceNumber);
 }
 
 bool RtpVideoStreamReceiver::DeliverRtcp(const uint8_t* rtcp_packet,
diff --git a/video/rtp_video_stream_receiver.h b/video/rtp_video_stream_receiver.h
index 43f87d1..a09eaa9 100644
--- a/video/rtp_video_stream_receiver.h
+++ b/video/rtp_video_stream_receiver.h
@@ -154,6 +154,7 @@
   void ParseAndHandleEncapsulatingHeader(const uint8_t* packet,
                                          size_t packet_length,
                                          const RTPHeader& header);
+  void NotifyReceiverOfEmptyPacket(uint16_t seq_num);
   void NotifyReceiverOfFecPacket(const RTPHeader& header);
   bool IsPacketInOrder(const RTPHeader& header) const;
   bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;