Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/mock_media_stream_dependency_factory.h" | 5 #include "content/renderer/media/mock_media_stream_dependency_factory.h" |
| 6 #include "content/renderer/media/mock_peer_connection_impl.h" | 6 #include "content/renderer/media/mock_peer_connection_impl.h" |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 virtual MediaStreamInterface* find(const std::string& label) OVERRIDE { | 22 virtual MediaStreamInterface* find(const std::string& label) OVERRIDE { |
| 23 for (size_t i = 0; i < streams_.size(); ++i) { | 23 for (size_t i = 0; i < streams_.size(); ++i) { |
| 24 if (streams_[i]->label() == label) | 24 if (streams_[i]->label() == label) |
| 25 return streams_[i]; | 25 return streams_[i]; |
| 26 } | 26 } |
| 27 return NULL; | 27 return NULL; |
| 28 } | 28 } |
| 29 void AddStream(MediaStreamInterface* stream) { | 29 void AddStream(MediaStreamInterface* stream) { |
| 30 streams_.push_back(stream); | 30 streams_.push_back(stream); |
| 31 } | 31 } |
| 32 void RemoveStream(MediaStreamInterface* stream) { | |
| 33 StreamVector::iterator it = streams_.begin(); | |
| 34 for (; it != streams_.end(); ++it) { | |
| 35 if (it->get() == stream) { | |
| 36 streams_.erase(it); | |
| 37 break; | |
| 38 } | |
| 39 } | |
| 40 } | |
| 32 | 41 |
| 33 protected: | 42 protected: |
| 34 virtual ~MockStreamCollection() {} | 43 virtual ~MockStreamCollection() {} |
| 35 | 44 |
| 36 private: | 45 private: |
| 37 std::vector<talk_base::scoped_refptr<MediaStreamInterface> > streams_; | 46 typedef std::vector<talk_base::scoped_refptr<MediaStreamInterface> > |
| 47 StreamVector; | |
| 48 StreamVector streams_; | |
| 38 }; | 49 }; |
| 39 | 50 |
| 40 const char MockPeerConnectionImpl::kDummyOffer[] = "dummy offer"; | 51 const char MockPeerConnectionImpl::kDummyOffer[] = "dummy offer"; |
| 41 | 52 |
| 42 MockPeerConnectionImpl::MockPeerConnectionImpl( | 53 MockPeerConnectionImpl::MockPeerConnectionImpl( |
| 43 MockMediaStreamDependencyFactory* factory) | 54 MockMediaStreamDependencyFactory* factory) |
| 44 : dependency_factory_(factory), | 55 : dependency_factory_(factory), |
| 45 local_streams_(new talk_base::RefCountedObject<MockStreamCollection>), | 56 local_streams_(new talk_base::RefCountedObject<MockStreamCollection>), |
| 46 remote_streams_(new talk_base::RefCountedObject<MockStreamCollection>), | 57 remote_streams_(new talk_base::RefCountedObject<MockStreamCollection>), |
| 47 hint_audio_(false), | 58 hint_audio_(false), |
| 48 hint_video_(false), | 59 hint_video_(false), |
| 49 action_(kAnswer), | 60 action_(kAnswer), |
| 50 ice_options_(kOnlyRelay), | 61 ice_options_(kOnlyRelay), |
| 51 ready_state_(kNew) { | 62 sdp_mline_index_(-1), |
| 63 ready_state_(kNew), | |
| 64 ice_state_(kIceNew) { | |
| 52 } | 65 } |
| 53 | 66 |
| 54 MockPeerConnectionImpl::~MockPeerConnectionImpl() {} | 67 MockPeerConnectionImpl::~MockPeerConnectionImpl() {} |
| 55 | 68 |
| 56 talk_base::scoped_refptr<StreamCollectionInterface> | 69 talk_base::scoped_refptr<StreamCollectionInterface> |
| 57 MockPeerConnectionImpl::local_streams() { | 70 MockPeerConnectionImpl::local_streams() { |
| 58 return local_streams_; | 71 return local_streams_; |
| 59 } | 72 } |
| 60 | 73 |
| 61 talk_base::scoped_refptr<StreamCollectionInterface> | 74 talk_base::scoped_refptr<StreamCollectionInterface> |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 75 DCHECK(stream_label_.empty()); | 88 DCHECK(stream_label_.empty()); |
| 76 stream_label_ = local_stream->label(); | 89 stream_label_ = local_stream->label(); |
| 77 local_streams_->AddStream(local_stream); | 90 local_streams_->AddStream(local_stream); |
| 78 return true; | 91 return true; |
| 79 } | 92 } |
| 80 | 93 |
| 81 void MockPeerConnectionImpl::RemoveStream( | 94 void MockPeerConnectionImpl::RemoveStream( |
| 82 MediaStreamInterface* local_stream) { | 95 MediaStreamInterface* local_stream) { |
| 83 DCHECK_EQ(stream_label_, local_stream->label()); | 96 DCHECK_EQ(stream_label_, local_stream->label()); |
| 84 stream_label_.clear(); | 97 stream_label_.clear(); |
| 98 local_streams_->RemoveStream(local_stream); | |
| 85 } | 99 } |
| 86 | 100 |
| 87 MockPeerConnectionImpl::ReadyState MockPeerConnectionImpl::ready_state() { | 101 MockPeerConnectionImpl::ReadyState MockPeerConnectionImpl::ready_state() { |
| 88 return ready_state_; | 102 return ready_state_; |
| 89 } | 103 } |
| 90 | 104 |
| 91 bool MockPeerConnectionImpl::StartIce(IceOptions options) { | 105 bool MockPeerConnectionImpl::StartIce(IceOptions options) { |
| 92 ice_options_ = options; | 106 ice_options_ = options; |
| 93 return true; | 107 return true; |
| 94 } | 108 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 120 bool MockPeerConnectionImpl::SetRemoteDescription( | 134 bool MockPeerConnectionImpl::SetRemoteDescription( |
| 121 Action action, | 135 Action action, |
| 122 webrtc::SessionDescriptionInterface* desc) { | 136 webrtc::SessionDescriptionInterface* desc) { |
| 123 action_ = action; | 137 action_ = action; |
| 124 remote_desc_.reset(desc); | 138 remote_desc_.reset(desc); |
| 125 return desc->ToString(&description_sdp_); | 139 return desc->ToString(&description_sdp_); |
| 126 } | 140 } |
| 127 | 141 |
| 128 bool MockPeerConnectionImpl::ProcessIceMessage( | 142 bool MockPeerConnectionImpl::ProcessIceMessage( |
| 129 const webrtc::IceCandidateInterface* ice_candidate) { | 143 const webrtc::IceCandidateInterface* ice_candidate) { |
| 130 sdp_mid_ = ice_candidate->sdp_mid(); | 144 return AddIceCandidate(ice_candidate); |
| 131 sdp_mline_index_ = ice_candidate->sdp_mline_index(); | |
| 132 return ice_candidate->ToString(&ice_sdp_); | |
| 133 } | 145 } |
| 134 | 146 |
| 135 const webrtc::SessionDescriptionInterface* | 147 const webrtc::SessionDescriptionInterface* |
| 136 MockPeerConnectionImpl::local_description() const { | 148 MockPeerConnectionImpl::local_description() const { |
| 137 return local_desc_.get(); | 149 return local_desc_.get(); |
| 138 } | 150 } |
| 139 | 151 |
| 140 const webrtc::SessionDescriptionInterface* | 152 const webrtc::SessionDescriptionInterface* |
| 141 MockPeerConnectionImpl::remote_description() const { | 153 MockPeerConnectionImpl::remote_description() const { |
| 142 return remote_desc_.get(); | 154 return remote_desc_.get(); |
| 143 } | 155 } |
| 144 | 156 |
| 145 void MockPeerConnectionImpl::AddRemoteStream(MediaStreamInterface* stream) { | 157 void MockPeerConnectionImpl::AddRemoteStream(MediaStreamInterface* stream) { |
| 146 remote_streams_->AddStream(stream); | 158 remote_streams_->AddStream(stream); |
| 147 } | 159 } |
| 148 | 160 |
| 149 void MockPeerConnectionImpl::CreateOffer( | 161 void MockPeerConnectionImpl::CreateOffer( |
| 150 CreateSessionDescriptionObserver* observer, | 162 CreateSessionDescriptionObserver* observer, |
| 151 const MediaConstraintsInterface* constraints) { | 163 const MediaConstraintsInterface* constraints) { |
| 152 NOTIMPLEMENTED(); | 164 DCHECK(observer); |
| 165 created_sessiondescription_.reset( | |
| 166 dependency_factory_->CreateSessionDescription(kDummyOffer)); | |
| 153 } | 167 } |
| 154 | 168 |
| 155 void MockPeerConnectionImpl::CreateAnswer( | 169 void MockPeerConnectionImpl::CreateAnswer( |
| 156 CreateSessionDescriptionObserver* observer, | 170 CreateSessionDescriptionObserver* observer, |
| 157 const MediaConstraintsInterface* constraints) { | 171 const MediaConstraintsInterface* constraints) { |
| 158 NOTIMPLEMENTED(); | 172 DCHECK(observer); |
| 173 created_sessiondescription_.reset( | |
| 174 dependency_factory_->CreateSessionDescription(kDummyOffer)); | |
|
Ronghua Wu (Left Chromium)
2012/08/15 00:57:32
Using kDummyOffer here is confusing. Let's have a
perkj_chrome
2012/08/15 09:12:30
Done.
| |
| 159 } | 175 } |
| 160 | 176 |
| 161 void MockPeerConnectionImpl::SetLocalDescription( | 177 void MockPeerConnectionImpl::SetLocalDescription( |
| 162 SetSessionDescriptionObserver* observer, | 178 SetSessionDescriptionObserver* observer, |
| 163 SessionDescriptionInterface* desc) { | 179 SessionDescriptionInterface* desc) { |
| 164 NOTIMPLEMENTED(); | 180 desc->ToString(&description_sdp_); |
| 181 local_desc_.reset(desc); | |
| 165 } | 182 } |
| 166 | 183 |
| 167 void MockPeerConnectionImpl::SetRemoteDescription( | 184 void MockPeerConnectionImpl::SetRemoteDescription( |
| 168 SetSessionDescriptionObserver* observer, | 185 SetSessionDescriptionObserver* observer, |
| 169 SessionDescriptionInterface* desc) { | 186 SessionDescriptionInterface* desc) { |
| 170 NOTIMPLEMENTED(); | 187 desc->ToString(&description_sdp_); |
| 188 remote_desc_.reset(desc); | |
| 171 } | 189 } |
| 172 | 190 |
| 173 bool MockPeerConnectionImpl::UpdateIce( | 191 bool MockPeerConnectionImpl::UpdateIce( |
| 174 const IceServers& configuration, | 192 const IceServers& configuration, |
| 175 const MediaConstraintsInterface* constraints) { | 193 const MediaConstraintsInterface* constraints) { |
| 176 NOTIMPLEMENTED(); | 194 return true; |
| 177 return false; | |
| 178 } | 195 } |
| 179 | 196 |
| 180 bool MockPeerConnectionImpl::AddIceCandidate( | 197 bool MockPeerConnectionImpl::AddIceCandidate( |
| 181 const IceCandidateInterface* candidate) { | 198 const IceCandidateInterface* candidate) { |
| 182 NOTIMPLEMENTED(); | 199 sdp_mid_ = candidate->sdp_mid(); |
| 183 return false; | 200 sdp_mline_index_ = candidate->sdp_mline_index(); |
| 201 return candidate->ToString(&ice_sdp_); | |
| 184 } | 202 } |
| 185 | 203 |
| 186 PeerConnectionInterface::IceState MockPeerConnectionImpl::ice_state() { | 204 PeerConnectionInterface::IceState MockPeerConnectionImpl::ice_state() { |
| 187 NOTIMPLEMENTED(); | 205 return ice_state_; |
| 188 return kIceNew; | |
| 189 } | 206 } |
| 190 | 207 |
| 191 } // namespace webrtc | 208 } // namespace webrtc |
| OLD | NEW |