mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
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}
This commit is contained in:
parent
806261ae8e
commit
6c2ac2ea6b
8 changed files with 55 additions and 57 deletions
|
@ -41,7 +41,7 @@ class SinusoidalLinearChirpSource : public SincResamplerCallback {
|
||||||
double Frequency(size_t position);
|
double Frequency(size_t position);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum { kMinFrequency = 5 };
|
static constexpr int kMinFrequency = 5;
|
||||||
|
|
||||||
int sample_rate_;
|
int sample_rate_;
|
||||||
size_t total_samples_;
|
size_t total_samples_;
|
||||||
|
|
|
@ -17,10 +17,19 @@
|
||||||
|
|
||||||
#include "common_audio/signal_processing/include/signal_processing_library.h"
|
#include "common_audio/signal_processing/include/signal_processing_library.h"
|
||||||
|
|
||||||
enum { kNumChannels = 6 }; // Number of frequency bands (named channels).
|
// TODO(https://bugs.webrtc.org/14476): When converted to C++, remove the macro.
|
||||||
enum { kNumGaussians = 2 }; // Number of Gaussians per channel in the GMM.
|
#if defined(__cplusplus)
|
||||||
enum { kTableSize = kNumChannels * kNumGaussians };
|
#define CONSTEXPR_INT(x) constexpr int x
|
||||||
enum { kMinEnergy = 10 }; // Minimum energy required to trigger audio signal.
|
#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_ {
|
typedef struct VadInstT_ {
|
||||||
int vad;
|
int vad;
|
||||||
|
|
|
@ -18,13 +18,13 @@ namespace webrtc {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
enum { kSpectrumSize = 65 };
|
constexpr int kSpectrumSize = 65;
|
||||||
// Delay history sizes.
|
// Delay history sizes.
|
||||||
enum { kMaxDelay = 100 };
|
constexpr int kMaxDelay = 100;
|
||||||
enum { kLookahead = 10 };
|
constexpr int kLookahead = 10;
|
||||||
enum { kHistorySize = kMaxDelay + kLookahead };
|
constexpr int kHistorySize = kMaxDelay + kLookahead;
|
||||||
// Length of binary spectrum sequence.
|
// Length of binary spectrum sequence.
|
||||||
enum { kSequenceLength = 400 };
|
constexpr int kSequenceLength = 400;
|
||||||
|
|
||||||
const int kDifferentHistorySize = 3;
|
const int kDifferentHistorySize = 3;
|
||||||
const int kDifferentLookahead = 1;
|
const int kDifferentLookahead = 1;
|
||||||
|
|
|
@ -37,12 +37,6 @@ static const size_t kNalHeaderSize = 1;
|
||||||
static const size_t kFuAHeaderSize = 2;
|
static const size_t kFuAHeaderSize = 2;
|
||||||
static const size_t kLengthFieldSize = 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
|
} // namespace
|
||||||
|
|
||||||
RtpPacketizerH264::RtpPacketizerH264(rtc::ArrayView<const uint8_t> payload,
|
RtpPacketizerH264::RtpPacketizerH264(rtc::ArrayView<const uint8_t> payload,
|
||||||
|
@ -267,7 +261,8 @@ void RtpPacketizerH264::NextAggregatePacket(RtpPacketToSend* rtp_packet) {
|
||||||
PacketUnit* packet = &packets_.front();
|
PacketUnit* packet = &packets_.front();
|
||||||
RTC_CHECK(packet->first_fragment);
|
RTC_CHECK(packet->first_fragment);
|
||||||
// STAP-A NALU header.
|
// 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;
|
size_t index = kNalHeaderSize;
|
||||||
bool is_last_fragment = packet->last_fragment;
|
bool is_last_fragment = packet->last_fragment;
|
||||||
while (packet->aggregated) {
|
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
|
// We do not send original NALU header, so it will be replaced by the
|
||||||
// FU indicator header of the first packet.
|
// FU indicator header of the first packet.
|
||||||
uint8_t fu_indicator =
|
uint8_t fu_indicator =
|
||||||
(packet->header & (kFBit | kNriMask)) | H264::NaluType::kFuA;
|
(packet->header & (kH264FBit | kH264NriMask)) | H264::NaluType::kFuA;
|
||||||
uint8_t fu_header = 0;
|
uint8_t fu_header = 0;
|
||||||
|
|
||||||
// S | E | R | 5 bit type.
|
// S | E | R | 5 bit type.
|
||||||
fu_header |= (packet->first_fragment ? kSBit : 0);
|
fu_header |= (packet->first_fragment ? kH264SBit : 0);
|
||||||
fu_header |= (packet->last_fragment ? kEBit : 0);
|
fu_header |= (packet->last_fragment ? kH264EBit : 0);
|
||||||
uint8_t type = packet->header & kTypeMask;
|
uint8_t type = packet->header & kH264TypeMask;
|
||||||
fu_header |= type;
|
fu_header |= type;
|
||||||
rtc::ArrayView<const uint8_t> fragment = packet->source_fragment;
|
rtc::ArrayView<const uint8_t> fragment = packet->source_fragment;
|
||||||
uint8_t* buffer =
|
uint8_t* buffer =
|
||||||
|
|
|
@ -26,6 +26,16 @@
|
||||||
|
|
||||||
namespace webrtc {
|
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 {
|
class RtpPacketizerH264 : public RtpPacketizer {
|
||||||
public:
|
public:
|
||||||
// Initialize with payload from encoder.
|
// Initialize with payload from encoder.
|
||||||
|
|
|
@ -50,12 +50,6 @@ enum Nalu {
|
||||||
static const size_t kNalHeaderSize = 1;
|
static const size_t kNalHeaderSize = 1;
|
||||||
static const size_t kFuAHeaderSize = 2;
|
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.
|
// Creates Buffer that looks like nal unit of given size.
|
||||||
rtc::Buffer GenerateNalUnit(size_t size) {
|
rtc::Buffer GenerateNalUnit(size_t size) {
|
||||||
RTC_CHECK_GT(size, 0);
|
RTC_CHECK_GT(size, 0);
|
||||||
|
@ -359,13 +353,13 @@ TEST(RtpPacketizerH264Test, MixedStapAFUA) {
|
||||||
ASSERT_THAT(packets, SizeIs(3));
|
ASSERT_THAT(packets, SizeIs(3));
|
||||||
// First expect two FU-A packets.
|
// First expect two FU-A packets.
|
||||||
EXPECT_THAT(packets[0].payload().subview(0, kFuAHeaderSize),
|
EXPECT_THAT(packets[0].payload().subview(0, kFuAHeaderSize),
|
||||||
ElementsAre(kFuA, FuDefs::kSBit | nalus[0][0]));
|
ElementsAre(kFuA, kH264SBit | nalus[0][0]));
|
||||||
EXPECT_THAT(
|
EXPECT_THAT(
|
||||||
packets[0].payload().subview(kFuAHeaderSize),
|
packets[0].payload().subview(kFuAHeaderSize),
|
||||||
ElementsAreArray(nalus[0].data() + kNalHeaderSize, kFuaPayloadSize));
|
ElementsAreArray(nalus[0].data() + kNalHeaderSize, kFuaPayloadSize));
|
||||||
|
|
||||||
EXPECT_THAT(packets[1].payload().subview(0, kFuAHeaderSize),
|
EXPECT_THAT(packets[1].payload().subview(0, kFuAHeaderSize),
|
||||||
ElementsAre(kFuA, FuDefs::kEBit | nalus[0][0]));
|
ElementsAre(kFuA, kH264EBit | nalus[0][0]));
|
||||||
EXPECT_THAT(
|
EXPECT_THAT(
|
||||||
packets[1].payload().subview(kFuAHeaderSize),
|
packets[1].payload().subview(kFuAHeaderSize),
|
||||||
ElementsAreArray(nalus[0].data() + kNalHeaderSize + kFuaPayloadSize,
|
ElementsAreArray(nalus[0].data() + kNalHeaderSize + kFuaPayloadSize,
|
||||||
|
@ -426,11 +420,11 @@ std::vector<int> TestFua(size_t frame_payload_size,
|
||||||
payload_sizes.push_back(payload.size() - kFuAHeaderSize);
|
payload_sizes.push_back(payload.size() - kFuAHeaderSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPECT_TRUE(fua_header.front() & FuDefs::kSBit);
|
EXPECT_TRUE(fua_header.front() & kH264SBit);
|
||||||
EXPECT_TRUE(fua_header.back() & FuDefs::kEBit);
|
EXPECT_TRUE(fua_header.back() & kH264EBit);
|
||||||
// Clear S and E bits before testing all are duplicating same original header.
|
// Clear S and E bits before testing all are duplicating same original header.
|
||||||
fua_header.front() &= ~FuDefs::kSBit;
|
fua_header.front() &= ~kH264SBit;
|
||||||
fua_header.back() &= ~FuDefs::kEBit;
|
fua_header.back() &= ~kH264EBit;
|
||||||
EXPECT_THAT(fua_header, Each(Eq((kFuA << 8) | nalu[0][0])));
|
EXPECT_THAT(fua_header, Each(Eq((kFuA << 8) | nalu[0][0])));
|
||||||
|
|
||||||
return payload_sizes;
|
return payload_sizes;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "common_video/h264/sps_parser.h"
|
#include "common_video/h264/sps_parser.h"
|
||||||
#include "common_video/h264/sps_vui_rewriter.h"
|
#include "common_video/h264/sps_vui_rewriter.h"
|
||||||
#include "modules/rtp_rtcp/source/byte_io.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 "modules/rtp_rtcp/source/video_rtp_depacketizer.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/copy_on_write_buffer.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 kLengthFieldSize = 2;
|
||||||
constexpr size_t kStapAHeaderSize = kNalHeaderSize + kLengthFieldSize;
|
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.
|
// TODO(pbos): Avoid parsing this here as well as inside the jitter buffer.
|
||||||
bool ParseStapAStartOffsets(const uint8_t* nalu_ptr,
|
bool ParseStapAStartOffsets(const uint8_t* nalu_ptr,
|
||||||
size_t length_remaining,
|
size_t length_remaining,
|
||||||
|
@ -81,7 +76,7 @@ absl::optional<VideoRtpDepacketizer::ParsedRtpPayload> ProcessStapAOrSingleNalu(
|
||||||
|
|
||||||
const uint8_t* nalu_start = payload_data + kNalHeaderSize;
|
const uint8_t* nalu_start = payload_data + kNalHeaderSize;
|
||||||
const size_t nalu_length = rtp_payload.size() - 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;
|
std::vector<size_t> nalu_start_offsets;
|
||||||
if (nal_type == H264::NaluType::kStapA) {
|
if (nal_type == H264::NaluType::kStapA) {
|
||||||
// Skip the StapA header (StapA NAL type + length).
|
// Skip the StapA header (StapA NAL type + length).
|
||||||
|
@ -96,7 +91,7 @@ absl::optional<VideoRtpDepacketizer::ParsedRtpPayload> ProcessStapAOrSingleNalu(
|
||||||
}
|
}
|
||||||
|
|
||||||
h264_header.packetization_type = kH264StapA;
|
h264_header.packetization_type = kH264StapA;
|
||||||
nal_type = payload_data[kStapAHeaderSize] & kTypeMask;
|
nal_type = payload_data[kStapAHeaderSize] & kH264TypeMask;
|
||||||
} else {
|
} else {
|
||||||
h264_header.packetization_type = kH264SingleNalu;
|
h264_header.packetization_type = kH264SingleNalu;
|
||||||
nalu_start_offsets.push_back(0);
|
nalu_start_offsets.push_back(0);
|
||||||
|
@ -117,7 +112,7 @@ absl::optional<VideoRtpDepacketizer::ParsedRtpPayload> ProcessStapAOrSingleNalu(
|
||||||
}
|
}
|
||||||
|
|
||||||
NaluInfo nalu;
|
NaluInfo nalu;
|
||||||
nalu.type = payload_data[start_offset] & kTypeMask;
|
nalu.type = payload_data[start_offset] & kH264TypeMask;
|
||||||
nalu.sps_id = -1;
|
nalu.sps_id = -1;
|
||||||
nalu.pps_id = -1;
|
nalu.pps_id = -1;
|
||||||
start_offset += H264::kNaluTypeSize;
|
start_offset += H264::kNaluTypeSize;
|
||||||
|
@ -241,9 +236,9 @@ absl::optional<VideoRtpDepacketizer::ParsedRtpPayload> ParseFuaNalu(
|
||||||
}
|
}
|
||||||
absl::optional<VideoRtpDepacketizer::ParsedRtpPayload> parsed_payload(
|
absl::optional<VideoRtpDepacketizer::ParsedRtpPayload> parsed_payload(
|
||||||
absl::in_place);
|
absl::in_place);
|
||||||
uint8_t fnri = rtp_payload.cdata()[0] & (kFBit | kNriMask);
|
uint8_t fnri = rtp_payload.cdata()[0] & (kH264FBit | kH264NriMask);
|
||||||
uint8_t original_nal_type = rtp_payload.cdata()[1] & kTypeMask;
|
uint8_t original_nal_type = rtp_payload.cdata()[1] & kH264TypeMask;
|
||||||
bool first_fragment = (rtp_payload.cdata()[1] & kSBit) > 0;
|
bool first_fragment = (rtp_payload.cdata()[1] & kH264SBit) > 0;
|
||||||
NaluInfo nalu;
|
NaluInfo nalu;
|
||||||
nalu.type = original_nal_type;
|
nalu.type = original_nal_type;
|
||||||
nalu.sps_id = -1;
|
nalu.sps_id = -1;
|
||||||
|
@ -300,7 +295,7 @@ VideoRtpDepacketizerH264::Parse(rtc::CopyOnWriteBuffer rtp_payload) {
|
||||||
return absl::nullopt;
|
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) {
|
if (nal_type == H264::NaluType::kFuA) {
|
||||||
// Fragmented NAL units (FU-A).
|
// Fragmented NAL units (FU-A).
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "common_video/h264/h264_common.h"
|
#include "common_video/h264/h264_common.h"
|
||||||
#include "modules/rtp_rtcp/mocks/mock_rtp_rtcp.h"
|
#include "modules/rtp_rtcp/mocks/mock_rtp_rtcp.h"
|
||||||
#include "modules/rtp_rtcp/source/byte_io.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 "rtc_base/copy_on_write_buffer.h"
|
||||||
#include "test/gmock.h"
|
#include "test/gmock.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
|
@ -42,12 +43,6 @@ enum Nalu {
|
||||||
kFuA = 28
|
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,
|
constexpr uint8_t kOriginalSps[] = {kSps, 0x00, 0x00, 0x03, 0x03,
|
||||||
0xF4, 0x05, 0x03, 0xC7, 0xC0};
|
0xF4, 0x05, 0x03, 0xC7, 0xC0};
|
||||||
constexpr uint8_t kRewrittenSps[] = {kSps, 0x00, 0x00, 0x03, 0x03,
|
constexpr uint8_t kRewrittenSps[] = {kSps, 0x00, 0x00, 0x03, 0x03,
|
||||||
|
@ -294,7 +289,7 @@ TEST(VideoRtpDepacketizerH264Test, FuA) {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
uint8_t packet1[] = {
|
uint8_t packet1[] = {
|
||||||
kFuA, // F=0, NRI=0, Type=28.
|
kFuA, // F=0, NRI=0, Type=28.
|
||||||
kSBit | kIdr, // FU header.
|
kH264SBit | kIdr, // FU header.
|
||||||
0x85, 0xB8, 0x0, 0x4, 0x0, 0x0, 0x13, 0x93, 0x12, 0x0 // Payload.
|
0x85, 0xB8, 0x0, 0x4, 0x0, 0x0, 0x13, 0x93, 0x12, 0x0 // Payload.
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
@ -310,7 +305,7 @@ TEST(VideoRtpDepacketizerH264Test, FuA) {
|
||||||
|
|
||||||
uint8_t packet3[] = {
|
uint8_t packet3[] = {
|
||||||
kFuA, // F=0, NRI=0, Type=28.
|
kFuA, // F=0, NRI=0, Type=28.
|
||||||
kEBit | kIdr, // FU header.
|
kH264EBit | kIdr, // FU header.
|
||||||
0x03 // Payload.
|
0x03 // Payload.
|
||||||
};
|
};
|
||||||
const uint8_t kExpected3[] = {0x03};
|
const uint8_t kExpected3[] = {0x03};
|
||||||
|
|
Loading…
Reference in a new issue