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_SVC_SVC_RATE_ALLOCATOR_H_ 12 #define MODULES_VIDEO_CODING_SVC_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 struct NumLayers { 40 size_t spatial = 1; 41 size_t temporal = 1; 42 }; 43 44 static NumLayers GetNumLayers(const VideoCodec& codec); 45 VideoBitrateAllocation GetAllocationNormalVideo( 46 DataRate total_bitrate, 47 size_t first_active_layer, 48 size_t num_spatial_layers) const; 49 50 VideoBitrateAllocation GetAllocationScreenSharing( 51 DataRate total_bitrate, 52 size_t first_active_layer, 53 size_t num_spatial_layers) const; 54 55 // Returns the number of layers that are active and have enough bitrate to 56 // actually be enabled. 57 size_t FindNumEnabledLayers(DataRate target_rate) const; 58 59 const VideoCodec codec_; 60 const NumLayers num_layers_; 61 const StableTargetRateExperiment experiment_settings_; 62 const absl::InlinedVector<DataRate, kMaxSpatialLayers> 63 cumulative_layer_start_bitrates_; 64 size_t last_active_layer_count_; 65 }; 66 67 } // namespace webrtc 68 69 #endif // MODULES_VIDEO_CODING_SVC_SVC_RATE_ALLOCATOR_H_ 70