Fix setting of recovered flag in RtxReceiveStream.

BUG=webrtc:7135

Review-Url: https://codereview.webrtc.org/3005793002
Cr-Original-Commit-Position: refs/heads/master@{#19599}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: 386449971a8f471e87f3844ebee1b1bc74144998
diff --git a/call/rtx_receive_stream.cc b/call/rtx_receive_stream.cc
index f08e3c3..1646352 100644
--- a/call/rtx_receive_stream.cc
+++ b/call/rtx_receive_stream.cc
@@ -12,16 +12,21 @@
 
 #include "webrtc/call/rtx_receive_stream.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h"
+#include "webrtc/rtc_base/logging.h"
 
 namespace webrtc {
 
-RtxReceiveStream::RtxReceiveStream(
-    RtpPacketSinkInterface* media_sink,
-    std::map<int, int> rtx_payload_type_map,
-    uint32_t media_ssrc)
+RtxReceiveStream::RtxReceiveStream(RtpPacketSinkInterface* media_sink,
+                                   std::map<int, int> associated_payload_types,
+                                   uint32_t media_ssrc)
     : media_sink_(media_sink),
-      rtx_payload_type_map_(std::move(rtx_payload_type_map)),
-      media_ssrc_(media_ssrc) {}
+      associated_payload_types_(std::move(associated_payload_types)),
+      media_ssrc_(media_ssrc) {
+  if (associated_payload_types_.empty()) {
+    LOG(LS_WARNING)
+        << "RtxReceiveStream created with empty payload type mapping.";
+  }
+}
 
 RtxReceiveStream::~RtxReceiveStream() = default;
 
@@ -32,8 +37,11 @@
     return;
   }
 
-  auto it = rtx_payload_type_map_.find(rtx_packet.PayloadType());
-  if (it == rtx_payload_type_map_.end()) {
+  auto it = associated_payload_types_.find(rtx_packet.PayloadType());
+  if (it == associated_payload_types_.end()) {
+    LOG(LS_VERBOSE) << "Unknown payload type "
+                    << static_cast<int>(rtx_packet.PayloadType())
+                    << " on rtx ssrc " << rtx_packet.Ssrc();
     return;
   }
   RtpPacketReceived media_packet;
@@ -42,6 +50,7 @@
   media_packet.SetSsrc(media_ssrc_);
   media_packet.SetSequenceNumber((payload[0] << 8) + payload[1]);
   media_packet.SetPayloadType(it->second);
+  media_packet.set_recovered(true);
 
   // Skip the RTX header.
   rtc::ArrayView<const uint8_t> rtx_payload =
diff --git a/call/rtx_receive_stream.h b/call/rtx_receive_stream.h
index 2830dd3..418775c 100644
--- a/call/rtx_receive_stream.h
+++ b/call/rtx_receive_stream.h
@@ -17,10 +17,12 @@
 
 namespace webrtc {
 
+// This class is responsible for RTX decapsulation. The resulting media packets
+// are passed on to a sink representing the associated media stream.
 class RtxReceiveStream : public RtpPacketSinkInterface {
  public:
   RtxReceiveStream(RtpPacketSinkInterface* media_sink,
-                   std::map<int, int> rtx_payload_type_map,
+                   std::map<int, int> associated_payload_types,
                    uint32_t media_ssrc);
   ~RtxReceiveStream() override;
   // RtpPacketSinkInterface.
@@ -28,8 +30,8 @@
 
  private:
   RtpPacketSinkInterface* const media_sink_;
-  // Mapping rtx_payload_type_map_[rtx] = associated.
-  const std::map<int, int> rtx_payload_type_map_;
+  // Map from rtx payload type -> media payload type.
+  const std::map<int, int> associated_payload_types_;
   // TODO(nisse): Ultimately, the media receive stream shouldn't care about the
   // ssrc, and we should delete this.
   const uint32_t media_ssrc_;
diff --git a/call/rtx_receive_stream_unittest.cc b/call/rtx_receive_stream_unittest.cc
index e9c8210..2b2625d 100644
--- a/call/rtx_receive_stream_unittest.cc
+++ b/call/rtx_receive_stream_unittest.cc
@@ -25,6 +25,7 @@
 
 constexpr int kMediaPayloadType = 100;
 constexpr int kRtxPayloadType = 98;
+constexpr int kUnknownPayloadType = 90;
 constexpr uint32_t kMediaSSRC = 0x3333333;
 constexpr uint16_t kMediaSeqno = 0x5657;
 
@@ -55,8 +56,7 @@
 };
 
 std::map<int, int> PayloadTypeMapping() {
-  std::map<int, int> m;
-  m[kRtxPayloadType] = kMediaPayloadType;
+  const std::map<int, int> m = {{kRtxPayloadType, kMediaPayloadType}};
   return m;
 }
 
@@ -84,9 +84,26 @@
   rtx_sink.OnRtpPacket(rtx_packet);
 }
 
+TEST(RtxReceiveStreamTest, SetsRecoveredFlag) {
+  StrictMock<MockRtpPacketSink> media_sink;
+  RtxReceiveStream rtx_sink(&media_sink, PayloadTypeMapping(), kMediaSSRC);
+  RtpPacketReceived rtx_packet;
+  EXPECT_TRUE(rtx_packet.Parse(rtc::ArrayView<const uint8_t>(kRtxPacket)));
+  EXPECT_FALSE(rtx_packet.recovered());
+  EXPECT_CALL(media_sink, OnRtpPacket(_))
+      .WillOnce(testing::Invoke([](const RtpPacketReceived& packet) {
+        EXPECT_TRUE(packet.recovered());
+      }));
+
+  rtx_sink.OnRtpPacket(rtx_packet);
+}
+
 TEST(RtxReceiveStreamTest, IgnoresUnknownPayloadType) {
   StrictMock<MockRtpPacketSink> media_sink;
-  RtxReceiveStream rtx_sink(&media_sink, std::map<int, int>(), kMediaSSRC);
+  const std::map<int, int> payload_type_mapping = {
+      {kUnknownPayloadType, kMediaPayloadType}};
+
+  RtxReceiveStream rtx_sink(&media_sink, payload_type_mapping, kMediaSSRC);
   RtpPacketReceived rtx_packet;
   EXPECT_TRUE(rtx_packet.Parse(rtc::ArrayView<const uint8_t>(kRtxPacket)));
   rtx_sink.OnRtpPacket(rtx_packet);