Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Unified Diff: webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc

Issue 2288223002: Extract simulcast rate allocation outside of video encoder. (Closed)
Patch Set: Rebase, handle pause case in simulcast wrapper Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc
diff --git a/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc b/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc
index dc32d3af4142ee2dae5e477983f206dbbe79d5dd..ef5e8e3d7356e374b519739e98a07d34bd6d450a 100644
--- a/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc
+++ b/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc
@@ -29,6 +29,7 @@
#include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h"
#include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h"
#include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h"
+#include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h"
#include "webrtc/system_wrappers/include/clock.h"
namespace webrtc {
@@ -59,46 +60,6 @@ int GCD(int a, int b) {
return b;
}
-std::vector<int> GetStreamBitratesKbps(const VideoCodec& codec,
- int bitrate_to_allocate_kbps) {
- if (codec.numberOfSimulcastStreams <= 1) {
- return std::vector<int>(1, bitrate_to_allocate_kbps);
- }
-
- std::vector<int> bitrates_kbps(codec.numberOfSimulcastStreams);
- // Allocate min -> target bitrates as long as we have bitrate to spend.
- size_t last_active_stream = 0;
- for (size_t i = 0; i < static_cast<size_t>(codec.numberOfSimulcastStreams) &&
- bitrate_to_allocate_kbps >=
- static_cast<int>(codec.simulcastStream[i].minBitrate);
- ++i) {
- last_active_stream = i;
- int allocated_bitrate_kbps =
- std::min(static_cast<int>(codec.simulcastStream[i].targetBitrate),
- bitrate_to_allocate_kbps);
- bitrates_kbps[i] = allocated_bitrate_kbps;
- bitrate_to_allocate_kbps -= allocated_bitrate_kbps;
- }
-
- // Spend additional bits on the highest-quality active layer, up to max
- // bitrate.
- // TODO(pbos): Consider spending additional bits on last_active_stream-1 down
- // to 0 and not just the top layer when we have additional bitrate to spend.
- int allocated_bitrate_kbps = std::min(
- static_cast<int>(codec.simulcastStream[last_active_stream].maxBitrate -
- bitrates_kbps[last_active_stream]),
- bitrate_to_allocate_kbps);
- bitrates_kbps[last_active_stream] += allocated_bitrate_kbps;
- bitrate_to_allocate_kbps -= allocated_bitrate_kbps;
-
- // Make sure we can always send something. Suspending below min bitrate is
- // controlled outside the codec implementation and is not overriden by this.
- if (bitrates_kbps[0] < static_cast<int>(codec.simulcastStream[0].minBitrate))
- bitrates_kbps[0] = static_cast<int>(codec.simulcastStream[0].minBitrate);
-
- return bitrates_kbps;
-}
-
uint32_t SumStreamMaxBitrate(int streams, const VideoCodec& codec) {
uint32_t bitrate_sum = 0;
for (int i = 0; i < streams; ++i) {
@@ -149,10 +110,9 @@ VP8Decoder* VP8Decoder::Create() {
return new VP8DecoderImpl();
}
-const float kTl1MaxTimeToDropFrames = 20.0f;
-
VP8EncoderImpl::VP8EncoderImpl()
- : encoded_complete_callback_(NULL),
+ : encoded_complete_callback_(nullptr),
+ rate_allocator_(new SimulcastRateAllocator(codec_)),
inited_(false),
timestamp_(0),
feedback_mode_(false),
@@ -162,8 +122,6 @@ VP8EncoderImpl::VP8EncoderImpl()
token_partitions_(VP8_ONE_TOKENPARTITION),
down_scale_requested_(false),
down_scale_bitrate_(0),
- tl0_frame_dropper_(),
- tl1_frame_dropper_(kTl1MaxTimeToDropFrames),
key_frame_request_(kMaxSimulcastStreams, false),
quality_scaler_enabled_(false) {
uint32_t seed = rtc::Time32();
@@ -273,8 +231,8 @@ int VP8EncoderImpl::SetRates(uint32_t new_bitrate_kbit,
}
}
- std::vector<int> stream_bitrates =
- GetStreamBitratesKbps(codec_, new_bitrate_kbit);
+ std::vector<uint32_t> stream_bitrates =
+ rate_allocator_->GetAllocation(new_bitrate_kbit);
size_t stream_idx = encoders_.size() - 1;
for (size_t i = 0; i < encoders_.size(); ++i, --stream_idx) {
if (encoders_.size() > 1)
@@ -403,6 +361,7 @@ int VP8EncoderImpl::InitEncode(const VideoCodec* inst,
timestamp_ = 0;
codec_ = *inst;
+ rate_allocator_.reset(new SimulcastRateAllocator(codec_));
// Code expects simulcastStream resolutions to be correct, make sure they are
// filled even when there are no simulcast layers.
@@ -570,8 +529,8 @@ int VP8EncoderImpl::InitEncode(const VideoCodec* inst,
// Note the order we use is different from webm, we have lowest resolution
// at position 0 and they have highest resolution at position 0.
int stream_idx = encoders_.size() - 1;
- std::vector<int> stream_bitrates =
- GetStreamBitratesKbps(codec_, inst->startBitrate);
+ std::vector<uint32_t> stream_bitrates =
+ rate_allocator_->GetAllocation(inst->startBitrate);
SetStreamState(stream_bitrates[stream_idx] > 0, stream_idx);
configurations_[0].rc_target_bitrate = stream_bitrates[stream_idx];
temporal_layers_[stream_idx]->ConfigureBitrates(
« no previous file with comments | « webrtc/modules/video_coding/codecs/vp8/vp8_impl.h ('k') | webrtc/modules/video_coding/utility/simulcast_rate_allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698