blob: 5a901ae359c5354d002d7e38c3e58dab09460b35 [file] [log] [blame]
philipelcfc319b2015-11-10 07:17:23 -08001/* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
2*
3* Use of this source code is governed by a BSD-style license
4* that can be found in the LICENSE file in the root of the source
5* tree. An additional intellectual property rights grant can be found
6* in the file PATENTS. All contributing project authors may
7* be found in the AUTHORS file in the root of the source tree.
8*/
9
10#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_SCREENSHARE_LAYERS_H_
11#define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_SCREENSHARE_LAYERS_H_
12
13#include "webrtc/modules/video_coding/codecs/vp9/vp9_impl.h"
14
15namespace webrtc {
16
17class ScreenshareLayersVP9 {
18 public:
19 explicit ScreenshareLayersVP9(uint8_t num_layers);
20
21 // The target bitrate for layer with id layer_id.
22 void ConfigureBitrate(int threshold_kbps, uint8_t layer_id);
23
24 // The current start layer.
25 uint8_t GetStartLayer() const;
26
27 // Update the layer with the size of the layer frame.
28 void LayerFrameEncoded(unsigned int size_bytes, uint8_t layer_id);
29
30 // Get the layer settings for the next superframe.
31 //
32 // In short, each time the GetSuperFrameSettings is called the
33 // bitrate of every layer is calculated and if the cummulative
34 // bitrate exceeds the configured cummulative bitrates
35 // (ConfigureBitrate to configure) up to and including that
36 // layer then the resulting encoding settings for the
37 // superframe will only encode layers above that layer.
38 VP9EncoderImpl::SuperFrameRefSettings GetSuperFrameSettings(
39 uint32_t timestamp,
40 bool is_keyframe);
41
42 private:
43 // How many layers that are used.
44 uint8_t num_layers_;
45
46 // The index of the first layer to encode.
47 uint8_t start_layer_;
48
49 // Cummulative target kbps for the different layers.
50 float threshold_kbps_[kMaxVp9NumberOfSpatialLayers - 1];
51
52 // How many bits that has been used for a certain layer. Increased in
53 // FrameEncoded() by the size of the encoded frame and decreased in
54 // GetSuperFrameSettings() depending on the time between frames.
55 float bits_used_[kMaxVp9NumberOfSpatialLayers];
56
57 // Timestamp of last frame.
58 uint32_t last_timestamp_;
59
60 // If the last_timestamp_ has been set.
61 bool timestamp_initialized_;
62};
63
64} // namespace webrtc
65
66#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_SCREENSHARE_LAYERS_H_