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}
This commit is contained in:
Steve Anton 2018-03-01 13:48:58 -08:00 committed by Commit Bot
parent 6d30631f01
commit fc8537143f
4 changed files with 26 additions and 19 deletions

View File

@ -986,15 +986,23 @@ RTCError PeerConnection::ValidateConfiguration(
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 @@ bool PeerConnection::AddStream(MediaStreamInterface* local_stream) {
}
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 @@ RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>
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 @@ PeerConnection::AddTransceiver(cricket::MediaType media_type) {
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<DtmfSenderInterface> PeerConnection::CreateDtmfSender(
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 @@ PeerConnection::GetReceiversInternal() const {
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);

View File

@ -2326,11 +2326,9 @@ TEST_P(PeerConnectionIntegrationTest, GetCaptureStartNtpTimeWithOldStatsApi) {
// 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.

View File

@ -263,9 +263,8 @@ rtc::scoped_refptr<webrtc::MediaStreamInterface>
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);

View File

@ -107,6 +107,7 @@ class PeerConnectionTestWrapper
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_