Index: webrtc/modules/video_coding/codecs/vp8/realtime_temporal_layers.cc |
diff --git a/webrtc/modules/video_coding/codecs/vp8/realtime_temporal_layers.cc b/webrtc/modules/video_coding/codecs/vp8/realtime_temporal_layers.cc |
index a3e65e4ce0d8c159f6ec68ea7bbf407338d4bfc5..b9721cde1bcc6b6b9bb31a3962db0dfe0c3deb2f 100644 |
--- a/webrtc/modules/video_coding/codecs/vp8/realtime_temporal_layers.cc |
+++ b/webrtc/modules/video_coding/codecs/vp8/realtime_temporal_layers.cc |
@@ -12,8 +12,6 @@ |
#include "vpx/vpx_encoder.h" |
#include "vpx/vp8cx.h" |
-#include "webrtc/base/checks.h" |
-#include "webrtc/base/optional.h" |
#include "webrtc/modules/video_coding/include/video_codec_interface.h" |
#include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h" |
#include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" |
@@ -97,20 +95,26 @@ |
layer_ids_(NULL), |
encode_flags_length_(0), |
encode_flags_(NULL) { |
- RTC_CHECK_GE(max_temporal_layers_, 1); |
- RTC_CHECK_GE(max_temporal_layers_, 3); |
+ assert(max_temporal_layers_ >= 1); |
+ assert(max_temporal_layers_ <= 3); |
} |
virtual ~RealTimeTemporalLayers() {} |
- std::vector<uint32_t> OnRatesUpdated(int bitrate_kbps, |
- int max_bitrate_kbps, |
- int framerate) override { |
+ bool ConfigureBitrates(int bitrate_kbit, |
+ int max_bitrate_kbit, |
+ int framerate, |
+ vpx_codec_enc_cfg_t* cfg) override { |
temporal_layers_ = |
CalculateNumberOfTemporalLayers(temporal_layers_, framerate); |
temporal_layers_ = std::min(temporal_layers_, max_temporal_layers_); |
- RTC_CHECK_GE(temporal_layers_, 1); |
- RTC_CHECK_LE(temporal_layers_, 3); |
+ assert(temporal_layers_ >= 1 && temporal_layers_ <= 3); |
+ |
+ cfg->ts_number_layers = temporal_layers_; |
+ for (int tl = 0; tl < temporal_layers_; ++tl) { |
+ cfg->ts_target_bitrate[tl] = |
+ bitrate_kbit * kVp8LayerRateAlloction[temporal_layers_ - 1][tl]; |
+ } |
switch (temporal_layers_) { |
case 1: { |
@@ -121,6 +125,9 @@ |
static const int encode_flags[] = {kTemporalUpdateLastRefAll}; |
encode_flags_length_ = sizeof(encode_flags) / sizeof(*layer_ids); |
encode_flags_ = encode_flags; |
+ |
+ cfg->ts_rate_decimator[0] = 1; |
+ cfg->ts_periodicity = layer_ids_length_; |
} break; |
case 2: { |
@@ -139,6 +146,10 @@ |
kTemporalUpdateNone}; |
encode_flags_length_ = sizeof(encode_flags) / sizeof(*layer_ids); |
encode_flags_ = encode_flags; |
+ |
+ cfg->ts_rate_decimator[0] = 2; |
+ cfg->ts_rate_decimator[1] = 1; |
+ cfg->ts_periodicity = layer_ids_length_; |
} break; |
case 3: { |
@@ -157,59 +168,19 @@ |
kTemporalUpdateNone}; |
encode_flags_length_ = sizeof(encode_flags) / sizeof(*layer_ids); |
encode_flags_ = encode_flags; |
+ |
+ cfg->ts_rate_decimator[0] = 4; |
+ cfg->ts_rate_decimator[1] = 2; |
+ cfg->ts_rate_decimator[2] = 1; |
+ cfg->ts_periodicity = layer_ids_length_; |
} break; |
default: |
- RTC_NOTREACHED(); |
- return std::vector<uint32_t>(); |
+ assert(false); |
+ return false; |
} |
- |
- std::vector<uint32_t> bitrates; |
- const int num_layers = std::max(1, temporal_layers_); |
- for (int i = 0; i < num_layers; ++i) { |
- float layer_bitrate = |
- bitrate_kbps * kVp8LayerRateAlloction[num_layers - 1][i]; |
- bitrates.push_back(static_cast<uint32_t>(layer_bitrate + 0.5)); |
- } |
- new_bitrates_kbps_ = rtc::Optional<std::vector<uint32_t>>(bitrates); |
- |
- // Allocation table is of aggregates, transform to individual rates. |
- uint32_t sum = 0; |
- for (int i = 0; i < num_layers; ++i) { |
- uint32_t layer_bitrate = bitrates[i]; |
- RTC_DCHECK_LE(sum, bitrates[i]); |
- bitrates[i] -= sum; |
- sum += layer_bitrate; |
- |
- if (sum == static_cast<uint32_t>(bitrate_kbps)) { |
- // Sum adds up; any subsequent layers will be 0. |
- bitrates.resize(i); |
- break; |
- } |
- } |
- |
- return bitrates; |
- } |
- |
- bool UpdateConfiguration(vpx_codec_enc_cfg_t* cfg) override { |
- if (!new_bitrates_kbps_) |
- return false; |
- |
- cfg->ts_number_layers = temporal_layers_; |
- for (int tl = 0; tl < temporal_layers_; ++tl) { |
- cfg->ts_target_bitrate[tl] = (*new_bitrates_kbps_)[tl]; |
- } |
- new_bitrates_kbps_ = rtc::Optional<std::vector<uint32_t>>(); |
- |
- cfg->ts_periodicity = layer_ids_length_; |
- int decimator = 1; |
- for (int i = temporal_layers_ - 1; i >= 0; --i, decimator *= 2) { |
- cfg->ts_rate_decimator[i] = decimator; |
- } |
- |
memcpy(cfg->ts_layer_id, layer_ids_, |
sizeof(unsigned int) * layer_ids_length_); |
- |
return true; |
} |
@@ -277,6 +248,8 @@ |
void FrameEncoded(unsigned int size, uint32_t timestamp, int qp) override {} |
+ bool UpdateConfiguration(vpx_codec_enc_cfg_t* cfg) override { return false; } |
+ |
private: |
int temporal_layers_; |
int max_temporal_layers_; |
@@ -293,19 +266,12 @@ |
// Pattern of encode flags. |
int encode_flags_length_; |
const int* encode_flags_; |
- |
- rtc::Optional<std::vector<uint32_t>> new_bitrates_kbps_; |
}; |
} // namespace |
TemporalLayers* RealTimeTemporalLayersFactory::Create( |
- int simulcast_id, |
int max_temporal_layers, |
uint8_t initial_tl0_pic_idx) const { |
- TemporalLayers* tl = |
- new RealTimeTemporalLayers(max_temporal_layers, initial_tl0_pic_idx); |
- if (listener_) |
- listener_->OnTemporalLayersCreated(simulcast_id, tl); |
- return tl; |
+ return new RealTimeTemporalLayers(max_temporal_layers, initial_tl0_pic_idx); |
} |
} // namespace webrtc |