Files
platform-external-webrtc/webrtc/voice_engine/voe_network_impl.cc
Jelena Marusic f353dd59b5 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}
2015-05-06 13:04:29 +00:00

115 lines
3.9 KiB
C++

/*
* 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 "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"
#include "webrtc/system_wrappers/interface/trace.h"
#include "webrtc/voice_engine/channel.h"
#include "webrtc/voice_engine/include/voe_errors.h"
#include "webrtc/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) {
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) {
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) {
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)) {
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((const int8_t*)data, length,
packet_time);
}
int VoENetworkImpl::ReceivedRTCPPacket(int channel,
const void* data,
size_t length) {
CHECK(_shared->statistics().Initialized());
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((const int8_t*)data, length);
}
} // namespace webrtc