niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
xians@webrtc.org | 79af734 | 2012-01-31 12:22:14 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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.org | 8c845cb | 2013-05-02 15:28:02 +0000 | [diff] [blame] | 11 | #include "webrtc/voice_engine/voe_network_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 13 | #include "webrtc/base/checks.h" |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 14 | #include "webrtc/base/format_macros.h" |
pbos | ad85622 | 2015-11-27 09:48:36 -0800 | [diff] [blame] | 15 | #include "webrtc/base/logging.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 16 | #include "webrtc/system_wrappers/include/trace.h" |
andrew@webrtc.org | 8c845cb | 2013-05-02 15:28:02 +0000 | [diff] [blame] | 17 | #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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 21 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 23 | VoENetwork* VoENetwork::GetInterface(VoiceEngine* voiceEngine) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 24 | if (!voiceEngine) { |
| 25 | return nullptr; |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 26 | } |
| 27 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
| 28 | s->AddRef(); |
| 29 | return s; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 32 | VoENetworkImpl::VoENetworkImpl(voe::SharedData* shared) : _shared(shared) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 35 | VoENetworkImpl::~VoENetworkImpl() = default; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | int VoENetworkImpl::RegisterExternalTransport(int channel, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 38 | Transport& transport) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 39 | RTC_DCHECK(_shared->statistics().Initialized()); |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 40 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 41 | voe::Channel* channelPtr = ch.channel(); |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 42 | if (!channelPtr) { |
| 43 | LOG_F(LS_ERROR) << "Failed to locate channel: " << channel; |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 44 | return -1; |
| 45 | } |
| 46 | return channelPtr->RegisterExternalTransport(transport); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 49 | int VoENetworkImpl::DeRegisterExternalTransport(int channel) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 50 | RTC_CHECK(_shared->statistics().Initialized()); |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 51 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 52 | voe::Channel* channelPtr = ch.channel(); |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 53 | if (!channelPtr) { |
| 54 | LOG_F(LS_ERROR) << "Failed to locate channel: " << channel; |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 55 | return -1; |
| 56 | } |
| 57 | return channelPtr->DeRegisterExternalTransport(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | int VoENetworkImpl::ReceivedRTPPacket(int channel, |
| 61 | const void* data, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 62 | size_t length) { |
solenberg@webrtc.org | b1f5010 | 2014-03-24 10:38:25 +0000 | [diff] [blame] | 63 | return ReceivedRTPPacket(channel, data, length, webrtc::PacketTime()); |
| 64 | } |
| 65 | |
| 66 | int VoENetworkImpl::ReceivedRTPPacket(int channel, |
| 67 | const void* data, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 68 | size_t length, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 69 | const PacketTime& packet_time) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 70 | RTC_CHECK(_shared->statistics().Initialized()); |
| 71 | RTC_CHECK(data); |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 72 | // L16 at 32 kHz, stereo, 10 ms frames (+12 byte RTP header) -> 1292 bytes |
| 73 | if ((length < 12) || (length > 1292)) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 74 | LOG_F(LS_ERROR) << "Invalid packet length: " << length; |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 75 | return -1; |
| 76 | } |
| 77 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 78 | voe::Channel* channelPtr = ch.channel(); |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 79 | if (!channelPtr) { |
| 80 | LOG_F(LS_ERROR) << "Failed to locate channel: " << channel; |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 81 | return -1; |
| 82 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 83 | if (!channelPtr->ExternalTransport()) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 84 | LOG_F(LS_ERROR) << "No external transport for channel: " << channel; |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 85 | return -1; |
| 86 | } |
| 87 | return channelPtr->ReceivedRTPPacket((const int8_t*)data, length, |
| 88 | packet_time); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 91 | int VoENetworkImpl::ReceivedRTCPPacket(int channel, |
| 92 | const void* data, |
| 93 | size_t length) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 94 | RTC_CHECK(_shared->statistics().Initialized()); |
| 95 | RTC_CHECK(data); |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 96 | if (length < 4) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 97 | LOG_F(LS_ERROR) << "Invalid packet length: " << length; |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 98 | return -1; |
| 99 | } |
| 100 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 101 | voe::Channel* channelPtr = ch.channel(); |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 102 | if (!channelPtr) { |
| 103 | LOG_F(LS_ERROR) << "Failed to locate channel: " << channel; |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 104 | return -1; |
| 105 | } |
| 106 | if (!channelPtr->ExternalTransport()) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 107 | LOG_F(LS_ERROR) << "No external transport for channel: " << channel; |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 108 | return -1; |
| 109 | } |
| 110 | return channelPtr->ReceivedRTCPPacket((const int8_t*)data, length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | } |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 112 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 113 | } // namespace webrtc |