VoE: cleanup VoENetwork implementation
Changes: 1. Documented return values of VoENetwork methods. 2. In VoENetworkImpl: replaced calls to SetLastError() with LOG_F(). SetLastError() is not used anymore because no one is calling LastError() to check for last error. Also, its usage is being removed in Video Engine and we want to be consistent. 3. In VoENetworkImpl: removed WEBRTC_TRACE() usage. 4. In VoENetworkImpl: replaced some defensive code with assert(). We are now assuming that the caller has called VoEBase::Init() where needed. We are also assuming that it is invalid to pass nullptr where data is expected. 5. Updated unit tests accordingly. R=henrika@webrtc.org, kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/53369004 Cr-Commit-Position: refs/heads/master@{#9145}
This commit is contained in:
@@ -55,16 +55,17 @@ class WEBRTC_DLLEXPORT VoENetwork {
|
||||
virtual int Release() = 0;
|
||||
|
||||
// Installs and enables a user-defined external transport protocol for a
|
||||
// specified |channel|.
|
||||
// specified |channel|. Returns -1 in case of an error, 0 otherwise.
|
||||
virtual int RegisterExternalTransport(int channel, Transport& transport) = 0;
|
||||
|
||||
// Removes and disables a user-defined external transport protocol for a
|
||||
// specified |channel|.
|
||||
// specified |channel|. Returns -1 in case of an error, 0 otherwise.
|
||||
virtual int DeRegisterExternalTransport(int channel) = 0;
|
||||
|
||||
// The packets received from the network should be passed to this
|
||||
// function when external transport is enabled. Note that the data
|
||||
// including the RTP-header must also be given to the VoiceEngine.
|
||||
// Returns -1 in case of an error, 0 otherwise.
|
||||
virtual int ReceivedRTPPacket(int channel,
|
||||
const void* data,
|
||||
size_t length) = 0;
|
||||
@@ -78,6 +79,7 @@ class WEBRTC_DLLEXPORT VoENetwork {
|
||||
// The packets received from the network should be passed to this
|
||||
// function when external transport is enabled. Note that the data
|
||||
// including the RTCP-header must also be given to the VoiceEngine.
|
||||
// Returns -1 in case of an error, 0 otherwise.
|
||||
virtual int ReceivedRTCPPacket(int channel,
|
||||
const void* data,
|
||||
size_t length) = 0;
|
||||
|
||||
@@ -325,29 +325,30 @@ int VoEBaseImpl::Init(AudioDeviceModule* external_adm,
|
||||
shared_->SetLastError(VE_APM_ERROR);
|
||||
// Configure AudioProcessing components.
|
||||
if (audioproc->high_pass_filter()->Enable(true) != 0) {
|
||||
LOG_FERR1(LS_ERROR, high_pass_filter()->Enable, true);
|
||||
LOG_F(LS_ERROR) << "Failed to enable high pass filter.";
|
||||
return -1;
|
||||
}
|
||||
if (audioproc->echo_cancellation()->enable_drift_compensation(false) != 0) {
|
||||
LOG_FERR1(LS_ERROR, enable_drift_compensation, false);
|
||||
LOG_F(LS_ERROR) << "Failed to disable drift compensation.";
|
||||
return -1;
|
||||
}
|
||||
if (audioproc->noise_suppression()->set_level(kDefaultNsMode) != 0) {
|
||||
LOG_FERR1(LS_ERROR, noise_suppression()->set_level, kDefaultNsMode);
|
||||
LOG_F(LS_ERROR) << "Failed to set noise suppression level: "
|
||||
<< kDefaultNsMode;
|
||||
return -1;
|
||||
}
|
||||
GainControl* agc = audioproc->gain_control();
|
||||
if (agc->set_analog_level_limits(kMinVolumeLevel, kMaxVolumeLevel) != 0) {
|
||||
LOG_FERR2(LS_ERROR, agc->set_analog_level_limits, kMinVolumeLevel,
|
||||
kMaxVolumeLevel);
|
||||
LOG_F(LS_ERROR) << "Failed to set analog level limits with minimum: "
|
||||
<< kMinVolumeLevel << " and maximum: " << kMaxVolumeLevel;
|
||||
return -1;
|
||||
}
|
||||
if (agc->set_mode(kDefaultAgcMode) != 0) {
|
||||
LOG_FERR1(LS_ERROR, agc->set_mode, kDefaultAgcMode);
|
||||
LOG_F(LS_ERROR) << "Failed to set mode: " << kDefaultAgcMode;
|
||||
return -1;
|
||||
}
|
||||
if (agc->Enable(kDefaultAgcState) != 0) {
|
||||
LOG_FERR1(LS_ERROR, agc->Enable, kDefaultAgcState);
|
||||
LOG_F(LS_ERROR) << "Failed to set agc state: " << kDefaultAgcState;
|
||||
return -1;
|
||||
}
|
||||
shared_->SetLastError(0); // Clear error state.
|
||||
@@ -356,7 +357,7 @@ int VoEBaseImpl::Init(AudioDeviceModule* external_adm,
|
||||
bool agc_enabled =
|
||||
agc->mode() == GainControl::kAdaptiveAnalog && agc->is_enabled();
|
||||
if (shared_->audio_device()->SetAGC(agc_enabled) != 0) {
|
||||
LOG_FERR1(LS_ERROR, audio_device()->SetAGC, agc_enabled);
|
||||
LOG_F(LS_ERROR) << "Failed to set agc to enabled: " << agc_enabled;
|
||||
shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR);
|
||||
// TODO(ajm): No error return here due to
|
||||
// https://code.google.com/p/webrtc/issues/detail?id=1464
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "webrtc/voice_engine/voe_network_impl.h"
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/base/format_macros.h"
|
||||
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
|
||||
#include "webrtc/system_wrappers/interface/logging.h"
|
||||
@@ -21,8 +22,8 @@
|
||||
namespace webrtc {
|
||||
|
||||
VoENetwork* VoENetwork::GetInterface(VoiceEngine* voiceEngine) {
|
||||
if (NULL == voiceEngine) {
|
||||
return NULL;
|
||||
if (!voiceEngine) {
|
||||
return nullptr;
|
||||
}
|
||||
VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
|
||||
s->AddRef();
|
||||
@@ -30,47 +31,28 @@ VoENetwork* VoENetwork::GetInterface(VoiceEngine* voiceEngine) {
|
||||
}
|
||||
|
||||
VoENetworkImpl::VoENetworkImpl(voe::SharedData* shared) : _shared(shared) {
|
||||
WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
||||
"VoENetworkImpl() - ctor");
|
||||
}
|
||||
|
||||
VoENetworkImpl::~VoENetworkImpl() {
|
||||
WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
||||
"~VoENetworkImpl() - dtor");
|
||||
}
|
||||
VoENetworkImpl::~VoENetworkImpl() = default;
|
||||
|
||||
int VoENetworkImpl::RegisterExternalTransport(int channel,
|
||||
Transport& transport) {
|
||||
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
||||
"SetExternalTransport(channel=%d, transport=0x%x)", channel,
|
||||
&transport);
|
||||
if (!_shared->statistics().Initialized()) {
|
||||
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
||||
return -1;
|
||||
}
|
||||
DCHECK(_shared->statistics().Initialized());
|
||||
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
||||
voe::Channel* channelPtr = ch.channel();
|
||||
if (channelPtr == NULL) {
|
||||
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
||||
"SetExternalTransport() failed to locate channel");
|
||||
if (!channelPtr) {
|
||||
LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
|
||||
return -1;
|
||||
}
|
||||
return channelPtr->RegisterExternalTransport(transport);
|
||||
}
|
||||
|
||||
int VoENetworkImpl::DeRegisterExternalTransport(int channel) {
|
||||
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
||||
"DeRegisterExternalTransport(channel=%d)", channel);
|
||||
if (!_shared->statistics().Initialized()) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
||||
"DeRegisterExternalTransport() - invalid state");
|
||||
}
|
||||
CHECK(_shared->statistics().Initialized());
|
||||
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
||||
voe::Channel* channelPtr = ch.channel();
|
||||
if (channelPtr == NULL) {
|
||||
_shared->SetLastError(
|
||||
VE_CHANNEL_NOT_VALID, kTraceError,
|
||||
"DeRegisterExternalTransport() failed to locate channel");
|
||||
if (!channelPtr) {
|
||||
LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
|
||||
return -1;
|
||||
}
|
||||
return channelPtr->DeRegisterExternalTransport();
|
||||
@@ -86,36 +68,21 @@ int VoENetworkImpl::ReceivedRTPPacket(int channel,
|
||||
const void* data,
|
||||
size_t length,
|
||||
const PacketTime& packet_time) {
|
||||
WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
||||
"ReceivedRTPPacket(channel=%d, length=%" PRIuS ")", channel,
|
||||
length);
|
||||
if (!_shared->statistics().Initialized()) {
|
||||
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
||||
return -1;
|
||||
}
|
||||
CHECK(_shared->statistics().Initialized());
|
||||
CHECK(data);
|
||||
// L16 at 32 kHz, stereo, 10 ms frames (+12 byte RTP header) -> 1292 bytes
|
||||
if ((length < 12) || (length > 1292)) {
|
||||
_shared->SetLastError(VE_INVALID_PACKET);
|
||||
LOG(LS_ERROR) << "Invalid packet length: " << length;
|
||||
return -1;
|
||||
}
|
||||
if (NULL == data) {
|
||||
_shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
|
||||
"ReceivedRTPPacket() invalid data vector");
|
||||
LOG_F(LS_ERROR) << "Invalid packet length: " << length;
|
||||
return -1;
|
||||
}
|
||||
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
||||
voe::Channel* channelPtr = ch.channel();
|
||||
if (channelPtr == NULL) {
|
||||
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
||||
"ReceivedRTPPacket() failed to locate channel");
|
||||
if (!channelPtr) {
|
||||
LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!channelPtr->ExternalTransport()) {
|
||||
_shared->SetLastError(
|
||||
VE_INVALID_OPERATION, kTraceError,
|
||||
"ReceivedRTPPacket() external transport is not enabled");
|
||||
LOG_F(LS_ERROR) << "No external transport for channel: " << channel;
|
||||
return -1;
|
||||
}
|
||||
return channelPtr->ReceivedRTPPacket((const int8_t*)data, length,
|
||||
@@ -125,36 +92,23 @@ int VoENetworkImpl::ReceivedRTPPacket(int channel,
|
||||
int VoENetworkImpl::ReceivedRTCPPacket(int channel,
|
||||
const void* data,
|
||||
size_t length) {
|
||||
WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
||||
"ReceivedRTCPPacket(channel=%d, length=%" PRIuS ")", channel,
|
||||
length);
|
||||
if (!_shared->statistics().Initialized()) {
|
||||
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
||||
return -1;
|
||||
}
|
||||
CHECK(_shared->statistics().Initialized());
|
||||
CHECK(data);
|
||||
if (length < 4) {
|
||||
_shared->SetLastError(VE_INVALID_PACKET, kTraceError,
|
||||
"ReceivedRTCPPacket() invalid packet length");
|
||||
return -1;
|
||||
}
|
||||
if (NULL == data) {
|
||||
_shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
|
||||
"ReceivedRTCPPacket() invalid data vector");
|
||||
LOG_F(LS_ERROR) << "Invalid packet length: " << length;
|
||||
return -1;
|
||||
}
|
||||
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
||||
voe::Channel* channelPtr = ch.channel();
|
||||
if (channelPtr == NULL) {
|
||||
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
||||
"ReceivedRTCPPacket() failed to locate channel");
|
||||
if (!channelPtr) {
|
||||
LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
|
||||
return -1;
|
||||
}
|
||||
if (!channelPtr->ExternalTransport()) {
|
||||
_shared->SetLastError(
|
||||
VE_INVALID_OPERATION, kTraceError,
|
||||
"ReceivedRTCPPacket() external transport is not enabled");
|
||||
LOG_F(LS_ERROR) << "No external transport for channel: " << channel;
|
||||
return -1;
|
||||
}
|
||||
return channelPtr->ReceivedRTCPPacket((const int8_t*)data, length);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace webrtc {
|
||||
class VoENetworkImpl : public VoENetwork {
|
||||
public:
|
||||
int RegisterExternalTransport(int channel, Transport& transport) override;
|
||||
|
||||
int DeRegisterExternalTransport(int channel) override;
|
||||
|
||||
int ReceivedRTPPacket(int channel, const void* data, size_t length) override;
|
||||
|
||||
@@ -45,15 +45,6 @@ TEST_F(VoENetworkTest, RegisterAndDeRegisterExternalTransport) {
|
||||
EXPECT_EQ(0, network_->DeRegisterExternalTransport(channelID));
|
||||
}
|
||||
|
||||
TEST_F(VoENetworkTest, RegisterExternalTransportBeforeInitShouldFail) {
|
||||
EXPECT_NE(
|
||||
0, network_->RegisterExternalTransport(kNonExistingChannel, transport_));
|
||||
}
|
||||
|
||||
TEST_F(VoENetworkTest, DeRegisterExternalTransportBeforeInitShouldFail) {
|
||||
EXPECT_NE(0, network_->DeRegisterExternalTransport(kNonExistingChannel));
|
||||
}
|
||||
|
||||
TEST_F(VoENetworkTest,
|
||||
RegisterExternalTransportOnNonExistingChannelShouldFail) {
|
||||
EXPECT_EQ(0, base_->Init(&adm_, nullptr));
|
||||
@@ -80,10 +71,6 @@ TEST_F(VoENetworkTest, ReceivedRTPPacketWithJunkDataShouldFail) {
|
||||
sizeof(kPacketJunk)));
|
||||
}
|
||||
|
||||
TEST_F(VoENetworkTest, ReceivedRTPPacketBeforeInitShouldFail) {
|
||||
EXPECT_EQ(-1, network_->ReceivedRTPPacket(0, kPacket, sizeof(kPacket)));
|
||||
}
|
||||
|
||||
TEST_F(VoENetworkTest, ReceivedRTPPacketOnNonExistingChannelShouldFail) {
|
||||
EXPECT_EQ(0, base_->Init(&adm_, nullptr));
|
||||
EXPECT_EQ(-1, network_->ReceivedRTPPacket(kNonExistingChannel, kPacket,
|
||||
@@ -110,11 +97,6 @@ TEST_F(VoENetworkTest, ReceivedTooLargeRTPPacketShouldFail) {
|
||||
channelID, kPacket, kMaxValidSizeOfRtpPacketInBytes + 1));
|
||||
}
|
||||
|
||||
TEST_F(VoENetworkTest, ReceivedRTPPacketWithNullDataShouldFail) {
|
||||
int channelID = CreateChannelAndRegisterExternalTransport();
|
||||
EXPECT_EQ(-1, network_->ReceivedRTPPacket(channelID, nullptr, 0));
|
||||
}
|
||||
|
||||
TEST_F(VoENetworkTest, ReceivedRTCPPacketWithJunkDataShouldFail) {
|
||||
int channelID = CreateChannelAndRegisterExternalTransport();
|
||||
EXPECT_EQ(0, network_->ReceivedRTCPPacket(channelID, kPacketJunk,
|
||||
@@ -122,11 +104,6 @@ TEST_F(VoENetworkTest, ReceivedRTCPPacketWithJunkDataShouldFail) {
|
||||
EXPECT_EQ(VE_SOCKET_TRANSPORT_MODULE_ERROR, base_->LastError());
|
||||
}
|
||||
|
||||
TEST_F(VoENetworkTest, ReceivedRTCPPacketBeforeInitShouldFail) {
|
||||
EXPECT_EQ(-1, network_->ReceivedRTCPPacket(kNonExistingChannel, kPacket,
|
||||
sizeof(kPacket)));
|
||||
}
|
||||
|
||||
TEST_F(VoENetworkTest, ReceivedRTCPPacketOnNonExistingChannelShouldFail) {
|
||||
EXPECT_EQ(0, base_->Init(&adm_, nullptr));
|
||||
EXPECT_EQ(-1, network_->ReceivedRTCPPacket(kNonExistingChannel, kPacket,
|
||||
@@ -147,9 +124,4 @@ TEST_F(VoENetworkTest, ReceivedTooSmallRTCPPacket4ShouldFail) {
|
||||
channelID, kPacket, kMinValidSizeOfRtcpPacketInBytes - 1));
|
||||
}
|
||||
|
||||
TEST_F(VoENetworkTest, ReceivedRTCPPacketWithNullDataShouldFail) {
|
||||
int channelID = CreateChannelAndRegisterExternalTransport();
|
||||
EXPECT_EQ(-1, network_->ReceivedRTCPPacket(channelID, nullptr, 0));
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include "webrtc/common_types.h"
|
||||
#include "webrtc/engine_configurations.h"
|
||||
#include "webrtc/modules/audio_processing/include/audio_processing.h"
|
||||
#include "webrtc/system_wrappers/interface/logging.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Enumerators
|
||||
|
||||
Reference in New Issue
Block a user