OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 Conductor::Conductor(PeerConnectionClient* client, MainWindow* main_wnd) | 56 Conductor::Conductor(PeerConnectionClient* client, MainWindow* main_wnd) |
57 : peer_id_(-1), | 57 : peer_id_(-1), |
58 loopback_(false), | 58 loopback_(false), |
59 client_(client), | 59 client_(client), |
60 main_wnd_(main_wnd) { | 60 main_wnd_(main_wnd) { |
61 client_->RegisterObserver(this); | 61 client_->RegisterObserver(this); |
62 main_wnd->RegisterObserver(this); | 62 main_wnd->RegisterObserver(this); |
63 } | 63 } |
64 | 64 |
65 Conductor::~Conductor() { | 65 Conductor::~Conductor() { |
66 RTC_DCHECK(peer_connection_.get() == NULL); | 66 RTC_DCHECK(peer_connection_.get() == nullptr); |
67 } | 67 } |
68 | 68 |
69 bool Conductor::connection_active() const { | 69 bool Conductor::connection_active() const { |
70 return peer_connection_.get() != NULL; | 70 return peer_connection_.get() != nullptr; |
71 } | 71 } |
72 | 72 |
73 void Conductor::Close() { | 73 void Conductor::Close() { |
74 client_->SignOut(); | 74 client_->SignOut(); |
75 DeletePeerConnection(); | 75 DeletePeerConnection(); |
76 } | 76 } |
77 | 77 |
78 bool Conductor::InitializePeerConnection() { | 78 bool Conductor::InitializePeerConnection() { |
79 RTC_DCHECK(peer_connection_factory_.get() == NULL); | 79 RTC_DCHECK(peer_connection_factory_.get() == nullptr); |
80 RTC_DCHECK(peer_connection_.get() == NULL); | 80 RTC_DCHECK(peer_connection_.get() == nullptr); |
81 | 81 |
82 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(); | 82 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(); |
83 | 83 |
84 if (!peer_connection_factory_.get()) { | 84 if (!peer_connection_factory_.get()) { |
85 main_wnd_->MessageBox("Error", | 85 main_wnd_->MessageBox("Error", |
86 "Failed to initialize PeerConnectionFactory", true); | 86 "Failed to initialize PeerConnectionFactory", true); |
87 DeletePeerConnection(); | 87 DeletePeerConnection(); |
88 return false; | 88 return false; |
89 } | 89 } |
90 | 90 |
91 if (!CreatePeerConnection(DTLS_ON)) { | 91 if (!CreatePeerConnection(DTLS_ON)) { |
92 main_wnd_->MessageBox("Error", | 92 main_wnd_->MessageBox("Error", |
93 "CreatePeerConnection failed", true); | 93 "CreatePeerConnection failed", true); |
94 DeletePeerConnection(); | 94 DeletePeerConnection(); |
95 } | 95 } |
96 AddStreams(); | 96 AddStreams(); |
97 return peer_connection_.get() != NULL; | 97 return peer_connection_.get() != nullptr; |
98 } | 98 } |
99 | 99 |
100 bool Conductor::ReinitializePeerConnectionForLoopback() { | 100 bool Conductor::ReinitializePeerConnectionForLoopback() { |
101 loopback_ = true; | 101 loopback_ = true; |
102 rtc::scoped_refptr<webrtc::StreamCollectionInterface> streams( | 102 rtc::scoped_refptr<webrtc::StreamCollectionInterface> streams( |
103 peer_connection_->local_streams()); | 103 peer_connection_->local_streams()); |
104 peer_connection_ = NULL; | 104 peer_connection_ = nullptr; |
105 if (CreatePeerConnection(DTLS_OFF)) { | 105 if (CreatePeerConnection(DTLS_OFF)) { |
106 for (size_t i = 0; i < streams->count(); ++i) | 106 for (size_t i = 0; i < streams->count(); ++i) |
107 peer_connection_->AddStream(streams->at(i)); | 107 peer_connection_->AddStream(streams->at(i)); |
108 peer_connection_->CreateOffer(this, NULL); | 108 peer_connection_->CreateOffer(this, nullptr); |
109 } | 109 } |
110 return peer_connection_.get() != NULL; | 110 return peer_connection_.get() != nullptr; |
111 } | 111 } |
112 | 112 |
113 bool Conductor::CreatePeerConnection(bool dtls) { | 113 bool Conductor::CreatePeerConnection(bool dtls) { |
114 RTC_DCHECK(peer_connection_factory_.get() != NULL); | 114 RTC_DCHECK(peer_connection_factory_.get() != nullptr); |
115 RTC_DCHECK(peer_connection_.get() == NULL); | 115 RTC_DCHECK(peer_connection_.get() == nullptr); |
116 | 116 |
117 webrtc::PeerConnectionInterface::RTCConfiguration config; | 117 webrtc::PeerConnectionInterface::RTCConfiguration config; |
118 webrtc::PeerConnectionInterface::IceServer server; | 118 webrtc::PeerConnectionInterface::IceServer server; |
119 server.uri = GetPeerConnectionString(); | 119 server.uri = GetPeerConnectionString(); |
120 config.servers.push_back(server); | 120 config.servers.push_back(server); |
121 | 121 |
122 webrtc::FakeConstraints constraints; | 122 webrtc::FakeConstraints constraints; |
123 if (dtls) { | 123 if (dtls) { |
124 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | 124 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
125 "true"); | 125 "true"); |
126 } else { | 126 } else { |
127 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | 127 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
128 "false"); | 128 "false"); |
129 } | 129 } |
130 | 130 |
131 peer_connection_ = peer_connection_factory_->CreatePeerConnection( | 131 peer_connection_ = peer_connection_factory_->CreatePeerConnection( |
132 config, &constraints, NULL, NULL, this); | 132 config, &constraints, nullptr, nullptr, this); |
133 return peer_connection_.get() != NULL; | 133 return peer_connection_.get() != nullptr; |
134 } | 134 } |
135 | 135 |
136 void Conductor::DeletePeerConnection() { | 136 void Conductor::DeletePeerConnection() { |
137 peer_connection_ = NULL; | 137 peer_connection_ = nullptr; |
138 active_streams_.clear(); | 138 active_streams_.clear(); |
139 main_wnd_->StopLocalRenderer(); | 139 main_wnd_->StopLocalRenderer(); |
140 main_wnd_->StopRemoteRenderer(); | 140 main_wnd_->StopRemoteRenderer(); |
141 peer_connection_factory_ = NULL; | 141 peer_connection_factory_ = nullptr; |
142 peer_id_ = -1; | 142 peer_id_ = -1; |
143 loopback_ = false; | 143 loopback_ = false; |
144 } | 144 } |
145 | 145 |
146 void Conductor::EnsureStreamingUI() { | 146 void Conductor::EnsureStreamingUI() { |
147 RTC_DCHECK(peer_connection_.get() != NULL); | 147 RTC_DCHECK(peer_connection_.get() != nullptr); |
148 if (main_wnd_->IsWindow()) { | 148 if (main_wnd_->IsWindow()) { |
149 if (main_wnd_->current_ui() != MainWindow::STREAMING) | 149 if (main_wnd_->current_ui() != MainWindow::STREAMING) |
150 main_wnd_->SwitchToStreamingUI(); | 150 main_wnd_->SwitchToStreamingUI(); |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 // | 154 // |
155 // PeerConnectionObserver implementation. | 155 // PeerConnectionObserver implementation. |
156 // | 156 // |
157 | 157 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 LOG(INFO) << __FUNCTION__; | 214 LOG(INFO) << __FUNCTION__; |
215 // Refresh the list if we're showing it. | 215 // Refresh the list if we're showing it. |
216 if (main_wnd_->current_ui() == MainWindow::LIST_PEERS) | 216 if (main_wnd_->current_ui() == MainWindow::LIST_PEERS) |
217 main_wnd_->SwitchToPeerList(client_->peers()); | 217 main_wnd_->SwitchToPeerList(client_->peers()); |
218 } | 218 } |
219 | 219 |
220 void Conductor::OnPeerDisconnected(int id) { | 220 void Conductor::OnPeerDisconnected(int id) { |
221 LOG(INFO) << __FUNCTION__; | 221 LOG(INFO) << __FUNCTION__; |
222 if (id == peer_id_) { | 222 if (id == peer_id_) { |
223 LOG(INFO) << "Our peer disconnected"; | 223 LOG(INFO) << "Our peer disconnected"; |
224 main_wnd_->QueueUIThreadCallback(PEER_CONNECTION_CLOSED, NULL); | 224 main_wnd_->QueueUIThreadCallback(PEER_CONNECTION_CLOSED, nullptr); |
225 } else { | 225 } else { |
226 // Refresh the list if we're showing it. | 226 // Refresh the list if we're showing it. |
227 if (main_wnd_->current_ui() == MainWindow::LIST_PEERS) | 227 if (main_wnd_->current_ui() == MainWindow::LIST_PEERS) |
228 main_wnd_->SwitchToPeerList(client_->peers()); | 228 main_wnd_->SwitchToPeerList(client_->peers()); |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 void Conductor::OnMessageFromPeer(int peer_id, const std::string& message) { | 232 void Conductor::OnMessageFromPeer(int peer_id, const std::string& message) { |
233 RTC_DCHECK(peer_id_ == peer_id || peer_id_ == -1); | 233 RTC_DCHECK(peer_id_ == peer_id || peer_id_ == -1); |
234 RTC_DCHECK(!message.empty()); | 234 RTC_DCHECK(!message.empty()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 if (!session_description) { | 283 if (!session_description) { |
284 LOG(WARNING) << "Can't parse received session description message. " | 284 LOG(WARNING) << "Can't parse received session description message. " |
285 << "SdpParseError was: " << error.description; | 285 << "SdpParseError was: " << error.description; |
286 return; | 286 return; |
287 } | 287 } |
288 LOG(INFO) << " Received session description :" << message; | 288 LOG(INFO) << " Received session description :" << message; |
289 peer_connection_->SetRemoteDescription( | 289 peer_connection_->SetRemoteDescription( |
290 DummySetSessionDescriptionObserver::Create(), session_description); | 290 DummySetSessionDescriptionObserver::Create(), session_description); |
291 if (session_description->type() == | 291 if (session_description->type() == |
292 webrtc::SessionDescriptionInterface::kOffer) { | 292 webrtc::SessionDescriptionInterface::kOffer) { |
293 peer_connection_->CreateAnswer(this, NULL); | 293 peer_connection_->CreateAnswer(this, nullptr); |
294 } | 294 } |
295 return; | 295 return; |
296 } else { | 296 } else { |
297 std::string sdp_mid; | 297 std::string sdp_mid; |
298 int sdp_mlineindex = 0; | 298 int sdp_mlineindex = 0; |
299 std::string sdp; | 299 std::string sdp; |
300 if (!rtc::GetStringFromJsonObject(jmessage, kCandidateSdpMidName, | 300 if (!rtc::GetStringFromJsonObject(jmessage, kCandidateSdpMidName, |
301 &sdp_mid) || | 301 &sdp_mid) || |
302 !rtc::GetIntFromJsonObject(jmessage, kCandidateSdpMlineIndexName, | 302 !rtc::GetIntFromJsonObject(jmessage, kCandidateSdpMlineIndexName, |
303 &sdp_mlineindex) || | 303 &sdp_mlineindex) || |
(...skipping 13 matching lines...) Expand all Loading... |
317 LOG(WARNING) << "Failed to apply the received candidate"; | 317 LOG(WARNING) << "Failed to apply the received candidate"; |
318 return; | 318 return; |
319 } | 319 } |
320 LOG(INFO) << " Received candidate :" << message; | 320 LOG(INFO) << " Received candidate :" << message; |
321 return; | 321 return; |
322 } | 322 } |
323 } | 323 } |
324 | 324 |
325 void Conductor::OnMessageSent(int err) { | 325 void Conductor::OnMessageSent(int err) { |
326 // Process the next pending message if any. | 326 // Process the next pending message if any. |
327 main_wnd_->QueueUIThreadCallback(SEND_MESSAGE_TO_PEER, NULL); | 327 main_wnd_->QueueUIThreadCallback(SEND_MESSAGE_TO_PEER, nullptr); |
328 } | 328 } |
329 | 329 |
330 void Conductor::OnServerConnectionFailure() { | 330 void Conductor::OnServerConnectionFailure() { |
331 main_wnd_->MessageBox("Error", ("Failed to connect to " + server_).c_str(), | 331 main_wnd_->MessageBox("Error", ("Failed to connect to " + server_).c_str(), |
332 true); | 332 true); |
333 } | 333 } |
334 | 334 |
335 // | 335 // |
336 // MainWndCallback implementation. | 336 // MainWndCallback implementation. |
337 // | 337 // |
(...skipping 15 matching lines...) Expand all Loading... |
353 RTC_DCHECK(peer_id != -1); | 353 RTC_DCHECK(peer_id != -1); |
354 | 354 |
355 if (peer_connection_.get()) { | 355 if (peer_connection_.get()) { |
356 main_wnd_->MessageBox("Error", | 356 main_wnd_->MessageBox("Error", |
357 "We only support connecting to one peer at a time", true); | 357 "We only support connecting to one peer at a time", true); |
358 return; | 358 return; |
359 } | 359 } |
360 | 360 |
361 if (InitializePeerConnection()) { | 361 if (InitializePeerConnection()) { |
362 peer_id_ = peer_id; | 362 peer_id_ = peer_id; |
363 peer_connection_->CreateOffer(this, NULL); | 363 peer_connection_->CreateOffer(this, nullptr); |
364 } else { | 364 } else { |
365 main_wnd_->MessageBox("Error", "Failed to initialize PeerConnection", true); | 365 main_wnd_->MessageBox("Error", "Failed to initialize PeerConnection", true); |
366 } | 366 } |
367 } | 367 } |
368 | 368 |
369 cricket::VideoCapturer* Conductor::OpenVideoCaptureDevice() { | 369 cricket::VideoCapturer* Conductor::OpenVideoCaptureDevice() { |
370 std::vector<std::string> device_names; | 370 std::vector<std::string> device_names; |
371 { | 371 { |
372 std::unique_ptr<webrtc::VideoCaptureModule::DeviceInfo> info( | 372 std::unique_ptr<webrtc::VideoCaptureModule::DeviceInfo> info( |
373 webrtc::VideoCaptureFactory::CreateDeviceInfo()); | 373 webrtc::VideoCaptureFactory::CreateDeviceInfo()); |
(...skipping 21 matching lines...) Expand all Loading... |
395 } | 395 } |
396 return capturer; | 396 return capturer; |
397 } | 397 } |
398 | 398 |
399 void Conductor::AddStreams() { | 399 void Conductor::AddStreams() { |
400 if (active_streams_.find(kStreamLabel) != active_streams_.end()) | 400 if (active_streams_.find(kStreamLabel) != active_streams_.end()) |
401 return; // Already added. | 401 return; // Already added. |
402 | 402 |
403 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( | 403 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
404 peer_connection_factory_->CreateAudioTrack( | 404 peer_connection_factory_->CreateAudioTrack( |
405 kAudioLabel, peer_connection_factory_->CreateAudioSource(NULL))); | 405 kAudioLabel, peer_connection_factory_->CreateAudioSource(nullptr))); |
406 | 406 |
407 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( | 407 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( |
408 peer_connection_factory_->CreateVideoTrack( | 408 peer_connection_factory_->CreateVideoTrack( |
409 kVideoLabel, | 409 kVideoLabel, peer_connection_factory_->CreateVideoSource( |
410 peer_connection_factory_->CreateVideoSource(OpenVideoCaptureDevice(), | 410 OpenVideoCaptureDevice(), nullptr))); |
411 NULL))); | |
412 main_wnd_->StartLocalRenderer(video_track); | 411 main_wnd_->StartLocalRenderer(video_track); |
413 | 412 |
414 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream = | 413 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream = |
415 peer_connection_factory_->CreateLocalMediaStream(kStreamLabel); | 414 peer_connection_factory_->CreateLocalMediaStream(kStreamLabel); |
416 | 415 |
417 stream->AddTrack(audio_track); | 416 stream->AddTrack(audio_track); |
418 stream->AddTrack(video_track); | 417 stream->AddTrack(video_track); |
419 if (!peer_connection_->AddStream(stream)) { | 418 if (!peer_connection_->AddStream(stream)) { |
420 LOG(LS_ERROR) << "Adding stream to PeerConnection failed"; | 419 LOG(LS_ERROR) << "Adding stream to PeerConnection failed"; |
421 } | 420 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 } | 536 } |
538 | 537 |
539 void Conductor::OnFailure(const std::string& error) { | 538 void Conductor::OnFailure(const std::string& error) { |
540 LOG(LERROR) << error; | 539 LOG(LERROR) << error; |
541 } | 540 } |
542 | 541 |
543 void Conductor::SendMessage(const std::string& json_object) { | 542 void Conductor::SendMessage(const std::string& json_object) { |
544 std::string* msg = new std::string(json_object); | 543 std::string* msg = new std::string(json_object); |
545 main_wnd_->QueueUIThreadCallback(SEND_MESSAGE_TO_PEER, msg); | 544 main_wnd_->QueueUIThreadCallback(SEND_MESSAGE_TO_PEER, msg); |
546 } | 545 } |
OLD | NEW |