Thanks to visit codestin.com
Credit goes to webrtc.googlesource.com

blob: 51cc40fc53abe04fe54d68d349a39a85243211de [file] [log] [blame]
[email protected]28e20752013-07-10 00:45:361/*
kjellander65c7f672016-02-12 08:05:012 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
[email protected]28e20752013-07-10 00:45:363 *
kjellander65c7f672016-02-12 08:05:014 * 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.
[email protected]28e20752013-07-10 00:45:369 */
10
Mirko Bonadei92ea95e2017-09-15 04:47:3111#ifndef PC_CHANNEL_H_
12#define PC_CHANNEL_H_
[email protected]28e20752013-07-10 00:45:3613
deadbeefcbecd352015-09-23 18:50:2714#include <map>
kwiberg31022942016-03-11 22:18:2115#include <memory>
deadbeefcbecd352015-09-23 18:50:2716#include <set>
kjellandera96e2d72016-02-05 07:52:2817#include <string>
deadbeefcbecd352015-09-23 18:50:2718#include <utility>
kjellandera96e2d72016-02-05 07:52:2819#include <vector>
[email protected]28e20752013-07-10 00:45:3620
Mirko Bonadei92ea95e2017-09-15 04:47:3121#include "api/call/audio_sink.h"
Danil Chapovalov89313452019-11-29 11:56:4322#include "api/function_view.h"
Steve Anton3828c062017-12-06 18:34:5123#include "api/jsep.h"
Steve Anton10542f22019-01-11 17:11:0024#include "api/rtp_receiver_interface.h"
Niels Möllerc6ce9c52018-05-11 09:15:3025#include "api/video/video_sink_interface.h"
Niels Möller0327c2d2018-05-21 12:09:3126#include "api/video/video_source_interface.h"
Zhi Huang365381f2018-04-13 23:44:3427#include "call/rtp_packet_sink_interface.h"
Steve Anton10542f22019-01-11 17:11:0028#include "media/base/media_channel.h"
29#include "media/base/media_engine.h"
30#include "media/base/stream_params.h"
31#include "p2p/base/dtls_transport_internal.h"
32#include "p2p/base/packet_transport_internal.h"
33#include "pc/channel_interface.h"
34#include "pc/dtls_srtp_transport.h"
35#include "pc/media_session.h"
36#include "pc/rtp_transport.h"
37#include "pc/srtp_filter.h"
38#include "pc/srtp_transport.h"
39#include "rtc_base/async_invoker.h"
40#include "rtc_base/async_udp_socket.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3141#include "rtc_base/network.h"
Taylor Brandstetterc03a1872020-09-02 20:25:3142#include "rtc_base/synchronization/sequence_checker.h"
Artem Titove41c4332018-07-25 13:04:2843#include "rtc_base/third_party/sigslot/sigslot.h"
Taylor Brandstetterc03a1872020-09-02 20:25:3144#include "rtc_base/thread_annotations.h"
Amit Hilbuchbcd39d42019-01-26 01:13:5645#include "rtc_base/unique_id_generator.h"
Tommif888bb52015-12-12 00:37:0146
47namespace webrtc {
48class AudioSinkInterface;
49} // namespace webrtc
[email protected]28e20752013-07-10 00:45:3650
51namespace cricket {
52
53struct CryptoParams;
[email protected]28e20752013-07-10 00:45:3654
deadbeef062ce9f2016-08-27 04:42:1555// BaseChannel contains logic common to voice and video, including enable,
56// marshaling calls to a worker and network threads, and connection and media
57// monitors.
58//
Danil Chapovalov33b01f22016-05-11 17:55:2759// BaseChannel assumes signaling and other threads are allowed to make
60// synchronous calls to the worker thread, the worker thread makes synchronous
61// calls only to the network thread, and the network thread can't be blocked by
62// other threads.
63// All methods with _n suffix must be called on network thread,
deadbeef062ce9f2016-08-27 04:42:1564// methods with _w suffix on worker thread
Danil Chapovalov33b01f22016-05-11 17:55:2765// and methods with _s suffix on signaling thread.
66// Network and worker threads may be the same thread.
[email protected]78187522013-10-07 23:32:0267//
68// WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS!
69// This is required to avoid a data race between the destructor modifying the
70// vtable, and the media channel's thread using BaseChannel as the
71// NetworkInterface.
72
Amit Hilbuchdd9390c2018-11-14 00:26:0573class BaseChannel : public ChannelInterface,
Tomas Gunnarssonabdb4702020-09-05 16:43:3674 public rtc::MessageHandlerAutoCleanup,
Zhi Huang365381f2018-04-13 23:44:3475 public sigslot::has_slots<>,
76 public MediaChannel::NetworkInterface,
Bjorn A Mellem7a9a0922019-11-26 17:19:4077 public webrtc::RtpPacketSinkInterface {
[email protected]28e20752013-07-10 00:45:3678 public:
deadbeef7af91dd2016-12-13 19:29:1179 // If |srtp_required| is true, the channel will not send or receive any
80 // RTP/RTCP packets without using SRTP (either using SDES or DTLS-SRTP).
Amit Hilbuchbcd39d42019-01-26 01:13:5681 // The BaseChannel does not own the UniqueRandomIdGenerator so it is the
82 // responsibility of the user to ensure it outlives this object.
Zhi Huange830e682018-03-30 17:48:3583 // TODO(zhihuang:) Create a BaseChannel::Config struct for the parameter lists
84 // which will make it easier to change the constructor.
Danil Chapovalov33b01f22016-05-11 17:55:2785 BaseChannel(rtc::Thread* worker_thread,
86 rtc::Thread* network_thread,
zhihuangf5b251b2017-01-13 03:37:4887 rtc::Thread* signaling_thread,
Steve Anton8699a322017-11-06 23:53:3388 std::unique_ptr<MediaChannel> media_channel,
deadbeefcbecd352015-09-23 18:50:2789 const std::string& content_name,
Zhi Huange830e682018-03-30 17:48:3590 bool srtp_required,
Amit Hilbuchbcd39d42019-01-26 01:13:5691 webrtc::CryptoOptions crypto_options,
92 rtc::UniqueRandomIdGenerator* ssrc_generator);
[email protected]28e20752013-07-10 00:45:3693 virtual ~BaseChannel();
Niels Möller2a707032020-06-16 14:39:1394 virtual void Init_w(webrtc::RtpTransportInternal* rtp_transport);
Zhi Huang2dfc42d2017-12-04 21:38:4895
Danil Chapovalov33b01f22016-05-11 17:55:2796 // Deinit may be called multiple times and is simply ignored if it's already
[email protected]78187522013-10-07 23:32:0297 // done.
98 void Deinit();
[email protected]28e20752013-07-10 00:45:3699
[email protected]d4e598d2014-07-29 17:36:52100 rtc::Thread* worker_thread() const { return worker_thread_; }
Danil Chapovalov33b01f22016-05-11 17:55:27101 rtc::Thread* network_thread() const { return network_thread_; }
Amit Hilbuchdd9390c2018-11-14 00:26:05102 const std::string& content_name() const override { return content_name_; }
deadbeeff5346592017-01-25 05:51:21103 // TODO(deadbeef): This is redundant; remove this.
Amit Hilbuchdd9390c2018-11-14 00:26:05104 const std::string& transport_name() const override { return transport_name_; }
105 bool enabled() const override { return enabled_; }
[email protected]28e20752013-07-10 00:45:36106
Zhi Huangcf990f52017-09-22 19:12:30107 // This function returns true if using SRTP (DTLS-based keying or SDES).
Zhi Huange830e682018-03-30 17:48:35108 bool srtp_active() const {
109 return rtp_transport_ && rtp_transport_->IsSrtpActive();
110 }
[email protected]28e20752013-07-10 00:45:36111
112 bool writable() const { return writable_; }
[email protected]28e20752013-07-10 00:45:36113
Zhi Huang2dfc42d2017-12-04 21:38:48114 // Set an RTP level transport which could be an RtpTransport without
115 // encryption, an SrtpTransport for SDES or a DtlsSrtpTransport for DTLS-SRTP.
116 // This can be called from any thread and it hops to the network thread
117 // internally. It would replace the |SetTransports| and its variants.
Amit Hilbuchdd9390c2018-11-14 00:26:05118 bool SetRtpTransport(webrtc::RtpTransportInternal* rtp_transport) override;
Zhi Huang2dfc42d2017-12-04 21:38:48119
Bjorn A Mellem3a1b9272019-05-24 23:13:08120 webrtc::RtpTransportInternal* rtp_transport() const { return rtp_transport_; }
121
[email protected]28e20752013-07-10 00:45:36122 // Channel control
123 bool SetLocalContent(const MediaContentDescription* content,
Steve Anton3828c062017-12-06 18:34:51124 webrtc::SdpType type,
Amit Hilbuchdd9390c2018-11-14 00:26:05125 std::string* error_desc) override;
[email protected]28e20752013-07-10 00:45:36126 bool SetRemoteContent(const MediaContentDescription* content,
Steve Anton3828c062017-12-06 18:34:51127 webrtc::SdpType type,
Amit Hilbuchdd9390c2018-11-14 00:26:05128 std::string* error_desc) override;
Taylor Brandstetterc03a1872020-09-02 20:25:31129 // Controls whether this channel will receive packets on the basis of
130 // matching payload type alone. This is needed for legacy endpoints that
131 // don't signal SSRCs or use MID/RID, but doesn't make sense if there is
132 // more than channel of specific media type, As that creates an ambiguity.
133 //
134 // This method will also remove any existing streams that were bound to this
135 // channel on the basis of payload type, since one of these streams might
136 // actually belong to a new channel. See: crbug.com/webrtc/11477
Taylor Brandstetterd3ef4992020-10-16 01:22:57137 bool SetPayloadTypeDemuxingEnabled(bool enabled) override;
[email protected]28e20752013-07-10 00:45:36138
Amit Hilbuchdd9390c2018-11-14 00:26:05139 bool Enable(bool enable) override;
[email protected]28e20752013-07-10 00:45:36140
Amit Hilbuchbcd39d42019-01-26 01:13:56141 const std::vector<StreamParams>& local_streams() const override {
[email protected]28e20752013-07-10 00:45:36142 return local_streams_;
143 }
Amit Hilbuchbcd39d42019-01-26 01:13:56144 const std::vector<StreamParams>& remote_streams() const override {
[email protected]28e20752013-07-10 00:45:36145 return remote_streams_;
146 }
147
[email protected]6bfd6192014-05-15 16:15:59148 // Used for latency measurements.
Tomas Gunnarssonb2995a12020-09-28 12:05:35149 sigslot::signal1<ChannelInterface*>& SignalFirstPacketReceived() override;
[email protected]28e20752013-07-10 00:45:36150
zhihuangb2cdd932017-01-20 00:54:25151 // Forward SignalSentPacket to worker thread.
Tomas Gunnarssonb2995a12020-09-28 12:05:35152 sigslot::signal1<const rtc::SentPacket&>& SignalSentPacket();
zhihuangf5b251b2017-01-13 03:37:48153
zstein56162b92017-04-24 23:54:35154 // From RtpTransport - public for testing only
155 void OnTransportReadyToSend(bool ready);
[email protected]28e20752013-07-10 00:45:36156
[email protected]4f852882015-03-12 20:09:44157 // Only public for unit tests. Otherwise, consider protected.
Yves Gerey665174f2018-06-19 13:03:05158 int SetOption(SocketType type, rtc::Socket::Option o, int val) override;
Danil Chapovalov33b01f22016-05-11 17:55:27159 int SetOption_n(SocketType type, rtc::Socket::Option o, int val);
[email protected]4f852882015-03-12 20:09:44160
Zhi Huang365381f2018-04-13 23:44:34161 // RtpPacketSinkInterface overrides.
162 void OnRtpPacket(const webrtc::RtpPacketReceived& packet) override;
zstein3dcf0e92017-06-01 20:22:42163
Steve Anton593e3252017-12-15 19:44:48164 // Used by the RTCStatsCollector tests to set the transport name without
165 // creating RtpTransports.
166 void set_transport_name_for_testing(const std::string& transport_name) {
167 transport_name_ = transport_name;
168 }
169
Amit Hilbuchdd9390c2018-11-14 00:26:05170 MediaChannel* media_channel() const override { return media_channel_.get(); }
Taylor Brandstetterbad33bf2016-08-25 20:31:14171
Amit Hilbuchdd9390c2018-11-14 00:26:05172 protected:
[email protected]28e20752013-07-10 00:45:36173 bool was_ever_writable() const { return was_ever_writable_; }
Steve Anton4e70a722017-11-28 22:57:10174 void set_local_content_direction(webrtc::RtpTransceiverDirection direction) {
[email protected]28e20752013-07-10 00:45:36175 local_content_direction_ = direction;
176 }
Steve Anton4e70a722017-11-28 22:57:10177 void set_remote_content_direction(webrtc::RtpTransceiverDirection direction) {
[email protected]28e20752013-07-10 00:45:36178 remote_content_direction_ = direction;
179 }
Taylor Brandstetterbad33bf2016-08-25 20:31:14180 // These methods verify that:
181 // * The required content description directions have been set.
182 // * The channel is enabled.
183 // * And for sending:
184 // - The SRTP filter is active if it's needed.
185 // - The transport has been writable before, meaning it should be at least
186 // possible to succeed in sending a packet.
187 //
188 // When any of these properties change, UpdateMediaSendRecvState_w should be
189 // called.
190 bool IsReadyToReceiveMedia_w() const;
191 bool IsReadyToSendMedia_w() const;
zhihuangf5b251b2017-01-13 03:37:48192 rtc::Thread* signaling_thread() { return signaling_thread_; }
[email protected]28e20752013-07-10 00:45:36193
Danil Chapovalov33b01f22016-05-11 17:55:27194 void FlushRtcpMessages_n();
[email protected]28e20752013-07-10 00:45:36195
196 // NetworkInterface implementation, called by MediaEngine
jbaucheec21bd2016-03-20 13:15:43197 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
198 const rtc::PacketOptions& options) override;
199 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
200 const rtc::PacketOptions& options) override;
[email protected]28e20752013-07-10 00:45:36201
Zhi Huangcd3fc5d2017-11-29 18:41:57202 // From RtpTransportInternal
203 void OnWritableState(bool writable);
Guo-wei Shieh1218d7a2015-12-05 17:59:56204
Danil Chapovalov66cadcc2018-06-19 14:47:43205 void OnNetworkRouteChanged(absl::optional<rtc::NetworkRoute> network_route);
Honghai Zhangcc411c02016-03-30 00:27:21206
deadbeef5bd5ca32017-02-10 19:31:50207 bool PacketIsRtcp(const rtc::PacketTransportInternal* transport,
johand89ab142016-10-25 17:50:32208 const char* data,
[email protected]28e20752013-07-10 00:45:36209 size_t len);
stefanc1aeaf02015-10-15 14:26:07210 bool SendPacket(bool rtcp,
jbaucheec21bd2016-03-20 13:15:43211 rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 14:26:07212 const rtc::PacketOptions& options);
Danil Chapovalov33b01f22016-05-11 17:55:27213
[email protected]28e20752013-07-10 00:45:36214 void EnableMedia_w();
215 void DisableMedia_w();
Taylor Brandstetterbad33bf2016-08-25 20:31:14216
217 // Performs actions if the RTP/RTCP writable state changed. This should
218 // be called whenever a channel's writable state changes or when RTCP muxing
219 // becomes active/inactive.
Danil Chapovalov33b01f22016-05-11 17:55:27220 void UpdateWritableState_n();
221 void ChannelWritable_n();
222 void ChannelNotWritable_n();
Taylor Brandstetterbad33bf2016-08-25 20:31:14223
[email protected]28e20752013-07-10 00:45:36224 bool AddRecvStream_w(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 10:23:21225 bool RemoveRecvStream_w(uint32_t ssrc);
Saurav Dasff27da52019-09-20 18:05:30226 void ResetUnsignaledRecvStream_w();
Taylor Brandstetterd3ef4992020-10-16 01:22:57227 bool SetPayloadTypeDemuxingEnabled_w(bool enabled);
[email protected]cadf9042013-08-30 21:24:16228 bool AddSendStream_w(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 10:23:21229 bool RemoveSendStream_w(uint32_t ssrc);
[email protected]28e20752013-07-10 00:45:36230
Taylor Brandstetterbad33bf2016-08-25 20:31:14231 // Should be called whenever the conditions for
232 // IsReadyToReceiveMedia/IsReadyToSendMedia are satisfied (or unsatisfied).
233 // Updates the send/recv state of the media channel.
234 void UpdateMediaSendRecvState();
235 virtual void UpdateMediaSendRecvState_w() = 0;
[email protected]28e20752013-07-10 00:45:36236
[email protected]28e20752013-07-10 00:45:36237 bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams,
Steve Anton3828c062017-12-06 18:34:51238 webrtc::SdpType type,
[email protected]4b26e2e2014-01-15 23:15:54239 std::string* error_desc);
[email protected]28e20752013-07-10 00:45:36240 bool UpdateRemoteStreams_w(const std::vector<StreamParams>& streams,
Steve Anton3828c062017-12-06 18:34:51241 webrtc::SdpType type,
[email protected]4b26e2e2014-01-15 23:15:54242 std::string* error_desc);
[email protected]28e20752013-07-10 00:45:36243 virtual bool SetLocalContent_w(const MediaContentDescription* content,
Steve Anton3828c062017-12-06 18:34:51244 webrtc::SdpType type,
[email protected]4b26e2e2014-01-15 23:15:54245 std::string* error_desc) = 0;
[email protected]28e20752013-07-10 00:45:36246 virtual bool SetRemoteContent_w(const MediaContentDescription* content,
Steve Anton3828c062017-12-06 18:34:51247 webrtc::SdpType type,
[email protected]4b26e2e2014-01-15 23:15:54248 std::string* error_desc) = 0;
jbauch5869f502017-06-29 19:31:36249 // Return a list of RTP header extensions with the non-encrypted extensions
250 // removed depending on the current crypto_options_ and only if both the
251 // non-encrypted and encrypted extension is present for the same URI.
252 RtpHeaderExtensions GetFilteredRtpHeaderExtensions(
253 const RtpHeaderExtensions& extensions);
[email protected]28e20752013-07-10 00:45:36254
[email protected]28e20752013-07-10 00:45:36255 // From MessageHandler
rlesterec9d1872015-10-27 21:22:16256 void OnMessage(rtc::Message* pmsg) override;
[email protected]28e20752013-07-10 00:45:36257
stefanf79ade12017-06-02 13:44:03258 // Helper function template for invoking methods on the worker thread.
Danil Chapovalov89313452019-11-29 11:56:43259 template <class T>
260 T InvokeOnWorker(const rtc::Location& posted_from,
261 rtc::FunctionView<T()> functor) {
stefanf79ade12017-06-02 13:44:03262 return worker_thread_->Invoke<T>(posted_from, functor);
[email protected]9cf037b2014-02-07 19:03:26263 }
264
Taylor Brandstetterc03a1872020-09-02 20:25:31265 // Add |payload_type| to |demuxer_criteria_| if payload type demuxing is
266 // enabled.
267 void MaybeAddHandledPayloadType(int payload_type) RTC_RUN_ON(worker_thread());
zstein3dcf0e92017-06-01 20:22:42268
Taylor Brandstetterc03a1872020-09-02 20:25:31269 void ClearHandledPayloadTypes() RTC_RUN_ON(worker_thread());
Steve Antonbe2e5f72019-09-06 23:26:02270
Zhi Huang365381f2018-04-13 23:44:34271 void UpdateRtpHeaderExtensionMap(
272 const RtpHeaderExtensions& header_extensions);
273
274 bool RegisterRtpDemuxerSink();
275
Yura Yaroshevichc3252462020-05-18 10:26:14276 // Return description of media channel to facilitate logging
277 std::string ToString() const;
278
Piotr (Peter) Slatala309aafe2019-01-15 22:24:34279 bool has_received_packet_ = false;
280
[email protected]28e20752013-07-10 00:45:36281 private:
Zhi Huang365381f2018-04-13 23:44:34282 bool ConnectToRtpTransport();
Zhi Huangcd3fc5d2017-11-29 18:41:57283 void DisconnectFromRtpTransport();
Zhi Huangcd3fc5d2017-11-29 18:41:57284 void SignalSentPacket_n(const rtc::SentPacket& sent_packet);
Taylor Brandstetterbad33bf2016-08-25 20:31:14285 bool IsReadyToSendMedia_n() const;
Piotr (Peter) Slatala179a3922018-11-16 17:57:58286
Danil Chapovalov33b01f22016-05-11 17:55:27287 rtc::Thread* const worker_thread_;
288 rtc::Thread* const network_thread_;
zhihuangf5b251b2017-01-13 03:37:48289 rtc::Thread* const signaling_thread_;
Danil Chapovalov33b01f22016-05-11 17:55:27290 rtc::AsyncInvoker invoker_;
Tomas Gunnarssonb2995a12020-09-28 12:05:35291 sigslot::signal1<ChannelInterface*> SignalFirstPacketReceived_
292 RTC_GUARDED_BY(signaling_thread_);
293 sigslot::signal1<const rtc::SentPacket&> SignalSentPacket_
294 RTC_GUARDED_BY(worker_thread_);
[email protected]28e20752013-07-10 00:45:36295
[email protected]990a00c2015-03-13 18:20:33296 const std::string content_name_;
Danil Chapovalov33b01f22016-05-11 17:55:27297
deadbeeff5346592017-01-25 05:51:21298 // Won't be set when using raw packet transports. SDP-specific thing.
deadbeefcbecd352015-09-23 18:50:27299 std::string transport_name_;
zhihuangb2cdd932017-01-20 00:54:25300
Zhi Huangcd3fc5d2017-11-29 18:41:57301 webrtc::RtpTransportInternal* rtp_transport_ = nullptr;
Zhi Huangcd3fc5d2017-11-29 18:41:57302
deadbeeff5346592017-01-25 05:51:21303 std::vector<std::pair<rtc::Socket::Option, int> > socket_options_;
deadbeefcbecd352015-09-23 18:50:27304 std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_;
deadbeef23d947d2016-08-22 23:00:30305 bool writable_ = false;
306 bool was_ever_writable_ = false;
deadbeef7af91dd2016-12-13 19:29:11307 const bool srtp_required_ = true;
Benjamin Wrighta54daf12018-10-11 22:33:17308 webrtc::CryptoOptions crypto_options_;
Danil Chapovalov33b01f22016-05-11 17:55:27309
Taylor Brandstetterbad33bf2016-08-25 20:31:14310 // MediaChannel related members that should be accessed from the worker
311 // thread.
Steve Anton8699a322017-11-06 23:53:33312 std::unique_ptr<MediaChannel> media_channel_;
Taylor Brandstetterbad33bf2016-08-25 20:31:14313 // Currently the |enabled_| flag is accessed from the signaling thread as
314 // well, but it can be changed only when signaling thread does a synchronous
315 // call to the worker thread, so it should be safe.
deadbeef23d947d2016-08-22 23:00:30316 bool enabled_ = false;
Taylor Brandstetterc03a1872020-09-02 20:25:31317 bool payload_type_demuxing_enabled_ RTC_GUARDED_BY(worker_thread()) = true;
Danil Chapovalov33b01f22016-05-11 17:55:27318 std::vector<StreamParams> local_streams_;
319 std::vector<StreamParams> remote_streams_;
Steve Anton4e70a722017-11-28 22:57:10320 webrtc::RtpTransceiverDirection local_content_direction_ =
321 webrtc::RtpTransceiverDirection::kInactive;
322 webrtc::RtpTransceiverDirection remote_content_direction_ =
323 webrtc::RtpTransceiverDirection::kInactive;
Zhi Huangc99b6c72017-11-11 00:44:46324
Taylor Brandstetterd3ef4992020-10-16 01:22:57325 // Cached list of payload types, used if payload type demuxing is re-enabled.
326 std::set<uint8_t> payload_types_ RTC_GUARDED_BY(worker_thread());
Zhi Huang365381f2018-04-13 23:44:34327 webrtc::RtpDemuxerCriteria demuxer_criteria_;
Amit Hilbuchbcd39d42019-01-26 01:13:56328 // This generator is used to generate SSRCs for local streams.
329 // This is needed in cases where SSRCs are not negotiated or set explicitly
330 // like in Simulcast.
331 // This object is not owned by the channel so it must outlive it.
332 rtc::UniqueRandomIdGenerator* const ssrc_generator_;
[email protected]28e20752013-07-10 00:45:36333};
334
335// VoiceChannel is a specialization that adds support for early media, DTMF,
336// and input/output level monitoring.
Bjorn A Mellem7a9a0922019-11-26 17:19:40337class VoiceChannel : public BaseChannel {
[email protected]28e20752013-07-10 00:45:36338 public:
Danil Chapovalov33b01f22016-05-11 17:55:27339 VoiceChannel(rtc::Thread* worker_thread,
340 rtc::Thread* network_thread,
zhihuangf5b251b2017-01-13 03:37:48341 rtc::Thread* signaling_thread,
Steve Anton8699a322017-11-06 23:53:33342 std::unique_ptr<VoiceMediaChannel> channel,
deadbeefcbecd352015-09-23 18:50:27343 const std::string& content_name,
Zhi Huange830e682018-03-30 17:48:35344 bool srtp_required,
Amit Hilbuchbcd39d42019-01-26 01:13:56345 webrtc::CryptoOptions crypto_options,
346 rtc::UniqueRandomIdGenerator* ssrc_generator);
[email protected]28e20752013-07-10 00:45:36347 ~VoiceChannel();
solenberg1dd98f32015-09-10 08:57:14348
[email protected]28e20752013-07-10 00:45:36349 // downcasts a MediaChannel
Danil Chapovalov33b01f22016-05-11 17:55:27350 VoiceMediaChannel* media_channel() const override {
[email protected]28e20752013-07-10 00:45:36351 return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel());
352 }
353
Amit Hilbuchdd9390c2018-11-14 00:26:05354 cricket::MediaType media_type() const override {
355 return cricket::MEDIA_TYPE_AUDIO;
356 }
Niels Möller2a707032020-06-16 14:39:13357 void Init_w(webrtc::RtpTransportInternal* rtp_transport) override;
[email protected]28e20752013-07-10 00:45:36358
[email protected]28e20752013-07-10 00:45:36359 private:
360 // overrides from BaseChannel
Taylor Brandstetterbad33bf2016-08-25 20:31:14361 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 17:55:27362 bool SetLocalContent_w(const MediaContentDescription* content,
Steve Anton3828c062017-12-06 18:34:51363 webrtc::SdpType type,
Danil Chapovalov33b01f22016-05-11 17:55:27364 std::string* error_desc) override;
365 bool SetRemoteContent_w(const MediaContentDescription* content,
Steve Anton3828c062017-12-06 18:34:51366 webrtc::SdpType type,
Danil Chapovalov33b01f22016-05-11 17:55:27367 std::string* error_desc) override;
Peter Thatcherc2ee2c82015-08-07 23:05:34368
369 // Last AudioSendParameters sent down to the media_channel() via
370 // SetSendParameters.
371 AudioSendParameters last_send_params_;
372 // Last AudioRecvParameters sent down to the media_channel() via
373 // SetRecvParameters.
374 AudioRecvParameters last_recv_params_;
[email protected]28e20752013-07-10 00:45:36375};
376
377// VideoChannel is a specialization for video.
378class VideoChannel : public BaseChannel {
379 public:
Danil Chapovalov33b01f22016-05-11 17:55:27380 VideoChannel(rtc::Thread* worker_thread,
zhihuangf5b251b2017-01-13 03:37:48381 rtc::Thread* network_thread,
382 rtc::Thread* signaling_thread,
Steve Anton8699a322017-11-06 23:53:33383 std::unique_ptr<VideoMediaChannel> media_channel,
deadbeefcbecd352015-09-23 18:50:27384 const std::string& content_name,
Zhi Huange830e682018-03-30 17:48:35385 bool srtp_required,
Amit Hilbuchbcd39d42019-01-26 01:13:56386 webrtc::CryptoOptions crypto_options,
387 rtc::UniqueRandomIdGenerator* ssrc_generator);
[email protected]28e20752013-07-10 00:45:36388 ~VideoChannel();
[email protected]28e20752013-07-10 00:45:36389
Fredrik Solenberg4b60c732015-05-07 12:07:48390 // downcasts a MediaChannel
Danil Chapovalov33b01f22016-05-11 17:55:27391 VideoMediaChannel* media_channel() const override {
Fredrik Solenberg4b60c732015-05-07 12:07:48392 return static_cast<VideoMediaChannel*>(BaseChannel::media_channel());
393 }
394
stefanf79ade12017-06-02 13:44:03395 void FillBitrateInfo(BandwidthEstimationInfo* bwe_info);
[email protected]28e20752013-07-10 00:45:36396
Amit Hilbuchdd9390c2018-11-14 00:26:05397 cricket::MediaType media_type() const override {
398 return cricket::MEDIA_TYPE_VIDEO;
399 }
[email protected]28e20752013-07-10 00:45:36400
[email protected]28e20752013-07-10 00:45:36401 private:
[email protected]28e20752013-07-10 00:45:36402 // overrides from BaseChannel
Taylor Brandstetterbad33bf2016-08-25 20:31:14403 void UpdateMediaSendRecvState_w() override;
Danil Chapovalov33b01f22016-05-11 17:55:27404 bool SetLocalContent_w(const MediaContentDescription* content,
Steve Anton3828c062017-12-06 18:34:51405 webrtc::SdpType type,
Danil Chapovalov33b01f22016-05-11 17:55:27406 std::string* error_desc) override;
407 bool SetRemoteContent_w(const MediaContentDescription* content,
Steve Anton3828c062017-12-06 18:34:51408 webrtc::SdpType type,
Danil Chapovalov33b01f22016-05-11 17:55:27409 std::string* error_desc) override;
[email protected]28e20752013-07-10 00:45:36410
Peter Thatcherc2ee2c82015-08-07 23:05:34411 // Last VideoSendParameters sent down to the media_channel() via
412 // SetSendParameters.
413 VideoSendParameters last_send_params_;
414 // Last VideoRecvParameters sent down to the media_channel() via
415 // SetRecvParameters.
416 VideoRecvParameters last_recv_params_;
[email protected]28e20752013-07-10 00:45:36417};
418
deadbeef953c2ce2017-01-09 22:53:41419// RtpDataChannel is a specialization for data.
420class RtpDataChannel : public BaseChannel {
[email protected]28e20752013-07-10 00:45:36421 public:
deadbeef953c2ce2017-01-09 22:53:41422 RtpDataChannel(rtc::Thread* worker_thread,
423 rtc::Thread* network_thread,
zhihuangf5b251b2017-01-13 03:37:48424 rtc::Thread* signaling_thread,
Steve Anton8699a322017-11-06 23:53:33425 std::unique_ptr<DataMediaChannel> channel,
deadbeef953c2ce2017-01-09 22:53:41426 const std::string& content_name,
Zhi Huange830e682018-03-30 17:48:35427 bool srtp_required,
Amit Hilbuchbcd39d42019-01-26 01:13:56428 webrtc::CryptoOptions crypto_options,
429 rtc::UniqueRandomIdGenerator* ssrc_generator);
deadbeef953c2ce2017-01-09 22:53:41430 ~RtpDataChannel();
Zhi Huang2dfc42d2017-12-04 21:38:48431 // TODO(zhihuang): Remove this once the RtpTransport can be shared between
432 // BaseChannels.
Steve Anton8699a322017-11-06 23:53:33433 void Init_w(DtlsTransportInternal* rtp_dtls_transport,
deadbeeff5346592017-01-25 05:51:21434 DtlsTransportInternal* rtcp_dtls_transport,
deadbeef5bd5ca32017-02-10 19:31:50435 rtc::PacketTransportInternal* rtp_packet_transport,
436 rtc::PacketTransportInternal* rtcp_packet_transport);
Niels Möller2a707032020-06-16 14:39:13437 void Init_w(webrtc::RtpTransportInternal* rtp_transport) override;
[email protected]28e20752013-07-10 00:45:36438
[email protected]d64719d2013-08-01 00:00:07439 virtual bool SendData(const SendDataParams& params,
jbaucheec21bd2016-03-20 13:15:43440 const rtc::CopyOnWriteBuffer& payload,
[email protected]d64719d2013-08-01 00:00:07441 SendDataResult* result);
[email protected]28e20752013-07-10 00:45:36442
[email protected]07a6fbe2013-11-04 18:41:34443 // Should be called on the signaling thread only.
Yves Gerey665174f2018-06-19 13:03:05444 bool ready_to_send_data() const { return ready_to_send_data_; }
[email protected]07a6fbe2013-11-04 18:41:34445
deadbeef953c2ce2017-01-09 22:53:41446 sigslot::signal2<const ReceiveDataParams&, const rtc::CopyOnWriteBuffer&>
447 SignalDataReceived;
[email protected]28e20752013-07-10 00:45:36448 // Signal for notifying when the channel becomes ready to send data.
[email protected]d64719d2013-08-01 00:00:07449 // That occurs when the channel is enabled, the transport is writable,
450 // both local and remote descriptions are set, and the channel is unblocked.
[email protected]28e20752013-07-10 00:45:36451 sigslot::signal1<bool> SignalReadyToSendData;
Amit Hilbuchdd9390c2018-11-14 00:26:05452 cricket::MediaType media_type() const override {
453 return cricket::MEDIA_TYPE_DATA;
454 }
[email protected]28e20752013-07-10 00:45:36455
[email protected]cadf9042013-08-30 21:24:16456 protected:
457 // downcasts a MediaChannel.
Danil Chapovalov33b01f22016-05-11 17:55:27458 DataMediaChannel* media_channel() const override {
[email protected]cadf9042013-08-30 21:24:16459 return static_cast<DataMediaChannel*>(BaseChannel::media_channel());
460 }
461
[email protected]28e20752013-07-10 00:45:36462 private:
[email protected]d4e598d2014-07-29 17:36:52463 struct SendDataMessageData : public rtc::MessageData {
[email protected]28e20752013-07-10 00:45:36464 SendDataMessageData(const SendDataParams& params,
jbaucheec21bd2016-03-20 13:15:43465 const rtc::CopyOnWriteBuffer* payload,
[email protected]28e20752013-07-10 00:45:36466 SendDataResult* result)
Yves Gerey665174f2018-06-19 13:03:05467 : params(params), payload(payload), result(result), succeeded(false) {}
[email protected]28e20752013-07-10 00:45:36468
469 const SendDataParams& params;
jbaucheec21bd2016-03-20 13:15:43470 const rtc::CopyOnWriteBuffer* payload;
[email protected]28e20752013-07-10 00:45:36471 SendDataResult* result;
472 bool succeeded;
473 };
474
[email protected]d4e598d2014-07-29 17:36:52475 struct DataReceivedMessageData : public rtc::MessageData {
[email protected]28e20752013-07-10 00:45:36476 // We copy the data because the data will become invalid after we
477 // handle DataMediaChannel::SignalDataReceived but before we fire
478 // SignalDataReceived.
Yves Gerey665174f2018-06-19 13:03:05479 DataReceivedMessageData(const ReceiveDataParams& params,
480 const char* data,
481 size_t len)
482 : params(params), payload(data, len) {}
[email protected]28e20752013-07-10 00:45:36483 const ReceiveDataParams params;
jbaucheec21bd2016-03-20 13:15:43484 const rtc::CopyOnWriteBuffer payload;
[email protected]28e20752013-07-10 00:45:36485 };
486
[email protected]d4e598d2014-07-29 17:36:52487 typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData;
[email protected]d64719d2013-08-01 00:00:07488
[email protected]28e20752013-07-10 00:45:36489 // overrides from BaseChannel
deadbeef953c2ce2017-01-09 22:53:41490 // Checks that data channel type is RTP.
Harald Alvestrand755187f2019-12-05 12:43:34491 bool CheckDataChannelTypeFromContent(const MediaContentDescription* content,
deadbeef953c2ce2017-01-09 22:53:41492 std::string* error_desc);
Danil Chapovalov33b01f22016-05-11 17:55:27493 bool SetLocalContent_w(const MediaContentDescription* content,
Steve Anton3828c062017-12-06 18:34:51494 webrtc::SdpType type,
Danil Chapovalov33b01f22016-05-11 17:55:27495 std::string* error_desc) override;
496 bool SetRemoteContent_w(const MediaContentDescription* content,
Steve Anton3828c062017-12-06 18:34:51497 webrtc::SdpType type,
Danil Chapovalov33b01f22016-05-11 17:55:27498 std::string* error_desc) override;
Taylor Brandstetterbad33bf2016-08-25 20:31:14499 void UpdateMediaSendRecvState_w() override;
[email protected]28e20752013-07-10 00:45:36500
Danil Chapovalov33b01f22016-05-11 17:55:27501 void OnMessage(rtc::Message* pmsg) override;
Yves Gerey665174f2018-06-19 13:03:05502 void OnDataReceived(const ReceiveDataParams& params,
503 const char* data,
504 size_t len);
[email protected]d64719d2013-08-01 00:00:07505 void OnDataChannelReadyToSend(bool writable);
[email protected]28e20752013-07-10 00:45:36506
deadbeef953c2ce2017-01-09 22:53:41507 bool ready_to_send_data_ = false;
Peter Thatcherc2ee2c82015-08-07 23:05:34508
509 // Last DataSendParameters sent down to the media_channel() via
510 // SetSendParameters.
511 DataSendParameters last_send_params_;
512 // Last DataRecvParameters sent down to the media_channel() via
513 // SetRecvParameters.
514 DataRecvParameters last_recv_params_;
[email protected]28e20752013-07-10 00:45:36515};
516
517} // namespace cricket
518
Mirko Bonadei92ea95e2017-09-15 04:47:31519#endif // PC_CHANNEL_H_