Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(722)

Side by Side Diff: webrtc/examples/peerconnection/client/conductor.cc

Issue 2620303003: Replace ASSERT by RTC_DCHECK in all non-test code. (Closed)
Patch Set: Address final nits. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/win32window.cc ('k') | webrtc/examples/peerconnection/client/linux/main_wnd.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 Conductor::Conductor(PeerConnectionClient* client, MainWindow* main_wnd) 57 Conductor::Conductor(PeerConnectionClient* client, MainWindow* main_wnd)
58 : peer_id_(-1), 58 : peer_id_(-1),
59 loopback_(false), 59 loopback_(false),
60 client_(client), 60 client_(client),
61 main_wnd_(main_wnd) { 61 main_wnd_(main_wnd) {
62 client_->RegisterObserver(this); 62 client_->RegisterObserver(this);
63 main_wnd->RegisterObserver(this); 63 main_wnd->RegisterObserver(this);
64 } 64 }
65 65
66 Conductor::~Conductor() { 66 Conductor::~Conductor() {
67 ASSERT(peer_connection_.get() == NULL); 67 RTC_DCHECK(peer_connection_.get() == NULL);
68 } 68 }
69 69
70 bool Conductor::connection_active() const { 70 bool Conductor::connection_active() const {
71 return peer_connection_.get() != NULL; 71 return peer_connection_.get() != NULL;
72 } 72 }
73 73
74 void Conductor::Close() { 74 void Conductor::Close() {
75 client_->SignOut(); 75 client_->SignOut();
76 DeletePeerConnection(); 76 DeletePeerConnection();
77 } 77 }
78 78
79 bool Conductor::InitializePeerConnection() { 79 bool Conductor::InitializePeerConnection() {
80 ASSERT(peer_connection_factory_.get() == NULL); 80 RTC_DCHECK(peer_connection_factory_.get() == NULL);
81 ASSERT(peer_connection_.get() == NULL); 81 RTC_DCHECK(peer_connection_.get() == NULL);
82 82
83 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(); 83 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory();
84 84
85 if (!peer_connection_factory_.get()) { 85 if (!peer_connection_factory_.get()) {
86 main_wnd_->MessageBox("Error", 86 main_wnd_->MessageBox("Error",
87 "Failed to initialize PeerConnectionFactory", true); 87 "Failed to initialize PeerConnectionFactory", true);
88 DeletePeerConnection(); 88 DeletePeerConnection();
89 return false; 89 return false;
90 } 90 }
91 91
(...skipping 13 matching lines...) Expand all
105 peer_connection_ = NULL; 105 peer_connection_ = NULL;
106 if (CreatePeerConnection(DTLS_OFF)) { 106 if (CreatePeerConnection(DTLS_OFF)) {
107 for (size_t i = 0; i < streams->count(); ++i) 107 for (size_t i = 0; i < streams->count(); ++i)
108 peer_connection_->AddStream(streams->at(i)); 108 peer_connection_->AddStream(streams->at(i));
109 peer_connection_->CreateOffer(this, NULL); 109 peer_connection_->CreateOffer(this, NULL);
110 } 110 }
111 return peer_connection_.get() != NULL; 111 return peer_connection_.get() != NULL;
112 } 112 }
113 113
114 bool Conductor::CreatePeerConnection(bool dtls) { 114 bool Conductor::CreatePeerConnection(bool dtls) {
115 ASSERT(peer_connection_factory_.get() != NULL); 115 RTC_DCHECK(peer_connection_factory_.get() != NULL);
116 ASSERT(peer_connection_.get() == NULL); 116 RTC_DCHECK(peer_connection_.get() == NULL);
117 117
118 webrtc::PeerConnectionInterface::RTCConfiguration config; 118 webrtc::PeerConnectionInterface::RTCConfiguration config;
119 webrtc::PeerConnectionInterface::IceServer server; 119 webrtc::PeerConnectionInterface::IceServer server;
120 server.uri = GetPeerConnectionString(); 120 server.uri = GetPeerConnectionString();
121 config.servers.push_back(server); 121 config.servers.push_back(server);
122 122
123 webrtc::FakeConstraints constraints; 123 webrtc::FakeConstraints constraints;
124 if (dtls) { 124 if (dtls) {
125 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, 125 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
126 "true"); 126 "true");
(...skipping 11 matching lines...) Expand all
138 peer_connection_ = NULL; 138 peer_connection_ = NULL;
139 active_streams_.clear(); 139 active_streams_.clear();
140 main_wnd_->StopLocalRenderer(); 140 main_wnd_->StopLocalRenderer();
141 main_wnd_->StopRemoteRenderer(); 141 main_wnd_->StopRemoteRenderer();
142 peer_connection_factory_ = NULL; 142 peer_connection_factory_ = NULL;
143 peer_id_ = -1; 143 peer_id_ = -1;
144 loopback_ = false; 144 loopback_ = false;
145 } 145 }
146 146
147 void Conductor::EnsureStreamingUI() { 147 void Conductor::EnsureStreamingUI() {
148 ASSERT(peer_connection_.get() != NULL); 148 RTC_DCHECK(peer_connection_.get() != NULL);
149 if (main_wnd_->IsWindow()) { 149 if (main_wnd_->IsWindow()) {
150 if (main_wnd_->current_ui() != MainWindow::STREAMING) 150 if (main_wnd_->current_ui() != MainWindow::STREAMING)
151 main_wnd_->SwitchToStreamingUI(); 151 main_wnd_->SwitchToStreamingUI();
152 } 152 }
153 } 153 }
154 154
155 // 155 //
156 // PeerConnectionObserver implementation. 156 // PeerConnectionObserver implementation.
157 // 157 //
158 158
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 LOG(INFO) << "Our peer disconnected"; 224 LOG(INFO) << "Our peer disconnected";
225 main_wnd_->QueueUIThreadCallback(PEER_CONNECTION_CLOSED, NULL); 225 main_wnd_->QueueUIThreadCallback(PEER_CONNECTION_CLOSED, NULL);
226 } else { 226 } else {
227 // Refresh the list if we're showing it. 227 // Refresh the list if we're showing it.
228 if (main_wnd_->current_ui() == MainWindow::LIST_PEERS) 228 if (main_wnd_->current_ui() == MainWindow::LIST_PEERS)
229 main_wnd_->SwitchToPeerList(client_->peers()); 229 main_wnd_->SwitchToPeerList(client_->peers());
230 } 230 }
231 } 231 }
232 232
233 void Conductor::OnMessageFromPeer(int peer_id, const std::string& message) { 233 void Conductor::OnMessageFromPeer(int peer_id, const std::string& message) {
234 ASSERT(peer_id_ == peer_id || peer_id_ == -1); 234 RTC_DCHECK(peer_id_ == peer_id || peer_id_ == -1);
235 ASSERT(!message.empty()); 235 RTC_DCHECK(!message.empty());
236 236
237 if (!peer_connection_.get()) { 237 if (!peer_connection_.get()) {
238 ASSERT(peer_id_ == -1); 238 RTC_DCHECK(peer_id_ == -1);
239 peer_id_ = peer_id; 239 peer_id_ = peer_id;
240 240
241 if (!InitializePeerConnection()) { 241 if (!InitializePeerConnection()) {
242 LOG(LS_ERROR) << "Failed to initialize our PeerConnection instance"; 242 LOG(LS_ERROR) << "Failed to initialize our PeerConnection instance";
243 client_->SignOut(); 243 client_->SignOut();
244 return; 244 return;
245 } 245 }
246 } else if (peer_id != peer_id_) { 246 } else if (peer_id != peer_id_) {
247 ASSERT(peer_id_ != -1); 247 RTC_DCHECK(peer_id_ != -1);
248 LOG(WARNING) << "Received a message from unknown peer while already in a " 248 LOG(WARNING) << "Received a message from unknown peer while already in a "
249 "conversation with a different peer."; 249 "conversation with a different peer.";
250 return; 250 return;
251 } 251 }
252 252
253 Json::Reader reader; 253 Json::Reader reader;
254 Json::Value jmessage; 254 Json::Value jmessage;
255 if (!reader.parse(message, jmessage)) { 255 if (!reader.parse(message, jmessage)) {
256 LOG(WARNING) << "Received unknown message. " << message; 256 LOG(WARNING) << "Received unknown message. " << message;
257 return; 257 return;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 server_ = server; 343 server_ = server;
344 client_->Connect(server, port, GetPeerName()); 344 client_->Connect(server, port, GetPeerName());
345 } 345 }
346 346
347 void Conductor::DisconnectFromServer() { 347 void Conductor::DisconnectFromServer() {
348 if (client_->is_connected()) 348 if (client_->is_connected())
349 client_->SignOut(); 349 client_->SignOut();
350 } 350 }
351 351
352 void Conductor::ConnectToPeer(int peer_id) { 352 void Conductor::ConnectToPeer(int peer_id) {
353 ASSERT(peer_id_ == -1); 353 RTC_DCHECK(peer_id_ == -1);
354 ASSERT(peer_id != -1); 354 RTC_DCHECK(peer_id != -1);
355 355
356 if (peer_connection_.get()) { 356 if (peer_connection_.get()) {
357 main_wnd_->MessageBox("Error", 357 main_wnd_->MessageBox("Error",
358 "We only support connecting to one peer at a time", true); 358 "We only support connecting to one peer at a time", true);
359 return; 359 return;
360 } 360 }
361 361
362 if (InitializePeerConnection()) { 362 if (InitializePeerConnection()) {
363 peer_id_ = peer_id; 363 peer_id_ = peer_id;
364 peer_connection_->CreateOffer(this, NULL); 364 peer_connection_->CreateOffer(this, NULL);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 if (main_wnd_->IsWindow()) 437 if (main_wnd_->IsWindow())
438 main_wnd_->SwitchToPeerList(client_->peers()); 438 main_wnd_->SwitchToPeerList(client_->peers());
439 } 439 }
440 440
441 void Conductor::UIThreadCallback(int msg_id, void* data) { 441 void Conductor::UIThreadCallback(int msg_id, void* data) {
442 switch (msg_id) { 442 switch (msg_id) {
443 case PEER_CONNECTION_CLOSED: 443 case PEER_CONNECTION_CLOSED:
444 LOG(INFO) << "PEER_CONNECTION_CLOSED"; 444 LOG(INFO) << "PEER_CONNECTION_CLOSED";
445 DeletePeerConnection(); 445 DeletePeerConnection();
446 446
447 ASSERT(active_streams_.empty()); 447 RTC_DCHECK(active_streams_.empty());
448 448
449 if (main_wnd_->IsWindow()) { 449 if (main_wnd_->IsWindow()) {
450 if (client_->is_connected()) { 450 if (client_->is_connected()) {
451 main_wnd_->SwitchToPeerList(client_->peers()); 451 main_wnd_->SwitchToPeerList(client_->peers());
452 } else { 452 } else {
453 main_wnd_->SwitchToConnectUI(); 453 main_wnd_->SwitchToConnectUI();
454 } 454 }
455 } else { 455 } else {
456 DisconnectFromServer(); 456 DisconnectFromServer();
457 } 457 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 } 538 }
539 539
540 void Conductor::OnFailure(const std::string& error) { 540 void Conductor::OnFailure(const std::string& error) {
541 LOG(LERROR) << error; 541 LOG(LERROR) << error;
542 } 542 }
543 543
544 void Conductor::SendMessage(const std::string& json_object) { 544 void Conductor::SendMessage(const std::string& json_object) {
545 std::string* msg = new std::string(json_object); 545 std::string* msg = new std::string(json_object);
546 main_wnd_->QueueUIThreadCallback(SEND_MESSAGE_TO_PEER, msg); 546 main_wnd_->QueueUIThreadCallback(SEND_MESSAGE_TO_PEER, msg);
547 } 547 }
OLDNEW
« no previous file with comments | « webrtc/base/win32window.cc ('k') | webrtc/examples/peerconnection/client/linux/main_wnd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698