Fix race when deleting video receive streams in Call.

BUG=
R=mflodman@webrtc.org, pbos@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@5457 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/video/call.cc b/video/call.cc
index ff7a05f..10dcf14 100644
--- a/video/call.cc
+++ b/video/call.cc
@@ -312,6 +312,8 @@
         receive_ssrcs_.begin();
     while (it != receive_ssrcs_.end()) {
       if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) {
+        assert(receive_stream_impl == NULL ||
+            receive_stream_impl == it->second);
         receive_stream_impl = it->second;
         receive_ssrcs_.erase(it++);
       } else {
@@ -365,19 +367,14 @@
 bool Call::DeliverRtp(const RTPHeader& header,
                       const uint8_t* packet,
                       size_t length) {
-  VideoReceiveStream* receiver;
-  {
-    ReadLockScoped read_lock(*receive_lock_);
-    std::map<uint32_t, VideoReceiveStream*>::iterator it =
-        receive_ssrcs_.find(header.ssrc);
-    if (it == receive_ssrcs_.end()) {
-      // TODO(pbos): Log some warning, SSRC without receiver.
-      return false;
-    }
-
-    receiver = it->second;
+  ReadLockScoped read_lock(*receive_lock_);
+  std::map<uint32_t, VideoReceiveStream*>::iterator it =
+      receive_ssrcs_.find(header.ssrc);
+  if (it == receive_ssrcs_.end()) {
+    // TODO(pbos): Log some warning, SSRC without receiver.
+    return false;
   }
-  return receiver->DeliverRtp(static_cast<const uint8_t*>(packet), length);
+  return it->second->DeliverRtp(static_cast<const uint8_t*>(packet), length);
 }
 
 bool Call::DeliverPacket(const uint8_t* packet, size_t length) {