blob: 26ad4176681a2198e762265baba4600a5d4dd18e [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:231/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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.orgad9cee82013-05-02 15:28:0211#include "webrtc/voice_engine/voe_network_impl.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:2312
Edward Lemur76de83e2017-07-06 17:44:3413#include "webrtc/rtc_base/checks.h"
14#include "webrtc/rtc_base/format_macros.h"
15#include "webrtc/rtc_base/logging.h"
andrew@webrtc.orgad9cee82013-05-02 15:28:0216#include "webrtc/voice_engine/channel.h"
17#include "webrtc/voice_engine/include/voe_errors.h"
18#include "webrtc/voice_engine/voice_engine_impl.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:2319
Jelena Marusic0705a022015-05-04 12:15:3220namespace webrtc {
andrew@webrtc.orgb015cbe2012-10-22 18:19:2321
Jelena Marusic0705a022015-05-04 12:15:3222VoENetwork* VoENetwork::GetInterface(VoiceEngine* voiceEngine) {
Jelena Marusic9e50d7e2015-05-06 13:04:2223 if (!voiceEngine) {
24 return nullptr;
Jelena Marusic0705a022015-05-04 12:15:3225 }
26 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
27 s->AddRef();
28 return s;
andrew@webrtc.orgb015cbe2012-10-22 18:19:2329}
30
Jelena Marusic0705a022015-05-04 12:15:3231VoENetworkImpl::VoENetworkImpl(voe::SharedData* shared) : _shared(shared) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:2332}
33
Jelena Marusic9e50d7e2015-05-06 13:04:2234VoENetworkImpl::~VoENetworkImpl() = default;
andrew@webrtc.orgb015cbe2012-10-22 18:19:2335
36int VoENetworkImpl::RegisterExternalTransport(int channel,
Jelena Marusic0705a022015-05-04 12:15:3237 Transport& transport) {
henrikg5c075c82015-09-17 07:24:3438 RTC_DCHECK(_shared->statistics().Initialized());
Jelena Marusic0705a022015-05-04 12:15:3239 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
40 voe::Channel* channelPtr = ch.channel();
Jelena Marusic9e50d7e2015-05-06 13:04:2241 if (!channelPtr) {
42 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0705a022015-05-04 12:15:3243 return -1;
44 }
mflodman823f9082016-04-29 07:57:1345 return channelPtr->RegisterExternalTransport(&transport);
andrew@webrtc.orgb015cbe2012-10-22 18:19:2346}
47
Jelena Marusic0705a022015-05-04 12:15:3248int VoENetworkImpl::DeRegisterExternalTransport(int channel) {
henrikg5c075c82015-09-17 07:24:3449 RTC_CHECK(_shared->statistics().Initialized());
Jelena Marusic0705a022015-05-04 12:15:3250 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
51 voe::Channel* channelPtr = ch.channel();
Jelena Marusic9e50d7e2015-05-06 13:04:2252 if (!channelPtr) {
53 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0705a022015-05-04 12:15:3254 return -1;
55 }
56 return channelPtr->DeRegisterExternalTransport();
andrew@webrtc.orgb015cbe2012-10-22 18:19:2357}
58
59int VoENetworkImpl::ReceivedRTPPacket(int channel,
60 const void* data,
pkasting@chromium.org0ab923a2014-11-20 22:28:1461 size_t length) {
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:2562 return ReceivedRTPPacket(channel, data, length, webrtc::PacketTime());
63}
64
65int VoENetworkImpl::ReceivedRTPPacket(int channel,
66 const void* data,
pkasting@chromium.org0ab923a2014-11-20 22:28:1467 size_t length,
Jelena Marusic0705a022015-05-04 12:15:3268 const PacketTime& packet_time) {
henrikg5c075c82015-09-17 07:24:3469 RTC_CHECK(_shared->statistics().Initialized());
70 RTC_CHECK(data);
Jelena Marusic0705a022015-05-04 12:15:3271 // L16 at 32 kHz, stereo, 10 ms frames (+12 byte RTP header) -> 1292 bytes
72 if ((length < 12) || (length > 1292)) {
Jelena Marusic9e50d7e2015-05-06 13:04:2273 LOG_F(LS_ERROR) << "Invalid packet length: " << length;
Jelena Marusic0705a022015-05-04 12:15:3274 return -1;
75 }
76 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
77 voe::Channel* channelPtr = ch.channel();
Jelena Marusic9e50d7e2015-05-06 13:04:2278 if (!channelPtr) {
79 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0705a022015-05-04 12:15:3280 return -1;
81 }
Jelena Marusic0705a022015-05-04 12:15:3282 if (!channelPtr->ExternalTransport()) {
Jelena Marusic9e50d7e2015-05-06 13:04:2283 LOG_F(LS_ERROR) << "No external transport for channel: " << channel;
Jelena Marusic0705a022015-05-04 12:15:3284 return -1;
85 }
mflodman823f9082016-04-29 07:57:1386 return channelPtr->ReceivedRTPPacket(static_cast<const uint8_t*>(data),
87 length, packet_time);
andrew@webrtc.orgb015cbe2012-10-22 18:19:2388}
89
Jelena Marusic0705a022015-05-04 12:15:3290int VoENetworkImpl::ReceivedRTCPPacket(int channel,
91 const void* data,
92 size_t length) {
henrikg5c075c82015-09-17 07:24:3493 RTC_CHECK(_shared->statistics().Initialized());
94 RTC_CHECK(data);
Jelena Marusic0705a022015-05-04 12:15:3295 if (length < 4) {
Jelena Marusic9e50d7e2015-05-06 13:04:2296 LOG_F(LS_ERROR) << "Invalid packet length: " << length;
Jelena Marusic0705a022015-05-04 12:15:3297 return -1;
98 }
99 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
100 voe::Channel* channelPtr = ch.channel();
Jelena Marusic9e50d7e2015-05-06 13:04:22101 if (!channelPtr) {
102 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel;
Jelena Marusic0705a022015-05-04 12:15:32103 return -1;
104 }
105 if (!channelPtr->ExternalTransport()) {
Jelena Marusic9e50d7e2015-05-06 13:04:22106 LOG_F(LS_ERROR) << "No external transport for channel: " << channel;
Jelena Marusic0705a022015-05-04 12:15:32107 return -1;
108 }
mflodman823f9082016-04-29 07:57:13109 return channelPtr->ReceivedRTCPPacket(static_cast<const uint8_t*>(data),
110 length);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23111}
Jelena Marusic9e50d7e2015-05-06 13:04:22112
pbos@webrtc.org3b89e102013-07-03 15:12:26113} // namespace webrtc