blob: 6941629d79debb6eef8f2cb9e1dbbcc076c61c05 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
xians@webrtc.org79af7342012-01-31 12:22:14 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
andrew@webrtc.org8c845cb2013-05-02 15:28:02 +000011#include "webrtc/voice_engine/voe_network_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
Jelena Marusicf353dd52015-05-06 15:04:22 +020013#include "webrtc/base/checks.h"
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000014#include "webrtc/base/format_macros.h"
pbosad856222015-11-27 09:48:36 -080015#include "webrtc/base/logging.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010016#include "webrtc/system_wrappers/include/trace.h"
andrew@webrtc.org8c845cb2013-05-02 15:28:02 +000017#include "webrtc/voice_engine/channel.h"
18#include "webrtc/voice_engine/include/voe_errors.h"
19#include "webrtc/voice_engine/voice_engine_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
Jelena Marusic0d266052015-05-04 14:15:32 +020021namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000022
Jelena Marusic0d266052015-05-04 14:15:32 +020023VoENetwork* VoENetwork::GetInterface(VoiceEngine* voiceEngine) {
Jelena Marusicf353dd52015-05-06 15:04:22 +020024 if (!voiceEngine) {
25 return nullptr;
Jelena Marusic0d266052015-05-04 14:15:32 +020026 }
27 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
28 s->AddRef();
29 return s;
niklase@google.com470e71d2011-07-07 08:21:25 +000030}
31
Jelena Marusic0d266052015-05-04 14:15:32 +020032VoENetworkImpl::VoENetworkImpl(voe::SharedData* shared) : _shared(shared) {
niklase@google.com470e71d2011-07-07 08:21:25 +000033}
34
Jelena Marusicf353dd52015-05-06 15:04:22 +020035VoENetworkImpl::~VoENetworkImpl() = default;
niklase@google.com470e71d2011-07-07 08:21:25 +000036
niklase@google.com470e71d2011-07-07 08:21:25 +000037int VoENetworkImpl::RegisterExternalTransport(int channel,
Jelena Marusic0d266052015-05-04 14:15:32 +020038 Transport& transport) {
henrikg91d6ede2015-09-17 00:24:34 -070039 RTC_DCHECK(_shared->statistics().Initialized());
Jelena Marusic0d266052015-05-04 14:15:32 +020040 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
41 voe::Channel* channelPtr = ch.channel();
Jelena Marusicf353dd52015-05-06 15:04:22 +020042 if (!channelPtr) {
43 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +020044 return -1;
45 }
mflodman3d7db262016-04-29 00:57:13 -070046 return channelPtr->RegisterExternalTransport(&transport);
niklase@google.com470e71d2011-07-07 08:21:25 +000047}
48
Jelena Marusic0d266052015-05-04 14:15:32 +020049int VoENetworkImpl::DeRegisterExternalTransport(int channel) {
henrikg91d6ede2015-09-17 00:24:34 -070050 RTC_CHECK(_shared->statistics().Initialized());
Jelena Marusic0d266052015-05-04 14:15:32 +020051 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
52 voe::Channel* channelPtr = ch.channel();
Jelena Marusicf353dd52015-05-06 15:04:22 +020053 if (!channelPtr) {
54 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +020055 return -1;
56 }
57 return channelPtr->DeRegisterExternalTransport();
niklase@google.com470e71d2011-07-07 08:21:25 +000058}
59
60int VoENetworkImpl::ReceivedRTPPacket(int channel,
61 const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000062 size_t length) {
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +000063 return ReceivedRTPPacket(channel, data, length, webrtc::PacketTime());
64}
65
66int VoENetworkImpl::ReceivedRTPPacket(int channel,
67 const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000068 size_t length,
Jelena Marusic0d266052015-05-04 14:15:32 +020069 const PacketTime& packet_time) {
henrikg91d6ede2015-09-17 00:24:34 -070070 RTC_CHECK(_shared->statistics().Initialized());
71 RTC_CHECK(data);
Jelena Marusic0d266052015-05-04 14:15:32 +020072 // L16 at 32 kHz, stereo, 10 ms frames (+12 byte RTP header) -> 1292 bytes
73 if ((length < 12) || (length > 1292)) {
Jelena Marusicf353dd52015-05-06 15:04:22 +020074 LOG_F(LS_ERROR) << "Invalid packet length: " << length;
Jelena Marusic0d266052015-05-04 14:15:32 +020075 return -1;
76 }
77 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
78 voe::Channel* channelPtr = ch.channel();
Jelena Marusicf353dd52015-05-06 15:04:22 +020079 if (!channelPtr) {
80 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +020081 return -1;
82 }
Jelena Marusic0d266052015-05-04 14:15:32 +020083 if (!channelPtr->ExternalTransport()) {
Jelena Marusicf353dd52015-05-06 15:04:22 +020084 LOG_F(LS_ERROR) << "No external transport for channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +020085 return -1;
86 }
mflodman3d7db262016-04-29 00:57:13 -070087 return channelPtr->ReceivedRTPPacket(static_cast<const uint8_t*>(data),
88 length, packet_time);
niklase@google.com470e71d2011-07-07 08:21:25 +000089}
90
Jelena Marusic0d266052015-05-04 14:15:32 +020091int VoENetworkImpl::ReceivedRTCPPacket(int channel,
92 const void* data,
93 size_t length) {
henrikg91d6ede2015-09-17 00:24:34 -070094 RTC_CHECK(_shared->statistics().Initialized());
95 RTC_CHECK(data);
Jelena Marusic0d266052015-05-04 14:15:32 +020096 if (length < 4) {
Jelena Marusicf353dd52015-05-06 15:04:22 +020097 LOG_F(LS_ERROR) << "Invalid packet length: " << length;
Jelena Marusic0d266052015-05-04 14:15:32 +020098 return -1;
99 }
100 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
101 voe::Channel* channelPtr = ch.channel();
Jelena Marusicf353dd52015-05-06 15:04:22 +0200102 if (!channelPtr) {
103 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +0200104 return -1;
105 }
106 if (!channelPtr->ExternalTransport()) {
Jelena Marusicf353dd52015-05-06 15:04:22 +0200107 LOG_F(LS_ERROR) << "No external transport for channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +0200108 return -1;
109 }
mflodman3d7db262016-04-29 00:57:13 -0700110 return channelPtr->ReceivedRTCPPacket(static_cast<const uint8_t*>(data),
111 length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000112}
Jelena Marusicf353dd52015-05-06 15:04:22 +0200113
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000114} // namespace webrtc