blob: 2ff6b6a81136ec15534db3db7d36d9c37662a388 [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"
andrew@webrtc.org8c845cb2013-05-02 15:28:02 +000015#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
16#include "webrtc/system_wrappers/interface/logging.h"
17#include "webrtc/system_wrappers/interface/trace.h"
18#include "webrtc/voice_engine/channel.h"
19#include "webrtc/voice_engine/include/voe_errors.h"
20#include "webrtc/voice_engine/voice_engine_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
Jelena Marusic0d266052015-05-04 14:15:32 +020022namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000023
Jelena Marusic0d266052015-05-04 14:15:32 +020024VoENetwork* VoENetwork::GetInterface(VoiceEngine* voiceEngine) {
Jelena Marusicf353dd52015-05-06 15:04:22 +020025 if (!voiceEngine) {
26 return nullptr;
Jelena Marusic0d266052015-05-04 14:15:32 +020027 }
28 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
29 s->AddRef();
30 return s;
niklase@google.com470e71d2011-07-07 08:21:25 +000031}
32
Jelena Marusic0d266052015-05-04 14:15:32 +020033VoENetworkImpl::VoENetworkImpl(voe::SharedData* shared) : _shared(shared) {
niklase@google.com470e71d2011-07-07 08:21:25 +000034}
35
Jelena Marusicf353dd52015-05-06 15:04:22 +020036VoENetworkImpl::~VoENetworkImpl() = default;
niklase@google.com470e71d2011-07-07 08:21:25 +000037
niklase@google.com470e71d2011-07-07 08:21:25 +000038int VoENetworkImpl::RegisterExternalTransport(int channel,
Jelena Marusic0d266052015-05-04 14:15:32 +020039 Transport& transport) {
henrikg91d6ede2015-09-17 00:24:34 -070040 RTC_DCHECK(_shared->statistics().Initialized());
Jelena Marusic0d266052015-05-04 14:15:32 +020041 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
42 voe::Channel* channelPtr = ch.channel();
Jelena Marusicf353dd52015-05-06 15:04:22 +020043 if (!channelPtr) {
44 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +020045 return -1;
46 }
47 return channelPtr->RegisterExternalTransport(transport);
niklase@google.com470e71d2011-07-07 08:21:25 +000048}
49
Jelena Marusic0d266052015-05-04 14:15:32 +020050int VoENetworkImpl::DeRegisterExternalTransport(int channel) {
henrikg91d6ede2015-09-17 00:24:34 -070051 RTC_CHECK(_shared->statistics().Initialized());
Jelena Marusic0d266052015-05-04 14:15:32 +020052 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
53 voe::Channel* channelPtr = ch.channel();
Jelena Marusicf353dd52015-05-06 15:04:22 +020054 if (!channelPtr) {
55 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +020056 return -1;
57 }
58 return channelPtr->DeRegisterExternalTransport();
niklase@google.com470e71d2011-07-07 08:21:25 +000059}
60
61int VoENetworkImpl::ReceivedRTPPacket(int channel,
62 const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000063 size_t length) {
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +000064 return ReceivedRTPPacket(channel, data, length, webrtc::PacketTime());
65}
66
67int VoENetworkImpl::ReceivedRTPPacket(int channel,
68 const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000069 size_t length,
Jelena Marusic0d266052015-05-04 14:15:32 +020070 const PacketTime& packet_time) {
henrikg91d6ede2015-09-17 00:24:34 -070071 RTC_CHECK(_shared->statistics().Initialized());
72 RTC_CHECK(data);
Jelena Marusic0d266052015-05-04 14:15:32 +020073 // L16 at 32 kHz, stereo, 10 ms frames (+12 byte RTP header) -> 1292 bytes
74 if ((length < 12) || (length > 1292)) {
Jelena Marusicf353dd52015-05-06 15:04:22 +020075 LOG_F(LS_ERROR) << "Invalid packet length: " << length;
Jelena Marusic0d266052015-05-04 14:15:32 +020076 return -1;
77 }
78 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
79 voe::Channel* channelPtr = ch.channel();
Jelena Marusicf353dd52015-05-06 15:04:22 +020080 if (!channelPtr) {
81 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +020082 return -1;
83 }
Jelena Marusic0d266052015-05-04 14:15:32 +020084 if (!channelPtr->ExternalTransport()) {
Jelena Marusicf353dd52015-05-06 15:04:22 +020085 LOG_F(LS_ERROR) << "No external transport for channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +020086 return -1;
87 }
88 return channelPtr->ReceivedRTPPacket((const int8_t*)data, length,
89 packet_time);
niklase@google.com470e71d2011-07-07 08:21:25 +000090}
91
Jelena Marusic0d266052015-05-04 14:15:32 +020092int VoENetworkImpl::ReceivedRTCPPacket(int channel,
93 const void* data,
94 size_t length) {
henrikg91d6ede2015-09-17 00:24:34 -070095 RTC_CHECK(_shared->statistics().Initialized());
96 RTC_CHECK(data);
Jelena Marusic0d266052015-05-04 14:15:32 +020097 if (length < 4) {
Jelena Marusicf353dd52015-05-06 15:04:22 +020098 LOG_F(LS_ERROR) << "Invalid packet length: " << length;
Jelena Marusic0d266052015-05-04 14:15:32 +020099 return -1;
100 }
101 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
102 voe::Channel* channelPtr = ch.channel();
Jelena Marusicf353dd52015-05-06 15:04:22 +0200103 if (!channelPtr) {
104 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +0200105 return -1;
106 }
107 if (!channelPtr->ExternalTransport()) {
Jelena Marusicf353dd52015-05-06 15:04:22 +0200108 LOG_F(LS_ERROR) << "No external transport for channel: " << channel;
Jelena Marusic0d266052015-05-04 14:15:32 +0200109 return -1;
110 }
111 return channelPtr->ReceivedRTCPPacket((const int8_t*)data, 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