andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [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 +0000 | [diff] [blame] | 11 | #include "webrtc/voice_engine/voe_network_impl.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 12 | |
andrew@webrtc.org | ad9cee8 | 2013-05-02 15:28:02 +0000 | [diff] [blame] | 13 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 14 | #include "webrtc/system_wrappers/interface/logging.h" |
| 15 | #include "webrtc/system_wrappers/interface/trace.h" |
| 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 +0000 | [diff] [blame] | 19 | |
| 20 | namespace webrtc |
| 21 | { |
| 22 | |
| 23 | VoENetwork* VoENetwork::GetInterface(VoiceEngine* voiceEngine) |
| 24 | { |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 25 | if (NULL == voiceEngine) |
| 26 | { |
| 27 | return NULL; |
| 28 | } |
tommi@webrtc.org | b9e5a3d | 2013-02-15 15:07:32 +0000 | [diff] [blame] | 29 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 30 | s->AddRef(); |
| 31 | return s; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 32 | } |
| 33 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 34 | VoENetworkImpl::VoENetworkImpl(voe::SharedData* shared) : _shared(shared) |
| 35 | { |
| 36 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 37 | "VoENetworkImpl() - ctor"); |
| 38 | } |
| 39 | |
| 40 | VoENetworkImpl::~VoENetworkImpl() |
| 41 | { |
| 42 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 43 | "~VoENetworkImpl() - dtor"); |
| 44 | } |
| 45 | |
| 46 | int VoENetworkImpl::RegisterExternalTransport(int channel, |
| 47 | Transport& transport) |
| 48 | { |
| 49 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 50 | "SetExternalTransport(channel=%d, transport=0x%x)", |
| 51 | channel, &transport); |
| 52 | if (!_shared->statistics().Initialized()) |
| 53 | { |
| 54 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 55 | return -1; |
| 56 | } |
pbos@webrtc.org | b3ada15 | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 57 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 58 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 59 | if (channelPtr == NULL) |
| 60 | { |
| 61 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 62 | "SetExternalTransport() failed to locate channel"); |
| 63 | return -1; |
| 64 | } |
| 65 | return channelPtr->RegisterExternalTransport(transport); |
| 66 | } |
| 67 | |
| 68 | int VoENetworkImpl::DeRegisterExternalTransport(int channel) |
| 69 | { |
| 70 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 71 | "DeRegisterExternalTransport(channel=%d)", channel); |
| 72 | if (!_shared->statistics().Initialized()) |
| 73 | { |
henrika@webrtc.org | 8da2f65 | 2013-09-24 15:42:49 +0000 | [diff] [blame] | 74 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 75 | VoEId(_shared->instance_id(), -1), |
| 76 | "DeRegisterExternalTransport() - invalid state"); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 77 | } |
pbos@webrtc.org | b3ada15 | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 78 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 79 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 80 | if (channelPtr == NULL) |
| 81 | { |
| 82 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 83 | "DeRegisterExternalTransport() failed to locate channel"); |
| 84 | return -1; |
| 85 | } |
| 86 | return channelPtr->DeRegisterExternalTransport(); |
| 87 | } |
| 88 | |
| 89 | int VoENetworkImpl::ReceivedRTPPacket(int channel, |
| 90 | const void* data, |
solenberg@webrtc.org | fec6b6e | 2014-03-24 10:38:25 +0000 | [diff] [blame] | 91 | unsigned int length) { |
| 92 | return ReceivedRTPPacket(channel, data, length, webrtc::PacketTime()); |
| 93 | } |
| 94 | |
| 95 | int VoENetworkImpl::ReceivedRTPPacket(int channel, |
| 96 | const void* data, |
| 97 | unsigned int length, |
| 98 | const PacketTime& packet_time) |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 99 | { |
| 100 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 101 | "ReceivedRTPPacket(channel=%d, length=%u)", channel, length); |
| 102 | if (!_shared->statistics().Initialized()) |
| 103 | { |
| 104 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 105 | return -1; |
| 106 | } |
andrew@webrtc.org | ad9cee8 | 2013-05-02 15:28:02 +0000 | [diff] [blame] | 107 | // L16 at 32 kHz, stereo, 10 ms frames (+12 byte RTP header) -> 1292 bytes |
| 108 | if ((length < 12) || (length > 1292)) |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 109 | { |
andrew@webrtc.org | ad9cee8 | 2013-05-02 15:28:02 +0000 | [diff] [blame] | 110 | _shared->SetLastError(VE_INVALID_PACKET); |
| 111 | LOG(LS_ERROR) << "Invalid packet length: " << length; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 112 | return -1; |
| 113 | } |
| 114 | if (NULL == data) |
| 115 | { |
| 116 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
| 117 | "ReceivedRTPPacket() invalid data vector"); |
| 118 | return -1; |
| 119 | } |
pbos@webrtc.org | b3ada15 | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 120 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 121 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 122 | if (channelPtr == NULL) |
| 123 | { |
| 124 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 125 | "ReceivedRTPPacket() failed to locate channel"); |
| 126 | return -1; |
| 127 | } |
| 128 | |
| 129 | if (!channelPtr->ExternalTransport()) |
| 130 | { |
| 131 | _shared->SetLastError(VE_INVALID_OPERATION, kTraceError, |
| 132 | "ReceivedRTPPacket() external transport is not enabled"); |
| 133 | return -1; |
| 134 | } |
solenberg@webrtc.org | fec6b6e | 2014-03-24 10:38:25 +0000 | [diff] [blame] | 135 | return channelPtr->ReceivedRTPPacket((const int8_t*) data, length, |
| 136 | packet_time); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | int VoENetworkImpl::ReceivedRTCPPacket(int channel, const void* data, |
| 140 | unsigned int length) |
| 141 | { |
| 142 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 143 | "ReceivedRTCPPacket(channel=%d, length=%u)", channel, length); |
| 144 | if (!_shared->statistics().Initialized()) |
| 145 | { |
| 146 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 147 | return -1; |
| 148 | } |
| 149 | if (length < 4) |
| 150 | { |
| 151 | _shared->SetLastError(VE_INVALID_PACKET, kTraceError, |
| 152 | "ReceivedRTCPPacket() invalid packet length"); |
| 153 | return -1; |
| 154 | } |
| 155 | if (NULL == data) |
| 156 | { |
| 157 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
| 158 | "ReceivedRTCPPacket() invalid data vector"); |
| 159 | return -1; |
| 160 | } |
pbos@webrtc.org | b3ada15 | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 161 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 162 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 163 | if (channelPtr == NULL) |
| 164 | { |
| 165 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 166 | "ReceivedRTCPPacket() failed to locate channel"); |
| 167 | return -1; |
| 168 | } |
| 169 | if (!channelPtr->ExternalTransport()) |
| 170 | { |
| 171 | _shared->SetLastError(VE_INVALID_OPERATION, kTraceError, |
| 172 | "ReceivedRTCPPacket() external transport is not enabled"); |
| 173 | return -1; |
| 174 | } |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 175 | return channelPtr->ReceivedRTCPPacket((const int8_t*) data, length); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 176 | } |
pbos@webrtc.org | 3b89e10 | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 177 | } // namespace webrtc |