1 /*
2  *  Copyright (c) 2016 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_UTILITY_SIMULCAST_RATE_ALLOCATOR_H_
12 #define MODULES_VIDEO_CODING_UTILITY_SIMULCAST_RATE_ALLOCATOR_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 #include <vector>
18 
19 #include "api/video/video_bitrate_allocation.h"
20 #include "api/video/video_bitrate_allocator.h"
21 #include "api/video_codecs/video_codec.h"
22 #include "rtc_base/constructor_magic.h"
23 #include "rtc_base/experiments/rate_control_settings.h"
24 #include "rtc_base/experiments/stable_target_rate_experiment.h"
25 
26 namespace webrtc {
27 
28 class SimulcastRateAllocator : public VideoBitrateAllocator {
29  public:
30   explicit SimulcastRateAllocator(const VideoCodec& codec);
31   ~SimulcastRateAllocator() override;
32 
33   VideoBitrateAllocation Allocate(
34       VideoBitrateAllocationParameters parameters) override;
35   const VideoCodec& GetCodec() const;
36 
37   static float GetTemporalRateAllocation(int num_layers,
38                                          int temporal_id,
39                                          bool base_heavy_tl3_alloc);
40 
41   void SetLegacyConferenceMode(bool mode) override;
42 
43  private:
44   void DistributeAllocationToSimulcastLayers(
45       DataRate total_bitrate,
46       DataRate stable_bitrate,
47       VideoBitrateAllocation* allocated_bitrates);
48   void DistributeAllocationToTemporalLayers(
49       VideoBitrateAllocation* allocated_bitrates) const;
50   std::vector<uint32_t> DefaultTemporalLayerAllocation(int bitrate_kbps,
51                                                        int max_bitrate_kbps,
52                                                        int simulcast_id) const;
53   std::vector<uint32_t> ScreenshareTemporalLayerAllocation(
54       int bitrate_kbps,
55       int max_bitrate_kbps,
56       int simulcast_id) const;
57   int NumTemporalStreams(size_t simulcast_id) const;
58 
59   const VideoCodec codec_;
60   const StableTargetRateExperiment stable_rate_settings_;
61   const RateControlSettings rate_control_settings_;
62   std::vector<bool> stream_enabled_;
63   bool legacy_conference_mode_;
64 
65   RTC_DISALLOW_COPY_AND_ASSIGN(SimulcastRateAllocator);
66 };
67 
68 }  // namespace webrtc
69 
70 #endif  // MODULES_VIDEO_CODING_UTILITY_SIMULCAST_RATE_ALLOCATOR_H_
71