• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef MODULES_VIDEO_CODING_CODECS_VP9_SVC_RATE_ALLOCATOR_H_
12 #define MODULES_VIDEO_CODING_CODECS_VP9_SVC_RATE_ALLOCATOR_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 #include "absl/container/inlined_vector.h"
18 #include "api/video/video_bitrate_allocation.h"
19 #include "api/video/video_bitrate_allocator.h"
20 #include "api/video/video_codec_constants.h"
21 #include "api/video_codecs/video_codec.h"
22 #include "rtc_base/experiments/stable_target_rate_experiment.h"
23 
24 namespace webrtc {
25 
26 class SvcRateAllocator : public VideoBitrateAllocator {
27  public:
28   explicit SvcRateAllocator(const VideoCodec& codec);
29 
30   VideoBitrateAllocation Allocate(
31       VideoBitrateAllocationParameters parameters) override;
32 
33   static DataRate GetMaxBitrate(const VideoCodec& codec);
34   static DataRate GetPaddingBitrate(const VideoCodec& codec);
35   static absl::InlinedVector<DataRate, kMaxSpatialLayers> GetLayerStartBitrates(
36       const VideoCodec& codec);
37 
38  private:
39   VideoBitrateAllocation GetAllocationNormalVideo(
40       DataRate total_bitrate,
41       size_t first_active_layer,
42       size_t num_spatial_layers) const;
43 
44   VideoBitrateAllocation GetAllocationScreenSharing(
45       DataRate total_bitrate,
46       size_t first_active_layer,
47       size_t num_spatial_layers) const;
48 
49   // Returns the number of layers that are active and have enough bitrate to
50   // actually be enabled.
51   size_t FindNumEnabledLayers(DataRate target_rate) const;
52 
53   const VideoCodec codec_;
54   const StableTargetRateExperiment experiment_settings_;
55   const absl::InlinedVector<DataRate, kMaxSpatialLayers>
56       cumulative_layer_start_bitrates_;
57   size_t last_active_layer_count_;
58 };
59 
60 }  // namespace webrtc
61 
62 #endif  // MODULES_VIDEO_CODING_CODECS_VP9_SVC_RATE_ALLOCATOR_H_
63