Make RtpTransceiver not inherit from RefCountedObject.
Also update API proxy Create() factory functions to accept the inner
reference counted object via scoped_refptr instead of a raw pointer.
This is to avoid accidentally creating and deleting an object when
passing an inner object to a proxy class.
Consider something like:
auto proxy = MyProxy::Create(
signaling_thread(), make_ref_counted<Foo>());
Bug: webrtc:13464, webrtc:12701
Change-Id: I55ccfff43bbc164a5e909b2c9020e306ebb09075
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/256010
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36261}
This commit is contained in:
parent
7bd06dda3c
commit
0d5ce62d01
@ -649,11 +649,13 @@ RTCError PeerConnection::Initialize(
|
|||||||
rtp_manager()->transceivers()->Add(
|
rtp_manager()->transceivers()->Add(
|
||||||
RtpTransceiverProxyWithInternal<RtpTransceiver>::Create(
|
RtpTransceiverProxyWithInternal<RtpTransceiver>::Create(
|
||||||
signaling_thread(),
|
signaling_thread(),
|
||||||
new RtpTransceiver(cricket::MEDIA_TYPE_AUDIO, channel_manager())));
|
rtc::make_ref_counted<RtpTransceiver>(cricket::MEDIA_TYPE_AUDIO,
|
||||||
|
channel_manager())));
|
||||||
rtp_manager()->transceivers()->Add(
|
rtp_manager()->transceivers()->Add(
|
||||||
RtpTransceiverProxyWithInternal<RtpTransceiver>::Create(
|
RtpTransceiverProxyWithInternal<RtpTransceiver>::Create(
|
||||||
signaling_thread(),
|
signaling_thread(),
|
||||||
new RtpTransceiver(cricket::MEDIA_TYPE_VIDEO, channel_manager())));
|
rtc::make_ref_counted<RtpTransceiver>(cricket::MEDIA_TYPE_VIDEO,
|
||||||
|
channel_manager())));
|
||||||
}
|
}
|
||||||
|
|
||||||
int delay_ms = configuration.report_usage_pattern_delay_ms
|
int delay_ms = configuration.report_usage_pattern_delay_ms
|
||||||
|
|||||||
58
pc/proxy.h
58
pc/proxy.h
@ -227,26 +227,26 @@ class ConstMethodCall : public QueuedTask {
|
|||||||
constexpr char class_name##ProxyWithInternal<INTERNAL_CLASS>::proxy_name_[];
|
constexpr char class_name##ProxyWithInternal<INTERNAL_CLASS>::proxy_name_[];
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
#define PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
|
#define PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
|
||||||
protected: \
|
protected: \
|
||||||
class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
|
class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
|
||||||
INTERNAL_CLASS* c) \
|
rtc::scoped_refptr<INTERNAL_CLASS> c) \
|
||||||
: primary_thread_(primary_thread), c_(c) {} \
|
: primary_thread_(primary_thread), c_(std::move(c)) {} \
|
||||||
\
|
\
|
||||||
private: \
|
private: \
|
||||||
mutable rtc::Thread* primary_thread_;
|
mutable rtc::Thread* primary_thread_;
|
||||||
|
|
||||||
#define SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
|
#define SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
|
||||||
protected: \
|
protected: \
|
||||||
class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
|
class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
|
||||||
rtc::Thread* secondary_thread, \
|
rtc::Thread* secondary_thread, \
|
||||||
INTERNAL_CLASS* c) \
|
rtc::scoped_refptr<INTERNAL_CLASS> c) \
|
||||||
: primary_thread_(primary_thread), \
|
: primary_thread_(primary_thread), \
|
||||||
secondary_thread_(secondary_thread), \
|
secondary_thread_(secondary_thread), \
|
||||||
c_(c) {} \
|
c_(std::move(c)) {} \
|
||||||
\
|
\
|
||||||
private: \
|
private: \
|
||||||
mutable rtc::Thread* primary_thread_; \
|
mutable rtc::Thread* primary_thread_; \
|
||||||
mutable rtc::Thread* secondary_thread_;
|
mutable rtc::Thread* secondary_thread_;
|
||||||
|
|
||||||
// Note that the destructor is protected so that the proxy can only be
|
// Note that the destructor is protected so that the proxy can only be
|
||||||
@ -284,15 +284,15 @@ class ConstMethodCall : public QueuedTask {
|
|||||||
void DestroyInternal() { delete c_; } \
|
void DestroyInternal() { delete c_; } \
|
||||||
INTERNAL_CLASS* c_;
|
INTERNAL_CLASS* c_;
|
||||||
|
|
||||||
#define BEGIN_PRIMARY_PROXY_MAP(class_name) \
|
#define BEGIN_PRIMARY_PROXY_MAP(class_name) \
|
||||||
PROXY_MAP_BOILERPLATE(class_name) \
|
PROXY_MAP_BOILERPLATE(class_name) \
|
||||||
PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
|
PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
|
||||||
REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
|
REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
|
||||||
public: \
|
public: \
|
||||||
static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
|
static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
|
||||||
rtc::Thread* primary_thread, INTERNAL_CLASS* c) { \
|
rtc::Thread* primary_thread, rtc::scoped_refptr<INTERNAL_CLASS> c) { \
|
||||||
return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
|
return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
|
||||||
primary_thread, c); \
|
primary_thread, std::move(c)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BEGIN_PROXY_MAP(class_name) \
|
#define BEGIN_PROXY_MAP(class_name) \
|
||||||
@ -302,9 +302,9 @@ class ConstMethodCall : public QueuedTask {
|
|||||||
public: \
|
public: \
|
||||||
static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
|
static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
|
||||||
rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
|
rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
|
||||||
INTERNAL_CLASS* c) { \
|
rtc::scoped_refptr<INTERNAL_CLASS> c) { \
|
||||||
return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
|
return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
|
||||||
primary_thread, secondary_thread, c); \
|
primary_thread, secondary_thread, std::move(c)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PROXY_PRIMARY_THREAD_DESTRUCTOR() \
|
#define PROXY_PRIMARY_THREAD_DESTRUCTOR() \
|
||||||
|
|||||||
@ -98,7 +98,7 @@ class SignalingProxyTest : public ::testing::Test {
|
|||||||
ASSERT_TRUE(signaling_thread_->Start());
|
ASSERT_TRUE(signaling_thread_->Start());
|
||||||
fake_ = Fake::Create();
|
fake_ = Fake::Create();
|
||||||
fake_signaling_proxy_ =
|
fake_signaling_proxy_ =
|
||||||
FakeSignalingProxy::Create(signaling_thread_.get(), fake_.get());
|
FakeSignalingProxy::Create(signaling_thread_.get(), fake_);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -186,8 +186,8 @@ class ProxyTest : public ::testing::Test {
|
|||||||
ASSERT_TRUE(signaling_thread_->Start());
|
ASSERT_TRUE(signaling_thread_->Start());
|
||||||
ASSERT_TRUE(worker_thread_->Start());
|
ASSERT_TRUE(worker_thread_->Start());
|
||||||
fake_ = Fake::Create();
|
fake_ = Fake::Create();
|
||||||
fake_proxy_ = FakeProxy::Create(signaling_thread_.get(),
|
fake_proxy_ =
|
||||||
worker_thread_.get(), fake_.get());
|
FakeProxy::Create(signaling_thread_.get(), worker_thread_.get(), fake_);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@ -39,7 +39,6 @@
|
|||||||
#include "pc/rtp_sender_proxy.h"
|
#include "pc/rtp_sender_proxy.h"
|
||||||
#include "pc/rtp_transport_internal.h"
|
#include "pc/rtp_transport_internal.h"
|
||||||
#include "pc/session_description.h"
|
#include "pc/session_description.h"
|
||||||
#include "rtc_base/ref_counted_object.h"
|
|
||||||
#include "rtc_base/task_utils/pending_task_safety_flag.h"
|
#include "rtc_base/task_utils/pending_task_safety_flag.h"
|
||||||
#include "rtc_base/third_party/sigslot/sigslot.h"
|
#include "rtc_base/third_party/sigslot/sigslot.h"
|
||||||
#include "rtc_base/thread_annotations.h"
|
#include "rtc_base/thread_annotations.h"
|
||||||
@ -76,9 +75,8 @@ namespace webrtc {
|
|||||||
// MediaType specified in the constructor. Audio RtpTransceivers will have
|
// MediaType specified in the constructor. Audio RtpTransceivers will have
|
||||||
// AudioRtpSenders, AudioRtpReceivers, and a VoiceChannel. Video RtpTransceivers
|
// AudioRtpSenders, AudioRtpReceivers, and a VoiceChannel. Video RtpTransceivers
|
||||||
// will have VideoRtpSenders, VideoRtpReceivers, and a VideoChannel.
|
// will have VideoRtpSenders, VideoRtpReceivers, and a VideoChannel.
|
||||||
class RtpTransceiver final
|
class RtpTransceiver : public RtpTransceiverInterface,
|
||||||
: public rtc::RefCountedObject<RtpTransceiverInterface>,
|
public sigslot::has_slots<> {
|
||||||
public sigslot::has_slots<> {
|
|
||||||
public:
|
public:
|
||||||
// Construct a Plan B-style RtpTransceiver with no senders, receivers, or
|
// Construct a Plan B-style RtpTransceiver with no senders, receivers, or
|
||||||
// channel set.
|
// channel set.
|
||||||
|
|||||||
@ -52,7 +52,8 @@ class ChannelManagerForTest : public cricket::ChannelManager {
|
|||||||
TEST(RtpTransceiverTest, CannotSetChannelOnStoppedTransceiver) {
|
TEST(RtpTransceiverTest, CannotSetChannelOnStoppedTransceiver) {
|
||||||
ChannelManagerForTest cm;
|
ChannelManagerForTest cm;
|
||||||
const std::string content_name("my_mid");
|
const std::string content_name("my_mid");
|
||||||
RtpTransceiver transceiver(cricket::MediaType::MEDIA_TYPE_AUDIO, &cm);
|
auto transceiver = rtc::make_ref_counted<RtpTransceiver>(
|
||||||
|
cricket::MediaType::MEDIA_TYPE_AUDIO, &cm);
|
||||||
cricket::MockChannelInterface channel1;
|
cricket::MockChannelInterface channel1;
|
||||||
EXPECT_CALL(channel1, media_type())
|
EXPECT_CALL(channel1, media_type())
|
||||||
.WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
|
.WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
|
||||||
@ -60,35 +61,37 @@ TEST(RtpTransceiverTest, CannotSetChannelOnStoppedTransceiver) {
|
|||||||
EXPECT_CALL(channel1, SetFirstPacketReceivedCallback(_));
|
EXPECT_CALL(channel1, SetFirstPacketReceivedCallback(_));
|
||||||
EXPECT_CALL(channel1, SetRtpTransport(_)).WillRepeatedly(Return(true));
|
EXPECT_CALL(channel1, SetRtpTransport(_)).WillRepeatedly(Return(true));
|
||||||
|
|
||||||
transceiver.SetChannel(&channel1, [&](const std::string& mid) {
|
transceiver->SetChannel(&channel1, [&](const std::string& mid) {
|
||||||
EXPECT_EQ(mid, content_name);
|
EXPECT_EQ(mid, content_name);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
});
|
});
|
||||||
EXPECT_EQ(&channel1, transceiver.channel());
|
EXPECT_EQ(&channel1, transceiver->channel());
|
||||||
|
|
||||||
// Stop the transceiver.
|
// Stop the transceiver.
|
||||||
transceiver.StopInternal();
|
transceiver->StopInternal();
|
||||||
EXPECT_EQ(&channel1, transceiver.channel());
|
EXPECT_EQ(&channel1, transceiver->channel());
|
||||||
|
|
||||||
cricket::MockChannelInterface channel2;
|
cricket::MockChannelInterface channel2;
|
||||||
EXPECT_CALL(channel2, media_type())
|
EXPECT_CALL(channel2, media_type())
|
||||||
.WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
|
.WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
|
||||||
|
|
||||||
// Channel can no longer be set, so this call should be a no-op.
|
// Channel can no longer be set, so this call should be a no-op.
|
||||||
transceiver.SetChannel(&channel2, [](const std::string&) { return nullptr; });
|
transceiver->SetChannel(&channel2,
|
||||||
EXPECT_EQ(&channel1, transceiver.channel());
|
[](const std::string&) { return nullptr; });
|
||||||
|
EXPECT_EQ(&channel1, transceiver->channel());
|
||||||
|
|
||||||
// Clear the current channel before `transceiver` goes out of scope.
|
// Clear the current channel before `transceiver` goes out of scope.
|
||||||
EXPECT_CALL(channel1, SetFirstPacketReceivedCallback(_));
|
EXPECT_CALL(channel1, SetFirstPacketReceivedCallback(_));
|
||||||
EXPECT_CALL(cm, DestroyChannel(&channel1)).WillRepeatedly(testing::Return());
|
EXPECT_CALL(cm, DestroyChannel(&channel1)).WillRepeatedly(testing::Return());
|
||||||
transceiver.SetChannel(nullptr, nullptr);
|
transceiver->SetChannel(nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks that a channel can be unset on a stopped `RtpTransceiver`
|
// Checks that a channel can be unset on a stopped `RtpTransceiver`
|
||||||
TEST(RtpTransceiverTest, CanUnsetChannelOnStoppedTransceiver) {
|
TEST(RtpTransceiverTest, CanUnsetChannelOnStoppedTransceiver) {
|
||||||
ChannelManagerForTest cm;
|
ChannelManagerForTest cm;
|
||||||
const std::string content_name("my_mid");
|
const std::string content_name("my_mid");
|
||||||
RtpTransceiver transceiver(cricket::MediaType::MEDIA_TYPE_VIDEO, &cm);
|
auto transceiver = rtc::make_ref_counted<RtpTransceiver>(
|
||||||
|
cricket::MediaType::MEDIA_TYPE_VIDEO, &cm);
|
||||||
cricket::MockChannelInterface channel;
|
cricket::MockChannelInterface channel;
|
||||||
EXPECT_CALL(channel, media_type())
|
EXPECT_CALL(channel, media_type())
|
||||||
.WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_VIDEO));
|
.WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_VIDEO));
|
||||||
@ -98,34 +101,35 @@ TEST(RtpTransceiverTest, CanUnsetChannelOnStoppedTransceiver) {
|
|||||||
EXPECT_CALL(channel, SetRtpTransport(_)).WillRepeatedly(Return(true));
|
EXPECT_CALL(channel, SetRtpTransport(_)).WillRepeatedly(Return(true));
|
||||||
EXPECT_CALL(cm, DestroyChannel(&channel)).WillRepeatedly(testing::Return());
|
EXPECT_CALL(cm, DestroyChannel(&channel)).WillRepeatedly(testing::Return());
|
||||||
|
|
||||||
transceiver.SetChannel(&channel, [&](const std::string& mid) {
|
transceiver->SetChannel(&channel, [&](const std::string& mid) {
|
||||||
EXPECT_EQ(mid, content_name);
|
EXPECT_EQ(mid, content_name);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
});
|
});
|
||||||
EXPECT_EQ(&channel, transceiver.channel());
|
EXPECT_EQ(&channel, transceiver->channel());
|
||||||
|
|
||||||
// Stop the transceiver.
|
// Stop the transceiver.
|
||||||
transceiver.StopInternal();
|
transceiver->StopInternal();
|
||||||
EXPECT_EQ(&channel, transceiver.channel());
|
EXPECT_EQ(&channel, transceiver->channel());
|
||||||
|
|
||||||
// Set the channel to `nullptr`.
|
// Set the channel to `nullptr`.
|
||||||
transceiver.SetChannel(nullptr, nullptr);
|
transceiver->SetChannel(nullptr, nullptr);
|
||||||
EXPECT_EQ(nullptr, transceiver.channel());
|
EXPECT_EQ(nullptr, transceiver->channel());
|
||||||
}
|
}
|
||||||
|
|
||||||
class RtpTransceiverUnifiedPlanTest : public ::testing::Test {
|
class RtpTransceiverUnifiedPlanTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
RtpTransceiverUnifiedPlanTest()
|
RtpTransceiverUnifiedPlanTest()
|
||||||
: transceiver_(RtpSenderProxyWithInternal<RtpSenderInternal>::Create(
|
: transceiver_(rtc::make_ref_counted<RtpTransceiver>(
|
||||||
rtc::Thread::Current(),
|
RtpSenderProxyWithInternal<RtpSenderInternal>::Create(
|
||||||
sender_),
|
rtc::Thread::Current(),
|
||||||
RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create(
|
sender_),
|
||||||
rtc::Thread::Current(),
|
RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create(
|
||||||
rtc::Thread::Current(),
|
rtc::Thread::Current(),
|
||||||
receiver_),
|
rtc::Thread::Current(),
|
||||||
&channel_manager_,
|
receiver_),
|
||||||
channel_manager_.GetSupportedAudioRtpHeaderExtensions(),
|
&channel_manager_,
|
||||||
/* on_negotiation_needed= */ [] {}) {}
|
channel_manager_.GetSupportedAudioRtpHeaderExtensions(),
|
||||||
|
/* on_negotiation_needed= */ [] {})) {}
|
||||||
|
|
||||||
static rtc::scoped_refptr<MockRtpReceiverInternal> MockReceiver() {
|
static rtc::scoped_refptr<MockRtpReceiverInternal> MockReceiver() {
|
||||||
auto receiver = rtc::make_ref_counted<MockRtpReceiverInternal>();
|
auto receiver = rtc::make_ref_counted<MockRtpReceiverInternal>();
|
||||||
@ -144,7 +148,7 @@ class RtpTransceiverUnifiedPlanTest : public ::testing::Test {
|
|||||||
rtc::scoped_refptr<MockRtpReceiverInternal> receiver_ = MockReceiver();
|
rtc::scoped_refptr<MockRtpReceiverInternal> receiver_ = MockReceiver();
|
||||||
rtc::scoped_refptr<MockRtpSenderInternal> sender_ = MockSender();
|
rtc::scoped_refptr<MockRtpSenderInternal> sender_ = MockSender();
|
||||||
ChannelManagerForTest channel_manager_;
|
ChannelManagerForTest channel_manager_;
|
||||||
RtpTransceiver transceiver_;
|
rtc::scoped_refptr<RtpTransceiver> transceiver_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Basic tests for Stop()
|
// Basic tests for Stop()
|
||||||
@ -154,16 +158,16 @@ TEST_F(RtpTransceiverUnifiedPlanTest, StopSetsDirection) {
|
|||||||
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
|
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
|
||||||
EXPECT_CALL(*sender_.get(), Stop());
|
EXPECT_CALL(*sender_.get(), Stop());
|
||||||
|
|
||||||
EXPECT_EQ(RtpTransceiverDirection::kInactive, transceiver_.direction());
|
EXPECT_EQ(RtpTransceiverDirection::kInactive, transceiver_->direction());
|
||||||
EXPECT_FALSE(transceiver_.current_direction());
|
EXPECT_FALSE(transceiver_->current_direction());
|
||||||
transceiver_.StopStandard();
|
transceiver_->StopStandard();
|
||||||
EXPECT_EQ(RtpTransceiverDirection::kStopped, transceiver_.direction());
|
EXPECT_EQ(RtpTransceiverDirection::kStopped, transceiver_->direction());
|
||||||
EXPECT_FALSE(transceiver_.current_direction());
|
EXPECT_FALSE(transceiver_->current_direction());
|
||||||
transceiver_.StopTransceiverProcedure();
|
transceiver_->StopTransceiverProcedure();
|
||||||
EXPECT_TRUE(transceiver_.current_direction());
|
EXPECT_TRUE(transceiver_->current_direction());
|
||||||
EXPECT_EQ(RtpTransceiverDirection::kStopped, transceiver_.direction());
|
EXPECT_EQ(RtpTransceiverDirection::kStopped, transceiver_->direction());
|
||||||
EXPECT_EQ(RtpTransceiverDirection::kStopped,
|
EXPECT_EQ(RtpTransceiverDirection::kStopped,
|
||||||
*transceiver_.current_direction());
|
*transceiver_->current_direction());
|
||||||
}
|
}
|
||||||
|
|
||||||
class RtpTransceiverTestForHeaderExtensions : public ::testing::Test {
|
class RtpTransceiverTestForHeaderExtensions : public ::testing::Test {
|
||||||
@ -182,16 +186,17 @@ class RtpTransceiverTestForHeaderExtensions : public ::testing::Test {
|
|||||||
RtpHeaderExtensionCapability(RtpExtension::kVideoRotationUri,
|
RtpHeaderExtensionCapability(RtpExtension::kVideoRotationUri,
|
||||||
4,
|
4,
|
||||||
RtpTransceiverDirection::kSendRecv)}),
|
RtpTransceiverDirection::kSendRecv)}),
|
||||||
transceiver_(RtpSenderProxyWithInternal<RtpSenderInternal>::Create(
|
transceiver_(rtc::make_ref_counted<RtpTransceiver>(
|
||||||
rtc::Thread::Current(),
|
RtpSenderProxyWithInternal<RtpSenderInternal>::Create(
|
||||||
sender_),
|
rtc::Thread::Current(),
|
||||||
RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create(
|
sender_),
|
||||||
rtc::Thread::Current(),
|
RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create(
|
||||||
rtc::Thread::Current(),
|
rtc::Thread::Current(),
|
||||||
receiver_),
|
rtc::Thread::Current(),
|
||||||
&channel_manager_,
|
receiver_),
|
||||||
extensions_,
|
&channel_manager_,
|
||||||
/* on_negotiation_needed= */ [] {}) {}
|
extensions_,
|
||||||
|
/* on_negotiation_needed= */ [] {})) {}
|
||||||
|
|
||||||
static rtc::scoped_refptr<MockRtpReceiverInternal> MockReceiver() {
|
static rtc::scoped_refptr<MockRtpReceiverInternal> MockReceiver() {
|
||||||
auto receiver = rtc::make_ref_counted<MockRtpReceiverInternal>();
|
auto receiver = rtc::make_ref_counted<MockRtpReceiverInternal>();
|
||||||
@ -212,7 +217,7 @@ class RtpTransceiverTestForHeaderExtensions : public ::testing::Test {
|
|||||||
EXPECT_CALL(mock_channel, SetFirstPacketReceivedCallback(_));
|
EXPECT_CALL(mock_channel, SetFirstPacketReceivedCallback(_));
|
||||||
EXPECT_CALL(channel_manager_, DestroyChannel(&mock_channel))
|
EXPECT_CALL(channel_manager_, DestroyChannel(&mock_channel))
|
||||||
.WillRepeatedly(testing::Return());
|
.WillRepeatedly(testing::Return());
|
||||||
transceiver_.SetChannel(nullptr, nullptr);
|
transceiver_->SetChannel(nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::scoped_refptr<MockRtpReceiverInternal> receiver_ = MockReceiver();
|
rtc::scoped_refptr<MockRtpReceiverInternal> receiver_ = MockReceiver();
|
||||||
@ -220,7 +225,7 @@ class RtpTransceiverTestForHeaderExtensions : public ::testing::Test {
|
|||||||
|
|
||||||
ChannelManagerForTest channel_manager_;
|
ChannelManagerForTest channel_manager_;
|
||||||
std::vector<RtpHeaderExtensionCapability> extensions_;
|
std::vector<RtpHeaderExtensionCapability> extensions_;
|
||||||
RtpTransceiver transceiver_;
|
rtc::scoped_refptr<RtpTransceiver> transceiver_;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(RtpTransceiverTestForHeaderExtensions, OffersChannelManagerList) {
|
TEST_F(RtpTransceiverTestForHeaderExtensions, OffersChannelManagerList) {
|
||||||
@ -229,7 +234,7 @@ TEST_F(RtpTransceiverTestForHeaderExtensions, OffersChannelManagerList) {
|
|||||||
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
|
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
|
||||||
EXPECT_CALL(*sender_.get(), Stop());
|
EXPECT_CALL(*sender_.get(), Stop());
|
||||||
|
|
||||||
EXPECT_EQ(transceiver_.HeaderExtensionsToOffer(), extensions_);
|
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), extensions_);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RtpTransceiverTestForHeaderExtensions, ModifiesDirection) {
|
TEST_F(RtpTransceiverTestForHeaderExtensions, ModifiesDirection) {
|
||||||
@ -241,20 +246,20 @@ TEST_F(RtpTransceiverTestForHeaderExtensions, ModifiesDirection) {
|
|||||||
auto modified_extensions = extensions_;
|
auto modified_extensions = extensions_;
|
||||||
modified_extensions[0].direction = RtpTransceiverDirection::kSendOnly;
|
modified_extensions[0].direction = RtpTransceiverDirection::kSendOnly;
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
transceiver_.SetOfferedRtpHeaderExtensions(modified_extensions).ok());
|
transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions).ok());
|
||||||
EXPECT_EQ(transceiver_.HeaderExtensionsToOffer(), modified_extensions);
|
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), modified_extensions);
|
||||||
modified_extensions[0].direction = RtpTransceiverDirection::kRecvOnly;
|
modified_extensions[0].direction = RtpTransceiverDirection::kRecvOnly;
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
transceiver_.SetOfferedRtpHeaderExtensions(modified_extensions).ok());
|
transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions).ok());
|
||||||
EXPECT_EQ(transceiver_.HeaderExtensionsToOffer(), modified_extensions);
|
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), modified_extensions);
|
||||||
modified_extensions[0].direction = RtpTransceiverDirection::kSendRecv;
|
modified_extensions[0].direction = RtpTransceiverDirection::kSendRecv;
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
transceiver_.SetOfferedRtpHeaderExtensions(modified_extensions).ok());
|
transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions).ok());
|
||||||
EXPECT_EQ(transceiver_.HeaderExtensionsToOffer(), modified_extensions);
|
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), modified_extensions);
|
||||||
modified_extensions[0].direction = RtpTransceiverDirection::kInactive;
|
modified_extensions[0].direction = RtpTransceiverDirection::kInactive;
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
transceiver_.SetOfferedRtpHeaderExtensions(modified_extensions).ok());
|
transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions).ok());
|
||||||
EXPECT_EQ(transceiver_.HeaderExtensionsToOffer(), modified_extensions);
|
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), modified_extensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RtpTransceiverTestForHeaderExtensions, AcceptsStoppedExtension) {
|
TEST_F(RtpTransceiverTestForHeaderExtensions, AcceptsStoppedExtension) {
|
||||||
@ -266,8 +271,8 @@ TEST_F(RtpTransceiverTestForHeaderExtensions, AcceptsStoppedExtension) {
|
|||||||
auto modified_extensions = extensions_;
|
auto modified_extensions = extensions_;
|
||||||
modified_extensions[0].direction = RtpTransceiverDirection::kStopped;
|
modified_extensions[0].direction = RtpTransceiverDirection::kStopped;
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
transceiver_.SetOfferedRtpHeaderExtensions(modified_extensions).ok());
|
transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions).ok());
|
||||||
EXPECT_EQ(transceiver_.HeaderExtensionsToOffer(), modified_extensions);
|
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), modified_extensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RtpTransceiverTestForHeaderExtensions, RejectsUnsupportedExtension) {
|
TEST_F(RtpTransceiverTestForHeaderExtensions, RejectsUnsupportedExtension) {
|
||||||
@ -279,9 +284,9 @@ TEST_F(RtpTransceiverTestForHeaderExtensions, RejectsUnsupportedExtension) {
|
|||||||
std::vector<RtpHeaderExtensionCapability> modified_extensions(
|
std::vector<RtpHeaderExtensionCapability> modified_extensions(
|
||||||
{RtpHeaderExtensionCapability("uri3", 1,
|
{RtpHeaderExtensionCapability("uri3", 1,
|
||||||
RtpTransceiverDirection::kSendRecv)});
|
RtpTransceiverDirection::kSendRecv)});
|
||||||
EXPECT_THAT(transceiver_.SetOfferedRtpHeaderExtensions(modified_extensions),
|
EXPECT_THAT(transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions),
|
||||||
Property(&RTCError::type, RTCErrorType::UNSUPPORTED_PARAMETER));
|
Property(&RTCError::type, RTCErrorType::UNSUPPORTED_PARAMETER));
|
||||||
EXPECT_EQ(transceiver_.HeaderExtensionsToOffer(), extensions_);
|
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), extensions_);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RtpTransceiverTestForHeaderExtensions,
|
TEST_F(RtpTransceiverTestForHeaderExtensions,
|
||||||
@ -294,15 +299,15 @@ TEST_F(RtpTransceiverTestForHeaderExtensions,
|
|||||||
std::vector<RtpHeaderExtensionCapability> modified_extensions = extensions_;
|
std::vector<RtpHeaderExtensionCapability> modified_extensions = extensions_;
|
||||||
// Attempting to stop the mandatory MID extension.
|
// Attempting to stop the mandatory MID extension.
|
||||||
modified_extensions[2].direction = RtpTransceiverDirection::kStopped;
|
modified_extensions[2].direction = RtpTransceiverDirection::kStopped;
|
||||||
EXPECT_THAT(transceiver_.SetOfferedRtpHeaderExtensions(modified_extensions),
|
EXPECT_THAT(transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions),
|
||||||
Property(&RTCError::type, RTCErrorType::INVALID_MODIFICATION));
|
Property(&RTCError::type, RTCErrorType::INVALID_MODIFICATION));
|
||||||
EXPECT_EQ(transceiver_.HeaderExtensionsToOffer(), extensions_);
|
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), extensions_);
|
||||||
modified_extensions = extensions_;
|
modified_extensions = extensions_;
|
||||||
// Attempting to stop the mandatory video orientation extension.
|
// Attempting to stop the mandatory video orientation extension.
|
||||||
modified_extensions[3].direction = RtpTransceiverDirection::kStopped;
|
modified_extensions[3].direction = RtpTransceiverDirection::kStopped;
|
||||||
EXPECT_THAT(transceiver_.SetOfferedRtpHeaderExtensions(modified_extensions),
|
EXPECT_THAT(transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions),
|
||||||
Property(&RTCError::type, RTCErrorType::INVALID_MODIFICATION));
|
Property(&RTCError::type, RTCErrorType::INVALID_MODIFICATION));
|
||||||
EXPECT_EQ(transceiver_.HeaderExtensionsToOffer(), extensions_);
|
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), extensions_);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RtpTransceiverTestForHeaderExtensions,
|
TEST_F(RtpTransceiverTestForHeaderExtensions,
|
||||||
@ -311,7 +316,7 @@ TEST_F(RtpTransceiverTestForHeaderExtensions,
|
|||||||
EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
|
EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
|
||||||
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
|
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
|
||||||
EXPECT_CALL(*sender_.get(), Stop());
|
EXPECT_CALL(*sender_.get(), Stop());
|
||||||
EXPECT_THAT(transceiver_.HeaderExtensionsNegotiated(), ElementsAre());
|
EXPECT_THAT(transceiver_->HeaderExtensionsNegotiated(), ElementsAre());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RtpTransceiverTestForHeaderExtensions,
|
TEST_F(RtpTransceiverTestForHeaderExtensions,
|
||||||
@ -329,9 +334,9 @@ TEST_F(RtpTransceiverTestForHeaderExtensions,
|
|||||||
EXPECT_CALL(mock_channel, media_channel()).WillRepeatedly(Return(nullptr));
|
EXPECT_CALL(mock_channel, media_channel()).WillRepeatedly(Return(nullptr));
|
||||||
EXPECT_CALL(mock_channel, mid()).WillRepeatedly(ReturnRef(content_name));
|
EXPECT_CALL(mock_channel, mid()).WillRepeatedly(ReturnRef(content_name));
|
||||||
EXPECT_CALL(mock_channel, SetRtpTransport(_)).WillRepeatedly(Return(true));
|
EXPECT_CALL(mock_channel, SetRtpTransport(_)).WillRepeatedly(Return(true));
|
||||||
transceiver_.SetChannel(&mock_channel,
|
transceiver_->SetChannel(&mock_channel,
|
||||||
[](const std::string&) { return nullptr; });
|
[](const std::string&) { return nullptr; });
|
||||||
EXPECT_THAT(transceiver_.HeaderExtensionsNegotiated(), ElementsAre());
|
EXPECT_THAT(transceiver_->HeaderExtensionsNegotiated(), ElementsAre());
|
||||||
|
|
||||||
ClearChannel(mock_channel);
|
ClearChannel(mock_channel);
|
||||||
}
|
}
|
||||||
@ -356,11 +361,11 @@ TEST_F(RtpTransceiverTestForHeaderExtensions, ReturnsNegotiatedHdrExts) {
|
|||||||
webrtc::RtpExtension("uri2", 2)};
|
webrtc::RtpExtension("uri2", 2)};
|
||||||
cricket::AudioContentDescription description;
|
cricket::AudioContentDescription description;
|
||||||
description.set_rtp_header_extensions(extensions);
|
description.set_rtp_header_extensions(extensions);
|
||||||
transceiver_.OnNegotiationUpdate(SdpType::kAnswer, &description);
|
transceiver_->OnNegotiationUpdate(SdpType::kAnswer, &description);
|
||||||
|
|
||||||
transceiver_.SetChannel(&mock_channel,
|
transceiver_->SetChannel(&mock_channel,
|
||||||
[](const std::string&) { return nullptr; });
|
[](const std::string&) { return nullptr; });
|
||||||
EXPECT_THAT(transceiver_.HeaderExtensionsNegotiated(),
|
EXPECT_THAT(transceiver_->HeaderExtensionsNegotiated(),
|
||||||
ElementsAre(RtpHeaderExtensionCapability(
|
ElementsAre(RtpHeaderExtensionCapability(
|
||||||
"uri1", 1, RtpTransceiverDirection::kSendRecv),
|
"uri1", 1, RtpTransceiverDirection::kSendRecv),
|
||||||
RtpHeaderExtensionCapability(
|
RtpHeaderExtensionCapability(
|
||||||
@ -380,9 +385,9 @@ TEST_F(RtpTransceiverTestForHeaderExtensions,
|
|||||||
webrtc::RtpExtension("uri2", 2)};
|
webrtc::RtpExtension("uri2", 2)};
|
||||||
cricket::AudioContentDescription description;
|
cricket::AudioContentDescription description;
|
||||||
description.set_rtp_header_extensions(extensions);
|
description.set_rtp_header_extensions(extensions);
|
||||||
transceiver_.OnNegotiationUpdate(SdpType::kAnswer, &description);
|
transceiver_->OnNegotiationUpdate(SdpType::kAnswer, &description);
|
||||||
|
|
||||||
EXPECT_THAT(transceiver_.HeaderExtensionsNegotiated(),
|
EXPECT_THAT(transceiver_->HeaderExtensionsNegotiated(),
|
||||||
ElementsAre(RtpHeaderExtensionCapability(
|
ElementsAre(RtpHeaderExtensionCapability(
|
||||||
"uri1", 1, RtpTransceiverDirection::kSendRecv),
|
"uri1", 1, RtpTransceiverDirection::kSendRecv),
|
||||||
RtpHeaderExtensionCapability(
|
RtpHeaderExtensionCapability(
|
||||||
@ -391,9 +396,9 @@ TEST_F(RtpTransceiverTestForHeaderExtensions,
|
|||||||
extensions = {webrtc::RtpExtension("uri3", 4),
|
extensions = {webrtc::RtpExtension("uri3", 4),
|
||||||
webrtc::RtpExtension("uri5", 6)};
|
webrtc::RtpExtension("uri5", 6)};
|
||||||
description.set_rtp_header_extensions(extensions);
|
description.set_rtp_header_extensions(extensions);
|
||||||
transceiver_.OnNegotiationUpdate(SdpType::kAnswer, &description);
|
transceiver_->OnNegotiationUpdate(SdpType::kAnswer, &description);
|
||||||
|
|
||||||
EXPECT_THAT(transceiver_.HeaderExtensionsNegotiated(),
|
EXPECT_THAT(transceiver_->HeaderExtensionsNegotiated(),
|
||||||
ElementsAre(RtpHeaderExtensionCapability(
|
ElementsAre(RtpHeaderExtensionCapability(
|
||||||
"uri3", 4, RtpTransceiverDirection::kSendRecv),
|
"uri3", 4, RtpTransceiverDirection::kSendRecv),
|
||||||
RtpHeaderExtensionCapability(
|
RtpHeaderExtensionCapability(
|
||||||
|
|||||||
@ -271,7 +271,7 @@ RtpTransmissionManager::CreateAndAddTransceiver(
|
|||||||
RTC_DCHECK(!FindSenderById(sender->id()));
|
RTC_DCHECK(!FindSenderById(sender->id()));
|
||||||
auto transceiver = RtpTransceiverProxyWithInternal<RtpTransceiver>::Create(
|
auto transceiver = RtpTransceiverProxyWithInternal<RtpTransceiver>::Create(
|
||||||
signaling_thread(),
|
signaling_thread(),
|
||||||
new RtpTransceiver(
|
rtc::make_ref_counted<RtpTransceiver>(
|
||||||
sender, receiver, channel_manager(),
|
sender, receiver, channel_manager(),
|
||||||
sender->media_type() == cricket::MEDIA_TYPE_AUDIO
|
sender->media_type() == cricket::MEDIA_TYPE_AUDIO
|
||||||
? channel_manager()->GetSupportedAudioRtpHeaderExtensions()
|
? channel_manager()->GetSupportedAudioRtpHeaderExtensions()
|
||||||
|
|||||||
@ -158,11 +158,8 @@ rtc::scoped_refptr<SctpDataChannel> SctpDataChannel::Create(
|
|||||||
rtc::scoped_refptr<DataChannelInterface> SctpDataChannel::CreateProxy(
|
rtc::scoped_refptr<DataChannelInterface> SctpDataChannel::CreateProxy(
|
||||||
rtc::scoped_refptr<SctpDataChannel> channel) {
|
rtc::scoped_refptr<SctpDataChannel> channel) {
|
||||||
// TODO(bugs.webrtc.org/11547): incorporate the network thread in the proxy.
|
// TODO(bugs.webrtc.org/11547): incorporate the network thread in the proxy.
|
||||||
// Also, consider allowing the proxy object to own the reference (std::move).
|
auto* signaling_thread = channel->signaling_thread_;
|
||||||
// As is, the proxy has a raw pointer and no reference to the channel object
|
return DataChannelProxy::Create(signaling_thread, std::move(channel));
|
||||||
// and trusting that the lifetime management aligns with the
|
|
||||||
// sctp_data_channels_ array in SctpDataChannelController.
|
|
||||||
return DataChannelProxy::Create(channel->signaling_thread_, channel.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SctpDataChannel::SctpDataChannel(const InternalDataChannelInit& config,
|
SctpDataChannel::SctpDataChannel(const InternalDataChannelInit& config,
|
||||||
|
|||||||
@ -406,7 +406,8 @@ class FakePeerConnectionForStats : public FakePeerConnectionBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto transceiver = RtpTransceiverProxyWithInternal<RtpTransceiver>::Create(
|
auto transceiver = RtpTransceiverProxyWithInternal<RtpTransceiver>::Create(
|
||||||
signaling_thread_, new RtpTransceiver(media_type, &channel_manager_));
|
signaling_thread_,
|
||||||
|
rtc::make_ref_counted<RtpTransceiver>(media_type, &channel_manager_));
|
||||||
transceivers_.push_back(transceiver);
|
transceivers_.push_back(transceiver);
|
||||||
return transceiver;
|
return transceiver;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -136,8 +136,9 @@ rtc::scoped_refptr<VideoTrack> VideoTrack::Create(
|
|||||||
rtc::Thread* worker_thread) {
|
rtc::Thread* worker_thread) {
|
||||||
rtc::scoped_refptr<
|
rtc::scoped_refptr<
|
||||||
VideoTrackSourceProxyWithInternal<VideoTrackSourceInterface>>
|
VideoTrackSourceProxyWithInternal<VideoTrackSourceInterface>>
|
||||||
source_proxy = VideoTrackSourceProxy::Create(rtc::Thread::Current(),
|
source_proxy = VideoTrackSourceProxy::Create(
|
||||||
worker_thread, source);
|
rtc::Thread::Current(), worker_thread,
|
||||||
|
rtc::scoped_refptr<VideoTrackSourceInterface>(source));
|
||||||
|
|
||||||
return rtc::make_ref_counted<VideoTrack>(id, std::move(source_proxy),
|
return rtc::make_ref_counted<VideoTrack>(id, std::move(source_proxy),
|
||||||
worker_thread);
|
worker_thread);
|
||||||
|
|||||||
@ -21,7 +21,9 @@ rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoTrackSourceProxy(
|
|||||||
rtc::Thread* signaling_thread,
|
rtc::Thread* signaling_thread,
|
||||||
rtc::Thread* worker_thread,
|
rtc::Thread* worker_thread,
|
||||||
VideoTrackSourceInterface* source) {
|
VideoTrackSourceInterface* source) {
|
||||||
return VideoTrackSourceProxy::Create(signaling_thread, worker_thread, source);
|
return VideoTrackSourceProxy::Create(
|
||||||
|
signaling_thread, worker_thread,
|
||||||
|
rtc::scoped_refptr<VideoTrackSourceInterface>(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user