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

Side by Side Diff: webrtc/pc/channel.cc

Issue 2274283004: Combining "SetTransportChannel" and "SetRtcpTransportChannel". (Closed)
Patch Set: Created 4 years, 3 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/pc/channel.h ('k') | no next file » | 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 2004 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2004 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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 // DTLS-SRTP when |writable_| becomes true again. 293 // DTLS-SRTP when |writable_| becomes true again.
294 writable_ = false; 294 writable_ = false;
295 srtp_filter_.ResetParams(); 295 srtp_filter_.ResetParams();
296 } 296 }
297 297
298 // If this BaseChannel uses RTCP and we haven't fully negotiated RTCP mux, 298 // If this BaseChannel uses RTCP and we haven't fully negotiated RTCP mux,
299 // we need an RTCP channel. 299 // we need an RTCP channel.
300 if (rtcp_enabled_ && !rtcp_mux_filter_.IsFullyActive()) { 300 if (rtcp_enabled_ && !rtcp_mux_filter_.IsFullyActive()) {
301 LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name() 301 LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name()
302 << " on " << transport_name << " transport "; 302 << " on " << transport_name << " transport ";
303 // TODO(deadbeef): Remove this grossness when we remove non-muxed RTCP. 303 SetTransportChannel_n(
304 SetRtcpTransportChannel_n( 304 true, transport_controller_->CreateTransportChannel_n(
305 transport_controller_->CreateTransportChannel_n( 305 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP));
306 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP),
307 false /* update_writablity */);
308 if (!rtcp_transport_channel_) { 306 if (!rtcp_transport_channel_) {
309 return false; 307 return false;
310 } 308 }
311 } 309 }
312 310
313 // We're not updating the writablity during the transition state. 311 LOG(LS_INFO) << "Create non-RTCP TransportChannel for " << content_name()
314 SetTransportChannel_n(transport_controller_->CreateTransportChannel_n( 312 << " on " << transport_name << " transport ";
315 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP)); 313 SetTransportChannel_n(
314 false, transport_controller_->CreateTransportChannel_n(
315 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP));
316 if (!transport_channel_) { 316 if (!transport_channel_) {
317 return false; 317 return false;
318 } 318 }
319 319
320 // TODO(deadbeef): Remove this grossness when we remove non-muxed RTCP.
321 if (rtcp_transport_channel_) {
322 // We can only update the RTCP ready to send after set_transport_channel has
323 // handled channel writability.
324 SetTransportChannelReadyToSend(true, rtcp_transport_channel_->writable());
325 }
326 transport_name_ = transport_name; 320 transport_name_ = transport_name;
327 return true;
328 }
329
330 void BaseChannel::SetTransportChannel_n(TransportChannel* new_tc) {
331 RTC_DCHECK(network_thread_->IsCurrent());
332
333 TransportChannel* old_tc = transport_channel_;
334 if (!old_tc && !new_tc) {
335 // Nothing to do.
336 return;
337 }
338 RTC_DCHECK(old_tc != new_tc);
339
340 if (old_tc) {
341 DisconnectFromTransportChannel(old_tc);
342 transport_controller_->DestroyTransportChannel_n(
343 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP);
344 }
345
346 transport_channel_ = new_tc;
347
348 if (new_tc) {
349 ConnectToTransportChannel(new_tc);
350 for (const auto& pair : socket_options_) {
351 new_tc->SetOption(pair.first, pair.second);
352 }
353 }
354 321
355 // Update aggregate writable/ready-to-send state between RTP and RTCP upon 322 // Update aggregate writable/ready-to-send state between RTP and RTCP upon
356 // setting new transport channels. 323 // setting new transport channels.
357 UpdateWritableState_n(); 324 UpdateWritableState_n();
325 // We can only update ready-to-send after updating writability.
326 //
358 // On setting a new channel, assume it's ready to send if it's writable, 327 // On setting a new channel, assume it's ready to send if it's writable,
359 // because we have no way of knowing otherwise (the channel doesn't give us 328 // because we have no way of knowing otherwise (the channel doesn't give us
360 // "was last send successful?"). 329 // "was last send successful?").
361 // 330 //
362 // This won't always be accurate (the last SendPacket call from another 331 // This won't always be accurate (the last SendPacket call from another
363 // BaseChannel could have resulted in an error), but even so, we'll just 332 // BaseChannel could have resulted in an error), but even so, we'll just
364 // encounter the error again and update "ready to send" accordingly. 333 // encounter the error again and update "ready to send" accordingly.
365 SetTransportChannelReadyToSend(false, new_tc && new_tc->writable()); 334 SetTransportChannelReadyToSend(
335 false, transport_channel_ && transport_channel_->writable());
336 SetTransportChannelReadyToSend(
337 true, rtcp_transport_channel_ && rtcp_transport_channel_->writable());
338 return true;
366 } 339 }
367 340
368 void BaseChannel::SetRtcpTransportChannel_n(TransportChannel* new_tc, 341 void BaseChannel::SetTransportChannel_n(bool rtcp,
369 bool update_writablity) { 342 TransportChannel* new_channel) {
370 RTC_DCHECK(network_thread_->IsCurrent()); 343 RTC_DCHECK(network_thread_->IsCurrent());
344 TransportChannel*& old_channel =
345 rtcp ? rtcp_transport_channel_ : transport_channel_;
371 346
372 TransportChannel* old_tc = rtcp_transport_channel_; 347 if (!old_channel && !new_channel) {
373 if (!old_tc && !new_tc) {
374 // Nothing to do. 348 // Nothing to do.
375 return; 349 return;
376 } 350 }
377 RTC_DCHECK(old_tc != new_tc); 351 RTC_DCHECK(old_channel != new_channel);
378 352
379 if (old_tc) { 353 if (old_channel) {
380 DisconnectFromTransportChannel(old_tc); 354 DisconnectFromTransportChannel(old_channel);
381 transport_controller_->DestroyTransportChannel_n( 355 transport_controller_->DestroyTransportChannel_n(
382 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); 356 transport_name_, rtcp ? cricket::ICE_CANDIDATE_COMPONENT_RTCP
357 : cricket::ICE_CANDIDATE_COMPONENT_RTP);
383 } 358 }
384 359
385 rtcp_transport_channel_ = new_tc; 360 old_channel = new_channel;
386 361
387 if (new_tc) { 362 if (new_channel) {
388 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive())) 363 if (rtcp) {
389 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " 364 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive()))
390 << "should never happen."; 365 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active "
391 ConnectToTransportChannel(new_tc); 366 << "should never happen.";
367 }
368 ConnectToTransportChannel(new_channel);
392 for (const auto& pair : rtcp_socket_options_) { 369 for (const auto& pair : rtcp_socket_options_) {
393 new_tc->SetOption(pair.first, pair.second); 370 new_channel->SetOption(pair.first, pair.second);
394 } 371 }
395 } 372 }
396
397 if (update_writablity) {
398 // Update aggregate writable/ready-to-send state between RTP and RTCP upon
399 // setting new channel
400 UpdateWritableState_n();
401 // On setting a new channel, assume it's ready to send if it's writable,
402 // because we have no way of knowing otherwise (the channel doesn't give us
403 // "was last send successful?").
404 //
405 // This won't always be accurate (the last SendPacket call from another
406 // BaseChannel could have resulted in an error), but even so, we'll just
407 // encounter the error again and update "ready to send" accordingly.
408 SetTransportChannelReadyToSend(true, new_tc && new_tc->writable());
409 }
410 } 373 }
411 374
412 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { 375 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) {
413 RTC_DCHECK(network_thread_->IsCurrent()); 376 RTC_DCHECK(network_thread_->IsCurrent());
414 377
415 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); 378 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState);
416 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); 379 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead);
417 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); 380 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend);
418 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); 381 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState);
419 tc->SignalSelectedCandidatePairChanged.connect( 382 tc->SignalSelectedCandidatePairChanged.connect(
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 } 1168 }
1206 1169
1207 void BaseChannel::ActivateRtcpMux() { 1170 void BaseChannel::ActivateRtcpMux() {
1208 network_thread_->Invoke<void>(RTC_FROM_HERE, 1171 network_thread_->Invoke<void>(RTC_FROM_HERE,
1209 Bind(&BaseChannel::ActivateRtcpMux_n, this)); 1172 Bind(&BaseChannel::ActivateRtcpMux_n, this));
1210 } 1173 }
1211 1174
1212 void BaseChannel::ActivateRtcpMux_n() { 1175 void BaseChannel::ActivateRtcpMux_n() {
1213 if (!rtcp_mux_filter_.IsActive()) { 1176 if (!rtcp_mux_filter_.IsActive()) {
1214 rtcp_mux_filter_.SetActive(); 1177 rtcp_mux_filter_.SetActive();
1215 SetRtcpTransportChannel_n(nullptr, true); 1178 SetTransportChannel_n(true, nullptr);
1179 // Update aggregate writable/ready-to-send state between RTP and RTCP upon
1180 // removing channel.
1181 UpdateWritableState_n();
1182 SetTransportChannelReadyToSend(true, false);
1216 } 1183 }
1217 } 1184 }
1218 1185
1219 bool BaseChannel::SetRtcpMux_n(bool enable, 1186 bool BaseChannel::SetRtcpMux_n(bool enable,
1220 ContentAction action, 1187 ContentAction action,
1221 ContentSource src, 1188 ContentSource src,
1222 std::string* error_desc) { 1189 std::string* error_desc) {
1223 bool ret = false; 1190 bool ret = false;
1224 switch (action) { 1191 switch (action) {
1225 case CA_OFFER: 1192 case CA_OFFER:
1226 ret = rtcp_mux_filter_.SetOffer(enable, src); 1193 ret = rtcp_mux_filter_.SetOffer(enable, src);
1227 break; 1194 break;
1228 case CA_PRANSWER: 1195 case CA_PRANSWER:
1229 // This may activate RTCP muxing, but we don't yet destroy the channel 1196 // This may activate RTCP muxing, but we don't yet destroy the channel
1230 // because the final answer may deactivate it. 1197 // because the final answer may deactivate it.
1231 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); 1198 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src);
1232 break; 1199 break;
1233 case CA_ANSWER: 1200 case CA_ANSWER:
1234 ret = rtcp_mux_filter_.SetAnswer(enable, src); 1201 ret = rtcp_mux_filter_.SetAnswer(enable, src);
1235 if (ret && rtcp_mux_filter_.IsActive()) { 1202 if (ret && rtcp_mux_filter_.IsActive()) {
1236 // We activated RTCP mux, close down the RTCP transport. 1203 // We activated RTCP mux, close down the RTCP transport.
1237 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() 1204 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name()
1238 << " by destroying RTCP transport channel for " 1205 << " by destroying RTCP transport channel for "
1239 << transport_name(); 1206 << transport_name();
1240 SetRtcpTransportChannel_n(nullptr, true); 1207 SetTransportChannel_n(true, nullptr);
1208 UpdateWritableState_n();
1209 SetTransportChannelReadyToSend(true, false);
skvlad 2016/08/26 23:23:13 Please add comments for what the "true" /* rtcp */
Taylor Brandstetter 2016/08/26 23:29:39 I agree. I was planning to use an enum; the struct
1241 } 1210 }
1242 break; 1211 break;
1243 case CA_UPDATE: 1212 case CA_UPDATE:
1244 // No RTCP mux info. 1213 // No RTCP mux info.
1245 ret = true; 1214 ret = true;
1246 break; 1215 break;
1247 default: 1216 default:
1248 break; 1217 break;
1249 } 1218 }
1250 if (!ret) { 1219 if (!ret) {
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after
2440 } 2409 }
2441 2410
2442 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { 2411 void DataChannel::OnStreamClosedRemotely(uint32_t sid) {
2443 rtc::TypedMessageData<uint32_t>* message = 2412 rtc::TypedMessageData<uint32_t>* message =
2444 new rtc::TypedMessageData<uint32_t>(sid); 2413 new rtc::TypedMessageData<uint32_t>(sid);
2445 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY, 2414 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY,
2446 message); 2415 message);
2447 } 2416 }
2448 2417
2449 } // namespace cricket 2418 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/pc/channel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698