andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1 | /* |
| 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.org | ad9cee8 | 2013-05-02 15:28:02 | [diff] [blame] | 11 | #include "webrtc/voice_engine/voe_network_impl.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 12 | |
Edward Lemur | 76de83e | 2017-07-06 17:44:34 | [diff] [blame] | 13 | #include "webrtc/rtc_base/checks.h" |
| 14 | #include "webrtc/rtc_base/format_macros.h" |
| 15 | #include "webrtc/rtc_base/logging.h" |
andrew@webrtc.org | ad9cee8 | 2013-05-02 15:28:02 | [diff] [blame] | 16 | #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.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 19 | |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 20 | namespace webrtc { |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 21 | |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 22 | VoENetwork* VoENetwork::GetInterface(VoiceEngine* voiceEngine) { |
Jelena Marusic | 9e50d7e | 2015-05-06 13:04:22 | [diff] [blame] | 23 | if (!voiceEngine) { |
| 24 | return nullptr; |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 25 | } |
| 26 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
| 27 | s->AddRef(); |
| 28 | return s; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 29 | } |
| 30 | |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 31 | VoENetworkImpl::VoENetworkImpl(voe::SharedData* shared) : _shared(shared) { |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 32 | } |
| 33 | |
Jelena Marusic | 9e50d7e | 2015-05-06 13:04:22 | [diff] [blame] | 34 | VoENetworkImpl::~VoENetworkImpl() = default; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 35 | |
| 36 | int VoENetworkImpl::RegisterExternalTransport(int channel, |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 37 | Transport& transport) { |
henrikg | 5c075c8 | 2015-09-17 07:24:34 | [diff] [blame] | 38 | RTC_DCHECK(_shared->statistics().Initialized()); |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 39 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 40 | voe::Channel* channelPtr = ch.channel(); |
Jelena Marusic | 9e50d7e | 2015-05-06 13:04:22 | [diff] [blame] | 41 | if (!channelPtr) { |
| 42 | LOG_F(LS_ERROR) << "Failed to locate channel: " << channel; |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 43 | return -1; |
| 44 | } |
mflodman | 823f908 | 2016-04-29 07:57:13 | [diff] [blame] | 45 | return channelPtr->RegisterExternalTransport(&transport); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 46 | } |
| 47 | |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 48 | int VoENetworkImpl::DeRegisterExternalTransport(int channel) { |
henrikg | 5c075c8 | 2015-09-17 07:24:34 | [diff] [blame] | 49 | RTC_CHECK(_shared->statistics().Initialized()); |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 50 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 51 | voe::Channel* channelPtr = ch.channel(); |
Jelena Marusic | 9e50d7e | 2015-05-06 13:04:22 | [diff] [blame] | 52 | if (!channelPtr) { |
| 53 | LOG_F(LS_ERROR) << "Failed to locate channel: " << channel; |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 54 | return -1; |
| 55 | } |
| 56 | return channelPtr->DeRegisterExternalTransport(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | int VoENetworkImpl::ReceivedRTPPacket(int channel, |
| 60 | const void* data, |
pkasting@chromium.org | 0ab923a | 2014-11-20 22:28:14 | [diff] [blame] | 61 | size_t length) { |
solenberg@webrtc.org | fec6b6e | 2014-03-24 10:38:25 | [diff] [blame] | 62 | return ReceivedRTPPacket(channel, data, length, webrtc::PacketTime()); |
| 63 | } |
| 64 | |
| 65 | int VoENetworkImpl::ReceivedRTPPacket(int channel, |
| 66 | const void* data, |
pkasting@chromium.org | 0ab923a | 2014-11-20 22:28:14 | [diff] [blame] | 67 | size_t length, |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 68 | const PacketTime& packet_time) { |
henrikg | 5c075c8 | 2015-09-17 07:24:34 | [diff] [blame] | 69 | RTC_CHECK(_shared->statistics().Initialized()); |
| 70 | RTC_CHECK(data); |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 71 | // L16 at 32 kHz, stereo, 10 ms frames (+12 byte RTP header) -> 1292 bytes |
| 72 | if ((length < 12) || (length > 1292)) { |
Jelena Marusic | 9e50d7e | 2015-05-06 13:04:22 | [diff] [blame] | 73 | LOG_F(LS_ERROR) << "Invalid packet length: " << length; |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 74 | return -1; |
| 75 | } |
| 76 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 77 | voe::Channel* channelPtr = ch.channel(); |
Jelena Marusic | 9e50d7e | 2015-05-06 13:04:22 | [diff] [blame] | 78 | if (!channelPtr) { |
| 79 | LOG_F(LS_ERROR) << "Failed to locate channel: " << channel; |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 80 | return -1; |
| 81 | } |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 82 | if (!channelPtr->ExternalTransport()) { |
Jelena Marusic | 9e50d7e | 2015-05-06 13:04:22 | [diff] [blame] | 83 | LOG_F(LS_ERROR) << "No external transport for channel: " << channel; |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 84 | return -1; |
| 85 | } |
mflodman | 823f908 | 2016-04-29 07:57:13 | [diff] [blame] | 86 | return channelPtr->ReceivedRTPPacket(static_cast<const uint8_t*>(data), |
| 87 | length, packet_time); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 88 | } |
| 89 | |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 90 | int VoENetworkImpl::ReceivedRTCPPacket(int channel, |
| 91 | const void* data, |
| 92 | size_t length) { |
henrikg | 5c075c8 | 2015-09-17 07:24:34 | [diff] [blame] | 93 | RTC_CHECK(_shared->statistics().Initialized()); |
| 94 | RTC_CHECK(data); |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 95 | if (length < 4) { |
Jelena Marusic | 9e50d7e | 2015-05-06 13:04:22 | [diff] [blame] | 96 | LOG_F(LS_ERROR) << "Invalid packet length: " << length; |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 97 | return -1; |
| 98 | } |
| 99 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 100 | voe::Channel* channelPtr = ch.channel(); |
Jelena Marusic | 9e50d7e | 2015-05-06 13:04:22 | [diff] [blame] | 101 | if (!channelPtr) { |
| 102 | LOG_F(LS_ERROR) << "Failed to locate channel: " << channel; |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 103 | return -1; |
| 104 | } |
| 105 | if (!channelPtr->ExternalTransport()) { |
Jelena Marusic | 9e50d7e | 2015-05-06 13:04:22 | [diff] [blame] | 106 | LOG_F(LS_ERROR) << "No external transport for channel: " << channel; |
Jelena Marusic | 0705a02 | 2015-05-04 12:15:32 | [diff] [blame] | 107 | return -1; |
| 108 | } |
mflodman | 823f908 | 2016-04-29 07:57:13 | [diff] [blame] | 109 | return channelPtr->ReceivedRTCPPacket(static_cast<const uint8_t*>(data), |
| 110 | length); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 111 | } |
Jelena Marusic | 9e50d7e | 2015-05-06 13:04:22 | [diff] [blame] | 112 | |
pbos@webrtc.org | 3b89e10 | 2013-07-03 15:12:26 | [diff] [blame] | 113 | } // namespace webrtc |