Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 template <class Codec> | 153 template <class Codec> |
| 154 void RtpSendParametersFromMediaDescription( | 154 void RtpSendParametersFromMediaDescription( |
| 155 const MediaContentDescriptionImpl<Codec>* desc, | 155 const MediaContentDescriptionImpl<Codec>* desc, |
| 156 RtpSendParameters<Codec>* send_params) { | 156 RtpSendParameters<Codec>* send_params) { |
| 157 RtpParametersFromMediaDescription(desc, send_params); | 157 RtpParametersFromMediaDescription(desc, send_params); |
| 158 send_params->max_bandwidth_bps = desc->bandwidth(); | 158 send_params->max_bandwidth_bps = desc->bandwidth(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 BaseChannel::BaseChannel(rtc::Thread* worker_thread, | 161 BaseChannel::BaseChannel(rtc::Thread* worker_thread, |
| 162 rtc::Thread* network_thread, | 162 rtc::Thread* network_thread, |
| 163 rtc::Thread* signaling_thread, | |
| 163 MediaChannel* media_channel, | 164 MediaChannel* media_channel, |
| 164 TransportController* transport_controller, | |
| 165 const std::string& content_name, | 165 const std::string& content_name, |
| 166 bool rtcp, | 166 bool rtcp, |
| 167 bool srtp_required) | 167 bool srtp_required) |
| 168 : worker_thread_(worker_thread), | 168 : worker_thread_(worker_thread), |
| 169 network_thread_(network_thread), | 169 network_thread_(network_thread), |
| 170 | 170 signaling_thread_(signaling_thread), |
| 171 content_name_(content_name), | 171 content_name_(content_name), |
| 172 | |
| 173 transport_controller_(transport_controller), | |
| 174 rtcp_enabled_(rtcp), | 172 rtcp_enabled_(rtcp), |
| 175 srtp_required_(srtp_required), | 173 srtp_required_(srtp_required), |
| 176 media_channel_(media_channel), | 174 media_channel_(media_channel), |
| 177 selected_candidate_pair_(nullptr) { | 175 selected_candidate_pair_(nullptr) { |
| 178 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); | 176 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| 179 if (transport_controller) { | |
| 180 RTC_DCHECK_EQ(network_thread, transport_controller->network_thread()); | |
| 181 } | |
| 182 LOG(LS_INFO) << "Created channel for " << content_name; | 177 LOG(LS_INFO) << "Created channel for " << content_name; |
| 183 } | 178 } |
| 184 | 179 |
| 185 BaseChannel::~BaseChannel() { | 180 BaseChannel::~BaseChannel() { |
| 186 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); | 181 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); |
| 187 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); | 182 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| 188 Deinit(); | 183 Deinit(); |
| 189 StopConnectionMonitor(); | 184 StopConnectionMonitor(); |
| 190 // Eats any outstanding messages or packets. | 185 // Eats any outstanding messages or packets. |
| 191 worker_thread_->Clear(&invoker_); | 186 worker_thread_->Clear(&invoker_); |
| 192 worker_thread_->Clear(this); | 187 worker_thread_->Clear(this); |
| 193 // We must destroy the media channel before the transport channel, otherwise | 188 // We must destroy the media channel before the transport channel, otherwise |
| 194 // the media channel may try to send on the dead transport channel. NULLing | 189 // the media channel may try to send on the dead transport channel. NULLing |
| 195 // is not an effective strategy since the sends will come on another thread. | 190 // is not an effective strategy since the sends will come on another thread. |
| 196 delete media_channel_; | 191 delete media_channel_; |
| 197 // Note that we don't just call SetTransportChannel_n(nullptr) because that | 192 LOG(LS_INFO) << "Destroyed channel: " << content_name_; |
| 198 // would call a pure virtual method which we can't do from a destructor. | |
| 199 network_thread_->Invoke<void>( | |
| 200 RTC_FROM_HERE, Bind(&BaseChannel::DestroyTransportChannels_n, this)); | |
| 201 LOG(LS_INFO) << "Destroyed channel"; | |
| 202 } | 193 } |
| 203 | 194 |
| 204 void BaseChannel::DisconnectTransportChannels_n() { | 195 void BaseChannel::DisconnectTransportChannels_n() { |
| 205 // Send any outstanding RTCP packets. | 196 // Send any outstanding RTCP packets. |
| 206 FlushRtcpMessages_n(); | 197 FlushRtcpMessages_n(); |
| 207 | 198 |
| 208 // Stop signals from transport channels, but keep them alive because | 199 // Stop signals from transport channels, but keep them alive because |
| 209 // media_channel may use them from a different thread. | 200 // media_channel may use them from a different thread. |
| 210 if (transport_channel_) { | 201 if (rtp_transport_) { |
| 211 DisconnectFromTransportChannel(transport_channel_); | 202 DisconnectFromTransportChannel(rtp_transport_); |
| 212 } | 203 } |
| 213 if (rtcp_transport_channel_) { | 204 if (rtcp_transport_) { |
| 214 DisconnectFromTransportChannel(rtcp_transport_channel_); | 205 DisconnectFromTransportChannel(rtcp_transport_); |
| 215 } | 206 } |
| 216 | 207 |
| 217 // Clear pending read packets/messages. | 208 // Clear pending read packets/messages. |
| 218 network_thread_->Clear(&invoker_); | 209 network_thread_->Clear(&invoker_); |
| 219 network_thread_->Clear(this); | 210 network_thread_->Clear(this); |
| 220 } | 211 } |
| 221 | 212 |
| 222 void BaseChannel::DestroyTransportChannels_n() { | 213 bool BaseChannel::Init_w(TransportChannel* rtp_transport, |
| 223 if (transport_channel_) { | 214 TransportChannel* rtcp_transport) { |
| 224 transport_controller_->DestroyTransportChannel_n( | |
| 225 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); | |
| 226 } | |
| 227 if (rtcp_transport_channel_) { | |
| 228 transport_controller_->DestroyTransportChannel_n( | |
| 229 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | |
| 230 } | |
| 231 // Clear pending send packets/messages. | |
| 232 network_thread_->Clear(&invoker_); | |
| 233 network_thread_->Clear(this); | |
| 234 } | |
| 235 | |
| 236 bool BaseChannel::Init_w(const std::string* bundle_transport_name) { | |
| 237 if (!network_thread_->Invoke<bool>( | 215 if (!network_thread_->Invoke<bool>( |
| 238 RTC_FROM_HERE, | 216 RTC_FROM_HERE, Bind(&BaseChannel::InitNetwork_n, this, rtp_transport, |
| 239 Bind(&BaseChannel::InitNetwork_n, this, bundle_transport_name))) { | 217 rtcp_transport))) { |
| 240 return false; | 218 return false; |
| 241 } | 219 } |
| 242 | 220 |
| 243 // Both RTP and RTCP channels are set, we can call SetInterface on | 221 // Both RTP and RTCP channels are set, we can call SetInterface on |
| 244 // media channel and it can set network options. | 222 // media channel and it can set network options. |
| 245 RTC_DCHECK(worker_thread_->IsCurrent()); | 223 RTC_DCHECK(worker_thread_->IsCurrent()); |
| 246 media_channel_->SetInterface(this); | 224 media_channel_->SetInterface(this); |
| 247 return true; | 225 return true; |
| 248 } | 226 } |
| 249 | 227 |
| 250 bool BaseChannel::InitNetwork_n(const std::string* bundle_transport_name) { | 228 bool BaseChannel::InitNetwork_n(TransportChannel* rtp_transport, |
| 229 TransportChannel* rtcp_transport) { | |
| 251 RTC_DCHECK(network_thread_->IsCurrent()); | 230 RTC_DCHECK(network_thread_->IsCurrent()); |
| 252 const std::string& transport_name = | 231 // const std::string& transport_name = |
| 253 (bundle_transport_name ? *bundle_transport_name : content_name()); | 232 // (bundle_transport_name ? *bundle_transport_name : content_name()); |
| 254 if (!SetTransport_n(transport_name)) { | 233 if (!SetTransport_n(rtp_transport, rtcp_transport)) { |
| 255 return false; | 234 return false; |
| 256 } | 235 } |
| 257 | 236 |
| 258 if (!SetDtlsSrtpCryptoSuites_n(transport_channel_, false)) { | 237 if (!SetDtlsSrtpCryptoSuites_n(rtp_transport_, false)) { |
| 259 return false; | 238 return false; |
| 260 } | 239 } |
| 261 if (rtcp_transport_channel_ && | 240 if (rtcp_transport_ && !SetDtlsSrtpCryptoSuites_n(rtcp_transport_, true)) { |
| 262 !SetDtlsSrtpCryptoSuites_n(rtcp_transport_channel_, true)) { | |
| 263 return false; | 241 return false; |
| 264 } | 242 } |
| 265 return true; | 243 return true; |
| 266 } | 244 } |
| 267 | 245 |
| 268 void BaseChannel::Deinit() { | 246 void BaseChannel::Deinit() { |
| 269 RTC_DCHECK(worker_thread_->IsCurrent()); | 247 RTC_DCHECK(worker_thread_->IsCurrent()); |
| 270 media_channel_->SetInterface(NULL); | 248 media_channel_->SetInterface(NULL); |
| 271 // Packets arrive on the network thread, processing packets calls virtual | 249 // Packets arrive on the network thread, processing packets calls virtual |
| 272 // functions, so need to stop this process in Deinit that is called in | 250 // functions, so need to stop this process in Deinit that is called in |
| 273 // derived classes destructor. | 251 // derived classes destructor. |
| 274 network_thread_->Invoke<void>( | 252 network_thread_->Invoke<void>( |
| 275 RTC_FROM_HERE, Bind(&BaseChannel::DisconnectTransportChannels_n, this)); | 253 RTC_FROM_HERE, Bind(&BaseChannel::DisconnectTransportChannels_n, this)); |
| 276 } | 254 } |
| 277 | 255 |
| 278 bool BaseChannel::SetTransport(const std::string& transport_name) { | 256 bool BaseChannel::SetTransport(TransportChannel* rtp_transport, |
| 257 TransportChannel* rtcp_transport) { | |
|
pthatcher1
2017/01/13 21:51:07
Shouldn't this be called SetTransports?
Taylor Brandstetter
2017/01/13 23:46:48
Sure, done in follow-up CL.
| |
| 279 return network_thread_->Invoke<bool>( | 258 return network_thread_->Invoke<bool>( |
| 280 RTC_FROM_HERE, Bind(&BaseChannel::SetTransport_n, this, transport_name)); | 259 RTC_FROM_HERE, |
| 260 Bind(&BaseChannel::SetTransport_n, this, rtp_transport, rtcp_transport)); | |
| 281 } | 261 } |
| 282 | 262 |
| 283 bool BaseChannel::SetTransport_n(const std::string& transport_name) { | 263 bool BaseChannel::SetTransport_n(TransportChannel* rtp_transport, |
| 264 TransportChannel* rtcp_transport) { | |
| 284 RTC_DCHECK(network_thread_->IsCurrent()); | 265 RTC_DCHECK(network_thread_->IsCurrent()); |
| 266 if (!rtp_transport && !rtcp_transport) { | |
| 267 LOG(LS_ERROR) << "Setting nullptr to RTP Transport and RTCP Transport."; | |
| 268 return false; | |
| 269 } | |
| 285 | 270 |
| 286 if (transport_name == transport_name_) { | 271 if (rtcp_transport) { |
| 272 RTC_DCHECK(rtp_transport->transport_name() == | |
| 273 rtcp_transport->transport_name()); | |
| 274 RTC_DCHECK(NeedsRtcpTransport()); | |
| 275 } | |
| 276 | |
| 277 if (rtp_transport->transport_name() == transport_name_) { | |
| 287 // Nothing to do if transport name isn't changing. | 278 // Nothing to do if transport name isn't changing. |
| 288 return true; | 279 return true; |
| 289 } | 280 } |
| 290 | 281 |
| 282 transport_name_ = rtp_transport->transport_name(); | |
| 283 | |
| 291 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport | 284 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport |
| 292 // changes and wait until the DTLS handshake is complete to set the newly | 285 // changes and wait until the DTLS handshake is complete to set the newly |
| 293 // negotiated parameters. | 286 // negotiated parameters. |
| 294 if (ShouldSetupDtlsSrtp_n()) { | 287 if (ShouldSetupDtlsSrtp_n()) { |
| 295 // Set |writable_| to false such that UpdateWritableState_w can set up | 288 // Set |writable_| to false such that UpdateWritableState_w can set up |
| 296 // DTLS-SRTP when |writable_| becomes true again. | 289 // DTLS-SRTP when |writable_| becomes true again. |
| 297 writable_ = false; | 290 writable_ = false; |
| 298 srtp_filter_.ResetParams(); | 291 srtp_filter_.ResetParams(); |
| 299 } | 292 } |
| 300 | 293 |
| 301 // If this BaseChannel uses RTCP and we haven't fully negotiated RTCP mux, | 294 // If this BaseChannel uses RTCP and we haven't fully negotiated RTCP mux, |
| 302 // we need an RTCP channel. | 295 // we need an RTCP channel. |
| 303 if (rtcp_enabled_ && !rtcp_mux_filter_.IsFullyActive()) { | 296 if (NeedsRtcpTransport()) { |
| 304 LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name() | 297 LOG(LS_INFO) << "Setting RTCP Transport for " << content_name() << " on " |
| 305 << " on " << transport_name << " transport "; | 298 << transport_name() << " transport " << rtcp_transport; |
| 306 SetTransportChannel_n( | 299 SetTransportChannel_n(true, rtcp_transport); |
| 307 true, transport_controller_->CreateTransportChannel_n( | 300 if (!rtcp_transport_) { |
| 308 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP)); | |
| 309 if (!rtcp_transport_channel_) { | |
| 310 return false; | 301 return false; |
| 311 } | 302 } |
| 312 } | 303 } |
| 313 | 304 |
| 314 LOG(LS_INFO) << "Create non-RTCP TransportChannel for " << content_name() | 305 LOG(LS_INFO) << "Setting non-RTCP Transport for " << content_name() << " on " |
| 315 << " on " << transport_name << " transport "; | 306 << transport_name() << " transport " << rtp_transport; |
| 316 SetTransportChannel_n( | 307 SetTransportChannel_n(false, rtp_transport); |
| 317 false, transport_controller_->CreateTransportChannel_n( | 308 if (!rtp_transport_) { |
| 318 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP)); | |
| 319 if (!transport_channel_) { | |
| 320 return false; | 309 return false; |
| 321 } | 310 } |
| 322 | 311 |
| 323 transport_name_ = transport_name; | |
| 324 | |
| 325 // Update aggregate writable/ready-to-send state between RTP and RTCP upon | 312 // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
| 326 // setting new transport channels. | 313 // setting new transport channels. |
| 327 UpdateWritableState_n(); | 314 UpdateWritableState_n(); |
| 328 // We can only update ready-to-send after updating writability. | 315 // We can only update ready-to-send after updating writability. |
| 329 // | 316 // |
| 330 // On setting a new channel, assume it's ready to send if it's writable, | 317 // On setting a new channel, assume it's ready to send if it's writable, |
| 331 // because we have no way of knowing otherwise (the channel doesn't give us | 318 // because we have no way of knowing otherwise (the channel doesn't give us |
| 332 // "was last send successful?"). | 319 // "was last send successful?"). |
| 333 // | 320 // |
| 334 // This won't always be accurate (the last SendPacket call from another | 321 // This won't always be accurate (the last SendPacket call from another |
| 335 // BaseChannel could have resulted in an error), but even so, we'll just | 322 // BaseChannel could have resulted in an error), but even so, we'll just |
| 336 // encounter the error again and update "ready to send" accordingly. | 323 // encounter the error again and update "ready to send" accordingly. |
| 324 SetTransportChannelReadyToSend(false, | |
| 325 rtp_transport_ && rtp_transport_->writable()); | |
| 337 SetTransportChannelReadyToSend( | 326 SetTransportChannelReadyToSend( |
| 338 false, transport_channel_ && transport_channel_->writable()); | 327 true, rtcp_transport_ && rtcp_transport_->writable()); |
| 339 SetTransportChannelReadyToSend( | |
| 340 true, rtcp_transport_channel_ && rtcp_transport_channel_->writable()); | |
| 341 return true; | 328 return true; |
| 342 } | 329 } |
| 343 | 330 |
| 344 void BaseChannel::SetTransportChannel_n(bool rtcp, | 331 void BaseChannel::SetTransportChannel_n(bool rtcp, |
| 345 TransportChannel* new_channel) { | 332 TransportChannel* new_transport) { |
| 346 RTC_DCHECK(network_thread_->IsCurrent()); | 333 RTC_DCHECK(network_thread_->IsCurrent()); |
| 347 TransportChannel*& old_channel = | 334 TransportChannel*& old_transport = rtcp ? rtcp_transport_ : rtp_transport_; |
| 348 rtcp ? rtcp_transport_channel_ : transport_channel_; | 335 if (!old_transport && !new_transport) { |
| 349 | |
| 350 if (!old_channel && !new_channel) { | |
| 351 // Nothing to do. | 336 // Nothing to do. |
| 352 return; | 337 return; |
| 353 } | 338 } |
| 354 RTC_DCHECK(old_channel != new_channel); | 339 RTC_DCHECK(old_transport != new_transport); |
| 355 | 340 if (old_transport) { |
| 356 if (old_channel) { | 341 DisconnectFromTransportChannel(old_transport); |
| 357 DisconnectFromTransportChannel(old_channel); | |
| 358 transport_controller_->DestroyTransportChannel_n( | |
| 359 transport_name_, rtcp ? cricket::ICE_CANDIDATE_COMPONENT_RTCP | |
| 360 : cricket::ICE_CANDIDATE_COMPONENT_RTP); | |
| 361 } | 342 } |
| 362 | 343 |
| 363 old_channel = new_channel; | 344 old_transport = new_transport; |
| 364 | 345 |
| 365 if (new_channel) { | 346 if (new_transport) { |
| 366 if (rtcp) { | 347 if (rtcp) { |
| 367 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive())) | 348 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive())) |
| 368 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " | 349 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " |
| 369 << "should never happen."; | 350 << "should never happen."; |
| 370 } | 351 } |
| 371 ConnectToTransportChannel(new_channel); | 352 ConnectToTransportChannel(new_transport); |
| 372 auto& socket_options = rtcp ? rtcp_socket_options_ : socket_options_; | 353 auto& socket_options = rtcp ? rtcp_socket_options_ : socket_options_; |
| 373 for (const auto& pair : socket_options) { | 354 for (const auto& pair : socket_options) { |
| 374 new_channel->SetOption(pair.first, pair.second); | 355 new_transport->SetOption(pair.first, pair.second); |
| 375 } | 356 } |
| 376 } | 357 } |
| 377 } | 358 } |
| 378 | 359 |
| 379 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { | 360 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { |
| 380 RTC_DCHECK(network_thread_->IsCurrent()); | 361 RTC_DCHECK(network_thread_->IsCurrent()); |
| 381 | 362 |
| 382 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); | 363 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |
| 383 tc->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); | 364 tc->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); |
| 384 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); | 365 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 | 419 |
| 439 bool BaseChannel::SetRemoteContent(const MediaContentDescription* content, | 420 bool BaseChannel::SetRemoteContent(const MediaContentDescription* content, |
| 440 ContentAction action, | 421 ContentAction action, |
| 441 std::string* error_desc) { | 422 std::string* error_desc) { |
| 442 TRACE_EVENT0("webrtc", "BaseChannel::SetRemoteContent"); | 423 TRACE_EVENT0("webrtc", "BaseChannel::SetRemoteContent"); |
| 443 return InvokeOnWorker(RTC_FROM_HERE, Bind(&BaseChannel::SetRemoteContent_w, | 424 return InvokeOnWorker(RTC_FROM_HERE, Bind(&BaseChannel::SetRemoteContent_w, |
| 444 this, content, action, error_desc)); | 425 this, content, action, error_desc)); |
| 445 } | 426 } |
| 446 | 427 |
| 447 void BaseChannel::StartConnectionMonitor(int cms) { | 428 void BaseChannel::StartConnectionMonitor(int cms) { |
| 448 // We pass in the BaseChannel instead of the transport_channel_ | 429 // We pass in the BaseChannel instead of the rtp_transport_ |
| 449 // because if the transport_channel_ changes, the ConnectionMonitor | 430 // because if the rtp_transport_ changes, the ConnectionMonitor |
| 450 // would be pointing to the wrong TransportChannel. | 431 // would be pointing to the wrong TransportChannel. |
| 451 // We pass in the network thread because on that thread connection monitor | 432 // We pass in the network thread because on that thread connection monitor |
| 452 // will call BaseChannel::GetConnectionStats which must be called on the | 433 // will call BaseChannel::GetConnectionStats which must be called on the |
| 453 // network thread. | 434 // network thread. |
| 454 connection_monitor_.reset( | 435 connection_monitor_.reset( |
| 455 new ConnectionMonitor(this, network_thread(), rtc::Thread::Current())); | 436 new ConnectionMonitor(this, network_thread(), rtc::Thread::Current())); |
| 456 connection_monitor_->SignalUpdate.connect( | 437 connection_monitor_->SignalUpdate.connect( |
| 457 this, &BaseChannel::OnConnectionMonitorUpdate); | 438 this, &BaseChannel::OnConnectionMonitorUpdate); |
| 458 connection_monitor_->Start(cms); | 439 connection_monitor_->Start(cms); |
| 459 } | 440 } |
| 460 | 441 |
| 461 void BaseChannel::StopConnectionMonitor() { | 442 void BaseChannel::StopConnectionMonitor() { |
| 462 if (connection_monitor_) { | 443 if (connection_monitor_) { |
| 463 connection_monitor_->Stop(); | 444 connection_monitor_->Stop(); |
| 464 connection_monitor_.reset(); | 445 connection_monitor_.reset(); |
| 465 } | 446 } |
| 466 } | 447 } |
| 467 | 448 |
| 468 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) { | 449 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) { |
| 469 RTC_DCHECK(network_thread_->IsCurrent()); | 450 RTC_DCHECK(network_thread_->IsCurrent()); |
| 470 return transport_channel_->GetStats(infos); | 451 return rtp_transport_->GetStats(infos); |
| 452 } | |
| 453 | |
| 454 bool BaseChannel::NeedsRtcpTransport() { | |
| 455 return rtcp_enabled_ && !rtcp_mux_filter_.IsFullyActive(); | |
| 471 } | 456 } |
| 472 | 457 |
| 473 bool BaseChannel::IsReadyToReceiveMedia_w() const { | 458 bool BaseChannel::IsReadyToReceiveMedia_w() const { |
| 474 // Receive data if we are enabled and have local content, | 459 // Receive data if we are enabled and have local content, |
| 475 return enabled() && IsReceiveContentDirection(local_content_direction_); | 460 return enabled() && IsReceiveContentDirection(local_content_direction_); |
| 476 } | 461 } |
| 477 | 462 |
| 478 bool BaseChannel::IsReadyToSendMedia_w() const { | 463 bool BaseChannel::IsReadyToSendMedia_w() const { |
| 479 // Need to access some state updated on the network thread. | 464 // Need to access some state updated on the network thread. |
| 480 return network_thread_->Invoke<bool>( | 465 return network_thread_->Invoke<bool>( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 506 RTC_FROM_HERE, Bind(&BaseChannel::SetOption_n, this, type, opt, value)); | 491 RTC_FROM_HERE, Bind(&BaseChannel::SetOption_n, this, type, opt, value)); |
| 507 } | 492 } |
| 508 | 493 |
| 509 int BaseChannel::SetOption_n(SocketType type, | 494 int BaseChannel::SetOption_n(SocketType type, |
| 510 rtc::Socket::Option opt, | 495 rtc::Socket::Option opt, |
| 511 int value) { | 496 int value) { |
| 512 RTC_DCHECK(network_thread_->IsCurrent()); | 497 RTC_DCHECK(network_thread_->IsCurrent()); |
| 513 TransportChannel* channel = nullptr; | 498 TransportChannel* channel = nullptr; |
| 514 switch (type) { | 499 switch (type) { |
| 515 case ST_RTP: | 500 case ST_RTP: |
| 516 channel = transport_channel_; | 501 channel = rtp_transport_; |
| 517 socket_options_.push_back( | 502 socket_options_.push_back( |
| 518 std::pair<rtc::Socket::Option, int>(opt, value)); | 503 std::pair<rtc::Socket::Option, int>(opt, value)); |
| 519 break; | 504 break; |
| 520 case ST_RTCP: | 505 case ST_RTCP: |
| 521 channel = rtcp_transport_channel_; | 506 channel = rtcp_transport_; |
| 522 rtcp_socket_options_.push_back( | 507 rtcp_socket_options_.push_back( |
| 523 std::pair<rtc::Socket::Option, int>(opt, value)); | 508 std::pair<rtc::Socket::Option, int>(opt, value)); |
| 524 break; | 509 break; |
| 525 } | 510 } |
| 526 return channel ? channel->SetOption(opt, value) : -1; | 511 return channel ? channel->SetOption(opt, value) : -1; |
| 527 } | 512 } |
| 528 | 513 |
| 529 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) { | 514 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) { |
| 530 crypto_options_ = crypto_options; | 515 crypto_options_ = crypto_options; |
| 531 return true; | 516 return true; |
| 532 } | 517 } |
| 533 | 518 |
| 534 void BaseChannel::OnWritableState(rtc::PacketTransportInterface* transport) { | 519 void BaseChannel::OnWritableState(rtc::PacketTransportInterface* transport) { |
| 535 RTC_DCHECK(transport == transport_channel_ || | 520 RTC_DCHECK(transport == rtp_transport_ || transport == rtcp_transport_); |
| 536 transport == rtcp_transport_channel_); | |
| 537 RTC_DCHECK(network_thread_->IsCurrent()); | 521 RTC_DCHECK(network_thread_->IsCurrent()); |
| 538 UpdateWritableState_n(); | 522 UpdateWritableState_n(); |
| 539 } | 523 } |
| 540 | 524 |
| 541 void BaseChannel::OnPacketRead(rtc::PacketTransportInterface* transport, | 525 void BaseChannel::OnPacketRead(rtc::PacketTransportInterface* transport, |
| 542 const char* data, | 526 const char* data, |
| 543 size_t len, | 527 size_t len, |
| 544 const rtc::PacketTime& packet_time, | 528 const rtc::PacketTime& packet_time, |
| 545 int flags) { | 529 int flags) { |
| 546 TRACE_EVENT0("webrtc", "BaseChannel::OnPacketRead"); | 530 TRACE_EVENT0("webrtc", "BaseChannel::OnPacketRead"); |
| 547 // OnPacketRead gets called from P2PSocket; now pass data to MediaEngine | 531 // OnPacketRead gets called from P2PSocket; now pass data to MediaEngine |
| 548 RTC_DCHECK(network_thread_->IsCurrent()); | 532 RTC_DCHECK(network_thread_->IsCurrent()); |
| 549 | 533 |
| 550 // When using RTCP multiplexing we might get RTCP packets on the RTP | 534 // When using RTCP multiplexing we might get RTCP packets on the RTP |
| 551 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. | 535 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. |
| 552 bool rtcp = PacketIsRtcp(transport, data, len); | 536 bool rtcp = PacketIsRtcp(transport, data, len); |
| 553 rtc::CopyOnWriteBuffer packet(data, len); | 537 rtc::CopyOnWriteBuffer packet(data, len); |
| 554 HandlePacket(rtcp, &packet, packet_time); | 538 HandlePacket(rtcp, &packet, packet_time); |
| 555 } | 539 } |
| 556 | 540 |
| 557 void BaseChannel::OnReadyToSend(rtc::PacketTransportInterface* transport) { | 541 void BaseChannel::OnReadyToSend(rtc::PacketTransportInterface* transport) { |
| 558 RTC_DCHECK(transport == transport_channel_ || | 542 RTC_DCHECK(transport == rtp_transport_ || transport == rtcp_transport_); |
| 559 transport == rtcp_transport_channel_); | 543 SetTransportChannelReadyToSend(transport == rtcp_transport_, true); |
| 560 SetTransportChannelReadyToSend(transport == rtcp_transport_channel_, true); | |
| 561 } | 544 } |
| 562 | 545 |
| 563 void BaseChannel::OnDtlsState(TransportChannel* channel, | 546 void BaseChannel::OnDtlsState(TransportChannel* channel, |
| 564 DtlsTransportState state) { | 547 DtlsTransportState state) { |
| 565 if (!ShouldSetupDtlsSrtp_n()) { | 548 if (!ShouldSetupDtlsSrtp_n()) { |
| 566 return; | 549 return; |
| 567 } | 550 } |
| 568 | 551 |
| 569 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED | 552 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED |
| 570 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to | 553 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to |
| 571 // cover other scenarios like the whole channel is writable (not just this | 554 // cover other scenarios like the whole channel is writable (not just this |
| 572 // TransportChannel) or when TransportChannel is attached after DTLS is | 555 // TransportChannel) or when TransportChannel is attached after DTLS is |
| 573 // negotiated. | 556 // negotiated. |
| 574 if (state != DTLS_TRANSPORT_CONNECTED) { | 557 if (state != DTLS_TRANSPORT_CONNECTED) { |
| 575 srtp_filter_.ResetParams(); | 558 srtp_filter_.ResetParams(); |
| 576 } | 559 } |
| 577 } | 560 } |
| 578 | 561 |
| 579 void BaseChannel::OnSelectedCandidatePairChanged( | 562 void BaseChannel::OnSelectedCandidatePairChanged( |
| 580 TransportChannel* channel, | 563 TransportChannel* channel, |
| 581 CandidatePairInterface* selected_candidate_pair, | 564 CandidatePairInterface* selected_candidate_pair, |
| 582 int last_sent_packet_id, | 565 int last_sent_packet_id, |
| 583 bool ready_to_send) { | 566 bool ready_to_send) { |
| 584 RTC_DCHECK(channel == transport_channel_ || | 567 RTC_DCHECK(channel == rtp_transport_ || channel == rtcp_transport_); |
| 585 channel == rtcp_transport_channel_); | |
| 586 RTC_DCHECK(network_thread_->IsCurrent()); | 568 RTC_DCHECK(network_thread_->IsCurrent()); |
| 587 selected_candidate_pair_ = selected_candidate_pair; | 569 selected_candidate_pair_ = selected_candidate_pair; |
| 588 std::string transport_name = channel->transport_name(); | 570 std::string transport_name = channel->transport_name(); |
| 589 rtc::NetworkRoute network_route; | 571 rtc::NetworkRoute network_route; |
| 590 if (selected_candidate_pair) { | 572 if (selected_candidate_pair) { |
| 591 network_route = rtc::NetworkRoute( | 573 network_route = rtc::NetworkRoute( |
| 592 ready_to_send, selected_candidate_pair->local_candidate().network_id(), | 574 ready_to_send, selected_candidate_pair->local_candidate().network_id(), |
| 593 selected_candidate_pair->remote_candidate().network_id(), | 575 selected_candidate_pair->remote_candidate().network_id(), |
| 594 last_sent_packet_id); | 576 last_sent_packet_id); |
| 595 | 577 |
| 596 UpdateTransportOverhead(); | 578 UpdateTransportOverhead(); |
| 597 } | 579 } |
| 598 invoker_.AsyncInvoke<void>( | 580 invoker_.AsyncInvoke<void>( |
| 599 RTC_FROM_HERE, worker_thread_, | 581 RTC_FROM_HERE, worker_thread_, |
| 600 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name, | 582 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name, |
| 601 network_route)); | 583 network_route)); |
| 602 } | 584 } |
| 603 | 585 |
| 604 void BaseChannel::SetTransportChannelReadyToSend(bool rtcp, bool ready) { | 586 void BaseChannel::SetTransportChannelReadyToSend(bool rtcp, bool ready) { |
| 605 RTC_DCHECK(network_thread_->IsCurrent()); | 587 RTC_DCHECK(network_thread_->IsCurrent()); |
| 606 if (rtcp) { | 588 if (rtcp) { |
| 607 rtcp_ready_to_send_ = ready; | 589 rtcp_ready_to_send_ = ready; |
| 608 } else { | 590 } else { |
| 609 rtp_ready_to_send_ = ready; | 591 rtp_ready_to_send_ = ready; |
| 610 } | 592 } |
| 611 | 593 |
| 612 bool ready_to_send = | 594 bool ready_to_send = |
| 613 (rtp_ready_to_send_ && | 595 (rtp_ready_to_send_ && |
| 614 // In the case of rtcp mux |rtcp_transport_channel_| will be null. | 596 // In the case of rtcp mux |rtcp_transport_| will be null. |
| 615 (rtcp_ready_to_send_ || !rtcp_transport_channel_)); | 597 (rtcp_ready_to_send_ || !rtcp_transport_)); |
| 616 | 598 |
| 617 invoker_.AsyncInvoke<void>( | 599 invoker_.AsyncInvoke<void>( |
| 618 RTC_FROM_HERE, worker_thread_, | 600 RTC_FROM_HERE, worker_thread_, |
| 619 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send)); | 601 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send)); |
| 620 } | 602 } |
| 621 | 603 |
| 622 bool BaseChannel::PacketIsRtcp(const rtc::PacketTransportInterface* transport, | 604 bool BaseChannel::PacketIsRtcp(const rtc::PacketTransportInterface* transport, |
| 623 const char* data, | 605 const char* data, |
| 624 size_t len) { | 606 size_t len) { |
| 625 return (transport == rtcp_transport_channel_ || | 607 return (transport == rtcp_transport_ || |
| 626 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); | 608 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); |
| 627 } | 609 } |
| 628 | 610 |
| 629 bool BaseChannel::SendPacket(bool rtcp, | 611 bool BaseChannel::SendPacket(bool rtcp, |
| 630 rtc::CopyOnWriteBuffer* packet, | 612 rtc::CopyOnWriteBuffer* packet, |
| 631 const rtc::PacketOptions& options) { | 613 const rtc::PacketOptions& options) { |
| 632 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread. | 614 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread. |
| 633 // If the thread is not our network thread, we will post to our network | 615 // If the thread is not our network thread, we will post to our network |
| 634 // so that the real work happens on our network. This avoids us having to | 616 // so that the real work happens on our network. This avoids us having to |
| 635 // synchronize access to all the pieces of the send path, including | 617 // synchronize access to all the pieces of the send path, including |
| 636 // SRTP and the inner workings of the transport channels. | 618 // SRTP and the inner workings of the transport channels. |
| 637 // The only downside is that we can't return a proper failure code if | 619 // The only downside is that we can't return a proper failure code if |
| 638 // needed. Since UDP is unreliable anyway, this should be a non-issue. | 620 // needed. Since UDP is unreliable anyway, this should be a non-issue. |
| 639 if (!network_thread_->IsCurrent()) { | 621 if (!network_thread_->IsCurrent()) { |
| 640 // Avoid a copy by transferring the ownership of the packet data. | 622 // Avoid a copy by transferring the ownership of the packet data. |
| 641 int message_id = rtcp ? MSG_SEND_RTCP_PACKET : MSG_SEND_RTP_PACKET; | 623 int message_id = rtcp ? MSG_SEND_RTCP_PACKET : MSG_SEND_RTP_PACKET; |
| 642 SendPacketMessageData* data = new SendPacketMessageData; | 624 SendPacketMessageData* data = new SendPacketMessageData; |
| 643 data->packet = std::move(*packet); | 625 data->packet = std::move(*packet); |
| 644 data->options = options; | 626 data->options = options; |
| 645 network_thread_->Post(RTC_FROM_HERE, this, message_id, data); | 627 network_thread_->Post(RTC_FROM_HERE, this, message_id, data); |
| 646 return true; | 628 return true; |
| 647 } | 629 } |
| 648 TRACE_EVENT0("webrtc", "BaseChannel::SendPacket"); | 630 TRACE_EVENT0("webrtc", "BaseChannel::SendPacket"); |
| 649 | 631 |
| 650 // Now that we are on the correct thread, ensure we have a place to send this | 632 // Now that we are on the correct thread, ensure we have a place to send this |
| 651 // packet before doing anything. (We might get RTCP packets that we don't | 633 // packet before doing anything. (We might get RTCP packets that we don't |
| 652 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP | 634 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP |
| 653 // transport. | 635 // transport. |
| 654 TransportChannel* channel = (!rtcp || rtcp_mux_filter_.IsActive()) ? | 636 TransportChannel* channel = |
| 655 transport_channel_ : rtcp_transport_channel_; | 637 (!rtcp || rtcp_mux_filter_.IsActive()) ? rtp_transport_ : rtcp_transport_; |
| 656 if (!channel || !channel->writable()) { | 638 if (!channel || !channel->writable()) { |
| 657 return false; | 639 return false; |
| 658 } | 640 } |
| 659 | 641 |
| 660 // Protect ourselves against crazy data. | 642 // Protect ourselves against crazy data. |
| 661 if (!ValidPacket(rtcp, packet)) { | 643 if (!ValidPacket(rtcp, packet)) { |
| 662 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " | 644 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " |
| 663 << PacketType(rtcp) | 645 << PacketType(rtcp) |
| 664 << " packet: wrong size=" << packet->size(); | 646 << " packet: wrong size=" << packet->size(); |
| 665 return false; | 647 return false; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 893 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); | 875 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| 894 if (!enabled_) | 876 if (!enabled_) |
| 895 return; | 877 return; |
| 896 | 878 |
| 897 LOG(LS_INFO) << "Channel disabled"; | 879 LOG(LS_INFO) << "Channel disabled"; |
| 898 enabled_ = false; | 880 enabled_ = false; |
| 899 UpdateMediaSendRecvState_w(); | 881 UpdateMediaSendRecvState_w(); |
| 900 } | 882 } |
| 901 | 883 |
| 902 void BaseChannel::UpdateWritableState_n() { | 884 void BaseChannel::UpdateWritableState_n() { |
| 903 if (transport_channel_ && transport_channel_->writable() && | 885 if (rtp_transport_ && rtp_transport_->writable() && |
| 904 (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) { | 886 (!rtcp_transport_ || rtcp_transport_->writable())) { |
| 905 ChannelWritable_n(); | 887 ChannelWritable_n(); |
| 906 } else { | 888 } else { |
| 907 ChannelNotWritable_n(); | 889 ChannelNotWritable_n(); |
| 908 } | 890 } |
| 909 } | 891 } |
| 910 | 892 |
| 911 void BaseChannel::ChannelWritable_n() { | 893 void BaseChannel::ChannelWritable_n() { |
| 912 RTC_DCHECK(network_thread_->IsCurrent()); | 894 RTC_DCHECK(network_thread_->IsCurrent()); |
| 913 if (writable_) { | 895 if (writable_) { |
| 914 return; | 896 return; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 949 if (!rtcp) { | 931 if (!rtcp) { |
| 950 GetSrtpCryptoSuites_n(&crypto_suites); | 932 GetSrtpCryptoSuites_n(&crypto_suites); |
| 951 } else { | 933 } else { |
| 952 GetDefaultSrtpCryptoSuites(crypto_options(), &crypto_suites); | 934 GetDefaultSrtpCryptoSuites(crypto_options(), &crypto_suites); |
| 953 } | 935 } |
| 954 return tc->SetSrtpCryptoSuites(crypto_suites); | 936 return tc->SetSrtpCryptoSuites(crypto_suites); |
| 955 } | 937 } |
| 956 | 938 |
| 957 bool BaseChannel::ShouldSetupDtlsSrtp_n() const { | 939 bool BaseChannel::ShouldSetupDtlsSrtp_n() const { |
| 958 // Since DTLS is applied to all channels, checking RTP should be enough. | 940 // Since DTLS is applied to all channels, checking RTP should be enough. |
| 959 return transport_channel_ && transport_channel_->IsDtlsActive(); | 941 return rtp_transport_ && rtp_transport_->IsDtlsActive(); |
| 960 } | 942 } |
| 961 | 943 |
| 962 // This function returns true if either DTLS-SRTP is not in use | 944 // This function returns true if either DTLS-SRTP is not in use |
| 963 // *or* DTLS-SRTP is successfully set up. | 945 // *or* DTLS-SRTP is successfully set up. |
| 964 bool BaseChannel::SetupDtlsSrtp_n(bool rtcp_channel) { | 946 bool BaseChannel::SetupDtlsSrtp_n(bool rtcp_channel) { |
| 965 RTC_DCHECK(network_thread_->IsCurrent()); | 947 RTC_DCHECK(network_thread_->IsCurrent()); |
| 966 bool ret = false; | 948 bool ret = false; |
| 967 | 949 |
| 968 TransportChannel* channel = | 950 TransportChannel* channel = rtcp_channel ? rtcp_transport_ : rtp_transport_; |
| 969 rtcp_channel ? rtcp_transport_channel_ : transport_channel_; | |
| 970 | 951 |
| 971 RTC_DCHECK(channel->IsDtlsActive()); | 952 RTC_DCHECK(channel->IsDtlsActive()); |
| 972 | 953 |
| 973 int selected_crypto_suite; | 954 int selected_crypto_suite; |
| 974 | 955 |
| 975 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { | 956 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { |
| 976 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; | 957 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; |
| 977 return false; | 958 return false; |
| 978 } | 959 } |
| 979 | 960 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1057 | 1038 |
| 1058 if (!ShouldSetupDtlsSrtp_n()) { | 1039 if (!ShouldSetupDtlsSrtp_n()) { |
| 1059 return; | 1040 return; |
| 1060 } | 1041 } |
| 1061 | 1042 |
| 1062 if (!SetupDtlsSrtp_n(false)) { | 1043 if (!SetupDtlsSrtp_n(false)) { |
| 1063 SignalDtlsSrtpSetupFailure_n(false); | 1044 SignalDtlsSrtpSetupFailure_n(false); |
| 1064 return; | 1045 return; |
| 1065 } | 1046 } |
| 1066 | 1047 |
| 1067 if (rtcp_transport_channel_) { | 1048 if (rtcp_transport_) { |
| 1068 if (!SetupDtlsSrtp_n(true)) { | 1049 if (!SetupDtlsSrtp_n(true)) { |
| 1069 SignalDtlsSrtpSetupFailure_n(true); | 1050 SignalDtlsSrtpSetupFailure_n(true); |
| 1070 return; | 1051 return; |
| 1071 } | 1052 } |
| 1072 } | 1053 } |
| 1073 } | 1054 } |
| 1074 | 1055 |
| 1075 void BaseChannel::ChannelNotWritable_n() { | 1056 void BaseChannel::ChannelNotWritable_n() { |
| 1076 RTC_DCHECK(network_thread_->IsCurrent()); | 1057 RTC_DCHECK(network_thread_->IsCurrent()); |
| 1077 if (!writable_) | 1058 if (!writable_) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1114 } | 1095 } |
| 1115 | 1096 |
| 1116 return true; | 1097 return true; |
| 1117 } | 1098 } |
| 1118 | 1099 |
| 1119 // |dtls| will be set to true if DTLS is active for transport channel and | 1100 // |dtls| will be set to true if DTLS is active for transport channel and |
| 1120 // crypto is empty. | 1101 // crypto is empty. |
| 1121 bool BaseChannel::CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos, | 1102 bool BaseChannel::CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos, |
| 1122 bool* dtls, | 1103 bool* dtls, |
| 1123 std::string* error_desc) { | 1104 std::string* error_desc) { |
| 1124 *dtls = transport_channel_->IsDtlsActive(); | 1105 *dtls = rtp_transport_->IsDtlsActive(); |
| 1125 if (*dtls && !cryptos.empty()) { | 1106 if (*dtls && !cryptos.empty()) { |
| 1126 SafeSetError("Cryptos must be empty when DTLS is active.", error_desc); | 1107 SafeSetError("Cryptos must be empty when DTLS is active.", error_desc); |
| 1127 return false; | 1108 return false; |
| 1128 } | 1109 } |
| 1129 return true; | 1110 return true; |
| 1130 } | 1111 } |
| 1131 | 1112 |
| 1132 bool BaseChannel::SetSrtp_n(const std::vector<CryptoParams>& cryptos, | 1113 bool BaseChannel::SetSrtp_n(const std::vector<CryptoParams>& cryptos, |
| 1133 ContentAction action, | 1114 ContentAction action, |
| 1134 ContentSource src, | 1115 ContentSource src, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1177 } | 1158 } |
| 1178 | 1159 |
| 1179 void BaseChannel::ActivateRtcpMux() { | 1160 void BaseChannel::ActivateRtcpMux() { |
| 1180 network_thread_->Invoke<void>(RTC_FROM_HERE, | 1161 network_thread_->Invoke<void>(RTC_FROM_HERE, |
| 1181 Bind(&BaseChannel::ActivateRtcpMux_n, this)); | 1162 Bind(&BaseChannel::ActivateRtcpMux_n, this)); |
| 1182 } | 1163 } |
| 1183 | 1164 |
| 1184 void BaseChannel::ActivateRtcpMux_n() { | 1165 void BaseChannel::ActivateRtcpMux_n() { |
| 1185 if (!rtcp_mux_filter_.IsActive()) { | 1166 if (!rtcp_mux_filter_.IsActive()) { |
| 1186 rtcp_mux_filter_.SetActive(); | 1167 rtcp_mux_filter_.SetActive(); |
| 1168 bool need_to_delete_rtcp = (rtcp_transport() != nullptr); | |
| 1187 SetTransportChannel_n(true, nullptr); | 1169 SetTransportChannel_n(true, nullptr); |
| 1170 if (need_to_delete_rtcp) { | |
| 1171 SignalDestroyRtcpTransport(rtp_transport()->transport_name()); | |
| 1172 } | |
| 1188 // Update aggregate writable/ready-to-send state between RTP and RTCP upon | 1173 // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
| 1189 // removing channel. | 1174 // removing channel. |
| 1190 UpdateWritableState_n(); | 1175 UpdateWritableState_n(); |
| 1191 SetTransportChannelReadyToSend(true, false); | 1176 SetTransportChannelReadyToSend(true, false); |
| 1192 } | 1177 } |
| 1193 } | 1178 } |
| 1194 | 1179 |
| 1195 bool BaseChannel::SetRtcpMux_n(bool enable, | 1180 bool BaseChannel::SetRtcpMux_n(bool enable, |
| 1196 ContentAction action, | 1181 ContentAction action, |
| 1197 ContentSource src, | 1182 ContentSource src, |
| 1198 std::string* error_desc) { | 1183 std::string* error_desc) { |
| 1199 bool ret = false; | 1184 bool ret = false; |
| 1200 switch (action) { | 1185 switch (action) { |
| 1201 case CA_OFFER: | 1186 case CA_OFFER: |
| 1202 ret = rtcp_mux_filter_.SetOffer(enable, src); | 1187 ret = rtcp_mux_filter_.SetOffer(enable, src); |
| 1203 break; | 1188 break; |
| 1204 case CA_PRANSWER: | 1189 case CA_PRANSWER: |
| 1205 // This may activate RTCP muxing, but we don't yet destroy the channel | 1190 // This may activate RTCP muxing, but we don't yet destroy the channel |
| 1206 // because the final answer may deactivate it. | 1191 // because the final answer may deactivate it. |
| 1207 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); | 1192 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); |
| 1208 break; | 1193 break; |
| 1209 case CA_ANSWER: | 1194 case CA_ANSWER: |
| 1210 ret = rtcp_mux_filter_.SetAnswer(enable, src); | 1195 ret = rtcp_mux_filter_.SetAnswer(enable, src); |
| 1211 if (ret && rtcp_mux_filter_.IsActive()) { | 1196 if (ret && rtcp_mux_filter_.IsActive()) { |
| 1212 // We activated RTCP mux, close down the RTCP transport. | 1197 // We activated RTCP mux, close down the RTCP transport. |
| 1213 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() | 1198 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() |
| 1214 << " by destroying RTCP transport channel for " | 1199 << " by destroying RTCP transport channel for " |
| 1215 << transport_name(); | 1200 << transport_name(); |
| 1201 bool need_to_delete_rtcp = (rtcp_transport() != nullptr); | |
| 1216 SetTransportChannel_n(true, nullptr); | 1202 SetTransportChannel_n(true, nullptr); |
| 1203 if (need_to_delete_rtcp) { | |
| 1204 SignalDestroyRtcpTransport(rtp_transport()->transport_name()); | |
| 1205 } | |
| 1217 UpdateWritableState_n(); | 1206 UpdateWritableState_n(); |
| 1218 SetTransportChannelReadyToSend(true, false); | 1207 SetTransportChannelReadyToSend(true, false); |
| 1219 } | 1208 } |
| 1220 break; | 1209 break; |
| 1221 case CA_UPDATE: | 1210 case CA_UPDATE: |
| 1222 // No RTCP mux info. | 1211 // No RTCP mux info. |
| 1223 ret = true; | 1212 ret = true; |
| 1224 break; | 1213 break; |
| 1225 default: | 1214 default: |
| 1226 break; | 1215 break; |
| 1227 } | 1216 } |
| 1228 if (!ret) { | 1217 if (!ret) { |
| 1229 SafeSetError("Failed to setup RTCP mux filter.", error_desc); | 1218 SafeSetError("Failed to setup RTCP mux filter.", error_desc); |
| 1230 return false; | 1219 return false; |
| 1231 } | 1220 } |
| 1232 // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or | 1221 // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or |
| 1233 // CA_ANSWER, but we only want to tear down the RTCP transport channel if we | 1222 // CA_ANSWER, but we only want to tear down the RTCP transport channel if we |
| 1234 // received a final answer. | 1223 // received a final answer. |
| 1235 if (rtcp_mux_filter_.IsActive()) { | 1224 if (rtcp_mux_filter_.IsActive()) { |
| 1236 // If the RTP transport is already writable, then so are we. | 1225 // If the RTP transport is already writable, then so are we. |
| 1237 if (transport_channel_->writable()) { | 1226 if (rtp_transport_->writable()) { |
| 1238 ChannelWritable_n(); | 1227 ChannelWritable_n(); |
| 1239 } | 1228 } |
| 1240 } | 1229 } |
| 1241 | 1230 |
| 1242 return true; | 1231 return true; |
| 1243 } | 1232 } |
| 1244 | 1233 |
| 1245 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) { | 1234 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) { |
| 1246 RTC_DCHECK(worker_thread() == rtc::Thread::Current()); | 1235 RTC_DCHECK(worker_thread() == rtc::Thread::Current()); |
| 1247 return media_channel()->AddRecvStream(sp); | 1236 return media_channel()->AddRecvStream(sp); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1462 rtc::Bind(&BaseChannel::SignalSentPacket_w, this, sent_packet)); | 1451 rtc::Bind(&BaseChannel::SignalSentPacket_w, this, sent_packet)); |
| 1463 } | 1452 } |
| 1464 | 1453 |
| 1465 void BaseChannel::SignalSentPacket_w(const rtc::SentPacket& sent_packet) { | 1454 void BaseChannel::SignalSentPacket_w(const rtc::SentPacket& sent_packet) { |
| 1466 RTC_DCHECK(worker_thread_->IsCurrent()); | 1455 RTC_DCHECK(worker_thread_->IsCurrent()); |
| 1467 SignalSentPacket(sent_packet); | 1456 SignalSentPacket(sent_packet); |
| 1468 } | 1457 } |
| 1469 | 1458 |
| 1470 VoiceChannel::VoiceChannel(rtc::Thread* worker_thread, | 1459 VoiceChannel::VoiceChannel(rtc::Thread* worker_thread, |
| 1471 rtc::Thread* network_thread, | 1460 rtc::Thread* network_thread, |
| 1461 rtc::Thread* signaling_thread, | |
| 1472 MediaEngineInterface* media_engine, | 1462 MediaEngineInterface* media_engine, |
| 1473 VoiceMediaChannel* media_channel, | 1463 VoiceMediaChannel* media_channel, |
| 1474 TransportController* transport_controller, | |
| 1475 const std::string& content_name, | 1464 const std::string& content_name, |
| 1476 bool rtcp, | 1465 bool rtcp, |
| 1477 bool srtp_required) | 1466 bool srtp_required) |
| 1478 : BaseChannel(worker_thread, | 1467 : BaseChannel(worker_thread, |
| 1479 network_thread, | 1468 network_thread, |
| 1469 signaling_thread, | |
| 1480 media_channel, | 1470 media_channel, |
| 1481 transport_controller, | |
| 1482 content_name, | 1471 content_name, |
| 1483 rtcp, | 1472 rtcp, |
| 1484 srtp_required), | 1473 srtp_required), |
| 1485 media_engine_(media_engine), | 1474 media_engine_(media_engine), |
| 1486 received_media_(false) {} | 1475 received_media_(false) {} |
| 1487 | 1476 |
| 1488 VoiceChannel::~VoiceChannel() { | 1477 VoiceChannel::~VoiceChannel() { |
| 1489 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); | 1478 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); |
| 1490 StopAudioMonitor(); | 1479 StopAudioMonitor(); |
| 1491 StopMediaMonitor(); | 1480 StopMediaMonitor(); |
| 1492 // this can't be done in the base class, since it calls a virtual | 1481 // this can't be done in the base class, since it calls a virtual |
| 1493 DisableMedia_w(); | 1482 DisableMedia_w(); |
| 1494 Deinit(); | 1483 Deinit(); |
| 1495 } | 1484 } |
| 1496 | 1485 |
| 1497 bool VoiceChannel::Init_w(const std::string* bundle_transport_name) { | 1486 bool VoiceChannel::Init_w(TransportChannel* rtp_transport, |
| 1498 if (!BaseChannel::Init_w(bundle_transport_name)) { | 1487 TransportChannel* rtcp_transport) { |
| 1499 return false; | 1488 return BaseChannel::Init_w(rtp_transport, rtcp_transport); |
| 1500 } | |
| 1501 return true; | |
| 1502 } | 1489 } |
| 1503 | 1490 |
| 1504 bool VoiceChannel::SetAudioSend(uint32_t ssrc, | 1491 bool VoiceChannel::SetAudioSend(uint32_t ssrc, |
| 1505 bool enable, | 1492 bool enable, |
| 1506 const AudioOptions* options, | 1493 const AudioOptions* options, |
| 1507 AudioSource* source) { | 1494 AudioSource* source) { |
| 1508 return InvokeOnWorker(RTC_FROM_HERE, | 1495 return InvokeOnWorker(RTC_FROM_HERE, |
| 1509 Bind(&VoiceMediaChannel::SetAudioSend, media_channel(), | 1496 Bind(&VoiceMediaChannel::SetAudioSend, media_channel(), |
| 1510 ssrc, enable, options, source)); | 1497 ssrc, enable, options, source)); |
| 1511 } | 1498 } |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1878 SignalAudioMonitor(this, info); | 1865 SignalAudioMonitor(this, info); |
| 1879 } | 1866 } |
| 1880 | 1867 |
| 1881 void VoiceChannel::GetSrtpCryptoSuites_n( | 1868 void VoiceChannel::GetSrtpCryptoSuites_n( |
| 1882 std::vector<int>* crypto_suites) const { | 1869 std::vector<int>* crypto_suites) const { |
| 1883 GetSupportedAudioCryptoSuites(crypto_options(), crypto_suites); | 1870 GetSupportedAudioCryptoSuites(crypto_options(), crypto_suites); |
| 1884 } | 1871 } |
| 1885 | 1872 |
| 1886 VideoChannel::VideoChannel(rtc::Thread* worker_thread, | 1873 VideoChannel::VideoChannel(rtc::Thread* worker_thread, |
| 1887 rtc::Thread* network_thread, | 1874 rtc::Thread* network_thread, |
| 1875 rtc::Thread* signaling_thread, | |
| 1888 VideoMediaChannel* media_channel, | 1876 VideoMediaChannel* media_channel, |
| 1889 TransportController* transport_controller, | |
| 1890 const std::string& content_name, | 1877 const std::string& content_name, |
| 1891 bool rtcp, | 1878 bool rtcp, |
| 1892 bool srtp_required) | 1879 bool srtp_required) |
| 1893 : BaseChannel(worker_thread, | 1880 : BaseChannel(worker_thread, |
| 1894 network_thread, | 1881 network_thread, |
| 1882 signaling_thread, | |
| 1895 media_channel, | 1883 media_channel, |
| 1896 transport_controller, | |
| 1897 content_name, | 1884 content_name, |
| 1898 rtcp, | 1885 rtcp, |
| 1899 srtp_required) {} | 1886 srtp_required) {} |
| 1900 | 1887 |
| 1901 bool VideoChannel::Init_w(const std::string* bundle_transport_name) { | 1888 bool VideoChannel::Init_w(TransportChannel* rtp_transport, |
| 1902 if (!BaseChannel::Init_w(bundle_transport_name)) { | 1889 TransportChannel* rtcp_transport) { |
| 1903 return false; | 1890 return BaseChannel::Init_w(rtp_transport, rtcp_transport); |
| 1904 } | |
| 1905 return true; | |
| 1906 } | 1891 } |
| 1907 | 1892 |
| 1908 VideoChannel::~VideoChannel() { | 1893 VideoChannel::~VideoChannel() { |
| 1909 TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel"); | 1894 TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel"); |
| 1910 StopMediaMonitor(); | 1895 StopMediaMonitor(); |
| 1911 // this can't be done in the base class, since it calls a virtual | 1896 // this can't be done in the base class, since it calls a virtual |
| 1912 DisableMedia_w(); | 1897 DisableMedia_w(); |
| 1913 | 1898 |
| 1914 Deinit(); | 1899 Deinit(); |
| 1915 } | 1900 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2141 SignalMediaMonitor(this, info); | 2126 SignalMediaMonitor(this, info); |
| 2142 } | 2127 } |
| 2143 | 2128 |
| 2144 void VideoChannel::GetSrtpCryptoSuites_n( | 2129 void VideoChannel::GetSrtpCryptoSuites_n( |
| 2145 std::vector<int>* crypto_suites) const { | 2130 std::vector<int>* crypto_suites) const { |
| 2146 GetSupportedVideoCryptoSuites(crypto_options(), crypto_suites); | 2131 GetSupportedVideoCryptoSuites(crypto_options(), crypto_suites); |
| 2147 } | 2132 } |
| 2148 | 2133 |
| 2149 RtpDataChannel::RtpDataChannel(rtc::Thread* worker_thread, | 2134 RtpDataChannel::RtpDataChannel(rtc::Thread* worker_thread, |
| 2150 rtc::Thread* network_thread, | 2135 rtc::Thread* network_thread, |
| 2136 rtc::Thread* signaling_thread, | |
| 2151 DataMediaChannel* media_channel, | 2137 DataMediaChannel* media_channel, |
| 2152 TransportController* transport_controller, | |
| 2153 const std::string& content_name, | 2138 const std::string& content_name, |
| 2154 bool rtcp, | 2139 bool rtcp, |
| 2155 bool srtp_required) | 2140 bool srtp_required) |
| 2156 : BaseChannel(worker_thread, | 2141 : BaseChannel(worker_thread, |
| 2157 network_thread, | 2142 network_thread, |
| 2143 signaling_thread, | |
| 2158 media_channel, | 2144 media_channel, |
| 2159 transport_controller, | |
| 2160 content_name, | 2145 content_name, |
| 2161 rtcp, | 2146 rtcp, |
| 2162 srtp_required) {} | 2147 srtp_required) {} |
| 2163 | 2148 |
| 2164 RtpDataChannel::~RtpDataChannel() { | 2149 RtpDataChannel::~RtpDataChannel() { |
| 2165 TRACE_EVENT0("webrtc", "RtpDataChannel::~RtpDataChannel"); | 2150 TRACE_EVENT0("webrtc", "RtpDataChannel::~RtpDataChannel"); |
| 2166 StopMediaMonitor(); | 2151 StopMediaMonitor(); |
| 2167 // this can't be done in the base class, since it calls a virtual | 2152 // this can't be done in the base class, since it calls a virtual |
| 2168 DisableMedia_w(); | 2153 DisableMedia_w(); |
| 2169 | 2154 |
| 2170 Deinit(); | 2155 Deinit(); |
| 2171 } | 2156 } |
| 2172 | 2157 |
| 2173 bool RtpDataChannel::Init_w(const std::string* bundle_transport_name) { | 2158 bool RtpDataChannel::Init_w(TransportChannel* rtp_transport, |
| 2174 if (!BaseChannel::Init_w(bundle_transport_name)) { | 2159 TransportChannel* rtcp_transport) { |
| 2160 if (!BaseChannel::Init_w(rtp_transport, rtcp_transport)) { | |
| 2175 return false; | 2161 return false; |
| 2176 } | 2162 } |
| 2177 media_channel()->SignalDataReceived.connect(this, | 2163 media_channel()->SignalDataReceived.connect(this, |
| 2178 &RtpDataChannel::OnDataReceived); | 2164 &RtpDataChannel::OnDataReceived); |
| 2179 media_channel()->SignalReadyToSend.connect( | 2165 media_channel()->SignalReadyToSend.connect( |
| 2180 this, &RtpDataChannel::OnDataChannelReadyToSend); | 2166 this, &RtpDataChannel::OnDataChannelReadyToSend); |
| 2181 return true; | 2167 return true; |
| 2182 } | 2168 } |
| 2183 | 2169 |
| 2184 bool RtpDataChannel::SendData(const SendDataParams& params, | 2170 bool RtpDataChannel::SendData(const SendDataParams& params, |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2410 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, | 2396 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, |
| 2411 new DataChannelReadyToSendMessageData(writable)); | 2397 new DataChannelReadyToSendMessageData(writable)); |
| 2412 } | 2398 } |
| 2413 | 2399 |
| 2414 void RtpDataChannel::GetSrtpCryptoSuites_n( | 2400 void RtpDataChannel::GetSrtpCryptoSuites_n( |
| 2415 std::vector<int>* crypto_suites) const { | 2401 std::vector<int>* crypto_suites) const { |
| 2416 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); | 2402 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); |
| 2417 } | 2403 } |
| 2418 | 2404 |
| 2419 } // namespace cricket | 2405 } // namespace cricket |
| OLD | NEW |