2013-11-20 21:49:41 +00:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2013 The WebRTC project authors. All Rights Reserved.
|
2013-11-20 21:49:41 +00:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2013-11-20 21:49:41 +00:00
|
|
|
*/
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "pc/test/peer_connection_test_wrapper.h"
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <stddef.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2019-09-17 17:06:18 +02:00
|
|
|
#include <memory>
|
2017-10-30 09:57:42 -07:00
|
|
|
#include <string>
|
2015-12-17 03:04:15 -08:00
|
|
|
#include <utility>
|
2018-01-24 19:35:55 -08:00
|
|
|
#include <vector>
|
2015-12-17 03:04:15 -08:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "absl/types/optional.h"
|
|
|
|
|
#include "api/audio/audio_mixer.h"
|
2018-11-22 09:00:13 +01:00
|
|
|
#include "api/create_peerconnection_factory.h"
|
2018-05-03 11:28:29 +02:00
|
|
|
#include "api/video_codecs/builtin_video_decoder_factory.h"
|
|
|
|
|
#include "api/video_codecs/builtin_video_encoder_factory.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "api/video_codecs/video_decoder_factory.h"
|
|
|
|
|
#include "api/video_codecs/video_encoder_factory.h"
|
|
|
|
|
#include "modules/audio_device/include/audio_device.h"
|
2018-05-03 11:28:29 +02:00
|
|
|
#include "modules/audio_processing/include/audio_processing.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "p2p/base/fake_port_allocator.h"
|
|
|
|
|
#include "p2p/base/port_allocator.h"
|
|
|
|
|
#include "pc/test/fake_periodic_video_source.h"
|
|
|
|
|
#include "pc/test/fake_periodic_video_track_source.h"
|
|
|
|
|
#include "pc/test/fake_rtc_certificate_generator.h"
|
|
|
|
|
#include "pc/test/mock_peer_connection_observers.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/gunit.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "rtc_base/logging.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/ref_counted_object.h"
|
|
|
|
|
#include "rtc_base/rtc_certificate_generator.h"
|
|
|
|
|
#include "rtc_base/string_encode.h"
|
2018-11-26 16:22:20 +01:00
|
|
|
#include "rtc_base/thread_checker.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/time_utils.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "test/gtest.h"
|
2013-11-20 21:49:41 +00:00
|
|
|
|
|
|
|
|
using webrtc::FakeVideoTrackRenderer;
|
|
|
|
|
using webrtc::IceCandidateInterface;
|
|
|
|
|
using webrtc::MediaStreamInterface;
|
2018-01-24 19:35:55 -08:00
|
|
|
using webrtc::MediaStreamTrackInterface;
|
2013-11-20 21:49:41 +00:00
|
|
|
using webrtc::MockSetSessionDescriptionObserver;
|
|
|
|
|
using webrtc::PeerConnectionInterface;
|
2018-01-24 19:35:55 -08:00
|
|
|
using webrtc::RtpReceiverInterface;
|
2017-12-07 10:27:41 -08:00
|
|
|
using webrtc::SdpType;
|
2013-11-20 21:49:41 +00:00
|
|
|
using webrtc::SessionDescriptionInterface;
|
|
|
|
|
using webrtc::VideoTrackInterface;
|
|
|
|
|
|
2017-12-07 10:27:41 -08:00
|
|
|
namespace {
|
2018-03-02 11:34:10 -08:00
|
|
|
const char kStreamIdBase[] = "stream_id";
|
2017-12-07 10:27:41 -08:00
|
|
|
const char kVideoTrackLabelBase[] = "video_track";
|
|
|
|
|
const char kAudioTrackLabelBase[] = "audio_track";
|
|
|
|
|
constexpr int kMaxWait = 10000;
|
|
|
|
|
constexpr int kTestAudioFrameCount = 3;
|
|
|
|
|
constexpr int kTestVideoFrameCount = 3;
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2013-11-20 21:49:41 +00:00
|
|
|
void PeerConnectionTestWrapper::Connect(PeerConnectionTestWrapper* caller,
|
|
|
|
|
PeerConnectionTestWrapper* callee) {
|
|
|
|
|
caller->SignalOnIceCandidateReady.connect(
|
|
|
|
|
callee, &PeerConnectionTestWrapper::AddIceCandidate);
|
|
|
|
|
callee->SignalOnIceCandidateReady.connect(
|
|
|
|
|
caller, &PeerConnectionTestWrapper::AddIceCandidate);
|
|
|
|
|
|
|
|
|
|
caller->SignalOnSdpReady.connect(callee,
|
|
|
|
|
&PeerConnectionTestWrapper::ReceiveOfferSdp);
|
|
|
|
|
callee->SignalOnSdpReady.connect(
|
|
|
|
|
caller, &PeerConnectionTestWrapper::ReceiveAnswerSdp);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-17 01:52:02 -07:00
|
|
|
PeerConnectionTestWrapper::PeerConnectionTestWrapper(
|
|
|
|
|
const std::string& name,
|
|
|
|
|
rtc::Thread* network_thread,
|
|
|
|
|
rtc::Thread* worker_thread)
|
|
|
|
|
: name_(name),
|
|
|
|
|
network_thread_(network_thread),
|
2020-06-11 12:26:53 +02:00
|
|
|
worker_thread_(worker_thread),
|
|
|
|
|
pending_negotiation_(false) {
|
2019-04-08 15:20:44 +02:00
|
|
|
pc_thread_checker_.Detach();
|
2018-11-26 16:22:20 +01:00
|
|
|
}
|
2013-11-20 21:49:41 +00:00
|
|
|
|
2018-11-26 16:22:20 +01:00
|
|
|
PeerConnectionTestWrapper::~PeerConnectionTestWrapper() {
|
|
|
|
|
RTC_DCHECK_RUN_ON(&pc_thread_checker_);
|
|
|
|
|
// Either network_thread or worker_thread might be active at this point.
|
|
|
|
|
// Relying on ~PeerConnection to properly wait for them doesn't work,
|
|
|
|
|
// as a vptr race might occur (before we enter the destruction body).
|
|
|
|
|
// See: bugs.webrtc.org/9847
|
|
|
|
|
if (pc()) {
|
|
|
|
|
pc()->Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-20 21:49:41 +00:00
|
|
|
|
|
|
|
|
bool PeerConnectionTestWrapper::CreatePc(
|
2017-04-19 03:47:57 -07:00
|
|
|
const webrtc::PeerConnectionInterface::RTCConfiguration& config,
|
|
|
|
|
rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
|
|
|
|
|
rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory) {
|
2016-04-27 06:47:29 -07:00
|
|
|
std::unique_ptr<cricket::PortAllocator> port_allocator(
|
2016-05-17 01:52:02 -07:00
|
|
|
new cricket::FakePortAllocator(network_thread_, nullptr));
|
2013-11-20 21:49:41 +00:00
|
|
|
|
2018-11-26 16:22:20 +01:00
|
|
|
RTC_DCHECK_RUN_ON(&pc_thread_checker_);
|
|
|
|
|
|
2015-08-13 14:27:18 -07:00
|
|
|
fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
|
2013-11-20 21:49:41 +00:00
|
|
|
if (fake_audio_capture_module_ == NULL) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
|
2016-05-17 01:52:02 -07:00
|
|
|
network_thread_, worker_thread_, rtc::Thread::Current(),
|
2018-05-03 11:28:29 +02:00
|
|
|
rtc::scoped_refptr<webrtc::AudioDeviceModule>(fake_audio_capture_module_),
|
|
|
|
|
audio_encoder_factory, audio_decoder_factory,
|
|
|
|
|
webrtc::CreateBuiltinVideoEncoderFactory(),
|
|
|
|
|
webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
|
|
|
|
|
nullptr /* audio_processing */);
|
2013-11-20 21:49:41 +00:00
|
|
|
if (!peer_connection_factory_) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 13:58:50 +02:00
|
|
|
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator(
|
2017-01-23 19:39:57 -08:00
|
|
|
new FakeRTCCertificateGenerator());
|
2016-06-01 13:58:50 +02:00
|
|
|
peer_connection_ = peer_connection_factory_->CreatePeerConnection(
|
2018-08-07 12:32:18 +02:00
|
|
|
config, std::move(port_allocator), std::move(cert_generator), this);
|
2013-11-20 21:49:41 +00:00
|
|
|
|
|
|
|
|
return peer_connection_.get() != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<webrtc::DataChannelInterface>
|
2014-06-12 21:59:29 +00:00
|
|
|
PeerConnectionTestWrapper::CreateDataChannel(
|
|
|
|
|
const std::string& label,
|
|
|
|
|
const webrtc::DataChannelInit& init) {
|
|
|
|
|
return peer_connection_->CreateDataChannel(label, &init);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-11 12:26:53 +02:00
|
|
|
void PeerConnectionTestWrapper::WaitForNegotiation() {
|
|
|
|
|
EXPECT_TRUE_WAIT(!pending_negotiation_, kMaxWait);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeerConnectionTestWrapper::OnSignalingChange(
|
|
|
|
|
webrtc::PeerConnectionInterface::SignalingState new_state) {
|
|
|
|
|
if (new_state == webrtc::PeerConnectionInterface::SignalingState::kStable) {
|
|
|
|
|
pending_negotiation_ = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-24 19:35:55 -08:00
|
|
|
void PeerConnectionTestWrapper::OnAddTrack(
|
|
|
|
|
rtc::scoped_refptr<RtpReceiverInterface> receiver,
|
|
|
|
|
const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) {
|
|
|
|
|
RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ << ": OnAddTrack";
|
|
|
|
|
if (receiver->track()->kind() == MediaStreamTrackInterface::kVideoKind) {
|
|
|
|
|
auto* video_track =
|
|
|
|
|
static_cast<VideoTrackInterface*>(receiver->track().get());
|
2019-09-17 17:06:18 +02:00
|
|
|
renderer_ = std::make_unique<FakeVideoTrackRenderer>(video_track);
|
2013-11-20 21:49:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeerConnectionTestWrapper::OnIceCandidate(
|
|
|
|
|
const IceCandidateInterface* candidate) {
|
|
|
|
|
std::string sdp;
|
|
|
|
|
EXPECT_TRUE(candidate->ToString(&sdp));
|
|
|
|
|
// Give the user a chance to modify sdp for testing.
|
|
|
|
|
SignalOnIceCandidateCreated(&sdp);
|
|
|
|
|
SignalOnIceCandidateReady(candidate->sdp_mid(), candidate->sdp_mline_index(),
|
|
|
|
|
sdp);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-12 21:59:29 +00:00
|
|
|
void PeerConnectionTestWrapper::OnDataChannel(
|
2016-05-31 13:02:21 -07:00
|
|
|
rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) {
|
2014-06-12 21:59:29 +00:00
|
|
|
SignalOnDataChannel(data_channel);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-20 21:49:41 +00:00
|
|
|
void PeerConnectionTestWrapper::OnSuccess(SessionDescriptionInterface* desc) {
|
2013-12-05 00:24:06 +00:00
|
|
|
// This callback should take the ownership of |desc|.
|
2016-04-27 06:47:29 -07:00
|
|
|
std::unique_ptr<SessionDescriptionInterface> owned_desc(desc);
|
2013-11-20 21:49:41 +00:00
|
|
|
std::string sdp;
|
|
|
|
|
EXPECT_TRUE(desc->ToString(&sdp));
|
|
|
|
|
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ << ": "
|
2017-12-07 10:27:41 -08:00
|
|
|
<< webrtc::SdpTypeToString(desc->GetType())
|
|
|
|
|
<< " sdp created: " << sdp;
|
2013-11-20 21:49:41 +00:00
|
|
|
|
|
|
|
|
// Give the user a chance to modify sdp for testing.
|
|
|
|
|
SignalOnSdpCreated(&sdp);
|
|
|
|
|
|
2017-12-07 10:27:41 -08:00
|
|
|
SetLocalDescription(desc->GetType(), sdp);
|
2013-11-20 21:49:41 +00:00
|
|
|
|
|
|
|
|
SignalOnSdpReady(sdp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeerConnectionTestWrapper::CreateOffer(
|
2018-08-07 12:32:18 +02:00
|
|
|
const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ << ": CreateOffer.";
|
2020-06-11 12:26:53 +02:00
|
|
|
pending_negotiation_ = true;
|
2018-08-07 12:32:18 +02:00
|
|
|
peer_connection_->CreateOffer(this, options);
|
2013-11-20 21:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeerConnectionTestWrapper::CreateAnswer(
|
2018-08-07 12:32:18 +02:00
|
|
|
const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_
|
|
|
|
|
<< ": CreateAnswer.";
|
2020-06-11 12:26:53 +02:00
|
|
|
pending_negotiation_ = true;
|
2018-08-07 12:32:18 +02:00
|
|
|
peer_connection_->CreateAnswer(this, options);
|
2013-11-20 21:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeerConnectionTestWrapper::ReceiveOfferSdp(const std::string& sdp) {
|
2017-12-07 10:27:41 -08:00
|
|
|
SetRemoteDescription(SdpType::kOffer, sdp);
|
2018-08-07 12:32:18 +02:00
|
|
|
CreateAnswer(webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
|
2013-11-20 21:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeerConnectionTestWrapper::ReceiveAnswerSdp(const std::string& sdp) {
|
2017-12-07 10:27:41 -08:00
|
|
|
SetRemoteDescription(SdpType::kAnswer, sdp);
|
2013-11-20 21:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
2017-12-07 10:27:41 -08:00
|
|
|
void PeerConnectionTestWrapper::SetLocalDescription(SdpType type,
|
2013-11-20 21:49:41 +00:00
|
|
|
const std::string& sdp) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_
|
2017-12-07 10:27:41 -08:00
|
|
|
<< ": SetLocalDescription " << webrtc::SdpTypeToString(type)
|
|
|
|
|
<< " " << sdp;
|
2013-11-20 21:49:41 +00:00
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
|
2013-11-20 21:49:41 +00:00
|
|
|
new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
|
|
|
|
|
peer_connection_->SetLocalDescription(
|
2017-12-07 10:27:41 -08:00
|
|
|
observer, webrtc::CreateSessionDescription(type, sdp).release());
|
2013-11-20 21:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
2017-12-07 10:27:41 -08:00
|
|
|
void PeerConnectionTestWrapper::SetRemoteDescription(SdpType type,
|
2013-11-20 21:49:41 +00:00
|
|
|
const std::string& sdp) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_
|
2017-12-07 10:27:41 -08:00
|
|
|
<< ": SetRemoteDescription " << webrtc::SdpTypeToString(type)
|
|
|
|
|
<< " " << sdp;
|
2013-11-20 21:49:41 +00:00
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
|
2013-11-20 21:49:41 +00:00
|
|
|
new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
|
|
|
|
|
peer_connection_->SetRemoteDescription(
|
2017-12-07 10:27:41 -08:00
|
|
|
observer, webrtc::CreateSessionDescription(type, sdp).release());
|
2013-11-20 21:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeerConnectionTestWrapper::AddIceCandidate(const std::string& sdp_mid,
|
|
|
|
|
int sdp_mline_index,
|
|
|
|
|
const std::string& candidate) {
|
2016-04-27 06:47:29 -07:00
|
|
|
std::unique_ptr<webrtc::IceCandidateInterface> owned_candidate(
|
2013-12-05 00:24:06 +00:00
|
|
|
webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, candidate, NULL));
|
|
|
|
|
EXPECT_TRUE(peer_connection_->AddIceCandidate(owned_candidate.get()));
|
2013-11-20 21:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeerConnectionTestWrapper::WaitForCallEstablished() {
|
|
|
|
|
WaitForConnection();
|
|
|
|
|
WaitForAudio();
|
|
|
|
|
WaitForVideo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeerConnectionTestWrapper::WaitForConnection() {
|
|
|
|
|
EXPECT_TRUE_WAIT(CheckForConnection(), kMaxWait);
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ << ": Connected.";
|
2013-11-20 21:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PeerConnectionTestWrapper::CheckForConnection() {
|
|
|
|
|
return (peer_connection_->ice_connection_state() ==
|
2014-02-14 00:56:12 +00:00
|
|
|
PeerConnectionInterface::kIceConnectionConnected) ||
|
|
|
|
|
(peer_connection_->ice_connection_state() ==
|
|
|
|
|
PeerConnectionInterface::kIceConnectionCompleted);
|
2013-11-20 21:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeerConnectionTestWrapper::WaitForAudio() {
|
|
|
|
|
EXPECT_TRUE_WAIT(CheckForAudio(), kMaxWait);
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_
|
|
|
|
|
<< ": Got enough audio frames.";
|
2013-11-20 21:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PeerConnectionTestWrapper::CheckForAudio() {
|
|
|
|
|
return (fake_audio_capture_module_->frames_received() >=
|
|
|
|
|
kTestAudioFrameCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeerConnectionTestWrapper::WaitForVideo() {
|
|
|
|
|
EXPECT_TRUE_WAIT(CheckForVideo(), kMaxWait);
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_
|
|
|
|
|
<< ": Got enough video frames.";
|
2013-11-20 21:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PeerConnectionTestWrapper::CheckForVideo() {
|
|
|
|
|
if (!renderer_) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return (renderer_->num_rendered_frames() >= kTestVideoFrameCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PeerConnectionTestWrapper::GetAndAddUserMedia(
|
2018-05-21 11:23:35 +02:00
|
|
|
bool audio,
|
|
|
|
|
const cricket::AudioOptions& audio_options,
|
2019-02-12 12:30:58 +01:00
|
|
|
bool video) {
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<webrtc::MediaStreamInterface> stream =
|
2019-02-12 12:30:58 +01:00
|
|
|
GetUserMedia(audio, audio_options, video);
|
2019-01-27 17:29:42 +01:00
|
|
|
for (const auto& audio_track : stream->GetAudioTracks()) {
|
2018-03-13 16:05:28 -07:00
|
|
|
EXPECT_TRUE(peer_connection_->AddTrack(audio_track, {stream->id()}).ok());
|
2018-01-24 19:35:55 -08:00
|
|
|
}
|
2019-01-27 17:29:42 +01:00
|
|
|
for (const auto& video_track : stream->GetVideoTracks()) {
|
2018-03-13 16:05:28 -07:00
|
|
|
EXPECT_TRUE(peer_connection_->AddTrack(video_track, {stream->id()}).ok());
|
2018-01-24 19:35:55 -08:00
|
|
|
}
|
2013-11-20 21:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<webrtc::MediaStreamInterface>
|
2018-05-21 11:23:35 +02:00
|
|
|
PeerConnectionTestWrapper::GetUserMedia(
|
|
|
|
|
bool audio,
|
|
|
|
|
const cricket::AudioOptions& audio_options,
|
2019-02-12 12:30:58 +01:00
|
|
|
bool video) {
|
2018-03-02 11:34:10 -08:00
|
|
|
std::string stream_id =
|
|
|
|
|
kStreamIdBase + rtc::ToString(num_get_user_media_calls_++);
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<webrtc::MediaStreamInterface> stream =
|
2018-03-02 11:34:10 -08:00
|
|
|
peer_connection_factory_->CreateLocalMediaStream(stream_id);
|
2013-11-20 21:49:41 +00:00
|
|
|
|
|
|
|
|
if (audio) {
|
2018-05-21 11:23:35 +02:00
|
|
|
cricket::AudioOptions options = audio_options;
|
2013-11-20 21:49:41 +00:00
|
|
|
// Disable highpass filter so that we can get all the test audio frames.
|
2018-05-21 11:23:35 +02:00
|
|
|
options.highpass_filter = false;
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
|
2018-05-21 11:23:35 +02:00
|
|
|
peer_connection_factory_->CreateAudioSource(options);
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
|
2013-11-20 21:49:41 +00:00
|
|
|
peer_connection_factory_->CreateAudioTrack(kAudioTrackLabelBase,
|
|
|
|
|
source));
|
|
|
|
|
stream->AddTrack(audio_track);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (video) {
|
|
|
|
|
// Set max frame rate to 10fps to reduce the risk of the tests to be flaky.
|
2018-05-28 16:20:42 +02:00
|
|
|
webrtc::FakePeriodicVideoSource::Config config;
|
|
|
|
|
config.frame_interval_ms = 100;
|
2018-09-13 15:36:20 +02:00
|
|
|
config.timestamp_offset_ms = rtc::TimeMillis();
|
2013-11-20 21:49:41 +00:00
|
|
|
|
2016-03-08 01:27:48 +01:00
|
|
|
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
|
2018-05-28 16:20:42 +02:00
|
|
|
new rtc::RefCountedObject<webrtc::FakePeriodicVideoTrackSource>(
|
|
|
|
|
config, /* remote */ false);
|
|
|
|
|
|
2018-03-02 11:34:10 -08:00
|
|
|
std::string videotrack_label = stream_id + kVideoTrackLabelBase;
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
|
2013-11-20 21:49:41 +00:00
|
|
|
peer_connection_factory_->CreateVideoTrack(videotrack_label, source));
|
|
|
|
|
|
|
|
|
|
stream->AddTrack(video_track);
|
|
|
|
|
}
|
|
|
|
|
return stream;
|
|
|
|
|
}
|