Fix math involving enums in C++20
(-Wdeprecated-anon-enum-enum-conversion)
- Replace enum with constexpr if necessary.
- Merge multiple definitions for H.264 NalDefs and FuDefs and apply
constexpr.
Bug: chromium:1284275
Change-Id: I4a4d95ed6aba258e7c19c3ae6251c8b78caf84ec
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/276561
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Auto-Submit: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com>
Cr-Commit-Position: refs/heads/main@{#38215}
diff --git a/common_audio/resampler/sinusoidal_linear_chirp_source.h b/common_audio/resampler/sinusoidal_linear_chirp_source.h
index a57cbfe..ccd11bb 100644
--- a/common_audio/resampler/sinusoidal_linear_chirp_source.h
+++ b/common_audio/resampler/sinusoidal_linear_chirp_source.h
@@ -41,7 +41,7 @@
double Frequency(size_t position);
private:
- enum { kMinFrequency = 5 };
+ static constexpr int kMinFrequency = 5;
int sample_rate_;
size_t total_samples_;
diff --git a/common_audio/vad/vad_core.h b/common_audio/vad/vad_core.h
index ee102de..fbaf970 100644
--- a/common_audio/vad/vad_core.h
+++ b/common_audio/vad/vad_core.h
@@ -17,10 +17,19 @@
#include "common_audio/signal_processing/include/signal_processing_library.h"
-enum { kNumChannels = 6 }; // Number of frequency bands (named channels).
-enum { kNumGaussians = 2 }; // Number of Gaussians per channel in the GMM.
-enum { kTableSize = kNumChannels * kNumGaussians };
-enum { kMinEnergy = 10 }; // Minimum energy required to trigger audio signal.
+// TODO(https://bugs.webrtc.org/14476): When converted to C++, remove the macro.
+#if defined(__cplusplus)
+#define CONSTEXPR_INT(x) constexpr int x
+#else
+#define CONSTEXPR_INT(x) enum { x }
+#endif
+
+CONSTEXPR_INT(kNumChannels = 6); // Number of frequency bands (named channels).
+CONSTEXPR_INT(
+ kNumGaussians = 2); // Number of Gaussians per channel in the GMM.
+CONSTEXPR_INT(kTableSize = kNumChannels * kNumGaussians);
+CONSTEXPR_INT(
+ kMinEnergy = 10); // Minimum energy required to trigger audio signal.
typedef struct VadInstT_ {
int vad;
diff --git a/modules/audio_processing/utility/delay_estimator_unittest.cc b/modules/audio_processing/utility/delay_estimator_unittest.cc
index 651d836..6052612 100644
--- a/modules/audio_processing/utility/delay_estimator_unittest.cc
+++ b/modules/audio_processing/utility/delay_estimator_unittest.cc
@@ -18,13 +18,13 @@
namespace {
-enum { kSpectrumSize = 65 };
+constexpr int kSpectrumSize = 65;
// Delay history sizes.
-enum { kMaxDelay = 100 };
-enum { kLookahead = 10 };
-enum { kHistorySize = kMaxDelay + kLookahead };
+constexpr int kMaxDelay = 100;
+constexpr int kLookahead = 10;
+constexpr int kHistorySize = kMaxDelay + kLookahead;
// Length of binary spectrum sequence.
-enum { kSequenceLength = 400 };
+constexpr int kSequenceLength = 400;
const int kDifferentHistorySize = 3;
const int kDifferentLookahead = 1;
diff --git a/modules/rtp_rtcp/source/rtp_format_h264.cc b/modules/rtp_rtcp/source/rtp_format_h264.cc
index 86f4858..cc8d1bf 100644
--- a/modules/rtp_rtcp/source/rtp_format_h264.cc
+++ b/modules/rtp_rtcp/source/rtp_format_h264.cc
@@ -37,12 +37,6 @@
static const size_t kFuAHeaderSize = 2;
static const size_t kLengthFieldSize = 2;
-// Bit masks for FU (A and B) indicators.
-enum NalDefs : uint8_t { kFBit = 0x80, kNriMask = 0x60, kTypeMask = 0x1F };
-
-// Bit masks for FU (A and B) headers.
-enum FuDefs : uint8_t { kSBit = 0x80, kEBit = 0x40, kRBit = 0x20 };
-
} // namespace
RtpPacketizerH264::RtpPacketizerH264(rtc::ArrayView<const uint8_t> payload,
@@ -267,7 +261,8 @@
PacketUnit* packet = &packets_.front();
RTC_CHECK(packet->first_fragment);
// STAP-A NALU header.
- buffer[0] = (packet->header & (kFBit | kNriMask)) | H264::NaluType::kStapA;
+ buffer[0] =
+ (packet->header & (kH264FBit | kH264NriMask)) | H264::NaluType::kStapA;
size_t index = kNalHeaderSize;
bool is_last_fragment = packet->last_fragment;
while (packet->aggregated) {
@@ -296,13 +291,13 @@
// We do not send original NALU header, so it will be replaced by the
// FU indicator header of the first packet.
uint8_t fu_indicator =
- (packet->header & (kFBit | kNriMask)) | H264::NaluType::kFuA;
+ (packet->header & (kH264FBit | kH264NriMask)) | H264::NaluType::kFuA;
uint8_t fu_header = 0;
// S | E | R | 5 bit type.
- fu_header |= (packet->first_fragment ? kSBit : 0);
- fu_header |= (packet->last_fragment ? kEBit : 0);
- uint8_t type = packet->header & kTypeMask;
+ fu_header |= (packet->first_fragment ? kH264SBit : 0);
+ fu_header |= (packet->last_fragment ? kH264EBit : 0);
+ uint8_t type = packet->header & kH264TypeMask;
fu_header |= type;
rtc::ArrayView<const uint8_t> fragment = packet->source_fragment;
uint8_t* buffer =
diff --git a/modules/rtp_rtcp/source/rtp_format_h264.h b/modules/rtp_rtcp/source/rtp_format_h264.h
index 283beac..f95c3b6 100644
--- a/modules/rtp_rtcp/source/rtp_format_h264.h
+++ b/modules/rtp_rtcp/source/rtp_format_h264.h
@@ -26,6 +26,16 @@
namespace webrtc {
+// Bit masks for NAL (F, NRI, Type) indicators.
+constexpr uint8_t kH264FBit = 0x80;
+constexpr uint8_t kH264NriMask = 0x60;
+constexpr uint8_t kH264TypeMask = 0x1F;
+
+// Bit masks for FU (A and B) headers.
+constexpr uint8_t kH264SBit = 0x80;
+constexpr uint8_t kH264EBit = 0x40;
+constexpr uint8_t kH264RBit = 0x20;
+
class RtpPacketizerH264 : public RtpPacketizer {
public:
// Initialize with payload from encoder.
diff --git a/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc b/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc
index d217196..09370b9 100644
--- a/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc
+++ b/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc
@@ -50,12 +50,6 @@
static const size_t kNalHeaderSize = 1;
static const size_t kFuAHeaderSize = 2;
-// Bit masks for FU (A and B) indicators.
-enum NalDefs { kFBit = 0x80, kNriMask = 0x60, kTypeMask = 0x1F };
-
-// Bit masks for FU (A and B) headers.
-enum FuDefs { kSBit = 0x80, kEBit = 0x40, kRBit = 0x20 };
-
// Creates Buffer that looks like nal unit of given size.
rtc::Buffer GenerateNalUnit(size_t size) {
RTC_CHECK_GT(size, 0);
@@ -359,13 +353,13 @@
ASSERT_THAT(packets, SizeIs(3));
// First expect two FU-A packets.
EXPECT_THAT(packets[0].payload().subview(0, kFuAHeaderSize),
- ElementsAre(kFuA, FuDefs::kSBit | nalus[0][0]));
+ ElementsAre(kFuA, kH264SBit | nalus[0][0]));
EXPECT_THAT(
packets[0].payload().subview(kFuAHeaderSize),
ElementsAreArray(nalus[0].data() + kNalHeaderSize, kFuaPayloadSize));
EXPECT_THAT(packets[1].payload().subview(0, kFuAHeaderSize),
- ElementsAre(kFuA, FuDefs::kEBit | nalus[0][0]));
+ ElementsAre(kFuA, kH264EBit | nalus[0][0]));
EXPECT_THAT(
packets[1].payload().subview(kFuAHeaderSize),
ElementsAreArray(nalus[0].data() + kNalHeaderSize + kFuaPayloadSize,
@@ -426,11 +420,11 @@
payload_sizes.push_back(payload.size() - kFuAHeaderSize);
}
- EXPECT_TRUE(fua_header.front() & FuDefs::kSBit);
- EXPECT_TRUE(fua_header.back() & FuDefs::kEBit);
+ EXPECT_TRUE(fua_header.front() & kH264SBit);
+ EXPECT_TRUE(fua_header.back() & kH264EBit);
// Clear S and E bits before testing all are duplicating same original header.
- fua_header.front() &= ~FuDefs::kSBit;
- fua_header.back() &= ~FuDefs::kEBit;
+ fua_header.front() &= ~kH264SBit;
+ fua_header.back() &= ~kH264EBit;
EXPECT_THAT(fua_header, Each(Eq((kFuA << 8) | nalu[0][0])));
return payload_sizes;
diff --git a/modules/rtp_rtcp/source/video_rtp_depacketizer_h264.cc b/modules/rtp_rtcp/source/video_rtp_depacketizer_h264.cc
index ee4d744..9978e5f 100644
--- a/modules/rtp_rtcp/source/video_rtp_depacketizer_h264.cc
+++ b/modules/rtp_rtcp/source/video_rtp_depacketizer_h264.cc
@@ -22,6 +22,7 @@
#include "common_video/h264/sps_parser.h"
#include "common_video/h264/sps_vui_rewriter.h"
#include "modules/rtp_rtcp/source/byte_io.h"
+#include "modules/rtp_rtcp/source/rtp_format_h264.h"
#include "modules/rtp_rtcp/source/video_rtp_depacketizer.h"
#include "rtc_base/checks.h"
#include "rtc_base/copy_on_write_buffer.h"
@@ -35,12 +36,6 @@
constexpr size_t kLengthFieldSize = 2;
constexpr size_t kStapAHeaderSize = kNalHeaderSize + kLengthFieldSize;
-// Bit masks for FU (A and B) indicators.
-enum NalDefs : uint8_t { kFBit = 0x80, kNriMask = 0x60, kTypeMask = 0x1F };
-
-// Bit masks for FU (A and B) headers.
-enum FuDefs : uint8_t { kSBit = 0x80, kEBit = 0x40, kRBit = 0x20 };
-
// TODO(pbos): Avoid parsing this here as well as inside the jitter buffer.
bool ParseStapAStartOffsets(const uint8_t* nalu_ptr,
size_t length_remaining,
@@ -81,7 +76,7 @@
const uint8_t* nalu_start = payload_data + kNalHeaderSize;
const size_t nalu_length = rtp_payload.size() - kNalHeaderSize;
- uint8_t nal_type = payload_data[0] & kTypeMask;
+ uint8_t nal_type = payload_data[0] & kH264TypeMask;
std::vector<size_t> nalu_start_offsets;
if (nal_type == H264::NaluType::kStapA) {
// Skip the StapA header (StapA NAL type + length).
@@ -96,7 +91,7 @@
}
h264_header.packetization_type = kH264StapA;
- nal_type = payload_data[kStapAHeaderSize] & kTypeMask;
+ nal_type = payload_data[kStapAHeaderSize] & kH264TypeMask;
} else {
h264_header.packetization_type = kH264SingleNalu;
nalu_start_offsets.push_back(0);
@@ -117,7 +112,7 @@
}
NaluInfo nalu;
- nalu.type = payload_data[start_offset] & kTypeMask;
+ nalu.type = payload_data[start_offset] & kH264TypeMask;
nalu.sps_id = -1;
nalu.pps_id = -1;
start_offset += H264::kNaluTypeSize;
@@ -241,9 +236,9 @@
}
absl::optional<VideoRtpDepacketizer::ParsedRtpPayload> parsed_payload(
absl::in_place);
- uint8_t fnri = rtp_payload.cdata()[0] & (kFBit | kNriMask);
- uint8_t original_nal_type = rtp_payload.cdata()[1] & kTypeMask;
- bool first_fragment = (rtp_payload.cdata()[1] & kSBit) > 0;
+ uint8_t fnri = rtp_payload.cdata()[0] & (kH264FBit | kH264NriMask);
+ uint8_t original_nal_type = rtp_payload.cdata()[1] & kH264TypeMask;
+ bool first_fragment = (rtp_payload.cdata()[1] & kH264SBit) > 0;
NaluInfo nalu;
nalu.type = original_nal_type;
nalu.sps_id = -1;
@@ -300,7 +295,7 @@
return absl::nullopt;
}
- uint8_t nal_type = rtp_payload.cdata()[0] & kTypeMask;
+ uint8_t nal_type = rtp_payload.cdata()[0] & kH264TypeMask;
if (nal_type == H264::NaluType::kFuA) {
// Fragmented NAL units (FU-A).
diff --git a/modules/rtp_rtcp/source/video_rtp_depacketizer_h264_unittest.cc b/modules/rtp_rtcp/source/video_rtp_depacketizer_h264_unittest.cc
index d335af0..f569c45 100644
--- a/modules/rtp_rtcp/source/video_rtp_depacketizer_h264_unittest.cc
+++ b/modules/rtp_rtcp/source/video_rtp_depacketizer_h264_unittest.cc
@@ -18,6 +18,7 @@
#include "common_video/h264/h264_common.h"
#include "modules/rtp_rtcp/mocks/mock_rtp_rtcp.h"
#include "modules/rtp_rtcp/source/byte_io.h"
+#include "modules/rtp_rtcp/source/rtp_format_h264.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "test/gmock.h"
#include "test/gtest.h"
@@ -42,12 +43,6 @@
kFuA = 28
};
-// Bit masks for FU (A and B) indicators.
-enum NalDefs { kFBit = 0x80, kNriMask = 0x60, kTypeMask = 0x1F };
-
-// Bit masks for FU (A and B) headers.
-enum FuDefs { kSBit = 0x80, kEBit = 0x40, kRBit = 0x20 };
-
constexpr uint8_t kOriginalSps[] = {kSps, 0x00, 0x00, 0x03, 0x03,
0xF4, 0x05, 0x03, 0xC7, 0xC0};
constexpr uint8_t kRewrittenSps[] = {kSps, 0x00, 0x00, 0x03, 0x03,
@@ -293,8 +288,8 @@
TEST(VideoRtpDepacketizerH264Test, FuA) {
// clang-format off
uint8_t packet1[] = {
- kFuA, // F=0, NRI=0, Type=28.
- kSBit | kIdr, // FU header.
+ kFuA, // F=0, NRI=0, Type=28.
+ kH264SBit | kIdr, // FU header.
0x85, 0xB8, 0x0, 0x4, 0x0, 0x0, 0x13, 0x93, 0x12, 0x0 // Payload.
};
// clang-format on
@@ -309,9 +304,9 @@
const uint8_t kExpected2[] = {0x02};
uint8_t packet3[] = {
- kFuA, // F=0, NRI=0, Type=28.
- kEBit | kIdr, // FU header.
- 0x03 // Payload.
+ kFuA, // F=0, NRI=0, Type=28.
+ kH264EBit | kIdr, // FU header.
+ 0x03 // Payload.
};
const uint8_t kExpected3[] = {0x03};