More minor improvements to BaseChannel/transport code.
Mostly from late comments on this CL: https://codereview.webrtc.org/2614263002/ Changes SetTransport to DCHECK instead of returning false. Renames it to SetTransports. Fixes some possible transport resource leaks. BUG=None Review-Url: https://codereview.webrtc.org/2637503003 Cr-Commit-Position: refs/heads/master@{#16130}
This commit is contained in:
@ -228,11 +228,7 @@ bool BaseChannel::Init_w(TransportChannel* rtp_transport,
|
||||
bool BaseChannel::InitNetwork_n(TransportChannel* rtp_transport,
|
||||
TransportChannel* rtcp_transport) {
|
||||
RTC_DCHECK(network_thread_->IsCurrent());
|
||||
// const std::string& transport_name =
|
||||
// (bundle_transport_name ? *bundle_transport_name : content_name());
|
||||
if (!SetTransport_n(rtp_transport, rtcp_transport)) {
|
||||
return false;
|
||||
}
|
||||
SetTransports_n(rtp_transport, rtcp_transport);
|
||||
|
||||
if (!SetDtlsSrtpCryptoSuites_n(rtp_transport_, false)) {
|
||||
return false;
|
||||
@ -256,30 +252,27 @@ void BaseChannel::Deinit() {
|
||||
RTC_FROM_HERE, Bind(&BaseChannel::DisconnectTransportChannels_n, this));
|
||||
}
|
||||
|
||||
bool BaseChannel::SetTransport(TransportChannel* rtp_transport,
|
||||
TransportChannel* rtcp_transport) {
|
||||
return network_thread_->Invoke<bool>(
|
||||
void BaseChannel::SetTransports(TransportChannel* rtp_transport,
|
||||
TransportChannel* rtcp_transport) {
|
||||
network_thread_->Invoke<void>(
|
||||
RTC_FROM_HERE,
|
||||
Bind(&BaseChannel::SetTransport_n, this, rtp_transport, rtcp_transport));
|
||||
Bind(&BaseChannel::SetTransports_n, this, rtp_transport, rtcp_transport));
|
||||
}
|
||||
|
||||
bool BaseChannel::SetTransport_n(TransportChannel* rtp_transport,
|
||||
TransportChannel* rtcp_transport) {
|
||||
void BaseChannel::SetTransports_n(TransportChannel* rtp_transport,
|
||||
TransportChannel* rtcp_transport) {
|
||||
RTC_DCHECK(network_thread_->IsCurrent());
|
||||
if (!rtp_transport && !rtcp_transport) {
|
||||
LOG(LS_ERROR) << "Setting nullptr to RTP Transport and RTCP Transport.";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify some assumptions (as described in the comment above SetTransport).
|
||||
RTC_DCHECK(rtp_transport);
|
||||
RTC_DCHECK(NeedsRtcpTransport() == (rtcp_transport != nullptr));
|
||||
if (rtcp_transport) {
|
||||
RTC_DCHECK(rtp_transport->transport_name() ==
|
||||
rtcp_transport->transport_name());
|
||||
RTC_DCHECK(NeedsRtcpTransport());
|
||||
}
|
||||
|
||||
if (rtp_transport->transport_name() == transport_name_) {
|
||||
// Nothing to do if transport name isn't changing.
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
transport_name_ = rtp_transport->transport_name();
|
||||
@ -300,17 +293,13 @@ bool BaseChannel::SetTransport_n(TransportChannel* rtp_transport,
|
||||
LOG(LS_INFO) << "Setting RTCP Transport for " << content_name() << " on "
|
||||
<< transport_name() << " transport " << rtcp_transport;
|
||||
SetTransportChannel_n(true, rtcp_transport);
|
||||
if (!rtcp_transport_) {
|
||||
return false;
|
||||
}
|
||||
RTC_DCHECK(rtcp_transport_);
|
||||
}
|
||||
|
||||
LOG(LS_INFO) << "Setting non-RTCP Transport for " << content_name() << " on "
|
||||
<< transport_name() << " transport " << rtp_transport;
|
||||
SetTransportChannel_n(false, rtp_transport);
|
||||
if (!rtp_transport_) {
|
||||
return false;
|
||||
}
|
||||
RTC_DCHECK(rtp_transport_);
|
||||
|
||||
// Update aggregate writable/ready-to-send state between RTP and RTCP upon
|
||||
// setting new transport channels.
|
||||
@ -328,7 +317,6 @@ bool BaseChannel::SetTransport_n(TransportChannel* rtp_transport,
|
||||
rtp_transport_ && rtp_transport_->writable());
|
||||
SetTransportChannelReadyToSend(
|
||||
true, rtcp_transport_ && rtcp_transport_->writable());
|
||||
return true;
|
||||
}
|
||||
|
||||
void BaseChannel::SetTransportChannel_n(bool rtcp,
|
||||
|
||||
@ -107,8 +107,14 @@ class BaseChannel
|
||||
|
||||
bool writable() const { return writable_; }
|
||||
|
||||
bool SetTransport(TransportChannel* rtp_transport,
|
||||
TransportChannel* rtcp_transport);
|
||||
// Set the transport(s), and update writability and "ready-to-send" state.
|
||||
// |rtp_transport| must be non-null.
|
||||
// |rtcp_transport| must be supplied if NeedsRtcpTransport() is true (meaning
|
||||
// RTCP muxing is not fully active yet).
|
||||
// |rtp_transport| and |rtcp_transport| must share the same transport name as
|
||||
// well.
|
||||
void SetTransports(TransportChannel* rtp_transport,
|
||||
TransportChannel* rtcp_transport);
|
||||
bool PushdownLocalDescription(const SessionDescription* local_desc,
|
||||
ContentAction action,
|
||||
std::string* error_desc);
|
||||
@ -194,11 +200,8 @@ class BaseChannel
|
||||
protected:
|
||||
virtual MediaChannel* media_channel() const { return media_channel_; }
|
||||
|
||||
// Sets the |rtp_transport_| (and |rtcp_transport_|, if
|
||||
// |rtcp_enabled_| is true).
|
||||
// This method also updates writability and "ready-to-send" state.
|
||||
bool SetTransport_n(TransportChannel* rtp_transport,
|
||||
TransportChannel* rtcp_transport);
|
||||
void SetTransports_n(TransportChannel* rtp_transport,
|
||||
TransportChannel* rtcp_transport);
|
||||
|
||||
// This does not update writability or "ready-to-send" state; it just
|
||||
// disconnects from the old channel and connects to the new one.
|
||||
|
||||
@ -3577,4 +3577,85 @@ TEST_F(RtpDataChannelDoubleThreadTest, TestSendData) {
|
||||
EXPECT_EQ("foo", media_channel1_->last_sent_data());
|
||||
}
|
||||
|
||||
#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
|
||||
|
||||
// Verifies some DCHECKs are in place.
|
||||
// Uses VoiceChannel, but any BaseChannel subclass would work.
|
||||
class BaseChannelDeathTest : public testing::Test {
|
||||
public:
|
||||
BaseChannelDeathTest()
|
||||
: // RTCP mux not required, SRTP required.
|
||||
voice_channel_(
|
||||
rtc::Thread::Current(),
|
||||
rtc::Thread::Current(),
|
||||
rtc::Thread::Current(),
|
||||
&fake_media_engine_,
|
||||
new cricket::FakeVoiceMediaChannel(nullptr,
|
||||
cricket::AudioOptions()),
|
||||
cricket::CN_AUDIO,
|
||||
false,
|
||||
true) {
|
||||
rtp_transport_ = fake_transport_controller_.CreateTransportChannel(
|
||||
"foo", cricket::ICE_CANDIDATE_COMPONENT_RTP);
|
||||
rtcp_transport_ = fake_transport_controller_.CreateTransportChannel(
|
||||
"foo", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
|
||||
EXPECT_TRUE(voice_channel_.Init_w(rtp_transport_, rtcp_transport_));
|
||||
}
|
||||
|
||||
protected:
|
||||
cricket::FakeTransportController fake_transport_controller_;
|
||||
cricket::FakeMediaEngine fake_media_engine_;
|
||||
cricket::VoiceChannel voice_channel_;
|
||||
// Will be cleaned up by FakeTransportController, don't need to worry about
|
||||
// deleting them in this test.
|
||||
cricket::TransportChannel* rtp_transport_;
|
||||
cricket::TransportChannel* rtcp_transport_;
|
||||
};
|
||||
|
||||
TEST_F(BaseChannelDeathTest, SetTransportWithNullRtpTransport) {
|
||||
cricket::TransportChannel* new_rtcp_transport =
|
||||
fake_transport_controller_.CreateTransportChannel(
|
||||
"bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
|
||||
EXPECT_DEATH(voice_channel_.SetTransports(nullptr, new_rtcp_transport), "");
|
||||
}
|
||||
|
||||
TEST_F(BaseChannelDeathTest, SetTransportWithMissingRtcpTransport) {
|
||||
cricket::TransportChannel* new_rtp_transport =
|
||||
fake_transport_controller_.CreateTransportChannel(
|
||||
"bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
|
||||
EXPECT_DEATH(voice_channel_.SetTransports(new_rtp_transport, nullptr), "");
|
||||
}
|
||||
|
||||
TEST_F(BaseChannelDeathTest, SetTransportWithUnneededRtcpTransport) {
|
||||
// Activate RTCP muxing, simulating offer/answer negotiation.
|
||||
cricket::AudioContentDescription content;
|
||||
content.set_rtcp_mux(true);
|
||||
ASSERT_TRUE(voice_channel_.SetLocalContent(&content, CA_OFFER, nullptr));
|
||||
ASSERT_TRUE(voice_channel_.SetRemoteContent(&content, CA_ANSWER, nullptr));
|
||||
cricket::TransportChannel* new_rtp_transport =
|
||||
fake_transport_controller_.CreateTransportChannel(
|
||||
"bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
|
||||
cricket::TransportChannel* new_rtcp_transport =
|
||||
fake_transport_controller_.CreateTransportChannel(
|
||||
"bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
|
||||
// After muxing is enabled, no RTCP transport should be passed in here.
|
||||
EXPECT_DEATH(
|
||||
voice_channel_.SetTransports(new_rtp_transport, new_rtcp_transport), "");
|
||||
}
|
||||
|
||||
// This test will probably go away if/when we move the transport name out of
|
||||
// the transport classes and into their parent classes.
|
||||
TEST_F(BaseChannelDeathTest, SetTransportWithMismatchingTransportNames) {
|
||||
cricket::TransportChannel* new_rtp_transport =
|
||||
fake_transport_controller_.CreateTransportChannel(
|
||||
"bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
|
||||
cricket::TransportChannel* new_rtcp_transport =
|
||||
fake_transport_controller_.CreateTransportChannel(
|
||||
"baz", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
|
||||
EXPECT_DEATH(
|
||||
voice_channel_.SetTransports(new_rtp_transport, new_rtcp_transport), "");
|
||||
}
|
||||
|
||||
#endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
|
||||
|
||||
// TODO(pthatcher): TestSetReceiver?
|
||||
|
||||
Reference in New Issue
Block a user