Move BitrateAllocation to api/ and rename it VideoBitrateAllocation
Since the webrtc_common build target does not have visibility set, we cannot easily use BitrateAllocation in other parts of Chromium. This is currently blocking parts of chromium:794608, and I know of other usage outside webrtc already, so moving it to api/ should be warranted. Also, since there's some naming confusion and this class is video specific rename it VideoBitrateAllocation. This also fits with the standard interface for producing these: VideoBitrateAllocator. Bug: chromium:794608 Change-Id: I4c0fae40f9365e860c605a76a4f67ecc9b9cf9fe Reviewed-on: https://webrtc-review.googlesource.com/70783 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Commit-Queue: Erik Språng <sprang@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22986}
This commit is contained in:
@ -288,7 +288,7 @@ int32_t H264EncoderImpl::RegisterEncodeCompleteCallback(
|
||||
}
|
||||
|
||||
int32_t H264EncoderImpl::SetRateAllocation(
|
||||
const BitrateAllocation& bitrate_allocation,
|
||||
const VideoBitrateAllocation& bitrate_allocation,
|
||||
uint32_t framerate) {
|
||||
if (bitrate_allocation.get_sum_bps() <= 0 || framerate <= 0)
|
||||
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
||||
|
||||
@ -44,7 +44,7 @@ class H264EncoderImpl : public H264Encoder {
|
||||
|
||||
int32_t RegisterEncodeCompleteCallback(
|
||||
EncodedImageCallback* callback) override;
|
||||
int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation,
|
||||
int32_t SetRateAllocation(const VideoBitrateAllocation& bitrate_allocation,
|
||||
uint32_t framerate) override;
|
||||
|
||||
// The result of encoding - an EncodedImage and RTPFragmentationHeader - are
|
||||
|
||||
@ -46,7 +46,7 @@ class MultiplexEncoderAdapter : public VideoEncoder {
|
||||
const std::vector<FrameType>* frame_types) override;
|
||||
int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override;
|
||||
int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
|
||||
int SetRateAllocation(const BitrateAllocation& bitrate,
|
||||
int SetRateAllocation(const VideoBitrateAllocation& bitrate,
|
||||
uint32_t new_framerate) override;
|
||||
int Release() override;
|
||||
const char* ImplementationName() const override;
|
||||
|
||||
@ -174,8 +174,9 @@ int MultiplexEncoderAdapter::SetChannelParameters(uint32_t packet_loss,
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
int MultiplexEncoderAdapter::SetRateAllocation(const BitrateAllocation& bitrate,
|
||||
uint32_t framerate) {
|
||||
int MultiplexEncoderAdapter::SetRateAllocation(
|
||||
const VideoBitrateAllocation& bitrate,
|
||||
uint32_t framerate) {
|
||||
for (auto& encoder : encoders_) {
|
||||
// TODO(emircan): |framerate| is used to calculate duration in encoder
|
||||
// instances. We report the total frame rate to keep real time for now.
|
||||
|
||||
@ -188,7 +188,7 @@ class VideoProcessor {
|
||||
webrtc::VideoEncoder* const encoder_;
|
||||
VideoDecoderList* const decoders_;
|
||||
const std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_;
|
||||
BitrateAllocation bitrate_allocation_ RTC_GUARDED_BY(sequence_checker_);
|
||||
VideoBitrateAllocation bitrate_allocation_ RTC_GUARDED_BY(sequence_checker_);
|
||||
uint32_t framerate_fps_ RTC_GUARDED_BY(sequence_checker_);
|
||||
|
||||
// Adapters for the codec callbacks.
|
||||
|
||||
@ -166,7 +166,7 @@ TEST_F(VideoProcessorTest, SetRates) {
|
||||
const int kFramerateFps = 17;
|
||||
EXPECT_CALL(encoder_mock_,
|
||||
SetRateAllocation(
|
||||
Property(&BitrateAllocation::get_sum_kbps, kBitrateKbps),
|
||||
Property(&VideoBitrateAllocation::get_sum_kbps, kBitrateKbps),
|
||||
kFramerateFps))
|
||||
.Times(1);
|
||||
DO_SYNC(q_, { video_processor_->SetRates(kBitrateKbps, kFramerateFps); });
|
||||
@ -174,9 +174,9 @@ TEST_F(VideoProcessorTest, SetRates) {
|
||||
const int kNewBitrateKbps = 456;
|
||||
const int kNewFramerateFps = 34;
|
||||
EXPECT_CALL(encoder_mock_,
|
||||
SetRateAllocation(
|
||||
Property(&BitrateAllocation::get_sum_kbps, kNewBitrateKbps),
|
||||
kNewFramerateFps))
|
||||
SetRateAllocation(Property(&VideoBitrateAllocation::get_sum_kbps,
|
||||
kNewBitrateKbps),
|
||||
kNewFramerateFps))
|
||||
.Times(1);
|
||||
DO_SYNC(q_,
|
||||
{ video_processor_->SetRates(kNewBitrateKbps, kNewFramerateFps); });
|
||||
|
||||
@ -252,7 +252,7 @@ int LibvpxVp8Encoder::Release() {
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
int LibvpxVp8Encoder::SetRateAllocation(const BitrateAllocation& bitrate,
|
||||
int LibvpxVp8Encoder::SetRateAllocation(const VideoBitrateAllocation& bitrate,
|
||||
uint32_t new_framerate) {
|
||||
if (!inited_)
|
||||
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
|
||||
@ -512,7 +512,7 @@ int LibvpxVp8Encoder::InitEncode(const VideoCodec* inst,
|
||||
// at position 0 and they have highest resolution at position 0.
|
||||
int stream_idx = encoders_.size() - 1;
|
||||
SimulcastRateAllocator init_allocator(codec_);
|
||||
BitrateAllocation allocation = init_allocator.GetAllocation(
|
||||
VideoBitrateAllocation allocation = init_allocator.GetAllocation(
|
||||
inst->startBitrate * 1000, inst->maxFramerate);
|
||||
std::vector<uint32_t> stream_bitrates;
|
||||
for (int i = 0; i == 0 || i < inst->numberOfSimulcastStreams; ++i) {
|
||||
|
||||
@ -46,7 +46,7 @@ class LibvpxVp8Encoder : public VP8Encoder {
|
||||
|
||||
int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
|
||||
|
||||
int SetRateAllocation(const BitrateAllocation& bitrate,
|
||||
int SetRateAllocation(const VideoBitrateAllocation& bitrate,
|
||||
uint32_t new_framerate) override;
|
||||
|
||||
ScalingSettings GetScalingSettings() const override;
|
||||
|
||||
@ -23,10 +23,10 @@ namespace webrtc {
|
||||
SimulcastRateAllocator::SimulcastRateAllocator(const VideoCodec& codec)
|
||||
: codec_(codec) {}
|
||||
|
||||
BitrateAllocation SimulcastRateAllocator::GetAllocation(
|
||||
VideoBitrateAllocation SimulcastRateAllocator::GetAllocation(
|
||||
uint32_t total_bitrate_bps,
|
||||
uint32_t framerate) {
|
||||
BitrateAllocation allocated_bitrates_bps;
|
||||
VideoBitrateAllocation allocated_bitrates_bps;
|
||||
DistributeAllocationToSimulcastLayers(total_bitrate_bps,
|
||||
&allocated_bitrates_bps);
|
||||
DistributeAllocationToTemporalLayers(framerate, &allocated_bitrates_bps);
|
||||
@ -35,7 +35,7 @@ BitrateAllocation SimulcastRateAllocator::GetAllocation(
|
||||
|
||||
void SimulcastRateAllocator::DistributeAllocationToSimulcastLayers(
|
||||
uint32_t total_bitrate_bps,
|
||||
BitrateAllocation* allocated_bitrates_bps) const {
|
||||
VideoBitrateAllocation* allocated_bitrates_bps) const {
|
||||
uint32_t left_to_allocate = total_bitrate_bps;
|
||||
if (codec_.maxBitrate && codec_.maxBitrate * 1000 < left_to_allocate)
|
||||
left_to_allocate = codec_.maxBitrate * 1000;
|
||||
@ -111,7 +111,7 @@ void SimulcastRateAllocator::DistributeAllocationToSimulcastLayers(
|
||||
|
||||
void SimulcastRateAllocator::DistributeAllocationToTemporalLayers(
|
||||
uint32_t framerate,
|
||||
BitrateAllocation* allocated_bitrates_bps) const {
|
||||
VideoBitrateAllocation* allocated_bitrates_bps) const {
|
||||
const int num_spatial_streams =
|
||||
std::max(1, static_cast<int>(codec_.numberOfSimulcastStreams));
|
||||
|
||||
|
||||
@ -28,18 +28,18 @@ class SimulcastRateAllocator : public VideoBitrateAllocator {
|
||||
public:
|
||||
explicit SimulcastRateAllocator(const VideoCodec& codec);
|
||||
|
||||
BitrateAllocation GetAllocation(uint32_t total_bitrate_bps,
|
||||
uint32_t framerate) override;
|
||||
VideoBitrateAllocation GetAllocation(uint32_t total_bitrate_bps,
|
||||
uint32_t framerate) override;
|
||||
uint32_t GetPreferredBitrateBps(uint32_t framerate) override;
|
||||
const VideoCodec& GetCodec() const;
|
||||
|
||||
private:
|
||||
void DistributeAllocationToSimulcastLayers(
|
||||
uint32_t total_bitrate_bps,
|
||||
BitrateAllocation* allocated_bitrates_bps) const;
|
||||
VideoBitrateAllocation* allocated_bitrates_bps) const;
|
||||
void DistributeAllocationToTemporalLayers(
|
||||
uint32_t framerate,
|
||||
BitrateAllocation* allocated_bitrates_bps) const;
|
||||
VideoBitrateAllocation* allocated_bitrates_bps) const;
|
||||
std::vector<uint32_t> DefaultTemporalLayerAllocation(int bitrate_kbps,
|
||||
int max_bitrate_kbps,
|
||||
int framerate,
|
||||
|
||||
@ -85,7 +85,7 @@ TEST_F(TestVp8Impl, SetRateAllocation) {
|
||||
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release());
|
||||
|
||||
const int kBitrateBps = 300000;
|
||||
BitrateAllocation bitrate_allocation;
|
||||
VideoBitrateAllocation bitrate_allocation;
|
||||
bitrate_allocation.SetBitrate(0, 0, kBitrateBps);
|
||||
EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED,
|
||||
encoder_->SetRateAllocation(bitrate_allocation,
|
||||
|
||||
@ -27,9 +27,10 @@ SvcRateAllocator::SvcRateAllocator(const VideoCodec& codec) : codec_(codec) {
|
||||
RTC_DCHECK_EQ(codec.codecType, kVideoCodecVP9);
|
||||
}
|
||||
|
||||
BitrateAllocation SvcRateAllocator::GetAllocation(uint32_t total_bitrate_bps,
|
||||
uint32_t framerate_fps) {
|
||||
BitrateAllocation bitrate_allocation;
|
||||
VideoBitrateAllocation SvcRateAllocator::GetAllocation(
|
||||
uint32_t total_bitrate_bps,
|
||||
uint32_t framerate_fps) {
|
||||
VideoBitrateAllocation bitrate_allocation;
|
||||
|
||||
size_t num_spatial_layers = codec_.VP9().numberOfSpatialLayers;
|
||||
RTC_CHECK(num_spatial_layers > 0);
|
||||
|
||||
@ -23,8 +23,8 @@ class SvcRateAllocator : public VideoBitrateAllocator {
|
||||
public:
|
||||
explicit SvcRateAllocator(const VideoCodec& codec);
|
||||
|
||||
BitrateAllocation GetAllocation(uint32_t total_bitrate_bps,
|
||||
uint32_t framerate_fps) override;
|
||||
VideoBitrateAllocation GetAllocation(uint32_t total_bitrate_bps,
|
||||
uint32_t framerate_fps) override;
|
||||
uint32_t GetPreferredBitrateBps(uint32_t framerate_fps) override;
|
||||
|
||||
private:
|
||||
|
||||
@ -46,7 +46,7 @@ TEST(SvcRateAllocatorTest, SingleLayerFor320x180Input) {
|
||||
VideoCodec codec = Configure(320, 180, 3, 3);
|
||||
SvcRateAllocator allocator = SvcRateAllocator(codec);
|
||||
|
||||
BitrateAllocation allocation = allocator.GetAllocation(1000 * 1000, 30);
|
||||
VideoBitrateAllocation allocation = allocator.GetAllocation(1000 * 1000, 30);
|
||||
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u);
|
||||
EXPECT_EQ(allocation.GetSpatialLayerSum(1), 0u);
|
||||
@ -56,7 +56,7 @@ TEST(SvcRateAllocatorTest, TwoLayersFor640x360Input) {
|
||||
VideoCodec codec = Configure(640, 360, 3, 3);
|
||||
SvcRateAllocator allocator = SvcRateAllocator(codec);
|
||||
|
||||
BitrateAllocation allocation = allocator.GetAllocation(1000 * 1000, 30);
|
||||
VideoBitrateAllocation allocation = allocator.GetAllocation(1000 * 1000, 30);
|
||||
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u);
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(1), 0u);
|
||||
@ -67,7 +67,7 @@ TEST(SvcRateAllocatorTest, ThreeLayersFor1280x720Input) {
|
||||
VideoCodec codec = Configure(1280, 720, 3, 3);
|
||||
SvcRateAllocator allocator = SvcRateAllocator(codec);
|
||||
|
||||
BitrateAllocation allocation = allocator.GetAllocation(1000 * 1000, 30);
|
||||
VideoBitrateAllocation allocation = allocator.GetAllocation(1000 * 1000, 30);
|
||||
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u);
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(1), 0u);
|
||||
@ -81,7 +81,7 @@ TEST(SvcRateAllocatorTest,
|
||||
|
||||
const SpatialLayer* layers = codec.spatialLayers;
|
||||
|
||||
BitrateAllocation allocation =
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator.GetAllocation(layers[0].minBitrate * 1000 / 2, 30);
|
||||
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u);
|
||||
@ -98,7 +98,7 @@ TEST(SvcRateAllocatorTest, Disable640x360Layer) {
|
||||
size_t min_bitrate_for_640x360_layer_kbps =
|
||||
layers[0].minBitrate + layers[1].minBitrate;
|
||||
|
||||
BitrateAllocation allocation = allocator.GetAllocation(
|
||||
VideoBitrateAllocation allocation = allocator.GetAllocation(
|
||||
min_bitrate_for_640x360_layer_kbps * 1000 - 1, 30);
|
||||
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u);
|
||||
@ -114,7 +114,7 @@ TEST(SvcRateAllocatorTest, Disable1280x720Layer) {
|
||||
size_t min_bitrate_for_1280x720_layer_kbps =
|
||||
layers[0].minBitrate + layers[1].minBitrate + layers[2].minBitrate;
|
||||
|
||||
BitrateAllocation allocation = allocator.GetAllocation(
|
||||
VideoBitrateAllocation allocation = allocator.GetAllocation(
|
||||
min_bitrate_for_1280x720_layer_kbps * 1000 - 1, 30);
|
||||
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u);
|
||||
@ -129,7 +129,7 @@ TEST(SvcRateAllocatorTest, BitrateIsCapped) {
|
||||
const SpatialLayer* layers = codec.spatialLayers;
|
||||
|
||||
const uint32_t link_mbps = 100;
|
||||
BitrateAllocation allocation =
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator.GetAllocation(link_mbps * 1000000, 30);
|
||||
|
||||
EXPECT_EQ(allocation.get_sum_kbps(),
|
||||
|
||||
@ -224,7 +224,7 @@ TEST_F(TestVp9Impl, EnableDisableSpatialLayers) {
|
||||
encoder_->InitEncode(&codec_settings_, 1 /* number of cores */,
|
||||
0 /* max payload size (unused) */));
|
||||
|
||||
BitrateAllocation bitrate_allocation;
|
||||
VideoBitrateAllocation bitrate_allocation;
|
||||
for (size_t sl_idx = 0; sl_idx < num_spatial_layers; ++sl_idx) {
|
||||
bitrate_allocation.SetBitrate(sl_idx, 0,
|
||||
layers[sl_idx].targetBitrate * 1000);
|
||||
@ -283,7 +283,7 @@ TEST_F(TestVp9Impl, EndOfSuperframe) {
|
||||
|
||||
// Encode both base and upper layers. Check that end-of-superframe flag is
|
||||
// set on upper layer frame but not on base layer frame.
|
||||
BitrateAllocation bitrate_allocation;
|
||||
VideoBitrateAllocation bitrate_allocation;
|
||||
bitrate_allocation.SetBitrate(0, 0, layers[0].targetBitrate * 1000);
|
||||
bitrate_allocation.SetBitrate(1, 0, layers[1].targetBitrate * 1000);
|
||||
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
|
||||
|
||||
@ -123,7 +123,8 @@ bool VP9EncoderImpl::ExplicitlyConfiguredSpatialLayers() const {
|
||||
return num_spatial_layers_ > 1 && codec_.spatialLayers[0].targetBitrate > 0;
|
||||
}
|
||||
|
||||
bool VP9EncoderImpl::SetSvcRates(const BitrateAllocation& bitrate_allocation) {
|
||||
bool VP9EncoderImpl::SetSvcRates(
|
||||
const VideoBitrateAllocation& bitrate_allocation) {
|
||||
uint8_t i = 0;
|
||||
|
||||
config_->rc_target_bitrate = bitrate_allocation.get_sum_kbps();
|
||||
@ -192,7 +193,7 @@ bool VP9EncoderImpl::SetSvcRates(const BitrateAllocation& bitrate_allocation) {
|
||||
}
|
||||
|
||||
int VP9EncoderImpl::SetRateAllocation(
|
||||
const BitrateAllocation& bitrate_allocation,
|
||||
const VideoBitrateAllocation& bitrate_allocation,
|
||||
uint32_t frame_rate) {
|
||||
if (!inited_) {
|
||||
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
|
||||
@ -434,7 +435,7 @@ int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) {
|
||||
}
|
||||
|
||||
SvcRateAllocator init_allocator(codec_);
|
||||
BitrateAllocation allocation = init_allocator.GetAllocation(
|
||||
VideoBitrateAllocation allocation = init_allocator.GetAllocation(
|
||||
inst->startBitrate * 1000, inst->maxFramerate);
|
||||
if (!SetSvcRates(allocation)) {
|
||||
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
||||
|
||||
@ -46,7 +46,7 @@ class VP9EncoderImpl : public VP9Encoder {
|
||||
|
||||
int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
|
||||
|
||||
int SetRateAllocation(const BitrateAllocation& bitrate_allocation,
|
||||
int SetRateAllocation(const VideoBitrateAllocation& bitrate_allocation,
|
||||
uint32_t frame_rate) override;
|
||||
|
||||
const char* ImplementationName() const override;
|
||||
@ -78,7 +78,7 @@ class VP9EncoderImpl : public VP9Encoder {
|
||||
bool first_frame_in_picture);
|
||||
|
||||
bool ExplicitlyConfiguredSpatialLayers() const;
|
||||
bool SetSvcRates(const BitrateAllocation& bitrate_allocation);
|
||||
bool SetSvcRates(const VideoBitrateAllocation& bitrate_allocation);
|
||||
|
||||
// Used for flexible mode to set the flags and buffer references used
|
||||
// by the encoder. Also calculates the references used by the RTP
|
||||
|
||||
Reference in New Issue
Block a user