Crash if PeerConnection methods are called with the wrong SdpSemantics.
Bug: None
Change-Id: I111098215ec83fdf97f9a5232efef6a4af329ddf
Reviewed-on: https://webrtc-review.googlesource.com/59262
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Reviewed-by: Seth Hampson <shampson@webrtc.org>
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22262}diff --git a/pc/peerconnection.cc b/pc/peerconnection.cc
index ef5294f..245e89d 100644
--- a/pc/peerconnection.cc
+++ b/pc/peerconnection.cc
@@ -986,15 +986,23 @@
rtc::scoped_refptr<StreamCollectionInterface>
PeerConnection::local_streams() {
+ RTC_CHECK(!IsUnifiedPlan()) << "local_streams is not available with Unified "
+ "Plan SdpSemantics. Please use GetSenders "
+ "instead.";
return local_streams_;
}
rtc::scoped_refptr<StreamCollectionInterface>
PeerConnection::remote_streams() {
+ RTC_CHECK(!IsUnifiedPlan()) << "remote_streams is not available with Unified "
+ "Plan SdpSemantics. Please use GetReceivers "
+ "instead.";
return remote_streams_;
}
bool PeerConnection::AddStream(MediaStreamInterface* local_stream) {
+ RTC_CHECK(!IsUnifiedPlan()) << "AddStream is not available with Unified Plan "
+ "SdpSemantics. Please use AddTrack instead.";
TRACE_EVENT0("webrtc", "PeerConnection::AddStream");
if (IsClosed()) {
return false;
@@ -1028,6 +1036,9 @@
}
void PeerConnection::RemoveStream(MediaStreamInterface* local_stream) {
+ RTC_CHECK(!IsUnifiedPlan()) << "RemoveStream is not available with Unified "
+ "Plan SdpSemantics. Please use RemoveTrack "
+ "instead.";
TRACE_EVENT0("webrtc", "PeerConnection::RemoveStream");
if (!IsClosed()) {
for (const auto& track : local_stream->GetAudioTracks()) {
@@ -1261,11 +1272,8 @@
PeerConnection::AddTransceiver(
rtc::scoped_refptr<MediaStreamTrackInterface> track,
const RtpTransceiverInit& init) {
- if (!IsUnifiedPlan()) {
- LOG_AND_RETURN_ERROR(
- RTCErrorType::INTERNAL_ERROR,
- "AddTransceiver only supported when Unified Plan is enabled.");
- }
+ RTC_CHECK(IsUnifiedPlan())
+ << "AddTransceiver is only available with Unified Plan SdpSemantics";
if (!track) {
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, "track is null");
}
@@ -1289,11 +1297,8 @@
RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>
PeerConnection::AddTransceiver(cricket::MediaType media_type,
const RtpTransceiverInit& init) {
- if (!IsUnifiedPlan()) {
- LOG_AND_RETURN_ERROR(
- RTCErrorType::INTERNAL_ERROR,
- "AddTransceiver only supported when Unified Plan is enabled.");
- }
+ RTC_CHECK(IsUnifiedPlan())
+ << "AddTransceiver is only available with Unified Plan SdpSemantics";
if (!(media_type == cricket::MEDIA_TYPE_AUDIO ||
media_type == cricket::MEDIA_TYPE_VIDEO)) {
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
@@ -1427,6 +1432,9 @@
rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender(
const std::string& kind,
const std::string& stream_id) {
+ RTC_CHECK(!IsUnifiedPlan()) << "CreateSender is not available with Unified "
+ "Plan SdpSemantics. Please use AddTransceiver "
+ "instead.";
TRACE_EVENT0("webrtc", "PeerConnection::CreateSender");
if (IsClosed()) {
return nullptr;
@@ -1506,7 +1514,8 @@
std::vector<rtc::scoped_refptr<RtpTransceiverInterface>>
PeerConnection::GetTransceivers() const {
- RTC_DCHECK(IsUnifiedPlan());
+ RTC_CHECK(IsUnifiedPlan())
+ << "GetTransceivers is only supported with Unified Plan SdpSemantics.";
std::vector<rtc::scoped_refptr<RtpTransceiverInterface>> all_transceivers;
for (auto transceiver : transceivers_) {
all_transceivers.push_back(transceiver);
diff --git a/pc/peerconnection_integrationtest.cc b/pc/peerconnection_integrationtest.cc
index 312407c..30dbdc8 100644
--- a/pc/peerconnection_integrationtest.cc
+++ b/pc/peerconnection_integrationtest.cc
@@ -2326,11 +2326,9 @@
// Get the remote audio track created on the receiver, so they can be used as
// GetStats filters.
- StreamCollectionInterface* remote_streams = callee()->remote_streams();
- ASSERT_EQ(1u, remote_streams->count());
- ASSERT_EQ(1u, remote_streams->at(0)->GetAudioTracks().size());
- MediaStreamTrackInterface* remote_audio_track =
- remote_streams->at(0)->GetAudioTracks()[0];
+ auto receivers = callee()->pc()->GetReceivers();
+ ASSERT_EQ(1u, receivers.size());
+ auto remote_audio_track = receivers[0]->track();
// Get the audio output level stats. Note that the level is not available
// until an RTCP packet has been received.
diff --git a/pc/test/peerconnectiontestwrapper.cc b/pc/test/peerconnectiontestwrapper.cc
index b34d7f8..e2f6067 100644
--- a/pc/test/peerconnectiontestwrapper.cc
+++ b/pc/test/peerconnectiontestwrapper.cc
@@ -263,9 +263,8 @@
PeerConnectionTestWrapper::GetUserMedia(
bool audio, const webrtc::FakeConstraints& audio_constraints,
bool video, const webrtc::FakeConstraints& video_constraints) {
- std::string label = kStreamLabelBase +
- rtc::ToString<int>(
- static_cast<int>(peer_connection_->local_streams()->count()));
+ std::string label =
+ kStreamLabelBase + rtc::ToString(num_get_user_media_calls_++);
rtc::scoped_refptr<webrtc::MediaStreamInterface> stream =
peer_connection_factory_->CreateLocalMediaStream(label);
diff --git a/pc/test/peerconnectiontestwrapper.h b/pc/test/peerconnectiontestwrapper.h
index aaf9408..338b31d 100644
--- a/pc/test/peerconnectiontestwrapper.h
+++ b/pc/test/peerconnectiontestwrapper.h
@@ -107,6 +107,7 @@
peer_connection_factory_;
rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
std::unique_ptr<webrtc::FakeVideoTrackRenderer> renderer_;
+ int num_get_user_media_calls_ = 0;
};
#endif // PC_TEST_PEERCONNECTIONTESTWRAPPER_H_