summaryrefslogtreecommitdiff
path: root/chromium/media/base/video_bitrate_allocation.h
blob: f56c0b072f98001a032d6f6d4b9ed6a40d991ec7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_BASE_VIDEO_BITRATE_ALLOCATION_H_
#define MEDIA_BASE_VIDEO_BITRATE_ALLOCATION_H_

#include <stddef.h>
#include <stdint.h>

#include "base/macros.h"
#include "media/base/media_export.h"

namespace media {

// Class that describes how video bitrate, in bps, is allocated across temporal
// and spatial layers. Note that bitrates are NOT cumulative. Depending on if
// layers are dependent or not, it is up to the user to aggregate.
class MEDIA_EXPORT VideoBitrateAllocation {
 public:
  static constexpr size_t kMaxSpatialLayers = 5;
  static constexpr size_t kMaxTemporalLayers = 4;

  VideoBitrateAllocation();
  ~VideoBitrateAllocation() = default;

  // Returns if this bitrate can't be set (sum exceeds int max value).
  bool SetBitrate(size_t spatial_index, size_t temporal_index, int bitrate_bps);

  // Returns the bitrate for specified spatial/temporal index, or 0 if not set.
  int GetBitrateBps(size_t spatial_index, size_t temporal_index) const;

  // Sum of all bitrates.
  int32_t GetSumBps() const;

  bool operator==(const VideoBitrateAllocation& other) const;
  inline bool operator!=(const VideoBitrateAllocation& other) const {
    return !(*this == other);
  }

 private:
  int sum_;  // Cached sum of all elements of |bitrates_|, for performance.
  int bitrates_[kMaxSpatialLayers][kMaxTemporalLayers];
};

}  // namespace media

#endif  // MEDIA_BASE_VIDEO_BITRATE_ALLOCATION_H_