blob: 8f0e717edf1a27b4bbda01a1059b08044bc74043 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org0975d212012-03-06 20:59:13 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000011#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
12#include "webrtc/system_wrappers/interface/file_wrapper.h"
13#include "webrtc/system_wrappers/interface/trace.h"
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +000014#include "webrtc/video_engine/include/vie_network.h"
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000015#include "webrtc/voice_engine/include/voe_errors.h"
16#include "webrtc/voice_engine/voe_rtp_rtcp_impl.h"
17#include "webrtc/voice_engine/voice_engine_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000018
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000019#include "webrtc/voice_engine/channel.h"
20#include "webrtc/voice_engine/transmit_mixer.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
22namespace webrtc {
23
24VoERTP_RTCP* VoERTP_RTCP::GetInterface(VoiceEngine* voiceEngine)
25{
26#ifndef WEBRTC_VOICE_ENGINE_RTP_RTCP_API
27 return NULL;
28#else
29 if (NULL == voiceEngine)
30 {
31 return NULL;
32 }
tommi@webrtc.org0989fb72013-02-15 15:07:32 +000033 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
tommi@webrtc.orga990e122012-04-26 15:28:22 +000034 s->AddRef();
35 return s;
niklase@google.com470e71d2011-07-07 08:21:25 +000036#endif
37}
38
39#ifdef WEBRTC_VOICE_ENGINE_RTP_RTCP_API
40
tommi@webrtc.org851becd2012-04-04 14:57:19 +000041VoERTP_RTCPImpl::VoERTP_RTCPImpl(voe::SharedData* shared) : _shared(shared)
niklase@google.com470e71d2011-07-07 08:21:25 +000042{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000043 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000044 "VoERTP_RTCPImpl::VoERTP_RTCPImpl() - ctor");
45}
46
47VoERTP_RTCPImpl::~VoERTP_RTCPImpl()
48{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000049 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000050 "VoERTP_RTCPImpl::~VoERTP_RTCPImpl() - dtor");
51}
52
niklase@google.com470e71d2011-07-07 08:21:25 +000053int VoERTP_RTCPImpl::SetLocalSSRC(int channel, unsigned int ssrc)
54{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000055 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000056 "SetLocalSSRC(channel=%d, %lu)", channel, ssrc);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000057 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +000058 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000059 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +000060 return -1;
61 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000062 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
63 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +000064 if (channelPtr == NULL)
65 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000066 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +000067 "SetLocalSSRC() failed to locate channel");
68 return -1;
69 }
70 return channelPtr->SetLocalSSRC(ssrc);
71}
72
73int VoERTP_RTCPImpl::GetLocalSSRC(int channel, unsigned int& ssrc)
74{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000075 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000076 "GetLocalSSRC(channel=%d, ssrc=?)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000077 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +000078 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000079 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +000080 return -1;
81 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000082 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
83 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +000084 if (channelPtr == NULL)
85 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000086 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +000087 "GetLocalSSRC() failed to locate channel");
88 return -1;
89 }
90 return channelPtr->GetLocalSSRC(ssrc);
91}
92
93int VoERTP_RTCPImpl::GetRemoteSSRC(int channel, unsigned int& ssrc)
94{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000095 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000096 "GetRemoteSSRC(channel=%d, ssrc=?)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000097 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +000098 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000099 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000100 return -1;
101 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000102 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
103 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000104 if (channelPtr == NULL)
105 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000106 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000107 "GetRemoteSSRC() failed to locate channel");
108 return -1;
109 }
110 return channelPtr->GetRemoteSSRC(ssrc);
111}
112
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000113int VoERTP_RTCPImpl::SetSendAudioLevelIndicationStatus(int channel,
114 bool enable,
115 unsigned char id)
niklase@google.com470e71d2011-07-07 08:21:25 +0000116{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000117 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000118 "SetSendAudioLevelIndicationStatus(channel=%d, enable=%d,"
119 " ID=%u)", channel, enable, id);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000120 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000121 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000122 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000123 return -1;
124 }
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000125 if (enable && (id < kVoiceEngineMinRtpExtensionId ||
126 id > kVoiceEngineMaxRtpExtensionId))
niklase@google.com470e71d2011-07-07 08:21:25 +0000127 {
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000128 // [RFC5285] The 4-bit id is the local identifier of this element in
niklase@google.com470e71d2011-07-07 08:21:25 +0000129 // the range 1-14 inclusive.
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000130 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000131 "SetSendAudioLevelIndicationStatus() invalid ID parameter");
niklase@google.com470e71d2011-07-07 08:21:25 +0000132 return -1;
133 }
134
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000135 // Set state and id for the specified channel.
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000136 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
137 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000138 if (channelPtr == NULL)
139 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000140 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000141 "SetSendAudioLevelIndicationStatus() failed to locate channel");
niklase@google.com470e71d2011-07-07 08:21:25 +0000142 return -1;
143 }
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000144 return channelPtr->SetSendAudioLevelIndicationStatus(enable, id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000145}
146
wu@webrtc.org93fd25c2014-04-24 20:33:08 +0000147int VoERTP_RTCPImpl::SetReceiveAudioLevelIndicationStatus(int channel,
148 bool enable,
149 unsigned char id) {
150 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
151 "SetReceiveAudioLevelIndicationStatus(channel=%d, enable=%d, id=%u)",
152 channel, enable, id);
153 if (!_shared->statistics().Initialized()) {
154 _shared->SetLastError(VE_NOT_INITED, kTraceError);
155 return -1;
156 }
157 if (enable &&
158 (id < kVoiceEngineMinRtpExtensionId ||
159 id > kVoiceEngineMaxRtpExtensionId)) {
160 // [RFC5285] The 4-bit id is the local identifier of this element in
161 // the range 1-14 inclusive.
162 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
163 "SetReceiveAbsoluteSenderTimeStatus() invalid id parameter");
164 return -1;
165 }
166 // Set state and id for the specified channel.
167 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
168 voe::Channel* channel_ptr = ch.channel();
169 if (channel_ptr == NULL) {
170 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
171 "SetReceiveAudioLevelIndicationStatus() failed to locate channel");
172 return -1;
173 }
174 return channel_ptr->SetReceiveAudioLevelIndicationStatus(enable, id);
175}
176
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000177int VoERTP_RTCPImpl::SetSendAbsoluteSenderTimeStatus(int channel,
178 bool enable,
179 unsigned char id) {
180 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
181 "SetSendAbsoluteSenderTimeStatus(channel=%d, enable=%d, id=%u)",
182 channel, enable, id);
183 if (!_shared->statistics().Initialized()) {
184 _shared->SetLastError(VE_NOT_INITED, kTraceError);
185 return -1;
186 }
187 if (enable && (id < kVoiceEngineMinRtpExtensionId ||
188 id > kVoiceEngineMaxRtpExtensionId)) {
189 // [RFC5285] The 4-bit id is the local identifier of this element in
190 // the range 1-14 inclusive.
191 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
192 "SetSendAbsoluteSenderTimeStatus() invalid id parameter");
193 return -1;
194 }
195 // Set state and id for the specified channel.
196 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
197 voe::Channel* channelPtr = ch.channel();
198 if (channelPtr == NULL) {
199 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
200 "SetSendAbsoluteSenderTimeStatus() failed to locate channel");
201 return -1;
202 }
203 return channelPtr->SetSendAbsoluteSenderTimeStatus(enable, id);
204}
205
206int VoERTP_RTCPImpl::SetReceiveAbsoluteSenderTimeStatus(int channel,
207 bool enable,
208 unsigned char id) {
209 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
210 "SetReceiveAbsoluteSenderTimeStatus(channel=%d, enable=%d, id=%u)",
211 channel, enable, id);
212 if (!_shared->statistics().Initialized()) {
213 _shared->SetLastError(VE_NOT_INITED, kTraceError);
214 return -1;
215 }
216 if (enable && (id < kVoiceEngineMinRtpExtensionId ||
217 id > kVoiceEngineMaxRtpExtensionId)) {
218 // [RFC5285] The 4-bit id is the local identifier of this element in
219 // the range 1-14 inclusive.
220 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
221 "SetReceiveAbsoluteSenderTimeStatus() invalid id parameter");
222 return -1;
223 }
224 // Set state and id for the specified channel.
225 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
226 voe::Channel* channelPtr = ch.channel();
227 if (channelPtr == NULL) {
228 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
229 "SetReceiveAbsoluteSenderTimeStatus() failed to locate channel");
230 return -1;
231 }
232 return channelPtr->SetReceiveAbsoluteSenderTimeStatus(enable, id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000233}
234
235int VoERTP_RTCPImpl::SetRTCPStatus(int channel, bool enable)
236{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000237 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000238 "SetRTCPStatus(channel=%d, enable=%d)", channel, enable);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000239 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000240 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000241 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000242 return -1;
243 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000244 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
245 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000246 if (channelPtr == NULL)
247 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000248 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000249 "SetRTCPStatus() failed to locate channel");
250 return -1;
251 }
252 return channelPtr->SetRTCPStatus(enable);
253}
254
255int VoERTP_RTCPImpl::GetRTCPStatus(int channel, bool& enabled)
256{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000257 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000258 "GetRTCPStatus(channel=%d)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000259 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000260 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000261 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000262 return -1;
263 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000264 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
265 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000266 if (channelPtr == NULL)
267 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000268 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000269 "GetRTCPStatus() failed to locate channel");
270 return -1;
271 }
272 return channelPtr->GetRTCPStatus(enabled);
273}
274
275int VoERTP_RTCPImpl::SetRTCP_CNAME(int channel, const char cName[256])
276{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000277 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000278 "SetRTCP_CNAME(channel=%d, cName=%s)", channel, cName);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000279 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000280 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000281 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000282 return -1;
283 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000284 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
285 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000286 if (channelPtr == NULL)
287 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000288 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000289 "SetRTCP_CNAME() failed to locate channel");
290 return -1;
291 }
292 return channelPtr->SetRTCP_CNAME(cName);
293}
294
295int VoERTP_RTCPImpl::GetRTCP_CNAME(int channel, char cName[256])
296{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000297 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000298 "GetRTCP_CNAME(channel=%d, cName=?)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000299 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000300 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000301 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000302 return -1;
303 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000304 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
305 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000306 if (channelPtr == NULL)
307 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000308 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000309 "GetRTCP_CNAME() failed to locate channel");
310 return -1;
311 }
312 return channelPtr->GetRTCP_CNAME(cName);
313}
314
315int VoERTP_RTCPImpl::GetRemoteRTCP_CNAME(int channel, char cName[256])
316{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000317 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000318 "GetRemoteRTCP_CNAME(channel=%d, cName=?)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000319 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000320 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000321 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000322 return -1;
323 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000324 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
325 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000326 if (channelPtr == NULL)
327 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000328 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000329 "GetRemoteRTCP_CNAME() failed to locate channel");
330 return -1;
331 }
332 return channelPtr->GetRemoteRTCP_CNAME(cName);
333}
334
335int VoERTP_RTCPImpl::GetRemoteRTCPData(
336 int channel,
337 unsigned int& NTPHigh, // from sender info in SR
338 unsigned int& NTPLow, // from sender info in SR
339 unsigned int& timestamp, // from sender info in SR
340 unsigned int& playoutTimestamp, // derived locally
341 unsigned int* jitter, // from report block 1 in SR/RR
342 unsigned short* fractionLost) // from report block 1 in SR/RR
343{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000344 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000345 "GetRemoteRTCPData(channel=%d,...)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000346 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000347 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000348 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000349 return -1;
350 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000351 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
352 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000353 if (channelPtr == NULL)
354 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000355 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000356 "GetRemoteRTCP_CNAME() failed to locate channel");
357 return -1;
358 }
359 return channelPtr->GetRemoteRTCPData(NTPHigh,
360 NTPLow,
361 timestamp,
362 playoutTimestamp,
363 jitter,
364 fractionLost);
365}
366
niklase@google.com470e71d2011-07-07 08:21:25 +0000367int VoERTP_RTCPImpl::GetRTPStatistics(int channel,
368 unsigned int& averageJitterMs,
369 unsigned int& maxJitterMs,
370 unsigned int& discardedPackets)
371{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000372 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000373 "GetRTPStatistics(channel=%d,....)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000374 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000375 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000376 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000377 return -1;
378 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000379 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
380 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000381 if (channelPtr == NULL)
382 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000383 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000384 "GetRTPStatistics() failed to locate channel");
385 return -1;
386 }
387 return channelPtr->GetRTPStatistics(averageJitterMs,
388 maxJitterMs,
389 discardedPackets);
390}
391
392int VoERTP_RTCPImpl::GetRTCPStatistics(int channel, CallStatistics& stats)
393{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000394 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000395 "GetRTCPStatistics(channel=%d)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000396 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000397 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000398 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000399 return -1;
400 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000401 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
402 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000403 if (channelPtr == NULL)
404 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000405 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000406 "GetRTPStatistics() failed to locate channel");
407 return -1;
408 }
409 return channelPtr->GetRTPStatistics(stats);
410}
411
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000412int VoERTP_RTCPImpl::GetRemoteRTCPReportBlocks(
413 int channel, std::vector<ReportBlock>* report_blocks) {
414 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
415 "GetRemoteRTCPReportBlocks(channel=%d)", channel);
416 if (!_shared->statistics().Initialized()) {
417 _shared->SetLastError(VE_NOT_INITED, kTraceError);
418 return -1;
419 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000420 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
421 voe::Channel* channel_ptr = ch.channel();
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000422 if (channel_ptr == NULL) {
423 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
424 "GetRemoteRTCPReportBlocks() failed to locate channel");
425 return -1;
426 }
427 return channel_ptr->GetRemoteRTCPReportBlocks(report_blocks);
428}
429
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000430int VoERTP_RTCPImpl::SetREDStatus(int channel, bool enable, int redPayloadtype)
niklase@google.com470e71d2011-07-07 08:21:25 +0000431{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000432 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000433 "SetREDStatus(channel=%d, enable=%d, redPayloadtype=%d)",
niklase@google.com470e71d2011-07-07 08:21:25 +0000434 channel, enable, redPayloadtype);
435#ifdef WEBRTC_CODEC_RED
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000436 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000437 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000438 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000439 return -1;
440 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000441 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
442 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000443 if (channelPtr == NULL)
444 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000445 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000446 "SetREDStatus() failed to locate channel");
niklase@google.com470e71d2011-07-07 08:21:25 +0000447 return -1;
448 }
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000449 return channelPtr->SetREDStatus(enable, redPayloadtype);
niklase@google.com470e71d2011-07-07 08:21:25 +0000450#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000451 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000452 "SetREDStatus() RED is not supported");
niklase@google.com470e71d2011-07-07 08:21:25 +0000453 return -1;
454#endif
455}
456
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000457int VoERTP_RTCPImpl::GetREDStatus(int channel,
niklase@google.com470e71d2011-07-07 08:21:25 +0000458 bool& enabled,
459 int& redPayloadtype)
460{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000461 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000462 "GetREDStatus(channel=%d, enabled=?, redPayloadtype=?)",
niklase@google.com470e71d2011-07-07 08:21:25 +0000463 channel);
464#ifdef WEBRTC_CODEC_RED
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000465 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000466 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000467 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000468 return -1;
469 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000470 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
471 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000472 if (channelPtr == NULL)
473 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000474 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000475 "GetREDStatus() failed to locate channel");
niklase@google.com470e71d2011-07-07 08:21:25 +0000476 return -1;
477 }
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000478 return channelPtr->GetREDStatus(enabled, redPayloadtype);
niklase@google.com470e71d2011-07-07 08:21:25 +0000479#else
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000480 _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000481 "GetREDStatus() RED is not supported");
niklase@google.com470e71d2011-07-07 08:21:25 +0000482 return -1;
483#endif
484}
485
niklas.enbom@webrtc.orgb35d2e32013-05-31 21:13:52 +0000486int VoERTP_RTCPImpl::SetNACKStatus(int channel,
487 bool enable,
488 int maxNoPackets)
489{
490 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
491 "SetNACKStatus(channel=%d, enable=%d, maxNoPackets=%d)",
492 channel, enable, maxNoPackets);
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +0000493
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000494 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
495 voe::Channel* channelPtr = ch.channel();
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +0000496 if (channelPtr == NULL)
497 {
498 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
499 "SetNACKStatus() failed to locate channel");
500 return -1;
501 }
502 channelPtr->SetNACKStatus(enable, maxNoPackets);
niklas.enbom@webrtc.orgb35d2e32013-05-31 21:13:52 +0000503 return 0;
504}
505
506
niklase@google.com470e71d2011-07-07 08:21:25 +0000507int VoERTP_RTCPImpl::StartRTPDump(int channel,
508 const char fileNameUTF8[1024],
509 RTPDirections direction)
510{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000511 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000512 "StartRTPDump(channel=%d, fileNameUTF8=%s, direction=%d)",
513 channel, fileNameUTF8, direction);
514 assert(1024 == FileWrapper::kMaxFileNameSize);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000515 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000516 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000517 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000518 return -1;
519 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000520 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
521 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000522 if (channelPtr == NULL)
523 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000524 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000525 "StartRTPDump() failed to locate channel");
526 return -1;
527 }
528 return channelPtr->StartRTPDump(fileNameUTF8, direction);
529}
530
531int VoERTP_RTCPImpl::StopRTPDump(int channel, RTPDirections direction)
532{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000533 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000534 "StopRTPDump(channel=%d, direction=%d)", channel, direction);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000535 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000536 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000537 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000538 return -1;
539 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000540 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
541 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000542 if (channelPtr == NULL)
543 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000544 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000545 "StopRTPDump() failed to locate channel");
546 return -1;
547 }
548 return channelPtr->StopRTPDump(direction);
549}
550
551int VoERTP_RTCPImpl::RTPDumpIsActive(int channel, RTPDirections direction)
552{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000553 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000554 "RTPDumpIsActive(channel=%d, direction=%d)",
555 channel, direction);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000556 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000557 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000558 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000559 return -1;
560 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000561 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
562 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000563 if (channelPtr == NULL)
564 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000565 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000566 "StopRTPDump() failed to locate channel");
567 return -1;
568 }
569 return channelPtr->RTPDumpIsActive(direction);
570}
571
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000572int VoERTP_RTCPImpl::SetVideoEngineBWETarget(int channel,
573 ViENetwork* vie_network,
574 int video_channel) {
575 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
576 "SetVideoEngineBWETarget(channel=%d, vie_network=?, video_channel=%d)",
577 channel, vie_network, video_channel);
578
579 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
580 voe::Channel* channelPtr = ch.channel();
581 if (channelPtr == NULL) {
582 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
583 "SetVideoEngineBWETarget() failed to locate channel");
584 if (vie_network) {
585 vie_network->Release();
586 }
587 return -1;
588 }
589 channelPtr->SetVideoEngineBWETarget(vie_network, video_channel);
590 return 0;
591}
592
niklase@google.com470e71d2011-07-07 08:21:25 +0000593#endif // #ifdef WEBRTC_VOICE_ENGINE_RTP_RTCP_API
594
595} // namespace webrtc