Make AudioFrameType an enum class, and move to audio_coding_module_typedefs.h

Bug: webrtc:5876
Change-Id: I0c92f9410fcf0832bfa321229b3437134255dba6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128085
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27190}
This commit is contained in:
Niels Möller
2019-03-19 14:10:16 +01:00
committed by Commit Bot
parent 1d14af908e
commit c936cb6a86
21 changed files with 91 additions and 102 deletions

View File

@ -15,11 +15,11 @@ if (rtc_enable_protobuf) {
visibility = [ ":*" ]
rtc_source_set("audio_coding_module_typedefs") {
visibility += [ "*" ]
sources = [
"include/audio_coding_module_typedefs.h",
]
deps = [
"../..:webrtc_common",
"../../rtc_base:deprecation",
]
}
@ -44,7 +44,6 @@ rtc_static_library("audio_coding") {
":neteq",
"..:module_api",
"..:module_api_public",
"../..:webrtc_common",
"../../api:array_view",
"../../api/audio:audio_frame_api",
"../../api/audio_codecs:audio_codecs_api",
@ -137,7 +136,6 @@ rtc_static_library("g711") {
deps = [
":legacy_encoded_audio_frame",
"../..:webrtc_common",
"../../api:array_view",
"../../api/audio_codecs:audio_codecs_api",
"../../rtc_base:checks",
@ -155,7 +153,6 @@ rtc_source_set("g711_c") {
"codecs/g711/g711_interface.h",
]
deps = [
"../..:webrtc_common",
"../third_party/g711:g711_3p",
]
}
@ -172,7 +169,6 @@ rtc_static_library("g722") {
deps = [
":legacy_encoded_audio_frame",
"../..:webrtc_common",
"../../api:array_view",
"../../api/audio_codecs:audio_codecs_api",
"../../api/audio_codecs/g722:audio_encoder_g722_config",
@ -191,7 +187,6 @@ rtc_source_set("g722_c") {
"codecs/g722/g722_interface.h",
]
deps = [
"../..:webrtc_common",
"../third_party/g722:g722_3p",
]
}
@ -208,7 +203,6 @@ rtc_static_library("ilbc") {
deps = [
":legacy_encoded_audio_frame",
"../..:webrtc_common",
"../../api:array_view",
"../../api/audio_codecs:audio_codecs_api",
"../../api/audio_codecs/ilbc:audio_encoder_ilbc_config",
@ -366,7 +360,6 @@ rtc_source_set("ilbc_c") {
]
deps = [
"../..:webrtc_common",
"../../api/audio_codecs:audio_codecs_api",
"../../common_audio",
"../../common_audio:common_audio_c",
@ -390,7 +383,6 @@ rtc_static_library("isac_common") {
]
deps = [
":isac_bwinfo",
"../..:webrtc_common",
"../../api:scoped_refptr",
"../../api/audio_codecs:audio_codecs_api",
"../../rtc_base:checks",
@ -500,7 +492,6 @@ rtc_static_library("isac_c") {
deps = [
":isac_bwinfo",
":isac_vad",
"../..:webrtc_common",
"../../common_audio",
"../../common_audio:common_audio_c",
"../../rtc_base:checks",
@ -615,7 +606,6 @@ rtc_source_set("isac_fix_c") {
deps = [
":isac_bwinfo",
":isac_common",
"../..:webrtc_common",
"../../api/audio_codecs:audio_codecs_api",
"../../common_audio",
"../../common_audio:common_audio_c",
@ -726,7 +716,6 @@ rtc_static_library("pcm16b") {
deps = [
":g711",
":legacy_encoded_audio_frame",
"../..:webrtc_common",
"../../api:array_view",
"../../api/audio_codecs:audio_codecs_api",
"../../rtc_base:checks",
@ -743,10 +732,6 @@ rtc_source_set("pcm16b_c") {
"codecs/pcm16b/pcm16b.c",
"codecs/pcm16b/pcm16b.h",
]
deps = [
"../..:webrtc_common",
]
}
rtc_static_library("webrtc_opus") {
@ -761,7 +746,6 @@ rtc_static_library("webrtc_opus") {
deps = [
":audio_network_adaptor",
"../..:webrtc_common",
"../../api:array_view",
"../../api/audio_codecs:audio_codecs_api",
"../../api/audio_codecs/opus:audio_encoder_opus_config",
@ -808,7 +792,6 @@ rtc_source_set("webrtc_opus_c") {
}
deps = [
"../..:webrtc_common",
"../../rtc_base:checks",
"../../rtc_base:rtc_base_approved",
]
@ -877,7 +860,6 @@ rtc_static_library("audio_network_adaptor") {
]
deps = [
"../..:webrtc_common",
"../../api/audio_codecs:audio_codecs_api",
"../../common_audio",
"../../logging:rtc_event_audio",
@ -977,7 +959,6 @@ rtc_static_library("neteq") {
":webrtc_cng",
"..:module_api",
"..:module_api_public",
"../..:webrtc_common",
"../../api:array_view",
"../../api:libjingle_peerconnection_api",
"../../api:scoped_refptr",
@ -1023,7 +1004,6 @@ rtc_source_set("neteq_tools_minimal") {
deps = [
":neteq",
"../..:webrtc_common",
"../../api:libjingle_peerconnection_api",
"../../api:neteq_simulator_api",
"../../api/audio:audio_frame_api",
@ -1058,7 +1038,6 @@ rtc_source_set("neteq_test_tools") {
deps = [
":pcm16b",
"../..:webrtc_common",
"../../api:array_view",
"../../api:libjingle_peerconnection_api",
"../../common_audio",
@ -1103,7 +1082,6 @@ rtc_source_set("neteq_tools") {
deps = [
"..:module_api",
"../..:webrtc_common",
"../../api:array_view",
"../../api/audio_codecs:audio_codecs_api",
"../../rtc_base:checks",
@ -1130,7 +1108,6 @@ rtc_source_set("neteq_input_audio_tools") {
]
deps = [
"../..:webrtc_common",
"../../common_audio",
"../../rtc_base:checks",
"../../rtc_base:rtc_base_approved",
@ -1166,7 +1143,6 @@ if (rtc_include_tests) {
audio_coding_deps = [
"../../common_audio",
"../../system_wrappers",
"../..:webrtc_common",
":audio_encoder_cng",
":g711",
":g722",
@ -1274,7 +1250,6 @@ if (rtc_include_tests) {
":red",
":webrtc_opus_c",
"..:module_api",
"../..:webrtc_common",
"../../api/audio:audio_frame_api",
"../../api/audio_codecs:audio_codecs_api",
"../../api/audio_codecs:builtin_audio_decoder_factory",
@ -1316,7 +1291,6 @@ if (rtc_include_tests) {
deps = [
":neteq_test_support",
":neteq_test_tools",
"../..:webrtc_common",
"../../api/audio_codecs/opus:audio_encoder_opus",
"../../rtc_base:rtc_base_approved",
"../../system_wrappers",
@ -1446,7 +1420,6 @@ if (rtc_include_tests) {
deps += [
":neteq",
":neteq_test_tools",
"../..:webrtc_common",
"../../api/audio_codecs:builtin_audio_decoder_factory",
"../../rtc_base:rtc_base_approved",
"../../test:audio_codec_mocks",
@ -1518,7 +1491,6 @@ if (rtc_include_tests) {
deps += [
":isac_fix",
":webrtc_opus",
"../..:webrtc_common",
"../../api:libjingle_peerconnection_api",
"../../rtc_base:rtc_base_approved",
"../../test:test_main",
@ -1539,7 +1511,6 @@ if (rtc_include_tests) {
":neteq",
":neteq_test_tools",
":pcm16b",
"../..:webrtc_common",
"../../api/audio:audio_frame_api",
"../../api/audio_codecs:audio_codecs_api",
"../../api/audio_codecs:builtin_audio_decoder_factory",
@ -1562,7 +1533,6 @@ if (rtc_include_tests) {
deps = [
":neteq",
":neteq_test_tools",
"../..:webrtc_common",
"../../api/audio_codecs:builtin_audio_decoder_factory",
"../../rtc_base:checks",
"../../rtc_base:rtc_base_approved",
@ -1672,7 +1642,6 @@ if (rtc_include_tests) {
deps = [
":neteq",
":neteq_test_support",
"../..:webrtc_common",
"../../rtc_base:rtc_base_approved",
"../../test:test_support",
]
@ -1690,7 +1659,6 @@ if (rtc_include_tests) {
":neteq",
":neteq_quality_test_support",
":neteq_tools",
"../..:webrtc_common",
"../../rtc_base:checks",
"../../rtc_base:rtc_base_approved",
"../../test:fileutils",
@ -1815,7 +1783,6 @@ if (rtc_include_tests) {
deps = [
":g722",
"../..:webrtc_common",
]
}
@ -1982,7 +1949,6 @@ if (rtc_include_tests) {
":webrtc_opus",
"..:module_api",
"..:module_api_public",
"../..:webrtc_common",
"../../api/audio:audio_frame_api",
"../../api/audio_codecs:audio_codecs_api",
"../../api/audio_codecs:builtin_audio_decoder_factory",

View File

@ -36,7 +36,7 @@ class AcmReceiverTestOldApi : public AudioPacketizationCallback,
: timestamp_(0),
packet_sent_(false),
last_packet_send_timestamp_(timestamp_),
last_frame_type_(kEmptyFrame) {
last_frame_type_(AudioFrameType::kEmptyFrame) {
config_.decoder_factory = decoder_factory_;
}
@ -109,7 +109,7 @@ class AcmReceiverTestOldApi : public AudioPacketizationCallback,
const uint8_t* payload_data,
size_t payload_len_bytes,
const RTPFragmentationHeader* fragmentation) override {
if (frame_type == kEmptyFrame)
if (frame_type == AudioFrameType::kEmptyFrame)
return 0;
rtp_header_.payloadType = payload_type;
@ -336,7 +336,7 @@ TEST_F(AcmReceiverTestOldApi, MAYBE_LastAudioCodec) {
SetEncoder(0, codecs.at(0), cng_payload_types)); // Enough to test
// with one codec.
ASSERT_TRUE(packet_sent_);
EXPECT_EQ(kAudioFrameCN, last_frame_type_);
EXPECT_EQ(AudioFrameType::kAudioFrameCN, last_frame_type_);
// Has received, only, DTX. Last Audio codec is undefined.
EXPECT_EQ(absl::nullopt, receiver_->LastDecoder());
@ -353,7 +353,7 @@ TEST_F(AcmReceiverTestOldApi, MAYBE_LastAudioCodec) {
// Sanity check if Actually an audio payload received, and it should be
// of type "speech."
ASSERT_TRUE(packet_sent_);
ASSERT_EQ(kAudioFrameSpeech, last_frame_type_);
ASSERT_EQ(AudioFrameType::kAudioFrameSpeech, last_frame_type_);
EXPECT_EQ(info_without_cng.sample_rate_hz,
receiver_->last_packet_sample_rate_hz());
@ -361,7 +361,7 @@ TEST_F(AcmReceiverTestOldApi, MAYBE_LastAudioCodec) {
// the expected codec. Encode repeatedly until a DTX is sent.
const AudioCodecInfo info_with_cng =
SetEncoder(payload_type, codecs.at(i), cng_payload_types);
while (last_frame_type_ != kAudioFrameCN) {
while (last_frame_type_ != AudioFrameType::kAudioFrameCN) {
packet_sent_ = false;
InsertOnePacketOfSilence(info_with_cng);
ASSERT_TRUE(packet_sent_);

View File

@ -44,7 +44,7 @@ AcmSendTestOldApi::AcmSendTestOldApi(InputAudioFile* audio_source,
static_cast<size_t>(source_rate_hz_ * kBlockSizeMs / 1000)),
codec_registered_(false),
test_duration_ms_(test_duration_ms),
frame_type_(kAudioFrameSpeech),
frame_type_(AudioFrameType::kAudioFrameSpeech),
payload_type_(0),
timestamp_(0),
sequence_number_(0) {

View File

@ -395,11 +395,12 @@ int32_t AudioCodingModuleImpl::Encode(const InputData& input_data) {
ConvertEncodedInfoToFragmentationHeader(encoded_info, &my_fragmentation);
AudioFrameType frame_type;
if (encode_buffer_.size() == 0 && encoded_info.send_even_if_empty) {
frame_type = kEmptyFrame;
frame_type = AudioFrameType::kEmptyFrame;
encoded_info.payload_type = previous_pltype;
} else {
RTC_DCHECK_GT(encode_buffer_.size(), 0);
frame_type = encoded_info.speech ? kAudioFrameSpeech : kAudioFrameCN;
frame_type = encoded_info.speech ? AudioFrameType::kAudioFrameSpeech
: AudioFrameType::kAudioFrameCN;
}
{

View File

@ -100,7 +100,7 @@ class PacketizationCallbackStubOldApi : public AudioPacketizationCallback {
public:
PacketizationCallbackStubOldApi()
: num_calls_(0),
last_frame_type_(kEmptyFrame),
last_frame_type_(AudioFrameType::kEmptyFrame),
last_payload_type_(-1),
last_timestamp_(0) {}
@ -350,11 +350,12 @@ TEST_F(AudioCodingModuleTestOldApi, TransportCallbackIsInvokedForEachPacket) {
for (int i = 0; i < kLoops; ++i) {
EXPECT_EQ(i / k10MsBlocksPerPacket, packet_cb_.num_calls());
if (packet_cb_.num_calls() > 0)
EXPECT_EQ(kAudioFrameSpeech, packet_cb_.last_frame_type());
EXPECT_EQ(AudioFrameType::kAudioFrameSpeech,
packet_cb_.last_frame_type());
InsertAudioAndVerifyEncoding();
}
EXPECT_EQ(kLoops / k10MsBlocksPerPacket, packet_cb_.num_calls());
EXPECT_EQ(kAudioFrameSpeech, packet_cb_.last_frame_type());
EXPECT_EQ(AudioFrameType::kAudioFrameSpeech, packet_cb_.last_frame_type());
}
#if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)
@ -431,12 +432,19 @@ class AudioCodingModuleTestWithComfortNoiseOldApi
const struct {
int ix;
AudioFrameType type;
} expectation[] = {
{2, kAudioFrameCN}, {5, kEmptyFrame}, {8, kEmptyFrame},
{11, kAudioFrameCN}, {14, kEmptyFrame}, {17, kEmptyFrame},
{20, kAudioFrameCN}, {23, kEmptyFrame}, {26, kEmptyFrame},
{29, kEmptyFrame}, {32, kAudioFrameCN}, {35, kEmptyFrame},
{38, kEmptyFrame}};
} expectation[] = {{2, AudioFrameType::kAudioFrameCN},
{5, AudioFrameType::kEmptyFrame},
{8, AudioFrameType::kEmptyFrame},
{11, AudioFrameType::kAudioFrameCN},
{14, AudioFrameType::kEmptyFrame},
{17, AudioFrameType::kEmptyFrame},
{20, AudioFrameType::kAudioFrameCN},
{23, AudioFrameType::kEmptyFrame},
{26, AudioFrameType::kEmptyFrame},
{29, AudioFrameType::kEmptyFrame},
{32, AudioFrameType::kAudioFrameCN},
{35, AudioFrameType::kEmptyFrame},
{38, AudioFrameType::kEmptyFrame}};
for (int i = 0; i < kLoops; ++i) {
int num_calls_before = packet_cb_.num_calls();
EXPECT_EQ(i / blocks_per_packet, num_calls_before);

View File

@ -33,6 +33,12 @@ enum ACMVADMode {
VADVeryAggr = 3
};
enum class AudioFrameType {
kEmptyFrame = 0,
kAudioFrameSpeech = 1,
kAudioFrameCN = 2,
};
///////////////////////////////////////////////////////////////////////////
//
// Enumeration of Opus mode for intended application.

View File

@ -13,7 +13,6 @@
#include "absl/memory/memory.h"
#include "api/audio/audio_frame.h"
#include "api/audio_codecs/audio_decoder.h"
#include "common_types.h" // NOLINT(build/include)
#include "modules/audio_coding/neteq/include/neteq.h"
#include "modules/audio_coding/neteq/tools/rtp_generator.h"

View File

@ -39,7 +39,7 @@ int32_t Channel::SendData(AudioFrameType frameType,
? timeStamp
: static_cast<uint32_t>(external_send_timestamp_);
if (frameType == kEmptyFrame) {
if (frameType == AudioFrameType::kEmptyFrame) {
// When frame is empty, we should not transmit it. The frame size of the
// next non-empty frame will be based on the previous frame size.
_useLastFrameSize = _lastFrameSizeSample > 0;

View File

@ -75,7 +75,7 @@ int32_t TestPack::SendData(AudioFrameType frame_type,
rtp_header.payloadType = payload_type;
rtp_header.timestamp = timestamp;
if (frame_type == kEmptyFrame) {
if (frame_type == AudioFrameType::kEmptyFrame) {
// Skip this frame.
return 0;
}

View File

@ -54,7 +54,7 @@ int32_t TestPackStereo::SendData(const AudioFrameType frame_type,
rtp_header.sequenceNumber = seq_no_++;
rtp_header.payloadType = payload_type;
rtp_header.timestamp = timestamp;
if (frame_type == kEmptyFrame) {
if (frame_type == AudioFrameType::kEmptyFrame) {
// Skip this frame
return 0;
}
@ -63,7 +63,7 @@ int32_t TestPackStereo::SendData(const AudioFrameType frame_type,
status =
receiver_acm_->IncomingPacket(payload_data, payload_size, rtp_header);
if (frame_type != kAudioFrameCN) {
if (frame_type != AudioFrameType::kAudioFrameCN) {
payload_size_ = static_cast<int>(payload_size);
} else {
payload_size_ = -1;

View File

@ -34,17 +34,18 @@ ActivityMonitor::ActivityMonitor() {
}
int32_t ActivityMonitor::InFrameType(AudioFrameType frame_type) {
counter_[frame_type]++;
counter_[static_cast<int>(frame_type)]++;
return 0;
}
void ActivityMonitor::PrintStatistics() {
printf("\n");
printf("kEmptyFrame %u\n", counter_[kEmptyFrame]);
printf("kAudioFrameSpeech %u\n", counter_[kAudioFrameSpeech]);
printf("kAudioFrameCN %u\n", counter_[kAudioFrameCN]);
printf("kVideoFrameKey %u\n", counter_[kVideoFrameKey]);
printf("kVideoFrameDelta %u\n", counter_[kVideoFrameDelta]);
printf("kEmptyFrame %u\n",
counter_[static_cast<int>(AudioFrameType::kEmptyFrame)]);
printf("kAudioFrameSpeech %u\n",
counter_[static_cast<int>(AudioFrameType::kAudioFrameSpeech)]);
printf("kAudioFrameCN %u\n",
counter_[static_cast<int>(AudioFrameType::kAudioFrameCN)]);
printf("\n\n");
}
@ -146,7 +147,7 @@ void TestVadDtx::Run(std::string in_filename,
monitor_->PrintStatistics();
#endif
uint32_t stats[5];
uint32_t stats[3];
monitor_->GetStatistics(stats);
monitor_->ResetStatistics();

View File

@ -34,9 +34,7 @@ class ActivityMonitor : public ACMVADCallback {
// 0 - kEmptyFrame
// 1 - kAudioFrameSpeech
// 2 - kAudioFrameCN
// 3 - kVideoFrameKey (not used by audio)
// 4 - kVideoFrameDelta (not used by audio)
uint32_t counter_[5];
uint32_t counter_[3];
};
// TestVadDtx is to verify that VAD/DTX perform as they should. It runs through
@ -64,8 +62,6 @@ class TestVadDtx {
// 0 - kEmptyFrame
// 1 - kAudioFrameSpeech
// 2 - kAudioFrameCN
// 3 - kVideoFrameKey (not used by audio)
// 4 - kVideoFrameDelta (not used by audio)
void Run(std::string in_filename,
int frequency,
int channels,

View File

@ -315,8 +315,8 @@ void OpusTest::Run(TestPackStereo* channel,
}
// Send data to the channel. "channel" will handle the loss simulation.
channel->SendData(kAudioFrameSpeech, payload_type_, rtp_timestamp_,
bitstream, bitstream_len_byte, NULL);
channel->SendData(AudioFrameType::kAudioFrameSpeech, payload_type_,
rtp_timestamp_, bitstream, bitstream_len_byte, NULL);
if (first_packet) {
first_packet = false;
start_time_stamp = rtp_timestamp_;