diff --git a/common_audio/resampler/sinusoidal_linear_chirp_source.h b/common_audio/resampler/sinusoidal_linear_chirp_source.h index a57cbfef02..ccd11bbd61 100644 --- a/common_audio/resampler/sinusoidal_linear_chirp_source.h +++ b/common_audio/resampler/sinusoidal_linear_chirp_source.h @@ -41,7 +41,7 @@ class SinusoidalLinearChirpSource : public SincResamplerCallback { 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 ee102de745..fbaf970065 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 651d836c82..6052612ef3 100644 --- a/modules/audio_processing/utility/delay_estimator_unittest.cc +++ b/modules/audio_processing/utility/delay_estimator_unittest.cc @@ -18,13 +18,13 @@ namespace webrtc { 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 86f48582a7..cc8d1bff34 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 kNalHeaderSize = 1; 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 payload, @@ -267,7 +261,8 @@ void RtpPacketizerH264::NextAggregatePacket(RtpPacketToSend* rtp_packet) { 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 @@ void RtpPacketizerH264::NextFragmentPacket(RtpPacketToSend* rtp_packet) { // 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 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 283beacb19..f95c3b6c6b 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 d2171963f3..09370b93d3 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 @@ enum Nalu { 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 @@ TEST(RtpPacketizerH264Test, MixedStapAFUA) { 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 @@ std::vector TestFua(size_t frame_payload_size, 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 ee4d744578..9978e5f5fc 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 kFuAHeaderSize = 2; 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 @@ absl::optional ProcessStapAOrSingleNalu( 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 nalu_start_offsets; if (nal_type == H264::NaluType::kStapA) { // Skip the StapA header (StapA NAL type + length). @@ -96,7 +91,7 @@ absl::optional ProcessStapAOrSingleNalu( } 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 @@ absl::optional ProcessStapAOrSingleNalu( } 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 ParseFuaNalu( } absl::optional 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 @@ VideoRtpDepacketizerH264::Parse(rtc::CopyOnWriteBuffer rtp_payload) { 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 d335af0244..f569c45fd3 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 @@ enum Nalu { 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, StapADelta) { 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 @@ TEST(VideoRtpDepacketizerH264Test, FuA) { 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};