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 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 13 | #include "webrtc/base/format_macros.h" |
andrew@webrtc.org | 8c845cb | 2013-05-02 15:28:02 +0000 | [diff] [blame] | 14 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 15 | #include "webrtc/system_wrappers/interface/logging.h" |
| 16 | #include "webrtc/system_wrappers/interface/trace.h" |
| 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) { |
| 24 | if (NULL == voiceEngine) { |
| 25 | return NULL; |
| 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) { |
| 33 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 34 | "VoENetworkImpl() - ctor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 37 | VoENetworkImpl::~VoENetworkImpl() { |
| 38 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 39 | "~VoENetworkImpl() - dtor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | } |
| 41 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | int VoENetworkImpl::RegisterExternalTransport(int channel, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 43 | Transport& transport) { |
| 44 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 45 | "SetExternalTransport(channel=%d, transport=0x%x)", channel, |
| 46 | &transport); |
| 47 | if (!_shared->statistics().Initialized()) { |
| 48 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 49 | return -1; |
| 50 | } |
| 51 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 52 | voe::Channel* channelPtr = ch.channel(); |
| 53 | if (channelPtr == NULL) { |
| 54 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 55 | "SetExternalTransport() failed to locate channel"); |
| 56 | return -1; |
| 57 | } |
| 58 | return channelPtr->RegisterExternalTransport(transport); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 61 | int VoENetworkImpl::DeRegisterExternalTransport(int channel) { |
| 62 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 63 | "DeRegisterExternalTransport(channel=%d)", channel); |
| 64 | if (!_shared->statistics().Initialized()) { |
| 65 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 66 | "DeRegisterExternalTransport() - invalid state"); |
| 67 | } |
| 68 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 69 | voe::Channel* channelPtr = ch.channel(); |
| 70 | if (channelPtr == NULL) { |
| 71 | _shared->SetLastError( |
| 72 | VE_CHANNEL_NOT_VALID, kTraceError, |
| 73 | "DeRegisterExternalTransport() failed to locate channel"); |
| 74 | return -1; |
| 75 | } |
| 76 | return channelPtr->DeRegisterExternalTransport(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | int VoENetworkImpl::ReceivedRTPPacket(int channel, |
| 80 | const void* data, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 81 | size_t length) { |
solenberg@webrtc.org | b1f5010 | 2014-03-24 10:38:25 +0000 | [diff] [blame] | 82 | return ReceivedRTPPacket(channel, data, length, webrtc::PacketTime()); |
| 83 | } |
| 84 | |
| 85 | int VoENetworkImpl::ReceivedRTPPacket(int channel, |
| 86 | const void* data, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 87 | size_t length, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 88 | const PacketTime& packet_time) { |
| 89 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 90 | "ReceivedRTPPacket(channel=%d, length=%" PRIuS ")", channel, |
| 91 | length); |
| 92 | if (!_shared->statistics().Initialized()) { |
| 93 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 94 | return -1; |
| 95 | } |
| 96 | // L16 at 32 kHz, stereo, 10 ms frames (+12 byte RTP header) -> 1292 bytes |
| 97 | if ((length < 12) || (length > 1292)) { |
| 98 | _shared->SetLastError(VE_INVALID_PACKET); |
| 99 | LOG(LS_ERROR) << "Invalid packet length: " << length; |
| 100 | return -1; |
| 101 | } |
| 102 | if (NULL == data) { |
| 103 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
| 104 | "ReceivedRTPPacket() invalid data vector"); |
| 105 | return -1; |
| 106 | } |
| 107 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 108 | voe::Channel* channelPtr = ch.channel(); |
| 109 | if (channelPtr == NULL) { |
| 110 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 111 | "ReceivedRTPPacket() failed to locate channel"); |
| 112 | return -1; |
| 113 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 115 | if (!channelPtr->ExternalTransport()) { |
| 116 | _shared->SetLastError( |
| 117 | VE_INVALID_OPERATION, kTraceError, |
| 118 | "ReceivedRTPPacket() external transport is not enabled"); |
| 119 | return -1; |
| 120 | } |
| 121 | return channelPtr->ReceivedRTPPacket((const int8_t*)data, length, |
| 122 | packet_time); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 125 | int VoENetworkImpl::ReceivedRTCPPacket(int channel, |
| 126 | const void* data, |
| 127 | size_t length) { |
| 128 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 129 | "ReceivedRTCPPacket(channel=%d, length=%" PRIuS ")", channel, |
| 130 | length); |
| 131 | if (!_shared->statistics().Initialized()) { |
| 132 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 133 | return -1; |
| 134 | } |
| 135 | if (length < 4) { |
| 136 | _shared->SetLastError(VE_INVALID_PACKET, kTraceError, |
| 137 | "ReceivedRTCPPacket() invalid packet length"); |
| 138 | return -1; |
| 139 | } |
| 140 | if (NULL == data) { |
| 141 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
| 142 | "ReceivedRTCPPacket() invalid data vector"); |
| 143 | return -1; |
| 144 | } |
| 145 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 146 | voe::Channel* channelPtr = ch.channel(); |
| 147 | if (channelPtr == NULL) { |
| 148 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 149 | "ReceivedRTCPPacket() failed to locate channel"); |
| 150 | return -1; |
| 151 | } |
| 152 | if (!channelPtr->ExternalTransport()) { |
| 153 | _shared->SetLastError( |
| 154 | VE_INVALID_OPERATION, kTraceError, |
| 155 | "ReceivedRTCPPacket() external transport is not enabled"); |
| 156 | return -1; |
| 157 | } |
| 158 | return channelPtr->ReceivedRTCPPacket((const int8_t*)data, length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 159 | } |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 160 | } // namespace webrtc |