henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2004 Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 28 | #include <utility> |
| 29 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 30 | #include "talk/session/media/channel.h" |
| 31 | |
buildbot@webrtc.org | 5b1ebac | 2014-08-07 17:18:00 +0000 | [diff] [blame] | 32 | #include "talk/media/base/constants.h" |
| 33 | #include "talk/media/base/rtputils.h" |
buildbot@webrtc.org | 5b1ebac | 2014-08-07 17:18:00 +0000 | [diff] [blame] | 34 | #include "talk/session/media/channelmanager.h" |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 35 | #include "webrtc/audio/audio_sink.h" |
buildbot@webrtc.org | 65b98d1 | 2014-08-07 22:09:08 +0000 | [diff] [blame] | 36 | #include "webrtc/base/bind.h" |
| 37 | #include "webrtc/base/buffer.h" |
| 38 | #include "webrtc/base/byteorder.h" |
| 39 | #include "webrtc/base/common.h" |
| 40 | #include "webrtc/base/dscp.h" |
| 41 | #include "webrtc/base/logging.h" |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 42 | #include "webrtc/base/trace_event.h" |
| 43 | #include "webrtc/p2p/base/transportchannel.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | |
| 45 | namespace cricket { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 46 | using rtc::Bind; |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 47 | |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 48 | namespace { |
| 49 | // See comment below for why we need to use a pointer to a scoped_ptr. |
| 50 | bool SetRawAudioSink_w(VoiceMediaChannel* channel, |
| 51 | uint32_t ssrc, |
| 52 | rtc::scoped_ptr<webrtc::AudioSinkInterface>* sink) { |
| 53 | channel->SetRawAudioSink(ssrc, std::move(*sink)); |
| 54 | return true; |
| 55 | } |
| 56 | } // namespace |
| 57 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | enum { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 59 | MSG_EARLYMEDIATIMEOUT = 1, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 60 | MSG_SCREENCASTWINDOWEVENT, |
| 61 | MSG_RTPPACKET, |
| 62 | MSG_RTCPPACKET, |
| 63 | MSG_CHANNEL_ERROR, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 64 | MSG_READYTOSENDDATA, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | MSG_DATARECEIVED, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | MSG_FIRSTPACKETRECEIVED, |
buildbot@webrtc.org | 1d66be2 | 2014-05-29 22:54:24 +0000 | [diff] [blame] | 67 | MSG_STREAMCLOSEDREMOTELY, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | // Value specified in RFC 5764. |
| 71 | static const char kDtlsSrtpExporterLabel[] = "EXTRACTOR-dtls_srtp"; |
| 72 | |
| 73 | static const int kAgcMinus10db = -10; |
| 74 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 75 | static void SafeSetError(const std::string& message, std::string* error_desc) { |
| 76 | if (error_desc) { |
| 77 | *error_desc = message; |
| 78 | } |
| 79 | } |
| 80 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 81 | struct PacketMessageData : public rtc::MessageData { |
| 82 | rtc::Buffer packet; |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 83 | rtc::PacketOptions options; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 86 | struct ScreencastEventMessageData : public rtc::MessageData { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 87 | ScreencastEventMessageData(uint32_t s, rtc::WindowEvent we) |
| 88 | : ssrc(s), event(we) {} |
| 89 | uint32_t ssrc; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 90 | rtc::WindowEvent event; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 93 | struct VoiceChannelErrorMessageData : public rtc::MessageData { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 94 | VoiceChannelErrorMessageData(uint32_t in_ssrc, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | VoiceMediaChannel::Error in_error) |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 96 | : ssrc(in_ssrc), error(in_error) {} |
| 97 | uint32_t ssrc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 98 | VoiceMediaChannel::Error error; |
| 99 | }; |
| 100 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 101 | struct VideoChannelErrorMessageData : public rtc::MessageData { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 102 | VideoChannelErrorMessageData(uint32_t in_ssrc, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 103 | VideoMediaChannel::Error in_error) |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 104 | : ssrc(in_ssrc), error(in_error) {} |
| 105 | uint32_t ssrc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 106 | VideoMediaChannel::Error error; |
| 107 | }; |
| 108 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 109 | struct DataChannelErrorMessageData : public rtc::MessageData { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 110 | DataChannelErrorMessageData(uint32_t in_ssrc, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 111 | DataMediaChannel::Error in_error) |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 112 | : ssrc(in_ssrc), error(in_error) {} |
| 113 | uint32_t ssrc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 114 | DataMediaChannel::Error error; |
| 115 | }; |
| 116 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 117 | |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 118 | struct VideoChannel::ScreencastDetailsData { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 119 | explicit ScreencastDetailsData(uint32_t s) |
| 120 | : ssrc(s), fps(0), screencast_max_pixels(0) {} |
| 121 | uint32_t ssrc; |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 122 | int fps; |
| 123 | int screencast_max_pixels; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 126 | static const char* PacketType(bool rtcp) { |
| 127 | return (!rtcp) ? "RTP" : "RTCP"; |
| 128 | } |
| 129 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 130 | static bool ValidPacket(bool rtcp, const rtc::Buffer* packet) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 131 | // Check the packet size. We could check the header too if needed. |
| 132 | return (packet && |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 133 | packet->size() >= (!rtcp ? kMinRtpPacketLen : kMinRtcpPacketLen) && |
| 134 | packet->size() <= kMaxRtpPacketLen); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static bool IsReceiveContentDirection(MediaContentDirection direction) { |
| 138 | return direction == MD_SENDRECV || direction == MD_RECVONLY; |
| 139 | } |
| 140 | |
| 141 | static bool IsSendContentDirection(MediaContentDirection direction) { |
| 142 | return direction == MD_SENDRECV || direction == MD_SENDONLY; |
| 143 | } |
| 144 | |
| 145 | static const MediaContentDescription* GetContentDescription( |
| 146 | const ContentInfo* cinfo) { |
| 147 | if (cinfo == NULL) |
| 148 | return NULL; |
| 149 | return static_cast<const MediaContentDescription*>(cinfo->description); |
| 150 | } |
| 151 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 152 | template <class Codec> |
| 153 | void RtpParametersFromMediaDescription( |
| 154 | const MediaContentDescriptionImpl<Codec>* desc, |
| 155 | RtpParameters<Codec>* params) { |
| 156 | // TODO(pthatcher): Remove this once we're sure no one will give us |
| 157 | // a description without codecs (currently a CA_UPDATE with just |
| 158 | // streams can). |
| 159 | if (desc->has_codecs()) { |
| 160 | params->codecs = desc->codecs(); |
| 161 | } |
| 162 | // TODO(pthatcher): See if we really need |
| 163 | // rtp_header_extensions_set() and remove it if we don't. |
| 164 | if (desc->rtp_header_extensions_set()) { |
| 165 | params->extensions = desc->rtp_header_extensions(); |
| 166 | } |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 167 | params->rtcp.reduced_size = desc->rtcp_reduced_size(); |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | template <class Codec, class Options> |
| 171 | void RtpSendParametersFromMediaDescription( |
| 172 | const MediaContentDescriptionImpl<Codec>* desc, |
| 173 | RtpSendParameters<Codec, Options>* send_params) { |
| 174 | RtpParametersFromMediaDescription(desc, send_params); |
| 175 | send_params->max_bandwidth_bps = desc->bandwidth(); |
| 176 | } |
| 177 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 178 | BaseChannel::BaseChannel(rtc::Thread* thread, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 179 | MediaChannel* media_channel, |
| 180 | TransportController* transport_controller, |
| 181 | const std::string& content_name, |
| 182 | bool rtcp) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 183 | : worker_thread_(thread), |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 184 | transport_controller_(transport_controller), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 185 | media_channel_(media_channel), |
| 186 | content_name_(content_name), |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 187 | rtcp_transport_enabled_(rtcp), |
| 188 | transport_channel_(nullptr), |
| 189 | rtcp_transport_channel_(nullptr), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 190 | enabled_(false), |
| 191 | writable_(false), |
| 192 | rtp_ready_to_send_(false), |
| 193 | rtcp_ready_to_send_(false), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 194 | was_ever_writable_(false), |
| 195 | local_content_direction_(MD_INACTIVE), |
| 196 | remote_content_direction_(MD_INACTIVE), |
| 197 | has_received_packet_(false), |
| 198 | dtls_keyed_(false), |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 199 | secure_required_(false), |
| 200 | rtp_abs_sendtime_extn_id_(-1) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 201 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 202 | LOG(LS_INFO) << "Created channel for " << content_name; |
| 203 | } |
| 204 | |
| 205 | BaseChannel::~BaseChannel() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 206 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 207 | Deinit(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 208 | StopConnectionMonitor(); |
| 209 | FlushRtcpMessages(); // Send any outstanding RTCP packets. |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 210 | worker_thread_->Clear(this); // eats any outstanding messages or packets |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 211 | // We must destroy the media channel before the transport channel, otherwise |
| 212 | // the media channel may try to send on the dead transport channel. NULLing |
| 213 | // is not an effective strategy since the sends will come on another thread. |
| 214 | delete media_channel_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 215 | // Note that we don't just call set_transport_channel(nullptr) because that |
| 216 | // would call a pure virtual method which we can't do from a destructor. |
| 217 | if (transport_channel_) { |
| 218 | DisconnectFromTransportChannel(transport_channel_); |
| 219 | transport_controller_->DestroyTransportChannel_w( |
| 220 | transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
| 221 | } |
| 222 | if (rtcp_transport_channel_) { |
| 223 | DisconnectFromTransportChannel(rtcp_transport_channel_); |
| 224 | transport_controller_->DestroyTransportChannel_w( |
| 225 | transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
| 226 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 227 | LOG(LS_INFO) << "Destroyed channel"; |
| 228 | } |
| 229 | |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 230 | bool BaseChannel::Init() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 231 | if (!SetTransport(content_name())) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 232 | return false; |
| 233 | } |
| 234 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 235 | if (!SetDtlsSrtpCryptoSuites(transport_channel(), false)) { |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 236 | return false; |
| 237 | } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 238 | if (rtcp_transport_enabled() && |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 239 | !SetDtlsSrtpCryptoSuites(rtcp_transport_channel(), true)) { |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 240 | return false; |
| 241 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 242 | |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 243 | // Both RTP and RTCP channels are set, we can call SetInterface on |
| 244 | // media channel and it can set network options. |
| 245 | media_channel_->SetInterface(this); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 246 | return true; |
| 247 | } |
| 248 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 249 | void BaseChannel::Deinit() { |
| 250 | media_channel_->SetInterface(NULL); |
| 251 | } |
| 252 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 253 | bool BaseChannel::SetTransport(const std::string& transport_name) { |
| 254 | return worker_thread_->Invoke<bool>( |
| 255 | Bind(&BaseChannel::SetTransport_w, this, transport_name)); |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 256 | } |
| 257 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 258 | bool BaseChannel::SetTransport_w(const std::string& transport_name) { |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 259 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 260 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 261 | if (transport_name == transport_name_) { |
| 262 | // Nothing to do if transport name isn't changing |
| 263 | return true; |
| 264 | } |
| 265 | |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 266 | // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport |
| 267 | // changes and wait until the DTLS handshake is complete to set the newly |
| 268 | // negotiated parameters. |
| 269 | if (ShouldSetupDtlsSrtp()) { |
guoweis | 4638331 | 2015-12-17 16:45:59 -0800 | [diff] [blame^] | 270 | // Set |writable_| to false such that UpdateWritableState_w can set up |
| 271 | // DTLS-SRTP when the writable_ becomes true again. |
| 272 | writable_ = false; |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 273 | srtp_filter_.ResetParams(); |
| 274 | } |
| 275 | |
guoweis | 4638331 | 2015-12-17 16:45:59 -0800 | [diff] [blame^] | 276 | // TODO(guoweis): Remove this grossness when we remove non-muxed RTCP. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 277 | if (rtcp_transport_enabled()) { |
| 278 | LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name() |
| 279 | << " on " << transport_name << " transport "; |
guoweis | 4638331 | 2015-12-17 16:45:59 -0800 | [diff] [blame^] | 280 | set_rtcp_transport_channel( |
| 281 | transport_controller_->CreateTransportChannel_w( |
| 282 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP), |
| 283 | false /* update_writablity */); |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 284 | if (!rtcp_transport_channel()) { |
| 285 | return false; |
| 286 | } |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 287 | } |
| 288 | |
guoweis | 4638331 | 2015-12-17 16:45:59 -0800 | [diff] [blame^] | 289 | // We're not updating the writablity during the transition state. |
| 290 | set_transport_channel(transport_controller_->CreateTransportChannel_w( |
| 291 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 292 | if (!transport_channel()) { |
| 293 | return false; |
| 294 | } |
| 295 | |
| 296 | // TODO(guoweis): Remove this grossness when we remove non-muxed RTCP. |
| 297 | if (rtcp_transport_enabled()) { |
| 298 | // We can only update the RTCP ready to send after set_transport_channel has |
| 299 | // handled channel writability. |
| 300 | SetReadyToSend( |
| 301 | true, rtcp_transport_channel() && rtcp_transport_channel()->writable()); |
| 302 | } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 303 | transport_name_ = transport_name; |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 304 | return true; |
| 305 | } |
| 306 | |
| 307 | void BaseChannel::set_transport_channel(TransportChannel* new_tc) { |
| 308 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 309 | |
| 310 | TransportChannel* old_tc = transport_channel_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 311 | if (!old_tc && !new_tc) { |
| 312 | // Nothing to do |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 313 | return; |
| 314 | } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 315 | ASSERT(old_tc != new_tc); |
| 316 | |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 317 | if (old_tc) { |
| 318 | DisconnectFromTransportChannel(old_tc); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 319 | transport_controller_->DestroyTransportChannel_w( |
| 320 | transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | transport_channel_ = new_tc; |
| 324 | |
| 325 | if (new_tc) { |
| 326 | ConnectToTransportChannel(new_tc); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 327 | for (const auto& pair : socket_options_) { |
| 328 | new_tc->SetOption(pair.first, pair.second); |
| 329 | } |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 330 | } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 331 | |
| 332 | // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
| 333 | // setting new channel |
| 334 | UpdateWritableState_w(); |
| 335 | SetReadyToSend(false, new_tc && new_tc->writable()); |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 336 | } |
| 337 | |
guoweis | 4638331 | 2015-12-17 16:45:59 -0800 | [diff] [blame^] | 338 | void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc, |
| 339 | bool update_writablity) { |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 340 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 341 | |
| 342 | TransportChannel* old_tc = rtcp_transport_channel_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 343 | if (!old_tc && !new_tc) { |
| 344 | // Nothing to do |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 345 | return; |
| 346 | } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 347 | ASSERT(old_tc != new_tc); |
| 348 | |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 349 | if (old_tc) { |
| 350 | DisconnectFromTransportChannel(old_tc); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 351 | transport_controller_->DestroyTransportChannel_w( |
| 352 | transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | rtcp_transport_channel_ = new_tc; |
| 356 | |
| 357 | if (new_tc) { |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 358 | RTC_CHECK(!(ShouldSetupDtlsSrtp() && srtp_filter_.IsActive())) |
| 359 | << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " |
| 360 | << "should never happen."; |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 361 | ConnectToTransportChannel(new_tc); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 362 | for (const auto& pair : rtcp_socket_options_) { |
| 363 | new_tc->SetOption(pair.first, pair.second); |
| 364 | } |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 365 | } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 366 | |
guoweis | 4638331 | 2015-12-17 16:45:59 -0800 | [diff] [blame^] | 367 | if (update_writablity) { |
| 368 | // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
| 369 | // setting new channel |
| 370 | UpdateWritableState_w(); |
| 371 | SetReadyToSend(true, new_tc && new_tc->writable()); |
| 372 | } |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { |
| 376 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 377 | |
| 378 | tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |
| 379 | tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); |
| 380 | tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 381 | tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { |
| 385 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 386 | |
| 387 | tc->SignalWritableState.disconnect(this); |
| 388 | tc->SignalReadPacket.disconnect(this); |
| 389 | tc->SignalReadyToSend.disconnect(this); |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 390 | tc->SignalDtlsState.disconnect(this); |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 391 | } |
| 392 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 393 | bool BaseChannel::Enable(bool enable) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 394 | worker_thread_->Invoke<void>(Bind( |
| 395 | enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, |
| 396 | this)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 397 | return true; |
| 398 | } |
| 399 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 400 | bool BaseChannel::AddRecvStream(const StreamParams& sp) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 401 | return InvokeOnWorker(Bind(&BaseChannel::AddRecvStream_w, this, sp)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 402 | } |
| 403 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 404 | bool BaseChannel::RemoveRecvStream(uint32_t ssrc) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 405 | return InvokeOnWorker(Bind(&BaseChannel::RemoveRecvStream_w, this, ssrc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 406 | } |
| 407 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 408 | bool BaseChannel::AddSendStream(const StreamParams& sp) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 409 | return InvokeOnWorker( |
| 410 | Bind(&MediaChannel::AddSendStream, media_channel(), sp)); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 413 | bool BaseChannel::RemoveSendStream(uint32_t ssrc) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 414 | return InvokeOnWorker( |
| 415 | Bind(&MediaChannel::RemoveSendStream, media_channel(), ssrc)); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 416 | } |
| 417 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 418 | bool BaseChannel::SetLocalContent(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 419 | ContentAction action, |
| 420 | std::string* error_desc) { |
Peter Boström | 9f45a45 | 2015-12-08 13:25:57 +0100 | [diff] [blame] | 421 | TRACE_EVENT0("webrtc", "BaseChannel::SetLocalContent"); |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 422 | return InvokeOnWorker(Bind(&BaseChannel::SetLocalContent_w, |
| 423 | this, content, action, error_desc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | bool BaseChannel::SetRemoteContent(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 427 | ContentAction action, |
| 428 | std::string* error_desc) { |
Peter Boström | 9f45a45 | 2015-12-08 13:25:57 +0100 | [diff] [blame] | 429 | TRACE_EVENT0("webrtc", "BaseChannel::SetRemoteContent"); |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 430 | return InvokeOnWorker(Bind(&BaseChannel::SetRemoteContent_w, |
| 431 | this, content, action, error_desc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 432 | } |
| 433 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 434 | void BaseChannel::StartConnectionMonitor(int cms) { |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame] | 435 | // We pass in the BaseChannel instead of the transport_channel_ |
| 436 | // because if the transport_channel_ changes, the ConnectionMonitor |
| 437 | // would be pointing to the wrong TransportChannel. |
| 438 | connection_monitor_.reset(new ConnectionMonitor( |
| 439 | this, worker_thread(), rtc::Thread::Current())); |
| 440 | connection_monitor_->SignalUpdate.connect( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 441 | this, &BaseChannel::OnConnectionMonitorUpdate); |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame] | 442 | connection_monitor_->Start(cms); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | void BaseChannel::StopConnectionMonitor() { |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame] | 446 | if (connection_monitor_) { |
| 447 | connection_monitor_->Stop(); |
| 448 | connection_monitor_.reset(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame] | 452 | bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) { |
| 453 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 454 | return transport_channel_->GetStats(infos); |
| 455 | } |
| 456 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 457 | bool BaseChannel::IsReadyToReceive() const { |
| 458 | // Receive data if we are enabled and have local content, |
| 459 | return enabled() && IsReceiveContentDirection(local_content_direction_); |
| 460 | } |
| 461 | |
| 462 | bool BaseChannel::IsReadyToSend() const { |
| 463 | // Send outgoing data if we are enabled, have local and remote content, |
| 464 | // and we have had some form of connectivity. |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 465 | return enabled() && IsReceiveContentDirection(remote_content_direction_) && |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 466 | IsSendContentDirection(local_content_direction_) && |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 467 | was_ever_writable() && |
| 468 | (srtp_filter_.IsActive() || !ShouldSetupDtlsSrtp()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 469 | } |
| 470 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 471 | bool BaseChannel::SendPacket(rtc::Buffer* packet, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 472 | const rtc::PacketOptions& options) { |
| 473 | return SendPacket(false, packet, options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 474 | } |
| 475 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 476 | bool BaseChannel::SendRtcp(rtc::Buffer* packet, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 477 | const rtc::PacketOptions& options) { |
| 478 | return SendPacket(true, packet, options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 479 | } |
| 480 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 481 | int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 482 | int value) { |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 483 | TransportChannel* channel = NULL; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 484 | switch (type) { |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 485 | case ST_RTP: |
| 486 | channel = transport_channel_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 487 | socket_options_.push_back( |
| 488 | std::pair<rtc::Socket::Option, int>(opt, value)); |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 489 | break; |
| 490 | case ST_RTCP: |
| 491 | channel = rtcp_transport_channel_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 492 | rtcp_socket_options_.push_back( |
| 493 | std::pair<rtc::Socket::Option, int>(opt, value)); |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 494 | break; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 495 | } |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 496 | return channel ? channel->SetOption(opt, value) : -1; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | void BaseChannel::OnWritableState(TransportChannel* channel) { |
| 500 | ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 501 | UpdateWritableState_w(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | void BaseChannel::OnChannelRead(TransportChannel* channel, |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 505 | const char* data, size_t len, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 506 | const rtc::PacketTime& packet_time, |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 507 | int flags) { |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 508 | TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 509 | // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 510 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 511 | |
| 512 | // When using RTCP multiplexing we might get RTCP packets on the RTP |
| 513 | // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. |
| 514 | bool rtcp = PacketIsRtcp(channel, data, len); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 515 | rtc::Buffer packet(data, len); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 516 | HandlePacket(rtcp, &packet, packet_time); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | void BaseChannel::OnReadyToSend(TransportChannel* channel) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 520 | ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |
| 521 | SetReadyToSend(channel == rtcp_transport_channel_, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 522 | } |
| 523 | |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 524 | void BaseChannel::OnDtlsState(TransportChannel* channel, |
| 525 | DtlsTransportState state) { |
| 526 | if (!ShouldSetupDtlsSrtp()) { |
| 527 | return; |
| 528 | } |
| 529 | |
| 530 | // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED |
| 531 | // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to |
| 532 | // cover other scenarios like the whole channel is writable (not just this |
| 533 | // TransportChannel) or when TransportChannel is attached after DTLS is |
| 534 | // negotiated. |
| 535 | if (state != DTLS_TRANSPORT_CONNECTED) { |
| 536 | srtp_filter_.ResetParams(); |
| 537 | } |
| 538 | } |
| 539 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 540 | void BaseChannel::SetReadyToSend(bool rtcp, bool ready) { |
| 541 | if (rtcp) { |
| 542 | rtcp_ready_to_send_ = ready; |
| 543 | } else { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 544 | rtp_ready_to_send_ = ready; |
| 545 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 546 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 547 | if (rtp_ready_to_send_ && |
| 548 | // In the case of rtcp mux |rtcp_transport_channel_| will be null. |
| 549 | (rtcp_ready_to_send_ || !rtcp_transport_channel_)) { |
torbjorng | a81a42f | 2015-09-23 02:16:58 -0700 | [diff] [blame] | 550 | // Notify the MediaChannel when both rtp and rtcp channel can send. |
| 551 | media_channel_->OnReadyToSend(true); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 552 | } else { |
| 553 | // Notify the MediaChannel when either rtp or rtcp channel can't send. |
| 554 | media_channel_->OnReadyToSend(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | |
| 558 | bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, |
| 559 | const char* data, size_t len) { |
| 560 | return (channel == rtcp_transport_channel_ || |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 561 | rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 562 | } |
| 563 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 564 | bool BaseChannel::SendPacket(bool rtcp, |
| 565 | rtc::Buffer* packet, |
| 566 | const rtc::PacketOptions& options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 567 | // SendPacket gets called from MediaEngine, typically on an encoder thread. |
| 568 | // If the thread is not our worker thread, we will post to our worker |
| 569 | // so that the real work happens on our worker. This avoids us having to |
| 570 | // synchronize access to all the pieces of the send path, including |
| 571 | // SRTP and the inner workings of the transport channels. |
| 572 | // The only downside is that we can't return a proper failure code if |
| 573 | // needed. Since UDP is unreliable anyway, this should be a non-issue. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 574 | if (rtc::Thread::Current() != worker_thread_) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 575 | // Avoid a copy by transferring the ownership of the packet data. |
| 576 | int message_id = (!rtcp) ? MSG_RTPPACKET : MSG_RTCPPACKET; |
| 577 | PacketMessageData* data = new PacketMessageData; |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 578 | data->packet = std::move(*packet); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 579 | data->options = options; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 580 | worker_thread_->Post(this, message_id, data); |
| 581 | return true; |
| 582 | } |
| 583 | |
| 584 | // Now that we are on the correct thread, ensure we have a place to send this |
| 585 | // packet before doing anything. (We might get RTCP packets that we don't |
| 586 | // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP |
| 587 | // transport. |
| 588 | TransportChannel* channel = (!rtcp || rtcp_mux_filter_.IsActive()) ? |
| 589 | transport_channel_ : rtcp_transport_channel_; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 590 | if (!channel || !channel->writable()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 591 | return false; |
| 592 | } |
| 593 | |
| 594 | // Protect ourselves against crazy data. |
| 595 | if (!ValidPacket(rtcp, packet)) { |
| 596 | LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 597 | << PacketType(rtcp) |
| 598 | << " packet: wrong size=" << packet->size(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 599 | return false; |
| 600 | } |
| 601 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 602 | rtc::PacketOptions updated_options; |
| 603 | updated_options = options; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 604 | // Protect if needed. |
| 605 | if (srtp_filter_.IsActive()) { |
| 606 | bool res; |
Karl Wiberg | c56ac1e | 2015-05-04 14:54:55 +0200 | [diff] [blame] | 607 | uint8_t* data = packet->data(); |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 608 | int len = static_cast<int>(packet->size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 609 | if (!rtcp) { |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 610 | // If ENABLE_EXTERNAL_AUTH flag is on then packet authentication is not done |
| 611 | // inside libsrtp for a RTP packet. A external HMAC module will be writing |
| 612 | // a fake HMAC value. This is ONLY done for a RTP packet. |
| 613 | // Socket layer will update rtp sendtime extension header if present in |
| 614 | // packet with current time before updating the HMAC. |
| 615 | #if !defined(ENABLE_EXTERNAL_AUTH) |
| 616 | res = srtp_filter_.ProtectRtp( |
| 617 | data, len, static_cast<int>(packet->capacity()), &len); |
| 618 | #else |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 619 | updated_options.packet_time_params.rtp_sendtime_extension_id = |
henrike@webrtc.org | 0537634 | 2014-03-10 15:53:12 +0000 | [diff] [blame] | 620 | rtp_abs_sendtime_extn_id_; |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 621 | res = srtp_filter_.ProtectRtp( |
| 622 | data, len, static_cast<int>(packet->capacity()), &len, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 623 | &updated_options.packet_time_params.srtp_packet_index); |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 624 | // If protection succeeds, let's get auth params from srtp. |
| 625 | if (res) { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 626 | uint8_t* auth_key = NULL; |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 627 | int key_len; |
| 628 | res = srtp_filter_.GetRtpAuthParams( |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 629 | &auth_key, &key_len, |
| 630 | &updated_options.packet_time_params.srtp_auth_tag_len); |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 631 | if (res) { |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 632 | updated_options.packet_time_params.srtp_auth_key.resize(key_len); |
| 633 | updated_options.packet_time_params.srtp_auth_key.assign( |
| 634 | auth_key, auth_key + key_len); |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | #endif |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 638 | if (!res) { |
| 639 | int seq_num = -1; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 640 | uint32_t ssrc = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 641 | GetRtpSeqNum(data, len, &seq_num); |
| 642 | GetRtpSsrc(data, len, &ssrc); |
| 643 | LOG(LS_ERROR) << "Failed to protect " << content_name_ |
| 644 | << " RTP packet: size=" << len |
| 645 | << ", seqnum=" << seq_num << ", SSRC=" << ssrc; |
| 646 | return false; |
| 647 | } |
| 648 | } else { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 649 | res = srtp_filter_.ProtectRtcp(data, len, |
| 650 | static_cast<int>(packet->capacity()), |
| 651 | &len); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 652 | if (!res) { |
| 653 | int type = -1; |
| 654 | GetRtcpType(data, len, &type); |
| 655 | LOG(LS_ERROR) << "Failed to protect " << content_name_ |
| 656 | << " RTCP packet: size=" << len << ", type=" << type; |
| 657 | return false; |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | // Update the length of the packet now that we've added the auth tag. |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 662 | packet->SetSize(len); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 663 | } else if (secure_required_) { |
| 664 | // This is a double check for something that supposedly can't happen. |
| 665 | LOG(LS_ERROR) << "Can't send outgoing " << PacketType(rtcp) |
| 666 | << " packet when SRTP is inactive and crypto is required"; |
| 667 | |
| 668 | ASSERT(false); |
| 669 | return false; |
| 670 | } |
| 671 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 672 | // Bon voyage. |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 673 | int ret = |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 674 | channel->SendPacket(packet->data<char>(), packet->size(), updated_options, |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 675 | (secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0); |
| 676 | if (ret != static_cast<int>(packet->size())) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 677 | if (channel->GetError() == EWOULDBLOCK) { |
| 678 | LOG(LS_WARNING) << "Got EWOULDBLOCK from socket."; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 679 | SetReadyToSend(rtcp, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 680 | } |
| 681 | return false; |
| 682 | } |
| 683 | return true; |
| 684 | } |
| 685 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 686 | bool BaseChannel::WantsPacket(bool rtcp, rtc::Buffer* packet) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 687 | // Protect ourselves against crazy data. |
| 688 | if (!ValidPacket(rtcp, packet)) { |
| 689 | LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " " |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 690 | << PacketType(rtcp) |
| 691 | << " packet: wrong size=" << packet->size(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 692 | return false; |
| 693 | } |
pbos | 482b12e | 2015-11-16 10:19:58 -0800 | [diff] [blame] | 694 | if (rtcp) { |
| 695 | // Permit all (seemingly valid) RTCP packets. |
| 696 | return true; |
| 697 | } |
| 698 | // Check whether we handle this payload. |
| 699 | return bundle_filter_.DemuxPacket(packet->data<uint8_t>(), packet->size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 700 | } |
| 701 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 702 | void BaseChannel::HandlePacket(bool rtcp, rtc::Buffer* packet, |
| 703 | const rtc::PacketTime& packet_time) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 704 | if (!WantsPacket(rtcp, packet)) { |
| 705 | return; |
| 706 | } |
| 707 | |
honghaiz@google.com | a67ca1a | 2015-01-28 19:48:33 +0000 | [diff] [blame] | 708 | // We are only interested in the first rtp packet because that |
| 709 | // indicates the media has started flowing. |
| 710 | if (!has_received_packet_ && !rtcp) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 711 | has_received_packet_ = true; |
| 712 | signaling_thread()->Post(this, MSG_FIRSTPACKETRECEIVED); |
| 713 | } |
| 714 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 715 | // Unprotect the packet, if needed. |
| 716 | if (srtp_filter_.IsActive()) { |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 717 | char* data = packet->data<char>(); |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 718 | int len = static_cast<int>(packet->size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 719 | bool res; |
| 720 | if (!rtcp) { |
| 721 | res = srtp_filter_.UnprotectRtp(data, len, &len); |
| 722 | if (!res) { |
| 723 | int seq_num = -1; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 724 | uint32_t ssrc = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 725 | GetRtpSeqNum(data, len, &seq_num); |
| 726 | GetRtpSsrc(data, len, &ssrc); |
| 727 | LOG(LS_ERROR) << "Failed to unprotect " << content_name_ |
| 728 | << " RTP packet: size=" << len |
| 729 | << ", seqnum=" << seq_num << ", SSRC=" << ssrc; |
| 730 | return; |
| 731 | } |
| 732 | } else { |
| 733 | res = srtp_filter_.UnprotectRtcp(data, len, &len); |
| 734 | if (!res) { |
| 735 | int type = -1; |
| 736 | GetRtcpType(data, len, &type); |
| 737 | LOG(LS_ERROR) << "Failed to unprotect " << content_name_ |
| 738 | << " RTCP packet: size=" << len << ", type=" << type; |
| 739 | return; |
| 740 | } |
| 741 | } |
| 742 | |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 743 | packet->SetSize(len); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 744 | } else if (secure_required_) { |
| 745 | // Our session description indicates that SRTP is required, but we got a |
| 746 | // packet before our SRTP filter is active. This means either that |
| 747 | // a) we got SRTP packets before we received the SDES keys, in which case |
| 748 | // we can't decrypt it anyway, or |
| 749 | // b) we got SRTP packets before DTLS completed on both the RTP and RTCP |
| 750 | // channels, so we haven't yet extracted keys, even if DTLS did complete |
| 751 | // on the channel that the packets are being sent on. It's really good |
| 752 | // practice to wait for both RTP and RTCP to be good to go before sending |
| 753 | // media, to prevent weird failure modes, so it's fine for us to just eat |
| 754 | // packets here. This is all sidestepped if RTCP mux is used anyway. |
| 755 | LOG(LS_WARNING) << "Can't process incoming " << PacketType(rtcp) |
| 756 | << " packet when SRTP is inactive and crypto is required"; |
| 757 | return; |
| 758 | } |
| 759 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 760 | // Push it down to the media channel. |
| 761 | if (!rtcp) { |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 762 | media_channel_->OnPacketReceived(packet, packet_time); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 763 | } else { |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 764 | media_channel_->OnRtcpReceived(packet, packet_time); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 765 | } |
| 766 | } |
| 767 | |
pthatcher@webrtc.org | 592470b | 2015-03-16 21:15:37 +0000 | [diff] [blame] | 768 | bool BaseChannel::PushdownLocalDescription( |
| 769 | const SessionDescription* local_desc, ContentAction action, |
| 770 | std::string* error_desc) { |
| 771 | const ContentInfo* content_info = GetFirstContent(local_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 772 | const MediaContentDescription* content_desc = |
| 773 | GetContentDescription(content_info); |
| 774 | if (content_desc && content_info && !content_info->rejected && |
pthatcher@webrtc.org | 592470b | 2015-03-16 21:15:37 +0000 | [diff] [blame] | 775 | !SetLocalContent(content_desc, action, error_desc)) { |
| 776 | LOG(LS_ERROR) << "Failure in SetLocalContent with action " << action; |
| 777 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 778 | } |
pthatcher@webrtc.org | 592470b | 2015-03-16 21:15:37 +0000 | [diff] [blame] | 779 | return true; |
| 780 | } |
| 781 | |
| 782 | bool BaseChannel::PushdownRemoteDescription( |
| 783 | const SessionDescription* remote_desc, ContentAction action, |
| 784 | std::string* error_desc) { |
| 785 | const ContentInfo* content_info = GetFirstContent(remote_desc); |
| 786 | const MediaContentDescription* content_desc = |
| 787 | GetContentDescription(content_info); |
| 788 | if (content_desc && content_info && !content_info->rejected && |
| 789 | !SetRemoteContent(content_desc, action, error_desc)) { |
| 790 | LOG(LS_ERROR) << "Failure in SetRemoteContent with action " << action; |
| 791 | return false; |
| 792 | } |
| 793 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | void BaseChannel::EnableMedia_w() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 797 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 798 | if (enabled_) |
| 799 | return; |
| 800 | |
| 801 | LOG(LS_INFO) << "Channel enabled"; |
| 802 | enabled_ = true; |
| 803 | ChangeState(); |
| 804 | } |
| 805 | |
| 806 | void BaseChannel::DisableMedia_w() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 807 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 808 | if (!enabled_) |
| 809 | return; |
| 810 | |
| 811 | LOG(LS_INFO) << "Channel disabled"; |
| 812 | enabled_ = false; |
| 813 | ChangeState(); |
| 814 | } |
| 815 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 816 | void BaseChannel::UpdateWritableState_w() { |
| 817 | if (transport_channel_ && transport_channel_->writable() && |
| 818 | (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) { |
| 819 | ChannelWritable_w(); |
| 820 | } else { |
| 821 | ChannelNotWritable_w(); |
| 822 | } |
| 823 | } |
| 824 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 825 | void BaseChannel::ChannelWritable_w() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 826 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 827 | if (writable_) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 828 | return; |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 829 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 830 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 831 | LOG(LS_INFO) << "Channel writable (" << content_name_ << ")" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 832 | << (was_ever_writable_ ? "" : " for the first time"); |
| 833 | |
| 834 | std::vector<ConnectionInfo> infos; |
| 835 | transport_channel_->GetStats(&infos); |
| 836 | for (std::vector<ConnectionInfo>::const_iterator it = infos.begin(); |
| 837 | it != infos.end(); ++it) { |
| 838 | if (it->best_connection) { |
| 839 | LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString() |
| 840 | << "->" << it->remote_candidate.ToSensitiveString(); |
| 841 | break; |
| 842 | } |
| 843 | } |
| 844 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 845 | was_ever_writable_ = true; |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 846 | MaybeSetupDtlsSrtp_w(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 847 | writable_ = true; |
| 848 | ChangeState(); |
| 849 | } |
| 850 | |
pthatcher@webrtc.org | 4eeef58 | 2015-03-16 19:34:23 +0000 | [diff] [blame] | 851 | void BaseChannel::SignalDtlsSetupFailure_w(bool rtcp) { |
| 852 | ASSERT(worker_thread() == rtc::Thread::Current()); |
| 853 | signaling_thread()->Invoke<void>(Bind( |
| 854 | &BaseChannel::SignalDtlsSetupFailure_s, this, rtcp)); |
| 855 | } |
| 856 | |
| 857 | void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) { |
| 858 | ASSERT(signaling_thread() == rtc::Thread::Current()); |
| 859 | SignalDtlsSetupFailure(this, rtcp); |
| 860 | } |
| 861 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 862 | bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) { |
| 863 | std::vector<int> crypto_suites; |
| 864 | // We always use the default SRTP crypto suites for RTCP, but we may use |
| 865 | // different crypto suites for RTP depending on the media type. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 866 | if (!rtcp) { |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 867 | GetSrtpCryptoSuites(&crypto_suites); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 868 | } else { |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 869 | GetDefaultSrtpCryptoSuites(&crypto_suites); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 870 | } |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 871 | return tc->SetSrtpCryptoSuites(crypto_suites); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | bool BaseChannel::ShouldSetupDtlsSrtp() const { |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 875 | // Since DTLS is applied to all channels, checking RTP should be enough. |
| 876 | return transport_channel_ && transport_channel_->IsDtlsActive(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | // This function returns true if either DTLS-SRTP is not in use |
| 880 | // *or* DTLS-SRTP is successfully set up. |
| 881 | bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { |
| 882 | bool ret = false; |
| 883 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 884 | TransportChannel* channel = |
| 885 | rtcp_channel ? rtcp_transport_channel_ : transport_channel_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 886 | |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 887 | RTC_DCHECK(channel->IsDtlsActive()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 888 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 889 | int selected_crypto_suite; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 890 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 891 | if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { |
| 892 | LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 893 | return false; |
| 894 | } |
| 895 | |
| 896 | LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " |
| 897 | << content_name() << " " |
| 898 | << PacketType(rtcp_channel); |
| 899 | |
| 900 | // OK, we're now doing DTLS (RFC 5764) |
| 901 | std::vector<unsigned char> dtls_buffer(SRTP_MASTER_KEY_KEY_LEN * 2 + |
| 902 | SRTP_MASTER_KEY_SALT_LEN * 2); |
| 903 | |
| 904 | // RFC 5705 exporter using the RFC 5764 parameters |
| 905 | if (!channel->ExportKeyingMaterial( |
| 906 | kDtlsSrtpExporterLabel, |
| 907 | NULL, 0, false, |
| 908 | &dtls_buffer[0], dtls_buffer.size())) { |
| 909 | LOG(LS_WARNING) << "DTLS-SRTP key export failed"; |
| 910 | ASSERT(false); // This should never happen |
| 911 | return false; |
| 912 | } |
| 913 | |
| 914 | // Sync up the keys with the DTLS-SRTP interface |
| 915 | std::vector<unsigned char> client_write_key(SRTP_MASTER_KEY_KEY_LEN + |
| 916 | SRTP_MASTER_KEY_SALT_LEN); |
| 917 | std::vector<unsigned char> server_write_key(SRTP_MASTER_KEY_KEY_LEN + |
| 918 | SRTP_MASTER_KEY_SALT_LEN); |
| 919 | size_t offset = 0; |
| 920 | memcpy(&client_write_key[0], &dtls_buffer[offset], |
| 921 | SRTP_MASTER_KEY_KEY_LEN); |
| 922 | offset += SRTP_MASTER_KEY_KEY_LEN; |
| 923 | memcpy(&server_write_key[0], &dtls_buffer[offset], |
| 924 | SRTP_MASTER_KEY_KEY_LEN); |
| 925 | offset += SRTP_MASTER_KEY_KEY_LEN; |
| 926 | memcpy(&client_write_key[SRTP_MASTER_KEY_KEY_LEN], |
| 927 | &dtls_buffer[offset], SRTP_MASTER_KEY_SALT_LEN); |
| 928 | offset += SRTP_MASTER_KEY_SALT_LEN; |
| 929 | memcpy(&server_write_key[SRTP_MASTER_KEY_KEY_LEN], |
| 930 | &dtls_buffer[offset], SRTP_MASTER_KEY_SALT_LEN); |
| 931 | |
| 932 | std::vector<unsigned char> *send_key, *recv_key; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 933 | rtc::SSLRole role; |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 934 | if (!channel->GetSslRole(&role)) { |
| 935 | LOG(LS_WARNING) << "GetSslRole failed"; |
| 936 | return false; |
| 937 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 938 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 939 | if (role == rtc::SSL_SERVER) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 940 | send_key = &server_write_key; |
| 941 | recv_key = &client_write_key; |
| 942 | } else { |
| 943 | send_key = &client_write_key; |
| 944 | recv_key = &server_write_key; |
| 945 | } |
| 946 | |
| 947 | if (rtcp_channel) { |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 948 | ret = srtp_filter_.SetRtcpParams(selected_crypto_suite, &(*send_key)[0], |
| 949 | static_cast<int>(send_key->size()), |
| 950 | selected_crypto_suite, &(*recv_key)[0], |
| 951 | static_cast<int>(recv_key->size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 952 | } else { |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 953 | ret = srtp_filter_.SetRtpParams(selected_crypto_suite, &(*send_key)[0], |
| 954 | static_cast<int>(send_key->size()), |
| 955 | selected_crypto_suite, &(*recv_key)[0], |
| 956 | static_cast<int>(recv_key->size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | if (!ret) |
| 960 | LOG(LS_WARNING) << "DTLS-SRTP key installation failed"; |
| 961 | else |
| 962 | dtls_keyed_ = true; |
| 963 | |
| 964 | return ret; |
| 965 | } |
| 966 | |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 967 | void BaseChannel::MaybeSetupDtlsSrtp_w() { |
| 968 | if (srtp_filter_.IsActive()) { |
| 969 | return; |
| 970 | } |
| 971 | |
| 972 | if (!ShouldSetupDtlsSrtp()) { |
| 973 | return; |
| 974 | } |
| 975 | |
| 976 | if (!SetupDtlsSrtp(false)) { |
| 977 | SignalDtlsSetupFailure_w(false); |
| 978 | return; |
| 979 | } |
| 980 | |
| 981 | if (rtcp_transport_channel_) { |
| 982 | if (!SetupDtlsSrtp(true)) { |
| 983 | SignalDtlsSetupFailure_w(true); |
| 984 | return; |
| 985 | } |
| 986 | } |
| 987 | } |
| 988 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 989 | void BaseChannel::ChannelNotWritable_w() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 990 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 991 | if (!writable_) |
| 992 | return; |
| 993 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 994 | LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 995 | writable_ = false; |
| 996 | ChangeState(); |
| 997 | } |
| 998 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 999 | bool BaseChannel::SetRtpTransportParameters_w( |
| 1000 | const MediaContentDescription* content, |
| 1001 | ContentAction action, |
| 1002 | ContentSource src, |
| 1003 | std::string* error_desc) { |
| 1004 | if (action == CA_UPDATE) { |
| 1005 | // These parameters never get changed by a CA_UDPATE. |
| 1006 | return true; |
| 1007 | } |
| 1008 | |
| 1009 | // Cache secure_required_ for belt and suspenders check on SendPacket |
| 1010 | if (src == CS_LOCAL) { |
| 1011 | set_secure_required(content->crypto_required() != CT_NONE); |
| 1012 | } |
| 1013 | |
| 1014 | if (!SetSrtp_w(content->cryptos(), action, src, error_desc)) { |
| 1015 | return false; |
| 1016 | } |
| 1017 | |
| 1018 | if (!SetRtcpMux_w(content->rtcp_mux(), action, src, error_desc)) { |
| 1019 | return false; |
| 1020 | } |
| 1021 | |
| 1022 | return true; |
| 1023 | } |
| 1024 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1025 | // |dtls| will be set to true if DTLS is active for transport channel and |
| 1026 | // crypto is empty. |
| 1027 | bool BaseChannel::CheckSrtpConfig(const std::vector<CryptoParams>& cryptos, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1028 | bool* dtls, |
| 1029 | std::string* error_desc) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1030 | *dtls = transport_channel_->IsDtlsActive(); |
| 1031 | if (*dtls && !cryptos.empty()) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1032 | SafeSetError("Cryptos must be empty when DTLS is active.", |
| 1033 | error_desc); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1034 | return false; |
| 1035 | } |
| 1036 | return true; |
| 1037 | } |
| 1038 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1039 | bool BaseChannel::SetSrtp_w(const std::vector<CryptoParams>& cryptos, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1040 | ContentAction action, |
| 1041 | ContentSource src, |
| 1042 | std::string* error_desc) { |
| 1043 | if (action == CA_UPDATE) { |
| 1044 | // no crypto params. |
| 1045 | return true; |
| 1046 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1047 | bool ret = false; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1048 | bool dtls = false; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1049 | ret = CheckSrtpConfig(cryptos, &dtls, error_desc); |
| 1050 | if (!ret) { |
| 1051 | return false; |
| 1052 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1053 | switch (action) { |
| 1054 | case CA_OFFER: |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1055 | // If DTLS is already active on the channel, we could be renegotiating |
| 1056 | // here. We don't update the srtp filter. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1057 | if (!dtls) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1058 | ret = srtp_filter_.SetOffer(cryptos, src); |
| 1059 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1060 | break; |
| 1061 | case CA_PRANSWER: |
| 1062 | // If we're doing DTLS-SRTP, we don't want to update the filter |
| 1063 | // with an answer, because we already have SRTP parameters. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1064 | if (!dtls) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1065 | ret = srtp_filter_.SetProvisionalAnswer(cryptos, src); |
| 1066 | } |
| 1067 | break; |
| 1068 | case CA_ANSWER: |
| 1069 | // If we're doing DTLS-SRTP, we don't want to update the filter |
| 1070 | // with an answer, because we already have SRTP parameters. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1071 | if (!dtls) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1072 | ret = srtp_filter_.SetAnswer(cryptos, src); |
| 1073 | } |
| 1074 | break; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1075 | default: |
| 1076 | break; |
| 1077 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1078 | if (!ret) { |
| 1079 | SafeSetError("Failed to setup SRTP filter.", error_desc); |
| 1080 | return false; |
| 1081 | } |
| 1082 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1083 | } |
| 1084 | |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 1085 | void BaseChannel::ActivateRtcpMux() { |
| 1086 | worker_thread_->Invoke<void>(Bind( |
| 1087 | &BaseChannel::ActivateRtcpMux_w, this)); |
| 1088 | } |
| 1089 | |
| 1090 | void BaseChannel::ActivateRtcpMux_w() { |
| 1091 | if (!rtcp_mux_filter_.IsActive()) { |
| 1092 | rtcp_mux_filter_.SetActive(); |
guoweis | 4638331 | 2015-12-17 16:45:59 -0800 | [diff] [blame^] | 1093 | set_rtcp_transport_channel(nullptr, true); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1094 | rtcp_transport_enabled_ = false; |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 1095 | } |
| 1096 | } |
| 1097 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1098 | bool BaseChannel::SetRtcpMux_w(bool enable, ContentAction action, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1099 | ContentSource src, |
| 1100 | std::string* error_desc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1101 | bool ret = false; |
| 1102 | switch (action) { |
| 1103 | case CA_OFFER: |
| 1104 | ret = rtcp_mux_filter_.SetOffer(enable, src); |
| 1105 | break; |
| 1106 | case CA_PRANSWER: |
| 1107 | ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); |
| 1108 | break; |
| 1109 | case CA_ANSWER: |
| 1110 | ret = rtcp_mux_filter_.SetAnswer(enable, src); |
| 1111 | if (ret && rtcp_mux_filter_.IsActive()) { |
| 1112 | // We activated RTCP mux, close down the RTCP transport. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1113 | LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() |
| 1114 | << " by destroying RTCP transport channel for " |
| 1115 | << transport_name(); |
guoweis | 4638331 | 2015-12-17 16:45:59 -0800 | [diff] [blame^] | 1116 | set_rtcp_transport_channel(nullptr, true); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1117 | rtcp_transport_enabled_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1118 | } |
| 1119 | break; |
| 1120 | case CA_UPDATE: |
| 1121 | // No RTCP mux info. |
| 1122 | ret = true; |
Henrik Kjellander | 7c027b6 | 2015-04-22 13:21:30 +0200 | [diff] [blame] | 1123 | break; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1124 | default: |
| 1125 | break; |
| 1126 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1127 | if (!ret) { |
| 1128 | SafeSetError("Failed to setup RTCP mux filter.", error_desc); |
| 1129 | return false; |
| 1130 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1131 | // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or |
| 1132 | // CA_ANSWER, but we only want to tear down the RTCP transport channel if we |
| 1133 | // received a final answer. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1134 | if (rtcp_mux_filter_.IsActive()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1135 | // If the RTP transport is already writable, then so are we. |
| 1136 | if (transport_channel_->writable()) { |
| 1137 | ChannelWritable_w(); |
| 1138 | } |
| 1139 | } |
| 1140 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1141 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | bool BaseChannel::AddRecvStream_w(const StreamParams& sp) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1145 | ASSERT(worker_thread() == rtc::Thread::Current()); |
pbos | 482b12e | 2015-11-16 10:19:58 -0800 | [diff] [blame] | 1146 | return media_channel()->AddRecvStream(sp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1149 | bool BaseChannel::RemoveRecvStream_w(uint32_t ssrc) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1150 | ASSERT(worker_thread() == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1151 | return media_channel()->RemoveRecvStream(ssrc); |
| 1152 | } |
| 1153 | |
| 1154 | bool BaseChannel::UpdateLocalStreams_w(const std::vector<StreamParams>& streams, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1155 | ContentAction action, |
| 1156 | std::string* error_desc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1157 | if (!VERIFY(action == CA_OFFER || action == CA_ANSWER || |
| 1158 | action == CA_PRANSWER || action == CA_UPDATE)) |
| 1159 | return false; |
| 1160 | |
| 1161 | // If this is an update, streams only contain streams that have changed. |
| 1162 | if (action == CA_UPDATE) { |
| 1163 | for (StreamParamsVec::const_iterator it = streams.begin(); |
| 1164 | it != streams.end(); ++it) { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 1165 | const StreamParams* existing_stream = |
| 1166 | GetStreamByIds(local_streams_, it->groupid, it->id); |
| 1167 | if (!existing_stream && it->has_ssrcs()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1168 | if (media_channel()->AddSendStream(*it)) { |
| 1169 | local_streams_.push_back(*it); |
| 1170 | LOG(LS_INFO) << "Add send stream ssrc: " << it->first_ssrc(); |
| 1171 | } else { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1172 | std::ostringstream desc; |
| 1173 | desc << "Failed to add send stream ssrc: " << it->first_ssrc(); |
| 1174 | SafeSetError(desc.str(), error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1175 | return false; |
| 1176 | } |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 1177 | } else if (existing_stream && !it->has_ssrcs()) { |
| 1178 | if (!media_channel()->RemoveSendStream(existing_stream->first_ssrc())) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1179 | std::ostringstream desc; |
| 1180 | desc << "Failed to remove send stream with ssrc " |
| 1181 | << it->first_ssrc() << "."; |
| 1182 | SafeSetError(desc.str(), error_desc); |
| 1183 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1184 | } |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 1185 | RemoveStreamBySsrc(&local_streams_, existing_stream->first_ssrc()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1186 | } else { |
| 1187 | LOG(LS_WARNING) << "Ignore unsupported stream update"; |
| 1188 | } |
| 1189 | } |
| 1190 | return true; |
| 1191 | } |
| 1192 | // Else streams are all the streams we want to send. |
| 1193 | |
| 1194 | // Check for streams that have been removed. |
| 1195 | bool ret = true; |
| 1196 | for (StreamParamsVec::const_iterator it = local_streams_.begin(); |
| 1197 | it != local_streams_.end(); ++it) { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 1198 | if (!GetStreamBySsrc(streams, it->first_ssrc())) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1199 | if (!media_channel()->RemoveSendStream(it->first_ssrc())) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1200 | std::ostringstream desc; |
| 1201 | desc << "Failed to remove send stream with ssrc " |
| 1202 | << it->first_ssrc() << "."; |
| 1203 | SafeSetError(desc.str(), error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1204 | ret = false; |
| 1205 | } |
| 1206 | } |
| 1207 | } |
| 1208 | // Check for new streams. |
| 1209 | for (StreamParamsVec::const_iterator it = streams.begin(); |
| 1210 | it != streams.end(); ++it) { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 1211 | if (!GetStreamBySsrc(local_streams_, it->first_ssrc())) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1212 | if (media_channel()->AddSendStream(*it)) { |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1213 | LOG(LS_INFO) << "Add send stream ssrc: " << it->ssrcs[0]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1214 | } else { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1215 | std::ostringstream desc; |
| 1216 | desc << "Failed to add send stream ssrc: " << it->first_ssrc(); |
| 1217 | SafeSetError(desc.str(), error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1218 | ret = false; |
| 1219 | } |
| 1220 | } |
| 1221 | } |
| 1222 | local_streams_ = streams; |
| 1223 | return ret; |
| 1224 | } |
| 1225 | |
| 1226 | bool BaseChannel::UpdateRemoteStreams_w( |
| 1227 | const std::vector<StreamParams>& streams, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1228 | ContentAction action, |
| 1229 | std::string* error_desc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1230 | if (!VERIFY(action == CA_OFFER || action == CA_ANSWER || |
| 1231 | action == CA_PRANSWER || action == CA_UPDATE)) |
| 1232 | return false; |
| 1233 | |
| 1234 | // If this is an update, streams only contain streams that have changed. |
| 1235 | if (action == CA_UPDATE) { |
| 1236 | for (StreamParamsVec::const_iterator it = streams.begin(); |
| 1237 | it != streams.end(); ++it) { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 1238 | const StreamParams* existing_stream = |
| 1239 | GetStreamByIds(remote_streams_, it->groupid, it->id); |
| 1240 | if (!existing_stream && it->has_ssrcs()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1241 | if (AddRecvStream_w(*it)) { |
| 1242 | remote_streams_.push_back(*it); |
| 1243 | LOG(LS_INFO) << "Add remote stream ssrc: " << it->first_ssrc(); |
| 1244 | } else { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1245 | std::ostringstream desc; |
| 1246 | desc << "Failed to add remote stream ssrc: " << it->first_ssrc(); |
| 1247 | SafeSetError(desc.str(), error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1248 | return false; |
| 1249 | } |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 1250 | } else if (existing_stream && !it->has_ssrcs()) { |
| 1251 | if (!RemoveRecvStream_w(existing_stream->first_ssrc())) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1252 | std::ostringstream desc; |
| 1253 | desc << "Failed to remove remote stream with ssrc " |
| 1254 | << it->first_ssrc() << "."; |
| 1255 | SafeSetError(desc.str(), error_desc); |
| 1256 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1257 | } |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 1258 | RemoveStreamBySsrc(&remote_streams_, existing_stream->first_ssrc()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1259 | } else { |
| 1260 | LOG(LS_WARNING) << "Ignore unsupported stream update." |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 1261 | << " Stream exists? " << (existing_stream != nullptr) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1262 | << " new stream = " << it->ToString(); |
| 1263 | } |
| 1264 | } |
| 1265 | return true; |
| 1266 | } |
| 1267 | // Else streams are all the streams we want to receive. |
| 1268 | |
| 1269 | // Check for streams that have been removed. |
| 1270 | bool ret = true; |
| 1271 | for (StreamParamsVec::const_iterator it = remote_streams_.begin(); |
| 1272 | it != remote_streams_.end(); ++it) { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 1273 | if (!GetStreamBySsrc(streams, it->first_ssrc())) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1274 | if (!RemoveRecvStream_w(it->first_ssrc())) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1275 | std::ostringstream desc; |
| 1276 | desc << "Failed to remove remote stream with ssrc " |
| 1277 | << it->first_ssrc() << "."; |
| 1278 | SafeSetError(desc.str(), error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1279 | ret = false; |
| 1280 | } |
| 1281 | } |
| 1282 | } |
| 1283 | // Check for new streams. |
| 1284 | for (StreamParamsVec::const_iterator it = streams.begin(); |
| 1285 | it != streams.end(); ++it) { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 1286 | if (!GetStreamBySsrc(remote_streams_, it->first_ssrc())) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1287 | if (AddRecvStream_w(*it)) { |
| 1288 | LOG(LS_INFO) << "Add remote ssrc: " << it->ssrcs[0]; |
| 1289 | } else { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1290 | std::ostringstream desc; |
| 1291 | desc << "Failed to add remote stream ssrc: " << it->first_ssrc(); |
| 1292 | SafeSetError(desc.str(), error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1293 | ret = false; |
| 1294 | } |
| 1295 | } |
| 1296 | } |
| 1297 | remote_streams_ = streams; |
| 1298 | return ret; |
| 1299 | } |
| 1300 | |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 1301 | void BaseChannel::MaybeCacheRtpAbsSendTimeHeaderExtension( |
| 1302 | const std::vector<RtpHeaderExtension>& extensions) { |
| 1303 | const RtpHeaderExtension* send_time_extension = |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 1304 | FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension); |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 1305 | rtp_abs_sendtime_extn_id_ = |
| 1306 | send_time_extension ? send_time_extension->id : -1; |
| 1307 | } |
| 1308 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1309 | void BaseChannel::OnMessage(rtc::Message *pmsg) { |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 1310 | TRACE_EVENT0("webrtc", "BaseChannel::OnMessage"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1311 | switch (pmsg->message_id) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1312 | case MSG_RTPPACKET: |
| 1313 | case MSG_RTCPPACKET: { |
| 1314 | PacketMessageData* data = static_cast<PacketMessageData*>(pmsg->pdata); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1315 | SendPacket(pmsg->message_id == MSG_RTCPPACKET, &data->packet, |
| 1316 | data->options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1317 | delete data; // because it is Posted |
| 1318 | break; |
| 1319 | } |
| 1320 | case MSG_FIRSTPACKETRECEIVED: { |
| 1321 | SignalFirstPacketReceived(this); |
| 1322 | break; |
| 1323 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1327 | void BaseChannel::FlushRtcpMessages() { |
| 1328 | // Flush all remaining RTCP messages. This should only be called in |
| 1329 | // destructor. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1330 | ASSERT(rtc::Thread::Current() == worker_thread_); |
| 1331 | rtc::MessageList rtcp_messages; |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1332 | worker_thread_->Clear(this, MSG_RTCPPACKET, &rtcp_messages); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1333 | for (rtc::MessageList::iterator it = rtcp_messages.begin(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1334 | it != rtcp_messages.end(); ++it) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1335 | worker_thread_->Send(this, MSG_RTCPPACKET, it->pdata); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1339 | VoiceChannel::VoiceChannel(rtc::Thread* thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1340 | MediaEngineInterface* media_engine, |
| 1341 | VoiceMediaChannel* media_channel, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1342 | TransportController* transport_controller, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1343 | const std::string& content_name, |
| 1344 | bool rtcp) |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1345 | : BaseChannel(thread, |
| 1346 | media_channel, |
| 1347 | transport_controller, |
| 1348 | content_name, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1349 | rtcp), |
Fredrik Solenberg | 0c02264 | 2015-08-05 12:25:22 +0200 | [diff] [blame] | 1350 | media_engine_(media_engine), |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1351 | received_media_(false) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1352 | |
| 1353 | VoiceChannel::~VoiceChannel() { |
| 1354 | StopAudioMonitor(); |
| 1355 | StopMediaMonitor(); |
| 1356 | // this can't be done in the base class, since it calls a virtual |
| 1357 | DisableMedia_w(); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 1358 | Deinit(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | bool VoiceChannel::Init() { |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 1362 | if (!BaseChannel::Init()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1363 | return false; |
| 1364 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1365 | return true; |
| 1366 | } |
| 1367 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1368 | bool VoiceChannel::SetAudioSend(uint32_t ssrc, |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 1369 | bool enable, |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 1370 | const AudioOptions* options, |
| 1371 | AudioRenderer* renderer) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1372 | return InvokeOnWorker(Bind(&VoiceMediaChannel::SetAudioSend, media_channel(), |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 1373 | ssrc, enable, options, renderer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1376 | // TODO(juberti): Handle early media the right way. We should get an explicit |
| 1377 | // ringing message telling us to start playing local ringback, which we cancel |
| 1378 | // if any early media actually arrives. For now, we do the opposite, which is |
| 1379 | // to wait 1 second for early media, and start playing local ringback if none |
| 1380 | // arrives. |
| 1381 | void VoiceChannel::SetEarlyMedia(bool enable) { |
| 1382 | if (enable) { |
| 1383 | // Start the early media timeout |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1384 | worker_thread()->PostDelayed(kEarlyMediaTimeout, this, |
| 1385 | MSG_EARLYMEDIATIMEOUT); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1386 | } else { |
| 1387 | // Stop the timeout if currently going. |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1388 | worker_thread()->Clear(this, MSG_EARLYMEDIATIMEOUT); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1389 | } |
| 1390 | } |
| 1391 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1392 | bool VoiceChannel::CanInsertDtmf() { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1393 | return InvokeOnWorker(Bind(&VoiceMediaChannel::CanInsertDtmf, |
| 1394 | media_channel())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1397 | bool VoiceChannel::InsertDtmf(uint32_t ssrc, |
| 1398 | int event_code, |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 1399 | int duration) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1400 | return InvokeOnWorker(Bind(&VoiceChannel::InsertDtmf_w, this, |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 1401 | ssrc, event_code, duration)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 1404 | bool VoiceChannel::SetOutputVolume(uint32_t ssrc, double volume) { |
| 1405 | return InvokeOnWorker(Bind(&VoiceMediaChannel::SetOutputVolume, |
| 1406 | media_channel(), ssrc, volume)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1407 | } |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1408 | |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 1409 | void VoiceChannel::SetRawAudioSink( |
| 1410 | uint32_t ssrc, |
| 1411 | rtc::scoped_ptr<webrtc::AudioSinkInterface> sink) { |
| 1412 | // We need to work around Bind's lack of support for scoped_ptr and ownership |
| 1413 | // passing. So we invoke to our own little routine that gets a pointer to |
| 1414 | // our local variable. This is OK since we're synchronously invoking. |
| 1415 | InvokeOnWorker(Bind(&SetRawAudioSink_w, media_channel(), ssrc, &sink)); |
| 1416 | } |
| 1417 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1418 | bool VoiceChannel::GetStats(VoiceMediaInfo* stats) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1419 | return InvokeOnWorker(Bind(&VoiceMediaChannel::GetStats, |
| 1420 | media_channel(), stats)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | void VoiceChannel::StartMediaMonitor(int cms) { |
| 1424 | media_monitor_.reset(new VoiceMediaMonitor(media_channel(), worker_thread(), |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1425 | rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1426 | media_monitor_->SignalUpdate.connect( |
| 1427 | this, &VoiceChannel::OnMediaMonitorUpdate); |
| 1428 | media_monitor_->Start(cms); |
| 1429 | } |
| 1430 | |
| 1431 | void VoiceChannel::StopMediaMonitor() { |
| 1432 | if (media_monitor_) { |
| 1433 | media_monitor_->Stop(); |
| 1434 | media_monitor_->SignalUpdate.disconnect(this); |
| 1435 | media_monitor_.reset(); |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | void VoiceChannel::StartAudioMonitor(int cms) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1440 | audio_monitor_.reset(new AudioMonitor(this, rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1441 | audio_monitor_ |
| 1442 | ->SignalUpdate.connect(this, &VoiceChannel::OnAudioMonitorUpdate); |
| 1443 | audio_monitor_->Start(cms); |
| 1444 | } |
| 1445 | |
| 1446 | void VoiceChannel::StopAudioMonitor() { |
| 1447 | if (audio_monitor_) { |
| 1448 | audio_monitor_->Stop(); |
| 1449 | audio_monitor_.reset(); |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | bool VoiceChannel::IsAudioMonitorRunning() const { |
| 1454 | return (audio_monitor_.get() != NULL); |
| 1455 | } |
| 1456 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1457 | int VoiceChannel::GetInputLevel_w() { |
Fredrik Solenberg | 0c02264 | 2015-08-05 12:25:22 +0200 | [diff] [blame] | 1458 | return media_engine_->GetInputLevel(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | int VoiceChannel::GetOutputLevel_w() { |
| 1462 | return media_channel()->GetOutputLevel(); |
| 1463 | } |
| 1464 | |
| 1465 | void VoiceChannel::GetActiveStreams_w(AudioInfo::StreamList* actives) { |
| 1466 | media_channel()->GetActiveStreams(actives); |
| 1467 | } |
| 1468 | |
| 1469 | void VoiceChannel::OnChannelRead(TransportChannel* channel, |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 1470 | const char* data, size_t len, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1471 | const rtc::PacketTime& packet_time, |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 1472 | int flags) { |
| 1473 | BaseChannel::OnChannelRead(channel, data, len, packet_time, flags); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1474 | |
| 1475 | // Set a flag when we've received an RTP packet. If we're waiting for early |
| 1476 | // media, this will disable the timeout. |
| 1477 | if (!received_media_ && !PacketIsRtcp(channel, data, len)) { |
| 1478 | received_media_ = true; |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | void VoiceChannel::ChangeState() { |
| 1483 | // Render incoming data if we're the active call, and we have the local |
| 1484 | // content. We receive data on the default channel and multiplexed streams. |
| 1485 | bool recv = IsReadyToReceive(); |
solenberg | 5b14b42 | 2015-10-01 04:10:31 -0700 | [diff] [blame] | 1486 | media_channel()->SetPlayout(recv); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1487 | |
| 1488 | // Send outgoing data if we're the active call, we have the remote content, |
| 1489 | // and we have had some form of connectivity. |
| 1490 | bool send = IsReadyToSend(); |
| 1491 | SendFlags send_flag = send ? SEND_MICROPHONE : SEND_NOTHING; |
| 1492 | if (!media_channel()->SetSend(send_flag)) { |
| 1493 | LOG(LS_ERROR) << "Failed to SetSend " << send_flag << " on voice channel"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | LOG(LS_INFO) << "Changing voice state, recv=" << recv << " send=" << send; |
| 1497 | } |
| 1498 | |
| 1499 | const ContentInfo* VoiceChannel::GetFirstContent( |
| 1500 | const SessionDescription* sdesc) { |
| 1501 | return GetFirstAudioContent(sdesc); |
| 1502 | } |
| 1503 | |
| 1504 | bool VoiceChannel::SetLocalContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1505 | ContentAction action, |
| 1506 | std::string* error_desc) { |
Peter Boström | 9f45a45 | 2015-12-08 13:25:57 +0100 | [diff] [blame] | 1507 | TRACE_EVENT0("webrtc", "VoiceChannel::SetLocalContent_w"); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1508 | ASSERT(worker_thread() == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1509 | LOG(LS_INFO) << "Setting local voice description"; |
| 1510 | |
| 1511 | const AudioContentDescription* audio = |
| 1512 | static_cast<const AudioContentDescription*>(content); |
| 1513 | ASSERT(audio != NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1514 | if (!audio) { |
| 1515 | SafeSetError("Can't find audio content in local description.", error_desc); |
| 1516 | return false; |
| 1517 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1518 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1519 | if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) { |
| 1520 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1521 | } |
| 1522 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1523 | AudioRecvParameters recv_params = last_recv_params_; |
| 1524 | RtpParametersFromMediaDescription(audio, &recv_params); |
| 1525 | if (!media_channel()->SetRecvParameters(recv_params)) { |
Peter Thatcher | bfab5cb | 2015-08-20 17:40:24 -0700 | [diff] [blame] | 1526 | SafeSetError("Failed to set local audio description recv parameters.", |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1527 | error_desc); |
| 1528 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1529 | } |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1530 | for (const AudioCodec& codec : audio->codecs()) { |
| 1531 | bundle_filter()->AddPayloadType(codec.id); |
| 1532 | } |
| 1533 | last_recv_params_ = recv_params; |
| 1534 | |
| 1535 | // TODO(pthatcher): Move local streams into AudioSendParameters, and |
| 1536 | // only give it to the media channel once we have a remote |
| 1537 | // description too (without a remote description, we won't be able |
| 1538 | // to send them anyway). |
| 1539 | if (!UpdateLocalStreams_w(audio->streams(), action, error_desc)) { |
| 1540 | SafeSetError("Failed to set local audio description streams.", error_desc); |
| 1541 | return false; |
| 1542 | } |
| 1543 | |
| 1544 | set_local_content_direction(content->direction()); |
| 1545 | ChangeState(); |
| 1546 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1550 | ContentAction action, |
| 1551 | std::string* error_desc) { |
Peter Boström | 9f45a45 | 2015-12-08 13:25:57 +0100 | [diff] [blame] | 1552 | TRACE_EVENT0("webrtc", "VoiceChannel::SetRemoteContent_w"); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1553 | ASSERT(worker_thread() == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1554 | LOG(LS_INFO) << "Setting remote voice description"; |
| 1555 | |
| 1556 | const AudioContentDescription* audio = |
| 1557 | static_cast<const AudioContentDescription*>(content); |
| 1558 | ASSERT(audio != NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1559 | if (!audio) { |
| 1560 | SafeSetError("Can't find audio content in remote description.", error_desc); |
| 1561 | return false; |
| 1562 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1563 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1564 | if (!SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) { |
| 1565 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1568 | AudioSendParameters send_params = last_send_params_; |
| 1569 | RtpSendParametersFromMediaDescription(audio, &send_params); |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1570 | if (audio->agc_minus_10db()) { |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 1571 | send_params.options.adjust_agc_delta = rtc::Optional<int>(kAgcMinus10db); |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1572 | } |
| 1573 | if (!media_channel()->SetSendParameters(send_params)) { |
| 1574 | SafeSetError("Failed to set remote audio description send parameters.", |
| 1575 | error_desc); |
| 1576 | return false; |
| 1577 | } |
| 1578 | last_send_params_ = send_params; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1579 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1580 | // TODO(pthatcher): Move remote streams into AudioRecvParameters, |
| 1581 | // and only give it to the media channel once we have a local |
| 1582 | // description too (without a local description, we won't be able to |
| 1583 | // recv them anyway). |
| 1584 | if (!UpdateRemoteStreams_w(audio->streams(), action, error_desc)) { |
| 1585 | SafeSetError("Failed to set remote audio description streams.", error_desc); |
| 1586 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
Peter Thatcher | bfab5cb | 2015-08-20 17:40:24 -0700 | [diff] [blame] | 1589 | if (audio->rtp_header_extensions_set()) { |
| 1590 | MaybeCacheRtpAbsSendTimeHeaderExtension(audio->rtp_header_extensions()); |
| 1591 | } |
| 1592 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1593 | set_remote_content_direction(content->direction()); |
| 1594 | ChangeState(); |
| 1595 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1598 | void VoiceChannel::HandleEarlyMediaTimeout() { |
| 1599 | // This occurs on the main thread, not the worker thread. |
| 1600 | if (!received_media_) { |
| 1601 | LOG(LS_INFO) << "No early media received before timeout"; |
| 1602 | SignalEarlyMediaTimeout(this); |
| 1603 | } |
| 1604 | } |
| 1605 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1606 | bool VoiceChannel::InsertDtmf_w(uint32_t ssrc, |
| 1607 | int event, |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 1608 | int duration) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1609 | if (!enabled()) { |
| 1610 | return false; |
| 1611 | } |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 1612 | return media_channel()->InsertDtmf(ssrc, event, duration); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1615 | void VoiceChannel::OnMessage(rtc::Message *pmsg) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1616 | switch (pmsg->message_id) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1617 | case MSG_EARLYMEDIATIMEOUT: |
| 1618 | HandleEarlyMediaTimeout(); |
| 1619 | break; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1620 | case MSG_CHANNEL_ERROR: { |
| 1621 | VoiceChannelErrorMessageData* data = |
| 1622 | static_cast<VoiceChannelErrorMessageData*>(pmsg->pdata); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1623 | delete data; |
| 1624 | break; |
| 1625 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1626 | default: |
| 1627 | BaseChannel::OnMessage(pmsg); |
| 1628 | break; |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | void VoiceChannel::OnConnectionMonitorUpdate( |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame] | 1633 | ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1634 | SignalConnectionMonitor(this, infos); |
| 1635 | } |
| 1636 | |
| 1637 | void VoiceChannel::OnMediaMonitorUpdate( |
| 1638 | VoiceMediaChannel* media_channel, const VoiceMediaInfo& info) { |
| 1639 | ASSERT(media_channel == this->media_channel()); |
| 1640 | SignalMediaMonitor(this, info); |
| 1641 | } |
| 1642 | |
| 1643 | void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor, |
| 1644 | const AudioInfo& info) { |
| 1645 | SignalAudioMonitor(this, info); |
| 1646 | } |
| 1647 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1648 | void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { |
| 1649 | GetSupportedAudioCryptoSuites(crypto_suites); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1652 | VideoChannel::VideoChannel(rtc::Thread* thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1653 | VideoMediaChannel* media_channel, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1654 | TransportController* transport_controller, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1655 | const std::string& content_name, |
Fredrik Solenberg | 7fb711f | 2015-04-22 15:30:51 +0200 | [diff] [blame] | 1656 | bool rtcp) |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1657 | : BaseChannel(thread, |
| 1658 | media_channel, |
| 1659 | transport_controller, |
| 1660 | content_name, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1661 | rtcp), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1662 | renderer_(NULL), |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1663 | previous_we_(rtc::WE_CLOSE) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1664 | |
| 1665 | bool VideoChannel::Init() { |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 1666 | if (!BaseChannel::Init()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1667 | return false; |
| 1668 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1669 | return true; |
| 1670 | } |
| 1671 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1672 | VideoChannel::~VideoChannel() { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1673 | std::vector<uint32_t> screencast_ssrcs; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1674 | ScreencastMap::iterator iter; |
| 1675 | while (!screencast_capturers_.empty()) { |
| 1676 | if (!RemoveScreencast(screencast_capturers_.begin()->first)) { |
| 1677 | LOG(LS_ERROR) << "Unable to delete screencast with ssrc " |
| 1678 | << screencast_capturers_.begin()->first; |
| 1679 | ASSERT(false); |
| 1680 | break; |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | StopMediaMonitor(); |
| 1685 | // this can't be done in the base class, since it calls a virtual |
| 1686 | DisableMedia_w(); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 1687 | |
| 1688 | Deinit(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1691 | bool VideoChannel::SetRenderer(uint32_t ssrc, VideoRenderer* renderer) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1692 | worker_thread()->Invoke<void>(Bind( |
| 1693 | &VideoMediaChannel::SetRenderer, media_channel(), ssrc, renderer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1694 | return true; |
| 1695 | } |
| 1696 | |
| 1697 | bool VideoChannel::ApplyViewRequest(const ViewRequest& request) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1698 | return InvokeOnWorker(Bind(&VideoChannel::ApplyViewRequest_w, this, request)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1701 | bool VideoChannel::AddScreencast(uint32_t ssrc, VideoCapturer* capturer) { |
buildbot@webrtc.org | 65b98d1 | 2014-08-07 22:09:08 +0000 | [diff] [blame] | 1702 | return worker_thread()->Invoke<bool>(Bind( |
| 1703 | &VideoChannel::AddScreencast_w, this, ssrc, capturer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1704 | } |
| 1705 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1706 | bool VideoChannel::SetCapturer(uint32_t ssrc, VideoCapturer* capturer) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1707 | return InvokeOnWorker(Bind(&VideoMediaChannel::SetCapturer, |
| 1708 | media_channel(), ssrc, capturer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1709 | } |
| 1710 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1711 | bool VideoChannel::RemoveScreencast(uint32_t ssrc) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1712 | return InvokeOnWorker(Bind(&VideoChannel::RemoveScreencast_w, this, ssrc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | bool VideoChannel::IsScreencasting() { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1716 | return InvokeOnWorker(Bind(&VideoChannel::IsScreencasting_w, this)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1719 | int VideoChannel::GetScreencastFps(uint32_t ssrc) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1720 | ScreencastDetailsData data(ssrc); |
| 1721 | worker_thread()->Invoke<void>(Bind( |
| 1722 | &VideoChannel::GetScreencastDetails_w, this, &data)); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1723 | return data.fps; |
| 1724 | } |
| 1725 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1726 | int VideoChannel::GetScreencastMaxPixels(uint32_t ssrc) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1727 | ScreencastDetailsData data(ssrc); |
| 1728 | worker_thread()->Invoke<void>(Bind( |
| 1729 | &VideoChannel::GetScreencastDetails_w, this, &data)); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1730 | return data.screencast_max_pixels; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | bool VideoChannel::SendIntraFrame() { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1734 | worker_thread()->Invoke<void>(Bind( |
| 1735 | &VideoMediaChannel::SendIntraFrame, media_channel())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1736 | return true; |
| 1737 | } |
| 1738 | |
| 1739 | bool VideoChannel::RequestIntraFrame() { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1740 | worker_thread()->Invoke<void>(Bind( |
| 1741 | &VideoMediaChannel::RequestIntraFrame, media_channel())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1742 | return true; |
| 1743 | } |
| 1744 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1745 | bool VideoChannel::SetVideoSend(uint32_t ssrc, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1746 | bool mute, |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 1747 | const VideoOptions* options) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1748 | return InvokeOnWorker(Bind(&VideoMediaChannel::SetVideoSend, media_channel(), |
| 1749 | ssrc, mute, options)); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1752 | void VideoChannel::ChangeState() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1753 | // Send outgoing data if we're the active call, we have the remote content, |
| 1754 | // and we have had some form of connectivity. |
| 1755 | bool send = IsReadyToSend(); |
| 1756 | if (!media_channel()->SetSend(send)) { |
| 1757 | LOG(LS_ERROR) << "Failed to SetSend on video channel"; |
| 1758 | // TODO(gangji): Report error back to server. |
| 1759 | } |
| 1760 | |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 1761 | LOG(LS_INFO) << "Changing video state, send=" << send; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1762 | } |
| 1763 | |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 1764 | bool VideoChannel::GetStats(VideoMediaInfo* stats) { |
| 1765 | return InvokeOnWorker( |
| 1766 | Bind(&VideoMediaChannel::GetStats, media_channel(), stats)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | void VideoChannel::StartMediaMonitor(int cms) { |
| 1770 | media_monitor_.reset(new VideoMediaMonitor(media_channel(), worker_thread(), |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1771 | rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1772 | media_monitor_->SignalUpdate.connect( |
| 1773 | this, &VideoChannel::OnMediaMonitorUpdate); |
| 1774 | media_monitor_->Start(cms); |
| 1775 | } |
| 1776 | |
| 1777 | void VideoChannel::StopMediaMonitor() { |
| 1778 | if (media_monitor_) { |
| 1779 | media_monitor_->Stop(); |
| 1780 | media_monitor_.reset(); |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | const ContentInfo* VideoChannel::GetFirstContent( |
| 1785 | const SessionDescription* sdesc) { |
| 1786 | return GetFirstVideoContent(sdesc); |
| 1787 | } |
| 1788 | |
| 1789 | bool VideoChannel::SetLocalContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1790 | ContentAction action, |
| 1791 | std::string* error_desc) { |
Peter Boström | 9f45a45 | 2015-12-08 13:25:57 +0100 | [diff] [blame] | 1792 | TRACE_EVENT0("webrtc", "VideoChannel::SetLocalContent_w"); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1793 | ASSERT(worker_thread() == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1794 | LOG(LS_INFO) << "Setting local video description"; |
| 1795 | |
| 1796 | const VideoContentDescription* video = |
| 1797 | static_cast<const VideoContentDescription*>(content); |
| 1798 | ASSERT(video != NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1799 | if (!video) { |
| 1800 | SafeSetError("Can't find video content in local description.", error_desc); |
| 1801 | return false; |
| 1802 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1803 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1804 | if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) { |
| 1805 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1806 | } |
| 1807 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1808 | VideoRecvParameters recv_params = last_recv_params_; |
| 1809 | RtpParametersFromMediaDescription(video, &recv_params); |
| 1810 | if (!media_channel()->SetRecvParameters(recv_params)) { |
| 1811 | SafeSetError("Failed to set local video description recv parameters.", |
| 1812 | error_desc); |
| 1813 | return false; |
| 1814 | } |
| 1815 | for (const VideoCodec& codec : video->codecs()) { |
| 1816 | bundle_filter()->AddPayloadType(codec.id); |
| 1817 | } |
| 1818 | last_recv_params_ = recv_params; |
| 1819 | |
| 1820 | // TODO(pthatcher): Move local streams into VideoSendParameters, and |
| 1821 | // only give it to the media channel once we have a remote |
| 1822 | // description too (without a remote description, we won't be able |
| 1823 | // to send them anyway). |
| 1824 | if (!UpdateLocalStreams_w(video->streams(), action, error_desc)) { |
| 1825 | SafeSetError("Failed to set local video description streams.", error_desc); |
| 1826 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1829 | set_local_content_direction(content->direction()); |
| 1830 | ChangeState(); |
| 1831 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1835 | ContentAction action, |
| 1836 | std::string* error_desc) { |
Peter Boström | 9f45a45 | 2015-12-08 13:25:57 +0100 | [diff] [blame] | 1837 | TRACE_EVENT0("webrtc", "VideoChannel::SetRemoteContent_w"); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1838 | ASSERT(worker_thread() == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1839 | LOG(LS_INFO) << "Setting remote video description"; |
| 1840 | |
| 1841 | const VideoContentDescription* video = |
| 1842 | static_cast<const VideoContentDescription*>(content); |
| 1843 | ASSERT(video != NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1844 | if (!video) { |
| 1845 | SafeSetError("Can't find video content in remote description.", error_desc); |
| 1846 | return false; |
| 1847 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1848 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1849 | |
| 1850 | if (!SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) { |
| 1851 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1852 | } |
| 1853 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1854 | VideoSendParameters send_params = last_send_params_; |
| 1855 | RtpSendParametersFromMediaDescription(video, &send_params); |
| 1856 | if (video->conference_mode()) { |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 1857 | send_params.options.conference_mode = rtc::Optional<bool>(true); |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1858 | } |
| 1859 | if (!media_channel()->SetSendParameters(send_params)) { |
| 1860 | SafeSetError("Failed to set remote video description send parameters.", |
| 1861 | error_desc); |
| 1862 | return false; |
| 1863 | } |
| 1864 | last_send_params_ = send_params; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1865 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1866 | // TODO(pthatcher): Move remote streams into VideoRecvParameters, |
| 1867 | // and only give it to the media channel once we have a local |
| 1868 | // description too (without a local description, we won't be able to |
| 1869 | // recv them anyway). |
| 1870 | if (!UpdateRemoteStreams_w(video->streams(), action, error_desc)) { |
| 1871 | SafeSetError("Failed to set remote video description streams.", error_desc); |
| 1872 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1873 | } |
| 1874 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1875 | if (video->rtp_header_extensions_set()) { |
| 1876 | MaybeCacheRtpAbsSendTimeHeaderExtension(video->rtp_header_extensions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1877 | } |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 1878 | |
| 1879 | set_remote_content_direction(content->direction()); |
| 1880 | ChangeState(); |
| 1881 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | bool VideoChannel::ApplyViewRequest_w(const ViewRequest& request) { |
| 1885 | bool ret = true; |
| 1886 | // Set the send format for each of the local streams. If the view request |
| 1887 | // does not contain a local stream, set its send format to 0x0, which will |
| 1888 | // drop all frames. |
| 1889 | for (std::vector<StreamParams>::const_iterator it = local_streams().begin(); |
| 1890 | it != local_streams().end(); ++it) { |
| 1891 | VideoFormat format(0, 0, 0, cricket::FOURCC_I420); |
| 1892 | StaticVideoViews::const_iterator view; |
| 1893 | for (view = request.static_video_views.begin(); |
| 1894 | view != request.static_video_views.end(); ++view) { |
| 1895 | if (view->selector.Matches(*it)) { |
| 1896 | format.width = view->width; |
| 1897 | format.height = view->height; |
| 1898 | format.interval = cricket::VideoFormat::FpsToInterval(view->framerate); |
| 1899 | break; |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | ret &= media_channel()->SetSendStreamFormat(it->first_ssrc(), format); |
| 1904 | } |
| 1905 | |
| 1906 | // Check if the view request has invalid streams. |
| 1907 | for (StaticVideoViews::const_iterator it = request.static_video_views.begin(); |
| 1908 | it != request.static_video_views.end(); ++it) { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 1909 | if (!GetStream(local_streams(), it->selector)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1910 | LOG(LS_WARNING) << "View request for (" |
| 1911 | << it->selector.ssrc << ", '" |
| 1912 | << it->selector.groupid << "', '" |
| 1913 | << it->selector.streamid << "'" |
| 1914 | << ") is not in the local streams."; |
| 1915 | } |
| 1916 | } |
| 1917 | |
| 1918 | return ret; |
| 1919 | } |
| 1920 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1921 | bool VideoChannel::AddScreencast_w(uint32_t ssrc, VideoCapturer* capturer) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1922 | if (screencast_capturers_.find(ssrc) != screencast_capturers_.end()) { |
buildbot@webrtc.org | 65b98d1 | 2014-08-07 22:09:08 +0000 | [diff] [blame] | 1923 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1924 | } |
buildbot@webrtc.org | 65b98d1 | 2014-08-07 22:09:08 +0000 | [diff] [blame] | 1925 | capturer->SignalStateChange.connect(this, &VideoChannel::OnStateChange); |
| 1926 | screencast_capturers_[ssrc] = capturer; |
| 1927 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1930 | bool VideoChannel::RemoveScreencast_w(uint32_t ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1931 | ScreencastMap::iterator iter = screencast_capturers_.find(ssrc); |
| 1932 | if (iter == screencast_capturers_.end()) { |
| 1933 | return false; |
| 1934 | } |
| 1935 | // Clean up VideoCapturer. |
| 1936 | delete iter->second; |
| 1937 | screencast_capturers_.erase(iter); |
| 1938 | return true; |
| 1939 | } |
| 1940 | |
| 1941 | bool VideoChannel::IsScreencasting_w() const { |
| 1942 | return !screencast_capturers_.empty(); |
| 1943 | } |
| 1944 | |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 1945 | void VideoChannel::GetScreencastDetails_w( |
| 1946 | ScreencastDetailsData* data) const { |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1947 | ScreencastMap::const_iterator iter = screencast_capturers_.find(data->ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1948 | if (iter == screencast_capturers_.end()) { |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1949 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1950 | } |
| 1951 | VideoCapturer* capturer = iter->second; |
| 1952 | const VideoFormat* video_format = capturer->GetCaptureFormat(); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 1953 | data->fps = VideoFormat::IntervalToFps(video_format->interval); |
| 1954 | data->screencast_max_pixels = capturer->screencast_max_pixels(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1955 | } |
| 1956 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1957 | void VideoChannel::OnScreencastWindowEvent_s(uint32_t ssrc, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1958 | rtc::WindowEvent we) { |
| 1959 | ASSERT(signaling_thread() == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1960 | SignalScreencastWindowEvent(ssrc, we); |
| 1961 | } |
| 1962 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1963 | void VideoChannel::OnMessage(rtc::Message *pmsg) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1964 | switch (pmsg->message_id) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1965 | case MSG_SCREENCASTWINDOWEVENT: { |
| 1966 | const ScreencastEventMessageData* data = |
| 1967 | static_cast<ScreencastEventMessageData*>(pmsg->pdata); |
| 1968 | OnScreencastWindowEvent_s(data->ssrc, data->event); |
| 1969 | delete data; |
| 1970 | break; |
| 1971 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1972 | case MSG_CHANNEL_ERROR: { |
| 1973 | const VideoChannelErrorMessageData* data = |
| 1974 | static_cast<VideoChannelErrorMessageData*>(pmsg->pdata); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1975 | delete data; |
| 1976 | break; |
| 1977 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1978 | default: |
| 1979 | BaseChannel::OnMessage(pmsg); |
| 1980 | break; |
| 1981 | } |
| 1982 | } |
| 1983 | |
| 1984 | void VideoChannel::OnConnectionMonitorUpdate( |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame] | 1985 | ConnectionMonitor* monitor, const std::vector<ConnectionInfo> &infos) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1986 | SignalConnectionMonitor(this, infos); |
| 1987 | } |
| 1988 | |
| 1989 | // TODO(pthatcher): Look into removing duplicate code between |
| 1990 | // audio, video, and data, perhaps by using templates. |
| 1991 | void VideoChannel::OnMediaMonitorUpdate( |
| 1992 | VideoMediaChannel* media_channel, const VideoMediaInfo &info) { |
| 1993 | ASSERT(media_channel == this->media_channel()); |
| 1994 | SignalMediaMonitor(this, info); |
| 1995 | } |
| 1996 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1997 | void VideoChannel::OnScreencastWindowEvent(uint32_t ssrc, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1998 | rtc::WindowEvent event) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1999 | ScreencastEventMessageData* pdata = |
| 2000 | new ScreencastEventMessageData(ssrc, event); |
| 2001 | signaling_thread()->Post(this, MSG_SCREENCASTWINDOWEVENT, pdata); |
| 2002 | } |
| 2003 | |
| 2004 | void VideoChannel::OnStateChange(VideoCapturer* capturer, CaptureState ev) { |
| 2005 | // Map capturer events to window events. In the future we may want to simply |
| 2006 | // pass these events up directly. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2007 | rtc::WindowEvent we; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2008 | if (ev == CS_STOPPED) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2009 | we = rtc::WE_CLOSE; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2010 | } else if (ev == CS_PAUSED) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2011 | we = rtc::WE_MINIMIZE; |
| 2012 | } else if (ev == CS_RUNNING && previous_we_ == rtc::WE_MINIMIZE) { |
| 2013 | we = rtc::WE_RESTORE; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2014 | } else { |
| 2015 | return; |
| 2016 | } |
| 2017 | previous_we_ = we; |
| 2018 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2019 | uint32_t ssrc = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2020 | if (!GetLocalSsrc(capturer, &ssrc)) { |
| 2021 | return; |
| 2022 | } |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 2023 | |
| 2024 | OnScreencastWindowEvent(ssrc, we); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2025 | } |
| 2026 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2027 | bool VideoChannel::GetLocalSsrc(const VideoCapturer* capturer, uint32_t* ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2028 | *ssrc = 0; |
| 2029 | for (ScreencastMap::iterator iter = screencast_capturers_.begin(); |
| 2030 | iter != screencast_capturers_.end(); ++iter) { |
| 2031 | if (iter->second == capturer) { |
| 2032 | *ssrc = iter->first; |
| 2033 | return true; |
| 2034 | } |
| 2035 | } |
| 2036 | return false; |
| 2037 | } |
| 2038 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 2039 | void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { |
| 2040 | GetSupportedVideoCryptoSuites(crypto_suites); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2041 | } |
| 2042 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2043 | DataChannel::DataChannel(rtc::Thread* thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2044 | DataMediaChannel* media_channel, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2045 | TransportController* transport_controller, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2046 | const std::string& content_name, |
| 2047 | bool rtcp) |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2048 | : BaseChannel(thread, |
| 2049 | media_channel, |
| 2050 | transport_controller, |
| 2051 | content_name, |
| 2052 | rtcp), |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 2053 | data_channel_type_(cricket::DCT_NONE), |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2054 | ready_to_send_data_(false) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2055 | |
| 2056 | DataChannel::~DataChannel() { |
| 2057 | StopMediaMonitor(); |
| 2058 | // this can't be done in the base class, since it calls a virtual |
| 2059 | DisableMedia_w(); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 2060 | |
| 2061 | Deinit(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | bool DataChannel::Init() { |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 +0000 | [diff] [blame] | 2065 | if (!BaseChannel::Init()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2066 | return false; |
| 2067 | } |
| 2068 | media_channel()->SignalDataReceived.connect( |
| 2069 | this, &DataChannel::OnDataReceived); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 2070 | media_channel()->SignalReadyToSend.connect( |
| 2071 | this, &DataChannel::OnDataChannelReadyToSend); |
buildbot@webrtc.org | 1d66be2 | 2014-05-29 22:54:24 +0000 | [diff] [blame] | 2072 | media_channel()->SignalStreamClosedRemotely.connect( |
| 2073 | this, &DataChannel::OnStreamClosedRemotely); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2074 | return true; |
| 2075 | } |
| 2076 | |
| 2077 | bool DataChannel::SendData(const SendDataParams& params, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2078 | const rtc::Buffer& payload, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2079 | SendDataResult* result) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 2080 | return InvokeOnWorker(Bind(&DataMediaChannel::SendData, |
| 2081 | media_channel(), params, payload, result)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | const ContentInfo* DataChannel::GetFirstContent( |
| 2085 | const SessionDescription* sdesc) { |
| 2086 | return GetFirstDataContent(sdesc); |
| 2087 | } |
| 2088 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2089 | bool DataChannel::WantsPacket(bool rtcp, rtc::Buffer* packet) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2090 | if (data_channel_type_ == DCT_SCTP) { |
| 2091 | // TODO(pthatcher): Do this in a more robust way by checking for |
| 2092 | // SCTP or DTLS. |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 2093 | return !IsRtpPacket(packet->data(), packet->size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2094 | } else if (data_channel_type_ == DCT_RTP) { |
| 2095 | return BaseChannel::WantsPacket(rtcp, packet); |
| 2096 | } |
| 2097 | return false; |
| 2098 | } |
| 2099 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2100 | bool DataChannel::SetDataChannelType(DataChannelType new_data_channel_type, |
| 2101 | std::string* error_desc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2102 | // It hasn't been set before, so set it now. |
| 2103 | if (data_channel_type_ == DCT_NONE) { |
| 2104 | data_channel_type_ = new_data_channel_type; |
| 2105 | return true; |
| 2106 | } |
| 2107 | |
| 2108 | // It's been set before, but doesn't match. That's bad. |
| 2109 | if (data_channel_type_ != new_data_channel_type) { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2110 | std::ostringstream desc; |
| 2111 | desc << "Data channel type mismatch." |
| 2112 | << " Expected " << data_channel_type_ |
| 2113 | << " Got " << new_data_channel_type; |
| 2114 | SafeSetError(desc.str(), error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2115 | return false; |
| 2116 | } |
| 2117 | |
| 2118 | // It's hasn't changed. Nothing to do. |
| 2119 | return true; |
| 2120 | } |
| 2121 | |
| 2122 | bool DataChannel::SetDataChannelTypeFromContent( |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2123 | const DataContentDescription* content, |
| 2124 | std::string* error_desc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2125 | bool is_sctp = ((content->protocol() == kMediaProtocolSctp) || |
| 2126 | (content->protocol() == kMediaProtocolDtlsSctp)); |
| 2127 | DataChannelType data_channel_type = is_sctp ? DCT_SCTP : DCT_RTP; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2128 | return SetDataChannelType(data_channel_type, error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | bool DataChannel::SetLocalContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2132 | ContentAction action, |
| 2133 | std::string* error_desc) { |
Peter Boström | 9f45a45 | 2015-12-08 13:25:57 +0100 | [diff] [blame] | 2134 | TRACE_EVENT0("webrtc", "DataChannel::SetLocalContent_w"); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2135 | ASSERT(worker_thread() == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2136 | LOG(LS_INFO) << "Setting local data description"; |
| 2137 | |
| 2138 | const DataContentDescription* data = |
| 2139 | static_cast<const DataContentDescription*>(content); |
| 2140 | ASSERT(data != NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2141 | if (!data) { |
| 2142 | SafeSetError("Can't find data content in local description.", error_desc); |
| 2143 | return false; |
| 2144 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2145 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2146 | if (!SetDataChannelTypeFromContent(data, error_desc)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2147 | return false; |
| 2148 | } |
| 2149 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 2150 | if (data_channel_type_ == DCT_RTP) { |
| 2151 | if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) { |
| 2152 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2153 | } |
| 2154 | } |
| 2155 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 2156 | // FYI: We send the SCTP port number (not to be confused with the |
| 2157 | // underlying UDP port number) as a codec parameter. So even SCTP |
| 2158 | // data channels need codecs. |
| 2159 | DataRecvParameters recv_params = last_recv_params_; |
| 2160 | RtpParametersFromMediaDescription(data, &recv_params); |
| 2161 | if (!media_channel()->SetRecvParameters(recv_params)) { |
| 2162 | SafeSetError("Failed to set remote data description recv parameters.", |
| 2163 | error_desc); |
| 2164 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2165 | } |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 2166 | if (data_channel_type_ == DCT_RTP) { |
| 2167 | for (const DataCodec& codec : data->codecs()) { |
| 2168 | bundle_filter()->AddPayloadType(codec.id); |
| 2169 | } |
| 2170 | } |
| 2171 | last_recv_params_ = recv_params; |
| 2172 | |
| 2173 | // TODO(pthatcher): Move local streams into DataSendParameters, and |
| 2174 | // only give it to the media channel once we have a remote |
| 2175 | // description too (without a remote description, we won't be able |
| 2176 | // to send them anyway). |
| 2177 | if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) { |
| 2178 | SafeSetError("Failed to set local data description streams.", error_desc); |
| 2179 | return false; |
| 2180 | } |
| 2181 | |
| 2182 | set_local_content_direction(content->direction()); |
| 2183 | ChangeState(); |
| 2184 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | bool DataChannel::SetRemoteContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2188 | ContentAction action, |
| 2189 | std::string* error_desc) { |
Peter Boström | 9f45a45 | 2015-12-08 13:25:57 +0100 | [diff] [blame] | 2190 | TRACE_EVENT0("webrtc", "DataChannel::SetRemoteContent_w"); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2191 | ASSERT(worker_thread() == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2192 | |
| 2193 | const DataContentDescription* data = |
| 2194 | static_cast<const DataContentDescription*>(content); |
| 2195 | ASSERT(data != NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2196 | if (!data) { |
| 2197 | SafeSetError("Can't find data content in remote description.", error_desc); |
| 2198 | return false; |
| 2199 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2200 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 2201 | // If the remote data doesn't have codecs and isn't an update, it |
| 2202 | // must be empty, so ignore it. |
| 2203 | if (!data->has_codecs() && action != CA_UPDATE) { |
| 2204 | return true; |
| 2205 | } |
| 2206 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2207 | if (!SetDataChannelTypeFromContent(data, error_desc)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2208 | return false; |
| 2209 | } |
| 2210 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 2211 | LOG(LS_INFO) << "Setting remote data description"; |
| 2212 | if (data_channel_type_ == DCT_RTP && |
| 2213 | !SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) { |
| 2214 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2215 | } |
| 2216 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 2217 | |
| 2218 | DataSendParameters send_params = last_send_params_; |
| 2219 | RtpSendParametersFromMediaDescription<DataCodec>(data, &send_params); |
| 2220 | if (!media_channel()->SetSendParameters(send_params)) { |
| 2221 | SafeSetError("Failed to set remote data description send parameters.", |
| 2222 | error_desc); |
| 2223 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2224 | } |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 2225 | last_send_params_ = send_params; |
| 2226 | |
| 2227 | // TODO(pthatcher): Move remote streams into DataRecvParameters, |
| 2228 | // and only give it to the media channel once we have a local |
| 2229 | // description too (without a local description, we won't be able to |
| 2230 | // recv them anyway). |
| 2231 | if (!UpdateRemoteStreams_w(data->streams(), action, error_desc)) { |
| 2232 | SafeSetError("Failed to set remote data description streams.", |
| 2233 | error_desc); |
| 2234 | return false; |
| 2235 | } |
| 2236 | |
| 2237 | set_remote_content_direction(content->direction()); |
| 2238 | ChangeState(); |
| 2239 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2240 | } |
| 2241 | |
| 2242 | void DataChannel::ChangeState() { |
| 2243 | // Render incoming data if we're the active call, and we have the local |
| 2244 | // content. We receive data on the default channel and multiplexed streams. |
| 2245 | bool recv = IsReadyToReceive(); |
| 2246 | if (!media_channel()->SetReceive(recv)) { |
| 2247 | LOG(LS_ERROR) << "Failed to SetReceive on data channel"; |
| 2248 | } |
| 2249 | |
| 2250 | // Send outgoing data if we're the active call, we have the remote content, |
| 2251 | // and we have had some form of connectivity. |
| 2252 | bool send = IsReadyToSend(); |
| 2253 | if (!media_channel()->SetSend(send)) { |
| 2254 | LOG(LS_ERROR) << "Failed to SetSend on data channel"; |
| 2255 | } |
| 2256 | |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 2257 | // Trigger SignalReadyToSendData asynchronously. |
| 2258 | OnDataChannelReadyToSend(send); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2259 | |
| 2260 | LOG(LS_INFO) << "Changing data state, recv=" << recv << " send=" << send; |
| 2261 | } |
| 2262 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2263 | void DataChannel::OnMessage(rtc::Message *pmsg) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2264 | switch (pmsg->message_id) { |
| 2265 | case MSG_READYTOSENDDATA: { |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 2266 | DataChannelReadyToSendMessageData* data = |
| 2267 | static_cast<DataChannelReadyToSendMessageData*>(pmsg->pdata); |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 2268 | ready_to_send_data_ = data->data(); |
| 2269 | SignalReadyToSendData(ready_to_send_data_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2270 | delete data; |
| 2271 | break; |
| 2272 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2273 | case MSG_DATARECEIVED: { |
| 2274 | DataReceivedMessageData* data = |
| 2275 | static_cast<DataReceivedMessageData*>(pmsg->pdata); |
| 2276 | SignalDataReceived(this, data->params, data->payload); |
| 2277 | delete data; |
| 2278 | break; |
| 2279 | } |
| 2280 | case MSG_CHANNEL_ERROR: { |
| 2281 | const DataChannelErrorMessageData* data = |
| 2282 | static_cast<DataChannelErrorMessageData*>(pmsg->pdata); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2283 | delete data; |
| 2284 | break; |
| 2285 | } |
buildbot@webrtc.org | 1d66be2 | 2014-05-29 22:54:24 +0000 | [diff] [blame] | 2286 | case MSG_STREAMCLOSEDREMOTELY: { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2287 | rtc::TypedMessageData<uint32_t>* data = |
| 2288 | static_cast<rtc::TypedMessageData<uint32_t>*>(pmsg->pdata); |
buildbot@webrtc.org | 1d66be2 | 2014-05-29 22:54:24 +0000 | [diff] [blame] | 2289 | SignalStreamClosedRemotely(data->data()); |
| 2290 | delete data; |
| 2291 | break; |
| 2292 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2293 | default: |
| 2294 | BaseChannel::OnMessage(pmsg); |
| 2295 | break; |
| 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | void DataChannel::OnConnectionMonitorUpdate( |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 +0000 | [diff] [blame] | 2300 | ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2301 | SignalConnectionMonitor(this, infos); |
| 2302 | } |
| 2303 | |
| 2304 | void DataChannel::StartMediaMonitor(int cms) { |
| 2305 | media_monitor_.reset(new DataMediaMonitor(media_channel(), worker_thread(), |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2306 | rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2307 | media_monitor_->SignalUpdate.connect( |
| 2308 | this, &DataChannel::OnMediaMonitorUpdate); |
| 2309 | media_monitor_->Start(cms); |
| 2310 | } |
| 2311 | |
| 2312 | void DataChannel::StopMediaMonitor() { |
| 2313 | if (media_monitor_) { |
| 2314 | media_monitor_->Stop(); |
| 2315 | media_monitor_->SignalUpdate.disconnect(this); |
| 2316 | media_monitor_.reset(); |
| 2317 | } |
| 2318 | } |
| 2319 | |
| 2320 | void DataChannel::OnMediaMonitorUpdate( |
| 2321 | DataMediaChannel* media_channel, const DataMediaInfo& info) { |
| 2322 | ASSERT(media_channel == this->media_channel()); |
| 2323 | SignalMediaMonitor(this, info); |
| 2324 | } |
| 2325 | |
| 2326 | void DataChannel::OnDataReceived( |
| 2327 | const ReceiveDataParams& params, const char* data, size_t len) { |
| 2328 | DataReceivedMessageData* msg = new DataReceivedMessageData( |
| 2329 | params, data, len); |
| 2330 | signaling_thread()->Post(this, MSG_DATARECEIVED, msg); |
| 2331 | } |
| 2332 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2333 | void DataChannel::OnDataChannelError(uint32_t ssrc, |
| 2334 | DataMediaChannel::Error err) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2335 | DataChannelErrorMessageData* data = new DataChannelErrorMessageData( |
| 2336 | ssrc, err); |
| 2337 | signaling_thread()->Post(this, MSG_CHANNEL_ERROR, data); |
| 2338 | } |
| 2339 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 2340 | void DataChannel::OnDataChannelReadyToSend(bool writable) { |
| 2341 | // This is usded for congestion control to indicate that the stream is ready |
| 2342 | // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates |
| 2343 | // that the transport channel is ready. |
| 2344 | signaling_thread()->Post(this, MSG_READYTOSENDDATA, |
| 2345 | new DataChannelReadyToSendMessageData(writable)); |
| 2346 | } |
| 2347 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 2348 | void DataChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { |
| 2349 | GetSupportedDataCryptoSuites(crypto_suites); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | bool DataChannel::ShouldSetupDtlsSrtp() const { |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 2353 | return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2356 | void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
| 2357 | rtc::TypedMessageData<uint32_t>* message = |
| 2358 | new rtc::TypedMessageData<uint32_t>(sid); |
buildbot@webrtc.org | 1d66be2 | 2014-05-29 22:54:24 +0000 | [diff] [blame] | 2359 | signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |
| 2360 | } |
| 2361 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2362 | } // namespace cricket |