henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 9 | */ |
| 10 | |
perkj | c11b184 | 2016-03-08 01:34:13 | [diff] [blame] | 11 | #ifndef WEBRTC_PC_CHANNEL_H_ |
| 12 | #define WEBRTC_PC_CHANNEL_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 13 | |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 14 | #include <map> |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 15 | #include <memory> |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 16 | #include <set> |
kjellander | a96e2d7 | 2016-02-05 07:52:28 | [diff] [blame] | 17 | #include <string> |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 18 | #include <utility> |
kjellander | a96e2d7 | 2016-02-05 07:52:28 | [diff] [blame] | 19 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 20 | |
kjellander | a69d973 | 2016-08-31 14:33:05 | [diff] [blame] | 21 | #include "webrtc/api/call/audio_sink.h" |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 22 | #include "webrtc/base/asyncinvoker.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 | [diff] [blame] | 23 | #include "webrtc/base/asyncudpsocket.h" |
| 24 | #include "webrtc/base/criticalsection.h" |
| 25 | #include "webrtc/base/network.h" |
| 26 | #include "webrtc/base/sigslot.h" |
| 27 | #include "webrtc/base/window.h" |
kjellander | a96e2d7 | 2016-02-05 07:52:28 | [diff] [blame] | 28 | #include "webrtc/media/base/mediachannel.h" |
| 29 | #include "webrtc/media/base/mediaengine.h" |
| 30 | #include "webrtc/media/base/streamparams.h" |
nisse | 08582ff | 2016-02-04 09:24:52 | [diff] [blame] | 31 | #include "webrtc/media/base/videosinkinterface.h" |
nisse | 2ded9b1 | 2016-04-08 09:23:55 | [diff] [blame] | 32 | #include "webrtc/media/base/videosourceinterface.h" |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 33 | #include "webrtc/p2p/base/transportcontroller.h" |
| 34 | #include "webrtc/p2p/client/socketmonitor.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 05:47:59 | [diff] [blame] | 35 | #include "webrtc/pc/audiomonitor.h" |
| 36 | #include "webrtc/pc/bundlefilter.h" |
| 37 | #include "webrtc/pc/mediamonitor.h" |
| 38 | #include "webrtc/pc/mediasession.h" |
| 39 | #include "webrtc/pc/rtcpmuxfilter.h" |
| 40 | #include "webrtc/pc/srtpfilter.h" |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 41 | |
| 42 | namespace webrtc { |
| 43 | class AudioSinkInterface; |
| 44 | } // namespace webrtc |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 45 | |
| 46 | namespace cricket { |
| 47 | |
| 48 | struct CryptoParams; |
| 49 | class MediaContentDescription; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 50 | |
deadbeef | 062ce9f | 2016-08-27 04:42:15 | [diff] [blame] | 51 | // BaseChannel contains logic common to voice and video, including enable, |
| 52 | // marshaling calls to a worker and network threads, and connection and media |
| 53 | // monitors. |
| 54 | // |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 55 | // BaseChannel assumes signaling and other threads are allowed to make |
| 56 | // synchronous calls to the worker thread, the worker thread makes synchronous |
| 57 | // calls only to the network thread, and the network thread can't be blocked by |
| 58 | // other threads. |
| 59 | // All methods with _n suffix must be called on network thread, |
deadbeef | 062ce9f | 2016-08-27 04:42:15 | [diff] [blame] | 60 | // methods with _w suffix on worker thread |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 61 | // and methods with _s suffix on signaling thread. |
| 62 | // Network and worker threads may be the same thread. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 63 | // |
| 64 | // WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS! |
| 65 | // This is required to avoid a data race between the destructor modifying the |
| 66 | // vtable, and the media channel's thread using BaseChannel as the |
| 67 | // NetworkInterface. |
| 68 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 69 | class BaseChannel |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 70 | : public rtc::MessageHandler, public sigslot::has_slots<>, |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 | [diff] [blame] | 71 | public MediaChannel::NetworkInterface, |
| 72 | public ConnectionStatsGetter { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 73 | public: |
deadbeef | 23d947d | 2016-08-22 23:00:30 | [diff] [blame] | 74 | // |rtcp| represents whether or not this channel uses RTCP. |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 75 | BaseChannel(rtc::Thread* worker_thread, |
| 76 | rtc::Thread* network_thread, |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 77 | MediaChannel* channel, |
| 78 | TransportController* transport_controller, |
| 79 | const std::string& content_name, |
| 80 | bool rtcp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 81 | virtual ~BaseChannel(); |
skvlad | 6c87a67 | 2016-05-18 00:49:52 | [diff] [blame] | 82 | bool Init_w(const std::string* bundle_transport_name); |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 83 | // Deinit may be called multiple times and is simply ignored if it's already |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 84 | // done. |
| 85 | void Deinit(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 86 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 87 | rtc::Thread* worker_thread() const { return worker_thread_; } |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 88 | rtc::Thread* network_thread() const { return network_thread_; } |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 89 | const std::string& content_name() const { return content_name_; } |
| 90 | const std::string& transport_name() const { return transport_name_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 91 | bool enabled() const { return enabled_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 92 | |
| 93 | // This function returns true if we are using SRTP. |
| 94 | bool secure() const { return srtp_filter_.IsActive(); } |
| 95 | // The following function returns true if we are using |
| 96 | // DTLS-based keying. If you turned off SRTP later, however |
| 97 | // you could have secure() == false and dtls_secure() == true. |
| 98 | bool secure_dtls() const { return dtls_keyed_; } |
| 99 | // This function returns true if we require secure channel for call setup. |
| 100 | bool secure_required() const { return secure_required_; } |
| 101 | |
| 102 | bool writable() const { return writable_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 103 | |
Peter Thatcher | af55ccc | 2015-05-21 14:48:41 | [diff] [blame] | 104 | // Activate RTCP mux, regardless of the state so far. Once |
| 105 | // activated, it can not be deactivated, and if the remote |
| 106 | // description doesn't support RTCP mux, setting the remote |
| 107 | // description will fail. |
| 108 | void ActivateRtcpMux(); |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 109 | bool SetTransport(const std::string& transport_name); |
pthatcher@webrtc.org | 592470b | 2015-03-16 21:15:37 | [diff] [blame] | 110 | bool PushdownLocalDescription(const SessionDescription* local_desc, |
| 111 | ContentAction action, |
| 112 | std::string* error_desc); |
| 113 | bool PushdownRemoteDescription(const SessionDescription* remote_desc, |
| 114 | ContentAction action, |
| 115 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 116 | // Channel control |
| 117 | bool SetLocalContent(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 118 | ContentAction action, |
| 119 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 120 | bool SetRemoteContent(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 121 | ContentAction action, |
| 122 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 123 | |
| 124 | bool Enable(bool enable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 125 | |
| 126 | // Multiplexing |
| 127 | bool AddRecvStream(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 128 | bool RemoveRecvStream(uint32_t ssrc); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 129 | bool AddSendStream(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 130 | bool RemoveSendStream(uint32_t ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 131 | |
| 132 | // Monitoring |
| 133 | void StartConnectionMonitor(int cms); |
| 134 | void StopConnectionMonitor(); |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 | [diff] [blame] | 135 | // For ConnectionStatsGetter, used by ConnectionMonitor |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 136 | bool GetConnectionStats(ConnectionInfos* infos) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 137 | |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 | [diff] [blame] | 138 | BundleFilter* bundle_filter() { return &bundle_filter_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 139 | |
| 140 | const std::vector<StreamParams>& local_streams() const { |
| 141 | return local_streams_; |
| 142 | } |
| 143 | const std::vector<StreamParams>& remote_streams() const { |
| 144 | return remote_streams_; |
| 145 | } |
| 146 | |
pthatcher@webrtc.org | 4eeef58 | 2015-03-16 19:34:23 | [diff] [blame] | 147 | sigslot::signal2<BaseChannel*, bool> SignalDtlsSetupFailure; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 148 | void SignalDtlsSetupFailure_n(bool rtcp); |
pthatcher@webrtc.org | 4eeef58 | 2015-03-16 19:34:23 | [diff] [blame] | 149 | void SignalDtlsSetupFailure_s(bool rtcp); |
| 150 | |
buildbot@webrtc.org | 6bfd619 | 2014-05-15 16:15:59 | [diff] [blame] | 151 | // Used for latency measurements. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 152 | sigslot::signal1<BaseChannel*> SignalFirstPacketReceived; |
| 153 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 154 | // Forward TransportChannel SignalSentPacket to worker thread. |
| 155 | sigslot::signal1<const rtc::SentPacket&> SignalSentPacket; |
| 156 | |
| 157 | // Only public for unit tests. Otherwise, consider private. |
| 158 | TransportChannel* transport_channel() const { return transport_channel_; } |
| 159 | TransportChannel* rtcp_transport_channel() const { |
| 160 | return rtcp_transport_channel_; |
| 161 | } |
| 162 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 163 | // Made public for easier testing. |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 164 | // |
| 165 | // Updates "ready to send" for an individual channel, and informs the media |
| 166 | // channel that the transport is ready to send if each channel (in use) is |
| 167 | // ready to send. This is more specific than just "writable"; it means the |
| 168 | // last send didn't return ENOTCONN. |
| 169 | // |
| 170 | // This should be called whenever a channel's ready-to-send state changes, |
| 171 | // or when RTCP muxing becomes active/inactive. |
| 172 | void SetTransportChannelReadyToSend(bool rtcp, bool ready); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 173 | |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 | [diff] [blame] | 174 | // Only public for unit tests. Otherwise, consider protected. |
rlester | ec9d187 | 2015-10-27 21:22:16 | [diff] [blame] | 175 | int SetOption(SocketType type, rtc::Socket::Option o, int val) |
| 176 | override; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 177 | int SetOption_n(SocketType type, rtc::Socket::Option o, int val); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 | [diff] [blame] | 178 | |
solenberg | 5b14b42 | 2015-10-01 11:10:31 | [diff] [blame] | 179 | SrtpFilter* srtp_filter() { return &srtp_filter_; } |
| 180 | |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 181 | virtual cricket::MediaType media_type() = 0; |
| 182 | |
jbauch | cb56065 | 2016-08-04 12:20:32 | [diff] [blame] | 183 | bool SetCryptoOptions(const rtc::CryptoOptions& crypto_options); |
| 184 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 185 | protected: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 186 | virtual MediaChannel* media_channel() const { return media_channel_; } |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 187 | |
| 188 | // Sets the |transport_channel_| (and |rtcp_transport_channel_|, if |
| 189 | // |rtcp_enabled_| is true). Gets the transport channels from |
| 190 | // |transport_controller_|. |
deadbeef | 062ce9f | 2016-08-27 04:42:15 | [diff] [blame] | 191 | // This method also updates writability and "ready-to-send" state. |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 192 | bool SetTransport_n(const std::string& transport_name); |
guoweis | 4638331 | 2015-12-18 00:45:59 | [diff] [blame] | 193 | |
deadbeef | 062ce9f | 2016-08-27 04:42:15 | [diff] [blame] | 194 | // This does not update writability or "ready-to-send" state; it just |
| 195 | // disconnects from the old channel and connects to the new one. |
| 196 | void SetTransportChannel_n(bool rtcp, TransportChannel* new_channel); |
guoweis | 4638331 | 2015-12-18 00:45:59 | [diff] [blame] | 197 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 198 | bool was_ever_writable() const { return was_ever_writable_; } |
| 199 | void set_local_content_direction(MediaContentDirection direction) { |
| 200 | local_content_direction_ = direction; |
| 201 | } |
| 202 | void set_remote_content_direction(MediaContentDirection direction) { |
| 203 | remote_content_direction_ = direction; |
| 204 | } |
Peter Thatcher | c2ee2c8 | 2015-08-07 23:05:34 | [diff] [blame] | 205 | void set_secure_required(bool secure_required) { |
| 206 | secure_required_ = secure_required; |
| 207 | } |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 208 | // These methods verify that: |
| 209 | // * The required content description directions have been set. |
| 210 | // * The channel is enabled. |
| 211 | // * And for sending: |
| 212 | // - The SRTP filter is active if it's needed. |
| 213 | // - The transport has been writable before, meaning it should be at least |
| 214 | // possible to succeed in sending a packet. |
| 215 | // |
| 216 | // When any of these properties change, UpdateMediaSendRecvState_w should be |
| 217 | // called. |
| 218 | bool IsReadyToReceiveMedia_w() const; |
| 219 | bool IsReadyToSendMedia_w() const; |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 220 | rtc::Thread* signaling_thread() { |
| 221 | return transport_controller_->signaling_thread(); |
| 222 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 223 | |
pthatcher@webrtc.org | 6ad507a | 2015-03-16 20:19:12 | [diff] [blame] | 224 | void ConnectToTransportChannel(TransportChannel* tc); |
| 225 | void DisconnectFromTransportChannel(TransportChannel* tc); |
| 226 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 227 | void FlushRtcpMessages_n(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 228 | |
| 229 | // NetworkInterface implementation, called by MediaEngine |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 230 | bool SendPacket(rtc::CopyOnWriteBuffer* packet, |
| 231 | const rtc::PacketOptions& options) override; |
| 232 | bool SendRtcp(rtc::CopyOnWriteBuffer* packet, |
| 233 | const rtc::PacketOptions& options) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 234 | |
| 235 | // From TransportChannel |
| 236 | void OnWritableState(TransportChannel* channel); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 | [diff] [blame] | 237 | virtual void OnChannelRead(TransportChannel* channel, |
| 238 | const char* data, |
| 239 | size_t len, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 240 | const rtc::PacketTime& packet_time, |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 | [diff] [blame] | 241 | int flags); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 242 | void OnReadyToSend(TransportChannel* channel); |
| 243 | |
Guo-wei Shieh | 1218d7a | 2015-12-05 17:59:56 | [diff] [blame] | 244 | void OnDtlsState(TransportChannel* channel, DtlsTransportState state); |
| 245 | |
Honghai Zhang | cc411c0 | 2016-03-30 00:27:21 | [diff] [blame] | 246 | void OnSelectedCandidatePairChanged( |
| 247 | TransportChannel* channel, |
Honghai Zhang | 52dce73f | 2016-03-31 19:37:31 | [diff] [blame] | 248 | CandidatePairInterface* selected_candidate_pair, |
Taylor Brandstetter | 6bb1ef2 | 2016-06-28 01:09:03 | [diff] [blame] | 249 | int last_sent_packet_id, |
| 250 | bool ready_to_send); |
Honghai Zhang | cc411c0 | 2016-03-30 00:27:21 | [diff] [blame] | 251 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 252 | bool PacketIsRtcp(const TransportChannel* channel, const char* data, |
| 253 | size_t len); |
stefan | c1aeaf0 | 2015-10-15 14:26:07 | [diff] [blame] | 254 | bool SendPacket(bool rtcp, |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 255 | rtc::CopyOnWriteBuffer* packet, |
stefan | c1aeaf0 | 2015-10-15 14:26:07 | [diff] [blame] | 256 | const rtc::PacketOptions& options); |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 257 | |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 258 | virtual bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet); |
| 259 | void HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 260 | const rtc::PacketTime& packet_time); |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 261 | void OnPacketReceived(bool rtcp, |
| 262 | const rtc::CopyOnWriteBuffer& packet, |
| 263 | const rtc::PacketTime& packet_time); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 264 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 265 | void EnableMedia_w(); |
| 266 | void DisableMedia_w(); |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 267 | |
| 268 | // Performs actions if the RTP/RTCP writable state changed. This should |
| 269 | // be called whenever a channel's writable state changes or when RTCP muxing |
| 270 | // becomes active/inactive. |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 271 | void UpdateWritableState_n(); |
| 272 | void ChannelWritable_n(); |
| 273 | void ChannelNotWritable_n(); |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 274 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 275 | bool AddRecvStream_w(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 276 | bool RemoveRecvStream_w(uint32_t ssrc); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 277 | bool AddSendStream_w(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 278 | bool RemoveSendStream_w(uint32_t ssrc); |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 279 | virtual bool ShouldSetupDtlsSrtp_n() const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 280 | // Do the DTLS key expansion and impose it on the SRTP/SRTCP filters. |
| 281 | // |rtcp_channel| indicates whether to set up the RTP or RTCP filter. |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 282 | bool SetupDtlsSrtp_n(bool rtcp_channel); |
| 283 | void MaybeSetupDtlsSrtp_n(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 284 | // Set the DTLS-SRTP cipher policy on this channel as appropriate. |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 285 | bool SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 286 | |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 287 | // Should be called whenever the conditions for |
| 288 | // IsReadyToReceiveMedia/IsReadyToSendMedia are satisfied (or unsatisfied). |
| 289 | // Updates the send/recv state of the media channel. |
| 290 | void UpdateMediaSendRecvState(); |
| 291 | virtual void UpdateMediaSendRecvState_w() = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 292 | |
| 293 | // Gets the content info appropriate to the channel (audio or video). |
| 294 | virtual const ContentInfo* GetFirstContent( |
| 295 | const SessionDescription* sdesc) = 0; |
| 296 | bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 297 | ContentAction action, |
| 298 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 299 | bool UpdateRemoteStreams_w(const std::vector<StreamParams>& streams, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 300 | ContentAction action, |
| 301 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 302 | virtual bool SetLocalContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 303 | ContentAction action, |
| 304 | std::string* error_desc) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 305 | virtual bool SetRemoteContent_w(const MediaContentDescription* content, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 306 | ContentAction action, |
| 307 | std::string* error_desc) = 0; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 308 | bool SetRtpTransportParameters(const MediaContentDescription* content, |
| 309 | ContentAction action, |
| 310 | ContentSource src, |
| 311 | std::string* error_desc); |
| 312 | bool SetRtpTransportParameters_n(const MediaContentDescription* content, |
Peter Thatcher | c2ee2c8 | 2015-08-07 23:05:34 | [diff] [blame] | 313 | ContentAction action, |
| 314 | ContentSource src, |
| 315 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 316 | |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 | [diff] [blame] | 317 | // Helper method to get RTP Absoulute SendTime extension header id if |
| 318 | // present in remote supported extensions list. |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 319 | void MaybeCacheRtpAbsSendTimeHeaderExtension_w( |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 320 | const std::vector<webrtc::RtpExtension>& extensions); |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 | [diff] [blame] | 321 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 322 | bool CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos, |
| 323 | bool* dtls, |
| 324 | std::string* error_desc); |
| 325 | bool SetSrtp_n(const std::vector<CryptoParams>& params, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 326 | ContentAction action, |
| 327 | ContentSource src, |
| 328 | std::string* error_desc); |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 329 | void ActivateRtcpMux_n(); |
| 330 | bool SetRtcpMux_n(bool enable, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 331 | ContentAction action, |
| 332 | ContentSource src, |
| 333 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 334 | |
| 335 | // From MessageHandler |
rlester | ec9d187 | 2015-10-27 21:22:16 | [diff] [blame] | 336 | void OnMessage(rtc::Message* pmsg) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 337 | |
jbauch | cb56065 | 2016-08-04 12:20:32 | [diff] [blame] | 338 | const rtc::CryptoOptions& crypto_options() const { |
| 339 | return crypto_options_; |
| 340 | } |
| 341 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 342 | // Handled in derived classes |
Guo-wei Shieh | 521ed7b | 2015-11-19 03:41:53 | [diff] [blame] | 343 | // Get the SRTP crypto suites to use for RTP media |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 344 | virtual void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const = 0; |
pthatcher@webrtc.org | b4aac13 | 2015-03-13 18:25:21 | [diff] [blame] | 345 | virtual void OnConnectionMonitorUpdate(ConnectionMonitor* monitor, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 346 | const std::vector<ConnectionInfo>& infos) = 0; |
| 347 | |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 | [diff] [blame] | 348 | // Helper function for invoking bool-returning methods on the worker thread. |
| 349 | template <class FunctorT> |
Taylor Brandstetter | 5d97a9a | 2016-06-10 21:17:27 | [diff] [blame] | 350 | bool InvokeOnWorker(const rtc::Location& posted_from, |
| 351 | const FunctorT& functor) { |
| 352 | return worker_thread_->Invoke<bool>(posted_from, functor); |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 | [diff] [blame] | 353 | } |
| 354 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 355 | private: |
skvlad | 6c87a67 | 2016-05-18 00:49:52 | [diff] [blame] | 356 | bool InitNetwork_n(const std::string* bundle_transport_name); |
Danil Chapovalov | dae07ba | 2016-05-13 23:43:50 | [diff] [blame] | 357 | void DisconnectTransportChannels_n(); |
| 358 | void DestroyTransportChannels_n(); |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 359 | void SignalSentPacket_n(TransportChannel* channel, |
| 360 | const rtc::SentPacket& sent_packet); |
| 361 | void SignalSentPacket_w(const rtc::SentPacket& sent_packet); |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 362 | bool IsReadyToSendMedia_n() const; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 363 | void CacheRtpAbsSendTimeHeaderExtension_n(int rtp_abs_sendtime_extn_id); |
| 364 | |
| 365 | rtc::Thread* const worker_thread_; |
| 366 | rtc::Thread* const network_thread_; |
| 367 | rtc::AsyncInvoker invoker_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 368 | |
pthatcher@webrtc.org | 990a00c | 2015-03-13 18:20:33 | [diff] [blame] | 369 | const std::string content_name_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 370 | std::unique_ptr<ConnectionMonitor> connection_monitor_; |
| 371 | |
| 372 | // Transport related members that should be accessed from network thread. |
| 373 | TransportController* const transport_controller_; |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 374 | std::string transport_name_; |
deadbeef | 23d947d | 2016-08-22 23:00:30 | [diff] [blame] | 375 | // Is RTCP used at all by this type of channel? |
| 376 | // Expected to be true (as of typing this) for everything except data |
| 377 | // channels. |
| 378 | const bool rtcp_enabled_; |
| 379 | TransportChannel* transport_channel_ = nullptr; |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 380 | std::vector<std::pair<rtc::Socket::Option, int> > socket_options_; |
deadbeef | 23d947d | 2016-08-22 23:00:30 | [diff] [blame] | 381 | TransportChannel* rtcp_transport_channel_ = nullptr; |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 382 | std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 383 | SrtpFilter srtp_filter_; |
| 384 | RtcpMuxFilter rtcp_mux_filter_; |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 | [diff] [blame] | 385 | BundleFilter bundle_filter_; |
deadbeef | 23d947d | 2016-08-22 23:00:30 | [diff] [blame] | 386 | bool rtp_ready_to_send_ = false; |
| 387 | bool rtcp_ready_to_send_ = false; |
| 388 | bool writable_ = false; |
| 389 | bool was_ever_writable_ = false; |
| 390 | bool has_received_packet_ = false; |
| 391 | bool dtls_keyed_ = false; |
| 392 | bool secure_required_ = false; |
jbauch | cb56065 | 2016-08-04 12:20:32 | [diff] [blame] | 393 | rtc::CryptoOptions crypto_options_; |
deadbeef | 23d947d | 2016-08-22 23:00:30 | [diff] [blame] | 394 | int rtp_abs_sendtime_extn_id_ = -1; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 395 | |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 396 | // MediaChannel related members that should be accessed from the worker |
| 397 | // thread. |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 398 | MediaChannel* const media_channel_; |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 399 | // Currently the |enabled_| flag is accessed from the signaling thread as |
| 400 | // well, but it can be changed only when signaling thread does a synchronous |
| 401 | // call to the worker thread, so it should be safe. |
deadbeef | 23d947d | 2016-08-22 23:00:30 | [diff] [blame] | 402 | bool enabled_ = false; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 403 | std::vector<StreamParams> local_streams_; |
| 404 | std::vector<StreamParams> remote_streams_; |
deadbeef | 23d947d | 2016-08-22 23:00:30 | [diff] [blame] | 405 | MediaContentDirection local_content_direction_ = MD_INACTIVE; |
| 406 | MediaContentDirection remote_content_direction_ = MD_INACTIVE; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 407 | }; |
| 408 | |
| 409 | // VoiceChannel is a specialization that adds support for early media, DTMF, |
| 410 | // and input/output level monitoring. |
| 411 | class VoiceChannel : public BaseChannel { |
| 412 | public: |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 413 | VoiceChannel(rtc::Thread* worker_thread, |
| 414 | rtc::Thread* network_thread, |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 415 | MediaEngineInterface* media_engine, |
| 416 | VoiceMediaChannel* channel, |
| 417 | TransportController* transport_controller, |
| 418 | const std::string& content_name, |
| 419 | bool rtcp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 420 | ~VoiceChannel(); |
skvlad | 6c87a67 | 2016-05-18 00:49:52 | [diff] [blame] | 421 | bool Init_w(const std::string* bundle_transport_name); |
solenberg | 1dd98f3 | 2015-09-10 08:57:14 | [diff] [blame] | 422 | |
| 423 | // Configure sending media on the stream with SSRC |ssrc| |
| 424 | // If there is only one sending stream SSRC 0 can be used. |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 425 | bool SetAudioSend(uint32_t ssrc, |
solenberg | dfc8f4f | 2015-10-01 09:31:10 | [diff] [blame] | 426 | bool enable, |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 427 | const AudioOptions* options, |
Taylor Brandstetter | 1a018dc | 2016-03-08 20:37:39 | [diff] [blame] | 428 | AudioSource* source); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 429 | |
| 430 | // downcasts a MediaChannel |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 431 | VoiceMediaChannel* media_channel() const override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 432 | return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel()); |
| 433 | } |
| 434 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 435 | void SetEarlyMedia(bool enable); |
| 436 | // This signal is emitted when we have gone a period of time without |
| 437 | // receiving early media. When received, a UI should start playing its |
| 438 | // own ringing sound |
| 439 | sigslot::signal1<VoiceChannel*> SignalEarlyMediaTimeout; |
| 440 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 441 | // Returns if the telephone-event has been negotiated. |
| 442 | bool CanInsertDtmf(); |
| 443 | // Send and/or play a DTMF |event| according to the |flags|. |
| 444 | // The DTMF out-of-band signal will be used on sending. |
| 445 | // The |ssrc| should be either 0 or a valid send stream ssrc. |
henrike@webrtc.org | 9de257d | 2013-07-17 14:42:53 | [diff] [blame] | 446 | // The valid value for the |event| are 0 which corresponding to DTMF |
| 447 | // event 0-9, *, #, A-D. |
solenberg | 1d63dd0 | 2015-12-02 20:35:09 | [diff] [blame] | 448 | bool InsertDtmf(uint32_t ssrc, int event_code, int duration); |
solenberg | 4bac9c5 | 2015-10-09 09:32:53 | [diff] [blame] | 449 | bool SetOutputVolume(uint32_t ssrc, double volume); |
deadbeef | 2d110be | 2016-01-13 20:00:26 | [diff] [blame] | 450 | void SetRawAudioSink(uint32_t ssrc, |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 451 | std::unique_ptr<webrtc::AudioSinkInterface> sink); |
Taylor Brandstetter | db0cd9e | 2016-05-16 18:40:30 | [diff] [blame] | 452 | webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const; |
| 453 | bool SetRtpSendParameters(uint32_t ssrc, |
| 454 | const webrtc::RtpParameters& parameters); |
| 455 | webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const; |
| 456 | bool SetRtpReceiveParameters(uint32_t ssrc, |
| 457 | const webrtc::RtpParameters& parameters); |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 458 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 459 | // Get statistics about the current media session. |
| 460 | bool GetStats(VoiceMediaInfo* stats); |
| 461 | |
| 462 | // Monitoring functions |
| 463 | sigslot::signal2<VoiceChannel*, const std::vector<ConnectionInfo>&> |
| 464 | SignalConnectionMonitor; |
| 465 | |
| 466 | void StartMediaMonitor(int cms); |
| 467 | void StopMediaMonitor(); |
| 468 | sigslot::signal2<VoiceChannel*, const VoiceMediaInfo&> SignalMediaMonitor; |
| 469 | |
| 470 | void StartAudioMonitor(int cms); |
| 471 | void StopAudioMonitor(); |
| 472 | bool IsAudioMonitorRunning() const; |
| 473 | sigslot::signal2<VoiceChannel*, const AudioInfo&> SignalAudioMonitor; |
| 474 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 475 | int GetInputLevel_w(); |
| 476 | int GetOutputLevel_w(); |
| 477 | void GetActiveStreams_w(AudioInfo::StreamList* actives); |
Taylor Brandstetter | db0cd9e | 2016-05-16 18:40:30 | [diff] [blame] | 478 | webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const; |
| 479 | bool SetRtpSendParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters); |
| 480 | webrtc::RtpParameters GetRtpReceiveParameters_w(uint32_t ssrc) const; |
| 481 | bool SetRtpReceiveParameters_w(uint32_t ssrc, |
| 482 | webrtc::RtpParameters parameters); |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 483 | cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_AUDIO; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 484 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 485 | private: |
| 486 | // overrides from BaseChannel |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 487 | void OnChannelRead(TransportChannel* channel, |
| 488 | const char* data, |
| 489 | size_t len, |
| 490 | const rtc::PacketTime& packet_time, |
| 491 | int flags) override; |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 492 | void UpdateMediaSendRecvState_w() override; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 493 | const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override; |
| 494 | bool SetLocalContent_w(const MediaContentDescription* content, |
| 495 | ContentAction action, |
| 496 | std::string* error_desc) override; |
| 497 | bool SetRemoteContent_w(const MediaContentDescription* content, |
| 498 | ContentAction action, |
| 499 | std::string* error_desc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 500 | void HandleEarlyMediaTimeout(); |
solenberg | 1d63dd0 | 2015-12-02 20:35:09 | [diff] [blame] | 501 | bool InsertDtmf_w(uint32_t ssrc, int event, int duration); |
solenberg | 4bac9c5 | 2015-10-09 09:32:53 | [diff] [blame] | 502 | bool SetOutputVolume_w(uint32_t ssrc, double volume); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 503 | bool GetStats_w(VoiceMediaInfo* stats); |
| 504 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 505 | void OnMessage(rtc::Message* pmsg) override; |
| 506 | void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override; |
| 507 | void OnConnectionMonitorUpdate( |
| 508 | ConnectionMonitor* monitor, |
| 509 | const std::vector<ConnectionInfo>& infos) override; |
| 510 | void OnMediaMonitorUpdate(VoiceMediaChannel* media_channel, |
| 511 | const VoiceMediaInfo& info); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 512 | void OnAudioMonitorUpdate(AudioMonitor* monitor, const AudioInfo& info); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 513 | |
| 514 | static const int kEarlyMediaTimeout = 1000; |
Fredrik Solenberg | 0c02264 | 2015-08-05 10:25:22 | [diff] [blame] | 515 | MediaEngineInterface* media_engine_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 516 | bool received_media_; |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 517 | std::unique_ptr<VoiceMediaMonitor> media_monitor_; |
| 518 | std::unique_ptr<AudioMonitor> audio_monitor_; |
Peter Thatcher | c2ee2c8 | 2015-08-07 23:05:34 | [diff] [blame] | 519 | |
| 520 | // Last AudioSendParameters sent down to the media_channel() via |
| 521 | // SetSendParameters. |
| 522 | AudioSendParameters last_send_params_; |
| 523 | // Last AudioRecvParameters sent down to the media_channel() via |
| 524 | // SetRecvParameters. |
| 525 | AudioRecvParameters last_recv_params_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 526 | }; |
| 527 | |
| 528 | // VideoChannel is a specialization for video. |
| 529 | class VideoChannel : public BaseChannel { |
| 530 | public: |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 531 | VideoChannel(rtc::Thread* worker_thread, |
| 532 | rtc::Thread* netwokr_thread, |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 533 | VideoMediaChannel* channel, |
| 534 | TransportController* transport_controller, |
| 535 | const std::string& content_name, |
Fredrik Solenberg | 0c02264 | 2015-08-05 10:25:22 | [diff] [blame] | 536 | bool rtcp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 537 | ~VideoChannel(); |
skvlad | 6c87a67 | 2016-05-18 00:49:52 | [diff] [blame] | 538 | bool Init_w(const std::string* bundle_transport_name); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 539 | |
Fredrik Solenberg | 4b60c73 | 2015-05-07 12:07:48 | [diff] [blame] | 540 | // downcasts a MediaChannel |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 541 | VideoMediaChannel* media_channel() const override { |
Fredrik Solenberg | 4b60c73 | 2015-05-07 12:07:48 | [diff] [blame] | 542 | return static_cast<VideoMediaChannel*>(BaseChannel::media_channel()); |
| 543 | } |
| 544 | |
nisse | 08582ff | 2016-02-04 09:24:52 | [diff] [blame] | 545 | bool SetSink(uint32_t ssrc, rtc::VideoSinkInterface<VideoFrame>* sink); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 546 | // Get statistics about the current media session. |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 | [diff] [blame] | 547 | bool GetStats(VideoMediaInfo* stats); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 548 | |
| 549 | sigslot::signal2<VideoChannel*, const std::vector<ConnectionInfo>&> |
| 550 | SignalConnectionMonitor; |
| 551 | |
| 552 | void StartMediaMonitor(int cms); |
| 553 | void StopMediaMonitor(); |
| 554 | sigslot::signal2<VideoChannel*, const VideoMediaInfo&> SignalMediaMonitor; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 555 | |
deadbeef | 5a4a75a | 2016-06-02 23:23:38 | [diff] [blame] | 556 | // Register a source and set options. |
| 557 | // The |ssrc| must correspond to a registered send stream. |
| 558 | bool SetVideoSend(uint32_t ssrc, |
| 559 | bool enable, |
| 560 | const VideoOptions* options, |
| 561 | rtc::VideoSourceInterface<cricket::VideoFrame>* source); |
Taylor Brandstetter | db0cd9e | 2016-05-16 18:40:30 | [diff] [blame] | 562 | webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const; |
| 563 | bool SetRtpSendParameters(uint32_t ssrc, |
| 564 | const webrtc::RtpParameters& parameters); |
| 565 | webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const; |
| 566 | bool SetRtpReceiveParameters(uint32_t ssrc, |
| 567 | const webrtc::RtpParameters& parameters); |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 568 | cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_VIDEO; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 569 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 570 | private: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 571 | // overrides from BaseChannel |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 572 | void UpdateMediaSendRecvState_w() override; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 573 | const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override; |
| 574 | bool SetLocalContent_w(const MediaContentDescription* content, |
| 575 | ContentAction action, |
| 576 | std::string* error_desc) override; |
| 577 | bool SetRemoteContent_w(const MediaContentDescription* content, |
| 578 | ContentAction action, |
| 579 | std::string* error_desc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 580 | bool GetStats_w(VideoMediaInfo* stats); |
Taylor Brandstetter | db0cd9e | 2016-05-16 18:40:30 | [diff] [blame] | 581 | webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const; |
| 582 | bool SetRtpSendParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters); |
| 583 | webrtc::RtpParameters GetRtpReceiveParameters_w(uint32_t ssrc) const; |
| 584 | bool SetRtpReceiveParameters_w(uint32_t ssrc, |
| 585 | webrtc::RtpParameters parameters); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 586 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 587 | void OnMessage(rtc::Message* pmsg) override; |
| 588 | void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override; |
| 589 | void OnConnectionMonitorUpdate( |
| 590 | ConnectionMonitor* monitor, |
| 591 | const std::vector<ConnectionInfo>& infos) override; |
| 592 | void OnMediaMonitorUpdate(VideoMediaChannel* media_channel, |
| 593 | const VideoMediaInfo& info); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 594 | |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 595 | std::unique_ptr<VideoMediaMonitor> media_monitor_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 596 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 23:05:34 | [diff] [blame] | 597 | // Last VideoSendParameters sent down to the media_channel() via |
| 598 | // SetSendParameters. |
| 599 | VideoSendParameters last_send_params_; |
| 600 | // Last VideoRecvParameters sent down to the media_channel() via |
| 601 | // SetRecvParameters. |
| 602 | VideoRecvParameters last_recv_params_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 603 | }; |
| 604 | |
| 605 | // DataChannel is a specialization for data. |
| 606 | class DataChannel : public BaseChannel { |
| 607 | public: |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 608 | DataChannel(rtc::Thread* worker_thread, |
| 609 | rtc::Thread* network_thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 610 | DataMediaChannel* media_channel, |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 611 | TransportController* transport_controller, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 612 | const std::string& content_name, |
| 613 | bool rtcp); |
| 614 | ~DataChannel(); |
skvlad | 6c87a67 | 2016-05-18 00:49:52 | [diff] [blame] | 615 | bool Init_w(const std::string* bundle_transport_name); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 616 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 | [diff] [blame] | 617 | virtual bool SendData(const SendDataParams& params, |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 618 | const rtc::CopyOnWriteBuffer& payload, |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 | [diff] [blame] | 619 | SendDataResult* result); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 620 | |
| 621 | void StartMediaMonitor(int cms); |
| 622 | void StopMediaMonitor(); |
| 623 | |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 | [diff] [blame] | 624 | // Should be called on the signaling thread only. |
| 625 | bool ready_to_send_data() const { |
| 626 | return ready_to_send_data_; |
| 627 | } |
| 628 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 629 | sigslot::signal2<DataChannel*, const DataMediaInfo&> SignalMediaMonitor; |
| 630 | sigslot::signal2<DataChannel*, const std::vector<ConnectionInfo>&> |
| 631 | SignalConnectionMonitor; |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 632 | sigslot::signal3<DataChannel*, const ReceiveDataParams&, |
| 633 | const rtc::CopyOnWriteBuffer&> SignalDataReceived; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 634 | // Signal for notifying when the channel becomes ready to send data. |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 | [diff] [blame] | 635 | // That occurs when the channel is enabled, the transport is writable, |
| 636 | // both local and remote descriptions are set, and the channel is unblocked. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 637 | sigslot::signal1<bool> SignalReadyToSendData; |
buildbot@webrtc.org | 1d66be2 | 2014-05-29 22:54:24 | [diff] [blame] | 638 | // Signal for notifying that the remote side has closed the DataChannel. |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 639 | sigslot::signal1<uint32_t> SignalStreamClosedRemotely; |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 640 | cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_DATA; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 641 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 642 | protected: |
| 643 | // downcasts a MediaChannel. |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 644 | DataMediaChannel* media_channel() const override { |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 645 | return static_cast<DataMediaChannel*>(BaseChannel::media_channel()); |
| 646 | } |
| 647 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 648 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 649 | struct SendDataMessageData : public rtc::MessageData { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 650 | SendDataMessageData(const SendDataParams& params, |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 651 | const rtc::CopyOnWriteBuffer* payload, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 652 | SendDataResult* result) |
| 653 | : params(params), |
| 654 | payload(payload), |
| 655 | result(result), |
| 656 | succeeded(false) { |
| 657 | } |
| 658 | |
| 659 | const SendDataParams& params; |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 660 | const rtc::CopyOnWriteBuffer* payload; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 661 | SendDataResult* result; |
| 662 | bool succeeded; |
| 663 | }; |
| 664 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 665 | struct DataReceivedMessageData : public rtc::MessageData { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 666 | // We copy the data because the data will become invalid after we |
| 667 | // handle DataMediaChannel::SignalDataReceived but before we fire |
| 668 | // SignalDataReceived. |
| 669 | DataReceivedMessageData( |
| 670 | const ReceiveDataParams& params, const char* data, size_t len) |
| 671 | : params(params), |
| 672 | payload(data, len) { |
| 673 | } |
| 674 | const ReceiveDataParams params; |
jbauch | eec21bd | 2016-03-20 13:15:43 | [diff] [blame] | 675 | const rtc::CopyOnWriteBuffer payload; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 676 | }; |
| 677 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 678 | typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 | [diff] [blame] | 679 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 680 | // overrides from BaseChannel |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 681 | const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 682 | // If data_channel_type_ is DCT_NONE, set it. Otherwise, check that |
| 683 | // it's the same as what was set previously. Returns false if it's |
| 684 | // set to one type one type and changed to another type later. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 685 | bool SetDataChannelType(DataChannelType new_data_channel_type, |
| 686 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 687 | // Same as SetDataChannelType, but extracts the type from the |
| 688 | // DataContentDescription. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 | [diff] [blame] | 689 | bool SetDataChannelTypeFromContent(const DataContentDescription* content, |
| 690 | std::string* error_desc); |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 691 | bool SetLocalContent_w(const MediaContentDescription* content, |
| 692 | ContentAction action, |
| 693 | std::string* error_desc) override; |
| 694 | bool SetRemoteContent_w(const MediaContentDescription* content, |
| 695 | ContentAction action, |
| 696 | std::string* error_desc) override; |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 697 | void UpdateMediaSendRecvState_w() override; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 698 | bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 699 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 700 | void OnMessage(rtc::Message* pmsg) override; |
| 701 | void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override; |
| 702 | void OnConnectionMonitorUpdate( |
| 703 | ConnectionMonitor* monitor, |
| 704 | const std::vector<ConnectionInfo>& infos) override; |
| 705 | void OnMediaMonitorUpdate(DataMediaChannel* media_channel, |
| 706 | const DataMediaInfo& info); |
| 707 | bool ShouldSetupDtlsSrtp_n() const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 708 | void OnDataReceived( |
| 709 | const ReceiveDataParams& params, const char* data, size_t len); |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 710 | void OnDataChannelError(uint32_t ssrc, DataMediaChannel::Error error); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 | [diff] [blame] | 711 | void OnDataChannelReadyToSend(bool writable); |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 712 | void OnStreamClosedRemotely(uint32_t sid); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 713 | |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 714 | std::unique_ptr<DataMediaMonitor> media_monitor_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 715 | // TODO(pthatcher): Make a separate SctpDataChannel and |
| 716 | // RtpDataChannel instead of using this. |
| 717 | DataChannelType data_channel_type_; |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 | [diff] [blame] | 718 | bool ready_to_send_data_; |
Peter Thatcher | c2ee2c8 | 2015-08-07 23:05:34 | [diff] [blame] | 719 | |
| 720 | // Last DataSendParameters sent down to the media_channel() via |
| 721 | // SetSendParameters. |
| 722 | DataSendParameters last_send_params_; |
| 723 | // Last DataRecvParameters sent down to the media_channel() via |
| 724 | // SetRecvParameters. |
| 725 | DataRecvParameters last_recv_params_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 726 | }; |
| 727 | |
| 728 | } // namespace cricket |
| 729 | |
perkj | c11b184 | 2016-03-08 01:34:13 | [diff] [blame] | 730 | #endif // WEBRTC_PC_CHANNEL_H_ |