Move BitrateAllocator from BitrateController logic to Call.

This is a step on the way to have variable bitrate for audio and is
intended to be as much of a no-op as possible.

BUG=webrtc:5079

Review URL: https://codereview.webrtc.org/1441673002

Cr-Commit-Position: refs/heads/master@{#10630}
This commit is contained in:
mflodman 2015-11-12 21:02:42 -08:00 committed by Commit bot
parent 69191ed845
commit 0e7e259ebd
18 changed files with 89 additions and 61 deletions

View File

@ -10,6 +10,7 @@ import("../build/webrtc.gni")
source_set("call") {
sources = [
"bitrate_allocator.cc",
"call.cc",
"congestion_controller.cc",
"transport_adapter.cc",

View File

@ -9,7 +9,7 @@
*
*/
#include "webrtc/modules/bitrate_controller/include/bitrate_allocator.h"
#include "webrtc/call/bitrate_allocator.h"
#include <algorithm>
#include <utility>
@ -136,7 +136,8 @@ void BitrateAllocator::EnforceMinBitrate(bool enforce_min_bitrate) {
BitrateAllocator::ObserverBitrateMap BitrateAllocator::NormalRateAllocation(
uint32_t bitrate,
uint32_t sum_min_bitrates) {
uint32_t number_of_observers = bitrate_observers_.size();
uint32_t number_of_observers =
static_cast<uint32_t>(bitrate_observers_.size());
uint32_t bitrate_per_observer =
(bitrate - sum_min_bitrates) / number_of_observers;
// Use map to sort list based on max bitrate.

View File

@ -12,8 +12,8 @@
* and push the result to the encoders via BitrateObserver(s).
*/
#ifndef WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_ALLOCATOR_H_
#define WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_ALLOCATOR_H_
#ifndef WEBRTC_CALL_BITRATE_ALLOCATOR_H_
#define WEBRTC_CALL_BITRATE_ALLOCATOR_H_
#include <list>
#include <map>
@ -99,4 +99,4 @@ class BitrateAllocator {
int64_t last_rtt_ GUARDED_BY(crit_sect_);
};
} // namespace webrtc
#endif // WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_ALLOCATOR_H_
#endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_

View File

@ -12,7 +12,7 @@
#include <vector>
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/modules/bitrate_controller/include/bitrate_allocator.h"
#include "webrtc/call/bitrate_allocator.h"
#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
namespace webrtc {
@ -53,7 +53,7 @@ TEST_F(BitrateAllocatorTest, UpdatingBitrateObserver) {
EXPECT_EQ(200000u, bitrate_observer.last_bitrate_);
// TODO(pbos): Expect capping to 1.5M instead of 3M when not boosting the max
// bitrate for FEC/retransmissions (see TODO in BitrateAllocator).
// bitrate for FEC/retransmissions (see todo in BitrateAllocator).
allocator_->OnNetworkChanged(4000000, 0, 0);
EXPECT_EQ(3000000u, bitrate_observer.last_bitrate_);
start_bitrate =

View File

@ -23,10 +23,13 @@
#include "webrtc/base/thread_checker.h"
#include "webrtc/base/trace_event.h"
#include "webrtc/call.h"
#include "webrtc/call/bitrate_allocator.h"
#include "webrtc/call/congestion_controller.h"
#include "webrtc/call/rtc_event_log.h"
#include "webrtc/common.h"
#include "webrtc/config.h"
#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
#include "webrtc/modules/pacing/include/paced_sender.h"
#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/modules/utility/include/process_thread.h"
@ -47,7 +50,8 @@ const int Call::Config::kDefaultStartBitrateBps = 300000;
namespace internal {
class Call : public webrtc::Call, public PacketReceiver {
class Call : public webrtc::Call, public PacketReceiver,
public BitrateObserver {
public:
explicit Call(const Call::Config& config);
virtual ~Call();
@ -86,6 +90,10 @@ class Call : public webrtc::Call, public PacketReceiver {
void OnSentPacket(const rtc::SentPacket& sent_packet) override;
// Implements BitrateObserver.
void OnNetworkChanged(uint32_t bitrate_bps, uint8_t fraction_loss,
int64_t rtt_ms) override;
private:
DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet,
size_t length);
@ -113,7 +121,7 @@ class Call : public webrtc::Call, public PacketReceiver {
const int num_cpu_cores_;
const rtc::scoped_ptr<ProcessThread> module_process_thread_;
const rtc::scoped_ptr<CallStats> call_stats_;
const rtc::scoped_ptr<CongestionController> congestion_controller_;
const rtc::scoped_ptr<BitrateAllocator> bitrate_allocator_;
Call::Config config_;
rtc::ThreadChecker configuration_thread_checker_;
@ -148,6 +156,8 @@ class Call : public webrtc::Call, public PacketReceiver {
rtc::RateTracker received_rtcp_bytes_per_sec_;
int64_t first_rtp_packet_received_ms_;
const rtc::scoped_ptr<CongestionController> congestion_controller_;
RTC_DISALLOW_COPY_AND_ASSIGN(Call);
};
} // namespace internal
@ -163,9 +173,7 @@ Call::Call(const Call::Config& config)
num_cpu_cores_(CpuInfo::DetectNumberOfCores()),
module_process_thread_(ProcessThread::Create("ModuleProcessThread")),
call_stats_(new CallStats()),
congestion_controller_(
new CongestionController(module_process_thread_.get(),
call_stats_.get())),
bitrate_allocator_(new BitrateAllocator()),
config_(config),
network_enabled_(true),
receive_crit_(RWLockWrapper::CreateRWLock()),
@ -173,7 +181,9 @@ Call::Call(const Call::Config& config)
received_video_bytes_per_sec_(1000, 1),
received_audio_bytes_per_sec_(1000, 1),
received_rtcp_bytes_per_sec_(1000, 1),
first_rtp_packet_received_ms_(-1) {
first_rtp_packet_received_ms_(-1),
congestion_controller_(new CongestionController(
module_process_thread_.get(), call_stats_.get(), this)) {
RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0);
RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps,
@ -335,8 +345,8 @@ webrtc::VideoSendStream* Call::CreateVideoSendStream(
// the call has already started.
VideoSendStream* send_stream = new VideoSendStream(
num_cpu_cores_, module_process_thread_.get(), call_stats_.get(),
congestion_controller_.get(), config, encoder_config,
suspended_video_send_ssrcs_);
congestion_controller_.get(), bitrate_allocator_.get(), config,
encoder_config, suspended_video_send_ssrcs_);
if (!network_enabled_)
send_stream->SignalNetworkState(kNetworkDown);
@ -522,6 +532,32 @@ void Call::OnSentPacket(const rtc::SentPacket& sent_packet) {
congestion_controller_->OnSentPacket(sent_packet);
}
void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss,
int64_t rtt_ms) {
uint32_t allocated_bitrate_bps = bitrate_allocator_->OnNetworkChanged(
target_bitrate_bps, fraction_loss, rtt_ms);
int pad_up_to_bitrate_bps = 0;
{
ReadLockScoped read_lock(*send_crit_);
// No need to update as long as we're not sending.
if (video_send_streams_.empty())
return;
for (VideoSendStream* stream : video_send_streams_)
pad_up_to_bitrate_bps += stream->GetPaddingNeededBps();
}
// Allocated bitrate might be higher than bitrate estimate if enforcing min
// bitrate, or lower if estimate is higher than the sum of max bitrates, so
// set the pacer bitrate to the maximum of the two.
uint32_t pacer_bitrate_bps =
std::max(target_bitrate_bps, allocated_bitrate_bps);
congestion_controller_->UpdatePacerBitrate(
target_bitrate_bps / 1000,
PacedSender::kDefaultPaceMultiplier * pacer_bitrate_bps / 1000,
pad_up_to_bitrate_bps / 1000);
}
void Call::ConfigureSync(const std::string& sync_group) {
// Set sync only if there was no previous one.
if (voice_engine() == nullptr || sync_group.empty())

View File

@ -13,6 +13,7 @@
#include "webrtc/base/checks.h"
#include "webrtc/base/thread_annotations.h"
#include "webrtc/common.h"
#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
#include "webrtc/modules/pacing/include/paced_sender.h"
#include "webrtc/modules/pacing/include/packet_router.h"
#include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h"
@ -144,9 +145,9 @@ class WrappingBitrateEstimator : public RemoteBitrateEstimator {
} // namespace
CongestionController::CongestionController(ProcessThread* process_thread,
CallStats* call_stats)
CallStats* call_stats,
BitrateObserver* bitrate_observer)
: remb_(new VieRemb()),
bitrate_allocator_(new BitrateAllocator()),
packet_router_(new PacketRouter()),
pacer_(new PacedSender(Clock::GetRealTimeClock(),
packet_router_.get(),
@ -166,7 +167,7 @@ CongestionController::CongestionController(ProcessThread* process_thread,
// construction.
bitrate_controller_(
BitrateController::CreateBitrateController(Clock::GetRealTimeClock(),
this)),
bitrate_observer)),
min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) {
call_stats_->RegisterStatsObserver(remote_bitrate_estimator_.get());
@ -249,6 +250,12 @@ CongestionController::GetTransportFeedbackObserver() {
return transport_feedback_adapter_.get();
}
void CongestionController::UpdatePacerBitrate(int bitrate_kbps,
int max_bitrate_kbps,
int min_bitrate_kbps) {
pacer_->UpdateBitrate(bitrate_kbps, max_bitrate_kbps, min_bitrate_kbps);
}
int64_t CongestionController::GetPacerQueuingDelayMs() const {
return pacer_->QueueInMs();
}
@ -278,29 +285,6 @@ void CongestionController::SignalNetworkState(NetworkState state) {
}
}
// TODO(mflodman): Move this logic out from CongestionController.
void CongestionController::OnNetworkChanged(uint32_t target_bitrate_bps,
uint8_t fraction_loss,
int64_t rtt) {
uint32_t allocated_bitrate_bps = bitrate_allocator_->OnNetworkChanged(
target_bitrate_bps, fraction_loss, rtt);
int pad_up_to_bitrate_bps = 0;
{
rtc::CritScope lock(&encoder_crit_);
for (const auto& encoder : encoders_)
pad_up_to_bitrate_bps += encoder->GetPaddingNeededBps();
}
// Allocated bitrate might be higher than bitrate estimate if enforcing min
// bitrate, or lower if estimate is higher than the sum of max bitrates, so
// set the pacer bitrate to the maximum of the two.
uint32_t pacer_bitrate_bps =
std::max(target_bitrate_bps, allocated_bitrate_bps);
pacer_->UpdateBitrate(
pacer_bitrate_bps / 1000,
PacedSender::kDefaultPaceMultiplier * pacer_bitrate_bps / 1000,
pad_up_to_bitrate_bps / 1000);
}
void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) {
if (transport_feedback_adapter_) {
transport_feedback_adapter_->OnSentPacket(sent_packet.packet_id,

View File

@ -16,12 +16,12 @@
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/base/socket.h"
#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
#include "webrtc/stream.h"
namespace webrtc {
class BitrateAllocator;
class BitrateController;
class BitrateObserver;
class CallStats;
class Config;
class PacedSender;
@ -32,12 +32,14 @@ class RemoteEstimatorProxy;
class RtpRtcp;
class SendStatisticsProxy;
class TransportFeedbackAdapter;
class TransportFeedbackObserver;
class ViEEncoder;
class VieRemb;
class CongestionController : public BitrateObserver {
class CongestionController {
public:
CongestionController(ProcessThread* process_thread, CallStats* call_stats);
CongestionController(ProcessThread* process_thread, CallStats* call_stats,
BitrateObserver* bitrate_observer);
~CongestionController();
void AddEncoder(ViEEncoder* encoder);
void RemoveEncoder(ViEEncoder* encoder);
@ -54,21 +56,15 @@ class CongestionController : public BitrateObserver {
int64_t GetPacerQueuingDelayMs() const;
PacedSender* pacer() const { return pacer_.get(); }
PacketRouter* packet_router() const { return packet_router_.get(); }
BitrateAllocator* bitrate_allocator() const {
return bitrate_allocator_.get(); }
TransportFeedbackObserver* GetTransportFeedbackObserver();
// Implements BitrateObserver.
void OnNetworkChanged(uint32_t target_bitrate_bps,
uint8_t fraction_loss,
int64_t rtt) override;
void UpdatePacerBitrate(int bitrate_kbps, int max_bitrate_kbps,
int min_bitrate_kbps);
void OnSentPacket(const rtc::SentPacket& sent_packet);
private:
rtc::scoped_ptr<VieRemb> remb_;
// TODO(mflodman): Move bitrate_allocator_ to Call.
rtc::scoped_ptr<BitrateAllocator> bitrate_allocator_;
rtc::scoped_ptr<PacketRouter> packet_router_;
rtc::scoped_ptr<PacedSender> pacer_;
rtc::scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;

View File

@ -14,6 +14,7 @@
'<(webrtc_root)/webrtc.gyp:rtc_event_log',
],
'webrtc_call_sources': [
'call/bitrate_allocator.cc',
'call/call.cc',
'call/congestion_controller.cc',
'call/transport_adapter.cc',

View File

@ -10,7 +10,6 @@ import("../../build/webrtc.gni")
source_set("bitrate_controller") {
sources = [
"bitrate_allocator.cc",
"bitrate_controller_impl.cc",
"bitrate_controller_impl.h",
"include/bitrate_allocator.h",

View File

@ -15,11 +15,9 @@
'<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers',
],
'sources': [
'bitrate_allocator.cc',
'bitrate_controller_impl.cc',
'bitrate_controller_impl.h',
'include/bitrate_controller.h',
'include/bitrate_allocator.h',
'send_side_bandwidth_estimation.cc',
'send_side_bandwidth_estimation.h',
],

View File

@ -196,7 +196,6 @@
'audio_processing/vad/vad_audio_proc_unittest.cc',
'audio_processing/vad/vad_circular_buffer_unittest.cc',
'audio_processing/vad/voice_activity_detector_unittest.cc',
'bitrate_controller/bitrate_allocator_unittest.cc',
'bitrate_controller/bitrate_controller_unittest.cc',
'bitrate_controller/send_side_bandwidth_estimation_unittest.cc',
'desktop_capture/desktop_and_cursor_composer_unittest.cc',

View File

@ -8,12 +8,13 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h"
#include <limits>
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
#include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h"
#include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
#include "webrtc/modules/utility/include/process_thread.h"

View File

@ -18,6 +18,7 @@
#include "webrtc/base/logging.h"
#include "webrtc/call/congestion_controller.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
#include "webrtc/system_wrappers/include/clock.h"
#include "webrtc/video/receive_statistics_proxy.h"
#include "webrtc/video_engine/call_stats.h"

View File

@ -20,6 +20,7 @@
#include "webrtc/base/trace_event.h"
#include "webrtc/call/congestion_controller.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
#include "webrtc/modules/pacing/include/packet_router.h"
#include "webrtc/video/video_capture_input.h"
#include "webrtc/video_engine/call_stats.h"
@ -31,7 +32,6 @@
namespace webrtc {
class BitrateAllocator;
class PacedSender;
class RtcpIntraFrameObserver;
class TransportFeedbackObserver;
@ -113,6 +113,7 @@ VideoSendStream::VideoSendStream(
ProcessThread* module_process_thread,
CallStats* call_stats,
CongestionController* congestion_controller,
BitrateAllocator* bitrate_allocator,
const VideoSendStream::Config& config,
const VideoEncoderConfig& encoder_config,
const std::map<uint32_t, RtpState>& suspended_ssrcs)
@ -144,7 +145,7 @@ VideoSendStream::VideoSendStream(
vie_encoder_.reset(new ViEEncoder(
num_cpu_cores, module_process_thread_, &stats_proxy_,
config.pre_encode_callback, congestion_controller_->pacer(),
congestion_controller_->bitrate_allocator()));
bitrate_allocator));
RTC_CHECK(vie_encoder_->Init());
vie_channel_.reset(new ViEChannel(
@ -532,6 +533,10 @@ int64_t VideoSendStream::GetRtt() const {
return -1;
}
int VideoSendStream::GetPaddingNeededBps() const {
return vie_encoder_->GetPaddingNeededBps();
}
bool VideoSendStream::SetSendCodec(VideoCodec video_codec) {
static const int kEncoderMinBitrate = 30;
if (video_codec.maxBitrate == 0) {

View File

@ -27,6 +27,7 @@
namespace webrtc {
class BitrateAllocator;
class CallStats;
class CongestionController;
class EncoderStateFeedback;
@ -43,6 +44,7 @@ class VideoSendStream : public webrtc::VideoSendStream,
ProcessThread* module_process_thread,
CallStats* call_stats,
CongestionController* congestion_controller,
BitrateAllocator* bitrate_allocator,
const VideoSendStream::Config& config,
const VideoEncoderConfig& encoder_config,
const std::map<uint32_t, RtpState>& suspended_ssrcs);
@ -68,6 +70,7 @@ class VideoSendStream : public webrtc::VideoSendStream,
RtpStateMap GetRtpStates() const;
int64_t GetRtt() const;
int GetPaddingNeededBps() const;
private:
bool SetSendCodec(VideoCodec video_codec);

View File

@ -17,6 +17,7 @@
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/trace_event.h"
#include "webrtc/call/bitrate_allocator.h"
#include "webrtc/common_video/interface/video_image.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/frame_callback.h"

View File

@ -19,7 +19,6 @@
#include "webrtc/base/thread_annotations.h"
#include "webrtc/common_types.h"
#include "webrtc/frame_callback.h"
#include "webrtc/modules/bitrate_controller/include/bitrate_allocator.h"
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "webrtc/modules/video_coding/main/interface/video_coding_defines.h"
#include "webrtc/modules/video_processing/main/interface/video_processing.h"
@ -28,6 +27,8 @@
namespace webrtc {
class BitrateAllocator;
class BitrateObserver;
class Config;
class CriticalSectionWrapper;
class EncodedImageCallback;

View File

@ -154,6 +154,7 @@
'audio/audio_receive_stream_unittest.cc',
'audio/audio_send_stream_unittest.cc',
'audio/audio_state_unittest.cc',
'call/bitrate_allocator_unittest.cc',
'call/bitrate_estimator_tests.cc',
'call/call_unittest.cc',
'call/packet_injection_tests.cc',