blob: 26ad4176681a2198e762265baba4600a5d4dd18e [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
Edward Lemurc20978e2017-07-06 19:44:34 +020013#include "webrtc/rtc_base/checks.h"
14#include "webrtc/rtc_base/format_macros.h"
15#include "webrtc/rtc_base/logging.h"
andrew@webrtc.org8c845cb2013-05-02 15:28:02 +000016#include "webrtc/voice_engine/channel.h"
17#include "webrtc/voice_engine/include/voe_errors.h"
18#include "webrtc/voice_engine/voice_engine_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000019
Jelena Marusic0d266052015-05-04 14:15:32 +020020namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000021
Jelena Marusic0d266052015-05-04 14:15:32 +020022VoENetwork* VoENetwork::GetInterface(VoiceEngine* voiceEngine) {
Jelena Marusicf353dd52015-05-06 15:04:22 +020023 if (!voiceEngine) {
24 return nullptr;
Jelena Marusic0d266052015-05-04 14:15:32 +020025 }
26 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
27 s->AddRef();
28 return s;
niklase@google.com470e71d2011-07-07 08:21:25 +000029}
30
Jelena Marusic0d266052015-05-04 14:15:32 +020031VoENetworkImpl::VoENetworkImpl(voe::SharedData* shared) : _shared(shared) {
niklase@google.com470e71d2011-07-07 08:21:25 +000032}
33
Jelena Marusicf353dd52015-05-06 15:04:22 +020034VoENetworkImpl::~VoENetworkImpl() = default;
niklase@google.com470e71d2011-07-07 08:21:25 +000035
niklase@google.com470e71d2011-07-07 08:21:25 +000036int VoENetworkImpl::RegisterExternalTransport(int channel,
Jelena Marusic0d266052015-05-04 14:15:32 +020037 Transport& transport) {
henrikg91d6ede2015-09-17 00:24:34 -070038 RTC_DCHECK(_shared->statistics().Initialized());
Jelena Marusic0d266052015-05-04 14:15:32 +020039 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
40 voe::Channel* channelPtr = ch.channel();
Jelena Marusicf353dd52015-05-06 15:04:22 +020041 if (!channelPtr) {
42 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +020043 return -1;
44 }
mflodman3d7db262016-04-29 00:57:13 -070045 return channelPtr->RegisterExternalTransport(&transport);
niklase@google.com470e71d2011-07-07 08:21:25 +000046}
47
Jelena Marusic0d266052015-05-04 14:15:32 +020048int VoENetworkImpl::DeRegisterExternalTransport(int channel) {
henrikg91d6ede2015-09-17 00:24:34 -070049 RTC_CHECK(_shared->statistics().Initialized());
Jelena Marusic0d266052015-05-04 14:15:32 +020050 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
51 voe::Channel* channelPtr = ch.channel();
Jelena Marusicf353dd52015-05-06 15:04:22 +020052 if (!channelPtr) {
53 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +020054 return -1;
55 }
56 return channelPtr->DeRegisterExternalTransport();
niklase@google.com470e71d2011-07-07 08:21:25 +000057}
58
59int VoENetworkImpl::ReceivedRTPPacket(int channel,
60 const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000061 size_t length) {
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +000062 return ReceivedRTPPacket(channel, data, length, webrtc::PacketTime());
63}
64
65int VoENetworkImpl::ReceivedRTPPacket(int channel,
66 const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000067 size_t length,
Jelena Marusic0d266052015-05-04 14:15:32 +020068 const PacketTime& packet_time) {
henrikg91d6ede2015-09-17 00:24:34 -070069 RTC_CHECK(_shared->statistics().Initialized());
70 RTC_CHECK(data);
Jelena Marusic0d266052015-05-04 14:15:32 +020071 // L16 at 32 kHz, stereo, 10 ms frames (+12 byte RTP header) -> 1292 bytes
72 if ((length < 12) || (length > 1292)) {
Jelena Marusicf353dd52015-05-06 15:04:22 +020073 LOG_F(LS_ERROR) << "Invalid packet length: " << length;
Jelena Marusic0d266052015-05-04 14:15:32 +020074 return -1;
75 }
76 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
77 voe::Channel* channelPtr = ch.channel();
Jelena Marusicf353dd52015-05-06 15:04:22 +020078 if (!channelPtr) {
79 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +020080 return -1;
81 }
Jelena Marusic0d266052015-05-04 14:15:32 +020082 if (!channelPtr->ExternalTransport()) {
Jelena Marusicf353dd52015-05-06 15:04:22 +020083 LOG_F(LS_ERROR) << "No external transport for channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +020084 return -1;
85 }
mflodman3d7db262016-04-29 00:57:13 -070086 return channelPtr->ReceivedRTPPacket(static_cast<const uint8_t*>(data),
87 length, packet_time);
niklase@google.com470e71d2011-07-07 08:21:25 +000088}
89
Jelena Marusic0d266052015-05-04 14:15:32 +020090int VoENetworkImpl::ReceivedRTCPPacket(int channel,
91 const void* data,
92 size_t length) {
henrikg91d6ede2015-09-17 00:24:34 -070093 RTC_CHECK(_shared->statistics().Initialized());
94 RTC_CHECK(data);
Jelena Marusic0d266052015-05-04 14:15:32 +020095 if (length < 4) {
Jelena Marusicf353dd52015-05-06 15:04:22 +020096 LOG_F(LS_ERROR) << "Invalid packet length: " << length;
Jelena Marusic0d266052015-05-04 14:15:32 +020097 return -1;
98 }
99 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
100 voe::Channel* channelPtr = ch.channel();
Jelena Marusicf353dd52015-05-06 15:04:22 +0200101 if (!channelPtr) {
102 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +0200103 return -1;
104 }
105 if (!channelPtr->ExternalTransport()) {
Jelena Marusicf353dd52015-05-06 15:04:22 +0200106 LOG_F(LS_ERROR) << "No external transport for channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +0200107 return -1;
108 }
mflodman3d7db262016-04-29 00:57:13 -0700109 return channelPtr->ReceivedRTCPPacket(static_cast<const uint8_t*>(data),
110 length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000111}
Jelena Marusicf353dd52015-05-06 15:04:22 +0200112
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000113} // namespace webrtc