summaryrefslogtreecommitdiff
path: root/chromium/media/base/bitrate.cc
blob: d2ae94baae9dcd6eaedfa3cd36c734d75feddb30 (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
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/base/bitrate.h"
#include "base/check_op.h"
#include "base/strings/stringprintf.h"

namespace media {

// static
Bitrate Bitrate::VariableBitrate(uint32_t target_bps, uint32_t peak_bps) {
  DCHECK_GE(peak_bps, target_bps);
  return Bitrate(Mode::kVariable, target_bps, peak_bps);
}

bool Bitrate::operator==(const Bitrate& right) const {
  return (this->mode_ == right.mode_) &&
         (this->target_bps_ == right.target_bps_) &&
         (this->peak_bps_ == right.peak_bps_);
}

bool Bitrate::operator!=(const Bitrate& right) const {
  return !(*this == right);
}

uint32_t Bitrate::peak_bps() const {
  DCHECK_EQ(mode_ == Mode::kConstant, peak_bps_ == 0u);
  return peak_bps_;
}

std::string Bitrate::ToString() const {
  switch (mode_) {
    case Mode::kConstant:
      return base::StringPrintf("CBR: %d bps", target_bps_);
    case Mode::kVariable:
      return base::StringPrintf("VBR: target %d bps, peak %d bps", target_bps_,
                                peak_bps_);
  }
}

}  // namespace media