henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [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 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef PC_CHANNEL_H_ |
| 12 | #define PC_CHANNEL_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 14 | #include <map> |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 15 | #include <memory> |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 16 | #include <set> |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 17 | #include <string> |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 18 | #include <utility> |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 19 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 20 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "api/call/audio_sink.h" |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 22 | #include "api/jsep.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "api/rtpreceiverinterface.h" |
Patrik Höglund | be214a2 | 2018-01-04 12:14:35 +0100 | [diff] [blame] | 24 | #include "api/videosinkinterface.h" |
Patrik Höglund | 9e19403 | 2018-01-04 15:58:20 +0100 | [diff] [blame] | 25 | #include "api/videosourceinterface.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "media/base/mediachannel.h" |
| 27 | #include "media/base/mediaengine.h" |
| 28 | #include "media/base/streamparams.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 29 | #include "p2p/base/dtlstransportinternal.h" |
| 30 | #include "p2p/base/packettransportinternal.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 31 | #include "pc/audiomonitor.h" |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 32 | #include "pc/dtlssrtptransport.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 33 | #include "pc/mediasession.h" |
| 34 | #include "pc/rtcpmuxfilter.h" |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 35 | #include "pc/rtptransport.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 36 | #include "pc/srtpfilter.h" |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 37 | #include "pc/srtptransport.h" |
Zhi Huang | b526158 | 2017-09-29 10:51:43 -0700 | [diff] [blame] | 38 | #include "pc/transportcontroller.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 39 | #include "rtc_base/asyncinvoker.h" |
| 40 | #include "rtc_base/asyncudpsocket.h" |
| 41 | #include "rtc_base/criticalsection.h" |
| 42 | #include "rtc_base/network.h" |
| 43 | #include "rtc_base/sigslot.h" |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 44 | |
| 45 | namespace webrtc { |
| 46 | class AudioSinkInterface; |
| 47 | } // namespace webrtc |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 48 | |
| 49 | namespace cricket { |
| 50 | |
| 51 | struct CryptoParams; |
| 52 | class MediaContentDescription; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 53 | |
deadbeef | 062ce9f | 2016-08-26 21:42:15 -0700 | [diff] [blame] | 54 | // BaseChannel contains logic common to voice and video, including enable, |
| 55 | // marshaling calls to a worker and network threads, and connection and media |
| 56 | // monitors. |
| 57 | // |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 58 | // BaseChannel assumes signaling and other threads are allowed to make |
| 59 | // synchronous calls to the worker thread, the worker thread makes synchronous |
| 60 | // calls only to the network thread, and the network thread can't be blocked by |
| 61 | // other threads. |
| 62 | // All methods with _n suffix must be called on network thread, |
deadbeef | 062ce9f | 2016-08-26 21:42:15 -0700 | [diff] [blame] | 63 | // methods with _w suffix on worker thread |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 64 | // and methods with _s suffix on signaling thread. |
| 65 | // Network and worker threads may be the same thread. |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 66 | // |
| 67 | // WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS! |
| 68 | // This is required to avoid a data race between the destructor modifying the |
| 69 | // vtable, and the media channel's thread using BaseChannel as the |
| 70 | // NetworkInterface. |
| 71 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | class BaseChannel |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 73 | : public rtc::MessageHandler, public sigslot::has_slots<>, |
Niels Möller | e2a9318 | 2018-01-17 14:18:27 +0100 | [diff] [blame] | 74 | public MediaChannel::NetworkInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | public: |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 76 | // If |srtp_required| is true, the channel will not send or receive any |
| 77 | // RTP/RTCP packets without using SRTP (either using SDES or DTLS-SRTP). |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 78 | BaseChannel(rtc::Thread* worker_thread, |
| 79 | rtc::Thread* network_thread, |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 80 | rtc::Thread* signaling_thread, |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 81 | std::unique_ptr<MediaChannel> media_channel, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 82 | const std::string& content_name, |
deadbeef | ac22f70 | 2017-01-12 21:59:29 -0800 | [diff] [blame] | 83 | bool rtcp_mux_required, |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 84 | bool srtp_required); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | virtual ~BaseChannel(); |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 86 | // TODO(zhihuang): Remove this once the RtpTransport can be shared between |
| 87 | // BaseChannels. |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 88 | void Init_w(DtlsTransportInternal* rtp_dtls_transport, |
deadbeef | f534659 | 2017-01-24 21:51:21 -0800 | [diff] [blame] | 89 | DtlsTransportInternal* rtcp_dtls_transport, |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 90 | rtc::PacketTransportInternal* rtp_packet_transport, |
| 91 | rtc::PacketTransportInternal* rtcp_packet_transport); |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 92 | void Init_w(webrtc::RtpTransportInternal* rtp_transport); |
| 93 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 94 | // Deinit may be called multiple times and is simply ignored if it's already |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 95 | // done. |
| 96 | void Deinit(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 97 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 98 | rtc::Thread* worker_thread() const { return worker_thread_; } |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 99 | rtc::Thread* network_thread() const { return network_thread_; } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 100 | const std::string& content_name() const { return content_name_; } |
deadbeef | f534659 | 2017-01-24 21:51:21 -0800 | [diff] [blame] | 101 | // TODO(deadbeef): This is redundant; remove this. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 102 | const std::string& transport_name() const { return transport_name_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 103 | bool enabled() const { return enabled_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 104 | |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 105 | // This function returns true if we are using SDES. |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 106 | bool sdes_active() const { |
| 107 | return sdes_transport_ && sdes_negotiator_.IsActive(); |
| 108 | } |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 109 | // The following function returns true if we are using DTLS-based keying. |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 110 | bool dtls_active() const { |
| 111 | return dtls_srtp_transport_ && dtls_srtp_transport_->IsActive(); |
| 112 | } |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 113 | // This function returns true if using SRTP (DTLS-based keying or SDES). |
| 114 | bool srtp_active() const { return sdes_active() || dtls_active(); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 115 | |
| 116 | bool writable() const { return writable_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 117 | |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 118 | // Set an RTP level transport which could be an RtpTransport without |
| 119 | // encryption, an SrtpTransport for SDES or a DtlsSrtpTransport for DTLS-SRTP. |
| 120 | // This can be called from any thread and it hops to the network thread |
| 121 | // internally. It would replace the |SetTransports| and its variants. |
| 122 | void SetRtpTransport(webrtc::RtpTransportInternal* rtp_transport); |
| 123 | |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 124 | // Set the transport(s), and update writability and "ready-to-send" state. |
| 125 | // |rtp_transport| must be non-null. |
| 126 | // |rtcp_transport| must be supplied if NeedsRtcpTransport() is true (meaning |
| 127 | // RTCP muxing is not fully active yet). |
| 128 | // |rtp_transport| and |rtcp_transport| must share the same transport name as |
| 129 | // well. |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 130 | // Can not start with "rtc::PacketTransportInternal" and switch to |
deadbeef | f534659 | 2017-01-24 21:51:21 -0800 | [diff] [blame] | 131 | // "DtlsTransportInternal", or vice-versa. |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 132 | // TODO(zhihuang): Remove these two once the RtpTransport can be shared |
| 133 | // between BaseChannels. |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 134 | void SetTransports(DtlsTransportInternal* rtp_dtls_transport, |
| 135 | DtlsTransportInternal* rtcp_dtls_transport); |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 136 | void SetTransports(rtc::PacketTransportInternal* rtp_packet_transport, |
| 137 | rtc::PacketTransportInternal* rtcp_packet_transport); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 138 | // Channel control |
| 139 | bool SetLocalContent(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 140 | webrtc::SdpType type, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 141 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 142 | bool SetRemoteContent(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 143 | webrtc::SdpType type, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 144 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 145 | |
| 146 | bool Enable(bool enable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 147 | |
| 148 | // Multiplexing |
| 149 | bool AddRecvStream(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 150 | bool RemoveRecvStream(uint32_t ssrc); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 151 | bool AddSendStream(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 152 | bool RemoveSendStream(uint32_t ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 153 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 154 | const std::vector<StreamParams>& local_streams() const { |
| 155 | return local_streams_; |
| 156 | } |
| 157 | const std::vector<StreamParams>& remote_streams() const { |
| 158 | return remote_streams_; |
| 159 | } |
| 160 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 161 | sigslot::signal2<BaseChannel*, bool> SignalDtlsSrtpSetupFailure; |
| 162 | void SignalDtlsSrtpSetupFailure_n(bool rtcp); |
| 163 | void SignalDtlsSrtpSetupFailure_s(bool rtcp); |
pthatcher@webrtc.org | 4eeef58 | 2015-03-16 19:34:23 +0000 | [diff] [blame] | 164 | |
buildbot@webrtc.org | 6bfd619 | 2014-05-15 16:15:59 +0000 | [diff] [blame] | 165 | // Used for latency measurements. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 166 | sigslot::signal1<BaseChannel*> SignalFirstPacketReceived; |
| 167 | |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 168 | // Forward SignalSentPacket to worker thread. |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 169 | sigslot::signal1<const rtc::SentPacket&> SignalSentPacket; |
| 170 | |
deadbeef | ac22f70 | 2017-01-12 21:59:29 -0800 | [diff] [blame] | 171 | // Emitted whenever rtcp-mux is fully negotiated and the rtcp-transport can |
| 172 | // be destroyed. |
| 173 | // Fired on the network thread. |
| 174 | sigslot::signal1<const std::string&> SignalRtcpMuxFullyActive; |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 175 | |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 176 | // Only public for unit tests. Otherwise, consider private. |
| 177 | DtlsTransportInternal* rtp_dtls_transport() const { |
| 178 | return rtp_dtls_transport_; |
| 179 | } |
| 180 | DtlsTransportInternal* rtcp_dtls_transport() const { |
| 181 | return rtcp_dtls_transport_; |
| 182 | } |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 183 | |
| 184 | bool NeedsRtcpTransport(); |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 185 | |
zstein | 56162b9 | 2017-04-24 16:54:35 -0700 | [diff] [blame] | 186 | // From RtpTransport - public for testing only |
| 187 | void OnTransportReadyToSend(bool ready); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 188 | |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 189 | // Only public for unit tests. Otherwise, consider protected. |
rlester | ec9d187 | 2015-10-27 14:22:16 -0700 | [diff] [blame] | 190 | int SetOption(SocketType type, rtc::Socket::Option o, int val) |
| 191 | override; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 192 | int SetOption_n(SocketType type, rtc::Socket::Option o, int val); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 193 | |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 194 | virtual cricket::MediaType media_type() = 0; |
| 195 | |
zstein | 3dcf0e9 | 2017-06-01 13:22:42 -0700 | [diff] [blame] | 196 | // Public for testing. |
| 197 | // TODO(zstein): Remove this once channels register themselves with |
| 198 | // an RtpTransport in a more explicit way. |
| 199 | bool HandlesPayloadType(int payload_type) const; |
| 200 | |
Steve Anton | 593e325 | 2017-12-15 11:44:48 -0800 | [diff] [blame] | 201 | // Used by the RTCStatsCollector tests to set the transport name without |
| 202 | // creating RtpTransports. |
| 203 | void set_transport_name_for_testing(const std::string& transport_name) { |
| 204 | transport_name_ = transport_name; |
| 205 | } |
| 206 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 207 | protected: |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 208 | virtual MediaChannel* media_channel() const { return media_channel_.get(); } |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 209 | |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 210 | void SetTransports_n(DtlsTransportInternal* rtp_dtls_transport, |
deadbeef | f534659 | 2017-01-24 21:51:21 -0800 | [diff] [blame] | 211 | DtlsTransportInternal* rtcp_dtls_transport, |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 212 | rtc::PacketTransportInternal* rtp_packet_transport, |
| 213 | rtc::PacketTransportInternal* rtcp_packet_transport); |
guoweis | 4638331 | 2015-12-17 16:45:59 -0800 | [diff] [blame] | 214 | |
deadbeef | 062ce9f | 2016-08-26 21:42:15 -0700 | [diff] [blame] | 215 | // This does not update writability or "ready-to-send" state; it just |
| 216 | // disconnects from the old channel and connects to the new one. |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 217 | // TODO(zhihuang): Remove this once the RtpTransport can be shared between |
| 218 | // BaseChannels. |
deadbeef | f534659 | 2017-01-24 21:51:21 -0800 | [diff] [blame] | 219 | void SetTransport_n(bool rtcp, |
| 220 | DtlsTransportInternal* new_dtls_transport, |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 221 | rtc::PacketTransportInternal* new_packet_transport); |
guoweis | 4638331 | 2015-12-17 16:45:59 -0800 | [diff] [blame] | 222 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 223 | bool was_ever_writable() const { return was_ever_writable_; } |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 224 | void set_local_content_direction(webrtc::RtpTransceiverDirection direction) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 225 | local_content_direction_ = direction; |
| 226 | } |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 227 | void set_remote_content_direction(webrtc::RtpTransceiverDirection direction) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 228 | remote_content_direction_ = direction; |
| 229 | } |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 230 | // These methods verify that: |
| 231 | // * The required content description directions have been set. |
| 232 | // * The channel is enabled. |
| 233 | // * And for sending: |
| 234 | // - The SRTP filter is active if it's needed. |
| 235 | // - The transport has been writable before, meaning it should be at least |
| 236 | // possible to succeed in sending a packet. |
| 237 | // |
| 238 | // When any of these properties change, UpdateMediaSendRecvState_w should be |
| 239 | // called. |
| 240 | bool IsReadyToReceiveMedia_w() const; |
| 241 | bool IsReadyToSendMedia_w() const; |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 242 | rtc::Thread* signaling_thread() { return signaling_thread_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 243 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 244 | void FlushRtcpMessages_n(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 245 | |
| 246 | // NetworkInterface implementation, called by MediaEngine |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 247 | bool SendPacket(rtc::CopyOnWriteBuffer* packet, |
| 248 | const rtc::PacketOptions& options) override; |
| 249 | bool SendRtcp(rtc::CopyOnWriteBuffer* packet, |
| 250 | const rtc::PacketOptions& options) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 251 | |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 252 | // From RtpTransportInternal |
| 253 | void OnWritableState(bool writable); |
Guo-wei Shieh | 1218d7a | 2015-12-05 09:59:56 -0800 | [diff] [blame] | 254 | |
Zhi Huang | 942bc2e | 2017-11-13 13:26:07 -0800 | [diff] [blame] | 255 | void OnNetworkRouteChanged(rtc::Optional<rtc::NetworkRoute> network_route); |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 256 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 257 | bool PacketIsRtcp(const rtc::PacketTransportInternal* transport, |
johan | d89ab14 | 2016-10-25 10:50:32 -0700 | [diff] [blame] | 258 | const char* data, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 259 | size_t len); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 260 | bool SendPacket(bool rtcp, |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 261 | rtc::CopyOnWriteBuffer* packet, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 262 | const rtc::PacketOptions& options); |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 263 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 264 | bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet); |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 265 | void HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 266 | const rtc::PacketTime& packet_time); |
zstein | 3dcf0e9 | 2017-06-01 13:22:42 -0700 | [diff] [blame] | 267 | // TODO(zstein): packet can be const once the RtpTransport handles protection. |
| 268 | virtual void OnPacketReceived(bool rtcp, |
zstein | 634977b | 2017-07-14 12:30:04 -0700 | [diff] [blame] | 269 | rtc::CopyOnWriteBuffer* packet, |
zstein | 3dcf0e9 | 2017-06-01 13:22:42 -0700 | [diff] [blame] | 270 | const rtc::PacketTime& packet_time); |
| 271 | void ProcessPacket(bool rtcp, |
| 272 | const rtc::CopyOnWriteBuffer& packet, |
| 273 | const rtc::PacketTime& packet_time); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 274 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 275 | void EnableMedia_w(); |
| 276 | void DisableMedia_w(); |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 277 | |
| 278 | // Performs actions if the RTP/RTCP writable state changed. This should |
| 279 | // be called whenever a channel's writable state changes or when RTCP muxing |
| 280 | // becomes active/inactive. |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 281 | void UpdateWritableState_n(); |
| 282 | void ChannelWritable_n(); |
| 283 | void ChannelNotWritable_n(); |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 284 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 285 | bool AddRecvStream_w(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 286 | bool RemoveRecvStream_w(uint32_t ssrc); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 287 | bool AddSendStream_w(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 288 | bool RemoveSendStream_w(uint32_t ssrc); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 289 | bool ShouldSetupDtlsSrtp_n() const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 290 | // Do the DTLS key expansion and impose it on the SRTP/SRTCP filters. |
| 291 | // |rtcp_channel| indicates whether to set up the RTP or RTCP filter. |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 292 | bool SetupDtlsSrtp_n(bool rtcp); |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 293 | void MaybeSetupDtlsSrtp_n(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 294 | |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 295 | // Should be called whenever the conditions for |
| 296 | // IsReadyToReceiveMedia/IsReadyToSendMedia are satisfied (or unsatisfied). |
| 297 | // Updates the send/recv state of the media channel. |
| 298 | void UpdateMediaSendRecvState(); |
| 299 | virtual void UpdateMediaSendRecvState_w() = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 300 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 301 | bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 302 | webrtc::SdpType type, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 303 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 304 | bool UpdateRemoteStreams_w(const std::vector<StreamParams>& streams, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 305 | webrtc::SdpType type, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 306 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 307 | virtual bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 308 | webrtc::SdpType type, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 309 | std::string* error_desc) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 310 | virtual bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 311 | webrtc::SdpType type, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 312 | std::string* error_desc) = 0; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 313 | bool SetRtpTransportParameters(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 314 | webrtc::SdpType type, |
| 315 | ContentSource src, |
| 316 | const RtpHeaderExtensions& extensions, |
| 317 | std::string* error_desc); |
| 318 | bool SetRtpTransportParameters_n( |
| 319 | const MediaContentDescription* content, |
| 320 | webrtc::SdpType type, |
| 321 | ContentSource src, |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 322 | const std::vector<int>& encrypted_extension_ids, |
| 323 | std::string* error_desc); |
| 324 | |
| 325 | // Return a list of RTP header extensions with the non-encrypted extensions |
| 326 | // removed depending on the current crypto_options_ and only if both the |
| 327 | // non-encrypted and encrypted extension is present for the same URI. |
| 328 | RtpHeaderExtensions GetFilteredRtpHeaderExtensions( |
| 329 | const RtpHeaderExtensions& extensions); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 330 | |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 331 | // Helper method to get RTP Absoulute SendTime extension header id if |
| 332 | // present in remote supported extensions list. |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 333 | void MaybeCacheRtpAbsSendTimeHeaderExtension_w( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 334 | const std::vector<webrtc::RtpExtension>& extensions); |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 335 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 336 | bool CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos, |
| 337 | bool* dtls, |
| 338 | std::string* error_desc); |
| 339 | bool SetSrtp_n(const std::vector<CryptoParams>& params, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 340 | webrtc::SdpType type, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 341 | ContentSource src, |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 342 | const std::vector<int>& encrypted_extension_ids, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 343 | std::string* error_desc); |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 344 | bool SetRtcpMux_n(bool enable, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 345 | webrtc::SdpType type, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 346 | ContentSource src, |
| 347 | std::string* error_desc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 348 | |
| 349 | // From MessageHandler |
rlester | ec9d187 | 2015-10-27 14:22:16 -0700 | [diff] [blame] | 350 | void OnMessage(rtc::Message* pmsg) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 351 | |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 352 | // Helper function template for invoking methods on the worker thread. |
| 353 | template <class T, class FunctorT> |
| 354 | T InvokeOnWorker(const rtc::Location& posted_from, const FunctorT& functor) { |
| 355 | return worker_thread_->Invoke<T>(posted_from, functor); |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 356 | } |
| 357 | |
zstein | 3dcf0e9 | 2017-06-01 13:22:42 -0700 | [diff] [blame] | 358 | void AddHandledPayloadType(int payload_type); |
| 359 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 360 | private: |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 361 | void ConnectToRtpTransport(); |
| 362 | void DisconnectFromRtpTransport(); |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 363 | void SignalSentPacket_n(const rtc::SentPacket& sent_packet); |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 364 | void SignalSentPacket_w(const rtc::SentPacket& sent_packet); |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 365 | bool IsReadyToSendMedia_n() const; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 366 | void CacheRtpAbsSendTimeHeaderExtension_n(int rtp_abs_sendtime_extn_id); |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 367 | // Wraps the existing RtpTransport in an SrtpTransport. |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 368 | void EnableSdes_n(); |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 369 | |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 370 | // Wraps the existing RtpTransport in a new SrtpTransport and wraps that in a |
| 371 | // new DtlsSrtpTransport. |
| 372 | void EnableDtlsSrtp_n(); |
| 373 | |
| 374 | // Update the encrypted header extension IDs when setting the local/remote |
Zhi Huang | c99b6c7 | 2017-11-10 16:44:46 -0800 | [diff] [blame] | 375 | // description and use them later together with other crypto parameters from |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 376 | // DtlsTransport. If DTLS-SRTP is enabled, it also update the encrypted header |
| 377 | // extension IDs for DtlsSrtpTransport. |
| 378 | void UpdateEncryptedHeaderExtensionIds(cricket::ContentSource source, |
| 379 | const std::vector<int>& extension_ids); |
Zhi Huang | c99b6c7 | 2017-11-10 16:44:46 -0800 | [diff] [blame] | 380 | |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 381 | // Permanently enable RTCP muxing. Set null RTCP PacketTransport for |
| 382 | // BaseChannel and RtpTransport. If using DTLS-SRTP, set null DtlsTransport |
| 383 | // for DtlsSrtpTransport. |
| 384 | void ActivateRtcpMux(); |
Zhi Huang | c99b6c7 | 2017-11-10 16:44:46 -0800 | [diff] [blame] | 385 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 386 | rtc::Thread* const worker_thread_; |
| 387 | rtc::Thread* const network_thread_; |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 388 | rtc::Thread* const signaling_thread_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 389 | rtc::AsyncInvoker invoker_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 390 | |
pthatcher@webrtc.org | 990a00c | 2015-03-13 18:20:33 +0000 | [diff] [blame] | 391 | const std::string content_name_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 392 | |
deadbeef | f534659 | 2017-01-24 21:51:21 -0800 | [diff] [blame] | 393 | // Won't be set when using raw packet transports. SDP-specific thing. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 394 | std::string transport_name_; |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 395 | |
zstein | 56162b9 | 2017-04-24 16:54:35 -0700 | [diff] [blame] | 396 | const bool rtcp_mux_required_; |
| 397 | |
deadbeef | f534659 | 2017-01-24 21:51:21 -0800 | [diff] [blame] | 398 | // Separate DTLS/non-DTLS pointers to support using BaseChannel without DTLS. |
| 399 | // Temporary measure until more refactoring is done. |
| 400 | // If non-null, "X_dtls_transport_" will always equal "X_packet_transport_". |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 401 | DtlsTransportInternal* rtp_dtls_transport_ = nullptr; |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 402 | DtlsTransportInternal* rtcp_dtls_transport_ = nullptr; |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 403 | |
| 404 | webrtc::RtpTransportInternal* rtp_transport_ = nullptr; |
| 405 | // Only one of these transports is non-null at a time. One for DTLS-SRTP, one |
| 406 | // for SDES and one for unencrypted RTP. |
| 407 | std::unique_ptr<webrtc::SrtpTransport> sdes_transport_; |
| 408 | std::unique_ptr<webrtc::DtlsSrtpTransport> dtls_srtp_transport_; |
| 409 | std::unique_ptr<webrtc::RtpTransport> unencrypted_rtp_transport_; |
| 410 | |
deadbeef | f534659 | 2017-01-24 21:51:21 -0800 | [diff] [blame] | 411 | std::vector<std::pair<rtc::Socket::Option, int> > socket_options_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 412 | std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 413 | SrtpFilter sdes_negotiator_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 414 | RtcpMuxFilter rtcp_mux_filter_; |
deadbeef | 23d947d | 2016-08-22 16:00:30 -0700 | [diff] [blame] | 415 | bool writable_ = false; |
| 416 | bool was_ever_writable_ = false; |
| 417 | bool has_received_packet_ = false; |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 418 | const bool srtp_required_ = true; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 419 | |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 420 | // MediaChannel related members that should be accessed from the worker |
| 421 | // thread. |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 422 | std::unique_ptr<MediaChannel> media_channel_; |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 423 | // Currently the |enabled_| flag is accessed from the signaling thread as |
| 424 | // well, but it can be changed only when signaling thread does a synchronous |
| 425 | // call to the worker thread, so it should be safe. |
deadbeef | 23d947d | 2016-08-22 16:00:30 -0700 | [diff] [blame] | 426 | bool enabled_ = false; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 427 | std::vector<StreamParams> local_streams_; |
| 428 | std::vector<StreamParams> remote_streams_; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 429 | webrtc::RtpTransceiverDirection local_content_direction_ = |
| 430 | webrtc::RtpTransceiverDirection::kInactive; |
| 431 | webrtc::RtpTransceiverDirection remote_content_direction_ = |
| 432 | webrtc::RtpTransceiverDirection::kInactive; |
Zhi Huang | c99b6c7 | 2017-11-10 16:44:46 -0800 | [diff] [blame] | 433 | |
| 434 | // The cached encrypted header extension IDs. |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 435 | rtc::Optional<std::vector<int>> cached_send_extension_ids_; |
| 436 | rtc::Optional<std::vector<int>> cached_recv_extension_ids_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 437 | }; |
| 438 | |
| 439 | // VoiceChannel is a specialization that adds support for early media, DTMF, |
| 440 | // and input/output level monitoring. |
| 441 | class VoiceChannel : public BaseChannel { |
| 442 | public: |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 443 | VoiceChannel(rtc::Thread* worker_thread, |
| 444 | rtc::Thread* network_thread, |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 445 | rtc::Thread* signaling_thread, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 446 | MediaEngineInterface* media_engine, |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 447 | std::unique_ptr<VoiceMediaChannel> channel, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 448 | const std::string& content_name, |
deadbeef | ac22f70 | 2017-01-12 21:59:29 -0800 | [diff] [blame] | 449 | bool rtcp_mux_required, |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 450 | bool srtp_required); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 451 | ~VoiceChannel(); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 452 | |
| 453 | // Configure sending media on the stream with SSRC |ssrc| |
| 454 | // If there is only one sending stream SSRC 0 can be used. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 455 | bool SetAudioSend(uint32_t ssrc, |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 456 | bool enable, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 457 | const AudioOptions* options, |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 458 | AudioSource* source); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 459 | |
| 460 | // downcasts a MediaChannel |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 461 | VoiceMediaChannel* media_channel() const override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 462 | return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel()); |
| 463 | } |
| 464 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 465 | void SetEarlyMedia(bool enable); |
| 466 | // This signal is emitted when we have gone a period of time without |
| 467 | // receiving early media. When received, a UI should start playing its |
| 468 | // own ringing sound |
| 469 | sigslot::signal1<VoiceChannel*> SignalEarlyMediaTimeout; |
| 470 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 471 | // Get statistics about the current media session. |
| 472 | bool GetStats(VoiceMediaInfo* stats); |
| 473 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 474 | webrtc::RtpParameters GetRtpSendParameters_w(uint32_t ssrc) const; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 475 | webrtc::RTCError SetRtpSendParameters_w(uint32_t ssrc, |
| 476 | webrtc::RtpParameters parameters); |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 477 | cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_AUDIO; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 478 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 479 | private: |
| 480 | // overrides from BaseChannel |
zstein | 3dcf0e9 | 2017-06-01 13:22:42 -0700 | [diff] [blame] | 481 | void OnPacketReceived(bool rtcp, |
zstein | 634977b | 2017-07-14 12:30:04 -0700 | [diff] [blame] | 482 | rtc::CopyOnWriteBuffer* packet, |
zstein | 3dcf0e9 | 2017-06-01 13:22:42 -0700 | [diff] [blame] | 483 | const rtc::PacketTime& packet_time) override; |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 484 | void UpdateMediaSendRecvState_w() override; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 485 | bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 486 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 487 | std::string* error_desc) override; |
| 488 | bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 489 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 490 | std::string* error_desc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 491 | void HandleEarlyMediaTimeout(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 492 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 493 | void OnMessage(rtc::Message* pmsg) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 494 | |
| 495 | static const int kEarlyMediaTimeout = 1000; |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 496 | bool received_media_ = false; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 497 | |
| 498 | // Last AudioSendParameters sent down to the media_channel() via |
| 499 | // SetSendParameters. |
| 500 | AudioSendParameters last_send_params_; |
| 501 | // Last AudioRecvParameters sent down to the media_channel() via |
| 502 | // SetRecvParameters. |
| 503 | AudioRecvParameters last_recv_params_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 504 | }; |
| 505 | |
| 506 | // VideoChannel is a specialization for video. |
| 507 | class VideoChannel : public BaseChannel { |
| 508 | public: |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 509 | VideoChannel(rtc::Thread* worker_thread, |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 510 | rtc::Thread* network_thread, |
| 511 | rtc::Thread* signaling_thread, |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 512 | std::unique_ptr<VideoMediaChannel> media_channel, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 513 | const std::string& content_name, |
deadbeef | ac22f70 | 2017-01-12 21:59:29 -0800 | [diff] [blame] | 514 | bool rtcp_mux_required, |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 515 | bool srtp_required); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 516 | ~VideoChannel(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 517 | |
Fredrik Solenberg | 4b60c73 | 2015-05-07 14:07:48 +0200 | [diff] [blame] | 518 | // downcasts a MediaChannel |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 519 | VideoMediaChannel* media_channel() const override { |
Fredrik Solenberg | 4b60c73 | 2015-05-07 14:07:48 +0200 | [diff] [blame] | 520 | return static_cast<VideoMediaChannel*>(BaseChannel::media_channel()); |
| 521 | } |
| 522 | |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 523 | void FillBitrateInfo(BandwidthEstimationInfo* bwe_info); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 524 | // Get statistics about the current media session. |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 525 | bool GetStats(VideoMediaInfo* stats); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 526 | |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 527 | cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_VIDEO; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 528 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 529 | private: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 530 | // overrides from BaseChannel |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 531 | void UpdateMediaSendRecvState_w() override; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 532 | bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 533 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 534 | std::string* error_desc) override; |
| 535 | bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 536 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 537 | std::string* error_desc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 538 | bool GetStats_w(VideoMediaInfo* stats); |
| 539 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 540 | // Last VideoSendParameters sent down to the media_channel() via |
| 541 | // SetSendParameters. |
| 542 | VideoSendParameters last_send_params_; |
| 543 | // Last VideoRecvParameters sent down to the media_channel() via |
| 544 | // SetRecvParameters. |
| 545 | VideoRecvParameters last_recv_params_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 546 | }; |
| 547 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 548 | // RtpDataChannel is a specialization for data. |
| 549 | class RtpDataChannel : public BaseChannel { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 550 | public: |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 551 | RtpDataChannel(rtc::Thread* worker_thread, |
| 552 | rtc::Thread* network_thread, |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 553 | rtc::Thread* signaling_thread, |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 554 | std::unique_ptr<DataMediaChannel> channel, |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 555 | const std::string& content_name, |
deadbeef | ac22f70 | 2017-01-12 21:59:29 -0800 | [diff] [blame] | 556 | bool rtcp_mux_required, |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 557 | bool srtp_required); |
| 558 | ~RtpDataChannel(); |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 559 | // TODO(zhihuang): Remove this once the RtpTransport can be shared between |
| 560 | // BaseChannels. |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 561 | void Init_w(DtlsTransportInternal* rtp_dtls_transport, |
deadbeef | f534659 | 2017-01-24 21:51:21 -0800 | [diff] [blame] | 562 | DtlsTransportInternal* rtcp_dtls_transport, |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 563 | rtc::PacketTransportInternal* rtp_packet_transport, |
| 564 | rtc::PacketTransportInternal* rtcp_packet_transport); |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 565 | void Init_w(webrtc::RtpTransportInternal* rtp_transport); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 566 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 567 | virtual bool SendData(const SendDataParams& params, |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 568 | const rtc::CopyOnWriteBuffer& payload, |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 569 | SendDataResult* result); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 570 | |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 571 | // Should be called on the signaling thread only. |
| 572 | bool ready_to_send_data() const { |
| 573 | return ready_to_send_data_; |
| 574 | } |
| 575 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 576 | sigslot::signal2<const ReceiveDataParams&, const rtc::CopyOnWriteBuffer&> |
| 577 | SignalDataReceived; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 578 | // Signal for notifying when the channel becomes ready to send data. |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 579 | // That occurs when the channel is enabled, the transport is writable, |
| 580 | // both local and remote descriptions are set, and the channel is unblocked. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 581 | sigslot::signal1<bool> SignalReadyToSendData; |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 582 | cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_DATA; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 583 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 584 | protected: |
| 585 | // downcasts a MediaChannel. |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 586 | DataMediaChannel* media_channel() const override { |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 587 | return static_cast<DataMediaChannel*>(BaseChannel::media_channel()); |
| 588 | } |
| 589 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 590 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 591 | struct SendDataMessageData : public rtc::MessageData { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 592 | SendDataMessageData(const SendDataParams& params, |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 593 | const rtc::CopyOnWriteBuffer* payload, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 594 | SendDataResult* result) |
| 595 | : params(params), |
| 596 | payload(payload), |
| 597 | result(result), |
| 598 | succeeded(false) { |
| 599 | } |
| 600 | |
| 601 | const SendDataParams& params; |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 602 | const rtc::CopyOnWriteBuffer* payload; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 603 | SendDataResult* result; |
| 604 | bool succeeded; |
| 605 | }; |
| 606 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 607 | struct DataReceivedMessageData : public rtc::MessageData { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 608 | // We copy the data because the data will become invalid after we |
| 609 | // handle DataMediaChannel::SignalDataReceived but before we fire |
| 610 | // SignalDataReceived. |
| 611 | DataReceivedMessageData( |
| 612 | const ReceiveDataParams& params, const char* data, size_t len) |
| 613 | : params(params), |
| 614 | payload(data, len) { |
| 615 | } |
| 616 | const ReceiveDataParams params; |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 617 | const rtc::CopyOnWriteBuffer payload; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 618 | }; |
| 619 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 620 | typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 621 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 622 | // overrides from BaseChannel |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 623 | // Checks that data channel type is RTP. |
| 624 | bool CheckDataChannelTypeFromContent(const DataContentDescription* content, |
| 625 | std::string* error_desc); |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 626 | bool SetLocalContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 627 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 628 | std::string* error_desc) override; |
| 629 | bool SetRemoteContent_w(const MediaContentDescription* content, |
Steve Anton | 3828c06 | 2017-12-06 10:34:51 -0800 | [diff] [blame] | 630 | webrtc::SdpType type, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 631 | std::string* error_desc) override; |
Taylor Brandstetter | bad33bf | 2016-08-25 13:31:14 -0700 | [diff] [blame] | 632 | void UpdateMediaSendRecvState_w() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 633 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 634 | void OnMessage(rtc::Message* pmsg) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 635 | void OnDataReceived( |
| 636 | const ReceiveDataParams& params, const char* data, size_t len); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 637 | void OnDataChannelReadyToSend(bool writable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 638 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 639 | bool ready_to_send_data_ = false; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 640 | |
| 641 | // Last DataSendParameters sent down to the media_channel() via |
| 642 | // SetSendParameters. |
| 643 | DataSendParameters last_send_params_; |
| 644 | // Last DataRecvParameters sent down to the media_channel() via |
| 645 | // SetRecvParameters. |
| 646 | DataRecvParameters last_recv_params_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 647 | }; |
| 648 | |
| 649 | } // namespace cricket |
| 650 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 651 | #endif // PC_CHANNEL_H_ |