diff --git a/webrtc/api/webrtcsession.cc b/webrtc/api/webrtcsession.cc index ded3023653..0532040394 100644 --- a/webrtc/api/webrtcsession.cc +++ b/webrtc/api/webrtcsession.cc @@ -1719,8 +1719,8 @@ bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content, rtcp_mux_policy_ == PeerConnectionInterface::kRtcpMuxPolicyRequire; bool create_rtcp_transport_channel = !sctp && !require_rtcp_mux; data_channel_.reset(channel_manager_->CreateDataChannel( - transport_controller_.get(), content->name, bundle_transport, - create_rtcp_transport_channel, data_channel_type_)); + transport_controller_.get(), media_controller_, content->name, + bundle_transport, create_rtcp_transport_channel, data_channel_type_)); if (!data_channel_) { return false; } diff --git a/webrtc/media/base/fakemediaengine.h b/webrtc/media/base/fakemediaengine.h index d97bab3dc2..dc547f8f10 100644 --- a/webrtc/media/base/fakemediaengine.h +++ b/webrtc/media/base/fakemediaengine.h @@ -943,7 +943,8 @@ class FakeDataEngine : public DataEngineInterface { public: FakeDataEngine() : last_channel_type_(DCT_NONE) {} - virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type) { + virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type, + const MediaConfig& config) { last_channel_type_ = data_channel_type; FakeDataMediaChannel* ch = new FakeDataMediaChannel(this, DataOptions()); channels_.push_back(ch); diff --git a/webrtc/media/base/hybriddataengine.h b/webrtc/media/base/hybriddataengine.h index 508210b8c5..341f054868 100644 --- a/webrtc/media/base/hybriddataengine.h +++ b/webrtc/media/base/hybriddataengine.h @@ -35,13 +35,14 @@ class HybridDataEngine : public DataEngineInterface { second_->data_codecs().end()); } - virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type) { + virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type, + const MediaConfig& config) { DataMediaChannel* channel = NULL; if (first_) { - channel = first_->CreateChannel(data_channel_type); + channel = first_->CreateChannel(data_channel_type, config); } if (!channel && second_) { - channel = second_->CreateChannel(data_channel_type); + channel = second_->CreateChannel(data_channel_type, config); } return channel; } diff --git a/webrtc/media/base/mediachannel.h b/webrtc/media/base/mediachannel.h index 4d44bffaea..d66424014b 100644 --- a/webrtc/media/base/mediachannel.h +++ b/webrtc/media/base/mediachannel.h @@ -1156,6 +1156,8 @@ class DataMediaChannel : public MediaChannel { ERROR_RECV_SRTP_REPLAY, // Packet replay detected. }; + DataMediaChannel() {} + DataMediaChannel(const MediaConfig& config) : MediaChannel(config) {} virtual ~DataMediaChannel() {} virtual bool SetSendParameters(const DataSendParameters& params) = 0; diff --git a/webrtc/media/base/mediaengine.h b/webrtc/media/base/mediaengine.h index 8083c8edac..57a2c7e6e6 100644 --- a/webrtc/media/base/mediaengine.h +++ b/webrtc/media/base/mediaengine.h @@ -170,7 +170,8 @@ enum DataChannelType { DCT_NONE = 0, DCT_RTP = 1, DCT_SCTP = 2, DCT_QUIC = 3 }; class DataEngineInterface { public: virtual ~DataEngineInterface() {} - virtual DataMediaChannel* CreateChannel(DataChannelType type) = 0; + virtual DataMediaChannel* CreateChannel(DataChannelType type, + const MediaConfig& config) = 0; virtual const std::vector& data_codecs() = 0; }; diff --git a/webrtc/media/base/rtpdataengine.cc b/webrtc/media/base/rtpdataengine.cc index a0c2cfc96e..12a37fa180 100644 --- a/webrtc/media/base/rtpdataengine.cc +++ b/webrtc/media/base/rtpdataengine.cc @@ -40,11 +40,12 @@ RtpDataEngine::RtpDataEngine() { } DataMediaChannel* RtpDataEngine::CreateChannel( - DataChannelType data_channel_type) { + DataChannelType data_channel_type, + const MediaConfig& config) { if (data_channel_type != DCT_RTP) { return NULL; } - return new RtpDataMediaChannel(); + return new RtpDataMediaChannel(config); } static const DataCodec* FindCodecByName(const std::vector& codecs, @@ -56,7 +57,8 @@ static const DataCodec* FindCodecByName(const std::vector& codecs, return nullptr; } -RtpDataMediaChannel::RtpDataMediaChannel() { +RtpDataMediaChannel::RtpDataMediaChannel(const MediaConfig& config) + : DataMediaChannel(config) { Construct(); } @@ -341,4 +343,8 @@ bool RtpDataMediaChannel::SendData( return true; } +rtc::DiffServCodePoint RtpDataMediaChannel::PreferredDscp() const { + return rtc::DSCP_AF41; +} + } // namespace cricket diff --git a/webrtc/media/base/rtpdataengine.h b/webrtc/media/base/rtpdataengine.h index 37a84da16f..adf0bef6e9 100644 --- a/webrtc/media/base/rtpdataengine.h +++ b/webrtc/media/base/rtpdataengine.h @@ -27,7 +27,8 @@ class RtpDataEngine : public DataEngineInterface { public: RtpDataEngine(); - virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type); + virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type, + const MediaConfig& config); virtual const std::vector& data_codecs() { return data_codecs_; @@ -61,7 +62,7 @@ class RtpClock { class RtpDataMediaChannel : public DataMediaChannel { public: - RtpDataMediaChannel(); + RtpDataMediaChannel(const MediaConfig& config); virtual ~RtpDataMediaChannel(); virtual bool SetSendParameters(const DataSendParameters& params); @@ -88,6 +89,7 @@ class RtpDataMediaChannel : public DataMediaChannel { const SendDataParams& params, const rtc::CopyOnWriteBuffer& payload, SendDataResult* result); + virtual rtc::DiffServCodePoint PreferredDscp() const; private: void Construct(); diff --git a/webrtc/media/base/rtpdataengine_unittest.cc b/webrtc/media/base/rtpdataengine_unittest.cc index 35daee5aeb..9d1e485916 100644 --- a/webrtc/media/base/rtpdataengine_unittest.cc +++ b/webrtc/media/base/rtpdataengine_unittest.cc @@ -70,9 +70,10 @@ class RtpDataMediaChannelTest : public testing::Test { } cricket::RtpDataMediaChannel* CreateChannel(cricket::RtpDataEngine* dme) { + cricket::MediaConfig config; cricket::RtpDataMediaChannel* channel = - static_cast(dme->CreateChannel( - cricket::DCT_RTP)); + static_cast( + dme->CreateChannel(cricket::DCT_RTP, config)); channel->SetInterface(iface_.get()); channel->SignalDataReceived.connect( receiver_.get(), &FakeDataReceiver::OnDataReceived); diff --git a/webrtc/media/sctp/sctpdataengine.cc b/webrtc/media/sctp/sctpdataengine.cc index 79754251e3..45dfad9e05 100644 --- a/webrtc/media/sctp/sctpdataengine.cc +++ b/webrtc/media/sctp/sctpdataengine.cc @@ -333,11 +333,12 @@ SctpDataEngine::~SctpDataEngine() {} // Called on the worker thread. DataMediaChannel* SctpDataEngine::CreateChannel( - DataChannelType data_channel_type) { + DataChannelType data_channel_type, + const MediaConfig& config) { if (data_channel_type != DCT_SCTP) { return NULL; } - return new SctpDataMediaChannel(rtc::Thread::Current()); + return new SctpDataMediaChannel(rtc::Thread::Current(), config); } // static @@ -378,15 +379,16 @@ int SctpDataMediaChannel::SendThresholdCallback(struct socket* sock, return 0; } -SctpDataMediaChannel::SctpDataMediaChannel(rtc::Thread* thread) - : worker_thread_(thread), +SctpDataMediaChannel::SctpDataMediaChannel(rtc::Thread* thread, + const MediaConfig& config) + : DataMediaChannel(config), + worker_thread_(thread), local_port_(kSctpDefaultPort), remote_port_(kSctpDefaultPort), sock_(NULL), sending_(false), receiving_(false), - debug_name_("SctpDataMediaChannel") { -} + debug_name_("SctpDataMediaChannel") {} SctpDataMediaChannel::~SctpDataMediaChannel() { CloseSctpSocket(); diff --git a/webrtc/media/sctp/sctpdataengine.h b/webrtc/media/sctp/sctpdataengine.h index 90011c4f46..8b6f37d6ba 100644 --- a/webrtc/media/sctp/sctpdataengine.h +++ b/webrtc/media/sctp/sctpdataengine.h @@ -88,7 +88,8 @@ class SctpDataEngine : public DataEngineInterface, public sigslot::has_slots<> { SctpDataEngine(); ~SctpDataEngine() override; - DataMediaChannel* CreateChannel(DataChannelType data_channel_type) override; + DataMediaChannel* CreateChannel(DataChannelType data_channel_type, + const MediaConfig& config) override; const std::vector& data_codecs() override { return codecs_; } private: @@ -125,7 +126,7 @@ class SctpDataMediaChannel : public DataMediaChannel, // Given a thread which will be used to post messages (received data) to this // SctpDataMediaChannel instance. - explicit SctpDataMediaChannel(rtc::Thread* thread); + explicit SctpDataMediaChannel(rtc::Thread* thread, const MediaConfig& config); virtual ~SctpDataMediaChannel(); // When SetSend is set to true, connects. When set to false, disconnects. diff --git a/webrtc/media/sctp/sctpdataengine_unittest.cc b/webrtc/media/sctp/sctpdataengine_unittest.cc index b32778d8c3..060b2d9749 100644 --- a/webrtc/media/sctp/sctpdataengine_unittest.cc +++ b/webrtc/media/sctp/sctpdataengine_unittest.cc @@ -265,8 +265,9 @@ class SctpDataMediaChannelTest : public testing::Test, SctpDataMediaChannel* CreateChannel(SctpFakeNetworkInterface* net, SctpFakeDataReceiver* recv) { - SctpDataMediaChannel* channel = - static_cast(engine_->CreateChannel(DCT_SCTP)); + cricket::MediaConfig config; + SctpDataMediaChannel* channel = static_cast( + engine_->CreateChannel(DCT_SCTP, config)); channel->SetInterface(net); // When data is received, pass it to the SctpFakeDataReceiver. channel->SignalDataReceived.connect( diff --git a/webrtc/pc/channelmanager.cc b/webrtc/pc/channelmanager.cc index 255730a0ba..fec57004a6 100644 --- a/webrtc/pc/channelmanager.cc +++ b/webrtc/pc/channelmanager.cc @@ -346,10 +346,22 @@ DataChannel* ChannelManager::CreateDataChannel( const std::string* bundle_transport_name, bool rtcp, DataChannelType channel_type) { + return CreateDataChannel(transport_controller, nullptr, content_name, + bundle_transport_name, rtcp, channel_type); +} + +DataChannel* ChannelManager::CreateDataChannel( + TransportController* transport_controller, + webrtc::MediaControllerInterface* media_controller, + const std::string& content_name, + const std::string* bundle_transport_name, + bool rtcp, + DataChannelType channel_type) { return worker_thread_->Invoke( RTC_FROM_HERE, Bind(&ChannelManager::CreateDataChannel_w, this, transport_controller, - content_name, bundle_transport_name, rtcp, channel_type)); + content_name, bundle_transport_name, rtcp, channel_type, + media_controller)); } DataChannel* ChannelManager::CreateDataChannel_w( @@ -357,11 +369,16 @@ DataChannel* ChannelManager::CreateDataChannel_w( const std::string& content_name, const std::string* bundle_transport_name, bool rtcp, - DataChannelType data_channel_type) { + DataChannelType data_channel_type, + webrtc::MediaControllerInterface* media_controller) { // This is ok to alloc from a thread other than the worker thread. ASSERT(initialized_); - DataMediaChannel* media_channel = data_media_engine_->CreateChannel( - data_channel_type); + MediaConfig config; + if (media_controller) { + config = media_controller->config(); + } + DataMediaChannel* media_channel = + data_media_engine_->CreateChannel(data_channel_type, config); if (!media_channel) { LOG(LS_WARNING) << "Failed to create data channel of type " << data_channel_type; diff --git a/webrtc/pc/channelmanager.h b/webrtc/pc/channelmanager.h index 15a3752c44..cc4ad23c7b 100644 --- a/webrtc/pc/channelmanager.h +++ b/webrtc/pc/channelmanager.h @@ -113,6 +113,13 @@ class ChannelManager { const std::string* bundle_transport_name, bool rtcp, DataChannelType data_channel_type); + DataChannel* CreateDataChannel( + TransportController* transport_controller, + webrtc::MediaControllerInterface* media_controller, + const std::string& content_name, + const std::string* bundle_transport_name, + bool rtcp, + DataChannelType data_channel_type); // Destroys a data channel created with the Create API. void DestroyDataChannel(DataChannel* data_channel); @@ -171,11 +178,13 @@ class ChannelManager { bool rtcp, const VideoOptions& options); void DestroyVideoChannel_w(VideoChannel* video_channel); - DataChannel* CreateDataChannel_w(TransportController* transport_controller, - const std::string& content_name, - const std::string* bundle_transport_name, - bool rtcp, - DataChannelType data_channel_type); + DataChannel* CreateDataChannel_w( + TransportController* transport_controller, + const std::string& content_name, + const std::string* bundle_transport_name, + bool rtcp, + DataChannelType data_channel_type, + webrtc::MediaControllerInterface* media_controller); void DestroyDataChannel_w(DataChannel* data_channel); std::unique_ptr media_engine_;