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