| Index: talk/session/media/channel.cc
|
| diff --git a/talk/session/media/channel.cc b/talk/session/media/channel.cc
|
| index 7b5809855f632f4db59876a6d6e05142548254eb..294681ef1449aa94033112e8e5315cec5048a0f7 100644
|
| --- a/talk/session/media/channel.cc
|
| +++ b/talk/session/media/channel.cc
|
| @@ -170,17 +170,15 @@
|
| }
|
|
|
| BaseChannel::BaseChannel(rtc::Thread* thread,
|
| - MediaChannel* media_channel,
|
| - TransportController* transport_controller,
|
| - const std::string& content_name,
|
| - bool rtcp)
|
| + MediaChannel* media_channel, BaseSession* session,
|
| + const std::string& content_name, bool rtcp)
|
| : worker_thread_(thread),
|
| - transport_controller_(transport_controller),
|
| + session_(session),
|
| media_channel_(media_channel),
|
| content_name_(content_name),
|
| - rtcp_transport_enabled_(rtcp),
|
| - transport_channel_(nullptr),
|
| - rtcp_transport_channel_(nullptr),
|
| + rtcp_(rtcp),
|
| + transport_channel_(NULL),
|
| + rtcp_transport_channel_(NULL),
|
| enabled_(false),
|
| writable_(false),
|
| rtp_ready_to_send_(false),
|
| @@ -206,31 +204,20 @@
|
| // the media channel may try to send on the dead transport channel. NULLing
|
| // is not an effective strategy since the sends will come on another thread.
|
| delete media_channel_;
|
| - // Note that we don't just call set_transport_channel(nullptr) because that
|
| - // would call a pure virtual method which we can't do from a destructor.
|
| - if (transport_channel_) {
|
| - DisconnectFromTransportChannel(transport_channel_);
|
| - transport_controller_->DestroyTransportChannel_w(
|
| - transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP);
|
| - }
|
| - if (rtcp_transport_channel_) {
|
| - DisconnectFromTransportChannel(rtcp_transport_channel_);
|
| - transport_controller_->DestroyTransportChannel_w(
|
| - transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
|
| - }
|
| + set_transport_channel(nullptr);
|
| + set_rtcp_transport_channel(nullptr);
|
| LOG(LS_INFO) << "Destroyed channel";
|
| }
|
|
|
| bool BaseChannel::Init() {
|
| - if (!SetTransport(content_name())) {
|
| + if (!SetTransportChannels(session(), rtcp())) {
|
| return false;
|
| }
|
|
|
| if (!SetDtlsSrtpCiphers(transport_channel(), false)) {
|
| return false;
|
| }
|
| - if (rtcp_transport_enabled() &&
|
| - !SetDtlsSrtpCiphers(rtcp_transport_channel(), true)) {
|
| + if (rtcp() && !SetDtlsSrtpCiphers(rtcp_transport_channel(), true)) {
|
| return false;
|
| }
|
|
|
| @@ -244,35 +231,29 @@
|
| media_channel_->SetInterface(NULL);
|
| }
|
|
|
| -bool BaseChannel::SetTransport(const std::string& transport_name) {
|
| - return worker_thread_->Invoke<bool>(
|
| - Bind(&BaseChannel::SetTransport_w, this, transport_name));
|
| -}
|
| -
|
| -bool BaseChannel::SetTransport_w(const std::string& transport_name) {
|
| +bool BaseChannel::SetTransportChannels(BaseSession* session, bool rtcp) {
|
| + return worker_thread_->Invoke<bool>(Bind(
|
| + &BaseChannel::SetTransportChannels_w, this, session, rtcp));
|
| +}
|
| +
|
| +bool BaseChannel::SetTransportChannels_w(BaseSession* session, bool rtcp) {
|
| ASSERT(worker_thread_ == rtc::Thread::Current());
|
|
|
| - if (transport_name == transport_name_) {
|
| - // Nothing to do if transport name isn't changing
|
| - return true;
|
| - }
|
| -
|
| - set_transport_channel(transport_controller_->CreateTransportChannel_w(
|
| - transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP));
|
| + set_transport_channel(session->CreateChannel(
|
| + content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP));
|
| if (!transport_channel()) {
|
| return false;
|
| }
|
| - if (rtcp_transport_enabled()) {
|
| - LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name()
|
| - << " on " << transport_name << " transport ";
|
| - set_rtcp_transport_channel(transport_controller_->CreateTransportChannel_w(
|
| - transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP));
|
| + if (rtcp) {
|
| + set_rtcp_transport_channel(session->CreateChannel(
|
| + content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP));
|
| if (!rtcp_transport_channel()) {
|
| return false;
|
| }
|
| - }
|
| -
|
| - transport_name_ = transport_name;
|
| + } else {
|
| + set_rtcp_transport_channel(nullptr);
|
| + }
|
| +
|
| return true;
|
| }
|
|
|
| @@ -280,62 +261,42 @@
|
| ASSERT(worker_thread_ == rtc::Thread::Current());
|
|
|
| TransportChannel* old_tc = transport_channel_;
|
| - if (!old_tc && !new_tc) {
|
| - // Nothing to do
|
| +
|
| + if (old_tc == new_tc) {
|
| return;
|
| }
|
| - ASSERT(old_tc != new_tc);
|
| -
|
| if (old_tc) {
|
| DisconnectFromTransportChannel(old_tc);
|
| - transport_controller_->DestroyTransportChannel_w(
|
| - transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP);
|
| + session()->DestroyChannel(
|
| + content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP);
|
| }
|
|
|
| transport_channel_ = new_tc;
|
|
|
| if (new_tc) {
|
| ConnectToTransportChannel(new_tc);
|
| - for (const auto& pair : socket_options_) {
|
| - new_tc->SetOption(pair.first, pair.second);
|
| - }
|
| - }
|
| -
|
| - // Update aggregate writable/ready-to-send state between RTP and RTCP upon
|
| - // setting new channel
|
| - UpdateWritableState_w();
|
| - SetReadyToSend(false, new_tc && new_tc->writable());
|
| + }
|
| }
|
|
|
| void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc) {
|
| ASSERT(worker_thread_ == rtc::Thread::Current());
|
|
|
| TransportChannel* old_tc = rtcp_transport_channel_;
|
| - if (!old_tc && !new_tc) {
|
| - // Nothing to do
|
| +
|
| + if (old_tc == new_tc) {
|
| return;
|
| }
|
| - ASSERT(old_tc != new_tc);
|
| -
|
| if (old_tc) {
|
| DisconnectFromTransportChannel(old_tc);
|
| - transport_controller_->DestroyTransportChannel_w(
|
| - transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
|
| + session()->DestroyChannel(
|
| + content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP);
|
| }
|
|
|
| rtcp_transport_channel_ = new_tc;
|
|
|
| if (new_tc) {
|
| ConnectToTransportChannel(new_tc);
|
| - for (const auto& pair : rtcp_socket_options_) {
|
| - new_tc->SetOption(pair.first, pair.second);
|
| - }
|
| - }
|
| -
|
| - // Update aggregate writable/ready-to-send state between RTP and RTCP upon
|
| - // setting new channel
|
| - UpdateWritableState_w();
|
| - SetReadyToSend(true, new_tc && new_tc->writable());
|
| + }
|
| }
|
|
|
| void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) {
|
| @@ -446,13 +407,9 @@
|
| switch (type) {
|
| case ST_RTP:
|
| channel = transport_channel_;
|
| - socket_options_.push_back(
|
| - std::pair<rtc::Socket::Option, int>(opt, value));
|
| break;
|
| case ST_RTCP:
|
| channel = rtcp_transport_channel_;
|
| - rtcp_socket_options_.push_back(
|
| - std::pair<rtc::Socket::Option, int>(opt, value));
|
| break;
|
| }
|
| return channel ? channel->SetOption(opt, value) : -1;
|
| @@ -460,7 +417,12 @@
|
|
|
| void BaseChannel::OnWritableState(TransportChannel* channel) {
|
| ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_);
|
| - UpdateWritableState_w();
|
| + if (transport_channel_->writable()
|
| + && (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) {
|
| + ChannelWritable_w();
|
| + } else {
|
| + ChannelNotWritable_w();
|
| + }
|
| }
|
|
|
| void BaseChannel::OnChannelRead(TransportChannel* channel,
|
| @@ -478,25 +440,26 @@
|
| }
|
|
|
| void BaseChannel::OnReadyToSend(TransportChannel* channel) {
|
| + SetReadyToSend(channel, true);
|
| +}
|
| +
|
| +void BaseChannel::SetReadyToSend(TransportChannel* channel, bool ready) {
|
| ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_);
|
| - SetReadyToSend(channel == rtcp_transport_channel_, true);
|
| -}
|
| -
|
| -void BaseChannel::SetReadyToSend(bool rtcp, bool ready) {
|
| - if (rtcp) {
|
| + if (channel == transport_channel_) {
|
| + rtp_ready_to_send_ = ready;
|
| + }
|
| + if (channel == rtcp_transport_channel_) {
|
| rtcp_ready_to_send_ = ready;
|
| - } else {
|
| - rtp_ready_to_send_ = ready;
|
| - }
|
| -
|
| - if (rtp_ready_to_send_ &&
|
| - // In the case of rtcp mux |rtcp_transport_channel_| will be null.
|
| - (rtcp_ready_to_send_ || !rtcp_transport_channel_)) {
|
| + }
|
| +
|
| + if (!ready) {
|
| + // Notify the MediaChannel when either rtp or rtcp channel can't send.
|
| + media_channel_->OnReadyToSend(false);
|
| + } else if (rtp_ready_to_send_ &&
|
| + // In the case of rtcp mux |rtcp_transport_channel_| will be null.
|
| + (rtcp_ready_to_send_ || !rtcp_transport_channel_)) {
|
| // Notify the MediaChannel when both rtp and rtcp channel can send.
|
| media_channel_->OnReadyToSend(true);
|
| - } else {
|
| - // Notify the MediaChannel when either rtp or rtcp channel can't send.
|
| - media_channel_->OnReadyToSend(false);
|
| }
|
| }
|
|
|
| @@ -618,7 +581,7 @@
|
| if (ret != static_cast<int>(packet->size())) {
|
| if (channel->GetError() == EWOULDBLOCK) {
|
| LOG(LS_WARNING) << "Got EWOULDBLOCK from socket.";
|
| - SetReadyToSend(rtcp, false);
|
| + SetReadyToSend(channel, false);
|
| }
|
| return false;
|
| }
|
| @@ -752,21 +715,14 @@
|
| ChangeState();
|
| }
|
|
|
| -void BaseChannel::UpdateWritableState_w() {
|
| - if (transport_channel_ && transport_channel_->writable() &&
|
| - (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) {
|
| - ChannelWritable_w();
|
| - } else {
|
| - ChannelNotWritable_w();
|
| - }
|
| -}
|
| -
|
| void BaseChannel::ChannelWritable_w() {
|
| ASSERT(worker_thread_ == rtc::Thread::Current());
|
| if (writable_)
|
| return;
|
|
|
| - LOG(LS_INFO) << "Channel writable (" << content_name_ << ")"
|
| + LOG(LS_INFO) << "Channel socket writable ("
|
| + << transport_channel_->content_name() << ", "
|
| + << transport_channel_->component() << ")"
|
| << (was_ever_writable_ ? "" : " for the first time");
|
|
|
| std::vector<ConnectionInfo> infos;
|
| @@ -783,13 +739,13 @@
|
| // If we're doing DTLS-SRTP, now is the time.
|
| if (!was_ever_writable_ && ShouldSetupDtlsSrtp()) {
|
| if (!SetupDtlsSrtp(false)) {
|
| - SignalDtlsSetupFailure_w(false);
|
| + SignalDtlsSetupFailure(this, false);
|
| return;
|
| }
|
|
|
| if (rtcp_transport_channel_) {
|
| if (!SetupDtlsSrtp(true)) {
|
| - SignalDtlsSetupFailure_w(true);
|
| + SignalDtlsSetupFailure(this, true);
|
| return;
|
| }
|
| }
|
| @@ -832,8 +788,8 @@
|
| bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) {
|
| bool ret = false;
|
|
|
| - TransportChannel* channel =
|
| - rtcp_channel ? rtcp_transport_channel_ : transport_channel_;
|
| + TransportChannel *channel = rtcp_channel ?
|
| + rtcp_transport_channel_ : transport_channel_;
|
|
|
| // No DTLS
|
| if (!channel->IsDtlsActive())
|
| @@ -928,7 +884,9 @@
|
| if (!writable_)
|
| return;
|
|
|
| - LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")";
|
| + LOG(LS_INFO) << "Channel socket not writable ("
|
| + << transport_channel_->content_name() << ", "
|
| + << transport_channel_->component() << ")";
|
| writable_ = false;
|
| ChangeState();
|
| }
|
| @@ -1027,8 +985,7 @@
|
| void BaseChannel::ActivateRtcpMux_w() {
|
| if (!rtcp_mux_filter_.IsActive()) {
|
| rtcp_mux_filter_.SetActive();
|
| - set_rtcp_transport_channel(nullptr);
|
| - rtcp_transport_enabled_ = false;
|
| + set_rtcp_transport_channel(NULL);
|
| }
|
| }
|
|
|
| @@ -1047,11 +1004,7 @@
|
| ret = rtcp_mux_filter_.SetAnswer(enable, src);
|
| if (ret && rtcp_mux_filter_.IsActive()) {
|
| // We activated RTCP mux, close down the RTCP transport.
|
| - LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name()
|
| - << " by destroying RTCP transport channel for "
|
| - << transport_name();
|
| - set_rtcp_transport_channel(nullptr);
|
| - rtcp_transport_enabled_ = false;
|
| + set_rtcp_transport_channel(NULL);
|
| }
|
| break;
|
| case CA_UPDATE:
|
| @@ -1278,16 +1231,14 @@
|
| VoiceChannel::VoiceChannel(rtc::Thread* thread,
|
| MediaEngineInterface* media_engine,
|
| VoiceMediaChannel* media_channel,
|
| - TransportController* transport_controller,
|
| + BaseSession* session,
|
| const std::string& content_name,
|
| bool rtcp)
|
| - : BaseChannel(thread,
|
| - media_channel,
|
| - transport_controller,
|
| - content_name,
|
| + : BaseChannel(thread, media_channel, session, content_name,
|
| rtcp),
|
| media_engine_(media_engine),
|
| - received_media_(false) {}
|
| + received_media_(false) {
|
| +}
|
|
|
| VoiceChannel::~VoiceChannel() {
|
| StopAudioMonitor();
|
| @@ -1313,12 +1264,11 @@
|
| media_channel(), ssrc, renderer));
|
| }
|
|
|
| -bool VoiceChannel::SetAudioSend(uint32 ssrc,
|
| - bool mute,
|
| +bool VoiceChannel::SetAudioSend(uint32 ssrc, bool mute,
|
| const AudioOptions* options,
|
| AudioRenderer* renderer) {
|
| - return InvokeOnWorker(Bind(&VoiceMediaChannel::SetAudioSend, media_channel(),
|
| - ssrc, mute, options, renderer));
|
| + return InvokeOnWorker(Bind(&VoiceMediaChannel::SetAudioSend,
|
| + media_channel(), ssrc, mute, options, renderer));
|
| }
|
|
|
| bool VoiceChannel::SetRingbackTone(const void* buf, int len) {
|
| @@ -1657,16 +1607,14 @@
|
|
|
| VideoChannel::VideoChannel(rtc::Thread* thread,
|
| VideoMediaChannel* media_channel,
|
| - TransportController* transport_controller,
|
| + BaseSession* session,
|
| const std::string& content_name,
|
| bool rtcp)
|
| - : BaseChannel(thread,
|
| - media_channel,
|
| - transport_controller,
|
| - content_name,
|
| + : BaseChannel(thread, media_channel, session, content_name,
|
| rtcp),
|
| renderer_(NULL),
|
| - previous_we_(rtc::WE_CLOSE) {}
|
| + previous_we_(rtc::WE_CLOSE) {
|
| +}
|
|
|
| bool VideoChannel::Init() {
|
| if (!BaseChannel::Init()) {
|
| @@ -1759,11 +1707,10 @@
|
| return true;
|
| }
|
|
|
| -bool VideoChannel::SetVideoSend(uint32 ssrc,
|
| - bool mute,
|
| +bool VideoChannel::SetVideoSend(uint32 ssrc, bool mute,
|
| const VideoOptions* options) {
|
| - return InvokeOnWorker(Bind(&VideoMediaChannel::SetVideoSend, media_channel(),
|
| - ssrc, mute, options));
|
| + return InvokeOnWorker(Bind(&VideoMediaChannel::SetVideoSend,
|
| + media_channel(), ssrc, mute, options));
|
| }
|
|
|
| void VideoChannel::ChangeState() {
|
| @@ -2098,16 +2045,13 @@
|
|
|
| DataChannel::DataChannel(rtc::Thread* thread,
|
| DataMediaChannel* media_channel,
|
| - TransportController* transport_controller,
|
| + BaseSession* session,
|
| const std::string& content_name,
|
| bool rtcp)
|
| - : BaseChannel(thread,
|
| - media_channel,
|
| - transport_controller,
|
| - content_name,
|
| - rtcp),
|
| + : BaseChannel(thread, media_channel, session, content_name, rtcp),
|
| data_channel_type_(cricket::DCT_NONE),
|
| - ready_to_send_data_(false) {}
|
| + ready_to_send_data_(false) {
|
| +}
|
|
|
| DataChannel::~DataChannel() {
|
| StopMediaMonitor();
|
|
|