Skip to content

Commit

Permalink
Fixes for C++20 support.
Browse files Browse the repository at this point in the history
* Math between disparate enum types, and between enums and floats, is
  deprecated.  Use constexprs instead.
* Types on both sides of comparison operators should be the same.
* Comparing arrays requires explicitly decaying them to pointers with
  unary "+".

Bug: 1284275
Change-Id: I954184b0fd045ce6b0655def205499ca978c40bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3629916
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Eugene Zemtsov <eugene@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1001610}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed May 10, 2022
1 parent d48c377 commit 57142ec
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 97 deletions.
128 changes: 63 additions & 65 deletions media/base/limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,78 +13,76 @@ namespace media {

namespace limits {

enum {
// Maximum possible dimension (width or height) for any video.
kMaxDimension = (1 << 15) - 1, // 32767

// Maximum possible canvas size (width multiplied by height) for any video.
kMaxCanvas = (1 << (14 * 2)), // 16384 x 16384

// Total number of video frames which are populating in the pipeline.
kMaxVideoFrames = 4,

// The following limits are used by AudioParameters::IsValid().
//
// A few notes on sample rates of common formats:
// - AAC files are limited to 96 kHz.
// - MP3 files are limited to 48 kHz.
// - Vorbis used to be limited to 96 kHz, but no longer has that
// restriction.
// - Most PC audio hardware is limited to 192 kHz, some specialized DAC
// devices will use 768 kHz though.
//
// kMaxSampleRate should be updated with
// blink::audio_utilities::MaxAudioBufferSampleRate()
kMaxSampleRate = 768000,
kMinSampleRate = 3000,
kMaxChannels = 32,
kMaxBytesPerSample = 4,
kMaxBitsPerSample = kMaxBytesPerSample * 8,
kMaxSamplesPerPacket = kMaxSampleRate,
kMaxPacketSizeInBytes =
kMaxBytesPerSample * kMaxChannels * kMaxSamplesPerPacket,

// This limit is used by ParamTraits<VideoCaptureParams>.
kMaxFramesPerSecond = 1000,

// The minimum elapsed amount of time (in seconds) for a playback to be
// considered as having active engagement.
kMinimumElapsedWatchTimeSecs = 7,

// Maximum lengths for various EME API parameters. These are checks to
// prevent unnecessarily large parameters from being passed around, and the
// lengths are somewhat arbitrary as the EME spec doesn't specify any limits.
kMinCertificateLength = 128,
kMaxCertificateLength = 16 * 1024,
kMaxSessionIdLength = 512,
kMinKeyIdLength = 1,
kMaxKeyIdLength = 512,
kMaxKeyIds = 128,
kMaxInitDataLength = 64 * 1024, // 64 KB
kMaxSessionResponseLength = 64 * 1024, // 64 KB
kMaxKeySystemLength = 256,
// Maximum possible dimension (width or height) for any video.
constexpr int kMaxDimension = (1 << 15) - 1; // 32767

// Maximum possible canvas size (width multiplied by height) for any video.
constexpr int kMaxCanvas = (1 << (14 * 2)); // 16384 x 16384

// Total number of video frames which are populating in the pipeline.
constexpr int kMaxVideoFrames = 4;

// The following limits are used by AudioParameters::IsValid().
//
// A few notes on sample rates of common formats:
// - AAC files are limited to 96 kHz.
// - MP3 files are limited to 48 kHz.
// - Vorbis used to be limited to 96 kHz, but no longer has that
// restriction.
// - Most PC audio hardware is limited to 192 kHz, some specialized DAC
// devices will use 768 kHz though.
//
// kMaxSampleRate should be updated with
// blink::audio_utilities::MaxAudioBufferSampleRate()
constexpr int kMaxSampleRate = 768000;
constexpr int kMinSampleRate = 3000;
constexpr int kMaxChannels = 32;
constexpr int kMaxBytesPerSample = 4;
constexpr int kMaxBitsPerSample = kMaxBytesPerSample * 8;
constexpr int kMaxSamplesPerPacket = kMaxSampleRate;
constexpr int kMaxPacketSizeInBytes =
kMaxBytesPerSample * kMaxChannels * kMaxSamplesPerPacket;

// This limit is used by ParamTraits<VideoCaptureParams>.
constexpr int kMaxFramesPerSecond = 1000;

// The minimum elapsed amount of time (in seconds) for a playback to be
// considered as having active engagement.
constexpr int kMinimumElapsedWatchTimeSecs = 7;

// Maximum lengths for various EME API parameters. These are checks to
// prevent unnecessarily large parameters from being passed around, and the
// lengths are somewhat arbitrary as the EME spec doesn't specify any limits.
constexpr int kMinCertificateLength = 128;
constexpr int kMaxCertificateLength = 16 * 1024;
constexpr int kMaxSessionIdLength = 512;
constexpr int kMinKeyIdLength = 1;
constexpr int kMaxKeyIdLength = 512;
constexpr int kMaxKeyIds = 128;
constexpr int kMaxInitDataLength = 64 * 1024; // 64 KB
constexpr int kMaxSessionResponseLength = 64 * 1024; // 64 KB
constexpr int kMaxKeySystemLength = 256;

// Minimum and maximum buffer sizes for certain audio platforms.
#if BUILDFLAG(IS_MAC)
kMinAudioBufferSize = 128,
kMaxAudioBufferSize = 4096,
constexpr int kMinAudioBufferSize = 128;
constexpr int kMaxAudioBufferSize = 4096;
#elif defined(USE_CRAS)
// Though CRAS has different per-board defaults, allow explicitly requesting
// this buffer size on any board.
kMinAudioBufferSize = 256,
kMaxAudioBufferSize = 8192,
// Though CRAS has different per-board defaults, allow explicitly requesting
// this buffer size on any board.
constexpr int kMinAudioBufferSize = 256;
constexpr int kMaxAudioBufferSize = 8192;
#endif

// Maximum buffer size supported by Web Audio.
kMaxWebAudioBufferSize = 8192,
// Maximum buffer size supported by Web Audio.
constexpr int kMaxWebAudioBufferSize = 8192;

// Bounds for the number of threads used for software video decoding.
kMinVideoDecodeThreads = 2,
kMaxVideoDecodeThreads =
16, // Matches ffmpeg's MAX_AUTO_THREADS. Higher values can result in
// immediate out of memory errors for high resolution content. See
// https://crbug.com/893984
};
// Bounds for the number of threads used for software video decoding.
constexpr int kMinVideoDecodeThreads = 2;
constexpr int kMaxVideoDecodeThreads =
16; // Matches ffmpeg's MAX_AUTO_THREADS. Higher values can result in
// immediate out of memory errors for high resolution content. See
// https://crbug.com/893984

} // namespace limits

Expand Down
31 changes: 15 additions & 16 deletions media/base/sinc_resampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@ namespace media {
// SincResampler is a high-quality single-channel sample-rate converter.
class MEDIA_EXPORT SincResampler {
public:
enum {
// The kernel size can be adjusted for quality (higher is better) at the
// expense of performance. Must be a multiple of 32.
// TODO(dalecurtis): Test performance to see if we can jack this up to 64+.
kKernelSize = 32,

// Default request size. Affects how often and for how much SincResampler
// calls back for input. Must be greater than kKernelSize.
kDefaultRequestSize = 512,

// The kernel offset count is used for interpolation and is the number of
// sub-sample kernel shifts. Can be adjusted for quality (higher is better)
// at the expense of allocating more memory.
kKernelOffsetCount = 32,
kKernelStorageSize = kKernelSize * (kKernelOffsetCount + 1),
};
// The kernel size can be adjusted for quality (higher is better) at the
// expense of performance. Must be a multiple of 32.
// TODO(dalecurtis): Test performance to see if we can jack this up to 64+.
static constexpr int kKernelSize = 32;

// Default request size. Affects how often and for how much SincResampler
// calls back for input. Must be greater than kKernelSize.
static constexpr int kDefaultRequestSize = 512;

// The kernel offset count is used for interpolation and is the number of
// sub-sample kernel shifts. Can be adjusted for quality (higher is better)
// at the expense of allocating more memory.
static constexpr int kKernelOffsetCount = 32;
static constexpr int kKernelStorageSize =
kKernelSize * (kKernelOffsetCount + 1);

// Callback type for providing more data into the resampler. Expects |frames|
// of data to be rendered into |destination|; zero padded if not enough frames
Expand Down
4 changes: 1 addition & 3 deletions media/base/sinc_resampler_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ class SinusoidalLinearChirpSource {
}

private:
enum {
kMinFrequency = 5
};
static constexpr int kMinFrequency = 5;

double sample_rate_;
int total_samples_;
Expand Down
30 changes: 24 additions & 6 deletions media/cast/common/expanded_value_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,30 @@ class ExpandedValueBase {
}

// Comparison operators.
bool operator==(Subclass rhs) const { return value_ == rhs.value_; }
bool operator!=(Subclass rhs) const { return value_ != rhs.value_; }
bool operator<(Subclass rhs) const { return value_ < rhs.value_; }
bool operator>(Subclass rhs) const { return value_ > rhs.value_; }
bool operator<=(Subclass rhs) const { return value_ <= rhs.value_; }
bool operator>=(Subclass rhs) const { return value_ >= rhs.value_; }
bool operator==(
const ExpandedValueBase<FullWidthInteger, Subclass>& rhs) const {
return value_ == rhs.value_;
}
bool operator!=(
const ExpandedValueBase<FullWidthInteger, Subclass>& rhs) const {
return value_ != rhs.value_;
}
bool operator<(
const ExpandedValueBase<FullWidthInteger, Subclass>& rhs) const {
return value_ < rhs.value_;
}
bool operator>(
const ExpandedValueBase<FullWidthInteger, Subclass>& rhs) const {
return value_ > rhs.value_;
}
bool operator<=(
const ExpandedValueBase<FullWidthInteger, Subclass>& rhs) const {
return value_ <= rhs.value_;
}
bool operator>=(
const ExpandedValueBase<FullWidthInteger, Subclass>& rhs) const {
return value_ >= rhs.value_;
}

// (De)Serialize for transmission over IPC. Do not use these to subvert the
// valid set of operators allowed by this class or its Subclass.
Expand Down
8 changes: 3 additions & 5 deletions media/cast/encoding/external_video_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,9 @@ class SizeAdaptableExternalVideoEncoder final
// value is related to the complexity of the content of the frame.
class QuantizerEstimator {
public:
enum {
NO_RESULT = -1,
MIN_VP8_QUANTIZER = 4,
MAX_VP8_QUANTIZER = 63,
};
static constexpr int NO_RESULT = -1;
static constexpr int MIN_VP8_QUANTIZER = 4;
static constexpr int MAX_VP8_QUANTIZER = 63;

QuantizerEstimator();

Expand Down
2 changes: 1 addition & 1 deletion media/filters/vp9_compressed_header_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void Vp9CompressedHeaderParser::ReadCoefProbs(Vp9FrameHeader* fhdr) {
for (auto& ai : fhdr->frame_context.coef_probs[tx_size]) {
for (auto& aj : ai) {
for (auto& ak : aj) {
int max_l = (ak == aj[0]) ? 3 : 6;
int max_l = (+ak == +aj[0]) ? 3 : 6;
for (int l = 0; l < max_l; l++) {
DiffUpdateProbArray(ak[l]);
}
Expand Down
2 changes: 1 addition & 1 deletion media/filters/vp9_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ bool Vp9FrameContext::IsValid() const {
for (auto& ai : a) {
for (auto& aj : ai) {
for (auto& ak : aj) {
int max_l = (ak == aj[0]) ? 3 : 6;
int max_l = (+ak == +aj[0]) ? 3 : 6;
for (int l = 0; l < max_l; l++) {
for (auto& x : ak[l]) {
if (x == 0) {
Expand Down

0 comments on commit 57142ec

Please sign in to comment.