Prevent recv-stream reconfig on identical codecs.

Receive streams seem to be reconfigured with identical codecs when
another stream is removed. Preventing this reconfiguration makes sure
that existing streams don't report stats during teardown when the stream
is still supposed to be running.

BUG=1788
R=asapersson@webrtc.org

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

Cr-Commit-Position: refs/heads/master@{#9059}
diff --git a/talk/media/webrtc/webrtcvideoengine2.cc b/talk/media/webrtc/webrtcvideoengine2.cc
index b9816fc..ec4f983 100644
--- a/talk/media/webrtc/webrtcvideoengine2.cc
+++ b/talk/media/webrtc/webrtcvideoengine2.cc
@@ -718,6 +718,19 @@
     return false;
   }
 
+  // Prevent reconfiguration when setting identical receive codecs.
+  if (recv_codecs_.size() == supported_codecs.size()) {
+    bool reconfigured = false;
+    for (size_t i = 0; i < supported_codecs.size(); ++i) {
+      if (recv_codecs_[i] != supported_codecs[i]) {
+        reconfigured = true;
+        break;
+      }
+    }
+    if (!reconfigured)
+      return true;
+  }
+
   recv_codecs_ = supported_codecs;
 
   rtc::CritScope stream_lock(&stream_crit_);
@@ -2250,6 +2263,11 @@
          rtx_payload_type == other.rtx_payload_type;
 }
 
+bool WebRtcVideoChannel2::VideoCodecSettings::operator!=(
+    const WebRtcVideoChannel2::VideoCodecSettings& other) const {
+  return !(*this == other);
+}
+
 std::vector<WebRtcVideoChannel2::VideoCodecSettings>
 WebRtcVideoChannel2::MapCodecs(const std::vector<VideoCodec>& codecs) {
   assert(!codecs.empty());
diff --git a/talk/media/webrtc/webrtcvideoengine2.h b/talk/media/webrtc/webrtcvideoengine2.h
index 927e699..b8ddfc6 100644
--- a/talk/media/webrtc/webrtcvideoengine2.h
+++ b/talk/media/webrtc/webrtcvideoengine2.h
@@ -246,7 +246,9 @@
 
   struct VideoCodecSettings {
     VideoCodecSettings();
-    bool operator ==(const VideoCodecSettings& other) const;
+
+    bool operator==(const VideoCodecSettings& other) const;
+    bool operator!=(const VideoCodecSettings& other) const;
 
     VideoCodec codec;
     webrtc::FecConfig fec;