Remove DegradedCall - To be submitted after 2024-07-01
Bug: webrtc:343801362 Change-Id: Icae19ab2f4c87521483d25ae8d44c849c5f8ed2e Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353140 Commit-Queue: Per Kjellander <perkj@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Florent Castelli <orphis@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42892}
This commit is contained in:
parent
a49abbb3b6
commit
b4c1f2f6fc
@ -37,7 +37,6 @@ rtc_source_set("enable_media") {
|
||||
":scoped_refptr",
|
||||
"../call",
|
||||
"../call:call_interfaces",
|
||||
"../call:call_interfaces",
|
||||
"../media:media_engine",
|
||||
"../media:rtc_audio_video",
|
||||
"../pc:media_factory",
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
#include "api/scoped_refptr.h"
|
||||
#include "call/call.h"
|
||||
#include "call/call_config.h"
|
||||
#include "call/create_call.h"
|
||||
#include "media/base/media_engine.h"
|
||||
#include "media/engine/webrtc_video_engine.h"
|
||||
#include "media/engine/webrtc_voice_engine.h"
|
||||
@ -40,7 +39,7 @@ class MediaFactoryImpl : public MediaFactory {
|
||||
~MediaFactoryImpl() override = default;
|
||||
|
||||
std::unique_ptr<Call> CreateCall(CallConfig config) override {
|
||||
return webrtc::CreateCall(std::move(config));
|
||||
return webrtc::Call::Create(std::move(config));
|
||||
}
|
||||
|
||||
std::unique_ptr<MediaEngineInterface> CreateMediaEngine(
|
||||
|
||||
@ -269,10 +269,6 @@ rtc_library("bitrate_allocator") {
|
||||
rtc_library("call") {
|
||||
sources = [
|
||||
"call.cc",
|
||||
"create_call.cc",
|
||||
"create_call.h",
|
||||
"degraded_call.cc",
|
||||
"degraded_call.h",
|
||||
"flexfec_receive_stream_impl.cc",
|
||||
"flexfec_receive_stream_impl.h",
|
||||
"receive_time_calculator.cc",
|
||||
|
||||
@ -10,72 +10,11 @@
|
||||
|
||||
#include "call/create_call.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/test/simulated_network.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "call/call.h"
|
||||
#include "call/degraded_call.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/experiments/field_trial_list.h"
|
||||
#include "rtc_base/experiments/field_trial_parser.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
using TimeScopedNetworkConfig = DegradedCall::TimeScopedNetworkConfig;
|
||||
|
||||
std::vector<TimeScopedNetworkConfig> GetNetworkConfigs(
|
||||
const FieldTrialsView& trials,
|
||||
bool send) {
|
||||
FieldTrialStructList<TimeScopedNetworkConfig> trials_list(
|
||||
{FieldTrialStructMember("queue_length_packets",
|
||||
[](TimeScopedNetworkConfig* p) {
|
||||
// FieldTrialParser does not natively support
|
||||
// size_t type, so use this ugly cast as
|
||||
// workaround.
|
||||
return reinterpret_cast<unsigned*>(
|
||||
&p->queue_length_packets);
|
||||
}),
|
||||
FieldTrialStructMember(
|
||||
"queue_delay_ms",
|
||||
[](TimeScopedNetworkConfig* p) { return &p->queue_delay_ms; }),
|
||||
FieldTrialStructMember("delay_standard_deviation_ms",
|
||||
[](TimeScopedNetworkConfig* p) {
|
||||
return &p->delay_standard_deviation_ms;
|
||||
}),
|
||||
FieldTrialStructMember(
|
||||
"link_capacity_kbps",
|
||||
[](TimeScopedNetworkConfig* p) { return &p->link_capacity_kbps; }),
|
||||
FieldTrialStructMember(
|
||||
"loss_percent",
|
||||
[](TimeScopedNetworkConfig* p) { return &p->loss_percent; }),
|
||||
FieldTrialStructMember(
|
||||
"allow_reordering",
|
||||
[](TimeScopedNetworkConfig* p) { return &p->allow_reordering; }),
|
||||
FieldTrialStructMember("avg_burst_loss_length",
|
||||
[](TimeScopedNetworkConfig* p) {
|
||||
return &p->avg_burst_loss_length;
|
||||
}),
|
||||
FieldTrialStructMember(
|
||||
"packet_overhead",
|
||||
[](TimeScopedNetworkConfig* p) { return &p->packet_overhead; }),
|
||||
FieldTrialStructMember(
|
||||
"duration",
|
||||
[](TimeScopedNetworkConfig* p) { return &p->duration; })},
|
||||
{});
|
||||
ParseFieldTrial({&trials_list},
|
||||
trials.Lookup(send ? "WebRTC-FakeNetworkSendConfig"
|
||||
: "WebRTC-FakeNetworkReceiveConfig"));
|
||||
return trials_list.Get();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Call> CreateCall(CallConfig config) {
|
||||
std::vector<DegradedCall::TimeScopedNetworkConfig> send_degradation_configs =
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef CALL_CREATE_CALL_H_
|
||||
#define CALL_CREATE_CALL_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "call/call.h"
|
||||
#include "call/call_config.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
std::unique_ptr<Call> CreateCall(CallConfig config);
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // CALL_CREATE_CALL_H_
|
||||
@ -1,380 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "call/degraded_call.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/sequence_checker.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_util.h"
|
||||
#include "rtc_base/thread.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
DegradedCall::FakeNetworkPipeOnTaskQueue::FakeNetworkPipeOnTaskQueue(
|
||||
TaskQueueBase* task_queue,
|
||||
rtc::scoped_refptr<PendingTaskSafetyFlag> call_alive,
|
||||
Clock* clock,
|
||||
std::unique_ptr<NetworkBehaviorInterface> network_behavior)
|
||||
: clock_(clock),
|
||||
task_queue_(task_queue),
|
||||
call_alive_(std::move(call_alive)),
|
||||
pipe_(clock, std::move(network_behavior)) {}
|
||||
|
||||
void DegradedCall::FakeNetworkPipeOnTaskQueue::SendRtp(
|
||||
rtc::ArrayView<const uint8_t> packet,
|
||||
const PacketOptions& options,
|
||||
Transport* transport) {
|
||||
pipe_.SendRtp(packet, options, transport);
|
||||
Process();
|
||||
}
|
||||
|
||||
void DegradedCall::FakeNetworkPipeOnTaskQueue::SendRtcp(
|
||||
rtc::ArrayView<const uint8_t> packet,
|
||||
Transport* transport) {
|
||||
pipe_.SendRtcp(packet, transport);
|
||||
Process();
|
||||
}
|
||||
|
||||
void DegradedCall::FakeNetworkPipeOnTaskQueue::AddActiveTransport(
|
||||
Transport* transport) {
|
||||
pipe_.AddActiveTransport(transport);
|
||||
}
|
||||
|
||||
void DegradedCall::FakeNetworkPipeOnTaskQueue::RemoveActiveTransport(
|
||||
Transport* transport) {
|
||||
pipe_.RemoveActiveTransport(transport);
|
||||
}
|
||||
|
||||
bool DegradedCall::FakeNetworkPipeOnTaskQueue::Process() {
|
||||
pipe_.Process();
|
||||
auto time_to_next = pipe_.TimeUntilNextProcess();
|
||||
if (!time_to_next) {
|
||||
// Packet was probably sent immediately.
|
||||
return false;
|
||||
}
|
||||
|
||||
task_queue_->PostTask(SafeTask(call_alive_, [this, time_to_next] {
|
||||
RTC_DCHECK_RUN_ON(task_queue_);
|
||||
int64_t next_process_time = *time_to_next + clock_->TimeInMilliseconds();
|
||||
if (!next_process_ms_ || next_process_time < *next_process_ms_) {
|
||||
next_process_ms_ = next_process_time;
|
||||
task_queue_->PostDelayedHighPrecisionTask(
|
||||
SafeTask(call_alive_,
|
||||
[this] {
|
||||
RTC_DCHECK_RUN_ON(task_queue_);
|
||||
if (!Process()) {
|
||||
next_process_ms_.reset();
|
||||
}
|
||||
}),
|
||||
TimeDelta::Millis(*time_to_next));
|
||||
}
|
||||
}));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DegradedCall::FakeNetworkPipeTransportAdapter::FakeNetworkPipeTransportAdapter(
|
||||
FakeNetworkPipeOnTaskQueue* fake_network,
|
||||
Call* call,
|
||||
Clock* clock,
|
||||
Transport* real_transport)
|
||||
: network_pipe_(fake_network),
|
||||
call_(call),
|
||||
clock_(clock),
|
||||
real_transport_(real_transport) {
|
||||
network_pipe_->AddActiveTransport(real_transport);
|
||||
}
|
||||
|
||||
DegradedCall::FakeNetworkPipeTransportAdapter::
|
||||
~FakeNetworkPipeTransportAdapter() {
|
||||
network_pipe_->RemoveActiveTransport(real_transport_);
|
||||
}
|
||||
|
||||
bool DegradedCall::FakeNetworkPipeTransportAdapter::SendRtp(
|
||||
rtc::ArrayView<const uint8_t> packet,
|
||||
const PacketOptions& options) {
|
||||
// A call here comes from the RTP stack (probably pacer). We intercept it and
|
||||
// put it in the fake network pipe instead, but report to Call that is has
|
||||
// been sent, so that the bandwidth estimator sees the delay we add.
|
||||
network_pipe_->SendRtp(packet, options, real_transport_);
|
||||
if (options.packet_id != -1) {
|
||||
rtc::SentPacket sent_packet;
|
||||
sent_packet.packet_id = options.packet_id;
|
||||
sent_packet.send_time_ms = clock_->TimeInMilliseconds();
|
||||
sent_packet.info.included_in_feedback = options.included_in_feedback;
|
||||
sent_packet.info.included_in_allocation = options.included_in_allocation;
|
||||
sent_packet.info.packet_size_bytes = packet.size();
|
||||
sent_packet.info.packet_type = rtc::PacketType::kData;
|
||||
call_->OnSentPacket(sent_packet);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DegradedCall::FakeNetworkPipeTransportAdapter::SendRtcp(
|
||||
rtc::ArrayView<const uint8_t> packet) {
|
||||
network_pipe_->SendRtcp(packet, real_transport_);
|
||||
return true;
|
||||
}
|
||||
|
||||
DegradedCall::DegradedCall(
|
||||
std::unique_ptr<Call> call,
|
||||
const std::vector<TimeScopedNetworkConfig>& send_configs,
|
||||
const std::vector<TimeScopedNetworkConfig>& receive_configs)
|
||||
: clock_(Clock::GetRealTimeClock()),
|
||||
call_(std::move(call)),
|
||||
call_alive_(PendingTaskSafetyFlag::CreateDetached()),
|
||||
send_config_index_(0),
|
||||
send_configs_(send_configs),
|
||||
send_simulated_network_(nullptr),
|
||||
receive_config_index_(0),
|
||||
receive_configs_(receive_configs) {
|
||||
if (!receive_configs_.empty()) {
|
||||
auto network = std::make_unique<SimulatedNetwork>(receive_configs_[0]);
|
||||
receive_simulated_network_ = network.get();
|
||||
receive_pipe_ =
|
||||
std::make_unique<webrtc::FakeNetworkPipe>(clock_, std::move(network));
|
||||
receive_pipe_->SetReceiver(call_->Receiver());
|
||||
if (receive_configs_.size() > 1) {
|
||||
call_->network_thread()->PostDelayedTask(
|
||||
SafeTask(call_alive_, [this] { UpdateReceiveNetworkConfig(); }),
|
||||
receive_configs_[0].duration);
|
||||
}
|
||||
}
|
||||
if (!send_configs_.empty()) {
|
||||
auto network = std::make_unique<SimulatedNetwork>(send_configs_[0]);
|
||||
send_simulated_network_ = network.get();
|
||||
send_pipe_ = std::make_unique<FakeNetworkPipeOnTaskQueue>(
|
||||
call_->network_thread(), call_alive_, clock_, std::move(network));
|
||||
if (send_configs_.size() > 1) {
|
||||
call_->network_thread()->PostDelayedTask(
|
||||
SafeTask(call_alive_, [this] { UpdateSendNetworkConfig(); }),
|
||||
send_configs_[0].duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DegradedCall::~DegradedCall() {
|
||||
RTC_DCHECK_RUN_ON(call_->worker_thread());
|
||||
// Thread synchronization is required to call `SetNotAlive`.
|
||||
// Otherwise, when the `DegradedCall` object is destroyed but
|
||||
// `SetNotAlive` has not yet been called,
|
||||
// another Closure guarded by `call_alive_` may be called.
|
||||
// TODO(https://crbug.com/webrtc/12649): Remove this block-invoke.
|
||||
static_cast<rtc::Thread*>(call_->network_thread())
|
||||
->BlockingCall(
|
||||
[flag = std::move(call_alive_)]() mutable { flag->SetNotAlive(); });
|
||||
}
|
||||
|
||||
AudioSendStream* DegradedCall::CreateAudioSendStream(
|
||||
const AudioSendStream::Config& config) {
|
||||
if (!send_configs_.empty()) {
|
||||
auto transport_adapter = std::make_unique<FakeNetworkPipeTransportAdapter>(
|
||||
send_pipe_.get(), call_.get(), clock_, config.send_transport);
|
||||
AudioSendStream::Config degrade_config = config;
|
||||
degrade_config.send_transport = transport_adapter.get();
|
||||
AudioSendStream* send_stream = call_->CreateAudioSendStream(degrade_config);
|
||||
if (send_stream) {
|
||||
audio_send_transport_adapters_[send_stream] =
|
||||
std::move(transport_adapter);
|
||||
}
|
||||
return send_stream;
|
||||
}
|
||||
return call_->CreateAudioSendStream(config);
|
||||
}
|
||||
|
||||
void DegradedCall::DestroyAudioSendStream(AudioSendStream* send_stream) {
|
||||
call_->DestroyAudioSendStream(send_stream);
|
||||
audio_send_transport_adapters_.erase(send_stream);
|
||||
}
|
||||
|
||||
AudioReceiveStreamInterface* DegradedCall::CreateAudioReceiveStream(
|
||||
const AudioReceiveStreamInterface::Config& config) {
|
||||
return call_->CreateAudioReceiveStream(config);
|
||||
}
|
||||
|
||||
void DegradedCall::DestroyAudioReceiveStream(
|
||||
AudioReceiveStreamInterface* receive_stream) {
|
||||
call_->DestroyAudioReceiveStream(receive_stream);
|
||||
}
|
||||
|
||||
VideoSendStream* DegradedCall::CreateVideoSendStream(
|
||||
VideoSendStream::Config config,
|
||||
VideoEncoderConfig encoder_config) {
|
||||
std::unique_ptr<FakeNetworkPipeTransportAdapter> transport_adapter;
|
||||
if (!send_configs_.empty()) {
|
||||
transport_adapter = std::make_unique<FakeNetworkPipeTransportAdapter>(
|
||||
send_pipe_.get(), call_.get(), clock_, config.send_transport);
|
||||
config.send_transport = transport_adapter.get();
|
||||
}
|
||||
VideoSendStream* send_stream = call_->CreateVideoSendStream(
|
||||
std::move(config), std::move(encoder_config));
|
||||
if (send_stream && transport_adapter) {
|
||||
video_send_transport_adapters_[send_stream] = std::move(transport_adapter);
|
||||
}
|
||||
return send_stream;
|
||||
}
|
||||
|
||||
VideoSendStream* DegradedCall::CreateVideoSendStream(
|
||||
VideoSendStream::Config config,
|
||||
VideoEncoderConfig encoder_config,
|
||||
std::unique_ptr<FecController> fec_controller) {
|
||||
std::unique_ptr<FakeNetworkPipeTransportAdapter> transport_adapter;
|
||||
if (!send_configs_.empty()) {
|
||||
transport_adapter = std::make_unique<FakeNetworkPipeTransportAdapter>(
|
||||
send_pipe_.get(), call_.get(), clock_, config.send_transport);
|
||||
config.send_transport = transport_adapter.get();
|
||||
}
|
||||
VideoSendStream* send_stream = call_->CreateVideoSendStream(
|
||||
std::move(config), std::move(encoder_config), std::move(fec_controller));
|
||||
if (send_stream && transport_adapter) {
|
||||
video_send_transport_adapters_[send_stream] = std::move(transport_adapter);
|
||||
}
|
||||
return send_stream;
|
||||
}
|
||||
|
||||
void DegradedCall::DestroyVideoSendStream(VideoSendStream* send_stream) {
|
||||
call_->DestroyVideoSendStream(send_stream);
|
||||
video_send_transport_adapters_.erase(send_stream);
|
||||
}
|
||||
|
||||
VideoReceiveStreamInterface* DegradedCall::CreateVideoReceiveStream(
|
||||
VideoReceiveStreamInterface::Config configuration) {
|
||||
return call_->CreateVideoReceiveStream(std::move(configuration));
|
||||
}
|
||||
|
||||
void DegradedCall::DestroyVideoReceiveStream(
|
||||
VideoReceiveStreamInterface* receive_stream) {
|
||||
call_->DestroyVideoReceiveStream(receive_stream);
|
||||
}
|
||||
|
||||
FlexfecReceiveStream* DegradedCall::CreateFlexfecReceiveStream(
|
||||
const FlexfecReceiveStream::Config config) {
|
||||
return call_->CreateFlexfecReceiveStream(std::move(config));
|
||||
}
|
||||
|
||||
void DegradedCall::DestroyFlexfecReceiveStream(
|
||||
FlexfecReceiveStream* receive_stream) {
|
||||
call_->DestroyFlexfecReceiveStream(receive_stream);
|
||||
}
|
||||
|
||||
void DegradedCall::AddAdaptationResource(
|
||||
rtc::scoped_refptr<Resource> resource) {
|
||||
call_->AddAdaptationResource(std::move(resource));
|
||||
}
|
||||
|
||||
PacketReceiver* DegradedCall::Receiver() {
|
||||
if (!receive_configs_.empty()) {
|
||||
return this;
|
||||
}
|
||||
return call_->Receiver();
|
||||
}
|
||||
|
||||
RtpTransportControllerSendInterface*
|
||||
DegradedCall::GetTransportControllerSend() {
|
||||
return call_->GetTransportControllerSend();
|
||||
}
|
||||
|
||||
Call::Stats DegradedCall::GetStats() const {
|
||||
return call_->GetStats();
|
||||
}
|
||||
|
||||
const FieldTrialsView& DegradedCall::trials() const {
|
||||
return call_->trials();
|
||||
}
|
||||
|
||||
TaskQueueBase* DegradedCall::network_thread() const {
|
||||
return call_->network_thread();
|
||||
}
|
||||
|
||||
TaskQueueBase* DegradedCall::worker_thread() const {
|
||||
return call_->worker_thread();
|
||||
}
|
||||
|
||||
void DegradedCall::SignalChannelNetworkState(MediaType media,
|
||||
NetworkState state) {
|
||||
call_->SignalChannelNetworkState(media, state);
|
||||
}
|
||||
|
||||
void DegradedCall::OnAudioTransportOverheadChanged(
|
||||
int transport_overhead_per_packet) {
|
||||
call_->OnAudioTransportOverheadChanged(transport_overhead_per_packet);
|
||||
}
|
||||
|
||||
void DegradedCall::OnLocalSsrcUpdated(AudioReceiveStreamInterface& stream,
|
||||
uint32_t local_ssrc) {
|
||||
call_->OnLocalSsrcUpdated(stream, local_ssrc);
|
||||
}
|
||||
|
||||
void DegradedCall::OnLocalSsrcUpdated(VideoReceiveStreamInterface& stream,
|
||||
uint32_t local_ssrc) {
|
||||
call_->OnLocalSsrcUpdated(stream, local_ssrc);
|
||||
}
|
||||
|
||||
void DegradedCall::OnLocalSsrcUpdated(FlexfecReceiveStream& stream,
|
||||
uint32_t local_ssrc) {
|
||||
call_->OnLocalSsrcUpdated(stream, local_ssrc);
|
||||
}
|
||||
|
||||
void DegradedCall::OnUpdateSyncGroup(AudioReceiveStreamInterface& stream,
|
||||
absl::string_view sync_group) {
|
||||
call_->OnUpdateSyncGroup(stream, sync_group);
|
||||
}
|
||||
|
||||
void DegradedCall::OnSentPacket(const rtc::SentPacket& sent_packet) {
|
||||
if (!send_configs_.empty()) {
|
||||
// If we have a degraded send-transport, we have already notified call
|
||||
// about the supposed network send time. Discard the actual network send
|
||||
// time in order to properly fool the BWE.
|
||||
return;
|
||||
}
|
||||
call_->OnSentPacket(sent_packet);
|
||||
}
|
||||
|
||||
void DegradedCall::DeliverRtpPacket(
|
||||
MediaType media_type,
|
||||
RtpPacketReceived packet,
|
||||
OnUndemuxablePacketHandler undemuxable_packet_handler) {
|
||||
RTC_DCHECK_RUN_ON(&received_packet_sequence_checker_);
|
||||
receive_pipe_->DeliverRtpPacket(media_type, std::move(packet),
|
||||
std::move(undemuxable_packet_handler));
|
||||
receive_pipe_->Process();
|
||||
}
|
||||
|
||||
void DegradedCall::DeliverRtcpPacket(rtc::CopyOnWriteBuffer packet) {
|
||||
RTC_DCHECK_RUN_ON(&received_packet_sequence_checker_);
|
||||
receive_pipe_->DeliverRtcpPacket(std::move(packet));
|
||||
receive_pipe_->Process();
|
||||
}
|
||||
|
||||
void DegradedCall::SetClientBitratePreferences(
|
||||
const webrtc::BitrateSettings& preferences) {
|
||||
call_->SetClientBitratePreferences(preferences);
|
||||
}
|
||||
|
||||
void DegradedCall::UpdateSendNetworkConfig() {
|
||||
send_config_index_ = (send_config_index_ + 1) % send_configs_.size();
|
||||
send_simulated_network_->SetConfig(send_configs_[send_config_index_]);
|
||||
call_->network_thread()->PostDelayedTask(
|
||||
SafeTask(call_alive_, [this] { UpdateSendNetworkConfig(); }),
|
||||
send_configs_[send_config_index_].duration);
|
||||
}
|
||||
|
||||
void DegradedCall::UpdateReceiveNetworkConfig() {
|
||||
receive_config_index_ = (receive_config_index_ + 1) % receive_configs_.size();
|
||||
receive_simulated_network_->SetConfig(
|
||||
receive_configs_[receive_config_index_]);
|
||||
call_->network_thread()->PostDelayedTask(
|
||||
SafeTask(call_alive_, [this] { UpdateReceiveNetworkConfig(); }),
|
||||
receive_configs_[receive_config_index_].duration);
|
||||
}
|
||||
} // namespace webrtc
|
||||
@ -1,201 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef CALL_DEGRADED_CALL_H_
|
||||
#define CALL_DEGRADED_CALL_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/call/transport.h"
|
||||
#include "api/fec_controller.h"
|
||||
#include "api/media_types.h"
|
||||
#include "api/rtp_headers.h"
|
||||
#include "api/task_queue/pending_task_safety_flag.h"
|
||||
#include "api/test/simulated_network.h"
|
||||
#include "call/audio_receive_stream.h"
|
||||
#include "call/audio_send_stream.h"
|
||||
#include "call/call.h"
|
||||
#include "call/fake_network_pipe.h"
|
||||
#include "call/flexfec_receive_stream.h"
|
||||
#include "call/packet_receiver.h"
|
||||
#include "call/rtp_transport_controller_send_interface.h"
|
||||
#include "call/video_receive_stream.h"
|
||||
#include "call/video_send_stream.h"
|
||||
#include "rtc_base/copy_on_write_buffer.h"
|
||||
#include "rtc_base/network/sent_packet.h"
|
||||
#include "system_wrappers/include/clock.h"
|
||||
#include "test/network/simulated_network.h"
|
||||
#include "video/config/video_encoder_config.h"
|
||||
|
||||
namespace webrtc {
|
||||
class DegradedCall : public Call, private PacketReceiver {
|
||||
public:
|
||||
struct TimeScopedNetworkConfig : public BuiltInNetworkBehaviorConfig {
|
||||
TimeDelta duration = TimeDelta::PlusInfinity();
|
||||
};
|
||||
|
||||
explicit DegradedCall(
|
||||
std::unique_ptr<Call> call,
|
||||
const std::vector<TimeScopedNetworkConfig>& send_configs,
|
||||
const std::vector<TimeScopedNetworkConfig>& receive_configs);
|
||||
~DegradedCall() override;
|
||||
|
||||
// Implements Call.
|
||||
AudioSendStream* CreateAudioSendStream(
|
||||
const AudioSendStream::Config& config) override;
|
||||
void DestroyAudioSendStream(AudioSendStream* send_stream) override;
|
||||
|
||||
AudioReceiveStreamInterface* CreateAudioReceiveStream(
|
||||
const AudioReceiveStreamInterface::Config& config) override;
|
||||
void DestroyAudioReceiveStream(
|
||||
AudioReceiveStreamInterface* receive_stream) override;
|
||||
|
||||
VideoSendStream* CreateVideoSendStream(
|
||||
VideoSendStream::Config config,
|
||||
VideoEncoderConfig encoder_config) override;
|
||||
VideoSendStream* CreateVideoSendStream(
|
||||
VideoSendStream::Config config,
|
||||
VideoEncoderConfig encoder_config,
|
||||
std::unique_ptr<FecController> fec_controller) override;
|
||||
void DestroyVideoSendStream(VideoSendStream* send_stream) override;
|
||||
|
||||
VideoReceiveStreamInterface* CreateVideoReceiveStream(
|
||||
VideoReceiveStreamInterface::Config configuration) override;
|
||||
void DestroyVideoReceiveStream(
|
||||
VideoReceiveStreamInterface* receive_stream) override;
|
||||
|
||||
FlexfecReceiveStream* CreateFlexfecReceiveStream(
|
||||
const FlexfecReceiveStream::Config config) override;
|
||||
void DestroyFlexfecReceiveStream(
|
||||
FlexfecReceiveStream* receive_stream) override;
|
||||
|
||||
void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) override;
|
||||
|
||||
PacketReceiver* Receiver() override;
|
||||
|
||||
RtpTransportControllerSendInterface* GetTransportControllerSend() override;
|
||||
|
||||
Stats GetStats() const override;
|
||||
|
||||
const FieldTrialsView& trials() const override;
|
||||
|
||||
TaskQueueBase* network_thread() const override;
|
||||
TaskQueueBase* worker_thread() const override;
|
||||
|
||||
void SignalChannelNetworkState(MediaType media, NetworkState state) override;
|
||||
void OnAudioTransportOverheadChanged(
|
||||
int transport_overhead_per_packet) override;
|
||||
void OnLocalSsrcUpdated(AudioReceiveStreamInterface& stream,
|
||||
uint32_t local_ssrc) override;
|
||||
void OnLocalSsrcUpdated(VideoReceiveStreamInterface& stream,
|
||||
uint32_t local_ssrc) override;
|
||||
void OnLocalSsrcUpdated(FlexfecReceiveStream& stream,
|
||||
uint32_t local_ssrc) override;
|
||||
void OnUpdateSyncGroup(AudioReceiveStreamInterface& stream,
|
||||
absl::string_view sync_group) override;
|
||||
void OnSentPacket(const rtc::SentPacket& sent_packet) override;
|
||||
|
||||
protected:
|
||||
// Implements PacketReceiver.
|
||||
void DeliverRtpPacket(
|
||||
MediaType media_type,
|
||||
RtpPacketReceived packet,
|
||||
OnUndemuxablePacketHandler undemuxable_packet_handler) override;
|
||||
void DeliverRtcpPacket(rtc::CopyOnWriteBuffer packet) override;
|
||||
|
||||
private:
|
||||
class FakeNetworkPipeOnTaskQueue {
|
||||
public:
|
||||
FakeNetworkPipeOnTaskQueue(
|
||||
TaskQueueBase* task_queue,
|
||||
rtc::scoped_refptr<PendingTaskSafetyFlag> call_alive,
|
||||
Clock* clock,
|
||||
std::unique_ptr<NetworkBehaviorInterface> network_behavior);
|
||||
|
||||
void SendRtp(rtc::ArrayView<const uint8_t> packet,
|
||||
const PacketOptions& options,
|
||||
Transport* transport);
|
||||
void SendRtcp(rtc::ArrayView<const uint8_t> packet, Transport* transport);
|
||||
|
||||
void AddActiveTransport(Transport* transport);
|
||||
void RemoveActiveTransport(Transport* transport);
|
||||
|
||||
private:
|
||||
// Try to process packets on the fake network queue.
|
||||
// Returns true if call resulted in a delayed process, false if queue empty.
|
||||
bool Process();
|
||||
|
||||
Clock* const clock_;
|
||||
TaskQueueBase* const task_queue_;
|
||||
rtc::scoped_refptr<PendingTaskSafetyFlag> call_alive_;
|
||||
FakeNetworkPipe pipe_;
|
||||
absl::optional<int64_t> next_process_ms_ RTC_GUARDED_BY(&task_queue_);
|
||||
};
|
||||
|
||||
// For audio/video send stream, a TransportAdapter instance is used to
|
||||
// intercept packets to be sent, and put them into a common FakeNetworkPipe
|
||||
// in such as way that they will eventually (unless dropped) be forwarded to
|
||||
// the correct Transport for that stream.
|
||||
class FakeNetworkPipeTransportAdapter : public Transport {
|
||||
public:
|
||||
FakeNetworkPipeTransportAdapter(FakeNetworkPipeOnTaskQueue* fake_network,
|
||||
Call* call,
|
||||
Clock* clock,
|
||||
Transport* real_transport);
|
||||
~FakeNetworkPipeTransportAdapter();
|
||||
|
||||
bool SendRtp(rtc::ArrayView<const uint8_t> packet,
|
||||
const PacketOptions& options) override;
|
||||
bool SendRtcp(rtc::ArrayView<const uint8_t> packet) override;
|
||||
|
||||
private:
|
||||
FakeNetworkPipeOnTaskQueue* const network_pipe_;
|
||||
Call* const call_;
|
||||
Clock* const clock_;
|
||||
Transport* const real_transport_;
|
||||
};
|
||||
|
||||
void SetClientBitratePreferences(
|
||||
const webrtc::BitrateSettings& preferences) override;
|
||||
void UpdateSendNetworkConfig();
|
||||
void UpdateReceiveNetworkConfig();
|
||||
|
||||
Clock* const clock_;
|
||||
const std::unique_ptr<Call> call_;
|
||||
// For cancelling tasks on the network thread when DegradedCall is destroyed
|
||||
rtc::scoped_refptr<PendingTaskSafetyFlag> call_alive_;
|
||||
size_t send_config_index_;
|
||||
const std::vector<TimeScopedNetworkConfig> send_configs_;
|
||||
SimulatedNetwork* send_simulated_network_;
|
||||
std::unique_ptr<FakeNetworkPipeOnTaskQueue> send_pipe_;
|
||||
std::map<AudioSendStream*, std::unique_ptr<FakeNetworkPipeTransportAdapter>>
|
||||
audio_send_transport_adapters_;
|
||||
std::map<VideoSendStream*, std::unique_ptr<FakeNetworkPipeTransportAdapter>>
|
||||
video_send_transport_adapters_;
|
||||
|
||||
size_t receive_config_index_;
|
||||
const std::vector<TimeScopedNetworkConfig> receive_configs_;
|
||||
SimulatedNetwork* receive_simulated_network_;
|
||||
SequenceChecker received_packet_sequence_checker_;
|
||||
std::unique_ptr<FakeNetworkPipe> receive_pipe_
|
||||
RTC_GUARDED_BY(received_packet_sequence_checker_);
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // CALL_DEGRADED_CALL_H_
|
||||
@ -41,20 +41,6 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
namespace {
|
||||
static const int kDefaultTimeoutMs = 5000;
|
||||
|
||||
bool AddIceCandidates(PeerConnectionWrapper* peer,
|
||||
std::vector<const IceCandidateInterface*> candidates) {
|
||||
for (const auto candidate : candidates) {
|
||||
if (!peer->pc()->AddIceCandidate(candidate)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
|
||||
|
||||
class PeerConnectionFieldTrialTest : public ::testing::Test {
|
||||
@ -220,59 +206,4 @@ TEST_F(PeerConnectionFieldTrialTest, MAYBE_InjectDependencyDescriptor) {
|
||||
EXPECT_TRUE(found2);
|
||||
}
|
||||
|
||||
// Test that the ability to emulate degraded networks works without crashing.
|
||||
TEST_F(PeerConnectionFieldTrialTest, ApplyFakeNetworkConfig) {
|
||||
std::unique_ptr<test::ScopedKeyValueConfig> field_trials =
|
||||
std::make_unique<test::ScopedKeyValueConfig>(
|
||||
"WebRTC-FakeNetworkSendConfig/link_capacity_kbps:500/"
|
||||
"WebRTC-FakeNetworkReceiveConfig/loss_percent:1/");
|
||||
|
||||
CreatePCFactory(std::move(field_trials));
|
||||
|
||||
WrapperPtr caller = CreatePeerConnection();
|
||||
BitrateSettings bitrate_settings;
|
||||
bitrate_settings.start_bitrate_bps = 1'000'000;
|
||||
bitrate_settings.max_bitrate_bps = 1'000'000;
|
||||
caller->pc()->SetBitrate(bitrate_settings);
|
||||
FrameGeneratorCapturerVideoTrackSource::Config config;
|
||||
auto video_track_source =
|
||||
rtc::make_ref_counted<FrameGeneratorCapturerVideoTrackSource>(
|
||||
config, clock_, /*is_screencast=*/false);
|
||||
video_track_source->Start();
|
||||
caller->AddTrack(pc_factory_->CreateVideoTrack(video_track_source, "v"));
|
||||
WrapperPtr callee = CreatePeerConnection();
|
||||
|
||||
ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
|
||||
ASSERT_TRUE(
|
||||
caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal()));
|
||||
|
||||
// Do the SDP negotiation, and also exchange ice candidates.
|
||||
ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get()));
|
||||
ASSERT_TRUE_WAIT(
|
||||
caller->signaling_state() == PeerConnectionInterface::kStable,
|
||||
kDefaultTimeoutMs);
|
||||
ASSERT_TRUE_WAIT(caller->IsIceGatheringDone(), kDefaultTimeoutMs);
|
||||
ASSERT_TRUE_WAIT(callee->IsIceGatheringDone(), kDefaultTimeoutMs);
|
||||
|
||||
// Connect an ICE candidate pairs.
|
||||
ASSERT_TRUE(
|
||||
AddIceCandidates(callee.get(), caller->observer()->GetAllCandidates()));
|
||||
ASSERT_TRUE(
|
||||
AddIceCandidates(caller.get(), callee->observer()->GetAllCandidates()));
|
||||
|
||||
// This means that ICE and DTLS are connected.
|
||||
ASSERT_TRUE_WAIT(callee->IsIceConnected(), kDefaultTimeoutMs);
|
||||
ASSERT_TRUE_WAIT(caller->IsIceConnected(), kDefaultTimeoutMs);
|
||||
|
||||
// Send packets for kDefaultTimeoutMs
|
||||
WAIT(false, kDefaultTimeoutMs);
|
||||
|
||||
std::vector<const RTCOutboundRtpStreamStats*> outbound_rtp_stats =
|
||||
caller->GetStats()->GetStatsOfType<RTCOutboundRtpStreamStats>();
|
||||
ASSERT_GE(outbound_rtp_stats.size(), 1u);
|
||||
ASSERT_TRUE(outbound_rtp_stats[0]->target_bitrate.has_value());
|
||||
// Link capacity is limited to 500k, so BWE is expected to be close to 500k.
|
||||
ASSERT_LE(*outbound_rtp_stats[0]->target_bitrate, 500'000 * 1.1);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user