Chromium Code Reviews| Index: webrtc/modules/video_coding/codecs/vp9/screenshare_layers.cc |
| diff --git a/webrtc/modules/video_coding/codecs/vp9/screenshare_layers.cc b/webrtc/modules/video_coding/codecs/vp9/screenshare_layers.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f4a2d0a963248c61525a8bb14c75d01648966a17 |
| --- /dev/null |
| +++ b/webrtc/modules/video_coding/codecs/vp9/screenshare_layers.cc |
| @@ -0,0 +1,77 @@ |
| +/* Copyright (c) 2015 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 <algorithm> |
| +#include "webrtc/modules/video_coding/codecs/vp9/screenshare_layers.h" |
| +#include "webrtc/base/checks.h" |
| + |
| +namespace webrtc { |
| + |
| +ScreenshareLayersVP9::ScreenshareLayersVP9(uint8_t num_layers) |
| + : num_layers_(num_layers), current_layer_(0), last_ts_(0) { |
| + RTC_DCHECK_GT(num_layers, 0); |
| + RTC_DCHECK_LE(num_layers, kMaxVp9NumberOfSpatialLayers); |
| + memset(bits_used_, 0, sizeof(bits_used_)); |
| + memset(threshold_kbps_, 0, sizeof(threshold_kbps_)); |
| +} |
| + |
| +uint8_t ScreenshareLayersVP9::GetStartLayer() const { |
|
stefan-webrtc
2015/10/28 13:59:04
should this be called current_layer()? What is a s
philipel1
2015/10/29 14:49:26
The start layer is the first spatial layer to enco
|
| + return current_layer_; |
| +} |
| + |
| +void ScreenshareLayersVP9::ConfigureBitrate(int threshold_kbps, |
| + uint8_t layer_id) { |
| + // The upper layer can't have a max bitrate, |
| + // and therefore it can't be set. |
|
stefan-webrtc
2015/10/28 13:59:04
Could you also explain why it can't have a max bit
philipel1
2015/10/29 14:49:26
I guess there is no reason other than that we woul
|
| + RTC_DCHECK_LT(layer_id, num_layers_ - 1); |
| + threshold_kbps_[layer_id] = threshold_kbps; |
| +} |
| + |
| +void ScreenshareLayersVP9::LayerFrameEncoded(unsigned int size_bytes, |
| + uint8_t layer_id) { |
| + RTC_DCHECK_LT(layer_id, num_layers_); |
| + bits_used_[layer_id] += size_bytes * 8; |
| +} |
| + |
| +VP9EncoderImpl::SuperFrameRefSettings |
| +ScreenshareLayersVP9::GetSuperFrameSettings(uint32_t timestamp, |
| + bool is_keyframe) { |
| + VP9EncoderImpl::SuperFrameRefSettings settings; |
| + if (last_ts_ == 0) |
|
stefan-webrtc
2015/10/28 13:59:04
0 isn't safe to use as "not initialized"
philipel1
2015/10/29 14:49:26
Added a timestamp_initialized_ variable for initia
|
| + last_ts_ = timestamp; |
| + float time_diff = (timestamp - last_ts_) / 90.f; |
|
stefan-webrtc
2015/10/28 13:59:04
I suspect that this won't handle the case where ti
philipel1
2015/10/29 14:49:26
This will use unsigned arithmetics so it's working
|
| + float total_bits_used = 0; |
|
stefan-webrtc
2015/10/28 13:59:04
I don't really think we need to count with fractio
philipel1
2015/10/29 14:49:26
I use floats not to count fractions of a bit, but
|
| + float total_threshold_kbps = 0; |
| + current_layer_ = 0; |
| + |
| + // Up to (num_layers - 1) because we only have |
| + // (num_layers - 1) thresholds to check. |
| + for (uint8_t layer_id = 0; layer_id < num_layers_ - 1; ++layer_id) { |
|
stefan-webrtc
2015/10/28 13:59:04
int
philipel1
2015/10/29 14:49:26
Done.
|
| + bits_used_[layer_id] = std::max( |
| + 0.f, bits_used_[layer_id] - time_diff * threshold_kbps_[layer_id]); |
| + total_bits_used += bits_used_[layer_id]; |
| + total_threshold_kbps += threshold_kbps_[layer_id]; |
| + if (!is_keyframe) { |
| + settings.layer[layer_id].ref_buf1 = layer_id; |
|
stefan-webrtc
2015/10/28 13:59:04
Comment on what this code block does.
philipel1
2015/10/29 14:49:26
Done.
|
| + if (total_bits_used > total_threshold_kbps * 1000) |
| + current_layer_ = layer_id + 1; |
| + } |
| + settings.layer[layer_id].upd_buf = layer_id; |
| + } |
| + if (!is_keyframe) |
|
stefan-webrtc
2015/10/28 13:59:04
Comment on why !is_keyframe. Why not for key frame
philipel1
2015/10/29 14:49:26
Done.
|
| + settings.layer[num_layers_ - 1].ref_buf1 = num_layers_ - 1; |
| + settings.layer[num_layers_ - 1].upd_buf = num_layers_ - 1; |
| + settings.is_keyframe = is_keyframe; |
| + settings.start_layer = current_layer_; |
| + settings.stop_layer = num_layers_ - 1; |
| + last_ts_ = timestamp; |
| + return settings; |
| +} |
| + |
| +} // namespace webrtc |