blob: 70c548857b8c1550d2977e676762f171e6b7be65 [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
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.orgad9cee82013-05-02 15:28:02 +000011#include "webrtc/voice_engine/voe_network_impl.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000012
andrew@webrtc.orgad9cee82013-05-02 15:28:02 +000013#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.orgb015cbe2012-10-22 18:19:23 +000019
20namespace webrtc
21{
22
23VoENetwork* VoENetwork::GetInterface(VoiceEngine* voiceEngine)
24{
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000025 if (NULL == voiceEngine)
26 {
27 return NULL;
28 }
tommi@webrtc.orgb9e5a3d2013-02-15 15:07:32 +000029 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000030 s->AddRef();
31 return s;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000032}
33
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000034VoENetworkImpl::VoENetworkImpl(voe::SharedData* shared) : _shared(shared)
35{
36 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
37 "VoENetworkImpl() - ctor");
38}
39
40VoENetworkImpl::~VoENetworkImpl()
41{
42 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
43 "~VoENetworkImpl() - dtor");
44}
45
46int 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.orgb3ada152013-08-07 17:57:36 +000057 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
58 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000059 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
68int 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.org8da2f652013-09-24 15:42:49 +000074 WEBRTC_TRACE(kTraceError, kTraceVoice,
75 VoEId(_shared->instance_id(), -1),
76 "DeRegisterExternalTransport() - invalid state");
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000077 }
pbos@webrtc.orgb3ada152013-08-07 17:57:36 +000078 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
79 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000080 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
89int VoENetworkImpl::ReceivedRTPPacket(int channel,
90 const void* data,
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25 +000091 unsigned int length) {
92 return ReceivedRTPPacket(channel, data, length, webrtc::PacketTime());
93}
94
95int VoENetworkImpl::ReceivedRTPPacket(int channel,
96 const void* data,
97 unsigned int length,
98 const PacketTime& packet_time)
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000099{
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.orgad9cee82013-05-02 15:28:02 +0000107 // L16 at 32 kHz, stereo, 10 ms frames (+12 byte RTP header) -> 1292 bytes
108 if ((length < 12) || (length > 1292))
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000109 {
andrew@webrtc.orgad9cee82013-05-02 15:28:02 +0000110 _shared->SetLastError(VE_INVALID_PACKET);
111 LOG(LS_ERROR) << "Invalid packet length: " << length;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000112 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.orgb3ada152013-08-07 17:57:36 +0000120 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
121 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000122 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.orgfec6b6e2014-03-24 10:38:25 +0000135 return channelPtr->ReceivedRTPPacket((const int8_t*) data, length,
136 packet_time);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000137}
138
139int 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.orgb3ada152013-08-07 17:57:36 +0000161 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
162 voe::Channel* channelPtr = ch.channel();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000163 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.org54f03bc2013-04-09 10:09:10 +0000175 return channelPtr->ReceivedRTCPPacket((const int8_t*) data, length);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000176}
pbos@webrtc.org3b89e102013-07-03 15:12:26 +0000177} // namespace webrtc