Register sample rate of Audio RED in RTPPayloadRegistry.

Sample rate of RED payload type was not registered. And therefore VoE can fail when it receives RED packets. This is a fix to this problem.

BUG=3619
R=henrik.lundin@webrtc.org, stefan@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/43919004

Cr-Commit-Position: refs/heads/master@{#8859}
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc b/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc
index 60c27e4..24f6d24 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc
@@ -102,27 +102,17 @@
         payload_name, payload_name_length, frequency, channels, rate);
   }
 
-  RtpUtility::Payload* payload = NULL;
+  RtpUtility::Payload* payload = rtp_payload_strategy_->CreatePayloadType(
+      payload_name, payload_type, frequency, channels, rate);
 
-  // Save the RED payload type. Used in both audio and video.
+  payload_type_map_[payload_type] = payload;
+  *created_new_payload = true;
+
   if (RtpUtility::StringCompare(payload_name, "red", 3)) {
     red_payload_type_ = payload_type;
-    payload = new RtpUtility::Payload;
-    memset(payload, 0, sizeof(*payload));
-    payload->audio = false;
-    strncpy(payload->name, payload_name, RTP_PAYLOAD_NAME_SIZE - 1);
-  } else if (RtpUtility::StringCompare(payload_name, "ulpfec", 3)) {
+  } else if (RtpUtility::StringCompare(payload_name, "ulpfec", 6)) {
     ulpfec_payload_type_ = payload_type;
-    payload = new RtpUtility::Payload;
-    memset(payload, 0, sizeof(*payload));
-    payload->audio = false;
-    strncpy(payload->name, payload_name, RTP_PAYLOAD_NAME_SIZE - 1);
-  } else {
-    *created_new_payload = true;
-    payload = rtp_payload_strategy_->CreatePayloadType(
-        payload_name, payload_type, frequency, channels, rate);
   }
-  payload_type_map_[payload_type] = payload;
 
   // Successful set of payload type, clear the value of last received payload
   // type since it might mean something else.
@@ -433,13 +423,15 @@
       const uint8_t channels,
       const uint32_t rate) const override {
     RtpVideoCodecTypes videoType = kRtpVideoGeneric;
+
     if (RtpUtility::StringCompare(payloadName, "VP8", 3)) {
       videoType = kRtpVideoVp8;
     } else if (RtpUtility::StringCompare(payloadName, "H264", 4)) {
       videoType = kRtpVideoH264;
     } else if (RtpUtility::StringCompare(payloadName, "I420", 4)) {
       videoType = kRtpVideoGeneric;
-    } else if (RtpUtility::StringCompare(payloadName, "ULPFEC", 6)) {
+    } else if (RtpUtility::StringCompare(payloadName, "ULPFEC", 6) ||
+        RtpUtility::StringCompare(payloadName, "RED", 3)) {
       videoType = kRtpVideoNone;
     } else {
       videoType = kRtpVideoGeneric;
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_payload_registry_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_payload_registry_unittest.cc
index 3dd3d7d..5026986 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_payload_registry_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_payload_registry_unittest.cc
@@ -87,24 +87,34 @@
       payload_type, retrieved_payload));
 }
 
-TEST_F(RtpPayloadRegistryTest, DoesNotCreateNewPayloadTypeIfRed) {
-  EXPECT_CALL(*mock_payload_strategy_,
-      CreatePayloadType(_, _, _, _, _)).Times(0);
+TEST_F(RtpPayloadRegistryTest, AudioRedWorkProperly) {
+  const uint8_t kRedPayloadType = 127;
+  const int kRedSampleRate = 8000;
+  const int kRedChannels = 1;
+  const int kRedBitRate = 0;
+
+  // This creates an audio RTP payload strategy.
+  rtp_payload_registry_.reset(new RTPPayloadRegistry(
+      RTPPayloadStrategy::CreateStrategy(true)));
 
   bool new_payload_created = false;
-  uint8_t red_type_of_the_day = 104;
   EXPECT_EQ(0, rtp_payload_registry_->RegisterReceivePayload(
-      "red", red_type_of_the_day, kTypicalFrequency, kTypicalChannels,
-      kTypicalRate, &new_payload_created));
-  ASSERT_FALSE(new_payload_created);
+      "red", kRedPayloadType, kRedSampleRate, kRedChannels, kRedBitRate,
+      &new_payload_created));
+  EXPECT_TRUE(new_payload_created);
 
-  ASSERT_EQ(red_type_of_the_day, rtp_payload_registry_->red_payload_type());
+  EXPECT_EQ(kRedPayloadType, rtp_payload_registry_->red_payload_type());
 
   RtpUtility::Payload* retrieved_payload = NULL;
-  EXPECT_TRUE(rtp_payload_registry_->PayloadTypeToPayload(red_type_of_the_day,
+  EXPECT_TRUE(rtp_payload_registry_->PayloadTypeToPayload(kRedPayloadType,
                                                           retrieved_payload));
-  EXPECT_FALSE(retrieved_payload->audio);
+  ASSERT_TRUE(retrieved_payload);
+  EXPECT_TRUE(retrieved_payload->audio);
   EXPECT_STRCASEEQ("red", retrieved_payload->name);
+
+  // Sample rate is correctly registered.
+  EXPECT_EQ(kRedSampleRate,
+            rtp_payload_registry_->GetPayloadTypeFrequency(kRedPayloadType));
 }
 
 TEST_F(RtpPayloadRegistryTest,