| Index: webrtc/pc/channel.h
|
| diff --git a/webrtc/pc/channel.h b/webrtc/pc/channel.h
|
| index 4518301d3b65e9e6fdf89586d258b519e42a4677..df75245f276d039b7af827f3470eda152a0c4e18 100644
|
| --- a/webrtc/pc/channel.h
|
| +++ b/webrtc/pc/channel.h
|
| @@ -19,6 +19,7 @@
|
| #include <vector>
|
|
|
| #include "webrtc/audio_sink.h"
|
| +#include "webrtc/base/asyncinvoker.h"
|
| #include "webrtc/base/asyncudpsocket.h"
|
| #include "webrtc/base/criticalsection.h"
|
| #include "webrtc/base/network.h"
|
| @@ -47,14 +48,17 @@ namespace cricket {
|
| struct CryptoParams;
|
| class MediaContentDescription;
|
|
|
| -enum SinkType {
|
| - SINK_PRE_CRYPTO, // Sink packets before encryption or after decryption.
|
| - SINK_POST_CRYPTO // Sink packets after encryption or before decryption.
|
| -};
|
| -
|
| // BaseChannel contains logic common to voice and video, including
|
| -// enable, marshaling calls to a worker thread, and
|
| +// enable, marshaling calls to a worker and network threads, and
|
| // connection and media monitors.
|
| +// BaseChannel assumes signaling and other threads are allowed to make
|
| +// synchronous calls to the worker thread, the worker thread makes synchronous
|
| +// calls only to the network thread, and the network thread can't be blocked by
|
| +// other threads.
|
| +// All methods with _n suffix must be called on network thread,
|
| +// methods with _w suffix - on worker thread
|
| +// and methods with _s suffix on signaling thread.
|
| +// Network and worker threads may be the same thread.
|
| //
|
| // WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS!
|
| // This is required to avoid a data race between the destructor modifying the
|
| @@ -66,26 +70,22 @@ class BaseChannel
|
| public MediaChannel::NetworkInterface,
|
| public ConnectionStatsGetter {
|
| public:
|
| - BaseChannel(rtc::Thread* thread,
|
| + BaseChannel(rtc::Thread* worker_thread,
|
| + rtc::Thread* network_thread,
|
| MediaChannel* channel,
|
| TransportController* transport_controller,
|
| const std::string& content_name,
|
| bool rtcp);
|
| virtual ~BaseChannel();
|
| - bool Init();
|
| - // Deinit may be called multiple times and is simply ignored if it's alreay
|
| + bool Init_w();
|
| + // Deinit may be called multiple times and is simply ignored if it's already
|
| // done.
|
| void Deinit();
|
|
|
| rtc::Thread* worker_thread() const { return worker_thread_; }
|
| + rtc::Thread* network_thread() const { return network_thread_; }
|
| const std::string& content_name() const { return content_name_; }
|
| const std::string& transport_name() const { return transport_name_; }
|
| - TransportChannel* transport_channel() const {
|
| - return transport_channel_;
|
| - }
|
| - TransportChannel* rtcp_transport_channel() const {
|
| - return rtcp_transport_channel_;
|
| - }
|
| bool enabled() const { return enabled_; }
|
|
|
| // This function returns true if we are using SRTP.
|
| @@ -143,18 +143,28 @@ class BaseChannel
|
| }
|
|
|
| sigslot::signal2<BaseChannel*, bool> SignalDtlsSetupFailure;
|
| - void SignalDtlsSetupFailure_w(bool rtcp);
|
| + void SignalDtlsSetupFailure_n(bool rtcp);
|
| void SignalDtlsSetupFailure_s(bool rtcp);
|
|
|
| // Used for latency measurements.
|
| sigslot::signal1<BaseChannel*> SignalFirstPacketReceived;
|
|
|
| + // Forward TransportChannel SignalSentPacket to worker thread.
|
| + sigslot::signal1<const rtc::SentPacket&> SignalSentPacket;
|
| +
|
| + // Only public for unit tests. Otherwise, consider private.
|
| + TransportChannel* transport_channel() const { return transport_channel_; }
|
| + TransportChannel* rtcp_transport_channel() const {
|
| + return rtcp_transport_channel_;
|
| + }
|
| +
|
| // Made public for easier testing.
|
| void SetReadyToSend(bool rtcp, bool ready);
|
|
|
| // Only public for unit tests. Otherwise, consider protected.
|
| int SetOption(SocketType type, rtc::Socket::Option o, int val)
|
| override;
|
| + int SetOption_n(SocketType type, rtc::Socket::Option o, int val);
|
|
|
| SrtpFilter* srtp_filter() { return &srtp_filter_; }
|
|
|
| @@ -162,11 +172,11 @@ class BaseChannel
|
| virtual MediaChannel* media_channel() const { return media_channel_; }
|
| // Sets the |transport_channel_| (and |rtcp_transport_channel_|, if |rtcp_| is
|
| // true). Gets the transport channels from |transport_controller_|.
|
| - bool SetTransport_w(const std::string& transport_name);
|
| + bool SetTransport_n(const std::string& transport_name);
|
|
|
| - void set_transport_channel(TransportChannel* transport);
|
| - void set_rtcp_transport_channel(TransportChannel* transport,
|
| - bool update_writablity);
|
| + void SetTransportChannel_n(TransportChannel* transport);
|
| + void SetRtcpTransportChannel_n(TransportChannel* transport,
|
| + bool update_writablity);
|
|
|
| bool was_ever_writable() const { return was_ever_writable_; }
|
| void set_local_content_direction(MediaContentDirection direction) {
|
| @@ -178,8 +188,8 @@ class BaseChannel
|
| void set_secure_required(bool secure_required) {
|
| secure_required_ = secure_required;
|
| }
|
| - bool IsReadyToReceive() const;
|
| - bool IsReadyToSend() const;
|
| + bool IsReadyToReceive_w() const;
|
| + bool IsReadyToSend_w() const;
|
| rtc::Thread* signaling_thread() {
|
| return transport_controller_->signaling_thread();
|
| }
|
| @@ -188,7 +198,7 @@ class BaseChannel
|
| void ConnectToTransportChannel(TransportChannel* tc);
|
| void DisconnectFromTransportChannel(TransportChannel* tc);
|
|
|
| - void FlushRtcpMessages();
|
| + void FlushRtcpMessages_n();
|
|
|
| // NetworkInterface implementation, called by MediaEngine
|
| bool SendPacket(rtc::CopyOnWriteBuffer* packet,
|
| @@ -217,28 +227,33 @@ class BaseChannel
|
| bool SendPacket(bool rtcp,
|
| rtc::CopyOnWriteBuffer* packet,
|
| const rtc::PacketOptions& options);
|
| +
|
| virtual bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet);
|
| void HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet,
|
| const rtc::PacketTime& packet_time);
|
| + void OnPacketReceived(bool rtcp,
|
| + const rtc::CopyOnWriteBuffer& packet,
|
| + const rtc::PacketTime& packet_time);
|
|
|
| void EnableMedia_w();
|
| void DisableMedia_w();
|
| - void UpdateWritableState_w();
|
| - void ChannelWritable_w();
|
| - void ChannelNotWritable_w();
|
| + void UpdateWritableState_n();
|
| + void ChannelWritable_n();
|
| + void ChannelNotWritable_n();
|
| bool AddRecvStream_w(const StreamParams& sp);
|
| bool RemoveRecvStream_w(uint32_t ssrc);
|
| bool AddSendStream_w(const StreamParams& sp);
|
| bool RemoveSendStream_w(uint32_t ssrc);
|
| - virtual bool ShouldSetupDtlsSrtp() const;
|
| + virtual bool ShouldSetupDtlsSrtp_n() const;
|
| // Do the DTLS key expansion and impose it on the SRTP/SRTCP filters.
|
| // |rtcp_channel| indicates whether to set up the RTP or RTCP filter.
|
| - bool SetupDtlsSrtp(bool rtcp_channel);
|
| - void MaybeSetupDtlsSrtp_w();
|
| + bool SetupDtlsSrtp_n(bool rtcp_channel);
|
| + void MaybeSetupDtlsSrtp_n();
|
| // Set the DTLS-SRTP cipher policy on this channel as appropriate.
|
| - bool SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp);
|
| + bool SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp);
|
|
|
| - virtual void ChangeState() = 0;
|
| + void ChangeState();
|
| + virtual void ChangeState_w() = 0;
|
|
|
| // Gets the content info appropriate to the channel (audio or video).
|
| virtual const ContentInfo* GetFirstContent(
|
| @@ -255,25 +270,29 @@ class BaseChannel
|
| virtual bool SetRemoteContent_w(const MediaContentDescription* content,
|
| ContentAction action,
|
| std::string* error_desc) = 0;
|
| - bool SetRtpTransportParameters_w(const MediaContentDescription* content,
|
| + bool SetRtpTransportParameters(const MediaContentDescription* content,
|
| + ContentAction action,
|
| + ContentSource src,
|
| + std::string* error_desc);
|
| + bool SetRtpTransportParameters_n(const MediaContentDescription* content,
|
| ContentAction action,
|
| ContentSource src,
|
| std::string* error_desc);
|
|
|
| // Helper method to get RTP Absoulute SendTime extension header id if
|
| // present in remote supported extensions list.
|
| - void MaybeCacheRtpAbsSendTimeHeaderExtension(
|
| + void MaybeCacheRtpAbsSendTimeHeaderExtension_w(
|
| const std::vector<RtpHeaderExtension>& extensions);
|
|
|
| - bool CheckSrtpConfig(const std::vector<CryptoParams>& cryptos,
|
| - bool* dtls,
|
| - std::string* error_desc);
|
| - bool SetSrtp_w(const std::vector<CryptoParams>& params,
|
| + bool CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos,
|
| + bool* dtls,
|
| + std::string* error_desc);
|
| + bool SetSrtp_n(const std::vector<CryptoParams>& params,
|
| ContentAction action,
|
| ContentSource src,
|
| std::string* error_desc);
|
| - void ActivateRtcpMux_w();
|
| - bool SetRtcpMux_w(bool enable,
|
| + void ActivateRtcpMux_n();
|
| + bool SetRtcpMux_n(bool enable,
|
| ContentAction action,
|
| ContentSource src,
|
| std::string* error_desc);
|
| @@ -283,7 +302,7 @@ class BaseChannel
|
|
|
| // Handled in derived classes
|
| // Get the SRTP crypto suites to use for RTP media
|
| - virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const = 0;
|
| + virtual void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const = 0;
|
| virtual void OnConnectionMonitorUpdate(ConnectionMonitor* monitor,
|
| const std::vector<ConnectionInfo>& infos) = 0;
|
|
|
| @@ -294,13 +313,23 @@ class BaseChannel
|
| }
|
|
|
| private:
|
| - rtc::Thread* worker_thread_;
|
| - TransportController* transport_controller_;
|
| - MediaChannel* media_channel_;
|
| - std::vector<StreamParams> local_streams_;
|
| - std::vector<StreamParams> remote_streams_;
|
| + bool InitNetwork_n();
|
| + void DeinitNetwork_n();
|
| + void SignalSentPacket_n(TransportChannel* channel,
|
| + const rtc::SentPacket& sent_packet);
|
| + void SignalSentPacket_w(const rtc::SentPacket& sent_packet);
|
| + bool IsTransportReadyToSend_n() const;
|
| + void CacheRtpAbsSendTimeHeaderExtension_n(int rtp_abs_sendtime_extn_id);
|
| +
|
| + rtc::Thread* const worker_thread_;
|
| + rtc::Thread* const network_thread_;
|
| + rtc::AsyncInvoker invoker_;
|
|
|
| const std::string content_name_;
|
| + std::unique_ptr<ConnectionMonitor> connection_monitor_;
|
| +
|
| + // Transport related members that should be accessed from network thread.
|
| + TransportController* const transport_controller_;
|
| std::string transport_name_;
|
| bool rtcp_transport_enabled_;
|
| TransportChannel* transport_channel_;
|
| @@ -310,32 +339,40 @@ class BaseChannel
|
| SrtpFilter srtp_filter_;
|
| RtcpMuxFilter rtcp_mux_filter_;
|
| BundleFilter bundle_filter_;
|
| - std::unique_ptr<ConnectionMonitor> connection_monitor_;
|
| - bool enabled_;
|
| - bool writable_;
|
| bool rtp_ready_to_send_;
|
| bool rtcp_ready_to_send_;
|
| + bool writable_;
|
| bool was_ever_writable_;
|
| - MediaContentDirection local_content_direction_;
|
| - MediaContentDirection remote_content_direction_;
|
| bool has_received_packet_;
|
| bool dtls_keyed_;
|
| bool secure_required_;
|
| int rtp_abs_sendtime_extn_id_;
|
| +
|
| + // MediaChannel related members that should be access from worker thread.
|
| + MediaChannel* const media_channel_;
|
| + // Currently enabled_ flag accessed from signaling thread too, but it can
|
| + // be changed only when signaling thread does sunchronious call to worker
|
| + // thread, so it should be safe.
|
| + bool enabled_;
|
| + std::vector<StreamParams> local_streams_;
|
| + std::vector<StreamParams> remote_streams_;
|
| + MediaContentDirection local_content_direction_;
|
| + MediaContentDirection remote_content_direction_;
|
| };
|
|
|
| // VoiceChannel is a specialization that adds support for early media, DTMF,
|
| // and input/output level monitoring.
|
| class VoiceChannel : public BaseChannel {
|
| public:
|
| - VoiceChannel(rtc::Thread* thread,
|
| + VoiceChannel(rtc::Thread* worker_thread,
|
| + rtc::Thread* network_thread,
|
| MediaEngineInterface* media_engine,
|
| VoiceMediaChannel* channel,
|
| TransportController* transport_controller,
|
| const std::string& content_name,
|
| bool rtcp);
|
| ~VoiceChannel();
|
| - bool Init();
|
| + bool Init_w();
|
|
|
| // Configure sending media on the stream with SSRC |ssrc|
|
| // If there is only one sending stream SSRC 0 can be used.
|
| @@ -345,7 +382,7 @@ class VoiceChannel : public BaseChannel {
|
| AudioSource* source);
|
|
|
| // downcasts a MediaChannel
|
| - virtual VoiceMediaChannel* media_channel() const {
|
| + VoiceMediaChannel* media_channel() const override {
|
| return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel());
|
| }
|
|
|
| @@ -393,29 +430,31 @@ class VoiceChannel : public BaseChannel {
|
|
|
| private:
|
| // overrides from BaseChannel
|
| - virtual void OnChannelRead(TransportChannel* channel,
|
| - const char* data, size_t len,
|
| - const rtc::PacketTime& packet_time,
|
| - int flags);
|
| - virtual void ChangeState();
|
| - virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc);
|
| - virtual bool SetLocalContent_w(const MediaContentDescription* content,
|
| - ContentAction action,
|
| - std::string* error_desc);
|
| - virtual bool SetRemoteContent_w(const MediaContentDescription* content,
|
| - ContentAction action,
|
| - std::string* error_desc);
|
| + void OnChannelRead(TransportChannel* channel,
|
| + const char* data,
|
| + size_t len,
|
| + const rtc::PacketTime& packet_time,
|
| + int flags) override;
|
| + void ChangeState_w() override;
|
| + const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
|
| + bool SetLocalContent_w(const MediaContentDescription* content,
|
| + ContentAction action,
|
| + std::string* error_desc) override;
|
| + bool SetRemoteContent_w(const MediaContentDescription* content,
|
| + ContentAction action,
|
| + std::string* error_desc) override;
|
| void HandleEarlyMediaTimeout();
|
| bool InsertDtmf_w(uint32_t ssrc, int event, int duration);
|
| bool SetOutputVolume_w(uint32_t ssrc, double volume);
|
| bool GetStats_w(VoiceMediaInfo* stats);
|
|
|
| - virtual void OnMessage(rtc::Message* pmsg);
|
| - virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const;
|
| - virtual void OnConnectionMonitorUpdate(
|
| - ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos);
|
| - virtual void OnMediaMonitorUpdate(
|
| - VoiceMediaChannel* media_channel, const VoiceMediaInfo& info);
|
| + void OnMessage(rtc::Message* pmsg) override;
|
| + void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
|
| + void OnConnectionMonitorUpdate(
|
| + ConnectionMonitor* monitor,
|
| + const std::vector<ConnectionInfo>& infos) override;
|
| + void OnMediaMonitorUpdate(VoiceMediaChannel* media_channel,
|
| + const VoiceMediaInfo& info);
|
| void OnAudioMonitorUpdate(AudioMonitor* monitor, const AudioInfo& info);
|
|
|
| static const int kEarlyMediaTimeout = 1000;
|
| @@ -435,16 +474,17 @@ class VoiceChannel : public BaseChannel {
|
| // VideoChannel is a specialization for video.
|
| class VideoChannel : public BaseChannel {
|
| public:
|
| - VideoChannel(rtc::Thread* thread,
|
| + VideoChannel(rtc::Thread* worker_thread,
|
| + rtc::Thread* netwokr_thread,
|
| VideoMediaChannel* channel,
|
| TransportController* transport_controller,
|
| const std::string& content_name,
|
| bool rtcp);
|
| ~VideoChannel();
|
| - bool Init();
|
| + bool Init_w();
|
|
|
| // downcasts a MediaChannel
|
| - virtual VideoMediaChannel* media_channel() const {
|
| + VideoMediaChannel* media_channel() const override {
|
| return static_cast<VideoMediaChannel*>(BaseChannel::media_channel());
|
| }
|
|
|
| @@ -469,24 +509,25 @@ class VideoChannel : public BaseChannel {
|
|
|
| private:
|
| // overrides from BaseChannel
|
| - virtual void ChangeState();
|
| - virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc);
|
| - virtual bool SetLocalContent_w(const MediaContentDescription* content,
|
| - ContentAction action,
|
| - std::string* error_desc);
|
| - virtual bool SetRemoteContent_w(const MediaContentDescription* content,
|
| - ContentAction action,
|
| - std::string* error_desc);
|
| + void ChangeState_w() override;
|
| + const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
|
| + bool SetLocalContent_w(const MediaContentDescription* content,
|
| + ContentAction action,
|
| + std::string* error_desc) override;
|
| + bool SetRemoteContent_w(const MediaContentDescription* content,
|
| + ContentAction action,
|
| + std::string* error_desc) override;
|
| bool GetStats_w(VideoMediaInfo* stats);
|
| webrtc::RtpParameters GetRtpParameters_w(uint32_t ssrc) const;
|
| bool SetRtpParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
|
|
|
| - virtual void OnMessage(rtc::Message* pmsg);
|
| - virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const;
|
| - virtual void OnConnectionMonitorUpdate(
|
| - ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos);
|
| - virtual void OnMediaMonitorUpdate(
|
| - VideoMediaChannel* media_channel, const VideoMediaInfo& info);
|
| + void OnMessage(rtc::Message* pmsg) override;
|
| + void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
|
| + void OnConnectionMonitorUpdate(
|
| + ConnectionMonitor* monitor,
|
| + const std::vector<ConnectionInfo>& infos) override;
|
| + void OnMediaMonitorUpdate(VideoMediaChannel* media_channel,
|
| + const VideoMediaInfo& info);
|
|
|
| std::unique_ptr<VideoMediaMonitor> media_monitor_;
|
|
|
| @@ -501,13 +542,14 @@ class VideoChannel : public BaseChannel {
|
| // DataChannel is a specialization for data.
|
| class DataChannel : public BaseChannel {
|
| public:
|
| - DataChannel(rtc::Thread* thread,
|
| + DataChannel(rtc::Thread* worker_thread,
|
| + rtc::Thread* network_thread,
|
| DataMediaChannel* media_channel,
|
| TransportController* transport_controller,
|
| const std::string& content_name,
|
| bool rtcp);
|
| ~DataChannel();
|
| - bool Init();
|
| + bool Init_w();
|
|
|
| virtual bool SendData(const SendDataParams& params,
|
| const rtc::CopyOnWriteBuffer& payload,
|
| @@ -535,7 +577,7 @@ class DataChannel : public BaseChannel {
|
|
|
| protected:
|
| // downcasts a MediaChannel.
|
| - virtual DataMediaChannel* media_channel() const {
|
| + DataMediaChannel* media_channel() const override {
|
| return static_cast<DataMediaChannel*>(BaseChannel::media_channel());
|
| }
|
|
|
| @@ -572,7 +614,7 @@ class DataChannel : public BaseChannel {
|
| typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData;
|
|
|
| // overrides from BaseChannel
|
| - virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc);
|
| + const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
|
| // If data_channel_type_ is DCT_NONE, set it. Otherwise, check that
|
| // it's the same as what was set previously. Returns false if it's
|
| // set to one type one type and changed to another type later.
|
| @@ -582,22 +624,23 @@ class DataChannel : public BaseChannel {
|
| // DataContentDescription.
|
| bool SetDataChannelTypeFromContent(const DataContentDescription* content,
|
| std::string* error_desc);
|
| - virtual bool SetLocalContent_w(const MediaContentDescription* content,
|
| - ContentAction action,
|
| - std::string* error_desc);
|
| - virtual bool SetRemoteContent_w(const MediaContentDescription* content,
|
| - ContentAction action,
|
| - std::string* error_desc);
|
| - virtual void ChangeState();
|
| - virtual bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet);
|
| + bool SetLocalContent_w(const MediaContentDescription* content,
|
| + ContentAction action,
|
| + std::string* error_desc) override;
|
| + bool SetRemoteContent_w(const MediaContentDescription* content,
|
| + ContentAction action,
|
| + std::string* error_desc) override;
|
| + void ChangeState_w() override;
|
| + bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) override;
|
|
|
| - virtual void OnMessage(rtc::Message* pmsg);
|
| - virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const;
|
| - virtual void OnConnectionMonitorUpdate(
|
| - ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos);
|
| - virtual void OnMediaMonitorUpdate(
|
| - DataMediaChannel* media_channel, const DataMediaInfo& info);
|
| - virtual bool ShouldSetupDtlsSrtp() const;
|
| + void OnMessage(rtc::Message* pmsg) override;
|
| + void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
|
| + void OnConnectionMonitorUpdate(
|
| + ConnectionMonitor* monitor,
|
| + const std::vector<ConnectionInfo>& infos) override;
|
| + void OnMediaMonitorUpdate(DataMediaChannel* media_channel,
|
| + const DataMediaInfo& info);
|
| + bool ShouldSetupDtlsSrtp_n() const override;
|
| void OnDataReceived(
|
| const ReceiveDataParams& params, const char* data, size_t len);
|
| void OnDataChannelError(uint32_t ssrc, DataMediaChannel::Error error);
|
|
|