Remove VoENetwork

BUG=webrtc:4690

Review-Url: https://codereview.webrtc.org/3016543002
Cr-Commit-Position: refs/heads/master@{#19912}
This commit is contained in:
solenberg 2017-09-21 04:02:53 -07:00 committed by Commit Bot
parent 99a81b613d
commit 946d886187
11 changed files with 17 additions and 505 deletions

View File

@ -113,20 +113,6 @@ class MockVoiceEngine : public VoiceEngineImpl {
MOCK_METHOD1(StopSend, int(int channel));
MOCK_METHOD0(audio_transport, AudioTransport*());
// VoENetwork
MOCK_METHOD2(RegisterExternalTransport,
int(int channel, Transport& transport));
MOCK_METHOD1(DeRegisterExternalTransport, int(int channel));
MOCK_METHOD3(ReceivedRTPPacket,
int(int channel, const void* data, size_t length));
MOCK_METHOD4(ReceivedRTPPacket,
int(int channel,
const void* data,
size_t length,
const PacketTime& packet_time));
MOCK_METHOD3(ReceivedRTCPPacket,
int(int channel, const void* data, size_t length));
private:
// TODO(ossu): I'm not particularly happy about keeping the decoder factory
// here, but due to how gmock is implemented, I cannot just keep it in the

View File

@ -18,7 +18,6 @@ rtc_static_library("voice_engine") {
"channel_proxy.h",
"include/voe_base.h",
"include/voe_errors.h",
"include/voe_network.h",
"monitor_module.h",
"output_mixer.cc",
"output_mixer.h",
@ -34,8 +33,6 @@ rtc_static_library("voice_engine") {
"utility.h",
"voe_base_impl.cc",
"voe_base_impl.h",
"voe_network_impl.cc",
"voe_network_impl.h",
"voice_engine_defines.h",
"voice_engine_impl.cc",
"voice_engine_impl.h",
@ -139,9 +136,6 @@ if (rtc_include_tests) {
"transport_feedback_packet_loss_tracker_unittest.cc",
"utility_unittest.cc",
"voe_base_unittest.cc",
"voe_network_unittest.cc",
"voice_engine_fixture.cc",
"voice_engine_fixture.h",
]
data = [

View File

@ -1362,49 +1362,26 @@ int32_t Channel::DeRegisterExternalTransport() {
return 0;
}
// TODO(nisse): Delete this method together with ReceivedRTPPacket.
// It's a temporary hack to support both ReceivedRTPPacket and
// OnRtpPacket interfaces without too much code duplication.
bool Channel::OnRtpPacketWithHeader(const uint8_t* received_packet,
size_t length,
RTPHeader *header) {
// Store playout timestamp for the received RTP packet
UpdatePlayoutTimestamp(false);
header->payload_type_frequency =
rtp_payload_registry_->GetPayloadTypeFrequency(header->payloadType);
if (header->payload_type_frequency < 0)
return false;
bool in_order = IsPacketInOrder(*header);
rtp_receive_statistics_->IncomingPacket(
*header, length, IsPacketRetransmitted(*header, in_order));
rtp_payload_registry_->SetIncomingPayloadType(*header);
return ReceivePacket(received_packet, length, *header, in_order);
}
int32_t Channel::ReceivedRTPPacket(const uint8_t* received_packet,
size_t length,
const PacketTime& packet_time) {
WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId),
"Channel::ReceivedRTPPacket()");
RTPHeader header;
if (!rtp_header_parser_->Parse(received_packet, length, &header)) {
WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVoice, _channelId,
"Incoming packet: invalid RTP header");
return -1;
}
return OnRtpPacketWithHeader(received_packet, length, &header) ? 0 : -1;
}
void Channel::OnRtpPacket(const RtpPacketReceived& packet) {
WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId),
"Channel::ReceivedRTPPacket()");
"Channel::OnRtpPacket()");
RTPHeader header;
packet.GetHeader(&header);
OnRtpPacketWithHeader(packet.data(), packet.size(), &header);
// Store playout timestamp for the received RTP packet
UpdatePlayoutTimestamp(false);
header.payload_type_frequency =
rtp_payload_registry_->GetPayloadTypeFrequency(header.payloadType);
if (header.payload_type_frequency >= 0) {
bool in_order = IsPacketInOrder(header);
rtp_receive_statistics_->IncomingPacket(
header, packet.size(), IsPacketRetransmitted(header, in_order));
rtp_payload_registry_->SetIncomingPayloadType(header);
ReceivePacket(packet.data(), packet.size(), header, in_order);
}
}
bool Channel::ReceivePacket(const uint8_t* packet,

View File

@ -16,6 +16,7 @@
#include "api/audio/audio_mixer.h"
#include "api/audio_codecs/audio_encoder.h"
#include "api/call/audio_sink.h"
#include "api/call/transport.h"
#include "api/optional.h"
#include "common_audio/resampler/include/push_resampler.h"
#include "common_types.h" // NOLINT(build/include)
@ -33,7 +34,6 @@
#include "rtc_base/thread_checker.h"
#include "voice_engine/audio_level.h"
#include "voice_engine/include/voe_base.h"
#include "voice_engine/include/voe_network.h"
#include "voice_engine/shared_data.h"
#include "voice_engine/voice_engine_defines.h"
@ -204,12 +204,9 @@ class Channel
void SetReceiverFrameLengthRange(int min_frame_length_ms,
int max_frame_length_ms);
// VoENetwork
// Network
int32_t RegisterExternalTransport(Transport* transport);
int32_t DeRegisterExternalTransport();
int32_t ReceivedRTPPacket(const uint8_t* received_packet,
size_t length,
const PacketTime& packet_time);
// TODO(nisse, solenberg): Delete when VoENetwork is deleted.
int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
void OnRtpPacket(const RtpPacketReceived& packet);
@ -362,9 +359,6 @@ class Channel
int GetRemoteSSRC(unsigned int& ssrc);
void OnUplinkPacketLossRate(float packet_loss_rate);
bool InputMute() const;
bool OnRtpPacketWithHeader(const uint8_t* received_packet,
size_t length,
RTPHeader *header);
bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length);
bool ReceivePacket(const uint8_t* packet,

View File

@ -1,95 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// This sub-API supports the following functionalities:
//
// - External protocol support.
// - Packet timeout notification.
// - Dead-or-Alive connection observations.
//
// Usage example, omitting error checking:
//
// using namespace webrtc;
// VoiceEngine* voe = VoiceEngine::Create();
// VoEBase* base = VoEBase::GetInterface(voe);
// VoENetwork* netw = VoENetwork::GetInterface(voe);
// base->Init();
// int ch = base->CreateChannel();
// ...
// netw->SetPeriodicDeadOrAliveStatus(ch, true);
// ...
// base->DeleteChannel(ch);
// base->Terminate();
// base->Release();
// netw->Release();
// VoiceEngine::Delete(voe);
//
#ifndef VOICE_ENGINE_VOE_NETWORK_H_
#define VOICE_ENGINE_VOE_NETWORK_H_
#include "api/call/transport.h"
#include "common_types.h" // NOLINT(build/include)
namespace webrtc {
class VoiceEngine;
// VoENetwork
class WEBRTC_DLLEXPORT VoENetwork {
public:
// Factory for the VoENetwork sub-API. Increases an internal
// reference counter if successful. Returns NULL if the API is not
// supported or if construction fails.
static VoENetwork* GetInterface(VoiceEngine* voiceEngine);
// Releases the VoENetwork sub-API and decreases an internal
// reference counter. Returns the new reference count. This value should
// be zero for all sub-API:s before the VoiceEngine object can be safely
// deleted.
virtual int Release() = 0;
// Installs and enables a user-defined external transport protocol for a
// 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|. 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;
virtual int ReceivedRTPPacket(int channel,
const void* data,
size_t length,
const PacketTime& packet_time) {
return 0;
}
// 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;
protected:
VoENetwork() {}
virtual ~VoENetwork() {}
};
} // namespace webrtc
#endif // VOICE_ENGINE_VOE_NETWORK_H_

View File

@ -1,113 +0,0 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "voice_engine/voe_network_impl.h"
#include "rtc_base/checks.h"
#include "rtc_base/format_macros.h"
#include "rtc_base/logging.h"
#include "voice_engine/channel.h"
#include "voice_engine/include/voe_errors.h"
#include "voice_engine/voice_engine_impl.h"
namespace webrtc {
VoENetwork* VoENetwork::GetInterface(VoiceEngine* voiceEngine) {
if (!voiceEngine) {
return nullptr;
}
VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
s->AddRef();
return s;
}
VoENetworkImpl::VoENetworkImpl(voe::SharedData* shared) : _shared(shared) {
}
VoENetworkImpl::~VoENetworkImpl() = default;
int VoENetworkImpl::RegisterExternalTransport(int channel,
Transport& transport) {
RTC_DCHECK(_shared->statistics().Initialized());
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
voe::Channel* channelPtr = ch.channel();
if (!channelPtr) {
LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
return -1;
}
return channelPtr->RegisterExternalTransport(&transport);
}
int VoENetworkImpl::DeRegisterExternalTransport(int channel) {
RTC_CHECK(_shared->statistics().Initialized());
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
voe::Channel* channelPtr = ch.channel();
if (!channelPtr) {
LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
return -1;
}
return channelPtr->DeRegisterExternalTransport();
}
int VoENetworkImpl::ReceivedRTPPacket(int channel,
const void* data,
size_t length) {
return ReceivedRTPPacket(channel, data, length, webrtc::PacketTime());
}
int VoENetworkImpl::ReceivedRTPPacket(int channel,
const void* data,
size_t length,
const PacketTime& packet_time) {
RTC_CHECK(_shared->statistics().Initialized());
RTC_CHECK(data);
// L16 at 32 kHz, stereo, 10 ms frames (+12 byte RTP header) -> 1292 bytes
if ((length < 12) || (length > 1292)) {
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) {
LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
return -1;
}
if (!channelPtr->ExternalTransport()) {
LOG_F(LS_ERROR) << "No external transport for channel: " << channel;
return -1;
}
return channelPtr->ReceivedRTPPacket(static_cast<const uint8_t*>(data),
length, packet_time);
}
int VoENetworkImpl::ReceivedRTCPPacket(int channel,
const void* data,
size_t length) {
RTC_CHECK(_shared->statistics().Initialized());
RTC_CHECK(data);
if (length < 4) {
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) {
LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
return -1;
}
if (!channelPtr->ExternalTransport()) {
LOG_F(LS_ERROR) << "No external transport for channel: " << channel;
return -1;
}
return channelPtr->ReceivedRTCPPacket(static_cast<const uint8_t*>(data),
length);
}
} // namespace webrtc

View File

@ -1,43 +0,0 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef VOICE_ENGINE_VOE_NETWORK_IMPL_H_
#define VOICE_ENGINE_VOE_NETWORK_IMPL_H_
#include "voice_engine/include/voe_network.h"
#include "voice_engine/shared_data.h"
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;
int ReceivedRTPPacket(int channel,
const void* data,
size_t length,
const PacketTime& packet_time) override;
int ReceivedRTCPPacket(int channel, const void* data, size_t length) override;
protected:
VoENetworkImpl(voe::SharedData* shared);
~VoENetworkImpl() override;
private:
voe::SharedData* _shared;
};
} // namespace webrtc
#endif // VOICE_ENGINE_VOE_NETWORK_IMPL_H_

View File

@ -1,120 +0,0 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "voice_engine/include/voe_network.h"
#include "test/gtest.h"
#include "voice_engine/include/voe_errors.h"
#include "voice_engine/voice_engine_fixture.h"
namespace webrtc {
enum {
kMinValidSizeOfRtcpPacketInBytes = 4,
kMinValidSizeOfRtpPacketInBytes = 12,
kMaxValidSizeOfRtpPacketInBytes = 1292
};
// A packet with a valid header for both RTP and RTCP.
// Methods that are tested in this file are checking only packet header.
static const uint8_t kPacket[kMinValidSizeOfRtpPacketInBytes] = {0x80};
static const uint8_t kPacketJunk[kMinValidSizeOfRtpPacketInBytes] = {};
static const int kNonExistingChannel = 1234;
class VoENetworkTest : public VoiceEngineFixture {
protected:
int CreateChannelAndRegisterExternalTransport() {
EXPECT_EQ(0, base_->Init(&adm_, apm_.get(), nullptr));
int channelID = base_->CreateChannel();
EXPECT_NE(channelID, -1);
EXPECT_EQ(0, network_->RegisterExternalTransport(channelID, transport_));
return channelID;
}
};
TEST_F(VoENetworkTest, RegisterAndDeRegisterExternalTransport) {
int channelID = CreateChannelAndRegisterExternalTransport();
EXPECT_EQ(0, network_->DeRegisterExternalTransport(channelID));
}
TEST_F(VoENetworkTest,
RegisterExternalTransportOnNonExistingChannelShouldFail) {
EXPECT_EQ(0, base_->Init(&adm_, apm_.get(), nullptr));
EXPECT_NE(
0, network_->RegisterExternalTransport(kNonExistingChannel, transport_));
}
TEST_F(VoENetworkTest,
DeRegisterExternalTransportOnNonExistingChannelShouldFail) {
EXPECT_EQ(0, base_->Init(&adm_, apm_.get(), nullptr));
EXPECT_NE(0, network_->DeRegisterExternalTransport(kNonExistingChannel));
}
TEST_F(VoENetworkTest, DeRegisterExternalTransportBeforeRegister) {
EXPECT_EQ(0, base_->Init(&adm_, apm_.get(), nullptr));
int channelID = base_->CreateChannel();
EXPECT_NE(channelID, -1);
EXPECT_EQ(0, network_->DeRegisterExternalTransport(channelID));
}
TEST_F(VoENetworkTest, ReceivedRTPPacketWithJunkDataShouldFail) {
int channelID = CreateChannelAndRegisterExternalTransport();
EXPECT_EQ(-1, network_->ReceivedRTPPacket(channelID, kPacketJunk,
sizeof(kPacketJunk)));
}
TEST_F(VoENetworkTest, ReceivedRTPPacketOnNonExistingChannelShouldFail) {
EXPECT_EQ(0, base_->Init(&adm_, apm_.get(), nullptr));
EXPECT_EQ(-1, network_->ReceivedRTPPacket(kNonExistingChannel, kPacket,
sizeof(kPacket)));
}
TEST_F(VoENetworkTest, ReceivedRTPPacketOnChannelWithoutTransportShouldFail) {
EXPECT_EQ(0, base_->Init(&adm_, apm_.get(), nullptr));
int channelID = base_->CreateChannel();
EXPECT_NE(channelID, -1);
EXPECT_EQ(-1,
network_->ReceivedRTPPacket(channelID, kPacket, sizeof(kPacket)));
}
TEST_F(VoENetworkTest, ReceivedTooSmallRTPPacketShouldFail) {
int channelID = CreateChannelAndRegisterExternalTransport();
EXPECT_EQ(-1, network_->ReceivedRTPPacket(
channelID, kPacket, kMinValidSizeOfRtpPacketInBytes - 1));
}
TEST_F(VoENetworkTest, ReceivedTooLargeRTPPacketShouldFail) {
int channelID = CreateChannelAndRegisterExternalTransport();
EXPECT_EQ(-1, network_->ReceivedRTPPacket(
channelID, kPacket, kMaxValidSizeOfRtpPacketInBytes + 1));
}
TEST_F(VoENetworkTest, ReceivedRTCPPacketOnNonExistingChannelShouldFail) {
EXPECT_EQ(0, base_->Init(&adm_, apm_.get(), nullptr));
EXPECT_EQ(-1, network_->ReceivedRTCPPacket(kNonExistingChannel, kPacket,
sizeof(kPacket)));
}
TEST_F(VoENetworkTest, ReceivedRTCPPacketOnChannelWithoutTransportShouldFail) {
EXPECT_EQ(0, base_->Init(&adm_, apm_.get(), nullptr));
int channelID = base_->CreateChannel();
EXPECT_NE(channelID, -1);
EXPECT_EQ(-1,
network_->ReceivedRTCPPacket(channelID, kPacket, sizeof(kPacket)));
}
TEST_F(VoENetworkTest, ReceivedTooSmallRTCPPacket4ShouldFail) {
int channelID = CreateChannelAndRegisterExternalTransport();
EXPECT_EQ(-1, network_->ReceivedRTCPPacket(
channelID, kPacket, kMinValidSizeOfRtcpPacketInBytes - 1));
}
} // namespace webrtc

View File

@ -1,32 +0,0 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "voice_engine/voice_engine_fixture.h"
#include "modules/audio_processing/include/mock_audio_processing.h"
namespace webrtc {
VoiceEngineFixture::VoiceEngineFixture()
: voe_(VoiceEngine::Create()),
base_(VoEBase::GetInterface(voe_)),
network_(VoENetwork::GetInterface(voe_)) {
EXPECT_NE(nullptr, base_);
EXPECT_NE(nullptr, network_);
apm_ = new rtc::RefCountedObject<test::MockAudioProcessing>();
}
VoiceEngineFixture::~VoiceEngineFixture() {
EXPECT_EQ(2, network_->Release());
EXPECT_EQ(0, base_->Terminate());
EXPECT_EQ(1, base_->Release());
EXPECT_TRUE(VoiceEngine::Delete(voe_));
}
} // namespace webrtc

View File

@ -1,33 +0,0 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/audio_device/include/fake_audio_device.h"
#include "modules/audio_processing/include/audio_processing.h"
#include "test/gtest.h"
#include "test/mock_transport.h"
#include "voice_engine/include/voe_base.h"
#include "voice_engine/include/voe_network.h"
namespace webrtc {
class VoiceEngineFixture : public ::testing::Test {
protected:
VoiceEngineFixture();
~VoiceEngineFixture();
VoiceEngine* voe_;
VoEBase* base_;
VoENetwork* network_;
FakeAudioDeviceModule adm_;
MockTransport transport_;
rtc::scoped_refptr<AudioProcessing> apm_;
};
} // namespace webrtc

View File

@ -16,7 +16,6 @@
#include "system_wrappers/include/atomic32.h"
#include "typedefs.h" // NOLINT(build/include)
#include "voice_engine/voe_base_impl.h"
#include "voice_engine/voe_network_impl.h"
namespace webrtc {
namespace voe {
@ -25,12 +24,10 @@ class ChannelProxy;
class VoiceEngineImpl : public voe::SharedData, // Must be the first base class
public VoiceEngine,
public VoENetworkImpl,
public VoEBaseImpl {
public:
VoiceEngineImpl()
: SharedData(),
VoENetworkImpl(this),
VoEBaseImpl(this),
_ref_count(0) {}
~VoiceEngineImpl() override { assert(_ref_count.Value() == 0); }