tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

svc_rate_allocator.h (2314B)


      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 
     16 #include <vector>
     17 
     18 #include "absl/container/inlined_vector.h"
     19 #include "api/field_trials_view.h"
     20 #include "api/units/data_rate.h"
     21 #include "api/video/video_bitrate_allocation.h"
     22 #include "api/video/video_bitrate_allocator.h"
     23 #include "api/video/video_codec_constants.h"
     24 #include "api/video_codecs/video_codec.h"
     25 
     26 namespace webrtc {
     27 
     28 class SvcRateAllocator : public VideoBitrateAllocator {
     29 public:
     30  SvcRateAllocator(const VideoCodec& codec,
     31                   const FieldTrialsView& field_trials);
     32 
     33  VideoBitrateAllocation Allocate(
     34      VideoBitrateAllocationParameters parameters) override;
     35 
     36  static DataRate GetMaxBitrate(const VideoCodec& codec);
     37  static DataRate GetPaddingBitrate(const VideoCodec& codec);
     38  static absl::InlinedVector<DataRate, kMaxSpatialLayers> GetLayerStartBitrates(
     39      const VideoCodec& codec);
     40 
     41 private:
     42  struct NumLayers {
     43    size_t spatial = 1;
     44    size_t temporal = 1;
     45  };
     46 
     47  static NumLayers GetNumLayers(const VideoCodec& codec);
     48  std::vector<DataRate> DistributeAllocationToSpatialLayersNormalVideo(
     49      DataRate total_bitrate,
     50      size_t first_active_layer,
     51      size_t num_spatial_layers) const;
     52 
     53  std::vector<DataRate> DistributeAllocationToSpatialLayersScreenSharing(
     54      DataRate total_bitrate,
     55      size_t first_active_layer,
     56      size_t num_spatial_layers) const;
     57 
     58  // Returns the number of layers that are active and have enough bitrate to
     59  // actually be enabled.
     60  size_t FindNumEnabledLayers(DataRate target_rate) const;
     61 
     62  const VideoCodec codec_;
     63  const NumLayers num_layers_;
     64  const absl::InlinedVector<DataRate, kMaxSpatialLayers>
     65      cumulative_layer_start_bitrates_;
     66  size_t last_active_layer_count_;
     67 };
     68 
     69 }  // namespace webrtc
     70 
     71 #endif  // MODULES_VIDEO_CODING_SVC_SVC_RATE_ALLOCATOR_H_